17 require_once dirname(__FILE__).
'/../../metadata_field/metadata_field_edit_fns.inc';
18 require_once SQ_LIB_PATH.
'/html_form/html_form.inc';
38 parent::__construct();
65 if (is_null($value_str)) {
67 $value_str = $default_value;
69 $value_str = trim($value_str);
72 $ra_styles = ($is_default && $enable_default) ?
'display:none' :
'display:block';
73 echo
'<div id="'.$prefix.
'_ra_container'.
'" style="float:left; '.$ra_styles.
'">';
74 asset_finder($prefix.
'_value', $value_str);
77 $default_ra_styles = !($is_default && $enable_default) ?
'display:none' :
'display:block';
78 echo
'<div id="'.$prefix.
'_default_ra_container'.
'" style="float:left; '.$default_ra_styles.
'">';
79 echo !$default_value ?
'No default asset!' : get_asset_tag_line($default_value);
82 if ($enable_default) {
83 echo
' ';
84 $default_string = str_replace(
"'",
"\'", $asset->
attr(
'default'));
86 $default_string = str_replace(Array(
"\r\n",
"\r",
"\n"),
'\n', $default_string);
88 $checkbox_extra =
'with(this.form.elements[\''.$prefix.
'_value\']) { disabled = this.checked; if (this.checked) { value = \''.$default_string.
'\'; }
else {
if(value==\
'\') {value=\
' \'; value = \'\';}}};';
90 check_box($prefix.
'_default',
'1', $is_default,
'handleMetadataRelatedAssetDefaultClickFor'.$prefix.
'()');
91 label(translate(
'use_default'), $prefix.
'_default');
94 if ($print_cascade_values_option) {
95 echo
' ';
96 check_box($prefix.
'_cascade_value',
'1', FALSE);
97 label(translate(
'cascade_value'), $prefix.
'_cascade_value');
101 <script type=
"text/javascript"><!--
103 function handleMetadataRelatedAssetDefaultClickFor<?php echo $prefix; ?>() {
104 var ra_div = document.getElementById(
'<?php echo $prefix.'_ra_container
'; ?>');
105 var default_ra_div = document.getElementById(
'<?php echo $prefix.'_default_ra_container
'; ?>');
107 if (ra_div.style.display ==
'block') {
108 ra_div.style.display =
'none';
109 default_ra_div.style.display =
'block';
111 ra_div.style.display =
'block';
112 default_ra_div.style.display =
'none';
120 echo !$value_str ? translate(
'no_asset_selected') : get_asset_tag_line($value_str);
122 echo
' <em style="color: #666">('.strtolower(translate(
'default')).
')</em>';
126 return $write_access;
143 if (!$asset->
attr(
'editable'))
return FALSE;
148 if (!empty($_POST[$prefix.
'_default'])) {
150 $new_value_str = NULL;
153 $value = trim(array_get_index($_POST,
'sq_asset_finder_'.$prefix.
'_value_assetid',
''));
154 if ($value && !$GLOBALS[
'SQ_SYSTEM']->am->getAssetInfo(Array($value))) {
155 trigger_localised_error(
'SYS0087', E_USER_WARNING, $value);
158 $new_value_str = $value;
162 if (isset($_POST[$prefix.
'_cascade_value'])) {
163 $field_cascade_value = TRUE;
187 if ((
boolean)$asset->
attr(
'is_contextable') === TRUE) {
188 $value = $asset->
attr(
'default');
190 $value = $GLOBALS[
'SQ_SYSTEM']->am->getAttributeValuesByName(
'default',
'metadata_field', Array($asset->id), 0);
191 $value = array_get_index($value, $asset->id,
'');
194 if (!$write_access) {
196 echo translate(
'no_asset_selected');
198 echo get_asset_tag_line($value);
201 asset_finder($prefix.
'_default', $value);
224 $new_value = trim(array_get_index($_POST,
'sq_asset_finder_'.$prefix.
'_default_assetid',
''));
226 $is_contextable = (boolean)$asset->
attr(
'is_contextable');
227 if ($is_contextable === TRUE) {
228 $value = $asset->
attr(
'default');
230 $value = $GLOBALS[
'SQ_SYSTEM']->am->getAttributeValuesByName(
'default',
'metadata_field', Array($asset->id), 0);
231 $value = array_get_index($value, $asset->id,
'');
235 if ($new_value != $value) {
236 if ($new_value && !$GLOBALS[
'SQ_SYSTEM']->am->getAssetInfo(Array($new_value))) {
237 trigger_localised_error(
'SYS0087', E_USER_WARNING, $new_value);
241 if ($is_contextable === TRUE) {
247 $GLOBALS[
'SQ_SYSTEM']->changeContext(0);
249 $default_asset = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($asset->id);
250 $default_asset->setAttrValue(
'default', $new_value);
251 $default_asset->saveAttributes();
252 $GLOBALS[
'SQ_SYSTEM']->am->forgetAsset($default_asset);
253 unset($default_asset);
255 $GLOBALS[
'SQ_SYSTEM']->restoreContext();