Project

General

Profile

Bug #5505 » userportal.lib.php

Yoselyn Castillo, 26/10/2012 15:30

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

    
4
use \ChamiloSession as Session;
5

    
6
class IndexManager {
7
	var $tpl 	= false; //An instance of the template engine
8
	var $name 	= '';
9
	
10
	var $home			= '';
11
	var $default_home 	= 'home/';    
12
	
13
	function __construct($title) {					
14
		$this->tpl = new Template($title);		
15
		$this->home     = api_get_home_path();
16
		$this->user_id  = api_get_user_id();
17
		$this->load_directories_preview = false;
18
        
19
		if (api_get_setting('show_documents_preview') == 'true') {
20
			$this->load_directories_preview = true;
21
		}		
22
	}	
23
	
24
	function set_login_form() {
25
		global $loginFailed;
26
		
27
		$login_form = '';
28
	
29
		if (!($this->user_id) || api_is_anonymous($this->user_id)) {
30
	
31
			// Only display if the user isn't logged in.
32
			$this->tpl->assign('login_language_form', api_display_language_form(true));
33
			$this->tpl->assign('login_form',  self::display_login_form());
34
			
35
			if ($loginFailed) {				
36
				$this->tpl->assign('login_failed',  self::handle_login_failed());
37
			}
38
	
39
			if (api_get_setting('allow_lostpassword') == 'true' || api_get_setting('allow_registration') == 'true') {
40
				$login_form .= '<ul class="nav nav-list">';
41
				if (api_get_setting('allow_registration') != 'false') {
42
					$login_form .= '<li><a href="main/auth/inscription.php">'.get_lang('Reg').'</a></li>';					
43
				}
44
				if (api_get_setting('allow_lostpassword') == 'true') {
45
					$login_form .= '<li><a href="main/auth/lostPassword.php">'.get_lang('LostPassword').'</a></li>';
46
				}
47
				$login_form .= '</ul>';
48
			}
49
			$this->tpl->assign('login_options',  $login_form);
50
		}
51
	}
52
	
53
	
54
	function return_exercise_block($personal_course_list) {
55
		require_once api_get_path(SYS_CODE_PATH).'exercice/exercise.lib.php';
56
		$exercise_list = array();
57
		if (!empty($personal_course_list)) {
58
			foreach($personal_course_list as  $course_item) {
59
				$course_code 	= $course_item['c'];
60
				$session_id 	= $course_item['id_session'];
61
					
62
				$exercises = get_exercises_to_be_taken($course_code, $session_id);
63
	
64
				foreach($exercises as $exercise_item) {
65
					$exercise_item['course_code'] 	= $course_code;
66
					$exercise_item['session_id'] 	= $session_id;
67
					$exercise_item['tms'] 	= api_strtotime($exercise_item['end_time'], 'UTC');
68
						
69
					$exercise_list[] = $exercise_item;
70
				}
71
			}
72
			if (!empty($exercise_list)) {
73
				$exercise_list = msort($exercise_list, 'tms');
74
				$my_exercise = $exercise_list[0];
75
				$url = Display::url($my_exercise['title'], api_get_path(WEB_CODE_PATH).'exercice/overview.php?exerciseId='.$my_exercise['id'].'&cidReq='.$my_exercise['course_code'].'&id_session='.$my_exercise['session_id']);
76
				$this->tpl->assign('exercise_url', $url);
77
				$this->tpl->assign('exercise_end_date', api_convert_and_format_date($my_exercise['end_time'], DATE_FORMAT_SHORT));
78
			}
79
		}
80
	}
81
	
82
	function return_announcements($show_slide = true) {	
83
		// Display System announcements
84
		$announcement = isset($_GET['announcement']) ? $_GET['announcement'] : null;
85
		$announcement = intval($announcement);	
86
        
87
		if (!api_is_anonymous() && $this->user_id) {
88
			$visibility = api_is_allowed_to_create_course() ? SystemAnnouncementManager::VISIBLE_TEACHER : SystemAnnouncementManager::VISIBLE_STUDENT;
89
			if ($show_slide) {
90
				$announcements = SystemAnnouncementManager :: display_announcements_slider($visibility, $announcement);                
91
			} else {
92
				$announcements = SystemAnnouncementManager :: display_all_announcements($visibility, $announcement);
93
			}
94
		} else {
95
			if ($show_slide) {
96
				$announcements = SystemAnnouncementManager :: display_announcements_slider(SystemAnnouncementManager::VISIBLE_GUEST, $announcement);
97
			} else {
98
				$announcements = SystemAnnouncementManager :: display_all_announcements(SystemAnnouncementManager::VISIBLE_GUEST, $announcement);
99
			}
100
		}
101
		return $announcements;
102
	}	
103
		
104
	/**
105
     * Alias for the online_logout() function	 
106
	 */
107
	function logout() {        
108
        online_logout($this->user_id, true);
109
	}
110
	
111
	/**
112
	 * This function checks if there are courses that are open to the world in the platform course categories (=faculties)
113
	 *
114
	 * @param string $category
115
	 * @return boolean
116
	 */
117
	function category_has_open_courses($category) {
118
		$setting_show_also_closed_courses = api_get_setting('show_closed_courses') == 'true';
119
		$main_course_table = Database :: get_main_table(TABLE_MAIN_COURSE);
120
        $category = Database::escape_string($category);
121
		$sql_query = "SELECT * FROM $main_course_table WHERE category_code='$category'";
122
		$sql_result = Database::query($sql_query);
123
		while ($course = Database::fetch_array($sql_result)) {
124
			if (!$setting_show_also_closed_courses) {
125
				if ((api_get_user_id() > 0 && $course['visibility'] == COURSE_VISIBILITY_OPEN_PLATFORM) || ($course['visibility'] == COURSE_VISIBILITY_OPEN_WORLD)) {
126
					return true; //at least one open course
127
				}
128
			} else {
129
				if (isset($course['visibility'])) {
130
					return true; // At least one course (it does not matter weither it's open or not because $setting_show_also_closed_courses = true).
131
				}
132
			}
133
		}
134
		return false;
135
	}
136
	
137
	
138
	/**
139
	 * Displays the right-hand menu for anonymous users:
140
	 * login form, useful links, help section
141
	 * Warning: function defines globals
142
	 * @version 1.0.1
143
	 * @todo does $_plugins need to be global?
144
	 */
145
	function display_anonymous_right_menu() {
146
		global $loginFailed, $_user;        
147
		$display_add_course_link	= api_is_allowed_to_create_course() && ($_SESSION['studentview'] != 'studentenview');	
148
		$current_user_id        	= api_get_user_id();
149
	
150
		echo self::set_login_form(false);				
151
		echo self::return_teacher_link();		
152
		echo self::return_notice();		
153
	}	
154
	
155
	function return_teacher_link() {
156
		$html = '';
157
		if (!empty($this->user_id)) {
158
			// tabs that are deactivated are added here
159
		
160
			$show_menu = false;
161
			$show_create_link = false;
162
			$show_course_link = false;
163
		
164
			if (api_is_platform_admin() || api_is_course_admin() || api_is_allowed_to_create_course()) {
165
				$show_menu = true;
166
				$show_course_link = true;
167
			} else {
168
				if (api_get_setting('allow_students_to_browse_courses') == 'true') {
169
					$show_menu = true;
170
					$show_course_link = true;
171
				}
172
			}
173
		
174
			if ($show_menu && ($show_create_link || $show_course_link )) {
175
				$show_menu = true;
176
			} else {
177
				$show_menu = false;
178
			}
179
		}	
180
		
181
		// My Account section
182
		
183
		if ($show_menu) {
184
			$html .= '<ul class="nav nav-list">';
185
			if ($show_create_link) {			
186
				$html .= '<li><a href="main/create_course/add_course.php" class="add course">'.(api_get_setting('course_validation') == 'true' ? get_lang('CreateCourseRequest') : get_lang('CourseCreate')).'</a></li>';
187
			}
188
			
189
			if ($show_course_link) {
190
				if (!api_is_drh() && !api_is_session_admin()) {
191
					$html .=  '<li><a href="main/auth/courses.php" class="list course">'.get_lang('CourseCatalog').'</a></li>';					
192
				} else {
193
					$html .= '<li><a href="main/dashboard/index.php">'.get_lang('Dashboard').'</a></li>';
194
				}
195
			}		
196
			$html .= '</ul>';
197
		}	
198
		
199
		if (!empty($html)) {
200
			$html = self::show_right_block(get_lang('Courses'), $html, 'teacher_block');
201
		}
202
		return $html;
203
	}
204
	
205
	/* Includes a created page */
206
	function return_home_page() {	
207

    
208
		// Including the page for the news
209
		$html = '';
210
		
211
		if (!empty($_GET['include']) && preg_match('/^[a-zA-Z0-9_-]*\.html$/', $_GET['include'])) {
212
			$open = @(string)file_get_contents(api_get_path(SYS_PATH).$this->home.$_GET['include']);
213
			$html = api_to_system_encoding($open, api_detect_encoding(strip_tags($open)));		 			
214
		} else {		
215
			if (!empty($_SESSION['user_language_choice'])) {
216
				$user_selected_language = $_SESSION['user_language_choice'];
217
			} elseif (!empty($_SESSION['_user']['language'])) {
218
				$user_selected_language = $_SESSION['_user']['language'];
219
			} else {
220
				$user_selected_language = api_get_setting('platformLanguage');
221
			}		
222
			if (!file_exists($this->home.'home_news_'.$user_selected_language.'.html')) {
223
				if (file_exists($this->home.'home_top.html')) {
224
					$home_top_temp = file($this->home.'home_top.html');
225
				} else {
226
					$home_top_temp = file($this->default_home.'home_top.html');
227
				}
228
				$home_top_temp = implode('', $home_top_temp);
229
			} else {
230
				if (file_exists($this->home.'home_top_'.$user_selected_language.'.html')) {
231
					$home_top_temp = file_get_contents($this->home.'home_top_'.$user_selected_language.'.html');
232
				} else {
233
					$home_top_temp = file_get_contents($this->home.'home_top.html');
234
				}
235
			}
236
			if (trim($home_top_temp) == '' && api_is_platform_admin()) {
237
				$home_top_temp = get_lang('PortalHomepageDefaultIntroduction');
238
			}
239
			$open = str_replace('{rel_path}', api_get_path(REL_PATH), $home_top_temp);
240
			$html = api_to_system_encoding($open, api_detect_encoding(strip_tags($open)));				
241
		}
242
		return $html;		
243
	}
244
	
245
	function return_notice() { 
246
		$sys_path               = api_get_path(SYS_PATH);
247
		$user_selected_language = api_get_interface_language();
248
		
249
		$html = '';
250
		// Notice
251
		$home_notice = @(string)file_get_contents($sys_path.$this->home.'home_notice_'.$user_selected_language.'.html');
252
		if (empty($home_notice)) {
253
			$home_notice = @(string)file_get_contents($sys_path.$this->home.'home_notice.html');
254
		}
255
		
256
		if (!empty($home_notice)) {
257
			$home_notice = api_to_system_encoding($home_notice, api_detect_encoding(strip_tags($home_notice)));
258
            $home_notice = Display::div($home_notice, array('class'  => 'homepage_notice'));
259
			$html = self::show_right_block(get_lang('Notice'), $home_notice, 'notice_block');
260
		}
261
        return $html;
262
    }
263
    
264
    function return_help() { 
265
        $user_selected_language = api_get_interface_language();
266
        $sys_path               = api_get_path(SYS_PATH);
267
        $platformLanguage       = api_get_setting('platformLanguage');
268
        
269
		// Help section.
270
		/* Hide right menu "general" and other parts on anonymous right menu. */
271
		
272
		if (!isset($user_selected_language)) {
273
			$user_selected_language = $platformLanguage;
274
		}
275
        
276
        $html = null;		
277
		$home_menu = @(string)file_get_contents($sys_path.$this->home.'home_menu_'.$user_selected_language.'.html');
278
		if (!empty($home_menu)) {
279
			$home_menu_content .= '<ul class="nav nav-list">';
280
			$home_menu_content .= api_to_system_encoding($home_menu, api_detect_encoding(strip_tags($home_menu)));
281
			$home_menu_content .= '</ul>';
282
			$html .= self::show_right_block(get_lang('MenuGeneral'), $home_menu_content, 'help_block');
283
		}        
284
		return $html;
285
	}
286
	    
287
    function return_skills_links() {
288
        $html = '';
289
        if (api_get_setting('allow_skills_tool') == 'true') {
290
            $content = '<ul class="nav nav-list">';      
291
            
292
            $content .= Display::tag('li', Display::url(get_lang('MySkills'), api_get_path(WEB_CODE_PATH).'social/skills_wheel.php'));
293
            
294
            if (api_get_setting('allow_hr_skills_management') == 'true' || api_is_platform_admin()) {
295
                $content .= Display::tag('li', Display::url(get_lang('ManageSkills'), api_get_path(WEB_CODE_PATH).'admin/skills_wheel.php'));
296
            }
297
            $content .= '</ul>';        
298
            $html = self::show_right_block(get_lang("Skills"), $content, 'skill_block');
299
        }
300
        return $html;
301
    }
302
	
303
	/**
304
	 * Reacts on a failed login:
305
	 * Displays an explanation with a link to the registration form.
306
	 *
307
	 * @version 1.0.1
308
	 */
309
	function handle_login_failed() {
310
        $message = get_lang('InvalidId');
311
        
312
		if (!isset($_GET['error'])) {	
313
			if (api_is_self_registration_allowed()) {
314
				$message = get_lang('InvalidForSelfRegistration');
315
			}
316
		} else {
317
			switch ($_GET['error']) {
318
				case '':					
319
					if (api_is_self_registration_allowed()) {
320
						$message = get_lang('InvalidForSelfRegistration');
321
					}
322
					break;
323
				case 'account_expired':
324
					$message = get_lang('AccountExpired');
325
					break;
326
				case 'account_inactive':
327
					$message = get_lang('AccountInactive');
328
					break;
329
				case 'user_password_incorrect':
330
					$message = get_lang('InvalidId');
331
					break;
332
				case 'access_url_inactive':
333
					$message = get_lang('AccountURLInactive');
334
					break;
335
                case 'unrecognize_sso_origin':
336
                    //$message = get_lang('SSOError');
337
                    break;
338
			}
339
		}
340
		return Display::return_message($message, 'error');
341
	}	
342
	
343
	/**
344
	 * Display list of courses in a category.
345
	 * (for anonymous users)
346
	 *
347
	 * @version 1.1
348
	 * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University - refactoring and code cleaning
349
     * @author Julio Montoya <gugli100@gmail.com>, Beeznest template modifs
350
	 */
351
	function return_courses_in_categories() {
352
        $result = '';
353
		$ctok = $_SESSION['sec_token'];
354
		$stok = Security::get_token();
355
	
356
		// Initialization.
357
		$user_identified = (api_get_user_id() > 0 && !api_is_anonymous());
358
		$web_course_path = api_get_path(WEB_COURSE_PATH);
359
		$category = Database::escape_string($_GET['category']);
360
		$setting_show_also_closed_courses = api_get_setting('show_closed_courses') == 'true';
361
	
362
		// Database table definitions.
363
		$main_course_table      = Database :: get_main_table(TABLE_MAIN_COURSE);
364
		$main_category_table    = Database :: get_main_table(TABLE_MAIN_CATEGORY);		
365
	
366
		// Get list of courses in category $category.
367
		$sql_get_course_list = "SELECT * FROM $main_course_table cours
368
	                                WHERE category_code = '".Database::escape_string($_GET['category'])."'
369
	                                ORDER BY title, UPPER(visual_code)";
370
	
371
		// Showing only the courses of the current access_url_id.
372
		global $_configuration;
373
		if ($_configuration['multiple_access_urls']) {
374
			$url_access_id = api_get_current_access_url_id();
375
			if ($url_access_id != -1) {
376
				$tbl_url_rel_course = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE);
377
				$sql_get_course_list = "SELECT * FROM $main_course_table as course INNER JOIN $tbl_url_rel_course as url_rel_course
378
	                    ON (url_rel_course.course_code=course.code)
379
	                    WHERE access_url_id = $url_access_id AND category_code = '".Database::escape_string($_GET['category'])."' ORDER BY title, UPPER(visual_code)";
380
			}
381
		}
382
	
383
		// Removed: AND cours.visibility='".COURSE_VISIBILITY_OPEN_WORLD."'
384
		$sql_result_courses = Database::query($sql_get_course_list);
385
	
386
		while ($course_result = Database::fetch_array($sql_result_courses)) {
387
			$course_list[] = $course_result;
388
		}
389
	
390
		$platform_visible_courses = '';
391
		// $setting_show_also_closed_courses
392
		if ($user_identified) {
393
			if ($setting_show_also_closed_courses) {
394
				$platform_visible_courses = '';
395
			} else {
396
				$platform_visible_courses = "  AND (t3.visibility='".COURSE_VISIBILITY_OPEN_WORLD."' OR t3.visibility='".COURSE_VISIBILITY_OPEN_PLATFORM."' )";
397
			}
398
		} else {
399
			if ($setting_show_also_closed_courses) {
400
				$platform_visible_courses = '';
401
			} else {
402
				$platform_visible_courses = "  AND (t3.visibility='".COURSE_VISIBILITY_OPEN_WORLD."' )";
403
			}
404
		}
405
		$sqlGetSubCatList = "
406
	                SELECT t1.name,t1.code,t1.parent_id,t1.children_count,COUNT(DISTINCT t3.code) AS nbCourse
407
	                FROM $main_category_table t1
408
	                LEFT JOIN $main_category_table t2 ON t1.code=t2.parent_id
409
	                LEFT JOIN $main_course_table t3 ON (t3.category_code=t1.code $platform_visible_courses)
410
	                WHERE t1.parent_id ". (empty ($category) ? "IS NULL" : "='$category'")."
411
	                GROUP BY t1.name,t1.code,t1.parent_id,t1.children_count ORDER BY t1.tree_pos, t1.name";
412
	
413
	
414
		// Showing only the category of courses of the current access_url_id		
415
		if ($_configuration['multiple_access_urls']) {
416
			$url_access_id = api_get_current_access_url_id();
417
			if ($url_access_id != -1) {
418
				$tbl_url_rel_course = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE);
419
				$sqlGetSubCatList = "
420
	                SELECT t1.name,t1.code,t1.parent_id,t1.children_count,COUNT(DISTINCT t3.code) AS nbCourse
421
	                FROM $main_category_table t1
422
	                LEFT JOIN $main_category_table t2 ON t1.code=t2.parent_id
423
	                LEFT JOIN $main_course_table t3 ON (t3.category_code=t1.code $platform_visible_courses)
424
	                INNER JOIN $tbl_url_rel_course as url_rel_course
425
	                    ON (url_rel_course.course_code=t3.code)
426
	                WHERE access_url_id = $url_access_id AND t1.parent_id ".(empty($category) ? "IS NULL" : "='$category'")."
427
	                GROUP BY t1.name,t1.code,t1.parent_id,t1.children_count ORDER BY t1.tree_pos, t1.name";
428
			}
429
		}
