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); } } } }
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']; } } } } }