Advertisement
Guest User

Untitled

a guest
Dec 20th, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.76 KB | None | 0 0
  1. <?php
  2.  
  3. include("include/session.php");
  4.  
  5. class Process {
  6. /* Class constructor */
  7.  
  8. function Process() {
  9. global $session;
  10. // echo "<pre>";
  11. // print_r($_POST);
  12. // echo "</pre>";
  13. // die();
  14. /* User submitted login form */
  15. if (isset($_POST['sublogin'])) {
  16. $this->procLogin();
  17. }
  18. /* User submitted registration form */
  19. else if (isset($_POST['subjoin'])) {
  20. $this->procRegister();
  21. }
  22.  
  23. /* User submitted forgot password form */
  24. else if (isset($_POST['subforgot'])) {
  25. $this->procForgotPass();
  26. }
  27. /* User submitted edit account form */
  28. else if (isset($_POST['subedit'])) {
  29. $this->procEditAccount();
  30. }
  31. else if (isset($_POST['vacationsrequest'])){
  32. $this->vacationsRequest();
  33. }
  34. else if (isset($_POST['approvevacations'])){
  35. $this->approveVacations();
  36. }
  37. else if (isset($_POST['vacationdatechange'])) {
  38. $this->changeVacationsUpdate();
  39. }
  40. /**
  41. * The only other reason user should be directed here
  42. * is if he wants to logout, which means user is
  43. * logged in currently.
  44. */ else if ($session->logged_in) {
  45. $this->procLogout();
  46. }
  47. /**
  48. * Should not get here, which means user is viewing this page
  49. * by mistake and therefore is redirected.
  50. */ else {
  51. header("Location: index.php");
  52. }
  53. }
  54.  
  55. /**
  56. * procLogin - Processes the user submitted login form, if errors
  57. * are found, the user is redirected to correct the information,
  58. * if not, the user is effectively logged in to the system.
  59. */
  60. function procLogin() {
  61. global $session, $form;
  62. /* Login attempt */
  63. $retval = $session->login($_POST['user'], $_POST['pass'], isset($_POST['remember']));
  64.  
  65. /* Login successful */
  66. if ($retval) {
  67. $session->logged_in = 1;
  68. header("Location: " . $session->referrer);
  69. }
  70. /* Login failed */ else {
  71. $session->logged_in = null;
  72. $_SESSION['value_array'] = $_POST;
  73. $_SESSION['error_array'] = $form->getErrorArray();
  74. header("Location: " . $session->referrer);
  75. }
  76. }
  77.  
  78. /**
  79. * procLogout - Simply attempts to log the user out of the system
  80. * given that there is no logout form to process.
  81. */
  82. function procLogout() {
  83. global $session;
  84. $retval = $session->logout();
  85. header("Location: index.php");
  86. }
  87.  
  88. /**
  89. * procRegister - Processes the user submitted registration form,
  90. * if errors are found, the user is redirected to correct the
  91. * information, if not, the user is effectively registered with
  92. * the system and an email is (optionally) sent to the newly
  93. * created user.
  94. */
  95. function procRegister() {
  96. global $session, $form;
  97. /* Convert username to all lowercase (by option) */
  98. if (ALL_LOWERCASE) {
  99. $_POST['user'] = strtolower($_POST['user']);
  100. }
  101. /* Registration attempt */
  102. $retval = $session->register($_POST['user'], $_POST['pass'], $_POST['email']);
  103.  
  104. /* Registration Successful */
  105. if ($retval == 0) {
  106. $_SESSION['reguname'] = $_POST['user'];
  107. $_SESSION['regsuccess'] = true;
  108. header("Location: " . $session->referrer);
  109. }
  110. /* Error found with form */ else if ($retval == 1) {
  111. $_SESSION['value_array'] = $_POST;
  112. $_SESSION['error_array'] = $form->getErrorArray();
  113. header("Location: " . $session->referrer);
  114. }
  115. /* Registration attempt failed */ else if ($retval == 2) {
  116. $_SESSION['reguname'] = $_POST['user'];
  117. $_SESSION['regsuccess'] = false;
  118. header("Location: " . $session->referrer);
  119. }
  120. }
  121.  
  122. /**
  123. * procForgotPass - Validates the given username then if
  124. * everything is fine, a new password is generated and
  125. * emailed to the address the user gave on sign up.
  126. */
  127. function procForgotPass() {
  128. global $database, $session, $mailer, $form;
  129. /* Username error checking */
  130. $subuser = $_POST['user'];
  131. $field = "user"; //Use field name for username
  132. if (!$subuser || strlen($subuser = trim($subuser)) == 0) {
  133. $form->setError($field, "* Neįvestas vartotojo vardas<br>");
  134. } else {
  135. /* Make sure username is in database */
  136. $subuser = stripslashes($subuser);
  137. if (strlen($subuser) < 5 || strlen($subuser) > 30 ||
  138. !eregi("^([0-9a-z])+$", $subuser) ||
  139. (!$database->usernameTaken($subuser))) {
  140. $form->setError($field, "* Vartotojas neegzistuoja<br>");
  141. }
  142. }
  143.  
  144. /* Errors exist, have user correct them */
  145. if ($form->num_errors > 0) {
  146. $_SESSION['value_array'] = $_POST;
  147. $_SESSION['error_array'] = $form->getErrorArray();
  148. }
  149. /* Generate new password and email it to user */ else {
  150. /* Generate new password */
  151. $newpass = $session->generateRandStr(8);
  152.  
  153. /* Get email of user */
  154. $usrinf = $database->getUserInfo($subuser);
  155. $email = $usrinf['email'];
  156.  
  157. /* Attempt to send the email with new password */
  158. if ($mailer->sendNewPass($subuser, $email, $newpass)) {
  159. /* Email sent, update database */
  160. $database->updateUserField($subuser, "password", md5($newpass));
  161. $_SESSION['forgotpass'] = true;
  162. }
  163. /* Email failure, do not change password */ else {
  164. $_SESSION['forgotpass'] = false;
  165. }
  166. }
  167.  
  168. header("Location: " . $session->referrer);
  169. }
  170.  
  171. /**
  172. * procEditAccount - Attempts to edit the user's account
  173. * information, including the password, which must be verified
  174. * before a change is made.
  175. */
  176. function procEditAccount() {
  177. global $session, $form;
  178. /* Account edit attempt */
  179. $retval = $session->editAccount($_POST['curpass'], $_POST['newpass'], $_POST['confirm-newpass'], $_POST['email']);
  180.  
  181. /* Account edit successful */
  182. if ($retval) {
  183. $_SESSION['useredit'] = true;
  184. header("Location: " . $session->referrer);
  185. }
  186. /* Error found with form */ else {
  187. $_SESSION['value_array'] = $_POST;
  188. $_SESSION['error_array'] = $form->getErrorArray();
  189. header("Location: " . $session->referrer);
  190. }
  191. }
  192.  
  193. function changeVacationsUpdate() {
  194. global $session, $database, $form;
  195. /* Username error checking */
  196. // echo "<pre>";
  197. // print_r($_POST);
  198. // echo "</pre>";
  199. // die();
  200. /* Errors exist, have user correct them */
  201. if ($form->num_errors > 0) {
  202. // die();
  203. $_SESSION['value_array'] = $_POST;
  204. $_SESSION['error_array'] = $form->getErrorArray();
  205. header("Location: " . $session->referrer);
  206.  
  207. }
  208. /* Update user olevel */ else {
  209. $datefrom = $_POST['datefrom'];
  210. $dateto = $_POST['dateto'];
  211. if(strtotime($datefrom) > strtotime($dateto)) {
  212. $tempdate = $datefrom;
  213. $datefrom = $dateto;
  214. $dateto = $tempdate;
  215. }
  216. $today=date("Y-m-d");
  217. if ($datefrom > date('Y-m-d', strtotime($today . ' +14 days'))){
  218.  
  219. // echo $datefrom;
  220. // die();
  221.  
  222. $database->updateRequestField($_POST['vacation_request_id'], "vacations_from", $datefrom);
  223. $database->updateRequestField($_POST['vacation_request_id'], "vacations_till", $dateto);
  224.  
  225. }
  226. else {
  227. $_SESSION['datechangeerror'] = false;
  228. }
  229. header("Location: " . $session->referrer . "?username=" . $_POST['username']);
  230. }
  231.  
  232. }
  233.  
  234. /**
  235. */
  236. function vacationsRequest() {
  237. global $session, $database, $form;
  238. $vacationsRequest = $_POST;
  239.  
  240. // echo "<pre>";
  241. // print_r($vacationsRequest);
  242. // echo "</pre>";
  243. // die();
  244.  
  245.  
  246. if( (isset($vacationsRequest['datefrom']) &&
  247. !strlen($vacationsRequest['datefrom'] = trim($vacationsRequest['datefrom'])) == 0) &&
  248. (isset($vacationsRequest['dateto']) &&
  249. !strlen($vacationsRequest['dateto'] = trim($vacationsRequest['dateto'])) == 0)
  250. ) {
  251. $vacationsRequest['username'] = $session->username;
  252.  
  253. $datefrom = new DateTime($vacationsRequest['datefrom']);
  254. $dateto = new DateTime($vacationsRequest['dateto']);
  255. $days_until_appt = $dateto->diff($datefrom)->days+1;
  256. $user_info = $database->getUserInfo($vacationsRequest['username']);
  257. if($user_info != NULL) {
  258. $max_days = $user_info['max_vacation_days'];
  259. if ($days_until_appt <= $max_days) {
  260. $return = $database->saveVacations($vacationsRequest);
  261. $_SESSION['maxdatechangeerror'] = true;
  262. if($return) {
  263.  
  264. }
  265. }
  266. else {
  267. $_SESSION['maxdatechangeerror'] = false;
  268. }
  269. }
  270.  
  271. }
  272.  
  273.  
  274. // die();
  275. header("Location: " . $session->referrer);
  276.  
  277. }
  278. }
  279.  
  280. function approveVacations() {
  281. global $session, $database, $form;
  282. $approveVacations = $_POST;
  283. // echo "<pre>";
  284. // print_r($vacationsRequest);
  285. // echo "</pre>";
  286. // die();
  287.  
  288.  
  289. if( (isset($approveVacations['datefrom']) &&
  290. !strlen($approveVacations['datefrom'] = trim($approveVacations['datefrom'])) == 0) &&
  291. (isset($approveVacations['dateto']) &&
  292. !strlen($approveVacations['dateto'] = trim($approveVacations['dateto'])) == 0)
  293. ) {
  294. $approveVacations['username'] = $session->username;
  295.  
  296. // echo "<br>rezultatai:";
  297. // echo "<pre>";
  298. // print_r($vacationsRequest);
  299. // echo "</pre>";
  300. // die();
  301. $return = $database->saveApprovedVacations($approveVacations);
  302.  
  303. if($return) {
  304.  
  305. }
  306. }
  307.  
  308.  
  309. // die();
  310. header("Location: " . $session->referrer);
  311.  
  312. }
  313.  
  314. /* Initialize process */
  315. $process = new Process;
  316. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement