Automatic whitespace cleaning for some files (2).

skala
Ivan Tcholakov 14 years ago
parent 6562def6cc
commit 4910890132
  1. 34
      main/admin/class_add.php
  2. 32
      main/admin/class_edit.php
  3. 110
      main/admin/class_import.php
  4. 124
      main/admin/class_information.php
  5. 136
      main/admin/class_list.php
  6. 232
      main/admin/class_user_import.php

@ -2,25 +2,25 @@
// $Id: class_add.php 10215 2006-11-27 13:57:17Z pcool $
/*
==============================================================================
Dokeos - elearning and course management software
Dokeos - elearning and course management software
Copyright (c) 2004 Dokeos S.A.
Copyright (c) 2003 Ghent University (UGent)
Copyright (c) 2001 Universite catholique de Louvain (UCL)
Copyright (c) Olivier Brouckaert
Copyright (c) Bart Mollet, Hogeschool Gent
Copyright (c) 2004 Dokeos S.A.
Copyright (c) 2003 Ghent University (UGent)
Copyright (c) 2001 Universite catholique de Louvain (UCL)
Copyright (c) Olivier Brouckaert
Copyright (c) Bart Mollet, Hogeschool Gent
For a full list of contributors, see "credits.txt".
The full license can be read in "license.txt".
For a full list of contributors, see "credits.txt".
The full license can be read in "license.txt".
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
See the GNU General Public License for more details.
See the GNU General Public License for more details.
Contact: Dokeos, 181 rue Royale, B-1000 Brussels, Belgium, info@dokeos.com
Contact: Dokeos, 181 rue Royale, B-1000 Brussels, Belgium, info@dokeos.com
==============================================================================
*/
/**
@ -56,9 +56,9 @@ $form = new FormValidator('add_class');
$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']);
header('Location: class_list.php');
$values = $form->exportValues();
ClassManager::create_class($values['name']);
header('Location: class_list.php');
}
// Displaying the header.

@ -3,24 +3,24 @@
/*
==============================================================================
Dokeos - elearning and course management software
Dokeos - elearning and course management software
Copyright (c) 2004 Dokeos S.A.
Copyright (c) 2003 Ghent University (UGent)
Copyright (c) 2001 Universite catholique de Louvain (UCL)
Copyright (c) Olivier Brouckaert
Copyright (c) 2004 Dokeos S.A.
Copyright (c) 2003 Ghent University (UGent)
Copyright (c) 2001 Universite catholique de Louvain (UCL)
Copyright (c) Olivier Brouckaert
For a full list of contributors, see "credits.txt".
The full license can be read in "license.txt".
For a full list of contributors, see "credits.txt".
The full license can be read in "license.txt".
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
See the GNU General Public License for more details.
See the GNU General Public License for more details.
Contact: Dokeos, 181 rue Royale, B-1000 Brussels, Belgium, info@dokeos.com
Contact: Dokeos, 181 rue Royale, B-1000 Brussels, Belgium, info@dokeos.com
==============================================================================
*/
/**
@ -62,9 +62,9 @@ $form->addElement('style_submit_button', 'submit', get_lang('Ok'), 'class="add"'
$form->setDefaults(array('name'=>$class['name']));
if($form->validate())
{
$values = $form->exportValues();
ClassManager :: set_name($values['name'], $class_id);
header('Location: class_list.php');
$values = $form->exportValues();
ClassManager :: set_name($values['name'], $class_id);
header('Location: class_list.php');
}
Display :: display_header($tool_name);

@ -2,25 +2,25 @@
// $Id: class_import.php 10215 2006-11-27 13:57:17Z pcool $
/*
==============================================================================
Dokeos - elearning and course management software
Dokeos - elearning and course management software
Copyright (c) 2004 Dokeos S.A.
Copyright (c) 2003 Ghent University (UGent)
Copyright (c) 2001 Universite catholique de Louvain (UCL)
Copyright (c) Olivier Brouckaert
Copyright (c) Bart Mollet, Hogeschool Gent
Copyright (c) 2004 Dokeos S.A.
Copyright (c) 2003 Ghent University (UGent)
Copyright (c) 2001 Universite catholique de Louvain (UCL)
Copyright (c) Olivier Brouckaert
Copyright (c) Bart Mollet, Hogeschool Gent
For a full list of contributors, see "credits.txt".
The full license can be read in "license.txt".
For a full list of contributors, see "credits.txt".
The full license can be read in "license.txt".
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
See the GNU General Public License for more details.
See the GNU General Public License for more details.
Contact: Dokeos, 181 rue Royale, B-1000 Brussels, Belgium, info@dokeos.com
Contact: Dokeos, 181 rue Royale, B-1000 Brussels, Belgium, info@dokeos.com
==============================================================================
*/
/**
@ -35,37 +35,37 @@
* Validates imported data.
*/
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;
$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
*/
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;
$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;
}
// Language files that should be included.
@ -106,22 +106,22 @@ $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) {
$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);
}
$classes = Import::csv_to_array($_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();

@ -1,24 +1,24 @@
<?php // $Id: class_information.php 16954 2008-11-26 14:41:35Z pcool $
/*
==============================================================================
Dokeos - elearning and course management software
Dokeos - elearning and course management software
Copyright (c) 2004 Dokeos S.A.
Copyright (c) 2003 Ghent University (UGent)
Copyright (c) 2001 Universite catholique de Louvain (UCL)
Copyright (c) Olivier Brouckaert
Copyright (c) 2004 Dokeos S.A.
Copyright (c) 2003 Ghent University (UGent)
Copyright (c) 2001 Universite catholique de Louvain (UCL)
Copyright (c) Olivier Brouckaert
For a full list of contributors, see "credits.txt".
The full license can be read in "license.txt".
For a full list of contributors, see "credits.txt".
The full license can be read in "license.txt".
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
See the GNU General Public License for more details.
See the GNU General Public License for more details.
Contact: Dokeos, 181 rue Royale, B-1000 Brussels, Belgium, info@dokeos.com
Contact: Dokeos, 181 rue Royale, B-1000 Brussels, Belgium, info@dokeos.com
==============================================================================
*/
/**
@ -41,7 +41,7 @@ api_protect_admin_script();
require api_get_path(LIBRARY_PATH).'classmanager.lib.php';
if (!isset($_GET['id'])) {
api_not_allowed();
api_not_allowed();
}
$interbreadcrumb[] = array ('url' => 'index.php', 'name' => get_lang('PlatformAdmin'));
@ -61,37 +61,37 @@ echo '<h4>'.get_lang('Users').'</h4>';
echo '<blockquote>';
$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) {
$row = array ();
$row[] = $user['official_code'];
if ($is_western_name_order) {
$row[] = $user['firstname'];
$row[] = $user['lastname'];
} else {
$row[] = $user['lastname'];
$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').'</a>';
$data[] = $row;
}
Display::display_sortable_table($table_header,$data,array(),array(),array('id'=>$_GET['id']));
$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) {
$row = array ();
$row[] = $user['official_code'];
if ($is_western_name_order) {
$row[] = $user['firstname'];
$row[] = $user['lastname'];
} else {
$row[] = $user['lastname'];
$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').'</a>';
$data[] = $row;
}
Display::display_sortable_table($table_header,$data,array(),array(),array('id'=>$_GET['id']));
} else {
echo get_lang('NoUsersInClass');
echo get_lang('NoUsersInClass');
}
echo '</blockquote>';
@ -100,25 +100,25 @@ echo '</blockquote>';
*/
$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>';
$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>';
echo '<p>'.get_lang('NoCoursesForThisClass').'</p>';
}
// Displaying the footer.

