Пример #1
0
function get_date_range_fields()
{
    $ret = array();
    $link = new Link();
    $link->delVar('date_start_day');
    $link->delVar('date_start_month');
    $link->delVar('date_start_year');
    $link->delVar('date_end_day');
    $link->delVar('date_end_month');
    $link->delVar('date_end_year');
    $ret['html'] = $link->getForm();
    // By default, show from "now() - 1 month" to NOW().
    // Unlike in case_details, we cannot show all, since it would return
    // too many results.
    $ret['html'] .= "<p class=\"normal_text\">\n";
    $ret['date_end'] = get_datetime_from_array($_REQUEST, 'date_end', 'end', "-1");
    $ret['date_start'] = get_datetime_from_array($_REQUEST, 'date_start', 'start', date('Y-m-d H:i:s', strtotime("-1 month" . ($ret['date_end'] != "-1" ? $ret['date_end'] : date('Y-m-d H:i:s')))));
    $ret['html'] .= _Ti('time_input_date_start');
    $ret['html'] .= get_date_inputs('date_start', $ret['date_start']);
    $ret['html'] .= _Ti('time_input_date_end');
    if ($ret['date_end'] == "-1") {
        $ret['html'] .= get_date_inputs('date_end');
    } else {
        $ret['html'] .= get_date_inputs('date_end', $ret['date_end']);
    }
    $ret['html'] .= ' <button name="submit" type="submit" value="submit" class="simple_form_btn">' . _T('button_validate') . "</button>\n";
    $ret['html'] .= "</p>\n";
    $ret['html'] .= "</form>\n";
    return $ret;
}
Пример #2
0
 function LcmClient($id_client = 0)
 {
     $id_client = intval($id_client);
     $this->cases = null;
     $this->case_start_from = 0;
     $this->LcmObject();
     if ($id_client > 0) {
         $query = "SELECT * FROM lcm_client WHERE id_client = {$id_client}";
         $result = lcm_query($query);
         if ($row = lcm_fetch_array($result)) {
             foreach ($row as $key => $val) {
                 $this->data[$key] = $val;
             }
         }
     }
     // If any, populate form values submitted
     foreach ($_REQUEST as $key => $value) {
         $nkey = $key;
         if (substr($key, 0, 7) == 'client_') {
             $nkey = substr($key, 7);
         }
         $this->data[$nkey] = _request($key);
     }
     // If any, populate with session variables (for error reporting)
     if (isset($_SESSION['form_data'])) {
         foreach ($_SESSION['form_data'] as $key => $value) {
             $nkey = $key;
             if (substr($key, 0, 7) == 'client_') {
                 $nkey = substr($key, 7);
             }
             $this->data[$nkey] = _session($key);
         }
     }
     if (get_datetime_from_array($_SESSION['form_data'], 'date_birth', 'start', -1) != -1) {
         $this->data['date_birth'] = get_datetime_from_array($_SESSION['form_data'], 'date_birth', 'start');
     }
 }
Пример #3
0
if (!count($_SESSION['errors']) && $unix_end_time < $unix_start_time) {
    $_SESSION['errors']['end_time'] = "The date interval is not valid (end before start)";
}
// TRAD
// reminder
if ($prefs['time_intervals'] == 'absolute') {
    // Set to default empty date if all fields empty
    if (!($_SESSION['form_data']['reminder_year'] || $_SESSION['form_data']['reminder_month'] || $_SESSION['form_data']['reminder_day'])) {
        $_SESSION['form_data']['reminder'] = '0000-00-00 00:00:00';
    } elseif (!$_SESSION['form_data']['reminder_year'] || !$_SESSION['form_data']['reminder_month'] || !$_SESSION['form_data']['reminder_day']) {
        $_SESSION['errors']['reminder'] = 'Incomplete reminder time';
        // TRAD
        $_SESSION['form_data']['reminder'] = get_datetime_from_array($_SESSION['form_data'], 'reminder', 'start', '', false);
    } else {
        // Join fields and check resulting time
        $_SESSION['form_data']['reminder'] = get_datetime_from_array($_SESSION['form_data'], 'reminder', 'start', '', false);
        $unix_reminder_time = strtotime($_SESSION['form_data']['reminder']);
        if ($unix_reminder_time < 0 || !checkdate($_SESSION['form_data']['reminder_month'], $_SESSION['form_data']['reminder_day'], $_SESSION['form_data']['reminder_year'])) {
            $_SESSION['errors']['reminder'] = 'Invalid reminder time!';
        }
        // TRAD
    }
} else {
    if (!(isset($_SESSION['form_data']['rem_offset_days']) && (!is_numeric($_SESSION['form_data']['rem_offset_days']) || $_SESSION['form_data']['rem_offset_days'] < 0) || isset($_SESSION['form_data']['rem_offset_hours']) && (!is_numeric($_SESSION['form_data']['rem_offset_hours']) || $_SESSION['form_data']['rem_offset_hours'] < 0) || isset($_SESSION['form_data']['rem_offset_minutes']) && (!is_numeric($_SESSION['form_data']['rem_offset_minutes']) || $_SESSION['form_data']['rem_offset_minutes'] < 0))) {
        $unix_reminder_time = $unix_start_time - $_SESSION['form_data']['rem_offset_days'] * 86400 - $_SESSION['form_data']['rem_offset_hours'] * 3600 - $_SESSION['form_data']['rem_offset_minutes'] * 60;
        $_SESSION['form_data']['reminder'] = date('Y-m-d H:i:s', $unix_reminder_time);
    } else {
        $_SESSION['errors']['reminder'] = _Ti('app_input_reminder') . _T('time_warning_invalid_format') . ' (' . $_SESSION['form_data']['rem_offset_hours'] . ')';
        // XXX
        $_SESSION['form_data']['reminder'] = $_SESSION['form_data']['start_time'];
    }
Пример #4
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;
 }
