Пример #1
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;
}
Пример #2
0
 /**
  * need to work out page_no, items_per_page, offset, etc
  *
  * This method will set the $this->_is_next_page and $this->is_previous_page
  * flags.
  */
 function _queryListing(&$HTTP_VARS)
 {
     // reset errors
     $this->_errors = NULL;
     $at_least_one_search_field_populated = FALSE;
     $input_field_values_r = array();
     $this->_search_query = NULL;
     // need to get a list of all input field values to pass into the querySite call.
     $results = fetch_site_plugin_input_field_rs($this->_type);
     if ($results) {
         while ($input_field_r = db_fetch_assoc($results)) {
             if (isset($HTTP_VARS[$input_field_r['field']]) && strlen($HTTP_VARS[$input_field_r['field']]) > 0) {
                 $field_value = trim($HTTP_VARS[$input_field_r['field']]);
                 $at_least_one_search_field_populated = TRUE;
                 if ($input_field_r['field_type'] == 'scan-isbn' || $input_field_r['field_type'] == 'scan-upc') {
                     // Determine type of scanner.
                     if (strrpos($HTTP_VARS[$input_field_r['field']], '.')) {
                         // cuecat
                         if ($input_field_r['field_type'] == 'scan-isbn') {
                             $scanCode = get_cuecat_isbn_code($field_value);
                         } else {
                             $scanCode = get_cuecat_upc_code($field_value);
                         }
                     } else {
                         //non-cuecat or modified cuecat
                         if ($input_field_r['field_type'] == 'scan-isbn') {
                             $scanCode = get_isbn_code($field_value);
                         } else {
                             $scanCode = get_upc_code($field_value);
                         }
                     }
                     if ($scanCode !== FALSE) {
                         $field_value = $scanCode;
                     }
                 }
                 $input_field_values_r[$input_field_r['field']] = $field_value;
                 $this->_search_query[] = array('field' => $input_field_r['field'], 'value' => $field_value, 'prompt' => $input_field_r['prompt'], 'field_type' => $input_field_r['field_type']);
             }
         }
         //while
         db_free_result($results);
     }
     // only continue if at least one input field was populated with a value.
     if ($at_least_one_search_field_populated) {
         unset($this->_item_list_rs);
         // initialise if not set.
         if (!is_numeric($HTTP_VARS['page_no'])) {
             $this->_page_no = 1;
         } else {
             $this->_page_no = $HTTP_VARS['page_no'];
         }
         if ($this->_page_no > 1) {
             $this->_is_previous_page = TRUE;
         } else {
             $this->_is_previous_page = FALSE;
         }
         // default, must be overriden by the individual plugins.
         $this->_is_next_page = FALSE;
         $offset = 0;
         if ($this->_items_per_page > 0 && $this->_page_no > 1) {
             $offset = $this->_items_per_page * ($HTTP_VARS['page_no'] - 1) + 1;
         }
         $this->_total_count = 0;
         // if its not a legal type, don't pass it on
         if (!is_exists_item_type($HTTP_VARS['s_item_type'])) {
             unset($HTTP_VARS['s_item_type']);
         }
         $this->_http_vars = $HTTP_VARS;
         // do not want to pass page_no through
         $this->_http_vars['page_no'] = NULL;
         // now at this point we need to grab the $items_per_page and
         // page_no values.
         if ($this->queryListing($this->_page_no, $this->_items_per_page, $offset, $HTTP_VARS['s_item_type'], $input_field_values_r)) {
             // no need for this anymore
             $this->_http_vars = NULL;
             // if a single item returned, we will populate the itemData at this point too
             if ($this->getRowCount() == 1 && $this->isPreviousPage() === FALSE) {
                 $rowData = $this->getRowData(0);
                 $this->_item_data_r = NULL;
                 // call the queryItem function directly here.
                 $return_val = $this->_queryItem($rowData['attributes'], $HTTP_VARS['s_item_type']);
                 if ($return_val) {
                     return TRUE;
                 } else {
                     return FALSE;
                 }
             } else {
                 // in some cases, the plugin will not be able to provide this
                 // information, but where it can, we can derive the is_next_page flag,
                 // other plugins, would have to call setNextPage() function instead.
                 if ($this->_items_per_page > 0 && $this->_total_count > $offset + $this->_items_per_page) {
                     $this->_is_next_page = TRUE;
                 }
                 // expect the call to querySite to set the is_next_page flag
                 return TRUE;
             }
         } else {
             // no need for this anymore
             $this->_http_vars = NULL;
             return FALSE;
         }
     } else {
         // if($at_least_one_search_field_populated)
         // nothing found.
         return TRUE;
     }
 }
Пример #3
0
/**
 * This function is responsible for grouping input fields that
 * should appear grouped together. Any hidden fields, will be
 * grouped together, so the array that gets returned will look like:
 * 
 * array(hidden_fields=>array(
 * 			$input_field_r, $input_field_r, ...),
 * 		 display_fields=>array(
 * 				array(prompt=>'field group prompt',
 * 					fieldset=>array(
 * 						$input_field_r, $input_field_r, ....)
 * 					)
 *		)
 * )
 */
function get_site_type_input_fields($HTTP_VARS, $site_plugin_r, $item_r)
{
    global $titleMaskCfg;
    $input_fields_rs = NULL;
    $sifresults = fetch_site_plugin_input_field_rs($site_plugin_r['site_type']);
    if ($sifresults) {
        $display_field_r = NULL;
        while ($input_field_r = db_fetch_assoc($sifresults)) {
            // Only if we are are refreshing an item.
            if (is_not_empty_array($item_r)) {
                $titleMaskCfg->reset();
                $value = $titleMaskCfg->expand_title($item_r, $input_field_r['refresh_mask']);
            } else {
                if ($input_field_r['field_type'] != 'hidden') {
                    $titleMaskCfg->reset();
                    // a kludge to support feature request #816240 - failure when adding an item should return previous search
                    $value = ifempty($titleMaskCfg->expand_title($HTTP_VARS, $input_field_r['refresh_mask']), $input_field_r['default_value']);
                } else {
                    $value = $input_field_r['default_value'];
                }
            }
            switch ($input_field_r['field_type']) {
                case 'hidden':
                    $input_fields_rs[] = array(name => $input_field_r['field'], type => 'hidden', value => $value);
                    break;
                default:
                    if (strlen($input_field_r['prompt']) > 0) {
                        if ($inrow) {
                            $input_fields_rs[] = $display_field_r;
                            $display_field_r = NULL;
                            $inrow = FALSE;
                        }
                        $display_field_r['prompt'] = $input_field_r['prompt'];
                        $display_field_r['type'] = 'fieldset';
                        $display_field_r['fieldset'][] = array(name => $input_field_r['field'], type => 'text', value => $value);
                        $inrow = TRUE;
                    } else {
                        if (!$inrow) {
                            $newrow = TRUE;
                            $input_fields_rs['fieldset'][] = $input_field_r;
                        }
                    }
                    break;
            }
            //switch
        }
        db_free_result($sifresults);
        if ($display_field_r != NULL) {
            $input_fields_rs[] = $display_field_r;
        }
    }
    return $input_fields_rs;
}