8 * @author Cake <cake_67@users.sourceforge.jp>
9 * @license http://www.opensource.org/licenses/mit-license.php The MIT License
10 * @link http://trpgtools-onweb.sourceforge.jp/
13 class CharactersController extends AppController {
15 var $name = 'Characters';
27 var $disableTokenActions = array();
28 var $post_data = array();
31 var $search_cols = array(
36 function beforeFilter() {
38 parent::beforeFilter();
41 $this->cacheAction = array(
42 'index' => Configure::read('Cache.expireShort'),
46 $this->AuthPlus->allow('view');
47 $this->AuthPlus->allow('index');
50 function beforeRender()
52 parent::beforeRender();
54 $this->set_public_flag4view();
55 $this->set_status4view();
61 function index($id = null) {
62 if (!empty($id) && $id == $this->user_id) {
63 $this->redirect(array_merge(array('action'=>'mycharacter'), $this->params['named']));
66 $this->set('isOwner', false);
71 function search($id = null) {
72 if (!empty($id) && $id == $this->user_id) {
73 $this->redirect(array_merge(array('action'=>'mycharacter'), $this->params['named']));
76 $this->set('isOwner', false);
82 $this->set('isOwner', true);
84 $this->_search($this->user_id);
87 function mycharacter(){
88 $this->set('isOwner', true);
90 $this->_index($this->user_id);
93 function view($id = null) {
95 $this->Session->setFlash(__('Invalid Character.', true));
96 $this->redirect(array('action'=>'index'));
99 $character = $this->_view($id, array(), false);
101 if (!$this->check_public_flag($character['System'])) {
102 unset($character['System']['Profile']);
105 $this->set('maxPictures', $this->check_character_picture_max(count($character['CharacterPicture'])));
108 if ($this->isOwner($character['Character'], $this->user_id)) {
111 $this->set('isOwner', $isOwner);
113 // キャラ画像のpublic_flagチェック
114 if ($isOwner !== true && !empty($character['CharacterPicture'])) {
115 foreach($character['CharacterPicture'] as $k => $v) {
116 if (!$this->check_public_flag2($v)) {
117 unset($character['CharacterPicture'][$k]);
122 $this->set('character', $this->HtmlEscape->nl2br_escaped($character));
126 $systems = $this->_get_systems('public');
128 if (isset($this->site_configs['System.singleSystem']['value']) && $this->site_configs['System.singleSystem']['value']) {
129 $this->params['named']['system_id'] = key($systems);
132 if (isset($this->params['named']['system_id']) && !empty($this->params['named']['system_id'])) {
133 $system = $this->Character->System->find('first', array(
134 'conditions' => array(
135 'System.id' => $this->params['named']['system_id'],
141 'System.public_flag',
145 if (empty($system) || !$this->check_public_flag2($system['System'])) {
146 $this->Session->setFlash(__('Invalid ID.', true));
147 $this->redirect(array('action'=>'index'));
150 if (isset($system['System']) && !empty($system['System']) && $system['System']['set_npc']) {
154 if (!empty($this->data)) {
155 $this->data['Character']['user_id'] = $this->user_id;
156 if (isset($this->site_configs['System.singleSystem']['value']) && $this->site_configs['System.singleSystem']['value']) {
157 $this->data['Character']['system_id'] = key($systems);
160 $this->Character->create();
161 if ($this->Character->save($this->data, array('fieldList' => $this->Character->fields['add']))) {
163 $this->Session->setFlash(sprintf(__('%s has been saved.', true), $this->data['Character']['name']));
164 $this->redirect(array('controller' => 'characters', 'action'=>'view', $this->Character->id));
166 $this->Session->setFlash(__('The data could not be saved. Please, try again.', true));
170 $this->set('systems', $systems);
171 $this->set('isOwner', false);
173 $this->set('title_for_layout', " ". __('Add Character', true));
176 function edit($id = null) {
177 if (!$id && empty($this->data)) {
178 $this->Session->setFlash(__('Invalid ID.', true));
179 $this->redirect(array('action'=>'index'));
183 unset($this->Character->System->hasMany['Profile']['fields']);
184 $this->Character->System->Profile->hasMany['CharactersHasProfile']['fields'] = '';
185 unset($this->Character->hasMany['CharacterProfileArchive']);
187 $character = $this->_get_character($id, array(), false);
188 if (!$this->isOwner($character['Character'], $this->user_id)) {
189 $this->Session->setFlash(__('No Permission', true));
190 $this->redirect(array('action'=>'index'));
194 if (!$this->check_public_flag($character['System'])) {
195 $this->redirect(array('action'=>'change_system', $id));
197 if ($character['System']['set_npc']) {
201 if (empty($this->data)) {
202 $character['System']['Profile'] = $this->_set_profile_table2characters_has_profiles($character['System']['Profile']);
205 if (!empty($this->data)) {
206 $this->post_data = $this->data;
208 $this->data['clearCache'] = array(
209 'character_id' => $id,
210 'user_id' => $this->user_id,
211 'system_id' => $character['System']['id'],
215 if (isset($this->data['CharactersHasProfile'])) {
216 $this->data['CharactersHasProfile'] = $this->_set_new_characters_has_profile($this->data['CharactersHasProfile']);
220 $this->_set_validate4characters_has_profile($character['System']['id']);
221 if ($this->Character->saveAll($this->data, array('validate' => 'only'))) {
223 $requiredCheck = $this->_checkRequiredProfile($character['System']['Profile']);
225 if ($requiredCheck) {
227 $this->Character->CharactersHasProfile->deleteAll(array(
228 'CharactersHasProfile.character_id' => $id
232 $this->data['Character']['id'] = $id;
233 $this->Character->create();
235 if ($this->Character->saveAll($this->data, array(
237 'fieldList' => array_merge(
238 $this->Character->fields['edit'],
239 $this->Character->CharactersHasProfile->fields['add']
244 if (isset($this->data['Character']['archive']) && $this->data['Character']['archive'] == 1) {
245 $this->Character->saveCharacterProfile($this->Character->id, $this->data);
248 $this->Session->setFlash(sprintf(__('%s has been saved.', true), $this->data['Character']['name']));
249 $this->redirect(array('action'=>'view', $id));
254 $this->data = array_merge($character, $this->data);
255 $this->data['Character'] = $this->post_data['Character'];
256 $this->data['Character']['main_picture'] = $character['Character']['main_picture'];
257 $this->data['Character']['id'] = $id;
258 foreach ($this->data['System']['Profile'] as $k1 => $profile) {
259 if ($profile['profile_type'] == 'table') {
260 $colum_num = count($profile['CharactersHasProfile']);
261 } elseif ($profile['profile_type'] == 's-table') {
262 $colum_num = count($profile['CharactersHasProfile']);
263 } elseif ($profile['profile_type'] == 'checkbox') {
264 $colum_num = count($profile['ProfileSelect']);
265 } elseif ($profile['profile_type'] == 'm-input') {
266 $colum_num = count($profile['CharactersHasProfile']);
271 if ($colum_num == 0) {
272 if ($profile['profile_type'] == 's-table') {
273 $colum_num = count($profile['ProfileTable']) * count($profile['ProfileTable'][0]['ProfileTableStatic']);
274 } elseif ($profile['profile_type'] == 'table') {
275 $colum_num = count($profile['ProfileTable']) * 4;
276 } elseif ($profile['profile_type'] == 'checkbox') {
277 $colum_num = count($profile['ProfileSelect']);
278 } elseif ($profile['profile_type'] == 'm-input') {
285 for ($i=0; $i<$colum_num; $i++) {
286 if (!isset($profile['CharactersHasProfile'][$i])) {
287 $profile['CharactersHasProfile'][$i] = array('character_id' => $character['Character']['id']);
290 $postdata = array_shift($this->post_data['CharactersHasProfile']);
292 if (is_array($postdata['value'])) {
293 $postdata['value'] = $postdata['value'][0];
296 if (isset($postdata[$i])) {
297 $this->data['System']['Profile'][$k1]['CharactersHasProfile'][$i] = array_merge($profile['CharactersHasProfile'][$i], $postdata[$i]);
299 $this->data['System']['Profile'][$k1]['CharactersHasProfile'][$i] = array_merge($profile['CharactersHasProfile'][$i], $postdata);
305 elseif (empty($this->data)) {
306 $this->data = $character;
307 $this->data['Character'] = $this->_restore_html_character($this->data['Character'], true);
310 $this->data['System']['Profile'] = $this->_restore_html_characters_has_profiles($this->data['System']['Profile'], true);
312 $this->set('isOwner', true);
314 $this->set('title_for_layout', " ". sprintf(__('Edit %s', true), $character['Character']['name']));
317 function add_milti_profiles($id = null) {
318 if (!$id || !CorePlus::is_valid($this->params['named'], 'profile_id')) {
319 $this->Session->setFlash(__('Invalid ID.', true));
320 $this->redirect(array('action'=>'index'));
324 $this->Character->System->hasMany['Profile']['fields'] = '';
325 $this->Character->System->Profile->hasMany['CharactersHasProfile']['fields'] = '';
326 unset($this->Character->hasMany['CharacterProfileArchive']);
328 $character = $this->_get_character($id);
329 if (!$this->isOwner($character['Character'], $this->user_id)) {
330 $this->Session->setFlash(__('No Permission', true));
331 $this->redirect(array('action'=>'index'));
334 if (!$this->check_public_flag($character['System'])) {
335 $this->redirect(array('action'=>'change_system', $id));
339 if (empty($character['System']['Profile'])) {
340 $this->Session->setFlash(__('Invalid Profile.', true));
341 $this->redirect(array('action'=>'view', $id));
344 $profile_id = $this->params['named']['profile_id'];
347 foreach ($character['System']['Profile'] as $profile) {
348 if ($profile['id'] == $profile_id) {
355 $this->Session->setFlash(__('No Profile.', true));
356 $this->redirect(array('action'=>'view', $id));
359 $character['System']['Profile'] = array();
360 $character['System']['Profile'][0] = $target;
362 $character['System']['Profile'] = $this->_set_profile_table2characters_has_profiles($character['System']['Profile']);
364 if (!empty($this->data)) {
365 $this->data['clearCache'] = array(
366 'character_id' => $id,
367 'user_id' => $this->user_id,
368 'system_id' => $character['System']['id'],
371 $this->post_data = $this->data;
373 $this->data['Character'] = array_merge($character['Character'], $this->data['Character']);
374 $this->data['Character'] = $this->_restore_html_character($this->data['Character']);
375 $this->data['Character']['__Token'] = $this->post_data['Character']['__Token'];
376 $this->data['Character']['modified'] = null;
379 $this->data['CharactersHasProfile'] = $this->_set_new_characters_has_profile($this->data['CharactersHasProfile'], $profile_id, $character['System']['Profile']);
382 $this->_set_validate4characters_has_profile($character['System']['id']);
383 if ($this->Character->saveAll($this->data, array('validate' => 'only'))) {
385 $requiredCheck = $this->_checkRequiredProfile($character['System']['Profile']);
387 if ($requiredCheck) {
389 $this->Character->CharactersHasProfile->deleteAll(array(
390 'CharactersHasProfile.profile_id' => $target['id'],
391 'CharactersHasProfile.character_id' => $id
395 $this->Character->create();
396 if ($this->Character->saveAll($this->data, array(
398 'fieldList' => array_merge(
399 $this->Character->CharactersHasProfile->fields['add']
404 if (isset($this->data['Character']['archive']) && $this->data['Character']['archive'] == 1) {
405 $this->Character->saveCharacterProfile($this->Character->id, $this->data);
408 $this->Session->setFlash(sprintf(__('%s has been saved.', true), $this->data['Character']['name']));
409 $this->redirect(array('action'=>'view', $id));
411 $this->data = array_merge($character, $this->data);
417 $this->data = array_merge($character, $this->data);
418 $this->data['Character']['id'] = $id;
419 unset($this->data['Character']['__Token']);
423 if (empty($this->data)) {
424 $this->data = $character;
426 $this->data['System']['Profile'] = $this->_restore_html_characters_has_profiles($this->data['System']['Profile']);
428 $this->set('isOwner', true);
430 if (isset($this->params['named']['num'])) {
431 $form_nums = $this->params['named']['num'];
435 $this->set('form_nums', $form_nums);
437 $this->set('title_for_layout', " ". sprintf(__('Edit %s', true), $character['Character']['name']));
440 function change_system($id = null) {
442 $this->Session->setFlash(__('Invalid ID.', true));
443 $this->redirect(array('action'=>'index'));
447 $this->Character->System->hasMany['Profile']['fields'] = '';
448 $this->Character->System->Profile->hasMany['CharactersHasProfile']['fields'] = '';
450 $character = $this->_get_character($id);
451 if (!$this->isOwner($character['Character'], $this->user_id)) {
452 $this->Session->setFlash(__('No Permission', true));
453 $this->redirect(array('action'=>'index'));
457 if (isset($character['System']) && !empty($character['System'])) {
459 if ($this->check_public_flag($character['System'])) {
460 $this->redirect(array('action'=>'edit', $id));
463 $this->set('isChange', true);
467 if (!empty($this->data)) {
468 $this->data['clearCache'] = array(
469 'character_id' => $id,
470 'user_id' => $this->user_id,
471 'system_id' => $character['System']['id'],
474 $this->data['Character']['id'] = $id;
476 // validateはsystem_idのみ
477 $this->Cahracter['validate'] = array(
478 'system_id' => array(
479 'validSystemId' => array(
480 'rule' => array('validSystemId', true),
481 'allowEmpty' => false,
486 if ($this->Character->save(
490 'fieldList' => array('system_id'),
493 $this->Session->setFlash(__('The new system has been saved', true));
494 $this->redirect(array('action'=>'view', $id));
496 $this->Session->setFlash(__('The data could not be saved. Please, try again.', true));
500 $this->set('isOwner', true);
501 $this->set('character', $character);
503 $systems = $this->_get_systems('public');
504 $this->set('systems', $systems);
506 $this->set('title_for_layout', " ". sprintf(__('%s Change System', true), $character['Character']['name']));
510 function set_status($id = null) {
511 if (!$id || !isset($this->params['named']['mode'])) {
512 $this->Session->setFlash(__('Invalid ID.', true));
513 $this->redirect(array('controller' => 'characters', 'action'=>'index'));
516 $character = $this->_get_character4character_id($id, $this->user_id, 'public');
518 if ($this->params['named']['mode'] != 'main_picture' && $this->params['named']['mode'] != 'full_length') {
519 $this->Session->setFlash(__('Invalid URL.', true));
520 $this->redirect(array('controller' => 'character_pictures', 'action'=>'index', $id));
524 $new_character_picture = null;
525 if (isset($this->params['named']['new_picture_id']) && $this->params['named']['new_picture_id'] != 'null') {
526 if ($character['CharacterPicture']) {
527 foreach($character['CharacterPicture'] as $k => $v) {
528 if ($v['id'] == $this->params['named']['new_picture_id']) {
529 $new_character_picture = CorePlus::get_value($v, 'Attachment.0.basename');
534 if (!$new_character_picture) {
535 $this->Session->setFlash(__('Invalid data.', true));
536 $this->redirect(array('controller' => 'character_pictures', 'action'=>'listview', $id));
541 $this->data['clearCache'] = array(
542 'character_id' => $id,
543 'user_id' => $this->user_id,
544 'system_id' => $character['Character']['system_id'],
548 $this->Character->id = $id;
549 $this->data['Character'][$this->params['named']['mode']] = $new_character_picture;
550 $this->Character->save(
553 'fieldList' => array(
554 $this->params['named']['mode']
559 $this->Character->deleteCache4CharacterPicture($id);
562 $this->Session->setFlash(__('CharacterPicture Configuration has been saved.', true));
563 $this->redirect(array('controller' => 'character_pictures', 'action' => 'listview', $id));
566 function delete($id = null) {
568 $this->Session->setFlash(__('Invalid id for Character', true));
569 $this->redirect(array('action'=>'index'));
572 if ($this->_delete($id)) {
573 $this->redirect(array('controller' => 'users', 'action'=>'index'));
576 $this->set('title_for_layout', " - ". __('Delete Character', true));
579 function admin_index($id = null) {
581 $this->_index($id, array('isAdmin' => true));
584 function admin_search($id = null) {
586 $this->_search($id, array('isAdmin' => true));
589 function admin_view($id = null) {
591 $this->Session->setFlash(__('Invalid Character.', true));
592 $this->redirect(array('action' => 'admin_index'));
595 $character = $this->_view($id, array(), true);
597 $this->set('character', $this->HtmlEscape->nl2br_escaped($character));
600 function admin_edit($id = null) {
601 if (!$id && empty($this->data)) {
602 $this->Session->setFlash(__('Invalid ID.', true));
603 $this->redirect(array('action'=>'index'));
607 $this->Character->System->hasMany['Profile']['fields'] = '';
608 $this->Character->System->Profile->hasMany['CharactersHasProfile']['fields'] = '';
609 unset($this->Character->hasMany['CharacterProfileArchive']);
611 $character = $this->_get_character($id, array(), true);
613 $this->Session->setFlash(__('No Character', true));
614 $this->redirect(array('action'=>'index'));
617 if (empty($this->data)) {
618 $character['System']['Profile'] = $this->_set_profile_table2characters_has_profiles($character['System']['Profile']);
621 if (!empty($this->data)) {
623 $this->data['clearCache'] = array(
624 'character_id' => $id,
625 'user_id' => $this->user_id,
626 'system_id' => $character['System']['id'],
629 if (isset($this->data['Character']['mode']) && $this->data['Character']['mode'] == 'set_private') {
630 $this->data['Character']['public_flag'] = 'private';
631 } elseif (isset($this->data['Character']['mode']) && $this->data['Character']['mode'] == 'set_public') {
632 $this->data['Character']['public_flag'] = 'public';
633 } elseif (isset($this->data['Character']['mode']) && $this->data['Character']['mode'] == 'delete_confirm') {
634 $this->redirect(array('controller' => 'characters', 'action'=>'admin_delete', $id));
636 $this->Session->setFlash(sprintf(__('Invalid data.', true), $this->data['Character']['name']));
637 $this->redirect(array('action'=>'view', $id));
640 $this->data['Character']['id'] = $id;
641 $this->Character->create();
642 if ($this->Character->save($this->data, array(
644 'fieldList' => array(
649 $this->Session->setFlash(sprintf(__('%s has been saved.', true), $character['Character']['name']));
650 $this->redirect(array('action'=>'view', $id));
653 $this->data = array_merge($character, $this->data);
654 $this->data['Character']['id'] = $id;
657 if (empty($this->data)) {
658 $this->data = $character;
659 $this->data['Character'] = $this->_restore_html_character($this->data['Character'], true);
661 $this->data['System']['Profile'] = $this->_restore_html_characters_has_profiles($this->data['System']['Profile'], true);
664 $this->set('title_for_layout', " ". sprintf(__('Edit %s', true), $character['Character']['name']));
667 function admin_delete($id = null) {
669 $this->Session->setFlash(__('Invalid id for Character', true));
670 $this->redirect(array('action'=>'index'));
673 if ($this->_delete($id, array(), true)) {
674 $this->redirect(array('action'=>'index'));
677 $this->set('title_for_layout', " - ". __('Delete Character', true));
682 function _index($id, $conditions = array(), $limit = 20, $fields = array(), $contain = array(), $order = array(), $page = 1) {
683 if (isset($conditions['isAdmin']) && $conditions['isAdmin'] === true) {
685 unset($this->Character->belongsTo['System']['conditions']['System.public_flag']);
690 $title = __('List of All Characters', true);
693 if (isset($this->params['named']['system']) && intval($this->params['named']['system'])) {
695 $system_conditions['System.id'] = $this->params['named']['system'];
696 if ($isAdmin === false) {
697 $system_conditions['System.public_flag'] = 'public';
700 $this_system = $this->Character->System->find('first', array(
701 'conditions' => $system_conditions,
705 if (!isset($this_system['System'])) {
706 $this->Session->setFlash(__('Invalid System.', true));
707 $this->redirect(array('controller' => 'systems', 'action' => 'index'));
709 $conditions['Character.system_id'] = $this->params['named']['system'];
711 $this_system = $this->_restore_html_system($this_system);
713 if ($this_system['System']['set_npc']) {
717 $title = $this_system['System']['name']. " ". $title;
719 $this->set('this_system', $this_system);
721 $contain = array_merge(array('System'), (array)$contain);
728 $user = $this->Character->User->find('first', array(
729 'conditions' => array('User.id' => $id),
738 $this->Session->setFlash(__('Invalid Id.', true));
739 $this->redirect(array('action'=>'index'));
742 $conditions['Character.user_id'] = $id;
743 if ($id == $this->user_id) {
744 unset($this->paginate['conditions']['Character.public_flag']);
747 $title = $user['User']['name']. " ". $title;
749 $contain = array_merge($contain, array('User'));
751 $this->set('userSet', $user);
754 if (!isset($this->params['named']['status'])) {
757 $status = $this->params['named']['status'];
763 $conditions['Character.status'] = $status;
767 unset($conditions['Character.status']);
770 $this->set('selected_status', $status);
772 $characters = $this->HtmlEscape->nl_unescape($this->_get_characters_page4user_id($id, $conditions, $limit, $fields, $contain, $order));
774 $this->set('characters', $characters);
776 $this->set('title_for_layout', " - ". $title);
779 function _search($id, $conditions = array(), $limit = 20) {
780 $this->search_cols = array(
781 'Character.name' => __('Charater Name', true),
782 'Character.notes' => __('Notes', true),
784 $this->fields = array_merge($this->fields, array('Character.notes'));
785 $this->set('fields', $this->fields);
790 if (isset($this->params['url']['keyword']) && !empty($this->params['url']['keyword'])) {
791 if (is_string($this->params['url']['keyword'])) {
792 foreach ($this->search_cols as $field => $name) {
793 $new_condition = $this->_create_search_sql($this->params['url']['keyword'], $field, $type);
794 $conditions[$type][] = $new_condition;
796 } else if (is_array($this->params['url']['keyword'])) {
798 $this->Session->setFlash(__('Invalid Data.', true));
799 $this->redirect(array('action'=>'index'));
802 $this->set('keyword', $this->params['url']['keyword']);
804 $this->set('keyword', null);
807 $this->_index($id, $conditions, $limit);
812 function _view($id, $conditions = array(), $isAdmin = false) {
813 $this->helpers[] = 'CharacterSheet';
817 if (isset($this->params['named']['mode']) && !empty($this->params['named']['mode'])) {
818 $this->view = 'Theme';
819 $this->theme = $this->params['named']['mode'];
824 $orig_character = $this->_get_character($id, $conditions, $isAdmin);
825 $character = $this->Character->set_profiles2view($orig_character);
827 Configure::write('isOwner', false);
828 if ($isAdmin || CorePlus::isOwner($character['Character'], $this->user_id)) {
829 Configure::write('isOwner', true);
833 $this->set('systemValid', 'public');
834 if (!$character['System']) {
835 $this->set('systemValid', false);
837 if (!$this->check_public_flag($character['System'])) {
838 $this->set('systemValid', 'unpublic');
840 if ($character['System']['set_npc']) {
843 $character = $this->_restore_html_system($character);
845 $this->set('title_for_layout', " - ". $character['Character']['name']);
850 function _delete($id = null, $conditions = array(), $isAdmin = false) {
852 $this->Session->setFlash(__('Invalid id for Character', true));
853 $this->redirect(array('action'=>'index'));
856 $character = $this->_view($id, $conditions, $isAdmin);
857 if (empty($character)) {
858 $this->Session->setFlash(__('No Character', true));
859 $this->redirect(array('action'=>'index'));
861 $this->set('character', $character);
863 if (!$isAdmin && !$this->isOwner($character['Character'], $this->user_id)) {
864 $this->Session->setFlash(__('No Permission', true));
865 $this->redirect(array('action'=>'index'));
867 $this->set('isOwner', true);
869 if (!empty($this->data)) {
871 $this->data['clearCache'] = array(
872 'character_id' => $id,
873 'user_id' => $this->user_id,
874 'system_id' => $character['System']['id'],
877 if ($this->data['Character']['confirm'] == 'yes') {
879 $this->data['Character']['id'] = $id;
880 $this->data['Character']['main_picture'] = null;
881 $this->data['Character']['full_length'] = null;
882 $this->data['Character']['deleted'] = true;
883 $this->data['Character']['deleted_date'] = date('Y-m-d H:i:s');
885 $this->Character->create();
886 if ($this->Character->save(
890 'fieldList' => array(
899 // CharactersHasProfiles
900 $this->Character->CharactersHasProfile->updateAll(
902 'CharactersHasProfile.public_flag' => "'private'",
905 'CharactersHasProfile.character_id' => $id
909 // CharacterProfileArchives
910 $date = date('Y-m-d H:i:s');
911 $this->Character->CharacterProfileArchive->updateAll(
913 'CharacterProfileArchive.deleted' => true,
914 'CharacterProfileArchive.deleted_date' => "'$date'",
917 'CharacterProfileArchive.character_id' => $id
922 if (isset($character['CharacterPicture']) && !empty($character['CharacterPicture'])) {
923 foreach ($character['CharacterPicture'] as $picture) {
924 $this->Character->CharacterPicture->delete($picture['id']);
928 $this->Session->setFlash(__('Character deleted', true));
932 $this->Session->setFlash(__('The Character could not be deleted.', true));
941 function _get_character($id, $conditions = array(), $isAdmin = false)
943 $character = $this->Character->get_character($id, $conditions, $isAdmin);
945 if (empty($character)) {
946 $this->Session->setFlash(__('No Character', true));
947 $this->redirect(array('action'=>'index'));
950 if ($isAdmin === false && !$this->check_public_flag($character['Character'])) {
951 $this->Session->setFlash(__('No Permission', true));
952 $this->redirect(array('action'=>'index'));
955 if (isset($character['System']['Profile'])) {
956 $character['System'] = $this->_restore_html_profile($character['System']);
962 // ProfileTableをCharacterHasProfilesのTableの形式にセット
963 function _set_profile_table2characters_has_profiles($profile)
965 if (!empty($profile[0]['CharactersHasProfile'])) {
969 foreach($profile as $k => $v) {
970 if (empty($v['ProfileTable'])) {
975 $rows = count($v['CharactersHasProfile']);
976 for($i=0; $i<$rows; $i++) {
977 foreach($v['ProfileTable'] as $k2 => $v2) {
978 if (isset($v2['CharactersHasProfile'][$i])) {
979 $tmp[] = $v2['CharactersHasProfile'][$i];
980 } elseif (isset($v['CharactersHasProfile'][$i])) {
981 $tmp[] = $v['CharactersHasProfile'][$i];
989 $profile[$k]['CharactersHasProfile'] = $tmp;
991 if (isset($profile[$k]['ProfileTable'][0]['ProfileTableStatic']) && !empty($profile[$k]['ProfileTable'][0]['ProfileTableStatic'])) {
992 $profile[$k]['ProfileTable'][0]['ProfileTableStatic'] = $this->_restore_html_profile_table_static($profile[$k]['ProfileTable'][0]['ProfileTableStatic']);
999 /* POSTのCharactersHasProfileを処理 */
1000 function _set_new_characters_has_profile($characters_has_profiles, $profile_id = null, $now_data = array())
1002 $prev_profile_id = null;
1003 $profileTable_tmp = array();
1006 foreach ($characters_has_profiles as $k => $v) {
1007 if (!empty($character_id)) {
1008 $characters_has_profiles[$k]['character_id'] = $character_id;
1011 if (is_array($v['value'])) {
1012 $characters_has_profiles[$k]['value'] = $v['value'][0];
1016 $characters_has_profiles[$k]['value'] = Sanitize::html($characters_has_profiles[$k]['value']);
1017 $characters_has_profiles[$k]['value'] = preg_replace('/[\\\n]/', '', $characters_has_profiles[$k]['value']);
1018 $characters_has_profiles[$k]['value'] = preg_replace('/[\\\r]/', '', $characters_has_profiles[$k]['value']);
1020 if (isset($v['is_textarea']) && $v['is_textarea'] == 1) {
1021 $characters_has_profiles[$k]['value'] = str_replace(array("\n\r", '\n', "\r"), '<br />', $characters_has_profiles[$k]['value']);
1022 $characters_has_profiles[$k]['value'] = str_replace("\\", '', $characters_has_profiles[$k]['value']);
1024 $characters_has_profiles[$k]['value'] = Sanitize::stripAll($characters_has_profiles[$k]['value']);
1026 // 空の値処理, public_flag
1027 // table: 一時保管して全項目空の場合行削除
1028 if (CorePlus::is_valid($v, 'profile_table_id')) {
1029 if (isset($profileTable_tmp[$v['profile_id']][$i][$v['profile_table_id']])) {
1035 if ($public == null && isset($characters_has_profiles[$k]['public_flag'])) {
1036 $public = $v['public_flag'];
1038 if ($v['profile_table_static_id']) {
1039 $characters_has_profiles[$k]['public_flag'] = 'public';
1042 $characters_has_profiles[$k]['public_flag'] = $public;
1045 $profileTable_tmp[$v['profile_id']][$i][$v['profile_table_id']] = array($characters_has_profiles[$k], $k);
1047 } elseif (empty($v['value'])) {
1048 unset($characters_has_profiles[$k]);
1052 // table: 空行削除、不正profile_table_idデータ削除
1053 if (!empty($profileTable_tmp)) {
1054 if (!isset($this->Character->ProfileTable)) {
1055 $this->Character->ProfileTable = CorePlus::set_model('ProfileTable');
1057 foreach($profileTable_tmp as $profile_id => $v) {
1058 $profile_table_columns = $this->Character->ProfileTable->find('list', array(
1059 'conditions' => array('ProfileTable.profile_id' => $profile_id),
1060 'fields' => array('ProfileTable.id'),
1061 'order' => array('ProfileTable.sort_order' => 'asc'),
1065 foreach ($v as $i => $profile_tables) {
1067 $diff_keys = array_diff_key($profile_tables, $profile_table_columns);
1068 if (!empty($diff_keys)) {
1069 foreach($diff_keys as $dvalue) {
1070 unset($characters_has_profiles[$dvalue[1]]);
1076 foreach($profile_table_columns as $k2 => $columns) {
1077 if (CorePlus::is_valid($profile_tables, $columns.'.0.value')) {
1078 $delete_flg = false;
1082 if ($delete_flg === true) {
1083 foreach ($profile_tables as $delk) {
1084 unset($characters_has_profiles[$delk[1]]);
1092 if (!is_null($profile_id) && !empty($now_data)) {
1095 foreach($now_data as $k => $v) {
1096 if ($v['id'] == $profile_id) {
1097 $v['CharactersHasProfile'] = $characters_has_profiles;
1100 foreach ($v['CharactersHasProfile'] as $k2 => $v2) {
1102 if (isset($tmp[$i]['id'])) {
1103 unset($tmp[$i]['id']);
1105 if (isset($tmp[$i]['character_id'])) {
1106 unset($tmp[$i]['character_id']);
1113 $characters_has_profiles = $tmp;
1116 return $characters_has_profiles;
1119 // CharactersHasProfileの追加valiadte設定
1120 function _set_validate4characters_has_profile($system_id)
1122 $this->Character->CharactersHasProfile->validate['profile_id']['validProfileId'] = array(
1123 'rule' => array('validProfileId', $system_id),
1125 $this->Character->CharactersHasProfile->validate['profile_select_id']['validProfileSelectId'] = array(
1126 'rule' => array('validProfileSelectId', $system_id),
1127 'allowEmpty' => true,
1129 $this->Character->CharactersHasProfile->validate['profile_table_id']['validProfiletableId'] = array(
1130 'rule' => array('validProfiletableId', $system_id),
1131 'allowEmpty' => true,
1136 function _restore_html_character($data, $nl2br = false) {
1137 $data['name'] = $this->{$this->modelClass}->restore_html($data['name'], false, false, false);
1138 $data['notes'] = $this->{$this->modelClass}->restore_html($data['notes'], false, false, false);
1140 $data['notes'] = str_replace('<br />', "\n", $data['notes']);
1146 function _restore_html_characters_has_profiles($profile, $nl2br = false) {
1147 if (empty($profile)) {
1151 foreach($profile as $k => $v) {
1152 if (empty($v['CharactersHasProfile'])) {
1155 $profile[$k]['CharactersHasProfile'] = $this->__restore_html_characters_has_profiles($v['CharactersHasProfile'], $nl2br, $v['profile_type']);
1160 function __restore_html_characters_has_profiles($data, $nl2br = false, $profile_type = null) {
1165 foreach ($data as $k => $v) {
1166 if (isset($v['value'])) {
1167 $data[$k]['value'] = $this->{$this->modelClass}->restore_html($v['value'], false, false, false);
1168 if ($nl2br && $profile_type == 'textarea') {
1169 $data[$k]['value'] = str_replace('<br />', "\n", $data[$k]['value']);
1177 function _checkRequiredProfile($profile)
1179 if (empty($profile) || !isset($this->data['CharactersHasProfile'])) {
1183 $requireCheck = array();
1184 foreach($this->data['CharactersHasProfile'] as $k => $v) {
1185 if (!isset($requireCheck[$v['profile_id']])) {
1186 $requireCheck[$v['profile_id']] = null;
1189 if (isset($requireCheck[$v['profile_id']]['value']) && !empty($requireCheck[$v['profile_id']]['value'])) {
1193 if (empty($v['value'])) {
1197 if (isset($v['profile_table_static_id']) && !empty($v['profile_table_static_id'])) {
1198 if (!isset($requireCheck[$v['profile_id']]['profile_table_id']) || empty($requireCheck[$v['profile_id']]['profile_table_id'])) {
1199 $requireCheck[$v['profile_id']]['profile_table_id'] = $v['profile_table_id'];
1202 if ($requireCheck[$v['profile_id']]['profile_table_id'] == $v['profile_table_id']) {
1207 $requireCheck[$v['profile_id']]['value'] = $v['value'];
1211 foreach ($profile as $k => $v) {
1212 if ($v['required']) {
1213 if (!isset($requireCheck[$v['id']]) || empty($requireCheck[$v['id']]['value'])) {
1214 $errors[] = $v['name'];
1220 $this->Session->setFlash(sprintf(__('%s is required.', true), implode(',', $errors)));
1227 function _create_search_sql($keyword, $field, $type = 'OR')
1229 if (empty($keyword) || !is_string($keyword) || empty($field)) {
1233 if (!array_key_exists($field, $this->search_cols)) {
1237 $keywords = rawurldecode($keyword);
1238 $searchwords = explode(",", $keywords);
1240 foreach ($searchwords as $k2 => $searchword) {
1242 $condition.= ' '. $type. ' ';
1247 $condition .= $field. ' LIKE '. '\'%'. $searchword. '%\'';