CourseSelectForm.class.php 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. require_once 'Course.class.php';
  4. /**
  5. * Class to show a form to select resources
  6. * @author Bart Mollet <bart.mollet@hogent.be>
  7. * @author Julio Montoya <gugli100@gmail.com>
  8. * @package chamilo.backup
  9. */
  10. class CourseSelectForm
  11. {
  12. /**
  13. * Display the form
  14. * @param array $hidden_fiels Hidden fields to add to the form.
  15. * @param boolean the document array will be serialize. This is used in the course_copy.php file
  16. */
  17. static function display_form($course, $hidden_fields = null, $avoid_serialize = false)
  18. {
  19. global $charset;
  20. $resource_titles[RESOURCE_EVENT] = get_lang('Events');
  21. $resource_titles[RESOURCE_ANNOUNCEMENT] = get_lang('Announcements');
  22. $resource_titles[RESOURCE_DOCUMENT] = get_lang('Documents');
  23. $resource_titles[RESOURCE_LINK] = get_lang('Links');
  24. $resource_titles[RESOURCE_COURSEDESCRIPTION] = get_lang('CourseDescription');
  25. $resource_titles[RESOURCE_FORUM] = get_lang('Forums');
  26. $resource_titles[RESOURCE_FORUMCATEGORY] = get_lang('ForumCategory');
  27. $resource_titles[RESOURCE_QUIZ] = get_lang('Tests');
  28. $resource_titles[RESOURCE_TEST_CATEGORY] = get_lang('QuestionCategory');
  29. $resource_titles[RESOURCE_LEARNPATH] = get_lang('ToolLearnpath');
  30. $resource_titles[RESOURCE_SCORM] = 'SCORM';
  31. $resource_titles[RESOURCE_TOOL_INTRO] = get_lang('ToolIntro');
  32. $resource_titles[RESOURCE_SURVEY] = get_lang('Survey');
  33. $resource_titles[RESOURCE_GLOSSARY] = get_lang('Glossary');
  34. $resource_titles[RESOURCE_WIKI] = get_lang('Wiki');
  35. $resource_titles[RESOURCE_THEMATIC] = get_lang('Thematic');
  36. $resource_titles[RESOURCE_ATTENDANCE] = get_lang('Attendance');
  37. $resource_titles[RESOURCE_WORK] = get_lang('ToolStudentPublication');
  38. $iconPath = api_get_path(WEB_IMG_PATH);
  39. ?>
  40. <script>
  41. function exp(item) {
  42. el = document.getElementById('div_'+item);
  43. if (el.style.display=='none'){
  44. el.style.display='';
  45. document.getElementById('img_'+item).src='<?php echo $iconPath; ?>1.gif';
  46. }
  47. else{
  48. el.style.display='none';
  49. document.getElementById('img_'+item).src='<?php echo $iconPath; ?>0.gif';
  50. }
  51. }
  52. function setCheckboxForum(type, value, item_id) {
  53. d = document.course_select_form;
  54. for (i = 0; i < d.elements.length; i++) {
  55. if (d.elements[i].type == "checkbox") {
  56. var name = d.elements[i].attributes.getNamedItem('name').nodeValue;
  57. if( name.indexOf(type) > 0 || type == 'all' ){
  58. if ($(d.elements[i]).attr('rel') == item_id) {
  59. d.elements[i].checked = value;
  60. }
  61. }
  62. }
  63. }
  64. }
  65. function setCheckbox(type,value) {
  66. d = document.course_select_form;
  67. for (i = 0; i < d.elements.length; i++) {
  68. if (d.elements[i].type == "checkbox") {
  69. var name = d.elements[i].attributes.getNamedItem('name').nodeValue;
  70. if( name.indexOf(type) > 0 || type == 'all' ){
  71. d.elements[i].checked = value;
  72. }
  73. }
  74. }
  75. }
  76. function checkLearnPath(message){
  77. d = document.course_select_form;
  78. for (i = 0; i < d.elements.length; i++) {
  79. if (d.elements[i].type == "checkbox") {
  80. var name = d.elements[i].attributes.getNamedItem('name').nodeValue;
  81. if( name.indexOf('learnpath') > 0){
  82. if(d.elements[i].checked){
  83. setCheckbox('document',true);
  84. alert(message);
  85. break;
  86. }
  87. }
  88. }
  89. }
  90. }
  91. function check_forum(obj) {
  92. var id = $(obj).attr('rel');
  93. var my_id = $(obj).attr('my_rel');
  94. var checked = false;
  95. if ($('#resource_forum_'+my_id).attr('checked')) {
  96. checked = true;
  97. }
  98. setCheckboxForum('thread', checked, my_id);
  99. $('#resource_Forum_Category_'+id).attr('checked','checked');
  100. }
  101. function check_category(obj) {
  102. var my_id = $(obj).attr('my_rel');
  103. var checked = false;
  104. if ($('#resource_Forum_Category_'+my_id).attr('checked')) {
  105. checked = true;
  106. }
  107. $('.resource_forum').each(function(index, value) {
  108. if ($(value).attr('rel') == my_id) {
  109. $(value).attr('checked', checked);
  110. }
  111. });
  112. $('.resource_topic').each(function(index, value) {
  113. if ($(value).attr('cat_id') == my_id) {
  114. $(value).attr('checked', checked);
  115. }
  116. });
  117. }
  118. function check_topic(obj) {
  119. var my_id = $(obj).attr('cat_id');
  120. var forum_id = $(obj).attr('forum_id');
  121. $('#resource_Forum_Category_'+my_id).attr('checked','checked');
  122. $('#resource_forum_'+forum_id).attr('checked','checked');
  123. }
  124. </script>
  125. <?php
  126. //get destination course title
  127. if (!empty($hidden_fields['destination_course'])) {
  128. $course_infos = CourseManager::get_course_information($hidden_fields['destination_course']);
  129. echo '<h3>';
  130. echo get_lang('DestinationCourse').' : '.$course_infos['title'];
  131. echo '</h3>';
  132. }
  133. echo '<script type="text/javascript">var myUpload = new upload(1000);</script>';
  134. echo '<form method="post" id="upload_form" name="course_select_form" onsubmit="javascript: myUpload.start(\'dynamic_div\', \'\' ,\''.get_lang('PleaseStandBy', '').'\',\'upload_form\')">';
  135. echo '<input type="hidden" name="action" value="course_select_form"/>';
  136. if (!empty($hidden_fields['destination_course']) &&
  137. !empty($hidden_fields['origin_course']) &&
  138. !empty($hidden_fields['destination_session']) &&
  139. !empty($hidden_fields['origin_session'])
  140. ) {
  141. echo '<input type="hidden" name="destination_course" value="'.$hidden_fields['destination_course'].'"/>';
  142. echo '<input type="hidden" name="origin_course" value="'.$hidden_fields['origin_course'].'"/>';
  143. echo '<input type="hidden" name="destination_session" value="'.$hidden_fields['destination_session'].'"/>';
  144. echo '<input type="hidden" name="origin_session" value="'.$hidden_fields['origin_session'].'"/>';
  145. }
  146. $element_count = 0;
  147. $forum_categories = array();
  148. $forums = array();
  149. $forum_topics = array();
  150. echo '<p>';
  151. echo get_lang('SelectResources');
  152. echo '</p>';
  153. Display::display_normal_message(get_lang('DontForgetToSelectTheMediaFilesIfYourResourceNeedIt'));
  154. foreach ($course->resources as $type => $resources) {
  155. if (count($resources) > 0) {
  156. switch ($type) {
  157. //Resources to avoid
  158. case RESOURCE_FORUMCATEGORY :
  159. foreach ($resources as $id => $resource) {
  160. $forum_categories[$id] = $resource;
  161. }
  162. $element_count++;
  163. break;
  164. case RESOURCE_FORUM:
  165. foreach ($resources as $id => $resource) {
  166. $forums[$resource->obj->forum_category][$id] = $resource;
  167. }
  168. $element_count++;
  169. break;
  170. case RESOURCE_FORUMTOPIC:
  171. foreach ($resources as $id => $resource) {
  172. $forum_topics[$resource->obj->forum_id][$id] = $resource;
  173. }
  174. $element_count++;
  175. break;
  176. case RESOURCE_LINKCATEGORY :
  177. case RESOURCE_FORUMPOST :
  178. case RESOURCE_QUIZQUESTION:
  179. case RESOURCE_SURVEYQUESTION:
  180. case RESOURCE_SURVEYINVITATION:
  181. case RESOURCE_SCORM:
  182. break;
  183. default :
  184. echo '<img id="img_'.$type.'" src="'.$iconPath.'1.gif" onclick="javascript:exp('."'$type'".');" />&nbsp;';
  185. echo '<b onclick="javascript:exp('."'$type'".');" >'.$resource_titles[$type].'</b><br />';
  186. echo '<div id="div_'.$type.'">';
  187. if ($type == RESOURCE_LEARNPATH) {
  188. Display::display_warning_message(get_lang('ToExportLearnpathWithQuizYouHaveToSelectQuiz'));
  189. Display::display_warning_message(get_lang('IfYourLPsHaveAudioFilesIncludedYouShouldSelectThemFromTheDocuments'));
  190. }
  191. if ($type == RESOURCE_DOCUMENT) {
  192. if (api_get_setting('show_glossary_in_documents') != 'none') {
  193. Display::display_warning_message(get_lang('ToExportDocumentsWithGlossaryYouHaveToSelectGlossary'));
  194. }
  195. }
  196. echo '<blockquote>';
  197. echo '<div class="btn-group">';
  198. echo "<a class=\"btn\" href=\"javascript: void(0);\" onclick=\"javascript: setCheckbox('$type',true);\" >".get_lang('All')."</a>";
  199. echo "<a class=\"btn\" href=\"javascript: void(0);\" onclick=\"javascript:setCheckbox('$type',false);\" >".get_lang('None')."</a>";
  200. echo '</div><br />';
  201. foreach ($resources as $id => $resource) {
  202. if ($resource) {
  203. echo '<label class="checkbox">';
  204. echo '<input type="checkbox" name="resource['.$type.']['.$id.']" id="resource['.$type.']['.$id.']" />';
  205. $resource->show();
  206. echo '</label>';
  207. }
  208. }
  209. echo '</blockquote>';
  210. echo '</div>';
  211. echo '<script language="javascript">exp('."'$type'".')</script>';
  212. $element_count++;
  213. }
  214. }
  215. }
  216. //Fixes forum order
  217. if (!empty($forum_categories)) {
  218. $type = RESOURCE_FORUMCATEGORY;
  219. echo '<img id="img_'.$type.'" src="'.$iconPath.'1.gif" onclick="javascript:exp('."'$type'".');" />&nbsp;';
  220. echo '<b onclick="javascript:exp('."'$type'".');" >'.$resource_titles[RESOURCE_FORUM].'</b><br />';
  221. echo '<div id="div_'.$type.'">';
  222. echo '<ul>';
  223. foreach ($forum_categories as $forum_category_id => $forum_category) {
  224. echo '<li>';
  225. echo '<label class="checkbox">';
  226. echo '<input type="checkbox" id="resource_'.RESOURCE_FORUMCATEGORY.'_'.$forum_category_id.'" my_rel="'.$forum_category_id.'" onclick="javascript:check_category(this);" name="resource['.RESOURCE_FORUMCATEGORY.']['.$forum_category_id.']" /> ';
  227. $forum_category->show();
  228. echo '</label>';
  229. echo '</li>';
  230. if (isset($forums[$forum_category_id])) {
  231. $my_forums = $forums[$forum_category_id];
  232. echo '<ul>';
  233. foreach ($my_forums as $forum_id => $forum) {
  234. echo '<li>';
  235. echo '<label class="checkbox">';
  236. echo '<input type="checkbox" class="resource_forum" id="resource_'.RESOURCE_FORUM.'_'.$forum_id.'" onclick="javascript:check_forum(this);" my_rel="'.$forum_id.'" rel="'.$forum_category_id.'" name="resource['.RESOURCE_FORUM.']['.$forum_id.']" />';
  237. $forum->show();
  238. echo '</label>';
  239. echo '</li>';
  240. if (isset($forum_topics[$forum_id])) {
  241. $my_forum_topics = $forum_topics[$forum_id];
  242. if (!empty($my_forum_topics)) {
  243. echo '<ul>';
  244. foreach ($my_forum_topics as $topic_id => $topic) {
  245. echo '<li>';
  246. echo '<label class="checkbox">';
  247. echo '<input type="checkbox" id="resource_'.RESOURCE_FORUMTOPIC.'_'.$topic_id.'" onclick="javascript:check_topic(this);" class="resource_topic" forum_id="'.$forum_id.'" rel="'.$forum_id.'" cat_id="'.$forum_category_id.'" name="resource['.RESOURCE_FORUMTOPIC.']['.$topic_id.']" />';
  248. $topic->show();
  249. echo '</label>';
  250. echo '</li>';
  251. }
  252. echo '</ul>';
  253. }
  254. }
  255. }
  256. echo '</ul>';
  257. }
  258. echo '<hr/>';
  259. }
  260. echo '</ul>';
  261. echo '</div>';
  262. echo '<script language="javascript">exp('."'$type'".')</script>';
  263. }
  264. if ($avoid_serialize) {
  265. /*Documents are avoided due the huge amount of memory that the serialize php function "eats"
  266. (when there are directories with hundred/thousand of files) */
  267. // this is a known issue of serialize
  268. $course->resources['document']= null;
  269. }
  270. echo '<input type="hidden" name="course" value="'.base64_encode(Course::serialize($course)).'"/>';
  271. if (is_array($hidden_fields)) {
  272. foreach ($hidden_fields as $key => $value) {
  273. echo '<input type="hidden" name="'.$key.'" value="'.$value.'"/>';
  274. }
  275. }
  276. $recycleOption = isset($_POST['recycle_option']) ? true : false;
  277. if (empty($element_count)) {
  278. Display::display_warning_message(get_lang('NoDataAvailable'));
  279. } else {
  280. if (!empty($hidden_fields['destination_session'])) {
  281. echo '<br /><button class="save" type="submit" onclick="javascript:if(!confirm('."'".addslashes(api_htmlentities(get_lang("ConfirmYourChoice"),ENT_QUOTES, $charset))."'".')) return false;" >'.
  282. get_lang('Ok').'</button>';
  283. } else {
  284. if ($recycleOption) {
  285. echo '<br /><button class="save" type="submit">'.
  286. get_lang('Ok').'</button>';
  287. } else {
  288. echo '<br /><button class="save" type="submit" onclick="checkLearnPath(\''.addslashes(get_lang('DocumentsWillBeAddedToo')).'\')">'.
  289. get_lang('Ok').'</button>';
  290. }
  291. }
  292. }
  293. CourseSelectForm :: display_hidden_quiz_questions($course);
  294. CourseSelectForm :: display_hidden_scorm_directories($course);
  295. echo '</form>';
  296. echo '<div id="dynamic_div" style="display:block;margin-left:40%;margin-top:10px;height:50px;"></div>';
  297. }
  298. /**
  299. * @param $course
  300. */
  301. static function display_hidden_quiz_questions($course)
  302. {
  303. if(is_array($course->resources)){
  304. foreach ($course->resources as $type => $resources) {
  305. if (count($resources) > 0) {
  306. switch ($type) {
  307. case RESOURCE_QUIZQUESTION:
  308. foreach ($resources as $id => $resource) {
  309. echo '<input type="hidden" name="resource['.RESOURCE_QUIZQUESTION.']['.$id.']" id="resource['.RESOURCE_QUIZQUESTION.']['.$id.']" value="On" />';
  310. }
  311. break;
  312. }
  313. }
  314. }
  315. }
  316. }
  317. /**
  318. * @param $course
  319. */
  320. static function display_hidden_scorm_directories($course)
  321. {
  322. if (is_array($course->resources)){
  323. foreach ($course->resources as $type => $resources) {
  324. if (count($resources) > 0) {
  325. switch($type) {
  326. case RESOURCE_SCORM:
  327. foreach ($resources as $id => $resource) {
  328. echo '<input type="hidden" name="resource['.RESOURCE_SCORM.']['.$id.']" id="resource['.RESOURCE_SCORM.']['.$id.']" value="On" />';
  329. }
  330. break;
  331. }
  332. }
  333. }
  334. }
  335. }
  336. /**
  337. * Get the posted course
  338. * @param string $from who calls the function?
  339. * It can be copy_course, create_backup, import_backup or recycle_course
  340. * @param int $session_id
  341. * @param string $course_code
  342. * @return course The course-object with all resources selected by the user
  343. * in the form given by display_form(...)
  344. */
  345. public static function get_posted_course($from = '', $session_id = 0, $course_code = '')
  346. {
  347. $course = null;
  348. if (isset($_POST['course'])) {
  349. $course = Course::unserialize(base64_decode($_POST['course']));
  350. } else {
  351. return false;
  352. }
  353. //Create the resource DOCUMENT objects
  354. //Loading the results from the checkboxes of ethe javascript
  355. $resource = isset($_POST['resource'][RESOURCE_DOCUMENT]) ? $_POST['resource'][RESOURCE_DOCUMENT] : null;
  356. $course_info = api_get_course_info($course_code);
  357. $table_doc = Database::get_course_table(TABLE_DOCUMENT);
  358. $table_prop = Database::get_course_table(TABLE_ITEM_PROPERTY);
  359. $course_id = $course_info['real_id'];
  360. /* Searching the documents resource that have been set to null because
  361. $avoid_serialize is true in the display_form() function*/
  362. if ($from == 'copy_course') {
  363. if (is_array($resource)) {
  364. $resource = array_keys($resource);
  365. foreach ($resource as $resource_item) {
  366. $condition_session = '';
  367. if (!empty($session_id)) {
  368. $session_id = intval($session_id);
  369. $condition_session = ' AND d.session_id ='.$session_id;
  370. }
  371. $sql = 'SELECT d.id, d.path, d.comment, d.title, d.filetype, d.size
  372. FROM '.$table_doc.' d, '.$table_prop.' p
  373. WHERE
  374. d.c_id = '.$course_id.' AND
  375. p.c_id = '.$course_id.' AND
  376. tool = \''.TOOL_DOCUMENT.'\' AND
  377. p.ref = d.id AND p.visibility != 2 AND
  378. d.id = '.$resource_item.$condition_session.'
  379. ORDER BY path';
  380. $db_result = Database::query($sql);
  381. while ($obj = Database::fetch_object($db_result)) {
  382. $doc = new Document($obj->id, $obj->path, $obj->comment, $obj->title, $obj->filetype, $obj->size);
  383. if ($doc) {
  384. $course->add_resource($doc);
  385. // adding item property
  386. $sql = "SELECT * FROM $table_prop
  387. WHERE
  388. c_id = $course_id AND
  389. tool = '".RESOURCE_DOCUMENT."' AND
  390. ref = $resource_item ";
  391. $res = Database::query($sql);
  392. $all_properties = array ();
  393. while ($item_property = Database::fetch_array($res,'ASSOC')) {
  394. $all_properties[] = $item_property;
  395. }
  396. $course->resources[RESOURCE_DOCUMENT][$resource_item]->item_properties = $all_properties;
  397. }
  398. }
  399. }
  400. }
  401. }
  402. if (is_array($course->resources)) {
  403. foreach ($course->resources as $type => $resources) {
  404. switch ($type) {
  405. case RESOURCE_SURVEYQUESTION:
  406. foreach($resources as $id => $obj) {
  407. if (isset($_POST['resource'][RESOURCE_SURVEY]) &&
  408. is_array($_POST['resource'][RESOURCE_SURVEY]) &&
  409. !in_array($obj->survey_id, array_keys($_POST['resource'][RESOURCE_SURVEY]))
  410. ) {
  411. unset($course->resources[$type][$id]);
  412. }
  413. }
  414. break;
  415. case RESOURCE_FORUMTOPIC:
  416. case RESOURCE_FORUMPOST:
  417. //Add post from topic
  418. if ($type == RESOURCE_FORUMTOPIC) {
  419. $posts_to_save = array();
  420. $posts = $course->resources[RESOURCE_FORUMPOST];
  421. foreach ($resources as $thread_id => $obj) {
  422. if (!isset($_POST['resource'][RESOURCE_FORUMTOPIC][$thread_id])) {
  423. unset($course->resources[RESOURCE_FORUMTOPIC][$thread_id]);
  424. continue;
  425. }
  426. $forum_id = $obj->obj->forum_id;
  427. $title = $obj->obj->thread_title;
  428. foreach ($posts as $post_id => $post) {
  429. if ($post->obj->thread_id == $thread_id && $forum_id == $post->obj->forum_id && $title == $post->obj->post_title) {
  430. //unset($course->resources[RESOURCE_FORUMPOST][$post_id]);
  431. $posts_to_save[] = $post_id;
  432. }
  433. }
  434. }
  435. if (!empty($posts)) {
  436. foreach ($posts as $post_id => $post) {
  437. if (!in_array($post_id, $posts_to_save)) {
  438. unset($course->resources[RESOURCE_FORUMPOST][$post_id]);
  439. }
  440. }
  441. }
  442. }
  443. break;
  444. case RESOURCE_LEARNPATH:
  445. $lps = isset($_POST['resource'][RESOURCE_LEARNPATH]) ? $_POST['resource'][RESOURCE_LEARNPATH] : null;
  446. if (!empty($lps)) {
  447. foreach ($lps as $id => $obj) {
  448. $lp_resource = $course->resources[RESOURCE_LEARNPATH][$id];
  449. if (isset($lp_resource) && !empty($lp_resource) && isset($lp_resource->items)) {
  450. foreach ($lp_resource->items as $item) {
  451. switch ($item['item_type']) {
  452. //Add links added in a LP see #5760
  453. case 'link':
  454. $_POST['resource'][RESOURCE_LINK][$item['path']] = 1;
  455. break;
  456. }
  457. }
  458. }
  459. }
  460. }
  461. case RESOURCE_LINKCATEGORY :
  462. case RESOURCE_FORUMCATEGORY :
  463. case RESOURCE_QUIZQUESTION :
  464. case RESOURCE_DOCUMENT:
  465. // Mark folders to import which are not selected by the user to import,
  466. // but in which a document was selected.
  467. $documents = isset($_POST['resource'][RESOURCE_DOCUMENT]) ? $_POST['resource'][RESOURCE_DOCUMENT] : null;
  468. if (!empty($resources) && is_array($resources))
  469. foreach ($resources as $id => $obj) {
  470. if (isset($obj->file_type) && $obj->file_type == 'folder' &&
  471. !isset($_POST['resource'][RESOURCE_DOCUMENT][$id]) &&
  472. is_array($documents)
  473. ) {
  474. foreach ($documents as $id_to_check => $post_value) {
  475. $obj_to_check = $resources[$id_to_check];
  476. $shared_path_part = substr($obj_to_check->path,0,strlen($obj->path));
  477. if ($id_to_check != $id && $obj->path == $shared_path_part) {
  478. $_POST['resource'][RESOURCE_DOCUMENT][$id] = 1;
  479. break;
  480. }
  481. }
  482. }
  483. }
  484. default :
  485. if (!empty($resources) && is_array($resources)) {
  486. foreach ($resources as $id => $obj) {
  487. $resource_is_used_elsewhere = $course->is_linked_resource($obj);
  488. // check if document is in a quiz (audio/video)
  489. if ($type == RESOURCE_DOCUMENT && $course->has_resources(RESOURCE_QUIZ)) {
  490. foreach($course->resources[RESOURCE_QUIZ] as $quiz) {
  491. $quiz = $quiz->obj;
  492. if (isset($quiz->media) && $quiz->media == $id) {
  493. $resource_is_used_elsewhere = true;
  494. }
  495. }
  496. }
  497. if (!isset($_POST['resource'][$type][$id]) && !$resource_is_used_elsewhere) {
  498. unset($course->resources[$type][$id]);
  499. }
  500. }
  501. }
  502. }
  503. }
  504. }
  505. return $course;
  506. }
  507. /**
  508. * Display the form session export
  509. * @param array $hidden_fiels Hidden fields to add to the form.
  510. * @param boolean the document array will be serialize. This is used in the course_copy.php file
  511. */
  512. function display_form_session_export($list_course, $hidden_fields = null, $avoid_serialize = false)
  513. {
  514. $iconPath = api_get_path(WEB_IMG_PATH);
  515. ?>
  516. <script>
  517. function exp(item) {
  518. el = document.getElementById('div_'+item);
  519. if (el.style.display=='none'){
  520. el.style.display='';
  521. document.getElementById('img_'+item).src='../img/1.gif';
  522. }
  523. else{
  524. el.style.display='none';
  525. document.getElementById('img_'+item).src='../img/0.gif';
  526. }
  527. }
  528. function setCheckbox(type,value) {
  529. d = document.course_select_form;
  530. for (i = 0; i < d.elements.length; i++) {
  531. if (d.elements[i].type == "checkbox") {
  532. var name = d.elements[i].attributes.getNamedItem('name').nodeValue;
  533. if( name.indexOf(type) > 0 || type == 'all' ){
  534. d.elements[i].checked = value;
  535. }
  536. }
  537. }
  538. }
  539. function checkLearnPath(message){
  540. d = document.course_select_form;
  541. for (i = 0; i < d.elements.length; i++) {
  542. if (d.elements[i].type == "checkbox") {
  543. var name = d.elements[i].attributes.getNamedItem('name').nodeValue;
  544. if( name.indexOf('learnpath') > 0){
  545. if(d.elements[i].checked){
  546. setCheckbox('document',true);
  547. alert(message);
  548. break;
  549. }
  550. }
  551. }
  552. }
  553. }
  554. </script>
  555. <?php
  556. // Get destination course title
  557. if (!empty($hidden_fields['destination_course'])) {
  558. $course_infos = CourseManager::get_course_information($hidden_fields['destination_course']);
  559. echo '<h3>';
  560. echo get_lang('DestinationCourse').' : '.$course_infos['title'];
  561. echo '</h3>';
  562. }
  563. echo '<script type="text/javascript">var myUpload = new upload(1000);</script>';
  564. echo '<form method="post" id="upload_form" name="course_select_form" onsubmit="myUpload.start(\'dynamic_div\',\'\',\''.get_lang('PleaseStandBy').'\',\'upload_form\')">';
  565. echo '<input type="hidden" name="action" value="course_select_form"/>';
  566. foreach ($list_course as $course){
  567. foreach ($course->resources as $type => $resources) {
  568. if (count($resources) > 0) {
  569. echo '<img id="img_'.$course->code.'" src="'.$iconPath.'1.gif" onclick="javascript:exp('."'$course->code'".');" />';
  570. echo '<b onclick="javascript:exp('."'$course->code'".');" > '.$course->code.'</b><br />';
  571. echo '<div id="div_'.$course->code.'">';
  572. echo '<blockquote>';
  573. echo '<div class="btn-group">';
  574. echo "<a class=\"btn\" href=\"#\" onclick=\"javascript:setCheckbox('".$course->code."',true);\" >".get_lang('All')."</a>";
  575. echo "<a class=\"btn\" href=\"#\" onclick=\"javascript:setCheckbox('".$course->code."',false);\" >".get_lang('None')."</a>";
  576. echo '</div><br />';
  577. foreach ($resources as $id => $resource) {
  578. echo '<label class="checkbox" for="resource['.$course->code.']['.$id.']">';
  579. echo '<input type="checkbox" name="resource['.$course->code.']['.$id.']" id="resource['.$course->code.']['.$id.']"/>';
  580. $resource->show();
  581. echo '</label>';
  582. }
  583. echo '</blockquote>';
  584. echo '</div>';
  585. echo '<script type="text/javascript">exp('."'$course->code'".')</script>';
  586. }
  587. }
  588. }
  589. if ($avoid_serialize) {
  590. //Documents are avoided due the huge amount of memory that the serialize php function "eats" (when there are directories with hundred/thousand of files)
  591. // this is a known issue of serialize
  592. $course->resources['document']= null;
  593. }
  594. echo '<input type="hidden" name="course" value="'.base64_encode(Course::serialize($course)).'"/>';
  595. if (is_array($hidden_fields)) {
  596. foreach ($hidden_fields as $key => $value) {
  597. echo "\n";
  598. echo '<input type="hidden" name="'.$key.'" value="'.$value.'"/>';
  599. }
  600. }
  601. echo '<br /><button class="save" type="submit" onclick="checkLearnPath(\''.addslashes(get_lang('DocumentsWillBeAddedToo')).'\')">'.get_lang('Ok').'</button>';
  602. CourseSelectForm :: display_hidden_quiz_questions($course);
  603. CourseSelectForm :: display_hidden_scorm_directories($course);
  604. echo '</form>';
  605. echo '<div id="dynamic_div" style="display:block;margin-left:40%;margin-top:10px;height:50px;"></div>';
  606. }
  607. }