Changeset 196 for trunk/admin

Show
Ignore:
Timestamp:
07/17/06 19:53:36 (2 years ago)
Author:
michiel
Message:

merge class rewrite work from branches/class-rewrite

Location:
trunk/admin
Files:
5 removed
1 modified
6 copied

Legend:

Unmodified
Added
Removed
  • trunk/admin/index.php

    r185 r196  
    1 <? 
    2 /* 
    3  * MvBlog -- An open source no-noncence blogtool 
    4  * 
    5  * Copyright (C) 2005-2006, Michiel van Baak 
    6  * Logo design (C) 2005, Sofie van Tendeloo 
    7  * 
    8  * Michiel van Baak <mvanbaak@users.sourceforge.net> 
    9  * Sofie van Tendeloo <eldridge@users.sourceforge.net> 
    10  * 
    11  * See http://dev.mvblog.org for more information on MvBlog. 
    12  * That page also provides Bugtrackers, Filereleases etc. 
    13  * 
    14  * This program is free software, distributed under the terms of 
    15  * the GNU General Public License Version 2. See the LICENSE file 
    16  * at the top of the source tree. 
    17  */ 
    18  
    19 require("../common/functions_blog.php"); 
    20 //----------------------------- 
    21 //{{{ check if we are logged in 
    22 //----------------------------- 
    23 check_admin_logged_in(); 
    24  
    25 //}}}-------------------------------------------- 
    26 //{{{ show_index: default txt we show after login 
    27 //----------------------------------------------- 
    28 function show_index() { 
    29         ?> 
    30         <p class="first">Welcome to MvBlog <?=$_SESSION["author_fullname"]?>.</p> 
    31         <p class="first">You can administer your blog with the menu items right above this useless text.</p> 
    32         <p class="first">Enjoy keeping your blog up-to-date</p> 
    33         <p class="first"> 
    34                 If you want to thank/support me, or complain about bugs, or tell me this tool sux, or whatever:<br /> 
    35                 Michiel van Baak<br /> 
    36                 michiel@vanbaak.info 
    37         </p> 
    38         <? 
    39 } 
    40  
    41 //}}}---------------------------------------------------- 
    42 //{{{ show_posts: show a list of all posts with some info 
    43 //------------------------------------------------------- 
    44 function show_posts($options = array()) { 
    45         global $db; 
    46         if (!is_object($db)) { 
    47                 echo "db should be an object, something went wrong"; 
    48                 exit; 
    49         } 
    50         if (!$options["top"])   { $options["top"]   = 0;  } else { $options["top"]   = (int)$options["top"];   } 
    51         if (!$options["limit"]) { $options["limit"] = 15; } else { $options["limit"] = (int)$options["limit"]; } 
    52         //put all categories in array 
    53         $res =& $db->query("SELECT * FROM categories"); 
    54         if (PEAR::isError($res)) { 
    55                 die($res->getMessage()); 
    56         } 
    57         while ($res->fetchInto($row, DB_FETCHMODE_ASSOC)) { 
    58                 $cats[$row["id"]] = $row["name"]; 
    59         } 
    60         $cats[-1] = "asides"; 
    61         if ((array_key_exists("month", $options) && $options["month"] > 0) && (array_key_exists("year", $options) && $options["year"] > 0)) { 
    62                 $timestamp_start = mktime(0,0,0,$options["month"],1,$options["year"]); 
    63                 $timestamp_stop  = mktime(0,0,0,$options["month"]+1,1,$options["year"]); 
    64                 $q1 = sprintf("WHERE %s BETWEEN %d AND %d", db_quote("date"), $timestamp_start, $timestamp_stop); 
    65         } else { 
    66                 $options["month"] = 0; 
    67                 $options["year"]  = 0; 
    68         } 
    69  
    70         $res_count =& $db->query("SELECT COUNT(*) FROM articles $q1"); 
    71         $res_count->fetchInto($counter_r, DB_FETCHMODE_NUM); 
    72         $counter = $counter_r[0]; 
    73         $res =& $db->limitQuery(sprintf("SELECT * FROM articles $q1 ORDER BY %s DESC", db_quote("date")), (int)$options["top"], $options["limit"]); 
    74         if (PEAR::isError($res)) { 
    75                 die($res->getDebugInfo()); 
    76         } 
    77         ?> 
    78         <a href="./index.php?action=edit_post&amp;id=0">create new</a> 
    79         <form id="filter" method="post" action="index.php?action=show_posts"> 
    80         <div id="post_select"> 
    81                 View month: 
    82                 <select name="options[month]"> 
    83                         <option value="0">---</option> 
    84                         <? 
    85                         for ($i=1;$i<=12;$i++) { 
    86                                 if ($options["month"] == $i) { $selected = " SELECTED"; } else { $selected = ""; } 
    87                                 ?><option value="<?=$i?>"<?=$selected?>><?=date("M", mktime(0,0,0,$i,1,0))?></option><? 
    88                         } 
    89                         ?> 
    90                 </select> 
    91                 <select name="options[year]"> 
    92                         <option value="0">---</option> 
    93                         <? 
    94                         /* find the first post we made so we know the start year */ 
    95                         $sql1 = sprintf("SELECT %s FROM articles ORDER BY date ASC", db_quote("date")); 
    96                         $res1 =& $db->limitQuery($sql1, 0, 1); 
    97                         $res1->fetchInto($row1); 
    98                         for ($i=date("Y", $row1[0]);$i<=date("Y");$i++) { 
    99                                 if ($options["year"] == $i) { $selected1 = " SELECTED"; } else { $selected1 = ""; } 
    100                                 ?><option value="<?=$i?>"<?=$selected1?>><?=$i?></option><? 
    101                         } 
    102                         ?> 
    103                 </select> 
    104                 <a href="javascript:document.getElementById('filter').submit();">go</a> 
    105                 <br /><br /> 
    106         </div> 
    107         </form> 
    108         <? 
    109  
    110         while ($res->fetchInto($row, DB_FETCHMODE_ASSOC)) { 
    111                 if (!trim($row["title"])) { 
    112                         $row["title"] = "[no title]"; 
    113                 } 
    114                 if ($row["aside"] == 1) { 
    115                         $row["categories_id"] = -1; 
    116                 } 
    117                 ?> 
    118                 <div class="log_post"> 
    119                         <div class="log_post_head"> 
    120                                 <h1 class="log_post_h1"><a href="?action=edit_post&amp;id=<?=$row["id"]?>"><?=stripslashes($row["title"])?></a></h1> 
    121                                 <? 
    122                                         $r =& $db->query(sprintf("SELECT COUNT(*) FROM articles WHERE categories_id = %d", $row["id"])); 
    123                                         if (PEAR::isError($r)) { 
    124                                                 die($r->getMessage()); 
    125                                         } 
    126                                         $r->fetchInto($count); 
    127                                 ?> 
    128                                 <h2 class="log_post_h2">category: <?=$cats[$row["categories_id"]]?></h2> 
    129                         </div> 
    130                         <div class="log_post_body"> 
    131                                 <div class="log_post_normal"> 
    132                                         <?=stripslashes($row["body"])?> 
    133                                 </div> 
    134                         </div> 
    135                         <div class="log_post_foot"> 
    136                                 <span class="log_post_author">active: <?=(int)$row["active"]?></span> 
    137                                 <span class="log_post_author">public: <?=(int)$row["public"]?></span> 
    138                                 <span class="log_post_author">aside: <?=(int)$row["aside"]?></span> 
    139                         </div> 
    140                 </div> 
    141                 <? 
    142         } 
    143         if ($options["top"]) { 
    144                 echo "<a class=\"link_prev\" href=\"index.php?action=show_posts&amp;options[month]=".(int)$options["month"]."&amp;options[year]=".(int)$options["year"]."&amp;options[top]=".($options["top"]-$options["limit"])."\">previous</a> "; 
    145         } 
    146         if (($options["top"] + $options["limit"]) > $counter) { 
    147                 $end = $counter; 
    148         } else { 
    149                 $end = ($options["top"]+$options["limit"]); 
    150         } 
    151         if ($counter == 0) { 
    152                 echo "<span class=\"log_cat\">no posts"; 
    153         } else { 
    154                 echo "<span class=\"log_cat\">showing ".($options["top"]+1)." to ".$end." of ".$counter." total posts"; 
    155         } 
    156         if (($options["top"]+$options["limit"]) < $counter) { 
    157                 echo " <a class=\"link_next\" href=\"index.php?action=show_posts&amp;options[month]=".(int)$options["month"]."&amp;options[year]=".(int)$options["year"]."&amp;options[top]=".($options["top"]+$options["limit"])."\">next</a>"; 
    158         } 
    159         echo "</span>"; 
    160 } 
    161  
    162 //}}}-------------------------------------------------- 
    163 //{{{ edit_post($id): show user a form to edit the post 
    164 //----------------------------------------------------- 
    165 function edit_post($id) { 
    166         global $db; 
    167         if ($id==0) { 
    168                 $post["id"]                = 0; 
    169                 $post["title"]             = "post title"; 
    170                 $post["body"]              = "post body"; 
    171                 $post["date"]              = mktime(); 
    172                 $post["categories_id"]     = 0; 
    173                 $post["active"]            = 1; 
    174                 $post["public"]            = 1; 
    175                 $post["mail_comments"]     = 1; 
    176                 $post["allowanoncomments"] = 0; 
    177         } else { 
    178                 $res =& $db->query(sprintf("SELECT * FROM articles WHERE id = %d", $id)); 
    179                 if (PEAR::isError($res)) { 
    180                         die($res->getMessage()); 
    181                 } 
    182                 $res->fetchInto($post, DB_FETCHMODE_ASSOC); 
    183         } 
    184  
    185         //put all known categories in array 
    186         $r =& $db->query("SELECT * FROM categories ORDER BY name"); 
    187         if (PEAR::isError($r)) { 
    188                 die($r->getMessage()); 
    189         } 
    190         while ($r->fetchInto($ro, DB_FETCHMODE_ASSOC)) { 
    191                 $cats[$ro["id"]] = $ro["name"]; 
    192         } 
    193         ?> 
    194         <!-- xinha stuff --> 
    195         <script type="text/javascript"> 
    196                 _editor_url  = "../xinha/"; 
    197                 _editor_lang = "en"; 
    198         </script> 
    199         <script type="text/javascript" src="../xinha/htmlarea.js"></script> 
    200         <script type="text/javascript" src="../common/xinha_conf.js"></script> 
    201         <!-- end xinha stuff --> 
    202         <form name="blogpost" method="post" action="index.php"> 
    203         <input type="hidden" name="action" value="save_post" /> 
    204         <input type="hidden" name="post[id]" value="<?=$post["id"]?>" /> 
    205         <div class="log_post"> 
    206                 <div class="log_post_head"> 
    207                         <h1 class="log_post_h1"><input type="text" id="title" name="post[title]" value="<?=stripslashes($post["title"])?>" /></h1> 
    208                         <h2 class="log_post_h2">category: 
    209                         <select name="post[categories_id]"> 
    210                         <? 
    211                         foreach ($cats as $k=>$v) { 
    212                                 if ($post["categories_id"] == $k) { 
    213                                         $selected = "selected=\"selected\""; 
    214                                 } else { 
    215                                         $selected = ""; 
    216                                 } 
    217                                 ?><option value="<?=$k?>" <?=$selected?>><?=$v?></option><? 
    218                         } 
    219                         ?> 
    220                         </select> 
    221                         </h2> 
    222                 </div> 
    223                 <div class="log_post_body"> 
    224                         <? 
    225                         /* xinha stuff */ 
    226                         ?> 
    227                         <textarea id="editor_area" name="post[body]" rows="10" cols="50" style="width: 100%"><?=stripslashes($post["body"])?></textarea> 
    228                         <? 
    229  
    230                         echo "to limit this post on the frontpage, enter ##BREAKPOINT## in your post.<br />"; 
    231                         echo "if this is not found, the frontpage article will be limited to 4000 characters"; 
    232                         ?> 
    233                         <br /><br /> 
    234                         date: 
    235                         <select name="post[day]"> 
    236                                 <? 
    237                                 for ($i=1;$i<=31;$i++) { 
    238                                         ?><option value="<?=$i?>" <?=($i==date("d", $post["date"])?" SELECTED":"") ?>><?=$i?></option><? 
    239                                 } 
    240                                 ?> 
    241                         </select> 
    242                         <select name="post[month]"> 
    243                                 <? 
    244                                 for ($i=1;$i<=12;$i++) { 
    245                                         ?><option value="<?=$i?>" <?=($i==date("m", $post["date"])?" SELECTED":"") ?>><?=$i?></option><? 
    246                                 } 
    247                                 ?> 
    248                         </select> 
    249                         <select name="post[year]"> 
    250                                 <? 
    251                                 for ($i=date("Y")-5;$i<=date("Y")+1;$i++) { 
    252                                         ?><option value="<?=$i?>" <?=($i==date("Y", $post["date"])?" SELECTED":"") ?>><?=$i?></option><? 
    253                                 } 
    254                                 ?> 
    255                         </select> 
    256                         <br /> 
    257                         send trackback info to:  
    258                         <input type="text" name="post[tb_uri]" value="<?=$post["tb_uri"]?>" size="50" /><br /> 
    259                         <input type="checkbox" value="1" name="post[mail_comments]"<? if ($post["mail_comments"]) { echo " checked=\"checked\""; } ?> />&nbsp;send comments as email to me.<br /> 
    260                         <input type="submit" value="save" /> 
    261                         <? if ($post["id"]) { ?> 
    262                                 <input type="button" value="delete" onClick="document.forms.blogpost.action.value='delete_post';document.forms.blogpost.submit();" /> 
    263                         <? } else { ?> 
    264                                 <input type="button" value="cancel" onClick="document.forms.blogpost.action.value='show_posts';document.forms.blogpost.submit();" /> 
    265                         <? } ?> 
    266                 </div> 
    267                 <div class="log_post_foot"> 
    268                         <span class="log_post_date">active: <input type="checkbox" value="1" name="post[active]" <? if ($post["active"]) { echo "checked=\"checked\""; } ?> /></span> 
    269                         <span class="log_post_author">public: <input type="checkbox" value="1" name="post[public]" <? if ($post["public"]) { echo "checked=\"checked\""; } ?> /></span> 
    270                         <span class="log_post_author">aside: <input type="checkbox" value="1" name="post[aside]" <? if ($post["aside"]) { echo "checked=\"checked\""; } ?> /></span> 
    271                         <span class="log_post_author">anoncomments: <input type="checkbox" value="1" name="post[allowanoncomments]" <? if ($post["allowanoncomments"]) { echo "checked=\"checked\""; } ?> /></span> 
    272                 </div> 
    273         </div> 
    274         </form> 
    275         <script language="Javascript" type="text/javascript"> 
    276                 document.blogpost.title.focus(); 
    277         </script> 
    278         <? 
    279 } 
    280  
    281 //}}}------------------------------------ 
    282 //{{{ save_post($post): store in database 
    283 //--------------------------------------- 
    284 function save_post($post) { 
    285         $db = $GLOBALS["db"]; 
    286         if ($post["id"]) { 
    287                 $sql = sprintf("SELECT date,active FROM articles WHERE id = %d", $post["id"]); 
    288                 $r =& $db->query($sql); 
    289                 $r->fetchInto($orig_post, DB_FETCHMODE_ASSOC); 
    290                 $query  = sprintf("UPDATE articles SET %s = '%s', %s = '%s', %s = %d, %s = %d, %s = %d, %s = %d, %s = %d, %s = %d", 
    291                         db_quote("title"), preg_quote(strip_tags($post["title"]), "'"), 
    292                         db_quote("body"),  preg_quote(_strip_tags($post["body"]), "'"), 
    293                         db_quote("categories_id"), $post["categories_id"], 
    294                         db_quote("active"), $post["active"], 
    295                         db_quote("public"), $post["public"], 
    296                         db_quote("aside"), $post["aside"], 
    297                         db_quote("mail_comments"), $post["mail_comments"], 
    298                         db_quote("allowanoncomments"), $post["allowanoncomments"] 
    299                 ); 
    300                 //if post was inactive, and now it's active, we don't update the "modified" fields in the database. 
    301                 if ($post["active"]) { 
    302                         if ($orig_post["active"]) { 
    303                                 $query .= sprintf(", %s = %d", db_quote("last_modified"), mktime()); 
    304                                 $query .= sprintf(", %s = %d", db_quote("modified_by"), $_SESSION["author_id"]);                 
    305                         } 
    306                 } 
    307                 //only update the date if it is not the same day as the posts original date 
    308                 if (date("d", $orig_post["date"]) != $post["day"] || date("m", $orig_post["date"]) != $post["month"] || date("Y", $orig_post["date"]) != $post["year"]) { 
    309                         $query .= sprintf(", %s = %d", db_quote("date"), mktime(date("H"), date("i"), date("s"), $post["month"], $post["day"], $post["year"])); 
    310                 } 
    311                 $query .= sprintf(", ping_sent = 1, tb_uri = '%s'", preg_quote($tb_uri, "'")); 
    312                 $query .= sprintf(" WHERE id = %d", $post["id"]); 
    313         } else { 
    314                 $query  = sprintf("INSERT INTO articles (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)", 
    315                         db_quote("title"), db_quote("body"), db_quote("authors_id"), db_quote("categories_id"), db_quote("date"), db_quote("active"), 
    316                         db_quote("public"), db_quote("aside"), db_quote("mail_comments"), db_quote("ping_sent"), db_quote("tb_uri"), db_quote("allowanoncomments") 
    317                 ); 
    318                 $query .= sprintf("VALUES ('%s', '%s', %d, %d, %d, %d, %d, %d, %d, %d, '%s', %d)", 
    319                         preg_quote(strip_tags($post["title"]), "'"), 
    320                         preg_quote(_strip_tags($post["body"]), "'"), 
    321                         $_SESSION["author_id"], 
    322                         $post["categories_id"], 
    323                         mktime(date("H"), date("i"), date("s"), $post["month"], $post["day"], $post["year"]), 
    324                         $post["active"], $post["public"], $post["aside"], $post["mail_comments"], 0, 
    325                         preg_quote($post["tb_uri"], "'"), $post["allowanoncomments"] 
    326                 ); 
    327         } 
    328         $res =& $db->query($query); 
    329         if (PEAR::isError($res)) { 
    330                 die($res->getUserInfo()); 
    331         } 
    332         if (!$post["id"]) { 
    333                 /* this is a new post. fetch old data */ 
    334                 $sql = sprintf("SELECT id FROM articles WHERE %s = '%s' AND %s = '%s' AND authors_id = %d AND categories_id = %d", 
    335                         db_quote("title"), preg_quote(strip_tags($post["title"]), "'"), 
    336                         db_quote("body"),  preg_quote(_strip_tags($post["body"]), "'"), 
    337                         $_SESSION["author_id"], $post["categories_id"] 
    338                 ); 
    339                 $res =& $db->query($sql); 
    340                 $res->fetchInto($temp, DB_FETCHMODE_ASSOC); 
    341                 $post["id"] = $temp["id"]; 
    342                 $new_post = 1; 
    343         } 
    344         if ($post["tb_uri"] && $new_post) { 
    345                 $post_uri = "http://".$_SERVER["SERVER_NAME"].substr($_SERVER["REQUEST_URI"],0,strpos($_SERVER["REQUEST_URI"], "/admin/index.php"))."/index.php?action=view/".$post["id"]; 
    346                 require_once("HTTP/Request.php"); 
    347                 $http =& new HTTP_Request($post["tb_uri"]); 
    348                 $http->setMethod(HTTP_REQUEST_METHOD_POST); 
    349                 $http->addPostData("title", $post["title"]); 
    350                 $http->addPostData("url", $post_uri); 
    351                 $http->addPostData("blog_name", "http://".$_SERVER["SERVER_NAME"].substr($_SERVER["REQUEST_URI"],0,strpos($_SERVER["REQUEST_URI"], "/admin/index.php"))."/"); 
    352                 $http->AddPostData("excerpt", substr(_strip_tags($post["body"]), 100)); 
    353                 $http->addPostData("charset", "UTF-8"); 
    354                 if (!PEAR::isError($http->sendRequest())) { 
    355                         $response1 = $http->getResponseBody(); 
    356                 } else { 
    357                         die("error"); 
    358                 } 
    359                 $sql = sprintf("UPDATE articles SET ping_sent = 1 WHERE id = %d", $post["id"]); 
    360                 $res =& $db->query($sql); 
    361         } 
    362         header("Location: index.php?action=show_posts"); 
    363 } 
    364  
    365 //}}}-------------------------------------------- 
    366 //{{{ delete_post($id): delete a post from the db 
    367 //----------------------------------------------- 
    368 function delete_post($id) { 
    369         global $db; 
    370         $query = sprintf("DELETE FROM articles WHERE id = %d", $id); 
    371         $res =& $db->query($query); 
    372         if (PEAR::isError($res)) { 
    373                 die($res->getUserInfo()); 
    374         } 
    375         //delete comments for this post 
    376         $query = sprintf("DELETE FROM comments WHERE articles_id = %d", $id); 
    377         $res =& $db->query($query); 
    378         if (PEAR::isError($res)) { 
    379                 die($res->getUserInfo()); 
    380         } 
    381         header("Location: index.php?action=show_posts"); 
    382 } 
    383  
    384 //}}}-------------------------------------------------------- 
    385 //{{{ show_cats: show a list of all categories with some info 
    386 //----------------------------------------------------------- 
    387 function show_cats() { 
    388         global $db; 
    389         $res =& $db->query("SELECT * FROM categories ORDER BY name"); 
    390         if (PEAR::isError($res)) { 
    391                 die($res->getMessage()); 
    392         } 
    393  
    394         ?><a href="./index.php?action=edit_cat&amp;id=0">create new</a><? 
    395         while ($res->fetchInto($row, DB_FETCHMODE_ASSOC)) { 
    396                 ?> 
    397                 <div class="log_post"> 
    398                         <div class="log_post_head"> 
    399                                 <h1 class="log_post_h1"><a href="?action=edit_cat&amp;id=<?=$row["id"]?>"><?=stripslashes($row["name"])?></a></h1> 
    400                                 <? 
    401                                         $r =& $db->query(sprintf("SELECT COUNT(*) FROM articles WHERE categories_id = %d", $row["id"])); 
    402                                         if (PEAR::isError($r)) { 
    403                                                 die($r->getMessage()); 
    404                                         } 
    405                                         $r->fetchInto($count); 
    406                                 ?> 
    407                                 <h2 class="log_post_h2">articles in this categorie: <?=$count[0]?></h2> 
    408                         </div> 
    409                         <div class="log_post_body"> 
    410                                 <div class="log_post_normal"> 
    411                                         <?=nl2br(stripslashes($row["desc"]))?> 
    412                                 </div> 
    413                         </div> 
    414                         <div class="log_post_foot"> 
    415                                 <span class="log_post_date">active: <?=$row["active"]?></span> 
    416                                 <span class="log_post_author">public: <?=$row["public"]?></span> 
    417                         </div> 
    418                 </div> 
    419                 <? 
    420         } 
    421 } 
    422  
    423 //}}}------------------------------------------------ 
    424 //{{{ edit_cat($id): show user a form to edit the cat 
    425 //--------------------------------------------------- 
    426 function edit_cat($id) { 
    427         global $db; 
    428         if ($id==0) { 
    429                 $cat["id"]     = 0; 
    430                 $cat["name"]   = "category name"; 
    431                 $cat["desc"]   = "Category description"; 
    432                 $cat["active"] = "1"; 
    433                 $cat["public"] = "1"; 
    434         } else { 
    435                 $res =& $db->query(sprintf("SELECT * FROM categories WHERE id = %d", $id)); 
    436                 if (PEAR::isError($res)) { 
    437                         die($res->getMessage()); 
    438                 } 
    439                 $res->fetchInto($cat, DB_FETCHMODE_ASSOC); 
    440         } 
    441         ?> 
    442         <form name="category" method="post" action="index.php"> 
    443         <input type="hidden" name="action" value="save_cat" /> 
    444         <input type="hidden" name="cat[id]" value="<?=$cat["id"]?>" /> 
    445         <div class="log_post"> 
    446                 <div class="log_post_head"> 
    447                         <h1 class="log_post_h1"><input type="text" name="cat[name]" value="<?=stripslashes($cat["name"])?>" /></h1> 
    448                         <? 
    449                                 $r =& $db->query(sprintf("SELECT COUNT(*) FROM articles WHERE categories_id = %d", $cat["id"])); 
    450                                 if (PEAR::isError($r)) { 
    451                                         die($r->getMessage()); 
    452                                 } 
    453                                 $r->fetchInto($count); 
    454                         ?> 
    455                         <h2 class="log_post_h2">articles in this categorie: <?=$count[0]?></h2> 
    456                 </div> 
    457                 <div class="log_post_body"> 
    458                         <textarea name="cat[description]" style="width: 200px; height: 100px;"><?=stripslashes($cat["desc"])?></textarea><br /> 
    459                         <input type="submit" value="save" /> 
    460                         <input type="button" value="cancel" onClick="document.forms.category.action.value='show_cats';document.forms.category.submit();" /> 
    461                         <? if ($id) { ?> 
    462                                 <input type="button" value="delete" onClick="document.forms.category.action.value='delete_cat';document.forms.category.submit();" /> 
    463                         <? } ?> 
    464                 </div> 
    465                 <div class="log_post_foot"> 
    466                         <span class="log_post_date">active: <input type="checkbox" value="1" name="cat[active]" <? if ($cat["active"]) { echo "checked=\"checked\""; } ?> /></span> 
    467                         <span class="log_post_author">public: <input type="checkbox" value="1" name="cat[public]" <? if ($cat["public"]) { echo "checked=\"checked\""; } ?> /></span> 
    468                 </div> 
    469         </div> 
    470         </form> 
    471         <? 
    472 } 
    473  
    474 //}}}---------------------------------- 
    475 //{{{ save_cat($cat): store in database 
    476 //------------------------------------- 
    477 function save_cat($cat) { 
    478         global $db; 
    479         if ($cat["id"]) { 
    480                 $query  = sprintf("UPDATE categories SET %s = '%s', %s = '%s', %s = %d, %s = %d WHERE id = %d", 
    481                         db_quote("name"),   preg_quote(strip_tags($cat["name"]), "'"), 
    482                         db_quote("desc"),   preg_quote(strip_tags($cat["description"]), "'"), 
    483                         db_quote("active"), $cat["active"], 
    484                         db_quote("public"), $cat["public"], 
    485                         $cat["id"] 
    486                 ); 
    487         } else { 
    488                 $query  = sprintf("INSERT INTO categories (%s, %s, %s, %s) VALUES ('%s', '%s', %d, %d)", 
    489                         db_quote("name"), db_quote("desc"), db_quote("active"), db_quote("public"), 
    490                         preg_quote(strip_tags($cat["name"]), "'"), 
    491                         preg_quote(strip_tags($cat["description"]), "'"), 
    492                         $cat["active"], 
    493                         $cat["public"] 
    494                 ); 
    495         } 
    496         $res =& $db->query($query); 
    497         if (PEAR::isError($res)) { 
    498                 die($res->getUserInfo()); 
    499         } 
    500         header("Location: index.php?action=show_cats"); 
    501 } 
    502  
    503 //}}}----------------------------------------------- 
    504 //{{{ delete_cat($id): delete a category from the db 
    505 //-------------------------------------------------- 
    506 function delete_cat($id) { 
    507         global $db; 
    508         $query = sprintf("DELETE FROM categories WHERE id=%d", $id); 
    509         $res =& $db->query($query); 
    510         if (PEAR::isError($res)) { 
    511                 die($res->getUserInfo()); 
    512         } 
    513         header("Location: index.php?action=show_cats"); 
    514 } 
    515  
    516 //}}}------------------------------------ 
    517 //{{{ show_acro: show a list of all acros 
    518 //--------------------------------------- 
    519 function show_acro() { 
    520         global $db; 
    521         $res =& $db->query("SELECT * FROM acronyms ORDER BY upper(acronym)"); 
    522         if (PEAR::isError($res)) { 
    523                 die($res->getMessage()); 
    524         } 
    525  
    526         ?><a href="./index.php?action=edit_acro&amp;id=0">create new</a><? 
    527         while ($res->fetchInto($row, DB_FETCHMODE_ASSOC)) { 
    528                 ?> 
    529                 <div class="log_post"> 
    530                         <div class="log_post_head"> 
    531                                 <h1 class="log_post_h1"><a href="?action=edit_acro&amp;id=<?=$row["id"]?>"><?=stripslashes($row["acronym"])?></a></h1> 
    532                         </div> 
    533                         <div class="log_post_body"> 
    534                                 <div class="log_post_normal"> 
    535                                         <?=stripslashes($row["description"])?> 
    536                                 </div> 
    537                         </div> 
    538                         <div class="log_post_foot"> 
    539                         </div> 
    540                 </div> 
    541                 <? 
    542         } 
    543 } 
    544  
    545 //}}}-------------------------------------------------- 
    546 //{{{ edit_acro($id): show user a form to edit the acro 
    547 //----------------------------------------------------- 
    548 function edit_acro($id) { 
    549         global $db; 
    550         if ($id==0) { 
    551                 $cat["id"]          = 0; 
    552                 $cat["acronym"]     = "acronym name"; 
    553                 $cat["description"] = "Category description"; 
    554         } else { 
    555                 $res =& $db->query(sprintf("SELECT * FROM acronyms WHERE id = %d", $id)); 
    556                 if (PEAR::isError($res)) { 
    557                         die($res->getMessage()); 
    558                 } 
    559                 $res->fetchInto($acro, DB_FETCHMODE_ASSOC); 
    560         } 
    561         ?> 
    562         <form name="acronym" method="post" action="index.php"> 
    563         <input type="hidden" name="action" value="save_acro" /> 
    564         <input type="hidden" name="acro[id]" value="<?=$acro["id"]?>" /> 
    565         <div class="log_post"> 
    566                 <div class="log_post_head"> 
    567                         <h1 class="log_post_h1"><input type="text" name="acro[acronym]" value="<?=stripslashes($acro["acronym"])?>" /></h1> 
    568                 </div> 
    569         &