Remove ClassManager

pull/2487/head
jmontoyaa 9 years ago
parent f909086d01
commit 3d793f4fa3
  1. 6
      certificates/index.php
  2. 44
      main/admin/class_add.php
  3. 48
      main/admin/class_edit.php
  4. 117
      main/admin/class_import.php
  5. 98
      main/admin/class_information.php
  6. 128
      main/admin/class_list.php
  7. 189
      main/admin/class_user_import.php
  8. 150
      main/admin/subscribe_class2course.php
  9. 151
      main/admin/subscribe_user2class.php
  10. 226
      main/inc/lib/classmanager.lib.php
  11. 146
      main/user/subscribe_class.php
  12. 11
      main/webservices/user_import/import.lib.php
  13. 94
      tests/main/inc/lib/classmanager.lib.test.php
  14. 1
      tests/main/inc/lib/fileManage.lib.test.php
  15. 2
      tests/main/inc/lib/fileManager.lib.test.php
  16. 1
      tests/main/inc/lib/groupmanager.lib.test.php
  17. 1
      tests/main/webservices/user_import/import.lib.test.php

@ -15,7 +15,7 @@ switch ($action) {
case 'export':
$hideExportLink = api_get_setting('hide_certificate_export_link');
$hideExportLinkStudent = api_get_setting('hide_certificate_export_link_students');
if ($hideExportLink === 'true' || (api_is_student() && $hideExportLinkStudent === 'true') ) {
if ($hideExportLink === 'true' || (api_is_student() && $hideExportLinkStudent === 'true')) {
api_not_allowed(true);
}
@ -33,8 +33,7 @@ switch ($action) {
);
$pdfParams['orientation'] = 'landscape';
$pageFormat = $pdfParams['orientation'] == 'landscape' ? 'A4-L' : 'A4';
$pageFormat = $pdfParams['orientation'] === 'landscape' ? 'A4-L' : 'A4';
$userInfo = api_get_user_info($certificate->user_id);
$pdfName = api_replace_dangerous_char(get_lang('Certificate') . ' ' . $userInfo['username']);
@ -45,4 +44,5 @@ switch ($action) {
default:
// Show certificate HTML
$certificate->show();
break;
}

@ -1,44 +0,0 @@
<?php
/* For licensing terms, see /license.txt */
/**
* @package chamilo.admin
*/
/**
* Code
*/
// Resetting the course id.
$cidReset = true;
// Including some necessary dokeos files.
require_once '../inc/global.inc.php';
// Setting the section (for the tabs).
$this_section = SECTION_PLATFORM_ADMIN;
// Access restrictions.
api_protect_admin_script();
// Setting breadcrumbs.
$interbreadcrumb[] = array('url' => 'index.php', 'name' => get_lang('PlatformAdmin'));
$interbreadcrumb[] = array ('url' => 'class_list.php', 'name' => get_lang('Classes'));
// Setting the name of the tool.
$tool_name = get_lang("AddClasses");
$form = new FormValidator('add_class');
$form->addText('name', get_lang('ClassName'));
$form->addButtonCreate(get_lang('Ok'));
if ($form->validate()) {
$values = $form->exportValues();
ClassManager::create_class($values['name']);
header('Location: class_list.php');
}
// Displaying the header.
Display :: display_header($tool_name);
// Displaying the form.
$form->display();
// Displaying the footer.
Display :: display_footer();

@ -1,48 +0,0 @@
<?php
/* For licensing terms, see /license.txt */
/**
* @package chamilo.admin
*/
/**
* Code
*/
// Resetting the course id.
$cidReset = true;
// Including some necessary dokeos files.
require_once '../inc/global.inc.php';
// Setting the section (for the tabs).
$this_section = SECTION_PLATFORM_ADMIN;
// Access restrictions.
api_protect_admin_script();
// Setting breadcrumbs.
$interbreadcrumb[] = array ('url' => 'index.php', 'name' => get_lang('PlatformAdmin'));
$interbreadcrumb[] = array ('url' => 'class_list.php', 'name' => get_lang('AdminClasses'));
// Setting the name of the tool.
$tool_name = get_lang('AddClasses');
$tool_name = get_lang('ModifyClassInfo');
$class_id = intval($_GET['idclass']);
$class = ClassManager :: get_class_info($class_id);
$form = new FormValidator('edit_class', 'post', 'class_edit.php?idclass='.$class_id);
$form->addText('name',get_lang('ClassName'));
$form->addButtonUpdate(get_lang('Ok'));
$form->setDefaults(array('name'=>$class['name']));
if($form->validate())
{
$values = $form->exportValues();
ClassManager :: set_name($values['name'], $class_id);
header('Location: class_list.php');
}
Display :: display_header($tool_name);
//api_display_tool_title($tool_name);
$form->display();
// Displaying the footer.
Display :: display_footer();

@ -1,117 +0,0 @@
<?php
/* For licensing terms, see /license.txt */
/**
* @package chamilo.admin
*/
/**
* Code
* This tool allows platform admins to add classes by uploading a CSV file
* @todo Add some langvars to DLTT
*/
/**
* Validates imported data.
* @param array $classes A list of classes to be validated
* @return array An array with error messages (if any)
*/
function validate_data($classes) {
$errors = array();
foreach ($classes as $index => $class) {
// 1. Check wheter ClassName is available.
if (!isset($class['ClassName']) || strlen(trim($class['ClassName'])) == 0) {
$class['line'] = $index + 2;
$class['error'] = get_lang('MissingClassName');
$errors[] = $class;
}
// 2. Check whether class doesn't exist yet.
else {
if (ClassManager::class_name_exists($class['ClassName'])) {
$class['line'] = $index + 2;
$class['error'] = get_lang('ClassNameExists').' <strong>'.$class['ClassName'].'</strong>';
$errors[] = $class;
}
}
}
return $errors;
}
/**
* Save imported class data to database
* @param array $classes A list of classes to be imported
* @return int The number of classes that where successfully imported
*/
function save_data($classes) {
$number_of_added_classes = 0;
foreach ($classes as $index => $class) {
if (ClassManager::create_class($class['ClassName'])) {
$number_of_added_classes++;
}
}
return $number_of_added_classes;
}
// Resetting the course id.
$cidReset = true;
// Including some necessary dokeos files.
include '../inc/global.inc.php';
// Setting the section (for the tabs).
$this_section = SECTION_PLATFORM_ADMIN;
// Access restrictions.
api_protect_admin_script();
// setting breadcrumbs
$interbreadcrumb[] = array ('url' => 'index.php', 'name' => get_lang('PlatformAdmin'));
$interbreadcrumb[] = array ('url' => 'class_list.php', 'name' => get_lang('Classes'));
// Database Table Definitions
// Setting the name of the tool.
$tool_name = get_lang('ImportClassListCSV');
// Displaying the header.
Display :: display_header($tool_name);
//api_display_tool_title($tool_name);
set_time_limit(0);
$form = new FormValidator('import_classes');
$form->addElement('file', 'import_file', get_lang('ImportCSVFileLocation'));
$form->addButtonImport(get_lang('Import'));
if ($form->validate()) {
$classes = Import::csvToArray($_FILES['import_file']['tmp_name']);
$errors = validate_data($classes);
if (count($errors) == 0) {
$number_of_added_classes = save_data($classes);
Display::display_normal_message($number_of_added_classes.' '.get_lang('ClassesCreated'));
} else {
$error_message = get_lang('ErrorsWhenImportingFile');
$error_message .= '<ul>';
foreach ($errors as $index => $error_class) {
$error_message .= '<li>'.$error_class['error'].' ('.get_lang('Line').' '.$error_class['line'].')';
$error_message .= '</li>';
}
$error_message .= '</ul>';
$error_message .= get_lang('NoClassesHaveBeenCreated');
Display :: display_error_message($error_message);
}
}
$form->display();
?>
<p><?php echo get_lang('CSVMustLookLike').' ('.get_lang('MandatoryFields').')'; ?> :</p>
<pre>
<b>ClassName</b>
<b>1A</b>
<b>1B</b>
<b>2A group 1</b>
<b>2A group 2</b>
</pre>
<?php
// Displaying the footer.
Display :: display_footer();

@ -1,98 +0,0 @@
<?php
/* For licensing terms, see /license.txt */
/**
* @package chamilo.admin
*/
/**
* Code
* @author Bart Mollet
*/
$cidReset = true;
require_once '../inc/global.inc.php';
$this_section = SECTION_PLATFORM_ADMIN;
api_protect_admin_script();
if (!isset($_GET['id'])) {
api_not_allowed();
}
$interbreadcrumb[] = array ('url' => 'index.php', 'name' => get_lang('PlatformAdmin'));
$interbreadcrumb[] = array ('url' => 'class_list.php', 'name' => get_lang('AdminClasses'));
$class_id = $_GET['id'];
$class = ClassManager::get_class_info($class_id);
$tool_name = $class['name'];
Display::display_header($tool_name);
//api_display_tool_title($tool_name);
/**
* Show all users subscribed in this class.
*/
echo '<h4>'.get_lang('Users').'</h4>';
$users = ClassManager::get_users($class_id);
if (count($users) > 0) {
$is_western_name_order = api_is_western_name_order();
$table_header[] = array (get_lang('OfficialCode'), true);
if ($is_western_name_order) {
$table_header[] = array (get_lang('FirstName'), true);
$table_header[] = array (get_lang('LastName'), true);
} else {
$table_header[] = array (get_lang('LastName'), true);
$table_header[] = array (get_lang('FirstName'), true);
}
$table_header[] = array (get_lang('Email'), true);
$table_header[] = array (get_lang('Status'), true);
$table_header[] = array ('', false);
$data = array();
foreach($users as $index => $user) {
$username = api_htmlentities(sprintf(get_lang('LoginX'), $user['username']), ENT_QUOTES);
$row = array ();
$row[] = $user['official_code'];
if ($is_western_name_order) {
$row[] = $user['firstname'];
$row[] = "<span title='$username'>".$user['lastname']."</span>";
} else {
$row[] = "<span title='$username'>".$user['lastname']."</span>";
$row[] = $user['firstname'];
}
$row[] = Display :: encrypted_mailto_link($user['email'], $user['email']);
$row[] = $user['status'] == 5 ? get_lang('Student') : get_lang('Teacher');
$row[] = '<a href="user_information.php?user_id='.$user['user_id'].'">'.Display::return_icon('synthese_view.gif', get_lang('Info')).'</a>';
$data[] = $row;
}
Display::display_sortable_table($table_header,$data,array(),array(),array('id'=>$_GET['id']));
} else {
echo get_lang('NoUsersInClass');
}
/**
* Show all courses in which this class is subscribed.
*/
$courses = ClassManager::get_courses($class_id);
if (count($courses) > 0) {
$header[] = array (get_lang('Code'), true);
$header[] = array (get_lang('Title'), true);
$header[] = array ('', false);
$data = array ();
foreach( $courses as $index => $course) {
$row = array ();
$row[] = $course['visual_code'];
$row[] = $course['title'];
$row[] = '<a href="course_information.php?code='.$course['code'].'">'.Display::return_icon('info_small.gif', get_lang('Delete')).'</a>'.
'<a href="'.api_get_path(WEB_COURSE_PATH).$course['directory'].'">'.Display::return_icon('course_home.gif', get_lang('CourseHome')).'</a>' .
'<a href="course_edit.php?course_code='.$course['code'].'">'.Display::return_icon('edit.gif', get_lang('Edit')).'</a>';
$data[] = $row;
}
echo '<p><b>'.get_lang('Courses').'</b></p>';
echo '<blockquote>';
Display :: display_sortable_table($header, $data, array (), array (), array('id'=>$_GET['id']));
echo '</blockquote>';
} else {
echo '<p>'.get_lang('NoCoursesForThisClass').'</p>';
}
// Displaying the footer.
Display::display_footer();

@ -1,128 +0,0 @@
<?php
/* For licensing terms, see /license.txt */
/**
* @package chamilo.admin
*/
/**
* Code
*/
$cidReset = true;
require '../inc/global.inc.php';
$this_section = SECTION_PLATFORM_ADMIN;
api_protect_admin_script();
/**
* Gets the total number of classes.
*/
function get_number_of_classes() {
$tbl_class = Database :: get_main_table(TABLE_MAIN_CLASS);
$sql = "SELECT COUNT(*) AS number_of_classes FROM $tbl_class";
if (isset ($_GET['keyword'])) {
$sql .= " WHERE (name LIKE '%".Database::escape_string(trim($_GET['keyword']))."%')";
}
$res = Database::query($sql);
$obj = Database::fetch_object($res);
return $obj->number_of_classes;
}
/**
* Gets the information about some classes.
* @param int $from
* @param int $number_of_items
* @param string $direction
*/
function get_class_data($from, $number_of_items, $column, $direction = 'ASC') {
$tbl_class_user = Database::get_main_table(TABLE_MAIN_CLASS_USER);
$tbl_class = Database :: get_main_table(TABLE_MAIN_CLASS);
$from = intval($from);
$number_of_items = intval($number_of_items);
$column = intval($column);
$direction = ($direction == 'ASC'?'ASC':'DESC');
$sql = "SELECT id AS col0, name AS col1, COUNT(user_id) AS col2, id AS col3
FROM $tbl_class
LEFT JOIN $tbl_class_user ON id=class_id ";
if (isset ($_GET['keyword'])) {
$sql .= " WHERE (name LIKE '%".Database::escape_string(trim($_GET['keyword']))."%')";
}
$sql .= " GROUP BY id,name ORDER BY col$column $direction LIMIT $from,$number_of_items";
$res = Database::query($sql);
$classes = array ();
while ($class = Database::fetch_row($res)) {
$classes[] = $class;
}
return $classes;
}
/**
* Filter for sortable table to display edit icons for class
*/
function modify_filter($class_id) {
$class_id = Security::remove_XSS($class_id);
$result = '<a href="class_information.php?id='.$class_id.'">'.Display::return_icon('synthese_view.gif', get_lang('Info')).'</a>';
$result .= ' <a href="class_edit.php?idclass='.$class_id.'">'.Display::return_icon('edit.png', get_lang('Edit')).'</a>';
$result .= ' <a href="subscribe_user2class.php?idclass='.$class_id.'">'.Display::return_icon('add_multiple_users.gif', get_lang('AddUsersToAClass')).'</a>';
$result .= ' <a href="class_list.php?action=delete_class&amp;class_id='.$class_id.'" onclick="javascript: if(!confirm('."'".addslashes(api_htmlentities(get_lang("ConfirmYourChoice"), ENT_QUOTES))."'".')) return false;">'.Display::return_icon('delete.png', get_lang('Delete')).'</a>';
return $result;
}
$tool_name = get_lang('ClassList');
$interbreadcrumb[] = array ('url' => 'index.php', 'name' => get_lang('PlatformAdmin'));
if (isset($_POST['action'])) {
switch ($_POST['action']) {
// Delete selected classes
case 'delete_classes' :
$classes = $_POST['class'];
if (count($classes) > 0) {
foreach ($classes as $index => $class_id) {
ClassManager :: delete_class($class_id);
}
$message = Display :: return_message(get_lang('ClassesDeleted'));
}
break;
}
}
if (isset($_GET['action'])) {
switch ($_GET['action']) {
case 'delete_class':
ClassManager :: delete_class($_GET['class_id']);
$message = Display :: return_message(get_lang('ClassDeleted'));
break;
case 'show_message':
$message = Display :: return_message(Security::remove_XSS(stripslashes($_GET['message'])));
break;
}
}
// Create a search-box
$form = new FormValidator('search_simple', 'get', '', '', null, false);
$renderer =& $form->defaultRenderer();
$renderer->setCustomElementTemplate('<span>{element}</span> ');
$form->addElement('text', 'keyword', get_lang('Keyword'));
$form->addElement('button', 'submit', get_lang('Search'));
$content .= $form->returnForm();
// Create the sortable table with class information
$table = new SortableTable('classes', 'get_number_of_classes', 'get_class_data', 1);
$table->set_additional_parameters(array('keyword' => $_GET['keyword']));
$table->set_header(0, '', false);
$table->set_header(1, get_lang('ClassName'));
$table->set_header(2, get_lang('NumberOfUsers'));
$table->set_header(3, '', false);
$table->set_column_filter(3, 'modify_filter');
$table->set_form_actions(array ('delete_classes' => get_lang('DeleteSelectedClasses')), 'class');
$content .= $table->return_table();
$actions .= Display::url(Display::return_icon('add.png', get_lang('Add'), array(), ICON_SIZE_MEDIUM), 'class_add.php');
$actions .= Display::url(Display::return_icon('import_csv.png', get_lang('AddUsersToAClass'), array(), ICON_SIZE_MEDIUM), 'class_user_import.php');
$actions .= Display::url(Display::return_icon('import_csv.png', get_lang('ImportClassListCSV'), array(), ICON_SIZE_MEDIUM), 'class_import.php');
$tpl = new Template($tool_name);
$tpl->assign('content', $content);
$tpl->assign('actions', $actions);
$tpl->assign('message', $message);
$tpl->display_one_col_template();

@ -1,189 +0,0 @@
<?php
/* For licensing terms, see /license.txt */
/**
* @package chamilo.admin
*/
/**
* Code
* This tool allows platform admins to update class-user relations by uploading
* a CSVfile
*/
/**
* Validates imported data.
*/
function validate_users_data($user_classes) {
global $purification_option_for_usernames;
$errors = array ();
$classcodes = array ();
if (!isset($_POST['subscribe']) && !isset($_POST['subscribe'])) {
$user_class['error'] = get_lang('SelectAnAction');
$errors[] = $user_class;
return $errors;
}
foreach ($user_classes as $index => $user_class) {
$user_class['line'] = $index + 1;
// 1. Check whether mandatory fields are set.
$mandatory_fields = array ('UserName', 'ClassName');
foreach ($mandatory_fields as $key => $field) {
if (!isset ($user_class[$field]) || strlen($user_class[$field]) == 0) {
$user_class['error'] = get_lang($field.'Mandatory');
$errors[] = $user_class;
}
}
// 2. Check whether classcode exists.
if (isset ($user_class['ClassName']) && strlen($user_class['ClassName']) != 0) {
// 2.1 Check whether code has been allready used in this CVS-file.
if (!isset ($classcodes[$user_class['ClassName']])) {
// 2.1.1 Check whether code exists in DB.
$class_table = Database :: get_main_table(TABLE_MAIN_CLASS);
$sql = "SELECT * FROM $class_table WHERE name = '".Database::escape_string($user_class['ClassName'])."'";
$res = Database::query($sql);
if (Database::num_rows($res) == 0) {
$user_class['error'] = get_lang('CodeDoesNotExists').': '.$user_class['ClassName'];
$errors[] = $user_class;
} else {
$classcodes[$user_class['CourseCode']] = 1;
}
}
}
// 3. Check username, first, check whether it is empty.
if (!UserManager::is_username_empty($user_class['UserName'])) {
// 3.1. Check whether username is too long.
if (UserManager::is_username_too_long($user_class['UserName'])) {
$user_class['error'] = get_lang('UserNameTooLong').': '.$user_class['UserName'];
$errors[] = $user_class;
}
$username = UserManager::purify_username($user_class['UserName'], $purification_option_for_usernames);
// 3.2. Check whether username exists.
if (UserManager::is_username_available($username)) {
$user_class['error'] = get_lang('UnknownUser').': '.$username;
$errors[] = $user_class;
}
}
}
return $errors;
}
/**
* Saves imported data.
*/
function save_users_data($users_classes) {
global $purification_option_for_usernames;
// Table definitions.
$user_table = Database :: get_main_table(TABLE_MAIN_USER);
$class_user_table = Database :: get_main_table(TABLE_MAIN_CLASS_USER);
$class_table = Database :: get_main_table(TABLE_MAIN_CLASS);
// Data parsing: purification + conversion (UserName, ClassName) --> (user_is, class_id)
$csv_data = array ();
foreach ($users_classes as $index => $user_class) {
$sql1 = "SELECT user_id FROM $user_table WHERE username = '".Database::escape_string(UserManager::purify_username($user_class['UserName'], $purification_option_for_usernames))."'";
$res1 = Database::query($sql1);
$obj1 = Database::fetch_object($res1);
$sql2 = "SELECT id FROM $class_table WHERE name = '".Database::escape_string(trim($user_class['ClassName']))."'";
$res2 = Database::query($sql2);
$obj2 = Database::fetch_object($res2);
if ($obj1 && $obj2) {
$csv_data[$obj1->user_id][$obj2->id] = 1;
}
}
// Logic for processing the request (data + UI options).
$db_subscriptions = array();
foreach ($csv_data as $user_id => $csv_subscriptions) {
$sql = "SELECT class_id FROM $class_user_table cu WHERE cu.user_id = $user_id";
$res = Database::query($sql);
while ($obj = Database::fetch_object($res)) {
$db_subscriptions[$obj->class_id] = 1;
}
$to_subscribe = array_diff(array_keys($csv_subscriptions), array_keys($db_subscriptions));
$to_unsubscribe = array_diff(array_keys($db_subscriptions), array_keys($csv_subscriptions));
// Subscriptions for new classes.
if ($_POST['subscribe']) {
foreach ($to_subscribe as $class_id) {
ClassManager::add_user($user_id, $class_id);
}
}
// Unsubscription from previous classes.
if ($_POST['unsubscribe']) {
foreach ($to_unsubscribe as $class_id) {
ClassManager::unsubscribe_user($user_id, $class_id);
}
}
}
}
/**
* Reads a CSV-file.
* @param string $file Path to the CSV-file
* @return array All course-information read from the file
*/
function parse_csv_data($file) {
$courses = Import::csvToArray($file);
return $courses;
}
$cidReset = true;
require_once '../inc/global.inc.php';
$this_section = SECTION_PLATFORM_ADMIN;
api_protect_admin_script(true);
$tool_name = get_lang('AddUsersToAClass').' CSV';
$interbreadcrumb[] = array ('url' => 'index.php', 'name' => get_lang('PlatformAdmin'));
$interbreadcrumb[] = array ('url' => 'class_list.php', 'name' => get_lang('Classes'));
// Set this option to true to enforce strict purification for usenames.
$purification_option_for_usernames = false;
set_time_limit(0);
$form = new FormValidator('class_user_import');
$form->addElement('file', 'import_file', get_lang('ImportFileLocation'));
$form->addElement('checkbox', 'subscribe', get_lang('Action'), get_lang('SubscribeUserIfNotAllreadySubscribed'));
$form->addElement('checkbox', 'unsubscribe', '', get_lang('UnsubscribeUserIfSubscriptionIsNotInFile'));
$form->addButtonImport(get_lang('Import'));
if ($form->validate()) {
$users_classes = parse_csv_data($_FILES['import_file']['tmp_name']);
$errors = validate_users_data($users_classes);
if (count($errors) == 0) {
save_users_data($users_classes);
header('Location: class_list.php?action=show_message&message='.urlencode(get_lang('FileImported')));
exit();
}
}
Display :: display_header($tool_name);
api_display_tool_title($tool_name);
if (count($errors) != 0) {
$error_message = "\n";
foreach ($errors as $index => $error_class_user) {
$error_message .= get_lang('Line').' '.$error_class_user['line'].': '.$error_class_user['error'].'</b>';
$error_message .= "<br />";
}
$error_message .= "\n";
Display :: display_error_message($error_message, false);
}
$form->display();
?>
<p><?php echo get_lang('CSVMustLookLike').' ('.get_lang('MandatoryFields').')'; ?> :</p>
<pre>
<b>UserName</b>;<b>ClassName</b>
jdoe;class01
adam;class01
</pre>
<?php
Display :: display_footer();

@ -1,150 +0,0 @@
<?php
/* For licensing terms, see /license.txt */
/**
* @package chamilo.admin
*/
/**
* Code
*/
$cidReset = true;
require_once '../inc/global.inc.php';
$this_section=SECTION_PLATFORM_ADMIN;
api_protect_admin_script();
$classes = $_GET['classes'];
$form_sent = 0;
$error_message = '';
$first_letter_class = '';
$first_letter_course = '';
$courses = array ();
$classes = array();
$tbl_course = Database :: get_main_table(TABLE_MAIN_COURSE);
$tbl_class = Database :: get_main_table(TABLE_MAIN_CLASS);
$tool_name = get_lang('AddClassesToACourse');
$interbreadcrumb[] = array ("url" => 'index.php', "name" => get_lang('PlatformAdmin'));
Display :: display_header($tool_name);
//api_display_tool_title($tool_name);
if ($_POST['formSent'])
{
$form_sent = $_POST['formSent'];
$classes = is_array($_POST['ClassList']) ? $_POST['ClassList'] : array();
$courses = is_array($_POST['CourseList']) ? $_POST['CourseList'] : array();
$first_letter_class = $_POST['firstLetterClass'];
$first_letter_course = $_POST['firstLetterCourse'];
if ($form_sent == 1)
{
if (count($classes) == 0 || count($courses) == 0)
{
Display::display_error_message(get_lang('AtLeastOneClassAndOneCourse'));
}
elseif (api_substr($_POST['formSubmit'], -2) == '>>') // add classes to courses
{
foreach ($courses as $course_code)
{
foreach ($classes as $class_id)
{
ClassManager :: subscribe_to_course($class_id, $course_code);
}
}
Display::display_normal_message(get_lang('ClassesSubscribed'));
} else {// remove classes from courses
foreach ($courses as $course_code) {
foreach ($classes as $class_id) {
ClassManager :: unsubscribe_from_course($class_id, $course_code);
}
}
Display::display_normal_message(get_lang('ClassesUnSubscribed'));
}
}
}
$sql = "SELECT id,name FROM $tbl_class WHERE name LIKE '".$first_letter_class."%' ORDER BY ". (count($classes) > 0 ? "(id IN('".implode("','", $classes)."')) DESC," : "")." name";
$result = Database::query($sql);
$db_classes = Database::store_result($result);
$sql = "SELECT code,visual_code,title FROM $tbl_course WHERE visual_code LIKE '".$first_letter_course."%' ORDER BY ". (count($courses) > 0 ? "(code IN('".implode("','", $courses)."')) DESC," : "")." visual_code";
$result = Database::query($sql);
$db_courses = Database::store_result($result);
if (!empty ($error_message))
{
Display :: display_normal_message($error_message);
}
?>
<form name="formulaire" method="post" action="<?php echo api_get_self(); ?>" style="margin:0px;">
<input type="hidden" name="formSent" value="1"/>
<table border="0" cellpadding="5" cellspacing="0" width="100%">
<tr>
<td width="40%" align="center">
<b><?php echo get_lang('ClassList'); ?></b>
<br/><br/>
<?php echo get_lang('FirstLetterClass'); ?> :
<select name="firstLetterClass" onchange="javascript:document.formulaire.formSent.value='2'; document.formulaire.submit();">
<option value="">--</option>
<?php
echo Display::get_alphabet_options($first_letter_class);
?>
</select>
</td>
<td width="20%">&nbsp;</td>
<td width="40%" align="center">
<b><?php echo get_lang('CourseList'); ?> :</b>
<br/><br/>
<?php echo get_lang('FirstLetterCourse'); ?> :
<select name="firstLetterCourse" onchange="javascript:document.formulaire.formSent.value='2'; document.formulaire.submit();">
<option value="">--</option>
<?php
echo Display::get_alphabet_options($first_letter_course);
?>
</select>
</td>
</tr>
<tr>
<td width="40%" align="center">
<select name="ClassList[]" multiple="multiple" size="20" style="width:230px;">
<?php
foreach ($db_classes as $class)
{
?>
<option value="<?php echo $class['id']; ?>" <?php if(in_array($class['id'],$classes)) echo 'selected="selected"'; ?>><?php echo $class['name']; ?></option>
<?php
}
?>
</select>
</td>
<td width="20%" valign="middle" align="center">
<input type="submit" name="formSubmit" value="<?php echo get_lang('AddToThatCourse'); ?> &gt;&gt;"/>
<br/>
<input type="submit" name="formSubmit" value="&lt;&lt; <?php echo get_lang('DeleteSelectedClasses'); ?>"/>
</td>
<td width="40%" align="center">
<select name="CourseList[]" multiple="multiple" size="20" style="width:230px;">
<?php
foreach ($db_courses as $course)
{
?>
<option value="<?php echo $course['code']; ?>" <?php if(in_array($course['code'],$courses)) echo 'selected="selected"'; ?>><?php echo '('.$course['visual_code'].') '.$course['title']; ?></option>
<?php
}
?>
</select>
</td>
</tr>
</table>
</form>
<?php
/*
==============================================================================
FOOTER
==============================================================================
*/
Display :: display_footer();
?>

@ -1,151 +0,0 @@
<?php
/* For licensing terms, see /license.txt */
/**
* @package chamilo.admin
*/
/**
* Code
*/
$cidReset = true;
require_once '../inc/global.inc.php';
$this_section = SECTION_PLATFORM_ADMIN;
api_protect_admin_script();
$course = $_GET['course'];
$class_id = intval($_GET['idclass']);
$form_sent = 0;
$error_message = '';
$first_letter_left = '';
$first_letter_right = '';
$left_user_list = array();
$right_user_list = array();
// Database table definitions
$tbl_class = Database :: get_main_table(TABLE_MAIN_CLASS);
$tbl_class_user = Database :: get_main_table(TABLE_MAIN_CLASS_USER);
$tbl_user = Database :: get_main_table(TABLE_MAIN_USER);
$sql = "SELECT name FROM $tbl_class WHERE id='$class_id'";
$result = Database::query($sql);
if (!list ($class_name) = Database::fetch_row($result)) {
header('Location: class_list.php?filtreCours=' . urlencode($course));
exit();
}
$noPHP_SELF = true;
$tool_name = get_lang('AddUsersToAClass') . ' (' . $class_name . ')';
$interbreadcrumb[] = array("url" => 'index.php', "name" => get_lang('PlatformAdmin'));
$interbreadcrumb[] = array("url" => "class_list.php?filtreCours=" . urlencode($course), "name" => get_lang('AdminClasses'));
if ($_POST['formSent']) {
$form_sent = $_POST['formSent'];
$first_letter_left = $_POST['firstLetterLeft'];
$first_letter_right = $_POST['firstLetterRight'];
$left_user_list = is_array($_POST['LeftUserList']) ? $_POST['LeftUserList'] : array();
$right_user_list = is_array($_POST['RightUserList']) ? $_POST['RightUserList'] : array();
$add_to_class = empty($_POST['addToClass']) ? 0 : 1;
$remove_from_class = empty($_POST['removeFromClass']) ? 0 : 1;
if ($form_sent == 1) {
if ($add_to_class) {
if (count($left_user_list) == 0) {
$error_message = get_lang('AtLeastOneUser');
} else {
foreach ($left_user_list as $user_id) {
ClassManager :: add_user($user_id, $class_id);
}
header('Location: class_list.php?filtreCours=' . urlencode($course));
exit();
}
} elseif ($remove_from_class) {
if (count($right_user_list) == 0)
$error_message = get_lang('AtLeastOneUser');
else {
foreach ($right_user_list as $index => $user_id) {
ClassManager :: unsubscribe_user($user_id, $class_id);
}
header('Location: class_list.php?filtreCours=' . urlencode($course));
exit();
}
}
}
}
Display :: display_header($tool_name);
//api_display_tool_title($tool_name);
$target_name = api_sort_by_first_name() ? 'firstname' : 'lastname';
$sql = "SELECT u.user_id,lastname,firstname,username FROM $tbl_user u LEFT JOIN $tbl_class_user cu ON u.user_id=cu.user_id AND class_id='$class_id' WHERE " . $target_name . " LIKE '" . $first_letter_left . "%' AND class_id IS NULL ORDER BY " . (count($left_user_list) > 0 ? "(user_id IN(" . implode(',', $left_user_list) . ")) DESC," : "") . " " . $target_name;
$result = Database::query($sql);
$left_users = Database::store_result($result);
$sql = "SELECT u.user_id,lastname,firstname,username FROM $tbl_user u,$tbl_class_user cu WHERE cu.user_id=u.user_id AND class_id='$class_id' AND " . $target_name . " LIKE '" . $first_letter_right . "%' ORDER BY " . (count($right_user_list) > 0 ? "(user_id IN(" . implode(',', $right_user_list) . ")) DESC," : "") . " " . $target_name;
$result = Database::query($sql);
$right_users = Database::store_result($result);
if (!empty($error_message)) {
Display :: display_normal_message($error_message);
}
?>
<form name="formulaire" method="post" action="<?php echo api_get_self(); ?>?course=<?php echo urlencode($course); ?>&amp;idclass=<?php echo $class_id; ?>" style="margin:0px;">
<input type="hidden" name="formSent" value="1"/>
<table border="0" cellpadding="5" cellspacing="0" width="100%">
<tr>
<td width="40%" align="center">
<b><?php echo get_lang('UsersOutsideClass'); ?> :</b>
<br/><br/>
<?php echo get_lang('FirstLetterUser'); ?> :
<select name="firstLetterLeft" onchange="javascript:document.formulaire.formSent.value='2'; document.formulaire.submit();">
<option value="">--</option>
<?php
echo Display :: get_alphabet_options($first_letter_left);
?>
</select>
</td>
<td width="20%">&nbsp;</td>
<td width="40%" align="center">
<b><?php echo get_lang('UsersInsideClass'); ?> :</b>
<br/><br/>
<?php echo get_lang('FirstLetterUser'); ?> :
<select name="firstLetterRight" onchange="javascript:document.formulaire.formSent.value='2'; document.formulaire.submit();">
<option value="">--</option>
<?php
echo Display :: get_alphabet_options($first_letter_right);
?>
</select>
</td>
</tr>
<tr>
<td width="40%" align="center">
<select name="LeftUserList[]" multiple="multiple" size="20" style="width:230px;">
<?php
foreach ($left_users as $user) {
?>
<option value="<?php echo $user['user_id']; ?>" <?php if (in_array($user['user_id'], $left_user_list)) echo 'selected="selected"'; ?>><?php echo api_get_person_name($user['firstname'], $user['lastname']) . ' (' . $user['username'] . ')'; ?></option>
<?php
}
?>
</select>
</td>
<td width="20%" valign="middle" align="center">
<input type="submit" name="addToClass" value="<?php echo get_lang('AddToClass'); ?> &gt;&gt;"/>
<br/><br/>
<input type="submit" name="removeFromClass" value="&lt;&lt; <?php echo get_lang('RemoveFromClass'); ?>"/>
</td>
<td width="40%" align="center">
<select name="RightUserList[]" multiple="multiple" size="20" style="width:230px;">
<?php
foreach ($right_users as $user) {
?>
<option value="<?php echo $user['user_id']; ?>" <?php if (in_array($user['user_id'], $right_user_list)) echo 'selected="selected"'; ?>><?php echo api_get_person_name($user['firstname'], $user['lastname']) . ' (' . $user['username'] . ')'; ?></option>
<?php
}
?>
</select>
</td>
</tr>
</table>
</form>
<?php
Display :: display_footer();

@ -1,226 +0,0 @@
<?php
/* For licensing terms, see /license.txt */
/**
* Class ClassManager
*/
class ClassManager
{
/**
* Get class information
* note: This function can't be named get_class() because that's a standard
* php-function.
*/
public static function get_class_info($class_id) {
$class_id = intval($class_id);
$table_class = Database :: get_main_table(TABLE_MAIN_CLASS);
$sql = "SELECT * FROM $table_class WHERE id='".$class_id."'";
$res = Database::query($sql);
return Database::fetch_array($res, 'ASSOC');
}
/**
* Change the name of a class
* @param string $name The new name
* @param int $class_id The class id
*/
public static function set_name($name, $class_id) {
$class_id = intval($class_id);
$table_class = Database :: get_main_table(TABLE_MAIN_CLASS);
$sql = "UPDATE $table_class SET name='".Database::escape_string($name)."' WHERE id='".$class_id."'";
$res = Database::query($sql);
}
/**
* Create a class
* @param string $name
*/
public static function create_class($name)
{
$table_class = Database :: get_main_table(TABLE_MAIN_CLASS);
$sql = "INSERT INTO $table_class SET name='".Database::escape_string($name)."'";
$result = Database::query($sql);
return Database::affected_rows($result) == 1;
}
/**
* Check if a classname is allready in use
* @param string $name
*/
public static function class_name_exists($name) {
$table_class = Database :: get_main_table(TABLE_MAIN_CLASS);
$sql = "SELECT * FROM $table_class WHERE name='".Database::escape_string($name)."'";
$res = Database::query($sql);
return Database::num_rows($res) != 0;
}
/**
* Delete a class
* @param int $class_id
* @todo Add option to unsubscribe class-members from the courses where the
* class was subscibed to
*/
public static function delete_class($class_id) {
$class_id = intval($class_id);
$table_class = Database :: get_main_table(TABLE_MAIN_CLASS);
$table_class_course = Database :: get_main_table(TABLE_MAIN_COURSE_CLASS);
$table_class_user = Database :: get_main_table(TABLE_MAIN_CLASS_USER);
$sql = "DELETE FROM $table_class_user WHERE class_id = '".$class_id."'";
Database::query($sql);
$sql = "DELETE FROM $table_class_course WHERE class_id = '".$class_id."'";
Database::query($sql);
$sql = "DELETE FROM $table_class WHERE id = '".$class_id."'";
Database::query($sql);
}
/**
* Get all users from a class
* @param int $class_id
* @return array
*/
public static function get_users($class_id) {
$class_id = intval($class_id);
$table_class_user = Database :: get_main_table(TABLE_MAIN_CLASS_USER);
$table_user = Database :: get_main_table(TABLE_MAIN_USER);
$sql = "SELECT * FROM $table_class_user cu, $table_user u WHERE cu.class_id = '".$class_id."' AND cu.user_id = u.user_id";
$res = Database::query($sql);
$users = array ();
while ($user = Database::fetch_array($res, 'ASSOC')) {
$users[] = $user;
}
return $users;
}
/**
* Add a user to a class. If the class is subscribed to a course, the new
* user will also be subscribed to that course.
* @param int $user_id The user id
* @param int $class_id The class id
*/
public static function add_user($user_id, $class_id) {
$table_class_user = Database :: get_main_table(TABLE_MAIN_CLASS_USER);
$user_id = intval($user_id);
$class_id = intval($class_id);
$sql = "INSERT IGNORE INTO $table_class_user SET user_id = '".$user_id."', class_id='".$class_id."'";
Database::query($sql);
$courses = ClassManager :: get_courses($class_id);
foreach ($courses as $index => $course) {
CourseManager :: subscribe_user($user_id, $course['course_code']);
}
}
/**
* Unsubscribe a user from a class. If the class is also subscribed in a
* course, the user will be unsubscribed from that course
* @param int $user_id The user id
* @param int $class_id The class id
*/
public static function unsubscribe_user($user_id, $class_id) {
$class_id = intval($class_id);
$user_id = intval($user_id);
$table_class_user = Database :: get_main_table(TABLE_MAIN_CLASS_USER);
$table_course_class = Database :: get_main_table(TABLE_MAIN_COURSE_CLASS);
$courses = ClassManager :: get_courses($class_id);
if (count($courses) != 0) {
$course_codes = array ();
foreach ($courses as $index => $course) {
$course_codes[] = $course['course_code'];
$sql = "SELECT DISTINCT user_id FROM $table_class_user t1, $table_course_class t2 WHERE t1.class_id=t2.class_id AND course_code = '".$course['course_code']."' AND user_id = $user_id AND t2.class_id<>'$class_id'";
$res = Database::query($sql);
if (Database::num_rows($res) == 0 && CourseManager :: get_user_in_course_status($user_id, $course['course_code']) == STUDENT)
{
CourseManager :: unsubscribe_user($user_id, $course['course_code']);
}
}
}
$sql = "DELETE FROM $table_class_user WHERE user_id='".$user_id."' AND class_id = '".$class_id."'";
Database::query($sql);
}
/**
* Get all courses in which a class is subscribed
* @param int $class_id
* @return array
*/
public static function get_courses($class_id) {
$class_id = intval($class_id);
$table_class_course = Database :: get_main_table(TABLE_MAIN_COURSE_CLASS);
$table_course = Database :: get_main_table(TABLE_MAIN_COURSE);
$sql = "SELECT * FROM $table_class_course cc, $table_course c WHERE cc.class_id = '".$class_id."' AND cc.course_code = c.code";
$res = Database::query($sql);
$courses = array ();
while ($course = Database::fetch_array($res, 'ASSOC')) {
$courses[] = $course;
}
return $courses;
}
/**
* Subscribe all members of a class to a course
* @param int $class_id The class id
* @param string $course_code The course code
*/
public static function subscribe_to_course($class_id, $course_code)
{
$tbl_course_class = Database :: get_main_table(TABLE_MAIN_COURSE_CLASS);
$tbl_class_user = Database :: get_main_table(TABLE_MAIN_CLASS_USER);
$sql = "INSERT IGNORE INTO $tbl_course_class SET course_code = '".Database::escape_string($course_code)."', class_id = '".Database::escape_string($class_id)."'";
Database::query($sql);
$sql = "SELECT user_id FROM $tbl_class_user WHERE class_id = '".intval($class_id)."'";
$res = Database::query($sql);
while ($user = Database::fetch_object($res)) {
CourseManager :: subscribe_user($user->user_id, $course_code);
}
}
/**
* Unsubscribe a class from a course.
* Only students are unsubscribed. If a user is member of 2 classes which
* are both subscribed to the course, the user stays in the course.
* @param int $class_id The class id
* @param string $course_code The course code
*/
public static function unsubscribe_from_course($class_id, $course_code)
{
$tbl_course_class = Database :: get_main_table(TABLE_MAIN_COURSE_CLASS);
$tbl_class_user = Database :: get_main_table(TABLE_MAIN_CLASS_USER);
$sql = "SELECT cu.user_id,COUNT(cc.class_id) FROM $tbl_course_class cc, $tbl_class_user cu WHERE cc.class_id = cu.class_id AND cc.course_code = '".Database::escape_string($course_code)."' GROUP BY cu.user_id HAVING COUNT(cc.class_id) = 1";
$single_class_users = Database::query($sql);
while ($single_class_user = Database::fetch_object($single_class_users))
{
$sql = "SELECT * FROM $tbl_class_user WHERE class_id = '".intval($class_id)."' AND user_id = '".Database::escape_string($single_class_user->user_id)."'";
$res = Database::query($sql);
if (Database::num_rows($res) > 0)
{
if (CourseManager :: get_user_in_course_status($single_class_user->user_id, $course_code) == STUDENT)
{
CourseManager :: unsubscribe_user($single_class_user->user_id, $course_code);
}
}
}
$sql = "DELETE FROM $tbl_course_class WHERE course_code = '".Database::escape_string($course_code)."' AND class_id = '".Database::escape_string($class_id)."'";
Database::query($sql);
}
/**
* Get the class-id
* @param string $name The class name
* @return int the ID of the class
*/
public static function get_class_id($name) {
$name = Database::escape_string($name);
$table_class = Database :: get_main_table(TABLE_MAIN_CLASS);
$sql = "SELECT * FROM $table_class WHERE name='".$name."'";
$res = Database::query($sql);
$obj = Database::fetch_object($res);
return $obj->id;
}
/**
* Get all classes subscribed in a course
* @param string $course_code
* @return array An array with all classes (keys: 'id','code','name')
*/
public static function get_classes_in_course($course_code) {
$table_class = Database :: get_main_table(TABLE_MAIN_CLASS);
$table_course_class = Database :: get_main_table(TABLE_MAIN_COURSE_CLASS);
$sql = "SELECT cl.* FROM $table_class cl, $table_course_class cc WHERE cc.course_code = '".Database::escape_string($course_code)."' AND cc.class_id = cl.id";
$res = Database::query($sql);
$classes = array ();
while ($class = Database::fetch_array($res, 'ASSOC')) {
$classes[] = $class;
}
return $classes;
}
}

@ -1,146 +0,0 @@
<?php
/* For licensing terms, see /license.txt */
/**
* @package chamilo.user
*/
include ('../inc/global.inc.php');
$this_section = SECTION_COURSES;
if (!api_is_allowed_to_edit()) {
api_not_allowed();
exit;
}
$tool_name = get_lang("AddClassesToACourse");
//extra entries in breadcrumb
$interbreadcrumb[] = array("url" => "user.php", "name" => get_lang("ToolUser"));
$interbreadcrumb[] = array("url" => "class.php", "name" => get_lang("Classes"));
Display :: display_header($tool_name, "User");
echo Display::page_header($tool_name);
if (isset($_GET['register'])) {
ClassManager::subscribe_to_course($_GET['class_id'], $_course['sysCode']);
Display::display_normal_message(get_lang('ClassesSubscribed'));
}
if (isset($_POST['action'])) {
switch ($_POST['action']) {
case 'subscribe' :
if (is_array($_POST['class'])) {
foreach ($_POST['class'] as $index => $class_id) {
ClassManager::subscribe_to_course($class_id, $_course['sysCode']);
}
Display::display_normal_message(get_lang('ClassesSubscribed'));
}
break;
}
}
/*
SHOW LIST OF USERS
*/
/**
* * Get the number of classes to display on the current page.
*/
function get_number_of_classes()
{
$class_table = Database :: get_main_table(TABLE_MAIN_CLASS);
$course_class_table = Database :: get_main_table(TABLE_MAIN_COURSE_CLASS);
$courseCode = api_get_course_id();
$sql = "SELECT * FROM $course_class_table
WHERE course_code = '" . $courseCode. "'";
$res = Database::query($sql);
$subscribed_classes = array();
while ($obj = Database::fetch_object($res)) {
$subscribed_classes[] = $obj->class_id;
}
$sql = "SELECT c.id FROM $class_table c WHERE 1 = 1";
if (isset($_GET['keyword'])) {
$keyword = Database::escape_string(trim($_GET['keyword']));
$sql .= " AND (c.name LIKE '%" . $keyword . "%')";
}
if (count($subscribed_classes) > 0) {
$sql .= " AND c.id NOT IN ('" . implode("','", $subscribed_classes) . "')";
}
$res = Database::query($sql);
$result = Database::num_rows($res);
return $result;
}
/**
* Get the classes to display on the current page.
*/
function get_class_data($from, $number_of_items, $column, $direction)
{
$class_table = Database :: get_main_table(TABLE_MAIN_CLASS);
$course_class_table = Database :: get_main_table(TABLE_MAIN_COURSE_CLASS);
$class_user_table = Database :: get_main_table(TABLE_MAIN_CLASS_USER);
$courseCode = api_get_course_id();
$sql = "SELECT * FROM $course_class_table WHERE course_code = '" . $courseCode . "'";
$res = Database::query($sql);
$subscribed_classes = array();
while ($obj = Database::fetch_object($res)) {
$subscribed_classes[] = $obj->class_id;
}
$sql = "SELECT
c.id AS col0,
c.name AS col1,
COUNT(cu.user_id) AS col2,
c.id AS col3
FROM $class_table c ";
$sql .= " LEFT JOIN $class_user_table cu ON cu.class_id = c.id";
$sql .= " WHERE 1 = 1";
if (isset($_GET['keyword'])) {
$keyword = Database::escape_string(trim($_GET['keyword']));
$sql .= " AND (c.name LIKE '%" . $keyword . "%')";
}
if (count($subscribed_classes) > 0) {
$sql .= " AND c.id NOT IN ('" . implode("','", $subscribed_classes) . "')";
}
$sql .= " GROUP BY c.id, c.name ";
$sql .= " ORDER BY col$column $direction ";
$sql .= " LIMIT $from,$number_of_items";
$res = Database::query($sql);
$classes = array();
while ($class = Database::fetch_row($res)) {
$classes[] = $class;
}
return $classes;
}
/**
* Build the reg-column of the table
* @param int $class_id The class id
* @return string Some HTML-code
*/
function reg_filter($class_id) {
$result = "<a href=\"" . api_get_self() . "?register=yes&amp;class_id=" . $class_id . "\">" . get_lang("reg") . "</a>";
return $result;
}
// Build search-form
$form = new FormValidator('search_class', 'get', '', '', null, false);
$form->addText('keyword', '', false);
$form->addButtonSearch(get_lang('SearchButton'));
// Build table
$table = new SortableTable('users', 'get_number_of_classes', 'get_class_data', 1);
$parameters['keyword'] = Security::remove_XSS($_GET['keyword']);
$table->set_additional_parameters($parameters);
$col = 0;
$table->set_header($col++, '', false);
$table->set_header($col++, get_lang('ClassName'));
$table->set_header($col++, get_lang('NumberOfUsers'));
$table->set_header($col++, get_lang('reg'), false);
$table->set_column_filter($col - 1, 'reg_filter');
$table->set_form_actions(array('subscribe' => get_lang('reg')), 'class');
// Display form & table
$form->display();
$table->display();
Display :: display_footer();

@ -43,13 +43,6 @@ function validate_data($users) {
$user['error'] = get_lang('WrongStatus');
$errors[] = $user;
}
// 4. Check classname.
if (isset ($user['ClassName']) && strlen($user['ClassName']) != 0) {
if (!ClassManager :: class_name_exists($user['ClassName'])) {
$user['error'] = get_lang('ClassNameNotAvailable');
$errors[] = $user;
}
}
// 5. Check authentication source.
if (isset ($user['AuthSource']) && strlen($user['AuthSource']) != 0) {
if (!in_array($user['AuthSource'], $defined_auth_sources)) {
@ -101,10 +94,6 @@ function save_data($users) {
if(CourseManager :: course_exists($course))
CourseManager :: subscribe_user($user_id, $course,$user['Status']);
}
if (strlen($user['ClassName']) > 0) {
$class_id = ClassManager :: get_class_id($user['ClassName']);
ClassManager :: add_user($user_id, $class_id);
}
// TODO: Hard-coded French texts.

@ -1,94 +0,0 @@
<?php
require_once(api_get_path(LIBRARY_PATH).'classmanager.lib.php');
class TestClassManager extends UnitTestCase {
public function __construct(){
$this->UnitTestCase('Class (students) manager library - main/inc/lib/classmanager.lib.test.php');
}
function testAddUser() {
$user_id='1';
$class_id='1';
$res=ClassManager::add_user($user_id, $class_id);
$this->assertNull($res);
$this->assertTrue(is_null($res));
}
function testclass_name_exists() {
$name='arthur';
$res=ClassManager::class_name_exists($name);
$this->assertTrue(is_bool($res));
}
function testCreateClass() {
$name='new class';
$res=ClassManager::create_class($name);
$this->assertTrue(is_bool($res));
}
function testDeleteClass() {
$class_id='new class';
$res=ClassManager::delete_class($class_id);
$this->assertTrue(is_null($res));
}
function testGetClassId() {
$name='new class';
$res=ClassManager::get_class_id($name);
$this->assertTrue(is_numeric($res));
}
function testGetClassInfo() {
$class_id='1';
$res=ClassManager::get_class_info($class_id);
$this->assertTrue(is_array($res));
}
function testGetClassesInCourse() {
$course_code='FDI';
$res=ClassManager::get_classes_in_course($course_code);
$this->assertTrue(is_array($res));
}
function testGetCourses() {
$class_id='1';
$res=ClassManager::get_courses($class_id);
$this->assertTrue(is_array($res));
}
function testGetUsers() {
$class_id='1';
$res=ClassManager::get_users($class_id);
$this->assertTrue(is_array($res));
}
function testSetName() {
$name='new class';
$class_id='1';
$res=ClassManager::set_name($name, $class_id);
$this->assertTrue(is_null($res));
}
function testSubscribeToCourse() {
$class_id='1';
$course_code='FDI';
$res=ClassManager::subscribe_to_course($class_id,$course_code);
$this->assertTrue(is_null($res));
}
function testUnsubscribeFromCourse() {
$class_id='1';
$course_code='FDI';
$res=ClassManager::unsubscribe_from_course($class_id, $course_code);
$this->assertTrue(is_null($res));
}
function testUnsubscribeUser() {
$user_id='1';
$class_id='1';
$res=ClassManager::unsubscribe_user($user_id, $class_id);
$this->assertTrue(is_null($res));
}
}
?>

@ -1,5 +1,4 @@
<?php
//require_once(api_get_path(LIBRARY_PATH).'classManager.lib.php');
class TestFileManager extends UnitTestCase {
public $fmanager;

@ -1,6 +1,4 @@
<?php
//require_once(api_get_path(LIBRARY_PATH).'classManager.lib.php');
class TestFileManager extends UnitTestCase {

@ -2,7 +2,6 @@
require_once(api_get_path(LIBRARY_PATH).'groupmanager.lib.php');
require_once(api_get_path(LIBRARY_PATH).'database.lib.php');
require_once(api_get_path(LIBRARY_PATH).'course.lib.php');
require_once(api_get_path(LIBRARY_PATH).'classmanager.lib.php');
require_once(api_get_path(LIBRARY_PATH).'fileUpload.lib.php');
require_once(api_get_path(LIBRARY_PATH).'fileManage.lib.php');
//require_once(api_get_path(LIBRARY_PATH).'tablesort.lib.php');moved to autoload

@ -2,7 +2,6 @@
require_once(api_get_path(SYS_CODE_PATH).'webservices/user_import/import.lib.php');
require_once(api_get_path(LIBRARY_PATH).'usermanager.lib.php');
require_once(api_get_path(LIBRARY_PATH).'import.lib.php');
require_once(api_get_path(LIBRARY_PATH).'classmanager.lib.php');
require_once(api_get_path(LIBRARY_PATH).'course.lib.php');

Loading…
Cancel
Save