paristemi
[ class tree: paristemi ] [ index: paristemi ] [ all elements ]

Source for file db_main.php

Documentation is available at db_main.php

  1. <?php
  2. /**
  3. * <b>Database Class : Main</b><br />
  4. * Provides all database access methods for:
  5. * - Main Page
  6. * - Announcements
  7. * - Bible Trivia
  8. * - Bible Verses
  9. * - Devotionals
  10. * - FAQ
  11. * - Resources
  12. * @author Kristen O'Brien <kristen_paristemi-com>
  13. * @copyright Copyright 2004, Kristen O'Brien
  14. * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  15. * @link http://www.paristemi.com Paristemi Main Site
  16. * @package paristemi
  17. * @subpackage paristemi_database_layer
  18. * @since Build 0.5
  19. * @version Build 0.7
  20. * @filesource
  21. */
  22. /**
  23. * <b>Database Class : Main</b><br />
  24. * Provides all database access methods for:
  25. * - Main Page
  26. * - Announcements
  27. * - Bible Trivia
  28. * - Bible Verses
  29. * - Devotionals
  30. * - FAQ
  31. * - Resources
  32. * @author Kristen O'Brien <kristen_paristemi-com>
  33. * @copyright Copyright 2004, Kristen O'Brien
  34. * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  35. * @link http://www.paristemi.com Paristemi Main Site
  36. * @package paristemi
  37. * @subpackage paristemi_database_layer
  38. * @since Build 0.5
  39. * @version Build 0.7
  40. * @filesource
  41. */
  42. class DB_Main {
  43. function DB_Main() { }
  44. //There must be an ID associated with all of the elements.
  45. function &GetAllAnnouncements() {
  46. $data = Array();
  47. $result = mysql_query("select A.ID, A.Title, A.Category,
  48. A.Description, A.Created, A.EndDate, A.ContactID,
  49. C.Last, C.First, C.Email,
  50. C.ShowMainTitle, C.ShowMainFirstName, C.Title as CTitle
  51. from Announcement A, Contact C
  52. where C.ID = A.ContactID
  53. order by A.Created desc");
  54. //Process each row.
  55. while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
  56.  
  57. $createdstamp = strtotime($row['Created']);
  58. $created = getDate($createdstamp);
  59. $endstamp = strtotime($row['EndDate']);
  60. $enddate = getDate($endstamp);
  61.  
  62. $fullname = "";
  63. if($row['ShowMainTitle']) { $fullname .= $row['CTitle']." "; }
  64. if($row['ShowMainFirstName']) { $fullname .= $row['First']." ".$row['Last']; }
  65. $data[] = new Announcement($row['ID'], $row['Title'], $row['Category'],
  66. $row['Description'], $created, $enddate,
  67. $fullname, $row['ContactID'], $row['Email']);
  68. }
  69.  
  70. return $data;
  71. }
  72. // There must be an ID associated with all of the elements.
  73. function &GetAnnouncementsByCat($cat,$limit=0,$useend=1) {
  74. $data = Array();
  75. $limittext = ""; $endtext = "";
  76. if($limit) { $limittext = "LIMIT ".$limit; }
  77. if($useend) { $endtext = " AND A.EndDate >= CURDATE() "; }
  78. $result = mysql_query("SELECT A.ID, A.Title, A.Category,
  79. A.Description, A.Created, A.EndDate, A.ContactID,
  80. C.Last, C.First, C.Email,
  81. C.ShowMainTitle, C.ShowMainFirstName, C.Title as CTitle
  82. FROM Announcement A, Contact C
  83. WHERE C.ID = A.ContactID
  84. AND A.Category = '$cat'
  85. $endtext
  86. ORDER BY A.Created desc
  87. $limittext");
  88. //Process each row.
  89. while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
  90.  
  91. $createdstamp = strtotime($row['Created']);
  92. $created = getDate($createdstamp);
  93. $endstamp = strtotime($row['EndDate']);
  94. $enddate = getDate($endstamp);
  95.  
  96. $fullname = "";
  97. if($row['ShowMainTitle']) { $fullname .= $row['CTitle']." "; }
  98. if($row['ShowMainFirstName']) { $fullname .= $row['First']." ".$row['Last']; }
  99. $data[] = new Announcement($row['ID'], $row['Title'], $row['Category'],
  100. $row['Description'], $created, $enddate,
  101. $fullname, $row['ContactID'], $row['Email']);
  102. }
  103.  
  104. return $data;
  105. }
  106. //There must be an ID associated with all of the elements.
  107. function &GetFAQsByCategory(&$category) {
  108. $data = Array();
  109. $result = mysql_query("select F.ID, F.Title, F.Category, F.Text, F.Links
  110. from FAQ F
  111. where F.Category = '$category'
  112. order by F.ID asc");
  113. //Process each row.
  114. while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
  115. $data[] = new FAQ($row['ID'], $row['Title'], $row['Category'],
  116. $row['Text'], $row['Links']);
  117. }
  118.  
  119. return $data;
  120. }
  121. //There must be an ID associated with all of the elements.
  122. function &GetFAQCategories() {
  123. $data = Array();
  124. $result = mysql_query("select DISTINCT F.Category
  125. from FAQ F
  126. order by F.Category");
  127. //Process each row.
  128. while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
  129. $data[] = $row['Category'];
  130. }
  131.  
  132. return $data;
  133. }
  134. //There must be an ID associated with all of the elements.
  135. function &GetResourcesByCategory(&$category) {
  136. $data = Array();
  137. $result = mysql_query("select R.ID, R.Title, R.Description, R.Link, R.Category
  138. from Resource R
  139. where R.Category = '$category'
  140. AND R.ShowItem = 1
  141. order by R.Title");
  142. //Process each row.
  143. while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
  144. $data[] = new Resource($row['ID'], $row['Title'],
  145. $row['Description'], $row['Link'], $row['Category']);
  146. }
  147.  
  148. return $data;
  149. }
  150. //There must be an ID associated with all of the elements.
  151. function &GetResourceCategories() {
  152. $data = Array();
  153. $result = mysql_query("select DISTINCT R.Category
  154. from Resource R
  155. order by R.Category");
  156. //Process each row.
  157. while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
  158. $data[] = $row['Category'];
  159. }
  160.  
  161. return $data;
  162. }
  163. function &GetRandomBibleVerse()
  164. {
  165. $result = mysql_query("select Verse
  166. from BibleVerses
  167. order by rand()
  168. limit 1");
  169. $row = mysql_fetch_array($result, MYSQL_ASSOC);
  170. return $row['Verse'];
  171. }
  172. function &GetTodaysBibleVerse($seder=1)
  173. {
  174. $today = getdate(time());
  175. $thisday = $today['yday']+$seder;
  176. $result = mysql_query("select Verse
  177. from BibleVerses
  178. where ID = $thisday
  179. limit 1");
  180. $row = mysql_fetch_array($result, MYSQL_ASSOC);
  181. return $row['Verse'];
  182. }
  183. //There must be an ID associated with all of the elements.
  184. function &GetAllBibleTrivia($limit,$blimit,$order) {
  185. $data = Array();
  186. $query_string = "select BT.ID, BT.Title, BT.Question, BT.Showcase, BT.AnswerNum,
  187. BT.CorrectText, BT.IncorrectText, BT.Answer1, BT.Answer2,
  188. BT.Answer3, BT.Answer4, BT.Answer5, BT.Answer6
  189. from BibleTrivia BT
  190. where BT.ShowItem > 0
  191. order by $order
  192. limit $blimit,$limit";
  193. $result = mysql_query($query_string);
  194. //Process each row.
  195. while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
  196. $data[] = new BibleTrivia($row['ID'],$row['Title'],$row['Question'],$row['Showcase'],
  197. $row['AnswerNum'],$row['CorrectText'],$row['IncorrectText'],
  198. $row['Answer1'],$row['Answer2'],$row['Answer3'],$row['Answer4'],
  199. $row['Answer5'],$row['Answer6']);
  200. }
  201.  
  202. return $data;
  203. }
  204. //There must be an ID associated with all of the elements.
  205. function &GetAllBibleTriviaCount() {
  206. $result = mysql_query("select count(*)
  207. from BibleTrivia BT
  208. where BT.ShowItem > 0");
  209. $row = mysql_fetch_array($result, MYSQL_ASSOC);
  210. foreach($row as $item) { $data = $item; }
  211. return $data;
  212. }
  213. function &IncrementBibleTriviaAnsweredCount(&$id) {
  214. $result = mysql_query("update BibleTrivia set AnsweredCount=AnsweredCount+1
  215. where ID = $id");
  216. return $result;
  217. }
  218. //There must be an ID associated with all of the elements.
  219. function &GetBibleTrivia(&$id) {
  220. $result = mysql_query("select BT.ID, BT.Title, BT.Question, BT.Showcase, BT.AnswerNum,
  221. BT.CorrectText, BT.IncorrectText, BT.Answer1, BT.Answer2,
  222. BT.Answer3, BT.Answer4, BT.Answer5, BT.Answer6
  223. from BibleTrivia BT
  224. where BT.ID = $id
  225. limit 1");
  226. $row = mysql_fetch_array($result, MYSQL_ASSOC);
  227. $data = new BibleTrivia($row['ID'],$row['Title'],$row['Question'],$row['Showcase'],
  228. $row['AnswerNum'],$row['CorrectText'],$row['IncorrectText'],
  229. $row['Answer1'],$row['Answer2'],$row['Answer3'],$row['Answer4'],
  230. $row['Answer5'],$row['Answer6']);
  231.  
  232. return $data;
  233. }
  234. //There must be an ID associated with all of the elements.
  235. function &GetShowcaseBibleTrivia() {
  236. $result = mysql_query("select BT.ID, BT.Title, BT.Question, BT.Showcase, BT.AnswerNum,
  237. BT.CorrectText, BT.IncorrectText, BT.Answer1, BT.Answer2,
  238. BT.Answer3, BT.Answer4, BT.Answer5, BT.Answer6
  239. from BibleTrivia BT
  240. where BT.Showcase > 0
  241. AND BT.ShowItem > 0
  242. limit 1");
  243. $row = mysql_fetch_array($result, MYSQL_ASSOC);
  244. $data = new BibleTrivia($row['ID'],$row['Title'],$row['Question'],$row['Showcase'],
  245. $row['AnswerNum'],$row['CorrectText'],$row['IncorrectText'],
  246. $row['Answer1'],$row['Answer2'],$row['Answer3'],$row['Answer4'],
  247. $row['Answer5'],$row['Answer6']);
  248.  
  249. return $data;
  250. }
  251. //There must be an ID associated with all of the elements.
  252. function &GetAllDevotional($limit,$blimit,$order) {
  253. $data = Array();
  254. $result = mysql_query("select D.ID, D.Title, D.Text, D.KeyVerse, D.Verses, D.Showcase, D.Prayer,
  255. C.ID as CID, C.First, C.Last, C.Email, C.Title as CTitle,
  256. C.ShowMainTitle, C.ShowMainFirstName, C.ShowMainLastName
  257. from Devotional D, Contact C
  258. where D.AuthorID = C.ID
  259. AND D.ShowItem > 0
  260. order by $order
  261. limit $blimit,$limit");
  262. //Process each row.
  263. while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
  264. $name = "";
  265. if($row['ShowMainTitle']) { $name .= $row['CTitle']." "; }
  266. if($row['ShowMainFirstName']) { $name .= $row['First']." "; }
  267. if($row['ShowMainLastName']) { $name .= $row['Last']; }
  268. $data[] = new Devotional($row['ID'],$row['Title'],$row['Text'],$row['KeyVerse'],$row['Prayer'],
  269. $row['Verses'],$row['CID'],$name,$row['Email'],$row['Showcase']);
  270. }
  271.  
  272. return $data;
  273. }
  274. //There must be an ID associated with all of the elements.
  275. function &GetAllDevotionalCount() {
  276. $data = Array();
  277. $result = mysql_query("select count(*)
  278. from Devotional D
  279. where D.ShowItem > 0");
  280. $row = mysql_fetch_array($result, MYSQL_ASSOC);
  281. foreach($row as $item) { $data = $item; }
  282. return $data;
  283. }
  284. //There must be an ID associated with all of the elements.
  285. function &GetDevotional(&$id) {
  286. $result = mysql_query("select D.ID, D.Title, D.Text, D.KeyVerse, D.Verses, D.Showcase, D.Prayer,
  287. C.ID as CID, C.First, C.Last, C.Email, C.Title as CTitle,
  288. C.ShowMainTitle, C.ShowMainFirstName, C.ShowMainLastName
  289. from Devotional D, Contact C
  290. where D.AuthorID = C.ID
  291. AND D.ID = $id
  292. order by D.Title desc
  293. limit 1");
  294. $row = mysql_fetch_array($result, MYSQL_ASSOC);
  295. $name = "";
  296. if($row['ShowMainTitle']) { $name .= $row['CTitle']." "; }
  297. if($row['ShowMainFirstName']) { $name .= $row['First']." "; }
  298. if($row['ShowMainLastName']) { $name .= $row['Last']; }
  299. $data = new Devotional($row['ID'],$row['Title'],$row['Text'],$row['KeyVerse'],$row['Prayer'],
  300. $row['Verses'],$row['CID'],$name,$row['Email'],$row['Showcase']);
  301.  
  302. return $data;
  303. }
  304. //There must be an ID associated with all of the elements.
  305. function &GetShowcaseDevotional() {
  306. $result2 = mysql_query("select MAX(ID) from Devotional where Showcase > 0 AND ShowItem > 0");
  307. $row2 = mysql_fetch_array($result2, MYSQL_ASSOC);
  308. foreach($row2 as $idnum) { $id = $idnum; }
  309. if($id == null) {
  310. $result2 = mysql_query("select MAX(ID) from Devotional where ShowItem > 0");
  311. $row2 = mysql_fetch_array($result2, MYSQL_ASSOC);
  312. foreach($row2 as $idnum) { $id = $idnum; }
  313. }
  314. $result = mysql_query("select D.ID, D.Title, D.Text, D.KeyVerse, D.Verses, D.Showcase, D.Prayer,
  315. C.ID as CID, C.First, C.Last, C.Email, C.Title as CTitle,
  316. C.ShowMainTitle, C.ShowMainFirstName, C.ShowMainLastName
  317. from Devotional D, Contact C
  318. where D.AuthorID = C.ID AND D.ID = $id
  319. limit 1");
  320. $row = mysql_fetch_array($result, MYSQL_ASSOC);
  321. $name = "";
  322. if($row['ShowMainTitle']) { $name = $row['CTitle']." "; }
  323. if($row['ShowMainFirstName']) { $name .= $row['First']." "; }
  324. if($row['ShowMainLastName']) { $name .= $row['Last']; }
  325. $data = new Devotional($row['ID'],$row['Title'],$row['Text'],$row['KeyVerse'],$row['Prayer'],
  326. $row['Verses'],$row['CID'],$name,$row['Email'],$row['Showcase']);
  327.  
  328. return $data;
  329. }
  330. }
  331.  
  332.  
  333. /**
  334. * <b>Database Container Class : Announcement</b><br />
  335. * Contains all of the specific data for an announcement.
  336. * @author Kristen O'Brien <kristen_paristemi-com>
  337. * @copyright Copyright 2004, Kristen O'Brien
  338. * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  339. * @link http://www.paristemi.com Paristemi Main Site
  340. * @package paristemi
  341. * @subpackage paristemi_database_layer
  342. * @since Build 0.5
  343. * @version Build 0.7
  344. * @filesource
  345. */
  346. class Announcement {
  347. var $ID;
  348. var $Title;
  349. var $Category;
  350. var $Description;
  351. var $Created;
  352. var $EndDate;
  353. var $Name;
  354. var $CID;
  355. var $Email;
  356. function Announcement($id,$title,$cat,$desc,$created,$enddate,$name,$cid,$email) {
  357. $this->ID = $id;
  358. $this->Title = $title;
  359. $this->Category = $cat;
  360. $this->Description = $desc;
  361. $this->Created = $created;
  362. $this->EndDate = $enddate;
  363. $this->Name = $name;
  364. $this->CID = $cid;
  365. $this->Email = $email;
  366. }
  367. }
  368.  
  369. /**
  370. * <b>Database Container Class Resource</b><br />
  371. * Contains all of the specific data for a resource (link).
  372. * @author Kristen O'Brien <kristen_paristemi-com>
  373. * @copyright Copyright 2004, Kristen O'Brien
  374. * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  375. * @link http://www.paristemi.com Paristemi Main Site
  376. * @package paristemi
  377. * @subpackage paristemi_database_layer
  378. * @since Build 0.5
  379. * @version Build 0.7
  380. * @filesource
  381. */
  382. class Resource {
  383. var $ID;
  384. var $Title;
  385. var $Description;
  386. var $Link;
  387. var $Category;
  388. function Resource($id,$title,$desc,$link,$category) {
  389. $this->ID = $id;
  390. $this->Title = $title;
  391. $this->Description = $desc;
  392. $this->Link = $link;
  393. $this->Category = $category;
  394. }
  395. }
  396.  
  397. /**
  398. * <b>Database Container Class : FAQ</b><br />
  399. * Contains all of the specific data for a FAQ (Frequently Asked Question).
  400. * @author Kristen O'Brien <kristen_paristemi-com>
  401. * @copyright Copyright 2004, Kristen O'Brien
  402. * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  403. * @link http://www.paristemi.com Paristemi Main Site
  404. * @package paristemi
  405. * @subpackage paristemi_database_layer
  406. * @since Build 0.5
  407. * @version Build 0.7
  408. * @filesource
  409. */
  410. class FAQ {
  411. var $ID;
  412. var $Title;
  413. var $Category;
  414. var $Text;
  415. var $Links;
  416. function FAQ($id,$title,$category,$text,$links) {
  417. $this->ID = $id;
  418. $this->Title = $title;
  419. $this->Category = $category;
  420. $this->Text = $text;
  421. $this->Links = $links;
  422. }
  423. }
  424.  
  425. /**
  426. * <b>Database Container Class : Bible Trivia</b><br />
  427. * Contains all of the specific data for a bible trivia question.
  428. * @author Kristen O'Brien <kristen_paristemi-com>
  429. * @copyright Copyright 2004, Kristen O'Brien
  430. * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  431. * @link http://www.paristemi.com Paristemi Main Site
  432. * @package paristemi
  433. * @subpackage paristemi_database_layer
  434. * @since Build 0.5
  435. * @version Build 0.7
  436. * @filesource
  437. */
  438. class BibleTrivia {
  439. var $ID;
  440. var $Title;
  441. var $Question;
  442. var $Showcase;
  443. var $AnswerNum;
  444. var $CorrectText;
  445. var $IncorrectText;
  446. var $Answer1;
  447. var $Answer2;
  448. var $Answer3;
  449. var $Answer4;
  450. var $Answer5;
  451. var $Answer6;
  452. function BibleTrivia($id,$title,$question,$showcase,$answernum,$ctext,$ictext,
  453. $ans1,$ans2,$ans3,$ans4,$ans5,$ans6) {
  454. $this->ID = $id;
  455. $this->Title = $title;
  456. $this->Question = $question;
  457. $this->Showcase = $showcase;
  458. $this->AnswerNum = $answernum;
  459. $this->CorrectText = $ctext;
  460. $this->IncorrectText = $ictext;
  461. $this->Answer1 = $ans1;
  462. $this->Answer2 = $ans2;
  463. $this->Answer3 = $ans3;
  464. $this->Answer4 = $ans4;
  465. $this->Answer5 = $ans5;
  466. $this->Answer6 = $ans6;
  467. }
  468. }
  469.  
  470. /**
  471. * <b>Database Container Class : Devotional</b><br />
  472. * Contains all of the specific data for a devotional.
  473. * @author Kristen O'Brien <kristen_paristemi-com>
  474. * @copyright Copyright 2004, Kristen O'Brien
  475. * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  476. * @link http://www.paristemi.com Paristemi Main Site
  477. * @package paristemi
  478. * @subpackage paristemi_database_layer
  479. * @since Build 0.5
  480. * @version Build 0.7
  481. * @filesource
  482. */
  483. class Devotional {
  484. var $ID;
  485. var $Title;
  486. var $Text;
  487. var $KeyVerse;
  488. var $Prayer;
  489. var $Verses;
  490. var $AuthorID;
  491. var $AuthorName;
  492. var $AuthorEmail;
  493. var $Showcase;
  494. function Devotional($id,$title,$text,$keyverse,$prayer,
  495. $verses,$aid,$aname,$aemail,$showcase) {
  496. $this->ID = $id;
  497. $this->Title = $title;
  498. $this->Text = $text;
  499. $this->KeyVerse = $keyverse;
  500. $this->Prayer = $prayer;
  501. $this->Verses = $verses;
  502. $this->AuthorID = $aid;
  503. $this->AuthorName = $aname;
  504. $this->AuthorEmail = $aemail;
  505. $this->Showcase = $showcase;
  506. }
  507. }
  508.  
  509. ?>

Documentation generated on Mon, 10 May 2004 12:08:56 -0700 by phpDocumentor 1.3.0RC3