scorm_admin.php 15 KB

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