function mailorder($orderid = null) { if (!$orderid) { return; } global $mainframe; $cfg = new sc_configuration(); $tsep = $cfg->get('thousand_sep'); $dsep = $cfg->get('decimal_sep'); $decs = $cfg->get('decimals'); $currency = $cfg->get('currency'); $curralign = $cfg->get('curralign'); $dateformat = $cfg->get('dateformat'); $timeformat = $cfg->get('timeformat'); $mode = $cfg->get("emailhtml"); $usecontentasemail = $cfg->get("usecidasemail"); // create html orderheader $db =& JFactory::getDBO(); $query = "select #__sc_orders.*, #__sc_orders.total as gtotal from #__sc_orders where #__sc_orders.id='{$orderid}' "; $db->setQuery($query); $header = $db->loadObject(); echo $db->getErrorMsg(); $hhtml = ""; // header html $hhtml .= "\n<br />" . JText::_('SC_ORDER'); $hhtml .= "\n<br />" . date("{$dateformat} {$timeformat}", $header->orderdt); $hhtml .= "\n<br />{$header->name}"; $hhtml .= "\n<br />{$header->email}"; $hhtml .= "\n<br />" . nl2br($header->address); $hhtml .= "\n<br />{$header->codepostal}"; $hhtml .= "\n<br />{$header->city}"; $hhtml .= "\n<br />{$header->telephone}"; $hhtml .= "\n<br />{$orderid}"; // now get the tax rate based on the shipping region in the header $taxes = new taxes(); $taxrate = $taxes->getTax($header->shipRegion); // create html order details block $odetails = new orderdetail(); $detailslist = $odetails->getDetailsByOrderId($orderid); $dhtml = "<p>"; // detail html $dhtml .= "<table width='100%' border='1'>\n"; $dhtml .= "<tr><th>" . JText::_('SC_CODE') . "</th><th>" . JText::_('SC_DESCRIPTION') . "</th><th>" . JText::_('SC_PRICE_PER_UNIT') . "</th><th>" . JText::_('SC_QUANTITY') . "</th><th>" . JText::_('SC_TOTAL') . "</th></tr>"; foreach ($detailslist as $detail) { $dhtml .= "<tr><td>{$detail->prodcode}</td>\n"; $dhtml .= "<td>{$detail->shorttext} - {$detail->option}</td>\n"; $dhtml .= "<td>" . number_format($detail->unitprice, $decs, $dsep, $tsep) . "</td>\n"; $dhtml .= "<td>{$detail->qty}</td>\n"; $dhtml .= "<td><strong>" . number_format($detail->qty * $detail->unitprice, $decs, $dsep, $tsep) . "</strong></td>\n"; } if ($taxrate > 0) { $dhtml .= "<tr><td colspan='2'><td colspan='2'>" . JText::_('SC_TAX') . "</td><td>" . number_format($header->tax, $decs, $dsep, $tsep) . "</td>"; } $ship['enabled'] = $cfg->get('shippingenabled'); if ($ship['enabled']) { $dhtml .= "<tr><td colspan='2'><td colspan='2'>" . JText::_('SC_SHIPPING_REGION') . "</td>"; $dhtml .= "<td colspan='1'>" . $header->shipRegion . "</td></tr>"; $dhtml .= "<tr><td colspan='2'><td colspan='2'>" . JText::_('SC_SHIPPING_COST') . "</td>"; $dhtml .= "<td colspan='3'>" . $header->shipCost . "</td></tr>"; } $dhtml .= "<tr><td colspan='2'><td colspan='2'>" . JText::_('SC_TOTAL') . "</td>"; $dhtml .= "<td>" . number_format($header->gtotal + $header->tax + $header->shipCost, $decs, $dsep, $tsep) . "</td></tr>\n"; $dhtml .= "</table>\n"; $dhtml .= "</p>"; $emailsubject = JText::_('SC_ORDER') . " " . JText::_('SC_FOR') . " " . number_format($header->gtotal, $decs, $dsep, $tsep) . " " . JText::_('SC_FROM') . " " . $header->name; if ($usecontentasemail == 1) { $contentemail = $cfg->get("emailcid"); $query = "select introtext from #__content where id = '{$contentemail}'"; $db->setQuery($query); $emailcontent = $db->loadResult(); $fields = new fields(); $fieldslist = $fields->getPublishedFields(); // the custom fields defined for this system $thefields = unserialize($header->customfields); // the fields filled by customers foreach ($fieldslist as $key => $customfield) { $emailcontent = str_replace("#" . $customfield->name . "#", $thefields[$customfield->name], $emailcontent); // replace custom tags with the field names } $emailcontent = str_replace("#orderheading#", $hhtml, $emailcontent); // replace the headertag with header html $emailcontent = str_replace("#orderdetails#", $dhtml, $emailcontent); // replace detail tag with detail html $emailcontent = str_replace("#orderid#", $orderid, $emailcontent); // replace orderid tag with the order ID $emailbody = $emailcontent; } else { $emailbody = $hhtml . $dhtml; // simply add one after the other without processing anything else } $mailengine = $cfg->get("mailengine"); if ($mailengine == "alternative") { // some servers do NOT like to send to an array of addresses // so as an alternative way we send the emails one by one $from = $mainframe->getCfg('mailfrom'); $fromname = $mainframe->getCfg('fromname'); $recipient = trim($header->email); // customer email $subject = stripslashes($emailsubject); $body = $emailbody; $mode = $mode; // send to customer $rs = JUtility::sendMail($from, $fromname, $recipient, $subject, $body, $mode, $cc, $bcc, $attachment, $replyto, $replytoname); // now send the eventual copies $emailcopies = $cfg->get('email_copies'); // the complete address list is already trimmed $aemailcopies = explode("\r\n", $emailcopies); foreach ($aemailcopies as $key => $emailaddress) { $copyrecipient = trim($emailaddress); // trim each address from any \n ... $rs = JUtility::sendMail($from, $fromname, $copyrecipient, $subject, $body, $mode, $cc, $bcc, $attachment, $replyto, $replytoname); } } else { $mailer =& JFactory::getMailer(); // Build e-mail message format $mailer->setSender(array($mainframe->getCfg('mailfrom'), $mainframe->getCfg('fromname'))); $mailer->setSubject(stripslashes($emailsubject)); $mailer->setBody($emailbody); $mailer->IsHTML($mode); $emailcopies = $cfg->get('email_copies'); // the complete address list is already trimmed $aemailcopies = explode("\n", $emailcopies); // Add recipients $mailer->addRecipient(trim($header->email)); // add the copies foreach ($aemailcopies as $key => $emailaddress) { $mailer->addRecipient(trim($emailaddress)); // trim each address from any \n ... } // Send the Mail $rs = $mailer->Send(); } return $rs; }
function checkerrors() { $errors = 0; // this is a very simple check, you can add any kind of checking method to refine and enhance your security // first start by getting the published fields $fields = new fields(); $fieldlist = $fields->getPublishedFields(); // now check if they are required, and if so, check if they are filled // default function is "checkfilled" see below! foreach ($fieldlist as $field) { if ($field->required == 1) { // required field // now get the required function, this is set in the DB for each field if (function_exists($field->checkfunction)) { //check if you defined this function $errors = $errors + call_user_func($field->checkfunction, $field); } } } return $errors; }