430
	
431
		$resCats = Database::query($sqlGetSubCatList);
432
		$thereIsSubCat = false;
433
		if (Database::num_rows($resCats) > 0) {
434
			$htmlListCat = Display::page_header(get_lang('CatList'));
435
            $htmlListCat .= '<ul>';
436
			while ($catLine = Database::fetch_array($resCats)) {
437
				if ($catLine['code'] != $category) {	
438
					$category_has_open_courses = self::category_has_open_courses($catLine['code']);
439
					if ($category_has_open_courses) {
440
						// The category contains courses accessible to anonymous visitors.
441
						$htmlListCat .= '<li>';
442
						$htmlListCat .= '<a href="'.api_get_self().'?category='.$catLine['code'].'">'.$catLine['name'].'</a>';
443
						if (api_get_setting('show_number_of_courses') == 'true') {
444
							$htmlListCat .= ' ('.$catLine['nbCourse'].' '.get_lang('Courses').')';
445
						}
446
						$htmlListCat .= "</li>";
447
						$thereIsSubCat = true;
448
					} elseif ($catLine['children_count'] > 0) {
449
						// The category has children, subcategories.
450
						$htmlListCat .= '<li>';
451
						$htmlListCat .= '<a href="'.api_get_self().'?category='.$catLine['code'].'">'.$catLine['name'].'</a>';
452
						$htmlListCat .= "</li>";
453
						$thereIsSubCat = true;
454
					}
455
					/* End changed code to eliminate the (0 courses) after empty categories. */
456
					elseif (api_get_setting('show_empty_course_categories') == 'true') {
457
						$htmlListCat .= '<li>';
458
						$htmlListCat .= $catLine['name'];
459
						$htmlListCat .= "</li>";
460
						$thereIsSubCat = true;
461
					} // Else don't set thereIsSubCat to true to avoid printing things if not requested.
462
				} else {
463
					$htmlTitre = '<p>';
464
					if (api_get_setting('show_back_link_on_top_of_tree') == 'true') {
465
						$htmlTitre .= '<a href="'.api_get_self().'">&lt;&lt; '.get_lang('BackToHomePage').'</a>';
466
					}
467
					if (!is_null($catLine['parent_id']) || (api_get_setting('show_back_link_on_top_of_tree') != 'true' && !is_null($catLine['code']))) {
468
						$htmlTitre .= '<a href="'.api_get_self().'?category='.$catLine['parent_id'].'">&lt;&lt; '.get_lang('Up').'</a>';
469
					}
470
					$htmlTitre .= "</p>";
471
					if ($category != "" && !is_null($catLine['code'])) {
472
						$htmlTitre .= '<h3>'.$catLine['name']."</h3>";
473
					} else {
474
						$htmlTitre .= '<h3>'.get_lang('Categories')."</h3>";
475
					}
476
				}
477
			}
478
			$htmlListCat .= "</ul>";
479
		}
