dolibarr 24.0.0-beta
commonsignedobject.class.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2024 William Mead <william.mead@manchenumerique.fr>
3 * Copyright (C) 2025 Frédéric France <frederic.france@free.fr>
4 * Copyright (C) 2025 MDW <mdeweerd@users.noreply.github.com>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
36trait CommonSignedObject
37{
42 public $signed_status = 0;
43
49 public static $SIGNED_STATUSES = [
50 'STATUS_NO_SIGNATURE' => 0,
51 'STATUS_SIGNED_SENDER' => 1,
52 'STATUS_SIGNED_RECEIVER' => 2,
53 'STATUS_SIGNED_RECEIVER_ONLINE' => 3,
54 'STATUS_SIGNED_ALL' => 9, // To handle future kind of signature (ex: tripartite contract)
55 ];
56
62 public function getSignedStatusLocalisedArray(): array
63 {
64 global $langs;
65 $langs->load("commercial");
66
67 $l10n_signed_status_labels = [
68 self::$SIGNED_STATUSES['STATUS_NO_SIGNATURE'] => 'NoSignature',
69 self::$SIGNED_STATUSES['STATUS_SIGNED_SENDER'] => 'SignedSender',
70 self::$SIGNED_STATUSES['STATUS_SIGNED_RECEIVER'] => 'SignedReceiver',
71 self::$SIGNED_STATUSES['STATUS_SIGNED_RECEIVER_ONLINE'] => 'SignedReceiverOnline',
72 self::$SIGNED_STATUSES['STATUS_SIGNED_ALL'] => 'SignedAll'
73 ];
74
75 $l10n_signed_status = [];
76 foreach (self::$SIGNED_STATUSES as $signed_status_code) {
77 $l10n_signed_status[$signed_status_code] = $langs->transnoentitiesnoconv($l10n_signed_status_labels[$signed_status_code]);
78 }
79 return $l10n_signed_status;
80 }
81
91 public function setSignedStatus(User $user, int $status = 0, int $notrigger = 0, string $triggercode = ''): int
92 {
93 global $langs;
94
95 $langs->loadLangs(array('commercial'));
96
97 $this->signed_status = $status;
98 $this->context['signature'] = $status;
99
100 switch ($status) {
101 case 0:
102 $this->context['actionmsg2'] = $langs->transnoentitiesnoconv('UnsignedInDolibarr');
103 break;
104 case 1:
105 $this->context['actionmsg2'] = $langs->transnoentitiesnoconv('SignedSender');
106 break;
107 case 2:
108 $this->context['actionmsg2'] = $langs->transnoentitiesnoconv('SignedReceiver');
109 break;
110 case 3:
111 $this->context['actionmsg2'] = $langs->transnoentitiesnoconv('SignedReceiverOnline');
112 break;
113 case 9:
114 $this->context['actionmsg2'] = $langs->transnoentitiesnoconv('SignedAll');
115 break;
116 }
117 return $this->setSignedStatusCommon($user, $status, $notrigger, $triggercode);
118 }
119
129 public function setSignedStatusCommon(User $user, int $status, int $notrigger = 0, string $triggercode = ''): int
130 {
131 global $langs;
132 $langs->loadLangs(array('commercial'));
133
134 $error = 0;
135
136 if ($this instanceof CommonObject) {
137 $this->db->begin();
138 $statusfield = 'signed_status';
139
140 $sql = "UPDATE ".$this->db->prefix().$this->table_element;
141 $sql .= " SET ".$this->db->sanitize($statusfield)." = ".((int) $status);
142 $sql .= " WHERE rowid = ".((int) $this->id);
143
144 if ($this->db->query($sql)) {
145 $this->oldcopy = clone $this;
146
147 if (!$notrigger) {
148 // Call trigger
149 $result = $this->call_trigger($triggercode, $user);
150 if ($result < 0) {
151 $error++;
152 }
153 }
154
155 if (!$error) {
156 $this->signed_status = $status;
157 $this->db->commit();
158
159 setEventMessages($langs->transnoentitiesnoconv($status == 0 ? 'DocumentUnsigned' : 'DocumentSigned'), null, 'warnings');
160 return 1;
161 } else {
162 $this->db->rollback();
163 return -1;
164 }
165 } else {
166 $this->error = $this->db->error();
167 $this->db->rollback();
168 return -1;
169 }
170 } else {
171 return $error;
172 }
173 }
174
181 public function getLibSignedStatus(int $mode = 0): string
182 {
183 global $langs;
184 $langs->load("commercial");
185 $list_signed_status = $this->getSignedStatusLocalisedArray();
186 $signed_status_label = $this->signed_status != '' ? $list_signed_status[$this->signed_status] : '';
187 $signed_status_label_short = $this->signed_status != '' ? $list_signed_status[$this->signed_status] : '';
188 $signed_status_code = 'status'.$this->signed_status;
189 return dolGetStatus($signed_status_label, $signed_status_label_short, '', $signed_status_code, $mode);
190 }
191}
Parent class of all other business classes (invoices, contracts, proposals, orders,...
Class to manage Dolibarr users.
setSignedStatusCommon(User $user, int $status, int $notrigger=0, string $triggercode='')
Set signed status & call trigger with context message.
setSignedStatus(User $user, int $status=0, int $notrigger=0, string $triggercode='')
Set signed status & object context.
getSignedStatusLocalisedArray()
Returns an array of signed statuses with associated localized labels.
getLibSignedStatus(int $mode=0)
Returns the label for signed status.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
print $langs trans("Show") . '< td style="' . $timeColor . '" align="center"> s</td > badge status0 badge status4 badge status3 Error badge status8< td align="center">< span class="badge ' . $badge . '"></span ></td >< td align="center">< a href="#" class="button button-small" onclick="openLogModal(this)" data-req="' . dol_escape_htmltag($reqSafe) . '" data-res="' . dol_escape_htmltag($resSafe) . '" data-err="' . dol_escape_htmltag($errSafe) . '">< span class="fa fa-search-plus"></span ></a ></td ></tr >< tr >< td colspan="' . $colspan . '" class="opacitymedium"></td ></tr ></table ></div ></form > logModal none logModal none s a JSON string
buildzip.php