Your IP : 3.137.184.169
<?
require($_SERVER["DOCUMENT_ROOT"]."/bitrix/header.php");
$APPLICATION->SetPageProperty("ISCUSTOMPAGE", "Y");
$APPLICATION->SetTitle("WebProfy Optima Menu Update");
$MENU_FILE = ".optimamenu.php";
$ROW_START = 4;
$COL_SECT = 2;
$COL_PAGE = 3;
$COL_PROTO = 42;
$COL_LINK = 12;
$COL_STATUS = 13;
$COL_CODE = 10;
$SEC_START = 2;
$SEC_SECT = 0;
$SEC_PAGE = 2;
$SEC_CODE = 3;
CModule::IncludeModule('iblock');
if($_POST['do'] && isset($_POST['pages_csv']) && isset($_POST['sections_csv'])){
$arPages = array();
$arSections = array();
if (($handle = fopen($_SERVER['DOCUMENT_ROOT'].$_POST['pages_csv'], "r")) !== FALSE) {
$row = 0;
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
$row++;
if($row < $ROW_START || $data[$COL_STATUS] == "")
continue;
$arPages[] = array(
'sort' => $row,
'section' => $data[$COL_SECT],
'page' => $data[$COL_PAGE],
'proto' => $data[$COL_PROTO],
'link' => $data[$COL_LINK],
'status' => $data[$COL_STATUS],
'code' => $data[$COL_CODE]
);
}
fclose($handle);
}
if (($handle = fopen($_SERVER['DOCUMENT_ROOT'].$_POST['sections_csv'], "r")) !== FALSE) {
$row = 0;
$lastSection = "";
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
$row++;
if($row < $SEC_START)
continue;
if($data[$SEC_SECT]){
$lastSection = $data[$SEC_SECT];
}
$arSections[] = array(
'sort' => $row,
'section' => $lastSection,
'page' => $data[$SEC_PAGE],
'code' => $data[$SEC_CODE]
);
}
fclose($handle);
}
$res = array(
'pages' => $arPages,
'sections' => $arSections
);
$filedata = '<?';
$filedata .= PHP_EOL.'// This file is generated from Optima Table CSV using /_optima/update.php script';
$filedata .= PHP_EOL.'$arResult = unserialize(\''.serialize($res).'\');';
file_put_contents($MENU_FILE, $filedata);
dump('Complete! Pages: '.count($res['pages']).', Sections: '.count($res['sections']));
}
?>
<div class="content-area layout__block">
<h2>Как пользоваться:</h2>
<ul>
<li>Откройте <a href="https://docs.google.com/spreadsheets/d/1vwJ_nyxXx7cX4uVdZrmy0vy3hczJ5YIF4r4xatBLucE/" target="_blank">таблицу ОПТИМА</a></li>
<li>Экспортируйте в CSV лист "РАЗДЕЛЫ"</li>
<li>Экспортируйте в CSV лист "СТРАНИЦЫ"</li>
<li>Загрузите их с помощью формы ниже</li>
<li>Поздравляю, меню обновлено.</li>
</ul>
</div>
<div class="form-standart is-hor is-e2 layout__block">
<div class="form-standart__plate">
<form method="POST" action="<?= $APPLICATION->GetCurPage(); ?>" id="optimaupdateform">
<div class="form-standart__fields-list">
<div class="form-standart__field">
<div class="form-standart__label">CSV-файл со списком базовых страниц</div>
<div class="form-standart__item">
<div class="form-standart__inputs">
<input type="text" name="pages_csv" id="pages_csv" style="width: 75%"/>
<a class="button" onclick="OpenPagesCSV()">Выбрать</a>
</div>
</div>
</div>
<div class="form-standart__field">
<div class="form-standart__label">CSV-файл со списком базовых разделов</div>
<div class="form-standart__item">
<div class="form-standart__inputs">
<input type="text" name="sections_csv" id="sections_csv" style="width: 75%" />
<a class="button" onclick="OpenSectionsCSV()">Выбрать</a>
</div>
</div>
</div>
<div class="form-standart__field">
<div class="form-standart__label is-empty"> </div>
<div class="form-standart__item">
<div class="form-standart__inputs">
<input type="submit" name="do" id="do_update" value="Обновить" class="button-primary"/>
</div>
</div>
</div>
</div>
<? CAdminFileDialog::ShowScript(Array
(
"event" => "OpenPagesCSV",
"arResultDest" => Array("FUNCTION_NAME" => "SetPagesCSVUrl"),
"arPath" => Array(),
"select" => 'F',
"operation" => 'O',
"showUploadTab" => true,
"showAddToMenuTab" => false,
"fileFilter" => 'csv',
"allowAllFiles" => true,
"saveConfig" => true
)
); ?>
<? CAdminFileDialog::ShowScript(Array
(
"event" => "OpenSectionsCSV",
"arResultDest" => Array("FUNCTION_NAME" => "SetSectionsCSVUrl"),
"arPath" => Array(),
"select" => 'F',
"operation" => 'O',
"showUploadTab" => true,
"showAddToMenuTab" => false,
"fileFilter" => 'csv',
"allowAllFiles" => true,
"saveConfig" => true
)
); ?>
<script>
function SetPagesCSVUrl(filename, path, site){
$('#pages_csv').val(path + '/' + filename);
SaveToStorage();
}
function SetSectionsCSVUrl(filename, path, site){
$('#sections_csv').val(path + '/' + filename);
SaveToStorage();
}
function SaveToStorage(){
localStorage.setItem('pages_csv', $('#pages_csv').val());
localStorage.setItem('sections_csv', $('#sections_csv').val());
}
$(function(){
$('#pages_csv').val(localStorage.getItem('pages_csv'));
$('#sections_csv').val(localStorage.getItem('sections_csv'));
});
</script>
</form>
</div>
</div>
<?require($_SERVER["DOCUMENT_ROOT"]."/bitrix/footer.php");?>