user_portal.php 68 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * This is the index file displayed when a user is logged in on Dokeos.
  5. *
  6. * It displays:
  7. * - personal course list
  8. * - menu bar
  9. *
  10. * Part of the what's new ideas were based on a rene haentjens hack
  11. *
  12. * Search for
  13. * CONFIGURATION parameters
  14. * to modify settings
  15. *
  16. * @todo rewrite code to separate display, logic, database code
  17. * @package chamilo.main
  18. */
  19. /**
  20. * @todo shouldn't the SCRIPTVAL_ and CONFVAL_ constant be moved to the config page? Has anybody any idea what the are used for?
  21. * if these are really configuration settings then we can add those to the dokeos config settings
  22. * @todo move get_personal_course_list and some other functions to a more appripriate place course.lib.php or user.lib.php
  23. * @todo use api_get_path instead of $rootAdminWeb
  24. * @todo check for duplication of functions with index.php (user_portal.php is orginally a copy of index.php)
  25. * @todo display_digest, shouldn't this be removed and be made into an extension?
  26. */
  27. /* INIT SECTION */
  28. // Don't change these settings
  29. define('SCRIPTVAL_No', 0);
  30. define('SCRIPTVAL_InCourseList', 1);
  31. define('SCRIPTVAL_UnderCourseList', 2);
  32. define('SCRIPTVAL_Both', 3);
  33. define('SCRIPTVAL_NewEntriesOfTheDay', 4);
  34. define('SCRIPTVAL_NewEntriesOfTheDayOfLastLogin', 5);
  35. define('SCRIPTVAL_NoTimeLimit', 6);
  36. // End 'don't change' section
  37. // Language files that should be included
  38. $language_file = array ('courses', 'index');
  39. $cidReset = true; /* Flag forcing the 'current course' reset,
  40. as we're not inside a course anymore */
  41. /*
  42. Included libraries
  43. */
  44. require_once './main/inc/global.inc.php';
  45. $libpath = api_get_path(LIBRARY_PATH);
  46. require_once $libpath.'course.lib.php';
  47. require_once $libpath.'debug.lib.inc.php';
  48. require_once $libpath.'system_announcements.lib.php';
  49. require_once $libpath.'groupmanager.lib.php';
  50. require_once $libpath.'usermanager.lib.php';
  51. require_once 'main/survey/survey.lib.php';
  52. require_once $libpath.'sessionmanager.lib.php';
  53. api_block_anonymous_users(); // only users who are logged in can proceed
  54. $htmlHeadXtra[] = '<script src="'.api_get_path(WEB_LIBRARY_PATH).'javascript/jquery.js" type="text/javascript" language="javascript"></script>';
  55. $htmlHeadXtra[] = '<script src="'.api_get_path(WEB_LIBRARY_PATH).'javascript/jquery.toggle.js" type="text/javascript" language="javascript"></script>';
  56. /*
  57. Table definitions
  58. */
  59. //Database table definitions
  60. $main_user_table = Database :: get_main_table(TABLE_MAIN_USER);
  61. $main_admin_table = Database :: get_main_table(TABLE_MAIN_ADMIN);
  62. $main_course_table = Database :: get_main_table(TABLE_MAIN_COURSE);
  63. $main_course_user_table = Database :: get_main_table(TABLE_MAIN_COURSE_USER);
  64. $main_category_table = Database :: get_main_table(TABLE_MAIN_CATEGORY);
  65. /*
  66. Constants and CONFIGURATION parameters
  67. */
  68. // ---- Course list options ----
  69. define('CONFVAL_showCourseLangIfNotSameThatPlatform', true);
  70. // Preview of course content
  71. // to disable all: set CONFVAL_maxTotalByCourse = 0
  72. // to enable all: set e.g. CONFVAL_maxTotalByCourse = 5
  73. // by default disabled since what's new icons are better (see function display_digest() )
  74. define('CONFVAL_maxValvasByCourse', 2); // Maximum number of entries
  75. define('CONFVAL_maxAgendaByCourse', 2); // collected from each course
  76. define('CONFVAL_maxTotalByCourse', 0); // and displayed in summary.
  77. define('CONFVAL_NB_CHAR_FROM_CONTENT', 80);
  78. // Order to sort data
  79. $orderKey = array('keyTools', 'keyTime', 'keyCourse'); // default "best" Choice
  80. //$orderKey = array('keyTools', 'keyCourse', 'keyTime');
  81. //$orderKey = array('keyCourse', 'keyTime', 'keyTools');
  82. //$orderKey = array('keyCourse', 'keyTools', 'keyTime');
  83. define('CONFVAL_showExtractInfo', SCRIPTVAL_UnderCourseList);
  84. // SCRIPTVAL_InCourseList // best choice if $orderKey[0] == 'keyCourse'
  85. // SCRIPTVAL_UnderCourseList // best choice
  86. // SCRIPTVAL_Both // probably only for debug
  87. //define('CONFVAL_dateFormatForInfosFromCourses', get_lang('dateFormatShort'));
  88. define('CONFVAL_dateFormatForInfosFromCourses', get_lang('dateFormatLong'));
  89. //define("CONFVAL_limitPreviewTo",SCRIPTVAL_NewEntriesOfTheDay);
  90. //define("CONFVAL_limitPreviewTo",SCRIPTVAL_NoTimeLimit);
  91. define("CONFVAL_limitPreviewTo", SCRIPTVAL_NewEntriesOfTheDayOfLastLogin);
  92. // this is the main function to get the course list
  93. $personal_course_list = UserManager::get_personal_session_course_list($_user['user_id']);
  94. // check if a user is enrolled only in one course for going directly to the course after the login
  95. if (api_get_setting('go_to_course_after_login') == 'true') {
  96. if (!isset($_SESSION['coursesAlreadyVisited']) && is_array($personal_course_list) && count($personal_course_list) == 1) {
  97. $key = array_keys($personal_course_list);
  98. $course_info = $personal_course_list[$key[0]];
  99. $course_directory = $course_info['d'];
  100. $id_session = isset($course_info['id_session'])?$course_info['id_session']:0;
  101. header('location:'.api_get_path(WEB_COURSE_PATH).$course_directory.'/?id_session='.$id_session);
  102. exit;
  103. }
  104. }
  105. $nosession = false;
  106. if (api_get_setting('use_session_mode') == 'true' && !$nosession) {
  107. $display_actives = !isset($_GET['inactives']);
  108. }
  109. $nameTools = get_lang('MyCourses');
  110. $this_section = SECTION_COURSES;
  111. /*
  112. Check configuration parameters integrity
  113. */
  114. if (CONFVAL_showExtractInfo != SCRIPTVAL_UnderCourseList and $orderKey[0] != "keyCourse") {
  115. // CONFVAL_showExtractInfo must be SCRIPTVAL_UnderCourseList to accept $orderKey[0] !="keyCourse"
  116. if (DEBUG || api_is_platform_admin()){ // Show bug if admin. Else force a new order
  117. die('
  118. <strong>config error:'.__FILE__.'</strong><br />
  119. set
  120. <ul>
  121. <li>
  122. CONFVAL_showExtractInfo = SCRIPTVAL_UnderCourseList
  123. (actually : '.CONFVAL_showExtractInfo.')
  124. </li>
  125. </ul>
  126. or
  127. <ul>
  128. <li>
  129. $orderKey[0] != "keyCourse"
  130. (actually : '.$orderKey[0].')
  131. </li>
  132. </ul>');
  133. }else {
  134. $orderKey = array ('keyCourse', 'keyTools', 'keyTime');
  135. }
  136. }
  137. /*
  138. -----------------------------------------------------------
  139. Header
  140. include the HTTP, HTML headers plus the top banner
  141. -----------------------------------------------------------
  142. */
  143. Display :: display_header($nameTools);
  144. /*
  145. FUNCTIONS
  146. display_admin_links()
  147. display_create_course_link()
  148. display_edit_course_list_links()
  149. display_digest($toolsList, $digest, $orderKey, $courses)
  150. show_notification($my_course)
  151. get_personal_course_list($user_id)
  152. get_logged_user_course_html($my_course)
  153. get_user_course_categories()
  154. */
  155. /*
  156. Database functions
  157. some of these can go to database layer.
  158. */
  159. /**
  160. * Database function that gets the list of courses for a particular user.
  161. * @param $user_id, the id of the user
  162. * @return an array with courses
  163. */
  164. function get_personal_course_list($user_id) {
  165. // initialisation
  166. $personal_course_list = array();
  167. // table definitions
  168. $main_user_table = Database :: get_main_table(TABLE_MAIN_USER);
  169. $main_course_table = Database :: get_main_table(TABLE_MAIN_COURSE);
  170. $main_course_user_table = Database :: get_main_table(TABLE_MAIN_COURSE_USER);
  171. $tbl_session_course = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE);
  172. $tbl_session_course_user= Database :: get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
  173. $tbl_session = Database :: get_main_table(TABLE_MAIN_SESSION);
  174. $user_id = Database::escape_string($user_id);
  175. $personal_course_list = array ();
  176. //Courses in which we suscribed out of any session
  177. $personal_course_list_sql = "SELECT course.code k, course.directory d, course.visual_code c, course.db_name db, course.title i,
  178. course.tutor_name t, course.course_language l, course_rel_user.status s, course_rel_user.sort sort,
  179. course_rel_user.user_course_cat user_course_cat
  180. FROM ".$main_course_table." course,".$main_course_user_table." course_rel_user
  181. WHERE course.code = course_rel_user.course_code"."
  182. AND course_rel_user.user_id = '".$user_id."'
  183. AND course_rel_user.relation_type<>".COURSE_RELATION_TYPE_RRHH."
  184. ORDER BY course_rel_user.user_course_cat, course_rel_user.sort ASC,i";
  185. $course_list_sql_result = Database::query($personal_course_list_sql);
  186. while ($result_row = Database::fetch_array($course_list_sql_result)) {
  187. $personal_course_list[] = $result_row;
  188. }
  189. //$personal_course_list = array_merge($personal_course_list, $course_list_sql_result);
  190. $personal_course_list_sql = "SELECT DISTINCT course.code k, course.directory d, course.visual_code c, course.db_name db, course.title i, course.tutor_name t, course.course_language l, 5 as s
  191. FROM $main_course_table as course, $tbl_session_course_user as srcru
  192. WHERE srcru.course_code=course.code AND srcru.id_user='$user_id'";
  193. $course_list_sql_result = Database::query($personal_course_list_sql);
  194. while ($result_row = Database::fetch_array($course_list_sql_result)) {
  195. $personal_course_list[] = $result_row;
  196. }
  197. //$personal_course_list = array_merge($personal_course_list, $course_list_sql_result);
  198. $personal_course_list_sql = "SELECT DISTINCT course.code k, course.directory d, course.visual_code c, course.db_name db, course.title i, course.tutor_name t, course.course_language l, 2 as s
  199. FROM $main_course_table as course, $tbl_session_course as src, $tbl_session as session
  200. WHERE session.id_coach='$user_id' AND session.id=src.id_session AND src.course_code=course.code";
  201. $course_list_sql_result = Database::query($personal_course_list_sql);
  202. //$personal_course_list = array_merge($personal_course_list, $course_list_sql_result);
  203. while ($result_row = Database::fetch_array($course_list_sql_result)) {
  204. $personal_course_list[] = $result_row;
  205. }
  206. return $personal_course_list;
  207. }
  208. /**
  209. * display special courses
  210. * @param int User id
  211. * @return void
  212. */
  213. function display_special_courses ($user_id) {
  214. $user_id = intval($user_id);
  215. $user_info = api_get_user_info($user_id);
  216. $special_course_list = array();
  217. $tbl_course = Database::get_main_table(TABLE_MAIN_COURSE);
  218. $tbl_course_user = Database::get_main_table(TABLE_MAIN_COURSE_USER);
  219. $tbl_course_field = Database::get_main_table(TABLE_MAIN_COURSE_FIELD);
  220. $tbl_course_field_value = Database::get_main_table(TABLE_MAIN_COURSE_FIELD_VALUES);
  221. $tbl_user_course_category = Database::get_user_personal_table(TABLE_USER_COURSE_CATEGORY);
  222. // get course list auto-register
  223. $sql = "SELECT course_code FROM $tbl_course_field_value tcfv INNER JOIN $tbl_course_field tcf ON " .
  224. " tcfv.field_id = tcf.id WHERE tcf.field_variable = 'special_course' AND tcfv.field_value = 1 ";
  225. $special_course_result = Database::query($sql);
  226. if(Database::num_rows($special_course_result)>0) {
  227. $special_course_list = array();
  228. while ($result_row = Database::fetch_array($special_course_result)) {
  229. $special_course_list[] = '"'.$result_row['course_code'].'"';
  230. }
  231. }
  232. $with_special_courses = $without_special_courses = '';
  233. if (!empty($special_course_list)) {
  234. $with_special_courses = ' course.code IN ('.implode(',',$special_course_list).')';
  235. }
  236. if (!empty($with_special_courses)) {
  237. $sql = "SELECT course.code, course.visual_code, course.subscribe subscr, course.unsubscribe unsubscr,
  238. course.title title, course.tutor_name tutor, course.db_name, course.directory, course_rel_user.status status,
  239. course_rel_user.sort sort, course_rel_user.user_course_cat user_course_cat, course_rel_user.user_id, course.visibility
  240. FROM $TABLECOURS course
  241. LEFT JOIN $TABLECOURSUSER course_rel_user ON course.code = course_rel_user.course_code AND course_rel_user.user_id = '$user_id'
  242. WHERE $with_special_courses";
  243. $rs_special_course = api_sql_query($sql);
  244. $number_of_courses = Database::num_rows($rs_special_course);
  245. $key = 0;
  246. $status_icon = '';
  247. if ($number_of_courses > 0) {
  248. echo "<table width=\"100%\">";
  249. while ($course = Database::fetch_array($rs_special_course)) {
  250. // get notifications
  251. $my_course = array();
  252. $my_course['db'] = $course['db_name'];
  253. $my_course['k'] = $course['code'];
  254. $my_course['id_session'] = null;
  255. $my_course['s'] = $course['status'];
  256. $show_notification = show_notification($my_course);
  257. if (empty($course['user_id'])) {
  258. $course['status'] = $user_info['status'];
  259. }
  260. if ($course['status'] == 1) {
  261. $status_icon=Display::return_icon('course.gif', get_lang('Course')).' '.Display::return_icon('teachers.gif', get_lang('Status').': '.get_lang('Teacher'),array('style'=>'width:11px; height:11px;'));
  262. }
  263. if (($course['status'] == 5 && !api_is_coach()) || empty($course['status'])) {
  264. $status_icon=Display::return_icon('course.gif', get_lang('Course')).' '.Display::return_icon('students.gif', get_lang('Status').': '.get_lang('Student'),array('style'=>'width:11px; height:11px'));
  265. }
  266. if (api_is_allowed_to_edit(null, true)) {
  267. $progress_thematic_icon = '<a href="'.api_get_path(WEB_CODE_PATH).'course_description/index.php?action=edit&cidReq='.$course['code'].'&description_type=8'.'">'.get_thematic_progress_icon($course['db_name']).'</a>';
  268. } else {
  269. $progress_thematic_icon = get_thematic_progress_icon($course['db_name']);
  270. }
  271. echo "\t<tr>\n";
  272. echo "\t\t<td>\n";
  273. //show a hyperlink to the course, unless the course is closed and user is not course admin
  274. //$course_access_settings = CourseManager :: get_access_settings($course['code']);
  275. $course_visibility = $course['visibility'];
  276. if ($course_visibility != COURSE_VISIBILITY_CLOSED || $course['status'] == COURSEMANAGER) {
  277. $course_title = '<a href="'.api_get_path(WEB_COURSE_PATH).$course['directory'].'/?id_session=0&amp;autoreg=1">'.$course['title'].'</a>';
  278. } else {
  279. $course_title = $course['title']." ".get_lang('CourseClosed');
  280. }
  281. echo "<div style=\"float:left;margin-right:10px;\">".$status_icon."</div><span style=\"font-size:135%;\">".$course_title."</span>&nbsp;&nbsp;<span>$progress_thematic_icon</span><br />";
  282. if (api_get_setting('display_coursecode_in_courselist') == 'true') {
  283. echo $course['visual_code'];
  284. }
  285. if (api_get_setting('display_coursecode_in_courselist') == 'true' && api_get_setting('display_teacher_in_courselist') == 'true') {
  286. echo " - ";
  287. }
  288. if (api_get_setting('display_teacher_in_courselist') == 'true') {
  289. echo $course['tutor'];
  290. }
  291. echo '&nbsp;';
  292. echo Display::return_icon('klipper.png', get_lang('CourseAutoRegister'));
  293. // show notifications
  294. echo $show_notification;
  295. echo "\t\t</td>\n";
  296. echo "\t</tr>\n";
  297. $key++;
  298. }
  299. echo "</table>";
  300. }
  301. }
  302. }
  303. /**
  304. * display courses without special courses
  305. * @param int User id
  306. * @return void
  307. */
  308. function display_courses($user_id) {
  309. global $_user, $_configuration;
  310. echo "<table width=\"100%\">\n";
  311. // building an array that contains all the id's of the user defined course categories
  312. // initially this was inside the display_courses_in_category function but when we do it here we have fewer
  313. // sql executions = performance increase.
  314. $all_user_categories = get_user_course_categories();
  315. // step 0: we display the course without a user category
  316. display_courses_in_category(0, 'true');
  317. // Step 1: We get all the categories of the user.
  318. $tucc = Database::get_user_personal_table(TABLE_USER_COURSE_CATEGORY);
  319. $sql = "SELECT * FROM $tucc WHERE user_id='".$_user['user_id']."' ORDER BY sort ASC";
  320. $result = Database::query($sql);
  321. while ($row = Database::fetch_array($result)) {
  322. // We simply display the title of the category.
  323. echo "<tr><td colspan=\"2\" class=\"user_course_category\">";
  324. echo '<a name="category'.$row['id'].'"></a>'; // display an internal anchor.
  325. echo $row['title'];
  326. echo "</td>";
  327. echo "</tr>";
  328. display_courses_in_category($row['id']);
  329. }
  330. echo "</table>\n";
  331. }
  332. /**
  333. * display courses in category without special courses
  334. * @param int User category id
  335. * @return void
  336. */
  337. function display_courses_in_category($user_category_id) {
  338. global $_user;
  339. // table definitions
  340. $TABLECOURS = Database::get_main_table(TABLE_MAIN_COURSE);
  341. $TABLECOURSUSER = Database::get_main_table(TABLE_MAIN_COURSE_USER);
  342. $TABLE_USER_COURSE_CATEGORY = Database::get_user_personal_table(TABLE_USER_COURSE_CATEGORY);
  343. $TABLE_COURSE_FIELD = Database :: get_main_table(TABLE_MAIN_COURSE_FIELD);
  344. $TABLE_COURSE_FIELD_VALUE = Database :: get_main_table(TABLE_MAIN_COURSE_FIELD_VALUES);
  345. // get course list auto-register
  346. $sql = "SELECT course_code FROM $TABLE_COURSE_FIELD_VALUE tcfv INNER JOIN $TABLE_COURSE_FIELD tcf ON " .
  347. " tcfv.field_id = tcf.id WHERE tcf.field_variable = 'special_course' AND tcfv.field_value = 1 ";
  348. $special_course_result = Database::query($sql);
  349. if(Database::num_rows($special_course_result)>0) {
  350. $special_course_list = array();
  351. while ($result_row = Database::fetch_array($special_course_result)) {
  352. $special_course_list[] = '"'.$result_row['course_code'].'"';
  353. }
  354. }
  355. $without_special_courses = '';
  356. if (!empty($special_course_list)) {
  357. $without_special_courses = ' AND course.code NOT IN ('.implode(',',$special_course_list).')';
  358. }
  359. $sql_select_courses = "SELECT course.code, course.visual_code, course.subscribe subscr, course.unsubscribe unsubscr,
  360. course.title title, course.tutor_name tutor, course.db_name, course.directory, course_rel_user.status status,
  361. course_rel_user.sort sort, course_rel_user.user_course_cat user_course_cat, course.visibility
  362. FROM $TABLECOURS course,
  363. $TABLECOURSUSER course_rel_user
  364. WHERE course.code = course_rel_user.course_code
  365. AND course_rel_user.user_id = '".$_user['user_id']."'
  366. AND course_rel_user.relation_type<>".COURSE_RELATION_TYPE_RRHH."
  367. AND course_rel_user.user_course_cat='".$user_category_id."' $without_special_courses
  368. ORDER BY course_rel_user.user_course_cat, course_rel_user.sort ASC";
  369. $result = Database::query($sql_select_courses);
  370. $number_of_courses = Database::num_rows($result);
  371. $key = 0;
  372. $status_icon = '';
  373. while ($course = Database::fetch_array($result)) {
  374. // get notifications
  375. $my_course = array();
  376. $my_course['db'] = $course['db_name'];
  377. $my_course['k'] = $course['code'];
  378. $my_course['id_session'] = null;
  379. $my_course['s'] = $course['status'];
  380. $show_notification = show_notification($my_course);
  381. // course list
  382. if ($course['status'] == COURSEMANAGER) {
  383. $status_icon=Display::return_icon('course.gif', get_lang('Course')).' '.Display::return_icon('teachers.gif', get_lang('Status').': '.get_lang('Teacher'),array('style'=>'width:11px; height:11px;'));
  384. }
  385. if (($course['status'] == STUDENT && !api_is_coach()) || empty($course['status'])) {
  386. $status_icon=Display::return_icon('course.gif', get_lang('Course')).' '.Display::return_icon('students.gif', get_lang('Status').': '.get_lang('Student'),array('style'=>'width:11px; height:11px'));
  387. }
  388. if (api_is_allowed_to_edit(null,true)) {
  389. $progress_thematic_icon = '<a href="'.api_get_path(WEB_CODE_PATH).'course_description/index.php?action=edit&cidReq='.$course['code'].'&description_type=8'.'">'.get_thematic_progress_icon($course['db_name']).'</a>';
  390. } else {
  391. $progress_thematic_icon = get_thematic_progress_icon($course['db_name']);
  392. }
  393. echo "\t<tr>\n";
  394. echo "\t\t<td>\n";
  395. //function logic - act on the data
  396. $is_virtual_course = CourseManager :: is_virtual_course_from_system_code($course['code']);
  397. if ($is_virtual_course) {
  398. // If the current user is also subscribed in the real course to which this
  399. // virtual course is linked, we don't need to display the virtual course entry in
  400. // the course list - it is combined with the real course entry.
  401. $target_course_code = CourseManager :: get_target_of_linked_course($course['code']);
  402. $is_subscribed_in_target_course = CourseManager :: is_user_subscribed_in_course(api_get_user_id(), $target_course_code);
  403. if ($is_subscribed_in_target_course) {
  404. return; //do not display this course entry
  405. }
  406. }
  407. $has_virtual_courses = CourseManager :: has_virtual_courses_from_code($course['code'], api_get_user_id());
  408. if ($has_virtual_courses) {
  409. $course_info = api_get_course_info($course['code']);
  410. $return_result = CourseManager :: determine_course_title_from_course_info(api_get_user_id(), $course_info);
  411. $course_title = $return_result['title'];
  412. $course_display_code = $return_result['code'];
  413. } else {
  414. $course_title = $course['title'];
  415. $course_display_code = $course['visual_code'];
  416. }
  417. //show a hyperlink to the course, unless the course is closed and user is not course admin
  418. $course_visibility = $course['visibility'];
  419. if ($course_visibility != COURSE_VISIBILITY_CLOSED || $course['status'] == COURSEMANAGER) {
  420. $course_title = '<a href="'.api_get_path(WEB_COURSE_PATH).$course['directory'].'/?id_session=0">'.$course['title'].'</a>';
  421. } else {
  422. $course_title = $course['title']." ".get_lang('CourseClosed');
  423. }
  424. echo "<div style=\"float:left;margin-right:10px;\">".$status_icon."</div><span style=\"font-size:135%;\">".$course_title."</span>&nbsp;&nbsp;<span>$progress_thematic_icon </span><br />";
  425. if (api_get_setting('display_coursecode_in_courselist') == 'true') {
  426. echo $course_display_code;
  427. }
  428. if (api_get_setting('display_coursecode_in_courselist') == 'true' && api_get_setting('display_teacher_in_courselist') == 'true') {
  429. echo " - ";
  430. }
  431. if (api_get_setting('display_teacher_in_courselist') == 'true') {
  432. echo $course['tutor'];
  433. }
  434. // show notifications
  435. echo $show_notification;
  436. echo "\t\t</td>\n";
  437. echo "\t</tr>\n";
  438. $key++;
  439. }
  440. }
  441. /*
  442. Display functions
  443. */
  444. /**
  445. * get icon showing thematic progress for a course
  446. * @param string Course database name
  447. * @param int Session id (optional)
  448. * @return string img html
  449. */
  450. function get_thematic_progress_icon($course_dbname,$session_id = 0) {
  451. $tbl_course_description = Database::get_course_table(TABLE_COURSE_DESCRIPTION,$course_dbname);
  452. $session_id = intval($session_id);
  453. $sql = "SELECT progress FROM $tbl_course_description WHERE description_type = 8 AND session_id = '$session_id' ";
  454. $rs = Database::query($sql);
  455. $img = '';
  456. $title = '0%';
  457. $image = 'level_0.png';
  458. if (Database::num_rows($rs) > 0) {
  459. $row = Database::fetch_array($rs);
  460. $progress = $row['progress'];
  461. $image = 'level_'.$progress.'.png';
  462. $title = $row['progress'].'%';
  463. $img = Display::return_icon($image,get_lang('ThematicAdvance'),array('style'=>'vertical-align:middle')).'&nbsp;<span>'.$title.'</span>';
  464. }
  465. return $img;
  466. }
  467. /**
  468. * Warning: this function defines a global.
  469. * @todo use the correct get_path function
  470. */
  471. function display_admin_links() {
  472. global $rootAdminWeb;
  473. echo "<li><a href=\"".$rootAdminWeb."\">".get_lang('PlatformAdmin')."</a></li>";
  474. }
  475. /**
  476. * Display create course link
  477. *
  478. */
  479. function display_create_course_link() {
  480. echo "<li><a href=\"main/create_course/add_course.php\">".get_lang('CourseCreate')."</a></li>";
  481. }
  482. /**
  483. * Display dashboard link
  484. *
  485. */
  486. function display_dashboard_link() {
  487. echo "<li><a href=\"main/dashboard/index.php\">".get_lang('Dashboard')."</a></li>";
  488. }
  489. /**
  490. * Display edit course list links
  491. *
  492. */
  493. function display_edit_course_list_links() {
  494. echo "<li><a href=\"main/auth/courses.php\">".get_lang('CourseManagement')."</a></li>";
  495. }
  496. /**
  497. * Show history sessions
  498. *
  499. */
  500. function display_history_course_session() {
  501. if (api_get_setting('use_session_mode')=='true') {
  502. if (isset($_GET['history']) && intval($_GET['history']) == 1) {
  503. echo "<li><a href=\"user_portal.php\">".get_lang('DisplayTrainingList')."</a></li>";
  504. } else {
  505. echo "<li><a href=\"user_portal.php?history=1\">".get_lang('HistoryTrainingSessions')."</a></li>";
  506. }
  507. }
  508. }
  509. /**
  510. * Displays a digest e.g. short summary of new agenda and announcements items.
  511. * This used to be displayed in the right hand menu, but is now
  512. * disabled by default (see config settings in this file) because most people like
  513. * the what's new icons better.
  514. *
  515. * @version 1.0
  516. */
  517. function display_digest($toolsList, $digest, $orderKey, $courses) {
  518. if (is_array($digest) && (CONFVAL_showExtractInfo == SCRIPTVAL_UnderCourseList || CONFVAL_showExtractInfo == SCRIPTVAL_Both)) {
  519. // // // LEVEL 1 // // //
  520. reset($digest);
  521. echo "<br /><br />\n";
  522. while (list($key1) = each($digest)) {
  523. if (is_array($digest[$key1])) {
  524. // // // Title of LEVEL 1 // // //
  525. echo "<strong>\n";
  526. if ($orderKey[0] == 'keyTools') {
  527. $tools = $key1;
  528. echo $toolsList[$key1]['name'];
  529. } elseif ($orderKey[0] == 'keyCourse') {
  530. $courseSysCode = $key1;
  531. echo "<a href=\"", api_get_path(WEB_COURSE_PATH), $courses[$key1]['coursePath'], "\">", $courses[$key1]['courseCode'], "</a>\n";
  532. } elseif ($orderKey[0] == 'keyTime') {
  533. echo api_convert_and_format_date($digest[$key1], DATE_FORMAT_LONG, date_default_timezone_get());
  534. }
  535. echo "</strong>\n";
  536. // // // End Of Title of LEVEL 1 // // //
  537. // // // LEVEL 2 // // //
  538. reset($digest[$key1]);
  539. while (list ($key2) = each($digest[$key1])) {
  540. // // // Title of LEVEL 2 // // //
  541. echo "<p>\n", "\n";
  542. if ($orderKey[1] == 'keyTools') {
  543. $tools = $key2;
  544. echo $toolsList[$key2][name];
  545. } elseif ($orderKey[1] == 'keyCourse') {
  546. $courseSysCode = $key2;
  547. echo "<a href=\"", api_get_path(WEB_COURSE_PATH), $courses[$key2]['coursePath'], "\">", $courses[$key2]['courseCode'], "</a>\n";
  548. } elseif ($orderKey[1] == 'keyTime') {
  549. echo api_convert_and_format_date($key2, DATE_FORMAT_LONG, date_default_timezone_get());
  550. }
  551. echo "\n";
  552. echo "</p>";
  553. // // // End Of Title of LEVEL 2 // // //
  554. // // // LEVEL 3 // // //
  555. reset($digest[$key1][$key2]);
  556. while (list ($key3, $dataFromCourse) = each($digest[$key1][$key2])) {
  557. // // // Title of LEVEL 3 // // //
  558. if ($orderKey[2] == 'keyTools') {
  559. $level3title = "<a href=\"".$toolsList[$key3]["path"].$courseSysCode."\">".$toolsList[$key3]['name']."</a>";
  560. } elseif ($orderKey[2] == 'keyCourse') {
  561. $level3title = "&#8226; <a href=\"".$toolsList[$tools]["path"].$key3."\">".$courses[$key3]['courseCode']."</a>\n";
  562. } elseif ($orderKey[2] == 'keyTime') {
  563. $level3title = "&#8226; <a href=\"".$toolsList[$tools]["path"].$courseSysCode."\">".api_convert_and_format_date($key3, DATE_FORMAT_LONG, date_default_timezone_get())."</a>";
  564. }
  565. // // // End Of Title of LEVEL 3 // // //
  566. // // // LEVEL 4 (data) // // //
  567. reset($digest[$key1][$key2][$key3]);
  568. while (list ($key4, $dataFromCourse) = each($digest[$key1][$key2][$key3])) {
  569. echo $level3title, ' &ndash; ', api_substr(strip_tags($dataFromCourse), 0, CONFVAL_NB_CHAR_FROM_CONTENT);
  570. //adding ... (three dots) if the texts are too large and they are shortened
  571. if (api_strlen($dataFromCourse) >= CONFVAL_NB_CHAR_FROM_CONTENT) {
  572. echo '...';
  573. }
  574. }
  575. echo "<br />\n";
  576. }
  577. }
  578. }
  579. }
  580. }
  581. } // end function display_digest
  582. /**
  583. * Display code for one specific course a logged in user is subscribed to.
  584. * Shows a link to the course, what's new icons...
  585. *
  586. * $my_course['d'] - course directory
  587. * $my_course['i'] - course title
  588. * $my_course['c'] - visual course code
  589. * $my_course['k'] - system course code
  590. * $my_course['db'] - course database
  591. *
  592. * @version 1.0.3
  593. * @todo refactor into different functions for database calls | logic | display
  594. * @todo replace single-character $my_course['d'] indices
  595. * @todo move code for what's new icons to a separate function to clear things up
  596. * @todo add a parameter user_id so that it is possible to show the courselist of other users (=generalisation). This will prevent having to write a new function for this.
  597. */
  598. function get_logged_user_course_html($course, $session_id = 0, $class='courses') {
  599. global $charset;
  600. global $nosession;
  601. $current_uid = api_get_user_id();
  602. $info = api_get_course_info($course['code']);
  603. $status_course = CourseManager::get_user_in_course_status($current_uid, $course['code']);
  604. if (!is_array($course['code'])) {
  605. $my_course = api_get_course_info($course['code']);
  606. $my_course['k'] = $my_course['id'];
  607. $my_course['db'] = $my_course['dbName'];
  608. $my_course['c'] = $my_course['official_code'];
  609. $my_course['i'] = $my_course['name'];
  610. $my_course['d'] = $my_course['path'];
  611. $my_course['t'] = $my_course['titular'];
  612. $my_course['id_session'] = $session_id;
  613. $my_course['status'] = ((empty($session_id))?$status_course:5);
  614. }
  615. if (api_get_setting('use_session_mode')=='true' && !$nosession) {
  616. global $now, $date_start, $date_end;
  617. }
  618. //initialise
  619. $result = '';
  620. // Table definitions
  621. //$statistic_database = Database::get_statistic_database();
  622. $main_user_table = Database :: get_main_table(TABLE_MAIN_USER);
  623. $tbl_session = Database :: get_main_table(TABLE_MAIN_SESSION);
  624. $tbl_session_category = Database :: get_main_table(TABLE_MAIN_SESSION_CATEGORY);
  625. $course_database = $my_course['db'];
  626. $course_tool_table = Database :: get_course_table(TABLE_TOOL_LIST, $course_database);
  627. $tool_edit_table = Database :: get_course_table(TABLE_ITEM_PROPERTY, $course_database);
  628. $course_group_user_table = Database :: get_course_table(TOOL_USER, $course_database);
  629. $user_id = api_get_user_id();
  630. $course_system_code = $my_course['k'];
  631. $course_visual_code = $my_course['c'];
  632. $course_title = $my_course['i'];
  633. $course_directory = $my_course['d'];
  634. $course_teacher = $my_course['t'];
  635. $course_teacher_email = isset($my_course['email'])?$my_course['email']:'';
  636. $course_info = Database :: get_course_info($course_system_code);
  637. $course_access_settings = CourseManager :: get_access_settings($course_system_code);
  638. $course_id = isset($course_info['course_id'])?$course_info['course_id']:null;
  639. $course_visibility = $course_access_settings['visibility'];
  640. $user_in_course_status = CourseManager :: get_user_in_course_status(api_get_user_id(), $course_system_code);
  641. //function logic - act on the data
  642. $is_virtual_course = CourseManager :: is_virtual_course_from_system_code($my_course['k']);
  643. if ($is_virtual_course) {
  644. // If the current user is also subscribed in the real course to which this
  645. // virtual course is linked, we don't need to display the virtual course entry in
  646. // the course list - it is combined with the real course entry.
  647. $target_course_code = CourseManager :: get_target_of_linked_course($course_system_code);
  648. $is_subscribed_in_target_course = CourseManager :: is_user_subscribed_in_course(api_get_user_id(), $target_course_code);
  649. if ($is_subscribed_in_target_course) {
  650. return; //do not display this course entry
  651. }
  652. }
  653. $has_virtual_courses = CourseManager :: has_virtual_courses_from_code($course_system_code, api_get_user_id());
  654. if ($has_virtual_courses) {
  655. $return_result = CourseManager :: determine_course_title_from_course_info(api_get_user_id(), $course_info);
  656. $course_display_title = $return_result['title'];
  657. $course_display_code = $return_result['code'];
  658. } else {
  659. $course_display_title = $course_title;
  660. $course_display_code = $course_visual_code;
  661. }
  662. $s_course_status = $my_course['status'];
  663. $is_coach = api_is_coach($my_course['id_session'],$course['code']);
  664. $s_htlm_status_icon = "";
  665. if ($s_course_status == 1) {
  666. $s_htlm_status_icon=Display::return_icon('course.gif', get_lang('Course')).' '.Display::return_icon('teachers.gif', get_lang('Status').': '.get_lang('Teacher'),array('style'=>'width:11px; height:11px'));
  667. }
  668. if ($s_course_status == 2 || ($is_coach && $s_course_status != 1)) {
  669. $s_htlm_status_icon=Display::return_icon('course.gif', get_lang('Course')).' '.Display::return_icon('coachs.gif', get_lang('Status').': '.get_lang('GeneralCoach'),array('style'=>'width:11px; height:11px'));
  670. }
  671. if (($s_course_status == 5 && !$is_coach) || empty($s_course_status)) {
  672. $s_htlm_status_icon=Display::return_icon('course.gif', get_lang('Course')).' '.Display::return_icon('students.gif', get_lang('Status').': '.get_lang('Student'),array('style'=>'width:11px; height:11px'));
  673. }
  674. //display course entry
  675. $result.="\n\t";
  676. $result .= '<li class="'.$class.'"><div class="coursestatusicons">'.$s_htlm_status_icon.'</div>';
  677. //show a hyperlink to the course, unless the course is closed and user is not course admin
  678. if ($course_visibility != COURSE_VISIBILITY_CLOSED || $user_in_course_status == COURSEMANAGER) {
  679. if(api_get_setting('use_session_mode')=='true' && !$nosession) {
  680. if(empty($my_course['id_session'])) {
  681. $my_course['id_session'] = 0;
  682. }
  683. if($user_in_course_status == COURSEMANAGER || ($date_start <= $now && $date_end >= $now) || $date_start=='0000-00-00') {
  684. $result .= '<a href="'.api_get_path(WEB_COURSE_PATH).$course_directory.'/?id_session='.$my_course['id_session'].'">'.$course_display_title.'</a>';
  685. }
  686. } else {
  687. $result .= '<a href="'.api_get_path(WEB_COURSE_PATH).$course_directory.'/">'.$course_display_title.'</a>';
  688. }
  689. } else {
  690. $result .= $course_display_title." "." ".get_lang('CourseClosed')."";
  691. }
  692. if (api_is_allowed_to_edit(null, true)) {
  693. $progress_thematic_icon = '<a href="'.api_get_path(WEB_CODE_PATH).'course_description/index.php?action=edit&cidReq='.$course['code'].'&description_type=8'.'">'.get_thematic_progress_icon($course_database, $session_id).'</a>';
  694. } else {
  695. $progress_thematic_icon = get_thematic_progress_icon($course_database, $session_id);
  696. }
  697. $result .= '&nbsp;&nbsp;<span>'.$progress_thematic_icon.'</span>';
  698. // show the course_code and teacher if chosen to display this
  699. if (api_get_setting('display_coursecode_in_courselist') == 'true' || api_get_setting('display_teacher_in_courselist') == 'true') {
  700. $result .= '<br />';
  701. }
  702. if (api_get_setting('display_coursecode_in_courselist') == 'true') {
  703. $result .= $course_display_code;
  704. }
  705. if (api_get_setting('display_teacher_in_courselist') == 'true') {
  706. if (api_get_setting('use_session_mode')=='true' && !$nosession) {
  707. $coachs_course = api_get_coachs_from_course($my_course['id_session'],$course['code']);
  708. $course_coachs = array();
  709. if (is_array($coachs_course)) {
  710. foreach ($coachs_course as $coach_course) {
  711. $course_coachs[] = api_get_person_name($coach_course['firstname'], $coach_course['lastname']);
  712. }
  713. }
  714. if ($s_course_status == 1 || ($s_course_status == 5 && empty($my_course['id_session'])) || empty($s_course_status)) {
  715. $result .= $course_teacher;
  716. }
  717. if (($s_course_status == 5 && !empty($my_course['id_session'])) || ($is_coach && $s_course_status != 1)) {
  718. if (is_array($course_coachs) && count($course_coachs)> 0 ) {
  719. if (api_get_setting('display_coursecode_in_courselist') == 'true' && api_get_setting('display_teacher_in_courselist') == 'true') {
  720. $result .= ' &ndash; ';
  721. }
  722. $result .= get_lang('Coachs').': '.implode(', ',$course_coachs);
  723. }
  724. }
  725. } else {
  726. $result .= $course_teacher;
  727. }
  728. if(!empty($course_teacher_email)) {
  729. $result .= ' ('.$course_teacher_email.')';
  730. }
  731. }
  732. $result .= (isset($course['special_course']))? ' '.Display::return_icon('klipper.png', get_lang('CourseAutoRegister')) : '';
  733. $current_course_settings = CourseManager :: get_access_settings($my_course['k']);
  734. // display the what's new icons
  735. $result .= show_notification($my_course);
  736. if ((CONFVAL_showExtractInfo == SCRIPTVAL_InCourseList || CONFVAL_showExtractInfo == SCRIPTVAL_Both) && $nbDigestEntries > 0) {
  737. reset($digest);
  738. $result .= '
  739. <ul>';
  740. while (list ($key2) = each($digest[$thisCourseSysCode])) {
  741. $result .= '<li>';
  742. if ($orderKey[1] == 'keyTools') {
  743. $result .= "<a href=\"$toolsList[$key2] [\"path\"] $thisCourseSysCode \">";
  744. $result .= "$toolsList[$key2][\"name\"]</a>";
  745. } else {
  746. $result .= api_convert_and_format_date($key2, DATE_FORMAT_LONG, date_default_timezone_get());
  747. }
  748. $result .= '</li>';
  749. $result .= '<ul>';
  750. reset ($digest[$thisCourseSysCode][$key2]);
  751. while (list ($key3, $dataFromCourse) = each($digest[$thisCourseSysCode][$key2])) {
  752. $result .= '<li>';
  753. if ($orderKey[2] == 'keyTools') {
  754. $result .= "<a href=\"$toolsList[$key3] [\"path\"] $thisCourseSysCode \">";
  755. $result .= "$toolsList[$key3][\"name\"]</a>";
  756. } else {
  757. $result .= api_convert_and_format_date($key3, DATE_FORMAT_LONG, date_default_timezone_get());
  758. }
  759. $result .= '<ul compact="compact">';
  760. reset($digest[$thisCourseSysCode][$key2][$key3]);
  761. while (list ($key4, $dataFromCourse) = each($digest[$thisCourseSysCode][$key2][$key3])) {
  762. $result .= '<li>';
  763. $result .= htmlspecialchars(api_substr(strip_tags($dataFromCourse), 0, CONFVAL_NB_CHAR_FROM_CONTENT), ENT_QUOTES, $charset);
  764. $result .= '</li>';
  765. }
  766. $result .= '</ul>';
  767. $result .= '</li>';
  768. }
  769. $result .= '</ul>';
  770. $result .= '</li>';
  771. }
  772. $result .= '</ul>';
  773. }
  774. $result .= '</li>';
  775. if (api_get_setting('use_session_mode') == 'true' && !$nosession) {
  776. $session = '';
  777. $active = false;
  778. if (!empty($my_course['session_name'])) {
  779. // Request for the name of the general coach
  780. $sql = 'SELECT lastname, firstname,sc.name
  781. FROM '.$tbl_session.' ts
  782. LEFT JOIN '.$main_user_table .' tu
  783. ON ts.id_coach = tu.user_id
  784. INNER JOIN '.$tbl_session_category.' sc ON ts.session_category_id = sc.id
  785. WHERE ts.id='.(int) $my_course['id_session']. ' LIMIT 1';
  786. $rs = Database::query($sql);
  787. $sessioncoach = Database::store_result($rs);
  788. $sessioncoach = $sessioncoach[0];
  789. $session = array();
  790. $session['title'] = $my_course['session_name'];
  791. $session_category_id = CourseManager::get_session_category_id_by_session_id($my_course['id_session']);
  792. $session['category'] = $sessioncoach['name'];
  793. if ( $my_course['date_start']=='0000-00-00' ) {
  794. $session['dates'] = get_lang('WithoutTimeLimits');
  795. if (api_get_setting('show_session_coach') === 'true') {
  796. $session['coach'] = get_lang('GeneralCoach').': '.api_get_person_name($sessioncoach['firstname'], $sessioncoach['lastname']);
  797. }
  798. $active = true;
  799. } else {
  800. $session ['dates'] = ' - '.get_lang('From').' '.$my_course['date_start'].' '.get_lang('To').' '.$my_course['date_end'];
  801. if (api_get_setting('show_session_coach') === 'true') {
  802. $session['coach'] = get_lang('GeneralCoach').': '.api_get_person_name($sessioncoach['firstname'], $sessioncoach['lastname']);
  803. }
  804. $active = ($date_start <= $now && $date_end >= $now)?true:false;
  805. }
  806. }
  807. $output = array ($my_course['user_course_cat'], $result, $my_course['id_session'], $session, 'active'=>$active,'session_category_id'=>$session_category_id);
  808. } else {
  809. $output = array ($my_course['user_course_cat'], $result);
  810. }
  811. return $output;
  812. }
  813. /**
  814. * Get the session box details as an array
  815. * @param int Session ID
  816. * @return array Empty array or session array ['title'=>'...','category'=>'','dates'=>'...','coach'=>'...','active'=>true/false,'session_category_id'=>int]
  817. */
  818. function get_session_title_box($session_id) {
  819. global $nosession;
  820. if (api_get_setting('use_session_mode')=='true' && !$nosession) {
  821. global $now, $date_start, $date_end;
  822. }
  823. $output = array();
  824. if (api_get_setting('use_session_mode')=='true' && !$nosession) {
  825. $main_user_table = Database :: get_main_table(TABLE_MAIN_USER);
  826. $tbl_session = Database :: get_main_table(TABLE_MAIN_SESSION);
  827. $tbl_session_category = Database :: get_main_table(TABLE_MAIN_SESSION_CATEGORY);
  828. $active = false;
  829. // Request for the name of the general coach
  830. $sql ='SELECT tu.lastname, tu.firstname, ts.name, ts.date_start, ts.date_end, ts.session_category_id
  831. FROM '.$tbl_session.' ts
  832. LEFT JOIN '.$main_user_table .' tu
  833. ON ts.id_coach = tu.user_id
  834. WHERE ts.id='.intval($session_id);
  835. $rs = Database::query($sql);
  836. $session_info = Database::store_result($rs);
  837. $session_info = $session_info[0];
  838. $session = array();
  839. $session['title'] = $session_info[2];
  840. $session['coach'] = '';
  841. if ( $session_info[3]=='0000-00-00' ) {
  842. $session['dates'] = get_lang('WithoutTimeLimits');
  843. if ( api_get_setting('show_session_coach') === 'true' ) {
  844. $session['coach'] = get_lang('GeneralCoach').': '.api_get_person_name($session_info[1], $session_info[0]);
  845. }
  846. $active = true;
  847. } else {
  848. $session ['dates'] = get_lang('From').' '.$session_info[3].' '.get_lang('Until').' '.$session_info[4];
  849. if ( api_get_setting('show_session_coach') === 'true' ) {
  850. $session['coach'] = get_lang('GeneralCoach').': '.api_get_person_name($session_info[1], $session_info[0]);
  851. }
  852. $active = ($date_start <= $now && $date_end >= $now)?true:false;
  853. }
  854. $session['active'] = $active;
  855. $session['session_category_id'] = $session_info[5];
  856. $output = $session;
  857. }
  858. return $output;
  859. }
  860. /**
  861. * Display code for one specific course a logged in user is subscribed to.
  862. * Shows a link to the course, what's new icons...
  863. *
  864. * $my_course['d'] - course directory
  865. * $my_course['i'] - course title
  866. * $my_course['c'] - visual course code
  867. * $my_course['k'] - system course code
  868. * $my_course['db'] - course database
  869. *
  870. * @version 1.0.3
  871. * @todo refactor into different functions for database calls | logic | display
  872. * @todo replace single-character $my_course['d'] indices
  873. * @todo move code for what's new icons to a separate function to clear things up
  874. * @todo add a parameter user_id so that it is possible to show the courselist of other users (=generalisation). This will prevent having to write a new function for this.
  875. */
  876. function get_global_courses_list($user_id) {
  877. //1. get list of sessions the user is subscribed to
  878. //2. build an ordered list of session categories and sessions
  879. //3. fill this ordered list with course details
  880. global $charset;
  881. global $nosession;
  882. if (api_get_setting('use_session_mode')=='true' && !$nosession) {
  883. global $now, $date_start, $date_end;
  884. }
  885. $output = array();
  886. return $output;
  887. }
  888. /**
  889. * Returns the "what's new" icon notifications
  890. * @param array Course information array, containing at least elements 'db' and 'k'
  891. * @return string The HTML link to be shown next to the course
  892. * @version
  893. */
  894. function show_notification($my_course) {
  895. $statistic_database = Database :: get_statistic_database();
  896. $user_id = api_get_user_id();
  897. $course_database = $my_course['db'];
  898. $course_tool_table = Database::get_course_table(TABLE_TOOL_LIST, $course_database);
  899. $tool_edit_table = Database::get_course_table(TABLE_ITEM_PROPERTY, $course_database);
  900. $course_group_user_table = Database :: get_course_table(TABLE_GROUP_USER, $course_database);
  901. $t_track_e_access = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_LASTACCESS);
  902. // get the user's last access dates to all tools of this course
  903. $sqlLastTrackInCourse = "SELECT * FROM $t_track_e_access
  904. USE INDEX (access_cours_code, access_user_id)
  905. WHERE access_cours_code = '".$my_course['k']."'
  906. AND access_user_id = '$user_id' AND access_session_id ='".$my_course['id_session']."'";
  907. $resLastTrackInCourse = Database::query($sqlLastTrackInCourse);
  908. $oldestTrackDate = "3000-01-01 00:00:00";
  909. while ($lastTrackInCourse = Database::fetch_array($resLastTrackInCourse)) {
  910. $lastTrackInCourseDate[$lastTrackInCourse['access_tool']] = $lastTrackInCourse['access_date'];
  911. if ($oldestTrackDate > $lastTrackInCourse['access_date']) {
  912. $oldestTrackDate = $lastTrackInCourse['access_date'];
  913. }
  914. }
  915. // get the last edits of all tools of this course
  916. $sql = "SELECT tet.*, tet.lastedit_date last_date, tet.tool tool, tet.ref ref,
  917. tet.lastedit_type type, tet.to_group_id group_id,
  918. ctt.image image, ctt.link link
  919. FROM $tool_edit_table tet, $course_tool_table ctt
  920. WHERE tet.lastedit_date > '$oldestTrackDate'
  921. AND ctt.name = tet.tool
  922. AND ctt.visibility = '1'
  923. AND tet.lastedit_user_id != $user_id AND tet.id_session = '".$my_course['id_session']."'
  924. ORDER BY tet.lastedit_date";
  925. $res = Database::query($sql);
  926. //get the group_id's with user membership
  927. $group_ids = GroupManager :: get_group_ids($course_database, $user_id);
  928. $group_ids[] = 0; //add group 'everyone'
  929. //filter all selected items
  930. while ($res && ($item_property = Database::fetch_array($res))) {
  931. if ((!isset ($lastTrackInCourseDate[$item_property['tool']]) || $lastTrackInCourseDate[$item_property['tool']] < $item_property['lastedit_date'])
  932. && ((in_array($item_property['to_group_id'], $group_ids) && ($item_property['tool'] != TOOL_DROPBOX && $item_property['tool'] != TOOL_NOTEBOOK && $item_property['tool'] != TOOL_CHAT)))
  933. && ($item_property['visibility'] == '1' || ($my_course['s'] == '1' && $item_property['visibility'] == '0') || !isset ($item_property['visibility']))) {
  934. if (($item_property['tool'] == TOOL_ANNOUNCEMENT || $item_property['tool'] == TOOL_CALENDAR_EVENT) && (($item_property['to_user_id'] != $user_id ) && (!isset($item_property['to_group_id']) || !in_array($item_property['to_group_id'],$group_ids)) )) continue;
  935. if ($item_property['tool'] == TOOL_SURVEY) {
  936. $survey_info = survey_manager::get_survey($item_property['ref'],0,$my_course['k']);
  937. $invited_users = SurveyUtil::get_invited_users($survey_info['code'],$course_database);
  938. if (!in_array($user_id,$invited_users['course_users'])) continue;
  939. }
  940. $notifications[$item_property['tool']] = $item_property;
  941. }
  942. }
  943. //show all tool icons where there is something new
  944. $retvalue = '&nbsp;';
  945. if (isset ($notifications)) {
  946. while (list ($key, $notification) = each($notifications)) {
  947. $lastDate = date('d/m/Y H:i', convert_mysql_date($notification['lastedit_date']));
  948. $type = $notification['lastedit_type'];
  949. //$notification[image]=str_replace(".png","gif",$notification[image]);
  950. //$notification[image]=str_replace(".gif","_s.gif",$notification[image]);
  951. if(empty($my_course['id_session'])) {
  952. $my_course['id_session'] = 0;
  953. }
  954. $retvalue .= '<a href="'.api_get_path(WEB_CODE_PATH).$notification['link'].'?cidReq='.$my_course['k'].'&amp;ref='.$notification['ref'].'&amp;gidReq='.$notification['to_group_id'].'&amp;id_session='.$my_course['id_session'].'">'.'<img title="-- '.get_lang(ucfirst($notification['tool'])).' -- '.get_lang('_title_notification').": ".get_lang($type)." ($lastDate).\"".' src="'.api_get_path(WEB_CODE_PATH).'img/'.$notification['image'].'" border="0" align="absbottom" /></a>&nbsp;';
  955. }
  956. }
  957. return $retvalue;
  958. }
  959. /**
  960. * retrieves the user defined course categories
  961. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  962. * @return array containing all the titles of the user defined courses with the id as key of the array
  963. */
  964. function get_user_course_categories() {
  965. global $_user;
  966. $output = array();
  967. $table_category = Database::get_user_personal_table(TABLE_USER_COURSE_CATEGORY);
  968. $sql = "SELECT * FROM ".$table_category." WHERE user_id='".Database::escape_string($_user['user_id'])."'";
  969. $result = Database::query($sql);
  970. while ($row = Database::fetch_array($result)) {
  971. $output[$row['id']] = $row['title'];
  972. }
  973. return $output;
  974. }
  975. /*
  976. ==============================================================================
  977. MAIN CODE
  978. ==============================================================================
  979. */
  980. /*
  981. ==============================================================================
  982. PERSONAL COURSE LIST
  983. ==============================================================================
  984. */
  985. if (!isset ($maxValvas)) {
  986. $maxValvas = CONFVAL_maxValvasByCourse; // Maximum number of entries
  987. }
  988. if (!isset ($maxAgenda)) {
  989. $maxAgenda = CONFVAL_maxAgendaByCourse; // collected from each course
  990. }
  991. if (!isset ($maxCourse)) {
  992. $maxCourse = CONFVAL_maxTotalByCourse; // and displayed in summary.
  993. }
  994. $maxValvas = (int) $maxValvas;
  995. $maxAgenda = (int) $maxAgenda;
  996. $maxCourse = (int) $maxCourse; // 0 if invalid
  997. if ($maxCourse > 0) {
  998. unset ($allentries); // we shall collect all summary$key1 entries in here:
  999. $toolsList['agenda']['name'] = get_lang('Agenda');
  1000. $toolsList['agenda']['path'] = api_get_path(WEB_CODE_PATH)."calendar/agenda.php?cidReq=";
  1001. $toolsList['valvas']['name'] = get_lang('Valvas');
  1002. $toolsList['valvas']['path'] = api_get_path(WEB_CODE_PATH)."announcements/announcements.php?cidReq=";
  1003. }
  1004. echo ' <div class="maincontent" id="maincontent">'; // start of content for logged in users
  1005. // Plugins for the my courses main area
  1006. api_plugin('mycourses_main');
  1007. /*
  1008. -----------------------------------------------------------------------------
  1009. System Announcements
  1010. -----------------------------------------------------------------------------
  1011. */
  1012. $announcement = isset($_GET['announcement']) ? $_GET['announcement'] : -1;
  1013. $visibility = api_is_allowed_to_create_course() ? VISIBLE_TEACHER : VISIBLE_STUDENT;
  1014. SystemAnnouncementManager :: display_announcements($visibility, $announcement);
  1015. if (!empty ($_GET['include']) && preg_match('/^[a-zA-Z0-9_-]*\.html$/',$_GET['include'])) {
  1016. include ('./home/'.$_GET['include']);
  1017. $pageIncluded = true;
  1018. } else {
  1019. /*--------------------------------------
  1020. DISPLAY COURSES
  1021. --------------------------------------*/
  1022. // compose a structured array of session categories, sessions and courses
  1023. // for the current user
  1024. if (isset($_GET['history']) && intval($_GET['history']) == 1) {
  1025. $courses_tree = UserManager::get_sessions_by_category($_user['user_id'],true,true);
  1026. } else {
  1027. $courses_tree = UserManager::get_sessions_by_category($_user['user_id'],true);
  1028. }
  1029. foreach ($courses_tree as $cat => $sessions) {
  1030. $courses_tree[$cat]['details'] = SessionManager::get_session_category($cat);
  1031. if ($cat == 0) {
  1032. $courses_tree[$cat]['courses'] = CourseManager::get_courses_list_by_user_id($_user['user_id'],false);
  1033. }
  1034. $courses_tree[$cat]['sessions'] = array_flip(array_flip($sessions));
  1035. if (count($courses_tree[$cat]['sessions'])>0) {
  1036. foreach ($courses_tree[$cat]['sessions'] as $k => $s_id) {
  1037. $courses_tree[$cat]['sessions'][$k] = array('details' => SessionManager::fetch($s_id));
  1038. $courses_tree[$cat]['sessions'][$k]['courses'] = UserManager::get_courses_list_by_session($_user['user_id'],$s_id);
  1039. }
  1040. }
  1041. }
  1042. $list = '';
  1043. foreach ($personal_course_list as $my_course) {
  1044. $thisCourseDbName = $my_course['db'];
  1045. $thisCourseSysCode = $my_course['k'];
  1046. $thisCoursePublicCode = $my_course['c'];
  1047. $thisCoursePath = $my_course['d'];
  1048. $sys_course_path = api_get_path(SYS_COURSE_PATH);
  1049. $dbname = $my_course['k'];
  1050. $status[$dbname] = $my_course['s'];
  1051. $nbDigestEntries = 0; // number of entries already collected
  1052. if ($maxCourse < $maxValvas) {
  1053. $maxValvas = $maxCourse;
  1054. }
  1055. if ($maxCourse > 0) {
  1056. $courses[$thisCourseSysCode]['coursePath'] = $thisCoursePath;
  1057. $courses[$thisCourseSysCode]['courseCode'] = $thisCoursePublicCode;
  1058. }
  1059. /*
  1060. -----------------------------------------------------------
  1061. Announcements
  1062. -----------------------------------------------------------
  1063. */
  1064. $course_database = $my_course['db'];
  1065. $course_tool_table = Database::get_course_table(TABLE_TOOL_LIST, $course_database);
  1066. $query = "SELECT visibility FROM $course_tool_table WHERE link = 'announcements/announcements.php' AND visibility = 1";
  1067. $result = Database::query($query);
  1068. // collect from announcements, but only if tool is visible for the course
  1069. if ($result && $maxValvas > 0 && Database::num_rows($result) > 0) {
  1070. //Search announcements table
  1071. //Take the entries listed at the top of advalvas/announcements tool
  1072. $course_announcement_table = Database::get_course_table(TABLE_ANNOUNCEMENT);
  1073. $sqlGetLastAnnouncements = "SELECT end_date publicationDate, content
  1074. FROM ".$course_announcement_table;
  1075. switch (CONFVAL_limitPreviewTo) {
  1076. case SCRIPTVAL_NewEntriesOfTheDay :
  1077. $sqlGetLastAnnouncements .= "WHERE DATE_FORMAT(end_date,'%Y %m %d') >= '".date("Y m d")."'";
  1078. break;
  1079. case SCRIPTVAL_NoTimeLimit :
  1080. break;
  1081. case SCRIPTVAL_NewEntriesOfTheDayOfLastLogin :
  1082. // take care mysql -> DATE_FORMAT(time,format) php -> date(format,date)
  1083. $sqlGetLastAnnouncements .= "WHERE DATE_FORMAT(end_date,'%Y %m %d') >= '".date("Y m d", $_user["lastLogin"])."'";
  1084. }
  1085. $sqlGetLastAnnouncements .= "ORDER BY end_date DESC LIMIT ".$maxValvas;
  1086. $resGetLastAnnouncements = Database::query($sqlGetLastAnnouncements);
  1087. if ($resGetLastAnnouncements) {
  1088. while ($annoncement = Database::fetch_array($resGetLastAnnouncements)) {
  1089. $keyTools = 'valvas';
  1090. $keyTime = $annoncement['publicationDate'];
  1091. $keyCourse = $thisCourseSysCode;
  1092. $digest[$$orderKey[0]][$$orderKey[1]][$$orderKey[2]][] = htmlspecialchars(api_substr(strip_tags($annoncement["content"]), 0, CONFVAL_NB_CHAR_FROM_CONTENT), ENT_QUOTES, $charset);
  1093. $nbDigestEntries ++; // summary has same order as advalvas
  1094. }
  1095. }
  1096. }
  1097. /*
  1098. -----------------------------------------------------------
  1099. Agenda
  1100. -----------------------------------------------------------
  1101. */
  1102. $course_database = $my_course['db'];
  1103. $course_tool_table = Database :: get_course_table(TABLE_TOOL_LIST,$course_database);
  1104. $query = "SELECT visibility FROM $course_tool_table WHERE link = 'calendar/agenda.php' AND visibility = 1";
  1105. $result = Database::query($query);
  1106. $thisAgenda = $maxCourse - $nbDigestEntries; // new max entries for agenda
  1107. if ($maxAgenda < $thisAgenda) {
  1108. $thisAgenda = $maxAgenda;
  1109. }
  1110. // collect from agenda, but only if tool is visible for the course
  1111. if ($result && $thisAgenda > 0 && Database::num_rows($result) > 0) {
  1112. $tableCal = $courseTablePrefix.$thisCourseDbName.$_configuration['db_glue']."calendar_event";
  1113. $sqlGetNextAgendaEvent = "SELECT start_date, title content, start_time
  1114. FROM $tableCal
  1115. WHERE start_date >= CURDATE()
  1116. ORDER BY start_date, start_time
  1117. LIMIT $maxAgenda";
  1118. $resGetNextAgendaEvent = Database::query($sqlGetNextAgendaEvent);
  1119. if ($resGetNextAgendaEvent) {
  1120. while ($agendaEvent = Database::fetch_array($resGetNextAgendaEvent)) {
  1121. $keyTools = 'agenda';
  1122. $keyTime = $agendaEvent['start_date'];
  1123. $keyCourse = $thisCourseSysCode;
  1124. $digest[$$orderKey[0]][$$orderKey[1]][$$orderKey[2]][] = htmlspecialchars(api_substr(strip_tags($agendaEvent["content"]), 0, CONFVAL_NB_CHAR_FROM_CONTENT), ENT_QUOTES, $charset);
  1125. $nbDigestEntries ++; // summary has same order as advalvas
  1126. }
  1127. }
  1128. }
  1129. /*
  1130. -----------------------------------------------------------
  1131. Digest Display
  1132. take collected data and display it
  1133. -----------------------------------------------------------
  1134. */
  1135. //$list[] = get_logged_user_course_html($my_course);
  1136. } //end while mycourse...
  1137. }
  1138. if (isset($_GET['history']) && intval($_GET['history']) == 1) {
  1139. echo '<h3>'.get_lang('HistoryTrainingSession').'</h3>';
  1140. if (empty($courses_tree[0]['sessions'])){
  1141. echo get_lang('YouDoNotHaveAnySessionInItsHistory');
  1142. }
  1143. }
  1144. if ( is_array($courses_tree) ) {
  1145. foreach ($courses_tree as $key => $category) {
  1146. if ($key == 0) {
  1147. // sessions and courses that are not in a session category
  1148. if (!isset($_GET['history'])) { // check if it's not history trainnign session list
  1149. display_special_courses(api_get_user_id());
  1150. display_courses(api_get_user_id());
  1151. }
  1152. //independent sessions
  1153. foreach ($category['sessions'] as $session) {
  1154. //don't show empty sessions
  1155. if (count($session['courses'])<1) { continue; }
  1156. //courses inside the current session
  1157. $date_session_start = $session['details']['date_start'];
  1158. $days_access_before_beginning = ($session['details']['nb_days_access_before_beginning'])*24*3600;
  1159. $session_now = time();
  1160. $html_courses_session = '';
  1161. $count_courses_session = 0;
  1162. foreach ($session['courses'] as $course) {
  1163. $is_coach_course = api_is_coach($session['details']['id'],$course['code']);
  1164. if ($is_coach_course) {
  1165. $allowed_time = (strtotime($date_session_start)-$days_access_before_beginning);
  1166. } else {
  1167. $allowed_time = strtotime($date_session_start);
  1168. }
  1169. if ($session_now > $allowed_time) {
  1170. $c = get_logged_user_course_html($course, $session['details']['id'], 'session_course_item');
  1171. $html_courses_session .= $c[1];
  1172. $count_courses_session++;
  1173. }
  1174. }
  1175. if ($count_courses_session > 0) {
  1176. echo '<ul class="session_box">';
  1177. echo '<li class="session_box_title" id="session_'.$session['details']['id'].'" >';
  1178. echo Display::return_icon('div_hide.gif', get_lang('Expand').'/'.get_lang('Hide'), array('align' => 'absmiddle', 'id' => 'session_img_'.$session['details']['id'])) . ' ';
  1179. $s = get_session_title_box($session['details']['id']);
  1180. //var_dump($s);
  1181. //echo get_lang('SessionName') . ': ' . $s['title']. ' - '.(!empty($s['coach'])?$s['coach'].' - ':'').$s['dates'];
  1182. echo '<span>' . $s['title']. ' </span> ';
  1183. if (api_is_platform_admin()) {
  1184. echo '<div style="float:right;"><a href="'.api_get_path(WEB_CODE_PATH).'admin/resume_session.php?id_session='.$session['details']['id'].'">'.Display::return_icon('edit.gif', get_lang('Edit'), array('align' => 'absmiddle')).'</a></div>';
  1185. }
  1186. echo '<br />'.(!empty($s['coach'])?$s['coach'].' | ':'').$s['dates'];
  1187. echo '</li>';
  1188. echo $html_courses_session;
  1189. echo '</ul>';
  1190. }
  1191. }
  1192. } else {
  1193. // all sessions included in
  1194. if (!empty($category['details'])) {
  1195. $count_courses_session = 0;
  1196. $html_sessions = '';
  1197. foreach ($category['sessions'] as $session) {
  1198. //don't show empty sessions
  1199. if (count($session['courses'])<1) { continue; }
  1200. $date_session_start = $session['details']['date_start'];
  1201. $days_access_before_beginning = ($session['details']['nb_days_access_before_beginning'])*24*3600;
  1202. $session_now = time();
  1203. $html_courses_session = '';
  1204. $count = 0;
  1205. foreach ($session['courses'] as $course) {
  1206. $is_coach_course = api_is_coach($session['details']['id'],$course['code']);
  1207. if ($is_coach_course) {
  1208. $allowed_time = (strtotime($date_session_start)-$days_access_before_beginning);
  1209. } else {
  1210. $allowed_time = strtotime($date_session_start);
  1211. }
  1212. if ($session_now > $allowed_time) {
  1213. $c = get_logged_user_course_html($course, $session['details']['id'], 'session_course_item');
  1214. $html_courses_session .= $c[1];
  1215. $count_courses_session++;
  1216. $count++;
  1217. }
  1218. }
  1219. if ($count > 0) {
  1220. $s = get_session_title_box($session['details']['id']);
  1221. $html_sessions .= '<ul class="session_box" id="session_'.$session['details']['id'].'">';
  1222. $html_sessions .= '<li class="session_box_title" id="session_'.$session['details']['id'].'">';
  1223. $html_sessions .= Display::return_icon('div_hide.gif', get_lang('Expand').'/'.get_lang('Hide'), array('align' => 'absmiddle', 'id' => 'session_img_'.$session['details']['id'])) . ' ';
  1224. $html_sessions .= '<span>' . $s['title']. ' </span> ';
  1225. if (api_is_platform_admin()) {
  1226. $html_sessions .= '<div style="float:right;"><a href="'.api_get_path(WEB_CODE_PATH).'admin/resume_session.php?id_session='.$session['details']['id'].'">'.Display::return_icon('edit.gif', get_lang('Edit'), array('align' => 'absmiddle')).'</a></div>';
  1227. }
  1228. $html_sessions .= ' <br /> '.(!empty($s['coach'])?$s['coach'].' | ':'').$s['dates'];
  1229. $html_sessions .= '</li>';
  1230. $html_sessions .= $html_courses_session;
  1231. $html_sessions .= '</ul>';
  1232. }
  1233. }
  1234. if ($count_courses_session > 0) {
  1235. echo '<div class="session_category" id="session_category_'.$category['details']['id'].'" style="background-color:#fbfbfb; border:1px solid #dddddd; padding:5px; margin-top: 10px;">';
  1236. echo '<div class="session_category_title_box" id="session_category_title_box_'.$category['details']['id'].'" style="color: #555555;">';
  1237. echo Display::return_icon('div_hide.gif', get_lang('Expand').'/'.get_lang('Hide'), array('align' => 'absmiddle', 'id' => 'category_img_'.$category['details']['id']));
  1238. echo Display::return_icon('folder_document.gif', get_lang('algo'));
  1239. echo '<span id="session_category_title">';
  1240. echo $category['details']['name'];
  1241. echo '</span>';
  1242. echo '<br / >'.get_lang('From').' '.$category['details']['date_start'].' '.get_lang('Until').' '.$category['details']['date_end'].'</div>';
  1243. echo $html_sessions;
  1244. echo '</div>';
  1245. }
  1246. }
  1247. }
  1248. }
  1249. }
  1250. /*
  1251. $userdefined_categories = get_user_course_categories();
  1252. if ( is_array($list) ) {
  1253. //Courses whithout sessions
  1254. $old_user_category = 0;
  1255. foreach ($list as $key => $value) {
  1256. if (empty($value[2])) { //if out of any session
  1257. $userdefined_categories = get_user_course_categories();
  1258. echo '<ul class="courseslist">';
  1259. if ($old_user_category<>$value[0]) {
  1260. if ($key <> 0 || $value[0] <> 0) {// there are courses in the previous category
  1261. echo "\n</ul>";
  1262. }
  1263. echo "\n\n\t<ul class=\"user_course_category\"><li>".$userdefined_categories[$value[0]]."</li></ul>\n";
  1264. if ($key<>0 OR $value[0]<>0){ // there are courses in the previous category
  1265. echo "<ul class=\"courseslist\">";
  1266. }
  1267. $old_user_category = $value[0];
  1268. }
  1269. echo $value[1];
  1270. echo "</ul>\n";
  1271. }
  1272. }
  1273. $listActives = $listInactives = $listCourses = array();
  1274. foreach ($list as $key => $value) {
  1275. if ($value['active']) { //if the session is still active (as told by get_logged_user_course_html())
  1276. $listActives[] = $value;
  1277. } else if (!empty($value[2])) { //if there is a session but it is not active
  1278. $listInactives[] = $value;
  1279. }
  1280. }
  1281. $old_user_category = 0;
  1282. $userdefined_categories = get_user_course_categories();
  1283. if (count($listActives) > 0 && $display_actives) {
  1284. echo "<ul class=\"courseslist\">\n";
  1285. $name_category = array();
  1286. $i = 0;
  1287. $j=0;
  1288. foreach ($listActives as $key => $value) {
  1289. $session_category_id=$value['session_category_id'];
  1290. if (!empty($value[3]['category'])) {
  1291. if (!in_array($value[3]['category'], $name_category)) {
  1292. if ($key != 0) {
  1293. echo '</ul>';
  1294. }
  1295. //Category
  1296. $name_category['name'] = $value[3]['category'];
  1297. echo '<ul class="category_box" id="category_box_'.$session_category_id.'">' .
  1298. '<li class="category_box_title" id="category_box_title_'.$session_category_id.'">'.$name_category['name'].'</li>';
  1299. echo "</ul>\n";
  1300. }
  1301. }
  1302. if (!empty($value[2])) {
  1303. if ((isset($old_session) && $old_session != $value[2]) or ((!isset($old_session)) && isset($value[2]))) {
  1304. $old_session = $value[2];
  1305. if ($key != 0) {
  1306. echo '</ul>';
  1307. }
  1308. //Session
  1309. echo '<ul style="display:none" class="session_box_'.$session_category_id.'" >' .
  1310. '<li class="session_box_title" >'.$value[3]['title'].' '.$value[3]['dates'].'</li>';
  1311. if ( !empty($value[3]['coach']) ) {
  1312. echo '<li class="session_box_coach">'.$value[3]['coach'].'</li>';
  1313. }
  1314. echo "</ul>\n";
  1315. echo '<ul class="session_course_item" id="session_course_item_'.$i.'">';
  1316. }
  1317. }
  1318. //Courses
  1319. echo $value[1];
  1320. $i++;
  1321. }
  1322. echo "\n</ul><br /><br />\n";
  1323. }
  1324. if (count($listInactives) > 0 && !$display_actives) {
  1325. echo '<ul class="sessions_list_inactive">';
  1326. foreach ($listInactives as $key => $value) {
  1327. if (!empty($value[2])) {
  1328. if ($old_session != $value[2]) {
  1329. $old_session = $value[2];
  1330. if ($key != 0) {
  1331. echo '</ul>';
  1332. }
  1333. echo '<ul class="session_box">' .
  1334. '<li class="session_box_title">'.$value[3]['title'].' '.$value[3]['dates'].'</li>';
  1335. if (!empty($value[3]['coach'])) {
  1336. echo '<li class="session_box_coach">'.$value[3]['coach'].'</li>';
  1337. }
  1338. echo "</ul>\n";
  1339. echo '<ul>';
  1340. }
  1341. }
  1342. echo $value[1];
  1343. }
  1344. echo "\n</ul><br /><br />\n";
  1345. }
  1346. }
  1347. */
  1348. echo '</div>'; // end of content section
  1349. // Register whether full admin or null admin course
  1350. // by course through an array dbname x user status
  1351. api_session_register('status');
  1352. /*
  1353. ==============================================================================
  1354. RIGHT MENU
  1355. ==============================================================================
  1356. */
  1357. echo ' <div id="menu" class="menu">';
  1358. // api_display_language_form(); // moved to the profile page.
  1359. $show_menu = false;
  1360. $show_create_link = false;
  1361. $show_course_link = false;
  1362. $show_digest_link = false;
  1363. $display_add_course_link = api_is_allowed_to_create_course() && ($_SESSION['studentview'] != 'studentenview');
  1364. if ($display_add_course_link) {
  1365. $show_menu = true;
  1366. $show_create_link = true;
  1367. }
  1368. if (api_is_platform_admin() || api_is_course_admin() || api_is_allowed_to_create_course()) {
  1369. $show_menu = true;
  1370. $show_course_link = true;
  1371. } else {
  1372. if (api_get_setting('allow_students_to_browse_courses')=='true') {
  1373. $show_menu = true;
  1374. $show_course_link = true;
  1375. }
  1376. }
  1377. if (isset($toolsList) and is_array($toolsList) and isset($digest)) {
  1378. $show_digest_link = true;
  1379. $show_menu = true;
  1380. }
  1381. echo '<div class="menusection">';
  1382. echo '<span class="menusectioncaption">'.get_lang('MenuUser').'</span>';
  1383. //user image
  1384. // @todo add a platform setting to add the user image
  1385. if (api_get_setting('allow_social_tool')=='true' && api_get_setting('allow_message_tool') == 'true') {
  1386. $img_array= UserManager::get_user_picture_path_by_id(api_get_user_id(),'web',true,true);
  1387. $no_image =false;
  1388. if ($img_array['file'] == 'unknown.jpg') {
  1389. $no_image =true;
  1390. }
  1391. $img_array = UserManager::get_picture_user(api_get_user_id(), $img_array['file'], 50, USER_IMAGE_SIZE_MEDIUM, ' width="90" height="90" ');
  1392. echo '<div class="clear"></div>';
  1393. echo '<div id="social_widget" >';
  1394. echo ' <div id="social_widget_image">';
  1395. if ($no_image == false) {
  1396. echo '<a href="'.api_get_path(WEB_PATH).'main/social/home.php"><img src="'.$img_array['file'].'" '.$img_array['style'].' border="1"></a>';
  1397. } else {
  1398. echo '<a href="'.api_get_path(WEB_PATH).'main/auth/profile.php"><img title="'.get_lang('EditProfile').'" src="'.$img_array['file'].'" '.$img_array['style'].' border="1"></a>';
  1399. }
  1400. echo '</div>';
  1401. require_once api_get_path(LIBRARY_PATH).'message.lib.php';
  1402. require_once api_get_path(LIBRARY_PATH).'social.lib.php';
  1403. require_once api_get_path(LIBRARY_PATH).'group_portal_manager.lib.php';
  1404. // New messages
  1405. $number_of_new_messages = MessageManager::get_new_messages();
  1406. // New contact invitations
  1407. $number_of_new_messages_of_friend = SocialManager::get_message_number_invitation_by_user_id(api_get_user_id());
  1408. // New group invitations sent by a moderator
  1409. $group_pending_invitations = GroupPortalManager::get_groups_by_user(api_get_user_id(), GROUP_USER_PERMISSION_PENDING_INVITATION,false);
  1410. $group_pending_invitations = count($group_pending_invitations);
  1411. $total_invitations = $number_of_new_messages_of_friend + $group_pending_invitations;
  1412. $cant_msg = '';
  1413. if ($number_of_new_messages > 0) {
  1414. $cant_msg = ' ('.$number_of_new_messages.')';
  1415. }
  1416. //<h2 class="message-title">'.get_lang('Messages').'</h2>
  1417. echo '<div class="clear"></div>';
  1418. echo '<div class="message-content"> <p>';
  1419. $link = '';
  1420. if (api_get_setting('show_tabs', 'social') == 'true') {
  1421. $link = '?f=social';
  1422. }
  1423. echo '<a href="'.api_get_path(WEB_PATH).'main/messages/inbox.php'.$link.'" class="message-body">'.get_lang('Inbox').$cant_msg.' </a><br />';
  1424. echo '<a href="'.api_get_path(WEB_PATH).'main/messages/new_message.php'.$link.'" class="message-body">'.get_lang('Compose').' </a><br />';
  1425. //echo '<a href="'.api_get_path(WEB_PATH).'main/auth/profile.php" class="message-body">'.get_lang('EditMyProfile').' </a><br />';
  1426. if ($total_invitations > 0) {
  1427. echo '<a href="'.api_get_path(WEB_PATH).'main/social/invitations.php" class="message-body">'.get_lang('PendingInvitations').' ('.$total_invitations.') </a><br />';
  1428. }
  1429. echo '</p>';
  1430. echo '</div>';
  1431. echo '</div><div class="clear"></div>';
  1432. }
  1433. // My account section
  1434. if ($show_menu) {
  1435. echo '<ul class="menulist">';
  1436. if ($show_create_link) {
  1437. display_create_course_link();
  1438. }
  1439. if ($show_course_link) {
  1440. if (!api_is_drh()) {
  1441. display_edit_course_list_links();
  1442. display_history_course_session();
  1443. } else {
  1444. display_dashboard_link();
  1445. }
  1446. }
  1447. if ($show_digest_link) {
  1448. display_digest($toolsList, $digest, $orderKey, $courses);
  1449. }
  1450. echo '</ul>';
  1451. }
  1452. echo '</div>'; //close menusection
  1453. //deleting the myprofile link
  1454. if (api_get_setting('allow_social_tool') == true) {
  1455. unset($menu_navigation['myprofile']);
  1456. }
  1457. // Main navigation section
  1458. // tabs that are deactivated are added here
  1459. if (!empty($menu_navigation)) {
  1460. echo '<div class="menusection">';
  1461. echo '<span class="menusectioncaption">'.get_lang('MainNavigation').'</span>';
  1462. echo '<ul class="menulist">';
  1463. foreach ($menu_navigation as $section => $navigation_info) {
  1464. $current = $section == $GLOBALS['this_section'] ? ' id="current"' : '';
  1465. echo '<li'.$current.'>';
  1466. echo '<a href="'.$navigation_info['url'].'" target="_self">'.$navigation_info['title'].'</a>';
  1467. echo '</li>';
  1468. echo "\n";
  1469. }
  1470. echo '</ul>';
  1471. echo '</div>';
  1472. }
  1473. // plugins for the my courses menu
  1474. if (isset($_plugins['mycourses_menu']) && is_array($_plugins['mycourses_menu'])) {
  1475. echo '<div class="note">';
  1476. api_plugin('mycourses_menu');
  1477. echo '</div>';
  1478. }
  1479. if (api_get_setting('allow_reservation') == 'true' && api_is_allowed_to_create_course() ){
  1480. echo '<div class="menusection">';
  1481. echo '<span class="menusectioncaption">'.get_lang('Booking').'</span>';
  1482. echo '<ul class="menulist">';
  1483. echo '<a href="main/reservation/reservation.php">'.get_lang('ManageReservations').'</a><br />';
  1484. echo '</ul>';
  1485. echo '</div>';
  1486. }
  1487. // search textbox
  1488. if (api_get_setting('search_enabled') == 'true') {
  1489. echo '<div class="searchbox">';
  1490. $search_btn = get_lang('Search');
  1491. $search_text_default = get_lang('YourTextHere');
  1492. echo <<<EOD
  1493. <br />
  1494. <form action="main/search/" method="post">
  1495. &nbsp;&nbsp;<input type="text" id="query" size="15" name="query" value="" />
  1496. &nbsp;&nbsp;<button class="save" type="submit" name="submit" value="$search_btn"/>$search_btn </button>
  1497. </form>
  1498. EOD;
  1499. echo '</div>';
  1500. }
  1501. echo '</div>'; // end of menu
  1502. //footer
  1503. Display :: display_footer();