foreach ($_POST as $key => $value) { $_SESSION['form_data'][$key] = $value; } $id_expense = _request('id_expense', 0); $id_comment = _request('id_comment', 0); $edit_comment = _request('edit_comment', 0); $ref_url = "edit_exp.php?expense={$id_expense}&edit_comment={$edit_comment}&c={$id_comment}"; if ($_SERVER['HTTP_REFERER']) { $ref_url = $_SERVER['HTTP_REFERER']; } // // Update data // if ($id_comment || $edit_comment) { $obj = new LcmExpenseComment($id_expense, $id_comment); $errs = $obj->save($true); if (!count($errs) && _request('new_exp_status')) { $obj = new LcmExpense($id_expense); $errs = $obj->setStatus(_request('new_exp_status')); } } else { $obj = new LcmExpense($id_expense); $errs = $obj->save(); } if (count($errs)) { $_SESSION['errors'] = array_merge($_SESSION['errors'], $errs); lcm_header("Location: " . $ref_url); exit; } // // Go to the 'view details' page
function save() { $errors = $this->validate(); if (count($errors)) { return $errors; } // // Update record in database // $cl = "type = '" . $this->getDataString('type') . "',\n\t\t\t cost = " . $this->getDataInt('cost') . ",\n\t\t\t description = '" . $this->getDataString('description') . "',\n\t\t\t date_update = NOW(),\n\t\t\t pub_read = 1,\n\t\t\t pub_write = 1"; // XXX add case where id_admin should be updated // XXX add status (user can delete, admin can grant/approve/delete) if ($this->getDataInt('id_expense') > 0) { $q = "UPDATE lcm_expense\n\t\t\t\tSET {$cl} \n\t\t\t\tWHERE id_expense = " . $this->getDataInt('id_expense', '__ASSERT__'); lcm_query($q); } else { $q = "INSERT INTO lcm_expense\n\t\t\t\t\tSET date_creation = NOW(), \n\t\t\t\t\t\tid_admin = 0,\n\t\t\t\t\t\tid_author = " . $this->getDataInt('id_author') . ",\n\t\t\t\t\t\tid_followup = " . $this->getDataInt('id_followup') . ",\n\t\t\t\t\t\tid_case = " . $this->getDataInt('id_case') . ",\n\t\t\t\t\t\tstatus = 'pending',\n\t\t\t\t\t\t{$cl}"; $result = lcm_query($q); $this->data['id_expense'] = lcm_insert_id('lcm_expense', 'id_expense'); $comment = new LcmExpenseComment($this->data['id_expense'], 0); $comment->save(); } return $errors; }