Skip to content

Commit bfa2ea1

Browse files
committed
Merge branch 'support/2.14.0' into develop
2 parents 5e068eb + a2f7d09 commit bfa2ea1

59 files changed

Lines changed: 959 additions & 594 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 9 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -31,51 +31,18 @@
3131

3232
include ('../../../inc/includes.php');
3333

34-
Session::checkRight(PluginFormcreatorForm::$rightname, UPDATE);
35-
3634
// Check if plugin is activated...
3735
if (!(new Plugin())->isActivated('formcreator')) {
38-
Html::displayNotFoundError();
39-
}
40-
41-
// Get target form
42-
$form_id = $_POST[PluginFormcreatorForm::getForeignKeyField()] ?? null;
43-
if (is_null($form_id)) {
44-
Html::displayNotFoundError();
45-
}
46-
47-
// No update if `access_rights` is not modified, keeping the save behavior as
48-
// the previous form_profile.form.php file
49-
if (!isset($_POST['access_rights'])) {
50-
Html::back();
51-
die;
36+
http_response_code(404);
37+
die();
5238
}
5339

54-
// Try to load form
55-
$form = PluginFormcreatorForm::getById($form_id);
56-
if (!$form) {
57-
Html::displayNotFoundError();
40+
if (!isset($_REQUEST['itemtype']) || !isset($_REQUEST['items_id']) || !isset($_REQUEST['action'])) {
41+
http_response_code(500);
42+
die();
5843
}
5944

60-
// Prepare input
61-
$input = [
62-
'id' => (int) $form_id,
63-
'is_captcha_enabled' => $_POST['is_captcha_enabled'] ?? false,
64-
'access_rights' => (int) $_POST['access_rights'],
65-
'users' => [],
66-
'groups' => [],
67-
'profiles' => [],
68-
'entities' => [],
69-
];
70-
71-
$restrictions = $_POST['restrictions'] ?? null;
72-
if (!is_null($restrictions)) {
73-
$input['users'] = AbstractRightsDropdown::getPostedIds($restrictions, User::class);
74-
$input['groups'] = AbstractRightsDropdown::getPostedIds($restrictions, Group::class);
75-
$input['profiles'] = AbstractRightsDropdown::getPostedIds($restrictions, Profile::class);
76-
}
77-
78-
// Update form
79-
$form->update($input);
80-
81-
Html::back();
45+
Session::checkRight('entity', UPDATE);
46+
if (!(new PluginFormcreatorForm())->duplicateTarget($_REQUEST)) {
47+
http_response_code(500);
48+
}

ajax/formanswer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
die();
3838
}
3939

