public function onBootstrap(MvcEvent $e) { $eventManager = $e->getApplication()->getEventManager(); $serviceManager = $e->getApplication()->getServiceManager(); $moduleRouteListener = new ModuleRouteListener(); $moduleRouteListener->attach($eventManager); $this->bootstrapSession($e); // Added by sazid to use common data in every page $application = $e->getParam('application'); $viewModel = $application->getMvcEvent()->getViewModel(); $api_url = $serviceManager->get('Config')['api_url']['value']; $session_apiurl = new Container('api_url'); $session_apiurl->apiurl = $api_url; $apiCall = new Api(); $getCommonData = $apiCall->getCommonData($api_url); foreach ($getCommonData as $key => $val) { if (!empty($val)) { $viewModel->{$key} = $val; } } // Hybrid view for ajax calls (disable layout for xmlHttpRequests) $eventManager->getSharedManager()->attach('Zend\\Mvc\\Controller\\AbstractController', MvcEvent::EVENT_DISPATCH, function (MvcEvent $event) { /** * @var Request $request */ $request = $event->getRequest(); $viewModel = $event->getResult(); $vModel = $event->getViewModel(); $vModel->setVariable('api_url', $event->getApplication()->getServiceManager()->get('Config')['api_url']['value']); $userAuth = new FrontEndAuth(); if ($userAuth->hasIdentity()) { $practitioner = new Practitioners(); $userSession = new Container('frontend'); $userType = $userSession->user_type_id == '3' ? 'practitioner' : 'consumer'; $vModel->setVariable('notifications', $practitioner->getNotifications($event->getApplication()->getServiceManager()->get('Config')['api_url']['value'], $userType)); } if ($request->isXmlHttpRequest()) { $viewModel->setTerminal(true); } return $viewModel; }, -95); $eventManager->attach('route', array($this, 'doHttpsRedirect')); }
public function readnotificationsAction() { $request = $this->getRequest(); if ($request->isPost()) { $model = new Practitioners(); $session = new Container('frontend'); $api_url = $this->getServiceLocator()->get('config')['api_url']['value']; if ($model->readNotifications($api_url, $request->getPost('tab'), $session->userid)) { echo json_encode(array('status' => 1, 'notifications' => $model->getNotifications($api_url))); } else { echo json_encode(array('status' => 0, 'notifications' => $model->getNotifications($api_url))); } } exit; }
public function settingsAction() { $auth = new FrontEndAuth(); if (!$auth->hasIdentity(4)) { return $this->redirect()->toUrl('/login'); } $session = new Container('frontend'); $api = new Api(); $common = new Common(); $booking_model = new Bookings(); $api_url = $this->getServiceLocator()->get('config')['api_url']['value']; $featureData = $common->getFeatures($api_url, $session->userid); $result_newsletter = $common->chkNewsletter($api_url); $unsubscribe_reasons = $common->getUnsubscribereason($api_url); $model_practitioner = new Practitioners(); $model_consumer = new Consumers(); $notifications = $model_practitioner->getNotifications($api_url, 'consumer'); $consumer_details = $model_consumer->getConsumerdetails($api_url, $session->userid); if (!$consumer_details) { $this->redirect()->toUrl('/consumer/index'); } $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 == "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 !== '') { 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 // remove all related bookings $bookings_data = $booking_model->getBookings($api_url, "", $session->userid, '', '', '', '', '', ''); if (isset($bookings_data['booking_ids']) && !empty($bookings_data['booking_ids'])) { $booking_ids = explode(',', $bookings_data['booking_ids']); $twilloconf = $this->getServiceLocator()->get('config')['Twilio']; if (count($booking_ids) > 0) { foreach ($booking_ids as $ids) { if (isset($ids['id']) && !empty($ids['id'])) { $booking_result = $booking_model->changeBookingStatus($api_url, $ids['id'], "6", $twilloconf); } } } } $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 { $error = true; $msg = "Invalid request"; echo json_encode(array('error' => $error, 'msg' => $msg)); exit; } } } } } $consumer_details = $model_consumer->getConsumerdetails($api_url, $session->userid); $data = $this->getConsumerData($consumer_details); // getting banner for this page $banners = $common->getBanner($api_url, 5); return new ViewModel(array('consumer' => $data, 'form' => $form, 'featureData' => $featureData, 'notifications' => $notifications, 'avtar_url' => $consumer_details['avtar_url'], 'first_name' => $consumer_details['first_name'], 'last_name' => $consumer_details['last_name'], 'newsletter_chk' => $result_newsletter, 'reasonsList' => $unsubscribe_reasons, 'banners' => $banners)); }
public function suggestTime($api_url, $booking, $newDate, $userid, $user_type_id, $common) { $model = new Practitioners(); $suggestion_res = $this->api->curl($api_url . "/api/suggestionhistory/", array('booking_id' => $booking), "GET"); if ($suggestion_res->getStatusCode() == 200) { $suggestions = json_decode($suggestion_res->getBody(), true); // change status of all previous pending suggestions to cancel foreach ($suggestions as $suggestion) { $suggestion['booking_status'] == '5' ? $this->api->curl($api_url . "/api/suggestionhistory/" . $suggestion['id'] . "/", array('booking_status' => 6), "PUT") : ''; } $booking_data = $this->getBookings($api_url, '', '', '', '', '', '', $booking); if ($user_type_id == 3) { $userObject = new Consumers(); $user_type = 'Practitioner'; $sender_id = $booking_data['results'][0]['user_id']; $user_name = $booking_data['results'][0]['consumer_first_name'] . ' ' . $booking_data['results'][0]['consumer_last_name']; $user_email = $booking_data['results'][0]['consumer_email']; $contact = $userObject->getContact($api_url, $booking_data['results'][0]['user_id']); $phone = $contact[0]['home_phone']; } else { $userObject = new Practitioners(); $user_type = 'Consumer'; $sender_id = $booking_data['results'][0]['service_provider_id']; $user_name = $booking_data['results'][0]['sp_first_name'] . ' ' . $booking_data['results'][0]['sp_last_name']; $user_email = $booking_data['results'][0]['sp_email']; $contact = $userObject->getContact($api_url, $booking_data['results'][0]['service_provider_id']); $phone = $contact[0]['phone_number']; } // add new suggestion $add_res = $this->api->curl($api_url . "/api/suggestionhistory/", array('user_id' => $userid, 'booking_id' => $booking, 'booking_time' => date('Y-m-d H:i:s', strtotime($newDate)), 'booking_status' => 5), "POST"); if ($add_res->getStatusCode() != 200 && $add_res->getStatusCode() != 201) { return array('status' => '0', 'msg' => 'Failed to suggest new date and time for appointment..!!', 'errors' => json_decode($add_res->getBody(), true)); } else { $pattern = array('/{{user_name}}/i', '/{{user_type}}/i', '/{{booking_id}}/i', '/{{new_date_time}}/i'); $replace = array('<strong>' . $user_name . '</strong>', $user_type, '<strong>#' . $booking . '</strong>', '<strong>' . date('l d/m/Y h:i A', strtotime($newDate)) . '</strong>'); $subscriptionDetails = $common->getSubscriptiondetails($api_url, $booking_data['results'][0]['service_provider_id'], true); if ($user_type == 'Consumer') { $userFeatures = $common->getFeatures($api_url, $booking_data['results'][0]['user_id']); if (isset($subscriptionDetails['features']) && is_array($subscriptionDetails['features']) && in_array(11, $subscriptionDetails['features']) && $userFeatures['email'] == 1) { $common->sendMail($api_url, $user_email, '', 12, '', $pattern, $replace); } if (isset($subscriptionDetails['features']) && is_array($subscriptionDetails['features']) && in_array(12, $subscriptionDetails['features']) && $userFeatures['sms'] == 1) { $common->sendMsg($phone, 4, '', $pattern, array($user_name, $user_type, $booking, date('l d/m/Y h:i A', strtotime($newDate)))); } } else { $userFeatures = $common->getFeatures($api_url, $booking_data['results'][0]['service_provider_id']); $common->sendMail($api_url, $user_email, '', 12, '', $pattern, $replace); if (isset($subscriptionDetails['features']) && is_array($subscriptionDetails['features']) && in_array(12, $subscriptionDetails['features']) && $userFeatures['sms'] == 1) { $common->sendMsg($phone, 4, '', $pattern, array($user_name, $user_type, $booking, date('l d/m/Y h:i A', strtotime($newDate)))); } } return array('status' => '1', 'msg' => 'New date and time suggested for appointment..!!', 'notifications' => $model->getNotifications($api_url), 'phone' => $phone, 'features' => $userFeatures, 'subscription' => $subscriptionDetails['features']); } } else { return array('status' => '0', 'msg' => 'Unable to suggest new date and time for appointment..!!', 'errors' => json_decode($suggestion_res->getBody(), true)); } }
public function updateAction() { $request = $this->getRequest(); if ($request->isPost()) { $model = new Practitioners(); $bookingModel = new Bookings(); $action = $request->getPost('action', 'profile'); $api_url = $this->getServiceLocator()->get('config')['api_url']['value']; switch ($action) { case 'booking_status': $status = $request->getPost('status', 4); $ids = $request->getPost('bookings'); if (is_array($ids) && count($ids) > 0) { foreach ($ids as $id) { if (!$bookingModel->changeBookingStatus($api_url, $id, $status, $this->getServiceLocator()->get('Application\\Model\\Common'))) { echo json_encode(array('status' => 0, 'msg' => 'Failed to change booking status..!!')); exit; } } echo json_encode(array('status' => 1, 'msg' => 'Booking status changed successfully..!!', 'notifications' => $model->getNotifications($api_url))); } else { echo json_encode(array('status' => 0, 'msg' => 'Failed to change booking status..!!')); } break; } } exit; }