Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
design_area_access_history_edit_fns.inc
1 <?php
18 require_once SQ_CORE_PACKAGE_PATH.'/designs/design_area/design_area_edit_fns.inc';
19 
32 {
33 
34 
39  function __construct()
40  {
41  parent::__construct();
42 
43  }//end constructor
44 
45 
55  public function _processContents(Design_Area_Access_History $asset, Array &$contents)
56  {
57  if (!$this->_setVariables($asset, $contents)) {
58  return FALSE;
59  }
60 
61  // see if our page element has any sub's in it
62  foreach ($contents as $index => $element) {
63  if ($element['_type'] != 'TAG') continue;
64 
65  if ('asset' == $element['operation']) {
66  if (empty($element['contents'])) {
67  $element['contents'] = $this->_getDefaultContents($asset, 'asset');
68  }
69 
70  if (!$asset->setAttrValue('asset_contents', $element['contents'])) {
71  return FALSE;
72  }
73  // Now what we do is morph it so that this element doesn't contain all the un-necessary contents stuff
74  $contents[$index] = Array(
75  '_type' => 'TAG',
76  'attributes' => Array (),
77  'operation' => 'asset',
78  'self_terminating' => 1,
79  );
80  break;
81  }
82  }//end foreach
83 
84  $GLOBALS['SQ_PROCESSED_DESIGN_AREAS'][$asset->attr('id_name')] = TRUE;
85 
86 
87  return $asset->setAttrValue('contents', $contents);
88 
89  }//end _processContents()
90 
91 
103  {
104 
105  $write_access = $asset->writeAccess('attributes');
106  $asset_types = $asset->attr('asset_types');
107  $action_column = $write_access && count($asset_types);
108 
109  $types = $GLOBALS['SQ_SYSTEM']->am->getAssetTypes(TRUE);
110 
111  $print_types[''] = '-- Add New Type --';
112 
113  foreach ($types as $code => $details) {
114  $type_name = $details['name'];
115 
116  if (isset($asset_types[$code])) {
117  $present_types[$code] = $type_name;
118  } else {
119  $print_types[$code] = $type_name;
120  }
121  }
122 
123  asort($print_types);
124  $req_type_count = count($asset->request_types);
125  echo '
126  <table class="sq-backend-table">
127  <tr>
128  <th rowspan="2" style="vertical-align:bottom">Asset Type:</th>
129  <th colspan="'.$req_type_count.'">What to do with request parameters?</th>';
130 
131  if ($action_column) {
132  echo '<th rowspan="2" style="vertical-align:bottom; background-color: #ccc;">Delete?</th>';
133  }
134 
135  echo'</tr><tr>';
136 
137  // request type headers
138  foreach ($asset->request_types as $name) {
139  echo '<th>'.$name.'</th>';
140  }
141 
142  echo '</tr>';
143 
144  // now print the types that were specified previously
145  $even = FALSE;
146  foreach ($asset_types as $type => $query_req) {
147  $type_prefix = $prefix.'[types]['.$type.']';
148 
149  $row_class = $even ? 'class="alt"' : '';
150  $even = !$even;
151 
152  echo '<tr '.$row_class.'><td>';
153  echo get_asset_type_icon($type).$present_types[$type].'</td>';
154  foreach ($asset->request_types as $req_type => $req_name) {
155  echo '<td>';
156  if ($write_access) {
157  radio_button($type_prefix.'[req_type]', $req_type, $req_type==$query_req);
158  } else {
159  if ($req_type==$query_req) {
160  echo '<img src="'.sq_web_path('lib').'/web/images/tick.gif" alt="'.$req_name.'" />';
161  } else {
162  echo '&ndash;';
163  }
164  }
165  echo '</td>';
166  }
167 
168  if ($action_column) {
169  echo '<td>';
170  check_box($type_prefix.'[delete]');
171  echo '</td>';
172  }
173 
174  echo '</tr>';
175  }
176 
177  if ($write_access) {
178  // new type selector
179  echo '<tr class="alt"><td>';
180  echo combo_box($prefix.'[new][type_code]', $print_types, FALSE, '');
181  echo '</td>';
182 
183  // request types for new asset type
184  $new_radio_prefix = $prefix.'[new][require_query]';
185  $selected = TRUE;
186  foreach ($asset->request_types as $req_type => $name) {
187  echo '<td>';
188  radio_button($new_radio_prefix, $req_type, $selected);
189  echo '</td>';
190  $selected = FALSE;
191  }
192  if ($action_column) echo '<td>&nbsp;</td>';
193  echo '</tr>';
194  }
195 
196  if (empty($asset_types) && !$write_access) {
197  echo '<tr><td colspan="'.($req_type_count+1).'" style="color: red">No asset types have been chosen</td></tr>';
198  }
199 
200  echo '</table>';
201 
202  return $write_access;
203 
204  }//end paintAssetTypes()
205 
206 
218  {
219  $request_info = array_get_index($_REQUEST, $prefix, Array());
220 
221  if (empty($request_info)) return TRUE;
222 
223  $asset_types = $asset->attr('asset_types');
224 
225  // add a new asset type
226  $new_type = array_get_index($request_info, 'new');
227  if (!empty($new_type) && !empty($new_type['type_code'])) {
228  $updated_types[$new_type['type_code']] = $new_type['require_query'];
229  }
230 
231  // update the existing types
232  $existing_types = array_get_index($request_info, 'types');
233  if (!empty($existing_types) && is_array($existing_types)) {
234  foreach ($existing_types as $type => $params) {
235  if (!isset($params['delete']) && isset($asset_types[$type])) {
236  $updated_types[$type] = $params['req_type'];
237  }
238  }
239  }
240 
241  $asset->setAttrValue('asset_types', $updated_types);
242 
243  return TRUE;
244 
245  }//end processAssetTypes()
246 
247 
259  {
260  if ($asset->writeAccess('attributes')) {
261  multiple_asset_finder($prefix.'exclude_assets', $asset->attr('exclude_assets'), Array());
262  return TRUE;
263  } else {
264  $asset_ids = $asset->attr('exclude_assets');
265  $asset_names = $GLOBALS['SQ_SYSTEM']->am->getAssetInfo($asset_ids, Array(), TRUE, 'name');
266  foreach ($asset_names as $id => $name) {
267  echo get_asset_tag_line($id);
268  }
269  return FALSE;
270  }
271 
272  }//end paintExcludeAssets()
273 
274 
286  {
287  if (isset($_POST[$prefix.'exclude_assets'])) {
288  $asset_ids = Array();
289  foreach ( $_POST[$prefix.'exclude_assets'] as $asset_info ) {
290  if (!empty($asset_info['assetid'])) {
291  $asset_ids[] = $asset_info['assetid'];
292  }
293  }
294  return ($asset->setAttrValue('exclude_assets',$asset_ids));
295  } else {
296  return FALSE;
297  }
298 
299  }//end processExcludeAssets()
300 
301 
313  {
314  $types = $asset->attr('add_history_asset_types');
315  if ($asset->writeAccess('attributes')) {
316  // print the form fields
317  $display_values = Array('type_code' => Array(), 'inherit' => Array());
318  foreach ($types as $type => $inherit) {
319  $display_values['type_code'][] = $type;
320  $display_values['inherit'][] = $inherit;
321  }
322  asset_type_chooser($prefix.'_button_types', TRUE, $display_values, NULL, TRUE, TRUE);
323  return TRUE;
324  } else {
325  // print the read-only version
326  if (empty($types)) {
327  echo '<p class="sq-backend-warning">'.translate('no_asset_types_selected').'</p>';
328  } else {
329  $type_names = $GLOBALS['SQ_SYSTEM']->am->getTypeInfo(array_keys($types), 'name');
330  ?>
331  <table class="sq-backend-table">
332  <tr>
333  <th><?php echo translate('type') ?></th>
334  <th><?php echo translate('inherit_question') ?></th>
335  </tr>
336  <?php
337  $inherit_image_path = sq_web_path('lib').'/web/images/';
338  foreach ($types as $type => $inherit) {
339  $inherit_image = $inherit_image_path.($inherit ? 'tick' : 'cross').'.gif';
340  $inherit_alt = $inherit ? translate('yes') : translate('no');
341  ?>
342  <tr>
343  <td><?php
344  echo get_asset_type_icon($type);
345  echo $type_names[$type];
346  ?></td>
347  <td><img src="<?php echo $inherit_image; ?>" alt="<?php echo $inherit_alt; ?>" /></td>
348  </tr>
349  <?php
350  }
351  ?>
352  </table>
353  <?php
354  }
355  return FALSE;
356  }//end else - if write access to content
357 
358  }//end paintAddHistoryAssetTypes()
359 
360 
372  {
373  if (isset($_POST[$prefix.'_button_types'])) {
374  $existing_types = $asset->attr('add_history_asset_types');
375  $submitted_types = Array();
376  foreach ($_POST[$prefix.'_button_types']['type_code'] as $i => $type_code) {
377  if (!empty($type_code)) {
378  $submitted_types[$type_code] = $_POST[$prefix.'_button_types']['inherit'][$i];
379  }
380  }
381 
382  $asset->setAttrValue('add_history_asset_types', $submitted_types);
383  return TRUE;
384  } else {
385  return FALSE;
386  }
387 
388  }//end processAddHistoryAssetTypes()
389 
390 
400  function useAddButton(Design_Area_Access_History $asset, $prefix)
401  {
402  return !$asset->attr('add_history_button_image');
403 
404  }//end useAddButton()
405 
406 
416  function useRemoveButton(Design_Area_Access_History $asset, $prefix)
417  {
418  return !$asset->attr('remove_history_button_image');
419 
420  }//end useRemoveButton()
421 
422 
433  {
434  return $asset->attr('remove_history_button_image');
435 
436  }//end showRemoveImageSelection()
437 
438 
449  {
450  return $asset->attr('add_history_button_image');
451 
452  }//end showAddImageSelection()
453 
454 
455 }//end class
456 ?>