$regions = new regions(); // инициируем объект - Города $citys = new citys(); /** * Работа со списком Городов */ if (isset($_GET['action'])) { if ('citys' === $_GET['action']) { if (isset($_GET['pid']) && ($pid = (int) $_GET['pid']) && 0 < $pid && ($region = $regions->retCategorysByIds($pid))) { // инициируем "Наименование страницы" отображаемое в форме $arrNamePage = array(array('name' => MENU_ADMIN_MAIN, 'link' => CONF_ADMIN_FILE), array('name' => MENU_DICTIONARY_REGIONS, 'link' => CONF_ADMIN_FILE . '?m=dictionary&s=regions'), array('name' => $region[$pid]['name'], 'link' => false)); $arrActRegions['citys'] = true; if ($region[$pid]['major']) { $arrErrors[] = ERROR_REGION_MAJOR; } else { $smarty->assign('arrCitys', $citys->retCategorysByParentIds($region[$pid]['id'])); } $smarty->assignByRef('pid', $pid); /** * добавление Города */ if (isset($_POST['add_city'])) { if (isset($_POST['arrBindFields']) || is_array($_POST['arrBindFields']) || !empty($_POST['arrBindFields'])) { !$_POST['arrBindFields']['name'] ? $arrErrors[] = ERROR_EMPTY_NAME : null; !$_POST['arrBindFields']['parent_id'] ? $arrErrors[] = ERROR_EMPTY_ID : null; if (empty($arrErrors)) { /** * передаем данные для записи в таблицу городов */ $citys->arrBindFields = $_POST['arrBindFields']; // обязательные поля
static function getCitys($parent_id) { $city = new citys(); //return self::sdgJSONencode($city->retCategorysByParentIds($parent_id, array('id', 'name'))); return $city->retCategorysByParentIds($parent_id, array('id', 'name')); }
} } else { if (!empty($_POST['do'])) { // переключение Региона в статус "Регион-Город" if ('setRegionMajor' == $_POST['do'] && !empty($_POST['rid'])) { $force = isset($_POST['force']) ? true : false; /** * инициализация списка регионов */ $regions = new regions(); $arrDataRegions = $regions->retCategorys(); if (!empty($arrDataRegions[$_POST['rid']])) { $arrFields = array($_POST['rid']); $citys = new citys(); if ($force) { $listCitys = $citys->retCategorysByParentIds($_POST['rid']); if (is_array($listCitys) && $citys->actionCitys('del', array_keys($listCitys), $_POST['rid'], true)) { if ($regions->actionRegions('setRegionMajor', $arrFields, true)) { echo ajax::sdgJSONencode(array('success' => true)); } else { echo ajax::sdgJSONencode(array('error' => 'errRegionSetMajor')); } } else { echo ajax::sdgJSONencode(array('error' => 'errRegionDeleteChildRecords')); } } else { if ($citys->retCategorysByParentIds($_POST['rid'])) { echo ajax::sdgJSONencode(array('error' => 'errRegionHasChildRecords')); } else { if ($regions->actionRegions('setRegionMajor', $arrFields, true)) { echo ajax::sdgJSONencode(array('success' => true));