示例#1
0
 function validate()
 {
     // TODO
     $errors = array();
     if (!$this->getDataString('description')) {
         $errors['description'] = _Ti('expense_input_description') . _T('warning_field_mandatory');
     }
     if (!preg_match('/^\\d*\\.?\\d*$/', $this->getDataFloat('cost'))) {
         $errors['cost'] = _Ti('expense_input_cost') . 'Format not recognised, please use 9999.99 format';
     }
     // TRAD
     //
     // Custom validation functions
     //
     // * other fields
     $id_expense = $this->getDataInt('id_expense');
     $fields = array('description' => 'ExpenseDescription');
     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('expense_input_' . $f) . $err;
             }
         }
     }
     return $errors;
 }
示例#2
0
 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;
 }
示例#3
0
 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;
 }
示例#4
0
function update_contact($id_contact, $new_value)
{
    if (!$id_contact) {
        lcm_panic("update_contact: no id_contact was provided");
    }
    $old_info = get_contact_by_id($id_contact);
    $kw = get_kwg_from_id($old_info['type_contact']);
    $type_contact = $kw['name'];
    $validator_file = 'contact';
    $validator_func = 'LcmCustomValidateContact';
    // This way, we can validate 'phone_home' or 'phone_mobile' using validate_contact_phone.php
    if (preg_match("/^\\+?([A-Za-z0-9]+)_/", $type_contact, $regs)) {
        $validator_file .= '_' . $regs[1];
        $validator_func .= ucfirst($regs[1]);
        lcm_debug("*********** MATCHES: " . $type_contact . ":" . $validator_file);
    }
    if (include_validator_exists($validator_file)) {
        include_validator($validator_file);
        $foo = new $validator_func();
        if ($err = $foo->validate($old_info['type_person'], $old_info['id_of_person'], $type_contact, $new_value)) {
            return $err;
        }
    }
    if ($old_info['value'] != $new_value) {
        $query = "UPDATE lcm_contact\n\t\t\tSET value = '" . clean_input($new_value) . "', \n\t\t\t\tdate_update = NOW()\n\t\t\t\t\tWHERE id_contact = " . intval($id_contact);
        lcm_query($query);
    }
    return '';
}
示例#5
0
 function validate()
 {
     $errors = array();
     if (!$this->getDataString('name')) {
         $errors['name'] = _Ti('org_input_name') . _T('warning_field_mandatory');
     }
     validate_update_keywords_request('org', $this->getDataInt('id_org'));
     if ($_SESSION['errors']) {
         $errors = array_merge($errors, $_SESSION['errors']);
     }
     //
     // Custom validation functions
     //
     $id_org = $this->getDataInt('id_org');
     $fields = array('name' => 'OrgName', 'court_reg' => 'OrgCourtReg', 'tax_number' => 'OrgTaxNumber', 'stat_number' => 'OrgStatNumber');
     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('org_input_' . $f) . $err;
             }
         }
     }
     return $errors;
 }
示例#6
0
 function validate()
 {
     $errors = array();
     // * Title must be non-empty
     if (!$this->getDataString('title')) {
         $errors['title'] = _Ti('case_input_title') . _T('warning_field_mandatory');
     }
     // * Date assignment must be a valid date
     if (!checkdate_sql($this->getDataString('date_assignment'))) {
         $errors['date_assignment'] = _Ti('case_input_date_assigned') . 'Invalid date.';
     }
     // TRAD
     // * Depending on site policy, legal reason may be mandatory
     if (read_meta('case_legal_reason') == 'yes_mandatory' && !$this->getDataString('legal_reason')) {
         $errors['legal_reason'] = _Ti('case_input_legal_reason') . _T('warning_field_mandatory');
     }
     // * Depending on site policy, alleged crime may be mandatory
     if (read_meta('case_alledged_crime') == 'yes_mandatory' && !$this->getDataString('alledged_crime')) {
         $errors['alledged_crime'] = _Ti('case_input_alledged_crime') . _T('warning_field_mandatory');
     }
     // * TODO: Status must be a valid option (where do we have official list?)
     if (!$this->getDataString('status')) {
         $errors['status'] = _Ti('case_input_status') . _T('warning_field_mandatory');
     }
     // * TODO: Stage must be a valid keyword
     if (!$this->getDataString('stage')) {
         $errors['stage'] = _Ti('case_input_stage') . _T('warning_field_mandatory');
     }
     validate_update_keywords_request('case', $this->getDataInt('id_case'));
     validate_update_keywords_request('stage', $this->getDataInt('id_case'), $this->getDataInt('id_stage'));
     if ($_SESSION['errors']) {
         $errors = array_merge($errors, $_SESSION['errors']);
     }
     //
     // Custom validation functions
     //
     $id_case = $this->getDataInt('id_case');
     $fields = array('title' => 'CaseTitle', 'legal_reason' => 'CaseLegalReason', 'alledged_crime' => 'CaseAllegedCrime', 'status' => 'CaseStatus', 'stage' => 'CaseStage');
     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('case_input_' . $f) . $err;
             }
         }
     }
     return $errors;
 }