480
		$result .= $htmlTitre;
481
		if ($thereIsSubCat) {
482
			$result .=  $htmlListCat;
483
		}
484
		while ($categoryName = Database::fetch_array($resCats)) {
485
			$result .= '<h3>' . $categoryName['name'] . "</h3>\n";
486
		}
487
		$numrows = Database::num_rows($sql_result_courses);
488
		$courses_list_string = '';
489
		$courses_shown = 0;
490
		if ($numrows > 0) {
491
			
492
			$courses_list_string .= Display::page_header(get_lang('CourseList'));
493
            $courses_list_string .= "<ul>";
494
	
495
			if (api_get_user_id()) {
496
				$courses_of_user = self::get_courses_of_user(api_get_user_id());
497
			}
498
	
499
			foreach ($course_list as $course) {
500
				// $setting_show_also_closed_courses
501
				if (!$setting_show_also_closed_courses) {
502
					// If we do not show the closed courses
503
					// we only show the courses that are open to the world (to everybody)
504
					// and the courses that are open to the platform (if the current user is a registered user.
505
					if( ($user_identified && $course['visibility'] == COURSE_VISIBILITY_OPEN_PLATFORM) || ($course['visibility'] == COURSE_VISIBILITY_OPEN_WORLD)) {
506
						$courses_shown++;
507
						$courses_list_string .= "<li>\n";
508
						$courses_list_string .= '<a href="'.$web_course_path.$course['directory'].'/">'.$course['title'].'</a><br />';
509
                        $course_details = array();
510
						if (api_get_setting('display_coursecode_in_courselist') == 'true') {
511
							$course_details[] = $course['visual_code'];
512
						}
513
						if (api_get_setting('display_teacher_in_courselist') == 'true') {
514
							$course_details[] = $course['tutor_name'];
515
						}
516
						if (api_get_setting('show_different_course_language') == 'true' && $course['course_language'] != api_get_setting('platformLanguage')) {
517
							$course_details[] = $course['course_language'];
518
						}
519
                        $courses_list_string .= implode(' - ', $course_details);
520
						$courses_list_string .= "</li>\n";
521
					}
522
				} else {
523
                    // We DO show the closed courses.
524
                    // The course is accessible if (link to the course homepage):
525
                    // 1. the course is open to the world (doesn't matter if the user is logged in or not): $course['visibility'] == COURSE_VISIBILITY_OPEN_WORLD);
526
                    // 2. the user is logged in and the course is open to the world or open to the platform: ($user_identified && $course['visibility'] == COURSE_VISIBILITY_OPEN_PLATFORM);
527
                    // 3. the user is logged in and the user is subscribed to the course and the course visibility is not COURSE_VISIBILITY_CLOSED;
528
                    // 4. the user is logged in and the user is course admin of te course (regardless of the course visibility setting);
529
                    // 5. the user is the platform admin api_is_platform_admin().
530
                    //
531
                    $courses_shown++;
532
					$courses_list_string .= "<li>\n";
533
					if ($course['visibility'] == COURSE_VISIBILITY_OPEN_WORLD
534
                        || ($user_identified && $course['visibility'] == COURSE_VISIBILITY_OPEN_PLATFORM)
535
                        || ($user_identified && key_exists($course['code'], $courses_of_user) && $course['visibility'] != COURSE_VISIBILITY_CLOSED)
536
                        || $courses_of_user[$course['code']]['status'] == '1'
537
                        || api_is_platform_admin()) {
538
                            $courses_list_string .= '<a href="'.$web_course_path.$course['directory'].'/">';
539
                        }
540
                        $courses_list_string .= $course['title'];
541
                    if ($course['visibility'] == COURSE_VISIBILITY_OPEN_WORLD
542
						|| ($user_identified && $course['visibility'] == COURSE_VISIBILITY_OPEN_PLATFORM)
543
						|| ($user_identified && key_exists($course['code'], $courses_of_user) && $course['visibility'] != COURSE_VISIBILITY_CLOSED)
544
	                        || $courses_of_user[$course['code']]['status'] == '1'
545
						|| api_is_platform_admin()) {
546
                        $courses_list_string .= '</a><br />';
547
                    }
548
                    $course_details = array();
549
                    if (api_get_setting('display_coursecode_in_courselist') == 'true') {
550
                        $course_details[] = $course['visual_code'];
551
                    }
552
//						if (api_get_setting('display_coursecode_in_courselist') == 'true' && api_get_setting('display_teacher_in_courselist') == 'true') {
553
//	                    $courses_list_string .= ' - ';
554
//				}
555
                    if (api_get_setting('display_teacher_in_courselist') == 'true') {
556
						$course_details[] = $course['tutor_name'];
557
	                }
558
	                if (api_get_setting('show_different_course_language') == 'true' && $course['course_language'] != api_get_setting('platformLanguage')) {
559
						$course_details[] = $course['course_language'];
560
	                }
561
                    if (api_get_setting('show_different_course_language') == 'true' && $course['course_language'] != api_get_setting('platformLanguage')) {
562
	                    $course_details[] = $course['course_language'];
563
	                }
564
                    
565
                    $courses_list_string .= implode(' - ', $course_details);
566
					// We display a subscription link if:
567
	                // 1. it is allowed to register for the course and if the course is not already in the courselist of the user and if the user is identiefied
568
	                // 2.
569
                    if ($user_identified && !key_exists($course['code'], $courses_of_user)) {
570
                        if ($course['subscribe'] == '1') {
571
                        $courses_list_string .= '<form action="main/auth/courses.php?action=subscribe&category='.Security::remove_XSS($_GET['category']).'" method="post">';
572
                        $courses_list_string .= '<input type="hidden" name="sec_token" value="'.$stok.'">';
573
                        $courses_list_string .= '<input type="hidden" name="subscribe" value="'.$course['code'].'" />';
574
                            $courses_list_string .= '<input type="image" name="unsub" src="main/img/enroll.gif" alt="'.get_lang('Subscribe').'" />'.get_lang('Subscribe').'</form>';
575
                        } else {
576
                            $courses_list_string .= '<br />'.get_lang('SubscribingNotAllowed');
577
                        }
578
                    }
579
                    $courses_list_string .= "</li>";
580
	            } //end else
581
	        } // end foreach
582
	        $courses_list_string .= "</ul>";
583
        }
