コード例 #1
0
 public function process()
 {
     $this->share_extensions();
     /// ¿El usuario tiene permiso para eliminar en esta página?
     $this->allow_delete = $this->user->allow_delete_on(__CLASS__);
     $this->agente = new agente();
     $this->ejercicio = new ejercicio();
     $this->suser = FALSE;
     if (isset($_GET['snick'])) {
         $this->suser = $this->user->get($_GET['snick']);
     }
     if ($this->suser) {
         $this->page->title = $this->suser->nick;
         if (isset($_POST['nnombre'])) {
             $age0 = new agente();
             $age0->codagente = $age0->get_new_codigo();
             $age0->nombre = $_POST['nnombre'];
             $age0->apellidos = $_POST['napellidos'];
             $age0->dnicif = $_POST['ndnicif'];
             $age0->telefono = $_POST['ntelefono'];
             $age0->email = $_POST['nemail'];
             if ($age0->save()) {
                 $this->new_message("Empleado " . $age0->codagente . " guardado correctamente.");
                 $this->suser->codagente = $age0->codagente;
                 if ($this->suser->save()) {
                     $this->new_message("Empleado " . $age0->codagente . " asignado correctamente.");
                 } else {
                     $this->new_error_msg("¡Imposible asignar el agente!");
                 }
             } else {
                 $this->new_error_msg("¡Imposible guardar el agente!");
             }
         } else {
             if (isset($_POST['spassword']) or isset($_POST['scodagente']) or isset($_POST['sadmin'])) {
                 $this->modificar_user();
             }
         }
         /// ¿Estamos modificando nuestro usuario?
         if ($this->suser->nick == $this->user->nick) {
             $this->user = $this->suser;
         }
         /// si el usuario no tiene acceso a ninguna página, entonces hay que informar del problema.
         if (!$this->suser->admin) {
             $sin_paginas = TRUE;
             foreach ($this->all_pages() as $p) {
                 if ($p->enabled) {
                     $sin_paginas = FALSE;
                     break;
                 }
             }
             if ($sin_paginas) {
                 $this->new_advice('No has autorizado a este usuario a acceder a ninguna' . ' página y por tanto no podrá hacer nada. Puedes darle acceso a alguna página' . ' desde la pestaña autorizar.');
             }
         }
         $fslog = new fs_log();
         $this->user_log = $fslog->all_from($this->suser->nick);
     } else {
         $this->new_error_msg("Usuario no encontrado.");
     }
 }
コード例 #2
0
 protected function private_core()
 {
     $this->agente = new agente();
     if (isset($_POST['sdnicif'])) {
         $age0 = new agente();
         $age0->codagente = $age0->get_new_codigo();
         $age0->nombre = $_POST['snombre'];
         $age0->apellidos = $_POST['sapellidos'];
         $age0->dnicif = $_POST['sdnicif'];
         $age0->telefono = $_POST['stelefono'];
         $age0->email = $_POST['semail'];
         if ($age0->save()) {
             $this->new_message("Empleado " . $age0->codagente . " guardado correctamente.");
             header('location: ' . $age0->url());
         } else {
             $this->new_error_msg("¡Imposible guardar el empleado!");
         }
     } else {
         if (isset($_GET['delete'])) {
             $age0 = $this->agente->get($_GET['delete']);
             if ($age0) {
                 if (FS_DEMO) {
                     $this->new_error_msg('En el modo <b>demo</b> no se pueden eliminar empleados. Otro usuario podría estar usándolo.');
                 } else {
                     if ($age0->delete()) {
                         $this->new_message("Empleado " . $age0->codagente . " eliminado correctamente.");
                     } else {
                         $this->new_error_msg("¡Imposible eliminar el empleado!");
                     }
                 }
             } else {
                 $this->new_error_msg("¡Empleado no encontrado!");
             }
         }
     }
     $this->offset = 0;
     if (isset($_GET['offset'])) {
         $this->offset = intval($_GET['offset']);
     }
     $this->ciudad = '';
     if (isset($_REQUEST['ciudad'])) {
         $this->ciudad = $_REQUEST['ciudad'];
     }
     $this->provincia = '';
     if (isset($_REQUEST['provincia'])) {
         $this->provincia = $_REQUEST['provincia'];
     }
     $this->orden = 'nombre ASC';
     if (isset($_REQUEST['orden'])) {
         $this->orden = $_REQUEST['orden'];
     }
     $this->buscar();
 }
