Skip to content

Commit

Permalink
fix(wizard): various errors displaying forms in service catalog
Browse files Browse the repository at this point in the history
Signed-off-by: Thierry Bugier <tbugier@teclib.com>
  • Loading branch information
btry committed Aug 22, 2019
1 parent 1697b7b commit 309e7e4
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 27 deletions.
8 changes: 4 additions & 4 deletions ajax/homepage_wizard.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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);
}

Expand Down
40 changes: 40 additions & 0 deletions inc/category.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
34 changes: 14 additions & 20 deletions inc/form.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand All @@ -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';
Expand All @@ -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
Expand Down Expand Up @@ -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']
]
]
];

Expand All @@ -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(),
Expand All @@ -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",
Expand All @@ -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'],
Expand Down Expand Up @@ -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'][] = [
Expand Down
3 changes: 1 addition & 2 deletions js/scripts.js.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
var currentCategory = "0";
var sortByName = false;
var tiles = [];
var helpdeskHome = 0;
var serviceCatalogEnabled = false;
var slinkyCategories;
var timers = [];
Expand Down Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 309e7e4

Please sign in to comment.