| Total Complexity | 518 |
| Total Lines | 2529 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
Complex classes like AdherentController often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use AdherentController, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 70 | class AdherentController extends DolibarrController |
||
| 71 | { |
||
| 72 | /** |
||
| 73 | * \file htdocs/adherents/agenda.php |
||
| 74 | * \ingroup member |
||
| 75 | * \brief Page of members events |
||
| 76 | */ |
||
| 77 | public function agenda() |
||
| 78 | { |
||
| 79 | global $conf; |
||
| 80 | global $db; |
||
| 81 | global $user; |
||
| 82 | global $hookmanager; |
||
| 83 | global $user; |
||
| 84 | global $menumanager; |
||
| 85 | global $langs; |
||
| 86 | |||
| 87 | // Load translation files required by the page |
||
| 88 | $langs->loadLangs(['companies', 'members']); |
||
| 89 | |||
| 90 | // Get Parameters |
||
| 91 | $id = GETPOSTINT('id') ? GETPOSTINT('id') : GETPOSTINT('rowid'); |
||
| 92 | |||
| 93 | // Pagination |
||
| 94 | $limit = GETPOSTINT('limit') ? GETPOSTINT('limit') : $conf->liste_limit; |
||
| 95 | $sortfield = GETPOST('sortfield', 'aZ09comma'); |
||
| 96 | $sortorder = GETPOST('sortorder', 'aZ09comma'); |
||
| 97 | $page = GETPOSTISSET('pageplusone') ? (GETPOSTINT('pageplusone') - 1) : GETPOSTINT("page"); |
||
| 98 | if (empty($page) || $page == -1) { |
||
| 99 | $page = 0; |
||
| 100 | } // If $page is not defined, or '' or -1 |
||
| 101 | $offset = $limit * $page; |
||
| 102 | $pageprev = $page - 1; |
||
| 103 | $pagenext = $page + 1; |
||
| 104 | if (!$sortfield) { |
||
| 105 | $sortfield = 'a.datep,a.id'; |
||
| 106 | } |
||
| 107 | if (!$sortorder) { |
||
| 108 | $sortorder = 'DESC'; |
||
| 109 | } |
||
| 110 | |||
| 111 | if (GETPOST('actioncode', 'array')) { |
||
| 112 | $actioncode = GETPOST('actioncode', 'array', 3); |
||
| 113 | if (!count($actioncode)) { |
||
| 114 | $actioncode = '0'; |
||
| 115 | } |
||
| 116 | } else { |
||
| 117 | $actioncode = GETPOST("actioncode", "alpha", 3) ? GETPOST("actioncode", "alpha", 3) : (GETPOST("actioncode") == '0' ? '0' : getDolGlobalString('AGENDA_DEFAULT_FILTER_TYPE_FOR_OBJECT')); |
||
| 118 | } |
||
| 119 | $search_rowid = GETPOST('search_rowid'); |
||
| 120 | $search_agenda_label = GETPOST('search_agenda_label'); |
||
| 121 | |||
| 122 | // Get object canvas (By default, this is not defined, so standard usage of dolibarr) |
||
| 123 | $objcanvas = null; |
||
| 124 | |||
| 125 | // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context |
||
| 126 | $hookmanager->initHooks(['memberagenda', 'globalcard']); |
||
| 127 | |||
| 128 | // Security check |
||
| 129 | $result = restrictedArea($user, 'adherent', $id); |
||
| 130 | |||
| 131 | // Initialize technical objects |
||
| 132 | $object = new Adherent($db); |
||
| 133 | $result = $object->fetch($id); |
||
| 134 | if ($result > 0) { |
||
| 135 | $object->fetch_thirdparty(); |
||
| 136 | |||
| 137 | $adht = new AdherentType($db); |
||
| 138 | $result = $adht->fetch($object->typeid); |
||
| 139 | } |
||
| 140 | |||
| 141 | /* |
||
| 142 | * Actions |
||
| 143 | */ |
||
| 144 | |||
| 145 | $parameters = ['id' => $id, 'objcanvas' => $objcanvas]; |
||
| 146 | $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks |
||
|
|
|||
| 147 | if ($reshook < 0) { |
||
| 148 | setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); |
||
| 149 | } |
||
| 150 | |||
| 151 | if (empty($reshook)) { |
||
| 152 | // Cancel |
||
| 153 | if (GETPOST('cancel', 'alpha') && !empty($backtopage)) { |
||
| 154 | header("Location: " . $backtopage); |
||
| 155 | exit; |
||
| 156 | } |
||
| 157 | |||
| 158 | // Purge search criteria |
||
| 159 | if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) { // All test are required to be compatible with all browsers |
||
| 160 | $actioncode = ''; |
||
| 161 | $search_rowid = ''; |
||
| 162 | $search_agenda_label = ''; |
||
| 163 | } |
||
| 164 | } |
||
| 165 | |||
| 166 | /* |
||
| 167 | * View |
||
| 168 | */ |
||
| 169 | |||
| 170 | require_once realpath(BASE_PATH . '/../Dolibarr/Modules/Adherent/Views/agenda.php'); |
||
| 171 | |||
| 172 | $db->close(); |
||
| 173 | return true; |
||
| 174 | } |
||
| 175 | |||
| 176 | /** |
||
| 177 | * \file htdocs/adherents/card.php |
||
| 178 | * \ingroup member |
||
| 179 | * \brief Page of a member |
||
| 180 | */ |
||
| 181 | public function card() |
||
| 182 | { |
||
| 183 | global $conf; |
||
| 184 | global $db; |
||
| 185 | global $user; |
||
| 186 | global $hookmanager; |
||
| 187 | global $user; |
||
| 188 | global $menumanager; |
||
| 189 | global $langs; |
||
| 190 | global $mysoc; |
||
| 191 | |||
| 192 | // Load translation files required by the page |
||
| 193 | $langs->loadLangs(["companies", "bills", "members", "users", "other", "paypal"]); |
||
| 194 | |||
| 195 | |||
| 196 | // Get parameters |
||
| 197 | $action = GETPOST('action', 'aZ09'); |
||
| 198 | $cancel = GETPOST('cancel', 'alpha'); |
||
| 199 | $backtopage = GETPOST('backtopage', 'alpha'); |
||
| 200 | $confirm = GETPOST('confirm', 'alpha'); |
||
| 201 | $rowid = GETPOSTINT('rowid'); |
||
| 202 | $id = GETPOST('id') ? GETPOSTINT('id') : $rowid; |
||
| 203 | $typeid = GETPOSTINT('typeid'); |
||
| 204 | $userid = GETPOSTINT('userid'); |
||
| 205 | $socid = GETPOSTINT('socid'); |
||
| 206 | $ref = GETPOST('ref', 'alpha'); |
||
| 207 | |||
| 208 | if (isModEnabled('mailmanspip')) { |
||
| 209 | include_once DOL_DOCUMENT_ROOT . '/mailmanspip/class/mailmanspip.class.php'; |
||
| 210 | |||
| 211 | $langs->load('mailmanspip'); |
||
| 212 | |||
| 213 | $mailmanspip = new MailmanSpip($db); |
||
| 214 | } |
||
| 215 | |||
| 216 | $object = new Adherent($db); |
||
| 217 | $extrafields = new ExtraFields($db); |
||
| 218 | |||
| 219 | // fetch optionals attributes and labels |
||
| 220 | $extrafields->fetch_name_optionals_label($object->table_element); |
||
| 221 | |||
| 222 | $socialnetworks = getArrayOfSocialNetworks(); |
||
| 223 | |||
| 224 | // Get object canvas (By default, this is not defined, so standard usage of dolibarr) |
||
| 225 | $object->getCanvas($id); |
||
| 226 | $canvas = $object->canvas ? $object->canvas : GETPOST("canvas"); |
||
| 227 | $objcanvas = null; |
||
| 228 | if (!empty($canvas)) { |
||
| 229 | require_once DOL_DOCUMENT_ROOT . '/core/class/canvas.class.php'; |
||
| 230 | $objcanvas = new Canvas($db, $action); |
||
| 231 | $objcanvas->getCanvas('adherent', 'membercard', $canvas); |
||
| 232 | } |
||
| 233 | |||
| 234 | // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context |
||
| 235 | $hookmanager->initHooks(['membercard', 'globalcard']); |
||
| 236 | |||
| 237 | // Fetch object |
||
| 238 | if ($id > 0 || !empty($ref)) { |
||
| 239 | // Load member |
||
| 240 | $result = $object->fetch($id, $ref); |
||
| 241 | |||
| 242 | // Define variables to know what current user can do on users |
||
| 243 | $canadduser = ($user->admin || $user->hasRight('user', 'user', 'creer')); |
||
| 244 | // Define variables to know what current user can do on properties of user linked to edited member |
||
| 245 | if ($object->user_id) { |
||
| 246 | // $User is the user who edits, $object->user_id is the id of the related user in the edited member |
||
| 247 | $caneditfielduser = ((($user->id == $object->user_id) && $user->hasRight('user', 'self', 'creer')) |
||
| 248 | || (($user->id != $object->user_id) && $user->hasRight('user', 'user', 'creer'))); |
||
| 249 | $caneditpassworduser = ((($user->id == $object->user_id) && $user->hasRight('user', 'self', 'password')) |
||
| 250 | || (($user->id != $object->user_id) && $user->hasRight('user', 'user', 'password'))); |
||
| 251 | } |
||
| 252 | } |
||
| 253 | |||
| 254 | // Define variables to determine what the current user can do on the members |
||
| 255 | $canaddmember = $user->hasRight('adherent', 'creer'); |
||
| 256 | // Define variables to determine what the current user can do on the properties of a member |
||
| 257 | if ($id) { |
||
| 258 | $caneditfieldmember = $user->hasRight('adherent', 'creer'); |
||
| 259 | } |
||
| 260 | |||
| 261 | // Security check |
||
| 262 | $result = restrictedArea($user, 'adherent', $object->id, '', '', 'socid', 'rowid', 0); |
||
| 263 | |||
| 264 | if (!$user->hasRight('adherent', 'creer') && $action == 'edit') { |
||
| 265 | accessforbidden('Not enough permission'); |
||
| 266 | } |
||
| 267 | |||
| 268 | $linkofpubliclist = DOL_MAIN_URL_ROOT . '/public/members/public_list.php' . ((isModEnabled('multicompany')) ? '?entity=' . $conf->entity : ''); |
||
| 269 | |||
| 270 | |||
| 271 | /* |
||
| 272 | * Actions |
||
| 273 | */ |
||
| 274 | |||
| 275 | $parameters = ['id' => $id, 'rowid' => $id, 'objcanvas' => $objcanvas, 'confirm' => $confirm]; |
||
| 276 | $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks |
||
| 277 | if ($reshook < 0) { |
||
| 278 | setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); |
||
| 279 | } |
||
| 280 | |||
| 281 | if (empty($reshook)) { |
||
| 282 | $backurlforlist = '/adherents/list.php'; |
||
| 283 | |||
| 284 | if (empty($backtopage) || ($cancel && empty($id))) { |
||
| 285 | if (empty($backtopage) || ($cancel && strpos($backtopage, '__ID__'))) { |
||
| 286 | if (empty($id) && (($action != 'add' && $action != 'create') || $cancel)) { |
||
| 287 | $backtopage = $backurlforlist; |
||
| 288 | } else { |
||
| 289 | $backtopage = '/adherents/card.php?id=' . ((!empty($id) && $id > 0) ? $id : '__ID__'); |
||
| 290 | } |
||
| 291 | } |
||
| 292 | } |
||
| 293 | |||
| 294 | if ($cancel) { |
||
| 295 | if (!empty($backtopageforcancel)) { |
||
| 296 | header("Location: " . $backtopageforcancel); |
||
| 297 | exit; |
||
| 298 | } elseif (!empty($backtopage)) { |
||
| 299 | header("Location: " . $backtopage); |
||
| 300 | exit; |
||
| 301 | } |
||
| 302 | $action = ''; |
||
| 303 | } |
||
| 304 | |||
| 305 | if ($action == 'setuserid' && ($user->hasRight('user', 'self', 'creer') || $user->hasRight('user', 'user', 'creer'))) { |
||
| 306 | $error = 0; |
||
| 307 | if (!$user->hasRight('user', 'user', 'creer')) { // If can edit only itself user, we can link to itself only |
||
| 308 | if ($userid != $user->id && $userid != $object->user_id) { |
||
| 309 | $error++; |
||
| 310 | setEventMessages($langs->trans("ErrorUserPermissionAllowsToLinksToItselfOnly"), null, 'errors'); |
||
| 311 | } |
||
| 312 | } |
||
| 313 | |||
| 314 | if (!$error) { |
||
| 315 | if ($userid != $object->user_id) { // If link differs from currently in database |
||
| 316 | $result = $object->setUserId($userid); |
||
| 317 | if ($result < 0) { |
||
| 318 | dol_print_error($object->db, $object->error); |
||
| 319 | } |
||
| 320 | $action = ''; |
||
| 321 | } |
||
| 322 | } |
||
| 323 | } |
||
| 324 | |||
| 325 | if ($action == 'setsocid') { |
||
| 326 | $error = 0; |
||
| 327 | if (!$error) { |
||
| 328 | if ($socid != $object->socid) { // If link differs from currently in database |
||
| 329 | $sql = "SELECT rowid FROM " . MAIN_DB_PREFIX . "adherent"; |
||
| 330 | $sql .= " WHERE socid = " . ((int) $socid); |
||
| 331 | $sql .= " AND entity = " . $conf->entity; |
||
| 332 | $resql = $db->query($sql); |
||
| 333 | if ($resql) { |
||
| 334 | $obj = $db->fetch_object($resql); |
||
| 335 | if ($obj && $obj->rowid > 0) { |
||
| 336 | $othermember = new Adherent($db); |
||
| 337 | $othermember->fetch($obj->rowid); |
||
| 338 | $thirdparty = new Societe($db); |
||
| 339 | $thirdparty->fetch($socid); |
||
| 340 | $error++; |
||
| 341 | setEventMessages($langs->trans("ErrorMemberIsAlreadyLinkedToThisThirdParty", $othermember->getFullName($langs), $othermember->login, $thirdparty->name), null, 'errors'); |
||
| 342 | } |
||
| 343 | } |
||
| 344 | |||
| 345 | if (!$error) { |
||
| 346 | $result = $object->setThirdPartyId($socid); |
||
| 347 | if ($result < 0) { |
||
| 348 | dol_print_error($object->db, $object->error); |
||
| 349 | } |
||
| 350 | $action = ''; |
||
| 351 | } |
||
| 352 | } |
||
| 353 | } |
||
| 354 | } |
||
| 355 | |||
| 356 | // Create user from a member |
||
| 357 | if ($action == 'confirm_create_user' && $confirm == 'yes' && $user->hasRight('user', 'user', 'creer')) { |
||
| 358 | if ($result > 0) { |
||
| 359 | // Creation user |
||
| 360 | $nuser = new User($db); |
||
| 361 | $tmpuser = dol_clone($object); |
||
| 362 | if (GETPOST('internalorexternal', 'aZ09') == 'internal') { |
||
| 363 | $tmpuser->fk_soc = 0; |
||
| 364 | } |
||
| 365 | |||
| 366 | $result = $nuser->create_from_member($tmpuser, GETPOST('login', 'alphanohtml')); |
||
| 367 | |||
| 368 | if ($result < 0) { |
||
| 369 | $langs->load("errors"); |
||
| 370 | setEventMessages($langs->trans($nuser->error), null, 'errors'); |
||
| 371 | } else { |
||
| 372 | setEventMessages($langs->trans("NewUserCreated", $nuser->login), null, 'mesgs'); |
||
| 373 | $action = ''; |
||
| 374 | } |
||
| 375 | } else { |
||
| 376 | setEventMessages($object->error, $object->errors, 'errors'); |
||
| 377 | } |
||
| 378 | } |
||
| 379 | |||
| 380 | // Create third party from a member |
||
| 381 | if ($action == 'confirm_create_thirdparty' && $confirm == 'yes' && $user->hasRight('societe', 'creer')) { |
||
| 382 | if ($result > 0) { |
||
| 383 | // User creation |
||
| 384 | $company = new Societe($db); |
||
| 385 | $result = $company->create_from_member($object, GETPOST('companyname', 'alpha'), GETPOST('companyalias', 'alpha')); |
||
| 386 | |||
| 387 | if ($result < 0) { |
||
| 388 | $langs->load("errors"); |
||
| 389 | setEventMessages($langs->trans($company->error), null, 'errors'); |
||
| 390 | setEventMessages($company->error, $company->errors, 'errors'); |
||
| 391 | } |
||
| 392 | } else { |
||
| 393 | setEventMessages($object->error, $object->errors, 'errors'); |
||
| 394 | } |
||
| 395 | } |
||
| 396 | |||
| 397 | if ($action == 'update' && !$cancel && $user->hasRight('adherent', 'creer')) { |
||
| 398 | require_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php'; |
||
| 399 | |||
| 400 | $birthdate = ''; |
||
| 401 | if (GETPOSTINT("birthday") && GETPOSTINT("birthmonth") && GETPOSTINT("birthyear")) { |
||
| 402 | $birthdate = dol_mktime(12, 0, 0, GETPOSTINT("birthmonth"), GETPOSTINT("birthday"), GETPOSTINT("birthyear")); |
||
| 403 | } |
||
| 404 | $lastname = GETPOST("lastname", 'alphanohtml'); |
||
| 405 | $firstname = GETPOST("firstname", 'alphanohtml'); |
||
| 406 | $gender = GETPOST("gender", 'alphanohtml'); |
||
| 407 | $societe = GETPOST("societe", 'alphanohtml'); |
||
| 408 | $morphy = GETPOST("morphy", 'alphanohtml'); |
||
| 409 | $login = GETPOST("login", 'alphanohtml'); |
||
| 410 | if ($morphy != 'mor' && empty($lastname)) { |
||
| 411 | $error++; |
||
| 412 | $langs->load("errors"); |
||
| 413 | setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Lastname")), null, 'errors'); |
||
| 414 | } |
||
| 415 | if ($morphy != 'mor' && (!isset($firstname) || $firstname == '')) { |
||
| 416 | $error++; |
||
| 417 | $langs->load("errors"); |
||
| 418 | setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Firstname")), null, 'errors'); |
||
| 419 | } |
||
| 420 | if ($morphy == 'mor' && empty($societe)) { |
||
| 421 | $error++; |
||
| 422 | $langs->load("errors"); |
||
| 423 | setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Company")), null, 'errors'); |
||
| 424 | } |
||
| 425 | // Check if the login already exists |
||
| 426 | if (!getDolGlobalString('ADHERENT_LOGIN_NOT_REQUIRED')) { |
||
| 427 | if (empty($login)) { |
||
| 428 | $error++; |
||
| 429 | setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Login")), null, 'errors'); |
||
| 430 | } |
||
| 431 | } |
||
| 432 | // Create new object |
||
| 433 | if ($result > 0 && !$error) { |
||
| 434 | $object->oldcopy = dol_clone($object, 2); |
||
| 435 | |||
| 436 | // Change values |
||
| 437 | $object->civility_id = trim(GETPOST("civility_id", 'alphanohtml')); |
||
| 438 | $object->firstname = trim(GETPOST("firstname", 'alphanohtml')); |
||
| 439 | $object->lastname = trim(GETPOST("lastname", 'alphanohtml')); |
||
| 440 | $object->gender = trim(GETPOST("gender", 'alphanohtml')); |
||
| 441 | $object->login = trim(GETPOST("login", 'alphanohtml')); |
||
| 442 | if (GETPOSTISSET('pass')) { |
||
| 443 | $object->pass = trim(GETPOST("pass", 'none')); // For password, we must use 'none' |
||
| 444 | } |
||
| 445 | |||
| 446 | $object->societe = trim(GETPOST("societe", 'alphanohtml')); // deprecated |
||
| 447 | $object->company = trim(GETPOST("societe", 'alphanohtml')); |
||
| 448 | |||
| 449 | $object->address = trim(GETPOST("address", 'alphanohtml')); |
||
| 450 | $object->zip = trim(GETPOST("zipcode", 'alphanohtml')); |
||
| 451 | $object->town = trim(GETPOST("town", 'alphanohtml')); |
||
| 452 | $object->state_id = GETPOSTINT("state_id"); |
||
| 453 | $object->country_id = GETPOSTINT("country_id"); |
||
| 454 | |||
| 455 | $object->phone = trim(GETPOST("phone", 'alpha')); |
||
| 456 | $object->phone_perso = trim(GETPOST("phone_perso", 'alpha')); |
||
| 457 | $object->phone_mobile = trim(GETPOST("phone_mobile", 'alpha')); |
||
| 458 | $object->email = preg_replace('/\s+/', '', GETPOST("member_email", 'alpha')); |
||
| 459 | $object->url = trim(GETPOST('member_url', 'custom', 0, FILTER_SANITIZE_URL)); |
||
| 460 | $object->socialnetworks = []; |
||
| 461 | foreach ($socialnetworks as $key => $value) { |
||
| 462 | if (GETPOSTISSET($key) && GETPOST($key, 'alphanohtml') != '') { |
||
| 463 | $object->socialnetworks[$key] = trim(GETPOST($key, 'alphanohtml')); |
||
| 464 | } |
||
| 465 | } |
||
| 466 | $object->birth = $birthdate; |
||
| 467 | $object->default_lang = GETPOST('default_lang', 'alpha'); |
||
| 468 | $object->typeid = GETPOSTINT("typeid"); |
||
| 469 | //$object->note = trim(GETPOST("comment", "restricthtml")); |
||
| 470 | $object->morphy = GETPOST("morphy", 'alpha'); |
||
| 471 | |||
| 472 | if (GETPOST('deletephoto', 'alpha')) { |
||
| 473 | $object->photo = ''; |
||
| 474 | } elseif (!empty($_FILES['photo']['name'])) { |
||
| 475 | $object->photo = dol_sanitizeFileName($_FILES['photo']['name']); |
||
| 476 | } |
||
| 477 | |||
| 478 | // Get status and public property |
||
| 479 | $object->statut = GETPOSTINT("statut"); |
||
| 480 | $object->status = GETPOSTINT("statut"); |
||
| 481 | $object->public = GETPOSTINT("public"); |
||
| 482 | |||
| 483 | // Fill array 'array_options' with data from add form |
||
| 484 | $ret = $extrafields->setOptionalsFromPost(null, $object, '@GETPOSTISSET'); |
||
| 485 | if ($ret < 0) { |
||
| 486 | $error++; |
||
| 487 | } |
||
| 488 | |||
| 489 | // Check if we need to also synchronize user information |
||
| 490 | $nosyncuser = 0; |
||
| 491 | if ($object->user_id) { // If linked to a user |
||
| 492 | if ($user->id != $object->user_id && !$user->hasRight('user', 'user', 'creer')) { |
||
| 493 | $nosyncuser = 1; // Disable synchronizing |
||
| 494 | } |
||
| 495 | } |
||
| 496 | |||
| 497 | // Check if we need to also synchronize password information |
||
| 498 | $nosyncuserpass = 1; // no by default |
||
| 499 | if (GETPOSTISSET('pass')) { |
||
| 500 | if ($object->user_id) { // If member is linked to a user |
||
| 501 | $nosyncuserpass = 0; // We may try to sync password |
||
| 502 | if ($user->id == $object->user_id) { |
||
| 503 | if (!$user->hasRight('user', 'self', 'password')) { |
||
| 504 | $nosyncuserpass = 1; // Disable synchronizing |
||
| 505 | } |
||
| 506 | } else { |
||
| 507 | if (!$user->hasRight('user', 'user', 'password')) { |
||
| 508 | $nosyncuserpass = 1; // Disable synchronizing |
||
| 509 | } |
||
| 510 | } |
||
| 511 | } |
||
| 512 | } |
||
| 513 | |||
| 514 | if (!$error) { |
||
| 515 | $result = $object->update($user, 0, $nosyncuser, $nosyncuserpass); |
||
| 516 | |||
| 517 | if ($result >= 0 && !count($object->errors)) { |
||
| 518 | $categories = GETPOST('memcats', 'array'); |
||
| 519 | $object->setCategories($categories); |
||
| 520 | |||
| 521 | // Logo/Photo save |
||
| 522 | $dir = $conf->adherent->dir_output . '/' . get_exdir(0, 0, 0, 1, $object, 'member') . '/photos'; |
||
| 523 | $file_OK = is_uploaded_file($_FILES['photo']['tmp_name']); |
||
| 524 | if ($file_OK) { |
||
| 525 | if (GETPOST('deletephoto')) { |
||
| 526 | require_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php'; |
||
| 527 | $fileimg = $conf->adherent->dir_output . '/' . get_exdir(0, 0, 0, 1, $object, 'member') . '/photos/' . $object->photo; |
||
| 528 | $dirthumbs = $conf->adherent->dir_output . '/' . get_exdir(0, 0, 0, 1, $object, 'member') . '/photos/thumbs'; |
||
| 529 | dol_delete_file($fileimg); |
||
| 530 | dol_delete_dir_recursive($dirthumbs); |
||
| 531 | } |
||
| 532 | |||
| 533 | if (image_format_supported($_FILES['photo']['name']) > 0) { |
||
| 534 | dol_mkdir($dir); |
||
| 535 | |||
| 536 | if (@is_dir($dir)) { |
||
| 537 | $newfile = $dir . '/' . dol_sanitizeFileName($_FILES['photo']['name']); |
||
| 538 | if (!dol_move_uploaded_file($_FILES['photo']['tmp_name'], $newfile, 1, 0, $_FILES['photo']['error']) > 0) { |
||
| 539 | setEventMessages($langs->trans("ErrorFailedToSaveFile"), null, 'errors'); |
||
| 540 | } else { |
||
| 541 | // Create thumbs |
||
| 542 | $object->addThumbs($newfile); |
||
| 543 | } |
||
| 544 | } |
||
| 545 | } else { |
||
| 546 | setEventMessages("ErrorBadImageFormat", null, 'errors'); |
||
| 547 | } |
||
| 548 | } else { |
||
| 549 | switch ($_FILES['photo']['error']) { |
||
| 550 | case 1: //uploaded file exceeds the upload_max_filesize directive in php.ini |
||
| 551 | case 2: //uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the html form |
||
| 552 | $errors[] = "ErrorFileSizeTooLarge"; |
||
| 553 | break; |
||
| 554 | case 3: //uploaded file was only partially uploaded |
||
| 555 | $errors[] = "ErrorFilePartiallyUploaded"; |
||
| 556 | break; |
||
| 557 | } |
||
| 558 | } |
||
| 559 | |||
| 560 | $rowid = $object->id; |
||
| 561 | $id = $object->id; |
||
| 562 | $action = ''; |
||
| 563 | |||
| 564 | if (!empty($backtopage)) { |
||
| 565 | header("Location: " . $backtopage); |
||
| 566 | exit; |
||
| 567 | } |
||
| 568 | } else { |
||
| 569 | setEventMessages($object->error, $object->errors, 'errors'); |
||
| 570 | $action = ''; |
||
| 571 | } |
||
| 572 | } else { |
||
| 573 | $action = 'edit'; |
||
| 574 | } |
||
| 575 | } else { |
||
| 576 | $action = 'edit'; |
||
| 577 | } |
||
| 578 | } |
||
| 579 | |||
| 580 | if ($action == 'add' && $user->hasRight('adherent', 'creer')) { |
||
| 581 | if ($canvas) { |
||
| 582 | $object->canvas = $canvas; |
||
| 583 | } |
||
| 584 | $birthdate = ''; |
||
| 585 | if (GETPOSTISSET("birthday") && GETPOST("birthday") && GETPOSTISSET("birthmonth") && GETPOST("birthmonth") && GETPOSTISSET("birthyear") && GETPOST("birthyear")) { |
||
| 586 | $birthdate = dol_mktime(12, 0, 0, GETPOSTINT("birthmonth"), GETPOSTINT("birthday"), GETPOSTINT("birthyear")); |
||
| 587 | } |
||
| 588 | $datesubscription = ''; |
||
| 589 | if (GETPOSTISSET("reday") && GETPOSTISSET("remonth") && GETPOSTISSET("reyear")) { |
||
| 590 | $datesubscription = dol_mktime(12, 0, 0, GETPOSTINT("remonth"), GETPOSTINT("reday"), GETPOSTINT("reyear")); |
||
| 591 | } |
||
| 592 | |||
| 593 | $typeid = GETPOSTINT("typeid"); |
||
| 594 | $civility_id = GETPOST("civility_id", 'alphanohtml'); |
||
| 595 | $lastname = GETPOST("lastname", 'alphanohtml'); |
||
| 596 | $firstname = GETPOST("firstname", 'alphanohtml'); |
||
| 597 | $gender = GETPOST("gender", 'alphanohtml'); |
||
| 598 | $societe = GETPOST("societe", 'alphanohtml'); |
||
| 599 | $address = GETPOST("address", 'alphanohtml'); |
||
| 600 | $zip = GETPOST("zipcode", 'alphanohtml'); |
||
| 601 | $town = GETPOST("town", 'alphanohtml'); |
||
| 602 | $state_id = GETPOSTINT("state_id"); |
||
| 603 | $country_id = GETPOSTINT("country_id"); |
||
| 604 | |||
| 605 | $phone = GETPOST("phone", 'alpha'); |
||
| 606 | $phone_perso = GETPOST("phone_perso", 'alpha'); |
||
| 607 | $phone_mobile = GETPOST("phone_mobile", 'alpha'); |
||
| 608 | $email = preg_replace('/\s+/', '', GETPOST("member_email", 'alpha')); |
||
| 609 | $url = trim(GETPOST('url', 'custom', 0, FILTER_SANITIZE_URL)); |
||
| 610 | $login = GETPOST("member_login", 'alphanohtml'); |
||
| 611 | $pass = GETPOST("password", 'none'); // For password, we use 'none' |
||
| 612 | $photo = GETPOST("photo", 'alphanohtml'); |
||
| 613 | $morphy = GETPOST("morphy", 'alphanohtml'); |
||
| 614 | $public = GETPOST("public", 'alphanohtml'); |
||
| 615 | |||
| 616 | $userid = GETPOSTINT("userid"); |
||
| 617 | $socid = GETPOSTINT("socid"); |
||
| 618 | $default_lang = GETPOST('default_lang', 'alpha'); |
||
| 619 | |||
| 620 | $object->civility_id = $civility_id; |
||
| 621 | $object->firstname = $firstname; |
||
| 622 | $object->lastname = $lastname; |
||
| 623 | $object->gender = $gender; |
||
| 624 | $object->societe = $societe; // deprecated |
||
| 625 | $object->company = $societe; |
||
| 626 | $object->address = $address; |
||
| 627 | $object->zip = $zip; |
||
| 628 | $object->town = $town; |
||
| 629 | $object->state_id = $state_id; |
||
| 630 | $object->country_id = $country_id; |
||
| 631 | $object->phone = $phone; |
||
| 632 | $object->phone_perso = $phone_perso; |
||
| 633 | $object->phone_mobile = $phone_mobile; |
||
| 634 | $object->socialnetworks = []; |
||
| 635 | if (isModEnabled('socialnetworks')) { |
||
| 636 | foreach ($socialnetworks as $key => $value) { |
||
| 637 | if (GETPOSTISSET($key) && GETPOST($key, 'alphanohtml') != '') { |
||
| 638 | $object->socialnetworks[$key] = GETPOST("member_" . $key, 'alphanohtml'); |
||
| 639 | } |
||
| 640 | } |
||
| 641 | } |
||
| 642 | |||
| 643 | $object->email = $email; |
||
| 644 | $object->url = $url; |
||
| 645 | $object->login = $login; |
||
| 646 | $object->pass = $pass; |
||
| 647 | $object->birth = $birthdate; |
||
| 648 | $object->photo = $photo; |
||
| 649 | $object->typeid = $typeid; |
||
| 650 | //$object->note = $comment; |
||
| 651 | $object->morphy = $morphy; |
||
| 652 | $object->user_id = $userid; |
||
| 653 | $object->socid = $socid; |
||
| 654 | $object->public = $public; |
||
| 655 | $object->default_lang = $default_lang; |
||
| 656 | // Fill array 'array_options' with data from add form |
||
| 657 | $ret = $extrafields->setOptionalsFromPost(null, $object); |
||
| 658 | if ($ret < 0) { |
||
| 659 | $error++; |
||
| 660 | } |
||
| 661 | |||
| 662 | // Check parameters |
||
| 663 | if (empty($morphy) || $morphy == "-1") { |
||
| 664 | $error++; |
||
| 665 | setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("MemberNature")), null, 'errors'); |
||
| 666 | } |
||
| 667 | // Tests if the login already exists |
||
| 668 | if (!getDolGlobalString('ADHERENT_LOGIN_NOT_REQUIRED')) { |
||
| 669 | if (empty($login)) { |
||
| 670 | $error++; |
||
| 671 | setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Login")), null, 'errors'); |
||
| 672 | } else { |
||
| 673 | $sql = "SELECT login FROM " . MAIN_DB_PREFIX . "adherent WHERE login='" . $db->escape($login) . "'"; |
||
| 674 | $result = $db->query($sql); |
||
| 675 | if ($result) { |
||
| 676 | $num = $db->num_rows($result); |
||
| 677 | } |
||
| 678 | if ($num) { |
||
| 679 | $error++; |
||
| 680 | $langs->load("errors"); |
||
| 681 | setEventMessages($langs->trans("ErrorLoginAlreadyExists", $login), null, 'errors'); |
||
| 682 | } |
||
| 683 | } |
||
| 684 | if (empty($pass)) { |
||
| 685 | $error++; |
||
| 686 | setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Password")), null, 'errors'); |
||
| 687 | } |
||
| 688 | } |
||
| 689 | if ($morphy == 'mor' && empty($societe)) { |
||
| 690 | $error++; |
||
| 691 | $langs->load("errors"); |
||
| 692 | setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Company")), null, 'errors'); |
||
| 693 | } |
||
| 694 | if ($morphy != 'mor' && empty($lastname)) { |
||
| 695 | $error++; |
||
| 696 | $langs->load("errors"); |
||
| 697 | setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Lastname")), null, 'errors'); |
||
| 698 | } |
||
| 699 | if ($morphy != 'mor' && (!isset($firstname) || $firstname == '')) { |
||
| 700 | $error++; |
||
| 701 | $langs->load("errors"); |
||
| 702 | setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Firstname")), null, 'errors'); |
||
| 703 | } |
||
| 704 | if (!($typeid > 0)) { // Keep () before ! |
||
| 705 | $error++; |
||
| 706 | setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Type")), null, 'errors'); |
||
| 707 | } |
||
| 708 | if (getDolGlobalString('ADHERENT_MAIL_REQUIRED') && !isValidEmail($email)) { |
||
| 709 | $error++; |
||
| 710 | $langs->load("errors"); |
||
| 711 | setEventMessages($langs->trans("ErrorBadEMail", $email), null, 'errors'); |
||
| 712 | } |
||
| 713 | if (!empty($object->url) && !isValidUrl($object->url)) { |
||
| 714 | $langs->load("errors"); |
||
| 715 | setEventMessages($langs->trans("ErrorBadUrl", $object->url), null, 'errors'); |
||
| 716 | } |
||
| 717 | $public = 0; |
||
| 718 | if (isset($public)) { |
||
| 719 | $public = 1; |
||
| 720 | } |
||
| 721 | |||
| 722 | if (!$error) { |
||
| 723 | $db->begin(); |
||
| 724 | |||
| 725 | // Create the member |
||
| 726 | $result = $object->create($user); |
||
| 727 | if ($result > 0) { |
||
| 728 | // Foundation categories |
||
| 729 | $memcats = GETPOST('memcats', 'array'); |
||
| 730 | $object->setCategories($memcats); |
||
| 731 | |||
| 732 | $db->commit(); |
||
| 733 | |||
| 734 | $rowid = $object->id; |
||
| 735 | $id = $object->id; |
||
| 736 | |||
| 737 | $backtopage = preg_replace('/__ID__/', $id, $backtopage); |
||
| 738 | } else { |
||
| 739 | $db->rollback(); |
||
| 740 | |||
| 741 | $error++; |
||
| 742 | setEventMessages($object->error, $object->errors, 'errors'); |
||
| 743 | } |
||
| 744 | |||
| 745 | // Auto-create thirdparty on member creation |
||
| 746 | if (getDolGlobalString('ADHERENT_DEFAULT_CREATE_THIRDPARTY')) { |
||
| 747 | if ($result > 0) { |
||
| 748 | // Create third party out of a member |
||
| 749 | $company = new Societe($db); |
||
| 750 | $result = $company->create_from_member($object); |
||
| 751 | if ($result < 0) { |
||
| 752 | $langs->load("errors"); |
||
| 753 | setEventMessages($langs->trans($company->error), null, 'errors'); |
||
| 754 | setEventMessages($company->error, $company->errors, 'errors'); |
||
| 755 | } |
||
| 756 | } else { |
||
| 757 | setEventMessages($object->error, $object->errors, 'errors'); |
||
| 758 | } |
||
| 759 | } |
||
| 760 | } |
||
| 761 | $action = ($result < 0 || !$error) ? '' : 'create'; |
||
| 762 | |||
| 763 | if (!$error && $backtopage) { |
||
| 764 | header("Location: " . $backtopage); |
||
| 765 | exit; |
||
| 766 | } |
||
| 767 | } |
||
| 768 | |||
| 769 | if ($user->hasRight('adherent', 'supprimer') && $action == 'confirm_delete' && $confirm == 'yes') { |
||
| 770 | $result = $object->delete($user); |
||
| 771 | if ($result > 0) { |
||
| 772 | setEventMessages($langs->trans("RecordDeleted"), null, 'errors'); |
||
| 773 | if (!empty($backtopage) && !preg_match('/' . preg_quote($_SERVER['PHP_SELF'], '/') . '/', $backtopage)) { |
||
| 774 | header("Location: " . $backtopage); |
||
| 775 | exit; |
||
| 776 | } else { |
||
| 777 | header("Location: list.php"); |
||
| 778 | exit; |
||
| 779 | } |
||
| 780 | } else { |
||
| 781 | setEventMessages($object->error, null, 'errors'); |
||
| 782 | } |
||
| 783 | } |
||
| 784 | |||
| 785 | if ($user->hasRight('adherent', 'creer') && $action == 'confirm_valid' && $confirm == 'yes') { |
||
| 786 | $error = 0; |
||
| 787 | |||
| 788 | $db->begin(); |
||
| 789 | |||
| 790 | $adht = new AdherentType($db); |
||
| 791 | $adht->fetch($object->typeid); |
||
| 792 | |||
| 793 | $result = $object->validate($user); |
||
| 794 | |||
| 795 | if ($result >= 0 && !count($object->errors)) { |
||
| 796 | // Send confirmation email (according to parameters of member type. Otherwise generic) |
||
| 797 | if ($object->email && GETPOST("send_mail")) { |
||
| 798 | $subject = ''; |
||
| 799 | $msg = ''; |
||
| 800 | |||
| 801 | // Send subscription email |
||
| 802 | include_once DOL_DOCUMENT_ROOT . '/core/class/html.formmail.class.php'; |
||
| 803 | $formmail = new FormMail($db); |
||
| 804 | // Set output language |
||
| 805 | $outputlangs = new Translate('', $conf); |
||
| 806 | $outputlangs->setDefaultLang(empty($object->thirdparty->default_lang) ? $mysoc->default_lang : $object->thirdparty->default_lang); |
||
| 807 | // Load traductions files required by page |
||
| 808 | $outputlangs->loadLangs(["main", "members", "companies", "install", "other"]); |
||
| 809 | // Get email content from template |
||
| 810 | $arraydefaultmessage = null; |
||
| 811 | $labeltouse = getDolGlobalString('ADHERENT_EMAIL_TEMPLATE_MEMBER_VALIDATION'); |
||
| 812 | |||
| 813 | if (!empty($labeltouse)) { |
||
| 814 | $arraydefaultmessage = $formmail->getEMailTemplate($db, 'member', $user, $outputlangs, 0, 1, $labeltouse); |
||
| 815 | } |
||
| 816 | |||
| 817 | if (!empty($labeltouse) && is_object($arraydefaultmessage) && $arraydefaultmessage->id > 0) { |
||
| 818 | $subject = $arraydefaultmessage->topic; |
||
| 819 | $msg = $arraydefaultmessage->content; |
||
| 820 | } |
||
| 821 | |||
| 822 | if (empty($labeltouse) || (int) $labeltouse === -1) { |
||
| 823 | //fallback on the old configuration. |
||
| 824 | $langs->load("errors"); |
||
| 825 | setEventMessages('<a href="' . DOL_URL_ROOT . '/adherents/admin/member_emails.php">' . $langs->trans('WarningMandatorySetupNotComplete') . '</a>', null, 'errors'); |
||
| 826 | $error++; |
||
| 827 | } else { |
||
| 828 | $substitutionarray = getCommonSubstitutionArray($outputlangs, 0, null, $object); |
||
| 829 | complete_substitutions_array($substitutionarray, $outputlangs, $object); |
||
| 830 | $subjecttosend = make_substitutions($subject, $substitutionarray, $outputlangs); |
||
| 831 | $texttosend = make_substitutions(dol_concatdesc($msg, $adht->getMailOnValid()), $substitutionarray, $outputlangs); |
||
| 832 | |||
| 833 | $moreinheader = 'X-Dolibarr-Info: send_an_email by adherents/card.php' . "\r\n"; |
||
| 834 | |||
| 835 | $result = $object->sendEmail($texttosend, $subjecttosend, [], [], [], "", "", 0, -1, '', $moreinheader); |
||
| 836 | if ($result < 0) { |
||
| 837 | $error++; |
||
| 838 | setEventMessages($object->error, $object->errors, 'errors'); |
||
| 839 | } |
||
| 840 | } |
||
| 841 | } |
||
| 842 | } else { |
||
| 843 | $error++; |
||
| 844 | setEventMessages($object->error, $object->errors, 'errors'); |
||
| 845 | } |
||
| 846 | |||
| 847 | if (!$error) { |
||
| 848 | $db->commit(); |
||
| 849 | } else { |
||
| 850 | $db->rollback(); |
||
| 851 | } |
||
| 852 | $action = ''; |
||
| 853 | } |
||
| 854 | |||
| 855 | if ($user->hasRight('adherent', 'supprimer') && $action == 'confirm_resiliate') { |
||
| 856 | $error = 0; |
||
| 857 | |||
| 858 | if ($confirm == 'yes') { |
||
| 859 | $adht = new AdherentType($db); |
||
| 860 | $adht->fetch($object->typeid); |
||
| 861 | |||
| 862 | $result = $object->resiliate($user); |
||
| 863 | |||
| 864 | if ($result >= 0 && !count($object->errors)) { |
||
| 865 | if ($object->email && GETPOST("send_mail")) { |
||
| 866 | $subject = ''; |
||
| 867 | $msg = ''; |
||
| 868 | |||
| 869 | // Send subscription email |
||
| 870 | include_once DOL_DOCUMENT_ROOT . '/core/class/html.formmail.class.php'; |
||
| 871 | $formmail = new FormMail($db); |
||
| 872 | // Set output language |
||
| 873 | $outputlangs = new Translate('', $conf); |
||
| 874 | $outputlangs->setDefaultLang(empty($object->thirdparty->default_lang) ? $mysoc->default_lang : $object->thirdparty->default_lang); |
||
| 875 | // Load traductions files required by page |
||
| 876 | $outputlangs->loadLangs(["main", "members", "companies", "install", "other"]); |
||
| 877 | // Get email content from template |
||
| 878 | $arraydefaultmessage = null; |
||
| 879 | $labeltouse = getDolGlobalString('ADHERENT_EMAIL_TEMPLATE_CANCELATION'); |
||
| 880 | |||
| 881 | if (!empty($labeltouse)) { |
||
| 882 | $arraydefaultmessage = $formmail->getEMailTemplate($db, 'member', $user, $outputlangs, 0, 1, $labeltouse); |
||
| 883 | } |
||
| 884 | |||
| 885 | if (!empty($labeltouse) && is_object($arraydefaultmessage) && $arraydefaultmessage->id > 0) { |
||
| 886 | $subject = $arraydefaultmessage->topic; |
||
| 887 | $msg = $arraydefaultmessage->content; |
||
| 888 | } |
||
| 889 | |||
| 890 | if (empty($labeltouse) || (int) $labeltouse === -1) { |
||
| 891 | //fallback on the old configuration. |
||
| 892 | setEventMessages('WarningMandatorySetupNotComplete', null, 'errors'); |
||
| 893 | $error++; |
||
| 894 | } else { |
||
| 895 | $substitutionarray = getCommonSubstitutionArray($outputlangs, 0, null, $object); |
||
| 896 | complete_substitutions_array($substitutionarray, $outputlangs, $object); |
||
| 897 | $subjecttosend = make_substitutions($subject, $substitutionarray, $outputlangs); |
||
| 898 | $texttosend = make_substitutions(dol_concatdesc($msg, $adht->getMailOnResiliate()), $substitutionarray, $outputlangs); |
||
| 899 | |||
| 900 | $moreinheader = 'X-Dolibarr-Info: send_an_email by adherents/card.php' . "\r\n"; |
||
| 901 | |||
| 902 | $result = $object->sendEmail($texttosend, $subjecttosend, [], [], [], "", "", 0, -1, '', $moreinheader); |
||
| 903 | if ($result < 0) { |
||
| 904 | $error++; |
||
| 905 | setEventMessages($object->error, $object->errors, 'errors'); |
||
| 906 | } |
||
| 907 | } |
||
| 908 | } |
||
| 909 | } else { |
||
| 910 | $error++; |
||
| 911 | |||
| 912 | setEventMessages($object->error, $object->errors, 'errors'); |
||
| 913 | $action = ''; |
||
| 914 | } |
||
| 915 | } |
||
| 916 | if (!empty($backtopage) && !$error) { |
||
| 917 | header("Location: " . $backtopage); |
||
| 918 | exit; |
||
| 919 | } |
||
| 920 | } |
||
| 921 | |||
| 922 | if ($user->hasRight('adherent', 'supprimer') && $action == 'confirm_exclude') { |
||
| 923 | $error = 0; |
||
| 924 | |||
| 925 | if ($confirm == 'yes') { |
||
| 926 | $adht = new AdherentType($db); |
||
| 927 | $adht->fetch($object->typeid); |
||
| 928 | |||
| 929 | $result = $object->exclude($user); |
||
| 930 | |||
| 931 | if ($result >= 0 && !count($object->errors)) { |
||
| 932 | if ($object->email && GETPOST("send_mail")) { |
||
| 933 | $subject = ''; |
||
| 934 | $msg = ''; |
||
| 935 | |||
| 936 | // Send subscription email |
||
| 937 | include_once DOL_DOCUMENT_ROOT . '/core/class/html.formmail.class.php'; |
||
| 938 | $formmail = new FormMail($db); |
||
| 939 | // Set output language |
||
| 940 | $outputlangs = new Translate('', $conf); |
||
| 941 | $outputlangs->setDefaultLang(empty($object->thirdparty->default_lang) ? $mysoc->default_lang : $object->thirdparty->default_lang); |
||
| 942 | // Load traductions files required by page |
||
| 943 | $outputlangs->loadLangs(["main", "members", "companies", "install", "other"]); |
||
| 944 | // Get email content from template |
||
| 945 | $arraydefaultmessage = null; |
||
| 946 | $labeltouse = getDolGlobalString('ADHERENT_EMAIL_TEMPLATE_EXCLUSION'); |
||
| 947 | |||
| 948 | if (!empty($labeltouse)) { |
||
| 949 | $arraydefaultmessage = $formmail->getEMailTemplate($db, 'member', $user, $outputlangs, 0, 1, $labeltouse); |
||
| 950 | } |
||
| 951 | |||
| 952 | if (!empty($labeltouse) && is_object($arraydefaultmessage) && $arraydefaultmessage->id > 0) { |
||
| 953 | $subject = $arraydefaultmessage->topic; |
||
| 954 | $msg = $arraydefaultmessage->content; |
||
| 955 | } |
||
| 956 | |||
| 957 | if (empty($labeltouse) || (int) $labeltouse === -1) { |
||
| 958 | //fallback on the old configuration. |
||
| 959 | setEventMessages('WarningMandatorySetupNotComplete', null, 'errors'); |
||
| 960 | $error++; |
||
| 961 | } else { |
||
| 962 | $substitutionarray = getCommonSubstitutionArray($outputlangs, 0, null, $object); |
||
| 963 | complete_substitutions_array($substitutionarray, $outputlangs, $object); |
||
| 964 | $subjecttosend = make_substitutions($subject, $substitutionarray, $outputlangs); |
||
| 965 | $texttosend = make_substitutions(dol_concatdesc($msg, $adht->getMailOnExclude()), $substitutionarray, $outputlangs); |
||
| 966 | |||
| 967 | $moreinheader = 'X-Dolibarr-Info: send_an_email by adherents/card.php' . "\r\n"; |
||
| 968 | |||
| 969 | $result = $object->sendEmail($texttosend, $subjecttosend, [], [], [], "", "", 0, -1, '', $moreinheader); |
||
| 970 | if ($result < 0) { |
||
| 971 | $error++; |
||
| 972 | setEventMessages($object->error, $object->errors, 'errors'); |
||
| 973 | } |
||
| 974 | } |
||
| 975 | } |
||
| 976 | } else { |
||
| 977 | $error++; |
||
| 978 | |||
| 979 | setEventMessages($object->error, $object->errors, 'errors'); |
||
| 980 | $action = ''; |
||
| 981 | } |
||
| 982 | } |
||
| 983 | if (!empty($backtopage) && !$error) { |
||
| 984 | header("Location: " . $backtopage); |
||
| 985 | exit; |
||
| 986 | } |
||
| 987 | } |
||
| 988 | |||
| 989 | // SPIP Management |
||
| 990 | if ($user->hasRight('adherent', 'supprimer') && $action == 'confirm_del_spip' && $confirm == 'yes') { |
||
| 991 | if (!count($object->errors)) { |
||
| 992 | if (!$mailmanspip->del_to_spip($object)) { |
||
| 993 | setEventMessages($langs->trans('DeleteIntoSpipError') . ': ' . $mailmanspip->error, null, 'errors'); |
||
| 994 | } |
||
| 995 | } |
||
| 996 | } |
||
| 997 | |||
| 998 | if ($user->hasRight('adherent', 'creer') && $action == 'confirm_add_spip' && $confirm == 'yes') { |
||
| 999 | if (!count($object->errors)) { |
||
| 1000 | if (!$mailmanspip->add_to_spip($object)) { |
||
| 1001 | setEventMessages($langs->trans('AddIntoSpipError') . ': ' . $mailmanspip->error, null, 'errors'); |
||
| 1002 | } |
||
| 1003 | } |
||
| 1004 | } |
||
| 1005 | |||
| 1006 | // Actions when printing a doc from card |
||
| 1007 | include DOL_DOCUMENT_ROOT . '/core/actions_printing.inc.php'; |
||
| 1008 | |||
| 1009 | // Actions to build doc |
||
| 1010 | $upload_dir = $conf->adherent->dir_output; |
||
| 1011 | $permissiontoadd = $user->hasRight('adherent', 'creer'); |
||
| 1012 | include DOL_DOCUMENT_ROOT . '/core/actions_builddoc.inc.php'; |
||
| 1013 | |||
| 1014 | // Actions to send emails |
||
| 1015 | $triggersendname = 'MEMBER_SENTBYMAIL'; |
||
| 1016 | $paramname = 'id'; |
||
| 1017 | $mode = 'emailfrommember'; |
||
| 1018 | $trackid = 'mem' . $object->id; |
||
| 1019 | include DOL_DOCUMENT_ROOT . '/core/actions_sendmails.inc.php'; |
||
| 1020 | } |
||
| 1021 | |||
| 1022 | |||
| 1023 | /* |
||
| 1024 | * View |
||
| 1025 | */ |
||
| 1026 | |||
| 1027 | require_once realpath(BASE_PATH . '/../Dolibarr/Modules/Adherent/Views/card.php'); |
||
| 1028 | |||
| 1029 | $db->close(); |
||
| 1030 | return true; |
||
| 1031 | } |
||
| 1032 | |||
| 1033 | /** |
||
| 1034 | * \file htdocs/adherents/document.php |
||
| 1035 | * \brief Tab for documents linked to third party |
||
| 1036 | * \ingroup societe |
||
| 1037 | */ |
||
| 1038 | public function document() |
||
| 1129 | } |
||
| 1130 | |||
| 1131 | /** |
||
| 1132 | * \file htdocs/adherents/index.php |
||
| 1133 | * \ingroup member |
||
| 1134 | * \brief Home page of membership module |
||
| 1135 | */ |
||
| 1136 | public function index(bool $executeActions = true): bool |
||
| 1137 | { |
||
| 1138 | global $conf; |
||
| 1139 | global $db; |
||
| 1140 | global $user; |
||
| 1141 | global $hookmanager; |
||
| 1142 | global $user; |
||
| 1143 | global $menumanager; |
||
| 1144 | global $langs; |
||
| 1145 | |||
| 1146 | // Load translation files required by the page |
||
| 1147 | $langs->loadLangs(["companies", "members"]); |
||
| 1148 | |||
| 1149 | // $hookmanager = new HookManager($db); |
||
| 1150 | |||
| 1151 | // Initialize technical object to manage hooks. Note that conf->hooks_modules contains array |
||
| 1152 | $hookmanager->initHooks(['membersindex']); |
||
| 1153 | |||
| 1154 | // Security check |
||
| 1155 | $result = restrictedArea($user, 'adherent'); |
||
| 1156 | |||
| 1157 | /* |
||
| 1158 | * Actions |
||
| 1159 | */ |
||
| 1160 | |||
| 1161 | $userid = GETPOSTINT('userid'); |
||
| 1162 | if (GETPOST('addbox')) { |
||
| 1163 | // Add box (when submit is done from a form when ajax disabled) |
||
| 1164 | require_once DOL_DOCUMENT_ROOT . '/core/class/infobox.class.php'; |
||
| 1165 | $zone = GETPOSTINT('areacode'); |
||
| 1166 | $boxorder = GETPOST('boxorder', 'aZ09'); |
||
| 1167 | $boxorder .= GETPOST('boxcombo', 'aZ09'); |
||
| 1168 | $result = InfoBox::saveboxorder($db, $zone, $boxorder, $userid); |
||
| 1169 | if ($result > 0) { |
||
| 1170 | setEventMessages($langs->trans("BoxAdded"), null); |
||
| 1171 | } |
||
| 1172 | } |
||
| 1173 | |||
| 1174 | /* |
||
| 1175 | * View |
||
| 1176 | */ |
||
| 1177 | |||
| 1178 | require_once realpath(BASE_PATH . '/../Dolibarr/Modules/Adherent/Views/index.php'); |
||
| 1179 | |||
| 1180 | $db->close(); |
||
| 1181 | |||
| 1182 | return true; |
||
| 1183 | } |
||
| 1184 | |||
| 1185 | /** |
||
| 1186 | * \file htdocs/adherents/ldap.php |
||
| 1187 | * \ingroup ldap member |
||
| 1188 | * \brief Page fiche LDAP adherent |
||
| 1189 | */ |
||
| 1190 | public function ldap() |
||
| 1275 | } |
||
| 1276 | |||
| 1277 | /** |
||
| 1278 | * \file htdocs/adherents/list.php |
||
| 1279 | * \ingroup member |
||
| 1280 | * \brief Page to list all members of foundation |
||
| 1281 | */ |
||
| 1282 | public function list() |
||
| 1283 | { |
||
| 1284 | global $conf; |
||
| 1285 | global $db; |
||
| 1286 | global $user; |
||
| 1287 | global $hookmanager; |
||
| 1288 | global $user; |
||
| 1289 | global $menumanager; |
||
| 1290 | global $langs; |
||
| 1291 | |||
| 1292 | // Load translation files required by the page |
||
| 1293 | $langs->loadLangs(["members", "companies", "categories"]); |
||
| 1294 | |||
| 1295 | |||
| 1296 | // Get parameters |
||
| 1297 | $action = GETPOST('action', 'aZ09'); |
||
| 1298 | $massaction = GETPOST('massaction', 'alpha'); |
||
| 1299 | $show_files = GETPOSTINT('show_files'); |
||
| 1300 | $confirm = GETPOST('confirm', 'alpha'); |
||
| 1301 | $cancel = GETPOST('cancel', 'alpha'); |
||
| 1302 | $toselect = GETPOST('toselect', 'array'); |
||
| 1303 | $contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : 'memberslist'; // To manage different context of search |
||
| 1304 | $backtopage = GETPOST('backtopage', 'alpha'); |
||
| 1305 | $optioncss = GETPOST('optioncss', 'aZ'); |
||
| 1306 | $mode = GETPOST('mode', 'alpha'); |
||
| 1307 | |||
| 1308 | // Search fields |
||
| 1309 | $search = GETPOST("search", 'alpha'); |
||
| 1310 | $search_ref = GETPOST("search_ref", 'alpha'); |
||
| 1311 | $search_lastname = GETPOST("search_lastname", 'alpha'); |
||
| 1312 | $search_firstname = GETPOST("search_firstname", 'alpha'); |
||
| 1313 | $search_gender = GETPOST("search_gender", 'alpha'); |
||
| 1314 | $search_civility = GETPOST("search_civility", 'alpha'); |
||
| 1315 | $search_company = GETPOST('search_company', 'alphanohtml'); |
||
| 1316 | $search_login = GETPOST("search_login", 'alpha'); |
||
| 1317 | $search_address = GETPOST("search_address", 'alpha'); |
||
| 1318 | $search_zip = GETPOST("search_zip", 'alpha'); |
||
| 1319 | $search_town = GETPOST("search_town", 'alpha'); |
||
| 1320 | $search_state = GETPOST("search_state", 'alpha'); // county / departement / federal state |
||
| 1321 | $search_country = GETPOST("search_country", 'alpha'); |
||
| 1322 | $search_phone = GETPOST("search_phone", 'alpha'); |
||
| 1323 | $search_phone_perso = GETPOST("search_phone_perso", 'alpha'); |
||
| 1324 | $search_phone_mobile = GETPOST("search_phone_mobile", 'alpha'); |
||
| 1325 | $search_type = GETPOST("search_type", 'alpha'); |
||
| 1326 | $search_email = GETPOST("search_email", 'alpha'); |
||
| 1327 | $search_categ = GETPOSTINT("search_categ"); |
||
| 1328 | $search_morphy = GETPOST("search_morphy", 'alpha'); |
||
| 1329 | $search_import_key = trim(GETPOST("search_import_key", 'alpha')); |
||
| 1330 | |||
| 1331 | $catid = GETPOSTINT("catid"); |
||
| 1332 | $socid = GETPOSTINT('socid'); |
||
| 1333 | |||
| 1334 | $search_filter = GETPOST("search_filter", 'alpha'); |
||
| 1335 | $search_status = GETPOST("search_status", 'intcomma'); // status |
||
| 1336 | $search_datec_start = dol_mktime(0, 0, 0, GETPOSTINT('search_datec_start_month'), GETPOSTINT('search_datec_start_day'), GETPOSTINT('search_datec_start_year')); |
||
| 1337 | $search_datec_end = dol_mktime(23, 59, 59, GETPOSTINT('search_datec_end_month'), GETPOSTINT('search_datec_end_day'), GETPOSTINT('search_datec_end_year')); |
||
| 1338 | $search_datem_start = dol_mktime(0, 0, 0, GETPOSTINT('search_datem_start_month'), GETPOSTINT('search_datem_start_day'), GETPOSTINT('search_datem_start_year')); |
||
| 1339 | $search_datem_end = dol_mktime(23, 59, 59, GETPOSTINT('search_datem_end_month'), GETPOSTINT('search_datem_end_day'), GETPOSTINT('search_datem_end_year')); |
||
| 1340 | |||
| 1341 | $filter = GETPOST("filter", 'alpha'); |
||
| 1342 | if ($filter) { |
||
| 1343 | $search_filter = $filter; // For backward compatibility |
||
| 1344 | } |
||
| 1345 | |||
| 1346 | $statut = GETPOST("statut", 'alpha'); |
||
| 1347 | if ($statut != '') { |
||
| 1348 | $search_status = $statut; // For backward compatibility |
||
| 1349 | } |
||
| 1350 | |||
| 1351 | $search_all = trim((GETPOST('search_all', 'alphanohtml') != '') ? GETPOST('search_all', 'alphanohtml') : GETPOST('sall', 'alphanohtml')); |
||
| 1352 | |||
| 1353 | if ($search_status < -2) { |
||
| 1354 | $search_status = ''; |
||
| 1355 | } |
||
| 1356 | |||
| 1357 | // Pagination parameters |
||
| 1358 | $limit = GETPOSTINT('limit') ? GETPOSTINT('limit') : $conf->liste_limit; |
||
| 1359 | $sortfield = GETPOST('sortfield', 'aZ09comma'); |
||
| 1360 | $sortorder = GETPOST('sortorder', 'aZ09comma'); |
||
| 1361 | $page = GETPOSTISSET('pageplusone') ? (GETPOSTINT('pageplusone') - 1) : GETPOSTINT("page"); |
||
| 1362 | if (empty($page) || $page == -1) { |
||
| 1363 | $page = 0; |
||
| 1364 | } // If $page is not defined, or '' or -1 |
||
| 1365 | $offset = $limit * $page; |
||
| 1366 | $pageprev = $page - 1; |
||
| 1367 | $pagenext = $page + 1; |
||
| 1368 | if (!$sortorder) { |
||
| 1369 | $sortorder = ($filter == 'outofdate' ? "DESC" : "ASC"); |
||
| 1370 | } |
||
| 1371 | if (!$sortfield) { |
||
| 1372 | $sortfield = ($filter == 'outofdate' ? "d.datefin" : "d.lastname"); |
||
| 1373 | } |
||
| 1374 | |||
| 1375 | $object = new Adherent($db); |
||
| 1376 | |||
| 1377 | // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context |
||
| 1378 | $hookmanager->initHooks(['memberlist']); |
||
| 1379 | $extrafields = new ExtraFields($db); |
||
| 1380 | |||
| 1381 | // fetch optionals attributes and labels |
||
| 1382 | $extrafields->fetch_name_optionals_label($object->table_element); |
||
| 1383 | |||
| 1384 | $search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_'); |
||
| 1385 | |||
| 1386 | // List of fields to search into when doing a "search in all" |
||
| 1387 | $fieldstosearchall = [ |
||
| 1388 | 'd.ref' => 'Ref', |
||
| 1389 | 'd.login' => 'Login', |
||
| 1390 | 'd.lastname' => 'Lastname', |
||
| 1391 | 'd.firstname' => 'Firstname', |
||
| 1392 | 'd.societe' => "Company", |
||
| 1393 | 'd.email' => 'EMail', |
||
| 1394 | 'd.address' => 'Address', |
||
| 1395 | 'd.zip' => 'Zip', |
||
| 1396 | 'd.town' => 'Town', |
||
| 1397 | 'd.phone' => "Phone", |
||
| 1398 | 'd.phone_perso' => "PhonePerso", |
||
| 1399 | 'd.phone_mobile' => "PhoneMobile", |
||
| 1400 | 'd.note_public' => 'NotePublic', |
||
| 1401 | 'd.note_private' => 'NotePrivate', |
||
| 1402 | ]; |
||
| 1403 | |||
| 1404 | $arrayfields = [ |
||
| 1405 | 'd.ref' => ['label' => "Ref", 'checked' => 1], |
||
| 1406 | 'd.civility' => ['label' => "Civility", 'checked' => 0], |
||
| 1407 | 'd.lastname' => ['label' => "Lastname", 'checked' => 1], |
||
| 1408 | 'd.firstname' => ['label' => "Firstname", 'checked' => 1], |
||
| 1409 | 'd.gender' => ['label' => "Gender", 'checked' => 0], |
||
| 1410 | 'd.company' => ['label' => "Company", 'checked' => 1, 'position' => 70], |
||
| 1411 | 'd.login' => ['label' => "Login", 'checked' => 1], |
||
| 1412 | 'd.morphy' => ['label' => "MemberNature", 'checked' => 1], |
||
| 1413 | 't.libelle' => ['label' => "Type", 'checked' => 1, 'position' => 55], |
||
| 1414 | 'd.address' => ['label' => "Address", 'checked' => 0], |
||
| 1415 | 'd.zip' => ['label' => "Zip", 'checked' => 0], |
||
| 1416 | 'd.town' => ['label' => "Town", 'checked' => 0], |
||
| 1417 | 'd.phone' => ['label' => "Phone", 'checked' => 0], |
||
| 1418 | 'd.phone_perso' => ['label' => "PhonePerso", 'checked' => 0], |
||
| 1419 | 'd.phone_mobile' => ['label' => "PhoneMobile", 'checked' => 0], |
||
| 1420 | 'd.email' => ['label' => "Email", 'checked' => 1], |
||
| 1421 | 'state.nom' => ['label' => "State", 'checked' => 0, 'position' => 90], |
||
| 1422 | 'country.code_iso' => ['label' => "Country", 'checked' => 0, 'position' => 95], |
||
| 1423 | /*'d.note_public'=>array('label'=>"NotePublic", 'checked'=>0), |
||
| 1424 | 'd.note_private'=>array('label'=>"NotePrivate", 'checked'=>0),*/ |
||
| 1425 | 'd.datefin' => ['label' => "EndSubscription"], |
||
| 1426 | 'd.datec' => ['label' => "DateCreation"], |
||
| 1427 | 'd.birth' => ['label' => "Birthday"], |
||
| 1428 | 'd.tms' => ['label' => "DateModificationShort"], |
||
| 1429 | 'd.statut' => ['label' => "Status"], |
||
| 1430 | 'd.import_key' => ['label' => "ImportId"], |
||
| 1431 | ]; |
||
| 1432 | |||
| 1433 | // Extra fields |
||
| 1434 | include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_list_array_fields.tpl.php'; |
||
| 1435 | |||
| 1436 | $object->fields = dol_sort_array($object->fields, 'position'); |
||
| 1437 | //$arrayfields['anotherfield'] = array('type'=>'integer', 'label'=>'AnotherField', 'checked'=>1, 'enabled'=>1, 'position'=>90, 'csslist'=>'right'); |
||
| 1438 | |||
| 1439 | // Complete array of fields for columns |
||
| 1440 | $tableprefix = 'd'; |
||
| 1441 | foreach ($object->fields as $key => $val) { |
||
| 1442 | if (!array_key_exists($tableprefix . '.' . $key, $arrayfields)) { // Discard record not into $arrayfields |
||
| 1443 | continue; |
||
| 1444 | } |
||
| 1445 | // If $val['visible']==0, then we never show the field |
||
| 1446 | |||
| 1447 | $arrayfields[$tableprefix . '.' . $key] = Fields::getVisibleField($val); |
||
| 1448 | } |
||
| 1449 | $arrayfields = dol_sort_array($arrayfields, 'position'); |
||
| 1450 | //var_dump($arrayfields);exit; |
||
| 1451 | |||
| 1452 | // Security check |
||
| 1453 | $result = restrictedArea($user, 'adherent'); |
||
| 1454 | |||
| 1455 | |||
| 1456 | /* |
||
| 1457 | * Actions |
||
| 1458 | */ |
||
| 1459 | |||
| 1460 | if (GETPOST('cancel', 'alpha')) { |
||
| 1461 | $action = 'list'; |
||
| 1462 | $massaction = ''; |
||
| 1463 | } |
||
| 1464 | if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') { |
||
| 1465 | $massaction = ''; |
||
| 1466 | } |
||
| 1467 | |||
| 1468 | $parameters = ['socid' => isset($socid) ? $socid : null]; |
||
| 1469 | $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks |
||
| 1470 | if ($reshook < 0) { |
||
| 1471 | setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); |
||
| 1472 | } |
||
| 1473 | |||
| 1474 | if (empty($reshook)) { |
||
| 1475 | // Selection of new fields |
||
| 1476 | include DOL_DOCUMENT_ROOT . '/core/actions_changeselectedfields.inc.php'; |
||
| 1477 | |||
| 1478 | // Purge search criteria |
||
| 1479 | if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) { // All tests are required to be compatible with all browsers |
||
| 1480 | $statut = ''; |
||
| 1481 | $filter = ''; |
||
| 1482 | |||
| 1483 | $search = ""; |
||
| 1484 | $search_ref = ""; |
||
| 1485 | $search_lastname = ""; |
||
| 1486 | $search_firstname = ""; |
||
| 1487 | $search_gender = ""; |
||
| 1488 | $search_civility = ""; |
||
| 1489 | $search_login = ""; |
||
| 1490 | $search_company = ""; |
||
| 1491 | $search_type = ""; |
||
| 1492 | $search_email = ""; |
||
| 1493 | $search_address = ""; |
||
| 1494 | $search_zip = ""; |
||
| 1495 | $search_town = ""; |
||
| 1496 | $search_state = ""; |
||
| 1497 | $search_country = ''; |
||
| 1498 | $search_phone = ''; |
||
| 1499 | $search_phone_perso = ''; |
||
| 1500 | $search_phone_mobile = ''; |
||
| 1501 | $search_morphy = ""; |
||
| 1502 | $search_categ = ""; |
||
| 1503 | $search_filter = ""; |
||
| 1504 | $search_status = ""; |
||
| 1505 | $search_import_key = ''; |
||
| 1506 | $catid = ""; |
||
| 1507 | $search_all = ""; |
||
| 1508 | $toselect = []; |
||
| 1509 | $search_datec_start = ''; |
||
| 1510 | $search_datec_end = ''; |
||
| 1511 | $search_datem_start = ''; |
||
| 1512 | $search_datem_end = ''; |
||
| 1513 | $search_array_options = []; |
||
| 1514 | } |
||
| 1515 | |||
| 1516 | // Close |
||
| 1517 | if ($massaction == 'close' && $user->hasRight('adherent', 'creer')) { |
||
| 1518 | $tmpmember = new Adherent($db); |
||
| 1519 | $error = 0; |
||
| 1520 | $nbclose = 0; |
||
| 1521 | |||
| 1522 | $db->begin(); |
||
| 1523 | |||
| 1524 | foreach ($toselect as $idtoclose) { |
||
| 1525 | $tmpmember->fetch($idtoclose); |
||
| 1526 | $result = $tmpmember->resiliate($user); |
||
| 1527 | |||
| 1528 | if ($result < 0 && !count($tmpmember->errors)) { |
||
| 1529 | setEventMessages($tmpmember->error, $tmpmember->errors, 'errors'); |
||
| 1530 | } else { |
||
| 1531 | if ($result > 0) { |
||
| 1532 | $nbclose++; |
||
| 1533 | } |
||
| 1534 | } |
||
| 1535 | } |
||
| 1536 | |||
| 1537 | if (!$error) { |
||
| 1538 | setEventMessages($langs->trans("XMembersClosed", $nbclose), null, 'mesgs'); |
||
| 1539 | |||
| 1540 | $db->commit(); |
||
| 1541 | } else { |
||
| 1542 | $db->rollback(); |
||
| 1543 | } |
||
| 1544 | } |
||
| 1545 | |||
| 1546 | // Create external user |
||
| 1547 | if ($massaction == 'createexternaluser' && $user->hasRight('adherent', 'creer') && $user->hasRight('user', 'user', 'creer')) { |
||
| 1548 | $tmpmember = new Adherent($db); |
||
| 1549 | $error = 0; |
||
| 1550 | $nbcreated = 0; |
||
| 1551 | |||
| 1552 | $db->begin(); |
||
| 1553 | |||
| 1554 | foreach ($toselect as $idtoclose) { |
||
| 1555 | $tmpmember->fetch($idtoclose); |
||
| 1556 | |||
| 1557 | if (!empty($tmpmember->fk_soc)) { |
||
| 1558 | $nuser = new User($db); |
||
| 1559 | $tmpuser = dol_clone($tmpmember); |
||
| 1560 | |||
| 1561 | $result = $nuser->create_from_member($tmpuser, $tmpmember->login); |
||
| 1562 | |||
| 1563 | if ($result < 0 && !count($tmpmember->errors)) { |
||
| 1564 | setEventMessages($tmpmember->error, $tmpmember->errors, 'errors'); |
||
| 1565 | } else { |
||
| 1566 | if ($result > 0) { |
||
| 1567 | $nbcreated++; |
||
| 1568 | } |
||
| 1569 | } |
||
| 1570 | } |
||
| 1571 | } |
||
| 1572 | |||
| 1573 | if (!$error) { |
||
| 1574 | setEventMessages($langs->trans("XExternalUserCreated", $nbcreated), null, 'mesgs'); |
||
| 1575 | |||
| 1576 | $db->commit(); |
||
| 1577 | } else { |
||
| 1578 | $db->rollback(); |
||
| 1579 | } |
||
| 1580 | } |
||
| 1581 | |||
| 1582 | // Create external user |
||
| 1583 | if ($action == 'createsubscription_confirm' && $confirm == "yes" && $user->hasRight('adherent', 'creer')) { |
||
| 1584 | $tmpmember = new Adherent($db); |
||
| 1585 | $adht = new AdherentType($db); |
||
| 1586 | $error = 0; |
||
| 1587 | $nbcreated = 0; |
||
| 1588 | $now = dol_now(); |
||
| 1589 | $amount = price2num(GETPOST('amount', 'alpha')); |
||
| 1590 | $db->begin(); |
||
| 1591 | foreach ($toselect as $id) { |
||
| 1592 | $res = $tmpmember->fetch($id); |
||
| 1593 | if ($res > 0) { |
||
| 1594 | $result = $tmpmember->subscription($now, $amount); |
||
| 1595 | if ($result < 0) { |
||
| 1596 | $error++; |
||
| 1597 | } else { |
||
| 1598 | $nbcreated++; |
||
| 1599 | } |
||
| 1600 | } else { |
||
| 1601 | $error++; |
||
| 1602 | } |
||
| 1603 | } |
||
| 1604 | |||
| 1605 | if (!$error) { |
||
| 1606 | setEventMessages($langs->trans("XSubsriptionCreated", $nbcreated), null, 'mesgs'); |
||
| 1607 | $db->commit(); |
||
| 1608 | } else { |
||
| 1609 | setEventMessages($langs->trans("XSubsriptionError", $error), null, 'mesgs'); |
||
| 1610 | $db->rollback(); |
||
| 1611 | } |
||
| 1612 | } |
||
| 1613 | |||
| 1614 | // Mass actions |
||
| 1615 | $objectclass = 'Adherent'; |
||
| 1616 | $objectlabel = 'Members'; |
||
| 1617 | $permissiontoread = $user->hasRight('adherent', 'lire'); |
||
| 1618 | $permissiontodelete = $user->hasRight('adherent', 'supprimer'); |
||
| 1619 | $permissiontoadd = $user->hasRight('adherent', 'creer'); |
||
| 1620 | $uploaddir = $conf->adherent->dir_output; |
||
| 1621 | include DOL_DOCUMENT_ROOT . '/core/actions_massactions.inc.php'; |
||
| 1622 | } |
||
| 1623 | |||
| 1624 | /* |
||
| 1625 | * View |
||
| 1626 | */ |
||
| 1627 | |||
| 1628 | require_once realpath(BASE_PATH . '/../Dolibarr/Modules/Adherent/Views/list.php'); |
||
| 1629 | |||
| 1630 | $db->close(); |
||
| 1631 | return true; |
||
| 1632 | } |
||
| 1633 | |||
| 1634 | /** |
||
| 1635 | * \file htdocs/adherents/subscription.php |
||
| 1636 | * \ingroup member |
||
| 1637 | * \brief tab for Adding, editing, deleting a member's memberships |
||
| 1638 | */ |
||
| 1639 | public function subscription() |
||
| 1640 | { |
||
| 1641 | global $conf; |
||
| 1642 | global $db; |
||
| 1643 | global $user; |
||
| 1644 | global $hookmanager; |
||
| 1645 | global $user; |
||
| 1646 | global $menumanager; |
||
| 1647 | global $langs; |
||
| 1648 | |||
| 1649 | $langs->loadLangs(["companies", "bills", "members", "users", "mails", 'other']); |
||
| 1650 | |||
| 1651 | $action = GETPOST('action', 'aZ09'); |
||
| 1652 | $confirm = GETPOST('confirm', 'alpha'); |
||
| 1653 | $contextpage = GETPOST('contextpage', 'aZ09'); |
||
| 1654 | $optioncss = GETPOST('optioncss', 'aZ'); // Option for the css output (always '' except when 'print') |
||
| 1655 | |||
| 1656 | $id = GETPOSTINT('rowid') ? GETPOSTINT('rowid') : GETPOSTINT('id'); |
||
| 1657 | $rowid = $id; |
||
| 1658 | $ref = GETPOST('ref', 'alphanohtml'); |
||
| 1659 | $typeid = GETPOSTINT('typeid'); |
||
| 1660 | $cancel = GETPOST('cancel'); |
||
| 1661 | |||
| 1662 | // Load variable for pagination |
||
| 1663 | $limit = GETPOSTINT('limit') ? GETPOSTINT('limit') : $conf->liste_limit; |
||
| 1664 | $sortfield = GETPOST('sortfield', 'aZ09comma'); |
||
| 1665 | $sortorder = GETPOST('sortorder', 'aZ09comma'); |
||
| 1666 | $page = GETPOSTISSET('pageplusone') ? (GETPOSTINT('pageplusone') - 1) : GETPOSTINT("page"); |
||
| 1667 | if (empty($page) || $page == -1) { |
||
| 1668 | $page = 0; |
||
| 1669 | } // If $page is not defined, or '' or -1 |
||
| 1670 | $offset = $limit * $page; |
||
| 1671 | $pageprev = $page - 1; |
||
| 1672 | $pagenext = $page + 1; |
||
| 1673 | |||
| 1674 | // Default sort order (if not yet defined by previous GETPOST) |
||
| 1675 | if (!$sortfield) { |
||
| 1676 | $sortfield = "c.rowid"; |
||
| 1677 | } |
||
| 1678 | if (!$sortorder) { |
||
| 1679 | $sortorder = "DESC"; |
||
| 1680 | } |
||
| 1681 | |||
| 1682 | $object = new Adherent($db); |
||
| 1683 | $extrafields = new ExtraFields($db); |
||
| 1684 | $adht = new AdherentType($db); |
||
| 1685 | |||
| 1686 | // fetch optionals attributes and labels |
||
| 1687 | $extrafields->fetch_name_optionals_label($object->table_element); |
||
| 1688 | |||
| 1689 | $errmsg = ''; |
||
| 1690 | |||
| 1691 | // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context |
||
| 1692 | $hookmanager->initHooks(['subscription']); |
||
| 1693 | |||
| 1694 | |||
| 1695 | $hidedetails = (GETPOSTINT('hidedetails') ? GETPOSTINT('hidedetails') : (getDolGlobalString('MAIN_GENERATE_DOCUMENTS_HIDE_DETAILS') ? 1 : 0)); |
||
| 1696 | $hidedesc = (GETPOSTINT('hidedesc') ? GETPOSTINT('hidedesc') : (getDolGlobalString('MAIN_GENERATE_DOCUMENTS_HIDE_DESC') ? 1 : 0)); |
||
| 1697 | $hideref = (GETPOSTINT('hideref') ? GETPOSTINT('hideref') : (getDolGlobalString('MAIN_GENERATE_DOCUMENTS_HIDE_REF') ? 1 : 0)); |
||
| 1698 | |||
| 1699 | $datefrom = 0; |
||
| 1700 | $dateto = 0; |
||
| 1701 | $paymentdate = -1; |
||
| 1702 | |||
| 1703 | // Fetch object |
||
| 1704 | if ($id > 0 || !empty($ref)) { |
||
| 1705 | // Load member |
||
| 1706 | $result = $object->fetch($id, $ref); |
||
| 1707 | |||
| 1708 | // Define variables to know what current user can do on users |
||
| 1709 | $canadduser = ($user->admin || $user->hasRight("user", "user", "creer")); |
||
| 1710 | // Define variables to know what current user can do on properties of user linked to edited member |
||
| 1711 | if ($object->user_id) { |
||
| 1712 | // $User is the user who edits, $object->user_id is the id of the related user in the edited member |
||
| 1713 | $caneditfielduser = ((($user->id == $object->user_id) && $user->hasRight("user", "self", "creer")) |
||
| 1714 | || (($user->id != $object->user_id) && $user->hasRight("user", "user", "creer"))); |
||
| 1715 | $caneditpassworduser = ((($user->id == $object->user_id) && $user->hasRight("user", "self", "password")) |
||
| 1716 | || (($user->id != $object->user_id) && $user->hasRight("user", "user", "password"))); |
||
| 1717 | } |
||
| 1718 | } |
||
| 1719 | |||
| 1720 | // Define variables to determine what the current user can do on the members |
||
| 1721 | $canaddmember = $user->hasRight('adherent', 'creer'); |
||
| 1722 | // Define variables to determine what the current user can do on the properties of a member |
||
| 1723 | if ($id) { |
||
| 1724 | $caneditfieldmember = $user->hasRight('adherent', 'creer'); |
||
| 1725 | } |
||
| 1726 | |||
| 1727 | // Security check |
||
| 1728 | $result = restrictedArea($user, 'adherent', $object->id, '', '', 'socid', 'rowid', 0); |
||
| 1729 | |||
| 1730 | |||
| 1731 | /* |
||
| 1732 | * Actions |
||
| 1733 | */ |
||
| 1734 | |||
| 1735 | $parameters = []; |
||
| 1736 | $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); |
||
| 1737 | if ($reshook < 0) { |
||
| 1738 | setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); |
||
| 1739 | } |
||
| 1740 | |||
| 1741 | // Create third party from a member |
||
| 1742 | if (empty($reshook) && $action == 'confirm_create_thirdparty' && $confirm == 'yes' && $user->hasRight('societe', 'creer')) { |
||
| 1743 | if ($result > 0) { |
||
| 1744 | // Creation of thirdparty |
||
| 1745 | $company = new Societe($db); |
||
| 1746 | $result = $company->create_from_member($object, GETPOST('companyname', 'alpha'), GETPOST('companyalias', 'alpha'), GETPOST('customercode', 'alpha')); |
||
| 1747 | |||
| 1748 | if ($result < 0) { |
||
| 1749 | $langs->load("errors"); |
||
| 1750 | setEventMessages($company->error, $company->errors, 'errors'); |
||
| 1751 | } else { |
||
| 1752 | $action = 'addsubscription'; |
||
| 1753 | } |
||
| 1754 | } else { |
||
| 1755 | setEventMessages($object->error, $object->errors, 'errors'); |
||
| 1756 | } |
||
| 1757 | } |
||
| 1758 | |||
| 1759 | if (empty($reshook) && $action == 'setuserid' && ($user->hasRight('user', 'self', 'creer') || $user->hasRight('user', 'user', 'creer'))) { |
||
| 1760 | $error = 0; |
||
| 1761 | if (!$user->hasRight('user', 'user', 'creer')) { // If can edit only itself user, we can link to itself only |
||
| 1762 | if (GETPOSTINT("userid") != $user->id && GETPOSTINT("userid") != $object->user_id) { |
||
| 1763 | $error++; |
||
| 1764 | setEventMessages($langs->trans("ErrorUserPermissionAllowsToLinksToItselfOnly"), null, 'errors'); |
||
| 1765 | } |
||
| 1766 | } |
||
| 1767 | |||
| 1768 | if (!$error) { |
||
| 1769 | if (GETPOSTINT("userid") != $object->user_id) { // If link differs from currently in database |
||
| 1770 | $result = $object->setUserId(GETPOSTINT("userid")); |
||
| 1771 | if ($result < 0) { |
||
| 1772 | dol_print_error(null, $object->error); |
||
| 1773 | } |
||
| 1774 | $action = ''; |
||
| 1775 | } |
||
| 1776 | } |
||
| 1777 | } |
||
| 1778 | |||
| 1779 | if (empty($reshook) && $action == 'setsocid') { |
||
| 1780 | $error = 0; |
||
| 1781 | if (!$error) { |
||
| 1782 | if (GETPOSTINT('socid') != $object->fk_soc) { // If link differs from currently in database |
||
| 1783 | $sql = "SELECT rowid FROM " . MAIN_DB_PREFIX . "adherent"; |
||
| 1784 | $sql .= " WHERE fk_soc = '" . GETPOSTINT('socid') . "'"; |
||
| 1785 | $resql = $db->query($sql); |
||
| 1786 | if ($resql) { |
||
| 1787 | $obj = $db->fetch_object($resql); |
||
| 1788 | if ($obj && $obj->rowid > 0) { |
||
| 1789 | $othermember = new Adherent($db); |
||
| 1790 | $othermember->fetch($obj->rowid); |
||
| 1791 | $thirdparty = new Societe($db); |
||
| 1792 | $thirdparty->fetch(GETPOSTINT('socid')); |
||
| 1793 | $error++; |
||
| 1794 | setEventMessages($langs->trans("ErrorMemberIsAlreadyLinkedToThisThirdParty", $othermember->getFullName($langs), $othermember->login, $thirdparty->name), null, 'errors'); |
||
| 1795 | } |
||
| 1796 | } |
||
| 1797 | |||
| 1798 | if (!$error) { |
||
| 1799 | $result = $object->setThirdPartyId(GETPOSTINT('socid')); |
||
| 1800 | if ($result < 0) { |
||
| 1801 | dol_print_error(null, $object->error); |
||
| 1802 | } |
||
| 1803 | $action = ''; |
||
| 1804 | } |
||
| 1805 | } |
||
| 1806 | } |
||
| 1807 | } |
||
| 1808 | |||
| 1809 | if ($user->hasRight('adherent', 'cotisation', 'creer') && $action == 'subscription' && !$cancel) { |
||
| 1810 | $error = 0; |
||
| 1811 | |||
| 1812 | $langs->load("banks"); |
||
| 1813 | |||
| 1814 | $result = $object->fetch($rowid); |
||
| 1815 | $result = $adht->fetch($object->typeid); |
||
| 1816 | |||
| 1817 | // Subscription information |
||
| 1818 | $datesubscription = 0; |
||
| 1819 | $datesubend = 0; |
||
| 1820 | $defaultdelay = !empty($adht->duration_value) ? $adht->duration_value : 1; |
||
| 1821 | $defaultdelayunit = !empty($adht->duration_unit) ? $adht->duration_unit : 'y'; |
||
| 1822 | $paymentdate = ''; // Do not use 0 here, default value is '' that means not filled where 0 means 1970-01-01 |
||
| 1823 | if (GETPOSTINT("reyear") && GETPOSTINT("remonth") && GETPOSTINT("reday")) { |
||
| 1824 | $datesubscription = dol_mktime(0, 0, 0, GETPOSTINT("remonth"), GETPOSTINT("reday"), GETPOSTINT("reyear")); |
||
| 1825 | } |
||
| 1826 | if (GETPOSTINT("endyear") && GETPOSTINT("endmonth") && GETPOSTINT("endday")) { |
||
| 1827 | $datesubend = dol_mktime(0, 0, 0, GETPOSTINT("endmonth"), GETPOSTINT("endday"), GETPOSTINT("endyear")); |
||
| 1828 | } |
||
| 1829 | if (GETPOSTINT("paymentyear") && GETPOSTINT("paymentmonth") && GETPOSTINT("paymentday")) { |
||
| 1830 | $paymentdate = dol_mktime(0, 0, 0, GETPOSTINT("paymentmonth"), GETPOSTINT("paymentday"), GETPOSTINT("paymentyear")); |
||
| 1831 | } |
||
| 1832 | $amount = price2num(GETPOST("subscription", 'alpha')); // Amount of subscription |
||
| 1833 | $label = GETPOST("label"); |
||
| 1834 | |||
| 1835 | // Payment information |
||
| 1836 | $accountid = GETPOSTINT("accountid"); |
||
| 1837 | $operation = GETPOST("operation", "alphanohtml"); // Payment mode |
||
| 1838 | $num_chq = GETPOST("num_chq", "alphanohtml"); |
||
| 1839 | $emetteur_nom = GETPOST("chqemetteur"); |
||
| 1840 | $emetteur_banque = GETPOST("chqbank"); |
||
| 1841 | $option = GETPOST("paymentsave"); |
||
| 1842 | if (empty($option)) { |
||
| 1843 | $option = 'none'; |
||
| 1844 | } |
||
| 1845 | $sendalsoemail = GETPOST("sendmail", 'alpha'); |
||
| 1846 | |||
| 1847 | // Check parameters |
||
| 1848 | if (!$datesubscription) { |
||
| 1849 | $error++; |
||
| 1850 | $langs->load("errors"); |
||
| 1851 | $errmsg = $langs->trans("ErrorBadDateFormat", $langs->transnoentitiesnoconv("DateSubscription")); |
||
| 1852 | setEventMessages($errmsg, null, 'errors'); |
||
| 1853 | $action = 'addsubscription'; |
||
| 1854 | } |
||
| 1855 | if (GETPOST('end') && !$datesubend) { |
||
| 1856 | $error++; |
||
| 1857 | $langs->load("errors"); |
||
| 1858 | $errmsg = $langs->trans("ErrorBadDateFormat", $langs->transnoentitiesnoconv("DateEndSubscription")); |
||
| 1859 | setEventMessages($errmsg, null, 'errors'); |
||
| 1860 | $action = 'addsubscription'; |
||
| 1861 | } |
||
| 1862 | if (!$datesubend) { |
||
| 1863 | $datesubend = dol_time_plus_duree(dol_time_plus_duree($datesubscription, $defaultdelay, $defaultdelayunit), -1, 'd'); |
||
| 1864 | } |
||
| 1865 | if (($option == 'bankviainvoice' || $option == 'bankdirect') && !$paymentdate) { |
||
| 1866 | $error++; |
||
| 1867 | $errmsg = $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("DatePayment")); |
||
| 1868 | setEventMessages($errmsg, null, 'errors'); |
||
| 1869 | $action = 'addsubscription'; |
||
| 1870 | } |
||
| 1871 | |||
| 1872 | // Check if a payment is mandatory or not |
||
| 1873 | if ($adht->subscription) { // Member type need subscriptions |
||
| 1874 | if (!is_numeric($amount)) { |
||
| 1875 | // If field is '' or not a numeric value |
||
| 1876 | $errmsg = $langs->trans("ErrorFieldRequired", $langs->transnoentities("Amount")); |
||
| 1877 | setEventMessages($errmsg, null, 'errors'); |
||
| 1878 | $error++; |
||
| 1879 | $action = 'addsubscription'; |
||
| 1880 | } else { |
||
| 1881 | // If an amount has been provided, we check also fields that becomes mandatory when amount is not null. |
||
| 1882 | if (isModEnabled('bank') && GETPOST("paymentsave") != 'none') { |
||
| 1883 | if (GETPOST("subscription")) { |
||
| 1884 | if (!GETPOST("label")) { |
||
| 1885 | $errmsg = $langs->trans("ErrorFieldRequired", $langs->transnoentities("Label")); |
||
| 1886 | setEventMessages($errmsg, null, 'errors'); |
||
| 1887 | $error++; |
||
| 1888 | $action = 'addsubscription'; |
||
| 1889 | } |
||
| 1890 | if (GETPOST("paymentsave") != 'invoiceonly' && !GETPOST("operation")) { |
||
| 1891 | $errmsg = $langs->trans("ErrorFieldRequired", $langs->transnoentities("PaymentMode")); |
||
| 1892 | setEventMessages($errmsg, null, 'errors'); |
||
| 1893 | $error++; |
||
| 1894 | $action = 'addsubscription'; |
||
| 1895 | } |
||
| 1896 | if (GETPOST("paymentsave") != 'invoiceonly' && !(GETPOSTINT("accountid") > 0)) { |
||
| 1897 | $errmsg = $langs->trans("ErrorFieldRequired", $langs->transnoentities("FinancialAccount")); |
||
| 1898 | setEventMessages($errmsg, null, 'errors'); |
||
| 1899 | $error++; |
||
| 1900 | $action = 'addsubscription'; |
||
| 1901 | } |
||
| 1902 | } else { |
||
| 1903 | if (GETPOSTINT("accountid")) { |
||
| 1904 | $errmsg = $langs->trans("ErrorDoNotProvideAccountsIfNullAmount"); |
||
| 1905 | setEventMessages($errmsg, null, 'errors'); |
||
| 1906 | $error++; |
||
| 1907 | $action = 'addsubscription'; |
||
| 1908 | } |
||
| 1909 | } |
||
| 1910 | } |
||
| 1911 | } |
||
| 1912 | } |
||
| 1913 | |||
| 1914 | // Record the subscription then complementary actions |
||
| 1915 | if (!$error && $action == 'subscription') { |
||
| 1916 | $db->begin(); |
||
| 1917 | |||
| 1918 | // Create subscription |
||
| 1919 | $crowid = $object->subscription($datesubscription, $amount, $accountid, $operation, $label, $num_chq, $emetteur_nom, $emetteur_banque, $datesubend); |
||
| 1920 | if ($crowid <= 0) { |
||
| 1921 | $error++; |
||
| 1922 | $errmsg = $object->error; |
||
| 1923 | setEventMessages($object->error, $object->errors, 'errors'); |
||
| 1924 | } |
||
| 1925 | |||
| 1926 | if (!$error) { |
||
| 1927 | $result = $object->subscriptionComplementaryActions($crowid, $option, $accountid, $datesubscription, $paymentdate, $operation, $label, $amount, $num_chq, $emetteur_nom, $emetteur_banque); |
||
| 1928 | if ($result < 0) { |
||
| 1929 | $error++; |
||
| 1930 | setEventMessages($object->error, $object->errors, 'errors'); |
||
| 1931 | } else { |
||
| 1932 | // If an invoice was created, it is into $object->invoice |
||
| 1933 | } |
||
| 1934 | } |
||
| 1935 | |||
| 1936 | if (!$error) { |
||
| 1937 | $db->commit(); |
||
| 1938 | } else { |
||
| 1939 | $db->rollback(); |
||
| 1940 | $action = 'addsubscription'; |
||
| 1941 | } |
||
| 1942 | |||
| 1943 | if (!$error) { |
||
| 1944 | setEventMessages("SubscriptionRecorded", null, 'mesgs'); |
||
| 1945 | } |
||
| 1946 | |||
| 1947 | // Send email |
||
| 1948 | if (!$error) { |
||
| 1949 | // Send confirmation Email |
||
| 1950 | if ($object->email && $sendalsoemail) { // $object is 'Adherent' |
||
| 1951 | $parameters = [ |
||
| 1952 | 'datesubscription' => $datesubscription, |
||
| 1953 | 'amount' => $amount, |
||
| 1954 | 'ccountid' => $accountid, |
||
| 1955 | 'operation' => $operation, |
||
| 1956 | 'label' => $label, |
||
| 1957 | 'num_chq' => $num_chq, |
||
| 1958 | 'emetteur_nom' => $emetteur_nom, |
||
| 1959 | 'emetteur_banque' => $emetteur_banque, |
||
| 1960 | 'datesubend' => $datesubend, |
||
| 1961 | ]; |
||
| 1962 | $reshook = $hookmanager->executeHooks('sendMail', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks |
||
| 1963 | if ($reshook < 0) { |
||
| 1964 | setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); |
||
| 1965 | } |
||
| 1966 | |||
| 1967 | if (empty($reshook)) { |
||
| 1968 | $subject = ''; |
||
| 1969 | $msg = ''; |
||
| 1970 | |||
| 1971 | // Send subscription email |
||
| 1972 | include_once DOL_DOCUMENT_ROOT . '/core/class/html.formmail.class.php'; |
||
| 1973 | $formmail = new FormMail($db); |
||
| 1974 | // Set output language |
||
| 1975 | $outputlangs = new Translate('', $conf); |
||
| 1976 | $outputlangs->setDefaultLang(empty($object->thirdparty->default_lang) ? $mysoc->default_lang : $object->thirdparty->default_lang); |
||
| 1977 | // Load traductions files required by page |
||
| 1978 | $outputlangs->loadLangs(["main", "members"]); |
||
| 1979 | |||
| 1980 | // Get email content from template |
||
| 1981 | $arraydefaultmessage = null; |
||
| 1982 | $labeltouse = getDolGlobalString('ADHERENT_EMAIL_TEMPLATE_SUBSCRIPTION'); |
||
| 1983 | |||
| 1984 | if (!empty($labeltouse)) { |
||
| 1985 | $arraydefaultmessage = $formmail->getEMailTemplate($db, 'member', $user, $outputlangs, 0, 1, $labeltouse); |
||
| 1986 | } |
||
| 1987 | |||
| 1988 | if (!empty($labeltouse) && is_object($arraydefaultmessage) && $arraydefaultmessage->id > 0) { |
||
| 1989 | $subject = $arraydefaultmessage->topic; |
||
| 1990 | $msg = $arraydefaultmessage->content; |
||
| 1991 | } |
||
| 1992 | |||
| 1993 | $substitutionarray = getCommonSubstitutionArray($outputlangs, 0, null, $object); |
||
| 1994 | complete_substitutions_array($substitutionarray, $outputlangs, $object); |
||
| 1995 | $subjecttosend = make_substitutions($subject, $substitutionarray, $outputlangs); |
||
| 1996 | $texttosend = make_substitutions(dol_concatdesc($msg, $adht->getMailOnSubscription()), $substitutionarray, $outputlangs); |
||
| 1997 | |||
| 1998 | // Attach a file ? |
||
| 1999 | $file = ''; |
||
| 2000 | $listofpaths = []; |
||
| 2001 | $listofnames = []; |
||
| 2002 | $listofmimes = []; |
||
| 2003 | if (is_object($object->invoice) && (!is_object($arraydefaultmessage) || intval($arraydefaultmessage->joinfiles))) { |
||
| 2004 | $invoicediroutput = $conf->facture->dir_output; |
||
| 2005 | $fileparams = dol_most_recent_file($invoicediroutput . '/' . $object->invoice->ref, preg_quote($object->invoice->ref, '/') . '[^\-]+'); |
||
| 2006 | $file = $fileparams['fullname']; |
||
| 2007 | |||
| 2008 | $listofpaths = [$file]; |
||
| 2009 | $listofnames = [basename($file)]; |
||
| 2010 | $listofmimes = [dol_mimetype($file)]; |
||
| 2011 | } |
||
| 2012 | |||
| 2013 | $moreinheader = 'X-Dolibarr-Info: send_an_email by adherents/subscription.php' . "\r\n"; |
||
| 2014 | |||
| 2015 | $result = $object->sendEmail($texttosend, $subjecttosend, $listofpaths, $listofmimes, $listofnames, "", "", 0, -1, '', $moreinheader); |
||
| 2016 | if ($result < 0) { |
||
| 2017 | $errmsg = $object->error; |
||
| 2018 | setEventMessages($object->error, $object->errors, 'errors'); |
||
| 2019 | } else { |
||
| 2020 | setEventMessages($langs->trans("EmailSentToMember", $object->email), null, 'mesgs'); |
||
| 2021 | } |
||
| 2022 | } |
||
| 2023 | } else { |
||
| 2024 | setEventMessages($langs->trans("NoEmailSentToMember"), null, 'mesgs'); |
||
| 2025 | } |
||
| 2026 | } |
||
| 2027 | |||
| 2028 | // Clean some POST vars |
||
| 2029 | if (!$error) { |
||
| 2030 | $_POST["subscription"] = ''; |
||
| 2031 | $_POST["accountid"] = ''; |
||
| 2032 | $_POST["operation"] = ''; |
||
| 2033 | $_POST["label"] = ''; |
||
| 2034 | $_POST["num_chq"] = ''; |
||
| 2035 | } |
||
| 2036 | } |
||
| 2037 | } |
||
| 2038 | |||
| 2039 | |||
| 2040 | /* |
||
| 2041 | * View |
||
| 2042 | */ |
||
| 2043 | |||
| 2044 | require_once realpath(BASE_PATH . '/../Dolibarr/Modules/Adherent/Views/subscription.php'); |
||
| 2045 | |||
| 2046 | $db->close(); |
||
| 2047 | return true; |
||
| 2048 | } |
||
| 2049 | |||
| 2050 | /** |
||
| 2051 | * \file htdocs/adherents/note.php |
||
| 2052 | * \ingroup member |
||
| 2053 | * \brief Tab for note of a member |
||
| 2054 | */ |
||
| 2055 | public function note() |
||
| 2056 | { |
||
| 2057 | global $conf; |
||
| 2058 | global $db; |
||
| 2059 | global $user; |
||
| 2060 | global $hookmanager; |
||
| 2061 | global $user; |
||
| 2062 | global $menumanager; |
||
| 2063 | global $langs; |
||
| 2064 | |||
| 2065 | // Load translation files required by the page |
||
| 2066 | $langs->loadLangs(["companies", "members", "bills"]); |
||
| 2067 | |||
| 2068 | |||
| 2069 | // Get parameters |
||
| 2070 | $action = GETPOST('action', 'aZ09'); |
||
| 2071 | $id = GETPOSTINT('id'); |
||
| 2072 | $ref = GETPOST('ref', 'alphanohtml'); |
||
| 2073 | |||
| 2074 | |||
| 2075 | // Initialize objects |
||
| 2076 | $object = new Adherent($db); |
||
| 2077 | |||
| 2078 | $result = $object->fetch($id); |
||
| 2079 | if ($result > 0) { |
||
| 2080 | $adht = new AdherentType($db); |
||
| 2081 | $result = $adht->fetch($object->typeid); |
||
| 2082 | } |
||
| 2083 | |||
| 2084 | |||
| 2085 | $permissionnote = $user->hasRight('adherent', 'creer'); // Used by the include of actions_setnotes.inc.php |
||
| 2086 | |||
| 2087 | // Fetch object |
||
| 2088 | if ($id > 0 || !empty($ref)) { |
||
| 2089 | // Load member |
||
| 2090 | $result = $object->fetch($id, $ref); |
||
| 2091 | |||
| 2092 | // Define variables to know what current user can do on users |
||
| 2093 | $canadduser = ($user->admin || $user->hasRight('user', 'user', 'creer')); |
||
| 2094 | // Define variables to know what current user can do on properties of user linked to edited member |
||
| 2095 | if ($object->user_id) { |
||
| 2096 | // $User is the user who edits, $object->user_id is the id of the related user in the edited member |
||
| 2097 | $caneditfielduser = ((($user->id == $object->user_id) && $user->hasRight('user', 'self', 'creer')) |
||
| 2098 | || (($user->id != $object->user_id) && $user->hasRight('user', 'user', 'creer'))); |
||
| 2099 | $caneditpassworduser = ((($user->id == $object->user_id) && $user->hasRight('user', 'self', 'password')) |
||
| 2100 | || (($user->id != $object->user_id) && $user->hasRight('user', 'user', 'password'))); |
||
| 2101 | } |
||
| 2102 | } |
||
| 2103 | |||
| 2104 | // Define variables to determine what the current user can do on the members |
||
| 2105 | $canaddmember = $user->hasRight('adherent', 'creer'); |
||
| 2106 | // Define variables to determine what the current user can do on the properties of a member |
||
| 2107 | if ($id) { |
||
| 2108 | $caneditfieldmember = $user->hasRight('adherent', 'creer'); |
||
| 2109 | } |
||
| 2110 | |||
| 2111 | $hookmanager->initHooks(['membernote']); |
||
| 2112 | |||
| 2113 | // Security check |
||
| 2114 | $result = restrictedArea($user, 'adherent', $object->id, '', '', 'socid', 'rowid', 0); |
||
| 2115 | |||
| 2116 | /* |
||
| 2117 | * Actions |
||
| 2118 | */ |
||
| 2119 | $parameters = []; |
||
| 2120 | $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks |
||
| 2121 | if ($reshook < 0) { |
||
| 2122 | setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); |
||
| 2123 | } |
||
| 2124 | if (empty($reshook)) { |
||
| 2125 | include DOL_DOCUMENT_ROOT . '/core/actions_setnotes.inc.php'; // Must be include, not include_once |
||
| 2126 | } |
||
| 2127 | |||
| 2128 | /* |
||
| 2129 | * View |
||
| 2130 | */ |
||
| 2131 | |||
| 2132 | require_once realpath(BASE_PATH . '/../Dolibarr/Modules/Adherent/Views/note.php'); |
||
| 2133 | |||
| 2134 | $title = $langs->trans("Member") . " - " . $langs->trans("Note"); |
||
| 2135 | |||
| 2136 | $help_url = "EN:Module_Foundations|FR:Module_Adhérents|ES:Módulo_Miembros|DE:Modul_Mitglieder"; |
||
| 2137 | |||
| 2138 | llxHeader("", $title, $help_url); |
||
| 2139 | |||
| 2140 | $form = new Form($db); |
||
| 2141 | |||
| 2142 | if ($id) { |
||
| 2143 | $head = member_prepare_head($object); |
||
| 2144 | |||
| 2145 | print dol_get_fiche_head($head, 'note', $langs->trans("Member"), -1, 'user'); |
||
| 2146 | |||
| 2147 | print '<form method="POST" action="' . $_SERVER['PHP_SELF'] . '">'; |
||
| 2148 | print '<input type="hidden" name="token" value="' . newToken() . '">'; |
||
| 2149 | |||
| 2150 | $linkback = '<a href="' . DOL_URL_ROOT . '/adherents/list.php?restore_lastsearch_values=1">' . $langs->trans("BackToList") . '</a>'; |
||
| 2151 | |||
| 2152 | $morehtmlref = '<a href="' . DOL_URL_ROOT . '/adherents/vcard.php?id=' . $object->id . '" class="refid">'; |
||
| 2153 | $morehtmlref .= img_picto($langs->trans("Download") . ' ' . $langs->trans("VCard"), 'vcard.png', 'class="valignmiddle marginleftonly paddingrightonly"'); |
||
| 2154 | $morehtmlref .= '</a>'; |
||
| 2155 | |||
| 2156 | dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'ref', $morehtmlref); |
||
| 2157 | |||
| 2158 | print '<div class="fichecenter">'; |
||
| 2159 | |||
| 2160 | print '<div class="underbanner clearboth"></div>'; |
||
| 2161 | print '<table class="border centpercent tableforfield">'; |
||
| 2162 | |||
| 2163 | // Login |
||
| 2164 | if (!getDolGlobalString('ADHERENT_LOGIN_NOT_REQUIRED')) { |
||
| 2165 | print '<tr><td class="titlefield">' . $langs->trans("Login") . ' / ' . $langs->trans("Id") . '</td><td class="valeur">' . dol_escape_htmltag($object->login) . '</td></tr>'; |
||
| 2166 | } |
||
| 2167 | |||
| 2168 | // Type |
||
| 2169 | print '<tr><td>' . $langs->trans("Type") . '</td>'; |
||
| 2170 | print '<td class="valeur">' . $adht->getNomUrl(1) . "</td></tr>\n"; |
||
| 2171 | |||
| 2172 | // Morphy |
||
| 2173 | print '<tr><td class="titlefield">' . $langs->trans("MemberNature") . '</td>'; |
||
| 2174 | print '<td class="valeur" >' . $object->getmorphylib('', 1) . '</td>'; |
||
| 2175 | print '</tr>'; |
||
| 2176 | |||
| 2177 | // Company |
||
| 2178 | print '<tr><td>' . $langs->trans("Company") . '</td><td class="valeur">' . dol_escape_htmltag($object->company) . '</td></tr>'; |
||
| 2179 | |||
| 2180 | // Civility |
||
| 2181 | print '<tr><td>' . $langs->trans("UserTitle") . '</td><td class="valeur">' . $object->getCivilityLabel() . '</td>'; |
||
| 2182 | print '</tr>'; |
||
| 2183 | |||
| 2184 | print "</table>"; |
||
| 2185 | |||
| 2186 | print '</div>'; |
||
| 2187 | |||
| 2188 | |||
| 2189 | $cssclass = 'titlefield'; |
||
| 2190 | $permission = $user->hasRight('adherent', 'creer'); // Used by the include of notes.tpl.php |
||
| 2191 | include DOL_DOCUMENT_ROOT . '/core/tpl/notes.tpl.php'; |
||
| 2192 | |||
| 2193 | |||
| 2194 | print dol_get_fiche_end(); |
||
| 2195 | } |
||
| 2196 | |||
| 2197 | // End of page |
||
| 2198 | llxFooter(); |
||
| 2199 | $db->close(); |
||
| 2200 | return true; |
||
| 2201 | } |
||
| 2202 | |||
| 2203 | /** |
||
| 2204 | * \file partnership_card.php |
||
| 2205 | * \ingroup partnership |
||
| 2206 | * \brief Page to create/edit/view partnership |
||
| 2207 | */ |
||
| 2208 | public function partnership() |
||
| 2329 | } |
||
| 2330 | |||
| 2331 | /** |
||
| 2332 | * \file htdocs/adherents/type_ldap.php |
||
| 2333 | * \ingroup ldap |
||
| 2334 | * \brief Page fiche LDAP members types |
||
| 2335 | */ |
||
| 2336 | public function type_ldap() |
||
| 2337 | { |
||
| 2338 | global $conf; |
||
| 2339 | global $db; |
||
| 2340 | global $user; |
||
| 2341 | global $hookmanager; |
||
| 2342 | global $user; |
||
| 2343 | global $menumanager; |
||
| 2344 | global $langs; |
||
| 2345 | |||
| 2346 | // Load translation files required by the page |
||
| 2347 | $langs->loadLangs(["admin", "members", "ldap"]); |
||
| 2348 | |||
| 2349 | $id = GETPOSTINT('rowid'); |
||
| 2350 | $action = GETPOST('action', 'aZ09'); |
||
| 2351 | |||
| 2352 | // Security check |
||
| 2353 | $result = restrictedArea($user, 'adherent', $id, 'adherent_type'); |
||
| 2354 | |||
| 2355 | $object = new AdherentType($db); |
||
| 2356 | $object->fetch($id); |
||
| 2357 | |||
| 2358 | // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context |
||
| 2359 | $hookmanager->initHooks(['membertypeldapcard', 'globalcard']); |
||
| 2360 | |||
| 2361 | /* |
||
| 2362 | * Actions |
||
| 2363 | */ |
||
| 2364 | |||
| 2365 | |||
| 2366 | $parameters = []; |
||
| 2367 | $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks |
||
| 2368 | if ($reshook < 0) { |
||
| 2369 | setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); |
||
| 2370 | } |
||
| 2371 | |||
| 2372 | if (empty($reshook)) { |
||
| 2373 | if ($action == 'dolibarr2ldap') { |
||
| 2374 | $ldap = new Ldap(); |
||
| 2375 | $result = $ldap->connectBind(); |
||
| 2376 | |||
| 2377 | if ($result > 0) { |
||
| 2378 | $object->listMembersForMemberType('', 1); |
||
| 2379 | |||
| 2380 | $info = $object->_load_ldap_info(); |
||
| 2381 | $dn = $object->_load_ldap_dn($info); |
||
| 2382 | $olddn = $dn; // We can say that old dn = dn as we force synchro |
||
| 2383 | |||
| 2384 | $result = $ldap->update($dn, $info, $user, $olddn); |
||
| 2385 | } |
||
| 2386 | |||
| 2387 | if ($result >= 0) { |
||
| 2388 | setEventMessages($langs->trans("MemberTypeSynchronized"), null, 'mesgs'); |
||
| 2389 | } else { |
||
| 2390 | setEventMessages($ldap->error, $ldap->errors, 'errors'); |
||
| 2391 | } |
||
| 2392 | } |
||
| 2393 | } |
||
| 2394 | |||
| 2395 | /* |
||
| 2396 | * View |
||
| 2397 | */ |
||
| 2398 | |||
| 2399 | require_once realpath(BASE_PATH . '/../Dolibarr/Modules/Adherent/Views/type_ldap.php'); |
||
| 2400 | |||
| 2401 | $db->close(); |
||
| 2402 | return true; |
||
| 2403 | } |
||
| 2404 | |||
| 2405 | /** |
||
| 2406 | * \file htdocs/adherents/type_translation.php |
||
| 2407 | * \ingroup product |
||
| 2408 | * \brief Member translation page |
||
| 2409 | */ |
||
| 2410 | public function type_translation() |
||
| 2538 | } |
||
| 2539 | |||
| 2540 | /** |
||
| 2541 | * \file htdocs/adherents/vcard.php |
||
| 2542 | * \ingroup societe |
||
| 2543 | * \brief Vcard tab of a member |
||
| 2544 | */ |
||
| 2545 | public function vcard() |
||
| 2599 | } |
||
| 2600 | } |
||
| 2601 |