function edit_category() { $category_model = new Category_model(); $category_service = new Category_service(); $category_model->set_id($this->input->post('category_id', TRUE)); $category_model->set_name($this->input->post('name', TRUE)); echo $category_service->update_category($category_model); }
public function get_options($rel) { // IDs $rel = explode(".", $rel); $id_page = !empty($rel[1]) ? $rel[0] : '0'; $id_article = !empty($rel[1]) ? $rel[1] : NULL; $resource = $this->_get_resource_name('backend', 'article', $id_article); if (Authority::can('edit', $resource, NULL, TRUE)) { // Edit article if ID exists if (!is_null($id_article)) { $article = $this->article_model->get_by_id($id_article); if (!empty($article)) { $this->load_modules_addons($article); // Page context of the current edited article $article['id_page'] = $id_page; // Merge article's data with template $this->template = array_merge($this->template, $article); $this->article_model->feed_lang_template($id_article, $this->template); // Add article types to template $data = $this->article_type_model->get_types_select(); if (!empty($data)) { $data = array('' => lang('ionize_select_no_type')) + $data; $this->template['all_article_types'] = $data; } else { $this->template['all_article_types'] = NULL; } $this->template['article_type_current'] = $article['id_type']; // Linked pages list $this->template['pages_list'] = $this->article_model->get_pages_list($id_article); // Categories $categories = $this->category_model->get_categories_select(); $current_categories = $this->category_model->get_current_categories('article', $id_article); $this->template['categories'] = form_dropdown('categories[]', $categories, $current_categories, 'class="select w100p" multiple="multiple"'); // Permissions $frontend_roles_resources = $this->resource_model->get_element_roles_resources('article', $id_article, self::$_AUTHORITY_FRONTEND_ACTIONS, 'frontend'); $this->template['frontend_roles_resources'] = $frontend_roles_resources; $backend_roles_resources = $this->resource_model->get_element_roles_resources('article', $id_article, self::$_AUTHORITY_BACKEND_ACTIONS, 'backend'); $this->template['backend_roles_resources'] = $backend_roles_resources; // Default Deny Action if (empty($article['deny_code'])) { $this->template['deny_code'] = '404'; } // Roles which have permission set for this page $this->template['frontend_role_ids'] = $this->rule_model->get_element_role_ids('article', $id_article); $this->template['backend_role_ids'] = $this->rule_model->get_element_role_ids('article', $id_article, 'backend'); // Output $this->output('article/options'); } else { // Article not found $this->error(lang('ionize_message_article_not_exist')); } } else { // Article not found $this->error(lang('ionize_message_article_not_exist')); } } else { $this->output(self::$_DENY_DEFAULT_VIEW); } }
function get($name = '', $limit = 999) { $links = array(); $this->db->select('*'); $this->db->from(self::table_name); if ($name) { $this->db->where('name', $name); } $this->db->limit($limit); $this->db->order_by('name', 'ASC'); $query = $this->db->get(); foreach ($query->result() as $c) { $link = new Category_model(); $link->_load_from_query($c); $links[$c->id] = $link; } return $links; }
/** * Saves categories ordering * * @param bool|string $parent * @param bool|int $id_parent */ public function save_ordering($parent = FALSE, $id_parent = FALSE) { $order = $this->input->post('order'); if ($order != FALSE) { // Saves the new ordering $this->category_model->save_ordering($order); if ($parent != FALSE) { // Update Array for JSON $this->update[] = array('element' => 'categories', 'url' => admin_url() . 'category/get_select/' . $parent . '/' . $id_parent); } // Answer $this->success(lang('ionize_message_operation_ok')); } else { $this->error(lang('ionize_message_operation_nok')); } }
/** * Displays the options side panel * * @param int $id_page Page ID * */ public function get_options($id_page) { $resource = $this->_get_resource_name('backend', 'page', $id_page); if (Authority::can('edit', $resource, null, true)) { // Data $page = $this->page_model->get_by_id($id_page); if (!empty($page)) { // Correct the menu ID (for phantom pages) if ($page['id_menu'] == '0') { $page['id_menu'] = '1'; } // Page data $this->template = array_merge($this->template, $page); $this->page_model->feed_lang_template($id_page, $this->template); // Load the module's addons $this->load_modules_addons($page); // Dropdown menus $data = $this->menu_model->get_select(); $this->template['menus'] = form_dropdown('id_menu', $data, $this->template['id_menu'], 'id="id_menu" class="select"'); // Subnav menu $subnav_page = $this->page_model->get_by_id($page['id_subnav']); $selected_subnav = !empty($subnav_page['id_menu']) ? $subnav_page['id_menu'] : '-1'; $this->template['subnav_menu'] = form_dropdown('id_subnav_menu', $data, $selected_subnav, 'id="id_subnav_menu" class="select"'); // Dropdown Views $views = array(); if (is_file(FCPATH . 'themes/' . Settings::get('theme') . '/config/views.php')) { require_once FCPATH . 'themes/' . Settings::get('theme') . '/config/views.php'; } // Dropdown Page views $data = isset($views['page']) ? $views['page'] : array(); if (count($data) > 0) { $data = $this->_get_views_dropdown_data($data, 'Page'); $data = array('' => lang('ionize_select_default_view')) + $data; $this->template['views'] = form_dropdown('view', $data, $this->template['view'], 'class="select"'); $this->template['single_views'] = form_dropdown('view_single', $data, $this->template['view_single'], 'class="select"'); } // Dropdown article list views (templates) $data = isset($views['article']) ? $views['article'] : array(); if (count($data) > 0) { $data = $this->_get_views_dropdown_data($data, 'Article'); $data = array('' => lang('ionize_select_default_view')) + $data; $this->template['article_list_views'] = form_dropdown('article_list_view', $data, $this->template['article_list_view'], 'class="select"'); $this->template['article_views'] = form_dropdown('article_view', $data, $this->template['article_view'], 'class="select"'); } // Roles & Rules $frontend_roles_resources = $this->resource_model->get_element_roles_resources('page', $id_page, self::$_AUTHORITY_FRONTEND_ACTIONS, 'frontend'); $this->template['frontend_roles_resources'] = $frontend_roles_resources; $backend_roles_resources = $this->resource_model->get_element_roles_resources('page', $id_page, self::$_AUTHORITY_BACKEND_ACTIONS, 'backend'); $this->template['backend_roles_resources'] = $backend_roles_resources; // Roles which have permission set for this page $this->template['frontend_role_ids'] = $this->rule_model->get_element_role_ids('page', $id_page); $this->template['backend_role_ids'] = $this->rule_model->get_element_role_ids('page', $id_page, 'backend'); // Default Deny Action if (empty($page['deny_code'])) { $this->template['deny_code'] = '404'; } // Types $types = $this->type_model->get_select('page', lang('ionize_select_no_type')); if (count($types) > 1) { $this->template['types'] = form_dropdown('id_type', $types, $this->template['id_type'], 'class="select"'); } // Categories $categories = $this->category_model->get_categories_select(); $current_categories = $this->category_model->get_current_categories('page', $id_page); $this->template['categories'] = form_dropdown('categories[]', $categories, $current_categories, 'class="select w100p" multiple="multiple"'); // Output $this->output('page/options'); } else { $this->error(lang('ionize_message_page_not_exist')); } } }
/** * New / Edit article form * The form is simplified if site use simple editing * * @param integer $id_area Area ID * @param string $lang Language code * @param integer $code_context Context code * @param string $bid, the unique ID of articles * @param integer $id_page Page ID (for simple editing) * @param boolean $duplicate Duplicate article resetting bid * @return void */ public function edit($id_area = 2, $lang = '', $code_context = 0, $bid = 0, $id_page = 0, $duplicate = 0) { // set language $lang = empty($lang) ? X4Route_core::$lang : $lang; // load dictionaries $this->dict->get_wordarray(array('form', 'articles')); // referer $qs = X4Route_core::get_query_string(); $referer = isset($qs['ref']) ? $qs['ref'] : ''; $mod = new Article_model(); // simple editing if ($id_page && $bid != 'x3') { $bid = $mod->get_bid_by_id_page($id_page); } // get object $item = $bid && $bid != 'x3' ? $mod->get_by_bid($bid) : new Article_obj($id_area, $lang, $code_context); // dedicated page when called from composer if ($bid == 'x3') { $item->id_page = $id_page; } // if duplicate reset bid if ($duplicate) { $item->name = _COPY_OF . ' ' . $item->name; $item->bid = $mod->get_new_bid(); } // build the form $fields = array(); $fields[] = array('label' => null, 'type' => 'html', 'value' => '<div class="band double-inner-pad clearfix"><div id="left-box" class="four-fifth md-three-fourth sm-two-third xs-one-whole">'); $fields[] = array('label' => null, 'type' => 'hidden', 'value' => $referer, 'name' => 'from'); $fields[] = array('label' => null, 'type' => 'hidden', 'value' => $item->bid, 'name' => 'bid'); $lmod = new Language_model(); if ($id_page == 0 || $bid == 'x3') { // advanced editing // area $amod = new Area_model(); $fields[] = array('label' => null, 'type' => 'html', 'value' => '<div class="band clearfix"><div class="one-fourth sm-one-half pad-right xs-one-whole xs-pad-none">'); $fields[] = array('label' => _AREA, 'type' => 'select', 'value' => $item->id_area, 'options' => array($amod->get_areas(), 'id', 'name'), 'name' => 'id_area', 'extra' => 'class="large spinner spin2"'); $fields[] = array('label' => null, 'type' => 'hidden', 'value' => 'module|' . BASE_URL . 'articles/refresh_module|id_area', 'name' => 'spinner1_data'); $fields[] = array('label' => null, 'type' => 'html', 'value' => '</div><div class="one-fourth sm-one-half pad-right xs-one-whole sm-pad-none">'); // language $fields[] = array('label' => _LANGUAGE, 'type' => 'select', 'value' => $item->lang, 'options' => array($lmod->get_languages(), 'code', 'language'), 'name' => 'lang', 'extra' => 'class="large spinner spin2"'); // value = id_to_update|url|ids_to_get $fields[] = array('label' => null, 'type' => 'hidden', 'value' => 'code_context|' . BASE_URL . 'articles/refresh_context|id_area|lang', 'name' => 'spinner2_data'); $fields[] = array('label' => null, 'type' => 'html', 'value' => '</div><div class="one-fourth sm-one-half pad-right xs-one-whole xs-pad-none">'); // contexts $cmod = new Context_model(); $fields[] = array('label' => _CONTEXT, 'type' => 'select', 'value' => $item->code_context, 'options' => array($cmod->get_contexts($item->id_area, $item->lang), 'code', 'name'), 'name' => 'code_context', 'extra' => 'class="large spin2"'); $fields[] = array('label' => null, 'type' => 'hidden', 'value' => $item->code_context, 'name' => 'old_context'); // value = id_to_update|url|ids_to_get $fields[] = array('label' => null, 'type' => 'hidden', 'value' => 'id_page|' . BASE_URL . 'articles/refresh_pages|id_area|lang|code_context', 'name' => 'spinner3_data'); $fields[] = array('label' => null, 'type' => 'html', 'value' => '</div><div class="one-fourth sm-one-half xs-one-whole">'); $fields[] = array('label' => _PAGE, 'type' => 'select', 'value' => $item->id_page, 'options' => $item->id_page ? array($cmod->get_pages($item->id_area, $item->lang, 1), 'id', 'name') : array(), 'name' => 'id_page', 'extra' => 'class="large"'); $fields[] = array('label' => null, 'type' => 'html', 'value' => '</div></div>'); } else { // simple editing // hidden fields $fields[] = array('label' => null, 'type' => 'hidden', 'value' => $item->id_area, 'name' => 'id_area'); $fields[] = array('label' => null, 'type' => 'hidden', 'value' => $item->lang, 'name' => 'lang'); $fields[] = array('label' => null, 'type' => 'hidden', 'value' => $item->code_context, 'name' => 'code_context'); $fields[] = array('label' => null, 'type' => 'hidden', 'value' => $item->code_context, 'name' => 'old_context'); $fields[] = array('label' => null, 'type' => 'hidden', 'value' => $item->id_page, 'name' => 'id_page'); } // classification section $fields[] = array('label' => _NAME, 'type' => 'text', 'value' => stripslashes($item->name), 'name' => 'name', 'rule' => 'required', 'extra' => 'class="large"'); // content $fields[] = array('label' => _CONTENT, 'type' => 'textarea', 'value' => $item->content, 'name' => 'content'); if (EDITOR_SCRIPTS) { // content $fields[] = array('label' => _SCRIPT, 'type' => 'textarea', 'value' => htmlentities($item->js), 'name' => 'js', 'extra' => 'class="NoEditor"', 'suggestion' => _SCRIPT_MSG); } else { $fields[] = array('label' => null, 'type' => 'hidden', 'value' => $item->js, 'name' => 'js'); } // plugin section $fields[] = array('label' => null, 'type' => 'html', 'value' => '<h3>' . _PLUGIN . '</h3> <div class="band clearfix"><div class="one-half pad-right">'); $plugin = new X4Plugin_model(); // for APC $fields[] = array('label' => null, 'type' => 'hidden', 'value' => $item->module, 'name' => 'old_module'); $fields[] = array('label' => null, 'type' => 'hidden', 'value' => $item->param, 'name' => 'old_param'); $fields[] = array('label' => _MODULE, 'type' => 'select', 'value' => $item->module, 'options' => array($plugin->get_modules($id_area, 0), 'name', 'description', ''), 'name' => 'module', 'extra' => 'class="large"'); $fields[] = array('label' => null, 'type' => 'html', 'value' => '</div><div class="one-half pad-left">'); $fields[] = array('label' => _PARAM, 'type' => 'text', 'value' => $item->param, 'name' => 'param', 'extra' => 'class="large"'); $fields[] = array('label' => null, 'type' => 'html', 'value' => '</div></div></div> <div id="right-box" class="one-fifth md-one-fourth sm-one-third xs-one-whole xs-hidden">'); // time window section $fields[] = array('label' => null, 'type' => 'html', 'value' => '<h2>' . _TIME_WINDOW . '</h2><div class="band clearfix inner-pad"><div class="one-half sm-one-whole">'); $fields[] = array('label' => null, 'type' => 'hidden', 'value' => $item->date_in, 'name' => 'old_date_in'); $fields[] = array('label' => _START_DATE, 'type' => 'text', 'value' => date('Y-m-d', $item->date_in), 'name' => 'date_in', 'rule' => 'required|date', 'extra' => 'class="date date_toggled large"'); $fields[] = array('label' => null, 'type' => 'html', 'value' => '</div><div class="one-half sm-one-whole">'); $fields[] = array('label' => _END_DATE, 'type' => 'text', 'value' => $item->date_out == 0 ? '' : date('Y-m-d', $item->date_out), 'name' => 'date_out', 'rule' => 'date', 'extra' => 'class="date date_toggled large"', 'suggestion' => _NO_END_MSG); // classification section $fields[] = array('label' => null, 'type' => 'html', 'value' => '</div></div><h2>' . _ORGANIZATION . '</h2>'); // categories $camod = new Category_model(); $fields[] = array('label' => _CATEGORY, 'type' => 'select', 'value' => $item->category, 'options' => array($camod->get_categories($item->id_area, $item->lang), 'name', 'description', 0), 'name' => 'category', 'extra' => 'class="large"'); // xkeys $fields[] = array('label' => _KEYS, 'type' => 'text', 'value' => $item->xkeys, 'name' => 'xkeys', 'extra' => 'class="large"'); // tags $fields[] = array('label' => _TAGS, 'type' => 'text', 'value' => $item->tags, 'name' => 'tags', 'extra' => 'class="large"'); // author $fields[] = array('label' => _AUTHOR, 'type' => 'text', 'value' => empty($item->author) ? $_SESSION['mail'] : $item->author, 'name' => 'author', 'rule' => 'required', 'extra' => 'class="large"'); if (EDITOR_OPTIONS) { // options section $fields[] = array('label' => null, 'type' => 'html', 'value' => '<h2>' . _OPTIONS . '</h2> <div class="band clearfix"> <div class="one-half sm-one-whole">'); $fields[] = array('label' => _SHOW_AUTHOR, 'type' => 'checkbox', 'value' => $item->show_author, 'name' => 'show_author', 'checked' => $item->show_author); $fields[] = array('label' => null, 'type' => 'html', 'value' => '</div><div class="one-half sm-one-whole">'); $fields[] = array('label' => _SHOW_DATE, 'type' => 'checkbox', 'value' => $item->show_date, 'name' => 'show_date', 'checked' => $item->show_date); $fields[] = array('label' => null, 'type' => 'html', 'value' => '</div><div class="one-half sm-one-whole">'); $fields[] = array('label' => _SHOW_TAGS, 'type' => 'checkbox', 'value' => $item->show_tags, 'name' => 'show_tags', 'checked' => $item->show_tags); $fields[] = array('label' => null, 'type' => 'html', 'value' => '</div><div class="one-half sm-one-whole">'); $fields[] = array('label' => _SHOW_ACTIONS, 'type' => 'checkbox', 'value' => $item->show_actions, 'name' => 'show_actions', 'checked' => $item->show_actions); $fields[] = array('label' => null, 'type' => 'html', 'value' => '</div></div>'); } $fields[] = array('label' => null, 'type' => 'html', 'value' => '</div></div>'); /* // TODO: maybe in the future $fields[] = array( 'label' => _SCHEMA, 'type' => 'textarea', 'value' => $item->xschema, 'name' => 'xschema', 'extra' => 'class="mceNoEditor"' ); */ // if submitted if (X4Route_core::$post) { $e = X4Validation_helper::form($fields, 'editor'); if ($e) { $this->editing($item, $_POST); } else { $this->notice($fields); } die; } // content $view = new X4View_core('tabber'); $view->tabs = array(); $view->down = new X4View_core('editor'); $view->down->close = false; // Set the navbar $page = $this->get_page('articles/edit'); $ref = isset($_SESSION['referer']) ? $_SESSION['referer'] : 'index/' . $id_area . '/' . $lang; $navbar = array($this->site->get_bredcrumb($page), array('articles' => $ref)); $pmod = new Page_model(); if ($id_page && $bid != 'x3') { // simple editing $page = $pmod->get_by_id($id_page); $view->title = _CONTENT_EDITOR . ' <a class="bta" href="' . BASE_URL . 'pages/index/' . $page->id_area . '/' . $page->lang . '/' . $page->xfrom . '/1" title="' . _GO_BACK . '">' . stripslashes($page->name) . '</a>' . _TRAIT_ . $lang; $view->down->js = ''; } else { // generic back $back = '<a class="bta" href="' . BASE_URL . 'pages/index/' . $id_area . '/' . $lang . '/home/1" title="' . _GO_BACK . '">' . _PAGES . '</a>'; if ($bid) { if ($item->id_page) { // back to the right page $page = $pmod->get_by_id($item->id_page); $back = ADVANCED_EDITING ? '<a class="bta" href="' . BASE_URL . 'sections/compose/' . $page->id . '" title="' . _GO_BACK . '">' . stripslashes($page->name) . '</a>' : '<a class="bta" href="' . BASE_URL . 'pages/index/' . $page->id_area . '/' . $page->lang . '/' . $page->xfrom . '/1" title="' . _GO_BACK . '">' . stripslashes($page->name) . '</a>'; } $view->title = $back . _TRAIT_ . _EDIT_ARTICLE . _TRAIT_ . $lang; } else { $view->title = $back . _TRAIT_ . _ADD_ARTICLE . _TRAIT_ . $lang; } $view->down->js = ' <script> window.addEvent("domready", function() { if ($chk($("spinner1_data"))) { var sdata = $("spinner1_data").get("value").split("|"); spinnerize(sdata, ".spinner"); } if ($chk($("spinner2_data"))) { var sdata = $("spinner2_data").get("value").split("|"); spinnerize(sdata, ".spinner"); } if ($chk($("spinner3_data"))) { var sdata = $("spinner3_data").get("value").split("|"); spinnerize(sdata, ".spin2"); } }); </script> '; } $view->down->js .= ' <script> window.addEvent("domready", function() { X3.content("filters","articles/filter/' . $id_area . '/' . $lang . '", "' . addslashes(X4Utils_helper::navbar($navbar, ' . ')) . '"); buttonize("tabber", "bta", "topic"); pickerize(1); $("module").addEvent("change", function(event, target){ event.preventDefault(); v = this.get("value"); if (v.length == 0) { $("param").set("value", ""); } else { X3.modal("", "' . _ARTICLE_PARAM_SETTING . '", "' . BASE_URL . 'articles/param/' . $id_area . '/' . $lang . '/"+v); } }); $("param").addEvent("focus", function(event, target){ event.preventDefault(); m = $("module").get("value"); if (m != "") { v = this.get("value"); X3.modal("", "' . _ARTICLE_PARAM_SETTING . '", "' . BASE_URL . 'articles/param/' . $id_area . '/' . $lang . '/"+m+"/"+v); } }); }); </script>'; // form builder $view->down->form = X4Form_helper::doform('editor', $_SERVER["REQUEST_URI"], $fields, array(_RESET, _SUBMIT, 'buttons'), 'post', '', 'onclick="setForm(\'editor\', \'content\');"'); $view->down->tinymce = new X4View_core('tinymce'); $view->down->tinymce->id_area = $id_area; // rtl if ($lmod->rtl($lang)) { $view->down->tinymce->rtl = 1; } $view->render(TRUE); }
/** * Delete category * * @access private * @param integer $id Category ID * @param object $obj Category Obj * @return void */ private function deleting($id, $obj) { $msg = null; // check permissions $msg = AdmUtils_helper::chk_priv_level($_SESSION['xuid'], 'categories', $id, 4); if (is_null($msg)) { // do action $mod = new Category_model(); $result = $mod->delete($id); // set message $msg = AdmUtils_helper::set_msg($result); // clear useless permissions if ($result[1]) { $perm = new Permission_model(); $perm->deleting_by_what('categories', $id); // set what update $msg->update[] = array('element' => 'topic', 'url' => BASE_URL . 'categories/index/' . $obj->id_area . '/' . $obj->lang . '/' . $obj->tag, 'title' => null); } } $this->response($msg); }
public function fetchAll() { $category = new Category_model(); $results = $category->fetchAll(); return $results; }
function get_menu() { // menu cats will be needed each time full page refresh is made $u = new Category_model($this->template, $this->query_string); $u->index(); return true; }
public function add() { $u = new Category_model($this->template, $this->router->query_string); $u->add($this->router->id); $this->template->render("add_category_result", "json"); }