diff --git a/.travis.yml b/.travis.yml
index e0a2c45cb..02abddd42 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -5,13 +5,6 @@ env:
- GLPI_SOURCE="https://github.com/glpi-project/glpi -b 9.2/bugfixes"
- PHPUNIT_ARGS="--verbose --debug"
-php:
- - '5.6'
- - '7.0'
- - '7.1'
- - '7.2'
- - nightly
-
before_script:
- mysql -u root -e 'create database glpitest;'
- git clone https://github.com/glpi-project/glpi --depth 1 -b 9.2/bugfixes ../glpi && cd ../glpi
@@ -24,9 +17,17 @@ before_script:
script:
- vendor/bin/phpunit $PHPUNIT_ARGS
- - vendor/bin/robo --no-interaction code:cs
+ - if [[ "$CS" == "true" ]]; then vendor/bin/robo --no-interaction code:cs; fi
matrix:
+ include:
+ - php: 5.6
+ - php: 7.0
+ - php: 7.1
+ - php: 7.2
+ env: CS=true
+ - php: nightly
+
allow_failures:
- php: nightly
diff --git a/CHANGELOG.md b/CHANGELOG.md
index f59dd081e..8e16a5d59 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,67 @@
-GLPI Formcreator ChangeLog
-===============================
+
+## [2.6.1](https://github.com-btry/pluginsGLPI/formcreator/compare/2.6.0...2.6.1) (2018-01-02)
+
+
+### Bug Fixes
+
+* avoid duplicated form having the uuid of the source one ([464757e](https://github.com-btry/pluginsGLPI/formcreator/commit/464757e))
+* form duplication issue when source form contains access restriction ([ec40d9f](https://github.com-btry/pluginsGLPI/formcreator/commit/ec40d9f))
+* misconceptions in duplication process ([06c2430](https://github.com-btry/pluginsGLPI/formcreator/commit/06c2430))
+* **locales:** fix missing locales, update them ([33cbe5e](https://github.com-btry/pluginsGLPI/formcreator/commit/33cbe5e))
+* rich description encoding in ticket ([#775](https://github.com-btry/pluginsGLPI/formcreator/issues/775)) ([f739c54](https://github.com-btry/pluginsGLPI/formcreator/commit/f739c54))
+* **answer:** HTML entity decode for older textarea answers ([3612c3c](https://github.com-btry/pluginsGLPI/formcreator/commit/3612c3c))
+* **condition:** fix inconsistency when checking question conditions ([a820e55](https://github.com-btry/pluginsGLPI/formcreator/commit/a820e55)), closes [#829](https://github.com-btry/pluginsGLPI/formcreator/issues/829)
+* **field:** avoid html entitization of accented chars ([a973f7b](https://github.com-btry/pluginsGLPI/formcreator/commit/a973f7b))
+* **form:** duplicate target changes when duplicating form ([7f78de9](https://github.com-btry/pluginsGLPI/formcreator/commit/7f78de9))
+* **form:** fix escaping and logic issues in duplication ([236effd](https://github.com-btry/pluginsGLPI/formcreator/commit/236effd))
+* **form:** repair massive acions ([7221644](https://github.com-btry/pluginsGLPI/formcreator/commit/7221644))
+* **form:** update target settings depending on questions ([7acbc11](https://github.com-btry/pluginsGLPI/formcreator/commit/7acbc11))
+* **form_answer:** restrict display of form answers to requesters and valdators ([8909e4e](https://github.com-btry/pluginsGLPI/formcreator/commit/8909e4e)), closes [#869](https://github.com-btry/pluginsGLPI/formcreator/issues/869)
+* **install:** detect version 2.6 without schema version, see [#794](https://github.com-btry/pluginsGLPI/formcreator/issues/794) ([decaafe](https://github.com-btry/pluginsGLPI/formcreator/commit/decaafe))
+* **install:** fix inconsistencies in install process" ([99eb790](https://github.com-btry/pluginsGLPI/formcreator/commit/99eb790))
+* **install:** fresh 2.6.0 install inconsistent ([903a13a](https://github.com-btry/pluginsGLPI/formcreator/commit/903a13a))
+* **install:** fresh installation does not saves current schema version ([8eadd7d](https://github.com-btry/pluginsGLPI/formcreator/commit/8eadd7d)), closes [#794](https://github.com-btry/pluginsGLPI/formcreator/issues/794)
+* **install:** inconsistency in fresh 2.6.0 install ([e41a86d](https://github.com-btry/pluginsGLPI/formcreator/commit/e41a86d)), closes [#822](https://github.com-btry/pluginsGLPI/formcreator/issues/822)
+* **install:** restore lost JSON type creation ([40afda3](https://github.com-btry/pluginsGLPI/formcreator/commit/40afda3))
+* **install:** run issues synchronization after install ([2441d02](https://github.com-btry/pluginsGLPI/formcreator/commit/2441d02))
+* **issue:** bad search option ([bc4bec8](https://github.com-btry/pluginsGLPI/formcreator/commit/bc4bec8))
+* **issue:** issue not updated to refused status ([8b1e3b8](https://github.com-btry/pluginsGLPI/formcreator/commit/8b1e3b8))
+* **issue:** wrong ticket disdplay ([5e33407](https://github.com-btry/pluginsGLPI/formcreator/commit/5e33407)), closes [#859](https://github.com-btry/pluginsGLPI/formcreator/issues/859)
+* **locale:** bad domain for some locales ([1d9ff65](https://github.com-btry/pluginsGLPI/formcreator/commit/1d9ff65))
+* **locales:** add missing strings; update locales ([792a6c2](https://github.com-btry/pluginsGLPI/formcreator/commit/792a6c2))
+* **locales:** follow change of a localizable string from GLPI 9.1 ([75a1057](https://github.com-btry/pluginsGLPI/formcreator/commit/75a1057))
+* **locales:** harmonize and fix locales ([62076ed](https://github.com-btry/pluginsGLPI/formcreator/commit/62076ed))
+* **question:** fix duplicate code ([779a5c3](https://github.com-btry/pluginsGLPI/formcreator/commit/779a5c3))
+* **question:** fix escaping issues with regexes ([c807936](https://github.com-btry/pluginsGLPI/formcreator/commit/c807936))
+* **question:** fix typo breaking duplication ([e7d2b0e](https://github.com-btry/pluginsGLPI/formcreator/commit/e7d2b0e))
+* **question:** remove abusive encoding ([f183091](https://github.com-btry/pluginsGLPI/formcreator/commit/f183091))
+* **rule:** location affectation on ticket via business rule ([06d6461](https://github.com-btry/pluginsGLPI/formcreator/commit/06d6461)), closes [#795](https://github.com-btry/pluginsGLPI/formcreator/issues/795)
+* **section:** delete a section displays an error ([1d1eb93](https://github.com-btry/pluginsGLPI/formcreator/commit/1d1eb93))
+* **selectfield:** workaround GLPI issue 3308 ([d086006](https://github.com-btry/pluginsGLPI/formcreator/commit/d086006))
+* **target:** do not mention the absence of an uploaded document in targets ([f1ac36b](https://github.com-btry/pluginsGLPI/formcreator/commit/f1ac36b))
+* **target:** fix HTML issues in generated tickets ([278c628](https://github.com-btry/pluginsGLPI/formcreator/commit/278c628))
+* **target:** fix typo preventing requester groups being added to targets ([ececfe3](https://github.com-btry/pluginsGLPI/formcreator/commit/ececfe3)), closes [#767](https://github.com-btry/pluginsGLPI/formcreator/issues/767)
+* **target:** fix warnings in timeline when no fiel uploaded ([9c94128](https://github.com-btry/pluginsGLPI/formcreator/commit/9c94128))
+* **target:** rename a target overriden by a global var ([f5b14a9](https://github.com-btry/pluginsGLPI/formcreator/commit/f5b14a9))
+* **target-change:** nug handling the comment field of a target change ([5371da5](https://github.com-btry/pluginsGLPI/formcreator/commit/5371da5))
+* **targetchange:** fix reversed condition ([e2288bf](https://github.com-btry/pluginsGLPI/formcreator/commit/e2288bf))
+* **targetticket:** fix entity of generated ticket ([1ea5325](https://github.com-btry/pluginsGLPI/formcreator/commit/1ea5325))
+* **targetticket:** follow change in GLPI for due date ([efa5fcb](https://github.com-btry/pluginsGLPI/formcreator/commit/efa5fcb))
+* **targetticket,targetchange:** ticket and change rendering without rich text mode ([d723a47](https://github.com-btry/pluginsGLPI/formcreator/commit/d723a47)), closes [#847](https://github.com-btry/pluginsGLPI/formcreator/issues/847)
+* **ui:** css ([c907214](https://github.com-btry/pluginsGLPI/formcreator/commit/c907214))
+* **ui:** dont force layout for service catalog ([617e8f1](https://github.com-btry/pluginsGLPI/formcreator/commit/617e8f1))
+* **ui:** pqselect enabled not loaded every time it is needed ([#768](https://github.com-btry/pluginsGLPI/formcreator/issues/768)) ([22f3508](https://github.com-btry/pluginsGLPI/formcreator/commit/22f3508))
+* **ui:** tinymce may ot load ([86893f4](https://github.com-btry/pluginsGLPI/formcreator/commit/86893f4))
+* **ui:** too long localized string ([c83323d](https://github.com-btry/pluginsGLPI/formcreator/commit/c83323d))
+* **wizard:** bookmark was renamed into saved search i GLPI 9.2 ([02c2877](https://github.com-btry/pluginsGLPI/formcreator/commit/02c2877)), closes [#799](https://github.com-btry/pluginsGLPI/formcreator/issues/799)
+
+
+### Features
+
+* **file:** use enhanced file field ([988136a](https://github.com-btry/pluginsGLPI/formcreator/commit/988136a))
+* **install:** prepare upgrade code ([0c8c64f](https://github.com-btry/pluginsGLPI/formcreator/commit/0c8c64f))
+
+
Version 2.6.0
-------------
diff --git a/README.md b/README.md
index fa6bc97d9..bf93c6928 100644
--- a/README.md
+++ b/README.md
@@ -75,7 +75,7 @@ Formcreator est un plugin permettant la création de formulaires personalisés s
Pour plus d'informations, visitez la [documentation (en anglais)](http://glpi-plugins.readthedocs.io/fr/latest/formcreator/)
-## Upgrade to 2.6.0
+## Mise à jour vers 2.6.0
Quand un formulaire contient plusieurs tickets destination et un champ d'envoi de fichier, le document téléversé était rattaché à t ous les tickets générés. A partir de la version 2.6.0 un document est rattaché à un ticket généré dans deux cas :
* si la balise ##FULLFORM## est utilisée
diff --git a/RoboFile.php b/RoboFile.php
index 682b37acb..324032a44 100644
--- a/RoboFile.php
+++ b/RoboFile.php
@@ -1,4 +1,6 @@
getPluginPath());
+ return basename($this->getProjectPath());
}
protected function getVersion() {
- $setupFile = $this->getPluginPath(). "/setup.php";
+ $setupFile = $this->getProjectPath(). "/setup.php";
$setupContent = file_get_contents($setupFile);
$pluginName = $this->getPluginName();
$constantName = "PLUGIN_" . strtoupper($this->getPluginName()) . "_VERSION";
@@ -48,7 +50,7 @@ protected function getVersion() {
}
protected function getGLPIMinVersion() {
- $setupFile = $this->getPluginPath(). "/setup.php";
+ $setupFile = $this->getProjectPath(). "/setup.php";
$setupContent = file_get_contents($setupFile);
$pluginName = $this->getPluginName();
$constantName = "PLUGIN_" . strtoupper($this->getPluginName()) . "_GLPI_MIN_VERSION";
@@ -77,25 +79,34 @@ public function archiveBuild() {
throw new Exception("$version is not semver compliant. See http://semver.org/");
}
- if (!$this->tagExists($version)) {
- throw new Exception("The tag $version does not exists yet");
+ if ($this->tagExists($version)) {
+ throw new Exception("The tag $version already exists");
}
- if (!$this->isTagMatchesCurrentCommit($version)) {
- throw new Exception("HEAD is not pointing to the tag of the version to build");
- }
+ //if (!$this->isTagMatchesCurrentCommit($version)) {
+ //throw new Exception("HEAD is not pointing to the tag of the version to build");
+ //}
$versionTag = $this->getVersionTagFromXML($version);
if (!is_array($versionTag)) {
throw new Exception("The version does not exists in the XML file");
}
+ // update version in package.json
+ $this->sourceUpdatePackageJson($version);
+ $this->sourceUpdateComposerJson($version);
+
+ $this->updateChangelog();
+
+ $this->gitCommit(['package.json', 'composer.json'], "docs: bump version in JSON files");
+ $this->gitCommit(['CHANGELOG.md'], "docs(changelog): update changelog");
+
$pluginName = $this->getPluginName();
- $pluginPath = $this->getPluginPath();
+ $pluginPath = $this->getProjectPath();
$targetFile = $pluginPath. "/dist/glpi-" . $this->getPluginName() . "-$version.tar.bz2";
- $toArchive = implode(' ', $this->getFileToArchive($version));
+ $toArchive = implode(' ', $this->getFileToArchive("HEAD"));
@mkdir($pluginPath. "/dist");
- $this->_exec("git archive --prefix=$pluginName/ $version $toArchive | bzip2 > $targetFile");
+ $this->_exec("git archive --prefix=$pluginName/ HEAD $toArchive | bzip2 > $targetFile");
}
protected function getTrackedFiles($version) {
@@ -208,9 +219,43 @@ protected function isTagMatchesCurrentCommit($tag) {
return false;
}
+ /**
+ * @param array $files files to commit
+ * @param string $commitMessage commit message
+ */
+ protected function gitCommit(array $files, $commitMessage) {
+ if (count($files) < 1) {
+ $arg = '-u';
+ } else {
+ $arg = '"' . implode('" "', $files) . '"';
+ }
+ exec("git add $arg", $output, $retCode);
+ if ($retCode > 0) {
+ throw new Exception("Failed to add files for $commitMessage");
+ }
+
+ exec("git commit -m \"$commitMessage\"", $output, $retCode);
+ if ($retCode > 0) {
+ throw new Exception("Failed to commit $commitMessage");
+ }
+
+ return true;
+ }
+
+ /**
+ */
+ protected function updateChangelog() {
+ exec("node_modules/.bin/conventional-changelog -p angular -i CHANGELOG.md -s", $output, $retCode);
+ if ($retCode > 0) {
+ throw new Exception("Failed to update the changelog");
+ }
+
+ return true;
+ }
+
public function localesExtract() {
- $potfile = strtolower($this->getPluginName()) . ".pot";
- $phpSources = "*.php ajax/*.php front/*.php inc/*.php install/*.php";
+ $potfile = strtolower("glpi.pot");
+ $phpSources = "*.php ajax/*.php front/*.php inc/*.php inc/fields/*.php install/*.php js/*.php";
// extract locales from source code
$command = "xgettext $phpSources -o locales/$potfile -L PHP --add-comments=TRANS --from-code=UTF-8 --force-po";
$command.= " --keyword=_n:1,2,4t --keyword=__s:1,2t --keyword=__:1,2t --keyword=_e:1,2t --keyword=_x:1c,2,3t --keyword=_ex:1c,2,3t";
@@ -219,4 +264,60 @@ public function localesExtract() {
return $this;
}
-}
\ No newline at end of file
+ /**
+ * Build MO files
+ *
+ * @return void
+ */
+ public function localesMo() {
+ $localesPath = $this->getProjectPath() . '/locales';
+ if ($handle = opendir($localesPath)) {
+ while (($file = readdir($handle)) !== false) {
+ if ($file != "." && $file != "..") {
+ $poFile = "$localesPath/$file";
+ if (pathinfo($poFile, PATHINFO_EXTENSION) == 'po') {
+ $moFile = str_replace('.po', '.mo', $poFile);
+ $command = "msgfmt $poFile -o $moFile";
+ $this->_exec($command);
+ }
+ }
+ }
+ closedir($handle);
+ }
+ return $this;
+ }
+
+ /**
+ *
+ * @param string $filename
+ * @param string $version
+ */
+ protected function updateJsonFile($filename, $version) {
+ // get Package JSON
+ $filename = __DIR__ . "/$filename";
+ $jsonContent = file_get_contents($filename);
+ $jsonContent = json_decode($jsonContent, true);
+
+ // update version
+ if (empty($version)) {
+ echo "Version not found in setup.php\n";
+ return;
+ }
+ $jsonContent['version'] = $version;
+ file_put_contents($filename, json_encode($jsonContent, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES) . "\n");
+ }
+
+ /**
+ * @param $version
+ */
+ protected function sourceUpdatePackageJson($version) {
+ $this->updateJsonFile('package.json', $version);
+ }
+
+ /**
+ * @param string $version
+ */
+ protected function sourceUpdateComposerJson($version) {
+ $this->updateJsonFile('composer.json', $version);
+ }
+}
diff --git a/composer.json b/composer.json
index d9f545751..a2998cd0e 100644
--- a/composer.json
+++ b/composer.json
@@ -7,6 +7,8 @@
},
"require-dev": {
"phpunit/phpunit": "^4.8 || ^5.7 || ^6.0",
- "glpi-project/tools": "^0.1.0"
- }
+ "glpi-project/tools": "^0.1.0",
+ "glpi-project/coding-standard": "0.5.0"
+ },
+ "version": "2.6.1"
}
diff --git a/composer.lock b/composer.lock
index 132fba730..eac379960 100644
--- a/composer.lock
+++ b/composer.lock
@@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
"This file is @generated automatically"
],
- "content-hash": "6bd2bddd060ab70475f15776c4c87303",
+ "content-hash": "130b51a4df0023be055391815fc0332d",
"packages": [],
"packages-dev": [
{
@@ -230,7 +230,7 @@
}
],
"description": "Modern task runner",
- "time": "2017-03-11 19:48:06"
+ "time": "2017-03-11T19:48:06+00:00"
},
{
"name": "container-interop/container-interop",
@@ -2383,6 +2383,9 @@
"stability-flags": [],
"prefer-stable": true,
"prefer-lowest": false,
- "platform": [],
+ "platform": {
+ "php": ">= 5.4.0",
+ "ext-xml": "*"
+ },
"platform-dev": []
}
diff --git a/front/form_answer.form.php b/front/form_answer.form.php
index f67410ba6..7487ab5c7 100644
--- a/front/form_answer.form.php
+++ b/front/form_answer.form.php
@@ -32,7 +32,12 @@
$_POST['plugin_formcreator_forms_id'] = intval($_POST['formcreator_form']);
$_POST['status'] = 'waiting';
$formanswer->saveAnswers($_POST);
- $formanswer->redirectToList();
+ if (plugin_formcreator_replaceHelpdesk()) {
+ $issue = new PluginFormcreatorIssue();
+ $issue->redirectToList();
+ } else {
+ $formanswer->redirectToList();
+ }
// Show target ticket form
} else {
diff --git a/front/issue.form.php b/front/issue.form.php
index d518f8d17..1d351ad70 100644
--- a/front/issue.form.php
+++ b/front/issue.form.php
@@ -11,6 +11,10 @@
Html::displayNotFoundError();
}
+// force layout of glpi
+$layout = $_SESSION['glpilayout'];
+$_SESSION['glpilayout'] = "lefttab";
+
$issue = new PluginFormcreatorIssue();
if (isset($_POST['save_formanswer'])) {
$_POST['plugin_formcreator_forms_id'] = intval($_POST['formcreator_form']);
@@ -33,3 +37,6 @@
Html::footer();
}
}
+
+// restore layout
+$_SESSION['glpilayout'] = $layout;
\ No newline at end of file
diff --git a/front/question.form.php b/front/question.form.php
index 19ccd9d9e..91f455722 100644
--- a/front/question.form.php
+++ b/front/question.form.php
@@ -45,7 +45,7 @@
} else if (isset($_POST["set_required"])) {
// Set a Question required
$question = new PluginFormcreatorQuestion();
- $question->gtFromDB((int) $_POST['id']);
+ $question->getFromDB((int) $_POST['id']);
$question->update(['required' => $_POST['value']] + $question->fields);
} else if (isset($_POST["move"])) {
diff --git a/front/section.form.php b/front/section.form.php
index 04308562a..b60c1e3e8 100644
--- a/front/section.form.php
+++ b/front/section.form.php
@@ -8,33 +8,34 @@
if ($plugin->isActivated("formcreator")) {
$section = new PluginFormcreatorSection();
- // Add a new Section
if (isset($_POST["add"])) {
+ // Add a new Section
Session::checkRight("entity", UPDATE);
$section->add($_POST);
Html::redirect($CFG_GLPI["root_doc"] . '/plugins/formcreator/front/form.form.php?id=' . $_POST['plugin_formcreator_forms_id']);
- // Edit an existing Section
} else if (isset($_POST["update"])) {
+ // Edit an existing section
Session::checkRight("entity", UPDATE);
$section->update($_POST);
Html::redirect($CFG_GLPI["root_doc"] . '/plugins/formcreator/front/form.form.php?id=' . $_POST['plugin_formcreator_forms_id']);
- // Delete a Section
} else if (isset($_POST["delete_section"])) {
+ // Delete a Section
Session::checkRight("entity", UPDATE);
$section->delete($_POST);
- Html::redirect($CFG_GLPI["root_doc"] . '/plugins/formcreator/front/form.form.php?id=' . $_POST['plugin_formcreator_forms_id']);
+ // Page refresh handled by Javascript
- // Duplicate a Section
} else if (isset($_POST["duplicate_section"])) {
+ // Duplicate a Section
Session::checkRight("entity", UPDATE);
if ($section->getFromDB((int) $_POST['id'])) {
$section->duplicate();
}
+ // Page refresh handled by Javascript
- // Move a Section
} else if (isset($_POST["move"])) {
+ // Move a Section
Session::checkRight("entity", UPDATE);
if ($section->getFromDB((int) $_POST['id'])) {
@@ -44,11 +45,10 @@
$section->moveDown();
}
}
-
// Page refresh handled by Javascript
- // Return to form list
} else {
+ // Return to form list
Html::redirect($CFG_GLPI["root_doc"] . '/plugins/formcreator/front/form.php');
}
diff --git a/front/target.form.php b/front/target.form.php
index ecbd1b8aa..e9346adcc 100644
--- a/front/target.form.php
+++ b/front/target.form.php
@@ -10,13 +10,11 @@
// Add a new target
if (isset($_POST["add"]) && !empty($_POST['plugin_formcreator_forms_id'])) {
- Session::checkRight("entity", UPDATE);
$target->add($_POST);
Html::back();
// Delete a target
} else if (isset($_POST["delete_target"])) {
- Session::checkRight("entity", UPDATE);
$target->delete($_POST);
Html::redirect($CFG_GLPI["root_doc"] . '/plugins/formcreator/front/form.form.php?id=' . $_POST['plugin_formcreator_forms_id']);
diff --git a/front/targetchange.form.php b/front/targetchange.form.php
index 1169dc10e..b0a5d9a0d 100644
--- a/front/targetchange.form.php
+++ b/front/targetchange.form.php
@@ -12,17 +12,14 @@
// Edit an existing target change
if (isset($_POST["update"])) {
- Session::checkRight("entity", UPDATE);
-
$target = new PluginFormcreatorTarget();
$found = $target->find('items_id = ' . (int) $_POST['id']);
$found = array_shift($found);
- $target->update(['id' => $found['id'], 'name' => $name]);
+ $target->update(['id' => $found['id'], 'name' => $_POST['name']]);
$targetticket->update($_POST);
Html::back();
} else if (isset($_POST['actor_role'])) {
- Session::checkRight("entity", UPDATE);
$id = (int) $_POST['id'];
$actor_value = isset($_POST['actor_value_' . $_POST['actor_type']])
? $_POST['actor_value_' . $_POST['actor_type']]
diff --git a/front/targetticket.form.php b/front/targetticket.form.php
index fbd3d43dd..d6891a802 100644
--- a/front/targetticket.form.php
+++ b/front/targetticket.form.php
@@ -12,8 +12,6 @@
// Edit an existing target ticket
if (isset($_POST["update"])) {
- Session::checkRight("entity", UPDATE);
-
$target = new PluginFormcreatorTarget();
$found = $target->find('items_id = ' . (int) $_POST['id']);
$found = array_shift($found);
@@ -22,7 +20,6 @@
Html::back();
} else if (isset($_POST['actor_role'])) {
- Session::checkRight("entity", UPDATE);
$id = (int) $_POST['id'];
$actor_value = isset($_POST['actor_value_' . $_POST['actor_type']])
? $_POST['actor_value_' . $_POST['actor_type']]
diff --git a/inc/common.class.php b/inc/common.class.php
index dbebfc870..046c3d27b 100644
--- a/inc/common.class.php
+++ b/inc/common.class.php
@@ -5,8 +5,7 @@
}
class PluginFormcreatorCommon {
-
- static function getEnumValues($table, $field) {
+ public static function getEnumValues($table, $field) {
global $DB;
$enum = [];
@@ -21,20 +20,20 @@ static function getEnumValues($table, $field) {
return $enum;
}
- static function isNotificationEnabled() {
+ public static function isNotificationEnabled() {
global $CFG_GLPI;
$notification = $CFG_GLPI['use_notifications'];
return ($notification == '1');
}
- static function setNotification($enable) {
+ public static function setNotification($enable) {
global $CFG_GLPI;
$CFG_GLPI['use_notifications'] = $enable ? '1' : '0';
}
- static function getGlpiVersion() {
+ public static function getGlpiVersion() {
return defined('GLPI_PREVER')
? GLPI_PREVER
: GLPI_VERSION;
@@ -48,7 +47,7 @@ static function getGlpiVersion() {
*
* @return string
**/
- static function getLinkName($value, $inverted = false) {
+ public static function getLinkName($value, $inverted = false) {
$tmp = [];
if (!$inverted) {
@@ -69,4 +68,22 @@ static function getLinkName($value, $inverted = false) {
return NOT_AVAILABLE;
}
+ /**
+ * Gets the ID of Formcreator request type
+ */
+ public static function getFormcreatorRequestTypeId() {
+ global $DB;
+
+ $requesttypes_id = 0;
+ $request = $DB->request(
+ RequestType::getTable(),
+ ['name' => ['LIKE', 'Formcreator']]
+ );
+ if (count($request) === 1) {
+ $row = $request->next();
+ $requesttypes_id = $row['id'];
+ }
+
+ return $requesttypes_id;
+ }
}
diff --git a/inc/fields.class.php b/inc/fields.class.php
index 2d76f25da..156bc19fd 100644
--- a/inc/fields.class.php
+++ b/inc/fields.class.php
@@ -160,7 +160,7 @@ public static function isVisible($id, $values) {
foreach ($questionConditions as $question_condition) {
$conditions[] = [
'logic' => $question_condition->getField('show_logic'),
- 'field' => $question_condition->getField('show_field'),
+ 'field' => 'formcreator_field_' . $question_condition->getField('show_field'),
'operator' => $question_condition->getField('show_condition'),
'value' => $question_condition->getField('show_value')
];
diff --git a/inc/fields/checkboxesfield.class.php b/inc/fields/checkboxesfield.class.php
index 46b7bcab1..67fa0a3bf 100644
--- a/inc/fields/checkboxesfield.class.php
+++ b/inc/fields/checkboxesfield.class.php
@@ -109,12 +109,10 @@ public function prepareQuestionInputForSave($input) {
return [];
} else {
$input['values'] = $this->trimValue($input['values']);
- $input['values'] = addslashes($input['values']);
}
}
if (isset($input['default_values'])) {
$input['default_values'] = $this->trimValue($input['default_values']);
- $input['default_values'] = addslashes($input['default_values']);
}
return $input;
}
diff --git a/inc/fields/filefield.class.php b/inc/fields/filefield.class.php
index 341ed5331..6ac3ada86 100644
--- a/inc/fields/filefield.class.php
+++ b/inc/fields/filefield.class.php
@@ -8,9 +8,11 @@ public function displayField($canEdit = true) {
echo '' . PHP_EOL;
- echo '';
+ echo Html::file([
+ 'name' => 'formcreator_field_' . $this->fields['id'],
+ 'display' => false,
+ ]);
+
} else {
$doc = new Document();
$answer = $this->getAnswer();
@@ -22,8 +24,8 @@ public function displayField($canEdit = true) {
public function isValid($value) {
// If the field is required it can't be empty
- if ($this->isRequired() && (empty($_FILES['formcreator_field_' . $this->fields['id']]['tmp_name'])
- || !is_file($_FILES['formcreator_field_' . $this->fields['id']]['tmp_name']))) {
+ if ($this->isRequired() && (empty($_POST['_formcreator_field_' . $this->fields['id']][0])
+ || !is_file(GLPI_TMP_DIR . '/' . $_POST['_formcreator_field_' . $this->fields['id']][0]))) {
Session::addMessageAfterRedirect(__('A required file is missing:', 'formcreator') . ' ' . $this->fields['name'], false, ERROR);
return false;
}
diff --git a/inc/fields/ipfield.class.php b/inc/fields/ipfield.class.php
index 3bdd12819..6b6140705 100644
--- a/inc/fields/ipfield.class.php
+++ b/inc/fields/ipfield.class.php
@@ -2,12 +2,7 @@
class PluginFormcreatorIpField extends PluginFormcreatorField
{
public function show($canEdit = true) {
- if (method_exists('Toolbox', 'getRemoteIpAddress')) {
- $ip = Toolbox::getRemoteIpAddress();
- } else {
- $ip = (isset($_SERVER["HTTP_X_FORWARDED_FOR"]) ? $_SERVER["HTTP_X_FORWARDED_FOR"]
- : $_SERVER["REMOTE_ADDR"]);
- }
+ $ip = Toolbox::getRemoteIpAddress();
echo 'getAnswer();
echo '
';
- echo empty($answer) ? '' : implode('
', json_decode($answer));
+ echo empty($answer) ? '' : implode('
', $answer);
echo '
';
}
}
@@ -64,7 +64,7 @@ public function getAnswer() {
$return[] = $value;
}
}
- return json_encode($return);
+ return $return;
}
public static function getName() {
diff --git a/inc/fields/radiosfield.class.php b/inc/fields/radiosfield.class.php
index d7891c65f..6ec758bf7 100644
--- a/inc/fields/radiosfield.class.php
+++ b/inc/fields/radiosfield.class.php
@@ -57,13 +57,11 @@ public function prepareQuestionInputForSave($input) {
} else {
// trim values
$input['values'] = $this->trimValue($input['values']);
- $input['values'] = addslashes($input['values']);
}
}
if (isset($input['default_values'])) {
// trim values
$input['default_values'] = $this->trimValue($input['default_values']);
- $input['default_values'] = addslashes($input['default_values']);
}
return $input;
}
diff --git a/inc/fields/selectfield.class.php b/inc/fields/selectfield.class.php
index f7f87c457..7f794208a 100644
--- a/inc/fields/selectfield.class.php
+++ b/inc/fields/selectfield.class.php
@@ -12,7 +12,11 @@ public function displayField($canEdit = true) {
if (!empty($this->fields['values'])) {
foreach ($values as $value) {
if ((trim($value) != '')) {
- $tab_values[$value] = $value;
+ if (version_compare(GLPI_VERSION, '9.2.1') <= 0) {
+ $tab_values[Html::entities_deep($value)] = $value;
+ } else {
+ $tab_values[$value] = $value;
+ }
}
}
@@ -63,13 +67,11 @@ public function prepareQuestionInputForSave($input) {
} else {
// trim values
$input['values'] = $this->trimValue($input['values']);
- $input['values'] = addslashes($input['values']);
}
}
if (isset($input['default_values'])) {
// trim values
$input['default_values'] = $this->trimValue($input['default_values']);
- $input['default_values'] = addslashes($input['default_values']);
}
return $input;
}
diff --git a/inc/form.class.php b/inc/form.class.php
index 13666e231..165aaeb18 100644
--- a/inc/form.class.php
+++ b/inc/form.class.php
@@ -132,14 +132,14 @@ public function getSearchOptionsNew() {
'searchtype' => [
'0' => 'equals'
],
- 'massiveaction' => false
+ 'massiveaction' => true
];
$tab[] = [
'id' => '8',
'table' => $this->getTable(),
'field' => 'helpdesk_home',
- 'name' => __('Homepage'),
+ 'name' => __('Homepage', 'formcreator'),
'datatype' => 'bool',
'searchtype' => [
'0' => 'equals',
@@ -165,7 +165,7 @@ public function getSearchOptionsNew() {
'id' => '10',
'table' => 'glpi_plugin_formcreator_categories',
'field' => 'name',
- 'name' => __('Form category'),
+ 'name' => __('Form category', 'formcreator'),
'datatype' => 'dropdown',
'massiveaction' => true
];
@@ -207,29 +207,30 @@ public static function getSpecificValueToSelect($field, $name='', $values='', ar
switch ($field) {
case 'is_active' :
- return Dropdown::showFromArray('criteria[0][value]', [
+ return Dropdown::showFromArray($name, [
'0' => __('Inactive'),
'1' => __('Active'),
], [
'value' => $values[$field],
- 'display_emptychoice' => true,
+ 'display_emptychoice' => false,
'display' => false
]);
break;
+
case 'access_rights' :
- return Dropdown::showFromArray('criteria[0][value]', [
- Dropdown::EMPTY_VALUE => '--- ' . __('All langages', 'formcreator') . ' ---',
+ return Dropdown::showFromArray($name, [
self::ACCESS_PUBLIC => __('Public access', 'formcreator'),
self::ACCESS_PRIVATE => __('Private access', 'formcreator'),
self::ACCESS_RESTRICTED => __('Restricted access', 'formcreator'),
], [
'value' => $values[$field],
- 'display_emptychoice' => true,
+ 'display_emptychoice' => false,
'display' => false
]);
break;
+
case 'language' :
- return Dropdown::showLanguages('criteria[0][value]', [
+ return Dropdown::showLanguages($name, [
'value' => $values[$field],
'display_emptychoice' => true,
'emptylabel' => '--- ' . __('All langages', 'formcreator') . ' ---',
@@ -269,20 +270,24 @@ public static function getSpecificValueToDisplay($field, $values, array $options
}
return $output;
break;
+
case 'access_rights':
switch ($values[$field]) {
case self::ACCESS_PUBLIC :
return __('Public access', 'formcreator');
break;
+
case self::ACCESS_PRIVATE :
return __('Private access', 'formcreator');
break;
+
case self::ACCESS_RESTRICTED :
return __('Restricted access', 'formcreator');
break;
}
return '';
break;
+
case 'language' :
if (empty($values[$field])) {
return __('All langages', 'formcreator');
@@ -451,7 +456,6 @@ public function showForm($ID, $options=[]) {
document.getElementById("validators_users").style.display = "none";
document.getElementById("validators_groups").style.display = "none";
}
- fcInitMultiSelect();
}
$(document).ready(function() {changeValidators(' . $this->fields["validation_required"] . ');});';
echo Html::scriptBlock($script);
@@ -567,7 +571,6 @@ public function showServiceCatalog() {
}
public function showWizard($service_catalog = false) {
-
echo '';
echo '
'._n("Category", "Categories", 2, 'formcreator').'
';
echo '
';
@@ -911,8 +914,8 @@ class='formcreator_form form_horizontal'>";
}
}
echo Html::scriptBlock('$(function() {
- formcreatorShowFields();
- })');
+ formcreatorShowFields();
+ })');
// Show validator selector
if ($item->fields['validation_required'] > 0) {
@@ -1103,7 +1106,7 @@ public function saveForm($input) {
$valid = true;
$data = [];
- // Validate form fields
+ // Prepare form fields for validation
$question = new PluginFormcreatorQuestion();
$found_questions = $question->getQuestionsFromForm($this->getID());
foreach ($found_questions as $id => $question) {
@@ -1122,7 +1125,10 @@ public function saveForm($input) {
} else {
$data['formcreator_field_' . $id] = '';
}
+ }
+ // Validate form fields
+ foreach ($found_questions as $id => $question) {
$className = 'PluginFormcreator' . ucfirst($question->getField('fieldtype')) . 'Field';
if (class_exists($className)) {
@@ -1203,7 +1209,9 @@ public function getByQuestionId($questionId) {
public function duplicate() {
$target = new PluginFormcreatorTarget();
$target_ticket = new PluginFormcreatorTargetTicket();
+ $target_change = new PluginFormcreatorTargetChange();
$target_ticket_actor = new PluginFormcreatorTargetTicket_Actor();
+ $target_change_actor = new PluginFormcreatorTargetChange_Actor();
$form_section = new PluginFormcreatorSection();
$section_question = new PluginFormcreatorQuestion();
$question_condition = new PluginFormcreatorQuestion_Condition();
@@ -1211,12 +1219,12 @@ public function duplicate() {
$form_profile = new PluginFormcreatorForm_Profile();
$tab_questions = [];
- // From datas
+ // From data
$form_datas = $this->fields;
$form_datas['name'] .= ' [' . __('Duplicate', 'formcreator') . ']';
$form_datas['is_active'] = 0;
- unset($form_datas['id']);
+ unset($form_datas['id'], $form_datas['uuid']);
$old_form_id = $this->getID();
$new_form_id = $this->add($form_datas);
@@ -1230,7 +1238,7 @@ public function duplicate() {
unset($row['id'],
$row['uuid']);
$row['plugin_formcreator_forms_id'] = $new_form_id;
- if (!$form_validator->add($row)) {
+ if (!$form_profile->add($row)) {
return false;
}
}
@@ -1290,44 +1298,166 @@ public function duplicate() {
unset($target_values['id'],
$target_values['uuid']);
$target_values['plugin_formcreator_forms_id'] = $new_form_id;
+
if (!$target->add($target_values)) {
return false;
}
- if (!$target_ticket->getFromDB($target_values['items_id'])) {
- return false;
- }
+ $new_target_item_id = $target->getField('items_id');
+ switch ($target_values['itemtype']) {
+ case PluginFormcreatorTargetTicket::class:
+ // Get the original target ticket
+ if (!$target_ticket->getFromDB($target_values['items_id'])) {
+ return false;
+ }
- $update_target_ticket = $target_ticket->fields;
- unset($update_target_ticket['id'], $update_target_ticket['uuid']);
- foreach ($tab_questions as $id => $value) {
- $update_target_ticket['name'] = str_replace('##question_' . $id . '##', '##question_' . $value . '##', $update_target_ticket['name']);
- $update_target_ticket['name'] = str_replace('##answer_' . $id . '##', '##answer_' . $value . '##', $update_target_ticket['name']);
- $update_target_ticket['comment'] = str_replace('##question_' . $id . '##', '##question_' . $value . '##', $update_target_ticket['comment']);
- $update_target_ticket['comment'] = str_replace('##answer_' . $id . '##', '##answer_' . $value . '##', $update_target_ticket['comment']);
- }
+ // Update the target ticket created while cloning the target
+ $update_target_ticket = $target_ticket->fields;
+ $update_target_ticket['id'] = $new_target_item_id;
+ unset($update_target_ticket['uuid']);
+ foreach ($tab_questions as $id => $value) {
+ $update_target_ticket['name'] = str_replace('##question_' . $id . '##', '##question_' . $value . '##', $update_target_ticket['name']);
+ $update_target_ticket['name'] = str_replace('##answer_' . $id . '##', '##answer_' . $value . '##', $update_target_ticket['name']);
+ $update_target_ticket['comment'] = str_replace('##question_' . $id . '##', '##question_' . $value . '##', $update_target_ticket['comment']);
+ $update_target_ticket['comment'] = str_replace('##answer_' . $id . '##', '##answer_' . $value . '##', $update_target_ticket['comment']);
+ }
- $new_target_ticket = new PluginFormcreatorTargetTicket();
- $new_target_ticket->add($update_target_ticket);
- $new_target_ticket_id = $new_target_ticket->getID();
- if (!$new_target_ticket_id) {
- return false;
+ // update time to resolve rule
+ if ($update_target_ticket['due_date_rule'] == 'answer'
+ || $update_target_ticket['due_date_rule'] == 'calcul') {
+ $update_target_ticket['due_date_question'] = $tab_questions[$update_target_ticket['due_date_question']];
+ }
+
+ // update urgency rule
+ if ($update_target_ticket['urgency_rule'] == 'answer') {
+ $update_target_ticket['urgency_question'] = $tab_questions[$update_target_ticket['urgency_question']];
+ }
+
+ // update destination entity
+ if ($update_target_ticket['destination_entity'] == 'user'
+ || $update_target_ticket['destination_entity'] == 'entity') {
+ $update_target_ticket['destination_entity_value'] = $tab_questions[$update_target_ticket['destination_entity_value']];
+ }
+
+ //update category
+ if ($update_target_ticket['category_rule'] == 'answer') {
+ $update_target_ticket['category_question'] = $tab_questions[$update_target_ticket['category_question']];
+ }
+
+ //update location
+ if ($update_target_ticket['location_rule'] == 'answer') {
+ $update_target_ticket['location_question'] = $tab_questions[$update_target_ticket['location_question']];
+ }
+
+ $new_target_ticket = new PluginFormcreatorTargetTicket();
+ $update_target_ticket['title'] = Toolbox::addslashes_deep($update_target_ticket['name']);
+ $update_target_ticket['comment'] = Toolbox::addslashes_deep($update_target_ticket['comment']);
+ if (!$new_target_ticket->update($update_target_ticket)) {
+ return false;
+ }
+ break;
+
+ case PluginFormcreatorTargetChange::class:
+ // Get the original target change
+ if (!$target_change->getFromDB($target_values['items_id'])) {
+ return false;
+ }
+
+ // Update the target change created while cloning the target
+ $update_target_change = $target_change->fields;
+ $update_target_change['id'] = $new_target_item_id;
+ unset($update_target_change['uuid']);
+ foreach ($tab_questions as $id => $value) {
+ $changeFields = [
+ 'name',
+ 'comment',
+ 'impactcontent',
+ 'controlistcontent',
+ 'rolloutplancontent',
+ 'backoutplancontent',
+ 'checklistcontent'
+ ];
+ foreach ($changeFields as $changeField) {
+ $update_target_change[$changeField] = str_replace(
+ '##question_' . $id . '##',
+ '##question_' . $value . '##',
+ $update_target_change[$changeField]
+ );
+ $update_target_change[$changeField] = str_replace(
+ '##answer_' . $id . '##',
+ '##answer_' . $value . '##',
+ $update_target_change[$changeField]
+ );
+ }
+ }
+
+ // update time to resolve rule
+ if ($update_target_change['due_date_rule'] == 'answer'
+ || $update_target_change['due_date_rule'] == 'calcul') {
+ $update_target_change['due_date_question'] = $tab_questions[$update_target_change['due_date_question']];
+ }
+
+ // update urgency rule
+ if ($update_target_change['urgency_rule'] == 'answer') {
+ $update_target_change['urgency_question'] = $tab_questions[$update_target_change['urgency_question']];
+ }
+
+ // update destination entity
+ if ($update_target_change['destination_entity'] == 'user'
+ || $update_target_change['destination_entity'] == 'entity') {
+ $update_target_change['destination_entity_value'] = $tab_questions[$update_target_change['destination_entity_value']];
+ }
+
+ //update category
+ if ($update_target_change['category_rule'] == 'answer') {
+ $update_target_change['category_question'] = $tab_questions[$update_target_change['category_question']];
+ }
+
+ $new_target_change = new PluginFormcreatorTargetChange();
+ $update_target_change['title'] = Toolbox::addslashes_deep($update_target_change['name']);
+ $update_target_change['comment'] = Toolbox::addslashes_deep($update_target_change['comment']);
+ if (!$new_target_change->update($update_target_change)) {
+ return false;
+ }
+ break;
}
- $target->update([
- 'id' => $target->getID(),
- 'items_id' => $new_target_ticket_id,
- ]);
+ switch ($target_values['itemtype']) {
+ case PluginFormcreatorTargetTicket::class:
+ // Drop default actors
+ $target_ticket_actor->deleteByCriteria([
+ 'plugin_formcreator_targettickets_id' => $new_target_item_id
+ ]);
+
+ // Form target tickets actors
+ $rows = $target_ticket_actor->find("`plugin_formcreator_targettickets_id` = '{$target_values['items_id']}'");
+ foreach ($rows as $row) {
+ unset($row['id'],
+ $row['uuid']);
+ $row['plugin_formcreator_targettickets_id'] = $new_target_item_id;
+ if (!$target_ticket_actor->add($row)) {
+ return false;
+ }
+ }
+ break;
- // Form target tickets actors
- $rows = $target_ticket_actor->find("`plugin_formcreator_targettickets_id` = '{$target_values['items_id']}'");
- foreach ($rows as $row) {
- unset($row['id'],
- $row['uuid']);
- $row['plugin_formcreator_targettickets_id'] = $new_target_ticket_id;
- if (!$target_ticket_actor->add($row)) {
- return false;
- }
+ case PluginFormcreatorTargetChange::class:
+ // Drop default actors
+ $target_ticket_actor->deleteByCriteria([
+ 'plugin_formcreator_targetchanges_id' => $new_target_item_id
+ ]);
+
+ // Form target change actors
+ $rows = $target_change_actor->find("`plugin_formcreator_targetchanges_id` = '{$target_values['items_id']}'");
+ foreach ($rows as $row) {
+ unset($row['id'],
+ $row['uuid']);
+ $row['plugin_formcreator_targetchanges_id'] = $new_target_item_id;
+ if (!$target_change_actor->add($row)) {
+ return false;
+ }
+ }
+ break;
}
}
@@ -1527,31 +1657,85 @@ function export($remove_uuid = false) {
* Display an html form to upload a json with forms data
*/
public function showImportForm() {
- echo "
';
+ } else {
+ echo "