Beispiel #1
0
 /**
  * processAction
  * Update the record previously selected
  * @return unknown_type
  */
 public function processAction()
 {
     $redirector = Zend_Controller_Action_HelperBroker::getStaticHelper('redirector');
     $form = $this->getForm("/profile/process");
     $request = $this->getRequest();
     // Check if we have a POST request
     if (!$request->isPost()) {
         return $this->_helper->redirector('index', 'index', 'default');
     }
     if ($form->isValid($request->getPost())) {
         // Get the id
         $id = $this->getRequest()->getParam('customer_id');
         try {
             // Set the new values
             if (is_numeric($id)) {
                 $customer = Doctrine::getTable('Customers')->find($id);
                 $oldCustomer = $customer->toArray();
                 // Get the values posted
                 $params = $form->getValues();
                 $customer->company = $params['company'];
                 $customer->firstname = $params['firstname'];
                 $customer->lastname = $params['lastname'];
                 $customer->email = $params['email'];
                 $customer->birthdate = Shineisp_Commons_Utilities::formatDateIn($params['birthdate']);
                 if (!empty($params['password'])) {
                     $customer->password = MD5($params['password']);
                 }
                 $customer->birthplace = $params['birthplace'];
                 $customer->birthdistrict = $params['birthdistrict'];
                 $customer->birthcountry = $params['birthcountry'];
                 $customer->birthnationality = $params['birthnationality'];
                 $customer->vat = $params['vat'];
                 $customer->taxpayernumber = $params['taxpayernumber'];
                 $customer->type_id = !empty($params['company_type_id']) ? $params['company_type_id'] : NULL;
                 $customer->legalform_id = $params['legalform'];
                 $customer->gender = $params['gender'];
                 // Save the data
                 $customer->save();
                 $id = is_numeric($id) ? $id : $customer->getIncremented();
                 // Manage the address of the customer
                 $address = new Addresses();
                 $mainAddress = $address->findOneByUserId($id);
                 if ($mainAddress) {
                     $address = $mainAddress;
                 }
                 $address->address = $params['address'];
                 $address->city = $params['city'];
                 $address->code = $params['code'];
                 $address->country_id = $params['country_id'];
                 $address->area = $params['area'];
                 $address->customer_id = $id;
                 $address->save();
                 if (!empty($params['contact'])) {
                     $contacts = new Contacts();
                     $contacts->contact = $params['contact'];
                     $contacts->type_id = $params['contacttypes'];
                     $contacts->customer_id = $id;
                     $contacts->save();
                 }
                 // Add or Remove the customer email in the newsletter list
                 Customers::newsletter_subscription($id, $params['newsletter']);
                 $retval = Shineisp_Commons_Utilities::getEmailTemplate('profile_changed');
                 if ($retval) {
                     $subject = $retval['subject'];
                     $subject = str_replace("[user]", $params['firstname'] . " " . $params['lastname'], $retval['subject']);
                     // Alert the administrator about the changing of the customer information
                     $body = $retval['template'];
                     $body = str_replace("[user]", $params['firstname'] . " " . $params['lastname'], $body);
                     $body = str_replace("[old]", print_r($oldCustomer, true), $body);
                     $body = str_replace("[new]", print_r($customer->toArray(), true), $body);
                     $isp = Shineisp_Registry::get('ISP');
                     Shineisp_Commons_Utilities::SendEmail($isp->email, $isp->email, null, $subject, $body);
                 }
             }
         } catch (Exception $e) {
             echo $e->getMessage();
             die;
         }
         return $this->_helper->redirector('account', 'profile', 'default', array('mex' => 'The task requested has been executed successfully.', 'status' => 'success'));
     } else {
         $this->view->form = $form;
         $this->view->title = $this->translator->translate("Profile details");
         $this->view->description = $this->translator->translate("Update here your details filling the applicant form with all the information about you.");
         return $this->_helper->viewRenderer('applicantform');
     }
 }
 public static function optOut($md5email)
 {
     if (!empty($md5email)) {
         // Check if the email owner is one of the registered customers
         $customer = Customers::getCustomerbyEmailMd5($md5email);
         if (!empty($customer[0]['customer_id'])) {
             Customers::newsletter_subscription($customer[0]['customer_id'], false);
         } else {
             // Remove the email address from the email subscribers
             Doctrine_Query::create()->delete('NewslettersSubscribers')->where('MD5(email)', $md5email)->delete();
         }
         return true;
     } else {
         return false;
     }
 }