Minor - Reformatted code to avoid warnings and consider code sniffer

1.9.x
Yannick Warnier 12 years ago
parent ad3e75dbdc
commit 1e993aca8e
  1. 67
      main/admin/user_import.php
  2. 410
      main/inc/lib/classmanager.lib.php

@ -2,7 +2,6 @@
/* For licensing terms, see /license.txt */ /* For licensing terms, see /license.txt */
/** /**
* This tool allows platform admins to add users by uploading a CSV or XML file * This tool allows platform admins to add users by uploading a CSV or XML file
* @todo Add some langvars to DLTT
* @package chamilo.admin * @package chamilo.admin
*/ */
@ -22,7 +21,8 @@ require_once api_get_path(LIBRARY_PATH).'import.lib.php';
// Set this option to true to enforce strict purification for usenames. // Set this option to true to enforce strict purification for usenames.
$purification_option_for_usernames = false; $purification_option_for_usernames = false;
function validate_data($users) { function validate_data($users)
{
global $defined_auth_sources; global $defined_auth_sources;
$errors = array(); $errors = array();
$usernames = array(); $usernames = array();
@ -85,7 +85,8 @@ function validate_data($users) {
/** /**
* Add missing user-information (which isn't required, like password, username etc). * Add missing user-information (which isn't required, like password, username etc).
*/ */
function complete_missing_data($user) { function complete_missing_data($user)
{
global $purification_option_for_usernames; global $purification_option_for_usernames;
// 1. Create a username if necessary. // 1. Create a username if necessary.
if (UserManager::is_username_empty($user['UserName'])) { if (UserManager::is_username_empty($user['UserName'])) {
@ -110,7 +111,7 @@ function complete_missing_data($user) {
/** /**
* Save the imported data * Save the imported data
* @param array List of users * @param array $users List of users
* @return void * @return void
* @uses global variable $inserted_in_course, which returns the list of courses the user was inserted in * @uses global variable $inserted_in_course, which returns the list of courses the user was inserted in
*/ */
@ -196,7 +197,8 @@ function save_data($users)
* @param string $file Path to the CSV-file * @param string $file Path to the CSV-file
* @return array All userinformation read from the file * @return array All userinformation read from the file
*/ */
function parse_csv_data($file) { function parse_csv_data($file)
{
$users = Import :: csv_to_array($file); $users = Import :: csv_to_array($file);
foreach ($users as $index => $user) { foreach ($users as $index => $user) {
if (isset ($user['Courses'])) { if (isset ($user['Courses'])) {
@ -208,30 +210,36 @@ function parse_csv_data($file) {
} }
/** /**
* XML-parser: handle start of element * XML-parser: handle start of element
* @param string $parser Deprecated?
* @param string $data The data to be parsed
*/ */
function element_start($parser, $data) { function element_start($parser, $data)
{
$data = api_utf8_decode($data); $data = api_utf8_decode($data);
global $user; global $user;
global $current_tag; global $current_tag;
switch ($data) { switch ($data) {
case 'Contact' : case 'Contact':
$user = array (); $user = array ();
break; break;
default : default:
$current_tag = $data; $current_tag = $data;
} }
} }
/** /**
* XML-parser: handle end of element * XML-parser: handle end of element
* @param string $parser Deprecated?
* @param string $data The data to be parsed
*/ */
function element_end($parser, $data) { function element_end($parser, $data)
{
$data = api_utf8_decode($data); $data = api_utf8_decode($data);
global $user; global $user;
global $users; global $users;
global $current_value; global $current_value;
switch ($data) { switch ($data) {
case 'Contact' : case 'Contact':
if ($user['Status'] == '5') { if ($user['Status'] == '5') {
$user['Status'] = STUDENT; $user['Status'] = STUDENT;
} }
@ -240,7 +248,7 @@ function element_end($parser, $data) {
} }
$users[] = $user; $users[] = $user;
break; break;
default : default:
$user[$data] = $current_value; $user[$data] = $current_value;
break; break;
} }
@ -248,8 +256,12 @@ function element_end($parser, $data) {
/** /**
* XML-parser: handle character data * XML-parser: handle character data
* @param string $parser Parser (deprecated?)
* @param string $data The data to be parsed
* @return void
*/ */
function character_data($parser, $data) { function character_data($parser, $data)
{
$data = trim(api_utf8_decode($data)); $data = trim(api_utf8_decode($data));
global $current_value; global $current_value;
$current_value = $data; $current_value = $data;
@ -258,12 +270,10 @@ function character_data($parser, $data) {
/** /**
* Read the XML-file * Read the XML-file
* @param string $file Path to the XML-file * @param string $file Path to the XML-file
* @return array All userinformation read from the file * @return array All user information read from the file
*/ */
function parse_xml_data($file) { function parse_xml_data($file)
global $current_tag; {
global $current_value;
global $user;
global $users; global $users;
$users = array(); $users = array();
$parser = xml_parser_create('UTF-8'); $parser = xml_parser_create('UTF-8');
@ -280,6 +290,7 @@ api_protect_admin_script(true, null, 'login');
$defined_auth_sources[] = PLATFORM_AUTH_SOURCE; $defined_auth_sources[] = PLATFORM_AUTH_SOURCE;
if (is_array($extAuthSource)) { if (is_array($extAuthSource)) {
$defined_auth_sources = array_merge($defined_auth_sources, array_keys($extAuthSource)); $defined_auth_sources = array_merge($defined_auth_sources, array_keys($extAuthSource));
} }
@ -292,7 +303,7 @@ $extra_fields = UserManager::get_extra_fields(0, 0, 5, 'ASC', true);
$user_id_error = array(); $user_id_error = array();
$error_message = ''; $error_message = '';
if ($_POST['formSent'] AND $_FILES['import_file']['size'] !== 0) { if ($_POST['formSent'] and $_FILES['import_file']['size'] !== 0) {
$file_type = $_POST['file_type']; $file_type = $_POST['file_type'];
Security::clear_token(); Security::clear_token();
$tok = Security::get_token(); $tok = Security::get_token();
@ -354,7 +365,9 @@ if ($_POST['formSent'] AND $_FILES['import_file']['size'] !== 0) {
$warning_message = '<ul>'; $warning_message = '<ul>';
foreach ($errors as $index => $error_user) { foreach ($errors as $index => $error_user) {
$warning_message .= '<li><b>'.$error_user['error'].'</b>: '; $warning_message .= '<li><b>'.$error_user['error'].'</b>: ';
$warning_message .= '<strong>'.$error_user['UserName'].'</strong>&nbsp;('.api_get_person_name($error_user['FirstName'], $error_user['LastName']).')'; $warning_message .=
'<strong>'.$error_user['UserName'].'</strong>&nbsp;('.
api_get_person_name($error_user['FirstName'], $error_user['LastName']).')';
$warning_message .= '</li>'; $warning_message .= '</li>';
} }
$warning_message .= '</ul>'; $warning_message .= '</ul>';
@ -384,8 +397,20 @@ $form->addElement('header', '', $tool_name);
$form->addElement('hidden', 'formSent'); $form->addElement('hidden', 'formSent');
$form->addElement('file', 'import_file', get_lang('ImportFileLocation')); $form->addElement('file', 'import_file', get_lang('ImportFileLocation'));
$group = array(); $group = array();
$group[] = $form->createElement('radio', 'file_type', '', 'CSV (<a href="example.csv" target="_blank">'.get_lang('ExampleCSVFile').'</a>)', 'csv'); $group[] = $form->createElement(
$group[] = $form->createElement('radio', 'file_type', null, 'XML (<a href="example.xml" target="_blank">'.get_lang('ExampleXMLFile').'</a>)', 'xml'); 'radio',
'file_type',
'',
'CSV (<a href="example.csv" target="_blank">'.get_lang('ExampleCSVFile').'</a>)',
'csv'
);
$group[] = $form->createElement(
'radio',
'file_type',
null,
'XML (<a href="example.xml" target="_blank">'.get_lang('ExampleXMLFile').'</a>)',
'xml'
);
$form->addGroup($group, '', get_lang('FileType'), '<br/>'); $form->addGroup($group, '', get_lang('FileType'), '<br/>');
$group = array(); $group = array();

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