dolibarr  19.0.0-dev
actions_contactcard_common.class.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2010-2012 Regis Houssin <regis.houssin@inodbox.com>
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program. If not, see <https://www.gnu.org/licenses/>.
16  */
17 
29 {
33  public $db;
34 
35  public $dirmodule;
36  public $targetmodule;
37  public $canvas;
38  public $card;
39 
41  public $tpl = array();
43  public $object;
44 
48  public $error = '';
49 
50 
54  public $errors = array();
55 
56 
63  public function getObject($id)
64  {
65  /*$ret = $this->getInstanceDao();
66 
67  if (is_object($this->object) && method_exists($this->object,'fetch'))
68  {
69  if (!empty($id)) $this->object->fetch($id);
70  }
71  else
72  {*/
73  $object = new Contact($this->db);
74  if (!empty($id)) {
75  $object->fetch($id);
76  }
77 
78  $this->object = $object;
79 
80  return $object;
81  }
82 
83  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
91  public function assign_values(&$action, $id)
92  {
93  // phpcs:enable
94  global $conf, $langs, $user, $canvas;
95  global $form, $formcompany, $objsoc;
96 
97  if ($action == 'add' || $action == 'update') {
98  $this->assign_post();
99  }
100 
101  foreach ($this->object as $key => $value) {
102  $this->tpl[$key] = $value;
103  }
104 
105  $this->tpl['error'] = $this->error;
106  $this->tpl['errors'] = $this->errors;
107 
108  if ($action == 'create' || $action == 'edit') {
109  if ($conf->use_javascript_ajax) {
110  $this->tpl['ajax_selectcountry'] = "\n".'<script type="text/javascript">
111  jQuery(document).ready(function () {
112  jQuery("#selectcountry_id").change(function() {
113  document.formsoc.action.value="'.$action.'";
114  document.formsoc.canvas.value="'.$canvas.'";
115  document.formsoc.submit();
116  });
117  })
118  </script>'."\n";
119  }
120 
121  if (is_object($objsoc) && $objsoc->id > 0) {
122  $this->tpl['company'] = $objsoc->getNomUrl(1);
123  $this->tpl['company_id'] = $objsoc->id;
124  } else {
125  $this->tpl['company'] = $form->select_company($this->object->socid, 'socid', '', 1);
126  }
127 
128  // Civility
129  $this->tpl['select_civility'] = $formcompany->select_civility($this->object->civility_id);
130 
131  // Predefined with third party
132  if ((isset($objsoc->typent_code) && $objsoc->typent_code == 'TE_PRIVATE') || !empty($conf->global->CONTACT_USE_COMPANY_ADDRESS)) {
133  if (dol_strlen(trim($this->object->address)) == 0) {
134  $this->tpl['address'] = $objsoc->address;
135  }
136  if (dol_strlen(trim($this->object->zip)) == 0) {
137  $this->object->zip = $objsoc->zip;
138  }
139  if (dol_strlen(trim($this->object->town)) == 0) {
140  $this->object->town = $objsoc->town;
141  }
142  if (dol_strlen(trim($this->object->phone_pro)) == 0) {
143  $this->object->phone_pro = $objsoc->phone;
144  }
145  if (dol_strlen(trim($this->object->fax)) == 0) {
146  $this->object->fax = $objsoc->fax;
147  }
148  if (dol_strlen(trim($this->object->email)) == 0) {
149  $this->object->email = $objsoc->email;
150  }
151  }
152 
153  // Zip
154  $this->tpl['select_zip'] = $formcompany->select_ziptown($this->object->zip, 'zipcode', array('town', 'selectcountry_id', 'state_id'), 6);
155 
156  // Town
157  $this->tpl['select_town'] = $formcompany->select_ziptown($this->object->town, 'town', array('zipcode', 'selectcountry_id', 'state_id'));
158 
159  if (dol_strlen(trim($this->object->country_id)) == 0) {
160  $this->object->country_id = $objsoc->country_id;
161  }
162 
163  // Country
164  $this->tpl['select_country'] = $form->select_country($this->object->country_id, 'country_id');
165  $countrynotdefined = $langs->trans("ErrorSetACountryFirst").' ('.$langs->trans("SeeAbove").')';
166 
167  if ($user->admin) {
168  $this->tpl['info_admin'] = info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
169  }
170 
171  // State
172  if ($this->object->country_id) {
173  $this->tpl['select_state'] = $formcompany->select_state($this->object->state_id, $this->object->country_code);
174  } else {
175  $this->tpl['select_state'] = $countrynotdefined;
176  }
177 
178  // Public or private
179  $selectarray = array('0'=>$langs->trans("ContactPublic"), '1'=>$langs->trans("ContactPrivate"));
180  $this->tpl['select_visibility'] = $form->selectarray('priv', $selectarray, $this->object->priv, 0);
181  }
182 
183  if ($action == 'view' || $action == 'edit' || $action == 'delete') {
184  // Emailing
185  if (isModEnabled('mailing')) {
186  $langs->load("mails");
187  $this->tpl['nb_emailing'] = $this->object->getNbOfEMailings();
188  }
189 
190  // Linked element
191  $this->tpl['contact_element'] = array();
192  $i = 0;
193 
194  $this->object->load_ref_elements();
195 
196  if (isModEnabled('commande')) {
197  $this->tpl['contact_element'][$i]['linked_element_label'] = $langs->trans("ContactForOrders");
198  $this->tpl['contact_element'][$i]['linked_element_value'] = $this->object->ref_commande ? $this->object->ref_commande : $langs->trans("NoContactForAnyOrder");
199  $i++;
200  }
201  if (isModEnabled("propal")) {
202  $this->tpl['contact_element'][$i]['linked_element_label'] = $langs->trans("ContactForProposals");
203  $this->tpl['contact_element'][$i]['linked_element_value'] = $this->object->ref_propal ? $this->object->ref_propal : $langs->trans("NoContactForAnyProposal");
204  $i++;
205  }
206  if (isModEnabled('contrat')) {
207  $this->tpl['contact_element'][$i]['linked_element_label'] = $langs->trans("ContactForContracts");
208  $this->tpl['contact_element'][$i]['linked_element_value'] = $this->object->ref_contrat ? $this->object->ref_contrat : $langs->trans("NoContactForAnyContract");
209  $i++;
210  }
211  if (isModEnabled('facture')) {
212  $this->tpl['contact_element'][$i]['linked_element_label'] = $langs->trans("ContactForInvoices");
213  $this->tpl['contact_element'][$i]['linked_element_value'] = $this->object->ref_facturation ? $this->object->ref_facturation : $langs->trans("NoContactForAnyInvoice");
214  $i++;
215  }
216 
217  // Dolibarr user
218  if ($this->object->user_id) {
219  $dolibarr_user = new User($this->db);
220  $result = $dolibarr_user->fetch($this->object->user_id);
221  $this->tpl['dolibarr_user'] = $dolibarr_user->getLoginUrl(1);
222  } else {
223  $this->tpl['dolibarr_user'] = $langs->trans("NoDolibarrAccess");
224  }
225  }
226 
227  if ($action == 'view' || $action == 'delete') {
228  $this->tpl['showrefnav'] = $form->showrefnav($this->object, 'id');
229 
230  if ($this->object->socid > 0) {
231  $objsoc = new Societe($this->db);
232 
233  $objsoc->fetch($this->object->socid);
234  $this->tpl['company'] = $objsoc->getNomUrl(1);
235  } else {
236  $this->tpl['company'] = $langs->trans("ContactNotLinkedToCompany");
237  }
238 
239  $this->tpl['civility'] = $this->object->getCivilityLabel();
240 
241  $this->tpl['address'] = dol_nl2br($this->object->address);
242 
243  $this->tpl['zip'] = ($this->object->zip ? $this->object->zip.'&nbsp;' : '');
244 
245  $img = picto_from_langcode($this->object->country_code);
246  $this->tpl['country'] = ($img ? $img.' ' : '').$this->object->country;
247 
248  $this->tpl['phone_pro'] = dol_print_phone($this->object->phone_pro, $this->object->country_code, 0, $this->object->id, 'AC_TEL');
249  $this->tpl['phone_perso'] = dol_print_phone($this->object->phone_perso, $this->object->country_code, 0, $this->object->id, 'AC_TEL');
250  $this->tpl['phone_mobile'] = dol_print_phone($this->object->phone_mobile, $this->object->country_code, 0, $this->object->id, 'AC_TEL');
251  $this->tpl['fax'] = dol_print_phone($this->object->fax, $this->object->country_code, 0, $this->object->id, 'AC_FAX');
252  $this->tpl['email'] = dol_print_email($this->object->email, 0, $this->object->id, 'AC_EMAIL');
253 
254  $this->tpl['visibility'] = $this->object->LibPubPriv($this->object->priv);
255 
256  $this->tpl['note'] = $this->object->note_private;
257  }
258 
259  if ($action == 'create_user') {
260  // Full firstname and lastname separated with a dot : firstname.lastname
261  include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
262  require_once DOL_DOCUMENT_ROOT.'/core/lib/security2.lib.php';
263  $login = dol_buildlogin($this->object->lastname, $this->object->firstname);
264 
265  $generated_password = getRandomPassword(false);
266  $password = $generated_password;
267 
268  // Create a form array
269  $formquestion = array(
270  array('label' => $langs->trans("LoginToCreate"), 'type' => 'text', 'name' => 'login', 'value' => $login),
271  array('label' => $langs->trans("Password"), 'type' => 'text', 'name' => 'password', 'value' => $password));
272 
273  $this->tpl['action_create_user'] = $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$this->object->id, $langs->trans("CreateDolibarrLogin"), $langs->trans("ConfirmCreateContact"), "confirm_create_user", $formquestion, 'no');
274  }
275  }
276 
277  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
283  private function assign_post()
284  {
285  // phpcs:enable
286  global $langs, $mysoc;
287 
288  $this->object->socid = GETPOST("socid", 'int');
289  $this->object->lastname = GETPOST("name");
290  $this->object->firstname = GETPOST("firstname");
291  $this->object->civility_id = GETPOST("civility_id");
292  $this->object->poste = GETPOST("poste");
293  $this->object->address = GETPOST("address");
294  $this->object->zip = GETPOST("zipcode");
295  $this->object->town = GETPOST("town");
296  $this->object->country_id = GETPOST("country_id") ? GETPOST("country_id") : $mysoc->country_id;
297  $this->object->state_id = GETPOST("state_id");
298  $this->object->phone_pro = GETPOST("phone_pro");
299  $this->object->phone_perso = GETPOST("phone_perso");
300  $this->object->phone_mobile = GETPOST("phone_mobile");
301  $this->object->fax = GETPOST("fax");
302  $this->object->email = GETPOST("email");
303  $this->object->priv = GETPOST("priv");
304  $this->object->note = GETPOST("note", "restricthtml");
305  $this->object->canvas = GETPOST("canvas");
306 
307  // We set country_id, and country_code label of the chosen country
308  if ($this->object->country_id) {
309  $sql = "SELECT code, label FROM ".MAIN_DB_PREFIX."c_country WHERE rowid = ".((int) $this->object->country_id);
310  $resql = $this->db->query($sql);
311  if ($resql) {
312  $obj = $this->db->fetch_object($resql);
313  } else {
314  dol_print_error($this->db);
315  }
316  $this->object->country_id = $langs->trans("Country".$obj->code) ? $langs->trans("Country".$obj->code) : $obj->label;
317  $this->object->country_code = $obj->code;
318  $this->object->country = $langs->trans("Country".$obj->code) ? $langs->trans("Country".$obj->code) : $obj->label;
319  }
320  }
321 }
Classe permettant la gestion des contacts par defaut.
assign_post()
Assign POST values into object.
assign_values(&$action, $id)
Set content of ->tpl array, to use into template.
Class to manage contact/addresses.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage Dolibarr users.
Definition: user.class.php:48
if(isModEnabled('facture') && $user->hasRight('facture', 'lire')) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') && $user->hasRight('don', 'lire')) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $sql
Social contributions to pay.
Definition: index.php:746
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:143
dol_buildlogin($lastname, $firstname)
Build a login from lastname, firstname.
picto_from_langcode($codelang, $moreatt='', $notitlealt=0)
Return img flag of country for a language code or country code.
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_nl2br($stringtoencode, $nl2brmode=0, $forxml=false)
Replace CRLF in string with a HTML BR tag.
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
dol_print_email($email, $cid=0, $socid=0, $addlink=0, $max=64, $showinvalid=1, $withpicto=0)
Show EMail link formatted for HTML output.
dol_print_phone($phone, $countrycode='', $cid=0, $socid=0, $addlink='', $separ="&nbsp;", $withpicto='', $titlealt='', $adddivfloat=0)
Format phone numbers according to country.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin='1', $morecss='hideonsmartphone', $textfordropdown='')
Show information for admin users or standard users.
isModEnabled($module)
Is Dolibarr module enabled.
getRandomPassword($generic=false, $replaceambiguouschars=null, $length=32)
Return a generated password using default module.