public static function import() { $data = array(); if ($_FILES['upload']['tmp_name']) { $objPHPExcel = PHPExcel_IOFactory::load($_FILES['upload']['tmp_name']); $sheet = $objPHPExcel->setActiveSheetIndex(0); $cols = 1; while ($sheet->getCell(Impexp::dfe($cols) . '2')->getValue() != NULL) { //$data[0][]=$sheet->getCell(Impexp::dfe($i).'1')->getValue(); $cols++; } $ii = 3; while ($sheet->getCell('A' . ($ii + 1))->getValue() != NULL) { $partname = $sheet->getCell('B' . ($ii + 1))->getValue(); $size = $sheet->getCell('C' . ($ii + 1))->getValue(); if ($size == '') { $size = 'universal'; } foreach (Price::$c as $i => $item) { if ($item != 'name' && $item != 'size') { if ($size == 'universal') { $data[$partname]['universal'][$item] = $sheet->getCell(Impexp::dfe($i) . ($ii + 1))->getValue(); $data[$partname]['nosize'][$item] = $sheet->getCell(Impexp::dfe($i) . ($ii + 1))->getValue(); } else { $data[$partname][$size][$item] = $sheet->getCell(Impexp::dfe($i) . ($ii + 1))->getValue(); } } } $ii++; } Price::setList($data); //print '<pre>';print_r($data);die; } }
public static function setList($list) { $row = 1; $is_catalog = false; $module = ''; $moduleFieldsAll = ''; $moduleFields = ''; foreach ($list as $data) { if ($row == 1) { $getfields = $data; } else { if ($row == 2) { $fields = Impexp::getFieldsByTree($data[0]); $sql = 'SELECT id FROM {{catalog}} WHERE tree=' . $data[0]; if (DB::getOne($sql)) { $is_catalog = true; } $module = Module::getModuleByTree($data[0]); $moduleFieldsAll = Module::getFieldList($module['id'], 'all'); foreach ($moduleFieldsAll as $item) { $moduleFields[$item['name']] = $item; } } $n = 0; foreach ($getfields as $item) { if ($data[0] > 0) { if (in_array($item, Impexp::$treeFieldsRus)) { if ($item != 'id') { if ($item == 'Дата') { $sql = 'UPDATE {{tree}} SET ' . Impexp::$treeFieldsRusConvert[$item] . '=\'' . date('Y-m-d H:i:s', strtotime($data[$n])) . '\' WHERE id=' . $data[0] . ''; } else { $sql = 'UPDATE {{tree}} SET ' . Impexp::$treeFieldsRusConvert[$item] . '=\'' . $data[$n] . '\' WHERE id=' . $data[0] . ''; } DB::exec($sql); } } else { if ($is_catalog) { if (in_array($moduleFields[$item]['path'], OneSSA::$catalogStandart)) { $sql = 'UPDATE {{catalog}} SET ' . $moduleFields[$item]['path'] . '=\'' . $data[$n] . '\' WHERE tree=' . $data[0] . ''; DB::exec($sql); } else { $sql = 'UPDATE {{data}} SET ' . Impexp::getFei($moduleFields[$item]['type']) . '=\'' . $data[$n] . '\' WHERE tree=' . $data[0] . ' AND path=\'' . $moduleFields[$item]['path'] . '\''; DB::exec($sql); } } else { $sql = 'UPDATE {{data}} SET ' . Impexp::getFei($moduleFields[$item]['type']) . '=\'' . $data[$n] . '\' WHERE tree=' . $data[0] . ' AND path=\'' . $moduleFields[$item]['path'] . '\''; DB::exec($sql); } } //print DB::prefix($sql); //print '<br>'; } $n++; } } $row++; } }
function import() { Impexp::import(); $this->redirect('/work/' . Funcs::$uri[3] . '/'); }