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