Example #1
0
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);
}
Example #2
0
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;
    }
}
Example #3
0
 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()&gt;=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
 }
Example #4
0
function typo($letexte)
{
    global $lcm_lang, $lang_typo;
    // escape <html>...</html> code, etc.
    list($letexte, $les_echap) = echappe_html($letexte, "SOURCETYPO");
    // Call the function for pre-processing
    $letexte = spip_avant_typo($letexte);
    if (!($lang = $lang_typo)) {
        include_lcm('inc_lang');
        $lang = lang_typo($lcm_lang);
    }
    if ($lang == 'fr') {
        $letexte = typo_fr($letexte);
    } else {
        $letexte = typo_en($letexte);
    }
    // Call the post-processing function
    $letexte = spip_apres_typo($letexte);
    // reintegrate the escaped text
    $letexte = echappe_retour($letexte, $les_echap, "SOURCETYPO");
    return $letexte;
}
Example #5
0
function menu_languages($select_name = 'var_lang_lcm', $default = '', $text = '', $herit = '')
{
    global $connect_id_auteur;
    $ret = '';
    if ($default == '') {
        $default = $GLOBALS['lcm_lang'];
    }
    if ($select_name == 'var_lang_lcm_all') {
        $languages = explode(',', $GLOBALS['all_langs']);
        // [ML] XXX because I need a normal var_lang_lcm, but with all
        // the languages, instead, the function parameters should be changed.
        $select_name = 'var_lang_lcm';
    } else {
        $languages = explode(',', read_meta('available_languages'));
    }
    // We do not offer a choice if there is only one language installed
    if (count($languages) <= 1) {
        return;
    }
    $lien = $GLOBALS['clean_link'];
    if ($select_name == 'var_lang_lcm') {
        include_lcm('inc_admin');
        $target = $lien->getUrl();
        if ($connect_id_auteur) {
            $post = "lcm_cookie.php?id_author={$connect_id_auteur}&amp;valeur=" . calculer_action_auteur('var_lang_lcm', $connect_id_auteur);
        } else {
            $post = "lcm_cookie.php";
        }
        $ret = "<form action='{$post}' method='post' style='margin:0px; padding:0px;'>";
        if ($target) {
            $ret .= "<input type='hidden' name='url' value='{$target}'/>";
        }
        if ($text) {
            $ret .= $text;
        }
        $style = "class='forml' style='vertical-align: top; max-height: 24px; margin-bottom: 5px; width: 120px;'";
        $postcomplet = new Link($post);
        if ($target) {
            $postcomplet->addvar('url', $target);
        }
        $ret .= "\n<select name='{$select_name}' {$style} onchange=\"document.location.href='" . $postcomplet->geturl() . "&amp;{$select_name}='+this.options[this.selectedIndex].value\">\n";
    } else {
        // XXX TODO FIXME
        // rename class 'forml' to 'form_lang' and adjust CSS
        $ret .= "\n<select class='sel_frm' name='{$select_name}'>\n";
    }
    sort($languages);
    while (list(, $l) = each($languages)) {
        if ($l == $default) {
            $selected = ' selected="selected"';
        } else {
            $selected = '';
        }
        if ($l == $herit) {
            $ret .= "<option class='maj-debut' style='font-weight: bold;' value='herit'{$selected}>" . translate_language_name($herit) . " (" . _T('info_multi_herit') . ")</option>\n";
        } else {
            $ret .= "<option class='maj-debut' value='{$l}'{$selected}>" . translate_language_name($l) . "</option>\n";
        }
    }
    $ret .= "</select>\n";
    if ($select_name == 'var_lang_lcm') {
        $ret .= "<noscript><input type='submit' name='Validate' value='&gt;&gt;'/></noscript>";
        $ret .= "</form>";
    }
    return $ret;
}
Example #6
0
	Free Software Foundation; either version 2 of the License, or (at your
	option) any later version.

	This program is distributed in the hope that it will be useful, but
	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: sel_auth.php,v 1.12 2006/02/20 03:25:03 mlutfy Exp $
