diff --git a/class/dolisirhsignature.class.php b/class/dolisirhsignature.class.php deleted file mode 100644 index eea6280..0000000 --- a/class/dolisirhsignature.class.php +++ /dev/null @@ -1,614 +0,0 @@ - - * - * 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/dolisirhsignature.class.php - * \ingroup dolisirh - * \brief This file is a CRUD class file for DoliSIRHSignature (Create/Read/Update/Delete) - */ - -require_once DOL_DOCUMENT_ROOT . '/core/class/commonobject.class.php'; -require_once DOL_DOCUMENT_ROOT . '/core/lib/ticket.lib.php'; - -/** - * Class for DoliSIRHSignature - */ -class DoliSIRHSignature extends CommonObject -{ - /** - * @var DoliDB Database handler. - */ - public $db; - - /** - * @var string[] Array of error strings - */ - public $errors = array(); - - /** - * @var string ID of module. - */ - public $module = 'dolisirh'; - - /** - * @var string ID to identify managed object. - */ - public $element = 'object_signature'; - - /** - * @var string Name of table without prefix where object is stored. This is also the key used for extrafields management. - */ - public $table_element = 'dolisirh_object_signature'; - - /** - * @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 = 0; - - /** - * @var string String with name of icon for dolisirhsignature. Must be the part after the 'object_' into object_dolisirhsignature.png - */ - public $picto = 'object_signature@dolisirh'; - - /** - * @var array Label status of const. - */ - public $labelStatus; - - /** - * @var array Label status short of const. - */ - public $labelStatusShort; - - const STATUS_DELETED = 0; - const STATUS_REGISTERED = 1; - const STATUS_SIGNATURE_REQUEST = 2; - const STATUS_PENDING_SIGNATURE = 3; - const STATUS_DENIED = 4; - const STATUS_SIGNED = 5; - const STATUS_UNSIGNED = 6; - const STATUS_ABSENT = 7; - const STATUS_JUSTIFIED_ABSENT = 8; - - /** - * @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 = array( - 'rowid' => array('type' => 'integer', 'label' => 'TechnicalID', 'enabled' => '1', 'position' => 1, 'notnull' => 1, 'visible' => 0, 'noteditable' => '1', 'index' => 1, 'comment' => "Id"), - 'entity' => array('type' => 'integer', 'label' => 'Entity', 'enabled' => '1', 'position' => 10, 'notnull' => 1, 'visible' => -1,), - 'date_creation' => array('type' => 'datetime', 'label' => 'DateCreation', 'enabled' => '1', 'position' => 20, 'notnull' => 1, 'visible' => -2,), - 'tms' => array('type' => 'timestamp', 'label' => 'DateModification', 'enabled' => '1', 'position' => 30, 'notnull' => 0, 'visible' => -2,), - 'import_key' => array('type' => 'integer', 'label' => 'ImportId', 'enabled' => '1', 'position' => 40, 'notnull' => 1, 'visible' => -2,), - 'status' => array('type' => 'smallint', 'label' => 'Status', 'enabled' => '1', 'position' => 50, 'notnull' => 0, 'visible' => 1, 'index' => 1,), - 'role' => array('type' => 'varchar(255)', 'label' => 'Role', 'enabled' => '1', 'position' => 60, 'notnull' => 0, 'visible' => 3,), - 'firstname' => array('type' => 'varchar(255)', 'label' => 'Firstname', 'enabled' => '1', 'position' => 70, 'notnull' => 0, 'visible' => 3,), - 'lastname' => array('type' => 'varchar(255)', 'label' => 'Lastname', 'enabled' => '1', 'position' => 80, 'notnull' => 0, 'visible' => 3,), - 'email' => array('type' => 'varchar(255)', 'label' => 'Email', 'enabled' => '1', 'position' => 90, 'notnull' => 0, 'visible' => 3,), - 'phone' => array('type' => 'varchar(255)', 'label' => 'Phone', 'enabled' => '1', 'position' => 100, 'notnull' => 0, 'visible' => 3,), - 'society_name' => array('type' => 'varchar(255)', 'label' => 'SocietyName', 'enabled' => '1', 'position' => 110, 'notnull' => 0, 'visible' => 3,), - 'signature_date' => array('type' => 'datetime', 'label' => 'SignatureDate', 'enabled' => '1', 'position' => 120, 'notnull' => 0, 'visible' => 3,), - 'signature_location' => array('type' => 'varchar(255)', 'label' => 'SignatureLocation', 'enabled' => '1', 'position' => 125, 'notnull' => 0, 'visible' => 3,), - 'signature_comment' => array('type' => 'varchar(255)', 'label' => 'SignatureComment', 'enabled' => '1', 'position' => 130, 'notnull' => 0, 'visible' => 3,), - 'element_id' => array('type' => 'integer', 'label' => 'ElementType', 'enabled' => '1', 'position' => 140, 'notnull' => 1, 'visible' => 1,), - 'element_type' => array('type' => 'varchar(50)', 'label' => 'ElementType', 'enabled' => '1', 'position' => 150, 'notnull' => 0, 'visible' => 1,), - 'signature' => array('type' => 'varchar(255)', 'label' => 'Signature', 'enabled' => '1', 'position' => 160, 'notnull' => 0, 'visible' => 3,), - 'stamp' => array('type' => 'varchar(255)', 'label' => 'Stamp', 'enabled' => '1', 'position' => 165, 'notnull' => 0, 'visible' => 3,), - 'signature_url' => array('type' => 'varchar(50)', 'label' => 'SignatureUrl', 'enabled' => '1', 'position' => 170, 'notnull' => 0, 'visible' => 1, 'default' => null,), - 'transaction_url' => array('type' => 'varchar(50)', 'label' => 'TransactionUrl', 'enabled' => '1', 'position' => 180, 'notnull' => 0, 'visible' => 1,'default' => null,), - 'last_email_sent_date' => array('type' => 'datetime', 'label' => 'LastEmailSentDate', 'enabled' => '1', 'position' => 190, 'notnull' => 0, 'visible' => 3,), - 'object_type' => array('type' => 'varchar(255)', 'label' => 'object_type', 'enabled' => '1', 'position' => 195, 'notnull' => 0, 'visible' => 0,), - 'fk_object' => array('type' => 'integer', 'label' => 'FKObject', 'enabled' => '1', 'position' => 200, 'notnull' => 1, 'visible' => 0,), - ); - - public $rowid; - public $entity; - public $date_creation; - public $tms; - public $import_key; - public $status; - public $role; - public $firstname; - public $lastname; - public $email; - public $phone; - public $society_name; - public $signature_date; - public $element_id; - public $element_type; - public $signature; - public $stamp; - public $signature_url; - public $last_email_sent_date; - public $object_type; - public $fk_object; - - /** - * Constructor - * - * @param DoliDb $db Database handler - */ - public function __construct(DoliDB $db) - { - global $conf, $langs; - - $this->db = $db; - - if (empty($conf->global->MAIN_SHOW_TECHNICAL_ID) && isset($this->fields['rowid'])) $this->fields['rowid']['visible'] = 0; - if (empty($conf->multicompany->enabled) && isset($this->fields['entity'])) $this->fields['entity']['enabled'] = 0; - - // Unset fields that are disabled - foreach ($this->fields as $key => $val) { - if (isset($val['enabled']) && empty($val['enabled'])) { - unset($this->fields[$key]); - } - } - - // Translate some data of arrayofkeyval - if (is_object($langs)) { - foreach ($this->fields as $key => $val) { - if ( ! empty($val['arrayofkeyval']) && is_array($val['arrayofkeyval'])) { - foreach ($val['arrayofkeyval'] as $key2 => $val2) { - $this->fields[$key]['arrayofkeyval'][$key2] = $langs->trans($val2); - } - } - } - } - } - - /** - * 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 - { - return $this->createCommon($user, $notrigger); - } - - /** - * Load object in memory from the database - * - * @param int $id ID object - * @param string|null $ref Ref - * @param string $morewhere More SQL filters (' AND ...') - * @return int 0 < if KO, 0 if not found, >0 if OK - */ - public function fetch(int $id, string $ref = null, string $morewhere = ''): int - { - return $this->fetchCommon($id, $ref, $morewhere); - } - - /** - * Load list of objects in memory from the database. - * - * @param string $sortorder Sort Order - * @param string $sortfield Sort field - * @param int $limit Limit - * @param int $offset Offset - * @param array $filter Filter array. Example array('field'=>'value', 'customurl'=>...) - * @param string $filtermode Filter mode (AND/OR) - * @param string $old_table_element Old table element due to rework - * @return array|int int <0 if KO, array of pages if OK - * @throws Exception - */ - public function fetchAll(string $sortorder = '', string $sortfield = '', int $limit = 0, int $offset = 0, array $filter = array(), string $filtermode = 'AND', string $old_table_element = '') - { - dol_syslog(__METHOD__, LOG_DEBUG); - - $records = array(); - - $sql = 'SELECT '; - if (dol_strlen($old_table_element) > 0) { - unset($this->fields['signature_location']); - unset($this->fields['object_type']); - } - $sql .= $this->getFieldList(); - - if (dol_strlen($old_table_element)) { - $sql .= ' FROM ' . MAIN_DB_PREFIX . $old_table_element . ' as t'; - } else { - $sql .= ' FROM ' . MAIN_DB_PREFIX . $this->table_element . ' as t'; - } if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) $sql .= ' WHERE t.entity IN (' . getEntity($this->table_element) . ')'; - else $sql .= ' WHERE 1 = 1'; - // Manage filter - $sqlwhere = array(); - if (count($filter) > 0) { - foreach ($filter as $key => $value) { - if ($key == 't.rowid') { - $sqlwhere[] = $key . '=' . $value; - } elseif (in_array($this->fields[$key]['type'], array('date', 'datetime', 'timestamp'))) { - $sqlwhere[] = $key . ' = \'' . $this->db->idate($value) . '\''; - } elseif ($key == 'customsql') { - $sqlwhere[] = $value; - } elseif (strpos($value, '%') === false) { - $sqlwhere[] = $key . ' IN (' . $this->db->sanitize($this->db->escape($value)) . ')'; - } else { - $sqlwhere[] = $key . ' LIKE \'%' . $this->db->escape($value) . '%\''; - } - } - } - if (count($sqlwhere) > 0) { - $sql .= ' AND (' . implode(' ' . $filtermode . ' ', $sqlwhere) . ')'; - } - - if ( ! empty($sortfield)) { - $sql .= $this->db->order($sortfield, $sortorder); - } - if ( ! empty($limit)) { - $sql .= ' ' . $this->db->plimit($limit, $offset); - } - $resql = $this->db->query($sql); - - if ($resql) { - $num = $this->db->num_rows($resql); - $i = 0; - while ($i < ($limit ? min($limit, $num) : $num)) { - $obj = $this->db->fetch_object($resql); - - $record = new self($this->db); - $record->setVarsFromFetchObj($obj); - - $records[$record->id] = $record; - - $i++; - } - $this->db->free($resql); - - return $records; - } else { - $this->errors[] = 'Error ' . $this->db->lasterror(); - dol_syslog(__METHOD__ . ' ' . join(',', $this->errors), LOG_ERR); - - return -1; - } - } - - /** - * Update object into database - * - * @param User $user User that modifies - * @param bool $notrigger false=launch triggers after, true=disable triggers - * @return int 0 < if KO, >0 if OK - */ - public function update(User $user, bool $notrigger = false): int - { - return $this->updateCommon($user, $notrigger); - } - - /** - * Delete object in database - * - * @param User $user User that deletes - * @param bool $notrigger false=launch triggers after, true=disable triggers - * @return int 0 < if KO, >0 if OK - */ - public function delete(User $user, bool $notrigger = false): int - { - return $this->deleteCommon($user, $notrigger); - } - - /** - * Set registered status - * - * @param User $user Object user that modify - * @param int $notrigger 1=Does not execute triggers, 0=Execute triggers - * @return int 0 < if KO, >0 if OK - */ - public function setRegistered(User $user, int $notrigger = 0): int - { - return $this->setStatusCommon($user, self::STATUS_REGISTERED, $notrigger, 'DOLISIRHSIGNATURE_REGISTERED'); - } - - /** - * Set pending status - * - * @param User $user Object user that modify - * @param int $notrigger 1=Does not execute triggers, 0=Execute triggers - * @return int 0 < if KO, >0 if OK - */ - public function setPending(User $user, int $notrigger = 0): int - { - return $this->setStatusCommon($user, self::STATUS_PENDING_SIGNATURE, $notrigger, 'DOLISIRHSIGNATURE_PENDING_SIGNATURE'); - } - - /** - * Set signed status - * - * @param User $user Object user that modify - * @param int $notrigger 1=Does not execute triggers, 0=Execute triggers - * @return int 0 < if KO, >0 if OK - */ - public function setSigned(User $user, int $notrigger = 0): int - { - return $this->setStatusCommon($user, self::STATUS_SIGNED, $notrigger, 'DOLISIRHSIGNATURE_SIGNED'); - } - - /** - * Set absent status - * - * @param User $user Object user that modify - * @param int $notrigger 1=Does not execute triggers, 0=Execute triggers - * @return int 0 < if KO, >0 if OK - */ - public function setAbsent(User $user, int $notrigger = 0): int - { - return $this->setStatusCommon($user, self::STATUS_ABSENT, $notrigger, 'DOLISIRHSIGNATURE_ABSENT'); - } - - /** - * Set deleted status - * - * @param User $user Object user that modify - * @param int $notrigger 1=Does not execute triggers, 0=Execute triggers - * @return int 0 < if KO, >0 if OK - */ - public function setDeleted(User $user, int $notrigger = 0): int - { - return $this->setStatusCommon($user, self::STATUS_DELETED, $notrigger, 'DOLISIRHSIGNATURE_DELETED'); - } - - /** - * Return the label of the 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 getLibStatut(int $mode = 0): string - { - return $this->LibStatut($this->status, $mode); - } - - /** - * 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_DELETED] = $langs->transnoentities('Deleted'); - $this->labelStatus[self::STATUS_REGISTERED] = $langs->transnoentities('Registered'); - $this->labelStatus[self::STATUS_SIGNATURE_REQUEST] = $langs->transnoentities('SignatureRequest'); - $this->labelStatus[self::STATUS_PENDING_SIGNATURE] = $langs->transnoentities('PendingSignature'); - $this->labelStatus[self::STATUS_DENIED] = $langs->transnoentities('Denied'); - $this->labelStatus[self::STATUS_SIGNED] = $langs->transnoentities('Signed'); - $this->labelStatus[self::STATUS_UNSIGNED] = $langs->transnoentities('Unsigned'); - $this->labelStatus[self::STATUS_ABSENT] = $langs->transnoentities('Absent'); - $this->labelStatus[self::STATUS_JUSTIFIED_ABSENT] = $langs->transnoentities('JustifiedAbsent'); - } - - $statusType = 'status' . $status; - if ($status == self::STATUS_SIGNED) $statusType = 'status4'; - if ($status == self::STATUS_ABSENT) $statusType = 'status8'; - - return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status], '', $statusType, $mode); - } - - /** - * Create signatory in database - * - * @param int $fk_object ID of object linked - * @param string $object_type Type of object - * @param string $element_type Type of resource - * @param array $element_ids ID of resource - * @param string $role Role of resource - * @param int $noupdate Update previous signatories - * @return int - * @throws Exception - */ - public function setSignatory(int $fk_object, string $object_type, string $element_type, array $element_ids, string $role = "", int $noupdate = 0): int - { - global $conf, $user; - - $society = new Societe($this->db); - $result = 0; - if ( ! empty($element_ids) && $element_ids > 0) { - if ( ! $noupdate) { - $this->deletePreviousSignatories($role, $fk_object, $object_type); - } - foreach ($element_ids as $element_id) { - if ($element_id > 0) { - $signatory_data = ''; - if ($element_type == 'user') { - $signatory_data = new User($this->db); - - $signatory_data->fetch($element_id); - - if ($signatory_data->socid > 0) { - $society->fetch($signatory_data->socid); - $this->society_name = $society->name; - } else { - $this->society_name = $conf->global->MAIN_INFO_SOCIETE_NOM; - } - - $this->phone = $signatory_data->user_mobile; - } elseif ($element_type == 'socpeople') { - $signatory_data = new Contact($this->db); - - $signatory_data->fetch($element_id); - if (!is_object($signatory_data)) { - $signatory_data = new StdClass(); - } - - $society->fetch($signatory_data->socid); - - $this->society_name = $society->name; - $this->phone = $signatory_data->phone_mobile; - } - - $this->status = self::STATUS_REGISTERED; - - $this->firstname = $signatory_data->firstname; - $this->lastname = $signatory_data->lastname; - $this->email = $signatory_data->email; - $this->role = $role; - - $this->element_type = $element_type; - $this->element_id = $element_id; - - $this->signature_url = generate_random_id(); - - $this->fk_object = $fk_object; - - $result = $this->create($user); - } - } - } - if ($result > 0 ) { - return 1; - } else { - return 0; - } - } - - /** - * Fetch signatory from database - * - * @param string $role Role of resource - * @param int $fk_object ID of object linked - * @param string $object_type ID of object linked - * @return array|int - * @throws Exception - */ - public function fetchSignatory(string $role, int $fk_object, string $object_type) - { - $filter = array('customsql' => 'fk_object=' . $fk_object . ' AND status!=0 AND object_type="' . $object_type . '"'); - if (strlen($role)) { - $filter['customsql'] .= ' AND role = "' . $role . '"'; - return $this->fetchAll('', '', 0, 0, $filter); - } else { - $signatories = $this->fetchAll('', '', 0, 0, $filter); - if ( ! empty($signatories) && $signatories > 0) { - $signatoriesArray = array(); - foreach ($signatories as $signatory) { - $signatoriesArray[$signatory->role][$signatory->id] = $signatory; - } - return $signatoriesArray; - } else { - return 0; - } - } - } - - /** - * Fetch signatories in database with parent ID - * - * @param int $fk_object ID of object linked - * @param string $object_type Type of object - * @param string $morefilter Filter - * @return array|integer - * @throws Exception - */ - public function fetchSignatories(int $fk_object, string $object_type, string $morefilter = '1 = 1') - { - $filter = array('customsql' => 'fk_object=' . $fk_object . ' AND ' . $morefilter . ' AND object_type="' . $object_type . '"' . ' AND status > 0'); - return $this->fetchAll('', '', 0, 0, $filter); - } - - /** - * Check if signatories signed - * - * @param int $fk_object ID of object linked - * @param string $object_type Type of object - * @return int - * @throws Exception - */ - public function checkSignatoriesSignatures(int $fk_object, string $object_type): int - { - $morefilter = 'status != 0'; - - $signatories = $this->fetchSignatories($fk_object, $object_type, $morefilter); - - if ( ! empty($signatories) && $signatories > 0) { - foreach ($signatories as $signatory) { - if ($signatory->status == 5 || $signatory->status == 7) { - continue; - } else { - return 0; - } - } - return 1; - } else { - return -1; - } - } - - /** - * Delete signatories signatures - * - * @param int $fk_object ID of object linked - * @param string $object_type Type of object - * @return int - * @throws Exception - */ - public function deleteSignatoriesSignatures(int $fk_object, string $object_type): int - { - global $user; - - $signatories = $this->fetchSignatories($fk_object, $object_type); - - if ( ! empty($signatories) && $signatories > 0) { - foreach ($signatories as $signatory) { - if (dol_strlen($signatory->signature)) { - $signatory->signature = ''; - $signatory->signature_date = ''; - $signatory->status = 1; - $signatory->update($user); - } - } - return 1; - } else { - return -1; - } - } - - /** - * Set previous signatories status to 0 - * - * @param string $role Role of resource - * @param int $fk_object ID of object linked - * @param string $object_type Type of object linked - * @return int - * @throws Exception - */ - public function deletePreviousSignatories(string $role, int $fk_object, string $object_type): int - { - global $user; - $filter = array('customsql' => ' role="' . $role . '" AND fk_object=' . $fk_object . ' AND status=1 AND object_type="' . $object_type . '"'); - $signatoriesToDelete = $this->fetchAll('', '', 0, 0, $filter); - - if ( ! empty($signatoriesToDelete) && $signatoriesToDelete > 0) { - foreach ($signatoriesToDelete as $signatoryToDelete) { - $signatoryToDelete->setDeleted($user, true); - } - return 1; - } else { - return -1; - } - } -} diff --git a/core/tpl/signature/dolisirh_signature_action_view.tpl.php b/core/tpl/signature/dolisirh_signature_action_view.tpl.php deleted file mode 100644 index b4b4b4a..0000000 --- a/core/tpl/signature/dolisirh_signature_action_view.tpl.php +++ /dev/null @@ -1,44 +0,0 @@ -
- - -
- - - - diff --git a/core/tpl/signature/dolisirh_signature_view.tpl.php b/core/tpl/signature/dolisirh_signature_view.tpl.php deleted file mode 100644 index 4d1801e..0000000 --- a/core/tpl/signature/dolisirh_signature_view.tpl.php +++ /dev/null @@ -1,43 +0,0 @@ -signature) && ($object->status == $object::STATUS_VALIDATED || $element->signature == $langs->transnoentities("FileGenerated")) && $element->status != $element::STATUS_ABSENT) : ?> - -signature)) : ?> - - - - - - - - diff --git a/core/tpl/signature/index.php b/core/tpl/signature/index.php deleted file mode 100644 index cd6990e..0000000 --- a/core/tpl/signature/index.php +++ /dev/null @@ -1,2 +0,0 @@ - --- --- 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_dolisirh_object_signature ADD INDEX idx_dolisirh_object_signature_rowid (rowid); -ALTER TABLE llx_dolisirh_object_signature ADD INDEX idx_dolisirh_object_signature_status (status); -ALTER TABLE llx_dolisirh_object_signature ADD INDEX idx_dolisirh_object_signature_element_id (element_id); -ALTER TABLE llx_dolisirh_object_signature ADD INDEX idx_dolisirh_object_signature_fk_object (fk_object); diff --git a/sql/signature/llx_dolisirh_object_signature.sql b/sql/signature/llx_dolisirh_object_signature.sql deleted file mode 100644 index 69f1ccb..0000000 --- a/sql/signature/llx_dolisirh_object_signature.sql +++ /dev/null @@ -1,41 +0,0 @@ --- Copyright (C) 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_dolisirh_object_signature( - rowid integer AUTO_INCREMENT PRIMARY KEY NOT NULL, - entity integer DEFAULT 1 NOT NULL, - date_creation datetime NOT NULL, - tms timestamp, - import_key integer DEFAULT NULL, - status smallint, - role varchar(255), - firstname varchar(255), - lastname varchar(255), - email varchar(255), - phone varchar(255), - society_name varchar(255), - signature_date datetime DEFAULT NULL, - signature_location varchar(255), - signature_comment text DEFAULT NULL, - element_id integer NOT NULL, - element_type varchar(255), - signature longtext, - stamp text, - last_email_sent_date datetime DEFAULT NULL, - signature_url varchar(255), - transaction_url varchar(255), - object_type varchar(255), - fk_object integer NOT NULL -) ENGINE=innodb; diff --git a/view/timesheet/timesheet_attendants.php b/view/timesheet/timesheet_attendants.php deleted file mode 100644 index 72baae5..0000000 --- a/view/timesheet/timesheet_attendants.php +++ /dev/null @@ -1,482 +0,0 @@ - - * - * 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/timesheet/timesheet_attendants.php - * \ingroup dolisirh - * \brief Page to add/edit/view timesheet_signature - */ - -// Load Dolibarr environment -$res = 0; -// Try main.inc.php into web root known defined into CONTEXT_DOCUMENT_ROOT (not always defined) -if (!$res && !empty($_SERVER["CONTEXT_DOCUMENT_ROOT"])) { - $res = @include $_SERVER["CONTEXT_DOCUMENT_ROOT"]."/main.inc.php"; -} -// Try main.inc.php into web root detected using web root calculated from SCRIPT_FILENAME -$tmp = empty($_SERVER['SCRIPT_FILENAME']) ? '' : $_SERVER['SCRIPT_FILENAME']; $tmp2 = realpath(__FILE__); $i = strlen($tmp) - 1; $j = strlen($tmp2) - 1; -while ($i > 0 && $j > 0 && isset($tmp[$i]) && isset($tmp2[$j]) && $tmp[$i] == $tmp2[$j]) { - $i--; $j--; -} -if (!$res && $i > 0 && file_exists(substr($tmp, 0, ($i + 1))."/main.inc.php")) { - $res = @include substr($tmp, 0, ($i + 1))."/main.inc.php"; -} -if (!$res && $i > 0 && file_exists(dirname(substr($tmp, 0, ($i + 1)))."/main.inc.php")) { - $res = @include dirname(substr($tmp, 0, ($i + 1)))."/main.inc.php"; -} -// Try main.inc.php using relative path -if (!$res && file_exists("../main.inc.php")) { - $res = @include "../main.inc.php"; -} -if (!$res && file_exists("../../main.inc.php")) { - $res = @include "../../main.inc.php"; -} -if (!$res && file_exists("../../../main.inc.php")) { - $res = @include "../../../main.inc.php"; -} -if (!$res && file_exists("../../../../main.inc.php")) { - $res = @include "../../../../main.inc.php"; -} -if (!$res) { - die("Include of main fails"); -} - -require_once DOL_DOCUMENT_ROOT . '/core/lib/images.lib.php'; -require_once DOL_DOCUMENT_ROOT . '/projet/class/project.class.php'; -require_once DOL_DOCUMENT_ROOT . '/contact/class/contact.class.php'; -require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php'; - -require_once __DIR__ . '/../../class/timesheet.class.php'; -require_once __DIR__ . '/../../lib/dolisirh_timesheet.lib.php'; -require_once __DIR__ . '/../../lib/dolisirh_function.lib.php'; - -global $db, $hookmanager, $langs, $user; - -// Load translation files required by the page -$langs->loadLangs(array("dolisirh@dolisirh", "other")); - -// Get parameters -$id = GETPOST('id', 'int'); -$ref = GETPOST('ref', 'alpha'); -$action = GETPOST('action', 'aZ09'); -$contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : 'timesheetsignature'; // To manage different context of search -$backtopage = GETPOST('backtopage', 'alpha'); -$cancel = GETPOST('cancel', 'aZ09'); - -// Initialize technical objects -$object = new TimeSheet($db); -$signatory = new TimeSheetSignature($db); -$usertmp = new User($db); -$contact = new Contact($db); -$form = new Form($db); -$project = new Project($db); -$thirdparty = new Societe($db); - -$object->fetch($id); - -$hookmanager->initHooks(array($object->element.'signature', 'globalcard')); // Note that conf->hooks_modules contains array - -// Load object -include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be include, not include_once // Must be include, not include_once. Include fetch and fetch_thirdparty but not fetch_optionals - -//Security check -$object_type = $object->element; -$permissiontoread = $user->rights->dolisirh->$object_type->read; -$permissiontoadd = $user->rights->dolisirh->$object_type->write; -$permissiontodelete = $user->rights->dolisirh->$object_type->delete; - -if ( ! $permissiontoread) accessforbidden(); - -/* - * 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($backtopage) || ($cancel && empty($id))) { - if (empty($backtopage) || ($cancel && strpos($backtopage, '__ID__'))) { - $backtopage = dol_buildpath('/dolisirh/view/'. $object->element .'/' . $object->element .'_attendants.php', 1) . '?id=' . ($object->id > 0 ? $object->id : '__ID__'); - } -} - -// Action to add internal attendant -if ($action == 'addSocietyAttendant') { - $error = 0; - $object->fetch($id); - $attendant_id = GETPOST('user_attendant'); - - if ( ! $error) { - $role = strtoupper(GETPOST('attendantRole')); - $result = $signatory->setSignatory($object->id, $object->element, 'user', array($attendant_id), strtoupper($object->element).'_' . $role, $role == 'SOCIETY_RESPONSIBLE ' ? 0 : 1); - if ($result > 0) { - $usertmp = $user; - $usertmp->fetch($attendant_id); - setEventMessages($langs->trans('AddAttendantMessage') . ' ' . $usertmp->firstname . ' ' . $usertmp->lastname, array()); - $signatory->call_trigger('DOLISIRHSIGNATURE_ADDATTENDANT', $user); - // Creation attendant OK - $urltogo = str_replace('__ID__', $result, $backtopage); - $urltogo = preg_replace('/--IDFORBACKTOPAGE--/', $id, $urltogo); // New method to autoselect project after a New on another form object creation - header("Location: " . $urltogo); - exit; - } else { - // Creation attendant KO - if ( ! empty($object->errors)) setEventMessages(null, $object->errors, 'errors'); - else setEventMessages($object->error, null, 'errors'); - } - } -} - -// Action to add record -if ($action == 'addSignature') { - $signatoryID = GETPOST('signatoryID'); - $data = json_decode(file_get_contents('php://input'), true); - - $signatory->fetch($signatoryID); - $signatory->signature = $data['signature']; - $signatory->signature_date = dol_now('tzuser'); - - if ( ! $error) { - $result = $signatory->update($user, false); - - if ($result > 0) { - // Creation signature OK - $signatory->setSigned($user, 0); - setEventMessages($langs->trans('SignatureEvent') . ' ' . $signatory->firstname . ' ' . $signatory->lastname, array()); - $urltogo = str_replace('__ID__', $result, $backtopage); - $urltogo = preg_replace('/--IDFORBACKTOPAGE--/', $id, $urltogo); // New method to autoselect project after a New on another form object creation - header("Location: " . $urltogo); - exit; - } else { - // Creation signature KO - if ( ! empty($signatory->errors)) setEventMessages(null, $signatory->errors, 'errors'); - else setEventMessages($signatory->error, null, 'errors'); - } - } -} - -// Action to set status STATUS_ABSENT -if ($action == 'setAbsent') { - $signatoryID = GETPOST('signatoryID'); - - $signatory->fetch($signatoryID); - - if ( ! $error) { - $result = $signatory->setAbsent($user, 0); - if ($result > 0) { - // set absent OK - setEventMessages($langs->trans('Attendant') . ' ' . $signatory->firstname . ' ' . $signatory->lastname . ' ' . $langs->trans('SetAbsentAttendant'), array()); - $urltogo = str_replace('__ID__', $result, $backtopage); - $urltogo = preg_replace('/--IDFORBACKTOPAGE--/', $id, $urltogo); // New method to autoselect project after a New on another form object creation - header("Location: " . $urltogo); - exit; - } else { - // set absent KO - if ( ! empty($signatory->errors)) setEventMessages(null, $signatory->errors, 'errors'); - else setEventMessages($signatory->error, null, 'errors'); - } - } -} - -// Action to send Email -if ($action == 'send') { - $signatoryID = GETPOST('signatoryID'); - $signatory->fetch($signatoryID); - - if ( ! $error) { - $langs->load('mails'); - - if (!dol_strlen($signatory->email)) { - if ($signatory->element_type == 'user') { - $usertmp = $user; - $usertmp->fetch($signatory->element_id); - if (dol_strlen($usertmp->email)) { - $signatory->email = $usertmp->email; - $signatory->update($user, true); - } - } elseif ($signatory->element_type == 'socpeople') { - $contact->fetch($signatory->element_id); - if (dol_strlen($contact->email)) { - $signatory->email = $contact->email; - $signatory->update($user, true); - } - } - } - - $sendto = $signatory->email; - - if (dol_strlen($sendto) && ( ! empty($conf->global->MAIN_MAIL_EMAIL_FROM))) { - require_once DOL_DOCUMENT_ROOT . '/core/class/CMailFile.class.php'; - - $from = $conf->global->MAIN_MAIL_EMAIL_FROM; - $url = dol_buildpath('/custom/dolisirh/public/signature/add_signature.php?track_id=' . $signatory->signature_url . '&type=' . $object->element, 3); - - $message = $langs->trans('SignatureEmailMessage') . ' ' . $url; - $subject = $langs->trans('SignatureEmailSubject') . ' ' . $object->ref; - - // Create form object - // Send mail (substitutionarray must be done just before this) - $mailfile = new CMailFile($subject, $sendto, $from, $message, array(), array(), array(), "", "", 0, -1, '', '', '', '', 'mail'); - - if ($mailfile->error) { - setEventMessages($mailfile->error, $mailfile->errors, 'errors'); - } else { - if ( ! empty($conf->global->MAIN_MAIL_SMTPS_ID)) { - $result = $mailfile->sendfile(); - if ($result) { - $signatory->last_email_sent_date = dol_now('tzuser'); - $signatory->update($user, true); - $signatory->setPending($user, false); - setEventMessages($langs->trans('SendEmailAt') . ' ' . $signatory->email, array()); - // This avoid sending mail twice if going out and then back to page - header('Location: ' . $_SERVER["PHP_SELF"] . '?id=' . $object->id); - exit; - } else { - $langs->load("other"); - $mesg = '
'; - if ($mailfile->error) { - $mesg .= $langs->transnoentities('ErrorFailedToSendMail', dol_escape_htmltag($from), dol_escape_htmltag($sendto)); - $mesg .= '
' . $mailfile->error; - } else { - $mesg .= $langs->transnoentities('ErrorFailedToSendMail', dol_escape_htmltag($from), dol_escape_htmltag($sendto)); - } - $mesg .= '
'; - setEventMessages($mesg, null, 'warnings'); - } - } else { - setEventMessages($langs->trans('ErrorSetupEmail'), '', 'errors'); - } - } - } else { - $langs->load("errors"); - setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv("MailTo")), null, 'warnings'); - dol_syslog('Try to send email with no recipient defined', LOG_WARNING); - } - } else { - // Mail sent KO - if ( ! empty($signatory->errors)) setEventMessages(null, $signatory->errors, 'errors'); - else setEventMessages($signatory->error, null, 'errors'); - } -} - -// Action to delete attendant -if ($action == 'deleteAttendant') { - $signatoryToDeleteID = GETPOST('signatoryID'); - $signatory->fetch($signatoryToDeleteID); - - if ( ! $error) { - $result = $signatory->setDeleted($user, 0); - if ($result > 0) { - setEventMessages($langs->trans('DeleteAttendantMessage') . ' ' . $signatory->firstname . ' ' . $signatory->lastname, array()); - // Deletion attendant OK - $urltogo = str_replace('__ID__', $result, $backtopage); - $urltogo = preg_replace('/--IDFORBACKTOPAGE--/', $id, $urltogo); // New method to autoselect project after a New on another form object creation - header("Location: " . $urltogo); - exit; - } else { - // Deletion attendant KO - if ( ! empty($object->errors)) setEventMessages(null, $object->errors, 'errors'); - else setEventMessages($object->error, null, 'errors'); - } - } -} - -/* - * View - */ - -$title = $langs->trans("TimeSheetAttendants"); -$help_url = 'FR:Module_DoliSIRH'; -$morejs = array("/dolisirh/js/signature-pad.min.js", "/dolisirh/js/dolisirh.js"); -$morecss = array("/dolisirh/css/dolisirh.css"); - -llxHeader('', $title, $help_url, '', '', '', $morejs, $morecss); - -// Part to show record -if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'create'))) { - if ( ! empty($object->id)) $res = $object->fetch_optionals(); - - // Object card - // ------------------------------------------------------------ - - $prepareHead = $object->element . 'PrepareHead'; - $head = $prepareHead($object); - print dol_get_fiche_head($head, 'attendants', $langs->trans("TimeSheet"), -1, $object->picto); - - $linkback = ''.$langs->trans("BackToList").''; - - $morehtmlref = '
'; - // Thirdparty - if (! empty($conf->societe->enabled)) { - $object->fetch_thirdparty(); - $morehtmlref .= $langs->trans('ThirdParty') . ' : ' . (is_object($object->thirdparty) ? $object->thirdparty->getNomUrl(1) : ''); - } - // Project - if (! empty($conf->projet->enabled)) { - $langs->load("projects"); - $morehtmlref .= '
' . $langs->trans('Project') . ' '; - if (! empty($object->fk_project)) { - $project->fetch($object->fk_project); - $morehtmlref .= ': ' . $project->getNomUrl(1, '', 1); - } else { - $morehtmlref .= ''; - } - } - $morehtmlref .= '
'; - - $object->picto = 'timesheet_small@dolisirh'; - dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref); - - print '
'; - - print dol_get_fiche_end(); - - print '
'; ?> - - status == $object::STATUS_DRAFT ) : ?> -
-
-
trans('DisclaimerSignatureTitle') ?>
-
trans("TimeSheetMustBeValidatedToSign") ?>
-
- trans("GoToValidate") ?>; -
- - - '; - - if ($signatory->checkSignatoriesSignatures($object->id, $object->element) && $object->status < $object::STATUS_LOCKED) { - print '' . $langs->trans("GoToLock") . ''; - } - - //Society attendants -- Participants de la société - $society_intervenants = $signatory->fetchSignatory(strtoupper($object->element).'_SOCIETY_ATTENDANT', $object->id, $object->element); - $society_responsible = $signatory->fetchSignatory(strtoupper($object->element).'_SOCIETY_RESPONSIBLE', $object->id, $object->element); - - $society_intervenants = array_merge($society_intervenants, $society_responsible); - - print load_fiche_titre($langs->trans("Attendants"), '', ''); - - print ''; - - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - - $already_added_users = array(); - $j = 1; - if (is_array($society_intervenants) && ! empty($society_intervenants) && $society_intervenants > 0) { - foreach ($society_intervenants as $element) { - $usertmp = $user; - $usertmp->fetch($element->element_id); - print ''; - print ''; - print ''; - print ''; - $already_added_users[$element->element_id] = $element->element_id; - $j++; - } - } else { - print ''; - } - - if ($object->status == $object::STATUS_DRAFT && $conf->global->DOLISIRH_TIMESHEET_ADD_ATTENDANTS && $permissiontoadd) { - print ''; - print ''; - print ''; - print ''; - print ''; - - //Participants interne - print ''; - print ''; - print ''; - print '
' . $langs->trans("Name") . '' . $langs->trans("Role") . '' . $langs->trans("SignatureLink") . '' . $langs->trans("SendMailDate") . '' . $langs->trans("SignatureDate") . '' . $langs->trans("Status") . '' . $langs->trans("ActionsSignature") . '' . $langs->trans("Signature") . '
'; - print $usertmp->getNomUrl(1); - print ''; - print $langs->trans($element->role); - print ''; - if ($object->status == $object::STATUS_VALIDATED) { - $signatureUrl = dol_buildpath('/custom/dolisirh/public/signature/add_signature.php?track_id=' . $element->signature_url . '&type=' . $object->element, 3); - print ''; - } else { - print '-'; - } - - print ''; - print dol_print_date($element->last_email_sent_date, 'dayhour'); - print ''; - print dol_print_date($element->signature_date, 'dayhour'); - print ''; - print $element->getLibStatut(5); - print ''; - if ($permissiontoadd && $object->status < $object::STATUS_LOCKED) { - require __DIR__ . "/../../core/tpl/signature/dolisirh_signature_action_view.tpl.php"; - } - print ''; - if ($element->signature != $langs->transnoentities("FileGenerated") && $permissiontoadd) { - require __DIR__ . "/../../core/tpl/signature/dolisirh_signature_view.tpl.php"; - } - print '
'; - print $langs->trans('NoSocietyAttendants'); - print '
'; - print $form->select_dolusers('', 'user_attendant', 1, $already_added_users, 0, '', '', $conf->entity); - print ''; - print ''; - print ajax_combobox('attendantRole'); - print ''; - print '-'; - print ''; - print '-'; - print ''; - print '-'; - print ''; - print '-'; - print ''; - print ''; - print ''; - print '-'; - print '
'; - print ''; - } - print '
'; -} - -// End of page -llxFooter(); -$db->close(); -