Remove unused code. (virtual course)

1.10.x
Julio Montoya 10 years ago
parent ab5244cf84
commit 512c20a427
  1. 390
      main/admin/course_virtual.php
  2. 89
      main/inc/lib/course.lib.php

@ -1,390 +0,0 @@
<?php
/* For licensing terms, see /license.txt */
/**
* @author Roan Embrechts - initial admin interface
* @package chamilo.admin
* @deprecated
*/
/**
* INIT SECTION
*/
// name of the language file that needs to be included
$language_file = 'admin';
$extra_lang_file = "create_course";
// global settings initialisation
// also provides access to main api (inc/lib/main_api.lib.php)
include("../inc/global.inc.php");
$this_section=SECTION_PLATFORM_ADMIN;
api_protect_admin_script();
if (isset($extra_lang_file)) include(api_get_path(INCLUDE_PATH)."../lang/english/".$extra_lang_file.".inc.php");
if (isset($extra_lang_file)) include(api_get_path(INCLUDE_PATH)."../lang/".$language_interface."/".$extra_lang_file.".inc.php");
/*
Constants
*/
define ("CREATE_VIRTUAL_COURSE_OPTION", "create_virtual_course");
define ("DISPLAY_VIRTUAL_COURSE_LIST_OPTION", "display_virtual_course_list");
define ("FORM_ELEMENT_CODE_SIZE", "20");
define ("FORM_ELEMENT_TEXT_SIZE", "60");
define ("SELECT_BOX_SIZE", "10");
define ("COURSE_TITLE_FORM_NAME", "course_title");
define ("LANGUAGE_SELECT_FORM_NAME" , "course_language");
define ("REAL_COURSE_SELECT_FORM_NAME" , "real_course_code");
define ("WANTED_COURSE_CODE_FORM_NAME" , "wanted_course_code");
define ("COURSE_CATEGORY_FORM_NAME" , "course_category");
/*
-----------------------------------------------------------
Header
-----------------------------------------------------------
*/
$tool_name = get_lang('AdminManageVirtualCourses'); // title of the page (should come from the language file)
$interbreadcrumb[]=array('url' => 'index.php',"name" => get_lang('PlatformAdmin'));
Display::display_header($tool_name);
/*
==============================================================================
DISPLAY FUNCTIONS
==============================================================================
*/
function make_strong($text)
{
return "<strong>" . $text . "</strong>";
}
/**
* Return a list of language directories.
* @todo function does not belong here, move to code library,
* also see infocours.php and index.php which contain a similar function
*/
function get_language_folder_list($dirname)
{
if($dirname[strlen($dirname)-1]!='/') $dirname.='/';
$handle=opendir($dirname);
while ($entries = readdir($handle))
{
if ($entries=='.' || $entries=='..' || $entries=='CVS') continue;
if (is_dir($dirname.$entries))
{
$language_list[] = $entries;
}
}
closedir($handle);
return $language_list;
}
/**
* Displays a select element (drop down menu) so the user can select
* the course language.
* @todo function does not belong here, move to (display?) library,
* @todo language display used apparently no longer existing array, converted to english for now.
* but we should switch to display the real language names.
*/
function display_language_select($element_name)
{
global $platformLanguage;
//get language list
$dirname = api_get_path(SYS_PATH)."main/lang/";
$language_list = get_language_folder_list($dirname);
sort($language_list);
//build array with strings to display
foreach ($language_list as $this_language)
{
$language_to_display[$this_language] = $this_language;
}
//sort alphabetically
//warning: key,value association needs to be maintained --> asort instead of sort
asort($language_to_display);
$user_selected_language = $_SESSION["user_language_choice"];
if (! isset($user_selected_language) ) $user_selected_language = $platformLanguage;
//display
echo "<select name=\"$element_name\">";
foreach ($language_to_display as $key => $value)
{
if ($key == $user_selected_language) $option_end = "selected >";
else $option_end = ">";
echo "<option value=\"$key\" $option_end";
echo $value;
echo "</option>\n";
}
echo "</select>";
}
/**
* This code creates a select form element to let the user
* choose a real course to link to.
*
* We display the course code, but internally store the course id.
*/
function display_real_course_code_select($element_name)
{
$real_course_list = CourseManager::get_real_course_list();
echo "<select name=\"$element_name\" size=\"".SELECT_BOX_SIZE."\" >\n";
foreach($real_course_list as $real_course)
{
$course_code = $real_course["code"];
echo "<option value=\"". $course_code ."\">";
echo $course_code;
echo "</option>\n";
}
echo "</select>\n";
}
function display_create_virtual_course_form()
{
global $charset;
$category_table = Database::get_main_table(TABLE_MAIN_CATEGORY);
$message = make_strong(get_lang('AdminCreateVirtualCourse')) . "<br/>" . get_lang('AdminCreateVirtualCourseExplanation') . "<br/>This feature is in development phase, bug reports welcome.";
?>
<p><?php echo $message; ?></p>
<b><?php echo get_lang('MandatoryFields') ?></b>
<form method="post" action="<?php echo api_get_self(); ?>">
<table>
<tr valign="top">
<td colspan="2">
</td>
</tr>
<tr valign="top">
<td align="right">
<?php
echo make_strong(get_lang('CourseTitle')) . "&nbsp;";
echo "</td>";
echo "<td valign=\"top\">";
echo "<input type=\"Text\" name=\"".COURSE_TITLE_FORM_NAME."\" size=\"".FORM_ELEMENT_TEXT_SIZE."\" value=\"$valueIntitule\"/><br />".get_lang('Ex') ;
?>
</td>
</tr>
<tr valign="top">
<td align="right"><?php echo make_strong(get_lang('CourseFaculty')) . "&nbsp;"; ?> </td>
<td>
<?php
echo "<select name=\"".COURSE_CATEGORY_FORM_NAME."\">";
$sql_query = "SELECT code, name
FROM $category_table
WHERE auth_course_child ='TRUE'
ORDER BY tree_pos";
$category_result = Database::query($sql_query);
while ($current_category = Database::fetch_array($category_result))
{
echo "<option value=\"", $current_category["code"], "\"";
echo ">(", $current_category["code"], ") ", $current_category["name"];
echo "</option>\n";
}
?>
</select>
<br /><?php echo make_strong(get_lang('TargetFac')) . "&nbsp;" ?>
</td>
</tr>
<tr valign="top">
<td align="right"><?php echo make_strong(get_lang('Code')) . "&nbsp;" ?> </td>
<td>
<?php
echo "<input type=\"Text\" name=\"".WANTED_COURSE_CODE_FORM_NAME."\" maxlength=\"".FORM_ELEMENT_CODE_SIZE."\" value=\"$valuePublicCode\"/>
<br/>" . get_lang('Max');
?>
</td>
</tr>
<tr valign="top">
<td align="right">
<?php echo make_strong(get_lang('RealCourseCode')) . "&nbsp;" ?>
</td>
<td>
<?php
display_real_course_code_select(REAL_COURSE_SELECT_FORM_NAME);
//echo "<input type=\"Text\" name=\"real_course_code\" maxlength=\"".FORM_ELEMENT_CODE_SIZE."\" value=\"" . api_htmlentities($valueTitular, ENT_COMPAT, $charset) . "\"/>";
?>
</td>
</tr>
<tr valign="top">
<td align="right">
<?php
echo make_strong(get_lang('CourseLanguage')) . "&nbsp;";
?>
</td>
<td> <?php display_language_select(LANGUAGE_SELECT_FORM_NAME); ?>
</td>
</tr>
<tr valign="top">
<td>
</td>
<td>
<input type="Submit" name="submit_create_virtual_course" value="<?php echo get_lang('Ok')?>"/>
</td>
</tr>
</table>
</form>
<?php
}
function display_main_options()
{
$message = "<ul><li><a href=\"?action=".CREATE_VIRTUAL_COURSE_OPTION."\">".get_lang('CreateVirtualCourse')."</a></li>";
$message .= "<li><a href=\"?action=".DISPLAY_VIRTUAL_COURSE_LIST_OPTION."\">".get_lang('DisplayListVirtualCourses')."</a></li></ul>";
echo $message;
}
function display_virtual_course_list()
{
$course_list = CourseManager::get_virtual_course_list();
if (! is_array($course_list) )
{
//there are no virtual courses
echo "<i>".get_lang('ThereAreNoVirtualCourses')."</i>";
return;
}
$column_header[] = array(get_lang('Title'),true);
$column_header[] = array(get_lang('Code'),true);
$column_header[] = array(get_lang('VisualCode'),true);
$column_header[] = array(get_lang('LinkedCourseTitle'),true);
$column_header[] = array(get_lang('LinkedCourseCode'),true);
$table_data = array();
for($i = 0; $i < count($course_list); $i++)
{
$course_list[$i] = Database::generate_abstract_course_field_names($course_list[$i]);
$target_course_code = $course_list[$i]["target_course_code"];
$real_course_info = Database::get_course_info($target_course_code);
$row = array();
$row[] = $course_list[$i]["title"];
$row[] = $course_list[$i]["system_code"];
$row[] = $course_list[$i]["visual_code"];
$row[] = $real_course_info["title"];
$row[]= $real_course_info["system_code"];
$table_data[] = $row;
}
Display::display_sortable_table($column_header,$table_data,array(),array(),array('action'=>$_GET['action']));
}
/*
==============================================================================
TOOL LOGIC FUNCTIONS
==============================================================================
*/
/**
* Checks all parameters needed to create a virtual course.
* If they are all set, the virtual course creation procedure is called.
* Call this function instead of create_virtual_course
*/
function attempt_create_virtual_course($real_course_code, $course_title, $wanted_course_code, $course_language, $course_category)
{
//better: create parameter list, check the entire list, when false display errormessage
CourseManager::check_parameter_or_fail($real_course_code, "Unspecified parameter: real course id.");
CourseManager::check_parameter_or_fail($course_title, "Unspecified parameter: course title.");
CourseManager::check_parameter_or_fail($wanted_course_code, "Unspecified parameter: wanted course code.");
CourseManager::check_parameter_or_fail($course_language, "Unspecified parameter: course language.");
CourseManager::check_parameter_or_fail($course_category, "Unspecified parameter: course category.");
$message = get_lang('AttemptedCreationVirtualCourse') . "<br/>";
$message .= get_lang('CourseTitle') . " " . $course_title . "<br/>";
$message .= get_lang('WantedCourseCode') . " " . $wanted_course_code . "<br/>";
$message .= get_lang('CourseLanguage') . " " . $course_language . "<br/>";
$message .= get_lang('CourseFaculty') . " " . $course_category . "<br/>";
$message .= get_lang('LinkedToRealCourseCode') . " " . $real_course_code . "<br/>";
Display::display_normal_message($message);
$creation_success = CourseManager::create_virtual_course( $real_course_code, $course_title, $wanted_course_code, $course_language, $course_category );
if ($creation_success)
{
Display::display_normal_message( $course_title . " - " . get_lang('CourseCreationSucceeded') );
return true;
}
return false;
}
/*
==============================================================================
MAIN CODE
==============================================================================
*/
$action = $_GET["action"];
$attempt_create_virtual_course = $_POST["submit_create_virtual_course"];
//api_display_tool_title($tool_name);
if ( isset($attempt_create_virtual_course) && $attempt_create_virtual_course )
{
$real_course_code = $_POST[REAL_COURSE_SELECT_FORM_NAME];
$course_title = $_POST[COURSE_TITLE_FORM_NAME];
$wanted_course_code = $_POST[WANTED_COURSE_CODE_FORM_NAME];
$course_language = $_POST[LANGUAGE_SELECT_FORM_NAME];
$course_category = $_POST[COURSE_CATEGORY_FORM_NAME];
$message = get_lang('AttemptedCreationVirtualCourse') . "<br/>";
$message .= get_lang('CourseTitle') . " " . $course_title . "<br/>";
$message .= get_lang('WantedCourseCode') . " " . $wanted_course_code . "<br/>";
$message .= get_lang('CourseLanguage') . " " . $course_language . "<br/>";
$message .= get_lang('CourseFaculty') . " " . $course_category . "<br/>";
$message .= get_lang('LinkedToRealCourseCode') . " " . $real_course_code . "<br/>";
Display::display_normal_message($message);
$creation_success = CourseManager::attempt_create_virtual_course($real_course_code, $course_title, $wanted_course_code, $course_language, $course_category);
if ($creation_success)
{
Display::display_normal_message( $course_title . " - " . get_lang('CourseCreationSucceeded') );
}
else
{
//should display error message
}
echo "<br/>";
}
display_main_options();
switch($action)
{
case CREATE_VIRTUAL_COURSE_OPTION:
display_create_virtual_course_form();
break;
case DISPLAY_VIRTUAL_COURSE_LIST_OPTION:
display_virtual_course_list();
break;
}
/*
==============================================================================
FOOTER
==============================================================================
*/
Display::display_footer();
?>

