CMS  Version 3.9
site_map_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 /**************************************************************
35  *
36  * Description: Update/edit site map page for the
37  * site hierarchy chart/tree. Site map pages cannot
38  * be added through this interface b/c they are brought
39  * in using a scan feature that gets all pages and
40  * component pages.
41  *
42  * @author Janice Gallant for Sonjara, Inc.
43  *
44  * date: 10/8/2010
45  *
46  ****************************************************************/
47 
48 Fakoli::using("site_map", "field_renderers", "page");
49 Fakoli::usingFeature("auto_form");
50 
51 $menu_item = "Site Map";
52 
53 $site_map_id = checkNumeric($_GET["site_map_id"]);
54 $parent_site_map_id = checkNumeric($_GET["parent_site_map_id"]);
55 
56 if(!$site_map_id)
57  redirect("/admin/site_map");
58 
60 
61 $title = "Edit Details for {$siteMapPage->url}";
62 
63 $form = new AutoForm($siteMapPage);
64 
65 $redirect = "/admin/site_map";
66 
67 $form->button("Cancel", $redirect);
68 $form->submitLabel = "Save Changes";
69 $form->hide("role", "page_title", "sort_order");
70 $form->readOnly("url");
71 
72 $urlSelect = new CMSLinkSelectFieldRenderer($form, "parent_url", "Parent Page");
73 
74 $subpages = $siteMapPage->Children("ORDER BY sort_order");
75 if(count($subpages) > 1)
76 {
77  $table = new DataListView($subpages, "site_map_subpages");
78  $table->column("URL", array(SiteMapHelper, formatURL), false);
79 
80  $table->filter = false;
81  $table->sortable = false;
82  $table->paginate = false;
83  $table->cssStyle = "width: 50%";
84  $table->enableDragReorder("/action/site_map/reorder_site_map");
85  $table->dragText = "<span style='font-size: 10px'>Click and drag to change the order of the pages</span>";
86 }
87 
88 if ($method == "POST")
89 {
91  {
92  $form->save();
93  redirect($redirect);
94  }
95  else
96  $form->msg = "<warning>Invalid tree. A page cannot have a parent that is also a child.</warning>";
97 }
98 
99 
100 $script = $form->writeScript();
101 
102 if($table)
103 {
104  $script .= $table->writeScript();
105 }
106 
107 $form->drawForm();
108 
109 if($table)
110 {
111  echo "<h4>SubPages</h4>\n";
112  $table->drawView();
113 }
114 
115 /*
116  * Validate that the tree ancestry and descendents are valid. That is,
117  * that no child of this node is also a parent and that no parent
118  * is also a child and the parent is not the same identifier as
119  * the node.
120  */
122 {
123  global $_POST;
124  $valid = true;
125 
126  $newParent = $_POST["parent_url"];
127 
128  // don't check if no change in parent
129  if($siteMapPage->parent != $newParent)
130  {
131  if($siteMapPage->parent_url == $newParent)
132  $valid = false;
133  else
134  $valid = validateDescendents($siteMapPage, $newParent, $valid);
135  }
136  return $valid;
137 }
138 
139 
140 
141 /*
142  * Recursively create an array of all child pages of $page down to the
143  * leaf page. Check if any of the child pages' identifier is the
144  * same as the newly selected parent.
145  */
146 function validateDescendents($siteMapPage, $newParent, &$valid)
147 {
148  $children = $siteMapPage->Children();
149 
150  if($children)
151  {
152  foreach($children as $child)
153  {
154  trace("validateDescendents:: child identifier {$child->identifier}", 3);
155  if($child->identifier == $newParent)
156  $valid = false;
157  else
158  validateDescendents($child, $newParent, $valid);
159  }
160  }
161  return $valid;
162 }
163 
164 
165 ?>
$_POST["owner_id"]
Definition: blog_form.inc:54
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
$method
Pull out a simple reference to the request method.
Definition: core.inc:1573
if(count($subpages) > 1) if($method=="POST") $script
$form
$parent_site_map_id
$urlSelect
$siteMapPage
validateDescendents($siteMapPage, $newParent, &$valid)
$redirect
$subpages
$menu_item
if($table) validateSiteMapTree($siteMapPage)
$title
$site_map_id