584
        if ($courses_shown > 0) {
585
            // Only display the list of courses and categories if there was more than
586
                    // 0 courses visible to the world (we're in the anonymous list here).
587
            $result .=  $courses_list_string;
588
        }
589
		if ($category != '') {
590
			$result .=  '<p><a href="'.api_get_self().'"> ' . Display :: return_icon('back.png', get_lang('BackToHomePage')) . get_lang('BackToHomePage') . '</a></p>';
591
		}
592
        return $result; 
593
	}
594
	
595
	/**
596
	* retrieves all the courses that the user has already subscribed to
597
		* @author Patrick Cool <patrick.cool@UGent.be>, Ghent University, Belgium
598
	* @param int $user_id: the id of the user
599
	* @return array an array containing all the information of the courses of the given user
600
		*/
601
	function get_courses_of_user($user_id) {
602
		$table_course       = Database::get_main_table(TABLE_MAIN_COURSE);
603
    	$table_course_user  = Database::get_main_table(TABLE_MAIN_COURSE_USER);
604
		// Secondly we select the courses that are in a category (user_course_cat <> 0) and sort these according to the sort of the category
605
		$user_id = intval($user_id);
606
		$sql_select_courses = "SELECT course.code k, course.visual_code  vc, course.subscribe subscr, course.unsubscribe unsubscr,
607
    		course.title i, course.tutor_name t, course.db_name db, course.directory dir, course_rel_user.status status,
608
    		course_rel_user.sort sort, course_rel_user.user_course_cat user_course_cat
609
    		FROM    $table_course       course,
610
    		$table_course_user  course_rel_user
611
    		WHERE course.code = course_rel_user.course_code
612
    		AND   course_rel_user.user_id = '".$user_id."'
613
                                    AND course_rel_user.relation_type<>".COURSE_RELATION_TYPE_RRHH."
614
                                    ORDER BY course_rel_user.sort ASC";
615
	    $result = Database::query($sql_select_courses);
616
	    $courses = array();
617
	    while ($row = Database::fetch_array($result)) {
618
	        // We only need the database name of the course.
619
	        $courses[$row['k']] = array('db' => $row['db'], 'code' => $row['k'], 'visual_code' => $row['vc'], 'title' => $row['i'], 'directory' => $row['dir'], 'status' => $row['status'], 'tutor' => $row['t'], 'subscribe' => $row['subscr'], 'unsubscribe' => $row['unsubscr'], 'sort' => $row['sort'], 'user_course_category' => $row['user_course_cat']);
620
	    }
621
		return $courses;
622
	}	
