Example #1
0
function _varByPattern($pattern)
{
    $res = _getByPattern($pattern);
    return count($res) > 0 ? $res : _postByPattern($pattern);
}
Example #2
0
 function recalcOrders()
 {
     global $authenticationMgr;
     $orderID = _post('orderID');
     $order = $this->getOrder($orderID);
     $userData = $authenticationMgr->getUserData($order['userID'], '');
     $cnt = _postByPattern('/gc\\d+/');
     $del = _postByPattern('/del\\d+/');
     foreach ($cnt as $key => $gcount) {
         $gcount = safe_numeric($gcount);
         if (preg_match('/gc(\\d+)/', $key, $match)) {
             $query = "SELECT pm_as_parts.ptID, salePrice, ptPercent FROM pm_as_parts LEFT JOIN pm_as_pricetypes ON (pm_as_parts.ptID = pm_as_pricetypes.ptID) WHERE accID = '" . $match[1] . "'";
             //echo $query.'<br>';
             $result = mysql_query($query);
             $cartRow = mysql_fetch_assoc($result);
             //print_r($cartRow);
             switch ($cartRow['ptID']) {
                 case 1:
                     if ($userData['cardID']) {
                         $curPrice = round($cartRow['salePrice'] - $cartRow['salePrice'] * 5 / 100);
                     } else {
                         $curPrice = $cartRow['salePrice'];
                     }
                     $cardPrice = round($cartRow['salePrice'] - $cartRow['salePrice'] * 5 / 100);
                     break;
                 case 2:
                     if ($userData['cardID']) {
                         $curPrice = round($cartRow['salePrice'] - $cartRow['salePrice'] * $cartRow['ptPercent'] / 100);
                     } else {
                         $curPrice = $cartRow['salePrice'];
                     }
                     break;
                 case 3:
                     if ($userData['cardID']) {
                         $curPrice = round($cartRow['salePrice'] - $cartRow['salePrice'] * $cartRow['ptPercent'] / 100);
                     } else {
                         $curPrice = $cartRow['salePrice'];
                     }
                     break;
                 case 4:
                     if ($userData['cardID']) {
                         $curPrice = round($cartRow['salePrice'] - $cartRow['salePrice'] * $cartRow['ptPercent'] / 100);
                     } else {
                         $curPrice = $cartRow['salePrice'];
                     }
                     break;
                 case 5:
                     $curPrice = round($cartRow['salePrice'] - $cartRow['salePrice'] * $cartRow['ptPercent'] / 100);
                     break;
                 case 6:
                     $curPrice = round($cartRow['salePrice'] - $cartRow['salePrice'] * $cartRow['ptPercent'] / 100);
                     break;
                 case 7:
                     $curPrice = round($cartRow['salePrice'] - $cartRow['salePrice'] * $cartRow['ptPercent'] / 100);
                     break;
                 default:
                     $curPrice = $cartRow['salePrice'];
                     break;
             }
             $curPrice *= $gcount;
             if (isset($del['del' . $match[1]]) || $gcount <= 0) {
                 mysql_query("DELETE FROM pm_order_parts WHERE orderID='{$orderID}' AND accID={$match['1']}");
             } else {
                 mysql_query("UPDATE pm_order_parts SET accCount='" . $gcount . "', price='" . $curPrice . "' WHERE orderID='" . $orderID . "' && accID={$match['1']}");
             }
             if (mysql_error()) {
                 trigger_error(mysql_error(), PM_FATAL);
             }
         }
     }
     header('location: /carorders?cmd=orders&act=order&orderID=' . $orderID);
 }
Example #3
0
function updateDictValues()
{
    $module = _post("moduleName");
    $ds = GetCfg($module . ".dictionaries");
    $res = "";
    if ($ds) {
        $dict = _post("dict");
        if (isset($ds[$dict])) {
            $d = $ds[$dict];
            $dname = $d[0];
            $dcols = $d[1];
            //$q = "DELETE FROM $dict WHERE {$dcols[id][0]}=" . _get("id");
            $ids = _postByPattern("/" . $dcols["id"][0] . "_\\d+/");
            foreach ($ids as $id) {
                $vals = "";
                $cl = "";
                foreach ($dcols as $cname => $col) {
                    if ($col[2]) {
                        if ($vals) {
                            $vals .= ", ";
                        }
                        $vals .= $col[0] . "=" . prepareVar(_post($col[0] . "_" . $id));
                    }
                }
                $q = "UPDATE {$dict} SET {$vals} WHERE " . $dcols["id"][0] . "={$id}";
                //print "$q<br>";
                $qr = mysql_query($q);
                if (!$qr) {
                    trigger_error("Error updating a value in a dictionary [{$dict}] for module [{$module}]", PM_FATAL);
                }
            }
            header("Status: 302 Moved");
            header("Location: /admin/?cmd=editDict&moduleName={$module}&dict={$dict}");
            exit(0);
        } else {
            trigger_error("Undefined dictionary [{$dict}] for module [{$module}]", PM_FATAL);
        }
    } else {
        trigger_error("Undefined module [{$module}]", PM_FATAL);
    }
}
Example #4
0
 function recalcCart()
 {
     global $structureMgr, $authenticationMgr;
     $sessionID = $authenticationMgr->getSessionID();
     $cnt = _postByPattern("/gc\\d+/");
     $del = _postByPattern("/del\\d+/");
     foreach ($cnt as $key => $gcount) {
         $gcount = safe_numeric($gcount);
         if (preg_match("/gc(\\d+)/", $key, $match)) {
             if (isset($del["del" . $match[1]]) || $gcount <= 0) {
                 mysql_query("DELETE FROM pm_as_cart WHERE sessionID='{$sessionID}' AND accID={$match['1']}");
             } else {
                 mysql_query("UPDATE pm_as_cart SET accCount={$gcount} WHERE sessionID='{$sessionID}' AND accID={$match['1']}");
             }
             //echo "DELETE FROM pm_as_cart WHERE sessionID='$sessionID' AND accID=$match[1]";
             if (mysql_error()) {
                 trigger_error(mysql_error(), PM_FATAL);
             }
         }
     }
     header("Status: 302 Moved");
     header("Location: " . getenv("HTTP_REFERER"));
     exit(0);
 }