40-
if (!isset($_POST['submit_formcreator']) || !isset($_POST['plugin_formcreator_forms_id'])) {
40+
if (!isset($_POST['add']) || !isset($_POST['plugin_formcreator_forms_id'])) {
4141
http_response_code(500);
4242
die();
4343
}
Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,25 +29,26 @@
2929
* ---------------------------------------------------------------------
3030
*/
3131

32+
use Glpi\Application\View\TemplateRenderer;
33+
3234
include ('../../../inc/includes.php');
3335

3436
// Check if plugin is activated...
3537
if (!Plugin::isPluginActive('formcreator')) {
3638
http_response_code(404);
3739
die();
3840
}
39-
$form_fk = PluginFormcreatorForm::getForeignKeyField();
40-
if (!isset($_POST['access_rights']) || !isset($_POST['extraparams'][$form_fk])) {
41-
http_response_code(400);
41+
42+
if (!Session::haveRight(PluginFormcreatorForm::$rightname, UPDATE)) {
43+
http_response_code(403);
4244
die();
4345
}
4446

45-
$form = PluginFormcreatorForm::getById($_POST['extraparams'][$form_fk]);
46-
if (!($form instanceof PluginFormcreatorForm)) {
47+
if (!isset($_POST['itemtype'])) {
4748
http_response_code(400);
4849
die();
4950
}
5051

51-
/** @var PluginFormcreatorForm $form */
52-
$form->fields['access_rights'] = $_POST['access_rights'];
53-
PluginFormcreatorFormAccessType::showAccessTypeOption($form);
52+
TemplateRenderer::getInstance()->display('@formcreator/components/form/form_validator.validator_type.html.twig', [
53+
'type' => $_POST['itemtype'],
54+
]);

ajax/homepage_wizard.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,15 @@
3535
exit;
3636
}
3737

38+
if (!isset($_REQUEST['wizard'])) {
39+
http_response_code(400);
40+
die();
41+
}
42+
3843
if ($_REQUEST['wizard'] == 'categories') {
3944
plugin_formcreator_showWizardCategories();
4045
} else if ($_REQUEST['wizard'] == 'forms') {
41-
if (isset($_REQUEST['categoriesId'])) {
42-
$categoriesId = (int) $_REQUEST['categoriesId'];
43-
} else {
44-
$categoriesId = 0;
45-
}
46+
$categoriesId = (int) ($_REQUEST['categoriesId'] ?? 0);
4647
$keywords = isset($_REQUEST['keywords']) ? $_REQUEST['keywords'] : '';
4748
$helpdeskHome = isset($_REQUEST['helpdeskHome']) ? $_REQUEST['helpdeskHome'] != '0' : false;
4849
plugin_formcreator_showWizardForms($categoriesId, $keywords, $helpdeskHome);

ajax/section_update.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,4 @@
5050
Session::addMessageAfterRedirect(__('Could not update the section', 'formcreator'), false, ERROR);
5151
exit;
5252
}
53-
echo json_encode(['id' => $section->getID(), 'name' => $section->fields['name']], JSON_UNESCAPED_UNICODE);
53+
echo json_encode(['id' => $section->getID(), 'name' => $section->getDesignLabel()], JSON_UNESCAPED_UNICODE);

hook.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -436,9 +436,10 @@ function plugin_formcreator_MassiveActions($itemtype) {
436436
switch ($itemtype) {
437437
case PluginFormcreatorForm::class:
438438
return [
439-
'PluginFormcreatorForm' . MassiveAction::CLASS_ACTION_SEPARATOR . 'Duplicate' => _x('button', 'Duplicate'),
440-
'PluginFormcreatorForm' . MassiveAction::CLASS_ACTION_SEPARATOR . 'Transfert' => __('Transfer'),
441-
'PluginFormcreatorForm' . MassiveAction::CLASS_ACTION_SEPARATOR . 'Export' => _sx('button', 'Export'),
439+
PluginFormcreatorForm::class . MassiveAction::CLASS_ACTION_SEPARATOR . 'Duplicate' => _x('button', 'Duplicate'),
440+
PluginFormcreatorForm::class . MassiveAction::CLASS_ACTION_SEPARATOR . 'Transfert' => __('Transfer'),
441+
PluginFormcreatorForm::class . MassiveAction::CLASS_ACTION_SEPARATOR . 'Export' => _sx('button', 'Export'),
442+
PluginFormcreatorForm::class . MassiveAction::CLASS_ACTION_SEPARATOR . 'AccessRights' => _sx('button', 'Access rights'),
442443
];
443444
}
444445
return [];
@@ -878,4 +879,4 @@ function plugin_formcreator_transfer(array $options) {
878879
'tickets_id' => $options['newID'],
879880
]);
880881
}
881-
}
882+
}

inc/abstractfield.class.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,4 +374,15 @@ public function getTranslatableStrings(array $options = []) : array {
374374

375375
return $strings;
376376
}
377+
378+
/**
379+
* Translates the label of the field into the current language
380+
*
381+
* @return string
382+
*/
383+
protected function getTtranslatedLabel(): string {
384+
$form = PluginFormcreatorForm::getByItem($this->question);
385+
$domain = PluginFormcreatorForm::getTranslationDomain($form->getID());
386+
return __($this->getLabel(), $domain);
387+
}
377388
}

inc/abstractitiltarget.class.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2379,6 +2379,11 @@ public function getDefaultData(PluginFormcreatorFormAnswer $formanswer): array {
23792379
}
23802380

23812381
$data = array_merge($data, $predefined_fields);
2382+
2383+
if (($data['requesttypes_id'] ?? 0) == 0) {
2384+
unset($data['requesttypes_id']);
2385+
}
2386+
23822387
return $data;
23832388
}
23842389

@@ -2639,4 +2644,16 @@ protected function setTargetSuppliers(array $data, PluginFormcreatorFormAnswer $
26392644
return $data;
26402645
}
26412646

