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(); }