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 *
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 * or see https://www.gnu.org/
19 */
20
33{
34 global $db, $langs, $conf, $user;
35
36 $h = 0;
37 $head = array();
38
39 $head[$h][0] = DOL_URL_ROOT.'/contrat/card.php?id='.$object->id;
40 $head[$h][1] = $langs->trans("ContractCard");
41 $head[$h][2] = 'card';
42 $h++;
43
44 if (!getDolGlobalString('MAIN_DISABLE_CONTACTS_TAB')) {
45 $nbContact = count($object->liste_contact(-1, 'internal')) + count($object->liste_contact(-1, 'external'));
46 $head[$h][0] = DOL_URL_ROOT.'/contrat/contact.php?id='.$object->id;
47 $head[$h][1] = $langs->trans("ContactsAddresses");
48 if ($nbContact > 0) {
49 $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbContact.'</span>';
50 }
51 $head[$h][2] = 'contact';
52 $h++;
53 }
54
55 /* deprecated. Contracts and tickets are already linked with the generic "Link to" feature */
56 if (isModEnabled('ticket') && getDolGlobalString('TICKET_LINK_TO_CONTRACT_WITH_HARDLINK')) {
57 $head[$h][0] = DOL_URL_ROOT.'/contrat/ticket.php?id='.$object->id;
58 $head[$h][1] = $langs->trans("Tickets");
59 $head[$h][2] = 'ticket';
60 $h++;
61 }
62
63 // Show more tabs from modules
64 // Entries must be declared in modules descriptor with line
65 // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
66 // $this->tabs = array('entity:-tabname); to remove a tab
67 complete_head_from_modules($conf, $langs, $object, $head, $h, 'contract', 'add', 'core');
68
69 if (!getDolGlobalString('MAIN_DISABLE_NOTES_TAB')) {
70 $nbNote = 0;
71 if (!empty($object->note_private)) {
72 $nbNote++;
73 }
74 if (!empty($object->note_public)) {
75 $nbNote++;
76 }
77 $head[$h][0] = DOL_URL_ROOT.'/contrat/note.php?id='.$object->id;
78 $head[$h][1] = $langs->trans("Notes");
79 if ($nbNote > 0) {
80 $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbNote.'</span>';
81 }
82 $head[$h][2] = 'note';
83 $h++;
84 }
85
86 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
87 require_once DOL_DOCUMENT_ROOT.'/core/class/link.class.php';
88 $upload_dir = $conf->contrat->multidir_output[$object->entity]."/".dol_sanitizeFileName($object->ref);
89 $nbFiles = count(dol_dir_list($upload_dir, 'files', 0, '', '(\.meta|_preview.*\.png)$'));
90 $nbLinks = Link::count($db, $object->element, $object->id);
91 $head[$h][0] = DOL_URL_ROOT.'/contrat/document.php?id='.$object->id;
92 $head[$h][1] = $langs->trans("Documents");
93 if (($nbFiles + $nbLinks) > 0) {
94 $head[$h][1] .= '<span class="badge marginleftonlyshort">'.($nbFiles + $nbLinks).'</span>';
95 }
96 $head[$h][2] = 'documents';
97 $h++;
98
99
100 $head[$h][0] = DOL_URL_ROOT.'/contrat/agenda.php?id='.$object->id;
101 $head[$h][1] = $langs->trans("Events");
102 if (isModEnabled('agenda')&& ($user->hasRight('agenda', 'myactions', 'read') || $user->hasRight('agenda', 'allactions', 'read'))) {
103 $nbEvent = 0;
104 // Enable caching of thirdparty count actioncomm
105 require_once DOL_DOCUMENT_ROOT.'/core/lib/memory.lib.php';
106 $cachekey = 'count_events_contract_'.$object->id;
107 $dataretrieved = dol_getcache($cachekey);
108 if (!is_null($dataretrieved)) {
109 $nbEvent = $dataretrieved;
110 } else {
111 $sql = "SELECT COUNT(id) as nb";
112 $sql .= " FROM ".MAIN_DB_PREFIX."actioncomm";
113 $sql .= " WHERE fk_element = ".((int) $object->id);
114 $sql .= " AND elementtype = 'contract'";
115 $resql = $db->query($sql);
116 if ($resql) {
117 $obj = $db->fetch_object($resql);
118 $nbEvent = $obj->nb;
119 } else {
120 dol_syslog('Failed to count actioncomm '.$db->lasterror(), LOG_ERR);
121 }
122 dol_setcache($cachekey, $nbEvent, 120); // If setting cache fails, this is not a problem, so we do not test result.
123 }
124
125 $head[$h][1] .= '/';
126 $head[$h][1] .= $langs->trans("Agenda");
127 if ($nbEvent > 0) {
128 $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbEvent.'</span>';
129 }
130 }
131 $head[$h][2] = 'agenda';
132 $h++;
133
134 complete_head_from_modules($conf, $langs, $object, $head, $h, 'contract', 'add', 'external');
135
136 complete_head_from_modules($conf, $langs, $object, $head, $h, 'contract', 'remove');
137
138 return $head;
139}
140
147{
148 global $langs, $conf, $db;
149
150 $extrafields = new ExtraFields($db);
151 $extrafields->fetch_name_optionals_label('contrat');
152 $extrafields->fetch_name_optionals_label('contratdet');
153
154 $h = 0;
155 $head = array();
156
157 $head[$h][0] = DOL_URL_ROOT."/admin/contract.php";
158 $head[$h][1] = $langs->trans("Contracts");
159 $head[$h][2] = 'contract';
160 $h++;
161
162 // Show more tabs from modules
163 // Entries must be declared in modules descriptor with line
164 // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
165 // $this->tabs = array('entity:-tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to remove a tab
166 complete_head_from_modules($conf, $langs, null, $head, $h, 'contract_admin', 'add', 'core');
167
168 $head[$h][0] = DOL_URL_ROOT.'/contrat/admin/contract_extrafields.php';
169 $head[$h][1] = $langs->trans("ExtraFields");
170 $nbExtrafields = $extrafields->attributes['contrat']['count'];
171 if ($nbExtrafields > 0) {
172 $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbExtrafields.'</span>';
173 }
174 $head[$h][2] = 'attributes';
175 $h++;
176
177 $head[$h][0] = DOL_URL_ROOT.'/contrat/admin/contractdet_extrafields.php';
178 $head[$h][1] = $langs->trans("ExtraFieldsLines");
179 $nbExtrafields = $extrafields->attributes['contratdet']['count'];
180 if ($nbExtrafields > 0) {
181 $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbExtrafields.'</span>';
182 }
183 $head[$h][2] = 'attributeslines';
184 $h++;
185
186 complete_head_from_modules($conf, $langs, null, $head, $h, 'contract_admin', 'add', 'external');
187
188 complete_head_from_modules($conf, $langs, null, $head, $h, 'contract_admin', 'remove');
189
190 return $head;
191}
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:58
Class to manage contracts.
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 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.