dolibarr  9.0.0
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 <http://www.gnu.org/licenses/>.
17  */
18 
29 {
33  public $db;
34 
35  var $dirmodule;
36  var $targetmodule;
37  var $canvas;
38  var $card;
39 
41  var $tpl = array();
43  var $object;
44 
48  public $error='';
49 
53  public $errors = array();
54 
55 
62  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)) $object->fetch($id);
74  $this->object = $object;
75  //}
76  }
77 
78  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
86  function assign_values(&$action, $id)
87  {
88  // phpcs:enable
89  global $conf, $langs, $user, $canvas;
90  global $form, $formcompany, $objsoc;
91 
92  if ($action == 'add' || $action == 'update') $this->assign_post();
93 
94  foreach($this->object as $key => $value)
95  {
96  $this->tpl[$key] = $value;
97  }
98 
99  $this->tpl['error']=$this->error;
100  $this->tpl['errors']=$this->errors;
101 
102  if ($action == 'create' || $action == 'edit')
103  {
104  if ($conf->use_javascript_ajax)
105  {
106  $this->tpl['ajax_selectcountry'] = "\n".'<script type="text/javascript" language="javascript">
107  jQuery(document).ready(function () {
108  jQuery("#selectcountry_id").change(function() {
109  document.formsoc.action.value="'.$action.'";
110  document.formsoc.canvas.value="'.$canvas.'";
111  document.formsoc.submit();
112  });
113  })
114  </script>'."\n";
115  }
116 
117  if (is_object($objsoc) && $objsoc->id > 0)
118  {
119  $this->tpl['company'] = $objsoc->getNomUrl(1);
120  $this->tpl['company_id'] = $objsoc->id;
121  }
122  else
123  {
124  $this->tpl['company'] = $form->select_company($this->object->socid,'socid','',1);
125  }
126 
127  // Civility
128  $this->tpl['select_civility'] = $formcompany->select_civility($this->object->civility_id);
129 
130  // Predefined with third party
131  if ((isset($objsoc->typent_code) && $objsoc->typent_code == 'TE_PRIVATE'))
132  {
133  if (dol_strlen(trim($this->object->address)) == 0) $this->tpl['address'] = $objsoc->address;
134  if (dol_strlen(trim($this->object->zip)) == 0) $this->object->zip = $objsoc->zip;
135  if (dol_strlen(trim($this->object->town)) == 0) $this->object->town = $objsoc->town;
136  if (dol_strlen(trim($this->object->phone_perso)) == 0) $this->object->phone_perso = $objsoc->phone;
137  if (dol_strlen(trim($this->object->phone_mobile)) == 0) $this->object->phone_mobile = $objsoc->phone_mobile;
138  if (dol_strlen(trim($this->object->email)) == 0) $this->object->email = $objsoc->email;
139  }
140 
141  // Zip
142  $this->tpl['select_zip'] = $formcompany->select_ziptown($this->object->zip,'zipcode',array('town','selectcountry_id','state_id'),6);
143 
144  // Town
145  $this->tpl['select_town'] = $formcompany->select_ziptown($this->object->town,'town',array('zipcode','selectcountry_id','state_id'));
146 
147  if (dol_strlen(trim($this->object->country_id)) == 0) $this->object->country_id = $objsoc->country_id;
148 
149  // Country
150  $this->tpl['select_country'] = $form->select_country($this->object->country_id,'country_id');
151  $countrynotdefined = $langs->trans("ErrorSetACountryFirst").' ('.$langs->trans("SeeAbove").')';
152 
153  if ($user->admin) $this->tpl['info_admin'] = info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1);
154 
155  // State
156  if ($this->object->country_id) $this->tpl['select_state'] = $formcompany->select_state($this->object->state_id,$this->object->country_code);
157  else $this->tpl['select_state'] = $countrynotdefined;
158 
159  // Physical or Moral
160  $selectarray=array('0'=>$langs->trans("Physical"),'1'=>$langs->trans("Moral"));
161  $this->tpl['select_morphy'] = $form->selectarray('morphy',$selectarray,$this->object->morphy,0);
162  }
163 
164  if ($action == 'view' || $action == 'edit' || $action == 'delete')
165  {
166  // Emailing
167  if (! empty($conf->mailing->enabled))
168  {
169  $langs->load("mails");
170  $this->tpl['nb_emailing'] = $this->object->getNbOfEMailings();
171  }
172 
173 
174  // Dolibarr user
175  if ($this->object->user_id)
176  {
177  $dolibarr_user=new User($this->db);
178  $result=$dolibarr_user->fetch($this->object->user_id);
179  $this->tpl['dolibarr_user'] = $dolibarr_user->getLoginUrl(1);
180  }
181  else $this->tpl['dolibarr_user'] = $langs->trans("NoDolibarrAccess");
182  }
183 
184  if ($action == 'view' || $action == 'delete')
185  {
186  $this->tpl['showrefnav'] = $form->showrefnav($this->object,'id');
187 
188  if ($this->object->socid > 0)
189  {
190  $objsoc = new Societe($this->db);
191 
192  $objsoc->fetch($this->object->socid);
193  $this->tpl['company'] = $objsoc->getNomUrl(1);
194  }
195  else
196  {
197  $this->tpl['company'] = $langs->trans("AdherentNotLinkedToThirdParty");
198  }
199 
200  $this->tpl['civility'] = $this->object->getCivilityLabel();
201 
202  $this->tpl['address'] = dol_nl2br($this->object->address);
203 
204  $this->tpl['zip'] = ($this->object->zip?$this->object->zip.'&nbsp;':'');
205 
206  $img=picto_from_langcode($this->object->country_code);
207  $this->tpl['country'] = ($img?$img.' ':'').$this->object->country;
208 
209  $this->tpl['phone_perso'] = dol_print_phone($this->object->phone_perso,$this->object->country_code,0,$this->object->id,'AC_TEL');
210  $this->tpl['phone_mobile'] = dol_print_phone($this->object->phone_mobile,$this->object->country_code,0,$this->object->id,'AC_TEL');
211  $this->tpl['email'] = dol_print_email($this->object->email,0,$this->object->id,'AC_EMAIL');
212 
213  $this->tpl['visibility'] = $this->object->getmorphylib($this->object->morphy);
214 
215  $this->tpl['note'] = nl2br($this->object->note);
216  }
217 
218  if ($action == 'create_user')
219  {
220  // Full firstname and lastname separated with a dot : firstname.lastname
221  include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
222  require_once DOL_DOCUMENT_ROOT.'/core/lib/security2.lib.php';
223  $login=dol_buildlogin($this->object->lastname, $this->object->firstname);
224 
225  $generated_password=getRandomPassword(false);
226  $password=$generated_password;
227 
228  // Create a form array
229  $formquestion=array(
230  array('label' => $langs->trans("LoginToCreate"), 'type' => 'text', 'name' => 'login', 'value' => $login),
231  array('label' => $langs->trans("Password"), 'type' => 'text', 'name' => 'password', 'value' => $password));
232 
233  $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');
234  }
235  }
236 
237  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
243  private function assign_post()
244  {
245  // phpcs:enable
246  global $langs, $mysoc;
247 
248  $this->object->old_name = $_POST["old_name"];
249  $this->object->old_firstname = $_POST["old_firstname"];
250 
251  $this->object->fk_soc = $_POST["fk_soc"];
252  $this->object->lastname = $_POST["lastname"];
253  $this->object->firstname = $_POST["firstname"];
254  $this->object->civility_id = $_POST["civility_id"];
255  $this->object->address = $_POST["address"];
256  $this->object->zip = $_POST["zipcode"];
257  $this->object->town = $_POST["town"];
258  $this->object->country_id = $_POST["country_id"]?$_POST["country_id"]:$mysoc->country_id;
259  $this->object->state_id = $_POST["state_id"];
260  $this->object->phone_perso = $_POST["phone_perso"];
261  $this->object->phone_mobile = $_POST["phone_mobile"];
262  $this->object->email = $_POST["email"];
263  $this->object->note = $_POST["note"];
264  $this->object->canvas = $_POST["canvas"];
265 
266  // We set country_id, and country_code label of the chosen country
267  if ($this->object->country_id)
268  {
269  $sql = "SELECT code, label FROM ".MAIN_DB_PREFIX."c_country WHERE rowid = ".$this->object->country_id;
270  $resql=$this->db->query($sql);
271  if ($resql)
272  {
273  $obj = $this->db->fetch_object($resql);
274 
275  $this->object->country_code = $obj->code;
276  $this->object->country = $langs->trans("Country".$obj->code)?$langs->trans("Country".$obj->code):$obj->libelle;
277  }
278  else
279  {
280  dol_print_error($this->db);
281  }
282  }
283  }
284 }
if(! empty($conf->facture->enabled) && $user->rights->facture->lire) if(! empty($conf->fournisseur->enabled) && $user->rights->fournisseur->facture->lire) if(! empty($conf->don->enabled) && $user->rights->societe->lire) if(! empty($conf->tax->enabled) && $user->rights->tax->charges->lire) if(! empty($conf->facture->enabled) &&! empty($conf->commande->enabled) && $user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(! empty($conf->facture->enabled) && $user->rights->facture->lire) if(! empty($conf->fournisseur->enabled) && $user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
Definition: index.php:1053
picto_from_langcode($codelang, $moreatt='')
Return img flag of country for a language code or country code.
Class to manage Dolibarr users.
Definition: user.class.php:41
dol_nl2br($stringtoencode, $nl2brmode=0, $forxml=false)
Replace CRLF in string with a HTML BR tag.
dol_print_error($db='', $error='', $errors=null)
Affiche message erreur system avec toutes les informations pour faciliter le diagnostic et la remonte...
assign_post()
Assign POST values into object.
dol_buildlogin($lastname, $firstname)
Build a login from lastname, firstname.
assign_values(&$action, $id)
Set content of ->tpl array, to use into template.
Class to manage third parties objects (customers, suppliers, prospects...)
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin='1', $morecss='')
Show information for admin users or standard users.
Class to manage members of a foundation.
Class to maage members using default canvas.
getRandomPassword($generic=false)
Return a generated password using default module.
dol_print_email($email, $cid=0, $socid=0, $addlink=0, $max=64, $showinvalid=1, $withpicto=0)
Show EMail link.
dol_print_phone($phone, $countrycode='', $cid=0, $socid=0, $addlink='', $separ="&nbsp;", $withpicto='', $titlealt='', $adddivfloat=0)
Format phone numbers according to country.
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.