Example #1
0
function _Tkw($grp, $val, $args = '')
{
    global $system_kwg;
    $kwg = array();
    // If a 'contact' keyword (starts with +), remove the +
    if (substr($val, 0, 1) == '+') {
        $val = substr($val, 1);
    }
    if ($system_kwg[$grp]) {
        $kwg = $system_kwg[$grp]['keywords'];
    } else {
        $kwg = get_keywords_in_group_name($grp, false);
    }
    if (count($kwg)) {
        if ($kwg[$val]) {
            return _T(remove_number_prefix($kwg[$val]['title']), $args);
        } else {
            // This is a weird case where the upgrade didn't refresh the
            // group correctly, so we will try to fix the situation.
            // First, we check in the database to see if the keyword exists,
            // and if it does, then we refresh the keywords.
            // Note: that get_keywords_in_group_id() consults only the DB
            // [ML] Note: this should not happen from 0.6.3, but i'm fed up of
            // thinking that this time we fixed it, so the code stays..
            $tmp_group = get_kwg_from_name($grp);
            $kws1 = get_keywords_in_group_id($tmp_group['id_group'], false);
            foreach ($kws1 as $kw) {
                if ($kw['name'] == $val) {
                    include_lcm('inc_keywords_default');
                    $system_keyword_groups = get_default_keywords();
                    create_groups($system_keyword_groups);
                    write_metas();
                    // regenerate inc/data/inc_meta_cache.php
                    return _T(remove_number_prefix($kw['title']), $args);
                }
            }
            lcm_panic("*** The keyword does not exist. It is possible that a\n\t\t\t\tminor error occured while the last upgrade of the software. Please\n\t\t\t\task your administrator to do the following: Go to the 'Keywords'\n\t\t\t\tmenu, then click on the 'Maintenance' tab, then click on the\n\t\t\t\t'Validate' button. This will refresh the available keywords.");
        }
    } else {
        lcm_panic("*** The keyword group does not exist. It is possible that a\n\t\t\tminor error occured while the last upgrade of the software. Please\n\t\t\task your administrator to do the following: Go to the 'Keywords'\n\t\t\tmenu, then click on the 'Maintenance' tab, then click on the\n\t\t\t'Validate' button. This will refresh the available keywords.");
    }
}
Example #2
0
function show_report_filters($id_report, $is_runtime = false)
{
    // Get general report info
    $q = "SELECT * FROM lcm_report WHERE id_report = " . intval($id_report);
    $res = lcm_query($q);
    $rep_info = lcm_fetch_array($res);
    if (!$rep_info) {
        lcm_panic("Report does not exist: {$id_report}");
    }
    // List filters attached to this report
    $query = "SELECT *\n\t\tFROM lcm_rep_filter as v, lcm_fields as f\n\t\tWHERE id_report = " . $id_report . "\n\t\tAND f.id_field = v.id_field";
    // If generating the report (as opposed to editing), show filters
    // who have a filter type (eq, neq, in, ..), but no value.
    if ($is_runtime) {
        $query .= " AND v.type != '' AND v.value = '' ";
    }
    $result = lcm_query($query);
    if (lcm_num_rows($result)) {
        if ($is_runtime) {
            // submit all at once (else submit on a per-filter basis)
            echo '<form action="run_rep.php" name="frm_filters" method="get">' . "\n";
            echo '<input name="rep" value="' . $id_report . '" type="hidden" />' . "\n";
            if (isset($_REQUEST['export'])) {
                echo '<input name="export" value="' . $_REQUEST['export'] . '" type="hidden" />' . "\n";
            }
        }
        echo "<table border='0' class='tbl_usr_dtl' width='99%'>\n";
        while ($filter = lcm_fetch_array($result)) {
            if (!$is_runtime) {
                echo "<form action='upd_rep_field.php' name='frm_line_additem' method='get'>\n";
                echo "<input name='update' value='filter' type='hidden' />\n";
                echo "<input name='rep' value='{$id_report}' type='hidden' />\n";
                echo "<input name='id_filter' value='" . $filter['id_filter'] . "' type='hidden' />\n";
            }
            echo "<tr>\n";
            echo "<td>" . _Th($filter['description']) . "</td>\n";
            // Type of filter
            echo "<td>";
            $all_filters = array('number' => array('none', 'num_eq', 'num_neq', 'num_lt', 'num_le', 'num_gt', 'num_ge'), 'date' => array('none', 'date_eq', 'date_in', 'date_lt', 'date_le', 'date_gt', 'date_ge'), 'text' => array('none', 'text_eq', 'text_neq'));
            if ($all_filters[$filter['filter']]) {
                // At runtime, if a filter has been selected, do not allow select
                if ($filter['type'] && $is_runtime) {
                    echo _T('rep_filter_' . $filter['type']);
                } else {
                    echo "<select name='filter_type'>\n";
                    echo "<option value=''>...</option>\n";
                    foreach ($all_filters[$filter['filter']] as $f) {
                        $sel = $filter['type'] == $f ? ' selected="selected"' : '';
                        echo "<option value='" . $f . "'" . $sel . ">" . _T('rep_filter_' . $f) . "</option>\n";
                    }
                    echo "</select>\n";
                }
            } else {
                // XXX Should happen only if a filter was removed in a future version, e.g. rarely
                // or between development releases.
                echo "Unknown filter";
            }
            echo "</td>\n";
            // Value for filter
            echo "<td>";
            switch ($filter['type']) {
                case 'num_eq':
                case 'num_neq':
                    if ($filter['field_name'] == 'id_author') {
                        $name = $is_runtime ? "filter_val" . $filter['id_filter'] : 'filter_value';
                        // XXX make this a function
                        $q = "SELECT * FROM lcm_author WHERE status IN ('admin', 'normal', 'external')";
                        $result_author = lcm_query($q);
                        echo "<select name='{$name}'>\n";
                        echo "<option value=''>...</option>\n";
                        // TRAD
                        while ($author = lcm_fetch_array($result_author)) {
                            // Check for already submitted value
                            $sel = $filter['value'] == $author['id_author'] || $_REQUEST['filter_val' . $filter['id_filter']] == $author['id_author'] ? ' selected="selected"' : '';
                            echo "<option value='" . $author['id_author'] . "'" . $sel . ">" . $author['id_author'] . " : " . get_person_name($author) . "</option>\n";
                        }
                        echo "</select>\n";
                        break;
                    }
                case 'num_lt':
                case 'num_gt':
                    $name = $is_runtime ? "filter_val" . $filter['id_filter'] : 'filter_value';
                    echo '<input style="width: 99%;" type="text" name="' . $name . '" value="' . $filter['value'] . '" />';
                    break;
                case 'date_eq':
                case 'date_lt':
                case 'date_le':
                case 'date_gt':
                case 'date_ge':
                    $name = $is_runtime ? "filter_val" . $filter['id_filter'] : 'date';
                    echo get_date_inputs($name, $filter['value']);
                    // FIXME
                    break;
                case 'date_in':
                    // date_in has two values, stored ex: 2005-01-01 00:00:00;2006-02-02 00:00:00
                    $name = $is_runtime ? "filter_val" . $filter['id_filter'] : 'date';
                    $values = split(";", $filter['value']);
                    echo get_date_inputs($name . '_start', $values[0]);
                    echo "<br />\n";
                    echo get_date_inputs($name . '_end', $values[1]);
                    break;
                case 'text_eq':
                case 'text_neq':
                    $name = $is_runtime ? "filter_val" . $filter['id_filter'] : 'filter_value';
                    if ($filter['enum_type']) {
                        $enum = explode(":", $filter['enum_type']);
                        if ($enum[0] == 'keyword') {
                            if ($enum[1] == 'system_kwg') {
                                $all_kw = get_keywords_in_group_name($enum[2]);
                                echo '<select name="' . $name . '">' . "\n";
                                echo '<option value="">' . "..." . "</option>\n";
                                // TRAD
                                foreach ($all_kw as $kw) {
                                    $sel = $filter['value'] == $kw['name'] || $_REQUEST['filter_val' . $filter['id_filter']] == $kw['name'] ? ' selected="selected" ' : '';
                                    echo '<option value="' . $kw['name'] . '"' . $sel . '>' . _Tkw($enum[2], $kw['name']) . "</option>\n";
                                }
                                echo "</select>\n";
                            }
                        } elseif ($enum[0] == 'list') {
                            $items = split(",", $enum[1]);
                            echo '<select name="' . $name . '">' . "\n";
                            echo '<option value="">' . "..." . "</option>\n";
                            // TRAD
                            foreach ($items as $i) {
                                $tmp = $i;
                                if ($enum[2]) {
                                    $tmp = _T($enum[2] . $tmp);
                                }
                                $sel = $filter['value'] == $i || $_REQUEST['filter_val' . $filter['id_filter']] == $i ? ' selected="selected" ' : '';
                                echo '<option value="' . $i . '"' . $sel . '>' . $tmp . "</option>\n";
                            }
                            echo "</select>\n";
                        }
                    } else {
                        echo '<input style="width: 99%;" type="text" name="' . $name . '" value="' . $filter['value'] . '" />';
                    }
                    break;
                default:
                    echo "<!-- no type -->\n";
            }
            echo "</td>\n";
            if (!$is_runtime) {
                // Button to validate
                echo "<td>";
                echo "<button class='simple_form_btn' name='validate_filter_addfield'>" . _T('button_validate') . "</button>\n";
                echo "</td>\n";
                // Link for "Remove"
                echo "<td><a class='content_link' href='upd_rep_field.php?rep=" . $id_report . "&amp;" . "remove=filter" . "&amp;" . "id_filter=" . $filter['id_filter'] . "'>" . "X" . "</a></td>\n";
            }
            echo "</tr>\n";
            if (!$is_runtime) {
                echo "</form>\n";
            }
        }
        echo "</table>\n";
    }
    if ($is_runtime) {
        echo "<p><button class='simple_form_btn' name='validate_filter_addfield'>" . _T('button_validate') . "</button></p>\n";
        echo "</form>\n";
        return;
    }
    // List all available fields in selected tables for report
    $query = "SELECT *\n\t\tFROM lcm_fields\n\t\tWHERE ";
    $sources = array();
    if ($rep_info['line_src_name']) {
        array_push($sources, "'lcm_" . $rep_info['line_src_name'] . "'");
    }
    // Fetch all tables available as rep colums
    // (this is not like rep line, because the source is not always in
    // lcm_report, but this should be 'fixed')
    $q_tmp = "SELECT DISTINCT table_name \n\t\t\t\tFROM lcm_rep_col as rp, lcm_fields as f\n\t\t\t\tWHERE rp.id_field = f.id_field\n\t\t\t\t  AND rp.id_report = " . $id_report;
    $result_tmp = lcm_query($q_tmp);
    while ($row = lcm_fetch_array($result_tmp)) {
        array_push($sources, "'" . $row['table_name'] . "'");
    }
    // Fetch all keyword sources
    if ($rep_info['col_src_type'] == 'keyword' && $rep_info['col_src_name']) {
        $kwg = get_kwg_from_name($rep_info['col_src_name']);
        if ($kwg['type'] == 'system') {
            switch ($kwg['name']) {
            }
        } else {
            if ($kwg['type'] == 'client_org') {
                array_push($sources, "'lcm_client'");
                array_push($sources, "'lcm_org'");
            } else {
                array_push($sources, "'lcm_" . $kwg['type'] . "'");
            }
        }
    }
    // If lcm_case in there, also add lcm_stage
    $tmp = '';
    foreach ($sources as $s) {
        if ($s == "'lcm_case'") {
            $tmp = "lcm_stage";
        }
    }
    if ($tmp) {
        array_push($sources, "'lcm_stage'");
    }
    // List only filters if table were selected as sources (line/col)
    if (count($sources)) {
        $query .= " table_name IN ( " . implode(" , ", $sources) . " ) AND ";
        $query .= " filter != 'none'";
        $query .= " ORDER BY table_name ";
        echo "<!-- QUERY: {$query} -->\n";
        $result = lcm_query($query);
        if (lcm_num_rows($result)) {
            echo "<form action='upd_rep_field.php' name='frm_line_additem' method='get'>\n";
            echo "<input name='rep' value='" . $rep_info['id_report'] . "' type='hidden' />\n";
            echo "<input name='add' value='filter' type='hidden' />\n";
            echo "<p class='normal_text'>" . _Ti('rep_input_filter_add');
            echo "<select name='id_field'>\n";
            echo "<option value=''>...</option>\n";
            while ($row = lcm_fetch_array($result)) {
                echo "<option value='" . $row['id_field'] . "'>" . _Ti('rep_info_table_' . $row['table_name']) . _Th($row['description']) . "</option>\n";
            }
            echo "</select>\n";
            echo "<button class='simple_form_btn' name='validate_filter_addfield'>" . _T('button_validate') . "</button>\n";
            echo "</p>\n";
            echo "</form>\n";
        }
    } else {
        echo '<p class="normal_text">' . _T('rep_info_select_source_first') . "</p>\n";
    }
}
Example #3
0
 function printEdit()
 {
     // Get site preferences
     $client_name_middle = read_meta('client_name_middle');
     $client_citizen_number = read_meta('client_citizen_number');
     $client_civil_status = read_meta('client_civil_status');
     $client_income = read_meta('client_income');
     $meta_date_birth = read_meta('client_date_birth');
     echo '<table width="99%" border="0" align="center" cellpadding="5" cellspacing="0" class="tbl_usr_dtl">' . "\n";
     if ($this->getDataInt('id_client')) {
         echo "<tr><td>" . _T('client_input_id') . "</td>\n";
         echo "<td>" . $this->getDataInt('id_client') . '<input type="hidden" name="id_client" value="' . $this->getDataInt('id_client') . '" /></td></tr>' . "\n";
     }
     // Client name
     echo '<tr><td>' . f_err_star('name_first') . _T('person_input_name_first') . '</td>' . "\n";
     echo '<td><input name="name_first" value="' . clean_output($this->getDataString('name_first')) . '" class="search_form_txt" /></td></tr>' . "\n";
     // [ML] always show middle name, if any, no matter the configuration
     if ($this->getDataString('name_middle') || substr($client_name_middle, 0, 3) == 'yes') {
         echo '<tr><td>' . f_err_star('name_middle') . _T('person_input_name_middle') . '</td>' . "\n";
         echo '<td><input name="name_middle" value="' . clean_output($this->getDataString('name_middle')) . '" class="search_form_txt" /></td></tr>' . "\n";
     }
     echo '<tr><td>' . f_err_star('name_last') . _T('person_input_name_last') . '</td>' . "\n";
     echo '<td><input name="name_last" value="' . clean_output($this->getDataString('name_last')) . '" class="search_form_txt" /></td></tr>' . "\n";
     if (substr($meta_date_birth, 0, 3) == 'yes') {
         echo "<tr>\n";
         echo "<td>" . f_err_star('date_birth') . _Ti('person_input_date_birth') . "</td>\n";
         echo "<td>" . get_date_inputs('date_birth', $this->getDataString('date_birth'), true) . "</td>\n";
         echo "</tr>\n";
     }
     echo '<tr><td>' . f_err_star('gender') . _T('person_input_gender') . '</td>' . "\n";
     echo '<td><select name="gender" class="sel_frm">' . "\n";
     $opt_sel_male = $opt_sel_female = $opt_sel_unknown = '';
     if ($this->getDataString('gender') == 'male') {
         $opt_sel_male = 'selected="selected" ';
     } else {
         if ($this->getDataString('gender') == 'female') {
             $opt_sel_female = 'selected="selected" ';
         } else {
             $opt_sel_unknown = 'selected="selected" ';
         }
     }
     echo '<option ' . $opt_sel_unknown . 'value="unknown">' . _T('info_not_available') . "</option>\n";
     echo '<option ' . $opt_sel_male . 'value="male">' . _T('person_input_gender_male') . "</option>\n";
     echo '<option ' . $opt_sel_female . 'value="female">' . _T('person_input_gender_female') . "</option>\n";
     echo "</select>\n";
     echo "</td></tr>\n";
     if ($this->getDataString('id_client')) {
         echo "<tr>\n";
         echo '<td>' . _Ti('time_input_date_creation') . '</td>';
         echo '<td>' . format_date($this->getDataString('date_creation'), 'full') . '</td>';
         echo "</tr>\n";
     }
     if (substr($client_citizen_number, 0, 3) == 'yes') {
         echo "<tr>\n";
         echo '<td>' . f_err_star('citizen_number') . _T('person_input_citizen_number') . '</td>';
         echo '<td><input name="citizen_number" value="' . clean_output($this->getDataString('citizen_number')) . '" class="search_form_txt" /></td>';
         echo "</tr>\n";
     }
     if (substr($client_civil_status, 0, 3) == 'yes') {
         echo "<tr>\n";
         echo '<td>' . f_err_star('civil_status') . _Ti('person_input_civil_status') . '</td>';
         echo '<td>';
         echo '<select name="civil_status">';
         if (!$this->getDataInt('id_client')) {
             echo '<option value=""></option>';
         }
         $kwg = get_kwg_from_name('civilstatus');
         $all_kw = get_keywords_in_group_name('civilstatus');
         // A bit overkill, but if the user made the error of not entering
         // a valid civil_status, make sure that the field stays empty
         if (!$this->getDataString('civil_status') || !count($_SESSION['errors'])) {
             if ($this->getDataInt('id_client')) {
                 $this->data['civil_status'] = $all_kw['unknown']['name'];
             } else {
                 $this->data['civil_status'] = $kwg['suggest'];
             }
         }
         foreach ($all_kw as $kw) {
             $sel = $this->getDataString('civil_status') == $kw['name'] ? ' selected="selected"' : '';
             echo '<option value="' . $kw['name'] . '"' . $sel . '>' . _T($kw['title']) . '</option>';
         }
         echo '</select>';
         echo '</td>';
         echo "</tr>\n";
     }
     if (substr($client_income, 0, 3) == 'yes') {
         echo "<tr>\n";
         echo '<td>' . f_err_star('income') . _Ti('person_input_income') . '</td>';
         echo '<td>';
         echo '<select name="income">';
         if (!$this->getDataInt('id_client')) {
             echo '<option value=""></option>';
         }
         $kwg = get_kwg_from_name('income');
         $all_kw = get_keywords_in_group_name('income');
         if (!$this->getDataString('income') && !count($_SESSION['errors'])) {
             if ($this->getDataInt('id_client')) {
                 $this->data['income'] = $all_kw['unknown']['name'];
             } else {
                 $this->data['income'] = $kwg['suggest'];
             }
         }
         foreach ($all_kw as $kw) {
             $sel = $this->getDataString('income') == $kw['name'] ? ' selected="selected"' : '';
             echo '<option value="' . $kw['name'] . '"' . $sel . '>' . _T($kw['title']) . '</option>';
         }
         echo '</select>';
         echo '</td>';
         echo "</tr>\n";
     }
     //
     // Keywords, if any
     //
     show_edit_keywords_form('client', $this->getDataInt('id_client'));
     // Notes
     echo "<tr>\n";
     echo "<td>" . f_err_star('client_notes') . _Ti('client_input_notes') . "</td>\n";
     echo '<td><textarea name="client_notes" id="input_client_notes" class="frm_tarea" rows="3" cols="60">' . clean_output($this->getDataString('notes')) . "</textarea>\n" . "</td>\n";
     echo "</tr>\n";
     //
     // Contacts (e-mail, phones, etc.)
     //
     echo "<tr>\n";
     echo '<td colspan="2" align="center" valign="middle">';
     show_page_subtitle(_T('client_subtitle_contacts'));
     echo '</td>';
     echo "</tr>\n";
     show_edit_contacts_form('client', $this->getDataInt('id_client'));
     echo "</table>\n";
 }
