예제 #1
0
 public function screen_regist($auth = "")
 {
     $btn = "";
     $btn2 = "";
     $this->file = "memberinfo_form.tpl";
     // デフォルト
     // フォーム要素のデフォルト値を設定
     $date_defaults = ['Y' => date('Y'), 'm' => date('m'), 'd' => date('d')];
     $this->form->setDefaults(['birthday' => $date_defaults]);
     $this->make_form_controle();
     // フォームの妥当性検証
     if (!$this->form->validate()) {
         $this->action = "form";
     }
     if ($this->action == "form") {
         $this->title = '新規登録画面';
         $this->next_type = 'regist';
         $this->next_action = 'confirm';
         $btn = '確認画面へ';
     } else {
         if ($this->action == "confirm") {
             $this->title = '確認画面';
             $this->next_type = 'regist';
             $this->next_action = 'complete';
             $this->form->freeze();
             $btn = '登録する';
             $btn2 = '戻る';
         } else {
             if ($this->action == "complete" && isset($_POST['submit2']) && $_POST['submit2'] == '戻る') {
                 $this->title = '新規登録画面';
                 $this->next_type = 'regist';
                 $this->next_action = 'confirm';
                 $btn = '確認画面へ';
             } else {
                 if ($this->action == "complete" && isset($_POST['submit']) && $_POST['submit'] == '登録する') {
                     // データベースを操作します。
                     $PrememberModel = new PrememberModel();
                     // データベースを操作します。
                     $MemberModel = new MemberModel();
                     $userdata = $this->form->getSubmitValues();
                     if ($MemberModel->check_username($userdata) || $PrememberModel->check_username($userdata)) {
                         $this->title = '新規登録画面';
                         $this->message = "メールアドレスは登録済みです。";
                         $this->next_type = 'regist';
                         $this->next_action = 'confirm';
                         $btn = '確認画面へ';
                     } else {
                         // システム側から利用するときに利用
                         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']);
                         if ($this->is_system) {
                             $MemberModel->regist_member($userdata);
                             $this->title = '登録完了画面';
                             $this->message = "登録を完了しました。";
                         } else {
                             $userdata['link_pass'] = hash('sha256', uniqid(rand(), 1));
                             $PrememberModel->regist_premember($userdata);
                             $this->mail_to_premember($userdata);
                             $this->title = 'メール送信完了画面';
                             $this->message = "登録されたメールアドレスへ確認のためのメールを送信しました。<BR>";
                             $this->message .= "メール本文に記載されているURLにアクセスして登録を完了してください。<BR>";
                         }
                         $this->file = "message.tpl";
                     }
                 }
             }
         }
     }
     $this->form->addElement('submit', 'submit', $btn);
     $this->form->addElement('submit', 'submit2', $btn2);
     $this->form->addElement('reset', 'reset', '取り消し');
     $this->view_display();
 }