veco_manage_official_data.php from pointcarre at Krugle
Show veco_manage_official_data.php syntax highlighted
<?php // $Id: veco_manage_official_data.php 534 2007-01-29 19:34:24Z evie_em $
/*
==============================================================================
Dokeos - elearning and course management software
Pointcarre - variant of Dokeos
Copyright (c) Roan Embrechts
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.
See the GNU General Public License for more details.
http://pointcarre.sourceforge.net/
http://www.dokeos.com/
==============================================================================
*/
/**
==============================================================================
* Script to deal with the course, teacher and student information
* of Vesalius College (a separate-but-connected entity of VUB with its own
* databases).
*
* @package dokeos.admin
==============================================================================
*/
/*
==============================================================================
INIT SECTION
==============================================================================
*/
$langFile='admin';
$cidReset=true;
include('../inc/claro_init_global.inc.php');
api_protect_admin_script();
/*
-----------------------------------------------------------
Libraries
-----------------------------------------------------------
*/
require_once(api_get_configuration_path()."/add_course.conf.php");
require_once(api_get_library_path()."/add_course.lib.inc.php");
require_once(api_get_library_path()."/fileManage.lib.php");
require_once(api_get_library_path()."/course.lib.php");
require_once('../curriculum/curriculum_database.lib.php');
require_once('../curriculum/curriculum_logic.lib.php');
/*
-----------------------------------------------------------
Constants
-----------------------------------------------------------
*/
define("VECO_PREFIX", "VECO_");
define("VECO_COURSE_PREFIX", "VECO");
define("SEE_TEACHER_LIST", "see_teacher_list");
define("SEE_STUDENT_LIST", "see_student_list");
define("UPDATE_TEACHER_LIST_DISPLAY_OPTIONS", "update_teacher_list_display_options");
define("UPDATE_TEACHER_LIST", "update_teacher_list");
define("VIEW_SPECIFIC_TEACHER_COURSES", "view_specific_teacher_courses");
define("CREATE_ONE_OFFICIAL_COURSE", "create_one_official_course");
define("SEE_ALL_TEACHER_ALL_COURSE_LIST", "see_all_teacher_all_course_list");
define("ADD_ONE_TEACHER", "add_teacher");
define("ADD_ONE_STUDENT", "add_student");
/*
-----------------------------------------------------------
Header
-----------------------------------------------------------
*/
$tool_name = "Manage teachers, courses and students of Vesalius College";
$interbredcrump[] = array ("url" => "index.php", "name" => get_lang('AdministrationTools'));
Display::display_header($tool_name);
api_display_tool_title($tool_name);
/*
==============================================================================
DISPLAY FUNCTIONS
==============================================================================
*/
function display_main_options()
{
echo 'What do you want to do?';
echo '<ul>';
echo '<li><a href="'.$_SERVER['PHP_SELF'].'?action='.SEE_TEACHER_LIST.'">See a list of official VeCo teachers</a></li>';
echo '<li><a href="'.$_SERVER['PHP_SELF'].'?action='.SEE_STUDENT_LIST.'">See a list of official VeCo students</a></li>';
//echo '<li><a href="'.$_SERVER['PHP_SELF'].'?action='.UPDATE_TEACHER_LIST_DISPLAY_OPTIONS.'">Update the list of official teachers in Pointcarré</a></li>';
//echo '<li><a href="'.$_SERVER['PHP_SELF'].'?action='.SEE_ALL_TEACHER_ALL_COURSE_LIST.'">See a list of all official teachers and their official courses</a></li>';
echo '</ul>';
}
function display_official_teacher_list()
{
$result_array = get_veco_teacher_info_list();
$row = 0;
$column_header[$row ++] = "last name";
$column_header[$row ++] = "first name";
$column_header[$row ++] = "login";
$column_header[$row ++] = "exists in Pointcarré";
$column_header[$row ++] = "view/update courses";
$properties["width"] = "100%";
$properties["cellspacing"] = "1";
Display :: display_complex_table_header($properties, $column_header);
for ($i = 0; $i < count($result_array); $i++)
{
$last_name = $result_array[$i]["lastname"];
$first_name = $result_array[$i]["firstname"];
$login = $result_array[$i]["login"];
$login = trim($login);
$user_exists = user_exists($login);
if ($user_exists)
{
CurriculumLogic::update_user_name($login, $last_name, $first_name);
}
else
{
add_one_teacher($login);
}
$add_user_link = '<a href="'.$_SERVER['PHP_SELF'].'?action='.ADD_ONE_TEACHER.'&login='.$login.'">add teacher</a>';
$row = 0;
$table_row[$row ++] = $last_name;
$table_row[$row ++] = $first_name;
$table_row[$row ++] = $login;
$table_row[$row ++] = $user_exists ? "Yes" : "No - " . $add_user_link;
$table_row[$row ++] = '<a href="'.$_SERVER['PHP_SELF'].'?action='.VIEW_SPECIFIC_TEACHER_COURSES.'&login='.$login.'">view/update courses</a>';
Display :: display_table_row($bgcolor, $table_row, true);
}
Display :: display_table_footer();
}
/**
* Display Vesalius College students
* and add/update them where necessary.
*/
function display_official_student_list()
{
$result_array = get_veco_student_info_list();
$row = 0;
$column_header[$row ++] = "last name";
$column_header[$row ++] = "first name";
$column_header[$row ++] = "login";
$column_header[$row ++] = "exists in Pointcarré";
$column_header[$row ++] = "view/update courses";
$properties["width"] = "100%";
$properties["cellspacing"] = "1";
Display :: display_complex_table_header($properties, $column_header);
for ($i = 0; $i < count($result_array); $i++)
{
$last_name = $result_array[$i]["lastname"];
$first_name = $result_array[$i]["firstname"];
$login = $result_array[$i]["login"];
$login = trim($login);
$user_exists = user_exists($login);
if ($user_exists)
{
CurriculumLogic::update_user_name($login, $last_name, $first_name);
}
else
{
add_one_student($login);
}
$add_user_link = '<a href="'.$_SERVER['PHP_SELF'].'?action='.ADD_ONE_STUDENT.'&login='.$login.'">add student</a>';
$row = 0;
$table_row[$row ++] = $last_name;
$table_row[$row ++] = $first_name;
$table_row[$row ++] = $login;
$table_row[$row ++] = $user_exists ? "Yes" : "No - " . $add_user_link;
$table_row[$row ++] = '<a href="'.$_SERVER['PHP_SELF'].'?action='.VIEW_SPECIFIC_STUDENT_COURSES.'&login='.$login.'">view/register for courses</a>';
Display :: display_table_row($bgcolor, $table_row, true);
}
Display :: display_table_footer();
}
/**
* Displays list of all courses connected to a certain teacher.
* reused code from official courses management page of teacher
*
* @todo: link to course dir now uses $rootWeb, convert to api_get_path
*/
function display_list_official_courses_of_specific_teacher($login)
{
$courses_directory = api_get_path(WEB_COURSE_PATH);
/*$official_course_table = CurriculumDatabase::get_vub_course_table();
$teacher_user_id = CurriculumDatabase::get_user_id_number_from_personnel_code($personnel_code);
if ( isset($teacher_user_id) && $teacher_user_id ) $teacher_exists = true;
else $teacher_exists = false;*/
$teacher_exists = user_exists($login);
$sql_query = "SELECT * FROM veco.teacher_course WHERE login='$login'";
$sql_result = api_sql_query($sql_query, __FILE__, __LINE__);
while ($result = mysql_fetch_array($sql_result))
{
$course_list[] = $result;
}
echo "\n<h3>"."List of Vesalius College courses for $login"."</h3>\n";
$bgcolor = Display::display_table_header();
foreach ($course_list as $this_course)
{
$official_code = $this_course["coursenumber"];
$official_title = $this_course["coursetitle"];
$dokeos_course_code = VECO_COURSE_PREFIX . $official_code;
$faculty = substr($official_code, 0, 3);
if ($bgcolor == "bgcolor='white'") $bgcolor = "bgcolor='".DOKEOSLIGHTGREY."'";
else if ($bgcolor == "bgcolor='".DOKEOSLIGHTGREY."'") $bgcolor = "bgcolor='white'";
//$course_exists = CurriculumDatabase::is_course_created($oocode);
$course_url = $courses_directory . $dokeos_course_code . "/index.php";
$course_exists = course_exists($dokeos_course_code);
if ( !$course_exists )
{
//course does not exist yet
echo "<tr>\n\n<td valign='top' $bgcolor>\n\n<b>$official_title</b><br>" .
"official code $official_code, pointcarre course code $dokeos_course_code, faculty $faculty",
"\n";
echo "<td valign='top' $bgcolor><i>". get_lang("CourseNotActivated") . "</i>";
echo '<form method="post" action="'.$_SERVER['PHP_SELF'].'">';
echo '<input type="hidden" name="teacher_login" value="'.$login.'">';
echo '<input type="hidden" name="official_course_code" value="'.$official_code.'">';
echo '<input type="hidden" name="dokeos_course_code" value="'.$dokeos_course_code.'">';
echo '<input type="hidden" name="faculty_code" value="'.$faculty.'">';
if ($teacher_exists)
{
echo '<br><input name="'.CREATE_ONE_OFFICIAL_COURSE.'" type="submit" value="Create Vesalius course">';
}
else
{
echo "<i>It cannot be activated because the teacher does not yet exist in Dokeos.</i>";
}
echo "</form></td>\n";
echo "<td valign='top' $bgcolor></td>\n";
}
else
{
echo "<tr>\n\n<td valign='top' $bgcolor><a href='$course_url'>\n\n<b>$official_title</b></a><br>" .
"official code $official_code, pointcarre course code $dokeos_course_code, faculty $faculty, ",
"</td>\n";
echo "<td valign='top' $bgcolor><i>" . get_lang("CourseAlreadyActivated") . "</i></td>\n";
}
echo "</tr>\n";
}
Display::display_table_footer();
}
/**
* Display a list of teachers that are in the official database
* but not yet in the Dokeos user table.
*/
function display_all_teacher_all_course_list($minimum, $maximum)
{
echo '<ul>';
echo '<li><a href="'.$_SERVER['PHP_SELF'].'?action='.SEE_ALL_TEACHER_ALL_COURSE_LIST.'&min=0&max=500">Show teachers 0 - 500 and their courses</a>';
echo '<li><a href="'.$_SERVER['PHP_SELF'].'?action='.SEE_ALL_TEACHER_ALL_COURSE_LIST.'&min=501&max=1000&is_simulation=true">Show teachers 501 - 1000 and their courses</a></li>';
echo '<li><a href="'.$_SERVER['PHP_SELF'].'?action='.SEE_ALL_TEACHER_ALL_COURSE_LIST.'&min=1001&max=1500&is_simulation=true">Show teachers 1001 - 1500 and their courses</a></li>';
echo '</ul>';
$official_teacher_list = CurriculumDatabase::get_official_teacher_info_list($minimum, $maximum);
$number_of_courses_can_be_created = 0;
//for all teachers...
for ($i = 0; $i < count($official_teacher_list); $i++)
{
$teacher_code = $official_teacher_list[$i][0];
$personnel_code = $official_teacher_list[$i][1];
$last_name = $official_teacher_list[$i][2];
$first_name = $official_teacher_list[$i][3];
$teacher_user_id = CurriculumDatabase::get_user_id_number_from_personnel_code($personnel_code);
if ( isset($teacher_user_id) && $teacher_user_id ) $teacher_exists = true;
else $teacher_exists = false;
echo "<p>";
//one line of info about the teacher
echo $last_name . ', ' . $first_name . ' (' . $teacher_code . ')';
//list all courses of the teacher, one line each
$number_courses = CurriculumDatabase::get_number_of_courses_of_teacher($teacher_code);
echo " has $number_courses official courses in 2005-2006<br/> ";
if ($number_courses > 0)
{
$course_list_of_teacher = CurriculumDatabase::get_current_courses_of_teacher($teacher_code);
echo '<ul>';
for ($j = 0; $j < count($course_list_of_teacher); $j++)
{
$oocode = $course_list_of_teacher[$j]["oocode"];
$oonaam = $course_list_of_teacher[$j]["naam"];
$faculty_code = $course_list_of_teacher[$j]["faculteit_afkorting"];
$course_exists = CurriculumDatabase::is_course_created($oocode);
echo '<li>';
echo "$oonaam ($oocode)";
if ( $teacher_exists && !$course_exists )
{
display_course_create_form($teacher_user_id, $personnel_code, $teacher_code, $oocode, $faculty_code);
$number_of_courses_can_be_created++;
}
echo '</li>';
}
echo '</ul>';
}
echo "</p>";
}
echo "<p>$number_of_courses_can_be_created courses can still be created.</p>";
}
/**
* Displays a form with a create course button - there is no other output.
*/
function display_course_create_form($teacher_user_id, $personnel_code, $teacher_code, $oocode, $faculty_code)
{
echo '<form method="post" action="'.$_SERVER['PHP_SELF'].'">';
echo '<input type="hidden" name="teacher_user_id" value="'.$teacher_user_id.'">';
echo '<input type="hidden" name="personnel_code" value="'.$personnel_code.'">';
echo '<input type="hidden" name="teacher_code" value="'.$teacher_code.'">';
echo '<input type="hidden" name="course_code" value="'.$oocode.'">';
echo '<input type="hidden" name="faculty_code" value="'.$faculty_code.'">';
echo '<br><input name="'.CREATE_ONE_OFFICIAL_COURSE.'" type="submit" value="'.get_lang("ActivateCourse").'">';
echo "</form>\n";
}
/*
==============================================================================
LOGIC AND DATABASE FUNCTIONS
==============================================================================
*/
function get_veco_teacher_info_list()
{
$sql_query = "SELECT DISTINCT(login) FROM veco.teacher_course ORDER BY lastname";
$sql_result = api_sql_query($sql_query, __FILE__, __LINE__);
while ($result = mysql_fetch_array($sql_result))
{
$teacher_list[] = $result;
}
//now get info on every teacher
foreach($teacher_list as $this_teacher)
{
$this_login = $this_teacher['login'];
$sql_query = "SELECT * FROM veco.teacher_course WHERE login='$this_login'";
$sql_result = api_sql_query($sql_query, __FILE__, __LINE__);
$result = mysql_fetch_array($sql_result);
$teacher_info_list[] = $result;
}
return $teacher_info_list;
}
function get_veco_student_info_list()
{
$sql_query = "SELECT DISTINCT(login) FROM veco.student_course ORDER BY lastname";
$sql_result = api_sql_query($sql_query, __FILE__, __LINE__);
while ($result = mysql_fetch_array($sql_result))
{
$teacher_list[] = $result;
}
//now get info on every teacher
foreach($teacher_list as $this_teacher)
{
$this_login = $this_teacher['login'];
$sql_query = "SELECT * FROM veco.student_course WHERE login='$this_login'";
$sql_result = api_sql_query($sql_query, __FILE__, __LINE__);
$result = mysql_fetch_array($sql_result);
$teacher_info_list[] = $result;
}
return $teacher_info_list;
}
/**
* Returns the Dokeos user id, given the official personnel code
*/
function user_exists ($login)
{
$dokeos_user_table = Database::get_main_table(MAIN_USER_TABLE);
$sql_query = "SELECT * FROM $dokeos_user_table WHERE username='$login'";
$sql_result = api_sql_query($sql_query, __FILE__, __LINE__);
$rows = mysql_num_rows($sql_result);
if ($rows >= 1) return true;
else return false;
}
function course_exists($dokeos_course_code)
{
$dokeos_course_table = Database::get_main_table(MAIN_COURSE_TABLE);
$sql_query = "SELECT * FROM $dokeos_course_table where code='$dokeos_course_code'";
$sql_result = api_sql_query($sql_query, __FILE__, __LINE__);
$rows = mysql_num_rows($sql_result);
if ($rows >= 1) return true;
else return false;
}
function add_one_teacher($login)
{
$login = trim($login);
$sql_query = "SELECT * FROM veco.teacher_course WHERE login='$login'";
$sql_result = api_sql_query($sql_query, __FILE__, __LINE__);
$result = mysql_fetch_array($sql_result);
//1. gather information about the teacher
$last_name = $result["lastname"];
$first_name = $result["firstname"];
$email = $login . "@vub.ac.be";
$password = PLACEHOLDER;
$status = COURSEMANAGER;
$authentication_method = CURL_AUTHENTICATION_METHOD;
//2. check wether the teacher already exists in Dokeos
$user_exists = user_exists($login);
if ($user_exists)
{
Display::display_normal_message("The user ($login) already exists.");
return;
}
echo "Adding $login,$last_name,$first_name,$email,$password,$status,$authentication_method...<br/>";
//3. add the teacher to Dokeos
if ($login == "" )
{
api_display_debug_info("problem: login '$login', name '$last_name $first_name'");
}
else if ($login != "" && ! $user_exists)
{
if (! $is_simulation )
{
$user_id = create_new_curl_user($first_name, $last_name, $status,
$email, $login, $password, '',
'', '', $authentication_method, '0');
}
Display::display_normal_message("The user ($login) has been added.");
}
else if ($login != "" && isset($user_exists) && $user_exists)
{
Display::display_normal_message("The user ($login) already exists.");
}
else if (! isset($login) || $login = "" )
{
Display::display_normal_message("The user ($login) has info missing.");
}
else
{
Display::display_normal_message("The user ($login) has unknown data missing.");
}
}
function add_one_student($login)
{
$login = trim($login);
$sql_query = "SELECT * FROM veco.student_course WHERE login='$login'";
$sql_result = api_sql_query($sql_query, __FILE__, __LINE__);
$result = mysql_fetch_array($sql_result);
//1. gather information about the student
$last_name = $result["lastname"];
$first_name = $result["firstname"];
$email = $login . "@vub.ac.be";
$password = PLACEHOLDER;
$status = STUDENT;
$authentication_method = CURL_AUTHENTICATION_METHOD;
//2. check wether the student already exists in Dokeos
$user_exists = user_exists($login);
if ($user_exists)
{
Display::display_normal_message("The user ($login) already exists.");
return;
}
echo "Adding $login,$last_name,$first_name,$email,$password,$status,$authentication_method...<br/>";
//3. add the student to Dokeos
if ($login == "" )
{
api_display_debug_info("problem: login '$login', name '$last_name $first_name'");
}
else if ($login != "" && ! $user_exists)
{
if (! $is_simulation )
{
$user_id = create_new_curl_user($first_name, $last_name, $status,
$email, $login, $password, '',
'', '', $authentication_method, '0');
}
Display::display_normal_message("The user ($login) has been added.");
}
else if ($login != "" && isset($user_exists) && $user_exists)
{
Display::display_normal_message("The user ($login) already exists.");
}
else if (! isset($login) || $login = "" )
{
Display::display_normal_message("The user ($login) has info missing.");
}
else
{
Display::display_normal_message("The user ($login) has unknown data missing.");
}
}
function get_user_info_from_login($login)
{
$table = Database::get_main_table(MAIN_USER_TABLE);
$sql_query = "SELECT * FROM $table WHERE username='$login'";
$sql_result = api_sql_query($sql_query,__FILE__,__LINE__);
$result_array = mysql_fetch_array($sql_result);
return $result_array;
}
/**
* This function attempts to create a course from the vesalius college curriculum,
* if this fails it displays a human readable error message
* that users can mail to us.
*
* The function uses the standard Dokeos Add Course library
*
* 1) define the course keys
* (code, id, databasename, course "repository" directory)
*
* 2) create and fill the course directory
*
* 3) create and fill course database and update main database
*
* To Do
* - error message
* - get official faculty
*/
function attempt_create_one_veco_course($teacher_login, $official_course_code, $dokeos_course_code, $faculty_code)
{
global $dbNamePrefix, $firstExpirationDelay, $_user;
$faculty_code = VECO_PREFIX . $faculty_code;
echo "Attempting to create $teacher_login, $official_course_code, $dokeos_course_code, $faculty_code...";
if ( course_exists($dokeos_course_code) )
{
return "The course already exists.";
}
//does the course already exist? do not create it twice
$course_exists = CurriculumDatabase::is_course_created($official_course_code);
if ($course_exists)
{
$error_message = "The course $official_course_code was not created because it seemed to exist already.";
return;
}
$wanted_course_code = $dokeos_course_code; // VECO_ + $official_course_code
$keys = define_course_keys($wanted_course_code,"","$dbNamePrefix", "");
$course_visual_code = $keys["currentCourseCode"];
$course_system_code = $keys["currentCourseId"];
$course_db_name = $keys["currentCourseDbName"];
$course_repository = $keys["currentCourseRepository"];
//teacher info
$teacher_user_info = get_user_info_from_login($teacher_login);
$teacher_user_id = $teacher_user_info['user_id'];
//get full name of teacher
$responsible_teacher = $teacher_user_info['firstname']." ".$teacher_user_info['lastname'];
$responsible_teacher = addslashes($responsible_teacher);
//get the official name of the course
$course_title = CurriculumDatabase::get_official_course_title($official_course_code);
$sql_query = "SELECT coursetitle FROM veco.teacher_course WHERE coursenumber='$official_course_code'";
$sql_result = api_sql_query($sql_query, __FILE__, __LINE__);
$result = mysql_fetch_array($sql_result);
$course_title = $result['coursetitle'];
if(empty($course_title)) $course_title=$course_code;
$course_title = addslashes($course_title);
if ( ! isset($teacher_user_info) && ! $teacher_user_info )
{
$error_message = "Attempting creation of course <i>$course_title</i> (code $course_visual_code) of faculty $faculty_code has failed, because the teacher user info in Dokeos was not found. First create the teacher - with the correct official code - and try again.";
return $error_message;
}
$info_message = "Attempting creation of course <i>$course_title</i> (code $course_visual_code) of faculty $faculty_code with database $course_db_name and directory $course_repository. The official teacher is $responsible_teacher (dokeosid $teacher_user_id, teachercode $teacher_code, personnelcode $personnel_code).";
if (api_is_platform_admin()) Display::display_normal_message($info_message);
//die("debugging phase - function ends here");
//actually create the course
prepare_course_repository($course_repository, $course_system_code);
update_Db_course($course_db_name);
fill_course_repository($course_repository);
//HACK ----------------------------------------------------------------
//default setting, should let this be selected on creation screen
$course_language = "english";
$expiration_date=time()+$firstExpirationDelay;
//END HACK ------------------------------------------------------------
fill_Db_course($course_db_name, $course_repository, $course_language);
register_course($course_system_code, $course_visual_code, $course_repository, $course_db_name,
$responsible_teacher, $faculty_code, $course_title,
$course_language, $teacher_user_id, $expiration_date);
$tool_table = Database::get_course_tool_list_table($course_db_name);
return "The course <i>$course_title</i> (oocode $official_course_code), taught by $responsible_teacher, has been created.";
}
/*
==============================================================================
MAIN CODE
==============================================================================
*/
$action = $_REQUEST['action'];
$login = $_REQUEST['login'];
$teacher_code = $_REQUEST['teacher_code'];
$official_course_code = $_REQUEST['official_course_code'];
$dokeos_course_code = $_REQUEST['dokeos_course_code'];
$faculty_code = $_REQUEST["faculty_code"];
$create_one_official_course = $_REQUEST[CREATE_ONE_OFFICIAL_COURSE];
$teacher_user_id = $_REQUEST['teacher_user_id'];
$minimum = $_REQUEST["min"];
$maximum = $_REQUEST["max"];
$is_simulation = $_REQUEST['is_simulation'];
if (trim($is_simulation) == "true") $is_simulation = true;
if (trim($is_simulation) == "false") $is_simulation = false;
display_main_options();
if ($action == SEE_TEACHER_LIST)
{
display_official_teacher_list();
}
else if ($action == ADD_ONE_TEACHER)
{
add_one_teacher($login);
display_official_teacher_list();
}
else if ($action == VIEW_SPECIFIC_TEACHER_COURSES)
{
display_list_official_courses_of_specific_teacher($login);
}
else if ($action == SEE_STUDENT_LIST)
{
display_official_student_list();
}
else if ($action == ADD_ONE_STUDENT)
{
add_one_student($login);
display_official_student_list();
}
if (isset($create_one_official_course) && $create_one_official_course)
{
$message = attempt_create_one_veco_course($teacher_login, $official_course_code, $dokeos_course_code, $faculty_code);
Display::display_normal_message($message);
display_list_official_courses_of_specific_teacher($teacher_login);
}
/*
==============================================================================
FOOTER
==============================================================================
*/
Display::display_footer();
?>
See more files for this project here