Dokeos PHP Cross Reference Learning Management Systems

Source: /user_portal_classic.php - 1455 lines - 60551 bytes - Summary - Text - Print

Description: This is the index file displayed when a user is logged in on Dokeos. It displays: - personal course list - menu bar

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

title

Description

title

Description

title

Description

title

title

Body