user_portal.php 70 KB

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