18 require_once dirname(__FILE__).
'/../../metadata_field/metadata_field_edit_fns.inc';
41 parent::__construct();
65 require_once SQ_LIB_PATH.
'/html_form/html_form.inc';
68 $value_components = $asset->
attr(
'value_components');
72 if (is_null($value_str)) {
79 if ($asset->
attr(
'multiple')) {
84 $value = explode(
'; ', $value);
90 $selection->value = $value;
91 if ($enable_default) {
92 $selection->_edit_params[
'extras'] =
'onclick="document.getElementById(\''.$prefix.
'_default\').checked = false;"';
94 $selection->_edit_params[
'extras'] .=
' disabled="disabled"';
96 echo
'<span id="'.$prefix.
'_field">';
98 $selection->paint($prefix, FALSE);
99 if ($enable_default) echo
'</span>';
101 if (!((is_array($value) && empty($value)) || (is_string($value) && $value ==
''))) {
102 if (!is_array($value)) $value = Array($value);
105 foreach ($value as $option) {
106 if (isset($select_options[$option])) {
107 $value_output .= $select_options[$option].
'; ';
110 echo trim($value_output,
'; ');
114 if ($enable_default) {
116 echo
' ';
120 $default_keys = explode(
'; ', $asset->
attr(
'default'));
121 $default_selected = Array();
123 $default_vals = Array();
124 $non_default_vals = Array();
125 foreach ($select_options as $key => $select_option) {
126 if (in_array($key, $default_keys)) {
127 $default_vals[] =
"'".addslashes(str_replace(
' ',
'_', $key)).
"'";
129 $non_default_vals[] =
"'".addslashes(str_replace(
' ',
'_', $key)).
"'";
132 $default_vals_expr =
'['.implode(
', ', $default_vals).
']';
133 $non_default_vals_expr =
'['.implode(
', ', $non_default_vals).
']';
134 check_box($prefix.
'_default',
'1', $is_default,
"handleDefaultClick(this, '$prefix', $default_vals_expr, $non_default_vals_expr); ");
135 label(translate(
'use_default'), $prefix.
'_default');
136 $o->
addJsInclude(sq_web_path(
'data').
'/asset_types/metadata_field_select/js/metadata_field_select.js');
139 echo
' <em style="color: #666">('.strtolower(translate(
'default')).
')</em>';
144 if ($write_access && $print_cascade_values_option) {
145 echo
' ';
146 check_box($prefix.
'_cascade_value',
'1', FALSE);
147 label(translate(
'cascade_value'), $prefix.
'_cascade_value');
150 return $write_access;
168 if (!$asset->
attr(
'editable'))
return FALSE;
173 if (!empty($_POST[$prefix.
'_default'])) {
175 $new_value_str = NULL;
180 $selection->process($prefix);
181 if ($selection->processed) {
183 $value = str_replace(
'|',
'; ', $selection->value);
189 if (isset($_POST[$prefix.
'_cascade_value'])) {
190 $field_cascade_value = TRUE;
212 $is_contextable = (boolean)$asset->
attr(
'is_contextable');
214 $contextid = $GLOBALS[
'SQ_SYSTEM']->getContextId();
215 $is_default_context = ($contextid === 0) ? TRUE : FALSE;
217 if ($is_contextable === TRUE) {
220 $select_options = $GLOBALS[
'SQ_SYSTEM']->am->getAttributeValuesByName(
'select_options',
'metadata_field_select', Array($asset->id), 0);
221 $select_options = unserialize($select_options[$asset->id]);
224 if (!empty($select_options)) {
226 <table
class=
"sq-backend-table">
228 <td
class=
"sq-backend-table-header"><?php echo translate(
'option_key'); ?></td>
229 <td
class=
"sq-backend-table-header"><?php echo translate(
'option_value'); ?></td>
231 if (($write_access === TRUE) && (($is_default_context === TRUE) || ($is_contextable === FALSE))) {
232 ?><td
class=
"sq-backend-table-header"><?php echo translate(
'delete_question'); ?></td><?php
242 foreach ($select_options as $option_key => $option_value) {
245 <td
class=
"sq-backend-table-cell">
247 if ($write_access === TRUE) {
248 if (($is_default_context === TRUE) || ($is_contextable === FALSE)) {
249 text_box($prefix.
'_options[key]['.$i.
']', $option_key, 20);
252 hidden_field($prefix.
'_options[key]['.$i.
']', $option_key);
259 <td
class=
"sq-backend-table-cell" align=
"left">
262 text_box($prefix.
'_options[val]['.$i.
']', $option_value, 20);
269 if (($write_access === TRUE) && (($is_default_context === TRUE) || ($is_contextable === FALSE))) {
271 <td
class=
"sq-backend-table-cell">
272 <?php check_box($prefix.
'_options[del]['.$i.
']', $option_key); ?>
286 echo translate(
'no_select_box_options');
290 if (($write_access === TRUE) && (($is_default_context === TRUE) || ($is_contextable === FALSE))) {
292 echo
'<b>'.translate(
'key').
'</b> ';
293 text_box($prefix.
'_new_key',
'');
294 echo
' <b>'.translate(
'value').
'</b> ';
295 text_box($prefix.
'_new_val',
'');
299 if (!empty($select_options)) {
301 $o->
openField(translate(
'default_value'));
303 $selection->paint($prefix.
'_default', !$write_access);
325 if (!$asset->
writeAccess(
'attributes'))
return FALSE;
326 $is_contextable = (boolean)$asset->
attr(
'is_contextable');
328 if ($is_contextable === FALSE) {
331 $GLOBALS[
'SQ_SYSTEM']->changeContext(0);
332 $asset = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($asset->id);
335 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'BEGIN');
337 $select_options = Array();
338 if (isset($_POST[$prefix.
'_options'])) {
339 $option_changes = $_POST[$prefix.
'_options'];
340 foreach ($option_changes[
'key'] as $i => $key) {
341 if (isset($option_changes[
'del'][$i]))
continue;
342 $select_options[trim($key)] = trim($option_changes[
'val'][$i]);
347 if (array_key_exists($prefix.
'_new_key', $_POST) === TRUE) {
348 if (strlen(trim($_POST[$prefix.
'_new_key']))>0 && strlen(trim($_POST[$prefix.
'_new_val']))>0) {
349 $new_select_key = trim($_POST[$prefix.
'_new_key']);
350 $new_select_val = trim($_POST[$prefix.
'_new_val']);
351 $select_options[$new_select_key] = $new_select_val;
356 $asset->
setAttrValue(
'select_options', $select_options);
360 if (!empty($select_options) && isset($_POST[$prefix.
'_default'])) {
361 $new_default = $_POST[$prefix.
'_default'];
362 if (is_array($new_default)) {
363 $new_default = implode(
'; ', $new_default);
366 if (!$asset->
attr(
'multiple')) {
367 if (!isset($select_options[$new_default])) {
373 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'COMMIT');
375 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'ROLLBACK');
378 if ($is_contextable === FALSE) {
381 $GLOBALS[
'SQ_SYSTEM']->restoreContext();
382 $asset = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($asset->id);
404 $selection->paintEditParams($prefix.
'_style', $asset->
writeAccess(
'attributes'));
421 if (!$asset->
writeAccess(
'attributes'))
return FALSE;
424 $edit_params = $selection->processEditParams($prefix.
'_style');
425 return $asset->
setAttrValue(
'edit_params', $edit_params);
444 if (is_null($value_str)) {
449 if ($asset->
attr(
'visible_part') ===
'value') {
453 return parent::generateMetadata($asset, $value_str, $tag_value, $keywords);
471 file_upload($prefix.
'_option_upload');
472 return $write_access;
490 check_box($prefix.
'_csv_header',
'1');
491 return $write_access;
508 if (isset($_FILES[$prefix.
'_option_upload'])) {
509 $file = $_FILES[$prefix.
'_option_upload'];
512 if (isset($_POST[$prefix.
'_csv_header'])) {
516 if ($file[
'error'] === UPLOAD_ERR_OK) {