Project

General

Profile

Bug #5540 » CourseSelectForm.class.php

Yoselyn Castillo, 09/10/2012 17:03

 
1
<?php
2
/* For licensing terms, see /license.txt */
3

    
4
require_once 'Course.class.php';
5

    
6
/**
7
 * Class to show a form to select resources
8
 * @author Bart Mollet <bart.mollet@hogent.be>
9
 * @author Julio Montoya <gugli100@gmail.com>
10
 * @package chamilo.backup
11
 */
12
class CourseSelectForm
13
{
14
	/**
15
	 * Display the form
16
	 * @param array $hidden_fiels Hidden fields to add to the form.
17
	 * @param boolean the document array will be serialize. This is used in the course_copy.php file
18
	 */
19
	static function display_form($course, $hidden_fields = null, $avoid_serialize=false) {
20
        global $charset;
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_LEARNPATH] 		= get_lang('Learnpaths');
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
?>
38
		<script>
39
			function exp(item) {
40
				el = document.getElementById('div_'+item);
41
				if (el.style.display=='none'){
42
					el.style.display='';
43
					document.getElementById('img_'+item).src='../img/1.gif';
44
				}
45
				else{
46
					el.style.display='none';
47
					document.getElementById('img_'+item).src='../img/0.gif';
48
				}
49
			}
50
            
51
            function setCheckboxForum(type, value, item_id) {
52
                //console.log("#resource["+type+"]["+value+"]");
53
                //$("#resource["+type+"]["+value+"]").attr('checked', value);
54
                
55
 				d = document.course_select_form;
56
 				for (i = 0; i < d.elements.length; i++) {
57
   					if (d.elements[i].type == "checkbox") {
58
						var name = d.elements[i].attributes.getNamedItem('name').nodeValue;
59
                        
60
 						if( name.indexOf(type) > 0 || type == 'all' ){
61
                            if ($(d.elements[i]).attr('rel') == item_id) {
62
                                d.elements[i].checked = value;
63
                            }
64
						}
65
   					}
66
 				}
67
			}
68
            
69
			function setCheckbox(type,value) {
70
 				d = document.course_select_form;
71
 				for (i = 0; i < d.elements.length; i++) {
72
   					if (d.elements[i].type == "checkbox") {
73
						var name = d.elements[i].attributes.getNamedItem('name').nodeValue;
74
 						if( name.indexOf(type) > 0 || type == 'all' ){
75
						     d.elements[i].checked = value;
76
						}
77
   					}
78
 				}
79
			}
80
            
81
			function checkLearnPath(message){
82
				d = document.course_select_form;
83
 				for (i = 0; i < d.elements.length; i++) {
84
 					if (d.elements[i].type == "checkbox") {
85
						var name = d.elements[i].attributes.getNamedItem('name').nodeValue;
86
 						if( name.indexOf('learnpath') > 0){
87
 							if(d.elements[i].checked){
88
	 							setCheckbox('document',true);
89
	 							alert(message);
90
	 							break;
91
 							}
92
 						}
93
 					}
94
 				}
95
			}
96
            	
97
            function check_forum(obj) {
98
                var id = $(obj).attr('rel'); 
99
                var my_id = $(obj).attr('my_rel');
100
                var checked = false;
101
                if ($('#resource_forum_'+my_id).attr('checked')) {
102
                    checked = true;    
103
                }                
104
                setCheckboxForum('thread', checked, my_id);
105
                $('#resource_Forum_Category_'+id).attr('checked','checked');     
106
            }
107
            
108
             function check_category(obj) {
109
                var my_id = $(obj).attr('my_rel');             
110
                var checked = false;
111
                if ($('#resource_Forum_Category_'+my_id).attr('checked')) {
112
                    checked = true;    
113
                }
114
                $('.resource_forum').each(function(index, value) {
115
                    if ($(value).attr('rel') == my_id) {
116
                        $(value).attr('checked', checked);
117
                    }
118
                });
119
                
120
                $('.resource_topic').each(function(index, value) {
121
                    if ($(value).attr('cat_id') == my_id) {
122
                        $(value).attr('checked', checked);
123
                    }
124
                });
125
            }
126
            
127
            function check_topic(obj) {
128
                var my_id = $(obj).attr('cat_id');
129
                var forum_id = $(obj).attr('forum_id');
130
                $('#resource_Forum_Category_'+my_id).attr('checked','checked');     
131
                $('#resource_forum_'+forum_id).attr('checked','checked');                
132
            }
133
		</script>
134
		<?php
135

    
136
		//get destination course title
137
		if (!empty($hidden_fields['destination_course'])) {
138
			$course_infos = CourseManager::get_course_information($hidden_fields['destination_course']);
139
			echo '<h3>';
140
			echo get_lang('DestinationCourse').' : '.$course_infos['title'];
141
			echo '</h3>';
142
		}
143
        echo '<script src="'.api_get_path(WEB_CODE_PATH).'inc/lib/javascript/upload.js" type="text/javascript"></script>';
144
		echo '<script type="text/javascript">var myUpload = new upload(1000);</script>';
145
		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\')">';
146
		echo '<input type="hidden" name="action" value="course_select_form"/>';
147

    
148
		if (!empty($hidden_fields['destination_course']) && !empty($hidden_fields['origin_course']) && !empty($hidden_fields['destination_session']) && !empty($hidden_fields['origin_session']) ) {
149
			echo '<input type="hidden" name="destination_course" 	value="'.$hidden_fields['destination_course'].'"/>';
150
			echo '<input type="hidden" name="origin_course" 		value="'.$hidden_fields['origin_course'].'"/>';
151
			echo '<input type="hidden" name="destination_session" 	value="'.$hidden_fields['destination_session'].'"/>';
152
			echo '<input type="hidden" name="origin_session" 		value="'.$hidden_fields['origin_session'].'"/>';
153
		}
154

    
155
		$element_count = 0;
156
        $forum_categories = array();
157
        $forums = array();
158
        $forum_topics = array();
159
        
160
        echo '<p>';
161
		echo get_lang('SelectResources');
162
		echo '</p>';
163

    
164
        Display::display_normal_message(get_lang('DontForgetToSelectTheMediaFilesIfYourResourceNeedIt'));
165
        
166
        foreach ($course->resources as $type => $resources) {            
167
            if (count($resources) > 0) {
168
				switch ($type) {
169
					//Resources to avoid					
170
					case RESOURCE_FORUMCATEGORY :
171
                        foreach ($resources as $id => $resource) {
172
                            $forum_categories[$id] = $resource;
173
                        }
174
                        $element_count++;
175
                        break;
176
                    case RESOURCE_FORUM:
177
                        foreach ($resources as $id => $resource) {
178
                            $forums[$resource->obj->forum_category][$id] = $resource;
179
                        }
180
                        $element_count++;
181
                        break;
182
                    case RESOURCE_FORUMTOPIC:
183
                        foreach ($resources as $id => $resource) {
184
                            $forum_topics[$resource->obj->forum_id][$id] = $resource;
185
                        }
186
                        $element_count++;
187
                        break;
188
                    case RESOURCE_LINKCATEGORY :
189
					case RESOURCE_FORUMPOST :					
190
					case RESOURCE_QUIZQUESTION:
191
					case RESOURCE_SURVEYQUESTION:
192
					case RESOURCE_SURVEYINVITATION:
193
					case RESOURCE_SCORM:
194
						break;
195
                    default :
196
						echo '<img id="img_'.$type.'" src="../img/1.gif" onclick="javascript:exp('."'$type'".');" />&nbsp;';
197
						echo '<b onclick="javascript:exp('."'$type'".');" >'.$resource_titles[$type].'</b><br />';
198
						echo '<div id="div_'.$type.'">';
199
						if ($type == RESOURCE_LEARNPATH) {
200
    						Display::display_warning_message(get_lang('ToExportLearnpathWithQuizYouHaveToSelectQuiz'));
201
    						Display::display_warning_message(get_lang('IfYourLPsHaveAudioFilesIncludedYouShouldSelectThemFromTheDocuments'));
202
						}
203
						if ($type == RESOURCE_DOCUMENT) {
204
                            if (api_get_setting('show_glossary_in_documents') != 'none') {
205
                                Display::display_warning_message(get_lang('ToExportDocumentsWithGlossaryYouHaveToSelectGlossary'));
206
                            }
207
						}
208

    
209
						echo '<blockquote>';
210
                        echo '<div class="btn-group">';
211
						echo "<a class=\"btn\" href=\"javascript: void(0);\" onclick=\"javascript: setCheckbox('$type',true);\" >".get_lang('All')."</a>";
212
                        echo "<a class=\"btn\" href=\"javascript: void(0);\" onclick=\"javascript:setCheckbox('$type',false);\" >".get_lang('None')."</a>";
213
						echo '</div><br />';
214

    
215
						foreach ($resources as $id => $resource) {
216
                            echo '<label class="checkbox">';
217
							echo '<input type="checkbox" name="resource['.$type.']['.$id.']"  id="resource['.$type.']['.$id.']" />';
218
							$resource->show();
219
							echo '</label>';
220
						}
221
						echo '</blockquote>';
222
						echo '</div>';
223
						echo '<script language="javascript">exp('."'$type'".')</script>';
224
						$element_count++;
225
                }
226
			}
227
		}
228
        
229
        //Fixes forum order
230
        if (!empty($forum_categories)) {
231
            $type = RESOURCE_FORUMCATEGORY;
232
            
233
            echo '<img id="img_'.$type.'" src="../img/1.gif" onclick="javascript:exp('."'$type'".');" />&nbsp;';
234
            echo '<b onclick="javascript:exp('."'$type'".');" >'.$resource_titles[RESOURCE_FORUM].'</b><br />';
235
            echo '<div id="div_'.$type.'">';
236
            
237
            //All non  categories
238
            /*echo '<div class="btn-group">';
239
            echo "<a class=\"btn\" href=\"javascript: void(0);\" onclick=\"javascript:setCheckbox('".RESOURCE_FORUMCATEGORY."', true);\" >".get_lang('All')."</a>";
240
            echo "<a class=\"btn\" href=\"javascript: void(0);\" onclick=\"javascript:setCheckbox('".RESOURCE_FORUMCATEGORY."', false);\" >".get_lang('None')."</a>";
241
            echo '</div><br />';*/
242
            
243
            echo '<ul>';
244
            foreach ($forum_categories as $forum_category_id => $forum_category) {
245
                echo '<li>';
246
                echo '<label class="checkbox">';
247
                
248
                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.']"  /> ';
249
                $forum_category->show();
250
                echo '</label>';
251
                
252
                if (isset($forums[$forum_category_id]) && count($forums[$forum_category_id])  > 1) {
253
                    /*echo '<div class="btn-group">';
254
                    echo "<a class=\"btn\" href=\"javascript: void(0);\" onclick=\"javascript:setCheckboxForum('".RESOURCE_FORUM."',true, '".$forum_category_id."');\" >".get_lang('All')."</a>";
255
                    echo "<a class=\"btn\" href=\"javascript: void(0);\" onclick=\"javascript:setCheckboxForum('".RESOURCE_FORUM."',false, '".$forum_category_id."' );\" >".get_lang('None')."</a>";
256
                    echo '</div>';*/
257
                }                
258
                echo '</li>';
259

    
260
                if (isset($forums[$forum_category_id])) {
261
                    $my_forums = $forums[$forum_category_id];
262
                    echo '<ul>';
263
                    foreach ($my_forums as $forum_id => $forum) {                        
264
                        echo '<li>';
265
                        echo '<label class="checkbox">';
266
                        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.']"  />';
267
                        $forum->show();
268
                        echo '</label>';
269
                        
270
                        if (isset($forum_topics[$forum_id])) {
271
                            /*echo '<div class="btn-group">';
272
                            echo "<a class=\"btn\" href=\"javascript: void(0);\" onclick=\"javascript:setCheckboxForum('".RESOURCE_FORUMTOPIC."',true, '".$forum_id."');\" >".get_lang('All')."</a>";
273
                            echo "<a class=\"btn\" href=\"javascript: void(0);\" onclick=\"javascript:setCheckboxForum('".RESOURCE_FORUMTOPIC."',false, '".$forum_id."' );\" >".get_lang('None')."</a>";
274
                            echo '</div>';*/
275
                        }
276

    
277
                        echo '</li>';
278
                        if (isset($forum_topics[$forum_id])) {
279
                            $my_forum_topics = $forum_topics[$forum_id];
280
                            
281
                            if (!empty($my_forum_topics)) {
282
                                echo '<ul>';
283
                                foreach ($my_forum_topics as $topic_id => $topic) {                                    
284
                                    echo '<li>';                                    
285
                                    echo '<label class="checkbox">';
286
                                    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.']"  />';
287
                                    $topic->show();
288
                                    echo '</label>';                                    
289
                                    echo '</li>';                                    
290
                                }
291
                                echo '</ul>';
292
                            }                            
293
                        }                        
294
                    }
295
                    echo '</ul>';
296
                }
297
                echo '<hr/>';                    
298
            }
299
            echo '</ul>';            
300
            echo '</div>';
301
            echo '<script language="javascript">exp('."'$type'".')</script>';            
302
        }
303

    
304
		if ($avoid_serialize) {
305
			/*Documents are avoided due the huge amount of memory that the serialize php function "eats"
306
			(when there are directories with hundred/thousand of files) */
307
			// this is a known issue of serialize
308
			$course->resources['document']= null;
309
		}
310

    
311
		echo '<input type="hidden" name="course" value="'.base64_encode(Course::serialize($course)).'"/>';
312

    
313
		if (is_array($hidden_fields)) {
314
			foreach ($hidden_fields as $key => $value) {
315
				echo '<input type="hidden" name="'.$key.'" value="'.$value.'"/>';
316
			}
317
		}
318

    
319
		if (empty($element_count)) {
320
		    Display::display_warning_message(get_lang('NoDataAvailable'));
321
		} else {
322
    		if (!empty($hidden_fields['destination_session'])) {
323
    			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>';
324
    		} else {
325
    			echo '<br /><button class="save" type="submit" onclick="checkLearnPath(\''.addslashes(get_lang('DocumentsWillBeAddedToo')).'\')">'.get_lang('Ok').'</button>';
326
    		}
327
		}
328

    
329
		CourseSelectForm :: display_hidden_quiz_questions($course);
330
		CourseSelectForm :: display_hidden_scorm_directories($course);
331
		echo '</form>';
332
		echo '<div id="dynamic_div" style="display:block;margin-left:40%;margin-top:10px;height:50px;"></div>';        
333
	}