623
	
624
    /**
625
     * @todo use the template system
626
     */
627
	function show_right_block($title, $content, $id = null, $params = null) {        
628
	    if (!empty($id)) {            
629
            $params['id'] = $id;
630
        }        
631
        $params['class'] = 'well sidebar-nav';
632
        $html = null;        
633
		if (!empty($title)) {
634
			$html.= '<h4>'.$title.'</h4>';
635
		}        
636
		$html.= $content;
637
        $html = Display::div($html, $params);
638
		return $html;
639
	}
640
	
641
	/**
642
	 * Adds a form to let users login
643
	 * @version 1.1
644
	 */
645
	function display_login_form() {
646
		$form = new FormValidator('formLogin', 'POST', null,  null, array('class'=>'form-vertical'));
647
        // 'placeholder'=>get_lang('UserName')
648
        //'autocomplete'=>"off",        
649
        
650
		$form->addElement('text', 'login', get_lang('UserName'), array('class' => 'span2 autocapitalize_off', 'autofocus' => 'autofocus'));
651
		$form->addElement('password', 'password', get_lang('Pass'), array('class' => 'span2'));
652
		$form->addElement('style_submit_button','submitAuth', get_lang('LoginEnter'), array('class' => 'btn'));		
653
		$html = $form->return_form();
654
		if (api_get_setting('openid_authentication') == 'true') {
655
			include_once 'main/auth/openid/login.php';
656
			$html .= '<div>'.openid_form().'</div>';
657
		}
658
		return $html;
659
	}
660
	
661
	function return_search_block() {
662
		$html = '';		
663
		if (api_get_setting('search_enabled') == 'true') {
664
			$html .= '<div class="searchbox">';
665
			$search_btn = get_lang('Search');			
666
			$search_content = '<br />
667
		    	<form action="main/search/" method="post">
668
		    	<input type="text" id="query" class="span2" name="query" value="" />
669
		    	<button class="save" type="submit" name="submit" value="'.$search_btn.'" />'.$search_btn.' </button>
670
		    	</form></div>';    
671
			$html .= self::show_right_block(get_lang('Search'), $search_content, 'search_block');
672
		}
673
		return $html;	
674
	}
675
	
676
	function return_classes_block() {
677
		$html = '';
678
		if (api_get_setting('show_groups_to_users') == 'true') {
679
			require_once api_get_path(LIBRARY_PATH).'usergroup.lib.php';
680
			$usergroup = new Usergroup();
681
			$usergroup_list = $usergroup->get_usergroup_by_user(api_get_user_id());
682
			$classes = '';
683
			if (!empty($usergroup_list)) {
684
				foreach($usergroup_list as $group_id) {
685
					$data = $usergroup->get($group_id);
686
					$data['name'] = Display::url($data['name'], api_get_path(WEB_CODE_PATH).'user/classes.php?id='.$data['id']);
687
					$classes .= Display::tag('li', $data['name']);
688
				}
689
			}
690
			if (api_is_platform_admin()) {
691
				$classes .= Display::tag('li',  Display::url(get_lang('AddClasses') ,api_get_path(WEB_CODE_PATH).'admin/usergroups.php?action=add'));
692
			}
693
			if (!empty($classes)) {
694
				$classes = Display::tag('ul', $classes, array('class'=>'nav nav-list'));
695
				$html .= self::show_right_block(get_lang('Classes'), $classes, 'classes_block');
696
			}		
697
		}
698
		return $html;
699
	}
