userInfo.php 18 KB

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