diff --git a/main/admin/class_add.php b/main/admin/class_add.php index 92632dda45..0ca969e200 100644 --- a/main/admin/class_add.php +++ b/main/admin/class_add.php @@ -29,48 +29,43 @@ ============================================================================== */ -// name of the language file that needs to be included +// Language files that should be included. $language_file = 'admin'; -// resetting the course id +// Resetting the course id. $cidReset = true; -// including some necessary dokeos files -require_once('../inc/global.inc.php'); -require_once (api_get_path(LIBRARY_PATH).'classmanager.lib.php'); -require_once (api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php'); +// Including some necessary dokeos files. +require_once '../inc/global.inc.php'; +require_once api_get_path(LIBRARY_PATH).'classmanager.lib.php'; +require_once api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php'; -// setting the section (for the tabs) +// Setting the section (for the tabs). $this_section = SECTION_PLATFORM_ADMIN; -// Access restrictions +// Access restrictions. api_protect_admin_script(); -// setting breadcrumbs +// Setting breadcrumbs. $interbreadcrumb[] = array('url' => 'index.php', 'name' => get_lang('PlatformAdmin')); -// setting the name of the tool +// Setting the name of the tool. $tool_name = get_lang("AddClasses"); $form = new FormValidator('add_class'); -$form->add_textfield('name',get_lang('ClassName')); -$form->addElement('submit','submit',get_lang('Ok')); -if($form->validate()) -{ +$form->add_textfield('name', get_lang('ClassName')); +$form->addElement('style_submit_button', 'submit', get_lang('Ok'), 'class="add"'); +if ($form->validate()) { $values = $form->exportValues(); - ClassManager :: create_class($values['name']); + ClassManager::create_class($values['name']); header('Location: class_list.php'); } -// Displaying the header +// Displaying the header. Display :: display_header($tool_name); -// Displaying the form +// Displaying the form. $form->display(); -/* -============================================================================== - FOOTER -============================================================================== -*/ + +// Displaying the footer. Display :: display_footer(); -?> \ No newline at end of file diff --git a/main/admin/class_edit.php b/main/admin/class_edit.php index 231f046a35..98b2c80b79 100644 --- a/main/admin/class_edit.php +++ b/main/admin/class_edit.php @@ -29,37 +29,36 @@ ============================================================================== */ -// name of the language file that needs to be included +// Language files that should be included. $language_file = 'admin'; -// resetting the course id +// Resetting the course id. $cidReset = true; -// including some necessary dokeos files -include ('../inc/global.inc.php'); -require_once(api_get_path(LIBRARY_PATH).'classmanager.lib.php'); -require_once (api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php'); +// Including some necessary dokeos files. +include '../inc/global.inc.php'; +require_once api_get_path(LIBRARY_PATH).'classmanager.lib.php'; +require_once api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php'; -// setting the section (for the tabs) -$this_section=SECTION_PLATFORM_ADMIN; +// Setting the section (for the tabs). +$this_section = SECTION_PLATFORM_ADMIN; -// Access restrictions +// 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"); +// 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 = new FormValidator('edit_class', 'post', 'class_edit.php?idclass='.$class_id); $form->add_textfield('name',get_lang('ClassName')); -$form->addElement('submit','submit',get_lang('Ok')); +$form->addElement('style_submit_button', 'submit', get_lang('Ok'), 'class="add"'); $form->setDefaults(array('name'=>$class['name'])); if($form->validate()) { @@ -68,14 +67,9 @@ if($form->validate()) header('Location: class_list.php'); } - Display :: display_header($tool_name); //api_display_tool_title($tool_name); $form->display(); -/* -============================================================================== - FOOTER -============================================================================== -*/ + +// Displaying the footer. Display :: display_footer(); -?> \ No newline at end of file diff --git a/main/admin/class_import.php b/main/admin/class_import.php index b9f121fadd..6cc37427cc 100644 --- a/main/admin/class_import.php +++ b/main/admin/class_import.php @@ -30,100 +30,91 @@ * @package dokeos.admin ============================================================================== */ + /** - * Validate the imported data + * Validates imported data. */ -function validate_data($classes) -{ +function validate_data($classes) { $errors = array(); - foreach($classes as $index => $class) - { - //1. Check if ClassName is available - if(!isset($class['ClassName']) || strlen(trim($class['ClassName'])) == 0) - { - $class['line'] = $index+2; + 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 if class doesn't exist yet - else - { - if(ClassManager::class_name_exists($class['ClassName'])) - { - $class['line'] = $index+2; - $class['error'] = get_lang('ClassNameExists'); + // 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').' '.$class['ClassName'].''; $errors[] = $class; } } } return $errors; } + /** * Save imported class data to database */ -function save_data($classes) -{ +function save_data($classes) { $number_of_added_classes = 0; - foreach($classes as $index => $class) - { - if(ClassManager::create_class($class['ClassName'])) - { + foreach ($classes as $index => $class) { + if (ClassManager::create_class($class['ClassName'])) { $number_of_added_classes++; } } return $number_of_added_classes; } - - -// name of the language file that needs to be included +// Language files that should be included. $language_file = array ('admin', 'registration'); -// resetting the course id +// Resetting the course id. $cidReset = true; -// including some necessary dokeos files -include ('../inc/global.inc.php'); -require_once (api_get_path(LIBRARY_PATH).'fileManage.lib.php'); -require_once (api_get_path(LIBRARY_PATH).'classmanager.lib.php'); -require_once (api_get_path(LIBRARY_PATH).'import.lib.php'); -require_once (api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php'); +// Including some necessary dokeos files. +include '../inc/global.inc.php'; +require_once api_get_path(LIBRARY_PATH).'fileManage.lib.php'; +require_once api_get_path(LIBRARY_PATH).'classmanager.lib.php'; +require_once api_get_path(LIBRARY_PATH).'import.lib.php'; +require_once api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php'; -// setting the section (for the tabs) +// Setting the section (for the tabs). $this_section = SECTION_PLATFORM_ADMIN; -// Access restrictions +// Access restrictions. api_protect_admin_script(); // setting breadcrumbs -$interbreadcrumb[] = array ("url" => 'index.php', "name" => get_lang('PlatformAdmin')); +$interbreadcrumb[] = array ('url' => 'index.php', 'name' => get_lang('PlatformAdmin')); // Database Table Definitions -// setting the name of the tool +// Setting the name of the tool. $tool_name = get_lang('ImportClassListCSV'); -// Displaying the header +// 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->addElement('submit','submit',get_lang('Ok')); -if( $form->validate()) -{ +$form->addElement('file', 'import_file', get_lang('ImportCSVFileLocation')); +$form->addElement('style_submit_button', 'submit', get_lang('Import'), 'class="save"'); + +if ($form->validate()) { $classes = Import::csv_to_array($_FILES['import_file']['tmp_name']); $errors = validate_data($classes); - if (count($errors) == 0) - { + if (count($errors) == 0) { $number_of_added_classes = save_data($classes); Display::display_normal_message($number_of_added_classes.' '.get_lang('ClassesCreated')); - } - else - { + } else { $error_message = get_lang('ErrorsWhenImportingFile'); $error_message .= '
:
@@ -145,10 +138,6 @@ $form->display();\ No newline at end of file diff --git a/main/admin/class_information.php b/main/admin/class_information.php index 0188d2de82..1e1c743d77 100644 --- a/main/admin/class_information.php +++ b/main/admin/class_information.php @@ -28,43 +28,39 @@ ============================================================================== */ -/* -============================================================================== - INIT SECTION -============================================================================== -*/ - -// name of the language file that needs to be included -$language_file='admin'; +// Language files that should be included. +$language_file = 'admin'; -$cidReset=true; +$cidReset = true; -require('../inc/global.inc.php'); -$this_section=SECTION_PLATFORM_ADMIN; +require '../inc/global.inc.php'; +$this_section = SECTION_PLATFORM_ADMIN; api_protect_admin_script(); -require(api_get_path(LIBRARY_PATH).'classmanager.lib.php'); -if( !isset($_GET['id'])) -{ + +require api_get_path(LIBRARY_PATH).'classmanager.lib.php'; + +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')); + +$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 + * Show all users subscribed in this class. */ echo '
'; - $users = ClassManager::get_users($class_id); -if (count($users) > 0) -{ +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) { @@ -78,8 +74,7 @@ if (count($users) > 0) $table_header[] = array (get_lang('Status'), true); $table_header[] = array ('', false); $data = array(); - foreach($users as $index => $user) - { + foreach($users as $index => $user) { $row = array (); $row[] = $user['official_code']; if ($is_western_name_order) { @@ -95,24 +90,21 @@ if (count($users) > 0) $data[] = $row; } Display::display_sortable_table($table_header,$data,array(),array(),array('id'=>$_GET['id'])); -} -else -{ +} else { echo get_lang('NoUsersInClass'); } echo ''; + /** - * Show all courses in which this class is subscribed + * Show all courses in which this class is subscribed. */ $courses = ClassManager::get_courses($class_id); -if (count($courses) > 0) -{ +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) - { + foreach( $courses as $index => $course) { $row = array (); $row[] = $course['visual_code']; $row[] = $course['title']; @@ -125,15 +117,9 @@ if (count($courses) > 0) echo '
'; Display :: display_sortable_table($header, $data, array (), array (), array('id'=>$_GET['id'])); echo ''; -} -else -{ +} else { echo '
'.get_lang('NoCoursesForThisClass').'
'; } -/* -============================================================================== - FOOTER -============================================================================== -*/ + +// Displaying the footer. Display::display_footer(); -?> \ No newline at end of file diff --git a/main/admin/class_list.php b/main/admin/class_list.php index c7f3cbb6c7..8810a63487 100644 --- a/main/admin/class_list.php +++ b/main/admin/class_list.php @@ -28,36 +28,36 @@ ============================================================================== */ -// name of the language file that needs to be included $language_file = 'admin'; + $cidReset = true; -require ('../inc/global.inc.php'); +require '../inc/global.inc.php'; + $this_section = SECTION_PLATFORM_ADMIN; +api_protect_admin_script(); /** - * Gets the total number of classes + * Gets the total number of classes. */ -function get_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'])) - { + if (isset ($_GET['keyword'])) { $sql .= " WHERE (name LIKE '%".Database::escape_string(trim($_GET['keyword']))."%')"; } - $res = api_sql_query($sql, __FILE__, __LINE__); + $res = Database::query($sql, __FILE__, __LINE__); $obj = Database::fetch_object($res); return $obj->number_of_classes; } + /** - * Gets the information about some 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) -{ - $tbl_class_user = Database :: get_main_table(TABLE_MAIN_CLASS_USER); +function get_class_data($from, $number_of_items, $column, $direction) { + $tbl_class_user = Database::get_main_table(TABLE_MAIN_CLASS_USER); $tbl_class = Database :: get_main_table(TABLE_MAIN_CLASS); $from = Database::escape_string($from); $number_of_items = Database::escape_string($number_of_items); @@ -65,55 +65,49 @@ function get_class_data($from, $number_of_items, $column, $direction) $direction = Database::escape_string($direction); $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'])) - { + 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 = api_sql_query($sql, __FILE__, __LINE__); + $sql .= " GROUP BY id,name ORDER BY col$column $direction LIMIT $from,$number_of_items"; + $res = Database::query($sql, __FILE__, __LINE__); $classes = array (); - while ($class = Database::fetch_row($res)) - { + 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) -{ - global $charset; +function modify_filter($class_id) { $class_id = Security::remove_XSS($class_id); $result = ''.Display::return_icon('synthese_view.gif', get_lang('Info')).''; $result .= ''.Display::return_icon('edit.gif', get_lang('Edit')).''; - $result .= ''.Display::return_icon('delete.gif', get_lang('Delete')).''; + $result .= ''.Display::return_icon('delete.gif', get_lang('Delete')).''; $result .= ''.Display::return_icon('add_multiple_users.gif', get_lang('AddUsersToAClass')).''; return $result; } -api_protect_admin_script(); -require (api_get_path(LIBRARY_PATH).'fileManage.lib.php'); -require (api_get_path(LIBRARY_PATH).'classmanager.lib.php'); -require_once (api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php'); +require api_get_path(LIBRARY_PATH).'fileManage.lib.php'; +require api_get_path(LIBRARY_PATH).'classmanager.lib.php'; +require_once api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php'; + $tool_name = get_lang('ClassList'); -$interbreadcrumb[] = array ("url" => 'index.php', "name" => get_lang('PlatformAdmin')); +$interbreadcrumb[] = array ('url' => 'index.php', 'name' => get_lang('PlatformAdmin')); Display :: display_header($tool_name); //api_display_tool_title($tool_name); -if (isset ($_POST['action'])) -{ - switch ($_POST['action']) - { + +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) - { + if (count($classes) > 0) { + foreach ($classes as $index => $class_id) { ClassManager :: delete_class($class_id); } Display :: display_normal_message(get_lang('ClassesDeleted')); @@ -121,36 +115,37 @@ if (isset ($_POST['action'])) break; } } -if (isset ($_GET['action'])) -{ - switch ($_GET['action']) - { - case 'delete_class' : + +if (isset($_GET['action'])) { + switch ($_GET['action']) { + case 'delete_class': ClassManager :: delete_class($_GET['class_id']); Display :: display_normal_message(get_lang('ClassDeleted')); + break; + case 'show_message': + Display :: display_normal_message(Security::remove_XSS(stripslashes($_GET['message']))); + break; } } + // Create a search-box -$form = new FormValidator('search_simple','get','','',null,false); +$form = new FormValidator('search_simple', 'get', '', '', null, false); $renderer =& $form->defaultRenderer(); $renderer->setElementTemplate('{element} '); -$form->addElement('text','keyword',get_lang('keyword')); -$form->addElement('submit','submit',get_lang('Search')); +$form->addElement('text', 'keyword', get_lang('keyword')); +$form->addElement('submit', 'submit', get_lang('Search')); $form->display(); + // 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_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'); +$table->set_form_actions(array ('delete_classes' => get_lang('DeleteSelectedClasses')), 'class'); $table->display(); -/* -============================================================================== - FOOTER -============================================================================== -*/ + +// Displaying the footer. Display :: display_footer(); -?>