Exemple #1
0
 public function action_load_price()
 {
     // Получение значения ячейки
     function get_cell_value($worksheet, $cell)
     {
         return $worksheet->getCell($cell)->getValue();
     }
     // Преобразование числового значения столбца в символьное
     function col_n2str($col_n)
     {
         return PHPExcel_Cell::stringFromColumnIndex($col_n - 1);
     }
     // Преобразование символьного значения столбца в числовое
     function col_str2n($col)
     {
         return PHPExcel_Cell::columnIndexFromString($col);
     }
     // Узнать уровень вложенности строки
     function get_level($worksheet, $row)
     {
         return $worksheet->getRowDimension($row)->getOutlineLevel();
     }
     $objPHPExcel = PHPExcel_IOFactory::load(DOCROOT . "/price.xls");
     $structure = array("name" => array("index" => "A", "type" => "chars", "title" => "Наименование", "ordering" => 1), "ed_izm" => array("index" => "N", "type" => "select", "title" => "Единица измерения", "ordering" => 2), "price" => array("index" => "O", "type" => "price", "title" => "Цена", "ordering" => 3));
     $num_structure = array_values($structure);
     $categories = array(array("id" => 0, "level" => -1, "name" => "root"));
     $materials = array();
     $category_id_counter = 1;
     // Счётчик для id категории
     $parent_category_id = 0;
     // id родительской категории
     //echo '<table border>';
     //echo "<tr><td>Id категории<td>Уровень<td>id родительской категории<td>Название категории</tr>";
     // Проход по листам
     foreach ($objPHPExcel->getWorksheetIterator() as $worksheet) {
         $worksheet_title = $worksheet->getTitle();
         $max_row = $worksheet->getHighestRow();
         // максимальная строка
         $max_col = $worksheet->getHighestColumn();
         // максимальный столбец (буква)
         $max_col = col_str2n($max_col);
         // максимальный столбец (цифра)
         //echo "<p>Максимальная строка: " . $max_row . "</p>";
         //echo "<p>Максимальный столбец: " . $max_col . " (" . col_n2str($max_col) . ")</p>";
         $start_row = 12;
         // С какой строки начинаем?
         // Перебор строк
         for ($row = $start_row; $row <= $max_row; $row++) {
             $level = get_level($worksheet, $row);
             // Уровень вложенности
             // Строка является заголовком?
             if (!get_cell_value($worksheet, $num_structure[1]["index"] . $row)) {
                 $current_cell = "A" . $row;
                 // Адрес ячейки
                 $value = get_cell_value($worksheet, $current_cell);
                 // Название категории
                 $categories[$category_id_counter] = array("id" => $category_id_counter, "level" => $level, "name" => $value);
                 // Поиск родителя
                 for ($i = $category_id_counter; $i >= 0; $i--) {
                     if ($categories[$i]["level"] == $level - 1) {
                         $parent_category_id = $categories[$i]["id"];
                         break;
                     }
                 }
                 //echo "<tr><td>" . $category_id_counter . "<td>" . $level . "<td>" . $parent_category_id . "<td>" . $value;
                 $categories[$category_id_counter]["parent"] = $parent_category_id;
                 $category_id_counter++;
             } else {
                 //echo '<tr><td colspan="4"><table style="width:100%;" border><tr>';
                 foreach ($structure as $name => $el) {
                     $current_cell = $el["index"] . $row;
                     // Адрес ячейки
                     $value = get_cell_value($worksheet, $current_cell);
                     $material_data[$name] = $value;
                     //echo '<td>' . $value;
                 }
                 //echo "</table>";
                 $category_id = $category_id_counter - 1;
                 $material_data["category_id"] = $category_id;
                 if (!isset($categories[$category_id]["materials"])) {
                     $categories[$category_id]["materials"] = array();
                 }
                 $categories[$category_id]["materials"][] = $material_data;
                 $materials[] = $material_data;
             }
         }
         //echo "</table>";
         //var_dump($categories);
         //var_dump($materials);
         //echo "<hr>";
     }
     $gid = 1218;
     // id группы
     $model_material = new Model_Material('groups');
     $model_base = new Model_Base();
     $group = $model_material->getGroup($gid);
     $categories[0]["db_id"] = $gid;
     $categories[0]["name"] = $group["name"];
     $parent_id = 0;
     $insertdata = array();
     $fieldset = $model_material->getFieldsSet($gid);
     //$insert_categories = array();
     $current_level = 0;
     while (true) {
         $search_level_status = false;
         foreach ($categories as $category_id => $category_data) {
             if ($category_data["level"] == $current_level) {
                 $search_level_status = true;
                 // Поиск родителя
                 for ($i = $category_id; $i >= 0; $i--) {
                     if ($categories[$i]["level"] == $current_level - 1) {
                         $parent_id = $categories[$i]["db_id"];
                         break;
                     }
                 }
                 $insert_group_id = $model_material->groupInsert($parent_id, $parent_id, array('name' => $category_data["name"]));
                 $group_params = array();
                 foreach ($structure as $name => $param) {
                     $param_data = array_merge($param, array("name" => $name, "gid" => $insert_group_id));
                     $model_material->addParam($param_data);
                 }
                 $category_data["db_id"] = $insert_group_id;
                 if (isset($category_data["materials"])) {
                     $fieldset = $model_material->getFieldsSet($insert_group_id);
                     //var_dump($fieldset);
                     // Проход по материалам
                     foreach ($category_data["materials"] as $material) {
                         //var_dump($material);
                         $insertdata = array();
                         $insertdata['title'] = Request::clearText($material["name"]);
                         $insertdata['url'] = Request::str2url($material["name"]);
                         $insertdata['description'] = Request::clearText($material["name"]);
                         // Проход по параметрам
                         foreach ($fieldset as $field) {
                             if (isset($structure[$field["name"]])) {
                                 $insertdata[$field["type"] . '_' . $field["id"]] = $material[$field["name"]];
                                 switch ($field["type"]) {
                                     case "files":
                                         $insertdata[$field["type"] . '_' . $field["id"]] = array($material[$field["name"]]);
                                         break;
                                     case "photoalbum":
                                         $insertdata[$field["type"] . '_' . $field["id"]] = array($material[$field["name"]]);
                                         break;
                                     case "select":
                                         $insertdata[$field["type"] . '_' . $field["id"]] = array($material[$field["name"]]);
                                         break;
                                 }
                                 // Наценка 30%
                                 /*if ($field["type"] == "price") {
                                 			$insertdata[$field["type"].'_'.$field["id"]] = $material[$field["name"]] * 1.3;
                                 		}*/
                             }
                         }
                         echo "<pre>";
                         var_dump($insertdata);
                         echo "</pre>";
                         $result = $model_material->newMaterial($insertdata, $insert_group_id, TRUE);
                     }
                 }
                 //var_dump($category_data);
                 echo "<hr>";
                 $categories[$category_id] = $category_data;
             }
         }
         if (!$search_level_status) {
             break;
         }
         $current_level++;
     }
 }
