various bugfixes
authorx2000habouzit <x2000habouzit>
Sat, 16 Oct 2004 22:06:32 +0000 (22:06 +0000)
committerx2000habouzit <x2000habouzit>
Sat, 16 Oct 2004 22:06:32 +0000 (22:06 +0000)
htdocs/admin/newsletter_edit.php
include/newsletter.inc.php
templates/admin/newsletter_edit.tpl

index 43ab984..8e39166 100644 (file)
@@ -18,7 +18,7 @@
  *  Foundation, Inc.,                                                      *
  *  59 Temple Place, Suite 330, Boston, MA  02111-1307  USA                *
  ***************************************************************************
-        $Id: newsletter_edit.php,v 1.2 2004-10-16 21:14:15 x2000habouzit Exp $
+        $Id: newsletter_edit.php,v 1.3 2004-10-16 22:06:32 x2000habouzit Exp $
  ***************************************************************************/
 
 require("auto.prepend.inc.php");
@@ -34,6 +34,7 @@ if(isset($_GET['del_aid'])) {
 
 if(isset($_POST['update'])) {
     $nl->_title = $_POST['title'];
+    $nl->_date = $_POST['date'];
     $nl->save();
 }
 
index b3b50b1..559d485 100644 (file)
  *  Foundation, Inc.,                                                      *
  *  59 Temple Place, Suite 330, Boston, MA  02111-1307  USA                *
  ***************************************************************************
-        $Id: newsletter.inc.php,v 1.9 2004-10-16 21:14:15 x2000habouzit Exp $
+        $Id: newsletter.inc.php,v 1.10 2004-10-16 22:06:33 x2000habouzit Exp $
  ***************************************************************************/
 
 
 define('FEMME', 1);
 define('HOMME', 0);
 
-function justify($text,$n) {
-    $arr = split("\n",wordwrap($text,$n));
-    $arr = array_map(trim,$arr);
-    $res = '';
-    foreach($arr as $key => $line) {
-       $nxl = isset($arr[$key+1]) ? trim($arr[$key+1]) : '';
-       $nxl_split = preg_split('! +!',$nxl);
-       $nxw_len = count($nxl_split) ? strlen($nxl_split[0]) : 0;
-
-       if(strlen($line)+1+$nxw_len <= 68) {
-           $res .= "$line\n";
-           continue;
-       }
-
-       $tmp = preg_split('! +!',trim($line));
-       $words = count($tmp);
-       if($words <= 1) {
-           $res .= "$line\n";
-           continue;
-       }
-
-       $len = array_sum(array_map(strlen,$tmp));
-       $empty = $n - $len;
-       $sw = floatval($empty) / floatval($words-1);
-       
-       $cur = 0;
-       $l = '';
-       foreach($tmp as $word) {
-           $l .= $word;
-           $cur += $sw + strlen($word);
-           $l = str_pad($l,intval($cur+0.5));
-       }
-       $res .= trim($l)."\n";
-    }
-    return trim($res);
-}
-
-
-function enriched_to_text($input,$html=false,$just=false) {
-    $text = stripslashes(trim($input));
-    if($html) {
-       $text = htmlspecialchars($text);
-       $text = str_replace('[b]','<strong>', $text);
-       $text = str_replace('[/b]','</strong>', $text);
-       $text = str_replace('[i]','<em>', $text);
-       $text = str_replace('[/i]','</em>', $text);
-       $text = str_replace('[u]','<span style="text-decoration: underline">', $text);
-       $text = str_replace('[/u]','</span>', $text);
-       $text = preg_replace('!((https?|ftp)://[^\r\n\t ]*)!','<a href="\1">\1</a>', $text);
-       $text = preg_replace('!([a-zA-Z0-9\-_+.]*@[a-zA-Z0-9\-_+.]*)!','<a href="mailto:\1">\1</a>', $text);
-       return nl2br($text);
-    } else {
-       $text = preg_replace('!\[\/?b\]!','*',$text);
-       $text = preg_replace('!\[\/?u\]!','_',$text);
-       $text = preg_replace('!\[\/?i\]!','/',$text);
-       $text = preg_replace('!((https?|ftp)://[^\r\n\t ]*)!','[\1]', $text);
-       $text = preg_replace('!([a-zA-Z0-9\-_+.]*@[a-zA-Z0-9\-_+.]*)!','[mailto:\1]', $text);
-       return $just ? justify($text,68) : wordwrap($text,68);
-    }
-}
-
 
 class NewsLetter {
     var $_id;
@@ -122,6 +61,7 @@ class NewsLetter {
                                      FROM  newsletter_art AS a
                                INNER JOIN  newsletter     AS n USING(id)
                                LEFT  JOIN  newsletter_cat AS c ON(a.cid=c.cid)
+                                    WHERE  a.id=$id
                                  ORDER BY  c.pos,a.pos");
        while(list($title,$body,$append,$aid,$cid,$pos) = mysql_fetch_row($res)) {
            $this->_arts[$cid]["a$aid"] = new NLArticle($title,$body,$append,$aid,$cid,$pos);
@@ -156,10 +96,10 @@ class NewsLetter {
            $globals->db->query(
                "INSERT INTO  newsletter_art
                      SELECT  {$this->_id},MAX(aid)+1,{$a->_cid},
-                             ". ($a->_pos ? $a->_pos : "IF(MAX(pos)<100,100,MAX(pos)+1),").",
+                             ".($a->_pos ? $a->_pos : "MAX(pos)+1").",
                              '{$a->_title}','{$a->_body}','{$a->_append}'
                        FROM  newsletter_art AS a
-                      WHERE  a.id={$this->_id}");
+                      WHERE  a.id={$this->_id} AND cid='{$a->_cid}'");
            $this->_arts['a'.$a->_aid] = $a;
        }
     }
@@ -173,7 +113,23 @@ class NewsLetter {
     }
 
     function toText() {
-       $res = "";
+       $res  = "====================================================================\n";
+       $res .= ' '.$this->title()."\n";
+       $res .= "====================================================================\n\n";
+
+       $res .= "INTRO\n\n";
+
+       $res .= "--------------------------------------------------------------------\n";
+       $i = 1;
+       foreach($this->_arts as $cid=>$arts) {
+           $res .= "\n$i *{$this->_cats[$cid]}*\n";
+           foreach($arts as $art) {
+               $res .= '- '.$art->title()."\n";
+           }
+           $i ++;
+       }
+       $res .= "\n";
+           
        foreach($this->_arts as $cid=>$arts) {
            $res .= "--------------------------------------------------------------------\n";
            $res .= "*{$this->_cats[$cid]}*\n";
@@ -187,9 +143,22 @@ class NewsLetter {
     }
     
     function toHtml() {
-       $res = "";
+       $res  = '<div style="margin: 2ex 0ex 2ex 0ex; padding: 1ex; width: 100%; border: 1px black solid; font-size: 125%; text-align: center">';
+       $res .= $this->title();
+       $res .= '</div>';
+
+       $i = 1;
        foreach($this->_arts as $cid=>$arts) {
-           $res .= '<div style="margin: 2ex 0ex 2ex 0ex; padding: 2px 1ex 2px 1ex; width: 100%; border: 1px black solid; font-size: 125%;">';
+           $res .= "<strong>$i. {$this->_cats[$cid]}</strong><br />";
+           foreach($arts as $art) {
+               $res .= '- '.$art->title()."<br />\n";
+           }
+           $res .= '<br />';
+           $i ++;
+       }
+
+       foreach($this->_arts as $cid=>$arts) {
+           $res .= '<div style="margin: 2ex 0ex 2ex 0ex; padding: 2px 1ex 2px 1ex; width: 100%; border: 1px black dotted; font-size: 125%;">';
            $res .= $this->_cats[$cid].'</div>';
            foreach($arts as $art) {
                $res .= $art->toHtml();
@@ -216,23 +185,24 @@ class NLArticle {
        $this->_pos = $pos;
     }
 
+    function title() { return stripslashes(trim($this->_title)); }
     function body() { return stripslashes(trim($this->_body)); }
     function append() { return stripslashes(trim($this->_append)); }
 
     function toText() {
-       $title = '*'.stripslashes($this->_title).'*';
+       $title = '*'.$this->title().'*';
        $body  = enriched_to_text($this->_body,false,true);
        $app   = enriched_to_text($this->_append);
        return trim("$title\n\n$body\n\n$app")."\n";
     }
 
     function toHtml() {
-       $title = '<span style="font-weight:bold; font-style: italic; font-size: 125%">'
-               .stripslashes($this->_title).'</span>';
+       $title = '<div style="margin: 2ex 0ex 2ex 0ex; font-weight:bold; font-style: italic; font-size: 125%">'
+               .$this->title().'</div>';
        $body  = enriched_to_text($this->_body,true);
        $app   = enriched_to_text($this->_append,true);
        
-       $art = "$title<br /><br />$body<br />";
+       $art = "$title\n$body<br />";
        if ($app) $art .= "<br />$app<br />";
        
        return $art;
@@ -247,38 +217,9 @@ class NLArticle {
     }
 }
 
-class NLConstraint {
-    var $_func;
-    var $_arg;
-    
-    function NLConstraint($func, $arg) {
-       $this->_func = $func;
-       $this->_arg = $arg;
-    }
-
-    function check($user) { return false; }
-}
-
-class NLPromoConstraint {
-    function check($user) {
-       $promo = $user['promo'];
-       switch($this->_func) {
-           case 'eq':   return ( $promo == $this->_arg );
-           case 'neq':  return ( $promo != $this->_arg );
-           case 'geq':  return ( $promo >= $this->_arg );
-           case 'leq':  return ( $promo <= $this->_arg );
-           case 'odd':  return ( $promo % 2 == 1 );
-           case 'even': return ( $promo % 2 == 0 );
-           default: return false;
-       }
-    }
-}
-
-class NLSexeConstraint {
-    function check($user) { return $user['sexe'] == $_arg; }
-}
-       
-
+/////////////////////////
+// functions ............
+//
 function get_nl_slist() {
     global $globals;
     $res = $globals->db->query("SELECT id,date,titre FROM newsletter ORDER BY date DESC");
@@ -317,4 +258,71 @@ function subscribe_nl() {
                                 FROM  newsletter WHERE bits!='new'");
 }
  
+function justify($text,$n) {
+    $arr = split("\n",wordwrap($text,$n));
+    $arr = array_map(trim,$arr);
+    $res = '';
+    foreach($arr as $key => $line) {
+       $nxl = isset($arr[$key+1]) ? trim($arr[$key+1]) : '';
+       $nxl_split = preg_split('! +!',$nxl);
+       $nxw_len = count($nxl_split) ? strlen($nxl_split[0]) : 0;
+       $line = trim($line);
+
+       if(strlen($line)+1+$nxw_len < 68) {
+           $res .= "$line\n";
+           continue;
+       }
+       
+       if(preg_match('![.:;]$!',$line)) {
+           $res .= "$line\n";
+           continue;
+       }
+
+       $tmp = preg_split('! +!',trim($line));
+       $words = count($tmp);
+       if($words <= 1) {
+           $res .= "$line\n";
+           continue;
+       }
+
+       $len = array_sum(array_map(strlen,$tmp));
+       $empty = $n - $len;
+       $sw = floatval($empty) / floatval($words-1);
+       
+       $cur = 0;
+       $l = '';
+       foreach($tmp as $word) {
+           $l .= $word;
+           $cur += $sw + strlen($word);
+           $l = str_pad($l,intval($cur+0.5));
+       }
+       $res .= trim($l)."\n";
+    }
+    return trim($res);
+}
+
+
+function enriched_to_text($input,$html=false,$just=false) {
+    $text = stripslashes(trim($input));
+    if($html) {
+       $text = htmlspecialchars($text);
+       $text = str_replace('[b]','<strong>', $text);
+       $text = str_replace('[/b]','</strong>', $text);
+       $text = str_replace('[i]','<em>', $text);
+       $text = str_replace('[/i]','</em>', $text);
+       $text = str_replace('[u]','<span style="text-decoration: underline">', $text);
+       $text = str_replace('[/u]','</span>', $text);
+       $text = preg_replace('!((https?|ftp)://[^\r\n\t ]*)!','<a href="\1">\1</a>', $text);
+       $text = preg_replace('!([a-zA-Z0-9\-_+.]*@[a-zA-Z0-9\-_+.]*)!','<a href="mailto:\1">\1</a>', $text);
+       return nl2br($text);
+    } else {
+       $text = preg_replace('!\[\/?b\]!','*',$text);
+       $text = preg_replace('!\[\/?u\]!','_',$text);
+       $text = preg_replace('!\[\/?i\]!','/',$text);
+       $text = preg_replace('!((https?|ftp)://[^\r\n\t ]*)!','[\1]', $text);
+       $text = preg_replace('!([a-zA-Z0-9\-_+.]*@[a-zA-Z0-9\-_+.]*)!','[mailto:\1]', $text);
+       return $just ? justify($text,68) : wordwrap($text,68);
+    }
+}
+
 ?>
index 98ae3f4..1125dc8 100644 (file)
@@ -17,7 +17,7 @@
  *  Foundation, Inc.,                                                      *
  *  59 Temple Place, Suite 330, Boston, MA  02111-1307  USA                *
  ***************************************************************************
-        $Id: newsletter_edit.tpl,v 1.2 2004-10-16 21:14:15 x2000habouzit Exp $
+        $Id: newsletter_edit.tpl,v 1.3 2004-10-16 22:06:33 x2000habouzit Exp $
  ***************************************************************************}
 
 {dynamic}
         <input type='text' size='60' name='title' value="{$nl->title()}" />
       </td>
     </tr>
+    <tr>
+      <td class='titre'>
+        Date d'envoi
+      </td>
+      <td>
+        <input type='text' size='60' name='date' value="{$nl->_date}" />
+      </td>
+    </tr>
     <tr class='center'>
       <td colspan='2'>
         <input type='submit' name='update' value='sauver' />
     <tr class="impair">
       <td class='titre'>Sujet</td>
       <td>
-        <input size='60' type='text' value='{$art->_title}' name='title' />
+        <input size='60' type='text' value='{$art->title()}' name='title' />
       </td>
     </tr>
     <tr class="impair">