Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
page_calendar_rolling_edit_fns.inc
1 <?php
18 require_once SQ_CORE_PACKAGE_PATH.'/page/page_edit_fns.inc';
19 
20 
33 {
34 
35 
40  function __construct()
41  {
42  parent::__construct();
43  }//end constructor
44 
55  function paintEventSources(&$asset, &$o, $prefix)
56  {
57  if ($asset->writeAccess('attributes')) {
58  multiple_asset_finder($prefix.'_event_sources', array_keys($asset->attr('root_nodes')));
59  return TRUE;
60  } else {
61  $infos = $GLOBALS['SQ_SYSTEM']->am->getAssetInfo(array_keys($asset->attr('root_nodes')), '', TRUE, 'name');
62  ?><ul style="margin: 1px 15px;"><?php
63  foreach ($infos as $id => $name) {
64  echo '<li>'.get_asset_tag_line($id).'</li>';
65  }
66  ?></ul><?php
67  return FALSE;
68  }
69 
70  }//end paintEventSources()
71 
72 
83  function processEventSources(&$asset, &$o, $prefix)
84  {
85  if (isset($_POST[$prefix.'_event_sources'])) {
86  $root_nodes = Array();
87  foreach ($_POST[$prefix.'_event_sources'] as $source) {
88  if (!empty($source['assetid'])) {
89  $root_nodes[$source['assetid']] = 1;
90  }
91  }
92  return $asset->setAttrValue('root_nodes', $root_nodes);
93  }
94  return FALSE;
95 
96  }//end processEventSources()
97 
98 
99 //-- DurationFromTo --//
100 
101 
112  function paintDurationFromTo(&$asset, &$o, $prefix)
113  {
114  $success = TRUE;
115 
116  // if we got write access we add an extra option to change
117  $write_access = $asset->writeAccess('attributes');
118  $success = $write_access;
119 
120  $o->openField(translate('cal_rolling_time_frame_time_unit'));
121  $dt_select_contents = Array(
122  'days' => translate('days'),
123  'weeks' => translate('weeks'),
124  'months' => translate('months'),
125  );
126  if ($write_access) {
127  ?>
128  <script type="text/javascript">
129  function changeTimeUnitTextfield(value)
130  {
131  document.getElementById(<?php echo '"'.$prefix.'_time_unit_select_duration_from"'; ?>).value=value;
132  document.getElementById(<?php echo '"'.$prefix.'_time_unit_select_duration_to"'; ?>).value=value;
133  }
134  //changeTimeUnitTextfield("test");
135  </script>
136  <?php
137  combo_box($prefix.'_time_unit_select', $dt_select_contents, FALSE, $asset->attr('time_unit'), 0, 'onchange="changeTimeUnitTextfield(this.value)"');
138  } else {
139  echo ucwords($dt_select_contents[$asset->attr('time_unit')]);
140  }
141  $o->closeField();
142 
143  $o->openField(translate('cal_rolling_time_frame_from'));
144  $success = $this->_paintDaySelect($asset, $prefix, 'duration_from') && $success;
145  $o->closeField();
146  $o->openField(translate('cal_rolling_time_frame_to'));
147  $success = $this->_paintDaySelect($asset, $prefix, 'duration_to') && $success;
148  $o->note(translate('cal_rolling_duration_from_to_note'));
149  $o->closeField();
150 
151  return $success;
152 
153  }//end paintDurationFromTo()
154 
155 
166  function processDurationFromTo(&$asset, &$o, $prefix)
167  {
168  $time_unit_val = array_get_index($_REQUEST, $prefix.'_time_unit_select');
169  return (($asset->setAttrValue('time_unit', $time_unit_val)) &&
170  ($this->_processDaySelect($asset, $prefix, 'duration_from')) &&
171  ($this->_processDaySelect($asset, $prefix, 'duration_to')));
172 
173  }//end processDurationFromTo()
174 
175 
176 //-- Days From/To --//
177 
178 
189  function paintDaysFrom(&$asset, &$o, $prefix)
190  {
191  return $this->_paintDaySelect($asset, $prefix, 'duration_from');
192 
193  }//end paintDaysFrom()
194 
195 
206  function processDaysFrom(&$asset, &$o, $prefix)
207  {
208  return $this->_processDaySelect($asset, $prefix, 'duration_from');
209 
210  }//end processDaysFrom()
211 
212 
223  function paintDaysTo(&$asset, &$o, $prefix)
224  {
225  return $this->_paintDaySelect($asset, $prefix, 'duration_to');
226 
227  }//end paintDaysTo()
228 
229 
240  function processDaysTo(&$asset, &$o, $prefix)
241  {
242  return $this->_processDaySelect($asset, $prefix, 'duration_to');
243 
244  }//end processDaysTo()
245 
246 
257  function _paintDaySelect(&$asset, $prefix, $attr)
258  {
259  $write_access = $asset->writeAccess('attributes');
260 
261  $dt_select_contents = Array (
262  'days' => translate('days'),
263  'weeks' => translate('weeks'),
264  'months' => translate('months'),
265  );
266 
267  $pf_select_contents = Array(
268  'duration_past' => translate('cal_rolling_duration_past_combo'),
269  'duration_future' => translate('cal_rolling_duration_future_combo'),
270  );
271 
272  // take the single attribute, break it out into a (positive) textbox value,
273  // and a dropdown switching between days in the past, and days in the future
274  $attr_val = $asset->attr($attr);
275  $text_val = abs($attr_val);
276  $combo_val = ($attr_val < 0 ? 'duration_past' : 'duration_future');
277 
278  if ($write_access) {
279  int_text_box($prefix.'_'.$attr, $text_val, FALSE, 2);
280  text_box($prefix.'_time_unit_select_'.$attr, $asset->attr('time_unit'), '5', '', FALSE, 'disabled');
281  combo_box($prefix.'_pastfuture_select_'.$attr, $pf_select_contents, FALSE, $combo_val);
282  } else {
283  echo translate('cal_rolling_'.$combo_val, $text_val, $asset->attr('time_unit'));
284  }
285 
286  return $write_access;
287 
288  }//end _paintDaySelect()
289 
290 
301  function _processDaySelect(&$asset, $prefix, $attr)
302  {
303  if ($asset->writeAccess('attributes')) {
304  $text_val = abs(array_get_index($_REQUEST, $prefix.'_'.$attr, 0));
305  $select_val = array_get_index($_REQUEST, $prefix.'_pastfuture_select_'.$attr, 'duration_future');
306 
307  $attr_val = ($select_val == 'duration_past' ? ($text_val * -1) : $text_val);
308  return $asset->setAttrValue($attr, $attr_val);
309  }
310 
311  return TRUE;
312 
313  }//end _processDaySelect()
314 
315 
326  function paintDefaultFormatLinks(&$asset, &$o, $prefix)
327  {
328  ?>
329  <table class="sq-backend-table">
330  <tr>
331  <th><?php echo translate('edit_format') ?></th>
332  <th><?php echo translate('note') ?></th>
333  </tr>
334  <?php
335  $this->_paintDefaultFormatLink($asset->id, '', translate('calendar_rolling_page_contents_desc'));
336  $this->_paintDefaultFormatLink($asset->id, 'time_unit', translate('calendar_rolling_time_formats_desc'));
337  ?>
338  </table>
339  <?php
340 
341  return FALSE;
342 
343  }//end paintDefaultFormatLinks()
344 
345 
358  function _paintDefaultFormatLink($root_assetid, $bodycopy_name, $bodycopy_description, $type_code='bodycopy', $screen='contents')
359  {
360  $link = $GLOBALS['SQ_SYSTEM']->am->getLink($root_assetid, SQ_LINK_TYPE_2, $type_code, TRUE, $bodycopy_name);
361  if (!empty($link)) {
362  $info = Array($link['minorid'] => 'contents');
363  $href = $GLOBALS['SQ_SYSTEM']->am->getAssetBackendHref($info);
364  ?>
365  <tr>
366  <td>
367  <?php echo get_asset_tag_line($link['minorid'], $screen); ?>
368  </td>
369  <td>
370  <?php echo $bodycopy_description; ?>
371  </td>
372  </tr>
373  <?php
374  }
375 
376  }//end _paintDefaultFormatLink()
377 
378 
389  function paintTypeFormats(&$asset, &$o, $prefix)
390  {
391  $write_access = $asset->writeAccess('links');
392  $types = $this->_getAvailableTypes($asset);
393  $formats = $asset->getFormats('type_formats');
394  if (count($formats) > 0) {
395  ?>
396  <table class="sq-backend-table">
397  <tr>
398  <th><?php echo translate('asset_type') ?></th>
399  <th><?php echo translate('edit_format') ?></th>
400  <?php
401  if ($write_access) {
402  ?>
403  <th><?php echo translate('delete_question') ?></th>
404  <?php
405  }
406  ?>
407  </tr>
408  <?php
409  foreach ($formats as $minorid => $value) {
410  if ($value == 'default_format') continue;
411 
412  $info = Array($minorid => 'contents');
413  $href = $GLOBALS['SQ_SYSTEM']->am->getAssetBackendHref($info);
414  $type_name = $GLOBALS['SQ_SYSTEM']->am->getTypeInfo($value, 'name');
415  ?>
416  <tr>
417  <td style="width: 200px;">
418  <?php
419  echo get_asset_type_icon($value);
420  echo $type_name;
421  ?>
422  </td>
423  <td>
424  <?php
425  echo get_asset_tag_line($minorid, 'contents');
426  ?>
427  </td>
428  <?php
429  if ($write_access) {
430  ?>
431  <td style="width: 100px;">
432  <?php
433  check_box($prefix.'_delete_type['.$value.']');
434  ?>
435  </td>
436  <?php
437  }
438  ?>
439  </tr>
440  <?php
441  }//end foreach
442  ?>
443  </table>
444  <?php
445  } else {
446  echo translate('calendar_rolling_no_type_formats');
447  }//end if cutomised formats
448 
449  if ($write_access) {
450  $new_format_options = Array('' => '');
451  foreach ($types as $type => $inherit) {
452  if (in_array($type, $formats)) continue;
453  $new_format_options[$type] = $GLOBALS['SQ_SYSTEM']->am->getTypeInfo($type, 'name');
454  }
455  if (count($new_format_options) > 0) {
456  echo '<p><b>'.translate('calendar_rolling_new_type_format').'</b> ';
457  combo_box($prefix.'_new_type', $new_format_options, FALSE, '');
458  echo '</p>';
459  }
460  }
461 
462  return $write_access;
463 
464  }//end paintTypeFormats()
465 
466 
477  function processTypeFormats(&$asset, &$o, $prefix)
478  {
479  $folder = $asset->getFolder('type_formats');
480  $types = $this->_getAvailableTypes($asset);
481 
482  $deleted_formats = array_get_index($_POST, $prefix.'_delete_type', Array());
483  $new_type = array_get_index($_POST, $prefix.'_new_type', '');
484  if (isset($deleted_formats[$new_type])) {
485  trigger_localised_error('CMS0042', E_USER_WARNING, $new_type);
486  unset($deleted_formats[$new_type]);
487  $new_type = '';
488  }
489 
490  foreach ($deleted_formats as $type => $on) {
491  $current_link = $GLOBALS['SQ_SYSTEM']->am->getLink($folder->id, SQ_LINK_TYPE_2, 'bodycopy', TRUE, $type);
492  if (empty($current_link)) {
493  trigger_localised_error('CMS0043', E_USER_WARNING, $type);
494  } else {
495  if (!$GLOBALS['SQ_SYSTEM']->am->deleteAssetLink($current_link['linkid'])) {
496  trigger_localised_error('CMS0044', E_USER_WARNING, $type);
497  }
498  }
499  }
500 
501  // check that the new type is valid
502  if ($new_type != '' && !isset($types[$new_type])) {
503  trigger_localised_error('CMS0045', E_USER_WARNING, $new_type);
504  $new_type = '';
505  }
506 
507  if ($new_type != '') {
508  // check that this type isnt already customised
509  $current_link = $GLOBALS['SQ_SYSTEM']->am->getLink($folder->id, SQ_LINK_TYPE_2, 'bodycopy', TRUE, $new_type);
510  if (empty($current_link)) {
511  // create a new format bodycopy for this type
512  $GLOBALS['SQ_SYSTEM']->changeDatabaseConnection('db2');
513  $GLOBALS['SQ_SYSTEM']->doTransaction('BEGIN');
514  $GLOBALS['SQ_SYSTEM']->am->includeAsset('bodycopy');
515 
516  $copy_link = Array('asset' => &$folder, 'value' => $new_type, 'link_type' => SQ_LINK_TYPE_2, 'is_dependant' => 1, 'is_exclusive' => 1);
517 
518  $bodycopy = new Bodycopy();
519  $bodycopy->setAttrValue('name', $GLOBALS['SQ_SYSTEM']->am->getTypeInfo($new_type, 'name').' Format');
520 
521  if (!$bodycopy->create($copy_link)) {
522  $GLOBALS['SQ_SYSTEM']->doTransaction('ROLLBACK');
523  $GLOBALS['SQ_SYSTEM']->restoreDatabaseConnection();
524  return FALSE;
525  }
526  $GLOBALS['SQ_SYSTEM']->doTransaction('COMMIT');
527  $GLOBALS['SQ_SYSTEM']->restoreDatabaseConnection();
528  } else {
529  trigger_localised_error('CMS0046', E_USER_WARNING, $new_type);
530  }
531  }
532  if (isset($asset->_tmp['formats']['type_formats'])) {
533  unset($asset->_tmp['formats']['type_formats']);
534  }
535 
536  return TRUE;
537 
538  }//end processTypeFormats()
539 
540 
554  function paintUseNoResultsBodycopy(&$asset, &$o, $prefix)
555  {
556  $write_access = $asset->writeAccess('links');
557  $bodycopy_link = $GLOBALS['SQ_SYSTEM']->am->getLink($asset->id, SQ_LINK_TYPE_2, 'bodycopy', FALSE, 'no_results');
558  $enabled = !empty($bodycopy_link);
559 
560  if ($write_access) {
561  $options = Array(
562  '1' => translate('yes'),
563  '0' => translate('no'),
564  );
565 
566  combo_box($prefix.'_use_bodycopy', $options, FALSE, Array($enabled));
567 
568  } else {
569  if ($enabled) {
570  echo translate('yes').' - '.get_asset_tag_line($bodycopy_link['minorid'], 'contents');
571  } else {
572  echo translate('no');
573  }
574  }
575 
576  return $write_access;
577 
578  }//end paintUseNoResultsBodycopy()
579 
580 
591  function processUseNoResultsBodycopy(&$asset, &$o, $prefix)
592  {
593  if (!$asset->writeAccess('links')) return FALSE;
594  $enabled = $_POST[$prefix.'_use_bodycopy'];
595 
596  $GLOBALS['SQ_SYSTEM']->changeDatabaseConnection('db2');
597  $GLOBALS['SQ_SYSTEM']->doTransaction('BEGIN');
598 
599  if (!$asset->setUseNoResultsBodycopy($enabled)) {
600  $GLOBALS['SQ_SYSTEM']->doTransaction('ROLLBACK');
601  $GLOBALS['SQ_SYSTEM']->restoreDatabaseConnection();
602  return FALSE;
603  }
604 
605  $GLOBALS['SQ_SYSTEM']->doTransaction('COMMIT');
606  $GLOBALS['SQ_SYSTEM']->restoreDatabaseConnection();
607 
608  return TRUE;
609 
610  }//end processUseNoResultsBodycopy()
611 
612 
621  function _getAvailableTypes(&$asset)
622  {
623  $types = $asset->attr('types');
624 
625  // For each of these types, grab direct descendent asset types
626  foreach ($types as $base_asset_type => $inherit) {
627  $descendents = $GLOBALS['SQ_SYSTEM']->am->getTypeDescendants($base_asset_type);
628 
629  if (is_array($descendents) && (count($descendents) > 0)) {
630  foreach ($descendents as $descendent_type) {
631  $types[$descendent_type] = 0;
632  }
633  }
634  }
635 
636  return $types;
637 
638  }//end _getAvailableTypes()
639 
640 
641 }//end class
642 ?>