Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
listing_engine_edit_fns.inc
1 <?php
18 require_once SQ_CORE_PACKAGE_PATH.'/page/page_edit_fns.inc';
19 require_once SQ_FUDGE_PATH.'/general/general.inc';
20 
21 
43 {
44 
45 
49  function __construct($assetid=0)
50  {
51  parent::__construct($assetid);
52  $this->static_screens['details']['force_unlock'] = FALSE;
53  $this->static_screens['details']['lock_type'] = 'content';
54 
55  }//end constructor
56 
57 
68  function paintAssetTypes(&$asset, &$o, $prefix)
69  {
70  $types = $asset->attr('types');
71  if ($asset->writeAccess('content')) {
72  // print the form fields
73  $display_values = Array('type_code' => Array(), 'inherit' => Array());
74  foreach ($types as $type => $inherit) {
75  $display_values['type_code'][] = $type;
76  $display_values['inherit'][] = $inherit;
77  }
78  asset_type_chooser($prefix.'_types', TRUE, $display_values, NULL, TRUE, TRUE);
79  return TRUE;
80  } else {
81  // print the read-only version
82  if (empty($types)) {
83  echo '<p class="sq-backend-warning">'.translate('cms_listing_no_asset_types_selected').'</p>';
84  } else {
85  $type_names = $GLOBALS['SQ_SYSTEM']->am->getTypeInfo(array_keys($types), 'name');
86  ?>
87  <table class="sq-backend-table">
88  <tr>
89  <th><?php echo translate('type') ?></th>
90  <th><?php echo translate('inherit_question') ?></th>
91  </tr>
92  <?php
93  $inherit_image_path = sq_web_path('lib').'/web/images/';
94  foreach ($types as $type => $inherit) {
95  $inherit_image = $inherit_image_path.($inherit ? 'tick' : 'cross').'.gif';
96  $inherit_alt = $inherit ? translate('yes') : translate('no');
97  ?>
98  <tr>
99  <td><?php
100  echo get_asset_type_icon($type);
101  echo $type_names[$type];
102  ?></td>
103  <td><img src="<?php echo $inherit_image; ?>" alt="<?php echo $inherit_alt; ?>" /></td>
104  </tr>
105  <?php
106  }
107  ?>
108  </table>
109  <?php
110  }
111  return FALSE;
112  }//end else - if write access to content
113 
114  }//end paintAssetTypes()
115 
116 
131  function processAssetTypes(&$asset, &$o, $prefix)
132  {
133  $proxy_settings = $asset->attr('proxy_types');
134 
135  if (isset($_POST[$prefix.'_types'])) {
136  $existing_types = $asset->attr('types');
137 
138  $submitted_types = Array();
139  foreach ($_POST[$prefix.'_types']['type_code'] as $i => $type_code) {
140  if (!empty($type_code)) {
141  $submitted_types[$type_code] = $_POST[$prefix.'_types']['inherit'][$i];
142  }
143  }
144 
145  $proxy_child_types = Array();
146  $delete_proxy_types = Array();
147  foreach ($proxy_settings as $proxy_type => $child_types) {
148  if (!empty($child_types)) {
149  if (in_array($proxy_type, array_keys($submitted_types))) {
150  $proxy_child_types = array_merge($proxy_child_types, array_keys($child_types));
151  } else {
152  $delete_proxy_types[] = $proxy_type;
153  }
154  $existing_types = array_merge($existing_types, $child_types);
155  }
156  }
157 
158  $folder = $asset->getFolder('type_formats');
159  $formats = $asset->getFormats('type_formats');
160 
161  // See if any types have been removed
162  foreach ($existing_types as $type => $inherit) {
163  // added second condition to prevent accidental deletion of proxied children type formats
164  if (!isset($submitted_types[$type]) && !in_array($type, $proxy_child_types)) {
165  if (in_array($type, $formats)) {
166  // send the type format bodycopy to the trash
167  $link = $GLOBALS['SQ_SYSTEM']->am->getLink($folder->id, SQ_LINK_TYPE_2, 'bodycopy', TRUE, $type);
168  if (!empty($link)) {
169  $folder->deleteLink($link['linkid']);
170  }
171  }
172  }
173  }
174 
175  $asset->setAttrValue('types', $submitted_types);
176 
177  // also remove associated proxy_types when the type is removed
178  foreach ($delete_proxy_types as $delete_proxy_type) {
179  unset($proxy_settings[$delete_proxy_type]);
180  }
181  $asset->setAttrValue('proxy_types', $proxy_settings);
182 
183  return TRUE;
184  } else {
185  return FALSE;
186  }
187 
188  }//end processAssetTypes()
189 
190 
201  function paintAssetPositions(&$asset, &$o, $prefix)
202  {
203  $write_access = $asset->writeAccess('attributes');
204  $asset_positions = $asset->attr('asset_positions');
205 
206  // if were using custom grouping, this option is useless
207  $groups = $asset->attr('asset_grouping');
208  if ($asset->attr('group_by') == 'grouped' && !empty($groups)) {
209  $o->note(translate('cms_listing_cannot_use_asset_postitions_with_groups'));
210  } else {
211  if (!empty($asset_positions)) {
212  ksort($asset_positions, SORT_NUMERIC);
213  if (!$write_access) {
214  $asset_ids = Array();
215  foreach ($asset_positions as $asset_data) {
216  $asset_ids[] = $asset_data['id'];
217  }
218  $asset_info = $GLOBALS['SQ_SYSTEM']->am->getAssetInfo($asset_ids);
219  }
220  ?>
221  <table class="sq-backend-table">
222  <tr>
223  <th><?php echo translate('position'); ?></th>
224  <th><?php echo translate('asset'); ?></th>
225  <?php
226  if ($write_access) {
227  ?><th><?php echo translate('delete_question'); ?></th><?php
228  }
229  ?>
230  </tr>
231  <?php
232  foreach ($asset_positions as $position => $asset_data) {
233  $assetid = $asset_data['id'];
234  ?>
235  <tr>
236  <td><?php echo $position; ?></td>
237  <td>
238  <?php
239  if ($write_access) {
240  asset_finder($prefix.'_asset_position['.$position.']', $assetid, Array('asset' => 'D'));
241  } else {
242  echo get_asset_tag_line($assetid);
243  }
244  ?>
245  </td>
246  <?php
247  if ($write_access) {
248  ?>
249  <td>
250  <?php
251  check_box($prefix.'_delete_asset_position['.$position.']');
252  ?>
253  </td>
254  <?php
255  }
256  ?>
257  </tr>
258  <?php
259  }//end foreach
260  ?>
261  </table>
262  <?php
263  } else {
264  echo translate('cms_listing_no_positions_defined');
265  }
266 
267  if ($write_access) {
268  echo '<p><b>'.translate('cms_listing_new_asset_position').'</b> ';
269  text_box($prefix.'_new_asset_position_pos', '', 5);
270  echo ' ';
271  asset_finder($prefix.'_new_asset_position_asset', '', Array('asset' => 'D'));
272  echo '</p>';
273  }
274  }//end else - if grouped
275 
276  return $write_access;
277 
278  }//end paintAssetPositions()
279 
280 
291  function processAssetPositions(&$asset, &$o, $prefix)
292  {
293  $asset_positions = Array();
294 
295  // if there's noting in the POST array, do nothing
296  if(!isset($_POST[$prefix.'_asset_position']) && !isset($_POST[$prefix.'_delete_asset_position']) && !isset($_POST[$prefix.'_new_asset_position_pos'])) return FALSE;
297 
298  // first, update the existing positions
299  $current_asset_positions = array_get_index($_POST, $prefix.'_asset_position', Array());
300  foreach ($current_asset_positions as $position => $data) {
301  if ($data['assetid']) {
302  $asset_positions[$position] = $data['assetid'];
303  }
304  }
305 
306  // and delete, the unneded ones
307  $delete_asset_position = array_get_index($_POST, $prefix.'_delete_asset_position', Array());
308  foreach ($delete_asset_position as $position => $on) {
309  unset($asset_positions[$position]);
310  }
311 
312  // now, process new asset
313  $new_position_pos = (int) array_get_index($_POST, $prefix.'_new_asset_position_pos', 0);
314  if ($new_position_pos > 0) {
315  $new_position_data = array_get_index($_POST, $prefix.'_new_asset_position_asset', Array());
316  if ($new_position_assetid = $new_position_data['assetid']) {
317  $asset_positions[$new_position_pos] = $new_position_assetid;
318  }
319  }
320 
321  $asset_types = $GLOBALS['SQ_SYSTEM']->am->getAssetInfo(array_values($asset_positions), 'asset', FALSE, 'type_code');
322  foreach ($asset_positions as $position=>$id) {
323  $asset_positions[$position] = Array('id'=>$id, 'type'=>$asset_types[$id]);
324  }
325  ksort($asset_positions, SORT_NUMERIC);
326 
327  return $asset->setAttrValue('asset_positions', $asset_positions);
328 
329  }//end processAssetPositions()
330 
331 
342  function paintColumnSettings(&$asset, &$o, $prefix)
343  {
344  $write_access = $asset->writeAccess('attributes');
345  $current = $asset->attr('column_layout');
346 
347  ?>
348  <table class="sq-backend-table">
349  <tr>
350  <th><?php echo translate('row'); ?></th>
351  <th><?php echo translate('column(s)'); ?></th>
352  <?php
353  if ($write_access) {
354  ?>
355  <th><?php echo translate('delete_question') ?></th>
356  <?php
357  }
358  ?>
359  </tr>
360  <?php
361  if (count($current) > 1) {
362  foreach ($current as $row => $columns) {
363  if ($row == 0) continue;
364  ?>
365  <tr>
366  <td><?php echo $row; ?></td>
367  <td>
368  <?php
369  if ($write_access) {
370  text_box($prefix.'_columns['.$row.']', $columns, 5);
371  } else {
372  echo $columns;
373  }
374  ?>
375  </td>
376  <?php
377  if ($write_access) {
378  ?>
379  <td>
380  <?php check_box($prefix.'_delete_row['.$row.']'); ?>
381  </td>
382  <?php
383  }
384  ?>
385  </tr>
386  <?php
387  }//end foreach
388  }//end if
389 
390  ?>
391  <tr>
392  <td><?php echo translate('cms_listing_all_remaining'); ?></td>
393  <td>
394  <?php
395  if ($write_access) {
396  text_box($prefix.'_columns[0]', $current['0'], 5);
397  } else {
398  echo $current['0'];
399  }
400  ?>
401  </td>
402  <?php
403  if ($write_access) {
404  ?><td>&nbsp;</td><?php
405  }
406  ?>
407  </tr>
408  </table>
409  <?php
410 
411  if ($write_access) {
412  $o->closeField();
413  $o->openField(translate('cms_listing_customise_row'));
414  echo strtolower(translate('row')).' ';
415  text_box($prefix.'_new_row', '', 5);
416  echo ' '.strtolower(translate('columns')).' ';
417  text_box($prefix.'_new_column', '', 5);
418  // field closed by asset_edit_interface
419  }
420 
421  return $write_access;
422 
423  }//end paintColumnSettings()
424 
425 
436  function processColumnSettings(&$asset, &$o, $prefix)
437  {
438  // change existing column settings
439  $column_layout = array_get_index($_POST, $prefix.'_columns', Array());
440  $deleted_rows = array_get_index($_POST, $prefix.'_delete_row', Array());
441  foreach ($deleted_rows as $row => $on) {
442  if (isset($column_layout[$row])) {
443  unset($column_layout[$row]);
444  }
445  }
446 
447  // Check if the existing column settings are at least 1 column
448  for (reset($column_layout); NULL !== ($row = key($column_layout)); next($column_layout)) {
449  if ((int)$column_layout[$row] < 1) {
450  // Tailor the error message depending on whether it's a customised
451  // row or an "all remaining rows" list
452  if ($row == 0) {
453  trigger_localised_error('CMS0061', E_USER_NOTICE);
454  } else {
455  trigger_localised_error('CMS0060', E_USER_NOTICE, $row);
456  }
457  $column_layout[$row] = 1;
458  }
459  }
460 
461  // add a new column setting
462  $new_row = (int)array_get_index($_POST, $prefix.'_new_row', 0);
463  $new_column = (int)array_get_index($_POST, $prefix.'_new_column', 0);
464  if ($new_row > 0) {
465  if ($new_column > 0) {
466  if (!isset($column_layout[$new_row])) {
467  $column_layout[$new_row] = $new_column;
468  } else {
469  trigger_localised_error('CMS0040', E_USER_WARNING, $new_row);
470  }
471  } else {
472  trigger_localised_error('CMS0041', E_USER_WARNING, $new_row);
473  }
474  }
475 
476  return $asset->setAttrValue('column_layout', $column_layout);
477 
478  }//end processColumnSettings()
479 
480 
491  function paintColumnPreview(&$asset, &$o, $prefix)
492  {
493  $column_layout = $asset->attr('column_layout');
494  $num_per_page = $asset->attr('num_per_page');
495 
496  $num_rows = max(array_keys($column_layout)) + 1;
497  $num_columns = max(array_values($column_layout));
498 
499  ?>
500  <table class="sq-backend-table">
501  <?php
502  $cell_num = 1;
503  for ($i = 1; $i <= $num_rows; $i++) {
504  echo '<tr>';
505  $cols_in_row = array_get_index($column_layout, $i, $column_layout['0']);
506  $each_colspan = (int)($num_columns / $cols_in_row);
507  $first_colspan = $each_colspan + $num_columns - ($cols_in_row * $each_colspan);
508 
509  for ($c = 1; $c <= $cols_in_row; $c++) {
510  $colspan = ($c == 1) ? $first_colspan : $each_colspan;
511  $class = 'sq-backend-table-cell';
512  if ($num_per_page > 0 && $cell_num > $num_per_page) {
513  $class .= '-alt';
514  }
515  ?>
516  <td class="<?php echo $class; ?>" style="<?php echo ($c < $cols_in_row) ? ' border-right: 1px solid #CCCCCC;' : ''; ?>"<?php echo ($colspan > 1) ? ' colspan="'.$colspan.'"' : ''; ?>>
517  <b><?php echo $cell_num; ?></b>
518  </td>
519  <?php
520  $cell_num++;
521  }
522  echo '</tr>';
523  }
524  ?>
525  <tr>
526  <td style="text-align: center;" colspan="<?php echo $num_columns; ?>">
527  <?php echo translate('cms_listing_column_all_remaining_rows', $column_layout[0]); ?>
528  <?php
529  if ($num_per_page > 0 && $cell_num > $num_per_page) {
530  echo '<br /><b>'.translate('cms_listing_column_page_note', $num_per_page).'</b>';
531  }
532  ?>
533  </td>
534  </tr>
535  </table>
536  <?php
537 
538  }//end paintColumnPreview()
539 
540 
551  function processColumnPreview(&$asset, &$o, $prefix)
552  {
553  return FALSE;
554 
555  }//end processColumnPreview()
556 
557 
568  function paintDefaultFormatLinks(&$asset, &$o, $prefix)
569  {
570  ?>
571  <table class="sq-backend-table">
572  <tr>
573  <th><?php echo translate('edit_format') ?></th>
574  <th><?php echo translate('note') ?></th>
575  </tr>
576  <?php
577  $this->_paintDefaultFormatLink($asset->id, 'page_contents', translate('cms_listing_page_contents_desc'));
578  $this->_paintDefaultFormatLink($asset->id, 'no_results', translate('cms_listing_no_results_bodycopy_desc'));
579 
580  $folder = $asset->getFolder('type_formats');
581  $this->_paintDefaultFormatLink($folder->id, 'default_format', translate('cms_listing_default_asset_desc'));
582  ?>
583  </table>
584  <?php
585 
586  return FALSE;
587 
588  }//end paintDefaultFormatLinks()
589 
590 
603  function _paintDefaultFormatLink($root_assetid, $bodycopy_name, $bodycopy_description, $type_code='bodycopy', $screen='contents')
604  {
605  $link = $GLOBALS['SQ_SYSTEM']->am->getLink($root_assetid, SQ_LINK_TYPE_2, $type_code, TRUE, $bodycopy_name);
606  if (!empty($link)) {
607  $info = Array($link['minorid'] => 'contents');
608  $href = $GLOBALS['SQ_SYSTEM']->am->getAssetBackendHref($info);
609  ?>
610  <tr>
611  <td>
612  <?php echo get_asset_tag_line($link['minorid'], $screen); ?>
613  </td>
614  <td>
615  <?php echo $bodycopy_description; ?>
616  </td>
617  </tr>
618  <?php
619  }
620 
621  }//end _paintDefaultFormatLink()
622 
623 
634  function paintGroupFormatLinks(&$asset, &$o, $prefix)
635  {
636  // first lets get the bodycopies we want
637  $formats = $asset->getFormats('group_formats');
638 
639  if (empty($formats)) {
640  echo translate('cms_listing_no_groups');
641  } else {
642  ?>
643  <table class="sq-backend-table">
644  <tr>
645  <th><?php echo translate('edit_format'); ?></th>
646  </tr>
647  <?php
648  foreach (array_keys($formats) as $assetid) {
649  $_format = $GLOBALS['SQ_SYSTEM']->am->getAssetInfo(Array($assetid));
650  $format = reset($_format);
651  $link = $GLOBALS['SQ_SYSTEM']->am->getAssetBackendHref(Array($assetid => 'contents'))
652  ?>
653  <tr>
654  <td><?php echo get_asset_tag_line($assetid, 'contents'); ?></td>
655  </tr>
656  <?php
657  }
658  ?>
659  </table>
660  <?php
661  }
662 
663  return TRUE;
664 
665  }//end paintGroupFormatLinks()
666 
667 
676  function _getAvailableTypes(&$asset)
677  {
678  $types = $asset->attr('types');
679  $proxy_settings = $asset->attr('proxy_types');
680 
681  foreach ($proxy_settings as $proxy_type => $proxy_children) {
682  if (!empty($proxy_children)) {
683  $types = array_merge($proxy_children, $types);
684  }
685  }
686 
687  return $types;
688 
689  }//end _getAvailableTypes()
690 
691 
702  function paintTypeFormats(&$asset, &$o, $prefix)
703  {
704  $write_access = $asset->writeAccess('links');
705  $types = $this->_getAvailableTypes($asset);
706  $formats = $asset->getFormats('type_formats');
707 
708  if (count($formats) > 1) {
709  ?>
710  <table class="sq-backend-table">
711  <tr>
712  <th><?php echo translate('asset_type') ?></th>
713  <th><?php echo translate('edit_format') ?></th>
714  <?php
715  if ($write_access) {
716  ?>
717  <th><?php echo translate('delete_question') ?></th>
718  <?php
719  }
720  ?>
721  </tr>
722  <?php
723  foreach ($formats as $minorid => $value) {
724  if ($value == 'default_format') continue;
725 
726  $info = Array($minorid => 'contents');
727  $href = $GLOBALS['SQ_SYSTEM']->am->getAssetBackendHref($info);
728  $type_name = $GLOBALS['SQ_SYSTEM']->am->getTypeInfo($value, 'name');
729  ?>
730  <tr>
731  <td style="width: 200px;">
732  <?php
733  echo get_asset_type_icon($value);
734  echo $type_name;
735  ?>
736  </td>
737  <td>
738  <?php
739  echo get_asset_tag_line($minorid, 'contents');
740  ?>
741  </td>
742  <?php
743  if ($write_access) {
744  ?>
745  <td style="width: 100px;">
746  <?php
747  check_box($prefix.'_delete_type['.$value.']');
748  ?>
749  </td>
750  <?php
751  }
752  ?>
753  </tr>
754  <?php
755  }//end foreach
756  ?>
757  </table>
758  <?php
759  } else {
760  echo translate('cms_listing_no_type_formats');
761  }//end if cutomised formats
762 
763  if ($write_access) {
764  $new_format_options = Array('' => '');
765  foreach ($types as $type => $inherit) {
766  if (in_array($type, $formats)) continue;
767  $new_format_options[$type] = $GLOBALS['SQ_SYSTEM']->am->getTypeInfo($type, 'name');
768  }
769  if (count($new_format_options) > 1) {
770  echo '<p><b>'.translate('cms_listing_new_type_format').'</b> ';
771  combo_box($prefix.'_new_type', $new_format_options, FALSE, '');
772  echo '</p>';
773  }
774  }
775  return FALSE;
776 
777  }//end paintTypeFormats()
778 
779 
790  function processTypeFormats(&$asset, &$o, $prefix)
791  {
792  $folder = $asset->getFolder('type_formats');
793  $types = $this->_getAvailableTypes($asset);
794 
795  $deleted_formats = array_get_index($_POST, $prefix.'_delete_type', Array());
796  $new_type = array_get_index($_POST, $prefix.'_new_type', '');
797  if (isset($deleted_formats[$new_type])) {
798  trigger_localised_error('CMS0042', E_USER_WARNING, $new_type);
799  unset($deleted_formats[$new_type]);
800  $new_type = '';
801  }
802 
803  foreach ($deleted_formats as $type => $on) {
804  $current_link = $GLOBALS['SQ_SYSTEM']->am->getLink($folder->id, SQ_LINK_TYPE_2, 'bodycopy', TRUE, $type);
805  if (empty($current_link)) {
806  trigger_localised_error('CMS0043', E_USER_WARNING, $type);
807  } else {
808  if (!$GLOBALS['SQ_SYSTEM']->am->deleteAssetLink($current_link['linkid'])) {
809  trigger_localised_error('CMS0044', E_USER_WARNING, $type);
810  }
811  }
812  }
813 
814  // check that the new type is valid
815  if ($new_type != '' && !isset($types[$new_type])) {
816  trigger_localised_error('CMS0045', E_USER_WARNING, $new_type);
817  $new_type = '';
818  }
819 
820  if ($new_type != '') {
821  // check that this type isnt already customised
822  $current_link = $GLOBALS['SQ_SYSTEM']->am->getLink($folder->id, SQ_LINK_TYPE_2, 'bodycopy', TRUE, $new_type);
823  if (empty($current_link)) {
824  // create a new format bodycopy for this type
825  $GLOBALS['SQ_SYSTEM']->changeDatabaseConnection('db2');
826  $GLOBALS['SQ_SYSTEM']->doTransaction('BEGIN');
827  $GLOBALS['SQ_SYSTEM']->am->includeAsset('bodycopy');
828 
829  $copy_link = Array('asset' => &$folder, 'value' => $new_type, 'link_type' => SQ_LINK_TYPE_2, 'is_dependant' => 1, 'is_exclusive' => 1);
830 
831  $bodycopy = new Bodycopy();
832  $bodycopy->setAttrValue('name', $GLOBALS['SQ_SYSTEM']->am->getTypeInfo($new_type, 'name').' Format');
833 
834  if (!$bodycopy->create($copy_link)) {
835  $GLOBALS['SQ_SYSTEM']->doTransaction('ROLLBACK');
836  $GLOBALS['SQ_SYSTEM']->restoreDatabaseConnection();
837  return FALSE;
838  }
839  $GLOBALS['SQ_SYSTEM']->doTransaction('COMMIT');
840  $GLOBALS['SQ_SYSTEM']->restoreDatabaseConnection();
841  } else {
842  trigger_localised_error('CMS0046', E_USER_WARNING, $new_type);
843  }
844  }
845  if (isset($asset->_tmp['formats']['type_formats'])) {
846  unset($asset->_tmp['formats']['type_formats']);
847  }
848 
849  return FALSE;
850 
851  }//end processTypeFormats()
852 
853 
864  function paintPositionFormats(&$asset, &$o, $prefix)
865  {
866  $write_access = $asset->writeAccess('links');
867  $formats = $asset->getFormats('position_formats');
868 
869  if (!empty($formats)) {
870  ?>
871  <table class="sq-backend-table">
872  <tr>
873  <th><?php echo translate('position') ?></th>
874  <th><?php echo translate('edit_format') ?></th>
875  <?php
876  if ($write_access) {
877  ?><th><?php echo translate('delete_question') ?></th><?php
878  }
879  ?>
880  </tr>
881  <?php
882  foreach ($formats as $minorid => $value) {
883  $info = Array($minorid => 'contents');
884  $href = $GLOBALS['SQ_SYSTEM']->am->getAssetBackendHref($info);
885  $position = substr($value, 9);
886  ?>
887  <tr>
888  <td style="width: 200px;">
889  <?php
890  echo $position;
891  ?>
892  </td>
893  <td>
894  <?php
895  echo get_asset_tag_line($minorid, 'contents');
896  ?>
897  </td>
898  <?php
899  if ($write_access) {
900  ?>
901  <td style="width: 100px;">
902  <?php
903  check_box($prefix.'_delete_position['.$position.']');
904  ?>
905  </td>
906  <?php
907  }
908  ?>
909  </tr>
910  <?php
911  }//end foreach
912  ?>
913  </table>
914  <?php
915  } else {
916  echo translate('cms_listing_no_position_formats');
917  }
918 
919  if ($write_access) {
920  echo '<p><b>'.translate('cms_listing_new_position_format').'</b> ';
921  text_box($prefix.'_new_position', '', 5);
922  echo '</p>';
923  }
924 
925  return $write_access;
926 
927  }//end paintPositionFormats()
928 
929 
940  function processPositionFormats(&$asset, &$o, $prefix)
941  {
942  $folder = $asset->getFolder('position_formats');
943 
944  $deleted_formats = array_get_index($_POST, $prefix.'_delete_position', Array());
945  $new_position = (int) array_get_index($_POST, $prefix.'_new_position', 0);
946  if (isset($deleted_formats[$new_position])) {
947  trigger_localised_error('CMS0047', E_USER_WARNING, $new_position);
948  unset($deleted_formats[$new_position]);
949  $new_position = 0;
950  }
951 
952  foreach ($deleted_formats as $position => $on) {
953  $current_link = $GLOBALS['SQ_SYSTEM']->am->getLink($folder->id, SQ_LINK_TYPE_2, 'bodycopy', TRUE, 'position_'.$position);
954  if (empty($current_link)) {
955  trigger_localised_error('CMS0048', E_USER_WARNING, $position);
956  } else {
957  if (!$GLOBALS['SQ_SYSTEM']->am->deleteAssetLink($current_link['linkid'])) {
958  trigger_localised_error('CMS0049', E_USER_WARNING, $position);
959  }
960  }
961  }
962 
963  if ($new_position != 0) {
964  // check that this position isnt already customised
965  $current_link = $GLOBALS['SQ_SYSTEM']->am->getLink($folder->id, SQ_LINK_TYPE_2, 'bodycopy', TRUE, 'position_'.$new_position);
966  if (empty($current_link)) {
967 
968  // create a new format bodycopy for this list position
969  $GLOBALS['SQ_SYSTEM']->changeDatabaseConnection('db2');
970  $GLOBALS['SQ_SYSTEM']->doTransaction('BEGIN');
971  $GLOBALS['SQ_SYSTEM']->am->includeAsset('bodycopy');
972 
973  $copy_link = Array('asset' => &$folder, 'value' => 'position_'.$new_position, 'link_type' => SQ_LINK_TYPE_2, 'is_dependant' => 1, 'is_exclusive' => 1);
974 
975  $bodycopy = new Bodycopy();
976  $bodycopy->setAttrValue('name', translate('cms_listing_position_number_format', $new_position));
977 
978  if (!$bodycopy->create($copy_link)) {
979  $GLOBALS['SQ_SYSTEM']->doTransaction('ROLLBACK');
980  $GLOBALS['SQ_SYSTEM']->restoreDatabaseConnection();
981  return FALSE;
982  }
983  $GLOBALS['SQ_SYSTEM']->doTransaction('COMMIT');
984  $GLOBALS['SQ_SYSTEM']->restoreDatabaseConnection();
985  } else {
986  trigger_localised_error('CMS0050', E_USER_POSITION, $new_position);
987  }
988  }
989  if (isset($asset->_tmp['formats']['position_formats'])) {
990  unset($asset->_tmp['formats']['position_formats']);
991  }
992  return FALSE;
993 
994  }//end processPositionFormats()
995 
996 
1007  function paintSortOptions(&$asset, &$o, $prefix)
1008  {
1009  // If random grouping is on, no sorting allowed
1010  if ($asset->attr('group_by') == 'random') {
1011  $o->openRaw();
1012  echo translate('cms_listing_random_selected_no_sort');
1013  $o->closeRaw();
1014  return FALSE;
1015  }
1016 
1017  // If no types, no sorting!
1018  $types = $asset->attr('types');
1019  if (empty($types)) {
1020  $o->openRaw();
1021  echo translate('cms_listing_no_types_no_sort');
1022  $o->closeRaw();
1023  return FALSE;
1024  }
1025 
1026  $wa = $asset->writeAccess('attributes');
1027 
1028  $o->openSection(translate('cms_listing_sort_by_standard_field'));
1029  $this->_paintStandardFieldSortOptions($asset, $o, $prefix.'_std_sort_options');
1030  $o->closeSection(); // end standard asset fields
1031 
1032  $o->openSection(translate('cms_listing_sort_by_attribute'));
1033  $this->_paintAttributeSortOptions($asset, $o, $prefix.'_attr_sort_options');
1034  $o->closeSection(); // end asset attributes
1035 
1036  $o->openSection(translate('cms_listing_sort_by_metadata_field'));
1037  $this->_paintMetadataSortOptions($asset, $o, $prefix.'_metadata_sort_options');
1038  $o->closeSection(); // end metadata
1039 
1040  $o->openSection(('Sorting by Asset Keyword Value'));
1041  $this->_paintKeywordSortOptions($asset, $o, $prefix.'_keyword_sort_options');
1042  $o->closeSection(); // end keyword options
1043 
1044  $o->openSection(translate('cms_listing_sort_by_extras'));
1045  $this->_paintExtraSortOptions($asset, $o, $prefix.'_extra_sort_options');
1046  $o->closeSection(); // end extra options
1047 
1048 
1049 
1050  return $wa;
1051 
1052  }//end paintSortOptions()
1053 
1054 
1065  function processSortOptions(&$asset, &$o, $prefix)
1066  {
1067  $this->_tmp['previous_sort_options'] = $asset->attr('sort_by');
1068 
1069  $res = FALSE;
1070  $res = $this->_processStandardFieldSortOptions($asset, $o, $prefix.'_std_sort_options') || $res;
1071  $res = $this->_processAttributeSortOptions($asset, $o, $prefix.'_attr_sort_options') || $res;
1072  $res = $this->_processMetadataSortOptions($asset, $o, $prefix.'_metadata_sort_options') || $res;
1073  $res = $this->_processKeywordSortOptions($asset, $o, $prefix.'_keyword_sort_options') || $res;
1074  $res = $this->_processExtraSortOptions($asset, $o, $prefix.'_extra_sort_options') || $res;
1075 
1076  if ($res) {
1077  // renumber
1078  return $asset->setAttrValue('sort_by', array_values($asset->attr('sort_by')));
1079  }
1080  return FALSE;
1081 
1082  }//end processSortOptions()
1083 
1084 
1095  function _paintStandardFieldSortOptions(&$asset, &$o, $prefix)
1096  {
1097  $wa = $asset->writeAccess('attributes');
1098  $sort_by_options = $this->_getStandardSortByOptions($asset);
1099  $o->openField($wa ? translate('current') : '');
1100  $fields = Array();
1101  foreach ($asset->attr('sort_by') as $option_id => $info) {
1102  if ($info['type'] == 'field') {
1103  $fields[$option_id] = $info;
1104  }
1105  }
1106  if (!empty($fields)) {
1107  ?>
1108  <table class="sq-backend-table" >
1109  <tr>
1110  <th style="width: 60ex"><?php echo translate('asset_field'); ?></td>
1111  <th><?php echo translate('display_name') ?></th>
1112  <?php
1113  if ($wa) {
1114  ?>
1115  <th style="width: 12ex"><?php echo translate('remove_question'); ?></td>
1116  <?php
1117  }
1118  ?>
1119  </tr>
1120  <?php
1121  foreach ($fields as $id => $info) {
1122  if (empty($sort_by_options[$info['params']['field']])) {
1123  continue;
1124  }
1125  ?>
1126  <tr>
1127  <td>
1128  <?php
1129  echo $sort_by_options[$info['params']['field']];
1130  ?>
1131  </td>
1132  <td>
1133  <?php
1134  if ($wa) {
1135  text_box($prefix.'_current['.$id.'][name]', $info['name']);
1136  } else {
1137  echo array_get_index($info, 'name', '');
1138  }
1139  ?>
1140  </td>
1141  <?php
1142  if ($wa) {
1143  ?>
1144  <td>
1145  <?php
1146  check_box($prefix.'_current['.$id.'][remove]', '1');
1147  ?>
1148  </td>
1149  <?php
1150  }
1151  ?>
1152  </tr>
1153  <?php
1154  }//end foreach
1155  ?>
1156  </table>
1157  <?php
1158  } else {
1159  echo translate('cms_listing_sort_by_standard_field_none');
1160  }
1161  $o->closeField();
1162 
1163  if ($wa) {
1164  $o->openField(translate('new'));
1165  ?>
1166  <table class="sq-backend-table" style="width: 60ex">
1167  <tr>
1168  <th style="width: 20ex"><?php echo translate('asset_field'); ?></th>
1169  <td>
1170  <?php
1171  combo_box($prefix.'_new[field]', $sort_by_options, FALSE, '');
1172  ?>
1173  </td>
1174  </tr>
1175  <tr>
1176  <th><?php echo translate('display_name'); ?></th>
1177  <td><?php text_box($prefix.'_new[name]', ''); ?></td>
1178  </tr>
1179  </table>
1180  <?php
1181  $o->closeField();
1182  }
1183 
1184  }//end _paintStandardFieldSortOptions()
1185 
1186 
1197  function _processStandardFieldSortOptions(&$asset, &$o, $prefix)
1198  {
1199  $val = $asset->attr('sort_by');
1200  $res = FALSE;
1201  if (!empty($_POST[$prefix.'_current'])) {
1202  foreach ($_POST[$prefix.'_current'] as $i => $details) {
1203  if (!empty($details['remove'])) {
1204  unset($val[$i]);
1205  } else {
1206  $val[$i]['name'] = $details['name'];
1207  }
1208  }
1209  $res = TRUE;
1210  }
1211  if (!empty($_POST[$prefix.'_new']['name'])) {
1212  $option = Array(
1213  'type' => 'field',
1214  'name' => $_POST[$prefix.'_new']['name'],
1215  'params' => Array('field' => $_POST[$prefix.'_new']['field']),
1216  );
1217  $this->_addNewSortOption($val, $option);
1218  $res = TRUE;
1219  }
1220  if ($res) {
1221  return $asset->setAttrValue('sort_by', $val);
1222  }
1223  return FALSE;
1224 
1225  }//end _processStandardFieldSortOptions()
1226 
1227 
1238  function _paintAttributeSortOptions(&$asset, &$o, $prefix)
1239  {
1240  $wa = $asset->writeAccess('attributes');
1241  $types = $asset->attr('types');
1242  $type_info = $GLOBALS['SQ_SYSTEM']->am->getTypeInfo(array_keys($types), 'name');
1243 
1244 
1245  $o->openField($wa ? translate('current') : '');
1246 
1247  $attrs = Array();
1248  foreach ($asset->attr('sort_by') as $id => $info) {
1249  if ($info['type'] == 'asset_attrib') {
1250  $attrs[$id] = $info;
1251  }
1252  }
1253 
1254  if (!empty($attrs)) {
1255  ?>
1256  <table class="sq-backend-table">
1257  <tr>
1258  <th style="width: 30ex"><?php echo translate('asset_type'); ?></th>
1259  <th style="width: 30ex; padding-left: 0px; padding-right: 0px"><?php echo translate('attribute_name'); ?></th>
1260  <th><?php echo translate('display_name') ?></th>
1261  <?php
1262  if ($wa) {
1263  ?>
1264  <th style="width: 12ex"><?php echo translate('remove_question'); ?></th>
1265  <?php
1266  }
1267  ?>
1268  </tr>
1269  <?php
1270  foreach ($attrs as $id => $info) {
1271  ?>
1272  <tr>
1273  <td>
1274  <?php
1275  if ($wa) {
1276  combo_box($prefix.'_current['.$id.'][type_code]', $type_info, FALSE, $info['params']['type_code']);
1277  } else {
1278  echo get_asset_type_icon($info['params']['type_code']);
1279  echo $type_info[$info['params']['type_code']];
1280  }
1281  ?>
1282  </td>
1283  <td>
1284  <?php
1285  $attributes = $GLOBALS['SQ_SYSTEM']->am->getAssetTypeAttributes($info['params']['type_code']);
1286  $display_attributes = Array();
1287  foreach (array_keys($attributes) as $attribute) {
1288  $display_attributes[$attribute] = ucwords(str_replace('_', ' ', $attribute));
1289  }
1290  if ($wa) {
1291  combo_box($prefix.'_current['.$id.'][attribute]', $display_attributes, FALSE, $info['params']['attribute']);
1292  } else {
1293  echo $display_attributes[$info['params']['attribute']];
1294  }
1295  ?>
1296  </td>
1297  <td>
1298  <?php
1299  if ($wa) {
1300  text_box($prefix.'_current['.$id.'][name]', $info['name']);
1301  } else {
1302  echo array_get_index($info, 'name', '');
1303  }
1304  ?>
1305  </td>
1306  <?php
1307  if ($wa) {
1308  ?>
1309  <td>
1310  <?php
1311  check_box($prefix.'_current['.$id.'][remove]', '1');
1312  ?>
1313  </td>
1314  <?php
1315  }
1316  ?>
1317  </tr>
1318  <?php
1319  }//end foreach
1320  ?>
1321  </table>
1322  <?php
1323  } else {
1324  echo translate('cms_listing_sort_by_attribute_none');
1325  }
1326  $o->closeField();
1327 
1328  if ($wa) {
1329  $o->openField(translate('new'));
1330  ?>
1331  <table class="sq-backend-table" style="width: 60ex">
1332  <tr>
1333  <th style="width: 20ex"><?php echo translate('asset_type'); ?></th>
1334  <td>
1335  <?php
1336  $types = $asset->attr('types');
1337  $type_info = $GLOBALS['SQ_SYSTEM']->am->getTypeInfo(array_keys($types), 'name');
1338  combo_box($prefix.'_new[type_code]', $type_info, FALSE);
1339  ?>
1340  </td>
1341  </tr>
1342  <tr>
1343  <th><?php echo translate('display_name'); ?></th>
1344  <td><?php text_box($prefix.'_new[name]', ''); ?></td>
1345  </tr>
1346  </table>
1347  <?php
1348  $o->closeField();
1349  }
1350 
1351  }//end _paintAttributeSortOptions()
1352 
1353 
1364  function _processAttributeSortOptions(&$asset, &$o, $prefix)
1365  {
1366  $val = $asset->attr('sort_by');
1367  $res = FALSE;
1368 
1369  if (!empty($_POST[$prefix.'_current'])) {
1370  foreach ($_POST[$prefix.'_current'] as $i => $details) {
1371  if (!empty($details['remove'])) {
1372  unset($val[$i]);
1373  } else {
1374  $val[$i]['name'] = $details['name'];
1375  $val[$i]['params']['type_code'] = $details['type_code'];
1376  $attributes = $GLOBALS['SQ_SYSTEM']->am->getAssetTypeAttributes($details['type_code']);
1377  if (isset($attributes[$details['attribute']])) {
1378  $val[$i]['params']['attribute'] = $details['attribute'];
1379  $val[$i]['params']['attr_type'] = $attributes[$val[$i]['params']['attribute']];
1380  } else {
1381  $val[$i]['params']['attribute'] = reset(array_keys($attributes));
1382  }
1383  }
1384  }
1385  $res = TRUE;
1386  }
1387 
1388  if (!empty($_POST[$prefix.'_new']['name'])) {
1389  $attributes = $GLOBALS['SQ_SYSTEM']->am->getAssetTypeAttributes($_POST[$prefix.'_new']['type_code']);
1390  if (empty($attributes)) {
1391  trigger_localised_error('CMS0110', E_USER_WARNING);
1392  } else {
1393  $default_attr = array_shift(array_keys($attributes));
1394  $option = Array(
1395  'type' => 'asset_attrib',
1396  'name' => $_POST[$prefix.'_new']['name'],
1397  'params' => Array(
1398  'type_code' => $_POST[$prefix.'_new']['type_code'],
1399  'attribute' => $default_attr,
1400  'attr_type' => $attributes[$default_attr],
1401  ),
1402  );
1403  $this->_addNewSortOption($val, $option);
1404  $res = TRUE;
1405  }//end if
1406  }
1407 
1408  if ($res) {
1409  return $asset->setAttrValue('sort_by', $val);
1410  }
1411  return FALSE;
1412 
1413  }//end _processAttributeSortOptions()
1414 
1415 
1426  function _paintMetadataSortOptions(&$asset, &$o, $prefix)
1427  {
1428  $wa = $asset->writeAccess('attributes');
1429  $o->openField($wa ? translate('current') : '');
1430  $meta_datas = Array();
1431  foreach ($asset->attr('sort_by') as $id => $info) {
1432  if ($info['type'] == 'metadata') {
1433  $meta_datas[$id] = $info;
1434  }
1435  }
1436 
1437  if (!empty($meta_datas)) {
1438  ?>
1439  <table class="sq-backend-table">
1440  <tr>
1441  <th style="width: 60ex"><?php echo translate('metadata_field'); ?></th>
1442  <th><?php echo translate('display_name') ?></th>
1443  <?php
1444  if ($wa) {
1445  ?>
1446  <th style="width: 12ex"><?php echo translate('remove_question'); ?></th>
1447  <?php
1448  }
1449  ?>
1450  </tr>
1451  <?php
1452  foreach ($meta_datas as $id => $info) {
1453  ?>
1454  <tr>
1455  <td>
1456  <?php
1457  if ($wa) {
1458  asset_finder($prefix.'_current['.$id.'][field]',$info['field'],Array('metadata_field' => 'D'));
1459  } else {
1460  echo get_asset_tag_line($info['field']);
1461  }
1462  ?>
1463  </td>
1464  <td>
1465  <?php
1466  if ($wa) {
1467  text_box($prefix.'_current['.$id.'][name]', array_get_index($info,'name',''));
1468  } else {
1469  echo array_get_index($info, 'name', '');
1470  }
1471  ?>
1472  </td>
1473  <?php
1474  if ($wa) {
1475  ?>
1476  <td>
1477  <?php
1478  check_box($prefix.'_current['.$id.'][remove]', '1');
1479  ?>
1480  </td>
1481  <?php
1482  }
1483  ?>
1484  </tr>
1485  <?php
1486  }//end foreach
1487  ?>
1488  </table>
1489  <?php
1490  } else {
1491  echo translate('cms_listing_sort_by_metadata_field_none');
1492  }
1493  $o->closeField();
1494  if ($wa) {
1495  $o->openField(translate('new'));
1496  ?>
1497  <table class="sq-backend-table" style="width: 60ex">
1498  <tr>
1499  <th style="width: 20ex"><?php echo translate('metadata_field'); ?></th>
1500  <td><?php asset_finder($prefix.'_new[field]',0,Array('metadata_field' => 'D')); ;?></td>
1501  </tr>
1502  <tr>
1503  <th><?php echo translate('display_name'); ?></th>
1504  <td><?php text_box($prefix.'_new[name]', ''); ?></td>
1505  </tr>
1506  </table>
1507  <?php
1508  $o->closeField();
1509  }
1510 
1511  }//end _paintMetadataSortOptions()
1512 
1513 
1524  function _processMetadataSortOptions(&$asset, &$o, $prefix)
1525  {
1526  $val = $asset->attr('sort_by');
1527  $res = FALSE;
1528 
1529  if (!empty($_POST[$prefix.'_current'])) {
1530  foreach ($_POST[$prefix.'_current'] as $i => $details) {
1531  if (!empty($details['remove'])) {
1532  unset($val[$i]);
1533  } else {
1534  $val[$i]['name'] = $details['name'];
1535  if (!empty($details['field']['assetid'])) {
1536  $val[$i]['field'] = $details['field']['assetid'];
1537  }
1538  }
1539  }
1540  $res = TRUE;
1541  }
1542 
1543  if (!empty($_POST[$prefix.'_new']['name']) && !empty($_POST[$prefix.'_new']['field']['assetid'])) {
1544  $option = Array(
1545  'type' => 'metadata',
1546  'name' => $_POST[$prefix.'_new']['name'],
1547  'field' => $_POST[$prefix.'_new']['field']['assetid'],
1548  'params' => Array(),
1549  );
1550  $this->_addNewSortOption($val, $option);
1551  $res = TRUE;
1552  }
1553 
1554  if ($res) {
1555  return $asset->setAttrValue('sort_by', $val);
1556  }
1557  return FALSE;
1558 
1559  }//end _processMetadataSortOptions()
1560 
1561 
1572  function _paintKeywordSortOptions(&$asset, &$o, $prefix)
1573  {
1574  $wa = $asset->writeAccess('attributes');
1575  $o->openField($wa ? translate('current') : '');
1576  $keyword_datas = Array();
1577  foreach ($asset->attr('sort_by') as $id => $info) {
1578  if ($info['type'] == 'keyword') {
1579  $keyword_datas[$id] = $info;
1580  }
1581  }
1582 
1583  if (!empty($keyword_datas)) {
1584  ?>
1585  <table class="sq-backend-table">
1586  <tr>
1587  <th style="width: 60ex"><?php echo ('Keyword'); ?></th>
1588  <th><?php echo translate('display_name') ?></th>
1589  <?php
1590  if ($wa) {
1591  ?>
1592  <th style="width: 12ex"><?php echo translate('remove_question'); ?></th>
1593  <?php
1594  }
1595  ?>
1596  </tr>
1597  <?php
1598  foreach ($keyword_datas as $id => $info) {
1599  ?>
1600  <tr>
1601  <td>
1602  <?php
1603  if ($wa) {
1604  text_box($prefix.'_current['.$id.'][keyword]', array_get_index($info,'keyword',''));
1605  } else {
1606  echo array_get_index($info, 'name', '');
1607  }
1608  ?>
1609  </td>
1610  <td>
1611  <?php
1612  if ($wa) {
1613  text_box($prefix.'_current['.$id.'][name]', array_get_index($info,'name',''));
1614  } else {
1615  echo array_get_index($info, 'name', '');
1616  }
1617  ?>
1618  </td>
1619  <?php
1620  if ($wa) {
1621  ?>
1622  <td>
1623  <?php
1624  check_box($prefix.'_current['.$id.'][remove]', '1');
1625  ?>
1626  </td>
1627  <?php
1628  }
1629  ?>
1630  </tr>
1631  <?php
1632  }//end foreach
1633  ?>
1634  </table>
1635  <?php
1636  } else {
1637  echo translate('cms_listing_sort_by_keyword_field_none');
1638  }
1639  $o->closeField();
1640  if ($wa) {
1641  $o->openField(translate('new'));
1642  ?>
1643  <table class="sq-backend-table" style="width: 60ex">
1644  <tr>
1645  <th style="width: 20ex"><?php echo translate('keyword'); ?></th>
1646  <td><?php text_box($prefix.'_new[keyword]', ''); ?></td>
1647  </tr>
1648  <tr>
1649  <th><?php echo translate('display_name'); ?></th>
1650  <td><?php text_box($prefix.'_new[name]', ''); ?></td>
1651  </tr>
1652  </table>
1653  <?php
1654  $o->closeField();
1655  }
1656 
1657  }//end _paintKeywordSortOptions()
1658 
1659 
1670  function _processKeywordSortOptions(&$asset, &$o, $prefix)
1671  {
1672  $val = $asset->attr('sort_by');
1673  $res = FALSE;
1674 
1675  if (!empty($_POST[$prefix.'_current'])) {
1676  foreach ($_POST[$prefix.'_current'] as $i => $details) {
1677  if (!empty($details['remove'])) {
1678  unset($val[$i]);
1679  } else {
1680  $val[$i]['name'] = $details['name'];
1681  if (!empty($details['keyword'])) {
1682  $val[$i]['keyword'] = $details['keyword'];
1683  }
1684  }
1685  }
1686  $res = TRUE;
1687  }
1688 
1689  if (!empty($_POST[$prefix.'_new']['name']) && !empty($_POST[$prefix.'_new']['keyword'])) {
1690  $option = Array(
1691  'type' => 'keyword',
1692  'name' => $_POST[$prefix.'_new']['name'],
1693  'keyword' => $_POST[$prefix.'_new']['keyword'],
1694  'params' => Array(),
1695  );
1696  $this->_addNewSortOption($val, $option);
1697  $res = TRUE;
1698  }
1699 
1700  if ($res) {
1701  return $asset->setAttrValue('sort_by', $val);
1702  }
1703  return FALSE;
1704 
1705 
1706  }//end _processKeywordSortOptions()
1707 
1708 
1719  function _paintExtraSortOptions(&$asset, &$o, $prefix)
1720  {
1721  $wa = $asset->writeAccess('attributes');
1722  if ($wa) $o->addHiddenField($prefix.'_submitted', 1);
1723 
1724  $o->openField(translate('cms_listing_random_sort'));
1725  $random_enabled = FALSE;
1726  foreach ($asset->attr('sort_by') as $v) {
1727  if ($v['name'] == 'Random') {
1728  $random_enabled = TRUE;
1729  break;
1730  }
1731  }
1732  if ($wa) {
1733  check_box($prefix.'_enable_random', '1', $random_enabled);
1734  label(translate('cms_listing_enable_random_sort'), $prefix.'_enable_random');
1735  } else {
1736  $filename = $random_enabled ? 'tick' : 'cross';
1737  echo '<img src="'.sq_web_path('lib').'/web/images/'.$filename.'.gif" /> ';
1738  echo translate('cms_listing_enable_random_sort');
1739  }
1740  $o->closeField();
1741  $o->openField(translate('cms_listing_no_sort'));
1742  $nosort_enabled = FALSE;
1743  foreach ($asset->attr('sort_by') as $v) {
1744  if ($v['name'] == 'No Sorting') {
1745  $nosort_enabled = TRUE;
1746  break;
1747  }
1748  }
1749  if ($wa) {
1750  check_box($prefix.'_enable_nosort', '1', $nosort_enabled);
1751  label(translate('cms_listing_enable_no_sort'), $prefix.'_enable_nosort');
1752  } else {
1753  $filename = $nosort_enabled ? 'tick' : 'cross';
1754  echo '<img src="'.sq_web_path('lib').'/web/images/'.$filename.'.gif" /> ';
1755  echo translate('cms_listing_enable_no_sort');
1756  }
1757  $o->closeField();
1758 
1759  }//end _paintExtraSortOptions()
1760 
1761 
1772  function _processExtraSortOptions(&$asset, &$o, $prefix)
1773  {
1774  $val = $asset->attr('sort_by');
1775  if (isset($_POST[$prefix.'_submitted'])) {
1776  $want_random = !empty($_POST[$prefix.'_enable_random']);
1777  $random_index = FALSE;
1778  foreach ($val as $i => $v) {
1779  if ($v['name'] == 'Random') {
1780  $random_index = $i;
1781  break;
1782  }
1783  }
1784  if (($random_index !== FALSE) && !$want_random) {
1785  unset($val[$random_index]);
1786  } else if (($random_index === FALSE) && $want_random) {
1787  $val[] = Array(
1788  'name' => 'Random',
1789  'type' => '',
1790  'field' => '',
1791  'params' => '',
1792  );
1793  }
1794 
1795  $want_nosort = !empty($_POST[$prefix.'_enable_nosort']);
1796  $nosort_index = FALSE;
1797  foreach ($val as $i => $v) {
1798  if ($v['name'] == 'No Sorting') {
1799  $nosort_index = $i;
1800  break;
1801  }
1802  }
1803  if (($nosort_index !== FALSE) && !$want_nosort) {
1804  unset($val[$nosort_index]);
1805  } else if (($nosort_index === FALSE) && $want_nosort) {
1806  $val[] = Array(
1807  'name' => 'No Sorting',
1808  'type' => '',
1809  'field' => '',
1810  'params' => '',
1811  );
1812  }
1813  return $asset->setAttrValue('sort_by', $val);
1814  }//end if
1815  return FALSE;
1816 
1817  }//end _processExtraSortOptions()
1818 
1819 
1832  function _addNewSortOption(&$options, $new_option)
1833  {
1834  $last = end($options);
1835  $ending = Array();
1836  while (($last['name'] == 'Random') || ($last['name'] == 'No Sorting')) {
1837  array_unshift($ending, $last);
1838  array_pop($options);
1839  $last = end($options);
1840  }
1841  $options = array_merge($options, Array($new_option), $ending);
1842 
1843  }//end _addNewSortOption()
1844 
1845 
1856  function paintMetadataSortType(&$asset, &$o, $prefix)
1857  {
1858  $write_access = $asset->writeAccess('attributes');
1859  $sort_by = $asset->attr('metadata_sort_type');
1860 
1861  $option = Array(
1862  'raw' => 'Raw Value',
1863  'presentation' => 'Presentation Value',
1864  );
1865 
1866  if ($write_access) {
1867  combo_box($prefix.'_metadata_sort_type', $option, FALSE, $sort_by);
1868  } else {
1869  echo ($sort_by == 'raw') ? 'Raw Value' : 'Presentation Value';
1870  }
1871 
1872  return $write_access;
1873 
1874  }//end paintMetadataSortType()
1875 
1876 
1887  function processMetadataSortType(&$asset, &$o, $prefix)
1888  {
1889  // check to see if the default has changed
1890  if (isset($_POST[$prefix.'_metadata_sort_type'])) {
1891  return $asset->setAttrValue('metadata_sort_type', $_POST[$prefix.'_metadata_sort_type']);
1892  }
1893  return FALSE;
1894 
1895  }//end processMetadataSortType()
1896 
1897 
1908  function paintDefaultSortByOption(&$asset, &$o, $prefix)
1909  {
1910  $write_access = $asset->writeAccess('attributes');
1911  $sort_by_list = $asset->attr('sort_by');
1912 
1913  if (empty($sort_by_list)) {
1914  echo translate('cms_listing_no_sorting_applied');
1915  return FALSE;
1916  }
1917  $last_index = count($sort_by_list) - 1;
1918  $names = Array();
1919  $default = $asset->attr('default_sort_by');
1920 
1921  foreach ($sort_by_list as $id => $info) {
1922  $names[$id] = $info['name'];
1923  }
1924 
1925  if ($write_access) {
1926  combo_box($prefix.'_default_sort', $names, FALSE, $default);
1927  } else {
1928  if (isset($sort_by_list[$default]['name'])) {
1929  echo $sort_by_list[$default]['name'];
1930  }
1931  }
1932 
1933  return $write_access;
1934 
1935  }//end paintDefaultSortByOption()
1936 
1937 
1948  function processDefaultSortByOption(&$asset, &$o, $prefix)
1949  {
1950  // check to see if the default has changed
1951  if (isset($_POST[$prefix.'_default_sort'])) {
1952  $new_default_index = $_POST[$prefix.'_default_sort'];
1953  $new_sort_order = $asset->attr('sort_by');
1954  $old_sort_order = $this->_tmp['previous_sort_options'];
1955  $new_default_entry = array_get_index($new_sort_order, $new_default_index, -1);
1956  $old_default_entry = $old_sort_order[$new_default_index];
1957  unset($new_default_entry['name']);
1958  unset($old_default_entry['name']);
1959  if ($new_default_entry != $old_default_entry) {
1960  // the chosen default has been moved to a new spot,
1961  // or the number of options has changed,
1962  // so we'll have to search for the new index by characteristics
1963  // If they've renamed it this will still work, but if they've
1964  // changed its characteristics we won't find it, bad luck.
1965  foreach ($new_sort_order as $i => $v) {
1966  unset($v['name']);
1967  if ($v == $old_default_entry) {
1968  // everything matches except maybe the name
1969  $new_default_index = $i;
1970  break;
1971  }
1972  }
1973  }
1974  return $asset->setAttrValue('default_sort_by', $new_default_index);
1975  }
1976  return FALSE;
1977 
1978  }//end processDefaultSortByOption()
1979 
1980 
1991  function paintSortOptionOrder(&$asset, &$o, $prefix)
1992  {
1993  $write_access = $asset->writeAccess('attributes');
1994  $sort_by_list = $asset->attr('sort_by');
1995 
1996  if (empty($sort_by_list)) {
1997  echo translate('cms_listing_no_sort_by_options');
1998  return FALSE;
1999  }
2000 
2001  // If no types, no sorting!
2002  $types = $asset->attr('types');
2003  if (empty($types)) {
2004  echo translate('cms_listing_no_types_no_sort');
2005  return FALSE;
2006  }
2007 
2008  ?>
2009  <script type="text/javascript">
2010  function sortOrderMoveDown(currentOrder) {
2011  if (!document.getElementById) {
2012  alert(js_translate('brower_does_not_support_getelementbyid'));
2013  return;
2014  }
2015 
2016  var currentElement = document.getElementById('<?php echo $prefix ?>_sort_order_' + currentOrder);
2017  var nextElement = document.getElementById('<?php echo $prefix ?>_sort_order_' + (currentOrder + 1));
2018 
2019  // if there is no next element, then this is the last one; we shouldn't be running
2020  if (!nextElement) return;
2021 
2022  if (!currentElement.innerHTML) {
2023  alert(js_translate('brower_does_not_support_innerhtml'));
2024  return;
2025  }
2026 
2027  var table = currentElement.parentNode;
2028  while (table.tagName != 'TABLE') {
2029  table = table.parentNode;
2030  }
2031  table.style.border = '2px dashed #7B9EBD';
2032 
2033  // switch the question names
2034  var temp = currentElement.innerHTML;
2035  currentElement.innerHTML = nextElement.innerHTML;
2036  nextElement.innerHTML = temp;
2037 
2038  var currOrder = document.getElementById('<?php echo $prefix; ?>_sort_order_list[' + currentOrder +']');
2039  var prevOrder = document.getElementById('<?php echo $prefix; ?>_sort_order_list[' + (currentOrder + 1) +']');
2040 
2041  var temp = prevOrder.value;
2042  prevOrder.value = currOrder.value;
2043  currOrder.value = temp;
2044  }
2045 
2046  function sortOrderMoveUp(currentOrder) {
2047  if (!document.getElementById) {
2048  alert(js_translate('brower_does_not_support_getelementbyid'));
2049  return;
2050  }
2051 
2052  if (currentOrder == 0) return;
2053 
2054  var currentElement = document.getElementById('<?php echo $prefix ?>_sort_order_' + currentOrder);
2055  var prevElement = document.getElementById('<?php echo $prefix ?>_sort_order_' + (currentOrder - 1));
2056 
2057  if (!currentElement.innerHTML) {
2058  alert(js_translate('brower_does_not_support_innerhtml'));
2059  return;
2060  }
2061 
2062  var table = currentElement.parentNode;
2063  while (table.tagName != 'TABLE') {
2064  table = table.parentNode;
2065  }
2066  table.style.border = '2px dashed #7B9EBD';
2067 
2068  // switch the question names
2069  var temp = currentElement.innerHTML;
2070  currentElement.innerHTML = prevElement.innerHTML;
2071  prevElement.innerHTML = temp;
2072 
2073  var currOrder = document.getElementById('<?php echo $prefix; ?>_sort_order_list[' + currentOrder +']');
2074  var prevOrder = document.getElementById('<?php echo $prefix; ?>_sort_order_list[' + (currentOrder - 1) +']');
2075 
2076  var temp = prevOrder.value;
2077  prevOrder.value = currOrder.value;
2078  currOrder.value = temp;
2079  }
2080  </script>
2081  <table class="sq-backend-table" style="width: 50%;">
2082  <tr>
2083  <th><?php echo translate('cms_listing_sort_option_name'); ?></th>
2084  <?php
2085  if ($write_access) {
2086  ?><th colspan="2" style="width: 8ex"><?php echo translate('order'); ?></th><?php
2087  }
2088  ?>
2089  </tr>
2090  <?php
2091  $i = 0;
2092  foreach ($sort_by_list as $id => $info) {
2093  ?>
2094  <tr>
2095  <td>
2096  <?php
2097  hidden_field($prefix.'_sort_order_list['.$id.']', $id); ?>
2098  <span id ="<?php echo $prefix ?>_sort_order_<?php echo $id; ?>"><?php echo $info['name']; ?></span>
2099  </td>
2100  <?php
2101  if ($write_access) {
2102  ?>
2103  <td>
2104  <?php
2105  if ($i != 0) {
2106  sq_print_icon(sq_web_path('lib').'/web/images/icons/up_arrow.png', 16, 16, translate('move_up'), NULL, 'class="clickable" onclick="sortOrderMoveUp('.$id.')"');
2107  }
2108  ?>
2109  </td>
2110  <td>
2111  <?php
2112  if ($i != count($sort_by_list)-1) {
2113  sq_print_icon(sq_web_path('lib').'/web/images/icons/down_arrow.png', 16, 16, translate('move_down'), NULL, 'class="clickable" onclick="sortOrderMoveDown('.$id.')"');
2114  }
2115  ?>
2116  </td>
2117  <?php
2118  }
2119  ?>
2120  </tr>
2121  <?php
2122 
2123  $i++;
2124  }//end foreach
2125  ?>
2126  </table>
2127  <?php
2128  return $write_access;
2129 
2130  }//end paintSortOptionOrder()
2131 
2132 
2143  function processSortOptionOrder(&$asset, &$o, $prefix)
2144  {
2145  $sort_by_list = $asset->attr('sort_by');
2146  if (isset($_POST[$prefix.'_sort_order_list'])) {
2147  $sort_order = $_POST[$prefix.'_sort_order_list'];
2148  $save_list = Array();
2149  $i = 0;
2150  foreach ($sort_order as $id => $order) {
2151  if (empty($sort_by_list[$order])) {
2152  unset($sort_by_list[$order]);
2153  }
2154  if (isset($sort_by_list[$order])) {
2155  $save_list[$i++] = $sort_by_list[$order];
2156  unset($sort_by_list[$order]);
2157  }
2158  }
2159  // $sort_by_list now contains only the newly-added fields, which we'll put last
2160  return $asset->setAttrValue('sort_by', array_merge($save_list, $sort_by_list));
2161  }
2162  return FALSE;
2163 
2164  }//end processSortOptionOrder()
2165 
2166 
2177  function paintDefaultSortDirection(&$asset, &$o, $prefix)
2178  {
2179  $write_access = $asset->writeAccess('attributes');
2180  $sort_direction = $asset->attr('reverse_sort');
2181  $sort_asc_text = $asset->attr('sort_direction_asc_text');
2182  $sort_desc_text = $asset->attr('sort_direction_desc_text');
2183 
2184  $options = Array(
2185  '0' => $sort_asc_text,
2186  '1' => $sort_desc_text,
2187  );
2188 
2189  if ($write_access) {
2190  combo_box($prefix.'_default_sort_direction', $options, FALSE, $sort_direction);
2191  } else {
2192  echo ($sort_direction) ? $sort_desc_text : $sort_asc_text;
2193  }
2194 
2195  return $write_access;
2196 
2197  }//end paintDefaultSortDirection()
2198 
2199 
2210  function processDefaultSortDirection(&$asset, &$o, $prefix)
2211  {
2212  $direction = array_get_index($_POST, $prefix.'_default_sort_direction');
2213  if (!is_null($direction)) {
2214  $direction = (int)(bool)$direction;
2215  $asset->setAttrValue('reverse_sort', $direction);
2216  return TRUE;
2217  }
2218  return FALSE;
2219 
2220  }//end processDefaultSortDirection()
2221 
2222 
2231  function _getStandardSortByOptions(&$asset)
2232  {
2233  if ($asset->attr('group_by') == 'letter') {
2234  return Array(
2235  'name' => translate('name'),
2236  'short_name' => translate('short_name'),
2237  );
2238  } else {
2239  return $GLOBALS['SQ_SYSTEM']->am->getAssetInfoFields();
2240  }
2241 
2242  }//end _getStandardSortByOptions()
2243 
2244 
2255  function paintRootNode(&$asset, &$o, $prefix)
2256  {
2257  // get root links
2258  $root_links = $GLOBALS['SQ_SYSTEM']->am->getLinks($asset->id, SQ_LINK_NOTICE, '', FALSE, 'major', 'root');
2259  $root_asset_ids = Array();
2260  foreach ($root_links as $root_link) {
2261  $root_asset_ids[$root_link['minorid']] = $root_link['minor_type_code'];
2262  }
2263 
2264  if ($asset->writeAccess('links')) {
2265  multiple_asset_finder($prefix.'_root_nodes', array_keys($root_asset_ids));
2266  } else {
2267  $infos = $GLOBALS['SQ_SYSTEM']->am->getAssetInfo(array_keys($root_asset_ids));
2268  ?><ul style="margin: 1px 15px;"><?php
2269  foreach ($infos as $assetid => $info) {
2270  echo '<li>'.get_asset_tag_line($assetid).'</li>';
2271  }
2272  ?></ul><?php
2273  }
2274  return TRUE;
2275 
2276  }//end paintRootNode()
2277 
2278 
2289  function processRootNode(&$asset, &$o, $prefix)
2290  {
2291  if (!isset($_POST[$prefix.'_root_nodes']) || (isset($asset->_tmp['reverting_to_system_version']) && $asset->_tmp['reverting_to_system_version'])) {
2292  return FALSE;
2293  }
2294  $new_root_nodes = $_POST[$prefix.'_root_nodes'];
2295  foreach ($new_root_nodes as $new_root_node) {
2296  $new_root_node_ids[] = $new_root_node['assetid'];
2297  }
2298 
2299  // get existing root links
2300  $root_links = $GLOBALS['SQ_SYSTEM']->am->getLinks($asset->id, SQ_LINK_NOTICE, '', FALSE, 'major', 'root');
2301 
2302  $GLOBALS['SQ_SYSTEM']->changeDatabaseConnection('db2');
2303  $GLOBALS['SQ_SYSTEM']->doTransaction('BEGIN');
2304  $ok = TRUE;
2305 
2306  // lets delete the root nodes that have been removed
2307  foreach ($root_links as $root_link) {
2308  if (!in_array($root_link['minorid'], $new_root_node_ids)) {
2309  if (!$GLOBALS['SQ_SYSTEM']->am->deleteAssetLink($root_link['linkid'])) {
2310  $ok = FALSE;
2311  }
2312  }
2313  }
2314 
2315  // now, create the new node links
2316  foreach ($new_root_nodes as $index => $node) {
2317  // first test to see if the node already exists -- if so, ignore it
2318  foreach ($root_links as $root_link) {
2319  if ($root_link['minorid'] == $node['assetid']) {
2320  continue 2;
2321  }
2322  }
2323  // otherwise, create the appropriate notice link
2324  if ($node['assetid'] != 0) {
2325  $new_root = $GLOBALS['SQ_SYSTEM']->am->getAsset($node['assetid']);
2326  if (!$asset->createLink($new_root, SQ_LINK_NOTICE, 'root')) {
2327  $ok = FALSE;
2328  trigger_localised_error('CMS0016', E_USER_WARNING, $new_root->name, $new_root->id);
2329  break;
2330  }
2331  }
2332  }
2333 
2334  if ($ok) {
2335  $GLOBALS['SQ_SYSTEM']->doTransaction('COMMIT');
2336  } else {
2337  $GLOBALS['SQ_SYSTEM']->doTransaction('ROLLBACK');
2338  }
2339 
2340  $GLOBALS['SQ_SYSTEM']->restoreDatabaseConnection();
2341  return $ok;
2342 
2343  }//end processRootNode()
2344 
2345 
2356  function paintGroupBy(&$asset, &$o, $prefix)
2357  {
2358  $asset->reindexGroupFormats();
2359 
2360  $write_access = $asset->writeAccess('attributes');
2361  $group_by = $asset->attr('asset_grouping');
2362  $commit_button = FALSE;
2363 
2364  foreach ($group_by as $level => $group_by_option) {
2365 
2366  switch ($group_by_option['group_type']) {
2367  case 'parent_asset':
2368  $option_name = 'cms_listing_parent_asset';
2369  break;
2370 
2371  case 'metadata':
2372  $option_name = 'asset_metadata';
2373  break;
2374 
2375  case 'standard_asset':
2376  $option_name = 'standard_asset_field';
2377  break;
2378 
2379  case 'attribute':
2380  $option_name = 'asset_attribute';
2381  break;
2382 
2383  case 'keyword':
2384  $option_name = 'keyword';
2385  break;
2386 
2387  default:
2388  $option_name = '';
2389  break;
2390  }
2391 
2392  $o->openSection('Group Level '.($level+1).': '.translate($option_name));
2393 
2394  switch ($group_by_option['group_type']) {
2395  case 'parent_asset':
2396  $commit_button |= $this->paintGroupByParentAsset($asset, $o, $prefix.'['.$level.']', $group_by_option);
2397  break;
2398 
2399  case 'metadata':
2400  $commit_button |= $this->paintGroupByMetadata($asset, $o, $prefix.'['.$level.']', $group_by_option);
2401  break;
2402 
2403  case 'standard_asset':
2404  $commit_button |= $this->paintGroupByStandardAssetField($asset, $o, $prefix.'['.$level.']', $group_by_option);
2405  break;
2406 
2407  case 'keyword':
2408  $commit_button |= $this->paintGroupByKeyword($asset, $o, $prefix.'['.$level.']', $group_by_option);
2409  break;
2410 
2411  case 'attribute':
2412  // implementation reserved
2413  break;
2414  }
2415 
2416  // common options - sort order, start group on a new page, delete
2417  $o->openField(translate('cms_listing_sort_order'));
2418 
2419  $options = Array(
2420  'asc' => translate('cms_listing_ascending_order'),
2421  'desc' => translate('cms_listing_descending_order'),
2422  );
2423 
2424  if ($write_access) {
2425  combo_box($prefix.'['.$level.'][sort_order]', $options, FALSE, array_get_index($group_by_option, 'sort_order', 'asc'));
2426  } else {
2427  echo $options[array_get_index($group_by_option, 'sort_order', 'asc')];
2428  }
2429 
2430  $o->closeField();
2431 
2432  $o->openField(translate('cms_listing_max_children_per_group'));
2433  $max_children = array_get_index($group_by_option, 'max_children', NULL);
2434  if ($write_access) {
2435  text_box($prefix.'['.$level.'][max_children]', $max_children, 5);
2436  } else {
2437  if (is_null($max_children)) {
2438  echo '<em>'.translate('unlimited').'</em>';
2439  } else {
2440  echo $max_children;
2441  }
2442  }
2443  $o->closeField();
2444 
2445 
2446  // only display Delete option if we have write access
2447  if ($write_access) {
2448 
2449  $o->openField(translate('delete_question'));
2450 
2451  check_box($prefix.'['.$level.'][delete]', '1', array_get_index($group_by_option, 'new_page', FALSE));
2452  label(translate('cms_listing_delete_group_format'), $prefix.'['.$level.'][delete]');
2453 
2454  $o->closeField();
2455 
2456  // link to group format bodycopy
2457  $o->openField('');
2458  $link = $GLOBALS['SQ_SYSTEM']->am->getAssetBackendHref(Array($group_by_option['format_assetid'] => 'contents'));
2459  ?><a href="<?php echo $link[$group_by_option['format_assetid']]; ?>"><?php echo translate('cms_listing_edit_group_format'); ?></a><?php
2460  $o->closeField();
2461 
2462  }
2463 
2464 
2465  $o->closeSection();
2466  }//end foreach
2467 
2468  return $commit_button;
2469 
2470  }//end paintGroupBy()
2471 
2472 
2483  function processGroupBy(&$asset, &$o, $prefix)
2484  {
2485  if (!$asset->writeAccess('attributes')) return FALSE;
2486 
2487  $group_by_details = $asset->attr('asset_grouping');
2488  $posted_options = array_get_index($_POST, $prefix, Array());
2489  $folder = $asset->getFolder('group_formats');
2490 
2491  // go through and process deletions of groups
2492  foreach ($posted_options as $key => $posted_option) {
2493  if (is_array($posted_option) && (array_get_index($posted_option, 'delete', 0) == 1)) {
2494  $format_assetid = $group_by_details[$key]['format_assetid'];
2495  $current_link = $GLOBALS['SQ_SYSTEM']->am->getLinkByAsset($folder->id, $format_assetid);
2496 
2497  if (empty($current_link)) {
2498  trigger_error('Group format does not seem to exist for group level '.($key+1), E_USER_WARNING);
2499  } else {
2500  if (!$GLOBALS['SQ_SYSTEM']->am->deleteAssetLink($current_link['linkid'])) {
2501  trigger_error('Could not delete link between group level '.($key+1).' and group formats folder', E_USER_WARNING);
2502  }
2503  }
2504 
2505  unset($group_by_details[$key]);
2506  }
2507  }
2508 
2509  foreach ($group_by_details as $group_by_key => $group_by_option) {
2510  switch ($group_by_option['group_type']) {
2511  case 'parent_asset':
2512  $this->processGroupByParentAsset($asset, $o, $prefix, $group_by_key, $group_by_details[$group_by_key]);
2513  break;
2514 
2515  case 'metadata':
2516  $this->processGroupByMetadata($asset, $o, $prefix, $group_by_key, $group_by_details[$group_by_key]);
2517  break;
2518 
2519  case 'standard_asset':
2520  $this->processGroupByStandardAssetField($asset, $o, $prefix, $group_by_key, $group_by_details[$group_by_key]);
2521  break;
2522 
2523  case 'keyword':
2524  $this->processGroupByKeyword($asset, $o, $prefix, $group_by_key, $group_by_details[$group_by_key]);
2525  break;
2526 
2527 
2528  case 'attribute':
2529  // $this->processGroupByAttribute($asset, $o, $prefix, $group_by_key, $group_by_details[$group_by_key]);
2530  break;
2531  }
2532  }
2533 
2534  // merge the array with nothing, to re-order the keys of the array back
2535  // to a numerical order
2536  $group_by_details = array_merge($group_by_details, Array());
2537  $asset->reindexGroupFormats();
2538 
2539  // process new stuff here
2540  $asset->setAttrValue('asset_grouping', $group_by_details);
2541  return $asset->saveAttributes();
2542 
2543  }//end processGroupBy()
2544 
2545 
2557  function paintGroupByMetadata(&$asset, &$o, $prefix, $group_by_option)
2558  {
2559  $write_access = $asset->writeAccess('attributes');
2560 
2561  $o->openField(translate('metadata_field'));
2562  $field_assetid = array_get_index($group_by_option, 'metadata_field', 0);
2563 
2564  if ($write_access) {
2565  asset_finder($prefix.'[metadata_field]', $field_assetid, Array('metadata_field' => 'D'));
2566  } else {
2567  if ($field_assetid) {
2568  echo get_asset_tag_line($field_assetid);
2569  }
2570  }
2571 
2572  $o->note(translate('cms_listing_group_metadata_field_note'));
2573  $o->closeField();
2574 
2575  $o->openField(translate('cms_listing_default_metadata_sort_type'));
2576 
2577  $sort_by = array_get_index($group_by_option, 'metadata_sort_type', 'raw');
2578  $option = Array(
2579  'raw' => translate('cms_listing_raw_value'),
2580  'presentation' => translate('cms_listing_presentation_value'),
2581  );
2582 
2583  if ($write_access) {
2584  combo_box($prefix.'[metadata_sort_type]', $option, FALSE, $sort_by);
2585  } else {
2586  echo ($sort_by == 'raw') ? translate('cms_listing_raw_value') : translate('cms_listing_presentation_value');
2587  }
2588 
2589  $o->note(translate('cms_listing_default_metadata_sort_type_note'));
2590  $o->closeField();
2591 
2592  return $write_access;
2593 
2594  }//end paintGroupByMetadata()
2595 
2596 
2609  function processGroupByMetadata(&$asset, &$o, $prefix, $key, &$group_by_option)
2610  {
2611  $posted_option = array_get_index($_POST[$prefix], $key, NULL);
2612  if (!is_array($posted_option)) return FALSE;
2613 
2614  if (isset($posted_option['metadata_field'])) {
2615  $group_by_option['metadata_field'] = $posted_option['metadata_field']['assetid'];
2616  }
2617  $group_by_option['sort_order'] = $posted_option['sort_order'];
2618 
2619  if (empty($posted_option['max_children'])) {
2620  $group_by_option['max_children'] = NULL;
2621  } else {
2622  $group_by_option['max_children'] = $posted_option['max_children'];
2623  }
2624 
2625  if (isset($posted_option['metadata_sort_type'])) {
2626  $group_by_option['metadata_sort_type'] = $posted_option['metadata_sort_type'];
2627  }
2628 
2629  return TRUE;
2630 
2631  }//end processGroupByMetadata()
2632 
2633 
2645  function paintGroupByStandardAssetField(&$asset, &$o, $prefix, $group_by_option)
2646  {
2647  $write_access = $asset->writeAccess('attributes');
2648 
2649  $options = Array(
2650  'assetid' => translate('asset_id'),
2651  'version' => translate('version'),
2652  'name' => translate('name'),
2653  'short_name' => translate('short_name'),
2654  'status' => translate('asset_status'),
2655  'created' => translate('created_date'),
2656  'updated' => translate('last_updated_date'),
2657  'published' => translate('last_published_date'),
2658  'status_changed' => translate('status_changed_date'),
2659  'type_code' => translate('type_code'),
2660  );
2661  $field = array_get_index($group_by_option, 'field', '');
2662 
2663  $o->openField(translate('standard_asset_field'));
2664 
2665  if ($write_access) {
2666  combo_box($prefix.'[standard_asset_field]', $options, FALSE, $field);
2667  } else {
2668  if (empty($field)) {
2669  echo '<em>'.translate('cms_listing_no_field_selected').'</em>';
2670  } else {
2671  echo $options[$field];
2672  }
2673  }
2674 
2675  $o->closeField();
2676 
2677  return $write_access;
2678 
2679  }//end paintGroupByStandardAssetField()
2680 
2681 
2694  function processGroupByStandardAssetField(&$asset, &$o, $prefix, $key, &$group_by_option)
2695  {
2696  $posted_option = array_get_index($_POST[$prefix], $key, NULL);
2697  if (!is_array($posted_option)) return FALSE;
2698 
2699  if (isset($posted_option['standard_asset_field'])) {
2700  $group_by_option['field'] = $posted_option['standard_asset_field'];
2701  }
2702  $group_by_option['sort_order'] = $posted_option['sort_order'];
2703 
2704  if (empty($posted_option['max_children'])) {
2705  $group_by_option['max_children'] = NULL;
2706  } else {
2707  $group_by_option['max_children'] = $posted_option['max_children'];
2708  }
2709 
2710  return TRUE;
2711 
2712  }//end processGroupByStandardAssetField()
2713 
2714 
2726  function paintGroupByParentAsset(&$asset, &$o, $prefix, $group_by_option)
2727  {
2728  $write_access = $asset->writeAccess('attributes');
2729 
2730  $o->openField(translate('cms_listing_restrict_types'));
2731 
2732  if ($write_access) {
2733  asset_type_chooser($prefix.'[restrict_types]', TRUE, array_get_index($group_by_option, 'restrict_types', Array()), NULL, FALSE, TRUE);
2734  } else {
2735  if (empty($group_by_option['restrict_types']['type_code'])) {
2736  echo '<i>'.translate('cms_listing_no_types_selected').'</i>';
2737  } else {
2738  ?><ul style="margin: 1px 15px"><?php
2739  $type_names = $GLOBALS['SQ_SYSTEM']->am->getTypeInfo($group_by_option['restrict_types']['type_code'], 'name');
2740 
2741  foreach ($group_by_option['restrict_types']['type_code'] as $key => $type_code) {
2742  ?><li><?php
2743  echo get_asset_type_icon($type_code);
2744  echo $type_names[$type_code];
2745  if ($group_by_option['restrict_types']['inherit'][$key]) {
2746  echo ' ('.strtolower(translate('cms_listing_inherits_child_types')).')';
2747  }
2748  ?></li><?php
2749  }
2750  ?></ul><?php
2751  }
2752  }
2753 
2754  $o->note(translate('cms_listing_group_asset_restriction_note'));
2755  $o->closeField();
2756 
2757  // option to include only assets with direct parent that matches one of the restricted types
2758  $o->openField('Direct Parent Only ?');
2759  if ($write_access) {
2760  check_box($prefix.'[direct_parent_only]', '1', array_get_index($group_by_option, 'direct_parent_only', FALSE));
2761  label('Only list assets with direct parent that matches the Restricted Types', $prefix.'[direct_parent_only]');
2762  } else {
2763  ?>
2764  <img src="<?php echo sq_web_path('lib'); ?>/web/images/<?php echo array_get_index($group_by_option, 'direct_parent_only', FALSE) ? 'tick' : 'cross'; ?>.gif" width="15" height="15" />
2765  <?php
2766  echo 'Only list assets with direct parent that matches the Restricted Types';
2767  }
2768  $o->closeField();
2769 
2770  $o->openField(translate('sort_by'));
2771 
2772  // for now we will only sort by the original set of options (not
2773  // attributes - it would clutter the page for one)
2774  $sort_by_options = $this->_getStandardSortByOptions($asset);
2775  $sort_by_options['sorting_metadata_field'] = 'Metadata Field';
2776  $sort_by_options[''] = '-- '.translate('select').' --';
2777 
2778  $current_option = array_get_index($group_by_option, 'sort_by', '');
2779 
2780  if ($write_access) {
2781  combo_box($prefix.'[sort_by]', $sort_by_options, FALSE, $current_option);
2782  if ($current_option == 'sorting_metadata_field') {
2783  echo '<br>';
2784  $field_assetid = array_get_index($group_by_option, 'sorting_metadata_field', 0);
2785  asset_finder($prefix.'[sorting_metadata_field]',$field_assetid);
2786  }
2787  $o->note('Select the order in which the parent assets should be displayed');
2788  } else {
2789 
2790  if (empty($current_option)) {
2791  echo '<i>'.translate('cms_listing_no_sorting_applied').'</i>';
2792  } else {
2793  echo $sort_by_options[$current_option];
2794  }
2795  }
2796 
2797  $o->closeField();
2798 
2799 
2800  if (isset($group_by_option['sort_by']) && $group_by_option['sort_by'] == 'sorting_metadata_field') {
2801  $o->openField(translate('cms_listing_default_metadata_sort_type'));
2802 
2803  $sort_by = array_get_index($group_by_option, 'metadata_sort_type', 'raw');
2804  $option = Array(
2805  'raw' => translate('cms_listing_raw_value'),
2806  'presentation' => translate('cms_listing_presentation_value'),
2807  );
2808 
2809  if ($write_access) {
2810  combo_box($prefix.'[metadata_sort_type]', $option, FALSE, $sort_by);
2811  } else {
2812  echo ($sort_by == 'raw') ? translate('cms_listing_raw_value') : translate('cms_listing_presentation_value');
2813  }
2814 
2815  $o->note(translate('cms_listing_default_metadata_sort_type_note'));
2816  $o->closeField();
2817  }
2818 
2819 
2820  return $write_access;
2821 
2822  }//end paintGroupByParentAsset()
2823 
2824 
2825 
2826 
2839  function processGroupByParentAsset(&$asset, &$o, $prefix, $key, &$group_by_option)
2840  {
2841  $posted_option = array_get_index($_POST[$prefix], $key, NULL);
2842  if (!is_array($posted_option)) return FALSE;
2843 
2844  if (isset($posted_option['restrict_types'])) {
2845  $group_by_option['restrict_types'] = $posted_option['restrict_types'];
2846 
2847  // the asset type chooser is prone to giving blank asset types if
2848  // 'more' fields are left blank, so strip them out right here
2849  foreach ($group_by_option['restrict_types']['type_code'] as $key => $type_code) {
2850  if (empty($type_code)) {
2851  unset($group_by_option['restrict_types']['type_code'][$key]);
2852  unset($group_by_option['restrict_types']['inherit'][$key]);
2853  }
2854  }
2855 
2856  if (isset($posted_option['sorting_metadata_field'])) {
2857  $group_by_option['sorting_metadata_field'] = $posted_option['sorting_metadata_field']['assetid'];
2858  }
2859 
2860  $group_by_option['direct_parent_only'] = array_get_index($posted_option, 'direct_parent_only', FALSE);
2861  $group_by_option['sort_by'] = $posted_option['sort_by'];
2862  $group_by_option['sort_order'] = $posted_option['sort_order'];
2863 
2864  if (isset($posted_option['metadata_sort_type'])) {
2865  $group_by_option['metadata_sort_type'] = $posted_option['metadata_sort_type'];
2866  }
2867 
2868  if (empty($posted_option['max_children'])) {
2869  $group_by_option['max_children'] = NULL;
2870  } else {
2871  $group_by_option['max_children'] = $posted_option['max_children'];
2872  }
2873  }
2874 
2875  return TRUE;
2876 
2877  }//end processGroupByParentAsset()
2878 
2879 
2891  function paintGroupByKeyword(&$asset, &$o, $prefix, $group_by_option)
2892  {
2893  $write_access = $asset->writeAccess('attributes');
2894 
2895  $o->openField(translate('keyword'));
2896  $keyword = array_get_index($group_by_option, 'keyword', NULL);
2897  if ($write_access) {
2898  text_box($prefix.'[keyword]', $keyword, 10);
2899  } else {
2900  if (is_null($keyword)) {
2901  echo '<em>'.translate('cms_listing_no_keyword').'</em>';
2902  } else {
2903  echo $keyword;
2904  }
2905  }
2906  $o->closeField();
2907 
2908  return $write_access;
2909 
2910  }//end paintGroupByKeyword()
2911 
2912 
2925  function processGroupByKeyword(&$asset, &$o, $prefix, $key, &$group_by_option)
2926  {
2927  $posted_option = array_get_index($_POST[$prefix], $key, NULL);
2928  if (!is_array($posted_option)) return FALSE;
2929 
2930  if (isset($posted_option['keyword'])) {
2931  $group_by_option['keyword'] = $posted_option['keyword'];
2932  }
2933  $group_by_option['sort_order'] = $posted_option['sort_order'];
2934 
2935  if (empty($posted_option['max_children'])) {
2936  $group_by_option['max_children'] = NULL;
2937  } else {
2938  $group_by_option['max_children'] = $posted_option['max_children'];
2939  }
2940 
2941  return TRUE;
2942 
2943  }//end processGroupByKeyword()
2944 
2945 
2956  function paintNewGroupBy(&$asset, &$o, $prefix)
2957  {
2958  if ($asset->writeAccess('attributes')) {
2959  $group_by = $asset->attr('asset_grouping');
2960 
2961  check_box($prefix.'[new]');
2962  ?> Add a new group level&nbsp;<?php
2963  $options = Array(0 => 'at the top level');
2964  for ($i = 1; $i <= count($group_by); $i++) {
2965  $options[$i] = 'after group level '.$i;
2966  }
2967  combo_box($prefix.'[new_after]', $options, FALSE, count($group_by));
2968 
2969  ?> of type <?php
2970  $options = Array(
2971  '' => '-- '.translate('select').' --',
2972  'parent_asset' => translate('cms_listing_parent_asset'),
2973  'metadata' => translate('asset_metadata'),
2974  'standard_asset' => translate('standard_asset_field'),
2975  'keyword' => translate('keyword'),
2976  );
2977 
2978  combo_box($prefix.'[new_type]', $options, FALSE, '');
2979 
2980  }
2981 
2982  return $asset->writeAccess('attributes');
2983 
2984  }//end paintNewGroupBy()
2985 
2986 
2997  function processNewGroupBy(&$asset, &$o, $prefix)
2998  {
2999  if ($asset->writeAccess('attributes')) {
3000 
3001  if (isset($_POST[$prefix]['new'])) {
3002 
3003  $new_type = array_get_index($_POST[$prefix], 'new_type', NULL);
3004  $new_position = array_get_index($_POST[$prefix], 'new_after', NULL);
3005 
3006  if (!is_null($new_type) && !is_null($new_position)) {
3007 
3008  // need to work out where the correct position is, taking
3009  // into account group deletions
3010 
3011  $posted_options = array_get_index($_POST, $prefix, Array());
3012  $pos_adjust = 0;
3013  $group_by_options = $asset->attr('asset_grouping');
3014 
3015  foreach ($group_by_options as $key => $group_by_option) {
3016  if (isset($posted_options[$key]['delete'])) {
3017  // if the deleted item's position is above where the
3018  // new group is going to be placed
3019  if ((int)$key <= $new_position)$pos_adjust++;
3020  }
3021  }
3022 
3023  // $new_position now holds the correct position for inserting
3024  // the new group
3025  $new_position -= $pos_adjust;
3026 
3027  // create a new group format bodycopy
3028  $GLOBALS['SQ_SYSTEM']->changeDatabaseConnection('db2');
3029  $GLOBALS['SQ_SYSTEM']->doTransaction('BEGIN');
3030  $GLOBALS['SQ_SYSTEM']->am->includeAsset('bodycopy');
3031  $folder = $asset->getFolder('group_formats');
3032 
3033 
3034  $copy_link = Array('asset' => &$folder, 'link_type' => SQ_LINK_TYPE_2, 'is_dependant' => 1, 'is_exclusive' => 1, 'sort_order' => $new_position);
3035 
3036  $bodycopy = new Bodycopy();
3037  $bodycopy->setAttrValue('name', 'Group Level '.($new_position+1).' Format');
3038  $group_listing_data = Array('content' => '%group_listing%');
3039 
3040  if (!$bodycopy->create($copy_link, $group_listing_data)) {
3041  $GLOBALS['SQ_SYSTEM']->doTransaction('ROLLBACK');
3042  $GLOBALS['SQ_SYSTEM']->restoreDatabaseConnection();
3043  return FALSE;
3044  }
3045 
3046  // if we lost the lock while creating the bodycopy
3047  if (!$asset->writeAccess('attributes')) {
3048  $GLOBALS['SQ_SYSTEM']->am->acquireLock($asset->id, 'attributes');
3049  }
3050 
3051  // update the grouping list
3052  $new_group = Array(Array('group_type' => $new_type, 'format_assetid' => $bodycopy->id));
3053  array_splice($group_by_options, $new_position, 0, $new_group);
3054  $asset->setAttrValue('asset_grouping', $group_by_options);
3055 
3056  // adjust the other group formats so their names are correct
3057  $asset->reindexGroupFormats();
3058  if (!$asset->saveAttributes()) {
3059  $GLOBALS['SQ_SYSTEM']->doTransaction('ROLLBACK');
3060  $GLOBALS['SQ_SYSTEM']->restoreDatabaseConnection();
3061  return FALSE;
3062  }
3063 
3064 
3065  $GLOBALS['SQ_SYSTEM']->doTransaction('COMMIT');
3066  $GLOBALS['SQ_SYSTEM']->restoreDatabaseConnection();
3067  return TRUE;
3068  }//end if
3069 
3070  }//end if
3071 
3072  }//end if
3073 
3074  return FALSE;
3075 
3076  }//end processNewGroupBy()
3077 
3078 
3089  function paintSelections(&$asset, &$o, $prefix)
3090  {
3091  $write_access = $asset->writeAccess('attributes');
3092 
3093  $selections = $asset->attr('asset_selections');
3094  $input_types = Array(
3095  'radio' => translate('cms_listing_radio_buttons'),
3096  'selection' => translate('cms_listing_drop_down_list'),
3097  'textbox' => translate('cms_listing_text_field'),
3098  );
3099  $defaults = $asset->getAssetSelectionDefaults();
3100 
3101  // print existing selections
3102  foreach ($selections as $name => $settings) {
3103  ?>
3104  <table class="sq-backend-table">
3105  <tr>
3106  <th><?php echo $name; ?></th>
3107  <td class="sq-backend-table-header" style="text-align: right;">
3108  <?php
3109  hidden_field($prefix.'_sel['.$name.'][permanent]', array_get_index($settings, 'permanent', $defaults['permanent']));
3110  if ($write_access && !array_get_index($settings, 'permanent', $defaults['permanent'])) {
3111  check_box($prefix.'_sel_delete['.$name.']', '1');
3112  label(translate('delete_question'), $prefix.'_sel_delete['.$name.']');
3113  }
3114  ?>
3115  </td>
3116  </tr>
3117  <tr>
3118  <td><?php echo translate('cms_listing_input_style') ?></td>
3119  <td>
3120  <?php
3121  if ($write_access) {
3122  combo_box($prefix.'_sel['.$name.'][type]', $input_types, FALSE, array_get_index($settings, 'type', $defaults['type']));
3123  } else {
3124  echo $input_types[array_get_index($settings, 'type', $defaults['type'])];
3125  }
3126  ?>
3127  </td>
3128  </tr>
3129  <tr>
3130  <td><?php echo translate('options') ?></td>
3131  <td>
3132 
3133  <?php
3134  $options = array_get_index($settings, 'options', Array());
3135  ?>
3136 
3137  <table style="width: 100%; border: 0;">
3138  <tr>
3139  <td>
3140  <?php
3141  if ($write_access) {
3142  check_box($prefix.'_sel['.$name.'][options][allow_multiple]', '1', array_get_index($options, 'allow_multiple', $defaults['options']['allow_multiple']));
3143  label(translate('cms_listing_allow_multiple'), $prefix.'_sel['.$name.'][options][allow_multiple]');
3144  } else {
3145  ?><img src="<?php echo sq_web_path('lib'); ?>/web/images/<?php echo (array_get_index($options, 'allow_multiple', $defaults['options']['allow_multiple']) ? 'tick' : 'cross'); ?>.gif" width="15" height="15" /><?php
3146  echo ' '.translate('cms_listing_allow_multiple');
3147  }
3148  ?>
3149  </td>
3150  <td style="text-align: right;"><?php echo translate('cms_listing_radio_dd_only') ?></td>
3151  </tr>
3152  <tr>
3153  <td>
3154  <?php
3155  if ($write_access) {
3156  check_box($prefix.'_sel['.$name.'][options][allow_negative]', '1', array_get_index($options, 'allow_negative', $defaults['options']['allow_negative']));
3157  label(translate('cms_listing_allow_negative_values'), $prefix.'_sel['.$name.'][options][allow_negative]');
3158  } else {
3159  ?><img src="<?php echo sq_web_path('lib'); ?>/web/images/<?php echo (array_get_index($options, 'allow_negative', $defaults['options']['allow_negative']) ? 'tick' : 'cross'); ?>.gif" width="15" height="15" /><?php
3160  echo ' '.translate('cms_listing_allow_negative_values');
3161  }
3162  ?>
3163  </td>
3164  <td style="text-align: right;"><?php echo translate('cms_listing_text_dd_only') ?></td>
3165  </tr>
3166  <tr>
3167  <td>
3168  <?php
3169  $restrict_range = array_get_index($options, 'restrict_range', Array());
3170  if ($write_access) {
3171  check_box($prefix.'_sel['.$name.'][options][restrict_range][enable]', '1', array_get_index($restrict_range, 'enable', $defaults['options']['restrict_range']['enable']));
3172  label(translate('cms_listing_restrict_values_to_range').':', $prefix.'_sel['.$name.'][options][restrict_range][enable]');
3173  } else {
3174  ?><img src="<?php echo sq_web_path('lib'); ?>/web/images/<?php echo (array_get_index($restrict_range, 'enable', $defaults['options']['restrict_range']['enable']) ? 'tick' : 'cross'); ?>.gif" width="15" height="15" /><?php
3175  echo translate('cms_listing_restrict_values_to_range') ?>:<?php
3176  }
3177 
3178  // From box
3179  ob_start();
3180  if ($write_access) {
3181  int_text_box($prefix.'_sel['.$name.'][options][restrict_range][min]', array_get_index($restrict_range, 'min', $defaults['options']['restrict_range']['min']), TRUE, 3);
3182  } else {
3183  echo '<strong>'.array_get_index($restrict_range, 'min', $defaults['options']['restrict_range']['min']).'</strong>';
3184  }
3185  $from_box = ob_get_contents();
3186  ob_end_clean();
3187 
3188  // To box
3189  ob_start();
3190  if ($write_access) {
3191  int_text_box($prefix.'_sel['.$name.'][options][restrict_range][max]', array_get_index($restrict_range, 'max', $defaults['options']['restrict_range']['max']), TRUE, 3);
3192  } else {
3193  echo '<strong>'.array_get_index($restrict_range, 'max', $defaults['options']['restrict_range']['max']).'</strong>';
3194  }
3195  $to_box = ob_get_contents();
3196  ob_end_clean();
3197 
3198  echo ' '.translate('cms_listing_from_to_range', $from_box, $to_box);
3199  ?>
3200  </td>
3201  <td style="text-align: right; vertical-align: top;">
3202  <?php echo translate('cms_listing_text_dd_only_dd_req') ?><br/>
3203  <?php echo translate('cms_listing_override_by_previous_options') ?>
3204 
3205  </td>
3206  </tr>
3207  </table>
3208 
3209  </td>
3210  </tr>
3211  </table><br />
3212  <?php
3213  }//end foreach $selections
3214 
3215  // new
3216  if ($write_access) {
3217  $o->closeField();
3218  $o->openField(translate('cms_listing_add_new_selection_question'));
3219 
3220  text_box($prefix.'_sel_new', '');
3221  }
3222 
3223  return $write_access;
3224 
3225  }//end paintSelections()
3226 
3227 
3238  function processSelections(&$asset, &$o, $prefix)
3239  {
3240  $write_access = $asset->writeAccess('attributes');
3241 
3242  if ($write_access) {
3243  $selections = $asset->attr('asset_selections');
3244  $defaults = $asset->getAssetSelectionDefaults();
3245 
3246  // modify values
3247  if (!empty($_POST[$prefix.'_sel'])) {
3248  foreach ($_POST[$prefix.'_sel'] as $name => $settings) {
3249 
3250  // only modify, not add
3251  if (isset($selections[$name])) {
3252 
3253  $selections[$name] = array_merge_multi($defaults, $settings);
3254 
3255  $type = array_get_index($selections[$name], 'type', $defaults['type']);
3256  $options = array_get_index($selections[$name], 'options', $defaults['options']);
3257  $restrict_range = array_get_index($options, 'restrict_range', $defaults['options']['restrict_range']);
3258 
3259  // check for invalid combinations of settings, and change them if required
3260  // ... allow_multiple - radio & selection only
3261  if (array_get_index($options, 'allow_multiple', $defaults['options']['allow_multiple']) && ($type != 'radio' && $type != 'selection')) {
3262  $selections[$name]['options']['allow_multiple'] = 0;
3263  }
3264 
3265  // ... allow_negative - textbox & selection only
3266  if (array_get_index($options, 'allow_negative', $defaults['options']['allow_negative']) && $type != 'textbox') {
3267  $selections[$name]['options']['allow_negative'] = 0;
3268  }
3269 
3270  // ... restrict_range - textbox & selection only
3271  if (array_get_index($restrict_range, 'enable', $defaults['options']['restrict_range']['enable']) && ($type != 'textbox' && $type != 'selection')) {
3272  $selections[$name]['options']['restrict_range']['enable'] = 0;
3273  }
3274 
3275  // turn the range if selection was selected
3276  if ($type == 'selection') {
3277  $selections[$name]['options']['restrict_range']['enable'] = 1;
3278  }
3279 
3280  // fix negative min or max when 'allow_negative' is unchecked
3281  if (array_get_index($restrict_range, 'min', $defaults['options']['restrict_range']['min']) < 0 && !array_get_index($options, 'allow_negative', $defaults['options']['allow_negative'])) {
3282  $selections[$name]['options']['restrict_range']['min'] = 0;
3283  }
3284  if (array_get_index($restrict_range, 'max', $defaults['options']['restrict_range']['max']) < 0 && !array_get_index($options, 'allow_negative', $defaults['options']['allow_negative'])) {
3285  $selections[$name]['options']['restrict_range']['max'] = 0;
3286  }
3287 
3288  // min > max
3289  if (array_get_index($restrict_range, 'min', $defaults['options']['restrict_range']['min']) > array_get_index($restrict_range, 'max', $defaults['options']['restrict_range']['max'])) {
3290  $selections[$name]['options']['restrict_range']['min'] = array_get_index($restrict_range, 'max', $defaults['options']['restrict_range']['max']);
3291  }
3292 
3293  }//end if
3294 
3295  }//end foreach
3296  }//end if
3297 
3298  // process deletions
3299  if (!empty($_POST[$prefix.'_sel_delete'])) {
3300  foreach ($_POST[$prefix.'_sel_delete'] as $name => $value) {
3301  if (isset($selections[$name])) {
3302  unset($selections[$name]);
3303  }
3304  }
3305  }
3306 
3307  if (!empty($_POST[$prefix.'_sel_new'])) {
3308  // set the defaults
3309  $name = trim($_POST[$prefix.'_sel_new']);
3310  $name = str_replace(' ','_',$name);
3311  $name = str_replace('%','_',$name);
3312 
3313  $selections[$name] = $defaults;
3314  }
3315 
3316  $asset->setAttrValue('asset_selections', $selections);
3317  }//end if
3318 
3319 
3320  return $write_access;
3321 
3322  }//end processSelections()
3323 
3324 
3335  function paintTargets(&$asset, &$o, $prefix)
3336  {
3337  $write_access = $asset->writeAccess('attributes');
3338 
3339  $targets = $asset->attr('asset_targets');
3340  $defaults = $asset->getAssetTargetDefaults();
3341 
3342  // print existing selections
3343  foreach ($targets as $name => $settings) {
3344  ?>
3345  <table class="sq-backend-table">
3346  <tr>
3347  <th><?php echo $name; ?></th>
3348  <td class="sq-backend-table-header" style="text-align: right;">
3349  <?php
3350  hidden_field($prefix.'_target['.$name.'][permanent]', array_get_index($settings, 'permanent', $defaults['permanent']));
3351  if ($write_access && !array_get_index($settings, 'permanent', $defaults['permanent'])) {
3352  check_box($prefix.'_target_delete['.$name.']', '1');
3353  label(translate('delete_question'), $prefix.'_target_delete['.$name.']');
3354  }
3355  ?>
3356  </td>
3357  </tr>
3358  <tr>
3359  <td><?php echo translate('cms_listing_button_label') ?>:</td>
3360  <td>
3361  <?php
3362  if ($write_access) {
3363  text_box($prefix.'_target['.$name.'][label]', array_get_index($settings, 'label', $defaults['label']));
3364  } else {
3365  echo array_get_index($settings, 'label', $defaults['label']);
3366  }
3367  ?>
3368  </td>
3369  </tr>
3370  <tr>
3371  <td><?php echo translate('cms_listing_target') ?>:</td>
3372  <td>
3373 
3374  <?php
3375  $assetid = array_get_index(array_get_index($settings, 'target_asset', $defaults['target_asset']), 'assetid', $defaults['target_asset']['assetid']);
3376 
3377  if ($write_access) {
3378  ?>
3379  <table style="width: 100%; border: 0;">
3380  <tr>
3381  <td style="width: 100px"><?php echo translate('url') ?>:</td>
3382  <td><?php text_box($prefix.'_target['.$name.'][target_url]', array_get_index($settings, 'target_url', $defaults['target_url'])); ?></td>
3383  </tr>
3384  <tr>
3385  <td style="width: 100px"><?php echo translate('cms_listing_or_asset') ?>:</td>
3386  <td><?php asset_finder($prefix.'_target['.$name.'][target_asset]', $assetid); ?></td>
3387  </tr>
3388  </table>
3389  <?php
3390 
3391  } else {
3392 
3393  if (!empty($settings['target_url'])) {
3394 
3395  ?>
3396  <table style="width: 100%; border: 0;">
3397  <tr>
3398  <td style="width: 100px"><?php echo translate('url') ?>:</td>
3399  <td><?php echo array_get_index($settings, 'target_url', $defaults['target_url']); ?></td>
3400  </tr>
3401  </table>
3402  <?php
3403 
3404  } else if (!empty($settings['target_asset'])) {
3405 
3406  ?>
3407  <table style="width: 100%; border: 0;">
3408  <tr>
3409  <td style="width: 100px"><?php echo translate('asset') ?>:</td>
3410  <td>
3411  <?php
3412  echo get_asset_tag_line($assetid);
3413  ?>
3414  </td>
3415  </tr>
3416  </table>
3417  <?php
3418 
3419  }
3420 
3421  }
3422  ?>
3423 
3424  </td>
3425  </tr>
3426  </table><br />
3427  <?php
3428  }//end foreach $targets
3429 
3430  // new
3431  if ($write_access) {
3432  $o->closeField();
3433  $o->openField(translate('cms_listing_add_new_target_question'));
3434 
3435  text_box($prefix.'_target_new', '');
3436  }
3437 
3438  return $write_access;
3439 
3440  }//end paintTargets()
3441 
3442 
3453  function processTargets(&$asset, &$o, $prefix)
3454  {
3455  $write_access = $asset->writeAccess('attributes');
3456 
3457  if ($write_access) {
3458 
3459  $targets = $asset->attr('asset_targets');
3460  $defaults = $asset->getAssetTargetDefaults();
3461 
3462  // modify values
3463  if (!empty($_POST[$prefix.'_target'])) {
3464  foreach ($_POST[$prefix.'_target'] as $name => $settings) {
3465  // only modify, not add
3466  if (isset($targets[$name])) {
3467  $targets[$name] = array_merge_multi($defaults, $settings);
3468 
3469  // if url is set, clear the asset selection
3470  if (!empty($targets[$name]['target_url'])) {
3471  $targets[$name]['target_asset']['assetid'] = 0;
3472  }
3473  }
3474  }
3475  }
3476 
3477  // process deletions
3478  if (!empty($_POST[$prefix.'_target_delete'])) {
3479  foreach ($_POST[$prefix.'_target_delete'] as $name => $value) {
3480  if (isset($targets[$name])) unset($targets[$name]);
3481  }
3482  }
3483 
3484  // new
3485  if (!empty($_POST[$prefix.'_target_new'])) {
3486  // set the defaults
3487  $name = trim($_POST[$prefix.'_target_new']);
3488  $name = str_replace(' ','_',$name);
3489  $name = str_replace('%','_',$name);
3490 
3491  $targets[$name] = $defaults;
3492  }
3493 
3494  $asset->setAttrValue('asset_targets', $targets);
3495  }//end if
3496 
3497  return $write_access;
3498 
3499  }//end processTargets()
3500 
3501 
3512  function paintStatus(&$asset, &$o, $prefix)
3513  {
3514  require_once SQ_INCLUDE_PATH.'/general_occasional.inc';
3515  $write_access = $asset->writeAccess('attributes');
3516 
3517  $current = $asset->attr('statuses');
3518 
3519  if ($write_access) {
3520  require_once SQ_LIB_PATH.'/html_form/html_form.inc';
3521  $statuses = get_constant_values('SQ_STATUS');
3522  $options = Array();
3523  foreach ($statuses as $constant => $value) {
3524  $options[$value] = get_status_description($value);
3525  }
3526 
3527  combo_box($prefix.'_statuses', $options, TRUE, $current);
3528  hidden_field($prefix.'_statuses_submitted', '1');
3529  } else {
3530  if (empty($current)) {
3531  echo translate('cms_listing_no_status_selected');
3532  } else {
3533  ?><ul style="margin: 1px 15px;"><?php
3534  foreach ($current as $status) {
3535  echo '<li>';
3536  echo get_asset_status_icon($status);
3537  echo get_status_description($status);
3538  echo '</li>';
3539  }
3540  ?></ul><?php
3541  }
3542  }
3543  return $write_access;
3544 
3545  }//end paintStatus()
3546 
3547 
3558  function processStatus(&$asset, &$o, $prefix)
3559  {
3560  // need to have write access to make any changes
3561  if (!$asset->writeAccess('attributes')) return FALSE;
3562 
3563  // must make sure if the form 'statuses to list' was actually submitted
3564  if (!isset($_POST[$prefix.'_statuses_submitted'])) return FALSE;
3565 
3566  $statuses = Array();
3567 
3568 
3569  if (isset($_POST[$prefix.'_statuses'])) {
3570  foreach ($_POST[$prefix.'_statuses'] as $status) {
3571  $statuses[] = $status;
3572  }
3573 
3574  $statuses = array_unique($statuses);
3575  }
3576 
3577  return $asset->setAttrValue('statuses', $statuses);
3578 
3579  }//end processStatus()
3580 
3581 
3592  function paintPermissions(&$asset, &$o, $prefix)
3593  {
3594  $write_access = $asset->writeAccess('attributes');
3595 
3596  $perms = Array(
3597  'read' => SQ_PERMISSION_READ,
3598  'write' => SQ_PERMISSION_WRITE,
3599  'admin' => SQ_PERMISSION_ADMIN,
3600  );
3601 
3602  // translate permissions
3603  $perm_options = Array();
3604  foreach ($perms as $title => $perm) {
3605  $perm_options[$perm] = translate($title);
3606  }
3607  $conf_perm = $asset->attr('list_permission');
3608  $conf_eff = $asset->attr('list_effective');
3609 
3610  if ($write_access) {
3611  combo_box($prefix.'_permissions[list]', $perm_options, FALSE, $conf_perm);
3612 
3613  echo '&nbsp;';
3614 
3615  // checkbox for effective permissions
3616  check_box($prefix.'_permissions[effective]', 1, $conf_eff);
3617  label(translate('cms_listing_access_include_effective'), $prefix.'_permissions[effective]');
3618  } else {
3619  // display effective permission status
3620  if ($conf_eff) {
3621  echo translate('cms_listing_access_effective_permission', $perm_options[$conf_perm]);
3622  } else {
3623  echo $perm_options[$conf_perm];
3624  }
3625  }
3626  return $asset->writeAccess('attributes');
3627 
3628  }//end paintPermissions()
3629 
3630 
3641  function processPermissions(&$asset, &$o, $prefix)
3642  {
3643  // need to have write access to make any changes
3644  if (!$asset->writeAccess('attributes')) return FALSE;
3645  if (!isset($_POST[$prefix.'_permissions'])) return FALSE;
3646 
3647  $permission = array_get_index($_POST[$prefix.'_permissions'], 'list');
3648  $effective = array_get_index($_POST[$prefix.'_permissions'], 'effective', 0);
3649 
3650  if (is_null($permission)) return FALSE;
3651 
3652  $asset->setAttrValue('list_permission', $permission);
3653  $asset->setAttrValue('list_effective', $effective);
3654 
3655  return TRUE;
3656 
3657  }//end processPermissions()
3658 
3659 
3671  function _paintStructuredTypes(&$asset, &$o, $prefix, &$options)
3672  {
3673 
3674  $types = $options['asset_types'];
3675  if ($asset->writeAccess('content')) {
3676  // print the form fields
3677  $display_values = Array('type_code' => Array(), 'inherit' => Array());
3678  foreach ($types as $type => $inherit) {
3679  $display_values['type_code'][] = $type;
3680  $display_values['inherit'][] = $inherit;
3681  }
3682  asset_type_chooser($prefix.'_structured_types', TRUE, $display_values, NULL, TRUE, TRUE);
3683  return TRUE;
3684  } else {
3685  // print the read-only version
3686  if (empty($types)) {
3687  echo '<p class="sq-backend-warning">'.translate('cms_listing_no_asset_types_selected').'</p>';
3688  } else {
3689  $type_names = $GLOBALS['SQ_SYSTEM']->am->getTypeInfo(array_keys($types), 'name');
3690  ?>
3691  <table class="sq-backend-table">
3692  <tr>
3693  <th><?php echo translate('type') ?></th>
3694  <th><?php echo translate('inherit_question') ?></th>
3695  </tr>
3696  <?php
3697  $inherit_image_path = sq_web_path('lib').'/web/images/';
3698  foreach ($types as $type => $inherit) {
3699  $inherit_image = $inherit_image_path.($inherit ? 'tick' : 'cross').'.gif';
3700  $inherit_alt = $inherit ? translate('yes') : translate('no');
3701  ?>
3702  <tr>
3703  <td><?php echo $type_names[$type]; ?></td>
3704  <td><img src="<?php echo $inherit_image; ?>" alt="<?php echo $inherit_alt; ?>" /></td>
3705  </tr>
3706  <?php
3707  }
3708  ?>
3709  </table>
3710  <?php
3711  }
3712  return FALSE;
3713  }
3714 
3715  return TRUE;
3716 
3717  }//end _paintStructuredTypes()
3718 
3719 
3731  function _processStructuredTypes(&$asset, &$o, $prefix, &$options)
3732  {
3733  // need to have write access to make any changes
3734  if (!$asset->writeAccess('attributes')) return FALSE;
3735 
3736  if (isset($_POST[$prefix.'_structured_types'])) {
3737  $existing_types = $options['asset_types'];
3738  $submitted_types = Array();
3739  foreach ($_POST[$prefix.'_structured_types']['type_code'] as $i => $type_code) {
3740  if (!empty($type_code)) {
3741  $submitted_types[$type_code] = $_POST[$prefix.'_structured_types']['inherit'][$i];
3742  }
3743  }
3744  $options['asset_types'] = $submitted_types;
3745  $asset->setAttrValue('structured_dropdown_options', $options);
3746  return TRUE;
3747  } else {
3748  return FALSE;
3749  }
3750 
3751  }//end _processStructuredTypes()
3752 
3753 
3764  function paintStructuredDropdownOptions(&$asset, &$o, $prefix)
3765  {
3766  $write_access = $asset->writeAccess('attributes');
3767  $options = $asset->attr('structured_dropdown_options');
3768  ?>
3769  <table class="sq-backend-table">
3770  <tr>
3771  <td class="sq-backend-table-header">
3772  <?php echo translate('name') ?>:
3773  </td>
3774  <td colspan="2" class="">
3775  <?php
3776  if ($write_access) {
3777  text_box($prefix.'_structured_name', $options['name']);
3778  } else {
3779  echo $options['name'];
3780  }
3781  ?>
3782  <br />&nbsp;&nbsp;&nbsp;*<?php echo translate('must_be_selected_dynamic_parameter'); ?>
3783  </td>
3784  </tr>
3785  <tr>
3786  <td class="sq-backend-table-header">
3787  <b><?php echo translate('root_node') ?>:</b>
3788  </td>
3789  <td >
3790  <?php
3791  if ($write_access) {
3792  asset_finder($prefix.'_structured_root', $options['root_node']);
3793  } else {
3794  if ($options['root_node'] != 0) {
3795  $asset_info = $GLOBALS['SQ_SYSTEM']->am->getAssetInfo(Array($options['root_node']));
3796  if (isset($asset_info[$options['root_node']]['name'])) {
3797  echo get_asset_tag_line($options['root_node']);
3798  } else {
3799  echo translate('core_no_selected_root_node');
3800  }
3801  } else {
3802  echo translate('core_no_selected_root_node');
3803  }
3804  }
3805  ?>
3806  </td>
3807  </tr>
3808  <tr>
3809  <td class="sq-backend-table-header">
3810  <b><?php echo translate('depth') ?></b>
3811  </td>
3812 
3813  <td class="sq-backend-table-header">
3814  <?php
3815  if ($write_access) {
3816  int_text_box($prefix.'_structured_max_depth', $options['max_depth'], FALSE, 4, 0);
3817  } else {
3818  echo ($options['max_depth'] == '0' ? translate('infinite').' '.translate('depth') : $options['max_depth']);
3819  }
3820  ?>
3821  </td>
3822  </tr>
3823  <tr>
3824  <td class="sq-backend-table-header">
3825  <b><?php echo translate('asset_types') ?>:</b>
3826  </td>
3827  <td colspan="2" class="">
3828  <?php
3829  $this->_paintStructuredTypes($asset, $o, $prefix, $options);
3830  ?>
3831  </td>
3832  </tr>
3833  <tr>
3834  <td class="sq-backend-table-header">
3835  <b><?php echo translate('style') ?></b>
3836  </td>
3837 
3838  <td >
3839  <?php if ($write_access) {
3840  ?>
3841  <select name="<?php echo $prefix.'_structured_input_style'; ?>">
3842  <option value="0" <?php echo $asset->attr('check_boxes')== 0 ? 'selected="selected"' : ''; ?> ><?php echo translate('dropdown_list'); ?></option>
3843  <option value="1" <?php echo $asset->attr('check_boxes')== 1 ? 'selected="selected"' : ''; ?> ><?php echo translate('radio_buttons'); ?></option>
3844  <option value="2" <?php echo $asset->attr('check_boxes')== 2 ? 'selected="selected"' : ''; ?> ><?php echo translate('check_boxes'); ?></option>
3845  </select>
3846  <?php } else {
3847  echo $asset->attr('check_boxes') == 0 ? translate('dropdown_list') : $asset->attr('check_boxes') == 1 ? translate('radio_buttons') : translate('check_boxes');
3848  }
3849 
3850  ?>
3851  </td>
3852 
3853  </tr>
3854  <tr>
3855  <td class="sq-backend-table-header">
3856  <b><?php echo translate('width') ?></b>
3857  </td>
3858  <td >
3859  <?php
3860  if ($write_access) {
3861  int_text_box($prefix.'_structured_width', $options['width'], FALSE, 4, 0);
3862  } else {
3863  echo $options['width'] == 0 ? translate('fit_to_contents') : $options['width'];
3864  }
3865  ?>
3866  </td>
3867  </tr>
3868  <tr>
3869  <td class="sq-backend-table-header">
3870  <b><?php echo translate('height') ?></b>
3871  </td>
3872  <td >
3873  <?php
3874  if ($write_access) {
3875  int_text_box($prefix.'_structured_height', $options['height'], FALSE, 4, 0);
3876  } else {
3877  echo $options['height'] == 0 ? translate('not_specified') : $options['height'];
3878  }
3879  ?>
3880  </td>
3881  </tr>
3882  <tr>
3883  <td class="sq-backend-table-header">
3884  <b><?php echo translate('seperator') ?></b>
3885  </td>
3886 
3887  <td >
3888  <?php
3889  if ($write_access) {
3890  text_box($prefix.'_structured_seperator', $options['seperator'], FALSE, 10, 0);
3891  } else {
3892  echo $options['seperator'];
3893  }
3894  ?>
3895  </td>
3896  </tr>
3897  </table>
3898  <br />
3899  <?php
3900  return $write_access;
3901 
3902  }//end paintStructuredDropdownOptions()
3903 
3904 
3915  function processStructuredDropdownOptions(&$asset, &$o, $prefix)
3916  {
3917  // need to have write access to make any changes
3918  if (!$asset->writeAccess('attributes')) return FALSE;
3919 
3920  // Get current options
3921  $options = $asset->attr('structured_dropdown_options');
3922 
3923  // Now step thrugh and see which stuff is set. If it isn't set, the value will stay the same
3924 
3925  if (isset($_REQUEST[$prefix.'_structured_root'])) {
3926  $options['root_node'] = $_REQUEST[$prefix.'_structured_root']['assetid'];
3927  }
3928 
3929  $this->_processStructuredTypes($asset, $o, $prefix, $options);
3930 
3931  if (isset($_REQUEST[$prefix.'_structured_name'])) {
3932  $options['name'] = $_REQUEST[$prefix.'_structured_name'];
3933  }
3934  if (isset($_REQUEST[$prefix.'_structured_width'])) {
3935  $options['width'] = $_REQUEST[$prefix.'_structured_width'];
3936  }
3937  if (isset($_REQUEST[$prefix.'_structured_height'])) {
3938  $options['height'] = $_REQUEST[$prefix.'_structured_height'];
3939  }
3940  if (isset($_REQUEST[$prefix.'_structured_max_depth'])) {
3941  $options['max_depth'] = $_REQUEST[$prefix.'_structured_max_depth'];
3942  }
3943  if (isset($_REQUEST[$prefix.'_structured_seperator'])) {
3944  $options['seperator'] = $_REQUEST[$prefix.'_structured_seperator'];
3945  }
3946  if (isset($_REQUEST[$prefix.'_structured_input_style'])) {
3947  $asset->setAttrValue('check_boxes', $_REQUEST[$prefix.'_structured_input_style']);
3948  }
3949 
3950  $asset->setAttrValue('structured_dropdown_options', $options);
3951  return TRUE;
3952 
3953  }//end processStructuredDropdownOptions()
3954 
3955 
3967  function isAZListing(&$asset, $prefix)
3968  {
3969  return ($asset->attr('group_by') == 'letter');
3970 
3971  }//end isAZListing()
3972 
3973 
3987  function paintUseNoResultsBodycopy(&$asset, &$o, $prefix)
3988  {
3989  $write_access = $asset->writeAccess('links');
3990  $bodycopy_link = $GLOBALS['SQ_SYSTEM']->am->getLink($asset->id, SQ_LINK_TYPE_2, 'bodycopy', FALSE, 'no_results');
3991  $enabled = !empty($bodycopy_link);
3992 
3993  if ($write_access) {
3994  $options = Array(
3995  '1' => translate('yes'),
3996  '0' => translate('no'),
3997  );
3998 
3999  combo_box($prefix.'_use_bodycopy', $options, FALSE, Array($enabled));
4000 
4001  } else {
4002  if ($enabled) {
4003  echo translate('yes').' - '.get_asset_tag_line($bodycopy_link['minorid'], 'contents');
4004  } else {
4005  echo translate('no');
4006  }
4007  }
4008 
4009  return $write_access;
4010 
4011  }//end paintUseNoResultsBodycopy()
4012 
4013 
4024  function processUseNoResultsBodycopy(&$asset, &$o, $prefix)
4025  {
4026  if (!$asset->writeAccess('links')) return FALSE;
4027  $enabled = $_POST[$prefix.'_use_bodycopy'];
4028 
4029  $GLOBALS['SQ_SYSTEM']->changeDatabaseConnection('db2');
4030  $GLOBALS['SQ_SYSTEM']->doTransaction('BEGIN');
4031 
4032  if (!$asset->setUseNoResultsBodycopy($enabled)) {
4033  $GLOBALS['SQ_SYSTEM']->doTransaction('ROLLBACK');
4034  $GLOBALS['SQ_SYSTEM']->restoreDatabaseConnection();
4035  return FALSE;
4036  }
4037 
4038  $GLOBALS['SQ_SYSTEM']->doTransaction('COMMIT');
4039  $GLOBALS['SQ_SYSTEM']->restoreDatabaseConnection();
4040 
4041  return TRUE;
4042 
4043  }//end processUseNoResultsBodycopy()
4044 
4045 
4058  function paintProxyTypes(&$asset, &$o, $prefix)
4059  {
4060  $write_access = $asset->writeAccess('attributes');
4061  $current_types = $asset->attr('proxy_types');
4062 
4063  $am = $GLOBALS['SQ_SYSTEM']->am;
4064 
4065  $o->openField(translate('cms_listing_proxy_asset_types'));
4066  if (empty($current_types)) {
4067  echo translate('cms_listing_no_types_defined');
4068  } else {
4069  ?>
4070  <table class="sq-backend-table">
4071  <tr>
4072  <td class="sq-backend-table-header" style="width: 200px;"><?php echo translate('cms_listing_proxy_type_code') ?></td>
4073  <td class="sq-backend-table-header"><?php echo translate('cms_listing_proxy_child_type_codes') ?></td>
4074  <?php
4075  if ($write_access) {
4076  ?><td class="sq-backend-table-header" style="width: 20px;"><?php echo translate('delete') ?></td><?php
4077  }
4078  ?>
4079 
4080  </tr>
4081  <?php
4082  foreach ($current_types as $current_type => $type_settings) {
4083  ?>
4084  <tr>
4085  <td class="sq_backend-data"><?php
4086  echo get_asset_type_icon($current_type);
4087  echo $am->getTypeInfo($current_type, 'name');
4088  ?></td>
4089  <td class="sq_backend-data"><?php
4090  if ($write_access) {
4091  $i = 0;
4092  $options = Array();
4093  foreach ($type_settings as $type_code => $inherit) {
4094  $options['type_code'][$i] = $type_code;
4095  $options['inherit'][$i] = $inherit;
4096  $i++;
4097  }
4098  asset_type_chooser($prefix.'_'.$current_type.'_children', TRUE, $options, NULL, TRUE, TRUE);
4099  } else {
4100  $type_names = $am->getTypeInfo(array_keys($type_settings), 'name');
4101  ?><ul style="margin: 1px 15px"><?php
4102  foreach ($type_settings as $type_code => $inherits) {
4103  echo '<li>';
4104  echo get_asset_type_icon($type_code);
4105  echo $type_names[$type_code];
4106  if ($inherits) {
4107  echo ' ('.strtolower(translate('cms_listing_inherits_child_types')).')';
4108  }
4109  echo '</li>';
4110  }
4111  ?></ul><?php
4112  }
4113  ?></td>
4114  <?php
4115  if ($write_access) {
4116  ?><td class="sq_backend-data"><?php check_box($prefix.'_'.$current_type.'_delete'); ?></td><?php
4117  }
4118  ?>
4119  <tr>
4120  <?php
4121  }//end foreach
4122  ?>
4123  </table>
4124  <?php
4125  }//end else
4126  $o->closeField();
4127 
4128  $search_types = array_keys($asset->attr('types'));
4129  if ($write_access && !empty($search_types)) {
4130  $o->openField(translate('cms_listing_proxy_type_code_new'));
4131  $types = array_diff($search_types, array_keys($current_types));
4132 
4133  if (empty($types)) {
4134  echo translate('cms_listing_proxy_all_types_selected');
4135  } else {
4136  echo '&nbsp;';
4137  $options = Array('' => '');
4138  $options += $am->getTypeInfo($types, 'name');
4139  combo_box($prefix.'_new_type', $options, FALSE, count($types));
4140  }
4141  $o->closeField();
4142  }
4143 
4144  return $write_access;
4145 
4146  }//end paintProxyTypes()
4147 
4148 
4159  function processProxyTypes(&$asset, &$o, $prefix)
4160  {
4161  $current_types = $asset->attr('proxy_types');
4162 
4163  foreach ($current_types as $current_type => $type_settings) {
4164  // First check to see if any have been deleted
4165  if (isset($_REQUEST[$prefix.'_'.$current_type.'_delete'])) {
4166  unset($current_types[$current_type]);
4167  continue;
4168  }
4169 
4170  // Set the new types or set to an empty array if they've all been cleared
4171  if (!empty($_REQUEST[$prefix.'_'.$current_type.'_children'])) {
4172  $children = $_REQUEST[$prefix.'_'.$current_type.'_children'];
4173 
4174  $current_types[$current_type] = Array();
4175  foreach ($children['type_code'] as $index => $type_code) {
4176  if (empty($type_code)) continue;
4177  $current_types[$current_type][$type_code] = (empty($children['inherit'][$index])) ? FALSE : TRUE;
4178  }
4179 
4180  } else {
4181  $current_types[$current_type]['children'] = Array();
4182  }
4183  }
4184 
4185  if (!empty($_REQUEST[$prefix.'_new_type'])) {
4186  $current_types[$_REQUEST[$prefix.'_new_type']] = Array();
4187  }
4188 
4189  return $asset->setAttrValue('proxy_types', $current_types);
4190 
4191  }//end processProxyTypes()
4192 
4193 
4204  function paintAssetExclusion(&$asset, &$o, $prefix)
4205  {
4206  $write_access = $asset->writeAccess('attributes');
4207 
4208  $exclude_assets = $asset->attr('exclude_assets');
4209 
4210  if ($write_access) {
4211  require_once SQ_LIB_PATH.'/html_form/html_form.inc';
4212 
4213  multiple_asset_finder($prefix.'_exclude_asset', $exclude_assets);
4214  } else {
4215  echo '<ul>';
4216  foreach ($exclude_assets as $index => $assetid) {
4217  echo '<li>'.get_asset_tag_line($assetid).'</li>';
4218  }
4219  echo '</ul>';
4220  }
4221 
4222  return $write_access;
4223 
4224  }//end paintAssetExclusion()
4225 
4226 
4227 
4228 
4239  function processAssetExclusion(&$asset, &$o, $prefix)
4240  {
4241  // need to have write access to make any changes
4242  if (!$asset->writeAccess('attributes')) return FALSE;
4243  if (empty($_POST[$prefix.'_exclude_asset'])) return FALSE;
4244 
4245  $exclude_assets = $_POST[$prefix.'_exclude_asset'];
4246  $save_exclude_assets = Array();
4247  foreach ($exclude_assets as $index => $asset_info) {
4248  if (!empty($asset_info['assetid'])) {
4249  $save_exclude_assets[] = $asset_info['assetid'];
4250  }//end if
4251  }//end foreach
4252 
4253  return $asset->setAttrValue('exclude_assets', $save_exclude_assets);
4254 
4255  }//end processAssetExclusion()
4256 
4257 
4258 
4259 
4270  function paintRootNodeExclusion(&$asset, &$o, $prefix)
4271  {
4272  $write_access = $asset->writeAccess('attributes');
4273 
4274  $exclude_assets = $asset->attr('exclude_root_nodes');
4275 
4276  if ($write_access) {
4277  require_once SQ_LIB_PATH.'/html_form/html_form.inc';
4278 
4279  multiple_asset_finder($prefix.'_exclude_root_node', $exclude_assets);
4280  } else {
4281  echo '<ul>';
4282  foreach ($exclude_assets as $index => $assetid) {
4283  echo '<li>'.get_asset_tag_line($assetid).'</li>';
4284  }
4285  echo '</ul>';
4286  }
4287 
4288  return $write_access;
4289 
4290  }//end paintRootNodeExclusion()
4291 
4292 
4303  function processRootNodeExclusion(&$asset, &$o, $prefix)
4304  {
4305  // need to have write access to make any changes
4306  if (!$asset->writeAccess('attributes')) return FALSE;
4307  if (empty($_POST[$prefix.'_exclude_root_node'])) return FALSE;
4308 
4309  $exclude_assets = $_POST[$prefix.'_exclude_root_node'];
4310  $save_exclude_assets = Array();
4311  foreach ($exclude_assets as $index => $asset_info) {
4312  if (!empty($asset_info['assetid'])) {
4313  $save_exclude_assets[] = $asset_info['assetid'];
4314  }//end if
4315  }//end foreach
4316 
4317  return $asset->setAttrValue('exclude_root_nodes', $save_exclude_assets);
4318 
4319  }//end processRootNodeExclusion()
4320 
4321 
4322 
4323 }//end class
4324 
4325 
4326 ?>