18 require_once dirname(__FILE__).
'/../../metadata_field/metadata_field_edit_fns.inc';
41 parent::__construct();
68 if (is_null($value_str)) {
75 $value_components = $asset->
attr(
'value_components');
79 $extras = ($is_default && $enable_default) ?
'disabled="disabled"' :
'';
80 if ($asset->
attr(
'multi_line')) {
82 if (!$asset->
attr(
'char_limit')) {
83 text_area($prefix.
'_value', $value, $asset->
attr(
'box_width'), $asset->
attr(
'box_height'), 0, $extras);
85 text_area($prefix.
'_value', $value, $asset->
attr(
'box_width'), $asset->
attr(
'box_height'), 0,
'id="'.htmlspecialchars($prefix.
'_value').
'" onchange="var note=document.getElementById(\''.$prefix.
'_value_note\'); note.innerHTML = \'\'; var tmp = document.getElementById(\''.htmlspecialchars($prefix.
'_value').
'\'); tmp.value = tmp.value.substr(0,
'.$asset->attr('char_limit
').');
" onkeydown="setTimeout(
function() { var note=document.getElementById(\
''.$prefix.
'_value_note\'); var tmp = document.getElementById(\''.htmlspecialchars($prefix.
'_value').
'\');
if (tmp.value.length >
'.$asset->attr('char_limit
').') {note.innerHTML = \
' \'+js_translate(\'max_characters_exceeded_by\', (tmp.value.length-'.$asset->attr(
'char_limit').
'));} else {note.innerHTML = \'\'} }, 50);" '.$extras);
88 text_box($prefix.
'_value', $value, $asset->
attr(
'box_width'), $asset->
attr(
'char_limit'), FALSE, $extras);
90 if ($enable_default) {
91 echo
' ';
92 $default_string = str_replace(
"'",
"\'", $asset->
attr(
'default'));
94 $default_string = str_replace(Array(
"\r\n",
"\r",
"\n"),
'\n', $default_string);
96 $checkbox_extra =
'with(this.form.elements[\''.$prefix.
'_value\']) { disabled = this.checked; if (this.checked) { value = \''.$default_string.
'\'; }
else {
if(value==\
'\') {value=\
' \'; value = \'\';}}};';
98 if (!empty($value_components)) {
99 foreach ($value_components as $vc_name => $vc_value) {
100 $default_value_comp = $asset->
attr(
'value_components');
101 $default_vc_value = $default_value_comp[$vc_name];
102 $checkbox_extra .=
'with(this.form.elements[\''.$prefix.
'_vc_value['.$vc_name.
']\']) { disabled = this.checked; if (this.checked) { value = \''.$default_vc_value.
'\'; }
else {
if(value==\
'\') {value=\
' \'; value = \'\';}}};';
106 check_box($prefix.
'_default',
'1', $is_default, $checkbox_extra);
107 label(translate(
'use_default'), $prefix.
'_default');
110 if ($print_cascade_values_option) {
111 echo
' ';
112 check_box($prefix.
'_cascade_value',
'1', FALSE);
113 label(translate(
'cascade_value'), $prefix.
'_cascade_value');
118 if ($asset->
attr(
'char_limit')) {
119 ?> <br/>Character Limit: <?php echo $asset->
attr(
'char_limit'); ?> <span style=
"color:red" id=
"<?php echo $prefix.'_value'; ?>_note"></span> <?php
123 echo htmlspecialchars($value);
125 echo
' <em style="color: #666">('.strtolower(translate(
'default')).
')</em>';
130 if (!empty($value_components)) {
135 <table
class=
"sq-backend-table">
138 foreach ($value_components as $vc_name => $vc_value) {
140 if ($num_done >= $num_per_row) {
145 echo
'<td width="150" valign="top" class="sq-backend-table-cell">';
146 echo
'<b>'.$vc_name.
'</b>';
149 $extras = ($is_default && $enable_default) ?
'disabled="disabled"' :
'';
150 text_area($prefix.
'_vc_value['.$vc_name.
']', $vc_value, 30, 4, 0, $extras);
158 if ($num_done && $num_done != $num_per_row) {
159 for ($i = ($num_per_row - $num_done); $i > 0; $i--) {
160 echo
'<td width="150" class="sq-backend-table-cell"> </td>';
169 return $write_access;
187 if (!$asset->
attr(
'editable'))
return FALSE;
192 if (!empty($_POST[$prefix.
'_default'])) {
194 $new_value_str = NULL;
197 if (isset($_POST[$prefix.
'_value'])) {
198 $value = $_POST[$prefix.
'_value'];
199 $keyword =
'%asset_metadata_'.$asset->name.
'%';
200 $value = trim(str_replace($keyword,
'', $value));
201 $value_components = $asset->
attr(
'value_components');
202 for (reset($value_components); NULL !== ($vc_name = key($value_components)); next($value_components)) {
203 if (isset($_POST[$prefix.
'_vc_value'][$vc_name])) {
204 $clean_vc = trim(str_replace($keyword,
'', $_POST[$prefix.
'_vc_value'][$vc_name]));
205 $value_components[$vc_name] = str_replace(Array(
'\n',
'\r'), Array(
' ',
''), $clean_vc);
210 if(!SQ_IN_BACKEND && !SQ_IN_LIMBO && !SQ_IN_LOGIN && !SQ_IN_CRON && !SQ_PHP_CLI) {
211 $filter_enabled = $GLOBALS[
'SQ_SYSTEM']->getUserPrefs(
'user',
'SQ_USER_FILTER_FRONT_END_INPUT');
212 if(isset($GLOBALS[
'SQ_REVERT_TO_SYSTEM_VERSION'] ) && $GLOBALS[
'SQ_REVERT_TO_SYSTEM_VERSION']) {
213 $filter_enabled = FALSE;
214 }
else if (isset($GLOBALS[
'SQ_CLONE_COMPONENTS'] ) && $GLOBALS[
'SQ_CLONE_COMPONENTS']) {
215 $filter_enabled = FALSE;
218 if ($filter_enabled && !empty($new_value_str)) {
219 $new_value_str = filter_content($new_value_str);
220 if ($new_value_str === FALSE){
221 trigger_localised_error(
'SYS0347', E_USER_WARNING, $asset->name, $asset->
type());
230 if (isset($_POST[$prefix.
'_cascade_value'])) {
231 $field_cascade_value = TRUE;
259 if ((
boolean)$asset->
attr(
'is_contextable') === TRUE) {
260 $value_str = $asset->
attr(
'default');
262 $value_str = $GLOBALS[
'SQ_SYSTEM']->am->getAttributeValuesByName(
'default',
'metadata_field', Array($asset->id), 0);
263 $value_str = array_get_index($value_str, $asset->id,
'');
266 $value_components = Array();
268 if ($write_access === TRUE) {
269 text_area($prefix.
'_default', $value_str, 30, 5);
294 $is_contextable = (boolean)$asset->
attr(
'is_contextable');
295 $new_value = array_get_index($_POST, $prefix.
'_default',
'');
298 if ($is_contextable === TRUE) {
299 $value = $asset->
attr(
'default');
301 $value = $GLOBALS[
'SQ_SYSTEM']->am->getAttributeValuesByName(
'default',
'metadata_field', Array($asset->id), 0);
302 $value = array_get_index($value, $asset->id,
'');
305 if ($value !== $new_value) {
306 if ($is_contextable === TRUE) {
313 $GLOBALS[
'SQ_SYSTEM']->changeContext(0);
315 $default_asset = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($asset->id);
316 $default_asset->setAttrValue(
'default', $new_value);
317 $default_asset->saveAttributes();
318 $GLOBALS[
'SQ_SYSTEM']->am->forgetAsset($default_asset);
319 unset($default_asset);
321 $GLOBALS[
'SQ_SYSTEM']->restoreContext();