17 require_once SQ_SYSTEM_ROOT.
'/core/assets/metadata/metadata_field/metadata_field_edit_fns.inc';
40 parent::__construct();
58 $root_links = $GLOBALS[
'SQ_SYSTEM']->am->getLinks($asset->id, SQ_LINK_NOTICE,
'', FALSE,
'major',
'root');
59 $root_asset_ids = Array();
60 foreach ($root_links as $root_link) {
61 $root_asset_ids[$root_link[
'minorid']] = $root_link[
'minor_type_code'];
65 multiple_asset_finder($prefix.
'_root_nodes', array_keys($root_asset_ids));
67 $infos = $GLOBALS[
'SQ_SYSTEM']->am->getAssetInfo(array_keys($root_asset_ids));
69 <table
class=
"sq-backend-table">
71 <td
class=
"sq-backend-table-header"><?php echo translate(
'id') ?></td>
72 <td
class=
"sq-backend-table-header"><?php echo translate(
'name') ?></td>
73 <td
class=
"sq-backend-table-header"><?php echo translate(
'type') ?></td>
76 foreach ($infos as $assetid => $info) {
80 <td
class=
"sq-backend-table-cell"><?php echo $assetid ?></td>
81 <td
class=
"sq-backend-table-cell"><?php echo $info[
'name'] ?></td>
82 <td
class=
"sq-backend-table-cell"><?php echo ucwords(str_replace(
'_',
' ', $info[
'type_code'])) ?></td>
115 if ($thesaurus == FALSE) {
116 echo translate(
'source_thesaurus_not_set');
121 require_once SQ_LIB_PATH.
'/html_form/html_form.inc';
124 $default = $asset->
attr(
'default');
125 if (is_null($value_str)) {
128 $value_components = $asset->
attr(
'value_components');
131 $value_components = $asset->
attr(
'value_components');
138 }
else if (!is_array($value)) {
139 $values = explode(
',', $value);
142 if (!is_array($values)) $values = Array($values);
144 $term_assetids = Array();
146 foreach ($values as $term) {
147 $term = str_replace(
',',
',', $term);
148 $termid = $thesaurus->getTermIdByName($term);
152 if (!empty($termid)) {
153 $term_assetids[$termid] = $thesaurus->id.
':'.$termid;
155 $term_info[$termid] = $term;
158 if (isset($asset->_tmp[
'error'])) {
160 foreach ($asset->_tmp[
'error'] as $message) {
161 echo
'<li class="sq-backend-warning">'.$message.
'</li>';
168 if ($enable_default) {
171 <script type=
"text/javascript">
173 function toggleManualInterface(div_1, div_2)
175 if (document.getElementById(div_1).style.display ==
'block') {
176 document.getElementById(div_1).style.display =
'none';
177 document.getElementById(div_2).style.display =
'block';
179 document.getElementById(div_2).style.display =
'none';
180 document.getElementById(div_1).style.display =
'block';
188 check_box($prefix.
'_default',
'1', $is_default,
'toggleManualInterface(\''.$prefix.
'_interface\',\''.$prefix.
'_defaults\')');
189 label(translate(
'thesaurus_use_default_value'), $prefix.
'_default');
191 echo
' '.translate(
'thesaurus_default_values_note');
196 echo
'<div id="'.$prefix.
'_interface" style="padding: 5px 0px; display:'.($is_default ?
'none' :
'block').
'">';
197 multiple_asset_finder($prefix.
'_thes_term', $term_assetids, Array(
'thesaurus_term'=>
'D'));
198 hidden_field($prefix.
'_terms_submitted', 1);
199 echo
'<div style="margin-top: 3px">';
200 echo translate(
'thesaurus_meta_thesaurus_note', get_asset_tag_line($thesaurus->id,
'details'));
205 echo
'<div id="'.$prefix.
'_defaults" style="display:'.($is_default ?
'block' :
'none').
'">';
210 multiple_asset_finder($prefix.
'_thes_term', $term_assetids, Array(
'thesaurus_term'=>
'D'));
211 hidden_field($prefix.
'_terms_submitted', 1);
214 if ($print_cascade_values_option) {
215 check_box($prefix.
'_cascade_value',
'1', FALSE);
216 label(translate(
'cascade_value'), $prefix.
'_cascade_value');
220 if (empty($values)) {
221 echo translate(
'thesaurus_no_values');
223 echo translate($is_default ?
'thesaurus_using_default_values' :
'thesaurus_using_non_default_values');
225 <table
class=
"sq-backend-table" border=
"1" style=
"margin-left: 0px">
227 <th style=
"width: 30%; white-space: none;"><?php echo translate(
'thesaurus_term'); ?></th>
228 <th><?php echo translate(
'thesaurus_lineages'); ?></th>
231 foreach ($term_info as $term_id => $term_name) {
235 if (!empty($term_id)) {
238 <td><?php echo get_asset_tag_line($term_assetids[$term_id],
'details') ?></td>
241 $lineages = $thesaurus->getLineagesForTerm($term_id);
242 if (!$lineages)
continue;
243 foreach ($lineages as $lineage) {
244 foreach ($lineage as $ancestor) {
246 if (isset($ancestor[
'relation'])) {
247 echo
'('.$ancestor[
'relation'].
') ';
249 echo $ancestor[
'term'];
264 return $write_access;
282 if (!$asset->
attr(
'editable'))
return FALSE;
290 if (!empty($_POST[$prefix.
'_default'])) {
292 $new_value_str = NULL;
295 if (!empty($_REQUEST[$prefix.
'_terms_submitted'])) {
296 $new_terms = array_get_index($_REQUEST, $prefix.
'_thes_term', Array());
297 foreach ($new_terms as $one_term) {
298 if (empty($one_term[
'assetid']))
continue;
299 $term_asset = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($one_term[
'assetid']);
300 $term_name = $term_asset->attr(
'name');
301 if ($term_asset->_thesaurus->id != $thesaurus->id) {
302 $asset->_tmp[
'error'][] = translate(
'thesaurus_meta_wrong_thesaurus', $term_name, $term_asset->_thesaurus->name, $term_asset->_thesaurus->id);
303 $GLOBALS[
'SQ_SYSTEM']->am->forgetAsset($term_asset);
306 $term_name = str_replace(
',',
',', $term_name);
307 $value[] = $term_name;
308 $GLOBALS[
'SQ_SYSTEM']->am->forgetAsset($term_asset);
311 $old_count = count($value);
312 $value = array_unique($value);
313 if ($old_count != count($value)) {
314 $asset->_tmp[
'error'][] = translate(
'thesaurus_term_duplicate_removed');
317 $value = implode(
',', $value);
324 if (isset($_POST[$prefix.
'_cascade_value'])) {
325 $field_cascade_value = TRUE;
348 if ((
boolean)$asset->
attr(
'is_contextable') === TRUE) {
349 $default = $asset->
attr(
'default');
351 $default = $GLOBALS[
'SQ_SYSTEM']->am->getAttributeValuesByName(
'default',
'metadata_field', Array($asset->id), 0);
352 $default = $default[$asset->id];
355 if (!$write_access) {
362 if (empty($default)) {
364 }
else if (!is_array($default)) {
365 $values = explode(
',', $default);
368 if (!is_array($values)) $values = Array($values);
370 $term_assetids = Array();
372 foreach ($values as $term) {
373 $termid = $thesaurus->getTermIdByName($term);
374 $term_assetids[] = $thesaurus->id.
':'.$termid;
375 $term_info[$termid] = $term;
378 multiple_asset_finder($prefix.
'_default_term', $term_assetids, Array(
'thesaurus_term'=>
'D'));
397 if (!$asset->
writeAccess(
'attributes'))
return FALSE;
401 $is_contextable = (boolean)$asset->
attr(
'is_contextable');
402 $contextid = $GLOBALS[
'SQ_SYSTEM']->getContextId();
403 $assetid = $asset->id;
406 $new_terms = array_get_index($_REQUEST, $prefix.
'_default_term', Array());
407 foreach ($new_terms as $one_term) {
408 if (empty($one_term[
'assetid']))
continue;
409 $term_asset = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($one_term[
'assetid']);
410 $term_name = $term_asset->attr(
'name');
411 if ($term_asset->_thesaurus->id != $thesaurus->id) {
412 $asset->_tmp[
'error'][] = translate(
'thesaurus_meta_wrong_thesaurus', $term_name, $term_asset->_thesaurus->name, $term_asset->_thesaurus->id);
413 $GLOBALS[
'SQ_SYSTEM']->am->forgetAsset($term_asset);
416 $value[] = $term_name;
417 $GLOBALS[
'SQ_SYSTEM']->am->forgetAsset($term_asset);
420 $old_count = count($value);
421 $value = array_unique($value);
422 if ($old_count != count($value)) {
423 $asset->_tmp[
'error'][] = translate(
'thesaurus_term_duplicate_removed');
425 $value = implode(
',', $value);
429 if ($is_contextable === FALSE) {
430 if ($contextid !== 0) {
431 $GLOBALS[
'SQ_SYSTEM']->changeContext(0);
432 $asset = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($assetid);
439 if ($is_contextable === FALSE) {
440 if ($contextid !== 0) {
441 $GLOBALS[
'SQ_SYSTEM']->am->forgetAsset($asset);
442 $GLOBALS[
'SQ_SYSTEM']->restoreContext();
443 $asset = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($assetid);