core/api/modules/upload_tovar_1c/index.php

63 lines
2.3 KiB
PHP
Executable File
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
/*
21.04.2022 - Загрузка базы товаров из 1с
*/
ini_set( 'display_errors', 0 );
$smarty -> caching = true;
$smarty -> cache_lifetime = $settings['cachePage'];
if ( $_SESSION['dostup'] !== 'a' && $_SESSION['dostup'] !=='e' )header( 'Location: /403/' );
if ( $_FILES['xmlFile']['name'] == 'import0_1.xml' ){
unlink( MYDIR . '/cache/tovar.xml' );
copy( $_FILES['xmlFile']['tmp_name'], MYDIR . '/cache/tovar.xml' );
$xmlstring = file_get_contents( MYDIR . '/cache/tovar.xml', true );
$xml = simplexml_load_string( $xmlstring, "SimpleXMLElement", LIBXML_NOCDATA );
$json = json_encode( $xml );
$array = json_decode( $json,TRUE );
$r1 = $array['Классификатор'];
$r2 = $r1['Группы'];
$r3 = $r2['Группа'];
unset( $r1 );
unset( $r2 );
//загружаем категории
function loadCategory( $arr, $parent=0, $db ){
$count = count( $arr );
for ( $i = 0; $i < $count; $i++ ){
$txt=@$arr[$i]['Наименование'];
$id = @$arr[$i]['Ид'];
//смотрим, есть ли такая категория в БД
$a['tovar_id'] = $id;
$cat_id = $db -> get_val( 'pages', $a, 'id' );
if ( $cat_id ){
//Обновляем
$sql = 'UPDATE `pages` SET `txt`="' . $db -> magicSQLite( $txt ) . '", `parent`="' . $parent . '", `public`="1" WHERE `id` = ' . $cat_id;
}else{
//Добавялем
$sql = 'INSERT INTO `pages` (`txt`, `tovar_id`, `parent`, `tip`, `user_id`, `public`) VALUES ("' . $db -> magicSQLite( $txt) . '", "' . $id . '", "' . $parent . '", "tovarCat", "6", "1")';
$cat_id = $db -> get_val( 'pages', $a, 'id' );
}
$db -> free_sql( $sql );
if ( @$arr[$i]['Группы'] ){
$sub_cat = $arr[$i]['Группы'];
$sub_cat2 = $sub_cat['Группа'];
loadCategory( $sub_cat2, $cat_id, $db );
}
}
}
loadCategory( $r3, 0, $db );
exec( 'php /home/www/tk-ligat.ru/cache/parce.php' );
}
?>