X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;f=philter%2Fphilter%2Finclude%2Femails.inc.php;h=15935eb62b8358ccdd657653018cacb2ec2da1c2;hb=4956445bb7da02adee93a10bcc6d038d1f676cb2;hp=e83b5b4bdc2fd1602f9d0a1c053a672a0da2d977;hpb=86b5093c27b4c24bf77edd715ed30967e89ff08f;p=old-projects.git diff --git a/philter/philter/include/emails.inc.php b/philter/philter/include/emails.inc.php index e83b5b4..15935eb 100644 --- a/philter/philter/include/emails.inc.php +++ b/philter/philter/include/emails.inc.php @@ -97,7 +97,7 @@ class EmailPool { * @return the string containing the form */ function to_form() { - $res = "
\n" + $res = "\n" . "\n" . "\n" . " \n" @@ -112,13 +112,15 @@ class EmailPool { . "\n" - . "\n" + . "\n" . "\n"; $pair = !$pair; } $res .= "
EmailActive\n" . " is_active() ? " checked=\"checked\"" : "")." />
\n" . "
\n" + . " \n" . " \n" . "
\n" . "
\n"; @@ -181,8 +183,33 @@ class EmailPool { $philter->set_error($_POST['emails']['new']." is not a valid email"); return false; } + } elseif(!empty($_POST['emails']['del'])) { // 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; + + 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("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[$del_id]->email}'"); + unset($this->emails[$del_id]); + } + } else { + $philter->set_error("you must have at least one active email !"); + return false; + } } elseif(isset($_POST['emails']['apply'])) { // apply actives changes $one_active = false; + foreach($this->emails as $id=>$mail) if(isset($_POST['emails'][$id]['active'])) { $one_active = true; @@ -199,35 +226,8 @@ class EmailPool { $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 false; - } - } - } return true; + } } }