5 * @copyright Copyright 2010, Cake. (http://trpgtools-onweb.sourceforge.jp/)
7 * @package TRPG Data Bank
9 * @author Cake <cake_67@users.sourceforge.jp>
10 * @license http://www.opensource.org/licenses/mit-license.php The MIT License
11 * @link http://trpgtools-onweb.sourceforge.jp/
14 class DefaultProfilesController extends AppController {
16 var $name = 'DefaultProfiles';
23 var $disableTokenActions = array();
27 function beforeFilter() {
28 parent::beforeFilter();
31 $this->cacheAction = array(
37 function beforeRender()
39 parent::beforeRender();
41 $this->set_public_flag4view();
45 function admin_edit($profile_id = null) {
47 $this->Session->setFlash(__('Invalid data.', true));
48 $this->redirect(array('controller' => 'systems', 'action'=>'admin_index'));
51 $profile = $this->get_profile4profile_id($profile_id);
52 if (empty($profile)) {
53 $this->Session->setFlash(__('Invalid Profile', true));
54 $this->redirect(array('controller' => 'systems', 'action'=>'admin_index'));
58 $this->checkEditOtherSystem($profile['Profile']['system_id']);
60 if (!empty($this->data)) {
61 $this->post_data = $this->data;
62 $this->data = array();
65 if ($profile['Profile']['profile_type'] == 'checkbox') {
68 $this->data['CharactersHasProfile'] = $this->_set_new_characters_has_profile($this->post_data['CharactersHasProfile'], $profile_id, array(), $allow_blank);
70 foreach ($this->data['CharactersHasProfile'] as $k => $v) {
71 $this->data['DefaultProfile'][$k]['profile_id'] = $profile_id;
72 if (!empty($v['profile_select_id'])) {
73 $this->data['DefaultProfile'][$k]['profile_select_id'] = $v['profile_select_id'];
75 if (!empty($v['profile_table_id'])) {
76 $this->data['DefaultProfile'][$k]['profile_table_id'] = $v['profile_table_id'];
78 if (!empty($v['profile_table_static_id'])) {
79 $this->data['DefaultProfile'][$k]['profile_table_static_id'] = $v['profile_table_static_id'];
82 if (!isset($v['value'])) {
83 $this->data['DefaultProfile'][$k]['value'] = '';
85 $this->data['DefaultProfile'][$k]['value'] = $v['value'];
88 if (!isset($v['public_flag'])) {
89 $this->data['DefaultProfile'][$k]['public_flag'] = 'public';
91 $this->data['DefaultProfile'][$k]['public_flag'] = $v['public_flag'];
94 unset($this->data["CharactersHasProfile"]);
96 // $this->data['DefaultProfile']['__Token'] = $this->post_data['DefaultProfile']['__Token'];
99 if ($this->DefaultProfile->saveAll($this->data['DefaultProfile'], array('validate' => 'only'))) {
101 // 現在のdefault_profiles削除
102 $this->DefaultProfile->deleteAll(array(
103 'DefaultProfile.profile_id' => $profile_id
107 $this->DefaultProfile->create();
108 if ($this->DefaultProfile->saveAll($this->data['DefaultProfile'], array(
110 'fieldList' => $this->DefaultProfile->fields['edit'],
112 $this->Session->setFlash(__('The default profile has been saved', true));
113 // $this->redirect(array('controller' => 'systems', 'action' => 'view', $profile['Profile']['system_id']));
114 $this->redirect(array('action' => 'edit', $profile_id));
117 $this->Session->setFlash(__('The default profile could not be saved. Please, try again.', true));
118 $this->data = $this->post_data;
122 $this->data['System'] = $profile['System'];
123 unset($profile['System']);
125 $profile['Profile']['CharactersHasProfile'] = $profile['DefaultProfile'];
127 $profile['Profile']['ProfileSelect'] = $profile['ProfileSelect'];
128 unset($profile['ProfileSelect']);
130 $profile['Profile']['ProfileTable'] = $profile['ProfileTable'];
131 unset($profile['ProfileTable']);
133 $this->data['System']['Profile'][0] = $profile['Profile'];
135 $this->set('form_nums', count($profile['Profile']['CharactersHasProfile']) + 3);
137 $this->set('title_for_layout', " - ". sprintf(__('DefaultProfile for %s %s', true), $this->data['System']['name'], $this->data['System']['Profile'][0]['name']));
141 function admin_delete($id = null) {
143 $this->Session->setFlash(__('Invalid id for default profile', true));
144 $this->redirect(array('action'=>'index'));
146 if ($this->DefaultProfile->delete($id)) {
147 $this->Session->setFlash(__('Default profile deleted', true));
148 $this->redirect(array('action'=>'index'));
150 $this->Session->setFlash(__('Default profile was not deleted', true));
151 $this->redirect(array('action' => 'index'));
155 function get_profile4profile_id($profile_id)
158 $this->Session->setFlash(__('Invalid ProfileTable.', true));
159 $this->redirect(array('controller' => 'systems', 'action'=>'admin_index'));
162 $profile = $this->DefaultProfile->Profile->find('first', array(
163 'conditions' => array(
164 'Profile.id' => $profile_id,
170 'ProfileTable' => array(
171 'ProfileTableStatic',
176 if (!empty($profile['ProfileSelect'])) {
177 foreach ($profile['ProfileSelect'] as $k => $v) {
179 if (isset($v['sort_order']) && !empty($v['sort_order'])) {
180 $sort_order[$k] = $v['sort_order'];
185 if (!empty($sort_order)) {
186 $profile['ProfileSelect'] = $this->sort4sort_order($profile['ProfileSelect'], $sort_order);
189 if (!empty($profile['ProfileTable'])) {
190 foreach ($profile['ProfileTable'] as $k => $v) {
192 if (isset($v['sort_order']) && !empty($v['sort_order'])) {
193 $sort_order[$k] = $v['sort_order'];
198 if (!empty($sort_order)) {
199 $profile['ProfileTable'] = $this->sort4sort_order($profile['ProfileTable'], $sort_order);