PageRenderTime 26ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/marsl/out/modules/userdata.php

https://bitbucket.org/marsl/marsl
PHP | 397 lines | 337 code | 36 blank | 24 comment | 63 complexity | 463efcc9bb6bc2b76f03db4fa19a680c MD5 | raw file
  1. <?php
  2. include_once(dirname(__FILE__)."/../includes/errorHandler.php");
  3. include_once(dirname(__FILE__)."/../user/user.php");
  4. include_once(dirname(__FILE__)."/../user/role.php");
  5. include_once(dirname(__FILE__)."/../user/auth.php");
  6. include_once(dirname(__FILE__)."/../includes/dbsocket.php");
  7. include_once(dirname(__FILE__)."/../includes/basic.php");
  8. include_once(dirname(__FILE__)."/../includes/mailer.php");
  9. include_once(dirname(__FILE__)."/module.php");
  10. class UserData implements Module {
  11. /*
  12. * Displays the user administration.
  13. */
  14. public function admin() {
  15. $user = new User();
  16. $db = new DB();
  17. $auth = new Authentication();
  18. $role = new Role();
  19. $mailer = new Mailer();
  20. $basic = new Basic();
  21. if ($auth->moduleAdminAllowed("userdata", $role->getRole())||$auth->moduleExtendedAllowed("userdata", $role->getRole())) {
  22. if ($auth->moduleAdminAllowed("userdata", $role->getRole())) {
  23. require_once("template/userdata.alphabet.tpl.php");
  24. }
  25. if (isset($_GET['action'])) {
  26. if (($_GET['action']=="list")&&$auth->moduleAdminAllowed("userdata", $role->getRole())) {
  27. $userdata = array();
  28. $search = mysql_real_escape_string($_GET['search']);
  29. $ownRole = $role->getRole();
  30. $possibleRoles = $role->getPossibleRoles($ownRole);
  31. $result = $db->query("SELECT `user`, `user`.`role` AS `roleid`, `nickname`, `prename`, `acronym`, `regdate`, `email`, `postcount`, `user`.`name` AS `username`, `role`.`name` AS `rolename` FROM `user` JOIN `role` USING(`role`) LEFT OUTER JOIN `email` USING(`user`) WHERE `nickname` LIKE '$search%' ORDER BY `nickname`");
  32. while ($row = mysql_fetch_array($result)) {
  33. $userid = htmlentities($row['user'], null, "ISO-8859-1");
  34. $nickname = htmlentities($row['nickname'], null, "ISO-8859-1");
  35. $prename = htmlentities($row['prename'], null, "ISO-8859-1");
  36. $acronym = htmlentities($row['acronym'], null, "ISO-8859-1");
  37. $regdate = date("d\. M Y\; H\:i\:s", $row['regdate']);
  38. $email = htmlentities($row['email'], null, "ISO-8859-1");
  39. $postcount = htmlentities($row['postcount'], null, "ISO-8859-1");
  40. $name = htmlentities($row['username'], null, "ISO-8859-1");
  41. $rolename = htmlentities($row['rolename'], null, "ISO-8859-1");
  42. $roleid = htmlentities($row['roleid'], null, "ISO-8859-1");
  43. $isMaster = $role->isMaster($ownRole, $roleid, $possibleRoles);
  44. if ($user->getID()==$userid) {
  45. $isMaster = true;
  46. }
  47. array_push($userdata, array('user'=>$userid, 'nickname'=>$nickname, 'prename'=>$prename, 'acronym'=>$acronym, 'regdate'=>$regdate, 'email'=>$email, 'postcount'=>$postcount, 'name'=>$name, 'rolename'=>$rolename, 'isMaster'=>$isMaster));
  48. }
  49. require_once("template/userdata.list.tpl.php");
  50. }
  51. if ($_GET['action']=="details") {
  52. if ($auth->moduleAdminAllowed("userdata", $role->getRole())||($auth->moduleExtendedAllowed("userdata", $role->getRole())&&($_GET['user']==$user->getID()))) {
  53. $userID = mysql_real_escape_string($_GET['user']);
  54. $ownID = $user->getID();
  55. $ownRole = $role->getRole();
  56. $possibleRoles = $role->getPossibleRoles($ownRole);
  57. if (isset($_POST['entermail'])) {
  58. if ($auth->checkToken($_POST['authTime'], $_POST['authToken'])) {
  59. $email = mysql_real_escape_string($_POST['email']);
  60. if ($basic->checkMail($email)) {
  61. $curTime = time();
  62. $confirmID = $basic->confirmID();
  63. $db->query("INSERT INTO `email`(`email`,`user`, `confirmed`, `time`, `confirm_id`) VALUES('$email', '$userID', '1', '$curTime', '$confirmID')");
  64. }
  65. }
  66. }
  67. if (isset($_GET['delmail'])) {
  68. if ($auth->checkToken($_GET['time'], $_GET['token'])) {
  69. $email = mysql_real_escape_string(urldecode($_GET['delmail']));
  70. $db->query("DELETE FROM `email` WHERE `user`='$userID' AND `primary`='0' AND `email`='$email'");
  71. }
  72. }
  73. if (isset($_GET['primemail'])) {
  74. if ($auth->checkToken($_GET['time'], $_GET['token'])) {
  75. $email = mysql_real_escape_string(urldecode($_GET['primemail']));
  76. if (!$db->isExisting("SELECT `email` FROM `email` WHERE `email`='$email' AND `user`='$userID' AND `confirmed`='0'")) {
  77. $db->query("UPDATE `email` SET `primary`='0' WHERE `user`='$userID'");
  78. $db->query("UPDATE `email` SET `primary`='1' WHERE `user`='$userID' AND `email`='$email'");
  79. }
  80. }
  81. }
  82. if (isset($_GET['confmail'])) {
  83. if ($auth->checkToken($_GET['time'], $_GET['token'])) {
  84. $email = mysql_real_escape_string(urldecode($_GET['confmail']));
  85. $mailer->sendConfirmationMail($userID, $email);
  86. }
  87. }
  88. $result = $db->query("SELECT `user`, `regdate`, `role`, `nickname`, `prename`, `acronym`, `name` FROM `user` WHERE `user`='$userID'");
  89. while ($row = mysql_fetch_array($result)) {
  90. $userRole = htmlentities($row['role'], null, "ISO-8859-1");
  91. $isMaster = $role->isMaster($ownRole, $userRole, $possibleRoles);
  92. if ($isMaster||($user->getID()==$userID)) {
  93. $userID = htmlentities($row['user'], null, "ISO-8859-1");
  94. $nickname = htmlentities($row['nickname'], null, "ISO-8859-1");
  95. $prename = htmlentities($row['prename'], null, "ISO-8859-1");
  96. $acronym = htmlentities($row['acronym'], null, "ISO-8859-1");
  97. $emails = array();
  98. $result2 = $db->query("SELECT * FROM `email` WHERE `user`='$userID' ORDER BY `confirmed` DESC, `primary` DESC");
  99. while ($row2 = mysql_fetch_array($result2)) {
  100. $email = htmlentities($row2['email'], null, "ISO-8859-1");
  101. $confirmed = $row2['confirmed'];
  102. $primary = $row2['primary'];
  103. array_push($emails, array('email'=>$email, 'confirmed'=>$confirmed, 'primary'=>$primary));
  104. }
  105. $name = htmlentities($row['name'], null, "ISO-8859-1");
  106. $regdate = $row['regdate'];
  107. $updateNickname = true;
  108. $updateAcronym = true;
  109. $samePasswords = true;
  110. $rightPassword = true;
  111. $safePassword = true;
  112. if (isset($_POST['change'])||isset($_POST['passwordChange'])) {
  113. if ($auth->checkToken($_POST['authTime'], $_POST['authToken'])) {
  114. if (isset($_POST['change'])) {
  115. $updateNickname = $user->updateNickname($userID, $_POST['nickname']);
  116. if ($updateNickname) {
  117. $nickname = htmlentities($_POST['nickname'], null, "ISO-8859-1");
  118. }
  119. $user->updatePrename($userID, $_POST['prename']);
  120. $prename = htmlentities($_POST['prename'], null, "ISO-8859-1");
  121. $user->updateName($userID, $_POST['name']);
  122. $name = htmlentities($_POST['name'], null, "ISO-8859-1");
  123. if ($isMaster) {
  124. $updateAcronym = $user->updateAcronym($userID, $_POST['acronym']);
  125. if ($updateAcronym) {
  126. $acronym = htmlentities($_POST['acronym'], null, "ISO-8859-1");
  127. }
  128. $user->updateRole($userID, $_POST['role']);
  129. $userRole = htmlentities($_POST['role'], null, "ISO-8859-1");
  130. }
  131. }
  132. if (isset($_POST['passwordChange'])) {
  133. if ($userID==$user->getID()) {
  134. $hash = $user->hashPassword($regdate, $_POST['oldPassword']);
  135. $proofPass = $user->getPassbyID($user->getID());
  136. if ($hash == $proofPass) {
  137. if ($_POST['newPassword']==$_POST['proofPassword']) {
  138. $safePassword = $user->setPassword($user->getID(), $_POST['newPassword']);
  139. }
  140. else {
  141. $samePasswords = false;
  142. }
  143. }
  144. else {
  145. $rightPassword = false;
  146. }
  147. }
  148. }
  149. }
  150. }
  151. $roles = array();
  152. foreach ($possibleRoles as $possibleRole) {
  153. if ($possibleRole!=$ownRole) {
  154. array_push($roles, array('role'=>$possibleRole, 'name'=>$role->getNamebyID($possibleRole)));
  155. }
  156. }
  157. $authTime = time();
  158. $authToken = $auth->getToken($authTime);
  159. require_once("template/userdata.edit.tpl.php");
  160. }
  161. }
  162. }
  163. }
  164. }
  165. }
  166. }
  167. public function display() {
  168. $db = new DB();
  169. $user = new User();
  170. $userID = $user->getID();
  171. $basic = new Basic();
  172. $location = "";
  173. if (isset($_GET['id'])) {
  174. $location = $_GET['id'];
  175. }
  176. else {
  177. $location = $basic->getHomeLocation();
  178. }
  179. $auth = new Authentication();
  180. $role = new Role();
  181. $samePasswords = true;
  182. $rightPassword = true;
  183. $passwordChange = false;
  184. if ($auth->locationReadAllowed($location, $role->getRole())&&$auth->moduleReadAllowed("userdata", $role->getRole())&&$auth->moduleWriteAllowed("userdata", $role->getRole())) {
  185. $mailer = new Mailer();
  186. if (isset($_POST['entermail'])) {
  187. if ($auth->checkToken($_POST['authTime'], $_POST['authToken'])) {
  188. $email = mysql_real_escape_string($_POST['email']);
  189. if ($basic->checkMail($email)) {
  190. $curTime = time();
  191. $confirmID = $basic->confirmID();
  192. $db->query("INSERT INTO `email`(`email`,`user`, `confirmed`, `time`, `confirm_id`) VALUES('$email', '$userID', '0', '$curTime', '$confirmID')");
  193. $mailer->sendConfirmationMail($userID, $email);
  194. }
  195. }
  196. }
  197. if (isset($_GET['delmail'])) {
  198. if ($auth->checkToken($_GET['time'], $_GET['token'])) {
  199. $email = mysql_real_escape_string(urldecode($_GET['delmail']));
  200. $db->query("DELETE FROM `email` WHERE `user`='$userID' AND `primary`='0' AND `email`='$email'");
  201. }
  202. }
  203. if (isset($_GET['primemail'])) {
  204. if ($auth->checkToken($_GET['time'], $_GET['token'])) {
  205. $email = mysql_real_escape_string(urldecode($_GET['primemail']));
  206. if (!$db->isExisting("SELECT `email` FROM `email` WHERE `email`='$email' AND `user`='$userID' AND `confirmed`='0'")) {
  207. $db->query("UPDATE `email` SET `primary`='0' WHERE `user`='$userID'");
  208. $db->query("UPDATE `email` SET `primary`='1' WHERE `user`='$userID' AND `email`='$email'");
  209. }
  210. }
  211. }
  212. if (isset($_GET['confmail'])) {
  213. if ($auth->checkToken($_GET['time'], $_GET['token'])) {
  214. $email = mysql_real_escape_string(urldecode($_GET['confmail']));
  215. $mailer->sendConfirmationMail($userID, $email);
  216. }
  217. }
  218. if (isset($_POST['action'])) {
  219. if (($userID == $_POST['userID'])&&($auth->checkToken($_POST['authTime'], $_POST['authToken']))) {
  220. if ($_POST['action']=="password") {
  221. $passwordChange = true;
  222. $regdate = $user->getRegisterDate($userID);
  223. $hash = $user->hashPassword($regdate, $_POST['oldPassword']);
  224. $proofPass = $user->getPassbyID($user->getID());
  225. if ($hash == $proofPass) {
  226. if ($_POST['newPassword']==$_POST['proofPassword']) {
  227. $safePassword = $user->setPassword($user->getID(), $_POST['newPassword']);
  228. }
  229. else {
  230. $samePasswords = false;
  231. }
  232. }
  233. else {
  234. $rightPassword = false;
  235. }
  236. }
  237. if ($_POST['action']=="edit") {
  238. $prename = mysql_real_escape_string($_POST['prename']);
  239. $name = mysql_real_escape_string($_POST['name']);
  240. $info = mysql_real_escape_string($basic->cleanStrict($_POST['info']));
  241. $signature = mysql_real_escape_string($basic->cleanStrict($_POST['signature']));
  242. $birthdate = 0;
  243. if (checkdate($_POST['month'], $_POST['day'], $_POST['year'])) {
  244. $birthdate = mktime(0,0,0,$_POST['month'],$_POST['day'],$_POST['year']);
  245. }
  246. $gender = "";
  247. if ($_POST['gender']=="female") {
  248. $gender = "female";
  249. }
  250. if ($_POST['gender']=="male") {
  251. $gender = "male";
  252. }
  253. $interests = mysql_real_escape_string($_POST['interests']);
  254. $job = mysql_real_escape_string($_POST['job']);
  255. $zip = mysql_real_escape_string($_POST['zip']);
  256. $street = mysql_real_escape_string($_POST['street']);
  257. $house = mysql_real_escape_string($_POST['house']);
  258. $city = mysql_real_escape_string($_POST['city']);
  259. $db->query("UPDATE `user` SET `prename`='$prename', `name`='$name', `info`='$info', `signature`='$signature', `birthdate`='$birthdate', `gender`='$gender', `interests`='$interests', `job`='$job', `zip`='$zip', `street`='$street', `house`='$house', `city`='$city' WHERE `user`='$userID'");
  260. }
  261. }
  262. }
  263. $authTime = time();
  264. $authToken = $auth->getToken($authTime);
  265. $nickname = "";
  266. $prename = "";
  267. $name = "";
  268. $info = "";
  269. $signature = "";
  270. $day = "DD";
  271. $month = "MM";
  272. $year = "YYYY";
  273. $gender = "";
  274. $interests = "";
  275. $job = "";
  276. $zip = "";
  277. $street = "";
  278. $house = "";
  279. $city = "";
  280. $result = $db->query("SELECT * FROM `user` WHERE `user`='$userID'");
  281. while ($row = mysql_fetch_array($result)) {
  282. $userID = $row['user'];
  283. $prename = htmlentities($row['prename'], null, "ISO-8859-1");
  284. $name = htmlentities($row['name'], null, "ISO-8859-1");
  285. $info = $row['info'];
  286. $signature = $row['signature'];
  287. $day = date("d", $row['birthdate']);
  288. $month = date("m", $row['birthdate']);
  289. $year = date("Y", $row['birthdate']);
  290. $gender = $row['gender'];
  291. $interests = htmlentities($row['interests'], null, "ISO-8859-1");
  292. $job = htmlentities($row['job'], null, "ISO-8859-1");
  293. $zip = htmlentities($row['zip'], null, "ISO-8859-1");
  294. $street = htmlentities($row['street'], null, "ISO-8859-1");
  295. $house = htmlentities($row['house'], null, "ISO-8859-1");
  296. $city = htmlentities($row['city'], null, "ISO-8859-1");
  297. }
  298. $emails = array();
  299. $result = $db->query("SELECT * FROM `email` WHERE `user` = '$userID' ORDER BY `confirmed` DESC, `primary` DESC");
  300. while ($row = mysql_fetch_array($result)) {
  301. $email = htmlentities($row['email'], null, "ISO-8859-1");
  302. $confirmed = $row['confirmed'];
  303. $primary = $row['primary'];
  304. array_push($emails, array('email'=>$email, 'confirmed'=>$confirmed, 'primary'=>$primary));
  305. }
  306. require_once("template/userdata.tpl.php");
  307. }
  308. }
  309. /*
  310. * Interface method stub.
  311. */
  312. public function isSearchable() {
  313. return false;
  314. }
  315. /*
  316. * Interface method stub.
  317. */
  318. public function getSearchList() {
  319. return array();
  320. }
  321. /*
  322. * Interface method stub.
  323. */
  324. public function search($query, $type) {
  325. return null;
  326. }
  327. /*
  328. * Interface method stub.
  329. */
  330. public function isTaggable() {
  331. return false;
  332. }
  333. /*
  334. * Interface method stub.
  335. */
  336. public function getTagList() {
  337. return null;
  338. }
  339. /*
  340. * Interface method stub.
  341. */
  342. public function addTags($tagString, $type, $news) {
  343. }
  344. /*
  345. * Interface method stub.
  346. */
  347. public function getTagString($type, $news) {
  348. }
  349. public function getTags($type, $news) {
  350. return null;
  351. }
  352. public function displayTag($tagID, $type) {
  353. }
  354. public function getImage() {
  355. return null;
  356. }
  357. public function getTitle() {
  358. return null;
  359. }
  360. }
  361. ?>