function setUp() { parent::setUp(); require_code('ecommerce'); require_code('catalogues'); require_code('catalogues2'); require_code('shopping'); require_lang('catalogues'); require_lang('shopping'); require_lang('ecommerce'); if (!is_null($GLOBALS['SITE_DB']->query_value_null_ok('catalogues', 'c_name', array('c_name' => 'storetesting' . strval(get_member()))))) { actual_delete_catalogue('storetesting' . strval(get_member())); } $this->access_mapping = array(db_get_first_id() => 4); // Creating cms catalogues object require_code('cms/pages/modules/cms_catalogues.php'); $this->cms_cat = new Module_cms_catalogues(); //Creating Shopping cart object require_code('site/pages/modules/shopping.php'); $this->shopping_cart = new Module_shopping(); $username = $GLOBALS['FORUM_DRIVER']->get_username(get_member()); $this->category_id = actual_add_catalogue('storetesting' . strval(get_member()), insert_lang(do_lang('DEFAULT_CATALOGUE_PRODUCTS_TITLE'), 2), '', 0, 1, '', 0, 1); $fields = array(array('ECOM_CAT_product_title', 'DESCRIPTION_TITLE', 'short_trans', 1, 1, 1, 1), array('ECOM_CAT_item_code', 'ECOM_CATD_item_code', 'random', 0, 1, 1, 1), array('ECOM_CAT_price_pre_tax', 'ECOM_CATD_price_pre_tax', 'float', 0, 1, 1, 1), array('ECOM_CAT_stock_level', 'ECOM_CATD_stock_level', 'integer', 0, 0, 1, 0), array('ECOM_CAT_stock_level_warn_at', 'ECOM_CATD_stock_level_warn_at', 'integer', 0, 0, 0, 0), array('ECOM_CAT_stock_level_maintain', 'ECOM_CATD_stock_level_maintain', 'tick', 0, 1, 0, 0), array('ECOM_CAT_tax_type', 'ECOM_CATD_tax_type', 'list', 0, 1, 0, 0, "0%|5%|17.5%", 0), array('ECOM_CAT_image', 'ECOM_CATD_image', 'picture', 0, 0, 1, 1), array('ECOM_CAT_weight', 'ECOM_CATD_weight', 'float', 0, 1, 0, 0), array('ECOM_CAT_description', 'DESCRIPTION_DESCRIPTION', 'long_trans', 0, 1, 1, 1)); foreach ($fields as $i => $field) { actual_add_catalogue_field('storetesting' . strval(get_member()), lang_code_to_default_content($field[0], false, 3), lang_code_to_default_content($field[1], true, 3), $field[2] == 'tick' ? 'list' : $field[2], $i, $field[3], $field[5], $field[6], $field[2] == 'tick' ? do_lang('NO') . '|' . do_lang('YES') : (array_key_exists(7, $field) ? $field[7] : ''), $field[4], array_key_exists(5, $field) ? $field[5] : 0, array_key_exists(5, $field) ? $field[5] : 0); } $catalogue_name = 'storetesting' . strval(get_member()); //Set Sample post values $fields = $GLOBALS['SITE_DB']->query_select('catalogue_fields', array('*'), array('c_name' => $catalogue_name)); foreach ($fields as $key => $val) { $type = $val['cf_type']; $id = $val['id']; switch ($type) { case 'integer': $_POST['field_' . strval($id)] = 4; break; case 'short_trans': $_POST['field_' . strval($id)] = 'Test field value'; break; case 'long_trans': $_POST['field_' . strval($id)] = 'Test field value'; break; case 'float': $_POST['field_' . strval($id)] = 68.34999999999999; break; case 'list': if ($val['cf_order'] = 6) { //Order 6 is tax $_POST['field_' . strval($id)] = 'Arizona=7.8%'; } elseif ($val['cf_order'] = 5) { //Order 5 yes keep stock "yes/no" $_POST['field_' . strval($id)] = 'yes'; } break; } } $map = $this->cms_cat->get_set_field_map($catalogue_name); $this->product_id = actual_add_catalogue_entry($this->category_id, $validated = 0, $notes = 'test note', $allow_rating = 1, $allow_comments = 1, $allow_trackbacks = 1, $map); }
/** * Standard import function. * * @param object The DB connection to import from * @param string The table prefix the target prefix is using * @param PATH The base directory we are importing from */ function import_reviews($db, $table_prefix, $old_base_dir) { require_code('menus2'); //check is the comment forum configured in ocPortal $this->test_for_comments_forum(); //include calatogue lib require_code('catalogues2'); // Can we comment the news? $com = 1; //get comments forum name $forum_name = get_option('comments_forum_name'); ocf_over_msn(); //used to fixed the correct forum prefix $forum_id = $GLOBALS['FORUM_DRIVER']->forum_id_from_name($forum_name); ocf_over_local(); //used to fixed the correct forum prefix //get specific reviews fields $catalogues = $db->query('SELECT * FROM ' . $table_prefix . 'reviews_sections'); $include_reviews_link = false; //include reviews link only once //go through all of the reviews sections foreach ($catalogues as $catalogue) { //make catalogue lang string $catalogue_name = strtoupper(preg_replace('#^[\\_\\.\\-]#', 'x', preg_replace('#[^\\w\\.\\-]#', '_', 'review_' . $catalogue['title']))); $catalogue['title'] = @html_entity_decode($catalogue['title'], ENT_QUOTES, get_charset()); $specific_fields = array(); // Add reviews catalogue if it doesn't already exist $current_review_catalogue = $GLOBALS['SITE_DB']->query_value_null_ok('catalogues', 'c_name', array('c_name' => strtolower($catalogue_name))); if (is_null($current_review_catalogue)) { $current_review_catalogue = actual_add_catalogue(strtolower($catalogue_name), $catalogue['title'], '', 0, 0, '', 30); $fields = array(array(do_lang('REVIEW_TITLE'), '', 'short_trans', 0, 1), array(do_lang('REVIEW_DESCRIPTION'), '', 'long_trans', 1, 1), array(do_lang('REVIEW_IMAGE'), '', 'picture', 0, 1), array(do_lang('REVIEW_REVIEW'), '', 'long_trans', 0, 1)); $specific_fields = array(); //add review/catalogue specific fields for ($i = 1; $i < 7; $i++) { if (strlen($catalogue['field' . strval($i)]) > 0) { //make lang string $lang_string = strtoupper(preg_replace('#^[\\_\\.\\-]#', 'x', preg_replace('#[^\\w\\.\\-]#', '_', $catalogue['field' . strval($i)]))); $lang_string = do_lang($lang_string, NULL, NULL, NULL, NULL, false); if (is_null($lang_string)) { $lang_string = $catalogue['field' . strval($i)]; } $fields[] = array($lang_string, '', 'long_trans', 0, 1); $specific_fields[] = $i; } } //add fields to catalogue foreach ($fields as $i => $field) { actual_add_catalogue_field(strtolower($catalogue_name), $field[0], '', $field[2], $i, $field[3], 1, 1, '', $field[4]); } } //import current reviews category $review_category_id = actual_add_catalogue_category(strtolower($catalogue_name), $catalogue['title'], '', '', NULL, ''); //include reviews link in main features menu if (!$include_reviews_link) { add_menu_item_simple('main_features', NULL, 'REVIEWS', 'site:catalogues:category:' . strval($review_category_id)); add_menu_item_simple('main_features', NULL, 'REVIEWS', 'site:catalogues:index:' . strtolower($catalogue_name)); $include_reviews_link = true; } $remappped_fields = collapse_1d_complexity('id', $GLOBALS['SITE_DB']->query_select('catalogue_fields', array('id'), array('c_name' => strtolower($catalogue_name)))); //select all reviews for current review catalogue $rows = $db->query('SELECT r.id AS review_id, r.title AS review_title, r.description AS review_description, r.field1 AS rf1, r.field2 AS rf2, r.field3 AS rf3, r.field4 AS rf4, r.field5 AS rf5, r.field6 AS rf6, r.field7 AS rf7, r.*, rc.title AS rc_title, rc.description AS rc_description, rc.field1 AS rcf1, rc.field2 AS rcf2, rc.field3 AS rcf3, rc.field4 AS rcf4, rc.field5 AS rcf5, rc.field6 AS rcf6, rc.field7 AS rcf7, rc.* FROM ' . $table_prefix . 'reviews r LEFT JOIN ' . $table_prefix . 'reviews_sections rc ON r.id_cat=rc.id WHERE r.id_cat=' . strval($catalogue['id'])); foreach ($rows as $row) { ocf_over_msn(); //used to fixed the correct forum prefix $map = array($remappped_fields[0] => html_to_comcode($row['review_title']), $remappped_fields[1] => html_to_comcode($row['review_description']), $remappped_fields[2] => $row['image'], $remappped_fields[3] => html_to_comcode($row['review'])); $map_next_ind = count($map); foreach ($specific_fields as $field_num) { if (!isset($remappped_fields[$map_next_ind])) { break; } // Don't want to import non-used fields $map[$remappped_fields[$map_next_ind]] = html_to_comcode($row['rf' . strval($field_num + 1)]); $map_next_ind++; } $new_id = actual_add_catalogue_entry($review_category_id, $row['validate'], '', 0, 0, 0, $map, $row['date'], $GLOBALS['FORUM_DRIVER']->get_member_from_username($row['author']), NULL, $row['click']); ocf_over_local(); //used to fixed the correct forum prefix //import rating too $this->_import_ratings($db, 'catalogues', $row['id'], $new_id, $row['rate'], $table_prefix); // Comments $comments = $db->query('SELECT * FROM ' . $table_prefix . 'reviews_comments WHERE id=' . strval($row['review_id']) . ' ORDER BY data'); if (!is_null($forum_id)) { foreach ($comments as $comment) { $member = $comment['id_autore']; //$GLOBALS['FORUM_DRIVER']->get_member_from_username($comment['userid']); ocf_over_msn(); //used to fixed the correct forum prefix if (is_null($member)) { $member = $GLOBALS['FORUM_DRIVER']->get_guest_id(); } ocf_over_local(); //used to fixed the correct forum prefix $title = $row['review_title']; $post = $comment['testo']; $content_url = build_url(array('page' => 'catalogues', 'id' => $new_id, 'type' => 'view'), get_module_zone('catalogues')); ocf_over_msn(); //used to fixed the correct forum prefix $GLOBALS['FORUM_DRIVER']->make_post_forum_topic($forum_name, 'reviews_' . strval($new_id), $member, $title, html_to_comcode($post), $row['review_title'], do_lang('COMMENT'), $content_url->evaluate()); ocf_over_local(); //used to fixed the correct forum prefix } } } } }
/** * Standard import function. * * @param object The DB connection to import from * @param string The table prefix the target prefix is using * @param PATH The base directory we are importing from */ function import_contacts($db, $table_prefix, $old_base_dir) { require_code('catalogues2'); require_code('catalogues'); // Add contacts catalogue if it doesn't already exist $test = $GLOBALS['SITE_DB']->query_value_null_ok('catalogues', 'c_name', array('c_name' => 'contacts')); if (is_null($test)) { actual_add_catalogue('contacts', lang_code_to_default_content('CONTACTS', false, 2), insert_lang('', 2), 0, 0, '', 30); $fields = array(array('CONTACT_FIRST_NAME', '', 'short_text', 0, 1), array('CONTACT_LAST_NAME', '', 'short_text', 1, 1), array('EMAIL_ADDRESS', '', 'short_text', 0, 1), array('CONTACT_COMPANY', '', 'short_text', 0, 1), array('CONTACT_HOMEADDRESS', '', 'short_text', 0, 1), array('CONTACT_CITY', '', 'short_text', 0, 1), array('CONTACT_HOMEPHONE', '', 'short_text', 0, 1), array('CONTACT_WORKPHONE', '', 'short_text', 0, 1), array('CONTACT_HOMEPAGE', '', 'short_text', 0, 1), array('CONTACT_IM', '', 'short_text', 0, 1), array('CONTACT_EVENTS', '', 'long_text', 0, 1), array('CONTACT_NOTES', '', 'long_text', 0, 1)); foreach ($fields as $i => $field) { actual_add_catalogue_field('contacts', lang_code_to_default_content($field[0], false, 3), insert_lang('', 2), $field[2], $i, $field[3], 1, 1, '', $field[4]); } } $id = actual_add_catalogue_category('contacts', 'ex-phpNuke', '', '', NULL, ''); $fields = collapse_1d_complexity('id', $GLOBALS['SITE_DB']->query_select('catalogue_fields', array('id'), array('c_name' => 'contacts'))); $contacts = $db->query('SELECT * FROM ' . $table_prefix . 'contactbook'); foreach ($contacts as $row) { $map = array($fields[0] => $row['firstname'], $fields[1] => $row['lastname'], $fields[2] => $row['email'], $fields[3] => $row['company'], $fields[4] => $row['homeaddress'], $fields[5] => $row['city'], $fields[6] => $row['homephone'], $fields[7] => $row['workphone'], $fields[8] => $row['homepage'], $fields[9] => $row['IM'], $fields[10] => $row['events'], $fields[11] => $row['notes']); actual_add_catalogue_entry($id, 1, '', 0, 0, 0, $map); } }
/** * Standard aed_module edit actualiser. * * @param ID_TEXT The entry being edited */ function edit_actualisation($old_name) { require_code('catalogues2'); $name = post_param('name', $old_name); $title = post_param('title', STRING_MAGIC_NULL); $description = post_param('description', STRING_MAGIC_NULL); $display_type = post_param_integer('display_type', fractional_edit() ? INTEGER_MAGIC_NULL : 0); $notes = post_param('notes', STRING_MAGIC_NULL); $submit_points = post_param_integer('submit_points', fractional_edit() ? INTEGER_MAGIC_NULL : 0); $ecommerce = post_param_integer('ecommerce', fractional_edit() ? INTEGER_MAGIC_NULL : 0); $send_view_reports = post_param('send_view_reports', STRING_MAGIC_NULL); if (!fractional_edit()) { if (post_param_integer('reset_category_permissions', 0) == 1) { if (function_exists('set_time_limit')) { @set_time_limit(0); } $start = 0; do { $rows = $GLOBALS['SITE_DB']->query_select('catalogue_categories', array('id'), array('c_name' => $name), '', 300, $start); foreach ($rows as $row) { $this->set_permissions(strval($row['id'])); } $start += 300; } while (array_key_exists(0, $rows)); } } $was_tree = $GLOBALS['SITE_DB']->query_value_null_ok('catalogues', 'c_is_tree', array('c_name' => $old_name)); if (is_null($was_tree)) { warn_exit(do_lang_tempcode('MISSING_RESOURCE')); } $is_tree = post_param_integer('is_tree', fractional_edit() ? INTEGER_MAGIC_NULL : 0); if (!fractional_edit()) { // What fields do we have? $old = array(); $new = array(); foreach ($_POST as $key => $val) { if (!is_string($val)) { continue; } if (get_magic_quotes_gpc()) { $val = stripslashes($val); } $matches = array(); if (preg_match('#new\\_field\\_(\\d+)\\_(.*)#A', $key, $matches) != 0) { $new[$matches[1]][$matches[2]] = $val; } elseif (preg_match('#existing\\_field\\_(\\d+)\\_(.*)#A', $key, $matches) != 0) { $old[$matches[1]][$matches[2]] = $val; } } $num_fields = 0; foreach ($new as $field) { if ($field['name'] != '') { $num_fields++; } } foreach ($old as $field) { if (!(array_key_exists('delete', $field) && $field['delete'] == '1')) { $num_fields++; } } if ($num_fields == 0) { warn_exit(do_lang_tempcode('NO_FIELDS')); } } if ($is_tree == 1 && $was_tree == 0) { catalogue_to_tree($name); } if ($is_tree == 0 && $was_tree == 1) { catalogue_from_tree($name); } $this->is_tree_catalogue = $is_tree == 1; actual_edit_catalogue($old_name, $name, $title, $description, $display_type, $notes, $submit_points, $ecommerce, $send_view_reports); $this->new_id = $name; if (!fractional_edit()) { // Now onto the fields // First we must rationalise the ordering $o = 0; $orderings = array(); foreach ($new as $current) { if (!array_key_exists('default', $current)) { warn_exit(do_lang_tempcode('IMPROPERLY_FILLED_IN')); } if (!array_key_exists('description', $current)) { warn_exit(do_lang_tempcode('IMPROPERLY_FILLED_IN')); } if (!array_key_exists('name', $current)) { warn_exit(do_lang_tempcode('IMPROPERLY_FILLED_IN')); } if (!array_key_exists('order', $current)) { warn_exit(do_lang_tempcode('IMPROPERLY_FILLED_IN')); } if (!array_key_exists('type', $current) || $current['type'] == '') { warn_exit(do_lang_tempcode('IMPROPERLY_FILLED_IN')); } if ($current['name'] != '') { if (!array_key_exists('order', $current) || $current['order'] == '') { $current['order'] = strval(count($new) + count($old)); } $orderings['new_' . strval($o)] = $current['order']; } $o++; } $o = 0; foreach ($old as $current) { if (!(array_key_exists('delete', $current) && $current['delete'] == '1')) { if (!array_key_exists('order', $current) || $current['order'] == '') { $current['order'] = strval(count($new) + count($old)); } $orderings['old_' . strval($o)] = $current['order']; } $o++; } asort($orderings); // Now add/edit them $o = 0; foreach ($new as $field) { $p = 0; foreach (array_keys($orderings) as $key) { if ($key == 'new_' . strval($o)) { $order = $p; } $p++; } $defines_order = array_key_exists('defines_order', $field) ? intval($field['defines_order']) : 0; $visible = array_key_exists('visible', $field) ? intval($field['visible']) : 0; $searchable = array_key_exists('searchable', $field) ? intval($field['searchable']) : 0; $required = array_key_exists('required', $field) ? intval($field['required']) : 0; $put_in_category = array_key_exists('put_in_category', $field) ? intval($field['put_in_category']) : 0; $put_in_search = array_key_exists('put_in_search', $field) ? intval($field['put_in_search']) : 0; if ($field['name'] != '') { actual_add_catalogue_field($name, $field['name'], $field['description'], $field['type'], $order, $defines_order, $visible, $searchable, $field['default'], $required, $put_in_category, $put_in_search); } $o++; } $o = 0; foreach ($old as $id => $field) { if (array_key_exists('delete', $field) && $field['delete'] == '1') { actual_delete_catalogue_field($id); } else { $p = 0; foreach (array_keys($orderings) as $key) { if ($key == 'old_' . strval($o)) { $order = $p; } $p++; } $defines_order = array_key_exists('defines_order', $field) ? intval($field['defines_order']) : 0; $visible = array_key_exists('visible', $field) ? intval($field['visible']) : 0; $searchable = array_key_exists('searchable', $field) ? intval($field['searchable']) : 0; $required = array_key_exists('required', $field) ? intval($field['required']) : 0; $put_in_category = array_key_exists('put_in_category', $field) ? intval($field['put_in_category']) : 0; $put_in_search = array_key_exists('put_in_search', $field) ? intval($field['put_in_search']) : 0; $field_type = array_key_exists('type', $field) ? $field['type'] : NULL; actual_edit_catalogue_field($id, $name, $field['name'], $field['description'], $order, $defines_order, $visible, $searchable, $field['default'], $required, $put_in_category, $put_in_search, $field_type); } $o++; } } // Do this last as it causes a main_sitemap decache which can cause memory errors if we do a warn_exit (i.e. we want the warn_exit's before this) if (!fractional_edit()) { $this->set_permissions($name); } }
/** * Standard modular install function. * * @param ?integer What version we're upgrading from (NULL: new install) * @param ?integer What hack version we're upgrading from (NULL: new-install/not-upgrading-from-a-hacked-version) */ function install($upgrade_from = NULL, $upgrade_from_hack = NULL) { require_lang('catalogues'); require_code('catalogues'); require_code('catalogues2'); if (is_null($upgrade_from)) { $GLOBALS['SITE_DB']->create_table('catalogues', array('c_name' => '*ID_TEXT', 'c_title' => 'SHORT_TRANS', 'c_description' => 'LONG_TRANS', 'c_display_type' => 'SHORT_INTEGER', 'c_is_tree' => 'BINARY', 'c_notes' => 'LONG_TEXT', 'c_add_date' => 'TIME', 'c_submit_points' => 'INTEGER', 'c_ecommerce' => 'BINARY', 'c_send_view_reports' => 'ID_TEXT')); $GLOBALS['SITE_DB']->create_table('catalogue_categories', array('id' => '*AUTO', 'c_name' => 'ID_TEXT', 'cc_title' => 'SHORT_TRANS', 'cc_description' => 'LONG_TRANS', 'rep_image' => 'URLPATH', 'cc_notes' => 'LONG_TEXT', 'cc_add_date' => 'TIME', 'cc_parent_id' => '?AUTO_LINK', 'cc_move_target' => '?AUTO_LINK', 'cc_move_days_lower' => 'INTEGER', 'cc_move_days_higher' => 'INTEGER')); $GLOBALS['SITE_DB']->create_index('catalogue_categories', 'catstoclean', array('cc_move_target')); $GLOBALS['SITE_DB']->create_index('catalogue_categories', 'cataloguefind', array('c_name')); } if (is_null($upgrade_from) || $upgrade_from < 6) { $GLOBALS['SITE_DB']->create_index('catalogue_categories', 'cc_parent_id', array('cc_parent_id')); } if (is_null($upgrade_from)) { $GLOBALS['SITE_DB']->create_table('catalogue_fields', array('id' => '*AUTO', 'c_name' => 'ID_TEXT', 'cf_name' => 'SHORT_TRANS', 'cf_description' => 'LONG_TRANS', 'cf_type' => 'ID_TEXT', 'cf_order' => 'INTEGER', 'cf_defines_order' => 'SHORT_INTEGER', 'cf_visible' => 'BINARY', 'cf_searchable' => 'BINARY', 'cf_default' => 'LONG_TEXT', 'cf_required' => 'BINARY', 'cf_put_in_category' => 'BINARY', 'cf_put_in_search' => 'BINARY')); $GLOBALS['SITE_DB']->create_table('catalogue_entries', array('id' => '*AUTO', 'c_name' => 'ID_TEXT', 'cc_id' => 'AUTO_LINK', 'ce_submitter' => 'USER', 'ce_add_date' => 'TIME', 'ce_edit_date' => '?TIME', 'ce_views' => 'INTEGER', 'ce_views_prior' => 'INTEGER', 'ce_validated' => 'BINARY', 'notes' => 'LONG_TEXT', 'allow_rating' => 'BINARY', 'allow_comments' => 'SHORT_INTEGER', 'allow_trackbacks' => 'BINARY', 'ce_last_moved' => 'INTEGER')); $GLOBALS['SITE_DB']->create_index('catalogue_entries', 'ce_views', array('ce_views')); $GLOBALS['SITE_DB']->create_index('catalogue_entries', 'ces', array('ce_submitter')); $GLOBALS['SITE_DB']->create_index('catalogue_entries', 'ce_validated', array('ce_validated')); $GLOBALS['SITE_DB']->create_table('catalogue_efv_long_trans', array('id' => '*AUTO', 'cf_id' => 'AUTO_LINK', 'ce_id' => 'AUTO_LINK', 'cv_value' => 'LONG_TRANS')); $GLOBALS['SITE_DB']->create_table('catalogue_efv_long', array('id' => '*AUTO', 'cf_id' => 'AUTO_LINK', 'ce_id' => 'AUTO_LINK', 'cv_value' => 'LONG_TEXT')); $GLOBALS['SITE_DB']->create_table('catalogue_efv_short_trans', array('id' => '*AUTO', 'cf_id' => 'AUTO_LINK', 'ce_id' => 'AUTO_LINK', 'cv_value' => 'SHORT_TRANS')); $GLOBALS['SITE_DB']->create_table('catalogue_efv_short', array('id' => '*AUTO', 'cf_id' => 'AUTO_LINK', 'ce_id' => 'AUTO_LINK', 'cv_value' => 'SHORT_TEXT')); } if (is_null($upgrade_from) || $upgrade_from < 6) { $GLOBALS['SITE_DB']->create_table('catalogue_entry_linkage', array('catalogue_entry_id' => '*AUTO_LINK', 'content_type' => 'ID_TEXT', 'content_id' => 'ID_TEXT')); $GLOBALS['SITE_DB']->create_index('catalogue_entry_linkage', 'custom_fields', array('content_type', 'content_id')); // This caches ancestor relationships. It is redundant to doing tree traversals on catalogue_categories.cc_id, allowing normal efficient SQL joins to be done instead // Note that self relationships (cc_id=cc_ancestor_id) are stored too, so that a single join covers that too. $GLOBALS['SITE_DB']->create_table('catalogue_cat_treecache', array('cc_id' => '*AUTO_LINK', 'cc_ancestor_id' => '*AUTO_LINK')); $GLOBALS['SITE_DB']->create_table('catalogue_childcountcache', array('cc_id' => '*AUTO_LINK', 'c_num_rec_children' => 'INTEGER', 'c_num_rec_entries' => 'INTEGER')); $GLOBALS['SITE_DB']->create_index('catalogue_cat_treecache', 'cc_ancestor_id', array('cc_ancestor_id')); $GLOBALS['SITE_DB']->create_table('catalogue_efv_float', array('id' => '*AUTO', 'cf_id' => 'AUTO_LINK', 'ce_id' => 'AUTO_LINK', 'cv_value' => '?REAL')); $GLOBALS['SITE_DB']->create_table('catalogue_efv_integer', array('id' => '*AUTO', 'cf_id' => 'AUTO_LINK', 'ce_id' => 'AUTO_LINK', 'cv_value' => '?INTEGER')); $GLOBALS['SITE_DB']->create_index('catalogue_efv_float', 'fcv_value', array('cv_value')); $GLOBALS['SITE_DB']->create_index('catalogue_efv_integer', 'itv_value', array('cv_value')); $GLOBALS['SITE_DB']->create_index('catalogue_efv_float', 'fcf_id', array('cf_id'), 'id'); $GLOBALS['SITE_DB']->create_index('catalogue_efv_integer', 'icf_id', array('cf_id'), 'id'); $GLOBALS['SITE_DB']->create_index('catalogue_efv_float', 'fce_id', array('ce_id'), 'id'); $GLOBALS['SITE_DB']->create_index('catalogue_efv_integer', 'ice_id', array('ce_id'), 'id'); $GLOBALS['SITE_DB']->create_index('catalogue_efv_float', 'cefv_f_combo', array('ce_id', 'cf_id'), 'id'); $GLOBALS['SITE_DB']->create_index('catalogue_efv_integer', 'cefv_i_combo', array('ce_id', 'cf_id'), 'id'); $GLOBALS['SITE_DB']->create_index('catalogue_efv_long', 'cefv_l_combo', array('ce_id', 'cf_id'), 'id'); $GLOBALS['SITE_DB']->create_index('catalogue_efv_short', 'cefv_s_combo', array('ce_id', 'cf_id'), 'id'); $GLOBALS['SITE_DB']->create_index('catalogue_efv_long_trans', 'cefv_lt_combo', array('ce_id', 'cf_id'), 'id'); $GLOBALS['SITE_DB']->create_index('catalogue_efv_short_trans', 'cefv_st_combo', array('ce_id', 'cf_id'), 'id'); } if (is_null($upgrade_from)) { // Add the default catalogues // ========================== $groups = $GLOBALS['FORUM_DRIVER']->get_usergroup_list(false, true); // Projects actual_add_catalogue('projects', lang_code_to_default_content('DEFAULT_CATALOGUE_PROJECTS_TITLE', false, 2), lang_code_to_default_content('DEFAULT_CATALOGUE_PROJECTS_DESCRIPTION', true, 3), 0, 0, '', 30); $fields = array(array('NAME', 'DESCRIPTION_NAME', 'short_trans', 1, 1), array('MAINTAINER', 'DESCRIPTION_MAINTAINER', 'user', 0, 1), array('DESCRIPTION', 'DESCRIPTION_DESCRIPTION', 'long_trans', 0, 1), array('PROJECT_PROGRESS', 'DESCRIPTION_PROJECT_PROGRESS', 'integer', 0, 1)); foreach ($fields as $i => $field) { actual_add_catalogue_field('projects', lang_code_to_default_content($field[0], false, 3), lang_code_to_default_content($field[1], true, 3), $field[2], $i, $field[3], 1, 1, '', $field[4]); } $cat_id = actual_add_catalogue_category('projects', lang_code_to_default_content('DEFAULT_CATALOGUE_PROJECTS_TITLE', false, 2), lang_code_to_default_content('DEFAULT_CATALOGUE_PROJECTS_DESCRIPTION', true, 3), '', NULL, ''); foreach (array_keys($groups) as $group_id) { $GLOBALS['SITE_DB']->query_insert('group_category_access', array('module_the_name' => 'catalogues_category', 'category_name' => strval($cat_id), 'group_id' => $group_id)); $GLOBALS['SITE_DB']->query_insert('group_category_access', array('module_the_name' => 'catalogues_catalogue', 'category_name' => 'projects', 'group_id' => $group_id)); } add_menu_item_simple('main_content', NULL, 'DEFAULT_CATALOGUE_PROJECTS_TITLE', '_SEARCH:catalogues:type=index:id=projects'); // Modifications actual_add_catalogue('modifications', lang_code_to_default_content('DEFAULT_CATALOGUE_MODIFICATIONS_TITLE', false, 2), lang_code_to_default_content('DEFAULT_CATALOGUE_MODIFICATIONS_DESCRIPTION', true, 3), 1, 0, '', 60); $fields = array(array('NAME', 'DESCRIPTION_NAME', 'short_trans', 1, 1), array('IMAGE', 'DESCRIPTION_MODIFICATION_IMAGE_URL', 'picture', 0, 0), array('STATUS', 'DESCRIPTION_MODIFICATION_STATUS', 'short_trans', 0, 1), array('URL', 'DESCRIPTION_URL', 'url', 0, 0), array('DESCRIPTION', 'DESCRIPTION_DESCRIPTION', 'long_trans', 0, 1), array('AUTHOR', 'DESCRIPTION_AUTHOR', 'short_text', 0, 1)); foreach ($fields as $i => $field) { actual_add_catalogue_field('modifications', lang_code_to_default_content($field[0], false, 3), lang_code_to_default_content($field[1], true, 3), $field[2], $i, $field[3], 1, 1, '', $field[4]); } foreach (array_keys($groups) as $group_id) { $GLOBALS['SITE_DB']->query_insert('group_category_access', array('module_the_name' => 'catalogues_catalogue', 'category_name' => 'modifications', 'group_id' => $group_id)); } add_menu_item_simple('main_content', NULL, 'DEFAULT_CATALOGUE_MODIFICATIONS_TITLE', '_SEARCH:catalogues:type=index:id=modifications'); // Hosted-sites actual_add_catalogue('hosted', lang_code_to_default_content('DEFAULT_CATALOGUE_HOSTED_TITLE', false, 2), lang_code_to_default_content('DEFAULT_CATALOGUE_HOSTED_DESCRIPTION', true, 3), 0, 0, '', 0); $fields = array(array('NAME', 'DESCRIPTION_NAME', 'short_trans', 1, 1), array('URL', 'DESCRIPTION_URL', 'url', 0, 0), array('DESCRIPTION', 'DESCRIPTION_DESCRIPTION', 'long_trans', 0, 0)); foreach ($fields as $i => $field) { actual_add_catalogue_field('hosted', lang_code_to_default_content($field[0], false, 2), lang_code_to_default_content($field[1], true, 3), $field[2], $i, $field[3], 1, 1, '', $field[4]); } $cat_id = actual_add_catalogue_category('hosted', lang_code_to_default_content('DEFAULT_CATALOGUE_HOSTED_TITLE', false, 2), lang_code_to_default_content('DEFAULT_CATALOGUE_HOSTED_DESCRIPTION', true, 3), '', NULL, ''); foreach (array_keys($groups) as $group_id) { $GLOBALS['SITE_DB']->query_insert('group_category_access', array('module_the_name' => 'catalogues_category', 'category_name' => strval($cat_id), 'group_id' => $group_id)); $GLOBALS['SITE_DB']->query_insert('group_category_access', array('module_the_name' => 'catalogues_catalogue', 'category_name' => 'hosted', 'group_id' => $group_id)); } add_menu_item_simple('main_content', NULL, 'DEFAULT_CATALOGUE_HOSTED_TITLE', '_SEARCH:catalogues:type=index:id=hosted'); // Links $links_category = actual_add_catalogue('links', lang_code_to_default_content('DEFAULT_CATALOGUE_LINKS_TITLE', false, 2), lang_code_to_default_content('DEFAULT_CATALOGUE_LINKS_DESCRIPTION', true, 3), 2, 1, '', 0); $fields = array(array('TITLE', 'DESCRIPTION_TITLE', 'short_trans', 1, 1, 1), array('URL', 'DESCRIPTION_URL', 'url', 0, 1, 0), array('DESCRIPTION', 'DESCRIPTION_DESCRIPTION', 'long_trans', 0, 0, 1)); foreach ($fields as $i => $field) { actual_add_catalogue_field('links', lang_code_to_default_content($field[0], false, 2), lang_code_to_default_content($field[1], true, 3), $field[2], $i, $field[3], 1, 1, '', $field[4], $field[5]); } foreach (array_keys($groups) as $group_id) { $GLOBALS['SITE_DB']->query_insert('group_category_access', array('module_the_name' => 'catalogues_category', 'category_name' => strval($links_category), 'group_id' => $group_id)); $GLOBALS['SITE_DB']->query_insert('group_category_access', array('module_the_name' => 'catalogues_catalogue', 'category_name' => 'links', 'group_id' => $group_id)); } add_menu_item_simple('main_content', NULL, 'DEFAULT_CATALOGUE_LINKS_TITLE', '_SEARCH:catalogues:type=index:id=links'); // FAQs actual_add_catalogue('faqs', lang_code_to_default_content('DEFAULT_CATALOGUE_FAQS_TITLE', false, 2), lang_code_to_default_content('DEFAULT_CATALOGUE_FAQS_DESCRIPTION', true, 3), 0, 0, '', 0); $fields = array(array('QUESTION', 'DESCRIPTON_QUESTION', 'short_trans', 0, 1, 1), array('ANSWER', '_DESCRIPTION_ANSWER', 'long_trans', 0, 1, 1), array('ORDER', 'DESCRIPTION_ORDER', 'auto_increment', 1, 0, 0)); foreach ($fields as $i => $field) { actual_add_catalogue_field('faqs', lang_code_to_default_content($field[0], false, 2), lang_code_to_default_content($field[1], true, 3), $field[2], $i, $field[3], $field[5], 1, '', $field[4]); } $cat_id = actual_add_catalogue_category('faqs', lang_code_to_default_content('DEFAULT_CATALOGUE_FAQS_TITLE', false, 2), lang_code_to_default_content('DEFAULT_CATALOGUE_FAQS_DESCRIPTION', true, 3), '', NULL, ''); foreach (array_keys($groups) as $group_id) { $GLOBALS['SITE_DB']->query_insert('group_category_access', array('module_the_name' => 'catalogues_category', 'category_name' => strval($cat_id), 'group_id' => $group_id)); $GLOBALS['SITE_DB']->query_insert('group_category_access', array('module_the_name' => 'catalogues_catalogue', 'category_name' => 'faqs', 'group_id' => $group_id)); } add_menu_item_simple('main_content', NULL, 'DEFAULT_CATALOGUE_FAQS_TITLE', '_SEARCH:catalogues:type=index:id=faqs'); // Contacts actual_add_catalogue('contacts', lang_code_to_default_content('CONTACTS', false, 2), lang_code_to_default_content('DEFAULT_CATALOGUE_CONTACTS_DESCRIPTION', true, 3), 0, 0, '', 30); $fields = array(array('CONTACT_FIRST_NAME', '', 'short_text', 0, 1), array('CONTACT_LAST_NAME', '', 'short_text', 1, 1), array('EMAIL_ADDRESS', '', 'short_text', 0, 1), array('CONTACT_COMPANY', '', 'short_text', 0, 1), array('CONTACT_HOMEADDRESS', '', 'short_text', 0, 1), array('CONTACT_CITY', '', 'short_text', 0, 1), array('CONTACT_HOMEPHONE', '', 'short_text', 0, 1), array('CONTACT_WORKPHONE', '', 'short_text', 0, 1), array('CONTACT_HOMEPAGE', '', 'short_text', 0, 1), array('CONTACT_IM', '', 'short_text', 0, 1), array('CONTACT_EVENTS', '', 'long_text', 0, 1), array('CONTACT_NOTES', '', 'long_text', 0, 1), array('CONTACT_PHOTO', '', 'picture', 0, 1)); foreach ($fields as $i => $field) { actual_add_catalogue_field('contacts', lang_code_to_default_content($field[0], false, 3), insert_lang('', 2), $field[2], $i, $field[3], 1, 1, '', $field[4]); } actual_add_catalogue_category('contacts', lang_code_to_default_content('CONTACTS', false, 2), '', '', NULL, ''); add_menu_item_simple('main_content', NULL, 'CONTACTS', '_SEARCH:catalogues:type=index:id=contacts'); $projects = add_menu_item_simple('collab_features', NULL, 'DEFAULT_CATALOGUE_PROJECTS_TITLE'); add_menu_item_simple('collab_features', $projects, 'VIEW', '_SEARCH:catalogues:id=projects:type=index', 0, 0, true, do_lang('ZONE_BETWEEN'), 1); add_menu_item_simple('collab_features', $projects, 'ADD', '_SEARCH:cms_catalogues:catalogue_name=projects:type=add_entry', 0, 0, true, do_lang('ZONE_BETWEEN'), 1); } if (is_null($upgrade_from) || $upgrade_from < 6) { $GLOBALS['SITE_DB']->create_index('catalogue_entries', 'ce_add_date', array('ce_add_date'), 'id'); $GLOBALS['SITE_DB']->create_index('catalogue_entries', 'ce_c_name', array('c_name'), 'id'); } if (!is_null($upgrade_from) && $upgrade_from < 4) { $GLOBALS['SITE_DB']->delete_table_field('catalogues', 'c_own_template'); $GLOBALS['SITE_DB']->add_table_field('catalogues', 'c_cat_tab', 'BINARY', 0); $GLOBALS['SITE_DB']->add_table_field('catalogues', 'c_ecommerce', 'BINARY', 0); $GLOBALS['SITE_DB']->add_table_field('catalogue_entries', 'ce_views_prior', 'INTEGER'); $GLOBALS['SITE_DB']->add_table_field('catalogues', 'c_send_view_reports', 'ID_TEXT', 'never'); $GLOBALS['SITE_DB']->add_table_field('catalogue_categories', 'cc_move_target', '?AUTO_LINK', NULL); $GLOBALS['SITE_DB']->add_table_field('catalogue_categories', 'cc_move_days_lower', 'INTEGER', 30); $GLOBALS['SITE_DB']->add_table_field('catalogue_categories', 'cc_move_days_higher', 'INTEGER', 60); $GLOBALS['SITE_DB']->add_table_field('catalogue_entries', 'ce_last_moved', 'INTEGER', 0); $GLOBALS['SITE_DB']->query('UPDATE ' . $GLOBALS['SITE_DB']->get_table_prefix() . 'catalogue_entries SET ce_last_moved=ce_add_date'); } if (is_null($upgrade_from) || $upgrade_from < 3) { $cat_id = actual_add_catalogue('products', lang_code_to_default_content('DEFAULT_CATALOGUE_PRODUCTS_TITLE', false, 2), lang_code_to_default_content('DEFAULT_CATALOGUE_PRODUCTS_DESCRIPTION', false, 2), 1, 1, '', 0, 1); $fields = array(array('ECOM_CAT_product_title', 'DESCRIPTION_TITLE', 'short_trans', 1, 1, 1, 1), array('ECOM_CAT_item_code', 'ECOM_CATD_item_code', 'random', 0, 1, 1, 1), array('ECOM_CAT_price_pre_tax', 'ECOM_CATD_price_pre_tax', 'float', 0, 1, 1, 1), array('ECOM_CAT_stock_level', 'ECOM_CATD_stock_level', 'integer', 0, 0, 1, 0), array('ECOM_CAT_stock_level_warn_at', 'ECOM_CATD_stock_level_warn_at', 'integer', 0, 0, 0, 0), array('ECOM_CAT_stock_level_maintain', 'ECOM_CATD_stock_level_maintain', 'tick', 0, 1, 0, 0), array('ECOM_CAT_tax_type', 'ECOM_CATD_tax_type', 'list', 0, 1, 0, 0, "0%|5%|17.5%", 0), array('ECOM_CAT_image', 'ECOM_CATD_image', 'picture', 0, 0, 1, 1), array('ECOM_CAT_weight', 'ECOM_CATD_weight', 'float', 0, 1, 0, 0), array('ECOM_CAT_description', 'DESCRIPTION_DESCRIPTION', 'long_trans', 0, 1, 1, 1)); foreach ($fields as $i => $field) { actual_add_catalogue_field('products', lang_code_to_default_content($field[0], false, 3), lang_code_to_default_content($field[1], true, 3), $field[2] == 'tick' ? 'list' : $field[2], $i, $field[3], $field[5], $field[6], $field[2] == 'tick' ? do_lang('NO') . '|' . do_lang('YES') : (array_key_exists(7, $field) ? $field[7] : ''), $field[4], array_key_exists(5, $field) ? $field[5] : 0, array_key_exists(5, $field) ? $field[5] : 0); } foreach (array_keys($groups) as $group_id) { $GLOBALS['SITE_DB']->query_insert('group_category_access', array('module_the_name' => 'catalogues_category', 'category_name' => strval($cat_id), 'group_id' => $group_id)); $GLOBALS['SITE_DB']->query_insert('group_category_access', array('module_the_name' => 'catalogues_catalogue', 'category_name' => 'products', 'group_id' => $group_id)); } add_menu_item_simple('main_content', NULL, 'DEFAULT_CATALOGUE_PRODUCTS_TITLE', '_SEARCH:catalogues:type=category:catalogue_name=products'); add_specific_permission('CATALOGUES', 'high_catalogue_entry_timeout', false); } if (is_null($upgrade_from) || $upgrade_from < 3) { $GLOBALS['SITE_DB']->create_index('catalogue_efv_long', '#lcv_value', array('cv_value'), 'id'); $GLOBALS['SITE_DB']->create_index('catalogue_efv_short', '#scv_value', array('cv_value'), 'id'); } if (!is_null($upgrade_from) && $upgrade_from < 3) { $GLOBALS['SITE_DB']->add_table_field('catalogue_entries', 'allow_trackbacks', 'BINARY', 1); $GLOBALS['SITE_DB']->add_table_field('catalogue_entries', 'c_name', 'ID_TEXT'); $GLOBALS['SITE_DB']->add_table_field('catalogue_categories', 'rep_image', 'URLPATH'); $GLOBALS['SITE_DB']->add_table_field('catalogue_fields', 'cf_default', 'LONG_TEXT'); $GLOBALS['SITE_DB']->add_table_field('catalogue_fields', 'cf_searchable', 'BINARY', 1); $entries = $GLOBALS['SITE_DB']->query_select('catalogue_entries e LEFT JOIN ' . $GLOBALS['SITE_DB']->get_table_prefix() . 'catalogue_categories c ON e.cc_id=c.id', array('e.id', 'c.c_name')); foreach ($entries as $entry) { $GLOBALS['SITE_DB']->query_update('catalogue_entries', array('c_name' => $entry['c_name']), array('id' => $entry['id']), '', 1); } } if (!is_null($upgrade_from) && $upgrade_from < 4) { $GLOBALS['SITE_DB']->alter_table_field('catalogues', 'c_own_pages', 'SHORT_INTEGER', 'c_display_type'); $GLOBALS['SITE_DB']->add_table_field('catalogue_fields', 'cf_put_in_category', 'BINARY', 1); $GLOBALS['SITE_DB']->add_table_field('catalogue_fields', 'cf_put_in_search', 'BINARY', 1); } if (is_null($upgrade_from) || $upgrade_from < 5) { //$GLOBALS['SITE_DB']->create_index('catalogue_efv_long','ilcv_value',array('cv_value'),'id'); Not allowed, LONG_TEXT can not be in key. People shouldn't order by this anyway $GLOBALS['SITE_DB']->create_index('catalogue_efv_short', 'iscv_value', array('cv_value'), 'id'); $GLOBALS['SITE_DB']->create_index('catalogue_efv_long', 'lcf_id', array('cf_id'), 'id'); $GLOBALS['SITE_DB']->create_index('catalogue_efv_short', 'scf_id', array('cf_id'), 'id'); $GLOBALS['SITE_DB']->create_index('catalogue_efv_long_trans', 'ltcf_id', array('cf_id'), 'id'); $GLOBALS['SITE_DB']->create_index('catalogue_efv_short_trans', 'stcf_id', array('cf_id'), 'id'); $GLOBALS['SITE_DB']->create_index('catalogue_efv_long', 'lce_id', array('ce_id'), 'id'); $GLOBALS['SITE_DB']->create_index('catalogue_efv_short', 'sce_id', array('ce_id'), 'id'); $GLOBALS['SITE_DB']->create_index('catalogue_efv_long_trans', 'ltce_id', array('ce_id'), 'id'); $GLOBALS['SITE_DB']->create_index('catalogue_efv_short_trans', 'stce_id', array('ce_id'), 'id'); $GLOBALS['SITE_DB']->create_index('catalogue_entries', 'ce_cc_id', array('cc_id'), 'id'); $GLOBALS['SITE_DB']->create_index('catalogue_categories', 'ftjoin_cctitle', array('cc_title')); $GLOBALS['SITE_DB']->create_index('catalogue_categories', 'ftjoin_ccdescrip', array('cc_description')); $GLOBALS['SITE_DB']->create_index('catalogue_efv_long_trans', 'ltcv_value', array('cv_value')); $GLOBALS['SITE_DB']->create_index('catalogue_efv_short_trans', 'stcv_value', array('cv_value')); } if (!is_null($upgrade_from) && $upgrade_from < 6) { require_code('catalogues2'); rebuild_catalogue_cat_treecache(); // Move floats and integers into their own new tables if (function_exists('set_time_limit')) { @set_time_limit(0); } $sql_integer = db_string_equal_to('cf_type', 'integer') . ' OR ' . db_string_equal_to('cf_type', 'auto_increment') . ' OR ' . db_string_equal_to('cf_type', 'random') . ' OR ' . db_string_equal_to('cf_type', 'user') . ' OR ' . db_string_equal_to('cf_type', 'tick'); $sql_float = db_string_equal_to('cf_type', 'float'); foreach (array($sql_float => 'float', $sql_integer => 'integer') as $where => $new_type) { $fields = $GLOBALS['SITE_DB']->query('SELECT id FROM ' . get_table_prefix() . 'catalogue_fields WHERE ' . $where); foreach ($fields as $field) { do { $or_list = ''; $rows = $GLOBALS['SITE_DB']->query_select('catalogue_efv_short', array('*'), array('cf_id' => $field['id']), '', 100); foreach ($rows as $row) { if ($or_list != '') { $or_list .= ' OR '; } $or_list .= 'ce_id=' . strval($row['ce_id']) . ' AND cf_id=' . strval($row['cf_id']); unset($row['id']); if ($new_type == 'float') { $row['cv_value'] = $row['cv_value'] == '' ? NULL : floatval($row['cv_value']); } elseif ($new_type == 'integer') { $row['cv_value'] = $row['cv_value'] == '' ? NULL : intval($row['cv_value']); } $GLOBALS['SITE_DB']->query_insert('catalogue_efv_' . $new_type, $row); } if ($or_list != '') { $GLOBALS['SITE_DB']->query('DELETE FROM ' . get_table_prefix() . 'catalogue_efv_short WHERE ' . $or_list); } } while (count($rows) != 0); } } } }