dolibarr  16.0.1
contact.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2005 Patrick Rouillon <patrick@rouillon.net>
3  * Copyright (C) 2005-2016 Destailleur Laurent <eldy@users.sourceforge.net>
4  * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
5  * Copyright (C) 2011-2015 Philippe Grand <philippe.grand@atoo-net.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  */
20 
27 require '../../main.inc.php';
28 require_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php';
29 require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
30 require_once DOL_DOCUMENT_ROOT.'/core/lib/propal.lib.php';
31 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
32 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
33 require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
34 
35 // Load translation files required by the page
36 $langs->loadLangs(array('facture', 'propal', 'orders', 'sendings', 'companies'));
37 
38 $id = GETPOST('id', 'int');
39 $ref = GETPOST('ref', 'alpha');
40 $lineid = GETPOST('lineid', 'int');
41 $action = GETPOST('action', 'aZ09');
42 
43 $object = new Propal($db);
44 
45 // Load object
46 if ($id > 0 || !empty($ref)) {
47  $ret = $object->fetch($id, $ref);
48  if ($ret == 0) {
49  $langs->load("errors");
50  setEventMessages($langs->trans('ErrorRecordNotFound'), null, 'errors');
51  $error++;
52  } elseif ($ret < 0) {
53  setEventMessages($object->error, $object->errors, 'errors');
54  $error++;
55  }
56 }
57 if (!$error) {
58  $object->fetch_thirdparty();
59 } else {
60  header('Location: '.DOL_URL_ROOT.'/comm/propal/list.php');
61  exit;
62 }
63 
64 // Security check
65 if (!empty($user->socid)) {
66  $socid = $user->socid;
67  $object->id = $user->socid;
68 }
69 restrictedArea($user, 'propal', $object->id);
70 
71 
72 /*
73  * Add a new contact
74  */
75 
76 if ($action == 'addcontact' && $user->rights->propale->creer) {
77  if ($object->id > 0) {
78  $contactid = (GETPOST('userid', 'int') ? GETPOST('userid', 'int') : GETPOST('contactid', 'int'));
79  $typeid = (GETPOST('typecontact') ? GETPOST('typecontact') : GETPOST('type'));
80  $result = $object->add_contact($contactid, $typeid, GETPOST("source", 'aZ09'));
81  }
82 
83  if ($result >= 0) {
84  header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
85  exit;
86  } else {
87  if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
88  $langs->load("errors");
89  setEventMessages($langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType"), null, 'errors');
90  } else {
91  setEventMessages($object->error, $object->errors, 'errors');
92  }
93  }
94 } elseif ($action == 'swapstatut' && $user->rights->propale->creer) {
95  // Toggle the status of a contact
96  if ($object->id > 0) {
97  $result = $object->swapContactStatus(GETPOST('ligne', 'int'));
98  }
99 } elseif ($action == 'deletecontact' && $user->rights->propale->creer) {
100  // Deletes a contact
101  $result = $object->delete_contact($lineid);
102 
103  if ($result >= 0) {
104  header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
105  exit;
106  } else {
107  dol_print_error($db);
108  }
109 }
110 
111 
112 /*
113  * View
114  */
115 $title = $langs->trans('Proposal')." - ".$langs->trans('ContactsAddresses');
116 $help_url = "EN:Commercial_Proposals|FR:Proposition_commerciale|ES:Presupuestos";
117 llxHeader('', $title, $help_url);
118 
119 $form = new Form($db);
120 $formcompany = new FormCompany($db);
121 $formother = new FormOther($db);
122 
123 if ($object->id > 0) {
124  $head = propal_prepare_head($object);
125  print dol_get_fiche_head($head, 'contact', $langs->trans("Proposal"), -1, 'propal');
126 
127 
128  // Proposal card
129 
130  $linkback = '<a href="'.DOL_URL_ROOT.'/comm/propal/list.php?restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
131 
132 
133  $morehtmlref = '<div class="refidno">';
134  // Ref customer
135  $morehtmlref .= $form->editfieldkey("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', 0, 1);
136  $morehtmlref .= $form->editfieldval("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', null, null, '', 1);
137  // Thirdparty
138  $morehtmlref .= '<br>'.$langs->trans('ThirdParty').' : '.$object->thirdparty->getNomUrl(1, 'customer');
139  // Project
140  if (!empty($conf->project->enabled)) {
141  $langs->load("projects");
142  $morehtmlref .= '<br>'.$langs->trans('Project').' ';
143  if ($user->rights->propal->creer) {
144  if ($action != 'classify') {
145  //$morehtmlref.='<a class="editfielda" href="' . $_SERVER['PHP_SELF'] . '?action=classify&token='.newToken().'&id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetProject')) . '</a>';
146  $morehtmlref .= ' : ';
147  }
148  if ($action == 'classify') {
149  //$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1);
150  $morehtmlref .= '<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
151  $morehtmlref .= '<input type="hidden" name="action" value="classin">';
152  $morehtmlref .= '<input type="hidden" name="token" value="'.newToken().'">';
153  $morehtmlref .= $formproject->select_projects($object->socid, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1);
154  $morehtmlref .= '<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
155  $morehtmlref .= '</form>';
156  } else {
157  $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1);
158  }
159  } else {
160  if (!empty($object->fk_project)) {
161  $proj = new Project($db);
162  $proj->fetch($object->fk_project);
163  $morehtmlref .= ' : '.$proj->getNomUrl(1);
164  if ($proj->title) {
165  $morehtmlref .= ' - '.$proj->title;
166  }
167  } else {
168  $morehtmlref .= '';
169  }
170  }
171  }
172  $morehtmlref .= '</div>';
173 
174  dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref, '', 0, '', '', 1);
175 
176  print dol_get_fiche_end();
177 
178 
179  // Contacts lines (modules that overwrite templates must declare this into descriptor)
180  $dirtpls = array_merge($conf->modules_parts['tpl'], array('/core/tpl'));
181  foreach ($dirtpls as $reldir) {
182  $res = @include dol_buildpath($reldir.'/contacts.tpl.php');
183  if ($res) {
184  break;
185  }
186  }
187 }
188 
189 // End of page
190 llxFooter();
191 $db->close();
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
if($cancel &&!$id) if($action== 'add'&&!$cancel) if($action== 'delete') if($id) $form
Actions.
Definition: card.php:142
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOCSRFCHECK')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
Definition: wrapper.php:59
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
if(GETPOST('button_removefilter_x', 'alpha')||GETPOST('button_removefilter.x', 'alpha')||GETPOST('button_removefilter', 'alpha')) if(GETPOST('button_search_x', 'alpha')||GETPOST('button_search.x', 'alpha')||GETPOST('button_search', 'alpha')) if($action=="save"&&empty($cancel)) $help_url
View.
Definition: agenda.php:116
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.
Classe permettant la generation de composants html autre Only common components are here...
restrictedArea($user, $features, $objectid=0, $tableandshare= '', $feature2= '', $dbt_keyfield= 'fk_soc', $dbt_select= 'rowid', $isdraft=0, $mode=0)
Check permissions of a user to show a page and an object.
propal_prepare_head($object)
Prepare array with list of tabs.
Definition: propal.lib.php:32
dol_get_fiche_head($links=array(), $active= '', $title= '', $notab=0, $picto= '', $pictoisfullpath=0, $morehtmlright= '', $morecss= '', $limittoshow=0, $moretabssuffix= '')
Show tabs of a record.
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:73
Class to manage proposals.