/
displayHelpers.php
4753 lines (4149 loc) · 232 KB
/
displayHelpers.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/** ---------------------------------------------------------------------
* app/helpers/displayHelpers.php : miscellaneous functions
* ----------------------------------------------------------------------
* CollectiveAccess
* Open-source collections management software
* ----------------------------------------------------------------------
*
* Software by Whirl-i-Gig (http://www.whirl-i-gig.com)
* Copyright 2009-2019 Whirl-i-Gig
*
* For more information visit http://www.CollectiveAccess.org
*
* This program is free software; you may redistribute it and/or modify it under
* the terms of the provided license as published by Whirl-i-Gig
*
* CollectiveAccess is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTIES whatsoever, including any implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
* This source code is free and modifiable under the terms of
* GNU General Public License. (http://www.gnu.org/copyleft/gpl.html). See
* the "license.txt" file for details, or visit the CollectiveAccess web site at
* http://www.CollectiveAccess.org
*
* @package CollectiveAccess
* @subpackage utils
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License version 3
*
* ----------------------------------------------------------------------
*/
/**
*
*/
require_once(__CA_LIB_DIR__.'/Datamodel.php');
require_once(__CA_LIB_DIR__.'/Configuration.php');
require_once(__CA_LIB_DIR__.'/Parsers/TimeExpressionParser.php');
require_once(__CA_LIB_DIR__.'/Parsers/ExpressionParser.php');
require_once(__CA_LIB_DIR__."/ApplicationPluginManager.php");
require_once(__CA_LIB_DIR__.'/Parsers/DisplayTemplateParser.php');
require_once(__CA_LIB_DIR__.'/Media/MediaInfoCoder.php');
# ------------------------------------------------------------------------------------------------
/**
* @param $ps_item_locale -
* @param $pa_preferred_locales -
* @return Array - returns an associative array defining which locales should be used when displaying values; suitable for use with caExtractValuesByLocale()
*/
$g_user_locale_rules = array();
function caGetUserLocaleRules($ps_item_locale=null, $pa_preferred_locales=null) {
global $g_ui_locale, $g_ui_locale_id, $g_user_locale_rules;
if (isset($g_user_locale_rules[$ps_item_locale])) { return $g_user_locale_rules[$ps_item_locale]; }
$o_config = Configuration::load();
$va_default_locales = $o_config->getList('locale_defaults');
$va_preferred_locales = array();
$va_similar_locales = [];
if ($ps_item_locale) {
// if item locale is passed as locale_id we need to convert it to a code
if (is_numeric($ps_item_locale)) {
$t_locales = new ca_locales();
if ($t_locales->load($ps_item_locale)) {
$ps_item_locale = $t_locales->getCode();
} else {
$ps_item_locale = null;
}
}
if ($ps_item_locale) {
$va_preferred_locales[$ps_item_locale] = true;
}
$va_similar_locales = ca_locales::localesForLanguage($ps_item_locale, ['codesOnly' => true]);
}
if (is_array($pa_preferred_locales)) {
foreach($pa_preferred_locales as $vs_preferred_locale) {
$va_preferred_locales[$vs_preferred_locale] = true;
}
}
$va_fallback_locales = array();
if (is_array($va_default_locales)) {
foreach($va_default_locales as $vs_fallback_locale) {
$va_similar_locales = array_merge($va_similar_locales, ca_locales::localesForLanguage($vs_fallback_locale, ['codesOnly' => true]));
if (!isset($va_preferred_locales[$vs_fallback_locale]) || !$va_preferred_locales[$vs_fallback_locale]) {
$va_fallback_locales[$vs_fallback_locale] = true;
}
}
}
// add locales with same language
foreach($va_similar_locales as $vs_similar_locale) {
$va_fallback_locales[$vs_similar_locale] = true;
}
if ($g_ui_locale) {
if (!isset($va_preferred_locales[$g_ui_locale]) || !$va_preferred_locales[$g_ui_locale]) {
$va_preferred_locales[$g_ui_locale] = true;
}
}
$va_fallback_locales = array_filter($va_fallback_locales, function($v, $k) use ($ps_item_locale, $va_fallback_locales, $va_preferred_locales) { return !isset($va_preferred_locales[$k]) && ($k !== $ps_item_locale); }, ARRAY_FILTER_USE_BOTH);
$va_rules = array(
'preferred' => $va_preferred_locales, /* all of these locales will display if available */
'fallback' => $va_fallback_locales /* the first of these that is available will display, but only if none of the preferred locales are available */
);
if($ps_item_locale){ $g_user_locale_rules[$ps_item_locale] = $va_rules; }
return $va_rules;
}
# ------------------------------------------------------------------------------------------------
/**
*
* @param $pa_locale_rules - Associative array defining which locales to extract, and how to fall back to alternative locales should your preferred locales not exist in $pa_values
* @param $pa_values - Associative array keyed by unique item_id and then locale code (eg. en_US) or locale_id; the values can be anything - string, numbers, objects, arrays, etc.
* @param $pa_options [optional] - Associative array of options; available options are:
* 'returnList' = return an indexed array of found values rather than an associative array keys on unique item_id [default is false]
* 'debug' = print debugging information [default is false]
* @return Array - an array of found values keyed by unique item_id; or an indexed list of found values if option 'returnList' is passed in $pa_options
*/
function caExtractValuesByLocale($pa_locale_rules, $pa_values, $pa_options=null) {
if (!is_array($pa_values)) { return array(); }
$va_locales = ca_locales::getLocaleList();
if (!is_array($pa_options)) { $pa_options = array(); }
if (!isset($pa_options['returnList'])) { $pa_options['returnList'] = false; }
if (!is_array($pa_values)) { return array(); }
$va_values = array();
foreach($pa_values as $vm_id => $va_value_list_by_locale) {
if (sizeof($va_value_list_by_locale) == 1) { // Don't bother looking if there's just a single value
$va_values[$vm_id] = array_pop($va_value_list_by_locale);
continue;
}
foreach($va_value_list_by_locale as $pm_locale => $vm_value) {
// convert locale_id to locale string
if (is_numeric($pm_locale)) {
if (!$va_locales[$pm_locale]) { continue; } // invalid locale_id?
$vs_locale = $va_locales[$pm_locale]['language'].'_'.$va_locales[$pm_locale]['country'];
} else {
$vs_locale = $pm_locale;
}
// try to find values for preferred locale
if (isset($pa_locale_rules['preferred'][$vs_locale]) && $pa_locale_rules['preferred'][$vs_locale]) {
$va_values[$vm_id] = $vm_value;
break;
}
// try fallback locales
if (isset($pa_locale_rules['fallback'][$vs_locale]) && $pa_locale_rules['fallback'][$vs_locale]) {
$va_values[$vm_id] = $vm_value;
}
}
if (!isset($va_values[$vm_id])) {
// desperation mode: pick an available locale
$va_values[$vm_id] = array_pop($va_value_list_by_locale);
}
}
return ($pa_options['returnList']) ? array_values($va_values) : $va_values;
}
# ------------------------------------------------------------------------------------------------
function caExtractValuesByUserLocale($pa_values, $ps_item_locale=null, $pa_preferred_locales=null, $pa_options=null) {
return caExtractValuesByLocale(caGetUserLocaleRules($ps_item_locale, $pa_preferred_locales), $pa_values, $pa_options);
}
# ------------------------------------------------------------------------------------------------
/**
* Takes the output of BaseModel->getHierarchyAncestors() and tries to extract the appropriate values for the current user's locale.
* This is designed for the common case where you want to get a list of ancestors with their labels in the appropriate language,
* so you call getHierarchyAncestors() with the 'getHierarchyAncestors' option set to the label table. What you get back is a simple
* list where each item is a node with the table fields + the label fields; if a node has labels in several languages then you'll get back
* dupes - one for each language.
*
* This function takes that list with dupes and returns an array key'ed upon the primary key containing a single entry for each node
* and the label set to the appropriate language - no dupes!
*
* @param array - the list of ancestor hierarchy nodes as returned by BaseModel->getHierarchyAncestors()
* @param string - the field name of the primary key of the hierarchy (eg. 'place_id' for ca_places)
* @return array - the list of ancestors with labels in the appropriate language; array is indexed by the primary key
*/
function caExtractValuesByUserLocaleFromHierarchyAncestorList($pa_list, $ps_primary_key_name, $ps_label_display_field, $ps_use_if_no_label_field, $ps_default_text='???') {
if (!is_array($pa_list)) { return array(); }
$va_values = array();
foreach($pa_list as $vn_i => $va_item) {
if (!isset($va_item[$ps_label_display_field]) || !$va_item[$ps_label_display_field]) {
if (!isset($va_item[$ps_use_if_no_label_field]) || !($va_item[$ps_label_display_field] = $va_item[$ps_use_if_no_label_field])) {
$va_item[$ps_label_display_field] = $ps_default_text;
}
}
$va_values[$va_item['NODE'][$ps_primary_key_name]][$va_item['NODE']['locale_id']] = $va_item;
}
return caExtractValuesByUserLocale($va_values);
}
# ------------------------------------------------------------------------------------------------
function caExtractValuesByUserLocaleFromHierarchyChildList($pa_list, $ps_primary_key_name, $ps_label_display_field, $ps_use_if_no_label_field, $ps_default_text='???') {
if (!is_array($pa_list)) { return array(); }
$va_values = array();
foreach($pa_list as $vn_i => $va_item) {
if (!$va_item[$ps_label_display_field]) {
if (!($va_item[$ps_label_display_field] = $va_item[$ps_use_if_no_label_field])) {
$va_item[$ps_label_display_field] = $ps_default_text;
}
}
$va_values[$va_item[$ps_primary_key_name]][$va_item['locale_id']] = $va_item;
}
return caExtractValuesByUserLocale($va_values);
}
# ------------------------------------------------------------------------------------------------
function caFormatFieldErrorsAsHTML($pa_errors, $ps_css_class) {
$vs_output = "<ul class='{$ps_css_class}'>\n";
foreach($pa_errors as $o_e) {
$vs_output .= '<li class="'.$ps_css_class.'"><img src=""/> ';
$vs_output .= $o_e->getErrorMessage()."</li>";
}
$vs_output .= "</ul>\n";
return $vs_output;
}
# ------------------------------------------------------------------------------------------------
function caFormControlBox($ps_left_content, $ps_middle_content, $ps_right_content, $ps_second_row_content='') {
$vs_output = '<div class="control-box rounded">
<div class="control-box-left-content">'.$ps_left_content;
$vs_output .= '</div>
<div class="control-box-right-content">'.$ps_right_content;
$vs_output .= '</div><div class="control-box-middle-content">'.$ps_middle_content.'</div>';
if ($ps_second_row_content) {
$vs_output .= '<div class="clear"><!--empty--></div>'.$ps_second_row_content;
}
$vs_output .= '</div>
<div class="clear"><!--empty--></div>'."\n";
return $vs_output;
}
# ------------------------------------------------------------------------------------------------
/**
*
*/
function caDeleteWarningBox($po_request, $t_instance, $ps_item_name, $ps_module_path, $ps_controller, $ps_cancel_action, $pa_parameters) {
if ($vs_warning = isset($pa_parameters['warning']) ? $pa_parameters['warning'] : null) {
$vs_warning = '<br/>'.$vs_warning;
}
$vs_remapping_controls = caDeleteRemapper($po_request, $t_instance);
$vs_output = caFormTag($po_request, 'Delete', 'caDeleteForm', null, 'post', 'multipart/form-data', '_top', array('noCSRFToken' => false,'disableUnsavedChangesWarning' => true));
$vs_output .= "<div class='delete-control-box'>".caFormControlBox(
"<div class='delete_warning_box'>"._t('Really delete "%1"?', $ps_item_name)."</div>".
($vs_remapping_controls ? "<div class='delete_remapping_controls'>{$vs_remapping_controls}</div>" : ''),
$vs_warning,
caFormSubmitButton($po_request, __CA_NAV_ICON_DELETE__, _t("Delete"), 'caDeleteForm', array()).
caFormNavButton($po_request, __CA_NAV_ICON_CANCEL__, _t("Cancel"), '', $ps_module_path, $ps_controller, $ps_cancel_action, $pa_parameters)
)."</div>\n";
foreach(array_merge($pa_parameters, array('confirm' => 1)) as $vs_f => $vs_v) {
$vs_output .= caHTMLHiddenInput($vs_f, array('value' => $vs_v));
}
$vs_output .= caHTMLHiddenInput($t_instance->primaryKey(), array('value' => $t_instance->getPrimaryKey()));
$vs_output .= "</form>\n";
return $vs_output;
}
# ------------------------------------------------------------------------------------------------
/**
*
*/
function caDeleteRemapper($po_request, $t_instance) {
$vs_instance_table = $t_instance->tableName();
$vn_reference_to_count = $vn_reference_from_count = $vn_child_count = 0;
$va_reference_to_buf = $va_reference_from_buf = array();
switch($vs_instance_table) {
case 'ca_relationship_types':
// get # of relationships using this type
$vn_rel_count = $t_instance->getRelationshipCountForType();
$t_rel_instance = Datamodel::getInstanceByTableNum($t_instance->get('table_num'));
if (!$t_rel_instance->load($t_instance->get('table_num'))) { return ''; }
if ($vn_rel_count == 1) {
$va_reference_to_buf[] = _t("Type is used by %1 %2", $vn_rel_count, $t_rel_instance->getProperty('NAME_PLURAL'))."<br>\n";
} else {
$va_reference_to_buf[] = _t("Type is used by %1 %2", $vn_rel_count, $t_rel_instance->getProperty('NAME_PLURAL'))."<br>\n";
}
$vn_reference_to_count += $vn_rel_count;
$vs_typename = _t('relationship type');
break;
default:
// Check relationships
$va_tables = array(
'ca_objects', 'ca_object_lots', 'ca_entities', 'ca_places', 'ca_occurrences', 'ca_collections', 'ca_storage_locations', 'ca_list_items', 'ca_loans', 'ca_movements', 'ca_tours', 'ca_tour_stops', 'ca_object_representations'
);
if (!in_array($t_instance->tableName(), $va_tables)) { return null; }
foreach($va_tables as $vs_table) {
if (!is_array($va_items = $t_instance->getRelatedItems($vs_table))) { $va_items = []; }
if (!($vn_c = sizeof($va_items))) { continue; }
if ($vn_c == 1) {
$va_reference_to_buf[] = _t("Has %1 relationship to %2", $vn_c, caGetTableDisplayName($vs_table, true))."<br>\n";
} else {
$va_reference_to_buf[] = _t("Has %1 relationships to %2", $vn_c, caGetTableDisplayName($vs_table, true))."<br>\n";
}
$vn_reference_to_count += $vn_c;
}
// Check attributes *using* this row
if ($vn_datatype = $t_instance->authorityElementDatatype()) {
if ($vn_c = $t_instance->getAuthorityElementReferences(array('countOnly' => true))) {
if ($vn_c == 1) {
$va_reference_to_buf[] = _t("Is referenced %1 time", $vn_c)."<br>\n";
} else {
$va_reference_to_buf[] = _t("Is referenced %1 times", $vn_c)."<br>\n";
}
$vn_reference_to_count += $vn_c;
}
}
$vs_typename = $t_instance->getTypeName();
// Check for authority references that are *part* of this row
if (is_array($va_references_from = $t_instance->getAuthorityElementList()) && sizeof($va_references_from)) {
foreach($va_references_from as $va_ref) {
if (!($t_element = ca_metadata_elements::getInstance($va_ref['hier_element_id']))) { continue; }
$va_reference_from_buf[] = _t(($va_ref['count'] == 1) ? "%1 reference in %2" : "%1 references in %2", $va_ref['count'], $t_element->getLabelForDisplay());
$vn_reference_from_count += $va_ref['count'];
}
}
// Check for child records in hierarchy
if ($t_instance->isHierarchical() && is_array($va_children = call_user_func($t_instance->tableName()."::getHierarchyChildrenForIDs", [$t_instance->getPrimaryKey()]))) {
$vn_child_count = sizeof($va_children);
if ($vn_child_count == 1) {
$va_reference_to_buf[] = _t("Has %1 child", $vn_child_count)."<br>\n";
} else {
$va_reference_to_buf[] = _t("Has %1 children", $vn_child_count)."<br>\n";
}
$vn_reference_to_count += $vn_child_count;
}
break;
}
// get default setting
$o_config = $po_request->getAppConfig();
if (!in_array($vs_default = strtolower($po_request->user->getPreference('cataloguing_delete_reference_handling_default')), ['transfer', 'remap', 'remove', 'delete'])) {
if (!in_array($vs_default = strtolower($o_config->get("{$vs_instance_table}_delete_reference_handling_default")), ['transfer', 'remap', 'remove', 'delete'])) {
if (!in_array($vs_default = strtolower($o_config->get('delete_reference_handling_default')), ['transfer', 'remap', 'remove', 'delete'])) {
$vs_default = null;
}
}
}
switch($vs_default) {
case 'transfer':
case 'remap':
$vs_default = 'remap';
break;
case 'remove':
case 'delete':
$vs_default = 'delete';
break;
}
$vs_output = '';
if (sizeof($va_reference_to_buf)) {
// add autocompleter for remapping
if ($vn_reference_to_count == 1) {
$vs_output .= "<h3 id='caReferenceHandlingToCount'>"._t('This %1 is referenced %2 time', $vs_typename, $vn_reference_to_count).". "._t('When deleting this %1:', $vs_typename)."</h3>\n";
} else {
$vs_output .= "<h3 id='caReferenceHandlingToCount'>"._t('This %1 is referenced %2 times', $vs_typename, $vn_reference_to_count).". "._t('When deleting this %1:', $vs_typename)."</h3>\n";
}
$va_delete_opts = ['value' => 'delete', 'id' => 'caReferenceHandlingToDelete'];
$va_remap_opts = ['value' => 'remap', 'id' => 'caReferenceToHandlingRemap'];
$va_remap_lookup_opts = ['value' => '', 'size' => 40, 'id' => 'caReferenceHandlingToRemapTo', 'class' => 'lookupBg'];
if ($vs_default === 'delete') {
$va_delete_opts['checked'] = 1;
$va_remap_lookup_opts['disabled'] = 1;
} else {
$va_remap_opts['checked'] = 1;
}
$vs_output .= caHTMLRadioButtonInput('caReferenceHandlingTo', $va_delete_opts).' '._t('remove all references')."<br/>\n";
if ($vs_instance_table === 'ca_storage_locations') {
AssetLoadManager::register('hierBrowser');
$vs_output .= caHTMLRadioButtonInput('caReferenceHandlingTo', $va_remap_opts).' '._t('transfer references to').' ';
$vs_output .= "<div id=\"caReferenceHandlingToRemapToHierBrowser\" class=\"hierarchyBrowserSmall\" style=\"width: 700px;\">
<!-- Content for hierarchy browser is dynamically inserted here by ca.hierbrowser -->
</div><!-- end hierbrowser -->";
$vs_output .= "
<div class=\"hierarchyBrowserFind\">
"._t('Find').": <input type=\"text\" id=\"caReferenceHandlingToRemapToHierBrowserSearch\" name=\"search\" value=\"\" size=\"25\"/>
</div>";
} else {
$vs_output .= caHTMLRadioButtonInput('caReferenceHandlingTo', $va_remap_opts).' '._t('transfer references to').' '.caHTMLTextInput('caReferenceHandlingToRemapTo', $va_remap_lookup_opts);
}
$vs_output .= "<a href='#' class='button' onclick='jQuery(\"#caReferenceHandlingToRemapToID\").val(\"\"); jQuery(\"#caReferenceHandlingToRemapTo\").val(\"\"); jQuery(\"#caReferenceHandlingToClear\").css(\"display\", \"none\"); return false;' style='display: none;' id='caReferenceHandlingToClear'>"._t('Clear').'</a>';
$vs_output .= caHTMLHiddenInput('caReferenceHandlingToRemapToID', array('value' => '', 'id' => 'caReferenceHandlingToRemapToID'));
if ($vn_child_count > 0) {
$vs_output .= '<p class="formLabelWarning" id="caChildDeletionWarning"><i class="caIcon fa fa-info-circle fa-1x"></i> '._t('Child records will be deleted')."</p>\n";
}
$vs_output .= "<script type='text/javascript'>";
$va_service_info = caJSONLookupServiceUrl($po_request, $t_instance->tableName(), array('noSymbols' => 1, 'noInline' => 1, 'exclude' => (int)$t_instance->getPrimaryKey(), 'table_num' => (int)$t_instance->get('table_num')));
if ($vs_instance_table === 'ca_storage_locations') {
$vs_output .= "
var caReferenceHandlingToRemapToHierBrowser = null;
jQuery(document).ready(function() {
if (!caReferenceHandlingToRemapToHierBrowser) {
caReferenceHandlingToRemapToHierBrowser = caUI.initHierBrowser('caReferenceHandlingToRemapToHierBrowser', {
levelDataUrl: '".$va_service_info['levelList']."',
initDataUrl: '".$va_service_info['ancestorList']."',
readOnly: true,
editButtonIcon: \"".caNavIcon(__CA_NAV_ICON_RIGHT_ARROW__, 1)."\",
disabledButtonIcon: \"".caNavIcon(__CA_NAV_ICON_DOT__, 1)."\",
allowDragAndDropSorting: false,
initItemID: '".$t_instance->get("{$vs_instance_table}.parent_id")."',
excludeItemIDs: [".$t_instance->getPrimaryKey()."],
indicator: \"".caNavIcon(__CA_NAV_ICON_SPINNER__, 1)."\",
displayCurrentSelectionOnLoad: false,
onSelection: function(id) {
jQuery(\"#caReferenceHandlingToRemapToID\").val(id);
}
});
}
jQuery(\"#caReferenceHandlingToRemapToHierBrowserSearch\").attr(\"disabled\", true);
jQuery('#caReferenceToHandlingRemap').click(function() {
caReferenceHandlingToRemapToHierBrowser.isReadOnly(false);
jQuery(\"#caReferenceHandlingToRemapToHierBrowserSearch\").attr(\"disabled\", false);
jQuery('#caChildDeletionWarning').hide();
});
jQuery('#caReferenceHandlingToDelete').click(function() {
caReferenceHandlingToRemapToHierBrowser.isReadOnly(true);
jQuery(\"#caReferenceHandlingToRemapToHierBrowserSearch\").attr(\"disabled\", true);
jQuery('#caChildDeletionWarning').show();
});
jQuery('#caReferenceHandlingToRemapToHierBrowserSearch').autocomplete(
{
source: '".$va_service_info['search']."', minLength: 3, delay: 800, html: true,
select: function( event, ui ) {
if (ui.item.id) {
caReferenceHandlingToRemapToHierBrowser.setUpHierarchy(ui.item.id); // jump browser to selected item
jQuery('#caReferenceHandlingToRemapToID').val(ui.item.id);
}
event.preventDefault();
jQuery('#caReferenceHandlingToRemapToHierBrowserSearch').val('');
}
}
).click(function() { this.select() });
})";
} else {
$vs_output .= "jQuery(document).ready(function() {";
$vs_output .= "jQuery('#caReferenceHandlingToRemapTo').autocomplete(
{
source: '".$va_service_info['search']."', html: true,
minLength: 3, delay: 800,
select: function(event, ui) {
jQuery('#caReferenceHandlingToRemapToID').val(ui.item.id);
jQuery('#caReferenceHandlingClear').css('display', 'inline');
}
}
);";
$vs_output .= "jQuery('#caReferenceToHandlingRemap').click(function() {
jQuery('#caReferenceHandlingToRemapTo').attr('disabled', false);
jQuery('#caChildDeletionWarning').hide();
});
jQuery('#caReferenceHandlingToDelete').click(function() {
jQuery('#caReferenceHandlingToRemapTo').attr('disabled', true);
jQuery('#caChildDeletionWarning').show();
});
";
$vs_output .= "});";
}
$vs_output .= "</script>\n";
TooltipManager::add('#caReferenceHandlingToCount', "<h2>"._t('References to this %1', $t_instance->getProperty('NAME_SINGULAR'))."</h2>\n".join("\n", $va_reference_to_buf));
}
if (sizeof($va_reference_from_buf)) {
// add autocompleter for remapping
if ($vn_reference_from_count == 1) {
$vs_output .= "<h3 id='caReferenceHandlingFromCount'>"._t('This %1 references %2 other item in metadata', $vs_typename, $vn_reference_from_count).". "._t('When deleting this %1:', $vs_typename)."</h3>\n";
} else {
$vs_output .= "<h3 id='caReferenceHandlingFromCount'>"._t('This %1 references %2 other items in metadata', $vs_typename, $vn_reference_from_count).". "._t('When deleting this %1:', $vs_typename)."</h3>\n";
}
$va_delete_opts = ['value' => 'delete', 'id' => 'caReferenceHandlingFromDelete'];
$va_remap_opts = ['value' => 'remap', 'id' => 'caReferenceHandlingFromRemap'];
$va_remap_lookup_opts = ['value' => '', 'size' => 40, 'id' => 'caReferenceHandlingToRemapFrom', 'class' => 'lookupBg'];
if ($vs_default === 'delete') {
$va_delete_opts['checked'] = 1;
$va_remap_lookup_opts['disabled'] = 1;
} else {
$va_remap_opts['checked'] = 1;
}
$vs_output .= caHTMLRadioButtonInput('caReferenceHandlingFrom', $va_delete_opts).' '._t('remove these references')."<br/>\n";
$vs_output .= caHTMLRadioButtonInput('caReferenceHandlingFrom', $va_remap_opts).' '._t('transfer these references and accompanying metadata to').' '.caHTMLTextInput('caReferenceHandlingToRemapFrom', $va_remap_lookup_opts);
$vs_output .= "<a href='#' class='button' onclick='jQuery(\"#caReferenceHandlingToRemapFromID\").val(\"\"); jQuery(\"#caReferenceHandlingToRemapFrom\").val(\"\"); jQuery(\"#caReferenceHandlingClear\").css(\"display\", \"none\"); return false;' style='display: none;' id='caReferenceHandlingClear'>"._t('Clear').'</a>';
$vs_output .= caHTMLHiddenInput('caReferenceHandlingToRemapFromID', array('value' => '', 'id' => 'caReferenceHandlingToRemapFromID'));
$vs_output .= "<script type='text/javascript'>";
$va_service_info = caJSONLookupServiceUrl($po_request, $t_instance->tableName(), array('noSymbols' => 1, 'noInline' => 1, 'exclude' => (int)$t_instance->getPrimaryKey(), 'table_num' => (int)$t_instance->get('table_num')));
$vs_output .= "jQuery(document).ready(function() {";
$vs_output .= "jQuery('#caReferenceHandlingToRemapFrom').autocomplete(
{
source: '".$va_service_info['search']."', html: true,
minLength: 3, delay: 800,
select: function(event, ui) {
jQuery('#caReferenceHandlingToRemapFromID').val(ui.item.id);
jQuery('#caReferenceHandlingClear').css('display', 'inline');
}
}
);";
$vs_output .= "jQuery('#caReferenceHandlingFromRemap').click(function() {
jQuery('#caReferenceHandlingToRemapFrom').attr('disabled', false);
});
jQuery('#caReferenceHandlingFromDelete').click(function() {
jQuery('#caReferenceHandlingToRemapFrom').attr('disabled', true);
});
";
$vs_output .= "});";
$vs_output .= "</script>\n";
TooltipManager::add('#caReferenceHandlingFromCount', "<h2>"._t('References by this %1', $t_instance->getProperty('NAME_SINGULAR'))."</h2>\n".join("<br/>\n", $va_reference_from_buf));
}
return $vs_output;
}
# ------------------------------------------------------------------------------------------------
/**
* Returns HTML <img> tag displaying spinning "I'm doing something" icon
*/
function caBusyIndicatorIcon($po_request, $pa_attributes=null) {
return caNavIcon(__CA_NAV_ICON_SPINNER__, 1, $pa_attributes);
}
# ------------------------------------------------------------------------------------------------
/**
*
*/
function caGetMediaInfoForDisplay($pm_media, $ps_version) {
$o_coder = (is_a($pm_media, "MediaInfoCoder")) ? $pm_media : new MediaInfoCoder($pm_media);
$va_ret = [];
$va_media_info = $o_coder->getMediaInfo();
$va_dimensions = [];
if (isset($va_media_info[$ps_version]['WIDTH']) && isset($va_media_info[$ps_version]['HEIGHT'])) {
if (($vn_w = $va_media_info[$ps_version]['WIDTH']) && ($vn_h = $va_media_info[$ps_version]['WIDTH'])) {
$va_dimensions[] = $va_media_info[$ps_version]['WIDTH'].'p x '.$va_media_info[$ps_version]['HEIGHT'].'p';
}
}
if (isset($va_media_info[$ps_version]['PROPERTIES']['bitdepth']) && ($vn_depth = $va_media_info[$ps_version]['PROPERTIES']['bitdepth'])) {
$va_dimensions[] = $va_ret['bitdepth'] = intval($vn_depth).' bpp';
}
if (isset($va_media_info[$ps_version]['PROPERTIES']['colorspace']) && ($vs_colorspace = $va_media_info[$ps_version]['PROPERTIES']['colorspace'])) {
$va_dimensions[] = $va_ret['colorspace'] = $vs_colorspace;
}
if (isset($va_media_info[$ps_version]['PROPERTIES']['resolution']) && is_array($va_resolution = $va_media_info[$ps_version]['PROPERTIES']['resolution'])) {
if (isset($va_resolution['x']) && isset($va_resolution['y']) && $va_resolution['x'] && $va_resolution['y']) {
// TODO: units for resolution? right now assume pixels per inch
if ($va_resolution['x'] == $va_resolution['y']) {
$va_dimensions[] = $va_ret['resolution'] = $va_resolution['x'].'ppi';
} else {
$va_dimensions[] = $va_ret['resolution'] = $va_resolution['x'].'x'.$va_resolution['y'].'ppi';
}
}
}
if (isset($va_media_info[$ps_version]['PROPERTIES']['duration']) && ($vn_duration = $va_media_info[$ps_version]['PROPERTIES']['duration'])) {
$va_dimensions[] = $va_ret['duration'] = sprintf("%4.1f", $vn_duration).'s';
}
if (isset($va_media_info[$ps_version]['PROPERTIES']['pages']) && ($vn_pages = $va_media_info[$ps_version]['PROPERTIES']['pages'])) {
$va_dimensions[] = $va_ret['pages'] = $vn_pages.' '.(($vn_pages == 1) ? _t('page') : _t('pages'));
}
if (!isset($va_media_info[$ps_version]['PROPERTIES']['filesize']) || !($vn_filesize = $va_media_info[$ps_version]['PROPERTIES']['filesize'])) {
$va_ret['filesize'] = $vn_filesize = @filesize($o_coder->getMediaPath($ps_version));
}
if ($vn_filesize) {
$va_dimensions[] = sprintf("%4.1f", $vn_filesize/(1024*1024)).'mb';
}
$va_ret['dimensions'] = join('; ', $va_dimensions);
$va_ret['MD5'] = $va_media_info[$ps_version]['MD5'];
$va_ret['mimetype'] = $va_media_info[$ps_version]['MIMETYPE'];
$va_ret['type'] = Media::getTypenameForMimetype($va_media_info[$ps_version]['MIMETYPE']);
$va_ret['filename'] = $va_media_info['ORIGINAL_FILENAME'];
$va_ret['thumbnail'] = $o_coder->getMediaTag('thumbnail');
$va_ret['info'] = $va_media_info;
return $va_ret;
}
# ------------------------------------------------------------------------------------------------
/**
* Formats extracted media metadata for display to user.
*
* @param $pa_metadata array - array key'ed by metadata system (eg. EXIF, DPX, IPTC) where values are arrays containing key/value metadata pairs
*
* @return string - formated metadata for display to user
*/
function caFormatMediaMetadata($pa_metadata) {
$vs_buf = "<table>\n";
$vn_metadata_rows = 0;
if (is_array($pa_metadata) && sizeof($pa_metadata)) {
foreach($pa_metadata as $vs_metadata_type => $va_metadata_data) {
if (isset($va_metadata_data) && is_array($va_metadata_data)) {
$vs_buf .= "<tr><th>".preg_replace('!^METADATA_!', '', $vs_metadata_type)."</th><th colspan='2'><!-- empty --></th></tr>\n";
foreach($va_metadata_data as $vs_key => $vm_value) {
$vs_buf .= "<tr valign='top'><td><!-- empty --></td><td>{$vs_key}</td><td>"._caFormatMediaMetadataArray($vm_value, 0, $vs_key)."</td></tr>\n";
$vn_metadata_rows++;
}
}
}
}
if (!$vn_metadata_rows) {
$vs_buf .= "<tr valign='top'><td colspan='3'>"._t('No embedded metadata was extracted from the media')."</td></tr>\n";
}
$vs_buf .= "</table>\n";
return $vs_buf;
}
# ------------------------------------------------------------------------------------------------
/**
* Formats extracted media metadata for display to user.
*
* @param $pa_metadata array - array key'ed by metadata system (eg. EXIF, DPX, IPTC) where values are arrays containing key/value metadata pairs
*
* @return string - formated metadata for display to user
*/
function _caFormatMediaMetadataArray($pa_array, $pn_level=0, $ps_key=null) {
if(!is_array($pa_array)) { return $pa_array; }
$vs_buf = "<div style='width: 100%; overflow: auto;'><table style='margin-left: ".($pn_level * 10)."px;'>";
foreach($pa_array as $vs_key => $vs_val) {
$vs_val = preg_replace('![^A-Za-z0-9 \-_\+\!\@\#\$\%\^\&\*\(\)\[\]\{\}\?\<\>\,\.\"\'\=]+!', '', $vs_val);
switch($vs_key) {
case 'MakerNote': // EXIF tags to skip output of
case 'ImageResourceInformation':
case 'ImageSourceData':
case 'ICC_Profile':
continue(2);
break;
}
$vs_buf .= "<tr><td width='130'>{$vs_key}</td><td>"._caFormatMediaMetadataArray($vs_val, $pn_level + 1, $vs_key)."</td></tr>";
}
$vs_buf .= "</table></div>\n";
return $vs_buf;
}
# ------------------------------------------------------------------------------------------------
/**
* Generates next/previous/back-to-results navigation HTML for bundleable editors
*
* @param $po_request RequestHTTP The current request
* @param $po_instance BaseModel An instance containing the currently edited record
* @param $po_result_context ResultContext The current result content
* @param $pa_options array An optional array of options. Supported options are:
* backText = a string to use as the "back" button text; default is "Results"
*
* @return string HTML implementing the navigation element
*/
function caEditorFindResultNavigation($po_request, $po_instance, $po_result_context, $pa_options=null) {
$vn_item_id = $po_instance->getPrimaryKey();
$vs_pk = $po_instance->primaryKey();
$vs_table_name = $po_instance->tableName();
if (($vs_priv_table_name = $vs_table_name) == 'ca_list_items') {
$vs_priv_table_name = 'ca_lists';
}
$va_found_ids = $po_result_context->getResultList();
$vn_current_pos = $po_result_context->getIndexInResultList($vn_item_id);
$vn_prev_id = $po_result_context->getPreviousID($vn_item_id);
$vn_next_id = $po_result_context->getNextID($vn_item_id);
if (isset($pa_options['backText']) && $pa_options['backText']) {
$vs_back_text = $pa_options['backText'];
} else {
$vs_back_text = "<span class='resultLink'>"._t('Results')."</span>";
}
$vs_buf = '';
if (is_array($va_found_ids) && sizeof($va_found_ids)) {
if ($vn_prev_id > 0) {
if(
$po_request->user->canAccess($po_request->getModulePath(),$po_request->getController(),"Edit",array($vs_pk => $vn_prev_id))
&&
!($po_request->getAppConfig()->get($vs_table_name.'_editor_defaults_to_summary_view'))
){
$vs_buf .= caNavLink($po_request, caNavIcon(__CA_NAV_ICON_SCROLL_LT__, 2), 'prev record', $po_request->getModulePath(), $po_request->getController(), 'Edit'.'/'.$po_request->getActionExtra(), array($vs_pk => $vn_prev_id)).' ';
} else {
$vs_buf .= caNavLink($po_request, caNavIcon(__CA_NAV_ICON_SCROLL_LT__, 2), 'prev record', $po_request->getModulePath(), $po_request->getController(), 'Summary', array($vs_pk => $vn_prev_id)).' ';
}
TooltipManager::add(".prev.record", "Previous");
} else {
$vs_buf .= '<span class="prev disabled">'.caNavIcon(__CA_NAV_ICON_SCROLL_LT__, 2).'</span>';
}
$vs_buf .= "<span class='resultCount'>".ResultContext::getResultsLinkForLastFind($po_request, $vs_table_name, $vs_back_text, ''). " (".($vn_current_pos)."/".sizeof($va_found_ids).")</span>";
if (!$vn_next_id && sizeof($va_found_ids)) { $vn_next_id = $va_found_ids[0]; }
if ($vn_next_id > 0) {
if(
$po_request->user->canAccess($po_request->getModulePath(),$po_request->getController(),"Edit",array($vs_pk => $vn_next_id))
&&
!($po_request->getAppConfig()->get($vs_table_name.'_editor_defaults_to_summary_view'))
){
$vs_buf .= ' '.caNavLink($po_request,caNavIcon(__CA_NAV_ICON_SCROLL_RT__, 2), 'next record', $po_request->getModulePath(), $po_request->getController(), 'Edit'.'/'.$po_request->getActionExtra(), array($vs_pk => $vn_next_id));
} else {
$vs_buf .= ' '.caNavLink($po_request,caNavIcon(__CA_NAV_ICON_SCROLL_RT__, 2), 'next record', $po_request->getModulePath(), $po_request->getController(), 'Summary', array($vs_pk => $vn_next_id));
}
TooltipManager::add(".next.record", "Next");
} else {
$vs_buf .= '<span class="next disabled">'.caNavIcon(__CA_NAV_ICON_SCROLL_RT__, 2).'</span>';
}
} elseif ($vn_item_id) {
$vs_buf .= "<span class='resultCount'>".ResultContext::getResultsLinkForLastFind($po_request, $vs_table_name, $vs_back_text, '')."</span>";
}
return $vs_buf;
}
# ------------------------------------------------------------------------------------------------
/**
*
*
* @param array $pa_bundle_list
* @param array $pa_options Optional array of options. Supported options are:
* NONE
*
* @return string
*/
function caSetupEditorScreenOverlays($po_request, $pt_subject, $pa_bundle_list, $pa_options=null) {
$vs_buf = '';
if ($pt_subject && $pt_subject->isHierarchical()) {
$vs_buf .= caEditorHierarchyOverview($po_request, $pt_subject->tableName(), $pt_subject->getPrimaryKey(), $pa_options);
}
$vs_buf .= caEditorFieldList($po_request, $pt_subject, $pa_bundle_list, $pa_options);
return $vs_buf;
}
# ------------------------------------------------------------------------------------------------
/**
*
*
* @param array $pa_bundle_list
* @param array $pa_options Optional array of options. Supported options are:
* NONE
*
* @return string
*/
function caEditorFieldList($po_request, $pt_subject, $pa_bundle_list, $pa_options=null) {
$vs_buf = "<script type=\"text/javascript\">
jQuery(document).on('ready', function() {
jQuery(document).on('keydown.ctrl_f', function() {
caHierarchyOverviewPanel.hidePanel({dontCloseMask:1});
caEditorFieldList.onOpenCallback = function(){
var selector = '#' + caEditorFieldList.panelID + ' a.editorFieldListLink:link';
jQuery(selector).first().focus();
};
caEditorFieldList.showPanel();
});
jQuery('#editorFieldListContentArea').html(jQuery(\"#editorFieldListHTML\").html());
jQuery('#editorFieldListContentArea a').click(function() {
caEditorFieldList.hidePanel();
});
if (typeof caBundleVisibilityManager !== 'undefined') { caBundleVisibilityManager.setAll(); }
if (typeof caBundleUpdateManager !== 'undefined') { caBundleUpdateManager = caUI.initBundleUpdateManager({url:'".caNavUrl($po_request, '*', '*', 'reload')."', screen:'".$po_request->getActionExtra()."', key:'".$pt_subject->primaryKey()."', id: ".(int)$pt_subject->getPrimaryKey()."}); }
caBundleUpdateManager.registerBundles(".json_encode($pa_bundle_list).");
});
</script>
<div id=\"editorFieldListHTML\">";
if (is_array($pa_bundle_list)) {
foreach($pa_bundle_list as $vs_anchor => $va_info) {
$vs_buf .= "<a href=\"#\" onclick=\"jQuery.scrollTo('a[name={$vs_anchor}]', {duration: 350, offset: -80 , onAfter : function(selector, data){jQuery(selector).parent('.bundleLabel').find('a:link').first().focus();}}); return false;\" class=\"editorFieldListLink\">".$va_info['name']."</a><br/>";
}
}
$vs_buf .= "</div>\n";
return $vs_buf;
}
# ------------------------------------------------------------------------------------------------
/**
*
*
* @param array $pa_bundle_list
* @param array $pa_options Optional array of options. Supported options are:
* NONE
*
* @return string
*/
function caEditorHierarchyOverview($po_request, $ps_table, $pn_id, $pa_options=null) {
$t_subject = Datamodel::getInstanceByTableName($ps_table, true);
$vs_buf = "<script type=\"text/javascript\">
jQuery(document).on('ready', function() {
jQuery(document).on('keydown.ctrl_h', function() {
caEditorFieldList.hidePanel({dontCloseMask:1});
var url;
if (jQuery('#caHierarchyOverviewContentArea').html().length == 0) {
url = '".caNavUrl($po_request, $po_request->getModulePath(), $po_request->getController(), 'getHierarchyForDisplay', array($t_subject->primaryKey() => $pn_id))."';
}
caHierarchyOverviewPanel.showPanel(url, null, false);
});
jQuery('#caHierarchyOverviewContentArea').html('');
jQuery('#caHierarchyOverviewContentArea a').click(function() {
caHierarchyOverviewPanel.hidePanel();
});
});
</script>
\n";
return $vs_buf;
}
# ------------------------------------------------------------------------------------------------
/**
* Generates standard-format inspector panels for editors
*
* @param View $po_view Inspector view object
* @param array $pa_options Optional array of options. Supported options are:
* backText = a string to use as the "back" button text; default is "Results"
*
* @return string HTML implementing the inspector
*/
function caEditorInspector($po_view, $pa_options=null) {
require_once(__CA_MODELS_DIR__.'/ca_sets.php');
require_once(__CA_MODELS_DIR__.'/ca_data_exporters.php');
$t_item = $po_view->getVar('t_item');
$vs_table_name = $t_item->tableName();
if (($vs_priv_table_name = $vs_table_name) == 'ca_list_items') {
$vs_priv_table_name = 'ca_lists';
$vs_style = "style='padding-top:10px;'";
}
$vn_item_id = $t_item->getPrimaryKey();
$o_result_context = $po_view->getVar('result_context');
$t_ui = $po_view->getVar('t_ui');
$t_type = method_exists($t_item, "getTypeInstance") ? $t_item->getTypeInstance() : null;
$vs_type_name = method_exists($t_item, "getTypeName") ? $t_item->getTypeName() : '';
if (!$vs_type_name) { $vs_type_name = $t_item->getProperty('NAME_SINGULAR'); }
if (!is_array($va_reps = $po_view->getVar('representations'))) { $va_reps = []; }
if ($t_item->isHierarchical()) {
$va_ancestors = $po_view->getVar('ancestors');
$vn_parent_id = $t_item->get($t_item->getProperty('HIERARCHY_PARENT_ID_FLD'));
} else {
$va_ancestors = array();
$vn_parent_id = null;
}
// action extra to preserve currently open screen across next/previous links
$vs_screen_extra = ($po_view->getVar('screen')) ? '/'.$po_view->getVar('screen') : '';
if (($vn_item_id) || ($po_view->request->getAction() === 'Delete')) {
$vs_buf = '<h3 class="nextPrevious" '.$vs_style.'>'.caEditorFindResultNavigation($po_view->request, $t_item, $o_result_context, $pa_options)."</h3>\n";
}
$vs_color = null;
if ($t_type) { $vs_color = trim($t_type->get('color')); }
if (!$vs_color && $t_ui) { $vs_color = trim($t_ui->get('color')); }
if (!$vs_color) { $vs_color = "FFFFFF"; }
$vs_buf .= "<h4><div id='caColorbox' style='border: 6px solid #{$vs_color};'>\n";
$vs_icon = null;
if ($t_type) { $vs_icon = $t_type->getMediaTag('icon', 'icon'); }
if (!$vs_icon && $t_ui) { $vs_icon = $t_ui->getMediaTag('icon', 'icon'); }
if ($vs_icon){
$vs_buf .= "<div id='inspectoricon' style='border-right: 6px solid #{$vs_color}; border-bottom: 6px solid #{$vs_color}; -moz-border-radius-bottomright: 8px; -webkit-border-bottom-right-radius: 8px;'>\n{$vs_icon}</div>\n";
}
if (($po_view->request->getAction() === 'Delete') && ($po_view->request->getParameter('confirm', pInteger))) {
$vs_buf .= "<strong>"._t("Deleted %1", $vs_type_name)."</strong>\n";
$vs_buf .= "<br style='clear: both;'/></div></h4>\n";
} else {
if ($vn_item_id) {
if(!$po_view->request->config->get("{$vs_priv_table_name}_inspector_disable_headline")) {
if($po_view->request->user->canDoAction("can_edit_".$vs_priv_table_name) && (sizeof($t_item->getTypeList()) > 1)){
$vs_buf .= "<strong>"._t("Editing %1", $vs_type_name).": </strong>\n";
}else{
$vs_buf .= "<strong>"._t("Viewing %1", $vs_type_name).": </strong>\n";
}
}
if ($t_item->hasField('is_deaccessioned') && $t_item->get('is_deaccessioned') && ($t_item->get('deaccession_date', array('getDirectDate' => true)) <= caDateToHistoricTimestamp(_t('now')))) {
// If currently deaccessioned then display deaccession message
$vs_buf .= "<br/><div class='inspectorDeaccessioned'>"._t('Deaccessioned %1', $t_item->get('deaccession_date'))."</div>\n";
if ($vs_deaccession_notes = $t_item->get('deaccession_notes')) { TooltipManager::add(".inspectorDeaccessioned", $vs_deaccession_notes); }
} else {
if ($po_view->request->user->canDoAction('can_see_current_location_in_inspector_ca_objects')) {
if (($t_ui && method_exists($t_item, "getObjectHistory")) && (is_array($va_placements = $t_ui->getPlacementsForBundle('ca_objects_history')) && (sizeof($va_placements) > 0))) {
//
// Output current "location" of object in life cycle. Configuration is taken from a ca_objects_history bundle configured for the current editor
//
$va_placement = array_shift($va_placements);
$va_bundle_settings = caConvertCurrentLocationCriteriaToBundleSettings(); //$va_placement['settings'];
if (is_array($va_history = $t_item->getObjectHistory($va_bundle_settings, array('limit' => 1, 'currentOnly' => true))) && (sizeof($va_history) > 0)) {
$va_current_location = array_shift(array_shift($va_history));
if(!($vs_inspector_current_location_label = $po_view->request->config->get("ca_objects_inspector_current_location_label"))) {
$vs_inspector_current_location_label = _t('Current');
}
if ($va_current_location['display']) { $vs_buf .= "<div class='inspectorCurrentLocation'><strong>".$vs_inspector_current_location_label.':</strong><br/>'.$va_current_location['display']."</div>"; }
}
} elseif (method_exists($t_item, "getLastLocationForDisplay")) {
// If no ca_objects_history bundle is configured then display the last storage location
if ($vs_current_location = $t_item->getLastLocationForDisplay("<ifdef code='ca_storage_locations.parent.preferred_labels'>^ca_storage_locations.parent.preferred_labels ➜ </ifdef>^ca_storage_locations.preferred_labels.name")) {
$vs_buf .= "<br/><div class='inspectorCurrentLocation'>"._t('Location: %1', $vs_current_location)."</div>\n";
$vs_full_location_hierarchy = $t_item->getLastLocationForDisplay("^ca_storage_locations.hierarchy.preferred_labels.name%delimiter=_➜_");
if ($vs_full_location_hierarchy !== $vs_current_location) { TooltipManager::add(".inspectorCurrentLocation", $vs_full_location_hierarchy); }
}
}
}
}
//
// Display flags; expressions for these are defined in app.conf in the <table_name>_inspector_display_flags directive
//
if (is_array($va_display_flags = $po_view->request->config->getAssoc("{$vs_table_name}_inspector_display_flags"))) {
$va_display_flag_buf = array();
foreach($va_display_flags as $vs_exp => $vs_display_flag) {
$va_exp_vars = array();
foreach(ExpressionParser::getVariableList($vs_exp) as $vs_var_name) {
$va_exp_vars[$vs_var_name] = $t_item->get($vs_var_name, array('convertCodesToIdno' => true));
}
if (ExpressionParser::evaluate($vs_exp, $va_exp_vars)) {
$va_display_flag_buf[] = $t_item->getWithTemplate("{$vs_display_flag}");
}
}
if(!($vs_display_flag_delim = $po_view->request->config->get("{$vs_table_name}_inspector_display_flags_delimiter"))) {
$vs_display_flag_delim = '; ';
}
if (sizeof($va_display_flag_buf) > 0) { $vs_buf .= join($vs_display_flag_delim, $va_display_flag_buf); }
}
$vs_label = '';
$vb_dont_use_labels_for_ca_objects = (bool)$t_item->getAppConfig()->get('ca_objects_dont_use_labels');
if(!(($vs_table_name === 'ca_objects') && $vb_dont_use_labels_for_ca_objects)){
if ($vs_get_spec = $po_view->request->config->get("{$vs_table_name}_inspector_display_title")) {
$vs_label = caProcessTemplateForIDs($vs_get_spec, $vs_table_name, array($t_item->getPrimaryKey()));
} else {
$va_object_collection_collection_ancestors = $po_view->getVar('object_collection_collection_ancestors');
if (
($t_item->tableName() == 'ca_objects') &&
$t_item->getAppConfig()->get('ca_objects_x_collections_hierarchy_enabled') &&
is_array($va_object_collection_collection_ancestors) && sizeof($va_object_collection_collection_ancestors)
) {
$va_collection_links = array();
foreach($va_object_collection_collection_ancestors as $va_collection_ancestor) {
$va_collection_links[] = caEditorLink($po_view->request, $va_collection_ancestor['label'], '', 'ca_collections', $va_collection_ancestor['collection_id']);
}
$vs_label .= join(" / ", $va_collection_links).' > ';
}
if (method_exists($t_item, 'getLabelForDisplay') && ($t_item->getLabelTableInstance())) {
$vn_parent_index = (sizeof($va_ancestors) - 1);
if ($vn_parent_id && (($vs_table_name != 'ca_places') || ($vn_parent_index > 0))) {
$va_parent = $va_ancestors[$vn_parent_index];
$vs_disp_fld = $t_item->getLabelDisplayField();
if ($va_parent['NODE'][$vs_disp_fld] && ($vs_editor_link = caEditorLink($po_view->request, $va_parent['NODE'][$vs_disp_fld], '', $vs_table_name, $va_parent['NODE'][$t_item->primaryKey()]))) {
$vs_label .= $vs_editor_link.' > '.$t_item->getLabelForDisplay();
} else {
$vs_label .= ($va_parent['NODE'][$vs_disp_fld] ? $va_parent['NODE'][$vs_disp_fld].' > ' : '').$t_item->getLabelForDisplay();
}
} else {
$vs_label .= $t_item->getLabelForDisplay();
if (($vs_table_name === 'ca_editor_uis') && (in_array($po_view->request->getAction(), array('EditScreen', 'DeleteScreen', 'SaveScreen')))) {
$t_screen = new ca_editor_ui_screens($po_view->request->getParameter('screen_id', pInteger));
if (!($vs_screen_name = $t_screen->getLabelForDisplay())) {
$vs_screen_name = _t('new screen');