CMS  Version 3.9
menu_item_form.inc
Go to the documentation of this file.
1 <?php
2 /**************************************************************
3 
4  Copyright (c) 2010 Sonjara, Inc
5 
6  Permission is hereby granted, free of charge, to any person
7  obtaining a copy of this software and associated documentation
8  files (the "Software"), to deal in the Software without
9  restriction, including without limitation the rights to use,
10  copy, modify, merge, publish, distribute, sublicense, and/or sell
11  copies of the Software, and to permit persons to whom the
12  Software is furnished to do so, subject to the following
13  conditions:
14 
15  The above copyright notice and this permission notice shall be
16  included in all copies or substantial portions of the Software.
17 
18  Except as contained in this notice, the name(s) of the above
19  copyright holders shall not be used in advertising or otherwise
20  to promote the sale, use or other dealings in this Software
21  without prior written authorization.
22 
23  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
25  OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
27  HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
28  WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
29  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
30  OTHER DEALINGS IN THE SOFTWARE.
31 
32 *****************************************************************/
33 
34 Fakoli::using("menu", "site", "role", "page", "field_renderers");
35 Fakoli::usingFeature("auto_form", "data_view");
36 
37 require_once "include/menu_tabs.inc";
38 
39 $menu_item = "Menus";
40 
41 $menu_id = checkNumeric($_GET["menu_id"]);
42 $menu_item_id = checkNumeric($_GET["menu_item_id"]);
43 
44 $parent_id = checkNumeric($_GET["parent_id"]);
45 
47 if ($menu_item_id)
48 {
49  $menuItem->load($menu_item_id);
50 }
51 else
52 {
53  $menuItem->parent_id = $parent_id;
54  $menuItem->menu_id = $menu_id;
55 }
56 
57 $menu = $menuItem->Menu();
58 $site = $menu->Site();
59 
61 $tabs->page = "menu_items";
62 
63 $form = new AutoForm($menuItem);
64 
65 $form->required("title");
66 //$form->allowDelete = true;
67 $form->hide("parent_id", "menu_id", "page_id", "identifier");
68 /*
69 $pageChoices = array("Content Pages" => array(), "Component Pages" => array());
70 
71 $contentPages = Query::create(Page, "ORDER BY page_title")->execute();
72 foreach($contentPages as $page)
73 {
74  $pageChoices["Content Pages"][$page->identifier] = $page->page_title;
75 }
76 $componentPages = Query::create(ComponentPage, "ORDER BY component, page_title")->execute();
77 foreach($componentPages as $page)
78 {
79  $pageChoices["Component Pages"][$page->identifier] = "$page->component: $page->page_title";
80 }
81 
82 $identifierSelect = new SelectFieldRenderer($form, "identifier", "Page", $pageChoices, null, true);
83 $identifierSelect = new CMSItemSelectFieldRenderer($form, "identifier", "Page", null);
84 */
85 
87 
88 
89 $roleList = new CheckListFieldRenderer($form, "role", "Role", SiteRole::getRolesArray());
91 
92 if ($method == "POST")
93 {
94  if ($_POST["reorder_subitems"])
95  {
96  $sort_nums = checkNumeric($_POST["m"]);
97 
98  foreach($sort_nums as $key => $sort_num)
99  {
100  $m = new MenuItem();
101  $m->filter = new InclusionFilter("menu_item_id", "sort_order");
102  $m->load($key);
103  $m->sort_order = $sort_num;
104  $m->save();
105  }
106  }
107  else
108  {
109  // Set up the page template for pages added via "or add new"
110  $pageTemplate = new Page();
111  $pageTemplate->identifier = codify(strtolower($_POST['autoform_add_page_id']));
112  $pageTemplate->author = "{$user->first_name} {$user->last_name}";
113  $pageTemplate->created_date = now();
114  $pageTemplate->site_id = $site->site_id;
115  $pageTemplate->template = $site->default_template;
116 
117  $pageSelect->templateItem = $pageTemplate;
118 
119  $form->save();
120  if ($form->deleted)
121  {
122  redirect("/admin/menu_items?menu_id={$menu->menu_id}");
123  }
124  else
125  {
126  if ($parent_id)
127  {
128  redirect("/admin/menu_item_form?menu_item_id={$parent_id}");
129  }
130  else
131  {
132  redirect("/admin/menu_items?menu_id={$form->data->menu_id}");
133  }
134  }
135  }
136 }
137 
138 if ($menu_item_id)
139 {
140  $title = "Edit Menu Item Details for {$menuItem->title}";
141 
142  $submenus = $menuItem->Children();
143  if(count($submenus) > 0) {
144  $form->allowDelete = false;
145  }
146  else {
147  $form->allowDelete = true;
148  }
149 
150  $form->button("Move Menu Item", "/admin/menu_move_form?menu_item_id=$menu_item_id&parent_id=$parent_id");
151  $form->button("Cancel", $redirect);
152 }
153 else
154 {
155  $title = "Add a new Menu Item";
156  $form->button("Cancel", $redirect);
157 }
158 
159 $script .= $form->writeScript();
160 
161 
162 
163 $tabs->writeHTML();
164 ?>
165 <div class="tab_border">
166 <h4><?echo $title?></h4>
167 <div id="breadcrumbs"><? echo menuAdminBreadcrumbs($menuItem, $menu)?></div>
168 <?
169 
170 $form->drawForm();
171 
172 if ($menu_item_id)
173 {
174 ?>
175 <h4>Sub-items</h4>
176 <?
177  if ($submenus)
178  {
179  $subTable = new DataListView($submenus, "submenus");
180  $subTable->column("Title", "<a href='/admin/menu_item_form?menu_item_id={menu_item_id}'>{title}</a>")
181  ->column("Link", "{url}");
182 
183  $subTable->enableDragReorder("/action/menu/reorder_submenus");
184  $subTable->dragText = "<span style='font-size: 10px'>Click and drag to reorder menu items</span>";
185  $subTable->emptyMessage = "<p><i>There are no sub-items associated with this menu item.</i></p>";
186  $script .= $subTable->writeScript();
187 
188  $subTable->drawView();
189  }
190 ?>
191 
192 <br/>
193 <a href="menu_item_form?menu_id=<?echo $menu->menu_id?>&parent_id=<?echo $menu_item_id?>" class="button">Add a new Sub-item</a>
194 </div>
195 <?
196 }
197 ?>
$redirect
$_POST["owner_id"]
Definition: blog_form.inc:54
$menu_id
$parent_id
$permissionsList
$urlSelect
$menu_item_id
$menuItem
$menu_item
$roleList
static usingFeature()
Uses the specified framework feature(s).
Definition: core.inc:388
static using()
Import the datamodels, views and manifest for the specified component(s).
Definition: core.inc:116
Definition: page.inc:43
static createPermissionsFieldRenderer($form, $field, $label="")
Definition: settings.inc:343
static getRolesArray()
Retrieves the array of roles and their names for the current site for use in a CMS form.
Definition: role.inc:75
$method
Pull out a simple reference to the request method.
Definition: core.inc:1573
menuTabs($key)
Definition: menu_tabs.inc:36
menuAdminBreadcrumbs($menuItem, $menu)
Definition: menu_tabs.inc:47