dolibarr 21.0.0-alpha
contact.lib.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2006-2010 Laurent Destailleur <eldy@users.sourceforge.net>
3 * Copyright (C) 2010-2017 Regis Houssin <regis.houssin@inodbox.com>
4 * Copyright (C) 2015-2021 Frederic France <frederic.france@netlogic.fr>
5 * Copyright (C) 2015 Raphaƫl Doursenaud <rdoursenaud@gpcsolutions.fr>
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 $tab = 0;
38 $head = array();
39
40 $head[$tab][0] = DOL_URL_ROOT.'/contact/card.php?id='.$object->id;
41 $head[$tab][1] = $langs->trans("Contact");
42 $head[$tab][2] = 'card';
43 $tab++;
44
45 if ((!empty($conf->ldap->enabled) && getDolGlobalString('LDAP_CONTACT_ACTIVE'))
46 && (!getDolGlobalString('MAIN_DISABLE_LDAP_TAB') || !empty($user->admin))) {
47 $langs->load("ldap");
48
49 $head[$tab][0] = DOL_URL_ROOT.'/contact/ldap.php?id='.$object->id;
50 $head[$tab][1] = $langs->trans("LDAPCard");
51 $head[$tab][2] = 'ldap';
52 $tab++;
53 }
54
55 $head[$tab][0] = DOL_URL_ROOT.'/contact/perso.php?id='.$object->id;
56 $head[$tab][1] = $langs->trans("PersonalInformations");
57 $head[$tab][2] = 'perso';
58 $tab++;
59
60 if (isModEnabled('project') && $user->hasRight('project', 'lire')) {
61 $nbProject = 0;
62 // Enable caching of thirdrparty count projects
63 require_once DOL_DOCUMENT_ROOT.'/core/lib/memory.lib.php';
64 $cachekey = 'count_projects_contact_'.$object->id;
65 $dataretrieved = dol_getcache($cachekey);
66
67 if (!is_null($dataretrieved)) {
68 $nbProject = $dataretrieved;
69 } else {
70 $sql = 'SELECT COUNT(n.rowid) as nb';
71 $sql .= ' FROM '.MAIN_DB_PREFIX.'projet as n';
72 $sql .= ' INNER JOIN '.MAIN_DB_PREFIX.'element_contact as cc ON (n.rowid = cc.element_id)';
73 $sql .= " WHERE cc.fk_socpeople = ".((int) $object->id);
74 $sql .= " AND cc.fk_c_type_contact IN (SELECT rowid FROM ".MAIN_DB_PREFIX."c_type_contact WHERE element='project' AND source='external')";
75 $sql .= " AND n.entity IN (".getEntity('project').")";
76
77 $resql = $db->query($sql);
78 if ($resql) {
79 $obj = $db->fetch_object($resql);
80 $nbProject = $obj->nb;
81 } else {
82 dol_print_error($db);
83 }
84 dol_setcache($cachekey, $nbProject, 120); // If setting cache fails, this is not a problem, so we do not test result.
85 }
86 $head[$tab][0] = DOL_URL_ROOT.'/contact/project.php?id='.$object->id;
87 $head[$tab][1] = $langs->trans("Projects");
88 if ($nbProject > 0) {
89 $head[$tab][1] .= '<span class="badge marginleftonlyshort">'.$nbProject.'</span>';
90 }
91 $head[$tab][2] = 'project';
92 $tab++;
93 }
94
95 // Related items
96 if (isModEnabled('order') || isModEnabled("propal") || isModEnabled('invoice') || isModEnabled('intervention') || isModEnabled("supplier_proposal") || isModEnabled("supplier_order") || isModEnabled("supplier_invoice")) {
97 $head[$tab][0] = DOL_URL_ROOT.'/contact/consumption.php?id='.$object->id;
98 $head[$tab][1] = $langs->trans("Referers");
99 $head[$tab][2] = 'consumption';
100 $tab++;
101 }
102
103 // Show more tabs from modules
104 // Entries must be declared in modules descriptor with line
105 // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
106 // $this->tabs = array('entity:-tabname); to remove a tab
107 complete_head_from_modules($conf, $langs, $object, $head, $tab, 'contact', 'add', 'core');
108
109 // Notes
110 if (!getDolGlobalString('MAIN_DISABLE_NOTES_TAB')) {
111 $nbNote = (empty($object->note_private) ? 0 : 1) + (empty($object->note_public) ? 0 : 1);
112 $head[$tab][0] = DOL_URL_ROOT.'/contact/note.php?id='.$object->id;
113 $head[$tab][1] = $langs->trans("Note");
114 if ($nbNote > 0) {
115 $head[$tab][1] .= '<span class="badge marginleftonlyshort">'.$nbNote.'</span>';
116 }
117 $head[$tab][2] = 'note';
118 $tab++;
119 }
120
121 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
122 require_once DOL_DOCUMENT_ROOT.'/core/class/link.class.php';
123 $upload_dir = $conf->societe->dir_output."/contact/".dol_sanitizeFileName($object->ref);
124 $nbFiles = count(dol_dir_list($upload_dir, 'files', 0, '', '(\.meta|_preview.*\.png)$'));
125 $nbLinks = Link::count($db, $object->element, $object->id);
126 $head[$tab][0] = DOL_URL_ROOT.'/contact/document.php?id='.$object->id;
127 $head[$tab][1] = $langs->trans("Documents");
128 if (($nbFiles + $nbLinks) > 0) {
129 $head[$tab][1] .= '<span class="badge marginleftonlyshort">'.($nbFiles + $nbLinks).'</span>';
130 }
131 $head[$tab][2] = 'documents';
132 $tab++;
133
134 // Agenda / Events
135 $head[$tab][0] = DOL_URL_ROOT.'/contact/agenda.php?id='.$object->id;
136 $head[$tab][1] = $langs->trans("Events");
137 if (isModEnabled('agenda') && ($user->hasRight('agenda', 'myactions', 'read') || $user->hasRight('agenda', 'allactions', 'read'))) {
138 $head[$tab][1] .= '/';
139 $head[$tab][1] .= $langs->trans("Agenda");
140 }
141 $head[$tab][2] = 'agenda';
142 $tab++;
143
144 // Log
145 /*
146 $head[$tab][0] = DOL_URL_ROOT.'/contact/info.php?id='.$object->id;
147 $head[$tab][1] = $langs->trans("Info");
148 $head[$tab][2] = 'info';
149 $tab++;*/
150
151 complete_head_from_modules($conf, $langs, $object, $head, $tab, 'contact', 'add', 'external');
152
153 complete_head_from_modules($conf, $langs, $object, $head, $tab, 'contact', 'remove');
154
155 return $head;
156}
157
170function show_contacts_projects($conf, $langs, $db, $object, $backtopage = '', $nocreatelink = 0, $morehtmlright = '')
171{
172 global $user;
173
174 $i = -1;
175
176 if (isModEnabled('project') && $user->hasRight('projet', 'lire')) {
177 $langs->load("projects");
178
179 $newcardbutton = '';
180 if (isModEnabled('project') && $user->hasRight('projet', 'creer') && empty($nocreatelink)) {
181 $newcardbutton .= dolGetButtonTitle($langs->trans('AddProject'), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/projet/card.php?socid='.$object->id.'&amp;action=create&amp;backtopage='.urlencode($backtopage));
182 }
183
184 print "\n";
185 print load_fiche_titre($langs->trans("ProjectsHavingThisContact"), $newcardbutton.$morehtmlright, '');
186 print '<div class="div-table-responsive">';
187 print "\n".'<table class="noborder" width=100%>';
188
189 $sql = 'SELECT p.rowid as id, p.entity, p.title, p.ref, p.public, p.dateo as do, p.datee as de, p.fk_statut as status, p.fk_opp_status, p.opp_amount, p.opp_percent, p.tms as date_modification, p.budget_amount';
190 $sql .= ', cls.code as opp_status_code, ctc.libelle as type_label';
191 $sql .= ' FROM '.MAIN_DB_PREFIX.'projet as p';
192 $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_lead_status as cls on p.fk_opp_status = cls.rowid';
193 $sql .= ' INNER JOIN '.MAIN_DB_PREFIX.'element_contact as cc ON (p.rowid = cc.element_id)';
194 $sql .= ' INNER JOIN '.MAIN_DB_PREFIX.'c_type_contact as ctc ON (ctc.rowid = cc.fk_c_type_contact)';
195 $sql .= " WHERE cc.fk_socpeople = ".((int) $object->id);
196 $sql .= " AND ctc.element='project' AND ctc.source='external'";
197 $sql .= " AND p.entity IN (".getEntity('project').")";
198 $sql .= " ORDER BY p.dateo DESC";
199
200 $result = $db->query($sql);
201 if ($result) {
202 $num = $db->num_rows($result);
203
204 print '<tr class="liste_titre">';
205 print '<td>'.$langs->trans("Ref").'</td>';
206 print '<td>'.$langs->trans("Name").'</td>';
207 print '<td>'.$langs->trans("ContactType").'</td>';
208 print '<td class="center">'.$langs->trans("DateStart").'</td>';
209 print '<td class="center">'.$langs->trans("DateEnd").'</td>';
210 print '<td class="right">'.$langs->trans("OpportunityAmountShort").'</td>';
211 print '<td class="center">'.$langs->trans("OpportunityStatusShort").'</td>';
212 print '<td class="right">'.$langs->trans("OpportunityProbabilityShort").'</td>';
213 print '<td class="right">'.$langs->trans("Status").'</td>';
214 print '</tr>';
215
216 if ($num > 0) {
217 require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
218
219 $projecttmp = new Project($db);
220
221 $i = 0;
222
223 while ($i < $num) {
224 $obj = $db->fetch_object($result);
225 $projecttmp->fetch($obj->id);
226
227 // To verify role of users
228 $userAccess = $projecttmp->restrictedProjectArea($user);
229
230 if ($user->hasRight('projet', 'lire') && $userAccess > 0) {
231 print '<tr class="oddeven">';
232
233 // Ref
234 print '<td>';
235 print $projecttmp->getNomUrl(1);
236 print '</td>';
237
238 // Label
239 print '<td>'.dol_escape_htmltag($obj->title).'</td>';
240 print '<td>'.dol_escape_htmltag($obj->type_label).'</td>';
241 // Date start
242 print '<td class="center">'.dol_print_date($db->jdate($obj->do), "day").'</td>';
243 // Date end
244 print '<td class="center">'.dol_print_date($db->jdate($obj->de), "day").'</td>';
245 // Opp amount
246 print '<td class="right">';
247 if ($obj->opp_status_code) {
248 print price($obj->opp_amount, 1, '', 1, -1, -1, '');
249 }
250 print '</td>';
251 // Opp status
252 print '<td class="center">';
253 if ($obj->opp_status_code) {
254 print $langs->trans("OppStatus".$obj->opp_status_code);
255 }
256 print '</td>';
257 // Opp percent
258 print '<td class="right">';
259 if ($obj->opp_percent) {
260 print price($obj->opp_percent, 1, '', 1, 0).'%';
261 }
262 print '</td>';
263 // Status
264 print '<td class="right">'.$projecttmp->getLibStatut(5).'</td>';
265
266 print '</tr>';
267 }
268 $i++;
269 }
270 } else {
271 print '<tr class="oddeven"><td colspan="8"><span class="opacitymedium">'.$langs->trans("None").'</span></td></tr>';
272 }
273 $db->free($result);
274 } else {
275 dol_print_error($db);
276 }
277 print "</table>";
278 print '</div>';
279
280 print "<br>\n";
281 }
282
283 return $i;
284}
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:58
Class to manage contact/addresses.
Class to manage projects.
contact_prepare_head(Contact $object)
Prepare array with list of tabs.
show_contacts_projects($conf, $langs, $db, $object, $backtopage='', $nocreatelink=0, $morehtmlright='')
Show html area for list of projects.
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
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
dolGetButtonTitle($label, $helpText='', $iconClass='fa fa-file', $url='', $id='', $status=1, $params=array())
Function dolGetButtonTitle : this kind of buttons are used in title in list.
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
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_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.