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