public function save_as() { if (!$this->user->hasPermission('modify', 'module/journal2')) { throw new Exception('You do not have permissions to modify Journal2 module'); } if (!isset($this->get_data['category'])) { throw new Exception('Parameter category was not found'); } $category = $this->get_data['category']; if (!isset($this->get_data['theme_id'])) { throw new Exception('Parameter theme_id was not found'); } $skin_id = $this->get_data['theme_id']; if (!isset($this->post_data['name'])) { throw new Exception('Parameter name was not found'); } $name = $this->post_data['name']; if (!isset($this->post_data['settings'])) { throw new Exception('Parameter settings was not found'); } $settings = $this->post_data['settings']; /* get parent id */ $parent_id = $skin_id; if ($skin_id >= 100) { $query = $this->db->query("SELECT parent_id FROM " . DB_PREFIX . "journal2_skins WHERE `skin_id` = '" . (int) $skin_id . "'"); if ($query->num_rows) { $parent_id = $query->row['parent_id']; } else { $parent_id = 1; } } /* insert new skin into db */ $this->db->query("INSERT INTO " . DB_PREFIX . "journal2_skins SET `skin_name` = '" . $this->db->escape($name) . "', `parent_id` = '" . (int) $parent_id . "'"); $new_skin_id = $this->db->getLastId(); /* save skin data */ $this->db->query("INSERT INTO " . DB_PREFIX . "journal2_settings (`theme_id`, `key`, `category`, `value`, `serialized`) (SELECT " . $new_skin_id . ", `key`, `category`, `value`, `serialized` FROM " . DB_PREFIX . "journal2_settings WHERE `theme_id` = '" . (int) $skin_id . "')"); $journal_skin = new Journal2Skin($this->db, $new_skin_id); $journal_skin->save($category, $settings); return $new_skin_id; }