messages and such
authorpaulr <me@pjr.cc>
Wed, 20 Apr 2011 18:20:30 +0000 (04:20 +1000)
committerpaulr <me@pjr.cc>
Wed, 20 Apr 2011 18:20:30 +0000 (04:20 +1000)
lib/plugins/datastore.php
lib/plugins/db.php
lib/plugins/messages.php [new file with mode: 0644]
lib/plugins/www.php
unittests/msgtest.php [new file with mode: 0644]

index 1b2ff4f..db51d36 100644 (file)
@@ -47,9 +47,9 @@ function ds_leftMenu()
        global $GLOBAL_BASE_URL;
        echo "<b>Browse</b><br>";
        $dss = ds_listDS();
-       echo "<pre>";
+       //echo "<pre>";
        //print_r($dss);
-       echo "</pre>";
+       //echo "</pre>";
        foreach ($dss as $dsl) {
                $dsname = $dsl["dsname"];
                echo "<a href=\"".urlCreate("/ds/browse/$dsname")."\">$dsname</a><br>";
index 1906157..f24917f 100644 (file)
@@ -38,7 +38,7 @@ function db_createTable($tablename)
        }
        $sql .= ")";
        
-       echo "sql: $sql\n";
+       //echo "sql: $sql\n";
        $db->query($sql);
 }
 
@@ -64,6 +64,7 @@ function db_selectData($tablename, $column="", $value="")
        else $extra = "";
        $sql = "select * from \"$tablename\"$extra";
        $res = $db->query($sql);
+       if(!$res) return false;
        $data = $res->fetchAll();
        
        return $data;
diff --git a/lib/plugins/messages.php b/lib/plugins/messages.php
new file mode 100644 (file)
index 0000000..557e6f6
--- /dev/null
@@ -0,0 +1,46 @@
+<?php
+
+
+function msg_haveMessages($acked = false)
+{
+       msg_createTable();
+       
+       return db_selectData("messages", "msgacked", 0);
+}
+
+function msg_getMessages($acked = false)
+{
+       msg_createTable();
+       
+       $data = db_selectData("messages");
+       
+       return $data;
+}
+
+function msg_toDate()
+{
+       
+}
+
+function msg_addMessage($colour, $message)
+{
+       msg_createTable();
+       
+       db_insertData("messages", $colour, time(), "$message", 0);
+}
+
+function msg_deleteMessage($message_id)
+{
+       db_deleteData("messages", "messages_id", "$message_id");
+}
+
+function msg_acknowledge($message_id)
+{
+       db_updateData("messages", "msgacked", "1", "messages_id", "$message_id");       
+}
+
+function msg_createTable()
+{
+       db_createTable("messages", "msgcolour", "msgdate", "msgtext", "msgacked");
+}
+?>
\ No newline at end of file
index ee6bc12..ab6bff9 100644 (file)
@@ -114,6 +114,19 @@ function www_top()
        }
        
        echo "</tr></table>";
+       if(function_exists("msg_haveMessages")) if(msg_haveMessages()) {
+               echo "<table>";
+               $msgs = msg_getMessages();
+               
+               foreach($msgs as $msg) {
+                       $msgtime = msg_toDate($msg["time"]);
+                       $msgcol = $msg["colour"];
+                       $msgtxt = $msg["text"];
+                       
+                       echo "<tr><td><font color=\"$msgcol\">$msgtime - $msgtxt</font>";
+               }
+               echo "</table>";
+       }
 }
 
 function www_leftmenu()
diff --git a/unittests/msgtest.php b/unittests/msgtest.php
new file mode 100644 (file)
index 0000000..c1db060
--- /dev/null
@@ -0,0 +1,41 @@
+<?php
+require_once("../lib/lib.php");
+
+// check
+echo "checking for messages\n";
+if(msg_haveMessages()) {
+       echo "Have some\n";
+} else {
+       echo "Have none\n";
+}
+
+echo "Create 4 message\n";
+msg_addMessage("blue", "hello there");
+msg_addMessage("blue", "hello there");
+msg_addMessage("blue", "hello there");
+msg_addMessage("blue", "hello there");
+
+echo "checking for messages\n";
+if(msg_haveMessages()) {
+       echo "Have some\n";
+} else {
+       echo "Have none\n";
+}
+
+echo "getting messages\n";
+$msgs = msg_getMessages();
+print_r($msgs);
+
+echo "deleting messages\n";
+foreach($msgs as $msg) {
+       msg_deleteMessage($msg["messages_id"]);
+}
+
+echo "checking for messages\n";
+if(msg_haveMessages()) {
+       echo "Have some\n";
+} else {
+       echo "Have none\n";
+}
+
+?>
\ No newline at end of file