private function saveImagesToFilesystem($savePath)
 {
     if (!file_exists($savePath)) {
         mkdir($savePath);
     }
     $upload = new Zend_File_Transfer();
     $upload->setDestination($savePath);
     $upload->receive();
     $this->resizeImagesAndCreateThumbnails($savePath, $upload->getFileInfo());
 }
 public function importSeasons()
 {
     $option = JRequest::getCmd('option');
     $controller = JRequest::getCmd('controller');
     // Check for request forgeries
     JRequest::checkToken() or die('Invalid Token');
     $path = JPATH_ROOT . "/tmp";
     $upload = new Zend_File_Transfer();
     $upload->setDestination($path);
     $upload->addValidator('Extension', false, array("csv"));
     $errors = array();
     $file = "products_seasons";
     $info = $upload->getFileInfo($file);
     if ($upload->isUploaded($file)) {
         if (!$upload->isValid($file)) {
             foreach ($upload->getMessages() as $k => $v) {
                 $errors[$k] = true;
             }
         }
     }
     if ($upload->receive()) {
         $mProduct = new EcwidgatewayModelProducts();
         $mProduct->processSeasonsCsv($path . "/" . $info[$file]["name"]);
         $msg = "Данные импортированы";
     } else {
         $errorMessages = array("Ошибка при загрузке файла");
         foreach ($errors as $k => $v) {
             if (isset($errors[Zend_Validate_File_Extension::FALSE_EXTENSION])) {
                 $errorMessages[] = JText::_("Недопустимое расширение файла");
             }
         }
         $msg = implode("<p>", $errorMessages);
     }
     $link = 'index.php?option=' . $option . '&controller=' . $controller;
     $this->setRedirect($link, $msg);
 }
 public function applyAction()
 {
     $this->view->pageTitle = 'Careers';
     if ($this->getRequest()->isPost()) {
         // Handle the cv file and form data
         $filters = array('name' => 'StringTrim', 'tel' => 'StringTrim', 'email' => 'StringTrim', 'enquiry' => 'StringTrim');
         $validators = array('name' => array('NotEmpty', 'messages' => 'Please enter your name'), 'tel' => array('NotEmpty', 'messages' => 'Please enter your telephone number'), 'email' => array('NotEmpty', 'messages' => 'Please enter your email address'), 'enquiry' => array('NotEmpty', 'messages' => 'Please tell us why this position interests you'));
         $input = new Zend_Filter_Input($filters, $validators, $_POST);
         if ($input->isValid()) {
             $upload = new Zend_File_Transfer();
             // Make sure the file is actually a document
             $upload->clearValidators();
             $upload->setOptions(array('ignoreNoFile' => true));
             //$upload->addValidator('MimeType', false, array('application/msword', 'application/pdf', 'application/rtf', 'text/plain'));
             if ($upload->isValid()) {
                 $params = Zend_Registry::get('params');
                 $uploadPath = $params->cms->fileUploadPath;
                 $upload->setDestination($uploadPath);
                 $upload->receive();
                 $fileInfo = $upload->getFileInfo();
                 $emailer = new Application_Core_Mail();
                 $emailer->setTo($params->email->careers, 'HomeLet');
                 $emailer->setFrom($input->email, $input->name);
                 $emailer->setSubject('HomeLet - Job Application (' . $input->position . ')');
                 $bodyHtml = 'Position : ' . $input->position . '<br />';
                 $bodyHtml .= 'Name : ' . $input->name . '<br />';
                 $bodyHtml .= 'Email : ' . $input->email . '<br />';
                 $bodyHtml .= 'Tel : ' . $input->tel . '<br />';
                 $bodyHtml .= 'Enquiry : <pre>' . $input->enquiry . '</pre><br />';
                 if ($fileInfo['cv_file']['type'] !== null) {
                     $emailer->addAttachment($fileInfo['cv_file']['destination'] . '/' . $fileInfo['cv_file']['name'], $fileInfo['cv_file']['name']);
                 }
                 $emailer->setBodyHtml($bodyHtml);
                 if ($emailer->send()) {
                     $this->_helper->redirector('thanks', 'careers');
                 } else {
                 }
             } else {
                 // Invalid file type
                 $this->view->errors = array('cv_file' => 'Invalid file type');
                 $this->view->name = $input->name;
                 $this->view->tel = $input->tel;
                 $this->view->email = $input->email;
                 $this->view->enquiry = $input->enquiry;
             }
         } else {
             // Invalid form data
             $this->view->errors = $input->getMessages();
             $this->view->name = $input->name;
             $this->view->tel = $input->tel;
             $this->view->email = $input->email;
             $this->view->enquiry = $input->enquiry;
         }
     }
     $careerUrl = $this->getRequest()->getParam('careerID');
     $careerID = substr($careerUrl, 0, strpos($careerUrl, '-'));
     $careers = new Datasource_Cms_Careers();
     $career = $careers->getById($careerID);
     $this->view->title = $career['title'];
     $this->view->id = $career['id'];
 }
 public function processpictureAction()
 {
     // disable rendering of the view and layout so that we can just echo the AJAX output
     $this->_helper->layout->disableLayout();
     $this->_helper->viewRenderer->setNoRender(TRUE);
     $session = SessionWrapper::getInstance();
     $config = Zend_Registry::get("config");
     $this->_translate = Zend_Registry::get("translate");
     $formvalues = $this->_getAllParams();
     //debugMessage($this->_getAllParams());
     $user = new UserAccount();
     $user->populate(decode($this->_getParam('id')));
     // only upload a file if the attachment field is specified
     $upload = new Zend_File_Transfer();
     // set the file size in bytes
     $upload->setOptions(array('useByteString' => false));
     // Limit the extensions to the specified file extensions
     $upload->addValidator('Extension', false, $config->uploads->photoallowedformats);
     $upload->addValidator('Size', false, $config->uploads->photomaximumfilesize);
     // base path for profile pictures
     $destination_path = BASE_PATH . DIRECTORY_SEPARATOR . "uploads" . DIRECTORY_SEPARATOR . "users" . DIRECTORY_SEPARATOR . "user_";
     // determine if user has destination avatar folder. Else user is editing there picture
     if (!is_dir($destination_path . $user->getID())) {
         // no folder exits. Create the folder
         mkdir($destination_path . $user->getID(), 0777);
     }
     // set the destination path for the image
     $profilefolder = $user->getID();
     $destination_path = $destination_path . $profilefolder . DIRECTORY_SEPARATOR . "avatar";
     if (!is_dir($destination_path)) {
         mkdir($destination_path, 0777);
     }
     // create archive folder for each user
     $archivefolder = $destination_path . DIRECTORY_SEPARATOR . "archive";
     if (!is_dir($archivefolder)) {
         mkdir($archivefolder, 0777);
     }
     $oldfilename = $user->getProfilePhoto();
     //debugMessage($destination_path);
     $upload->setDestination($destination_path);
     // the profile image info before upload
     $file = $upload->getFileInfo('profileimage');
     $uploadedext = findExtension($file['profileimage']['name']);
     $currenttime = time();
     $currenttime_file = $currenttime . '.' . $uploadedext;
     $thefilename = $destination_path . DIRECTORY_SEPARATOR . 'base_' . $currenttime_file;
     $thelargefilename = $destination_path . DIRECTORY_SEPARATOR . 'large_' . $currenttime_file;
     $updateablefile = $destination_path . DIRECTORY_SEPARATOR . 'base_' . $currenttime;
     $updateablelarge = $destination_path . DIRECTORY_SEPARATOR . 'large_' . $currenttime;
     //debugMessage($thefilename);
     // rename the base image file
     $upload->addFilter('Rename', array('target' => $thefilename, 'overwrite' => true));
     // exit();
     // process the file upload
     if ($upload->receive()) {
         // debugMessage('Completed');
         $file = $upload->getFileInfo('profileimage');
         // debugMessage($file);
         $basefile = $thefilename;
         // convert png to jpg
         if (in_array(strtolower($uploadedext), array('png', 'PNG', 'gif', 'GIF'))) {
             ak_img_convert_to_jpg($thefilename, $updateablefile . '.jpg', $uploadedext);
             unlink($thefilename);
         }
         $basefile = $updateablefile . '.jpg';
         // new profilenames
         $newlargefilename = "large_" . $currenttime_file;
         // generate and save thumbnails for sizes 250, 125 and 50 pixels
         resizeImage($basefile, $destination_path . DIRECTORY_SEPARATOR . 'large_' . $currenttime . '.jpg', 400);
         resizeImage($basefile, $destination_path . DIRECTORY_SEPARATOR . 'medium_' . $currenttime . '.jpg', 165);
         // unlink($thefilename);
         unlink($destination_path . DIRECTORY_SEPARATOR . 'base_' . $currenttime . '.jpg');
         // exit();
         // update the user with the new profile images
         try {
             $user->setProfilePhoto($currenttime . '.jpg');
             $user->save();
             // check if user already has profile picture and archive it
             $ftimestamp = current(explode('.', $user->getProfilePhoto()));
             $allfiles = glob($destination_path . DIRECTORY_SEPARATOR . '*.*');
             $currentfiles = glob($destination_path . DIRECTORY_SEPARATOR . '*' . $ftimestamp . '*.*');
             // debugMessage($currentfiles);
             $deletearray = array();
             foreach ($allfiles as $value) {
                 if (!in_array($value, $currentfiles)) {
                     $deletearray[] = $value;
                 }
             }
             // debugMessage($deletearray);
             if (count($deletearray) > 0) {
                 foreach ($deletearray as $afile) {
                     $afile_filename = basename($afile);
                     rename($afile, $archivefolder . DIRECTORY_SEPARATOR . $afile_filename);
                 }
             }
             $session->setVar(SUCCESS_MESSAGE, $this->_translate->translate("global_update_success"));
             $this->_helper->redirector->gotoUrl($this->view->baseUrl("profile/picture/id/" . encode($user->getID()) . '/crop/1'));
         } catch (Exception $e) {
             $session->setVar(ERROR_MESSAGE, $e->getMessage());
             $session->setVar(FORM_VALUES, $this->_getAllParams());
             $this->_helper->redirector->gotoUrl($this->view->baseUrl('profile/picture/id/' . encode($user->getID())));
         }
     } else {
         // debugMessage($upload->getMessages());
         $uploaderrors = $upload->getMessages();
         $customerrors = array();
         if (!isArrayKeyAnEmptyString('fileUploadErrorNoFile', $uploaderrors)) {
             $customerrors['fileUploadErrorNoFile'] = "Please browse for image on computer";
         }
         if (!isArrayKeyAnEmptyString('fileExtensionFalse', $uploaderrors)) {
             $custom_exterr = sprintf($this->_translate->translate('global_invalid_ext_error'), $config->uploads->photoallowedformats);
             $customerrors['fileExtensionFalse'] = $custom_exterr;
         }
         if (!isArrayKeyAnEmptyString('fileUploadErrorIniSize', $uploaderrors)) {
             $custom_exterr = sprintf($this->_translate->translate('global_invalid_size_error'), formatBytes($config->uploads->photomaximumfilesize, 0));
             $customerrors['fileUploadErrorIniSize'] = $custom_exterr;
         }
         if (!isArrayKeyAnEmptyString('fileSizeTooBig', $uploaderrors)) {
             $custom_exterr = sprintf($this->_translate->translate('global_invalid_size_error'), formatBytes($config->uploads->photomaximumfilesize, 0));
             $customerrors['fileSizeTooBig'] = $custom_exterr;
         }
         $session->setVar(ERROR_MESSAGE, 'The following errors occured <ul><li>' . implode('</li><li>', $customerrors) . '</li></ul>');
         $session->setVar(FORM_VALUES, $this->_getAllParams());
         $this->_helper->redirector->gotoUrl($this->view->baseUrl('profile/picture/id/' . encode($user->getID())));
     }
     // exit();
 }
