Source for file courses.php
Documentation is available at courses.php
<?php // $Id: courses.php 14406 2008-02-27 21:53:15Z yannoo $
==============================================================================
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) various contributors
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.
Contact: Dokeos, 181 rue Royale, B-1000 Brussels, Belgium, info@dokeos.com
==============================================================================
==============================================================================
* @todo check if unsubscribing from a course WITH group memberships works as it should
* @todo constants are in uppercase, variables aren't
==============================================================================
==============================================================================
==============================================================================
// name of the language file that needs to be included
$language_file = 'courses';
// including the global file
include('../inc/global.inc.php');
// acces rights: anonymous users can't do anything usefull here
// include additional libraries
include_once(api_get_path(LIBRARY_PATH) . 'debug.lib.inc.php');
include_once(api_get_path(LIBRARY_PATH) . 'course.lib.php');
$ctok = $_SESSION['sec_token'];
// Database table definitions
$actions = array('sortmycourses','createcoursecategory','subscribe','deletecoursecategory','unsubscribe');
if ($safe['action'] == 'sortmycourses' OR !isset ($safe['action']))
if ($safe['action'] == 'createcoursecategory')
$nameTools = get_lang('CreateCourseCategory');
if ($safe['action'] == 'subscribe')
$nameTools = get_lang("SubscribeToCourse");
$interbreadcrumb[] = array('name'=> get_lang('CourseManagement'), 'url'=> 'courses.php');
==============================================================================
==============================================================================
// we are moving a course or category of the user up/down the list (=Sort My Courses)
if (isset ($_GET['move']))
if (isset ($_GET['course']))
if($ctok == $_GET['sec_token'])
$message= move_course($_GET['move'], $_GET['course'],$_GET['category']);
if (isset ($_GET['category']) and !$_GET['course'])
if($ctok == $_GET['sec_token'])
// we are moving the course of the user to a different user defined course category (=Sort My Courses)
if (isset ($_POST['submit_change_course_category']))
if($ctok == $_POST['sec_token'])
// we are creating a new user defined course category (= Create Course Category)
if (isset ($_POST['create_course_category']) AND isset ($_POST['title_course_category']) AND strlen(trim($_POST['title_course_category'])) > 0)
if($ctok == $_POST['sec_token'])
if (isset ($_POST['submit_edit_course_category']) AND isset ($_POST['title_course_category']) AND strlen(trim($_POST['title_course_category'])) > 0)
if($ctok == $_POST['sec_token'])
// we are subcribing to a course (=Subscribe to course)
if (isset ($_POST['subscribe']))
if($ctok == $_POST['sec_token'])
// we are unsubscribing from a course (=Unsubscribe from course)
if (isset ($_POST['unsubscribe']))
if($ctok == $_POST['sec_token'])
// we are deleting a course category
if ($safe['action']== 'deletecoursecategory' AND isset ($_GET['id']))
if($ctok == $_GET['sec_token'])
==============================================================================
==============================================================================
// Diplaying the tool title
// api_display_tool_title($nameTools);
// we are displaying any result messages;
// The menu with the different options in the course management
echo "<div id=\"actions\">\n";
if ($safe['action'] <> 'sortmycourses' AND isset ($safe['action']))
if ($safe['action']<> 'createcoursecategory')
if ($safe['action']<> 'subscribe')
//api_display_tool_title(get_lang('SubscribeToCourse'));
//api_display_tool_title(get_lang('UnsubscribeFromCourse'));
case 'createcoursecategory':
//api_display_tool_title(get_lang('CreateCourseCategory'));
case 'deletecoursecategory':
//api_display_tool_title(get_lang('SortMyCourses'));
==============================================================================
==============================================================================
* Subscribe the user to a given course
* @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
* @param string $course_code the code of the course the user wants to subscribe to
* @return string we return the message that is displayed when the action is succesfull
if ($all_course_information['registration_code']== '' OR $_POST['course_registration_code']== $all_course_information['registration_code'])
return get_lang('EnrollToCourseSuccessful');
return get_lang('ErrorContactPlatformAdmin');
if (isset ($_POST['course_registration_code']) AND $_POST['course_registration_code']<> $all_course_information['registration_code'])
$return.= get_lang('CourseRequiresPassword'). '<br/>';
$return.= $all_course_information['visual_code']. ' - '. $all_course_information['title'];
$return.= "<form action=\"". $_SERVER["REQUEST_URI"]. "\" method=\"post\">";
$return.= '<input type="hidden" name="sec_token" value="'. $stok. '" />';
$return.= "<input type=\"hidden\" name=\"subscribe\" value=\"". $all_course_information['code']. "\" />";
$return.= "<input type=\"text\" name=\"course_registration_code\" value=\"". $_POST['course_registration_code']. "\" />";
$return.= "<input type=\"Submit\" name=\"submit_course_registration_code\" value=\"OK\" alt=\"". get_lang("SubmitRegistrationCode"). "\" /></form>";
* unsubscribe the user from a given course
* @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
* @param int $user_id The user id of the user that is performing the unsubscribe action
* @param string $course_code the course code of the course the user wants to unsubscribe from
* @return string we return the message that is displayed when the action is succesfull
// we check (once again) if the user is not course administrator
// because the course administrator cannot unsubscribe himself
// (s)he can only delete the course
$sql_check= "SELECT * FROM $tbl_course_user WHERE user_id='". $user_id. "' AND course_code='". $course_code. "' AND status='1'";
return get_lang("YouAreNowUnsubscribed");
* handles the display of the courses to which the user can subscribe
* @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
* Allows you to browse through the course categories (faculties) and subscribe to the courses of
* this category (faculty)
* @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
if (!isset ($_POST['search_course']))
* Counts the number of courses in a given course category
$sql= "SELECT * FROM $tbl_course WHERE category_code". (empty($category)? " IS NULL": "='". $category. "'");
* displays the browsing of the course categories (faculties)
* @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
* @return HTML code containing a list with all the categories and subcategories and the navigation to go one category up(if needed)
echo "<p><b>". get_lang('CourseCategories'). "</b>";
$sql= "SELECT * FROM $tbl_courses_nodes WHERE parent_id ". (empty($category)? "IS NULL": "='". $category. "'"). " GROUP BY code, parent_id ORDER BY tree_pos ASC";
if ($row['children_count'] > 0 OR $count_courses_in_categ> 0)
echo "<li><a href=\"". api_get_self(). "?action=subscribe&category=". $row['code']. "&up=". $safe_url_categ. "&sec_token=". $stok. "\">". $row['name']. "</a>".
" (". $count_courses_in_categ. ")</li>";
elseif ($row['nbChilds'] > 0)
echo "<li><a href=\"". api_get_self(). "?action=subscribe&category=". $row['code']. "&up=". $safe_url_categ. "&sec_token=". $stok. "\">". $row['name']. "</a></li>";
echo "<li>". $row['name']. "</li>";
* Display all the courses in the given course category. I could have used a parameter here
* but instead I use the already available $_GET['category']
* @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
* @return HTML code: a table with all the courses in a given category (title, code, tutor) and a subscription icon if applicable)
echo "<p><b>". get_lang('CoursesInCategory'). "</b>";
$my_category = (empty($category)? " IS NULL": "='". $category. "'");
$sql= "SELECT * FROM $tbl_course WHERE category_code". $my_category. ' ORDER BY title, visual_code';
if ($row['registration_code']== '')
$registration_code= false;
$courses[]= array("code" => $row['code'], "directory" => $row['directory'], "db"=> $row['db_name'], "visual_code" => $row['visual_code'], "title" => $row['title'], "tutor" => $row['tutor_name'], "subscribe" => $row['subscribe'], "unsubscribe" => $row['unsubscribe'], 'registration_code'=> $registration_code);
* displays the form for searching for a course and the results if a query has been submitted.
* @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
* @return HTML code: the form for searching for a course
global $_user,$charset,$stok;
echo "<p><b>". get_lang("SearchCourse"). "</b><br />";
echo "<form class=\"course_list\" method=\"post\" action=\"". api_get_self(). "?action=subscribe\">",
'<input type="hidden" name="sec_token" value="'. $stok. '">',
"<input type=\"hidden\" name=\"search_course\" value=\"1\" />",
"<input type=\"text\" name=\"search_term\" value=\"". (empty($_POST['search_term'])? '': $_POST['search_term']). "\" />",
" <input type=\"submit\" value=\"",get_lang("_search"),"\" />",
if (isset ($_POST['search_course']))
echo "<p><b>". get_lang("SearchResultsFor"). " ". htmlentities($_POST['search_term'],ENT_QUOTES,$charset). "</b><br />";
* This function displays the list of course that can be subscribed to.
* This list can come from the search results or from the browsing of the platform course categories
// getting all the courses to which the user is subscribed to
$user_coursecodes= array();
// we need only the course codes as these will be used to match against the courses of the category
foreach ($user_courses as $key=> $value)
$user_coursecodes[]= $value['code'];
echo "<table cellpadding=\"4\">\n";
foreach ($courses as $key=> $course)
// displaying the course title, visual code and teacher/teaching staff
echo "<b>". $course['title']. "</b><br />";
if (get_setting("display_coursecode_in_courselist") == "true")
echo $course['visual_code'];
if (get_setting("display_coursecode_in_courselist") == "true" AND get_setting("display_teacher_in_courselist") == "true")
if (get_setting("display_teacher_in_courselist") == "true")
if ($course['registration_code'])
* Search the courses database for a course that matches the search term.
* The search is done on the code, title and tutor field of the course table.
* @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
* @param string $search_term: the string that the user submitted, what we are looking for
* @return array an array containing a list of all the courses (the code, directory, dabase, visual_code, title, ... )
* matching the the search term.
$sql_find= "SELECT * FROM $TABLECOURS WHERE code LIKE '%". $search_term_safe. "%' OR title LIKE '%". $search_term_safe. "%' OR tutor_name LIKE '%". $search_term_safe. "%' ORDER BY title, visual_code ASC";
$courses[]= array("code" => $row['code'], "directory" => $row['directory'], "db"=> $row['db_name'], "visual_code" => $row['visual_code'], "title" => $row['title'], "tutor" => $row['tutor_name'], "subscribe" => $row['subscribe'], "unsubscribe" => $row['unsubscribe']);
* deletes a course category and moves all the courses that were in this category to main category
* @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
* @param int $id: the id of the user_course_category
* @return string a language variable saying that the deletion went OK.
global $_user, $_configuration;
$sql_delete= "DELETE FROM $tucc WHERE id='". $id. "' and user_id='". $_user['user_id']. "'";
$sql_update= "UPDATE $TABLECOURSUSER SET user_course_cat='0' WHERE user_course_cat='". $id. "' AND user_id='". $_user['user_id']. "'";
return get_lang("CourseCategoryDeleted");
* stores the user course category in the dokeos_user database
* @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
* @return string a language variable saying that the user course category was stored
global $_user, $_configuration, $charset;
// step 1: we determine the max value of the user defined course categories
$sql= "SELECT sort FROM $tucc WHERE user_id='". $_user['user_id']. "' ORDER BY sort DESC";
$nextsort= $maxsort['sort']+ 1;
// step 2: we check if there is already a category with this name, if not we store it, else we give an error.
$sql= "SELECT * FROM $tucc WHERE user_id='". $_user['user_id']. "' AND title='". Database::escape_string($_POST['title_course_category']). "'ORDER BY sort DESC";
$sql_insert= "INSERT INTO $tucc (user_id, title,sort) VALUES ('". $_user['user_id']. "', '". htmlentities($_POST['title_course_category'],ENT_QUOTES,$charset). "', '". $nextsort. "')";
* displays the form that is needed to create a course category.
* @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
* @return HTML the form (input field + submit button) to create a user course category
global $_user, $_configuration,$stok;
echo "<form name=\"create_course_category\" method=\"post\" action=\"". api_get_self(). "?action=sortmycourses\">\n";
echo '<input type="hidden" name="sec_token" value="'. $stok. '">';
echo "<input type=\"text\" name=\"title_course_category\" />\n";
echo "<input type=\"submit\" name=\"create_course_category\" value=\"". get_lang("Ok"). "\" />\n";
echo get_lang("ExistingCourseCategories");
$sql= "SELECT * FROM $tucc WHERE user_id='". $_user['user_id']. "'";
echo "\t<li>". $row['title']. "</li>\n";
// ***************************************************************************
// this function stores the changes in a course category
// ***************************************************************************
* stores the changes in a course category (moving a course to a different course category)
* @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
* @param string $course_code : the course_code of the course we are moving
* int $newcategory : the id of the user course category we are moving the course to.
* @return string a language variable saying that the course was moved.
$max_sort_value= api_max_sort_value($newcategory,$_user['user_id']); //max_sort_value($newcategory);
$sql= "UPDATE $TABLECOURSUSER SET user_course_cat='". $newcategory. "', sort='". ($max_sort_value+ 1). "' WHERE course_code='". $course_code. "' AND user_id='". $_user['user_id']. "'";
return get_lang("EditCourseCategorySucces");
* moves the course one place up or down
* @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
* @param string $direction : the direction we are moving the course to (up or down)
* string $course2move : the course we are moving
* @return string a language variable saying that the course was moved.
function move_course($direction, $course2move, $category)
// we need only the courses of the category we are moving in
foreach ($all_user_courses as $key=> $course)
if ($course['user_course_category']== $category)
foreach ($user_courses as $key=> $course)
if ($course2move== $course['code'])
// source_course is the course where we clicked the up or down icon
// target_course is the course before/after the source_course (depending on the up/down icon)
{$target_course= $user_courses[$key- 1];}
{$target_course= $user_courses[$key+ 1];}
} // if ($course2move==$course['code'])
if(count($target_course)> 0 && count($source_course)> 0)
$sql_update1= "UPDATE $TABLECOURSUSER SET sort='". $target_course['sort']. "' WHERE course_code='". $source_course['code']. "' AND user_id='". $_user['user_id']. "'";
$sql_update2= "UPDATE $TABLECOURSUSER SET sort='". $source_course['sort']. "' WHERE course_code='". $target_course['code']. "' AND user_id='". $_user['user_id']. "'";
* Moves the course one place up or down
* @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
* @param string $direction : the direction we are moving the course to (up or down)
* string $course2move : the course we are moving
* @return string a language variable saying that the course was moved.
// the database definition of the table that stores the user defined course categories
foreach ($user_coursecategories as $key=> $category_id)
if ($category2move== $category_id)
// source_course is the course where we clicked the up or down icon
//$source_category=get_user_course_category($category2move);
$source_category = $user_course_categories_info[$category2move];
// target_course is the course before/after the source_course (depending on the up/down icon)
$target_category= $user_course_categories_info[$user_coursecategories[$key- 1]];
$target_category= $user_course_categories_info[$user_coursecategories[$key+ 1]];
} // if ($course2move==$course['code'])
} // foreach ($user_courses as $key=>$course)
if(count($target_category)> 0 && count($source_category)> 0)
$sql_update1= "UPDATE $table_user_defined_category SET sort='". $target_category['sort']. "' WHERE id='". $source_category['id']. "' AND user_id='". $_user['user_id']. "'";
$sql_update2= "UPDATE $table_user_defined_category SET sort='". $source_category['sort']. "' WHERE id='". $target_category['id']. "' AND user_id='". $_user['user_id']. "'";
* displays everything that is needed when the user wants to manage his current courses (sorting, subscribing, unsubscribing, ...)
* @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
* @param int $user_id: the user_id of the current user
* string $parameter: determines weither we are displaying for the sorting, subscribing or unsubscribin
array $user_courses: the courses to which the user is subscribed
* @return html a table containing courses and the appropriate icons (sub/unsub/move)
global $_user, $_configuration;
echo "<table cellpadding=\"4\">\n";
// building an array that contains all the id's of the user defined course categories
// initially this was inside the display_courses_in_category function but when we do it here we have fewer
// sql executions = performance increase.
// step 0: we display the course without a user category
// Step 1: we get all the categories of the user
$sql= "SELECT * FROM $tucc WHERE user_id='". $_user['user_id']. "' ORDER BY sort ASC";
if ($show_course_icons= true)
// the edit link is clicked: we display the edit form for the category
if (isset ($_GET['categoryid']) AND $_GET['categoryid']== $row['id'])
echo "<tr><td colspan=\"2\" class=\"user_course_category\">";
echo '<a name="category'. $row['id']. '"></a>'; // display an internal anchor.
// we simply display the title of the catgory
echo "<tr><td colspan=\"2\" class=\"user_course_category\">";
echo '<a name="category'. $row['id']. '"></a>'; // display an internal anchor.
echo "</td><td class=\"user_course_category\">";
// Step 2: show the courses inside this category
* This function displays all the courses in the particular user category;
* @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
* @param int id: the id of the user defined course category
* @return string: the name of the user defined course category
$sql_select_courses= "SELECT course.code, course.visual_code, course.subscribe subscr, course.unsubscribe unsubscr,
course.title title, course.tutor_name tutor, course.db_name, course.directory, course_rel_user.status status,
course_rel_user.sort sort, course_rel_user.user_course_cat user_course_cat
$TABLECOURSUSER course_rel_user
WHERE course.code = course_rel_user.course_code
AND course_rel_user.user_id = '". $_user['user_id']. "'
AND course_rel_user.user_course_cat='". $user_category_id. "'
ORDER BY course_rel_user.user_course_cat, course_rel_user.sort ASC";
echo '<a name="course'. $course['code']. '"></a>'; // display an internal anchor.
echo "<b>". $course['title']. "</b><br />";
if (get_setting("display_coursecode_in_courselist") == "true")
echo $course['visual_code'];
if (get_setting("display_coursecode_in_courselist") == "true" AND get_setting("display_teacher_in_courselist") == "true")
if (get_setting("display_teacher_in_courselist") == "true")
// displaying the up/down/edit icons when we are sorting courses
echo "\t\t<td valign=\"top\">\n";
//if ($parameter=="sorting")
// displaying the delete icon when we are unsubscribing from courses
//if($parameter=="deleting")
// display_unsubscribe_icons($course);
// display the subscribing icon when we are to courses.
//if ($parameter=="subscribing")
// display_subscribe_icon($course);
* gets the title of the user course category
* @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
* @param int id: the id of the user defined course category
* @return string: the name of the user defined course category
global $_user, $_configuration;
$sql= "SELECT * FROM $tucc WHERE user_id='". $_user['user_id']. "' AND id='$id'";
* displays the subscribe icon if the subscribing is allowed and if the user is not yet
* subscribe to this course
* @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
* @param string $current_course: the course code of the course we need to display the subscribe icon for
* @return string a subscribe icon or the text that subscribing is not allowed or the user is already subscribed
// we display the icon to subscribe or the text already subscribed
if (in_array($current_course['code'],$user_coursecodes))
echo "<form action=\"". $_SERVER["REQUEST_URI"]. "\" method=\"post\">";
echo '<input type="hidden" name="sec_token" value="'. $stok. '">';
echo "<input type=\"hidden\" name=\"subscribe\" value=\"". $current_course['code']. "\" />";
if(!empty($_POST['search_term']))
echo '<input type="hidden" name="search_course" value="1" />';
echo '<input type="hidden" name="search_term" value="'. Security::remove_XSS($_POST['search_term']). '" />';
echo "<input type=\"image\" name=\"unsub\" src=\"../img/enroll.gif\" alt=\"". get_lang("Subscribe"). "\" />". get_lang("Subscribe"). "</form>";
* Displays the subscribe icon if the subscribing is allowed and if the user is not yet
* subscribed to this course
* @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
* @return html a small table containing the up/down icons and the edit icon (for moving to a different user course category)
* @todo complete the comments on this function: the parameter section
global $safe,$charset,$stok;
echo "<a href=\"courses.php?action=". $safe['action']. "&move=up&course=". $course['code']. "&category=". $course['user_course_cat']. "&sec_token=". $stok. "\">";
// the edit icon OR the edit dropdown list
if (isset ($_GET['edit']) and $course['code']== $_GET['edit'])
echo "<td rowspan=\"2\" valign=\"middle\"><a href=\"courses.php?action=". $safe['action']. "&edit=". $course['code']. "&sec_token=". $stok. "\">";
echo "<td rowspan=\"2\" valign=\"top\" class=\"invisible\">";
if ($course['status'] != 1)
if ($course['unsubscr'] == 1)
{ // changed link to submit to avoid action by the search tool indexer
echo '<input type="hidden" name="sec_token" value="'. $stok. '">';
echo "<input type=\"hidden\" name=\"unsubscribe\" value=\"". $course['code']. "\" />";
echo "<input type=\"image\" name=\"unsub\" src=\"../img/delete.gif\" alt=\"". get_lang("_unsubscribe"). "\" /></form>";
if ($key< $number_of_courses- 1)
echo "<a href=\"courses.php?action=". $safe['action']. "&move=down&course=". $course['code']. "&category=". $course['user_course_cat']. "&sec_token=". $stok. "\">";
echo "</td></tr></table>";
* displays the relevant icons for the category (if applicable):move up, move down, edit, delete
* @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
* @param $current_category the id of the current category
* $allcategories an associative array containing all the categories.
* @return html: a small table containing the up/down icons and the edit icon (for moving to a different user course category)
* @todo complete the comments on this function: the parameter section
global $safe,$charset,$stok;
$max_category_key= count($all_user_categories);
if ($safe['action']<> 'unsubscribe') // we are in the unsubscribe section then we do not show the icons.
if ($current_category<> $all_user_categories[0])
echo "<a href=\"courses.php?action=". $safe['action']. "&move=up&category=". $current_category. "&sec_token=". $stok. "\">";
echo "<img src=\"../img/up.gif\" alt=\"". htmlentities(get_lang("Up"),ENT_QUOTES,$charset). "\"></a>";
echo " <td rowspan=\"2\">";
echo " <a href=\"courses.php?action=sortmycourses&categoryid=". $current_category. "&sec_token=". $stok. "#category". $current_category. "\">";
echo "<td rowspan=\"2\">";
echo " <a href=\"courses.php?action=deletecoursecategory&id=". $current_category. "&sec_token=". $stok. "\">";
if ($current_category<> $all_user_categories[$max_category_key- 1])
echo "<a href=\"courses.php?action=". $safe['action']. "&move=down&category=". $current_category. "&sec_token=". $stok. "\">";
echo "<img src=\"../img/down.gif\" alt=\"". htmlentities(get_lang("Down"),ENT_QUOTES,$charset). "\"></a>";
* This function displays the form (dropdown list) to move a course to a
* different course_category (after the edit icon has been changed)
* @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
* @param string $edit_course:
* @return html a dropdown list containing all the user defined course categories and a submit button
* @todo when editing (moving) a course inside a user defined course category to a different user defined category
* the dropdown list should have the current course category selected.
global $_user, $_configuration, $safe, $stok;
$DATABASE_USER_TOOLS = $_configuration['user_personal_database'];
$sql= "SELECT * FROM $tucc WHERE user_id='". $_user['user_id']. "'";
$output= "<form name=\"edit_course_category\" method=\"post\" action=\"courses.php?action=". $safe['action']. "\">\n";
$output.= '<input type="hidden" name="sec_token" value="'. $stok. '">';
$output.= "<input type=\"hidden\" name=\"course_2_edit_category\" value=\"". $edit_course. "\" />";
$output.= "\t<select name=\"course_categories\">\n";
$output.= "\t\t<option value=\"0\">". get_lang("NoCourseCategory"). "</option>";
{$output.= "\t\t<option value=\"". $row['id']. "\">". $row['title']. "</option>";}
$output.= "\t</select>\n";
$output.= "\t<input type=\"submit\" name=\"submit_change_course_category\" value=\"". get_lang("Ok"). "\" />\n";
* This function displays the unsubscribe part which can be
* 1. the unsubscribe link
* 2. text: you are course admin of this course (=> unsubscription is not possible
* 3. text: you are not allowed to unsubscribe from this course
* @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
* @param array $course: the array with all the course & course_rel_user information
* @return html a delete icon or a text that unsubscribing is not possible (course admin) or not allowed.
if ($course['status'] != 1)
if ($course['unsubscribe'] == 1)
{ // changed link to submit to avoid action by the search tool indexer
echo '<input type="hidden" name="sec_token" value="'. $stok. '">';
echo "<input type=\"hidden\" name=\"unsubscribe\" value=\"". $course['code']. "\" />";
echo "<input type=\"image\" name=\"unsub\" src=\"../img/delete.gif\" alt=\"". get_lang("_unsubscribe"). "\" /></form>";
* retrieves all the courses that the user has already subscribed to
* @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
* @param int $user_id: the id of the user
* @return array an array containing all the information of the courses of the given user
// Secondly we select the courses that are in a category (user_course_cat<>0) and sort these according to the sort of the category
$sql_select_courses= "SELECT course.code k, course.visual_code vc, course.subscribe subscr, course.unsubscribe unsubscr,
course.title i, course.tutor_name t, course.db_name db, course.directory dir, course_rel_user.status status,
course_rel_user.sort sort, course_rel_user.user_course_cat user_course_cat
$TABLECOURSUSER course_rel_user
WHERE course.code = course_rel_user.course_code
AND course_rel_user.user_id = '". $user_id. "'
ORDER BY course_rel_user.sort ASC";
// we only need the database name of the course
$courses[]= array("db"=> $row['db'], "code" => $row['k'], "visual_code" => $row['vc'], "title" => $row['i'], "directory" => $row['dir'], "status" => $row['status'], "tutor" => $row['t'], "subscribe" => $row['subscr'], "unsubscribe" => $row['unsubscr'], "sort" => $row['sort'], "user_course_category" => $row['user_course_cat']);
* retrieves the user defined course categories
* @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
* @return array containing all the IDs of the user defined courses categories, sorted by the "sort" field
$sql = "SELECT * FROM ". $table_category. " WHERE user_id='". $_user['user_id']. "' ORDER BY sort ASC";
* Retrieves the user defined course categories and all the info that goes with it
* @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
* @return array containing all the info of the user defined courses categories with the id as key of the array
$sql = "SELECT * FROM ". $table_category. " WHERE user_id='". $_user['user_id']. "' ORDER BY sort ASC";
$output[$row['id']] = $row;
* @param string $text: the text that has to be written in grey
* @return string: the text with the grey formatting
* @todo move this to a stylesheet
//echo "<font color=\"#808080\">" . $text . "</font>\n";
* @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
* @param string $edit_course:
* @return html output: the form
echo "<form name=\"edit_course_category\" method=\"post\" action=\"courses.php?action=". $safe['action']. "\">\n";
echo "\t<input type=\"hidden\" name=\"edit_course_category\" value=\"". $edit_course_category. "\" />\n";
echo '<input type="hidden" name="sec_token" value="'. $stok. '">';
echo "\t<input type=\"text\" name=\"title_course_category\" value=\"". $info_this_user_course_category['title']. "\" />";
echo "\t<input type=\"submit\" name=\"submit_edit_course_category\" value=\"". get_lang("Ok"). "\" />\n";
* Updates the user course category in the dokeos_user database
* @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
* @return string a language variable saying that the user course category was stored
global $_user, $_configuration, $charset;
$sql_update= "UPDATE $tucc SET title='". htmlentities($_POST['title_course_category'],ENT_QUOTES,$charset). "' WHERE id='".(int) $_POST['edit_course_category']. "'";
return get_lang("CourseCategoryEditStored");
|