From fe2512d5ce82ad18ce3125f6a2387e849b464da9 Mon Sep 17 00:00:00 2001 From: Ivan Tcholakov Date: Tue, 6 Oct 2009 18:52:15 +0300 Subject: [PATCH] Feature #306 - export.lib.php: Cleaning code, removing non-UTF characters. --- main/inc/lib/export.lib.inc.php | 597 +++++++++++++++----------------- 1 file changed, 288 insertions(+), 309 deletions(-) diff --git a/main/inc/lib/export.lib.inc.php b/main/inc/lib/export.lib.inc.php index e448a49514..3afce110ae 100755 --- a/main/inc/lib/export.lib.inc.php +++ b/main/inc/lib/export.lib.inc.php @@ -22,21 +22,26 @@ Contact address: Dokeos, rue du Corbeau, 108, B-1030 Brussels, Belgium, info@dokeos.com ============================================================================== */ + /** ============================================================================== * This is the export library for Dokeos. * Include/require it in your code to use its functionality. * -* plusieures fonctions ci-dessous ont �t� adapt�es de fonctions distribu�es par www.nexen.net +* Several functions below are adaptations from functions distributed by www.nexen.net * * @package dokeos.library ============================================================================== */ -require_once ('document.lib.php'); + +require_once 'document.lib.php'; + class Export { + private function __construct() { } + /** * Export tabular data to CSV-file * @param array $data @@ -46,16 +51,12 @@ class Export { $file = api_get_path(SYS_ARCHIVE_PATH).uniqid('').'.csv'; $handle = @fopen($file, 'a+'); - if(is_array($data)) - { - foreach ($data as $index => $row) - { - $line=''; - if(is_array($row)) - { - foreach($row as $value) - { - $line .= '"'.str_replace('"','""',$value).'";'; + if(is_array($data)) { + foreach ($data as $index => $row) { + $line = ''; + if(is_array($row)) { + foreach($row as $value) { + $line .= '"'.str_replace('"', '""', $value).'";'; } } @fwrite($handle, $line."\n"); @@ -65,6 +66,7 @@ class Export { DocumentManager :: file_send_for_download($file, true, $filename.'.csv'); exit(); } + /** * Export tabular data to XLS-file * @param array $data @@ -73,14 +75,14 @@ class Export { public static function export_table_xls ($data, $filename = 'export') { $file = api_get_path(SYS_ARCHIVE_PATH).uniqid('').'.xls'; $handle = @fopen($file, 'a+'); - foreach ($data as $index => $row) - { + foreach ($data as $index => $row) { @fwrite($handle, implode("\t", $row)."\n"); } @fclose($handle); DocumentManager :: file_send_for_download($file, true, $filename.'.xls'); exit(); } + /** * Export tabular data to XML-file * @param array Simple array of data to put in XML @@ -89,29 +91,24 @@ class Export { * @param string Name of the root element. A root element should always be given. * @param string Encoding in which the data is provided */ - public static function export_table_xml ($data, $filename = 'export', $item_tagname = 'item', $wrapper_tagname = null, $encoding=null) { - if (empty($encoding)) - { + public static function export_table_xml ($data, $filename = 'export', $item_tagname = 'item', $wrapper_tagname = null, $encoding = null) { + if (empty($encoding)) { $encoding = api_get_system_encoding(); } $file = api_get_path(SYS_ARCHIVE_PATH).'/'.uniqid('').'.xml'; $handle = fopen($file, 'a+'); fwrite($handle, ''."\n"); - if (!is_null($wrapper_tagname)) - { + if (!is_null($wrapper_tagname)) { fwrite($handle, "\t".'<'.$wrapper_tagname.'>'."\n"); } - foreach ($data as $index => $row) - { + foreach ($data as $index => $row) { fwrite($handle, '<'.$item_tagname.'>'."\n"); - foreach ($row as $key => $value) - { + foreach ($row as $key => $value) { fwrite($handle, "\t\t".'<'.$key.'>'.$value.''."\n"); } fwrite($handle, "\t".''."\n"); } - if (!is_null($wrapper_tagname)) - { + if (!is_null($wrapper_tagname)) { fwrite($handle, ''."\n"); } fclose($handle); @@ -128,36 +125,34 @@ class Export { * @param string Encoding in which the data is provided * @return void Prompts the user for a file download */ - public static function export_complex_table_xml ($data, $filename = 'export', $wrapper_tagname, $encoding='ISO-8859-1') { + public static function export_complex_table_xml ($data, $filename = 'export', $wrapper_tagname, $encoding = 'ISO-8859-1') { $file = api_get_path(SYS_ARCHIVE_PATH).'/'.uniqid('').'.xml'; $handle = fopen($file, 'a+'); fwrite($handle, ''."\n"); - if (!is_null($wrapper_tagname)) - { + if (!is_null($wrapper_tagname)) { fwrite($handle, '<'.$wrapper_tagname.'>'); } $s = self::_export_complex_table_xml_helper($data); fwrite($handle,$s); - if (!is_null($wrapper_tagname)) - { + if (!is_null($wrapper_tagname)) { fwrite($handle, ''."\n"); } fclose($handle); DocumentManager :: file_send_for_download($file, true, $filename.'.xml'); exit; } + /** * Helper for the hierarchical XML exporter * @param array Hierarhical array composed of elements of type ('name'=>'xyz','value'=>'...') * @param int Level of recursivity. Allows the XML to be finely presented * @return string The XML string to be inserted into the root element */ - public static function _export_complex_table_xml_helper ($data,$level=1) { + public static function _export_complex_table_xml_helper ($data, $level = 1) { if (count($data)<1) { return '';} $string = ''; - foreach ($data as $index => $row) - { + foreach ($data as $index => $row) { $string .= "\n".str_repeat("\t",$level).'<'.$row['name'].'>'; if (is_array($row['value'])) { $string .= self::_export_complex_table_xml_helper($row['value'],$level+1)."\n"; @@ -169,12 +164,15 @@ class Export { } return $string; } + } + /* ============================================================================== FUNCTIONS ============================================================================== */ + /** * Backup a db to a file * @@ -189,157 +187,159 @@ class Export { * @param boolean $verbose true => comment are printed * @deprecated Function only used in deprecated function makeTheBackup(...) */ -function backupDatabase($link, $db_name, $structure, $donnees, $format = 'SQL', $whereSave = '.', $insertComplet = '', $verbose = false) -{ - $errorCode = ""; - if (!is_resource($link)) - { +function backupDatabase($link, $db_name, $structure, $donnees, $format = 'SQL', $whereSave = '.', $insertComplet = '', $verbose = false) { + $errorCode = ''; + if (!is_resource($link)) { global $error_msg, $error_no; - $error_msg["backup"][] = "[".basename(__FILE__)."][".__LINE__."] link is not a ressource"; - $error_no["backup"][] = "1"; + $error_msg['backup'][] = '['.basename(__FILE__).']['.__LINE__.'] link is not a ressource'; + $error_no['backup'][] = '1'; return false; } mysql_select_db($db_name); $format = strtolower($format); - $filename = $whereSave."/courseDbContent.".$format; + $filename = $whereSave.'/courseDbContent.'.$format; $format = strtoupper($format); - $fp = fopen($filename, "w"); - if (!is_resource($fp)) + $fp = fopen($filename, 'w'); + if (!is_resource($fp)) { return false; + } // liste des tables $res = mysql_list_tables($db_name, $link); $num_rows = Database::num_rows($res); $i = 0; - while ($i < $num_rows) - { + while ($i < $num_rows) { $tablename = mysql_tablename($res, $i); - if ($format == "PHP") + if ($format == 'PHP') { fwrite($fp, "\nmysql_query(\""); - if ($format == "HTML") + } + if ($format == 'HTML') { fwrite($fp, "\n

