dolibarr  17.0.4
actions_adherentcard_common.class.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2010-2012 Regis Houssin <regis.houssin@inodbox.com>
3  * Copyright (C) 2012 Philippe Grand <philippe.grand@atoo-net.com>
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 
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 
53  public $errors = array();
54 
55 
62  public function getObject($id)
63  {
64  //$ret = $this->getInstanceDao();
65 
66  /*if (is_object($this->object) && method_exists($this->object,'fetch'))
67  {
68  if (!empty($id)) $this->object->fetch($id);
69  }
70  else
71  {*/
72  $object = new Adherent($this->db);
73  if (!empty($id)) {
74  $object->fetch($id);
75  }
76  $this->object = $object;
77  //}
78  }
79 
80  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
88  public function assign_values(&$action, $id)
89  {
90  // phpcs:enable
91  global $conf, $langs, $user, $canvas;
92  global $form, $formcompany, $objsoc;
93 
94  if ($action == 'add' || $action == 'update') {
95  $this->assign_post();
96  }
97 
98  foreach ($this->object as $key => $value) {
99  $this->tpl[$key] = $value;
100  }
101 
102  $this->tpl['error'] = $this->error;
103  $this->tpl['errors'] = $this->errors;
104 
105  if ($action == 'create' || $action == 'edit') {
106  if ($conf->use_javascript_ajax) {
107  $this->tpl['ajax_selectcountry'] = "\n".'<script type="text/javascript">
108  jQuery(document).ready(function () {
109  jQuery("#selectcountry_id").change(function() {
110  document.formsoc.action.value="'.$action.'";
111  document.formsoc.canvas.value="'.$canvas.'";
112  document.formsoc.submit();
113  });
114  })
115  </script>'."\n";
116  }
117 
118  if (is_object($objsoc) && $objsoc->id > 0) {
119  $this->tpl['company'] = $objsoc->getNomUrl(1);
120  $this->tpl['company_id'] = $objsoc->id;
121  } else {
122  $this->tpl['company'] = $form->select_company($this->object->socid, 'socid', '', 1);
123  }
124 
125  // Civility
126  $this->tpl['select_civility'] = $formcompany->select_civility($this->object->civility_id);
127 
128  // Predefined with third party
129  if ((isset($objsoc->typent_code) && $objsoc->typent_code == 'TE_PRIVATE')) {
130  if (dol_strlen(trim($this->object->address)) == 0) {
131  $this->tpl['address'] = $objsoc->address;
132  }
133  if (dol_strlen(trim($this->object->zip)) == 0) {
134  $this->object->zip = $objsoc->zip;
135  }
136  if (dol_strlen(trim($this->object->town)) == 0) {
137  $this->object->town = $objsoc->town;
138  }
139  if (dol_strlen(trim($this->object->phone_perso)) == 0) {
140  $this->object->phone_perso = $objsoc->phone;
141  }
142  if (dol_strlen(trim($this->object->phone_mobile)) == 0) {
143  $this->object->phone_mobile = $objsoc->phone_mobile;
144  }
145  if (dol_strlen(trim($this->object->email)) == 0) {
146  $this->object->email = $objsoc->email;
147  }
148  }
149 
150  // Zip
151  $this->tpl['select_zip'] = $formcompany->select_ziptown($this->object->zip, 'zipcode', array('town', 'selectcountry_id', 'state_id'), 6);
152 
153  // Town
154  $this->tpl['select_town'] = $formcompany->select_ziptown($this->object->town, 'town', array('zipcode', 'selectcountry_id', 'state_id'));
155 
156  if (dol_strlen(trim($this->object->country_id)) == 0) {
157  $this->object->country_id = $objsoc->country_id;
158  }
159 
160  // Country
161  $this->tpl['select_country'] = $form->select_country($this->object->country_id, 'country_id');
162  $countrynotdefined = $langs->trans("ErrorSetACountryFirst").' ('.$langs->trans("SeeAbove").')';
163 
164  if ($user->admin) {
165  $this->tpl['info_admin'] = info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
166  }
167 
168  // State
169  if ($this->object->country_id) {
170  $this->tpl['select_state'] = $formcompany->select_state($this->object->state_id, $this->object->country_code);
171  } else {
172  $this->tpl['select_state'] = $countrynotdefined;
173  }
174 
175  // Physical or Moral
176  $selectarray = array('0'=>$langs->trans("Physical"), '1'=>$langs->trans("Moral"));
177  $this->tpl['select_morphy'] = $form->selectarray('morphy', $selectarray, $this->object->morphy, 0);
178  }
179 
180  if ($action == 'view' || $action == 'edit' || $action == 'delete') {
181  // Emailing
182  if (isModEnabled('mailing')) {
183  $langs->load("mails");
184  $this->tpl['nb_emailing'] = $this->object->getNbOfEMailings();
185  }
186 
187  // Dolibarr user
188  if ($this->object->user_id) {
189  $dolibarr_user = new User($this->db);
190  $result = $dolibarr_user->fetch($this->object->user_id);
191  $this->tpl['dolibarr_user'] = $dolibarr_user->getLoginUrl(1);
192  } else {
193  $this->tpl['dolibarr_user'] = $langs->trans("NoDolibarrAccess");
194  }
195  }
196 
197  if ($action == 'view' || $action == 'delete') {
198  $this->tpl['showrefnav'] = $form->showrefnav($this->object, 'id');
199 
200  if ($this->object->socid > 0) {
201  $objsoc = new Societe($this->db);
202 
203  $objsoc->fetch($this->object->socid);
204  $this->tpl['company'] = $objsoc->getNomUrl(1);
205  } else {
206  $this->tpl['company'] = $langs->trans("AdherentNotLinkedToThirdParty");
207  }
208 
209  $this->tpl['civility'] = $this->object->getCivilityLabel();
210 
211  $this->tpl['address'] = dol_nl2br($this->object->address);
212 
213  $this->tpl['zip'] = ($this->object->zip ? $this->object->zip.'&nbsp;' : '');
214 
215  $img = picto_from_langcode($this->object->country_code);
216  $this->tpl['country'] = ($img ? $img.' ' : '').$this->object->country;
217 
218  $this->tpl['phone_perso'] = dol_print_phone($this->object->phone_perso, $this->object->country_code, 0, $this->object->id, 'AC_TEL');
219  $this->tpl['phone_mobile'] = dol_print_phone($this->object->phone_mobile, $this->object->country_code, 0, $this->object->id, 'AC_TEL');
220  $this->tpl['email'] = dol_print_email($this->object->email, 0, $this->object->id, 'AC_EMAIL');
221 
222  $this->tpl['visibility'] = $this->object->getmorphylib($this->object->morphy);
223 
224  $this->tpl['note'] = nl2br($this->object->note);
225  }
226 
227  if ($action == 'create_user') {
228  // Full firstname and lastname separated with a dot : firstname.lastname
229  include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
230  require_once DOL_DOCUMENT_ROOT.'/core/lib/security2.lib.php';
231  $login = dol_buildlogin($this->object->lastname, $this->object->firstname);
232 
233  $generated_password = getRandomPassword(false);
234  $password = $generated_password;
235 
236  // Create a form array
237  $formquestion = array(
238  array('label' => $langs->trans("LoginToCreate"), 'type' => 'text', 'name' => 'login', 'value' => $login),
239  array('label' => $langs->trans("Password"), 'type' => 'text', 'name' => 'password', 'value' => $password));
240 
241  $this->tpl['action_create_user'] = $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$this->object->id, $langs->trans("CreateDolibarrLogin"), $langs->trans("ConfirmCreateAdherent"), "confirm_create_user", $formquestion, 'no');
242  }
243  }
244 
245  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
251  private function assign_post()
252  {
253  // phpcs:enable
254  global $langs, $mysoc;
255 
256  $this->object->old_name = GETPOST("old_name");
257  $this->object->old_firstname = GETPOST("old_firstname");
258 
259  $this->object->fk_soc = GETPOST("fk_soc");
260  $this->object->lastname = GETPOST("lastname");
261  $this->object->firstname = GETPOST("firstname");
262  $this->object->civility_id = GETPOST("civility_id");
263  $this->object->address = GETPOST("address");
264  $this->object->zip = GETPOST("zipcode");
265  $this->object->town = GETPOST("town");
266  $this->object->country_id = GETPOST("country_id", 'int') ? GETPOST("country_id", 'int') : $mysoc->country_id;
267  $this->object->state_id = GETPOST("state_id", 'int');
268  $this->object->phone_perso = GETPOST("phone_perso");
269  $this->object->phone_mobile = GETPOST("phone_mobile");
270  $this->object->email = GETPOST("email", 'alphawithlgt');
271  $this->object->note = GETPOST("note", 'restricthtml');
272  $this->object->canvas = GETPOST("canvas");
273 
274  // We set country_id, and country_code label of the chosen country
275  if ($this->object->country_id) {
276  $sql = "SELECT code, label FROM ".MAIN_DB_PREFIX."c_country WHERE rowid = ".((int) $this->object->country_id);
277  $resql = $this->db->query($sql);
278  if ($resql) {
279  $obj = $this->db->fetch_object($resql);
280 
281  $this->object->country_code = $obj->code;
282  $this->object->country = $langs->trans("Country".$obj->code) ? $langs->trans("Country".$obj->code) : $obj->libelle;
283  } else {
284  dol_print_error($this->db);
285  }
286  }
287  }
288 }
Class to manage members using default canvas.
assign_post()
Assign POST values into object.
assign_values(&$action, $id)
Set content of ->tpl array, to use into template.
Class to manage members of a foundation.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage Dolibarr users.
Definition: user.class.php:47
if(isModEnabled('facture') &&!empty($user->rights->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') &&!empty($user->rights->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)) $resql
Social contributions to pay.
Definition: index.php:745
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.
$conf db
API class for accounts.
Definition: inc.php:41