/** * Update a user */ public function update() { if ($_SERVER['REQUEST_METHOD'] === 'GET' and isset($_GET['cod_rh']) and is_numeric($_GET['cod_rh'])) { $certificate = modelClass::certifyRh($_GET['cod_rh']); if (is_array($certificate)) { if (count($certificate) > 0) { $data = modelClass::getRow($_GET['cod_rh']); if (is_array($data)) { if (count($data) > 0) { $args['textId'] = $data[0]['cod_rh']; $args['textDes'] = $data[0]['des_rh']; } } else { $args['error'] = $data; viewClass::renderHTML('error.php', $args); } } } else { $args['error'] = $certificate; viewClass::renderHTML('error.php', $args); } $args['formAction'] = 'index.php?action=update&cod_rh=' . $_GET['cod_rh']; viewClass::renderHTML('update.php', $args); } else { if ($_SERVER['REQUEST_METHOD'] === 'POST') { $data['cod_rh'] = $_POST['textId']; $data['des_rh'] = $_POST['textDes']; $rsp = modelClass::updateRh($_GET['cod_rh'], $data); if ($rsp === true) { $args['success'] = 'Los cambios fueron realizados exitosamente'; } else { $args['error'] = $rsp->getMessage(); } $args['formAction'] = 'index.php?action=update&cod_rh=' . $_GET['cod_rh']; $args = array_merge($args, $_POST); viewClass::renderHTML('update.php', $args); } else { $this->index(); } } }