issue #0001914 : Gestion des emails secondaires lors de la modification du compte utilisateur
This commit is contained in:
parent
6c6d3f1f15
commit
7dd7e2f6ec
@ -190,49 +190,98 @@ class UserController extends Zend_Controller_Action
|
||||
* Email length 80 * 3 = 240
|
||||
* 255 chars is the length to store emails (email1;email2;email3)
|
||||
*/
|
||||
public function emailsAction()
|
||||
{
|
||||
$this->_helper->layout()->disableLayout();
|
||||
|
||||
$nbEmails = 3;
|
||||
|
||||
$request = $this->getRequest();
|
||||
$emails = $request->getParam('q');
|
||||
|
||||
if (null !== $emails) {
|
||||
$emailList = explode(';', $emails);
|
||||
if ( count($emailList)>0 ) {
|
||||
$i = 1;
|
||||
foreach ( $emailList as $email ) {
|
||||
$this->view->assign('email'.$i, $email);
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate email
|
||||
*/
|
||||
public function emailvalidAction()
|
||||
public function emailAction()
|
||||
{
|
||||
$this->_helper->layout()->disableLayout();
|
||||
|
||||
$request = $this->getRequest();
|
||||
|
||||
$check = $request->getParam('check');
|
||||
$email = $request->getParam('q');
|
||||
|
||||
$valid = false;
|
||||
if ( $check == 1) {
|
||||
|
||||
$this->view->assign('checkemail', true);
|
||||
|
||||
$valid = false;
|
||||
|
||||
$this->view->assign('msg', 'Email invalide !');
|
||||
|
||||
if (null !== $email) {
|
||||
$validateur = new Zend_Validate_EmailAddress();
|
||||
$valid = $validateur->isValid($email);
|
||||
|
||||
if ( $valid ) {
|
||||
$this->view->assign('msg', 'Modification effectué.');
|
||||
$this->view->assign('email', $email);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
$this->view->assign('email', $email);
|
||||
|
||||
if (null !== $email) {
|
||||
$validateur = new Zend_Validate_EmailAddress();
|
||||
$valid = $validateur->isValid($email);
|
||||
}
|
||||
|
||||
$result = array(
|
||||
'valid' => $valid,
|
||||
);
|
||||
}
|
||||
|
||||
public function emailsecondaryAction()
|
||||
{
|
||||
$this->_helper->layout()->disableLayout();
|
||||
|
||||
$request = $this->getRequest();
|
||||
|
||||
$user = new Scores_Utilisateur();
|
||||
|
||||
$mode = $request->getParam('mode');
|
||||
$this->view->assign('mode', $mode);
|
||||
$email = $request->getParam('email');
|
||||
$login = $request->getParam('login', $user->getLogin());
|
||||
$this->view->assign('login', $login);
|
||||
|
||||
$idClient = $request->getParam('client', $user->getIdClient());
|
||||
|
||||
if ( $mode === null ) {
|
||||
|
||||
$ws = new WsScores();
|
||||
$result = $ws->getGestionEmail($login);
|
||||
$emails = array();
|
||||
if (count($result->item)>0) {
|
||||
$emails = $result->item;
|
||||
}
|
||||
$this->view->assign('emails', $emails);
|
||||
|
||||
} elseif ( $mode == 'set' ) {
|
||||
|
||||
$this->view->assign('msg', 'Email invalide !');
|
||||
|
||||
if (null !== $email) {
|
||||
$validateur = new Zend_Validate_EmailAddress();
|
||||
$valid = $validateur->isValid($email);
|
||||
|
||||
if ( $valid ) {
|
||||
$ws = new WsScores();
|
||||
$result = $ws->setGestionEmail($email, $login);
|
||||
if ( $result ) {
|
||||
$this->view->assign('msg', 'Modification effectué.');
|
||||
$this->view->assign('email', $email);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
} elseif ( $mode == 'del' ) {
|
||||
|
||||
$this->view->assign('msg', 'Erreur lors de la suppression !');
|
||||
|
||||
$ws = new WsScores();
|
||||
$result = $ws->setGestionEmail($email, $login, $id, $mode);
|
||||
if ( $result ) {
|
||||
$this->view->assign('msg', 'Adresse email supprimé.');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$this->view->assign('result', $result);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -421,7 +470,7 @@ class UserController extends Zend_Controller_Action
|
||||
|
||||
if ( $ajax == 0 ) {
|
||||
$this->view->assign('refresh', $refresh);
|
||||
//$this->view->headMeta()->appendHttpEquiv('refresh', $refresh.'; url='.$url);
|
||||
$this->view->headMeta()->appendHttpEquiv('refresh', $refresh.'; url='.$url);
|
||||
}
|
||||
}
|
||||
|
||||
|
52
application/views/default/scripts/user/email.phtml
Normal file
52
application/views/default/scripts/user/email.phtml
Normal file
@ -0,0 +1,52 @@
|
||||
<?php if ( $this->checkemail ) {?>
|
||||
|
||||
<strong><?=$this->msg?></strong>
|
||||
<input type="hidden" name="email" value="<?=$this->email?>"/>
|
||||
|
||||
<?php if ($this->email!='') {?>
|
||||
<p><i>Enregistrer les modifications en cliquant sur "Sauver", en bas de la page, après avoir fermer la fenêtre.</i></p>
|
||||
<?php }?>
|
||||
|
||||
<script>
|
||||
$('#dialog').dialog({ buttons: [
|
||||
{ text: "Fermer", click: function() {
|
||||
var email = $('#dialog input[name=email]').val();
|
||||
if (email!='') {
|
||||
$('div#email').html('<span>'+email+'</span>');
|
||||
$('input[name="frmOptions[email]"]').val(email);
|
||||
}
|
||||
$(this).dialog('close');
|
||||
} }
|
||||
]});
|
||||
</script>
|
||||
|
||||
<?php } else {?>
|
||||
|
||||
<style>
|
||||
#bloc-addemail { display:none; }
|
||||
</style>
|
||||
|
||||
<p>Email principal associé au compte utilisateur</p>
|
||||
|
||||
<form name="email" action="<?=$this->url(array('controller'=>'user', 'action'=>'email'), null, true)?>" method="post">
|
||||
|
||||
<label>Adresse Email principal :</label><br/>
|
||||
<input type="text" size="50" maxlength="80" name="q" value="<?=$this->email?>"/>
|
||||
<input type="hidden" name="check" value="1"/>
|
||||
|
||||
</form>
|
||||
|
||||
<script>
|
||||
$('#dialog').dialog({ buttons: [
|
||||
{ text: "Valider", click: function() {
|
||||
$.post($('form[name=email]').attr('action'), $('form[name=email]').serialize(), function(data){
|
||||
$('#dialog').html(data);
|
||||
}).fail(function() {
|
||||
$('#dialog').html('<strong>Unknown error</strong>');
|
||||
});
|
||||
} },
|
||||
{ text: "Quitter", click: function() { $(this).dialog('close'); } }
|
||||
]});
|
||||
</script>
|
||||
|
||||
<?php }?>
|
65
application/views/default/scripts/user/emailsecondary.phtml
Normal file
65
application/views/default/scripts/user/emailsecondary.phtml
Normal file
@ -0,0 +1,65 @@
|
||||
<?php if ( $this->msg ) {?>
|
||||
|
||||
<?=$this->msg?>
|
||||
<script>
|
||||
$('#dialog').dialog({ buttons: [
|
||||
{ text: "Fermer", click: function() { $(this).dialog('close'); } }
|
||||
]});
|
||||
</script>
|
||||
|
||||
<?php } elseif( $this->mode == 'add' ) {?>
|
||||
|
||||
<form name="email" action="<?=$this->url(array('controller'=>'user', 'action'=>'emailsecondary'), null, true)?>">
|
||||
<label>Saisisez l'email à ajouter : </label><br/>
|
||||
<input type="text" size="50" maxlength="80" name="email" value=""/>
|
||||
<input type="hidden" name="login" value="<?=$this->login?>">
|
||||
<input type="hidden" name="mode" value="set">
|
||||
</form>
|
||||
|
||||
<script>
|
||||
$('#dialog').dialog({ buttons: [
|
||||
{ text: "Valider", click: function() {
|
||||
$.post($('form[name=email]').attr('action'), $('form[name=email]').serialize(), function(data) {
|
||||
$('#dialog').html(data);
|
||||
});
|
||||
} },
|
||||
{ text: "Fermer", click: function() { $(this).dialog('close'); } }
|
||||
]});
|
||||
</script>
|
||||
|
||||
<?php } else {?>
|
||||
|
||||
<p>Emails secondaires associés au compte <strong><?=$this->login?></strong></p>
|
||||
|
||||
<?php if ( count($this->emails)>0 ) {?>
|
||||
<ul>
|
||||
<?php foreach ($this->emails as $email) {?>
|
||||
<li><?=$email->value?> (<a class="email-delete" href="<?=$this->url(array(
|
||||
'controller'=>'user', 'action'=>'emailsecondary', 'login'=>$this->login,
|
||||
'id'=>$email->id, 'email'=>$email->value, 'mode'=>'del'), null, true)?>">supprimer</a>)
|
||||
</li>
|
||||
<?php }?>
|
||||
</ul>
|
||||
<?php } else {?>
|
||||
<strong>Aucun email secondaire.</strong>
|
||||
<?php }?>
|
||||
|
||||
<script>
|
||||
$('#dialog').dialog({ buttons: [
|
||||
{ text: "Associer une nouvelle adresse email", click: function() {
|
||||
$.post('<?=$this->url(array('controller'=>'user', 'action'=>'emailsecondary', 'mode'=> 'add', 'login' => $this->login), null, true)?>', function(data) {
|
||||
$('#dialog').html(data);
|
||||
});
|
||||
} },
|
||||
{ text: "Fermer", click: function() { $(this).dialog('close'); } }
|
||||
]});
|
||||
|
||||
$('a.email-delete').on('click', function(e) {
|
||||
e.preventDefault();
|
||||
$.post($(this).attr('href'), function(data) {
|
||||
$('#dialog').html(data);
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
<?php }?>
|
@ -1 +1,3 @@
|
||||
<?=json_encode($this->result);?>
|
||||
|
||||
<strong><?=$this->msg?></strong>
|
||||
<input type="hidden" name="email" value="<?=$this->email?>"/>
|
@ -43,22 +43,51 @@ if ($this->action != 'new') {
|
||||
</div>
|
||||
|
||||
<div class="infoTitle StyleInfoLib">Adresse e-mail</div>
|
||||
<div class="infoData">
|
||||
<div class="infoData" id="email">
|
||||
<?php $emails = explode(';', $this->options->email); ?>
|
||||
<?php foreach ( $emails as $email ) {?>
|
||||
<span><?=$email?></span><br/>
|
||||
<?php }?>
|
||||
</div>
|
||||
<div style="float:left;">
|
||||
<button id="user-emails">Editer les emails</button>
|
||||
<button id="user-emails" data-href="<?=$this->url(array(
|
||||
'controller' => 'user', 'action' => 'email',
|
||||
'q' => $this->options->email,
|
||||
))?>">Editer e-mail du compte</button>
|
||||
<button id="user-emailsecondary" data-href="<?=$this->url(array(
|
||||
'controller' => 'user', 'action' => 'emailsecondary',
|
||||
'idClient' => $this->options->idClient,
|
||||
'login' => $this->loginVu,
|
||||
|
||||
))?>">Editer e-mails secondaires</button>
|
||||
<script>
|
||||
$('button#user-emails').button({
|
||||
icons: { primary: "ui-icon-pencil" },
|
||||
text: false
|
||||
}).click(function( event ) {
|
||||
event.preventDefault();
|
||||
$('button#user-emails').button({ icons: { primary: "ui-icon-pencil" }, text: false}).click(function(e) {
|
||||
e.preventDefault();
|
||||
var title = $(this).text();
|
||||
var href = '/user/emails/q/'+$('input[name="frmOptions[email]"]').val();
|
||||
var href = $(this).data('href');
|
||||
var dialogOpts = {
|
||||
bgiframe: true,
|
||||
title: title,
|
||||
width: 500,
|
||||
height: 300,
|
||||
modal: true,
|
||||
open: function(event, ui) {
|
||||
$(this).html('Chargement...');
|
||||
$(this).load(href);
|
||||
},
|
||||
buttons: {
|
||||
Quitter: function() { $(this).dialog('close'); }
|
||||
},
|
||||
close: function() { $('#dialog').remove(); }
|
||||
};
|
||||
$('<div id="dialog"></div>').dialog(dialogOpts);
|
||||
return false;
|
||||
|
||||
});
|
||||
$('button#user-emailsecondary').button({icons: { primary: "ui-icon-plusthick" }, text: false}).click(function(e) {
|
||||
e.preventDefault();
|
||||
var title = $(this).text();
|
||||
var href = $(this).data('href');;
|
||||
var dialogOpts = {
|
||||
bgiframe: true,
|
||||
title: title,
|
||||
|
@ -1072,6 +1072,54 @@ class WsScores
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get secondary email
|
||||
* @param string $login
|
||||
* @param int $id
|
||||
* @return boolean
|
||||
*/
|
||||
public function getGestionEmail($login, $id=null)
|
||||
{
|
||||
$params = new stdClass();
|
||||
$params->login = $login;
|
||||
$params->id = $id;
|
||||
$client = $this->loadClient('gestion');
|
||||
try {
|
||||
$reponse = $client->getEmail($params);
|
||||
Zend_Registry::get('firebug')->info($reponse);
|
||||
return $reponse->getEmailResult;
|
||||
} catch (SoapFault $fault) {
|
||||
$this->soaperror(__FUNCTION__, $fault, $client->__getLastRequest(), $client->__getLastResponse());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set secondary email
|
||||
* @param string $email
|
||||
* @param login $login
|
||||
* @param int $id
|
||||
* @param string $action
|
||||
* @return boolean
|
||||
*/
|
||||
public function setGestionEmail($email, $login, $id=null, $action = 'set')
|
||||
{
|
||||
$params = new stdClass();
|
||||
$params->email = $email;
|
||||
$params->login = $login;
|
||||
$params->idClient = $idClient;
|
||||
$params->id = $id;
|
||||
$params->action = $action;
|
||||
$client = $this->loadClient('gestion');
|
||||
try {
|
||||
$reponse = $client->setEmail($params);
|
||||
return $reponse->setEmailResult;
|
||||
} catch (SoapFault $fault) {
|
||||
$this->soaperror(__FUNCTION__, $fault, $client->__getLastRequest(), $client->__getLastResponse());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Retourne les infos du groupe
|
||||
* @param string $siren
|
||||
|
Loading…
Reference in New Issue
Block a user