Project

General

Profile

Feature #3898 » userportal.lib.php

Yoselyn Castillo, 14/09/2012 00:28

 
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
        	
714
		//Always show the user image
715
		$img_array = UserManager::get_user_picture_path_by_id(api_get_user_id(), 'web', true, true);
716
		$no_image = false;
717
		if ($img_array['file'] == 'unknown.jpg') {
718
			$no_image = true;
719
		}
720
		$img_array = UserManager::get_picture_user(api_get_user_id(), $img_array['file'], 50, USER_IMAGE_SIZE_MEDIUM, ' width="90" height="90" ');
721
		
722
        if (api_get_setting('allow_social_tool') == 'true') {
723
            if (!$no_image) {
724
				$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>';
725
			} else {
726
				$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>';
727
			}
728
		}        
729
        $html = self::show_right_block(null, $profile_content, 'user_image_block', array('style' => 'text-align:center;'));
730
        return $html;
731
    }
732
	
733
	function return_profile_block() {
734
		$html = '';
735
		$user_id = api_get_user_id();
736
        
737
		if (empty($user_id)) {
738
			return; 
739
		}
740
	
741
		$profile_content .= '<ul class="nav nav-list">'; 
742
		
743
		//  @todo Add a platform setting to add the user image.
744
		if (api_get_setting('allow_message_tool') == 'true') {
745
			require_once api_get_path(LIBRARY_PATH).'group_portal_manager.lib.php';
746
		
747
			// New messages.
748
			$number_of_new_messages             = MessageManager::get_new_messages();
749
			// New contact invitations.
750
			$number_of_new_messages_of_friend   = SocialManager::get_message_number_invitation_by_user_id(api_get_user_id());
751
		
752
			// New group invitations sent by a moderator.
753
			$group_pending_invitations = GroupPortalManager::get_groups_by_user(api_get_user_id(), GROUP_USER_PERMISSION_PENDING_INVITATION, false);
754
			$group_pending_invitations = count($group_pending_invitations);
755
		
756
			$total_invitations = $number_of_new_messages_of_friend + $group_pending_invitations;
757
            $cant_msg = Display::badge($number_of_new_messages);			         
758
            
759
			$link = '';
760
			if (api_get_setting('allow_social_tool') == 'true') {
761
				$link = '?f=social';
762
			}
763
			$profile_content .= '<li><a href="'.api_get_path(WEB_PATH).'main/messages/inbox.php'.$link.'">'.get_lang('Inbox').$cant_msg.' </a></li>';
764
			$profile_content .= '<li><a href="'.api_get_path(WEB_PATH).'main/messages/new_message.php'.$link.'">'.get_lang('Compose').' </a></li>';            
765
		
766
			if (api_get_setting('allow_social_tool') == 'true') {                				
767
				$total_invitations = Display::badge($total_invitations);				                
768
				$profile_content .= '<li><a href="'.api_get_path(WEB_PATH).'main/social/invitations.php">'.get_lang('PendingInvitations').$total_invitations.'</a></li>';
769
			}
770
            $profile_content .= '<li><a href="'.api_get_path(WEB_PATH).'main/auth/profile.php">'.get_lang('EditProfile').'</a></li>';			
771
		}
772
        $profile_content .= '</ul>';
773
		$html = self::show_right_block(get_lang('Profile'), $profile_content, 'profile_block');
774
		return $html;
775
	}
776
	
777
	function return_navigation_links() {
778
		$html = '';
779
		
780
		// Deleting the myprofile link.
781
		if (api_get_setting('allow_social_tool') == 'true') {
782
			unset($this->tpl->menu_navigation['myprofile']);
783
		}
784
                
785
		// Main navigation section.
786
		// Tabs that are deactivated are added here.
787
		if (!empty($this->tpl->menu_navigation)) {            
788
			$content = '<ul class="nav nav-list">';
789
			foreach ($this->tpl->menu_navigation as $section => $navigation_info) {                
790
				$current = $section == $GLOBALS['this_section'] ? ' id="current"' : '';
791
				$content .= '<li'.$current.'>';
792
				$content .= '<a href="'.$navigation_info['url'].'" target="_self">'.$navigation_info['title'].'</a>';
793
				$content .= '</li>';
794
			}
795
			$content .= '</ul>';            
796
			$html = self::show_right_block(get_lang('MainNavigation'), $content, 'navigation_link_block');
797
		}        
798
		return $html;
799
	}
800
	
