dolibarr  21.0.0-alpha
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  $object = new Adherent($this->db);
65 
66  if (!empty($id)) {
67  $object->fetch($id);
68  }
69 
70  $this->object = $object;
71 
72  return $object;
73  }
74 
75  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
83  public function assign_values(&$action, $id)
84  {
85  // phpcs:enable
86  global $conf, $langs, $user, $canvas;
87  global $form, $formcompany, $objsoc;
88 
89  if ($action == 'add' || $action == 'update') {
90  $this->assign_post();
91  }
92 
93  foreach ($this->object as $key => $value) {
94  $this->tpl[$key] = $value;
95  }
96 
97  $this->tpl['error'] = $this->error;
98  $this->tpl['errors'] = $this->errors;
99 
100  if ($action == 'create' || $action == 'edit') {
101  if ($conf->use_javascript_ajax) {
102  $this->tpl['ajax_selectcountry'] = "\n".'<script type="text/javascript">
103  jQuery(document).ready(function () {
104  jQuery("#selectcountry_id").change(function() {
105  document.formsoc.action.value="'.$action.'";
106  document.formsoc.canvas.value="'.$canvas.'";
107  document.formsoc.submit();
108  });
109  })
110  </script>'."\n";
111  }
112 
113  if (is_object($objsoc) && $objsoc->id > 0) {
114  $this->tpl['company'] = $objsoc->getNomUrl(1);
115  $this->tpl['company_id'] = $objsoc->id;
116  } else {
117  $this->tpl['company'] = $form->select_company($this->object->socid, 'socid', '', 1);
118  }
119 
120  // Civility
121  $this->tpl['select_civility'] = $formcompany->select_civility($this->object->civility_id);
122 
123  // Predefined with third party
124  if ((isset($objsoc->typent_code) && $objsoc->typent_code == 'TE_PRIVATE')) {
125  if (dol_strlen(trim($this->object->address)) == 0) {
126  $this->tpl['address'] = $objsoc->address;
127  }
128  if (dol_strlen(trim($this->object->zip)) == 0) {
129  $this->object->zip = $objsoc->zip;
130  }
131  if (dol_strlen(trim($this->object->town)) == 0) {
132  $this->object->town = $objsoc->town;
133  }
134  if (dol_strlen(trim($this->object->phone_perso)) == 0) {
135  $this->object->phone_perso = $objsoc->phone;
136  }
137  if (dol_strlen(trim($this->object->phone_mobile)) == 0) {
138  $this->object->phone_mobile = $objsoc->phone_mobile;
139  }
140  if (dol_strlen(trim($this->object->email)) == 0) {
141  $this->object->email = $objsoc->email;
142  }
143  }
144 
145  // Zip
146  $this->tpl['select_zip'] = $formcompany->select_ziptown($this->object->zip, 'zipcode', array('town', 'selectcountry_id', 'state_id'), 6);
147 
148  // Town
149  $this->tpl['select_town'] = $formcompany->select_ziptown($this->object->town, 'town', array('zipcode', 'selectcountry_id', 'state_id'));
150 
151  if ($this->object->country_id == 0) {
152  $this->object->country_id = $objsoc->country_id;
153  }
154 
155  // Country
156  $this->tpl['select_country'] = $form->select_country($this->object->country_id, 'country_id');
157  $countrynotdefined = $langs->trans("ErrorSetACountryFirst").' ('.$langs->trans("SeeAbove").')';
158 
159  if ($user->admin) {
160  $this->tpl['info_admin'] = info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
161  }
162 
163  // State
164  if ($this->object->country_id) {
165  $this->tpl['select_state'] = $formcompany->select_state($this->object->state_id, $this->object->country_code);
166  } else {
167  $this->tpl['select_state'] = $countrynotdefined;
168  }
169 
170  // Physical or Moral
171  $selectarray = array('0' => $langs->trans("Physical"), '1' => $langs->trans("Moral"));
172  $this->tpl['select_morphy'] = $form->selectarray('morphy', $selectarray, $this->object->morphy, 0);
173  }
174 
175  if ($action == 'view' || $action == 'edit' || $action == 'delete') {
176  // Emailing
177  if (isModEnabled('mailing')) {
178  $langs->load("mails");
179  $this->tpl['nb_emailing'] = $this->object->getNbOfEMailings();
180  }
181 
182  // Dolibarr user
183  if ($this->object->user_id) {
184  $dolibarr_user = new User($this->db);
185  $result = $dolibarr_user->fetch($this->object->user_id);
186  $this->tpl['dolibarr_user'] = $dolibarr_user->getLoginUrl(1);
187  } else {
188  $this->tpl['dolibarr_user'] = $langs->trans("NoDolibarrAccess");
189  }
190  }
191 
192  if ($action == 'view' || $action == 'delete') {
193  $this->tpl['showrefnav'] = $form->showrefnav($this->object, 'id');
194 
195  if ($this->object->socid > 0) {
196  $objsoc = new Societe($this->db);
197 
198  $objsoc->fetch($this->object->socid);
199  $this->tpl['company'] = $objsoc->getNomUrl(1);
200  } else {
201  $this->tpl['company'] = $langs->trans("AdherentNotLinkedToThirdParty");
202  }
203 
204  $this->tpl['civility'] = $this->object->getCivilityLabel();
205 
206  $this->tpl['address'] = dol_nl2br($this->object->address);
207 
208  $this->tpl['zip'] = ($this->object->zip ? $this->object->zip.'&nbsp;' : '');
209 
210  $img = picto_from_langcode($this->object->country_code);
211  $this->tpl['country'] = ($img ? $img.' ' : '').$this->object->country;
212 
213  $this->tpl['phone_perso'] = dol_print_phone($this->object->phone_perso, $this->object->country_code, 0, $this->object->id, 'AC_TEL');
214  $this->tpl['phone_mobile'] = dol_print_phone($this->object->phone_mobile, $this->object->country_code, 0, $this->object->id, 'AC_TEL');
215  $this->tpl['email'] = dol_print_email($this->object->email, 0, $this->object->id, 'AC_EMAIL');
216 
217  $this->tpl['visibility'] = $this->object->getmorphylib($this->object->morphy);
218 
219  $this->tpl['note'] = $this->object->note_private;
220  }
221 
222  if ($action == 'create_user') {
223  // Full firstname and lastname separated with a dot : firstname.lastname
224  include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
225  require_once DOL_DOCUMENT_ROOT.'/core/lib/security2.lib.php';
226  $login = dol_buildlogin($this->object->lastname, $this->object->firstname);
227 
228  $generated_password = getRandomPassword(false);
229  $password = $generated_password;
230 
231  // Create a form array
232  $formquestion = array(
233  array('label' => $langs->trans("LoginToCreate"), 'type' => 'text', 'name' => 'login', 'value' => $login),
234  array('label' => $langs->trans("Password"), 'type' => 'text', 'name' => 'password', 'value' => $password));
235 
236  $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');
237  }
238  }
239 
240  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
246  private function assign_post()
247  {
248  // phpcs:enable
249  global $langs, $mysoc;
250 
251  $this->object->old_name = GETPOST("old_name");
252  $this->object->old_firstname = GETPOST("old_firstname");
253 
254  $this->object->fk_soc = GETPOSTINT("fk_soc");
255  $this->object->socid = GETPOSTINT("fk_soc");
256  $this->object->lastname = GETPOST("lastname");
257  $this->object->firstname = GETPOST("firstname");
258  $this->object->civility_id = GETPOST("civility_id");
259  $this->object->address = GETPOST("address");
260  $this->object->zip = GETPOST("zipcode");
261  $this->object->town = GETPOST("town");
262  $this->object->country_id = GETPOSTINT("country_id") ? GETPOSTINT("country_id") : $mysoc->country_id;
263  $this->object->state_id = GETPOSTINT("state_id");
264  $this->object->phone_perso = GETPOST("phone_perso");
265  $this->object->phone_mobile = GETPOST("phone_mobile");
266  $this->object->email = GETPOST("email", 'alphawithlgt');
267  $this->object->note_private = GETPOST("note", 'restricthtml');
268  $this->object->canvas = GETPOST("canvas");
269 
270  // We set country_id, and country_code label of the chosen country
271  if ($this->object->country_id) {
272  $sql = "SELECT code, label FROM ".MAIN_DB_PREFIX."c_country WHERE rowid = ".((int) $this->object->country_id);
273  $resql = $this->db->query($sql);
274  if ($resql) {
275  $obj = $this->db->fetch_object($resql);
276 
277  $this->object->country_code = $obj->code;
278  $this->object->country = $langs->trans("Country".$obj->code) ? $langs->trans("Country".$obj->code) : $obj->label;
279  } else {
280  dol_print_error($this->db);
281  }
282  }
283  }
284 }
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:50
if(isModEnabled('invoice') && $user->hasRight('facture', 'lire')) if((isModEnabled('fournisseur') &&!getDolGlobalString('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') && $user->hasRight('tax', 'charges', 'lire')) if(isModEnabled('invoice') &&isModEnabled('order') && $user->hasRight("commande", "lire") &&!getDolGlobalString('WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER')) $sql
Social contributions to pay.
Definition: index.php:751
dol_buildlogin($lastname, $firstname)
Build a login from lastname, firstname.
dol_print_phone($phone, $countrycode='', $cid=0, $socid=0, $addlink='', $separ="&nbsp;", $withpicto='', $titlealt='', $adddivfloat=0, $morecss='')
Format phone numbers according to country.
picto_from_langcode($codelang, $moreatt='', $notitlealt=0)
Return img flag of country for a language code or country code.
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
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.
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 in HTML for admin users or standard users.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
isModEnabled($module)
Is Dolibarr module enabled.
getRandomPassword($generic=false, $replaceambiguouschars=null, $length=32)
Return a generated password using default module.