*/
include 'inc/inc.php';
include_lcm('inc_acc');
global $prefs;
$case = intval($_REQUEST['case']);
if (!($case > 0)) {
    lcm_page_start(_T('title_error'));
    echo "<p>" . _T('error_no_case_specified') . "</p>\n";
    lcm_page_end();
    exit;
}
$destination = "case_det.php?id_case=" . $case;
if (isset($_SERVER['HTTP_REFERER'])) {
    $destination = $_SERVER['HTTP_REFERER'];
}
$dest_link = new Link($destination);
if (!allowed($case, 'a')) {
    die("You don't have permission to add users to this case!");
Example #7
0
function send_registration_by_email()
{
    global $lcm_lang_left;
    $_SESSION['form_data'] = array();
    $_SESSION['errors'] = array();
    $kwg_email = get_kwg_from_name('+email_main');
    $form_items = array('name_first' => 'person_input_name_first', 'name_last' => 'person_input_name_last', 'email' => 'input_email', 'username' => 'authoredit_input_username');
    foreach ($form_items as $field => $trad) {
        $_SESSION['form_data'][$field] = _request($field);
        if (!_session($field)) {
            $_SESSION['errors'][$field] = _Ti($trad) . _T('warning_field_mandatory');
        }
    }
    if (count($_SESSION['errors'])) {
        lcm_header("Location: lcm_pass.php?register=yes");
        exit;
    }
    install_html_start(_T('pass_title_register'), 'login');
    // There is a risk that an author changes his e-mail after his account
    // is created, to the e-mail of another person, and therefore block the
    // other person from registering. But then.. this would allow the other
    // person to hijack the account, so it would be a stupid DoS.
    $query = "SELECT id_of_person, status FROM lcm_contact as c, lcm_author as a\n\t\tWHERE c.id_of_person = a.id_author\n\t\tAND value = '" . _session('email') . "'\n\t\tAND type_person = 'author'\n\t\tAND type_contact = " . $kwg_email['id_group'];
    $result = lcm_query($query);
    // Test if the user already exists
    if ($row = lcm_fetch_array($result)) {
        $id_author = $row['id_of_person'];
        $status = $row['status'];
        // TODO: if status = 'pending for validation by admin', show message
        if ($status == 'trash') {
            echo "<br />\n";
            echo "<div class='box_error'>" . _T('pass_registration_denied') . "</div>\n";
        } else {
            echo "<br />\n";
            echo "<div class=\"box_error\" align=\"{$lcm_lang_left}\">" . _T('pass_warning_already_registered') . "</div>\n";
            return;
        }
    }
    //
    // Send identifiers by e-mail
    //
    include_lcm('inc_access');
    include_lcm('inc_mail');
    $username = get_unique_username(_session('username'));
    $pass = create_random_password(8, $username);
    $mdpass = md5($pass);
    $open_subscription = read_meta("site_open_subscription");
    if (!($open_subscription == 'yes' || $open_subscription == 'moderated')) {
        lcm_panic("Subscriptions not permitted.");
    }
    $status = 'waiting';
    if ($open_subscription == 'yes') {
        $status = 'normal';
    }
    lcm_query("INSERT INTO lcm_author (name_first, name_last, username, password, status, date_creation, date_update) " . "VALUES ('" . _session('name_first') . "', '" . _session('name_last') . "', '{$username}', '{$mdpass}', 'normal', NOW(), NOW())");
    $id_author = lcm_insert_id('lcm_author', 'id_author');
    // Add e-mail to lcm_contact
    lcm_query("INSERT INTO lcm_contact (type_person, type_contact, id_of_person, value)\n\t\t\tVALUES ('author', " . $kwg_email['id_group'] . ", {$id_author}, '" . _session('email') . "')");
    // Prepare the e-mail to send to the user
    $site_name = _T(read_meta('site_name'));
    $site_address = read_meta('site_address');
    $message = _T('info_greetings') . ",\n\n";
    $message .= _T('pass_info_here_info', array('site_name' => $site_name, 'site_address' => $site_address)) . "\n\n";
    $message .= "- " . _Ti('login_login') . " {$username}\n";
    $message .= "- " . _Ti('login_password') . " {$pass}\n\n";
    if ($open_subscription == 'moderated') {
        $message .= _T('pass_info_moderated') . "\n\n";
    }
    $message .= _T('pass_info_automated_msg') . "\n\n";
    if (send_email(_session('email'), "[{$site_name}] " . _T('pass_title_personal_identifier'), $message)) {
        echo "<p>" . _T('pass_info_identifier_mail') . "</p>\n";
    } else {
        $email_admin = read_meta('email_sysadmin');
        echo "<div class=\"box_error\"><p>" . _T('pass_warning_mail_failure', array('email_admin' => $email_admin)) . "</p></div>\n";
    }
    // If moderated, send copy to site admin
    if ($open_subscription == 'moderated') {
        $email_admin = read_meta('email_sysadmin');
        send_email($email_admin, "[{$site_name}] " . _T('pass_title_personal_identifier'), $message);
    }
}
Example #8
0
	This program is distributed in the hope that it will be useful, but
	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_exp.php,v 1.4 2007/03/20 14:16:59 mlutfy Exp $
*/
include 'inc/inc.php';
include_lcm('inc_acc');
include_lcm('inc_filters');
include_lcm('inc_obj_exp');
// Don't clear form data if comming back from upd_exp 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');
//
// Check for access rights
//
// TODO
$edit = 1;
$write = 1;
if (!($admin || $write)) {
    lcm_panic("You don't have permission to add follow-ups to this case");
Example #9
0
function install_step_3()
{
    $db_address = _request('db_address');
    $db_login = _request('db_login');
    $db_password = _request('db_password');
    global $lcm_db_version;
    $install_log = "";
    $upgrade_log = "";
    // Possible errors will get trapped in the output buffer and displayed later,
    // so that they don't mess up with headers/html.
    ob_start();
    if (_request('db_choice') == "__manual__") {
        $sel_db = _request('manual_db');
    } else {
        $sel_db = _request('db_choice');
    }
    $link = lcm_connect_db($db_address, 0, $db_login, $db_password, $sel_db);
    $io_output = ob_get_contents();
    ob_end_clean();
    if (!$link) {
        install_html_start('AUTO', '', 3);
        lcm_panic("connection denied: " . lcm_sql_error());
    }
    //
    // TEMPORARY (used by testing the installer)
    /*
    lcm_query("DROP TABLE lcm_case", true);
    lcm_query("DROP TABLE lcm_case_attachment", true);
    lcm_query("DROP TABLE lcm_stage", true);
    lcm_query("DROP TABLE lcm_followup", true);
    lcm_query("DROP TABLE lcm_author", true);
    lcm_query("DROP TABLE lcm_client", true);
    lcm_query("DROP TABLE lcm_client_attachment", true);
    lcm_query("DROP TABLE lcm_org", true);
    lcm_query("DROP TABLE lcm_org_attachment", true);
    lcm_query("DROP TABLE lcm_contact", true);
    lcm_query("DROP TABLE lcm_keyword", true);
    lcm_query("DROP TABLE lcm_keyword_case", true);
    lcm_query("DROP TABLE lcm_keyword_client", true);
    lcm_query("DROP TABLE lcm_keyword_org", true);
    lcm_query("DROP TABLE lcm_keyword_group", true);
    lcm_query("DROP TABLE lcm_report", true);
    lcm_query("DROP TABLE lcm_fields", true);
    lcm_query("DROP TABLE lcm_filter", true);
    lcm_query("DROP TABLE lcm_app", true);
    lcm_query("DROP TABLE lcm_app_client_org", true);
    lcm_query("DROP TABLE lcm_app_fu", true);
    lcm_query("DROP TABLE lcm_author_app", true);
    lcm_query("DROP TABLE lcm_case_client_org", true);
    lcm_query("DROP TABLE lcm_case_author", true);
    lcm_query("DROP TABLE lcm_client_org", true);
    lcm_query("DROP TABLE lcm_rep_col", true);
    lcm_query("DROP TABLE lcm_rep_line", true);
    lcm_query("DROP TABLE lcm_rep_filters", true);
    lcm_query("DROP TABLE lcm_filter_conds", true);
    lcm_query("DROP TABLE lcm_rep_filter", true);
    lcm_query("DROP TABLE lcm_meta", true);
    */
    // Test if the software was already installed
    $result = lcm_query("SELECT * FROM lcm_meta", true);
    $already_installed = !lcm_sql_errno() && lcm_num_rows($result);
    $old_lcm_version = 'NONE';
    if ($already_installed) {
        lcm_log("LCM already installed", 'install');
        // Find the current database version
        $old_lcm_db_version = 0;
        $query = "SELECT value FROM lcm_meta WHERE name = 'lcm_db_version'";
        $result = lcm_query_db($query);
        while ($row = lcm_fetch_array($result)) {
            $old_lcm_db_version = $row['value'];
        }
        lcm_log("LCM version installed is {$old_lcm_db_version}", 'install');
        // Check if upgrade is needed
        if ($old_lcm_db_version < $lcm_db_version) {
            lcm_log("Calling the upgrade procedure (since < {$lcm_db_version})", 'install');
            include_lcm('inc_db_upgrade');
            $upgrade_log = upgrade_database($old_lcm_db_version);
        } else {
            lcm_log("Upgrade _not_ called, looks OK (= {$lcm_db_version})", 'install');
        }
    } else {
        lcm_log("Creating the database from scratch", 'install');
        include_lcm('inc_db_create');
        $install_log .= create_database();
        lcm_log("DB creation complete", 'install');
    }
    // Create default meta + keywords
    include_lcm('inc_meta');
    include_lcm('inc_keywords_default');
    include_lcm('inc_meta_defaults');
    init_default_config();
    init_languages();
    $skwg = get_default_keywords();
    create_groups($skwg);
    write_metas();
    // regenerate inc/data/inc_meta_cache.php
    // Test DB: not used for now..
    include_lcm('inc_db_test');
    $structure_ok = lcm_structure_test();
    if (!empty($install_log)) {
        install_html_start('AUTO', '', 3);
        echo "<h3><small>" . _T('install_step_three') . "</small> " . _T('install_title_creating_database') . "</h3>\n";
        echo "<div class='box_error'>\n";
        echo "<p>";
        echo "<b>" . _T('warning_operation_failed') . "</b> " . _T('install_database_install_failed');
        echo " " . lcm_help("install_connection") . "</p>\n";
        echo "</div>\n";
        // Dump error listing
        echo put_text_in_textbox($install_log);
        install_html_end();
    } else {
        if (!empty($upgrade_log)) {
            install_html_start('AUTO', '', 3);
            echo "<h3><small>" . _T('install_step_three') . "</small> " . _T('install_title_creating_database') . "</h3>\n";
            echo "<div class='box_error'>\n";
            echo "<p>" . _T('install_warning_update_impossible', array('old_version' => $old_lcm_version, 'version' => $lcm_version)) . "</p>\n";
            echo "</div>\n";
            // Dump error listing
            echo put_text_in_textbox($upgrade_log);
            install_html_end();
        } else {
            if (!$structure_ok) {
                install_html_start('AUTO', '', 3);
                echo "<h3><small>" . _T('install_step_three') . "</small> " . _T('install_title_creating_database') . "</h3>\n";
                echo "<div class='box_error'>\n";
                echo "<p> STRUCTURE PROBLEM </p>\n";
                // TRAD
                echo "</div>\n";
                install_html_end();
            } else {
                // Everything OK
                $conn = '<' . '?php' . "\n";
                $conn .= "if (defined('_CONFIG_INC_CONNECT')) return;\n";
                $conn .= "define('_CONFIG_INC_CONNECT', '1');\n";
                $conn .= "\$GLOBALS['lcm_connect_version'] = 0.1;\n";
                $conn .= "include_lcm('inc_db');\n";
                $conn .= "@lcm_connect_db('{$db_address}','','{$db_login}','{$db_password}','{$sel_db}');\n";
                $conn .= "\$GLOBALS['db_ok'] = !!@lcm_num_rows(@lcm_query_db('SELECT COUNT(*) FROM lcm_meta'));\n";
                $conn .= '?' . '>';
                $lcm_config_prefix = isset($_SERVER['LcmConfigDir']) ? $_SERVER['LcmConfigDir'] : 'inc/config';
                $myFile = fopen($lcm_config_prefix . '/inc_connect_install.php', 'wb');
                fputs($myFile, $conn);
                fclose($myFile);
                install_step_4();
            }
        }
    }
}
Example #10
0
<?php

include 'inc/inc_version.php';
include_lcm('inc_presentation');
use_language_of_visitor();
function bad_dirs($bad_dirs, $test_dir, $install)
{
    install_html_start();
    if ($install) {
        $titre = _T('directories_setup_start');
    } else {
        $titre = _T('directories_setup_problem');
    }
    $bad_url = "lcm_test_dirs.php";
    if ($test_dir) {
        $bad_url .= '?test_dir=' . $test_dir;
    }
    echo "<h3>" . $titre . "</h3>\n";
    echo "<div align='right'>" . menu_languages('var_lang_lcm') . "</div>\n";
    echo "<div class='box_error'>\n";
    echo "<p>" . _T('directories_bad_rights') . "</p>\n";
    echo "<ul>" . $bad_dirs . "</ul>\n";
    echo "<p>" . _T('directories_bad_rights_cause') . lcm_help('install_permissions') . "</p>\n";
    echo "</div>\n";
    echo "<p>" . _T('directories_continue') . "</p>\n";
    echo "<form action='{$bad_urls}' method='get'>\n";
    echo "<div align='right'><button class='fondl' name='Validate'>" . _T('button_reload_page') . "</button></div>";
    echo "</form>";
    install_html_end();
}
function absent_dirs($bad_dirs, $test_dir)
Example #11
0
	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: inc_obj_fu.php,v 1.27 2008/04/07 19:13:03 mlutfy Exp $
*/
// Execute this file only once
if (defined('_INC_OBJ_FU')) {
    return;
}
define('_INC_OBJ_FU', '1');
include_lcm('inc_db');
include_lcm('inc_obj_generic');
class LcmFollowup extends LcmObject
{
    // Note: Since PHP5 we should use "private", and generates a warning,
    // but we must support PHP >= 4.0.
    var $data;
    function LcmFollowup($id_fu = 0, $id_case = 0)
    {
        $id_fu = intval($id_fu);
        $id_case = intval($id_case);
        $this->data = array();
        if ($id_fu > 0) {
            $query = "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\t\t\t\tFROM lcm_followup as fu, lcm_author as a\n\t\t\t\t\tWHERE id_followup = {$id_fu}\n\t\t\t\t\t  AND fu.id_author = a.id_author";
            $result = lcm_query($query);
            if ($row = lcm_fetch_array($result)) {
                foreach ($row as $key => $val) {
Example #12
0
 function save()
 {
     $errors = $this->validate();
     if (count($errors)) {
         return $errors;
     }
     //
     // Update record in database
     //
     $cl = "name_first = '" . clean_input($this->getDataString('name_first')) . "',\n\t\t\t   name_middle = '" . clean_input($this->getDataString('name_middle')) . "',\n\t\t\t   name_last = '" . clean_input($this->getDataString('name_last')) . "',\n\t\t\t   gender = '" . clean_input($this->getDataString('gender')) . "',\n\t\t\t   notes = '" . clean_input($this->getDataString('notes')) . "'";
     // ,
     if ($this->getDataString('date_birth')) {
         $cl .= ", date_birth = '" . $this->getDataString('date_birth') . "'";
     }
     $cl .= ", citizen_number = '" . clean_input($this->getDataString('citizen_number')) . "'";
     $cl .= ", civil_status = '" . clean_input($this->getDataString('civil_status')) . "'";
     $cl .= ", income = '" . clean_input($this->getDataString('income')) . "'";
     if ($this->getDataInt('id_client') > 0) {
         $q = "UPDATE lcm_client\n\t\t\t\tSET date_update = NOW(), \n\t\t\t\t\t{$cl} \n\t\t\t\tWHERE id_client = " . $this->getDataInt('id_client', '__ASSERT__');
         lcm_query($q);
     } else {
         $q = "INSERT INTO lcm_client\n\t\t\t\t\tSET date_creation = NOW(),\n\t\t\t\t\t\tdate_update = NOW(),\n\t\t\t\t\t\t{$cl}";
         $result = lcm_query($q);
         $this->data['id_client'] = lcm_insert_id('lcm_client', 'id_client');
     }
     // Keywords
     update_keywords_request('client', $this->getDataInt('id_client'));
     if ($_SESSION['errors']) {
         $errors = array_merge($_SESSION['errors'], $errors);
     }
     // Insert/update client contacts
     include_lcm('inc_contacts');
     update_contacts_request('client', $this->getDataInt('id_client'));
     if ($_SESSION['errors']) {
         $errors = array_merge($_SESSION['errors'], $errors);
     }
     return $errors;
 }
Example #13
0
    lcm_page_start(_T('title_upgrade_database'));
    echo "\n<!-- Upgrading from {$current_version} to {$lcm_db_version} -->\n";
    $log = upgrade_database($current_version);
    // To be honest, in most cases, it will cause a lcm_panic() and this will
    // not show, altough we could (in the future) catch/interpret errors.
    if ($log) {
        echo "<div class='box_error'>\n";
        echo "<p>An error occured while upgrading the database: <br/>{$log}</p>\n";
        // TRAD
        echo "</div>\n";
        lcm_panic("upgrade error ({$log})");
    } else {
        echo "<div class='box_success'>\n";
        echo '<p class="normal_text">' . _T('info_upgrade_database3') . ' <a class="content_link" href="index.php">' . _T('info_upgrade_database5') . "</a></p>\n";
        echo "</div>\n";
    }
    lcm_page_end();
} else {
    global $author_session;
    lcm_page_start("No database upgrade needed");
    // TRAD
    // Small practical trick to refresh the report fields/filters
    if ($author_session['status'] == 'admin') {
        include_lcm('inc_db_upgrade');
        include_lcm('inc_repfields_defaults');
        $fields = get_default_repfields();
        create_repfields($fields);
    }
    echo '<p class="normal_text"><a class="content_link" href="index.php">' . _T('info_upgrade_database5') . "</a></p>\n";
    lcm_page_end();
}
Example #14
0
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;
}
Example #15
0
<?php

/***************************************************************************\
 *  SPIP, Systeme de publication pour l'internet                           *
 *                                                                         *
 *  Copyright (c) 2001-2005                                                *
 *  Arnaud Martin, Antoine Pitrou, Philippe Riviere, Emmanuel Saint-James  *
 *                                                                         *
 *  Ce programme est un logiciel libre distribue sous licence GNU/GPL.     *
 *  Pour plus de details voir le fichier COPYING.txt ou l'aide en ligne.   *
\***************************************************************************/
include 'inc/inc.php';
include_lcm('inc_calendar');
lcm_page_start(_T('title_calendar_view'));
$afficher_bandeau_calendrier = true;
echo http_calendrier_init('', $_REQUEST['type']);
lcm_page_end();
Example #16
0
<?php

if (defined('_INC_DB')) {
    return;
}
define('_INC_DB', '1');
// if -- configuration -- mysql or postgresql
// ....
if (isset($GLOBALS['lcm_db_type']) && $GLOBALS['lcm_db_type']) {
    include_lcm('inc_db_' . $GLOBALS['lcm_db_type']);
} else {
    include_lcm('inc_db_mysql');
}
#  include_lcm('inc_db_pgsql');
Example #17
0
 function LcmReportGenUI($my_id_report, $my_export = 'html', $my_debug = 0)
 {
     $this->ui = $my_export;
     switch ($my_export) {
         case 'csv':
             include_lcm('inc_obj_export_csv');
             $this->exporter = new LcmExportCSV();
             break;
         case 'ods':
             include_lcm('inc_obj_export_ods');
             $this->exporter = new LcmExportODS();
             break;
         default:
             include_lcm('inc_obj_export_html');
             $this->exporter = new LcmExportHtml();
     }
     $this->LcmReportGen($my_id_report, $my_debug);
 }
Example #18
0
function _Tkw($grp, $val, $args = '')
{
    global $system_kwg;
    $kwg = array();
    // If a 'contact' keyword (starts with +), remove the +
    if (substr($val, 0, 1) == '+') {
        $val = substr($val, 1);
    }
    if ($system_kwg[$grp]) {
        $kwg = $system_kwg[$grp]['keywords'];
    } else {
        $kwg = get_keywords_in_group_name($grp, false);
    }
    if (count($kwg)) {
        if ($kwg[$val]) {
            return _T(remove_number_prefix($kwg[$val]['title']), $args);
        } else {
            // This is a weird case where the upgrade didn't refresh the
            // group correctly, so we will try to fix the situation.
            // First, we check in the database to see if the keyword exists,
            // and if it does, then we refresh the keywords.
            // Note: that get_keywords_in_group_id() consults only the DB
            // [ML] Note: this should not happen from 0.6.3, but i'm fed up of
            // thinking that this time we fixed it, so the code stays..
            $tmp_group = get_kwg_from_name($grp);
            $kws1 = get_keywords_in_group_id($tmp_group['id_group'], false);
            foreach ($kws1 as $kw) {
                if ($kw['name'] == $val) {
                    include_lcm('inc_keywords_default');
                    $system_keyword_groups = get_default_keywords();
                    create_groups($system_keyword_groups);
                    write_metas();
                    // regenerate inc/data/inc_meta_cache.php
                    return _T(remove_number_prefix($kw['title']), $args);
                }
            }
            lcm_panic("*** The keyword does not exist. It is possible that a\n\t\t\t\tminor error occured while the last upgrade of the software. Please\n\t\t\t\task your administrator to do the following: Go to the 'Keywords'\n\t\t\t\tmenu, then click on the 'Maintenance' tab, then click on the\n\t\t\t\t'Validate' button. This will refresh the available keywords.");
        }
    } else {
        lcm_panic("*** The keyword group does not exist. It is possible that a\n\t\t\tminor error occured while the last upgrade of the software. Please\n\t\t\task your administrator to do the following: Go to the 'Keywords'\n\t\t\tmenu, then click on the 'Maintenance' tab, then click on the\n\t\t\t'Validate' button. This will refresh the available keywords.");
    }
}
Example #19
0
	$Id: inc.php,v 1.61 2007/02/16 21:37:28 mlutfy Exp $
*/
include 'inc/inc_version.php';
// Test if LCM is installed
if (!include_config_exists('inc_connect')) {
    header('Location: install.php');
    exit;
}
// For profiling: count the number of SQL queries
$GLOBALS['db_query_count'] = 0;
include_lcm('inc_auth');
include_lcm('inc_acc');
include_lcm('inc_presentation');
include_lcm('inc_text');
include_lcm('inc_filters');
include_lcm('inc_keywords');
// include_lcm('inc_calendar'); [ML] not used
if (!include_data_exists('inc_meta_cache')) {
    write_metas();
}
// Just precaution, avoids PHP warnings sometimes
if (!isset($_SESSION['form_data'])) {
    $_SESSION['form_data'] = array();
}
// [AG] Adding to validate later references to it
global $author_session;
//
// Preferences for presentation
// Can be done from any screen, but for now most is in config_author.php
// The presence of author_ui_modified assumed that all other form variables are set.
// [AG] added author_advanced_settings_modified to split settings into tabs
Example #20
0
	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: inc_obj_exp.php,v 1.12 2007/03/20 15:51:36 mlutfy Exp $
*/
// Execute this file only once
if (defined('_INC_OBJ_EXPENSE')) {
    return;
}
define('_INC_OBJ_EXPENSE', '1');
include_lcm('inc_obj_generic');
include_lcm('inc_obj_exp_ac');
class LcmExpense extends LcmObject
{
    // Note: Since PHP5 we should use "private", and generates a warning,
    // but we must support PHP >= 4.0.
    var $comments;
    var $comment_start_from;
    function LcmExpense($id_expense = 0)
    {
        $id_expense = intval($id_expense);
        $this->comments = null;
        $this->comment_start_from = 0;
        $this->LcmObject();
        if ($id_expense > 0) {
            $query = "SELECT e.*, a.name_first, a.name_middle, a.name_last, c.title as case_title\n\t\t\t\t\t\tFROM lcm_expense as e\n\t\t\t\t\t\tLEFT JOIN lcm_author as a ON (a.id_author = e.id_author)\n\t\t\t\t\t\tLEFT JOIN lcm_case as c ON (c.id_case = e.id_case)\n\t\t\t\t\t\tWHERE e.id_expense = {$id_expense}";
            $result = lcm_query($query);
Example #21
0
	Free Software Foundation; either version 2 of the License, or (at your
	option) any later version.

	This program is distributed in the hope that it will be useful, but
	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: listorgs.php,v 1.20 2006/02/20 02:55:17 mlutfy Exp $
*/
include 'inc/inc.php';
include_lcm('inc_impex');
$find_org_string = '';
if (isset($_REQUEST['find_org_string'])) {
    $find_org_string = $_REQUEST['find_org_string'];
}
if (!empty($_REQUEST['export']) && $GLOBALS['author_session']['status'] == 'admin') {
    export('org', $_REQUEST['exp_format'], $find_org_string);
    exit;
}
lcm_page_start(_T('title_org_list'), '', '', 'clients_intro');
lcm_bubble('org_list');
show_find_box('org', $find_org_string, '', (string) ($GLOBALS['author_session']['status'] == 'admin'));
// List all organisations in the system + search criterion if any
$q = "SELECT id_org,name\n\t\tFROM lcm_org";
if (strlen($find_org_string) > 1) {
    $q .= " WHERE (name LIKE '%{$find_org_string}%')";
Example #22
0
}
// Change the language of the private area (or login)
// [ML] I once wanted to put this in a function, and it did a hell
// of a mess because of the session handling stuff..
if (isset($_REQUEST['var_lang_lcm'])) {
    // ex: bg, fr, en, en_uk, etc. nothing else is accepted
    if (preg_match("/^[_A-Za-z]+[0-9]*\$/", $_REQUEST['var_lang_lcm'])) {
        include_lcm('inc_lang');
        include_lcm('inc_session');
        $new_lang = clean_input($_REQUEST['var_lang_lcm']);
        $valid_author = verifier_visiteur();
        if (lcm_set_language($new_lang)) {
            lcm_setcookie('lcm_lang', $new_lang, time() + 365 * 24 * 3600);
            // Save language preference only if we are installed and if author connected
            if ($valid_author && include_config_exists('inc_connect')) {
                include_lcm('inc_admin');
                lcm_query("UPDATE lcm_author \n\t\t\t\t\t\tSET lang = '" . $new_lang . "' \n\t\t\t\t\t\tWHERE id_author = " . $GLOBALS['author_session']['id_author']);
                $author_session['lang'] = $new_lang;
                lcm_add_session($author_session, $_COOKIE['lcm_session']);
            } else {
                lcm_log("Not valid_author ({$valid_author}) or not yet installed");
            }
            $cible->delvar('lang');
            $cible->addvar('lang', $new_lang);
        } else {
            lcm_log("lcm_set_language() is not happy, wrong lang code?");
        }
    }
}
// Redirection
// Under Apache, cookies with a redirection work
Example #23
0
function write_metas()
{
    global $meta, $meta_upd;
    read_metas();
    $s = '<' . '?php

if (defined("_INC_META_CACHE")) return;
define("_INC_META_CACHE", "1");

function read_meta($name) {
	global $meta;

	if (! isset($meta[$name])) {
		lcm_debug("read_meta: -$name- does not exist");
		return "";
	}

	return $meta[$name];
}

function read_meta_upd($name) {
	global $meta_upd;
	return $meta_upd[$name];
}

';
    if ($meta) {
        reset($meta);
        while (list($key, $val) = each($meta)) {
            $key = addslashes($key);
            $val = preg_replace("/([\\\\'])/", "\\\\1", $val);
            $s .= "\$GLOBALS['meta']['{$key}'] = '{$val}';\n";
        }
        $s .= "\n";
    }
    if ($meta_upd) {
        reset($meta_upd);
        while (list($key, $val) = each($meta_upd)) {
            $key = addslashes($key);
            $s .= "\$GLOBALS['meta_upd']['{$key}'] = '{$val}';\n";
        }
        $s .= "\n";
    }
    // System keywords
    include_lcm('inc_keywords');
    $kwg_all = get_kwg_all('system');
    foreach ($kwg_all as $key0 => $val0) {
        // Dump every field of the keyword group
        foreach ($val0 as $key => $val) {
            // We filter out numeric keys because lcm_fetch_array()
            // returns the two types of arrays
            if (!is_numeric($key)) {
                $key = addslashes($key);
                $val = preg_replace("/([\\\\'])/", "\\\\1", $val);
                $s .= "\$GLOBALS['system_kwg']['" . $kwg_all[$key0]['name'] . "']['{$key}'] = '{$val}';\n";
            }
        }
    }
    reset($kwg_all);
    foreach ($kwg_all as $kwg) {
        // Dump every keyword and field of the keyword group
        $kw_all = get_keywords_in_group_id($kwg['id_group'], false);
        foreach ($kw_all as $kw) {
            $kw_name = $kw['name'];
            // Dump every field of the keyword into the kwg
            while (list($key, $val) = each($kw)) {
                if (!is_numeric($key)) {
                    $key = addslashes($key);
                    $val = preg_replace("/([\\\\'])/", "\\\\1", $val);
                    $s .= "\$GLOBALS['system_kwg']['" . $kwg['name'] . "']['keywords']['{$kw_name}']['{$key}'] = '{$val}';\n";
                }
            }
        }
    }
    $s .= '?' . '>';
    if (isset($_SERVER['LcmDataDir'])) {
        $file_meta_cache = $_SERVER['LcmDataDir'] . '/inc_meta_cache.php';
    } else {
        $file_meta_cache = 'inc/data/inc_meta_cache.php';
    }
    @unlink($file_meta_cache);
    $file_meta_cache_w = $file_meta_cache . '-' . @getmypid();
    $f = @fopen($file_meta_cache_w, "wb");
    if ($f) {
        $r = @fputs($f, $s);
        @fclose($f);
        if ($r == strlen($s)) {
            @rename($file_meta_cache_w, $file_meta_cache);
        } else {
            @unlink($file_meta_cache_w);
        }
    } else {
        global $connect_status;
        if ($connect_status == 'admin') {
            echo "<h4 font color='red'>" . _T('texte_inc_meta_1') . " <a href='lcm_test_dirs.php'>" . _T('texte_inc_meta_2') . "</a> " . _T('texte_inc_meta_3') . "&nbsp;</h4>\n";
        }
    }
}
Example #24
0
	Free Software Foundation; either version 2 of the License, or (at your
	option) any later version.

	This program is distributed in the hope that it will be useful, but
	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: config_author.php,v 1.61 2006/08/15 20:30:34 mlutfy Exp $
*/
include 'inc/inc.php';
include_lcm('inc_filters');
function read_author_data($id_author)
{
    $q = "SELECT * FROM lcm_author WHERE id_author=" . $id_author;
    $result = lcm_query($q);
    if (!($usr = lcm_fetch_array($result))) {
        lcm_panic("The user #{$id_author} does not exist in the database.");
    }
    return $usr;
}
function show_author_form($tab)
{
    global $author_session;
    global $prefs;
    // Referer not always set (bookmark, reload, etc.)
    // [AG] This is to preserve page's referer in 'ref' GET value during tab transitions
Example #25
0
	This program is distributed in the hope that it will be useful, but
	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: export.php,v 1.4 2005/04/28 01:06:32 antzi Exp $
*/
include 'inc/inc_version.php';
include_lcm('inc_auth');
include_lcm('inc_filters');
include_lcm('inc_impex');
include_lcm('inc_xml');
if ($GLOBALS['author_session']['status'] != 'admin') {
    lcm_panic("You don't have permission to export!");
}
$item = clean_input($_REQUEST['item']);
if (!empty($_REQUEST['id'])) {
    $id = intval($_REQUEST['id']);
}
$data = array();
switch ($item) {
    case 'case':
        load_case($id, $data, _LOAD_ALL);
        break;
    case 'followup':
        $data = load_followup($id, $data, _LOAD_ALL);
        break;
Example #26
0
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;
}
Example #27
0
function auth()
{
    global $INSECURE, $HTTP_POST_VARS, $HTTP_GET_VARS, $HTTP_COOKIE_VARS, $REMOTE_USER, $PHP_AUTH_USER, $PHP_AUTH_PW;
    global $auth_can_disconnect;
    global $connect_id_auteur, $connect_nom, $connect_bio, $connect_email;
    global $connect_nom_site, $connect_url_site, $connect_login, $connect_pass;
    global $connect_activer_imessage, $connect_activer_messagerie;
    global $connect_status;
    global $author_session, $prefs;
    global $clean_link;
    // This reloads $GLOBALS['db_ok'], just in case
    include_config('inc_connect');
    // If there is not SQL connection, quit.
    if (!$GLOBALS['db_ok']) {
        include_lcm('inc_presentation');
        lcm_html_start("Technical problem", "install");
        // annoy sql_errno()
        echo "\n<!-- \n";
        echo "\t* Flag connect: " . $GLOBALS['flag_connect'] . "\n\t";
        lcm_query("SELECT count(*) from lcm_meta");
        echo "\n-->\n\n";
        echo "<div align='left' style='width: 600px;' class='box_error'>\n";
        echo "\t<h3>" . _T('title_technical_problem') . "</h3>\n";
        echo "\t<p>" . _T('info_technical_problem_database') . "</p>\n";
        if (lcm_sql_errno()) {
            echo "\t<p><tt>" . lcm_sql_errno() . " " . lcm_sql_error() . "</tt></p>\n";
        } else {
            echo "\t<p><tt>No error diagnostic was provided.</tt></p>\n";
        }
        echo "</div>\n";
        lcm_html_end();
        return false;
    }
    // Initialise variables (avoid URL hacks)
    $auth_login = "";
    $auth_pass = "";
    $auth_pass_ok = false;
    $auth_can_disconnect = false;
    // Fetch identification data from authentication session
    if (isset($_COOKIE['lcm_session'])) {
        if (verifier_session($_COOKIE['lcm_session'])) {
            if ($author_session['status'] == 'admin' or $author_session['status'] == 'normal') {
                $auth_login = $author_session['username'];
                $auth_pass_ok = true;
                $auth_can_disconnect = true;
            }
        }
    } else {
        if ($_REQUEST['privet'] == 'yes') {
            // Failed login attempt: cookie failed
            $link = new Link("lcm_cookie.php?cookie_test_failed=yes");
            $clean_link->delVar('privet');
            $url = str_replace('/./', '/', $clean_link->getUrl());
            $link->addVar('var_url', $url);
            @header("Location: " . $link->getUrl());
            exit;
        }
    }
    // If not authenticated, ask for login / password
    if (!$auth_login) {
        $url = $clean_link->getUrl();
        @header("Location: lcm_login.php?var_url=" . urlencode($url));
        exit;
    }
    //
    // Search for the login in the authors' table
    //
    $auth_login = addslashes($auth_login);
    $query = "SELECT * FROM lcm_author WHERE username='******' AND status !='external' AND status !='6forum'";
    $result = @lcm_query($query);
    if ($row = lcm_fetch_array($result)) {
        $connect_id_auteur = $row['id_author'];
        $connect_nom = $row['name_first'];
        $connect_login = $row['username'];
        $connect_pass = $row['password'];
        $connect_status = $row['status'];
        $connect_activer_messagerie = "non";
        //$row["messagerie"];
        $connect_activer_imessage = "non ";
        //$row["imessage"];
        // Set the users' preferences
        $prefs = unserialize(get_magic_quotes_runtime() ? stripslashes($row['prefs']) : $row['prefs']);
        //
        // Default values for some possibly unset preferences
        //
        if (!isset($prefs['page_rows']) || intval($prefs['page_rows']) < 1) {
            $prefs['page_rows'] = 15;
        }
        if (!isset($prefs['theme']) || !$prefs['theme']) {
            $prefs['theme'] = 'green';
        }
        if (!isset($prefs['screen']) || !$prefs['screen']) {
            $prefs['screen'] = 'wide';
        }
        if (!isset($prefs['font_size']) || !$prefs['font_size']) {
            $prefs['font_size'] = 'medium_font';
        }
        if (!isset($prefs['case_owner']) || !$prefs['case_owner']) {
            $prefs['case_owner'] = 'my';
        }
        if (!isset($prefs['case_period']) || !$prefs['case_period']) {
            $prefs['case_period'] = '91';
        }
        if (!isset($prefs['mode']) || !$prefs['mode']) {
            $prefs['mode'] = 'simple';
        }
        if (!isset($prefs['time_intervals']) || !$prefs['time_intervals']) {
            $prefs['time_intervals'] = 'relative';
            $prefs['time_intervals_notation'] = 'hours_only';
        }
    } else {
        // This case is a strange possibility: the author is authentified
        // OK, but he does not exist in the authors table. Possible cause:
        // the database was restaured and the author does not exist (and
        // the user was authentified by another source, such as LDAP).
        // Note: we use to show a strange error message which would advice
        // to logout, but since it occurs only after db upgrade, just logout
        // brutally (with cookie_admin=no to forget the username).
        lcm_header('Location: lcm_cookie.php?cookie_admin=no&logout=' . $auth_login);
        exit;
    }
    if (!$auth_pass_ok) {
        @header("Location: lcm_login.php?var_erreur=pass");
        exit;
    }
    // [ML] Again, not sure how this is used, but we can ignore it for now
    // TODO (note: nouveau == new)
    if ($connect_status == 'nouveau') {
        $query = "UPDATE lcm_author SET status = 'normal' WHERE id_author = {$connect_id_auteur}";
        $result = lcm_query($query);
        $connect_status = 'normal';
    }
    // PHP sessions are started here, and stopped at logout
    session_start();
    return true;
}
Example #28
0
	option) any later version.

	This program is distributed in the hope that it will be useful, but
	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: upd_client.php,v 1.21 2007/01/12 17:34:51 mlutfy Exp $
*/
include 'inc/inc.php';
include_lcm('inc_filters');
include_lcm('inc_obj_client');
// Clear all previous errors
$_SESSION['errors'] = array();
$_SESSION['form_data'] = array();
// Get form data from POST fields
foreach ($_POST as $key => $value) {
    $_SESSION['form_data'][$key] = $value;
}
$ref_upd_client = 'edit_client.php?client=' . _session('id_client', 0);
if ($_SERVER['HTTP_REFERER']) {
    $ref_upd_client = $_SERVER['HTTP_REFERER'];
}
//
// Update data
//
$obj_client = new LcmClient(_session('id_client'));
Example #29
0
	This program is distributed in the hope that it will be useful, but
	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);
Example #30
0
	This program is distributed in the hope that it will be useful, but
	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_org.php,v 1.28 2007/01/12 17:36:42 mlutfy Exp $
*/
include 'inc/inc.php';
include_lcm('inc_filters');
include_lcm('inc_contacts');
include_lcm('inc_obj_org');
// Initialise variables
$org = intval($_GET['org']);
if (empty($_SESSION['errors'])) {
    // Clear form data
    $_SESSION['form_data'] = array();
    $_SESSION['form_data']['ref_edit_org'] = $_REQUEST['HTTP_REFERER'];
    if (!empty($org)) {
        // Prepare query
        $q = "SELECT *\n\t\t\tFROM lcm_org\n\t\t\tWHERE id_org={$org}";
        $result = lcm_query($q);
        // Process the output of the query
        if ($row = lcm_fetch_array($result)) {
            // Get org details
            foreach ($row as $key => $value) {
                $_SESSION['form_data'][$key] = $value;