From 616080458b682bc2fb3dd6874d8feeec407c9628 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20David?= Date: Tue, 3 Dec 2024 14:28:58 +0100 Subject: [PATCH] #1927 [QuestionGroup] add: question group object --- class/question.class.php | 5 + class/question_group.class.php | 578 ++++++++++++++ .../digiquali/question_group/index.php | 2 + .../mod_question_group_standard.php | 42 ++ core/modules/modDigiQuali.class.php | 72 +- js/modules/question_group.js | 102 +++ langs/fr_FR/digiquali.lang | 14 + lib/digiquali_question_group.lib.php | 37 + sql/question_group/index.php | 2 + .../llx_categorie_question_group.key.sql | 20 + .../llx_categorie_question_group.sql | 20 + .../llx_digiquali_question_group.key.sql | 20 + .../llx_digiquali_question_group.sql | 29 + ...giquali_question_group_extrafields.key.sql | 17 + ...x_digiquali_question_group_extrafields.sql | 21 + view/question_group/index.php | 2 + view/question_group/question_group_card.php | 464 ++++++++++++ view/question_group/question_group_list.php | 709 ++++++++++++++++++ 18 files changed, 2144 insertions(+), 12 deletions(-) create mode 100644 class/question_group.class.php create mode 100644 core/modules/digiquali/question_group/index.php create mode 100644 core/modules/digiquali/question_group/mod_question_group_standard.php create mode 100644 js/modules/question_group.js create mode 100644 lib/digiquali_question_group.lib.php create mode 100644 sql/question_group/index.php create mode 100644 sql/question_group/llx_categorie_question_group.key.sql create mode 100644 sql/question_group/llx_categorie_question_group.sql create mode 100644 sql/question_group/llx_digiquali_question_group.key.sql create mode 100644 sql/question_group/llx_digiquali_question_group.sql create mode 100644 sql/question_group/llx_digiquali_question_group_extrafields.key.sql create mode 100644 sql/question_group/llx_digiquali_question_group_extrafields.sql create mode 100644 view/question_group/index.php create mode 100644 view/question_group/question_group_card.php create mode 100644 view/question_group/question_group_list.php diff --git a/class/question.class.php b/class/question.class.php index 45a219c8..a4c857cc 100644 --- a/class/question.class.php +++ b/class/question.class.php @@ -529,6 +529,11 @@ public function selectQuestionList($selected = '', $htmlname = 'socid', $filter $num = $this->db->num_rows($resql); $i = 0; + if ($showempty) + { + if ($showempty === '1') $out .= ''; + else $out .= ''; + } if ($num) { while ($i < $num) { $obj = $this->db->fetch_object($resql); diff --git a/class/question_group.class.php b/class/question_group.class.php new file mode 100644 index 00000000..52f348dd --- /dev/null +++ b/class/question_group.class.php @@ -0,0 +1,578 @@ + + * + * This program 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 3 of the License, or + * (at your option) any later version. + * + * This program 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 this program. If not, see . + */ + +/** + * \file class/question_group.class.php + * \ingroup digiquali + * \brief This file is a CRUD class file for Question (Create/Read/Update/Delete) + */ + +// Load Saturne libraries. +require_once __DIR__ . '/../../saturne/class/saturneobject.class.php'; + +/** + * Class for Question. + */ +class QuestionGroup extends SaturneObject +{ + /** + * @var string Module name + */ + public $module = 'digiquali'; + + /** + * @var string Element type of object + */ + public $element = 'question_group'; + + /** + * @var string Name of table without prefix where object is stored. This is also the key used for extrafields management + */ + public $table_element = 'digiquali_question_group'; + + /** + * @var int Does this object support multicompany module ? + * 0 = No test on entity, 1 = Test with field entity, 'field@table' = Test with link by field@table + */ + public $ismultientitymanaged = 1; + + /** + * @var int Does object support extrafields ? 0 = No, 1 = Yes + */ + public $isextrafieldmanaged = 1; + + /** + * @var string Name of icon for control. Must be a 'fa-xxx' fontawesome code (or 'fa-xxx_fa_color_size') or 'control@digiquali' if picto is file 'img/object_control.png' + */ + public string $picto = 'fontawesome_fa-question_group_fas_#d35968'; + + public const STATUS_DELETED = -1; + public const STATUS_DRAFT = 0; + public const STATUS_VALIDATED = 1; + public const STATUS_LOCKED = 2; + public const STATUS_ARCHIVED = 3; + + /** + * 'type' field format: + * 'integer', 'integer:ObjectClass:PathToClass[:AddCreateButtonOrNot[:Filter[:Sortfield]]]', + * 'select' (list of values are in 'options'), + * 'sellist:TableName:LabelFieldName[:KeyFieldName[:KeyFieldParent[:Filter[:Sortfield]]]]', + * 'chkbxlst:...', + * 'varchar(x)', + * 'text', 'text:none', 'html', + * 'double(24,8)', 'real', 'price', + * 'date', 'datetime', 'timestamp', 'duration', + * 'boolean', 'checkbox', 'radio', 'array', + * 'mail', 'phone', 'url', 'password', 'ip' + * Note: Filter can be a string like "(t.ref:like:'SO-%') or (t.date_creation:<:'20160101') or (t.nature:is:NULL)" + * 'label' the translation key + * 'picto' is code of a picto to show before value in forms + * 'enabled' is a condition when the field must be managed (Example: 1 or '$conf->global->MY_SETUP_PARAM' or '!empty($conf->multicurrency->enabled)' ...) + * 'position' is the sort order of field + * 'notnull' is set to 1 if not null in database. Set to -1 if we must set data to null if empty '' or 0 + * 'visible' says if field is visible in list (Examples: 0=Not visible, 1=Visible on list and create/update/view forms, 2=Visible on list only, 3=Visible on create/update/view form only (not list), 4=Visible on list and update/view form only (not create). 5=Visible on list and view only (not create/not update). Using a negative value means field is not shown by default on list but can be selected for viewing) + * 'noteditable' says if field is not editable (1 or 0) + * 'default' is a default value for creation (can still be overwroted by the Setup of Default Values if field is editable in creation form). Note: If default is set to '(PROV)' and field is 'ref', the default value will be set to '(PROVid)' where id is rowid when a new record is created + * 'index' if we want an index in database + * 'foreignkey'=>'tablename.field' if the field is a foreign key (it is recommanded to name the field fk_...) + * 'searchall' is 1 if we want to search in this field when making a search from the quick search button + * 'isameasure' must be set to 1 or 2 if field can be used for measure. Field type must be summable like integer or double(24,8). Use 1 in most cases, or 2 if you don't want to see the column total into list (for example for percentage) + * 'css' and 'cssview' and 'csslist' is the CSS style to use on field. 'css' is used in creation and update. 'cssview' is used in view mode. 'csslist' is used for columns in lists. For example: 'css'=>'minwidth300 maxwidth500 widthcentpercentminusx', 'cssview'=>'wordbreak', 'csslist'=>'tdoverflowmax200' + * 'help' is a 'TranslationString' to use to show a tooltip on field. You can also use 'TranslationString:keyfortooltiponlick' for a tooltip on click + * 'showoncombobox' if value of the field must be visible into the label of the combobox that list record + * 'disabled' is 1 if we want to have the field locked by a 'disabled' attribute. In most cases, this is never set into the definition of $fields into class, but is set dynamically by some part of code + * 'arrayofkeyval' to set a list of values if type is a list of predefined values. For example: array("0"=>"Draft","1"=>"Active","-1"=>"Cancel"). Note that type can be 'integer' or 'varchar' + * 'autofocusoncreate' to have field having the focus on a create form. Only 1 field should have this property set to 1 + * 'comment' is not used. You can store here any text of your choice. It is not used by application + * 'validate' is 1 if you need to validate with $this->validateField() + * 'copytoclipboard' is 1 or 2 to allow to add a picto to copy value into clipboard (1=picto after label, 2=picto after value) + * + * Note: To have value dynamic, you can set value to 0 in definition and edit the value on the fly into the constructor + */ + +//CREATE TABLE llx_digiquali_question_group( +//rowid integer AUTO_INCREMENT PRIMARY KEY NOT NULL, +//ref varchar(128) DEFAULT '(PROV)' NOT NULL, +//ref_ext varchar(128), +//entity integer DEFAULT 1 NOT NULL, +//date_creation datetime NOT NULL, +//tms timestamp DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, +//import_key varchar(14), +//status integer DEFAULT 1 NOT NULL, +//label varchar(255) NOT NULL, +//description text, +//fk_user_creat integer NOT NULL, +//fk_user_modif integer +//) ENGINE=innodb; + + /** + * @var array Array with all fields and their property. Do not use it as a static var. It may be modified by constructor + */ + public $fields = [ + 'rowid' => ['type' => 'integer', 'label' => 'TechnicalID', 'enabled' => 1, 'position' => 1, 'notnull' => 1, 'visible' => 0, 'noteditable' => 1, 'index' => 1, 'comment' => 'Id'], + 'ref' => ['type' => 'varchar(128)', 'label' => 'Ref', 'enabled' => 1, 'position' => 10, 'notnull' => 1, 'visible' => 4, 'noteditable' => 1, 'default' => '(PROV)', 'index' => 1, 'searchall' => 1, 'showoncombobox' => 1, 'validate' => 1, 'comment' => 'Reference of object'], + 'ref_ext' => ['type' => 'varchar(128)', 'label' => 'RefExt', 'enabled' => 1, 'position' => 20, 'notnull' => 0, 'visible' => 0, 'noteditable' => 1, 'index' => 1, 'comment' => 'External reference of object'], + 'entity' => ['type' => 'integer', 'label' => 'Entity', 'enabled' => 1, 'position' => 30, 'notnull' => 1, 'visible' => 0, 'noteditable' => 1, 'default' => 1, 'index' => 1, 'comment' => 'Entity'], + 'date_creation' => ['type' => 'datetime', 'label' => 'DateCreation', 'enabled' => 1, 'position' => 40, 'notnull' => 1, 'visible' => 0, 'noteditable' => 1, 'default' => '@NOW@', 'index' => 1, 'comment' => 'Creation date'], + 'tms' => ['type' => 'timestamp', 'label' => 'DateModification', 'enabled' => 1, 'position' => 50, 'notnull' => 1, 'visible' => 0, 'noteditable' => 1, 'default' => 'CURRENT_TIMESTAMP', 'index' => 1, 'comment' => 'Timestamp'], + 'import_key' => ['type' => 'varchar(14)', 'label' => 'ImportKey', 'enabled' => 1, 'position' => 60, 'notnull' => 0, 'visible' => 0, 'noteditable' => 1, 'index' => 1, 'comment' => 'Import key'], + 'status' => ['type' => 'integer', 'label' => 'Status', 'enabled' => 1, 'position' => 70, 'notnull' => 1, 'visible' => 0, 'noteditable' => 1, 'default' => 1, 'index' => 1, 'comment' => 'Status'], + 'label' => ['type' => 'varchar(255)', 'label' => 'Label', 'enabled' => 1, 'position' => 80, 'notnull' => 1, 'visible' => 1, 'noteditable' => 0, 'index' => 1, 'comment' => 'Label'], + 'description' => ['type' => 'text', 'label' => 'Description', 'enabled' => 1, 'position' => 90, 'notnull' => 0, 'visible' => 1, 'noteditable' => 0, 'comment' => 'Description'], + 'fk_user_creat' => ['type' => 'integer', 'label' => 'UserCreation', 'enabled' => 1, 'position' => 100, 'notnull' => 1, 'visible' => 0, 'noteditable' => 1, 'index' => 1, 'comment' => 'User ID of creation'], + 'fk_user_modif' => ['type' => 'integer', 'label' => 'UserModification', 'enabled' => 1, 'position' => 110, 'notnull' => 0, 'visible' => 0, 'noteditable' => 1, 'index' => 1, 'comment' => 'User ID of modification'], + ]; + + /** + * @var int ID + */ + public int $rowid; + + /** + * @var string Ref + */ + public $ref; + + /** + * @var string Ref ext + */ + public $ref_ext; + + /** + * @var int Entity + */ + public $entity; + + /** + * @var string Date creation + */ + public $date_creation; + + /** + * @var string Timestamp + */ + public $tms; + + /** + * @var string Import key + */ + public $import_key; + + /** + * @var int Status + */ + public $status; + + /** + * @var string Label + */ + public $label; + + /** + * @var string Description + */ + public $description; + + + /** + * @var int User ID + */ + public $fk_user_creat; + + /** + * @var int|null User ID + */ + public $fk_user_modif; + + /** + * Constructor + * + * @param DoliDb $db Database handler + */ + public function __construct(DoliDB $db) + { + parent::__construct($db, $this->module, $this->element); + } + + /** + * Create object into database + * + * @param User $user User that creates + * @param bool $notrigger false = launch triggers after, true = disable triggers + * @return int 0 < if KO, ID of created object if OK + */ + public function create(User $user, bool $notrigger = false): int + { + $this->ref = $this->getNextNumRef(); + $this->status = $this->status ?: 1; + + return parent::create($user, $notrigger); + } + + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + /** + * Return if a question_group can be deleted + * + * @return int <=0 if no, >0 if yes + */ + public function isErasable() { + return $this->isLinkedToOtherObjects(); + } + + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + /** + * Return if a question_group is linked to another object + * + * @return int <=0 if no, >0 if yes + */ + public function isLinkedToOtherObjects() { + + // Links between objects are stored in table element_element + $sql = 'SELECT rowid, fk_source, sourcetype, fk_target, targettype'; + $sql .= ' FROM '.MAIN_DB_PREFIX.'element_element'; + $sql .= " WHERE fk_target = " . $this->id; + $sql .= " AND targettype = '" . $this->table_element . "'"; + + $resql = $this->db->query($sql); + + if ($resql) { + $nbObjectsLinked = 0; + $num = $this->db->num_rows($resql); + $i = 0; + while ($i < $num) { + $nbObjectsLinked++; + $i++; + } + if ($nbObjectsLinked > 0) { + return -1; + } else { + return 1; + } + } else { + dol_print_error($this->db); + return -1; + } + } + + /** + * Return the status + * + * @param int $status ID status + * @param int $mode 0 = long label, 1 = short label, 2 = Picto + short label, 3 = Picto, 4 = Picto + long label, 5 = Short label + Picto, 6 = Long label + Picto + * @return string Label of status + */ + public function LibStatut(int $status, int $mode = 0): string + { + if (empty($this->labelStatus) || empty($this->labelStatusShort)) { + global $langs; + $this->labelStatus[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('StatusDraft'); + $this->labelStatus[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('InProgress'); + $this->labelStatus[self::STATUS_LOCKED] = $langs->transnoentitiesnoconv('Locked'); + $this->labelStatus[self::STATUS_ARCHIVED] = $langs->transnoentitiesnoconv('Archived'); + $this->labelStatus[self::STATUS_DELETED] = $langs->transnoentitiesnoconv('Deleted'); + + $this->labelStatusShort[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('StatusDraft'); + $this->labelStatusShort[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('InProgress'); + $this->labelStatusShort[self::STATUS_LOCKED] = $langs->transnoentitiesnoconv('Locked'); + $this->labelStatusShort[self::STATUS_ARCHIVED] = $langs->transnoentitiesnoconv('Archived'); + $this->labelStatusShort[self::STATUS_DELETED] = $langs->transnoentitiesnoconv('Deleted'); + } + + $statusType = 'status' . $status; + if ($status == self::STATUS_LOCKED) { + $statusType = 'status4'; + } + if ($status == self::STATUS_ARCHIVED) { + $statusType = 'status8'; + } + if ($status == self::STATUS_DELETED) { + $statusType = 'status9'; + } + + return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status], '', $statusType, $mode); + } + + /** + * Clone an object into another one + * + * @param User $user User that creates + * @param int $fromid ID of object to clone + * @param array $options Options array + * @return int New object created, < 0 if KO + * @throws Exception + */ + public function createFromClone(User $user, int $fromid, array $options): int + { + dol_syslog(__METHOD__, LOG_DEBUG); + + global $conf; + $error = 0; + + $object = new self($this->db); + $answer = new Answer($this->db); + + $this->db->begin(); + + // Load source object + $object->fetchCommon($fromid); + + // Reset some properties + unset($object->id); + unset($object->fk_user_creat); + unset($object->import_key); + + $oldRef = $object->ref; + + // Clear fields + if (property_exists($object, 'ref')) { + $object->ref = $this->getNextNumRef(); + } + if (!empty($options['label'])) { + if (property_exists($object, 'label')) { + $object->label = $options['label']; + } + } + if (property_exists($object, 'date_creation')) { + $object->date_creation = dol_now(); + } + if (property_exists($object, 'status')) { + $object->status = 1; + } + + // Create clone + $object->context['createfromclone'] = 'createfromclone'; + $result = $object->create($user); + + if ($result > 0) { + if (!empty($options['categories'])) { + $cat = new Categorie($this->db); + $categories = $cat->containing($fromid, 'question_group'); + if (is_array($categories) && !empty($categories)) { + foreach ($categories as $cat) { + $categoryIds[] = $cat->id; + } + $object->fetch($result); + $object->setCategories($categoryIds); + } + } + } else { + $error++; + $this->error = $object->error; + $this->errors = $object->errors; + } + + unset($object->context['createfromclone']); + + // End + if (!$error) { + $this->db->commit(); + return $result; + } else { + $this->db->rollback(); + return -1; + } + } + + /** + * Initialise object with example values + * Id must be 0 if object instance is a specimen + * + * @return void + */ + public function initAsSpecimen() + { + $this->initAsSpecimenCommon(); + } + + /** + * Output html form to select a third party + * Note, you must use the select_company to get the component to select a third party. This function must only be called by select_company + * + * @param string $selected Preselected type + * @param string $htmlname Name of field in form + * @param string $filter Optional filters criteras (example: 's.rowid <> x', 's.client in (1,3)') + * @param string $showempty Add an empty field (Can be '1' or text to use on empty line like 'SelectThirdParty') + * @param int $showtype Show third party type in combolist (customer, prospect or supplier) + * @param int $forcecombo Force to use standard HTML select component without beautification + * @param array $events Event options. Example: array(array('method'=>'getContacts', 'url'=>dol_buildpath('/core/ajax/contacts.php',1), 'htmlname'=>'contactid', 'params'=>array('add-customer-contact'=>'disabled'))) + * @param string $filterkey Filter on key value + * @param int $outputmode 0=HTML select string, 1=Array + * @param int $limit Limit number of answers + * @param string $morecss Add more css styles to the SELECT component + * @param string $moreparam Add more parameters onto the select tag. For example 'style="width: 95%"' to avoid select2 component to go over parent container + * @param bool $multiple add [] in the name of element and add 'multiple' attribut + * @return string HTML string with + * @throws Exception + */ + public function selectQuestionGroupList($selected = '', $htmlname = 'socid', $filter = '', $showempty = '1', $showtype = 0, $forcecombo = 0, $events = array(), $filterkey = '', $outputmode = 0, $limit = 0, $morecss = 'minwidth100', $moreparam = '', $multiple = false, $alreadyAdded = array()) + { + $out = ''; + $num = 0; + $outarray = array(); + + if ($selected === '') $selected = array(); + elseif ( ! is_array($selected)) $selected = array($selected); + + // Clean $filter that may contains sql conditions so sql code + if (function_exists('testSqlAndScriptInject')) { + if (testSqlAndScriptInject($filter, 3) > 0) { + $filter = ''; + } + } + // On recherche les societes + $sql = "SELECT *"; + $sql .= " FROM " . MAIN_DB_PREFIX . "digiquali_question_group as s"; + + $sql .= " WHERE s.entity IN (" . getEntity($this->table_element) . ")"; + if ($filter) $sql .= " AND (" . $filter . ")"; + + $sql .= $this->db->order("rowid", "ASC"); + $sql .= $this->db->plimit($limit, 0); + + // Build output string + dol_syslog(get_class($this) . "::selectQuestionList", LOG_DEBUG); + $resql = $this->db->query($sql); + if ($resql) { + if ( ! $forcecombo) { + include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php'; + $out .= ajax_combobox($htmlname, $events, 0); + } + + // Construct $out and $outarray + $out .= '' . "\n"; + } else { + dol_print_error($this->db); + } + + $this->result = array('nbofquestion_groups' => $num); + + if ($outputmode) return $outarray; + return $out; + } + + /** + * Write information of trigger description + * + * @param Object $object Object calling the trigger + * @return string Description to display in actioncomm->note_private + */ + public function getTriggerDescription(SaturneObject $object): string + { + global $langs; + + $ret = parent::getTriggerDescription($object); + $ret .= (dol_strlen($object->photo_ok) > 0 ? $langs->transnoentities('PhotoOK') . ' : ' . $object->photo_ok . '
' : ''); + $ret .= (dol_strlen($object->photo_ko) > 0 ? $langs->transnoentities('PhotoKO') . ' : ' . $object->photo_ko . '
' : ''); + + return $ret; + } + + /** + * Add question into question group + * + * @param int $questionId ID of question + */ + public function addQuestion($questionId) { + $this->add_object_linked('digiquali_question', $questionId, $this->id, 'question_group'); + } + + /** + * Move questions + */ + public function updateQuestionPosition($questionIds) + { + + foreach ($questionIds as $position => $questionId) { + $sql = 'UPDATE ' . MAIN_DB_PREFIX . 'element_element'; + $sql .= ' SET position =' . $position; + $sql .= ' WHERE fk_source = ' . $questionId; + $sql .= ' AND sourcetype = \'digiquali_question\''; + $sql .= ' AND fk_target = ' . $this->id; + $sql .= ' AND targettype = \'digiquali_question_group\''; + $res = $this->db->query($sql); + + if (!$res) { + $error++; + } + } + if ($error) { + $this->db->rollback(); + } else { + $this->db->commit(); + } + } + + /** + * Get questions + * + * @return array + */ + public function fetchQuestionsOrderedByPosition() + { + $questions = []; + $sql = 'SELECT fk_source'; + $sql .= ' FROM ' . MAIN_DB_PREFIX . 'element_element'; + $sql .= ' WHERE fk_target = ' . $this->id; + $sql .= ' AND targettype = \'digiquali_question_group\''; + $sql .= ' AND sourcetype = \'digiquali_question\''; + $sql .= ' ORDER BY position ASC'; + $res = $this->db->query($sql); + if ($res) { + while ($obj = $this->db->fetch_object($res)) { + + $question = new Question($this->db); + + $question->fetch($obj->fk_source); + $questions[] = $question; + } + } + return $questions; + } +} diff --git a/core/modules/digiquali/question_group/index.php b/core/modules/digiquali/question_group/index.php new file mode 100644 index 00000000..cd6990e2 --- /dev/null +++ b/core/modules/digiquali/question_group/index.php @@ -0,0 +1,2 @@ + + * + * This program 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 3 of the License, or + * (at your option) any later version. + * + * This program 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 this program. If not, see . + * or see https://www.gnu.org/ + */ + +/** + * \file core/modules/digiquali/question/mod_question_standard.php + * \ingroup digiquali + * \brief File of class to manage question numbering rules standard. + */ + +// Load Saturne libraries. +require_once __DIR__ . '/../../../../../saturne/core/modules/saturne/modules_saturne.php'; + +/** + * Class to manage question numbering rules standard. + */ +class mod_question_group_standard extends ModeleNumRefSaturne +{ + /** + * @var string Numbering module ref prefix. + */ + public string $prefix = 'QG'; + + /** + * @var string Name. + */ + public string $name = 'Kari'; +} diff --git a/core/modules/modDigiQuali.class.php b/core/modules/modDigiQuali.class.php index 295f3b76..dcbbfb59 100644 --- a/core/modules/modDigiQuali.class.php +++ b/core/modules/modDigiQuali.class.php @@ -202,7 +202,7 @@ public function __construct($db) $i++ => ['DIGIQUALI_SHEET_BACKWARD_COMPATIBILITY', 'integer', 0, '', 0, 'current'], // CONST QUESTION - $i++ => ['DIGIQUALI_QUESTION_ADDON', 'chaine', 'mod_question_standard', '', 0, 'current'], + $i++ => ['DIGIQUALI_QUESTION_ADDON', 'chaine', 'mod_question_group_standard', '', 0, 'current'], $i++ => ['DIGIQUALI_QUESTION_BACKWARD_COMPATIBILITY', 'integer', 1, '', 0, 'current'], // CONST ANSWER @@ -470,6 +470,23 @@ public function __construct($db) $this->rights[$r][1] = $langs->transnoentities('DeleteObjects', dol_strtolower($langs->transnoentities('Surveys'))); // Permission label $this->rights[$r][4] = 'survey'; // In php code, permission will be checked by test if ($user->rights->digiquali->level1->level2) $this->rights[$r][5] = 'delete'; // In php code, permission will be checked by test if ($user->rights->digiquali->level1->level2) + $r++; + + /* QUESTION GROUP PERMISSIONS */ + $this->rights[$r][0] = $this->numero . sprintf('%02d', $r + 1); // Permission id (must not be already used) + $this->rights[$r][1] = $langs->transnoentities('ReadObjects', dol_strtolower($langs->transnoentities('QuestionGroups'))); // Permission label + $this->rights[$r][4] = 'question_group'; // In php code, permission will be checked by test if ($user->rights->digiquali->level1->level2) + $this->rights[$r][5] = 'read'; // In php code, permission will be checked by test if ($user->rights->digiquali->level1->level2) + $r++; + $this->rights[$r][0] = $this->numero . sprintf('%02d', $r + 1); // Permission id (must not be already used) + $this->rights[$r][1] = $langs->transnoentities('CreateObjects', dol_strtolower($langs->transnoentities('QuestionGroups'))); // Permission label + $this->rights[$r][4] = 'question_group'; // In php code, permission will be checked by test if ($user->rights->digiquali->level1->level2) + $this->rights[$r][5] = 'write'; // In php code, permission will be checked by test if ($user->rights->digiquali->level1->level2) + $r++; + $this->rights[$r][0] = $this->numero . sprintf('%02d', $r + 1); // Permission id (must not be already used) + $this->rights[$r][1] = $langs->transnoentities('DeleteObjects', dol_strtolower($langs->transnoentities('QuestionGroups'))); // Permission label + $this->rights[$r][4] = 'question_group'; // In php code, permission will be checked by test if ($user->rights->digiquali->level1->level2) + $this->rights[$r][5] = 'delete'; // In php code, permission will be checked by test if ($user->rights->digiquali->level1->level2) $r++; /* ADMINPAGE PANEL ACCESS PERMISSIONS */ @@ -598,32 +615,63 @@ public function __construct($db) ]; $this->menu[$r++] = [ - 'fk_menu' => 'fk_mainmenu=digiquali', + 'fk_menu' => 'fk_mainmenu=digiquali', + 'type' => 'left', + 'titre' => $langs->transnoentities('Survey'), + 'prefix' => '', + 'mainmenu' => 'digiquali', + 'leftmenu' => 'digiquali_survey', + 'url' => '/digiquali/view/survey/survey_list.php', + 'langs' => 'digiquali@digiquali', + 'position' => 1000 + $r, + 'enabled' => '$conf->digiquali->enabled && $user->rights->digiquali->survey->read', + 'perms' => '$user->rights->digiquali->survey->read', + 'target' => '', + 'user' => 0, + ]; + + $this->menu[$r++] = [ + 'fk_menu' => 'fk_mainmenu=digiquali,fk_leftmenu=digiquali_survey', 'type' => 'left', - 'titre' => $langs->transnoentities('Survey'), - 'prefix' => '', + 'titre' => '' . $langs->transnoentities('Categories'), 'mainmenu' => 'digiquali', - 'leftmenu' => 'digiquali_survey', - 'url' => '/digiquali/view/survey/survey_list.php', + 'leftmenu' => 'digiquali_surveytags', + 'url' => '/categories/index.php?type=survey', 'langs' => 'digiquali@digiquali', 'position' => 1000 + $r, - 'enabled' => '$conf->digiquali->enabled && $user->rights->digiquali->survey->read', + 'enabled' => '$conf->digiquali->enabled && $conf->categorie->enabled && $user->rights->digiquali->survey->read', 'perms' => '$user->rights->digiquali->survey->read', 'target' => '', 'user' => 0, ]; $this->menu[$r++] = [ - 'fk_menu' => 'fk_mainmenu=digiquali,fk_leftmenu=digiquali_survey', + 'fk_menu' => 'fk_mainmenu=digiquali', + 'type' => 'left', + 'titre' => $langs->transnoentities('QuestionGroup'), + 'prefix' => '', + 'mainmenu' => 'digiquali', + 'leftmenu' => 'digiquali_question_group', + 'url' => '/digiquali/view/question_group/question_group_list.php', + 'langs' => 'digiquali@digiquali', + 'position' => 1000 + $r, + 'enabled' => '$conf->digiquali->enabled && $user->rights->digiquali->question_group->read', + 'perms' => '$user->rights->digiquali->question_group->read', + 'target' => '', + 'user' => 0, + ]; + + $this->menu[$r++] = [ + 'fk_menu' => 'fk_mainmenu=digiquali,fk_leftmenu=digiquali_question_group', 'type' => 'left', 'titre' => '' . $langs->transnoentities('Categories'), 'mainmenu' => 'digiquali', - 'leftmenu' => 'digiquali_surveytags', - 'url' => '/categories/index.php?type=survey', + 'leftmenu' => 'digiquali_question_groupytags', + 'url' => '/categories/index.php?type=question_group', 'langs' => 'digiquali@digiquali', 'position' => 1000 + $r, - 'enabled' => '$conf->digiquali->enabled && $conf->categorie->enabled && $user->rights->digiquali->survey->read', - 'perms' => '$user->rights->digiquali->survey->read', + 'enabled' => '$conf->digiquali->enabled && $conf->categorie->enabled && $user->rights->digiquali->question_group->read', + 'perms' => '$user->rights->digiquali->question_group->read', 'target' => '', 'user' => 0, ]; diff --git a/js/modules/question_group.js b/js/modules/question_group.js new file mode 100644 index 00000000..4f57d9ba --- /dev/null +++ b/js/modules/question_group.js @@ -0,0 +1,102 @@ + +/** + * Initialise l'objet "questionGroup" ainsi que la méthode "init" obligatoire pour la bibliothèque EoxiaJS. + * + * @since 1.1.0 + * @version 1.1.0 + */ +window.digiquali.questionGroup = {}; + +/** + * La méthode appelée automatiquement par la bibliothèque EoxiaJS. + * + * @since 1.1.0 + * @version 1.1.0 + * + * @return {void} + */ +window.digiquali.questionGroup.init = function() { + window.digiquali.questionGroup.event(); +}; + +/** + * La méthode contenant tous les événements pour le questionGroup. + * + * @since 1.1.0 + * @version 1.1.0 + * + * @return {void} + */ +window.digiquali.questionGroup.event = function() { + $( document ).on( 'click', '.clicked-photo-preview', window.digiquali.questionGroup.previewPhoto ); + $( document ).on( 'click', '.ui-dialog-titlebar-close', window.digiquali.questionGroup.closePreviewPhoto ); + $( document ).on( 'click', '#show_photo', window.digiquali.questionGroup.showPhoto ); + $( document ).on( 'click', '.answer-picto .item, .wpeo-table .item', window.digiquali.questionGroup.selectAnswerPicto ); +}; + +/** + * Add border on preview photo. + * + * @since 1.1.0 + * @version 1.1.0 + * + * @param {MouseEvent} event Les attributs lors du clic. + * @return {void} + */ +window.digiquali.questionGroup.previewPhoto = function ( event ) { + if ($(this).hasClass('photo-ok')) { + $("#dialogforpopup").attr('style', 'border: 10px solid #47e58e') + } else if ($(this).hasClass('photo-ko')) { + $("#dialogforpopup").attr('style', 'border: 10px solid #e05353') + } +}; + +/** + * Close preview photo. + * + * @since 1.1.0 + * @version 1.1.0 + * + * @param {MouseEvent} event Les attributs lors du clic. + * @return {void} + */ +window.digiquali.questionGroup.closePreviewPhoto = function ( event ) { + $("#dialogforpopup").attr('style', 'border:') +}; + +/** + * Show photo for questionGroup. + * + * @since 1.3.0 + * @version 1.3.0 + * + * @return {void} + */ +window.digiquali.questionGroup.showPhoto = function() { + let photo = $(this).closest('.questionGroup-table').find('.linked-medias') + + if (photo.hasClass('hidden')) { + photo.attr('style', '') + photo.removeClass('hidden') + } else { + photo.attr('style', 'display:none') + photo.addClass('hidden') + } +}; + +/** + * Lors du clic sur un picto de réponse, remplace le contenu du toggle et met l'image du picto sélectionné. + * + * @since 1.0.0 + * @version 1.0.0 + * + * @param {MouseEvent} event [description] + * @return {void} + */ +window.digiquali.questionGroup.selectAnswerPicto = function( event ) { + var element = $(this).closest('.wpeo-dropdown'); + $(this).closest('.content').removeClass('active'); + element.find('.dropdown-toggle span').hide(); + element.find('.dropdown-toggle.button-picto').html($(this).closest('.wpeo-tooltip-event').html()); + element.find('.input-hidden-picto').val($(this).data('label')); +}; diff --git a/langs/fr_FR/digiquali.lang b/langs/fr_FR/digiquali.lang index b99c76b3..f4d4909c 100644 --- a/langs/fr_FR/digiquali.lang +++ b/langs/fr_FR/digiquali.lang @@ -369,6 +369,20 @@ AutoSaveActionQuestionAnswer = Sauvegarde automatique des réponses a AutoSaveActionQuestionAnswerDescription = Sauvegarde automatiquement les réponses aux questions lors du choix de la réponse NoObjectLineAnswersPhoto = Pas de photos sur les réponses du %s + + +# +# Groupes de questions +# + +# Data - Donnée +QuestionGroup = Groupe de questions +QuestionGroups = Groupes de questions +NewQuestionGroup = Nouveau groupe de questions +ModifyQuestionGroup = Modifier un groupe de questions + + + # # ControlDocument - Fiche de Contrôle # diff --git a/lib/digiquali_question_group.lib.php b/lib/digiquali_question_group.lib.php new file mode 100644 index 00000000..577531f9 --- /dev/null +++ b/lib/digiquali_question_group.lib.php @@ -0,0 +1,37 @@ + + * + * This program 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 3 of the License, or + * (at your option) any later version. + * + * This program 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 this program. If not, see . + */ + +/** + * \file lib/digiquali_question_group.lib.php + * \ingroup digiquali + * \brief Library files with common functions for Question. + */ + +// Load Saturne libraries. +require_once __DIR__ . '/../../saturne/lib/object.lib.php'; + +/** + * Prepare array of tabs for question group. + * + * @param QuestionGroup $object QuestionGroup object. + * @return array Array of tabs. + * @throws Exception + */ +function question_group_prepare_head(QuestionGroup $object): array +{ + return saturne_object_prepare_head($object); +} diff --git a/sql/question_group/index.php b/sql/question_group/index.php new file mode 100644 index 00000000..cd6990e2 --- /dev/null +++ b/sql/question_group/index.php @@ -0,0 +1,2 @@ + +-- +-- This program 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 3 of the License, or +-- (at your option) any later version. +-- +-- This program 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 this program. If not, see https://www.gnu.org/licenses/. + +ALTER TABLE llx_categorie_question_group ADD PRIMARY KEY pk_categorie_question (fk_categorie, fk_question); +ALTER TABLE llx_categorie_question_group ADD INDEX idx_categorie_question_fk_categorie (fk_categorie); +ALTER TABLE llx_categorie_question_group ADD INDEX idx_categorie_question_fk_question (fk_question); +ALTER TABLE llx_categorie_question_group ADD CONSTRAINT fk_categorie_question_group_categorie_rowid FOREIGN KEY (fk_categorie) REFERENCES llx_categorie (rowid); +ALTER TABLE llx_categorie_question_group ADD CONSTRAINT fk_categorie_question_group_digiquali_question_group_rowid FOREIGN KEY (fk_question) REFERENCES llx_digiquali_question_group (rowid); diff --git a/sql/question_group/llx_categorie_question_group.sql b/sql/question_group/llx_categorie_question_group.sql new file mode 100644 index 00000000..41fbbd03 --- /dev/null +++ b/sql/question_group/llx_categorie_question_group.sql @@ -0,0 +1,20 @@ +-- Copyright (C) 2022 EVARISK +-- +-- This program 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 3 of the License, or +-- (at your option) any later version. +-- +-- This program 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 this program. If not, see https://www.gnu.org/licenses/. + +CREATE TABLE llx_categorie_question_group( + fk_categorie integer NOT NULL, + fk_question_group integer NOT NULL, + import_key varchar(14) +) ENGINE=innodb; diff --git a/sql/question_group/llx_digiquali_question_group.key.sql b/sql/question_group/llx_digiquali_question_group.key.sql new file mode 100644 index 00000000..6235238d --- /dev/null +++ b/sql/question_group/llx_digiquali_question_group.key.sql @@ -0,0 +1,20 @@ +-- Copyright (C) 2022 EVARISK +-- +-- This program 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 3 of the License, or +-- (at your option) any later version. +-- +-- This program 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 this program. If not, see https://www.gnu.org/licenses/. + +ALTER TABLE llx_digiquali_question_group ADD INDEX idx_digiquali_question_group_rowid (rowid); +ALTER TABLE llx_digiquali_question_group ADD INDEX idx_digiquali_question_group_ref (ref); +ALTER TABLE llx_digiquali_question_group ADD INDEX idx_digiquali_question_group_status (status); +ALTER TABLE llx_digiquali_question_group ADD UNIQUE INDEX uk_digiquali_question_group_ref (ref, entity); +ALTER TABLE llx_digiquali_question_group ADD CONSTRAINT llx_digiquali_question_group_fk_user_creat FOREIGN KEY (fk_user_creat) REFERENCES llx_user(rowid); diff --git a/sql/question_group/llx_digiquali_question_group.sql b/sql/question_group/llx_digiquali_question_group.sql new file mode 100644 index 00000000..61ed462c --- /dev/null +++ b/sql/question_group/llx_digiquali_question_group.sql @@ -0,0 +1,29 @@ +-- Copyright (C) 2022-2023 EVARISK +-- +-- This program 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 3 of the License, or +-- (at your option) any later version. +-- +-- This program 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 this program. If not, see https://www.gnu.org/licenses/. + +CREATE TABLE llx_digiquali_question_group( + rowid integer AUTO_INCREMENT PRIMARY KEY NOT NULL, + ref varchar(128) DEFAULT '(PROV)' NOT NULL, + ref_ext varchar(128), + entity integer DEFAULT 1 NOT NULL, + date_creation datetime NOT NULL, + tms timestamp DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + import_key varchar(14), + status integer DEFAULT 1 NOT NULL, + label varchar(255) NOT NULL, + description text, + fk_user_creat integer NOT NULL, + fk_user_modif integer +) ENGINE=innodb; diff --git a/sql/question_group/llx_digiquali_question_group_extrafields.key.sql b/sql/question_group/llx_digiquali_question_group_extrafields.key.sql new file mode 100644 index 00000000..b0156208 --- /dev/null +++ b/sql/question_group/llx_digiquali_question_group_extrafields.key.sql @@ -0,0 +1,17 @@ +-- Copyright (C) 2022 EVARISK +-- +-- This program 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 3 of the License, or +-- (at your option) any later version. +-- +-- This program 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 this program. If not, see https://www.gnu.org/licenses/. + +ALTER TABLE llx_digiquali_question_group_extrafields ADD INDEX idx_digiquali_question_group_extrafields_rowid (rowid); +ALTER TABLE llx_digiquali_question_group_extrafields ADD INDEX idx_digiquali_question_group_extrafields_fk_object (fk_object); diff --git a/sql/question_group/llx_digiquali_question_group_extrafields.sql b/sql/question_group/llx_digiquali_question_group_extrafields.sql new file mode 100644 index 00000000..9738994e --- /dev/null +++ b/sql/question_group/llx_digiquali_question_group_extrafields.sql @@ -0,0 +1,21 @@ +-- Copyright (C) 2022 EVARISK +-- +-- This program 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 3 of the License, or +-- (at your option) any later version. +-- +-- This program 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 this program. If not, see https://www.gnu.org/licenses/. + +create table llx_digiquali_question_group_extrafields( + rowid integer AUTO_INCREMENT PRIMARY KEY, + tms timestamp, + import_key varchar(14), + fk_object integer NOT NULL +) ENGINE=innodb; diff --git a/view/question_group/index.php b/view/question_group/index.php new file mode 100644 index 00000000..cd6990e2 --- /dev/null +++ b/view/question_group/index.php @@ -0,0 +1,2 @@ + + * + * This program 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 3 of the License, or + * (at your option) any later version. + * + * This program 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 this program. If not, see . + */ + +/** + * \file view/question_group/question_group_card.php + * \ingroup digiquali + * \brief Page to create/edit/view question_group + */ + +// Load DigiQuali environment +if (file_exists('../digiquali.main.inc.php')) { + require_once __DIR__ . '/../digiquali.main.inc.php'; +} elseif (file_exists('../../digiquali.main.inc.php')) { + require_once __DIR__ . '/../../digiquali.main.inc.php'; +} else { + die('Include of digiquali main fails'); +} + +// Libraries +require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php'; +require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php'; +require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php'; +require_once DOL_DOCUMENT_ROOT . '/core/class/doleditor.class.php'; +require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php'; +require_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php'; +require_once DOL_DOCUMENT_ROOT . '/core/lib/images.lib.php'; + +require_once '../../class/question_group.class.php'; +require_once '../../class/question.class.php'; +require_once '../../core/modules/digiquali/question_group/mod_question_group_standard.php'; +require_once '../../class/answer.class.php'; +require_once '../../lib/digiquali_question_group.lib.php'; +require_once '../../lib/digiquali_answer.lib.php'; + +// Global variables definitions +global $conf, $db, $hookmanager, $langs, $user, $langs; + +// Load translation files required by the page +saturne_load_langs(); + +// Get parameters +$id = GETPOST('id', 'int'); +$ref = GETPOST('ref', 'alpha'); +$action = GETPOST('action', 'aZ09'); +$subaction = GETPOST('subaction', 'aZ09'); +$confirm = GETPOST('confirm', 'alpha'); +$cancel = GETPOST('cancel', 'aZ09'); +$contextpage = GETPOST('contextpage', 'aZ') ?GETPOST('contextpage', 'aZ') : 'question_groupcard'; // To manage different context of search +$backtopage = GETPOST('backtopage', 'alpha'); +$backtopageforcancel = GETPOST('backtopageforcancel', 'alpha'); + +// Initialize objects +// Technical objets +$object = new QuestionGroup($db); +$question = new Question($db); +$answer = new Answer($db); +$extrafields = new ExtraFields($db); + +// View objects +$form = new Form($db); + +$hookmanager->initHooks(array('question_groupcard', 'globalcard')); // Note that conf->hooks_modules contains array + +// Fetch optionals attributes and labels +$extrafields->fetch_name_optionals_label($object->table_element); + +$search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_'); + +// Initialize array of search criterias +$searchAll = GETPOST("search_all", 'alpha'); +$search = array(); +foreach ($object->fields as $key => $val) { + if (GETPOST('search_'.$key, 'alpha')) $search[$key] = GETPOST('search_'.$key, 'alpha'); +} + +if (empty($action) && empty($id) && empty($ref)) $action = 'view'; + +// Load object +include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be include, not include_once. + +$permissiontoread = $user->rights->digiquali->question_group->read; +$permissiontoadd = $user->rights->digiquali->question_group->write; // Used by the include of actions_addupdatedelete.inc.php and actions_lineupdown.inc.php +$permissiontodelete = $user->rights->digiquali->question_group->delete || ($permissiontoadd && isset($object->status) && $object->status == $object::STATUS_DRAFT); + +// Security check - Protection if external user +saturne_check_access($permissiontoread, $object); + +/* + * Actions + */ + +$parameters = array(); +$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks +if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); + +if (empty($reshook)) { + $error = 0; + + $backurlforlist = dol_buildpath('/digiquali/view/question_group/question_group_list.php', 1); + + if (empty($backtopage) || ($cancel && empty($id))) { + if (empty($backtopage) || ($cancel && strpos($backtopage, '__ID__'))) { + if (empty($id) && (($action != 'add' && $action != 'create') || $cancel)) $backtopage = $backurlforlist; + else $backtopage = dol_buildpath('/digiquali/view/question_group/question_group_card.php', 1).'?id='.($id > 0 ? $id : '__ID__'); + } + } + + if ($cancel && $action != 'update') { + $backtopage .= '#answerList'; + } + + if ($action == 'add_question') { + $object->addQuestion(GETPOST('questionId')); + + header('Location: ' . $_SERVER['PHP_SELF'] . '?id=' . $object->id); + + } + + if ($action == 'moveLine' && $permissiontoadd) { + $idsArray = json_decode(file_get_contents('php://input'), true); + if (is_array($idsArray['order']) && !empty($idsArray['order'])) { + $ids = array_values($idsArray['order']); + $reIndexedIds = array_combine(range(1, count($ids)), array_values($ids)); + } + $object->updateQuestionPosition($reIndexedIds); + } + + // Actions cancel, add, update, update_extras, confirm_validate, confirm_delete, confirm_deleteline, confirm_clone, confirm_close, confirm_setdraft, confirm_reopen + include DOL_DOCUMENT_ROOT.'/core/actions_addupdatedelete.inc.php'; +} + +/* + * View + */ + +$title = $langs->trans(ucfirst($object->element)); +$help_url = 'FR:Module_DigiQuali'; +$moreJS = ['/saturne/js/includes/hammer.min.js']; + +saturne_header(1,'', $title, $help_url, '', 0, 0, $moreJS); + +// Part to create +if ($action == 'create') { + print load_fiche_titre($langs->trans('NewQuestionGroup'), '', 'object_'.$object->picto); + + print '
'; + print ''; + print ''; + if ($backtopage) print ''; + if ($backtopageforcancel) print ''; + + print dol_get_fiche_head(); + + print ''."\n"; + + // Label -- Libellé + print ''; + + // Description -- Description + print ''; + + // Categories + if (!empty($conf->categorie->enabled)) { + print '"; + } + + // Other attributes + include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_add.tpl.php'; + + print '
'.$langs->trans("Label").''; + print ''; + print '
'; + $doleditor = new DolEditor('description', GETPOST('description'), '', 90, 'dolibarr_details', '', false, true, $conf->global->FCKEDITOR_ENABLE_SOCIETE, ROWS_3, '90%'); + $doleditor->Create(); + print '
'.$langs->trans("Categories").''; + $categoryArborescence = $form->select_all_categories('question_group', '', 'parent', 64, 0, 1); + print img_picto('', 'category', 'class="pictofixedwidth"').$form::multiselectarray('categories', $categoryArborescence, GETPOST('categories', 'array'), '', 0, 'minwidth100imp maxwidth500 widthcentpercentminusxx'); + print ''; + print "
'."\n"; + + print dol_get_fiche_end(); + + print '
'; + print ''; + print '  '; + print '   '; + print '
'; + + print '
'; + + dol_set_focus('input[name="label"]'); +} + +// Part to edit record +if (($id || $ref) && $action == 'edit') { + print load_fiche_titre($langs->trans("ModifyQuestionGroup"), '', $object->picto); + + print '
'; + print ''; + print ''; + print ''; + if ($backtopage) print ''; + if ($backtopageforcancel) print ''; + + print dol_get_fiche_head(); + + print ''."\n"; + + // Ref -- Ref + print ''; + + //Label -- Libellé + print ''; + + //Description -- Description + print ''; + + // Other attributes + include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_edit.tpl.php'; + + print '
' . $langs->trans("Ref") . ''; + print $object->ref; + print '
'.$langs->trans("Label").''; + print ''; + print '
'; + $doleditor = new DolEditor('description', $object->description, '', 90, 'dolibarr_details', '', false, true, $conf->global->FCKEDITOR_ENABLE_SOCIETE, ROWS_3, '90%'); + $doleditor->Create(); + print '
'; + + print dol_get_fiche_end(); + + print '
'; + print '   '; + print '
'; + + print '
'; +} + +// Part to show record +if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'create'))) { + $res = $object->fetch_optionals(); + + saturne_get_fiche_head($object, 'card', $title); + saturne_banner_tab($object); + + $formconfirm = ''; + + // Lock confirmation + if (($action == 'lock' && (empty($conf->use_javascript_ajax) || !empty($conf->dol_use_jmobile))) || (!empty($conf->use_javascript_ajax) && empty($conf->dol_use_jmobile))) { + $formconfirm .= $form->formconfirm($_SERVER['PHP_SELF'] . '?id=' . $object->id, $langs->trans('LockObject', $langs->transnoentities('The' . ucfirst($object->element))), $langs->trans('ConfirmLockObject', $langs->transnoentities('The' . ucfirst($object->element))), 'confirm_lock', '', 'yes', 'actionButtonLock', 350, 600); + } + + // Clone confirmation + if (($action == 'clone' && (empty($conf->use_javascript_ajax) || !empty($conf->dol_use_jmobile))) || (!empty($conf->use_javascript_ajax) && empty($conf->dol_use_jmobile))) { + // Define confirmation messages + $formquestion_groupclone = [ + ['type' => 'text', 'name' => 'clone_label', 'label' => $langs->trans('NewLabelForClone', $langs->transnoentities('The' . ucfirst($object->element))), 'value' => $langs->trans('CopyOf') . ' ' . $object->ref, 'size' => 24], + ['type' => 'checkbox', 'name' => 'clone_photos', 'label' => $langs->trans('ClonePhotos'), 'value' => 1], + ['type' => 'checkbox', 'name' => 'clone_categories', 'label' => $langs->trans('CloneCategories'), 'value' => 1], + ]; + $formconfirm .= $form->formconfirm($_SERVER['PHP_SELF'] . '?id=' . $object->id, $langs->trans('CloneObject', $langs->transnoentities('The' . ucfirst($object->element))), $langs->trans('ConfirmCloneObject', $langs->transnoentities('The' . ucfirst($object->element)), $object->ref), 'confirm_clone', $formquestion_groupclone, 'yes', 'actionButtonClone', 350, 600); + } + + // Confirmation to delete + if ($action == 'delete') { + $formconfirm = $form->formconfirm($_SERVER['PHP_SELF'] . '?id=' . $object->id, $langs->trans('Delete') . ' ' . $langs->transnoentities('The' . ucfirst($object->element)), $langs->trans('ConfirmDeleteObject', $langs->transnoentities('The' . ucfirst($object->element))), 'confirm_delete', '', 'yes', 1); + } + + // Call Hook formConfirm + $parameters = ['formConfirm' => $formconfirm]; + $reshook = $hookmanager->executeHooks('formConfirm', $parameters, $object, $action); // Note that $action and $object may have been modified by hook + if (empty($reshook)) { + $formconfirm .= $hookmanager->resPrint; + } elseif ($reshook > 0) { + $formconfirm = $hookmanager->resPrint; + } + + // Print form confirm + print $formconfirm; + + print '
'; + print '
'; + print ''; + + //Description -- Description + print ''; + print ''; + + // Categories + if ($conf->categorie->enabled) { + print '"; + } + + // Other attributes. Fields from hook formObjectOptions and Extrafields. + include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php'; + + print '
'; + print $langs->trans("Description"); + print ''; + print $object->description; + print '
'.$langs->trans("Categories").''; + print $form->showCategories($object->id, 'question_group', 1); + print "
'; + print '
'; + print '
'; + + print '
'; + + + + // Buttons for actions + if ($action != 'presend') { + print '
'; + $parameters = []; + $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been modified by hook + if ($reshook < 0) { + setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); + } + + if (empty($reshook) && $permissiontoadd) { + // Modify + if ($object->status == $object::STATUS_VALIDATED) { + print ' ' . $langs->trans('Modify') . ''; + } else { + print ' ' . $langs->trans('Modify') . ''; + } + + // Lock + if (($object->type == 'UniqueChoice' || $object->type == 'MultipleChoices') && empty($answerList)) { + print ' ' . $langs->trans('Lock') . ''; + } else if ($object->status == $object::STATUS_VALIDATED) { + print ' ' . $langs->trans('Lock') . ''; + } else { + print ' ' . $langs->trans('Lock') . ''; + } + + // Archive + if ($object->status == $object::STATUS_LOCKED) { + print ' ' . $langs->trans('Archive') . ''; + } else { + print ' ' . $langs->trans('Archive') . ''; + } + + // Clone + print ' ' . $langs->trans('Clone') . ''; + + // Delete (need delete permission, or if draft, just need create/modify permission) + print dolGetButtonAction(' ' . $langs->trans('Delete'), '', 'delete', $_SERVER['PHP_SELF'] . '?id=' . $object->id . '&action=delete', '', $permissiontodelete || ($object->status == $object::STATUS_DRAFT && $permissiontoadd)); + } + print '
'; + } + + // ANSWERS LINES + print '
'; + print load_fiche_titre($langs->trans("AnswersList"), '', '', 0, 'answerList'); + print ''; + global $forceall, $forcetoshowtitlelines; + + if (empty($forceall)) $forceall = 0; + + // Define colspan for the button 'Add' + $colspan = 3; + ?> + + '; + print ''; + print ''; + print ''; + print ''; + print ''; + + $questionsLinked = $object->fetchQuestionsOrderedByPosition(); + + if (is_array($questionsLinked) && !empty($questionsLinked)) { + foreach ($questionsLinked as $questionLinked) { + $alreadyAdded[] = $questionLinked->id; + //SHOW LINE + print ''; + print ''; + + print ''; + + print ''; + print ''; + print ''; + } + } + + if ($object->status < QuestionGroup::STATUS_LOCKED) { + print ''; + print ''; + print ''; + print ''; + + print ''; + + print ''; + + print ''; + print ''; + print ''; + + print '
' . $langs->trans('Ref') . '' . $langs->trans('Description') . '
'; + print img_picto('', $questionLinked->picto, 'class="pictofixedwidth"') . $questionLinked->ref; + print ''; + print $questionLinked->description; + print ''; + if ($object->status < Question::STATUS_LOCKED) { + print ''; + } else { + print ''; + } + print '
-'; + + print $question->selectQuestionList(GETPOST('questionId'), 'questionId', '', $langs->trans('SelectQuestion'), '', '', '', '', '', '', '', '', '', $alreadyAdded); + + print ''; + print ''; + print ''; + print '
'; + print ''; + print '
'; + } + print dol_get_fiche_end(); + + print '
'; + + $maxEvent = 10; + + $morehtmlcenter = dolGetButtonTitle($langs->trans('SeeAll'), '', 'fa fa-bars imgforviewmode', dol_buildpath('/saturne/view/saturne_agenda.php', 1) . '?id=' . $object->id . '&module_name=DigiQuali&object_type=' . $object->element); + + // List of actions on element + include_once DOL_DOCUMENT_ROOT.'/core/class/html.formactions.class.php'; + $formactions = new FormActions($db); + $somethingshown = $formactions->showactions($object, $object->element . '@' . $object->module, '', 1, '', $MAXEVENT, '', $morehtmlcenter); + + print '
'; +} + +// End of page +llxFooter(); +$db->close(); diff --git a/view/question_group/question_group_list.php b/view/question_group/question_group_list.php new file mode 100644 index 00000000..6f19f0c3 --- /dev/null +++ b/view/question_group/question_group_list.php @@ -0,0 +1,709 @@ + + * + * This program 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 3 of the License, or + * (at your option) any later version. + * + * This program 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 this program. If not, see . + */ + +/** + * \file view/question_group/question_group_list.php + * \ingroup digiquali + * \brief List page for question_group + */ + +// Load DigiQuali environment +if (file_exists('../digiquali.main.inc.php')) { + require_once __DIR__ . '/../digiquali.main.inc.php'; +} elseif (file_exists('../../digiquali.main.inc.php')) { + require_once __DIR__ . '/../../digiquali.main.inc.php'; +} else { + die('Include of digiquali main fails'); +} + +// Libraries +require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php'; +require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php'; +require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php'; +require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcategory.class.php'; +require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php'; + +// load digiquali libraries +require_once __DIR__ . '/../../class/sheet.class.php'; +require_once __DIR__ . '/../../class/question_group.class.php'; +require_once __DIR__ . '/../../class/question_group.class.php'; +require_once __DIR__ . '/../../class/answer.class.php'; + +// Global variables definitions +global $db, $hookmanager, $langs, $user; + +// Load translation files required by the page +saturne_load_langs(["other"]); + +// Get parameters +$action = GETPOST('action', 'aZ09') ?GETPOST('action', 'aZ09') : 'view'; // The action 'add', 'create', 'edit', 'update', 'view', ... +$massaction = GETPOST('massaction', 'alpha'); // The bulk action (combo box choice into lists) +$show_files = GETPOST('show_files', 'int'); // Show files area generated by bulk actions ? +$confirm = GETPOST('confirm', 'alpha'); // Result of a confirmation +$cancel = GETPOST('cancel', 'alpha'); // We click on a Cancel button +$toselect = GETPOST('toselect', 'array'); // Array of ids of elements selected into a list +$contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : 'question_grouplist'; // To manage different context of search +$backtopage = GETPOST('backtopage', 'alpha'); // Go back to a dedicated page +$optioncss = GETPOST('optioncss', 'aZ'); // Option for the css output (always '' except when 'print') +$id = GETPOST('id', 'int'); + +// Load variable for pagination +$limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit; +$sortfield = GETPOST('sortfield', 'aZ09comma'); +$sortorder = GETPOST('sortorder', 'aZ09comma'); +$page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int'); + +if (empty($page) || $page < 0 || GETPOST('button_search', 'alpha') || GETPOST('button_removefilter', 'alpha')) { $page = 0; } // If $page is not defined, or '' or -1 or if we click on clear filters +$offset = $limit * $page; +$pageprev = $page - 1; +$pagenext = $page + 1; + +// Initialize objects +// Technical objets +$object = new QuestionGroup($db); +$answer = new Answer($db); +$sheet = new Sheet($db); +$extrafields = new ExtraFields($db); + +// View objects +$form = new Form($db); + +$hookmanager->initHooks(array('question_grouplist')); // Note that conf->hooks_modules contains array + +// Fetch optionals attributes and labels +$extrafields->fetch_name_optionals_label($object->table_element); +//$extrafields->fetch_name_optionals_label($object->table_element_line); + +if (!empty($conf->categorie->enabled)) { + $search_category_array = GETPOST("search_category_question_group_list", "array"); +} + +$search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_'); + +// Default sort order (if not yet defined by previous GETPOST) +if (!$sortfield) { + reset($object->fields); // Reset is required to avoid key() to return null + $sortfield = 't.date_creation'; // Set here default search field. By default, date_creation +} +if (!$sortorder) { + $sortorder = 'DESC'; +} + +// Initialize array of search criterias +$searchAll = GETPOST('search_all', 'alphanohtml') ? GETPOST('search_all', 'alphanohtml') : GETPOST('sall', 'alphanohtml'); +$search = []; +$search['status'] = 'specialCase'; +foreach ($object->fields as $key => $val) { + if (GETPOST('search_'.$key, 'alpha') !== '') { + $search[$key] = GETPOST('search_' . $key, 'alpha'); + } +} +// List of fields to search into when doing a "search in all" +$fieldstosearchall = []; +foreach ($object->fields as $key => $val) { + if ($val['searchall']) $fieldstosearchall['t.'.$key] = $val['label']; +} + +// Definition of array of fields for columns +$arrayfields = []; +foreach ($object->fields as $key => $val) { + // If $val['visible']==0, then we never show the field + if (!empty($val['visible'])) { + $visible = (int) dol_eval($val['visible'], 1); + $arrayfields['t.'.$key] = [ + 'label' => $val['label'], + 'checked' => (($visible < 0) ? 0 : 1), + 'enabled' => ($visible != 3 && dol_eval($val['enabled'], 1)), + 'position' => $val['position'], + 'help' => $val['help'] + ]; + } +} + +// Extra fields +include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_array_fields.tpl.php'; + +$object->fields = dol_sort_array($object->fields, 'position'); +$arrayfields = dol_sort_array($arrayfields, 'position'); + +$permissiontoread = $user->rights->digiquali->question_group->read; +$permissiontoadd = $user->rights->digiquali->question_group->write; +$permissiontodelete = $user->rights->digiquali->question_group->delete; + +// Security check +saturne_check_access($permissiontoread, $object); + +/* + * Actions + */ + +if (GETPOST('cancel', 'alpha')) { + $action = 'list'; + $massaction = ''; +} +if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') { + $massaction = ''; +} + +$parameters = []; +$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks +if ($reshook < 0) { + setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); +} + +if (empty($reshook)) { + // Selection of new fields + include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php'; + + // Purge search criteria + if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) { // All tests are required to be compatible with all browsers + foreach ($object->fields as $key => $val) { + $search[$key] = ''; + } + $toselect = ''; + $search_array_options = []; + $search_category_array = []; + } + if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha') || GETPOST('button_search_x', 'alpha') || GETPOST('button_search.x', 'alpha') || GETPOST('button_search', 'alpha')) { + $massaction = ''; // Protection to avoid mass action if we force a new search during a mass action confirmation + } + + $error = 0; + + // Action to set status STATUS_LOCKED + if (!$error && ($massaction == 'lock' || ($action == 'lock' && $confirm == 'yes')) && $permissiontoadd) { + if (!empty($toselect)) { + foreach ($toselect as $toselectedid) { + $object->fetch($toselectedid); + if ($object->type == 'UniqueChoice' || $object->type == 'MultipleChoices') { + $answerList = $answer->fetchAll('ASC', 'position', 0, 0, ['fk_question_group' => $object->id]); + } + if (($object->type != 'UniqueChoice' && $object->type != 'MultipleChoices') || !empty($answerList)) { + // Set locked OK + $object->setLocked($user, false); + $massaction = ''; + foreach ($object->fields as $key => $val) { + $search[$key] = ''; + } + $toselect = ''; + $search_array_options = []; + $action = 'list'; + setEventMessages($langs->trans("LockQuestion", $object->ref), []); + } else { + // Set locked KO + setEventMessages($langs->trans('AnswerMustBeCreated', $object->ref), [], 'errors'); + } + } + } + } + + // Mass actions + $objectclass = 'Question'; + $objectlabel = 'Question'; + $uploaddir = $conf->digiquali->dir_output; + + if (!$error && ($massaction == 'delete' || ($action == 'delete' && $confirm == 'yes')) && $permissiontodelete) { + $db->begin(); + + $objecttmp = new $objectclass($db); + $nbok = 0; + $TMsg = []; + foreach ($toselect as $toselectid) { + $result = $objecttmp->fetch($toselectid); + if ($result > 0) { + if (method_exists($objecttmp, 'isErasable') && $objecttmp->isErasable() <= 0) { + $langs->load("errors"); + $nbignored++; + $TMsg[] = '
'.$langs->trans('ErrorQuestionUsedInSheet',$objecttmp->ref).'

'; + continue; + } + + $result = $objecttmp->delete($user); + + if (empty($result)) { // if delete returns 0, there is at least one object linked + $TMsg = array_merge($objecttmp->errors, $TMsg); + } elseif ($result < 0) { // if delete returns is < 0, there is an error, we break and rollback later + setEventMessages($objecttmp->error, $objecttmp->errors, 'errors'); + $error++; + break; + } else { + $nbok++; + } + } else { + setEventMessages($objecttmp->error, $objecttmp->errors, 'errors'); + $error++; + break; + } + } + + if (empty($error)) { + // Message for elements well deleted + if ($nbok > 1) { + setEventMessages($langs->trans("RecordsDeleted", $nbok), null, 'mesgs'); + } elseif ($nbok > 0) { + setEventMessages($langs->trans("RecordDeleted", $nbok), null, 'mesgs'); + } + + // Message for elements which can't be deleted + if (!empty($TMsg)) { + sort($TMsg); + setEventMessages('', array_unique($TMsg), 'warnings'); + } + + $db->commit(); + } else { + $db->rollback(); + } + } + + if (!$error && ($massaction == 'add_question_groups' || ($action == 'add_question_groups' && $confirm == 'yes')) && $permissiontoadd) { + if (is_array($toselect) && !empty($toselect)) { + $totalQuestions = 0; + $question_groupInArray = []; + if (GETPOSTISSET('sheet') && GETPOST('sheet') > 0) { + $sheet->fetch(GETPOST('sheet')); + $sheet->fetchObjectLinked($sheet->id, 'digiquali_' . $sheet->element, null, 'digiquali_' . $object->element, 'OR', 1, 'position'); + foreach ($toselect as $selected) { + $object->fetch($selected); + if (is_array($sheet->linkedObjectsIds['digiquali_' . $object->element]) && !empty($sheet->linkedObjectsIds['digiquali_' . $object->element]) && in_array($object->id, $sheet->linkedObjectsIds['digiquali_' . $object->element])) { + $question_groupInArray[] = $object->getNomUrl(1, 'nolink', 1); + } else { + $totalQuestions++; + $object->add_object_linked('digiquali_' . $sheet->element, GETPOST('sheet')); + $question_groupIds = $sheet->linkedObjectsIds['digiquali_' . $object->element]; + $question_groupIds[] = $object->id; + $sheet->updateQuestionsPosition($question_groupIds); + } + } + if (!empty($question_groupInArray)) { + setEventMessages($langs->trans('WarningQuestionLink', count($question_groupInArray)) . ' ', $question_groupInArray, 'warnings'); + } + if ($totalQuestionGroups > 0) { + setEventMessages($langs->trans('AddQuestionGroupLink', $totalQuestionGroups) . ' ' . $sheet->getNomUrl(1), []); + } + } else { + setEventMessages($langs->transnoentities('ObjectNotFound', img_picto('', $sheet->picto, 'class="paddingrightonly"') . $langs->transnoentities(ucfirst($sheet->element))), [], 'errors'); + } + } + } + + // Mass actions archive + require_once __DIR__ . '/../../../saturne/core/tpl/actions/list_massactions.tpl.php'; +} + +/* + * View + */ + +$now = dol_now(); +$help_url = ''; +$title = $langs->trans('ListOf', $langs->transnoentitiesnoconv("QuestionGroups")); + +// Build and execute select +// -------------------------------------------------------------------- +$sql = 'SELECT DISTINCT '; +foreach ($object->fields as $key => $val) { + $sql .= 't.'.$key.', '; +} +// Add fields from extrafields +if (!empty($extrafields->attributes[$object->table_element]['label'])) { + foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) { + $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? "ef." . $key . ' as options_' . $key . ', ' : ''); + } +} +// Add fields from hooks +$parameters = []; +$reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters, $object); // Note that $action and $object may have been modified by hook +$sql .= preg_replace('/^,/', '', $hookmanager->resPrint); +$sql = preg_replace('/,\s*$/', '', $sql); +$sql .= " FROM ".MAIN_DB_PREFIX.$object->table_element." as t"; +if (!empty($conf->categorie->enabled)) { + $sql .= Categorie::getFilterJoinQuery('question_group', "t.rowid"); +} +if (is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) { + $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . $object->table_element . "_extrafields as ef on (t.rowid = ef.fk_object)"; +} +// Add table from hooks +$parameters = []; +$reshook = $hookmanager->executeHooks('printFieldListFrom', $parameters, $object); // Note that $action and $object may have been modified by hook +$sql .= $hookmanager->resPrint; +if ($object->ismultientitymanaged == 1) { + $sql .= " WHERE t.entity IN (" . getEntity($object->element) . ")"; +} else { + $sql .= " WHERE 1 = 1"; +} +$sql .= ' AND status > -1'; +foreach ($search as $key => $val) { + if ($key == 'status' && $val == 'specialCase') { + $newStatus = [QuestionGroup::STATUS_VALIDATED, QuestionGroup::STATUS_LOCKED]; + if (!empty($newStatus)) { + $sql .= natural_search($key, implode(',', $newStatus), 2); + } + continue; + } elseif ($key == 'status' && $val == -1) { + continue; + } + $mode_search = (($object->isInt($object->fields[$key]) || $object->isFloat($object->fields[$key])) ? 1 : 0); + if (strpos($object->fields[$key]['type'], 'integer:') === 0) { + if ($search[$key] == '-1') $search[$key] = ''; + $mode_search = 2; + } + if ($search[$key] != '') { + $sql .= natural_search($key, $search[$key], (($key == 'status') ? 2 : $mode_search)); + } +} +if ($searchAll) { + $sql .= natural_search(array_keys($fieldstosearchall), $searchAll); +} + +if (!empty($conf->categorie->enabled)) { + $sql .= Categorie::getFilterSelectQuery('question_group', "t.rowid", $search_category_array); +} + +//$sql.= dolSqlDateFilter("t.field", $search_xxxday, $search_xxxmonth, $search_xxxyear); +// Add where from extra fields +include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php'; +// Add where from hooks +$parameters = []; +$reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $object); // Note that $action and $object may have been modified by hook +$sql .= $hookmanager->resPrint; + +$sql .= $db->order($sortfield, $sortorder); + +// Count total nb of records +$nbtotalofrecords = ''; +if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) { + $resql = $db->query($sql); + $nbtotalofrecords = $db->num_rows($resql); + if (($page * $limit) > $nbtotalofrecords) { // if total of record found is smaller than page * limit, goto and load page 0 + $page = 0; + $offset = 0; + } +} + +// if total of record found is smaller than limit, no need to do paging and to restart another select with limits set. +if (is_numeric($nbtotalofrecords) && ($limit > $nbtotalofrecords || empty($limit))) { + $num = $nbtotalofrecords; +} else { + if ($limit) $sql .= $db->plimit($limit + 1, $offset); + + $resql = $db->query($sql); + if (!$resql) { + dol_print_error($db); + exit; + } + + $num = $db->num_rows($resql); +} + +// Direct jump if only one record found +if ($num == 1 && !empty($conf->global->MAIN_SEARCH_DIRECT_OPEN_IF_ONLY_ONE) && $searchAll && !$page) { + $obj = $db->fetch_object($resql); + $id = $obj->rowid; + header("Location: ".dol_buildpath('/digiquali/view/question_group/question_group_card.php', 1).'?id='.$id); + exit; +} + + +// Output page +// -------------------------------------------------------------------- + +saturne_header(0,'', $title, $help_url); + +$arrayofselected = is_array($toselect) ? $toselect : []; + +$param = ''; +if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param .= '&contextpage='.urlencode($contextpage); +if ($limit > 0 && $limit != $conf->liste_limit) $param .= '&limit='.urlencode($limit); +foreach ($search as $key => $val) { + if (is_array($search[$key]) && count($search[$key])) foreach ($search[$key] as $skey) $param .= '&search_'.$key.'[]='.urlencode($skey); + else $param .= '&search_'.$key.'='.urlencode($search[$key]); +} +if ($optioncss != '') $param .= '&optioncss='.urlencode($optioncss); + +// Add $param from extra fields +include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php'; + +// Add $param from hooks +$parameters = []; +$reshook = $hookmanager->executeHooks('printFieldListSearchParam', $parameters, $object); // Note that $action and $object may have been modified by hook +$param .= $hookmanager->resPrint; + +// List of mass actions available +$arrayofmassactions['prelock'] = '' . $langs->trans('Lock'); +$arrayofmassactions['prearchive'] = '' . $langs->trans('Archive'); +$arrayofmassactions['pre_add_question_groups'] = '' . $langs->transnoentities('AddToSheet'); + +if ($permissiontodelete) { + $arrayofmassactions['predelete'] = '' . $langs->trans('Delete'); +} +if (GETPOST('nomassaction', 'int') || in_array($massaction, ['presend', 'predelete'])) { + $arrayofmassactions = []; +} +$massactionbutton = $form->selectMassAction('', $arrayofmassactions); + +print '
'."\n"; +if ($optioncss != '') print ''; +print ''; +print ''; +print ''; +print ''; +print ''; +print ''; + +$newcardbutton = dolGetButtonTitle($langs->trans('New'), '', 'fa fa-plus-circle', dol_buildpath('/digiquali/view/question_group/question_group_card.php', 1).'?action=create', '', $permissiontoadd); + +print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'object_'.$object->picto, 0, $newcardbutton, '', $limit, 0, 0, 1); + +if ($massaction == 'prelock') { + print $form->formconfirm($_SERVER["PHP_SELF"], $langs->trans('ConfirmMassLock'), $langs->trans('ConfirmMassLockingQuestionGroup', count($toselect)), 'lock', null, '', 0, 200, 500, 1); +} + +if ($massaction == 'prearchive') { + print $form->formconfirm($_SERVER["PHP_SELF"], $langs->trans('ConfirmMassArchive'), $langs->trans('ConfirmMassArchivingQuestionGroup', count($toselect)), 'archive', null, '', 0, 200, 500, 1); +} + +if ($massaction == 'pre_add_question_groups') { + $sheets = $sheet->fetchAll('', '', 0, 0, ['customsql' => 't.status = ' . Sheet::STATUS_VALIDATED]); + if (is_array($sheets) && !empty($sheets)) { + $sheetArray = []; + foreach ($sheets as $sheet) { + $sheetArray[$sheet->id] = $sheet->ref . ' - ' . $sheet->label; + } + $formQuestionGroup = [ + ['type' => 'select', 'name' => 'sheet', 'label' => $langs->trans('Sheet'), 'values' => $sheetArray] + ]; + print $form->formconfirm($_SERVER['PHP_SELF'], $langs->trans('ConfirmMassAddQuestionGroup'), $langs->trans('ConfirmMassAddingQuestionGroup', count($toselect)), 'add_question_groups', $formQuestionGroup, '', 0, 200, 500, 1); + } else { + setEventMessages('' . $langs->transnoentities('ObjectNotFound', img_picto('', $sheet->picto, 'class="paddingrightonly"') . $langs->transnoentities(ucfirst($sheet->element))) . '', [], 'warnings'); + } +} + +include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php'; + +if ($searchAll) { + foreach ($fieldstosearchall as $key => $val) $fieldstosearchall[$key] = $langs->trans($val); + print '
'.$langs->trans("FilterOnInto", $searchAll).join(', ', $fieldstosearchall).'
'; +} + +$moreforfilter = ''; + +// Filter on categories +if (!empty($conf->categorie->enabled) && $user->rights->categorie->lire && !empty($search_category_array)) { + $formcategory = new FormCategory($db); + $moreforfilter .= $formcategory->getFilterBox('question_group', $search_category_array); +} + +$parameters = []; +$reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters, $object); // Note that $action and $object may have been modified by hook +if (empty($reshook)) { + $moreforfilter .= $hookmanager->resPrint; +} +else { + $moreforfilter = $hookmanager->resPrint; +} + +if (!empty($moreforfilter)) { + print '
'; + print $moreforfilter; + print '
'; +} + +$varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage; + +$selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields +$selectedfields .= (count($arrayofmassactions) ? $form->showCheckAddButtons('checkforselect', 1) : ''); + +print '
'; // You can use div-table-responsive-no-min if you dont need reserved height for your table +print ''."\n"; + +// Fields title search +// -------------------------------------------------------------------- +print ''; +foreach ($object->fields as $key => $val) { + $cssforfield = (empty($val['css']) ? '' : $val['css']); + if ($key == 'status') $cssforfield .= ($cssforfield ? ' ' : '').'center'; + elseif (in_array($val['type'], array('date', 'datetime', 'timestamp'))) $cssforfield .= ($cssforfield ? ' ' : '').'center'; + elseif (in_array($val['type'], array('timestamp'))) $cssforfield .= ($cssforfield ? ' ' : '').'nowrap'; + elseif (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && $val['label'] != 'TechnicalID') $cssforfield .= ($cssforfield ? ' ' : '').'right'; + if (!empty($arrayfields['t.'.$key]['checked'])) + { + print ''; + } +} + +// Extra fields +include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php'; + +// Fields from hook +$parameters = ['arrayfields' => $arrayfields]; +$reshook = $hookmanager->executeHooks('printFieldListOption', $parameters, $object); // Note that $action and $object may have been modified by hook + +print $hookmanager->resPrint; + +// Action column +print ''; +print ''."\n"; + +// Fields title label +// -------------------------------------------------------------------- +print ''; +foreach ($object->fields as $key => $val) { + $cssforfield = (empty($val['csslist']) ? (empty($val['css']) ? '' : $val['css']) : $val['csslist']); + if ($key == 'status') $cssforfield .= ($cssforfield ? ' ' : '').'center'; + elseif (in_array($val['type'], array('date', 'datetime', 'timestamp'))) $cssforfield .= ($cssforfield ? ' ' : '').'center'; + elseif (in_array($val['type'], array('timestamp'))) $cssforfield .= ($cssforfield ? ' ' : '').'nowrap'; + elseif (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && $val['label'] != 'TechnicalID') $cssforfield .= ($cssforfield ? ' ' : '').'right'; + if (!empty($arrayfields['t.'.$key]['checked'])) { + print getTitleFieldOfList($arrayfields['t.'.$key]['label'], 0, $_SERVER['PHP_SELF'], 't.'.$key, '', $param, ($cssforfield ? 'class="'.$cssforfield.'"' : ''), $sortfield, $sortorder, ($cssforfield ? $cssforfield.' ' : ''))."\n"; + } +} + +// Extra fields +include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php'; + +// Hook fields +$parameters = ['arrayfields' => $arrayfields, 'param' => $param, 'sortfield' => $sortfield, 'sortorder' => $sortorder]; +$reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters, $object); // Note that $action and $object may have been modified by hook +print $hookmanager->resPrint; + +// Action column +print getTitleFieldOfList($selectedfields, 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ')."\n"; +print ''."\n"; + +// Detect if we need a fetch on each output line +$needToFetchEachLine = 0; +if (is_array($extrafields->attributes[$object->table_element]['computed']) && count($extrafields->attributes[$object->table_element]['computed']) > 0) +{ + foreach ($extrafields->attributes[$object->table_element]['computed'] as $key => $val) + { + if (preg_match('/\$object/', $val)) $needToFetchEachLine++; // There is at least one compute field that use $object + } +} + +// Loop on record +// -------------------------------------------------------------------- +$i = 0; +$totalarray = []; +while ($i < ($limit ? min($num, $limit) : $num)) { + $obj = $db->fetch_object($resql); + if (empty($obj)) { + break; + } // Should not happen + + // Store properties in $object + $object->setVarsFromFetchObj($obj); + + // Show here line of result + print ''; + foreach ($object->fields as $key => $val) { + $cssforfield = (empty($val['css']) ? '' : $val['css']); + if (in_array($val['type'], ['date', 'datetime', 'timestamp'])) { + $cssforfield .= ($cssforfield ? ' ' : '').'center'; + } else if ($key == 'status') { + $cssforfield .= ($cssforfield ? ' ' : '').'center'; + } + + if (in_array($val['type'], ['timestamp'])) { + $cssforfield .= ($cssforfield ? ' ' : '') . 'nowrap'; + } else if ($key == 'ref') { + $cssforfield .= ($cssforfield ? ' ' : '') . 'nowrap'; + } + + if (in_array($val['type'], ['double(24,8)', 'double(6,3)', 'integer', 'real', 'price']) && !in_array($key, ['rowid', 'status'])) { + $cssforfield .= ($cssforfield ? ' ' : '').'right'; + } + //if (in_array($key, array('fk_soc', 'fk_user', 'fk_warehouse'))) $cssforfield = 'tdoverflowmax100'; + + if (!empty($arrayfields['t.'.$key]['checked'])) { + print ''; + if ($key == 'status') { + print $object->getLibStatut(5); + } else if ($key == 'ref') { + print $object->getNomUrl(1); + } else if ($key == 'type') { + print $object->showOutputField($val, $key, $langs->trans($object->$key), ''); + } else { + print $object->showOutputField($val, $key, $object->$key, ''); + } + print ''; + if (!$i) { + $totalarray['nbfield']++; + } + if (!empty($val['isameasure'])) { + if (!$i) { + $totalarray['pos'][$totalarray['nbfield']] = 't.' . $key; + } + $totalarray['val']['t.'.$key] += $object->$key; + } + } + } + + // Extra fields + include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php'; + + // Fields from hook + $parameters = ['arrayfields' => $arrayfields, 'object' => $object, 'obj' => $obj, 'i' => $i, 'totalarray' => &$totalarray]; + $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters, $object); // Note that $action and $object may have been modified by hook + print $hookmanager->resPrint; + + // Action column + print ''; + if (!$i) $totalarray['nbfield']++; + + print ''."\n"; + + $i++; +} + +// If no record found +if ($num == 0) { + $colspan = 1; + foreach ($arrayfields as $key => $val) { if (!empty($val['checked'])) $colspan++; } + print ''; +} + + +$db->free($resql); + +$parameters = array('arrayfields'=>$arrayfields, 'sql'=>$sql); +$reshook = $hookmanager->executeHooks('printFieldListFooter', $parameters, $object); // Note that $action and $object may have been modified by hook +print $hookmanager->resPrint; + +print '
'; + if (is_array($val['arrayofkeyval']) && !empty($val['arrayofkeyval'])) { + print $form->selectarray('search_' . $key, $val['arrayofkeyval'], $search[$key], $val['notnull'], 0, 0, '', 1, 0, 0, '', (($key != 'status') ? 'maxwidth100' : 'maxwidth200'), 1); + } elseif (strpos($val['type'], 'integer:') === 0) { + print $object->showInputField($val, $key, $search[$key], '', '', 'search_', 'maxwidth125', 1); + } elseif (!preg_match('/^(date|timestamp)/', $val['type'])) print ''; + print ''; +$searchpicto = $form->showFilterButtons(); +print $searchpicto; +print '
'; + if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined + $selected = 0; + if (in_array($object->id, $arrayofselected)) $selected = 1; + print ''; + } + print '
'.$langs->trans("NoRecordFound").'
'."\n"; +print '
'."\n"; + +print '
'."\n"; + +// End of page +llxFooter(); +$db->close();