Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
page_asset_builder.inc
1 <?php
18 require_once SQ_CORE_PACKAGE_PATH.'/page/page.inc';
19 require_once SQ_FUDGE_PATH.'/general/text.inc';
20 require_once SQ_LIB_PATH.'/html_form/html_form.inc';
21 require_once SQ_FUDGE_PATH.'/mollom/mollom.inc';
22 
23 
38 class Page_Asset_Builder extends Page
39 {
40 
46  var $_current_state = '';
47 
52  var $_errors = Array();
53 
58  var $_replacements = Array();
59 
64  var $_default_state = 'create';
65 
66 
73  function __construct($assetid=0)
74  {
75  $this->_ser_attrs = TRUE;
76  parent::__construct($assetid);
77 
78  }//end constructor
79 
80 
91  function _createAdditional(&$link)
92  {
93  if (!parent::_createAdditional($link)) return FALSE;
94 
95  // add a bodycopy to this page when creating
96  $GLOBALS['SQ_SYSTEM']->am->includeAsset('bodycopy');
97  $copy_link = Array('asset' => &$this, 'link_type' => SQ_LINK_TYPE_2, 'is_dependant' => 1, 'is_exclusive' => 1, 'value' => '');
98 
99  foreach ($this->_getBodycopies() as $value => $details) {
100  $bodycopy = new Bodycopy();
101  $bodycopy->setAttrValue('name', $details['name']);
102  $copy_link['value'] = $value;
103  unset($details['name']);
104  if (!$bodycopy->create($copy_link, $details)) {
105  return FALSE;
106  }
107  }
108  return TRUE;
109 
110  }//end _createAdditional()
111 
112 
123  function saveAttributes($dont_run_updated=FALSE)
124  {
125  if (!parent::saveAttributes($dont_run_updated)) {
126  return FALSE;
127  }
128 
129  // Create / remove layouts
130  // Bug Fix : #3360 Cloning asset builder with customised create layout fail
131  // We now check is Asset Exists, because while cloning it is trying to link the layout
132  // to the page_asset_builder Asset when it doesnt exist on the system
133  if ($this->id && !$GLOBALS['SQ_SYSTEM']->am->assetInTrash($this->id, TRUE)) {
134  $custom_types = $this->attr('create_form_customisations');
135  $current_layout_links = $GLOBALS['SQ_SYSTEM']->am->getLinks($this->id, SQ_LINK_TYPE_2, 'layout', TRUE);
136  $current_layouts = Array();
137  foreach ($current_layout_links as $link) {
138  if (in_array($link['value'], $custom_types)) {
139  $current_layouts[] = $link['value'];
140  } else {
141  $GLOBALS['SQ_SYSTEM']->am->deleteAssetLink($link['linkid']);
142  }
143  }
144  $types_needing_layouts = array_diff($custom_types, $current_layouts);
145  if (!empty($types_needing_layouts)) {
146  $type_names = $GLOBALS['SQ_SYSTEM']->am->getTypeInfo($types_needing_layouts, 'name');
147  $GLOBALS['SQ_SYSTEM']->am->includeAsset('layout');
148  foreach ($types_needing_layouts as $type_code) {
149  $layout = new Layout();
150  $layout->setAttrValue('name', translate('cms_asset_builder_create_form_layout_for_type', $type_names[$type_code]));
151  $link = Array(
152  'asset' => &$this,
153  'link_type' => SQ_LINK_TYPE_2,
154  'is_dependant' => TRUE,
155  'is_exclusive' => TRUE,
156  'value' => $type_code,
157  );
158  $layout->create($link);
159  }
160  }
161  }
162  return TRUE;
163 
164  }//end saveAttributes()
165 
166 
187  function prepareLink(&$asset, $side_of_link, &$link_type, &$value, &$sort_order, &$dependant, &$exclusive)
188  {
189  // if this is a bodycopy then we need to make it a dependant link
190  if ($side_of_link == 'major' && ($asset instanceof Bodycopy) && $dependant != '1') {
191  $dependant = '1';
192  return TRUE;
193  }
194 
195  return FALSE;
196 
197  }//end prepareLink()
198 
199 
208  function isDeletableLink($linkid)
209  {
210  // the only reason why we would object to this link being deleted is if it is a bodycopy linked to us
211  $bodycopy_link = $GLOBALS['SQ_SYSTEM']->am->getLinks($this->id, SQ_LINK_TYPE_2, 'bodycopy', TRUE, 'major', NULL, '1', '1');
212 
213  if ($bodycopy_link[0]['linkid'] == $linkid && !$GLOBALS['SQ_PURGING_TRASH']) {
214  return translate('cms_cannot_delete_link', $GLOBALS['SQ_SYSTEM']->am->getTypeInfo($this->type(), 'name'));
215  }
216 
217  return parent::isDeletableLink($linkid);
218 
219  }//end isDeletableLink()
220 
221 
229  function _getAllowedLinks()
230  {
231  $page_links = parent::_getAllowedLinks();
232  $page_links[SQ_LINK_TYPE_2]['bodycopy'] = Array('card' => 'M', 'exclusive' => TRUE);
233  $page_links[SQ_LINK_NOTICE]['metadata_schema'] = Array('card' => 'M', 'exclusive' => FALSE);
234  return $page_links;
235 
236  }//end _getAllowedLinks()
237 
238 
245  function printBody()
246  {
247  if (isset($_POST['AB_'.$this->id.'_ASSET_BUILDER_ACTION'])) {
248  $GLOBALS['SQ_SYSTEM']->changeDatabaseConnection('db2');
249  }
250 
251  $this->_current_state = '';
252  $current_user = $GLOBALS['SQ_SYSTEM']->user;
253  set_error_handler(Array(&$this, '_errorHandler'));
254  $success = $this->_processGlobalActions();
255  restore_error_handler();
256 
257  // create a friendly error message on error
258  if (isset($_POST['AB_'.$this->id.'_ASSET_BUILDER_ACTION']) && !$success) {
259  $this->_replacements[strtolower($_POST['AB_'.$this->id.'_ASSET_BUILDER_ACTION']).'_error'] = $this->attr(strtolower($_POST['AB_'.$this->id.'_ASSET_BUILDER_ACTION']).'_error');
260 
261  if (!empty($this->_errors)) {
262  $errors = '';
263  foreach ($this->_errors as $text) {
264  $errors .= '<li>'.$text.'</li>';
265  }
266  $this->_replacements[strtolower($_POST['AB_'.$this->id.'_ASSET_BUILDER_ACTION']).'_error'] .= '<ul>'.$errors.'</ul>';
267  }
268  }
269 
270  // start performance mode timer
271  $GLOBALS['SQ_SYSTEM']->pm->startTimer($this, 'printBody');
272 
273  // if a new asset is created, it will be stored in the tmp vars for use by other asset types
274  // that extend this one, but we wont need it any more - so chuck it out, but first, load up
275  // some replacements for the newly created asset
276  if (isset($this->_tmp['created_asset'])) {
277  $this->_loadAssetReplacements();
278  unset($this->_tmp['created_asset']);
279  }
280 
281  if (empty($this->_current_state)) {
282  if (is_null($current_user) || ($current_user instanceof Public_User)) {
283  // this person is not logged in, so we should let them log in
284  $this->_current_state = 'not_logged_in';
285  $this->_replacements['login_invite'] = $this->getKeywordReplacement('login_invite');
286  $this->_replacements['login_form'] = $this->getKeywordReplacement('login_form');
287  } else {
288  $this->_current_state = 'logged_in';
289  }
290  }
291 
292  $fn = '_load'.$this->_default_state.'Replacements';
293  $this->$fn();
294  $this->_printBody();
295 
296  // stop performance mode timer
297  $GLOBALS['SQ_SYSTEM']->pm->stopTimer($this, 'printBody');
298 
299  if (isset($_POST['AB_'.$this->id.'_ASSET_BUILDER_ACTION'])) {
300  $GLOBALS['SQ_SYSTEM']->restoreDatabaseConnection();
301  }
302 
303  }//end printBody()
304 
305 
312  function _printBody()
313  {
314  if ($this->_current_state == 'created'){
315  $this->_printContents();
316  } else {
317  $submission_url = $this->attr('submit_to_page_url') ? replace_query_string_vars(Array(), $this->getURL()) : replace_query_string_vars(Array());
318  ?>
319  <form id="<?php echo $this->getPrefix() ?>" method="post" action="<?php echo htmlentities($submission_url); ?>" enctype="multipart/form-data" onsubmit="return form_on_submit()">
320  <?php
321  hidden_field('AB_'.$this->id.'_ASSET_BUILDER_ACTION', $this->_default_state);
322  $parameter_map = $this->getAttribute('parameter_map');
323  if (($additional_locs = $parameter_map->getParameterValue('additional_locations')) != NULL) {
324  hidden_field('AB_'.$this->id.'_ASSET_BUILDER_ADDITIONAL_LOCATIONS', $additional_locs);
325  } else if (isset($_POST['AB_'.$this->id.'_ASSET_BUILDER_ADDITIONAL_LOCATIONS'])) {
326  hidden_field('AB_'.$this->id.'_ASSET_BUILDER_ADDITIONAL_LOCATIONS', $_POST['AB_'.$this->id.'_ASSET_BUILDER_ADDITIONAL_LOCATIONS']);
327  }
328 
329  $this->_printContents();
330  ?>
331  </form>
332  <?php
333  }
334 
335  }//end _printBody()
336 
337 
345  {
346  if (!$this->attr('captcha_ttf') == '') {
347  $font = $GLOBALS['SQ_SYSTEM']->am->getAsset($this->attr('captcha_ttf'));
348  $file_path = $font->data_path.'/'.$font->attr('name');
349  } else {
350  $file_path = '';
351  }
352 
353  ob_start();
354  security_key(
355  $this->attr('captcha_length'),
356  $this->attr('captcha_length'),
357  $this->attr('captcha_zoom'),
358  FALSE,
359  trim($this->attr('captcha_bgcolour'), '#'),
360  trim($this->attr('captcha_textcolour'), '#'),
361  trim($this->attr('captcha_bordercolour'), '#'),
362  $this->attr('captcha_use_colours'),
363  $this->attr('captcha_usefont'),
364  $file_path,
365  $this->attr('captcha_font_size'),
366  $this->attr('captcha_min_angle'),
367  $this->attr('captcha_max_angle'),
368  $this->attr('captcha_x_start'),
369  $this->attr('captcha_min_distance'),
370  $this->attr('captcha_max_distance'),
371  $this->attr('captcha_width'),
372  $this->attr('captcha_height'),
373  $this->attr('captcha_arc'),
374  trim($this->attr('captcha_arc_colour'), '#'),
375  $this->attr('captcha_include_uppercase'),
376  $this->attr('captcha_include_numbers'),
377  $this->attr('provide_accessible_captcha')
378  );
379  return ob_get_clean();
380 
381  }//end getFormCaptchaKeywordReplacement()
382 
383 
391  {
392  if (!$this->attr('captcha_ttf') == '') {
393  $font = $GLOBALS['SQ_SYSTEM']->am->getAsset($this->attr('captcha_ttf'));
394  $file_path = $font->data_path.'/'.$font->attr('name');
395  } else {
396  $file_path = '';
397  }
398 
399  ob_start();
400  security_key_image_box(
401  $this->attr('captcha_length'),
402  $this->attr('captcha_zoom'),
403  trim($this->attr('captcha_bgcolour'), '#'),
404  trim($this->attr('captcha_textcolour'), '#'),
405  trim($this->attr('captcha_bordercolour'), '#'),
406  $this->attr('captcha_use_colours'),
407  $this->attr('captcha_usefont'),
408  $file_path,
409  $this->attr('captcha_font_size'),
410  $this->attr('captcha_min_angle'),
411  $this->attr('captcha_max_angle'),
412  $this->attr('captcha_x_start'),
413  $this->attr('captcha_min_distance'),
414  $this->attr('captcha_max_distance'),
415  $this->attr('captcha_width'),
416  $this->attr('captcha_height'),
417  $this->attr('captcha_arc'),
418  trim($this->attr('captcha_arc_colour'), '#'),
419  $this->attr('captcha_include_uppercase'),
420  $this->attr('captcha_include_numbers'),
421  $this->attr('provide_accessible_captcha')
422  );
423  return ob_get_clean();
424 
425  }//end getFormCaptchaImageKeywordReplacement()
426 
427 
435  {
436  ob_start();
437  security_key_field($this->attr('captcha_length'));
438  return ob_get_clean();
439 
440  }//end getFormCaptchaFieldKeywordReplacement()
441 
442 
450  {
451  ob_start();
452  security_key_image_link($this->attr('captcha_link_text'));
453  return ob_get_clean();
454 
455  }//end getFormCaptchaLinkKeywordReplacement()
456 
457 
467  {
468  $success = TRUE;
469 
470  // process some global asset builder actions
471  if (isset($_POST['AB_'.$this->id.'_ASSET_BUILDER_ACTION'])) {
472 
473  // okay, we are doing something - so success is not guaranteed
474  $success = FALSE;
475 
476  switch (strtolower($_POST['AB_'.$this->id.'_ASSET_BUILDER_ACTION'])) {
477 
478  case 'login' :
479  // they have tried logging in - but failed
480  // the error will get picked up down below though, so we dont have to do anything
481  // uhhh... lazy days.... wish all coding was this easy
482  break;
483 
484  case 'create' :
485 
486  $required_error = FALSE;
487 
488  // verify captcha
489  if ($this->attr('require_captcha')) {
490  if (!validate_security_key()) {
491  $error_text = translate('security_key_incorrect');
492  trigger_error($error_text, E_USER_NOTICE);
493  $required_error = TRUE;
494  }
495  }
496 
497  // create our dummy asset so we can access all its you beaut functions
498  // to make life easier for ourselves
499  $create_type = $_POST['AB_'.$this->id.'_ASSET_BUILDER_CREATE_TYPE'];
500  $allowed_types = $this->attr('create_type');
501  if(!isset($allowed_types[$create_type])) {
502  trigger_error('Create type is not allowed', E_USER_NOTICE);
503  return FALSE;
504  }
505  $GLOBALS['SQ_SYSTEM']->am->includeAsset($create_type);
506  $new_asset = new $create_type();
507  $prefix = $new_asset->getPrefix();
508 
509 
511  // REQUIRED FIELDS //
513  // start performance mode timer
514  $GLOBALS['SQ_SYSTEM']->pm->startTimer($this, 'checkRequiredFields');
515 
516  $required_fields = $this->attr('required_fields');
517  if (!empty($required_fields[$new_asset->type()])) {
518 
519  foreach ($required_fields[$new_asset->type()] as $attr => $error_text) {
520  $pos = strpos($attr, $this->getPrefix().'_metadata_');
521  if ($pos !== FALSE) {
522  // Process metadata
523  $mm = $GLOBALS['SQ_SYSTEM']->getMetadataManager();
524  $am = $GLOBALS['SQ_SYSTEM']->am;
525  $metadata_values = Array();
526  $cascade_values_asset_ids = Array();
527  $metadata_schemas = Array();
528  $metadata_schema_list = $GLOBALS['SQ_SYSTEM']->am->getLinks($this->id, SQ_LINK_NOTICE, '', FALSE, 'major', 'schema_to_apply');
529  foreach ($metadata_schema_list as $metadata_schema) {
530  $metadata_schemas[] = $metadata_schema['minorid'];
531  }
532  if (!empty($metadata_schemas)) {
533  $create_locations = $this->getCreateLocations($create_type);
534  $metadata_field = substr($attr, strlen($this->getPrefix().'_metadata_'));
535  $mf_asset = $am->getAsset($metadata_field);
536  $valid_value = TRUE;
537  $empty_value = TRUE;
538 
539  // Validate the metadata value
540  if (!is_null($mf_asset)) {
541  $edit_fns = $mf_asset->getEditFns();
542  $cascade = TRUE;
543  $did_process = $edit_fns->processInlineValueInterface($mf_asset, $result_value, $cascade, $create_type);
544 
545  // When date is not supplied for metadata date field
546  if ($mf_asset->type() == 'metadata_field_date' && $result_value == '---------- --:--:--') {
547  $result_value = '';
548  }
549 
550  if (!$did_process) {
551  $valid_value = FALSE;
552  }//end if
553  if (empty($result_value)) {
554  // Maybe using default
555  if (!is_null($result_value)) {
556  $empty_value = FALSE;
557  }
558  }//end if
559  }//end if
560 
561 
562  if (!$valid_value) {
563  if (empty($error_text)) {
564  $error_text = translate('cms_asset_builder_invalid_attr_value', $mf_asset->name);
565  }
566  trigger_error($error_text, E_USER_NOTICE);
567  $required_error = TRUE;
568  } else if (!$empty_value) {
569  if (empty($error_text)) {
570  $error_text = translate('cms_asset_builder_missing_attr', $mf_asset->name);
571  }
572  trigger_error($error_text, E_USER_NOTICE);
573  $required_error = TRUE;
574  }//end else
575 
576  // Forget a few things
577  $am->forgetAsset($schema);
578  $am->forgetAsset($mf_asset);
579  $am->forgetAsset($temp_asset);
580  unset($temp_asset);
581 
582  }//end if
583  } else {
584  // Process attributes
585  $real_attribute = $new_asset->getAttribute($attr, TRUE);
586  if (is_null($real_attribute)) continue;
587  // take a copy of the attribute so we don't muck anything up for the processBackend() below
588  $attribute = clone $real_attribute;
589  $attribute->process($prefix.'_'.$attribute->id);
590 
591  // For attributes that use paint and process functions, they return an empty result
592  // So we should try again with a different param
593  // See Bug #3099
594  if (empty($attribute->value)) {
595  $attribute->process($prefix.'_'.$attribute->name);
596  }//end if
597 
598  if (!$attribute->processed) {
599  if (empty($error_text)) {
600  $error_text = translate('cms_asset_builder_invalid_attr_value', $attribute->name);
601  }
602  trigger_error($error_text, E_USER_NOTICE);
603  $required_error = TRUE;
604  } else if (empty($attribute->value)) {
605  if (empty($error_text)) {
606  $error_text = translate('cms_asset_builder_missing_attr', $attribute->name);
607  }
608  trigger_error($error_text, E_USER_NOTICE);
609  $required_error = TRUE;
610  }
611 
612  unset($real_attribute);
613  unset($attribute);
614 
615  }//end else
616  }//end foreach
617 
618  }//end if
619 
620  // stop performance mode timer
621  $GLOBALS['SQ_SYSTEM']->pm->stopTimer($this, 'checkRequiredFields');
622  if ($required_error) break;
623 
625  // CREATE LOCATIONS //
627  // start performance mode timer
628  $GLOBALS['SQ_SYSTEM']->pm->startTimer($this, 'getCreateLocations');
629  if (($create_locations = $this->getCreateLocations($create_type)) === FALSE) {
630  return FALSE;
631  }
632  // stop performance mode timer
633  $GLOBALS['SQ_SYSTEM']->pm->stopTimer($this, 'getCreateLocations');
634 
635  // if we dont have any create locations, there is no point in continuing with this charade
636  // whoever set this up may think they want to build asset on the frontend, but they dont really
637  // know what they want - let them get back to us with something we can use
638  if (empty($create_locations)) {
639  trigger_localised_error('CMS0033', E_USER_WARNING, $GLOBALS['SQ_SYSTEM']->am->getTypeInfo($new_asset->type(), 'name'));
640  break;
641  }
642 
643 
645  // CREATE THE ASSET //
647  // start performance mode timer
648  $GLOBALS['SQ_SYSTEM']->pm->startTimer($this, 'createAsset');
649 
650  // we'll just use a limbo outputter to do the outputting for us
651  require_once SQ_INCLUDE_PATH.'/limbo_outputter.inc';
652  $o = new Limbo_Outputter();
653  $create_location_key = array_keys($create_locations);
654  $create_parentid = $create_location_key[0];
655  $create_location_value = array_values($create_locations);
656  $link_type = $create_location_value[0];
657  $parent = $GLOBALS['SQ_SYSTEM']->am->getAsset($create_parentid);
658  if (is_null($parent)) {
659  $this->_replacements['create_error'] = $this->getKeywordReplacement('create_error');
660  break;
661  }
662 
663  // If the link value is set, grab it, otherwise return a blank ''
664  $grab_link_value = $this->attr('link_value');
665  if (!empty($grab_link_value)) {
666  $link_value = trim($grab_link_value);
667  } else {
668  $link_value = '';
669  }
670 
671  // start the transaction to create the asset
672  $link = Array(
673  'asset' => &$parent,
674  'link_type' => $create_locations[$create_parentid],
675  'value' => $link_value,
676  'sort_order' => -1,
677  );
678 
679  $this->_modifyCreateLink($link);
680 
681  $GLOBALS['SQ_SYSTEM']->changeDatabaseConnection('db2');
682  $GLOBALS['SQ_SYSTEM']->doTransaction('BEGIN');
683 
684  // set the install run level because we are creating an asset without being
685  // logged in - so any write access checks will fail
686  if ($this->attr('allow_public_user')) {
687  $GLOBALS['SQ_SYSTEM']->setRunLevel(SQ_RUN_LEVEL_FORCED);
688  }
689 
690  // Fast track!
691  // Due to the way that events are broadcast and handled, and the complexity introduced with
692  // contexts, we can find ourselves re-regenerating/reindexing metadata, and firing off
693  // multiple trigger events for metadata regeneration with the same details.
694  //
695  // Using these 'fast track' settings, we can skip work we know will be completed later.
696  // They are unset accordingly later..
697  $new_asset->fastTrack( Array(
698  'metadata_manager_generate_content_file',
699  'search_manager_reindex_metadata',
700  'trigger_event_metadata_updated',
701  ));
702 
703  $create_success = $new_asset->processBackend($o, $link);
704  $new_asset_linkid = FALSE;
705  if ($create_success && ($_REQUEST['asset_action'] != 'create')) {
706  $new_asset_linkid = $new_asset->create($link);
707  $create_success = $create_success && $new_asset_linkid;
708  } else if ($create_success) {
709  $new_asset_link = $GLOBALS['SQ_SYSTEM']->am->getLinkByAsset($parent->id, $new_asset->id);
710  $new_asset_linkid = array_get_index($new_asset_link, 'linkid', FALSE);
711  }
712 
713  if (!$create_success) {
714  $this->_tmp['new_asset_created_'.$create_type] =& $new_asset;
715  $this->_abortAssetCreate($new_asset_linkid);
716  } else {
717  // Attributes to be verified by Mollom
718  $attr_to_verify_assets = $this->attr('mollom_attributes_to_check');
719  $attr_to_verify = isset($attr_to_verify_assets[$create_type]) ? $attr_to_verify_assets[$create_type] : Array();
720  $mollom_parameters = Array();
721 
722  // make sure text attributes dont have javascripts etc
723  foreach ($new_asset->vars as $attr_name => $attr_info) {
724  // Prepare parameters for Mollom spam verification
725  $attr_value = array_get_index($attr_info, 'value', '');
726  if ($attr_value) {
727  $attr_content_type = array_get_index($attr_to_verify, $attr_name, -1);
728  if ($attr_content_type >= 0) {
729  $mollom_parameters[$attr_content_type] = $attr_value;
730  }
731  }
732 
733  if ($attr_info['type'] == 'text') {
734  if ($attr_name == 'name' || $attr_name == 'short_name') {
735  $attr_name_value = htmlspecialchars($attr_info['value'], ENT_NOQUOTES);
736  $attr_name_value = str_replace('&amp;', '&', $attr_name_value);
737  $new_asset->setAttrValue($attr_name, $attr_name_value);
738  } else {
739  $attr_name_value = htmlspecialchars($attr_info['value']);
740  $attr_name_value = str_replace('&amp;', '&', $attr_name_value);
741  $new_asset->setAttrValue($attr_name, $attr_name_value);
742  }
743  }
744  }
745 
746 
747  // locks need to be acquired here in case any attribute values change above
748  // saveAttributes() is smart enough to only run queries if values have changed since creation, i.e. a value gets escaped above
749  $GLOBALS['SQ_SYSTEM']->am->acquireLock($new_asset->id, 'attributes');
750  $new_asset->saveAttributes();
751  $GLOBALS['SQ_SYSTEM']->am->releaseLock($new_asset->id, 'attributes');
752 
753  // stop performance mode timer
754  $GLOBALS['SQ_SYSTEM']->pm->stopTimer($this, 'createAsset');
755 
756  // start performance mode timer
757  $GLOBALS['SQ_SYSTEM']->pm->startTimer($this, 'processMetadata');
758 
759  // process metadata
760  $mm = $GLOBALS['SQ_SYSTEM']->getMetadataManager();
761  $metadata_values = Array();
762  $schemaids = $this->_getMetadataSchemasToApply();
763  $cascade_values_asset_ids = Array();
764  if (!empty($schemaids)) {
765  $metadata_run_level_changed = FALSE;
766  if ($GLOBALS['SQ_SYSTEM']->runLevelEnables(SQ_SECURITY_PERMISSIONS)) {
767  $GLOBALS['SQ_SYSTEM']->setRunLevel($GLOBALS['SQ_SYSTEM']->getRunLevel() - SQ_SECURITY_PERMISSIONS);
768  $metadata_run_level_changed = TRUE;
769  }
770  $GLOBALS['SQ_SYSTEM']->am->acquireLock($new_asset->id, 'metadata');
771  foreach ($schemaids as $schemaid) {
772  $schema = $GLOBALS['SQ_SYSTEM']->am->getAsset($schemaid);
773  $mm->setSchema($new_asset->id, $schema->id, TRUE);
774  if (!is_null($schema)) {
775  $edit_fns = $schema->getEditFns();
776  $edit_fns->processInlineValueInterface($schema, $metadata_values, $cascade_values_asset_ids, $create_type);
777  }
778  }
779 
780  // set metadata without reindexing and reset the switch to skip reindex
781  $mm->setMetadata($new_asset->id, $metadata_values);
782 
783  // Fast track's mission is accomplished, reset.
784  $new_asset->unFastTrack( Array(
785  'metadata_manager_generate_content_file',
786  'search_manager_reindex_metadata',
787  'trigger_event_metadata_updated',
788  ));
789 
790  $mm->regenerateMetadata($new_asset->id, 'all');
791 
792  $GLOBALS['SQ_SYSTEM']->am->releaseLock($new_asset->id, 'metadata');
793  if ($metadata_run_level_changed) {
794  $GLOBALS['SQ_SYSTEM']->restoreRunLevel();
795  }
796 
797  // Set metadata values for Mollom check, if any
798  foreach($metadata_values as $fieldid => $m_data) {
799  $attr_content_type = array_get_index($attr_to_verify, $this->getPrefix().'_metadata_'.$fieldid, -1);
800  if ($attr_content_type >= 0) {
801  $m_value = array_get_index($m_data[0], 'value', '');
802  if (!empty($m_value)) {
803  $mollom_parameters[$attr_content_type] = $m_value;
804  }
805  }
806  }//end foreach
807  }
808 
809  // stop performance mode timer
810  $GLOBALS['SQ_SYSTEM']->pm->stopTimer($this, 'processMetadata');
811 
812  // Carryout Mollom spam verification
813  if ($this->attr('use_mollom') && !empty($mollom_parameters)) {
814  $mollom_result = Mollom::verifySubmission($this->id, $mollom_parameters);
815  switch ($mollom_result) {
816  case SQ_MOLLOM_SPAM:
817  // Mollom has identified this submission as spam
818  $error_text = $this->attr('mollom_spam_submission_text');
819  if ($error_text) {
820  $this->_errors[] = $error_text;
821  } else {
822  $this->_errors[] = translate('cms_asset_builder_mollom_spam_submission_message');
823  }
824  break;
825 
826  case SQ_MOLLOM_UNSURE:
827  // Mollom is not sure about the submission
828  $error_text = $this->attr('mollom_unsure_submission_text');
829  if ($error_text) {
830  $this->_errors[] = $error_text;
831  } else {
832  $this->_errors[] = translate('cms_asset_builder_mollom_unsure_spam_submission_message');
833  }
834  break;
835 
836  case SQ_MOLLOM_HAM:
837  // Everything cool
838  break;
839 
840  case SQ_MOLLOM_UNKNOWN:
841  // No response from Mollom
842  break;
843 
844  case SQ_MOLLOM_INCORRECT_CAPTCHA:
845  $error_text = $this->attr('mollom_captcha_incorrect_text');
846  if($error_text) {
847  $this->_errors[] = $error_text;
848  } else {
849  $this->_errors[] = translate('cms_asset_builder_mollom_invalid_captcha_message');
850  }
851  break;
852  }//end switch
853  }//end if use mollom
854 
855  // start performance mode timer
856  $GLOBALS['SQ_SYSTEM']->pm->startTimer($this, 'processLayouts');
857 
858  // process paint layouts
859  $layouts['paint_layout::system::frontend'] = $this->attr('layout_to_apply');
860  $layouts['override::paint_layout::system::frontend'] = $this->attr('override_layout_to_apply');
861  $new_asset->setPaintLayouts($layouts);
862 
863  // stop performance mode timer
864  $GLOBALS['SQ_SYSTEM']->pm->stopTimer($this, 'processLayouts');
865 
866  // start performance mode timer
867  $GLOBALS['SQ_SYSTEM']->pm->startTimer($this, 'linkMultipleLocations');
868 
869  // if we have multiple locations to create this asset under, create
870  // the new links to all the other parents
871  if (is_array($create_locations)) {
872  foreach ($create_locations as $link_parentid => $link_type) {
873 
874  // skip the orginal parent we linked the new asset to
875  if ($link_parentid == $parent->id) continue;
876 
877  $link_parent = $GLOBALS['SQ_SYSTEM']->am->getAsset($link_parentid, '', TRUE);
878  if (is_null($link_parent)) {
879  trigger_localised_error('CMS0034', E_USER_WARNING, $link_parentid);
880  continue;
881  }
882  if (!$GLOBALS['SQ_SYSTEM']->am->createAssetLink($link_parent, $new_asset, $link_type, $link_value)) {
883  trigger_localised_error('CMS0035', E_USER_WARNING, $link_parent->id);
884  continue;
885  }
886 
887  $current_paths = $new_asset->getWebPaths();
888 
889  // ensure we always have valid web paths if more than one create location
890  require_once SQ_INCLUDE_PATH.'/general_occasional.inc';
891  $valid_paths = make_valid_web_paths($current_paths, $new_asset->id);
892  $valid_paths = $GLOBALS['SQ_SYSTEM']->am->webPathsInUse($link_parent, $valid_paths, $new_asset->id, TRUE);
893 
894  if (!$new_asset->saveWebPaths($valid_paths, FALSE)) {
895  $this->_errors[] = translate('cms_asset_builder_cannot_save_web_path', $new_asset->name, $link_parent->name);
896  }
897  // if there is no difference in the arrays
898  // we have to update lookups mannualy, otherwise it would have be done in saveWebPath already
899  if (!array_diff_assoc($valid_paths, $current_paths) && !array_diff_assoc($current_paths, $valid_paths)) {
900  $new_asset->updateLookups();
901  }
902  }
903  }
904 
905  // stop performance mode timer
906  $GLOBALS['SQ_SYSTEM']->pm->stopTimer($this, 'linkMultipleLocations');
907 
908  // start performance mode timer
909  $GLOBALS['SQ_SYSTEM']->pm->startTimer($this, 'setCreateStatus');
910 
911  if (empty($this->_errors)) {
912  $GLOBALS['SQ_SYSTEM']->doTransaction('COMMIT');
913  $GLOBALS['SQ_SYSTEM']->restoreDatabaseConnection();
914  $this->_current_state = 'created';
915  $success = TRUE;
916  $this->_setCreateStatus($new_asset);
917  $this->_tmp['created_asset'] = $new_asset;
918 
919  // if we have reached so far the asset has been built, even with regards to Account Manager Asset,
920  // user is created already, so lets celebrate firing (trigger) !!!
921  $GLOBALS['SQ_SYSTEM']->broadcastTriggerEvent('trigger_event_after_asset_built', $new_asset);
922  } else {
923  $this->_abortAssetCreate($new_asset_linkid);
924  }
925 
926  // stop performance mode timer
927  $GLOBALS['SQ_SYSTEM']->pm->stopTimer($this, 'setCreateStatus');
928  }//end else
929 
930  if ($this->attr('allow_public_user')) {
931  $GLOBALS['SQ_SYSTEM']->restoreRunLevel();
932  }
933 
934  break;
935 
936  default :
937  // there was an action, but we didnt do anything
938  $success = TRUE;
939 
940  break;
941 
942  }//end switch
943 
944  }//end if ASSET_BUILDER_ACTION
945 
946  return $success;
947 
948  }//end _processGlobalActions()
949 
950 
951  /*
952  * Abort the asset creation (asset created by Asset Builder)
953  *
954  * @param int $linkid Linkid of the asset that failed while getting created
955  *
956  * @return void
957  * @access private
958  */
959  function _abortAssetCreate($linkid=0)
960  {
961  $GLOBALS['SQ_SYSTEM']->doTransaction('ROLLBACK');
962  $GLOBALS['SQ_SYSTEM']->restoreDatabaseConnection();
963 
964  // Clean up the redundent links left in the link table
965  if ($linkid) {
966  $GLOBALS['SQ_SYSTEM']->changeDatabaseConnection('db3');
967 
968  $sql = '
969  SELECT t.treeid
970  FROM sq_ast_lnk_tree t INNER JOIN sq_ast_lnk l ON t.linkid = l.linkid
971  WHERE l.linkid = :linkid';
972  $sql = db_extras_modify_limit_clause($sql, MatrixDAL::getDbType(), 1);
973 
974  try {
975  $query = MatrixDAL::preparePdoQuery($sql);
976  MatrixDAL::bindValueToPdo($query, 'linkid', $linkid);
977  $treeid = MatrixDAL::executePdoOne($query);
978  } catch (Exception $e) {
979  throw new Exception('Unable to get treeid for linkid: '.$linkid.' due to database error: '.$e->getMessage());
980  }
981 
982  if (!empty($treeid)) {
983  $sql = '
984  SELECT t.linkid
985  FROM sq_ast_lnk_tree t
986  WHERE
987  t.treeid LIKE :treeid';
988 
989  try {
990  $query = MatrixDAL::preparePdoQuery($sql);
991  MatrixDAL::bindValueToPdo($query, 'treeid', $treeid.'%');
992  $result = MatrixDAL::executePdoAssoc($query);
993  } catch (Exception $e) {
994  throw new Exception('Unable to get linkids like treeid: '.$treeid.' due to database error: '.$e->getMessage());
995  }
996 
997  $result[]['linkid'] = '';
998  $to_delete_links = Array();
999  foreach($result as $row) {
1000  if (isset($row['linkid']) && $row['linkid']) {
1001  $to_delete_links[] = $row['linkid'];
1002  }
1003  }
1004 
1005  // Get rid of redendent links from the link and link tree table
1006  $GLOBALS['SQ_SYSTEM']->doTransaction('BEGIN');
1007 
1008  $sql = '
1009  DELETE FROM sq_ast_lnk
1010  WHERE linkid IN ('.implode(', ',$to_delete_links).')';
1011 
1012  try {
1013  $query = MatrixDAL::preparePdoQuery($sql);
1014  $result = MatrixDAL::executePdoAssoc($query);
1015  } catch (Exception $e) {
1016  throw new Exception('Unable to delete redundent links from sq_ast_lnk table due to database error: '.$e->getMessage());
1017  }
1018 
1019  $sql = '
1020  DELETE FROM sq_ast_lnk_tree
1021  WHERE linkid IN ('.implode(', ',$to_delete_links).')';
1022 
1023  try {
1024  $query = MatrixDAL::preparePdoQuery($sql);
1025  $result = MatrixDAL::executePdoAssoc($query);
1026  } catch (Exception $e) {
1027  throw new Exception('Unable to delete redundent links from sq_ast_lnk_tree table due to database error: '.$e->getMessage());
1028  }
1029 
1030  $GLOBALS['SQ_SYSTEM']->doTransaction('COMMIT');
1031  }
1032 
1033  $GLOBALS['SQ_SYSTEM']->restoreDatabaseConnection();
1034 
1035  }// end if
1036 
1037  }//end function _abortAssetCreate()
1038 
1039 
1047  {
1048  $all_selected_locations = Array();
1049  foreach ($this->attr('create_location_optional') as $set_name => $details) {
1050  $selected_locations = Array();
1051  $code_name = $this->_sanitiseLocationSetName($set_name);
1052  if (isset($_POST[$code_name])) {
1053  if ($details['allow_multiple'] && is_array($_POST[$code_name])) {
1054  foreach ($_POST[$code_name] as $location_id) {
1055  // add it to the list
1056  $selected_locations[] = $location_id;
1057  }
1058  // check the list options are valid
1059  $selected_locations = array_intersect($selected_locations, array_keys($details['locations']));
1060  // add them to the collection
1061  foreach ($selected_locations as $location_id) {
1062  $all_selected_locations[$location_id] = (int)$details['link_type'];
1063  }
1064  } else {
1065  // if it's valid, add it to the list
1066  if (in_array($_POST[$code_name], array_keys($details['locations']))) {
1067  $all_selected_locations[$_POST[$code_name]] = (int)$details['link_type'];
1068  }
1069  }
1070  } else if (!$details['allow_empty']) {
1071  trigger_localised_error('CMS0036', E_USER_WARNING, $set_name);
1072  return FALSE;
1073  }
1074  }
1075  return $all_selected_locations;
1076 
1077  }//end getSelectedCreateLocations()
1078 
1079 
1087  {
1088  $res = Array();
1089  $selectable_sets = $this->attr('create_location_optional');
1090  if (is_array($selectable_sets)) {
1091  foreach ($selectable_sets as $set_name => $set_details) {
1092  foreach ($set_details['locations'] as $loc => $name) {
1093  if (isset($res[$loc])) {
1094  $res[$loc] = min($res[$loc], $set_details['link_type']);
1095  } else {
1096  $res[$loc] = $set_details['link_type'];
1097  }
1098  }
1099  }
1100  }
1101  return $res;
1102 
1103  }//end getAllSelectableCreateLocations()
1104 
1105 
1113  {
1114  if (empty($this->id)) return Array();
1115  $schema_links = $GLOBALS['SQ_SYSTEM']->am->getLinks($this->id, SQ_LINK_NOTICE, 'metadata_schema', FALSE, 'major', 'schema_to_apply');
1116  $res = Array();
1117  foreach ($schema_links as $link) {
1118  $res[] = $link['minorid'];
1119  }
1120  return $res;
1121 
1122  }//end _getMetadataSchemasToApply()
1123 
1124 
1134  {
1135  return $this->attr('create_location');
1136 
1137  }//end getFixedCreateLocations()
1138 
1139 
1149  function getRuleMatchCreateLocations($create_type, $attributes=Array())
1150  {
1151  $all_rule_match_locations = Array();
1152  if (empty($attributes)) {
1153  $create_type = $_POST['AB_'.$this->id.'_ASSET_BUILDER_CREATE_TYPE'];
1154  $GLOBALS['SQ_SYSTEM']->am->includeAsset($create_type);
1155  $temp_asset = new $create_type();
1156  $prefix = $temp_asset->getPrefix();
1157  unset($temp_asset);
1158  }
1159 
1160  // check what rules dictate where the asset should be created
1161  $location_rules = $this->attr('create_location_rules');
1162  $attributeids = ($GLOBALS['SQ_SYSTEM']->am->getAssetTypeAttributes($create_type, Array('name', 'attrid')));
1163  if (!empty($location_rules[$create_type])) {
1164  foreach ($location_rules[$create_type] as $i => $rule) {
1165  $pass = TRUE;
1166  $j = 0;
1167  while ($j < count($rule['attributes'])) {
1168  if (empty($attributes)) {
1169  $attr_value = isset($_POST[$prefix.'_'.$attributeids[$rule['attributes'][$j]]['attrid']]) ? trim(strtolower($_POST[$prefix.'_'.$attributeids[$rule['attributes'][$j]]['attrid']])) : '';
1170  } else {
1171  $attr_value = isset($attributes[$rule['attributes'][$j]]) ? trim(strtolower($attributes[$rule['attributes'][$j]])) : '';
1172  }
1173 
1174  switch ($rule['comparators'][$j]) {
1175  case 'equals':
1176  if ($attr_value != $rule['values'][$j]) $pass = FALSE;
1177  break;
1178 
1179  case 'starts_with':
1180  if (!preg_match('|^'.$rule['values'][$j].'.*$|', $attr_value)) {
1181  $pass = FALSE;
1182  }
1183  break;
1184 
1185  case 'ends_with':
1186  if (!preg_match('|^.*'.$rule['values'][$j].'$|', $attr_value)) {
1187  $pass = FALSE;
1188  }
1189  break;
1190 
1191  case 'contains':
1192  if (strpos($attr_value, $rule['values'][$j]) === FALSE) {
1193  $pass = FALSE;
1194  }
1195  break;
1196  }
1197  $j++;
1198  }//end while
1199 
1200  if ($pass) {
1201  foreach ($rule['locations'] as $index => $assetid) {
1202  $all_rule_match_locations[$assetid] = $rule['link_types'][$index];
1203  }
1204  }
1205  }//end foreach
1206  }//end if
1207  return $all_rule_match_locations;
1208 
1209  }//end getRuleMatchCreateLocations()
1210 
1211 
1220  function getCreateLocations($create_type)
1221  {
1222  if (is_array($selected_locs = $this->getSelectedCreateLocations())) {
1223  $res = $this->getFixedCreateLocations()
1224  + $selected_locs
1225  + $this->getRuleMatchCreateLocations($create_type)
1226  + $this->getAdditionalCreateLocations()
1227  + $this->getDynamicCreateLocations();
1228 
1229  // make sure all the create locations actually exist
1230  $details = $GLOBALS['SQ_SYSTEM']->am->getAssetInfo(array_keys($res), Array(), TRUE, 'name');
1231  foreach ($res as $i => $v) {
1232  if (empty($details[$i])) {
1233  unset($res[$i]);
1234  }
1235  }
1236 
1237  return $res;
1238  } else {
1239  // failed to select some compulsory selectable locations
1240  return FALSE;
1241  }
1242 
1243  }//end getCreateLocations()
1244 
1245 
1256  {
1257  $res = Array();
1258  $additional_locs = '';
1259 
1260  $parameter_map = $this->getAttribute('parameter_map');
1261  if (isset($_REQUEST['AB_'.$this->id.'_ASSET_BUILDER_ADDITIONAL_LOCATIONS']) && !empty($_REQUEST['AB_'.$this->id.'_ASSET_BUILDER_ADDITIONAL_LOCATIONS'])) {
1262  $additional_locs = $_REQUEST['AB_'.$this->id.'_ASSET_BUILDER_ADDITIONAL_LOCATIONS'];
1263  } else if ($parameter_map->getParameterValue('additional_locations') != NULL) {
1264  // As per Bug #2982, the POST var was not registering here, so here we check for the value
1265  // and allow asset builder to create the asset.
1266  $additional_locs = $parameter_map->getParameterValue('additional_locations');
1267  }
1268 
1269  if (!empty($additional_locs)) {
1270  // get the assetids and link types
1271  foreach (explode(';', $additional_locs) as $loc_code) {
1272  if (FALSE === strpos($loc_code, '-')) {
1273  // no link type specified, use the default
1274  $link_type = $this->attr('additional_location_default_link_type');
1275  $loc_id = $loc_code;
1276  } else {
1277  list($loc_id, $link_type) = explode('-', $loc_code);
1278  }
1279  if (!isset($res[$loc_id]) || ($res[$loc_id] > $link_type)) {
1280  $res[$loc_id] = $link_type;
1281  }
1282  }
1283  // check that the types and tree locations are valid
1284  $infos = $GLOBALS['SQ_SYSTEM']->am->getAssetInfo(array_keys($res));
1285  $valid_types = $this->attr('additional_location_types');
1286  $valid_parents = $this->attr('additional_location_parents');
1287  foreach ($infos as $assetid => $info) {
1288  if (!in_array($info['type_code'], $valid_types)) {
1289  $matches = array_intersect($GLOBALS['SQ_SYSTEM']->am->getTypeAncestors($info['type_code']), $valid_types);
1290  if (empty($matches)) {
1291  unset($res[$assetid]);
1292  } else {
1293  // save us looking it up again
1294  $valid_types[] = $info['type_code'];
1295  }
1296  }
1297  if (!in_array($assetid, $valid_parents)) {
1298  $matches = array_intersect(array_keys($GLOBALS['SQ_SYSTEM']->am->getParents($assetid)), $valid_parents);
1299  if (empty($matches)) unset($res[$assetid]);
1300  }
1301  }
1302  } // end if (!empty($additional_locs))
1303  return $res;
1304 
1305  }//end getAdditionalCreateLocations()
1306 
1307 
1315  {
1316  $all_selected_locations = Array();
1317  foreach ($this->attr('create_location_dynamic') as $set_name => $details) {
1318  $code_name = $this->_sanitiseLocationSetName($set_name);
1319  if (isset($_POST[$code_name]) && !empty($_POST[$code_name])) {
1320  $locations = $_POST[$code_name];
1321  if (!is_array($locations)) {
1322  $locations = Array($_POST[$code_name]);
1323  }
1324 
1325  foreach ($locations as $location_id) {
1326  $all_selected_locations[$location_id] = $details['link_type'];
1327  if (!$details['allow_multiple']) break;
1328  }
1329  } else if (!$details['allow_empty']) {
1330  trigger_localised_error('CMS0036', E_USER_WARNING, $set_name);
1331  return Array();
1332  }
1333  }
1334 
1335  return $all_selected_locations;
1336 
1337  }//end getDynamicCreateLocations()
1338 
1339 
1348  function _sanitiseLocationSetName($set_name)
1349  {
1350  return str_replace(Array(' ','\''), '_', strtolower($set_name));
1351 
1352  }//end _sanitiseLocationSetName()
1353 
1354 
1363  function _modifyCreateLink(&$link)
1364  {
1365  return;
1366 
1367  }//end _modifyCreateLink()
1368 
1369 
1378  function _setCreateStatus(&$new_asset)
1379  {
1380  $create_status = $this->attr('create_status');
1381  if ($create_status != 0) {
1382  if ($new_asset->status != $create_status) {
1383  $hh = $GLOBALS['SQ_SYSTEM']->getHipoHerder();
1384  $vars = Array('assetid' => $new_asset->id, 'new_status' => $create_status);
1385  $status_errors = $hh->freestyleHipo('hipo_job_edit_status', $vars);
1386 
1387  //make sure the HIPO error message is in right format for asset builder
1388  $message = Array();
1389  foreach ($status_errors as $error) {
1390  if(is_array($error) && array_key_exists('message',$error)) {
1391  $message []= $error['message'];
1392  }
1393  else {
1394  $message = $error;
1395  }
1396  }
1397 
1398  $this->_errors = array_merge($this->_errors, $message);
1399  return empty($this->_errors);
1400  }
1401  }
1402  return TRUE;
1403 
1404  }//end _setCreateStatus()
1405 
1406 
1414  {
1415  $this->_replacements['created_assetid'] = $this->getKeywordReplacement('created_assetid');
1416  $this->_replacements['created_asset_name'] = $this->getKeywordReplacement('created_asset_name');
1417  $this->_replacements['created_asset_short_name'] = $this->getKeywordReplacement('created_asset_short_name');
1418  $this->_replacements['created_asset_url'] = $this->getKeywordReplacement('created_asset_url');
1419  $this->_replacements['created_asset_edit'] = $this->getKeywordReplacement('created_asset_edit');
1420  $this->_replacements['created_asset_backend'] = $this->getKeywordReplacement('created_asset_backend');
1421 
1422  }//end _loadAssetReplacements()
1423 
1424 
1432  {
1433 
1435  // CREATE CAPTCHA KEYWORD //
1437 
1438  // Moved to Page_Asset_Builder::_printContents() as per Bug #5518: CAPTCHA settings conflict.
1439 
1441  // CREATE MOLLOM SPAM KEYWORD //
1443  $regen_link_text = $this->attr('mollom_captcha_regen_link_text');
1444  if (empty($regen_link_text)) {
1445  $regen_link_text = translate('cms_asset_builder_mollom_regen_link_text');
1446  }
1447  $this->_replacements['asset_builder_mollom_captcha'] = Mollom::getMollomCaptchaKeywordReplacement($this->id);
1448  $this->_replacements['asset_builder_mollom_captcha_image'] = Mollom::getMollomCaptchaImageKeywordReplacement($this->id);
1449  $this->_replacements['asset_builder_mollom_captcha_audio'] = Mollom::getMollomCaptchaAudioKeywordReplacement($this->id);
1450  $this->_replacements['asset_builder_mollom_captcha_field'] = Mollom::getMollomCaptchaFieldKeywordReplacement($this->id);
1451  $this->_replacements['asset_builder_mollom_captcha_regen_link'] = Mollom::getMollomCaptchaRegenLinkKeywordReplacement($this->id, $regen_link_text);
1452 
1453 
1455  // CREATE INVITE KEYWORD //
1457  $this->_replacements['create_invite'] = $this->getKeywordReplacement('create_invite');
1458 
1460  // CREATE FORM KEYWORD //
1462  $this->_replacements['create_form'] = $this->getKeywordReplacement('create_form');
1463 
1465  // SELECTABLE CREATE LOCATIONS KEYWORDS //
1467  foreach ($this->attr('create_location_optional') as $name => $data) {
1468  $code_name = $this->_sanitiseLocationSetName($name);
1469 
1470  // the following line will remove any assets that no longer exist
1471  $options = $GLOBALS['SQ_SYSTEM']->am->getAssetInfo(array_keys($data['locations']), Array(), TRUE, 'name');
1472 
1473  if (!$this->attr('allow_public_user')) {
1474  $remaining_options = Array();
1475  $user_groups = $GLOBALS['SQ_SYSTEM']->user->getUserGroups();
1476  $user_groups[] = $GLOBALS['SQ_SYSTEM']->user->id;
1477  $user_groups[] = $GLOBALS['SQ_SYSTEM']->am->getSystemAssetid('public_user');
1478  foreach ($options as $key => $value) {
1479  $allowed_user_groups = $GLOBALS['SQ_SYSTEM']->am->getPermission($key,SQ_PERMISSION_WRITE,TRUE);
1480  // getPermission does not return root or sysadmin users so we will have to add the options ourselves
1481  // NOTE: root and sysadmin users are allowed to do anything unless _checkPermissionAccess is overridden
1482  if (array_intersect($user_groups,$allowed_user_groups)) {
1483  $remaining_options[$key] = $value;
1484  } else if (($GLOBALS['SQ_SYSTEM']->userRoot() || $GLOBALS['SQ_SYSTEM']->userSystemAdmin())) {
1485  $remaining_options[$key] = $value;
1486  }
1487  }
1488  $options = $remaining_options;
1489  }
1490  ob_start();
1491  switch ($data['input_style']) {
1492  case 'dropdown':
1493  if ($data['allow_empty'] && !$data['allow_multiple']) {
1494  $options = Array(''=>'') + $options;
1495  }
1496  $default = $data['allow_empty'] ? Array() : key($options);
1497  $height = $data['allow_multiple'] ? 4 : 1;
1498  combo_box($code_name, $options, $data['allow_multiple'], $default, $height);
1499  break;
1500  case 'radio':
1501  if ($data['allow_multiple']) {
1502  // print checkboxes
1503  $checked = !$data['allow_empty'];
1504  $i = 0;
1505  foreach ($data['locations'] as $id => $name) {
1506  check_box($code_name."[$i]", $id, $checked);
1507  label(str_replace(' ', '&nbsp;',$options[$id]), $code_name."[$i]");
1508  echo "<br />";
1509  $checked = FALSE;
1510  $i++;
1511  }
1512  } else {
1513  $checked = !$data['allow_empty'];
1514 
1515  foreach ($data['locations'] as $id => $name) {
1516  radio_button($code_name, $id, $checked);
1517  label(str_replace(' ', '&nbsp;',$options[$id]), $code_name.'_'.$id);
1518  echo "<br />";
1519  $checked = FALSE;
1520  }
1521  }
1522  break;
1523 
1524  default:
1525  echo '('.translate('cms_asset_builder_undefined_input_style', $data['input_style']).')';
1526  break;
1527  }//end switch
1528  $this->_replacements[$code_name.'_field'] = ob_get_contents();
1529  ob_end_clean();
1530  }//end foreach selectable create location
1531 
1532  foreach ($this->attr('create_location_dynamic') as $name => $data) {
1533  $code_name = $this->_sanitiseLocationSetName($name);
1534 
1535  // get the selected asset types and inherited types if necessary
1536  $types = Array();
1537  if (is_array($new_types = $data['types'])) {
1538  if (isset($new_types['type_code']) && isset($new_types['inherit'])) {
1539  if (count($new_types['type_code']) == count($new_types['inherit'])) {
1540  $new_types_keys = array_keys($new_types['type_code']);
1541 
1542  for ($ii = reset($new_types_keys); $ii < count($new_types_keys); $ii++) {
1543  if (empty($new_types['type_code'][$ii])) continue;
1544  if ($new_types['inherit'][$ii] == '1') {
1545  // get all descendants, add them to the types array
1546  $descendant_types = $GLOBALS['SQ_SYSTEM']->am->getTypeDescendants($new_types['type_code'][$ii], TRUE);
1547  foreach ($descendant_types as $type_code) {
1548  if (!isset($types[$type_code])) {
1549  $types[$type_code] = '';
1550  }
1551  }
1552  } else {
1553  $types[$new_types['type_code'][$ii]] = '';
1554 
1555  }
1556  }
1557  }
1558  }
1559  }
1560  $types = array_keys($types);
1561  ob_start();
1562  structured_drop_down($code_name, $data['root'], $types, Array(), 0, $data['allow_multiple'] ? 5 : 1, $data['depth'], $data['allow_multiple'], '-', FALSE, '', $data['input_style'] == 'radio', Array(), $data['display_structured'], array_keys($data['filter_link_type']), $data['allow_empty'], $this->attr('allow_public_user') ? NULL : SQ_PERMISSION_WRITE);
1563  $this->_replacements[$code_name.'_field'] = ob_get_contents();
1564  ob_end_clean();
1565  }//end foreach
1566 
1567  // Replace all available keywords in create_form keyword replacement, not leaving it to mysource.inc to pick it up
1568  replace_keywords($this->_replacements['create_form'], $this->_replacements);
1569 
1570  }//end _loadCreateReplacements()
1571 
1572 
1579  function _printContents()
1580  {
1581  // get the bodycopy attached to us
1582  $bodycopy_data = $GLOBALS['SQ_SYSTEM']->am->getLink($this->id, SQ_LINK_TYPE_2, 'bodycopy', TRUE, $this->_current_state, 'major', '1');
1583  if (empty($bodycopy_data)) return;
1584  $bodycopy = $GLOBALS['SQ_SYSTEM']->am->getAsset($bodycopy_data['minorid'], $bodycopy_data['minor_type_code']);
1585  if (is_null($bodycopy)) return;
1586 
1587  $keywords = $bodycopy->getKeywords();
1588  foreach($keywords as $word) {
1589 
1590  // Bug #5518: CAPTCHA settings conflict. Only replace if keyword exists in the content.
1591  if ($word == 'create_form' && isset($this->_replacements['create_form'])){
1592  $create_form_keywords = extract_keywords($this->_replacements['create_form']);
1593  $captcha_keywords = Array('form_captcha', 'form_captcha_image', 'form_captcha_field', 'form_captcha_link');
1594  $captcha_replacements = Array();
1595  foreach ($captcha_keywords as $captcha_word){
1596  if (in_array($captcha_word, $create_form_keywords)){
1597  $captcha_replacements[$captcha_word] = $this->getKeywordReplacement($captcha_word);
1598  }
1599  }
1600  replace_keywords($this->_replacements['create_form'], $captcha_replacements);
1601  }
1602 
1603  if ((strpos($word, 'form_captcha') === 0)){
1604  $this->_replacements[$word] = $this->getKeywordReplacement($word);
1605  }
1606 
1607  //pick up any global keywords and replace them
1608  if(!isset($this->_replacements[$word]) && (strpos($word, 'globals_') === 0 )){
1609  $this->_replacements[$word] = $this->getKeywordReplacement($word);
1610  // replace them here, it's not good enough to leave it to mysource.inc for replacement
1611  // mysource.inc will only do replacement in frontend, account manager will be used in simple edit mode,
1612  // so for global keywords in account manager we have to replace it here
1613  replace_global_keywords($this->_replacements[$word]);
1614  }
1615  }
1616 
1617 
1618  // Apply keyword modifiers to the keyword replacements
1619  foreach($keywords as $full_keyword) {
1620  $keyword = parse_keyword($full_keyword, $modifiers);
1621  if (!empty($modifiers) && isset($this->_replacements[$keyword])) {
1622  $this->_replacements[$full_keyword] = $this->_replacements[$keyword];
1623  apply_keyword_modifiers($this->_replacements[$full_keyword], $modifiers);
1624  }//end if
1625  }//end foreach
1626 
1627  $bodycopy->setKeywordReplacements($this->_replacements);
1628 
1629  $bodycopy->printBody();
1630 
1631  }//end _printContents()
1632 
1633 
1646  function _errorHandler($err_no, $err_msg, $err_file, $err_line)
1647  {
1648  $terminate = ((E_USER_ERROR | E_ERROR) & $err_no);
1649 
1650  // Treat PHP 5.2 catchable fatals as PHP 5.1 fatals
1651  if (defined('E_RECOVERABLE_ERROR') && ($err_no == E_RECOVERABLE_ERROR)) {
1652  $terminate = TRUE;
1653  }
1654 
1655  // if the function didn't have an '@' prepended OR if we are about to terminate
1656  // catch the error
1657  if ((error_reporting() & $err_no) || $terminate) {
1658 
1659  $bt = debug_backtrace();
1660  if (count($bt) > 1) {
1661  $real_bt_index = 0;
1662  while (($real_bt_index < count($bt)-1) && ((FALSE !== strpos(strtolower(array_get_index($bt[$real_bt_index], 'class')), 'locale_manager')) || (FALSE !== strpos(strtolower(array_get_index($bt[$real_bt_index], 'file')), 'locale_manager')) || (strtolower($bt[$real_bt_index]['function']) == '_errorhandler'))) {
1663  $real_bt_index++;
1664  }
1665  $err_file = hide_system_root($bt[$real_bt_index]['file']);
1666  $err_line = $bt[$real_bt_index]['line'];
1667  $err_msg = hide_system_root($err_msg);
1668  }
1669 
1670  $text_msg = strip_tags(preg_replace(Array('/<br\\/?>/i', '/<p[^>]*>/i'), Array("\n", "\n\n"), $err_msg));
1671 
1672  // send a report to the system error log
1673  if (ini_get('log_errors')) {
1674  log_error($text_msg, $err_no, $err_file, $err_line);
1675  }
1676 
1677  $this->_errors[] = $text_msg;
1678 
1679  }//end error_reporting
1680 
1681  if ($terminate) exit(1);
1682 
1683  }//end _errorHandler()
1684 
1685 
1692  function _getBodycopies()
1693  {
1694  $res = Array();
1695  $res['not_logged_in']= Array(
1696  'name' => translate('not_logged_in'),
1697  'content' => '%login_error%
1698  %login_invite%
1699  %login_form%',
1700  );
1701  $res['logged_in']= Array(
1702  'name' => translate('logged_in'),
1703  'content' => '%create_error%
1704  %create_invite%
1705  %create_form%',
1706  );
1707  $res['created']= Array(
1708  'name' => translate('created'),
1709  'content' => translate('cms_asset_builder_default_created_message'),
1710  );
1711  return $res;
1712 
1713  }//end _getBodycopies()
1714 
1715 
1716 //-- KEYWORD DESCRIPTION --//
1717 
1718 
1729  function onRequestKeywords(&$broadcaster, $vars=Array())
1730  {
1731  if (!isset($vars['keywords'])) return;
1732 
1733  // which type-code?
1734  $parents = $GLOBALS['SQ_SYSTEM']->am->getParents($broadcaster->id, 'bodycopy', TRUE);
1735  $type_links = $GLOBALS['SQ_SYSTEM']->am->getLinks($this->id, SQ_LINK_TYPE_2, 'bodycopy');
1736  $bodycopy_type = '';
1737  foreach ($type_links as $link_info) {
1738  if (isset($parents[$link_info['minorid']])) {
1739  $bodycopy_type = $link_info['value'];
1740  }
1741  }
1742 
1743  switch ($bodycopy_type) {
1744  case 'not_logged_in' :
1745  $vars['keywords'] = array_merge($vars['keywords'], $this->_getNotLoggedInKeywords());
1746  break;
1747  case 'logged_in' :
1748  $vars['keywords'] = array_merge($vars['keywords'], $this->_getLoggedInKeywords());
1749  break;
1750  case 'created' :
1751  $vars['keywords'] = array_merge($vars['keywords'], $this->_getCreatedKeywords());
1752  break;
1753  }
1754 
1755  $vars['keywords'] = array_merge($vars['keywords'], $this->_getSelectableLocationKeywords());
1756  $vars['keywords'] = array_merge($vars['keywords'], $this->_getDynamicLocationKeywords());
1757 
1758  }//end onRequestKeywords()
1759 
1760 
1768  {
1769  $keywords = Array();
1770 
1771  $keywords['login_invite'] = translate('cms_asset_builder_keyword_login_invite');
1772  $keywords['login_form'] = translate('cms_asset_builder_keyword_login_form');
1773  $keywords['login_error'] = translate('cms_asset_builder_keyword_login_error');
1774  $keywords['create_invite'] = translate('cms_asset_builder_keyword_create_invite');
1775  $keywords['create_form'] = translate('cms_asset_builder_keyword_create_form');
1776  $keywords['create_error'] = translate('cms_asset_builder_keyword_create_error');
1777 
1778  if ($this->attr('require_captcha')) {
1779  $keywords['form_captcha'] = translate('cms_asset_builder_keyword_form_captcha');
1780  $keywords['form_captcha_image'] = translate('cms_asset_builder_keyword_form_captcha_image');
1781  $keywords['form_captcha_field'] = translate('cms_asset_builder_keyword_form_captcha_field');
1782  $keywords['form_captcha_link'] = translate('cms_asset_builder_keyword_form_captcha_link');
1783  }
1784 
1785  if ($this->attr('use_mollom')) {
1786  $keywords['asset_builder_mollom_captcha'] = translate('cms_asset_builder_mollom_captcha');
1787  $keywords['asset_builder_mollom_captcha_image'] = translate('cms_asset_builder_mollom_captcha_image');
1788  $keywords['asset_builder_mollom_captcha_audio'] = translate('cms_asset_builder_mollom_captcha_audio');
1789  $keywords['asset_builder_mollom_captcha_field'] = translate('cms_asset_builder_mollom_captcha_field');
1790  $keywords['asset_builder_mollom_captcha_regen_link'] = translate('cms_asset_builder_mollom_captcha_link');
1791  }
1792 
1793  return $keywords;
1794 
1795  }//end _getNotLoggedInKeywords()
1796 
1797 
1805  {
1806  $keywords = Array();
1807  $keywords['create_invite'] = translate('cms_asset_builder_keyword_create_invite');
1808  $keywords['create_form'] = translate('cms_asset_builder_keyword_create_form');
1809  $keywords['create_error'] = translate('cms_asset_builder_keyword_create_error');
1810 
1811  if ($this->attr('require_captcha')) {
1812  $keywords['form_captcha'] = translate('cms_asset_builder_keyword_form_captcha');
1813  $keywords['form_captcha_image'] = translate('cms_asset_builder_keyword_form_captcha_image');
1814  $keywords['form_captcha_field'] = translate('cms_asset_builder_keyword_form_captcha_field');
1815  $keywords['form_captcha_link'] = translate('cms_asset_builder_keyword_form_captcha_link');
1816  }
1817 
1818  if ($this->attr('use_mollom')) {
1819  $keywords['asset_builder_mollom_captcha'] = translate('cms_asset_builder_mollom_captcha');
1820  $keywords['asset_builder_mollom_captcha_image'] = translate('cms_asset_builder_mollom_captcha_image');
1821  $keywords['asset_builder_mollom_captcha_audio'] = translate('cms_asset_builder_mollom_captcha_audio');
1822  $keywords['asset_builder_mollom_captcha_field'] = translate('cms_asset_builder_mollom_captcha_field');
1823  $keywords['asset_builder_mollom_captcha_regen_link'] = translate('cms_asset_builder_mollom_captcha_link');
1824  }
1825 
1826  return $keywords;
1827 
1828  }//end _getLoggedInKeywords()
1829 
1830 
1838  {
1839  $keywords = Array();
1840 
1841  $keywords['created_assetid'] = translate('cms_asset_builder_created_assetid');
1842  $keywords['created_asset_name'] = translate('cms_asset_builder_created_asset_name');
1843  $keywords['created_asset_short_name'] = translate('cms_asset_builder_created_asset_short_name');
1844  $keywords['created_asset_url'] = translate('cms_asset_builder_created_asset_url');
1845  $keywords['created_asset_edit'] = translate('cms_asset_builder_created_asset_edit');
1846  $keywords['created_asset_backend'] = translate('cms_asset_builder_created_asset_backend');
1847 
1848  return $keywords;
1849 
1850  }//end _getCreatedKeywords()
1851 
1852 
1860  {
1861  $keywords = Array();
1862  foreach ($this->attr('create_location_optional') as $name => $data) {
1863  $keyword_name = $this->_sanitiseLocationSetName($name).'_field';
1864  $keywords[$keyword_name] = translate('cms_asset_builder_field_keyword', $name);
1865  }
1866  return $keywords;
1867 
1868  }//end _getSelectableLocationKeywords()
1869 
1870 
1878  {
1879  $keywords = Array();
1880  foreach ($this->attr('create_location_dynamic') as $name => $data) {
1881  $keyword_name = $this->_sanitiseLocationSetName($name).'_field';
1882  $keywords[$keyword_name] = translate('cms_asset_builder_field_keyword', $name);
1883  }
1884  return $keywords;
1885 
1886  }//end _getDynamicLocationKeywords()
1887 
1888 
1889 //-- KEYWORD REPLACEMENT --//
1890 
1891 
1899  {
1900  return $this->attr('login_invite');
1901 
1902  }//end getLoginInviteKeywordReplacement()
1903 
1904 
1912  {
1913  return $this->attr('login_error');
1914 
1915  }//end getLoginErrorKeywordReplacement()
1916 
1917 
1925  {
1926  ob_start();
1927  ?>
1928  <input type="hidden" name="SQ_LOGIN_KEY" value="<?php echo $GLOBALS['SQ_SYSTEM']->generateLoginKey(); ?>" />
1929  <input type="hidden" name="SQ_LOGIN_REFERER" value="" />
1930 
1931  <table border="0">
1932  <tr>
1933  <td valign="top"><?php echo translate('username'); ?></td>
1934  <td valign="top"><?php echo text_box('SQ_LOGIN_USERNAME', (isset($_POST['SQ_LOGIN_USERNAME'])) ? $_POST['SQ_LOGIN_USERNAME'] : 'Enter your username here', 25, 0, (isset($_POST['SQ_LOGIN_USERNAME'])) ? FALSE : TRUE, 'title="Username"'); ?></td>
1935  </tr>
1936  <tr>
1937  <td valign="top"><?php echo translate('password'); ?></td>
1938  <td valign="top"><?php echo password_box('SQ_LOGIN_PASSWORD', '', 25, 0, 'title="Password"'); ?></td>
1939  </tr>
1940  <tr>
1941  <td valign="top">&nbsp;</td>
1942  <td valign="top">
1943  <input type="hidden" name="SQ_ACTION" value="" id="SQ_ACTION" />
1944  <?php echo submit_button('SQ_LOGIN_SUBMIT', 'Login', 'document.getElementById(\'SQ_ACTION\').value = \'login\'; document.getElementById(\'AB_'.$this->id.'_ASSET_BUILDER_ACTION\').value = \'login\';'); ?>
1945  </td>
1946  </tr>
1947  </table>
1948 
1949  <?php
1950  $login_form = ob_get_contents();
1951  ob_end_clean();
1952  return $login_form;
1953 
1954  }//end getLoginFormKeywordReplacement()
1955 
1956 
1964  {
1965  if(isset($this->_replacements['created_assetid'] )) {
1966  return $this->_replacements['created_assetid'];
1967  }
1968  else if (isset($this->_tmp['created_asset'])) {
1969  return $this->_tmp['created_asset']->id;
1970  }
1971  return '';
1972  }//end getCreatedAssetidKeywordReplacement()
1973 
1974 
1982  {
1983  if(isset($this->_replacements['created_asset_name'] )) {
1984  return $this->_replacements['created_asset_name'];
1985  }
1986  else if (isset($this->_tmp['created_asset'])) {
1987  return $this->_tmp['created_asset']->name;
1988  }
1989  return '';
1990 
1991  }//end getCreatedAssetNameKeywordReplacement()
1992 
1993 
2001  {
2002  if(isset($this->_replacements['created_asset_short_name'] )) {
2003  return $this->_replacements['created_asset_short_name'];
2004  }
2005  else if (isset($this->_tmp['created_asset'])) {
2006  return $this->_tmp['created_asset']->short_name;
2007  }
2008  return '';
2009  }//end getCreatedAssetShortNameKeywordReplacement()
2010 
2011 
2019  {
2020  if(isset($this->_replacements['created_asset_url'] )) {
2021  return $this->_replacements['created_asset_url'];
2022  }
2023  else if (isset($this->_tmp['created_asset'])) {
2024  return $this->_tmp['created_asset']->getURL();
2025  }
2026  return '';
2027  }//end getCreatedAssetUrlKeywordReplacement()
2028 
2029 
2037  {
2038  if(isset($this->_replacements['created_asset_edit'] )) {
2039  return $this->_replacements['created_asset_edit'];
2040  }
2041  else if (isset($this->_tmp['created_asset'])) {
2042  return $this->_tmp['created_asset']->getURL().'/'.SQ_CONF_LIMBO_SUFFIX;
2043  }
2044  return '';
2045  }//end getCreatedAssetEditKeywordReplacement()
2046 
2047 
2055  {
2056  if(isset($this->_replacements['created_asset_backend'] )) {
2057  return $this->_replacements['created_asset_backend'];
2058  }
2059  else if (isset($this->_tmp['created_asset'])) {
2060  return sq_web_path('root_url').'/'.$this->_tmp['created_asset']->getBackendHref('contents');
2061  }
2062  return '';
2063  }//end getCreatedAssetBackendKeywordReplacement()
2064 
2065 
2073  {
2074  return $this->attr('create_error');
2075 
2076  }//end getCreateErrorKeywordReplacement()
2077 
2078 
2086  {
2087  return $this->attr('create_invite');
2088 
2089  }//end getCreateInviteKeywordReplacement()
2090 
2091 
2099  {
2100  $create_form = '';
2101  $create_types = $this->attr('create_type');
2102  if (!is_array($create_types)) {
2103  $create_types = Array($create_types => '');
2104  }
2105 
2106  require_once SQ_INCLUDE_PATH.'/limbo_outputter.inc';
2107  $o = new Limbo_Outputter();
2108  $o->addHiddenField('AB_'.$this->id.'_ASSET_BUILDER_CREATE_TYPE', key($create_types)); // first asset type is selected initially
2109  if (count($create_types) > 1) $o->addOnSubmit('disableHiddenInputs();');
2110 
2111  // Get the Metadata schemas ready
2112  $metadata_schemas = $this->_getMetadataSchemasToApply();
2113  $metadata_edit_fns = NULL;
2114 
2115  // get each asset type's form fields for the create form
2116  ob_start();
2117  $display = 'block'; // first create type is shown initially
2118  foreach ($create_types as $create_type => $value) {
2119  $prefix = $this->type().'_'.$this->id.'_type_'.$create_type;
2120  echo '<div class="sq-asset-builder-tab-content" id="'.$prefix.'" style="display: '.$display.'">';
2121  $GLOBALS['SQ_SYSTEM']->am->includeAsset($create_type);
2122  $asset = NULL;
2123  if (isset($this->_tmp['new_asset_created_'.$create_type])) {
2124  $asset =& $this->_tmp['new_asset_created_'.$create_type];
2125  } else {
2126  $asset = new $create_type();
2127  }
2128 
2129  if ($layout = $this->_getCreateFormLayout($create_type)) {
2130  $ei = $asset->getEI();
2131  $ei->paintLayout($asset, $o, $layout);
2132  $o->addHiddenField('asset_action', 'create_custom');
2133  } else {
2134  unset($GLOBALS['painted_inline_value_interface']);
2135  foreach ($metadata_schemas as $schemaid) {
2136  $schema = $GLOBALS['SQ_SYSTEM']->am->getAsset($schemaid);
2137  if (is_null($metadata_edit_fns)) {
2138  $metadata_edit_fns = $schema->getEditFns();
2139  }
2140  $metadata_edit_fns->paintInlineValueInterface($schema, $o, Array(), TRUE, FALSE, $create_type);
2141  }
2142  $asset->paintBackend($o);
2143  $o->addHiddenField('asset_action', 'create');
2144  }
2145  $o->paintSections();
2146  $o->_contents = Array();
2147 
2148  echo '</div>';
2149 
2150  // If this form was commited before but AB failed to create the asset due to errors
2151  // then we will insert the previously entered field values to the asset's attribute values
2152  ?>
2153  <script type="text/javascript">
2154  <?php
2155  foreach ($asset->vars as $attr_name => $attr_details) {
2156  foreach ($_POST as $post_var => $post_var_value) {
2157  $pos = strpos($post_var, $create_type);
2158  if (($pos !== FALSE) && ($pos == 0)) {
2159  // does this var ends with the current attrid?
2160  $idlength = strlen($attr_details['attrid']);
2161  if (substr($post_var, -$idlength) == $attr_details['attrid']) {
2162  // we got the attribute value in post change the attr val
2163  ?>
2164  document.getElementById('<?php echo htmlspecialchars($post_var, ENT_QUOTES); ?>').value = '<?php echo htmlspecialchars($post_var_value, ENT_QUOTES); ?>';
2165  <?php
2166  }
2167  }
2168  }
2169  }
2170  ?>
2171  </script>
2172  <?php
2173 
2174  $display = 'none'; // all subsequent create types hidden initially
2175  }//end foreach
2176  $create_form = ob_get_contents();
2177  ob_end_clean();
2178 
2179  // get the header for the create form
2180  ob_start();
2181  // Header material from the limbo outputter
2182  $o->_paintInlineHeader();
2183 
2184  // Tabs if necessary
2185  if (count($create_types) > 1) {
2186  reset($create_types);
2187  ?>
2188  <script type="text/javascript"><!--
2189  //<![CDATA[
2190  var current_option = '<?php echo $this->type().'_'.$this->id.'_type_'.key($create_types) ?>';
2191 
2192  function showAssetBuilderTab(type_code)
2193  {
2194  document.getElementById(current_option).style.display = 'none';
2195  document.getElementById(current_option+"_tab").className = 'sq-asset-builder-tab';
2196  current_option = '<?php echo $this->type().'_'.$this->id.'_type_' ?>' + type_code;
2197  document.getElementById(current_option).style.display = 'block';
2198  document.getElementById(current_option+"_tab").className = 'sq-asset-builder-tab-active';
2199  document.getElementById('AB_<?php echo $this->id ?>_ASSET_BUILDER_CREATE_TYPE').value = type_code;
2200 
2201  }//end showAssetBuilderTab()
2202 
2203  function disableHiddenInputs()
2204  {
2205  var divs = document.getElementsByTagName('DIV');
2206  for (var i=0; i < divs.length; i++) {
2207  if (divs[i].className == 'sq-asset-builder-tab-content') {
2208  if (divs[i].style.display == 'none') {
2209  var inputs = divs[i].getElementsByTagName('INPUT');
2210  for (var j=0; j < inputs.length; j++) {
2211  inputs[j].disabled = true;
2212  }
2213  inputs = divs[i].getElementsByTagName('TEXTAREA');
2214  for (var j=0; j < inputs.length; j++) {
2215  inputs[j].disabled = true;
2216  }
2217  inputs = divs[i].getElementsByTagName('SELECT');
2218  for (var j=0; j < inputs.length; j++) {
2219  inputs[j].disabled = true;
2220  }
2221  }
2222  }
2223  }
2224  return true;
2225  }
2226 
2227  //]]> -->
2228  </script>
2229 
2230  <div id="sq-asset-builder-header">
2231  <ul>
2232  <?php
2233  $active = '-active'; // first asset type is shown initially
2234  foreach ($create_types as $create_type => $value) {
2235  $prefix = $this->type().'_'.$this->id.'_type_'.$create_type;
2236  $type_name = $GLOBALS['SQ_SYSTEM']->am->getTypeInfo($create_type, 'name');
2237  ?>
2238  <li class="sq-asset-builder-tab<?php echo $active; ?>" id="<?php echo $prefix; ?>_tab">
2239  <a href="#" onclick="showAssetBuilderTab('<?php echo $create_type ?>'); return false;">
2240  <?php echo $type_name; ?>
2241  </a>
2242  </li>
2243  <?php
2244  $active = ''; // subsequent asset types are hidden initially
2245  }
2246  ?>
2247  </ul>
2248  </div>
2249  <?php
2250  }//end if
2251  $create_form = ob_get_contents().$create_form;
2252  ob_end_clean();
2253 
2254  return $create_form;
2255 
2256  }//end getCreateFormKeywordReplacement()
2257 
2258 
2267  function &_getCreateFormLayout($type_code)
2268  {
2269  $res = NULL;
2270  $link = $GLOBALS['SQ_SYSTEM']->am->getLink($this->id, SQ_LINK_TYPE_2, 'layout', TRUE, $type_code);
2271  if (!empty($link)) {
2272  $res = $GLOBALS['SQ_SYSTEM']->am->getAsset($link['minorid'], 'layout');
2273  }
2274 
2275  return $res;
2276 
2277  }//end _getCreateFormLayout()
2278 
2279 
2280 }//end class
2281 
2282 ?>