Skip to content

Commit 309e7e4

Browse files
committed
fix(wizard): various errors displaying forms in service catalog
Signed-off-by: Thierry Bugier <[email protected]>
1 parent 1697b7b commit 309e7e4

File tree

5 files changed

+60
-27
lines changed

5 files changed

+60
-27
lines changed

ajax/homepage_wizard.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@
3636
}
3737

3838
if ($_REQUEST['wizard'] == 'categories') {
39-
plugin_formcreator_showWizardCategories(plugin_formcreator_replaceHelpdesk());
39+
plugin_formcreator_showWizardCategories();
4040
} else if ($_REQUEST['wizard'] == 'forms') {
4141
if (isset($_REQUEST['categoriesId'])) {
42-
$categoriesId = intval($_REQUEST['categoriesId']);
42+
$categoriesId = (int) $_REQUEST['categoriesId'];
4343
} else {
4444
$categoriesId = 0;
4545
}
@@ -52,8 +52,8 @@
5252
: true;
5353
}
5454

55-
function plugin_formcreator_showWizardCategories($helpdesk = true) {
56-
$tree = PluginFormcreatorCategory::getCategoryTree(0, $helpdesk);
55+
function plugin_formcreator_showWizardCategories($helpdeskHome = false) {
56+
$tree = PluginFormcreatorCategory::getCategoryTree(0, $helpdeskHome);
5757
echo json_encode($tree, JSON_UNESCAPED_SLASHES);
5858
}
5959

inc/category.class.php

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,46 @@ public static function getCategoryTree($rootId = 0, $helpdeskHome = false) {
9494
]);
9595

9696
// Selects categories containing forms or sub-categories
97+
// $subQuery = [];
98+
// $subQuery[] = new QuerySubQuery([
99+
// 'COUNT' => 'count',
100+
// 'FROM' => $form_table,
101+
// 'WHERE' => [
102+
// "AND" => [
103+
// "$form_table.is_active" => '1',
104+
// "$form_table.is_deleted" => '0',
105+
// "$form_table.plugin_formcreator_categories_id" => $cat_table."id",
106+
// "$form_table.language" => [$_SESSION['glpilanguage'], '', '0', null],
107+
// 'OR' => [
108+
// 'access_rights' => ['!=', PluginFormcreatorForm::ACCESS_RESTRICTED],
109+
// "$form_table.id" => new QuerySubQuery([
110+
// 'SELECT' => 'plugin_formcreator_forms_id',
111+
// 'FROM' => $table_fp,
112+
// 'WHERE' => [
113+
// 'profiles_id' => $_SESSION['glpiactiveprofile']['id']
114+
// ]
115+
// ])
116+
// ]
117+
// ]
118+
// + $dbUtils->getEntitiesRestrictCriteria($form_table, "", "", true, false)
119+
// + ($helpdeskHome ? ["$form_table.helpdesk_home" => '1'] : [])
120+
// ],
121+
// ]);
122+
// $subQuery[] = new QuerySubQuery([
123+
// 'COUNT' => 'count',
124+
// 'FROM' => "$cat_table AS cat2",
125+
// 'WHERE' => [
126+
// new QueryExpression("`cat2`.`plugin_formcreator_categories_id`=`$cat_table`.`id`"),
127+
// ],
128+
// ]);
129+
// $subQuery[] = new QuerySubQuery([
130+
// 'COUNT' => 'count',
131+
// 'FROM' => "$cat_table AS cat2",
132+
// 'WHERE' => [
133+
// new QueryExpression("`cat2`.`plugin_formcreator_categories_id`=`$cat_table`.`id`"),
134+
// ],
135+
// ]);
136+
// TODO: To solve the 3rd OR for faq count
97137
$where = "(SELECT COUNT($form_table.id)
98138
FROM $form_table
99139
WHERE $form_table.`plugin_formcreator_categories_id` = $cat_table.`id`

