userInfo.php 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492
  1. <?php
  2. /*
  3. ==============================================================================
  4. Dokeos - elearning and course management software
  5. Copyright (c) 2004 Dokeos S.A.
  6. Copyright (c) 2003 hent 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. * This script displays info about one specific user, specified through
  22. * a GET parameter, e.g. uInfo=2
  23. *
  24. * @todo clean up script in clean sections:
  25. * (1) gather information
  26. * (2) tool logic
  27. * (3) display
  28. * @author original author (unknown, probably thomas,hugues,moosh)
  29. * @author Roan Embrechts, minor modification: virtual courses support
  30. * @package dokeos.user
  31. ==============================================================================
  32. */
  33. /*
  34. ==============================================================================
  35. INIT SECTION
  36. ==============================================================================
  37. */
  38. $editMainUserInfo = $_REQUEST['editMainUserInfo'];
  39. $uInfo = intval($_REQUEST['uInfo']);
  40. // name of the language file that needs to be included
  41. $language_file = array ('registration', 'userInfo');
  42. include ("../inc/global.inc.php");
  43. require_once (api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php');
  44. $this_section = SECTION_COURSES;
  45. $nameTools = get_lang("Users");
  46. api_protect_course_script();
  47. $TBL_USERINFO_DEF = Database :: get_course_table(TABLE_USER_INFO);
  48. $TBL_USERINFO_CONTENT = Database :: get_course_table(TABLE_USER_INFO_CONTENT);
  49. $interbreadcrumb[] = array ("url" => "user.php", "name" => get_lang('Users'));
  50. if ($origin != 'learnpath')
  51. { //so we are not in learnpath tool
  52. Display :: display_header($nameTools, "User");
  53. }
  54. else
  55. {
  56. ?> <link rel="stylesheet" type="text/css" href="<?php echo api_get_path(WEB_CODE_PATH);?>css/default.css" /> <?php
  57. }
  58. $currentCourse = $currentCourseID;
  59. api_display_tool_title(get_lang("Users"));
  60. /*
  61. * data found in settings are :
  62. * $uid
  63. * $isAdmin
  64. * $isAdminOfCourse
  65. * $_configuration['main_database']
  66. * $currentCourseID
  67. */
  68. $userIdViewed = $uInfo; // Id of the user we want to view coming from the user.php
  69. /*
  70. -----------------------------------------------------------
  71. Connection layer between Dokeos and the current script
  72. -----------------------------------------------------------
  73. */
  74. $mainDB = $_configuration['main_database'];
  75. $courseCode = $currentCourseID = $_course['sysCode'];
  76. $tbl_coursUser = Database :: get_main_table(TABLE_MAIN_COURSE_USER);
  77. $userIdViewer = $_user['user_id']; // id fo the user currently online
  78. //$userIdViewed = $_GET['userIdViewed']; // Id of the user we want to view
  79. $allowedToEditContent = ($userIdViewer == $userIdViewed) || $is_platformAdmin;
  80. $allowedToEditDef = api_is_allowed_to_edit();
  81. $is_allowedToTrack = api_is_allowed_to_edit() && $_configuration['tracking_enabled'];
  82. echo $is_allowedToTrack;
  83. // Library connection
  84. include ("userInfoLib.php");
  85. // clean field submitted by the user
  86. foreach ($_POST as $key => $value)
  87. {
  88. $$key = replace_dangerous_char($value);
  89. }
  90. /*
  91. ==============================================================================
  92. FUNCTIONS
  93. ==============================================================================
  94. */
  95. /*
  96. ==============================================================================
  97. COMMANDS SECTION
  98. ==============================================================================
  99. */
  100. $displayMode = "viewContentList";
  101. if ($allowedToEditDef)
  102. {
  103. if ($submitDef)
  104. {
  105. if ($id)
  106. {
  107. edit_cat_def($id, $title, $comment, $nbline);
  108. }
  109. else
  110. {
  111. create_cat_def($title, $comment, $nbline);
  112. }
  113. $displayMode = "viewDefList";
  114. }
  115. elseif ($removeDef)
  116. {
  117. remove_cat_def($removeDef, true);
  118. $displayMode = "viewDefList";
  119. }
  120. elseif ($editDef)
  121. {
  122. $displayMode = "viewDefEdit";
  123. }
  124. elseif (isset ($addDef))
  125. {
  126. $displayMode = "viewDefEdit";
  127. }
  128. elseif ($moveUpDef)
  129. {
  130. move_cat_rank($moveUpDef, "up");
  131. $displayMode = "viewDefList";
  132. }
  133. elseif ($moveDownDef)
  134. {
  135. move_cat_rank($moveDownDef, "down");
  136. $displayMode = "viewDefList";
  137. }
  138. elseif ($viewDefList)
  139. {
  140. $displayMode = "viewDefList";
  141. }
  142. elseif ($editMainUserInfo)
  143. {
  144. $userIdViewed = $editMainUserInfo;
  145. $displayMode = "viewMainInfoEdit";
  146. }
  147. elseif ($submitMainUserInfo)
  148. {
  149. $userIdViewed = $submitMainUserInfo;
  150. $promoteCourseAdmin ? $userProperties['status'] = 1 : $userProperties['status'] = 5;
  151. $promoteTutor ? $userProperties['tutor'] = 1 : $userProperties['tutor'] = 0;
  152. $userProperties['role'] = $role;
  153. update_user_course_properties($userIdViewed, $courseCode, $userProperties);
  154. $displayMode = "viewContentList";
  155. }
  156. }
  157. // COMMON COMMANDS
  158. if ($allowedToEditContent)
  159. {
  160. if ($submitContent)
  161. {
  162. if ($cntId) // submit a content change
  163. {
  164. edit_cat_content($catId, $userIdViewer, $content, $REMOTE_ADDR);
  165. }
  166. else // submit a totally new content
  167. {
  168. fill_new_cat_content($catId, $userIdViewer, $content, $REMOTE_ADDR);
  169. }
  170. $displayMode = "viewContentList";
  171. }
  172. elseif ($editContent)
  173. {
  174. $displayMode = "viewContentEdit";
  175. $userIdViewed = $userIdViewer;
  176. }
  177. }
  178. /*
  179. ==============================================================================
  180. DISPLAY MODES
  181. ==============================================================================
  182. */
  183. // Back button for each display mode (Top)
  184. echo "<p align=\"right\"><a href=\"user.php?".api_get_cidreq()."&origin=".$origin."\">".get_lang('BackUser')."</a></p>\n";
  185. if ($displayMode == "viewDefEdit")
  186. {
  187. /*>>>>>>>>>>>> CATEGORIES DEFINITIONS : EDIT <<<<<<<<<<<<*/
  188. $catToEdit = get_cat_def($editDef);
  189. $edit_heading_form = new FormValidator('edit_heading_form');
  190. $edit_heading_form->addElement('hidden', 'id');
  191. $edit_heading_form->add_textfield('title', get_lang('Title'));
  192. $edit_heading_form->addElement('textarea', 'comment', get_lang('Comment'), array ('cols' => 60, 'rows' => 4));
  193. $possible_line_nrs[1] = '1 '.get_lang('Line');
  194. $possible_line_nrs[3] = '3 '.get_lang('Lines');
  195. $possible_line_nrs[5] = '5 '.get_lang('Lines');
  196. $possible_line_nrs[10] = '10 '.get_lang('Lines');
  197. $possible_line_nrs[15] = '15 '.get_lang('Lines');
  198. $edit_heading_form->addElement('select', 'nbline', get_lang('LineNumber'), $possible_line_nrs);
  199. $edit_heading_form->addElement('submit', 'submitDef', get_lang('Ok'));
  200. $edit_heading_form->setDefaults($catToEdit);
  201. $edit_heading_form->display();
  202. }
  203. elseif ($displayMode == "viewDefList")
  204. {
  205. /*>>>>>>>>>>>> CATEGORIES DEFINITIONS : LIST <<<<<<<<<<<<*/
  206. $catList = get_cat_def_list();
  207. if ($catList)
  208. {
  209. foreach ($catList as $thisCat)
  210. {
  211. // displays Title and comments
  212. echo "<p>", "<b>".htmlize($thisCat['title'])."</b><br>\n", "<i>".htmlize($thisCat['comment'])."</i>\n", "</p>";
  213. // displays lines
  214. echo "<blockquote>\n", "<font color=\"gray\">\n";
  215. for ($i = 1; $i <= $thisCat['nbline']; $i ++)
  216. {
  217. echo "<br>__________________________________________\n";
  218. }
  219. echo "</font>\n", "</blockquote>\n";
  220. // displays commands
  221. echo "<a href=\"".$_SERVER['PHP_SELF']."?removeDef=", $thisCat['catId'], "\">", "<img src=\"../img/delete.gif\" border=\"0\" alt=\"".get_lang('Remove')."\" onclick=\"javascript:if(!confirm('".addslashes(htmlentities(get_lang('ConfirmYourChoice')))."')) return false;\">", "</a>", "<a href=\"".$_SERVER['PHP_SELF']."?editDef=", $thisCat['catId'], "\">", "<img src=\"../img/edit.gif\" border=\"0\" alt=\"".get_lang('Edit')."\">", "</a>", "<a href=\"".$_SERVER['PHP_SELF']."?moveUpDef=", $thisCat['catId'], "\">", "<img src=\"../img/up.gif\" border=\"0\" alt=\"".get_lang('MoveUp')."\">", "</a>", "<a href=\"".$_SERVER['PHP_SELF']."?moveDownDef=", $thisCat['catId'], "\">", "<img src=\"../img/down.gif\" border=\"0\" alt=\"".get_lang('MoveDown')."\">", "</a>\n";
  222. } // end for each
  223. } // end if ($catList)
  224. echo "<center>\n", "<form method=\"post\" action=\"".$_SERVER['PHP_SELF']."\">", "<input type=\"submit\" name=\"addDef\" value=\"".get_lang('AddNewHeading')."\">", "</form>\n", "<center>\n";
  225. }
  226. elseif ($displayMode == "viewContentEdit")
  227. {
  228. /*>>>>>>>>>>>> CATEGORIES CONTENTS : EDIT <<<<<<<<<<<<*/
  229. $catToEdit = get_cat_content($userIdViewed, $editContent);
  230. $content_heading_form = new FormValidator('content_heading_form');
  231. $content_heading_form->addElement('hidden', 'cntId');
  232. $content_heading_form->addElement('hidden', 'catId');
  233. $content_heading_form->addElement('hidden', 'uInfo');
  234. $content_heading_form->addElement('static', null, $catToEdit['title'], htmlize($catToEdit['comment']));
  235. if ($catToEdit['nbline'] == 1)
  236. {
  237. $content_heading_form->addElement('text', 'content', null, array ('size' => 80));
  238. }
  239. else
  240. {
  241. $content_heading_form->addElement('textarea', 'content', null, array ('cols' => 60, 'rows' => $catToEdit['nbline']));
  242. }
  243. $content_heading_form->addElement('submit', 'submitContent', get_lang('Ok'));
  244. $defaults = $catToEdit;
  245. $defaults['cntId'] = $catToEdit['contentId'];
  246. $defaults['uInfo'] = $userIdViewed;
  247. $content_heading_form->setDefaults($defaults);
  248. $content_heading_form->display();
  249. }
  250. elseif ($displayMode == "viewMainInfoEdit")
  251. {
  252. /*>>>>>>>>>>>> CATEGORIES MAIN INFO : EDIT <<<<<<<<<<<<*/
  253. $mainUserInfo = get_main_user_info($userIdViewed, $courseCode);
  254. if ($mainUserInfo)
  255. {
  256. ($mainUserInfo['status'] == 1) ? $courseAdminChecked = "checked" : $courseAdminChecked = "";
  257. ($mainUserInfo['tutor_id'] == 1) ? $tutorChecked = "checked" : $tutorChecked = "";
  258. if ($mainUserInfo['picture'] != '')
  259. {
  260. $size = @ getImageSize('../upload/users/'.$mainUserInfo['picture']);
  261. $vertical_space = (($size[1] > 200) ? 'height="200"' : '');
  262. echo "<img src=\"../upload/users/".$mainUserInfo['picture']."\" $vertical_space border=\"1\">";
  263. }
  264. else
  265. {
  266. echo "<img src=\"../img/unknown.jpg\" border=\"1\">";
  267. }
  268. echo "<form action=\"".$_SERVER['PHP_SELF']."\" method=\"post\">\n", "<input type=\"hidden\" name=\"submitMainUserInfo\" value=\"$userIdViewed\">\n", "<table width=\"80%\" border=\"0\">", "<tr align=\"center\" bgcolor=\"#E6E6E6\">\n", "<td align=\"left\">", get_lang('Name'), "</td>\n", "<td align=\"left\">", get_lang('Role'), "</td>\n", "<td>", get_lang('Tutor'), "</td>\n", "<td>", get_lang('CourseManager'), "</td>\n", "</tr>\n", "<tr align=\"center\">", "<td align=\"left\"><b>", htmlize($mainUserInfo['firstName']), " ", htmlize($mainUserInfo['lastName']), "</b></td>\n", "<td align=\"left\"><input type=\"text\" name =\"role\" value=\"", $mainUserInfo['role'], "\" maxlength=\"40\"></td>", "<td><input class=\"checkbox\" type=\"checkbox\" name=\"promoteTutor\" value=\"1\" ", $tutorChecked, "></td>";
  269. if (!($is_courseAdmin && $_user['user_id'] == $userIdViewed))
  270. {
  271. echo "<td><input class=\"checkbox\" type=\"checkbox\" name=\"promoteCourseAdmin\" value=\"1\"", $courseAdminChecked, "></td>\n";
  272. }
  273. else
  274. {
  275. echo "<td>", get_lang('CourseManager'), "</td>\n";
  276. }
  277. echo "<td><input type=\"submit\" name=\"submit\" value=\"Ok\"></td>\n", "</tr>", "</table>", "</form>\n";
  278. echo "<p>".Display :: encrypted_mailto_link($mainUserInfo['email'], $mainUserInfo['email'])."</p>";
  279. }
  280. }
  281. elseif ($displayMode == "viewContentList") // default display
  282. {
  283. /*>>>>>>>>>>>> CATEGORIES CONTENTS : LIST <<<<<<<<<<<<*/
  284. $virtual_course_code = $_GET["virtual_course"];
  285. if (isset ($virtual_course_code))
  286. {
  287. $courseCode = $virtual_course_code;
  288. //not supported yet: editing users of virtual courses
  289. $allowedToEditDef = false;
  290. }
  291. $mainUserInfo = get_main_user_info($userIdViewed, $courseCode);
  292. if ($mainUserInfo)
  293. {
  294. if ($mainUserInfo['picture'] != '')
  295. {
  296. $size = @ getImageSize('../upload/users/'.$mainUserInfo['picture']);
  297. $vertical_space = (($size[1] > 200) ? 'height="200"' : '');
  298. echo "<img src=\"../upload/users/".$mainUserInfo['picture']."\" $vertical_space border=\"1\">";
  299. }
  300. else
  301. {
  302. echo "<img src=\"../img/unknown.jpg\" border=\"1\">";
  303. }
  304. if($is_allowedToTrack)
  305. {
  306. echo get_lang('Tracking');
  307. }
  308. //DISPLAY TABLE HEADING
  309. if ($origin == 'learnpath') { $allowedToEditDef=false; $is_allowedToTrack=false; }
  310. echo "<table width=\"80%\" border=\"0\">",
  311. "<tr align=\"center\" bgcolor=\"#E6E6E6\">\n",
  312. "<td align=\"left\">",get_lang('Name'),"</td>\n",
  313. "<td align=\"left\">",get_lang('Description'),"</td>\n",
  314. "<td>",get_lang('Tutor'),"</td>\n",
  315. "<td>",get_lang('CourseManager'),"</td>\n",
  316. ($allowedToEditDef?"<td>".get_lang('Edit')."</td>\n":""),
  317. ($is_allowedToTrack?"<td>".get_lang('Tracking')."</td>\n":""),
  318. "</tr>\n",
  319. "<tr align=\"center\">\n",
  320. "<td align=\"left\"><b>",htmlize($mainUserInfo['firstName'])," ",htmlize($mainUserInfo['lastName']),"</b></td>\n",
  321. "<td align=\"left\">",htmlize($mainUserInfo['role']),"</td>";
  322. //DISPLAY TABLE CONTENT
  323. if ($mainUserInfo['tutor_id'] == 1)
  324. {
  325. echo "<td>",get_lang('Tutor'),"</td>\n";
  326. }
  327. else
  328. {
  329. echo "<td> - </td>\n";
  330. }
  331. if ($mainUserInfo['status'] == 1)
  332. {
  333. echo "<td>",get_lang('CourseManager'),"</td>";
  334. }
  335. else
  336. {
  337. echo "<td> - </td>\n";
  338. }
  339. if ($allowedToEditDef)
  340. {
  341. echo "<td>",
  342. "<a href=\"".$_SERVER['PHP_SELF']."?editMainUserInfo=$userIdViewed\">",
  343. "<img border=\"0\" alt=\"\" src=\"../img/edit.gif\">",
  344. "</a>",
  345. "</td>";
  346. }
  347. if ($is_allowedToTrack)
  348. {
  349. echo "<td>",
  350. "<a href=\"../tracking/userLog.php?".api_get_cidreq()."&uInfo=$userIdViewed\">",
  351. "<img border=\"0\" alt=\"".get_lang('Tracking')." : $userIdViewed\" src=\"../img/statistics.png\" />",
  352. "</a>",
  353. "</td>";
  354. }
  355. echo "</tr>",
  356. "</table>";
  357. //"<p><a href=\"mailto:",$mainUserInfo['email'],"\">",$mainUserInfo['email'],"</a>",
  358. echo "<p>". Display::encrypted_mailto_link($mainUserInfo['email'],$mainUserInfo['email']). "</p>";
  359. echo "<p>\n";
  360. }
  361. if (get_setting('allow_user_headings') == 'true' && $allowedToEditDef) // only course administrators see this line
  362. {
  363. echo "<div align=right>",
  364. "<form method=\"post\" action=\"".$_SERVER['PHP_SELF']."\">",
  365. get_lang('CourseAdministratorOnly')," : ",
  366. "<input type=\"submit\" name=\"viewDefList\" value=\"".get_lang('DefineHeadings')."\">",
  367. "</form>",
  368. "<hr noshade size=\"1\" style=\"color:#99CCFF\">",
  369. "</div>\n";
  370. }
  371. $catList = get_course_user_info($userIdViewed);
  372. if ($catList)
  373. {
  374. foreach ($catList as $thisCat)
  375. {
  376. // Category title
  377. echo "<p><b>",$thisCat['title'],"</b></p>\n";
  378. // Category content
  379. echo "<blockquote>\n";
  380. if ($thisCat['content'])
  381. {
  382. echo htmlize($thisCat['content'])."\n";
  383. }
  384. else
  385. {
  386. echo "....";
  387. }
  388. // Edit command
  389. if ($allowedToEditContent)
  390. {
  391. echo "<br><br>\n",
  392. "<a href=\"".$_SERVER['PHP_SELF']."?editContent=",$thisCat['catId'],"&uInfo=",$userIdViewed,"\">",
  393. "<img src=\"../img/edit.gif\" border=\"0\" alt=\"edit\">",
  394. "</a>\n";
  395. }
  396. echo "</blockquote>\n";
  397. }
  398. }
  399. }
  400. // Back button for each display mode (bottom)
  401. echo "<p align=\"right\"><a href=\"user.php?".api_get_cidreq()."&origin=".$origin."\">".get_lang('BackUser')."</a></p>\n";
  402. /*
  403. ==============================================================================
  404. FOOTER
  405. ==============================================================================
  406. */
  407. Display :: display_footer();
  408. ?>