801
	function return_course_block() {
802
		$html = '';
803

    
804
		$show_create_link = false;
805
		$show_course_link = false;
806
				
807
		$display_add_course_link = api_is_allowed_to_create_course() && ($_SESSION['studentview'] != 'studentenview');
808
		if ($display_add_course_link) {
809
			$show_create_link = true;
810
		}
811
		
812
		if (api_is_platform_admin() || api_is_course_admin() || api_is_allowed_to_create_course()) {
813
			$show_course_link = true;
814
		} else {
815
			if (api_get_setting('allow_students_to_browse_courses') == 'true') {		
816
				$show_course_link = true;
817
			}
818
		}
819
		
820
		// My account section		
821
		$my_account_content = '<ul class="nav nav-list">';
822
        
823
		if ($show_create_link) {
824
			$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>';
825
		}
826
        
827
        //Sort courses
828
        $url = api_get_path(WEB_CODE_PATH).'auth/courses.php?action=sortmycourses';
829
        $my_account_content .= '<li>'.Display::url(get_lang('SortMyCourses'), $url, array('class' => 'sort course')).'</li>';
830

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

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

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

    
911
                        // Courses inside the current session.
912
                        $date_session_start = $session['date_start'];
913
                        $days_access_before_beginning  = $session['nb_days_access_before_beginning'] * 24 * 3600;
914

    
915
                        $session_now = time();
916
                        $html_courses_session = '';
917
                        $count_courses_session = 0;
918
                        
919
                        foreach ($session['courses'] as $course) {
920
                            $is_coach_course = api_is_coach($session_id, $course['code']);
921
                            $allowed_time = 0;
922
                            if ($date_session_start != '0000-00-00') {
923
                                if ($is_coach_course) {
924
                                    $allowed_time = api_strtotime($date_session_start) - $days_access_before_beginning;
925
                                } else {
926
                                    $allowed_time = api_strtotime($date_session_start);
927
                                }
928
                            }
929
                            if ($session_now > $allowed_time) {
930
                                //read only and accesible
931
                                if (api_get_setting('hide_courses_in_sessions') == 'false') {
932
                                    $c = CourseManager :: get_logged_user_course_html($course, $session_id, 'session_course_item', true, $this->load_directories_preview);									
933
                                    $html_courses_session .= $c[1];
934
                                }
935
                                $count_courses_session++;
936
                            }
937
                        }
938

    
939
                        if ($count_courses_session > 0) {
940
                            $params = array();          							
941

    
942
                            $session_box = Display :: get_session_title_box($session_id);
943

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

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

    
956
                            $params['title'] = $session_link;
957
                            $params['subtitle'] = $extra_info;                            
958

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

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

    
989
                        foreach ($session['courses'] as $course) {
990
                            $is_coach_course = api_is_coach($session_id, $course['code']);
991
                            
992
                            if ($is_coach_course) {
993
                                $allowed_time = api_strtotime($date_session_start) - $days_access_before_beginning;
994
                            } else {
995
                                $allowed_time = api_strtotime($date_session_start);
996
                            }
997
                            if ($session_now > $allowed_time) {
998
                                $c = CourseManager :: get_logged_user_course_html($course, $session_id, 'session_course_item');
999
                                $html_courses_session .= $c[1];
1000
                                $count_courses_session++;
1001
                                $count++;
1002
                            }
1003
                        }
1004
                        
1005
                        $params = array();
1006

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

    
1011
                            if (api_is_drh()) {
1012
                                $session_link = $session_box['title'];
1013
                                $params['link'] = null;
1014
                            } else {
1015
                                $session_link   = Display::tag('a', $session_box['title'], array('href'=>api_get_path(WEB_CODE_PATH).'session/index.php?session_id='.$session_id));
1016
                                $params['link'] =  api_get_path(WEB_CODE_PATH).'session/index.php?session_id='.$session_id;
1017
                            }
1018

    
1019
                            $params['title'] .=  $session_link;
1020

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

    
1023
                            if (api_is_platform_admin()) {
1024
                                $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>';
1025
                            }                                
1026
                            $html_sessions .= CourseManager::course_item_html($params, true).$html_courses_session;                         
1027
                        }
1028
                    }                    
1029
                    
1030
                    if ($count_courses_session > 0) {
1031
                        $params = array();				
1032
                        $params['icon'] = Display::return_icon('folder_blue.png', $session_category['session_category']['name'], array(), ICON_SIZE_LARGE);
1033

    
1034
                        if (api_is_platform_admin()) {
1035
                            $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>';
1036
                        }
1037

    
1038
                        $params['title'] .= $session_category['session_category']['name'];
1039

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

    
1088
	function return_hot_courses() {
1089
		return CourseManager::return_hot_courses();		
1090
	}
1091
}
(2-2/4)