CourseSelectForm.class.php 28 KB

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