Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
layout_manager_edit_fns.inc
1 <?php
17 require_once SQ_INCLUDE_PATH.'/asset_edit/asset_edit_fns.inc';
18 require_once SQ_INCLUDE_PATH.'/asset_edit_interface.inc';
19 
33 {
34 
35 
41  function __construct()
42  {
43  $this->static_screens['details']['force_unlock'] = FALSE;
44  parent::__construct();
45 
46  unset($this->static_screens['settings']);
47  unset($this->static_screens['preview']);
48  unset($this->static_screens['lookupValues']);
49  unset($this->static_screens['web_paths']);
50  unset($this->static_screens['metadata']);
51  unset($this->static_screens['metadataSchemas']);
52  unset($this->static_screens['workflow']);
53  unset($this->static_screens['tagging']);
54  unset($this->static_screens['roles']);
55  unset($this->static_screens['permissions']);
56  unset($this->static_screens['dependants']);
57  unset($this->static_screens['linking']);
58  unset($this->static_screens['layouts']);
59 
60  }//end constructor
61 
62 
73  public function paintAddLayout(Layout_Manager $asset, Backend_Outputter $o, $prefix)
74  {
75  if (!$asset->writeAccess('attributes')) return FALSE;
76 
77  $types = $GLOBALS['SQ_SYSTEM']->am->getTypeList();
78  asset_type_chooser($prefix.'_layouts', TRUE, Array());
79 
80  return TRUE;
81 
82  }//end paintAddLayout()
83 
84 
95  public function processAddLayout(Layout_Manager $asset, Backend_Outputter $o, $prefix)
96  {
97  if (isset($_POST[$prefix.'_layouts']) && !empty($_POST[$prefix.'_layouts'])) {
98  $layouts = $asset->attr('layouts');
99  foreach ($_POST[$prefix.'_layouts'] as $type_code) {
100  // this should never happen
101  if (in_array($type_code, $asset->attr('layouts'))) {
102  return FALSE;
103  }
104  if (!empty($type_code)) $layouts[$type_code] = Array();
105  }
106  $asset->setAttrValue('layouts', $layouts);
107  $asset->saveAttributes();
108  }
109  return TRUE;
110 
111  }//end processAddLayout()
112 
113 
124  public function paintEditLayouts(Layout_Manager $asset, Backend_Outputter $o, $prefix)
125  {
126  $write_access = $asset->writeAccess('attributes');
127 
128  $layouts = $asset->attr('layouts');
129  if (empty($layouts)) {
130  $o->note(translate('no_layouts_defined'));
131  return FALSE;
132  }
133 
134  // print the current type_codes that we have defined in the manager
135  foreach ($layouts as $type_code => $screens) {
136 
137  $uc_type_code = ucwords(str_replace('_', ' ', $type_code));
138  $o->openSection($uc_type_code);
139 
140  if ($write_access) {
141  $o->openField('');
142 
143  check_box($prefix.'_remove_type_code['.$type_code.']');
144  label(translate('remove_customisations_for', $uc_type_code), $prefix.'_remove_type_code['.$type_code.']');
145 
146  $o->closeField();
147  }
148 
149  $o->openField('');
150 
151  if (empty($screens)) {
152  $o->note(translate('no_layouts_for_screens', $uc_type_code));
153  } else {
154  ?>
155  <table class="sq-backend-table">
156  <tr>
157  <td class="sq-backend-table-header" width="33%"><?php echo translate('screen_name'); ?></td>
158  <td class="sq-backend-table-header" width="33%"><?php echo translate('layout'); ?></td>
159  <?php if ($write_access) {
160  ?>
161  <td align="center" class="sq-backend-table-header" width="33%"><?php echo translate('remove'); ?></td>
162  <?php }
163  ?>
164  </tr>
165 
166  <?php
167 
168  // print the current screens that are defined for this type_code
169  foreach ($screens as $screen => $assetid) {
170  ?>
171  <tr>
172  <td class="sq-backend-table-cell">
173  <?php echo ucfirst($screen) ?>
174  </td>
175  <td class="sq-backend-table-cell">
176  <?php
177  if ($write_access) {
178  asset_finder($prefix.'_find['.$type_code.'@'.$screen.']', $assetid, Array('layout' => 'I'));
179  } else {
180  if (empty($assetid)) {
181  echo '<em>'.translate('none').'</em>';
182  } else {
183  echo get_asset_tag_line($assetid);
184  }
185  }
186  ?>
187  </td>
188  <?php if ($write_access) {
189  ?>
190  <td align="center" class="sq-backend-table-cell">
191  <?php check_box($prefix.'_remove_screen['.$type_code.'@'.$screen.']'); ?>
192  </td>
193  <?php }
194  ?>
195  </tr>
196  <?php
197  }//end foreach screen
198 
199  ?>
200  </table>
201  <?php
202  }//end else
203 
204  if ($write_access) {
205  ?>
206  <br /><?php echo translate('add_layout'); ?>:
207  <?php
208  $ei = new Asset_Edit_Interface($type_code);
209 
210  $GLOBALS['SQ_SYSTEM']->am->includeAsset($type_code);
211  $as = new $type_code();
212  $ef = $as->getEditFns();
213 
214  $screens = Array(''); // first option is blank
215  foreach (array_keys($ef->static_screens) as $screen) {
216  $screens[] = $screen;
217  }
218  foreach (array_keys($ei->getScreens()) as $screen) {
219  $screens[] = $screen;
220  }
221 
222  // remove any screens that have already been defined
223  $screens = array_unique(array_diff($screens, array_keys($layouts[$type_code])));
224 
225  $uc_screens = Array();
226  foreach ($screens as $screen) {
227  $uc_screens[$screen] = ucfirst($screen);
228  }
229  // print a box to add more screens
230  combo_box($prefix.'_screens['.$type_code.']', $uc_screens, FALSE, Array());
231  }
232 
233  $o->closeField();
234  $o->closeSection();
235 
236  }//end foreach type_code
237 
238  return $write_access;
239 
240  }//end paintEditLayouts()
241 
242 
253  public function processEditLayouts(Layout_Manager $asset, Backend_Outputter $o, $prefix)
254  {
255  $save = FALSE;
256 
257  // get any new screens added to a type code
258  if (isset($_POST[$prefix.'_screens'])) {
259  $layouts = $asset->attr('layouts');
260  foreach ($_POST[$prefix.'_screens'] as $type_code => $screen) {
261  if (!$screen) continue;
262  if (!isset($layouts[$type_code])) {
263  $layouts[$type_code] = Array();
264  }
265  $layouts[$type_code][$screen] = 0; // set assetid to 0
266  $save = TRUE;
267  }
268  }
269  // get any layouts that have been allocated to a screen
270  if (isset($_POST[$prefix.'_find'])) {
271  foreach ($_POST[$prefix.'_find'] as $info => $assetid) {
272  if (!isset($assetid['assetid']) || !$assetid['assetid']) {
273  continue;
274  }
275  list($type_code, $screen) = explode('@', $info);
276  $layouts[$type_code][$screen] = $assetid['assetid'];
277  $save = TRUE;
278  }
279  }
280  // check to see if any screens have been flagged for removal
281  // which will ignore any uncommited customisations to the screen
282  if (isset($_POST[$prefix.'_remove_screen'])) {
283  foreach (array_keys($_POST[$prefix.'_remove_screen']) as $info) {
284  list($type_code, $screen) = explode('@', $info);
285  unset($layouts[$type_code][$screen]);
286  $save = TRUE;
287  }
288  }
289  // remove all customisations
290  // which will overide any uncommited customisations, and any flagged removal of screens
291  if (isset($_POST[$prefix.'_remove_type_code'])) {
292  foreach (array_keys($_POST[$prefix.'_remove_type_code']) as $type_code) {
293  unset($layouts[$type_code]);
294  $save = TRUE;
295  }
296  }
297  // save only if we need to
298  if ($save) {
299  $asset->setAttrValue('layouts', $layouts);
300  $asset->saveAttributes();
301  }
302 
303  return TRUE;
304 
305  }//end processEditLayouts()
306 
307 
308 }//end class
309 ?>