CourseSelectForm.class.php 27 KB

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