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

Source for file class.php

Documentation is available at class.php

  1. <?php
  2. //  $Id: class.php 9119 2006-08-18 07:10:23Z bmol $
  3. /*
  4. ==============================================================================
  5.     Dokeos - elearning and course management software
  6.  
  7.     Copyright (c) 2004-2005 Dokeos S.A.
  8.     Copyright (c) Bart Mollet, Hogeschool Gent
  9.  
  10.     For a full list of contributors, see "credits.txt".
  11.     The full license can be read in "license.txt".
  12.  
  13.     This program is free software; you can redistribute it and/or
  14.     modify it under the terms of the GNU General Public License
  15.     as published by the Free Software Foundation; either version 2
  16.     of the License, or (at your option) any later version.
  17.  
  18.     See the GNU General Public License for more details.
  19.  
  20.     Contact address: Dokeos, 44 rue des palais, B-1030 Brussels, Belgium
  21.     Mail: info@dokeos.com
  22. ==============================================================================
  23. */
  24. /**
  25. ==============================================================================
  26. *    This                             script allows teachers to manage subscribed
  27. *classes in their course.
  28. *    @package dokeos.user
  29. ==============================================================================
  30. */
  31. /*
  32. ==============================================================================
  33.         INIT SECTION
  34. ==============================================================================
  35. */
  36. // name of the language file that needs to be included 
  37. $language_file array('registration','admin');
  38. include ('../inc/global.inc.php');
  39. $this_section SECTION_COURSES;
  40.  
  41. require_once (api_get_path(LIBRARY_PATH).'course.lib.php');
  42. require_once (api_get_path(LIBRARY_PATH).'sortabletable.class.php');
  43. require_once (api_get_path(LIBRARY_PATH).'classmanager.lib.php');
  44. require_once (api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php');
  45.  
  46. /*
  47. ==============================================================================
  48.         MAIN CODE
  49. ==============================================================================
  50. */
  51.  
  52.  
  53. if(api_get_setting('use_session_mode')=='true')
  54. {
  55.     api_not_allowed();
  56. }
  57.  
  58. /*
  59. -----------------------------------------------------------
  60.     Header
  61. -----------------------------------------------------------
  62. */
  63. $tool_name get_lang("Classes");
  64. //extra entries in breadcrumb
  65. $interbreadcrumb[array ("url" => "user.php""name" => get_lang("Users"));
  66. Display :: display_header($tool_name"User");
  67.  
  68. {
  69.     echo '<a href="subscribe_class.php?'.api_get_cidreq().'">'.get_lang("AddClassesToACourse").'</a><br /><br />';
  70. }
  71. /*
  72. ==============================================================================
  73.         MAIN SECTION
  74. ==============================================================================
  75. */
  76.  
  77. {
  78.     if (isset ($_GET['unsubscribe']))
  79.     {
  80.         ClassManager::unsubscribe_from_course($_GET['class_id'],$_course['sysCode']);
  81.         Display::display_normal_message(get_lang('ClassesUnSubscribed'));
  82.     }
  83.     if (isset ($_POST['action']))
  84.     {
  85.         switch ($_POST['action'])
  86.         {
  87.             case 'unsubscribe' :
  88.                 if (is_array($_POST['class']))
  89.                 {
  90.                     foreach ($_POST['class'as $index => $class_id)
  91.                     {
  92.                         ClassManager::unsubscribe_from_course($class_id,$_course['sysCode']);
  93.                     }
  94.                     Display::display_normal_message(get_lang('ClassesUnSubscribed'));
  95.                 }
  96.                 break;
  97.         }
  98.     }
  99. }
  100. /*
  101. -----------------------------------------------------------
  102.         SHOW LIST OF CLASSES
  103. -----------------------------------------------------------
  104. */
  105.  
  106. /**
  107.  *  * Get the number of classes to display on the current page.
  108.  */
  109. {
  110.     $class_table Database :: get_main_table(TABLE_MAIN_CLASS);
  111.     $course_class_table Database :: get_main_table(TABLE_MAIN_COURSE_CLASS);
  112.     $sql "SELECT c.id    FROM $class_table c, $course_class_table cc WHERE cc.class_id = c.id AND cc.course_code ='".$_SESSION['_course']['id']."'";
  113.     if (isset ($_GET['keyword']))
  114.     {
  115.         $keyword mysql_real_escape_string($_GET['keyword']);
  116.         $sql .= " AND (c.name LIKE '%".$keyword."%')";
  117.     }
  118.     $res api_sql_query($sql__FILE____LINE__);
  119.     $result mysql_num_rows($res);
  120.     return $result;
  121. }
  122. /**
  123.  * Get the classes to display on the current page.
  124.  */
  125. function get_class_data($from$number_of_items$column$direction)
  126. {
  127.     $class_table Database :: get_main_table(TABLE_MAIN_CLASS);
  128.     $course_class_table Database :: get_main_table(TABLE_MAIN_COURSE_CLASS);
  129.     $class_user_table Database :: get_main_table(TABLE_MAIN_CLASS_USER);
  130.     $sql "SELECT
  131.                             c.id AS col0,
  132.                             c.name   AS col1,
  133.                             COUNT(cu.user_id) AS col2";
  134.     if (api_is_allowed_to_edit())
  135.     {
  136.         $sql .=    " ,c.id AS col3";
  137.     }
  138.     // '(' and ')' in next query is necessary (see http://bugs.mysql.com/bug.php?id=19053)
  139.     $sql .= " FROM ($class_table c, $course_class_table cc)";
  140.     $sql .= " LEFT JOIN $class_user_table cu ON cu.class_id = c.id";
  141.     $sql .= " WHERE c.id = cc.class_id AND cc.course_code = '".$_SESSION['_course']['id']."'";
  142.     if (isset ($_GET['keyword']))
  143.     {
  144.         $keyword mysql_real_escape_string($_GET['keyword']);
  145.         $sql .= " AND (c.name LIKE '%".$keyword."%')";
  146.     }
  147.     $sql .= " GROUP BY c.id, c.name ";
  148.     $sql .= " ORDER BY col$column $direction ";
  149.     $sql .= " LIMIT $from,$number_of_items";
  150.     $res api_sql_query($sql__FILE____LINE__);
  151.     $classes array ();
  152.     while ($class mysql_fetch_row($res))
  153.     {
  154.         $classes[$class;
  155.     }
  156.     return $classes;
  157. }
  158. /**
  159.  * Build the reg-column of the table
  160.  * @param int $class_id The class id
  161.  * @return string Some HTML-code
  162.  */
  163. function reg_filter($class_id)
  164. {
  165.     global $charset;
  166.     $result '<a href="'.api_get_self().'?'.api_get_cidreq().'&unsubscribe=yes&amp;class_id='.$class_id.'" onclick="javascript:if(!confirm(\''.addslashes(htmlentities(get_lang('ConfirmYourChoice'),ENT_QUOTES,$charset)).'\')) return false;"><img src="../img/delete.gif"/></a>';
  167.     return $result;
  168. }
  169. // Build search-form
  170. $form new FormValidator('search_class''get','','',null,false);
  171. $renderer $form->defaultRenderer();
  172. $renderer->setElementTemplate('<span>{element}</span> ');
  173. $form->add_textfield('keyword'''false);
  174. $form->addElement('submit''submit'get_lang('SearchButton'));
  175.  
  176. // Build table
  177. $table new SortableTable('users''get_number_of_classes''get_class_data'1);
  178. $parameters['keyword'$_GET['keyword'];
  179. $table->set_additional_parameters($parameters);
  180. $col 0;
  181. $table->set_header($col ++''false);
  182. $table->set_header($col ++get_lang('ClassName'));
  183. $table->set_header($col ++get_lang('NumberOfUsers'));
  184. {
  185.     $table->set_header($col ++''false);
  186.     $table->set_column_filter($col -1'reg_filter');
  187.     $table->set_form_actions(array ('unsubscribe' => get_lang('Unreg'))'class');
  188. }
  189. // Display form & table
  190. $form->display();
  191. echo '<br />';
  192. $table->display();
  193. /*
  194. ==============================================================================
  195.         FOOTER
  196. ==============================================================================
  197. */
  198. ?>

Documentation generated on Thu, 12 Jun 2008 13:05:47 -0500 by phpDocumentor 1.4.1