コード例 #3
0
 protected function process()
 {
     $this->agente = new agente();
     $this->buttons[] = new fs_button_img('b_nuevo_agente', 'Nuevo');
     if (isset($_POST['sdnicif'])) {
         $age0 = new agente();
         $age0->codagente = $age0->get_new_codigo();
         $age0->nombre = $_POST['snombre'];
         $age0->apellidos = $_POST['sapellidos'];
         $age0->dnicif = $_POST['sdnicif'];
         $age0->telefono = $_POST['stelefono'];
         $age0->email = $_POST['semail'];
         if ($age0->save()) {
             $this->new_message("Empleado " . $age0->codagente . " guardado correctamente.");
             header('location: ' . $age0->url());
         } else {
             $this->new_error_msg("¡Imposible guardar el empleado!");
         }
     } else {
         if (isset($_GET['delete'])) {
             $age0 = $this->agente->get($_GET['delete']);
             if ($age0) {
                 if (FS_DEMO) {
                     $this->new_error_msg('En el modo <b>demo</b> no se pueden eliminar empleados. Otro usuario podría estar usándolo.');
                 } else {
                     if ($age0->delete()) {
                         $this->new_message("Empleado " . $age0->codagente . " eliminado correctamente.");
                     } else {
                         $this->new_error_msg("¡Imposible eliminar el empleado!");
                     }
                 }
             } else {
                 $this->new_error_msg("¡Empleado no encontrado!");
             }
         }
     }
 }
コード例 #4
0
ファイル: fs_controller.php プロジェクト: ramikat/ERPSISFS
 /**
  * Devuelve TRUE si el usuario realmente tiene acceso a esta página
  * @return type
  */
 private function log_in()
 {
     $ips = array();
     if ($this->ip_baneada($ips)) {
         $this->banear_ip($ips);
         $this->new_error_msg('Tu IP ha sido baneada. Tendrás que esperar 10 minutos antes de volver a intentar entrar.', 'login', TRUE);
     } else {
         if (isset($_POST['user']) and isset($_POST['password'])) {
             if (FS_DEMO) {
                 $user = $this->user->get($_POST['user']);
                 if (!$user) {
                     $user = new fs_user();
                     $user->nick = $_POST['user'];
                     $user->set_password('demo');
                     /// creamos un agente para asociarlo
                     $agente = new agente();
                     $agente->codagente = $agente->get_new_codigo();
                     $agente->nombre = $_POST['user'];
                     $agente->apellidos = 'Demo';
                     if ($agente->save()) {
                         $user->codagente = $agente->codagente;
                     }
                 }
                 $user->new_logkey();
                 if ($user->save()) {
                     setcookie('user', $user->nick, time() + FS_COOKIES_EXPIRE);
                     setcookie('logkey', $user->log_key, time() + FS_COOKIES_EXPIRE);
                     $this->user = $user;
                     $this->load_menu();
                 }
             } else {
                 $user = $this->user->get($_POST['user']);
                 $password = strtolower($_POST['password']);
                 if ($user) {
                     if ($user->password == sha1($password)) {
                         $user->new_logkey();
                         if (!$user->admin and !$this->ip_in_whitelist($user->last_ip)) {
                             $this->new_error_msg('No puedes acceder desde esta IP.', 'login', TRUE);
                         } else {
                             if ($user->save()) {
                                 setcookie('user', $user->nick, time() + FS_COOKIES_EXPIRE);
                                 setcookie('logkey', $user->log_key, time() + FS_COOKIES_EXPIRE);
                                 $this->user = $user;
                                 $this->load_menu();
                                 /// añadimos el mensaje al log
                                 $fslog = new fs_log();
                                 $fslog->usuario = $user->nick;
                                 $fslog->tipo = 'login';
                                 $fslog->detalle = 'Login correcto.';
                                 $fslog->ip = $user->last_ip;
                                 $fslog->save();
                             } else {
                                 $this->new_error_msg('Imposible guardar los datos de usuario.');
                                 $this->cache->clean();
                             }
                         }
                     } else {
                         $this->new_error_msg('¡Contraseña incorrecta!');
                         $this->banear_ip($ips);
                     }
                 } else {
                     $this->new_error_msg('El usuario ' . $_POST['user'] . ' no existe!');
                     $this->user->clean_cache(TRUE);
                     $this->cache->clean();
                 }
             }
         } else {
             if (isset($_COOKIE['user']) and isset($_COOKIE['logkey'])) {
                 $user = $this->user->get($_COOKIE['user']);
                 if ($user) {
                     if ($user->log_key == $_COOKIE['logkey']) {
                         $user->logged_on = TRUE;
                         $user->update_login();
                         $this->user = $user;
                         $this->load_menu();
                     } else {
                         if (!is_null($user->log_key)) {
                             $this->new_message('¡Cookie no válida! Alguien ha accedido a esta cuenta desde otro PC con IP: ' . $user->last_ip . ". Si has sido tú, ignora este mensaje.");
                             $this->log_out();
                         }
                     }
                 } else {
                     $this->new_error_msg('¡El usuario ' . $_COOKIE['user'] . ' no existe!');
                     $this->log_out();
                     $this->user->clean_cache(TRUE);
                     $this->cache->clean();
                 }
             }
         }
     }
     return $this->user->logged_on;
 }
