function HandleLoadImage() { require_once "../includes/HTTP/Upload.php"; $upload = new HTTP_Upload(); $files = $upload->getFiles(); $tempDir = "../data/tmp/"; if ($_REQUEST["imgType"] == "normal") { // Получение большого файла $file = current($files); if (PEAR::isError($file) || !$file->isValid()) { print "Ошибка при загрузке файла: " . $file->getMessage(); return; } $moved = $file->moveTo($tempDir); if (PEAR::isError($moved)) { print "Ошибка при загрузке файла: " . $moved->getMessage(); return; } if ($_REQUEST["newItem"]) { $fName = "../" . getNormImagePath("new" . $_REQUEST["id"]); } else { $fName = "../" . getNormImagePath($_REQUEST["id"]); } if (file_exists($fName)) { unlink($fName); } if (!rename($tempDir . $moved, $fName)) { print "Ошибка - файл {$moved} не скопирован."; return; } chmod($fName, 0755); setUploaded($_REQUEST["id"], $_REQUEST["newItem"]); } else { if ($_REQUEST["imgType"] == "small") { // Получение маленького файла $file = next($files); if (PEAR::isError($file) || !$file->isValid()) { print "Ошибка при загрузке файла: " . $file->getMessage(); return; } $moved = $file->moveTo($tempDir); if (PEAR::isError($moved)) { print "Ошибка при загрузке файла: " . $moved->getMessage(); return; } if ($_REQUEST["newItem"]) { $fName = "../" . getSmallImagePath("new" . $_REQUEST["id"]); } else { $fName = "../" . getSmallImagePath($_REQUEST["id"]); } if (file_exists($fName)) { unlink($fName); } if (!rename($tempDir . $moved, $fName)) { print "Ошибка - файл {$moved} не скопирован."; return; } chmod($fName, 0755); } } print "Файлы успешно загружены."; }
function showSmallImage($id, $new = false) { if ($new) { $fileName = getSmallImagePath("new" . $id); } else { $fileName = getSmallImagePath($id); } if (file_exists("../" . $fileName)) { print "../" . $fileName; } else { print "../" . NOIMAGE_FILE; } }
function HandleSiteStat() { // NOTE Поля для свойств товара переопределяются для других типов товаров define("CMD_SEL_TMP_ITEMS", <<<SQL \t\tCREATE TEMPORARY TABLE tmp_items \t\t\tSELECT category_id, site_categories.id, items.id as item_id, \t\t\t\t\titems.art, \t\t\t\t\titems.url, \t\t\t\t\titems.name, \t\t\t\t\titems.price, \t\t\t\t\titems.descr, \t\t\t\t\titems.image_large, \t\t\t\t\titems.image_small, \t\t\t\t\titems.sizein, \t\t\t\t\titems.sizeout, \t\t\t\t\titems.type, \t\t\t\t\titems.power, \t\t\t\t\titems.weight, \t\t\t\t\titems.velocity, \t\t\t\t\titems.noiselevel, \t\t\t\t\titems.drainage, \t\t\t\t\titems.area, \t\t\t\t\titems.refrigerating, \t\t\t\t\titems.innervatecontr, \t\t\t\t\titems.voltage, \t\t\t\t\titems.controlconsole, \t\t\t\t\titems.cooling, \t\t\t\t\titems.heating, \t\t\t\t\titems.brandname, \t\t\t\t\titems.powerconsum, \t\t\t\t\titems.descr_other, \t\t\t\t\titems.powercooling \t\t\t\tFROM items, site_categories \t\t\t\t\tWHERE (category_id = site_categories.id) \t\t\t\t\t\tAND (site_categories.site_id = ?) SQL ); define("CMD_SEL_TMP_ITEMS_COUNT", <<<SQL \t\tSELECT count(*) FROM tmp_items SQL ); define("CMD_SEL_TMP_ITEMS_FIELDCOUNT", <<<SQL \t\tSELECT count(*) FROM tmp_items WHERE %s != "" SQL ); define("CMD_SEL_TMP_ITEMS_IDS", <<<SQL \t\tSELECT item_id FROM tmp_items SQL ); global $db; $row =& $db->getRow(CMD_SEL_SITE, array($_REQUEST["siteId"]), DB_FETCHMODE_OBJECT); if (PEAR::isError($row)) { printError($row); exit; } if (strlen(trim($row->keyname)) == 0) { print "Parser not defined.\n"; return; } $parserName = $row->keyname . "ContentGrabber"; include_once "../parsers/{$parserName}.php"; if (!class_exists($parserName)) { print "Parser not found.\n"; return; } $parser =& new $parserName(); print <<<HTML <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=windows-1251" /> <title>Статистика сайта</title> <link rel="stylesheet" type="text/css" href="styles/PanelInfo.css"> <script src="scripts/glm-ajax.js"></script> </head> <body> <div id="Stat"> HTML; $allFields = $parser->getAllFields(); $fields = $parser->getSupportedFields(); // Вывод информации полей print "<b>Поддерживаемые поля:</b><p>"; $suppFields = array_intersect(array_keys($allFields), $fields); foreach ($suppFields as $field) { print $allFields[$field] . ": <b>+</b><br>"; } print "<p><b>Неподдерживаемые поля:</b><p>"; $unsuppFields = array_diff(array_keys($allFields), $fields); foreach ($unsuppFields as $field) { print $allFields[$field] . ": <b>-</b><br>"; } print "<p><hr><p>"; $res =& $db->query(CMD_SEL_TMP_ITEMS, array($row->id)); if (PEAR::isError($res)) { printError($res); exit; } $allCount =& $db->getOne(CMD_SEL_TMP_ITEMS_COUNT); if (PEAR::isError($allCount)) { printError($allCount); exit; } print "<b>Количество скаченных записей:</b> " . $allCount . "<p>"; if ($allCount == 0) { return; } $res =& $db->query(CMD_SEL_TMP_ITEMS_IDS); if (PEAR::isError($res)) { printError($res); exit; } $imgCount = 0; $imgSmallCount = 0; while ($row =& $res->fetchRow(DB_FETCHMODE_OBJECT)) { if (file_exists(realpath("../" . getNormImagePath($row->item_id)))) { $imgCount++; } if (file_exists(realpath("../" . getSmallImagePath($row->item_id)))) { $imgSmallCount++; } } print "<b>Статистика по скаченным полям (не пустые значения):</b><p>"; // Вывод процентов скачанных данных для каждого поля foreach ($fields as $field) { if ($field === "image_large") { $fieldCount = $imgCount; } else { if ($field === "image_small") { $fieldCount = $imgSmallCount; } else { $fieldCount =& $db->getOne(sprintf(CMD_SEL_TMP_ITEMS_FIELDCOUNT, $field)); if (PEAR::isError($fieldCount)) { printError($fieldCount); continue; } } } $perc = round($fieldCount / $allCount * 100, 2); print $allFields[$field] . ": " . $fieldCount . " - <b>" . $perc . "%</b><br>"; } print <<<HTML \t</div> </body> </html> HTML; }
function generateCatalogFiles($parentId, $path, $subCategsRows) { global $db; global $pathBuilder; $newRows =& $db->getAll(CMD_SEL_NEW_ITEMS, array($parentId), DB_FETCHMODE_OBJECT); if (PEAR::isError($newRows)) { print $newRows->getMessage() . "\n"; return; } $rows =& $db->getAll(CMD_SEL_ITEMS, array($parentId), DB_FETCHMODE_OBJECT); if (PEAR::isError($rows)) { print $rows->getMessage() . "\n"; return; } $rows = array_merge(array_values($rows), array_values($newRows)); usort($rows, "sortByStatus1"); $tmpFullPath = OUTPUT_DIR . "/" . $path; print "Generate catalog page {$tmpFullPath}...\n"; FileUtils::mkDirRecursive($tmpFullPath); FileUtils::saveContents($tmpFullPath . "/title.html", $pathBuilder->reversePath() . START_PATH_TITLE); $itemsData = array(); foreach ($rows as $row) { if ($row->id != "") { $itemsData[] = $row; } } $params = array("itemData" => $itemsData, "perPage" => 12, "delta" => 3, "append" => false, "expanded" => true, "fileName" => BASE_URL . $pathBuilder->pathFile . "page%d.html", "mode" => "Sliding", "path" => "", "prevImg" => "<prev", "nextImg" => "next>"); $pager = new ExtendedPager($params); $pager->prev = NAV_PREV; $pager->prevDis = NAV_PREV_DIS; $pager->next = NAV_NEXT; $pager->nextDis = NAV_NEXT_DIS; $pager->prevPages = NAV_PREV_PAGES; $pager->prevPagesDis = NAV_PREV_PAGES_DIS; $pager->nextPages = NAV_NEXT_PAGES; $pager->nextPagesDis = NAV_NEXT_PAGES_DIS; $pager->currentPage = 1; $num = 1; do { $navigation = $pager->getLinks(); //$navigation = str_replace("index1.html", "index.html", $navigation); $navigation = str_replace("page1.html", "", $navigation); $navigation = str_replace("/http://", "http://", $navigation); $navigation = str_replace(".http://", "http://", $navigation); ob_start(); $tpl = new HTML_Template_IT(""); $tpl->loadTemplatefile(CATEG_TPL_FILE, true, true); $tpl->setVariable("NAVIGATION", $navigation); $tpl->setVariable("PATH", START_PATH . $pathBuilder->htmlCode); $tpl->setVariable("TITLE", $pathBuilder->items[sizeof($pathBuilder->items) - 1]); $tpl->setVariable("SCRIPT1", <<<SCRIPT <script> var setActiveCategory = function () { \tTree_setActiveNode({$parentId}); } </script> SCRIPT ); if (showColorSheme($parentId)) { $tpl->setVariable("COLORSHEME", COLORSHEME_HTML); } else { $tpl->setVariable("COLORSHEME", ""); } // Создание списка подкатегорий if (sizeof($subCategsRows) > 0) { if (dirname($pathBuilder->pathFile) != ".") { foreach ($subCategsRows as $i => $row) { if ($i == 0) { $tpl->setCurrentBlock("asubcategory"); } else { $tpl->setCurrentBlock("subcategory"); } $url = BASE_URL . dirname($pathBuilder->pathFile) . "/" . $row->dirname . "/"; $tpl->setVariable("NAME", stripslashes($row->name)); $tpl->setVariable("URL", $url); $tpl->parseCurrentBlock(); } $tpl->parse("subcategories"); $tpl->setCurrentBlock("subcategoriestitle"); $tpl->setVariable("TMP", " "); $tpl->parseCurrentBlock(); } } // Создание таблицы товаров $col = 0; $rowNum = 0; $rows = $pager->range; $rowCount = ceil(sizeof($rows) / 3); addEmptyItems($rows, 3); foreach ($rows as $row) { $url = BASE_INDEX_URL_POPUP . str_replace(" ", "-", trim($row->art)); $num++; if ($row != null) { $tpl->setCurrentBlock("column"); $tpl->setVariable("ART", $row->art); $tpl->setVariable("NAME", stripslashes($row->name)); $tpl->setVariable("URL", $url . "/"); $imgUrl = ""; if (isset($row->item_id)) { // Если новый объект if ($row->item_id == 0) { $imgUrl = IMAGES_BASE . getSmallImagePath("new" . $row->id); } else { $imgUrl = IMAGES_BASE . getSmallImagePath($row->item_id); } $tpl->setVariable("IMAGE", $imgUrl); } else { $tpl->setVariable("IMAGE", IMAGES_BASE . getSmallImagePath("new" . $row->id)); } } else { $tpl->setCurrentBlock("emptycolumn"); $tpl->setVariable("EMPTY", " "); } $tdclass = $col == 2 ? "cat_last_td_item" : "cat_leftborder"; $tpl->setVariable("TDCLASS", $tdclass); $tpl->parseCurrentBlock(); $col++; if ($col >= 3) { $trclass = $rowNum == $rowCount - 1 ? "cat_last_tr_item , cat_leftborder" : "cat_top_tr_item , cat_leftborder"; $tpl->setVariable("TRCLASS", $trclass); $rowNum++; $col = 0; $tpl->parse("row"); } } $tpl->show(); $contents = ob_get_contents(); ob_end_clean(); $state = $pager->currentPage == 1 ? "index.html" : "page" . $pager->currentPage . ".html"; FileUtils::saveContents($tmpFullPath . "/{$state}", $contents); $pager->currentPage++; } while (!$pager->isLast()); print "Generate items pages...\n"; foreach ($itemsData as $idx => $row) { generateItemFile($row->id, $path, $idx, $itemsData); } }