700
	
701
	function return_reservation_block() {
702
		$html = '';
703
		if (api_get_setting('allow_reservation') == 'true' && api_is_allowed_to_create_course()) {
704
			$booking_content .='<ul class="nav nav-list">';
705
			$booking_content .='<a href="main/reservation/reservation.php">'.get_lang('ManageReservations').'</a><br />';
706
			$booking_content .='</ul>';
707
			$html .= self::show_right_block(get_lang('Booking'), $booking_content, 'reservation_block');
708
		}
709
		return $html;
710
	}
711
    
712
    function return_user_image_block() {		
713
		$img_array = UserManager::get_user_picture_path_by_id(api_get_user_id(), 'web', true, true);		
714
		$img_array = UserManager::get_picture_user(api_get_user_id(), $img_array['file'], 50, USER_IMAGE_SIZE_MEDIUM, ' width="90" height="90" ');		
715
        if (api_get_setting('allow_social_tool') == 'true') {
716
            $profile_content .='<a style="text-align:center" href="'.api_get_path(WEB_PATH).'main/social/home.php"><img src="'.$img_array['file'].'"  '.$img_array['style'].' ></a>';
717
        } else {
718
            $profile_content .='<a style="text-align:center"  href="'.api_get_path(WEB_PATH).'main/auth/profile.php"><img title="'.get_lang('EditProfile').'" src="'.$img_array['file'].'" '.$img_array['style'].'></a>';
719
        }		     
720
        $html = self::show_right_block(null, $profile_content, 'user_image_block', array('style' => 'text-align:center;'));
721
        return $html;
722
    }
723
	
724
	function return_profile_block() {
725
		$html = '';
726
		$user_id = api_get_user_id();
727
        
728
		if (empty($user_id)) {
729
			return; 
730
		}
731
	
732
		$profile_content .= '<ul class="nav nav-list">'; 
733
		
734
		//  @todo Add a platform setting to add the user image.
735
		if (api_get_setting('allow_message_tool') == 'true') {
736
			require_once api_get_path(LIBRARY_PATH).'group_portal_manager.lib.php';
737
		
738
			// New messages.
739
			$number_of_new_messages             = MessageManager::get_new_messages();
740
			// New contact invitations.
741
			$number_of_new_messages_of_friend   = SocialManager::get_message_number_invitation_by_user_id(api_get_user_id());
742
		
743
			// New group invitations sent by a moderator.
744
			$group_pending_invitations = GroupPortalManager::get_groups_by_user(api_get_user_id(), GROUP_USER_PERMISSION_PENDING_INVITATION, false);
745
			$group_pending_invitations = count($group_pending_invitations);
746
		
747
			$total_invitations = $number_of_new_messages_of_friend + $group_pending_invitations;
748
            $cant_msg = Display::badge($number_of_new_messages);			         
749
            
750
			$link = '';
751
			if (api_get_setting('allow_social_tool') == 'true') {
752
				$link = '?f=social';
753
			}
754
			$profile_content .= '<li><a href="'.api_get_path(WEB_PATH).'main/messages/inbox.php'.$link.'">'.get_lang('Inbox').$cant_msg.' </a></li>';
755
			$profile_content .= '<li><a href="'.api_get_path(WEB_PATH).'main/messages/new_message.php'.$link.'">'.get_lang('Compose').' </a></li>';            
756
		
757
			if (api_get_setting('allow_social_tool') == 'true') {                				
758
				$total_invitations = Display::badge($total_invitations);				                
759
				$profile_content .= '<li><a href="'.api_get_path(WEB_PATH).'main/social/invitations.php">'.get_lang('PendingInvitations').$total_invitations.'</a></li>';
760
			}
761
        }
762
        $profile_content .= '<li><a href="'.api_get_path(WEB_PATH).'main/auth/profile.php">'.get_lang('EditProfile').'</a></li>';        
763
        $profile_content .= '</ul>';
764
		$html = self::show_right_block(get_lang('Profile'), $profile_content, 'profile_block');
765
		return $html;
766
	}
767
	
768
	function return_navigation_links() {
769
		$html = '';
770
		
771
		// Deleting the myprofile link.
772
		if (api_get_setting('allow_social_tool') == 'true') {
773
			unset($this->tpl->menu_navigation['myprofile']);
774
		}
775
                
776
		// Main navigation section.
777
		// Tabs that are deactivated are added here.
778
		if (!empty($this->tpl->menu_navigation)) {            
779
			$content = '<ul class="nav nav-list">';
780
			foreach ($this->tpl->menu_navigation as $section => $navigation_info) {                
781
				$current = $section == $GLOBALS['this_section'] ? ' id="current"' : '';
782
				$content .= '<li'.$current.'>';
783
				$content .= '<a href="'.$navigation_info['url'].'" target="_self">'.$navigation_info['title'].'</a>';
784
				$content .= '</li>';
785
			}
786
			$content .= '</ul>';            
787
			$html = self::show_right_block(get_lang('MainNavigation'), $content, 'navigation_link_block');
788
		}        
789
		return $html;
790
	}
791
	
792
	function return_course_block() {
793
		$html = '';
794

    
795
		$show_create_link = false;
796
		$show_course_link = false;
797
				
798
		if ((api_get_setting('allow_users_to_create_courses') == 'false' && !api_is_platform_admin()) || api_is_student()) {
799
            $display_add_course_link = false;
800
        } else {
801
            $display_add_course_link = true;
802
        }
803
        //$display_add_course_link = api_is_allowed_to_create_course() && ($_SESSION['studentview'] != 'studentenview');
804
        
805
		if ($display_add_course_link) {
806
			$show_create_link = true;
807
		}
808
		
809
		if (api_is_platform_admin() || api_is_course_admin() || api_is_allowed_to_create_course()) {
810
			$show_course_link = true;
811
		} else {
812
			if (api_get_setting('allow_students_to_browse_courses') == 'true') {		
813
				$show_course_link = true;
814
			}
815
		}
816
		
817
		// My account section		
818
		$my_account_content = '<ul class="nav nav-list">';
819
        
820
		if ($show_create_link) {
821
			$my_account_content .= '<li><a href="main/create_course/add_course.php" class="add course">'.(api_get_setting('course_validation') == 'true' ? get_lang('CreateCourseRequest') : get_lang('CourseCreate')).'</a></li>';
822
		}
823
        
824
        //Sort courses
825
        $url = api_get_path(WEB_CODE_PATH).'auth/courses.php?action=sortmycourses';
826
        $my_account_content .= '<li>'.Display::url(get_lang('SortMyCourses'), $url, array('class' => 'sort course')).'</li>';
827

    
828
        //Course management                
829
		if ($show_course_link) {
830
			if (!api_is_drh()) {
831
				$my_account_content .= '<li><a href="main/auth/courses.php" class="list course">'.get_lang('CourseCatalog').'</a></li>';	
832
				
833
                if (isset($_GET['history']) && intval($_GET['history']) == 1) {
834
                    $my_account_content .= '<li><a href="user_portal.php">'.get_lang('DisplayTrainingList').'</a></li>';
835
                } else {
836
                    $my_account_content .= '<li><a href="user_portal.php?history=1"  class="history course">'.get_lang('HistoryTrainingSessions').'</a></li>';
837
                }
838
				
839
			} else {
840
				$my_account_content .= '<li><a href="main/dashboard/index.php">'.get_lang('Dashboard').'</a></li>';
841
			}
842
		}
843
        
844
		$my_account_content .= '</ul>';
845
		
846
		if (!empty($my_account_content)) {
847
			$html =  self::show_right_block(get_lang('Courses'), $my_account_content, 'course_block');
848
		}
849
		return $html;
850
	}