@ -2,24 +2,24 @@
// $Id: class_list.php 20441 2009-05-10 07:39:15Z ivantcholakov $
/*
==============================================================================
Dokeos - elearning and course management software
Dokeos - elearning and course management software
Copyright (c) 2004 Dokeos S.A.
Copyright (c) 2003 Ghent University (UGent)
Copyright (c) 2001 Universite catholique de Louvain (UCL)
Copyright (c) Olivier Brouckaert
Copyright (c) 2004 Dokeos S.A.
Copyright (c) 2003 Ghent University (UGent)
Copyright (c) 2001 Universite catholique de Louvain (UCL)
Copyright (c) Olivier Brouckaert
For a full list of contributors, see "credits.txt".
The full license can be read in "license.txt".
For a full list of contributors, see "credits.txt".
The full license can be read in "license.txt".
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
See the GNU General Public License for more details.
See the GNU General Public License for more details.
Contact: Dokeos, 181 rue Royale, B-1000 Brussels, Belgium, info@dokeos.com
Contact: Dokeos, 181 rue Royale, B-1000 Brussels, Belgium, info@dokeos.com
==============================================================================
*/
/**
@ -41,14 +41,14 @@ 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;
$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;
}
/**
@ -58,38 +58,38 @@ function get_number_of_classes() {
* @param string $direction
*/
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);
$column = Database::escape_string($column);
$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'])) {
$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;
$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);
$column = Database::escape_string($column);
$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'])) {
$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.gif', get_lang('Edit')).'</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.gif', get_lang('Delete')).'</a>';
$result .= '<a href="subscribe_user2class.php?idclass='.$class_id.'">'.Display::return_icon('add_multiple_users.gif', get_lang('AddUsersToAClass')).'</a>';
return $result;
$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.gif', get_lang('Edit')).'</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.gif', get_lang('Delete')).'</a>';
$result .= '<a href="subscribe_user2class.php?idclass='.$class_id.'">'.Display::return_icon('add_multiple_users.gif', get_lang('AddUsersToAClass')).'</a>';
return $result;
}
require api_get_path(LIBRARY_PATH).'fileManage.lib.php';
@ -103,30 +103,30 @@ Display :: display_header($tool_name);
//api_display_tool_title($tool_name);
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);
}
Display :: display_normal_message(get_lang('ClassesDeleted'));
}
break;
}
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);
}
Display :: display_normal_message(get_lang('ClassesDeleted'));
}
break;
}
}
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;
}
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

