scorm_admin.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414
  1. <?php //$id: $
  2. /*
  3. ==============================================================================
  4. Dokeos - elearning and course management software
  5. Copyright (c) 2004 Dokeos S.A.
  6. Copyright (c) 2004 Denes Nagy
  7. Copyright (c) 2003 Ghent University (UGent)
  8. Copyright (c) 2001 Universite catholique de Louvain (UCL)
  9. For a full list of contributors, see "credits.txt".
  10. The full license can be read in "license.txt".
  11. This program is free software; you can redistribute it and/or
  12. modify it under the terms of the GNU General Public License
  13. as published by the Free Software Foundation; either version 2
  14. of the License, or (at your option) any later version.
  15. See the GNU General Public License for more details.
  16. Contact: Dokeos, 181 rue Royale, B-1000 Brussels, Belgium, info@dokeos.com
  17. ==============================================================================
  18. */
  19. /**
  20. ==============================================================================
  21. * This script handles SCO administration features
  22. * @package dokeos.learnpath.scorm
  23. * @author Denes Nagy, principal author
  24. * @author Isthvan Mandak, several new features
  25. * @author Roan Embrechts, code improvements and refactoring
  26. * @author Yannick Warnier, complete refactoring <ywarnier@beeznest.org>
  27. ==============================================================================
  28. */
  29. /**
  30. * Script init
  31. */
  32. //flag to allow for anonymous user - needs to be set before global.inc.php
  33. $use_anonymous = true;
  34. // name of the language file that needs to be included
  35. $language_file = "scormdocument";
  36. $uncompress=1; //this variable shouldn't be found here (find its usage before removal)
  37. require_once('back_compat.inc.php');
  38. include('learnpath_functions.inc.php');
  39. include_once('scorm.lib.php');
  40. $is_allowedToEdit = api_is_allowed_to_edit();
  41. /**
  42. * Variables
  43. */
  44. //escapable integers
  45. if($_REQUEST['id'] != strval(intval($_REQUEST['id']))){$id = $_REQUEST['id'];}else{$id=null;}
  46. //imported strings
  47. $path = (!empty($_REQUEST['path'])?$_REQUEST['path']:null);
  48. $Submit = (!empty($_POST['Submit'])?$_POST['Submit']:null);
  49. $submitImage = (!empty($_POST['submitImage'])?$_POST['submitImage']:null);
  50. $cancelSubmitImage = (!empty($_POST['cancelSubmitImage'])?$_POST['cancelSubmitImage']:null);
  51. $action = (!empty($_REQUEST['action'])?$_REQUEST['action']:null);
  52. $delete = (!empty($_REQUEST['delete'])?$_REQUEST['delete']:null);
  53. $createDir = (!empty($_REQUEST['createDir'])?$_REQUEST['createDir']:null);
  54. $make_directory_visible = (!empty($_REQUEST['make_directory_visible'])?$_REQUEST['make_directory_visible']:'');
  55. $make_directory_invisible = (!empty($_REQUEST['make_directory_invisible'])?$_REQUEST['make_directory_invisible']:'');
  56. //values from POST form to add directory
  57. $newDirPath = (!empty($_POST['newDirPath'])?$_POST['newDirPath']:null);
  58. $newDirName = (!empty($_POST['newDirName'])?$_POST['newDirName']:null);
  59. //initialising internal variables
  60. $dialogbox = '';
  61. if (! $is_allowed_in_course) api_not_allowed();
  62. $is_allowedToUnzip = $is_courseAdmin;
  63. /**
  64. * Main code
  65. */
  66. switch($action){
  67. case 'exportpath':
  68. if(!empty($id)){
  69. $export = exportpath($id);
  70. $dialogBox .= "This LP has been exported to the Document folder "
  71. ."of your course.";
  72. }
  73. break;
  74. case 'exportscorm':
  75. exportSCORM($path);
  76. break;
  77. case 'deletepath':
  78. /*==================================================
  79. DELETE A DOKEOS LEARNPATH
  80. and all the items in it
  81. ==================================================*/
  82. if(!empty($id)){
  83. $l="learnpath/learnpath_handler.php?learnpath_id=$id";
  84. $sql="DELETE FROM $tbl_tool where (link='$l' AND image='scormbuilder.gif')";
  85. $result=api_sql_query($sql,__FILE__,__LINE__);
  86. $sql="SELECT * FROM $tbl_learnpath_chapter where learnpath_id=$id";
  87. $result=api_sql_query($sql,__FILE__,__LINE__);
  88. while ($row=mysql_fetch_array($result))
  89. {
  90. $c=$row['id'];
  91. $sql2="DELETE FROM $tbl_learnpath_item where chapter_id=$c";
  92. $result2=api_sql_query($sql2,__FILE__,__LINE__);
  93. }
  94. $sql="DELETE FROM $tbl_learnpath_chapter where learnpath_id=$id";
  95. $result=api_sql_query($sql,__FILE__,__LINE__);
  96. deletepath($id);
  97. $dialogBox=get_lang('_learnpath_deleted');
  98. }
  99. break;
  100. case 'publishpath':
  101. /*==================================================================
  102. PUBLISHING (SHOWING) A DOKEOS LEARNPATH
  103. ==================================================================*/
  104. if(!empty($id)){
  105. $sql="SELECT * FROM $tbl_learnpath_main where learnpath_id=$id";
  106. $result=api_sql_query($sql,__FILE__,__LINE__);
  107. $row=mysql_fetch_array($result);
  108. $name=domesticate($row['learnpath_name']);
  109. if ($set_visibility == 'i') {
  110. $s=$name." ".get_lang('_no_published');
  111. $dialogBox=$s;
  112. $v=0;
  113. }
  114. if ($set_visibility == 'v') {
  115. $s=$name." ".get_lang('_published');
  116. $dialogBox=$s;
  117. $v=1;
  118. }
  119. $sql="SELECT * FROM $tbl_tool where (name='$name' and image='scormbuilder.gif')";
  120. $result=api_sql_query($sql,__FILE__,__LINE__);
  121. $row2=mysql_fetch_array($result);
  122. $num=mysql_num_rows($result);
  123. if (($set_visibility == 'i') && ($num>0))
  124. {
  125. //it is visible or hidden but once was published
  126. if (($row2['visibility'])==1)
  127. {
  128. $sql ="DELETE FROM $tbl_tool WHERE (name='$name' and image='scormbuilder.gif')";
  129. }
  130. else
  131. {
  132. $sql ="UPDATE $tbl_tool set visibility=1 WHERE (name='$name' and image='scormbuilder.gif')";
  133. }
  134. }
  135. elseif (($set_visibility == 'v') && ($num==0))
  136. {
  137. $sql ="INSERT INTO $tbl_tool (id, name, link, image, visibility, admin, address, added_tool) VALUES ('$theid','$name','learnpath/learnpath_handler.php?learnpath_id=$id','scormbuilder.gif','$v','0','pastillegris.gif',0)";
  138. }
  139. else
  140. {
  141. //parameter and database incompatible, do nothing
  142. }
  143. $result=api_sql_query($sql,__FILE__,__LINE__);
  144. }
  145. break;
  146. case 'editpath':
  147. /*==================================================================
  148. EDITING A DOKEOS NEW LEARNPATH
  149. ==================================================================*/
  150. if(!empty($Submit))
  151. {
  152. $l="learnpath/learnpath_handler.php?learnpath_id=$id";
  153. $sql="UPDATE $tbl_tool set name='".domesticate($learnpath_name)."' where (link='$l' and image='scormbuilder.gif')";
  154. $result=api_sql_query($sql,__FILE__,__LINE__);
  155. $sql ="UPDATE $tbl_learnpath_main SET learnpath_name='".domesticate($learnpath_name)."', learnpath_description='".domesticate($learnpath_description)."' WHERE learnpath_id=$id";
  156. $result=api_sql_query($sql,__FILE__,__LINE__);
  157. $dialogBox=get_lang('_learnpath_edited');
  158. }
  159. break;
  160. case 'add':
  161. /*==================================================================
  162. ADDING A NEW LEARNPATH : treating the form
  163. ==================================================================*/
  164. if (!empty($Submit))
  165. {
  166. $sql ="INSERT INTO $tbl_learnpath_main (learnpath_name, learnpath_description) VALUES ('".domesticate($learnpath_name)."','".domesticate($learnpath_description)."')";
  167. api_sql_query($sql,__FILE__,__LINE__);
  168. $my_lp_id = Database::get_last_insert_id();
  169. $sql ="INSERT INTO $tbl_tool (name, link, image, visibility, admin, address, added_tool) VALUES ('".domesticate($learnpath_name)."','learnpath/learnpath_handler.php?learnpath_id=$my_lp_id','scormbuilder.gif','1','0','pastillegris.gif',0)";
  170. api_sql_query($sql,__FILE__,__LINE__);
  171. //instead of displaying this info text, get the user directly to the learnpath edit page
  172. //$dialogBox=get_lang('_learnpath_added');
  173. header('location:../learnpath/learnpath_handler.php?'.api_get_cidreq().'&learnpath_id='.$my_lp_id);
  174. exit();
  175. }
  176. break;
  177. case 'editscorm':
  178. /*==================================================================
  179. EDITING A SCORM PACKAGE
  180. ==================================================================*/
  181. if (!empty($Submit))
  182. {
  183. $sql ="UPDATE $tbl_document SET comment='".domesticate($learnpath_description)."', name='".domesticate($learnpath_name)."' WHERE path='$path'";
  184. $result=api_sql_query($sql,__FILE__,__LINE__);
  185. $dialogBox=get_lang('_learnpath_edited');
  186. }
  187. break;
  188. default:
  189. break;
  190. }
  191. /*============================================================================*/
  192. if($is_allowedToEdit) // TEACHER ONLY
  193. {
  194. /*======================================
  195. UPLOAD SCORM
  196. ======================================*/
  197. /*
  198. * Check the request method instead of a variable from POST
  199. * because if the file size exceeds the maximum file upload
  200. * size set in php.ini, all variables from POST are cleared !
  201. */
  202. if ($_SERVER['REQUEST_METHOD'] == 'POST'
  203. && count($_FILES)>0
  204. && empty($submitImage)
  205. && empty($cancelSubmitImage)
  206. && empty($action))
  207. {
  208. // A SCORM upload has been detected, now deal with the file...
  209. //directory creation
  210. $s=$_FILES['userFile']['name'];
  211. $pathInfo = pathinfo($s);
  212. //Check the filename has at least several letters in it :-)
  213. //This is a very loose check as later on we might accept other formats of packages
  214. //sent than just "zip"
  215. if(preg_match('/[\w-_]+/',$pathInfo['basename'])){
  216. //get the basename without extension
  217. $newDirName=substr(
  218. $pathInfo['basename'],
  219. 0,
  220. strlen($pathInfo['basename'])-(strlen($pathInfo['extension'])+1));
  221. $newDirName = replace_dangerous_char(trim($newDirName),'strict');
  222. if( check_name_exist($baseWorkDir.$newDirPath.$openDir."/".$newDirName) )
  223. {
  224. /** @todo change this output. Inaccurate at least in french. In this case, the
  225. * file might not exist or the transfer might have been wrong (no $_FILES at all)
  226. * but we still get the error message
  227. */
  228. $dialogBox = get_lang('FileExists');
  229. $createDir = $newDirPath; unset($newDirPath);// return to step 1
  230. }
  231. else
  232. {
  233. if(mkdir($baseWorkDir.$newDirPath.$openDir."/".$newDirName, 0700)){
  234. FileManager::set_default_settings($newDirPath.$openDir, $newDirName, "folder", $tbl_document);
  235. // RH: was: set_default_settings($newDirPath.$openDir,$newDirName,"folder");
  236. $dialogBox = get_lang('DirCr');
  237. }else{
  238. //Display msg "could not create dir..."
  239. //exit();
  240. }
  241. //directory creation end
  242. $uploadPath=$openDir.'/'.$newDirName;
  243. if(!$_FILES['userFile']['size'])
  244. {
  245. $dialogBox .= get_lang('FileError').'<br />'.get_lang('Notice').' : '.get_lang('MaxFileSize').' '.ini_get('upload_max_filesize');
  246. }
  247. else //the file size is alright, we can assume the file is OK too
  248. {
  249. if($uncompress == 1 && $is_allowedToUnzip)
  250. {
  251. $unzip = 'unzip';
  252. }
  253. else
  254. {
  255. $unzip = '';
  256. }
  257. if (treat_uploaded_file($_FILES['userFile'], $baseWorkDir,
  258. $uploadPath, $maxFilledSpace, $unzip))
  259. {
  260. if ($uncompress == 1)
  261. {
  262. //$dialogBox .= get_lang('DownloadAndZipEnd');
  263. //modified by darkden : I omitted this part, so the user can see
  264. //the scorm content message at once
  265. }
  266. else
  267. {
  268. $dialogBox = get_lang('DownloadEnd');
  269. }
  270. // "WHAT'S NEW" notification: update table last_tooledit
  271. //update_last_tooledit($_course, $nameTools, $id, get_lang('_new_document'), $_user['user_id']);
  272. item_property_update($_course, TOOL_LEARNPATH, $id, "LearnpathAdded", $_user['user_id']);
  273. }
  274. else
  275. {
  276. if(api_failure::get_last_failure() == 'not_enough_space')
  277. {
  278. $dialogBox = get_lang('NoSpace');
  279. }
  280. elseif (api_failure::get_last_failure() == 'php_file_in_zip_file')
  281. {
  282. $dialogBox = get_lang('ZipNoPhp');
  283. }
  284. elseif(api_failure::get_last_failure() == 'not_scorm_content')
  285. {
  286. $dialogBox = get_lang('NotScormContent');
  287. }
  288. }
  289. }
  290. $uploadPath='';
  291. if (api_failure::get_last_failure())
  292. {
  293. rmdir($baseWorkDir.$newDirPath.$openDir."/".$newDirName);
  294. }
  295. }
  296. }//
  297. else
  298. {//the filename doesn't contain any alphanum chars (empty filename?)
  299. //get a more detailed message?
  300. $dialogBox .= get_lang('FileError').'<br />';
  301. }
  302. /*======================================
  303. DELETE FILE OR DIRECTORY
  304. ======================================*/
  305. if ( isset($delete) )
  306. {
  307. if ( scorm_delete($baseWorkDir.$delete))
  308. {
  309. //$tbl_document = substr($tbl_document, 1, strlen($tbl_document) - 2); // RH...
  310. update_db_info("delete", $delete);
  311. $dialogBox = get_lang('DocDeleted');
  312. }
  313. }
  314. /*======================================
  315. CREATE DIRECTORY
  316. ======================================*/
  317. /*
  318. * The code begin with STEP 2 so it allows to return to STEP 1
  319. * if STEP 2 unsucceds
  320. */
  321. /*-------------------------------------
  322. STEP 2
  323. --------------------------------------*/
  324. if (isset($newDirPath) && isset($newDirName))
  325. {
  326. // echo $newDirPath . $newDirName;
  327. $newDirName = replace_dangerous_char(trim(stripslashes($newDirName)),'strict');
  328. if( check_name_exist($baseWorkDir.$newDirPath."/".$newDirName) )
  329. {
  330. $dialogBox = get_lang('FileExists');
  331. $createDir = $newDirPath; unset($newDirPath);// return to step 1
  332. }
  333. else
  334. {
  335. if(mkdir($baseWorkDir.$newDirPath."/".$newDirName, 0700))
  336. FileManager::set_default_settings($newDirPath, $newDirName, "folder", $tbl_document);
  337. // RH: was: set_default_settings($newDirPath,$newDirName,"folder");
  338. $dialogBox = get_lang('DirCr');
  339. }
  340. }
  341. /*-------------------------------------
  342. STEP 1
  343. --------------------------------------*/
  344. if (isset($createDir))
  345. {
  346. $dialogBox .= "<!-- create dir -->\n"
  347. ."<form name='createdir' action='' method='POST'>\n"
  348. ."<input type=\"hidden\" name=\"newDirPath\" value=\"$createDir\" />\n"
  349. .get_lang('NameDir')." : \n"
  350. ."<input type=\"text\" name=\"newDirName\" />\n"
  351. ."<input type=\"submit\" value=\"".get_lang('Ok')."\" />\n"
  352. ."</form>\n";
  353. }
  354. /*======================================
  355. VISIBILITY COMMANDS
  356. ======================================*/
  357. if (!empty($make_directory_visible) || !empty($make_directory_invisible))
  358. {
  359. $visibilityPath = $make_directory_visible.$make_directory_invisible;
  360. // At least one of these variables are empty. So it's okay to proceed this way
  361. /* Check if there is yet a record for this file in the DB */
  362. $result = mysql_query ("SELECT * FROM $tbl_document WHERE path LIKE '".$visibilityPath."'");
  363. while($row = mysql_fetch_array($result, MYSQL_ASSOC))
  364. {
  365. $attribute['path' ] = $row['path' ];
  366. $attribute['visibility'] = $row['visibility'];
  367. $attribute['comment' ] = $row['comment' ];
  368. }
  369. if ($make_directory_visible)
  370. {
  371. $newVisibilityStatus = "v";
  372. }
  373. elseif ($make_directory_invisible)
  374. {
  375. $newVisibilityStatus = "i";
  376. }
  377. $query = "UPDATE $tbl_document SET visibility='$newVisibilityStatus' WHERE path=\"".$visibilityPath."\""; //added by Toon
  378. api_sql_query($query,__FILE__,__LINE__);
  379. if (mysql_affected_rows() == 0) // extra check added by Toon, normally not necessary anymore because all files are in the db
  380. {
  381. api_sql_query("INSERT INTO $tbl_document SET path=\"".$visibilityPath."\", visibility=\"".$newVisibilityStatus."\"",__FILE__,__LINE__);
  382. }
  383. unset($attribute);
  384. $dialogBox = get_lang('ViMod');
  385. }
  386. } // END is Allowed to Edit;
  387. }
  388. ?>