- <?php
- /**
- * <b>Database Class : Main</b><br />
- * Provides all database access methods for:
- * - Main Page
- * - Announcements
- * - Bible Trivia
- * - Bible Verses
- * - Devotionals
- * - FAQ
- * - Resources
- * @author Kristen O'Brien <kristen_paristemi-com>
- * @copyright Copyright 2004, Kristen O'Brien
- * @license http://opensource.org/licenses/gpl-license.php GNU Public License
- * @link http://www.paristemi.com Paristemi Main Site
- * @package paristemi
- * @subpackage paristemi_database_layer
- * @since Build 0.5
- * @version Build 0.7
- * @filesource
- */
- /**
- * <b>Database Class : Main</b><br />
- * Provides all database access methods for:
- * - Main Page
- * - Announcements
- * - Bible Trivia
- * - Bible Verses
- * - Devotionals
- * - FAQ
- * - Resources
- * @author Kristen O'Brien <kristen_paristemi-com>
- * @copyright Copyright 2004, Kristen O'Brien
- * @license http://opensource.org/licenses/gpl-license.php GNU Public License
- * @link http://www.paristemi.com Paristemi Main Site
- * @package paristemi
- * @subpackage paristemi_database_layer
- * @since Build 0.5
- * @version Build 0.7
- * @filesource
- */
- class DB_Main {
-
- function DB_Main() { }
-
- //There must be an ID associated with all of the elements.
-
- function &GetAllAnnouncements() {
- $data = Array();
- $result = mysql_query("select A.ID, A.Title, A.Category,
- A.Description, A.Created, A.EndDate, A.ContactID,
- C.Last, C.First, C.Email,
- C.ShowMainTitle, C.ShowMainFirstName, C.Title as CTitle
- from Announcement A, Contact C
- where C.ID = A.ContactID
- order by A.Created desc");
-
- //Process each row.
- while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
-
- $createdstamp = strtotime($row['Created']);
- $created = getDate($createdstamp);
- $endstamp = strtotime($row['EndDate']);
- $enddate = getDate($endstamp);
-
- $fullname = "";
- if($row['ShowMainTitle']) { $fullname .= $row['CTitle']." "; }
- if($row['ShowMainFirstName']) { $fullname .= $row['First']." ".$row['Last']; }
- $data[] = new Announcement($row['ID'], $row['Title'], $row['Category'],
- $row['Description'], $created, $enddate,
- $fullname, $row['ContactID'], $row['Email']);
- }
-
- return $data;
- }
-
- // There must be an ID associated with all of the elements.
-
- function &GetAnnouncementsByCat($cat,$limit=0,$useend=1) {
- $data = Array();
- $limittext = ""; $endtext = "";
- if($limit) { $limittext = "LIMIT ".$limit; }
- if($useend) { $endtext = " AND A.EndDate >= CURDATE() "; }
- $result = mysql_query("SELECT A.ID, A.Title, A.Category,
- A.Description, A.Created, A.EndDate, A.ContactID,
- C.Last, C.First, C.Email,
- C.ShowMainTitle, C.ShowMainFirstName, C.Title as CTitle
- FROM Announcement A, Contact C
- WHERE C.ID = A.ContactID
- AND A.Category = '$cat'
- $endtext
- ORDER BY A.Created desc
- $limittext");
-
- //Process each row.
- while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
-
- $createdstamp = strtotime($row['Created']);
- $created = getDate($createdstamp);
- $endstamp = strtotime($row['EndDate']);
- $enddate = getDate($endstamp);
-
- $fullname = "";
- if($row['ShowMainTitle']) { $fullname .= $row['CTitle']." "; }
- if($row['ShowMainFirstName']) { $fullname .= $row['First']." ".$row['Last']; }
- $data[] = new Announcement($row['ID'], $row['Title'], $row['Category'],
- $row['Description'], $created, $enddate,
- $fullname, $row['ContactID'], $row['Email']);
- }
-
- return $data;
- }
-
- //There must be an ID associated with all of the elements.
-
- function &GetFAQsByCategory(&$category) {
- $data = Array();
- $result = mysql_query("select F.ID, F.Title, F.Category, F.Text, F.Links
- from FAQ F
- where F.Category = '$category'
- order by F.ID asc");
-
- //Process each row.
- while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
- $data[] = new FAQ($row['ID'], $row['Title'], $row['Category'],
- $row['Text'], $row['Links']);
- }
-
- return $data;
- }
-
- //There must be an ID associated with all of the elements.
-
- function &GetFAQCategories() {
- $data = Array();
- $result = mysql_query("select DISTINCT F.Category
- from FAQ F
- order by F.Category");
-
- //Process each row.
- while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
- $data[] = $row['Category'];
- }
-
- return $data;
- }
-
- //There must be an ID associated with all of the elements.
-
- function &GetResourcesByCategory(&$category) {
- $data = Array();
- $result = mysql_query("select R.ID, R.Title, R.Description, R.Link, R.Category
- from Resource R
- where R.Category = '$category'
- AND R.ShowItem = 1
- order by R.Title");
-
- //Process each row.
- while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
- $data[] = new Resource($row['ID'], $row['Title'],
- $row['Description'], $row['Link'], $row['Category']);
- }
-
- return $data;
- }
-
- //There must be an ID associated with all of the elements.
-
- function &GetResourceCategories() {
- $data = Array();
- $result = mysql_query("select DISTINCT R.Category
- from Resource R
- order by R.Category");
-
- //Process each row.
- while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
- $data[] = $row['Category'];
- }
-
- return $data;
- }
-
- function &GetRandomBibleVerse()
- {
- $result = mysql_query("select Verse
- from BibleVerses
- order by rand()
- limit 1");
- $row = mysql_fetch_array($result, MYSQL_ASSOC);
- return $row['Verse'];
- }
-
- function &GetTodaysBibleVerse($seder=1)
- {
- $today = getdate(time());
- $thisday = $today['yday']+$seder;
- $result = mysql_query("select Verse
- from BibleVerses
- where ID = $thisday
- limit 1");
- $row = mysql_fetch_array($result, MYSQL_ASSOC);
- return $row['Verse'];
- }
-
- //There must be an ID associated with all of the elements.
-
- function &GetAllBibleTrivia($limit,$blimit,$order) {
- $data = Array();
- $query_string = "select BT.ID, BT.Title, BT.Question, BT.Showcase, BT.AnswerNum,
- BT.CorrectText, BT.IncorrectText, BT.Answer1, BT.Answer2,
- BT.Answer3, BT.Answer4, BT.Answer5, BT.Answer6
- from BibleTrivia BT
- where BT.ShowItem > 0
- order by $order
- limit $blimit,$limit";
- $result = mysql_query($query_string);
-
- //Process each row.
- while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
- $data[] = new BibleTrivia($row['ID'],$row['Title'],$row['Question'],$row['Showcase'],
- $row['AnswerNum'],$row['CorrectText'],$row['IncorrectText'],
- $row['Answer1'],$row['Answer2'],$row['Answer3'],$row['Answer4'],
- $row['Answer5'],$row['Answer6']);
- }
-
- return $data;
- }
-
- //There must be an ID associated with all of the elements.
-
- function &GetAllBibleTriviaCount() {
- $result = mysql_query("select count(*)
- from BibleTrivia BT
- where BT.ShowItem > 0");
-
- $row = mysql_fetch_array($result, MYSQL_ASSOC);
- foreach($row as $item) { $data = $item; }
- return $data;
- }
-
- function &IncrementBibleTriviaAnsweredCount(&$id) {
- $result = mysql_query("update BibleTrivia set AnsweredCount=AnsweredCount+1
- where ID = $id");
- return $result;
- }
-
- //There must be an ID associated with all of the elements.
-
- function &GetBibleTrivia(&$id) {
- $result = mysql_query("select BT.ID, BT.Title, BT.Question, BT.Showcase, BT.AnswerNum,
- BT.CorrectText, BT.IncorrectText, BT.Answer1, BT.Answer2,
- BT.Answer3, BT.Answer4, BT.Answer5, BT.Answer6
- from BibleTrivia BT
- where BT.ID = $id
- limit 1");
-
- $row = mysql_fetch_array($result, MYSQL_ASSOC);
- $data = new BibleTrivia($row['ID'],$row['Title'],$row['Question'],$row['Showcase'],
- $row['AnswerNum'],$row['CorrectText'],$row['IncorrectText'],
- $row['Answer1'],$row['Answer2'],$row['Answer3'],$row['Answer4'],
- $row['Answer5'],$row['Answer6']);
-
- return $data;
- }
-
- //There must be an ID associated with all of the elements.
-
- function &GetShowcaseBibleTrivia() {
- $result = mysql_query("select BT.ID, BT.Title, BT.Question, BT.Showcase, BT.AnswerNum,
- BT.CorrectText, BT.IncorrectText, BT.Answer1, BT.Answer2,
- BT.Answer3, BT.Answer4, BT.Answer5, BT.Answer6
- from BibleTrivia BT
- where BT.Showcase > 0
- AND BT.ShowItem > 0
- limit 1");
-
- $row = mysql_fetch_array($result, MYSQL_ASSOC);
- $data = new BibleTrivia($row['ID'],$row['Title'],$row['Question'],$row['Showcase'],
- $row['AnswerNum'],$row['CorrectText'],$row['IncorrectText'],
- $row['Answer1'],$row['Answer2'],$row['Answer3'],$row['Answer4'],
- $row['Answer5'],$row['Answer6']);
-
- return $data;
- }
-
- //There must be an ID associated with all of the elements.
-
- function &GetAllDevotional($limit,$blimit,$order) {
- $data = Array();
-
- $result = mysql_query("select D.ID, D.Title, D.Text, D.KeyVerse, D.Verses, D.Showcase, D.Prayer,
- C.ID as CID, C.First, C.Last, C.Email, C.Title as CTitle,
- C.ShowMainTitle, C.ShowMainFirstName, C.ShowMainLastName
- from Devotional D, Contact C
- where D.AuthorID = C.ID
- AND D.ShowItem > 0
- order by $order
- limit $blimit,$limit");
-
- //Process each row.
- while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
- $name = "";
- if($row['ShowMainTitle']) { $name .= $row['CTitle']." "; }
- if($row['ShowMainFirstName']) { $name .= $row['First']." "; }
- if($row['ShowMainLastName']) { $name .= $row['Last']; }
- $data[] = new Devotional($row['ID'],$row['Title'],$row['Text'],$row['KeyVerse'],$row['Prayer'],
- $row['Verses'],$row['CID'],$name,$row['Email'],$row['Showcase']);
- }
-
- return $data;
- }
- //There must be an ID associated with all of the elements.
-
- function &GetAllDevotionalCount() {
- $data = Array();
-
- $result = mysql_query("select count(*)
- from Devotional D
- where D.ShowItem > 0");
-
- $row = mysql_fetch_array($result, MYSQL_ASSOC);
- foreach($row as $item) { $data = $item; }
- return $data;
- }
- //There must be an ID associated with all of the elements.
-
- function &GetDevotional(&$id) {
- $result = mysql_query("select D.ID, D.Title, D.Text, D.KeyVerse, D.Verses, D.Showcase, D.Prayer,
- C.ID as CID, C.First, C.Last, C.Email, C.Title as CTitle,
- C.ShowMainTitle, C.ShowMainFirstName, C.ShowMainLastName
- from Devotional D, Contact C
- where D.AuthorID = C.ID
- AND D.ID = $id
- order by D.Title desc
- limit 1");
-
- $row = mysql_fetch_array($result, MYSQL_ASSOC);
- $name = "";
- if($row['ShowMainTitle']) { $name .= $row['CTitle']." "; }
- if($row['ShowMainFirstName']) { $name .= $row['First']." "; }
- if($row['ShowMainLastName']) { $name .= $row['Last']; }
- $data = new Devotional($row['ID'],$row['Title'],$row['Text'],$row['KeyVerse'],$row['Prayer'],
- $row['Verses'],$row['CID'],$name,$row['Email'],$row['Showcase']);
-
- return $data;
- }
-
- //There must be an ID associated with all of the elements.
-
- function &GetShowcaseDevotional() {
- $result2 = mysql_query("select MAX(ID) from Devotional where Showcase > 0 AND ShowItem > 0");
- $row2 = mysql_fetch_array($result2, MYSQL_ASSOC);
- foreach($row2 as $idnum) { $id = $idnum; }
- if($id == null) {
- $result2 = mysql_query("select MAX(ID) from Devotional where ShowItem > 0");
- $row2 = mysql_fetch_array($result2, MYSQL_ASSOC);
- foreach($row2 as $idnum) { $id = $idnum; }
- }
- $result = mysql_query("select D.ID, D.Title, D.Text, D.KeyVerse, D.Verses, D.Showcase, D.Prayer,
- C.ID as CID, C.First, C.Last, C.Email, C.Title as CTitle,
- C.ShowMainTitle, C.ShowMainFirstName, C.ShowMainLastName
- from Devotional D, Contact C
- where D.AuthorID = C.ID AND D.ID = $id
- limit 1");
- $row = mysql_fetch_array($result, MYSQL_ASSOC);
- $name = "";
- if($row['ShowMainTitle']) { $name = $row['CTitle']." "; }
- if($row['ShowMainFirstName']) { $name .= $row['First']." "; }
- if($row['ShowMainLastName']) { $name .= $row['Last']; }
- $data = new Devotional($row['ID'],$row['Title'],$row['Text'],$row['KeyVerse'],$row['Prayer'],
- $row['Verses'],$row['CID'],$name,$row['Email'],$row['Showcase']);
-
- return $data;
- }
- }
-
-
- /**
- * <b>Database Container Class : Announcement</b><br />
- * Contains all of the specific data for an announcement.
- * @author Kristen O'Brien <kristen_paristemi-com>
- * @copyright Copyright 2004, Kristen O'Brien
- * @license http://opensource.org/licenses/gpl-license.php GNU Public License
- * @link http://www.paristemi.com Paristemi Main Site
- * @package paristemi
- * @subpackage paristemi_database_layer
- * @since Build 0.5
- * @version Build 0.7
- * @filesource
- */
- class Announcement {
- var $ID;
- var $Title;
- var $Category;
- var $Description;
- var $Created;
- var $EndDate;
- var $Name;
- var $CID;
- var $Email;
-
- function Announcement($id,$title,$cat,$desc,$created,$enddate,$name,$cid,$email) {
- $this->ID = $id;
- $this->Title = $title;
- $this->Category = $cat;
- $this->Description = $desc;
- $this->Created = $created;
- $this->EndDate = $enddate;
- $this->Name = $name;
- $this->CID = $cid;
- $this->Email = $email;
- }
- }
-
- /**
- * <b>Database Container Class Resource</b><br />
- * Contains all of the specific data for a resource (link).
- * @author Kristen O'Brien <kristen_paristemi-com>
- * @copyright Copyright 2004, Kristen O'Brien
- * @license http://opensource.org/licenses/gpl-license.php GNU Public License
- * @link http://www.paristemi.com Paristemi Main Site
- * @package paristemi
- * @subpackage paristemi_database_layer
- * @since Build 0.5
- * @version Build 0.7
- * @filesource
- */
- class Resource {
- var $ID;
- var $Title;
- var $Description;
- var $Link;
- var $Category;
-
- function Resource($id,$title,$desc,$link,$category) {
- $this->ID = $id;
- $this->Title = $title;
- $this->Description = $desc;
- $this->Link = $link;
- $this->Category = $category;
- }
- }
-
- /**
- * <b>Database Container Class : FAQ</b><br />
- * Contains all of the specific data for a FAQ (Frequently Asked Question).
- * @author Kristen O'Brien <kristen_paristemi-com>
- * @copyright Copyright 2004, Kristen O'Brien
- * @license http://opensource.org/licenses/gpl-license.php GNU Public License
- * @link http://www.paristemi.com Paristemi Main Site
- * @package paristemi
- * @subpackage paristemi_database_layer
- * @since Build 0.5
- * @version Build 0.7
- * @filesource
- */
- class FAQ {
- var $ID;
- var $Title;
- var $Category;
- var $Text;
- var $Links;
-
- function FAQ($id,$title,$category,$text,$links) {
- $this->ID = $id;
- $this->Title = $title;
- $this->Category = $category;
- $this->Text = $text;
- $this->Links = $links;
- }
- }
-
- /**
- * <b>Database Container Class : Bible Trivia</b><br />
- * Contains all of the specific data for a bible trivia question.
- * @author Kristen O'Brien <kristen_paristemi-com>
- * @copyright Copyright 2004, Kristen O'Brien
- * @license http://opensource.org/licenses/gpl-license.php GNU Public License
- * @link http://www.paristemi.com Paristemi Main Site
- * @package paristemi
- * @subpackage paristemi_database_layer
- * @since Build 0.5
- * @version Build 0.7
- * @filesource
- */
- class BibleTrivia {
- var $ID;
- var $Title;
- var $Question;
- var $Showcase;
- var $AnswerNum;
- var $CorrectText;
- var $IncorrectText;
- var $Answer1;
- var $Answer2;
- var $Answer3;
- var $Answer4;
- var $Answer5;
- var $Answer6;
-
- function BibleTrivia($id,$title,$question,$showcase,$answernum,$ctext,$ictext,
- $ans1,$ans2,$ans3,$ans4,$ans5,$ans6) {
- $this->ID = $id;
- $this->Title = $title;
- $this->Question = $question;
- $this->Showcase = $showcase;
- $this->AnswerNum = $answernum;
- $this->CorrectText = $ctext;
- $this->IncorrectText = $ictext;
- $this->Answer1 = $ans1;
- $this->Answer2 = $ans2;
- $this->Answer3 = $ans3;
- $this->Answer4 = $ans4;
- $this->Answer5 = $ans5;
- $this->Answer6 = $ans6;
- }
- }
-
- /**
- * <b>Database Container Class : Devotional</b><br />
- * Contains all of the specific data for a devotional.
- * @author Kristen O'Brien <kristen_paristemi-com>
- * @copyright Copyright 2004, Kristen O'Brien
- * @license http://opensource.org/licenses/gpl-license.php GNU Public License
- * @link http://www.paristemi.com Paristemi Main Site
- * @package paristemi
- * @subpackage paristemi_database_layer
- * @since Build 0.5
- * @version Build 0.7
- * @filesource
- */
- class Devotional {
- var $ID;
- var $Title;
- var $Text;
- var $KeyVerse;
- var $Prayer;
- var $Verses;
- var $AuthorID;
- var $AuthorName;
- var $AuthorEmail;
- var $Showcase;
-
- function Devotional($id,$title,$text,$keyverse,$prayer,
- $verses,$aid,$aname,$aemail,$showcase) {
- $this->ID = $id;
- $this->Title = $title;
- $this->Text = $text;
- $this->KeyVerse = $keyverse;
- $this->Prayer = $prayer;
- $this->Verses = $verses;
- $this->AuthorID = $aid;
- $this->AuthorName = $aname;
- $this->AuthorEmail = $aemail;
- $this->Showcase = $showcase;
- }
- }
-
- ?>