<html>
<head>
<title></title>
<style>
.info {
border:1px solid red;
background:#D6E6C6;
color:black;
font-weight:bolder;
padding:3px;
}
.finish {
border:1px solid green;
background:#D6E6C6;
color:black;
font-weight:bolder;
padding:3px;
}
</style>
</head>
<body>
<?php
// http://webdev/libSiteMessage/example.SiteMessage.php
// Read from Top to the bottom. otherways you may not
// understand this script. though it's quite simple,
// read the comments!!
// thanks.
// SET ERROR_REPORTING TO ERRORs ONLY
// OTHERWAYs WE WILL HAVE ALL THE SQLITE-WARNINGS...
error_reporting(E_ERROR);
// INCLUDE NEEDED LIBs
include_once("lib.SiteMessage.php");
include_once("lib.SiteMessageFolder.php");
include_once("lib.SiteMessageException.php");
// CREATE DATABASE AND TABLEs
$db = sqlite_open('libSiteMessage', 0666, $sqliteerror);
$error = sqlite_query($db, "
CREATE TABLE libSiteMessage (
sm_id INTEGER PRIMARY KEY NOT NULL,
sm_sender_id INTEGER NOT NULL,
sm_receiver_id INTEGER NOT NULL,
sm_subject_data TEXT NOT NULL,
sm_message_data TEXT NOT NULL,
sm_message_date VARCHAR(15) NOT NULL,
sm_message_read VARCHAR(15) NULL,
sm_folder_id INTEGER NULL,
UNIQUE (sm_id)
);
");
$error = sqlite_query($db, "
CREATE TABLE libSiteMessageFolders (
sm_folder_id INTEGER PRIMARY KEY NOT NULL,
sm_user_id INTEGER NOT NULL,
sm_folder_name VARCHAR(50) NOT NULL,
sm_parent_id INTEGER(10) NULL,
sm_folder_date VARCHAR(15) NOT NULL,
UNIQUE (sm_user_id,sm_folder_name)
);
");
/**
* TRY TO OPEN FOLDER ID 1, IF IT DOESN't EXIST,
* CREATE A NEW FOLDER(INBOX) FOR USERID 1
*
* SiteMessageFolder::open()
* SiteMessageFolder::create()
**/
$myFolder = new SiteMessageFolder($db);
try {
// OPEN
$myFolder->open(1);
echo "<pre class=\"info\">-> opened Folder</pre>";
} catch (FolderNotAvailableException $e) {
// CREATE
$myFolder->create("INBOX","1");
echo "<pre class=\"info\">-> created Folder</pre>";
} catch (SQLiteException $e) {
// DIE BECAUSE OF SQL-ERROR
die($e->getMessage());
}
/**
* SOME TESTs
*
* SiteMessageFolder::getName()
* SiteMessageFolder::getDate()
* SiteMessageFolder::hasSubfolder()
* SiteMessageFolder::hasMessage()
**/
echo "<pre>Foldername: ".$myFolder->getName()."</pre>";
echo "<pre>created: ".date("H:i:s d.m.Y", $myFolder->getDate())."</pre>";
echo "<pre>Subfolders: ".$myFolder->hasSubfolder()."</pre>";
echo "<pre>Messages: ".$myFolder->hasMessage()."</pre>";
/**
* SOME TESTs
*
* SiteMessageFolder::setName()
**/
try {
switch($myFolder->getName()) {
case "INBOX": echo "<pre class=\"info\">-> renaming folder from INBOX to OUTBOX...</pre>";
$myFolder->setName("OUTBOX");
break;
case "OUTBOX": echo "<pre class=\"info\">-> renaming folder from OUTBOX to INBOX...</pre>";
$myFolder->setName("INBOX");
break;
}
} catch (SQLiteException $e) {
die($e->getMessage());
}
/**
* SOME TESTs
*
* SiteMessageFolder::getName()
**/
echo "<pre>Foldername: ".$myFolder->getName()."</pre>";
/**
* Create a Subfolder of Folder #1
*/
echo "<pre class=\"info\">-> creating subfolder</pre>";
$myFolder->create("SUB1",1,1);
$myFolder->open(1);
/**
* SOME TESTs
*
* SiteMessageFolder::hasSubfolder()
**/
echo "<pre>Subfolders: ".$myFolder->hasSubfolder()."</pre>";
$mySubFolder = $myFolder->getSubfolder(1);
/**
* SOME TESTs ON SUBFOLDER
*
* SiteMessageFolder::getName()
* SiteMessageFolder::getDate()
* SiteMessageFolder::hasSubfolder()
* SiteMessageFolder::hasMessage()
**/
echo "<pre class=\"info\">-> showing subfolder-infos</pre>";
echo "<pre>Foldername: ".$mySubFolder->getName()."</pre>";
echo "<pre>created: ".date("H:i:s d.m.Y", $mySubFolder->getDate())."</pre>";
echo "<pre>Subfolders: ".$mySubFolder->hasSubfolder()."</pre>";
echo "<pre>Messages: ".$mySubFolder->hasMessage()."</pre>";
/**
* SOME TESTs
*
* SiteMessage::create()
* SiteMessageFolder::hasMessage()
**/
$myMessage = new SiteMessage($db);
try {
if($myMessage->create(1,1,"This is the subject","This is the text")) {
echo "<pre class=\"info\">-> creating a message</pre>";
}
} catch (SQLiteException $e) {
// DIE BECAUSE OF SQL-ERROR
die($e->getMessage());
}
/**
* SOME TESTs
* Move the newly created message into INBOX-Folder (id:1)
*/
echo "<pre class=\"info\">-> moving message to folder INBOX.</pre>";
$myMessage->setFolder(1);
/**
* SOME TESTs
* SiteMessageFolder::hasMessage()
**/
echo "<pre>Messages: ".$myFolder->hasMessage()."</pre>";
/**
* SOME TESTs
*
* SiteMessage::getSender()
* SiteMessage::getReceiver()
* SiteMessage::getSubject()
* SiteMessage::getText()
* SiteMessage::getDate()
**/
echo "<pre class=\"info\">-> show Message-Informations</pre>";
echo "<pre>Sender(id): ".$myMessage->getSender()."</pre>";
echo "<pre>Receiver(id): ".$myMessage->getReceiver()."</pre>";
echo "<pre>Folder(id): ".$myMessage->getFolder()."</pre>";
echo "<pre>Date: ".date("H:i:s d.m.Y", $myMessage->getDate())."</pre>";
echo "<pre>Subject: ".$myMessage->getSubject()."</pre>";
echo "<pre>Text: ".$myMessage->getText()."</pre>";
/**
* SOME TESTs
* Deleting Folder #1
* comment out, to keep all messages, folders, etc.
*/
echo "<pre class=\"info\">-> Deleting Folder (id:1) and all Subfolders/Messages</pre>";
$myFolder->delete();
echo "<pre class=\"finish\">That's it. All Messages and Folders have been deleted.
<p>Be inspired </p> Have fun! <p>- Cornelius -</p></pre>";
?>
</body>
</html>
|