die("Sorry. You can't access directly to this file");
}
-use Analog\Analog;
-
/**
* Check URL validity
*
$url
));
}
-
-/**
- * Custom HTML entitiy decode
- *
- * @param string $given_html Original HTML
- * @param int $quote_style Quoting style
- *
- * @return string
- */
-function custom_html_entity_decode($given_html, $quote_style = ENT_QUOTES)
-{
- $trans_table = array_flip(
- get_html_translation_table(
- HTML_ENTITIES,
- $quote_style
- )
- );
- $trans_table['''] = "'";
- return strtr($given_html, $trans_table);
-}
-
-/**
- * Get a value sent by a form, either in POST and GET arrays
- *
- * @param string $name property name
- * @param string $defval default rollback value
- *
- * @return string value retrieved from :
- * - GET array if defined and numeric,
- * - POST array if defined and numéric
- * - $defval otherwise
- */
-function get_form_value($name, $defval)
-{
- $val = $defval;
- if (isset($_GET[$name])) {
- $val = $_GET[$name];
- } elseif (isset($_POST[$name])) {
- $val = $_POST[$name];
- }
- return $val;
-}
-
-/**
- * Get a numeric value sent by a form, either in POST and GET arrays
- *
- * @param string $name property name
- * @param string $defval default rollback value
- *
- * @return numeric value retrieved from :
- * - GET array if defined and numeric,
- * - POST array if defined and numéric
- * - $defval otherwise
- */
-function get_numeric_form_value($name, $defval)
-{
- $val = get_form_value($name, $defval);
- if (!is_numeric($val)) {
- Analog::log(
- '[get_numeric_form_value] not a numeric value! (value was: `' .
- $val . '`)',
- Analog::INFO
- );
- $val = $defval;
- }
- return $val;
-}
-
-/**
- * Get a post numeric value
- *
- * @param string $name property name
- * @param string $defval default rollback value
- *
- * @return string value retrieved from :
- * - POST array if defined and numéric
- * - $defval otherwise
- */
-function get_numeric_posted_value($name, $defval)
-{
- if (isset($_POST[$name])) {
- $val = $_POST[$name];
- if (is_numeric($val)) {
- return $val;
- }
- }
- return $defval;
-}
-
-if (!function_exists('str_contains')) {
- /**
- * PHP8 str_contains polyfill
- *
- * based on original work from the PHP Laravel framework
- * see https://www.php.net/manual/fr/function.str-contains.php#125977
- *
- * @param string $haystack The string to search in.
- * @param string $needle The substring to search for in the haystack
- *
- * @return bool
- */
- function str_contains($haystack, $needle)
- {
- return $needle !== '' && mb_strpos($haystack, $needle) !== false;
- }
-}
*/
public function edit(Request $request, Response $response, int $id = null, string|null $action = 'edit'): Response
{
- $trans = null;
-
if ($this->session->transaction !== null) {
$trans = $this->session->transaction;
$this->session->transaction = null;
$trans_id = $id;
}
- $transaction['trans_id'] = $trans_id;
- $transaction['trans_amount'] = get_numeric_form_value("trans_amount", '');
- $transaction['trans_date'] = get_form_value("trans_date", '');
- $transaction['trans_desc'] = get_form_value("trans_desc", '');
- $transaction['id_adh'] = get_numeric_form_value("id_adh", '');
-
// flagging required fields
$required = array(
'trans_amount' => 1,
$params = [
'page_title' => $title,
'required' => $required,
- 'data' => $transaction, //TODO: remove
'transaction' => $trans
];