Guest User

Untitled

a guest
Apr 21st, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.13 KB | None | 0 0
  1. <?php
  2.  
  3. class CheckoutForm extends User {
  4.  
  5.     public $authed;
  6.     public $restid;
  7.  
  8.     public $use_creditcard;
  9.     public $cc_serial;
  10.     public $cc_holder;
  11.     public $cc_exp_month;
  12.     public $cc_exp_year;
  13.     public $cc_ccv;
  14.  
  15.     public $method;
  16.     public $address;
  17.     public $phonenumber;
  18.     public $instruction;
  19.     public $doorman;
  20.  
  21.     public $verifyPassword;
  22.     public $verifyCode;
  23.    
  24.     public function addressArea($attribute, $params)
  25.     {
  26.         if( $attribute == "" )
  27.             return;
  28.  
  29.         {
  30.             $maps = new GoogleMaps();
  31.             $mapresult = $maps->geoGetCoordsFull($this->$attribute );
  32.             if ($mapresult->status != "OK" || !isset( $mapresult->results[0]->types[0] ) || $mapresult->results[0]->types[0] != 'sublocality_level_4' )
  33.             {
  34.                 $this->addError($attribute, LangControl::GetText('GENERAL_VALIDATION_ADDRESS') );
  35.             }          
  36.         }
  37.     }
  38.  
  39.     public function rules() {
  40.    
  41.         $rules = array(
  42.             array('address', 'addressArea' ),
  43.             array('method, authed, use_creditcard, address, restid', 'required'),
  44.         );
  45.  
  46.         // Add validation rules USER STATUS
  47.         if( $this->authed == 0 )
  48.         {
  49.             $rules[] = array('password, verifyPassword, email', 'required');
  50.             $rules[] = array('password', 'length', 'max'=>128, 'min' => 4,'message' => UserModule::t("Incorrect password (minimal length 4 symbols)."));
  51.             $rules[] = array('email', 'email');
  52.             $rules[] = array('email', 'unique', 'message' => UserModule::t("This user's email address already exists."));
  53.             $rules[] = array('verifyPassword', 'compare', 'compareAttribute'=>'password', 'message' => UserModule::t("Retype Password is incorrect."));
  54.         }
  55.         else if( $this->authed == 1 )
  56.         {
  57.             $rules[] = array('email', 'safe');
  58.             $rules[] = array('password', 'safe');
  59.             $rules[] = array('verifyPassword', 'safe');
  60.         }
  61.  
  62.         // Add validation rules for PAYMENT
  63.         if( $this->use_creditcard == 1 )
  64.         {
  65.             $rules[] = array('cc_holder', 'required');
  66.             $rules[] = array('cc_holder', 'length', 'min'=>5, 'max'=>40 );
  67.  
  68.             $rules[] = array('cc_serial', 'required');
  69.             $rules[] = array('cc_serial', 'length', 'is'=>16 );
  70.             $rules[] = array('cc_serial', 'numerical', 'integerOnly'=>true);
  71.  
  72.             $rules[] = array('cc_exp_month', 'required');
  73.             $rules[] = array('cc_exp_month', 'type', 'type'=>'date', 'dateFormat'=>'MM');
  74.  
  75.             $rules[] = array('cc_exp_year', 'required');
  76.             $rules[] = array('cc_exp_year', 'type', 'type'=>'date', 'dateFormat'=>'yyyy');
  77.            
  78.             $rules[] = array('cc_ccv', 'safe');
  79.         }
  80.         else if( $this->use_creditcard == 0 )
  81.         {
  82.             $rules[] = array('cc_holder', 'safe');
  83.             $rules[] = array('cc_serial', 'safe');
  84.             $rules[] = array('cc_exp_month', 'safe');
  85.             $rules[] = array('cc_exp_year', 'safe');
  86.             $rules[] = array('cc_ccv', 'safe');
  87.         }
  88.  
  89.         // Add validation rules for METHOD
  90.         if( $this->method == 0 )
  91.         {
  92.             $rules[] = array('phonenumber', 'safe');
  93.             $rules[] = array('doorman', 'safe');
  94.             $rules[] = array('instruction', 'safe');
  95.         }
  96.         else if( $this->method == 1 )
  97.         {
  98.             $rules[] = array('instruction', 'required');
  99.  
  100.             $rules[] = array('phonenumber', 'required');
  101.             $rules[] = array('phonenumber', 'numerical', 'min'=>10, 'max'=>11 );
  102.             $rules[] = array('doorman', 'safe');
  103.         }
  104.  
  105.         return $rules;
  106.     }
  107.    
  108. }
Add Comment
Please, Sign In to add comment