Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 79 additions & 0 deletions inc/abstracttarget.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,10 @@ abstract protected function getTargetTemplate(array $data): int;
const LOCATION_RULE_SPECIFIC = 2;
const LOCATION_RULE_ANSWER = 3;

const REQUESTSOURCE_RULE_NONE = 1;
const REQUESTSOURCE_RULE_SPECIFIC = 2;
const REQUESTSOURCE_RULE_ANSWER = 3;

const OLA_RULE_NONE = 1;
const OLA_RULE_SPECIFIC = 2;
const OLA_RULE_FROM_ANWSER = 3;
Expand Down Expand Up @@ -276,6 +280,14 @@ public static function getEnumLocationRule() {
];
}

public static function getEnumRequestSourceRule() {
return [
self::REQUESTSOURCE_RULE_NONE => __('Request source from template or none', 'formcreator'),
self::REQUESTSOURCE_RULE_SPECIFIC => __('Specific request source', 'formcreator'),
self::REQUESTSOURCE_RULE_ANSWER => __('Equals to the answer to the question', 'formcreator'),
];
}

public function isEntityAssign() {
return false;
}
Expand Down Expand Up @@ -1491,6 +1503,73 @@ protected function showLocationSettings($rand) {
echo '</tr>';
}

protected function showRequestSourceSettings($rand) {
global $DB;

echo '<tr>';
echo '<td width="15%">' . __('Request source') . '</td>';
echo '<td width="45%">';
Dropdown::showFromArray('requestsource_rule', static::getEnumRequestSourceRule(), [
'value' => $this->fields['requestsource_rule'],
'on_change' => "plugin_formcreator_change_request_source($rand)",
'rand' => $rand
]);

echo Html::scriptBlock("plugin_formcreator_change_request_source($rand)");
echo '</td>';
echo '<td width="15%">';
echo '<span id="requestsource_question_title" style="display: none">' . __('Question', 'formcreator') . '</span>';
echo '<span id="requestsource_specific_title" style="display: none">' . __('Request source') . '</span>';
echo '</td>';
echo '<td width="25%">';

echo '<div id="requestsource_specific_value" style="display: none">';
RequestType::dropdown([
'name' => '_requestsource_specific',
'value' => $this->fields["requestsource_question"],
]);
echo '</div>';
echo '<div id="requestsource_question_value" style="display: none">';
// select all user questions (GLPI Object)
$questionTable = PluginFormcreatorQuestion::getTable();
$sectionTable = PluginFormcreatorSection::getTable();
$sectionFk = PluginFormcreatorSection::getForeignKeyField();
$formFk = PluginFormcreatorForm::getForeignKeyField();
$result = $DB->request([
'SELECT' => [
$questionTable => ['id', 'name', 'values'],
$sectionTable => ['name as sname'],
],
'FROM' => $questionTable,
'INNER JOIN' => [
$sectionTable => [
'FKEY' => [
$sectionTable => 'id',
$questionTable => $sectionFk
]
],
],
'WHERE' => [
"$formFk" => $this->getForm()->getID(),
"$questionTable.fieldtype" => 'dropdown'
]
]);
$users_questions = [];
foreach ($result as $question) {
$decodedValues = json_decode($question['values'], JSON_OBJECT_AS_ARRAY);
if (isset($decodedValues['itemtype']) && $decodedValues['itemtype'] === 'RequestType') {
$users_questions[$question['sname']][$question['id']] = $question['name'];
}
}
Dropdown::showFromArray('_requestsource_question', $users_questions, [
'value' => $this->fields['requestsource_question'],
]);

echo '</div>';
echo '</td>';
echo '</tr>';
}

