示例#1
0
 /**
  * Get custom fields for ecommerce product
  *
  * @param	AUTO_LINK	Product entry ID
  * @param	array			Map where product details are placed
  */
 function get_custom_product_map_fields($id, &$map)
 {
     require_code('feedback');
     require_lang('shopping');
     require_code('ecommerce');
     require_code('images');
     $shopping_cart_url = build_url(array('page' => 'shopping', 'type' => 'misc'), '_SELF');
     $product_title = NULL;
     if (array_key_exists('FIELD_0', $map)) {
         $product_title = $map['FIELD_0_PLAIN'];
         if (is_object($product_title)) {
             $product_title = @html_entity_decode(strip_tags($product_title->evaluate()), ENT_QUOTES);
         }
     }
     $licence = method_exists($this, 'get_agreement') ? $this->get_agreement(strval($id)) : '';
     $fields = method_exists($this, 'get_needed_fields') ? $this->get_needed_fields(strval($id)) : NULL;
     if (array_key_exists('FIELD_3', $map)) {
         if (!is_object($map['FIELD_3'])) {
             $out_of_stock = $map['FIELD_3'] == '0';
         } else {
             $out_of_stock = $map['FIELD_3']->evaluate() == '0';
         }
     } else {
         $out_of_stock = false;
     }
     $cart_url = build_url(array('page' => 'shopping', 'type' => 'add_item', 'hook' => 'catalogue_items'), '_SELF');
     $purchase_mod_url = build_url(array('page' => 'purchase', 'type' => $licence == '' ? is_null($fields) ? 'pay' : 'details' : 'licence', 'product' => strval($id), 'id' => $id), '_SELF');
     $map['CART_BUTTONS'] = do_template('CATALOGUE_ENTRY_ADD_TO_CART', array('OUT_OF_STOCK' => $out_of_stock, 'ACTION_URL' => $cart_url, 'PRODUCT_ID' => strval($id), 'ALLOW_OPTOUT_TAX' => get_option('allow_opting_out_of_tax'), 'PURCHASE_ACTION_URL' => $purchase_mod_url, 'CART_URL' => $shopping_cart_url));
     $map['CART_LINK'] = show_cart_image();
 }
