dolibarr  13.0.2
contact.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2010 Regis Houssin <regis.houssin@inodbox.com>
3  * Copyright (C) 2012-2015 Laurent Destailleur <eldy@users.sourceforge.net>
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  */
18 
25 require '../main.inc.php';
26 require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
27 require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
28 require_once DOL_DOCUMENT_ROOT.'/core/lib/project.lib.php';
29 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
30 if ($conf->categorie->enabled) { require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php'; }
31 
32 // Load translation files required by the page
33 $langs->loadLangs(array('projects', 'companies'));
34 
35 $id = GETPOST('id', 'int');
36 $ref = GETPOST('ref', 'alpha');
37 $lineid = GETPOST('lineid', 'int');
38 $socid = GETPOST('socid', 'int');
39 $action = GETPOST('action', 'aZ09');
40 
41 $mine = GETPOST('mode') == 'mine' ? 1 : 0;
42 //if (! $user->rights->projet->all->lire) $mine=1; // Special for projects
43 
44 $object = new Project($db);
45 
46 include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be include, not include_once
47 if (!empty($conf->global->PROJECT_ALLOW_COMMENT_ON_PROJECT) && method_exists($object, 'fetchComments') && empty($object->comments)) $object->fetchComments();
48 
49 // Security check
50 $socid = 0;
51 //if ($user->socid > 0) $socid = $user->socid; // For external user, no check is done on company because readability is managed by public status of project and assignement.
52 $result = restrictedArea($user, 'projet', $id, 'projet&project');
53 
54 $hookmanager->initHooks(array('projectcontactcard', 'globalcard'));
55 
56 /*
57  * Actions
58  */
59 
60 // Add new contact
61 if ($action == 'addcontact' && $user->rights->projet->creer)
62 {
63  $result = 0;
64  $result = $object->fetch($id);
65 
66  if ($result > 0 && $id > 0)
67  {
68  $contactid = (GETPOST('userid') ? GETPOST('userid', 'int') : GETPOST('contactid', 'int'));
69  $typeid = (GETPOST('typecontact') ? GETPOST('typecontact') : GETPOST('type'));
70  $result = $object->add_contact($contactid, $typeid, GETPOST("source", 'aZ09'));
71  }
72 
73  if ($result >= 0)
74  {
75  header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
76  exit;
77  } else {
78  if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS')
79  {
80  $langs->load("errors");
81  setEventMessages($langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType"), null, 'errors');
82  } else {
83  setEventMessages($object->error, $object->errors, 'errors');
84  }
85  }
86 }
87 
88 // Change contact's status
89 if ($action == 'swapstatut' && $user->rights->projet->creer)
90 {
91  if ($object->fetch($id))
92  {
93  $result = $object->swapContactStatus(GETPOST('ligne', 'int'));
94  } else {
95  dol_print_error($db);
96  }
97 }
98 
99 // Delete a contact
100 if (($action == 'deleteline' || $action == 'deletecontact') && $user->rights->projet->creer)
101 {
102  $object->fetch($id);
103  $result = $object->delete_contact(GETPOST("lineid"));
104 
105  if ($result >= 0)
106  {
107  header("Location: contact.php?id=".$object->id);
108  exit;
109  } else {
110  dol_print_error($db);
111  }
112 }
113 
114 
115 /*
116  * View
117  */
118 
119 $title = $langs->trans("ProjectContact").' - '.$object->ref.' '.$object->name;
120 if (!empty($conf->global->MAIN_HTML_TITLE) && preg_match('/projectnameonly/', $conf->global->MAIN_HTML_TITLE) && $object->name) $title = $object->ref.' '.$object->name.' - '.$langs->trans("ProjectContact");
121 $help_url = "EN:Module_Projects|FR:Module_Projets|ES:M&oacute;dulo_Proyectos";
122 llxHeader('', $title, $help_url);
123 
124 $form = new Form($db);
125 $formcompany = new FormCompany($db);
126 $contactstatic = new Contact($db);
127 $userstatic = new User($db);
128 
129 
130 /* *************************************************************************** */
131 /* */
132 /* Edition and view mode */
133 /* */
134 /* *************************************************************************** */
135 
136 if ($id > 0 || !empty($ref))
137 {
138  if (!empty($conf->global->PROJECT_ALLOW_COMMENT_ON_PROJECT) && method_exists($object, 'fetchComments') && empty($object->comments)) $object->fetchComments();
139  // To verify role of users
140  //$userAccess = $object->restrictedProjectArea($user,'read');
141  $userWrite = $object->restrictedProjectArea($user, 'write');
142  //$userDelete = $object->restrictedProjectArea($user,'delete');
143  //print "userAccess=".$userAccess." userWrite=".$userWrite." userDelete=".$userDelete;
144 
145  $head = project_prepare_head($object);
146  print dol_get_fiche_head($head, 'contact', $langs->trans("Project"), -1, ($object->public ? 'projectpub' : 'project'));
147 
148 
149  // Project card
150 
151  $linkback = '<a href="'.DOL_URL_ROOT.'/projet/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
152 
153  $morehtmlref = '<div class="refidno">';
154  // Title
155  $morehtmlref .= $object->title;
156  // Thirdparty
157  if ($object->thirdparty->id > 0)
158  {
159  $morehtmlref .= '<br>'.$langs->trans('ThirdParty').' : '.$object->thirdparty->getNomUrl(1, 'project');
160  }
161  $morehtmlref .= '</div>';
162 
163  // Define a complementary filter for search of next/prev ref.
164  if (!$user->rights->projet->all->lire)
165  {
166  $objectsListId = $object->getProjectsAuthorizedForUser($user, 0, 0);
167  $object->next_prev_filter = " rowid in (".(count($objectsListId) ?join(',', array_keys($objectsListId)) : '0').")";
168  }
169 
170  dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
171 
172 
173  print '<div class="fichecenter">';
174  print '<div class="fichehalfleft">';
175  print '<div class="underbanner clearboth"></div>';
176 
177  print '<table class="border tableforfield centpercent">';
178 
179  // Usage
180  print '<tr><td class="tdtop">';
181  print $langs->trans("Usage");
182  print '</td>';
183  print '<td>';
184  if (!empty($conf->global->PROJECT_USE_OPPORTUNITIES))
185  {
186  print '<input type="checkbox" disabled name="usage_opportunity"'.(GETPOSTISSET('usage_opportunity') ? (GETPOST('usage_opportunity', 'alpha') != '' ? ' checked="checked"' : '') : ($object->usage_opportunity ? ' checked="checked"' : '')).'"> ';
187  $htmltext = $langs->trans("ProjectFollowOpportunity");
188  print $form->textwithpicto($langs->trans("ProjectFollowOpportunity"), $htmltext);
189  print '<br>';
190  }
191  if (empty($conf->global->PROJECT_HIDE_TASKS))
192  {
193  print '<input type="checkbox" disabled name="usage_task"'.(GETPOSTISSET('usage_task') ? (GETPOST('usage_task', 'alpha') != '' ? ' checked="checked"' : '') : ($object->usage_task ? ' checked="checked"' : '')).'"> ';
194  $htmltext = $langs->trans("ProjectFollowTasks");
195  print $form->textwithpicto($langs->trans("ProjectFollowTasks"), $htmltext);
196  print '<br>';
197  }
198  if (!empty($conf->global->PROJECT_BILL_TIME_SPENT))
199  {
200  print '<input type="checkbox" disabled name="usage_bill_time"'.(GETPOSTISSET('usage_bill_time') ? (GETPOST('usage_bill_time', 'alpha') != '' ? ' checked="checked"' : '') : ($object->usage_bill_time ? ' checked="checked"' : '')).'"> ';
201  $htmltext = $langs->trans("ProjectBillTimeDescription");
202  print $form->textwithpicto($langs->trans("BillTime"), $htmltext);
203  print '<br>';
204  }
205  print '</td></tr>';
206 
207  // Visibility
208  print '<tr><td class="titlefield">'.$langs->trans("Visibility").'</td><td>';
209  if ($object->public) print $langs->trans('SharedProject');
210  else print $langs->trans('PrivateProject');
211  print '</td></tr>';
212 
213  if (!empty($conf->global->PROJECT_USE_OPPORTUNITIES) && $object->opp_status)
214  {
215  // Opportunity status
216  print '<tr><td>'.$langs->trans("OpportunityStatus").'</td><td>';
217  $code = dol_getIdFromCode($db, $object->opp_status, 'c_lead_status', 'rowid', 'code');
218  if ($code) print $langs->trans("OppStatus".$code);
219  print '</td></tr>';
220 
221  // Opportunity percent
222  print '<tr><td>'.$langs->trans("OpportunityProbability").'</td><td>';
223  if (strcmp($object->opp_percent, '')) print price($object->opp_percent, '', $langs, 1, 0).' %';
224  print '</td></tr>';
225 
226  // Opportunity Amount
227  print '<tr><td>'.$langs->trans("OpportunityAmount").'</td><td>';
228  if (strcmp($object->opp_amount, '')) print price($object->opp_amount, '', $langs, 0, 0, 0, $conf->currency);
229  print '</td></tr>';
230  }
231 
232  // Date start - end
233  print '<tr><td>'.$langs->trans("DateStart").' - '.$langs->trans("DateEnd").'</td><td>';
234  $start = dol_print_date($object->date_start, 'day');
235  print ($start ? $start : '?');
236  $end = dol_print_date($object->date_end, 'day');
237  print ' - ';
238  print ($end ? $end : '?');
239  if ($object->hasDelay()) print img_warning("Late");
240  print '</td></tr>';
241 
242  // Budget
243  print '<tr><td>'.$langs->trans("Budget").'</td><td>';
244  if (strcmp($object->budget_amount, '')) print price($object->budget_amount, '', $langs, 0, 0, 0, $conf->currency);
245  print '</td></tr>';
246 
247  // Other attributes
248  $cols = 2;
249  include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php';
250 
251  print "</table>";
252 
253  print '</div>';
254  print '<div class="fichehalfright">';
255  print '<div class="ficheaddleft">';
256  print '<div class="underbanner clearboth"></div>';
257 
258  print '<table class="border tableforfield" width="100%">';
259 
260  // Description
261  print '<td class="titlefield tdtop">'.$langs->trans("Description").'</td><td>';
262  print nl2br($object->description);
263  print '</td></tr>';
264 
265  // Categories
266  if ($conf->categorie->enabled) {
267  print '<tr><td class="valignmiddle">'.$langs->trans("Categories").'</td><td>';
268  print $form->showCategories($object->id, Categorie::TYPE_PROJECT, 1);
269  print "</td></tr>";
270  }
271 
272  print '</table>';
273 
274  print '</div>';
275  print '</div>';
276  print '</div>';
277 
278  print '<div class="clearboth"></div>';
279 
281 
282  print '<br>';
283 
284  // Contacts lines (modules that overwrite templates must declare this into descriptor)
285  $dirtpls = array_merge($conf->modules_parts['tpl'], array('/core/tpl'));
286  foreach ($dirtpls as $reldir)
287  {
288  $res = @include dol_buildpath($reldir.'/contacts.tpl.php');
289  if ($res) break;
290  }
291 }
292 
293 // End of page
294 llxFooter();
295 $db->close();
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Class to manage contact/addresses.
Class to manage Dolibarr users.
Definition: user.class.php:44
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
img_warning($titlealt= 'default', $moreatt= '', $morecss= 'pictowarning')
Show warning logo.
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...
llxHeader()
Empty header.
Definition: wrapper.php:45
Class to build HTML component for third parties management Only common components are here...
setEventMessages($mesg, $mesgs, $style= 'mesgs', $messagekey= '')
Set event messages in dol_events session object.
Class to manage generation of HTML components Only common components must be here.
Class to manage projects.
restrictedArea($user, $features, $objectid=0, $tableandshare= '', $feature2= '', $dbt_keyfield= 'fk_soc', $dbt_select= 'rowid', $isdraft=0)
Check permissions of a user to show a page and an object.
print $_SERVER["PHP_SELF"]
Edit parameters.
dol_getIdFromCode($db, $key, $tablename, $fieldkey= 'code', $fieldid= 'id', $entityfilter=0)
Return an id or code from a code or id.
dol_get_fiche_head($links=array(), $active= '', $title= '', $notab=0, $picto= '', $pictoisfullpath=0, $morehtmlright= '', $morecss= '', $limittoshow=0, $moretabssuffix= '')
Show tabs of a record.
project_prepare_head(Project $project)
Prepare array with list of tabs.
Definition: project.lib.php:36
print
Draft customers invoices.
Definition: index.php:89
dol_print_date($time, $format= '', $tzoutput= 'auto', $outputlangs= '', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_get_fiche_end($notab=0)
Return tab footer of a card.
dol_banner_tab($object, $paramid, $morehtml= '', $shownav=1, $fieldid= 'rowid', $fieldref= 'ref', $morehtmlref= '', $moreparam= '', $nodbprefix=0, $morehtmlleft= '', $morehtmlstatus= '', $onlybanner=0, $morehtmlright= '')
Show tab footer of a card.
llxFooter()
Empty footer.
Definition: wrapper.php:59