dolibarr  9.0.0
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 <http://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', 'orders', 'sendings', 'companies'));
37 
38 $id=GETPOST('id','int');
39 $ref= GETPOST('ref','alpha');
40 $lineid=GETPOST('lineid','int');
41 $action=GETPOST('action','alpha');
42 
43 // Security check
44 if ($user->societe_id) $socid=$user->societe_id;
45 $result = restrictedArea($user, 'propal', $id);
46 
47 $object = new Propal($db);
48 
49 // Load object
50 if ($id > 0 || ! empty($ref))
51 {
52  $ret=$object->fetch($id, $ref);
53  if ($ret == 0)
54  {
55  $langs->load("errors");
56  setEventMessages($langs->trans('ErrorRecordNotFound'), null, 'errors');
57  $error++;
58  }
59  else if ($ret < 0)
60  {
61  setEventMessages($object->error, $object->errors, 'errors');
62  $error++;
63  }
64 }
65 if (! $error)
66 {
67  $object->fetch_thirdparty();
68 }
69 else
70 {
71  header('Location: '.DOL_URL_ROOT.'/comm/propal/list.php');
72  exit;
73 }
74 
75 
76 /*
77  * Add a new contact
78  */
79 
80 if ($action == 'addcontact' && $user->rights->propale->creer)
81 {
82  if ($object->id > 0)
83  {
84  $contactid = (GETPOST('userid','int') ? GETPOST('userid','int') : GETPOST('contactid','int'));
85  $result = $object->add_contact($contactid, $_POST["type"], $_POST["source"]);
86  }
87 
88  if ($result >= 0)
89  {
90  header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
91  exit;
92  }
93  else
94  {
95  if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS')
96  {
97  $langs->load("errors");
98  setEventMessages($langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType"), null, 'errors');
99  }
100  else
101  {
102  setEventMessages($object->error, $object->errors, 'errors');
103  }
104  }
105 }
106 
107 // Toggle the status of a contact
108 else if ($action == 'swapstatut' && $user->rights->propale->creer)
109 {
110  if ($object->id > 0)
111  {
112  $result=$object->swapContactStatus(GETPOST('ligne'));
113  }
114 }
115 
116 // Deletes a contact
117 else if ($action == 'deletecontact' && $user->rights->propale->creer)
118 {
119  $result = $object->delete_contact($lineid);
120 
121  if ($result >= 0)
122  {
123  header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
124  exit;
125  }
126  else
127  {
128  dol_print_error($db);
129  }
130 }
131 /*
132 else if ($action == 'setaddress' && $user->rights->propale->creer)
133 {
134  $result=$object->setDeliveryAddress($_POST['fk_address']);
135  if ($result < 0) dol_print_error($db,$object->error);
136 }*/
137 
138 
139 /*
140  * View
141  */
142 
143 llxHeader('',$langs->trans('Proposal'),'EN:Commercial_Proposals|FR:Proposition_commerciale|ES:Presupuestos');
144 
145 $form = new Form($db);
146 $formcompany= new FormCompany($db);
147 $formother = new FormOther($db);
148 
149 if ($object->id > 0)
150 {
151  $head = propal_prepare_head($object);
152  dol_fiche_head($head, 'contact', $langs->trans("Proposal"), -1, 'propal');
153 
154 
155  // Proposal card
156 
157  $linkback = '<a href="' . DOL_URL_ROOT . '/comm/propal/list.php?restore_lastsearch_values=1' . (! empty($socid) ? '&socid=' . $socid : '') . '">' . $langs->trans("BackToList") . '</a>';
158 
159 
160  $morehtmlref='<div class="refidno">';
161  // Ref customer
162  $morehtmlref.=$form->editfieldkey("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', 0, 1);
163  $morehtmlref.=$form->editfieldval("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', null, null, '', 1);
164  // Thirdparty
165  $morehtmlref.='<br>'.$langs->trans('ThirdParty') . ' : ' . $object->thirdparty->getNomUrl(1,'customer');
166  // Project
167  if (! empty($conf->projet->enabled))
168  {
169  $langs->load("projects");
170  $morehtmlref.='<br>'.$langs->trans('Project') . ' ';
171  if ($user->rights->propal->creer)
172  {
173  if ($action != 'classify')
174  //$morehtmlref.='<a href="' . $_SERVER['PHP_SELF'] . '?action=classify&amp;id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetProject')) . '</a>';
175  $morehtmlref.=' : ';
176  if ($action == 'classify') {
177  //$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1);
178  $morehtmlref.='<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
179  $morehtmlref.='<input type="hidden" name="action" value="classin">';
180  $morehtmlref.='<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
181  $morehtmlref.=$formproject->select_projects($object->socid, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1);
182  $morehtmlref.='<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
183  $morehtmlref.='</form>';
184  } else {
185  $morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1);
186  }
187  } else {
188  if (! empty($object->fk_project)) {
189  $proj = new Project($db);
190  $proj->fetch($object->fk_project);
191  $morehtmlref.='<a href="'.DOL_URL_ROOT.'/projet/card.php?id=' . $object->fk_project . '" title="' . $langs->trans('ShowProject') . '">';
192  $morehtmlref.=$proj->ref;
193  $morehtmlref.='</a>';
194  } else {
195  $morehtmlref.='';
196  }
197  }
198  }
199  $morehtmlref.='</div>';
200 
201  dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref, '', 0, '', '', 1);
202 
203  dol_fiche_end();
204 
205 
206  // Contacts lines (modules that overwrite templates must declare this into descriptor)
207  $dirtpls=array_merge($conf->modules_parts['tpl'],array('/core/tpl'));
208  foreach($dirtpls as $reldir)
209  {
210  $res=@include dol_buildpath($reldir.'/contacts.tpl.php');
211  if ($res) break;
212  }
213 }
214 
215 // End of page
216 llxFooter();
217 $db->close();
llxFooter()
Empty footer.
Definition: wrapper.php:56
GETPOST($paramname, $check='none', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
setEventMessages($mesg, $mesgs, $style='mesgs')
Set event messages in dol_events session object.
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.
dol_print_error($db='', $error='', $errors=null)
Affiche message erreur system avec toutes les informations pour faciliter le diagnostic et la remonte...
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
Class to build HTML component for third parties management Only common components are here...
Class to manage generation of HTML components Only common components must be here.
Class to manage projects.
dol_fiche_end($notab=0)
Show tab footer of a card.
Classe permettant la generation de composants html autre Only common components are here...
llxHeader()
Empty header.
Definition: wrapper.php:44
propal_prepare_head($object)
Prepare array with list of tabs.
Definition: propal.lib.php:32
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.
dol_fiche_head($links=array(), $active='0', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='')
Show tab header of a card.
Class to manage proposals.