diff --git a/inc/abstracttarget.class.php b/inc/abstracttarget.class.php
index 19ae522..67780e2 100644
--- a/inc/abstracttarget.class.php
+++ b/inc/abstracttarget.class.php
@@ -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;
@@ -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;
}
@@ -1491,6 +1503,73 @@ protected function showLocationSettings($rand) {
echo '';
}
+ protected function showRequestSourceSettings($rand) {
+ global $DB;
+
+ echo '
';
+ echo '| ' . __('Request source') . ' | ';
+ echo '';
+ 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 ' | ';
+ echo '';
+ echo '' . __('Question', 'formcreator') . '';
+ echo '' . __('Request source') . '';
+ echo ' | ';
+ echo '';
+
+ echo ' ';
+ RequestType::dropdown([
+ 'name' => '_requestsource_specific',
+ 'value' => $this->fields["requestsource_question"],
+ ]);
+ echo ' ';
+ echo '';
+ // 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 ' ';
+ echo ' | ';
+ echo '
';
+ }
+
/**
* Sets the time to resolve of the target object
*
diff --git a/inc/targetticket.class.php b/inc/targetticket.class.php
index ecf510c..0b90b70 100644
--- a/inc/targetticket.class.php
+++ b/inc/targetticket.class.php
@@ -229,6 +229,12 @@ public function showForm($ID, $options = []) {
// Location selection
// -------------------------------------------------------------------------------------------
$this->showLocationSettings($rand);
+
+ // -------------------------------------------------------------------------------------------
+ // Request source selection
+ // -------------------------------------------------------------------------------------------
+ $this->showRequestSourceSettings($rand);
+
// -------------------------------------------------------------------------------------------
// Tags
// -------------------------------------------------------------------------------------------
@@ -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']))
@@ -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
@@ -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;
@@ -927,7 +974,7 @@ protected function setTargetType(array $data, PluginFormcreatorFormAnswer $forma
protected function showTypeSettings($rand) {
echo '';
- echo '| ' . __('Request type') . ' | ';
+ echo '' . __('Request type', 'formcreator') . ' | ';
echo '';
Dropdown::showFromArray('type_rule', static::getEnumRequestTypeRule(), [
'value' => $this->fields['type_rule'],
@@ -939,7 +986,7 @@ protected function showTypeSettings($rand) {
echo ' | ';
echo '';
echo '' . __('Question', 'formcreator') . '';
- echo '' . __('Type ', 'formcreator') . '';
+ echo '' . __('Type', 'formcreator') . '';
echo ' | ';
echo '';
echo ' ';
@@ -967,7 +1014,7 @@ protected function showAssociateSettings($rand) {
global $CFG_GLPI;
echo ' |
';
- echo '| ' . __('Associated elements') . ' | ';
+ echo '' . _n('Associated element', 'Associated elements', Session::getPluralNumber()) . ' | ';
echo '';
Dropdown::showFromArray('associate_rule', static::getEnumAssociateRule(), [
'value' => $this->fields['associate_rule'],
@@ -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,
@@ -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,
diff --git a/install/install.php b/install/install.php
index fb46422..c514545 100644
--- a/install/install.php
+++ b/install/install.php
@@ -73,6 +73,7 @@ class PluginFormcreatorInstall {
'2.12.5' => '2.13',
'2.13' => '2.14',
'2.14' => '2.15',
+ '2.15' => '2.16'
];
/**
diff --git a/install/mysql/plugin_formcreator_empty.sql b/install/mysql/plugin_formcreator_empty.sql
index ec21ebe..90399d3 100644
--- a/install/mysql/plugin_formcreator_empty.sql
+++ b/install/mysql/plugin_formcreator_empty.sql
@@ -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`)
diff --git a/install/upgrade_to_2.16.php b/install/upgrade_to_2.16.php
new file mode 100644
index 0000000..0d82985
--- /dev/null
+++ b/install/upgrade_to_2.16.php
@@ -0,0 +1,67 @@
+.
+ * ---------------------------------------------------------------------
+ * @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();
+ }
+}
diff --git a/js/scripts.js b/js/scripts.js
index f97cfb5..e58a01f 100644
--- a/js/scripts.js
+++ b/js/scripts.js
@@ -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();
diff --git a/locales/en_GB.mo b/locales/en_GB.mo
index 41e74ca..4e0dd94 100644
Binary files a/locales/en_GB.mo and b/locales/en_GB.mo differ
diff --git a/locales/en_GB.po b/locales/en_GB.po
index bf9ecec..9683474 100644
--- a/locales/en_GB.po
+++ b/locales/en_GB.po
@@ -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"
diff --git a/locales/fr_FR.mo b/locales/fr_FR.mo
index d9879c3..4ec08c6 100644
Binary files a/locales/fr_FR.mo and b/locales/fr_FR.mo differ
diff --git a/locales/fr_FR.po b/locales/fr_FR.po
index efcd0b7..07741ee 100644
--- a/locales/fr_FR.po
+++ b/locales/fr_FR.po
@@ -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\""
diff --git a/setup.php b/setup.php
index dc29438..bf64886 100644
--- a/setup.php
+++ b/setup.php
@@ -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);
|