Implemented articles
authorshort <>
Fri, 28 Sep 2001 03:51:08 +0000 (03:51 +0000)
committershort <>
Fri, 28 Sep 2001 03:51:08 +0000 (03:51 +0000)
clanek.php [new file with mode: 0644]
config.php
obsah_init.pl

diff --git a/clanek.php b/clanek.php
new file mode 100644 (file)
index 0000000..5465ab7
--- /dev/null
@@ -0,0 +1,36 @@
+<?php $cvs_id='$Id$';
+
+       include("common.php");
+
+       prepvar("year" ,"[0-9]+");
+       prepvar("month","[0-9]+");
+       prepvar("id"   ,"[0-9]+",false/*required*/);
+
+       $title_tail=title_name($year,$month);
+       $result=db_query("select name,contents from $tb_clanek where year=$year and month=$month"
+                       .(isset($id) ? " and id=$id" : "")." order by id");
+       if (isset($id) && 1==mysql_num_rows($result)) {
+               $row=mysql_fetch_array($result);
+               $title_tail.=" - ".$row["name"];
+               }
+
+       heading();
+       print("<h1>".title_name($year,$month)."</h1>\n");
+
+       if (isset($id) && 1!=mysql_num_rows($result))
+               fatal("Zadaný èlánek nebyl nalezen");
+
+function print_article($row)
+{
+       print("<h2>".htmlspecialchars($row["name"])."</h2>\n".$row["contents"]);
+}
+
+       if (isset($id))
+               print_article($row);
+       else
+               while (($row=mysql_fetch_array($result)))
+                       print_article($row);
+       mysql_free_result($result);
+
+       footer();
+?>
index 1bed492..bffe3ef 100644 (file)
@@ -20,5 +20,6 @@
        $appendix_obsah_contents=chr(4);
        $obsah_year_base=1996;
        $tb_objednavka="energie_objednavka";
+       $tb_clanek="energie_clanek";
 
 ?>
index 2c1c11d..d2ded01 100755 (executable)
@@ -6,7 +6,7 @@ use strict;
 use DBI;
 
 use vars qw/$db_driver $db_host $db_user $db_pwd $DB_PWD $db_name $db/;
-use vars qw/$tb_obsah/;
+use vars qw/$tb_obsah $tb_clanek/;
 
 $db_driver="mysql";
 $db_host="";
@@ -14,6 +14,7 @@ $db_user="short";
 $DB_PWD=$ENV{"HOME"}."/priv/mysql.${db_user}.pwd";
 $db_name="short";
 $tb_obsah="energie_obsah";
+$tb_clanek="energie_clanek";
 
 open DB_PWD or die "Failed open \"$DB_PWD\": $!";
 $db_pwd=<DB_PWD>;
@@ -41,8 +42,19 @@ eval { &db_do("drop table $tb_obsah") };
 
 &db_do("alter table $tb_obsah add unique (year,month)");
 
+eval { &db_do("drop table $tb_clanek") };
 
-use vars qw/$insert_tb_obsah $year $month $month_last $sequential $contents $first/;
+&db_do("create table $tb_clanek ("
+               ."year year(4) not null,"
+               ."month tinyint not null,"
+               ."id tinyint not null,"
+               ."name text not null,"
+               ."contents text not null"
+               .")");
+
+&db_do("alter table $tb_clanek add unique (year,month,id)");
+
+use vars qw/$insert_tb_obsah $insert_tb_clanek $year $month $month_last $sequential $contents $first $article_id/;
 
 sub where
 {
@@ -68,10 +80,13 @@ sub flush_month
        undef $year,$month;
        undef $contents;
        undef $first;
+       undef $article_id;
 }
 
 $insert_tb_obsah=$db->prepare("insert into $tb_obsah (year,month,month_last,sequential,contents) values (?,?,?,?,?)")
                or die "Prepare fail: $!";
+$insert_tb_clanek=$db->prepare("insert into $tb_clanek (year,month,id,name,contents) values (?,?,?,?,?)")
+               or die "Prepare fail: $!";
 
 while (<>) {
        chomp;
@@ -84,6 +99,17 @@ while (<>) {
                $contents="";
                next;
                }
+       if (/^#(.+)$/) {
+my( $clanek )="";
+my( $line );
+               while (($line=<>)!~/^#$/) {
+                       die "Article EOF marker not found".&where() if (!$line);
+                       $clanek.=$line;
+                       }
+               # $article_id probably should not be zero
+               $insert_tb_clanek->execute($year,$month,++$article_id,$1,$clanek) or die "SQL insert failure: $!";
+               next;
+               }
        if (/^Pøíloha:$/) {
                die "Multiple \"Pøíloha\"s".&where() if ($contents=~/\004/);
                $contents.="\004";