/** * Actually commit a vendor payment to the database. * * @param array An array of details about the vendor payment. * @return int The ID of the new vendor payment that was just created. */ private function CommitVendorPayment($data) { if (!isset($data['paymentdeducted'])) { $data['paymentdeducted'] = 0; } if (!isset($data['paymentcomments'])) { $data['paymentcomments'] = ''; } $paymentDetails = $this->CalculateOutstandingVendorBalance($data['paymentvendorid']); $balanceForward = number_format($paymentDetails['balanceForward'], GetConfig('DecimalPlaces')); $totalOrders = number_format($paymentDetails['totalOrders'], GetConfig('DecimalPlaces')); $profitMargin = number_format($paymentDetails['profitMargin'], GetConfig('DecimalPlaces')); $forwardBalance = $balanceForward + $totalOrders - $profitMargin; if ($data['paymentdeducted']) { $forwardBalance -= $data['paymentamount']; } $data['paymentamount'] = CNumeric($data['paymentamount']); $newPayment = array('paymentfrom' => $data['paymentfrom'], 'paymentto' => $data['paymentto'], 'paymentvendorid' => $data['paymentvendorid'], 'paymentamount' => $data['paymentamount'], 'paymentforwardbalance' => $forwardBalance, 'paymentmethod' => $data['paymentmethod'], 'paymentdate' => time(), 'paymentdeducted' => $data['paymentdeducted'], 'paymentcomments' => $data['paymentcomments']); $paymentId = $GLOBALS['ISC_CLASS_DB']->InsertQuery('vendor_payments', $newPayment); if (isset($data['notifyvendor'])) { $query = "\n\t\t\t\tSELECT vendorname, vendoremail\n\t\t\t\tFROM [|PREFIX|]vendors\n\t\t\t\tWHERE vendorid='" . (int) $data['paymentvendorid'] . "'\n\t\t\t"; $result = $GLOBALS['ISC_CLASS_DB']->Query($query); $vendor = $GLOBALS['ISC_CLASS_DB']->Fetch($result); $emailTemplate = FetchEmailTemplateParser(); $GLOBALS['VendorName'] = isc_html_escape($vendor['vendorname']); $GLOBALS['VendorPaymentEmail1'] = sprintf(GetLang('VendorPaymentEmail1'), isc_html_escape(GetConfig('StoreName')), CDate($data['paymentfrom']), CDate($data['paymentto'])); $GLOBALS['SalesFrom'] = CDate($data['paymentfrom']); $GLOBALS['SalesTo'] = CDate($data['paymentto']); $GLOBALS['OrderTotal'] = FormatPrice($paymentDetails['totalOrders']); $GLOBALS['PaymentAmount'] = FormatPrice($data['paymentamount']); $GLOBALS['PaymentMethod'] = isc_html_escape($data['paymentmethod']); if ($data['paymentcomments']) { $GLOBALS['Comments'] = '<strong>' . GetLang('Comments') . ':</strong><br />' . isc_html_escape($data['paymentcomments']); } $GLOBALS['AccountBalance'] = FormatPrice($forwardBalance); $emailTemplate->SetTemplate("vendor_payment"); $message = $emailTemplate->ParseTemplate(true); // Create a new email API object to send the email $storeName = GetConfig('StoreName'); $subject = sprintf(GetLang('VendorPaymentEmailSubject'), $storeName); require_once ISC_BASE_PATH . "/lib/email.php"; $objEmail = GetEmailClass(); $objEmail->Set('CharSet', GetConfig('CharacterSet')); $objEmail->From(GetConfig('AdminEmail'), $storeName); $objEmail->Set('Subject', $subject); $objEmail->AddBody("html", $message); $objEmail->AddRecipient($vendor['vendoremail'], '', "h"); $objEmail->Send(); } if (!$paymentId) { return false; } return $paymentId; }
private function SaveUpdatedGiftCertificateSettings() { $boolean = array('EnableGiftCertificates', 'GiftCertificateCustomAmounts'); foreach ($boolean as $var) { if (isset($_POST[$var]) && $_POST[$var] == 1) { $GLOBALS['ISC_NEW_CFG'][$var] = 1; } else { $GLOBALS['ISC_NEW_CFG'][$var] = 0; } } $positive_ints = array('GiftCertificateMinimum', 'GiftCertificateMaximum'); foreach ($positive_ints as $var) { if (isset($_POST[$var]) && (int) $_POST[$var] > 0) { $GLOBALS['ISC_NEW_CFG'][$var] = (int) $_POST[$var]; } else { $GLOBALS['ISC_NEW_CFG'][$var] = 0; } } if (isset($_POST['GiftCertificateExpiry']) && isset($_POST['EnableGiftCertificateExpiry'])) { if ($_POST['GiftCertificateExpiryRange'] == "years") { $_POST['GiftCertificateExpiry'] *= 365; } else { if ($_POST['GiftCertificateExpiryRange'] == "months") { $_POST['GiftCertificateExpiry'] *= 30; } else { if ($_POST['GiftCertificateExpiryRange'] == "weeks") { $_POST['GiftCertificateExpiry'] *= 7; } } } $GLOBALS['ISC_NEW_CFG']['GiftCertificateExpiry'] = $_POST['GiftCertificateExpiry'] * 86400; } else { $GLOBALS['ISC_NEW_CFG']['GiftCertificateExpiry'] = 0; } // Get a list of the enabled gift certificate themes // TODO: validate that all the themes are valid filenames $_POST['GiftCertificateThemes'] = array_map('trim', $_POST['GiftCertificateThemes']); $GLOBALS['ISC_NEW_CFG']['GiftCertificateThemes'] = implode(',', $_POST['GiftCertificateThemes']); $amounts = preg_split("#\\s+#", $_POST['GiftCertificateAmounts'], -1, PREG_SPLIT_NO_EMPTY); $PredefinedAmounts = array(); foreach ($amounts as $amount) { if (CNumeric($amount) > 0 && trim($amount) != "") { $PredefinedAmounts[] = trim(CNumeric($amount)); } } // GiftCertificateAmounts is var_exported in CommitSettings so no need to addslashes here $GLOBALS['ISC_NEW_CFG']['GiftCertificateAmounts'] = $PredefinedAmounts; if ($this->CommitSettings($messages)) { // Log this action $GLOBALS['ISC_CLASS_LOG']->LogAdminAction(); FlashMessage(GetLang('GiftCertificateSettingsSavedSuccessfully'), MSG_SUCCESS, 'index.php?ToDo=viewGiftCertificateSettings'); } else { FlashMessage(sprintf(GetLang('GiftCertificateSettingsNotSaved'), $messages), MSG_ERROR, 'index.php?ToDo=viewGiftCertificateSettings'); } }
private function ExportFroogle() { if (!isset($_REQUEST['start'])) { // This is our first visit to the export function. We create the file and the export session if (isset($_SESSION['FroogleFile']) && basename($_SESSION['FroogleFile']) == $_SESSION['FroogleFile'] && file_exists(APP_ROOT . "../cache/" . $_SESSION['FroogleFile'])) { @unlink(APP_ROOT . "../cache/" . $_SESSION['FroogleFile']); unset($_SESSION['FroogleFile']); } // Log this action $GLOBALS['ISC_CLASS_LOG']->LogAdminAction(); $exportFile = "froogle-export-" . time() . ".xml"; $_SESSION['FroogleFile'] = $exportFile; $fp = fopen(APP_ROOT . "/../cache/" . $exportFile, "w+"); if (!$fp) { echo "<script type='text/javascript'>self.parent.FroogleExportError('" . GetLang('FroogleExportUnableCreate') . "');</script>"; exit; } $exportDate = isc_date("Y-m-d\\TH:i:s\\Z", time()); $header = '<?xml version="1.0" encoding="' . GetConfig('CharacterSet') . '"?> <feed xmlns="http://www.w3.org/2005/Atom" xmlns:g="http://base.google.com/ns/1.0"> <title>' . $GLOBALS['StoreName'] . '</title> <link rel="self" href="' . str_replace("https://", "http://", $GLOBALS['ShopPath']) . '"/> <updated>' . $exportDate . '</updated> <author> <name>' . isc_html_escape($GLOBALS['StoreName']) . '</name> </author> <id>tag:' . time() . '</id>'; // Add the header to the file fwrite($fp, $header); $start = 0; // Count the number of products we'll be exporting $query = "\n\t\t\t\t\tSELECT COUNT(*)\n\t\t\t\t\tFROM [|PREFIX|]products p\n\t\t\t\t\tLEFT JOIN [|PREFIX|]categoryassociations ca ON (p.productid=ca.productid)\n\t\t\t\t\tWHERE prodvisible=1\n\t\t\t\t"; $result = $GLOBALS['ISC_CLASS_DB']->Query($query); $numProducts = $GLOBALS['ISC_CLASS_DB']->FetchOne($result); $_SESSION['FroogleNumProducts'] = $numProducts; } else { $exportFile = ''; if (isset($_SESSION['FroogleFile']) && basename($_SESSION['FroogleFile']) == $_SESSION['FroogleFile'] && file_exists(APP_ROOT . "/../cache/" . $_SESSION['FroogleFile'])) { $exportFile = $_SESSION['FroogleFile']; } if (!$exportFile) { echo "<script type='text/javascript'>self.parent.FroogleExportError('" . GetLang('FroogleExportInvalidFile') . "');</script>"; exit; } $fp = fopen(APP_ROOT . "/../cache/" . $exportFile, "a"); if (!$fp) { echo "<script type='text/javascript'>self.parent.FroogleExportError('" . GetLang('FroogleExportUnableCreate') . "');</script>"; exit; } $start = $_REQUEST['start']; } ob_end_clean(); $entryBuffer = array(); $expirationDate = isc_date("Y-m-d", time() + 60 * 60 * 24 * 30); $query = "\n\t\t\t\tSELECT p.*, c.catname,\n\t\t\t\t\t(SELECT b.brandname FROM [|PREFIX|]brands b WHERE b.brandid=p.prodbrandid) AS brandname,\n\t\t\t\t\t(SELECT pi.imagefile FROM [|PREFIX|]product_images pi WHERE pi.imageprodid=p.productid AND pi.imageisthumb=0 AND pi.imagesort=1) AS imagefile\n\t\t\t\t FROM [|PREFIX|]products p\n\t\t\t\tINNER JOIN [|PREFIX|]categoryassociations ca ON (p.productid=ca.productid)\n\t\t\t\tINNER JOIN [|PREFIX|]categories c ON (ca.categoryid=c.categoryid)\n\t\t\t\tWHERE p.prodvisible=1\n\t\t\t"; $done = $start; $lastPercent = 0; $query .= $GLOBALS['ISC_CLASS_DB']->AddLimit($start, ISC_EXPORT_FROOGLE_PER_PAGE); $result = $GLOBALS['ISC_CLASS_DB']->Query($query); while ($row = $GLOBALS['ISC_CLASS_DB']->Fetch($result)) { $link = ProdLink($row['prodname']); $link = str_replace("https://", "http://", $link); $desc = strip_tags($row['proddesc']); // If the product is on sale, use the sale price instead of the product price if ($row['prodsaleprice'] < $row['prodprice'] && $row['prodsaleprice'] > 0) { $price = CNumeric($row['prodsaleprice']); } else { $price = CNumeric($row['prodprice']); } $entry = array(); if ($row['brandname']) { $entry[] = sprintf("<g:brand><![CDATA[%s]]></g:brand>", isc_html_escape($row['brandname'])); } $entry[] = sprintf("<g:department><![CDATA[%s]]></g:department>", isc_html_escape($row['catname'])); if (isc_strlen($desc) > 1000) { $desc = isc_substr($desc, 0, 997) . "..."; } $entry[] = sprintf("<summary><![CDATA[%s]]></summary>", isc_html_escape($desc)); $entry[] = sprintf("<g:expiration_date><![CDATA[%s]]></g:expiration_date>", $expirationDate); $entry[] = sprintf("<g:id>%d</g:id>", $row['productid']); if ($row['imagefile']) { $image = str_replace("https://", "http://", $GLOBALS['ShopPath']) . '/' . GetConfig('ImageDirectory') . '/' . $row['imagefile']; $entry[] = sprintf("<g:image_link>%s</g:image_link>", isc_html_escape($image)); } $entry[] = sprintf("<link>%s</link>", isc_html_escape($link)); $entry[] = sprintf("<g:price>%s</g:price>", $price); if ($row['prodcode']) { $entry[] = sprintf("<g:model_number><![CDATA[%s]]></g:model_number>", isc_html_escape($row['prodcode'])); } $entry = implode("\n\n\t", $entry); $entry = sprintf("<entry>\n\t\t\t\t\t<title><![CDATA[%s]]></title>\n\t\t\t\t\t%s\n\t\t\t\t\t</entry>", isc_html_escape($row['prodname']), $entry); fwrite($fp, $entry); ++$done; $percent = ceil($done / $_SESSION['FroogleNumProducts'] * 100); // Spit out a progress bar update if ($percent != $lastPercent) { echo sprintf("<script type='text/javascript'>self.parent.UpdateFroogleExportProgress('%s');</script>", $percent); flush(); } } $end = $start + ISC_EXPORT_FROOGLE_PER_PAGE; if ($end >= $_SESSION['FroogleNumProducts']) { fwrite($fp, "</feed>"); echo "<script type='text/javascript'>self.parent.FroogleExportComplete();</script>"; } else { echo sprintf("<script type='text/javascript'>window.location='index.php?ToDo=exportFroogle&start=%d';</script>", $end); } fclose($fp); exit; }