示例#2
0
 /**
  * The UI to show a catalogue category.
  *
  * @return tempcode		The UI
  */
 function view_catalogue_category()
 {
     require_code('feedback');
     require_code('images');
     $id = get_param_integer('id', -1);
     if ($id == -1) {
         $id = $GLOBALS['SITE_DB']->query_value('catalogue_categories', 'MIN(id)', array('c_name' => get_param('catalogue_name'), 'cc_parent_id' => NULL));
     }
     $GLOBALS['FEED_URL'] = find_script('backend') . '?mode=catalogues&filter=' . strval($id);
     $categories = $GLOBALS['SITE_DB']->query_select('catalogue_categories', array('*'), array('id' => $id), '', 1);
     if (!array_key_exists(0, $categories)) {
         return warn_screen(get_page_title('CATALOGUES'), do_lang_tempcode('MISSING_RESOURCE'));
     }
     $category = $categories[0];
     // Permission for here?
     if (!has_category_access(get_member(), 'catalogues_catalogue', $category['c_name'])) {
         access_denied('CATALOGUE_ACCESS');
     }
     if (get_value('disable_cat_cat_perms') !== '1' && !has_category_access(get_member(), 'catalogues_category', strval($id))) {
         access_denied('CATEGORY_ACCESS');
     }
     $catalogue_name = $category['c_name'];
     $root = get_param_integer('root', NULL);
     $_title = get_translated_text($category['cc_title']);
     $catalogues = $GLOBALS['SITE_DB']->query_select('catalogues', array('*'), array('c_name' => $catalogue_name), '', 1);
     if (!array_key_exists(0, $catalogues)) {
         warn_exit(do_lang_tempcode('CATALOGUE_NOT_FOUND', $catalogue_name));
     }
     $catalogue = $catalogues[0];
     $tpl_set = $catalogue_name;
     if (is_ecommerce_catalogue($catalogue_name)) {
         $is_ecommerce = true;
         $tpl_set = 'products';
     } else {
         $is_ecommerce = false;
     }
     $title_to_use = do_lang_tempcode($catalogue_name . '__CATALOGUE_CATEGORY', escape_html($_title));
     $title_to_use_2 = do_lang($catalogue_name . '__CATALOGUE_CATEGORY', $_title, NULL, NULL, NULL, false);
     if (is_null($title_to_use_2)) {
         $title_to_use = do_lang_tempcode('DEFAULT__CATALOGUE_CATEGORY', escape_html($_title));
         $title_to_use_2 = do_lang('DEFAULT__CATALOGUE_CATEGORY', $_title);
     }
     $awards = array();
     if (addon_installed('awards')) {
         require_code('awards');
         $awards = array_merge($awards, find_awards_for('catalogue', $catalogue_name));
         $awards = array_merge($awards, find_awards_for('catalogue_category', strval($id)));
     }
     $title = get_page_title($title_to_use, false, NULL, NULL, $awards);
     if (is_object($title_to_use_2)) {
         $title_to_use_2 = $title_to_use_2->evaluate();
     }
     seo_meta_load_for('catalogue_category', strval($id), $title_to_use_2);
     $max = get_param_integer('max', 30);
     $start = get_param_integer('start', 0);
     list($entry_buildup, $sorting, $entries, $max_rows) = get_catalogue_category_entry_buildup($id, $catalogue_name, $catalogue, 'CATEGORY', $tpl_set, $max, $start, NULL, $root);
     // Build up subcategories
     $rows_subcategories = $GLOBALS['SITE_DB']->query_select('catalogue_categories', array('*'), array('cc_parent_id' => $id), '', 600);
     if (count($rows_subcategories) == 300) {
         $rows_subcategories = array();
     }
     // Performance issue, manual browsing will be needed
     foreach ($rows_subcategories as $i => $subcategory) {
         $rows_subcategories[$i]['cc_title'] = get_translated_text($subcategory['cc_title']);
     }
     for ($i = 0; $i < count($rows_subcategories); $i++) {
         for ($j = $i + 1; $j < count($rows_subcategories); $j++) {
             if ($rows_subcategories[$i]['cc_title'] > $rows_subcategories[$j]['cc_title']) {
                 $temp = $rows_subcategories[$j];
                 $rows_subcategories[$j] = $rows_subcategories[$i];
                 $rows_subcategories[$i] = $temp;
             }
         }
     }
     $subcategories = new ocp_tempcode();
     $uses_rep_image = false;
     foreach ($rows_subcategories as $sc) {
         if ($sc['rep_image'] != '') {
             $uses_rep_image = true;
         }
     }
     foreach ($rows_subcategories as $sc) {
         if (get_value('disable_cat_cat_perms') !== '1' && !has_category_access(get_member(), 'catalogues_category', strval($sc['id']))) {
             continue;
         }
         $child_counts = count_catalogue_category_children($sc['id']);
         $num_children = $child_counts['num_children'];
         $num_entries = $child_counts['num_entries_children'];
         $map = array('page' => '_SELF', 'id' => $sc['id'], 'type' => 'category');
         if (!is_null($root)) {
             $map['root'] = $root;
         }
         $url = build_url($map, '_SELF');
         if ($uses_rep_image || $is_ecommerce) {
             $display_string = do_lang_tempcode($catalogue['c_is_tree'] == 1 ? 'CATEGORY_SUBORDINATE' : 'CATEGORY_SUBORDINATE_2', integer_format($num_entries), integer_format($num_children));
             if ($sc['rep_image']) {
                 $rep_image = do_image_thumb($sc['rep_image'], $sc['cc_title'], $sc['cc_title'], false);
             } else {
                 $rep_image = new ocp_tempcode();
             }
             $description = $sc['cc_description'];
             $description = get_translated_tempcode($description);
             $ajax_edit_url = '_SEARCH:cms_catalogues:type=__edit_category:id=' . strval($sc['id']);
             $subcategories->attach(do_template('CATEGORY_' . $tpl_set . '_ENTRY', array('_GUID' => '871f5f5195fcb426fac716e35569d6a3', 'ID' => strval($sc['id']), 'NAME_FIELD' => 'title', 'AJAX_EDIT_URL' => $ajax_edit_url, 'URL' => $url, 'REP_IMAGE' => $rep_image, 'CHILDREN' => $display_string, 'NAME' => $sc['cc_title'], 'NAME_PLAIN' => $sc['cc_title'], 'DESCRIPTION' => $description, 'NUM_CHILDREN' => integer_format($num_children), 'NUM_CHILDREN_RECURSIVE' => integer_format($child_counts['num_children_children']), 'NUM_ENTRIES' => integer_format($num_entries), 'NUM_ENTRIES_DIRECT' => integer_format($child_counts['num_entries'])), NULL, false, 'CATEGORY_ENTRY'));
         } else {
             $subcategories->attach(do_template('CATALOGUE_' . $tpl_set . '_SUBCATEGORY', array('ID' => strval($sc['id']), 'CATALOGUE' => $catalogue_name, 'URL' => $url, 'NUM_CHILDREN' => integer_format($num_children), 'NUM_CHILDREN_RECURSIVE' => integer_format($child_counts['num_children_children']), 'NUM_ENTRIES' => integer_format($num_entries), 'NUM_ENTRIES_DIRECT' => integer_format($child_counts['num_entries']), 'NAME' => $sc['cc_title']), NULL, false, 'CATALOGUE_DEFAULT_SUBCATEGORY'));
         }
     }
     if (!$subcategories->is_empty()) {
         if ($uses_rep_image) {
             $subcategories = do_template('CATEGORY_LIST', array('_GUID' => '3041620a953e52229f752b1bccfbeee3', 'CONTENT' => $subcategories));
         } else {
             $subcategories = do_template('CATALOGUE_' . $tpl_set . '_SUBCATEGORY_WRAP', array('CATALOGUE' => $catalogue_name, 'CONTENT' => $subcategories), NULL, false, 'CATALOGUE_DEFAULT_SUBCATEGORY_WRAP');
         }
     }
     // Links to add to catalogue category etc
     if (has_actual_page_access(NULL, 'cms_catalogues', NULL, get_value('disable_cat_cat_perms') === '1' ? array('catalogues_catalogue', $catalogue_name) : array('catalogues_catalogue', $catalogue_name, 'catalogues_category', strval($id)), 'submit_midrange_content')) {
         $add_link = build_url(array('page' => 'cms_catalogues', 'type' => 'add_entry', 'catalogue_name' => $catalogue_name, 'category_id' => $id), get_module_zone('cms_catalogues'));
     } else {
         $add_link = new ocp_tempcode();
     }
     if (has_actual_page_access(NULL, 'cms_catalogues', NULL, get_value('disable_cat_cat_perms') === '1' ? array('catalogues_catalogue', $catalogue_name) : array('catalogues_catalogue', $catalogue_name, 'catalogues_category', strval($id)), 'submit_cat_midrange_content')) {
         $add_cat_url = build_url(array('page' => 'cms_catalogues', 'type' => 'add_category', 'catalogue_name' => $catalogue_name, 'parent_id' => $id), get_module_zone('cms_catalogues'));
     } else {
         $add_cat_url = new ocp_tempcode();
     }
     if (has_actual_page_access(NULL, 'cms_catalogues', NULL, get_value('disable_cat_cat_perms') === '1' ? array('catalogues_catalogue', $catalogue_name) : array('catalogues_catalogue', $catalogue_name, 'catalogues_category', strval($id)), 'edit_cat_midrange_content')) {
         $edit_cat_url = build_url(array('page' => 'cms_catalogues', 'type' => '_edit_category', 'catalogue_name' => $catalogue_name, 'id' => $id), get_module_zone('cms_catalogues'));
     } else {
         $edit_cat_url = new ocp_tempcode();
     }
     if (has_actual_page_access(NULL, 'cms_catalogues', NULL, get_value('disable_cat_cat_perms') === '1' ? array('catalogues_catalogue', $catalogue_name) : array('catalogues_catalogue', $catalogue_name), 'edit_cat_highrange_content')) {
         $edit_catalogue_url = build_url(array('page' => 'cms_catalogues', 'type' => '_edit_catalogue', 'id' => $catalogue_name), get_module_zone('cms_catalogues'));
     } else {
         $edit_catalogue_url = new ocp_tempcode();
     }
     require_code('templates_results_browser');
     $browser = results_browser(do_lang_tempcode('ENTRIES'), $id, $start, 'start', $max, 'max', $max_rows, $root, 'category', true);
     if ($catalogue['c_is_tree'] == 1) {
         $tree = catalogue_category_breadcrumbs($id, $root);
         if (!$tree->is_empty()) {
             $tree->attach(do_template('BREADCRUMB_ESCAPED'));
         }
         if (has_specific_permission(get_member(), 'open_virtual_roots')) {
             $url = get_self_url(false, false, is_null(get_param('root', NULL)) ? array('root' => $id) : array('root' => $id == -1 ? NULL : $id));
             $tree->attach(hyperlink($url, escape_html($_title), false, false, do_lang_tempcode('VIRTUAL_ROOT')));
         } else {
             $tree->attach('<span>' . escape_html($_title) . '</span>');
         }
     } else {
         $tree = new ocp_tempcode();
         $url = build_url(array('page' => '_SELF', 'type' => 'index', 'id' => $catalogue_name), '_SELF');
         $catalogue_title = get_translated_text($catalogue['c_title']);
         $tree->attach(hyperlink($url, escape_html($catalogue_title), false, false, do_lang_tempcode('GO_BACKWARDS_TO', escape_html($catalogue_name))));
         $tree->attach(do_template('BREADCRUMB_ESCAPED'));
         $tree->attach(escape_html($_title));
     }
     breadcrumb_add_segment($tree);
     if (is_null($root)) {
         breadcrumb_set_parents(array(array('_SELF:_SELF:misc' . ($is_ecommerce ? ':ecommerce=1' : ''), do_lang('CATALOGUES'))));
     }
     $GLOBALS['META_DATA'] += array('created' => date('Y-m-d', $category['cc_add_date']), 'creator' => '', 'publisher' => '', 'modified' => '', 'type' => get_translated_text($catalogue['c_title']) . ' category', 'title' => $_title, 'identifier' => '_SEARCH:catalogues:category:' . strval($id), 'description' => get_translated_text($category['cc_description']));
     $rep_image_str = $category['rep_image'];
     if ($rep_image_str != '') {
         $GLOBALS['META_DATA'] += array('image' => (url_is_local($rep_image_str) ? get_custom_base_url() . '/' : '') . $rep_image_str);
     }
     $cart_link = new ocp_tempcode();
     if ($is_ecommerce) {
         if (get_forum_type() != 'ocf') {
             warn_exit(do_lang_tempcode('NO_OCF'));
         }
         require_code('shopping');
         require_lang('shopping');
         $cart_link = show_cart_image();
     }
     return do_template('CATALOGUE_' . $tpl_set . '_CATEGORY_SCREEN', array('ID' => strval($id), 'ADD_DATE_RAW' => strval($category['cc_add_date']), 'TITLE' => $title, '_TITLE' => $_title, 'TAGS' => get_loaded_tags('catalogue_categories'), 'CATALOGUE' => $catalogue_name, 'BROWSER' => $browser, 'SORTING' => $sorting, 'ADD_LINK' => $add_link, 'ADD_CAT_URL' => $add_cat_url, 'EDIT_CAT_URL' => $edit_cat_url, 'EDIT_CATALOGUE_URL' => $edit_catalogue_url, 'ENTRIES' => $entry_buildup, 'SUBCATEGORIES' => $subcategories, 'DESCRIPTION' => get_translated_tempcode($category['cc_description']), 'CART_LINK' => $cart_link, 'TREE' => $tree), NULL, false, 'CATALOGUE_DEFAULT_CATEGORY_SCREEN');
 }