dolibarr 21.0.0-beta
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 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
30{
34 public $db;
35
39 public $dirmodule;
43 public $targetmodule;
47 public $canvas;
51 public $card;
55 public $tpl = array();
59 public $object;
60
64 public $error = '';
65
69 public $errors = array();
70
71
78 public function getObject($id)
79 {
80 $object = new Adherent($this->db);
81
82 if (!empty($id)) {
83 $object->fetch($id);
84 }
85
86 $this->object = $object;
87
88 return $object;
89 }
90
91 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
99 public function assign_values(&$action, $id)
100 {
101 // phpcs:enable
102 global $conf, $langs, $user, $canvas;
103 global $form, $formcompany, $objsoc;
104
105 if ($action == 'add' || $action == 'update') {
106 $this->assign_post();
107 }
108
109 foreach ($this->object as $key => $value) {
110 $this->tpl[$key] = $value;
111 }
112
113 $this->tpl['error'] = $this->error;
114 $this->tpl['errors'] = $this->errors;
115
116 if ($action == 'create' || $action == 'edit') {
117 if ($conf->use_javascript_ajax) {
118 $this->tpl['ajax_selectcountry'] = "\n".'<script type="text/javascript">
119 jQuery(document).ready(function () {
120 jQuery("#selectcountry_id").change(function() {
121 document.formsoc.action.value="'.$action.'";
122 document.formsoc.canvas.value="'.$canvas.'";
123 document.formsoc.submit();
124 });
125 })
126 </script>'."\n";
127 }
128
129 if (is_object($objsoc) && $objsoc->id > 0) {
130 $this->tpl['company'] = $objsoc->getNomUrl(1);
131 $this->tpl['company_id'] = $objsoc->id;
132 } else {
133 $this->tpl['company'] = $form->select_company($this->object->socid, 'socid', '', 1);
134 }
135
136 // Civility
137 $this->tpl['select_civility'] = $formcompany->select_civility($this->object->civility_id);
138
139 // Predefined with third party
140 if ((isset($objsoc->typent_code) && $objsoc->typent_code == 'TE_PRIVATE')) {
141 if (dol_strlen(trim($this->object->address)) == 0) {
142 $this->tpl['address'] = $objsoc->address;
143 }
144 if (dol_strlen(trim($this->object->zip)) == 0) {
145 $this->object->zip = $objsoc->zip;
146 }
147 if (dol_strlen(trim($this->object->town)) == 0) {
148 $this->object->town = $objsoc->town;
149 }
150 if (dol_strlen(trim($this->object->phone_perso)) == 0) {
151 $this->object->phone_perso = $objsoc->phone;
152 }
153 if (dol_strlen(trim($this->object->phone_mobile)) == 0) {
154 $this->object->phone_mobile = $objsoc->phone_mobile;
155 }
156 if (dol_strlen(trim($this->object->email)) == 0) {
157 $this->object->email = $objsoc->email;
158 }
159 }
160
161 // Zip
162 $this->tpl['select_zip'] = $formcompany->select_ziptown($this->object->zip, 'zipcode', array('town', 'selectcountry_id', 'state_id'), 6);
163
164 // Town
165 $this->tpl['select_town'] = $formcompany->select_ziptown($this->object->town, 'town', array('zipcode', 'selectcountry_id', 'state_id'));
166
167 if ($this->object->country_id == 0) {
168 $this->object->country_id = $objsoc->country_id;
169 }
170
171 // Country
172 $this->tpl['select_country'] = $form->select_country($this->object->country_id, 'country_id');
173 $countrynotdefined = $langs->trans("ErrorSetACountryFirst").' ('.$langs->trans("SeeAbove").')';
174
175 if ($user->admin) {
176 $this->tpl['info_admin'] = info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
177 }
178
179 // State
180 if ($this->object->country_id) {
181 $this->tpl['select_state'] = $formcompany->select_state($this->object->state_id, $this->object->country_code);
182 } else {
183 $this->tpl['select_state'] = $countrynotdefined;
184 }
185
186 // Physical or Moral
187 $selectarray = array('0' => $langs->trans("Physical"), '1' => $langs->trans("Moral"));
188 $this->tpl['select_morphy'] = $form->selectarray('morphy', $selectarray, $this->object->morphy, 0);
189 }
190
191 if ($action == 'view' || $action == 'edit' || $action == 'delete') {
192 // Emailing
193 if (isModEnabled('mailing')) {
194 $langs->load("mails");
195 $this->tpl['nb_emailing'] = $this->object->getNbOfEMailings();
196 }
197
198 // Dolibarr user
199 if ($this->object->user_id) {
200 $dolibarr_user = new User($this->db);
201 $result = $dolibarr_user->fetch($this->object->user_id);
202 $this->tpl['dolibarr_user'] = $dolibarr_user->getLoginUrl(1);
203 } else {
204 $this->tpl['dolibarr_user'] = $langs->trans("NoDolibarrAccess");
205 }
206 }
207
208 if ($action == 'view' || $action == 'delete') {
209 $this->tpl['showrefnav'] = $form->showrefnav($this->object, 'id');
210
211 if ($this->object->socid > 0) {
212 $objsoc = new Societe($this->db);
213
214 $objsoc->fetch($this->object->socid);
215 $this->tpl['company'] = $objsoc->getNomUrl(1);
216 } else {
217 $this->tpl['company'] = $langs->trans("AdherentNotLinkedToThirdParty");
218 }
219
220 $this->tpl['civility'] = $this->object->getCivilityLabel();
221
222 $this->tpl['address'] = dol_nl2br($this->object->address);
223
224 $this->tpl['zip'] = ($this->object->zip ? $this->object->zip.'&nbsp;' : '');
225
226 $img = picto_from_langcode($this->object->country_code);
227 $this->tpl['country'] = ($img ? $img.' ' : '').$this->object->country;
228
229 $this->tpl['phone_perso'] = dol_print_phone($this->object->phone_perso, $this->object->country_code, 0, $this->object->id, 'AC_TEL');
230 $this->tpl['phone_mobile'] = dol_print_phone($this->object->phone_mobile, $this->object->country_code, 0, $this->object->id, 'AC_TEL');
231 $this->tpl['email'] = dol_print_email($this->object->email, 0, $this->object->id, 'AC_EMAIL');
232
233 $this->tpl['visibility'] = $this->object->getmorphylib($this->object->morphy);
234
235 $this->tpl['note'] = $this->object->note_private;
236 }
237
238 if ($action == 'create_user') {
239 // Full firstname and lastname separated with a dot : firstname.lastname
240 include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
241 require_once DOL_DOCUMENT_ROOT.'/core/lib/security2.lib.php';
242 $login = dol_buildlogin($this->object->lastname, $this->object->firstname);
243
244 $generated_password = getRandomPassword(false);
245 $password = $generated_password;
246
247 // Create a form array
248 $formquestion = array(
249 array('label' => $langs->trans("LoginToCreate"), 'type' => 'text', 'name' => 'login', 'value' => $login),
250 array('label' => $langs->trans("Password"), 'type' => 'text', 'name' => 'password', 'value' => $password));
251
252 $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');
253 }
254 }
255
256 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
262 private function assign_post()
263 {
264 // phpcs:enable
265 global $langs, $mysoc;
266
267 $this->object->old_name = GETPOST("old_name");
268 $this->object->old_firstname = GETPOST("old_firstname");
269
270 $this->object->fk_soc = GETPOSTINT("fk_soc");
271 $this->object->socid = GETPOSTINT("fk_soc");
272 $this->object->lastname = GETPOST("lastname");
273 $this->object->firstname = GETPOST("firstname");
274 $this->object->civility_id = GETPOST("civility_id");
275 $this->object->address = GETPOST("address");
276 $this->object->zip = GETPOST("zipcode");
277 $this->object->town = GETPOST("town");
278 $this->object->country_id = GETPOSTINT("country_id") ? GETPOSTINT("country_id") : $mysoc->country_id;
279 $this->object->state_id = GETPOSTINT("state_id");
280 $this->object->phone_perso = GETPOST("phone_perso");
281 $this->object->phone_mobile = GETPOST("phone_mobile");
282 $this->object->email = GETPOST("email", 'alphawithlgt');
283 $this->object->note_private = GETPOST("note", 'restricthtml');
284 $this->object->canvas = GETPOST("canvas");
285
286 // We set country_id, and country_code label of the chosen country
287 if ($this->object->country_id) {
288 $sql = "SELECT code, label FROM ".MAIN_DB_PREFIX."c_country WHERE rowid = ".((int) $this->object->country_id);
289 $resql = $this->db->query($sql);
290 if ($resql) {
291 $obj = $this->db->fetch_object($resql);
292
293 $this->object->country_code = $obj->code;
294 $this->object->country = $langs->trans("Country".$obj->code) ? $langs->trans("Country".$obj->code) : $obj->label;
295 } else {
296 dol_print_error($this->db);
297 }
298 }
299 }
300}
$id
Definition account.php:48
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.
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.
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_print_phone($phone, $countrycode='', $cid=0, $socid=0, $addlink='', $separ="&nbsp;", $withpicto='', $titlealt='', $adddivfloat=0, $morecss='paddingright')
Format phone numbers according to country.
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, $morecss='paddingrightonly')
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.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin='1', $morecss='hideonsmartphone', $textfordropdown='', $picto='')
Show information in HTML for admin users or standard users.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79
getRandomPassword($generic=false, $replaceambiguouschars=null, $length=32)
Return a generated password using default module.