Exemple #1
0
function show_edit_keywords_form($type_obj, $id_obj, $id_obj_sec = 0)
{
    include_lcm('inc_access');
    if (!$GLOBALS['legal_obj'][$type_obj]) {
        lcm_panic("Invalid object type requested");
    }
    if ($id_obj) {
        //
        // Show current keywords (already attached to object)
        //
        $current_kws = get_keywords_applied_to($type_obj, $id_obj, $id_obj_sec);
        $cpt = 0;
        foreach ($current_kws as $kw) {
            $kwg = get_kwg_from_id($kw['id_group']);
            $show_kw_value = false;
            echo "<tr>\n";
            echo "<td>" . "<label for=\"kw_value_{$type_obj}{$cpt}\">" . f_err_star('kwg' . $kwg['id_group']) . _Ti(remove_number_prefix($kwg['title'])) . "</label>" . "<br />(" . _T('keywords_input_policy_' . $kwg['policy']) . ")" . "</td>\n";
            echo "<td>";
            $kw_for_kwg = get_keywords_in_group_id($kwg['id_group']);
            if (count($kw_for_kwg)) {
                echo '<input type="hidden" name="kwg_id_' . $type_obj . '[]" value="' . $kwg['id_group'] . '" />' . "\n";
                echo '<input type="hidden" name="kw_entry_' . $type_obj . '[]" value="' . $kw['id_entry'] . '" />' . "\n";
                echo '<select id="kw_value_' . $type_obj . $cpt . '" name="kw_value_' . $type_obj . '[]">';
                echo '<option value="">' . '' . "</option>\n";
                foreach ($kw_for_kwg as $kw1) {
                    if ($kw1['hasvalue'] == 'Y') {
                        $show_kw_value = true;
                    }
                    $sel = '';
                    if (isset($_SESSION['form_data']['kw_value_' . $type_obj][$cpt]) && $_SESSION['form_data']['kw_value_' . $type_obj][$cpt] == $kw1['id_keyword']) {
                        $sel = ' selected="selected" ';
                    } elseif ($kw1['id_keyword'] == $kw['id_keyword']) {
                        $sel = ' selected="selected" ';
                    }
                    echo '<option value="' . $kw1['id_keyword'] . '"' . $sel . '>' . _T(remove_number_prefix($kw1['title'])) . "</option>\n";
                }
                echo "</select>\n";
            }
            // Check if keyword policy = mandatory, and quantity = one
            $kwg = get_kwg_from_id($kw['id_group']);
            if (!($kwg['policy'] == 'mandatory' && $kwg['quantity'] == 'one')) {
                echo '<label for="kw_del_' . $type_obj . $cpt . '">' . '<img src="images/jimmac/stock_trash-16.png" width="16" height="16" alt="Delete?" title="Delete?" />' . '</label>&nbsp;<input type="checkbox" id="kw_del_' . $type_obj . $cpt . '" name="kw_del_' . $type_obj . $cpt . '"/>';
            }
            if ($show_kw_value) {
                // Use value if submitted with the form, else use previous one
                if (isset($_SESSION['form_data']['kw_entryval_' . $type_obj . $cpt])) {
                    $tmp_value = $_SESSION['form_data']['kw_entryval_' . $type_obj . $cpt];
                } else {
                    $tmp_value = $kw['value'];
                }
                echo "<br />\n";
                echo '<input type="text" name="kw_entryval_' . $type_obj . $cpt . '" ' . 'value="' . $tmp_value . '" />' . "\n";
            }
            echo "</td>\n";
            echo "</tr>\n";
            $cpt++;
        }
    }
    //
    // New keywords
    //
    $kwg_for_case = get_kwg_applicable_for($type_obj, $id_obj, $id_obj_sec);
    $cpt_kw = 0;
    foreach ($kwg_for_case as $kwg) {
        echo "<tr>\n";
        echo '<td><label for="new_keyword_' . $type_obj . $cpt_kw . '">' . f_err_star('keyword_' . $type_obj . $cpt_kw) . f_err_star('kwg' . $kwg['id_group']) . _Ti(remove_number_prefix($kwg['title'])) . '</label>' . "<br />(" . _T('keywords_input_policy_' . $kwg['policy']) . ")</td>\n";
        echo "<td>";
        $kw_for_kwg = get_keywords_in_group_id($kwg['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="' . $kwg['id_group'] . '" />' . "\n";
            echo '<select id="new_keyword_' . $type_obj . $cpt_kw . '" ' . 'name="new_keyword_' . $type_obj . '_value[]" ' . "onchange=\"getKeywordInfo('get_kwg_in','" . $kwg['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
                $sel = '';
                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" ';
                } elseif ($kwg['suggest'] == $kw['name']) {
                    $sel = ' selected="selected" ';
                }
                // $sel = ($kwg['suggest'] == $kw['name'] ? ' selected="selected" ' : '');
                echo '<option ' . $sel . ' value="' . $kw['id_keyword'] . '">' . _T(remove_number_prefix($kw['title'])) . "</option>\n";
            }
            echo "</select>\n";
            if ($show_kw_value) {
                $tmp_value = '';
                if (isset($_SESSION['form_data']['new_kw_entryval_' . $type_obj . $cpt_kw])) {
                    $tmp_value = $_SESSION['form_data']['new_kw_entryval_' . $type_obj . $cpt_kw];
                }
                echo "<br />\n";
                echo '<input type="text" name="new_kw_entryval_' . $type_obj . $cpt_kw . '" ' . 'value="' . $tmp_value . '" />' . "\n";
            }
            echo '<div id="' . $obj_id_ajax . '"></div>' . "\n";
        } else {
            //
            // Sub-keyword group(s), since no top-level keywords
            //
            $sub_kwgs = get_subgroups_in_group_id($kwg['id_group']);
            if (count($sub_kwgs)) {
                echo '<input type="hidden" name="nop_kwg_' . $type_obj . '_id[]" value="' . $kwg['id_group'] . '" />' . "\n";
                $obj_id_ajax = 'kw_' . create_random_password(15, time());
                $sel_id = 'nop_kwg_' . $type_obj . $cpt_kw;
                $sel_name = 'nop_keyword_' . $type_obj . '_value[]';
                echo "<select id=\"{$sel_id}\" name=\"{$sel_name}\" " . "onchange=\"getKeywordInfo('get_kwg_in', this.value, '{$type_obj}', {$id_obj}, 0, '{$obj_id_ajax}')\"" . '>';
                echo '<option value="">' . '' . "</option>\n";
                foreach ($sub_kwgs as $sg) {
                    echo '<option value="' . $sg['name'] . '">' . _T(remove_number_prefix($sg['title'])) . "</option>\n";
                }
                echo "</select>\n";
                echo '<div id="' . $obj_id_ajax . '"></div>' . "\n";
            }
            echo '<div id="keywords_in_group_data' . $kwg['id_group'] . '"></div>' . "\n";
        }
        echo "</td>\n";
        echo "</tr>\n";
        $cpt_kw++;
    }
}
function show_context_stage($id_case, $id_stage)
{
    if (!(is_numeric($id_case) && $id_case > 0)) {
        lcm_log("Warning: show_context_stage, id_case not a number > 0: {$id_case}");
        return;
    }
    if (!(is_numeric($id_stage) && $id_stage > 0)) {
        lcm_log("Warning: show_context_stage, id_stage not a number > 0: {$id_stage}");
        return;
    }
    include_lcm('inc_keywords');
    $kws = get_keywords_applied_to('stage', $id_case, $id_stage);
    foreach ($kws as $kw) {
        echo '<li style="list-style-type: none;">';
        if ($kw['value']) {
            echo _Ti(remove_number_prefix($kw['title']));
            echo $kw['value'];
        } else {
            echo _Ti(remove_number_prefix($kw['kwg_title'])) . _T(remove_number_prefix($kw['title']));
        }
        echo "</li>\n";
    }
}