Example #4
0
 function printEdit()
 {
     global $prefs;
     $admin = allowed($this->getDataInt('id_case'), 'a');
     // FIXME
     $edit = allowed($this->getDataInt('id_case'), 'e');
     // FIXME
     $write = allowed($this->getDataInt('id_case'), 'w');
     // FIXME (put in constructor)
     // FIXME: not sure whether this works as previously
     $dis = isDisabled(!($admin || $edit));
     echo '<table class="tbl_usr_dtl" width="99%">' . "\n";
     echo '<tr><td>';
     echo f_err_star('date_start') . _T('fu_input_date_start');
     echo "</td>\n";
     echo "<td>";
     $name = $admin || $edit ? 'start' : '';
     echo get_date_inputs($name, $this->data['date_start'], false);
     echo ' ' . _T('time_input_time_at') . ' ';
     echo get_time_inputs($name, $this->data['date_start']);
     echo "</td>\n";
     echo "</tr>\n";
     echo "<tr><td>";
     echo f_err_star('date_end') . ($prefs['time_intervals'] == 'absolute' ? _T('fu_input_date_end') : _T('fu_input_time_length'));
     echo "</td>\n";
     echo '<td>';
     if ($prefs['time_intervals'] == 'absolute') {
         // Buggy code, so isolated most important cases
         if ($this->data['id_followup'] == 0) {
             $name = 'end';
         } elseif ($edit) {
             $name = 'end';
         } else {
             // user can 'finish' entering data
             $name = $admin || $edit && $this->data['date_end'] == '0000-00-00 00:00:00' ? 'end' : '';
         }
         echo get_date_inputs($name, $this->data['date_end']);
         echo ' ';
         echo _T('time_input_time_at') . ' ';
         echo get_time_inputs($name, $this->data['date_end']);
     } else {
         $name = '';
         // Buggy code, so isolated most important cases
         if ($this->getDataInt('id_followup') == 0) {
             $name = 'delta';
         } elseif ($edit) {
             $name = 'delta';
         } else {
             // user can 'finish' entering data
             $name = $admin || $edit && $this->getDataString('date_end') == '0000-00-00 00:00:00' ? 'delta' : '';
         }
         if (empty($_SESSION['errors'])) {
             $interval = $this->getDataString('date_end') != '0000-00-00 00:00:00' ? strtotime($this->getDataString('date_end')) - strtotime($this->getDataString('date_start')) : 0;
             echo get_time_interval_inputs($name, $interval);
         } else {
             echo get_time_interval_inputs_from_array($name, $this->data);
         }
     }
     echo "</td>\n";
     echo "</tr>\n";
     // Show 'conclusion' options
     if ($this->show_conclusion) {
         $kws_conclusion = get_keywords_in_group_name('conclusion');
         $kws_result = get_keywords_in_group_name('_crimresults');
         echo "<tr>\n";
         echo "<td>" . _Ti('fu_input_conclusion') . "</td>\n";
         echo '<td>';
         // Result
         if (read_meta('case_result') == 'yes') {
             echo '<select ' . $dis . ' name="result" size="1" class="sel_frm">' . "\n";
             $default = '';
             if ($this->data['result']) {
                 $default = $this->data['result'];
             }
             foreach ($kws_result as $kw) {
                 $sel = isSelected($kw['name'] == $default);
                 echo '<option ' . $sel . ' value="' . $kw['name'] . '">' . _T(remove_number_prefix($kw['title'])) . "</option>\n";
             }
             echo "</select><br/>\n";
         }
         // Conclusion
         echo '<select ' . $dis . ' name="conclusion" size="1" class="sel_frm">' . "\n";
         $default = '';
         if ($this->data['conclusion']) {
             $default = $this->data['conclusion'];
         }
         foreach ($kws_conclusion as $kw) {
             $sel = isSelected($kw['name'] == $default);
             echo '<option ' . $sel . ' value="' . $kw['name'] . '">' . _T(remove_number_prefix($kw['title'])) . "</option>\n";
         }
         echo "</select>\n";
         echo "</td>\n";
         echo "</tr>\n";
         // If guilty, what sentence?
         $kws_sentence = get_keywords_in_group_name('sentence');
         echo "<tr>\n";
         echo "<td>" . _Ti('fu_input_sentence') . "</td>\n";
         echo '<td>';
         echo '<select ' . $dis . ' name="sentence" size="1" class="sel_frm">' . "\n";
         $default = '';
         if ($this->data['sentence']) {
             $default = $this->data['sentence'];
         }
         echo "<!-- " . $default . " -->\n";
         foreach ($kws_sentence as $kw) {
             $sel = $kw['name'] == $default ? ' selected="selected"' : '';
             echo '<option ' . $sel . ' value="' . $kw['name'] . '">' . _T(remove_number_prefix($kw['title']), array('currency' => read_meta('currency'))) . "</option>\n";
         }
         echo "</select>\n";
         // If sentence, for how much?
         echo '<input type="text" name="sentence_val" size="10" value="' . $this->data['sentence_val'] . '" />';
         echo "</td>\n";
         echo "</tr>\n";
     }
     if (_request('submit') == 'set_status' || is_status_change($this->getDataString('type'))) {
         // Change status
         echo "<tr>\n";
         echo "<td>" . _T('case_input_status') . "</td>\n";
         echo "<td>";
         echo '<input type="hidden" name="type" value="' . $this->getDataString('type') . '" />' . "\n";
         echo _T('kw_followups_' . $this->data['type'] . '_title');
         echo "</td>\n";
         echo "</tr>\n";
     } elseif (_request('submit') == 'set_stage' || $this->getDataString('type') == 'stage_change') {
         // Change stage
         echo "<tr>\n";
         echo "<td>" . _T('fu_input_next_stage') . "</td>\n";
         echo "<td>";
         echo '<input type="hidden" name="type" value="' . $this->getDataString('type') . '" />' . "\n";
         // This is to compensate an old bug, when 'case stage' was not stored in fu.description
         // and therefore editing a follow-up would not give correct information.
         // Bug was in CVS of 0.4.3 between 19-20 April 2005. Should not affect many people.
         if ($s = $this->getDataString('new_stage')) {
             echo '<input type="hidden" name="new_stage" value="' . $s . '" />' . "\n";
             echo _Tkw('stage', $s);
         } else {
             echo "New stage information not available";
         }
         echo "</td>\n";
         echo "</tr>\n";
         if ($s = $this->getDataString('new_stage')) {
             // Update stage keywords (if any)
             $stage = get_kw_from_name('stage', $s);
             $id_stage = $stage['id_keyword'];
             show_edit_keywords_form('stage', $this->data['id_case'], $id_stage);
         }
     } elseif ($this->getDataString('type') == 'assignment' || $this->getDataString('type') == 'unassignment') {
         // Do not allow assignment/un-assignment follow-ups to be changed
         echo "<tr>\n";
         echo "<td>" . _T('fu_input_next_stage') . "</td>\n";
         echo "<td>";
         echo '<input type="hidden" name="type" value="' . $this->getDataString('type') . '" />' . "\n";
         echo _Tkw('followups', $this->getDataString('type'));
         echo "</td>\n";
         echo "</tr>\n";
     } else {
         // The usual follow-up
         echo "<tr>\n";
         echo "<td>" . _T('fu_input_type') . "</td>\n";
         echo "<td>";
         echo '<select ' . $dis . ' name="type" size="1" class="sel_frm">' . "\n";
         $default_fu = get_suggest_in_group_name('followups');
         $futype_kws = get_keywords_in_group_name('followups');
         $kw_found = false;
         foreach ($futype_kws as $kw) {
             $sel = isSelected($kw['name'] == $default_fu);
             if ($sel) {
                 $kw_found = true;
             }
             echo '<option value="' . $kw['name'] . '"' . $sel . '>' . _T(remove_number_prefix($kw['title'])) . "</option>\n";
         }
         // Exotic case where the FU keyword was hidden by the administrator,
         // but an old follow-up using that keyword is being edited.
         if (!$kw_found) {
             echo '<option selected="selected" value="' . $default_fu . '">' . _Tkw('followups', $default_fu) . "</option>\n";
         }
         echo "</select>\n";
         echo "</td>\n";
         echo "</tr>\n";
     }
     // Keywords (if any)
     show_edit_keywords_form('followup', $this->getDataInt('id_followup'));
     // Description
     echo "<tr>\n";
     echo '<td valign="top">' . f_err_star('description') . _T('fu_input_description') . "</td>\n";
     echo '<td>';
     if ($this->getDataString('type') == 'assignment' || $this->getDataString('type') == 'unassignment') {
         // Do not allow edit of assignment
         echo '<input type="hidden" name="description" value="' . $this->getDataString('description') . '" />' . "\n";
         echo get_fu_description($this->data);
     } else {
         echo '<textarea ' . $dis . ' name="description" rows="15" cols="60" class="frm_tarea">';
         echo clean_output($this->getDataString('description'));
         echo "</textarea>";
     }
     echo "</td></tr>\n";
     // Sum billed field
     if ($this->show_sum_billed == "yes") {
         echo '<tr>';
         echo '<td>' . _T('fu_input_sum_billed') . "</td>\n";
         echo '<td>';
         echo '<input ' . $dis . ' name="sumbilled" ' . 'value="' . clean_output($this->getDataString('sumbilled')) . '" ' . 'class="search_form_txt" size="10" />';
         // [ML] If we do this we may as well make a function
         // out of it, but not sure where to place it :-)
         // This code is also in config_site.php
         $currency = read_meta('currency');
         if (empty($currency)) {
             $current_lang = $GLOBALS['lang'];
             $GLOBALS['lang'] = read_meta('default_language');
             $currency = _T('currency_default_format');
             $GLOBALS['lang'] = $current_lang;
         }
         echo htmlspecialchars($currency);
         echo "</td></tr>\n";
     }
     echo "</table>\n\n";
     // XXX FIXME: Should probably be in some function "is_system_fu"
     // or even "is_deletable"
     if ($this->getDataInt('id_followup') && allowed($this->data['id_case'], 'a') && !(is_status_change($this->data['type']) || $this->data['type'] == 'assignment' || $this->data['type'] == 'unassignment')) {
         $checked = $this->getDataString('hidden') == 'Y' ? ' checked="checked" ' : '';
         echo '<p class="normal_text">';
         echo '<input type="checkbox"' . $checked . ' name="delete" id="box_delete" />';
         echo '<label for="box_delete">' . _T('fu_info_delete') . '</label>';
         echo "</p>\n";
     }
     // Add followup appointment
     if (!_request('followup')) {
         echo "<!-- Add appointment? -->\n";
         echo '<p class="normal_text">';
         echo '<input type="checkbox" name="add_appointment" id="box_new_app" onclick="display_block(\'new_app\', \'flip\')" />';
         echo '<label for="box_new_app">' . _T('fu_info_add_future_activity') . '</label>';
         echo "</p>\n";
         echo '<div id="new_app" style="display: none;">';
         echo '<table class="tbl_usr_dtl" width="99%">' . "\n";
         echo "<!-- Start time -->\n\t\t<tr><td>";
         echo _T('time_input_date_start');
         echo "</td><td>";
         echo get_date_inputs('app_start', $this->data['app_start_time'], false);
         echo ' ' . _T('time_input_time_at') . ' ';
         echo get_time_inputs('app_start', $this->data['app_start_time']);
         echo f_err_star('app_start_time');
         echo "</td></tr>\n";
         echo "<!-- End time -->\n\t\t<tr><td>";
         echo $prefs['time_intervals'] == 'absolute' ? _T('time_input_date_end') : _T('app_input_time_length');
         echo "</td><td>";
         if ($prefs['time_intervals'] == 'absolute') {
             echo get_date_inputs('app_end', $this->data['app_end_time']);
             echo ' ' . _T('time_input_time_at') . ' ';
             echo get_time_inputs('app_end', $this->data['app_end_time']);
             echo f_err_star('app_end_time');
         } else {
             $interval = $this->data['app_end_time'] != '0000-00-00 00:00:00' ? strtotime($this->data['app_end_time']) - strtotime($this->data['app_start_time']) : 0;
             //	echo _T('calendar_info_time') . ' ';
             echo get_time_interval_inputs('app_delta', $interval);
             echo f_err_star('app_end_time');
         }
         echo "</td></tr>\n";
         /* [ML] Removing, not useful for now
         			   echo "<!-- Reminder -->\n\t\t<tr><td>";
         			   echo (($prefs['time_intervals'] == 'absolute') ? _T('app_input_reminder_time') : _T('app_input_reminder_offset'));
         			   echo "</td><td>";
         			   if ($prefs['time_intervals'] == 'absolute') {
         			   echo get_date_inputs('app_reminder', $this->data['app_reminder']);
         			   echo ' ' . _T('time_input_time_at') . ' ';
         			   echo get_time_inputs('app_reminder', $this->data['app_reminder']);
         			   echo f_err_star('app_reminder');
         			   } else {
         			   $interval = ( ($this->data['app_end_time']!='0000-00-00 00:00:00') ?
         			   strtotime($this->data['app_start_time']) - strtotime($this->data['app_reminder']) : 0);
         			//	echo _T('calendar_info_time') . ' ';
         			echo get_time_interval_inputs('app_rem_offset', $interval);
         			echo " " . _T('time_info_before_start');
         			echo f_err_star('app_reminder');
         			}
         			echo "</td></tr>\n";
         			 */
         // TODO: [ML] a bit of testing to see if this survives an error on new case
         // I suspect it doesn't..
         echo "<!-- Appointment title -->\n\t\t<tr><td>";
         echo f_err_star('app_title') . _T('app_input_title');
         echo "</td><td>";
         echo '<input type="text" ' . $dis . ' name="app_title" size="50" value="';
         echo clean_output($this->getDataString('app_title')) . '" class="search_form_txt" />';
         echo "</td></tr>\n";
         echo "<!-- Appointment type -->\n\t\t<tr><td>";
         echo _T('app_input_type');
         echo "</td><td>";
         echo '<select ' . $dis . ' name="app_type" size="1" class="sel_frm">';
         global $system_kwg;
         if ($_SESSION['fu_app_data']['type']) {
             $default_app = $_SESSION['fu_app_data']['type'];
         } else {
             $app_kwg = get_kwg_from_name('appointments');
             $default_app = $app_kwg['suggest'];
         }
         $opts = array();
         foreach ($system_kwg['appointments']['keywords'] as $kw) {
             $opts[$kw['name']] = _T(remove_number_prefix($kw['title']));
         }
         asort($opts);
         foreach ($opts as $k => $opt) {
             $sel = isSelected($k == $default_app);
             echo "<option value='{$k}'{$sel}>{$opt}</option>\n";
         }
         echo '</select>';
         echo "</td></tr>\n";
         echo "<!-- Appointment description -->\n";
         echo "<tr><td valign=\"top\">";
         echo _T('app_input_description');
         echo "</td><td>";
         echo '<textarea ' . $dis . ' name="app_description" rows="5" cols="60" class="frm_tarea">';
         echo clean_output($this->getDataString('app_description'));
         echo '</textarea>';
         echo "</td></tr>\n";
         echo "</table>\n";
         echo "</div>\n";
     }
 }
