[ Index ]
 

Code source de Claroline 188

Accédez au Source d'autres logiciels libres

Classes | Fonctions | Variables | Constantes | Tables

title

Body

[fermer]

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

   1  <?php // $Id: modules_pool.php,v 1.48.2.1 2007/08/10 13:37:12 mathieu Exp $
   2  /**
   3   * CLAROLINE
   4   *
   5   * @version 1.8 $Revision: 1.48.2.1 $
   6   *
   7   * @copyright (c) 2001-2006 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   * This is the page where the list of modules of the course present
  17   * on the platform can be browsed
  18   * user allowed to edit the course can
  19   * delete the modules form this page
  20   */
  21  
  22  /*======================================
  23         CLAROLINE MAIN
  24    ======================================*/
  25  
  26  $tlabelReq = 'CLLNP';
  27  require  '../inc/claro_init_global.inc.php';
  28  
  29  $is_allowedToEdit = claro_is_course_manager();
  30  if ( ! claro_is_in_a_course() || ! claro_is_course_allowed() ) claro_disp_auth_form(true);
  31  if ( ! $is_allowedToEdit ) claro_die(get_lang('Not allowed'));
  32  
  33  $htmlHeadXtra[] =
  34          '<script type="text/javascript">
  35          function confirmation (name, timeUsed)
  36          {
  37              if (confirm("'.clean_str_for_javascript(get_block('blockConfirmDeleteModule'))
  38                          . ' \n" + name + "\n '
  39                          . clean_str_for_javascript(get_lang('Number of learning paths using this module : '))
  40                          . '" + timeUsed))
  41                  {return true;}
  42              else
  43                  {return false;}
  44          }
  45          </script>';
  46  
  47  $interbredcrump[]= array ("url"=>"../learnPath/learningPathList.php", "name"=> get_lang('Learning path list'));
  48  $nameTools = get_lang('Pool of modules');
  49  
  50  // tables names
  51  /*
  52   * DB tables definition
  53   */
  54  
  55  $tbl_cdb_names = claro_sql_get_course_tbl();
  56  $tbl_lp_learnPath            = $tbl_cdb_names['lp_learnPath'           ];
  57  $tbl_lp_rel_learnPath_module = $tbl_cdb_names['lp_rel_learnPath_module'];
  58  $tbl_lp_user_module_progress = $tbl_cdb_names['lp_user_module_progress'];
  59  $tbl_lp_module               = $tbl_cdb_names['lp_module'              ];
  60  $tbl_lp_asset                = $tbl_cdb_names['lp_asset'               ];
  61  
  62  //this bloc would be removed later by direct use of var name
  63  $TABLELEARNPATH         = $tbl_lp_learnPath;
  64  $TABLEMODULE            = $tbl_lp_module;
  65  $TABLELEARNPATHMODULE   = $tbl_lp_rel_learnPath_module;
  66  $TABLEASSET             = $tbl_lp_asset;
  67  $TABLEUSERMODULEPROGRESS= $tbl_lp_user_module_progress;
  68  
  69  
  70  //lib of this tool
  71  include(get_path('incRepositorySys')."/lib/learnPath.lib.inc.php");
  72  
  73  /*======================================
  74         CLAROLINE MAIN
  75    ======================================*/
  76  
  77  //header
  78  include get_path('incRepositorySys') . '/claro_init_header.inc.php';
  79  
  80  // display title
  81  echo claro_html_tool_title($nameTools);
  82  
  83  // display use explication text
  84  echo get_block('blockModulePoolHelp')."<br /><br />";
  85  
  86  // HANDLE COMMANDS:
  87  $cmd = ( isset($_REQUEST['cmd']) )? $_REQUEST['cmd'] : '';
  88  
  89  switch( $cmd )
  90  {
  91      // MODULE DELETE
  92      case "eraseModule" :
  93          // used to physically delete the module  from server
  94          include(get_path('incRepositorySys')."/lib/fileManage.lib.php");
  95  
  96          $moduleDir   = claro_get_course_path() . '/modules';
  97          $moduleWorkDir = get_path('coursesRepositorySys').$moduleDir;
  98  
  99          // delete all assets of this module
 100          $sql = "DELETE
 101                  FROM `".$TABLEASSET."`
 102                  WHERE `module_id` = ". (int)$_REQUEST['cmdid'];
 103          claro_sql_query($sql);
 104  
 105          // delete from all learning path of this course but keep there id before
 106          $sql = "SELECT *
 107                  FROM `".$TABLELEARNPATHMODULE."`
 108                  WHERE `module_id` = ". (int)$_REQUEST['cmdid'];
 109          $result = claro_sql_query($sql);
 110  
 111          $sql = "DELETE
 112                  FROM `".$TABLELEARNPATHMODULE."`
 113                  WHERE `module_id` = ". (int)$_REQUEST['cmdid'];
 114          claro_sql_query($sql);
 115  
 116          // delete the module in modules table
 117          $sql = "DELETE
 118                  FROM `".$TABLEMODULE."`
 119                  WHERE `module_id` = ". (int)$_REQUEST['cmdid'];
 120          claro_sql_query($sql);
 121  
 122          //delete all user progression concerning this module
 123          $sql = "DELETE
 124                  FROM `".$TABLEUSERMODULEPROGRESS."`
 125                  WHERE 1=0 ";
 126  
 127          while ($list = mysql_fetch_array($result))
 128          {
 129              $sql.=" OR `learnPath_module_id`=". (int)$list['learnPath_module_id'];
 130          }
 131          claro_sql_query($sql);
 132  
 133          // This query does the same as the 3 previous queries but does not work with MySQL versions before 4.0.0
 134          // delete all asset, all learning path module, and from module table
 135          /*
 136          claro_sql_query("DELETE
 137                         FROM `".$TABLEASSET."`, `".$TABLELEARNPATHMODULE."`, `".$TABLEMODULE."`
 138                        WHERE `module_id` = ".$_REQUEST['cmdid'] );
 139          */
 140  
 141          // delete directory and it content
 142          claro_delete_file($moduleWorkDir."/module_".(int)$_REQUEST['cmdid']);
 143          break;
 144  
 145      // COMMAND RENAME :
 146      //display the form to enter new name
 147      case "rqRename" :
 148          //get current name from DB
 149          $query= "SELECT `name`
 150                   FROM `".$TABLEMODULE."`
 151                   WHERE `module_id` = '". (int)$_REQUEST['module_id']."'";
 152          $result = claro_sql_query($query);
 153          $list = mysql_fetch_array($result);
 154          echo "\n" 
 155          .     '<form method="post" name="rename" action="'.$_SERVER['PHP_SELF'].'">' . "\n"
 156          .    claro_form_relay_context()
 157          .     '<label for="newName">'.get_lang('Insert new name').'</label> :' . "\n"
 158          .     '<input type="text" name="newName" id="newName" value="'.htmlspecialchars($list['name']).'" />' . "\n"
 159          .     '<input type="submit" value="'.get_lang('Ok').'" name="submit" />' . "\n"
 160          .     '<input type="hidden" name="cmd" value="exRename" />' . "\n"
 161          .     '<input type="hidden" name="module_id" value="'.$_REQUEST['module_id'].'" />' . "\n"
 162          .     '</form>' . "\n\n";
 163          break;
 164  
 165       //try to change name for selected module
 166      case "exRename" :
 167          //check if newname is empty
 168          if( isset($_REQUEST["newName"]) && $_REQUEST["newName"] != "" )
 169          {
 170              //check if newname is not already used in another module of the same course
 171              $sql="SELECT `name`
 172                    FROM `".$TABLEMODULE."`
 173                    WHERE `name` = '". addslashes($_POST['newName'])."'
 174                      AND `module_id` != '". (int)$_REQUEST['module_id']."'";
 175  
 176              $query = claro_sql_query($sql);
 177              $num = mysql_num_rows($query);
 178              if($num == 0 ) // "name" doesn't already exist
 179              {
 180                  // if no error occurred, update module's name in the database
 181                  $query="UPDATE `".$TABLEMODULE."`
 182                          SET `name`= '". addslashes($_POST['newName'])."'
 183                          WHERE `module_id` = '". (int)$_REQUEST['module_id']."'";
 184  
 185                  $result = claro_sql_query($query);
 186              }
 187              else
 188              {
 189                  echo claro_html_message_box(get_lang('Error : Name already exists in the learning path or in the module pool'));
 190                  echo "<br />";
 191              }
 192          }
 193          else
 194          {
 195              echo claro_html_message_box(get_lang('Name cannot be empty'));
 196              echo "<br />";
 197          }
 198          break;
 199  
 200      //display the form to modify the comment
 201      case "rqComment" :
 202          if( isset($_REQUEST['module_id']) )
 203          {
 204              //get current comment from DB
 205              $query="SELECT `comment`
 206                      FROM `".$TABLEMODULE."`
 207                      WHERE `module_id` = '". (int)$_REQUEST['module_id']."'";
 208              $result = claro_sql_query($query);
 209              $comment = mysql_fetch_array($result);
 210  
 211              if( isset($comment['comment']) )
 212              {
 213                  echo "<form method=\"get\" action=\"".$_SERVER['PHP_SELF']."\">\n"
 214                  .    claro_form_relay_context()
 215                      .claro_html_textarea_editor('comment', $comment['comment'], 15, 55)
 216                      ."<br />\n"
 217                      ."<input type=\"hidden\" name=\"cmd\" value=\"exComment\">\n"
 218                      ."<input type=\"hidden\" name=\"module_id\" value=\"".$_REQUEST['module_id']."\">\n"
 219                      ."<input type=\"submit\" value=\"".get_lang('Ok')."\">\n"
 220                      ."<br /><br />\n"
 221                      ."</form>\n";
 222              }
 223          } // else no module_id
 224          break;
 225  
 226      //make update to change the comment in the database for this module
 227      case "exComment":
 228          if( isset($_REQUEST['module_id']) && isset($_REQUEST['comment']) )
 229          {
 230              $sql = "UPDATE `".$TABLEMODULE."`
 231                      SET `comment` = \"". addslashes($_REQUEST['comment']) ."\"
 232                      WHERE `module_id` = '". (int)$_REQUEST['module_id']."'";
 233              claro_sql_query($sql);
 234          }
 235          break;
 236  }
 237  
 238  $sql = "SELECT M.*,
 239                 count(M.`module_id`) AS timesUsed
 240          FROM `" . $TABLEMODULE . "` AS M
 241            LEFT JOIN `".$TABLELEARNPATHMODULE."` AS LPM ON LPM.`module_id` = M.`module_id`
 242          WHERE M.`contentType` != '".CTSCORM_."'
 243            AND M.`contentType` != '".CTLABEL_."'
 244          GROUP BY M.`module_id`
 245          ORDER BY M.`name` ASC, M.`contentType`ASC, M.`accessibility` ASC";
 246  
 247  $result = claro_sql_query($sql);
 248  $atleastOne = false;
 249  
 250  
 251  echo '<table class="claroTable" width="100%" border="0" cellspacing="2">'
 252  .    '<thead>' . "\n"
 253  .    '<tr class="headerX" align="center" valign="top">' . "\n"
 254  .    '<th>' . "\n"
 255  .    get_lang('Module') . "\n"
 256  .    '</th>' . "\n"
 257  .    '<th>' . "\n"
 258  .    get_lang('Delete') . "\n"
 259  .    '</th>' . "\n"
 260  .    '<th>' . "\n"
 261  .    get_lang('Rename') . "\n"
 262  .    '</th>' . "\n"
 263  .    '<th>' . "\n"
 264  .    get_lang('Comment') . "\n"
 265  .    '</th>' . "\n"
 266  .    '</tr>' . "\n"
 267  .    '</thead>' . "\n"
 268  .    '<tbody>' . "\n"
 269  ;
 270  
 271  // Display modules of the pool of this course
 272  
 273  while ($list = mysql_fetch_array($result))
 274  {
 275      //DELETE , RENAME, COMMENT
 276  
 277      $contentType_img = selectImage($list['contentType']);
 278      $contentType_alt = selectAlt($list['contentType']);
 279      echo '<tr>' . "\n"
 280      .     '<td align="left">' . "\n"
 281      .     '<img src="' . get_path('imgRepositoryWeb') . $contentType_img.'" alt="'.$contentType_alt.'" />'.$list['name'] . "\n"
 282      .     '</td>' . "\n"
 283      .     '<td align="center">' . "\n"
 284      .     '<a href="'.$_SERVER['PHP_SELF'].'?cmd=eraseModule&amp;cmdid='.$list['module_id'].'"'
 285      .     ' onClick="return confirmation(\''.clean_str_for_javascript($list['name']).'\', \''.$list['timesUsed'] .'\');">'
 286      .     '<img src="' . get_path('imgRepositoryWeb') . 'delete.gif" border="0" alt="'.get_lang('Delete').'" />'
 287      .     '</a>' . "\n"
 288      .     '</td>' . "\n"
 289      .     '<td align="center">' . "\n"
 290      .     '<a href="'.$_SERVER['PHP_SELF'].'?cmd=rqRename&amp;module_id='.$list['module_id'].'"><img src="' . get_path('imgRepositoryWeb') . 'edit.gif" border="0" alt="'.get_lang('Rename').'" /></a>' . "\n"
 291      .     '</td>' . "\n"
 292      .     '<td align="center">' . "\n"
 293      .     '<a href="'.$_SERVER['PHP_SELF'].'?cmd=rqComment&amp;module_id='.$list['module_id'].'"><img src="' . get_path('imgRepositoryWeb') . 'comment.gif" border="0" alt="'.get_lang('Comment').'" /></a>' . "\n"
 294      .     '</td>' . "\n"
 295      .     '</tr>' . "\n\n";
 296  
 297      if ( isset($list['comment']) )
 298      {
 299          echo '<tr>'
 300          .    '<td colspan="5">'
 301          .    '<small>' . $list['comment'] . '</small>'
 302          .    '</td>'
 303          .    '</tr>'
 304          ;
 305      }
 306  
 307      $atleastOne = true;
 308  
 309  } //end while another module to display
 310  
 311  if ($atleastOne == false) 
 312  {
 313      echo '<tr><td align="center" colspan="5">'.get_lang('No module').'</td></tr>' . "\n";
 314  }
 315  
 316  // Display button to add selected modules
 317  
 318  echo '</tbody>' . "\n"
 319  .    '</table>'
 320  ;
 321  
 322  // footer
 323  
 324  include get_path('incRepositorySys') . '/claro_init_footer.inc.php';
 325  ?>


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