Code Search for Developers
 
 
  

manage_official_classes.php from pointcarre at Krugle


Show manage_official_classes.php syntax highlighted

<?php // $Id: manage_official_classes.php 482 2006-10-10 11:45:45Z evie_em $
/*
==============================================================================
	Dokeos - elearning and course management software
	Pointcarre - variant of Dokeos

	Copyright (c) Evie, Free University of Brussels

	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 with several class-related functions:
* - create Dokeos classes based on official curriculum data of "studyyears"
*
* @package dokeos.admin
==============================================================================
*/
/*
==============================================================================
		INIT SECTION
==============================================================================
*/ 

$langFile='admin';

$cidReset=true;

include('../inc/claro_init_global.inc.php');
api_protect_admin_script();

/*
-----------------------------------------------------------
	Libraries
-----------------------------------------------------------
*/
require_once('../curriculum/curriculum_database.lib.php');
require_once('../curriculum/curriculum_logic.lib.php');

/*
-----------------------------------------------------------
	Constants
-----------------------------------------------------------
*/
define ("CREATE_OFFICIAL_STUDYYEAR_CLASS_LIST", "create_official_studyyear_class_list");
define ("CREATE_OFFICIAL_OPLEIDING_CLASS_LIST", "create_official_opleiding_class_list");
define ("CREATE_STUDENT_STUDYYEAR_RELATIONS", "create_student_studyyear_relations");
define ("CREATE_STUDENT_OPLEIDING_RELATIONS", "create_student_opleiding_relations");

/*
-----------------------------------------------------------
	Header
-----------------------------------------------------------
*/
$tool_name = get_lang('ManageOfficialClasses');
$interbredcrump[] = array ("url" => "index.php", "name" => get_lang('AdministrationTools'));
Display::display_header($tool_name);
api_display_tool_title($tool_name);

/*
==============================================================================
		LOGIC FUNCTIONS
==============================================================================
*/ 

/**
* Returns a list of all study years from the official
* curriculum database.
*/
function get_official_studyyear_class_list()
{
	$study_year_table = CurriculumDatabase::get_vub_studyyear_table();
	$year_condition = CurriculumDatabase::get_years_sql_condition('academiejaar');
	
	$sql_query = "SELECT * FROM $study_year_table WHERE $year_condition ORDER BY benaming";
	$sql_result = api_sql_query($sql_query, __FILE__, __LINE__);
	
	//get list of all official classes
	while ($result = mysql_fetch_array($sql_result))
	{
		$official_class_list[] = $result;
	}
	
	return $official_class_list;
}

/**
* Returns a list of all study years from the official
* curriculum database.
*/
function get_official_opleiding_class_list()
{
	$study_year_table = CurriculumDatabase::get_vub_studyyear_table();
	$year_condition = CurriculumDatabase::get_years_sql_condition('academiejaar');
	$sql_query = "SELECT DISTINCT(opleiding_nummer), opleiding_naam FROM $study_year_table WHERE $year_condition ";
	$sql_result = api_sql_query($sql_query);
	
	//get list of all official classes
	while ($result = mysql_fetch_array($sql_result))
	{
		$official_class_list[] = $result;
	}
	
	return $official_class_list;
}

/**
* Create a list of classes in the Dokeos database based on the VUB
* 'studiejaren'. This function only adds new classes that aren't 
* in the Dokeos database already.
* @todo: also update names of classes
*/
function create_update_official_studyyear_class_list()
{
	$dokeos_class_table = Database::get_main_table(MAIN_CLASS_TABLE);
	$official_class_list = get_official_studyyear_class_list();
	
	foreach ($official_class_list as $this_class)
	{
		//echo $this_class['stjcode'] . " " . $this_class['benaming'] . '<br/>';
		$class_code = $this_class['stjcode'];
		$class_name = $this_class['benaming'];
		if (! class_already_exists($class_code))
		{
			$sql_query =  "INSERT INTO $dokeos_class_table VALUES ('', '$class_code', '$class_name')";
			api_sql_query($sql_query, __FILE__, __LINE__);
		}
	}
	Display::display_normal_message("All official classes based on 'studiejaren' have been added to the Dokeos class list.");
}