334

    
335

    
336
    static function display_hidden_quiz_questions($course) {
337
		if(is_array($course->resources)){
338
			foreach ($course->resources as $type => $resources) {
339
				if (count($resources) > 0) {
340
					switch ($type) {
341
						case RESOURCE_QUIZQUESTION:
342
							foreach ($resources as $id => $resource) {
343
								echo '<input type="hidden" name="resource['.RESOURCE_QUIZQUESTION.']['.$id.']" id="resource['.RESOURCE_QUIZQUESTION.']['.$id.']" value="On" />';
344
							}
345
							break;
346
					}
347
				}
348
			}
349
		}
350
	}
351

    
352
	static function display_hidden_scorm_directories($course) {
353
        if (is_array($course->resources)){
354
			foreach ($course->resources as $type => $resources) {
355
				if (count($resources) > 0) {
356
					switch($type) {
357
						case RESOURCE_SCORM:
358
							foreach ($resources as $id=>$resource) {
359
								echo '<input type="hidden" name="resource['.RESOURCE_SCORM.']['.$id.']" id="resource['.RESOURCE_SCORM.']['.$id.']" value="On" />';
360
							}
361
							break;
362
					}
363
				}
364
			}
365
		}
366
	}
367

    
368
	/**
369
	 * Get the posted course
370
	 * @param string who calls the function? It can be copy_course, create_backup, import_backup or recycle_course
371
	 * @return course The course-object with all resources selected by the user
372
	 * in the form given by display_form(...)
373
	 */
