@@ -28,8 +28,6 @@ class InstanceTable extends AbstractExternalModule
28
28
protected $ group_id ;
29
29
protected $ repeat_instance ;
30
30
protected $ defaultValueForNewPopup ;
31
- protected $ hideChoice ;
32
-
33
31
34
32
const ACTION_TAG = '@INSTANCETABLE ' ;
35
33
const ACTION_TAG_HIDE_FIELD = '@INSTANCETABLE_HIDE ' ;
@@ -40,11 +38,11 @@ class InstanceTable extends AbstractExternalModule
40
38
const ACTION_TAG_VARLIST = '@INSTANCETABLE_VARLIST ' ; // provide a comma-separated list of variables to include (not including any tagged HIDE)
41
39
const ACTION_TAG_PAGESIZE = '@INSTANCETABLE_PAGESIZE ' ; // Override default choices for page sizing: specify integer default page size, use -1 for All
42
40
const ACTION_TAG_REF = '@INSTANCETABLE_REF ' ;
43
- const ACTION_TAG_SRC = '@INSTANCETABLE_SRC ' ; // deprecated
41
+ const ACTION_TAG_SRC = '@INSTANCETABLE_SRC ' ; // deprecated
44
42
const ACTION_TAG_DST = '@INSTANCETABLE_DST ' ; // deprecated
45
43
const ACTION_TAG_FILTER = '@INSTANCETABLE_FILTER ' ;
46
- const ACTION_TAG_ADDBTNLABEL = '@INSTANCETABLE_ADDBTNLABEL ' ;
47
- const ACTION_TAG_HIDECHOICEVAL = '@INSTANCETABLE_HIDECHOICEVAL ' ;
44
+ const ACTION_TAG_ADDBTNLABEL = '@INSTANCETABLE_ADDBTNLABEL ' ;
45
+ const ACTION_TAG_HIDECHOICEVALUES = '@INSTANCETABLE_HIDECHOICEVALUES ' ;
48
46
const ADD_NEW_BTN_YSHIFT = '0px ' ;
49
47
const MODULE_VARNAME = 'MCRI_InstanceTable ' ;
50
48
@@ -250,33 +248,37 @@ protected function setTaggedFields() {
250
248
251
249
$ ajaxUrl = $ this ->getUrl ('instance_table_ajax.php ' );
252
250
$ filter = htmlspecialchars (str_replace ("' " ,self ::REPLQUOTE_SINGLE ,str_replace ('" ' ,self ::REPLQUOTE_DOUBLE ,$ filter )), ENT_QUOTES );
253
- $ repeatingFormDetails ['ajax_url ' ] = $ ajaxUrl ."&record= {$ this ->record }&event_id= $ eventId&form_name= $ formName&filter= $ filter&fields= " .implode ('| ' ,$ includeVars );
254
- $ repeatingFormDetails ['markup ' ] = '' ;
255
251
256
- if (preg_match ("/ " .self ::ACTION_TAG_SCROLLX ."/ " , $ fieldDetails ['field_annotation ' ], $ matches )) {
252
+ if (preg_match ("/ " .self ::ACTION_TAG_SCROLLX ."/ " , $ fieldDetails ['field_annotation ' ])) {
257
253
$ repeatingFormDetails ['scroll_x ' ] = true ;
258
254
} else {
259
255
$ repeatingFormDetails ['scroll_x ' ] = false ;
260
256
}
261
257
262
- if (preg_match ("/ " .self ::ACTION_TAG_HIDEADDBTN ."/ " , $ fieldDetails ['field_annotation ' ], $ matches )) {
258
+ if (preg_match ("/ " .self ::ACTION_TAG_HIDEADDBTN ."/ " , $ fieldDetails ['field_annotation ' ])) {
263
259
$ repeatingFormDetails ['hide_add_btn ' ] = true ;
264
260
} else {
265
261
$ repeatingFormDetails ['hide_add_btn ' ] = false ;
266
262
}
267
263
268
-
264
+ $ matches = array ();
269
265
if (preg_match ("/ " .self ::ACTION_TAG_ADDBTNLABEL ."\s*=\'([^\']+)\'/ " , $ fieldDetails ['field_annotation ' ], $ matches )) {
270
- $ value = $ matches [1 ];
271
- $ repeatingFormDetails ['button_label ' ] = $ value ;
272
- } else {
273
- $ repeatingFormDetails ['button_label ' ] = '' ;
266
+ $ repeatingFormDetails ['button_label ' ] = REDCap::filterHtml ($ matches [1 ]);
267
+ } else {
268
+ $ repeatingFormDetails ['button_label ' ] = '' ;
274
269
}
275
270
276
- if (preg_match ("/ " . self ::ACTION_TAG_HIDECHOICEVAL . "/ " , $ fieldDetails ['field_annotation ' ], $ matches )) {
277
- $ this ->hideChoice = true ;
271
+ if (preg_match ("/ " .self ::ACTION_TAG_HIDECHOICEVALUES ."/ " , $ fieldDetails ['field_annotation ' ])) {
272
+ $ hideVals = '&hide_vals=1 ' ;
273
+ $ repeatingFormDetails ['hide_choice_values ' ] = true ;
274
+ } else {
275
+ $ hideVals = '' ;
276
+ $ repeatingFormDetails ['hide_choice_values ' ] = false ;
278
277
}
279
-
278
+
279
+ $ repeatingFormDetails ['ajax_url ' ] = $ ajaxUrl ."$ hideVals&record= {$ this ->record }&event_id= $ eventId&form_name= $ formName&filter= $ filter&fields= " .implode ('| ' ,$ includeVars );
280
+ $ repeatingFormDetails ['markup ' ] = '' ;
281
+
280
282
$ this ->taggedFields [] = $ repeatingFormDetails ;
281
283
}
282
284
}
@@ -345,11 +347,12 @@ protected function makeHtmlTable($repeatingFormDetails, $canEdit) {
345
347
$ eventId = $ repeatingFormDetails ['event_id ' ];
346
348
$ formName = $ repeatingFormDetails ['form_name ' ];
347
349
$ scrollX = $ repeatingFormDetails ['scroll_x ' ];
348
- $ btnlabel = $ repeatingFormDetails ['button_label ' ];
349
350
$ linkField = $ repeatingFormDetails ['link_field ' ];
350
351
$ linkValue = $ repeatingFormDetails ['link_instance ' ];
351
352
$ filter = $ repeatingFormDetails ['filter ' ]; // The filter actually contains linkfield=linkvalue
352
353
$ varList = $ repeatingFormDetails ['var_list ' ];
354
+ $ btnLabel = ($ repeatingFormDetails ['button_label ' ]=='' ) ? $ this ->lang ['data_entry_247 ' ] : $ repeatingFormDetails ['button_label ' ];
355
+ $ hideChoiceValues = $ repeatingFormDetails ['hide_choice_values ' ];
353
356
354
357
$ scrollStyle = ($ scrollX ) ? "display:block; max-width:790px; " : "" ;
355
358
$ nColumns = 1 ; // start at 1 for # (Instance) column
@@ -374,7 +377,7 @@ protected function makeHtmlTable($repeatingFormDetails, $canEdit) {
374
377
375
378
// if survey form get data on page load (as no add/edit and have no auth for an ajax call)
376
379
if ($ this ->isSurvey ) {
377
- $ instanceData = $ this ->getInstanceData ($ this ->record , $ eventId , $ formName , $ varList , $ filter , false );
380
+ $ instanceData = $ this ->getInstanceData ($ this ->record , $ eventId , $ formName , $ varList , $ filter , false , $ hideChoiceValues );
378
381
if (count ($ instanceData ) > 0 ) {
379
382
$ html .='<tbody> ' ;
380
383
foreach ($ instanceData as $ rowValues ) {
@@ -388,20 +391,19 @@ protected function makeHtmlTable($repeatingFormDetails, $canEdit) {
388
391
$ html .='</tbody> ' ;
389
392
} else {
390
393
// $html.='<tr><td colspan="'.$nColumns.'">No data available in table</td></tr>';
391
- // unnecessary and DT does not supprt colspan in body tr // https://datatables.net/forums/discussion/32575/uncaught-typeerror-cannot-set-property-dt-cellindex-of-undefined
394
+ // unnecessary and DT does not support colspan in body tr // https://datatables.net/forums/discussion/32575/uncaught-typeerror-cannot-set-property-dt-cellindex-of-undefined
392
395
}
393
396
}
394
397
395
398
$ html .='</table> ' ;
396
-
397
- $ btnlabelval = $ btnlabel == '' ? $ this ->lang ['data_entry_247 ' ] : $ btnlabel ;
399
+
398
400
if ($ canEdit ) {
399
- $ html .='<div style="position:relative;top: ' .self ::ADD_NEW_BTN_YSHIFT .';margin-bottom:5px;"><button type="button" class="btn btn-sm btn-success " onclick=" ' .self ::MODULE_VARNAME .'.addNewInstance( \'' .$ this ->record .'\', ' .$ eventId .', \'' .$ formName .'\', \'' .$ linkField .'\', \'' .$ linkValue .'\');"><span class="fas fa-plus-circle" aria-hidden="true"></span> ' .$ btnlabelval .'</button></div> ' ; // Add new
401
+ $ html .='<div style="position:relative;top: ' .self ::ADD_NEW_BTN_YSHIFT .';margin-bottom:5px;"><button type="button" class="btn btn-sm btn-success " onclick=" ' .self ::MODULE_VARNAME .'.addNewInstance( \'' .$ this ->record .'\', ' .$ eventId .', \'' .$ formName .'\', \'' .$ linkField .'\', \'' .$ linkValue .'\');"><span class="fas fa-plus-circle mr-1 " aria-hidden="true"></span> ' .$ btnLabel .'</button></div> ' ; // Add new
400
402
}
401
403
return $ html ;
402
404
}
403
405
404
- public function getInstanceData ($ record , $ event , $ form , $ fields , $ filter , $ includeFormStatus =true ) {
406
+ public function getInstanceData ($ record , $ event , $ form , $ fields , $ filter , $ includeFormStatus =true , $ hideChoiceValues = false ) {
405
407
global $ Proj , $ lang , $ user_rights ;
406
408
$ this ->Proj = $ Proj ;
407
409
$ this ->lang = &$ lang ;
@@ -467,7 +469,7 @@ public function getInstanceData($record, $event, $form, $fields, $filter, $inclu
467
469
$ outValue = $ this ->makeFormStatusDisplay ($ value , $ record , $ event , $ form , $ instance );
468
470
469
471
} else if (in_array ($ fieldType , array ("advcheckbox " , "radio " , "select " , "checkbox " , "dropdown " , "sql " , "yesno " , "truefalse " ))) {
470
- $ outValue = $ this ->makeChoiceDisplay ($ value , $ repeatingFormFields , $ fieldName );
472
+ $ outValue = $ this ->makeChoiceDisplay ($ value , $ repeatingFormFields , $ fieldName, $ hideChoiceValues );
471
473
472
474
} else if ($ fieldType ==='text ' ) {
473
475
$ ontologyOption = $ this ->Proj ->metadata [$ fieldName ]['element_enum ' ];
@@ -484,7 +486,7 @@ public function getInstanceData($record, $event, $form, $fields, $filter, $inclu
484
486
$ outValue = $ this ->makeTextDisplay ($ value , $ repeatingFormFields , $ fieldName );
485
487
486
488
} else if ($ fieldType ==='file ' ) {
487
- $ outValue = $ this ->makeFileDisplay ($ value , $ record , $ event , $ instance , $ fieldName, $ survey_hash );
489
+ $ outValue = $ this ->makeFileDisplay ($ value , $ record , $ event , $ instance , $ fieldName );
488
490
489
491
} else {
490
492
$ outValue = htmlentities ($ value , ENT_QUOTES );
@@ -510,7 +512,7 @@ protected function makeInstanceNumDisplay($val, $record, $event, $form, $instanc
510
512
return $ this ->makeOpenPopupAnchor ($ val , $ record , $ event , $ form , $ instance );
511
513
}
512
514
513
- protected function makeFormStatusDisplay ($ val , $ record , $ event , $ form , $ instance, ) {
515
+ protected function makeFormStatusDisplay ($ val , $ record , $ event , $ form , $ instance ) {
514
516
switch ($ val ) {
515
517
case '2 ' :
516
518
$ circle = '<img src=" ' .APP_PATH_IMAGES .'circle_green.png" style="height:16px;width:16px;"> ' ;
@@ -525,7 +527,7 @@ protected function makeFormStatusDisplay($val, $record, $event, $form, $instance
525
527
return $ this ->makeOpenPopupAnchor ($ circle , $ record , $ event , $ form , $ instance );
526
528
}
527
529
528
- protected function makeChoiceDisplay ($ val , $ repeatingFormFields , $ fieldName ) {
530
+ protected function makeChoiceDisplay ($ val , $ repeatingFormFields , $ fieldName, $ hideChoiceValues = false ) {
529
531
if ($ this ->Proj ->metadata [$ fieldName ]['element_type ' ]==='sql ' ) {
530
532
$ choices = parseEnum (getSqlFieldEnum ($ this ->Proj ->metadata [$ fieldName ]['element_enum ' ]));
531
533
} else {
@@ -535,25 +537,22 @@ protected function makeChoiceDisplay($val, $repeatingFormFields, $fieldName) {
535
537
if (is_array ($ val )) {
536
538
foreach ($ val as $ valkey => $ cbval ) {
537
539
if ($ cbval ==='1 ' ) {
538
- $ val [$ valkey ] = $ this ->makeChoiceDisplayHtml ($ valkey , $ choices );
540
+ $ val [$ valkey ] = $ this ->makeChoiceDisplayHtml ($ valkey , $ choices, $ hideChoiceValues );
539
541
} else {
540
542
unset($ val [$ valkey ]);
541
543
}
542
544
}
543
545
$ outValue = implode ('<br> ' , $ val ); // multiple checkbox selections one per line
544
546
} else {
545
- $ outValue = $ this ->makeChoiceDisplayHtml ($ val , $ choices );
547
+ $ outValue = $ this ->makeChoiceDisplayHtml ($ val , $ choices, $ hideChoiceValues );
546
548
}
547
549
return REDCap::filterHtml ($ outValue );
548
550
}
549
551
550
- protected function makeChoiceDisplayHtml ($ val , $ choices )
551
- {
552
+ protected function makeChoiceDisplayHtml ($ val , $ choices , $ hideChoiceValues =false ) {
552
553
if (array_key_exists ($ val , $ choices )) {
553
- if ($ this ->hideChoice ) {
554
- return $ choices [$ val ];
555
- }
556
- return $ choices [$ val ] . ' <span class="text-muted">( ' . $ val . ')</span> ' ;
554
+ $ valDisplay = ($ hideChoiceValues ) ? '' : ' <span class="text-muted">( ' .$ val .')</span> ' ;
555
+ return $ choices [$ val ].$ valDisplay ;
557
556
}
558
557
return $ val ;
559
558
}
@@ -562,54 +561,33 @@ protected function makeTextDisplay($val, $repeatingFormFields, $fieldName) {
562
561
if (trim ($ val )=='' ) { return '' ; }
563
562
$ valType = $ repeatingFormFields [$ fieldName ]['text_validation_type_or_show_slider_number ' ];
564
563
switch ($ valType ) {
565
- case 'date_mdy ' :
566
- $ outVal = date ("m-d-Y " , strtotime ($ val ));
567
- break ;
568
- case 'date_dmy ' :
569
- $ outVal = date ("d-m-Y " , strtotime ($ val ));
570
- break ;
571
- case 'datetime_mdy ' :
572
- $ dateWithTime = date ("Y-m-d H:i " , strtotime ($ val ));
573
- if ($ dateWithTime == $ val ) {
574
- $ outVal = date ("d-m-Y H:i " , strtotime ($ val ));
575
- } else {
576
- $ outVal = date ("d-m-Y " , strtotime ($ val ));
577
- }
578
- break ;
579
- case 'datetime_dmy ' :
580
- case 'datetime_seconds_mdy ' :
581
- $ dateWithTimewiths = date ("Y-m-d H:i:s " , strtotime ($ val ));
582
- $ dateWithTime = date ("Y-m-d H:i " , strtotime ($ val ));
583
- if ($ dateWithTimewiths == $ val ) {
584
- $ outVal = date ("d-m-Y H:i:s " , strtotime ($ val ));
585
- } else if ($ dateWithTime == $ val ) {
586
- $ outVal = date ("d-m-Y H:i " , strtotime ($ val ));
587
- }else {
588
- $ outVal = date ("d-m-Y " , strtotime ($ val ));
589
- }
590
- break ;
591
- case 'datetime_seconds_dmy ' :
592
- $ outVal = DateTimeRC::datetimeConvert ($ val , 'ymd ' , substr ($ valType , -3 )); // reformat raw ymd date/datetime value to mdy or dmy, if appropriate
593
- $ outVal = $ valType ; // stick with standard ymd format for better sorting
594
- break ;
595
- case 'email ' :
596
- $ outVal = "<a href='mailto: $ val'> $ val</a> " ;
597
- break ;
598
- default :
599
- $ outVal = $ val ;
600
- break ;
564
+ case 'date_mdy ' :
565
+ case 'date_dmy ' :
566
+ case 'datetime_mdy ' :
567
+ case 'datetime_dmy ' :
568
+ case 'datetime_seconds_mdy ' :
569
+ case 'datetime_seconds_dmy ' :
570
+ $ outVal = DateTimeRC::datetimeConvert ($ val , 'ymd ' , substr ($ valType , -3 )); // reformat raw ymd date/datetime value to mdy or dmy, if appropriate
571
+ $ outVal = $ val ; // stick with standard ymd format for better sorting
572
+ break ;
573
+ case 'email ' :
574
+ $ outVal = "<a href='mailto: $ val'> $ val</a> " ;
575
+ break ;
576
+ default :
577
+ $ outVal = $ val ;
578
+ break ;
601
579
}
602
580
return REDCap::filterHtml ($ outVal );
603
581
}
604
582
605
- protected function makeFileDisplay ($ val , $ record , $ event_id , $ instance , $ fieldName, $ survey_hash ) {
606
- $ survery_hash = $ _GET [ ' s ' ];
607
- if ( $ this -> isSurvey ){
608
- $ downloadDocUrl = APP_PATH_SURVEY . "index.php?pid= " .PROJECT_ID ."&__passthru= " .urlencode ("DataEntry/file_download.php " )."&doc_id_hash= " .Files::docIdHash ($ val )."&id= $ val&s= $ survery_hash &record= $ record&event_id= $ event_id&field_name= $ fieldName&instance= $ instance " ;
609
- } else {
610
- $ downloadDocUrl = APP_PATH_WEBROOT .'DataEntry/file_download.php?pid= ' .PROJECT_ID ."&s=&record= $ record&event_id= $ event_id&instance= $ instance&field_name= $ fieldName&id= $ val&doc_id_hash= " .Files::docIdHash ($ val );
611
- }
612
- $ fileDlBtn = "<button class='btn btn-defaultrc btn-xs' style='font-size:8pt;' onclick= \"window.open(' $ downloadDocUrl','_blank');return false; \"> {$ this ->lang ['design_121 ' ]}</button> " ;
583
+ protected function makeFileDisplay ($ val , $ record , $ event_id , $ instance , $ fieldName ) {
584
+ if ( $ this -> isSurvey ) {
585
+ $ surveyHash = REDCap:: filterHtml ( $ _GET [ ' s ' ]);
586
+ $ downloadDocUrl = APP_PATH_SURVEY . "index.php?pid= " .PROJECT_ID ."&__passthru= " .urlencode ("DataEntry/file_download.php " )."&doc_id_hash= " .Files::docIdHash ($ val )."&id= $ val&s= $ surveyHash &record= $ record&event_id= $ event_id&field_name= $ fieldName&instance= $ instance " ;
587
+ } else {
588
+ $ downloadDocUrl = APP_PATH_WEBROOT .'DataEntry/file_download.php?pid= ' .PROJECT_ID ."&s=&record= $ record&event_id= $ event_id&instance= $ instance&field_name= $ fieldName&id= $ val&doc_id_hash= " .Files::docIdHash ($ val );
589
+ }
590
+ $ fileDlBtn = "<button class='btn btn-defaultrc btn-xs' style='font-size:8pt;' onclick= \"window.open(' $ downloadDocUrl','_blank');return false; \"> {$ this ->lang ['design_121 ' ]}</button> " ;
613
591
return str_replace ('removed= ' ,'onclick= ' ,REDCap::filterHtml ($ fileDlBtn ));
614
592
}
615
593
@@ -882,7 +860,7 @@ function(){
882
860
* - Augment the action_tag_explain content on project Design pages by adding some additional tr following the last built-in action tag.
883
861
* @param type $project_id
884
862
*/
885
- public function redcap_every_page_before_render ($ project_id ) {
863
+ public function redcap_every_page_before_render ($ project_id ) {
886
864
if (isset ($ _POST ['extmod_closerec_home ' ])) {
887
865
$ _SESSION ['extmod_closerec_home ' ] = $ _POST ['extmod_closerec_home ' ];
888
866
0 commit comments