// // Start date // $_SESSION['form_data']['start_time'] = get_datetime_from_array($_SESSION['form_data'], 'start', 'start', '', false); $unix_start_time = strtotime($_SESSION['form_data']['start_time']); if ($unix_start_time < 0 || !checkdate_sql($_SESSION['form_data']['start_time'])) { $_SESSION['errors']['start_time'] = _Ti('time_input_date_start') . 'Invalid date'; } // TRAD // // End date // if ($prefs['time_intervals'] == 'absolute') { $_SESSION['form_data']['end_time'] = get_datetime_from_array($_SESSION['form_data'], 'end', 'start', '', false); // Set to default empty date if all fields empty if (!isset_datetime_from_array($_SESSION['form_data'], 'end', 'date_only')) { $_SESSION['errors']['end_time'] = _Ti('time_input_date_end') . 'Invalid date'; // TRAD } else { $unix_end_time = strtotime($_SESSION['form_data']['end_time']); if ($unix_end_time < 0 || !checkdate_sql($_SESSION['form_data']['end_time'])) { $_SESSION['errors']['end_time'] = _Ti('time_input_date_end') . 'Invalid date'; } // TRAD } } else { if (!(isset($_SESSION['form_data']['delta_days']) && (!is_numeric($_SESSION['form_data']['delta_days']) || $_SESSION['form_data']['delta_days'] < 0) || isset($_SESSION['form_data']['delta_hours']) && (!is_numeric($_SESSION['form_data']['delta_hours']) || $_SESSION['form_data']['delta_hours'] < 0) || isset($_SESSION['form_data']['delta_minutes']) && (!is_numeric($_SESSION['form_data']['delta_minutes']) || $_SESSION['form_data']['delta_minutes'] < 0))) { $unix_end_time = $unix_start_time + $_SESSION['form_data']['delta_days'] * 86400 + $_SESSION['form_data']['delta_hours'] * 3600 + $_SESSION['form_data']['delta_minutes'] * 60; $_SESSION['form_data']['end_time'] = date('Y-m-d H:i:s', $unix_end_time); } else { $_SESSION['errors']['end_time'] = _Ti('app_input_time_length') . _T('time_warning_invalid_format') . ' (' . $_SESSION['form_data']['delta_hours'] . ')';
function validate() { $errors = array(); // * Check for id_case if (!($this->getDataInt('id_case') > 0)) { $errors['id_case'] = "Internal error: No id_case found"; } // * Check for fu type if (!$this->getDataString('type')) { $errors['type'] = _Ti('fu_input_type') . _T('warning_field_mandatory'); } // * Check if fu type exists if (!get_kw_from_name('followups', $this->getDataString('type'))) { $errors['type'] = _Ti('fu_input_type') . "Unknown type"; } // TRAD // * Check start date $unix_date_start = strtotime($this->getDataString('date_start')); if ($unix_date_start < 0 || !checkdate_sql($this->getDataString('date_start'))) { $errors['date_start'] = _Ti('time_input_date_start') . 'Invalid start date.'; } // TRAD if (!is_numeric($this->getDataFloat('sumbilled', 0.0))) { $errors['sumbilled'] = _Ti('fu_input_sum_billed') . 'Incorrect format, must be 00000.00'; } // TRAD // * Check end date // [ML] This is probably very buggy, because I re-wrote parts of it // to make it LCM 0.7.0 compliant, but it's a hell of a mess! // And parts of this code should be in the constructor. global $prefs; if ($prefs['time_intervals'] == 'absolute') { if (isempty_datetime_from_array($_SESSION['form_data'], 'end', 'date_only')) { // Set to default empty date if all fields empty $this->data['date_end'] = '0000-00-00 00:00:00'; } elseif (!isset_datetime_from_array($_SESSION['form_data'], 'end', 'date_only')) { // Report error if some of the fields empty $this->data['date_end'] = get_datetime_from_array($_SESSION['form_data'], 'end', 'start', '', false); $errors['date_end'] = 'Partial end date!'; // TRAD } else { $this->data['date_end'] = get_datetime_from_array($_SESSION['form_data'], 'end', 'start', '', false); $unix_date_end = strtotime($this->getDataString('date_end')); if ($unix_date_end < 0 || !checkdate_sql($this->getDataString('date_end'))) { $errors['date_end'] = 'Invalid end date.'; } // TRAD } } else { $valid_interval = true; $unix_date_end = $unix_date_start; $_SESSION['form_data']['delta_days'] = trim($_SESSION['form_data']['delta_days']); $_SESSION['form_data']['delta_hours'] = trim($_SESSION['form_data']['delta_hours']); $_SESSION['form_data']['delta_minutes'] = trim($_SESSION['form_data']['delta_minutes']); if (is_numeric(_session('delta_days', 0)) && _session('delta_days', 0) >= 0) { $unix_date_end += _session('delta_days', 0) * 86400; } else { $valid_interval = false; } if (is_numeric(_session('delta_hours', 0)) && _session('delta_hours', 0) >= 0) { $unix_date_end += _session('delta_hours', 0) * 3600; } else { $valid_interval = false; } if (is_numeric(_session('delta_minutes', 0)) && _session('delta_minutes', 0) >= 0) { $unix_date_end += _session('delta_minutes', 0) * 60; } else { $valid_interval = false; } if ($valid_interval) { $this->data['date_end'] = date('Y-m-d H:i:s', $unix_date_end); } else { $errors['date_end'] = _Ti('time_input_length') . 'Invalid time interval.'; // TRAD $this->data['date_end'] = $_SESSION['form_data']['date_start']; } } // Description /* [ML] This was requested to be optional (MG, PDO) if ( !(strlen($this->data['description']) > 0) ) $errors['description'] = _Ti('fu_input_description') . _T('warning_field_mandatory'); */ validate_update_keywords_request('followup', $this->getDataInt('id_followup')); if ($_SESSION['errors']) { $errors = array_merge($errors, $_SESSION['errors']); } // // Custom validation functions // $id_case = $this->getDataInt('id_case'); $fields = array('description' => 'FollowupDescription'); foreach ($fields as $f => $func) { if (include_validator_exists($f)) { include_validator($f); $class = "LcmCustomValidate{$func}"; $data = $this->getDataString($f); $v = new $class(); if ($err = $v->validate($id_case, $data)) { $errors[$f] = _Ti('fu_input_' . $f) . $err; } } } return $errors; }
// ex: date >= 2005 becomes date >= 2005-01-01 00:00:00 // ex: date >= 2005 becomes date >= 2005-01-01 00:00:00 case 'date_lt': // ex: date < 2005 becomes date < 2005-01-01 00:00:00 $date = get_datetime_from_array($_REQUEST, 'date', 'start', '0000-00-00 00:00:00'); array_push($fields, "value = IF(TO_DAYS('{$date}') > 0, '" . $date . "', '')"); break; case 'date_gt': // ex: date > 2005 becomes date > 2005-12-31 23:59:59 $date = get_datetime_from_array($_REQUEST, 'date', 'end', '0000-00-00 00:00:00'); array_push($fields, "value = IF(TO_DAYS('{$date}') > 0, '" . $date . "', '')"); break; case 'date_in': $date_start = get_datetime_from_array($_REQUEST, 'date_start', 'start', '0000-00-00 00:00:00'); $date_end = get_datetime_from_array($_REQUEST, 'date_end', 'end', '0000-00-00 00:00:00'); if (isset_datetime_from_array($_REQUEST, 'date_start', 'year_only') || isset_datetime_from_array($_REQUEST, 'date_end', 'year_only')) { array_push($fields, "value = CONCAT(" . "IF(TO_DAYS('{$date_start}') > 0, '{$date_start}', '')," . "';'," . "IF(TO_DAYS('{$date_end}') > 0, '{$date_end}', '')" . ")"); } break; default: $value = clean_input($_REQUEST['filter_value']); array_push($fields, "value = '" . $value . "'"); } if (count($fields)) { $flist = implode(", ", $fields); } $query = "UPDATE lcm_rep_filter\n\t\t\t\t\t\tSET " . $flist . "\n\t\t\t\t\t\tWHERE id_filter = " . $id_filter; lcm_query($query); $ref_tag = "#filter"; } }
function validate() { $errors = array(); if (!$this->getDataString('name_first')) { $errors['name_first'] = _Ti('person_input_name_first') . _T('warning_field_mandatory'); } if (!$this->getDataString('name_last')) { $errors['name_last'] = _Ti('person_input_name_last') . _T('warning_field_mandatory'); } if (read_meta('client_name_middle') == 'yes_mandatory' && !$this->getDataString('name_middle')) { $errors['name_middle'] = _Ti('person_input_name_middle') . _T('warning_field_mandatory'); } if (read_meta('client_citizen_number') == 'yes_mandatory' && !$this->getDataString('citizen_number')) { $errors['citizen_number'] = _Ti('person_input_citizen_number') . _T('warning_field_mandatory'); } if (read_meta('client_civil_status') == 'yes_mandatory' && !$this->getDataString('civil_status')) { $errors['civil_status'] = _Ti('person_input_civil_status') . _T('warning_field_mandatory'); } if (read_meta('client_income') == 'yes_mandatory' && !$this->getDataString('income')) { $errors['income'] = _Ti('person_input_income') . _T('warning_field_mandatory'); } // * Check gender $genders = array('unknown' => 1, 'female' => 1, 'male' => 1); if (!array_key_exists($this->getDataString('gender'), $genders)) { $errors['gender'] = _Ti('person_input_gender') . 'Incorrect format.'; } // TRAD FIXME // * Check for date of birth $meta_date_birth = read_meta('client_date_birth'); $date_birth = $this->getDataString('date_birth'); if ($meta_date_birth == 'yes_mandatory' && (!$date_birth || $date_birth == -1)) { $errors['date_birth'] = _Ti('person_input_date_birth') . _T('warning_field_mandatory'); } else { if ($date_birth) { if (!isset_datetime_from_array($_SESSION['form_data'], 'date_birth', 'date_only')) { $errors['date_birth'] = _Ti('person_input_date_birth') . "Partial date."; // TRAD } else { $unix_date_birth = strtotime($date_birth); if ($unix_date_birth < 0 || !checkdate_sql($date_birth)) { $errors['date_birth'] = 'Invalid end date.'; } // TRAD } } } // // Custom validation functions // // * Client name (special function) if (include_validator_exists('client_name')) { include_validator('client_name'); $foo = new LcmCustomValidateClientName(); $test = array('first', 'last'); if (substr(read_meta('client_name_middle'), 0, 3) == 'yes') { array_push($test, 'middle'); } foreach ($test as $t) { $n = $this->getDataString('name_' . $t); if ($err = $foo->validate($this->getDataInt('id_client'), $t, $n)) { $errors['name_' . $t] = _Ti('person_input_name_' . $t) . $err; } } } // * other fields $id_client = $this->getDataInt('id_client'); $fields = array('citizen_number' => 'ClientCitizenNumber', 'civil_status' => 'ClientCivilStatus', 'income' => 'ClientIncome', 'gender' => 'PersonGender'); foreach ($fields as $f => $func) { if (include_validator_exists($f)) { include_validator($f); $class = "LcmCustomValidate{$func}"; $data = $this->getDataString($f); $v = new $class(); if ($err = $v->validate($id_client, $data)) { $errors[$f] = _Ti('person_input_' . $f) . $err; } } } return $errors; }
function show_filters_info($report) { if (!$report->getOption('headers_sent')) { return; } $my_filters = get_filters($report->getId()); if (count($my_filters)) { echo '<p class="normal_text">'; } foreach ($my_filters as $f) { if (!$f['value']) { // Value may be provided by $_REQUEST if (isset($_REQUEST['filter_val' . $f['id_filter']])) { // text or number $f['value'] = $_REQUEST['filter_val' . $f['id_filter']]; } elseif (isset_datetime_from_array($_REQUEST, 'filter_val' . $f['id_filter'], 'year_only')) { // Date $f['value'] = get_datetime_from_array($_REQUEST, 'filter_val' . $f['id_filter'], 'year_only'); } elseif (isset_datetime_from_array($_REQUEST, 'filter_val' . $f['id_filter'] . "_start", 'year_only') && isset_datetime_from_array($_REQUEST, 'filter_val' . $f['id_filter'] . "_end", 'year_only')) { // Date interval $f['value'] = get_datetime_from_array($_REQUEST, 'filter_val' . $f['id_filter'] . "_start", 'start'); $f['value'] .= ";"; $f['value'] .= get_datetime_from_array($_REQUEST, 'filter_val' . $f['id_filter'] . "_end", 'end'); } else { // Should never happen $f['value'] = _T('info_not_available'); } } // TODO: If field.type == text and field.value is based on keyword or // list, use translation if known. if ($f['enum_type']) { $enum = explode(":", $f['enum_type']); if ($enum[0] == 'keyword') { if ($enum[2]) { $f['value'] = _Tkw($enum[2], $f['value']); } } elseif ($enum[0] == 'list') { if ($enum[2]) { $f['value'] = _T($enum[2] . $f['value']); } } } // Example: "Follow-up - Start: in 1 Apr 05, 00h00 - 31 Dec 05, 23h59" // or.....: Table - Field: type_filter value echo _T('rep_info_table_' . $f['table_name']) . " - " . _Ti($f['description']) . _T('rep_filter_' . $f['type']) . " "; switch ($f['type']) { case 'date_in': $values = split(";", $f['value']); echo format_date($values[0], 'short') . " - " . format_date($values[1], 'short'); break; case 'date_eq': case 'date_ge': case 'date_gt': case 'date_le': case 'date_lt': echo format_date($f['value'], 'short'); break; default: echo $f['value']; } echo "<br />\n"; } if (count($my_filters)) { echo "</p>\n"; } }