/** * 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); } }
/** * Delete a catalogue. * * @param ID_TEXT The name of the catalogue */ function actual_delete_catalogue($name) { // Delete lang $rows = $GLOBALS['SITE_DB']->query_select('catalogues', array('c_description', 'c_title'), array('c_name' => $name), '', 1); if (!array_key_exists(0, $rows)) { warn_exit(do_lang_tempcode('MISSING_RESOURCE')); } $myrow = $rows[0]; // Delete anything involved (ha ha destruction!) if (function_exists('set_time_limit')) { @set_time_limit(0); } do { $entries = collapse_1d_complexity('id', $GLOBALS['SITE_DB']->query_select('catalogue_entries', array('id'), array('c_name' => $name), '', 500)); foreach ($entries as $entry) { actual_delete_catalogue_entry($entry); } } while (array_key_exists(0, $entries)); do { $categories = collapse_1d_complexity('id', $GLOBALS['SITE_DB']->query_select('catalogue_categories', array('id'), array('c_name' => $name), '', 30)); foreach ($categories as $category) { actual_delete_catalogue_category($category, true); } } while (array_key_exists(0, $categories)); $fields = collapse_1d_complexity('id', $GLOBALS['SITE_DB']->query_select('catalogue_fields', array('id'), array('c_name' => $name))); foreach ($fields as $field) { actual_delete_catalogue_field($field); } $GLOBALS['SITE_DB']->query_delete('catalogues', array('c_name' => $name), '', 1); delete_lang($myrow['c_title']); delete_lang($myrow['c_description']); $GLOBALS['SITE_DB']->query_delete('group_category_access', array('module_the_name' => 'catalogues_catalogue', 'category_name' => $name)); $GLOBALS['SITE_DB']->query_delete('gsp', array('module_the_name' => 'catalogues_catalogue', 'category_name' => $name)); log_it('DELETE_CATALOGUE', $name); }