[ Index ]
 

Code source de Claroline 188

Accédez au Source d'autres logiciels libres

Classes | Fonctions | Variables | Constantes | Tables

title

Body

[fermer]

/claroline/admin/upgrade/ -> restore_course_repository.php (source)

   1  <?php // $Id: restore_course_repository.php,v 1.16.2.1 2007/09/03 20:27:05 mathieu Exp $
   2  /**
   3   * CLAROLINE 
   4   *
   5   * Try to create main database of claroline without remove existing content
   6   * 
   7   * @version 1.8 $Revision: 1.16.2.1 $
   8   *
   9   * @copyright 2001-2006 Universite catholique de Louvain (UCL)
  10   *
  11   * @license http://www.gnu.org/copyleft/gpl.html (GPL) GENERAL PUBLIC LICENSE 
  12   *
  13   * @see http://www.claroline.net/wiki/index.php/Upgrade_claroline_1.6
  14   *
  15   * @package UPGRADE
  16   *
  17   * @author Claro Team <cvs@claroline.net>
  18   * @author Christophe Gesché <moosh@claroline.net>
  19   * @author Mathieu Laurent <laurent@cerdecam.be>
  20   * @since 1.6
  21   *
  22   */
  23  
  24  /*=====================================================================
  25    Init Section
  26   =====================================================================*/
  27  
  28  // Initialise Upgrade
  29  require  'upgrade_init_global.inc.php';
  30  
  31  // Security Check
  32  if ( !claro_is_platform_admin() ) upgrade_disp_auth_form();
  33  
  34  /*=====================================================================
  35    Main Section
  36   =====================================================================*/
  37  
  38  $nameTools = get_lang('Restore course repository');
  39  
  40  // Execute command
  41  
  42  if ( isset($_REQUEST['cmd']) 
  43       && ( $_REQUEST['cmd'] == 'exRestore'
  44            || ( $_REQUEST['cmd'] == 'exMove' && get_path('coursesRepositoryAppend') != 'courses/'  ) ) )
  45  {
  46      if ( $_REQUEST['cmd'] == 'exMove' )
  47      {
  48          $newCourseFolder = get_path('rootSys').'courses/';
  49  
  50          if ( ! is_dir($newCourseFolder) )
  51          {
  52              if ( mkdir($newCourseFolder) === false )
  53              {
  54                  echo sprintf('Creation of "%s" folder failed',$newCourseFolder);
  55              }
  56          }
  57      }
  58  
  59      // query returns course code and course folder
  60      $tbl_mdb_names = claro_sql_get_main_tbl();
  61      
  62      $tbl_course = $tbl_mdb_names['course'];
  63      
  64      $sqlListCourses = " SELECT code sysCode, directory coursePath ".
  65                        " FROM `". $tbl_course . "` " .
  66                        " ORDER BY sysCode";
  67      
  68      $res_listCourses = claro_sql_query($sqlListCourses);
  69      
  70      if (mysql_num_rows($res_listCourses))
  71      {
  72          $restored_courses =  '<ol>' . "\n";
  73          $moved_courses =  '<ol>' . "\n";        
  74          
  75          while ( ( $course = mysql_fetch_array($res_listCourses)) )
  76          {
  77              $currentcoursePathSys = get_path('coursesRepositorySys') . $course['coursePath'] . '/';
  78              $currentCourseIDsys = $course['sysCode'];
  79              
  80              if ( $_REQUEST['cmd'] == 'exRestore' )
  81              {
  82                  if ( restore_course_repository($currentCourseIDsys,$currentcoursePathSys) )
  83                  {
  84                      $restored_courses .= '<li>' . sprintf('Course repository "%s" updated', $currentcoursePathSys) . '</li>' . "\n";       
  85                  }
  86              }
  87              elseif ( $_REQUEST['cmd'] == 'exMove' )
  88              {
  89                  $currentFolder = get_path('coursesRepositorySys') . $course['coursePath'] . '/';
  90                  $newFolder = get_path('rootSys') . 'courses/' . $course['coursePath'] . '/';
  91  
  92                  if ( move_course_folder($currentFolder,$newFolder) === false )
  93                  {
  94                      $moved_courses .= '<li>' . sprintf('Error: Cannot rename "%s" to "%s"', $currentFolder ,$newFolder) . '</li>' . "\n";
  95                  }
  96                  else
  97                  {
  98                      $moved_courses.= '<li>' . sprintf('Course repository "%s" moved to "%s"', $currentFolder,$newFolder) . '</li>' . "\n"; 
  99                  }
 100              }        
 101          }
 102          $restored_courses .= '</ol>' . "\n";
 103          $moved_courses .= '</ol>' . "\n";
 104      }
 105  
 106      // TODO if course move succeed, update the value in configuration
 107      if ( $_REQUEST['cmd'] == 'exMove' && $error = false )
 108      {
 109          $_GLOBALS['coursesRepositoryAppend'] = 'courses/';
 110  
 111          $config = new Config('CLMAIN');
 112          $config->load();
 113          $config->validate(array('coursesRepositoryAppend'=>'courses/'));
 114          $config->save();
 115      }
 116  }
 117  
 118  // Display Header
 119  echo upgrade_disp_header();
 120  
 121  echo claro_html_tool_title($nameTools);
 122  
 123  // display result
 124  
 125  if (isset($restored_courses)) echo $restored_courses;
 126  if (isset($moved_courses)) echo $moved_courses;
 127  
 128  // display link to launch the restore
 129  if ( get_path('coursesRepositoryAppend') != 'courses/' )
 130  {
 131      echo '<p><a href="' . $_SERVER['PHP_SELF'] . '?cmd=exMove">' . sprintf('Move "course repository" to folder "%s"', get_path('rootSys') . 'courses/') . '</a></p>';
 132  }
 133  
 134  echo '<p><a href="' . $_SERVER['PHP_SELF'] . '?cmd=exRestore">' . sprintf('Launch restore of the course repository') . '</a></p>';
 135  
 136  // Display footer
 137  echo upgrade_disp_footer();
 138  
 139  // move folder to new folder
 140  // TODO use claro_failure
 141  
 142  function move_course_folder ( $currentFolder, $newFolder )
 143  {
 144      if ( ! is_dir($currentFolder) )
 145      {
 146          // current folder doesn't exist
 147          return false ;
 148      }
 149  
 150      if ( is_dir($newFolder) )
 151      {
 152          // folder already exists
 153          return false ;
 154      }
 155  
 156      if ( $currentFolder == $newFolder )
 157      {
 158          // the currentFolder is the newFolder
 159          return false ;
 160      }
 161                  
 162      if ( @rename($currentFolder,$newFolder) === false )
 163      {
 164          return false;
 165      }
 166      else
 167      {
 168          return true;
 169      }
 170  }
 171  
 172  function restore_course_repository($courseId, $courseRepository)
 173  {
 174  
 175      global $urlAppend;
 176  
 177      if ( is_writable($courseRepository) )
 178      {
 179          umask(0);
 180  
 181          /**
 182              create directory for new tools of claroline 1.5 
 183          */
 184      
 185          if ( !is_dir($courseRepository) ) mkdir($courseRepository, CLARO_FILE_PERMISSIONS);
 186          if ( !is_dir($courseRepository . '/chat'          ) ) mkdir($courseRepository . '/chat'          , CLARO_FILE_PERMISSIONS);
 187          if ( !is_dir($courseRepository . '/modules'       ) ) mkdir($courseRepository . '/modules'       , CLARO_FILE_PERMISSIONS);
 188          if ( !is_dir($courseRepository . '/scormPackages' ) ) mkdir($courseRepository . '/scormPackages' , CLARO_FILE_PERMISSIONS);
 189  
 190          // build index.php of course
 191          $fd = fopen($courseRepository . '/index.php', 'w');
 192          if ( ! $fd) return claro_failure::set_failure('CANT_CREATE_COURSE_INDEX');
 193  
 194          $string = '<?php ' . "\n"
 195                  . 'header (\'Location: '. $urlAppend . '/claroline/course/index.php?cid=' . htmlspecialchars($courseId) . '\') ;' . "\n"
 196                . '?' . '>' . "\n" ;
 197  
 198          if ( ! fwrite($fd, $string) ) return false;
 199          if ( ! fclose($fd) )          return false;
 200  
 201          $fd = fopen($courseRepository . '/group/index.php', 'w');
 202          if ( ! $fd ) return false;
 203  
 204          $string = '<?php session_start(); ?'.'>';
 205  
 206          if ( ! fwrite($fd, $string) ) return false;
 207  
 208          return true;
 209      
 210      } else {
 211          printf ('repository %s not writable', $courseRepository);
 212          return 0;
 213      }
 214  
 215  }
 216  
 217  ?>


Généré le : Thu Nov 29 14:38:42 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics