function template_update_upload() { require_once JPATH_COMPONENT . DS . 'assets' . DS . 'export_helper.php'; jimport('joomla.filesystem.file'); $file = ""; $msg = ''; foreach ($_FILES as $k => $v) { // $msg .= 'key: '.$k.'<br />'; // $msg .= 'val: '.$v.'<br />'; if (strpos($k, 'uploadedupdatefile_') !== false && !empty($_FILES[$k]['name'])) { $file = $k; } } $arr = explode('_', $file); if (count($arr) > 1) { $tid = $arr[1]; if (!is_numeric($tid)) { return "Error!"; } // get previous file $ehelper = new OnepageTemplateHelper(); $tt = $ehelper->getTemplate($tid); $target_path = JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_onepage' . DS . 'export' . DS . 'templates' . DS; $newname = JFile::makesafe(basename($_FILES['uploadedupdatefile_' . $tid]['name'])); if (file_exists($target_path . $newname) && $tt['file'] != $newname) { $msg = 'Another theme is using the same filename'; } else { if (file_exists($target_path . $tt['file'])) { if (!JFile::delete($target_path . $tt['file'])) { $msg .= 'Could not remove old template file: ' . $tt['file'] . '<br />'; } } $msg .= $ehelper->updateFileName($tid, $newname); if (!empty($msg)) { //$userfile = JRequest::getVar('uploadedupdatefile_'.$tid, null, 'files'); //var_dump($userfile); die(); $target_path = $target_path . $newname; //echo $target_path.'<br />'; var_dump($_FILES); die(); if (JFile::upload($_FILES[$file]['tmp_name'], $target_path)) { $msg .= "The template file " . $newname . " has been uploaded"; } else { $msg .= "There was an error uploading the file, please try again! file: " . $newname; } } } } if (empty($msg)) { $msg = 'O.K.'; } //JFile::delete($_FILES[$file]['tmp_name']); $link = 'index.php?option=com_onepage&view=order_export'; $this->setRedirect($link, $msg); return $msg; //die('som tu'); }
function template_update_upload() { return false; jimport('joomla.filesystem.file'); $file = ""; $msg = ''; foreach ($_FILES as $k => $v) { // $msg .= 'key: '.$k.'<br />'; // $msg .= 'val: '.$v.'<br />'; if (strpos($k, 'uploadedupdatefile_') !== false && !empty($_FILES[$k]['name'])) { $file = $k; } } $arr = explode('_', $file); if (count($arr) > 1) { $tid = $arr[1]; if (!is_numeric($tid)) { return "Error!"; } // get previous file $ehelper = new OnepageTemplateHelper(); $tt = $ehelper->getTemplate($tid); $target_path = JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_onepage' . DS . 'export' . DS; if (file_exists($target_path . $tt['file'])) { if (!JFile::delete($target_path . $tt['file'])) { $msg .= 'Could not remove old template file: ' . $tt['file']; } } $newname = JFile::makesafe(basename($_FILES['uploadedupdatefile_' . $tid]['name'])); $msg .= $ehelper->updateFileName($tid, $newname); //$userfile = JRequest::getVar('uploadedupdatefile_'.$tid, null, 'files'); //var_dump($userfile); die(); $target_path = $target_path . $newname; if (JFile::upload($_FILES[$file]['tmp_name'], $target_path)) { $msg .= "The template file " . $newname . " has been uploaded"; } else { $msg .= "There was an error uploading the file, please try again! file: " . $newname; } } else { $msg .= "There was an error uploading the file, please try again! "; } return $msg; }
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 xmlexport() { $eu = JRequest::getVar('export_eu_csv'); if (!empty($eu)) { $this->runEucsv(); return; } $tid = JRequest::getInt('selected_tid'); if (empty($tid)) { return; } $startdate = JRequest::getVar('startdateo'); $enddate = JRequest::getVar('enddateo'); $startid = JRequest::getVar('startid'); $endid = JRequest::getVar('endid'); if (!empty($startdate)) { $startdate = strtotime($startdate) == -1 ? '' : strtotime($startdate); } if (!empty($enddate)) { $enddate = strtotime($enddate) == -1 ? '' : strtotime($enddate); } $startdate = date("Y-m-d H:i:s", $startdate); if (!empty($startdate)) { $where = ' where o.created_on >= "' . $startdate . '" '; } if (!empty($enddate)) { $enddate = $enddate + 60 * 60 * 24 - 1; $enddate = date("Y-m-d H:i:s", $enddate); if (!empty($where)) { $where .= ' and '; } else { $where = ' where '; } $where .= ' o.created_on <= "' . $enddate . '" '; } $startid = JRequest::getVar('startid', ''); $endid = JRequest::getVar('endid', ''); if (!empty($startid)) { $where = ' where o.virtuemart_order_id >= ' . $startid . ' '; } if (!empty($endid)) { if (!empty($where)) { $where .= ' and '; } else { $where = ' where '; } $where .= ' o.virtuemart_order_id <= "' . $endid . '" '; } require_once JPATH_ROOT . DS . 'administrator' . DS . 'components' . DS . 'com_onepage' . DS . 'assets' . DS . 'export_helper.php'; $ehelper = new OnepageTemplateHelper(); $tt = $ehelper->getTemplate($tid); $q = 'select `virtuemart_order_id` from #__virtuemart_orders as o ' . $where; $db = JFactory::getDBO(); $db->setQuery($q); ob_start(); $arr = $db->loadAssocList(); $e = $db->getErrorMsg(); echo $e; /* var_dump($q); var_dump($arr); die(); */ foreach ($arr as $k => $order_data) { $v = $order_data['virtuemart_order_id']; $ra = $ehelper->getOrderDataEx($tid, $v); $localid = $v; $ehelper->processTxtTemplate($tid, $v, $ra); } $msg = ob_get_clean(); $option = JRequest::getVar('option'); $mainframe = JFactory::getApplication(); $limit = $mainframe->getUserStateFromRequest("{$option}.limit", 'limit', 50, 'int'); $limitstart = $mainframe->getUserStateFromRequest("{$option}.limitstart", 'limitstart', 0, 'int'); //var_dump($limit); var_dump($limitstart); die(); $link = 'index.php?option=com_onepage&view=orders&limitstart=' . $limitstart . '&limit=' . $limit; $this->setRedirect($link); $this->setRedirect($link, $msg); }
function sendXmlMulti() { //echo 'Sending Multi Order Request... <br />'; $tid = JRequest::getVar('tid'); if (!is_numeric($tid)) { die; } $data = JRequest::get('post'); $enum = 0; require_once JPATH_COMPONENT . DS . 'assets' . DS . 'export_helper.php'; $ehelper = new OnepageTemplateHelper(); $tt = $ehelper->getTemplate($tid); $ra = array(); $localid = ''; if ($tt['tid_type'] == 'ORDERS') { foreach ($data as $k => $v) { //echo '<br />'.$k.' '.$v; if (strpos($k, 'selectedorder') !== false) { //echo 'Order: '.$v.'<br />'; $ra[] = $ehelper->getOrderDataEx($tid, $v, null, $enum); $enum++; //$ra = array_merge($ra, $arr); if (!empty($localid)) { $localid .= '_' . $v; } else { $localid .= $v; } } } $oa = array(); foreach ($ra as $va) { foreach ($va as $key => $val) { $oa[$key] = $val; } } $ehelper->setStatus($tid, $localid, 'PROCESSING'); $xml = $ehelper->getXml($tid, $localid, $oa); $hash = $ehelper->getFileHash($tid); $XPost = '&xml=' . urlencode((string) $xml); $ehelper->sendData($XPost); //file_put_contents(JPATH_ROOT.DS.'temp.xml', $xml); } else { if ($tt['tid_type'] == 'ORDER_DATA') { foreach ($data as $k => $v) { //echo '<br />'.$k.' '.$v; if (strpos($k, 'selectedorder') !== false) { //echo 'Order: '.$v.'<br />'; $ra[] = $ehelper->getOrderDataEx($tid, $v); $localid = $v; $ehelper->setStatus($tid, $localid, 'PROCESSING'); $xml = $ehelper->getXml($tid, $localid); $hash = $ehelper->getFileHash($tid); $XPost = '&xml=' . urlencode((string) $xml); $ehelper->sendData($XPost); //file_put_contents(JPATH_ROOT.DS.'temp.xml', $xml); } } } else { if ($tt['tid_type'] == 'ORDER_DATA_TXT') { foreach ($data as $k => $v) { //echo '<br />'.$k.' '.$v; if (strpos($k, 'selectedorder') !== false) { var_dump($v); echo '<br />'; //echo 'Order: '.$v.'<br />'; $ra = $ehelper->getOrderDataEx($tid, $v); $localid = $v; $ehelper->processTxtTemplate($tid, $v, $ra); //echo 'som tu'; } } } } } echo $tt['tid_type']; $mainframe = JFactory::getApplication(); $mainframe->close(); }