CourseSelectForm.class.php 27 KB

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