From 6e15ff8cf30841cfade256673594426289a9582e Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 14 Jan 2009 14:59:28 +0000 Subject: [PATCH] New: can force login value when creating a user from a member. --- ChangeLog | 1 + htdocs/adherents/fiche.php | 175 ++++++++++++++++++++----------------- htdocs/contact/fiche.php | 16 ++-- htdocs/user.class.php | 18 ++-- 4 files changed, 111 insertions(+), 99 deletions(-) diff --git a/ChangeLog b/ChangeLog index b9a3e0b5794..5eb9570711b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -11,6 +11,7 @@ For users: - New: Add graph report on number of entities in product statistics page. - New: Can delete a supplier order whatever is its status. - New: No limit on free text on PDF generated documents. +- New: can force login value when creating a user from a member. - Fix: Failed to go on the future view of bank transaction if there is no future bank transaction already wrote. - Fix: Bad ref in supplier list. diff --git a/htdocs/adherents/fiche.php b/htdocs/adherents/fiche.php index f4e6dd1509f..7323d4ac3e6 100644 --- a/htdocs/adherents/fiche.php +++ b/htdocs/adherents/fiche.php @@ -67,38 +67,36 @@ $typeid=isset($_GET["typeid"])?$_GET["typeid"]:$_POST["typeid"]; * Actions */ -// Creation utilisateur depuis adherent -if ($user->rights->user->user->creer) +// Create user from a memeber +if ($_POST["action"] == 'confirm_create_user' && $_POST["confirm"] == 'yes' && $user->rights->user->user->creer) { - if ($_GET["action"] == 'create_user') - { - // Recuperation contact actuel - $adh = new Adherent($db); - $result = $adh->fetch($_GET["rowid"]); - - if ($result > 0) - { - // Creation user - $nuser = new User($db); - $result=$nuser->create_from_member($adh); + // Recuperation contact actuel + $adh = new Adherent($db); + $result = $adh->fetch($_GET["rowid"]); - if ($result < 0) - { - $msg=$nuser->error; - } - } - else + if ($result > 0) + { + // Creation user + $nuser = new User($db); + $result=$nuser->create_from_member($adh,$_POST["login"]); + + if ($result < 0) { - $msg=$adh->error; + $langs->load("errors"); + $msg=$langs->trans($nuser->error); } } + else + { + $msg=$adh->error; + } } if ($_POST["action"] == 'confirm_sendinfo' && $_POST["confirm"] == 'yes') { $adh->id = $rowid; $adh->fetch($rowid); - + if ($adh->email) { $result=$adh->send_an_email("Voici le contenu de votre fiche\n\n%INFOS%\n\n","Contenu de votre fiche adherent"); @@ -348,7 +346,7 @@ if ($user->rights->adherent->creer && $_POST["action"] == 'add') } } } - + $db->commit(); Header("Location: liste.php?statut=-1"); @@ -360,12 +358,12 @@ if ($user->rights->adherent->creer && $_POST["action"] == 'add') if ($adh->error) $errmsg=$adh->error; else $errmsg=$adh->errors[0]; - - $action = 'create'; + + $action = 'create'; } } else { - $action = 'create'; + $action = 'create'; } } @@ -388,7 +386,7 @@ if ($user->rights->adherent->creer && $_POST["action"] == 'confirm_valid' && $_P { $result=$adh->fetch($rowid); $result=$adh->validate($user); - + $adht = new AdherentType($db); $adht->fetch($adh->typeid); @@ -410,13 +408,13 @@ if ($user->rights->adherent->creer && $_POST["action"] == 'confirm_valid' && $_P $errmsg.=$adh->error; } } - + // Rajoute l'utilisateur dans les divers abonnements (mailman, spip, etc...) if ($adh->add_to_abo($adht) < 0) { // error $errmsg.="Echec du rajout de l'utilisateur aux abonnements mailman: ".$adh->error."
\n"; - } + } } else { @@ -455,7 +453,7 @@ if ($user->rights->adherent->supprimer && $_POST["action"] == 'confirm_resign' & { $errmsg.=$adh->error; } - + // supprime l'utilisateur des divers abonnements .. if (! $adh->del_to_abo($adht)) { @@ -540,7 +538,7 @@ if ($action == 'edit') $adh->fetch_optionals($rowid); // fetch optionals attributes and labels $adho->fetch_name_optionals_label(); - + $adht = new AdherentType($db); $adht->fetch($adh->typeid); @@ -549,7 +547,7 @@ if ($action == 'edit') * Affichage onglets */ $head = member_prepare_head($adh); - + dolibarr_fiche_head($head, 'general', $langs->trans("Member")); @@ -561,10 +559,10 @@ if ($action == 'edit') $htmls = new Form($db); print ''; - + // Ref print ''; - + // Nom print ''; @@ -593,10 +591,10 @@ if ($action == 'edit') // Prenom print ''; print ''; - + // Login print ''; - + // Password print ''; @@ -612,14 +610,14 @@ if ($action == 'edit') print ''; } print ""; - - // Physique-Moral + + // Physique-Moral $morphys["phy"] = $langs->trans("Physical"); $morphys["mor"] = $langs->trans("Morale"); print ""; - + // Societe print ''; @@ -629,12 +627,12 @@ if ($action == 'edit') // Cp print ''; - + // Pays print ''; - + // Tel print ''; @@ -646,7 +644,7 @@ if ($action == 'edit') // EMail print ''; - + // Date naissance print "
'.$langs->trans("Ref").''.$adh->id.' 
'.$langs->trans("Lastname").'*
'.$langs->trans("Firstname").'*
'.$langs->trans("Login").'*
'.$langs->trans("Password").'*
".$langs->trans("Person")."*"; $htmls->select_array("morphy", $morphys, $adh->morphy); print "
'.$langs->trans("Company").'
'.$langs->trans("Zip").'/'.$langs->trans("Town").'
'.$langs->trans("Country").''; $htmls->select_pays($adh->pays_code?$adh->pays_code:$mysoc->pays_code,'pays'); print '
'.$langs->trans("PhonePro").'
'.$langs->trans("EMail").($conf->global->ADHERENT_MAIL_REQUIRED?'*':'').'
".$langs->trans("Birthday")."\n"; $htmls->select_date(($adh->naiss ? $adh->naiss : -1),'naiss','','',1,'update'); @@ -672,8 +670,8 @@ if ($action == 'edit') print '
'; print ''; - - print ''; + + print ''; } if ($action == 'create') @@ -689,7 +687,7 @@ if ($action == 'create') print_titre($langs->trans("NewMember")); - print '
'; + print ''; print ''; print ''; @@ -704,7 +702,7 @@ if ($action == 'create') // Login print ''; - + // Mot de passe $generated_password=''; if ($conf->global->USER_PASSWORD_GENERATED) @@ -727,7 +725,7 @@ if ($action == 'create') { $htmls->select_array("type", $listetype, $typeid); } else { - print ''.$langs->trans("NoTypeDefinedGoToSetup").''; + print ''.$langs->trans("NoTypeDefinedGoToSetup").''; } print "\n"; @@ -740,11 +738,11 @@ if ($action == 'create') print "\n"; print ''; - + // Adresse print ''; - + // CP / Ville print ''; @@ -752,7 +750,7 @@ if ($action == 'create') print ''; - + // Tel pro print ''; @@ -818,15 +816,28 @@ if ($rowid && $action != 'edit') if ($msg) print '
'.$msg.'
'; + // Confirm create user + if ($_GET["action"] == 'create_user') + { + $login=$adh->login; + if (empty($login)) $login=strtolower(substr($adh->prenom, 0, 4)) . strtolower(substr($adh->nom, 0, 4)); - // Confirmation de la suppression de l'adherent + // Create a form array + $formquestion=array( + array('label' => $langs->trans("LoginToCreate"), 'type' => 'text', 'name' => 'login', 'value' => $login)); + + $html->form_confirm($_SERVER["PHP_SELF"]."?rowid=".$adh->id,$langs->trans("CreateDolibarrLogin"),$langs->trans("ConfirmCreateContact"),"confirm_create_user",$formquestion); + print '
'; + } + + // Confirm remove member if ($action == 'delete') { $html->form_confirm("fiche.php?rowid=$rowid",$langs->trans("DeleteMember"),$langs->trans("ConfirmDeleteMember"),"confirm_delete"); print '
'; } - // Confirmation de la validation + // Confirm validate memeber if ($action == 'valid') { // Cree un tableau formulaire @@ -837,18 +848,18 @@ if ($rowid && $action != 'edit') print '
'; } - // Confirmation de l'envoi fiche par mail + // Confirm send card by mail if ($action == 'sendinfo') { $html->form_confirm("fiche.php?rowid=$rowid",$langs->trans("SendCardByMail"),$langs->trans("ConfirmSendCardByMail"),"confirm_sendinfo"); print '
'; } - // Confirmation de la Resiliation + // Confirm resiliate if ($action == 'resign') { $langs->load("mails"); - + // Cree un tableau formulaire $formquestion=array(); $label=$langs->trans("SendAnEMailToMember").' ('.$langs->trans("MailFrom").': '.$conf->global->ADHERENT_MAIL_FROM.', '; @@ -861,7 +872,7 @@ if ($rowid && $action != 'edit') } /* - * Confirmation de l'ajout dans spip + * Confirm add in spip */ if ($action == 'add_spip') { @@ -870,7 +881,7 @@ if ($rowid && $action != 'edit') } /* - * Confirmation de la suppression dans spip + * Confirm removed from spip */ if ($action == 'del_spip') { @@ -915,7 +926,7 @@ if ($rowid && $action != 'edit') // Type print '\n"; - + // Morphy print ''; @@ -924,7 +935,7 @@ if ($rowid && $action != 'edit') // Adresse print ''; - + // CP / Ville print ''; @@ -939,16 +950,16 @@ if ($rowid && $action != 'edit') // Tel mobile print ''; - + // EMail print ''; // Date naissance print ''; - + // Public print ''; - + // Status print ''; @@ -964,25 +975,25 @@ if ($rowid && $action != 'edit') else print $langs->trans("NoDolibarrAccess"); print ''; - + // Other attributs foreach($adho->attribute_label as $key=>$value) { print "\n"; } - + print "
'.$langs->trans("Login").'*
'.$langs->trans("Company").'
'.$langs->trans("Address").''; print '
'.$langs->trans("Zip").' / '.$langs->trans("Town").'
'.$langs->trans("Country").''; $htmls->select_pays($adh->pays_id ? $adh->pays_id : $mysoc->pays_id,'pays_id'); print '
'.$langs->trans("PhonePro").'
'.$langs->trans("Type").''.$adht->getNomUrl(1)."
'.$langs->trans("Person").''.$adh->getmorphylib().'
'.$langs->trans("Address").''.nl2br($adh->adresse).' 
'.$langs->trans("Zip").' / '.$langs->trans("Town").''.$adh->cp.' '.$adh->ville.' 
'.$langs->trans("PhoneMobile").''.dol_print_phone($adh->phone_mobile,$adh->pays_code).'
'.$langs->trans("EMail").''.dol_print_email($adh->email,0,0,1).' 
'.$langs->trans("Birthday").''.dolibarr_print_date($adh->naiss,'day').' 
'.$langs->trans("Public").''.yn($adh->public).'
'.$langs->trans("Status").''.$adh->getLibStatut(4).'
$value".$adh->array_options["options_$key"]." 
\n"; print '
'; - + print "\n"; - + /* * Barre d'actions * */ print '
'; - + // Modify if ($user->rights->adherent->creer || ($user->rights->adherent->self->creer && $adh->user_id == $user->id)) { @@ -992,7 +1003,7 @@ if ($rowid && $action != 'edit') { print "".$langs->trans("Modify").""; } - + // Valider if ($adh->statut == -1) { @@ -1005,7 +1016,7 @@ if ($rowid && $action != 'edit') print "".$langs->trans("Validate").""; } } - + // Reactiver if ($adh->statut == 0) { @@ -1018,7 +1029,7 @@ if ($rowid && $action != 'edit') print "".$langs->trans("Reenable").""; } } - + // Envoi fiche par mail if ($adh->statut >= 1 && $adh->email) { @@ -1031,7 +1042,7 @@ if ($rowid && $action != 'edit') print "".$langs->trans("SendCardByMail").""; } } - + // Resilier if ($adh->statut >= 1) { @@ -1044,7 +1055,7 @@ if ($rowid && $action != 'edit') print "".$langs->trans("Resiliate").""; } } - + // Create user if (! $user->societe_id && ! $adh->user_id) { @@ -1057,7 +1068,7 @@ if ($rowid && $action != 'edit') print "".$langs->trans("CreateDolibarrLogin").""; } } - + // Supprimer if ($user->rights->adherent->supprimer) { @@ -1067,7 +1078,7 @@ if ($rowid && $action != 'edit') { print "".$langs->trans("Delete").""; } - + // Action SPIP if ($conf->global->ADHERENT_USE_SPIP) { @@ -1084,27 +1095,27 @@ if ($rowid && $action != 'edit') print '
Failed to connect to SPIP: '.$adh->error.''; } } - + print '
'; print "
\n"; - - - + + + /* * Bandeau des cotisations * */ - + print ''; - + print ''; print ''; print '
'; - + print ''; - + print '
'; - + } diff --git a/htdocs/contact/fiche.php b/htdocs/contact/fiche.php index 384dd7e3c9e..63c738faf93 100644 --- a/htdocs/contact/fiche.php +++ b/htdocs/contact/fiche.php @@ -265,7 +265,7 @@ if ($user->rights->societe->contact->creer) } else { print ''.$langs->trans("Company").''; - print $form->select_societes('','socid','',1); + print $form->select_societes('','socid','',1); //print $form->select_societes('','socid',''); //print $langs->trans("ContactNotLinkedToCompany"); print ''; @@ -313,7 +313,7 @@ if ($user->rights->societe->contact->creer) $selectarray=array('0'=>$langs->trans("ContactPublic"),'1'=>$langs->trans("ContactPrivate")); $form->select_array('priv',$selectarray,$contact->priv,0); print ''; - + // Note print ''.$langs->trans("Note").''; @@ -473,7 +473,7 @@ if ($_GET["id"] && $_GET["action"] != 'edit') * Fiche en mode visualisation * */ - if ($msg) + if ($msg) { $langs->load("errors"); print '
'.$langs->trans($msg).'
'; @@ -482,15 +482,15 @@ if ($_GET["id"] && $_GET["action"] != 'edit') if ($_GET["action"] == 'create_user') { $login=strtolower(substr($contact->prenom, 0, 4)) . strtolower(substr($contact->nom, 0, 4)); - - // Cr�e un tableau formulaire + + // Create a form array $formquestion=array( array('label' => $langs->trans("LoginToCreate"), 'type' => 'text', 'name' => 'login', 'value' => $login)); - + $form->form_confirm($_SERVER["PHP_SELF"]."?id=".$contact->id,$langs->trans("CreateDolibarrLogin"),$langs->trans("ConfirmCreateContact"),"confirm_create_user",$formquestion); print '
'; } - + print ''; // Ref @@ -558,7 +558,7 @@ if ($_GET["id"] && $_GET["action"] != 'edit') print ''; - + print ''; diff --git a/htdocs/user.class.php b/htdocs/user.class.php index ce054d38520..304e4dec5a1 100644 --- a/htdocs/user.class.php +++ b/htdocs/user.class.php @@ -637,7 +637,7 @@ class User extends CommonObject $sql = "UPDATE ".MAIN_DB_PREFIX."socpeople SET fk_user_creat = null WHERE rowid = ".$this->contact_id; if ($this->db->query($sql)) { - + } } @@ -797,7 +797,6 @@ class User extends CommonObject if (empty($login)) $login=strtolower(substr($contact->prenom, 0, 4)) . strtolower(substr($contact->nom, 0, 4)); $this->login = $login; - $this->db->begin(); // Cree et positionne $this->id @@ -839,21 +838,22 @@ class User extends CommonObject /** * \brief Cree en base un utilisateur depuis l'objet adherent * \param member Objet adherent source + * \param login Login to force * \return int Si erreur <0, si ok renvoie id compte cree */ - function create_from_member($member) + function create_from_member($member,$login='') { global $conf,$user,$langs; // Positionne parametres + $this->admin = 0; $this->nom = $member->nom; $this->prenom = $member->prenom; - - $this->login = $member->login; - $this->pass = $member->pass; - $this->admin = 0; - $this->email = $member->email; + $this->pass = $member->pass; + + if (empty($login)) $login=strtolower(substr($member->prenom, 0, 4)) . strtolower(substr($member->nom, 0, 4)); + $this->login = $login; $this->db->begin(); @@ -1339,7 +1339,7 @@ class User extends CommonObject } $this->clicktodial_loaded = 1; // Data loaded (found or not) - + $this->db->free($resql); return 1; }
'.$langs->trans("ContactVisibility").''; print $contact->LibPubPriv($contact->priv); print '
'.$langs->trans("Note").''; print nl2br($contact->note); print '