$tablename

"); - if ($verbose) - echo "[".$tablename."] "; - if ($structure === true) - { - if ($format == "PHP" || $format == "SQL") + } + if ($verbose) { + echo '['.$tablename.'] '; + } + if ($structure === true) { + if ($format == 'PHP' || $format == 'SQL') { fwrite($fp, "DROP TABLE IF EXISTS `$tablename`;"); - if ($format == "PHP") + } + if ($format == 'PHP') { fwrite($fp, "\");\n"); - if ($format == "PHP") + } + if ($format == 'PHP') { fwrite($fp, "\nmysql_query(\""); + } // requete de creation de la table $query = "SHOW CREATE TABLE `".$tablename."`"; $resCreate = Database::query($query,__FILE__, __LINE__); $row = Database::fetch_array($resCreate); - $schema = $row[1].";"; - if ($format == "PHP" || $format == "SQL") + $schema = $row[1].';'; + if ($format == 'PHP' || $format == 'SQL') { fwrite($fp, "$schema"); - if ($format == "PHP") + } + if ($format == 'PHP') { fwrite($fp, "\");\n\n"); + } } - if ($donnees === true) - { + if ($donnees === true) { // les donn�es de la table $query = "SELECT * FROM $tablename"; $resData = Database::query($query,__FILE__, __LINE__); - if (Database::num_rows($resData) > 0) - { - $sFieldnames = ""; - if ($insertComplet === true) - { + if (Database::num_rows($resData) > 0) { + $sFieldnames = ''; + if ($insertComplet === true) { $num_fields = mysql_num_fields($resData); - for ($j = 0; $j < $num_fields; $j ++) - { + for ($j = 0; $j < $num_fields; $j ++) { $sFieldnames .= "`".mysql_field_name($resData, $j)."`, "; } - $sFieldnames = "(".substr($sFieldnames, 0, -2).")"; + $sFieldnames = '('.substr($sFieldnames, 0, -2).')'; } $sInsert = "INSERT INTO `$tablename` $sFieldnames values "; - while ($rowdata = Database::fetch_array($resData,'ASSOC')) - { - if ($format == "HTML") - { + while ($rowdata = Database::fetch_array($resData, 'ASSOC')) { + if ($format == 'HTML') { $lesDonnees = "\n\t\n\t\t\n\t\t"; } - if ($format == "SQL" || $format == "PHP") - { - $lesDonnees = "".implode(",", $rowdata).""; - $lesDonnees = str_replace("", "'", addslashes($lesDonnees)); - if ($format == "SQL") - { - $lesDonnees = $sInsert." ( ".$lesDonnees." );"; + if ($format == 'SQL' || $format == 'PHP') { + $lesDonnees = ''.implode(',', $rowdata).''; + $lesDonnees = str_replace('', "'", addslashes($lesDonnees)); + if ($format == 'SQL') { + $lesDonnees = $sInsert.' ( '.$lesDonnees.' );'; } - if ($format == "PHP") + if ($format == 'PHP') { fwrite($fp, "\nmysql_query(\""); + } } fwrite($fp, "$lesDonnees"); - if ($format == "PHP") + if ($format == 'PHP') { fwrite($fp, "\");\n"); + } } } } $i ++; - if ($format == "HTML") + if ($format == 'HTML') { fwrite($fp, "\n
".implode("\n\t\t", $rowdata)."\n\t\t
\n
\n"); + } } - echo "fin du backup au format :".$format; + echo 'fin du backup au format :'.$format; fclose($fp); } + /** * @deprecated use function copyDirTo($origDirPath, $destination) in * fileManagerLib.inc.php */ -function copydir($origine, $destination, $verbose = false) -{ - $dossier = @ opendir($origine) or die("
impossible d'ouvrir ".$origine." [".__LINE__."]"); - if ($verbose) - echo "
$origine -> $destination"; - /* if (file_exists($destination)) - { - echo "la cible existe, ca ne va pas �tre possible"; +function copydir($origine, $destination, $verbose = false) { + $dossier = @ opendir($origine) or die('
impossible d\'ouvrir '.$origine.' ['.__LINE__.']'); + if ($verbose) { + echo "
$origine -> $destination"; + } + /* + if (file_exists($destination)) { + echo "la cible existe, ca ne va pas �tre possible"; return 0; - } - */ + } + */ mkpath($destination, 0770); - if ($verbose) + if ($verbose) { echo " [".basename($destination)."] -
    "; +
      "; + } $total = 0; - while ($fichier = readdir($dossier)) - { + while ($fichier = readdir($dossier)) { $l = array ('.', '..'); - if (!in_array($fichier, $l)) - { - if (is_dir($origine."/".$fichier)) - { - if ($verbose) + if (!in_array($fichier, $l)) { + if (is_dir($origine.'/'.$fichier)) { + if ($verbose) { echo " -
    1. "; +
    2. "; + } $total += copydir("$origine/$fichier", "$destination/$fichier", $verbose); - } - else - { + } else { copy("$origine/$fichier", "$destination/$fichier"); - if ($verbose) + if ($verbose) { echo " -
    3. +
    4. $fichier"; + } $total ++; } - if ($verbose) + if ($verbose) { echo " -
    5. "; + "; + } } } - if ($verbose) + if ($verbose) { echo " -
    "; +
"; + } return $total; } + /** * Export a course to a zip file * @@ -350,10 +350,10 @@ function copydir($origine, $destination, $verbose = false) * * @deprecated Function not in use (old backup system) * - * 1� Check if all data needed are aivailable - * 2� Build the archive repository tree - * 3� Build exported element and Fill the archive repository tree - * 4� Compress the tree + * 1. Check if all data needed are aivailable + * 2. Build the archive repository tree + * 3. Build exported element and Fill the archive repository tree + * 4. Compress the tree == tree structure == == here we can found == /archivePath/ temporary files of export for the current claroline /$exportedCourseId temporary files of export for the current course @@ -374,102 +374,90 @@ function copydir($origine, $destination, $verbose = false) */ -function makeTheBackup($exportedCourseId, $verbose_backup = FALSE, $ignore = "", $formats = "ALL") -{ +function makeTheBackup($exportedCourseId, $verbose_backup = FALSE, $ignore = '', $formats = 'ALL') { global $error_msg, $error_no, $db, $archiveRepositorySys, $archiveRepositoryWeb, $appendCourse, $appendMainDb, $archiveName, $_configuration, $_course, $TABLEUSER, $TABLECOURSUSER, $TABLECOURS, $TABLEANNOUNCEMENT; - // ****** 1� 2. params. + // ****** 1.2. params. $errorCode = 0; $stop = FALSE; - // ****** 1� 2. 1 params.needed - if (!isset ($exportedCourseId)) - { - $error_msg["backup"][] = "[".basename(__FILE__)."][".__LINE__."] Course Id Missing"; - $error_no["backup"][] = "1"; + // ****** 1.2.1. params.needed + if (!isset ($exportedCourseId)) { + $error_msg['backup'][] = '['.basename(__FILE__).']['.__LINE__.'] Course Id Missing'; + $error_no['backup'][] = '1'; $stop = TRUE; } - if (!isset ($_configuration['main_database'])) - { - $error_msg["backup"][] = "[".basename(__FILE__)."][".__LINE__."] Main Db name is Missing"; - $error_no["backup"][] = "2"; + if (!isset ($_configuration['main_database'])) { + $error_msg['backup'][] = '['.basename(__FILE__).']['.__LINE__.'] Main Db name is Missing'; + $error_no['backup'][] = '2'; $stop = TRUE; } - if (!isset ($archiveRepositorySys)) - { - $error_msg["backup"][] = "[".basename(__FILE__)."][".__LINE__."] archive Path not found"; - $error_no["backup"][] = "3"; + if (!isset ($archiveRepositorySys)) { + $error_msg['backup'][] = '['.basename(__FILE__).']['.__LINE__.'] archive Path not found'; + $error_no['backup'][] = '3'; $stop = TRUE; } - if (!isset ($appendMainDb)) - { - $error_msg["backup"][] = "[".basename(__FILE__)."][".__LINE__."] where place course datas from main db in archive"; - $error_no["backup"][] = "4"; + if (!isset ($appendMainDb)) { + $error_msg['backup'][] = '['.basename(__FILE__).']['.__LINE__.'] where place course datas from main db in archive'; + $error_no['backup'][] = '4'; $stop = TRUE; } - if (!isset ($appendCourse)) - { - $error_msg["backup"][] = "[".basename(__FILE__)."][".__LINE__."] where place course datas in archive"; - $error_no["backup"][] = "5"; + if (!isset ($appendCourse)) { + $error_msg['backup'][] = '['.basename(__FILE__).']['.__LINE__.'] where place course datas in archive'; + $error_no['backup'][] = '5'; $stop = TRUE; } - if (!isset ($TABLECOURS)) - { - $error_msg["backup"][] = "[".basename(__FILE__)."][".__LINE__."] name of table of course not defined"; - $error_no["backup"][] = "6"; + if (!isset ($TABLECOURS)) { + $error_msg['backup'][] = '['.basename(__FILE__).']['.__LINE__.'] name of table of course not defined'; + $error_no['backup'][] = '6'; $stop = TRUE; } - if (!isset ($TABLEUSER)) - { - $error_msg["backup"][] = "[".basename(__FILE__)."][".__LINE__."] name of table of users not defined"; - $error_no["backup"][] = "7"; + if (!isset ($TABLEUSER)) { + $error_msg['backup'][] = '['.basename(__FILE__).']['.__LINE__.'] name of table of users not defined'; + $error_no['backup'][] = '7'; $stop = TRUE; } - if (!isset ($TABLECOURSUSER)) - { - $error_msg["backup"][] = "[".basename(__FILE__)."][".__LINE__."] name of table of subscription of users in courses not defined"; - $error_no["backup"][] = "8"; + if (!isset ($TABLECOURSUSER)) { + $error_msg['backup'][] = '['.basename(__FILE__).']['.__LINE__.'] name of table of subscription of users in courses not defined'; + $error_no['backup'][] = '8'; $stop = TRUE; } - if ($stop) - { + if ($stop) { return false; } - // ****** 1� 2. 2 params.optional - if (!isset ($verbose_backup)) - { + // ****** 1.2.2. params.optional + if (!isset ($verbose_backup)) { $verbose_backup = false; } - // ****** 1� 3. check if course exist + // ****** 1.3. check if course exist // not done ////////////////////////////////////////////// - // ****** 2� Build the archive repository tree - // ****** 2� 1. fix names - $shortDateBackuping = date("YzBs"); // YEAR - Day in Year - Swatch - second - $archiveFileName = "archive.".$exportedCourseId.".".$shortDateBackuping.".zip"; + // ****** 2. Build the archive repository tree + // ****** 2.1. fix names + $shortDateBackuping = date('YzBs'); // YEAR - Day in Year - Swatch - second + $archiveFileName = 'archive.'.$exportedCourseId.'.'.$shortDateBackuping.'.zip'; $dateBackuping = $shortDateBackuping; - $archiveDir .= $archiveRepositorySys.$exportedCourseId."/".$shortDateBackuping."/"; - $archiveDirOriginalDocs = $archiveDir."originalDocs/"; - $archiveDirHtml = $archiveDir."HTML/"; - $archiveDirCsv = $archiveDir."CSV/"; - $archiveDirXml = $archiveDir."XML/"; - $archiveDirPhp = $archiveDir."PHP/"; - $archiveDirLog = $archiveDir."LOG/"; - $archiveDirSql = $archiveDir."SQL/"; - $systemFileNameOfArchive = "claroBak-".$exportedCourseId."-".$dateBackuping.".txt"; - $systemFileNameOfArchiveIni = "archive.ini"; - $systemFileNameOfReadMe = "readme.txt"; - $systemFileNameOfarchiveLog = "readme.txt"; + $archiveDir .= $archiveRepositorySys.$exportedCourseId.'/'.$shortDateBackuping.'/'; + $archiveDirOriginalDocs = $archiveDir.'originalDocs/'; + $archiveDirHtml = $archiveDir.'HTML/'; + $archiveDirCsv = $archiveDir.'CSV/'; + $archiveDirXml = $archiveDir.'XML/'; + $archiveDirPhp = $archiveDir.'PHP/'; + $archiveDirLog = $archiveDir.'LOG/'; + $archiveDirSql = $archiveDir.'SQL/'; + $systemFileNameOfArchive = 'claroBak-'.$exportedCourseId.'-'.$dateBackuping.'.txt'; + $systemFileNameOfArchiveIni = 'archive.ini'; + $systemFileNameOfReadMe = 'readme.txt'; + $systemFileNameOfarchiveLog = 'readme.txt'; ################### - if ($verbose_backup) - { - echo "
", get_lang('ArchiveName'), " : ", "", basename($systemFileNameOfArchive), "
", get_lang('ArchiveLocation'), " : ", "", realpath($systemFileNameOfArchive), "
", get_lang('SizeOf'), " ", realpath("../../".$exportedCourseId."/"), " : ", "", DirSize("../../".$exportedCourseId."/"), " bytes
"; + if ($verbose_backup) { + echo '
', get_lang('ArchiveName'), ' : ', '', basename($systemFileNameOfArchive), '
', get_lang('ArchiveLocation'), ' : ', '', realpath($systemFileNameOfArchive), '
', get_lang('SizeOf'), ' ', realpath('../../'.$exportedCourseId.'/'), ' : ', '', DirSize('../../'.$exportedCourseId.'/'), ' bytes
'; if (function_exists(diskfreespace)) - echo "".get_lang('DiskFreeSpace')." : ".diskfreespace("/")." bytes"; - echo "
"; + echo ''.get_lang('DiskFreeSpace').' : '.diskfreespace('/').' bytes'; + echo '
'; } mkpath($archiveDirOriginalDocs.$appendMainDb, $verbose_backup); mkpath($archiveDirHtml.$appendMainDb, $verbose_backup); @@ -488,11 +476,12 @@ function makeTheBackup($exportedCourseId, $verbose_backup = FALSE, $ignore = "", $dirCourBase = $archiveDirSqlCourse; $dirMainBase = $archiveDirSqlMainDb; ///////////////////////////////////////////////////////////////////////// - // ****** 3� Build exported element and Fill the archive repository tree - if ($verbose_backup) + // ****** 3. Build exported element and Fill the archive repository tree + if ($verbose_backup) { echo " build config file -
"; +
"; + } // ******************************************************************** // build config file // ******************************************************************** @@ -527,10 +516,10 @@ function makeTheBackup($exportedCourseId, $verbose_backup = FALSE, $ignore = "", // ******************************************************************** if ($verbose_backup) echo " -
  • +
  • ".get_lang('BUCourseDataOfMainBase')." ".$exportedCourseId." -
    -
    ";
    +				
    +
    ";
     	$sqlInsertCourse = "
     		INSERT INTO course SET ";
     	$csvInsertCourse = "\n";
    @@ -538,13 +527,13 @@ function makeTheBackup($exportedCourseId, $verbose_backup = FALSE, $ignore = "",
     	$sqlSelectInfoCourse = "Select * from `".$TABLECOURS."` `course` where code = '".$exportedCourseId."' ";
     	$resInfoCourse = Database::query($sqlSelectInfoCourse, __FILE__, __LINE__);
     	$infoCourse = Database::fetch_array($resInfoCourse);
    -	for ($noField = 0; $noField < mysql_num_fields($resInfoCourse); $noField ++)
    -	{
    -		if ($noField > 0)
    +	for ($noField = 0; $noField < mysql_num_fields($resInfoCourse); $noField ++) {
    +		if ($noField > 0) {
     			$sqlInsertCourse .= ", ";
    +		}
     		$nameField = mysql_field_name($resInfoCourse, $noField);
     		/*echo "
    -		
    +
    $nameField -> ".$infoCourse["$nameField"]." "; */ $sqlInsertCourse .= "$nameField = '".$infoCourse["$nameField"]."'"; @@ -557,38 +546,38 @@ function makeTheBackup($exportedCourseId, $verbose_backup = FALSE, $ignore = "", "dbName=".strtr($infoCourse['code'], "()", "[]")."\n".// use as key in db list "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'] == 2 || $infoCourse['visibility'] == 3)."registrationAllowed=". ($infoCourse['visibility'] == 1 || $infoCourse['visibility'] == 2); $sqlInsertCourse .= ";"; - // echo $csvInsertCourse."
    "; + // echo $csvInsertCourse."
    "; $stringConfig .= " # Insert Course #------------------------ # ".$sqlInsertCourse." #------------------------ "; - if ($verbose_backup) - { - echo "
    "; + if ($verbose_backup) { + echo "
    "; } - $fcoursql = fopen($archiveDirSql.$appendMainDb."course.sql", "w"); + $fcoursql = fopen($archiveDirSql.$appendMainDb.'course.sql', 'w'); fwrite($fcoursql, $sqlInsertCourse); fclose($fcoursql); - $fcourcsv = fopen($archiveDirCsv.$appendMainDb."course.csv", "w"); + $fcourcsv = fopen($archiveDirCsv.$appendMainDb.'course.csv', 'w'); fwrite($fcourcsv, $csvInsertCourse); fclose($fcourcsv); - $fcourini = fopen($archiveDir.$systemFileNameOfArchiveIni, "w"); + $fcourini = fopen($archiveDir.$systemFileNameOfArchiveIni, 'w'); fwrite($fcourini, $iniCourse); fclose($fcourini); - echo $iniCourse, " ini Course"; + echo $iniCourse, ' ini Course'; // ******************************************************************** // info about users // ******************************************************************** - // if ($backupUser ) - { - if ($verbose_backup) + // if ($backupUser ) { + + if ($verbose_backup) { echo " -
  • +
  • ".get_lang('BUUsersInMainBase')." ".$exportedCourseId." -
    -
    ";
    +									
    +
    ";
    +		}
     		// recup users
     		$sqlUserOfTheCourse = "
     					SELECT
    @@ -598,46 +587,43 @@ function makeTheBackup($exportedCourseId, $verbose_backup = FALSE, $ignore = "",
     							AND `".$TABLECOURSUSER."`.`course_code`='".$exportedCourseId."'";
     		$resUsers = Database::query($sqlUserOfTheCourse, __FILE__, __LINE__);
     		$nbUsers = Database::num_rows($resUsers);
    -		if ($nbUsers > 0)
    -		{
    +		if ($nbUsers > 0) {
     			$nbFields = mysql_num_fields($resUsers);
    -			$sqlInsertUsers = "";
    -			$csvInsertUsers = "";
    -			$htmlInsertUsers = "\t\n";
    +			$sqlInsertUsers = '';
    +			$csvInsertUsers = '';
    +			$htmlInsertUsers = "
    \t\n"; // // creation of headers // - for ($noField = 0; $noField < $nbFields; $noField ++) - { + for ($noField = 0; $noField < $nbFields; $noField ++) { $nameField = mysql_field_name($resUsers, $noField); $csvInsertUsers .= "'".addslashes($nameField)."';"; - $htmlInsertUsers .= "\t\t\n"; + $htmlInsertUsers .= "\t\t\n"; } - $htmlInsertUsers .= "\t\n"; + $htmlInsertUsers .= "\t\n"; // // creation of body // - while ($users = Database::fetch_array($resUsers)) - { - $htmlInsertUsers .= "\t\n"; + while ($users = Database::fetch_array($resUsers)) { + $htmlInsertUsers .= "\t\n"; $sqlInsertUsers .= " INSERT IGNORE INTO user SET "; $csvInsertUsers .= "\n"; - for ($noField = 0; $noField < $nbFields; $noField ++) - { - if ($noField > 0) + for ($noField = 0; $noField < $nbFields; $noField ++) { + if ($noField > 0) { $sqlInsertUsers .= ", "; + } $nameField = mysql_field_name($resUsers, $noField); /*echo " -
    +
    $nameField -> ".$users["$nameField"]." "; */ $sqlInsertUsers .= "$nameField = '".$users["$nameField"]."' "; $csvInsertUsers .= "'".addslashes($users["$nameField"])."';"; - $htmlInsertUsers .= "\t\t\n"; + $htmlInsertUsers .= "\t\t\n"; } $sqlInsertUsers .= ";"; - $htmlInsertUsers .= "\t\n"; + $htmlInsertUsers .= "\t\n"; } $htmlInsertUsers .= "
    ".$nameField."".$nameField."
    ".$users["$nameField"]."".$users["$nameField"]."
    \n"; $stringConfig .= " @@ -646,41 +632,37 @@ function makeTheBackup($exportedCourseId, $verbose_backup = FALSE, $ignore = "", # ".$sqlInsertUsers." #------------------------------------------ "; - $fuserssql = fopen($archiveDirSql.$appendMainDb."users.sql", "w"); + $fuserssql = fopen($archiveDirSql.$appendMainDb.'users.sql', 'w'); fwrite($fuserssql, $sqlInsertUsers); fclose($fuserssql); - $fuserscsv = fopen($archiveDirCsv.$appendMainDb."users.csv", "w"); + $fuserscsv = fopen($archiveDirCsv.$appendMainDb.'users.csv', 'w'); fwrite($fuserscsv, $csvInsertUsers); fclose($fuserscsv); - $fusershtml = fopen($archiveDirHtml.$appendMainDb."users.html", "w"); + $fusershtml = fopen($archiveDirHtml.$appendMainDb.'users.html', 'w'); fwrite($fusershtml, $htmlInsertUsers); fclose($fusershtml); - } - else - { - if ($verbose_backup) - { - echo "
    NO user in this course !!!!

    "; + } else { + if ($verbose_backup) { + echo "
    NO user in this course !!!!

    "; } } - if ($verbose_backup) - { - echo "
    "; + if ($verbose_backup) { + echo "
    "; } - } + + //} + /* End of backup user */ - if ($saveAnnouncement) - { + if ($saveAnnouncement) { // ******************************************************************** // info about announcment // ******************************************************************** - if ($verbose_backup) - { + if ($verbose_backup) { echo " -
  • +
  • ".get_lang('BUAnnounceInMainBase')." ".$exportedCourseId." -
    -
    ";
    +								
    +
    ";
     		}
     		// recup annonce
     		$sqlAnnounceOfTheCourse = "
    @@ -690,123 +672,125 @@ function makeTheBackup($exportedCourseId, $verbose_backup = FALSE, $ignore = "",
     					WHERE course_code='".$exportedCourseId."'";
     		$resAnn = Database::query($sqlAnnounceOfTheCourse, __FILE__, __LINE__);
     		$nbFields = mysql_num_fields($resAnn);
    -		$sqlInsertAnn = "";
    -		$csvInsertAnn = "";
    -		$htmlInsertAnn .= "\t\n";
    +		$sqlInsertAnn = '';
    +		$csvInsertAnn = '';
    +		$htmlInsertAnn .= "
    \t\n"; // // creation of headers // - for ($noField = 0; $noField < $nbFields; $noField ++) - { + for ($noField = 0; $noField < $nbFields; $noField ++) { $nameField = mysql_field_name($resUsers, $noField); $csvInsertAnn .= "'".addslashes($nameField)."';"; - $htmlInsertAnn .= "\t\t\n"; + $htmlInsertAnn .= "\t\t\n"; } - $htmlInsertAnn .= "\t\n"; + $htmlInsertAnn .= "\t\n"; // // creation of body // - while ($announce = Database::fetch_array($resAnn)) - { - $htmlInsertAnn .= "\t\n"; + while ($announce = Database::fetch_array($resAnn)) { + $htmlInsertAnn .= "\t\n"; $sqlInsertAnn .= " INSERT INTO users SET "; $csvInsertAnn .= "\n"; - for ($noField = 0; $noField < $nbFields; $noField ++) - { + for ($noField = 0; $noField < $nbFields; $noField ++) { if ($noField > 0) $sqlInsertAnn .= ", "; $nameField = mysql_field_name($resAnn, $noField); /*echo " -
    +
    $nameField -> ".$users["$nameField"]." "; */ $sqlInsertAnn .= "$nameField = '".addslashes($announce["$nameField"])."' "; $csvInsertAnn .= "'".addslashes($announce["$nameField"])."';"; - $htmlInsertAnn .= "\t\t\n"; + $htmlInsertAnn .= "\t\t\n"; } $sqlInsertAnn .= ";"; - $htmlInsertAnn .= "\t\n"; + $htmlInsertAnn .= "\t\n"; } - if ($verbose_backup) - { - echo ""; + if ($verbose_backup) { + echo ""; } - $htmlInsertAnn .= "
    ".$nameField."".$nameField."
    ".$announce["$nameField"]."".$announce["$nameField"]."
    \n"; + $htmlInsertAnn .= "\n"; $stringConfig .= " #INSERT ANNOUNCE #------------------------------------------ # ".$sqlInsertAnn." #------------------------------------------ "; - $fannsql = fopen($archiveDirSql.$appendMainDb."annonces.sql", "w"); + $fannsql = fopen($archiveDirSql.$appendMainDb.'annonces.sql', 'w'); fwrite($fannsql, $sqlInsertAnn); fclose($fannsql); - $fanncsv = fopen($archiveDirCsv.$appendMainDb."annnonces.csv", "w"); + $fanncsv = fopen($archiveDirCsv.$appendMainDb.'annnonces.csv', 'w'); fwrite($fanncsv, $csvInsertAnn); fclose($fanncsv); - $fannhtml = fopen($archiveDirHtml.$appendMainDb."annonces.html", "w"); + $fannhtml = fopen($archiveDirHtml.$appendMainDb.'annonces.html', 'w'); fwrite($fannhtml, $htmlInsertAnn); fclose($fannhtml); /* End of backup Annonces */ } // we can copy file of course - if ($verbose_backup) - { + if ($verbose_backup) { echo '
  • '.get_lang('CopyDirectoryCourse'); } $nbFiles = copydir(api_get_path(SYS_COURSE_PATH).$_course['path'], $archiveDirOriginalDocs.$appendCourse, $verbose_backup); - if ($verbose_backup) + if ($verbose_backup) { echo " ".$nbFiles." ".get_lang('FileCopied')." -
    +
  • "; + } $stringConfig .= " // ".$nbFiles." was in ".realpath($archiveDirOriginalDocs); // ******************************************************************** // Copy of DB course // with mysqldump // ******************************************************************** - if ($verbose_backup) + if ($verbose_backup) { echo " -
  • +
  • ".get_lang('BackupOfDataBase')." ".$exportedCourseId." (SQL) -
    "; +
    "; + } backupDatabase($db, $exportedCourseId, true, true, 'SQL', $archiveDirSql.$appendCourse, true, $verbose_backup); - if ($verbose_backup) + if ($verbose_backup) { echo " -
  • -
  • +
  • +
  • ".get_lang('BackupOfDataBase')." ".$exportedCourseId." (PHP) -
    "; +
    "; + } backupDatabase($db, $exportedCourseId, true, true, 'PHP', $archiveDirPhp.$appendCourse, true, $verbose_backup); - if ($verbose_backup) + if ($verbose_backup) { echo " -
  • -
  • +
  • +
  • ".get_lang('BackupOfDataBase')." ".$exportedCourseId." (CSV) -
    "; +
    "; + } backupDatabase($db, $exportedCourseId, true, true, 'CSV', $archiveDirCsv.$appendCourse, true, $verbose_backup); - if ($verbose_backup) + if ($verbose_backup) { echo " -
  • +
  • ".get_lang('BackupOfDataBase')." ".$exportedCourseId." (HTML) -
    "; +
    "; + } backupDatabase($db, $exportedCourseId, true, true, 'HTML', $archiveDirHtml.$appendCourse, true, $verbose_backup); - if ($verbose_backup) + if ($verbose_backup) { echo " -
  • +
  • ".get_lang('BackupOfDataBase')." ".$exportedCourseId." (XML) -
    "; +
    "; + } backupDatabase($db, $exportedCourseId, true, true, 'XML', $archiveDirXml.$appendCourse, true, $verbose_backup); - if ($verbose_backup) + if ($verbose_backup) { echo " -
  • +
  • ".get_lang('BackupOfDataBase')." ".$exportedCourseId." (LOG) -
    "; +
    "; + } backupDatabase($db, $exportedCourseId, true, true, 'LOG', $archiveDirLog.$appendCourse, true, $verbose_backup); // ******************************************************************** // Copy of DB course @@ -815,41 +799,36 @@ function makeTheBackup($exportedCourseId, $verbose_backup = FALSE, $ignore = "", $fdesc = fopen($archiveDir.$systemFileNameOfArchive, "w"); fwrite($fdesc, $stringConfig); fclose($fdesc); - if ($verbose_backup) + if ($verbose_backup) { echo " -
  • - +
  • + -
    "; +
    "; + } /////////////////////////////////// - // ****** 4� Compress the tree - if (extension_loaded("zlib")) - { - $whatZip[] = $archiveRepositorySys.$exportedCourseId."/".$shortDateBackuping."/HTML"; - $forgetPath = $archiveRepositorySys.$exportedCourseId."/".$shortDateBackuping."/"; + // ****** 4. Compress the tree + if (extension_loaded('zlib')) { + $whatZip[] = $archiveRepositorySys.$exportedCourseId.'/'.$shortDateBackuping.'/HTML'; + $forgetPath = $archiveRepositorySys.$exportedCourseId.'/'.$shortDateBackuping.'/'; $prefixPath = $exportedCourseId; $zipCourse = new PclZip($archiveRepositorySys.$archiveFileName); $zipRes = $zipCourse->create($whatZip, PCLZIP_OPT_ADD_PATH, $prefixPath, PCLZIP_OPT_REMOVE_PATH, $forgetPath); - if ($zipRes == 0) - { + if ($zipRes == 0) { echo "", $zipCourse->errorInfo(true), ""; - } - else - for ($i = 0; $i < sizeof($zipRes); $i ++) - { - for (reset($zipRes[$i]); $key = key($zipRes[$i]); next($zipRes[$i])) - { - echo "File $i / [$key] = ".$list[$i][$key]."
    "; + } else { + for ($i = 0; $i < sizeof($zipRes); $i ++) { + for (reset($zipRes[$i]); $key = key($zipRes[$i]); next($zipRes[$i])) { + echo "File $i / [$key] = ".$list[$i][$key]."
    "; } - echo "
    "; + echo "
    "; } + } $pathToArchive = $archiveRepositoryWeb.$archiveFileName; - if ($verbose_backup) - { - echo '
    '.get_lang('BuildTheCompressedFile'); + if ($verbose_backup) { + echo '
    '.get_lang('BuildTheCompressedFile'); } // removeDir($archivePath); } return 1; } // function makeTheBackup() -?>