@ -997,7 +997,7 @@ class CourseManager
}
$real_course_id = $course_info['system_code'];
$real_course_info = Database::get_course_info($real_course_id);
$real_course_info = api_get_course_info($real_course_id);
$real_course_name = $real_course_info['title'];
$real_course_visual_code = $real_course_info['visual_code'];
$real_course_real_code = Database::escape_string($course_info['system_code']);
@ -2099,87 +2099,6 @@ class CourseManager
return $group_list;
}
/**
* Checks all parameters needed to create a virtual course.
* If they are all set, the virtual course creation procedure is called.
*
* Call this function instead of create_virtual_course
* @param string Course code
* @param string Course title
* @param string Wanted course code
* @param string Course language
* @param string Course category
* @return bool True on success, false on error
* @deprecated virtual course feature is not supported
*/
public static function attempt_create_virtual_course($real_course_code, $course_title, $wanted_course_code, $course_language, $course_category) {
//better: create parameter list, check the entire list, when false display errormessage
self::check_parameter_or_fail($real_course_code, 'Unspecified parameter: real course id.');
self::check_parameter_or_fail($course_title, 'Unspecified parameter: course title.');
self::check_parameter_or_fail($wanted_course_code, 'Unspecified parameter: wanted course code.');
self::check_parameter_or_fail($course_language, 'Unspecified parameter: course language.');
self::check_parameter_or_fail($course_category, 'Unspecified parameter: course category.');
return self::create_virtual_course($real_course_code, $course_title, $wanted_course_code, $course_language, $course_category);
}
/**
* This function creates a virtual course.
* It assumes all parameters have been checked and are not empty.
* It checks wether a course with the $wanted_course_code already exists.
*
* Users of this library should consider this function private,
* please call attempt_create_virtual_course instead of this one.
*
* note: The virtual course 'owner' id (the first course admin) is set to the CURRENT user id.
* @param string Course code
* @param string Course title
* @param string Wanted course code
* @param string Course language
* @param string Course category
* @return true if the course creation succeeded, false otherwise
* @todo research: expiration date of a course
* @deprecated virtual course feature is not supported
*/
public static function create_virtual_course($real_course_code, $course_title, $wanted_course_code, $course_language, $course_category) {
global $firstExpirationDelay;
$user_id = api_get_user_id();
$real_course_info = Database::get_course_info($real_course_code);
$real_course_code = $real_course_info['system_code'];
//check: virtual course creation fails if another course has the same
//code, real or fake.
if (self::course_code_exists($wanted_course_code)) {
Display::display_error_message($wanted_course_code.' - '.get_lang('CourseCodeAlreadyExists'));
return false;
}
//add data to course table, course_rel_user
$course_sys_code = $wanted_course_code;
$course_screen_code = $wanted_course_code;
$course_repository = $real_course_info['directory'];
$course_db_name = $real_course_info['db_name'];
$responsible_teacher = $real_course_info['tutor_name'];
$faculty_shortname = $course_category;
// $course_title = $course_title;
// $course_language = $course_language;
$teacher_id = $user_id;
//HACK ----------------------------------------------------------------
$expiration_date = time() + $firstExpirationDelay;
//END HACK ------------------------------------------------------------
AddCourse::register_course($course_sys_code, $course_screen_code, $course_repository, $course_db_name, $responsible_teacher, $faculty_shortname, $course_title, $course_language, $teacher_id, $expiration_date);
//above was the normal course creation table update call,
//now one more thing: fill in the target_course_code field
Database::query("UPDATE ".Database::get_main_table(TABLE_MAIN_COURSE)." SET target_course_code = '$real_course_code'
WHERE code = '".Database::escape_string($course_sys_code)."' LIMIT 1 ");
return true;
}
/**
* Delete a course
* This function deletes a whole course-area from the platform. When the
@ -2634,7 +2553,7 @@ class CourseManager
$codes = array();
$tbl_course = Database::get_main_table(TABLE_MAIN_COURSE);
$tbl_course_user = Database::get_main_table(TABLE_MAIN_COURSE_USER);
$tbl_user_course_category = Database::get_user_personal_table(TABLE_USER_COURSE_CATEGORY);
$tbl_user_course_category = Database::get_main_table(TABLE_USER_COURSE_CATEGORY);
$special_course_list = self::get_special_course_list();
$with_special_courses = $without_special_courses = '';
@ -3677,7 +3596,7 @@ class CourseManager
}
// Step 1: We get all the categories of the user
$tucc = Database::get_user_personal_table(TABLE_USER_COURSE_CATEGORY);
$tucc = Database::get_main_table(TABLE_USER_COURSE_CATEGORY);
$sql = "SELECT id, title FROM $tucc WHERE user_id='".$user_id."' ORDER BY sort ASC";
$result = Database::query($sql);
$html = null;
@ -3874,7 +3793,7 @@ class CourseManager
{
global $_user;
$output = array();
$table_category = Database::get_user_personal_table(TABLE_USER_COURSE_CATEGORY);
$table_category = Database::get_main_table(TABLE_USER_COURSE_CATEGORY);
$sql = "SELECT * FROM ".$table_category." WHERE user_id='".intval($_user['user_id'])."'";
$result = Database::query($sql);
while ($row = Database::fetch_array($result)) {

Loading…
Cancel
Save