- LSattr_html_maildir & LSformElement_maildir :

-> Refonte pour passer la gestion des bindings depuis l'attribut HTML
		 et ainsi pouvoir gérer la suppression/archivage de la boite mail lors
		 de la suppression d'un objet (hors LSform et donc sans LSformElement)
This commit is contained in:
Benjamin Renard 2009-04-01 15:55:13 +00:00
parent b4beb767b0
commit 6c61f671f5
2 changed files with 104 additions and 67 deletions

View file

@ -20,6 +20,8 @@
******************************************************************************/ ******************************************************************************/
LSsession :: loadLSaddon('maildir');
/** /**
* Type d'attribut HTML maildir * Type d'attribut HTML maildir
* *
@ -28,6 +30,104 @@
class LSattr_html_maildir extends LSattr_html { class LSattr_html_maildir extends LSattr_html {
var $LSformElement_type = 'maildir'; var $LSformElement_type = 'maildir';
var $_toDo = array();
function LSattr_html_maildir ($name,$config,&$attribute) {
$attribute -> addObjectEvent('before_delete',$this,'beforeDelete');
$attribute -> addObjectEvent('after_delete',$this,'deleteMaildirByFTP');
return parent :: LSattr_html($name,$config,&$attribute);
}
public function doOnModify($action,$cur,$new) {
$this -> _toDo = array (
'action' => $action,
'old' => $cur,
'new' => $new
);
$this -> attribute -> addObjectEvent('after_modify',$this,'toDo');
}
function toDo() {
if (is_array($this -> _toDo)) {
switch($this -> _toDo['action']) {
case 'delete':
return $this -> deleteMaildirByFTP();
break;
case 'modify':
if (renameMaildirByFTP($this -> _toDo['old'],$this -> _toDo['new'])) {
LSsession :: addInfo(_("The mailbox has been moved."));
return true;
}
return;
break;
case 'create':
if (createMaildirByFTP(null,$this -> _toDo['new'])) {
LSsession :: addInfo(_("The mailbox has been created."));
return true;
}
return;
break;
default:
LSdebug($this -> name.' - LSformElement_maildir->toDo() : Unknown action.');
}
}
LSdebug($this -> name.' - LSformElement_maildir->toDo() : Nothing to do.');
return true;
}
public function deleteMaildirByFTP() {
if ($this -> config['html_options']['archiveNameFormat']) {
LSdebug('LSformElement_maildir : archive');
$newname=getFData($this -> config['html_options']['archiveNameFormat'],$this -> _toDo['old']);
if ($newname) {
if (renameMaildirByFTP($this -> _toDo['old'],$newname)) {
LSsession :: addInfo(_("The mailbox has been archived successfully."));
return true;
}
return;
}
LSdebug($this -> name." - LSformElement_maildir->toDo() : Incorrect archive name.");
return;
}
else {
LSdebug('LSformElement_maildir : delete');
if (removeMaildirByFTP(null,$this -> _toDo['old'])) {
LSsession :: addInfo(_("The mailbox has been deleted."));
return true;
}
return;
}
}
public function beforeDelete() {
$this -> _toDo = array (
'action' => 'delete',
'old' => $this -> getRemoteRootPathRegex(),
'new' => ''
);
}
public function getRemoteRootPathRegex($val='LS') {
if ($val=='LS') {
$val = $this -> attribute -> getValue();
$val=$val[0];
}
LSdebug($this -> config['html_options']['remoteRootPathRegex']);
if ($this -> config['html_options']['remoteRootPathRegex']) {
if (
ereg($this -> config['html_options']['remoteRootPathRegex'],$val,$r)
||
empty($val)
)
{
$val = $r[1];
}
else {
LSdebug('Pbl remoteRootPathRegex');
}
}
return $val;
}
} }

View file

@ -21,7 +21,6 @@
******************************************************************************/ ******************************************************************************/
LSsession :: loadLSclass('LSformElement_text'); LSsession :: loadLSclass('LSformElement_text');
LSsession :: loadLSaddon('maildir');
/** /**
* Element maildir d'un formulaire pour LdapSaisie * Element maildir d'un formulaire pour LdapSaisie
@ -106,77 +105,15 @@ class LSformElement_maildir extends LSformElement_text {
} }
if ($action) { if ($action) {
if ($this -> params['html_options']['remoteRootPathRegex']) { $new = $this -> attr_html -> getRemoteRootPathRegex($new);
if ( $cur = $this -> attr_html -> getRemoteRootPathRegex($cur);
(ereg($this -> params['html_options']['remoteRootPathRegex'],$new,$r_new) ||empty($new)) $this -> attr_html -> doOnModify($action,$cur,$new);
&&
(ereg($this -> params['html_options']['remoteRootPathRegex'],$cur,$r_cur)||empty($cur))
)
{
$new = $r_new[1];
$cur = $r_cur[1];
}
else {
LSdebug('Pbl remoteRootPathRegex');
}
}
$this -> _toDo = array (
'action' => $action,
'old' => $cur,
'new' => $new
);
$this -> attr_html -> attribute -> addObjectEvent('after_modify',$this,'toDo');
} }
} }
} }
return $retval; return $retval;
} }
function toDo() {
if (is_array($this -> _toDo)) {
switch($this -> _toDo['action']) {
case 'delete':
if ($this -> params['html_options']['archiveNameFormat']) {
$newname=getFData($this -> params['html_options']['archiveNameFormat'],$this -> _toDo['old']);
if ($newname) {
if (renameMaildirByFTP($this -> _toDo['old'],$newname)) {
LSsession :: addInfo(_("The mailbox has been archived successfully."));
return true;
}
return;
}
LSdebug($this -> name." - LSformElement_maildir->toDo() : Incorrect archive name.");
return;
}
else {
if (removeMaildirByFTP(null,$this -> _toDo['old'])) {
LSsession :: addInfo(_("The mailbox has been deleted."));
return true;
}
return;
}
break;
case 'modify':
if (renameMaildirByFTP($this -> _toDo['old'],$this -> _toDo['new'])) {
LSsession :: addInfo(_("The mailbox has been moved."));
return true;
}
return;
break;
case 'create':
if (createMaildirByFTP(null,$this -> _toDo['new'])) {
LSsession :: addInfo(_("The mailbox has been created."));
return true;
}
return;
break;
default:
LSdebug($this -> name.' - LSformElement_maildir->toDo() : Unknown action.');
}
}
LSdebug($this -> name.' - LSformElement_maildir->toDo() : Nothing to do.');
return true;
}
} }
?> ?>