Example #5
0
 private function saveImagesToFilesystem(Zend_File_Transfer $upload, $savePath)
 {
     $upload->setDestination($savePath);
     $upload->receive();
 }
 /**
  * @param $id
  * @param Zend_File_Transfer $upload
  * @param string $uploadName
  * @return mixed
  */
 protected function _uploadFiles($id, Zend_File_Transfer $upload, $uploadName = 'fileLoad')
 {
     $destinationPath = UPLOAD_DIR . '/products/' . $id;
     if (!file_exists($destinationPath)) {
         mkdir($destinationPath, 0755, true);
     }
     $upload->setDestination($destinationPath)->addValidator('Size', false, 1024000)->addValidator('Extension', false, 'jpg,png,gif,svg');
     $upload->receive($uploadName);
     $uploadFile = $upload->getFileInfo($uploadName);
     return $uploadFile;
 }
 /**
  * @param $id
  * @param Zend_File_Transfer $upload
  * @param string $inputName
  * @return mixed
  */
 protected function _uploadFiles($id, Zend_File_Transfer $upload, $inputName = 'fileLoad')
 {
     $moduleFolder = UPLOAD_DIR . '/categories';
     if (!file_exists($moduleFolder)) {
         mkdir($moduleFolder, 0755);
     }
     $destinationPath = $moduleFolder . '/' . $id;
     if (!file_exists($destinationPath)) {
         mkdir($destinationPath, 0755);
     }
     $upload->setDestination($destinationPath)->addValidator('Size', false, 1024000)->addValidator('Extension', false, 'jpg,png,gif,svg');
     $upload->receive();
     $uploadFile = $upload->getFileInfo($inputName);
     return $uploadFile;
 }
