dokeos-main
[ class tree: dokeos-main ] [ index: dokeos-main ] [ all elements ]

Source for file index.php

Documentation is available at index.php

  1. <?php
  2. /*
  3.     DOKEOS - elearning and course management software
  4.  
  5.     For a full list of contributors, see documentation/credits.html
  6.  
  7.     This program is free software; you can redistribute it and/or
  8.     modify it under the terms of the GNU General Public License
  9.     as published by the Free Software Foundation; either version 2
  10.     of the License, or (at your option) any later version.
  11.     See "documentation/licence.html" more details.
  12.  
  13.     Contact:
  14.         Dokeos
  15.         Rue du Corbeau, 108
  16.         B-1030 Brussels - Belgium
  17.         Contact: info@dokeos.com
  18. */
  19.  
  20. /**
  21. *    @package dokeos.main
  22. *     @author Patrick Cool <patrick.cool@UGent.be>, Ghent University, Refactoring
  23. *     @version $Id: index.php 15173 2008-04-29 17:29:11Z yannoo $
  24. *   @todo check the different @todos in this page and really do them
  25. *     @todo check if the news management works as expected
  26. */
  27.  
  28. // only this script should have this constant defined. This is used to activate the javascript that
  29. // gives the login name automatic focus in header.inc.html.
  30. /** @todo  Couldn't this be done using the $HtmlHeadXtra array? */
  31. define('DOKEOS_HOMEPAGE'true);
  32.  
  33. // the language file
  34. $language_file array ('courses''index');
  35.  
  36. /* Flag forcing the 'current course' reset, as we're not inside a course anymore  */
  37. // maybe we should change this into an api function? an example: Coursemanager::unset();
  38. $cidReset true;
  39.  
  40.  
  41.  
  42. /*
  43. -----------------------------------------------------------
  44.     Included libraries
  45. -----------------------------------------------------------
  46. */
  47. /** @todo make all the library files consistent, use filename.lib.php and not filename.lib.inc.php */
  48. require_once ('main/inc/global.inc.php');
  49. include_once (api_get_path(LIBRARY_PATH).'course.lib.php');
  50. include_once (api_get_path(LIBRARY_PATH).'debug.lib.inc.php');
  51. include_once (api_get_path(LIBRARY_PATH).'events.lib.inc.php');
  52. include_once (api_get_path(LIBRARY_PATH).'system_announcements.lib.php');
  53. include_once (api_get_path(LIBRARY_PATH).'groupmanager.lib.php');
  54. include_once (api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php');
  55.  
  56. $loginFailed = isset($_GET['loginFailed']true : isset($loginFailed);
  57. $setting_show_also_closed_courses (api_get_setting('show_closed_courses')=='true'true false;
  58.  
  59. // the section (for the tabs)
  60. $this_section SECTION_CAMPUS;
  61.  
  62. /*
  63. -----------------------------------------------------------
  64.     Action Handling
  65. -----------------------------------------------------------
  66. */
  67. /** @todo     wouldn't it make more sense if this would be done in local.inc.php so that local.inc.php become the only place where authentication is done?
  68.  *              by doing this you could logout from any page instead of only from index.php. From the moment there is a logout=true in the url you will be logged out
  69.  *              this can be usefull when you are on an open course and you need to log in to edit something and you immediately want to check how anonymous users
  70.  *              will see it.
  71.  */
  72. if (!empty($_GET['logout']))
  73. {
  74.     logout();
  75. }
  76.  
  77. /*
  78. -----------------------------------------------------------
  79.     Table definitions
  80. -----------------------------------------------------------
  81. */
  82. $main_course_table         Database :: get_main_table(TABLE_MAIN_COURSE);
  83. $main_category_table     Database :: get_main_table(TABLE_MAIN_CATEGORY);
  84. $track_login_table         Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_LOGIN);
  85.  
  86. /*
  87. -----------------------------------------------------------
  88.     Constants and CONFIGURATION parameters
  89. -----------------------------------------------------------
  90. */
  91. /** @todo these configuration settings should move to the dokeos config settings */
  92. /** defines wether or not anonymous visitors can see a list of the courses on the Dokeos homepage that are open to the world */
  93. $_setting['display_courses_to_anonymous_users''true';
  94.  
  95. /** @todo remove this piece of code because this is not used */
  96. if (isset ($_user['user_id']))
  97. {
  98.     $nameTools api_get_setting('siteName');
  99. }
  100.  
  101. /*
  102. ==============================================================================
  103.         LOGIN
  104. ==============================================================================
  105. */
  106. /**
  107.  * @todo This piece of code should probably move to local.inc.php where the actual login / logout procedure is handled.
  108.  * @todo consider removing this piece of code because does nothing.
  109.  */
  110. if (isset($_GET['submitAuth']&& $_GET['submitAuth'== 1)
  111. {
  112.     // nice lie!!!
  113.     echo 'Attempted breakin - sysadmins notified.';
  114.     session_destroy();
  115.     die();
  116. }
  117.  
  118. /**
  119.  * @todo This piece of code should probably move to local.inc.php where the actual login procedure is handled.
  120.  * @todo check if this code is used. I think this code is never executed because after clicking the submit button
  121.  *           the code does the stuff in local.inc.php and then redirects to index.php or user_portal.php depending
  122.  *           on api_get_setting('page_after_login')
  123.  */
  124. if (!empty($_POST["submitAuth"]))
  125. {
  126.     // the user is already authenticated, we now find the last login of the user.
  127.     if (isset ($_user['user_id']))
  128.     {
  129.         $sql_last_login "SELECT UNIX_TIMESTAMP(login_date)
  130.                                 FROM $track_login_table
  131.                                 WHERE login_user_id = '".$_user['user_id']."'
  132.                                 ORDER BY login_date DESC LIMIT 1";
  133.         $result_last_login api_sql_query($sql_last_login__FILE____LINE__);
  134.         if (!$result_last_login)
  135.             if (mysql_num_rows($result_last_login0)
  136.             {
  137.                 $user_last_login_datetime mysql_fetch_array($result_last_login);
  138.                 $user_last_login_datetime $user_last_login_datetime[0];
  139.                 api_session_register('user_last_login_datetime');
  140.             }
  141.         mysql_free_result($result_last_login);
  142.  
  143.         //event_login();
  144.         if (api_is_platform_admin())
  145.         {
  146.             // decode all open event informations and fill the track_c_* tables
  147.             include (api_get_path(LIBRARY_PATH)."stats.lib.inc.php");
  148.             decodeOpenInfos();
  149.         }
  150.     }
  151. // end login -- if($_POST["submitAuth"])
  152. else
  153. {
  154.     // only if login form was not sent because if the form is sent the user was already on the page.
  155.     event_open();
  156. }
  157.  
  158. // the header
  159. Display :: display_header('''dokeos');
  160.  
  161. /*
  162. ==============================================================================
  163.         MAIN CODE
  164. ==============================================================================
  165. */
  166. echo '<div class="maincontent" id="content">';
  167.  
  168. // Plugins for loginpage_main AND campushomepage_main
  169. {
  170.     api_plugin('loginpage_main');
  171. }
  172. else
  173. {
  174.     api_plugin('campushomepage_main');
  175. }
  176.  
  177. // Including the page for the news
  178. $page_included false;
  179. if (!empty ($_GET['include']&& !strstr($_GET['include']'/'&& !strstr($_GET['include']'\\'&& strstr($_GET['include']'.html'))
  180. {
  181.     include ('./home/'.$_GET['include']);
  182.     $page_included true;
  183. }
  184. else
  185. {
  186.     
  187.     if(!empty($_SESSION['user_language_choice']))
  188.     {
  189.         $user_selected_language=$_SESSION['user_language_choice'];
  190.     }
  191.     elseif(!empty($_SESSION['_user']['language']))
  192.     {
  193.         $user_selected_language=$_SESSION['_user']['language'];
  194.     }
  195.     else
  196.     {
  197.         $user_selected_language=get_setting('platformLanguage');
  198.     }
  199.     
  200.     if(!file_exists('home/home_news_'.$user_selected_language.'.html'))
  201.     {
  202.         $home_top_temp=file('home/home_top.html');
  203.         $home_top_temp=implode('',$home_top_temp);
  204.         $open=str_replace('{rel_path}',api_get_path(REL_PATH),$home_top_temp);
  205.         echo $open;
  206.     }
  207.     else
  208.     {
  209.         if(file_exists('home/home_top_'.$user_selected_language.'.html'))
  210.         {
  211.             $home_top_temp file_get_contents('home/home_top_'.$user_selected_language.'.html');
  212.         }
  213.         else
  214.         {
  215.             $home_top_temp file_get_contents('home/home_top.html');
  216.         }
  217.         $open=str_replace('{rel_path}',api_get_path(REL_PATH),$home_top_temp);
  218.         echo $open;
  219.     }
  220. }
  221.  
  222. // Display System announcements
  223. $announcement = isset($_GET['announcement']$_GET['announcement': -1;
  224. $announcement intval($announcement);
  225.  
  226. if (isset($_user['user_id']))
  227. {
  228.     SystemAnnouncementManager :: display_announcements($visibility$announcement);
  229. }
  230. else
  231. {
  232. }
  233.  
  234. // Display courses and category list
  235. if (!$page_included)
  236. {
  237.  
  238.     if (api_get_setting('display_categories_on_homepage'== 'true')
  239.     {
  240.         echo '<div class="home_cats">';
  241.         echo '</div>';
  242.     }
  243. }
  244. echo '</div>';
  245.  
  246. // display right menu: language form, login section + useful weblinks
  247. echo '<div class="menu" id="menu">';
  248. echo '</div>';
  249.  
  250. /*
  251. ==============================================================================
  252.         FOOTER
  253. ==============================================================================
  254. */
  255.  
  256. /**
  257.  * This function handles the logout and is called whenever there is a $_GET['logout']
  258.  *
  259.  * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  260.  */
  261. function logout()
  262. {
  263.     global $_configuration$extAuthSource;
  264.     // variable initialisation
  265.     $query_string='';
  266.  
  267.     if(!empty($_SESSION['user_language_choice']))
  268.     {
  269.         $query_string='?language='.$_SESSION['user_language_choice'];
  270.     }
  271.  
  272.     // Database table definition
  273.     $tbl_track_login Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_LOGIN);
  274.  
  275.     // selecting the last login of the user
  276.     $uid intval($_GET['uid']);
  277.     $sql_last_connection="SELECT login_id, login_date FROM $tbl_track_login WHERE login_user_id='$uid' ORDER BY login_date DESC LIMIT 0,1";
  278.     $q_last_connection=api_sql_query($sql_last_connection);
  279.     if(Database::num_rows($q_last_connection)>0)
  280.     {
  281.         $i_id_last_connection=mysql_result($q_last_connection,0,"login_id");
  282.     }
  283.     
  284.     if(!isset($_SESSION['login_as']))
  285.     {
  286.         $s_sql_update_logout_date="UPDATE $tbl_track_login SET logout_date=NOW() WHERE login_id='$i_id_last_connection'";
  287.         api_sql_query($s_sql_update_logout_date);
  288.     }
  289.  
  290.     LoginDelete($uid$_configuration['statistics_database'])//from inc/lib/online.inc.php - removes the "online" status
  291.     
  292.     //the following code enables the use of an external logout function.
  293.     //example: define a $extAuthSource['ldap']['logout']="file.php" in configuration.php
  294.     // then a function called ldap_logout() inside that file 
  295.     // (using *authent_name*_logout as the function name) and the following code 
  296.     // will find and execute it 
  297.     $uinfo api_get_user_info($uid);
  298.     if(($uinfo['auth_source'!= PLATFORM_AUTH_SOURCE&& is_array($extAuthSource))
  299.     {
  300.         if(is_array($extAuthSource[$uinfo['auth_source']]))
  301.         {
  302.             $subarray $extAuthSource[$uinfo['auth_source']];
  303.             if(!empty($subarray['logout']&& file_exists($subarray['logout']))
  304.             {
  305.                 include_once($subarray['logout']);
  306.                 $logout_function $uinfo['auth_source'].'_logout';
  307.                 if(function_exists($logout_function))
  308.                 {
  309.                     $logout_function($uinfo);
  310.                 }
  311.             }
  312.         }
  313.     }
  314.  
  315.  
  316.     header("Location: index.php$query_string");
  317.     exit();
  318. }
  319.  
  320. /**
  321.  * This function checks if there are courses that are open to the world in the platform course categories (=faculties)
  322.  *
  323.  * @param unknown_type $category 
  324.  * @return boolean 
  325.  */
  326. function category_has_open_courses($category)
  327. {
  328.     global $setting_show_also_closed_courses;
  329.     
  330.     $user_identified (api_get_user_id()>&& !api_is_anonymous());
  331.     $main_course_table Database :: get_main_table(TABLE_MAIN_COURSE);
  332.     $sql_query "SELECT * FROM $main_course_table WHERE category_code='$category'";
  333.     $sql_result api_sql_query($sql_query__FILE____LINE__);
  334.     while ($course mysql_fetch_array($sql_result))
  335.     {
  336.         if ($setting_show_also_closed_courses == false)
  337.         {
  338.             if((api_get_user_id()>
  339.                 and $course['visibility'== COURSE_VISIBILITY_OPEN_PLATFORM)
  340.                 or ($course['visibility'== COURSE_VISIBILITY_OPEN_WORLD))
  341.             {
  342.                 return true//at least one open course
  343.             }
  344.         }
  345.         else 
  346.         {
  347.             if(isset($course['visibility']))
  348.             {
  349.                 return true//at least one course (does not matter weither it's open or not because $setting_show_also_closed_courses = true
  350.             }            
  351.         }
  352.     }
  353.     return false;
  354. }
  355.  
  356. {
  357.     echo "<li><a href=\"main/create_course/add_course.php\">".get_lang("CourseCreate")."</a></li>";
  358. }
  359.  
  360. {
  361.     echo "<li><a href=\"main/auth/courses.php\">".get_lang("CourseManagement")."</a></li>";
  362. }
  363.  
  364. /**
  365.  * Displays the right-hand menu for anonymous users:
  366.  * login form, useful links, help section
  367.  * Warning: function defines globals
  368.  * @version 1.0.1
  369.  * @todo does $_plugins need to be global?
  370.  */
  371. {
  372.     global $loginFailed$_plugins$_user$menu_navigation;
  373.  
  374.     $platformLanguage api_get_setting('platformLanguage');
  375.  
  376.     if !($_user['user_id']or api_is_anonymous($_user['user_id']) ) // only display if the user isn't logged in
  377.     {
  378.         api_display_language_form();
  379.         echo '<br />';
  380.         display_login_form();
  381.  
  382.         if ($loginFailed)
  383.         {
  384.             handle_login_failed();
  385.         }
  386.         if (api_get_setting('allow_lostpassword'== 'true' OR api_get_setting('allow_registration'== 'true')
  387.         {
  388.             echo '<div class="menusection"><span class="menusectioncaption">'.get_lang('MenuUser').'</span><ul class="menulist">';
  389.             if (get_setting('allow_registration'<> 'false')
  390.             {
  391.                 echo '<li><a href="main/auth/inscription.php">'.get_lang('Reg').'</a></li>';
  392.             }
  393.             if (get_setting('allow_lostpassword'== 'true')
  394.             {
  395.                 display_lost_password_info();
  396.             }
  397.             echo '</ul></div>';
  398.         }
  399.         if(api_number_of_plugins('loginpage_menu'0)
  400.         {
  401.             echo '<div class="note" style="background: none">';
  402.             api_plugin('loginpage_menu');
  403.             echo '</div>';
  404.         }
  405.     }
  406.  
  407.     /*** hide right menu "general" and other parts on anonymous right menu  *****/
  408.     echo "<div class=\"menusection\">""<span class=\"menusectioncaption\">".get_lang("MenuGeneral")."</span>";
  409.      echo "<ul class=\"menulist\">";
  410.  
  411.     $user_selected_language api_get_interface_language();
  412.     if (!isset ($user_selected_language))
  413.         $user_selected_language $platformLanguage;
  414.     if(!file_exists('home/home_menu_'.$user_selected_language.'.html'))
  415.     {
  416.         include ('home/home_menu.html');
  417.     }
  418.     else
  419.     {
  420.         include('home/home_menu_'.$user_selected_language.'.html');
  421.     }
  422.     echo '</ul>';
  423.     echo '</div>';
  424.  
  425.     if ($_user['user_id'&& api_number_of_plugins('campushomepage_menu'0)
  426.     {
  427.         echo '<div class="note" style="background: none">';
  428.         api_plugin('campushomepage_menu');
  429.         echo '</div>';
  430.     }
  431.  
  432.     /**
  433.      * User section
  434.      */
  435.     if(isset($_SESSION['_user']['user_id']&& $_SESSION['_user']['user_id']!=0)
  436.     {
  437.         // tabs that are deactivated are added here
  438.         if (!empty($menu_navigation))
  439.         {
  440.             echo "<div class=\"menusection\">";
  441.             echo "<span class=\"menusectioncaption\">".get_lang("MainNavigation")."</span>";
  442.             echo "<ul class=\"menulist\">";
  443.             foreach($menu_navigation as $section => $navigation_info)
  444.             {
  445.                 $current ($section == $GLOBALS['this_section'' id="current"' '');
  446.                 echo '<li'.$current.'>';
  447.                 echo '<a href="'.$navigation_info['url'].'" target="_top">'.$navigation_info['title'].'</a>';
  448.                 echo '</li>';
  449.                 echo "\n";
  450.             }
  451.             echo "</ul>";
  452.             echo '</div>';
  453.         }
  454.  
  455.         echo "<div class=\"menusection\">";
  456.         echo "<span class=\"menusectioncaption\">".get_lang("MenuUser")."</span>";
  457.         echo "<ul class=\"menulist\">";
  458.  
  459.         $display_add_course_link api_is_allowed_to_create_course(&& ($_SESSION["studentview"!= "studentenview");
  460.         if ($display_add_course_link)
  461.             display_create_course_link();
  462.  
  463.         echo "</ul>";
  464.         echo "</div>";
  465.     }
  466.  
  467.  
  468.     
  469.     // includes for any files to be displayed below anonymous right menu
  470.     if(!file_exists('home/home_notice_'.$user_selected_language.'.html'&& file_get_contents('home/home_notice.html')!='')
  471.     {
  472.         echo '<div class="note">';
  473.         include ('home/home_notice.html');
  474.         echo '</div>';
  475.     }
  476.     elseif(file_exists('home/home_notice_'.$user_selected_language.'.html'&& file_get_contents('home/home_notice_'.$user_selected_language.'.html')!='')
  477.     {
  478.         echo '<div class="note">';
  479.         include('home/home_notice_'.$user_selected_language.'.html');
  480.         echo '</div>';
  481.     }
  482.     
  483.  
  484.  
  485. }
  486.  
  487. /**
  488. *    Reacts on a failed login:
  489. *    displays an explanation with
  490. *    a link to the registration form.
  491. *
  492. *    @version 1.0.1
  493. */
  494. {
  495.     if(!isset($_GET['error']))
  496.     {
  497.         $message get_lang("InvalidId");
  498.         if (api_is_self_registration_allowed())
  499.         {
  500.             $message get_lang("InvalidForSelfRegistration");
  501.         }
  502.     }
  503.     else
  504.     {
  505.         switch ($_GET['error'])
  506.         {
  507.             case '':
  508.                 $message get_lang("InvalidId");
  509.                 if (api_is_self_registration_allowed())
  510.                 {
  511.                     $message get_lang("InvalidForSelfRegistration");
  512.                 }
  513.                 break;
  514.             case 'account_expired':
  515.                 $message=get_lang('AccountExpired');
  516.                 break;
  517.             case 'account_inactive':
  518.                 $message=get_lang('AccountInactive');
  519.                 break;
  520.             case 'user_password_incorrect':
  521.                 $message=get_lang('InvalidId');
  522.                 break;
  523.         }
  524.     }
  525.     echo "<div id=\"login_fail\">".$message."</div>";
  526. }
  527.  
  528. /**
  529. *    Adds a form to let users login
  530. *    @version 1.1
  531. */
  532. function display_login_form()
  533. {
  534.     $form new FormValidator('formLogin');
  535.     $form->addElement('text','login',get_lang('UserName'),array('size'=>15));
  536.     $form->addElement('password','password',get_lang('Pass'),array('size'=>15));
  537.     $form->addElement('submit','submitAuth',get_lang('Ok'));
  538.     $renderer =$form->defaultRenderer();
  539.     $renderer->setElementTemplate('<div><label>{label}</label></div><div>{element}</div>');
  540.     $form->display();
  541.     if(api_get_setting('openid_authentication')=='true')
  542.     {
  543.         include_once('main/auth/openid/login.php');
  544.         echo '<div>'.openid_form().'</div>';
  545.     }
  546. }
  547. /**
  548.  * Displays a link to the lost password section
  549.  */
  550. {
  551.     echo "<li><a href=\"main/auth/lostPassword.php\">".get_lang("LostPassword")."</a></li>";
  552. }
  553.  
  554. /**
  555. * Display list of courses in a category.
  556. * (for anonymous users)
  557. *
  558. @version 1.1
  559. @author Patrick Cool <patrick.cool@UGent.be>, Ghent University - refactoring and code cleaning
  560. */
  561. {
  562.     $ctok $_SESSION['sec_token'];
  563.     $stok Security::get_token();    
  564.     
  565.     //init
  566.     $user_identified (api_get_user_id()>&& !api_is_anonymous());
  567.     $web_course_path api_get_path(WEB_COURSE_PATH);
  568.     $category $_GET["category"];
  569.     global $setting_show_also_closed_courses;
  570.  
  571.     // Database table definitions
  572.     $main_course_table         Database :: get_main_table(TABLE_MAIN_COURSE);
  573.     $main_category_table     Database :: get_main_table(TABLE_MAIN_CATEGORY);
  574.  
  575.     $platformLanguage api_get_setting('platformLanguage');
  576.  
  577.     //get list of courses in category $category
  578.     $sql_get_course_list "SELECT * FROM $main_course_table cours
  579.                                 WHERE category_code = '".mysql_real_escape_string($_GET["category"])."'
  580.                                 ORDER BY title, UPPER(visual_code)";
  581.     //removed: AND cours.visibility='".COURSE_VISIBILITY_OPEN_WORLD."'
  582.     $sql_result_courses api_sql_query($sql_get_course_list__FILE____LINE__);
  583.  
  584.     while ($course_result mysql_fetch_array($sql_result_courses))
  585.     {
  586.         $course_list[$course_result;
  587.     }
  588.  
  589.     $platform_visible_courses '';
  590.     // $setting_show_also_closed_courses
  591.     if($user_identified)
  592.     {
  593.         if ($setting_show_also_closed_courses)
  594.         {
  595.             $platform_visible_courses '';
  596.         }
  597.         else 
  598.         {
  599.             $platform_visible_courses "  AND (t3.visibility='".COURSE_VISIBILITY_OPEN_WORLD."' OR t3.visibility='".COURSE_VISIBILITY_OPEN_PLATFORM."' )";    
  600.         }
  601.     }
  602.     else 
  603.     {
  604.         if ($setting_show_also_closed_courses)
  605.         {
  606.             $platform_visible_courses '';
  607.         }
  608.         else 
  609.         {
  610.             $platform_visible_courses "  AND (t3.visibility='".COURSE_VISIBILITY_OPEN_WORLD."' )";    
  611.         }                
  612.     }
  613.     $sqlGetSubCatList "
  614.                 SELECT t1.name,t1.code,t1.parent_id,t1.children_count,COUNT(DISTINCT t3.code) AS nbCourse
  615.                 FROM $main_category_table t1
  616.                 LEFT JOIN $main_category_table t2 ON t1.code=t2.parent_id
  617.                 LEFT JOIN $main_course_table t3 ON (t3.category_code=t1.code $platform_visible_courses)
  618.                 WHERE t1.parent_id "(empty ($category"IS NULL" "='$category'")."
  619.                 GROUP BY t1.name,t1.code,t1.parent_id,t1.children_count ORDER BY t1.tree_pos, t1.name";
  620.     $resCats api_sql_query($sqlGetSubCatList__FILE____LINE__);
  621.     $thereIsSubCat false;
  622.     if (mysql_num_rows($resCats0)
  623.     {
  624.         $htmlListCat "<h4 style=\"margin-top: 0px;\">".get_lang("CatList")."</h4>"."<ul>";
  625.         while ($catLine mysql_fetch_array($resCats))
  626.         {
  627.             if ($catLine['code'!= $category)
  628.             {
  629.  
  630.                 $category_has_open_courses category_has_open_courses($catLine['code']);
  631.                 if ($category_has_open_courses)
  632.                 {
  633.                     //the category contains courses accessible to anonymous visitors
  634.                     $htmlListCat .= "<li>";
  635.                     $htmlListCat .= "<a href=\"".api_get_self()."?category=".$catLine['code']."\">".$catLine['name']."</a>";
  636.                     if (api_get_setting('show_number_of_courses'== 'true')
  637.                     {
  638.                         $htmlListCat .= " (".$catLine['nbCourse']." ".get_lang("Courses").")";
  639.                     }
  640.                     $htmlListCat .= "</li>\n";
  641.                     $thereIsSubCat true;
  642.                 }
  643.                 elseif ($catLine['children_count'0)
  644.                 {
  645.                     //the category has children, subcategories
  646.                     $htmlListCat .= "<li>";
  647.                     $htmlListCat .= "<a href=\"".api_get_self()."?category=".$catLine['code']."\">".$catLine['name']."</a>";
  648.                     $htmlListCat .= "</li>\n";
  649.                     $thereIsSubCat true;
  650.                 }
  651.                 /************************************************************************
  652.                  end changed code to eliminate the (0 courses) after empty categories
  653.                  ************************************************************************/
  654.                 elseif (api_get_setting('show_empty_course_categories'== 'true')
  655.                 {
  656.                     $htmlListCat .= "<li>";
  657.                     $htmlListCat .= $catLine['name'];
  658.                     $htmlListCat .= "</li>\n";
  659.                     $thereIsSubCat true;
  660.                 }//else don't set thereIsSubCat to true to avoid printing things if not requested
  661.             }
  662.             else
  663.             {
  664.                 $htmlTitre "<p>";
  665.                 if (api_get_setting('show_back_link_on_top_of_tree'== 'true')
  666.                 {
  667.                     $htmlTitre .= "<a href=\"".api_get_self()."\">"."&lt;&lt; ".get_lang("BackToHomePage")."</a>";
  668.                 }
  669.                 if (!is_null($catLine['parent_id']|| (api_get_setting('show_back_link_on_top_of_tree'<> 'true' && !is_null($catLine['code'])))
  670.                 {
  671.                     $htmlTitre .= "<a href=\"".api_get_self()."?category=".$catLine['parent_id']."\">"."&lt;&lt; ".get_lang("Up")."</a>";
  672.                 }
  673.                 $htmlTitre .= "</p>\n";
  674.                 if ($category != "" && !is_null($catLine['code']))
  675.                 {
  676.                     $htmlTitre .= "<h3>".$catLine['name']."</h3>\n";
  677.                 }
  678.                 else
  679.                 {
  680.                     $htmlTitre .= "<h3>".get_lang("Categories")."</h3>\n";
  681.                 }
  682.             }
  683.         }
  684.         $htmlListCat .= "</ul>\n";
  685.     }
  686.     echo $htmlTitre;
  687.     if ($thereIsSubCat)
  688.     {
  689.         echo $htmlListCat;
  690.     }
  691.     while ($categoryName mysql_fetch_array($resCats))
  692.     {
  693.         echo "<h3>"$categoryName['name']"</h3>\n";
  694.     }
  695.     $numrows mysql_num_rows($sql_result_courses);
  696.     $courses_list_string '';
  697.     $courses_shown 0;
  698.     if ($numrows 0)
  699.     {
  700.         if ($thereIsSubCat)
  701.         {
  702.             $courses_list_string .= "<hr size=\"1\" noshade=\"noshade\">\n";
  703.         }
  704.         $courses_list_string .= "<h4 style=\"margin-top: 0px;\">".get_lang("CourseList")."</h4>\n"."<ul>\n";
  705.         
  706.         if (api_get_user_id())
  707.         {
  708.             $courses_of_user get_courses_of_user(api_get_user_id());
  709.         }
  710.         
  711.         foreach ($course_list AS $course)
  712.         {
  713.             // $setting_show_also_closed_courses
  714.             
  715.             if ($setting_show_also_closed_courses==false)
  716.             {
  717.                 // if we do not show the closed courses 
  718.                 // we only show the courses that are open to the world (to everybody)
  719.                 // and the courses that are open to the platform (if the current user is a registered user
  720.                 if( ($user_identified && $course['visibility'== COURSE_VISIBILITY_OPEN_PLATFORMOR ($course['visibility'== COURSE_VISIBILITY_OPEN_WORLD))
  721.                 {
  722.                     $courses_shown++;
  723.                     $courses_list_string .= "<li>\n";
  724.                 $courses_list_string .= "<a href=\"".$web_course_path.$course['directory']."/\">".$course['title']."</a><br />";
  725.                 if (get_setting("display_coursecode_in_courselist"== "true")
  726.                 {
  727.                     $courses_list_string .= $course['visual_code'];
  728.                 }
  729.                 if (get_setting("display_coursecode_in_courselist"== "true" AND get_setting("display_teacher_in_courselist"== "true")
  730.                 {
  731.                     $courses_list_string .= " - ";
  732.                 }
  733.                 if (get_setting("display_teacher_in_courselist"== "true")
  734.                 {
  735.                     $courses_list_string .= $course['tutor_name'];
  736.                 }                
  737.                     if (api_get_setting('show_different_course_language'== 'true' && $course['course_language'<> api_get_setting('platformLanguage'))
  738.                     {
  739.                         $courses_list_string .= ' - '.$course['course_language'];
  740.                     }
  741.                     $courses_list_string .= "</li>\n";
  742.                 }
  743.             }
  744.             // we DO show the closed courses.
  745.             // the course is accessible if (link to the course homepage)
  746.             // 1. the course is open to the world (doesn't matter if the user is logged in or not): $course['visibility'] == COURSE_VISIBILITY_OPEN_WORLD)
  747.             // 2. the user is logged in and the course is open to the world or open to the platform: ($user_identified && $course['visibility'] == COURSE_VISIBILITY_OPEN_PLATFORM)
  748.             // 3. the user is logged in and the user is subscribed to the course and the course visibility is not COURSE_VISIBILITY_CLOSED
  749.             // 4. the user is logged in and the user is course admin of te course (regardless of the course visibility setting)
  750.             // 5. the user is the platform admin api_is_platform_admin()
  751.             // 
  752.             else 
  753.             {
  754.                 $courses_shown++;
  755.                 $courses_list_string .= "<li>\n";
  756.                     if$course['visibility'== COURSE_VISIBILITY_OPEN_WORLD
  757.                             OR ($user_identified AND $course['visibility'== COURSE_VISIBILITY_OPEN_PLATFORM
  758.                             OR ($user_identified AND key_exists($course['code'],$courses_of_userAND $course['visibility'<> COURSE_VISIBILITY_CLOSED
  759.                             OR $courses_of_user[$course['code']]['status'== '1'
  760.                             OR api_is_platform_admin())
  761.                     {
  762.                         $courses_list_string .= "<a href=\"".$web_course_path.$course['directory']."/\">";
  763.                     }
  764.                     $courses_list_string .= $course['title'];
  765.                     if$course['visibility'== COURSE_VISIBILITY_OPEN_WORLD
  766.                             OR ($user_identified AND $course['visibility'== COURSE_VISIBILITY_OPEN_PLATFORM
  767.                             OR ($user_identified AND key_exists($course['code'],$courses_of_userAND $course['visibility'<> COURSE_VISIBILITY_CLOSED
  768.                             OR $courses_of_user[$course['code']]['status'== '1'
  769.                             OR api_is_platform_admin())
  770.                     {
  771.                         $courses_list_string .="</a><br />";
  772.                     }
  773.                     if (get_setting("display_coursecode_in_courselist"== "true")
  774.                     {
  775.                         $courses_list_string .= $course['visual_code'];
  776.                     }
  777.                     if (get_setting("display_coursecode_in_courselist"== "true" AND get_setting("display_teacher_in_courselist"== "true")
  778.                     {
  779.                         $courses_list_string .= " - ";
  780.                     }
  781.                     if (get_setting("display_teacher_in_courselist"== "true")
  782.                     {
  783.                         $courses_list_string .= $course['tutor_name'];
  784.                     }                
  785.                 if (api_get_setting('show_different_course_language'== 'true' && $course['course_language'<> api_get_setting('platformLanguage'))
  786.                 {
  787.                     $courses_list_string .= ' - '.$course['course_language'];
  788.                 }
  789.                     if (api_get_setting('show_different_course_language'== 'true' && $course['course_language'<> api_get_setting('platformLanguage'))
  790.                     {
  791.                         $courses_list_string .= ' - '.$course['course_language'];
  792.                     }
  793.                     // We display a subscription link if 
  794.                     // 1. it is allowed to register for the course and if the course is not already in the courselist of the user and if the user is identiefied
  795.                     // 2
  796.                     if ($user_identified AND !key_exists($course['code'],$courses_of_user))
  797.                     {
  798.                         if ($course['subscribe'== '1')
  799.                         {
  800.                             $courses_list_string .= "<form action=\"main/auth/courses.php?action=subscribe&category=".$_GET['category']."\" method=\"post\">";
  801.                             $courses_list_string .= '<input type="hidden" name="sec_token" value="'.$stok.'">';
  802.                             $courses_list_string .= "<input type=\"hidden\" name=\"subscribe\" value=\"".$course['code']."\" />";
  803.                             $courses_list_string .= "<input type=\"image\" name=\"unsub\" src=\"main/img/enroll.gif\" alt=\"".get_lang("Subscribe")."\" />".get_lang("Subscribe")."</form>";
  804.                         }
  805.                         else
  806.                         {
  807.                             $courses_list_string .= '<br />'.get_lang("SubscribingNotAllowed");
  808.                         }
  809.                     }
  810.                 $courses_list_string .= "</li>\n";
  811.             }
  812.         }
  813.         $courses_list_string .= "</ul>\n";
  814.     }
  815.     else
  816.     {
  817.         // echo "<blockquote>",get_lang('_No_course_publicly_available'),"</blockquote>\n";
  818.     }
  819.     if($courses_shown 0)
  820.     //only display the list of courses and categories if there was more than
  821.       // 0 courses visible to the world (we're in the anonymous list here)
  822.         echo $courses_list_string;
  823.     }
  824.     if ($category != "")
  825.     {
  826.         echo "<p>""<a href=\"".api_get_self()."\"><b>&lt;&lt;</b> "get_lang("BackToHomePage")"</a>""</p>\n";
  827.     }
  828. }
  829.  
  830. /**
  831.  * retrieves all the courses that the user has already subscribed to
  832.  * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University, Belgium
  833.  * @param int $user_id: the id of the user
  834.  * @return array an array containing all the information of the courses of the given user
  835. */
  836. function get_courses_of_user($user_id)
  837. {
  838.     $table_course        Database::get_main_table(TABLE_MAIN_COURSE);
  839.     $table_course_user    Database::get_main_table(TABLE_MAIN_COURSE_USER);
  840.  
  841.     // Secondly we select the courses that are in a category (user_course_cat<>0) and sort these according to the sort of the category
  842.     $user_id intval($user_id);
  843.     $sql_select_courses="SELECT course.code k, course.visual_code  vc, course.subscribe subscr, course.unsubscribe unsubscr,
  844.                                 course.title i, course.tutor_name t, course.db_name db, course.directory dir, course_rel_user.status status,
  845.                                 course_rel_user.sort sort, course_rel_user.user_course_cat user_course_cat
  846.                                 FROM    $table_course       course,
  847.                                         $table_course_user  course_rel_user
  848.                                 WHERE course.code = course_rel_user.course_code
  849.                                 AND   course_rel_user.user_id = '".$user_id."'
  850.                                 ORDER BY course_rel_user.sort ASC";
  851.     $result api_sql_query($sql_select_courses,__FILE__,__LINE__);
  852.     while ($row=Database::fetch_array($result))
  853.     {
  854.         // we only need the database name of the course
  855.         $courses[$row['k']] array("db"=> $row['db']"code" => $row['k']"visual_code" => $row['vc']"title" => $row['i']"directory" => $row['dir']"status" => $row['status']"tutor" => $row['t']"subscribe" => $row['subscr']"unsubscribe" => $row['unsubscr']"sort" => $row['sort']"user_course_category" => $row['user_course_cat']);
  856.     }
  857.     return $courses;
  858. }
  859. ?>

Documentation generated on Thu, 12 Jun 2008 13:49:55 -0500 by phpDocumentor 1.4.1