CourseSelectForm.class.php 29 KB

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