userInfo.php 15 KB

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