Nuevos logos, eliminada pantalla de inicio, correciĆ³n de multiples errores.
[CLab.git] / process.php
blob894132f732e2c6092d90c607db1dd4a5a2951e41
1 <?
2 /**
3 * Process.php
4 */
5 include("include/session.php");
7 class Process
9 /* Class constructor */
10 function Process(){
11 global $session;
12 /* User submitted login form */
13 if(isset($_POST['sublogin'])){
14 $this->procLogin();
16 /* User submitted registration form */
17 else if(isset($_POST['subjoin'])){
18 $this->procRegister();
20 /* User submitted forgot password form */
21 else if(isset($_POST['subforgot'])){
22 $this->procForgotPass();
24 /* User submitted edit account form */
25 else if(isset($_POST['subedit'])){
26 $this->procEditAccount();
28 /**
29 * The only other reason user should be directed here
30 * is if he wants to logout, which means user is
31 * logged in currently.
33 else if($session->logged_in){
34 $this->procLogout();
36 /**
37 * Should not get here, which means user is viewing this page
38 * by mistake and therefore is redirected.
40 else{
41 header("Location: ".$session->referrer);
45 /**
46 * procLogin - Processes the user submitted login form, if errors
47 * are found, the user is redirected to correct the information,
48 * if not, the user is effectively logged in to the system.
50 function procLogin(){
51 global $session, $form;
52 /* Login attempt */
53 $retval = $session->login($_POST['user'], $_POST['pass'], isset($_POST['remember']));
55 /* Login successful */
56 if($retval){
57 $_SESSION['regsuccess'] = true;
58 unset($_SESSION['regfail']);
60 /* Login failed */
61 else{
62 $_SESSION['regsuccess'] = false;
63 $_SESSION['regfail'] = true;
64 $_SESSION['value_array'] = $_POST;
65 $_SESSION['error_array'] = $form->getErrorArray();
67 header("Location:./?x=ingresar");
70 /**
71 * procLogout - Simply attempts to log the user out of the system
72 * given that there is no logout form to process.
74 function procLogout(){
75 global $session;
76 $retval = $session->logout();
77 header("Location: ".$session->referrer);
80 /**
81 * procRegister - Processes the user submitted registration form,
82 * if errors are found, the user is redirected to correct the
83 * information, if not, the user is effectively registered with
84 * the system and an email is (optionally) sent to the newly
85 * created user.
87 function procRegister(){
88 global $session, $form;
89 /* Convert username to all lowercase (by option) */
90 if(ALL_LOWERCASE){
91 $_POST['user'] = strtolower($_POST['user']);
93 /* Registration attempt */
94 $retval = $session->register($_POST['user'], $_POST['pass'], $_POST['email'],$_POST['nombre'], $_POST['encargado'], $_POST['catedratico'], $_POST['tipo'], $_POST['departamento']);
96 /* Registration Successful */
97 if($retval == 0){
98 $_SESSION['regsuccess'] = true;
99 $_SESSION['reguname'] = $_POST['user'];
101 /* Error found with form */
102 else if($retval == 1){
103 $_SESSION['value_array'] = $_POST;
104 $_SESSION['error_array'] = $form->getErrorArray();
106 /* Registration attempt failed */
107 else if($retval == 2){
108 $_SESSION['reguname'] = $_POST['user'];
109 $_SESSION['regsuccess'] = false;
112 $_SESSION['post-post'] = true;
113 header("Location: ./?x=registro");
117 * procForgotPass - Validates the given username then if
118 * everything is fine, a new password is generated and
119 * emailed to the address the user gave on sign up.
121 function procForgotPass(){
122 global $database, $session, $mailer, $form;
123 /* Username error checking */
124 $subuser = $_POST['user'];
125 $field = "user"; //Use field name for username
126 if(!$subuser || strlen($subuser = trim($subuser)) == 0){
127 $form->setError($field, "* Username not entered<br>");
129 else{
130 /* Make sure username is in database */
131 $subuser = stripslashes($subuser);
132 if(strlen($subuser) < 5 || strlen($subuser) > 30 ||
133 !eregi("^([0-9a-z])+$", $subuser) ||
134 (!$database->usernameTaken($subuser))){
135 $form->setError($field, "* Username does not exist<br>");
139 /* Errors exist, have user correct them */
140 if($form->num_errors > 0){
141 $_SESSION['value_array'] = $_POST;
142 $_SESSION['error_array'] = $form->getErrorArray();
144 /* Generate new password and email it to user */
145 else{
146 /* Generate new password */
147 $newpass = $session->generateRandStr(8);
149 /* Get email of user */
150 $usrinf = $database->getUserInfo($subuser);
151 $email = $usrinf['email'];
153 /* Attempt to send the email with new password */
154 if($mailer->sendNewPass($subuser,$email,$newpass)){
155 /* Email sent, update database */
156 $database->updateUserField($subuser, "password", md5($newpass));
157 $_SESSION['forgotpass'] = true;
159 /* Email failure, do not change password */
160 else{
161 $_SESSION['forgotpass'] = false;
165 header("Location: ".$session->referrer);
169 * procEditAccount - Attempts to edit the user's account
170 * information, including the password, which must be verified
171 * before a change is made.
173 function procEditAccount(){
174 global $session, $form;
175 /* Account edit attempt */
176 $retval = $session->editAccount($_POST['curpass'], $_POST['newpass'], $_POST['email']);
178 /* Account edit successful */
179 if($retval){
180 $_SESSION['useredit'] = true;
181 header("Location: ".$session->referrer);
183 /* Error found with form */
184 else{
185 $_SESSION['value_array'] = $_POST;
186 $_SESSION['error_array'] = $form->getErrorArray();
187 header("Location: ".$session->referrer);
192 /* Initialize process */
193 $process = new Process;