374
	static function get_posted_course($from='', $session_id = 0, $course_code = '') {
375
		$course = Course::unserialize(base64_decode($_POST['course']));
376
        
377
		//Create the resource DOCUMENT objects
378
		//Loading the results from the checkboxes of the javascript
379
		$resource       = $_POST['resource'][RESOURCE_DOCUMENT];
380

    
381
		$course_info 	= api_get_course_info($course_code);
382
		$table_doc 		= Database::get_course_table(TABLE_DOCUMENT);
383
		$table_prop 	= Database::get_course_table(TABLE_ITEM_PROPERTY);
384

    
385
		$course_id 		= $course_info['real_id'];
386

    
387
		// Searching the documents resource that have been set to null because $avoid_serialize is true in the display_form() function
388
        
389
		if ($from == 'copy_course') {
390
			if (is_array($resource)) {
391
				$resource = array_keys($resource);
392
				foreach	($resource as $resource_item) {
393

    
394
					$condition_session = '';
395
					if (!empty($session_id)) {
396
						$session_id = intval($session_id);
397
						$condition_session = ' AND d.session_id ='.$session_id;
398
					}
399

    
400
					$sql = 'SELECT d.id, d.path, d.comment, d.title, d.filetype, d.size
401
							FROM '.$table_doc.' d, '.$table_prop.' p
402
							WHERE 	d.c_id = '.$course_id.' AND
403
									p.c_id = '.$course_id.' AND
404
									tool 	= \''.TOOL_DOCUMENT.'\' AND
405
									p.ref 	= d.id AND p.visibility != 2 AND
406
									d.id 	= '.$resource_item.$condition_session.'
407
							ORDER BY path';
408
					$db_result = Database::query($sql);
409
					while ($obj = Database::fetch_object($db_result)) {
410
						$doc = new Document($obj->id, $obj->path, $obj->comment, $obj->title, $obj->filetype, $obj->size);
411
						$course->add_resource($doc);
412
						// adding item property
413
						$sql = "SELECT * FROM $table_prop WHERE c_id = '.$course_id.'  AND TOOL = '".RESOURCE_DOCUMENT."' AND ref='".$resource_item."'";
414
						$res = Database::query($sql);
415
						$all_properties = array ();
416
						while ($item_property = Database::fetch_array($res,'ASSOC')) {
417
							$all_properties[] = $item_property;
418
						}
419
						$course->resources[RESOURCE_DOCUMENT][$resource_item]->item_properties = $all_properties;
420
					}
421
				}
422
			}
423
		}
424
		if (is_array($course->resources)) {
425
			foreach ($course->resources as $type => $resources) {
426
				switch ($type) {
427
					case RESOURCE_SURVEYQUESTION:
428
						foreach($resources as $id => $obj) {
429
						    if (is_array($_POST['resource'][RESOURCE_SURVEY]) && !in_array($obj->survey_id, array_keys($_POST['resource'][RESOURCE_SURVEY]))) {
430
								unset($course->resources[$type][$id]);
431
							}
432
						}
433
						break;
434
                    case RESOURCE_FORUMTOPIC:
435
                    case RESOURCE_FORUMPOST:
436
                       //Add post from topic
437
                        if ($type == RESOURCE_FORUMTOPIC) {
438
                            $posts_to_save = array();
439
                            $posts = $course->resources[RESOURCE_FORUMPOST];
440
                            foreach ($resources as $thread_id => $obj) {
441
                                if (!isset($_POST['resource'][RESOURCE_FORUMTOPIC][$thread_id])) {
442
                                    unset($course->resources[RESOURCE_FORUMTOPIC][$thread_id]);
443
                                    continue;
444
                                }
445
                                $forum_id = $obj->obj->forum_id;                             
446
                                $title = $obj->obj->thread_title;
447
                                foreach ($posts as $post_id => $post) {                                
448
                                    if ($post->obj->thread_id == $thread_id && $forum_id == $post->obj->forum_id && $title == $post->obj->post_title) {
449
                                        //unset($course->resources[RESOURCE_FORUMPOST][$post_id]);
450
                                        $posts_to_save[] = $post_id;
451
                                    } 
452
                                }                            
453
                            }                      
454
                            if (!empty($posts)) {
455
                                foreach ($posts as $post_id => $post) {
456
                                    if (!in_array($post_id, $posts_to_save)) {
457
                                        unset($course->resources[RESOURCE_FORUMPOST][$post_id]);
458
                                    }
459
                                }
460
                            }
461
                        }
462
                        break;
463
					case RESOURCE_LINKCATEGORY :
464
					case RESOURCE_FORUMCATEGORY :					
465
					case RESOURCE_QUIZQUESTION :
466
					case RESOURCE_DOCUMENT:
467
						// Mark folders to import which are not selected by the user to import,
468
						// but in which a document was selected.
469
						$documents = $_POST['resource'][RESOURCE_DOCUMENT];
470
						if (is_array($resources))
471
							foreach($resources as $id => $obj) {
472
								if ($obj->file_type == 'folder' && ! isset($_POST['resource'][RESOURCE_DOCUMENT][$id]) && is_array($documents)) {
473
									foreach($documents as $id_to_check => $post_value) {
474
										$obj_to_check = $resources[$id_to_check];
475
										$shared_path_part = substr($obj_to_check->path,0,strlen($obj->path));
476
										if ($id_to_check != $id && $obj->path == $shared_path_part) {
477
											$_POST['resource'][RESOURCE_DOCUMENT][$id] = 1;
478
											break;
479
										}
480
									}
481
								}
482
							}
483
					default :
484
						if (is_array($resources)) {
485
							foreach ($resources as $id => $obj) {
486
								$resource_is_used_elsewhere = $course->is_linked_resource($obj);
487
								// check if document is in a quiz (audio/video)
488
								if ($type == RESOURCE_DOCUMENT && $course->has_resources(RESOURCE_QUIZ)) {
489
									foreach($course->resources[RESOURCE_QUIZ] as $qid => $quiz) {
490
										if ($quiz->media == $id) {
491
											$resource_is_used_elsewhere = true;
492
										}
493
									}
494
								}
495
								if (!isset($_POST['resource'][$type][$id]) && !$resource_is_used_elsewhere) {
496
									unset($course->resources[$type][$id]);
497
								}
498
							}
499
						}
500
				}
501
			}
502
		}        
503
		return $course;
504
	}
505

    
506
	/**
507
	 * Display the form session export
508
	 * @param array $hidden_fiels Hidden fields to add to the form.
509
	 * @param boolean the document array will be serialize. This is used in the course_copy.php file
510
	 */
511
	 function display_form_session_export($list_course, $hidden_fields = null, $avoid_serialize=false) {
512
?>
513
		<script>
514
			function exp(item) {
515
				el = document.getElementById('div_'+item);
516
				if (el.style.display=='none'){
517
					el.style.display='';
518
					document.getElementById('img_'+item).src='../img/1.gif';
519
				}
520
				else{
521
					el.style.display='none';
522
					document.getElementById('img_'+item).src='../img/0.gif';
523
				}
524
			}
525
			function setCheckbox(type,value) {
526
 				d = document.course_select_form;
527
 				for (i = 0; i < d.elements.length; i++) {
528
   					if (d.elements[i].type == "checkbox") {
529
						var name = d.elements[i].attributes.getNamedItem('name').nodeValue;
530
 						if( name.indexOf(type) > 0 || type == 'all' ){
531
						     d.elements[i].checked = value;
532
						}
533
   					}
534
 				}
535
			}
536
			function checkLearnPath(message){
537
				d = document.course_select_form;
538
 				for (i = 0; i < d.elements.length; i++) {
539
 					if (d.elements[i].type == "checkbox") {
540
						var name = d.elements[i].attributes.getNamedItem('name').nodeValue;
541
 						if( name.indexOf('learnpath') > 0){
542
 							if(d.elements[i].checked){
543
	 							setCheckbox('document',true);
544
	 							alert(message);
545
	 							break;
546
 							}
547
 						}
548
 					}
549
 				}
550
			}
551
		</script>
552
		<?php
553

    
554
		//get destination course title
555
		if(!empty($hidden_fields['destination_course'])) {
556
			require_once(api_get_path(LIBRARY_PATH).'course.lib.php');
557
			$course_infos = CourseManager::get_course_information($hidden_fields['destination_course']);
558
			echo '<h3>';
559
				echo get_lang('DestinationCourse').' : '.$course_infos['title'];
560
			echo '</h3>';
561
		}
562

    
563
		echo '<script src="'.api_get_path(WEB_CODE_PATH).'inc/lib/javascript/upload.js" type="text/javascript"></script>';
564
		echo '<script type="text/javascript">var myUpload = new upload(1000);</script>';
565
		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\')">';
566
		echo '<input type="hidden" name="action" value="course_select_form"/>';
567
		foreach($list_course as $course){
568
			foreach ($course->resources as $type => $resources) {
569
				if (count($resources) > 0) {
570
					echo '<img id="img_'.$course->code.'" src="../img/1.gif" onclick="javascript:exp('."'$course->code'".');" />';
571
					echo '<b  onclick="javascript:exp('."'$course->code'".');" > '.$course->code.'</b><br />';
572
					echo '<div id="div_'.$course->code.'">';
573
					echo '<blockquote>';
574

    
575
                    echo '<div class="btn-group">';
576
					echo "<a class=\"btn\" href=\"#\" onclick=\"javascript:setCheckbox('".$course->code."',true);\" >".get_lang('All')."</a>";
577
                    echo "<a class=\"btn\" href=\"#\" onclick=\"javascript:setCheckbox('".$course->code."',false);\" >".get_lang('None')."</a>";
578
					echo '</div><br />';
579

    
580
					foreach ($resources as $id => $resource) {
581
						echo ' <label class="checkbox" for="resource['.$course->code.']['.$id.']">';
582
                        echo '<input type="checkbox" name="resource['.$course->code.']['.$id.']" id="resource['.$course->code.']['.$id.']"/>';
583
						$resource->show();
584
						echo '</label>';
585
						echo "\n";
586
					}
587
					echo '</blockquote>';
588
					echo '</div>';
589
					echo '<script type="text/javascript">exp('."'$course->code'".')</script>';
590
				}
591
			}
592
		}
593
		if ($avoid_serialize) {
594
			//Documents are avoided due the huge amount of memory that the serialize php function "eats" (when there are directories with hundred/thousand of files)
595
			// this is a known issue of serialize
596
			$course->resources['document']= null;
597
		}
598
		echo '<input type="hidden" name="course" value="'.base64_encode(Course::serialize($course)).'"/>';
599
		if (is_array($hidden_fields)) {
600
			foreach ($hidden_fields as $key => $value) {
601
				echo "\n";
602
				echo '<input type="hidden" name="'.$key.'" value="'.$value.'"/>';
603
			}
604
		}
605
		echo '<br /><button class="save" type="submit" onclick="checkLearnPath(\''.addslashes(get_lang('DocumentsWillBeAddedToo')).'\')">'.get_lang('Ok').'</button>';
606
		CourseSelectForm :: display_hidden_quiz_questions($course);
607
		CourseSelectForm :: display_hidden_scorm_directories($course);
608
		echo '</form>';
609
		echo '<div id="dynamic_div" style="display:block;margin-left:40%;margin-top:10px;height:50px;"></div>';
610
	}
611
}
(2-2/3)