userInfo.php 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509
  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 = 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();
  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. if ($allowedToEditDef)
  102. {
  103. if (!empty($_POST['submitDef']))
  104. {
  105. if (!empty($_POST['id']))
  106. {
  107. edit_cat_def($_POST['id'], $_POST['title'], $_POST['comment'], $_POST['nbline']);
  108. }
  109. else
  110. {
  111. create_cat_def($_POST['title'], $_POST['comment'], $_POST['nbline']);
  112. }
  113. $displayMode = "viewDefList";
  114. }
  115. elseif (!empty($_GET['removeDef']))
  116. {
  117. remove_cat_def($_GET['removeDef'], true);
  118. $displayMode = "viewDefList";
  119. }
  120. elseif (!empty($_GET['editDef']))
  121. {
  122. $displayMode = "viewDefEdit";
  123. }
  124. elseif (!empty ($_POST['addDef']))
  125. {
  126. $displayMode = "viewDefEdit";
  127. }
  128. elseif (!empty($_GET['moveUpDef']))
  129. {
  130. move_cat_rank($_GET['moveUpDef'], "up");
  131. $displayMode = "viewDefList";
  132. }
  133. elseif (!empty($_GET['moveDownDef']))
  134. {
  135. move_cat_rank($_GET['moveDownDef'], "down");
  136. $displayMode = "viewDefList";
  137. }
  138. elseif (!empty($_POST['viewDefList']))
  139. {
  140. $displayMode = "viewDefList";
  141. }
  142. elseif (!empty($_GET['editMainUserInfo']))
  143. {
  144. $userIdViewed = strval(intval($_GET['editMainUserInfo']));
  145. $displayMode = "viewMainInfoEdit";
  146. }
  147. elseif (!empty($_GET['submitMainUserInfo']))
  148. {
  149. $userIdViewed = strval(intval($_GET['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 (isset($_POST['submitContent']))
  161. {
  162. if ($_POST['cntId']) // submit a content change
  163. {
  164. edit_cat_content($_POST['catId'], $userIdViewed, $_POST['content'], $_SERVER['REMOTE_ADDR']);
  165. }
  166. else // submit a totally new content
  167. {
  168. fill_new_cat_content($_POST['catId'], $userIdViewed, $_POST['content'], $_SERVER['REMOTE_ADDR']);
  169. }
  170. $displayMode = "viewContentList";
  171. }
  172. elseif (!empty($_GET['editContent']))
  173. {
  174. $displayMode = "viewContentEdit";
  175. $userIdViewed = $userIdViewed;
  176. }
  177. }
  178. /*
  179. ==============================================================================
  180. DISPLAY MODES
  181. ==============================================================================
  182. */
  183. // Back button for each display mode (Top)
  184. echo "<div align=\"right\"><a href=\"user.php?".api_get_cidreq()."&amp;origin=".$origin."\">".get_lang('BackUser')."</a></div>\n";
  185. if ($displayMode == "viewDefEdit")
  186. {
  187. /*>>>>>>>>>>>> CATEGORIES DEFINITIONS : EDIT <<<<<<<<<<<<*/
  188. $catToEdit = get_cat_def($_GET['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=\"".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";
  222. } // end for each
  223. } // end if ($catList)
  224. echo "<center>\n",
  225. "<form method=\"post\" action=\"".api_get_self()."\">",
  226. "<input type=\"submit\" name=\"addDef\" value=\"".get_lang('AddNewHeading')."\" />",
  227. "</form>\n",
  228. "<center>\n";
  229. }
  230. elseif ($displayMode == "viewContentEdit")
  231. {
  232. /*>>>>>>>>>>>> CATEGORIES CONTENTS : EDIT <<<<<<<<<<<<*/
  233. $catToEdit = get_cat_content($userIdViewed, $_GET['editContent']);
  234. $content_heading_form = new FormValidator('content_heading_form');
  235. $content_heading_form->addElement('hidden', 'cntId');
  236. $content_heading_form->addElement('hidden', 'catId');
  237. $content_heading_form->addElement('hidden', 'uInfo');
  238. $content_heading_form->addElement('static', null, $catToEdit['title'], htmlize($catToEdit['comment']));
  239. if ($catToEdit['nbline'] == 1)
  240. {
  241. $content_heading_form->addElement('text', 'content', null, array ('size' => 80));
  242. }
  243. else
  244. {
  245. $content_heading_form->addElement('textarea', 'content', null, array ('cols' => 60, 'rows' => $catToEdit['nbline']));
  246. }
  247. $content_heading_form->addElement('submit', 'submitContent', get_lang('Ok'));
  248. $defaults = $catToEdit;
  249. $defaults['cntId'] = $catToEdit['contentId'];
  250. $defaults['uInfo'] = $userIdViewed;
  251. $content_heading_form->setDefaults($defaults);
  252. $content_heading_form->display();
  253. }
  254. elseif ($displayMode == "viewMainInfoEdit")
  255. {
  256. /*>>>>>>>>>>>> CATEGORIES MAIN INFO : EDIT <<<<<<<<<<<<*/
  257. $mainUserInfo = get_main_user_info($userIdViewed, $courseCode);
  258. if ($mainUserInfo)
  259. {
  260. ($mainUserInfo['status'] == 1) ? $courseAdminChecked = "checked" : $courseAdminChecked = "";
  261. ($mainUserInfo['tutor_id'] == 1) ? $tutorChecked = "checked" : $tutorChecked = "";
  262. $image_array=UserManager::get_user_picture_path_by_id($userIdViewed,'web',false,true);
  263. echo '<img src="'.$image_array['dir'].$image_array['file'].'" border="1">';
  264. echo "<form action=\"".api_get_self()."\" method=\"post\">\n",
  265. "<input type=\"hidden\" name=\"submitMainUserInfo\" value=\"$userIdViewed\" />\n",
  266. "<table width=\"80%\" border=\"0\">",
  267. "<tr align=\"center\" bgcolor=\"#E6E6E6\">\n",
  268. "<td align=\"left\">", get_lang('Name'), "</td>\n",
  269. "<td align=\"left\">", get_lang('Role'), "</td>\n",
  270. "<td>", get_lang('Tutor'), "</td>\n",
  271. "<td>", get_lang('CourseManager'), "</td>\n",
  272. "</tr>\n",
  273. "<tr align=\"center\">",
  274. "<td align=\"left\"><b>", htmlize($mainUserInfo['firstName']), " ", htmlize($mainUserInfo['lastName']), "</b></td>\n",
  275. "<td align=\"left\"><input type=\"text\" name =\"role\" value=\"", $mainUserInfo['role'], "\" maxlength=\"40\" /></td>",
  276. "<td><input class=\"checkbox\" type=\"checkbox\" name=\"promoteTutor\" value=\"1\" ", $tutorChecked, " /></td>";
  277. if (!($is_courseAdmin && $_user['user_id'] == $userIdViewed))
  278. {
  279. echo "<td><input class=\"checkbox\" type=\"checkbox\" name=\"promoteCourseAdmin\" value=\"1\"", $courseAdminChecked, " /></td>\n";
  280. }
  281. else
  282. {
  283. echo "<td>", get_lang('CourseManager'), "</td>\n";
  284. }
  285. echo "<td><input type=\"submit\" name=\"submit\" value=\"Ok\" /></td>\n", "</tr>", "</table>", "</form>\n";
  286. echo "<p>".Display :: encrypted_mailto_link($mainUserInfo['email'], $mainUserInfo['email'])."</p>";
  287. if (api_get_setting('extended_profile') == 'true')
  288. {
  289. echo '<div style="margin-top:10px;"><strong>'.get_lang('MyCompetences').'</strong></div><div>'.$mainUserInfo['competences'].'</div>';
  290. echo '<div style="margin-top:10px;"><strong>'.get_lang('MyDiplomas').'</strong></div><div>'.$mainUserInfo['diplomas'].'</div>';
  291. echo '<div style="margin-top:10px;"><strong>'.get_lang('MyTeach').'</strong></div><div>'.$mainUserInfo['teach'].'</div>';
  292. echo '<div style="margin-top:10px;"><strong>'.get_lang('MyPersonalOpenArea').'</strong></div><div>'.$mainUserInfo['openarea'].'</div>';
  293. echo '<div style="margin-top:10px;"><strong>'.get_lang('MyProductions').'</strong></div><div>'.UserManager::build_production_list($mainUserInfo['user_id']).'</div>';
  294. }
  295. }
  296. else{
  297. Display :: display_normal_message(get_lang('ThisStudentIsSubscribeThroughASession'));
  298. }
  299. }
  300. elseif ($displayMode == "viewContentList") // default display
  301. {
  302. /*>>>>>>>>>>>> CATEGORIES CONTENTS : LIST <<<<<<<<<<<<*/
  303. $virtual_course_code = $_GET["virtual_course"];
  304. if (isset ($virtual_course_code))
  305. {
  306. $courseCode = $virtual_course_code;
  307. //not supported yet: editing users of virtual courses
  308. $allowedToEditDef = false;
  309. }
  310. $mainUserInfo = get_main_user_info($userIdViewed, $courseCode);
  311. if ($mainUserInfo)
  312. {
  313. $image_array=UserManager::get_user_picture_path_by_id($userIdViewed,'web',false,true);
  314. echo '<img src="'.$image_array['dir'].$image_array['file'].'" border="1">';
  315. //DISPLAY TABLE HEADING
  316. if ($origin == 'learnpath') { $allowedToEditDef=false; $is_allowedToTrack=false; }
  317. echo "<table width=\"80%\" border=\"0\">",
  318. "<tr align=\"center\" bgcolor=\"#E6E6E6\">\n",
  319. "<td align=\"left\">",get_lang('Name'),"</td>\n",
  320. "<td align=\"left\">",get_lang('Description'),"</td>\n",
  321. "<td>",get_lang('Tutor'),"</td>\n",
  322. "<td>",get_lang('CourseManager'),"</td>\n",
  323. ($allowedToEditDef?"<td>".get_lang('Edit')."</td>\n":""),
  324. ($is_allowedToTrack?"<td>".get_lang('Tracking')."</td>\n":""),
  325. "</tr>\n",
  326. "<tr align=\"center\">\n",
  327. "<td align=\"left\"><b>",htmlize($mainUserInfo['firstName'])," ",htmlize($mainUserInfo['lastName']),"</b></td>\n",
  328. "<td align=\"left\">",htmlize($mainUserInfo['role']),"</td>";
  329. //DISPLAY TABLE CONTENT
  330. if ($mainUserInfo['tutor_id'] == 1)
  331. {
  332. echo "<td>",get_lang('Tutor'),"</td>\n";
  333. }
  334. else
  335. {
  336. echo "<td> - </td>\n";
  337. }
  338. if ($mainUserInfo['status'] == 1)
  339. {
  340. echo "<td>",get_lang('CourseManager'),"</td>";
  341. }
  342. else
  343. {
  344. echo "<td> - </td>\n";
  345. }
  346. if ($allowedToEditDef)
  347. {
  348. echo "<td>",
  349. "<a href=\"".api_get_self()."?".api_get_cidreq()."&editMainUserInfo=$userIdViewed\">",
  350. "<img border=\"0\" alt=\"\" src=\"../img/edit.gif\" />",
  351. "</a>",
  352. "</td>";
  353. }
  354. if ($is_allowedToTrack)
  355. {
  356. echo "<td>",
  357. "<a href=\"../mySpace/myStudents.php?".api_get_cidreq()."&origin=user_course&student=$userIdViewed&details=true&course=".$_course['id']."\">",
  358. "<img border=\"0\" alt=\"".get_lang('Tracking')." : $userIdViewed\" src=\"../img/statistics.gif\" />",
  359. "</a>",
  360. "</td>";
  361. }
  362. echo "</tr>",
  363. "</table>";
  364. //"<p><a href=\"mailto:",$mainUserInfo['email'],"\">",$mainUserInfo['email'],"</a>",
  365. echo "<p>". Display::encrypted_mailto_link($mainUserInfo['email'],$mainUserInfo['email']). "</p>";
  366. if (api_get_setting('extended_profile') == 'true')
  367. {
  368. echo '<div style="margin-top:10px;"><strong>'.get_lang('MyCompetences').'</strong></div><div>'.$mainUserInfo['competences'].'</div>';
  369. echo '<div style="margin-top:10px;"><strong>'.get_lang('MyDiplomas').'</strong></div><div>'.$mainUserInfo['diplomas'].'</div>';
  370. echo '<div style="margin-top:10px;"><strong>'.get_lang('MyTeach').'</strong></div><div>'.$mainUserInfo['teach'].'</div>';
  371. echo '<div style="margin-top:10px;"><strong>'.get_lang('MyPersonalOpenArea').'</strong></div><div>'.$mainUserInfo['openarea'].'</div>';
  372. echo '<div style="margin-top:10px;"><strong>'.get_lang('MyProductions').'</strong></div><div>'.UserManager::build_production_list($mainUserInfo['user_id']).'</div>';
  373. }
  374. }
  375. else{
  376. Display :: display_normal_message(get_lang('ThisStudentIsSubscribeThroughASession'));
  377. }
  378. if (get_setting('allow_user_headings') == 'true' && $allowedToEditDef) // only course administrators see this line
  379. {
  380. echo "<div align=right>",
  381. "<form method=\"post\" action=\"".api_get_self()."\">",
  382. get_lang('CourseAdministratorOnly')," : ",
  383. "<input type=\"submit\" name=\"viewDefList\" value=\"".get_lang('DefineHeadings')."\" />",
  384. "</form>",
  385. "<hr noshade size=\"1\" style=\"color:#99CCFF\">",
  386. "</div>\n";
  387. }
  388. $catList = get_course_user_info($userIdViewed);
  389. if ($catList)
  390. {
  391. foreach ($catList as $thisCat)
  392. {
  393. // Category title
  394. echo "<p><b>",$thisCat['title'],"</b></p>\n";
  395. // Category content
  396. echo "<blockquote>\n";
  397. if ($thisCat['content'])
  398. {
  399. echo htmlize($thisCat['content'])."\n";
  400. }
  401. else
  402. {
  403. echo "....";
  404. }
  405. // Edit command
  406. if ($allowedToEditContent)
  407. {
  408. echo "<br><br>\n",
  409. "<a href=\"".api_get_self()."?".api_get_cidreq()."&editContent=",$thisCat['catId'],"&uInfo=",$userIdViewed,"\">",
  410. "<img src=\"../img/edit.gif\" border=\"0\" alt=\"edit\">",
  411. "</a>\n";
  412. }
  413. echo "</blockquote>\n";
  414. }
  415. }
  416. }
  417. // Back button for each display mode (bottom)
  418. echo "<div align=\"right\"><a href=\"user.php?".api_get_cidreq()."&amp;origin=".$origin."\">".get_lang('BackUser')."</a></div>\n";
  419. /*
  420. ==============================================================================
  421. FOOTER
  422. ==============================================================================
  423. */
  424. Display :: display_footer();
  425. ?>