Example #5
0
 function setupReportLines()
 {
     $this->addComment("setupReportLines() called.");
     $q = "SELECT *\n\t\t\t\tFROM lcm_rep_line as l, lcm_fields as f\n\t\t\t\tWHERE id_report = " . $this->getId() . "\n\t\t\t\tAND l.id_field = f.id_field\n\t\t\t\tORDER BY col_order, id_line ASC";
     $result = lcm_query($q);
     while ($row = lcm_fetch_array($result)) {
         $my_line_table = $row['table_name'];
         $this->addLine(prefix_field($row['table_name'], $row['field_name']));
         $this->addHeader(_Th($row['description']), $row['filter'], $row['enum_type'], '', $row['field_name']);
         if ($row['field_name'] == 'count(*)') {
             $this->setOption('do_grouping', 'yes');
         }
         // $do_grouping = true;
     }
     if (count($this->getLines())) {
         return;
     }
     //
     // No fields were specified: show them all (avoids errors)
     //
     if ($this->rep_info['line_src_type'] == 'table') {
         $q = "SELECT * \n\t\t\t\t\tFROM lcm_fields \n\t\t\t\t\tWHERE table_name = 'lcm_" . $this->rep_info['line_src_name'] . "'\n\t\t\t\t\t  AND field_name != 'count(*)'";
         $result = lcm_query($q);
         while ($row = lcm_fetch_array($result)) {
             $this->addLine(prefix_field($row['table_name'], $row['field_name']));
             $this->addHeader(_Th($row['description']), $row['filter'], $row['enum_type'], '', $row['field_name']);
         }
     } elseif ($this->rep_info['line_src_type'] == 'keyword') {
         $kwg = get_kwg_from_name($this->rep_info['line_src_name']);
         $this->addLine("k.title as 'TRAD'");
         $this->addHeader(_Th(remove_number_prefix($kwg['title'])), $kwg['filter'], $kwg['enum_type'], '', 'k.id_keyword');
         // XXX not sure about id_keyword
     }
 }
