Пример #1
0
 public function load($id = null, $checkSession = true)
 {
     $this->id = $this->bucket = null;
     if ($id === null && $this->useCookie && isset($_COOKIE[$this->name]) && preg_match('/^[0-9a-zA-Z]{32}$/', $_COOKIE[$this->name])) {
         $id = $_COOKIE[$this->name];
     }
     if ($id) {
         $this->bucket = $this->bucketBase->load($id, $this->name);
     }
     $this->isNew = !$this->bucket;
     if (!$this->isNew) {
         if ($checkSession && !$this->checkSession()) {
             $this->reset();
         } else {
             $this->data = $this->bucket->data['data'];
             $this->id = $this->bucket->id;
         }
     } else {
         $this->data = null;
         $data = $this->_getBucketData();
         $this->bucket = $this->bucketBase->create($data, $this->expirationTime, $this->name);
         $this->id = $this->bucket->id;
     }
 }
Пример #2
0
 public function execute()
 {
     // PreInit form
     $this->_preInit();
     if ($this->flags == -1) {
         $this->flags = self::$defaultFlags;
     }
     $this->status = new StatusContainer();
     if (!$this->id) {
         $this->id = get_class($this);
     }
     $this->_internalID = substr(md5($this->id), 0, 8);
     $this->dataIn = $this->getDataIn();
     // Check for form id
     $requestedID = $this->dataIn->get($this->_internalID . '_BucketID');
     $isNew = !$requestedID;
     if (!$this->bucketBase) {
         if (!AdvancedForm::$defaultBucketBase) {
             trigger_error('Could not find valid bucket base. Specify with $form->bucketBase set AdvancedForm::$defaultBucketBase', E_USER_ERROR);
         }
         $this->bucketBase = AdvancedForm::$defaultBucketBase;
     }
     $context = $this->getContext();
     if ($this->status->error) {
         $this->_endProcessing();
         return;
     }
     // Form id existing, try to load bucket
     if (!$isNew) {
         $this->_bucket = $this->bucketBase->load($requestedID, $context);
         // No valid bucket found
         if (!$this->_bucket) {
             $isNew = true;
             $this->_processSecurityError(self::ERROR_DELETED);
         } else {
             /** @var AdvancedFormData $formData */
             $formData = $this->_bucket->data;
             $this->formData = $formData;
             $this->data = $this->formData->data;
             // Bucket is valid but doesn't fit to this form
             if ($this->formData->id != $this->dataIn->get('CT_Form_ID')) {
                 $isNew = true;
                 $this->_processSecurityError(self::ERROR_DELETED);
                 $this->_bucket = null;
             } else {
                 if ($this->formData->resetOnNextAccess) {
                     $this->formData->reset();
                     $this->formData->data = $this->data = $this->_createDataObject();
                 }
             }
             if ($this->formData->finished) {
                 $this->formData->finished = false;
             }
         }
     }
     // New form, create data object
     if ($isNew) {
         $this->data = $this->_createDataObject();
         $uID = StringTools::random(32);
         $this->formData = new AdvancedFormData($uID, $this->data);
         $this->_bucket = $this->bucketBase->create('', 86400, $context);
     }
     $this->isSubmit = $this->_isSubmit();
     // Init form
     $this->_init();
     // Form hasn't been submitted yet or an error has occurred, so end processing here
     if (!$this->isSubmit || !$this->flags & self::FLAG_ALLOW_INSTANT_SUBMIT && $isNew || $this->status->error) {
         $this->_endProcessing();
         return;
     }
     // Get submitted step
     $step = intval($this->dataIn->get('CT_Form_Step'));
     if ($step < 1 && $this->flags & self::FLAG_ALLOW_INSTANT_SUBMIT) {
         $step = 1;
     }
     if ($step < 1) {
         $this->_endProcessing();
         return;
     }
     if ($step > $this->formData->currentStep) {
         $this->_endProcessing();
         return;
     }
     $this->_getStepData($step);
     // Check whether earlier step is requested
     if (is_int($this->action)) {
         $this->formData->nextStep = $this->action;
         if ($this->formData->nextStep > 0 && $this->formData->nextStep <= $this->formData->currentStep) {
             $this->formData->currentStep = $this->formData->nextStep;
             $this->_endProcessing();
             return;
         } else {
             $this->action = 'next';
         }
     }
     if (!$this->action) {
         $this->action = 'next';
     }
     // Calculate next step
     if ($this->action == 'next') {
         $this->formData->nextStep = $this->_getNextStep($step);
     } else {
         if ($this->action == 'prev') {
             $this->formData->nextStep = $this->_getPrevStep($step);
         } else {
             $this->formData->nextStep = $step;
         }
     }
     if ($this->formData->nextStep < 1) {
         $this->formData->nextStep = 1;
     } else {
         if ($this->formData->nextStep > $this->steps) {
             $this->formData->nextStep = $this->steps;
         }
     }
     // Let's check some security stuff
     if ($this->flags & self::FLAG_ACTION_TIME && !$this->flags & self::FLAG_ALLOW_INSTANT_SUBMIT) {
         if (microtime(true) - $this->formData->lastAction < self::$earlyTimeout) {
             $this->_processSecurityError(self::ERROR_EARLY);
         }
     }
     if ($this->action == 'prev') {
         $this->formData->currentStep = $this->formData->nextStep;
         $this->_endProcessing();
         return;
     }
     if ($this->status->error || $this->steps > 1 && $step == $this->steps) {
         $this->_endProcessing();
         return;
     }
     $this->_checkStepData($step);
     // Form has some errors, so end processing here
     if ($this->status->error) {
         $this->_endProcessing();
         return;
     }
     $this->_submitStep($step);
     // Processing successful so set next step
     if (!$this->status->error && $this->steps > 1) {
         $this->formData->currentStep = $this->formData->nextStep;
     }
     $this->_endProcessing();
 }