Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
page_asset_builder_edit_fns.inc
1 <?php
18 require_once SQ_CORE_PACKAGE_PATH.'/page/page_edit_fns.inc';
19 require_once SQ_LIB_PATH.'/html_form/html_form.inc';
20 require_once SQ_INCLUDE_PATH.'/general_occasional.inc';
21 
22 
36 {
37 
38 
43  var $location_types = Array();
44 
45 
50  function __construct()
51  {
52  parent::__construct();
53  $this->static_screens['details']['force_unlock'] = FALSE;
54 
55  }//end constructor
56 
57 
58 //-- DETAILS SCREEN --//
59 
60 
71  function paintAssetTypes(&$asset, &$o, $prefix)
72  {
73  $types = $asset->attr('create_type');
74  if (empty($types)) {
75  echo '<p class="sq-backend-warning">'.translate('cms_asset_builder_no_types_defined').'</p>';
76  }
77  if ($asset->writeAccess('attributes')) {
78  asset_type_chooser($prefix.'_create_types', TRUE, array_keys($types));
79  } else {
80  $type_infos = $GLOBALS['SQ_SYSTEM']->am->getAssetTypes(NULL, TRUE);
81  foreach ($types as $type => $value) {
82  echo $type_infos[$type]['name'].'<br />';
83  }
84  }
85 
86  }//end paintAssetTypes()
87 
88 
99  function processAssetTypes(&$asset, &$o, $prefix)
100  {
101  if (isset($_POST[$prefix.'_create_types'])) {
102  $types = Array();
103  foreach ($_POST[$prefix.'_create_types'] as $type) {
104  if (!empty($type)) $types[$type] = 1;
105  }
106  $asset->setAttrValue('create_type', $types);
107  return TRUE;
108  }
109  return FALSE;
110 
111  }//end processAssetTypes()
112 
113 
124  function paintCreateStatus(&$asset, &$o, $prefix)
125  {
126  require_once SQ_INCLUDE_PATH.'/general_occasional.inc';
127  if (!$asset->writeAccess('attributes')) {
128  if ($asset->attr('create_status')) {
129  echo get_status_description($asset->attr('create_status'));
130  } else {
131  echo translate('cms_asset_builder_do_not_change_status');
132  }
133  } else {
134  $status_options = Array(
135  0 => translate('cms_asset_builder_do_not_change_status'),
136  SQ_STATUS_ARCHIVED => translate('archived'),
137  SQ_STATUS_UNDER_CONSTRUCTION => translate('under_construction'),
138  SQ_STATUS_LIVE => translate('live'),
139  );
140  combo_box($prefix.'_create_status', $status_options, FALSE, $asset->attr('create_status'));
141  }
142 
143  }//end paintCreateStatus()
144 
145 
156  function processCreateStatus(&$asset, &$o, $prefix)
157  {
158  if (!isset($_POST[$prefix.'_create_status'])) {
159  return FALSE;
160  }
161  $create_status = (int)$_POST[$prefix.'_create_status'];
162  return $asset->setAttrValue('create_status', $create_status);
163 
164  }//end processCreateStatus()
165 
166 
177  function paintSchemasToApply(&$asset, &$o, $prefix)
178  {
179  return $this->paintNoticeLinkedAsset($asset, 'schema_to_apply', Array('metadata_schema' => 'D'), $prefix.'schemas_to_apply', TRUE);
180 
181  }//end paintSchemasToApply()
182 
183 
194  function processSchemasToApply(&$asset, &$o, $prefix)
195  {
196  if ($asset->writeAccess('links')) {
197  $this->processNoticeLinkedAsset($asset, 'schema_to_apply', $prefix.'schemas_to_apply', TRUE);
198  }
199  return FALSE; // no need to save attrs, it's only links
200 
201  }//end processSchemasToApply()
202 
203 
214  function paintCreateFormCustomisation(&$asset, &$o, $prefix)
215  {
216  $type_names = $GLOBALS['SQ_SYSTEM']->am->getTypeInfo(array_keys($asset->attr('create_type')), 'name');
217  $customised_types = $asset->attr('create_form_customisations');
218  $wa = $asset->writeAccess('attributes');
219  if ($wa) {
220  hidden_field($prefix.'_customise_form_submitted', 1);
221  }
222  ?>
223  <table class="sq-backend-table">
224  <thead>
225  <tr>
226  <th>Asset Type</th>
227  <th>Customise Create Form?</th>
228  </tr>
229  </thead>
230  <tbody>
231  <?php
232  foreach ($type_names as $code => $name) {
233  ?>
234  <tr>
235  <td><?php echo $type_names[$code]; ?></td>
236  <td>
237  <?php
238  if ($wa) {
239  echo check_box($prefix.'_customise_form[]', $code, in_array($code, $customised_types));
240  } else {
241  $fn = in_array($code, $customised_types) ? 'tick' : 'cross';
242  echo '<img src="'.sq_web_path('lib').'/web/images/'.$fn.'.gif" />';
243  }
244  ?>
245  </td>
246  </tr>
247  <?php
248  }
249  ?>
250  </tbody>
251  </table>
252  <?php
253 
254  }//end paintCreateFormCustomisation()
255 
256 
267  function processCreateFormCustomisation(&$asset, &$o, $prefix)
268  {
269  if ($asset->writeAccess('attributes') && isset($_POST[$prefix.'_customise_form_submitted'])) {
270  $customised_types = array_get_index($_POST, $prefix.'_customise_form', Array());
271  $customised_types = array_intersect($customised_types, array_keys($asset->attr('create_type')));
272  return $asset->setAttrValue('create_form_customisations', $customised_types);
273  }
274  return FALSE;
275 
276  }//end processCreateFormCustomisation()
277 
278 
279 //-- CREATE LOCATIONS SCREEN --//
280 
281 
292  function paintFixedCreateLocations(&$asset, &$o, $prefix)
293  {
294  require_once SQ_INCLUDE_PATH.'/general_occasional.inc';
295 
296  $link_type_names = Array(
297  SQ_LINK_TYPE_1 => '',
298  SQ_LINK_TYPE_2 => '',
299  SQ_LINK_TYPE_3 => '',
300  SQ_LINK_NOTICE => '',
301  );
302  foreach ($link_type_names as $link_type => $null) {
303  $link_type_names[$link_type] = link_type_name($link_type);
304  }
305 
306  $write_access = $asset->writeAccess('attributes');
307  $locations = $asset->attr('create_location');
308 
309  if (empty($locations)) {
310  echo translate('cms_no_fixed_create_locations');
311  } else {
312  ?>
313  <table class="sq-backend-table">
314  <tr>
315  <td class="sq-backend-table-header"><?php echo translate('asset'); ?></td>
316  <td class="sq-backend-table-header"><?php echo translate('link_type'); ?></td>
317  <?php
318  if ($write_access) {
319  ?><td class="sq-backend-table-header"><?php echo translate('delete_question'); ?></td><?php
320  }
321  ?>
322  </tr>
323  <?php
324 
325  foreach ($locations as $locationid => $link_type) {
326  $location = $GLOBALS['SQ_SYSTEM']->am->getAsset($locationid, '', TRUE);
327  if (is_null($location)) continue;
328  ?>
329  <tr>
330  <td class="sq-backend-table-cell"><?php echo get_asset_tag_line($location->id); ?></td>
331  <td class="sq-backend-table-cell"><?php echo $link_type_names[$link_type]; ?>
332  </td>
333  <?php
334  if ($write_access) {
335  ?><td class="sq-backend-table-cell"><?php check_box($prefix.'_delete_location['.$location->id.']'); ?></td><?php
336  }
337  ?>
338  </tr>
339  <?php
340  $GLOBALS['SQ_SYSTEM']->am->forgetAsset($location);
341  }
342  ?>
343  </table>
344  <?php
345  }//end else
346 
347  if ($write_access) {
348  echo '<p><b>'.translate('cms_add_location').':</b>&nbsp;&nbsp;&nbsp; ';
349  asset_finder($prefix.'_new_create_location', 0, $this->location_types);
350  echo '&nbsp;&nbsp;&nbsp;'.translate('link_type').': ';
351  combo_box($prefix.'_new_link_type', $link_type_names, FALSE, '');
352  echo '</p>';
353  }
354 
355  return $write_access;
356 
357  }//end paintFixedCreateLocations()
358 
359 
370  function processFixedCreateLocations(&$asset, &$o, $prefix)
371  {
372  require_once SQ_INCLUDE_PATH.'/general_occasional.inc';
373 
374  $old_locations = $asset->attr('create_location');
375  $new_locations = $old_locations;
376 
377  // add a new create location
378  if (isset($_POST[$prefix.'_new_create_location'])) {
379  $new_location = trim($_POST[$prefix.'_new_create_location']['assetid']);
380  if ($new_location && assert_valid_assetid($new_location, 'Invalid Asset Id: #'.$new_location.' supplied for "create location"', FALSE, FALSE) && !isset($new_locations[$new_location])) {
381  $link_type_name = link_type_name((int)$_POST[$prefix.'_new_link_type']);
382  if (!empty($link_type_name)) {
383  $new_locations[$new_location] = (int)$_POST[$prefix.'_new_link_type'];
384  }
385  }
386  }
387 
388  // delete existing create locations
389  if (isset($_POST[$prefix.'_delete_location'])) {
390  foreach ($_POST[$prefix.'_delete_location'] as $locationid => $on) {
391  if (isset($new_locations[$locationid])) {
392  unset($new_locations[$locationid]);
393  }
394  }
395  }
396 
397  if ($old_locations != $new_locations) {
398  return $asset->setAttrValue('create_location', $new_locations);
399  }
400  return FALSE;
401 
402  }//end processFixedCreateLocations()
403 
404 
417  function _paintSelectableLocationSet(&$asset, &$o, $prefix, $name, &$data)
418  {
419  $write_access = $asset->writeAccess('attributes');
420  $code_name = str_replace(Array(' ','\''), '_', strtolower($name));
421  ?>
422  <table class="sq-backend-table">
423  <tr>
424  <td colspan="2" class="sq-backend-table-header">
425  <?php echo $name; ?>
426  </td>
427  </tr>
428  <tr>
429  <td class="sq-backend-table-cell">
430  <b><?php echo translate('cms_location_options') ?>:</b>
431  </td>
432  <td class="sq-backend-table-cell">
433  <?php
434  if ($write_access) {
435  multiple_asset_finder($prefix.'_'.$code_name.'_location_options', array_keys($data['locations']), $this->location_types);
436  } else {
437  echo '<ul style="margin: 1px 15px;">';
438  foreach ($data['locations'] as $assetid => $name) {
439  echo '<li>'.get_asset_tag_line($assetid).'</li>';
440  }
441  echo '</ul>';
442  }
443  ?>
444  </td>
445  </tr>
446  <tr>
447  <td class="sq-backend-table-cell">
448  <b>Link Type:</b>
449  </td>
450  <td class="sq-backend-table-cell">
451  <?php
452  $link_type_names = Array(SQ_LINK_TYPE_1=>'', SQ_LINK_TYPE_2=>'', SQ_LINK_TYPE_3=>'', SQ_LINK_NOTICE=>'');
453  foreach ($link_type_names as $link_type => $null) {
454  $link_type_names[$link_type] = link_type_name($link_type);
455  }
456  if ($write_access) {
457  combo_box($prefix.'_'.$code_name.'_link_type', $link_type_names, FALSE, $data['link_type']);
458  } else {
459  echo $link_type_names[$data['link_type']];
460  }
461  ?>
462  </td>
463  </tr>
464 
465  <tr>
466  <td class="sq-backend-table-cell">
467  <b><?php echo translate('cms_asset_builder_input_style') ?></b>
468  </td>
469 
470  <td class="sq-backend-table-cell">
471  <?php
472  if ($write_access) {
473  ?>
474  <select name="<?php echo $prefix.'_'.$code_name.'_input_style'; ?>">
475  <option value="dropdown" <?php echo $data['input_style']=='dropdown' ? 'selected="selected"' : ''; ?>>Dropdown</option>
476  <option value="radio" <?php echo $data['input_style']=='radio' ? 'selected="selected"' : ''; ?>>Radio Buttons</option>
477  </select>
478  <?php } else {
479  echo $data['input_style'];
480  }
481  ?>
482  </td>
483 
484  </tr>
485 
486  <tr>
487  <td class="sq-backend-table-cell" >
488  Rules:
489  </td>
490  <td class="sq-backend-table-cell">
491  <table border="0" cellpadding="0" cellspacing="0" style="width: 100%">
492  <tr>
493  <td style="width: 48%">
494  <?php
495  if ($write_access) {
496  ?>
497  <input type="checkbox" name="<?php echo $prefix.'_'.$code_name.'_allow_empty'; ?>" id="<?php echo $prefix.'_'.$code_name.'_allow_empty'; ?>" value="1" class="sq-form-field" <?php echo $data['allow_empty'] ? 'checked="checked"' : ''; ?> />
498  <?php
499  } else {
500  ?>
501  <img src="<?php echo sq_web_path('lib'); ?>/web/images/<?php echo $data['allow_empty'] ? 'tick' : 'cross'; ?>.gif" width="15" height="15" />
502  <?php
503  }
504  ?>
505  <?php echo translate('cms_allow_no_selection'); ?> &nbsp;&nbsp;&nbsp;&nbsp;
506  </td>
507 
508  <td style="width: 48%;">
509  <?php
510  if ($write_access) {
511  ?>
512  <input type="checkbox" name="<?php echo $prefix.'_'.$code_name.'_allow_multiple'; ?>" id="<?php echo $prefix.'_'.$code_name.'_allow_multiple'; ?>" value="1" class="sq-form-field" <?php echo $data['allow_multiple'] ? 'checked="checked"' : ''; ?> />
513  <?php
514  } else {
515  ?>
516  <img src="<?php echo sq_web_path('lib'); ?>/web/images/<?php echo $data['allow_multiple'] ? 'tick' : 'cross'; ?>.gif" width="15" height="15" />
517  <?php
518  }
519  ?>
520  <?php echo translate('cms_allow_multiple_selections'); ?> &nbsp;&nbsp;&nbsp;&nbsp;
521  </td>
522 
523  <td style="width: 4%; text-align: right">
524  <?php
525  if ($write_access) {
526  ?>
527  <input type="hidden" name="<?php echo $prefix.'_'.$code_name.'_delete' ?>" id="<?php echo $prefix.'_'.$code_name.'_delete' ?>" value="0" class="sq-form-field" /><input type="button" value="Delete Set" onclick="if (confirm(js_translate('cms_asset_builder_delete_selectable_locations'))) { document.getElementById('<?php echo $prefix.'_'.$code_name.'_delete' ?>').value=1; form.submit(); }" />
528  <?php
529  }
530  ?>
531  </td>
532  </tr>
533  </table>
534  </td>
535  </tr>
536  </table>
537  <br />
538  <?php
539 
540  }//end _paintSelectableLocationSet()
541 
542 
553  function paintSelectableLocationSets(&$asset, &$o, $prefix)
554  {
555  $write_access = $asset->writeAccess('attributes');
556  if (is_array($sets = $asset->attr('create_location_optional')) && (!empty($sets))) {
557  foreach ($sets as $name => $data) {
558  $this->_paintSelectableLocationSet($asset, $o, $prefix, $name, $data);
559  }
560  } else {
561  echo translate('cms_asset_builder_no_selectable_sets');
562  }
563 
564  if ($write_access) {
565  echo '<p><b>'.translate('cms_asset_builder_add_new_set').': </b> ';
566  text_box($prefix.'_new_set_name', '');
567  echo '</p>';
568  }
569 
570  return $write_access;
571 
572  }//end paintSelectableLocationSets()
573 
574 
585  function processSelectableLocationSets(&$asset, &$o, $prefix)
586  {
587 
588  $sets = $asset->attr('create_location_optional');
589 
590  // see if there is a set to delete altogether
591  foreach (array_keys($sets) as $name) {
592  $code_name = str_replace(Array(' ','\''), '_', strtolower($name));
593 
594  if ($_POST[$prefix.'_'.$code_name.'_delete']) {
595  unset($sets[$name]);
596  $asset->setAttrValue('create_location_optional', $sets);
597  $asset->saveAttributes();
598 
599  return TRUE; // when deleting a set, nothing else should be done.
600  }
601  }
602 
603  // update the details for existing sets
604  foreach ($sets as $name => $details) {
605  $code_name = str_replace(Array(' ','\''), '_', strtolower($name));
606  // location options
607  if (is_array($new_options = array_values($_POST[$prefix.'_'.$code_name.'_location_options']))) {
608  $sets[$name]['locations'] = Array();
609  foreach ($new_options as $option) {
610  if (($new_loc_id = $option['assetid']) && (!in_array($new_loc_id, array_keys($sets[$name]['locations'])))) {
611  $sets[$name]['locations'][$new_loc_id] = ''; // this format exists for historical reasons
612  }
613  }
614  }
615 
616  // update the other options
617  $sets[$name]['allow_empty'] = (int)isset($_POST[$prefix.'_'.$code_name.'_allow_empty']);
618  $sets[$name]['allow_multiple'] = (int)isset($_POST[$prefix.'_'.$code_name.'_allow_multiple']);
619  if (in_array(($input_style = $_POST[$prefix.'_'.$code_name.'_input_style']), Array('dropdown', 'radio'))) {
620  $sets[$name]['input_style'] = $input_style;
621  }
622  if (in_array(($link_type = $_POST[$prefix.'_'.$code_name.'_link_type']), Array(SQ_LINK_TYPE_1, SQ_LINK_TYPE_2, SQ_LINK_TYPE_3, SQ_LINK_NOTICE))) {
623  $sets[$name]['link_type'] = $link_type;
624  }
625  }
626 
627 
628  // see if there is a new set to create
629  if ($_POST[$prefix.'_new_set_name']) {
630  $sets[$_POST[$prefix.'_new_set_name']] = Array(
631  'locations' => Array(),
632  'allow_empty' => 0,
633  'allow_multiple' => 0,
634  'input_style' => 'dropdown',
635  'link_type' => SQ_LINK_TYPE_1,
636  );
637  }
638 
639  $asset->setAttrValue('create_location_optional', $sets);
640  $asset->saveAttributes();
641  $asset->_updated();
642 
643  return TRUE;
644 
645  }//end processSelectableLocationSets()
646 
647 
658  function paintConditionalCreateLocations(&$asset, &$o, $prefix)
659  {
660  $current_assets = $asset->attr('create_type');
661  if (empty($current_assets)) {
662  echo translate('cms_asset_builder_rules_no_asset_type');
663  return FALSE;
664  }
665 
666  $write_access = $asset->writeAccess('attributes');
667  $current_rules = $asset->attr('create_location_rules');
668 
669  $link_type_names = Array(SQ_LINK_TYPE_1 => '', SQ_LINK_TYPE_2 => '', SQ_LINK_TYPE_3 => '', SQ_LINK_NOTICE => '');
670  foreach ($link_type_names as $lt => $null) {
671  $link_type_names[$lt] = link_type_name($lt);
672  }
673 
674  $comparators = Array(
675  'equals' => translate('equals'),
676  'starts_with' => translate('starts_with'),
677  'ends_with' => translate('ends_with'),
678  'contains' => translate('contains'),
679  );
680 
681  $create_types = $asset->attr('create_type');
682  // print the rules for each create type
683  foreach ($create_types as $create_type => $null) {
684  echo '<p><b>'.translate('cms_asset_builder_rules_for_asset_type', $create_type).'</b></p>';
685 
686  $attributes = Array();
687  $attrs = $GLOBALS['SQ_SYSTEM']->am->getAssetTypeAttributes($create_type, Array('name', 'attrid', 'type'));
688  foreach ($attrs as $name => $data) {
689  $attributes[$name] = ucwords(str_replace('_', ' ', $name));
690  }
691  $attributes = Array(''=>'-- '.translate('select_attribute').' --') + $attributes;
692 
693  $i = 1;
694  // print out the current rules, if we have them
695  if ((isset($current_rules[$create_type])) && (is_array($rules = $current_rules[$create_type])) && (!empty($rules))) {
696  foreach ($rules as $rule) {
697  $parent_names = $GLOBALS['SQ_SYSTEM']->am->getAssetInfo($rule['locations']);
698  ?>
699  <table class="sq-backend-table" style="width: 90%; margin-left: 2em; margin-top: 1ex; "><tr><td class="sq-backend-table-header">
700  <b><?php echo translate('rule_number', $i) ?></b>
701  </td></tr>
702  <tr><td class="sq-backend-table-cell">
703 
704  <?php echo translate('cms_asset_builder_rules_all_true'); ?><br />
705  <ul>
706  <?php
707  for ($j = 0; $j < count($rule['attributes']); $j++) {
708  if ($write_access) {
709  echo '<li>';
710  combo_box($prefix.'_rules['.$create_type.']['.$i.'][attributes]['.$j.']', $attributes, FALSE, $rule['attributes'][$j]);
711  echo '&nbsp;';
712  combo_box($prefix.'_rules['.$create_type.']['.$i.'][comparators]['.$j.']', $comparators, FALSE, $rule['comparators'][$j]);
713  echo '&nbsp;';
714  text_box($prefix.'_rules['.$create_type.']['.$i.'][values]['.$j.']', $rule['values'][$j]);
715  echo '</li>';
716  } else {
717  echo '<li><i>'.$attributes[$rule['attributes'][$j]].'</i> '.$comparators[$rule['comparators'][$j]].' "'.$rule['values'][$j].'"</li>';
718  }
719  }
720  if ($write_access) {
721  // allow them to add a new condition
722  echo '<li>';
723  combo_box($prefix.'_rules['.$create_type.']['.$i.'][attributes]['.$j.']', $attributes, FALSE, '');
724  echo '&nbsp;';
725  combo_box($prefix.'_rules['.$create_type.']['.$i.'][comparators]['.$j.']', $comparators, FALSE, '');
726  echo '&nbsp;';
727  text_box($prefix.'_rules['.$create_type.']['.$i.'][values]['.$j.']', '');
728  echo '</li>';
729  }
730  ?>
731  </ul>
732 
733  <?php echo translate('cms_asset_builder_rules_link_to'); ?><br />
734  <ul style="margin-bottom: 3px;">
735  <?php
736  $j = 0;
737  while ($j < count($rule['locations'])) {
738  if ($write_access) {
739  echo '<li>';
740  asset_finder($prefix.'_rules['.$create_type.']['.$i.'][locations]['.$j.']', $rule['locations'][$j], $this->location_types);
741  echo ' '.translate('link_type').': ';
742  combo_box($prefix.'_rules['.$create_type.']['.$i.'][link_types]['.$j.']', $link_type_names, FALSE, $rule['link_types'][$j]);
743  echo '</li>';
744  } else {
745  $assetid = $rule['locations'][$j];
746  $link_type_name = $link_type_names[$rule['link_types'][$j]];
747  echo '<li>'.get_asset_tag_line($assetid).' ('.$link_type_name.')</li>';
748  }
749  $j++;
750  }
751  if ($write_access) {
752  // allow them to add a location
753  echo '<li>';
754  asset_finder($prefix.'_rules['.$create_type.']['.$i.'][locations]['.$j.']', 0, $this->location_types);
755  echo ' '.translate('link_type').': ';
756  combo_box($prefix.'_rules['.$create_type.']['.$i.'][link_types]['.$j.']', $link_type_names, FALSE, '');
757  echo '</li>';
758  }
759  ?>
760  </ul>
761  <?php
762  if ($write_access) {
763  ?>
764  <input type="hidden" name="<?php echo $prefix.'_rules['.$create_type.']['.$i.'][delete]'; ?>" id="<?php echo $prefix.'_rules_'.$create_type.'_'.$i.'_delete'; ?>" value="0" />
765  <input style="display: inline; float: right; clear: none; margin: 0px; " type="button" onclick="if (confirm(js_translate('confirm_delete_rule'))) { document.getElementById('<?php echo $prefix.'_rules_'.$create_type.'_'.$i.'_delete'; ?>').value=1; form.submit(); }" value="<?php echo translate('delete_rule'); ?>" />
766  <?php
767  }
768  ?>
769  </td></tr>
770  </table>
771 
772  <?php
773  $i++;
774  }//end foreach
775  } else {
776  ?><span style="margin-left: 2em; "><?php echo translate('cms_asset_builder_no_rules_defined') ?><br /></span><?php
777  }
778 
779  // allow the user to add a rule
780  if ($write_access) {
781  ?>
782  <table class="sq-backend-table" style="width: 90%; margin-left: 2em; margin-top: 1ex; ">
783  <tr>
784  <td class="sq-backend-table-header"><a id="<?php echo $prefix.'_'.$create_type; ?>_new_rule_link" href="#" onclick="document.getElementById('<?php echo $prefix.'_'.$create_type; ?>_new_rule_link').style.display='none'; document.getElementById('<?php echo $prefix.'_'.$create_type; ?>_new_rule_header').style.display='inline'; document.getElementById('<?php echo $prefix.'_'.$create_type; ?>_new_rule_body').style.display='block'; return false;"><b>New Rule</b></a><span style="display: none" id="<?php echo $prefix.'_'.$create_type; ?>_new_rule_header" style="display: none" ><b>New Rule</b></span></td>
785  </tr>
786 
787  <tr>
788  <td id="<?php echo $prefix.'_'.$create_type; ?>_new_rule_body" class="sq-backend-table-cell" style="display: none" >
789  <?php echo translate('cms_asset_builder_rules_all_true') ?><br />
790  <ul>
791  <?php
792  for ($j = 0; $j < 3; $j++) {
793  echo '<li>';
794  combo_box($prefix.'_rules['.$create_type.']['.$i.'][attributes]['.$j.']', $attributes, FALSE, '');
795  echo '&nbsp;';
796  combo_box($prefix.'_rules['.$create_type.']['.$i.'][comparators]['.$j.']', $comparators, FALSE, '');
797  echo '&nbsp;';
798  text_box($prefix.'_rules['.$create_type.']['.$i.'][values]['.$j.']', '');
799  }
800  ?>
801  </ul>
802 
803  <?php echo translate('cms_asset_builder_rules_link_to') ?><br />
804  <ul>
805  <li>
806  <?php
807  asset_finder($prefix.'_rules['.$create_type.']['.$i.'][locations][0]', 0, $this->location_types); echo ' Link Type: ';
808  combo_box($prefix.'_rules['.$create_type.']['.$i.'][link_types][0]', $link_type_names, FALSE, '');
809  ?>
810  </li>
811  </ul>
812  </td>
813  </tr>
814  </table>
815  <?php
816  }//end if
817 
818  }//end foreach
819 
820  return TRUE;
821 
822  }//end paintConditionalCreateLocations()
823 
824 
835  function processConditionalCreateLocations(&$asset, &$o, $prefix)
836  {
837  if (!isset($_POST[$prefix.'_rules'])) return FALSE;
838  $rules = $_POST[$prefix.'_rules'];
839 
840  // remove empty elements from our array
841  foreach ($rules as $create_type => $type_rules) {
842  foreach ($type_rules as $i => $rule_data) {
843  foreach ($rule_data['attributes'] as $index => $attribute) {
844  if ((empty($attribute)) || empty($rule_data['values'][$index])) {
845  unset($rules[$create_type][$i]['attributes'][$index]);
846  unset($rules[$create_type][$i]['comparators'][$index]);
847  unset($rules[$create_type][$i]['values'][$index]);
848  } else {
849  // make it lowercase for comparison later
850  $rules[$create_type][$i]['values'][$index] = strtolower($rules[$create_type][$i]['values'][$index]);
851  }
852  }
853  foreach ($rule_data['locations'] as $index => $location) {
854  if (empty($location['assetid'])) {
855  unset($rules[$create_type][$i]['locations'][$index]);
856  unset($rules[$create_type][$i]['link_types'][$index]);
857  } else {
858  $rules[$create_type][$i]['locations'][$index] = $location['assetid'];
859  }
860  }
861  // remove the rule altogether if it's totally empty or the delete button was clicked
862  if ((isset($rule_data['delete']) && $rule_data['delete']) || (strlen(implode('', $rule_data['attributes'])) == 0)) {
863  unset($rules[$create_type][$i]);
864  } else {
865  unset($rules[$create_type][$i]['delete']);
866  }
867 
868  }//end foreach ($type_rules)
869  }//end foreach (create_type)
870 
871  return $asset->setAttrValue('create_location_rules', $rules);
872 
873  }//end processConditionalCreateLocations()
874 
875 
886  function paintAdditionalLocationParents(&$asset, &$o, $prefix)
887  {
888  if ($asset->writeAccess('attributes')) {
889  multiple_asset_finder($prefix.'_additional_location_parents', $asset->attr('additional_location_parents'), $this->location_types);
890  } else {
891  $infos = $GLOBALS['SQ_SYSTEM']->am->getAssetInfo($asset->attr('additional_location_parents'));
892  echo '<ul style="margin: 1px 15px;">';
893  foreach ($infos as $assetid => $info) {
894  echo '<li>'.get_asset_tag_line($assetid).'</li>';
895  }
896  echo '</ul>';
897  }
898  return TRUE;
899 
900  }//end paintAdditionalLocationParents()
901 
902 
913  function processAdditionalLocationParents(&$asset, &$o, $prefix)
914  {
915  $new_parents = Array();
916  if (isset($_POST[$prefix.'_additional_location_parents']) && is_array($_POST[$prefix.'_additional_location_parents'])) {
917  foreach ($_POST[$prefix.'_additional_location_parents'] as $parent) {
918  if ($parent['assetid']) {
919  $new_parents[] = $parent['assetid'];
920  }
921  }
922  }
923  $asset->setAttrValue('additional_location_parents', $new_parents);
924 
925  }//end processAdditionalLocationParents()
926 
927 
938  function paintAdditionalLocationTypes(&$asset, &$o, $prefix)
939  {
940  if (!$asset->writeAccess('attributes')) {
941  echo '<ul style="margin: 1px 15px;">';
942  foreach ($asset->attr('additional_location_types') as $type) {
943  echo '<li>'.ucwords(str_replace('_', ' ', $type)).'</li>';
944  }
945  echo '</ul>';
946  } else {
947  asset_type_chooser($prefix.'_additional_location_types', TRUE, $asset->attr('additional_location_types'));
948  }
949  return TRUE;
950 
951  }//end paintAdditionalLocationTypes()
952 
953 
964  function processAdditionalLocationTypes(&$asset, &$o, $prefix)
965  {
966  $new_types = Array();
967  if (isset($_POST[$prefix.'_additional_location_types']) && is_array($_POST[$prefix.'_additional_location_types'])) {
968  foreach ($_POST[$prefix.'_additional_location_types'] as $type) {
969  if ($type) $new_types[] = $type;
970  }
971  }
972 
973  return $asset->setAttrValue('additional_location_types', array_unique($new_types));
974 
975  }//end processAdditionalLocationTypes()
976 
977 
988  function paintDynamicCreateLocations(&$asset, &$o, $prefix)
989  {
990  $write_access = $asset->writeAccess('attributes');
991  if (is_array($sets = $asset->attr('create_location_dynamic')) && (!empty($sets))) {
992  foreach ($sets as $name => $data) {
993  $this->_paintDynamicCreateLocationSet($asset, $o, $prefix, $name, $data);
994  }
995  } else {
996  echo translate('cms_asset_builder_no_dynamic_sets');
997  }
998 
999  if ($write_access) {
1000  echo '<p><b>'.translate('cms_asset_builder_add_new_set').': </b> ';
1001  text_box($prefix.'_new_dynamic_set_name', '');
1002  echo '</p>';
1003  }
1004 
1005  return $write_access;
1006 
1007  }//end paintDynamicCreateLocations()
1008 
1009 
1022  function _paintDynamicCreateLocationSet(&$asset, &$o, $prefix, $name, &$data)
1023  {
1024  $write_access = $asset->writeAccess('attributes');
1025  $code_name = 'dynamic_location_'.str_replace(Array(' ','\''), '_', strtolower($name));
1026  ?>
1027  <table class="sq-backend-table">
1028  <tr>
1029  <td colspan="2" class="sq-backend-table-header">
1030  <?php echo $name; ?>
1031  </td>
1032  </tr>
1033  <tr>
1034  <td class="sq-backend-table-cell">
1035  <b>Root Node:</b>
1036  </td>
1037  <td class="sq-backend-table-cell">
1038  <?php
1039  if ($write_access) {
1040  asset_finder($prefix.'_'.$code_name.'_root', array_get_index($data, 'root', 0), $this->location_types);
1041  } else {
1042  $rootid = array_get_index($data, 'root', 0);
1043  ?><p><?php
1044  if ($rootid > 0 && $GLOBALS['SQ_SYSTEM']->am->assetExists($rootid)) {
1045  echo get_asset_tag_line($rootid);
1046  } else {
1047  echo translate('none_selected');
1048  }
1049  ?></p><?php
1050  }
1051  ?>
1052  </td>
1053  </tr>
1054  <tr>
1055  <td class="sq-backend-table-cell">
1056  <b><?php echo translate('depth') ?>:</b>
1057  </td>
1058  <td class="sq-backend-table-cell">
1059  <?php
1060  if ($write_access) {
1061  int_text_box($prefix.'_'.$code_name.'_depth', array_get_index($data, 'depth', 0), FALSE, 3);
1062  echo ' '.translate('cms_asset_builder_levels_text');
1063  } else {
1064  $levels = array_get_index($data, 'depth', 0);
1065  if ($levels == 0) $levels = translate('infinite');
1066  echo '<p>'.translate('cms_asset_builder_num_levels', $levels).'</p>';
1067  }
1068  ?>
1069  </td>
1070  </tr>
1071  <tr>
1072  <td class="sq-backend-table-cell">
1073  <b><?php echo translate('cms_asset_builder_restrict_types') ?>:</b>
1074  </td>
1075  <td class="sq-backend-table-cell">
1076  <?php
1077  if (isset($data['types'])) {
1078  $selected_asset_types = $data['types'];
1079  } else {
1080  $selected_asset_types = Array(
1081  'type_code' => Array(),
1082  'inherit' => Array(),
1083  );
1084  }
1085 
1086  if ($write_access) {
1087  asset_type_chooser($prefix.'_'.$code_name.'_types', TRUE, $selected_asset_types, NULL, FALSE, TRUE);
1088  } else {
1089  foreach ($selected_asset_types['type_code'] as $index => $type) {
1090  if (empty($type)) {
1091  unset($selected_asset_types['type_code'][$index]);
1092  } else {
1093  $selected_asset_types['type_code'][$index] = $GLOBALS['SQ_SYSTEM']->am->getTypeInfo($type, 'name');
1094  }
1095  }
1096  echo implode(",<br />\n", $selected_asset_types['type_code']);
1097  }
1098  ?>
1099  </td>
1100  </tr>
1101  <tr>
1102  <td class="sq-backend-table-cell">
1103  <b><?php echo translate('cms_asset_builder_include_link_type') ?>:</b>
1104  </td>
1105  <td class="sq-backend-table-cell">
1106  <?php
1107  // the link types that dynamic create locations concern themselves with
1108  $link_types = Array(
1109  SQ_LINK_TYPE_1 => 'TYPE_1',
1110  SQ_LINK_TYPE_2 => 'TYPE_2',
1111  );
1112  if ($write_access) {
1113  foreach ($link_types as $link_type => $link_name) {
1114  if (isset($data['filter_link_type'][$link_type])) {
1115  $selected = TRUE;
1116  } else {
1117  $selected = FALSE;
1118  }
1119  check_box($prefix.'_'.$code_name.'_filter_link_type['.$link_type.']', '1', $selected);
1120  ?>&nbsp;<?php echo $link_name; ?><br />
1121  <?php
1122  }
1123  } else {
1124  $display_link_types = Array();
1125  foreach (array_get_index($data, 'filter_link_type', Array()) as $filter_link_type => $filter_link_type_data) {
1126  if (isset($link_types[$filter_link_type])) {
1127  $display_link_types[] = $link_types[$filter_link_type];
1128  }
1129  }
1130  if (empty($display_link_types)) {
1131  echo translate('cms_asset_builder_no_exclusions');
1132  } else {
1133  echo implode(",<br />\n", $display_link_types);
1134  }
1135  }
1136  ?>
1137  </td>
1138  </tr>
1139  <tr>
1140  <td class="sq-backend-table-cell">
1141  <b><?php echo translate('cms_asset_builder_created_link_type') ?>:</b>
1142  </td>
1143  <td class="sq-backend-table-cell">
1144  <?php
1145  $link_type_names = get_link_type_names();
1146  $selected_link_type = array_get_index($data, 'link_type', SQ_LINK_TYPE_1);
1147  if ($write_access) {
1148  combo_box($prefix.'_'.$code_name.'_link_type', $link_type_names, FALSE, $selected_link_type);
1149  } else {
1150  echo $link_type_names[$data['link_type']];
1151  }
1152  ?>
1153  </td>
1154  </tr>
1155 
1156  <tr>
1157  <td class="sq-backend-table-cell">
1158  <b><?php echo translate('cms_asset_builder_input_style'); ?></b>
1159  </td>
1160 
1161  <td class="sq-backend-table-cell">
1162  <?php
1163  $input_style = array_get_index($data, 'input_style', translate('none_selected'));
1164  $display_structured = array_get_index($data, 'display_structured', 0);
1165  $options = Array(
1166  'dropdown' => translate('dropdown_list'),
1167  'radio' => translate('radio_buttons'),
1168  );
1169  if ($write_access) {
1170  ?><select name="<?php echo $prefix.'_'.$code_name.'_input_style'; ?>"><?php
1171  foreach ($options as $opt_value => $opt_text) {
1172  echo '<option value="'.$opt_value.'" '.($input_style == $opt_value ? 'selected="selected"' : '').'>'.$opt_text.'</option>'."\n";
1173  }
1174  ?></select>&nbsp;<?php
1175 
1176  // display structured?
1177  check_box($prefix.'_'.$code_name.'_display_structured', '1', ($display_structured == 1 ? TRUE : FALSE));
1178  echo '&nbsp;'.translate('cms_asset_builder_display_as_tree')."\n";
1179 
1180  } else {
1181  echo '<p>'.$options[$input_style].' ('.($display_structured ? translate('cms_asset_builder_display_as_tree') : translate('cms_asset_builder_display_as_list')).')</p>';
1182  }
1183  ?>
1184  </td>
1185  </tr>
1186  <tr>
1187  <td class="sq-backend-table-cell" >
1188  <?php echo translate('rules') ?>:
1189  </td>
1190  <td class="sq-backend-table-cell">
1191  <table border="0" cellpadding="0" cellspacing="0" style="width: 100%">
1192  <tr>
1193  <td style="width: 48%">
1194  <?php
1195  $selected_allow_empty = array_get_index($data, 'allow_empty', FALSE);
1196  if ($write_access) {
1197  ?>
1198  <input type="checkbox" name="<?php echo $prefix.'_'.$code_name.'_allow_empty'; ?>" id="<?php echo $prefix.'_'.$code_name.'_allow_empty'; ?>" value="1" class="sq-form-field" <?php echo $selected_allow_empty ? 'checked="checked"' : ''; ?> />
1199  <?php
1200  } else {
1201  ?>
1202  <img src="<?php echo sq_web_path('lib'); ?>/web/images/<?php echo $selected_allow_empty ? 'tick' : 'cross'; ?>.gif" width="15" height="15" />
1203  <?php
1204  }
1205  ?> <?php echo translate('cms_allow_no_selection') ?> &nbsp;&nbsp;&nbsp;&nbsp;
1206  </td>
1207 
1208  <td style="width: 48%;">
1209  <?php
1210  $selected_allow_multiple = array_get_index($data, 'allow_multiple', FALSE);
1211  if ($write_access) {
1212  ?>
1213  <input type="checkbox" name="<?php echo $prefix.'_'.$code_name.'_allow_multiple'; ?>" id="<?php echo $prefix.'_'.$code_name.'_allow_multiple'; ?>" value="1" class="sq-form-field" <?php echo $selected_allow_multiple ? 'checked="checked"' : ''; ?> />
1214  <?php
1215  } else {
1216  ?>
1217  <img src="<?php echo sq_web_path('lib'); ?>/web/images/<?php echo $selected_allow_multiple ? 'tick' : 'cross'; ?>.gif" width="15" height="15" />
1218  <?php
1219  }
1220  ?> <?php echo translate('cms_allow_multiple_selections') ?> &nbsp;&nbsp;&nbsp;&nbsp;
1221  </td>
1222 
1223  <td style="width: 4%; text-align: right">
1224  <?php
1225  if ($write_access) {
1226  ?>
1227  <input type="hidden" name="<?php echo $prefix.'_'.$code_name.'_delete' ?>" id="<?php echo $prefix.'_'.$code_name.'_delete' ?>" value="0" class="sq-form-field" /><input type="button" value="Delete Set" onclick="if (confirm(js_translate('cms_asset_builder_delete_dynamic_locations'))) { document.getElementById('<?php echo $prefix.'_'.$code_name.'_delete' ?>').value=1; form.submit(); }" />
1228  <?php
1229  }
1230  ?>
1231  </td>
1232  </tr>
1233  </table>
1234  </td>
1235  </tr>
1236  </table>
1237  <br />
1238  <?php
1239 
1240  }//end _paintDynamicCreateLocationSet()
1241 
1242 
1253  function processDynamicCreateLocations(&$asset, &$o, $prefix)
1254  {
1255  /*
1256  * Settings structure:
1257  * $sets = Array(
1258  * 'set_name' => Array(
1259  * 'root' => location_id, // from asset_finder
1260  * 'types' => Array(
1261  * 0 => 'page',
1262  * ),
1263  * 'depth' => 0, // default to infinite levels
1264  * 'input_style' => 'dropdown', // or 'radio', 'checkbox', 'multiselect'
1265  * 'allow_empty' => false, // boolean
1266  * 'link_type' => SQ_LINK_TYPE_1,
1267  * )
1268  * )
1269  */
1270 
1271  $sets = $asset->attr('create_location_dynamic');
1272 
1273  // see if there is a set to delete altogether
1274  foreach (array_keys($sets) as $name) {
1275  $code_name = 'dynamic_location_'.str_replace(Array(' ','\''), '_', strtolower($name));
1276 
1277  if ($_POST[$prefix.'_'.$code_name.'_delete']) {
1278  unset($sets[$name]);
1279  $asset->setAttrValue('create_location_dynamic', $sets);
1280  $asset->saveAttributes();
1281 
1282  // when deleting a set, nothing else should be done.
1283  return TRUE;
1284  }
1285  }
1286 
1287  // update the details for existing sets
1288  foreach ($sets as $name => $details) {
1289  $code_name = 'dynamic_location_'.str_replace(Array(' ','\''), '_', strtolower($name));
1290 
1291  // root
1292  if (isset($_POST[$prefix.'_'.$code_name.'_root']['assetid'])) {
1293  $sets[$name]['root'] = $_POST[$prefix.'_'.$code_name.'_root']['assetid'];
1294  }
1295 
1296  // depth
1297  if (isset($_POST[$prefix.'_'.$code_name.'_depth'])) {
1298  $sets[$name]['depth'] = $_POST[$prefix.'_'.$code_name.'_depth'];
1299  }
1300 
1301  // backend display
1302  if (isset($_POST[$prefix.'_'.$code_name.'_types'])) {
1303  $sets[$name]['types'] = $_POST[$prefix.'_'.$code_name.'_types'];
1304  }
1305 
1306  // filter link_type
1307  if (isset($_POST[$prefix.'_'.$code_name.'_filter_link_type'])) {
1308  $sets[$name]['filter_link_type'] = $_POST[$prefix.'_'.$code_name.'_filter_link_type'];
1309  } else {
1310  $sets[$name]['filter_link_type'] = Array();
1311  }
1312 
1313  // input style
1314  if (in_array(($input_style = $_POST[$prefix.'_'.$code_name.'_input_style']), Array('dropdown', 'radio'))) {
1315  $sets[$name]['input_style'] = $input_style;
1316  }
1317 
1318  // display structured?
1319  if (isset($_POST[$prefix.'_'.$code_name.'_display_structured'])) {
1320  $sets[$name]['display_structured'] = $_POST[$prefix.'_'.$code_name.'_display_structured'];
1321  } else {
1322  $sets[$name]['display_structured'] = 0;
1323  }
1324 
1325  // link_type
1326  if (isset($_POST[$prefix.'_'.$code_name.'_link_type'])) {
1327  $link_type_list = get_link_type_names();
1328  if (isset($link_type_list[$_POST[$prefix.'_'.$code_name.'_link_type']])) {
1329  $sets[$name]['link_type'] = (int) $_POST[$prefix.'_'.$code_name.'_link_type'];
1330  }
1331  }
1332 
1333  // update the other options
1334  $sets[$name]['allow_empty'] = (int) isset($_POST[$prefix.'_'.$code_name.'_allow_empty']);
1335  $sets[$name]['allow_multiple'] = (int) isset($_POST[$prefix.'_'.$code_name.'_allow_multiple']);
1336  }//end foreach
1337 
1338 
1339  // see if there is a new set to create
1340  if ($_POST[$prefix.'_new_dynamic_set_name']) {
1341  $sets[$_POST[$prefix.'_new_dynamic_set_name']] = Array(
1342  'root' => 0,
1343  'depth' => 0,
1344  'allow_empty' => 0,
1345  'allow_multiple' => 0,
1346  'input_style' => 'dropdown',
1347  'link_type' => SQ_LINK_TYPE_1,
1348  'filter_link_type' => Array(
1349  SQ_LINK_TYPE_1 => '1',
1350  SQ_LINK_TYPE_2 => '1',
1351  ),
1352  'types' => Array(
1353  'type_code' => Array(),
1354  'inherit' => Array(),
1355  ),
1356  'diplay_structured' => 0,
1357  );
1358  }
1359 
1360  $asset->setAttrValue('create_location_dynamic', $sets);
1361  $asset->saveAttributes();
1362  $asset->_updated();
1363 
1364  return TRUE;
1365 
1366  }//end processDynamicCreateLocations()
1367 
1368 
1369 //-- REQUIRED FIELDS SCREEN --//
1370 
1371 
1382  function paintRequiredFields(&$asset, &$o, $prefix)
1383  {
1384  $write_access = $asset->writeAccess('attributes');
1385  $current = $asset->attr('required_fields');
1386  $metadata_schemas = Array();
1387  $metadata_schema_list = $GLOBALS['SQ_SYSTEM']->am->getLinks($asset->id, SQ_LINK_NOTICE, '', FALSE, 'major', 'schema_to_apply');
1388  foreach ($metadata_schema_list as $metadata_schema) {
1389  $metadata_schemas[] = $metadata_schema['minorid'];
1390  }
1391 
1392  foreach (array_keys($asset->attr('create_type')) as $create_type) {
1393 
1394  $attributes = Array();
1395  $attrs = $GLOBALS['SQ_SYSTEM']->am->getAssetTypeAttributes($create_type, Array('name'));
1396  foreach ($attrs as $name) {
1397  $attributes[$name] = ucwords(str_replace('_', ' ', $name));
1398  }
1399 
1400  if (!isset($current[$create_type])) {
1401  $current[$create_type] = Array();
1402  }
1403  $type_prefix = $prefix.'_'.$create_type;
1404 
1405  $type_name = $GLOBALS['SQ_SYSTEM']->am->getTypeInfo($create_type, 'name');
1406  $o->openSection($type_name);
1407  $o->openRaw();
1408 
1409  if (empty($current[$create_type])) {
1410  echo translate('cms_asset_builder_no_required_attrs');
1411  } else {
1412  ?>
1413  <table class="sq-backend-table">
1414  <tr>
1415  <td class="sq-backend-table-header"><?php echo translate('name') ?></td>
1416  <td class="sq-backend-table-header"><?php echo translate('error_text') ?></td>
1417  <?php
1418  if ($write_access) {
1419  ?><td class="sq-backend-table-header"><?php echo translate('delete_question') ?></td><?php
1420  }
1421  ?>
1422  </tr>
1423  <?php
1424  foreach ($current[$create_type] as $attr => $error_text) {
1425  $required_name = '';
1426  $pos = strpos($attr, $prefix.'_metadata_');
1427  if ($pos !== FALSE) {
1428  if (empty($metadata_schemas)) continue;
1429  $metadata_field = substr($attr, strlen($prefix.'_metadata_'));
1430  $am = $GLOBALS['SQ_SYSTEM']->am;
1431  $mf_asset = $am->getAsset($metadata_field);
1432  if (!is_null($mf_asset)) {
1433  $required_name = 'Metadata: '.$mf_asset->name;
1434  } else {
1435  $required_name = translate('unknown_metadata_field');
1436  }
1437  } else {
1438  $required_name = $attributes[$attr];
1439  }
1440  ?>
1441  <tr>
1442  <td class="sq-backend-table-cell"><?php echo $required_name; ?></td>
1443  <td class="sq-backend-table-cell">
1444  <?php
1445  if ($write_access) {
1446  text_box($type_prefix.'_required_field['.$attr.']', $error_text, 50);
1447  } else {
1448  echo $error_text;
1449  }
1450  ?>
1451  </td>
1452  <?php
1453  if ($write_access) {
1454  ?>
1455  <td class="sq-backend-table-cell">
1456  <?php check_box($type_prefix.'_delete_required['.$attr.']'); ?>
1457  </td>
1458  <?php
1459  }
1460  ?>
1461  </tr>
1462  <?php
1463  }//end foreach
1464  ?>
1465  </table>
1466  <?php
1467  }//end else
1468 
1469  if ($write_access) {
1470 
1471  $new_required = Array('' => '-- '.translate('select_attribute').' --');
1472  foreach ($attributes as $attr => $name) {
1473  if (isset($current[$create_type][$attr])) continue;
1474  $new_required[$attr] = $name;
1475  }
1476  // If a metadata schema is applied, allow the option to choose Metadata as a required field
1477  if (!empty($metadata_schemas)) {
1478  $mm = $GLOBALS['SQ_SYSTEM']->getMetadataManager();
1479  $am = $GLOBALS['SQ_SYSTEM']->am;
1480  $metadata_fields = $mm->getMetadataFields($metadata_schemas);
1481  foreach ($metadata_fields as $metadata_field => $metadata_field_type_code) {
1482  if (isset($current[$create_type][$prefix.'_metadata_'.$metadata_field])) continue;
1483  // Get each field from the schema
1484  $asset = $am->getAsset($metadata_field);
1485  if (!is_null($asset)) {
1486  $current_links = $GLOBALS['SQ_SYSTEM']->am->getLinks($asset->id, SQ_LINK_TYPE_2, 'metadata_section', FALSE, 'minor', NULL, TRUE);
1487  foreach ($current_links as $link) {
1488  $section = $GLOBALS['SQ_SYSTEM']->am->getAsset($link['majorid'], $link['major_type_code']);
1489  if (is_null($section)) continue;
1490  $restrictions = $section->attr('restrict');
1491  if (empty($restrictions) || (!is_null($create_type) && array_key_exists($create_type, $restrictions))) {
1492  $new_required[$prefix.'_metadata_'.$metadata_field] = 'Metadata: '.$asset->name;
1493  }
1494  }//end foreach
1495  }//end if
1496  $am->forgetAsset($asset);
1497  }//end foreach
1498  }
1499 
1500  echo '<br/><b>'.translate('cms_asset_builder_new_req_attr_question').' </b>';
1501  combo_box($type_prefix.'_new_required', $new_required, FALSE, '');
1502  }
1503 
1504  $o->closeRaw();
1505  $o->closeSection();
1506 
1507  }//end foreach
1508 
1509  return $write_access;
1510 
1511  }//end paintRequiredFields()
1512 
1513 
1524  function processRequiredFields(&$asset, &$o, $prefix)
1525  {
1526  $current = $asset->attr('required_fields');
1527  $required_fields = Array();
1528 
1529  foreach (array_keys($asset->attr('create_type')) as $create_type) {
1530 
1531  if (!isset($current[$create_type])) {
1532  $current[$create_type] = Array();
1533  }
1534  $type_prefix = $prefix.'_'.$create_type;
1535 
1536  // construct new required fields array removing deleted fields and updating error text
1537  foreach ($current[$create_type] as $attr => $error_text) {
1538  if (!isset($_POST[$type_prefix.'_delete_required'][$attr]) || !$_POST[$type_prefix.'_delete_required'][$attr]) {
1539  if (isset($_POST[$type_prefix.'_required_field'][$attr])) {
1540  $required_fields[$create_type][$attr] = trim($_POST[$type_prefix.'_required_field'][$attr]);
1541  } else {
1542  $required_fields[$create_type][$attr] = $current[$create_type][$attr];
1543  }//end else
1544  }//end if
1545  }//end foreach
1546 
1547  // add new required field
1548  if (isset($_POST[$type_prefix.'_new_required']) && !empty($_POST[$type_prefix.'_new_required'])) {
1549  $new_required = $_POST[$type_prefix.'_new_required'];
1550  if (!isset($required_fields[$create_type][$new_required])) {
1551  $required_fields[$create_type][$new_required] = '';
1552  }
1553  }
1554  }
1555 
1556  return $asset->setAttrValue('required_fields', $required_fields);
1557 
1558  }//end processRequiredFields()
1559 
1560 
1571  function paintCaptchaFontField(&$asset, &$o, $prefix)
1572  {
1573  if ($asset->writeAccess('attributes')) {
1574  asset_finder($prefix.'_captcha_ttf', $asset->attr('captcha_ttf'), Array('file' => 'D'));
1575  } else {
1576  $asset_info = $GLOBALS['SQ_SYSTEM']->am->getAssetInfo($asset->attr('captcha_ttf'));
1577  $ttf_file_id = $asset->attr('captcha_ttf');
1578  if ($ttf_file_id > 0) {
1579  echo get_asset_tag_line($ttf_file_id);
1580  } else {
1581  echo translate('none_selected');
1582  }
1583  }
1584  return TRUE;
1585 
1586  }//end paintCaptchaFontField()
1587 
1588 
1599  function processCaptchaFontField(&$asset, &$o, $prefix)
1600  {
1601  if (isset($_POST[$prefix.'_captcha_ttf'])) {
1602  $ttf_file_id = $_POST[$prefix.'_captcha_ttf']['assetid'];
1603 
1604  if ($ttf_file_id != $asset->attr('captcha_ttf')) {
1605  if ($ttf_file_id > 0) {
1606  // Grab the specified asset - it should be a File - and ensure that it is a TrueType Font
1607  $ttf_file = $GLOBALS['SQ_SYSTEM']->am->getAsset($ttf_file_id);
1608 
1609  $ttf_file_info = $ttf_file->getExistingFile();
1610  $filename = strtolower($ttf_file_info['filename']);
1611 
1612  $extension_index = strpos($filename, '.ttf');
1613  if (($extension_index !== FALSE) && ($extension_index == strlen($filename)-4)) {
1614  return $asset->setAttrValue('captcha_ttf', $ttf_file_id);
1615  } else {
1616  trigger_localised_error('CMS0109', E_USER_WARNING);
1617  }
1618  } else {
1619  return $asset->setAttrValue('captcha_ttf', NULL);
1620  }
1621  }
1622  }
1623 
1624  return FALSE;
1625 
1626  }//end processCaptchaFontField()
1627 
1628 
1629 //-- OTHER STUFF --//
1630 
1631 
1640  function definesMultipleLocations(&$asset)
1641  {
1642  return (count($asset->attr('create_location_optional')) > 1);
1643 
1644  }//end definesMultipleLocations()
1645 
1646 
1655  function definesMultipleAssetTypes(&$asset)
1656  {
1657  return (count($asset->attr('create_type')) > 1);
1658 
1659  }//end definesMultipleAssetTypes()
1660 
1661 
1662 //-- MOLLOM CAPTCHA --//
1663 
1664 
1675  function paintMollomAttributeToCheck(&$asset, &$o, $prefix)
1676  {
1677  $write_access = $asset->writeAccess('attributes');
1678  $current = $asset->attr('mollom_attributes_to_check');
1679  $metadata_schemas = Array();
1680  $metadata_schema_list = $GLOBALS['SQ_SYSTEM']->am->getLinks($asset->id, SQ_LINK_NOTICE, '', FALSE, 'major', 'schema_to_apply');
1681  foreach ($metadata_schema_list as $metadata_schema) {
1682  $metadata_schemas[] = $metadata_schema['minorid'];
1683  }
1684 
1685  foreach (array_keys($asset->attr('create_type')) as $create_type) {
1686 
1687  $type_name = $GLOBALS['SQ_SYSTEM']->am->getTypeInfo($create_type, 'name');
1688  $attributes = Array();
1689  $attrs = $GLOBALS['SQ_SYSTEM']->am->getAssetTypeAttributes($create_type, Array('name'));
1690  foreach ($attrs as $name) {
1691  $attributes[$name] = ucwords(str_replace('_', ' ', $name));
1692  }
1693 
1694  if (!isset($current[$create_type])) {
1695  $current[$create_type] = Array();
1696  }
1697  $type_prefix = $prefix.'_'.$create_type;
1698 
1699  if (empty($current[$create_type])) {
1700  echo translate('cms_asset_builder_mollom_no_attr_to_check').'<br />';
1701  } else {
1702  ?>
1703  <table class="sq-backend-table">
1704  <tr><td colspan="3" style="font-style:italic;"><b><?php echo $type_name; ?></b></td></tr>
1705  <tr>
1706  <td class="sq-backend-table-header"><?php echo translate('name') ?></td>
1707  <td class="sq-backend-table-header">Content Type</td>
1708  <?php
1709  if ($write_access) {
1710  ?><td class="sq-backend-table-header"><?php echo translate('delete_question') ?></td><?php
1711  }
1712  ?>
1713  </tr>
1714  <?php
1715  foreach ($current[$create_type] as $attr => $content_type) {
1716  $required_name = '';
1717  $pos = strpos($attr, $prefix.'_metadata_');
1718  if ($pos !== FALSE) {
1719  if (empty($metadata_schemas)) continue;
1720  $metadata_field = substr($attr, strlen($prefix.'_metadata_'));
1721  $am = $GLOBALS['SQ_SYSTEM']->am;
1722  $mf_asset = $am->getAsset($metadata_field);
1723  if (!is_null($mf_asset)) {
1724  $required_name = 'Metadata: '.$mf_asset->name;
1725  } else {
1726  $required_name = translate('unknown_metadata_field');
1727  }
1728  } else {
1729  $required_name = $attributes[$attr];
1730  }
1731  ?>
1732  <tr>
1733  <td class="sq-backend-table-cell"><?php echo $required_name; ?></td>
1734  <td class="sq-backend-table-cell">
1735  <?php
1736  $content_types = Array();
1737  if (file_exists(SQ_FUDGE_PATH.'/mollom/mollom.inc')) {
1738  require_once SQ_FUDGE_PATH.'/mollom/mollom.inc';
1739  $content_types = Mollom::getContentTypes();
1740  }
1741  if ($write_access) {
1742  combo_box($type_prefix.'_content_type['.$attr.']', $content_types, FALSE, $content_type);
1743  } else {
1744  echo isset($content_types[$content_type]) ? $content_types[$content_type] : '';
1745  }
1746  ?>
1747  </td>
1748  <?php
1749  if ($write_access) {
1750  ?>
1751  <td class="sq-backend-table-cell">
1752  <?php check_box($type_prefix.'_delete_content_type['.$attr.']'); ?>
1753  </td>
1754  <?php
1755  }
1756  ?>
1757  </tr>
1758  <?php
1759  }//end foreach
1760  ?>
1761  </table>
1762  <?php
1763  }//end else
1764 
1765  if ($write_access) {
1766 
1767  $new_required = Array('' => '-- '.translate('select_attribute').' --');
1768  foreach ($attributes as $attr => $name) {
1769  if (isset($current[$create_type][$attr])) continue;
1770  $new_required[$attr] = $name;
1771  }
1772  // If a metadata schema is applied, allow the option to choose Metadata as a required field
1773  if (!empty($metadata_schemas)) {
1774  $mm = $GLOBALS['SQ_SYSTEM']->getMetadataManager();
1775  $am = $GLOBALS['SQ_SYSTEM']->am;
1776  $metadata_fields = $mm->getMetadataFields($metadata_schemas);
1777  foreach ($metadata_fields as $metadata_field => $metadata_field_type_code) {
1778  if (isset($current[$create_type][$prefix.'_metadata_'.$metadata_field])) continue;
1779  // Get each field from the schema
1780  $m_asset = $am->getAsset($metadata_field);
1781  if (!is_null($m_asset)) {
1782  $current_links = $GLOBALS['SQ_SYSTEM']->am->getLinks($m_asset->id, SQ_LINK_TYPE_2, 'metadata_section', FALSE, 'minor', NULL, TRUE);
1783  foreach ($current_links as $link) {
1784  $section = $GLOBALS['SQ_SYSTEM']->am->getAsset($link['majorid'], $link['major_type_code']);
1785  if (is_null($section)) continue;
1786  $restrictions = $section->attr('restrict');
1787  if (empty($restrictions) || (!is_null($create_type) && array_key_exists($create_type, $restrictions))) {
1788  $new_required[$prefix.'_metadata_'.$metadata_field] = 'Metadata: '.$m_asset->name;
1789  }
1790  }//end foreach
1791  }//end if
1792  $am->forgetAsset($m_asset);
1793  }//end foreach
1794  }
1795 
1796  echo '<b>'.translate('cms_asset_builder_new_mollom_attr_question').' </b>';
1797  combo_box($type_prefix.'_new_content_type', $new_required, FALSE, '');
1798  echo '<br /><br />';
1799  }
1800 
1801 
1802  }//end foreach
1803 
1804  return $write_access;
1805 
1806  }//end paintMollomAttributeToCheck()
1807 
1808 
1819  function processMollomAttributeToCheck(&$asset, &$o, $prefix)
1820  {
1821  $current = $asset->attr('mollom_attributes_to_check');
1822  $content_types = Array();
1823 
1824  foreach (array_keys($asset->attr('create_type')) as $create_type) {
1825 
1826  if (!isset($current[$create_type])) {
1827  $current[$create_type] = Array();
1828  }
1829  $type_prefix = $prefix.'_'.$create_type;
1830 
1831  // construct new required fields array removing deleted fields and updating error text
1832  foreach ($current[$create_type] as $attr => $error_text) {
1833  if (!isset($_POST[$type_prefix.'_delete_content_type'][$attr]) || !$_POST[$type_prefix.'_delete_content_type'][$attr]) {
1834  if (isset($_POST[$type_prefix.'_content_type'][$attr])) {
1835  $content_types[$create_type][$attr] = trim($_POST[$type_prefix.'_content_type'][$attr]);
1836  } else {
1837  $content_types[$create_type][$attr] = $current[$create_type][$attr];
1838  }//end else
1839  }//end if
1840  }//end foreach
1841 
1842  // add new required field
1843  if (isset($_POST[$type_prefix.'_new_content_type']) && !empty($_POST[$type_prefix.'_new_content_type'])) {
1844  $new_required = $_POST[$type_prefix.'_new_content_type'];
1845  if (!isset($content_types[$create_type][$new_required])) {
1846  $content_types[$create_type][$new_required] = '';
1847  }
1848  }
1849  }
1850 
1851 
1852 
1853  return $asset->setAttrValue('mollom_attributes_to_check', $content_types);
1854 
1855  }//end processMollomAttributeToCheck()
1856 
1857 }//end class
1858 
1859 ?>