/[corp_html]/back/newsletter/send.php
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Annotation of /back/newsletter/send.php

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.4 - (hide annotations)
Thu Apr 25 12:39:04 2002 UTC (22 years ago) by dpavlin
Branch: MAIN
CVS Tags: HEAD
Changes since 1.3: +1 -0 lines
display one newsletter on screen

1 dpavlin 1.1 <?php
2    
3     $dir = "/data/corp_html";
4    
5     include_once("DB.php"); // PEAR
6     include_once("$dir/inc/Smarty.class.php");
7     include_once("$dir/inc/quoted-printable.inc");
8     include_once("$dir/inc/news_type.inc");
9    
10     function CheckError($sth) {
11     if (DB::isError($sth)) die($sth->getMessage());
12     }
13    
14     $user = "dpavlin";
15     $pwd = "";
16     $host = "localhost";
17     $db = "corp";
18    
19     $smarty = new Smarty;
20     $smarty->template_dir = "$dir/templates";
21     $smarty->compile_dir = "$dir/templates_c";
22    
23     $dbh = DB::connect("pgsql://$user:$pwd@$host/$db");
24     // $dbh->setFetchmode(DB_FETCHMODE_ORDERED);
25     $dbh->setFetchmode(DB_FETCHMODE_ASSOC);
26     $dbh->query("SET DATESTYLE='ISO'");
27    
28    
29     $sth = $dbh->query("select max(id) as max_id from news_sent");
30     CheckError($sth);
31    
32     while ($row = $sth->fetchRow()) {
33     if ($row[max_id]) {
34     $max_id = $row[max_id];
35     } else {
36     $max_id = 0;
37     }
38     }
39     $sql="
40     select
41     id,upper(title) as title,town_date,body,more,pdf,
42     (date-now()::date) as comming,type,title as title_lc
43     from news where newsletter is true and id > $max_id
44     order by priority desc,date desc";
45    
46     $sth = $dbh->query($sql);
47     CheckError($sth);
48    
49 dpavlin 1.2
50 dpavlin 1.1 if ($sth->numRows() > 0) {
51    
52 dpavlin 1.2 $new_news=0;
53    
54 dpavlin 1.1 $max_id = 0;
55     while ($row = $sth->fetchRow()) {
56     $row[news_type] = $news_type[$row[type]];
57 dpavlin 1.3 $body = strip_tags($row[body]);
58     $body = strtr($body,"\n\r"," ");
59     $body = ereg_replace(" *"," ",$body);
60     $row[body] = wordwrap($body, 75, "\n");
61 dpavlin 1.1 $data[] = $row;
62     if ($row[id] > $max_id) $max_id = $row[id];
63 dpavlin 1.2 $new_news++;
64 dpavlin 1.1 }
65    
66     $sth->free();
67    
68 dpavlin 1.2 $subscribers = 0;
69    
70     $sql = "select email from news_sub where confirmed is true";
71     $sth = $dbh->query($sql);
72     CheckError($sth);
73    
74     while ($row = $sth->fetchRow()) {
75     $smarty->assign(array(
76     "email"=>$row[email],
77     "data"=>$data
78     ));
79     iso_sendmail_t($smarty->fetch("newsletter_outgoing.tpl"));
80     # print "<pre>".$smarty->fetch("newsletter_outgoing.tpl")."</pre><hr>";
81     $subscribers++;
82     }
83 dpavlin 1.1
84     // insert last news sent
85     $sth = $dbh->query("insert into news_sent (id) values ($max_id)");
86     CheckError($sth);
87    
88 dpavlin 1.2
89     print "sent $new_news news to $subscribers subscribers.";
90 dpavlin 1.4 print "<hr><pre>".$smarty->fetch("newsletter_outgoing.tpl")."</pre>";
91 dpavlin 1.1 } else {
92     print "no news for newsletter to send!";
93     }
94    
95     $dbh->disconnect();
96     $dbh = null;
97    
98     ?>

  ViewVC Help
Powered by ViewVC 1.1.26