<?php

require_once(dirname(dirname(__FILE__)) . '/app.php');
need_manager();

if($_POST && ($_POST['provider']!="null") && ($_POST['category']!="null")){  
    if( $_POST['csv']!=""){
          OItem::importFromCsv($_POST['provider'],$_POST['category'], $_POST['csv']);
    }
    if($_POST['csvfile']!="null"){
        $csvfile = IMG_ROOT ."/data/".iconv('UTF-8','GB2312',trim($_POST['csvfile']));
        $csv = file_get_contents($csvfile);
        OItem::importFromCsv($_POST['provider'],$_POST['category'], $csv);
    }
}else{
    if($_POST) Session::Set('error','信息填写不完整，导入失败');
}

$provider = DB::LimitQuery('provider');
$category = DB::LimitQuery('category');
$files = array();
if ($handle = opendir(WWW_ROOT.'/static/data')) {
    while (false !== ($file = readdir($handle))) {
        array_push($files,$file);
    }
    closedir($handle);
}


include template('manage_item_upload');?>
