dolibarr 18.0.6
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 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <https://www.gnu.org/licenses/>.
17 * or see https://www.gnu.org/
18 */
19
32{
33 global $db, $langs, $conf, $user;
34
35 $h = 0;
36 $head = array();
37
38 $head[$h][0] = DOL_URL_ROOT.'/contrat/card.php?id='.$object->id;
39 $head[$h][1] = $langs->trans("ContractCard");
40 $head[$h][2] = 'card';
41 $h++;
42
43 if (empty($conf->global->MAIN_DISABLE_CONTACTS_TAB)) {
44 $nbContact = count($object->liste_contact(-1, 'internal')) + count($object->liste_contact(-1, 'external'));
45 $head[$h][0] = DOL_URL_ROOT.'/contrat/contact.php?id='.$object->id;
46 $head[$h][1] = $langs->trans("ContactsAddresses");
47 if ($nbContact > 0) {
48 $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbContact.'</span>';
49 }
50 $head[$h][2] = 'contact';
51 $h++;
52 }
53
54 // Show more tabs from modules
55 // Entries must be declared in modules descriptor with line
56 // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
57 // $this->tabs = array('entity:-tabname); to remove a tab
58 complete_head_from_modules($conf, $langs, $object, $head, $h, 'contract', 'add', 'core');
59
60 if (empty($conf->global->MAIN_DISABLE_NOTES_TAB)) {
61 $nbNote = 0;
62 if (!empty($object->note_private)) {
63 $nbNote++;
64 }
65 if (!empty($object->note_public)) {
66 $nbNote++;
67 }
68 $head[$h][0] = DOL_URL_ROOT.'/contrat/note.php?id='.$object->id;
69 $head[$h][1] = $langs->trans("Notes");
70 if ($nbNote > 0) {
71 $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbNote.'</span>';
72 }
73 $head[$h][2] = 'note';
74 $h++;
75 }
76
77 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
78 require_once DOL_DOCUMENT_ROOT.'/core/class/link.class.php';
79 $upload_dir = $conf->contrat->multidir_output[$object->entity]."/".dol_sanitizeFileName($object->ref);
80 $nbFiles = count(dol_dir_list($upload_dir, 'files', 0, '', '(\.meta|_preview.*\.png)$'));
81 $nbLinks = Link::count($db, $object->element, $object->id);
82 $head[$h][0] = DOL_URL_ROOT.'/contrat/document.php?id='.$object->id;
83 $head[$h][1] = $langs->trans("Documents");
84 if (($nbFiles + $nbLinks) > 0) {
85 $head[$h][1] .= '<span class="badge marginleftonlyshort">'.($nbFiles + $nbLinks).'</span>';
86 }
87 $head[$h][2] = 'documents';
88 $h++;
89
90
91 $head[$h][0] = DOL_URL_ROOT.'/contrat/agenda.php?id='.$object->id;
92 $head[$h][1] = $langs->trans("Events");
93 if (isModEnabled('agenda')&& ($user->hasRight('agenda', 'myactions', 'read') || $user->hasRight('agenda', 'allactions', 'read'))) {
94 $nbEvent = 0;
95 // Enable caching of thirdparty count actioncomm
96 require_once DOL_DOCUMENT_ROOT.'/core/lib/memory.lib.php';
97 $cachekey = 'count_events_contract_'.$object->id;
98 $dataretrieved = dol_getcache($cachekey);
99 if (!is_null($dataretrieved)) {
100 $nbEvent = $dataretrieved;
101 } else {
102 $sql = "SELECT COUNT(id) as nb";
103 $sql .= " FROM ".MAIN_DB_PREFIX."actioncomm";
104 $sql .= " WHERE fk_element = ".((int) $object->id);
105 $sql .= " AND elementtype = 'contract'";
106 $resql = $db->query($sql);
107 if ($resql) {
108 $obj = $db->fetch_object($resql);
109 $nbEvent = $obj->nb;
110 } else {
111 dol_syslog('Failed to count actioncomm '.$db->lasterror(), LOG_ERR);
112 }
113 dol_setcache($cachekey, $nbEvent, 120); // If setting cache fails, this is not a problem, so we do not test result.
114 }
115
116 $head[$h][1] .= '/';
117 $head[$h][1] .= $langs->trans("Agenda");
118 if ($nbEvent > 0) {
119 $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbEvent.'</span>';
120 }
121 }
122 $head[$h][2] = 'agenda';
123 $h++;
124
125 complete_head_from_modules($conf, $langs, $object, $head, $h, 'contract', 'add', 'external');
126
127 complete_head_from_modules($conf, $langs, $object, $head, $h, 'contract', 'remove');
128
129 return $head;
130}
131
138{
139 global $langs, $conf, $db;
140
141 $extrafields = new ExtraFields($db);
142 $extrafields->fetch_name_optionals_label('contrat');
143 $extrafields->fetch_name_optionals_label('contratdet');
144
145 $h = 0;
146 $head = array();
147
148 $head[$h][0] = DOL_URL_ROOT."/admin/contract.php";
149 $head[$h][1] = $langs->trans("Contracts");
150 $head[$h][2] = 'contract';
151 $h++;
152
153 // Show more tabs from modules
154 // Entries must be declared in modules descriptor with line
155 // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
156 // $this->tabs = array('entity:-tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to remove a tab
157 complete_head_from_modules($conf, $langs, null, $head, $h, 'contract_admin', 'add', 'core');
158
159 $head[$h][0] = DOL_URL_ROOT.'/contrat/admin/contract_extrafields.php';
160 $head[$h][1] = $langs->trans("ExtraFields");
161 $nbExtrafields = $extrafields->attributes['contrat']['count'];
162 if ($nbExtrafields > 0) {
163 $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbExtrafields.'</span>';
164 }
165 $head[$h][2] = 'attributes';
166 $h++;
167
168 $head[$h][0] = DOL_URL_ROOT.'/contrat/admin/contractdet_extrafields.php';
169 $head[$h][1] = $langs->trans("ExtraFieldsLines");
170 $nbExtrafields = $extrafields->attributes['contratdet']['count'];
171 if ($nbExtrafields > 0) {
172 $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbExtrafields.'</span>';
173 }
174 $head[$h][2] = 'attributeslines';
175 $h++;
176
177 complete_head_from_modules($conf, $langs, null, $head, $h, 'contract_admin', 'add', 'external');
178
179 complete_head_from_modules($conf, $langs, null, $head, $h, 'contract_admin', 'remove');
180
181 return $head;
182}
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 informations.
dol_dir_list($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:62
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).
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.