dolibarr 21.0.0-alpha
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 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 * or see https://www.gnu.org/
20 */
21
34{
35 global $db, $langs, $conf, $user;
36
37 $h = 0;
38 $head = array();
39
40 $head[$h][0] = DOL_URL_ROOT.'/contrat/card.php?id='.$object->id;
41 $head[$h][1] = $langs->trans("ContractCard");
42 $head[$h][2] = 'card';
43 $h++;
44
45 if (!getDolGlobalString('MAIN_DISABLE_CONTACTS_TAB')) {
46 $nbContact = count($object->liste_contact(-1, 'internal')) + count($object->liste_contact(-1, 'external'));
47 $head[$h][0] = DOL_URL_ROOT.'/contrat/contact.php?id='.$object->id;
48 $head[$h][1] = $langs->trans("ContactsAddresses");
49 if ($nbContact > 0) {
50 $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbContact.'</span>';
51 }
52 $head[$h][2] = 'contact';
53 $h++;
54 }
55
56 /* deprecated. Contracts and tickets are already linked with the generic "Link to" feature */
57 if (isModEnabled('ticket') && getDolGlobalString('TICKET_LINK_TO_CONTRACT_WITH_HARDLINK')) {
58 $head[$h][0] = DOL_URL_ROOT.'/contrat/ticket.php?id='.$object->id;
59 $head[$h][1] = $langs->trans("Tickets");
60 $head[$h][2] = 'ticket';
61 $h++;
62 }
63
64 // Show more tabs from modules
65 // Entries must be declared in modules descriptor with line
66 // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
67 // $this->tabs = array('entity:-tabname); to remove a tab
68 complete_head_from_modules($conf, $langs, $object, $head, $h, 'contract', 'add', 'core');
69
70 if (!getDolGlobalString('MAIN_DISABLE_NOTES_TAB')) {
71 $nbNote = 0;
72 if (!empty($object->note_private)) {
73 $nbNote++;
74 }
75 if (!empty($object->note_public)) {
76 $nbNote++;
77 }
78 $head[$h][0] = DOL_URL_ROOT.'/contrat/note.php?id='.$object->id;
79 $head[$h][1] = $langs->trans("Notes");
80 if ($nbNote > 0) {
81 $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbNote.'</span>';
82 }
83 $head[$h][2] = 'note';
84 $h++;
85 }
86
87 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
88 require_once DOL_DOCUMENT_ROOT.'/core/class/link.class.php';
89 $upload_dir = $conf->contrat->multidir_output[$object->entity]."/".dol_sanitizeFileName($object->ref);
90 $nbFiles = count(dol_dir_list($upload_dir, 'files', 0, '', '(\.meta|_preview.*\.png)$'));
91 $nbLinks = Link::count($db, $object->element, $object->id);
92 $head[$h][0] = DOL_URL_ROOT.'/contrat/document.php?id='.$object->id;
93 $head[$h][1] = $langs->trans("Documents");
94 if (($nbFiles + $nbLinks) > 0) {
95 $head[$h][1] .= '<span class="badge marginleftonlyshort">'.($nbFiles + $nbLinks).'</span>';
96 }
97 $head[$h][2] = 'documents';
98 $h++;
99
100
101 $head[$h][0] = DOL_URL_ROOT.'/contrat/agenda.php?id='.$object->id;
102 $head[$h][1] = $langs->trans("Events");
103 if (isModEnabled('agenda') && ($user->hasRight('agenda', 'myactions', 'read') || $user->hasRight('agenda', 'allactions', 'read'))) {
104 $nbEvent = 0;
105 // Enable caching of thirdparty count actioncomm
106 require_once DOL_DOCUMENT_ROOT.'/core/lib/memory.lib.php';
107 $cachekey = 'count_events_contract_'.$object->id;
108 $dataretrieved = dol_getcache($cachekey);
109 if (!is_null($dataretrieved)) {
110 $nbEvent = $dataretrieved;
111 } else {
112 $sql = "SELECT COUNT(id) as nb";
113 $sql .= " FROM ".MAIN_DB_PREFIX."actioncomm";
114 $sql .= " WHERE fk_element = ".((int) $object->id);
115 $sql .= " AND elementtype = 'contract'";
116 $resql = $db->query($sql);
117 if ($resql) {
118 $obj = $db->fetch_object($resql);
119 $nbEvent = $obj->nb;
120 } else {
121 dol_syslog('Failed to count actioncomm '.$db->lasterror(), LOG_ERR);
122 }
123 dol_setcache($cachekey, $nbEvent, 120); // If setting cache fails, this is not a problem, so we do not test result.
124 }
125
126 $head[$h][1] .= '/';
127 $head[$h][1] .= $langs->trans("Agenda");
128 if ($nbEvent > 0) {
129 $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbEvent.'</span>';
130 }
131 }
132 $head[$h][2] = 'agenda';
133 $h++;
134
135 complete_head_from_modules($conf, $langs, $object, $head, $h, 'contract', 'add', 'external');
136
137 complete_head_from_modules($conf, $langs, $object, $head, $h, 'contract', 'remove');
138
139 return $head;
140}
141
148{
149 global $langs, $conf, $db;
150
151 $extrafields = new ExtraFields($db);
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] = 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] = 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] = 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( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:58
Class to manage standard extra fields.
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.
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:63
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
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.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
dol_setcache($memoryid, $data, $expire=0)
Save data into a memory area shared by all users, all sessions on server.
dol_getcache($memoryid)
Read a memory area shared by all users, all sessions on server.