public function copy($with_child = true, $copyTo = 0) { if (!empty($this->id)) { $copy = new ormPage(); $copy->setClass($this->getClass()->id()); // Перенос данных полей $fields = $this->getClass()->loadFields(); while (list($fname, $field) = each($fields)) { if (!empty($field['f_type']) && $field['f_type'] != 97 && $field['f_relation'] < 2 && $fname != 'pseudo_url' && $fname != 'tags') { $copy->__set($fname, $this->__get($fname)); } } if (empty($copyTo)) { $copy->__set('name', $this->__get('name') . lang::get('copy')); $copy->__set('h1', $this->__get('h1') . lang::get('copy')); $copy->__set('title', $this->__get('title') . lang::get('copy')); $copy->__set('pseudo_url', $this->__get('pseudo_url') . rand(1000, 9999)); } else { $copy->__set('pseudo_url', $this->__get('pseudo_url')); } $copy->__set('template_id', $this->__get('template_id')); $copy->__set('template2_id', $this->__get('template2_id')); $copy->__set('tags', $this->__get('_tags')); // Устанавливаем родителя if (empty($copyTo)) { $parents = $this->getParents(); while (list($id, $parent) = each($parents)) { // $parent['position'] $copy->setNewParent($id); } } else { $copy->setNewParent($copyTo); } // Права доступа $rights = db::q('SELECT r_state, r_group_id FROM <<rights>> WHERE r_obj_id = "' . $this->id . '";', records); if (count($rights) === 1 && empty($rights[0]['r_group_id'])) { $copy->setRightForAll($rights[0]['r_state']); } else { while (list($key, $right) = each($rights)) { $copy->setRight($right['r_group_id'], $right['r_state']); } } $copy->save(); if (!$copy->issetErrors() && $with_child) { while ($child = $this->getChild()) { $child->copy(true, $copy->id); } return true; } else { if ($copy->issetErrors()) { //echo $copy->getErrorListText(); return false; } } } }
public function proc_upd() { $mini_action = substr(system::action(), -3); $this->createTemplate('template_id'); $this->createTemplate('template2_id'); if (system::action() == "proc_upd") { // Говорим какой объект нужно изменить $obj = new ormPage(system::POST('obj_id')); } else { if (system::action() == "proc_add") { // Говорим какой объект нужно создать $obj = new ormPage(); $obj->setClass(system::POST('class_id')); $obj->setParent(system::POST('obj_id')); } } // Если произошли ошибки, перенаправляем на главную страницу модуля if ($obj->issetErrors()) { system::redirect('/structure/tree'); } // Присваиваем пришедшие значения полям в объекте $obj->loadFromPost($mini_action); rights::setListForObject($obj); // Сохраняем изменения $obj_id = $obj->save(); // Если объект не сохранился, выводим пользователю текст ошибки. if ($obj_id === false) { system::savePostToSession(); ui::MessageBox(lang::get('TEXT_MESSAGE_ERROR'), $obj->getErrorListText()); ui::selectErrorFields($obj->getErrorFields()); $class = $mini_action == 'add' ? '/' . system::POST('class_id') : ''; system::redirect('/structure/page_' . $mini_action . '/' . $_POST['obj_id'] . $class); } else { // Присваиваем выбранные шаблоны для всех вложенных объектов, если выбрано. if (system::POST('template_id_all', isBool)) { $this->inheritTemplate($_POST['template_id'], false, $obj_id); } if (system::POST('template2_id_all', isBool)) { $this->inheritTemplate($_POST['template2_id'], true, $obj_id); } } // Если данные изменились корректно перенаправляем на соответствующию страницу if ($_POST['parram'] == 'apply') { system::redirect('/structure/page_upd/' . $obj_id); } else { if (isset($_SESSION['STRUCTURE_LIST_FLAG']) && $_SESSION['STRUCTURE_LIST_FLAG']) { system::redirect('/structure/list/' . $obj->getParentId()); } else { system::redirect('/structure/tree'); } } }