Ejemplo n.º 1
0
 public function editPostAction()
 {
     parent::editPostAction();
     //if($this->getRequest()->getPost('save_type') == 1){
     $cust_type = $this->getRequest()->getPost('cust_type');
     $company = $this->getRequest()->getPost('buscompany');
     $customer = Mage::getSingleton('customer/session')->getCustomer();
     if ($cust_type == 'business' && $this->getRequest()->getPost('save_type') == 1 || $cust_type == 'business' && Mage::getModel('docupload/docupload')->getLastDocumentchk() == 0) {
         //echo "mmmmmmmm"; exit;
         if ($_FILES['businessfile']['size'] > 5242880) {
             Mage::getSingleton('customer/session')->addError('Please upload file size 5MB max.');
             $this->_redirect('*/*/');
             return;
         }
         if (isset($_FILES['businessfile']['name']) && $_FILES['businessfile']['name'] != '') {
             try {
                 // 				$customer = Mage::getSingleton('customer/session')->getCustomer();
                 $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();
                 $emailSend = 0;
                 if ($customer->getZiscorporate() == 813) {
                     $emailSend = 1;
                 }
                 $customer->setZiscorporate(816);
                 $customer->setCompany($company);
                 $customer->save();
                 if ($emailSend && $customer->getId() > 0) {
                     $customer->sendSmeUpgradeEmail();
                 }
                 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());
                 $this->_redirect('*/*/');
                 return;
             }
         } else {
             if ($_FILES['businessfile']['name'] == "") {
                 //customer error messages for maker and approver
                 $makerModel = Mage::getModel('makerchecker/MakerChecker');
                 if ($customer->getZmyapprover() == "") {
                     $doc_error = "Please upload file.";
                 }
                 Mage::getSingleton('customer/session')->addError($doc_error);
                 $this->_redirect('*/*/');
                 return;
             }
         }
     } else {
         if ($cust_type == "individual") {
             $resource = Mage::getSingleton('core/resource');
             $readConnection = $resource->getConnection('core_read');
             $customer = Mage::getSingleton('customer/session')->getCustomer();
             $query = "SELECT id FROM docupload WHERE user_id ='" . $customer->getId() . "' ORDER BY id DESC LIMIT 1";
             //echo $query; exit;
             $id = $readConnection->fetchOne($query);
             $model = Mage::getModel('docupload/docupload')->load($id);
             $model->setStatus(2);
             $model->save();
             $customer->setZiscorporate(813);
             $customer->save();
         }
     }
     //Fix MakerChecker issue
     Mage::dispatchEvent('customer_save_save_after', array('customer' => $customer));
     //}
 }
Ejemplo n.º 2
0
 /**
  * Change customer password action
  */
 public function editPostAction()
 {
     if (Mage::helper('cminds_multiuseraccounts')->hasWritePermission()) {
         return parent::editPostAction();
     }
     $this->_getSession()->addError('You Don\'t have permission for this action');
     return $this->_redirect('*/*/');
 }