@ -3,21 +3,21 @@
// $Id: class_user_import.php 9018 2006-06-28 15:11:16Z evie_em $
/*
==============================================================================
Dokeos - elearning and course management software
Dokeos - elearning and course management software
Copyright (c) 2005 Bart Mollet <bart.mollet@hogent.be>
Copyright (c) 2005 Bart Mollet <bart.mollet@hogent.be>
For a full list of contributors, see "credits.txt".
The full license can be read in "license.txt".
For a full list of contributors, see "credits.txt".
The full license can be read in "license.txt".
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
See the GNU General Public License for more details.
See the GNU General Public License for more details.
Contact: Dokeos, 181 rue Royale, B-1000 Brussels, Belgium, info@dokeos.com
Contact: Dokeos, 181 rue Royale, B-1000 Brussels, Belgium, info@dokeos.com
==============================================================================
*/
/**
@ -32,51 +32,51 @@
* Validates imported data.
*/
function validate_data($user_classes) {
global $purification_option_for_usernames;
$errors = array ();
$classcodes = array ();
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');
$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;
global $purification_option_for_usernames;
$errors = array ();
$classcodes = array ();
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');
$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;
}
/**
@ -84,50 +84,50 @@ function validate_data($user_classes) {
*/
function save_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);
}
}
}
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);
}
}
}
}
/**
@ -136,8 +136,8 @@ function save_data($users_classes) {
* @return array All course-information read from the file
*/
function parse_csv_data($file) {
$courses = Import::csv_to_array($file);
return $courses;
$courses = Import::csv_to_array($file);
return $courses;
}
$language_file = array('admin', 'registration');
@ -170,26 +170,26 @@ $form->addElement('checkbox', 'subscribe', get_lang('Action'), get_lang('Subscri
$form->addElement('checkbox', 'unsubscribe', '', get_lang('UnsubscribeUserIfSubscriptionIsNotInFile'));
$form->addElement('style_submit_button', 'submit', get_lang('Import'), 'class="save"');
if ($form->validate()) {
$users_classes = parse_csv_data($_FILES['import_file']['tmp_name']);
$errors = validate_data($users_classes);
if (count($errors) == 0) {
save_data($users_classes);
header('Location: class_list.php?action=show_message&message='.urlencode(get_lang('FileImported')));
exit();
}
$users_classes = parse_csv_data($_FILES['import_file']['tmp_name']);
$errors = validate_data($users_classes);
if (count($errors) == 0) {
save_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 .= "\n";
}
$error_message .= "\n";
Display :: display_error_message($error_message);
$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 .= "\n";
}
$error_message .= "\n";
Display :: display_error_message($error_message);
}
$form->display();
@ -206,7 +206,7 @@ adam;class01
/*
==============================================================================
FOOTER
FOOTER
==============================================================================
*/
Display :: display_footer();

Loading…
Cancel
Save