12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679 |
- <?php
- /* Copyright (C) 2001-2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
- * Copyright (C) 2002-2003 Jean-Louis Bergamo <jlb@j1b.org>
- * Copyright (C) 2004-2012 Laurent Destailleur <eldy@users.sourceforge.net>
- * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@capnetworks.com>
- * Copyright (C) 2012 Marcos García <marcosgdf@gmail.com>
- * Copyright (C) 2012-2013 Philippe Grand <philippe.grand@atoo-net.com>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
- /**
- * \file htdocs/adherents/card.php
- * \ingroup member
- * \brief Page of member
- */
- require '../main.inc.php';
- require_once DOL_DOCUMENT_ROOT.'/core/lib/member.lib.php';
- require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
- require_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php';
- require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
- require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
- require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent_type.class.php';
- require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
- require_once DOL_DOCUMENT_ROOT.'/adherents/class/cotisation.class.php';
- require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
- require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
- $langs->load("companies");
- $langs->load("bills");
- $langs->load("members");
- $langs->load("users");
- $langs->load('other');
- $action=GETPOST('action','alpha');
- $backtopage=GETPOST('backtopage','alpha');
- $confirm=GETPOST('confirm','alpha');
- $rowid=GETPOST('rowid','int');
- $typeid=GETPOST('typeid','int');
- $userid=GETPOST('userid','int');
- $socid=GETPOST('socid','int');
- if (! empty($conf->mailmanspip->enabled))
- {
- include_once DOL_DOCUMENT_ROOT.'/mailmanspip/class/mailmanspip.class.php';
- $langs->load('mailmanspip');
- $mailmanspip = new MailmanSpip($db);
- }
- $object = new Adherent($db);
- $extrafields = new ExtraFields($db);
- // fetch optionals attributes and labels
- $extralabels=$extrafields->fetch_name_optionals_label($object->table_element);
- // Get object canvas (By default, this is not defined, so standard usage of dolibarr)
- $object->getCanvas($rowid);
- $canvas = $object->canvas?$object->canvas:GETPOST("canvas");
- $objcanvas='';
- if (! empty($canvas))
- {
- require_once DOL_DOCUMENT_ROOT.'/core/class/canvas.class.php';
- $objcanvas = new Canvas($db, $action);
- $objcanvas->getCanvas('adherent', 'membercard', $canvas);
- }
- // Security check
- $result=restrictedArea($user,'adherent',$rowid,'','','fk_soc', 'rowid', $objcanvas);
- if ($rowid > 0)
- {
- // Load member
- $result = $object->fetch($rowid);
- // Define variables to know what current user can do on users
- $canadduser=($user->admin || $user->rights->user->user->creer);
- // Define variables to know what current user can do on properties of user linked to edited member
- if ($object->user_id)
- {
- // $user est le user qui edite, $object->user_id est l'id de l'utilisateur lies au membre edite
- $caneditfielduser=((($user->id == $object->user_id) && $user->rights->user->self->creer)
- || (($user->id != $object->user_id) && $user->rights->user->user->creer));
- $caneditpassworduser=((($user->id == $object->user_id) && $user->rights->user->self->password)
- || (($user->id != $object->user_id) && $user->rights->user->user->password));
- }
- }
- // Define variables to determine what the current user can do on the members
- $canaddmember=$user->rights->adherent->creer;
- // Define variables to determine what the current user can do on the properties of a member
- if ($rowid)
- {
- $caneditfieldmember=$user->rights->adherent->creer;
- }
- // Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array
- $hookmanager->initHooks(array('membercard','globalcard'));
- /*
- * Actions
- */
- $parameters=array('rowid'=>$rowid, 'objcanvas'=>$objcanvas);
- $reshook=$hookmanager->executeHooks('doActions',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
- if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
- if ($action == 'setuserid' && ($user->rights->user->self->creer || $user->rights->user->user->creer))
- {
- $error=0;
- if (empty($user->rights->user->user->creer)) // If can edit only itself user, we can link to itself only
- {
- if ($userid != $user->id && $userid != $object->user_id)
- {
- $error++;
- setEventMessage($langs->trans("ErrorUserPermissionAllowsToLinksToItselfOnly"), 'errors');
- }
- }
- if (! $error)
- {
- if ($userid != $object->user_id) // If link differs from currently in database
- {
- $result=$object->setUserId($userid);
- if ($result < 0) dol_print_error($object->db,$object->error);
- $action='';
- }
- }
- }
- if ($action == 'setsocid')
- {
- $error=0;
- if (! $error)
- {
- if ($socid != $object->fk_soc) // If link differs from currently in database
- {
- $sql ="SELECT rowid FROM ".MAIN_DB_PREFIX."adherent";
- $sql.=" WHERE fk_soc = '".$socid."'";
- $sql.=" AND entity = ".$conf->entity;
- $resql = $db->query($sql);
- if ($resql)
- {
- $obj = $db->fetch_object($resql);
- if ($obj && $obj->rowid > 0)
- {
- $othermember=new Adherent($db);
- $othermember->fetch($obj->rowid);
- $thirdparty=new Societe($db);
- $thirdparty->fetch($socid);
- $error++;
- setEventMessage($langs->trans("ErrorMemberIsAlreadyLinkedToThisThirdParty",$othermember->getFullName($langs),$othermember->login,$thirdparty->name), 'errors');
- }
- }
- if (! $error)
- {
- $result=$object->setThirdPartyId($socid);
- if ($result < 0) dol_print_error($object->db,$object->error);
- $action='';
- }
- }
- }
- }
- // Create user from a member
- if ($action == 'confirm_create_user' && $confirm == 'yes' && $user->rights->user->user->creer)
- {
- if ($result > 0)
- {
- // Creation user
- $nuser = new User($db);
- $result=$nuser->create_from_member($object,GETPOST('login'));
- if ($result < 0)
- {
- $langs->load("errors");
- setEventMessage($langs->trans($nuser->error), 'errors');
- }
- }
- else
- {
- setEventMessage($object->error, 'errors');
- }
- }
- // Create third party from a member
- if ($action == 'confirm_create_thirdparty' && $confirm == 'yes' && $user->rights->societe->creer)
- {
- if ($result > 0)
- {
- // Creation user
- $company = new Societe($db);
- $result=$company->create_from_member($object,GETPOST('companyname'));
- if ($result < 0)
- {
- $langs->load("errors");
- setEventMessage($langs->trans($company->error), 'errors');
- setEventMessage($company->errors, 'errors');
- }
- }
- else
- {
- setEventMessage($object->error, 'errors');
- }
- }
- if ($action == 'confirm_sendinfo' && $confirm == 'yes')
- {
- if ($object->email)
- {
- $from=$conf->email_from;
- if (! empty($conf->global->ADHERENT_MAIL_FROM)) $from=$conf->global->ADHERENT_MAIL_FROM;
- $result=$object->send_an_email($langs->transnoentitiesnoconv("ThisIsContentOfYourCard")."\n\n%INFOS%\n\n",$langs->transnoentitiesnoconv("CardContent"));
- $langs->load("mails");
- setEventMessage($langs->trans("MailSuccessfulySent", $from, $object->email));
- }
- }
- if ($action == 'update' && ! $_POST["cancel"] && $user->rights->adherent->creer)
- {
- require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
- $birthdate='';
- if (isset($_POST["birthday"]) && $_POST["birthday"]
- && isset($_POST["birthmonth"]) && $_POST["birthmonth"]
- && isset($_POST["birthyear"]) && $_POST["birthyear"])
- {
- $birthdate=dol_mktime(12, 0, 0, $_POST["birthmonth"], $_POST["birthday"], $_POST["birthyear"]);
- }
- $lastname=$_POST["lastname"];
- $firstname=$_POST["firstname"];
- $morphy=$morphy=$_POST["morphy"];;
- if ($morphy != 'mor' && empty($lastname)) {
- $error++;
- $langs->load("errors");
- setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentities("Lastname")), 'errors');
- }
- if ($morphy != 'mor' && (!isset($firstname) || $firstname=='')) {
- $error++;
- $langs->load("errors");
- setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentities("Firstname")), 'errors');
- }
- // Create new object
- if ($result > 0 && ! $error)
- {
- $object->oldcopy=dol_clone($object);
- // Change values
- $object->civility_id = trim($_POST["civility_id"]);
- $object->firstname = trim($_POST["firstname"]);
- $object->lastname = trim($_POST["lastname"]);
- $object->login = trim($_POST["login"]);
- $object->pass = trim($_POST["pass"]);
- $object->societe = trim($_POST["societe"]);
- $object->company = trim($_POST["societe"]);
- $object->address = trim($_POST["address"]);
- $object->zip = trim($_POST["zipcode"]);
- $object->town = trim($_POST["town"]);
- $object->state_id = $_POST["state_id"];
- $object->country_id = $_POST["country_id"];
- $object->phone = trim($_POST["phone"]);
- $object->phone_perso = trim($_POST["phone_perso"]);
- $object->phone_mobile= trim($_POST["phone_mobile"]);
- $object->email = trim($_POST["email"]);
- $object->skype = trim($_POST["skype"]);
- $object->birth = $birthdate;
- $object->typeid = $_POST["typeid"];
- //$object->note = trim($_POST["comment"]);
- $object->morphy = $_POST["morphy"];
- $object->amount = $_POST["amount"];
- if (GETPOST('deletephoto')) $object->photo='';
- elseif (! empty($_FILES['photo']['name'])) $object->photo = dol_sanitizeFileName($_FILES['photo']['name']);
- // Get status and public property
- $object->statut = $_POST["statut"];
- $object->public = $_POST["public"];
- // Fill array 'array_options' with data from add form
- $ret = $extrafields->setOptionalsFromPost($extralabels,$object);
- // Check if we need to also synchronize user information
- $nosyncuser=0;
- if ($object->user_id) // If linked to a user
- {
- if ($user->id != $object->user_id && empty($user->rights->user->user->creer)) $nosyncuser=1; // Disable synchronizing
- }
- // Check if we need to also synchronize password information
- $nosyncuserpass=0;
- if ($object->user_id) // If linked to a user
- {
- if ($user->id != $object->user_id && empty($user->rights->user->user->password)) $nosyncuserpass=1; // Disable synchronizing
- }
- $result=$object->update($user,0,$nosyncuser,$nosyncuserpass);
- if ($result >= 0 && ! count($object->errors))
- {
- // Logo/Photo save
- $dir= $conf->adherent->dir_output . '/' . get_exdir($object->id,2,0,1).'/photos';
- $file_OK = is_uploaded_file($_FILES['photo']['tmp_name']);
- if ($file_OK)
- {
- if (GETPOST('deletephoto'))
- {
- require_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php';
- $fileimg=$conf->adherent->dir_output.'/'.get_exdir($object->id,2,0,1).'/photos/'.$object->photo;
- $dirthumbs=$conf->adherent->dir_output.'/'.get_exdir($object->id,2,0,1).'/photos/thumbs';
- dol_delete_file($fileimg);
- dol_delete_dir_recursive($dirthumbs);
- }
- if (image_format_supported($_FILES['photo']['name']) > 0)
- {
- dol_mkdir($dir);
- if (@is_dir($dir))
- {
- $newfile=$dir.'/'.dol_sanitizeFileName($_FILES['photo']['name']);
- if (! dol_move_uploaded_file($_FILES['photo']['tmp_name'],$newfile,1,0,$_FILES['photo']['error']) > 0)
- {
- setEventMessage($langs->trans("ErrorFailedToSaveFile"), 'errors');
- }
- else
- {
- // Create small thumbs for company (Ratio is near 16/9)
- // Used on logon for example
- $imgThumbSmall = vignette($newfile, $maxwidthsmall, $maxheightsmall, '_small', $quality);
- // Create mini thumbs for company (Ratio is near 16/9)
- // Used on menu or for setup page for example
- $imgThumbMini = vignette($newfile, $maxwidthmini, $maxheightmini, '_mini', $quality);
- }
- }
- }
- else
- {
- setEventMessage("ErrorBadImageFormat", 'errors');
- }
- }
- else
- {
- switch($_FILES['photo']['error'])
- {
- case 1: //uploaded file exceeds the upload_max_filesize directive in php.ini
- case 2: //uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the html form
- $errors[] = "ErrorFileSizeTooLarge";
- break;
- case 3: //uploaded file was only partially uploaded
- $errors[] = "ErrorFilePartiallyUploaded";
- break;
- }
- }
- $rowid=$object->id;
- $action='';
- if (! empty($backtopage))
- {
- header("Location: ".$backtopage);
- exit;
- }
- }
- else
- {
- if ($object->error) {
- setEventMessage($object->error, 'errors');
- } else {
- setEventMessage($object->errors, 'errors');
- }
- $action='';
- }
- }
- else
- {
- $action='edit';
- }
- }
- if ($action == 'add' && $user->rights->adherent->creer)
- {
- if ($canvas) $object->canvas=$canvas;
- $birthdate='';
- if (isset($_POST["birthday"]) && $_POST["birthday"]
- && isset($_POST["birthmonth"]) && $_POST["birthmonth"]
- && isset($_POST["birthyear"]) && $_POST["birthyear"])
- {
- $birthdate=dol_mktime(12, 0, 0, $_POST["birthmonth"], $_POST["birthday"], $_POST["birthyear"]);
- }
- $datecotisation='';
- if (isset($_POST["reday"]) && isset($_POST["remonth"]) && isset($_POST["reyear"]))
- {
- $datecotisation=dol_mktime(12, 0, 0, $_POST["remonth"], $_POST["reday"], $_POST["reyear"]);
- }
- $typeid=$_POST["typeid"];
- $civility_id=$_POST["civility_id"];
- $lastname=$_POST["lastname"];
- $firstname=$_POST["firstname"];
- $societe=$_POST["societe"];
- $address=$_POST["address"];
- $zip=$_POST["zipcode"];
- $town=$_POST["town"];
- $state_id=$_POST["state_id"];
- $country_id=$_POST["country_id"];
- $phone=$_POST["phone"];
- $phone_perso=$_POST["phone_perso"];
- $phone_mobile=$_POST["phone_mobile"];
- $skype=$_POST["member_skype"];
- $email=$_POST["member_email"];
- $login=$_POST["member_login"];
- $pass=$_POST["password"];
- $photo=$_POST["photo"];
- //$comment=$_POST["comment"];
- $morphy=$_POST["morphy"];
- $cotisation=$_POST["cotisation"];
- $public=$_POST["public"];
- $userid=$_POST["userid"];
- $socid=$_POST["socid"];
- $object->civility_id = $civility_id;
- $object->firstname = $firstname;
- $object->lastname = $lastname;
- $object->societe = $societe;
- $object->address = $address;
- $object->zip = $zip;
- $object->town = $town;
- $object->state_id = $state_id;
- $object->country_id = $country_id;
- $object->phone = $phone;
- $object->phone_perso = $phone_perso;
- $object->phone_mobile= $phone_mobile;
- $object->skype = $skype;
- $object->email = $email;
- $object->login = $login;
- $object->pass = $pass;
- $object->birth = $birthdate;
- $object->photo = $photo;
- $object->typeid = $typeid;
- //$object->note = $comment;
- $object->morphy = $morphy;
- $object->user_id = $userid;
- $object->fk_soc = $socid;
- $object->public = $public;
- // Fill array 'array_options' with data from add form
- $ret = $extrafields->setOptionalsFromPost($extralabels,$object);
- // Check parameters
- if (empty($morphy) || $morphy == "-1") {
- $error++;
- setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Nature")), 'errors');
- }
- // Test si le login existe deja
- if (empty($conf->global->ADHERENT_LOGIN_NOT_REQUIRED))
- {
- if (empty($login)) {
- $error++;
- setEventMessage($langs->trans("ErrorFieldRequired",$langs->trans("Login")), 'errors');
- }
- else {
- $sql = "SELECT login FROM ".MAIN_DB_PREFIX."adherent WHERE login='".$db->escape($login)."'";
- $result = $db->query($sql);
- if ($result) {
- $num = $db->num_rows($result);
- }
- if ($num) {
- $error++;
- $langs->load("errors");
- setEventMessage($langs->trans("ErrorLoginAlreadyExists",$login), 'errors');
- }
- }
- if (empty($pass)) {
- $error++;
- setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentities("Password")), 'errors');
- }
- }
- if ($morphy != 'mor' && empty($lastname)) {
- $error++;
- $langs->load("errors");
- setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentities("Lastname")), 'errors');
- }
- if ($morphy != 'mor' && (!isset($firstname) || $firstname=='')) {
- $error++;
- $langs->load("errors");
- setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentities("Firstname")), 'errors');
- }
- if (! ($typeid > 0)) { // Keep () before !
- $error++;
- setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Type")), 'errors');
- }
- if ($conf->global->ADHERENT_MAIL_REQUIRED && ! isValidEMail($email)) {
- $error++;
- $langs->load("errors");
- setEventMessage($langs->trans("ErrorBadEMail",$email), 'errors');
- }
- $public=0;
- if (isset($public)) $public=1;
- if (! $error)
- {
- $db->begin();
- // Email a peu pres correct et le login n'existe pas
- $result=$object->create($user);
- if ($result > 0)
- {
- $db->commit();
- $rowid=$object->id;
- $action='';
- }
- else
- {
- $db->rollback();
- if ($object->error) {
- setEventMessage($object->error, 'errors');
- } else {
- setEventMessage($object->errors, 'errors');
- }
- $action = 'create';
- }
- }
- else {
- $action = 'create';
- }
- }
- if ($user->rights->adherent->supprimer && $action == 'confirm_delete' && $confirm == 'yes')
- {
- $result=$object->delete($rowid);
- if ($result > 0)
- {
- if (! empty($backtopage))
- {
- header("Location: ".$backtopage);
- exit;
- }
- else
- {
- header("Location: list.php");
- exit;
- }
- }
- else
- {
- $errmesg=$object->error;
- }
- }
- if ($user->rights->adherent->creer && $action == 'confirm_valid' && $confirm == 'yes')
- {
- $error=0;
- $db->begin();
- $adht = new AdherentType($db);
- $adht->fetch($object->typeid);
- $result=$object->validate($user);
- if ($result >= 0 && ! count($object->errors))
- {
- // Send confirmation Email (selon param du type adherent sinon generique)
- if ($object->email && GETPOST("send_mail"))
- {
- $result=$object->send_an_email($adht->getMailOnValid(),$conf->global->ADHERENT_MAIL_VALID_SUBJECT,array(),array(),array(),"","",0,2);
- if ($result < 0)
- {
- $error++;
- setEventMessage($object->error, 'errors');
- }
- }
- }
- else
- {
- $error++;
- if ($object->error) {
- setEventMessage($object->error, 'errors');
- } else {
- setEventMessage($object->errors, 'errors');
- }
- }
- if (! $error)
- {
- $db->commit();
- }
- else
- {
- $db->rollback();
- }
- $action='';
- }
- if ($user->rights->adherent->supprimer && $action == 'confirm_resign')
- {
- $error = 0;
- if ($confirm == 'yes')
- {
- $adht = new AdherentType($db);
- $adht->fetch($object->typeid);
- $result=$object->resiliate($user);
- if ($result >= 0 && ! count($object->errors))
- {
- if ($object->email && GETPOST("send_mail"))
- {
- $result=$object->send_an_email($adht->getMailOnResiliate(),$conf->global->ADHERENT_MAIL_RESIL_SUBJECT,array(),array(),array(),"","",0,-1);
- }
- if ($result < 0)
- {
- $error++;
- setEventMessage($object->error, 'errors');
- }
- }
- else
- {
- $error++;
- if ($object->error) {
- setEventMessage($object->error, 'errors');
- } else {
- setEventMessage($object->errors, 'errors');
- }
- $action='';
- }
- }
- if (! empty($backtopage) && ! $error)
- {
- header("Location: ".$backtopage);
- exit;
- }
- }
- // SPIP Management
- if ($user->rights->adherent->supprimer && $action == 'confirm_del_spip' && $confirm == 'yes')
- {
- if (! count($object->errors))
- {
- if (!$mailmanspip->del_to_spip($object))
- {
- setEventMessage($langs->trans('DeleteIntoSpipError').': '.$mailmanspip->error, 'errors');
- }
- }
- }
- if ($user->rights->adherent->creer && $action == 'confirm_add_spip' && $confirm == 'yes')
- {
- if (! count($object->errors))
- {
- if (!$mailmanspip->add_to_spip($object))
- {
- setEventMessage($langs->trans('AddIntoSpipError').': '.$mailmanspip->error, 'errors');
- }
- }
- }
- /*
- * View
- */
- $form = new Form($db);
- $formcompany = new FormCompany($db);
- $help_url='EN:Module_Foundations|FR:Module_Adhérents|ES:Módulo_Miembros';
- llxHeader('',$langs->trans("Member"),$help_url);
- $countrynotdefined=$langs->trans("ErrorSetACountryFirst").' ('.$langs->trans("SeeAbove").')';
- if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action))
- {
- // -----------------------------------------
- // When used with CANVAS
- // -----------------------------------------
- if (empty($object->error) && $rowid)
- {
- $object = new Adherent($db);
- $result=$object->fetch($rowid);
- if ($result <= 0) dol_print_error('',$object->error);
- }
- $objcanvas->assign_values($action, $object->id, $object->ref); // Set value for templates
- $objcanvas->display_canvas($action); // Show template
- }
- else
- {
- // -----------------------------------------
- // When used in standard mode
- // -----------------------------------------
- if ($action == 'create')
- {
- /* ************************************************************************** */
- /* */
- /* Creation card */
- /* */
- /* ************************************************************************** */
- $object->canvas=$canvas;
- $object->state_id = GETPOST('state_id', 'int');
- // We set country_id, country_code and country for the selected country
- $object->country_id=GETPOST('country_id','int')?GETPOST('country_id','int'):$mysoc->country_id;
- if ($object->country_id)
- {
- $tmparray=getCountry($object->country_id,'all');
- $object->country_code=$tmparray['code'];
- $object->country=$tmparray['label'];
- }
- $adht = new AdherentType($db);
- print_fiche_titre($langs->trans("NewMember"));
- if ($conf->use_javascript_ajax)
- {
- print "\n".'<script type="text/javascript" language="javascript">';
- print 'jQuery(document).ready(function () {
- jQuery("#selectcountry_id").change(function() {
- document.formsoc.action.value="create";
- document.formsoc.submit();
- });
- function initfieldrequired()
- {
- jQuery("#tdcompany").removeClass("fieldrequired");
- jQuery("#tdlastname").removeClass("fieldrequired");
- jQuery("#tdfirstname").removeClass("fieldrequired");
- if (jQuery("#morphy").val() == \'mor\')
- {
- jQuery("#tdcompany").addClass("fieldrequired");
- }
- if (jQuery("#morphy").val() == \'phy\')
- {
- jQuery("#tdlastname").addClass("fieldrequired");
- jQuery("#tdfirstname").addClass("fieldrequired");
- }
- }
- jQuery("#morphy").change(function() {
- initfieldrequired();
- });
- initfieldrequired();
- })';
- print '</script>'."\n";
- }
- print '<form name="formsoc" action="'.$_SERVER["PHP_SELF"].'" method="post" enctype="multipart/form-data">';
- print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
- print '<input type="hidden" name="action" value="add">';
- print '<table class="border" width="100%">';
- // Login
- if (empty($conf->global->ADHERENT_LOGIN_NOT_REQUIRED))
- {
- print '<tr><td><span class="fieldrequired">'.$langs->trans("Login").' / '.$langs->trans("Id").'</span></td><td><input type="text" name="member_login" size="40" value="'.(isset($_POST["member_login"])?$_POST["member_login"]:$object->login).'"></td></tr>';
- }
- // Moral-Physique
- $morphys["phy"] = $langs->trans("Physical");
- $morphys["mor"] = $langs->trans("Moral");
- print '<tr><td class="fieldrequired">'.$langs->trans("Nature")."</td><td>\n";
- print $form->selectarray("morphy", $morphys, GETPOST('morphy','alpha')?GETPOST('morphy','alpha'):$object->morphy, 1);
- print "</td>\n";
- // Type
- print '<tr><td class="fieldrequired">'.$langs->trans("MemberType").'</td><td>';
- $listetype=$adht->liste_array();
- if (count($listetype))
- {
- print $form->selectarray("typeid", $listetype, GETPOST('typeid','int')?GETPOST('typeid','int'):$typeid, count($listetype)>1?1:0);
- } else {
- print '<font class="error">'.$langs->trans("NoTypeDefinedGoToSetup").'</font>';
- }
- print "</td>\n";
- // Company
- print '<tr><td id="tdcompany">'.$langs->trans("Company").'</td><td><input type="text" name="societe" size="40" value="'.(GETPOST('societe','alpha')?GETPOST('societe','alpha'):$object->societe).'"></td></tr>';
- // Civility
- print '<tr><td>'.$langs->trans("UserTitle").'</td><td>';
- print $formcompany->select_civility(GETPOST('civility_id','int')?GETPOST('civility_id','int'):$object->civility_id,'civility_id').'</td>';
- print '</tr>';
- // Lastname
- print '<tr><td id="tdlastname">'.$langs->trans("Lastname").'</td><td><input type="text" name="lastname" value="'.(GETPOST('lastname','alpha')?GETPOST('lastname','alpha'):$object->lastname).'" size="40"></td>';
- print '</tr>';
- // Firstname
- print '<tr><td id="tdfirstname">'.$langs->trans("Firstname").'</td><td><input type="text" name="firstname" size="40" value="'.(GETPOST('firstname','alpha')?GETPOST('firstname','alpha'):$object->firstname).'"></td>';
- print '</tr>';
- // EMail
- print '<tr><td>'.($conf->global->ADHERENT_MAIL_REQUIRED?'<span class="fieldrequired">':'').$langs->trans("EMail").($conf->global->ADHERENT_MAIL_REQUIRED?'</span>':'').'</td><td><input type="text" name="member_email" size="40" value="'.(GETPOST('member_email','alpha')?GETPOST('member_email','alpha'):$object->email).'"></td></tr>';
- // Password
- if (empty($conf->global->ADHERENT_LOGIN_NOT_REQUIRED))
- {
- require_once DOL_DOCUMENT_ROOT.'/core/lib/security2.lib.php';
- $generated_password=getRandomPassword(false);
- print '<tr><td><span class="fieldrequired">'.$langs->trans("Password").'</span></td><td>';
- print '<input size="30" maxsize="32" type="text" name="password" value="'.$generated_password.'">';
- print '</td></tr>';
- }
- // Address
- print '<tr><td valign="top">'.$langs->trans("Address").'</td><td>';
- print '<textarea name="address" wrap="soft" cols="40" rows="2">'.(GETPOST('address','alpha')?GETPOST('address','alpha'):$object->address).'</textarea>';
- print '</td></tr>';
- // Zip / Town
- print '<tr><td>'.$langs->trans("Zip").' / '.$langs->trans("Town").'</td><td>';
- print $formcompany->select_ziptown((GETPOST('zipcode','alpha')?GETPOST('zipcode','alpha'):$object->zip),'zipcode',array('town','selectcountry_id','state_id'),6);
- print ' ';
- print $formcompany->select_ziptown((GETPOST('town','alpha')?GETPOST('town','alpha'):$object->town),'town',array('zipcode','selectcountry_id','state_id'));
- print '</td></tr>';
- // Country
- $object->country_id=$object->country_id?$object->country_id:$mysoc->country_id;
- print '<tr><td width="25%">'.$langs->trans('Country').'</td><td>';
- print $form->select_country(GETPOST('country_id','alpha')?GETPOST('country_id','alpha'):$object->country_id,'country_id');
- if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1);
- print '</td></tr>';
- // State
- if (empty($conf->global->MEMBER_DISABLE_STATE))
- {
- print '<tr><td>'.$langs->trans('State').'</td><td>';
- if ($object->country_id)
- {
- print $formcompany->select_state(GETPOST('state_id','int')?GETPOST('state_id','int'):$object->state_id,$object->country_code);
- }
- else
- {
- print $countrynotdefined;
- }
- print '</td></tr>';
- }
- // Tel pro
- print '<tr><td>'.$langs->trans("PhonePro").'</td><td><input type="text" name="phone" size="20" value="'.(GETPOST('phone','alpha')?GETPOST('phone','alpha'):$object->phone).'"></td></tr>';
- // Tel perso
- print '<tr><td>'.$langs->trans("PhonePerso").'</td><td><input type="text" name="phone_perso" size="20" value="'.(GETPOST('phone_perso','alpha')?GETPOST('phone_perso','alpha'):$object->phone_perso).'"></td></tr>';
- // Tel mobile
- print '<tr><td>'.$langs->trans("PhoneMobile").'</td><td><input type="text" name="phone_mobile" size="20" value="'.(GETPOST('phone_mobile','alpha')?GETPOST('phone_mobile','alpha'):$object->phone_mobile).'"></td></tr>';
- // Skype
- if (! empty($conf->skype->enabled))
- {
- print '<tr><td>'.$langs->trans("Skype").'</td><td><input type="text" name="member_skype" size="40" value="'.(GETPOST('member_skype','alpha')?GETPOST('member_skype','alpha'):$object->skype).'"></td></tr>';
- }
- // Birthday
- print "<tr><td>".$langs->trans("Birthday")."</td><td>\n";
- $form->select_date(($object->birth ? $object->birth : -1),'birth','','',1,'formsoc');
- print "</td></tr>\n";
- // Profil public
- print "<tr><td>".$langs->trans("Public")."</td><td>\n";
- print $form->selectyesno("public",$object->public,1);
- print "</td></tr>\n";
- // Other attributes
- $parameters=array();
- $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook
- if (empty($reshook) && ! empty($extrafields->attribute_label))
- {
- print $object->showOptionals($extrafields,'edit');
- }
- /*
- // Third party Dolibarr
- if (! empty($conf->societe->enabled))
- {
- print '<tr><td>'.$langs->trans("LinkedToDolibarrThirdParty").'</td><td class="valeur">';
- print $form->select_company($object->fk_soc,'socid','',1);
- print '</td></tr>';
- }
- // Login Dolibarr
- print '<tr><td>'.$langs->trans("LinkedToDolibarrUser").'</td><td class="valeur">';
- print $form->select_dolusers($object->user_id,'userid',1);
- print '</td></tr>';
- */
- print "</table>\n";
- print '<br>';
- print '<center><input type="submit" class="button" value="'.$langs->trans("AddMember").'"></center>';
- print "</form>\n";
- }
- if ($action == 'edit')
- {
- /********************************************
- *
- * Fiche en mode edition
- *
- ********************************************/
- $res=$object->fetch($rowid);
- if ($res < 0) {
- dol_print_error($db,$object->error); exit;
- }
- $res=$object->fetch_optionals($object->id,$extralabels);
- if ($res < 0) {
- dol_print_error($db); exit;
- }
- $adht = new AdherentType($db);
- $adht->fetch($object->typeid);
- // We set country_id, and country_code, country of the chosen country
- $country=GETPOST('country','int');
- if (!empty($country) || $object->country_id)
- {
- $sql = "SELECT rowid, code, label from ".MAIN_DB_PREFIX."c_country where rowid = ".(!empty($country)?$country:$object->country_id);
- $resql=$db->query($sql);
- if ($resql)
- {
- $obj = $db->fetch_object($resql);
- }
- else
- {
- dol_print_error($db);
- }
- $object->country_id=$obj->rowid;
- $object->country_code=$obj->code;
- $object->country=$langs->trans("Country".$obj->code)?$langs->trans("Country".$obj->code):$obj->label;
- }
- $head = member_prepare_head($object);
- dol_fiche_head($head, 'general', $langs->trans("Member"), 0, 'user');
- if ($conf->use_javascript_ajax)
- {
- print "\n".'<script type="text/javascript" language="javascript">';
- print 'jQuery(document).ready(function () {
- jQuery("#selectcountry_id").change(function() {
- document.formsoc.action.value="edit";
- document.formsoc.submit();
- });
- function initfieldrequired()
- {
- jQuery("#tdcompany").removeClass("fieldrequired");
- jQuery("#tdlastname").removeClass("fieldrequired");
- jQuery("#tdfirstname").removeClass("fieldrequired");
- if (jQuery("#morphy").val() == \'mor\')
- {
- jQuery("#tdcompany").addClass("fieldrequired");
- }
- if (jQuery("#morphy").val() == \'phy\')
- {
- jQuery("#tdlastname").addClass("fieldrequired");
- jQuery("#tdfirstname").addClass("fieldrequired");
- }
- }
- jQuery("#morphy").change(function() {
- initfieldrequired();
- });
- initfieldrequired();
- })';
- print '</script>'."\n";
- }
- $rowspan=15;
- if (empty($conf->global->ADHERENT_LOGIN_NOT_REQUIRED)) $rowspan++;
- if (! empty($conf->societe->enabled)) $rowspan++;
- print '<form name="formsoc" action="'.$_SERVER["PHP_SELF"].'" method="post" enctype="multipart/form-data">';
- print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'" />';
- print '<input type="hidden" name="action" value="update" />';
- print '<input type="hidden" name="rowid" value="'.$rowid.'" />';
- print '<input type="hidden" name="statut" value="'.$object->statut.'" />';
- if ($backtopage) print '<input type="hidden" name="backtopage" value="'.($backtopage != '1' ? $backtopage : $_SERVER["HTTP_REFERER"]).'">';
- print '<table class="border" width="100%">';
- // Ref
- print '<tr><td>'.$langs->trans("Ref").'</td><td class="valeur" colspan="2">'.$object->id.'</td></tr>';
- // Login
- if (empty($conf->global->ADHERENT_LOGIN_NOT_REQUIRED))
- {
- print '<tr><td><span class="fieldrequired">'.$langs->trans("Login").' / '.$langs->trans("Id").'</span></td><td colspan="2"><input type="text" name="login" size="30" value="'.(isset($_POST["login"])?$_POST["login"]:$object->login).'"></td></tr>';
- }
- // Physique-Moral
- $morphys["phy"] = $langs->trans("Physical");
- $morphys["mor"] = $langs->trans("Morale");
- print '<tr><td><span class="fieldrequired">'.$langs->trans("Nature").'</span></td><td>';
- print $form->selectarray("morphy", $morphys, isset($_POST["morphy"])?$_POST["morphy"]:$object->morphy);
- print "</td>";
- // Photo
- print '<td align="center" class="hideonsmartphone" valign="middle" width="25%" rowspan="'.$rowspan.'">';
- print $form->showphoto('memberphoto',$object)."\n";
- if ($caneditfieldmember)
- {
- if ($object->photo) print "<br>\n";
- print '<table class="nobordernopadding">';
- if ($object->photo) print '<tr><td align="center"><input type="checkbox" class="flat" name="deletephoto" id="photodelete"> '.$langs->trans("Delete").'<br><br></td></tr>';
- print '<tr><td>'.$langs->trans("PhotoFile").'</td></tr>';
- print '<tr><td><input type="file" class="flat" name="photo" id="photoinput"></td></tr>';
- print '</table>';
- }
- print '</td>';
- // Type
- print '<tr><td class="fieldrequired">'.$langs->trans("Type").'</td><td>';
- if ($user->rights->adherent->creer)
- {
- print $form->selectarray("typeid", $adht->liste_array(), (isset($_POST["typeid"])?$_POST["typeid"]:$object->typeid));
- }
- else
- {
- print $adht->getNomUrl(1);
- print '<input type="hidden" name="typeid" value="'.$object->typeid.'">';
- }
- print "</td></tr>";
- // Company
- print '<tr><td id="tdcompany">'.$langs->trans("Company").'</td><td><input type="text" name="societe" size="40" value="'.(isset($_POST["societe"])?$_POST["societe"]:$object->societe).'"></td></tr>';
- // Civility
- print '<tr><td width="20%">'.$langs->trans("UserTitle").'</td><td width="35%">';
- print $formcompany->select_civility(isset($_POST["civility_id"])?$_POST["civility_id"]:$object->civility_id)."\n";
- print '</td>';
- print '</tr>';
- // Lastname
- print '<tr><td id="tdlastname">'.$langs->trans("Lastname").'</td><td><input type="text" name="lastname" size="40" value="'.(isset($_POST["lastname"])?$_POST["lastname"]:$object->lastname).'"></td>';
- print '</tr>';
- // Firstname
- print '<tr><td id="tdfirstname">'.$langs->trans("Firstname").'</td><td><input type="text" name="firstname" size="40" value="'.(isset($_POST["firstname"])?$_POST["firstname"]:$object->firstname).'"></td>';
- print '</tr>';
- // EMail
- print '<tr><td>'.($conf->global->ADHERENT_MAIL_REQUIRED?'<span class="fieldrequired">':'').$langs->trans("EMail").($conf->global->ADHERENT_MAIL_REQUIRED?'</span>':'').'</td><td><input type="text" name="email" size="40" value="'.(isset($_POST["email"])?$_POST["email"]:$object->email).'"></td></tr>';
- // Password
- if (empty($conf->global->ADHERENT_LOGIN_NOT_REQUIRED))
- {
- print '<tr><td class="fieldrequired">'.$langs->trans("Password").'</td><td><input type="password" name="pass" size="30" value="'.(isset($_POST["pass"])?$_POST["pass"]:$object->pass).'"></td></tr>';
- }
- // Address
- print '<tr><td>'.$langs->trans("Address").'</td><td>';
- print '<textarea name="address" wrap="soft" cols="40" rows="2">'.(isset($_POST["address"])?$_POST["address"]:$object->address).'</textarea>';
- print '</td></tr>';
- // Zip / Town
- print '<tr><td>'.$langs->trans("Zip").' / '.$langs->trans("Town").'</td><td>';
- print $formcompany->select_ziptown((isset($_POST["zipcode"])?$_POST["zipcode"]:$object->zip),'zipcode',array('town','selectcountry_id','state_id'),6);
- print ' ';
- print $formcompany->select_ziptown((isset($_POST["town"])?$_POST["town"]:$object->town),'town',array('zipcode','selectcountry_id','state_id'));
- print '</td></tr>';
- // Country
- //$object->country_id=$object->country_id?$object->country_id:$mysoc->country_id; // In edit mode we don't force to company country if not defined
- print '<tr><td width="25%">'.$langs->trans('Country').'</td><td>';
- print $form->select_country(isset($_POST["country_id"])?$_POST["country_id"]:$object->country_id,'country_id');
- if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1);
- print '</td></tr>';
- // State
- if (empty($conf->global->MEMBER_DISABLE_STATE))
- {
- print '<tr><td>'.$langs->trans('State').'</td><td>';
- print $formcompany->select_state($object->state_id,isset($_POST["country_id"])?$_POST["country_id"]:$object->country_id);
- print '</td></tr>';
- }
- // Tel
- print '<tr><td>'.$langs->trans("PhonePro").'</td><td><input type="text" name="phone" size="20" value="'.(isset($_POST["phone"])?$_POST["phone"]:$object->phone).'"></td></tr>';
- // Tel perso
- print '<tr><td>'.$langs->trans("PhonePerso").'</td><td><input type="text" name="phone_perso" size="20" value="'.(isset($_POST["phone_perso"])?$_POST["phone_perso"]:$object->phone_perso).'"></td></tr>';
- // Tel mobile
- print '<tr><td>'.$langs->trans("PhoneMobile").'</td><td><input type="text" name="phone_mobile" size="20" value="'.(isset($_POST["phone_mobile"])?$_POST["phone_mobile"]:$object->phone_mobile).'"></td></tr>';
- // Skype
- if (! empty($conf->skype->enabled))
- {
- print '<tr><td>'.$langs->trans("Skype").'</td><td><input type="text" name="skype" size="40" value="'.(isset($_POST["skype"])?$_POST["skype"]:$object->skype).'"></td></tr>';
- }
- // Birthday
- print "<tr><td>".$langs->trans("Birthday")."</td><td>\n";
- $form->select_date(($object->birth ? $object->birth : -1),'birth','','',1,'formsoc');
- print "</td></tr>\n";
- // Profil public
- print "<tr><td>".$langs->trans("Public")."</td><td>\n";
- print $form->selectyesno("public",(isset($_POST["public"])?$_POST["public"]:$object->public),1);
- print "</td></tr>\n";
- // Other attributes
- $parameters=array();
- $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook
- if (empty($reshook) && ! empty($extrafields->attribute_label))
- {
- print $object->showOptionals($extrafields,'edit');
- }
- // Third party Dolibarr
- if (! empty($conf->societe->enabled))
- {
- print '<tr><td>'.$langs->trans("LinkedToDolibarrThirdParty").'</td><td colspan="2" class="valeur">';
- if ($object->fk_soc)
- {
- $company=new Societe($db);
- $result=$company->fetch($object->fk_soc);
- print $company->getNomUrl(1);
- }
- else
- {
- print $langs->trans("NoThirdPartyAssociatedToMember");
- }
- print '</td></tr>';
- }
- // Login Dolibarr
- print '<tr><td>'.$langs->trans("LinkedToDolibarrUser").'</td><td colspan="2" class="valeur">';
- if ($object->user_id)
- {
- print $form->form_users($_SERVER['PHP_SELF'].'?rowid='.$object->id,$object->user_id,'none');
- }
- else print $langs->trans("NoDolibarrAccess");
- print '</td></tr>';
- print '</table>';
- print '<br><center>';
- print '<input type="submit" class="button" name="save" value="'.$langs->trans("Save").'">';
- print ' ';
- print '<input type="submit" class="button" name="cancel" value="'.$langs->trans("Cancel").'">';
- print '</center';
- print '</form>';
- print '</div>';
- }
- if ($rowid && $action != 'edit')
- {
- /* ************************************************************************** */
- /* */
- /* Mode affichage */
- /* */
- /* ************************************************************************** */
- $res=$object->fetch($rowid);
- if ($res < 0) {
- dol_print_error($db,$object->error); exit;
- }
- $res=$object->fetch_optionals($object->id,$extralabels);
- if ($res < 0) {
- dol_print_error($db); exit;
- }
- $adht = new AdherentType($db);
- $res=$adht->fetch($object->typeid);
- if ($res < 0) {
- dol_print_error($db); exit;
- }
- /*
- * Affichage onglets
- */
- $head = member_prepare_head($object);
- dol_fiche_head($head, 'general', $langs->trans("Member"), 0, 'user');
- // Confirm create user
- if ($action == 'create_user')
- {
- $login=$object->login;
- if (empty($login))
- {
- // Full firstname and name separated with a dot : firstname.name
- include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
- $login=dol_buildlogin($object->lastname,$object->firstname);
- }
- if (empty($login)) $login=strtolower(substr($object->firstname, 0, 4)) . strtolower(substr($object->lastname, 0, 4));
- // Create a form array
- $formquestion=array(
- array('label' => $langs->trans("LoginToCreate"), 'type' => 'text', 'name' => 'login', 'value' => $login)
- );
- $text=$langs->trans("ConfirmCreateLogin").'<br>';
- if (! empty($conf->societe->enabled))
- {
- if ($object->fk_soc > 0) $text.=$langs->trans("UserWillBeExternalUser");
- else $text.=$langs->trans("UserWillBeInternalUser");
- }
- print $form->formconfirm($_SERVER["PHP_SELF"]."?rowid=".$object->id,$langs->trans("CreateDolibarrLogin"),$text,"confirm_create_user",$formquestion,'yes');
- }
- // Confirm create third party
- if ($action == 'create_thirdparty')
- {
- $name = $object->getFullName($langs);
- if (! empty($name))
- {
- if ($object->societe) $name.=' ('.$object->societe.')';
- }
- else
- {
- $name=$object->societe;
- }
- // Create a form array
- $formquestion=array( array('label' => $langs->trans("NameToCreate"), 'type' => 'text', 'name' => 'companyname', 'value' => $name));
- print $form->formconfirm($_SERVER["PHP_SELF"]."?rowid=".$object->id,$langs->trans("CreateDolibarrThirdParty"),$langs->trans("ConfirmCreateThirdParty"),"confirm_create_thirdparty",$formquestion,1);
- }
- // Confirm validate member
- if ($action == 'valid')
- {
- $langs->load("mails");
- $adht = new AdherentType($db);
- $adht->fetch($object->typeid);
- $subjecttosend=$object->makeSubstitution($conf->global->ADHERENT_MAIL_VALID_SUBJECT);
- $texttosend=$object->makeSubstitution($adht->getMailOnValid());
- $tmp=$langs->trans("SendAnEMailToMember");
- $tmp.=' ('.$langs->trans("MailFrom").': <b>'.$conf->global->ADHERENT_MAIL_FROM.'</b>, ';
- $tmp.=$langs->trans("MailRecipient").': <b>'.$object->email.'</b>)';
- $helpcontent='';
- $helpcontent.='<b>'.$langs->trans("MailFrom").'</b>: '.$conf->global->ADHERENT_MAIL_FROM.'<br>'."\n";
- $helpcontent.='<b>'.$langs->trans("MailRecipient").'</b>: '.$object->email.'<br>'."\n";
- $helpcontent.='<b>'.$langs->trans("Subject").'</b>:<br>'."\n";
- $helpcontent.=$subjecttosend."\n";
- $helpcontent.="<br>";
- $helpcontent.='<b>'.$langs->trans("Content").'</b>:<br>';
- $helpcontent.=dol_htmlentitiesbr($texttosend)."\n";
- $label=$form->textwithpicto($tmp,$helpcontent,1,'help');
- // Cree un tableau formulaire
- $formquestion=array();
- if ($object->email) $formquestion[]=array('type' => 'checkbox', 'name' => 'send_mail', 'label' => $label, 'value' => ($conf->global->ADHERENT_DEFAULT_SENDINFOBYMAIL?true:false));
- if (! empty($conf->mailman->enabled) && ! empty($conf->global->ADHERENT_USE_MAILMAN)) {
- $formquestion[]=array('type'=>'other','label'=>$langs->transnoentitiesnoconv("SynchroMailManEnabled"),'value'=>'');
- }
- if (! empty($conf->mailman->enabled) && ! empty($conf->global->ADHERENT_USE_SPIP)) {
- $formquestion[]=array('type'=>'other','label'=>$langs->transnoentitiesnoconv("SynchroSpipEnabled"),'value'=>'');
- }
- print $form->formconfirm("card.php?rowid=".$rowid,$langs->trans("ValidateMember"),$langs->trans("ConfirmValidateMember"),"confirm_valid",$formquestion,1);
- }
- // Confirm send card by mail
- if ($action == 'sendinfo')
- {
- print $form->formconfirm("card.php?rowid=".$rowid,$langs->trans("SendCardByMail"),$langs->trans("ConfirmSendCardByMail",$object->email),"confirm_sendinfo",'',0,1);
- }
- // Confirm resiliate
- if ($action == 'resign')
- {
- $langs->load("mails");
- $adht = new AdherentType($db);
- $adht->fetch($object->typeid);
- $subjecttosend=$object->makeSubstitution($conf->global->ADHERENT_MAIL_RESIL_SUBJECT);
- $texttosend=$object->makeSubstitution($adht->getMailOnResiliate());
- $tmp=$langs->trans("SendAnEMailToMember");
- $tmp.=' ('.$langs->trans("MailFrom").': <b>'.$conf->global->ADHERENT_MAIL_FROM.'</b>, ';
- $tmp.=$langs->trans("MailRecipient").': <b>'.$object->email.'</b>)';
- $helpcontent='';
- $helpcontent.='<b>'.$langs->trans("MailFrom").'</b>: '.$conf->global->ADHERENT_MAIL_FROM.'<br>'."\n";
- $helpcontent.='<b>'.$langs->trans("MailRecipient").'</b>: '.$object->email.'<br>'."\n";
- $helpcontent.='<b>'.$langs->trans("Subject").'</b>:<br>'."\n";
- $helpcontent.=$subjecttosend."\n";
- $helpcontent.="<br>";
- $helpcontent.='<b>'.$langs->trans("Content").'</b>:<br>';
- $helpcontent.=dol_htmlentitiesbr($texttosend)."\n";
- $label=$form->textwithpicto($tmp,$helpcontent,1,'help');
- // Cree un tableau formulaire
- $formquestion=array();
- if ($object->email) $formquestion[]=array('type' => 'checkbox', 'name' => 'send_mail', 'label' => $label, 'value' => (! empty($conf->global->ADHERENT_DEFAULT_SENDINFOBYMAIL)?'true':'false'));
- if ($backtopage) $formquestion[]=array('type' => 'hidden', 'name' => 'backtopage', 'value' => ($backtopage != '1' ? $backtopage : $_SERVER["HTTP_REFERER"]));
- print $form->formconfirm("card.php?rowid=".$rowid,$langs->trans("ResiliateMember"),$langs->trans("ConfirmResiliateMember"),"confirm_resign",$formquestion);
- }
- // Confirm remove member
- if ($action == 'delete')
- {
- $formquestion=array();
- if ($backtopage) $formquestion[]=array('type' => 'hidden', 'name' => 'backtopage', 'value' => ($backtopage != '1' ? $backtopage : $_SERVER["HTTP_REFERER"]));
- print $form->formconfirm("card.php?rowid=".$rowid,$langs->trans("DeleteMember"),$langs->trans("ConfirmDeleteMember"),"confirm_delete",$formquestion,0,1);
- }
- /*
- * Confirm add in spip
- */
- if ($action == 'add_spip')
- {
- print $form->formconfirm("card.php?rowid=".$rowid, $langs->trans('AddIntoSpip'), $langs->trans('AddIntoSpipConfirmation'), 'confirm_add_spip');
- }
- /*
- * Confirm removed from spip
- */
- if ($action == 'del_spip')
- {
- print $form->formconfirm("card.php?rowid=$rowid", $langs->trans('DeleteIntoSpip'), $langs->trans('DeleteIntoSpipConfirmation'), 'confirm_del_spip');
- }
- $rowspan=17;
- if (empty($conf->global->ADHERENT_LOGIN_NOT_REQUIRED)) $rowspan++;
- if (! empty($conf->societe->enabled)) $rowspan++;
- if (! empty($conf->skype->enabled)) $rowspan++;
- print '<table class="border" width="100%">';
- $linkback = '<a href="'.DOL_URL_ROOT.'/adherents/list.php">'.$langs->trans("BackToList").'</a>';
- // Ref
- print '<tr><td width="20%">'.$langs->trans("Ref").'</td>';
- print '<td class="valeur" colspan="2">';
- print $form->showrefnav($object, 'rowid', $linkback);
- print '</td></tr>';
- $showphoto='<td rowspan="'.$rowspan.'" align="center" class="hideonsmartphone" valign="middle" width="25%">';
- $showphoto.=$form->showphoto('memberphoto',$object);
- $showphoto.='</td>';
- // Login
- if (empty($conf->global->ADHERENT_LOGIN_NOT_REQUIRED))
- {
- print '<tr><td>'.$langs->trans("Login").' / '.$langs->trans("Id").'</td><td class="valeur">'.$object->login.' </td>';
- // Photo
- print $showphoto; $showphoto='';
- print '</tr>';
- }
- // Morphy
- print '<tr><td>'.$langs->trans("Nature").'</td><td class="valeur" >'.$object->getmorphylib().'</td>';
- print $showphoto; $showphoto='';
- print '</tr>';
- // Type
- print '<tr><td>'.$langs->trans("Type").'</td><td class="valeur">'.$adht->getNomUrl(1)."</td></tr>\n";
- // Company
- print '<tr><td>'.$langs->trans("Company").'</td><td class="valeur">'.$object->societe.'</td></tr>';
- // Civility
- print '<tr><td>'.$langs->trans("UserTitle").'</td><td class="valeur">'.$object->getCivilityLabel().' </td>';
- print '</tr>';
- // Lastname
- print '<tr><td>'.$langs->trans("Lastname").'</td><td class="valeur">'.$object->lastname.' </td>';
- print '</tr>';
- // Firstname
- print '<tr><td>'.$langs->trans("Firstname").'</td><td class="valeur">'.$object->firstname.' </td></tr>';
- // EMail
- print '<tr><td>'.$langs->trans("EMail").'</td><td class="valeur">'.dol_print_email($object->email,0,$object->fk_soc,1).'</td></tr>';
- // Password
- if (empty($conf->global->ADHERENT_LOGIN_NOT_REQUIRED))
- {
- print '<tr><td>'.$langs->trans("Password").'</td><td>'.preg_replace('/./i','*',$object->pass).'</td></tr>';
- }
- // Address
- print '<tr><td>'.$langs->trans("Address").'</td><td class="valeur">';
- dol_print_address($object->address,'gmap','member',$object->id);
- print '</td></tr>';
- // Zip / Town
- print '<tr><td class="nowrap">'.$langs->trans("Zip").' / '.$langs->trans("Town").'</td><td class="valeur">'.$object->zip.(($object->zip && $object->town)?' / ':'').$object->town.'</td></tr>';
- // Country
- print '<tr><td>'.$langs->trans("Country").'</td><td class="valeur">';
- $img=picto_from_langcode($object->country_code);
- if ($img) print $img.' ';
- print getCountry($object->country_code);
- print '</td></tr>';
- // State
- print '<tr><td>'.$langs->trans('State').'</td><td class="valeur">'.$object->state.'</td>';
- // Tel pro.
- print '<tr><td>'.$langs->trans("PhonePro").'</td><td class="valeur">'.dol_print_phone($object->phone,$object->country_code,0,$object->fk_soc,1).'</td></tr>';
- // Tel perso
- print '<tr><td>'.$langs->trans("PhonePerso").'</td><td class="valeur">'.dol_print_phone($object->phone_perso,$object->country_code,0,$object->fk_soc,1).'</td></tr>';
- // Tel mobile
- print '<tr><td>'.$langs->trans("PhoneMobile").'</td><td class="valeur">'.dol_print_phone($object->phone_mobile,$object->country_code,0,$object->fk_soc,1).'</td></tr>';
- // Skype
- if (! empty($conf->skype->enabled))
- {
- print '<tr><td>'.$langs->trans("Skype").'</td><td class="valeur">'.dol_print_skype($object->skype,0,$object->fk_soc,1).'</td></tr>';
- }
- // Birthday
- print '<tr><td>'.$langs->trans("Birthday").'</td><td class="valeur">'.dol_print_date($object->birth,'day').'</td></tr>';
- // Public
- print '<tr><td>'.$langs->trans("Public").'</td><td class="valeur">'.yn($object->public).'</td></tr>';
- // Status
- print '<tr><td>'.$langs->trans("Status").'</td><td class="valeur">'.$object->getLibStatut(4).'</td></tr>';
- // Other attributes
- $parameters=array();
- $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook
- if (empty($reshook) && ! empty($extrafields->attribute_label))
- {
- print $object->showOptionals($extrafields);
- }
- // Third party Dolibarr
- if (! empty($conf->societe->enabled))
- {
- print '<tr><td>';
- print '<table class="nobordernopadding" width="100%"><tr><td>';
- print $langs->trans("LinkedToDolibarrThirdParty");
- print '</td>';
- if ($action != 'editthirdparty' && $user->rights->adherent->creer) print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=editthirdparty&rowid='.$object->id.'">'.img_edit($langs->trans('SetLinkToThirdParty'),1).'</a></td>';
- print '</tr></table>';
- print '</td><td colspan="2" class="valeur">';
- if ($action == 'editthirdparty')
- {
- $htmlname='socid';
- print '<form method="POST" action="'.$_SERVER['PHP_SELF'].'" name="form'.$htmlname.'">';
- print '<input type="hidden" name="rowid" value="'.$object->id.'">';
- print '<input type="hidden" name="action" value="set'.$htmlname.'">';
- print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
- print '<table class="nobordernopadding" cellpadding="0" cellspacing="0">';
- print '<tr><td>';
- print $form->select_company($object->fk_soc,'socid','',1);
- print '</td>';
- print '<td align="left"><input type="submit" class="button" value="'.$langs->trans("Modify").'"></td>';
- print '</tr></table></form>';
- }
- else
- {
- if ($object->fk_soc)
- {
- $company=new Societe($db);
- $result=$company->fetch($object->fk_soc);
- print $company->getNomUrl(1);
- }
- else
- {
- print $langs->trans("NoThirdPartyAssociatedToMember");
- }
- }
- print '</td></tr>';
- }
- // Login Dolibarr
- print '<tr><td>';
- print '<table class="nobordernopadding" width="100%"><tr><td>';
- print $langs->trans("LinkedToDolibarrUser");
- print '</td>';
- if ($action != 'editlogin' && $user->rights->adherent->creer)
- {
- print '<td align="right">';
- if ($user->rights->user->user->creer)
- {
- print '<a href="'.$_SERVER["PHP_SELF"].'?action=editlogin&rowid='.$object->id.'">'.img_edit($langs->trans('SetLinkToUser'),1).'</a>';
- }
- print '</td>';
- }
- print '</tr></table>';
- print '</td><td colspan="2" class="valeur">';
- if ($action == 'editlogin')
- {
- print $form->form_users($_SERVER['PHP_SELF'].'?rowid='.$object->id,$object->user_id,'userid','');
- }
- else
- {
- if ($object->user_id)
- {
- print $form->form_users($_SERVER['PHP_SELF'].'?rowid='.$object->id,$object->user_id,'none');
- }
- else print $langs->trans("NoDolibarrAccess");
- }
- print '</td></tr>';
- print "</table>\n";
- print "</div>\n";
- /*
- * Barre d'actions
- *
- */
- print '<div class="tabsAction">';
- if ($action != 'valid' && $action != 'editlogin' && $action != 'editthirdparty')
- {
- // Modify
- if ($user->rights->adherent->creer)
- {
- print '<div class="inline-block divButAction"><a class="butAction" href="card.php?rowid='.$rowid.'&action=edit">'.$langs->trans("Modify")."</a></div>";
- }
- else
- {
- print '<div class="inline-block divButAction"><font class="butActionRefused" href="#" title="'.dol_escape_htmltag($langs->trans("NotEnoughPermissions")).'">'.$langs->trans("Modify").'</font></div>';
- }
- // Valider
- if ($object->statut == -1)
- {
- if ($user->rights->adherent->creer)
- {
- print '<div class="inline-block divButAction"><a class="butAction" href="card.php?rowid='.$rowid.'&action=valid">'.$langs->trans("Validate")."</a></div>\n";
- }
- else
- {
- print '<div class="inline-block divButAction"><font class="butActionRefused" href="#" title="'.dol_escape_htmltag($langs->trans("NotEnoughPermissions")).'">'.$langs->trans("Validate").'</font></div>';
- }
- }
- // Reactiver
- if ($object->statut == 0)
- {
- if ($user->rights->adherent->creer)
- {
- print '<div class="inline-block divButAction"><a class="butAction" href="card.php?rowid='.$rowid.'&action=valid">'.$langs->trans("Reenable")."</a></div>\n";
- }
- else
- {
- print '<div class="inline-block divButAction"><font class="butActionRefused" href="#" title="'.dol_escape_htmltag($langs->trans("NotEnoughPermissions")).'">'.$langs->trans("Reenable")."</font></div>";
- }
- }
- // Send card by email
- if ($user->rights->adherent->creer)
- {
- if ($object->statut >= 1)
- {
- if ($object->email) print '<div class="inline-block divButAction"><a class="butAction" href="card.php?rowid='.$object->id.'&action=sendinfo">'.$langs->trans("SendCardByMail")."</a></div>\n";
- else print '<div class="inline-block divButAction"><a class="butActionRefused" href="#" title="'.dol_escape_htmltag($langs->trans("NoEMail")).'">'.$langs->trans("SendCardByMail")."</a></div>\n";
- }
- else
- {
- print '<div class="inline-block divButAction"><font class="butActionRefused" href="#" title="'.dol_escape_htmltag($langs->trans("ValidateBefore")).'">'.$langs->trans("SendCardByMail")."</font></div>";
- }
- }
- else
- {
- print '<div class="inline-block divButAction"><font class="butActionRefused" href="#" title="'.dol_escape_htmltag($langs->trans("NotEnoughPermissions")).'">'.$langs->trans("SendCardByMail")."</font></div>";
- }
- // Resilier
- if ($object->statut >= 1)
- {
- if ($user->rights->adherent->supprimer)
- {
- print '<div class="inline-block divButAction"><a class="butAction" href="card.php?rowid='.$rowid.'&action=resign">'.$langs->trans("Resiliate")."</a></div>\n";
- }
- else
- {
- print '<div class="inline-block divButAction"><font class="butActionRefused" href="#" title="'.dol_escape_htmltag($langs->trans("NotEnoughPermissions")).'">'.$langs->trans("Resiliate")."</font></div>";
- }
- }
- // Create third party
- if (! empty($conf->societe->enabled) && ! $object->fk_soc)
- {
- if ($user->rights->societe->creer)
- {
- if ($object->statut != -1) print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER["PHP_SELF"].'?rowid='.$object->id.'&action=create_thirdparty">'.$langs->trans("CreateDolibarrThirdParty").'</a></div>';
- else print '<div class="inline-block divButAction"><a class="butActionRefused" href="#" title="'.dol_escape_htmltag($langs->trans("ValidateBefore")).'">'.$langs->trans("CreateDolibarrThirdParty").'</a></div>';
- }
- else
- {
- print '<div class="inline-block divButAction"><font class="butActionRefused" href="#" title="'.dol_escape_htmltag($langs->trans("NotEnoughPermissions")).'">'.$langs->trans("CreateDolibarrThirdParty")."</font></div>";
- }
- }
- // Create user
- if (! $user->societe_id && ! $object->user_id)
- {
- if ($user->rights->user->user->creer)
- {
- if ($object->statut != -1) print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER["PHP_SELF"].'?rowid='.$object->id.'&action=create_user">'.$langs->trans("CreateDolibarrLogin").'</a></div>';
- else print '<div class="inline-block divButAction"><a class="butActionRefused" href="#" title="'.dol_escape_htmltag($langs->trans("ValidateBefore")).'">'.$langs->trans("CreateDolibarrLogin").'</a></div>';
- }
- else
- {
- print '<div class="inline-block divButAction"><font class="butActionRefused" href="#" title="'.dol_escape_htmltag($langs->trans("NotEnoughPermissions")).'">'.$langs->trans("CreateDolibarrLogin")."</font></div>";
- }
- }
- // Delete
- if ($user->rights->adherent->supprimer)
- {
- print '<div class="inline-block divButAction"><a class="butActionDelete" href="card.php?rowid='.$object->id.'&action=delete">'.$langs->trans("Delete")."</a></div>\n";
- }
- else
- {
- print '<div class="inline-block divButAction"><font class="butActionRefused" href="#" title="'.dol_escape_htmltag($langs->trans("NotEnoughPermissions")).'">'.$langs->trans("Delete")."</font></div>";
- }
- // Action SPIP
- if (! empty($conf->mailmanspip->enabled) && ! empty($conf->global->ADHERENT_USE_SPIP))
- {
- $isinspip = $mailmanspip->is_in_spip($object);
- if ($isinspip == 1)
- {
- print '<div class="inline-block divButAction"><a class="butAction" href="card.php?rowid='.$object->id.'&action=del_spip">'.$langs->trans("DeleteIntoSpip")."</a></div>\n";
- }
- if ($isinspip == 0)
- {
- print '<div class="inline-block divButAction"><a class="butAction" href="card.php?rowid='.$object->id.'&action=add_spip">'.$langs->trans("AddIntoSpip")."</a></div>\n";
- }
- }
- }
- print '</div>';
- if ($isinspip == -1)
- {
- print '<br><br><font class="error">'.$langs->trans('SPIPConnectionFailed').': '.$mailmanspip->error.'</font>';
- }
- print "<br>\n";
- }
- }
- llxFooter();
- $db->close();
|