<?php
-/**
+/*
* PHP version 5
*
+ * @copyright Copyright 2010, Cake. (http://trpgtools-onweb.sourceforge.jp/)
* @category Controller
- * @package Chara-Shee!
+ * @package TRPG Data Bank
* @version beta
* @author Cake <cake_67@users.sourceforge.jp>
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
* @link http://trpgtools-onweb.sourceforge.jp/
*/
+
class CharactersController extends AppController {
var $name = 'Characters';
function search($id = null) {
if (!empty($id) && $id == $this->user_id) {
- $this->redirect(array_merge(array('action'=>'mycharacter'), $this->params['named']));
+ $this->redirect(array_merge(array('action'=>'mysearch'), $this->params['named']));
}
$this->set('isOwner', false);
}
function mycharacter(){
+ // お知らせ
+ $news = array();
+ if (empty($this->site_configs['Site.myHome']['value'])) {
+ $news = $this->get_news();
+ }
+ $this->set('news', $news);
+
$this->set('isOwner', true);
$this->_index($this->user_id);
$this->redirect(array('action'=>'index'));
}
}
- if (isset($system['System']) && !empty($system['System']) && $system['System']['set_npc']) {
+/* if (isset($system['System']) && !empty($system['System']) && $system['System']['set_npc']) {
$this->isNpc = true;
- }
+ }*/
if (!empty($this->data)) {
$this->data['Character']['user_id'] = $this->user_id;
if (!$this->check_public_flag($character['System'])) {
$this->redirect(array('action'=>'change_system', $id));
}
- if ($character['System']['set_npc']) {
+/* if ($character['System']['set_npc']) {
$this->isNpc = true;
- }
+ }*/
if (empty($this->data)) {
$character['System']['Profile'] = $this->_set_profile_table2characters_has_profiles($character['System']['Profile']);
/* validate */
$this->_set_validate4characters_has_profile($character['System']['id']);
+
if ($this->Character->saveAll($this->data, array('validate' => 'only'))) {
// requiredのチェック
$requiredCheck = $this->_checkRequiredProfile($character['System']['Profile']);
$this->redirect(array('action'=>'view', $id));
}
}
+ } else {
+ $validate_error = current(current(current($this->Character->validationErrors)));
+ $this->Session->setFlash($validate_error);
}
- $this->data = array_merge($character, $this->data);
+ $this->data = array_merge($character, $this->post_data);
$this->data['Character'] = $this->post_data['Character'];
$this->data['Character']['main_picture'] = $character['Character']['main_picture'];
+ $this->data['Character']['system_id'] = $character['Character']['system_id'];
$this->data['Character']['id'] = $id;
foreach ($this->data['System']['Profile'] as $k1 => $profile) {
if ($profile['profile_type'] == 'table') {
if (isset($postdata[$i])) {
$this->data['System']['Profile'][$k1]['CharactersHasProfile'][$i] = array_merge($profile['CharactersHasProfile'][$i], $postdata[$i]);
} else {
- $this->data['System']['Profile'][$k1]['CharactersHasProfile'][$i] = array_merge($profile['CharactersHasProfile'][$i], $postdata);
+ $this->data['System']['Profile'][$k1]['CharactersHasProfile'][$i] = array_merge($profile['CharactersHasProfile'][$i], (array)$postdata);
}
}
}
);
$this->post_data = $this->data;
-
- $this->data['Character'] = array_merge($character['Character'], $this->data['Character']);
+ $this->data = array();
+ if (isset($this->post_data['Character'])) {
+ $this->data['Character'] = array_merge($character['Character'], $this->post_data['Character']);
+ } else {
+ $this->data['Character'] = $character['Character'];
+ }
$this->data['Character'] = $this->_restore_html_character($this->data['Character']);
$this->data['Character']['__Token'] = $this->post_data['Character']['__Token'];
$this->data['Character']['modified'] = null;
// 新hasProfile処理
- $this->data['CharactersHasProfile'] = $this->_set_new_characters_has_profile($this->data['CharactersHasProfile'], $profile_id, $character['System']['Profile']);
+ $this->data['CharactersHasProfile'] = $this->_set_new_characters_has_profile($this->post_data['CharactersHasProfile'], $profile_id, $character['System']['Profile']);
/* validate */
$this->_set_validate4characters_has_profile($character['System']['id']);
if ($this->Character->saveAll($this->data, array('validate' => 'only'))) {
}
} else {
}
+ } else {
+ $validate_error = current(current(current($this->Character->validationErrors)));
+ $this->Session->setFlash($validate_error);
}
$this->data = array_merge($character, $this->data);
$this->Session->setFlash(__('No Permission', true));
$this->redirect(array('action'=>'index'));
}
+
// Systemチェック
// Systemあり
if (isset($character['System']) && !empty($character['System'])) {
+ // 「その他」設定
+ if ($this->isOtherSystem($character['System']['id'])) {
+ $this->set('isChange', true);
// 公開状態は変更不可
- if ($this->check_public_flag($character['System'])) {
+ } elseif ($this->check_public_flag($character['System'])) {
$this->redirect(array('action'=>'edit', $id));
// System非公開
} else {
$this_system = $this->_restore_html_system($this_system);
- if ($this_system['System']['set_npc']) {
+/* if ($this_system['System']['set_npc']) {
$this->isNpc = true;
- }
+ }*/
$title = $this_system['System']['name']. " ". $title;
} else {
$contain = array_merge(array('System'), (array)$contain);
- $this->isNpc = true;
+// $this->isNpc = true;
}
$user = array();
switch ($status) {
case 'active':
case 'inactive':
- case 'npc':
+// case 'npc':
$conditions['Character.status'] = $status;
break;
default:
$system_id = 0;
}
$systems = $this->_get_systems('public');
- $systems = array_merge(array(
- '0' => __('All', true),
- ), $systems);
+ $systems =
+ array(0 => __('All', true)) + $systems;
$this->search_cols['Character'] = array_merge($this->search_cols['Character'], array(
'system_id' => array(
'name' => __('Charater Name', true),
'type' => 'text',
),
- 'notes' => array(
- 'name' => __('Notes', true),
- 'type' => 'text',
- )
));
+ if ($this->site_configs['Character.NotesSearch']['value']) {
+ $this->search_cols['Character'] = array_merge($this->search_cols['Character'], array(
+ 'notes' => array(
+ 'name' => __('Notes', true),
+ 'type' => 'text',
+ )
+ ));
+ }
// Profileの検索対象
if (!empty($system_id)) {
$this->set('search_cols', $this->search_cols);
- $this->fields = array_merge($this->fields, array('Character.notes'));
+ if ($this->site_configs['Character.ListSearchNotes']['value'] || $this->site_configs['Character.NotesSearch']['value']) {
+ $this->fields = array_merge($this->fields, array('Character.notes'));
+ }
// $this->set('fields', $this->fields);
// 検索条件設定
break;
case 'CharactersHasProfile':
if (isset($search_options['value']) && !empty($search_options['value'])) {
+ $conditions['profile_search'] = true;
+
if (!empty($prev_type_set)) {
$new_condition .= ' '. strtoupper($prev_type). ' ';
$prev_type_set = false;
if (empty($isAdmin)) {
if (!empty($new_condition)) {
$new_condition = '('. $new_condition. ')';
+ }
+ if (isset($conditions['profile_search'])) {
$new_condition .= ' AND';
+ $new_condition .= ' CharactersHasProfile.public_flag = \'public\'';
}
- $new_condition .= ' CharactersHasProfile.public_flag = \'public\'';
}
if (!empty($new_condition)) {
function _view($id, $conditions = array(), $isAdmin = false) {
$this->helpers[] = 'CharacterSheet';
- // キャラクターシート設定
- $mode = null;
- if (isset($this->params['named']['mode']) && !empty($this->params['named']['mode'])) {
- $this->view = 'Theme';
- $this->theme = $this->params['named']['mode'];
-
- }
-
// キャラデータ取得
$orig_character = $this->_get_character($id, $conditions, $isAdmin);
$character = $this->Character->set_profiles2view($orig_character);
if (!$this->check_public_flag($character['System'])) {
$this->set('systemValid', 'unpublic');
}
- if ($character['System']['set_npc']) {
+/* if ($character['System']['set_npc']) {
$this->isNpc = true;
- }
+ }*/
$character = $this->_restore_html_system($character);
+ $character['System']['Profile'] = $this->_restore_html_characters_has_profiles($character['System']['Profile'], false);
$this->set('title_for_layout', " - ". $character['Character']['name']);
+ // キャラクターシート設定
+ if (isset($this->params['named']['mode']) && !empty($this->params['named']['mode'])) {
+ $mode = $this->params['named']['mode'];
+
+ // スキン公開チェック
+ $public_flg = false;
+ $skin = array();
+ if (!$isAdmin) {
+ // 公開済み
+ foreach ($character['System']['CharacterSheet'] as $v) {
+ if ($v['key_name'] == $mode) {
+ $public_flg = true;
+ $skin = $v;
+ break;
+ }
+ }
+
+ // 自身のキャラシのみ
+ if (!$public_flg) {
+ $this->CharacterSheet = CorePlus::set_model('CharacterSheet');
+ $characterSheet = $this->CharacterSheet->find('first', array(
+ 'conditions' => array('CharacterSheet.key_name' => $mode),
+ 'recursive' => -1,
+ ));
+
+ if ($this->_checkCharaSheeOwner($characterSheet)) {
+ $skin = $characterSheet['CharacterSheet'];
+ $public_flg = true;
+ }
+ }
+ } else {
+ $public_flg = true;
+ }
+ if ($public_flg) {
+ $this->view = 'Theme';
+ $this->theme = $mode;
+
+ $this->set('skin', $skin);
+ }
+ }
+
return $character;
}
return $profile;
}
-
- /* POSTのCharactersHasProfileを処理 */
- function _set_new_characters_has_profile($characters_has_profiles, $profile_id = null, $now_data = array())
- {
- $prev_profile_id = null;
- $profileTable_tmp = array();
- $i = 0;
- $public = null;
- foreach ($characters_has_profiles as $k => $v) {
- if (!empty($character_id)) {
- $characters_has_profiles[$k]['character_id'] = $character_id;
- }
- // 配列valueの処理
- if (is_array($v['value'])) {
- $characters_has_profiles[$k]['value'] = $v['value'][0];
- }
-
- // サニタイズ
- $characters_has_profiles[$k]['value'] = Sanitize::html($characters_has_profiles[$k]['value']);
- $characters_has_profiles[$k]['value'] = preg_replace('/[\\\n]/', '', $characters_has_profiles[$k]['value']);
- $characters_has_profiles[$k]['value'] = preg_replace('/[\\\r]/', '', $characters_has_profiles[$k]['value']);
- // textarea改行処理
- if (isset($v['is_textarea']) && $v['is_textarea'] == 1) {
- $characters_has_profiles[$k]['value'] = str_replace(array("\n\r", '\n', "\r"), '<br />', $characters_has_profiles[$k]['value']);
- $characters_has_profiles[$k]['value'] = str_replace("\\", '', $characters_has_profiles[$k]['value']);
- }
- $characters_has_profiles[$k]['value'] = Sanitize::stripAll($characters_has_profiles[$k]['value']);
-
- // 空の値処理, public_flag
- // table: 一時保管して全項目空の場合行削除
- if (CorePlus::is_valid($v, 'profile_table_id')) {
- if (isset($profileTable_tmp[$v['profile_id']][$i][$v['profile_table_id']])) {
- $i++;
- $public = null;
- }
-
- // 行単位public_flag
- if ($public == null && isset($characters_has_profiles[$k]['public_flag'])) {
- $public = $v['public_flag'];
- // Static設定タイトルは公開
- if ($v['profile_table_static_id']) {
- $characters_has_profiles[$k]['public_flag'] = 'public';
- }
- } else {
- $characters_has_profiles[$k]['public_flag'] = $public;
- }
-
- $profileTable_tmp[$v['profile_id']][$i][$v['profile_table_id']] = array($characters_has_profiles[$k], $k);
- // それ以外は削除
- } elseif (empty($v['value'])) {
- unset($characters_has_profiles[$k]);
- }
- }
-
- // table: 空行削除、不正profile_table_idデータ削除
- if (!empty($profileTable_tmp)) {
- if (!isset($this->Character->ProfileTable)) {
- $this->Character->ProfileTable = CorePlus::set_model('ProfileTable');
- }
- foreach($profileTable_tmp as $profile_id => $v) {
- $profile_table_columns = $this->Character->ProfileTable->find('list', array(
- 'conditions' => array('ProfileTable.profile_id' => $profile_id),
- 'fields' => array('ProfileTable.id'),
- 'order' => array('ProfileTable.sort_order' => 'asc'),
- 'recursive' => -1,
- ));
-
- foreach ($v as $i => $profile_tables) {
- // 不正POSTの削除
- $diff_keys = array_diff_key($profile_tables, $profile_table_columns);
- if (!empty($diff_keys)) {
- foreach($diff_keys as $dvalue) {
- unset($characters_has_profiles[$dvalue[1]]);
- }
- }
-
- // 空行削除
- $delete_flg = true;
- foreach($profile_table_columns as $k2 => $columns) {
- if (CorePlus::is_valid($profile_tables, $columns.'.0.value')) {
- $delete_flg = false;
- break;
- }
- }
- if ($delete_flg === true) {
- foreach ($profile_tables as $delk) {
- unset($characters_has_profiles[$delk[1]]);
- }
- }
- }
- }
- }
-
- // 指定データのみ変更
- if (!is_null($profile_id) && !empty($now_data)) {
- $tmp = array();
- $i = 0;
- foreach($now_data as $k => $v) {
- if ($v['id'] == $profile_id) {
- $v['CharactersHasProfile'] = $characters_has_profiles;
- }
-
- foreach ($v['CharactersHasProfile'] as $k2 => $v2) {
- $tmp[$i] = $v2;
- if (isset($tmp[$i]['id'])) {
- unset($tmp[$i]['id']);
- }
- if (isset($tmp[$i]['character_id'])) {
- unset($tmp[$i]['character_id']);
- }
-
- $i++;
- }
- }
-
- $characters_has_profiles = $tmp;
- }
-
- return $characters_has_profiles;
- }
-
// CharactersHasProfileの追加valiadte設定
function _set_validate4characters_has_profile($system_id)
{
function _restore_html_character($data, $nl2br = false) {
$data['name'] = $this->{$this->modelClass}->restore_html($data['name'], false, false, false);
$data['notes'] = $this->{$this->modelClass}->restore_html($data['notes'], false, false, false);
+ $data['secret_notes'] = $this->{$this->modelClass}->restore_html($data['secret_notes'], false, false, false);
if ($nl2br) {
$data['notes'] = str_replace('<br />', "\n", $data['notes']);
+ $data['secret_notes'] = str_replace('<br />', "\n", $data['secret_notes']);
}
return $data;
}
}
}
-
return $data;
}
return $result;
}
- function _getThisSystem($id, $isAdmin = false)
- {
- static $this_system;
-
- if (!empty($this_system)) {
- return $this_system;
- }
-
- $system_conditions['System.id'] = $id;
- if ($isAdmin === false) {
- $system_conditions['System.public_flag'] = 'public';
- }
-
- $this_system = $this->Character->System->find('first', array(
- 'conditions' => $system_conditions,
- 'recursive' => -1,
- ));
-
- if (!isset($this_system['System'])) {
- $this->Session->setFlash(__('Invalid System.', true));
- $this->redirect(array('controller' => 'systems', 'action' => 'index'));
- }
-
- return $this_system;
- }
-
}