courses.php 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110
  1. <?php // $Id: courses.php 9721 2006-10-25 08:23:18Z grayd0n $
  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. // including the relevant language file
  32. $langFile = '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(MAIN_COURSE_TABLE);
  50. $tbl_courses_nodes = Database::get_main_table(MAIN_CATEGORY_TABLE);
  51. $tbl_courseUser = Database::get_main_table(MAIN_COURSE_USER_TABLE);
  52. $tbl_user = Database::get_main_table(MAIN_USER_TABLE);
  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. $userId = $_uid;
  68. unset($message);
  69. // we are moving a course or category of the user up/down the list (=Sort My Courses)
  70. if (isset($_GET['move']))
  71. {
  72. if (isset($_GET['course']))
  73. {
  74. $message=move_course($_GET['move'], $_GET['course'],$_GET['category']);
  75. }
  76. if (isset($_GET['category']) and !$_GET['course'])
  77. {
  78. $message=move_category($_GET['move'], $_GET['category']);
  79. }
  80. }
  81. // we are moving the course of the user to a different user defined course category (=Sort My Courses)
  82. if (isset($_POST['submit_change_course_category']))
  83. {
  84. $message=store_changecoursecategory($_POST['course_2_edit_category'], $_POST['course_categories']);
  85. }
  86. // we are creating a new user defined course category (= Create Course Category)
  87. if (isset($_POST['create_course_category']) AND isset($_POST['title_course_category']) AND strlen(trim($_POST['title_course_category'])) > 0)
  88. {
  89. $message=store_course_category();
  90. }
  91. if (isset($_POST['submit_edit_course_category']) AND isset($_POST['title_course_category']) AND strlen(trim($_POST['title_course_category'])) > 0)
  92. {
  93. $message=store_edit_course_category();
  94. }
  95. // we are subcribing to a course (=Subscribe to course)
  96. if (isset($_POST['subscribe']))
  97. {
  98. $message = subscribe_user($_POST['subscribe']);
  99. }
  100. // we are unsubscribing from a course (=Unsubscribe from course)
  101. if (isset($_POST['unsubscribe']))
  102. {
  103. $message=remove_user_from_course($_uid, $_POST['unsubscribe']);
  104. }
  105. // we are deleting a course category
  106. if ($_GET['action']=='deletecoursecategory' AND isset($_GET['id']))
  107. {
  108. $message=delete_course_category($_GET['id']);
  109. }
  110. // we are displaying any result messages;
  111. if (isset($message))
  112. {
  113. Display::display_normal_message($message);
  114. }
  115. /*
  116. ==============================================================================
  117. DISPLAY SECTION
  118. ==============================================================================
  119. */
  120. // The menu with the different options in the course management
  121. echo "<div>\n";
  122. echo "\t<ul>\n";
  123. echo "\t\t<li><a href=\"".$_SERVER['PHP_SELF']."?action=sortmycourses\">".get_lang("SortMyCourses")."</a></li>\n";
  124. echo "\t\t<li><a href=\"".$_SERVER['PHP_SELF']."?action=createcoursecategory\">".get_lang("CreateCourseCategory")."</a></li>\n";
  125. echo "\t\t<li><a href=\"".$_SERVER['PHP_SELF']."?action=subscribe\">".get_lang("SubscribeToCourse")."</a></li>\n";
  126. echo "\t</ul>\n";
  127. echo "</div>";
  128. echo "<div>";
  129. switch ($_GET['action'])
  130. {
  131. case 'subscribe':
  132. api_display_tool_title(get_lang('SubscribeToCourse'));
  133. courses_subscribing();
  134. break;
  135. case 'unsubscribe':
  136. api_display_tool_title(get_lang('UnsubscribeFromCourse'));
  137. $user_courses=get_courses_of_user($_uid);
  138. display_courses($_uid, true, $user_courses);
  139. break;
  140. case 'createcoursecategory':
  141. api_display_tool_title(get_lang('CreateCourseCategory'));
  142. display_create_course_category_form();
  143. break;
  144. case 'deletecoursecategory':
  145. case 'sortmycourses':
  146. default:
  147. api_display_tool_title(get_lang('SortMyCourses'));
  148. $user_courses=get_courses_of_user($_uid);
  149. display_courses($_uid, true, $user_courses);
  150. break;
  151. }
  152. echo '</div>';
  153. Display :: display_footer();
  154. /*
  155. ==============================================================================
  156. FUNCTIONS
  157. ==============================================================================
  158. */
  159. /**
  160. * Subscribe the user to a given course
  161. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  162. * @param string $course_code the code of the course the user wants to subscribe to
  163. * @return string we return the message that is displayed when the action is succesfull
  164. */
  165. function subscribe_user($course_code)
  166. {
  167. global $_uid;
  168. $all_course_information = CourseManager::get_course_information($course_code);
  169. if ($all_course_information['registration_code']=='' OR $_POST['course_registration_code']==$all_course_information['registration_code'])
  170. {
  171. if (CourseManager::add_user_to_course($_uid, $course_code))
  172. {
  173. return get_lang('EnrollToCourseSuccessful');
  174. }
  175. else
  176. {
  177. return get_lang('ErrorContactPlatformAdmin');
  178. }
  179. }
  180. else
  181. {
  182. $return='';
  183. if (isset($_POST['course_registration_code']) AND $_POST['course_registration_code']<>$all_course_information['registration_code'])
  184. {
  185. Display::display_error_message(get_lang('CourseRegistrationCodeIncorrect'));
  186. }
  187. $return.=get_lang('CourseRequiresPassword').'<br/>';
  188. $return.=$all_course_information['visual_code'].' - '.$all_course_information['title'];
  189. $return.="<form action=\"".$_SERVER["REQUEST_URI"]."\" method=\"post\">";
  190. $return.="<input type=\"hidden\" name=\"subscribe\" value=\"".$all_course_information['code']."\" />";
  191. $return.="<input type=\"text\" name=\"course_registration_code\" value=\"".$_POST['course_registration_code']."\" />";
  192. $return.="<input type=\"Submit\" name=\"submit_course_registration_code\" value=\"OK\" alt=\"".get_lang("SubmitRegistrationCode")."\" /></form>";
  193. return $return;
  194. }
  195. }
  196. /**
  197. * unsubscribe the user from a given course
  198. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  199. * @param int $user_id The user id of the user that is performing the unsubscribe action
  200. * @param string $course_code the course code of the course the user wants to unsubscribe from
  201. * @return string we return the message that is displayed when the action is succesfull
  202. */
  203. function remove_user_from_course($user_id, $course_code)
  204. {
  205. $tbl_course_user = Database::get_main_table(MAIN_COURSE_USER_TABLE);
  206. // we check (once again) if the user is not course administrator
  207. // because the course administrator cannot unsubscribe himself
  208. // (s)he can only delete the course
  209. $sql_check="SELECT * FROM $tbl_course_user WHERE user_id='".$user_id."' AND course_code='".$course_code."' AND status='1'";
  210. $result_check=api_sql_query($sql_check);
  211. $number_of_rows=mysql_num_rows($result_check);
  212. if ($number_of_rows>0)
  213. {return false;}
  214. else
  215. {
  216. CourseManager::unsubscribe_user($user_id,$course_code);
  217. return get_lang("YouAreNowUnsubscribed");
  218. }
  219. }
  220. /**
  221. * handles the display of the courses to which the user can subscribe
  222. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  223. */
  224. function courses_subscribing()
  225. {
  226. browse_courses();
  227. display_search_courses();
  228. }
  229. /**
  230. * allows you to browse through the course categories (faculties) and subscribe to the courses of
  231. * this category (faculty)
  232. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  233. */
  234. function browse_courses()
  235. {
  236. browse_course_categories();
  237. if (!isset($_POST['search_course']))
  238. {
  239. browse_courses_in_category();
  240. }
  241. }
  242. /**
  243. * counts the number of courses in a given course category
  244. */
  245. function count_courses_in_category($category)
  246. {
  247. $tbl_course = Database::get_main_table(MAIN_COURSE_TABLE);
  248. $sql="SELECT * FROM $tbl_course WHERE category_code".(empty($category)?" IS NULL":"='".$category."'");
  249. $result=api_sql_query($sql);
  250. return mysql_num_rows($result);
  251. }
  252. /**
  253. * displays the browsing of the course categories (faculties)
  254. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  255. * @return HTML code containing a list with all the categories and subcategories and the navigation to go one category up(if needed)
  256. */
  257. function browse_course_categories()
  258. {
  259. $tbl_courses_nodes = Database::get_main_table(MAIN_CATEGORY_TABLE);
  260. echo "<p><b>".get_lang('CourseCategories')."</b>";
  261. $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";
  262. $result=mysql_query($sql);
  263. echo "<ul>";
  264. while ($row=mysql_fetch_array($result))
  265. {
  266. if ($row['children_count'] > 0 OR count_courses_in_category($row['code'])>0)
  267. {
  268. echo "<li><a href=\"".$_SERVER['PHP_SELF']."?action=subscribe&amp;category=".$row['code']."&amp;up=".$_GET['category']."\">".$row['name']."</a>".
  269. " (".count_courses_in_category($row['code']).")</li>";
  270. }
  271. elseif ($row['nbChilds'] > 0)
  272. {
  273. echo "<li><a href=\"".$_SERVER['PHP_SELF']."?action=subscribe&amp;category=".$row['code']."&amp;up=".$_GET['category']."\">".$row['name']."</a></li>";
  274. }
  275. else
  276. {
  277. echo "<li>".$row['name']."</li>";
  278. }
  279. }
  280. echo "</ul>";
  281. if ($_GET['category'])
  282. {
  283. echo "<a href=\"".$_SERVER['PHP_SELF']."?action=subscribe&amp;category=".$_GET['up']."\">&lt; ".get_lang('UpOneCategory')."</a>";
  284. }
  285. }
  286. /**
  287. * Display all the courses in the given course category. I could have used a parameter here
  288. * but instead I use the already available $_GET['category']
  289. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  290. * @return HTML code: a table with all the courses in a given category (title, code, tutor) and a subscription icon if applicable)
  291. */
  292. function browse_courses_in_category()
  293. {
  294. $tbl_course = Database::get_main_table(MAIN_COURSE_TABLE);
  295. echo "<p><b>".get_lang('CoursesInCategory')."</b>";
  296. $sql="SELECT * FROM $tbl_course WHERE category_code".(empty($_GET['category'])?" IS NULL":"='".$_GET['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 $_uid;
  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 $_uid;
  340. // getting all the courses to which the user is subscribed to
  341. $user_courses=get_courses_of_user($_uid);
  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(MAIN_COURSE_TABLE);
  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 $_uid, $user_personal_database;
  428. $DATABASE_USER_TOOLS = $user_personal_database;
  429. $TABLE_USER_COURSE_CATEGORY = $DATABASE_USER_TOOLS."`.`user_course_category";
  430. $TABLECOURSUSER=Database::get_main_table(MAIN_COURSE_USER_TABLE);
  431. $sql_delete="DELETE FROM `$TABLE_USER_COURSE_CATEGORY` WHERE id='".$id."' and user_id='".$_uid."'";
  432. $sql_update="UPDATE $TABLECOURSUSER SET user_course_cat='0' WHERE user_course_cat='".$id."' AND user_id='".$_uid."'";
  433. mysql_query($sql_delete) or die(mysql_error());
  434. mysql_query($sql_update) or die(mysql_error());
  435. return get_lang("CourseCategoryDeleted");
  436. }
  437. /**
  438. * stores the user course category in the dokeos_user database
  439. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  440. * @return string a language variable saying that the user course category was stored
  441. */
  442. function store_course_category()
  443. {
  444. global $_uid, $user_personal_database;
  445. $DATABASE_USER_TOOLS = $user_personal_database;
  446. $TABLE_USER_COURSE_CATEGORY = $DATABASE_USER_TOOLS."`.`user_course_category";
  447. // step 1: we determine the max value of the user defined course categories
  448. $sql="SELECT sort FROM `$TABLE_USER_COURSE_CATEGORY` WHERE user_id='".$_uid."' ORDER BY sort DESC";
  449. $result=api_sql_query($sql);
  450. $maxsort=mysql_fetch_array($result);
  451. $nextsort=$maxsort['sort']+1;
  452. $sql_insert="INSERT INTO `$TABLE_USER_COURSE_CATEGORY` (user_id, title,sort) VALUES ('".$_uid."', '".htmlentities($_POST['title_course_category'])."', '".$nextsort."')";
  453. api_sql_query($sql_insert);
  454. return get_lang("CourseCategoryStored");
  455. }
  456. /**
  457. * displays the form that is needed to create a course category.
  458. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  459. * @return HTML the form (input field + submit button) to create a user course category
  460. */
  461. function display_create_course_category_form()
  462. {
  463. global $_uid, $user_personal_database;
  464. echo "<form name=\"create_course_category\" method=\"post\" action=\"".$_SERVER['PHP_SELF']."?action=sortmycourses\">\n";
  465. echo "<input type=\"text\" name=\"title_course_category\" />\n";
  466. echo "<input type=\"submit\" name=\"create_course_category\" value=\"".get_lang("Ok")."\" />\n";
  467. echo "</form>\n";
  468. echo get_lang("ExistingCourseCategories");
  469. $DATABASE_USER_TOOLS = $user_personal_database;
  470. $TABLE_USER_COURSE_CATEGORY = $DATABASE_USER_TOOLS."`.`user_course_category";
  471. $sql="SELECT * FROM `$TABLE_USER_COURSE_CATEGORY` WHERE user_id='".$_uid."'";
  472. $result=api_sql_query($sql, __LINE__, __FILE__);
  473. if (mysql_num_rows($result)>0)
  474. {
  475. echo "<ul>\n";
  476. while ($row=mysql_fetch_array($result))
  477. {
  478. echo "\t<li>".$row['title']."</li>\n";
  479. }
  480. echo "</ul>\n";
  481. }
  482. }
  483. // ***************************************************************************
  484. // this function stores the changes in a course category
  485. //
  486. // ***************************************************************************
  487. /**
  488. * stores the changes in a course category (moving a course to a different course category)
  489. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  490. * @param string $course_code : the course_code of the course we are moving
  491. * int $newcategory : the id of the user course category we are moving the course to.
  492. * @return string a language variable saying that the course was moved.
  493. */
  494. function store_changecoursecategory($course_code, $newcategory)
  495. {
  496. global $_uid;
  497. $TABLECOURSUSER = Database::get_main_table(MAIN_COURSE_USER_TABLE);
  498. $max_sort_value=api_max_sort_value($newcategory,$_uid); //max_sort_value($newcategory);
  499. $sql="UPDATE $TABLECOURSUSER SET user_course_cat='".$newcategory."', sort='".($max_sort_value+1)."' WHERE course_code='".$course_code."' AND user_id='".$_uid."'";
  500. $result=api_sql_query($sql);
  501. return get_lang("EditCourseCategorySucces");
  502. }
  503. /**
  504. * moves the course one place up or down
  505. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  506. * @param string $direction : the direction we are moving the course to (up or down)
  507. * string $course2move : the course we are moving
  508. * @return string a language variable saying that the course was moved.
  509. */
  510. function move_course($direction, $course2move, $category)
  511. {
  512. global $_uid;
  513. $TABLECOURSUSER = Database::get_main_table(MAIN_COURSE_USER_TABLE);
  514. $all_user_courses=get_courses_of_user($_uid);
  515. // we need only the courses of the category we are moving in
  516. foreach ($all_user_courses as $key=>$course)
  517. {
  518. if ($course['user_course_category']==$category)
  519. {
  520. $user_courses[]=$course;
  521. }
  522. }
  523. foreach ($user_courses as $key=>$course)
  524. {
  525. if ($course2move==$course['code'])
  526. {
  527. // source_course is the course where we clicked the up or down icon
  528. $source_course=$course;
  529. // target_course is the course before/after the source_course (depending on the up/down icon)
  530. if ($direction=="up")
  531. {$target_course=$user_courses[$key-1];}
  532. else
  533. {$target_course=$user_courses[$key+1];}
  534. } // if ($course2move==$course['code'])
  535. }
  536. $sql_update1="UPDATE $TABLECOURSUSER SET sort='".$target_course['sort']."' WHERE course_code='".$source_course['code']."' AND user_id='".$_uid."'";
  537. $sql_update2="UPDATE $TABLECOURSUSER SET sort='".$source_course['sort']."' WHERE course_code='".$target_course['code']."' AND user_id='".$_uid."'";
  538. mysql_query($sql_update2);
  539. mysql_query($sql_update1);
  540. return get_lang("CourseSortingDone");
  541. }
  542. /**
  543. * moves the course one place up or down
  544. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  545. * @param string $direction : the direction we are moving the course to (up or down)
  546. * string $course2move : the course we are moving
  547. * @return string a language variable saying that the course was moved.
  548. */
  549. function move_category($direction, $category2move)
  550. {
  551. global $_uid;
  552. // the database definition of the table that stores the user defined course categories
  553. $table_user_defined_category = Database::get_user_personal_table(USER_COURSE_CATEGORY_TABLE);
  554. $user_coursecategories=get_user_course_categories();
  555. foreach ($user_coursecategories as $key=>$categoryid)
  556. {
  557. if ($category2move==$categoryid)
  558. {
  559. // source_course is the course where we clicked the up or down icon
  560. $source_category=get_user_course_category($category2move);
  561. // target_course is the course before/after the source_course (depending on the up/down icon)
  562. if ($direction=="up")
  563. {$target_category=get_user_course_category($user_coursecategories[$key-1]);}
  564. else
  565. {$target_category=get_user_course_category($user_coursecategories[$key+1]);}
  566. } // if ($course2move==$course['code'])
  567. } // foreach ($user_courses as $key=>$course)
  568. $sql_update1="UPDATE $table_user_defined_category SET sort='".$target_category['sort']."' WHERE id='".$source_category['id']."' AND user_id='".$_uid."'";
  569. $sql_update2="UPDATE $table_user_defined_category SET sort='".$source_category['sort']."' WHERE id='".$target_category['id']."' AND user_id='".$_uid."'";
  570. mysql_query($sql_update2);
  571. mysql_query($sql_update1);
  572. return get_lang("CategorySortingDone");
  573. }
  574. /**
  575. * displays everything that is needed when the user wants to manage his current courses (sorting, subscribing, unsubscribing, ...)
  576. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  577. * @param int $user_id: the user_id of the current user
  578. * string $parameter: determines weither we are displaying for the sorting, subscribing or unsubscribin
  579. array $user_courses: the courses to which the user is subscribed
  580. * @return html a table containing courses and the appropriate icons (sub/unsub/move)
  581. */
  582. function display_courses($user_id, $show_course_icons, $user_courses)
  583. {
  584. global $_uid, $user_personal_database;
  585. echo "<table cellpadding=\"4\">\n";
  586. // building an array that contains all the id's of the user defined course categories
  587. // initially this was inside the display_courses_in_category function but when we do it here we have fewer
  588. // sql executions = performance increase.
  589. $all_user_categories=get_user_course_categories();
  590. // step 0: we display the course without a user category
  591. display_courses_in_category(0,'true');
  592. // Step 1: we get all the categories of the user
  593. $DATABASE_USER_TOOLS = $user_personal_database;
  594. $TABLE_USER_COURSE_CATEGORY = $DATABASE_USER_TOOLS."`.`user_course_category";
  595. $sql="SELECT * FROM `$TABLE_USER_COURSE_CATEGORY` WHERE user_id=$_uid ORDER BY sort ASC";
  596. $result=api_sql_query($sql);
  597. while ($row=mysql_fetch_array($result))
  598. {
  599. if ($show_course_icons=true)
  600. {
  601. // the edit link is clicked: we display the edit form for the category
  602. if (isset($_GET['categoryid']) AND $_GET['categoryid']==$row['id'])
  603. {
  604. echo "<tr><td colspan=\"2\" class=\"user_course_category\">";
  605. echo '<a name="category'.$row['id'].'"></a>'; // display an internal anchor.
  606. display_edit_course_category_form($row['id']);
  607. }
  608. // we simply display the title of the catgory
  609. else
  610. {
  611. $info_this_user_course_category=get_user_course_category($row['id']);
  612. echo "<tr><td colspan=\"2\" class=\"user_course_category\">";
  613. echo '<a name="category'.$row['id'].'"></a>'; // display an internal anchor.
  614. echo $info_this_user_course_category['title'];
  615. }
  616. echo "</td><td class=\"user_course_category\">";
  617. display_category_icons($row['id'],$all_user_categories);
  618. echo "</td></tr>";
  619. }
  620. // Step 2: show the courses inside this category
  621. display_courses_in_category($row['id'], $show_course_icons);
  622. }
  623. echo "</table>\n";
  624. }
  625. /**
  626. * This function displays all the courses in the particular user category;
  627. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  628. * @param int id: the id of the user defined course category
  629. * @return string: the name of the user defined course category
  630. */
  631. function display_courses_in_category($user_category_id, $showicons)
  632. {
  633. global $_uid;
  634. // table definitions
  635. $TABLECOURS=Database::get_main_table(MAIN_COURSE_TABLE);
  636. $TABLECOURSUSER=Database::get_main_table(MAIN_COURSE_USER_TABLE);
  637. $TABLE_USER_COURSE_CATEGORY = "`".Database::get_user_personal_database()."`.`user_course_category`";
  638. $sql_select_courses="SELECT course.code, course.visual_code, course.subscribe subscr, course.unsubscribe unsubscr,
  639. course.title title, course.tutor_name tutor, course.db_name, course.directory, course_rel_user.status status,
  640. course_rel_user.sort sort, course_rel_user.user_course_cat user_course_cat
  641. FROM $TABLECOURS course,
  642. $TABLECOURSUSER course_rel_user
  643. WHERE course.code = course_rel_user.course_code
  644. AND course_rel_user.user_id = '".$_uid."'
  645. AND course_rel_user.user_course_cat='".$user_category_id."'
  646. ORDER BY course_rel_user.user_course_cat, course_rel_user.sort ASC";
  647. $result = api_sql_query($sql_select_courses) or die(mysql_error());
  648. $number_of_courses=mysql_num_rows($result);
  649. $key=0;
  650. while ($course=mysql_fetch_array($result))
  651. {
  652. echo "\t<tr>\n";
  653. echo "\t\t<td>\n";
  654. echo '<a name="course'.$course['code'].'"></a>'; // display an internal anchor.
  655. echo "<b>".$course['title']."</b><br />";
  656. if (get_setting("display_coursecode_in_courselist") == "true")
  657. {
  658. echo $course['visual_code'];
  659. }
  660. if (get_setting("display_coursecode_in_courselist") == "true" AND get_setting("display_teacher_in_courselist") == "true")
  661. {
  662. echo " - ";
  663. }
  664. if (get_setting("display_teacher_in_courselist") == "true")
  665. {
  666. echo $course['tutor'];
  667. }
  668. echo "\t\t</td>\n";
  669. // displaying the up/down/edit icons when we are sorting courses
  670. echo "\t\t<td valign=\"top\">\n";
  671. //if ($parameter=="sorting")
  672. //{
  673. display_course_icons($key, $number_of_courses, $course, $user_courses);
  674. //}
  675. // displaying the delete icon when we are unsubscribing from courses
  676. //if($parameter=="deleting")
  677. //{
  678. // display_unsubscribe_icons($course);
  679. //}
  680. // display the subscribing icon when we are to courses.
  681. //if ($parameter=="subscribing")
  682. //{
  683. // display_subscribe_icon($course);
  684. //}
  685. echo "\t\t</td>\n";
  686. echo "\t</tr>\n";
  687. $key++;
  688. }
  689. }
  690. /**
  691. * gets the title of the user course category
  692. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  693. * @param int id: the id of the user defined course category
  694. * @return string: the name of the user defined course category
  695. */
  696. function get_user_course_category($id)
  697. {
  698. global $_uid, $user_personal_database;
  699. $DATABASE_USER_TOOLS = $user_personal_database;
  700. $TABLE_USER_COURSE_CATEGORY = $DATABASE_USER_TOOLS."`.`user_course_category";
  701. $sql="SELECT * FROM `".$TABLE_USER_COURSE_CATEGORY."` WHERE user_id='$_uid' AND id='$id'";
  702. $result=mysql_query($sql) or die(mysql_error());
  703. $row=mysql_fetch_array($result);
  704. return $row;
  705. }
  706. /**
  707. * displays the subscribe icon if the subscribing is allowed and if the user is not yet
  708. * subscribe to this course
  709. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  710. * @param string $current_course: the course code of the course we need to display the subscribe icon for
  711. * @return string a subscribe icon or the text that subscribing is not allowed or the user is already subscribed
  712. */
  713. function display_subscribe_icon($current_course, $user_coursecodes)
  714. {
  715. // we display the icon to subscribe or the text already subscribed
  716. if (in_array($current_course['code'],$user_coursecodes))
  717. {
  718. echo get_lang("AlreadySubscribed");
  719. }
  720. else
  721. {
  722. if ($current_course['subscribe'] == SUBSCRIBE_ALLOWED)
  723. {
  724. echo "<form action=\"".$_SERVER["REQUEST_URI"]."\" method=\"post\">";
  725. echo "<input type=\"hidden\" name=\"subscribe\" value=\"".$current_course['code']."\" />";
  726. echo "<input type=\"image\" name=\"unsub\" src=\"../img/enroll.gif\" alt=\"".get_lang("Subscribe")."\" />".get_lang("Subscribe")."</form>";
  727. }
  728. else
  729. {
  730. echo get_lang("SubscribingNotAllowed");
  731. }
  732. }
  733. }
  734. /**
  735. * displays the subscribe icon if the subscribing is allowed and if the user is not yet
  736. * subscribed to this course
  737. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  738. * @param $key:
  739. * $number_of_courses
  740. * $course
  741. * $user_courses
  742. * @return html a small table containing the up/down icons and the edit icon (for moving to a different user course category)
  743. * @todo complete the comments on this function: the parameter section
  744. */
  745. function display_course_icons($key, $number_of_courses, $course, $user_courses)
  746. {
  747. //print_r($course);
  748. echo "<table><tr><td>";
  749. // the up icon
  750. if ($key>0 AND $user_courses[$key-1]['user_course_category']==$course['user_course_category'])
  751. {
  752. echo "<a href=\"courses.php?action=".$_GET['action']."&amp;move=up&amp;course=".$course['code']."&amp;category=".$course['user_course_cat']."\">";
  753. echo "<img src=\"../img/up.gif\" alt=\"".htmlentities(get_lang("Up"))."\"></a>";
  754. }
  755. echo "</td>";
  756. // the edit icon OR the edit dropdown list
  757. if (isset($_GET['edit']) and $course['code']==$_GET['edit'])
  758. {
  759. echo "<td rowspan=\"2\" valign=\"top\">".display_change_course_category_form($_GET['edit'])."</td>";
  760. }
  761. else
  762. {
  763. echo "<td rowspan=\"2\" valign=\"middle\"><a href=\"courses.php?action=".$_GET['action']."&amp;edit=".$course['code']."\">";
  764. Display::display_icon('edit.gif',get_lang('Edit'));
  765. echo "</a></td>";
  766. }
  767. echo "<td rowspan=\"2\" valign=\"top\">";
  768. if ($course['status'] != 1)
  769. {
  770. if ($course['unsubscr'] == 1)
  771. { // changed link to submit to avoid action by the search tool indexer
  772. echo "<form action=\"".$_SERVER['PHP_SELF']."\" method=\"post\" onsubmit=\"javascript:if(!confirm('".addslashes(htmlentities(get_lang("ConfirmUnsubscribeFromCourse")))."')) return false;\">";
  773. echo "<input type=\"hidden\" name=\"unsubscribe\" value=\"".$course['code']."\" />";
  774. echo "<input type=\"image\" name=\"unsub\" src=\"../img/delete.gif\" alt=\"".get_lang("_unsubscribe")."\" /></form>";
  775. }
  776. else
  777. {display_info_text(get_lang("UnsubscribeNotAllowed"));}
  778. }
  779. else
  780. {
  781. display_info_text(get_lang("CourseAdminUnsubscribeNotAllowed"));
  782. }
  783. echo "</td>";
  784. echo "</tr><tr><td>";
  785. if ($key<$number_of_courses-1 AND $user_courses[$key+1]['user_course_category']==$course['user_course_category'])
  786. {
  787. echo "<a href=\"courses.php?action=".$_GET['action']."&amp;move=down&amp;course=".$course['code']."&amp;category=".$course['user_course_cat']."\">";
  788. echo "<img src=\"../img/down.gif\" alt=\"".htmlentities(get_lang("Down"))."\"></a>";
  789. }
  790. echo "</td></tr></table>";
  791. }
  792. /**
  793. * displays the relevant icons for the category (if applicable):move up, move down, edit, delete
  794. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  795. * @param $current_category the id of the current category
  796. * $allcategories an associative array containing all the categories.
  797. * @return html: a small table containing the up/down icons and the edit icon (for moving to a different user course category)
  798. * @todo complete the comments on this function: the parameter section
  799. */
  800. function display_category_icons($current_category, $all_user_categories)
  801. {
  802. $max_category_key=count($all_user_categories);
  803. if ($_GET['action']<>'unsubscribe') // we are in the unsubscribe section then we do not show the icons.
  804. {
  805. echo "<table>";
  806. echo "<tr>";
  807. echo "<td>";
  808. if ($current_category<>$all_user_categories[0])
  809. {
  810. echo "<a href=\"courses.php?action=".$_GET['action']."&amp;move=up&amp;category=".$current_category."\">";
  811. echo "<img src=\"../img/up.gif\" alt=\"".htmlentities(get_lang("Up"))."\"></a>";
  812. }
  813. echo "</td>";
  814. echo " <td rowspan=\"2\">";
  815. echo " <a href=\"courses.php?action=sortmycourses&amp;categoryid=".$current_category."#category".$current_category."\">";
  816. Display::display_icon('edit.gif',get_lang('Edit'));
  817. echo "</a>";
  818. echo "</td>";
  819. echo "<td rowspan=\"2\">";
  820. echo " <a href=\"courses.php?action=deletecoursecategory&amp;id=".$current_category."\">";
  821. Display::display_icon('delete.gif',get_lang('Edit'),array('onclick'=>"javascript:if(!confirm('".addslashes(htmlentities(get_lang("CourseCategoryAbout2bedeleted")))."')) return false;"));
  822. echo "</a>";
  823. echo "</td>";
  824. echo "</tr>";
  825. echo "<tr>";
  826. echo " <td>";
  827. if ($current_category<>$all_user_categories[$max_category_key-1])
  828. {
  829. echo "<a href=\"courses.php?action=".$_GET['action']."&amp;move=down&amp;category=".$current_category."\">";
  830. echo "<img src=\"../img/down.gif\" alt=\"".htmlentities(get_lang("Down"))."\"></a>";
  831. }
  832. echo "</td>";
  833. echo " </tr>";
  834. echo "</table>";
  835. }
  836. }
  837. /**
  838. * This function displays the form (dropdown list) to move a course to a
  839. * different course_category (after the edit icon has been changed)
  840. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  841. * @param string $edit_course:
  842. * @return html a dropdown list containing all the user defined course categories and a submit button
  843. * @todo when editing (moving) a course inside a user defined course category to a different user defined category
  844. * the dropdown list should have the current course category selected.
  845. */
  846. function display_change_course_category_form($edit_course)
  847. {
  848. global $_uid, $user_personal_database;
  849. $DATABASE_USER_TOOLS = $user_personal_database;
  850. $TABLE_USER_COURSE_CATEGORY = $DATABASE_USER_TOOLS."`.`user_course_category";
  851. $sql="SELECT * FROM `$TABLE_USER_COURSE_CATEGORY` WHERE user_id='".$_uid."'";
  852. $result=api_sql_query($sql);
  853. $output="<form name=\"edit_course_category\" method=\"post\" action=\"courses.php?action=".$_GET['action']."\">\n";
  854. $output.="<input type=\"hidden\" name=\"course_2_edit_category\" value=\"".$edit_course."\" />";
  855. $output.="\t<select name=\"course_categories\">\n";
  856. $output.="\t\t<option value=\"0\">".get_lang("NoCourseCategory")."</option>";
  857. while ($row=mysql_fetch_array($result))
  858. {$output.="\t\t<option value=\"".$row['id']."\">".$row['title']."</option>";}
  859. $output.="\t</select>\n";
  860. $output.="\t<input type=\"submit\" name=\"submit_change_course_category\" value=\"".get_lang("Ok")."\" />\n";
  861. $output.="</form>";
  862. return $output;
  863. }
  864. /**
  865. * This function displays the unsubscribe part which can be
  866. * 1. the unsubscribe link
  867. * 2. text: you are course admin of this course (=> unsubscription is not possible
  868. * 3. text: you are not allowed to unsubscribe from this course
  869. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  870. * @param array $course: the array with all the course & course_rel_user information
  871. * @return html a delete icon or a text that unsubscribing is not possible (course admin) or not allowed.
  872. */
  873. function display_unsubscribe_icons($course)
  874. {
  875. if ($course['status'] != 1)
  876. {
  877. if ($course['unsubscribe'] == 1)
  878. { // changed link to submit to avoid action by the search tool indexer
  879. echo "<form action=\"".$_SERVER['PHP_SELF']."\" method=\"post\" onsubmit=\"javascript:if(!confirm('".addslashes(htmlentities(get_lang("ConfirmUnsubscribeFromCourse")))."')) return false;\">";
  880. echo "<input type=\"hidden\" name=\"unsubscribe\" value=\"".$course['code']."\" />";
  881. echo "<input type=\"image\" name=\"unsub\" src=\"../img/delete.gif\" alt=\"".get_lang("_unsubscribe")."\" /></form>";
  882. }
  883. else
  884. {display_info_text(get_lang("UnsubscribeNotAllowed"));}
  885. }
  886. else
  887. {
  888. display_info_text(get_lang("CourseAdminUnsubscribeNotAllowed"));
  889. }
  890. }
  891. /**
  892. * retrieves all the courses that the user has already subscribed to
  893. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  894. * @param int $user_id: the id of the user
  895. * @return array an array containing all the information of the courses of the given user
  896. */
  897. function get_courses_of_user($user_id)
  898. {
  899. $TABLECOURS=Database::get_main_table(MAIN_COURSE_TABLE);
  900. $TABLECOURSUSER=Database::get_main_table(MAIN_COURSE_USER_TABLE);
  901. // Secondly we select the courses that are in a category (user_course_cat<>0) and sort these according to the sort of the category
  902. $sql_select_courses="SELECT course.code k, course.visual_code vc, course.subscribe subscr, course.unsubscribe unsubscr,
  903. course.title i, course.tutor_name t, course.db_name db, course.directory dir, course_rel_user.status status,
  904. course_rel_user.sort sort, course_rel_user.user_course_cat user_course_cat
  905. FROM $TABLECOURS course,
  906. $TABLECOURSUSER course_rel_user
  907. WHERE course.code = course_rel_user.course_code
  908. AND course_rel_user.user_id = '".$user_id."'
  909. ORDER BY course_rel_user.sort ASC";
  910. $result = api_sql_query($sql_select_courses) or die(mysql_error());
  911. while ($row=mysql_fetch_array($result))
  912. {
  913. // we only need the database name of the course
  914. $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']);
  915. }
  916. return $courses;
  917. }
  918. /**
  919. * retrieves the user defined course categories
  920. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  921. * @return array containing all the titles of the user defined courses with the id as key of the array
  922. */
  923. function get_user_course_categories()
  924. {
  925. global $_uid;
  926. $table_category = Database::get_user_personal_table(USER_COURSE_CATEGORY_TABLE);
  927. $sql = "SELECT * FROM ".$table_category." WHERE user_id='".$_uid."' ORDER BY sort ASC";
  928. $result = api_sql_query($sql,__FILE__,__LINE__);
  929. while ($row = mysql_fetch_array($result))
  930. {
  931. $output[] = $row['id'];
  932. }
  933. return $output;
  934. }
  935. /**
  936. * @author unknown
  937. * @param string $text: the text that has to be written in grey
  938. * @return string: the text with the grey formatting
  939. * @todo move this to a stylesheet
  940. */
  941. function display_info_text($text)
  942. {
  943. echo "<font color=\"#808080\">" . $text . "</font>\n";
  944. }
  945. /**
  946. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  947. * @param string $edit_course:
  948. * @return html output: the form
  949. */
  950. function display_edit_course_category_form($edit_course_category)
  951. {
  952. echo "<form name=\"edit_course_category\" method=\"post\" action=\"courses.php?action=".$_GET['action']."\">\n";
  953. echo "\t<input type=\"hidden\" name=\"edit_course_category\" value=\"".$edit_course_category."\" />\n";
  954. $info_this_user_course_category=get_user_course_category($edit_course_category);
  955. echo "\t<input type=\"text\" name=\"title_course_category\" value=\"".$info_this_user_course_category['title']."\" />";
  956. echo "\t<input type=\"submit\" name=\"submit_edit_course_category\" value=\"".get_lang("Ok")."\" />\n";
  957. echo "</form>";
  958. }
  959. /**
  960. * Updates the user course category in the dokeos_user database
  961. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  962. * @return string a language variable saying that the user course category was stored
  963. */
  964. function store_edit_course_category()
  965. {
  966. global $_uid, $user_personal_database;
  967. $DATABASE_USER_TOOLS = $user_personal_database;
  968. $TABLE_USER_COURSE_CATEGORY = $DATABASE_USER_TOOLS."`.`user_course_category";
  969. $sql_update="UPDATE `$TABLE_USER_COURSE_CATEGORY` SET title='".htmlentities($_POST['title_course_category'])."' WHERE id='".(int)$_POST['edit_course_category']."'";
  970. mysql_query($sql_update) or die(mysql_error());
  971. //api_sql_query(sql_update);
  972. return get_lang("CourseCategoryEditStored");
  973. }
  974. ?>