コード例 #1
0
ファイル: BitlyAccessTest.php プロジェクト: CakeDC/bitly
 /**
  * Start test callback
  * 
  * @param string $method Test being executed
  * @return void
  */
 public function startTest($method)
 {
     parent::startTest($method);
     $this->BitlyApi = new MockBitlyApiBehavior();
     if ($this->__testWithMockApi) {
         Classregistry::removeObject('bitly_api_behavior');
         Classregistry::addObject('bitly_api_behavior', $this->BitlyApi);
     }
     $this->BitlyAccess = ClassRegistry::init('Bitly.BitlyAccess');
 }
コード例 #2
0
ファイル: controller.php プロジェクト: swordguard/hello-world
 function index($pageID = 0, $registration_type = null)
 {
     App::import('Controller', 'Locations');
     $locations = new LocationsController();
     $locations->constructClasses();
     /* Step 1: set the layout for registration page and include the required CSS and JS (validation etc..) for registration page */
     $this->layout = 'default';
     /* Step 2: retrieve the required data. These data could be cached. The data is displayed in the view */
     //$this->getShowData();
     $this->set('showPages', $this->showPages);
     $this->set('showContents', $this->showContents);
     $this->set('showContentConfigurations', $this->showContentConfigurations);
     $this->set('showQuestions', $this->showQuestions);
     $this->set('showForms', $this->showForms);
     $this->set('showDiscountCodes', $this->showDiscountCodes);
     $this->set('showDelegateDiscountRules', $this->showDelegateDiscountRules);
     $this->set('showTransactionDiscountRules', $this->showTransactionDiscountRules);
     $this->set('accom_booking_details', $this->getBookingDetails('passkey'));
     $this->set('countryPhoneCodes', $locations->getCountriesPhoneCodes());
     if (Configure::read('ISAReg.linked_in_sign_in') && Configure::read('linkedInAPIKey')) {
         $this->set('linked_in_sign_in_integration', true);
     }
     if (Configure::read('ISAReg.non_linear_nav') && $this->allNavStepsComplete()) {
         $this->set('all_nav_steps_complete', TRUE);
     }
     /* Step 2a: Load up the error messages */
     $this->Util->getErrorMessages();
     //get the default country and state list from XML files
     /* Step 3: set up the display logic */
     $nNoOfContent = count($this->showContents);
     $nNoOfNavContent = count($this->showPages);
     // Step 3a: Set the default page id. This is used to redirect user back to the default page ID whenever required
     if (!$this->Session->check('User.defaultPageID')) {
         if ($nNoOfContent > 0) {
             $this->Session->write('User.defaultPageID', $this->showContents[0]['page']['id']);
         } else {
             $this->Session->write('User.defaultPageID', 0);
         }
     }
     // Step 3b: if the show is closed, then set page ID to be the last page, which is the closed page
     if (!$this->Session->check('User.closedPageID')) {
         if ($nNoOfContent > 0) {
             $this->Session->write('User.closedPageID', $this->showContents[$nNoOfContent - 1]['page']['id']);
         } else {
             $this->Session->write('User.closedPageID', 0);
         }
     }
     /* Step 3c: get the current page the user is in. If page ID is not defined, set page ID to be the 1st page. */
     if ($this->Session->check('User.PageID') && $this->Session->read('User.PageID') != 0) {
         $this->Session->write('User.PageID', $this->Session->read('User.PageID'));
     } else {
         if (count($this->showContents)) {
             $this->Session->write('User.PageID', $this->showContents[0]['page']['id']);
         } else {
             $this->Session->write('User.PageID', 0);
         }
     }
     // Determine if the user is on the second last navigated page, and the data should be saved to the webtable
     $is_last_nav_page_to_save = FALSE;
     // Or if the user is on the last navigated page and their session should be destroyed
     $is_final_nav_page = FALSE;
     $current_page_location = $this->Util->ArraySearchRecursive($this->Session->read('User.PageID'), $this->showPages, 'id');
     if ($current_page_location !== FALSE) {
         $current_page_location = current($current_page_location);
         if ($current_page_location === $nNoOfNavContent - 2) {
             $is_last_nav_page_to_save = TRUE;
         } elseif ($current_page_location === $nNoOfNavContent - 1) {
             $is_final_nav_page = TRUE;
         }
     }
     /* Step 3d: define the default registration session data if it doesnt exist yet */
     if (strtotime(date("d-m-Y H:i")) >= strtotime(Configure::read('ISAReg.show_closed_date'))) {
         $this->Session->write('User.PageID', $this->Session->read('User.closedPageID'));
     }
     /* Step 3d: redirect user to the 1st page, if they try to go to the navigated page without completing the data */
     $arrPageID = $this->Util->ArraySearchRecursive($this->Session->read('User.PageID'), $this->showPages, 'id');
     //if current pageID is navigated page
     if (is_array($arrPageID)) {
         //if current pageID is not a first navigated page or the last navigated page
         if ($arrPageID[0] > 0 && $arrPageID[0] < count($this->showPages)) {
             // If we are allowing non-linear navigation, then we will allow random completion of the form pages
             if (Configure::read('ISAReg.non_linear_nav')) {
                 // Do nothing - we are happy to let the user navigate around at will
                 // Otherwise we will enforce the proper page order
             } else {
                 // check if the first navigated page exists in the _SESSION['navPageVisited'] array, if it does not, redirect to the default page
                 if (!$this->Session->check('navPageVisited')) {
                     if ($current_page_location) {
                         $this->redirect(array('controller' => 'registrations', 'action' => 'index', $this->showContents[0]['page']['id']));
                     }
                 } else {
                     // Check that the user has visited all of the previous navigation pages - if not, then redirect them to the next one in the sequence that they must complete
                     $visited_pages = $this->Session->read('navPageVisited');
                     // Get this page id
                     $this_page_id = $this->Session->read('User.PageID');
                     // Get the previous page id
                     $previous_page_id = $this->showPages[$arrPageID[0] - 1]['Content']['id'];
                     // If this page is not in the list of navigated pages, or the previous page, redirect to the last navigated page + 1 (Unless updating profile)
                     // Or if the current page should not be displayed
                     $page_should_display = $this->pageShouldDisplay($this->Session->read("User.NavPages.{$arrPageID[0]}.Content"));
                     if (!$page_should_display || !$this->Session->check('User.updateProfile') && (!in_array($this_page_id, $visited_pages) && !in_array($previous_page_id, $visited_pages))) {
                         $last_navigated_page = $this->Util->ArraySearchRecursive(end($visited_pages), $this->showPages, 'id');
                         $next_required_page_index = $last_navigated_page[0] + 1;
                         $next_required_page_id = $this->showPages[$next_required_page_index]['Content']['id'];
                         $this->redirect(array('controller' => 'registrations', 'action' => 'index', $next_required_page_id));
                     }
                 }
             }
             //if the current page is the last navigated page, delete the Session as we dont want user to be able to go back to previous page as their registration data has been saved already
             if ($is_final_nav_page) {
                 // If we are allowing non-linear navigation, then we must check that the registration is complete
                 if (Configure::read('ISAReg.non_linear_nav')) {
                     if ($this->Session->read('navPageVisited')) {
                         $all_pages_complete = $this->allNavStepsComplete();
                     } else {
                         $this->redirect(array('controller' => 'registrations', 'action' => 'index', $this->showContents[0]['page']['id']));
                     }
                     // If not then we will redirect the user back to the first one that has not been completed
                     if (!$all_pages_complete) {
                         $last_navigated_page = $this->Util->ArraySearchRecursive(end($visited_pages), $this->showPages, 'id');
                         $next_required_page_index = $last_navigated_page[0] + 1;
                         $next_required_page_id = $this->showPages[$next_required_page_index]['Content']['id'];
                         $this->redirect(array('controller' => 'registrations', 'action' => 'index', $next_required_page_id));
                     }
                 }
                 // Update the RegStatus of the registration and send the confirmation email if last step was successful, as we are already in the last navigated page
                 if ($this->Session->read('User.Data.Registration.StepCompleted') == 1) {
                     $reg_status = self::REG_COMPLETE;
                     if ($this->Session->read('User.updateProfile')) {
                         $reg_status = self::REG_UPDATED;
                     }
                     $this->Session->write('User.Data.Registration.RegStatus', $reg_status);
                     $this->Session->write('User.Data.Registration.Downloaded', 0);
                     $this->saveDataToWebDB($this->Session->read('User'));
                     // Process any uploaded files
                     if ($this->Session->read('User.file_uploads')) {
                         $this->processFileUploads();
                     }
                     $attachments = array();
                     // Invoice + Confirmation
                     $pdf_invoice_path = null;
                     if (Configure::read('ISAReg.invoice_enable') == 1 && $this->Session->read('User.Data.Registration.PaymentProcessed') == 1) {
                         $pdf_invoice_path = $this->Pdf->generate('invoice_' . $this->Session->read('User.Data.Registration.FullCardNumber') . '.pdf', 'email' . DS . 'html' . DS . 'invoice_pdf', array('data' => $this->Session->read('User.Data')));
                         $invoice_delivery_method = Configure::read('ISAReg.invoice_delivery_method');
                         $invoice_delivery_method_definitions = array(0 => 'CONFIRMATION EMAIL', 1 => 'INVOICE EMAIL');
                         if ($invoice_delivery_method_definitions[$invoice_delivery_method] == 'INVOICE EMAIL') {
                             //debug($this->Session->read('User.Data'));
                             $this->sendInvoiceEmail($this->Session->read('User.Data'), $pdf_invoice_path);
                             $pdf_invoice_path = null;
                         } else {
                             $attachments[] = $pdf_invoice_path;
                         }
                         // remove the pdf-view instance from the registry so that only registration-contoller-view inside the repository
                         Classregistry::removeObject('view');
                     }
                     /* 20141223: Add new configuration option not to send confirmation email, client will be sending this from their end */
                     if (is_null(Configure::read('ISAReg.sendConfirmationEmail')) || Configure::read('ISAReg.sendConfirmationEmail')) {
                         $this->sendConfirmationEmail($this->Session->read('User.Data'), $attachments);
                     } elseif (Configure::read('ISAReg.sendColleagueConfirmationEmail') === true) {
                         $this->sendConfirmationEmail($this->Session->read('User.Data'), $attachments, false, true);
                     }
                 }
                 $this->set('userData', $this->Session->read('User.Data'));
                 // Set the uplad result to the session if there is one
                 if ($this->Session->read('User.file_uploads_result')) {
                     $this->set('uploadResult', $this->Session->read('User.file_uploads_result'));
                 }
                 //User was successfully saved to the Web Table && Payment is processed && Confirmationed Email sent so we need to delete the Session
                 //$this->deleteSessionData(array('navPageVisited', 'User.Data', 'User.updateProfile', 'User.prepopProfile', 'User.file_uploads_result'));
             }
         }
     }
     $i = 0;
     foreach ($this->showPages as $key) {
         if ($this->Session->read('User.PageID') == $key['Content']['id']) {
             $this->Session->write('User.currentPageIndex', $i);
             break;
         } else {
             $this->Session->write('User.currentPageIndex', 0);
         }
         $i++;
     }
     //Step 3e: Set up the registration type
     if (isset($registration_type) && $registration_type != null) {
         $this->set('registration_type', $registration_type);
         $this->Session->write('User.RegistrationType', $registration_type);
     }
     /* Step 4: save user's response data */
     if (!empty($this->data)) {
         // Perform server-side validation of the data submitted from this page
         $page_id = $this->Session->read('User.PageID');
         // If we are going back, we don't need to validate the page
         if (isset($this->data['Registration']['prevPage']) && $this->data['Registration']['prevPage']) {
             $page_valid = TRUE;
             // If we came from the create event profile form we need to suppress the serverside validation for the first nav page before the user has completed the whole form
         } elseif (!$this->Session->read('navPageVisited') && isset($this->data['CreateEventProfile']) && $current_page_location === 0) {
             $page_valid = TRUE;
             unset($this->data['CreateEventProfile']);
         } else {
             $reg_type = 'default';
             if ($this->Session->read('User.RegistrationType')) {
                 $reg_type = $this->Session->read('User.RegistrationType');
             }
             $validate_questions = NULL;
             if (isset($this->showQuestions[$reg_type])) {
                 $validate_questions = $this->showQuestions[$reg_type];
             }
             $this->Validator->init($this->showContents, $this->showContentConfigurations, $this->showForms, $validate_questions, $this->data);
             $page_valid = $this->Validator->validatePage($page_id);
         }
         if ($page_valid === TRUE) {
             // Discard any file upload refs we may still have in the data as we don't need those any more
             unset($this->data['Registration']['files']);
             // Check for any pre-existing data to prepop or update
             $prepop_data = false;
             if (isset($this->data['Registration']['prepopProfile']) && $this->data['Registration']['prepopProfile']) {
                 $prepop_data = true;
             }
             $existing_reg_data = false;
             if (isset($this->data['Registration']['updateProfile']) && $this->data['Registration']['updateProfile']) {
                 $existing_reg_data = true;
             }
             // If we have either prepop or existing data then attempt to use that data
             if ($prepop_data || $existing_reg_data) {
                 $users_data = $this->getPrepopulateData($this->data);
                 if ($users_data) {
                     $user_data_found = $this->checkPrepopUser($users_data);
                     switch ($user_data_found) {
                         case self::CHECK_USER_REG_FOUND:
                             $this->set('updateProfile', 1);
                             $this->Session->write('User.UserData', $users_data);
                             if (!$this->Session->check('User.updateProfile')) {
                                 $this->Session->write('User.updateProfile', 1);
                             }
                             $this->redirect(array('controller' => 'registrations', 'action' => 'verifyUser'));
                             break;
                         case self::CHECK_USER_PREPOP_FOUND:
                             $this->set('prepopProfile', 1);
                             $this->Session->write('User.UserData', $users_data);
                             if (!$this->Session->check('User.prepopProfile')) {
                                 $this->Session->write('User.prepopProfile', 1);
                             }
                             $this->redirect(array('controller' => 'registrations', 'action' => 'verifyUser'));
                             break;
                             // case self::CHECK_USER_NO_DATA_FOUND: not required - fall through to default action
                         // case self::CHECK_USER_NO_DATA_FOUND: not required - fall through to default action
                         default:
                             if (!($this->Session->check('User.prepopProfile') || $this->Session->check('User.updateProfile'))) {
                                 $this->Session->write('errorFound', 1);
                                 $this->Session->write('errorMessage', Configure::read('prepopulationErrorMessage'));
                             }
                     }
                 }
             }
             /******** RETRIEVE PASSWORD ***********/
             //user wants to retrieve password. We need to validate user 1st, if not found, return error message, else redirect to the 1st form page with retrievePassword = 1 and the found data
             if (isset($this->data['Registration']['retrievePassword']) && $this->data['Registration']['retrievePassword'] == 1) {
                 //echo 'Retrieving User Password<br>';
                 //debug($this->data);
                 $userData = $this->retrievePassword($this->data);
                 //debug($userData);
                 if (!empty($userData)) {
                     $this->set('retrievePassword', 1);
                 }
             }
             /******** SEND INVITATION EMAIL ***********/
             //send colleague email. Registration confirmed email is only sent when data is successfully saved into DB
             if (isset($this->data['Registration']['sendColleagueEmail']) && $this->data['Registration']['sendColleagueEmail'] == 1) {
                 $this->sendInvitationEmail($this->data);
                 $this->set('sendInvitationEmail', 1);
             }
             /******** RESEND CONFIRMATION EMAIL ***********/
             //Resend Confirmation Email to User
             if (isset($this->data['Registration']['resendConfirmationEmail']) && $this->data['Registration']['resendConfirmationEmail'] == 1) {
                 $this->resendConfirmationEmail($this->data);
                 $this->set('resendConfirmationEmailDone', 1);
             }
             $update_profile_and_exit = FALSE;
             if (isset($this->data['Registration']['UpdateProfileAndExit']) && $this->data['Registration']['UpdateProfileAndExit'] == 1) {
                 $update_profile_and_exit = TRUE;
             }
             $save_and_exit = FALSE;
             if (isset($this->data['Registration']['SaveAndExit']) && $this->data['Registration']['SaveAndExit'] == 1) {
                 $save_and_exit = TRUE;
             }
             /******** SAVE REGISTRATION FORM DATA TO SESSION OR WEB TABLE ***********/
             // Save the form data only if the user has navigated forward
             if (!isset($this->data['Registration']['prevPage']) || !$this->data['Registration']['prevPage']) {
                 if (!Configure::read('ISAReg.save_data_every_step')) {
                     //save navigated form data to session if the current page is the navigated page
                     if (is_array($arrPageID)) {
                         $this->saveFormDataToSession($this->data);
                     }
                 } else {
                     if (is_array($arrPageID)) {
                         $this->saveFormDataToSession($this->data);
                         $this->calculateDiscount();
                         $this->saveDataToWebDB($this->Session->read('User'));
                         // The calculation of discount to multiple guest must occur after the fullcard number generation.
                         // If the save discount is required immediate after the step, then another save should be triggered.s
                         if (isset($this->data['Registration']['SaveDiscountImmediate']) && $this->data['Registration']['SaveDiscountImmediate'] == 1) {
                             $this->calculateDiscount();
                             $this->saveDataToWebDB($this->Session->read('User'));
                         }
                         $this->saveDataToWebDBDone = 1;
                     }
                 }
                 /******** SAVE REGISTRATION FORM DATA TO WEB TABLE ***********/
                 if (!(isset($this->saveDataToWebDBDone) && $this->saveDataToWebDBDone == 1)) {
                     if (isset($this->data['Registration']['saveDataToWebTable']) && $this->data['Registration']['saveDataToWebTable'] == 1 || isset($this->data['Registration']['savePaymentData']) && $this->data['Registration']['savePaymentData'] == 1 || $is_last_nav_page_to_save && !Configure::read('ISAReg.non_linear_nav') || $update_profile_and_exit || $save_and_exit) {
                         $this->calculateDiscount();
                         $this->saveDataToWebDB($this->Session->read('User'));
                         if (isset($this->data['Registration']['SaveDiscountImmediate']) && $this->data['Registration']['SaveDiscountImmediate'] == 1) {
                             $this->calculateDiscount();
                             $this->saveDataToWebDB($this->Session->read('User'));
                         }
                     }
                 }
             } else {
                 // Else if the user has navigated back then clean out any payment data we might have
                 $payment_data = array('savePaymentData', 'PaymentType', 'CardType', 'CardHolder', 'CardNumber', 'CardExpMonth', 'CardExpYear', 'CardCVV');
                 foreach ($payment_data as $payment_data_item) {
                     unset($this->data['Registration'][$payment_data_item]);
                     $this->Session->delete('User.Data.Registration.' . $payment_data_item);
                 }
             }
             /******** NAVIGATED WHEN NEXT OR BACK BUTTON IS CLICKED ***********/
             //if data been save successfully, redirect to the next available page if next button was clicked
             //or go back to the previous page if back button was clicked. Otherwise, redirect back to the current page.
             if (!$this->Session->read('errorFound')) {
                 //go to next page
                 $next_page = FALSE;
                 if (isset($this->data['Registration']['nextPage']) && $this->data['Registration']['nextPage'] == 1) {
                     $next_page = TRUE;
                     $this->addNavPageVisited($this->Session->read('User.PageID'));
                 }
                 if (Configure::read('ISAReg.non_linear_nav') && $this->allNavStepsComplete()) {
                     $this->set('all_nav_steps_complete', TRUE);
                 }
                 if ($next_page || $update_profile_and_exit || $save_and_exit) {
                     // If we have non-linear navigation enabled then we will reload the same page after saving
                     if (Configure::read('ISAReg.non_linear_nav') && !$save_and_exit) {
                         // Do nothing
                         // Otherwise we will load the next page
                     } else {
                         $next_page_id = $this->getNextPageId();
                         $this->Session->write('User.PageID', $next_page_id);
                         $this->redirect(array('controller' => 'registrations', 'action' => 'index', $next_page_id));
                     }
                 }
                 //go to previous page
                 if (isset($this->data['Registration']['prevPage']) && $this->data['Registration']['prevPage'] == 1) {
                     $previous_page_id = $this->getPreviousPageId();
                     $this->Session->write('User.PageID', $previous_page_id);
                     $this->redirect(array('controller' => 'registrations', 'action' => 'index', $previous_page_id));
                 }
             } else {
                 $this->redirect(array('controller' => 'registrations', 'action' => 'index', $pageID));
             }
             // Handle any validation errors found
         } else {
             $this->Session->write('errorFound', 1);
             $this->Session->write('errorMessage.validation', $page_valid);
         }
     }
     // If we get here but have no $_POST data and the REQUEST_METHOD is POST and we have content length, then the user attempted to upload something that was too big and the server refused to process it
     // The result is that the same page is loaded again
     if ($_SERVER['REQUEST_METHOD'] == 'POST' && empty($_POST) && $_SERVER['CONTENT_LENGTH'] > 0) {
         $this->Session->write('errorFound', 1);
         if (!class_exists('RpgUtil')) {
             App::import('Lib', 'RpgUtil');
         }
         $error_message = sprintf('The total size of the data you tried to submit (Including uploaded files) was too big: %sMB<br />', RpgUtil::convertMbToBytes($_SERVER['CONTENT_LENGTH']));
         $error_message .= 'The maximum total size you can submit is ' . ini_get('post_max_size') . 'B - please try again.';
         $this->Session->write('errorMessage', $error_message);
     }
 }