blog->getCategory($_REQUEST['id']); } catch (Exception $e) { $core->error->add($e->getMessage()); } if (!$core->error->flag() && !$rs->isEmpty()) { $cat_id = (integer) $rs->cat_id; $cat_title = $rs->cat_title; $cat_url = $rs->cat_url; $cat_desc = $rs->cat_desc; } unset($rs); # Getting hierarchy information $parents = $core->blog->getCategoryParents($cat_id); $rs = $core->blog->getCategoryParent($cat_id); $cat_parent = $rs->isEmpty() ? 0 : (integer) $rs->cat_id; unset($rs); # Allowed parents list $children = $core->blog->getCategories(array('post_type'=>'post','start'=>$cat_id)); $allowed_parents = array(__('Top level')=>0); $p = array(); while ($children->fetch()) { $p[$children->cat_id] = 1; } $rs = $core->blog->getCategories(array('post_type'=>'post')); while ($rs->fetch()) { if (!isset($p[$rs->cat_id])) { $allowed_parents[] = new formSelectOption( str_repeat('  ',$rs->level-1).'• '.html::escapeHTML($rs->cat_title), $rs->cat_id ); } } unset($rs); # Allowed siblings list $siblings = array(); $rs = $core->blog->getCategoryFirstChildren($cat_parent); while ($rs->fetch()) { if ($rs->cat_id != $cat_id) { $siblings[html::escapeHTML($rs->cat_title)] = $rs->cat_id; } } unset($rs); } # Changing parent if ($cat_id && isset($_POST['cat_parent'])) { $new_parent = (integer) $_POST['cat_parent']; if ($cat_parent != $new_parent) { try { $core->blog->setCategoryParent($cat_id,$new_parent); http::redirect('categories.php?moved=1'); } catch (Exception $e) { $core->error->add($e->getMessage()); } } } # Changing sibling if ($cat_id && isset($_POST['cat_sibling'])) { try { $core->blog->setCategoryPosition($cat_id,(integer) $_POST['cat_sibling'],$_POST['cat_move']); http::redirect('categories.php?moved=1'); } catch (Exception $e) { $core->error->add($e->getMessage()); } } # Create or update a category if (isset($_POST['cat_title'])) { $cur = $core->con->openCursor($core->prefix.'category'); $cur->cat_title = $cat_title = $_POST['cat_title']; if (isset($_POST['cat_desc'])) { $cur->cat_desc = $cat_desc = $_POST['cat_desc']; } if (isset($_POST['cat_url'])) { $cur->cat_url = $cat_url = $_POST['cat_url']; } else { $cur->cat_url = $cat_url; } try { # Update category if ($cat_id) { # --BEHAVIOR-- adminBeforeCategoryUpdate $core->callBehavior('adminBeforeCategoryUpdate',$cur,$cat_id); $core->blog->updCategory($_POST['id'],$cur); # --BEHAVIOR-- adminAfterCategoryUpdate $core->callBehavior('adminAfterCategoryUpdate',$cur,$cat_id); http::redirect('category.php?id='.$_POST['id'].'&upd=1'); } # Create category else { # --BEHAVIOR-- adminBeforeCategoryCreate $core->callBehavior('adminBeforeCategoryCreate',$cur); $id = $core->blog->addCategory($cur,(integer) $_POST['new_cat_parent']); # --BEHAVIOR-- adminAfterCategoryCreate $core->callBehavior('adminAfterCategoryCreate',$cur,$id); http::redirect('categories.php?add=1'); } } catch (Exception $e) { $core->error->add($e->getMessage()); } } $title = $cat_id ? html::escapeHTML($cat_title) : __('New category'); dcPage::open($title, dcPage::jsConfirmClose('category-form'). dcPage::jsToolBar(). dcPage::jsLoad('js/_category.js') ); if (!empty($_GET['upd'])) { echo '

'.__('Category has been successfully updated.').'

'; } echo '

'.html::escapeHTML($core->blog->name).' › '. __('Categories').' › '; if ($cat_id) { while($parents->fetch()) { echo ''.html::escapeHTML($parents->cat_title).''; echo " › "; } } echo $title.'

'; echo '
'. '
'.__('Category information').''. '

'; if (!$cat_id) { $rs = $core->blog->getCategories(array('post_type'=>'post')); echo '

'; unset($rs); } echo '
'. '

'. '

'. __('Warning: If you set the URL manually, it may conflict with another category.').'

'. '
'. '

'. form::textarea('cat_desc',50,8,html::escapeHTML($cat_desc),'',5). '

'. '

'. ($cat_id ? form::hidden('id',$cat_id) : ''). $core->formNonce(). '

'. '
'. '
'; if ($cat_id) { echo '

'.__('Move this category').'

'. '
'. '
'. '
'. '
'.__('Category parent').''. '

'. '

'. form::hidden(array('id'),$cat_id).$core->formNonce().'

'. '
'. '
'. '
'; if (count($siblings) > 0) { echo '
'. '
'. '
'.__('Category sibling').''. '

'. form::combo('cat_move',array(__('before')=>'before',__('after')=>'after')).' '. form::combo('cat_sibling',$siblings).'

'. '

'. form::hidden(array('id'),$cat_id).$core->formNonce().'

'. '
'. '
'. '
'; } echo '
'; } dcPage::helpBlock('core_categories'); dcPage::close(); ?>