Example #8
0
    function regAction()
    {
        if ($this->_request->isPost('reg-form')) {
            Zend_Loader::loadClass('Zend_Filter_StripTags');
            Zend_Loader::loadClass('Zend_File_Transfer');
            Zend_Loader::loadClass('Zend_Date');
            Zend_Loader::loadClass('Zend_Mail');
            Zend_Loader::loadClass('Zend_Validate_EmailAddress');
            Zend_Loader::loadClass('Zend_Validate_StringLength');
            Zend_Loader::loadClass('Zend_Validate_Alnum');
            $filter = new Zend_Filter_StripTags();
            $email = trim($filter->filter($this->_request->getPost('reg-email')));
            $username = trim($filter->filter($this->_request->getPost('reg-name')));
            $password = trim($filter->filter($this->_request->getPost('reg-pswd')));
            $password_confirm = trim($filter->filter($this->_request->getPost('reg-pswd-verification')));
            $real_name = trim($filter->filter($this->_request->getPost('reg-real-name')));
            $file_name = '';
            $warnings = new Zend_Session_Namespace();
            $warnings->username = $username;
            $warnings->email = $email;
            $warnings->real_name = $real_name;
            $warnings->error = '';
            $error_msg = '';
            $mail_val = new Zend_Validate_EmailAddress();
            $name_lenght_val = new Zend_Validate_StringLength(6, 12);
            $name_an_val = new Zend_Validate_Alnum();
            $pass_lenght_val = new Zend_Validate_StringLength(6, 16);
            $real_name_lenght_val = new Zend_Validate_StringLength(0, 60);
            if ($email == '') {
                $error_msg .= '<p>Enter your email.</p>';
            } else {
                if (!$mail_val->isValid($email)) {
                    foreach ($mail_val->getMessages() as $message) {
                        $error_msg .= '<p>' . $message . '</p>';
                    }
                } else {
                    $data = new Users();
                    $query = 'email = "' . $email . '"';
                    $data_row = $data->fetchRow($query);
                    if ($data_row['email'] != '') {
                        $error_msg .= '<p>User with such an email is already registered.</p>';
                    }
                }
            }
            if ($username == '') {
                $error_msg .= '<p>Enter your username.</p>';
            } else {
                if (!$name_lenght_val->isValid($username) || !$name_an_val->isValid($username)) {
                    foreach ($name_lenght_val->getMessages() as $message) {
                        $error_msg .= '<p>' . $message . '</p>';
                    }
                    foreach ($name_an_val->getMessages() as $message) {
                        $error_msg .= '<p>' . $message . '</p>';
                    }
                } else {
                    $data = new Users();
                    $query = 'login = "******"';
                    $data_row = $data->fetchRow($query);
                    if ($data_row['login'] != '') {
                        $error_msg .= '<p>User with such an username is already registered.</p>';
                    }
                }
            }
            if ($password == '' || !$pass_lenght_val->isValid($password)) {
                $error_msg .= '<p>Enter password (must consist 6 to 16 characters).</p>';
            } else {
                if ($password_confirm == '') {
                    $error_msg .= '<p>Empty verification password.</p>';
                } else {
                    if ($password != $password_confirm) {
                        $error_msg .= '<p>The entered passwords do not match.</p>';
                    } else {
                        $salt = substr(sha1(microtime(true) . rand(1, 99999)), 0, 3);
                        $password = sha1($password . $salt);
                    }
                }
            }
            if ($real_name != '') {
                if (!$real_name_lenght_val->isValid($real_name)) {
                    foreach ($real_name_lenght_val->getMessages() as $message) {
                        $error_msg .= '<p>' . $message . '</p>';
                    }
                }
            }
            $upload = new Zend_File_Transfer();
            if ($upload->isUploaded()) {
                $upload->setDestination('public/upload/avatars/');
                $upload->addValidator('IsImage', false);
                $upload->addValidator('Size', false, 1024 * 1024);
                if (!$upload->isValid()) {
                    foreach ($upload->getMessages() as $message) {
                        $error_msg .= '<p>' . $message . '</p>';
                    }
                } else {
                    $upload_info = $upload->getFileName();
                    $file_ext = mb_substr($upload_info, strrpos($upload_info, '.') + 1);
                    $file_name = $username . '.' . $file_ext;
                    $upload->addFilter('Rename', array('target' => 'public/upload/avatars/' . $file_name, 'overwrite' => true));
                }
            }
            if ($error_msg != '') {
                $warnings->error = $error_msg;
                $warnings->status = '';
                $this->_redirect('/register/');
                return;
            } else {
                $date = new Zend_Date();
                $current_date = $date->toString('YYYY-MM-dd');
                $upload->receive();
                $data = array('login' => $username, 'email' => $email, 'password' => $password, 'salt' => $salt, 'real_name' => $real_name, 'reg_date' => $current_date, 'avatar' => $file_name, 'last_login' => '-');
                $user = new Users();
                $user->insert($data);
                $warnings->error = '<p>Registration complete.</p><p>Now check your E-Mail to activate your profile.</p>';
                $warnings->username = '';
                $warnings->email = '';
                $warnings->real_name = '';
                $warnings->status = ' reg_ok';
                $mail = new Zend_Mail();
                $hash = sha1($email . $salt);
                $url = $this->getRequest()->getServer('HTTP_HOST');
                $mail->setBodyHtml('<p>To activate your profile follow the link below:</p>
									<p>Link: <a href="http://' . $url . '/register/activate/' . $hash . '">http://' . $url . '/register/activate/' . $hash . '</a></p>
									<p>Thanks for your registration.</p>
									');
                $mail->setFrom('*****@*****.**', 'Administrator');
                $mail->addTo($email, $username);
                $mail->setSubject('Test activation link');
                $mail->send();
                $this->_redirect('/register/');
                return;
            }
        }
    }