예제 #1
0
    show_context_stage($case, $id_stage);
} else {
    // Normal follow-up
    $result = lcm_query("SELECT stage FROM lcm_case WHERE id_case = " . $case);
    $row = lcm_fetch_array($result);
    if ($row['stage']) {
        $stage_info = get_kw_from_name('stage', $row['stage']);
        $id_stage = $stage_info['id_keyword'];
        show_context_stage($case, $id_stage);
    }
}
show_context_end();
// Show the errors (if any)
echo show_all_errors($_SESSION['errors']);
// Disable inputs when edit is not allowed for the field
$dis = $admin || $edit ? '' : 'disabled="disabled"';
echo '<form action="upd_fu.php" method="post">' . "\n";
$obj_fu = new LcmFollowupInfoUI($_SESSION['follow']);
$obj_fu->printEdit();
echo '<button name="submit" type="submit" value="submit" class="simple_form_btn">' . _T('button_validate') . "</button>\n";
echo '<input type="hidden" name="id_followup" value="' . _session('id_followup') . '" />';
echo '<input type="hidden" name="id_case" value="' . _session('id_case') . '">';
echo '<input type="hidden" name="id_app" value="' . _session('id_app', 0) . '">';
echo '<input type="hidden" name="ref_edit_fu" value="' . _session('ref_edit_fu') . '">';
echo "</form>\n";
lcm_page_end();
// Clear the errors, in case user jumps to other 'edit' page
$_SESSION['errors'] = array();
$_SESSION['form_data'] = array();
$_SESSION['fu_data'] = array();
// DEPRECATED LCM 0.7.0
예제 #2
0
function show_keyword_id($id_keyword = 0)
{
    if (!$id_keyword) {
        if (!intval($_REQUEST['id_group']) > 0) {
            lcm_panic("missing valid id_group for new keyword");
        }
        $kwg = get_kwg_from_id($_REQUEST['id_group']);
        // Suggest a keyword name: kwgnameNN, where NN = numeric sequence
        $all_kws = get_keywords_in_group_name($kwg['name'], false);
        $cpt = sprintf("%02d", count($all_kws) + 1);
        while (get_kw_from_name($kwg['name'], $kwg['name'] . $cpt)) {
            $cpt = sprintf("%02d", ++$cpt);
        }
        $kw['name'] = $kwg['name'] . $cpt;
        $kw['title'] = '';
        $kw['description'] = '';
        $kw['id_group'] = $kwg['id_group'];
        $kw['ac_author'] = 'Y';
        $kw['hasvalue'] = 'N';
        $kw['type'] = $kwg['type'];
        lcm_page_start(_T('title_keyword_new'));
    } else {
        $kw = get_kw_from_id($id_keyword);
        $kwg = get_kwg_from_id($kw['id_group']);
        lcm_page_start(_T('title_keyword_edit'));
    }
    echo show_all_errors($_SESSION['errors']);
    if (!$id_keyword) {
        echo "<ul style=\"padding-left: 0.5em; padding-top: 0.2; padding-bottom: 0.2; font-size: 12px;\">\n";
        echo '<li style="list-style-type: none;">' . _T('keywords_input_for_group') . " " . '<a class="content_link" href="keywords.php?action=edit_group&id_group=' . $kwg['id_group'] . '">' . _T($kwg['title']) . "</a></li>\n";
        echo "</ul>\n";
    }
    echo '<fieldset class="info_box">';
    echo '<form action="keywords.php" method="post">' . "\n";
    echo '<input type="hidden" name="action" value="update_keyword" />' . "\n";
    echo '<input type="hidden" name="id_keyword" value="' . $id_keyword . '" />' . "\n";
    echo '<input type="hidden" name="id_group" value="' . $kw['id_group'] . '" />' . "\n";
    // for new keyword only
    // Name (only for new keywords, must be unique and cannot be changed)
    echo "<strong>" . f_err_star('name') . _T('keywords_input_name') . "</strong> " . "(short identifier, unique to this keyword group)" . "<br />\n";
    // TRAD
    $disabled = isDisabled($id_keyword);
    echo '<input ' . $disabled . ' type="text" id="kw_name" name="kw_name" size="45" value="' . $kw['name'] . '" class="search_form_txt" />' . "\n";
    echo "<br /><br />\n";
    // Title
    echo "<strong>" . f_err_star('title') . _T('keywords_input_title') . "</strong><br />\n";
    echo "<input type='text' id='kw_title' name='kw_title' size='45' value='" . $kw['title'] . "' class='search_form_txt' />\n";
    echo "<br /><br />\n";
    // Description
    echo "<strong>" . _T('keywords_input_description') . "</strong><br />\n";
    echo "<textarea id='kw_desc' name='kw_desc' rows='2' cols='45' wrap='soft' class='frm_tarea'>";
    echo $kw['description'];
    echo "</textarea>\n";
    // Ac_author
    echo '<ul class="info">';
    echo '<li>' . _T('keywords_info_kw_ac_author') . ' ' . get_yes_no('kw_ac_author', $kw['ac_author']) . "</li>\n";
    if (!$id_keyword || $id_keyword && $kwg['type'] != 'system') {
        echo '<li>' . "Does the keyword have a specific value?" . ' ' . get_yes_no('kw_hasvalue', $kw['hasvalue']) . "</li>\n";
    }
    echo '<button name="submit" type="submit" value="submit" class="simple_form_btn">' . _T('button_validate') . "</button>\n";
    echo "</form>\n";
    echo '</fieldset>';
    // destroy error messages
    $_SESSION['errors'] = array();
    lcm_page_end();
    exit;
}
예제 #3
0
function get_filters_sql($report, $obj_type = '', $obj_name = '')
{
    $ret = "";
    $is_missing_filters = false;
    $my_filters = get_filters($report->getId(), $obj_type, $obj_name);
    $clauses = array();
    // Apply the filter values and check for missing values
    foreach ($my_filters as $f) {
        if ($f['value'] || isset($_REQUEST['filter_val' . $f['id_filter']]) || isset_datetime_from_array($_REQUEST, 'filter_val' . $f['id_filter'], 'year_only') || isset_datetime_from_array($_REQUEST, 'filter_val' . $f['id_filter'] . "_start", 'year_only') && isset_datetime_from_array($_REQUEST, 'filter_val' . $f['id_filter'] . "_end", 'year_only')) {
            $filter_sql = apply_filter($f);
            if ($filter_sql) {
                array_push($clauses, $filter_sql);
            }
        } else {
            // For now, we ignore filters without type (eq/lt/gt/..)
            // because it's a bit messy to allow input at runtime
            // (because of fields for filter value)
            if ($f['type']) {
                $is_missing_filters = true;
            }
        }
    }
    if ($is_missing_filters) {
        if (!($report->getOption('headers_sent') == 'yes')) {
            lcm_page_start(_T('title_rep_run') . " " . remove_number_prefix($rep_info['title']), '', '', 'report_intro');
        }
        show_page_subtitle(_T('rep_subtitle_filters'), 'reports_edit', 'filters');
        echo '<p class="normal_text">';
        include_lcm('inc_conditions');
        show_report_filters($report->getId(), true);
        echo "</p>\n";
        lcm_page_end();
        exit;
    }
    $ret1 = implode(" AND ", $clauses);
    return $ret1;
}
예제 #4
0
function import_database($input_filename)
{
    global $tabs;
    $input_filename = clean_input($input_filename);
    $root = addslashes(getcwd());
    $dir = DIR_BACKUPS_PREFIX . $input_filename;
    if (file_exists($dir)) {
        if ($_POST['conf'] !== 'yes') {
            // Print confirmation form
            lcm_page_start(_T('title_archives'), '', '', 'archives_import');
            show_tabs_links($tabs, 1, true);
            echo "<fieldset class='info_box'>\n";
            show_page_subtitle(_T('generic_subtitle_warning'), 'archives_import');
            echo "<p class='normal_text'><img src='images/jimmac/icon_warning.gif' alt='' " . "align='right' height='48' width='48' />" . _T('archives_info_restore_will_delete') . "</p>\n";
            echo "<form action='import_db.php' method='post'>\n";
            echo '<input type="hidden" name="action" value="import" />' . "\n";
            echo "<button type='submit' class='simple_form_btn' name='conf' value='yes'>" . _T('info_yes') . "</button>\n";
            echo "<button type='submit' class='simple_form_btn' name='conf' value='no'>" . _T('info_no') . "</button>\n";
            echo "<input type='hidden' name='file' value='{$input_filename}' />\n";
            echo "<input type='hidden' name='restore_type' value='" . $_POST['restore_type'] . "' />\n";
            echo "</form>";
            echo "</fieldset\n>";
            lcm_page_end();
            return;
        }
    }
    // Get saved database version
    if (!($fh = fopen("{$dir}/db-version", 'r'))) {
        lcm_panic("System error: Could not open file '{$dir}/db-version");
    }
    $backup_db_version = intval(fread($fh, 10));
    fclose($fh);
    // For debugging - use another database
    //lcm_query("use lcm_new");
    // Recreate tables
    if ($_POST['restore_type'] == 'clean' || $backup_db_version < read_meta('lcm_db_version')) {
        // Open backup dir
        if (!($dh = opendir("{$dir}/"))) {
            lcm_panic("System error: Could not open directory '{$dir}'");
        }
        while ($file = readdir($dh)) {
            // Get table name
            $table = substr($file, 0, -10);
            // Add path to filename
            $file = "{$dir}/{$file}";
            if (strlen($file) > 10) {
                if (is_file($file) && substr($file, -10) === ".structure" && is_file("{$dir}/{$table}" . DATA_EXT_NAME)) {
                    // Clear the table
                    $q = "DROP TABLE IF EXISTS {$table}";
                    $result = lcm_query($q);
                    // Create table
                    $fh = fopen($file, 'r');
                    $q = fread($fh, filesize($file));
                    fclose($fh);
                    $result = lcm_query_restore_table($q);
                }
            }
        }
        closedir($dh);
        // Update lcm_db_version
        // [ML] This is rather useless because they will be overwritten when the
        // values are loaded (LOAD FILE), but I leave it just in case there are
        // obscur bugs (altough this will most likely generate strange bugs..)
        write_meta('lcm_db_version', $backup_db_version);
        if (!preg_match('/^MySQL (4\\.0|3\\.)/', lcm_sql_server_info())) {
            write_meta('db_utf8', 'yes');
        }
        write_metas();
    } else {
        if ($backup_db_version > read_meta('lcm_db_version')) {
            // Backup version newer than installed db version
            lcm_page_start(_T('title_archives'), '', '', 'archives_import');
            // Show tabs
            show_tabs_links($tabs, 1, true);
            // Show tab header
            echo "Version mismatch!\n";
            // TRAD
            echo "<fieldset class='info_box'>\n";
            echo "Backup database version is newer than the installed database.";
            // TRAD
            echo "</fieldset\n>";
            lcm_page_end();
            return;
        } else {
            // Backup and current db versions are equal
        }
    }
    //
    // Import data into database tables\
    //
    // Change backup dir permissions, so MySQL could read from it.
    chmod($dir, 0755);
    // Open backup dir
    if (!($dh = opendir("{$dir}/"))) {
        lcm_panic("System error: Could not open directory '{$dir}'");
    }
    while ($file = readdir($dh)) {
        // Get table name
        $table = substr($file, 0, -DATA_EXT_LEN);
        // Add path to filename
        $file = "{$dir}/{$file}";
        if (strlen($file) > 5) {
            // [ML] why?
            if (is_file($file) && substr($file, -DATA_EXT_LEN) === DATA_EXT_NAME) {
                // If restore_type='clean', clear the table
                if ($_POST['restore_type'] == 'clean') {
                    lcm_query("TRUNCATE TABLE {$table}");
                }
                $q = "LOAD DATA INFILE '{$file}' ";
                $q .= $_POST['restore_type'] == 'replace' ? 'REPLACE' : 'IGNORE';
                $q .= "\tINTO TABLE {$table}\n\t\t\t\t\tFIELDS TERMINATED BY ','\n\t\t\t\t\t\tOPTIONALLY ENCLOSED BY '\"'\n\t\t\t\t\t\tESCAPED BY '\\\\'\n\t\t\t\t\tLINES TERMINATED BY '\r\n'";
                $result = lcm_query($q);
            }
        }
    }
    closedir($dh);
    // Change backup dir permissions back
    chmod($dir, 0700);
    // Update lcm_db_version since we have overwritten lcm_meta
    write_meta('lcm_db_version', $backup_db_version);
    if ($_REQUEST['restore_type'] == 'clean') {
        if (!preg_match('/^MySQL (4\\.0|3\\.)/', lcm_sql_server_info())) {
            write_meta('db_utf8', 'yes');
        }
    }
    write_metas();
    lcm_page_start(_T('title_archives'), '', '', 'archives_import');
    // FIXME?
    show_tabs_links($tabs, 1, true);
    echo '<div class="sys_msg_box">' . "\n";
    show_page_subtitle("Import finished", 'archives_import');
    // FIXME TRAD?
    echo "Backup '{$input_filename}' was successfully imported into database.";
    // TRAD
    echo "</div\n>";
    lcm_page_end();
}
예제 #5
0
function export_database($output_filename = '', $ignore_old = false)
{
    global $tabs;
    $output_filename = clean_input($output_filename);
    if (!$output_filename) {
        $output_filename = "lcm-" . date('Ymd');
    }
    //
    // Check if file exists. If exists, add a revision number to name (ex: foo-2)
    //
    $cpt = 0;
    while (file_exists(DIR_BACKUPS_PREFIX . $output_filename . ($cpt ? "-" . $cpt : ''))) {
        $cpt++;
    }
    if ($cpt) {
        $output_filename .= "-" . $cpt;
    }
    //
    // Export database
    //
    if (!mkdir(DIR_BACKUPS_PREFIX . $output_filename, 0777)) {
        lcm_panic("Could not create " . DIR_BACKUPS_PREFIX . $output_filename);
    }
    // Record database version
    $file = fopen(DIR_BACKUPS_PREFIX . $output_filename . '/db-version', 'w');
    fwrite($file, read_meta('lcm_db_version'));
    fclose($file);
    // Get the list of tables in the database
    $q = "SHOW TABLES";
    $result = lcm_query($q);
    while ($row = lcm_fetch_array($result)) {
        // Backup table structure
        $q = "SHOW CREATE TABLE " . $row[0];
        $res = lcm_query($q);
        $sql = lcm_fetch_row($res);
        $file = fopen(DIR_BACKUPS_PREFIX . $output_filename . '/' . $row[0] . ".structure", 'w');
        fwrite($file, $sql[1]);
        fclose($file);
        // Backup data
        $q = "SELECT * FROM " . $row[0] . "\n\t\t\t\tINTO OUTFILE '" . DIR_BACKUPS_PREFIX . $output_filename . '/' . $row[0] . DATA_EXT_NAME . "'\n\t\t\t\tFIELDS TERMINATED BY ','\n\t\t\t\t\tOPTIONALLY ENCLOSED BY '\"'\n\t\t\t\t\tESCAPED BY '\\\\'\n\t\t\t\tLINES TERMINATED BY '\r\n'";
        $res = lcm_query($q, true);
        if (!$res) {
            die("<p>Configuration error: please make sure that your MySQL user\n\t\t\thas 'File_priv' = 'Y'. For example, in phpmyadmin or using the\n\t\t\tcommand line mysql tool, go to the mysql.user table, and update\n\t\t\tthe File_priv of your LCM database account. Do not forget to\n\t\t\texecute 'flush privileges' afterwards. For more information,\n\t\t\tplease refer to: <a href='http://www.lcm.ngo-bg.org/article147.html'>http://www.lcm.ngo-bg.org/article147.html</a></p>");
            // TRAD
        }
    }
    // By default, in most installations, directory will have 0777 mode
    // and will be owned by the Apache process' user.
    chmod(DIR_BACKUPS_PREFIX . $output_filename, 0700);
    @(include "Archive/Tar.php");
    $tar_worked = false;
    if (class_exists("Archive_Tar")) {
        $tar_worked = true;
        $old_cwd = getcwd();
        chdir(DIR_BACKUPS);
        $tar_object = new Archive_Tar(FILE_PREFIX . $output_filename . '.tar');
        $files = array();
        $file_dir = opendir(FILE_PREFIX . $output_filename);
        if (!$file_dir) {
            lcm_panic("Could not open dir: {$file_dir}");
        }
        while ($file = readdir($file_dir)) {
            if (is_file(FILE_PREFIX . $output_filename . '/' . $file)) {
                $files[] = FILE_PREFIX . $output_filename . '/' . $file;
            }
        }
        if (count($files)) {
            $tar_object->setErrorHandling(PEAR_ERROR_PRINT);
            $tar_object->create($files) or lcm_panic("Could not add files " . get_var_dump($files));
        }
        chdir($old_cwd);
    }
    //
    // Finished
    //
    lcm_page_start(_T('title_archives'), '', '', 'archives_export');
    show_tabs_links($tabs, 0);
    echo '<div class="sys_msg_box">' . "\n";
    if ($tar_worked) {
        $name = '<a class="content_link" href="export_db.php?action=download&file=' . $output_filename . '.tar">' . $output_filename . '.tar' . '</a> (' . filesize_in_bytes(DIR_BACKUPS_PREFIX . $output_filename . '.tar') . ')';
        echo _T('archives_info_new_success', array('name' => $name));
    } else {
        echo _T('archives_info_new_success', array('name' => $output_filename));
    }
    echo "</div>\n";
    show_export_form_partial();
    lcm_page_end();
}