Пример #1
0
 public function screen_modify($auth = "")
 {
     $btn = "";
     $btn2 = "";
     $this->file = "memberinfo_form.tpl";
     // データベースを操作します。
     $MemberModel = new MemberModel();
     $PrememberModel = new PrememberModel();
     if ($this->is_system && $this->action == "form") {
         $_SESSION[_MEMBER_AUTHINFO] = $MemberModel->get_member_data_id($_GET['id']);
     }
     // フォーム要素のデフォルト値を設定
     $date_defaults = ['Y' => substr($_SESSION[_MEMBER_AUTHINFO]['birthday'], 0, 4), 'm' => substr($_SESSION[_MEMBER_AUTHINFO]['birthday'], 4, 2), 'd' => substr($_SESSION[_MEMBER_AUTHINFO]['birthday'], 6, 2)];
     $this->form->setDefaults(['username' => $_SESSION[_MEMBER_AUTHINFO]['username'], 'last_name' => $_SESSION[_MEMBER_AUTHINFO]['last_name'], 'first_name' => $_SESSION[_MEMBER_AUTHINFO]['first_name'], 'ken' => $_SESSION[_MEMBER_AUTHINFO]['ken'], 'birthday' => $date_defaults]);
     $this->make_form_controle();
     // フォームの妥当性検証
     if (!$this->form->validate()) {
         $this->action = "form";
     }
     if ($this->action == "form") {
         $this->title = '更新画面';
         $this->next_type = 'modify';
         $this->next_action = 'confirm';
         $btn = '確認画面へ';
     } else {
         if ($this->action == "confirm") {
             $this->title = '確認画面';
             $this->next_type = 'modify';
             $this->next_action = 'complete';
             $this->form->freeze();
             $btn = '更新する';
             $btn2 = '戻る';
         } else {
             if ($this->action == "complete" && isset($_POST['submit2']) && $_POST['submit2'] == '戻る') {
                 $this->title = '更新画面';
                 $this->next_type = 'modify';
                 $this->next_action = 'confirm';
                 $btn = '確認画面へ';
             } else {
                 if ($this->action == "complete" && isset($_POST['submit']) && $_POST['submit'] == '更新する') {
                     $userdata = $this->form->getSubmitValues();
                     if (($MemberModel->check_username($userdata) || $PrememberModel->check_username($userdata)) && $_SESSION[_MEMBER_AUTHINFO]['username'] != $userdata['username']) {
                         $this->next_type = 'modify';
                         $this->next_action = 'confirm';
                         $this->title = '更新画面';
                         $this->message = "メールアドレスは登録済みです。";
                         $btn = '確認画面へ';
                     } else {
                         $this->title = '更新完了画面';
                         $userdata['id'] = $_SESSION[_MEMBER_AUTHINFO]['id'];
                         // システム側から利用するときに利用
                         if ($this->is_system && is_object($auth)) {
                             $userdata['password'] = $auth->get_hashed_password($userdata['password']);
                         } else {
                             $userdata['password'] = $this->auth->get_hashed_password($userdata['password']);
                         }
                         $userdata['birthday'] = sprintf("%04d%02d%02d", $userdata['birthday']['Y'], $userdata['birthday']['m'], $userdata['birthday']['d']);
                         $MemberModel->modify_member($userdata);
                         $this->message = "会員情報を修正しました。";
                         $this->file = "message.tpl";
                         if ($this->is_system) {
                             unset($_SESSION[_MEMBER_AUTHINFO]);
                         } else {
                             $_SESSION[_MEMBER_AUTHINFO] = $MemberModel->get_member_data_id($_SESSION[_MEMBER_AUTHINFO]['id']);
                         }
                     }
                 }
             }
         }
     }
     $this->form->addElement('submit', 'submit', $btn);
     $this->form->addElement('submit', 'submit2', $btn2);
     $this->form->addElement('reset', 'reset', '取り消し');
     $this->view_display();
 }