CMS  Version 3.9
component_page_list.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 
38 Fakoli::using("role");
39 Fakoli::usingFeature("data_view", "context_menu");
40 
42 {
43  var $table;
44  var $pages;
46 
48  {
49  if ($component)
50  {
51  $this->pages = $component->ComponentPages();
52  }
53  else
54  {
55  $this->pages = Query::create(ComponentPage, "ORDER BY component, identifier")->execute();
56  }
57 
58  $this->table = new DataListView($this->pages, "component_pages");
59  $this->table->selector();
60 
61  $contextMenu = $this->table->commandMenu();
62  $contextMenu->command("component_enable", "Enable Pages", "new ComponentPageList().setEnabled(1)", false)
63  ->command("component_disable", "Disable Pages", "new ComponentPageList().setEnabled(0)", false);
64  //->command("component_site", "Set Page Template", "new ComponentPageList().templatePopup(document.id('component_pages').getSelectedValues())", false)
65  //->command("component_roles", "Set Page Roles", "new ComponentPageList().rolePopupMulti(document.id('component_pages').getSelectedValues())", false)
66  //->command("component_site", "Set Page Site", "new ComponentPageList().sitePopup(document.id('component_pages').getSelectedValues())", false);
67 
68  if (!$component)
69  {
70  $this->table->column("Component", array($this, formatComponent), true);
71  }
72 
73  $this->table->column("Page", "<a href='/admin/component_page_form?component_page_id={component_page_id}'>{identifier}</a>", true, "width: 50%")
74  ->column("Page Title", "{page_title}")
75  ->column("Enabled", array($this, formatEnabled), false, "width: 10%; text-align: center");
76  $this->table->sortable = true;
77  $this->table->filter = true;
78  $this->table->pageSize = 20;
79 
80  //$this->templates = $this->readTemplates();
81  }
82 
84  {
86  $component = $components[$page->component];
87  return "<a href='/admin/component_form?component_id={$component->component_id}'>{$component->name}</a>";
88  }
89 
90  function formatEnabled($page)
91  {
92  $img = $page->enabled ? "on.png" : "off.png";
93  $alt = $page->enabled ? "Enabled" : "Disabled";
94 
95  return "<img src='/fakoli/images/$img' id='enable_{$page->component_page_id}' alt='$alt' style='display: inline-block; vertical-align: middle; border: none; cursor: pointer' onclick='new ComponentPageList().toggleEnabled(this, {$page->component_page_id})'/>";
96  }
97 
99  {
100  $out = "<select onchange='new ComponentPageList().changeTemplate(this.value, {$page->component_page_id})' id='template_{$page->component_page_id}'>\n";
101  $out .= "<option value=''></option>\n";
102  foreach($this->templates as $template)
103  {
104  $out .= "<option value='$template'";
105  if ($page->template == $template)
106  {
107  $out .= " selected";
108  }
109  $out .= ">$template</option>";
110  }
111  $out .= "</select>";
112 
113  return $out;
114  }
115 
116  function formatRole($page)
117  {
118  $out = "<button onclick=\"new ComponentPageList().rolePopup('roles_{$page->component_page_id}', {$page->component_page_id}, this); return false\" class='button small' style='float: right'>...</button>";
119  $out .= "<span id=\"roles_{$page->component_page_id}\">$page->role</span>";
120 
121  return $out;
122  }
123 
124  function writeScript()
125  {
128 
129  global $dialogs;
130  ob_start();
131 ?>
132 <div class="dialog" id="rolePopup" style="width: 200px">
133  <div class="dialog_header" id="rolePopupHeader">
134  <div style="padding: 4px;">
135  <div style="float: right">&nbsp;<a id='closeRolePopup'">Close &times;</a></div>
136  <span"style="font-weight: bold">Roles</span>
137  </div>
138  </div>
139  <div class="dialog_body">
140 <?
141 foreach($roles as $role => $name)
142 {
143 ?>
144  <input type="checkbox" id="role_<?echo $role?>" value="<?echo $role?>"/>&nbsp;<?echo $name?><br/>
145 <?
146 }
147 ?>
148  <button class='button' style='float: right; margin-bottom: 4px' onclick='new ComponentPageList().updateRoles()'>Update Roles</button>
149  </div>
150 </div>
151 <div class="dialog" id="sitePopup" style="width: 200px">
152  <div class="dialog_header" id="sitePopupHeader">
153  <div style="padding: 4px;">
154  <div style="float: right">&nbsp;<a id='closeSitePopup'">Close &times;</a></div>
155  <span"style="font-weight: bold">Sites</span>
156  </div>
157  </div>
158  <div class="dialog_body">
159  <label for="site_id">Select Site: </label>
160  <select id="site_id" name="site_id">
161 <?
162  foreach($sites as $s)
163  {
164  option($s->site_id, $s->site_name, 0);
165  }
166 ?>
167  </select><br/>
168  <button class='button' style='float: right; margin-bottom: 4px' onclick='new ComponentPageList().updateSites()'>Update Templates</button>
169  </div>
170 </div>
171 <div class="dialog" id="templatePopup" style="width: 200px">
172  <div class="dialog_header" id="templatePopupHeader">
173  <div style="padding: 4px;">
174  <div style="float: right">&nbsp;<a id='closeTemplatePopup'">Close &times;</a></div>
175  <span"style="font-weight: bold">Templates</span>
176  </div>
177  </div>
178  <div class="dialog_body">
179  <label for="template_id">Select Template: </label>
180  <select id='template_id'>
181  <option value=''></option>
182 <?
183 
184  foreach($this->templates as $template)
185  {
186  option($template, $template, "");
187  }
188 ?>
189  </select><br/>
190  <button class='button' style='float: right; margin-bottom: 4px' onclick='new ComponentPageList().updateTemplates()'>Update Templates</button>
191  </div>
192 </div>
193 <?
194  $dialogs .= ob_get_contents();
195  ob_end_clean();
196 
197  ob_start();
198 ?>
199 <script type='text/javascript' src="/components/component/js/component_page_list.js"></script>
200 <?
201  $script = ob_get_contents();
202  ob_end_clean();
203  $script .= $this->table->writeScript();
204  return $script;
205  }
206 
207  function drawView()
208  {
209  return $this->table->drawView();
210  }
211 
212  function readTemplates()
213  {
214  global $config;
215 
216  $home = $config["homedir"] . DIRECTORY_SEPARATOR . "templates";
217 
218  trace("Scanning Templates", 3);
219 
220  $options = array();
221 
222  $folders = array("$dir");
223 
224  while(($dir = array_shift($folders)) !== null)
225  {
226  $path = "$home/$dir";
227 
228  trace("Reading $path", 3);
229 
230  $handle = opendir($path);
231  if (!$handle)
232  {
233  trace("Directory read failed for $path", 3);
234  continue;
235  }
236 
237  while(false !== ($file = readdir($handle)))
238  {
239  trace("Checking $file", 4);
240 
241  if ($file != "." &&
242  $file != ".." &&
243  $file != ".svn" &&
244  $file != "CVS")
245  {
246  $f = "$path/$file";
247  $l = ($dir != '') ? "$dir/$file" : $file;
248 
249  if (is_dir($f))
250  {
251  array_push($folders, $l);
252  }
253  else if (preg_match('/.tpl$/i', $file))
254  {
255  $options[] = $l;
256  }
257  }
258  }
259  closedir($handle);
260  }
261  return $options;
262  }
263 
264 }
265 
267 ?>
& nbsp
Definition: index.inc:49
$page
Definition: help.inc:39
$component
Definition: help.inc:38
$out
Definition: page.inc:66
if(! $page) $path
Definition: page.inc:57
$components
Definition: tree.inc:41
$helpTree style
Definition: tree.inc:46
$dir
Definition: delete.inc:44
$file
Definition: delete.inc:47
$f
Definition: download.inc:46
$name
Definition: upload.inc:54
ComponentPageListView($component=null)
static usingFeature()
Uses the specified framework feature(s).
Definition: core.inc:388
static getComponents()
Retrieve an array of all the currently enabled components, indexed by component name.
Definition: core.inc:206
static using()
Import the datamodels, views and manifest for the specified component(s).
Definition: core.inc:116
Definition: site.inc:40
static getSites()
Definition: site.inc:141
static getRolesArray()
Retrieves the array of roles and their names for the current site for use in a CMS form.
Definition: role.inc:75
$sites
Definition: event_edit.inc:83
global $config
Definition: import.inc:4
$role
Definition: role_form.inc:41
if(php_sapi_name() !="cli") $home
Definition: run.php:39