Exemple #2
0
 public function action_index()
 {
     $group = new Model_Material('groups');
     $pagination = '';
     //Добавление группы
     if (isset($_POST['add_group'])) {
         $groupName = Arr::get($_POST, 'groupName', '');
         $parentId = Arr::get($_POST, 'parentId', '');
         $previousId = Arr::get($_POST, 'previousId', '');
         $res = $group->groupInsert($parentId, $previousId, array('name' => $groupName));
         if ($res) {
             Controller::redirect('admin/materials');
         } else {
             $data['errors'] = $group->getErrors();
         }
     }
     //Редактирование группы
     if (isset($_POST['save_group'])) {
         $groupName = Arr::get($_POST, 'groupName', '');
         $groupKeywords = Arr::get($_POST, 'groupKeywords', '');
         $groupDescription = Arr::get($_POST, 'groupDescription', '');
         $id = $this->request->param('id');
         $res = $group->groupUpdate($id, array('name' => $groupName, 'keywords' => $groupKeywords, 'description' => $groupDescription));
         if ($res) {
             Controller::redirect('admin/materials/' . $id);
         } else {
             $data['errors'] = $group->getErrors();
         }
     }
     //Добавление поля группы
     if (isset($_POST['add_field'])) {
         $groupId = $this->request->param('id');
         $paramTitle = Arr::get($_POST, 'field_title', '');
         $paramName = Arr::get($_POST, 'field_name', '');
         $paramType = Arr::get($_POST, 'field_type', '');
         $previousPos = Arr::get($_POST, 'previousPos', '0');
         $ordering = $previousPos + 1;
         $result = $group->addParam(array('gid' => $groupId, 'name' => $paramName, 'title' => $paramTitle, 'type' => $paramType, 'ordering' => $ordering));
         if (!$result) {
             $data['groupErrors'] = $group->getErrors();
         }
     }
     if (isset($_POST['change_group'])) {
         $oldGroup = Arr::get($_POST, 'old_group', '0');
         $newGroup = Arr::get($_POST, 'new_group', '0');
         $ids = Arr::get($_POST, 'check_name', NULL);
         $result = $group->changeGroup($oldGroup, $newGroup, $ids);
     }
     //Загрузка из Excell
     if (isset($_POST['load_xls'])) {
         $groupId = $this->request->param('id');
         $excel = new Model_Excel();
         $load = $excel->load_xls($_FILES, $groupId);
     }
     if (isset($_POST['delete_fields'])) {
         $groupId = $this->request->param('id');
         $paramId = Arr::get($_POST, 'pid', '');
         $result = $group->deleteParams($paramId);
     }
     //удаление отмеченных материалов
     if (isset($_POST['checked_del'])) {
         $gid = $this->request->param('id');
         $delArr = Arr::get($_POST, 'check_name', array());
         $group = new Model_Material('groups');
         foreach ($delArr as $del) {
             $group->deleteMaterial($del, $gid);
         }
     }
     //if(isset())
     $groupId = $this->request->param('id');
     $pageNum = str_replace('page', '', $this->request->param('page'));
     if ($groupId != NULL && $groupId != 'cart') {
         $data['thisGroup'] = $group->getGroup($groupId);
         $data['groupParams'] = $group->getParams($groupId);
         if (!$this->request->param('url')) {
             $q = Arr::get($_GET, 'q', '');
             $countMaterials = $group->getCountAdmMaterials($groupId, $q);
             $pagination = Pagination::factory(array('total_items' => $countMaterials));
             $pagination->current_page = $pageNum;
             if (isset($_GET['sort'])) {
                 $data['items'] = $group->getMaterials($groupId, $pagination->items_per_page, $pagination->offset, $q, array($_GET['sort']));
             } else {
                 $data['items'] = $group->getMaterials($groupId, $pagination->items_per_page, $pagination->offset, $q);
             }
         } else {
             if (isset($_POST['save_material'])) {
                 $res = $group->saveMaterial($_POST, $_FILES);
                 if ($res) {
                     Controller::redirect('admin/materials/' . $groupId);
                 } else {
                     $data['errors'] = $group->getErrors();
                 }
             }
             //Данные материала
             $materialId = $group->getMaterialIdByUrl($this->request->param('url'));
             $data['material'] = $group->getAdminMaterial($materialId);
             //комментарии
             $comments['data'] = $group->getComments($materialId, FALSE);
             //Поля
             $fieldset = array();
             $fields = $group->getFields2($data['material']['id']);
             foreach ($fields as $field) {
                 //генерируем код для каждого поля
                 //если поле - список выбора
                 if ($field['type'] == 'select') {
                     $values = $group->getSelectValues($field['id']);
                     $field['myValues'] = $values;
                 }
                 $fieldset[] = View::factory('admin/fields/' . $field['type'])->bind('data', $field)->render();
             }
             $data['fields'] = $fieldset;
         }
     } elseif ($groupId == 'cart') {
         $data['items'] = $group->getMaterials($groupId);
         $data['is_cart'] = TRUE;
     }
     $data['groups'] = $group->getTree();
     //
     $wpm['status'] = Cookie::get('wpm', FALSE);
     $wpm['folder'] = Cookie::get('wpm_folder', '');
     $folders = $this->getFolders();
     $pictures = $this->action_pictures($wpm['folder']);
     $comments['status'] = Cookie::get('comments', FALSE);
     $this->template->content = View::factory('admin/admMaterials', array('data' => $data, 'folders' => $folders, 'pictures' => $pictures, 'wpm' => $wpm, 'user' => $this->user, 'pagination' => $pagination));
     // $this->template->content = View::factory('admin/admMaterials', array('data'=> $data, 'user' => $this->user, 'pagination' => $pagination, 'comments' => $comments, 'pictures' => $pictures, 'wpm' => $wpm, ));
 }
