OSDN Git Service

プロフィールのデフォルト入力機能追加
[trpgtools-onweb/cake-frame.git] / app / views / helpers / profiledisp.php
index 9a648af..bca6eea 100644 (file)
@@ -6,6 +6,7 @@
 class ProfiledispHelper extends Helper {
        var $helpers = array(
                'Html',
+               'Text',
                'Form',
                'Select',
        );
@@ -100,16 +101,21 @@ class ProfiledispHelper extends Helper {
        }
 
        /* profileの設定をフォームで出力 */
-       function disp_form4profile($profile, $character_id, $form_num = 2, $disp_add_link = false, $label = false, $option = array())
+       function disp_form4profile($profile, $form_num = 2, $disp_add_link = false, $disp_public = false, $options = array())
        {
                if ($profile['profile_type'] == 'textarea') {
-                       $option['type'] = 'textarea';
+                       $options['type'] = 'textarea';
                } else {
-                       $option['type'] = 'text';
+                       $options['type'] = 'text';
+               }
+
+               $character_id = null;
+               if (isset($options['character_id'])) {
+                       $character_id = $options['character_id'];
                }
 
                $isMulti = false;
-               if ($option['type'] == 'textarea') {
+               if ($options['type'] == 'textarea') {
                        $isMulti = true;
                }
 
@@ -117,29 +123,37 @@ class ProfiledispHelper extends Helper {
                        $profile['CharactersHasProfile'][0]['value'] = null;
                }
 
-               foreach ($profile['CharactersHasProfile'] as $v) {
-                       $this->_get_profile_tag($profile['id'], $v['value'], $label, $option);
+               foreach ($profile['CharactersHasProfile'] as $k => $v) {
+                       $disp_profile = $this->_get_profile_tag($profile['id'], $v['value'], false, $options);
 
-                       echo $this->dispPublicFlag4Profile($this->character_has_profile_num, $v, false)."<br>\n";
+                       if ($disp_public) {
+                               echo $this->dispPublicFlag4Profile($disp_profile, $this->character_has_profile_num, $v, false)."<br>\n";
+                       } else {
+                               echo $disp_profile;
+                       }
 
                        $this->character_has_profile_num++;
                }
 
                if ($this->profile_type['is_multi']) {
                        for ($i=0;$i<$form_num;$i++) {
-                               $this->_get_profile_tag($profile['id'], null, false, $option);
+                               $disp_profile =  $this->_get_profile_tag($profile['id'], null, false, $options);
 
-                               echo $this->dispPublicFlag4Profile($this->character_has_profile_num, $profile, $isMulti)."<br>\n";
+                               if ($disp_public) {
+                                       echo $this->dispPublicFlag4Profile($disp_profile, $this->character_has_profile_num, $profile, $isMulti)."<br>\n";
+                               } else {
+                                       echo $disp_profile;
+                               }
 
                                $this->character_has_profile_num++;
                        }
 
                        if ($disp_add_link) {
                                echo $this->Html->div('editLink', $this->Html->link(
-                                       __('Edit Data', true),
+                                       __('Edit', true),
                                        array(
                                                'action' => 'add_milti_profiles',
-                                               $character_id.
+                                               $options['character_id'].
                                                '/profile_id:'.$profile['id']
                                        ),
                                        null,
@@ -148,27 +162,27 @@ class ProfiledispHelper extends Helper {
                        }
                }
        }
-       function _get_profile_tag($profile_id, $value = null, $label = false, $option = array())
+       function _get_profile_tag($profile_id, $value = null, $label = false, $options = array())
        {
                if (empty($profile_id)) {
-                       echo null;
+                       return null;
                }
 
                $name1 = sprintf('CharactersHasProfile.%s.value', $this->character_has_profile_num);
                $name2 = sprintf('CharactersHasProfile.%s.profile_id', $this->character_has_profile_num);
-               $option = array_merge(array(
+               $options = array_merge(array(
                        'label' => $label,
                        'value' => $value,
-                       ), $option
+                       ), $options
                );
 
                $profile_tag = 
-                       $this->Form->input($name1, $option).
+                       $this->Form->input($name1, $options).
                        $this->Form->input($name2, array(
                                'type' => 'hidden',
                                'value' => $profile_id,
                        ));
-               if ($option['type'] == 'textarea') {
+               if ($options['type'] == 'textarea') {
                        $name3 = sprintf('CharactersHasProfile.%s.is_textarea', $this->character_has_profile_num);
                        $profile_tag .= $this->Form->input($name3, array(
                                'type' => 'hidden',
@@ -176,21 +190,19 @@ class ProfiledispHelper extends Helper {
                        ));
                }
 
-               echo $profile_tag;
-
-               return ;
+               return $profile_tag;
        }
 
-       function dispPublicFlag4Profile($profile_num, $profile = null, $isMulti = false)
+       function dispPublicFlag4Profile($profile, $profile_num, $public_flag = null, $isMulti = false)
        {
                $profilePublicName = sprintf('CharactersHasProfile.%d.public_flag', $profile_num);
 
                if (is_array($profile) && isset($profile['CharactersHasProfile'][0]['public_flag'])) {
                        $selected_public_flag = $profile['CharactersHasProfile'][0]['public_flag'];
-               } elseif(is_array($profile) && isset($profile['public_flag'])) {
-                       $selected_public_flag = $profile['public_flag'];
-               } elseif (is_string($profile)) {
-                       $selected_public_flag = $profile;
+               } elseif(is_array($public_flag) && isset($public_flag['public_flag'])) {
+                       $selected_public_flag = $public_flag['public_flag'];
+               } elseif (is_string($public_flag)) {
+                       $selected_public_flag = $public_flag;
                } else {
                        $selected_public_flag = null;
                }
@@ -204,16 +216,25 @@ class ProfiledispHelper extends Helper {
                        $publicSelect['div'] = 'profilePublic profilePublicMulti';
                }
 
-               return $this->Select->create_publicflag_select($this->public_flags, $profilePublicName, $publicSelect);
+               if (!empty($profile)) {
+                       $publicSelect['before'] = $profile;
+               }
+
+               $public_select = $this->Select->create_publicflag_select($this->public_flags, $profilePublicName, $publicSelect);
+               if (!empty($profile)) {
+                       $public_select .= '<WBR>';
+               }
+
+               return $public_select;
        }
 
        /* profile_selectsの設定を出力 */
-       function disp4profile_selects($profile_selects, $option = array())
+       function disp4profile_selects($profile_selects, $disp_public = false, $option = array())
        {
                foreach ($profile_selects as $k => $v) {
                        $options[stripcslashes($v['value'])] = stripcslashes($v['value']);
                }
-               $option = array_merge(
+               $options = array_merge(
                        array(
                        'type' => 'select',
                        'options' => $options,
@@ -222,7 +243,7 @@ class ProfiledispHelper extends Helper {
                );
 
                $profile_select_tag = 
-                        $this->Form->input('CharactersHasProfile.'.$this->character_has_profile_num.'.value', $option).
+                        $this->Form->input('CharactersHasProfile.'.$this->character_has_profile_num.'.value', $options).
                         $this->Form->input('CharactersHasProfile.'.$this->character_has_profile_num.'.profile_id', array(
                                'type' => 'hidden',
                                'value' => $profile_selects[0]['profile_id'],
@@ -231,29 +252,33 @@ class ProfiledispHelper extends Helper {
                                'type' => 'hidden',
                                'value' => $profile_selects[0]['id'],
                        ));
-               echo $profile_select_tag;
+               $profile = $profile_select_tag;
 
-               echo $this->dispPublicFlag4Profile($this->character_has_profile_num, $option['public_flag']);
+               if ($disp_public) {
+                       echo $this->dispPublicFlag4Profile($profile, $this->character_has_profile_num, $options['public_flag']);
+               } else {
+                       echo $profile;
+               }
 
                $this->character_has_profile_num++;
        }
 
 
        /* profile_selectsの設定をプルダウンで出力 */
-       function disp_select4profile_selects($profile_selects, $characters_has_profile = array(), $option = array(), $label = false, $legend = false)
+       function disp_select4profile_selects($profile_selects, $characters_has_profile = array(), $options = array(), $label = false, $legend = false, $disp_public = false, $isProfileDefault = false)
        {
                if (empty($profile_selects)) {
                        return null;
                }
 
-               $selected = $this->set_form_value($profile_selects, $characters_has_profile);
+               $selected = $this->set_form_value($profile_selects, $characters_has_profile, $isProfileDefault);
 
                $public_flag = null;
                if (isset($characters_has_profile[0]['public_flag'])) {
                        $public_flag = $characters_has_profile[0]['public_flag'];
                }
 
-               $option = array_merge(
+               $options = array_merge(
                        array(
                                'type' => 'select',
                                'label' => $label,
@@ -261,14 +286,14 @@ class ProfiledispHelper extends Helper {
                                'selected' => $selected['value'],
                                'public_flag' => $public_flag,
                        ),
-                       $option
+                       $options
                );
 
-               $this->disp4profile_selects($profile_selects, $option);
+               $this->disp4profile_selects($profile_selects, $disp_public, $options);
        }
 
        /* profile_selectsの設定をラジオボタンで出力 */
-       function disp_radio4profile_selects($profile_selects, $characters_has_profile = array(), $label = false, $legend = false)
+       function disp_radio4profile_selects($profile_selects, $characters_has_profile = array(), $label = false, $legend = false, $disp_public = false)
        {
                if (empty($profile_selects)) {
                        return null;
@@ -287,7 +312,7 @@ class ProfiledispHelper extends Helper {
                        $public_flag = $characters_has_profile[0]['public_flag'];
                }
 
-               $option = array(
+               $options = array(
                        'type' => 'radio',
                        'value' => $selected_value,
                        'label' => $label,
@@ -298,12 +323,12 @@ class ProfiledispHelper extends Helper {
                        ),
                );
 
-               return $this->disp4profile_selects($profile_selects, $option);
+               return $this->disp4profile_selects($profile_selects, $disp_public, $options);
 
        }
 
        /* profile_selectsの設定をチェックボックスで出力 */
-       function disp_checkbox4profile_selects($profile_selects, $characters_has_profile = array(), $label = false, $legend = false)
+       function disp_checkbox4profile_selects($profile_selects, $characters_has_profile = array(), $label = false, $legend = false, $disp_public = false, $isProfileDefault = false)
        {
                if (empty($profile_selects)) {
                        return null;
@@ -315,7 +340,7 @@ class ProfiledispHelper extends Helper {
                        }
 
                        $profile_select[0] = $v;
-                       $has_profile[0] = $this->get_selected_profile($v, $characters_has_profile);
+                       $has_profile[0] = $this->get_selected_profile($v, $characters_has_profile, $isProfileDefault);
                        $this->disp_select4profile_selects(
                                $profile_select, 
                                $has_profile,
@@ -326,13 +351,13 @@ class ProfiledispHelper extends Helper {
                                        'div' => array(
                                                'class' => 'input checkbox inline'
                                        ),
-                               )
+                               ), $label, $legend, $disp_public, $isProfileDefault
                        );
                }
        }
 
        /* profile_tablesの設定からtableHeadersを出力 */
-       function disp_th4profile_tables($profile_tables, $tableId = null, $tr_options = array(), $th_options = array())
+       function disp_th4profile_tables($profile_tables, $tableId = null, $disp_public = false, $tr_options = array(), $th_options = array())
        {
                if (empty($profile_tables)) {
                        return null;
@@ -353,6 +378,10 @@ class ProfiledispHelper extends Helper {
                        $i++;
                }
 
+               if ($disp_public === true) {
+                       $values[] = __('Public Flag', true);
+               }
+
                if (!empty($style_options)) {
                        echo '<style type="text/css"><!--'."\n";
                        foreach($style_options as $k => $v) {
@@ -380,6 +409,7 @@ class ProfiledispHelper extends Helper {
                if (empty($characters_has_profiles)) {
                        return null;
                }
+
                if (isset($characters_has_profiles[0]['ProfileTableStatic'])) {
                        $statics = $characters_has_profiles[0]['ProfileTableStatic'];
                }
@@ -399,7 +429,7 @@ class ProfiledispHelper extends Helper {
        }
 
        /* characters_has_profileからtable td出力 */
-       function disp_tds4characters_has_profiles($characters_has_profile, $type = 'view', $publicOnly = true, $oddTrOptions = null, $evenTrOptions = null, $useCount = false, $continueOddEven = true)
+       function disp_tds4characters_has_profiles($characters_has_profile, $type = 'view', $publicOnly = true, $profile_type = null, $oddTrOptions = null, $evenTrOptions = null, $useCount = false, $continueOddEven = true, $isProfileDefault = false)
        {
                $i = 1;
                $profile_num = 0;
@@ -420,7 +450,6 @@ class ProfiledispHelper extends Helper {
                        if (!CorePlus::is_valid($v, 'profile_table_id')) {
                                $profile_table_ids = array_keys(Set::combine($characters_has_profile, '{n}.profile_table_id'));
 
-
                                if (!empty($prof_table_ids)) {
                                        $v['profile_table_id'] = current(array_slice($prof_table_ids, $profile_num+1, 1));
                                        $v['value'] = null;
@@ -444,9 +473,9 @@ class ProfiledispHelper extends Helper {
 
                foreach($profiles as $k => $v) {
                        if ($type == 'form') {
-                               $tds = $this->disp_form4profile_tables($v, null, null, true);
+                               $tds = $this->disp_form4profile_tables($v, $publicOnly, $oddTrOptions, $evenTrOptions, true, true, $isProfileDefault);
                        } else {
-                               $tds = $this->disp_value4profile_tables($v, $publicOnly, null, null, true);
+                               $tds = $this->disp_value4profile_tables($v, $publicOnly, $profile_type, null, null, true, $isProfileDefault);
                        }
                }
                $this->character_has_profile_cols = 0;
@@ -456,47 +485,65 @@ class ProfiledispHelper extends Helper {
 
 
        /* characters_has_profileからvalue出力 */
-       function disp_value_td4characters_has_profiles($characters_has_profile, $publicOnly = true)
+       function disp_value_td4characters_has_profiles($characters_has_profile, $publicOnly = true, $profile_type = null)
        {
-               $this->disp_tds4characters_has_profiles($characters_has_profile, 'view', $publicOnly, null, null, true);
+               $this->disp_tds4characters_has_profiles($characters_has_profile, 'view', $publicOnly, $profile_type, null, null, true);
        }
 
        /* characters_has_profileからtdフォーム出力 */
-       function disp_form_td4characters_has_profiles($characters_has_profile)
+       function disp_form_td4characters_has_profiles($characters_has_profile, $disp_public = false, $profile_type = null, $isProfileDefault = false)
        {
-               $this->disp_tds4characters_has_profiles($characters_has_profile, 'form', false, null, null, true);
+               if ($disp_public === true) {
+                       $publicOnly = false;
+               } else {
+                       $publicOnly = true;
+               }
+               $this->disp_tds4characters_has_profiles($characters_has_profile, 'form', $publicOnly, $profile_type, null, null, true, true, $isProfileDefault);
        }
 
        /* profile_tablesの設定からView表示を出力 */
-       function disp_value4profile_tables($profile_tables, $publicOnly = true, $oddTrOptions = null, $evenTrOptions = null, $useCount = false, $continueOddEven = true)
+       function disp_value4profile_tables($profile_tables, $publicOnly = true, $profile_type = null, $oddTrOptions = null, $evenTrOptions = null, $useCount = false, $continueOddEven = true, $isProfileDefault = false)
        {
                if (empty($profile_tables)) {
                        return null;
                }
 
                $tds = array();
+               $i = 0;
                foreach ($profile_tables as $k => $v) {
-                       if (!Set::check($v, 'value') || !$this->isPublic($v, $publicOnly)) {
+                       if (!Set::check($v, 'value')) {
+                               $v['value'] = "&nbsp";
+                       } elseif (!$this->isPublic($v, $publicOnly)) {
                                $v['value'] = "&nbsp";
                        }
-                       $tds[] = $v['value'];
+                       if(!$publicOnly && $v['public_flag'] != 'public') {
+                               $v['value'] = $this->Html->tag('span', $v['value'], array('class' => 'publicFlagBg'));
+                       }
+                       if ($this->isPublic($v, $publicOnly)|| $profile_type != 'table') {
+                               $tds[] = $v['value'];
+                       }
+                       $i++;
                }
+
                $this->disp_td4characters_has_profiles($tds, $oddTrOptions, $evenTrOptions, $useCount, $continueOddEven);
        }
 
        /* profile_tablesの設定から入力フォームを出力 */
-       function disp_form4profile_tables($profile_tables, $oddTrOptions = null, $evenTrOptions = null, $useCount = false, $continueOddEven = true)
+       function disp_form4profile_tables($profile_tables, $publicOnly = true, $oddTrOptions = null, $evenTrOptions = null, $useCount = false, $continueOddEven = true, $isProfileDefault = false)
        {
                if (empty($profile_tables)) {
                        return null;
                }
                $first = reset($profile_tables);
+
                if (isset($first['ProfileTableStatic'])) {
                        $statics = $first['ProfileTableStatic'];
                }
 
                $forms = array();
                $i = 0;
+               $first_num = $this->character_has_profile_num;
+               $first = reset($profile_tables);
                foreach ($profile_tables as $k => $v) {
                        if (!Set::check($v, 'profile_id')) {
                                continue;
@@ -513,7 +560,7 @@ class ProfiledispHelper extends Helper {
                                $v['value'] = null;
                        }
 
-                       if ($i == 0 && (isset($statics[$this->character_has_profile_cols]) || isset($v['profile_table_static_id']))) {
+                       if ($i == 0 && (isset($statics[$this->character_has_profile_cols]) || (isset($v['profile_table_static_id']) && !empty($v['profile_table_static_id'])))) {
                                $value = isset($v['profile_table_static_id']) ? $v['value']: $statics[$this->character_has_profile_cols]['title']; 
                                $form = '<span class="staticHead">'.$value.'</span>'.
                                        $this->Form->input('CharactersHasProfile.'.$this->character_has_profile_num.'.value', array(
@@ -524,6 +571,7 @@ class ProfiledispHelper extends Helper {
                                $form = $this->Form->input('CharactersHasProfile.'.$this->character_has_profile_num.'.value', array(
                                        'type' => 'text',
                                        'label' => false,
+                                       'class' => 'longInput',
                                        'value' => $v['value'],
                                ));
                        }
@@ -553,6 +601,16 @@ class ProfiledispHelper extends Helper {
                        $this->character_has_profile_num++;
                        $i++;
                }
+
+               if ($publicOnly === false) {
+                       if ($isProfileDefault && isset($last["public_flag"])) {
+                               $last = end($profile_tables);
+                               $forms[] = $this->dispPublicFlag4Profile(null, $first_num, $last["public_flag"], false);
+                       } else {
+                               $forms[] = $this->dispPublicFlag4Profile(null, $first_num, $first, false);
+                       }
+               }
+
                $this->character_has_profile_cols++;
 
                $this->disp_td4characters_has_profiles($forms, $oddTrOptions, $evenTrOptions, $useCount, $continueOddEven);
@@ -566,6 +624,7 @@ class ProfiledispHelper extends Helper {
                }
 
                $blank = array_fill(0, count($profile_tables), $this->Html->div('blank', "&nbsp;"));
+
                for ($i=0; $i<$num; $i++) {
                        $this->disp_td4characters_has_profiles($blank, $oddTrOptions, $evenTrOptions, $useCount, $continueOddEven);
                }
@@ -606,49 +665,60 @@ class ProfiledispHelper extends Helper {
        /* profile_typeの設定に応じてフォーム表示
         * set_profile_type4view($profile)チェック済み前提。
         */
-       function disp_forms4profile_type($profile, $form_num = 2, $table_blank = 2, $disp_add_link = false, $character_id = null)
+       function disp_forms4profile_type($profile, $form_num = 2, $table_blank = 2, $disp_add_link = false, $character_id = null, $disp_public = false, $options = array(), $isProfileDefault = false)
        {
-               if (!isset($profile['CharactersHasProfile'])) {
-                       $profile['CharactersHasProfile'] = array();
+               if (!isset($profile['CharactersHasProfile']) || empty($profile['CharactersHasProfile'])) {
+                       if (isset($profile['DefaultProfile']) && !empty($profile['DefaultProfile'])) {
+                               $profile['CharactersHasProfile'] = $profile['DefaultProfile'];
+                               $form_num = $form_num - count($profile['DefaultProfile']) +1;
+                       } else {
+                               $profile['CharactersHasProfile'] = array();
+                       }
                }
 
                if ($this->profile_type['is_select'] || $this->profile_type['is_radio'] || $this->profile_type['is_checkbox']) {
                        if ($this->profile_type['is_select']) {
-                               $this->disp_select4profile_selects($profile['ProfileSelect'], $profile['CharactersHasProfile'], array('div' => array('class' => 'inline')));
+                               $this->disp_select4profile_selects($profile['ProfileSelect'], $profile['CharactersHasProfile'], array('div' => array('class' => 'inline')), false, false, $disp_public);
                        } elseif ($this->profile_type['is_radio']) {
-                               $this->disp_radio4profile_selects($profile['ProfileSelect'], $profile['CharactersHasProfile']);
+                               $this->disp_radio4profile_selects($profile['ProfileSelect'], $profile['CharactersHasProfile'], false, false, $disp_public);
                        } elseif ($this->profile_type['is_checkbox']) {
-                               $this->disp_checkbox4profile_selects($profile['ProfileSelect'], $profile['CharactersHasProfile']);
+                               $this->disp_checkbox4profile_selects($profile['ProfileSelect'], $profile['CharactersHasProfile'],  false, false, $disp_public, $isProfileDefault);
                        }
                } elseif ($this->profile_type['is_table']) {
+                       if ($disp_public == true) {
+                               $publicOnly = false;
+                       } else {
+                               $publicOnly = true;
+                       }
+
                        if (isset($profile['id'])) {
                                $tableId = 'TableProfileId'. $profile['id'];
                        } else {
                                $tableId = 'TableProfileId'. $profile['Profile']['id'];
                        }
                        echo '<table id="'.$tableId.'">';
-                       $this->disp_th4profile_tables($profile['ProfileTable'], $tableId);
+                       $this->disp_th4profile_tables($profile['ProfileTable'], $tableId, $disp_public);
                        echo '<tbody>';
                        if (!empty($profile['CharactersHasProfile'])) {
-                               $this->disp_form_td4characters_has_profiles($profile['CharactersHasProfile']);
+                               $this->disp_form_td4characters_has_profiles($profile['CharactersHasProfile'], $disp_public, null, $isProfileDefault);
 
                        }
                        if (intval($form_num) > 0 
                                && ((isset ($profile['Profile']['profile_type']) && $profile['Profile']['profile_type'] != 's-table') || (isset($profile['profile_type']) && $profile['profile_type'] != 's-table'))
                                || empty($profile['CharactersHasProfile'])) {
                                for ($i=0; $i<$form_num; $i++) {
-                                       $this->disp_form4profile_tables($profile['ProfileTable'], null, null, true);
+                                       $this->disp_form4profile_tables($profile['ProfileTable'], $publicOnly, array(), array(), true);
                                }
                                $this->character_has_profile_cols = 0;
                        }
                        if (intval($table_blank) > 0 && $profile['profile_type'] != 's-table') {
-                               $this->disp_blank_td4profile_tables($profile['ProfileTable'], intval($table_blank));
+                               $this->disp_blank_td4profile_tables($profile['ProfileTable'], intval($table_blank), null, null, true);
                        }
                        echo '</tbody>';
                        echo '</table>';
                        if ($disp_add_link) {
                                $link = $this->Html->link(
-                                       __('Edit Data', true),
+                                       __('Add Column', true),
                                        array(
                                                'action' => 'add_milti_profiles',
                                                $character_id.
@@ -678,9 +748,23 @@ class ProfiledispHelper extends Helper {
                        }
 
                } else {
-                       $this->disp_form4profile($profile, $character_id, $form_num , $disp_add_link);
+                       $options = array_merge(array(
+                               'character_id' => $character_id,
+                               ), $options
+                       );
+                       $this->disp_form4profile($profile, $form_num, $disp_add_link, $disp_public, $options);
                }
 
+               if (isset($profile['required']) && $profile['required']) 
+               {
+                       echo $this->Html->tag(
+                               'div',
+                               __(' required', true),
+                               array(
+                                       'class' => 'required'
+                               )
+                       );
+               }
        }
 
        /* characters_has_profilesの設定に応じてView表示
@@ -701,15 +785,25 @@ class ProfiledispHelper extends Helper {
                                                echo "&nbsp;";
                                        }
 
-                                       echo $this->Html->tag('span', $v['value']);
 
                                        if (!$publicOnly && isset($v['public_flag']) && $v['public_flag'] != 'public') {
                                                echo $this->Html->tag('span', 
-                                               __('[Private]', true), 
-                                               array(
-                                                       'class' => 'publicFlag',
-                                               )
-                                       );
+                                                       $this->autoLinkProf($v['value']),
+                                                       array(
+                                                               'class' => 'publicFlagBg',
+                                                       )
+                                               );
+
+                                               echo $this->Html->tag('span', 
+                                                       __('[Private]', true), 
+                                                       array(
+                                                               'class' => 'publicFlag publicFlagBg',
+                                                       )
+                                               );
+                                       } else {
+                                               echo $this->Html->tag('span',
+                                                       $this->autoLinkProf($v['value'])
+                                               );
                                        }
 
                                        $num++;
@@ -718,7 +812,7 @@ class ProfiledispHelper extends Helper {
 
                        if ($this->profile_type['is_multi'] && $disp_add_link) {
                                echo $this->Html->div('editLink', $this->Html->link(
-                                       __('Edit Data', true),
+                                       __('Add Column', true),
                                        array(
                                                'action' => 'add_milti_profiles',
                                                $character_id.
@@ -734,7 +828,7 @@ class ProfiledispHelper extends Helper {
                                $this->disp_th4profile_tables($profile['ProfileTable'], $tableId);
                                echo '<tbody>';
                                if (!empty($profile['CharactersHasProfile'])) {
-                                       $this->disp_value_td4characters_has_profiles($profile['CharactersHasProfile'], $publicOnly);
+                                       $this->disp_value_td4characters_has_profiles($profile['CharactersHasProfile'], $publicOnly, $profile['profile_type']);
                                } else {
                                        if (intval($table_blank) > 0) {
                                                $this->disp_blank_td4profile_tables($profile['ProfileTable'], intval($table_blank));
@@ -745,14 +839,14 @@ class ProfiledispHelper extends Helper {
                        echo '</table>';
                        if ($disp_add_link) {
                                $link = $this->Html->link(
-                                       __('Edit Data', true),
+                                       __('Edit', true),
                                        array(
                                                'action' => 'add_milti_profiles',
                                                $character_id.
                                                '/profile_id:'.$profile['id']
                                        )
                                );
-                               if (!empty($profile['CharactersHasProfile'][0]['character_id'])) {
+                               if (isset($profile['CharactersHasProfile'][0]) && !empty($profile['CharactersHasProfile'][0]['character_id'])) {
                                        $link .= " ".$this->Html->link(
                                                __('Clear', true),
                                                array(
@@ -774,15 +868,16 @@ class ProfiledispHelper extends Helper {
        }
 
        /* フォームに値入力 */
-       function set_form_value($profile_selects, $characters_has_profile)
+       function set_form_value($profile_selects, $characters_has_profile, $isProfileDefault = false)
        {
                $this->form_id++;
 
                if ($this->profile_type['is_select'] || $this->profile_type['is_radio'] || $this->profile_type['is_checkbox']) {
-                       return $this->set_form_value_select($profile_selects, $characters_has_profile);
+                       return $this->set_form_value_select($profile_selects, $characters_has_profile, $isProfileDefault);
                } elseif ($this->profile_type['is_table']) {
                        return $this->set_form_value_table($characters_has_profile);
                } else {
+//                     return $profile_selects;
                        return $this->set_form_value_profile($profile_selects, $characters_has_profile);
                }
 
@@ -790,14 +885,18 @@ class ProfiledispHelper extends Helper {
 
        /* profile_select */
        /* profile_select_id->profile_idで抽出 */
-       function set_form_value_select($profile_selects, $characters_has_profile)
+       function set_form_value_select($profile_selects, $characters_has_profile, $isProfileDefault = false)
        {
-               if (isset($characters_has_profile[0]['id'])) {
+               if (isset($characters_has_profile[0]['value'])) {
                        $selected = array(
                                'value' => $characters_has_profile[0]['value'],
-                               'public_flag' => $characters_has_profile[0]['public_flag'],
-                               'link_value' => $characters_has_profile[0]['link_value'],
                        );
+                       if (isset($characters_has_profile[0]['public_flag'])) {
+                               $selected['public_flag'] = $characters_has_profile[0]['public_flag'];
+                       }
+                       if (isset($characters_has_profile[0]['link_value'])) {
+                               $selected['link_value'] = $characters_has_profile[0]['link_value'];
+                       }
                } else {
                        $selected = array(
                                'value' => '',
@@ -814,14 +913,18 @@ class ProfiledispHelper extends Helper {
        }
 
        /* postからprofile_select_id->profile_idで抽出 */
-       function get_selected_profile($profile_select, $characters_has_profile)
+       function get_selected_profile($profile_select, $characters_has_profile, $isProfileDefault = false)
        {
                $profile = array(
                        'profile_select_id' => $profile_select['id'],
                        'profile_id' => $profile_select['profile_id'],
-                       'value' => $profile_select['value'],
                );
 
+               if (!empty($isProfileDefault)) {
+               } else {
+                       $profile['value'] = $profile_select['value'];
+               }
+
                foreach ($characters_has_profile as $v) {
                        if (Set::contains($v, $profile)) {
                                return $v;
@@ -840,5 +943,194 @@ class ProfiledispHelper extends Helper {
 
                return true;
        }
+
+       function autoLinkProf($value)
+       {
+               if (!$value) {
+                       return null;
+               }
+
+               // URL espaceの解除
+               $patterns = array("/\&amp;/", "/\&#37;/", "/\&#43;/", "/\&#45;/");
+               $replacements = array("&", "%", "+", "-");
+               $value = preg_replace($patterns, $replacements, $value);
+
+               return $this->Text->autoLinkUrls(
+                       $value,
+                       array(
+                               'target' => '_blank',
+                               'escape' => false,
+                       )
+               );
+;
+       }
+
+       /* ProfileTableを横並びに表示(行単位) */
+       function dispTableBySideways($profile, $key_name = 'title', $option = array())
+       {
+               $option = array_merge(array(
+                       'header' => null,
+                       'type' => 'text',
+                       'tabindex' => array(
+                               'start' => 0,
+                               'gap' => 0,
+                       ),
+                       'add_column' => array(),
+                       'form_options' => array(),
+                       'tr_options' => array(),
+                       'td_options' => array(),
+               ), $option);
+
+               if (!isset($profile['ProfileTable']) || empty($profile['ProfileTable'])) {
+                       if (isset($option['add_column']) && empty($option['add_column'])) {
+                               return null;
+                       }
+               }
+
+               if (!empty($option['add_column'])) {
+                       $add_profile = array(
+                               'id' => 0,
+                               'profile_id' => $profile['Profile']['id'],
+                               'title' => '',
+                               'tablekey_name' => '',
+                               'width' => '',
+                               'sort_order' => '',
+                               'ProfileTableStatic' => array(),
+                       );
+                       if (isset($option['add_column']['data']) && isset($add_profile[$key_name])) {
+                               $add_profile[$key_name] = $option['add_column']['data'];
+                       }
+                       if (isset($option['add_column']['place']) && $option['add_column']['place'] == 'top') {
+                               array_unshift($profile['ProfileTable'], $add_profile);
+                       } else {
+                               array_push($profile['ProfileTable'], $add_profile);
+                       }
+               }
+
+               $rows = count($profile['ProfileTable']);
+               if (!empty($option['header'])) {
+                       $tds = $this->Html->tag('th', $option['header'], array('style' => 'width:65px;'));
+               } else {
+                       $tds = null;
+               }
+
+               for ($i=0; $i<$rows;$i++) {
+                       if (!isset($profile['ProfileTable'][$i][$key_name])) {
+                               $profile['ProfileTable'][$i][$key_name] = null;
+                       }
+
+                       if ($option['type'] == 'form') {
+                               $tabindex = $option['tabindex']['start'] + $option['tabindex']['gap'] * $i;
+                               $form_options = array_merge(
+                                       array(
+                                               'type' => 'text',
+                                               'value' => $profile['ProfileTable'][$i][$key_name],
+                                               'label' => false,
+                                               'tabindex' => $tabindex,
+                                       ),
+                                       $option['form_options']
+                               );
+
+                               $content = $this->Form->input(
+                                       'ProfileTable.'.$profile['ProfileTable'][$i]['id'].'.'.$key_name,
+                                       $form_options
+                               );
+                               $option['td_options'] = array_merge($option['td_options'], array('escape' => false));
+                       } else {
+                               if (isset($option['add_column']['place']) &&
+                                       (($option['add_column']['place'] == 'top' && $i == 0) || 
+                                       ($option['add_column']['place'] != 'top' && $i == $rows - 1))) {
+                                       $content = __('Add', true);
+                               } else {
+                                       $content = $profile['ProfileTable'][$i][$key_name];
+                               }
+                       }
+
+                       $tds .= $this->Html->tag('td', $content, $option['td_options']);
+               }
+
+               return $this->Html->tag('tr', $tds, $option['tr_options']);
+       }
+
+
+       /* 一定の文字数で複数行に折り返すtruncate
+        * マルチバイト対応
+        * URLやタグはスキップしない
+        * @param array $options is for truncate()
+        */
+       function multi_truncate($text, $length = 20, $rows = 3, $options = array())
+       {
+               if (empty($text)) {
+                       return $text;
+               }
+
+               $rows = (int)$rows;
+               if (!($rows > 0)) {
+                       $rows = 1;
+               }
+
+               // 置換
+               $replace_pairs = array(
+                       // 改行
+                       '<br>' => "\n",
+                       '<br />' => "\n",
+                       // スペースの連続
+                       "\s\s" => "\s",
+                       ' ' => '',
+               );
+               $text = strtr($text, $replace_pairs);
+
+               // Sanitize戻し
+               $Sanitize = CorePlus::set_behavoir('SanitizePlus');
+               $text = $Sanitize->restore_html($this->model(), $text);
+
+               $text = trim($text);
+
+               if (mb_strlen($text) < $length) {
+                       return $text;
+               }
+
+               // 複数行対応
+               $result = array();
+               $last_row = '';
+               for ($i = 1; $i <= $rows; $i++) {
+                       if ($i > 1) {
+                               if (!$text) {
+                                       break;
+                               }
+
+                               // 前行の分を切り取り
+                               if (!empty($last_row)) {
+                                       $text = substr_replace($text, '', 0, strlen($last_row));
+                               }
+                       }
+                       if ($i == $rows) {
+                               $text_len = mb_strlen($text);
+
+                               if ($text_len < $length) {
+                                       $result[$i] = $text;
+                               } else {
+                                       $result[$i] = $this->Text->truncate($text, mb_strlen(mb_substr($text, 0, $length)), $options);
+                               }
+
+                               break;
+                       } else {
+                               $result[$i] = mb_substr($text, 0, $length);
+                       }
+
+                       $last_row = $result[$i];
+                       $result[$i] = strip_tags($result[$i]);
+
+
+                       // タグをエスケープ
+                       $result[$i] = $Sanitize->escapeTags($this->model(), $result[$i]);
+               }
+
+               $text = implode("<br />\n", $result);
+
+               return $text;
+       }
+
+
 }