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 "Файлы успешно загружены.";
}
Example #2
0
function showNormImage($id, $new = false)
{
    if ($new) {
        $fileName = getNormImagePath("new" . $id);
    } else {
        $fileName = getNormImagePath($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;
}
Example #4
0
function generateItemFile($itemId, $path, $idx, $itemsData)
{
    global $db;
    $row =& $db->getRow(CMD_SEL_ITEM, array($itemId), DB_FETCHMODE_ASSOC);
    if (PEAR::isError($row)) {
        print $row->getMessage() . "\n";
        return;
    }
    print "Generate item page... {$itemId} \n";
    // Новый объект
    if ($row["item_id"] == 0) {
        $fields = getViewFields();
        $imgUrl = IMAGES_BASE . getNormImagePath("new" . $row["id"]);
    } else {
        $categId =& $db->getOne("SELECT category_id FROM items WHERE id = ?", array($row["item_id"]));
        if (PEAR::isError($categId)) {
            $fields = getViewFields();
        } else {
            $fields = getViewFields($categId);
        }
        $imgUrl = IMAGES_BASE . getNormImagePath($row["item_id"]);
    }
    $fields = removeFields($fields[0], $fields[1]);
    $fields = array_unique($fields);
    ob_start();
    $tpl = new HTML_Template_IT("");
    $tpl->loadTemplatefile(ITEM_TPL_FILE, true, true);
    $params = array("itemData" => $itemsData, "perPage" => 1, "delta" => 3, "append" => false, "expanded" => true, "fileName" => "?popup=[%d]", "mode" => "Sliding", "path" => "", "prevImg" => "&lt;prev", "nextImg" => "next&gt;");
    $pager = new ExtendedPager1($params);
    $pager->ext = BASE_INDEX_URL_POPUP;
    $pager->infoStr = NAV_INFO_STR;
    $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 = $idx + 1;
    $navigation = $pager->getLinks();
    $navigation = $pager->replaceLinks($navigation);
    $navigation = str_replace("/http://", "http://", $navigation);
    $navigation = str_replace(".http://", "http://", $navigation);
    $tpl->setVariable("NAVIGATION", $navigation);
    $row["name"] = stripslashes($row["name"]);
    $tpl->setVariable("name1", $row["name"]);
    $tpl->setVariable("HTMLTITLE", $row["name"] . START_PATH_TITLE);
    foreach ($fields as $field) {
        if (!isset($row[$field])) {
            continue;
        }
        if (strlen(trim($row[$field])) == 0) {
            continue;
        }
        $row[$field] = stripslashes($row[$field]);
        $tpl->setCurrentBlock($field);
        $tpl->setVariable($field, $row[$field]);
        $tpl->parseCurrentBlock();
    }
    $tpl->setCurrentBlock("image");
    $tpl->setVariable("image", $imgUrl);
    $tpl->parseCurrentBlock();
    $tpl->show();
    $contents = ob_get_contents();
    ob_end_clean();
    $fName = str_replace(" ", "-", trim($row['art']));
    $fName = str_replace("/", "-", $fName);
    FileUtils::saveContents(OUTPUT_DIR . "/popup/" . $fName . ".html", $contents);
}