Пример #1
0
 public function update()
 {
     if ($_SERVER['REQUEST_METHOD'] === 'GET' and isset($_GET['id']) and is_numeric($_GET['id'])) {
         $certificate = modelClass::certifyId($_GET['id']);
         if (is_array($certificate)) {
             if (count($certificate) > 0) {
                 $data = modelClass::getRow($_GET['id']);
                 if (is_array($data)) {
                     if (count($data) > 0) {
                         $args['txtid'] = $data[0]['id_aprendiz'];
                         $args['txtapre'] = $data[0]['nom_pre'];
                         $args['txtape'] = $data[0]['apell_apre'];
                         $args['txttel'] = $data[0]['tel'];
                         $args['txtciudad'] = $data[0]['cod_ciudad'];
                         $args['txttipo'] = $data[0]['cod_rh'];
                         $args['txttipoid'] = $data[0]['cod_tipo_id'];
                         $args['txtgenero'] = $data[0]['genero'];
                         $args['txtedad'] = $data[0]['edad'];
                     }
                 } else {
                     $args['error'] = $data;
                     viewClass::renderHTML('error.php', $args);
                 }
             }
         } else {
             $args['error'] = $certificate;
             viewClass::renderHTML('error.php', $args);
         }
         $args['formAction'] = 'index.php?action=update&id=' . $_GET['id'];
         viewClass::renderHTML('update.php', $args);
     } elseif ($_SERVER['REQUEST_METHOD'] === 'POST') {
         $data['nom_pre'] = $_POST['txtapre'];
         $data['apell_apre'] = $_POST['txtape'];
         $data['tel'] = $_POST['txttel'];
         $data['cod_ciudad'] = $_POST['txtciudad'];
         $data['cod_rh'] = $_POST['txttipo'];
         $data['cod_tipo_id'] = $_POST['txttipoid'];
         $data['genero'] = $_POST['txtgenero'];
         $data['edad'] = $_POST['txtedad'];
         $rsp = modelClass::updateUsuario($_GET['id'], $data);
         if ($rsp === true) {
             $args['success'] = 'Los cambios fueron realizados exitosamente';
         } else {
             $args['error'] = $rsp->getMessage();
         }
         $args['formAction'] = 'index.php?action=update&id=' . $_GET['id'];
         $args = array_merge($args, $_POST);
         viewClass::renderHTML('update.php', $args);
     } else {
         $this->index();
     }
 }
 public function update()
 {
     if ($_SERVER['REQUEST_METHOD'] === 'GET' and isset($_GET['id']) and is_numeric($_GET['id'])) {
         $certificate = modelClass::certifyId($_GET['id']);
         if (is_array($certificate)) {
             if (count($certificate) > 0) {
                 $data = modelClass::getRow($_GET['id']);
                 if (is_array($data)) {
                     if (count($data) > 0) {
                         $args['idUsuario'] = $data[0]['id'];
                         $args['txtUsuario'] = $data[0]['usuario'];
                         $args['rdoActivado'] = $data[0]['activado'] === '1' ? 'true' : 'false';
                     }
                 } else {
                     $args['error'] = $data;
                     viewClass::renderHTML('error.php', $args);
                 }
             }
         } else {
             $args['error'] = $certificate;
             viewClass::renderHTML('error.php', $args);
         }
         $args['formAction'] = 'index.php?action=update&id=' . $_GET['id'];
         viewClass::renderHTML('update.php', $args);
     } elseif ($_SERVER['REQUEST_METHOD'] === 'POST') {
         if (isset($_POST['txtPassword1']) and strlen($_POST['txtPassword1']) > 0 or isset($_POST['txtPassword2']) and strlen($_POST['txtPassword2']) > 0) {
             if ($_POST['txtPassword1'] === $_POST['txtPassword2']) {
                 $data['password'] = md5($_POST['txtPassword1']);
             } else {
                 $args['error'] = 'Las contraseñas no son iguales';
                 $args['formAction'] = 'index.php?action=update&id=' . $_GET['id'];
                 $args = array_merge($args, $_POST);
                 viewClass::renderHTML('update.php', $args);
             }
         }
         $data['usuario'] = $_POST['txtUsuario'];
         $data['activado'] = $_POST['rdoActivado'] === 'true' ? 1 : 0;
         $rsp = modelClass::updateUsuario($_GET['id'], $data);
         if ($rsp === true) {
             $args['success'] = 'Los cambios fueron realizados exitosamente';
         } else {
             $args['error'] = $rsp->getMessage();
         }
         $args['formAction'] = 'index.php?action=update&id=' . $_GET['id'];
         $args = array_merge($args, $_POST);
         viewClass::renderHTML('update.php', $args);
     } else {
         $this->index();
     }
 }