Example #1
0
function scan_Dir($dir)
{
    $arrfiles = array();
    if (is_dir($dir)) {
        if ($handle = opendir($dir)) {
            chdir($dir);
            while (false !== ($r_file = readdir($handle))) {
                if ($r_file != "." && $r_file != "..") {
                    if (is_dir($r_file)) {
                        $arr = scan_Dir($r_file);
                        foreach ($arr as $value) {
                            $arrfiles[] = $dir . "/" . $value;
                        }
                    } else {
                        $arrfiles[] = $dir . "/" . $r_file;
                    }
                }
            }
            chdir("../");
        }
        closedir($handle);
    }
    return $arrfiles;
}
function include_resort_tools_text()
{
    global $local_stats, $userid;
    //     mysql_grab($userid, 'local', 'stats');
    // Two ways of pulling user stats; 1 is the above (bad) and 1 is with object
    // like below (good). Old resort tools require the above, but we want to
    // change that.
    $objUser =& $GLOBALS['objSrcUser'];
    $arrSrcStats = $objUser->get_stats();
    $local_stats = $arrSrcStats;
    if (!$arrSrcStats['level'] > 0) {
        echo '<div class="center">' . "Sorry, this page is restricted to ORKFiA Staff" . '</div>';
        include_game_down();
        exit;
    }
    $count = 0;
    if (isset($_POST['update_staff_tools'])) {
        // Save new tools and access limits to DB
        foreach ($_POST['new_tools'] as $details) {
            $toolname = substr(stripslashes($details['toolname']), 0, 30);
            $new_name = addslashes(trim(stripslashes($details['new_name'])));
            $req_level = stripslashes($details['req_level']);
            $req_resort = stripslashes($details['req_resort']);
            $sql = "INSERT INTO `staff_tools` SET\n                    toolname    = '{$toolname}',\n                    name_output = '{$new_name}',\n                    req_level   = {$req_level},\n                    req_resort  = {$req_resort}";
            if ($new_name != "Tool Output Name") {
                if (!($result = mysql_query($sql))) {
                    echo '<div class="center">' . "{$count} Resort tool(s) added" . '</div>';
                    die('<div class="center">' . "Could not save record!<br /><b>TOOL: {$toolname}</b>" . '</div>');
                }
                $count++;
            }
        }
        echo '<div class="center">' . "{$count} Resort tool(s) added<br /><br />";
        echo "<a href=\"main.php?cat=game&amp;page=resort_tools\">";
        echo "Back to Control Panel</a>" . '</div>';
    } elseif (isset($_POST['remove_staff_tool'])) {
        $toolname = $_POST['remove_staff_tool'];
        $sql = 'DELETE FROM staff_tools WHERE toolname = \'' . $toolname . '\'';
        if (!($result = mysql_query($sql))) {
            die("Could not remove tool!<br /><b>TOOL: {$toolname}</b>");
        }
        echo "{$toolname} removed from the list.<br /><br />";
        echo "<a href=\"main.php?cat=game&amp;page=resort_tools\">";
        echo "Back to Control Panel</a>";
    } elseif (isset($_GET['tool'])) {
        // Log activity
        include_once 'inc/functions/resort_tools.php';
        $tool = $_GET['tool'];
        log_staff_activity($tool);
        // Show tool
        echo '<div id="textBig">';
        echo "<a href=\"main.php?cat=game&amp;page=resort_tools\">";
        echo "<p>Back to Resort Tools</a></p>";
        include_once "inc/staff/{$tool}.inc.php";
        $function = "call_" . $tool . "_text";
        $function();
        echo "<p><a href=\"main.php?cat=game&amp;page=resort_tools\">";
        echo "Back to Resort Tools</a></p>";
        echo '</div>';
    } else {
        $staffmember = stripslashes($arrSrcStats['name']);
        echo '<div class="center">' . "<b>Welcome {$staffmember} =)</b></div><br />";
        // List all new pages found in /staff/
        if ($arrSrcStats['level'] == 6) {
            // Get all tool file names
            $arrfiles = scan_Dir('inc/staff');
            // Query DB for existing tools
            $query = "SELECT * FROM staff_tools";
            $result = mysql_query($query) or die("Error querying staff_tools!");
            while ($row = mysql_fetch_row($result)) {
                $arrtools[] = $row[0];
            }
            // Add both arrays together and sort out the doubles
            $arrtotal = array_diff($arrfiles, $arrtools);
            $count = count($arrtotal);
            // Display remaining tools as 'new tools found'
            if ($count > 0) {
                ?>
            <form action="main.php?cat=game&amp;page=resort_tools" method="post">
            <input type="hidden" name="update_staff_tools" value="yes">

            <table class="medium" cellpadding="0" cellspacing="0">
            <tr class="header">
                <th colspan="4"><?php 
                echo $count;
                ?>
 New Tools Found!</th>
            </tr>
            <tr class="subheader">
                <th>Tool</th>
                <td>Name</td>
                <td>Resort</td>
                <td>Level</td>
            </tr>

            <?php 
                foreach ($arrtotal as $id => $toolname) {
                    $link = "<a href=\"main.php?cat=game&amp;page=resort_tools";
                    $link .= "&amp;tool={$toolname}\">{$toolname}</a>";
                    ?>

            <tr class="data">
            <th>
                <?php 
                    echo $link;
                    ?>
            </th>

            <td>
                <input type="hidden" name="new_tools[<?php 
                    echo $id;
                    ?>
][toolname]"
                                                     value="<?php 
                    echo $toolname;
                    ?>
">
                <input size="30" name="new_tools[<?php 
                    echo $id;
                    ?>
][new_name]"
                                                   value="Tool Output Name">
            </td>

            <td>
                <Select size=1 name="new_tools[<?php 
                    echo $id;
                    ?>
][req_resort]">
                    <option value=0>All</option>
                    <option value=1>(#1)</option>
                    <option value=2>(#2)</option>
                    <option value=3>(#3)</option>
                    <option value=4>(#4)</option>
                    <option value=5>(#5)</option>
                    <option value=6>(#6)</option>
                    <option value=7>(#7)</option>
                    <option value=8>(#8)</option>
                    <option value=9>(#9)</option>
                    <option value=10>(#10)</option>
                </select>
            </td>

            <td>
                <Select size=1 name="new_tools[<?php 
                    echo $id;
                    ?>
][req_level]">
                    <option value=2>2</option>
                    <option value=3>3</option>
                    <option value=4>4</option>
                    <option value=5>5</option>
                    <option value=6>6</option>
                </select>
            </td>
            </tr>

                <?php 
                }
                ?>
            <tr>
                <td class="center" colspan="4">
                <input type="submit" value="Add Tool(s)">
                </td>
            </tr>
            </table>
            </form>
            <br />
            <?php 
            }
        }
        // List available tools
        echo build_table($arrSrcStats);
    }
}
Example #3
0
function add_elements_from_file($filename, $iblock_id, $section_id, $series_name, $series_title_prefix, $price_multiplier)
{
    $image_files = scan_Dir("images/tb-images");
    chdir("..");
    test_dump($image_files);
    //Получить мощность и IP
    $power_file = file("power_and_ip.csv");
    $power_and_ip = array_map(function ($row1) {
        return explode(';', $row1);
    }, $power_file);
    test_dump($power_file);
    $file = file($filename);
    $e1 = array_map(function ($row2) {
        return explode(';', $row2);
    }, $file);
    $el_count = count($e1);
    test_dump($el_count);
    for ($i = 1; $i < $el_count; $i++) {
        test_dump($i);
        $row = $e1[$i];
        for ($j = 5; $j <= 15; $j++) {
            if ($row[$j] != "") {
                $row[$j] = "Y";
            }
        }
        //вместо цен ставим "Есть" или "Нет" как бы
        $row[0] = "НЕ НУЖНО";
        $row[3] = "НЕ НУЖНО";
        $row[16] = "НЕ НУЖНО";
        $row[17] = "НЕ НУЖНО";
        unset($row[19]);
        unset($row[20]);
        unset($row[21]);
        unset($row[22]);
        $BRAND_REF = "itprom";
        $TB_SERIES = "";
        if ($series_name == "TL") {
            $TB_SERIES = 123;
        } elseif ($series_name == "T") {
            $TB_SERIES = 124;
        } elseif ($series_name == "VT") {
            $TB_SERIES = 125;
        } elseif ($series_name == "IBL") {
            $TB_SERIES = 158;
        } elseif ($series_name == "IB") {
            $TB_SERIES = 159;
        } elseif ($series_name == "IBV") {
            $TB_SERIES = 160;
        }
        $r = explode("+", $row[2]);
        $option = "NONE";
        if (count($r) == 2) {
            $option = $r[1];
            $TB_PANELS = "128";
            if (substr_count($option, "оков") > 0) {
                $TB_OPTION = "150";
            } elseif (substr_count($option, "лухая") > 0) {
                $TB_OPTION = "151";
            } elseif (substr_count($option, "анель") > 0) {
                $TB_OPTION = "152";
            }
        }
        $size = explode("x", $r[0]);
        if (count($size) == 3) {
            echo "<p>({$size['0']}, {$size['1']}, {$size['2']}) + {$option} <br /></p>";
            $TB_WIDTH = $size[0];
            $TB_HEIGHT = $size[1];
            $TB_DEPTH = $size[2];
        } else {
            echo "WRONG SIZE!";
        }
        if ($series_name == "VT" || $series_name == "IBV") {
            $PRICE_EUR = str_replace(" ", "", str_replace("€", "", $row[18 + 1]));
        } else {
            $PRICE_EUR = str_replace(" ", "", str_replace("€", "", $row[18]));
        }
        echo "Цена ({$PRICE_EUR}) евро<br />\n";
        $w = intval($TB_WIDTH);
        $h = intval($TB_HEIGHT);
        $d = intval($TB_DEPTH);
        $power_ip_count = count($power_and_ip);
        $count = 0;
        $p_row_id = -1;
        for ($k = 0; $k < $power_ip_count; $k++) {
            $p_row = $power_and_ip[$k];
            if ($p_row[1] == $w && $p_row[2] == $h && $p_row[3] == $d) {
                $count++;
                $p_row_id = $k;
            }
        }
        $TP_HEAT_POWER = "";
        $TP_IP_CLASS = "";
        //$series_from_list = explode("-", $power_and_ip[$p_row_id][0])[0];
        //test_dump($series_from_list);
        //echo "Series: " . $series_name . " = " . $series_from_list . "<br>";
        if ($count == 1) {
            $TP_HEAT_POWER = $power_and_ip[$p_row_id][4];
            $TP_IP_CLASS = $power_and_ip[$p_row_id][6];
        }
        if ($series_name == "T") {
            $TP_IP_CLASS = "157";
        } elseif ($series_name == "VT") {
            $TP_IP_CLASS = "156";
        }
        if ($count == 1) {
            echo "count: " . $count . "<br>";
        } else {
            echo "<h1>count: " . $count . "</h1><br>";
        }
        $NAME = $series_name . "-" . $w / 10 . $h / 10 . $d;
        //$image_prefix = $w . "-" . $h . "-" . $d . " " . $series_name . " ";
        $image_prefix = $w . "-" . $h . "-" . $d . " ";
        $image_count = count($image_files);
        $MORE_PHOTO = array();
        $MORE_PHOTO_2D = array();
        $DETAIL_PICTURE = "";
        //Если изображение ищется для серий IB* нужно искать для соответствующих серий TL, T, VT
        $series_name_img = $series_name;
        if ($series_name == "IBL") {
            $series_name_img = "TL";
        } elseif ($series_name == "IBV") {
            $series_name_img = "VT";
        } elseif ($series_name == "IB") {
            $series_name_img = "T";
        }
        for ($k = 0; $k < $image_count; $k++) {
            $image_path = $image_files[$k];
            $image_name = basename($image_path);
            //echo "Image name " . $image_name . "<br>";
            if (0 === strpos($image_name, $image_prefix) && 0 != strpos($image_path, " " . $series_name_img . " ")) {
                echo "FOUND IMAGE! " . $image_path . "<br>";
                if (strpos($image_name, "3D") != false) {
                    $MORE_PHOTO[] = CFile::MakeFileArray($image_path);
                } else {
                    $MORE_PHOTO_2D[] = CFile::MakeFileArray($image_path);
                }
            }
        }
        if (count($MORE_PHOTO) > 0) {
            $DETAIL_PICTURE = $MORE_PHOTO[0];
            unset($MORE_PHOTO[0]);
        }
        foreach ($MORE_PHOTO_2D as $PHOTO) {
            $MORE_PHOTO[] = $PHOTO;
        }
        //test_dump($MORE_PHOTO);
        if ($TP_HEAT_POWER != "") {
            $NAME = $NAME . "-" . $TP_HEAT_POWER;
        }
        echo $NAME . "<br>";
        if ($series_name != "VT" || $series_name != "IBV") {
            $P = array("ARTNUMBER" => $NAME, "BRAND_REF" => $BRAND_REF, "TB_SERIES" => $TB_SERIES, "TB_WIDTH" => $TB_WIDTH, "TB_HEIGHT" => $TB_HEIGHT, "TB_DEPTH" => $TB_DEPTH, "TB_PANELS" => $TB_PANELS, "TB_DBK_COOL" => emptyOrValue($row[5], 130), "TB_DBK_HEAT" => emptyOrValue($row[6], 132), "TB_RESH" => emptyOrValue($row[8], 134), "TB_FAN" => emptyOrValue($row[9], 136), "TB_FAN_RESH" => emptyOrValue($row[10], 138), "TB_DIN_ROZ" => emptyOrValue($row[11], 140), "TB_DIN_AUTO" => emptyOrValue($row[12], 1142), "TB_KLEMM" => emptyOrValue($row[13], 144), "TB_DIN_METIZ" => emptyOrValue($row[14], 146), "TB_UTEPLITEL" => emptyOrValue($row[15], 148), "TB_OPTION" => $TB_OPTION, "TP_IP_CLASS" => $TP_IP_CLASS, "TP_HEAT_POWER" => $TP_HEAT_POWER, "MORE_PHOTO" => $MORE_PHOTO);
        } else {
            $P = array("ARTNUMBER" => $NAME, "BRAND_REF" => $BRAND_REF, "TB_SERIES" => $TB_SERIES, "TB_WIDTH" => $TB_WIDTH, "TB_HEIGHT" => $TB_HEIGHT, "TB_DEPTH" => $TB_DEPTH, "TB_PANELS" => $TB_PANELS, "TB_DBK_COOL" => emptyOrValue($row[5], 130), "TB_DBK_HEAT" => emptyOrValue($row[6], 132), "TB_RESH" => emptyOrValue($row[8], 134), "TB_FAN" => emptyOrValue($row[9 + 1], 136), "TB_FAN_RESH" => emptyOrValue($row[10 + 1], 138), "TB_DIN_ROZ" => emptyOrValue($row[11 + 1], 140), "TB_DIN_AUTO" => emptyOrValue($row[12 + 1], 1142), "TB_KLEMM" => emptyOrValue($row[13 + 1], 144), "TB_DIN_METIZ" => emptyOrValue($row[14 + 1], 146), "TB_UTEPLITEL" => emptyOrValue($row[15 + 1], 148), "TB_OPTION" => $TB_OPTION, "TP_IP_CLASS" => $TP_IP_CLASS, "TP_HEAT_POWER" => $TP_HEAT_POWER, "MORE_PHOTO" => $MORE_PHOTO);
        }
        $PRICE_EUR = floatval($PRICE_EUR) * $price_multiplier;
        if ($w * $w + $h * $h + $d * $d != 0) {
            add_element($iblock_id, $section_id, $series_title_prefix . " " . $NAME, $PRICE_EUR, $P, $DETAIL_PICTURE);
        } else {
            echo "Не добавлен!<br>";
            echo $w . " " . $h . " " . $d . "<br>";
        }
    }
}