Estilo.
[ecomupi.git] / include / x.php
blob1251285b7c66e2cdbeba9a76b6edb68e6ad8af6e
1 <?
2 require_once("sesion.php");
3 require_once("../contenido/sub.php");
5 class Process
7 /* Class constructor */
8 function Process(){
9 global $session;
10 /* User submitted login form */
11 if(isset($_POST['sublogin'])){
12 $this->procLogin();
14 /* User submitted registration form */
15 else if(isset($_POST['subjoin'])){
16 $this->procRegister();
18 /* User submitted forgot password form */
19 else if(isset($_POST['subforgot'])){
20 $this->procForgotPass();
22 /* User submitted edit account form */
23 else if(isset($_POST['subedit'])){
24 $this->procEditAccount();
26 /**
27 * The only other reason user should be directed here
28 * is if he wants to logout, which means user is
29 * logged in currently.
31 else if($session->logged_in){
32 DEPURAR ('ok Logout');
33 $this->procLogout();
35 /**
36 * Should not get here, which means user is viewing this page
37 * by mistake and therefore is redirected.
39 else{
40 header("Location: ../");
44 /**
45 * procLogin - Processes the user submitted login form, if errors
46 * are found, the user is redirected to correct the information,
47 * if not, the user is effectively logged in to the system.
49 function procLogin(){
50 global $session, $form;
51 /* Login attempt */
52 DEPURAR ("Intengo de LOGIN");
53 $retval = $session->login($_POST['codigo'], $_POST['clave'], isset($_POST['remember']));
55 /* Login successful */
56 if($retval){
57 $_SESSION['regsuccess'] = true;
60 /* Login failed */
61 else{
62 $_SESSION['regsuccess'] = false;
63 $_SESSION['value_array'] = $_POST;
64 $_SESSION['error_array'] = $form->getErrorArray();
66 header("Location:../");
69 /**
70 * procLogout - Simply attempts to log the user out of the system
71 * given that there is no logout form to process.
73 function procLogout(){
74 global $session;
75 $retval = $session->logout();
76 header("Location: ../");
79 /**
80 * procRegister - Processes the user submitted registration form,
81 * if errors are found, the user is redirected to correct the
82 * information, if not, the user is effectively registered with
83 * the system and an email is (optionally) sent to the newly
84 * created user.
86 function procRegister(){
87 global $session, $form;
88 /* Convert username to all lowercase (by option) */
89 if(ALL_LOWERCASE){
90 $_POST['codigo'] = strtolower($_POST['codigo']);
92 /* Registration attempt */
93 $retval = $session->register($_POST['codigo'], $_POST['clave'], $_POST['nombre'],$_POST['razon'], $_POST['email'], $_POST['telefono1'], $_POST['telefono2'], $_POST['telefono3'], '', $_POST['notas']);
94 //echo $retval;
95 /* Registration Successful */
96 $_SESSION['reguname'] = $_POST['codigo'];
97 if($retval == 0){
98 $_SESSION['regsuccess'] = true;
100 /* Error found with form */
101 else if($retval == 1){
102 $_SESSION['value_array'] = $_POST;
103 $_SESSION['error_array'] = $form->getErrorArray();
104 $_SESSION['regsuccess'] = false;
106 /* Registration attempt failed */
107 else if($retval == 2){
108 $_SESSION['regsuccess'] = false;
111 header("Location: ../?"._ACC_."=registro");
115 * procForgotPass - Validates the given username then if
116 * everything is fine, a new password is generated and
117 * emailed to the address the user gave on sign up.
119 function procForgotPass(){
120 global $database, $session, $mailer, $form;
121 /* Username error checking */
122 $subuser = $_POST['codigo'];
123 $field = "user"; //Use field name for username
124 if(!$subuser || strlen($subuser = trim($subuser)) == 0){
125 $form->setError($field, "* Nombre de usuario no ingresado<br>");
127 else{
128 /* Make sure username is in database */
129 $subuser = stripslashes($subuser);
130 if(strlen($subuser) < 5 || strlen($subuser) > 30 ||
131 !eregi("^([0-9a-z])+$", $subuser) ||
132 (!$database->codigoTaken($subuser))){
133 $form->setError($field, "* El usuario no existe<br>");
137 /* Errors exist, have user correct them */
138 if($form->num_errors > 0){
139 $_SESSION['value_array'] = $_POST;
140 $_SESSION['error_array'] = $form->getErrorArray();
142 /* Generate new password and email it to user */
143 else{
144 /* Generate new password */
145 $newpass = $session->generateRandStr(8);
147 /* Get email of user */
148 $usrinf = $database->getUserInfo($subuser);
149 $email = $usrinf['email'];
151 /* Attempt to send the email with new password */
152 if($mailer->sendNewPass($subuser,$email,$newpass)){
153 /* Email sent, update database */
154 $database->updateUserField($subuser, "password", md5($newpass));
155 $_SESSION['forgotpass'] = true;
157 /* Email failure, do not change password */
158 else{
159 $_SESSION['forgotpass'] = false;
163 header("Location: ../?accion=rpr+clave");
167 * procEditAccount - Attempts to edit the user's account
168 * information, including the password, which must be verified
169 * before a change is made.
171 function procEditAccount(){
172 global $session, $form;
173 /* Account edit attempt */
174 $retval = $session->editAccount($_POST['newpass'], $_POST['codigo'], $_POST['nombre'],$_POST['razon'], $_POST['email'], $_POST['telefono1'], $_POST['telefono2'], $_POST['telefono3'], '', $_POST['notas']);
176 /* Account edit successful */
177 if($retval){
178 $_SESSION['useredit'] = true;
180 /* Error found with form */
181 else{
182 $_SESSION['value_array'] = $_POST;
183 $_SESSION['error_array'] = $form->getErrorArray();
185 header("Location: ../?"._ACC_."=editar+usuario:".$_POST['codigo']);
189 /* Initialize process */
190 $process = new Process;