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

Source for file db_prayer.php

Documentation is available at db_prayer.php

  1. <?php
  2. /**
  3. * <b>Database Class : Prayer</b><br />
  4. * Provides all database access/modification methods for the prayer section.
  5. * @author Kristen O'Brien <kristen_paristemi-com>
  6. * @copyright Copyright 2004, Kristen O'Brien
  7. * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  8. * @link http://www.paristemi.com Paristemi Main Site
  9. * @package paristemi
  10. * @subpackage paristemi_database_layer
  11. * @since Build 0.5
  12. * @version Build 0.7
  13. * @filesource
  14. */
  15. /**
  16. * <b>Database Class : Prayer</b><br />
  17. * Provides all database access/modification methods for the prayer section.
  18. * @author Kristen O'Brien <kristen_paristemi-com>
  19. * @copyright Copyright 2004, Kristen O'Brien
  20. * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  21. * @link http://www.paristemi.com Paristemi Main Site
  22. * @package paristemi
  23. * @subpackage paristemi_database_layer
  24. * @since Build 0.5
  25. * @version Build 0.7
  26. * @filesource
  27. */
  28. class DB_Prayer {
  29. function DB_Prayer() { }
  30. // Get contact info
  31. function &GetPrayerData(&$id) {
  32. $result = mysql_query("select P.ID, P.Title, P.Description,
  33. P.PersonName, P.PersonEmail, P.PrayerContact,
  34. P.Private, P.DateEntered, P.DateNeeded,
  35. P.DateDelete, P.Approved, P.RandomKey,
  36. CG.Name as ContactName, CG.Contacts
  37. from ContactGroup CG, Prayer P
  38. where CG.ID = P.PrayerContact
  39. AND P.ID = $id
  40. limit 1");
  41.  
  42. $row = mysql_fetch_array($result, MYSQL_ASSOC);
  43. $dateentered = getdate(strtotime($row['DateEntered']));
  44. $dateneeded = getdate(strtotime($row['DateNeeded']));
  45. $datedelete = getdate(strtotime($row['DateDelete']));
  46. $data = new PrayerData($row['ID'], $row['Title'], $row['Description'],
  47. $row['PersonName'], $row['PersonEmail'], $row['PrayerContact'],
  48. $row['Private'], $dateentered, $dateneeded,
  49. $datedelete, $row['Approved'], $row['ContactName'],
  50. $row['Contacts'], $row['RandomKey']);
  51.  
  52. return $data;
  53. }
  54. function &GetLatestPrayerID() {
  55. $result = mysql_query("SELECT max(id) FROM Prayer;")
  56. or $this->Error('Nothing found?');
  57. $row = mysql_fetch_array($result, MYSQL_ASSOC);
  58. return $row['max(id)'];
  59. }
  60. function &GetPrayers() {
  61. $data = Array();
  62. $result = mysql_query("select P.ID, P.Title, P.Description,
  63. P.PersonName, P.PersonEmail, P.PrayerContact,
  64. P.Private, P.DateEntered, P.DateNeeded,
  65. P.DateDelete, P.Approved, P.Key,
  66. CG.Name as ContactName, CG.Contacts
  67. from ContactGroup CG, Prayer P
  68. where CG.ID = P.PrayerContact
  69. order by P.DateEntered");
  70.  
  71. //Process each row.
  72. while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
  73. $dateentered = getdate(strtotime($row['DateEntered']));
  74. $dateneeded = getdate(strtotime($row['DateNeeded']));
  75. $datedelete = getdate(strtotime($row['DateDelete']));
  76. $data[] = new PrayerData($row['ID'], $row['Title'], $row['Description'],
  77. $row['PersonName'], $row['PersonEmail'], $row['PrayerContact'],
  78. $row['Private'], $dateentered, $dateneeded,
  79. $datedelte, $row['Approved'], $row['ContactName'],
  80. $row['Contacts'], $row['Key']);
  81. }
  82.  
  83. return $data;
  84. }
  85. function &GetCurrentPublicPrayers() {
  86. $data = Array();
  87. $result = mysql_query("select P.ID, P.Title, P.Description,
  88. P.PersonName, P.PersonEmail, P.PrayerContact,
  89. P.Private, P.DateEntered, P.DateNeeded,
  90. P.DateDelete, P.Approved, P.RandomKey,
  91. CG.Name as ContactName, CG.Contacts
  92. from ContactGroup CG, Prayer P
  93. where CG.ID = P.PrayerContact
  94. AND (P.Approved > 0)
  95. AND (P.DateDelete > NOW())
  96. AND (P.Private = 0)
  97. order by P.DateEntered DESC");
  98.  
  99. //Process each row.
  100. while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
  101. $dateentered = getdate(strtotime($row['DateEntered']));
  102. $dateneeded = getdate(strtotime($row['DateNeeded']));
  103. $datedelete = getdate(strtotime($row['DateDelete']));
  104. $data[] = new PrayerData($row['ID'], $row['Title'], $row['Description'],
  105. $row['PersonName'], $row['PersonEmail'], $row['PrayerContact'],
  106. $row['Private'], $dateentered, $dateneeded,
  107. $datedelete, $row['Approved'], $row['ContactName'],
  108. $row['Contacts'],$row['RandomKey']);
  109. }
  110.  
  111. return $data;
  112. }
  113. function &AddPrayer(&$title, &$desc, &$personname, &$personemail,
  114. &$prayercontact, &$private, &$dateentered, &$dateneeded,
  115. &$datedelete,&$key)
  116. {
  117. $result = mysql_query("insert into Prayer
  118. (Title, Description, PersonName, PersonEmail,
  119. PrayerContact, Private, DateEntered,
  120. DateNeeded, DateDelete, Approved, RandomKey)
  121. values ('$title', '$desc', '$personname', '$personemail',
  122. $prayercontact, $private, '$dateentered',
  123. '$dateneeded', '$datedelete',0,$key);");
  124. return ($result);
  125. }
  126. function &ApprovePrayer(&$id,&$key)
  127. {
  128. $result = mysql_query("update Prayer
  129. set Approved = 1
  130. where ID = $id AND RandomKey = $key;");
  131. return ($result);
  132. }
  133. function &UpdatePrayer(&$id, &$title, &$desc, &$personname, &$personemail,
  134. &$prayercontact, &$private, &$dateentered, &$dateneeded,
  135. &$datedelete,&$key,&$approve)
  136. {
  137. $result = mysql_query("update Prayer
  138. set Title = '$title',
  139. Description = '$desc',
  140. PersonName = '$personname',
  141. PersonEmail = '$personemail',
  142. PrayerContact = '$prayercontact',
  143. Private = $private,
  144. DateEntered = '$dateentered',
  145. DateNeeded = '$dateneeded',
  146. DateDelete = '$datedelete',
  147. Approved = $approve
  148. where ID = $id AND RandomKey = $key;");
  149. return ($result);
  150. }
  151. function &DeletePrayer(&$id)
  152. {
  153. $result = mysql_query("delete from Prayer
  154. where ID = $id
  155. limit 1;");
  156. return ($result);
  157. }
  158.  
  159. }
  160.  
  161.  
  162. /**
  163. * <b>Database Container Class : Prayer</b><br />
  164. * Contains all of the specific data for a prayer request.
  165. * @author Kristen O'Brien <kristen_paristemi-com>
  166. * @copyright Copyright 2004, Kristen O'Brien
  167. * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  168. * @link http://www.paristemi.com Paristemi Main Site
  169. * @package paristemi
  170. * @subpackage paristemi_database_layer
  171. * @since Build 0.5
  172. * @version Build 0.7
  173. * @filesource
  174. */
  175. class PrayerData {
  176. var $ID;
  177. var $Title;
  178. var $Description;
  179. var $PersonName;
  180. var $PersonEmail;
  181. var $PrayerContact;
  182. var $Private;
  183. var $DateEntered;
  184. var $DateNeeded;
  185. var $DateDelete;
  186. var $Approved;
  187. var $ContactName;
  188. var $Contacts;
  189. var $Key;
  190.  
  191. function PrayerData($id, $title, $desc, $personname, $personemail,
  192. $prayercontact, $private, $dateentered, $dateneeded,
  193. $datedelete, $approved, $contactname, $contacts, $key) {
  194. $this->ID = $id;
  195. $this->Title = $title;
  196. $this->Description = $desc;
  197. $this->PersonName = $personname;
  198. $this->PersonEmail = $personemail;
  199. $this->PrayerContact = $prayercontact;
  200. $this->Private = $private;
  201. $this->DateEntered = $dateentered;
  202. $this->DateNeeded = $dateneeded;
  203. $this->DateDelete = $datedelete;
  204. $this->Approved = $approved;
  205. $this->ContactName = $contactname;
  206. $this->Contacts = $contacts;
  207. $this->Key = $key;
  208. }
  209. }
  210. ?>

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