/** * main action */ public function mainAction() { require_once 'models/common/common_file.php'; $File = new common_file(); if ($this->GET['file_path_encoded']) { $file_path = $File->decode_file_path($this->GET['file_path_encoded']); $info = $File->getFileInfo($file_path, true); $this->tpl->assign("ITEM", $info); } return true; }
/** * send * internal function * * @return boolean * send status */ function send() { $email_data = $this->_format($this->template); $this->set('subject', $email_data['title']); require_once 'Zend/Mail.php'; $mail = new Zend_Mail('utf-8'); $mail->addHeader('X-MailGenerator', ONXSHOP_VERSION); $mail->setFrom($this->get('email_from'), $this->get('name_from')); $mail->addTo($this->get('email_recipient'), $this->get('name_recipient')); $mail->setSubject($this->get('subject')); //send BCC of all emails to specified address if ($this->conf['mail_bcc_address']) { $mail->addBcc($this->conf['mail_bcc_address'], $this->conf['mail_bcc_name']); } if ($this->conf['smtp_server_address']) { msg("use SMTP " . $this->conf['smtp_server_address'], 'ok', 2); require_once 'Zend/Mail/Transport/Smtp.php'; if ($this->conf['smtp_server_username'] && $this->conf['smtp_server_password']) { msg('using SMTP auth', 'ok', 2); $config = array('auth' => 'login', 'username' => $this->conf['smtp_server_username'], 'password' => $this->conf['smtp_server_password']); } else { $config = array(); msg("Not using SMTP auth", 'ok', 2); } $transport = new Zend_Mail_Transport_Smtp($this->conf['smtp_server_address'], $config); Zend_Mail::setDefaultTransport($transport); } else { msg('use internal mail()', 'ok', 2); } /** * attachment(s) via upload */ if (count($_FILES) > 0) { foreach ($_FILES as $key => $file) { if (is_uploaded_file($file['tmp_name'])) { /** * file */ require_once 'models/common/common_file.php'; //getSingleUpload could be static method $CommonFile = new common_file(); $upload = $CommonFile->getSingleUpload($file, 'var/tmp/'); /** * array indicated the same file name already exists in the var/tmp/ folder * we can ignore it, as the previous attachement was overwritten * FIXME: could be a problem when more users submit the same filename in the same time * perhaps saving file with PHP session id or not saving in var/tmp would help */ if (is_array($upload)) { $attachment_saved_file = ONXSHOP_PROJECT_DIR . $upload['temp_file']; } else { $attachment_saved_file = ONXSHOP_PROJECT_DIR . $upload; } /** * check if file exists and than add to email as attachemnt */ if (file_exists($attachment_saved_file)) { $attachment_info = $CommonFile->getFileInfo($attachment_saved_file); $Attachment = $mail->createAttachment(file_get_contents($attachment_saved_file)); $Attachment->filename = $attachment_info['filename']; } } } } /** * attachments * quick hack to add attachment functionality, curently used only in gift_voucher_generate */ if (is_array($GLOBALS['onxshop_atachments']) && count($GLOBALS['onxshop_atachments']) > 0) { foreach ($GLOBALS['onxshop_atachments'] as $file) { if (file_exists($file)) { require_once 'models/common/common_file.php'; $CommonFile = new common_file(); $attachment_info = $CommonFile->getFileInfo($file); $Attachment = $mail->createAttachment(file_get_contents($file)); $Attachment->filename = $attachment_info['filename']; } } } /** * content alternative text */ $mail->setBodyText($email_data['content']['txt']); $mail->setBodyHtml($email_data['content']['html']); /** * send */ if (!$mail->send()) { msg('The email was not sent! Some problem with email sending.', 'error'); return false; } else { msg("The email to {$this->email_recipient} has been sent successfully.", 'ok', 2); return true; } }
/** * saveFile */ public function saveFile($file_single, $survey_entry_id, $question_id, $answer_id) { // find survey_id by $survey_entry_id require_once 'models/education/education_survey_entry.php'; $Survey_Entry = new education_survey_entry(); $survey_entry_data = $Survey_Entry->detail($survey_entry_id); $survey_id = $survey_entry_data['survey_id']; /** * add prefix to filename (rename) */ $file_single['name'] = $this->getFilenameToSave($file_single['name'], $survey_entry_id, $question_id, $answer_id); /** * file */ require_once 'models/common/common_file.php'; //getSingleUpload could be a static method $CommonFile = new common_file(); $upload = $CommonFile->getSingleUpload($file_single, "var/surveys/{$survey_id}/"); /** * array indicated the same file name already exists in the var/tmp/ folder * this should never happen as we have entry id in filename */ if (is_array($upload)) { $attachment_saved_file = ONXSHOP_PROJECT_DIR . $upload['temp_file']; } else { $attachment_saved_file = ONXSHOP_PROJECT_DIR . $upload; } /** * check if file exists and than return filename */ if (file_exists($attachment_saved_file)) { $attachment_info = $CommonFile->getFileInfo($attachment_saved_file); return $attachment_info['filename']; } }
/** * getFileInfo */ private function getFileInfo($filename) { if (!$filename) { return false; } $file_path = ONXSHOP_PROJECT_DIR . 'var/backup/' . $filename; if (!file_exists($file_path) && !is_file($file_path)) { return false; } require_once 'models/common/common_file.php'; $file_info = common_file::getFileInfo($file_path); return $file_info; }