function write_metas() { global $meta, $meta_upd; read_metas(); $s = '<' . '?php if (defined("_INC_META_CACHE")) return; define("_INC_META_CACHE", "1"); function read_meta($name) { global $meta; if (! isset($meta[$name])) { lcm_debug("read_meta: -$name- does not exist"); return ""; } return $meta[$name]; } function read_meta_upd($name) { global $meta_upd; return $meta_upd[$name]; } '; if ($meta) { reset($meta); while (list($key, $val) = each($meta)) { $key = addslashes($key); $val = preg_replace("/([\\\\'])/", "\\\\1", $val); $s .= "\$GLOBALS['meta']['{$key}'] = '{$val}';\n"; } $s .= "\n"; } if ($meta_upd) { reset($meta_upd); while (list($key, $val) = each($meta_upd)) { $key = addslashes($key); $s .= "\$GLOBALS['meta_upd']['{$key}'] = '{$val}';\n"; } $s .= "\n"; } // System keywords include_lcm('inc_keywords'); $kwg_all = get_kwg_all('system'); foreach ($kwg_all as $key0 => $val0) { // Dump every field of the keyword group foreach ($val0 as $key => $val) { // We filter out numeric keys because lcm_fetch_array() // returns the two types of arrays if (!is_numeric($key)) { $key = addslashes($key); $val = preg_replace("/([\\\\'])/", "\\\\1", $val); $s .= "\$GLOBALS['system_kwg']['" . $kwg_all[$key0]['name'] . "']['{$key}'] = '{$val}';\n"; } } } reset($kwg_all); foreach ($kwg_all as $kwg) { // Dump every keyword and field of the keyword group $kw_all = get_keywords_in_group_id($kwg['id_group'], false); foreach ($kw_all as $kw) { $kw_name = $kw['name']; // Dump every field of the keyword into the kwg while (list($key, $val) = each($kw)) { if (!is_numeric($key)) { $key = addslashes($key); $val = preg_replace("/([\\\\'])/", "\\\\1", $val); $s .= "\$GLOBALS['system_kwg']['" . $kwg['name'] . "']['keywords']['{$kw_name}']['{$key}'] = '{$val}';\n"; } } } } $s .= '?' . '>'; if (isset($_SERVER['LcmDataDir'])) { $file_meta_cache = $_SERVER['LcmDataDir'] . '/inc_meta_cache.php'; } else { $file_meta_cache = 'inc/data/inc_meta_cache.php'; } @unlink($file_meta_cache); $file_meta_cache_w = $file_meta_cache . '-' . @getmypid(); $f = @fopen($file_meta_cache_w, "wb"); if ($f) { $r = @fputs($f, $s); @fclose($f); if ($r == strlen($s)) { @rename($file_meta_cache_w, $file_meta_cache); } else { @unlink($file_meta_cache_w); } } else { global $connect_status; if ($connect_status == 'admin') { echo "<h4 font color='red'>" . _T('texte_inc_meta_1') . " <a href='lcm_test_dirs.php'>" . _T('texte_inc_meta_2') . "</a> " . _T('texte_inc_meta_3') . " </h4>\n"; } } }
function show_all_keywords_type($type = 'system') { $kwg_all = get_kwg_all($type); foreach ($kwg_all as $kwg) { show_kwg_info($kwg); } if ($type == 'user') { echo '<p><a href="keywords.php?action=edit_group&id_group=0" class="create_new_lnk">' . _T('keywords_button_kwg_new') . '</a></p>' . "\n"; } elseif ($type == 'contact') { echo '<p><a href="keywords.php?action=edit_group&type=contact&id_group=0" class="create_new_lnk">' . _T('keywords_button_kwg_new') . '</a></p>' . "\n"; } }
function update_contacts_request($type_person, $id_of_person) { // This will be useful later, to check mandatory/optional contacts $all_contact_kwg = get_kwg_all('contact'); // // Update existing contacts // if (isset($_REQUEST['contact_value'])) { $contacts = $_REQUEST['contact_value']; $c_ids = $_REQUEST['contact_id']; $c_types = $_REQUEST['contact_type']; // // Check if the contacts provided are really attached to the person // or else the user can provide a form with false contacts. // $all_contacts = get_contacts($type_person, $id_of_person); for ($cpt = 0; isset($c_ids[$cpt]) && $c_ids[$cpt]; $cpt++) { $valid = false; foreach ($all_contacts as $c) { if ($c['id_contact'] == $c_ids[$cpt]) { $valid = true; } } if (!$valid) { lcm_panic("Invalid modification of existing contact detected."); } } for ($cpt = 0; isset($c_ids[$cpt]); $cpt++) { // Check first to see if the contact is mandatory $kwg = get_kwg_from_id($c_types[$cpt]); $delete_allowed = true; if ($kwg['policy'] == 'mandatory') { // XXX Having policy == 'mandatory' but quantity = many // really makes a mess, and is not handled. $delete_allowed = false; } if (_request('del_contact_' . $c_ids[$cpt])) { if ($delete_allowed) { lcm_debug("Contact DEL: {$type_person}, {$id_of_person}, " . $c_ids[$cpt], 1); delete_contact($c_ids[$cpt]); } else { $_SESSION['errors']['upd_contact_' . $cpt] = _T('warning_field_mandatory'); } } else { if (!$delete_allowed && !$contacts[$cpt]) { $_SESSION['errors']['upd_contact_' . $cpt] = _T('warning_field_mandatory'); } else { lcm_debug("Contact UPD: {$type_person}, {$id_of_person}, " . $c_ids[$cpt] . ' = ' . $contacts[$cpt], 1); $err = update_contact($c_ids[$cpt], $contacts[$cpt]); if ($err) { $_SESSION['errors']['upd_contact_' . $cpt] = $err; } } } } } // // New contacts // if (isset($_REQUEST['new_contact_value'])) { $cpt = 0; $new_contacts = $_REQUEST['new_contact_value']; $c_type_names = $_REQUEST['new_contact_type_name']; while (isset($new_contacts[$cpt])) { // Process only new contacts which have a value if ($new_contacts[$cpt]) { // And make sure that they have a "type of contact" if ($c_type_names[$cpt]) { lcm_debug("Contact NEW: {$type_person}, {$id_of_person}, Name = " . $c_type_names[$cpt] . ', ' . $new_contacts[$cpt], 1); $err = add_contact($type_person, $id_of_person, $c_type_names[$cpt], $new_contacts[$cpt]); if ($err) { $_SESSION['errors']['new_contact_' . $cpt] = $err; } } else { $_SESSION['errors']['new_contact_' . $cpt] = "Please specify the type of contact."; // TRAD } } $cpt++; } } // // Check if all mandatory contacts were provided // $all_contacts = get_contacts($type_person, $id_of_person); foreach ($all_contact_kwg as $c) { if ($c['policy'] == 'mandatory') { $found = false; foreach ($all_contacts as $a) { if ($a['name'] == $c['name'] && trim($a['value'])) { $found = true; } } if (!$found) { $_SESSION['errors']['contact_' . $c['name']] = _Ti($c['title']) . _T('warning_field_mandatory'); } } } }
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'] . "&" . "remove=" . $type . "&" . $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'] . '&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"; } } }