2647+
public function getCloneRelations(): array {
2648+
return [
2649+
PluginFormcreatorTarget_Actor::class,
2650+
PluginFormcreatorCondition::class,
2651+
];
2652+
}
2653+
2654+
public function prepareInputForClone($input) {
2655+
$input = parent::prepareInputForClone($input);
2656+
$input['_skip_create_actors'] = true;
2657+
return $input;
2658+
}
26422659
}

inc/abstracttarget.class.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
*/
3232

3333
use Glpi\Application\View\TemplateRenderer;
34-
use Glpi\Toolbox\Sanitizer;
34+
use \Glpi\Features\Clonable;
3535

3636
if (!defined('GLPI_ROOT')) {
3737
die("Sorry. You can't access this file directly");
@@ -43,6 +43,7 @@ abstract class PluginFormcreatorAbstractTarget extends CommonDBChild implements
4343
PluginFormcreatorConditionnableInterface,
4444
PluginFormcreatorTranslatableInterface
4545
{
46+
use Clonable;
4647
use PluginFormcreatorConditionnableTrait;
4748
use PluginFormcreatorExportableTrait;
4849
use PluginFormcreatorTranslatable;
@@ -552,4 +553,9 @@ protected function showDestinationEntitySetings($rand) {
552553
echo '</td>';
553554
echo '</tr>';
554555
}
556+
557+
public function prepareInputForClone($input) {
558+
unset($input['uuid']);
559+
return $input;
560+
}
555561
}

inc/category.class.php

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -117,15 +117,20 @@ public static function getCategoryTree(): array {
117117

118118
$cat_table = PluginFormcreatorCategory::getTable();
119119
$form_table = PluginFormcreatorForm::getTable();
120+
$knowbaseitems_knowbaseitemcategories_table = KnowbaseItem_KnowbaseItemCategory::getTable();
121+
122+
if (version_compare(GLPI_VERSION, '10.0.6') > 0) {
123+
$knowbase_category = KnowbaseItemCategory::SEEALL;
124+
} else {
125+
$knowbase_category = 0;
126+
}
120127

121128
$query_faqs = KnowbaseItem::getListRequest([
122129
'faq' => '1',
123130
'contains' => '',
124-
'knowbaseitemcategories_id' => 0,
131+
'knowbaseitemcategories_id' => $knowbase_category,
125132
]);
126-
// GLPI 9.5 returns an array
127-
$subQuery = new DBMysqlIterator($DB);
128-
$subQuery->buildQuery($query_faqs);
133+
$query_faqs['SELECT'] = [$query_faqs['FROM'] . '.' . 'id'];
129134

130135
$dbUtils = new DbUtils();
131136
$entityRestrict = $dbUtils->getEntitiesRestrictCriteria($form_table, "", "", true, false);
@@ -139,18 +144,15 @@ public static function getCategoryTree(): array {
139144
// Get base query, add count and category condition
140145
$count_forms_criteria = PluginFormcreatorForm::getFormListQuery();
141146
$count_forms_criteria['COUNT'] = 'count';
142-
$count_forms_criteria['WHERE']["$form_table.$categoryFk"] = new QueryExpression("$cat_table.id");
147+
$count_forms_criteria['WHERE']["`$form_table`.`$categoryFk`"] = new QueryExpression("`$cat_table`.`id`");
143148

144149
$count1 = new QuerySubQuery($count_forms_criteria);
145150
$count2 = new QuerySubQuery([
146151
'COUNT' => 'count',
147-
'FROM' => 'glpi_knowbaseitems_knowbaseitemcategories',
152+
'FROM' => $knowbaseitems_knowbaseitemcategories_table,
148153
'WHERE' => [
149-
'knowbaseitems_id' => new QuerySubQuery([
150-
'SELECT' => 'faqs.id',
151-
'FROM' => (new QuerySubQuery($query_faqs, 'faqs'))
152-
]),
153-
[(new QueryExpression("knowbaseitemcategories_id = $cat_table.knowbaseitemcategories_id"))],
154+
'knowbaseitems_id' => new QuerySubQuery($query_faqs),
155+
[(new QueryExpression("`$knowbaseitems_knowbaseitemcategories_table`.`knowbaseitemcategories_id` = `$cat_table`.`knowbaseitemcategories_id`"))],
154156
]
155157
]);
156158
$request = [

0 commit comments

Comments
 (0)