/**
* Sets the time to resolve of the target object
*
Expand Down
55 changes: 52 additions & 3 deletions inc/targetticket.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,12 @@ public function showForm($ID, $options = []) {
// Location selection
// -------------------------------------------------------------------------------------------
$this->showLocationSettings($rand);

// -------------------------------------------------------------------------------------------
// Request source selection
// -------------------------------------------------------------------------------------------
$this->showRequestSourceSettings($rand);

// -------------------------------------------------------------------------------------------
// Tags
// -------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -546,6 +552,17 @@ public function prepareInputForUpdate($input) {
$input['location_question'] = '0';
}

switch ($input['requestsource_rule']) {
case self::REQUESTSOURCE_RULE_ANSWER:
$input['requestsource_question'] = $input['_requestsource_question'];
break;
case self::REQUESTSOURCE_RULE_SPECIFIC:
$input['requestsource_question'] = $input['_requestsource_specific'];
break;
default:
$input['requestsource_question'] = '0';
}

$plugin = new Plugin();
if ($plugin->isActivated('tag')) {
$input['tag_questions'] = (!empty($input['_tag_questions']))
Expand Down Expand Up @@ -773,6 +790,7 @@ public function save(PluginFormcreatorFormAnswer $formanswer) {
$data = $this->setOLA($data, $formanswer);
$data = $this->setTargetUrgency($data, $formanswer);
$data = $this->setTargetLocation($data, $formanswer);
$data = $this->setTargetRequestSource($data, $formanswer);
$data = $this->setTargetAssociatedItem($data, $formanswer);

// There is always at least one requester
Expand Down Expand Up @@ -896,6 +914,35 @@ protected function setTargetLocation($data, $formanswer) {
return $data;
}

protected function setTargetRequestSource($data, $formanswer) {
global $DB;

$requestSource = null;
switch ($this->fields['requestsource_rule']) {
case self::REQUESTSOURCE_RULE_ANSWER:
$requestSource = $DB->request([
'SELECT' => ['answer'],
'FROM' => PluginFormcreatorAnswer::getTable(),
'WHERE' => [
'plugin_formcreator_formanswers_id' => $formanswer->fields['id'],
'plugin_formcreator_questions_id' => $this->fields['requestsource_question']
]
])->next();
if (ctype_digit($requestSource['answer'])) {
$requestSource = $requestSource['answer'];
}
break;
case self::REQUESTSOURCE_RULE_SPECIFIC:
$requestSource = $this->fields['requestsource_question'];
break;
}
if (!is_null($requestSource)) {
$data['requesttypes_id'] = $requestSource;
}

return $data;
}

protected function setTargetType(array $data, PluginFormcreatorFormAnswer $formanswer) {
global $DB;

Expand Down Expand Up @@ -927,7 +974,7 @@ protected function setTargetType(array $data, PluginFormcreatorFormAnswer $forma

protected function showTypeSettings($rand) {
echo '<tr>';
echo '<td width="15%">' . __('Request type') . '</td>';
echo '<td width="15%">' . __('Request type', 'formcreator') . '</td>';
echo '<td width="25%">';
Dropdown::showFromArray('type_rule', static::getEnumRequestTypeRule(), [
'value' => $this->fields['type_rule'],
Expand All @@ -939,7 +986,7 @@ protected function showTypeSettings($rand) {
echo '</td>';
echo '<td width="15%">';
echo '<span id="requesttype_question_title" style="display: none">' . __('Question', 'formcreator') . '</span>';
echo '<span id="requesttype_specific_title" style="display: none">' . __('Type ', 'formcreator') . '</span>';
echo '<span id="requesttype_specific_title" style="display: none">' . __('Type', 'formcreator') . '</span>';
echo '</td>';
echo '<td width="25%">';
echo '<div id="requesttype_specific_value" style="display: none">';
Expand Down Expand Up @@ -967,7 +1014,7 @@ protected function showAssociateSettings($rand) {
global $CFG_GLPI;

echo '<tr>';
echo '<td width="15%">' . __('Associated elements') . '</td>';
echo '<td width="15%">' . _n('Associated element', 'Associated elements', Session::getPluralNumber()) . '</td>';
echo '<td width="45%">';
Dropdown::showFromArray('associate_rule', static::getEnumAssociateRule(), [
'value' => $this->fields['associate_rule'],
Expand Down Expand Up @@ -1209,6 +1256,7 @@ public static function import(PluginFormcreatorLinker $linker, array $input = []
'category_rule' => ['values' => self::CATEGORY_RULE_ANSWER, 'field' => 'category_question'],
'associate_rule' => ['values' => self::ASSOCIATE_RULE_ANSWER, 'field' => 'associate_question'],
'location_rule' => ['values' => self::LOCATION_RULE_ANSWER, 'field' => 'location_question'],
'requestsource_rule' => ['values' => self::REQUESTSOURCE_RULE_ANSWER, 'field' => 'requestsource_question'],
'destination_entity' => [
'values' => [
self::DESTINATION_ENTITY_ENTITY,
Expand Down Expand Up @@ -1323,6 +1371,7 @@ public function export(bool $remove_uuid = false) : array {
'category_rule' => ['values' => self::CATEGORY_RULE_ANSWER, 'field' => 'category_question'],
'associate_rule' => ['values' => self::ASSOCIATE_RULE_ANSWER, 'field' => 'associate_question'],
'location_rule' => ['values' => self::LOCATION_RULE_ANSWER, 'field' => 'location_question'],
'requestsource_rule' => ['values' => self::REQUESTSOURCE_RULE_ANSWER, 'field' => 'requestsource_question'],
'destination_entity' => [
'values' => [
self::DESTINATION_ENTITY_ENTITY,
Expand Down
1 change: 1 addition & 0 deletions install/install.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ class PluginFormcreatorInstall {
'2.12.5' => '2.13',
'2.13' => '2.14',
'2.14' => '2.15',
'2.15' => '2.16'
];

/**
Expand Down
2 changes: 2 additions & 0 deletions install/mysql/plugin_formcreator_empty.sql
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,8 @@ CREATE TABLE IF NOT EXISTS `glpi_plugin_formcreator_targettickets` (
`ola_rule` int(11) NOT NULL DEFAULT '1',
`ola_question_tto` int(11) NOT NULL DEFAULT '0',
`ola_question_ttr` int(11) NOT NULL DEFAULT '0',
`requestsource_rule` int(11) NOT NULL DEFAULT '1',
`requestsource_question` int(11) NOT NULL DEFAULT '0',
`uuid` varchar(255) DEFAULT NULL,
PRIMARY KEY (`id`),
INDEX `tickettemplates_id` (`tickettemplates_id`)
Expand Down
67 changes: 67 additions & 0 deletions install/upgrade_to_2.16.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?php
/**
* ---------------------------------------------------------------------
* Formcreator is a plugin which allows creation of custom forms of
* easy access.
* ---------------------------------------------------------------------
* LICENSE
*
* This file is part of Formcreator.
*
* Formcreator is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* Formcreator is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Formcreator. If not, see <http://www.gnu.org/licenses/>.
* ---------------------------------------------------------------------
* @copyright Copyright © 2011 - 2021 Teclib'
* @license http://www.gnu.org/licenses/gpl.txt GPLv3+
* @link https://github.com/pluginsGLPI/formcreator/
* @link https://pluginsglpi.github.io/formcreator/
* @link http://plugins.glpi-project.org/#/plugin/formcreator
* ---------------------------------------------------------------------
*/
class PluginFormcreatorUpgradeTo2_16 {
/** @var Migration */
protected $migration;

/**
* @param Migration $migration
*/
public function upgrade(Migration $migration) {
global $DB;

$migration->displayMessage("Upgrade to schema version 2.16");

$migration->displayMessage("Upgrade glpi_plugin_formcreator_targettickets");

// add requestsource rule
if (!$DB->fieldExists('glpi_plugin_formcreator_targettickets', 'requestsource_rule', false)) {
$migration->addField(
'glpi_plugin_formcreator_targettickets',
'requestsource_rule',
"int(11) NOT NULL DEFAULT '1'",
['after' => 'ola_question_ttr']
);
}

// add requestsource question
if (!$DB->fieldExists('glpi_plugin_formcreator_targettickets', 'requestsource_question', false)) {
$migration->addField(
'glpi_plugin_formcreator_targettickets',
'requestsource_question',
'integer',
['after' => 'requestsource_rule']
);
}

$migration->executeMigration();
}
}
18 changes: 18 additions & 0 deletions js/scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -2092,6 +2092,24 @@ function plugin_formcreator_change_location(rand) {
}
}

