PageRenderTime 61ms CodeModel.GetById 8ms RepoModel.GetById 1ms app.codeStats 0ms

/manageuser.php

https://gitlab.com/vectorci/Collabtive
PHP | 324 lines | 285 code | 35 blank | 4 comment | 57 complexity | 24cde372a7272d47fc61a3638882f2e7 MD5 | raw file
  1. <?php
  2. include("init.php");
  3. $user = (object) new user();
  4. $action = getArrayVal($_GET, "action");
  5. $id = getArrayVal($_GET, "id");
  6. $mode = getArrayVal($_GET, "mode");
  7. if ($action != "login" and $action != "logout" and $action != "resetpassword" and $action != "loginerror") {
  8. if (!isset($_SESSION["userid"])) {
  9. $template->assign("loginerror", 0);
  10. $template->display("login.tpl");
  11. die();
  12. }
  13. }
  14. $name = getArrayVal($_POST, "name");
  15. $realname = getArrayVal($_POST, "realname");
  16. $role = getArrayVal($_POST, "role");
  17. $email = getArrayVal($_POST, "email");
  18. $tel1 = getArrayVal($_POST, "tel1");
  19. $tel2 = getArrayVal($_POST, "tel2");
  20. $company = getArrayVal($_POST, "company");
  21. $address1 = getArrayVal($_POST, "address1");
  22. $address2 = getArrayVal($_POST, "address2");
  23. $state = getArrayVal($_POST, "state");
  24. $country = getArrayVal($_POST, "country");
  25. $locale = getArrayVal($_POST, "locale");
  26. $tags = getArrayVal($_POST, "tags");
  27. $oldpass = getArrayVal($_POST, "oldpass");
  28. $newpass = getArrayVal($_POST, "newpass");
  29. $repeatpass = getArrayVal($_POST, "repeatpass");
  30. $admin = getArrayVal($_POST, "admin");
  31. $turl = getArrayVal($_POST, "web");
  32. $gender = getArrayVal($_POST, "gender");
  33. $zip = getArrayVal($_POST, "zip");
  34. $taski = getArrayVal($_GET, "task");
  35. $fproject = getArrayVal($_GET, "project");
  36. $template->assign("mode", $mode);
  37. // get the available languages
  38. $languages = getAvailableLanguages();
  39. $template->assign("languages", $languages);
  40. $project = array();
  41. $project['ID'] = $id;
  42. $template->assign("project", $project);
  43. // set css classes for menue buttons
  44. $classes = array("overview" => "overview", "msgs" => "msgs", "tasks" => "tasks", "miles" => "miles", "files" => "files", "users" => "users_active", "tracker" => "tracking");
  45. $mainclasses = array("desktop" => "",
  46. "profil" => "active",
  47. "admin" => ""
  48. );
  49. $template->assign("mainclasses", $mainclasses);
  50. $template->assign("classes", $classes);
  51. if ($action == "loginerror") {
  52. $template->display("resetpassword.tpl");
  53. } elseif ($action == "resetpassword") {
  54. $newpass = $user->resetPassword($email);
  55. if ($newpass != "") {
  56. // Send e-mail with new password
  57. $themail = new emailer($settings);
  58. $themail->send_mail($email, $langfile["projectpasswordsubject"], $langfile["hello"] . ",<br /><br/>" . $langfile["projectpasswordtext"] . "<br /><br />" . $langfile["newpass"] . ": " . "$newpass<br />" . $langfile["login"] . ": <a href = \"$url\">$url</a>");
  59. $template->assign("success", 1);
  60. $template->display("resetpassword.tpl");
  61. } else {
  62. $template->assign("loginerror", 1);
  63. $template->display("resetpassword.tpl");
  64. }
  65. } elseif ($action == "login") {
  66. $mode = getArrayVal($_GET, "openid_mode");
  67. $username = getArrayVal($_POST, "username");
  68. $pass = getArrayVal($_POST, "pass");
  69. // normal login
  70. if ($user->login($username, $pass)) {
  71. $loc = $url . "index.php?mode=login";
  72. header("Location: $loc");
  73. } else {
  74. $template->assign("loginerror", 1);
  75. $template->display("login.tpl");
  76. }
  77. } elseif ($action == "logout") {
  78. if ($user->logout()) {
  79. header("Location: index.php?mode=logout");
  80. }
  81. } elseif ($action == "addform") {
  82. $title = $langfile['adduser'];
  83. $template->assign("title", $title);
  84. $template->display("adduserform.tpl");
  85. } elseif ($action == "editform") {
  86. $languages_fin = array();
  87. foreach($languages as $lang) {
  88. $lang2 = $langfile[$lang];
  89. $fin = countLanguageStrings($lang);
  90. if (!empty($lang2)) {
  91. $lang2 .= " (" . $fin . "%)";
  92. $fin = array("val" => $lang, "str" => $lang2);
  93. } else {
  94. $lang2 = $lang . " (" . $fin . "%)";
  95. $fin = array("val" => $lang, "str" => $lang2);
  96. }
  97. array_push($languages_fin, $fin);
  98. }
  99. $template->assign("languages_fin", $languages_fin);
  100. $title = $langfile['edituser'];
  101. $template->assign("title", $title);
  102. $euser = $user->getProfile($userid);
  103. $template->assign("user", $euser);
  104. $template->display("edituserform.tpl");
  105. } elseif ($action == "edit") {
  106. $_SESSION['userlocale'] = $locale;
  107. $_SESSION['username'] = $name;
  108. if (!empty($_FILES['userfile']['name'])) {
  109. $fname = $_FILES['userfile']['name'];
  110. $typ = $_FILES['userfile']['type'];
  111. $size = $_FILES['userfile']['size'];
  112. $tmp_name = $_FILES['userfile']['tmp_name'];
  113. $error = $_FILES['userfile']['error'];
  114. $root = "./";
  115. $teilnamen = explode(".", $fname);
  116. $teile = count($teilnamen);
  117. $workteile = $teile - 1;
  118. $erweiterung = $teilnamen[$workteile];
  119. $subname = "";
  120. if ($erweiterung != "image/jpeg" and $erweiterung != "image/png" and $erweiterung != "image/gif" and $erweiterung != "image/pjpeg") {
  121. $loc = $url . "manageuser.php?action=profile&id=$userid";
  122. header("Location: $loc");
  123. die();
  124. }
  125. for ($i = 0; $i < $workteile; $i++) {
  126. $subname .= $teilnamen[$i];
  127. }
  128. list($usec, $sec) = explode(' ', microtime());
  129. $seed = (float) $sec + ((float) $usec * 100000);
  130. srand($seed);
  131. $randval = rand(1, 999999);
  132. $subname = preg_replace("/[^-_0-9a-zA-Z]/", "_", $subname);
  133. $subname = preg_replace("/\W/", "", $subname);
  134. if (strlen($subname) > 200) {
  135. $subname = substr($subname, 0, 200);
  136. }
  137. $fname = $subname . "_" . $randval . "." . $erweiterung;
  138. $datei_final = CL_ROOT . "/files/" . CL_CONFIG . "/avatar/" . $fname;
  139. if (move_uploaded_file($tmp_name, $datei_final)) {
  140. $avatar = $fname;
  141. }
  142. if ($user->edit($userid, $name, $realname, $email, $tel1, $tel2, $company, $zip, $gender, $turl, $address1, $address2, $state, $country, "", $locale, $avatar, 0)) {
  143. if (!empty($oldpass) and !empty($newpass) and !empty($repeatpass)) {
  144. $user->editpass($userid, $oldpass, $newpass, $repeatpass);
  145. }
  146. $loc = $url . "manageuser.php?action=profile&id=$userid&mode=edited";
  147. header("Location: $loc");
  148. }
  149. } else {
  150. if ($user->edit($userid, $name, $realname, $email, $tel1, $tel2, $company, $zip, $gender, $turl, $address1, $address2, $state, $country, "", $locale, "", 0)) {
  151. if (isset($oldpass) and isset($newpass) and isset($repeatpass)) {
  152. $user->editpass($userid, $oldpass, $newpass, $repeatpass);
  153. }
  154. $loc = $url . "manageuser.php?action=profile&id=$userid&mode=edited";
  155. header("Location: $loc");
  156. }
  157. }
  158. } elseif ($action == "del") {
  159. if ($user->del($id)) {
  160. $loc = $url . "admin.php?action=users&mode=deleted";
  161. header("Location: $loc");
  162. }
  163. } elseif ($action == "profile") {
  164. $thetag = new tags();
  165. $start = getArrayVal($_GET, "start");
  166. $end = getArrayVal($_GET, "end");
  167. $proj = (object) new project();
  168. if ($userpermissions["admin"]["add"]) {
  169. $projects = $proj->getMyProjects($id);
  170. $i = 0;
  171. if (!empty($projects)) {
  172. foreach($projects as $opro) {
  173. $membs = $proj->getProjectMembers($opro["ID"], 1000);
  174. $projects[$i]['members'] = $membs;
  175. $i = $i + 1;
  176. }
  177. $template->assign("opros", $projects);
  178. }
  179. }
  180. $tracker = (object) new timetracker();
  181. $track = array();
  182. if (!empty($start) and !empty($end)) {
  183. $track = $tracker->getUserTrack($id, $fproject, $taski, $start, $end);
  184. } elseif (is_array($fproject)) {
  185. foreach ($fproject as $fpro) {
  186. $ptrack = $tracker->getUserTrack($id, $fpro, $taski, $start, $end);
  187. if (!empty($ptrack)) {
  188. foreach ($ptrack as $mytrack) {
  189. array_push($track, $mytrack);
  190. }
  191. }
  192. }
  193. } else {
  194. $track = $tracker->getUserTrack($id, $fproject, $taski);
  195. }
  196. if (!empty($track)) {
  197. $totaltime = $tracker->getTotalTrackTime($track);
  198. $template->assign("totaltime", $totaltime);
  199. $template->assign("fproject", $fproject);
  200. $template->assign("start", $start);
  201. $template->assign("end", $end);
  202. }
  203. $template->assign("tracker", $track);
  204. SmartyPaginate::assign($template);
  205. $profile = $user->getProfile($id);
  206. $title = $langfile['userprofile'];
  207. $template->assign("title", $title);
  208. $template->assign("user", $profile);
  209. $template->display("userprofile.tpl");
  210. } elseif ($action == "showproject") {
  211. if (!chkproject($userid, $id)) {
  212. $errtxt = $langfile["notyourproject"];
  213. $noperm = $langfile["accessdenied"];
  214. $template->assign("mode", "error");
  215. $template->assign("errortext", "$errtxt<br>$noperm");
  216. $template->display("error.tpl");
  217. die();
  218. }
  219. $mainclasses = array("desktop" => "desktop",
  220. "profil" => "profil",
  221. "admin" => "admin"
  222. );
  223. $template->assign("mainclasses", $mainclasses);
  224. $proj = (object) new project();
  225. $alluser = $user->getAllUsers(10000);
  226. $users = array();
  227. foreach($alluser as $all) {
  228. if (!chkproject($all['ID'], $id)) {
  229. array_push($users, $all);
  230. }
  231. }
  232. SmartyPaginate::disconnect();
  233. $members = $proj->getProjectMembers($id, 14);
  234. $pro = $proj->getProject($id);
  235. $projectname = $pro['name'];
  236. $title = $langfile['members'];
  237. $template->assign("title", $title);
  238. $template->assign("projectname", $projectname);
  239. SmartyPaginate::assign($template);
  240. $template->assign("members", $members);
  241. $template->assign("users", $users);
  242. $template->display("projectmembers.tpl");
  243. } elseif ($action == "onlinelist") {
  244. $onlinelist = $user->getOnlinelist();
  245. if (!empty($onlinelist)) {
  246. echo "<ul>";
  247. foreach($onlinelist as $online) {
  248. if ($online["avatar"]) {
  249. $userpic = "thumb.php?pic=files/" . CL_CONFIG . "/avatar/$online[avatar]&width=90";
  250. } elseif ($online["gender"] == "f") {
  251. $userpic = "thumb.php?pic=templates/standard/images/no-avatar-female.jpg&amp;width=90";
  252. } else {
  253. $userpic = "thumb.php?pic=templates/standard/images/no-avatar-male.jpg&amp;width=90";
  254. }
  255. echo "<li>" . "<a class=\"user\" href = \"manageuser.php?action=profile&id=$online[ID]\">$online[name]<div><img src = \"$userpic\" /></div> </a>";
  256. if ($online['ID'] != $userid and $userpermissions["chat"]["add"]) {
  257. echo " <a class=\"chat\" href = \"javascript:openChatwin('$online[name]',$online[ID]);\" title=\"chat\"></a>";
  258. } elseif ($online['ID'] == $userid and $userpermissions["chat"]["add"]) {
  259. echo " <a class=\"chat-user\" ></a>";
  260. }
  261. echo "</li>";
  262. }
  263. echo "</ul>";
  264. }
  265. } elseif ($action == "vcard") {
  266. $theuser = $user->getProfile($id);
  267. $vCard = (object) new vCard($theuser["locale"]);
  268. $vCard->setFirstName($theuser["name"]);
  269. $vCard->setCompany($theuser["company"]);
  270. $vCard->setOrganisation($theuser["company"]);
  271. $vCard->setPostalStreet($theuser["adress"]);
  272. $vCard->setPostalZIP($theuser["zip"]);
  273. $vCard->setWorkZIP($theuser["zip"]);
  274. $vCard->setHomeZIP($theuser["zip"]);
  275. $vCard->setPostalCity($theuser["adress2"]);
  276. $vCard->setHomeCity($theuser["adress2"]);
  277. $vCard->setPostalRegion($theuser["state"]);
  278. $vCard->setPostalCountry($theuser["country"]);
  279. $vCard->setWorkStreet($theuser["adress"]);
  280. $vCard->setWorkCity($theuser["adress2"]);
  281. $vCard->setWorkRegion($theuser["state"]);
  282. $vCard->setWorkCountry($theuser["country"]);
  283. $vCard->setUrlWork($theuser["url"]);
  284. $vCard->setEMail($theuser["email"]);
  285. header('Content-Type: text/x-vcard');
  286. header('Content-Disposition: inline; filename=' . $theuser["name"] . '_' . date("d-m-Y") . '.vcf');
  287. echo $vCard->getCardOutput();
  288. }
  289. ?>