Example #6
0
function show_new_contact($num_new, $type_person, $ctype = "__add__", $exceptions = array())
{
    $all_contact_types = get_kwg_all('contact');
    // There may be a config error, or admin removed all contact types
    if (!count($all_contact_types)) {
        return;
    }
    echo "<tr>\n";
    // Contact type (either specific or 'Add contact')
    echo '<td align="left" valign="top">' . f_err_star('new_contact_' . $num_new);
    if ($ctype == "__add__") {
        echo _Ti('generic_input_contact_other');
    } else {
        $c = get_kwg_from_name($ctype);
        echo f_err_star('contact_' . $c['name']);
        echo _Ti(remove_number_prefix($c['title']));
        echo $c['policy'] != 'optional' ? '<br/>(' . _T('keywords_input_policy_' . $c['policy']) . ')' : '';
    }
    echo '</td>';
    echo '<td align="left" valign="top">';
    // Avoids that the values in these fields get lost when there is an error after submitting the form
    $value = '';
    $type = '';
    if (isset($_SESSION['form_data']['new_contact_type_name'][$num_new])) {
        $type = $_SESSION['form_data']['new_contact_type_name'][$num_new];
    }
    if (isset($_SESSION['form_data']['new_contact_value'][$num_new])) {
        $value = $_SESSION['form_data']['new_contact_value'][$num_new];
    }
    if ($ctype == "__add__") {
        echo "<div>\n";
        echo '<select name="new_contact_type_name[]" id="new_contact_type_' . $num_new . '" class="sel_frm">' . "\n";
        echo "<option value=''>" . " ... " . "</option>\n";
        foreach ($all_contact_types as $contact) {
            if (!($contact['quantity'] == 'one' && isset($exceptions[$contact['name']]) && $type != $contact['name'])) {
                $sel = isSelected($type == $contact['name']);
                echo "<option value='" . $contact['name'] . "' {$sel}>" . _T($contact['title']) . "</option>\n";
            }
        }
        echo "</select>\n";
        echo "</div>\n";
        echo "<div>\n";
        echo '<input type="text" size="40" name="new_contact_value[]" id="new_contact_value_' . $num_new . '" ';
        echo ' value="' . $value . '" ';
        echo 'class="search_form_txt" />' . "\n";
        echo "</div>\n";
    } else {
        echo '<input name="new_contact_type_name[]" id="new_contact_type_name_' . $num_new . '" ' . 'type="hidden" value="' . $ctype . '" />' . "\n";
        echo '<input name="new_contact_value[]" id="new_contact_value_' . $num_new . '" type="text" ' . 'class="search_form_txt" size="35" value="' . $value . '"/>&nbsp;';
    }
    echo "</td>\n";
    echo "</tr>\n";
}
Example #7
0
function send_registration_by_email()
{
    global $lcm_lang_left;
    $_SESSION['form_data'] = array();
    $_SESSION['errors'] = array();
    $kwg_email = get_kwg_from_name('+email_main');
    $form_items = array('name_first' => 'person_input_name_first', 'name_last' => 'person_input_name_last', 'email' => 'input_email', 'username' => 'authoredit_input_username');
    foreach ($form_items as $field => $trad) {
        $_SESSION['form_data'][$field] = _request($field);
        if (!_session($field)) {
            $_SESSION['errors'][$field] = _Ti($trad) . _T('warning_field_mandatory');
        }
    }
    if (count($_SESSION['errors'])) {
        lcm_header("Location: lcm_pass.php?register=yes");
        exit;
    }
    install_html_start(_T('pass_title_register'), 'login');
    // There is a risk that an author changes his e-mail after his account
    // is created, to the e-mail of another person, and therefore block the
    // other person from registering. But then.. this would allow the other
    // person to hijack the account, so it would be a stupid DoS.
    $query = "SELECT id_of_person, status FROM lcm_contact as c, lcm_author as a\n\t\tWHERE c.id_of_person = a.id_author\n\t\tAND value = '" . _session('email') . "'\n\t\tAND type_person = 'author'\n\t\tAND type_contact = " . $kwg_email['id_group'];
    $result = lcm_query($query);
    // Test if the user already exists
    if ($row = lcm_fetch_array($result)) {
        $id_author = $row['id_of_person'];
        $status = $row['status'];
        // TODO: if status = 'pending for validation by admin', show message
        if ($status == 'trash') {
            echo "<br />\n";
            echo "<div class='box_error'>" . _T('pass_registration_denied') . "</div>\n";
        } else {
            echo "<br />\n";
            echo "<div class=\"box_error\" align=\"{$lcm_lang_left}\">" . _T('pass_warning_already_registered') . "</div>\n";
            return;
        }
    }
    //
    // Send identifiers by e-mail
    //
    include_lcm('inc_access');
    include_lcm('inc_mail');
    $username = get_unique_username(_session('username'));
    $pass = create_random_password(8, $username);
    $mdpass = md5($pass);
    $open_subscription = read_meta("site_open_subscription");
    if (!($open_subscription == 'yes' || $open_subscription == 'moderated')) {
        lcm_panic("Subscriptions not permitted.");
    }
    $status = 'waiting';
    if ($open_subscription == 'yes') {
        $status = 'normal';
    }
    lcm_query("INSERT INTO lcm_author (name_first, name_last, username, password, status, date_creation, date_update) " . "VALUES ('" . _session('name_first') . "', '" . _session('name_last') . "', '{$username}', '{$mdpass}', 'normal', NOW(), NOW())");
    $id_author = lcm_insert_id('lcm_author', 'id_author');
    // Add e-mail to lcm_contact
    lcm_query("INSERT INTO lcm_contact (type_person, type_contact, id_of_person, value)\n\t\t\tVALUES ('author', " . $kwg_email['id_group'] . ", {$id_author}, '" . _session('email') . "')");
    // Prepare the e-mail to send to the user
    $site_name = _T(read_meta('site_name'));
    $site_address = read_meta('site_address');
    $message = _T('info_greetings') . ",\n\n";
    $message .= _T('pass_info_here_info', array('site_name' => $site_name, 'site_address' => $site_address)) . "\n\n";
    $message .= "- " . _Ti('login_login') . " {$username}\n";
    $message .= "- " . _Ti('login_password') . " {$pass}\n\n";
    if ($open_subscription == 'moderated') {
        $message .= _T('pass_info_moderated') . "\n\n";
    }
    $message .= _T('pass_info_automated_msg') . "\n\n";
    if (send_email(_session('email'), "[{$site_name}] " . _T('pass_title_personal_identifier'), $message)) {
        echo "<p>" . _T('pass_info_identifier_mail') . "</p>\n";
    } else {
        $email_admin = read_meta('email_sysadmin');
        echo "<div class=\"box_error\"><p>" . _T('pass_warning_mail_failure', array('email_admin' => $email_admin)) . "</p></div>\n";
    }
    // If moderated, send copy to site admin
    if ($open_subscription == 'moderated') {
        $email_admin = read_meta('email_sysadmin');
        send_email($email_admin, "[{$site_name}] " . _T('pass_title_personal_identifier'), $message);
    }
}
Example #8
0
function get_parent_kwg_name($name)
{
    $ret = "";
    $kwg = get_kwg_from_name($name);
    if ($kwg['id_parent']) {
        lcm_log("get_parent_kwg_name: has parent: " . $kwg['id_parent']);
        $parent_kwg = get_kwg_from_id($kwg['id_parent']);
        if ($parent_kwg['id_parent']) {
            lcm_log("get_parent_kwg_name: PARENT has parent: " . $parent_kwg['id_parent']);
            $ret = get_parent_kwg_name($parent_kwg['name']);
        }
        $ret .= _T(remove_number_prefix($parent_kwg['title'])) . ' / ';
    }
    return $ret;
}
Example #9
0
                     echo '<div id="' . $obj_id_ajax . '"></div>' . "\n";
                 }
             }
         }
     }
     echo "</div>\n";
 } elseif ($action == 'get_kws_in') {
     // Searching keywords to add to a case (experimental)
     include_lcm('inc_keywords');
     include_lcm('inc_access');
     echo '<div id="' . _request('div') . '">';
     $id_obj = _request('id_obj', 0);
     $type_obj = _request('type_obj', '__ASSERT__');
     $group_name = _request('group_name');
     if ($group_name) {
         $kwg = get_kwg_from_name($group_name);
         $id_group = $kwg['id_group'];
         $kw_for_kwg = get_keywords_in_group_id($id_group);
         if (count($kw_for_kwg)) {
             $obj_id_ajax = 'kw_' . create_random_password(15, time());
             echo '<input type="hidden" name="new_kwg_' . $type_obj . '_id[]" value="' . $id_group . '" />' . "\n";
             echo '<select id="new_keyword_' . $type_obj . $cpt_kw . '" ' . 'name="new_keyword_' . $type_obj . '_value[]" ' . "onchange=\"getKeywordInfo('get_kwg_in','{$group_name}','{$type_obj}',{$id_obj},0, '{$obj_id_ajax}')\"" . '>';
             echo '<option value="">' . '' . "</option>\n";
             $show_kw_value = false;
             foreach ($kw_for_kwg as $kw) {
                 if ($kw['hasvalue'] == 'Y') {
                     $show_kw_value = true;
                 }
                 // For default value, use the form_data (if present), else use suggested keyword
                 if (isset($_SESSION['form_data']['new_keyword_' . $type_obj . '_value'][$cpt_kw]) && $_SESSION['form_data']['new_keyword_' . $type_obj . '_value'][$cpt_kw] == $kw['id_keyword']) {
                     $sel = ' selected="selected" ';
Example #10
0
function show_report_field_edit($type, $rep_info)
{
    $src_type = $rep_info[$type . '_src_type'];
    $src_name = $rep_info[$type . '_src_name'];
    if ($src_type == 'table' && $src_name && !preg_match('/^lcm_/', $src_name)) {
        $src_name = 'lcm_' . $src_name;
    }
    // Extract source type, if any
    if ($src_type && $src_name) {
        if ($src_type == 'keyword') {
            $kwg = get_kwg_from_name($src_name);
            echo '<p class="normal_text">' . _Ti('rep_info_source_' . $src_type) . " (" . _T('rep_info_table_lcm_' . $kwg['type']) . ") " . _T(remove_number_prefix($kwg['title']));
        } else {
            echo "<p class='normal_text'>" . _Ti('rep_info_source_' . $src_type) . _T('rep_info_table_' . $src_name);
        }
        // Show list of fields for line/col, if any
        $my_id = $type == 'col' ? 'id_column' : 'id_line';
        $my_fields = array();
        $query = "SELECT " . $my_id . ", f.id_field, f.description \n\t\t\tFROM lcm_rep_" . $type . " as rl, lcm_fields as f\n\t\t\tWHERE id_report = " . $rep_info['id_report'] . "\n\t\t\tAND rl.id_field = f.id_field\n\t\t\tORDER BY col_order, " . $my_id . " ASC";
        $result_fields = lcm_query($query);
        if (lcm_num_rows($result_fields)) {
            echo "</p>\n";
            echo "<table border='0' class='tbl_usr_dtl' width='99%'>\n";
            while ($field = lcm_fetch_array($result_fields)) {
                echo "<tr>\n";
                echo "<td>" . _Th($field['description']) . "</td>\n";
                echo "<td><a href='upd_rep_field.php?rep=" . $rep_info['id_report'] . "&amp;" . "remove=" . $type . "&amp;" . $my_id . "=" . $field[$my_id] . "' class='content_link'>" . "X" . "</a></td>\n";
                // ACCESSIBILITY
                echo "</tr>\n";
                array_push($my_fields, $field['id_field']);
            }
            echo "</table>\n";
        } else {
            if (!$rep_info['filecustom']) {
                // Allow to change the source table
                echo ' <a href="upd_rep_field.php?rep=' . $rep_info['id_report'] . '&amp;unselect_' . $type . '=1" class="content_link">' . "X" . '</a>';
                // TRAD ACCESSIBILITY
                echo "</p>\n";
            }
        }
        // Add field (if line_src_type == table)
        // TODO: add 'not in (...existing fields..)
        $query = "SELECT *\n\t\t\tFROM lcm_fields\n\t\t\tWHERE table_name = '" . $src_name . "'";
        $result = lcm_query($query);
        if (lcm_num_rows($result)) {
            echo "\n<br />\n\n";
            echo "<form action='upd_rep_field.php' name='frm_" . $type . "_additem' method='get'>\n";
            echo "<input name='rep' value='" . $rep_info['id_report'] . "' type='hidden' />\n";
            echo "<input name='add' value='" . $type . "' type='hidden' />\n";
            echo "<table border='0' class='tbl_usr_dtl' width='99%'>\n";
            echo "<tr>\n";
            echo "<th class='heading'>" . _Ti('rep_input_item_add') . "</th>\n";
            echo "<td>\n";
            echo "<select name='id_field' class='sel_frm'>";
            echo "<option value=''>...</option>\n";
            while ($row = lcm_fetch_array($result)) {
                echo "<option value='" . $row['id_field'] . "'>" . _Th($row['description']) . "</option>\n";
            }
            echo "</select>\n";
            echo "<button class='simple_form_btn' name='validate_" . $type . "_additem'>" . _T('button_validate') . "</button>\n";
            echo "</td>\n";
            echo "</tr>\n";
            echo "</table>\n";
            echo "</form>\n";
        }
    } else {
        if (!$src_type || $src_type != 'keyword') {
            echo "<form action='upd_rep_field.php' name='frm_" . $type . "_source' method='post'>\n";
            echo "<input name='rep' value='" . $rep_info['id_report'] . "' type='hidden' />\n";
            echo '<p class="normal_text">' . f_err_star('rep_' . $type) . _Ti('rep_info_source_table');
            echo "<input name='select_" . $type . "_type' value='table' type='hidden' />\n";
            echo "<select name='select_" . $type . "_name' class='sel_frm'>\n\t\t\t\t<option value='author'>" . _T('rep_info_table_lcm_author') . "</option>\n\t\t\t\t<option value='case'>" . _T('rep_info_table_lcm_case') . "</option>\n\t\t\t\t<option value='stage'>" . _T('rep_info_table_lcm_stage') . "</option>\n\t\t\t\t<option value='client'>" . _T('rep_info_table_lcm_client') . "</option>\n\t\t\t\t<option value='followup'>" . _T('rep_info_table_lcm_followup') . "</option>\n\t\t\t\t</select>\n";
            echo "<button class='simple_form_btn' name='validate_" . $type . "_source'>" . _T('button_validate') . "</button>\n";
            echo "</p>\n";
            echo "</form>\n";
        }
        if (!$src_type) {
            echo '<p class="normal_text">' . _T('info_or') . "</p>\n";
        }
        if (!$src_type || $src_type != 'table') {
            echo "<form action='upd_rep_field.php' name='frm_" . $type . "_source' method='post'>\n";
            echo "<input name='rep' value='" . $rep_info['id_report'] . "' type='hidden' />\n";
            echo "<p class='normal_text'>" . _Ti('rep_info_source_keyword');
            echo "<input name='select_" . $type . "_type' value='keyword' type='hidden' />\n";
            // Restrict list of keywords if custom report
            if ($rep_info['filecustom']) {
                include_custom_report($rep_info['filecustom']);
                $obj = new CustomReportSpecs();
                $info = $type == 'line' ? $obj->getReportLine() : $obj->getReportCol();
                if (substr($info['name'], 0, 4) == 'FOR:') {
                    $choices = split(':', $info['name']);
                    $all_kwgs = get_kwg_all($choices[1], true);
                } else {
                    lcm_panic("Error in custom report specifications.");
                }
            } else {
                $all_kwgs = get_kwg_all('', true);
            }
            echo "<select name='select_" . $type . "_name' class='sel_frm'>\n";
            echo "<option value=''>...</option>\n";
            foreach ($all_kwgs as $kwg) {
                echo "<option value='" . $kwg['name'] . "'>" . _T('rep_info_table_lcm_' . $kwg['type']) . " - " . _T(remove_number_prefix($kwg['title'])) . "</option>\n";
            }
            echo "</select>\n";
            echo "<button class='simple_form_btn' name='validate_" . $type . "_source_kw'>" . _T('button_validate') . "</button>\n";
            echo "</p>\n";
            echo "</form>\n";
        }
    }
}
Example #11
0
function join_tables($table1, $table2 = '', $id1 = 0, $id2 = 0, $report = null, $query = '')
{
    $from = "";
    // select .. FROM [here] (for dependancies between tables)
    $from_glue = "";
    // for joining the FROM
    $where = "";
    // the usual stuff (LEFT JOIN ON .., WHERE ..)
    if ($report) {
        $report->addComment("join_tables: " . $table1 . " - " . $table2 . " id1 = " . $id1 . " id2 = " . $id2);
    }
    // lcm_debug("join_tables: " . $table1 . " - " . $table2 . " id1 = " . $id1 . " id2 = " . $id2);
    // lcm_debug(lcm_getbacktrace(false));
    $table_keys = array("lcm_case" => "id_case", "lcm_author" => "id_author", "lcm_followup" => "id_followup", "lcm_client" => "id_client", "lcm_org" => "id_org", "lcm_keyword_case" => "id_keyword");
    if ($table1 == $table2) {
        panic_not_implemented($table1, $table2);
    }
    switch ($table1) {
        case 'lcm_author':
            switch ($table2) {
                case 'lcm_case':
                    // $from = " LEFT JOIN lcm_case_author as ca ON (a.id_author = ca.id_author AND c.id_case = ca.id_case) ";
                    $from = " , lcm_case_author as ca ";
                    $from_glue .= " a.id_author = ca.id_author AND c.id_case = ca.id_case ";
                    $where .= " a.id_author = ca.id_author ";
                    break;
                case 'lcm_followup':
                    $where .= " a.id_author = fu.id_author ";
                    break;
                case 'lcm_client':
                    panic_not_implemented($table1, $table2);
                    break;
                case 'lcm_org':
                    panic_not_implemented($table1, $table2);
                    break;
                case 'lcm_stage':
                    /* TESTCASE: Count number of cases concluded by author
                     *  - row = lcm_author (name, family)
                     *  - col = lcm_stage (count)
                     *  - filter = lcm_stage.date_conclusion date_in (...)
                     */
                    $from = " , lcm_case_author as ca ";
                    $from_glue .= " a.id_author = ca.id_author AND s.id_case = ca.id_case ";
                    $where .= " a.id_author = ca.id_author ";
                    break;
                case '':
                    break;
                default:
                    panic_not_implemented($table1, $table2);
                    break;
            }
            break;
        case 'lcm_case':
            switch ($table2) {
                case '':
                    break;
                case 'lcm_followup':
                    $where .= " c.id_case = fu.id_case ";
                    break;
                case 'lcm_author':
                    // [ML] This may not generate anything interested. Was implemented just for fun.
                    $from = " , lcm_case_author as ca ";
                    $from_glue .= " c.id_case = ca.id_case AND ca.id_author = a.id_author ";
                    $where .= " ca.id_author = a.id_author ";
                    break;
                default:
                    panic_not_implemented($table1, $table2);
            }
            break;
        case 'lcm_followup':
            switch ($table2) {
                case '':
                    break;
                case 'lcm_author':
                    $where .= " fu.id_author = a.id_author ";
                    break;
                default:
                    panic_not_implemented($table1, $table2);
            }
            break;
        case 'lcm_client':
            switch ($table2) {
                case '':
                    break;
                case 'lcm_case':
                    $from = " , lcm_case_client_org as cco ";
                    $from_glue .= " cl.id_client = cco.id_client AND c.id_case = cco.id_case ";
                    $where .= " cl.id_client = cco.id_client ";
                    break;
                default:
                    panic_not_implemented($table1, $table2);
            }
            break;
        case 'lcm_org':
            switch ($table2) {
                default:
                    panic_not_implemented($table1, $table2);
            }
            break;
        default:
            // Try to process as a keyword group
            $kwg = get_kwg_from_name($table1);
            switch ($kwg['type']) {
                case 'case':
                    $from = " , lcm_keyword_case as kc ";
                    $from_glue .= " kc.id_case = ca.id_case ";
                    $table1 = 'lcm_keyword_case';
                    // $where .= " cl.id_client = cco.id_client ";
                    break;
            }
    }
    if ($id1) {
        if ($id2) {
            // [ML] TEST THIS
            $where .= " AND " . prefix_field($table1, $table_keys[$table1]) . " = {$id1} ";
            if (isset($report)) {
                $report->addComment(" AND " . prefix_field($table1, $table_keys[$table1]) . " = {$id1} ");
            }
        } elseif ($field = $report->getLineKeyField()) {
            // If joining some special query, check if $field in $query
            // [ML] this really needs more testing
            if ($query && preg_match('/^(.+)\\./', $field, $regs)) {
                $table = $regs[1];
                if (preg_match('/as ' . $table . '/', $query)) {
                    $where .= " AND {$field} = {$id1} ";
                } elseif ($table == 'a' && preg_match('/as ca/', $query)) {
                    $where .= " AND ca.id_author = {$id1} ";
                } elseif ($table == 'a' && preg_match('/as fu/', $query)) {
                    $where .= " AND fu.id_author = {$id1} ";
                } else {
                    $where .= " AND " . prefix_field($table1, $table_keys[$table1]) . " = {$id1} ";
                }
            } else {
                $where .= " AND {$field} = {$id1} ";
            }
            if (isset($report)) {
                $report->addComment($where);
            }
        }
    }
    if ($id2) {
        // [ML] TEST THIS
        $where .= " AND " . prefix_field($table2, $table_keys[$table2]) . " = {$id2} ";
    }
    return array($from, $from_glue, $where);
}