define('IN_ECS', true);
require(dirname(__FILE__) . '/includes/init.php');
require('includes/lib_goods.php');
/*------------------------------------------------------ */
//-- 批量上传
/*------------------------------------------------------ */
if ($_REQUEST['act'] == 'add')
{
/* 检查权限 */
admin_priv('goods_batch');
/* 取得分类列表 */
$smarty->assign('cat_list', cat_list());
/* 取得可选语言 */
$dir = opendir('../languages');
$lang_list = array(
'UTF8' => $_LANG['charset']['utf8'],
'cp1251' => $_LANG['charset']['cp1251'],
);
$download_list = array();
while (@$file = readdir($dir))
{
if ($file != '.' && $file != '..' && $file != ".svn" && $file != "_svn" && is_dir('../languages/' .$file) == true)
{
$download_list[$file] = sprintf($_LANG['download_file'], isset($_LANG['charset'][$file]) ? $_LANG['charset'][$file] : $file);
}
}
@closedir($dir);
$data_format_array = array(
'ecshop' => $_LANG['export_ecshop'],
);
$smarty->assign('data_format', $data_format_array);
$smarty->assign('lang_list', $lang_list);
$smarty->assign('download_list', $download_list);
/* 参数赋值 */
$ur_here = $_LANG['13_batch_add'];
$smarty->assign('ur_here', $ur_here);
/* 显示模板 */
assign_query_info();
$smarty->display('goods_batch_add.htm');
}
/*------------------------------------------------------ */
//-- Пакетный импорт товаров из EXCEL ( csv )
/*------------------------------------------------------ */
elseif ($_REQUEST['act'] == 'upload')
{
/* Check permissions */
admin_priv('goods_batch');
/* Read the file by line array, line by line analysis */
$line_number = 0;
$arr = array();
$goods_list = array();
$field_list = array_keys($_LANG['upload_goods']); // Field List
$data = file($_FILES['file']['tmp_name']);
if($_POST['data_cat'] == 'ecshop')
{
foreach ($data AS $line)
{
// Skip the first line
if ($line_number == 0)
{
$line_number++;
continue;
}
// Transcoding
/*if (($_POST['charset'] != 'UTF8') && (strpos(strtolower(EC_CHARSET), 'utf') === 0))
{
$line = ecs_iconv($_POST['charset'], 'UTF8', $line);
} */
if ($_POST['charset'] == 'cp1251') {
$line = iconv('cp1251', 'utf-8', $line);
}
// Beginning of the first
$arr = array();
$buff = '';
$quote = 0;
$len = strlen($line);
for ($i = 0; $i < $len; $i++) // Посимвольно разбираем всю строку ( параметр1;параметр2; )
{
$char = $line[$i];
if ('\\' == $char)
{
$i++;
$char = $line[$i];
switch ($char)
{
case '"':
$buff .= '"';
break;
case '\'':
$buff .= '\'';
break;
case ',';
$buff .= ',';
break;
default:
$buff .= '\\' . $char;
break;
}
}
elseif ('"' == $char)
{
if (0 == $quote)
{
$quote++;
}
else
{
$quote = 0;
}
}
elseif (';' == $char)
{
if (0 == $quote)
{
if (!isset($field_list[count($arr)]))
{
continue;
}
$field_name = $field_list[count($arr)];
$arr[$field_name] = trim($buff);
$buff = '';
$quote = 0;
}
else
{
$buff .= $char;
}
}
else
{
$buff .= $char;
}
if ($i == $len - 1)
{
if (!isset($field_list[count($arr)]))
{
continue;
}
$field_name = $field_list[count($arr)];
$arr[$field_name] = trim($buff);
}
}
$goods_list[] = $arr;
}
}
$smarty->assign('goods_class', $_LANG['g_class']);
$smarty->assign('goods_list', $goods_list);
// Field Name List
$smarty->assign('title_list', $_LANG['upload_goods']);
// Display the list of fields
$smarty->assign('field_show', array('goods_name' => true, 'goods_sn' => true, 'brand_name' => true, 'market_price' => true, 'shop_price' => true));
/* Parameter assignment */
$smarty->assign('ur_here', $_LANG['goods_upload_confirm']);
/* Display Template */
assign_query_info();
$smarty->display('goods_batch_confirm.htm');
}