X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;f=philter%2Fphilter%2Finclude%2Femails.inc.php;h=f699f2ca1c5cf497806260209d667b3a33b8f1b7;hb=deccde633d03e7c8cf186f47851684c932f88ddc;hp=dee810f541fcda2306af2e900bd13205068adfe7;hpb=dd8de1ec2684f9cd9616e97bbbdda114bc813097;p=old-projects.git
diff --git a/philter/philter/include/emails.inc.php b/philter/philter/include/emails.inc.php
index dee810f..f699f2c 100644
--- a/philter/philter/include/emails.inc.php
+++ b/philter/philter/include/emails.inc.php
@@ -37,6 +37,8 @@ class Email {
* @return true if the string is a valid email, false else
*/
function Check($_string) {
+ if(function_exists('isvalid_email_redirection'))
+ return isvalid_email_redirection($_string);
return preg_match("/^[\w\-.]+(\+[\w\-.]+)?@[\w\-.]+\.[a-zA-Z]{2,44}$/", $_string);
}
@@ -54,7 +56,7 @@ class Email {
function toggle_flag($_flag) {
$flags = explode(",", $this->flags);
$key = array_search($_flag,$flags);
- if($key===false)
+ if($key===NULL || $key===false)
$flags[]=$_flag;
else
unset($flags[$key]);
@@ -97,31 +99,76 @@ class EmailPool {
* @return the string containing the form
*/
function to_form() {
- $res = "
\n";
+ return $res;
+ }
+
+ /** create the part of the small form for the mail pool.
+ * @return the string containing the form
+ */
+ function to_small_form() {
+ $res = "\n";
return $res;
}
@@ -160,7 +207,7 @@ class EmailPool {
// we check that the email is not already there
foreach($this->emails as $id=>$key)
if($key->email == $new_mail) {
- $philter->set_error("$new_mail is already in the Email Pool");
+ $philter->set_error("$new_mail "._i18n('pool_err_already'));
return false;
}
@@ -170,7 +217,35 @@ class EmailPool {
$this->emails[$mid]->commit($this->uid, $mid);
uasort($this->emails, "email_cmp");
} else {
- $philter->set_error($_POST['emails']['new']." is not a valid email");
+ $philter->set_error($_POST['emails']['new'].' '._i18n('pool_err_not_valid'));
+ return false;
+ }
+ } elseif(isset($_POST['emails']['del']) && $_POST['emails']['del'] != -1) { // delete one email
+ $del_id = $_POST['emails']['del'];
+ // we compute a list of all actives emails
+ $allow = false;
+
+ foreach($this->emails as $id=>$mail) {
+ if($del_id!=$id && $mail->is_active()) {
+ $allow = true;
+ break;
+ }
+ }
+
+ if($allow && isset($this->emails[$del_id])) {
+ list($count) = mysql_fetch_row(mysql_query("SELECT COUNT(*) FROM actions "
+ ."WHERE uid='{$this->uid}' AND pid='"
+ .FwdPlugin::rtti()."' AND data='$del_id'"));
+ if($count) {
+ $philter->set_error(_i18n('pool_err_active'));
+ return false;
+ } else {
+ mysql_query("DELETE FROM emails WHERE uid='{$this->uid}' "
+ ."AND email='{$this->emails[$del_id]->email}'");
+ unset($this->emails[$del_id]);
+ }
+ } else {
+ $philter->set_error(_i18n('pool_err_need_one'));
return false;
}
} elseif(isset($_POST['emails']['apply'])) { // apply actives changes
@@ -182,44 +257,47 @@ class EmailPool {
}
if(!$one_active) {
- $philter->set_error("you must have at least one active email !");
+ $philter->set_error(_i18n('pool_err_need_one'));
return false;
}
- foreach($this->emails as $id=>$key)
+ foreach($this->emails as $id=>$key) {
if(isset($_POST['emails'][$id]['active']) xor $this->emails[$id]->is_active()) {
$this->emails[$id]->toggle_flag('active');
$this->emails[$id]->commit($this->uid, $id);
}
- } else { // delete one email
- // we compute a list of all actives emails
- $actives = array();
- foreach($this->emails as $id=>$mail)
- if($mail->is_active())
- $actives[$id] = true;
-
- foreach($this->emails as $id=>$key)
- if(isset($_POST['emails'][$id]['del'])) {
- if(count($this->emails)>0 && (count($actives)>1 || empty($actives[$id]))) {
- list($count) = mysql_fetch_row(mysql_query("SELECT COUNT(*) FROM actions "
- ."WHERE uid='{$this->uid}' AND pid='"
- .FwdPlugin::rtti()."' AND data='$id'"));
- if($count) {
- $philter->set_error("This email is still in use and can't be deleted !");
- return false;
- } else {
- mysql_query("DELETE FROM emails WHERE uid='{$this->uid}' "
- ."AND email='{$this->emails[$id]->email}'");
- unset($this->emails[$id]);
- unset($actives[$id]);
- }
- } else {
- $philter->set_error("you must have at least one active email !");
+ }
+ return true;
+ }
+ }
+
+ /** handle the data from the small form
+ * @return true if all is ok, false and sets $philter->error() else
+ */
+ function handle_small_form() {
+ global $philter;
+
+ if(isset($_POST['emails']['add'])) { // add an email to the pool
+ if(Email::Check($_POST['emails']['new'])) {
+ $new_mail = strtolower($_POST['emails']['new']);
+
+ // we check that the email is not already there
+ foreach($this->emails as $id=>$key)
+ if($key->email == $new_mail) {
+ $philter->set_error("$new_mail "._i18n('pool_err_already'));
return false;
}
- }
+
+ // then we compute one free id, and we add it to the list
+ $mid = $this->new_mail_id();
+ $this->emails[$mid] = new Email($new_mail, '');
+ $this->emails[$mid]->commit($this->uid, $mid);
+ uasort($this->emails, "email_cmp");
+ } else {
+ $philter->set_error($_POST['emails']['new'].' '._i18n('pool_err_not_valid'));
+ return false;
+ }
}
- return true;
}
}