コード例 #1
0
 public function settingsAction()
 {
     $auth = new FrontEndAuth();
     if (!$auth->hasIdentity(3)) {
         return $this->redirect()->toUrl('/login');
     }
     $session = new Container('frontend');
     $common = new Common();
     $api = new Api();
     $api_url = $this->getServiceLocator()->get('config')['api_url']['value'];
     $featureData = $common->getFeatures($api_url, $session->userid);
     $subscriptionData = $this->getSpsubscription($session->userid, $api, $api_url);
     $result_newsletter = $common->chkNewsletter($api_url);
     $unsubscribe_reasons = $common->getUnsubscribereason($api_url);
     $model = new Practitioners();
     $notifications = $model->getNotifications($api_url);
     $sp_details = $model->getSPDetails($api_url, $session->userid);
     $form = new SPChangePasswordForm();
     $form->get('submit')->setValue('Add');
     $request = $this->getRequest();
     if ($this->getRequest()->isXmlHttpRequest()) {
         $request = $this->getRequest();
         $error = false;
         $request->getPost('action') != '' ? $action = $request->getPost('action') : ($action = '');
         if ($action == "change_password") {
             if (preg_match('/^.*(?=.{6,})(?=.*[0-9])(?=.*[a-z])(?=.*[A-Z])(?=.*[^a-zA-Z0-9])(?!.*\\s).*$/', $request->getPost('Pass'))) {
                 $request->getPost('old_pass') != '' ? $old_pass = $request->getPost('old_pass') : ($old_pass = '');
                 $request->getPost('Pass') != '' ? $Pass = $request->getPost('Pass') : ($Pass = '');
                 $request->getPost('confirm_password') != '' ? $confirm_password = $request->getPost('confirm_password') : ($confirm_password = '');
                 if ($old_pass != '' && $Pass != '' && $confirm_password != '') {
                     if ($Pass == $confirm_password) {
                         $data = array('op' => 'changepassword', 'old_password' => md5($old_pass), 'new_password' => md5($Pass), 'user_id' => $session->userid);
                         $url = $api_url . "/api/useractivity/";
                         $res = $api->curl($url, $data, "POST");
                         if ($res->getStatusCode() == 200) {
                             $msg = "Success!! Password changed sucessfully";
                         } else {
                             if ($res->getStatusCode() == 404) {
                                 $error = true;
                                 $msg = "Error!! Old password is not correct";
                             } else {
                                 $error = true;
                                 $msg = "Error!! Password could not be updated";
                             }
                         }
                     } else {
                         // Password and confirm password do not match
                         $error = true;
                         $msg = "Error!! Confirm password do not match";
                     }
                 } else {
                     $error = true;
                     $msg = "Error!! Invalid form data";
                 }
             } else {
                 $error = true;
                 $msg = "Password must be at least 6 characters and must contain at least one lower case letter, one upper case letter, one digit and one special character.";
             }
             echo json_encode(array('error' => $error, 'msg' => $msg));
             exit;
         } else {
             if ($action == "change_features") {
                 $request->getPost('feature_email') != '' ? $feature_email = $request->getPost('feature_email') : ($feature_email = '');
                 $request->getPost('feature_sms') != '' ? $feature_sms = $request->getPost('feature_sms') : ($feature_sms = '');
                 $request->getPost('feature_chat') != '' ? $feature_chat = $request->getPost('feature_chat') : ($feature_chat = '');
                 $request->getPost('feature_table_id') != '' ? $feature_table_id = $request->getPost('feature_table_id') : ($feature_table_id = '');
                 $data = array('email' => $feature_email, 'sms' => $feature_sms, 'chat' => $feature_chat, 'user_id' => $session->userid);
                 $data['id'] = $featureData['id'];
                 if ($common->addFeature($api_url, $data)) {
                     $msg = "Feature setting updated successfully";
                 } else {
                     $error = true;
                     $msg = "Feature setting updated successfully";
                 }
                 echo json_encode(array('error' => $error, 'msg' => $msg));
                 exit;
             } else {
                 if ($action == "newletter-chk") {
                     $request->getPost('newletter_chk') != '' ? $newletter_chk = $request->getPost('newletter_chk') : ($newletter_chk = '');
                     $data = array('user_id' => $session->userid, 'newsletter' => $newletter_chk);
                     if (isset($featureData['id'])) {
                         // update
                         $url = $api_url . '/api/userfeaturesetting/' . $featureData['id'] . '/';
                         $res = $api->curlUpdate($url, $data, "PUT");
                     } else {
                         $url = $api_url . '/api/userfeaturesetting/';
                         $res = $api->curlUpdate($url, $data, "POST");
                     }
                     if ($res) {
                         $msg = "Feature setting updated successfully";
                     } else {
                         $error = true;
                         $msg = "Feature setting updated successfully";
                     }
                     echo json_encode(array('error' => $error, 'msg' => $msg));
                     exit;
                 } else {
                     if ($action == "auto-renewal") {
                         $autorenew = $request->getPost('auto_renewal') != '' ? $request->getPost('auto_renewal') : '0';
                         $subscription_id = $request->getPost('subscription_id') != '' ? $request->getPost('subscription_id') : '';
                         $result = $common->autorenew($api_url, $subscription_id, $autorenew);
                         echo json_encode($result);
                         exit;
                     } else {
                         if ($action == "close-acc") {
                             $reason_id = $request->getPost('reason_id') != '' ? $request->getPost('reason_id') : '';
                             $other_reason = $request->getPost('other_reason') != '' ? $request->getPost('other_reason') : '';
                             if ($reason_id !== '') {
                                 $result = $common->isaccountRemovable($api_url);
                                 if (!$result) {
                                     $error = true;
                                     $msg = "Sorry!! you cannot deactivate your account untill you clear all your pending bookings.";
                                 } else {
                                     if ($reason_id == 5 && $other_reason == '') {
                                         $error = true;
                                         $msg = "Please provide other reason in the text area";
                                     } else {
                                         $result = $common->closeAccount($api_url, $reason_id, $other_reason);
                                         if ($result) {
                                             // close acc here
                                             $msg = "You account has been deactivated successfully..you will be logged out in 5 seconds";
                                         } else {
                                             // error acc could not be closed
                                             $error = true;
                                             $msg = "Some Error occured , Could not close your account , please try after some time";
                                         }
                                     }
                                 }
                             } else {
                                 $error = true;
                                 $msg = "Please provide us a reason to close your account";
                             }
                             echo json_encode(array('error' => $error, 'msg' => $msg));
                             exit;
                         } else {
                             if ($action == "unsubscribe") {
                                 $subscription_id = $request->getPost('subscription_id') != '' ? $request->getPost('subscription_id') : '';
                                 $result = $common->unsubscribeMembership($api_url, $subscription_id);
                                 if ($result) {
                                     $msg = "Unsubscribed Successfully";
                                 } else {
                                     $error = true;
                                     $msg = "Error, could not unsubscribe";
                                 }
                                 echo json_encode(array('error' => $error, 'msg' => $msg));
                                 exit;
                             } else {
                                 if ($action == "update_card") {
                                     $trans = new Transactions();
                                     echo json_encode($trans->updateCard($this->getServiceLocator()->get('config'), $request->getPost('card_data')));
                                     exit;
                                 } else {
                                     $error = true;
                                     $msg = "Invalid request";
                                     echo json_encode(array('error' => $error, 'msg' => $msg));
                                     exit;
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     // getting banner for this page
     $banners = $common->getBanner($api_url, 4);
     return new ViewModel(array('form' => $form, 'featureData' => $featureData, 'subscriptionData' => $subscriptionData, 'notifications' => $notifications, 'avtar_url' => $sp_details['avtar_url'], 'first_name' => $sp_details['first_name'], 'last_name' => $sp_details['last_name'], 'newsletter_chk' => $result_newsletter, 'reasonsList' => $unsubscribe_reasons, 'card_details' => $common->getUserCardDetails($api_url, array('user_id' => $session->userid)), 'banners' => $banners));
 }