/**
* Create a list of classes in the Dokeos database based on the VUB
* 'opleidingen'. This function only adds new classes that aren't 
* in the Dokeos database already.
* @todo: also update names of classes
*/
function create_update_official_opleiding_class_list()
{
	$dokeos_class_table = Database::get_main_table(MAIN_CLASS_TABLE);
	$official_class_list = get_official_opleiding_class_list();
	
	foreach ($official_class_list as $this_class)
	{
		//echo $this_class['opleiding_nummer'] . " " . $this_class['opleiding_naam'] . '<br/>';
		$class_code = $this_class['opleiding_nummer'];
		$class_name = $this_class['opleiding_naam'];
		if (! class_already_exists($class_code))
		{
			$sql_query =  "INSERT INTO $dokeos_class_table VALUES ('', '$class_code', '$class_name')";
			api_sql_query($sql_query, __FILE__, __LINE__);
		}
	}
	Display::display_normal_message("All official classes based on 'opleiding' have been added to the Dokeos class list.");
}

/**
* This checks wether an official class already exists in the Dokeos database.
* @param $official_class_code, the official code of the class to check
*/
function class_already_exists($official_class_code)
{
	$dokeos_class_table = Database::get_main_table(MAIN_CLASS_TABLE);
	$sql_query = "SELECT * FROM $dokeos_class_table WHERE code = '$official_class_code'";
	$sql_result = api_sql_query($sql_query, __FILE__, __LINE__);
	if (mysql_num_rows($sql_result) > 0) return true;
	else return false;
}

/**
* This function assumes that all official classes have already been added to Dokeos. This can be done using the create_update_official_class_list() function.
*/
function add_student_studyyear_relations_to_dokeos()
{
	$student_table = CurriculumDatabase::get_vub_student_table();
	$study_year_table = CurriculumDatabase::get_vub_studyyear_table();
	$registration_table = CurriculumDatabase::get_vub_registration_table();
	$dokeos_user_table = Database::get_main_table(MAIN_USER_TABLE);
	$dokeos_class_user_table = Database::get_main_table(MAIN_CLASS_USER_TABLE);
	$current_academic_year = CurriculumLogic::get_current_academic_year();
	
	$sql_query = "SELECT s.rolnr, sj.stjcode FROM $student_table s, $registration_table i, $study_year_table sj WHERE s.rolnr = i.rolnr AND i.stjcode = sj.stjcode AND i.academiejaar='$current_academic_year' AND sj.academiejaar='$current_academic_year'";
	$sql_result = api_sql_query($sql_query, __FILE__, __LINE__);
	
	//get list of the official student-class relations
	while ($result = mysql_fetch_array($sql_result))
	{
		//echo $result['rolnr'] . ', ' . $result['stjcode'] . '<br/>';
		$official_user_class_list[] = $result;
	}
	
	//process list
	foreach ($official_user_class_list as $this_user_class)
	{
		$student_number = $this_user_class['rolnr'];
		$class_code = $this_user_class['stjcode'];
		$user_id = CurriculumDatabase::get_user_id_number_from_student_number($student_number);
		$class_id = get_class_id_from_code($class_code);
		
		$sql_query =  "INSERT IGNORE INTO $dokeos_class_user_table VALUES ('$class_id', '$user_id')";
		api_sql_query($sql_query, __FILE__, __LINE__);
	}
	Display::display_normal_message('The official <em>student-studiejaar</em> relations have been added to the Dokeos database.');
}

/**
* This function assumes that all official opleiding-classes have already been added to Dokeos.
* This can be done using the create_update_official_class_list() function.
*/
function add_student_opleiding_relations_to_dokeos()
{
	$student_table = CurriculumDatabase::get_vub_student_table();
	$study_year_table = CurriculumDatabase::get_vub_studyyear_table();
	$registration_table = CurriculumDatabase::get_vub_registration_table();
	$dokeos_user_table = Database::get_main_table(MAIN_USER_TABLE);
	$dokeos_class_user_table = Database::get_main_table(MAIN_CLASS_USER_TABLE);
	$current_academic_year = CurriculumLogic::get_current_academic_year();
	
	$sql_query = "SELECT s.rolnr, sj.stjcode, sj.benaming, sj.opleiding_nummer, sj.opleiding_naam FROM $student_table s, $registration_table i, $study_year_table sj WHERE s.rolnr = i.rolnr AND i.stjcode = sj.stjcode AND i.academiejaar='$current_academic_year' AND sj.academiejaar='$current_academic_year'";
	$sql_result = api_sql_query($sql_query, __FILE__, __LINE__);
	
	//get list of the official student-opleiding relations
	while ($result = mysql_fetch_array($sql_result))
	{
		//echo $result['rolnr'] . ', ' . $result['stjcode'] . '<br/>';
		$official_user_class_list[] = $result;
	}
	
	//process list
	foreach ($official_user_class_list as $this_user_class)
	{
		$student_number = $this_user_class['rolnr'];
		$opleiding_number = $this_user_class['opleiding_nummer'];
		$opleiding_name = $this_user_class['opleiding_naam'];
		$studiejaar_number = $this_user_class['stjcode'];
		$studiejaar_name = $this_user_class['benaming'];
		
		echo "Student $student_number - studiejaar $studiejaar_name ($studiejaar_number) - opleiding $opleiding_name ($opleiding_number) <br/>";

		$user_id = CurriculumDatabase::get_user_id_number_from_student_number($student_number);
		$class_id = get_class_id_from_code($opleiding_number);
		
		$sql_query =  "INSERT IGNORE INTO $dokeos_class_user_table VALUES ('$class_id', '$user_id')";
		api_sql_query($sql_query, __FILE__, __LINE__);
	}
	Display::display_normal_message('The official <em>student-opleiding</em> relations have been added to the Dokeos database.');
}