851
	
852
	/**
853
	 * The most important function here, prints the session and course list (user_portal.php)
854
	 *  
855
	 * */
856
	function return_courses_and_sessions($user_id) {		       
857
        $session_categories = array();        
858
        $load_history = (isset($_GET['history']) && intval($_GET['history']) == 1) ? true : false;
859
		
860
		if ($load_history) {
861
            //Load sessions in category in *history*
862
			$session_categories = UserManager::get_sessions_by_category($user_id, true);			
863
		} else {
864
            //Load sessions in category
865
			$session_categories = UserManager::get_sessions_by_category($user_id, false);
866
		}             
867

    
868
        $html = '';
869
        
870
        //Showing history title
871
		
872
		if ($load_history) {
873
			$html .= Display::page_subheader(get_lang('HistoryTrainingSession'));			
874
			if (empty($session_categories)) {
875
				$html .=  get_lang('YouDoNotHaveAnySessionInItsHistory');
876
			}
877
		}
878
        
879
        $courses_html = '';
880
        $special_courses = '';
881
        
882
        // If we're not in the history view...
883
        if (!isset($_GET['history'])) {
884
            //Display special courses
885
            $special_courses = CourseManager::display_special_courses($user_id, $this->load_directories_preview);                        
886
            //Display courses
887
            $courses_html .= CourseManager::display_courses($user_id, $this->load_directories_preview);
888
        }
889
        
890
        $sessions_with_category = '';
891
        $sessions_with_no_category = '';        
892
        
893
		if (is_array($session_categories)) {
894
            foreach ($session_categories as $session_category) {
895
                $session_category_id = $session_category['session_category']['id'];
896
                // Sessions and courses that are not in a session category
897
                if ($session_category_id == 0) {
898
                    
899
                    // Independent sessions
900
                    foreach ($session_category['sessions'] as $session) {                  
901
                        $session_id = $session['session_id'];
902

    
903
                        // Don't show empty sessions.
904
                        if (count($session['courses']) < 1) {
905
                            continue;
906
                        }
907

    
908
                        // Courses inside the current session.
909
                        $date_session_start = $session['date_start'];
910
                        $days_access_before_beginning  = $session['nb_days_access_before_beginning'];
911
                        $days_access_after_end  = $session['nb_days_access_after_end'];
912
                        $date_session_end = $session['date_end'];
913
                        $session_now = time();
914
                        $html_courses_session = '';
915
                        $count_courses_session = 0;
916
                        
917
                        foreach ($session['courses'] as $course) {
918
                            $is_coach_course = api_is_coach($session_id, $course['code']);
919
                            $allowed_time = 0;
920
                            $dif_time_after = 0;
921
                            if ($date_session_start != '0000-00-00') {
922
                                if ($is_coach_course) {
923
                                    $allowed_time = api_strtotime($date_session_start) - ($days_access_before_beginning*86400);
924
                                    if ($session_now > $date_session_end) {
925
                                        $dif_time_after = $session_now - api_strtotime($date_session_end);
926
                                        $dif_time_after = round($dif_time_after/86400);
927
                                    }
928
                                } else {
929
                                    $allowed_time = api_strtotime($date_session_start);
930
                                }
931
                            }
932
                            if ($session_now > $allowed_time && $days_access_after_end >= $dif_time_after-1) {
933
                                //read only and accesible
934
                                if (api_get_setting('hide_courses_in_sessions') == 'false') {
935
                                    $c = CourseManager :: get_logged_user_course_html($course, $session_id, 'session_course_item', true, $this->load_directories_preview);									
936
                                    $html_courses_session .= $c[1];
937
                                }
938
                                $count_courses_session++;
939
                            }
940
                        }
941

    
942
                        if ($count_courses_session > 0) {
943
                            $params = array();          							
944

    
945
                            $session_box = Display :: get_session_title_box($session_id);
946

    
947
                            $params['icon'] =  Display::return_icon('window_list.png', $session_box['title'], array('id' => 'session_img_'.$session_id), ICON_SIZE_LARGE);
948
                            $extra_info = !empty($session_box['coach']) ? $session_box['coach'] : null;
949
                            $extra_info .= !empty($session_box['coach']) ? ' - '.$session_box['dates'] : $session_box['dates'];
950

    
951
                            if (api_is_drh()) {
952
                                $session_link = $session_box['title'];
953
                                $params['link'] = null;
954
                            } else {
955
                                $session_link = Display::tag('a', $session_box['title'], array('href'=>api_get_path(WEB_CODE_PATH).'session/index.php?session_id='.$session_id));
956
                                $params['link'] = api_get_path(WEB_CODE_PATH).'session/index.php?session_id='.$session_id;
957
                            }
958

    
959
                            $params['title'] = $session_link;
960
                            $params['subtitle'] = $extra_info;                            
961

    
962
                            $params['right_actions'] = '';
963
                            if (api_is_platform_admin()) {
964
                                $params['right_actions'] .= '<a href="'.api_get_path(WEB_CODE_PATH).'admin/resume_session.php?id_session='.$session_id.'">';
965
                                $params['right_actions'] .= Display::return_icon('edit.png', get_lang('Edit'), array('align' => 'absmiddle'), ICON_SIZE_SMALL).'</a>';
966
                            }
967

    
968
                            if (api_get_setting('hide_courses_in_sessions') == 'false') {
969
                            //	$params['extra'] .=  $html_courses_session;
970
                            }
971
                            $sessions_with_no_category .= CourseManager::course_item_parent(CourseManager::course_item_html($params, true), $html_courses_session);
972
                        }
973
                    }                    
974
				} else {              
975
					// All sessions included in					
976
                    $count_courses_session = 0;
977
                    $html_sessions = '';                        
978
                    foreach ($session_category['sessions'] as $session) {
979
                        $session_id = $session['session_id'];
980
                        //var_dump($session);var_dump($session_category);
981
                        // Don't show empty sessions.
982
                        if (count($session['courses']) < 1) {
983
                            continue;
984
                        }
985
                        $date_session_start             = $session['date_start'];
986
                        //api_get_session_visibility($session_id);
987
                        $days_access_before_beginning   = $session['nb_days_access_before_beginning'];
988
                        $days_access_after_end  = $session['nb_days_access_after_end'];
989
                        $date_session_end = $session['date_end'];
990
                        $session_now = time();
991
                        $html_courses_session = '';
992
                        $count = 0;
993

    
994
                        foreach ($session['courses'] as $course) {
995
                            $is_coach_course = api_is_coach($session_id, $course['code']);
996
                            $dif_time_after = 0;
997
                            if ($is_coach_course) {
998
                                $allowed_time = api_strtotime($date_session_start) - ($days_access_before_beginning*86400);
999
                                if ($session_now > $date_session_end) {
1000
                                        $dif_time_after = $session_now - api_strtotime($date_session_end);
1001
                                        $dif_time_after = round($dif_time_after/86400);
1002
                                }
1003
                            } else {
1004
                                $allowed_time = api_strtotime($date_session_start);
1005
                            }
1006
                            if ($session_now > $allowed_time && $days_access_after_end >= $dif_time_after-1) {
1007
                                if (api_get_setting('hide_courses_in_sessions') == 'false') {
1008
                                    $c = CourseManager :: get_logged_user_course_html($course, $session_id, 'session_course_item');
1009
                                    $html_courses_session .= $c[1];
1010
                                }
1011
                                $count_courses_session++;
1012
                                $count++;
1013
                            }
1014
                        }
1015
                        
1016
                        $params = array();
1017

    
1018
                        if ($count > 0) {
1019
                            $session_box = Display :: get_session_title_box($session_id);                                                        
1020
                            $params['icon'] = Display::return_icon('window_list.png', $session_box['title'], array('width' => '48px', 'align' => 'absmiddle', 'id' => 'session_img_'.$session_id)) . ' ';
1021

    
1022
                            if (api_is_drh()) {
1023
                                $session_link = $session_box['title'];
1024
                                $params['link'] = null;
1025
                            } else {
1026
                                $session_link   = Display::tag('a', $session_box['title'], array('href'=>api_get_path(WEB_CODE_PATH).'session/index.php?session_id='.$session_id));
1027
                                $params['link'] =  api_get_path(WEB_CODE_PATH).'session/index.php?session_id='.$session_id;
1028
                            }
1029

    
1030
                            $params['title'] .=  $session_link;
1031

    
1032
                            $params['subtitle'] =  (!empty($session_box['coach']) ? $session_box['coach'].' | ' : '').$session_box['dates'];								
1033

    
1034
                            if (api_is_platform_admin()) {
1035
                                $params['right_actions'] .=  '<a href="'.api_get_path(WEB_CODE_PATH).'admin/resume_session.php?id_session='.$session_id.'">'.Display::return_icon('edit.png', get_lang('Edit'), array('align' => 'absmiddle'), ICON_SIZE_SMALL).'</a>';
1036
                            }                                
1037
                            $html_sessions .= CourseManager::course_item_html($params, true).$html_courses_session;                         
1038
                        }
1039
                    }                    
1040
                    
1041
                    if ($count_courses_session > 0) {
1042
                        $params = array();				
1043
                        $params['icon'] = Display::return_icon('folder_blue.png', $session_category['session_category']['name'], array(), ICON_SIZE_LARGE);
1044

    
1045
                        if (api_is_platform_admin()) {
1046
                            $params['right_actions'] .= '<a href="'.api_get_path(WEB_CODE_PATH).'admin/session_category_edit.php?&id='.$session_category['session_category']['id'].'">'.Display::return_icon('edit.png', get_lang('Edit'), array(), ICON_SIZE_SMALL).'</a>';
1047
                        }
1048

    
1049
                        $params['title'] .= $session_category['session_category']['name'];
1050

    
1051
                        if (api_is_platform_admin()) {
1052
                            $params['link']   = api_get_path(WEB_CODE_PATH).'admin/session_category_edit.php?&id='.$session_category['session_category']['id'];
1053
                        }
1054
                        
1055
                        $session_category_start_date = $session_category['session_category']['date_start'];
1056
                        $session_category_end_date = $session_category['session_category']['date_end'];
1057
                        
1058
                        if (!empty($session_category_start_date) && $session_category_start_date != '0000-00-00' && !empty($session_category_end_date) && $session_category_end_date != '0000-00-00' ) {
1059
                            $params['subtitle'] = sprintf(get_lang('FromDateXToDateY'), $session_category['session_category']['date_start'], $session_category['session_category']['date_end']);
1060
                        } else {                            
1061
                            if (!empty($session_category_start_date) && $session_category_start_date != '0000-00-00') {
1062
                                 $params['subtitle'] = get_lang('From').' '.$session_category_start_date;
1063
                            }
1064
                            if (!empty($session_category_end_date) && $session_category_end_date != '0000-00-00') {
1065
                                $params['subtitle'] = get_lang('Until').' '.$session_category_end_date;
1066
                            }
1067
                        }                        
1068
                        $sessions_with_category .= CourseManager::course_item_parent(CourseManager::course_item_html($params, true), $html_sessions);
1069
                    }
1070
					
1071
				}
1072
			}
1073
		}        
1074
        return $sessions_with_category.$sessions_with_no_category.$courses_html.$special_courses;
1075
	}
1076
    
1077
    /** 
1078
     * Shows a welcome message when the user doesn't have any content in the course list 
1079
     */
1080
    function return_welcome_to_course_block() {  	    
1081
        $count_courses = CourseManager::count_courses();        
1082
        $tpl = $this->tpl->get_template('layout/welcome_to_course.tpl');
1083
        
1084
        $course_catalog_url = api_get_path(WEB_CODE_PATH).'auth/courses.php';
1085
        $course_list_url = api_get_path(WEB_PATH).'user_portal.php';
1086
                
1087
        $this->tpl->assign('course_catalog_url', $course_catalog_url);
1088
        $this->tpl->assign('course_list_url', $course_list_url);
1089
        $this->tpl->assign('course_catalog_link', Display::url(get_lang('here'), $course_catalog_url));
1090
        $this->tpl->assign('course_list_link', Display::url(get_lang('here'), $course_list_url));
1091
        $this->tpl->assign('count_courses', $count_courses);
1092
  
1093
        return $this->tpl->fetch($tpl);
1094
    }
1095

    
1096
	function return_hot_courses() {
1097
		return CourseManager::return_hot_courses();		
1098
	}
1099
}
(3-3/5)