Exemple #3
0
 public function action_index()
 {
     $group = new Model_Material('groups');
     $pagination = '';
     $folders = $this->getFolders();
     //Добавление группы
     if (isset($_POST['add_group'])) {
         $groupName = Arr::get($_POST, 'groupName', '');
         $parentId = Arr::get($_POST, 'parentId', '');
         $previousId = Arr::get($_POST, 'previousId', '');
         $res = $group->groupInsert($parentId, $previousId, array('name' => $groupName));
         if ($res) {
             Controller::redirect('admin/materials');
         } else {
             $data['errors'] = $group->getErrors();
         }
     }
     //Редактирование группы
     if (isset($_POST['save_group'])) {
         $groupName = Arr::get($_POST, 'groupName', '');
         $groupKeywords = Arr::get($_POST, 'groupKeywords', '');
         $groupDescription = Arr::get($_POST, 'groupDescription', '');
         $id = $this->request->param('id');
         $res = $group->groupUpdate($id, array('name' => $groupName, 'keywords' => $groupKeywords, 'description' => $groupDescription));
         if ($res) {
             Controller::redirect('admin/materials/' . $id);
         } else {
             $data['errors'] = $group->getErrors();
         }
     }
     //Добавление поля группы
     if (isset($_POST['add_field'])) {
         $groupId = $this->request->param('id');
         $paramTitle = Arr::get($_POST, 'field_title', '');
         $paramName = Arr::get($_POST, 'field_name', '');
         $paramType = Arr::get($_POST, 'field_type', '');
         $previousPos = Arr::get($_POST, 'previousPos', '0');
         $addToChildren = Arr::get($_POST, 'add_to_children', '');
         $ordering = $previousPos + 1;
         $param_data = array('gid' => $groupId, 'name' => $paramName, 'title' => $paramTitle, 'type' => $paramType, 'ordering' => $ordering);
         if ($addToChildren) {
             $parent_data = $group->getGroup($groupId);
             $children_groups = DB::select()->from('groups')->where('left_key', '>', $parent_data['left_key'])->and_where('right_key', '<', $parent_data['right_key'])->execute();
             foreach ($children_groups as $group_data) {
                 $param_data["gid"] = $group_data["id"];
                 $result = $group->addParam($param_data);
                 if (!$result) {
                     $data['groupErrors'] = $group->getErrors();
                 }
             }
         }
         $param_data["gid"] = $groupId;
         $result = $group->addParam($param_data);
         if (!$result) {
             $data['groupErrors'] = $group->getErrors();
         }
     }
     if (isset($_POST['change_group'])) {
         $groupId = $this->request->param('id');
         $newGroup = Arr::get($_POST, 'new_group', '0');
         $ids = Arr::get($_POST, 'check_name', NULL);
         if (!empty($ids)) {
             $result = $group->changeGroup($groupId, $newGroup, $ids);
         }
     }
     if (isset($_POST['save_selects'])) {
         $selects = new Model_Params_Selects();
         $values = $_POST;
         unset($values['save_selects']);
         $selects->saveSelectsValues($values, $_POST['save_selects']);
     }
     if (isset($_POST['sort_fields'])) {
         $groupId = $this->request->param('id');
         $group->sortParams($_POST['params'], $groupId);
     }
     if (isset($_POST['save_param'])) {
         $selects = new Model_Selects();
         $values = $_POST;
         unset($values['save_param']);
         $selects->saveSelectsParam($values, $_POST['save_param'], $_FILES);
     }
     //Загрузка из Excell
     if (isset($_POST['load_xls'])) {
         $groupId = $this->request->param('id');
         $excel = new Model_Excel();
         //  $file = DOCROOT . '/upload/task/file.xlsx';
         //  $load = $excel->load_xls($file, 602, 11, 20);
         $load = $excel->load_xls($_FILES, $groupId);
     }
     if (isset($_GET['exportExcel'])) {
         $excel = new Model_Excel();
         $res = $excel->uploadFile($_GET['exportExcel']);
         if ($res) {
             $data['messages'] = $res;
         }
     }
     if (isset($_POST['delete_fields'])) {
         $groupId = $this->request->param('id');
         $paramId = Arr::get($_POST, 'pid', '');
         $result = $group->deleteParams($paramId);
     }
     //удаление отмеченных материалов
     if (isset($_POST['checked_del'])) {
         $gid = $this->request->param('id');
         $delArr = Arr::get($_POST, 'check_name', array());
         $group = new Model_Material('groups');
         foreach ($delArr as $del) {
             $group->deleteMaterial($del, $gid);
         }
     }
     //if(isset())
     $groupId = $this->request->param('id');
     $pageNum = str_replace('page', '', $this->request->param('page'));
     if ($groupId != NULL && $groupId != 'cart') {
         $data['thisGroup'] = $group->getGroup($groupId);
         $data['groupParams'] = $group->getParams($groupId);
         $data['admfields'] = $group->getAdminFields($groupId, TRUE);
         if (!$this->request->param('url')) {
             $q = Arr::get($_GET, 'q', '');
             $countMaterials = $group->getCountAdmMaterials($groupId, $q);
             $pagination = Pagination::factory(array('total_items' => $countMaterials, 'items_per_page' => 100, 'view' => 'pagination/basic2'));
             $pagination->current_page = intval($pageNum);
             if (isset($_GET['sort']) && $_GET['sort'] != '') {
                 $data['items'] = $group->getMaterials($groupId, $pagination->items_per_page, $pagination->offset, $q, array($_GET['sort']));
             } else {
                 $data['items'] = $group->getMaterials($groupId, $pagination->items_per_page, $pagination->offset, $q);
             }
         } else {
             if (isset($_POST['save_material'])) {
                 $res = $group->saveMaterial($_POST, $_FILES);
                 if ($res) {
                     Controller::redirect('admin/materials/' . $groupId);
                 } else {
                     $data['errors'] = $group->getErrors();
                 }
             }
             //Данные материала
             $materialId = $group->getMaterialIdByUrl($this->request->param('url'), $groupId);
             $data['material'] = $group->getAdminMaterial($materialId);
             //                    //комментарии
             $comments['data'] = $group->getComments($materialId, FALSE);
             //комментарии
             //$docs['data'] = $group->getDocs($materialId);
             //Поля
             $fieldset = array();
             $fields = $group->getFields2($data['material']['id']);
             foreach ($fields as $field) {
                 //генерируем код для каждого поля
                 //если поле - список выбора
                 if ($field['type'] == 'select') {
                     $values = $group->getSelectValues($field['id']);
                     $field['myValues'] = $values;
                 }
                 if ($field['type'] == 'photoalbum') {
                     $base = new Model_Base();
                     $options = $base->getOptions();
                     $field['photos_base_path'] = $options['photos_base_path'];
                 }
                 if ($field['type'] == 'files') {
                     $base = new Model_Base();
                     $options = $base->getOptions();
                     $field['files_base_path'] = $options['files_base_path'];
                 }
                 $fieldset[] = View::factory('admin/fields/' . $field['type'])->bind('data', $field)->bind('multiselect', $field['multiselect'])->bind('folders', $folders)->bind('user', $this->user)->render();
             }
             $data['fields'] = $fieldset;
         }
     } elseif ($groupId == 'cart') {
         $data['items'] = $group->getMaterials($groupId);
         $data['is_cart'] = TRUE;
     }
     $data['groups'] = $group->getTree();
     //
     $wpm['status'] = Cookie::get('wpm', FALSE);
     $wpm['folder'] = Cookie::get('wpm_folder', '');
     $pictures = $this->action_pictures($wpm['folder']);
     //$comments['status'] = Cookie::get('comments', FALSE);
     // $docs['status'] = Cookie::get('comments', FALSE);
     $this->template->content = View::factory('admin/admMaterials', array('data' => $data, 'folders' => $folders, 'pictures' => $pictures, 'wpm' => $wpm, 'user' => $this->user, 'pagination' => $pagination));
     //$this->template->content = View::factory('admin/admMaterials', array('data'=> $data, 'user' => $this->user, 'pagination' => $pagination, 'comments' => $comments));
 }
