@@ -94,12 +94,6 @@ public function canPurgeItem() {
94
94
return Session::haveRight ('entity ' , UPDATE );
95
95
}
96
96
97
- /**
98
- * Returns the type name with consideration of plural
99
- *
100
- * @param number $nb Number of item(s)
101
- * @return string Itemtype name
102
- */
103
97
public static function getTypeName ($ nb = 0 ) {
104
98
return _n ('Form ' , 'Forms ' , $ nb , 'formcreator ' );
105
99
}
@@ -403,8 +397,6 @@ public static function getSpecificValueToDisplay($field, $values, array $options
403
397
* @return NULL Nothing, just display the form
404
398
*/
405
399
public function showForm ($ ID , $ options = []) {
406
- global $ DB ;
407
-
408
400
$ this ->initForm ($ ID , $ options );
409
401
$ this ->showFormHeader ($ options );
410
402
@@ -472,163 +464,6 @@ public function showForm($ID, $options = []) {
472
464
echo '</td> ' ;
473
465
echo '</tr> ' ;
474
466
475
- echo '<tr class="tab_bg_2"> ' ;
476
- echo '<td> ' . __ ('Need to be validate? ' , 'formcreator ' ) . '</td> ' ;
477
- echo '<td class="validators_bloc"> ' ;
478
-
479
- Dropdown::showFromArray ('validation_required ' , [
480
- self ::VALIDATION_NONE => Dropdown::EMPTY_VALUE ,
481
- self ::VALIDATION_USER => User::getTypeName (1 ),
482
- self ::VALIDATION_GROUP => Group::getTypeName (1 ),
483
- ], [
484
- 'value ' => $ this ->fields ['validation_required ' ],
485
- 'on_change ' => 'plugin_formcreator_changeValidators(this.value) '
486
- ]);
487
- echo '</td> ' ;
488
- echo '<td colspan="2"> ' ;
489
- // Select all users with ticket validation right and the groups
490
- $ userTable = User::getTable ();
491
- $ userFk = User::getForeignKeyField ();
492
- $ groupTable = Group::getTable ();
493
- $ groupFk = Group::getForeignKeyField ();
494
- $ profileUserTable = Profile_User::getTable ();
495
- $ profileTable = Profile::getTable ();
496
- $ profileFk = Profile::getForeignKeyField ();
497
- $ profileRightTable = ProfileRight::getTable ();
498
- $ groupUserTable = Group_User::getTable ();
499
- $ subQuery = [
500
- 'SELECT ' => "$ profileUserTable. $ userFk " ,
501
- 'FROM ' => $ profileUserTable ,
502
- 'INNER JOIN ' => [
503
- $ profileTable => [
504
- 'FKEY ' => [
505
- $ profileTable => 'id ' ,
506
- $ profileUserTable => $ profileFk ,
507
- ]
508
- ],
509
- $ profileRightTable =>[
510
- 'FKEY ' => [
511
- $ profileTable => 'id ' ,
512
- $ profileRightTable => $ profileFk ,
513
- ]
514
- ],
515
- ],
516
- 'WHERE ' => [
517
- "$ profileRightTable.name " => "ticketvalidation " ,
518
- [
519
- 'OR ' => [
520
- "$ profileRightTable.rights " => ['& ' , TicketValidation::VALIDATEREQUEST ],
521
- "$ profileRightTable.rights " => ['& ' , TicketValidation::VALIDATEINCIDENT ],
522
- ],
523
- ],
524
- "$ userTable.is_active " => '1 ' ,
525
- ],
526
- ];
527
- $ usersCondition = [
528
- "$ userTable.id " => new QuerySubquery ($ subQuery )
529
- ];
530
- $ formValidator = new PluginFormcreatorForm_Validator ();
531
- $ selectedValidatorUsers = [];
532
- foreach ($ formValidator ->getValidatorsForForm ($ this , User::class) as $ user ) {
533
- $ selectedValidatorUsers [$ user ->getID ()] = $ user ->getID ();
534
- }
535
- $ users = $ DB ->request ([
536
- 'SELECT ' => ['id ' , 'name ' ],
537
- 'FROM ' => User::getTable (),
538
- 'WHERE ' => $ usersCondition ,
539
- ]);
540
- $ validatorUsers = [];
541
- foreach ($ users as $ user ) {
542
- $ validatorUsers [$ user ['id ' ]] = $ user ['name ' ];
543
- }
544
- echo '<div id="validators_users"> ' ;
545
- echo User::getTypeName () . '  ' ;
546
- Dropdown::showFromArray (
547
- '_validator_users ' ,
548
- $ validatorUsers , [
549
- 'multiple ' => true ,
550
- 'values ' => $ selectedValidatorUsers
551
- ]
552
- );
553
- echo '</div> ' ;
554
-
555
- // Validators groups
556
- $ subQuery = [
557
- 'SELECT ' => "$ groupUserTable. $ groupFk " ,
558
- 'FROM ' => $ groupUserTable ,
559
- 'INNER JOIN ' => [
560
- $ userTable => [
561
- 'FKEY ' => [
562
- $ groupUserTable => $ userFk ,
563
- $ userTable => 'id ' ,
564
- ]
565
- ],
566
- $ profileUserTable => [
567
- 'FKEY ' => [
568
- $ profileUserTable => $ userFk ,
569
- $ userTable => 'id ' ,
570
- ],
571
- ],
572
- $ profileTable => [
573
- 'FKEY ' => [
574
- $ profileTable => 'id ' ,
575
- $ profileUserTable => $ profileFk ,
576
- ]
577
- ],
578
- $ profileRightTable =>[
579
- 'FKEY ' => [
580
- $ profileTable => 'id ' ,
581
- $ profileRightTable => $ profileFk ,
582
- ]
583
- ],
584
- ],
585
- 'WHERE ' => [
586
- "$ groupUserTable. $ userFk " => new QueryExpression ("` $ userTable`.`id` " ),
587
- "$ profileRightTable.name " => "ticketvalidation " ,
588
- [
589
- 'OR ' => [
590
- "$ profileRightTable.rights " => ['& ' , TicketValidation::VALIDATEREQUEST ],
591
- "$ profileRightTable.rights " => ['& ' , TicketValidation::VALIDATEINCIDENT ],
592
- ],
593
- ],
594
- "$ userTable.is_active " => '1 ' ,
595
- ],
596
- ];
597
- $ groupsCondition = [
598
- "$ groupTable.id " => new QuerySubquery ($ subQuery ),
599
- ];
600
- $ groups = $ DB ->request ([
601
- 'SELECT ' => ['id ' ,'name ' ],
602
- 'FROM ' => Group::getTable (),
603
- 'WHERE ' => $ groupsCondition ,
604
- ]);
605
- $ formValidator = new PluginFormcreatorForm_Validator ();
606
- $ selectecValidatorGroups = [];
607
- foreach ($ formValidator ->getValidatorsForForm ($ this , Group::class) as $ group ) {
608
- $ selectecValidatorGroups [$ group ->getID ()] = $ group ->getID ();
609
- }
610
- $ validatorGroups = [];
611
- foreach ($ groups as $ group ) {
612
- $ validatorGroups [$ group ['id ' ]] = $ group ['name ' ];
613
- }
614
- echo '<div id="validators_groups" style="width: 100%"> ' ;
615
- echo Group::getTypeName () . '  ' ;
616
- Dropdown::showFromArray (
617
- '_validator_groups ' ,
618
- $ validatorGroups ,
619
- [
620
- 'multiple ' => true ,
621
- 'values ' => $ selectecValidatorGroups
622
- ]
623
- );
624
- echo '</div> ' ;
625
-
626
- $ script = '$(document).ready(function() {plugin_formcreator_changeValidators( ' . $ this ->fields ["validation_required " ] . ');}); ' ;
627
- echo Html::scriptBlock ($ script );
628
-
629
- echo '</td> ' ;
630
- echo '</tr> ' ;
631
-
632
467
echo '<tr> ' ;
633
468
echo '<td> ' .__ ('Default form in service catalog ' , 'formcreator ' ).'</td> ' ;
634
469
echo '<td> ' ;
@@ -762,6 +597,7 @@ public static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $
762
597
public function defineTabs ($ options = []) {
763
598
$ ong = [];
764
599
$ this ->addDefaultFormTab ($ ong );
600
+ $ this ->addStandardTab (PluginFormcreatorForm_Validator::class, $ ong , $ options );
765
601
$ this ->addStandardTab (PluginFormcreatorQuestion::class, $ ong , $ options );
766
602
$ this ->addStandardTab (PluginFormcreatorForm_Profile::class, $ ong , $ options );
767
603
$ this ->addStandardTab (__CLASS__ , $ ong , $ options );
@@ -1336,38 +1172,7 @@ public function displayUserForm() : void {
1336
1172
1337
1173
// Show validator selector
1338
1174
if ($ this ->fields ['validation_required ' ] != PluginFormcreatorForm_Validator::VALIDATION_NONE ) {
1339
- $ validators = [];
1340
- $ formValidator = new PluginFormcreatorForm_Validator ();
1341
- switch ($ this ->fields ['validation_required ' ]) {
1342
- case PluginFormcreatorForm_Validator::VALIDATION_GROUP :
1343
- $ validatorType = Group::class;
1344
- $ result = $ formValidator ->getValidatorsForForm ($ this , $ validatorType );
1345
- foreach ($ result as $ validator ) {
1346
- $ validators [$ validator ->getID ()] = $ validator ->fields ['completename ' ];
1347
- }
1348
- break ;
1349
- case PluginFormcreatorForm_Validator::VALIDATION_USER :
1350
- $ validatorType = User::class;
1351
- $ result = $ formValidator ->getValidatorsForForm ($ this , $ validatorType );
1352
- foreach ($ result as $ validator ) {
1353
- $ validators [$ validator ->getID ()] = formatUserName ($ validator ->getID (), $ validator ->fields ['name ' ], $ validator ->fields ['realname ' ], $ validator ->fields ['firstname ' ]);
1354
- }
1355
- break ;
1356
- }
1357
-
1358
- $ resultCount = count ($ result );
1359
- if ($ resultCount == 1 ) {
1360
- reset ($ validators );
1361
- $ validatorId = key ($ validators );
1362
- echo Html::hidden ('formcreator_validator ' , ['value ' => $ validatorId ]);
1363
- } else if ($ resultCount > 1 ) {
1364
- $ validators = [0 => Dropdown::EMPTY_VALUE ] + $ validators ;
1365
- echo '<h2> ' . __ ('Validation ' , 'formcreator ' ) . '</h2> ' ;
1366
- echo '<div class="form-group required liste" id="form-validator"> ' ;
1367
- echo '<label> ' . __ ('Choose a validator ' , 'formcreator ' ) . ' <span class="red">*</span></label> ' ;
1368
- Dropdown::showFromArray ('formcreator_validator ' , $ validators );
1369
- echo '</div> ' ;
1370
- }
1175
+ echo PluginFormcreatorForm_Validator::dropdownValidator ($ this );
1371
1176
}
1372
1177
1373
1178
echo Html::scriptBlock ('$(function() {
0 commit comments