initForm(); $this->checkPostData($this->form); } // general function to initialize Form oobject public function initForm () { $users = new Model_DbTable_Registration(); $form = $this->form = new Form_Registration(); $this->view->form = $this->form; $this->form->setDecorators(array( 'FormElements', array('HtmlTag', array('tag' => 'table')), 'Form', )); } public function checkPostData ($form) { if ($this->getRequest()->isPost()) { $formData = $this->_request->getPost(); if ($form->isValid($formData)) { // build the address to be checked later in Google Maps api $street_address = "{$formData['contact_info']['full_address']}"; $country = "{$formData['demog']['country']}"; // wipe numbers from street address to exclude irregularities during geocoding check ups $street_address = preg_replace("/[0-9]/","", $street_address); // build the address variable sent for checkup in maps.google.com // A valid address is build like this: “city, country, Street Address, Zip Post/Code” $address = "{$formData['demog']['city']} {$formData['demog']['country']} $street_address {$formData['contact_info']['post_code']}"; // check if passwords in registration form match if ($formData['password']['password'] != $formData['password2']['password2']) { $this->view->errorMsg = 'Password and Repeat Password must match.'; $this->render('index'); return; } // check if there is a selected country if($formData['demog']['country'] == "0") { $this->view->errorMsg = ' You must select Country from the Select Country dialog '; $this->render('index'); return; } // upload id and cv files $adapter = new Zend_File_Transfer_Adapter_Http(); $file_upload = Zend_Registry::get('Config')->file_uploads->destination_dir; // $adapter->setDestination('/tmp'); $adapter->setDestination("$file_upload"); if(!$adapter->receive()){ printf("Some kind of File upload error occured, exiting"); exit(1); } // unset this variables since they are not needed anymore unset($formData['password2']); unset($formData['register']); // check $address for validity in Geomaps Geocoding $is_address_valid is assigned 1 if address valid either 0 if invalid $is_address_valid = $this->validateinGoogleMaps($address); // crypt password with md5 $crypted_pass = md5($formData['password']['password']); //echo $crypted_pass; $actionName = Zend_Controller_Front::getInstance()->getRequest()->getActionName(); $newUserData = array ( 'userid' => '', 'title' => $formData['user']['title'], 'first_name' => $formData['user']['first_name'], 'last_name' => $formData['user']['last_name'], 'distributor_id' => $formData['user']['distributor_id'], 'password' => $crypted_pass, 'email' => $formData['email']['email'], 'state_country' => $formData['demog']['country'], 'city' => $formData['demog']['city'], 'post_code' => $formData['contact_info']['post_code'], 'full_address' => $formData['contact_info']['full_address'], 'phone_number' => $formData['contact_info']['phonenumber'], 'birth_date' => $formData['contact_info']['birth_date'], 'user_file_pass_id' => '123_1', 'user_file_cv' => '123_2', 'language' => 'EN', 'account_status' => 'pending', 'user_type' => $actionName, 'created' => '', ); $store_in_database = new Model_DbTable_Registration(); $store_in_database->addNewRegFormUser($newUserData); // $send_approval_notice = new Model_DbTable_SendRegistrationEmail(); //$send_approval_notice->send($newUserData); //$this->render('success'); //// $label = '', $recipients = '', $sender = array(), $data = array()) { //$recipient['email_address'] = $newUserData['email']; //echo "kopai" . $recipient['email_address']; // $send_approval_notice = new Model_DbTable_EmailTemplates(); // $send_approval_notice->send(array('label' => 'Loan Conservator new User Registration'), // array( // 'email_address' => $recipient['email_address'], // 'name' => $newUserData['first_name'] // ), // array( // 'email_address' => 'support@loanconservator.com', // 'name' => 'Loan Conservator Support' // ), // array( // 'thank_you' => 'Thank you for Registering in LoanConservator', // ) // ); // Zend_Debug::dump($is_address_valid); if($is_address_valid == '1') { $this->render('success'); } else { // $this->render('index'); $this->validateinGoogleMaps($address); $this->view->errorMsg = " Address $address specified is invalid "; } } } return $newUserData; } /* check in Google Maps api if passed address from the Registration Form is valid */ function validateinGoogleMaps($address) { $client = new Zend_Http_Client('http://maps.google.com/maps/geo'); // Google Maps API key, key available through http://code.google.com/intl/nl-BE/apis/maps/signup.html $googleApiKey = Zend_Registry::get('Config')->google_maps_api_key->google_api_key; $client->setParameterGet(array( 'q' => $address, 'output' => 'json', 'oe' => 'utf8', 'sensor' => 'false', 'key' => $googleApiKey )); $response = Zend_Json::decode($client->request()->getBody()); // different codes that the api returns and their meanings /* * 200 No errors occurred; the address was successfully parsed and its geocode was returned. * 500 A geocoding or directions request could not be successfully processed, yet the exact reason for the failure is unknown. * 601 An empty address was specified in the HTTP q parameter. * 602 No corresponding geographic location could be found for the specified address, possibly because the address is relatively new, or because it may be incorrect. * 603 The geocode for the given address or the route for the given directions query cannot be returned due to legal or contractual rea sons. * 610 The given key is either invalid or does not match the domain for which it was given. * 620 The given key has gone over the requests limit in the 24 hour period or has submitted too many requests in too short a period of time. If you're sending multiple requests in parallel or in a tight loop, use a timer or pause in your code to make sure you don't sen d the requests too quickly. */ switch ($response['Status']['code']) { case 200: /* your thing here */ echo "Address $address has a valid geocode response"; $is_address_valid = '1'; $this->view->Msg = "Thank you for supplying a valid Street Address"; break; case 500: /* your thing here */ $this->view->errorMsg = "Unknown error occured please try filling in your address again"; $this->render('index'); //... //echo "Address $address invalid"; $this->view->errorMsg = " Address $address specified is invalid, please type in a valid one "; $this->render('index'); $is_address_valid = '0'; case 602: //echo "This is either a new address or invalid one, please provide a valid one"; $this->view->errorMsg = " This is either a new address or invalid one, please provide a valid one "; $is_address_valid = '0'; //$this->render('index'); } // possible match accuracy levels /* * 0 Unknown accuracy. * 1 Country level accuracy. * 2 Region (state, province, prefecture, etc.) level accuracy. * 3 Sub-region (county, municipality, etc.) level accuracy. * 4 Town (city, village) level accuracy. * 5 Post code (zip code) level accuracy. * 6 Street level accuracy. * 7 Intersection level accuracy. * 8 Address level accuracy. * 9 Premise (building name, property name, shopping center, etc.) level accuracy. */ // validation level must be at least 5 (valid post code) if (isset($response['Placemark'])) { if ($response['Placemark'][0]['AddressDetails']['Accuracy'] < 6) { // Placemark example 821 Mohawk St, Columbus, OH 43206, USA $this->view->errorMsg = ' Invalid Address data input, please specify correct data '; $this->render('index'); $is_address_valid = '1'; /* invalid address */ } } return $is_address_valid; } // Investor registration form public function investorAction () { // $user_type = 'investor'; $this->initForm(); $this->formSessionInit(); $this->checkPostData($this->form); $this->sendRegistrationNotice($newUserData); } // Distributor registration form public function distributorAction () { // $user_type = 'distributor'; $this->initForm(); $this->formSessionInit(); $this->checkPostData($this->form); $this->sendRegistrationNotice($newUserData); } // create registration success action public function successAction () { } /* initiate session when form is accessed */ public function formSessionInit () { $sess = new Zend_Session_Namespace('RegistrationForm_NameSpace'); $sess->reg_var = 'registration'; $this->view->sess = $sess->reg_var; return $sess; } public function sendRegistrationNotice ($newUserData) { print_r($newUserData); // $send_approval_notice = new Model_DbTable_SendRegistrationEmail(); //$send_approval_notice->send($newUserData); //$this->render('success'); //// $label = '', $recipients = '', $sender = array(), $data = array()) { //$recipient['email_address'] = $newUserData['email']; //echo "kopai" . $recipient['email_address']; // $send_approval_notice = new Model_DbTable_EmailTemplates(); // $send_approval_notice->send(array('label' => 'Loan Conservator new User Registration'), // array( // 'email_address' => $recipient['email_address'], // 'name' => $newUserData['first_name'] // ), // array( // 'email_address' => 'support@loanconservator.com', // 'name' => 'Loan Conservator Support' // ), // array( // 'thank_you' => 'Thank you for Registering in LoanConservator', // ) // ); } } ?>