function plugin_formcreator_change_request_source(rand) {
$('#requestsource_specific_title').hide();
$('#requestsource_specific_value').hide();
$('#requestsource_question_title').hide();
$('#requestsource_question_value').hide();

switch($('#dropdown_requestsource_rule' + rand).val()) {
case '3' :
$('#requestsource_question_title').show();
$('#requestsource_question_value').show();
break;
case '2' :
$('#requestsource_specific_title').show();
$('#requestsource_specific_value').show();
break;
}
}

function plugin_formcreator_change_entity(rand) {
$('#entity_specific_title').hide();
$('#entity_user_title').hide();
Expand Down
Binary file modified locales/en_GB.mo
Binary file not shown.
8 changes: 8 additions & 0 deletions locales/en_GB.po
Original file line number Diff line number Diff line change
Expand Up @@ -754,6 +754,14 @@ msgstr "Location from template or none"
msgid "Specific location"
msgstr "Specific location"

#: inc/targetbase.class.php:226
msgid "Request source from template or none"
msgstr "Request source from template or none"

#: inc/targetbase.class.php:227
msgid "Specific request source"
msgstr "Specific request source"

#: inc/targetbase.class.php:667
msgid "User type question"
msgstr "User type question"
Expand Down
Binary file modified locales/fr_FR.mo
Binary file not shown.
8 changes: 8 additions & 0 deletions locales/fr_FR.po
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,14 @@ msgstr "Lieu à partir d'un gabarit ou aucun"
msgid "Specific location"
msgstr "Lieu spécifique"

#: inc/abstracttarget.class.php:226
msgid "Request source from template or none"
msgstr "Source de la demande à partir d'un gabarit ou aucune"

#: inc/abstracttarget.class.php:227
msgid "Specific request source"
msgstr "Source de la demande spécifique"

#: inc/abstracttarget.class.php:919
msgid "User type question"
msgstr "Question de type \"utilisateur\""
Expand Down
4 changes: 2 additions & 2 deletions setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@

global $CFG_GLPI;
// Version of the plugin (major.minor.bugfix)
define('PLUGIN_FORMCREATOR_VERSION', '2.14.5');
define('PLUGIN_FORMCREATOR_VERSION', '2.14.6');
// Schema version of this version (major.minor only)
define('PLUGIN_FORMCREATOR_SCHEMA_VERSION', '2.15');
define('PLUGIN_FORMCREATOR_SCHEMA_VERSION', '2.16');
// is or is not an official release of the plugin
define('PLUGIN_FORMCREATOR_IS_OFFICIAL_RELEASE', true);

Expand Down