dokeos-library
[ class tree: dokeos-library ] [ index: dokeos-library ] [ all elements ]

Source for file export.lib.inc.php

Documentation is available at export.lib.inc.php

  1. <?php
  2. /*
  3. ==============================================================================
  4.     Dokeos - elearning and course management software
  5.  
  6.     Copyright (c) 2004-2008 Dokeos SPRL
  7.     Copyright (c) 2003 Ghent University (UGent)
  8.     Copyright (c) 2001 Universite catholique de Louvain (UCL)
  9.     Copyright (c) Olivier Brouckaert
  10.     Copyright (c) Bart Mollet, Hogeschool Gent
  11.  
  12.     For a full list of contributors, see "credits.txt".
  13.     The full license can be read in "license.txt".
  14.  
  15.     This program is free software; you can redistribute it and/or
  16.     modify it under the terms of the GNU General Public License
  17.     as published by the Free Software Foundation; either version 2
  18.     of the License, or (at your option) any later version.
  19.  
  20.     See the GNU General Public License for more details.
  21.  
  22.     Contact address: Dokeos, rue du Corbeau, 108, B-1030 Brussels, Belgium, info@dokeos.com
  23. ==============================================================================
  24. */
  25. /**
  26. ==============================================================================
  27. *    This is the export library for Dokeos.
  28. *    Include/require it in your code to use its functionality.
  29. *
  30. *    plusieures fonctions ci-dessous  ont �t� adapt�es de fonctions  distribu�es par www.nexen.net
  31. *
  32. *    @package dokeos.library
  33. ==============================================================================
  34. */
  35. require_once ('document.lib.php');
  36. class Export
  37. {
  38.     /**
  39.      * Export tabular data to CSV-file
  40.      * @param array $data 
  41.      * @param string $filename 
  42.      */
  43.     function export_table_csv($data$filename 'export')
  44.     {            
  45.         $file api_get_path(SYS_ARCHIVE_PATH).uniqid('').'.csv';
  46.         $handle @fopen($file'a+');        
  47.         
  48.         if(is_array($data))
  49.         {
  50.             foreach ($data as $index => $row)
  51.             {
  52.                 $line='';
  53.                 if(is_array($row))
  54.                 {    
  55.                     foreach($row as $value)            
  56.                     {                
  57.                         $line .= '"'.str_replace('"','""',$value).'";';
  58.                     }
  59.                 }
  60.                 @fwrite($handle$line."\n");    
  61.             }
  62.         }
  63.         @fclose($handle);                
  64.         DocumentManager :: file_send_for_download($filetrue$filename.'.csv');    
  65.         exit();
  66.     }
  67.     /**
  68.      * Export tabular data to XLS-file
  69.      * @param array $data 
  70.      * @param string $filename 
  71.      */
  72.     function export_table_xls($data$filename 'export')
  73.     {
  74.         $file api_get_path(SYS_ARCHIVE_PATH).uniqid('').'.xls';
  75.         $handle @fopen($file'a+');        
  76.         foreach ($data as $index => $row)    
  77.         {                        
  78.             @fwrite($handleimplode("\t"$row)."\n");                            
  79.         }    
  80.         @fclose($handle);
  81.         DocumentManager :: file_send_for_download($filetrue$filename.'.xls');
  82.         exit();
  83.     }
  84.     /**
  85.      * Export tabular data to XML-file
  86.      * @param array $data 
  87.      * @param string $filename 
  88.      */
  89.     function export_table_xml($data$filename 'export'$item_tagname 'item'$wrapper_tagname null)
  90.     {
  91.         $file api_get_path(SYS_ARCHIVE_PATH).'/'.uniqid('').'.xml';
  92.         $handle fopen($file'a+');
  93.         fwrite($handle'<?xml version="1.0" encoding="ISO-8859-1"?>'."\n");
  94.         if (!is_null($wrapper_tagname))
  95.         {
  96.             fwrite($handle"\t".'<'.$wrapper_tagname.'>'."\n");
  97.         }
  98.         foreach ($data as $index => $row)
  99.         {
  100.             fwrite($handle'<'.$item_tagname.'>'."\n");
  101.             foreach ($row as $key => $value)
  102.             {
  103.                 fwrite($handle"\t\t".'<'.$key.'>'.$value.'</'.$key.'>'."\n");
  104.             }
  105.             fwrite($handle"\t".'</'.$item_tagname.'>'."\n");
  106.         }
  107.         if (!is_null($wrapper_tagname))
  108.         {
  109.             fwrite($handle'</'.$wrapper_tagname.'>'."\n");
  110.         }
  111.         fclose($handle);
  112.         DocumentManager :: file_send_for_download($filetrue$filename.'.xml');
  113.         exit;
  114.     }
  115. }
  116. /*
  117. ==============================================================================
  118.         FUNCTIONS
  119. ==============================================================================
  120. */
  121. /**
  122.  * Backup a db to a file
  123.  *
  124.  * @param ressource    $link            lien vers la base de donnees
  125.  * @param string    $db_name        nom de la base de donnees
  126.  * @param boolean    $structure        true => sauvegarde de la structure des tables
  127.  * @param boolean    $donnees        true => sauvegarde des donnes des tables
  128.  * @param boolean    $format            format des donnees
  129.                                      'INSERT' => des clauses SQL INSERT
  130.                                     'CSV' => donnees separees par des virgules
  131.  * @param boolean    $insertComplet    true => clause INSERT avec nom des champs
  132.  * @param boolean    $verbose         true => comment are printed
  133.  * @deprecated Function only used in deprecated function makeTheBackup(...)
  134.  */
  135. function backupDatabase($link$db_name$structure$donnees$format 'SQL'$whereSave '.'$insertComplet ''$verbose false)
  136. {
  137.     $errorCode "";
  138.     if (!is_resource($link))
  139.     {
  140.         GLOBAL $error_msg$error_no;
  141.         $error_msg["backup"]["[".basename(__FILE__)."][".__LINE__."] link is not a ressource";
  142.         $error_no["backup"]["1";
  143.         return false;
  144.     }
  145.     mysql_select_db($db_name);
  146.     $format strtolower($format);
  147.     $filename $whereSave."/courseDbContent.".$format;
  148.     $format strtoupper($format);
  149.     $fp fopen($filename"w");
  150.     if (!is_resource($fp))
  151.         return false;
  152.     // liste des tables
  153.     $res mysql_list_tables($db_name$link);
  154.     $num_rows Database::num_rows($res);
  155.     $i 0;
  156.     while ($i $num_rows)
  157.     {
  158.         $tablename mysql_tablename($res$i);
  159.  
  160.         if ($format == "PHP")
  161.             fwrite($fp"\nmysql_query(\"");
  162.         if ($format == "HTML")
  163.             fwrite($fp"\n<h2>$tablename</h2><table border=\"1\" width=\"100%\">");
  164.         if ($verbose)
  165.             echo "[".$tablename."] ";
  166.         if ($structure === true)
  167.         {
  168.             if ($format == "PHP" || $format == "SQL")
  169.                 fwrite($fp"DROP TABLE IF EXISTS `$tablename`;");
  170.             if ($format == "PHP")
  171.                 fwrite($fp"\");\n");
  172.             if ($format == "PHP")
  173.                 fwrite($fp"\nmysql_query(\"");
  174.             // requete de creation de la table
  175.             $query "SHOW CREATE TABLE `".$tablename."`";
  176.             $resCreate api_sql_query($query,__FILE____LINE__);
  177.             $row Database::fetch_array($resCreate);
  178.             $schema $row[1].";";
  179.             if ($format == "PHP" || $format == "SQL")
  180.                 fwrite($fp"$schema");
  181.             if ($format == "PHP")
  182.                 fwrite($fp"\");\n\n");
  183.         }
  184.         if ($donnees === true)
  185.         {
  186.             // les donn�es de la table
  187.             $query "SELECT * FROM $tablename";
  188.             $resData api_sql_query($query,__FILE____LINE__);
  189.             if (Database::num_rows($resData0)
  190.             {
  191.                 $sFieldnames "";
  192.                 if ($insertComplet === true)
  193.                 {
  194.                     $num_fields mysql_num_fields($resData);
  195.                     for ($j 0$j $num_fields$j ++)
  196.                     {
  197.                         $sFieldnames .= "`".mysql_field_name($resData$j)."`, ";
  198.                     }
  199.                     $sFieldnames "(".substr($sFieldnames0-2).")";
  200.                 }
  201.                 $sInsert "INSERT INTO `$tablename$sFieldnames values ";
  202.                 while ($rowdata Database::fetch_array($resData,'ASSOC'))
  203.                 {
  204.                     if ($format == "HTML")
  205.                     {
  206.                         $lesDonnees "\n\t<tr>\n\t\t<td>".implode("\n\t\t</td>\n\t\t<td>"$rowdata)."\n\t\t</td></tr>";
  207.                     }
  208.                     if ($format == "SQL" || $format == "PHP")
  209.                     {
  210.                         $lesDonnees "<guillemet>".implode("<guillemet>,<guillemet>"$rowdata)."<guillemet>";
  211.                         $lesDonnees str_replace("<guillemet>""'"addslashes($lesDonnees));
  212.                         if ($format == "SQL")
  213.                         {
  214.                             $lesDonnees $sInsert." ( ".$lesDonnees." );";
  215.                         }
  216.                         if ($format == "PHP")
  217.                             fwrite($fp"\nmysql_query(\"");
  218.                     }
  219.                     fwrite($fp"$lesDonnees");
  220.                     if ($format == "PHP")
  221.                         fwrite($fp"\");\n");
  222.                 }
  223.             }
  224.         }
  225.         $i ++;
  226.         if ($format == "HTML")
  227.             fwrite($fp"\n</table>\n<hr />\n");
  228.     }
  229.     echo "fin du backup au  format :".$format;
  230.     fclose($fp);
  231. }
  232. /**
  233.  * @deprecated use function copyDirTo($origDirPath, $destination) in
  234.  *  fileManagerLib.inc.php
  235.  */
  236. function copydir($origine$destination$verbose false)
  237. {
  238.     $dossier opendir($origineor die("<HR>impossible d'ouvrir ".$origine." [".__LINE__."]");
  239.     if ($verbose)
  240.         echo "<BR> $origine -> $destination";
  241.     /*    if (file_exists($destination))
  242.         {
  243.             echo "la cible existe, ca ne va pas �tre possible";
  244.             return 0;
  245.         }
  246.         */
  247.     mkpath($destination0770);
  248.     if ($verbose)
  249.         echo "
  250.                         <strong>
  251.                             [".basename($destination)."]
  252.                         </strong>
  253.                         <OL>";
  254.     $total 0;
  255.     while ($fichier readdir($dossier))
  256.     {
  257.         $l array ('.''..');
  258.         if (!in_array($fichier$l))
  259.         {
  260.             if (is_dir($origine."/".$fichier))
  261.             {
  262.                 if ($verbose)
  263.                     echo "
  264.                                                     <LI>";
  265.                 $total += copydir("$origine/$fichier""$destination/$fichier"$verbose);
  266.             }
  267.             else
  268.             {
  269.                 copy("$origine/$fichier""$destination/$fichier");
  270.                 if ($verbose)
  271.                     echo "
  272.                                                     <LI>
  273.                                                         $fichier";
  274.                 $total ++;
  275.             }
  276.             if ($verbose)
  277.                 echo "
  278.                                             </LI>";
  279.         }
  280.     }
  281.     if ($verbose)
  282.         echo "
  283.                         </OL>";
  284.     return $total;
  285. }
  286. /**
  287.  * Export a course to a zip file
  288.  *
  289.  * @param integer    $currentCourseID    needed        sysId Of course to be exported
  290.  * @param boolean     $verbose_backup        def FALSE    echo  step of work
  291.  * @param string    $ignore                def NONE     // future param  for selected bloc to export.
  292.  * @param string    $formats            def ALL        ALL,SQL,PHP,XML,CSV,XLS,HTML
  293.  *
  294.  * @deprecated Function not in use (old backup system)
  295.  *
  296.  *  1� Check if all data needed are aivailable
  297.  *  2� Build the archive repository tree
  298.  *  3� Build exported element and Fill  the archive repository tree
  299.  *  4� Compress the tree
  300. == tree structure ==                == here we can found ==
  301. /archivePath/                        temporary files of export for the current claroline
  302.     /$exportedCourseId                temporary files of export for the current course
  303.         /$dateBackuping/            root of the future archive
  304.             archive.ini                course properties
  305.             readme.txt
  306.             /originalDocs
  307.             /html
  308.             /sql
  309.             /csv
  310.             /xml
  311.             /php
  312.             ;
  313.  
  314.             about "ignore"
  315.              As  we don't know what is  add in course  by the local admin  of  claroline,
  316.              I  prefer follow the  logic : save all except ...
  317.  
  318.  
  319.  */
  320. function makeTheBackup($exportedCourseId$verbose_backup FALSE$ignore ""$formats "ALL")
  321. {
  322.         global $error_msg$error_no$db$archiveRepositorySys$archiveRepositoryWeb,
  323.                 $appendCourse$appendMainDb$archiveName$_configuration$_course$TABLEUSER$TABLECOURSUSER$TABLECOURS$TABLEANNOUNCEMENT;
  324.  
  325.     // ****** 1� 2. params.
  326.     $errorCode 0;
  327.     $stop FALSE;
  328.  
  329.     // ****** 1� 2. 1 params.needed
  330.     if (!isset ($exportedCourseId))
  331.     {
  332.         $error_msg["backup"]["[".basename(__FILE__)."][".__LINE__."] Course Id Missing";
  333.         $error_no["backup"]["1";
  334.         $stop TRUE;
  335.     }
  336.     if (!isset ($_configuration['main_database']))
  337.     {
  338.         $error_msg["backup"]["[".basename(__FILE__)."][".__LINE__."] Main Db name is Missing";
  339.         $error_no["backup"]["2";
  340.         $stop TRUE;
  341.     }
  342.     if (!isset ($archiveRepositorySys))
  343.     {
  344.         $error_msg["backup"]["[".basename(__FILE__)."][".__LINE__."] archive Path not found";
  345.         $error_no["backup"]["3";
  346.         $stop TRUE;
  347.     }
  348.     if (!isset ($appendMainDb))
  349.     {
  350.         $error_msg["backup"]["[".basename(__FILE__)."][".__LINE__."] where place course datas from main db in archive";
  351.         $error_no["backup"]["4";
  352.         $stop TRUE;
  353.     }
  354.     if (!isset ($appendCourse))
  355.     {
  356.         $error_msg["backup"]["[".basename(__FILE__)."][".__LINE__."] where place course datas in archive";
  357.         $error_no["backup"]["5";
  358.         $stop TRUE;
  359.     }
  360.     if (!isset ($TABLECOURS))
  361.     {
  362.         $error_msg["backup"]["[".basename(__FILE__)."][".__LINE__."] name of table of course not defined";
  363.         $error_no["backup"]["6";
  364.         $stop TRUE;
  365.     }
  366.     if (!isset ($TABLEUSER))
  367.     {
  368.         $error_msg["backup"]["[".basename(__FILE__)."][".__LINE__."] name of table of users not defined";
  369.         $error_no["backup"]["7";
  370.         $stop TRUE;
  371.     }
  372.     if (!isset ($TABLECOURSUSER))
  373.     {
  374.         $error_msg["backup"]["[".basename(__FILE__)."][".__LINE__."] name of table of subscription of users in courses not defined";
  375.         $error_no["backup"]["8";
  376.         $stop TRUE;
  377.     }
  378.     if ($stop)
  379.     {
  380.         return false;
  381.     }
  382.  
  383.     // ****** 1� 2. 2 params.optional
  384.     if (!isset ($verbose_backup))
  385.     {
  386.         $verbose_backup false;
  387.     }
  388.  
  389.     // ****** 1� 3. check if course exist
  390.     //  not  done
  391.     //////////////////////////////////////////////
  392.     // ****** 2� Build the archive repository tree
  393.     // ****** 2� 1. fix names
  394.     $shortDateBackuping date("YzBs")// YEAR - Day in Year - Swatch - second
  395.     $archiveFileName "archive.".$exportedCourseId.".".$shortDateBackuping.".zip";
  396.     $dateBackuping $shortDateBackuping;
  397.     $archiveDir .= $archiveRepositorySys.$exportedCourseId."/".$shortDateBackuping."/";
  398.     $archiveDirOriginalDocs $archiveDir."originalDocs/";
  399.     $archiveDirHtml $archiveDir."HTML/";
  400.     $archiveDirCsv $archiveDir."CSV/";
  401.     $archiveDirXml $archiveDir."XML/";
  402.     $archiveDirPhp $archiveDir."PHP/";
  403.     $archiveDirLog $archiveDir."LOG/";
  404.     $archiveDirSql $archiveDir."SQL/";
  405.     $systemFileNameOfArchive "claroBak-".$exportedCourseId."-".$dateBackuping.".txt";
  406.     $systemFileNameOfArchiveIni "archive.ini";
  407.     $systemFileNameOfReadMe "readme.txt";
  408.     $systemFileNameOfarchiveLog "readme.txt";
  409.     ###################
  410.     if ($verbose_backup)
  411.     {
  412.         echo "<hr><u>"get_lang('ArchiveName')"</u> : ""<strong>"basename($systemFileNameOfArchive)"</strong><br><u>"get_lang('ArchiveLocation')"</u> : ""<strong>"realpath($systemFileNameOfArchive)"</strong><br><u>"get_lang('SizeOf')" "realpath("../../".$exportedCourseId."/")"</u> : ""<strong>"DirSize("../../".$exportedCourseId."/")"</strong> bytes <br>";
  413.         if (function_exists(diskfreespace))
  414.             echo "<u>".get_lang('DiskFreeSpace')."</u> : <strong>".diskfreespace("/")."</strong> bytes";
  415.         echo "<hr />";
  416.     }
  417.     mkpath($archiveDirOriginalDocs.$appendMainDb$verbose_backup);
  418.     mkpath($archiveDirHtml.$appendMainDb$verbose_backup);
  419.     mkpath($archiveDirCsv.$appendMainDb$verbose_backup);
  420.     mkpath($archiveDirXml.$appendMainDb$verbose_backup);
  421.     mkpath($archiveDirPhp.$appendMainDb$verbose_backup);
  422.     mkpath($archiveDirLog.$appendMainDb$verbose_backup);
  423.     mkpath($archiveDirSql.$appendMainDb$verbose_backup);
  424.     mkpath($archiveDirOriginalDocs.$appendCourse$verbose_backup);
  425.     mkpath($archiveDirHtml.$appendCourse$verbose_backup);
  426.     mkpath($archiveDirCsv.$appendCourse$verbose_backup);
  427.     mkpath($archiveDirXml.$appendCourse$verbose_backup);
  428.     mkpath($archiveDirPhp.$appendCourse$verbose_backup);
  429.     mkpath($archiveDirLog.$appendCourse$verbose_backup);
  430.     mkpath($archiveDirSql.$appendCourse$verbose_backup);
  431.     $dirCourBase $archiveDirSqlCourse;
  432.     $dirMainBase $archiveDirSqlMainDb;
  433.     /////////////////////////////////////////////////////////////////////////
  434.     // ****** 3� Build exported element and Fill  the archive repository tree
  435.     if ($verbose_backup)
  436.         echo "
  437.                 build config file
  438.                 <hr>";
  439.     // ********************************************************************
  440.     // build config file
  441.     // ********************************************************************
  442.     $stringConfig "<?php
  443.         /*
  444.               +----------------------------------------------------------------------+
  445.               Dokeos version ".$dokeos_version."
  446.               +----------------------------------------------------------------------+
  447.               This file was generate by script ".api_get_self()."
  448.               ".date("r")."                  |
  449.               +----------------------------------------------------------------------+
  450.               |   This program is free software; you can redistribute it and/or      |
  451.               |   modify it under the terms of the GNU General Public License        |
  452.               |   as published by the Free Software Foundation; either version 2     |
  453.         */
  454.  
  455.         // Dokeos Version was :  ".$dokeos_version."
  456.         // Source was  in ".realpath("../../".$exportedCourseId."/")."
  457.         // find in ".$archiveDir."/courseBase/courseBase.sql sql to rebuild the course base
  458.         // find in ".$archiveDir."/".$exportedCourseId." to content of directory of course
  459.  
  460.         /**
  461.          * options
  462.          ";
  463.     $stringConfig .= "
  464.          */";
  465.     // ********************************************************************
  466.     // Copy of  from DB main
  467.     // fields about this course
  468.     // ********************************************************************
  469.     //  info  about cours
  470.     // ********************************************************************
  471.     if ($verbose_backup)
  472.         echo "
  473.                 <LI>
  474.                 ".get_lang('BUCourseDataOfMainBase')."  ".$exportedCourseId."
  475.                 <HR>
  476.                 <PRE>";
  477.     $sqlInsertCourse "
  478.         INSERT INTO course SET ";
  479.     $csvInsertCourse "\n";
  480.     $iniCourse "[".$exportedCourseId."]\n";
  481.     $sqlSelectInfoCourse "Select * from `".$TABLECOURS."` `course` where code = '".$exportedCourseId."' ";
  482.     $resInfoCourse api_sql_query($sqlSelectInfoCourse__FILE____LINE__);
  483.     $infoCourse Database::fetch_array($resInfoCourse);
  484.     for ($noField 0$noField mysql_num_fields($resInfoCourse)$noField ++)
  485.     {
  486.         if ($noField 0)
  487.             $sqlInsertCourse .= ", ";
  488.         $nameField mysql_field_name($resInfoCourse$noField);
  489.         /*echo "
  490.         <BR>
  491.         $nameField ->  ".$infoCourse["$nameField"]." ";
  492.         */
  493.         $sqlInsertCourse .= "$nameField = '".$infoCourse["$nameField"]."'";
  494.         $csvInsertCourse .= "'".addslashes($infoCourse["$nameField"])."';";
  495.     }
  496.     //     buildTheIniFile
  497.     $iniCourse .= "name=".strtr($infoCourse['title']"()""[]")."\n"."official_code=".strtr($infoCourse['visual_code']"()""[]")."\n".// use in echo
  498.     "adminCode=".strtr($infoCourse['code']"()""[]")."\n".// use as key in db
  499.     "path=".strtr($infoCourse['code']"()""[]")."\n".// use as key in path
  500.     "dbName=".strtr($infoCourse['code']"()""[]")."\n".// use as key in db list
  501.     "titular=".strtr($infoCourse['titulaire']"()""[]")."\n"."language=".strtr($infoCourse['language']"()""[]")."\n"."extLinkUrl=".strtr($infoCourse['departementUrl']"()""[]")."\n"."extLinkName=".strtr($infoCourse['departementName']"()""[]")."\n"."categoryCode=".strtr($infoCourse['faCode']"()""[]")."\n"."categoryName=".strtr($infoCourse['faName']"()""[]")."\n"."visibility="($infoCourse['visibility'== || $infoCourse['visibility'== 3)."registrationAllowed="($infoCourse['visibility'== || $infoCourse['visibility'== 2);
  502.     $sqlInsertCourse .= ";";
  503.     //    echo $csvInsertCourse."<BR>";
  504.     $stringConfig .= "
  505.         # Insert Course
  506.         #------------------------
  507.         #    ".$sqlInsertCourse."
  508.         #------------------------
  509.             ";
  510.     if ($verbose_backup)
  511.     {
  512.         echo "</PRE>";
  513.     }
  514.     $fcoursql fopen($archiveDirSql.$appendMainDb."course.sql""w");
  515.     fwrite($fcoursql$sqlInsertCourse);
  516.     fclose($fcoursql);
  517.     $fcourcsv fopen($archiveDirCsv.$appendMainDb."course.csv""w");
  518.     fwrite($fcourcsv$csvInsertCourse);
  519.     fclose($fcourcsv);
  520.     $fcourini fopen($archiveDir.$systemFileNameOfArchiveIni"w");
  521.     fwrite($fcourini$iniCourse);
  522.     fclose($fcourini);
  523.     echo $iniCourse" ini Course";
  524.     // ********************************************************************
  525.     //  info  about users
  526.     // ********************************************************************
  527.     //    if ($backupUser )
  528.     {
  529.         if ($verbose_backup)
  530.             echo "
  531.                                 <LI>
  532.                                     ".get_lang('BUUsersInMainBase')." ".$exportedCourseId."
  533.                                     <hR>
  534.                                 <PRE>";
  535.         // recup users
  536.         $sqlUserOfTheCourse "
  537.                     SELECT
  538.                         `user`.*
  539.                         FROM `".$TABLEUSER."`, `".$TABLECOURSUSER."`
  540.                         WHERE `user`.`user_id`=`".$TABLECOURSUSER."`.`user_id`
  541.                             AND `".$TABLECOURSUSER."`.`course_code`='".$exportedCourseId."'";
  542.         $resUsers api_sql_query($sqlUserOfTheCourse__FILE____LINE__);
  543.         $nbUsers Database::num_rows($resUsers);
  544.         if ($nbUsers 0)
  545.         {
  546.             $nbFields mysql_num_fields($resUsers);
  547.             $sqlInsertUsers "";
  548.             $csvInsertUsers "";
  549.             $htmlInsertUsers "<table>\t<TR>\n";
  550.             //
  551.             // creation of headers
  552.             //
  553.             for ($noField 0$noField $nbFields$noField ++)
  554.             {
  555.                 $nameField mysql_field_name($resUsers$noField);
  556.                 $csvInsertUsers .= "'".addslashes($nameField)."';";
  557.                 $htmlInsertUsers .= "\t\t<TH>".$nameField."</TH>\n";
  558.             }
  559.             $htmlInsertUsers .= "\t</TR>\n";
  560.             //
  561.             // creation of body
  562.             //
  563.             while ($users Database::fetch_array($resUsers))
  564.             {
  565.                 $htmlInsertUsers .= "\t<TR>\n";
  566.                 $sqlInsertUsers .= "
  567.                                         INSERT IGNORE INTO user SET ";
  568.                 $csvInsertUsers .= "\n";
  569.                 for ($noField 0$noField $nbFields$noField ++)
  570.                 {
  571.                     if ($noField 0)
  572.                         $sqlInsertUsers .= ", ";
  573.                     $nameField mysql_field_name($resUsers$noField);
  574.                     /*echo "
  575.                         <BR>
  576.                         $nameField ->  ".$users["$nameField"]." ";
  577.                     */
  578.                     $sqlInsertUsers .= "$nameField = '".$users["$nameField"]."' ";
  579.                     $csvInsertUsers .= "'".addslashes($users["$nameField"])."';";
  580.                     $htmlInsertUsers .= "\t\t<TD>".$users["$nameField"]."</TD>\n";
  581.                 }
  582.                 $sqlInsertUsers .= ";";
  583.                 $htmlInsertUsers .= "\t</TR>\n";
  584.             }
  585.             $htmlInsertUsers .= "</TABLE>\n";
  586.             $stringConfig .= "
  587.                             # INSERT Users
  588.                             #------------------------------------------
  589.                             #    ".$sqlInsertUsers."
  590.                             #------------------------------------------
  591.                                 ";
  592.             $fuserssql fopen($archiveDirSql.$appendMainDb."users.sql""w");
  593.             fwrite($fuserssql$sqlInsertUsers);
  594.             fclose($fuserssql);
  595.             $fuserscsv fopen($archiveDirCsv.$appendMainDb."users.csv""w");
  596.             fwrite($fuserscsv$csvInsertUsers);
  597.             fclose($fuserscsv);
  598.             $fusershtml fopen($archiveDirHtml.$appendMainDb."users.html""w");
  599.             fwrite($fusershtml$htmlInsertUsers);
  600.             fclose($fusershtml);
  601.         }
  602.         else
  603.         {
  604.             if ($verbose_backup)
  605.             {
  606.                 echo "<HR><div align=\"center\">NO user in this course !!!!</div><HR>";
  607.             }
  608.         }
  609.         if ($verbose_backup)
  610.         {
  611.             echo "</PRE>";
  612.         }
  613.     }
  614.     /*  End  of  backup user */
  615.     if ($saveAnnouncement)
  616.     {
  617.         // ********************************************************************
  618.         //  info  about announcment
  619.         // ********************************************************************
  620.         if ($verbose_backup)
  621.         {
  622.             echo "
  623.                             <LI>
  624.                                 ".get_lang('BUAnnounceInMainBase')." ".$exportedCourseId."
  625.                                 <hR>
  626.                             <PRE>";
  627.         }
  628.         // recup annonce
  629.         $sqlAnnounceOfTheCourse "
  630.                 SELECT
  631.                     *
  632.                     FROM  `".$TABLEANNOUNCEMENT."`
  633.                     WHERE course_code='".$exportedCourseId."'";
  634.         $resAnn api_sql_query($sqlAnnounceOfTheCourse__FILE____LINE__);
  635.         $nbFields mysql_num_fields($resAnn);
  636.         $sqlInsertAnn "";
  637.         $csvInsertAnn "";
  638.         $htmlInsertAnn .= "<table>\t<TR>\n";
  639.         //
  640.         // creation of headers
  641.         //
  642.         for ($noField 0$noField $nbFields$noField ++)
  643.         {
  644.             $nameField mysql_field_name($resUsers$noField);
  645.             $csvInsertAnn .= "'".addslashes($nameField)."';";
  646.             $htmlInsertAnn .= "\t\t<TH>".$nameField."</TH>\n";
  647.         }
  648.         $htmlInsertAnn .= "\t</TR>\n";
  649.         //
  650.         // creation of body
  651.         //
  652.         while ($announce Database::fetch_array($resAnn))
  653.         {
  654.             $htmlInsertAnn .= "\t<TR>\n";
  655.             $sqlInsertAnn .= "
  656.                         INSERT INTO users SET ";
  657.             $csvInsertAnn .= "\n";
  658.             for ($noField 0$noField $nbFields$noField ++)
  659.             {
  660.                 if ($noField 0)
  661.                     $sqlInsertAnn .= ", ";
  662.                 $nameField mysql_field_name($resAnn$noField);
  663.                 /*echo "
  664.                 <BR>
  665.                 $nameField ->  ".$users["$nameField"]." ";
  666.                 */
  667.                 $sqlInsertAnn .= "$nameField = '".addslashes($announce["$nameField"])."' ";
  668.                 $csvInsertAnn .= "'".addslashes($announce["$nameField"])."';";
  669.                 $htmlInsertAnn .= "\t\t<TD>".$announce["$nameField"]."</TD>\n";
  670.             }
  671.             $sqlInsertAnn .= ";";
  672.             $htmlInsertAnn .= "\t</TR>\n";
  673.         }
  674.         if ($verbose_backup)
  675.         {
  676.             echo "</PRE>";
  677.         }
  678.         $htmlInsertAnn .= "</TABLE>\n";
  679.         $stringConfig .= "
  680.                 #INSERT ANNOUNCE
  681.                 #------------------------------------------
  682.                 #    ".$sqlInsertAnn."
  683.                 #------------------------------------------
  684.                     ";
  685.         $fannsql fopen($archiveDirSql.$appendMainDb."annonces.sql""w");
  686.         fwrite($fannsql$sqlInsertAnn);
  687.         fclose($fannsql);
  688.         $fanncsv fopen($archiveDirCsv.$appendMainDb."annnonces.csv""w");
  689.         fwrite($fanncsv$csvInsertAnn);
  690.         fclose($fanncsv);
  691.         $fannhtml fopen($archiveDirHtml.$appendMainDb."annonces.html""w");
  692.         fwrite($fannhtml$htmlInsertAnn);
  693.         fclose($fannhtml);
  694.         /*  End  of  backup Annonces */
  695.     }
  696.     // we can copy file of course
  697.     if ($verbose_backup)
  698.     {
  699.         echo '<li>'.get_lang('CopyDirectoryCourse');
  700.     }
  701.     $nbFiles copydir(api_get_path(SYS_COURSE_PATH).$_course['path']$archiveDirOriginalDocs.$appendCourse$verbose_backup);
  702.     if ($verbose_backup)
  703.         echo "
  704.                             <strong>
  705.                                 ".$nbFiles."
  706.                             </strong>
  707.                             ".get_lang('FileCopied')."
  708.                             <br>
  709.                         </li>";
  710.     $stringConfig .= "
  711.         // ".$nbFiles." was in ".realpath($archiveDirOriginalDocs);
  712.     // ********************************************************************
  713.     // Copy of  DB course
  714.     // with mysqldump
  715.     // ********************************************************************
  716.     if ($verbose_backup)
  717.         echo "
  718.                         <LI>
  719.                             ".get_lang('BackupOfDataBase')." ".$exportedCourseId."  (SQL)
  720.                             <hr>";
  721.     backupDatabase($db$exportedCourseIdtruetrue'SQL'$archiveDirSql.$appendCoursetrue$verbose_backup);
  722.     if ($verbose_backup)
  723.         echo "
  724.                         </LI>
  725.                         <LI>
  726.                             ".get_lang('BackupOfDataBase')." ".$exportedCourseId."  (PHP)
  727.                             <hr>";
  728.     backupDatabase($db$exportedCourseIdtruetrue'PHP'$archiveDirPhp.$appendCoursetrue$verbose_backup);
  729.     if ($verbose_backup)
  730.         echo "
  731.                         </LI>
  732.                         <LI>
  733.                             ".get_lang('BackupOfDataBase')." ".$exportedCourseId."  (CSV)
  734.                             <hr>";
  735.     backupDatabase($db$exportedCourseIdtruetrue'CSV'$archiveDirCsv.$appendCoursetrue$verbose_backup);
  736.     if ($verbose_backup)
  737.         echo "
  738.                         <LI>
  739.                             ".get_lang('BackupOfDataBase')." ".$exportedCourseId."  (HTML)
  740.                             <hr>";
  741.     backupDatabase($db$exportedCourseIdtruetrue'HTML'$archiveDirHtml.$appendCoursetrue$verbose_backup);
  742.     if ($verbose_backup)
  743.         echo "
  744.                         <LI>
  745.                             ".get_lang('BackupOfDataBase')." ".$exportedCourseId."  (XML)
  746.                             <hr>";
  747.     backupDatabase($db$exportedCourseIdtruetrue'XML'$archiveDirXml.$appendCoursetrue$verbose_backup);
  748.     if ($verbose_backup)
  749.         echo "
  750.                         <LI>
  751.                             ".get_lang('BackupOfDataBase')." ".$exportedCourseId."  (LOG)
  752.                             <hr>";
  753.     backupDatabase($db$exportedCourseIdtruetrue'LOG'$archiveDirLog.$appendCoursetrue$verbose_backup);
  754.     // ********************************************************************
  755.     // Copy of DB course
  756.     // with mysqldump
  757.     // ********************************************************************
  758.     $fdesc fopen($archiveDir.$systemFileNameOfArchive"w");
  759.     fwrite($fdesc$stringConfig);
  760.     fclose($fdesc);
  761.     if ($verbose_backup)
  762.         echo "
  763.                         </LI>
  764.                     </OL>
  765.  
  766.                     <br>";
  767.     ///////////////////////////////////
  768.     // ****** 4� Compress the tree
  769.     if (extension_loaded("zlib"))
  770.     {
  771.         $whatZip[$archiveRepositorySys.$exportedCourseId."/".$shortDateBackuping."/HTML";
  772.         $forgetPath $archiveRepositorySys.$exportedCourseId."/".$shortDateBackuping."/";
  773.         $prefixPath $exportedCourseId;
  774.         $zipCourse new PclZip($archiveRepositorySys.$archiveFileName);
  775.         $zipRes $zipCourse->create($whatZipPCLZIP_OPT_ADD_PATH$prefixPathPCLZIP_OPT_REMOVE_PATH$forgetPath);
  776.         if ($zipRes == 0)
  777.         {
  778.             echo "<font size=\"+1\" color=\"#FF0000\">"$zipCourse->errorInfo(true)"</font>";
  779.         }
  780.         else
  781.             for ($i 0$i sizeof($zipRes)$i ++)
  782.             {
  783.                 for (reset($zipRes[$i])$key key($zipRes[$i])next($zipRes[$i]))
  784.                 {
  785.                     echo "File $i / [$key] = ".$list[$i][$key]."<br>";
  786.                 }
  787.                 echo "<br>";
  788.             }
  789.         $pathToArchive $archiveRepositoryWeb.$archiveFileName;
  790.         if ($verbose_backup)
  791.         {
  792.             echo '<hr>'.get_lang('BuildTheCompressedFile');
  793.         }
  794.         //        removeDir($archivePath);
  795.     }
  796.     return 1;
  797. // function makeTheBackup()
  798. ?>

Documentation generated on Thu, 12 Jun 2008 13:27:47 -0500 by phpDocumentor 1.4.1