Example #1
0
function generate_language_sql($language, $options = NULL)
{
    $CRLF = get_user_browser_crlf();
    $sqlscript = '';
    //language, description, default_ind
    $language_r = fetch_language_r($language);
    if (is_not_empty_array($language_r)) {
        $sqlscript = '#########################################################' . $CRLF . '# OpenDb ' . get_opendb_version() . ' \'' . $language . '\' Language Pack' . $CRLF . '#########################################################' . $CRLF . $CRLF;
        $sqlscript .= "INSERT INTO s_language (language, description, default_ind) " . "VALUES ('" . $language_r['language'] . "', '" . addslashes($language_r['description']) . "', '" . $language_r['default_ind'] . "'); " . $CRLF;
        $results = fetch_language_langvar_rs($language, $options);
        if ($results) {
            $sqlscript .= $CRLF . '#' . $CRLF . '# System Language Variables' . $CRLF . '#' . $CRLF;
            while ($lang_var_r = db_fetch_assoc($results)) {
                if ($language_r['default_ind'] != 'Y') {
                    $value = ifempty($lang_var_r['value'], $lang_var_r['default_value']);
                } else {
                    $value = $lang_var_r['value'];
                }
                $sqlscript .= "INSERT INTO s_language_var (language, varname, value) " . "VALUES ('" . $language_r['language'] . "', '" . $lang_var_r['varname'] . "', '" . addslashes($value) . "'); " . $CRLF;
            }
            db_free_result($results);
        }
        if ($language_r['default_ind'] != 'Y') {
            $table_r = get_system_table_r();
            if (is_array($table_r)) {
                $sqlscript .= $CRLF . '#' . $CRLF . '# System Table Language Variables' . $CRLF . '#' . $CRLF;
                reset($table_r);
                while (list(, $table) = each($table_r)) {
                    $tableconf_r = get_system_table_config($table);
                    // key, column
                    if (is_array($tableconf_r) && is_array($tableconf_r['columns'])) {
                        reset($tableconf_r['columns']);
                        while (list(, $column) = each($tableconf_r['columns'])) {
                            $results = fetch_system_table_column_langvar_rs($language, $table, $column, $options);
                            if ($results) {
                                while ($lang_var_r = db_fetch_assoc($results)) {
                                    if ($language_r['default_ind'] != 'Y') {
                                        $value = ifempty($lang_var_r['value'], $lang_var_r[$column]);
                                    } else {
                                        $value = $lang_var_r['value'];
                                    }
                                    if (strlen($value)) {
                                        $sqlscript .= "INSERT INTO s_table_language_var (language, tablename, columnname, key1, key2, key3, value) " . "VALUES ('" . $language_r['language'] . "', '" . $table . "', '" . $column . "', '" . $lang_var_r['key1'] . "', " . (strlen($lang_var_r['key2']) > 0 ? "'" . $lang_var_r['key2'] . "'" : "''") . ", " . (strlen($lang_var_r['key3']) > 0 ? "'" . $lang_var_r['key3'] . "'" : "''") . ", '" . addslashes($value) . "'); " . $CRLF;
                                    }
                                }
                                db_free_result($results);
                            }
                        }
                    }
                }
            }
        }
    }
    return $sqlscript;
}
Example #2
0
function generate_site_plugin_sql($site_type_r)
{
    $CRLF = get_user_browser_crlf();
    $buffer = "#########################################################" . $CRLF . "# OpenDb " . get_opendb_version() . " " . $site_type_r['title'] . " (" . $site_type_r['site_type'] . ") Site Plugin" . $CRLF . "#########################################################";
    $buffer .= $CRLF . $CRLF . "#" . $CRLF . "# Site Plugin." . $CRLF . "#" . $CRLF;
    $buffer .= $CRLF . "INSERT INTO s_site_plugin ( site_type, classname, title, image, description, external_url, items_per_page, more_info_url ) " . "VALUES ( " . "'" . $site_type_r['site_type'] . "', " . "'" . $site_type_r['classname'] . "', " . "'" . addslashes($site_type_r['title']) . "', " . "'" . addslashes($site_type_r['image']) . "', " . "'" . addslashes($site_type_r['description']) . "', " . "'" . addslashes($site_type_r['external_url']) . "', " . "" . $site_type_r['items_per_page'] . ", " . "'" . addslashes($site_type_r['more_info_url']) . "' );";
    $results = fetch_site_plugin_conf_rs($site_type_r['site_type']);
    if ($results) {
        $buffer .= $CRLF . $CRLF . "#" . $CRLF . "# Site Plugin Configuration" . $CRLF . "#" . $CRLF;
        while ($site_plugin_conf_r = db_fetch_assoc($results)) {
            $buffer .= $CRLF . "INSERT INTO s_site_plugin_conf ( site_type, name, keyid, description, value ) " . "VALUES ( " . "'" . $site_plugin_conf_r['site_type'] . "', " . "'" . addslashes($site_plugin_conf_r['name']) . "', " . "'" . addslashes($site_plugin_conf_r['keyid']) . "', " . "'" . addslashes($site_plugin_conf_r['description']) . "', " . "'" . addslashes($site_plugin_conf_r['value']) . "' );";
        }
        db_fetch_assoc($results);
    }
    $results = fetch_site_plugin_input_field_rs($site_type_r['site_type']);
    if ($results) {
        $buffer .= $CRLF . $CRLF . "#" . $CRLF . "# Site Plugin Input Fields" . $CRLF . "#" . $CRLF;
        while ($site_plugin_input_field_r = db_fetch_assoc($results)) {
            $buffer .= $CRLF . "INSERT INTO s_site_plugin_input_field ( site_type, field, order_no, description, prompt, field_type, default_value, refresh_mask ) " . "VALUES ( " . "'" . $site_plugin_input_field_r['site_type'] . "', " . "'" . $site_plugin_input_field_r['field'] . "', " . "" . $site_plugin_input_field_r['order_no'] . ", " . "'" . addslashes($site_plugin_input_field_r['description']) . "', " . "'" . addslashes($site_plugin_input_field_r['prompt']) . "', " . "'" . $site_plugin_input_field_r['field_type'] . "', " . "'" . addslashes($site_plugin_input_field_r['default_value']) . "', " . "'" . addslashes($site_plugin_input_field_r['refresh_mask']) . "' );";
        }
        db_fetch_assoc($results);
    }
    $results = fetch_site_plugin_link_rs($site_type_r['site_type']);
    if ($results) {
        $buffer .= $CRLF . $CRLF . "#" . $CRLF . "# Site Plugin Links" . $CRLF . "#" . $CRLF;
        while ($fetch_site_plugin_link_r = db_fetch_assoc($results)) {
            $buffer .= $CRLF . "INSERT INTO s_site_plugin_link ( site_type, s_item_type_group, s_item_type, order_no, description, url, title_url ) " . "VALUES ( " . "'" . $fetch_site_plugin_link_r['site_type'] . "', " . "'" . $fetch_site_plugin_link_r['s_item_type_group'] . "', " . "'" . $fetch_site_plugin_link_r['s_item_type'] . "', " . "" . $fetch_site_plugin_link_r['order_no'] . ", " . "'" . addslashes($fetch_site_plugin_link_r['description']) . "', " . "'" . addslashes($fetch_site_plugin_link_r['url']) . "', " . "'" . addslashes($fetch_site_plugin_link_r['title_url']) . "' );";
        }
        db_fetch_assoc($results);
    }
    $results = fetch_site_plugin_s_attribute_type_map_rs($site_type_r['site_type']);
    if ($results) {
        $buffer .= $CRLF . $CRLF . "#" . $CRLF . "# Site Plugin System Attribute Type Map" . $CRLF . "#" . $CRLF;
        while ($site_plugin_s_attribute_type_map_r = db_fetch_assoc($results)) {
            $buffer .= $CRLF . "INSERT INTO s_site_plugin_s_attribute_type_map ( site_type, s_item_type_group, s_item_type, variable, s_attribute_type, lookup_attribute_val_restrict_ind ) " . "VALUES ( " . "'" . $site_plugin_s_attribute_type_map_r['site_type'] . "', " . "'" . $site_plugin_s_attribute_type_map_r['s_item_type_group'] . "', " . "'" . $site_plugin_s_attribute_type_map_r['s_item_type'] . "', " . "'" . addslashes($site_plugin_s_attribute_type_map_r['variable']) . "', " . "'" . $site_plugin_s_attribute_type_map_r['s_attribute_type'] . "', " . "'" . $site_plugin_s_attribute_type_map_r['lookup_attribute_val_restrict_ind'] . "' );";
        }
        db_fetch_assoc($results);
    }
    $results = fetch_site_plugin_s_attribute_type_lookup_map_rs($site_type_r['site_type']);
    if ($results) {
        $buffer .= $CRLF . $CRLF . "#" . $CRLF . "# Site Plugin System Attribute Type Lookup Map" . $CRLF . "#" . $CRLF;
        while ($site_plugin_s_attribute_type_lookup_map_r = db_fetch_assoc($results)) {
            $buffer .= $CRLF . "INSERT INTO s_site_plugin_s_attribute_type_lookup_map ( site_type, s_attribute_type, value, lookup_attribute_val ) " . "VALUES ( " . "'" . $site_plugin_s_attribute_type_lookup_map_r['site_type'] . "', " . "'" . $site_plugin_s_attribute_type_lookup_map_r['s_attribute_type'] . "', " . "'" . addslashes($site_plugin_s_attribute_type_lookup_map_r['value']) . "', " . "'" . addslashes($site_plugin_s_attribute_type_lookup_map_r['lookup_attribute_val']) . "' ); ";
        }
        db_fetch_assoc($results);
    }
    $results = fetch_site_attribute_type_rs($site_type_r['site_type']);
    if ($results) {
        $buffer .= $CRLF . $CRLF . "####################################################################################################" . $CRLF . "# Item Type / Attribute Type relationships" . $CRLF . "####################################################################################################";
        $attr_inserts = "";
        $list_of_attribute_types = NULL;
        while ($site_attribute_type_r = db_fetch_assoc($results)) {
            $list_of_attribute_types[] = $site_attribute_type_r['s_attribute_type'];
            $attr_inserts .= $CRLF . "INSERT INTO s_attribute_type ( s_attribute_type, description, prompt, input_type, display_type, s_field_type, site_type ) " . "VALUES ( " . "'" . $site_attribute_type_r['s_attribute_type'] . "', " . "'" . addslashes($site_attribute_type_r['description']) . "', " . "'" . addslashes($site_attribute_type_r['prompt']) . "', " . "'" . addslashes($site_attribute_type_r['input_type']) . "', " . "'" . addslashes($site_attribute_type_r['display_type']) . "', " . "'" . $site_attribute_type_r['s_field_type'] . "', " . "'" . $site_attribute_type_r['site_type'] . "' );";
        }
        db_fetch_assoc($results);
        $buffer .= $CRLF . $CRLF . "#" . $CRLF . "# Site Plugin Attribute Type(s)" . $CRLF . "#" . $CRLF;
        $buffer .= $attr_inserts;
        $results = fetch_site_item_attribute_type_rs($site_type_r['site_type']);
        if ($results) {
            $buffer .= $CRLF . $CRLF . "#" . $CRLF . "# Site Plugin Item Attribute Type Relationship(s)" . $CRLF . "#" . $CRLF;
            while ($site_item_attribute_type_r = db_fetch_assoc($results)) {
                $buffer .= $CRLF . "INSERT INTO s_item_attribute_type ( s_item_type, s_attribute_type, order_no, prompt, compulsory_ind ) " . "VALUES ( " . "'" . $site_item_attribute_type_r['s_item_type'] . "', " . "'" . $site_item_attribute_type_r['s_attribute_type'] . "', " . " " . $site_item_attribute_type_r['order_no'] . ", " . "'" . addslashes($site_item_attribute_type_r['prompt']) . "', " . "'" . ifempty($site_item_attribute_type_r['compulsory_ind'], 'N') . "' );";
            }
            db_fetch_assoc($results);
        }
    }
    $buffer .= $CRLF;
    return $buffer;
}
Example #3
0
        // Get rid of newlines.
        $schema_insert = str_replace("\n", "", $schema_insert);
        $schema_insert = str_replace("\r", "", $schema_insert);
        echo trim($schema_insert) . ";" . $crlf;
        $i++;
    }
    return TRUE;
}
if ($HTTP_VARS['op'] == 'export') {
    @set_time_limit(600);
    header("Cache-control: no-store");
    header("Pragma: no-store");
    header("Expires: 0");
    header("Content-disposition: attachment; filename=backup.sql");
    header("Content-type: application/octet-stream");
    $CRLF = get_user_browser_crlf();
    echo "# -------------------------------------------------------------" . $CRLF;
    echo "# " . get_opendb_title_and_version() . $CRLF;
    echo "# https://github.com/pellcorp/opendb" . $CRLF;
    echo "#" . $CRLF;
    echo "# " . get_opendb_lang_var('connected_to', get_opendb_config_var('db_server')) . $CRLF;
    echo "# " . get_opendb_lang_var('db_backup_generated', 'date', get_localised_timestamp(get_opendb_config_var('listings', 'print_listing_datetime_mask'))) . $CRLF;
    echo "# -------------------------------------------------------------" . $CRLF;
    // special all tables option reset $HTTP_VARS['tables'] array as a result
    if (strcasecmp($HTTP_VARS['all_tables'], 'y') === 0) {
        unset($HTTP_VARS['tables']);
        $opendb_tables_r = fetch_opendb_table_list_r();
        while (list(, $value) = each($opendb_tables_r)) {
            $HTTP_VARS['tables'][] = $value;
        }
    }
Example #4
0
/**
 * Generate a complete s_item_type script.
 * 
 * Data generated:
 * 	s_item_type
 * 	s_attribute_type's (Those not included in $_ATTRIBUTE_TYPES['core'])
 * 	s_item_attribute_type's
 * 	s_item_attribute_type_lookup (Those not included in $_ATTRIBUTE_TYPES['core'])
 */
function generate_s_item_type_sql($s_item_type)
{
    global $_CORE_ATTRIBUTE_TYPES;
    $CRLF = get_user_browser_crlf();
    $s_item_type_r = fetch_s_item_type_r($s_item_type);
    if ($s_item_type_r !== FALSE) {
        $type_sql = $CRLF . '#' . $CRLF . '# Item Type' . $CRLF . '#' . $CRLF . 'INSERT INTO s_item_type ( s_item_type, description, image ) VALUES ( \'' . $s_item_type . '\', \'' . addslashes($s_item_type_r['description']) . '\', \'' . addslashes($s_item_type_r['image']) . '\' );' . $CRLF;
        $results = fetch_item_type_group_rlshp_rs(NULL, $s_item_type);
        if ($results) {
            $type_sql .= $CRLF . '#' . $CRLF . '# Item Type Group Relationships' . $CRLF . '#' . $CRLF;
            while ($item_type_group_rlshp_r = db_fetch_assoc($results)) {
                $type_sql .= 'INSERT INTO s_item_type_group_rltshp ( s_item_type_group, s_item_type ) VALUES ( \'' . $item_type_group_rlshp_r['s_item_type_group'] . '\', \'' . $item_type_group_rlshp_r['s_item_type'] . '\' );' . $CRLF;
            }
            db_fetch_assoc($results);
        }
        $attr_sql = '';
        $item_attr_sql = $CRLF . '#' . $CRLF . '# Item Attribute Relationships' . $CRLF . '#';
        $attr_lookup_sql = '';
        $result = fetch_s_item_attribute_type_rs($s_item_type);
        if ($result) {
            $attr_added = array();
            while ($s_item_attribute_type_r = db_fetch_assoc($result)) {
                // Ensure to also check that the attribute has not already been encountered, in case we have duplicates
                // in s_item_attribute_type structure (such as CDTRACK for instance)
                if (strlen($s_item_attribute_type_r['site_type']) == 0 && (!is_array($_CORE_ATTRIBUTE_TYPES) || !in_array($s_item_attribute_type_r['s_attribute_type'], $_CORE_ATTRIBUTE_TYPES)) && !in_array($s_item_attribute_type_r['s_attribute_type'], $attr_added)) {
                    // Add s_attribute_type, so we do not insert it twice.
                    $attr_added[] = $s_item_attribute_type_r['s_attribute_type'];
                    $s_attribute_type_r = fetch_s_attribute_type_r($s_item_attribute_type_r['s_attribute_type']);
                    $attr_sql .= $CRLF . "INSERT INTO s_attribute_type ( s_attribute_type, description, prompt, input_type, input_type_arg1, input_type_arg2, input_type_arg3, input_type_arg4, input_type_arg5, display_type, display_type_arg1, display_type_arg2, display_type_arg3, display_type_arg4, display_type_arg5, listing_link_ind, file_attribute_ind, lookup_attribute_ind, multi_attribute_ind, s_field_type, site_type ) " . "VALUES ( '" . $s_attribute_type_r['s_attribute_type'] . "', " . "'" . addslashes($s_attribute_type_r['description']) . "', " . "'" . addslashes($s_attribute_type_r['prompt']) . "', " . "'" . $s_attribute_type_r['input_type'] . "', " . (strlen($s_attribute_type_r['input_type_arg1']) > 0 ? "'" . addslashes($s_attribute_type_r['input_type_arg1']) . "'" : "NULL") . ", " . (strlen($s_attribute_type_r['input_type_arg2']) > 0 ? "'" . addslashes($s_attribute_type_r['input_type_arg2']) . "'" : "NULL") . ", " . (strlen($s_attribute_type_r['input_type_arg3']) > 0 ? "'" . addslashes($s_attribute_type_r['input_type_arg3']) . "'" : "NULL") . ", " . (strlen($s_attribute_type_r['input_type_arg4']) > 0 ? "'" . addslashes($s_attribute_type_r['input_type_arg4']) . "'" : "NULL") . ", " . (strlen($s_attribute_type_r['input_type_arg5']) > 0 ? "'" . addslashes($s_attribute_type_r['input_type_arg5']) . "'" : "NULL") . ", " . "'" . $s_attribute_type_r['display_type'] . "'," . (strlen($s_attribute_type_r['display_type_arg1']) > 0 ? "'" . addslashes($s_attribute_type_r['display_type_arg1']) . "'" : "NULL") . ", " . (strlen($s_attribute_type_r['display_type_arg2']) > 0 ? "'" . addslashes($s_attribute_type_r['display_type_arg2']) . "'" : "NULL") . ", " . (strlen($s_attribute_type_r['display_type_arg3']) > 0 ? "'" . addslashes($s_attribute_type_r['display_type_arg3']) . "'" : "NULL") . ", " . (strlen($s_attribute_type_r['display_type_arg4']) > 0 ? "'" . addslashes($s_attribute_type_r['display_type_arg4']) . "'" : "NULL") . ", " . (strlen($s_attribute_type_r['display_type_arg5']) > 0 ? "'" . addslashes($s_attribute_type_r['display_type_arg5']) . "'" : "NULL") . ", " . "'" . $s_attribute_type_r['listing_link_ind'] . "', " . "'" . $s_attribute_type_r['file_attribute_ind'] . "', " . "'" . $s_attribute_type_r['lookup_attribute_ind'] . "', " . "'" . $s_attribute_type_r['multi_attribute_ind'] . "', " . (strlen($s_attribute_type_r['s_field_type']) > 0 ? "'" . $s_attribute_type_r['s_field_type'] . "'" : "NULL") . ", " . (strlen($s_attribute_type_r['site_type']) > 0 ? "'" . $s_attribute_type_r['s_field_type'] . "'" : "NULL") . ");";
                    $result2 = fetch_attribute_type_lookup_rs($s_item_attribute_type_r['s_attribute_type'], 'value ASC', FALSE);
                    if ($result2) {
                        $attr_lookup_sql .= $CRLF . '#' . $CRLF . '# Attribute Type Lookup (' . $s_item_attribute_type_r['s_attribute_type'] . ')' . $CRLF . '#';
                        while ($s_attribute_type_lookup_r = db_fetch_assoc($result2)) {
                            $attr_lookup_sql .= $CRLF . 'INSERT INTO s_attribute_type_lookup ( s_attribute_type, order_no, value, display, img, checked_ind ) VALUES ( \'' . $s_item_attribute_type_r['s_attribute_type'] . '\', ' . (is_numeric($s_attribute_type_lookup_r['order_no']) ? $s_attribute_type_lookup_r['order_no'] : 'NULL') . ', \'' . addslashes($s_attribute_type_lookup_r['value']) . '\', \'' . addslashes($s_attribute_type_lookup_r['display']) . '\', \'' . addslashes($s_attribute_type_lookup_r['img']) . '\', \'' . $s_attribute_type_lookup_r['checked_ind'] . '\' );';
                        }
                        db_fetch_assoc($result2);
                        $attr_lookup_sql .= $CRLF;
                    }
                }
                $item_attr_sql .= $CRLF . 'INSERT INTO s_item_attribute_type ( s_item_type, s_attribute_type, order_no, prompt, instance_attribute_ind, compulsory_ind, printable_ind, rss_ind ) VALUES ( \'' . $s_item_type . '\', \'' . $s_item_attribute_type_r['s_attribute_type'] . '\', ' . $s_item_attribute_type_r['order_no'] . ', ' . (strlen($s_item_attribute_type_r['prompt']) > 0 ? '\'' . $s_item_attribute_type_r['prompt'] . '\'' : 'NULL') . ', \'' . $s_item_attribute_type_r['instance_attribute_ind'] . '\', \'' . $s_item_attribute_type_r['compulsory_ind'] . '\', \'' . $s_item_attribute_type_r['printable_ind'] . '\', \'' . $s_item_attribute_type_r['rss_ind'] . '\' );';
            }
            db_fetch_assoc($result);
        }
        if (strlen($attr_sql) > 0) {
            $attr_sql = $CRLF . '#' . $CRLF . '# Attributes (non-core)' . $CRLF . '#' . $attr_sql;
        }
        $sqlscript = '#########################################################' . $CRLF . '# OpenDb ' . get_opendb_version() . ' \'' . $s_item_type . '\' Item Type' . $CRLF . '#########################################################' . $CRLF . $type_sql . $attr_sql . $CRLF . $item_attr_sql . $CRLF . $attr_lookup_sql;
        return $sqlscript;
    } else {
        return NULL;
    }
}