17 require_once dirname(__FILE__).
'/../../metadata_field/metadata_field_edit_fns.inc';
40 parent::__construct();
58 $attr->paint($prefix.
'_format', !$asset->
writeAccess(
'attributes'));
60 ?><a href=
"<?php echo sq_web_path('data'); ?>/asset_types/metadata_field_date/popups/keywords.html" onClick=
"var win = window.open(this.href, 'keywords', 'toolbar=0,menubar=0,location=0,status=0,scrollbars=1,resizable=1,width=640,height=520'); return false;"><?php echo translate(
'click_here'); ?></a><?php
61 $replacements_link = ob_get_contents();
64 $o->
note(translate(
'metadata_date_object_keys', $replacements_link));
83 $attr->process($prefix.
'_format');
84 if ($attr->processed) {
105 $offset = $asset->
attr(
'offset');
107 text_box($prefix.
'_offset', $offset, 30);
127 if (!isset($_POST[$prefix.
'_offset']))
return FALSE;
128 return $asset->
setAttrValue(
'offset', $_POST[$prefix.
'_offset']);
146 if ((
boolean)$asset->
attr(
'is_contextable') === TRUE) {
147 $default = $asset->
attr(
'default');
149 $default = $GLOBALS[
'SQ_SYSTEM']->am->getAttributeValuesByName(
'default',
'metadata_field', Array($asset->id), 0);
150 $default = $default[$asset->id];
172 $is_contextable = (boolean)$asset->
attr(
'is_contextable');
173 $assetid = $asset->id;
175 if ($is_contextable === TRUE) {
176 $default = $asset->
attr(
'default');
178 $default = $GLOBALS[
'SQ_SYSTEM']->am->getAttributeValuesByName(
'default',
'metadata_field', Array($assetid), 0);
179 $default = $default[$assetid];
182 $field_cascade_value=FALSE;
186 $value = array_get_index($_POST, $prefix.
'_repkeys',
'');
188 if (!empty($value)) {
189 $default =
'%'.trim($value).
'%';
193 if ($field->processField()) {
194 $value = $field->value;
195 $default = trim($value);
200 if (isset($_POST[$prefix.
'_cascade_value'])) {
201 $field_cascade_value = TRUE;
204 if ($is_contextable === FALSE) {
205 $GLOBALS[
'SQ_SYSTEM']->changeContext(0);
206 $asset = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($assetid);
212 if ($is_contextable === FALSE) {
213 $GLOBALS[
'SQ_SYSTEM']->am->forgetAsset($asset);
214 $GLOBALS[
'SQ_SYSTEM']->restoreContext();
215 $asset = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($assetid);
242 $arr = Array(
's',
'n',
'c');
243 $field->printEditOptions($arr);
245 echo $field->format();
248 $o->
note(translate(
'metadata_setup_table_explanation'));
267 if ($asset->
writeAccess(
'attributes') && $field->processEditOptions()) {
268 return $asset->
setAttrValue(
'setup_params', $field->parameters);
297 $default_val = $asset->
attr(
'default');
299 if (is_null($value_str)) {
300 $value_str = $default_val;
305 $value_components = $asset->
attr(
'value_components');
308 $select_options = Array(
309 '' =>
'-- '.strtolower(translate(
'keywords')).
' --',
310 'asset_created' => translate(
'creation_date'),
311 'asset_updated' => translate(
'last_updated_date'),
312 'asset_published' => translate(
'last_published_date'),
316 $uses_keyword = (substr($value, 0, 1) ==
'%');
317 if (empty($value)) $value = NULL;
320 if ($asset->
attr(
'show_keywords')) {
321 $field->parameters[
'extras'] = Array(
322 'd' =>
'onchange="document.getElementById(\''.$prefix.
'_repkeys\').value = \'\'"',
323 'm' =>
'onchange="document.getElementById(\''.$prefix.
'_repkeys\').value = \'\'"',
324 'y' =>
'onchange="document.getElementById(\''.$prefix.
'_repkeys\').value = \'\'"',
325 'h' =>
'onchange="document.getElementById(\''.$prefix.
'_repkeys\').value = \'\'"',
326 'm' =>
'onchange="document.getElementById(\''.$prefix.
'_repkeys\').value = \'\'"',
327 's' =>
'onchange="document.getElementById(\''.$prefix.
'_repkeys\').value = \'\'"',
328 'i' =>
'onchange="document.getElementById(\''.$prefix.
'_repkeys\').value = \'\'"',
333 $field->printField();
334 echo
'<br /> <b>-'.strtoupper(translate(
'or_in')).
'- </b>';
335 preg_match(
'/([0-9]+)\s([i|h|d|w|m|y])/', $value, $matches);
336 text_box($prefix.
'_duration',
'0', 2,
'', TRUE);
339 '-' =>
'--Select One --',
340 'minutes' => translate(
'minutes'),
341 'hours' => translate(
'hours'),
342 'days' => translate(
'days'),
343 'weeks' => translate(
'weeks'),
344 'months' => translate(
'months'),
345 'years' => translate(
'years'),
348 combo_box($prefix.
'_period', $periods, FALSE,
'-', NULL);
349 echo
"<b> from now</b>";
351 if ($asset->
attr(
'show_keywords')) {
352 echo
'<br /> <b>-'.strtoupper(translate(
'or')).
'-</b> ';
353 combo_box($prefix.
'_repkeys', $select_options, FALSE, trim($value,
'%'), 0,
'');
356 if ($enable_default) {
357 echo
'<br /> <b>-'.strtoupper(translate(
'or')).
'-</b> ';
358 if ((substr($default_val, 0, 1) ==
'%') || empty($value)) {
359 $default_date_exp =
'null';
360 $default_kw_exp =
"'".trim($default_val,
'%').
"'";
362 list($dy, $dm, $dd, $dh, $di, $ds) = sscanf($default_val,
'%d-%d-%d %d:%d:%d');
365 if($dy == NULL && $dm == NULL && $dd == NULL && $dh == NULL && $di == NULL && $ds == NULL) {
366 $default_date_exp =
'null';
368 $default_date_exp =
"{y:$dy, m:$dm, d:$dd, h:$dh, i:$di, s:$ds}";
370 $default_kw_exp =
'null';
373 check_box($prefix.
'_default',
'1', $is_default,
'handleMetadataDatetimeDefaultClick(this, \''.$prefix.
'\',
'.$default_date_exp.',
'.$default_kw_exp.')
');
374 label(translate('use_default
'), $prefix.'_default
');
376 <script type="text/javascript" src="<?php echo sq_web_path('data
'); ?>/asset_types/metadata_field_date/js/metadata_field_date.js"></script>
377 <script type="text/javascript"><!--
379 handleMetadataDatetimeDefaultClick(document.getElementById('<?php echo $prefix; ?>_default
'), '<?php echo $prefix; ?>
', <?php echo $default_date_exp; ?>, <?php echo $default_kw_exp; ?>);
385 if ($print_cascade_values_option) {
387 check_box($prefix.'_cascade_value
', '1
', FALSE);
388 label(translate('cascade_value
'), $prefix.'_cascade_value
');
391 } else if ($uses_keyword && isset($select_options[trim($value, '%
')])) {
392 echo '<i>
'.translate('keyword_replacement
').': </i>
', $select_options[trim($value, '%
')];
393 if ($is_default && $enable_default) {
394 echo ' <em style=
"color: #666">(
'.strtolower(translate('default')).')</em>
';
397 echo $field->format();
398 if ($is_default && $enable_default) {
399 echo ' <em style=
"color: #666">(
'.strtolower(translate('default')).')</em>
';
403 return $write_access;
405 }//end paintValueInterface()
422 public function processInlineValueInterface(Metadata_Field_Date $asset, &$new_value_str, &$field_cascade_value)
424 if (!$asset->attr('editable
')) return FALSE; // nothing for us to do
427 $prefix = $asset->getPrefix();
429 if (!empty($_POST[$prefix.'_default
'])) {
431 $new_value_str = NULL;
434 $value = array_get_index($_POST, $prefix.'_repkeys
', '');
435 if (!empty($value)) {
436 $new_value_str = Metadata_Field::encodeValueString('%
'.trim($value).'%
', Array());
438 } else if (!empty($_POST[$prefix.'_duration
']) && $_POST[$prefix.'_duration
'] != '0
' && $_POST[$prefix.'_period
'] != '-
') {
439 $value = date('Y-m-d H:i:s
', strtotime($_POST[$prefix.'_duration
'].' '.$_POST[$prefix.'_period
']));
440 $new_value_str = Metadata_Field::encodeValueString(trim($value), Array());
443 $field = $asset->_getDateTimeField($prefix);
444 if ($field->processField()) {
445 $value = $field->value;
446 $new_value_str = Metadata_Field::encodeValueString(trim($value), Array());
452 if (isset($_POST[$prefix.'_cascade_value
'])) {
453 $field_cascade_value = TRUE;
459 }//end processInlineValueInterface()
474 public function generateMetadata(Metadata_Field_Date $asset, $value_str, &$tag_value, Array &$keywords)
476 require_once SQ_FUDGE_PATH.'/
general/text.inc
';
480 if (is_null($value_str)) {
481 $value_str = $asset->getDefaultValue();
486 $value_components = $asset->attr('value_components
');
487 Metadata_Field::decodeValueString($value_str, $value, $value_components);
491 // we create a new array here to pass to our parent so we dont muck up the
492 // referenced timestamp values
493 if (substr($value, 0, 1) != '%
') {
494 if (empty($value)) $value = NULL;
495 $field = $asset->_getDateTimeField('', $value);
496 $value = $field->format();
500 parent::generateMetadata($asset, Metadata_Field::encodeValueString($value, $value_components), $tag_value, $keywords);
501 $metadata_tag = ob_get_contents();
504 if (substr($original, 0, 1) == '%
') {
505 // strip off the last % sign from the end of $key string
506 $key = substr($original, 0, -1);
508 // prepare date format for merging - we will replace all spaces with underscores
509 $format = str_replace(' ', '~
', $asset->attr('format
'));
511 // merge the values with '_
', add closing % sign and proceed...
512 $key = $key.'_
'.$format;
513 $offset = $asset->attr('offset
');
514 if (!empty($offset)) {
515 $offset = str_replace(' ', '', $offset);
520 // replace the plain keyword with the one that contains the format
521 $tag_value = str_replace($original, $key, $tag_value);
523 // replace the plain keyword (or at least it's first occurance in the keywords array)
525 $keyword = substr($original, 1, -1);
526 if (($i = array_search($keyword, $keywords)) !== FALSE) {
527 $keywords[$i] = substr($key, 1, -1);