small pool of emails for the filter screen
authorPierre Habouzit <madcoder@debian.org>
Thu, 11 Sep 2003 16:06:57 +0000 (16:06 +0000)
committerPierre Habouzit <madcoder@debian.org>
Thu, 11 Sep 2003 16:06:57 +0000 (16:06 +0000)
philter/philter/include/emails.inc.php
philter/philter/include/form_filter.inc.php
philter/philter/locales/philter.fr.inc.php

index b7905f2..f699f2c 100644 (file)
@@ -141,6 +141,38 @@ class EmailPool {
         return $res;
     }
 
+    /** create the part of the small form for the mail pool.
+     * @return  the string containing the form
+     */
+    function to_small_form() {
+        $res = "<form id=\"emails\" action=\"{$_SERVER['REQUEST_URI']}\" method=\"post\">\n"
+            .  "<table class=\"bicol\" cellpadding=\"1\" cellspacing=\"1\" width=\"95%\" align=\"center\">\n"
+            .  "<tr><th>"._i18n('email')."</th>\n"
+            .  "</tr>\n";
+
+        $pair = true;
+
+        foreach($this->emails as $id => $email) {
+            
+            $res .= "<tr class=\"".($pair?"pair":"impair")."\">\n"
+                .   "<td>".($email->is_active() ? "<strong>" : "")
+                    .$email->email.($email->is_active() ? "</strong>" : "")."</td>\n"
+                .   "</tr>\n";
+            $pair = !$pair;
+        }
+
+        $val = _i18n('your_email');
+        $res .= "<tr><th>\n"
+            .   "<input type=\"text\" name=\"emails[new]\" size=\"50\" value='$val' "
+            .   "    onfocus=\"text_onfocus(this,'$val')\" onblur=\"text_onblur(this,'$val')\" />\n"
+            .   "<input type=\"submit\" name=\"emails[add]\" value=\""._i18n('add')."\" />\n"
+            .   "</th></tr>\n"
+            .   "</table>\n"
+            .   "</form>\n";
+
+        return $res;
+    }
+
     /** return the string containing the list of $this->emails in javascript.
      * @return  the JS code
      */
@@ -238,6 +270,35 @@ class EmailPool {
         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;
+            }
+        }
+    }
 }
 
 /********************************************************************************
index 97bf2ce..1e6a5d7 100644 (file)
@@ -1,5 +1,8 @@
 <?php
 if(count($_POST)) {                             // a FORM has been submitted
+    if(isset($_POST['emails']))                 //      FORM emails
+        if(!$mail_pool->handle_small_form())
+            echo "<p style=\"color:red;\">".$philter->error()."</p>\n";
     if(!empty($_POST['order']['action']))       //      FORM order
         if($_POST['order']['action']=='submit') {
             foreach($filter->rules as $id=>$rule)
@@ -10,12 +13,13 @@ if(count($_POST)) {                             // a FORM has been submitted
             $filter->delete_rule($_POST['order']['select']);
             unset($_POST['order']['select']);
         }
-    if(!empty($_POST['rule']))
+    if(!empty($_POST['rule']))                  //      FORM rule
         if(!$filter->handle_form())
             echo "<p style=\"color:red;\">".$philter->error()."</p>\n";
 }
 
 require("include/js_factory.inc.php");
+
 ?>
 <div class="rubrique"><?php i18n('filter_sync'); ?></div>
 <?php i18n('filter_sync_txt') ?>
@@ -26,6 +30,12 @@ require("include/js_factory.inc.php");
 </center>
 </form>
 <br />
+<div class="rubrique"><?php i18n('pool_title'); ?></div>
+<?php
+i18n('small_pool_help');
+echo $mail_pool->to_small_form();
+?>
+<br />
 <div class="rubrique"><?php i18n('filter_title'); ?></div>
 <?php
 i18n('filter_help');
index f77f961..20ffc56 100644 (file)
@@ -28,6 +28,9 @@ $philter->config['i18n'] = Array(
     'pool_err_active' => 'Cet email est encore utilisé et ne peut pas être supprimé !',
     'pool_err_need_one' => 'Tu dois avoir au moins un email actif !',
     
+    'spool_help' => '<p class="normal">Tu peux ajouter ici des adresses mails utilisabels dans ton
+        filtre. Ces adresses mails sont ajoutées comme inactives dans ton filtre global.</p>
+        <p class="normal">Les adresses en gras sont tes addresses actives</p>',
     'pool_help' => '<p class="normal">Tu configures ici les adresses emails vers lesquelles
         tu rediriges ton courrier.</p>
         <p class="normal">Toutes les modifications faites sur cette page sont immédiatement prises