function __construct($table, $record_id) { global $CFG; $this->table = $table; $this->record_id = $CFG->include_id > 0 ? $CFG->include_id : $record_id; $this->row = DB::getRecord($this->table, $this->record_id, 0, 1); $this->db_fields = DB::getTableFields($this->table); $this->db_subtables = DB::getSubtables($this->table); $this->db_subtables = !$this->db_subtables ? array() : $this->db_subtables; $this->area_i = 0; $this->current_area = 0; $page_id = Control::getPageId($CFG->url, $CFG->is_tab); $corresponding_form = Control::getControls($page_id, 'form', $CFG->is_tab); if ($corresponding_form) { $k = key($corresponding_form); if ($corresponding_form[$k]['params'] = 'Form') { foreach ($corresponding_form[$k]['methods'] as $method) { $args = Control::parseArguments($method['arguments'], 'Form', $method['method']); $name = $args['name'] ? $args['name'] : $args['value']; $this->form_method_args[$name] = $args; } } } }
function save() { global $CFG; if ($_REQUEST['bypass_save'] || $CFG->save_called || strstr($_REQUEST['form_name'], 'form_filters')) { return false; } $this->save_called = true; $CFG->save_called = true; if (!$this->get_called && $this->record_id > 0) { if (!is_array(self::$old_info_prev)) { $this->old_info = DB::getRecord($this->table, $this->record_id, 0, 1); self::$old_info_prev = $this->old_info; } else { $this->old_info = self::$old_info_prev; } $subtables = DB::getSubtables($this->name); if (is_array($subtables)) { foreach ($subtables as $subtable) { if (!DB::tableExists($this->table . '_' . $subtable)) { continue; } if (strstr($subtable, 'grid_')) { $name_parts = explode('grid_', $subtable); $name = $name_parts[1]; $this->old_info[$name] = DB::getGridValues($this->table . '_grid_' . $name, $subtable_fields, $this->record_id); } elseif (strstr($subtable, 'files')) { //$files = DB::getFiles($this->table.'_files',$this->record_id); } else { if ($this->info['cat_selects'] && $this->info['cat_selects'][$subtable]) { $cats = DB::getCats($this->table . '_' . $subtable, $this->record_id); if ($cats) { foreach ($cats as $cat) { $this->old_info['cat_selects'][$subtable][] = $cat['row']['c_id']; } } } } } } } /* if ($CFG->backstage_mode && !empty($_REQUEST['trigger_field'])) { if (is_array($_REQUEST['trigger_field'])) { foreach ($_REQUEST['trigger_field'] as $k => $tfield) { self::emailNotify($tfield,$_REQUEST['trigger_value'][$k],$_REQUEST['email_field'][$k],$_REQUEST['email_table'][$k],$_REQUEST['email_record'][$k]); } $this->bypass_email = true; } } */ /* if ($CFG->backstage_mode && !empty($_REQUEST['trigger_field1'])) { if (is_array($_REQUEST['trigger_field1'])) { foreach ($_REQUEST['trigger_field1'] as $k => $tfield) { if (!empty($tfield)) { self::createRecord($_REQUEST['create_record_table'][$k],$tfield,$_REQUEST['trigger_value'][$k]); } } } } */ if ($_FILES[$this->name]['name']) { foreach ($_FILES[$this->name]['name'] as $input_name => $file_name) { if ($file_name) { $temp_files[] = Upload::saveTemp($this->name, $input_name); } } if (is_array($temp_files)) { foreach ($temp_files as $file_info) { $field_name = $file_info['input_name']; if ($file_info['error']) { $this->errors[$field_name] = $file_info['error']; } else { $this->temp_files[$field_name] = $file_info['filename']; $CFG->temp_files[$field_name] = $file_info['filename']; $this->temp_descs[$field_name] = $file_info['file_desc']; } } } } if ($this->info && !$this->errors) { if ($CFG->auto_create_table) { if (!DB::tableExists($this->table)) { if (DB::createTable($this->table, $_REQUEST['db_fields'], $_REQUEST['radioinputs'], $this->ignore_fields)) { $this->messages[$this->table] = $CFG->table_created; } else { $this->errors[] = $CFG->table_creation_error; } } } if (!$this->errors) { $insert_values = $this->info; if (is_array($this->ignore_fields)) { foreach ($this->ignore_fields as $i_name => $i_table) { unset($insert_values[$i_name]); } } if (is_array($this->includes)) { foreach ($this->includes as $i_table => $i_info) { if (is_array($this->ignore_fields)) { foreach ($this->info as $key => $value) { if (array_key_exists($key, $this->ignore_fields) && $this->ignore_fields[$key] == $i_table) { $i_values[$key] = $value; } } } if (!$this->record_id) { $include_ids[$i_table] = DB::insert($i_table, $i_values); $this->include_ids = $include_ids; } else { DB::update($i_table, $i_values, $i_info['id']); } } } if (!$this->record_id) { if ($include_ids) { $t_fields = DB::getTableFields($this->table, 1); if (is_array($t_fields)) { foreach ($include_ids as $i_table => $i_id) { if (!in_array($i_table . '_include_id', $t_fields)) { db_query('ALTER TABLE ' . $this->table . ' ADD ' . $i_table . '_include_id INT( 10 ) UNSIGNED NOT NULL '); } $insert_values[$i_table . '_include_id'] = $i_id; } } } if ($this->record_id = DB::insert($this->table, $insert_values, false, $this->ignore_fields)) { $this->record_created = true; $CFG->id = $this->record_id; $this->info['id'] = $this->record_id; $this->messages[] = $CFG->form_save_message; } else { $this->errors[] = $CFG->form_save_error; } } else { DB::saveImageOrder($_REQUEST['file_order'], $this->table); if (DB::update($this->table, $insert_values, $this->record_id, $this->ignore_fields) != -1) { $this->record_created = false; $this->messages[$this->record_id] = $CFG->form_update_message; if ($this->table == 'admin_users' && $CFG->url != 'users') { User::logOut(1); User::logIn($this->info['user'], $this->info['pass']); } } else { $this->errors[$this->record_id] = $CFG->form_update_error; } } } if (!$this->errors && is_array($this->temp_files)) { foreach ($this->temp_files as $field_name => $file_name) { $field_name_parts = explode('__', $field_name); $field_name_n = $field_name_parts[0]; $file_reqs = $_REQUEST['files'][$field_name_n]; $image_sizes = $file_reqs['image_sizes'] ? $file_reqs['image_sizes'] : $CFG->image_sizes; if (Upload::save($file_name, $field_name_n, $this->table, $this->record_id, $file_reqs['dir'], $image_sizes, $field_name)) { $this->messages[$file_name] = $CFG->file_save_message; unset($this->temp_files[$field_name]); unset($CFG->temp_files[$field_name]); } else { $this->errors[$file_name] = $CFG->file_save_error; } } } if ($_REQUEST['file_descs']) { foreach ($_REQUEST['file_descs'] as $i => $desc) { Upload::saveDescriptions($this->table, false, $i); } } } }
<?php include 'lib/common.php'; String::magicQuotesOff(); //print_ar($_REQUEST); $action = $_REQUEST['action']; if ($action == 'delete') { if (is_array($_REQUEST['rows'])) { foreach ($_REQUEST['rows'] as $table => $rows) { if (!$table || $table == 'undefined') { continue; } if (is_array($rows)) { $subtables = DB::getSubtables($table); foreach ($rows as $id) { if (is_array($_REQUEST['sub_records'])) { DB::deleteRecursive($table, $id); } elseif (!db_delete($table, $id)) { $errors[] = $CFG->ajax_delete_error; } DB::deleteFiles($table . '_files', $id); DB::deleteCats($table, $id); if ($_REQUEST['delete_controls']) { $f_key = $table == 'admin_tabs' ? 'tab_id' : 'page_id'; $sql = "\n\t\t\t\t\t\t\tDELETE admin_controls.*,admin_controls_methods.* \n\t\t\t\t\t\t\tFROM admin_controls\n\t\t\t\t\t\t\tLEFT JOIN admin_controls_methods ON (admin_controls_methods.control_id = admin_controls.id)\n\t\t\t\t\t\t\tWHERE admin_controls.{$f_key} = {$id}"; if (!db_query($sql)) { $errors[] = $CFG->ajax_delete_error; } } } }
function save() { global $CFG; if ($_REQUEST['bypass_save'] || $CFG->save_called || strstr($_REQUEST['form_name'], 'form_filters')) { return false; } $this->save_called = true; $CFG->save_called = true; if (!$this->get_called && $this->record_id > 0) { if (!is_array(self::$old_info_prev)) { $this->old_info = DB::getRecord($this->table, $this->record_id, 0, 1); self::$old_info_prev = $this->old_info; } else { $this->old_info = self::$old_info_prev; } $subtables = DB::getSubtables($this->name); if (is_array($subtables)) { foreach ($subtables as $subtable) { if (!DB::tableExists($this->table . '_' . $subtable)) { continue; } if (strstr($subtable, 'grid_')) { $name_parts = explode('grid_', $subtable); $name = $name_parts[1]; $this->old_info[$name] = DB::getGridValues($this->table . '_grid_' . $name, $subtable_fields, $this->record_id); } elseif (strstr($subtable, 'files')) { //$files = DB::getFiles($this->table.'_files',$this->record_id); } else { if ($this->info['cat_selects']) { $cats = DB::getCats($this->table . '_' . $subtable, $this->record_id); if ($cats) { foreach ($cats as $cat) { $this->old_info['cat_selects'][$subtable][] = $cat['row']['c_id']; } } } } } } } if ($_FILES[$this->name]['name']) { foreach ($_FILES[$this->name]['name'] as $input_name => $file_name) { if ($file_name) { $temp_files[] = Upload::saveTemp($this->name, $input_name); } } if (is_array($temp_files)) { foreach ($temp_files as $file_info) { $field_name = $file_info['input_name']; if ($file_info['error']) { $this->errors[$field_name] = $file_info['error']; } else { $this->temp_files[$field_name] = $file_info['filename']; $CFG->temp_files[$field_name] = $file_info['filename']; $this->temp_descs[$field_name] = $file_info['file_desc']; } } } } }