Changeset 190 for branches

Show
Ignore:
Timestamp:
07/10/06 00:40:55 (2 years ago)
Author:
michiel
Message:

more work on porting the admin stuff to oop
I'm at 50% roughly, but more work will have to wait because my girl is getting naked and I wont be focused ;-)

Sweet dreams

Location:
branches/class-rewrite
Files:
6 added
5 removed
3 modified

Legend:

Unmodified
Added
Removed
  • branches/class-rewrite/admin/index.php

    r189 r190  
    44#load_admin_plugins(); 
    55$admin = new MvBlog_admin(); 
    6 $admin->html_header("Admin interface", "."); 
     6$admin->html_header("Admin interface", "../"); 
    77        ?> 
    88        <div id="if_container"> 
     
    1212                        <a href="index.php"><h1 class="page_title">admin</h1></a> 
    1313                </div> 
    14                 <div id="if_menu"> 
    15                         <a class="if_menu_item" href="../index.php">Site</a>&nbsp; 
    16                         <a class="if_menu_item<? if ($_REQUEST["action"] == "show_cats")      { echo "_act"; } ?>" href="./index.php?action=show_cats">categories</a>&nbsp; 
    17                         <a class="if_menu_item<? if ($_REQUEST["action"] == "show_authors")   { echo "_act"; } ?>" href="./index.php?action=show_authors">authors</a>&nbsp; 
    18                         <a class="if_menu_item<? if ($_REQUEST["action"] == "show_users")     { echo "_act"; } ?>" href="./index.php?action=show_users">users</a>&nbsp; 
    19                         <a class="if_menu_item<? if ($_REQUEST["action"] == "show_posts")     { echo "_act"; } ?>" href="./index.php?action=show_posts">posts</a>&nbsp; 
    20                         <a class="if_menu_item<? if ($_REQUEST["action"] == "show_comments")  { echo "_act"; } ?>" href="./index.php?action=show_comments">comments</a>&nbsp; 
    21                         <a class="if_menu_item<? if ($_REQUEST["action"] == "show_acro")      { echo "_act"; } ?>" href="./index.php?action=show_acro">acronyms</a>&nbsp; 
    22                         <a class="if_menu_item<? if ($_REQUEST["action"] == "show_settings")  { echo "_act"; } ?>" href="./index.php?action=show_settings">blogsettings</a>&nbsp; 
    23                         <a class="if_menu_item<? if ($_REQUEST["action"] == "show_menuitems") { echo "_act"; } ?>" href="./index.php?action=show_menuitems">menuitems</a>&nbsp; 
    24                         <a class="if_menu_item" href="./login.php?action=logout">logout</a>&nbsp; 
    25                 </div> 
     14                <?php if ($_SESSION["author_id"]) { ?> 
     15                        <div id="if_menu"> 
     16                                <a class="if_menu_item" href="../index.php">Site</a>&nbsp; 
     17                                <a class="if_menu_item<? if ($_REQUEST["action"] == "show_cats")      { echo "_act"; } ?>" href="./index.php?action=show_cats">categories</a>&nbsp; 
     18                                <a class="if_menu_item<? if ($_REQUEST["action"] == "show_authors")   { echo "_act"; } ?>" href="./index.php?action=show_authors">authors</a>&nbsp; 
     19                                <a class="if_menu_item<? if ($_REQUEST["action"] == "show_users")     { echo "_act"; } ?>" href="./index.php?action=show_users">users</a>&nbsp; 
     20                                <a class="if_menu_item<? if ($_REQUEST["action"] == "show_posts")     { echo "_act"; } ?>" href="./index.php?action=show_posts">posts</a>&nbsp; 
     21                                <a class="if_menu_item<? if ($_REQUEST["action"] == "show_comments")  { echo "_act"; } ?>" href="./index.php?action=show_comments">comments</a>&nbsp; 
     22                                <a class="if_menu_item<? if ($_REQUEST["action"] == "show_acro")      { echo "_act"; } ?>" href="./index.php?action=show_acro">acronyms</a>&nbsp; 
     23                                <a class="if_menu_item<? if ($_REQUEST["action"] == "show_settings")  { echo "_act"; } ?>" href="./index.php?action=show_settings">blogsettings</a>&nbsp; 
     24                                <a class="if_menu_item<? if ($_REQUEST["action"] == "show_menuitems") { echo "_act"; } ?>" href="./index.php?action=show_menuitems">menuitems</a>&nbsp; 
     25                                <a class="if_menu_item" href="./index.php?action=logout">logout</a>&nbsp; 
     26                        </div> 
     27                <?php } ?> 
    2628                <div id="if_page"> 
    27                         <? 
     29                        <?php 
    2830                        switch ($_REQUEST["action"]) { 
    29                                 case "show_acro"      : show_acro();                          break; 
    30                                 case "edit_acro"      : edit_acro($_REQUEST["id"]);           break; 
    31                                 case "save_acro"      : save_acro($_POST["acro"]);            break; 
    32                                 case "delete_acro"    : delete_acro($_REQUEST["acro"]["id"]); break; 
    33                                 case "show_cats"      : show_cats();                          break; 
    34                                 case "edit_cat"       : edit_cat($_REQUEST["id"]);            break; 
    35                                 case "save_cat"       : save_cat($_POST["cat"]);              break; 
    36                                 case "delete_cat"     : delete_cat($_REQUEST["cat"]["id"]);   break; 
    37                                 case "show_posts"     : show_posts($_REQUEST["options"]);     break; 
    38                                 case "edit_post"      : edit_post($_REQUEST["id"]);           break; 
    39                                 case "save_post"      : save_post($_POST["post"]);            break; 
    40                                 case "delete_post"    : delete_post($_REQUEST["post"]["id"]); break; 
    41                                 case "show_authors"   : show_authors();                       break; 
    42                                 case "edit_author"    : edit_author($_REQUEST["id"]);         break; 
    43                                 case "save_author"    : save_author($_POST["author"]);        break; 
    44                                 case "show_users"     : show_users();                         break; 
    45                                 case "edit_user"      : edit_user($_REQUEST["id"]);           break; 
    46                                 case "save_user"      : save_user($_POST["user"]);            break; 
    47                                 case "delete_user"    : delete_user($_REQUEST["user"]["id"]); break; 
    48                                 case "show_settings"  : show_settings();                      break; 
    49                                 case "save_settings"  : save_settings($_POST["settings"]);    break; 
    50                                 case "show_menuitems" : show_menuitems();                     break; 
    51                                 case "save_menuitems" : save_menuitems($_POST["link"]);       break; 
    52                                 case "show_comments"  : show_comments($_REQUEST["options"]);  break; 
    53                                 case "delete_comment" : delete_comment($_REQUEST["id"]);      break; 
    54                                 case "recover_comment": recover_comment($_REQUEST["id"]);     break; 
    55                                 default               : show_index();                         break; 
     31                                case "check_login"    : $admin->check_login($_POST["login"]);         break; 
     32                                case "logout"         : $admin->logout();                             break; 
     33                                case "show_acro"      : $admin->show_acro();                          break; 
     34                                case "edit_acro"      : $admin->edit_acro($_REQUEST["id"]);           break; 
     35                                case "save_acro"      : $admin->save_acro($_POST["acro"]);            break; 
     36                                case "delete_acro"    : $admin->delete_acro($_REQUEST["acro"]["id"]); break; 
     37                                case "show_cats"      : $admin->show_cats();                          break; 
     38                                case "edit_cat"       : $admin->edit_cat($_REQUEST["id"]);            break; 
     39                                case "save_cat"       : $admin->save_cat($_POST["cat"]);              break; 
     40                                case "delete_cat"     : $admin->delete_cat($_REQUEST["cat"]["id"]);   break; 
     41                                case "show_posts"     : $admin->show_posts($_REQUEST["options"]);     break; 
     42                                case "edit_post"      : $admin->edit_post($_REQUEST["id"]);           break; 
     43                                case "save_post"      : $admin->save_post($_POST["post"]);            break; 
     44                                case "delete_post"    : $admin->delete_post($_REQUEST["post"]["id"]); break; 
     45                                case "show_authors"   : $admin->show_authors();                       break; 
     46                                case "edit_author"    : $admin->edit_author($_REQUEST["id"]);         break; 
     47                                case "save_author"    : $admin->save_author($_POST["author"]);        break; 
     48                                case "show_users"     : $admin->show_users();                         break; 
     49                                case "edit_user"      : $admin->edit_user($_REQUEST["id"]);           break; 
     50                                case "save_user"      : $admin->save_user($_POST["user"]);            break; 
     51                                case "delete_user"    : $admin->delete_user($_REQUEST["user"]["id"]); break; 
     52                                case "show_settings"  : $admin->show_settings();                      break; 
     53                                case "save_settings"  : $admin->save_settings($_POST["settings"]);    break; 
     54                                case "show_menuitems" : $admin->show_menuitems();                     break; 
     55                                case "save_menuitems" : $admin->save_menuitems($_POST["link"]);       break; 
     56                                case "show_comments"  : $admin->show_comments($_REQUEST["options"]);  break; 
     57                                case "delete_comment" : $admin->delete_comment($_REQUEST["id"]);      break; 
     58                                case "recover_comment": $admin->recover_comment($_REQUEST["id"]);     break; 
     59                                default               : $admin->show_index();                         break; 
    5660                        } 
    5761$admin->html_footer(); 
  • branches/class-rewrite/common/admin.php

    r189 r190  
    1717 */ 
    1818Class MvBlog_admin extends MvBlog { 
    19 //{{{ check if we are logged in 
    20 //----------------------------- 
    21 check_admin_logged_in(); 
    22  
    23 //}}}-------------------------------------------- 
    24 //{{{ show_index: default txt we show after login 
    25 //----------------------------------------------- 
    26 function show_index() { 
    27         ?> 
    28         <p class="first">Welcome to MvBlog <?=$_SESSION["author_fullname"]?>.</p> 
    29         <p class="first">You can administer your blog with the menu items right above this useless text.</p> 
    30         <p class="first">Enjoy keeping your blog up-to-date</p> 
    31         <p class="first"> 
    32                 If you want to thank/support me, or complain about bugs, or tell me this tool sux, or whatever:<br /> 
    33                 Michiel van Baak<br /> 
    34                 michiel@vanbaak.info 
    35         </p> 
    36         <? 
    37 } 
    38  
    39 //}}}---------------------------------------------------- 
    40 //{{{ show_posts: show a list of all posts with some info 
    41 //------------------------------------------------------- 
    42 function show_posts($options = array()) { 
    43         global $db; 
    44         if (!is_object($db)) { 
    45                 echo "db should be an object, something went wrong"; 
     19         
     20        /* constants */ 
     21 
     22        /* variables */ 
     23 
     24        /* methods */ 
     25 
     26        /* __construct {{{ */ 
     27        /** 
     28         * Class constructor. Check some defaults etc 
     29         */ 
     30        public function __construct() { 
     31                /* start session and output buffering */ 
     32                session_start(); 
     33                ob_start(); 
     34 
     35                /* handle magic quotes */ 
     36                $this->_handle_magic_quotes(); 
     37 
     38                /* init database connection */ 
     39                $this->_init_db(); 
     40 
     41                /* check if we are logged in */ 
     42                if (!$_SESSION["author_id"] && $_POST["action"] != "check_login") { 
     43                        $this->show_login(); 
     44                } 
     45        } 
     46        /* }}} */ 
     47        /* show_login {{{ */ 
     48        /** 
     49         * Show admin login screen 
     50         */ 
     51        public function show_login() { 
     52                $this->html_header("Admin login"); 
     53                ?> 
     54                <form name="loginform" method="post" action="index.php"> 
     55                <input type="hidden" name="action" value="check_login" /> 
     56                <div id="if_container"> 
     57                        <div id="if_title"></div> 
     58                        <div id="if_bar1"></div> 
     59                        <div id="if_page_header"> 
     60                                <h1 class="page_title">login</h1> 
     61                        </div> 
     62                        <div id="if_page"> 
     63                                <div class="log_post"> 
     64                                        <table border="0" cellspacing="3" cellpadding="0" align="center"><tr> 
     65                                                <td align="right">username:</td><td><input type="text" id="loginname" name="login[name]" /></td> 
     66                                        </tr><tr> 
     67                                                <td align="right">password:</td><td><input type="password" name="login[password]" /></td> 
     68                                        </tr><tr> 
     69                                                <td colspan="2" align="center"><input type="submit" value="login" /></td> 
     70                                        </tr></table> 
     71                                </div> 
     72                </form> 
     73                <script language="Javascript" type="text/javascript"> 
     74                        document.loginform.loginname.focus(); 
     75                </script> 
     76                <?php 
     77                $this->html_footer(); 
    4678                exit; 
    4779        } 
    48         if (!$options["top"])   { $options["top"]   = 0;  } else { $options["top"]   = (int)$options["top"];   } 
    49         if (!$options["limit"]) { $options["limit"] = 15; } else { $options["limit"] = (int)$options["limit"]; } 
    50         //put all categories in array 
    51         $res =& $db->query("SELECT * FROM categories"); 
    52         if (PEAR::isError($res)) { 
    53                 die($res->getMessage()); 
    54         } 
    55         while ($res->fetchInto($row, DB_FETCHMODE_ASSOC)) { 
    56                 $cats[$row["id"]] = $row["name"]; 
    57         } 
    58         $cats[-1] = "asides"; 
    59         if ((array_key_exists("month", $options) && $options["month"] > 0) && (array_key_exists("year", $options) && $options["year"] > 0)) { 
    60                 $timestamp_start = mktime(0,0,0,$options["month"],1,$options["year"]); 
    61                 $timestamp_stop  = mktime(0,0,0,$options["month"]+1,1,$options["year"]); 
    62                 $q1 = sprintf("WHERE %s BETWEEN %d AND %d", db_quote("date"), $timestamp_start, $timestamp_stop); 
    63         } else { 
    64                 $options["month"] = 0; 
    65                 $options["year"]  = 0; 
    66         } 
    67  
    68         $res_count =& $db->query("SELECT COUNT(*) FROM articles $q1"); 
    69         $res_count->fetchInto($counter_r, DB_FETCHMODE_NUM); 
    70         $counter = $counter_r[0]; 
    71         $res =& $db->limitQuery(sprintf("SELECT * FROM articles $q1 ORDER BY %s DESC", db_quote("date")), (int)$options["top"], $options["limit"]); 
    72         if (PEAR::isError($res)) { 
    73                 die($res->getDebugInfo()); 
    74         } 
    75         ?> 
    76         <a href="./index.php?action=edit_post&amp;id=0">create new</a> 
    77         <form id="filter" method="post" action="index.php?action=show_posts"> 
    78         <div id="post_select"> 
    79                 View month: 
    80                 <select name="options[month]"> 
    81                         <option value="0">---</option> 
    82                         <? 
    83                         for ($i=1;$i<=12;$i++) { 
    84                                 if ($options["month"] == $i) { $selected = " SELECTED"; } else { $selected = ""; } 
    85                                 ?><option value="<?=$i?>"<?=$selected?>><?=date("M", mktime(0,0,0,$i,1,0))?></option><? 
    86                         } 
     80        /* }}} */ 
     81        /* check_login {{{ */ 
     82        /** 
     83         * Check user supplied data against admin database 
     84         * 
     85         * @param array name and password to check 
     86         */ 
     87        public function check_login($login) { 
     88                $query = sprintf("SELECT * FROM authors WHERE login = '%s' AND password = '%s' AND active = 1", 
     89                        preg_quote($login["name"], "'"), 
     90                        preg_quote($login["password"], "'") 
     91                ); 
     92                $res =& $this->db->query($query); 
     93                if (PEAR::isError($res)) { 
     94                        die($res->getUserInfo()); 
     95                } 
     96                if ($res->numRows()) { 
     97                        $res->fetchInto($row, DB_FETCHMODE_ASSOC); 
     98                        $_SESSION["author_id"]       = $row["id"]; 
     99                        $_SESSION["author_name"]     = $row["login"]; 
     100                        $_SESSION["author_fullname"] = $row["fullname"]; 
     101                        $_SESSION["author_email"]    = $row["email"]; 
     102                        $_SESSION["author_website"]  = $row["website"]; 
     103                        $_SESSION["blog_user"]       = 1; 
     104                        header("Location: index.php"); 
     105                } else { 
     106                        $this->show_login(); 
     107                } 
     108        } 
     109        /* }}} */ 
     110        /* logout {{{ */ 
     111        /** 
     112         * Logout user 
     113         */ 
     114        public function logout() { 
     115                session_destroy(); 
     116                header("Location: index.php"); 
     117        } 
     118        /* }}} */ 
     119        /* db_quote {{{ */ 
     120        /** 
     121         * Quote a fieldname with the database specific quote style 
     122         * 
     123         * @param string fieldname to quote 
     124         * @return string the quoted version 
     125         */ 
     126        public function db_quote($field) { 
     127                /* get the db type */ 
     128                $dbtype = $this->db->dbsyntax; 
     129                switch ($dbtype) { 
     130                        case "mysql" : 
     131                                $return = "`".$field."`"; 
     132                                break; 
     133                        case "pgsql" : 
     134                                $return = "\"".$field."\""; 
     135                                break; 
     136                        default : 
     137                                $return = $field; 
     138                                break; 
     139                } 
     140                return $return; 
     141        } 
     142        /* }}} */ 
     143        /* show_index {{{ */ 
     144        /** 
     145         * Show nice welcome screen for admin 
     146         */ 
     147        public function show_index() { 
     148                ?> 
     149                <p class="first">Welcome to MvBlog "<?=$_SESSION["author_fullname"]?>".</p> 
     150                <p class="first">You can administer your blog with the menu items right above this useless text.</p> 
     151                <p class="first">Enjoy keeping your blog up-to-date</p> 
     152                <p class="first"> 
     153                        If you want to thank/support me, or complain about bugs, or tell me this tool sux, or whatever:<br /> 
     154                        Michiel van Baak<br /> 
     155                        michiel@vanbaak.info 
     156                </p> 
     157                <?php 
     158        } 
     159        /* }}} */ 
     160        /* show_cats {{{ */ 
     161        /** 
     162         * Show overview of available categories 
     163         */ 
     164        public function show_cats() { 
     165                $res =& $this->db->query("SELECT * FROM categories ORDER BY name"); 
     166                if (PEAR::isError($res)) { 
     167                        die($res->getMessage()); 
     168                } 
     169 
     170                ?><a href="./index.php?action=edit_cat&amp;id=0">create new</a><?php 
     171                while ($res->fetchInto($row, DB_FETCHMODE_ASSOC)) { 
    87172                        ?> 
    88                 </select> 
    89                 <select name="options[year]"> 
    90                         <option value="0">---</option> 
    91                         <? 
    92                         /* find the first post we made so we know the start year */ 
    93                         $sql1 = sprintf("SELECT %s FROM articles ORDER BY date ASC", db_quote("date")); 
    94                         $res1 =& $db->limitQuery($sql1, 0, 1); 
    95                         $res1->fetchInto($row1); 
    96                         for ($i=date("Y", $row1[0]);$i<=date("Y");$i++) { 
    97                                 if ($options["year"] == $i) { $selected1 = " SELECTED"; } else { $selected1 = ""; } 
    98                                 ?><option value="<?=$i?>"<?=$selected1?>><?=$i?></option><? 
    99                         } 
    100                         ?> 
    101                 </select> 
    102                 <a href="javascript:document.getElementById('filter').submit();">go</a> 
    103                 <br /><br /> 
    104         </div> 
    105         </form> 
    106         <? 
    107  
    108         while ($res->fetchInto($row, DB_FETCHMODE_ASSOC)) { 
    109                 if (!trim($row["title"])) { 
    110                         $row["title"] = "[no title]"; 
    111                 } 
    112                 if ($row["aside"] == 1) { 
    113                         $row["categories_id"] = -1; 
     173                        <div class="log_post"> 
     174                                <div class="log_post_head"> 
     175                                        <h1 class="log_post_h1"><a href="?action=edit_cat&amp;id=<?php echo $row["id"]; ?>"><?php echo stripslashes($row["name"]); ?></a></h1> 
     176                                        <?php 
     177                                                $r =& $this->db->query(sprintf("SELECT COUNT(*) AS count FROM articles WHERE categories_id = %d", $row["id"])); 
     178                                                if (PEAR::isError($r)) { 
     179                                                        die($r->getMessage()); 
     180                                                } 
     181                                                $r->fetchInto($count, DB_FETCHMODE_ASSOC); 
     182                                        ?> 
     183                                        <h2 class="log_post_h2">articles in this categorie: <?php echo $count["count"]; ?></h2> 
     184                                </div> 
     185                                <div class="log_post_body"> 
     186                                        <div class="log_post_normal"> 
     187                                                <?php echo nl2br(stripslashes($row["desc"])); ?> 
     188                                        </div> 
     189                                </div> 
     190                                <div class="log_post_foot"> 
     191                                        <span class="log_post_date">active: <?php echo $row["active"]; ?></span> 
     192                                        <span class="log_post_author">public: <?php echo $row["public"]; ?></span> 
     193                                </div> 
     194                        </div> 
     195                        <?php 
     196                } 
     197        } 
     198        /* }}} */ 
     199        /* edit_cat {{{ */ 
     200        /** 
     201         * Show form to edit a category. 
     202         * 
     203         * @param int The category id or 0 to create a new one 
     204         */ 
     205        function edit_cat($id) { 
     206                if ($id==0) { 
     207                        $cat["id"]     = 0; 
     208                        $cat["name"]   = "category name"; 
     209                        $cat["desc"]   = "Category description"; 
     210                        $cat["active"] = "1"; 
     211                        $cat["public"] = "1"; 
     212                } else { 
     213                        $res =& $this->db->query(sprintf("SELECT * FROM categories WHERE id = %d", $id)); 
     214                        if (PEAR::isError($res)) { 
     215                                die($res->getMessage()); 
     216                        } 
     217                        $res->fetchInto($cat, DB_FETCHMODE_ASSOC); 
    114218                } 
    115219                ?> 
     220                <form name="category" method="post" action="index.php"> 
     221                <input type="hidden" name="action" value="save_cat" /> 
     222                <input type="hidden" name="cat[id]" value="<?php echo $cat["id"]; ?>" /> 
    116223                <div class="log_post"> 
    117224                        <div class="log_post_head"> 
    118                                 <h1 class="log_post_h1"><a href="?action=edit_post&amp;id=<?=$row["id"]?>"><?=stripslashes($row["title"])?></a></h1> 
    119                                 <? 
    120                                         $r =& $db->query(sprintf("SELECT COUNT(*) FROM articles WHERE categories_id = %d", $row["id"])); 
     225                                <h1 class="log_post_h1"><input type="text" name="cat[name]" value="<?php echo stripslashes($cat["name"]); ?>" /></h1> 
     226                                <?php 
     227                                        $r =& $this->db->query(sprintf("SELECT COUNT(*) AS count FROM articles WHERE categories_id = %d", $cat["id"])); 
    121228                                        if (PEAR::isError($r)) { 
    122229                                                die($r->getMessage()); 
    123230                                        } 
    124                                         $r->fetchInto($count); 
     231                                        $r->fetchInto($count, DB_FETCHMODE_ASSOC); 
    125232                                ?> 
    126                                 <h2 class="log_post_h2">category: <?=$cats[$row["categories_id"]]?></h2> 
     233                                <h2 class="log_post_h2">articles in this categorie: <?php echo $count["count"]; ?></h2> 
     234                        </div> 
     235                        <div class="log_post_body"> 
     236                                <textarea name="cat[description]" style="width: 200px; height: 100px;"><?php echo stripslashes($cat["desc"]); ?></textarea><br /> 
     237                                <input type="submit" value="save" /> 
     238                                <input type="button" value="cancel" onClick="document.forms.category.action.value='show_cats';document.forms.category.submit();" /> 
     239                                <?php if ($id) { ?> 
     240                                        <input type="button" value="delete" onClick="document.forms.category.action.value='delete_cat';document.forms.category.submit();" /> 
     241                                <?php } ?> 
     242                        </div> 
     243                        <div class="log_post_foot"> 
     244                                <span class="log_post_date">active: <input type="checkbox" value="1" name="cat[active]" <?php if ($cat["active"]) { echo "checked=\"checked\""; } ?> /></span> 
     245                                <span class="log_post_author">public: <input type="checkbox" value="1" name="cat[public]" <?php if ($cat["public"]) { echo "checked=\"checked\""; } ?> /></span> 
     246                        </div> 
     247                </div> 
     248                </form> 
     249                <?php 
     250        } 
     251        /* }}} */ 
     252        /* save_cat {{{ */ 
     253        /** 
     254         * Store altered/new category in the database 
     255         * 
     256         * @param array The category info 
     257         */ 
     258        function save_cat($cat) { 
     259                if ($cat["id"]) { 
     260                        $query  = sprintf("UPDATE categories SET %s = '%s', %s = '%s', %s = %d, %s = %d WHERE id = %d", 
     261                                $this->db_quote("name"),   preg_quote(strip_tags($cat["name"]), "'"), 
     262                                $this->db_quote("desc"),   preg_quote(strip_tags($cat["description"]), "'"), 
     263                                $this->db_quote("active"), $cat["active"], 
     264                                $this->db_quote("public"), $cat["public"], 
     265                                $cat["id"] 
     266                        ); 
     267                } else { 
     268                        $query  = sprintf("INSERT INTO categories (%s, %s, %s, %s) VALUES ('%s', '%s', %d, %d)", 
     269                                $this->db_quote("name"), $this->db_quote("desc"), $this->db_quote("active"), $this->db_quote("public"), 
     270                                preg_quote(strip_tags($cat["name"]), "'"), 
     271                                preg_quote(strip_tags($cat["description"]), "'"), 
     272                                $cat["active"], 
     273                                $cat["public"] 
     274                        ); 
     275                } 
     276                $res =& $this->db->query($query); 
     277                if (PEAR::isError($res)) { 
     278                        die($res->getUserInfo()); 
     279                } 
     280                header("Location: index.php?action=show_cats"); 
     281        } 
     282        /* }}} */ 
     283        /* delete_cat {{{ */ 
     284        /** 
     285         * Delete category from database 
     286         * 
     287         * @param int The category id to delete 
     288         */ 
     289        function delete_cat($id) { 
     290                $query = sprintf("DELETE FROM categories WHERE id=%d", $id); 
     291                $res =& $this->db->query($query); 
     292                if (PEAR::isError($res)) { 
     293                        die($res->getUserInfo()); 
     294                } 
     295                header("Location: index.php?action=show_cats"); 
     296        } 
     297        /* }}} */ 
     298        /* show_authors {{{ */ 
     299        /** 
     300         * show all authors 
     301         */ 
     302        public function show_authors() { 
     303                $res =& $this->db->query("SELECT * FROM authors ORDER BY fullname"); 
     304                if (PEAR::isError($res)) { 
     305                        die($res->getMessage()); 
     306                } 
     307 
     308                ?><a href="./index.php?action=edit_author&amp;id=0">create new</a><?php 
     309                while ($res->fetchInto($row, DB_FETCHMODE_ASSOC)) { 
     310                        ?> 
     311                        <div class="log_post"> 
     312                                <div class="log_post_head"> 
     313                                        <h1 class="log_post_h1"> 
     314                                        <a href="?action=edit_author&amp;id=<?php echo $row["id"]; ?>"> 
     315                                                <?php  
     316                                                echo stripslashes($row["fullname"]); 
     317                                                if ($row["active"]) 
     318                                                        echo "(active)"; 
     319                                                else 
     320      &nbs