/** * Эта функция использует "некрасивые" URL-пераметры. Ее нужно переписать * * @param array $cats * @param array $prodIDs * @param array $propVals * @param array $carID * @return string */ function getTitleFromParams($cats = 0, $prodIDs = 0, $propVals = 0, $carID = 0) { if (!$cats) { $cats = _varByPattern('/c-\\d+/'); } if (!$prodIDs) { $prodIDs = _varByPattern('/p-\\d+/'); } if (!$propVals) { $propVals = _varByPattern('/propVal-\\d+/'); } if (!$carID) { $carID = _var('carID'); } $shownCats = array(); $shownProds = array(); $shownProps = array(); $resArray = array(); foreach ($cats as $pageID) { if (!in_array($pageID, $shownCats)) { $metaData = $this->getMetaData($pageID); $resArray['cats'][] = $metaData['Title'] ? $metaData['Title'] : $metaData['ShortTitle']; $shownCats[] = $pageID; } } foreach ($propVals as $prop) { $val = explode('_', $prop); if (!in_array($val[0], $shownCats)) { $metaData = $this->getMetaData($val[0]); $resArray['cats'][] = $metaData['Title'] ? $metaData['Title'] : $metaData['ShortTitle']; $shownCats[] = $val[0]; } } if ($carID) { $query = 'SELECT pm_as_cars.carName, pm_as_cars.carModel, pm_as_autocreators.plantName FROM pm_as_cars, pm_as_autocreators WHERE pm_as_cars.plantID = pm_as_autocreators.plantID AND pm_as_cars.carID = \'' . $carID . '\''; $result = mysql_query($query); $row = mysql_fetch_assoc($result); $resArray['other'][] = $row['plantName'] . ' ' . ($row['carName'] ? $row['carModel'] . $row['carName'] : $row['carModel']); } foreach ($prodIDs as $prodID) { if (!in_array($prodID, $shownProds)) { $query = 'SELECT * FROM pm_as_producer WHERE accPlantID=\'' . $prodID . '\''; $result = mysql_query($query); $row = mysql_fetch_assoc($result); $resArray['other'][] = $row['accPlantName']; $shownProds[] = $prodID; } } foreach ($propVals as $prop) { $val = explode('_', $prop); if (!in_array($val[1], $shownProps)) { $resArray['other'][] = $val[1]; $shownProps[] = $val[0]; } } /* if ( empty($resArray) ) { die('yes'); } else { die('no'); } */ if (!empty($resArray['other']) || !empty($resArray['cats'])) { if (count($resArray['other']) || count($resArray['cats'])) { $str = trim(implode(", ", $resArray['cats'])) . (count($resArray['other']) && count($resArray['cats']) ? ': ' : '') . implode(', ', $resArray['other']); } return $str; } else { return ''; } }
function getItemsListByPageID($pageID, &$branch) { global $structureMgr, $templatesMgr; $prodIDs = _varByPattern('/p-\\d+/'); $propVals = _varByPattern('/propVal-\\d+/'); $res = ""; $pager = ""; $topContent = $structureMgr->getData($pageID); $metaData = $structureMgr->getMetaData($pageID); $from = _get("from"); $to = _get("to"); $propID = _get("propID"); $order = _get("order"); $filterTpl = $templatesMgr->getTemplate(-1, GetCfg("TemplatesPath") . "/" . "Catalogue/filterMenu.html"); $br = $structureMgr->getChildrenDataTypesForPageID($this->getParentPageID($pageID), 1); //echo $pageID; $catFilter = ""; $propsArray = array(); $bsIDArray = array(); for ($i = 0; $i < count($branch); $i++) { $bsID = $branch[$i]["sID"]; $URL = $structureMgr->getPathByPageID($branch[$i]["sID"], false); $chCount = $structureMgr->getChildrenCount($branch[$i]["sID"]); if ($chCount > 0) { $catFilter .= "<img src=\"/images/arr_gray2.gif\" width=\"7\" height=\"9\" alt=\"\" /><a href=\"?c-{$i}={$bsID}\" >" . $branch[$i]["Title"] . " ({$chCount})</a><br/>\n"; } $bsIDArray[] = $bsID; } $subCats = $this->getSubCategoris($this->getParentPageID($pageID), $bsIDArray, $this->FILTER_CONSTANT_ARRAY[$pageID]['otherParamId']); foreach ($subCats as $key => $value) { $propsArray[$key] = $value; } $pageIDList = array(); for ($i = 0; $i < count($br); $i++) { $pageIDList[] = $br[$i]["sID"]; } $prodList = array(); if (count($pageIDList) > 0) { $prodList = $structureMgr->getProducersByPageIDList($pageIDList); } $prods = ""; foreach ($prodList as $prodItem) { $prods .= "<option value=\"" . $prodItem[0] . "\" " . (in_array($prodItem[0], $prodIDs) ? "selected" : "") . ">" . $prodItem[1] . "</option>"; } $filterTpl = str_replace("%prods%", $prods, $filterTpl); $propsValues = ""; foreach ($propsArray as $propsArrayItem) { $propsValues .= "<option value=\"" . $propsArrayItem['propListID'] . "\" " . ($propsArrayItem['propListID'] == $propID ? "selected" : "") . ">" . $propsArrayItem['propValue'] . "</option>"; } $filterTpl = str_replace("%propsValues%", $propsValues, $filterTpl); $filterTpl = str_replace("%filter_result%", $this->FILTER_CONSTANT_ARRAY[$pageID]['result'], $filterTpl); $filterTpl = str_replace("%from%", $from, $filterTpl); $filterTpl = str_replace("%to%", $to, $filterTpl); //$filterTpl = str_replace("%ShortTitle%", $ShortTitle, $filterTpl); //$filterTpl = str_replace("%actionUrl%", $_SERVER['QUERY_STRING'], $filterTpl); $props = array(); $filterArray = array(); $podborArray = array(); $hidenInputArray = array(); foreach ($propVals as $key => $value) { if ($value) { $param = explode("_", $value); $props['props'][] = "pp.propValue = '" . $param[1] . "' && s.pms_sID = '" . $param[0] . "'"; //$props['p.accCatID'][] = $param[0]; $podborArray['prop'][] = $param[1]; $filterArray[] = $key . "=" . $value; $hidenInputArray[] = '<input type="hidden" name="' . $key . '" value="' . $value . '">' . "\n"; } } foreach ($prodIDs as $key => $value) { if ($value) { $props['prods'][] = "ap.accPlantID = '" . $value . "'"; $filterArray[] = $key . "=" . $value; $query = "SELECT * FROM pm_as_producer WHERE accPlantID='" . $value . "'"; $result = mysql_query($query); $row = mysql_fetch_assoc($result); $podborArray['prod'][] = $row['accPlantName']; $hidenInputArray[] = '<input type="hidden" name="' . $key . '" value="' . $value . '">'; } } if (count($podborArray)) { $catFilter = "<p><img src=\"/images/arr_gray2.gif\" width=\"7\" height=\"9\" alt=\"\" />" . implode(', ', $podborArray['prod']) . " " . (count($podborArray['prod']) && count($podborArray['prop']) ? ":" : "") . " " . implode(', ', $podborArray['prop']) . "</p>" . "\n<p>" . $catFilter . "</p>"; } if (count($hidenInputArray)) { $catFilter .= implode("\n", $hidenInputArray); } $filterTpl = str_replace("%catFilter%", $catFilter, $filterTpl); $filter = $_SERVER['QUERY_STR']; $filter .= "&" . implode("&", $filterArray); $pNum = $structureMgr->getPageNumberByPageID($pageID); $URL = $structureMgr->getPathByPageID($pageID, false); $carIDFilter = _var("carID"); if ("" == $carIDFilter) { $carIDFilter = "0"; } $producerIDFilter = _var("producerID"); $prodIDFilter = _varByPattern('/p-\\d+/'); $perPage = GetCfg("Catalogue.perPage"); $startFrom = ($pNum - 1) * $perPage; $endAt = $startFrom + $perPage - 1; $cnt = count($branch); if ($endAt >= $cnt) { $endAt = $cnt - 1; } $pagesCount = ceil($cnt / $perPage); if ($pagesCount < $pNum) { trigger_error("Invalid pageNumber [{$pNum} of {$pagesCount}] - possibly hacking or serious change in DB", PM_ERROR); } else { if ($pagesCount > 1) { $tpl = $templatesMgr->getTemplate(-1, GetCfg("TemplatesPath") . "/" . "pager.html"); $purePager = ""; $filter = ""; if ($carIDFilter != "" && count($prodIDFilter) == 0) { $filter .= "carID={$carIDFilter}"; } if ($producerIDFilter != "") { if ($filter) { $filter .= "&"; } $filter .= "producerID={$producerIDFilter}"; } else { if (count($prodIDFilter) > 0) { foreach ($prodIDFilter as $prod => $_p) { if ($filter) { $filter .= "&"; } $filter .= "{$prod}={$_p}"; } } } $cats = _varByPattern('/c' . $carIDFilter . '-\\d+/'); if (count($cats) > 0) { foreach ($cats as $cat => $v) { if ($filter) { $filter .= "&"; } $filter .= "{$cat}={$v}"; } } for ($i = 1; $i <= $pagesCount; $i++) { if ($i > 1) { $purePager .= " - "; $u = $URL . "/page" . $i; } else { $u = $URL; } if ($filter) { $u .= "?" . $filter; } if ($i == $pNum) { $purePager .= $i; } else { $purePager .= "<a href=\"{$u}\" class=\"levm\">" . $i . "</a>"; } } $pager = str_replace("%links%", $purePager, $tpl); $filterTpl = str_replace("%links%", "Страницы: " . $purePager, $filterTpl); } else { $filterTpl = str_replace("%links%", "", $filterTpl); } for ($i = $startFrom; $i <= $endAt; $i++) { switch ($branch[$i]["DataType"]) { case "CatItem": $items = true; $ci = $this->getCatItemByPageID($branch[$i]["sID"]); $style = $i > $startFrom ? "mid" : "up"; $res .= $this->getFilledItemTemplate($ci, $style); break; } } } return " {$filterTpl}\n <div class=\"items\"><table width=\"100%\" border=\"0\" cellpadding=\"5\" cellspacing=\"0\" bgcolor=\"#DCDDE0\" class=\"items-table\">\n {$res}\n </table></div>\n <img src=\"/images/pix.gif\" width=\"1\" height=\"10\" alt=\"\" />\n {$pager}\n "; }
function getTitleFromParamsTranslit($cats = 0, $prodIDs = 0, $propVals = 0, $carID = 0) { if (!$cats) { $cats = _varByPattern('/c-\\d+/'); } if (!$prodIDs) { $prodIDs = _varByPattern('/p-\\d+/'); } if (!$propVals) { $propVals = _varByPattern('/propVal-\\d+/'); } if (!$carID) { $carID = _var('carID'); } $shownCats = array(); $shownProds = array(); $shownProps = array(); $resArray = array(); foreach ($cats as $pageID) { if (!in_array($pageID, $shownCats)) { $metaData = $this->getMetaData($pageID); $resArray['cats'][] = $metaData['Title'] ? $metaData['Title'] : $metaData['ShortTitle']; $shownCats[] = $pageID; } } foreach ($propVals as $prop) { $val = explode('_', $prop); if (!in_array($val[0], $shownCats)) { $metaData = $this->getMetaData($val[0]); $resArray['cats'][] = $metaData['Title'] ? $metaData['Title'] : $metaData['ShortTitle']; $shownCats[] = $val[0]; } } if ($carID) { $query = 'SELECT pm_as_cars.carName, pm_as_cars.carModel, pm_as_autocreators.plantName FROM pm_as_cars, pm_as_autocreators WHERE pm_as_cars.plantID = pm_as_autocreators.plantID AND pm_as_cars.carID = "' . $carID . '"'; $result = mysql_query($query); $row = mysql_fetch_assoc($result); $resArray['other'][] = $row['plantName'] . ' ' . ($row['carName'] ? $row['carModel'] . $row['carName'] : $row['carModel']); } foreach ($prodIDs as $prodID) { if (!in_array($prodID, $shownProds)) { $query = 'SELECT * FROM pm_as_producer WHERE accPlantID="' . $prodID . '"'; $result = mysql_query($query); $row = mysql_fetch_assoc($result); $resArray['other'][] = $row['accPlantName']; $shownProds[] = $prodID; } } foreach ($propVals as $prop) { $val = explode('_', $prop); if (!in_array($val[1], $shownProps)) { $resArray['other'][] = $val[1]; $shownProps[] = $val[0]; } } if (isset($resArray['cats']) && count($resArray['cats'])) { $str = trim(implode(', ', $resArray['cats'])); if (!empty($resArray['other']) && count($resArray['other'])) { foreach ($resArray['other'] as $key => $val) { $query = sprintf("SELECT propValue FROM pm_as_parts_properties WHERE propValueTranslit = '%s' LIMIT 1", $val); $result = mysql_query($query); if (0 != mysql_num_rows($result)) { $resArray['other'][$key] = mysql_result($result, 0); } } $str .= ': ' . implode(', ', $resArray['other']); } return $str; } else { return ''; } }