Exemple #4
0
 public function load_xls($files = NULL, $gid, $offset = 11, $limit = 20)
 {
     $material = new Model_Material('groups');
     $base = new Model_Base();
     $group = $material->getGroup($gid);
     $insertdata = array();
     $fieldset = $material->getFieldsSet($gid);
     if (is_array($files)) {
         if (isset($files) && count($files) > 0) {
             $files_size = $files['xls_price']['size'];
         } else {
             $files_size = $_GET['files_size'];
         }
         if (isset($files) && count($files) > 0) {
             $temp = $files['xls_price']['name'];
         } else {
             $temps = explode('_', $_GET['files_name']);
             $temp = implode(' ', $temps);
         }
         $name_arr = explode('.', $temp);
         $ext = array_pop($name_arr);
         if (isset($files) && count($files) > 0) {
             $tmp_name = $_FILES['xls_price']['tmp_name'];
         } else {
             $tmp_name = $_GET['files_tmp'];
         }
     } else {
         $files_size = filesize($files);
         $ext = pathinfo($files, PATHINFO_EXTENSION);
         $loadedfilename = $files;
     }
     $create_categories = TRUE;
     $load_data = TRUE;
     if ($create_categories == TRUE) {
         if ($files_size > 0 && ($ext == 'xls' || $ext == 'xlsx')) {
             //echo $files['xls_price']['size'];
             //get upload file
             if (!isset($loadedfilename)) {
                 $uploadfile = $this->uploads_dir() . $temp;
             } else {
                 $uploadfile = $loadedfilename;
                 $tmp_name = $loadedfilename;
             }
             //if lile moved
             if (move_uploaded_file($tmp_name, $uploadfile) || isset($_GET['files_name']) || isset($loadedfilename)) {
                 //load file
                 $objPHPExcel = PHPExcel_IOFactory::load($uploadfile);
                 //foreach pages
                 foreach ($objPHPExcel->getWorksheetIterator() as $worksheet) {
                     $worksheetTitle = $worksheet->getTitle();
                     $highestRow = $worksheet->getHighestRow();
                     // например, 10
                     $highestColumn = $worksheet->getHighestColumn();
                     // например, 'F'
                     $highestColumnIndex = PHPExcel_Cell::columnIndexFromString($highestColumn);
                     $nrColumns = ord($highestColumn) - 64;
                     //получаем все поля для группы
                     //$fieldset = $material->getFieldsSet($gid);
                     //перебираем страницы файла
                     foreach ($objPHPExcel->getWorksheetIterator() as $worksheet) {
                         $fields_index = array();
                         $worksheetTitle = $worksheet->getTitle();
                         $highestRow = $worksheet->getHighestRow();
                         // например, 10
                         $highestColumn = $worksheet->getHighestColumn();
                         // например, 'F'
                         $highestColumnIndex = PHPExcel_Cell::columnIndexFromString($highestColumn);
                         $nrColumns = ord($highestColumn) - 64;
                         if ($highestRow > $limit) {
                             $highestRow = $offset + $limit;
                         }
                         foreach ($objPHPExcel->getWorksheetIterator() as $worksheet) {
                             for ($row = $offset; $row <= $highestRow; ++$row) {
                                 $group_name = Arr::get($group, 'title_field', 'A') . $row;
                                 $group_nameCell = $worksheet->getCell($group_name);
                                 $insertdata[$row]['group_name'] = $group_nameCell->getValue();
                                 $title = 'D' . $row;
                                 $titleCell = $worksheet->getCell($title);
                                 $insertdata[$row]['title'] = $titleCell->getValue();
                                 $insertdata[$row]['url'] = Request::str2url($insertdata[$row]['title']);
                                 $insertdata[$row]['description'] = $insertdata[$row]['title'];
                                 $article = 'B' . $row;
                                 $articleCell = $worksheet->getCell($article);
                                 $insertdata[$row]['article'] = array($articleCell->getValue());
                                 $count = 'P' . $row;
                                 $countCell = $worksheet->getCell($count);
                                 $insertdata[$row]['count'] = array($countCell->getValue());
                                 $made_in = 'E' . $row;
                                 $made_inCell = $worksheet->getCell($made_in);
                                 $insertdata[$row]['madein'] = array($made_inCell->getValue());
                                 $trademark = 'F' . $row;
                                 $trademarkCell = $worksheet->getCell($trademark);
                                 $insertdata[$row]['trademark'] = array($trademarkCell->getValue());
                                 $photos = 'G' . $row;
                                 $photosCell = $worksheet->getCell($photos)->getHyperlink()->getUrl();
                                 $insertdata[$row]['photos'] = array($photosCell);
                                 $price = 'S' . $row;
                                 $priceCell = $worksheet->getCell($price);
                                 $insertdata[$row]['price'] = $priceCell->getOldCalculatedValue();
                             }
                         }
                     }
                 }
                 //                    echo '<pre>';
                 //                    var_dump($insertdata);
                 //                    echo '</pre>';
                 $params = array(0 => array('type' => 'select', 'title' => 'Страна производителя', 'name' => 'madein', 'ordering' => '3'), 1 => array('type' => 'select', 'title' => 'Торговая марка', 'name' => 'trademark', 'ordering' => '4'), 2 => array('type' => 'photoalbum', 'title' => 'Фото', 'name' => 'photos', 'ordering' => '1'), 3 => array('type' => 'price', 'title' => 'Цена', 'name' => 'price', 'ordering' => '2'));
                 foreach ($insertdata as $id => $group) {
                     $names = Arr::get($group, 'group_name');
                     $groupnames = explode('\\', $names);
                     $parent = '602';
                     $groupnames = array_reverse($groupnames);
                     $i = 1;
                     foreach ($groupnames as $name) {
                         if ($name != '') {
                             $groups = new Model_Material('groups');
                             if ($parent) {
                                 //проверяем наличие такой группы у родителя
                                 $res = $groups->getGroupChildren($parent, $name);
                                 if (!$res) {
                                     //если нет создаем
                                     //$newGroupId = $groups->groupInsert($parent, $parent, array('name' => $name));
                                     //$parent = $newGroupId;
                                 } else {
                                     if ($load_data == TRUE) {
                                         //загружаем данные в группу при условии, что это последняя группа
                                         if ($i == count($groupnames)) {
                                             //                                                $fieldset = $material->getFieldsSet($res['id']);
                                             $result = $material->unique_url($group['url'], $res['id']);
                                             //                                                foreach($fieldset as $field)
                                             //                                                {
                                             //                                                    if(isset($group[$field['name']]))
                                             //                                                    {
                                             //                                                        $gname = $field['type'].'_'.$field['id'];
                                             //                                                        $gvalue = $group[$field['name']];
                                             //                                                        $group[$gname] = $gvalue;
                                             //                                                        unset($group[$field['name']]);
                                             //                                                    }
                                             //                                                }
                                             //
                                             //                                                echo "<pre>";
                                             //                                                var_dump($group);
                                             //                                                echo "</pre>";
                                             if ($result) {
                                                 $fieldset = $material->getFieldsSet($res['id']);
                                                 foreach ($fieldset as $field) {
                                                     if (isset($group[$field['name']])) {
                                                         $gname = $field['type'] . '_' . $field['id'];
                                                         $gvalue = $group[$field['name']];
                                                         $group[$gname] = $gvalue;
                                                         unset($group[$field['name']]);
                                                     }
                                                 }
                                                 unset($group['group_name']);
                                                 $result = $material->newMaterial($group, $res['id'], TRUE, TRUE);
                                             }
                                             //                                                if(!$res)
                                             //                                                {
                                             //                                                    $group['mid'] = $material->getMaterialIdByUrl($group['url'], $res['id']);
                                             //                                                    if(isset($group['sleep']))
                                             //                                                        unset($group['sleep']);
                                             //
                                             //                                                    $result = $material->saveMaterial($group, $res['id'], TRUE, TRUE);
                                             //                                                }
                                             //                                                else
                                             //                                                {
                                             //                                                    $result = $material->newMaterial($group, $res['id'], TRUE, TRUE);
                                             //                                                }
                                         }
                                     }
                                     $parent = $res['id'];
                                 }
                             }
                         }
                         //создаем стандартный набор параметров
                         if ($i == count($groupnames)) {
                             foreach ($params as $param) {
                                 $param['gid'] = $parent;
                                 //получаем параметры группы
                                 $groups->addParam($param);
                             }
                         }
                         ++$i;
                     }
                 }
                 //                    if(is_array($insertdata))
                 //                    {
                 //                        foreach($insertdata as $item)
                 //                        {
                 //                            $id = $material->unique_url($item['url'], $gid);
                 //                            if(!$id)
                 //                            {
                 //                                $item['mid'] = $material->getMaterialIdByUrl($item['url'], $gid);
                 //                                if(isset($item['sleep']))
                 //                                    unset($item['sleep']);
                 //
                 //                                $result = $material->saveMaterial($item, $gid, TRUE);
                 //                            }
                 //                            else
                 //                            {
                 //                                $result = $material->newMaterial($item, $gid, TRUE);
                 //                            }
                 //                        }
                 //                    }
             }
         } else {
             echo '<div class="error_box">Не выбран файл или он неверного формата</div>';
         }
     } else {
         if ($files_size > 0 && ($ext == 'xls' || $ext == 'xlsx')) {
             //echo $files['xls_price']['size'];
             //get upload file
             $uploadfile = $this->uploads_dir() . $temp;
             //if lile moved
             if (move_uploaded_file($tmp_name, $uploadfile) || isset($_GET['files_name'])) {
                 //load file
                 $objPHPExcel = PHPExcel_IOFactory::load($uploadfile);
                 //foreach pages
                 foreach ($objPHPExcel->getWorksheetIterator() as $worksheet) {
                     $worksheetTitle = $worksheet->getTitle();
                     $highestRow = $worksheet->getHighestRow();
                     // например, 10
                     $highestColumn = $worksheet->getHighestColumn();
                     // например, 'F'
                     $highestColumnIndex = PHPExcel_Cell::columnIndexFromString($highestColumn);
                     $nrColumns = ord($highestColumn) - 64;
                     //получаем все поля для группы
                     $fieldset = $material->getFieldsSet($gid);
                     //перебираем страницы файла
                     foreach ($objPHPExcel->getWorksheetIterator() as $worksheet) {
                         $fields_index = array();
                         $worksheetTitle = $worksheet->getTitle();
                         $highestRow = $worksheet->getHighestRow();
                         // например, 10
                         $highestColumn = $worksheet->getHighestColumn();
                         // например, 'F'
                         $highestColumnIndex = PHPExcel_Cell::columnIndexFromString($highestColumn);
                         $nrColumns = ord($highestColumn) - 64;
                         foreach ($fieldset as $field) {
                             if ($worksheetTitle === $field['xls_page']) {
                                 $fields_index[$field['xls_col']] = $field['type'] . '_' . $field['id'];
                             }
                         }
                         for ($row = Arr::get($group, 'first_row', 0); $row <= $highestRow; ++$row) {
                             //формируем заголовоки массива
                             $title = Arr::get($group, 'title_field', 'А') . $row;
                             $titleCell = $worksheet->getCell($title);
                             $desc = Arr::get($group, 'desc_field', 'А') . $row;
                             $descCell = $worksheet->getCell($desc);
                             $insertdata[$row]['title'] = Request::clearText($titleCell->getValue());
                             //  $insertdata[$row]['title'] = $streetCell->getValue().' '.$houseCell->getValue().$korpus.$liter;
                             $insertdata[$row]['url'] = Request::str2url($insertdata[$row]['title']);
                             $insertdata[$row]['description'] = Request::clearText($descCell->getValue());
                             foreach ($fields_index as $key => $value) {
                                 $cell = $worksheet->getCell($key . $row);
                                 $ftype = explode('_', $value);
                                 if (Arr::get($ftype, 0) == 'chars' || Arr::get($ftype, 0) == 'texts') {
                                     $insertdata[$row][$value] = strval($cell->getValue());
                                 } elseif (Arr::get($ftype, 0) == 'select' || Arr::get($ftype, 0) == 'date' || Arr::get($ftype, 0) == 'files' || Arr::get($ftype, 0) == 'photoalbum') {
                                     $param = $material->getParam(Arr::get($ftype, 1));
                                     if ($param && isset($param['delimetr']) && $param['delimetr'] != '') {
                                         $arr = explode($param['delimetr'], strval($cell->getValue()));
                                         $arr = array_map('trim', $arr);
                                         $insertdata[$row][$value] = $arr;
                                     } else {
                                         $insertdata[$row][$value] = array(strval($cell->getValue()));
                                     }
                                 } elseif (Arr::get($ftype, 0) == 'price') {
                                     $insertdata[$row][$value] = round($cell->getValue(), 2);
                                 }
                             }
                         }
                     }
                 }
                 //                    echo '<pre>';
                 //                    var_dump($insertdata);
                 //                    echo '</pre>';
                 if (is_array($insertdata)) {
                     foreach ($insertdata as $item) {
                         $id = $material->unique_url($item['url'], $gid);
                         if (!$id) {
                             $item['mid'] = $material->getMaterialIdByUrl($item['url'], $gid);
                             if (isset($item['sleep'])) {
                                 unset($item['sleep']);
                             }
                             $result = $material->saveMaterial($item, $gid, TRUE);
                         } else {
                             $result = $material->newMaterial($item, $gid, TRUE);
                         }
                     }
                 }
             }
         } else {
             echo '<div class="error_box">Не выбран файл или он неверного формата</div>';
         }
     }
 }