Advertisement
Guest User

Untitled

a guest
Dec 20th, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.34 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. // echo "<pre>";
  240. // print_r($vacationsRequest);
  241. // echo "</pre>";
  242. // die();
  243.  
  244.  
  245. if( (isset($vacationsRequest['datefrom']) &&
  246. !strlen($vacationsRequest['datefrom'] = trim($vacationsRequest['datefrom'])) == 0) &&
  247. (isset($vacationsRequest['dateto']) &&
  248. !strlen($vacationsRequest['dateto'] = trim($vacationsRequest['dateto'])) == 0)
  249. ) {
  250. $vacationsRequest['username'] = $session->username;
  251.  
  252. // echo "<br>rezultatai:";
  253. // echo "<pre>";
  254. // print_r($vacationsRequest);
  255. // echo "</pre>";
  256. // die();
  257. $return = $database->saveVacations($vacationsRequest);
  258.  
  259. if($return) {
  260.  
  261. }
  262. }
  263.  
  264.  
  265. // die();
  266. header("Location: " . $session->referrer);
  267.  
  268. }
  269. }
  270.  
  271. function approveVacations() {
  272. global $session, $database, $form;
  273. $approveVacations = $_POST;
  274. // echo "<pre>";
  275. // print_r($vacationsRequest);
  276. // echo "</pre>";
  277. // die();
  278.  
  279.  
  280. if( (isset($approveVacations['datefrom']) &&
  281. !strlen($approveVacations['datefrom'] = trim($approveVacations['datefrom'])) == 0) &&
  282. (isset($approveVacations['dateto']) &&
  283. !strlen($approveVacations['dateto'] = trim($approveVacations['dateto'])) == 0)
  284. ) {
  285. $approveVacations['username'] = $session->username;
  286.  
  287. // echo "<br>rezultatai:";
  288. // echo "<pre>";
  289. // print_r($vacationsRequest);
  290. // echo "</pre>";
  291. // die();
  292. $return = $database->saveApprovedVacations($approveVacations);
  293.  
  294. if($return) {
  295.  
  296. }
  297. }
  298.  
  299.  
  300. // die();
  301. header("Location: " . $session->referrer);
  302.  
  303. }
  304.  
  305. /* Initialize process */
  306. $process = new Process;
  307. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement