Skip to content

Commit

Permalink
Merge branch 'support/2.13.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
btry committed Aug 22, 2023
2 parents 51d632a + a3f16ac commit 9157911
Show file tree
Hide file tree
Showing 60 changed files with 1,056 additions and 2,797 deletions.
41 changes: 41 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,44 @@
<a name="2.13.7"></a>
## [2.13.7](https://github.com/pluginsGLPI/formcreator/compare/2.13.6..2.13.7) (2023-07-19)


### Bug Fixes

* Adding READ right for display reservations menu tab ([03e6281e](https://github.com/pluginsGLPI/formcreator/commit/03e6281e))
* bad lcoale in en_US ([db9986f1](https://github.com/pluginsGLPI/formcreator/commit/db9986f1))
* resize dashboard to match GLPI's core (#3306) ([9272cda3](https://github.com/pluginsGLPI/formcreator/commit/9272cda3))
* show FAQ without tabs for self-service ([c5499ad4](https://github.com/pluginsGLPI/formcreator/commit/c5499ad4))
* **TargetChange:** use RichText instead of plaintext ([8845b888](https://github.com/pluginsGLPI/formcreator/commit/8845b888))
* **checkboxesfield,radiosfield,selectfield:** add missing error messages ([66585193](https://github.com/pluginsGLPI/formcreator/commit/66585193))
* **datefield, datetimefield:** comparison against empty string ([be4831c7](https://github.com/pluginsGLPI/formcreator/commit/be4831c7))
* **dropdownfield:** SQL error for GLPI objects / tickets and some specific rights ([2539e366](https://github.com/pluginsGLPI/formcreator/commit/2539e366))
* **dropdownfield:** handle specific case with Entity itemtype ([bd25e7d1](https://github.com/pluginsGLPI/formcreator/commit/bd25e7d1))
* **dropdownfield:** missing entity restriction setting ([54543cb3](https://github.com/pluginsGLPI/formcreator/commit/54543cb3))
* **dropdownfield:** prevent language switching and log error ([49f8fc07](https://github.com/pluginsGLPI/formcreator/commit/49f8fc07))
* **fieldsfield:** restore mandatory field as read only ([52a9fc2b](https://github.com/pluginsGLPI/formcreator/commit/52a9fc2b))
* **form,category:** obey show count on tabs parameter ([f4ebf9e5](https://github.com/pluginsGLPI/formcreator/commit/f4ebf9e5))
* **form_language:** obey show counter in tab setting ([9dfc3b8d](https://github.com/pluginsGLPI/formcreator/commit/9dfc3b8d))
* **formanswer:** php warning ([ce078990](https://github.com/pluginsGLPI/formcreator/commit/ce078990))
* **formanswer:** prevent silent rejection of answers ([d630302d](https://github.com/pluginsGLPI/formcreator/commit/d630302d))
* **formanswer:** redirect to login if session expired ([eb0acb65](https://github.com/pluginsGLPI/formcreator/commit/eb0acb65))
* **glpiselectfield:** fix namespace (#3287) ([613e0fad](https://github.com/pluginsGLPI/formcreator/commit/613e0fad))
* **install:** missing row in sql query, causing PHP warning ([0c47776a](https://github.com/pluginsGLPI/formcreator/commit/0c47776a))
* **issue:** php warnings when anonymisation enabled ([f6f01d7d](https://github.com/pluginsGLPI/formcreator/commit/f6f01d7d))
* **issue:** prevent fatal error in tooltip ([3419affc](https://github.com/pluginsGLPI/formcreator/commit/3419affc))
* **question,section:** duplicate a question or section must duplicate inner conditions ([22597832](https://github.com/pluginsGLPI/formcreator/commit/22597832))
* **section:** cannot rename section twice ([7bbb9b81](https://github.com/pluginsGLPI/formcreator/commit/7bbb9b81))
* **section:** condition rule loss after duplicate / import ([883a1227](https://github.com/pluginsGLPI/formcreator/commit/883a1227))
* **section:** duplicate form may lead to bad question id in condition ([a6f9c41c](https://github.com/pluginsGLPI/formcreator/commit/a6f9c41c))
* **section:** rename section impacts display of inner questions ([c4277d8c](https://github.com/pluginsGLPI/formcreator/commit/c4277d8c))
* **selectfield,multiselectfield:** fix possible encoding problem ([8aaec8ac](https://github.com/pluginsGLPI/formcreator/commit/8aaec8ac))
* **tag:** tag was always deleted ([6201d61d](https://github.com/pluginsGLPI/formcreator/commit/6201d61d))
* **targetchange,targetproblem:** folow method call signature for fields plugin ([016696ab](https://github.com/pluginsGLPI/formcreator/commit/016696ab))
* **textfield:** Unescaped HTML when displaying a form answer ([6ce71f95](https://github.com/pluginsGLPI/formcreator/commit/6ce71f95))
* **textfield:** exception while displaying counters ([0a857d7f](https://github.com/pluginsGLPI/formcreator/commit/0a857d7f))
* **textfield:** target ticket title need html encoding ([1b71d652](https://github.com/pluginsGLPI/formcreator/commit/1b71d652))



<a name="2.13.6"></a>
## [2.13.6](https://github.com/pluginsGLPI/formcreator/compare/2.13.5..2.13.6) (2023-05-26)

Expand Down
11 changes: 10 additions & 1 deletion RoboFilePlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,16 @@ public function localesPull($percent = 70) {
* @return void
*/
public function localesMo() {
$this->_exec('./tools/release --compile-mo');
$po_files = preg_grep('/\.po$/', scandir('./locales'));
foreach ($po_files as $po_file) {
$mo_file = preg_replace('/\.po$/', '.mo', $po_file);
echo("Processing {$po_file}\n");
passthru("cd ./locales && msgfmt -f -o {$mo_file} {$po_file}", $exit_code);
if ($exit_code > 0) {
exit($exit_code);
}
}

return $this;
}

Expand Down
2 changes: 1 addition & 1 deletion ajax/formanswer.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@

// Save form
$backup_debug = $_SESSION['glpi_use_mode'];
$_SESSION['glpi_use_mode'] = \Session::NORMAL_MODE;
$_SESSION['glpi_use_mode'] = Session::NORMAL_MODE;
$formAnswer = PluginFormcreatorCommon::getFormAnswer();
if ($formAnswer->add($_POST) === false) {
http_response_code(400);
Expand Down
2 changes: 1 addition & 1 deletion css/styles.scss
Original file line number Diff line number Diff line change
Expand Up @@ -1068,7 +1068,7 @@ a.plugin_formcreator_formTile_title {
}
}

/* TODO when the following PR is merged and minimal GLPI version is above the version containing it, remove this CSS */
/* remove this CSS when requirement is GLPI 10.0.1 or later */
/* https://github.com/glpi-project/glpi/pull/11524 */
.formcreator_dashboard_container .dashboard .big-number .label {
font-size: 12px !important;
Expand Down
2 changes: 2 additions & 0 deletions front/formanswer.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
Html::displayNotFoundError();
}

Session::checkLoginUser();

if (!PluginFormcreatorFormAnswer::canView()) {
Html::displayRightError();
}
Expand Down
4 changes: 1 addition & 3 deletions front/wizard.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,7 @@
Html::header(__('Service catalog', 'formcreator'));
}

if (PluginFormcreatorEntityconfig::getUsedConfig('is_dashboard_visible', Session::getActiveEntity()) == PluginFormcreatorEntityconfig::CONFIG_DASHBOARD_VISIBLE) {
PluginFormcreatorCommon::showMiniDashboard();
}
PluginFormcreatorCommon::showMiniDashboard();

$form = PluginFormcreatorCommon::getForm();
$form->showServiceCatalog();
Expand Down
8 changes: 5 additions & 3 deletions inc/abstracttarget.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -217,11 +217,11 @@ protected function prepareTemplate($template, PluginFormcreatorFormAnswer $formA
/**
* Append fields data to input
*
* @param PluginFormcreatorFormanswer $formanswer the source formanswer
* @param array $input data of the generated target
* @return void
* @param PluginFormcreatorFormanswer $formanswer the source formanswer
* @return array
*/
protected function appendFieldsData(PluginFormcreatorFormanswer $formanswer, &$input): void {
protected function appendFieldsData(array $input, PluginFormcreatorFormanswer $formanswer): array {
global $DB;

//get all PluginFormcreatorAnswer
Expand Down Expand Up @@ -262,6 +262,8 @@ protected function appendFieldsData(PluginFormcreatorFormanswer $formanswer, &$i
}
$input['c_id'] = $blocks_field;
}

return $input;
}


Expand Down
2 changes: 1 addition & 1 deletion inc/category.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public static function getTypeName($nb = 1) {
public function getTabNameForItem(CommonGLPI $item, $withtemplate = 0) {
$env = new self;
$found_env = $env->find([static::getForeignKeyField() => $item->getID()]);
$nb = count($found_env);
$nb = $_SESSION['glpishow_count_on_tabs'] ? count($found_env) : 0;
return self::createTabEntry(self::getTypeName($nb), $nb);
}

Expand Down
4 changes: 2 additions & 2 deletions inc/common.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -806,7 +806,7 @@ public static function hookRedefineMenu($menus) {
$newMenu['faq'] = $menus['faq'];
$newMenu['faq']['default'] = Plugin::getWebDir('formcreator', false) . '/front/knowbaseitem.php';
}
if (Session::haveRight("reservation", ReservationItem::RESERVEANITEM)) {
if (Session::haveRightsOr("reservation", [READ, ReservationItem::RESERVEANITEM])) {
if (isset($menus['reservation'])) {
$newMenu['reservation'] = $menus['reservation'];
}
Expand Down Expand Up @@ -871,7 +871,7 @@ public static function showMiniDashboard(): void {

if (PluginFormcreatorEntityconfig::getUsedConfig('is_dashboard_visible', Session::getActiveEntity()) == PluginFormcreatorEntityconfig::CONFIG_DASHBOARD_VISIBLE) {
if (version_compare(GLPI_VERSION, '10.0.3') > 0) {
$dashboard = new Glpi\Dashboard\Grid('plugin_formcreator_issue_counters', 33, 1, 'mini_core');
$dashboard = new Glpi\Dashboard\Grid('plugin_formcreator_issue_counters', 33, 2, 'mini_core');
} else {
$dashboard = new Glpi\Dashboard\Grid('plugin_formcreator_issue_counters', 33, 0, 'mini_core');
}
Expand Down
10 changes: 2 additions & 8 deletions inc/condition.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,14 +153,8 @@ public static function import(PluginFormcreatorLinker $linker, array $input = []
// set ID for linked objects
$linked = $linker->getObject($input['plugin_formcreator_questions_id'], PluginFormcreatorQuestion::class);
if ($linked === false) {
$linked = new PluginFormcreatorQuestion();
$linked->getFromDBByCrit([
$idKey => $input['plugin_formcreator_questions_id']
]);
if ($linked->isNewItem()) {
$linker->postpone($input[$idKey], $item->getType(), $input, $containerId);
return false;
}
$linker->postpone($input[$idKey], $item->getType(), $input, $containerId);
return false;
}
/** @var CommonDBTM $linked */
$input['plugin_formcreator_questions_id'] = $linked->getID();
Expand Down
10 changes: 10 additions & 0 deletions inc/field/checkboxesfield.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -204,9 +204,19 @@ public function isValidValue($value): bool {

foreach ($value as $item) {
if (trim($item) == '') {
Session::addMessageAfterRedirect(
sprintf(__('Empty values are not allowed: %s', 'formcreator'), $this->getTtranslatedLabel()),
false,
ERROR
);
return false;
}
if (!in_array($item, $this->getAvailableValues())) {
Session::addMessageAfterRedirect(
sprintf(__('This value %1$s is not alowed: %2$s', 'formcreator'), $item, $this->getTtranslatedLabel()),
false,
ERROR
);
return false;
}
}
Expand Down
161 changes: 15 additions & 146 deletions inc/field/datefield.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,32 +32,13 @@

namespace GlpiPlugin\Formcreator\Field;

use PluginFormcreatorAbstractField;
use Html;
use DateTime;
use Session;
use PluginFormcreatorFormAnswer;
use GlpiPlugin\Formcreator\Exception\ComparisonException;
use Glpi\Application\View\TemplateRenderer;

class DateField extends PluginFormcreatorAbstractField
class DateField extends DatetimeField
{
const DATE_FORMAT = 'Y-m-d';

public function isPrerequisites(): bool {
return true;
}

public function showForm(array $options): void {
$template = '@formcreator/field/' . $this->question->fields['fieldtype'] . 'field.html.twig';

$this->question->fields['default_values'] = Html::entities_deep($this->question->fields['default_values']);
$this->deserializeValue($this->question->fields['default_values']);
TemplateRenderer::getInstance()->display($template, [
'item' => $this->question,
'params' => $options,
]);
}
const DATE_ZERO = '0000-00-00';

public function getRenderedHtml($domain, $canEdit = true): string {
if (!$canEdit) {
Expand All @@ -81,137 +62,25 @@ public function getRenderedHtml($domain, $canEdit = true): string {
return $html;
}

public function serializeValue(PluginFormcreatorFormAnswer $formanswer): string {
return $this->value;
}

public function deserializeValue($value) {
$this->value = $value;
}

public function getValueForDesign(): string {
return $this->value;
}

public function getValueForTargetText($domain, $richText): ?string {
return Html::convDate($this->value);
}

public function hasInput($input): bool {
return isset($input['formcreator_field_' . $this->question->getID()]);
}

public function moveUploads() {
}

public function getDocumentsForTarget(): array {
return [];
}

public function isValid(): bool {
// If the field is required it can't be empty
if ($this->isRequired() && (strtotime($this->value) == '')) {
Session::addMessageAfterRedirect(
sprintf(__('A required field is empty: %s', 'formcreator'), $this->getTtranslatedLabel()),
false,
ERROR
);
return false;
}

// All is OK
return $this->isValidValue($this->value);
}

public function isValidValue($value): bool {
if (!$this->isRequired() && empty($value)) {
return true;
}

$check = DateTime::createFromFormat(self::DATE_FORMAT, $value);
return $check !== false;
}

public static function getName(): string {
return __('Date');
}

public static function canRequire(): bool {
return true;
}

public function equals($value): bool {
if ($this->value === '') {
$answer = '0000-00-00';
} else {
$answer = $this->value;
}
$answerDatetime = DateTime::createFromFormat(self::DATE_FORMAT, $answer);
$answerDatetime->setTime(0, 0, 0, 0);
$compareDatetime = DateTime::createFromFormat(self::DATE_FORMAT, $value);
$compareDatetime->setTime(0, 0, 0, 0);
return $answerDatetime == $compareDatetime;
}

public function notEquals($value): bool {
return !$this->equals($value);
}

public function greaterThan($value): bool {
if (empty($this->value)) {
$answer = '0000-00-00';
} else {
$answer = $this->value;
}
$answerDatetime = DateTime::createFromFormat(self::DATE_FORMAT, $answer);
$answerDatetime->setTime(0, 0, 0, 0);
$compareDatetime = DateTime::createFromFormat(self::DATE_FORMAT, $value);
$compareDatetime->setTime(0, 0, 0, 0);
return $answerDatetime > $compareDatetime;
}

public function lessThan($value): bool {
return !$this->greaterThan($value) && !$this->equals($value);
}

public function regex($value): bool {
throw new ComparisonException('Meaningless comparison');
}

public function parseAnswerValues($input, $nonDestructive = false): bool {
$key = 'formcreator_field_' . $this->question->getID();
if (!isset($input[$key])) {
$input[$key] = '';
/**
* Convert a string value into DateTime object
*
* @param string $value
* @return false|DateTime
*/
protected function getDateFromValue(string $value) {
if (empty($value)) {
$value = self::DATE_ZERO;
}

if (!is_string($input[$key])) {
return false;
$datetime = DateTime::createFromFormat(self::DATE_FORMAT, $value);
if ($datetime !== false) {
$datetime->setTime(0, 0, 0, 0);
}

if ($input[$key] != ''
&& DateTime::createFromFormat(self::DATE_FORMAT, $input[$key]) === false
) {
return false;
}

$this->value = $input[$key];
return true;
}

public function isPublicFormCompatible(): bool {
return true;
}

public function getHtmlIcon(): string {
return '<i class="fa fa-calendar" aria-hidden="true"></i>';
}

public function isVisibleField(): bool {
return true;
}

public function isEditableField(): bool {
return true;
return $datetime;
}

public function getValueForApi() {
Expand Down
Loading

0 comments on commit 9157911

Please sign in to comment.