Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
page_whats_new_edit_fns.inc
1 <?php
18 require_once SQ_PACKAGES_PATH.'/cms/listing_engine/listing_engine_edit_fns.inc';
19 
33 {
34 
35 
40  function __construct()
41  {
42  parent::__construct();
43 
44  }//end constructor
45 
46 
57  function paintCurrentRanges(&$asset, &$o, $prefix)
58  {
59  $ranges = $asset->attr('date_ranges');
60 
61  if (empty($ranges)) {
62  echo translate('cms_whats_new_no_ranges');
63  } else {
64  foreach ($ranges as $id => $info) {
65  $options[$id] = $info['name'];
66  }
67  $options = array_reverse($options);
68  $options[] = '-- '.translate('please_select').' --';
69  $options = array_reverse($options);
70 
71  combo_box($prefix.'_range_id', $options, FALSE, '', 0 , 'onchange="this.form.submit();"');
72  }
73 
74  return FALSE;
75 
76  }//end paintCurrentRanges()
77 
78 
89  function processCurrentRanges(&$asset, &$o, $prefix)
90  {
91  return FALSE;
92 
93  }//end processCurrentRanges()
94 
95 
106  function paintAddRange(&$asset, &$o, $prefix)
107  {
108  if (!$asset->writeAccess('attributes')) return FALSE;
109  check_box($prefix.'_new_range');
110 
111  return TRUE;
112 
113  }//end paintAddRange()
114 
115 
126  function processAddRange(&$asset, &$o, $prefix)
127  {
128  return FALSE;
129 
130  }//end processAddRange()
131 
132 
143  function paintMainDateRange(&$asset, &$o, $prefix)
144  {
145  require_once SQ_ATTRIBUTES_PATH.'/datetime/datetime.inc';
146  $write_access = $asset->writeAccess('attributes');
147 
148  if ($asset->attr('range_type') !== 'default') {
149  $range = $asset->attr('range_type');
150  $date_range_from = '---------- --:--:--';
151  $date_range_to = '---------- --:--:--';
152  } else {
153  $range = '';
154  $date_range_from = $asset->attr('date_range_from');
155  $date_range_to = $asset->attr('date_range_to');
156  }
157 
158  $range_types = Array(
159  'default' => 'Specified Range',
160  'today' => 'Today',
161  'week' => 'This Week',
162  'month' => 'This Month',
163  'year' => 'This Year',
164  );
165 
166  $o->openField('Range Type');
167  if ($write_access === TRUE) {
168  combo_box($prefix.'_range_type', $range_types, FALSE, $range);
169  } else {
170  if(!empty($range))
171  echo $range_types[$range];
172  }
173  $o->note(translate('cms_whats_new_range_type_note'));
174  $o->closeField();
175 
176  foreach (Array('date_range_from', 'date_range_to') as $type) {
177 
178  $o->openField(ucwords(str_replace('_', ' ', $type)));
179  $datetime = new Asset_Attribute_DateTime();
180 
181  // set some params for the datetime field so that it paints properly
182  $datetime->_edit_params['allow_period'] = TRUE;
183  $datetime->_edit_params['allow_period_today'] = TRUE;
184  $datetime->_edit_params['use_picker'] = TRUE;
185  $datetime->_edit_params['show'] = Array('y','m','d','h','i','s');
186  $datetime->_edit_params['null'] = Array('y','m','d','h','i','s');
187 
188  foreach ($datetime->_edit_params['show'] as $u) {
189  $datetime->_edit_params['style'][$u] = 's';
190  }
191  $datetime->_edit_params['style']['y'] = 't';
192  $datetime->value = $$type;
193 
194  $datetime->paint($prefix.'_'.$type, !$write_access);
195 
196  $o->closeField();
197  }
198 
199  return $write_access;
200 
201  }//end paintMainDateRange()
202 
203 
214  function processMainDateRange(&$asset, &$o, $prefix)
215  {
216  if ($asset->writeAccess('attributes') === FALSE) {
217  return FALSE;
218  }
219 
220  require_once SQ_ATTRIBUTES_PATH.'/datetime/datetime.inc';
221 
222  $range_type = array_get_index($_POST, $prefix.'_range_type', 'default');
223  $save = FALSE;
224 
225  if ($range_type !== 'default') {
226  if ($asset->attr('range_type') !== $range_type) {
227  $asset->setAttrValue('range_type', $range_type);
228  $asset->setAttrValue('date_range_from', '---------- --:--:--');
229  $asset->setAttrValue('date_range_to', '---------- --:--:--');
230  $save = TRUE;
231  }
232  } else {
233  $asset->setAttrValue('range_type', 'default');
234  foreach (Array('date_range_from', 'date_range_to') as $type) {
235  $datetime = new Asset_Attribute_DateTime();
236  $datetime->process($prefix.'_'.$type);
237 
238  if ($asset->attr($type) !== $datetime->value) {
239  $asset->setAttrValue($type, $datetime->value);
240  $save = TRUE;
241  }
242  }
243  }
244 
245  return $save;
246 
247  }//end processMainDateRange()
248 
249 
260  function paintRangeOptions(&$asset, &$o, $prefix)
261  {
262  require_once SQ_ATTRIBUTES_PATH.'/datetime/datetime.inc';
263  $write_access = $asset->writeAccess('attributes');
264  $ranges = $asset->attr('date_ranges');
265 
266  if (isset($_POST[$prefix.'_new_range'])) {
267  $rangeid = -1;
268  } else if (isset($_POST[$prefix.'_range_id']) && $_POST[$prefix.'_range_id'] != 0 && isset($ranges[$_POST[$prefix.'_range_id'] - 1])) {
269  // remove 1 from the index because of the please select option
270  $rangeid = $_POST[$prefix.'_range_id'] - 1;
271  } else {
272  echo translate('cms_whats_new_select_range');
273  return FALSE;
274  }
275 
276  $range_name = isset($ranges[$rangeid]['name']) ? $ranges[$rangeid]['name'] : '';
277  $o->addHiddenField($prefix.'_curr_range_id', $rangeid);
278 
279  // field opened by XML
280 
281  if ($write_access) {
282  text_box($prefix.'_range_name', $range_name);
283  } else {
284  echo $range_name;
285  }
286 
287  $o->closeField();
288 
289  if ($rangeid === -1) {
290  $range = 'default';
291  $oldest_date = '---------- --:--:--';
292  $newest_date = '---------- --:--:--';
293  } else if (array_key_exists('range_type', $ranges[$rangeid]) === TRUE) {
294  $range = $ranges[$rangeid]['range_type'];
295  $oldest_date = isset($ranges[$rangeid]['oldest_date']) ? $ranges[$rangeid]['oldest_date'] : '---------- --:--:--';
296  $newest_date = isset($ranges[$rangeid]['newest_date']) ? $ranges[$rangeid]['newest_date'] : '---------- --:--:--';
297  } else {
298  $range = 'default';
299  $oldest_date = '---------- --:--:--';
300  $newest_date = '---------- --:--:--';
301  }
302 
303  $range_types = Array(
304  'default' => 'Specified Range',
305  'today' => 'Today',
306  'week' => 'This Week',
307  'month' => 'This Month',
308  'year' => 'This Year',
309  );
310 
311  $o->openField('Range Type');
312  if ($write_access === TRUE) {
313  combo_box($prefix.'_range_type', $range_types, FALSE, $range);
314  } else {
315  echo $range_types[$range];
316  }
317  $o->note(translate('cms_whats_new_range_type_note'));
318  $o->closeField();
319 
320  foreach (Array('oldest_date', 'newest_date') as $type) {
321 
322  $o->openField(ucwords(str_replace('_', ' ', $type)));
323  $datetime = new Asset_Attribute_DateTime();
324 
325  // set some params for the datetime field so that it paints properly
326  $datetime->_edit_params['allow_period'] = TRUE;
327  $datetime->_edit_params['allow_period_today'] = TRUE;
328  $datetime->_edit_params['use_picker'] = TRUE;
329  $datetime->_edit_params['show'] = Array('y','m','d','h','i','s');
330  $datetime->_edit_params['null'] = Array('y','m','d','h','i','s');
331 
332  foreach ($datetime->_edit_params['show'] as $u) {
333  $datetime->_edit_params['style'][$u] = 's';
334  }
335  $datetime->value = $$type;
336 
337  $datetime->paint($prefix.'_'.$type, !$write_access);
338 
339  $o->closeField();
340  }
341 
342  // only add an option to remove this range if it has a name (it has been saved)
343  if ($asset->writeAccess('attributes') && trim($range_name) != '') {
344  $o->openField(translate('remove_question'));
345  check_box($prefix.'_remove', FALSE);
346  $o->closeField();
347  }
348 
349  return $write_access;
350 
351  }//end paintRangeOptions()
352 
353 
364  function processRangeOptions(&$asset, &$o, $prefix)
365  {
366  if (!isset($_POST[$prefix.'_curr_range_id']) || !isset($_POST[$prefix.'_range_name']) ) {
367  return FALSE;
368  }
369  require_once SQ_ATTRIBUTES_PATH.'/datetime/datetime.inc';
370 
371  $ranges = $asset->attr('date_ranges');
372  $rangeid = $_POST[$prefix.'_curr_range_id'];
373  $range_name = $_POST[$prefix.'_range_name'];
374  $range_type = array_get_index($_POST, $prefix.'_range_type', 'default');
375  $save = FALSE;
376 
377  if (isset($_POST[$prefix.'_remove'])) {
378  unset($ranges[$rangeid]);
379  $save = TRUE;
380  } else {
381 
382  // if the rangeid is -1, then we are creating a new range
383  if ($rangeid == -1) {
384  // if there is no name set for this, just return
385  if (trim($range_name) == '') return FALSE;
386  $ranges[count($ranges)] = Array('name' => $range_name);
387  $current_range =& $ranges[count($ranges) - 1];
388 
389  } else {
390  $current_range =& $ranges[$rangeid];
391  if (trim($range_name) != '' && $range_name != $current_range['name']) {
392  $current_range['name'] = $range_name;
393  $save = TRUE;
394  }
395  }
396 
397  if ($range_type !== 'default') {
398  if (array_get_index($current_range, 'range_type', 'default') !== $range_type) {
399  $current_range['range_type'] = $range_type;
400  unset($current_range['oldest_date']);
401  unset($current_range['newest_date']);
402  $save = TRUE;
403  }
404  } else {
405  $current_range['range_type'] = 'default';
406  foreach (Array('oldest_date', 'newest_date') as $type) {
407  $datetime = new Asset_Attribute_DateTime();
408  $datetime->process($prefix.'_'.$type);
409 
410  if (isset($current_range[$type]) && $current_range[$type] == $datetime->value) {
411  continue;
412  }
413  $current_range[$type] = $datetime->value;
414  $save = TRUE;
415  }
416  }
417  }//end if remove
418 
419  if ($save) {
420  $ranges = array_values($ranges);
421  $asset->setAttrValue('date_ranges', $ranges);
422  }
423  return $save;
424 
425  }//end processRangeOptions()
426 
427 
438  function paintLinkTypes(&$asset, &$o, $prefix)
439  {
440  require_once SQ_INCLUDE_PATH.'/general_occasional.inc';
441  $write_access = $asset->writeAccess('attributes');
442 
443  $current = $asset->attr('link_types');
444  $link_types = get_link_type_names();
445 
446  if ($write_access) {
447  require_once SQ_LIB_PATH.'/html_form/html_form.inc';
448 
449  $selected = Array();
450  foreach ($link_types as $link_type => $link_type_name) {
451  if ($current & $link_type) {
452  $selected[] = $link_type;
453  }
454  }
455 
456  combo_box($prefix.'_link_types', $link_types, TRUE, $selected);
457  } else {
458  if ($current == 0) {
459  echo translate('cms_listing_no_link_types_selected');
460  } else {
461  echo '<ul>';
462  foreach ($link_types as $link_type => $link_type_name) {
463  if ($current & $link_type) {
464  echo '<li>'.$link_type_name.'</li>';
465  }
466  }
467  echo '</ul>';
468  }
469  }
470 
471  return $write_access;
472 
473  }//end paintLinkTypes()
474 
475 
486  function processLinkTypes(&$asset, &$o, $prefix)
487  {
488  // need to have write access to make any changes
489  if (!$asset->writeAccess('attributes')) return FALSE;
490 
491  $link_types = 0;
492  if (isset($_POST[$prefix.'_link_types'])) {
493  foreach ($_POST[$prefix.'_link_types'] as $link_type) {
494  $link_types |= $link_type;
495  }
496  }
497 
498  return $asset->setAttrValue('link_types', $link_types);
499 
500  }//end processLinkTypes()
501 
502 
503 }//end class
504 
505 ?>