inc/form.class.php

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -758,7 +758,6 @@ public function showFormList($rootCategory = 0, $keywords = '', $helpdeskHome =
758758
$table_cat = getTableForItemType('PluginFormcreatorCategory');
759759
$table_form = getTableForItemType('PluginFormcreatorForm');
760760
$table_fp = getTableForItemType('PluginFormcreatorForm_Profile');
761-
$table_target = getTableForItemType('PluginFormcreatorTargets');
762761
$table_section = getTableForItemType('PluginFormcreatorSections');
763762
$table_question= getTableForItemType('PluginFormcreatorQuestions');
764763

@@ -769,8 +768,8 @@ public function showFormList($rootCategory = 0, $keywords = '', $helpdeskHome =
769768
'AND' => [
770769
"$table_form.is_active" => '1',
771770
"$table_form.is_deleted" => '0',
772-
"$table_form.language" => [$_SESSION['glpilanguage'], '0', null],
773-
] + $dbUtils->getEntitiesRestrictCriteria($table_form, '', '', true, false),
771+
"$table_form.language" => [$_SESSION['glpilanguage'], '0', '', null],
772+
] + $dbUtils->getEntitiesRestrictCriteria($table_form, '', '', true, false)
774773
];
775774
if ($helpdeskHome) {
776775
$where_form['AND']["$table_form.helpdesk_home"] = '1';
@@ -779,7 +778,7 @@ public function showFormList($rootCategory = 0, $keywords = '', $helpdeskHome =
779778
$selectedCategories = [];
780779
if ($rootCategory != 0) {
781780
$selectedCategories = getSonsOf($table_cat, $rootCategory);
782-
$where_form['AND']["$table_form.plugin_formcreator_categories_id"] = [$selectedCategories];
781+
$where_form['AND']["$table_form.plugin_formcreator_categories_id"] = $selectedCategories;
783782
}
784783

785784
// Find forms accessible by the current user
@@ -807,13 +806,9 @@ public function showFormList($rootCategory = 0, $keywords = '', $helpdeskHome =
807806
$where_form['AND'][] = [
808807
'OR' => [
809808
'access_rights' => ['!=', PluginFormcreatorForm::ACCESS_RESTRICTED],
810-
"$table_form.id" => new QuerySubQuery([
811-
'SELECT' => 'plugin_formcreator_forms_id',
812-
'FROM' => $table_fp,
813-
'WHERE' => [
814-
'profiles_id' => $_SESSION['glpiactiveprofile']['id']
815-
]
816-
])
809+
[
810+
"$table_fp.profiles_id" => $_SESSION['glpiactiveprofile']['id']
811+
]
817812
]
818813
];
819814

@@ -829,12 +824,6 @@ public function showFormList($rootCategory = 0, $keywords = '', $helpdeskHome =
829824
$table_form => PluginFormcreatorCategory::getForeignKeyField(),
830825
]
831826
],
832-
$table_target => [
833-
'FKEY' => [
834-
$table_target => PluginFormcreatorForm::getForeignKeyField(),
835-
$table_form => 'id',
836-
]
837-
],
838827
$table_section => [
839828
'FKEY' => [
840829
$table_section => PluginFormcreatorForm::getForeignKeyField(),
@@ -846,11 +835,16 @@ public function showFormList($rootCategory = 0, $keywords = '', $helpdeskHome =
846835
$table_question => PluginFormcreatorSection::getForeignKeyField(),
847836
$table_section => 'id'
848837
]
838+
],
839+
$table_fp => [
840+
'FKEY' => [
841+
$table_fp => PluginFormcreatorForm::getForeignKeyField(),
842+
$table_form => 'id',
843+
]
849844
]
850845
],
851846
'WHERE' => $where_form,
852847
'GROUPBY' => [
853-
"$table_target.plugin_formcreator_forms_id",
854848
"$table_form.id",
855849
"$table_form.name",
856850
"$table_form.description",
@@ -864,7 +858,6 @@ public function showFormList($rootCategory = 0, $keywords = '', $helpdeskHome =
864858

865859
$formList = [];
866860
if ($result_forms->count() > 0) {
867-
// while ($form = $DB->fetch_array($result_forms)) {
868861
foreach ($result_forms as $form) {
869862
$formList[] = [
870863
'id' => $form['id'],
@@ -933,7 +926,8 @@ public function showFormList($rootCategory = 0, $keywords = '', $helpdeskHome =
933926
'AND' => [
934927
"$table_form.is_active" => '1',
935928
"$table_form.is_deleted" => '0',
936-
"$table_form.language" => [$_SESSION['glpilanguage'], '0', null],
929+
"$table_form.language" => [$_SESSION['glpilanguage'], '0', '', null],
930+
"$table_form.is_default" => ['<>', '0']
937931
] + $dbUtils->getEntitiesRestrictCriteria($table_form, '', '', true, false),
938932
];
939933
$where_form['AND'][] = [

js/scripts.js.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
var currentCategory = "0";
3939
var sortByName = false;
4040
var tiles = [];
41-
var helpdeskHome = 0;
4241
var serviceCatalogEnabled = false;
4342
var slinkyCategories;
4443
var timers = [];
@@ -257,7 +256,7 @@ function getFormAndFaqItems(categoryId) {
257256
deferred = jQuery.Deferred();
258257
$.ajax({
259258
url: rootDoc + '/plugins/formcreator/ajax/homepage_wizard.php',
260-
data: {wizard: 'forms', categoriesId: categoryId, keywords: keywords, helpdeskHome: helpdeskHome},
259+
data: {wizard: 'forms', categoriesId: categoryId, keywords: keywords, helpdeskHome: 0},
261260
type: "GET",
262261
dataType: "json"
263262
}).done(function (response) {

setup.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ function plugin_formcreator_replaceHelpdesk() {
294294
$helpdeskMode = PluginFormcreatorEntityconfig::getUsedConfig('replace_helpdesk', $_SESSION['glpiactive_entity']);
295295
if ($helpdeskMode != '0'
296296
&& $_SESSION['glpiactiveprofile']['interface'] == 'helpdesk') {
297-
return $helpdeskMode;
297+
return true;
298298
}
299299
}
300300
return false;

0 commit comments

Comments
 (0)