Changeset 77 for trunk/admin

Show
Ignore:
Timestamp:
03/27/06 22:06:15 (3 years ago)
Author:
michiel
Message:

added access to comments.
You can now delete the comments from here. The rest will follow soon.

re #41

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/admin/index.php

    r73 r77  
    971971} 
    972972 
     973//}}}------------------------------------ 
     974//{{{ show_comments(): show comment items 
     975//--------------------------------------- 
     976function show_comments($options) { 
     977        global $db; 
     978        if (!$options["top"]) { $options["top"] = 0; } else { $options["top"] = (int)$options["top"]; } 
     979        if (!$options["limit"]) { $options["limit"] = 15; } else { $options["limit"] = (int)$options["limit"]; } 
     980        /* create an array with the article titles */ 
     981        $sql = "SELECT id,title FROM articles"; 
     982        $res = $db->query($sql); 
     983        $articles[0] = "no article"; 
     984        while ($res->fetchInto($row, DB_FETCHMODE_ASSOC)) { 
     985                $articles[$row["id"]] = $row["title"]; 
     986        } 
     987        /* loop through the comments */ 
     988        $res_count =& $db->query("SELECT COUNT(*) FROM comments"); 
     989        $res_count->fetchInto($counter_r, DB_FETCHMODE_NUM); 
     990        $counter = $counter_r[0]; 
     991        $res =& $db->limitQuery("SELECT * FROM comments ORDER BY date DESC", (int)$options["top"], $options["limit"]); 
     992        if (PEAR::isError($res)) { 
     993                die($res->getMessage()); 
     994        } 
     995        while ($res->fetchInto($row, DB_FETCHMODE_ASSOC)) { 
     996                if (!trim($row["title"])) { $row["title"] = "no title"; } 
     997                ?> 
     998                <div class="log_post"> 
     999                        <div class="log_head"> 
     1000                                <span class="log_subject"> 
     1001                                        <?=$row["title"]?> (<?=$articles[$row["articles_id"]]?>) 
     1002                                        <span class="log_cat"><br /> 
     1003                                                name: <?=$row["name"]?>&nbsp;ip: <?=$row["ip"]?><br /> 
     1004                                                website: <?=$row["website"]?>&nbsp;email: <?=$row["email"]?> 
     1005                                        </span> 
     1006                                </span> 
     1007                        </div> 
     1008                        <div class="log_contents"> 
     1009                                <?=$row["comment"]?> 
     1010                        </div> 
     1011                        <div class="log_foot"> 
     1012                                <!-- not yet implemented 
     1013                                <? if (trim($row["ip"])) { ?><a href="index.php?action=blacklist_ip&commentid=<?=$row["id"]?>">blacklist ip</a><? } ?>&nbsp;&nbsp; 
     1014                                --> 
     1015                                <a href="index.php?action=delete_comment&id=<?=$row["id"]?>">delete</a> 
     1016                        </div> 
     1017                </div> 
     1018                <? 
     1019        } 
     1020        if ($options["top"]) { 
     1021                echo "<a href=\"index.php?action=show_comments&amp;options[top]=".($options["top"]-$options["limit"])."\">previous</a> "; 
     1022        } 
     1023        if (($options["top"] + $options["limit"]) > $counter) { 
     1024                $end = $counter; 
     1025        } else { 
     1026                $end = ($options["top"]+$options["limit"]); 
     1027        } 
     1028        if ($counter == 0) { 
     1029                echo "<span class=\"log_cat\">no comments"; 
     1030        } else { 
     1031                echo "<span class=\"log_cat\">showing ".($options["top"]+1)." to ".$end." of ".$counter." total comments"; 
     1032        } 
     1033        if (($options["top"]+$options["limit"]) < $counter) { 
     1034                echo " <a href=\"index.php?action=show_comments&amp;options[top]=".($options["top"]+$options["limit"])."\">next</a>"; 
     1035        } 
     1036        echo "</span>"; 
     1037} 
     1038 
     1039//}}}-------------------------------------------------------- 
     1040//{{{ delete_comment($id): Delete a comment from the database 
     1041//----------------------------------------------------------- 
     1042function delete_comment($id) { 
     1043        global $db; 
     1044        $sql = sprintf("DELETE FROM comments WHERE id = %d", $id); 
     1045        $res = $db->query($sql); 
     1046        header("Location: index.php?action=show_comments"); 
     1047} 
     1048 
    9731049//}}}------------------------------------------ 
    9741050//{{{ html_header_admin: create own html header 
     
    10031079                <div id="if_title"></div> 
    10041080                <div id="if_menu"> 
    1005                         &nbsp;<a class="if_menu_item" href="../index.php">&nbsp;View&nbsp;Site</a>&nbsp; 
    1006                         &nbsp;<a class="if_menu_item<? if ($_REQUEST["action"] == "show_cats") { echo "_act"; } ?>" href="./index.php?action=show_cats">&nbsp;categories</a>&nbsp; 
    1007                         &nbsp;<a class="if_menu_item<? if ($_REQUEST["action"] == "show_authors") { echo "_act"; } ?>" href="./index.php?action=show_authors">&nbsp;authors</a>&nbsp; 
    1008 <!--                    &nbsp;<a class="if_menu_item" href="./index.php?action=show_comments">&nbsp;comments</a>&nbsp; --> 
    1009                         &nbsp;<a class="if_menu_item<? if ($_REQUEST["action"] == "show_posts") { echo "_act"; } ?>" href="./index.php?action=show_posts">&nbsp;posts</a>&nbsp; 
    1010                         &nbsp;<a class="if_menu_item<? if ($_REQUEST["action"] == "show_acro") { echo "_act"; } ?>" href="./index.php?action=show_acro">&nbsp;acronyms</a>&nbsp; 
    1011 <!--                    &nbsp;<a class="if_menu_item<? if ($_REQUEST["action"] == "show_pages") { echo "_act"; } ?>" href="./index.php?action=show_pages">&nbsp;pages</a>&nbsp; 
     1081                        <a class="if_menu_item" href="../index.php">Site</a>&nbsp; 
     1082                        <a class="if_menu_item<? if ($_REQUEST["action"] == "show_cats") { echo "_act"; } ?>" href="./index.php?action=show_cats">categories</a>&nbsp; 
     1083                        <a class="if_menu_item<? if ($_REQUEST["action"] == "show_authors") { echo "_act"; } ?>" href="./index.php?action=show_authors">authors</a>&nbsp; 
     1084                        <a class="if_menu_item<? if ($_REQUEST["action"] == "show_comments") { echo "_act"; } ?>" href="./index.php?action=show_comments">comments</a>&nbsp; 
     1085                        <a class="if_menu_item<? if ($_REQUEST["action"] == "show_posts") { echo "_act"; } ?>" href="./index.php?action=show_posts">posts</a>&nbsp; 
     1086                        <a class="if_menu_item<? if ($_REQUEST["action"] == "show_acro") { echo "_act"; } ?>" href="./index.php?action=show_acro">acronyms</a>&nbsp; 
     1087<!--                    <a class="if_menu_item<? if ($_REQUEST["action"] == "show_pages") { echo "_act"; } ?>" href="./index.php?action=show_pages">&nbsp;pages</a>&nbsp; 
    10121088--> 
    1013                         &nbsp;<a class="if_menu_item<? if ($_REQUEST["action"] == "show_settings") { echo "_act"; } ?>" href="./index.php?action=show_settings">&nbsp;blogsettings</a>&nbsp; 
    1014                         &nbsp;<a class="if_menu_item<? if ($_REQUEST["action"] == "show_menuitems") { echo "_act"; } ?>" href="./index.php?action=show_menuitems">&nbsp;menu items</a>&nbsp; 
    1015                         &nbsp;<a class="if_menu_item" href="./login.php?action=logout">&nbsp;logout</a>&nbsp; 
     1089                        <a class="if_menu_item<? if ($_REQUEST["action"] == "show_settings") { echo "_act"; } ?>" href="./index.php?action=show_settings">blogsettings</a>&nbsp; 
     1090                        <a class="if_menu_item<? if ($_REQUEST["action"] == "show_menuitems") { echo "_act"; } ?>" href="./index.php?action=show_menuitems">menuitems</a>&nbsp; 
     1091                        <a class="if_menu_item" href="./login.php?action=logout">logout</a>&nbsp; 
    10161092                </div> 
    10171093                <div id="if_bar1"></div> 
    10181094                <div id="if_page_header"> 
    1019                         <h1 class="page_title">admin</h1> 
     1095                        <a href="index.php"><h1 class="page_title">admin</h1></a> 
    10201096                </div> 
    10211097                <div id="if_page"> 
     
    10411117                                case "show_menuitems" : show_menuitems();                     break; 
    10421118                                case "save_menuitems" : save_menuitems($_POST["link"]);       break; 
     1119                                case "show_comments"  : show_comments($_REQUEST["options"]);  break; 
     1120                                case "delete_comment" : delete_comment($_REQUEST["id"]);      break; 
    10431121                                default               : show_index();                         break; 
    10441122                        }