CourseSelectForm.class.php 27 KB

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