New: Can choose login of dolibarr account created when create from contact

This commit is contained in:
Laurent Destailleur 2008-12-17 18:34:47 +00:00
parent 1fd45ffec8
commit ec98799c14
6 changed files with 97 additions and 84 deletions

View File

@ -38,6 +38,7 @@ For users:
- Show greyed lines for not allowed export filters. - Show greyed lines for not allowed export filters.
- Add nature in product fields (manufactured product or not). - Add nature in product fields (manufactured product or not).
- Add export filters for category module. - Add export filters for category module.
- Can choose login of dolibarr account created when create from contact
For translators: For translators:
- The errors language file contains only error or warning messages with - The errors language file contains only error or warning messages with

View File

@ -51,9 +51,7 @@ $result = restrictedArea($user, 'contact', $contactid, 'socpeople');
*/ */
// Creation utilisateur depuis contact // Creation utilisateur depuis contact
if ($user->rights->user->user->creer) if ($_POST["action"] == 'confirm_create_user' && $_POST["confirm"] == 'yes' && $user->rights->user->user->creer)
{
if ($_GET["action"] == 'create_user')
{ {
// Recuperation contact actuel // Recuperation contact actuel
$contact = new Contact($db); $contact = new Contact($db);
@ -63,7 +61,7 @@ if ($user->rights->user->user->creer)
{ {
// Creation user // Creation user
$nuser = new User($db); $nuser = new User($db);
$result=$nuser->create_from_contact($contact); $result=$nuser->create_from_contact($contact,$_POST["login"]);
if ($result < 0) if ($result < 0)
{ {
@ -75,12 +73,9 @@ if ($user->rights->user->user->creer)
$msg=$contact->error; $msg=$contact->error;
} }
} }
}
// Creation contact // Creation contact
if ($user->rights->societe->contact->creer) if ($_POST["action"] == 'add' && $user->rights->societe->contact->creer)
{
if ($_POST["action"] == 'add')
{ {
$contact = new Contact($db); $contact = new Contact($db);
@ -125,11 +120,8 @@ if ($user->rights->societe->contact->creer)
} }
} }
} }
}
if ($user->rights->societe->contact->supprimer) if ($_POST["action"] == 'confirm_delete' && $_POST["confirm"] == 'yes' && $user->rights->societe->contact->supprimer)
{
if ($_POST["action"] == 'confirm_delete' AND $_POST["confirm"] == 'yes')
{ {
$contact = new Contact($db); $contact = new Contact($db);
$result=$contact->fetch($_GET["id"]); $result=$contact->fetch($_GET["id"]);
@ -142,11 +134,8 @@ if ($user->rights->societe->contact->supprimer)
Header("Location: index.php"); Header("Location: index.php");
exit; exit;
} }
}
if ($user->rights->societe->contact->creer) if ($_POST["action"] == 'update' && ! $_POST["cancel"] && $user->rights->societe->contact->creer)
{
if ($_POST["action"] == 'update' && ! $_POST["cancel"])
{ {
$contact = new Contact($db); $contact = new Contact($db);
@ -186,7 +175,6 @@ if ($user->rights->societe->contact->creer)
$error = $contact->error; $error = $contact->error;
} }
} }
}
/* /*
@ -484,7 +472,23 @@ if ($_GET["id"] && $_GET["action"] != 'edit')
* Fiche en mode visualisation * Fiche en mode visualisation
* *
*/ */
if ($msg) print '<div class="error">'.$msg.'</div>'; if ($msg)
{
$langs->load("errors");
print '<div class="error">'.$langs->trans($msg).'</div>';
}
if ($_GET["action"] == 'create_user')
{
$login=strtolower(substr($contact->prenom, 0, 4)) . strtolower(substr($contact->nom, 0, 4));
// Crée un tableau formulaire
$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 '<br>';
}
print '<table class="border" width="100%">'; print '<table class="border" width="100%">';

View File

@ -1491,6 +1491,7 @@ class Form
{ {
global $langs; global $langs;
print "\n<!-- begin form_confirm -->\n";
print '<form method="post" action="'.$page.'" class="notoptoleftroright">'; print '<form method="post" action="'.$page.'" class="notoptoleftroright">';
print '<input type="hidden" name="action" value="'.$action.'">'; print '<input type="hidden" name="action" value="'.$action.'">';
@ -1574,6 +1575,8 @@ class Form
} }
print "</form>\n"; print "</form>\n";
print "\n<!-- end form_confirm -->\n";
} }

View File

@ -93,3 +93,5 @@ UserDeleted=User %s removed
NewGroupCreated=Group %s created NewGroupCreated=Group %s created
GroupModified=Group %s modified GroupModified=Group %s modified
GroupDeleted=Group %s removed GroupDeleted=Group %s removed
ConfirmCreateContact=Are you sure yu want to create a Dolibarr account for this contact ?
LoginToCreate=Login to create

View File

@ -93,3 +93,5 @@ UserDeleted=Suppression utilisateur %s
NewGroupCreated=Création groupe %s NewGroupCreated=Création groupe %s
GroupModified=Modification groupe %s GroupModified=Modification groupe %s
GroupDeleted=Suppression groupe %s GroupDeleted=Suppression groupe %s
ConfirmCreateContact=Etes vous sur de vouloir créer un compte Dolibarr pour ce contact ?
LoginToCreate=Login à créer

View File

@ -781,26 +781,27 @@ class User extends CommonObject
/** /**
* \brief Cree en base un utilisateur depuis l'objet contact * \brief Cree en base un utilisateur depuis l'objet contact
* \param contact Objet du contact source * \param contact Objet du contact source
* \param login Login to force
* \return int si erreur <0, si ok renvoie id compte cree * \return int si erreur <0, si ok renvoie id compte cree
*/ */
function create_from_contact($contact) function create_from_contact($contact,$login='')
{ {
global $user,$langs; global $user,$langs;
// Positionne parametres // Positionne parametres
$this->admin = 0;
$this->nom = $contact->nom; $this->nom = $contact->nom;
$this->prenom = $contact->prenom; $this->prenom = $contact->prenom;
$this->login = strtolower(substr($contact->prenom, 0, 4)) . strtolower(substr($contact->nom, 0, 4));
$this->admin = 0;
$this->email = $contact->email; $this->email = $contact->email;
if (empty($login)) $login=strtolower(substr($contact->prenom, 0, 4)) . strtolower(substr($contact->nom, 0, 4));
$this->login = $login;
$this->db->begin(); $this->db->begin();
// Cree et positionne $this->id // Cree et positionne $this->id
$result=$this->create($user); $result=$this->create($user);
if ($result > 0) if ($result > 0)
{ {
$sql = "UPDATE ".MAIN_DB_PREFIX."user"; $sql = "UPDATE ".MAIN_DB_PREFIX."user";