function init_default_config() { // default language of the site = installation language (cookie) // (if no cookie, then set to English) if (!($lang = $GLOBALS['lcm_lang'])) { $lang = 'en'; } $meta_name_middle = 'no'; if ($lang == 'bg' || $lang == 'pt_br') { $meta_name_middle = 'yes'; } // Check whether database supports utf8 $db_utf8 = 'no'; if (!preg_match('/^MySQL (4\\.0|3\\.)/', lcm_sql_server_info())) { $db_utf8 = 'yes'; } // c.f. http://www.lcm.ngo-bg.org/article28.html $list_meta = array('default_language' => $lang, 'site_open_subscription' => 'no', 'site_name' => 'title_software', 'site_description' => 'title_software_description', 'currency' => _T('currency_default_format'), 'case_default_read' => 'yes', 'case_default_write' => 'no', 'case_read_always' => 'no', 'case_write_always' => 'no', 'client_name_middle' => $meta_name_middle, 'client_citizen_number' => 'no', 'client_civil_status' => 'no', 'client_income' => 'no', 'client_hide_all' => 'no', 'client_share_read' => 'yes', 'client_share_write' => 'yes', 'client_date_birth' => 'no', 'person_name_format' => '1', 'org_hide_all' => 'no', 'org_share_read' => 'yes', 'org_share_write' => 'yes', 'case_court_archive' => 'no', 'case_assignment_date' => 'yes', 'case_alledged_crime' => 'yes_optional', 'case_legal_reason' => 'yes_optional', 'case_new_showorg' => 'no', 'case_allow_modif' => 'yes', 'fu_sum_billed' => 'no', 'fu_allow_modif' => 'yes', 'hide_emails' => 'no', 'db_utf8' => $db_utf8, 'charset' => 'UTF-8'); $modifs = false; while (list($key, $value) = each($list_meta)) { if (!read_meta($key)) { write_meta($key, $value); $modifs = true; } } if ($modifs) { write_metas(); } // Force the update list of available languages include_lcm('inc_lang'); init_languages(true); }
function lcm_query_db($query, $accept_fail = false) { global $lcm_mysql_link; static $tt = 0; $my_debug = $GLOBALS['sql_debug']; $my_profile = $GLOBALS['sql_profile']; /* [ML] I have no idea whether this is overkill, but without it, we get strange problems with Cyrillic and other non-latin charsets. We need to check whether tables were installed correctly, or else it will not show non-latin utf8 characters correctly. (i.e. for people who upgraded LCM, but didn't import/export their data to fix the tables.) */ if (read_meta('db_utf8') == 'yes') { lcm_mysql_set_utf8(); } elseif (!read_meta('db_utf8') == 'no' && !read_meta('lcm_db_version')) { // We are not yet installed, so check MySQL version on every request // Note: checking is is_file('inc/data/inc_meta_cache.php') is not // enough, because the keywords cache may have been generated, but not // the meta. if (!preg_match("/^(4\\.0|3\\.)/", mysql_get_server_info())) { lcm_mysql_set_utf8(); } } $query = process_query($query); if ($my_profile) { $m1 = microtime(); } if ($GLOBALS['mysql_recall_link'] and $lcm_mysql_link) { $result = mysql_query($query, $lcm_mysql_link); } else { $result = mysql_query($query); } if ($my_debug and $my_profile) { $m2 = microtime(); list($usec, $sec) = explode(" ", $m1); list($usec2, $sec2) = explode(" ", $m2); $dt = $sec2 + $usec2 - $sec - $usec; $tt += $dt; echo "<small>" . htmlentities($query); echo " -> <font color='blue'>" . sprintf("%3f", $dt) . "</font> ({$tt})</small><p>\n"; } if ($my_debug) { lcm_debug("QUERY: {$query}\n", 1, 'sql'); } if (lcm_sql_errno() && !$accept_fail) { $s = lcm_sql_error(); $error = _T('warning_sql_query_failed') . "<br />\n" . htmlentities($query) . "<br />\n"; $error .= "« " . htmlentities($s) . " »<br />"; lcm_panic($error); } return $result; }
function send_email($email, $subject, $texte, $from = "", $headers = "") { global $hebergeur, $queue_mails, $flag_wordwrap, $os_serveur; include_lcm('inc_filters'); if (!$from) { $email_envoi = read_meta("email_sender"); $from = is_valid_email($email_envoi) ? $email_envoi : $email; } if (!is_valid_email($email)) { return false; } lcm_debug("mail ({$email}): {$subject}"); $charset = read_meta('charset'); $headers = "From: {$from}\n" . "MIME-Version: 1.0\n" . "Content-Type: text/plain; charset={$charset}\n" . "Content-Transfer-Encoding: 8bit\n{$headers}"; $texte = filtrer_entites($texte); $subject = filtrer_entites($subject); // fignoler ce qui peut l'etre... if ($charset != 'utf-8') { $texte = str_replace("’", "'", $texte); $subject = str_replace("’", "'", $subject); } // encoder le sujet si possible selon la RFC if ($GLOBALS['flag_multibyte'] and @mb_internal_encoding($charset)) { $subject = mb_encode_mimeheader($subject, $charset, 'Q'); } if ($flag_wordwrap) { $texte = wordwrap($texte); } if ($os_serveur == 'windows') { $texte = preg_replace("/\r*\n/", "\r\n", $texte); $headers = preg_replace("/\r*\n/", "\r\n", $headers); } switch ($hebergeur) { case 'lycos': $queue_mails[] = array('email' => $email, 'sujet' => $subject, 'texte' => $texte, 'headers' => $headers); return true; case 'free': return false; case 'online': if (!($ret = @email('webmaster', $email, $subject, $texte))) { lcm_log("ERROR mail: (online) returned false"); } return $ret; default: if (!($ret = @mail($email, $subject, $texte, $headers))) { lcm_log("ERROR mail: (default) returned false"); } return $ret; } }
function _action_auteur($action, $id_auteur, $nom_alea) { if (!$id_auteur) { global $connect_id_auteur, $connect_pass; $id_auteur = $connect_id_auteur; $pass = $connect_pass; } else { $result = spip_query("SELECT password FROM lcm_author WHERE id_author={$id_auteur}"); if ($result) { if ($row = spip_fetch_array($result)) { $pass = $row['password']; } } } $alea = read_meta($nom_alea); return md5($action . $id_auteur . $pass . $alea); }
function get_kwg_all($type, $exclude_empty = false, $show_subgroups = false) { $ret = array(); if ($type == 'user') { $in_type = "IN ('case', 'stage', 'followup', 'client', 'org', 'client_org')"; } elseif ($type) { $in_type = "= '" . addslashes($type) . "'"; } if ($exclude_empty) { $query = "SELECT kwg.*, COUNT(k.id_keyword) as cpt\n\t\t\t\t\tFROM lcm_keyword_group as kwg, lcm_keyword as k\n\t\t\t\t\tWHERE kwg.id_group = k.id_group "; if ($in_type) { $query .= " AND type {$in_type} "; } if (!$show_subgroups) { $query .= " AND id_parent = 0 "; } // pgsql requires that we group on all fields $query .= " GROUP BY kwg.id_group, kwg.name, kwg.title, kwg.description, kwg.type, kwg.policy, kwg.quantity, kwg.suggest, kwg.ac_admin, kwg.ac_author, kwg.id_parent\n\t\t\t\t\tHAVING COUNT(k.id_keyword) > 0"; } else { $query = "SELECT *\n\t\t\t\t\tFROM lcm_keyword_group "; if ($in_type) { $query .= " WHERE type {$in_type} "; } // [ML] If importing an old DB (ex: form 0.6.4) in LCM 0.7.x, // ignore this, or the import will panic. if (!$show_subgroups && read_meta('lcm_db_version') >= 47) { $query .= " AND id_parent = 0 "; } } $result = lcm_query($query); while ($row = lcm_fetch_array($result)) { $ret[$row['title']] = $row; $ret[$row['title']]['title'] = remove_number_prefix($row['title']); } ksort($ret); reset($ret); return $ret; }
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"; }
$org->printGeneral(false); $org->printCases(); $org->printAttach(); } if ($attach_client) { show_page_subtitle(_Th('title_client_view'), 'clients_intro'); $client = new LcmClientInfoUI($attach_client); $client->printGeneral(false); $client->printCases(); $client->printAttach(); } if (!$attach_client && !$attach_org) { // // Find or create an organisation for case // if (read_meta('case_new_showorg') == 'yes') { show_page_subtitle(_Th('title_org_view'), 'clients_intro'); echo '<p class="normal_text">'; echo '<input type="checkbox"' . isChecked(_session('add_org')) . 'name="add_org" id="box_new_org" onclick="display_block(\'new_org\', \'flip\')" />'; echo '<label for="box_new_org">' . _T('case_button_add_org') . '</label>'; echo "</p>\n"; // Open box that hides this form by default echo '<div id="new_org" ' . (_session('add_org') ? '' : ' style="display: none;"') . '>'; echo "<div style='overflow: hidden; width: 100%;'>"; echo '<div style="float: left; text-align: right; width: 29%;">'; echo '<p class="normal_text" style="margin: 0; padding: 4px;">' . _Ti('input_search_org') . '</p>'; echo "</div>\n"; echo '<div style="float: right; width: 69%;">'; echo '<p class="normal_text" style="margin: 0; padding: 4px;"><input type="text" autocomplete="off" name="orgsearchkey" id="orgsearchkey" size="25" />' . "</p>\n"; echo '<span id="autocomplete-org-popup" class="autocomplete" style="position: absolute; visibility: hidden;"><span></span></span>'; echo '</div>';
include_lcm('inc_meta'); include_lcm('inc_auth'); global $lcm_db_version; // Check dir permissions: if we upgrade the LCM files, the permissions // of the directories may have changed. // c.f. Mateusz Hołysz (1148727224.9101.18.camel@localhost.localdomain) if (_request('dirs_ok') != 1) { lcm_header('Location: lcm_test_dirs.php?url=' . urlencode("lcm_upgrade.php?dirs_ok=1")); exit; } // Usually done in inc.php, but we cannot include it otherwise // it will loop on "please upgrade your database". if (!include_data_exists('inc_meta_cache')) { write_metas(); } $current_version = read_meta('lcm_db_version'); // Quite unlikely to happen, because it would cause warnings // But let's be paranoid, nothing to loose.. if (!$current_version) { lcm_log("lcm_upgrade: meta is misbehaving, searching in DB"); $query = "SELECT value FROM lcm_meta WHERE name = 'lcm_db_version'"; $result = lcm_query($query); if ($row = lcm_fetch_array($result)) { $current_version = $row['value']; } else { lcm_panic("Could not find lcm_db_version"); } } lcm_log("lcm_upgrade test: current = {$current_version}, should be = {$lcm_db_version}"); // test if upgraded necessary if ($current_version < $lcm_db_version) {
$followup = intval($_GET['followup']); // Fetch the details on the specified follow-up $q = "SELECT fu.*, a.name_first, a.name_middle, a.name_last, " . lcm_query_subst_time('fu.date_start', 'fu.date_end') . " as length\n\t\tFROM lcm_followup as fu, lcm_author as a\n\t\tWHERE id_followup = {$followup}\n\t\t\tAND fu.id_author = a.id_author"; $result = lcm_query($q); if ($row = lcm_fetch_array($result)) { foreach ($row as $key => $value) { $fu_data[$key] = $value; } } else { die("There's no such follow-up!"); } } else { die("Which follow-up?"); } // For 'edit case' button + 'undelete' message $case_allow_modif = read_meta('case_allow_modif'); $edit = allowed($fu_data['id_case'], 'e'); $admin = allowed($fu_data['id_case'], 'a'); lcm_page_start(_T('title_fu_view'), '', '', 'cases_followups'); echo '<fieldset class="info_box">'; // Show a bit of background on the case $case = $fu_data['id_case']; show_context_start(); show_context_case_title($fu_data['id_case']); show_context_case_stage($fu_data['id_case'], $fu_data['id_followup']); show_context_case_involving($fu_data['id_case']); // Show parent appointment, if any // [ML] todo put in inc_presentation $q = "SELECT app.*\n\t\tFROM lcm_app_fu as af, lcm_app as app\n\t\tWHERE af.id_followup = {$followup} \n\t\t AND af.id_app = app.id_app \n\t\t AND af.relation = 'child'"; $res_app = lcm_query($q); if ($app = lcm_fetch_array($res_app)) {
function install_step_5() { include_config('inc_connect_install'); include_lcm('inc_meta'); include_lcm('inc_access'); global $lcm_lang_left, $lcm_lang_right; // Either leave the form completely empty, or fill in everything if (_request('username') || _request('name_first') || _request('name_last') || _request('email')) { $_SESSION['form_data']['name_first'] = _request('name_first'); $_SESSION['form_data']['name_middle'] = _request('name_middle'); $_SESSION['form_data']['name_last'] = _request('name_last'); $_SESSION['form_data']['username'] = _request('username'); $_SESSION['form_data']['password'] = _request('password'); $_SESSION['form_data']['password_confirm'] = _request('password_confirm'); $_SESSION['form_data']['email'] = _request('email'); $_SESSION['form_data']['getnews'] = _request('getnews'); // Test mandatory fields, sorry for the ugly code $mandatory = array('name_first' => 'person_input', 'name_last' => 'person_input', 'username' => 'authoredit_input', 'password' => 'authorconf_input', 'password_confirm' => 'authorconf_input', 'getnews' => 'install_input'); foreach ($mandatory as $mn => $str) { if (!_request($mn)) { $_SESSION['errors'][$mn] = _T($str . '_' . $mn) . ' ' . _T('warning_field_mandatory'); } } if (_session('password') != _session('password_confirm')) { $_SESSION['errors']['password'] = _T('login_warning_password_dont_match'); } if (count($_SESSION['errors'])) { return install_step_4(); } $query = "SELECT id_author FROM lcm_author WHERE username='******'username') . "'"; $result = lcm_query($query); unset($id_author); while ($row = lcm_fetch_array($result)) { $id_author = $row['id_author']; } // If user exists, allow to reset a forgotten password, which is possible // by deleting inc_connect.php and re-installing (it does not affect the DB). if ($id_author) { $query = "UPDATE lcm_author " . "SET name_first = '" . _session('name_first') . "', \n\t\t\t\t\tname_middle = '" . _session('name_middle') . "', \n\t\t\t\t\tname_last = '" . _session('name_last') . "', \n\t\t\t\t\tusername = '******'username') . "', \n\t\t\t\t\tdate_update = NOW(),\n\t\t\t\t\talea_actuel = '', \n\t\t\t\t\talea_futur = FLOOR(32000*RAND()), \n\t\t\t\t\tstatus = 'admin'\n\t\t\t\t WHERE id_author = " . $id_author; lcm_query_db($query); } else { $query = "INSERT INTO lcm_author " . "(name_first, name_middle, name_last, username, prefs, cookie_recall, pgp, " . "password, alea_actuel, alea_futur, status, date_update, date_creation)" . "VALUES (" . "'" . _session('name_first') . "'," . "'" . _session('name_middle') . "'," . "'" . _session('name_last') . "'," . "'" . _session('username') . "'," . "'', '', '', " . "'temp'," . "''," . "FLOOR(32000*RAND())," . "'admin'," . "NOW()," . "NOW()" . ")"; lcm_query_db($query); $id_author = lcm_insert_id('lcm_author', 'id_author'); } // // Set password // $class_auth = 'Auth_db'; include_lcm('inc_auth_db'); $auth = new $class_auth(); if (!$auth->init()) { lcm_log("pass change: failed auth init: " . $auth->error); $_SESSION['errors']['password'] = $auth->error; return install_step_4(); } if (!$auth->newpass($id_author, _session('username'), _session('password'))) { $_SESSION['errors']['password'] = $auth->error; } if (count($_SESSION['errors'])) { return install_step_4(); } // // Set e-mail for author // if (_session('email')) { include_lcm('inc_contacts'); if (!is_existing_contact('author', $id_author, 'email_main', _session('email'))) { add_contact('author', $id_author, 'email_main', _session('email')); } // Insert email as main system administrator write_meta('email_sysadmin', _session('email')); } } else { // Test if an administrator already exists $number_admins = get_number_admins(); if (!$number_admins) { $_SESSION['errors']['generic'] = _T('install_warning_no_admins_exist'); return install_step_4(); } } $site_address = read_meta('site_address'); if (!$site_address) { global $HTTP_SERVER_VARS, $HTTP_HOST; // Replace www.site.net/foo/name.php -> www.site.net/foo/ $site_address = $_SERVER['REQUEST_URI']; if (!$site_address) { $site_address = $_ENV['PHP_SELF']; } // [ML] unsure $site_address = preg_replace("/\\/[^\\/]+\\.php\$/", "/", $site_address); $site_address = 'http://' . $_SERVER['HTTP_HOST'] . $site_address; write_meta('site_address', $site_address); } // Force regeneration of metas, just in case.. $lcm_meta_cache = 'inc_meta_cache.php'; if (isset($_SERVER['LcmDataDir'])) { $lcm_meta_cache = $_SERVER['LcmDataDir'] . '/' . $lcm_meta_cache; } else { $lcm_meta_cache = 'inc/data/' . $lcm_meta_cache; } @unlink($lcm_meta_cache); write_metas(); // Finalise installation $lcm_config_prefix = isset($_SERVER['LcmConfigDir']) ? $_SERVER['LcmConfigDir'] : 'inc/config'; if (!@rename($lcm_config_prefix . '/inc_connect_install.php', $lcm_config_prefix . '/inc_connect.php')) { copy($lcm_config_prefix . '/inc_connect_install.php', $lcm_config_prefix . '/inc_connect.php'); @unlink($lcm_config_prefix . '/inc_connect_install.php'); } // If requested, send registration request to News mailing-list if (_request('getnews') == 'yes') { if (_session('email') && is_valid_email(_session('email'))) { send_email("*****@*****.**", "subscribe", "subscribe", _session('email')); send_email("*****@*****.**", "[lcm-news] subscribe " . _session('email'), "[lcm-news] subscribe " . _session('email')); } } install_html_start('AUTO', '', 5); echo "<h3><small>" . _T('install_step_last') . "</small></h3>\n"; echo "<div class='box_success'>\n"; echo "<p><b>" . _T('install_info_application_ready') . "</b></p>\n"; echo '<p align="center">' . _T('install_info_do_not_forget') . "</p>\n"; if (_request('getnews') == 'yes') { echo '<p align="' . $lcm_lang_left . '">' . _T('install_info_subscribe_may_fail') . "</p>\n"; } echo '<p align="' . $lcm_lang_left . '">' . _T('install_info_more_about_software', array("url" => '<a class="content_link" href="http://www.lcm.ngo-bg.org">www.lcm.ngo-bg.org</a>')) . "</p>\n"; echo "</div>\n"; echo "<form action='index.php' method='post'>\n"; echo "<div align='" . $lcm_lang_right . "'>" . "<button type='submit' name='Next'>" . _T('button_next') . " >></button> " . "</div>\n"; echo "</form>\n"; install_html_end(); }
function lcm_panic($message) { global $lcm_version, $lcm_db_version; function lcm_ini_get($param) { $ret = ini_get($param); return $ret ? $ret : 'n/a'; } echo "<p>" . _T('warning_panic_is_useful') . "</p>\n"; $error = "[INTERNAL] (v" . $lcm_version . "-db" . $lcm_db_version . ", PHP v" . PHP_VERSION . ")\n"; $error .= "Server: " . $_SERVER['SERVER_SOFTWARE'] . "\n"; if (function_exists('lcm_sql_server_info')) { $error .= "SQL server: " . lcm_sql_server_info() . "\n"; } else { $error .= "SQL server: not yet connected\n"; } $error .= "Referer: " . $_SERVER['HTTP_REFERER'] . "\n"; $error .= "Request: " . $_SERVER['REQUEST_METHOD'] . " " . $_SERVER['REQUEST_URI'] . "\n"; $error .= "Error: " . $message . "\n"; // Show DB version in meta cache $error .= "Version-DB: " . read_meta('lcm_db_version') . " (in cache)\n"; // Show existence + size of cache, in case it doesnt exist, or there were // problems while generating it (i.e. it will be less than 30kb) if (include_data_exists('inc_meta_cache')) { if (isset($_SERVER['LcmDataDir'])) { $prefix = $_SERVER['LcmDataDir'] . '/'; } else { $prefix = 'inc/data/'; } $error .= "inc_meta_cache: exists (" . filesize($prefix . 'inc_meta_cache.php') . " bytes)\n"; } else { $error .= "inc_meta_cache: does NOT exists\n"; } $check_confs = array('safe_mode', 'safe_mode_gid', 'safe_mode_include_dir', 'safe_mode_exec_dir', 'open_basedir', 'disable_functions'); foreach ($check_confs as $conf) { $error .= $conf . ': ' . lcm_ini_get($conf) . "\n"; } if ($GLOBALS['debug']) { $error .= "cookie_prefix: " . $GLOBALS['cookie_prefix'] . "\n"; $error .= "table_prefix: " . $GLOBALS['table_prefix'] . "\n"; $error .= "_GET: " . get_var_dump($_GET) . "\n"; $error .= "_POST: " . get_var_dump($_POST) . "\n"; $error .= "_COOKIE: " . get_var_dump($_COOKIE) . "\n"; $error .= "_SERVER: " . get_var_dump($_SERVER) . "\n"; $error .= "included_files: " . get_var_dump($GLOBALS['included_files']) . "\n"; $error .= "meta: " . get_var_dump($GLOBALS['meta']) . "\n"; } // Too much paranoia? I am not even sure if we can inject code // either XSS or shellcode .. but should not hurt.. $error = htmlspecialchars($error); // Make different lcm_getbacktrace() calls to avoid html in logs lcm_log($error . lcm_getbacktrace(false) . "END OF REPORT\n"); die("<pre>" . $error . " " . lcm_getbacktrace() . "END OF REPORT\n</pre>"); }
function init_languages($force_init = false) { global $all_langs, $langue_site, $cache_lang, $cache_lang_modifs; global $pile_langues, $lang_typo, $lang_dir; $all_langs = read_meta('available_languages'); $langue_site = read_meta('default_language'); $cache_lang = array(); $cache_lang_modifs = array(); $pile_langues = array(); $lang_typo = ''; $lang_dir = ''; $list_all_langs = array(); if ($force_init || !$all_langs || !$langue_site) { if (!($d = @opendir('inc/lang'))) { return; } while ($f = readdir($d)) { if (preg_match('/^lcm_([a-z_]+[0-9]*)\\.php?$/', $f, $regs)) { $list_all_langs[] = $regs[1]; } } closedir($d); sort($list_all_langs); $all_langs2 = join(',', $list_all_langs); // Re-initiatlize site data, if it has changed if ($all_langs2 != $all_langs) { $all_langs = $all_langs2; if (!$langue_site) { // Initialisation: English by default, else the first language found if (preg_match('/,en,/', ",{$all_langs},")) { $langue_site = 'en'; } else { list(, $langue_site) = each($list_all_langs); } if (defined('_INC_META')) { write_meta('default_language', $langue_site); } } if (defined('_INC_META')) { write_meta('available_languages', $all_langs); write_metas(); } } } init_codes_langues(); }
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); } }
} // Sort clients by ID $order_set = false; $order_id = ''; if (isset($_REQUEST['order_id'])) { if ($_REQUEST['order_id'] == 'ASC' || $_REQUEST['order_id'] == 'DESC') { $order_id = $_REQUEST['order_id']; $q .= " ORDER BY id_client " . $order_id; $order_set = true; } } // Sort clients by first name // [ML] I know, problably more logical by last name, but we do not split the columns // later we can sort by any column if we need to // [ML] 2006-03-07: Sorts using last name if siteconfig has name_order to Last, First Middle $person_name_format = read_meta('person_name_format'); $order_name_first = 'ASC'; if (isset($_REQUEST['order_name_first'])) { if ($_REQUEST['order_name_first'] == 'ASC' || $_REQUEST['order_name_first'] == 'DESC') { $order_name_first = $_REQUEST['order_name_first']; } } $q .= $order_set ? " , " : " ORDER BY "; if ($person_name_format == '10') { $q .= " name_last " . $order_name_first; } else { $q .= " name_first " . $order_name_first; } $result = lcm_query($q); $number_of_rows = lcm_num_rows($result); // Check for correct start position of the list
function translitteration($texte, $charset = 'AUTO', $complexe = '') { static $trans; if ($charset == 'AUTO') { $charset = read_meta('charset'); } $charset = strtolower($charset); $table_translit = 'translit' . $complexe; // 1. Passer le charset et les é en utf-8 $texte = unicode_to_utf_8(html2unicode(charset2unicode($texte, $charset, true))); // 2. Translitterer grace a la table predefinie if (!$trans[$complexe]) { global $CHARSET; load_charset($table_translit); reset($CHARSET[$table_translit]); while (list($key, $val) = each($CHARSET[$table_translit])) { $trans[$complexe][caractere_utf_8($key)] = $val; } } if ($GLOBALS['flag_strtr2']) { $texte = strtr($texte, $trans[$complexe]); } else { $tr = $trans[$complexe]; while (list($from, $to) = each($tr)) { $texte = str_replace($from, $to, $texte); } } /* // Le probleme d'iconv c'est qu'il risque de nous renvoyer des ? alors qu'on // prefere garder l'utf-8 pour que la chaine soit indexable. // 3. Translitterer grace a iconv if ($GLOBALS['flag_iconv'] && preg_match('/�*([0-9]+);/', $texte)) { $texte = iconv('utf-8', 'ascii//translit', $texte); } */ return $texte; }
return $ok; } if ($code) { // code should be short word, ex: installation, case_edit, ... $code = preg_replace("/[^_a-z]/", "", $code); $page_title = _T('help_title_' . $code); if ($page_title == 'help_title_' . $code) { $error_section = true; } } else { $page_title = _T('title_software'); } help_page_start($page_title, $code); if ($code) { global $lcm_lang; $lang_site = read_meta('default_language'); // Sometimes the help might not be translated in every // language. We will try first the language of the user, // then the default site language, then we fallback on English. $try_langs = array($lcm_lang, $lang_site, 'en'); $ok = include_help($code, $try_langs); if (!$ok) { if ($error_section) { echo "<p>" . $code . ": " . _T('help_warning_no_section') . "</p>\n"; } else { $toc = get_help_page_toc(); if (isset($toc[$code])) { // [ML] TODO: Show chapter intro? echo "<ul>"; foreach ($toc[$code] as $st) { echo '<li><a href="lcm_help.php?code=' . $st . '">' . _T('help_title_' . $st) . "</a></li>\n";
function printStartDoc($title, $description, $helpref) { $title = trim($title); $description = trim($description); // Prepare the ZIP file /* @include("pear/Archive/Zip.php"); if (! class_exists("Archive_Zip")) lcm_panic("You must have PEAR installed (Archive/Zip.php)"); */ include_lcm('inc_pclzip'); // Zip filename must use random ID, to avoid overwriting existing reports // not catastrophic if that happens, but annoyance nonetheless. $this->zipname = $this->dir . '.ods'; // $this->zipfile = new Archive_Zip($this->zipname); $this->zipfile = new PclZip($this->zipname); $filename = preg_replace('/\\s+/', '_', $title); header("Content-Type: " . $this->mimetype); header('Content-Disposition: filename="' . $filename . '.ods"'); header("Content-Description: " . ($description ? $description : $title)); header("Content-Transfer-Encoding: binary"); // TODO: show description in the XML, near $title // // Write the styles.xml file // $styles = '<?xml version="1.0" encoding="UTF-8"?>' . "\n" . '<office:document-styles' . ' xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0"' . ' xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0"' . ' xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0"' . ' xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0"' . ' xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0"' . ' xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0"' . ' xmlns:xlink="http://www.w3.org/1999/xlink"' . ' xmlns:dc="http://purl.org/dc/elements/1.1/"' . ' xmlns:meta="urn:oasis:names:tc:opendocument:xmlns:meta:1.0"' . ' xmlns:number="urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0"' . ' xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0"' . ' xmlns:chart="urn:oasis:names:tc:opendocument:xmlns:chart:1.0"' . ' xmlns:dr3d="urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0"' . ' xmlns:math="http://www.w3.org/1998/Math/MathML"' . ' xmlns:form="urn:oasis:names:tc:opendocument:xmlns:form:1.0"' . ' xmlns:script="urn:oasis:names:tc:opendocument:xmlns:script:1.0"' . ' xmlns:ooo="http://openoffice.org/2004/office"' . ' xmlns:ooow="http://openoffice.org/2004/writer"' . ' xmlns:oooc="http://openoffice.org/2004/calc"' . ' xmlns:dom="http://www.w3.org/2001/xml-events"' . ' office:version="1.0">' . "\n"; $styles .= '<office:styles>' . ' <number:currency-style style:name="N106P0" style:volatile="true">' . ' <number:number number:decimal-places="2" number:min-integer-digits="1" number:grouping="true" />' . ' <number:text></number:text>' . ' <number:currency-symbol' . ' number:language="' . $GLOBALS['lcm_lang'] . '"' . ' number:country="' . strtoupper($GLOBALS['lcm_lang']) . '">' . read_meta('currency') . '</number:currency-symbol>' . '</number:currency-style>' . '<number:currency-style style:name="N106">' . '<style:text-properties fo:color="#ff0000" />' . '<number:text>-</number:text>' . '<number:number number:decimal-places="2" number:min-integer-digits="1" number:grouping="true" />' . '<number:text></number:text>' . ' <number:currency-symbol' . ' number:language="' . $GLOBALS['lcm_lang'] . '"' . ' number:country="' . strtoupper($GLOBALS['lcm_lang']) . '">' . read_meta('currency') . '</number:currency-symbol>' . '<style:map style:condition="value()>=0" style:apply-style-name="N106P0" />' . '</number:currency-style>' . '</office:styles>'; $styles .= '</office:document-styles>' . "\n"; $f = fopen($this->dir . '/styles.xml', 'w'); fwrite($f, $styles); fclose($f); // content $content = '<?xml version="1.0" encoding="UTF-8"?>' . "\n" . '<office:document-content xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0"' . ' xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0"' . ' xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0"' . ' xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0"' . ' xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0"' . ' xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0"' . ' xmlns:xlink="http://www.w3.org/1999/xlink"' . ' xmlns:dc="http://purl.org/dc/elements/1.1/"' . ' xmlns:meta="urn:oasis:names:tc:opendocument:xmlns:meta:1.0"' . ' xmlns:number="urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0"' . ' xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0"' . ' xmlns:chart="urn:oasis:names:tc:opendocument:xmlns:chart:1.0"' . ' xmlns:dr3d="urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0"' . ' xmlns:math="http://www.w3.org/1998/Math/MathML"' . ' xmlns:form="urn:oasis:names:tc:opendocument:xmlns:form:1.0"' . ' xmlns:script="urn:oasis:names:tc:opendocument:xmlns:script:1.0"' . ' xmlns:ooo="http://openoffice.org/2004/office"' . ' xmlns:ooow="http://openoffice.org/2004/writer"' . ' xmlns:oooc="http://openoffice.org/2004/calc"' . ' xmlns:dom="http://www.w3.org/2001/xml-events"' . ' xmlns:xforms="http://www.w3.org/2002/xforms"' . ' xmlns:xsd="http://www.w3.org/2001/XMLSchema"' . ' xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"' . ' office:version="1.0">'; $content .= '<office:scripts />' . '<office:font-face-decls>' . '<style:font-face style:name="Verdana1" svg:font-family="Verdana" style:font-pitch="variable" />' . '<style:font-face style:name="Verdana" svg:font-family="Verdana" style:font-family-generic="swiss" style:font-pitch="variable" />' . '</office:font-face-decls>' . '<office:automatic-styles>' . '<style:style style:name="co1" style:family="table-column">' . '<style:table-column-properties fo:break-before="auto" style:column-width="2.267cm" />' . '</style:style>' . '<style:style style:name="ro1" style:family="table-row">' . '<style:table-row-properties style:row-height="0.453cm" fo:break-before="auto" style:use-optimal-row-height="true" />' . '</style:style>' . '<style:style style:name="ta1" style:family="table" style:master-page-name="Default">' . '<style:table-properties table:display="true" style:writing-mode="lr-tb" />' . '</style:style>' . '<style:style style:name="ce1" style:family="table-cell" style:parent-style-name="Default" style:data-style-name="N0" />' . '</office:automatic-styles>'; $content .= '<office:body>' . '<office:spreadsheet>' . '<table:table table:name="Sheet1" table:style-name="ta1" table:print="false">' . '<table:table-column table:style-name="co1" table:number-columns-repeated="4" table:default-cell-style-name="Default" />' . '<table:table-row table:style-name="ro1">' . '<table:table-cell office:value-type="string">' . '<text:p>' . $title . '</text:p>' . '</table:table-cell>' . '<table:table-cell table:number-columns-repeated="3" />' . '</table:table-row>' . '<table:table-row table:style-name="ro1">' . '<table:table-cell table:number-columns-repeated="4" />' . '</table:table-row>'; if (!($this->fcontent = fopen($this->dir . '/content.xml', 'w'))) { lcm_panic("Could not open content.xml. " . $GLOBALS['lcm_errormsg']); } fwrite($this->fcontent, $content); // leave $fcontent open until we are finished }
function show_report_for_user($author, $date_start, $date_end, $type) { if ($type == "case") { $q = "SELECT c.title, c.id_case, \n\t\t\t\t\t\t\t\tsum(IF(UNIX_TIMESTAMP(fu.date_end) > 0,\n\t\t\t\t\t\t\t\t\tUNIX_TIMESTAMP(fu.date_end)-UNIX_TIMESTAMP(fu.date_start), 0)) as time,\n\t\t\t\t\t\t\t\tsum(sumbilled) as sumbilled \n\t\t\t\t\t\t \t FROM lcm_case as c, lcm_followup as fu \n\t\t\t\t\t\t\t WHERE fu.id_case = c.id_case AND fu.id_author = {$author}\n\t\t\t\t\t\t\t\tAND UNIX_TIMESTAMP(date_start) >= UNIX_TIMESTAMP('" . $date_start . "') "; if ($date_end != "-1") { $q .= " AND UNIX_TIMESTAMP(date_end) <= UNIX_TIMESTAMP('" . $date_end . "')"; } $q .= " GROUP BY fu.id_case"; } elseif ($type == "fu") { $q = "SELECT fu.type,\n\t\t\t\t\t\t\t\tsum(IF(UNIX_TIMESTAMP(fu.date_end) > 0,\n\t\t\t\t\t\t\t\t\tUNIX_TIMESTAMP(fu.date_end)-UNIX_TIMESTAMP(fu.date_start), 0)) as time,\n\t\t\t\t\t\t\t\tsum(sumbilled) as sumbilled \n\t\t\t\t\t\t \t FROM lcm_followup as fu \n\t\t\t\t\t\t\t WHERE fu.id_author = {$author}\n\t\t\t\t\t\t\t\tAND UNIX_TIMESTAMP(date_start) >= UNIX_TIMESTAMP('" . $date_start . "') "; if ($date_end != "-1") { $q .= " AND UNIX_TIMESTAMP(date_end) <= UNIX_TIMESTAMP('" . $date_end . "') "; } $q .= " GROUP BY fu.type"; } elseif ($type == "agenda") { $q = "SELECT ap.type,\n\t\t\t\t\t\t\t\tsum(IF(UNIX_TIMESTAMP(ap.end_time) > 0,\n\t\t\t\t\t\t\t\t\tUNIX_TIMESTAMP(ap.end_time)-UNIX_TIMESTAMP(ap.start_time), 0)) as time\n\t\t\t\t\t\t \t FROM lcm_app as ap\n\t\t\t\t\t\t\t WHERE ap.id_author = {$author}\n\t\t\t\t\t\t\t \tAND ap.id_case = 0\n\t\t\t\t\t\t\t\tAND UNIX_TIMESTAMP(start_time) >= UNIX_TIMESTAMP('" . $date_start . "') "; if ($date_end != "-1") { $q .= " AND UNIX_TIMESTAMP(end_time) <= UNIX_TIMESTAMP('" . $date_end . "') "; } $q .= " GROUP BY ap.type"; } $result = lcm_query($q); echo "<p class=\"normal_text\">\n"; echo "<table border='0' class='tbl_usr_dtl' width='99%'>\n"; echo "<tr>\n"; echo '<th class="heading">' . _T('case_subtitle_times_by_' . $type) . "</th>\n"; echo "<th class='heading' width='1%' nowrap='nowrap'>" . _Th('case_input_total_time') . ' (' . _T('time_info_short_hour') . ")" . "</th>\n"; $total_time = 0; $total_sum_billed = 0.0; $meta_sum_billed = read_meta('fu_sum_billed') == 'yes'; $meta_sum_billed &= $type == "case" || $type == "fu"; if ($meta_sum_billed) { $currency = read_meta('currency'); echo "<th class='heading' width='1%' nowrap='nowrap'>" . _Th('fu_input_sum_billed') . ' (' . $currency . ")</th>\n"; } echo "</tr>\n"; // Show table contents & calculate total while ($row = lcm_fetch_array($result)) { echo "<tr>\n"; echo "<!-- Total = " . $total_sum_billed . " - row = " . $row['sumbilled'] . " -->\n"; $total_time += $row['time']; $total_sum_billed += $row['sumbilled']; echo '<td>'; if ($type == "case") { echo '<a class="content_link" href="case_det.php?case=' . $row['id_case'] . '">' . $row['id_case'] . ': ' . $row['title'] . '</a>'; } elseif ($type == "fu") { echo _Tkw("followups", $row['type']); } elseif ($type == "agenda") { echo _Tkw("appointments", $row['type']); } echo '</td>'; echo '<td align="right">' . format_time_interval_prefs($row['time']) . "</td>\n"; if ($meta_sum_billed) { echo '<td align="right">'; echo format_money($row['sumbilled']); echo "</td>\n"; } echo "</tr>\n"; } // Show total case hours echo "<tr>\n"; echo "<td><strong>" . _Ti('generic_input_total') . "</strong></td>\n"; echo "<td align='right'><strong>"; echo format_time_interval_prefs($total_time); echo "</strong></td>\n"; if ($meta_sum_billed) { echo '<td align="right"><strong>'; echo format_money($total_sum_billed); echo "</strong></td>\n"; } echo "</tr>\n"; echo "</table>\n"; echo "</p>\n"; }
function show_login($cible, $prive = 'prive', $message_login = '') { $error = ''; $login = _request('var_login'); $logout = _request('var_logout'); // If the cookie fails, inc_auth tried to redirect to lcm_cookie who // then tried to put a cookie. If it is not there, it is "cookie failed" // who is there, and it's probably a bookmark on privet=yes and not // a cookie failure. $cookie_failed = ""; if (_request('var_cookie_failed')) { $cookie_failed = $_COOKIE['lcm_session'] != 'cookie_test_failed'; } global $author_session; global $lcm_session; global $clean_link; if (!$cible) { // cible = destination $cible = new Link(_request('var_url', 'index.php')); } $cible->delVar('var_erreur'); $cible->delVar('var_url'); $cible->delVar('var_cookie_failed'); $clean_link->delVar('var_erreur'); $clean_link->delVar('var_login'); $clean_link->delVar('var_cookie_failed'); $url = $cible->getUrl(); // This populates the $author_session variable include_lcm('inc_session'); verifier_visiteur(); if ($author_session and !$logout and ($author_session['status'] == 'admin' or $author_session['status'] == 'normal')) { if ($url != $GLOBALS['clean_link']->getUrl()) { lcm_header("Location: " . $cible->getUrlForHeader()); } // [ML] This is making problems for no reason, we use login only // for one mecanism (entering the system). // echo "<a href='$url'>"._T('login_this_way')."</a>\n"; echo "<a class='content_link' href='index.php'>" . _T('login_this_way') . "</a>\n"; return; } if (_request('var_erreur') == 'pass') { $error = _T('login_password_incorrect'); } // The login is memorized in the cookie for a possible future admin login if (!$login && isset($_COOKIE['lcm_admin'])) { if (preg_match("/^@(.*)\$/", $_COOKIE['lcm_admin'], $regs)) { $login = $regs[1]; } } else { if ($login == '-1') { $login = ''; } } // other sources for authentication $flag_autres_sources = isset($GLOBALS['ldap_present']) ? $GLOBALS['ldap_present'] : ''; // What informations to pass? if ($login) { $status_login = 0; // unknown status $login = clean_input($login); $query = "SELECT id_author, status, password, prefs, alea_actuel, alea_futur \n\t\t\t\t\tFROM lcm_author \n\t\t\t\t\tWHERE username='******'"; $result = lcm_query($query); if ($row = lcm_fetch_array($result)) { if ($row['status'] == 'trash' or $row['password'] == '') { $status_login = -1; // deny } else { $status_login = 1; // known login // Which infos to pass for the javascript ? $id_author = $row['id_author']; $alea_actuel = $row['alea_actuel']; // for MD5 $alea_futur = $row['alea_futur']; // Button for lenght of connection if ($row['prefs']) { $prefs = unserialize($row['prefs']); $rester_checked = $prefs['cnx'] == 'perma' ? ' checked=\'checked\'' : ''; } } } // Unknown login (except LDAP) or refused if ($status_login == -1 or $status_login == 0 and !$flag_autres_sources) { $error = _T('login_identifier_unknown', array('login' => htmlspecialchars(clean_output($login)))); $login = ''; // [ML] Not sure why this was here, but headers are already sent // therefore it causes an error message (which is not shown, but // might make a mess, knowing how PHP runs differently everywhere..) // @lcm_setcookie('lcm_admin', '', time() - 3600); } } // Javascript for the focus if ($login) { $js_focus = 'document.form_login.session_password.focus();'; } else { $js_focus = 'document.form_login.var_login.focus();'; } // [ML] we should probably add a help link here, since tech, but let's see // how many users complain first, since this should affect only tech users if ($cookie_failed == "yes") { $error = _T('login_warning_cookie'); } echo open_login(); // [ML] Looks like there is no reason why to use $clean_link (defined in inc_version.php) // It would cause very strange bugs when the "feed_globals()" were removed from inc_version // and in the end, well, it looks rather useless. // // Strange bugs were caused because $action would be "./" and therefore it // would call index.php -> listcases.php -> includes inc_auth.php who then // calls auth(), who redirects to the login page. $action = $clean_link->getUrl(); // $action = "lcm_login.php"; if ($login) { // Shows the login form, including the MD5 javascript $flag_challenge_md5 = true; if ($flag_challenge_md5) { echo '<script type="text/javascript" src="inc/md5.js"></script>'; } echo "\n"; echo '<form name="form_login" action="lcm_cookie.php" method="post"'; if ($flag_challenge_md5) { echo " onsubmit='if (this.session_password.value) {\n\t\t\t\tthis.session_password_md5.value = calcMD5(\"{$alea_actuel}\" + this.session_password.value);\n\t\t\t\tthis.next_session_password_md5.value = calcMD5(\"{$alea_futur}\" + this.session_password.value);\n\t\t\t\tthis.session_password.value = \"\"; }'"; } echo ">\n"; echo "<div class='main_login_box' style='text-align:" . $GLOBALS["lcm_lang_left"] . ";'>\n"; if ($error) { echo "<div style='color:red;'><b>" . _T('login_access_denied') . " {$error}</b></div><br />\n"; } if ($flag_challenge_md5) { // This is printed with javascript so that it is hidden from navigators not // using JS, since they will see the username field anyway. echo "<script type=\"text/javascript\"><!--\n" . "document.write('" . addslashes(_T('login_login')) . " <b>{$login}</b><br/>" . "<font size=\\'2\\'><a href=\\'lcm_cookie.php?cookie_admin=no&url=" . rawurlencode($action) . "\\' class=\\'link_btn\\'>" . _T('login_other_identifier') . "</a></font>');\n" . "//--></script>\n"; // If javascript is active, we pass the login in the hidden field echo "<input type='hidden' name='session_login_hidden' value='{$login}' />"; // If javascript is not active, the login is still modifiable // (since the challenge is not used) echo "<noscript>"; } echo "\t<label for='session_login'><b>" . _T('login_login') . "</b> (" . _T('login_info_login') . ")<br /></label>"; echo "\t<input type='text' name='session_login' id='session_login' class='forml' value=\"{$login}\" size='40' />\n"; if ($flag_challenge_md5) { echo "</noscript>\n"; } echo "\t<p />\n"; echo "\t<label for='session_password'><b>" . _T('login_password') . "</b><br /></label>"; echo "\t<input type='password' name='session_password' id='session_password' class='forml' value=\"\" size='40' />\n"; echo "\t<input type='hidden' name='essai_login' value='oui' />\n"; echo "\t<br /> <input type='checkbox' name='session_remember' value='yes' id='session_remember'{$rester_checked} /> "; echo "\t<label for='session_remember'>" . _T('login_remain_logged_on') . "</label>"; echo "\t<input type='hidden' name='url' value='{$url}' />\n"; echo "\t<input type='hidden' name='session_password_md5' value='' />\n"; echo "\t<input type='hidden' name='next_session_password_md5' value='' />\n"; echo "<div align='right'><input class='button_login' type='submit' value='" . _T('button_validate') . "' /></div>\n"; echo "</div>"; echo "</form>"; } else { // Ask only for the login/username $action = quote_amp($action); echo "<form name='form_login' action='{$action}' method='post'>\n"; echo "<div class='main_login_box' style='text-align:" . $GLOBALS["lcm_lang_left"] . ";'>"; if ($error) { echo "<span style='color:red;'><b>" . _T('login_access_denied') . " {$error}</b></span><p />"; } echo "<label><b>" . _T('login_login') . '</b> (' . _T('login_info_login') . ')' . "<br /></label>"; echo "<input type='text' name='var_login' class='forml' value=\"\" size='40' />\n"; echo "<input type='hidden' name='var_url' value='{$url}' />\n"; echo "<div align='right'><input class='button_login' type='submit' value='" . _T('button_validate') . "' /></div>\n"; echo "</div>"; echo "</form>"; } // Focus management echo "<script type=\"text/javascript\"><!--\n" . $js_focus . "\n//--></script>\n"; // Start the login footer echo "<div align='left' style='font-size: 12px;' >"; echo "<div class='lang_combo_box'>" . menu_languages() . "</div>\n"; // button for "forgotten password" include_lcm('inc_mail'); if (server_can_send_email()) { echo '<a href="lcm_pass.php?pass_forgotten=yes" target="lcm_pass" onclick="' . "javascript:window.open(this.href, 'lcm_pass', 'scrollbars=yes, resizable=yes, width=640, height=280'); return false;\" class=\"link_btn\">" . _T('login_password_forgotten') . '</a>'; } $register_popup = 'href="lcm_pass.php?register=yes" target="lcm_pass" ' . ' onclick="' . "javascript:window.open('lcm_pass.php?register=yes', 'lcm_pass', 'scrollbars=yes, resizable=yes, width=640, height=500'); return false;\""; $open_subscription = read_meta("site_open_subscription"); if ($open_subscription == 'yes' || $open_subscription == 'moderated') { echo " <a {$register_popup} class=\"link_btn\">" . _T('login_register') . '</a>'; } echo "</div>\n"; echo close_login(); }
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"; } }
function printEdit() { echo '<input type="hidden" name="id_case" value="' . $this->getDataInt('id_case') . '" />' . "\n"; echo '<table width="99%" border="0" align="center" cellpadding="5" cellspacing="0" class="tbl_usr_dtl">' . "\n"; // TODO: // Ajouter auteur, etc. // Ajouter "approved by" si id_admin != 0 show_context_start(); show_context_case_title($this->getDataInt('id_case'), 'exps'); show_context_end(); if ($this->getDataInt('id_expense')) { echo "<tr><td>" . _T('expense_input_id') . "</td>\n"; echo "<td>" . $this->getDataInt('id_expense') . '<input type="hidden" name="id_expense" value="' . $this->getDataInt('id_expense') . '" /></td></tr>' . "\n"; } echo '<tr><td>' . f_err_star('description') . _T('expense_input_description') . '</td>' . "\n"; echo '<td><textarea name="description" id="input_expense_description" class="frm_tarea" rows="3" cols="60">' . clean_output($this->getDataString('description')) . "</textarea>\n" . "</td>\n"; echo "</tr>\n"; echo '<tr><td>' . f_err_star('type') . _T('expense_input_type') . '</td>' . "\n"; echo '<td>'; echo '<select ' . $dis . ' name="type" size="1" class="sel_frm">' . "\n"; $default_exp = $this->getDataString('type', get_suggest_in_group_name('_exptypes')); $exptype_kws = get_keywords_in_group_name('_exptypes'); foreach ($exptype_kws as $kw) { $sel = isSelected($kw['name'] == $default_exp); if ($sel) { $kw_found = true; } echo '<option value="' . $kw['name'] . '"' . $sel . '>' . _T(remove_number_prefix($kw['title'])) . "</option>\n"; } echo '</td></tr>' . "\n"; echo '<tr><td>' . f_err_star('cost') . _T('expense_input_cost') . '</td>' . "\n"; echo '<td>'; echo '<input type="text" name="cost" value="' . $this->getDataFloat('cost') . '" class="search_form_txt" size="10" />'; echo ' ' . htmlspecialchars(read_meta('currency')); echo "</td></tr>\n"; // Show comment box only if new expense (not edit) if (!$this->getDataInt('id_expense')) { echo "<tr>\n"; echo "<td>" . f_err_star('comment') . _Ti('expense_input_comment') . "</td>\n"; echo '<td><textarea name="comment" id="input_expense_comment" class="frm_tarea" rows="3" cols="60">' . clean_output($this->getDataString('comment')) . "</textarea>\n" . "</td>\n"; echo "</tr>\n"; } echo "</table>\n"; }
with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA $Id: edit_client.php,v 1.50 2006/03/20 23:03:10 mlutfy Exp $ */ include 'inc/inc.php'; include_lcm('inc_filters'); include_lcm('inc_contacts'); include_lcm('inc_obj_client'); // Get input value(s) $id_client = intval(_request('client', 0)); // 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'); if (empty($_SESSION['errors'])) { $form_data = array('id_client' => 0, 'referer' => $_SERVER['HTTP_REFERER']); if ($id_client > 0) { $q = 'SELECT * FROM lcm_client WHERE id_client = ' . $id_client; $result = lcm_query($q); if ($row = lcm_fetch_array($result)) { foreach ($row as $key => $value) { $form_data[$key] = $value; } } } } else { // Fetch previously submitted values, if any
function typo_fr($letexte) { global $flag_strtr2; static $trans; // Nettoyer 160 = nbsp ; 187 = raquo ; 171 = laquo ; 176 = deg ; 147 = ldquo; 148 = rdquo if (!$trans) { $trans = array(" " => "~", "»" => "»", "«" => "«", "”" => "”", "“" => "“", "°" => "°"); $chars = array(160 => '~', 187 => '»', 171 => '«', 148 => '”', 147 => '“', 176 => '°'); $charset = read_meta('charset'); include_lcm('inc_charsets'); while (list($c, $r) = each($chars)) { $c = unicode2charset(charset2unicode(chr($c), 'iso-8859-1', 'forcer')); $trans[$c] = $r; } } if ($flag_strtr2) { $letexte = strtr($letexte, $trans); } else { reset($trans); while (list($c, $r) = each($trans)) { $letexte = str_replace($c, $r, $letexte); } } $cherche1 = array('/((^|[^\\#0-9a-zA-Z\\&])[\\#0-9a-zA-Z]*)\\;/', '/»| --?,|:([^0-9]|$)/', '/([^<!?])([!?])/', '/«|(M(M?\\.|mes?|r\\.?)|[MnN]°) /'); $remplace1 = array('\\1~;', '~\\0', '\\1~\\2', '\\0~'); $letexte = ereg_remplace($cherche1, $remplace1, $letexte); $letexte = preg_replace("/ *~+ */", "~", $letexte); $cherche2 = array('/([^-\\n]|^)--([^-]|$)/', '/(http|https|ftp|mailto)~:/', '/~/'); $remplace2 = array('\\1—\\2', '\\1:', ' '); $letexte = ereg_remplace($cherche2, $remplace2, $letexte); return $letexte; }
function upgrade_database($old_db_version) { $log = ""; $lcm_db_version_current = intval($old_db_version); // // Verify the rights to modify the database // lcm_log("upgrade_database: starting, old_db_version = {$lcm_db_version_current}", 'upgrade'); include_lcm('inc_db_test'); $alter_test_log = lcm_test_alter_table(); if ($alter_test_log) { return $alter_test_log; } lcm_log("upgrade_database: alter table test was OK.", 'upgrade'); // // Upgrade the database accordingly to the current version // lcm_log("Starting LCM database upgrade; version = :{$lcm_db_version_current}:", 'upgrade'); if ($lcm_db_version_current < 2) { lcm_query("ALTER TABLE lcm_case ADD public tinyint(1) DEFAULT '0' NOT NULL"); lcm_query("ALTER TABLE lcm_case_author ADD ac_read tinyint(1) DEFAULT '1' NOT NULL,\n\t\t\t\t\t\t\t\t\t\t\t\tADD ac_write tinyint(1) DEFAULT '0' NOT NULL,\n\t\t\t\t\t\t\t\t\t\t\t\tADD ac_admin tinyint(1) DEFAULT '0' NOT NULL"); upgrade_db_version(2); } if ($lcm_db_version_current < 3) { lcm_query("ALTER TABLE lcm_case_author ADD ac_edit tinyint(1) DEFAULT '0' NOT NULL AFTER ac_write"); upgrade_db_version(3); } if ($lcm_db_version_current < 4) { lcm_query("ALTER TABLE lcm_author ALTER id_office SET DEFAULT 0"); upgrade_db_version(4); } if ($lcm_db_version_current < 5) { lcm_query("ALTER TABLE lcm_case ADD pub_write tinyint(1) DEFAULT '0' NOT NULL"); upgrade_db_version(5); } // Renames a previously unused column // (stores a cookie for when user forgets pass and needs reset) if ($lcm_db_version_current < 6) { lcm_query("ALTER TABLE lcm_author DROP cookie_oubli"); lcm_query("ALTER TABLE lcm_author ADD cookie_recall char(3) default 'no' NOT NULL"); upgrade_db_version(6); } if ($lcm_db_version_current < 7) { // Ahem.. the previous version was a mistake lcm_query("ALTER TABLE lcm_author DROP cookie_recall"); lcm_query("ALTER TABLE lcm_author ADD cookie_recall tinytext NOT NULL"); // For author/client/org contact book lcm_query("CREATE TABLE lcm_contact (\n\t\t\tid_contact bigint(21) NOT NULL auto_increment,\n\t\t\ttype_person ENUM('author', 'client', 'org') DEFAULT 'author' NOT NULL,\n\t\t\tid_of_person bigint(21) DEFAULT '0' NOT NULL,\n\t\t\tvalue text NOT NULL,\n\t\t\ttype_contact tinyint(2) DEFAULT 0 NOT NULL,\n\t\t\tPRIMARY KEY id_contact (id_contact))"); upgrade_db_version(7); } if ($lcm_db_version_current < 8) { $site_address = read_meta('site_address'); if (!$site_address) { global $HTTP_SERVER_VARS, $HTTP_HOST; // Replace www.site.net/foo/name.php -> www.site.net/foo/ $site_address = $HTTP_SERVER_VARS['REQUEST_URI']; if (!$site_address) { $site_address = $_ENV['PHP_SELF']; } // [ML] unsure $site_address = preg_replace("/\\/[^\\/]+\\.php\$/", "/", $site_address); $site_address = 'http://' . $HTTP_HOST . $site_address; write_meta('site_address', $site_address); } // Added 'trash' and 'suspended' lcm_query("ALTER TABLE lcm_author\n\t\t\tCHANGE status status ENUM('admin', 'normal', 'external', 'trash', 'waiting', 'suspended')\n\t\t\tDEFAULT 'normal' NOT NULL"); upgrade_db_version(8); } if ($lcm_db_version_current < 10) { $query = "CREATE TABLE lcm_keyword (\n\t\t\tid_keyword bigint(21) NOT NULL auto_increment,\n\t\t\tid_group bigint(21) NOT NULL DEFAULT 0,\n\t\t\tname VARCHAR(255) NOT NULL,\n\t\t\ttitle text NOT NULL,\n\t\t\tdescription text NOT NULL,\n\t\t\tac_author ENUM('Y', 'N') NOT NULL DEFAULT 'Y',\n\t\t\tPRIMARY KEY (id_keyword))"; $result = lcm_query($query); $query = "CREATE UNIQUE INDEX idx_kw_name ON lcm_keyword (name)"; $result = lcm_query($query); $query = "CREATE TABLE lcm_keyword_group (\n\t\t\tid_group bigint(21) NOT NULL auto_increment,\n\t\t\tname VARCHAR(255) NOT NULL,\n\t\t\ttitle text NOT NULL,\n\t\t\tdescription text NOT NULL,\n\t\t\ttype ENUM('system', 'case', 'followup', 'client', 'org', 'author'),\n\t\t\tpolicy ENUM('optional', 'recommended', 'mandatory') DEFAULT 'optional',\n\t\t\tsuggest text NOT NULL,\n\t\t\tquantity ENUM('one', 'many') DEFAULT 'one',\n\t\t\tac_admin ENUM('Y', 'N') DEFAULT 'Y',\n\t\t\tac_author ENUM('Y', 'N') DEFAULT 'Y',\n\t\t\tPRIMARY KEY (id_group))"; $result = lcm_query($query); $query = "CREATE UNIQUE INDEX idx_kwg_name ON lcm_keyword_group (name)"; $result = lcm_query($query); global $system_keyword_groups; $system_keyword_groups = array(); include_lcm('inc_keywords_default'); create_groups($system_keyword_groups); upgrade_db_version(10); } if ($lcm_db_version_current < 11) { write_metas(); // forgotten at last upgrade read_metas(); // make sure they are loaded global $system_kwg; $type_email = $system_kwg['contacts']['keywords']['email_main']['id_keyword']; $query = "UPDATE lcm_contact\n\t\t\t\t\tSET type_contact = {$type_email}\n\t\t\t\t\tWHERE type_contact = 1"; $result = lcm_query($query); upgrade_db_version(11); } // [ML] Was for db version 9, but it had a bug in the query // + added 'unknown' to the ENUM + set as default if ($lcm_db_version_current < 12) { lcm_query("ALTER TABLE lcm_client ADD gender ENUM('female', 'male', 'unknown') DEFAULT 'unknown' NOT NULL"); upgrade_db_version(12); } if ($lcm_db_version_current < 13) { lcm_query("CREATE TABLE lcm_report (\n\t\t\tid_report bigint(21) NOT NULL auto_increment,\n\t\t\ttitle varchar(255) NOT NULL default '',\n\t\t\tid_author bigint(21) NOT NULL default '0',\n\t\t\tdate_creation datetime NOT NULL default '0000-00-00 00:00:00',\n\t\t\tdate_update datetime NOT NULL default '0000-00-00 00:00:00',\n\t\t\tPRIMARY KEY (id_report),\n\t\t\tKEY id_author (id_author))"); lcm_query("CREATE TABLE lcm_fields (\n\t\t\tid_field bigint(21) NOT NULL auto_increment,\n\t\t\ttable_name varchar(255) NOT NULL default '',\n\t\t\tfield_name varchar(255) NOT NULL default '',\n\t\t\tdescription varchar(255) NOT NULL default '',\n\t\t\tPRIMARY KEY (id_field))"); lcm_query("REPLACE INTO lcm_fields VALUES (1, 'lcm_case', 'title', 'Case: Title'),\n\t\t\t\t\t\t\t\t\t\t\t(3, 'lcm_case', 'date_creation', 'Case: Creation date'),\n\t\t\t\t\t\t\t\t\t\t\t(4, 'lcm_case', 'date_assignment', 'Case: Assignment date'),\n\t\t\t\t\t\t\t\t\t\t\t(5, 'lcm_case', 'legal_reason', 'Case: Legal reason'),\n\t\t\t\t\t\t\t\t\t\t\t(6, 'lcm_case', 'alledged_crime', 'Case: Alleged crime'),\n\t\t\t\t\t\t\t\t\t\t\t(7, 'lcm_author', 'name_first', 'Author: First name'),\n\t\t\t\t\t\t\t\t\t\t\t(8, 'lcm_author', 'name_middle', 'Author: Middle name'),\n\t\t\t\t\t\t\t\t\t\t\t(9, 'lcm_author', 'name_last', 'Author: Last name'),\n\t\t\t\t\t\t\t\t\t\t\t(10, 'lcm_author', 'date_creation', 'Author: Date created'),\n\t\t\t\t\t\t\t\t\t\t\t(11, 'lcm_author', 'date_update', 'Author: Date updated')"); lcm_query("CREATE TABLE lcm_filter (\n\t\t\tid_filter bigint(21) NOT NULL auto_increment,\n\t\t\ttitle varchar(255) NOT NULL default '',\n\t\t\ttype enum('AND','OR') NOT NULL default 'AND',\n\t\t\tid_author bigint(21) NOT NULL default '0',\n\t\t\tdate_creation datetime NOT NULL default '0000-00-00 00:00:00',\n\t\t\tdate_update datetime NOT NULL default '0000-00-00 00:00:00',\n\t\t\tPRIMARY KEY (id_filter),\n\t\t\tKEY id_author (id_author))"); // [AG] Removed due to error in field name ('order') /* lcm_query("CREATE TABLE lcm_rep_cols ( id_column bigint(21) NOT NULL auto_increment, id_report bigint(21) NOT NULL default '0', id_field bigint(21) NOT NULL default '0', order bigint(21) NOT NULL default '0', header varchar(255) NOT NULL default '', sort enum('asc','desc') default NULL, total tinyint(1) NOT NULL default '0', group enum('COUNT','SUM') default NULL, PRIMARY KEY (id_column), KEY id_report (id_report), KEY id_field (id_field), KEY order (order))"); */ lcm_query("CREATE TABLE lcm_rep_filters (\n\t\t\tid_report bigint(21) NOT NULL default '0',\n\t\t\tid_filter bigint(21) NOT NULL default '0',\n\t\t\ttype enum('AND','OR') NOT NULL default 'AND',\n\t\t\tKEY id_report (id_report),\n\t\t\tKEY id_filter (id_filter))"); // [AG] Removed due to error in field name ('order') /* lcm_query("CREATE TABLE lcm_filter_conds ( id_filter bigint(21) NOT NULL default '0', id_field bigint(21) NOT NULL default '0', order bigint(21) NOT NULL default '0', type tinyint(2) NOT NULL default '0', value varchar(255) default NULL, KEY id_filter (id_filter), KEY id_field (id_field), KEY order (order))"); */ upgrade_db_version(13); } if ($lcm_db_version_current < 14) { lcm_query("CREATE TABLE lcm_rep_cols (\n\t\t\tid_column bigint(21) NOT NULL auto_increment,\n\t\t\tid_report bigint(21) NOT NULL default '0',\n\t\t\tid_field bigint(21) NOT NULL default '0',\n\t\t\tcol_order bigint(21) NOT NULL default '0',\n\t\t\theader varchar(255) NOT NULL default '',\n\t\t\tsort enum('asc','desc') default NULL,\n\t\t\ttotal tinyint(1) NOT NULL default '0',\n\t\t\tcol_group enum('COUNT','SUM') default NULL,\n\t\t\tPRIMARY KEY (id_column),\n\t\t\tKEY id_report (id_report),\n\t\t\tKEY id_field (id_field),\n\t\t\tKEY col_order (col_order))"); lcm_query("CREATE TABLE lcm_filter_conds (\n\t\t\tid_filter bigint(21) NOT NULL default '0',\n\t\t\tid_field bigint(21) NOT NULL default '0',\n\t\t\tcond_order bigint(21) NOT NULL default '0',\n\t\t\ttype tinyint(2) NOT NULL default '0',\n\t\t\tvalue varchar(255) default NULL,\n\t\t\tKEY id_filter (id_filter),\n\t\t\tKEY id_field (id_field),\n\t\t\tKEY cond_order (cond_order))"); upgrade_db_version(14); } // [ML] 15 + 16 had bugs, corrected below if ($lcm_db_version_current < 17) { lcm_query("ALTER TABLE lcm_followup CHANGE type type ENUM('assignment','suspension','resumption','delay','conclusion','reopening','merge','consultation','correspondance','travel','other') DEFAULT 'assignment' NOT NULL"); lcm_query("ALTER TABLE lcm_followup ADD id_author bigint(21) DEFAULT '0' NOT NULL AFTER id_case"); lcm_query("ALTER TABLE lcm_followup ADD INDEX id_author (id_author)"); upgrade_db_version(17); } if ($lcm_db_version_current < 18) { lcm_query("ALTER TABLE lcm_report\n\t\t\t\tADD description text NOT NULL,\n\t\t\t\tADD line_src_type text NOT NULL,\n\t\t\t\tADD line_src_name text NOT NULL,\n\t\t\t\tADD col_src_type text NOT NULL,\n\t\t\t\tADD col_src_name text NOT NULL "); lcm_query("CREATE TABLE lcm_rep_line (\n\t\t\t\tid_line bigint(21) NOT NULL auto_increment,\n\t\t\t\tid_report bigint(21) NOT NULL DEFAULT 0,\n\t\t\t\tid_field bigint(21) NOT NULL DEFAULT 0,\n\t\t\t\tsort_type ENUM('asc', 'desc') DEFAULT NULL,\n\t\t\t\tcol_order bigint(21) NOT NULL DEFAULT 0,\n\t\t\t\ttotal tinyint(1) NOT NULL DEFAULT 0,\n\t\t\t\tPRIMARY KEY (id_line),\n\t\t\t\tKEY id_report (id_report),\n\t\t\t\tKEY id_field (id_field),\n\t\t\t\tKEY col_order (col_order))"); // [ML] I'm stubborn, and renaming this table to singular lcm_query("CREATE TABLE lcm_rep_col (\n\t\t\t\tid_column bigint(21) NOT NULL auto_increment,\n\t\t\t\tid_report bigint(21) NOT NULL default 0,\n\t\t\t\tid_field bigint(21) NOT NULL default 0,\n\t\t\t\tcol_order bigint(21) NOT NULL default 0,\n\t\t\t\theader varchar(255) NOT NULL default '',\n\t\t\t\tsort enum('asc','desc') default NULL,\n\t\t\t\ttotal tinyint(1) NOT NULL default 0,\n\t\t\t\tcol_group enum('COUNT','SUM') default NULL,\n\t\t\t\tPRIMARY KEY (id_column),\n\t\t\t\tKEY id_report (id_report),\n\t\t\t\tKEY id_field (id_field),\n\t\t\t\tKEY col_order (col_order))"); lcm_query("INSERT INTO lcm_rep_col\n\t\t\t\t\tSELECT * FROM lcm_rep_cols"); lcm_query("drop table lcm_rep_cols"); lcm_query("ALTER TABLE lcm_fields\n\t\t\t\tADD enum_type text NOT NULL"); lcm_query("INSERT INTO lcm_fields (table_name, field_name, description, enum_type)\n\t\t\t\tVALUES\n\t\t\t\t\t('lcm_case', 'count(*)', 'COUNT(*)', ''),\n\t\t\t\t\t('lcm_author', 'count(*)', 'COUNT(*)', ''),\n\t\t\t\t\t('lcm_author', 'id_author', 'Author: ID', ''),\n\t\t\t\t\t('lcm_case', 'id_case', 'Case: ID', ''),\n\t\t\t\t\t('lcm_followup', 'type', 'Activities: Type', 'keyword:system_kwg:followups'),\n\t\t\t\t\t('lcm_followup', 'date_start', 'Activities: Date start', ''),\n\t\t\t\t\t('lcm_followup', 'date_end', 'Activities: Date end', ''),\n\t\t\t\t\t('lcm_followup', 'date_end - date_start', 'Activities: Time spent', ''),\n\t\t\t\t\t('lcm_followup', 'id_followup', 'Activities: ID', '')"); upgrade_db_version(18); } if ($lcm_db_version_current < 19) { lcm_query("CREATE TABLE lcm_rep_filter (\n\t\t\tid_filter bigint(21) NOT NULL auto_increment,\n\t\t\tid_report bigint(21) NOT NULL default 0,\n\t\t\tid_field bigint(21) NOT NULL default 0,\n\t\t\ttype varchar(255) NOT NULL default '',\n\t\t\tvalue varchar(255) NOT NULL default '',\n\t\t\tKEY id_report (id_report),\n\t\t\tKEY id_field (id_field),\n\t\t\tPRIMARY KEY (id_filter))"); lcm_query("ALTER TABLE lcm_fields\n\t\t\tADD filter ENUM('none', 'date', 'number', 'text') NOT NULL DEFAULT 'none'"); upgrade_db_version(19); } if ($lcm_db_version_current < 20) { // [ML] Sorry for the brutality lcm_query("DELETE FROM lcm_fields"); lcm_query("INSERT INTO lcm_fields (table_name, field_name, description, enum_type, filter) VALUES\n\t\t\t\t('lcm_case', 'id_case', 'id_case', '', 'number'),\n\t\t\t\t('lcm_case', 'title', 'title', '', 'text'),\n\t\t\t\t('lcm_case', 'date_creation', 'date_creation', '', 'date'),\n\t\t\t\t('lcm_case', 'date_assignment', 'date_assignment', '', 'date'),\n\t\t\t\t('lcm_case', 'legal_reason', 'legal_reason', '', 'none'),\n\t\t\t\t('lcm_case', 'alledged_crime', 'alleged_crime', '', 'none'),\n\t\t\t\t('lcm_case', 'count(*)', 'count', '', 'number'),\n\t\t\t\t('lcm_author', 'id_author', 'id_author', '', 'number'),\n\t\t\t\t('lcm_author', 'id_office', 'id_office', '', 'number'),\n\t\t\t\t('lcm_author', 'name_first', 'name_first', '', 'text'),\n\t\t\t\t('lcm_author', 'name_middle', 'name_middle', '', 'text'),\n\t\t\t\t('lcm_author', 'name_last', 'name_last', '', 'text'),\n\t\t\t\t('lcm_author', 'date_creation', 'date_creation', '', 'date'),\n\t\t\t\t('lcm_author', 'status', 'status', '', 'text'),\n\t\t\t\t('lcm_author', 'count(*)', 'count', '', 'number'),\n\t\t\t\t('lcm_client', 'id_client', 'id_client', '', 'number'),\n\t\t\t\t('lcm_client', 'name_first', 'name_first', '', 'text'),\n\t\t\t\t('lcm_client', 'name_middle', 'name_middle', '', 'text'),\n\t\t\t\t('lcm_client', 'name_last', 'name_last', '', 'text'),\n\t\t\t\t('lcm_client', 'date_creation', 'date_creation', '', 'date'),\n\t\t\t\t('lcm_client', 'citizen_number', 'citizen_number', '', 'text'),\n\t\t\t\t('lcm_client', 'civil_status', 'civil_status', 'keyword:system_kwg:civilstatus', 'number'),\n\t\t\t\t('lcm_client', 'income', 'income', 'keyword:system_kwg:income', 'number'),\n\t\t\t\t('lcm_client', 'gender', 'gender', 'list:female,male,unknown', 'text'),\n\t\t\t\t('lcm_followup', 'id_followup', 'id_followup', '', 'number'),\n\t\t\t\t('lcm_followup', 'id_case', 'id_case', '', 'number'),\n\t\t\t\t('lcm_followup', 'id_author', 'id_author', '', 'number'),\n\t\t\t\t('lcm_followup', 'type', 'type', 'keyword:system_kwg:followups', 'number'),\n\t\t\t\t('lcm_followup', 'description', 'description', '', 'none'),\n\t\t\t\t('lcm_followup', 'sumbilled', 'sumbilled', '', 'number'),\n\t\t\t\t('lcm_followup', 'date_start', 'date_start', '', 'date'),\n\t\t\t\t('lcm_followup', 'date_end', 'date_end', '', 'date'),\n\t\t\t\t('lcm_followup', 'date_end - date_start', 'time_spent', '', 'number'),\n\t\t\t\t('lcm_followup', 'count(*)', 'count', '', 'none')"); upgrade_db_version(20); } if ($lcm_db_version_current < 21) { lcm_query("CREATE TABLE lcm_app (\n\t\t\tid_app bigint(21) NOT NULL auto_increment,\n\t\t\tid_case bigint(21) NOT NULL default '0',\n\t\t\tid_author bigint(21) NOT NULL default '0',\n\t\t\ttype varchar(255) NOT NULL default '',\n\t\t\ttitle varchar(255) NOT NULL default '',\n\t\t\tdescription text NOT NULL,\n\t\t\tstart_time datetime NOT NULL default '0000-00-00 00:00:00',\n\t\t\tend_time datetime NOT NULL default '0000-00-00 00:00:00',\n\t\t\treminder datetime NOT NULL default '0000-00-00 00:00:00',\n\t\t\tdate_creation datetime NOT NULL default '0000-00-00 00:00:00',\n\t\t\tdate_update datetime NOT NULL default '0000-00-00 00:00:00',\n\t\t\tPRIMARY KEY (id_app),\n\t\t\tKEY id_case (id_case),\n\t\t\tKEY id_author (id_author),\n\t\t\tKEY type (type),\n\t\t\tFULLTEXT KEY title (title),\n\t\t\tFULLTEXT KEY description (description))"); lcm_query("CREATE TABLE lcm_app_client_org (\n\t\t\tid_app bigint(21) NOT NULL default '0',\n\t\t\tid_client bigint(21) NOT NULL default '0',\n\t\t\tid_org bigint(21) NOT NULL default '0',\n\t\t\tKEY id_app (id_app,id_client,id_org))"); lcm_query("CREATE TABLE lcm_app_fu (\n\t\t\tid_app bigint(21) NOT NULL default '0',\n\t\t\tid_followup bigint(21) NOT NULL default '0',\n\t\t\trelation enum('parent','child') NOT NULL default 'parent',\n\t\t\tKEY id_app (id_app,id_followup))"); lcm_query("CREATE TABLE lcm_author_app (\n\t\t\tid_author bigint(21) NOT NULL default '0',\n\t\t\tid_app bigint(21) NOT NULL default '0',\n\t\t\tKEY id_author (id_author,id_app))"); upgrade_db_version(21); } if ($lcm_db_version_current < 22) { lcm_query("CREATE TABLE lcm_case_attachment (\n\t\t\t id_attachment bigint(21) NOT NULL auto_increment,\n\t\t\t id_case bigint(21) NOT NULL default '0',\n\t\t\t filename varchar(255) NOT NULL default '',\n\t\t\t type varchar(255) default NULL,\n\t\t\t size bigint(21) NOT NULL default '0',\n\t\t\t description text,\n\t\t\t content longblob NOT NULL,\n\t\t\t date_attached datetime NOT NULL default '0000-00-00 00:00:00',\n\t\t\t PRIMARY KEY (id_attachment),\n\t\t\t KEY id_case (id_case),\n\t\t\t KEY filename (filename),\n\t\t\t FULLTEXT KEY description (description))"); upgrade_db_version(22); } if ($lcm_db_version_current < 23) { // Clear duplicated table lines $tables = array('lcm_app_client_org' => 'id_app,id_client,id_org', 'lcm_app_fu' => 'id_app,id_followup', 'lcm_author_app' => 'id_author,id_app', 'lcm_case_client_org' => 'id_case,id_client,id_org', 'lcm_case_author' => 'id_case,id_author', 'lcm_client_org' => 'id_client,id_org', 'lcm_rep_filters' => 'id_report,id_filter', 'lcm_filter_conds' => 'id_filter,id_field,cond_order'); foreach ($tables as $k => $v) { $result = lcm_query("SELECT DISTINCT {$v},count(*) as copies FROM {$k} GROUP BY {$v}"); while ($row = lcm_fetch_array($result)) { if ($row['copies'] > 1) { $w = ''; foreach ($row as $rk => $rv) { if (!is_int($rk) && $rk != 'copies') { $w .= ($w ? ' AND ' : '') . "{$rk}={$rv}"; } } $q = "DELETE FROM {$k} WHERE {$w} LIMIT " . ($row['copies'] - 1); lcm_query($q); } } lcm_query("OPTIMIZE TABLE {$k}"); } // Create unique indexes lcm_query("ALTER TABLE lcm_app_client_org DROP INDEX id_app"); lcm_query("CREATE UNIQUE INDEX uniq ON lcm_app_client_org (id_app,id_client,id_org)"); lcm_query("ALTER TABLE lcm_app_fu DROP INDEX id_app"); lcm_query("CREATE UNIQUE INDEX uniq ON lcm_app_fu (id_app,id_followup)"); lcm_query("ALTER TABLE lcm_author_app DROP INDEX id_author"); lcm_query("CREATE UNIQUE INDEX uniq ON lcm_author_app (id_author,id_app)"); lcm_query("CREATE UNIQUE INDEX uniq ON lcm_case_client_org (id_case,id_client,id_org)"); lcm_query("CREATE UNIQUE INDEX uniq ON lcm_case_author (id_case,id_author)"); lcm_query("CREATE UNIQUE INDEX uniq ON lcm_client_org (id_client,id_org)"); lcm_query("CREATE UNIQUE INDEX uniq ON lcm_rep_filters (id_report,id_filter)"); lcm_query("CREATE UNIQUE INDEX uniq ON lcm_filter_conds (id_filter,id_field,cond_order)"); upgrade_db_version(23); } if ($lcm_db_version_current < 24) { // Name doesn't need to be 100% unique, but unique for a given group lcm_query("ALTER TABLE lcm_keyword DROP INDEX idx_kw_name"); lcm_query("CREATE UNIQUE INDEX idx_kw_name ON lcm_keyword (id_group, name)"); // Convert civil_status + income to varchar(255) for keywords // Users should not have been using this field, and if they have, the usage was wrong, sorry lcm_query("ALTER TABLE lcm_client CHANGE civil_status civil_status varchar(255) NOT NULL DEFAULT 'unknown'"); lcm_query("ALTER TABLE lcm_client CHANGE income income varchar(255) NOT NULL DEFAULT 'unknown'"); lcm_query("UPDATE lcm_client SET civil_status = 'unknown', income = 'unknown'"); // Convert follow-up type to varchar(255) so that we can use keywords // This should convert without problems. Knock on wood. lcm_query("ALTER TABLE lcm_followup CHANGE type type varchar(255) NOT NULL DEFAULT 'other'"); upgrade_db_version(24); } if ($lcm_db_version_current < 25) { // Add case stage lcm_query("ALTER TABLE lcm_case ADD stage VARCHAR(255) NOT NULL AFTER status"); upgrade_db_version(25); } if ($lcm_db_version_current < 26) { // Add case stage lcm_query("ALTER TABLE lcm_followup ADD case_stage VARCHAR(255) NOT NULL AFTER description"); upgrade_db_version(26); } if ($lcm_db_version_current < 27) { // Add client attachments table lcm_query("CREATE TABLE lcm_client_attachment (\n\t\t id_attachment bigint(21) NOT NULL auto_increment,\n\t\t id_client bigint(21) NOT NULL default '0',\n\t\t filename varchar(255) NOT NULL default '',\n\t\t type varchar(255) default NULL,\n\t\t size bigint(21) NOT NULL default '0',\n\t\t description text,\n\t\t content longblob NOT NULL,\n\t\t date_attached datetime NOT NULL default '0000-00-00 00:00:00',\n\t\t PRIMARY KEY (id_attachment),\n\t\t KEY id_client (id_client),\n\t\t KEY filename (filename),\n\t\t FULLTEXT KEY description (description))"); upgrade_db_version(27); } if ($lcm_db_version_current < 27) { // Add client attachments table lcm_query("CREATE TABLE lcm_client_attachment (\n\t\t id_attachment bigint(21) NOT NULL auto_increment,\n\t\t id_client bigint(21) NOT NULL default '0',\n\t\t filename varchar(255) NOT NULL default '',\n\t\t type varchar(255) default NULL,\n\t\t size bigint(21) NOT NULL default '0',\n\t\t description text,\n\t\t content longblob NOT NULL,\n\t\t date_attached datetime NOT NULL default '0000-00-00 00:00:00',\n\t\t PRIMARY KEY (id_attachment),\n\t\t KEY id_client (id_client),\n\t\t KEY filename (filename),\n\t\t FULLTEXT KEY description (description))"); upgrade_db_version(27); } if ($lcm_db_version_current < 28) { // Add client attachments table lcm_query("CREATE TABLE lcm_org_attachment (\n\t\t id_attachment bigint(21) NOT NULL auto_increment,\n\t\t id_org bigint(21) NOT NULL default '0',\n\t\t filename varchar(255) NOT NULL default '',\n\t\t type varchar(255) default NULL,\n\t\t size bigint(21) NOT NULL default '0',\n\t\t description text,\n\t\t content longblob NOT NULL,\n\t\t date_attached datetime NOT NULL default '0000-00-00 00:00:00',\n\t\t PRIMARY KEY (id_attachment),\n\t\t KEY id_org (id_org),\n\t\t KEY filename (filename),\n\t\t FULLTEXT KEY description (description))"); upgrade_db_version(28); } if ($lcm_db_version_current < 29) { lcm_query("CREATE TABLE lcm_keyword_case (\n\t\t\tid_entry bigint(21) NOT NULL auto_increment,\n\t\t\tid_case bigint(21) NOT NULL default '0',\n\t\t\tPRIMARY KEY (id_entry),\n\t\t\tKEY id_case (id_case))"); lcm_query("CREATE TABLE lcm_keyword_client (\n\t\t\tid_entry bigint(21) NOT NULL auto_increment,\n\t\t\tid_keyword bigint(21) NOT NULL default '0',\n\t\t\tid_client bigint(21) NOT NULL default '0',\n\t\t\tPRIMARY KEY (id_entry),\n\t\t\tKEY id_client (id_client))"); lcm_query("CREATE TABLE lcm_keyword_org (\n\t\t\tid_entry bigint(21) NOT NULL auto_increment,\n\t\t\tid_keyword bigint(21) NOT NULL default '0',\n\t\t\tid_org bigint(21) NOT NULL default '0',\n\t\t\tPRIMARY KEY (id_entry),\n\t\t\tKEY id_org (id_org))"); lcm_query("ALTER TABLE lcm_case ADD notes text NOT NULL AFTER alledged_crime"); lcm_query("ALTER TABLE lcm_client ADD notes text NOT NULL"); lcm_query("ALTER TABLE lcm_org \n\t\t\t\t\t\tADD notes text NOT NULL,\n\t\t\t\t\t\tADD court_reg text NOT NULL,\n\t\t\t\t\t\tADD tax_number text NOT NULL,\n\t\t\t\t\t\tADD stat_number text NOT NULL"); // Remove lcm_client.address = lcm_org.address and move to lcm_contacts // If no one complains, we can remove the fields at the next upgrade include_lcm('inc_contacts'); $id_address = get_contact_type_id('address_main'); lcm_query("INSERT INTO lcm_contact (type_person, id_of_person, value, type_contact)\n\t\t\t\tSELECT 'client', id_client, address, " . $id_address . " \n\t\t\t\t\tFROM lcm_client\n\t\t\t\t\tWHERE (address IS NOT NULL AND address != '')"); lcm_query("INSERT INTO lcm_contact (type_person, id_of_person, value, type_contact)\n\t\t\t\tSELECT 'org', id_org, address, " . $id_address . " \n\t\t\t\t\tFROM lcm_org\n\t\t\t\t\tWHERE (address IS NOT NULL AND address != '')"); upgrade_db_version(29); } if ($lcm_db_version_current < 30) { lcm_query("ALTER TABLE lcm_keyword_group\n\t\t\tCHANGE type type ENUM('system','case','followup','client','org','client_org','author')"); // in version 29, the id_entry + key was missing lcm_query("ALTER TABLE lcm_keyword_case\n\t\t\tADD id_keyword bigint(21) NOT NULL default '0' AFTER id_entry,\n\t\t\tADD KEY id_keyword (id_keyword)"); lcm_query("ALTER TABLE lcm_keyword_client ADD KEY id_keyword (id_keyword)"); lcm_query("ALTER TABLE lcm_keyword_org ADD KEY id_keyword (id_keyword)"); upgrade_db_version(30); } if ($lcm_db_version_current < 31) { lcm_query("ALTER TABLE lcm_client DROP address"); lcm_query("ALTER TABLE lcm_org DROP address"); // [AG] Adding id_author, date_removed and index to attached documents lcm_query("ALTER TABLE lcm_case_attachment\tADD id_author BIGINT(21) NOT NULL AFTER id_case,\n\t\t\t\t\t\t\t\tCHANGE content content LONGBLOB DEFAULT NULL,\n\t\t\t\t\t\t\t\tADD date_removed DATETIME NOT NULL,\n\t\t\t\t\t\t\t\tADD INDEX (id_author)"); lcm_query("ALTER TABLE lcm_client_attachment\tADD id_author BIGINT(21) NOT NULL AFTER id_client,\n\t\t\t\t\t\t\t\tCHANGE content content LONGBLOB DEFAULT NULL,\n\t\t\t\t\t\t\t\tADD date_removed DATETIME NOT NULL,\n\t\t\t\t\t\t\t\tADD INDEX (id_author)"); lcm_query("ALTER TABLE lcm_org_attachment\tADD id_author BIGINT(21) NOT NULL AFTER id_org,\n\t\t\t\t\t\t\t\tCHANGE content content LONGBLOB DEFAULT NULL,\n\t\t\t\t\t\t\t\tADD date_removed DATETIME NOT NULL,\n\t\t\t\t\t\t\t\tADD INDEX (id_author)"); upgrade_db_version(31); } if ($lcm_db_version_current < 32) { // [AG] Expanding author preferences field to fit all data lcm_query("ALTER TABLE lcm_author CHANGE prefs prefs text NOT NULL"); upgrade_db_version(32); } if ($lcm_db_version_current < 33) { lcm_query("ALTER TABLE lcm_keyword_case\n\t\t\t\t\tADD id_stage bigint(21) not null default 0 AFTER id_case,\n\t\t\t\t\tADD value text not null"); upgrade_db_version(33); } if ($lcm_db_version_current < 34) { // Add 'stage' type lcm_query("ALTER TABLE lcm_keyword_group\n\t\t\t\t\tCHANGE type type ENUM('system','case','stage','followup','client','org','client_org','author')"); // Used for stage court archives numbers lcm_query("ALTER TABLE lcm_keyword\n\t\t\t\t\tADD hasvalue ENUM('Y', 'N') NOT NULL DEFAULT 'N' AFTER description"); upgrade_db_version(34); } if ($lcm_db_version_current < 35) { lcm_query("ALTER TABLE lcm_fields CHANGE filter filter text NOT NULL"); include_lcm('inc_repfields_defaults'); $fields = get_default_repfields(); create_repfields($fields); upgrade_db_version(35); } if ($lcm_db_version_current < 36) { lcm_query("ALTER TABLE lcm_report ADD notes text NOT NULL AFTER description"); upgrade_db_version(36); } if ($lcm_db_version_current < 37) { // Converts the lcm_case.id_court_archive into 'court archive' keywords // for the latest 'stage' of the case (if there is a court archive). lcm_query("INSERT INTO lcm_keyword_case (id_keyword, id_case, id_stage, value)\n\t\t\tSELECT kk.id_keyword as kw_court_archive,\n\t\t\t\tc.id_case, k.id_keyword as id_stage, \n\t\t\t\tc.id_court_archive \n\t\t\tFROM lcm_case as c, lcm_keyword as k \n\t\t\tLEFT JOIN lcm_keyword as kk ON (kk.name = 'courtarchive')\n\t\t\tWHERE id_court_archive != '' AND k.name = c.stage AND c.stage != '' "); upgrade_db_version(37); } if ($lcm_db_version_current < 38) { lcm_query("CREATE TABLE lcm_stage (\n\t\t\tid_entry bigint(21) NOT NULL auto_increment,\n\t\t\tid_case bigint(21) DEFAULT 0 NOT NULL,\n\t\t\tkw_case_stage varchar(255) NOT NULL DEFAULT '',\n\t\t\tdate_creation datetime DEFAULT '0000-00-00 00:00:00' NOT NULL,\n\t\t\tid_fu_creation bigint(21) NOT NULL DEFAULT 0,\n\t\t\tdate_conclusion datetime DEFAULT '0000-00-00 00:00:00' NOT NULL,\n\t\t\tid_fu_conclusion bigint(21) NOT NULL DEFAULT 0,\n\t\t\tkw_result varchar(255) NOT NULL DEFAULT '',\n\t\t\tkw_conclusion varchar(255) NOT NULL DEFAULT '',\n\t\t\tkw_sentence varchar(255) NOT NULL DEFAULT '',\n\t\t\tsentence_val text NOT NULL,\n\t\t\tdate_agreement datetime DEFAULT '0000-00-00 00:00:00' NOT NULL,\n\t\t\tlatest tinyint(1) DEFAULT '0' NOT NULL,\n\t\t\tPRIMARY KEY (id_entry),\n\t\t\tKEY id_case (id_case))"); lcm_query("CREATE UNIQUE INDEX idx_case_stage ON lcm_stage (id_case, kw_case_stage)"); // Populate table based on lcm_followup // case stage creation (use one followup per stage) lcm_query("INSERT INTO lcm_stage (id_case, kw_case_stage, date_creation, id_fu_creation, latest)\n\t\t\t\tSELECT c.id_case, fu.case_stage, fu.date_start, fu.id_followup, 0\n\t\t\t\tFROM lcm_case as c, lcm_followup as fu \n\t\t\t\tWHERE c.id_case = fu.id_case\n\t\t\t\t AND fu.case_stage != '' \n\t\t\t\tGROUP BY c.id_case, fu.case_stage\n\t\t\t\tORDER BY fu.date_start ASC"); $q = "SELECT *\n\t\t\t\tFROM lcm_followup\n\t\t\t\tWHERE type = 'conclusion'\n\t\t\t\t OR type = 'case_change'"; $result = lcm_query($q); while ($row = lcm_fetch_array($result)) { $tmp = lcm_unserialize($row['description']); $q = "UPDATE lcm_stage SET\n\t\t\t\t\tdate_conclusion = '" . $row['date_start'] . "',\n\t\t\t\t\tid_fu_conclusion = " . $row['id_followup'] . ",\n\t\t\t\t\tkw_result = '" . $tmp['result'] . "',\n\t\t\t\t\tkw_conclusion = '" . $tmp['conclusion'] . "',\n\t\t\t\t\tkw_sentence = '" . $tmp['sentence'] . "',\n\t\t\t\t\tsentence_val = '" . $tmp['sentence_val'] . "',\n\t\t\t\t\tdate_agreement = '" . $row['date_start'] . "'\n\t\t\t\t WHERE id_case = " . $row['id_case'] . "\n\t\t\t\t AND kw_case_stage = '" . $row['case_stage'] . "'"; lcm_query($q); } upgrade_db_version(38); } if ($lcm_db_version_current < 39) { lcm_query("ALTER TABLE lcm_followup\n\t\t\t\t\tADD hidden ENUM('N', 'Y') not null default 'N' AFTER sumbilled"); upgrade_db_version(39); } // [ML] Yes, quite awful, I know, but LCM 0.6.4 had problems.. function lcm_db_40_refresh_case_update() { $server_info = lcm_sql_server_info(); // [ML] This won't work on MySQL 3.23 .. nor 4.0 (?!) if (preg_match('/^MySQL/', $server_info) && !preg_match('/^MySQL 3\\./', $server_info) && !preg_match('/^MySQL 4\\.0/', $server_info)) { lcm_query("UPDATE lcm_case \n\t\t\t\t\t\tSET date_update = (SELECT max(fu.date_start) \n\t\t\t\t\t\t\t\t\t\tFROM lcm_followup as fu \n\t\t\t\t\t\t\t\t\t\tWHERE lcm_case.id_case = fu.id_case\n\t\t\t\t\t\t\t\t\t\tGROUP BY fu.id_case)", true); } else { // [ML] Probably not the best idea.. but brain-dead mysql // incompatibilities are driving me crazy.. // // Note: using the join to exclude non-empty dates allows to // continue/re-run the upgrade if it makes a time-out. $result = lcm_query("SELECT c.id_case, MAX(fu.date_start) as date\n\t\t\t\t\t\t\t\tFROM lcm_followup as fu, lcm_case as c\n\t\t\t\t\t\t\t\tWHERE fu.id_case = c.id_case\n\t\t\t\t\t\t\t\t AND c.date_update != '0000-00-00 00:00:00'\n\t\t\t\t\t\t\t\tGROUP BY fu.id_case\n\t\t\t\t\t\t\t\tORDER BY fu.id_case ASC"); while ($row = lcm_fetch_array($result)) { lcm_query("UPDATE lcm_case\n\t\t\t\t\t\t\tSET date_update = '" . $row['date'] . "'\n\t\t\t\t\t\t\tWHERE id_case = " . $row['id_case']); } } } if ($lcm_db_version_current < 40) { lcm_query("ALTER TABLE lcm_case\n\t\t\t\t\tADD date_update datetime DEFAULT '0000-00-00 00:00:00' NOT NULL AFTER date_assignment", true); lcm_query("UPDATE lcm_case\n\t\t\t\t\tSET date_update = date_assignment", true); lcm_db_40_refresh_case_update(); upgrade_db_version(40); } if ($lcm_db_version_current < 41) { // Clients would get a "" (empty) field if revenue and civil_status field // were left blank. LCM would then lcm_panic() when the fields are activated. lcm_query("UPDATE lcm_client\n\t\t\t\t\tSET civil_status = 'unknown'\n\t\t\t\t\tWHERE civil_status = ''"); lcm_query("UPDATE lcm_client\n\t\t\t\t\tSET income = 'unknown'\n\t\t\t\t\tWHERE income = ''"); // Altough "gender enum('female', 'male', 'unknown') DEFAULT 'unknown'" // was added in lcm_db_version = 12, it was left "DEFAULT 'male'" in the // inc_db_create.php until now. The result is that installations that // do not activate their "gender" field get clients that are all male. lcm_query("ALTER TABLE lcm_client \n\t\t\t\t\tCHANGE gender gender enum('female', 'male', 'unknown') \n\t\t\t\t\tDEFAULT 'unknown' NOT NULL"); // Therefore, the following "UPDATE" will not fix much, users will have // to manually fix their client data, but just in case.. lcm_query("UPDATE lcm_client\n\t\t\t\t\tSET gender = 'unknown'\n\t\t\t\t\tWHERE gender = ''"); upgrade_db_version(41); } if ($lcm_db_version_current < 42) { // This has been deprecated for some time lcm_query("DELETE FROM lcm_fields WHERE table_name = 'lcm_case' AND field_name = 'id_court_archive'"); lcm_db_40_refresh_case_update(); // for 0.6.4a release upgrade_db_version(42); } // LCM 0.7.0 if ($lcm_db_version_current < 43) { lcm_query("ALTER TABLE lcm_keyword_client\n\t\t\t\t\tADD value text NOT NULL"); lcm_query("ALTER TABLE lcm_keyword_org\n\t\t\t\t\tADD value text NOT NULL"); upgrade_db_version(43); } if ($lcm_db_version_current < 44) { // Values which were previously 'yes' become 'yes_optional' // because that's how they were processed in previous versions $upd_metas = array('client_name_middle', 'client_citizen_number', 'client_civil_status', 'client_income', 'case_alledged_crime', 'case_legal_reason'); foreach ($upd_metas as $m) { lcm_query("UPDATE lcm_meta\n\t\t\t\t\t\tSET value = 'yes_optional'\n\t\t\t\t\t\tWHERE value = 'yes' AND name = '{$m}'"); } $fields = array("id_expense bigint(21) NOT NULL auto_increment", "id_case bigint(21) NOT NULL DEFAULT 0", "id_followup bigint(21) NOT NULL DEFAULT 0", "id_author bigint(21) NOT NULL", "id_admin bigint(21) NOT NULL DEFAULT 0", "status ENUM('pending', 'granted', 'refused', 'deleted') NOT NULL", "type varchar(255) NOT NULL", "cost decimal(19,4) NOT NULL DEFAULT 0", "description text NOT NULL", "date_creation datetime NOT NULL", "date_update datetime NOT NULL", "pub_read tinyint(1) NOT NULL", "pub_write tinyint(1) NOT NULL", "PRIMARY KEY (id_expense)"); $keys = array("id_case" => "id_case", "id_author" => "id_author"); // If user installs LCM 0.7.0, then imports a 0.6.4 database, the // lcm_expense table will already exist. It is better to drop and // re-create because we may "ALTER" the table later. On the other // hand, there is a risk that we accidently drop a table with data. lcm_query("DROP TABLE lcm_expense", true); lcm_query_create_table("lcm_expense", $fields, $keys); $fields = array("id_comment bigint(21) NOT NULL auto_increment", "id_expense bigint(21) NOT NULL", "id_author bigint(21) NOT NULL", "date_creation datetime NOT NULL", "date_update datetime NOT NULL", "comment text NOT NULL", "PRIMARY KEY (id_comment)"); lcm_query("DROP TABLE lcm_expense_comment", true); lcm_query_create_table("lcm_expense_comment", $fields); upgrade_db_version(44); } if ($lcm_db_version_current < 45) { lcm_query("ALTER TABLE lcm_report\n\t\t\t\t\tADD filecustom text NOT NULL"); upgrade_db_version(45); } // This should have been done a long time ago! if ($lcm_db_version_current < 46) { lcm_query("ALTER TABLE lcm_fields\n\t\t\tCHANGE filter filter ENUM('none','date','number','text','currency') NOT NULL DEFAULT 'none'"); upgrade_db_version(46); } if ($lcm_db_version_current < 47) { lcm_query("ALTER TABLE lcm_keyword_group\n\t\t\tADD id_parent bigint(21) NOT NULL DEFAULT 0 AFTER id_group"); upgrade_db_version(47); } if ($lcm_db_version_current < 48) { lcm_query("ALTER TABLE lcm_client\n\t\t\tADD date_birth datetime NULL AFTER date_update"); upgrade_db_version(48); } if ($lcm_db_version_current < 49) { // If user installs LCM 0.7.0, then imports a 0.6.4 database, the // lcm_expense table will already exist. It is better to drop and // re-create because we may "ALTER" the table later. On the other // hand, there is a risk that we accidently drop a table with data. lcm_query("DROP TABLE lcm_keyword_followup", true); $fields = array("id_entry bigint(21) NOT NULL auto_increment", "id_keyword bigint(21) NOT NULL default 0", "id_followup bigint(21) NOT NULL default 0", "value text NOT NULL", "PRIMARY KEY (id_entry)"); $keys = array('id_keyword' => 'id_keyword', 'id_followup' => 'id_followup'); lcm_query_create_table('lcm_keyword_followup', $fields, $keys); upgrade_db_version(49); } if ($lcm_db_version_current < 50) { lcm_query("ALTER TABLE lcm_stage\n\t\t\tCHANGE date_creation date_creation datetime NOT NULL,\n\t\t\tCHANGE date_conclusion date_conclusion datetime DEFAULT NULL,\n\t\t\tCHANGE date_agreement date_agreement datetime DEFAULT NULL"); lcm_query("ALTER TABLE lcm_case_attachment\n\t\t\tCHANGE date_removed date_removed datetime default NULL"); lcm_query("ALTER TABLE lcm_client_attachment\n\t\t\tCHANGE date_removed date_removed datetime default NULL"); lcm_query("ALTER TABLE lcm_org_attachment\n\t\t\tCHANGE date_removed date_removed datetime default NULL"); lcm_query("ALTER TABLE lcm_followup\n\t\t\tCHANGE date_end date_end datetime default NULL"); lcm_query("ALTER TABLE lcm_app\n\t\t\tCHANGE reminder reminder datetime default NULL"); upgrade_db_version(50); } if ($lcm_db_version_current < 51) { // // Contacts keywords now become lcm_keyword_group instead of lcm_keyword // so that we can decide whether they are mandatory/sugg/opt, etc. // lcm_query("ALTER TABLE lcm_keyword_group\n\t\t\tCHANGE type type ENUM('system', 'contact', 'case', 'stage', 'followup', 'client', 'org', 'client_org', 'author') NOT NULL"); lcm_query("ALTER TABLE lcm_contact\n\t\t\tADD date_update datetime default NULL", true); // [ML] Intentionally not using inc_keywords.php functions, so that it // is more error resistant (i.e. to avoid lcm_panic if there is an error). $result = lcm_query("SELECT id_group FROM lcm_keyword_group WHERE name = 'contacts'"); if ($row0 = lcm_fetch_array($result)) { $id_group = $row0['id_group']; lcm_log("UPGRADE: Found kwg = {$id_group}"); lcm_query("INSERT INTO lcm_keyword_group \n\t\t\t\t(name, title, description, type, policy, quantity, suggest, ac_admin, ac_author)\n\t\t\t\tSELECT CONCAT('+', name), title, description, 'contact', 'optional', 'many', 'none', 'Y', ac_author\n\t\t\t\t FROM lcm_keyword\n\t\t\t\t WHERE id_group = {$id_group}"); lcm_log("UPGRADE: added a few new groups."); // Create table to convert IDs in lcm_contact // Note: we use the date_update to know whether an entry has been // update already (in case the upgrade has a runtime timeout) // but we then later set it to null afterwards, because on existing // entries, we don't really know when it was last updated // (will show 'unknown' in interface) $table_kw1 = array(); $result1 = lcm_query("SELECT id_keyword, name FROM lcm_keyword WHERE id_group = {$id_group}"); while ($row1 = lcm_fetch_array($result1)) { $table_kw1[$row1['id_keyword']] = '+' . $row1['name']; lcm_log("UPGRADE: load old kw .. " . $row1['id_keyword'] . " = " . $row1['name']); } $table_kw2 = array(); $result2 = lcm_query("SELECT id_group, name FROM lcm_keyword_group WHERE type = 'contact'"); while ($row2 = lcm_fetch_array($result2)) { $table_kw2[$row2['name']] = $row2['id_group']; lcm_log("UPGRADE: load new kwg .. " . $row2['id_group'] . " = " . $row2['name']); } $result3 = lcm_query("SELECT id_contact, type_contact, value\n\t\t\t\t\t\t\tFROM lcm_contact " . "\n\t\t\t\t\t\t\tORDER BY id_contact ASC"); while ($row3 = lcm_fetch_array($result3)) { lcm_log("UPGRADE: contact id " . $row3['id_contact'] . " type: " . $row3['type_contact'] . " value: " . $row3['value'] . " ->> " . $table_kw2[$table_kw1[$row3['type_contact']]]); if ($table_kw2[$table_kw1[$row3['type_contact']]]) { lcm_query("UPDATE lcm_contact\n\t\t\t\t\t\t\t\tSET type_contact = " . $table_kw2[$table_kw1[$row3['type_contact']]] . ",\n\t\t\t\t\t\t\t\t date_update = NOW()\n\t\t\t\t\t\t\t\tWHERE id_contact = " . $row3['id_contact']); } else { lcm_log("UPGRADE: contact ignored."); } } lcm_query("DELETE FROM lcm_keyword\n\t\t\t\t\t\tWHERE id_group = {$id_group}"); } else { lcm_log("WARNING: Could not find contact group in lcm_keyword_group. " . "You may have to re-create your contacts manually. " . "Please e-mail legalcase-devel@lists.sf.net to warn us that this happened."); } lcm_query("UPDATE lcm_keyword_group\n\t\t\t\t\tSET policy = 'recommended'\n\t\t\t\t\tWHERE name IN ('+address_main', '+phone_home')"); upgrade_db_version(51); // Reset date_update on contacts, since we are finished with update, // and better to show 'unknown'. In the future, it will show the latest // date at which a given contact was updated. lcm_query("UPDATE lcm_contact SET date_update = NULL"); } if ($lcm_db_version_current < 52) { lcm_query("ALTER TABLE lcm_app\n\t\t\t\t\tADD hidden ENUM('N', 'Y') not null default 'N' AFTER date_update"); upgrade_db_version(52); } // // LCM 0.7.3 // if ($lcm_db_version_current < 53) { lcm_query("ALTER TABLE lcm_stage\n\t\t\t\t\t\tCHANGE sentence_val sentence_val text"); lcm_query("ALTER TABLE lcm_keyword_case\n\t\t\t\t\t\tCHANGE value value text"); upgrade_db_version(53); } if ($lcm_db_version_current < 54) { lcm_query("ALTER TABLE lcm_case\n\t\t\t\t\tADD id_stage bigint(21) NOT NULL AFTER id_case"); lcm_query("ALTER TABLE lcm_followup\n\t\t\t\t\tADD id_stage bigint(21) NOT NULL AFTER id_case"); // Populate id_stage in lcm_case // the "where" and "order" statements make it easier to recuperate // if the database has a very large number of cases $query = "SELECT c.id_case, c.stage, s.id_entry as id_stage\n\t\t\t\t\tFROM lcm_case as c\n\t\t\t\t\tLEFT JOIN lcm_stage as s ON (c.stage = s.kw_case_stage AND c.id_case = s.id_case)\n\t\t\t\t\tWHERE c.id_stage = 0 \n\t\t\t\t\tORDER by id_case asc"; $res = lcm_query($query); while ($row = lcm_fetch_array($res)) { // exception for very early versions of LCM if (!$row['id_stage']) { $row['id_stage'] = 0; } $upd = "UPDATE lcm_case\n\t\t\t\t\t SET id_stage = " . $row['id_stage'] . "\n\t\t\t\t\t WHERE id_case = " . $row['id_case']; lcm_query($upd); } // Populate id_stage in lcm_followup $query = "SELECT f.id_followup, f.id_case, f.case_stage, s.id_entry as id_stage\n\t\t\t\t\tFROM lcm_followup as f\n\t\t\t\t\tLEFT JOIN lcm_stage as s ON (f.case_stage = s.kw_case_stage AND f.id_case = s.id_case)\n\t\t\t\t\tWHERE f.id_stage = 0 \n\t\t\t\t\tORDER by id_followup asc"; $res = lcm_query($query); while ($row = lcm_fetch_array($res)) { // exception for very early versions of LCM if (!$row['id_stage']) { $row['id_stage'] = 0; } $upd = "UPDATE lcm_followup\n\t\t\t\t\t SET id_stage = " . $row['id_stage'] . "\n\t\t\t\t\t WHERE id_followup = " . $row['id_followup']; lcm_query($upd); } upgrade_db_version(54); } if ($lcm_db_version_current < 55) { include_lcm('inc_keywords'); // Fix id_stage entries in lcm_keyword_case // They use to have the id_keyword of the keyword associated to that stage // .. doesn't make much sense, should be the lcm_stage.id_entry $query = "SELECT id_entry as id_kw_entry, id_keyword, id_case, id_stage\n\t\t\t\t \tFROM lcm_keyword_case\n\t\t\t\t WHERE id_stage != 0\n\t\t\t\t ORDER BY id_entry ASC"; $result = lcm_query($query); while ($row = lcm_fetch_array($result)) { // get the keyword name associated with the id_keyword // so that we can get the lcm_stage.id_entry $kw = get_kw_from_id($row['id_stage']); $query2 = "SELECT id_entry\n\t\t\t\t\t\t FROM lcm_stage\n\t\t\t\t\t\tWHERE id_case = " . $row['id_case'] . "\n\t\t\t\t\t\t AND kw_case_stage = '" . $kw['name'] . "'"; $result2 = lcm_query($query2); if ($row2 = lcm_fetch_array($result2)) { $upd = "UPDATE lcm_keyword_case\n\t\t\t\t\t\t SET id_stage = " . $row2['id_entry'] . "\n\t\t\t\t\t\t WHERE id_entry = " . $row['id_kw_entry']; lcm_query($upd); } } upgrade_db_version(55); } if ($lcm_db_version_current < 56) { // should have been done a long time ago lcm_query("ALTER TABLE lcm_case\n\t\t\t\t\tDROP id_court_archive", true); upgrade_db_version(56); } if ($lcm_db_version_current < 57) { // should have been done a long time ago lcm_query("ALTER TABLE lcm_stage\n\t\t\t\t\tDROP key idx_case_stage"); upgrade_db_version(57); } // Update the meta, lcm_fields, keywords, etc. lcm_log("Updating LCM default configuration (meta/keywords/repfields/..)", 'upgrade'); upgrade_database_conf(); lcm_log("LCM database upgrade complete", 'upgrade'); return $log; }
if (isset($lang) and $lang != $lcm_lang) { // Boomerang via lcm_cookie to set a cookie and do all the dirty work // The REQUEST_URI should always be set, and point to the current page // we are being sent to (Ex: from config_author.php to listcases.php). // [ML] I used $lcm_lang because there are rare cases where the cookie // can disagree with $author_session['lang'] (e.g. login one user, set // cookie, logout, login other user, conflict). // [ML] Added $ref because some forms such as config_author.php expect it $ref = isset($_REQUEST['referer']) ? '&referer=' . urlencode($_REQUEST['referer']) : ''; header("Location: lcm_cookie.php?var_lang_lcm=" . $lang . "&url=" . urlencode($_SERVER['REQUEST_URI']) . $ref); exit; } // // Database version management // $installed_db_version = read_meta('lcm_db_version'); if ($installed_db_version < $lcm_db_version) { lcm_page_start(_T('title_upgrade_database')); echo "<div class='box_warning'>\n"; echo '<p class="normal_text"><b>' . _T('title_technical_message') . "</b> " . _T('info_upgrade_database1') . ' ' . '<a class="content_link" href="lcm_upgrade.php">' . _T('info_upgrade_database2') . "</a>" . "</p>"; echo "</div>\n"; echo "<!-- VERSION installed = {$installed_db_version} ; should be = {$lcm_db_version} -->\n"; lcm_log("Upgrade required: installed = {$installed_db_version}, should be = {$lcm_db_version}"); lcm_page_end(); exit; } // Fetch the administration cookie // [ML] Where is this used and why? :-) if (isset($_COOKIE['lcm_admin'])) { $cookie_admin = $_COOKIE['lcm_admin']; } else {
function filtrer_ical($texte) { include_lcm('inc_charsets'); $texte = html2unicode($texte); $texte = unicode2charset(charset2unicode($texte, read_meta('charset'), 1), 'utf-8'); $texte = preg_replace("/\n/", " ", $texte); $texte = preg_replace("/,/", "\\,", $texte); return $texte; }
$q = "SELECT\n\t\t\t\t\t\ta.id_author, name_first, name_middle, name_last,\n\t\t\t\t\t\tsum(IF(UNIX_TIMESTAMP(fu.date_end) > 0,\n\t\t\t\t\t\t\tUNIX_TIMESTAMP(fu.date_end)-UNIX_TIMESTAMP(fu.date_start), 0)) as time,\n\t\t\t\t\t\tsum(sumbilled) as sumbilled\n\t\t\t\t\tFROM lcm_author as a, lcm_followup as fu\n\t\t\t\t\tWHERE fu.id_author = a.id_author\n\t\t\t\t\t AND fu.id_case = {$case}\n\t\t\t\t\t AND fu.hidden = 'N'\n\t\t\t\t\tGROUP BY fu.id_author"; $result = lcm_query($q); // Show table headers echo '<fieldset class="info_box">'; show_page_subtitle(_T('case_subtitle_times'), 'reports_intro'); $link_details = new Link(); $link_details->addVar('more_times', intval(!$show_more_times)); echo "<table border='0' class='tbl_usr_dtl' width='99%'>\n"; echo "<tr>\n"; echo "<th class='heading'>" . _Th('case_input_author') . ' ' . '<a title="' . _T('fu_button_stats_' . ($show_more_times ? 'less' : 'more')) . '" href="' . $link_details->getUrl() . '">' . '<img src="images/spip/' . ($show_more_times ? 'moins' : 'plus') . '.gif" alt="" border="0" />' . '</a>' . "</th>\n"; echo "<th class='heading' width='120' nowrap='nowrap' align='right'>" . _Th('time_input_length') . ' (' . _T('time_info_short_hour') . ")</th>\n"; $total_time = 0; $total_sum_billed = 0.0; $meta_sum_billed = read_meta('fu_sum_billed'); if ($meta_sum_billed == 'yes') { $currency = read_meta('currency'); echo "<th class='heading' width='120' nowrap='nowrap' align='right'>" . _Th('fu_input_sum_billed') . ' (' . $currency . ")</th>\n"; } echo "</tr>\n"; // Show table contents & calculate total while ($row = lcm_fetch_array($result)) { $total_time += $row['time']; $total_sum_billed += $row['sumbilled']; echo "<tr><td>"; echo get_person_name($row); echo '</td><td align="right" valign="top">'; echo format_time_interval_prefs($row['time']); echo "</td>\n"; if ($meta_sum_billed == 'yes') { echo '<td align="right" valign="top">'; echo format_money($row['sumbilled']);
function printEdit() { // Read site configuration preferences $case_assignment_date = read_meta('case_assignment_date'); $case_alledged_crime = read_meta('case_alledged_crime'); $case_legal_reason = read_meta('case_legal_reason'); $case_allow_modif = read_meta('case_allow_modif'); echo '<table class="tbl_usr_dtl">' . "\n"; // Case ID (if editing existing case) if ($this->getDataInt('id_case')) { echo "<tr>" . "<td>" . _T('case_input_id') . "</td>" . "<td>" . $this->getDataInt('id_case') . '<input type="hidden" name="id_case" value="' . $this->getDataInt('id_case') . '" />' . "</td></tr>\n"; } echo '<tr><td><label for="input_case_title">' . f_err_star('title') . _T('case_input_title') . "</label></td>\n"; echo '<td><input size="35" name="title" id="input_case_title" value="' . clean_output($this->getDataString('title')) . '" class="search_form_txt" />'; echo "</td></tr>\n"; // Date of earlier assignment if ($case_assignment_date == 'yes') { echo "<tr>\n"; echo "<td>" . f_err_star('date_assignment') . _Ti('case_input_date_assigned') . "</td>\n"; echo "<td>" . get_date_inputs('assignment', $this->getDataString('date_assignment'), false) . "</td>\n"; echo "</tr>\n"; } // Legal reason if (substr($case_legal_reason, 0, 3) == 'yes') { echo '<tr><td><label for="input_legal_reason">' . f_err_star('legal_reason') . _T('case_input_legal_reason') . "</label>" . ($case_legal_reason == 'yes_mandatory' ? '<br/>(' . _T('keywords_input_policy_mandatory') . ')' : '') . "</td>\n"; echo '<td>'; echo '<textarea name="legal_reason" id="input_legal_reason" class="frm_tarea" rows="2" cols="60">'; echo clean_output($this->getDataString('legal_reason')); echo "</textarea>"; echo "</td>\n"; echo "</tr>\n"; } // Alledged crime if (substr($case_alledged_crime, 0, 3) == 'yes') { echo '<tr><td><label for="input_alledged_crime">' . f_err_star('alledged_crime') . _T('case_input_alledged_crime') . "</label>" . ($case_alledged_crime == 'yes_mandatory' ? '<br/>(' . _T('keywords_input_policy_mandatory') . ')' : '') . "</td>\n"; echo '<td>'; echo '<textarea name="alledged_crime" id="input_alledged_crime" class="frm_tarea" rows="2" cols="60">'; echo clean_output($this->getDataString('alledged_crime')); echo '</textarea>'; echo "</td>\n"; echo "</tr>\n"; } // Keywords (if any) show_edit_keywords_form('case', $this->getDataInt('id_case')); $id_stage = 0; // new case, stage not yet known if ($this->getDataString('stage')) { $stage = get_kw_from_name('stage', $this->getDataString('stage', '__ASSERT__')); $id_stage = $stage['id_keyword']; } show_edit_keywords_form('stage', $this->getDataInt('id_case'), $id_stage); // Notes echo "<tr>\n"; echo "<td><label for='input_case_notes'>" . f_err_star('case_notes') . _Ti('case_input_notes') . "</label></td>\n"; echo '<td><textarea name="case_notes" id="input_case_notes" class="frm_tarea" rows="3" cols="60">' . clean_output($this->getDataString('notes')) . "</textarea>\n" . "</td>\n"; echo "</tr>\n"; // Case status echo '<tr><td><label for="input_status">' . f_err_star('status') . _Ti('case_input_status') . "</label></td>\n"; echo '<td>'; echo '<select name="status" id="input_status" class="sel_frm">' . "\n"; $statuses = $this->getDataInt('id_case') ? array('draft', 'open', 'suspended', 'closed', 'merged') : array('draft', 'open'); foreach ($statuses as $s) { $sel = $s == $this->getDataString('status') ? ' selected="selected"' : ''; echo '<option value="' . $s . '"' . $sel . ">" . _T('case_status_option_' . $s) . "</option>\n"; } echo "</select></td>\n"; echo "</tr>\n"; // Case stage if (!$this->getDataString('stage')) { $this->data['stage'] = get_suggest_in_group_name('stage'); } $kws = get_keywords_in_group_name('stage'); echo '<tr><td><label for="input_stage">' . f_err_star('stage') . _T('case_input_stage') . "</label></td>\n"; echo '<td><select name="stage" id="input_stage" class="sel_frm">' . "\n"; foreach ($kws as $kw) { $sel = $kw['name'] == $this->data['stage'] ? ' selected="selected"' : ''; echo "\t\t\t\t<option value='" . $kw['name'] . "'" . "{$sel}>" . _T(remove_number_prefix($kw['title'])) . "</option>\n"; } echo "</select></td>\n"; echo "</tr>\n"; // Public access rights // FIXME FIXME FIXME if ($this->data['admin'] || read_meta('case_read_always') != 'yes' || read_meta('case_write_always') != 'yes') { $dis = isDisabled(!allowed($this->getDataInt('id_case'), 'a')); echo '<tr><td colspan="2">' . _T('case_input_collaboration') . ' <br /><ul>'; if (read_meta('case_read_always') != 'yes' || $GLOBALS['author_session']['status'] == 'admin') { echo '<li style="list-style-type: none;">'; echo '<input type="checkbox" name="public" id="case_public_read" value="yes"'; if ($_SESSION['form_data']['public']) { echo ' checked="checked"'; } echo "{$dis} />"; echo '<label for="case_public_read">' . _T('case_input_collaboration_read') . "</label></li>\n"; } if (read_meta('case_write_always') != 'yes' || _session('admin')) { echo '<li style="list-style-type: none;">'; echo '<input type="checkbox" name="pub_write" id="case_public_write" value="yes"'; if (_session('pub_write')) { echo ' checked="checked"'; } echo "{$dis} />"; echo '<label for="case_public_write">' . _T('case_input_collaboration_write') . "</label></li>\n"; } echo "</ul>\n"; echo "</td>\n"; echo "</tr>\n"; } echo "</table>\n"; }
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA $Id: edit_fu.php,v 1.116 2006/11/14 19:14:11 mlutfy Exp $ */ include 'inc/inc.php'; include_lcm('inc_acc'); include_lcm('inc_filters'); include_lcm('inc_obj_fu'); // Read the policy settings $fu_sum_billed = read_meta('fu_sum_billed'); $admin = $GLOBALS['author_session']['status'] == 'admin'; // Don't clear form data if comming back from upd_fu with errors if (!isset($_SESSION['form_data'])) { $_SESSION['form_data'] = array(); } // Set the returning page, usually, there should not be, therefore // it will send back to "fu_det.php?followup=NNN" after update. $_SESSION['form_data']['ref_edit_fu'] = _request('ref'); if (isset($_GET['followup'])) { $_SESSION['followup'] = intval($_GET['followup']); // Fetch the details on the specified follow-up $q = "SELECT *\n\t\t\tFROM lcm_followup as fu\n\t\t\tWHERE fu.id_followup=" . $_SESSION['followup']; $result = lcm_query($q); if (!($row = lcm_fetch_array($result))) { lcm_panic("Edit follow-up: invalid 'follow-up id': " . $_SESSION['followup']);
function show_all_contacts($type_person, $id_of_person) { global $author_session; $show_emails = !(read_meta('hide_emails') && $author_session['status'] != 'admin'); $contacts = get_contacts($type_person, $id_of_person); $html = ""; $i = 0; if (!count($contacts)) { return; } show_page_subtitle(_T('generic_subtitle_contacts')); echo '<table border="0" class="tbl_usr_dtl" width="100%">' . "\n"; foreach ($contacts as $c) { // Check if the contact is an e-mail echo "<tr>\n"; echo "<td class='tbl_cont_" . ($i % 2 ? "dark" : "light") . "'>" . _T($c['title']) . ":</td>\n"; echo "<td class='tbl_cont_" . ($i % 2 ? "dark" : "light") . "'>"; if ($show_emails && strpos($c['name'], 'email') === 0) { echo '<a href="mailto:' . $c['value'] . '" class="content_link">' . $c['value'] . '</a></td>\\n'; } else { echo "<td class='tbl_cont_" . ($i % 2 ? "dark" : "light") . "'>" . $c['value'] . "</td>\n"; } echo '<td class="tbl_cont_' . ($i % 2 ? 'dark' : 'light') . '">' . ($c['date_update'] != null ? format_date($c['date_update'], 'date_short') : '') . "</td>\n"; echo "</tr>\n"; $i++; } echo "</table>\n"; echo "<br />\n"; }