function get_class_id_from_code($class_code)
{
	$dokeos_class_table = Database::get_main_table(MAIN_CLASS_TABLE);
	$sql_query = "SELECT id FROM $dokeos_class_table WHERE code='$class_code'";
	$sql_result = api_sql_query($sql_query, __FILE__, __LINE__);
	$result = mysql_fetch_array($sql_result);
	return $result["id"];
}


/*
==============================================================================
		DISPLAY FUNCTIONS
==============================================================================
*/ 

function display_main_options()
{
	echo "The current academic year is set to " . CurriculumLogic::get_current_academic_year() . ".<br/>";
	echo 'What do you want to do?';
	echo '<ul>';
	echo "<li><a href=\"".$_SERVER['PHP_SELF']."?action=".CREATE_OFFICIAL_STUDYYEAR_CLASS_LIST."\">Create the list of official classes based on 'studiejaren'.</a></li>";
	echo "<li><a href=\"".$_SERVER['PHP_SELF']."?action=".CREATE_OFFICIAL_OPLEIDING_CLASS_LIST."\">Create the list of official classes based on 'opleidingen'.</a></li>";
	echo "<li><a href=\"".$_SERVER['PHP_SELF']."?action=".CREATE_STUDENT_STUDYYEAR_RELATIONS."\">Create the list of official <em>student-studiejaar</em> connections</a></li>";
	echo "<li><a href=\"".$_SERVER['PHP_SELF']."?action=".CREATE_STUDENT_OPLEIDING_RELATIONS."\">Create the list of official <em>student-opleiding</em> connections.</a></li>";
	echo '</ul>';
}


/*
==============================================================================
		MAIN CODE
==============================================================================
*/ 

$action = $_REQUEST['action'];
display_main_options();

if ($action == CREATE_OFFICIAL_STUDYYEAR_CLASS_LIST)
{
	create_update_official_studyyear_class_list();
}
else if ($action == CREATE_OFFICIAL_OPLEIDING_CLASS_LIST)
{
	create_update_official_opleiding_class_list();
}
else if ($action == CREATE_STUDENT_STUDYYEAR_RELATIONS)
{
	add_student_studyyear_relations_to_dokeos();
}
else if ($action == CREATE_STUDENT_OPLEIDING_RELATIONS)
{
	add_student_opleiding_relations_to_dokeos();
}
/*
==============================================================================
		FOOTER 
==============================================================================
*/ 
Display::display_footer();
?>



See more files for this project here

pointcarre

Pointcarre - a learning management system based on the Dokeos community releases. No fork, but containing locally developed extensions, features not (yet) in the standard release, integrated plugins...

Project homepage: http://sourceforge.net/projects/pointcarre
Programming language(s): PHP
License: other

  nightly_update/
    nightly_update.php
  class_add.php
  class_edit.php
  class_information.php
  class_list.php
  configure_homepage.php
  course_add.php
  course_category.php
  course_create_content.php
  course_edit.php
  course_information.php
  course_list.php
  course_virtual.php
  curriculum_complete_update.php
  exemple.csv
  exemple.xml
  index.php
  languages.php
  manage_course_tools.php
  manage_official_classes.php
  manage_official_communities.php
  manage_official_personnel.php
  manage_official_students.php
  manage_official_teachers.php
  manage_special_options.php
  official_update_titles_teachers.php
  settings.php
  statistics.php
  subscribe_class2course.php
  subscribe_user2class.php
  subscribe_user2course.php
  system_announcements.php
  user_add.php
  user_edit.php
  user_export.php
  user_import.php
  user_information.php
  user_list.php
  veco_manage_official_data.php