Пример #5
0
         case 'date_ge':
             // 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";
 }
Пример #6
0
 function printFollowups($show_filters = false)
 {
     $cpt = 0;
     $my_list_pos = intval(_request('list_pos', 0));
     show_page_subtitle(_T('case_subtitle_followups'), 'cases_followups');
     // Show filters (if not shown in ajaxed page)
     if ($show_filters) {
         // By default, show from "case creation date" to NOW().
         $link = new Link();
         $link->delVar('date_start_day');
         $link->delVar('date_start_month');
         $link->delVar('date_start_year');
         $link->delVar('date_end_day');
         $link->delVar('date_end_month');
         $link->delVar('date_end_year');
         echo $link->getForm();
         $date_end = get_datetime_from_array($_REQUEST, 'date_end', 'end', '0000-00-00 00:00:00');
         // date('Y-m-d H:i:s'));
         $date_start = get_datetime_from_array($_REQUEST, 'date_start', 'start', '0000-00-00 00:00:00');
         // $row['date_creation']);
         echo _Ti('time_input_date_start');
         echo get_date_inputs('date_start', $date_start);
         echo _Ti('time_input_date_end');
         echo get_date_inputs('date_end', $date_end);
         echo ' <button name="submit" type="submit" value="submit" class="simple_form_btn">' . _T('button_validate') . "</button>\n";
         echo "</form>\n";
         echo "<div style='margin-bottom: 4px;'>&nbsp;</div>\n";
         // FIXME patch for now (leave small space between filter and list)
     }
     show_listfu_start('general', false);
     for ($cpt = 0, $this->getFollowupStart(); !$this->getFollowupDone(); $cpt++) {
         $item = $this->getFollowupIterator();
         show_listfu_item($item, $cpt);
     }
     if (!$cpt) {
         echo "No followups";
     }
     // TRAD
     show_list_end($my_list_pos, $this->getFollowupTotal(), true);
 }
Пример #7
0
function apply_filter($f)
{
    $ret = '';
    $filter_conv = array("neq" => "!=", "eq" => "=", "lt" => "<", "le" => "<=", "gt" => ">", "ge" => ">=");
    if (!$f['type']) {
        return '';
    }
    if ($f['type'] == 'date_in') {
        $dates = array();
        if ($f['value']) {
            $dates = explode(";", $f['value']);
        } else {
            $dates[0] = get_datetime_from_array($_REQUEST, 'filter_val' . $f['id_filter'] . '_start', 'start');
            $dates[1] = get_datetime_from_array($_REQUEST, 'filter_val' . $f['id_filter'] . '_end', 'end');
        }
        $ret .= "(DATE_FORMAT(" . prefix_field($f['table_name'], $f['field_name']) . ", '%Y-%m-%d') " . " >= DATE_FORMAT('" . $dates[0] . "', '%Y-%m-%d')" . " AND DATE_FORMAT(" . prefix_field($f['table_name'], $f['field_name']) . ", '%Y-%m-%d') " . " <= DATE_FORMAT('" . $dates[1] . "', '%Y-%m-%d')) ";
    } else {
        $foo = explode("_", $f['type']);
        // ex: date_eq
        $filter_type = $foo[0];
        // date
        $filter_op = $foo[1];
        // eq
        if (!$f['value']) {
            if (isset($_REQUEST['filter_val' . $f['id_filter']])) {
                $f['value'] = $_REQUEST['filter_val' . $f['id_filter']];
            }
        }
        // FIELD OPERATOR 'VALUE'
        if ($filter_conv[$filter_op]) {
            switch ($filter_type) {
                case 'date':
                    $ret .= "DATE_FORMAT(" . prefix_field($f['table_name'], $f['field_name']) . ", '%Y-%m-%d')" . " " . $filter_conv[$filter_op] . " " . "DATE_FORMAT('" . get_datetime_from_array($_REQUEST, 'filter_val' . $f['id_filter']) . "', '%Y-%m-%d') ";
                    break;
                case 'text':
                    $ret .= $f['field_name'] . " " . $filter_conv[$filter_op] . " " . "'" . $f['value'] . "' ";
                    break;
                default:
                    // number
                    if ($f['description'] == 'time_input_length') {
                        $f['value'] = " " . $f['value'] . " * 3600 ";
                    }
                    $ret .= $f['field_name'] . " " . $filter_conv[$filter_op] . " " . $f['value'] . " ";
            }
        } else {
            lcm_log("no filter_conv for {$filter_op} ?");
            return '';
        }
    }
    return $ret;
}