private function putfile() { require_once JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_onepage' . DS . 'assets' . DS . 'export_helper.php'; $ehelper = new OnepageTemplateHelper(); // no direct access // POST: tid, localid, file, hash, $tid = JRequest::getVar('tid'); $localid = JRequest::getVar('localid'); //$ehelper->setStatus($tid, $localid, 'RECEIVING'); $hash = JRequest::getVar('hash'); $hash2 = $ehelper->getFileHash($tid); $eitem = $ehelper->getExportItem($tid, $localid); $tt = $ehelper->getTemplate($tid); jimport('joomla.filesystem.file'); $tname = $tid; $tname = JFile::makesafe($tname); $ex = JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_onepage' . DS . 'export' . DS; $exf = $ex . $tname; if (empty($_FILES)) { JFactory::getApplication()->close(); } if (strtolower($hash) == $hash2 && is_numeric($tid)) { $ehelper->prepareDirectory($tid); // here we should have autoincrement value instead of order id=local id $fileName = $_FILES['file_contents']['name']; $fileTemp = $_FILES['file_contents']['tmp_name']; $num = $eitem['ai']; if (!isset($num)) { $num = $localid; } else { $num = $num; } if (is_numeric($num)) { $num = $ehelper->addZeros($num, 4); } $tn = JFile::makesafe($tt['tid_name']); $path = $exf . DS . $num . '_' . $tn . '.pdf'; $path = $ehelper->getFileName2Save($tid, $localid); if (file_exists($path)) { $xt = rand(); JFile::move($path, $path . '_history_' . $xt . '.bck'); //JFile::delete($path); } if (!JFile::upload($fileTemp, $path)) { $ehelper->setStatus($tid, $localid, 'ERROR'); echo 'Error saving file!'; //JFile::write($exf.DS.'log'.DS.'log.txt', var_export($fileTemp, true)); } else { //echo 'Saving data: '.$tid.' '.$localid.' '.$path; // here we can send it to a customer $tt = $ehelper->getTemplate($tid); if ($ehelper->getStatus($tid, $localid) == 'AUTOPROCESSING') { if (!empty($tt['tid_autocreate']) && !empty($tt['tid_email'])) { $ehelper->setStatus($tid, $localid, 'CREATED', urlencode($path)); ob_start(); $ehelper->sendMail($tid, $localid, false); $x = ob_get_clean(); //JFile::write($exf.DS.'log'.DS.'log.txt', 'sending mail'.$x); //$ehelper->syntaxError(); } } $ehelper->setStatus($tid, $localid, 'CREATED', urlencode($path)); echo 'File Saved OK!'; } //file_put_contents($exf.DS.$localid.'_'.$tname.'.pdf', $file); /* else { echo 'ERROR: Nothing to save!'; } */ JFactory::getApplication()->close(); } else { JFile::write($exf . DS . 'log' . DS . 'log.txt', 'secret not equal'); $ehelper->setStatus($tid, $localid, 'ERROR'); echo 'Secret not equal !'; JFactory::getApplication()->close(); } }
function sendMail() { echo 'Sending email... <br />'; $order_id = JRequest::getVar('localid'); $tid = JRequest::getVar('tid'); require_once JPATH_COMPONENT . DS . 'assets' . DS . 'export_helper.php'; $ehelper = new OnepageTemplateHelper($order_id); $ehelper->sendMail($tid, $order_id); /* $data = $ehelper->getOrderData($order_id); $vemail = $data['contact_email_0_0']; $cemail = $data['bt_user_email_0']; $vname = $data['vendor_name_0_0']; if (empty($vemail) || (empty($cemail))) die(); $config = JFactory::getConfig(); $sender = array( $vemail, $vname, ); $mailer = JFactory::getMailer(); $mailer->setSender($sender); $recipient = array( $cemail, $vemail ); // http://docs.joomla.org/How_to_send_email_from_components $mailer->addRecipient($recipient); $tt = $ehelper->getTemplate($tid); if (!empty($tt['tid_emailbody'])) $body = $tt['tid_emailbody']; else $body = "A new file was sent to you by shop owner."; if (!empty($tt['tid_emailsubject'])) $subject = $tt['tid_emailsubject']; else $subject = 'New file'; $mailer->setSubject($subject); $mailer->setBody($body); // Optional file attached $item = $ehelper->getExportItem($tid, $order_id); //echo 'File: '.urldecode($item['path']); if (file_exists(urldecode($item['path']))) { $mailer->addAttachment(urldecode($item['path'])); $send = $mailer->Send(); if ( $send !== true ) { echo 'Error sending email: ' . $send->message. '<br />'; } else { echo 'Mail sent to '.$cemail.' and '.$vemail. '<br />'; } } else { echo 'Exported file not found! <br />'; } */ $mainframe = JFactory::getApplication(); $mainframe->close(); }