[ Index ]
 

Code source de Claroline 188

Accédez au Source d'autres logiciels libres

Classes | Fonctions | Variables | Constantes | Tables

title

Body

[fermer]

/claroline/learnPath/ -> insertMyDoc.php (source)

   1  <?php // $Id: insertMyDoc.php,v 1.36.2.1 2007/08/10 13:37:12 mathieu Exp $
   2  /**
   3   * CLAROLINE
   4   *
   5   * @version 1.8 $Revision: 1.36.2.1 $
   6   *
   7   * @copyright (c) 2001-2007 Universite catholique de Louvain (UCL)
   8   *
   9   * @license http://www.gnu.org/copyleft/gpl.html (GPL) GENERAL PUBLIC LICENSE
  10   *
  11   * @author Piraux Sébastien <pir@cerdecam.be>
  12   * @author Lederer Guillaume <led@cerdecam.be>
  13   *
  14   * @package CLLNP
  15   */
  16  
  17  /*======================================
  18         CLAROLINE MAIN
  19    ======================================*/
  20  $tlabelReq = 'CLLNP';
  21  require  '../inc/claro_init_global.inc.php';
  22  
  23  // if there is an auth information missing redirect to the first page of lp tool
  24  // this page will do the necessary to auth the user,
  25  // when leaving a course all the LP sessions infos are cleared so we use this trick to avoid other errors
  26  
  27  if ( ! claro_is_in_a_course() || ! claro_is_course_allowed() ) claro_disp_auth_form(true);
  28  $is_allowedToEdit = claro_is_course_manager();
  29  
  30  if ( ! $is_allowedToEdit ) claro_die(get_lang('Not allowed'));
  31  
  32  $interbredcrump[]= array ("url"=>get_module_url('CLLNP') . '/learningPathList.php', "name"=> get_lang('Learning path list'));
  33  $interbredcrump[]= array ("url"=>get_module_url('CLLNP') . '/learningPathAdmin.php', "name"=> get_lang('Learning path admin'));
  34  
  35  $nameTools = get_lang('Add a document');
  36  
  37  include get_path('incRepositorySys') . '/claro_init_header.inc.php';
  38  
  39  // tables names
  40  
  41  $tbl_cdb_names = claro_sql_get_course_tbl();
  42  
  43  $tbl_lp_learnPath            = $tbl_cdb_names['lp_learnPath'           ];
  44  $tbl_lp_rel_learnPath_module = $tbl_cdb_names['lp_rel_learnPath_module'];
  45  $tbl_lp_user_module_progress = $tbl_cdb_names['lp_user_module_progress'];
  46  $tbl_lp_module               = $tbl_cdb_names['lp_module'              ];
  47  $tbl_lp_asset                = $tbl_cdb_names['lp_asset'               ];
  48  
  49  $TABLELEARNPATH            = $tbl_lp_learnPath;
  50  $TABLELEARNPATHMODULE      = $tbl_lp_rel_learnPath_module;
  51  $TABLEUSERMODULEPROGRESS   = $tbl_lp_user_module_progress;
  52  $TABLEMODULE               = $tbl_lp_module;
  53  $TABLEASSET                = $tbl_lp_asset;
  54  
  55  $dbTable = $tbl_cdb_names['document'];
  56  
  57  // document browser vars
  58  $TABLEDOCUMENT = claro_get_current_course_data('dbNameGlu') . 'document';
  59  
  60  $courseDir   = claro_get_course_path() . '/document';
  61  $moduleDir   = claro_get_course_path() . '/modules';
  62  $baseWorkDir = get_path('coursesRepositorySys').$courseDir;
  63  $moduleWorkDir = get_path('coursesRepositorySys').$moduleDir;
  64  
  65  //lib of this tool
  66  include(get_path('incRepositorySys') . "/lib/learnPath.lib.inc.php");
  67  
  68  include(get_path('incRepositorySys') . "/lib/fileDisplay.lib.php");
  69  include(get_path('incRepositorySys') . "/lib/fileManage.lib.php");
  70  
  71  // $_SESSION
  72  if ( !isset($_SESSION['path_id']) )
  73  {
  74        claro_redirect("./learningPath.php");
  75  }
  76  
  77  /*======================================
  78         CLAROLINE MAIN
  79   ======================================*/
  80  
  81  // FUNCTION NEEDED TO BUILD THE QUERY TO SELECT THE MODULES THAT MUST BE AVAILABLE
  82  
  83  // 1)  We select first the modules that must not be displayed because
  84  // as they are already in this learning path
  85  
  86  function buildRequestModules()
  87  {
  88  
  89   global $TABLELEARNPATHMODULE;
  90   global $TABLEMODULE;
  91  
  92   $firstSql = "SELECT `module_id`
  93                FROM `".$TABLELEARNPATHMODULE."` AS LPM
  94                WHERE LPM.`learnPath_id` = ". (int)$_SESSION['path_id'];
  95  
  96   $firstResult = claro_sql_query($firstSql);
  97  
  98   // 2) We build the request to get the modules we need
  99  
 100   $sql = "SELECT M.*
 101           FROM `".$TABLEMODULE."` AS M
 102           WHERE 1 = 1";
 103  
 104   while ($list=mysql_fetch_array($firstResult))
 105   {
 106      $sql .=" AND M.`module_id` != ". (int)$list['module_id'];
 107   }
 108  
 109   /** To find which module must displayed we can also proceed  with only one query.
 110    * But this implies to use some features of MySQL not available in the version 3.23, so we use
 111    * two differents queries to get the right list.
 112    * Here is how to proceed with only one
 113  
 114    $query = "SELECT *
 115               FROM `".$TABLEMODULE."` AS M
 116               WHERE NOT EXISTS(SELECT * FROM `".$TABLELEARNPATHMODULE."` AS TLPM
 117               WHERE TLPM.`module_id` = M.`module_id`)";
 118    */
 119  
 120    return $sql;
 121  
 122  }//end function
 123  
 124  //####################################################################################\\
 125  //################################ DOCUMENTS LIST ####################################\\
 126  //####################################################################################\\
 127  
 128  // display title
 129  
 130  echo claro_html_tool_title($nameTools);
 131  
 132  // FORM SENT
 133  /*
 134   *
 135   * SET THE DOCUMENT AS A MODULE OF THIS LEARNING PATH
 136   *
 137   */
 138  
 139  // evaluate how many form could be sent
 140  if (!isset($dialogBox)) $dialogBox = "";
 141  
 142  $iterator = 0;
 143  
 144  if (!isset($_REQUEST['maxDocForm'])) $_REQUEST['maxDocForm'] = 0;
 145  
 146  while ($iterator <= $_REQUEST['maxDocForm'])
 147  {
 148      $iterator++;
 149  
 150      if (isset($_REQUEST['submitInsertedDocument']) && isset($_POST['insertDocument_'.$iterator]) )
 151      {
 152          $insertDocument = str_replace('..', '',$_POST['insertDocument_'.$iterator]);
 153  
 154          $sourceDoc = $baseWorkDir.$insertDocument;
 155  
 156          if ( check_name_exist($sourceDoc) ) // source file exists ?
 157          {
 158              // check if a module of this course already used the same document
 159              $sql = "SELECT *
 160                      FROM `".$TABLEMODULE."` AS M, `".$TABLEASSET."` AS A
 161                      WHERE A.`module_id` = M.`module_id`
 162                        AND A.`path` LIKE \"". addslashes($insertDocument)."\"
 163                        AND M.`contentType` = \"".CTDOCUMENT_."\"";
 164              $query = claro_sql_query($sql);
 165              $num = mysql_num_rows($query);
 166              $basename = substr($insertDocument, strrpos($insertDocument, '/') + 1);
 167  
 168              if($num == 0)
 169              {
 170                  // create new module
 171                  $sql = "INSERT INTO `".$TABLEMODULE."`
 172                          (`name` , `comment`, `contentType`, `launch_data`)
 173                          VALUES ('". addslashes($basename) ."' , '". addslashes(get_block('blockDefaultModuleComment')) . "', '".CTDOCUMENT_."', '' )";
 174                  $query = claro_sql_query($sql);
 175  
 176                  $insertedModule_id = claro_sql_insert_id();
 177  
 178                  // create new asset
 179                  $sql = "INSERT INTO `".$TABLEASSET."`
 180                          (`path` , `module_id` , `comment`)
 181                          VALUES ('". addslashes($insertDocument)."', " . (int)$insertedModule_id . ", '')";
 182                  $query = claro_sql_query($sql);
 183  
 184                  $insertedAsset_id = claro_sql_insert_id();
 185  
 186                  $sql = "UPDATE `".$TABLEMODULE."`
 187                          SET `startAsset_id` = " . (int)$insertedAsset_id . "
 188                          WHERE `module_id` = " . (int)$insertedModule_id . "";
 189                  $query = claro_sql_query($sql);
 190  
 191                  // determine the default order of this Learning path
 192                  $sql = "SELECT MAX(`rank`)
 193                          FROM `".$TABLELEARNPATHMODULE."`";
 194                  $result = claro_sql_query($sql);
 195  
 196                  list($orderMax) = mysql_fetch_row($result);
 197                  $order = $orderMax + 1;
 198  
 199                  // finally : insert in learning path
 200                  $sql = "INSERT INTO `".$TABLELEARNPATHMODULE."`
 201                          (`learnPath_id`, `module_id`, `specificComment`, `rank`, `lock`)
 202                          VALUES ('". (int)$_SESSION['path_id']."', '".(int)$insertedModule_id."','".addslashes(get_block('blockDefaultModuleAddedComment'))."', ".(int)$order.", 'OPEN')";
 203                  $query = claro_sql_query($sql);
 204  
 205                  $dialogBox .= get_lang("%moduleName has been added as module", array('%moduleName' => $basename)).'<br />' . "\n";
 206              }
 207              else
 208              {
 209                  // check if this is this LP that used this document as a module
 210                  $sql = "SELECT *
 211                          FROM `".$TABLELEARNPATHMODULE."` AS LPM,
 212                               `".$TABLEMODULE."` AS M,
 213                               `".$TABLEASSET."` AS A
 214                          WHERE M.`module_id` =  LPM.`module_id`
 215                            AND M.`startAsset_id` = A.`asset_id`
 216                            AND A.`path` = '". addslashes($insertDocument)."'
 217                            AND LPM.`learnPath_id` = ". (int)$_SESSION['path_id'];
 218                  $query2 = claro_sql_query($sql);
 219                  $num = mysql_num_rows($query2);
 220                  if ($num == 0)     // used in another LP but not in this one, so reuse the module id reference instead of creating a new one
 221                  {
 222                      $thisDocumentModule = mysql_fetch_array($query);
 223                      // determine the default order of this Learning path
 224                      $sql = "SELECT MAX(`rank`)
 225                              FROM `".$TABLELEARNPATHMODULE."`";
 226                      $result = claro_sql_query($sql);
 227  
 228                      list($orderMax) = mysql_fetch_row($result);
 229                      $order = $orderMax + 1;
 230                      // finally : insert in learning path
 231                      $sql = "INSERT INTO `".$TABLELEARNPATHMODULE."`
 232                              (`learnPath_id`, `module_id`, `specificComment`, `rank`,`lock`)
 233                              VALUES ('". (int)$_SESSION['path_id']."', '". (int)$thisDocumentModule['module_id']."','".addslashes(get_block('blockDefaultModuleAddedComment'))."', ".(int)$order.",'OPEN')";
 234                      $query = claro_sql_query($sql);
 235  
 236                      $dialogBox .= get_lang("%moduleName has been added as module", array('%moduleName' => $basename)).'<br />' . "\n";
 237                  }
 238                  else
 239                  {
 240                      $dialogBox .= get_lang("%moduleName is already used as a module in this learning path", array('%moduleName' => $basename)).'<br />' . "\n";
 241                  }
 242              }
 243          }
 244      }
 245  }
 246  
 247  /*======================================
 248    DEFINE CURRENT DIRECTORY
 249   ======================================*/
 250  
 251  if (isset($_REQUEST['openDir']) ) // $newDirPath is from createDir command (step 2) and $uploadPath from upload command
 252  {
 253      $curDirPath = $_REQUEST['openDir'];
 254      /*
 255       * NOTE: Actually, only one of these variables is set.
 256       * By concatenating them, we eschew a long list of "if" statements
 257       */
 258  }
 259  else
 260  {
 261      $curDirPath="";
 262  }
 263  
 264  if ($curDirPath == "/" || $curDirPath == "\\" || strstr($curDirPath, ".."))
 265  {
 266      $curDirPath =""; // manage the root directory problem
 267  
 268      /*
 269       * The strstr($curDirPath, "..") prevent malicious users to go to the root directory
 270       */
 271  }
 272  
 273  $curDirName = basename($curDirPath);
 274  $parentDir  = dirname($curDirPath);
 275  
 276  if ($parentDir == "/" || $parentDir == "\\")
 277  {
 278          $parentDir =""; // manage the root directory problem
 279  }
 280  
 281  /*======================================
 282          READ CURRENT DIRECTORY CONTENT
 283    ======================================*/
 284  
 285  /*--------------------------------------
 286    SEARCHING FILES & DIRECTORIES INFOS
 287                ON THE DB
 288    --------------------------------------*/
 289  
 290  /* Search infos in the DB about the current directory the user is in */
 291  
 292  $sql = "SELECT *
 293          FROM `".$TABLEDOCUMENT."`
 294          WHERE `path` LIKE '". addslashes($curDirPath) ."/%'
 295          AND `path` NOT LIKE '". addslashes($curDirPath) ."/%/%'";
 296  $result = claro_sql_query($sql);
 297  $attribute = array();
 298  
 299  while($row = mysql_fetch_array($result, MYSQL_ASSOC))
 300  {
 301      $attribute['path'      ][] = $row['path'      ];
 302      $attribute['visibility'][] = $row['visibility'];
 303      $attribute['comment'   ][] = $row['comment'   ];
 304  }
 305  
 306  /*--------------------------------------
 307    LOAD FILES AND DIRECTORIES INTO ARRAYS
 308    --------------------------------------*/
 309  @chdir (realpath($baseWorkDir.$curDirPath))
 310  or die("<center>
 311          <b>Wrong directory !</b>
 312          <br /> Please contact your platform administrator.</center>");
 313  $handle = opendir(".");
 314  
 315  define('A_DIRECTORY', 1);
 316  define('A_FILE',      2);
 317  
 318  $fileList = array();
 319  
 320  while ($file = readdir($handle))
 321  {
 322      if ($file == "." || $file == "..")
 323      {
 324          continue; // Skip current and parent directories
 325      }
 326  
 327      $fileList['name'][] = $file;
 328  
 329      if(is_dir($file))
 330      {
 331          $fileList['type'][] = A_DIRECTORY;
 332          $fileList['size'][] = false;
 333          $fileList['date'][] = false;
 334      }
 335      elseif(is_file($file))
 336      {
 337          $fileList['type'][] = A_FILE;
 338          $fileList['size'][] = filesize($file);
 339          $fileList['date'][] = filectime($file);
 340      }
 341  
 342      /*
 343       * Make the correspondance between
 344       * info given by the file system
 345       * and info given by the DB
 346       */
 347  
 348      if (!isset($dirNameList)) $dirNameList = array();
 349      $keyDir = sizeof($dirNameList)-1;
 350  
 351      if (isset($attribute))
 352      {
 353          if (isset($attribute['path']))
 354          {
 355              $keyAttribute = array_search($curDirPath."/".$file, $attribute['path']);
 356          }
 357          else
 358          {
 359              $keyAttribute = false;
 360          }
 361      }
 362  
 363      if ($keyAttribute !== false)
 364      {
 365          $fileList['comment'   ][] = $attribute['comment'   ][$keyAttribute];
 366          $fileList['visibility'][] = $attribute['visibility'][$keyAttribute];
 367      }
 368      else
 369      {
 370          $fileList['comment'   ][] = false;
 371          $fileList['visibility'][] = false;
 372      }
 373  } // end while ($file = readdir($handle))
 374  
 375  /*
 376   * Sort alphabetically the File list
 377   */
 378  
 379  if ($fileList)
 380  {
 381      array_multisort($fileList['type'], $fileList['name'],
 382                      $fileList['size'], $fileList['date'],
 383                      $fileList['comment'],$fileList['visibility']);
 384  }
 385  
 386  /*----------------------------------------
 387          CHECK BASE INTEGRITY
 388  --------------------------------------*/
 389  
 390  if (isset($attribute))
 391  {
 392      /*
 393       * check if the number of DB records is greater
 394       * than the numbers of files attributes previously given
 395       */
 396  
 397      if ( isset($attribute['path']) && isset($fileList['comment'])
 398           && ( sizeof($attribute['path']) > (sizeof($fileList['comment']) + sizeof($fileList['visibility'])) ) )
 399      {
 400          /* SEARCH DB RECORDS WICH HAVE NOT CORRESPONDANCE ON THE DIRECTORY */
 401          foreach( $attribute['path'] as $chekinFile)
 402          {
 403              if (isset($dirNameList) && in_array(basename($chekinFile), $dirNameList))
 404                  continue;
 405              elseif (isset($fileNameList) && $fileNameList && in_array(basename($chekinFile), $fileNameList))
 406                  continue;
 407              else
 408                  $recToDel[]= $chekinFile; // add chekinFile to the list of records to delete
 409          }
 410  
 411          /* BUILD THE QUERY TO DELETE DEPRECATED DB RECORDS */
 412          $nbrRecToDel = sizeof ($recToDel);
 413          $queryClause = "";
 414  
 415          for ($i=0; $i < $nbrRecToDel ;$i++)
 416          {
 417              $queryClause .= "path LIKE \"". addslashes($recToDel[$i]) ."%\"";
 418              if ($i < $nbrRecToDel-1)
 419              {
 420                  $queryClause .=" OR ";
 421              }
 422          }
 423  
 424          $sql = "DELETE
 425                  FROM `".$dbTable."`
 426                  WHERE ".$queryClause;
 427          claro_sql_query($sql);
 428  
 429          $sql = "DELETE
 430                  FROM `".$dbTable."`
 431                  WHERE `comment` LIKE ''
 432                    AND `visibility` LIKE 'v'";
 433          claro_sql_query($sql);
 434  
 435          /* The second query clean the DB 'in case of' empty records (no comment an visibility=v)
 436             These kind of records should'nt be there, but we never know... */
 437  
 438      }
 439  } // end if (isset($attribute))
 440  
 441  closedir($handle);
 442  unset($attribute);
 443  
 444  // display list of available documents
 445  
 446  display_my_documents($dialogBox) ;
 447  
 448  //####################################################################################\\
 449  //################################## MODULES LIST ####################################\\
 450  //####################################################################################\\
 451  
 452  echo claro_html_tool_title(get_lang('Learning path content'));
 453  echo '<a href="learningPathAdmin.php">&lt;&lt;&nbsp;'.get_lang('Back to learning path administration').'</a>';
 454  
 455  // display list of modules used by this learning path
 456  display_path_content();
 457  
 458  // footer
 459  include get_path('incRepositorySys') . '/claro_init_footer.inc.php';
 460  ?>


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