コード例 #5
0
 public function process()
 {
     $this->show_fs_toolbar = FALSE;
     $this->ppage = $this->page->get('admin_users');
     $this->agente = new agente();
     $this->ejercicio = new ejercicio();
     $user_no_more_admin = FALSE;
     $this->suser = FALSE;
     if (isset($_GET['snick'])) {
         $this->suser = $this->user->get($_GET['snick']);
     }
     if ($this->suser) {
         $this->page->title = $this->suser->nick;
         if (isset($_POST['ncodagente'])) {
             $age0 = new agente();
             $age0->codagente = $_POST['ncodagente'];
             $age0->nombre = $_POST['nnombre'];
             $age0->apellidos = $_POST['napellidos'];
             $age0->dnicif = $_POST['ndnicif'];
             $age0->telefono = $_POST['ntelefono'];
             $age0->email = $_POST['nemail'];
             if ($age0->save()) {
                 $this->new_message("Empleado " . $age0->codagente . " guardado correctamente.");
                 $this->suser->codagente = $_POST['ncodagente'];
                 if ($this->suser->save()) {
                     $this->new_message("Empleado " . $age0->codagente . " asignado correctamente.");
                 } else {
                     $this->new_error_msg("¡Imposible asignar el agente!");
                 }
             } else {
                 $this->new_error_msg("¡Imposible guardar el agente!");
             }
         } else {
             if (isset($_POST['spassword']) or isset($_POST['scodagente']) or isset($_POST['sadmin'])) {
                 if ($_POST['spassword'] != '') {
                     $this->suser->set_password($_POST['spassword']);
                 }
                 if ($_POST['template'] != '') {
                     $this->suser->template = $_POST['template'];
                 }
                 if (isset($_POST['scodagente'])) {
                     if ($_POST['scodagente'] == '') {
                         $this->suser->codagente = NULL;
                     } else {
                         $this->suser->codagente = $_POST['scodagente'];
                     }
                 }
                 /*
                  * El propio usuario no puede decidir dejar de ser administrador.
                  */
                 if ($this->user->nick != $this->suser->nick) {
                     /*
                      * Si un usuario es administrador y deja de serlo, hay que darle acceso
                      * a algunas páginas, en caso contrario no podrá continuar
                      */
                     if ($this->suser->admin and !isset($_POST['sadmin'])) {
                         $user_no_more_admin = TRUE;
                     }
                     $this->suser->admin = isset($_POST['sadmin']);
                 }
                 $this->suser->fs_page = NULL;
                 if (isset($_POST['udpage'])) {
                     $this->suser->fs_page = $_POST['udpage'];
                 }
                 $this->suser->codejercicio = NULL;
                 if (isset($_POST['ejercicio'])) {
                     $this->suser->codejercicio = $_POST['ejercicio'];
                 }
                 if (FS_DEMO and $this->user->nick != $this->suser->nick) {
                     $this->new_error_msg('En el modo <b>demo</b> sólo puedes modificar los datos de TU usuario.
               Esto es así para evitar malas prácticas entre usuarios que prueban la demo.');
                     $this->suser = $this->user->get($_GET['snick']);
                 } else {
                     if ($this->suser->save()) {
                         if (!$this->suser->admin) {
                             foreach ($this->all_pages() as $p) {
                                 $a = new fs_access(array('fs_user' => $this->suser->nick, 'fs_page' => $p->name));
                                 if ($user_no_more_admin) {
                                     $a->save();
                                 } else {
                                     if (!isset($_POST['enabled'])) {
                                         $a->delete();
                                     } else {
                                         if (!$p->enabled and in_array($p->name, $_POST['enabled'])) {
                                             $a->save();
                                         } else {
                                             if ($p->enabled and !in_array($p->name, $_POST['enabled'])) {
                                                 $a->delete();
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                         $this->new_message("Datos modificados correctamente.");
                     } else {
                         $this->new_error_msg("¡Imposible modificar los datos!");
                     }
                 }
             }
         }
         /// si el usuario no tiene acceso a ninguna página, entonces hay que informar del problema.
         if (!$this->suser->admin) {
             $sin_paginas = TRUE;
             foreach ($this->all_pages() as $p) {
                 if ($p->enabled) {
                     $sin_paginas = FALSE;
                     break;
                 }
             }
             if ($sin_paginas) {
                 $this->new_advice('No has autorizado a este usuario a acceder a ninguna' . ' página y por tanto no podrá hacer nada. Puedes darle acceso a alguna página' . ' desde el panel de más abajo.');
             }
         }
         $fslog = new fs_log();
         $this->user_log = $fslog->all_from($this->suser->nick);
     } else {
         $this->new_error_msg("Usuario no encontrado.");
     }
 }
コード例 #6
0
 /**
  * Devuelve TRUE si el usuario realmente tiene acceso a esta página
  * @return type
  */
 private function log_in()
 {
     $ips = array();
     if ($this->ip_baneada($ips)) {
         $this->banear_ip($ips);
         $this->new_error_msg('Tu IP ha sido baneada. Tendrás que esperar 10 minutos antes de volver a intentar entrar.', 'login', TRUE);
     } else {
         if (isset($_POST['user']) and isset($_POST['password'])) {
             if (FS_DEMO) {
                 if (filter_var($_POST['user'], FILTER_VALIDATE_EMAIL)) {
                     $aux = explode('@', $_POST['user']);
                     $nick = substr($aux[0], 0, 12);
                     if ($nick == 'admin') {
                         $nick .= $this->random_string(7);
                     }
                     $user = $this->user->get($nick);
                     if (!$user) {
                         $user = new fs_user();
                         $user->nick = $nick;
                         $user->set_password('demo');
                         $user->email = $_POST['user'];
                         /// creamos un agente para asociarlo
                         $agente = new agente();
                         $agente->codagente = $agente->get_new_codigo();
                         $agente->nombre = $nick;
                         $agente->apellidos = 'Demo';
                         $agente->email = $_POST['user'];
                         if ($agente->save()) {
                             $user->codagente = $agente->codagente;
                         }
                     }
                     $user->new_logkey();
                     if ($user->save()) {
                         setcookie('user', $user->nick, time() + FS_COOKIES_EXPIRE);
                         setcookie('logkey', $user->log_key, time() + FS_COOKIES_EXPIRE);
                         $this->user = $user;
                         $this->load_menu();
                     }
                 } else {
                     $this->new_error_msg('Email no válido');
                 }
             } else {
                 $user = $this->user->get($_POST['user']);
                 $password = $_POST['password'];
                 if ($user) {
                     /**
                      * En versiones anteriores se guardaban las contraseñas siempre en
                      * minúsculas, por eso, para dar compatibilidad comprobamos también
                      * en minúsculas.
                      */
                     if ($user->password == sha1($password) or $user->password == sha1(mb_strtolower($password, 'UTF8'))) {
                         $user->new_logkey();
                         if (!$user->admin and !$this->ip_in_whitelist($user->last_ip)) {
                             $this->new_error_msg('No puedes acceder desde esta IP.', 'login', TRUE);
                         } else {
                             if ($user->save()) {
                                 setcookie('user', $user->nick, time() + FS_COOKIES_EXPIRE);
                                 setcookie('logkey', $user->log_key, time() + FS_COOKIES_EXPIRE);
                                 $this->user = $user;
                                 $this->load_menu();
                                 /// añadimos el mensaje al log
                                 $fslog = new fs_log();
                                 $fslog->usuario = $user->nick;
                                 $fslog->tipo = 'login';
                                 $fslog->detalle = 'Login correcto.';
                                 $fslog->ip = $user->last_ip;
                                 $fslog->save();
                             } else {
                                 $this->new_error_msg('Imposible guardar los datos de usuario.');
                                 $this->cache->clean();
                             }
                         }
                     } else {
                         $this->new_error_msg('¡Contraseña incorrecta! (' . $_POST['user'] . ')', 'login', TRUE);
                         $this->banear_ip($ips);
                     }
                 } else {
                     $this->new_error_msg('El usuario ' . $_POST['user'] . ' no existe!');
                     $this->user->clean_cache(TRUE);
                     $this->cache->clean();
                 }
             }
         } else {
             if (isset($_COOKIE['user']) and isset($_COOKIE['logkey'])) {
                 $user = $this->user->get($_COOKIE['user']);
                 if ($user) {
                     if ($user->log_key == $_COOKIE['logkey']) {
                         $user->logged_on = TRUE;
                         $user->update_login();
                         $this->user = $user;
                         $this->load_menu();
                     } else {
                         if (!is_null($user->log_key)) {
                             $this->new_message('¡Cookie no válida! Alguien ha accedido a esta cuenta desde otro PC con IP: ' . $user->last_ip . ". Si has sido tú, ignora este mensaje.");
                             $this->log_out();
                         }
                     }
                 } else {
                     $this->new_error_msg('¡El usuario ' . $_COOKIE['user'] . ' no existe!');
                     $this->log_out(TRUE);
                     $this->user->clean_cache(TRUE);
                     $this->cache->clean();
                 }
             }
         }
     }
     return $this->user->logged_on;
 }