예제 #1
0
 public function tradepostAction()
 {
     if ($_FILES['businessfile']['size'] > 5242880) {
         Mage::getSingleton('customer/session')->addError('Please upload file size 5MB max.');
         Mage::getSingleton('core/session')->setThankyouerror('1');
         $this->_redirect('*/*/trade');
         return;
     }
     if (isset($_FILES['businessfile']['name']) && $_FILES['businessfile']['name'] != '') {
         try {
             $customer = Mage::getSingleton('customer/session')->getCustomer();
             //$company = $this->getRequest()->getPost('buscompany');
             $path = Mage::getBaseDir() . DS . 'customer_business_doc' . DS;
             //desitnation directory
             $archpath = Mage::getBaseDir() . DS . 'customer_business_doc' . DS . 'archieves' . DS;
             $fname = $_FILES['businessfile']['name'];
             //file name
             $uploader = new Varien_File_Uploader('businessfile');
             //load class
             $uploader->setAllowedExtensions(array('doc', 'pdf', 'odt', 'docx', 'png', 'jpeg', 'jpg', 'tiff'));
             //Allowed extension for file
             $uploader->checkMimeTypeCustom(array('application/msword', 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', 'application/pdf', 'application/vnd.oasis.opendocument.text', 'image/png', 'image/jpeg', 'image/tiff'));
             //$uploader->setAllowCreateFolders(true); //for creating the directory if not exists
             $uploader->setAllowRenameFiles(true);
             //if true, uploaded file's name will be changed, if file with the same name already exists directory.
             $uploader->setFilesDispersion(false);
             $output = $uploader->save($path, $fname);
             //save the file on the specified path
             //print_r($output); exit;
             $model = Mage::getModel('docupload/docupload');
             $model->setUserId($customer->getId());
             $model->setName($customer->getFirstname() . ' ' . $customer->getLastname());
             $model->setFilename($output['file']);
             $model->setNewDocs(1);
             $model->setDocumentType($this->getRequest()->getPost('docu_type'));
             //$model->setOwnershipType($this->getRequest()->getPost('owner-type'));
             //$model->setNatureOfBusiness($this->getRequest()->getPost('business-nature'));
             $model->save();
             $customer->setZiscorporate(816);
             //$customer->setCompany($company);
             $customer->save();
             Mage::getSingleton('customer/session')->addSuccess('File uploaded successfully and your verification is pending from zoffio side.');
             $collection = Mage::getModel('docupload/docupload')->getCollection()->addFieldToFilter('user_id', $customer->getId())->setOrder('id', 'DESC');
             if (count($collection->getData()) > 1) {
                 $i = 1;
                 foreach ($collection as $doc) {
                     if ($i > 1) {
                         $model = Mage::getModel('docupload/docupload')->load($doc->getId());
                         $model->setNewDocs(0);
                         $model->save();
                     }
                     $filename = $doc->getFilename();
                     if ($fname != $filename) {
                         if ($i > 1) {
                             if (copy($path . $filename, $archpath . $filename)) {
                                 $delete[] = $path . $filename;
                             }
                             foreach ($delete as $file) {
                                 unlink($file);
                             }
                         }
                         if ($i >= 5) {
                             unlink($archpath . $filename);
                         }
                     }
                     $i++;
                 }
             }
             //echo $output['file']; exit;
         } catch (Exception $e) {
             //echo 'Error Message: '.$e->getMessage();
             //Mage::throwException('Error Message: '.$e->getMessage());
             Mage::getSingleton('customer/session')->addError($e->getMessage());
             Mage::getSingleton('core/session')->setThankyouerror('1');
             $this->_redirect('*/*/trade');
             return;
         }
     } else {
         if ($_FILES['businessfile']['name'] == "") {
             Mage::getSingleton('customer/session')->addError('Please upload file.');
             Mage::getSingleton('core/session')->setThankyouerror('1');
             $this->_redirect('*/*/trade');
             return;
         }
     }
     Mage::getSingleton('core/session')->setTradesuccess('1');
     $this->_redirect('*/*/tradeSuccess');
     return;
 }
예제 #2
0
 /**
  * Save customer action
  */
 public function saveAction()
 {
     $data = $this->getRequest()->getPost();
     $this->_initCustomer('customer_id');
     $customer = Mage::registry('current_customer');
     //echo $_FILES['business_file']['name'];
     //echo "<pre>"; print_r($data); echo "</pre>"; exit;
     if (isset($_FILES['business_file']['name']) && $_FILES['business_file']['name'] != '' && $_FILES['business_file']['size'] < 5242880) {
         try {
             //$company = $data['business_company'];
             $path = Mage::getBaseDir() . DS . 'customer_business_doc' . DS;
             //desitnation directory
             $archpath = Mage::getBaseDir() . DS . 'customer_business_doc' . DS . 'archieves' . DS;
             $fname = $_FILES['business_file']['name'];
             //file name
             $uploader = new Varien_File_Uploader('business_file');
             //load class
             $uploader->setAllowedExtensions(array('doc', 'pdf', 'odt', 'docx', 'png', 'jpeg', 'jpg', 'tiff'));
             //Allowed extension for file
             $uploader->checkMimeTypeCustom(array('application/msword', 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', 'application/pdf', 'application/vnd.oasis.opendocument.text', 'image/png', 'image/jpeg', 'image/tiff'));
             $uploader->setAllowRenameFiles(true);
             //if true, uploaded file's name will be changed, if file with the same name already exists directory.
             $uploader->setFilesDispersion(false);
             $output = $uploader->save($path, $fname);
             //save the file on the specified path
             //print_r($output); exit;
             $model = Mage::getModel('docupload/docupload');
             $model->setUserId($customer->getId());
             $model->setName($customer->getFirstname() . ' ' . $customer->getLastname());
             $model->setFilename($output['file']);
             $model->setNewDocs(1);
             $model->setDocumentType($data['document_type']);
             $model->setOwnershipType($data['ownership_type']);
             $model->setNatureOfBusiness($data['nature_of_business']);
             $model->save();
             $customer->setZiscorporate(816);
             //$customer->setCompany($company);
             $customer->save();
             Mage::getSingleton('adminhtml/session')->addSuccess('File uploaded successfully and your verification is pending from zoffio side.');
             $collection = Mage::getModel('docupload/docupload')->getCollection()->addFieldToFilter('user_id', $customer->getId())->setOrder('id', 'DESC');
             if (count($collection->getData()) > 1) {
                 $i = 1;
                 foreach ($collection as $doc) {
                     if ($i > 1) {
                         $model = Mage::getModel('docupload/docupload')->load($doc->getId());
                         $model->setNewDocs(0);
                         $model->save();
                     }
                     $filename = $doc->getFilename();
                     if ($fname != $filename) {
                         if ($i > 1) {
                             if (copy($path . $filename, $archpath . $filename)) {
                                 $delete[] = $path . $filename;
                             }
                             foreach ($delete as $file) {
                                 unlink($file);
                             }
                         }
                         if ($i >= 5) {
                             unlink($archpath . $filename);
                         }
                     }
                     $i++;
                 }
             }
             //echo $output['file']; exit;
         } catch (Exception $e) {
             //echo 'Error Message: '.$e->getMessage();
             //Mage::throwException('Error Message: '.$e->getMessage());
             Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
             $this->_redirect('*/*/');
             return;
         }
     }
     if ($data) {
         $redirectBack = $this->getRequest()->getParam('back', false);
         //$this->_initCustomer('customer_id');
         /** @var $customer Mage_Customer_Model_Customer */
         //$customer = Mage::registry('current_customer');
         /** @var $customerForm Mage_Customer_Model_Form */
         $customerForm = Mage::getModel('customer/form');
         $customerForm->setEntity($customer)->setFormCode('adminhtml_customer')->ignoreInvisible(false);
         $formData = $customerForm->extractData($this->getRequest(), 'account');
         // Handle 'disable auto_group_change' attribute
         if (isset($formData['disable_auto_group_change'])) {
             $formData['disable_auto_group_change'] = empty($formData['disable_auto_group_change']) ? '0' : '1';
         }
         $errors = $customerForm->validateData($formData);
         if ($errors !== true) {
             foreach ($errors as $error) {
                 $this->_getSession()->addError($error);
             }
             $this->_getSession()->setCustomerData($data);
             $this->getResponse()->setRedirect($this->getUrl('*/customer/edit', array('id' => $customer->getId())));
             return;
         }
         $customerForm->compactData($formData);
         // Unset template data
         if (isset($data['address']['_template_'])) {
             unset($data['address']['_template_']);
         }
         $modifiedAddresses = array();
         if (!empty($data['address'])) {
             /** @var $addressForm Mage_Customer_Model_Form */
             $addressForm = Mage::getModel('customer/form');
             $addressForm->setFormCode('adminhtml_customer_address')->ignoreInvisible(false);
             foreach (array_keys($data['address']) as $index) {
                 $address = $customer->getAddressItemById($index);
                 if (!$address) {
                     $address = Mage::getModel('customer/address');
                 }
                 $requestScope = sprintf('address/%s', $index);
                 $formData = $addressForm->setEntity($address)->extractData($this->getRequest(), $requestScope);
                 // Set default billing and shipping flags to address
                 $isDefaultBilling = isset($data['account']['default_billing']) && $data['account']['default_billing'] == $index;
                 $address->setIsDefaultBilling($isDefaultBilling);
                 $isDefaultShipping = isset($data['account']['default_shipping']) && $data['account']['default_shipping'] == $index;
                 $address->setIsDefaultShipping($isDefaultShipping);
                 $errors = $addressForm->validateData($formData);
                 if ($errors !== true) {
                     foreach ($errors as $error) {
                         $this->_getSession()->addError($error);
                     }
                     $this->_getSession()->setCustomerData($data);
                     $this->getResponse()->setRedirect($this->getUrl('*/customer/edit', array('id' => $customer->getId())));
                     return;
                 }
                 $addressForm->compactData($formData);
                 // Set post_index for detect default billing and shipping addresses
                 $address->setPostIndex($index);
                 if ($address->getId()) {
                     $modifiedAddresses[] = $address->getId();
                 } else {
                     $customer->addAddress($address);
                 }
             }
         }
         // Default billing and shipping
         if (isset($data['account']['default_billing'])) {
             $customer->setData('default_billing', $data['account']['default_billing']);
         }
         if (isset($data['account']['default_shipping'])) {
             $customer->setData('default_shipping', $data['account']['default_shipping']);
         }
         if (isset($data['account']['confirmation'])) {
             $customer->setData('confirmation', $data['account']['confirmation']);
         }
         // Mark not modified customer addresses for delete
         foreach ($customer->getAddressesCollection() as $customerAddress) {
             if ($customerAddress->getId() && !in_array($customerAddress->getId(), $modifiedAddresses)) {
                 $customerAddress->setData('_deleted', true);
             }
         }
         if (Mage::getSingleton('admin/session')->isAllowed('customer/newsletter')) {
             $customer->setIsSubscribed(isset($data['subscription']));
         }
         if (isset($data['account']['sendemail_store_id'])) {
             $customer->setSendemailStoreId($data['account']['sendemail_store_id']);
         }
         $isNewCustomer = $customer->isObjectNew();
         try {
             $sendPassToEmail = false;
             // Force new customer confirmation
             if ($isNewCustomer) {
                 $customer->setPassword($data['account']['password']);
                 $customer->setForceConfirmed(true);
                 if ($customer->getPassword() == 'auto') {
                     $sendPassToEmail = true;
                     $customer->setPassword($customer->generatePassword());
                 }
             }
             Mage::dispatchEvent('adminhtml_customer_prepare_save', array('customer' => $customer, 'request' => $this->getRequest()));
             $customer->save();
             // Send welcome email
             if ($customer->getWebsiteId() && (isset($data['account']['sendemail']) || $sendPassToEmail)) {
                 $storeId = $customer->getSendemailStoreId();
                 if ($isNewCustomer) {
                     $customer->sendNewAccountEmail('registered', '', $storeId);
                 } elseif (!$customer->getConfirmation()) {
                     // Confirm not confirmed customer
                     $customer->sendNewAccountEmail('confirmed', '', $storeId);
                 }
             }
             if (!empty($data['account']['new_password'])) {
                 $newPassword = $data['account']['new_password'];
                 if ($newPassword == 'auto') {
                     $newPassword = $customer->generatePassword();
                 }
                 $customer->changePassword($newPassword);
                 $customer->sendPasswordReminderEmail();
             }
             Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('adminhtml')->__('The customer has been saved.'));
             $model = Mage::getModel('agent/agent');
             $agent_id = $this->getRequest()->getPost('agent_id');
             $dep = $this->getRequest()->getPost('dep');
             $model->updateagent($customer->getEmail(), $agent_id, $dep);
             Mage::dispatchEvent('adminhtml_customer_save_after', array('customer' => $customer, 'request' => $this->getRequest()));
             if ($redirectBack) {
                 $this->_redirect('*/*/edit', array('id' => $customer->getId(), '_current' => true));
                 return;
             }
         } catch (Mage_Core_Exception $e) {
             $this->_getSession()->addError($e->getMessage());
             $this->_getSession()->setCustomerData($data);
             $this->getResponse()->setRedirect($this->getUrl('*/customer/edit', array('id' => $customer->getId())));
         } catch (Exception $e) {
             $this->_getSession()->addException($e, Mage::helper('adminhtml')->__('An error occurred while saving the customer.'));
             $this->_getSession()->setCustomerData($data);
             $this->getResponse()->setRedirect($this->getUrl('*/customer/edit', array('id' => $customer->getId())));
             return;
         }
     }
     $this->getResponse()->setRedirect($this->getUrl('*/customer'));
 }