userInfo.php 16 KB

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