dolibarr 24.0.0-beta
contract.lib.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2006-2012 Laurent Destailleur <eldy@users.sourceforge.net>
3 * Copyright (C) 2009-2012 Regis Houssin <regis.houssin@inodbox.com>
4 * Copyright (C) 2023 Charlene BENKE <charlene@patas-monkey.com>
5 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
6 * Copyright (C) 2025-2026 Frédéric France <frederic.france@free.fr>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <https://www.gnu.org/licenses/>.
20 * or see https://www.gnu.org/
21 */
22
35{
36 global $db, $langs, $conf, $user;
37
38 $h = 0;
39 $head = array();
40
41 $head[$h][0] = dolBuildUrl(DOL_URL_ROOT.'/contrat/card.php', ['id' => $object->id]);
42 $head[$h][1] = $langs->trans("ContractCard");
43 $head[$h][2] = 'card';
44 $h++;
45
46 if (!getDolGlobalString('MAIN_DISABLE_CONTACTS_TAB')) {
47 $nbContact = count($object->liste_contact(-1, 'internal')) + count($object->liste_contact(-1, 'external'));
48 $head[$h][0] = dolBuildUrl(DOL_URL_ROOT.'/contrat/contact.php', ['id' => $object->id]);
49 $head[$h][1] = $langs->trans("ContactsAddresses");
50 if ($nbContact > 0) {
51 $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbContact.'</span>';
52 }
53 $head[$h][2] = 'contact';
54 $h++;
55 }
56
57 /* deprecated. Contracts and tickets are already linked with the generic "Link to" feature */
58 if (isModEnabled('ticket') && getDolGlobalString('TICKET_LINK_TO_CONTRACT_WITH_HARDLINK')) {
59 $head[$h][0] = dolBuildUrl(DOL_URL_ROOT.'/contrat/ticket.php', ['id' => $object->id]);
60 $head[$h][1] = $langs->trans("Tickets");
61 $head[$h][2] = 'ticket';
62 $h++;
63 }
64
65 // Show more tabs from modules
66 // Entries must be declared in modules descriptor with line
67 // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
68 // $this->tabs = array('entity:-tabname); to remove a tab
69 complete_head_from_modules($conf, $langs, $object, $head, $h, 'contract', 'add', 'core');
70
71 if (!getDolGlobalString('MAIN_DISABLE_NOTES_TAB')) {
72 $nbNote = 0;
73 if (!empty($object->note_private)) {
74 $nbNote++;
75 }
76 if (!empty($object->note_public)) {
77 $nbNote++;
78 }
79 $head[$h][0] = dolBuildUrl(DOL_URL_ROOT.'/contrat/note.php', ['id' => $object->id]);
80 $head[$h][1] = $langs->trans("Notes");
81 if ($nbNote > 0) {
82 $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbNote.'</span>';
83 }
84 $head[$h][2] = 'note';
85 $h++;
86 }
87
88 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
89 require_once DOL_DOCUMENT_ROOT.'/core/class/link.class.php';
90 $upload_dir = $conf->contrat->multidir_output[$object->entity ?? $conf->entity]."/".dol_sanitizeFileName($object->ref);
91 $nbFiles = count(dol_dir_list($upload_dir, 'files', 0, '', '(\.meta|_preview.*\.png)$'));
92 $nbLinks = Link::count($db, $object->element, $object->id);
93 $head[$h][0] = dolBuildUrl(DOL_URL_ROOT.'/contrat/document.php', ['id' => $object->id]);
94 $head[$h][1] = $langs->trans("Documents");
95 if (($nbFiles + $nbLinks) > 0) {
96 $head[$h][1] .= '<span class="badge marginleftonlyshort">'.($nbFiles + $nbLinks).'</span>';
97 }
98 $head[$h][2] = 'documents';
99 $h++;
100
101
102 $head[$h][0] = dolBuildUrl(DOL_URL_ROOT . '/contrat/agenda.php', ['id' => $object->id]);
103 $head[$h][1] = $langs->trans("Events");
104 if (isModEnabled('agenda') && ($user->hasRight('agenda', 'myactions', 'read') || $user->hasRight('agenda', 'allactions', 'read'))) {
105 $nbEvent = 0;
106 // Enable caching of thirdparty count actioncomm
107 require_once DOL_DOCUMENT_ROOT.'/core/lib/memory.lib.php';
108 $cachekey = 'count_events_contract_'.$object->id;
109 $dataretrieved = dol_getcache($cachekey);
110 if (!is_null($dataretrieved)) {
111 $nbEvent = $dataretrieved;
112 } else {
113 $sql = "SELECT COUNT(id) as nb";
114 $sql .= " FROM ".MAIN_DB_PREFIX."actioncomm";
115 $sql .= " WHERE fk_element = ".((int) $object->id);
116 $sql .= " AND elementtype = 'contract'";
117 $resql = $db->query($sql);
118 if ($resql) {
119 $obj = $db->fetch_object($resql);
120 $nbEvent = $obj->nb;
121 } else {
122 dol_syslog('Failed to count actioncomm '.$db->lasterror(), LOG_ERR);
123 }
124 dol_setcache($cachekey, $nbEvent, 120); // If setting cache fails, this is not a problem, so we do not test result.
125 }
126
127 $head[$h][1] .= '/';
128 $head[$h][1] .= $langs->trans("Agenda");
129 if ($nbEvent > 0) {
130 $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbEvent.'</span>';
131 }
132 }
133 $head[$h][2] = 'agenda';
134 $h++;
135
136 complete_head_from_modules($conf, $langs, $object, $head, $h, 'contract', 'add', 'external');
137
138 complete_head_from_modules($conf, $langs, $object, $head, $h, 'contract', 'remove');
139
140 return $head;
141}
142
149{
150 global $langs, $conf, $extrafields;
151
152 $extrafields->fetch_name_optionals_label('contrat');
153 $extrafields->fetch_name_optionals_label('contratdet');
154
155 $h = 0;
156 $head = array();
157
158 $head[$h][0] = dolBuildUrl(DOL_URL_ROOT."/admin/contract.php");
159 $head[$h][1] = $langs->trans("Contracts");
160 $head[$h][2] = 'contract';
161 $h++;
162
163 // Show more tabs from modules
164 // Entries must be declared in modules descriptor with line
165 // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
166 // $this->tabs = array('entity:-tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to remove a tab
167 complete_head_from_modules($conf, $langs, null, $head, $h, 'contract_admin', 'add', 'core');
168
169 $head[$h][0] = dolBuildUrl(DOL_URL_ROOT.'/contrat/admin/contract_extrafields.php');
170 $head[$h][1] = $langs->trans("ExtraFields");
171 $nbExtrafields = $extrafields->attributes['contrat']['count'];
172 if ($nbExtrafields > 0) {
173 $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbExtrafields.'</span>';
174 }
175 $head[$h][2] = 'attributes';
176 $h++;
177
178 $head[$h][0] = dolBuildUrl(DOL_URL_ROOT.'/contrat/admin/contractdet_extrafields.php');
179 $head[$h][1] = $langs->trans("ExtraFieldsLines");
180 $nbExtrafields = $extrafields->attributes['contratdet']['count'];
181 if ($nbExtrafields > 0) {
182 $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbExtrafields.'</span>';
183 }
184 $head[$h][2] = 'attributeslines';
185 $h++;
186
187 complete_head_from_modules($conf, $langs, null, $head, $h, 'contract_admin', 'add', 'external');
188
189 complete_head_from_modules($conf, $langs, null, $head, $h, 'contract_admin', 'remove');
190
191 return $head;
192}
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
contract_prepare_head(Contrat $object)
Prepare array with list of tabs.
contract_admin_prepare_head()
Return array head with list of tabs to view object information.
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $db
API class for accounts.
dol_dir_list($utf8_path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="", $donotfollowsymlinks=0, $nbsecondsold=0)
Scan a directory and return a list of files/directories.
Definition files.lib.php:64
dolBuildUrl($url, $params=[], $addtoken=false, $anchor='')
Return path of url.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1, $includequotes=0, $allowdash=0)
Clean a string to use it as a file name.
complete_head_from_modules($conf, $langs, $object, &$head, &$h, $type, $mode='add', $filterorigmodule='')
Complete or removed entries into a head array (used to build tabs).
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
dol_setcache($memoryid, $data, $expire=0, $filecache=0, $replace=0)
Save data into a memory area shared by all users, all sessions on server.
dol_getcache($memoryid, $filecache=0)
Read a memory area shared by all users, all sessions on server.