From 309e7e49d518183912de8c83631590d42adc81ad Mon Sep 17 00:00:00 2001 From: Thierry Bugier Date: Wed, 5 Jun 2019 18:41:52 +0200 Subject: [PATCH] fix(wizard): various errors displaying forms in service catalog Signed-off-by: Thierry Bugier --- ajax/homepage_wizard.php | 8 ++++---- inc/category.class.php | 40 ++++++++++++++++++++++++++++++++++++++++ inc/form.class.php | 34 ++++++++++++++-------------------- js/scripts.js.php | 3 +-- setup.php | 2 +- 5 files changed, 60 insertions(+), 27 deletions(-) diff --git a/ajax/homepage_wizard.php b/ajax/homepage_wizard.php index b56695fad..a6d3e3b26 100644 --- a/ajax/homepage_wizard.php +++ b/ajax/homepage_wizard.php @@ -36,10 +36,10 @@ } if ($_REQUEST['wizard'] == 'categories') { - plugin_formcreator_showWizardCategories(plugin_formcreator_replaceHelpdesk()); + plugin_formcreator_showWizardCategories(); } else if ($_REQUEST['wizard'] == 'forms') { if (isset($_REQUEST['categoriesId'])) { - $categoriesId = intval($_REQUEST['categoriesId']); + $categoriesId = (int) $_REQUEST['categoriesId']; } else { $categoriesId = 0; } @@ -52,8 +52,8 @@ : true; } -function plugin_formcreator_showWizardCategories($helpdesk = true) { - $tree = PluginFormcreatorCategory::getCategoryTree(0, $helpdesk); +function plugin_formcreator_showWizardCategories($helpdeskHome = false) { + $tree = PluginFormcreatorCategory::getCategoryTree(0, $helpdeskHome); echo json_encode($tree, JSON_UNESCAPED_SLASHES); } diff --git a/inc/category.class.php b/inc/category.class.php index 5480ddea5..405df2499 100644 --- a/inc/category.class.php +++ b/inc/category.class.php @@ -94,6 +94,46 @@ public static function getCategoryTree($rootId = 0, $helpdeskHome = false) { ]); // Selects categories containing forms or sub-categories + // $subQuery = []; + // $subQuery[] = new QuerySubQuery([ + // 'COUNT' => 'count', + // 'FROM' => $form_table, + // 'WHERE' => [ + // "AND" => [ + // "$form_table.is_active" => '1', + // "$form_table.is_deleted" => '0', + // "$form_table.plugin_formcreator_categories_id" => $cat_table."id", + // "$form_table.language" => [$_SESSION['glpilanguage'], '', '0', null], + // 'OR' => [ + // 'access_rights' => ['!=', PluginFormcreatorForm::ACCESS_RESTRICTED], + // "$form_table.id" => new QuerySubQuery([ + // 'SELECT' => 'plugin_formcreator_forms_id', + // 'FROM' => $table_fp, + // 'WHERE' => [ + // 'profiles_id' => $_SESSION['glpiactiveprofile']['id'] + // ] + // ]) + // ] + // ] + // + $dbUtils->getEntitiesRestrictCriteria($form_table, "", "", true, false) + // + ($helpdeskHome ? ["$form_table.helpdesk_home" => '1'] : []) + // ], + // ]); + // $subQuery[] = new QuerySubQuery([ + // 'COUNT' => 'count', + // 'FROM' => "$cat_table AS cat2", + // 'WHERE' => [ + // new QueryExpression("`cat2`.`plugin_formcreator_categories_id`=`$cat_table`.`id`"), + // ], + // ]); + // $subQuery[] = new QuerySubQuery([ + // 'COUNT' => 'count', + // 'FROM' => "$cat_table AS cat2", + // 'WHERE' => [ + // new QueryExpression("`cat2`.`plugin_formcreator_categories_id`=`$cat_table`.`id`"), + // ], + // ]); + // TODO: To solve the 3rd OR for faq count $where = "(SELECT COUNT($form_table.id) FROM $form_table WHERE $form_table.`plugin_formcreator_categories_id` = $cat_table.`id` diff --git a/inc/form.class.php b/inc/form.class.php index 11f53fee5..61627683a 100644 --- a/inc/form.class.php +++ b/inc/form.class.php @@ -758,7 +758,6 @@ public function showFormList($rootCategory = 0, $keywords = '', $helpdeskHome = $table_cat = getTableForItemType('PluginFormcreatorCategory'); $table_form = getTableForItemType('PluginFormcreatorForm'); $table_fp = getTableForItemType('PluginFormcreatorForm_Profile'); - $table_target = getTableForItemType('PluginFormcreatorTargets'); $table_section = getTableForItemType('PluginFormcreatorSections'); $table_question= getTableForItemType('PluginFormcreatorQuestions'); @@ -769,8 +768,8 @@ public function showFormList($rootCategory = 0, $keywords = '', $helpdeskHome = 'AND' => [ "$table_form.is_active" => '1', "$table_form.is_deleted" => '0', - "$table_form.language" => [$_SESSION['glpilanguage'], '0', null], - ] + $dbUtils->getEntitiesRestrictCriteria($table_form, '', '', true, false), + "$table_form.language" => [$_SESSION['glpilanguage'], '0', '', null], + ] + $dbUtils->getEntitiesRestrictCriteria($table_form, '', '', true, false) ]; if ($helpdeskHome) { $where_form['AND']["$table_form.helpdesk_home"] = '1'; @@ -779,7 +778,7 @@ public function showFormList($rootCategory = 0, $keywords = '', $helpdeskHome = $selectedCategories = []; if ($rootCategory != 0) { $selectedCategories = getSonsOf($table_cat, $rootCategory); - $where_form['AND']["$table_form.plugin_formcreator_categories_id"] = [$selectedCategories]; + $where_form['AND']["$table_form.plugin_formcreator_categories_id"] = $selectedCategories; } // Find forms accessible by the current user @@ -807,13 +806,9 @@ public function showFormList($rootCategory = 0, $keywords = '', $helpdeskHome = $where_form['AND'][] = [ 'OR' => [ 'access_rights' => ['!=', PluginFormcreatorForm::ACCESS_RESTRICTED], - "$table_form.id" => new QuerySubQuery([ - 'SELECT' => 'plugin_formcreator_forms_id', - 'FROM' => $table_fp, - 'WHERE' => [ - 'profiles_id' => $_SESSION['glpiactiveprofile']['id'] - ] - ]) + [ + "$table_fp.profiles_id" => $_SESSION['glpiactiveprofile']['id'] + ] ] ]; @@ -829,12 +824,6 @@ public function showFormList($rootCategory = 0, $keywords = '', $helpdeskHome = $table_form => PluginFormcreatorCategory::getForeignKeyField(), ] ], - $table_target => [ - 'FKEY' => [ - $table_target => PluginFormcreatorForm::getForeignKeyField(), - $table_form => 'id', - ] - ], $table_section => [ 'FKEY' => [ $table_section => PluginFormcreatorForm::getForeignKeyField(), @@ -846,11 +835,16 @@ public function showFormList($rootCategory = 0, $keywords = '', $helpdeskHome = $table_question => PluginFormcreatorSection::getForeignKeyField(), $table_section => 'id' ] + ], + $table_fp => [ + 'FKEY' => [ + $table_fp => PluginFormcreatorForm::getForeignKeyField(), + $table_form => 'id', + ] ] ], 'WHERE' => $where_form, 'GROUPBY' => [ - "$table_target.plugin_formcreator_forms_id", "$table_form.id", "$table_form.name", "$table_form.description", @@ -864,7 +858,6 @@ public function showFormList($rootCategory = 0, $keywords = '', $helpdeskHome = $formList = []; if ($result_forms->count() > 0) { - // while ($form = $DB->fetch_array($result_forms)) { foreach ($result_forms as $form) { $formList[] = [ 'id' => $form['id'], @@ -933,7 +926,8 @@ public function showFormList($rootCategory = 0, $keywords = '', $helpdeskHome = 'AND' => [ "$table_form.is_active" => '1', "$table_form.is_deleted" => '0', - "$table_form.language" => [$_SESSION['glpilanguage'], '0', null], + "$table_form.language" => [$_SESSION['glpilanguage'], '0', '', null], + "$table_form.is_default" => ['<>', '0'] ] + $dbUtils->getEntitiesRestrictCriteria($table_form, '', '', true, false), ]; $where_form['AND'][] = [ diff --git a/js/scripts.js.php b/js/scripts.js.php index fb0623c34..ef1eb9f3e 100644 --- a/js/scripts.js.php +++ b/js/scripts.js.php @@ -38,7 +38,6 @@ var currentCategory = "0"; var sortByName = false; var tiles = []; -var helpdeskHome = 0; var serviceCatalogEnabled = false; var slinkyCategories; var timers = []; @@ -257,7 +256,7 @@ function getFormAndFaqItems(categoryId) { deferred = jQuery.Deferred(); $.ajax({ url: rootDoc + '/plugins/formcreator/ajax/homepage_wizard.php', - data: {wizard: 'forms', categoriesId: categoryId, keywords: keywords, helpdeskHome: helpdeskHome}, + data: {wizard: 'forms', categoriesId: categoryId, keywords: keywords, helpdeskHome: 0}, type: "GET", dataType: "json" }).done(function (response) { diff --git a/setup.php b/setup.php index 97d1605ae..1aeab5485 100644 --- a/setup.php +++ b/setup.php @@ -294,7 +294,7 @@ function plugin_formcreator_replaceHelpdesk() { $helpdeskMode = PluginFormcreatorEntityconfig::getUsedConfig('replace_helpdesk', $_SESSION['glpiactive_entity']); if ($helpdeskMode != '0' && $_SESSION['glpiactiveprofile']['interface'] == 'helpdesk') { - return $helpdeskMode; + return true; } } return false;