courses.php 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113
  1. <?php // $Id: courses.php 11166 2007-02-20 01:53:14Z yannoo $
  2. /*
  3. ==============================================================================
  4. Dokeos - elearning and course management software
  5. Copyright (c) 2004 Dokeos S.A.
  6. Copyright (c) 2003 Ghent University (UGent)
  7. Copyright (c) 2001 Universite catholique de Louvain (UCL)
  8. Copyright (c) various contributors
  9. For a full list of contributors, see "credits.txt".
  10. The full license can be read in "license.txt".
  11. This program is free software; you can redistribute it and/or
  12. modify it under the terms of the GNU General Public License
  13. as published by the Free Software Foundation; either version 2
  14. of the License, or (at your option) any later version.
  15. See the GNU General Public License for more details.
  16. Contact: Dokeos, 181 rue Royale, B-1000 Brussels, Belgium, info@dokeos.com
  17. ==============================================================================
  18. */
  19. /**
  20. ==============================================================================
  21. * @package dokeos.auth
  22. * @todo check if unsubscribing from a course WITH group memberships works as it should
  23. * @todo constants are in uppercase, variables aren't
  24. ==============================================================================
  25. */
  26. /*
  27. ==============================================================================
  28. INIT SECTION
  29. ==============================================================================
  30. */
  31. // name of the language file that needs to be included
  32. $language_file = 'courses';
  33. // including the global file
  34. include('../inc/global.inc.php');
  35. $this_section=SECTION_COURSES;
  36. api_block_anonymous_users();
  37. /*
  38. -----------------------------------------------------------
  39. Libraries
  40. -----------------------------------------------------------
  41. */
  42. include_once(api_get_path(LIBRARY_PATH) . 'debug.lib.inc.php');
  43. include_once(api_get_path(LIBRARY_PATH) . 'course.lib.php');
  44. /*
  45. -----------------------------------------------------------
  46. Variables
  47. -----------------------------------------------------------
  48. */
  49. $tbl_course = Database::get_main_table(TABLE_MAIN_COURSE);
  50. $tbl_courses_nodes = Database::get_main_table(TABLE_MAIN_CATEGORY);
  51. $tbl_courseUser = Database::get_main_table(TABLE_MAIN_COURSE_USER);
  52. $tbl_user = Database::get_main_table(TABLE_MAIN_USER);
  53. /*
  54. -----------------------------------------------------------
  55. Header
  56. -----------------------------------------------------------
  57. */
  58. // title of the page
  59. $nameTools= get_lang('CourseManagement');
  60. Display::display_header($nameTools);
  61. api_display_tool_title($nameTools);
  62. /*
  63. ==============================================================================
  64. COMMANDS SECTION
  65. ==============================================================================
  66. */
  67. unset($message);
  68. // we are moving a course or category of the user up/down the list (=Sort My Courses)
  69. if (isset($_GET['move']))
  70. {
  71. if (isset($_GET['course']))
  72. {
  73. $message=move_course($_GET['move'], $_GET['course'],$_GET['category']);
  74. }
  75. if (isset($_GET['category']) and !$_GET['course'])
  76. {
  77. $message=move_category($_GET['move'], $_GET['category']);
  78. }
  79. }
  80. // we are moving the course of the user to a different user defined course category (=Sort My Courses)
  81. if (isset($_POST['submit_change_course_category']))
  82. {
  83. $message=store_changecoursecategory($_POST['course_2_edit_category'], $_POST['course_categories']);
  84. }
  85. // we are creating a new user defined course category (= Create Course Category)
  86. if (isset($_POST['create_course_category']) AND isset($_POST['title_course_category']) AND strlen(trim($_POST['title_course_category'])) > 0)
  87. {
  88. $message=store_course_category();
  89. }
  90. if (isset($_POST['submit_edit_course_category']) AND isset($_POST['title_course_category']) AND strlen(trim($_POST['title_course_category'])) > 0)
  91. {
  92. $message=store_edit_course_category();
  93. }
  94. // we are subcribing to a course (=Subscribe to course)
  95. if (isset($_POST['subscribe']))
  96. {
  97. $message = subscribe_user($_POST['subscribe']);
  98. }
  99. // we are unsubscribing from a course (=Unsubscribe from course)
  100. if (isset($_POST['unsubscribe']))
  101. {
  102. $message=remove_user_from_course($_user['user_id'], $_POST['unsubscribe']);
  103. }
  104. // we are deleting a course category
  105. if ($_GET['action']=='deletecoursecategory' AND isset($_GET['id']))
  106. {
  107. $message=delete_course_category($_GET['id']);
  108. }
  109. // we are displaying any result messages;
  110. if (isset($message))
  111. {
  112. Display::display_normal_message($message);
  113. }
  114. /*
  115. ==============================================================================
  116. DISPLAY SECTION
  117. ==============================================================================
  118. */
  119. // The menu with the different options in the course management
  120. echo "<div>\n";
  121. echo "\t<ul>\n";
  122. echo "\t\t<li><a href=\"".$_SERVER['PHP_SELF']."?action=sortmycourses\">".get_lang("SortMyCourses")."</a></li>\n";
  123. echo "\t\t<li><a href=\"".$_SERVER['PHP_SELF']."?action=createcoursecategory\">".get_lang("CreateCourseCategory")."</a></li>\n";
  124. echo "\t\t<li><a href=\"".$_SERVER['PHP_SELF']."?action=subscribe\">".get_lang("SubscribeToCourse")."</a></li>\n";
  125. echo "\t</ul>\n";
  126. echo "</div>";
  127. echo "<div>";
  128. switch ($_GET['action'])
  129. {
  130. case 'subscribe':
  131. api_display_tool_title(get_lang('SubscribeToCourse'));
  132. courses_subscribing();
  133. break;
  134. case 'unsubscribe':
  135. api_display_tool_title(get_lang('UnsubscribeFromCourse'));
  136. $user_courses=get_courses_of_user($_user['user_id']);
  137. display_courses($_user['user_id'], true, $user_courses);
  138. break;
  139. case 'createcoursecategory':
  140. api_display_tool_title(get_lang('CreateCourseCategory'));
  141. display_create_course_category_form();
  142. break;
  143. case 'deletecoursecategory':
  144. case 'sortmycourses':
  145. default:
  146. api_display_tool_title(get_lang('SortMyCourses'));
  147. $user_courses=get_courses_of_user($_user['user_id']);
  148. display_courses($_user['user_id'], true, $user_courses);
  149. break;
  150. }
  151. echo '</div>';
  152. Display :: display_footer();
  153. /*
  154. ==============================================================================
  155. FUNCTIONS
  156. ==============================================================================
  157. */
  158. /**
  159. * Subscribe the user to a given course
  160. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  161. * @param string $course_code the code of the course the user wants to subscribe to
  162. * @return string we return the message that is displayed when the action is succesfull
  163. */
  164. function subscribe_user($course_code)
  165. {
  166. global $_user;
  167. $all_course_information = CourseManager::get_course_information($course_code);
  168. if ($all_course_information['registration_code']=='' OR $_POST['course_registration_code']==$all_course_information['registration_code'])
  169. {
  170. if (CourseManager::add_user_to_course($_user['user_id'], $course_code))
  171. {
  172. return get_lang('EnrollToCourseSuccessful');
  173. }
  174. else
  175. {
  176. return get_lang('ErrorContactPlatformAdmin');
  177. }
  178. }
  179. else
  180. {
  181. $return='';
  182. if (isset($_POST['course_registration_code']) AND $_POST['course_registration_code']<>$all_course_information['registration_code'])
  183. {
  184. Display::display_error_message(get_lang('CourseRegistrationCodeIncorrect'));
  185. }
  186. $return.=get_lang('CourseRequiresPassword').'<br/>';
  187. $return.=$all_course_information['visual_code'].' - '.$all_course_information['title'];
  188. $return.="<form action=\"".$_SERVER["REQUEST_URI"]."\" method=\"post\">";
  189. $return.="<input type=\"hidden\" name=\"subscribe\" value=\"".$all_course_information['code']."\" />";
  190. $return.="<input type=\"text\" name=\"course_registration_code\" value=\"".$_POST['course_registration_code']."\" />";
  191. $return.="<input type=\"Submit\" name=\"submit_course_registration_code\" value=\"OK\" alt=\"".get_lang("SubmitRegistrationCode")."\" /></form>";
  192. return $return;
  193. }
  194. }
  195. /**
  196. * unsubscribe the user from a given course
  197. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  198. * @param int $user_id The user id of the user that is performing the unsubscribe action
  199. * @param string $course_code the course code of the course the user wants to unsubscribe from
  200. * @return string we return the message that is displayed when the action is succesfull
  201. */
  202. function remove_user_from_course($user_id, $course_code)
  203. {
  204. $tbl_course_user = Database::get_main_table(TABLE_MAIN_COURSE_USER);
  205. // we check (once again) if the user is not course administrator
  206. // because the course administrator cannot unsubscribe himself
  207. // (s)he can only delete the course
  208. $sql_check="SELECT * FROM $tbl_course_user WHERE user_id='".$user_id."' AND course_code='".$course_code."' AND status='1'";
  209. $result_check=api_sql_query($sql_check);
  210. $number_of_rows=mysql_num_rows($result_check);
  211. if ($number_of_rows>0)
  212. {return false;}
  213. else
  214. {
  215. CourseManager::unsubscribe_user($user_id,$course_code);
  216. return get_lang("YouAreNowUnsubscribed");
  217. }
  218. }
  219. /**
  220. * handles the display of the courses to which the user can subscribe
  221. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  222. */
  223. function courses_subscribing()
  224. {
  225. browse_courses();
  226. display_search_courses();
  227. }
  228. /**
  229. * allows you to browse through the course categories (faculties) and subscribe to the courses of
  230. * this category (faculty)
  231. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  232. */
  233. function browse_courses()
  234. {
  235. browse_course_categories();
  236. if (!isset($_POST['search_course']))
  237. {
  238. browse_courses_in_category();
  239. }
  240. }
  241. /**
  242. * counts the number of courses in a given course category
  243. */
  244. function count_courses_in_category($category)
  245. {
  246. $tbl_course = Database::get_main_table(TABLE_MAIN_COURSE);
  247. $sql="SELECT * FROM $tbl_course WHERE category_code".(empty($category)?" IS NULL":"='".$category."'");
  248. $result=api_sql_query($sql);
  249. return mysql_num_rows($result);
  250. }
  251. /**
  252. * displays the browsing of the course categories (faculties)
  253. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  254. * @return HTML code containing a list with all the categories and subcategories and the navigation to go one category up(if needed)
  255. */
  256. function browse_course_categories()
  257. {
  258. $tbl_courses_nodes = Database::get_main_table(TABLE_MAIN_CATEGORY);
  259. echo "<p><b>".get_lang('CourseCategories')."</b>";
  260. $sql= "SELECT * FROM $tbl_courses_nodes WHERE parent_id ".(empty($_GET['category'])?"IS NULL":"='".$_GET['category']."'")." GROUP BY code, parent_id ORDER BY tree_pos ASC";
  261. $result=mysql_query($sql);
  262. echo "<ul>";
  263. while ($row=mysql_fetch_array($result))
  264. {
  265. if ($row['children_count'] > 0 OR count_courses_in_category($row['code'])>0)
  266. {
  267. echo "<li><a href=\"".$_SERVER['PHP_SELF']."?action=subscribe&amp;category=".$row['code']."&amp;up=".$_GET['category']."\">".$row['name']."</a>".
  268. " (".count_courses_in_category($row['code']).")</li>";
  269. }
  270. elseif ($row['nbChilds'] > 0)
  271. {
  272. echo "<li><a href=\"".$_SERVER['PHP_SELF']."?action=subscribe&amp;category=".$row['code']."&amp;up=".$_GET['category']."\">".$row['name']."</a></li>";
  273. }
  274. else
  275. {
  276. echo "<li>".$row['name']."</li>";
  277. }
  278. }
  279. echo "</ul>";
  280. if ($_GET['category'])
  281. {
  282. echo "<a href=\"".$_SERVER['PHP_SELF']."?action=subscribe&amp;category=".$_GET['up']."\">&lt; ".get_lang('UpOneCategory')."</a>";
  283. }
  284. }
  285. /**
  286. * Display all the courses in the given course category. I could have used a parameter here
  287. * but instead I use the already available $_GET['category']
  288. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  289. * @return HTML code: a table with all the courses in a given category (title, code, tutor) and a subscription icon if applicable)
  290. */
  291. function browse_courses_in_category()
  292. {
  293. $tbl_course = Database::get_main_table(TABLE_MAIN_COURSE);
  294. echo "<p><b>".get_lang('CoursesInCategory')."</b>";
  295. $my_category = (empty($_GET['category'])?" IS NULL":"='".mysql_real_escape_string($_GET['category'])."'");
  296. $sql="SELECT * FROM $tbl_course WHERE category_code".$my_category;
  297. $result=api_sql_query($sql);
  298. while ($row=mysql_fetch_array($result))
  299. {
  300. if ($row['registration_code']=='')
  301. {
  302. $registration_code=false;
  303. }
  304. else
  305. {
  306. $registration_code=true;
  307. }
  308. $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);
  309. }
  310. display_subscribe_to_courses($courses);
  311. }
  312. /**
  313. * displays the form for searching for a course and the results if a query has been submitted.
  314. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  315. * @return HTML code: the form for searching for a course
  316. */
  317. function display_search_courses()
  318. {
  319. global $_user;
  320. echo "<p><b>".get_lang("SearchCourse")."</b><br />";
  321. echo "<form class=\"course_list\" method=\"post\" action=\"".$_SERVER['PHP_SELF']."?action=subscribe\">",
  322. "<input type=\"hidden\" name=\"search_course\" value=\"1\" />",
  323. "<input type=\"text\" name=\"search_term\" />",
  324. "&nbsp;<input type=\"submit\" value=\"",get_lang("_search"),"\" />",
  325. "</form>";
  326. if (isset($_POST['search_course']))
  327. {
  328. echo "<p><b>".get_lang("SearchResultsFor")." ".$_POST['search_term']."</b><br />";
  329. $result_search_courses_array=search_courses($_POST['search_term']);
  330. display_subscribe_to_courses($result_search_courses_array);
  331. }
  332. }
  333. /**
  334. * This function displays the list of course that can be subscribed to.
  335. * This list can come from the search results or from the browsing of the platform course categories
  336. */
  337. function display_subscribe_to_courses($courses)
  338. {
  339. global $_user;
  340. // getting all the courses to which the user is subscribed to
  341. $user_courses=get_courses_of_user($_user['user_id']);
  342. $user_coursecodes=array();
  343. // we need only the course codes as these will be used to match against the courses of the category
  344. if ($user_courses<>"")
  345. {
  346. foreach ($user_courses as $key=>$value)
  347. {
  348. $user_coursecodes[]=$value['code'];
  349. }
  350. }
  351. if ($courses==0)
  352. {
  353. return false;
  354. }
  355. echo "<table cellpadding=\"4\">\n";
  356. foreach ($courses as $key=>$course)
  357. {
  358. // displaying the course title, visual code and teacher/teaching staff
  359. echo "\t<tr>\n";
  360. echo "\t\t<td>\n";
  361. echo "<b>".$course['title']."</b><br />";
  362. if (get_setting("display_coursecode_in_courselist") == "true")
  363. {
  364. echo $course['visual_code'];
  365. }
  366. if (get_setting("display_coursecode_in_courselist") == "true" AND get_setting("display_teacher_in_courselist") == "true")
  367. {
  368. echo " - ";
  369. }
  370. if (get_setting("display_teacher_in_courselist") == "true")
  371. {
  372. echo $course['tutor'];
  373. }
  374. echo "\t\t</td>\n";
  375. echo "\t\t<td>\n";
  376. if ($course['registration_code'])
  377. {
  378. Display::display_icon('passwordprotected.png','',array('style'=>'float:left;'));
  379. }
  380. display_subscribe_icon($course, $user_coursecodes);
  381. echo "\t\t</td>\n";
  382. echo "</tr>";
  383. }
  384. echo "</table>";
  385. }
  386. /**
  387. * This function filters dangerous stuff out. It does addslashes when the php.ini setting
  388. * magic_quotes is set to off.
  389. * @author Olivier Cauberghe <olivier.cauberghe@UGent.be>, Ghent University
  390. * @param string something that possibly needs addslashing
  391. * @return string the addslahed version of the input
  392. */
  393. function escape($s)
  394. {
  395. if(!get_magic_quotes_gpc())
  396. return addslashes($s);
  397. else return $s;
  398. }
  399. /**
  400. * Search the courses database for a course that matches the search term.
  401. * The search is done on the code, title and tutor field of the course table.
  402. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  403. * @param string $search_term: the string that the user submitted, what we are looking for
  404. * @return array an array containing a list of all the courses (the code, directory, dabase, visual_code, title, ... )
  405. * matching the the search term.
  406. */
  407. function search_courses($search_term)
  408. {
  409. $TABLECOURS = Database::get_main_table(TABLE_MAIN_COURSE);
  410. $search_term_safe=escape($search_term);
  411. $sql_find="SELECT * FROM $TABLECOURS WHERE code LIKE '%".$search_term_safe."%' OR title LIKE '%".$search_term_safe."%' OR tutor_name LIKE '%".$search_term_safe."%'";
  412. $result_find=mysql_query($sql_find) or die(mysql_error());
  413. while ($row=mysql_fetch_array($result_find))
  414. {
  415. $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']);
  416. }
  417. return $courses;
  418. }
  419. /**
  420. * deletes a course category and moves all the courses that were in this category to main category
  421. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  422. * @param int $id: the id of the user_course_category
  423. * @return string a language variable saying that the deletion went OK.
  424. */
  425. function delete_course_category($id)
  426. {
  427. global $_user, $_configuration;
  428. $DATABASE_USER_TOOLS = $_configuration['user_personal_database'];
  429. $TABLE_USER_COURSE_CATEGORY = $DATABASE_USER_TOOLS."`.`user_course_category";
  430. $TABLECOURSUSER=Database::get_main_table(TABLE_MAIN_COURSE_USER);
  431. $id = intval($id);
  432. $sql_delete="DELETE FROM `$TABLE_USER_COURSE_CATEGORY` WHERE id='".$id."' and user_id='".$_user['user_id']."'";
  433. $sql_update="UPDATE $TABLECOURSUSER SET user_course_cat='0' WHERE user_course_cat='".$id."' AND user_id='".$_user['user_id']."'";
  434. mysql_query($sql_delete) or die(mysql_error());
  435. mysql_query($sql_update) or die(mysql_error());
  436. return get_lang("CourseCategoryDeleted");
  437. }
  438. /**
  439. * stores the user course category in the dokeos_user database
  440. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  441. * @return string a language variable saying that the user course category was stored
  442. */
  443. function store_course_category()
  444. {
  445. global $_user, $_configuration;
  446. $DATABASE_USER_TOOLS = $_configuration['user_personal_database'];
  447. $TABLE_USER_COURSE_CATEGORY = $DATABASE_USER_TOOLS."`.`user_course_category";
  448. // step 1: we determine the max value of the user defined course categories
  449. $sql="SELECT sort FROM `$TABLE_USER_COURSE_CATEGORY` WHERE user_id='".$_user['user_id']."' ORDER BY sort DESC";
  450. $result=api_sql_query($sql);
  451. $maxsort=mysql_fetch_array($result);
  452. $nextsort=$maxsort['sort']+1;
  453. $sql_insert="INSERT INTO `$TABLE_USER_COURSE_CATEGORY` (user_id, title,sort) VALUES ('".$_user['user_id']."', '".htmlentities($_POST['title_course_category'])."', '".$nextsort."')";
  454. api_sql_query($sql_insert);
  455. return get_lang("CourseCategoryStored");
  456. }
  457. /**
  458. * displays the form that is needed to create a course category.
  459. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  460. * @return HTML the form (input field + submit button) to create a user course category
  461. */
  462. function display_create_course_category_form()
  463. {
  464. global $_user, $_configuration;
  465. echo "<form name=\"create_course_category\" method=\"post\" action=\"".$_SERVER['PHP_SELF']."?action=sortmycourses\">\n";
  466. echo "<input type=\"text\" name=\"title_course_category\" />\n";
  467. echo "<input type=\"submit\" name=\"create_course_category\" value=\"".get_lang("Ok")."\" />\n";
  468. echo "</form>\n";
  469. echo get_lang("ExistingCourseCategories");
  470. $DATABASE_USER_TOOLS = $_configuration['user_personal_database'];
  471. $TABLE_USER_COURSE_CATEGORY = $DATABASE_USER_TOOLS."`.`user_course_category";
  472. $sql="SELECT * FROM `$TABLE_USER_COURSE_CATEGORY` WHERE user_id='".$_user['user_id']."'";
  473. $result=api_sql_query($sql, __LINE__, __FILE__);
  474. if (mysql_num_rows($result)>0)
  475. {
  476. echo "<ul>\n";
  477. while ($row=mysql_fetch_array($result))
  478. {
  479. echo "\t<li>".$row['title']."</li>\n";
  480. }
  481. echo "</ul>\n";
  482. }
  483. }
  484. // ***************************************************************************
  485. // this function stores the changes in a course category
  486. //
  487. // ***************************************************************************
  488. /**
  489. * stores the changes in a course category (moving a course to a different course category)
  490. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  491. * @param string $course_code : the course_code of the course we are moving
  492. * int $newcategory : the id of the user course category we are moving the course to.
  493. * @return string a language variable saying that the course was moved.
  494. */
  495. function store_changecoursecategory($course_code, $newcategory)
  496. {
  497. global $_user;
  498. $TABLECOURSUSER = Database::get_main_table(TABLE_MAIN_COURSE_USER);
  499. $max_sort_value=api_max_sort_value($newcategory,$_user['user_id']); //max_sort_value($newcategory);
  500. $sql="UPDATE $TABLECOURSUSER SET user_course_cat='".$newcategory."', sort='".($max_sort_value+1)."' WHERE course_code='".$course_code."' AND user_id='".$_user['user_id']."'";
  501. $result=api_sql_query($sql);
  502. return get_lang("EditCourseCategorySucces");
  503. }
  504. /**
  505. * moves the course one place up or down
  506. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  507. * @param string $direction : the direction we are moving the course to (up or down)
  508. * string $course2move : the course we are moving
  509. * @return string a language variable saying that the course was moved.
  510. */
  511. function move_course($direction, $course2move, $category)
  512. {
  513. global $_user;
  514. $TABLECOURSUSER = Database::get_main_table(TABLE_MAIN_COURSE_USER);
  515. $all_user_courses=get_courses_of_user($_user['user_id']);
  516. // we need only the courses of the category we are moving in
  517. foreach ($all_user_courses as $key=>$course)
  518. {
  519. if ($course['user_course_category']==$category)
  520. {
  521. $user_courses[]=$course;
  522. }
  523. }
  524. foreach ($user_courses as $key=>$course)
  525. {
  526. if ($course2move==$course['code'])
  527. {
  528. // source_course is the course where we clicked the up or down icon
  529. $source_course=$course;
  530. // target_course is the course before/after the source_course (depending on the up/down icon)
  531. if ($direction=="up")
  532. {$target_course=$user_courses[$key-1];}
  533. else
  534. {$target_course=$user_courses[$key+1];}
  535. } // if ($course2move==$course['code'])
  536. }
  537. $sql_update1="UPDATE $TABLECOURSUSER SET sort='".$target_course['sort']."' WHERE course_code='".$source_course['code']."' AND user_id='".$_user['user_id']."'";
  538. $sql_update2="UPDATE $TABLECOURSUSER SET sort='".$source_course['sort']."' WHERE course_code='".$target_course['code']."' AND user_id='".$_user['user_id']."'";
  539. mysql_query($sql_update2);
  540. mysql_query($sql_update1);
  541. return get_lang("CourseSortingDone");
  542. }
  543. /**
  544. * moves the course one place up or down
  545. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  546. * @param string $direction : the direction we are moving the course to (up or down)
  547. * string $course2move : the course we are moving
  548. * @return string a language variable saying that the course was moved.
  549. */
  550. function move_category($direction, $category2move)
  551. {
  552. global $_user;
  553. // the database definition of the table that stores the user defined course categories
  554. $table_user_defined_category = Database::get_user_personal_table(TABLE_USER_COURSE_CATEGORY);
  555. $user_coursecategories=get_user_course_categories();
  556. foreach ($user_coursecategories as $key=>$categoryid)
  557. {
  558. if ($category2move==$categoryid)
  559. {
  560. // source_course is the course where we clicked the up or down icon
  561. $source_category=get_user_course_category($category2move);
  562. // target_course is the course before/after the source_course (depending on the up/down icon)
  563. if ($direction=="up")
  564. {$target_category=get_user_course_category($user_coursecategories[$key-1]);}
  565. else
  566. {$target_category=get_user_course_category($user_coursecategories[$key+1]);}
  567. } // if ($course2move==$course['code'])
  568. } // foreach ($user_courses as $key=>$course)
  569. $sql_update1="UPDATE $table_user_defined_category SET sort='".$target_category['sort']."' WHERE id='".$source_category['id']."' AND user_id='".$_user['user_id']."'";
  570. $sql_update2="UPDATE $table_user_defined_category SET sort='".$source_category['sort']."' WHERE id='".$target_category['id']."' AND user_id='".$_user['user_id']."'";
  571. mysql_query($sql_update2);
  572. mysql_query($sql_update1);
  573. return get_lang("CategorySortingDone");
  574. }
  575. /**
  576. * displays everything that is needed when the user wants to manage his current courses (sorting, subscribing, unsubscribing, ...)
  577. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  578. * @param int $user_id: the user_id of the current user
  579. * string $parameter: determines weither we are displaying for the sorting, subscribing or unsubscribin
  580. array $user_courses: the courses to which the user is subscribed
  581. * @return html a table containing courses and the appropriate icons (sub/unsub/move)
  582. */
  583. function display_courses($user_id, $show_course_icons, $user_courses)
  584. {
  585. global $_user, $_configuration;
  586. echo "<table cellpadding=\"4\">\n";
  587. // building an array that contains all the id's of the user defined course categories
  588. // initially this was inside the display_courses_in_category function but when we do it here we have fewer
  589. // sql executions = performance increase.
  590. $all_user_categories=get_user_course_categories();
  591. // step 0: we display the course without a user category
  592. display_courses_in_category(0,'true');
  593. // Step 1: we get all the categories of the user
  594. $DATABASE_USER_TOOLS = $_configuration['user_personal_database'];
  595. $TABLE_USER_COURSE_CATEGORY = $DATABASE_USER_TOOLS."`.`user_course_category";
  596. $sql="SELECT * FROM `$TABLE_USER_COURSE_CATEGORY` WHERE user_id='".$_user['user_id']."' ORDER BY sort ASC";
  597. $result=api_sql_query($sql);
  598. while ($row=mysql_fetch_array($result))
  599. {
  600. if ($show_course_icons=true)
  601. {
  602. // the edit link is clicked: we display the edit form for the category
  603. if (isset($_GET['categoryid']) AND $_GET['categoryid']==$row['id'])
  604. {
  605. echo "<tr><td colspan=\"2\" class=\"user_course_category\">";
  606. echo '<a name="category'.$row['id'].'"></a>'; // display an internal anchor.
  607. display_edit_course_category_form($row['id']);
  608. }
  609. // we simply display the title of the catgory
  610. else
  611. {
  612. $info_this_user_course_category=get_user_course_category($row['id']);
  613. echo "<tr><td colspan=\"2\" class=\"user_course_category\">";
  614. echo '<a name="category'.$row['id'].'"></a>'; // display an internal anchor.
  615. echo $info_this_user_course_category['title'];
  616. }
  617. echo "</td><td class=\"user_course_category\">";
  618. display_category_icons($row['id'],$all_user_categories);
  619. echo "</td></tr>";
  620. }
  621. // Step 2: show the courses inside this category
  622. display_courses_in_category($row['id'], $show_course_icons);
  623. }
  624. echo "</table>\n";
  625. }
  626. /**
  627. * This function displays all the courses in the particular user category;
  628. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  629. * @param int id: the id of the user defined course category
  630. * @return string: the name of the user defined course category
  631. */
  632. function display_courses_in_category($user_category_id, $showicons)
  633. {
  634. global $_user;
  635. // table definitions
  636. $TABLECOURS=Database::get_main_table(TABLE_MAIN_COURSE);
  637. $TABLECOURSUSER=Database::get_main_table(TABLE_MAIN_COURSE_USER);
  638. $TABLE_USER_COURSE_CATEGORY = "`".Database::get_user_personal_database()."`.`user_course_category`";
  639. $sql_select_courses="SELECT course.code, course.visual_code, course.subscribe subscr, course.unsubscribe unsubscr,
  640. course.title title, course.tutor_name tutor, course.db_name, course.directory, course_rel_user.status status,
  641. course_rel_user.sort sort, course_rel_user.user_course_cat user_course_cat
  642. FROM $TABLECOURS course,
  643. $TABLECOURSUSER course_rel_user
  644. WHERE course.code = course_rel_user.course_code
  645. AND course_rel_user.user_id = '".$_user['user_id']."'
  646. AND course_rel_user.user_course_cat='".$user_category_id."'
  647. ORDER BY course_rel_user.user_course_cat, course_rel_user.sort ASC";
  648. $result = api_sql_query($sql_select_courses) or die(mysql_error());
  649. $number_of_courses=mysql_num_rows($result);
  650. $key=0;
  651. while ($course=mysql_fetch_array($result))
  652. {
  653. echo "\t<tr>\n";
  654. echo "\t\t<td>\n";
  655. echo '<a name="course'.$course['code'].'"></a>'; // display an internal anchor.
  656. echo "<b>".$course['title']."</b><br />";
  657. if (get_setting("display_coursecode_in_courselist") == "true")
  658. {
  659. echo $course['visual_code'];
  660. }
  661. if (get_setting("display_coursecode_in_courselist") == "true" AND get_setting("display_teacher_in_courselist") == "true")
  662. {
  663. echo " - ";
  664. }
  665. if (get_setting("display_teacher_in_courselist") == "true")
  666. {
  667. echo $course['tutor'];
  668. }
  669. echo "\t\t</td>\n";
  670. // displaying the up/down/edit icons when we are sorting courses
  671. echo "\t\t<td valign=\"top\">\n";
  672. //if ($parameter=="sorting")
  673. //{
  674. display_course_icons($key, $number_of_courses, $course, $user_courses);
  675. //}
  676. // displaying the delete icon when we are unsubscribing from courses
  677. //if($parameter=="deleting")
  678. //{
  679. // display_unsubscribe_icons($course);
  680. //}
  681. // display the subscribing icon when we are to courses.
  682. //if ($parameter=="subscribing")
  683. //{
  684. // display_subscribe_icon($course);
  685. //}
  686. echo "\t\t</td>\n";
  687. echo "\t</tr>\n";
  688. $key++;
  689. }
  690. }
  691. /**
  692. * gets the title of the user course category
  693. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  694. * @param int id: the id of the user defined course category
  695. * @return string: the name of the user defined course category
  696. */
  697. function get_user_course_category($id)
  698. {
  699. global $_user, $_configuration;
  700. $DATABASE_USER_TOOLS = $_configuration['user_personal_database'];
  701. $TABLE_USER_COURSE_CATEGORY = $DATABASE_USER_TOOLS."`.`user_course_category";
  702. $id = intval($id);
  703. $sql="SELECT * FROM `".$TABLE_USER_COURSE_CATEGORY."` WHERE user_id='".$_user['user_id']."' AND id='$id'";
  704. $result=mysql_query($sql) or die(mysql_error());
  705. $row=mysql_fetch_array($result);
  706. return $row;
  707. }
  708. /**
  709. * displays the subscribe icon if the subscribing is allowed and if the user is not yet
  710. * subscribe to this course
  711. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  712. * @param string $current_course: the course code of the course we need to display the subscribe icon for
  713. * @return string a subscribe icon or the text that subscribing is not allowed or the user is already subscribed
  714. */
  715. function display_subscribe_icon($current_course, $user_coursecodes)
  716. {
  717. // we display the icon to subscribe or the text already subscribed
  718. if (in_array($current_course['code'],$user_coursecodes))
  719. {
  720. echo get_lang("AlreadySubscribed");
  721. }
  722. else
  723. {
  724. if ($current_course['subscribe'] == SUBSCRIBE_ALLOWED)
  725. {
  726. echo "<form action=\"".$_SERVER["REQUEST_URI"]."\" method=\"post\">";
  727. echo "<input type=\"hidden\" name=\"subscribe\" value=\"".$current_course['code']."\" />";
  728. echo "<input type=\"image\" name=\"unsub\" src=\"../img/enroll.gif\" alt=\"".get_lang("Subscribe")."\" />".get_lang("Subscribe")."</form>";
  729. }
  730. else
  731. {
  732. echo get_lang("SubscribingNotAllowed");
  733. }
  734. }
  735. }
  736. /**
  737. * displays the subscribe icon if the subscribing is allowed and if the user is not yet
  738. * subscribed to this course
  739. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  740. * @param $key:
  741. * $number_of_courses
  742. * $course
  743. * $user_courses
  744. * @return html a small table containing the up/down icons and the edit icon (for moving to a different user course category)
  745. * @todo complete the comments on this function: the parameter section
  746. */
  747. function display_course_icons($key, $number_of_courses, $course, $user_courses)
  748. {
  749. //print_r($course);
  750. echo "<table><tr><td>";
  751. // the up icon
  752. if ($key>0 AND $user_courses[$key-1]['user_course_category']==$course['user_course_category'])
  753. {
  754. echo "<a href=\"courses.php?action=".$_GET['action']."&amp;move=up&amp;course=".$course['code']."&amp;category=".$course['user_course_cat']."\">";
  755. echo "<img src=\"../img/up.gif\" alt=\"".htmlentities(get_lang("Up"))."\"></a>";
  756. }
  757. echo "</td>";
  758. // the edit icon OR the edit dropdown list
  759. if (isset($_GET['edit']) and $course['code']==$_GET['edit'])
  760. {
  761. echo "<td rowspan=\"2\" valign=\"top\">".display_change_course_category_form($_GET['edit'])."</td>";
  762. }
  763. else
  764. {
  765. echo "<td rowspan=\"2\" valign=\"middle\"><a href=\"courses.php?action=".$_GET['action']."&amp;edit=".$course['code']."\">";
  766. Display::display_icon('edit.gif',get_lang('Edit'));
  767. echo "</a></td>";
  768. }
  769. echo "<td rowspan=\"2\" valign=\"top\" class=\"invisible\">";
  770. if ($course['status'] != 1)
  771. {
  772. if ($course['unsubscr'] == 1)
  773. { // changed link to submit to avoid action by the search tool indexer
  774. echo "<form action=\"".$_SERVER['PHP_SELF']."\" method=\"post\" onsubmit=\"javascript:if(!confirm('".addslashes(htmlentities(get_lang("ConfirmUnsubscribeFromCourse")))."')) return false;\">";
  775. echo "<input type=\"hidden\" name=\"unsubscribe\" value=\"".$course['code']."\" />";
  776. echo "<input type=\"image\" name=\"unsub\" src=\"../img/delete.gif\" alt=\"".get_lang("_unsubscribe")."\" /></form>";
  777. }
  778. else
  779. {display_info_text(get_lang("UnsubscribeNotAllowed"));}
  780. }
  781. else
  782. {
  783. display_info_text(get_lang("CourseAdminUnsubscribeNotAllowed"));
  784. }
  785. echo "</td>";
  786. echo "</tr><tr><td>";
  787. if ($key<$number_of_courses-1 AND $user_courses[$key+1]['user_course_category']==$course['user_course_category'])
  788. {
  789. echo "<a href=\"courses.php?action=".$_GET['action']."&amp;move=down&amp;course=".$course['code']."&amp;category=".$course['user_course_cat']."\">";
  790. echo "<img src=\"../img/down.gif\" alt=\"".htmlentities(get_lang("Down"))."\"></a>";
  791. }
  792. echo "</td></tr></table>";
  793. }
  794. /**
  795. * displays the relevant icons for the category (if applicable):move up, move down, edit, delete
  796. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  797. * @param $current_category the id of the current category
  798. * $allcategories an associative array containing all the categories.
  799. * @return html: a small table containing the up/down icons and the edit icon (for moving to a different user course category)
  800. * @todo complete the comments on this function: the parameter section
  801. */
  802. function display_category_icons($current_category, $all_user_categories)
  803. {
  804. $max_category_key=count($all_user_categories);
  805. if ($_GET['action']<>'unsubscribe') // we are in the unsubscribe section then we do not show the icons.
  806. {
  807. echo "<table>";
  808. echo "<tr>";
  809. echo "<td>";
  810. if ($current_category<>$all_user_categories[0])
  811. {
  812. echo "<a href=\"courses.php?action=".$_GET['action']."&amp;move=up&amp;category=".$current_category."\">";
  813. echo "<img src=\"../img/up.gif\" alt=\"".htmlentities(get_lang("Up"))."\"></a>";
  814. }
  815. echo "</td>";
  816. echo " <td rowspan=\"2\">";
  817. echo " <a href=\"courses.php?action=sortmycourses&amp;categoryid=".$current_category."#category".$current_category."\">";
  818. Display::display_icon('edit.gif',get_lang('Edit'));
  819. echo "</a>";
  820. echo "</td>";
  821. echo "<td rowspan=\"2\">";
  822. echo " <a href=\"courses.php?action=deletecoursecategory&amp;id=".$current_category."\">";
  823. Display::display_icon('delete.gif',get_lang('Edit'),array('onclick'=>"javascript:if(!confirm('".addslashes(htmlentities(get_lang("CourseCategoryAbout2bedeleted")))."')) return false;"));
  824. echo "</a>";
  825. echo "</td>";
  826. echo "</tr>";
  827. echo "<tr>";
  828. echo " <td>";
  829. if ($current_category<>$all_user_categories[$max_category_key-1])
  830. {
  831. echo "<a href=\"courses.php?action=".$_GET['action']."&amp;move=down&amp;category=".$current_category."\">";
  832. echo "<img src=\"../img/down.gif\" alt=\"".htmlentities(get_lang("Down"))."\"></a>";
  833. }
  834. echo "</td>";
  835. echo " </tr>";
  836. echo "</table>";
  837. }
  838. }
  839. /**
  840. * This function displays the form (dropdown list) to move a course to a
  841. * different course_category (after the edit icon has been changed)
  842. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  843. * @param string $edit_course:
  844. * @return html a dropdown list containing all the user defined course categories and a submit button
  845. * @todo when editing (moving) a course inside a user defined course category to a different user defined category
  846. * the dropdown list should have the current course category selected.
  847. */
  848. function display_change_course_category_form($edit_course)
  849. {
  850. global $_user, $_configuration;
  851. $DATABASE_USER_TOOLS = $_configuration['user_personal_database'];
  852. $TABLE_USER_COURSE_CATEGORY = $DATABASE_USER_TOOLS."`.`user_course_category";
  853. $sql="SELECT * FROM `$TABLE_USER_COURSE_CATEGORY` WHERE user_id='".$_user['user_id']."'";
  854. $result=api_sql_query($sql);
  855. $output="<form name=\"edit_course_category\" method=\"post\" action=\"courses.php?action=".$_GET['action']."\">\n";
  856. $output.="<input type=\"hidden\" name=\"course_2_edit_category\" value=\"".$edit_course."\" />";
  857. $output.="\t<select name=\"course_categories\">\n";
  858. $output.="\t\t<option value=\"0\">".get_lang("NoCourseCategory")."</option>";
  859. while ($row=mysql_fetch_array($result))
  860. {$output.="\t\t<option value=\"".$row['id']."\">".$row['title']."</option>";}
  861. $output.="\t</select>\n";
  862. $output.="\t<input type=\"submit\" name=\"submit_change_course_category\" value=\"".get_lang("Ok")."\" />\n";
  863. $output.="</form>";
  864. return $output;
  865. }
  866. /**
  867. * This function displays the unsubscribe part which can be
  868. * 1. the unsubscribe link
  869. * 2. text: you are course admin of this course (=> unsubscription is not possible
  870. * 3. text: you are not allowed to unsubscribe from this course
  871. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  872. * @param array $course: the array with all the course & course_rel_user information
  873. * @return html a delete icon or a text that unsubscribing is not possible (course admin) or not allowed.
  874. */
  875. function display_unsubscribe_icons($course)
  876. {
  877. if ($course['status'] != 1)
  878. {
  879. if ($course['unsubscribe'] == 1)
  880. { // changed link to submit to avoid action by the search tool indexer
  881. echo "<form action=\"".$_SERVER['PHP_SELF']."\" method=\"post\" onsubmit=\"javascript:if(!confirm('".addslashes(htmlentities(get_lang("ConfirmUnsubscribeFromCourse")))."')) return false;\">";
  882. echo "<input type=\"hidden\" name=\"unsubscribe\" value=\"".$course['code']."\" />";
  883. echo "<input type=\"image\" name=\"unsub\" src=\"../img/delete.gif\" alt=\"".get_lang("_unsubscribe")."\" /></form>";
  884. }
  885. else
  886. {display_info_text(get_lang("UnsubscribeNotAllowed"));}
  887. }
  888. else
  889. {
  890. display_info_text(get_lang("CourseAdminUnsubscribeNotAllowed"));
  891. }
  892. }
  893. /**
  894. * retrieves all the courses that the user has already subscribed to
  895. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  896. * @param int $user_id: the id of the user
  897. * @return array an array containing all the information of the courses of the given user
  898. */
  899. function get_courses_of_user($user_id)
  900. {
  901. $TABLECOURS=Database::get_main_table(TABLE_MAIN_COURSE);
  902. $TABLECOURSUSER=Database::get_main_table(TABLE_MAIN_COURSE_USER);
  903. // Secondly we select the courses that are in a category (user_course_cat<>0) and sort these according to the sort of the category
  904. $user_id = intval($user_id);
  905. $sql_select_courses="SELECT course.code k, course.visual_code vc, course.subscribe subscr, course.unsubscribe unsubscr,
  906. course.title i, course.tutor_name t, course.db_name db, course.directory dir, course_rel_user.status status,
  907. course_rel_user.sort sort, course_rel_user.user_course_cat user_course_cat
  908. FROM $TABLECOURS course,
  909. $TABLECOURSUSER course_rel_user
  910. WHERE course.code = course_rel_user.course_code
  911. AND course_rel_user.user_id = '".$user_id."'
  912. ORDER BY course_rel_user.sort ASC";
  913. $result = api_sql_query($sql_select_courses) or die(mysql_error());
  914. while ($row=mysql_fetch_array($result))
  915. {
  916. // we only need the database name of the course
  917. $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']);
  918. }
  919. return $courses;
  920. }
  921. /**
  922. * retrieves the user defined course categories
  923. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  924. * @return array containing all the titles of the user defined courses with the id as key of the array
  925. */
  926. function get_user_course_categories()
  927. {
  928. global $_user;
  929. $table_category = Database::get_user_personal_table(TABLE_USER_COURSE_CATEGORY);
  930. $sql = "SELECT * FROM ".$table_category." WHERE user_id='".$_user['user_id']."' ORDER BY sort ASC";
  931. $result = api_sql_query($sql,__FILE__,__LINE__);
  932. while ($row = mysql_fetch_array($result))
  933. {
  934. $output[] = $row['id'];
  935. }
  936. return $output;
  937. }
  938. /**
  939. * @author unknown
  940. * @param string $text: the text that has to be written in grey
  941. * @return string: the text with the grey formatting
  942. * @todo move this to a stylesheet
  943. * Added id grey to CSS
  944. */
  945. function display_info_text($text)
  946. {
  947. //echo "<font color=\"#808080\">" . $text . "</font>\n";
  948. echo $text;
  949. }
  950. /**
  951. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  952. * @param string $edit_course:
  953. * @return html output: the form
  954. */
  955. function display_edit_course_category_form($edit_course_category)
  956. {
  957. echo "<form name=\"edit_course_category\" method=\"post\" action=\"courses.php?action=".$_GET['action']."\">\n";
  958. echo "\t<input type=\"hidden\" name=\"edit_course_category\" value=\"".$edit_course_category."\" />\n";
  959. $info_this_user_course_category=get_user_course_category($edit_course_category);
  960. echo "\t<input type=\"text\" name=\"title_course_category\" value=\"".$info_this_user_course_category['title']."\" />";
  961. echo "\t<input type=\"submit\" name=\"submit_edit_course_category\" value=\"".get_lang("Ok")."\" />\n";
  962. echo "</form>";
  963. }
  964. /**
  965. * Updates the user course category in the dokeos_user database
  966. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  967. * @return string a language variable saying that the user course category was stored
  968. */
  969. function store_edit_course_category()
  970. {
  971. global $_user, $_configuration;
  972. $DATABASE_USER_TOOLS = $_configuration['user_personal_database'];
  973. $TABLE_USER_COURSE_CATEGORY = $DATABASE_USER_TOOLS."`.`user_course_category";
  974. $sql_update="UPDATE `$TABLE_USER_COURSE_CATEGORY` SET title='".htmlentities($_POST['title_course_category'])."' WHERE id='".(int)$_POST['edit_course_category']."'";
  975. mysql_query($sql_update) or die(mysql_error());
  976. //api_sql_query(sql_update);
  977. return get_lang("CourseCategoryEditStored");
  978. }
  979. ?>