scorm_admin.php 15 KB

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