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

Source for file db_messages.php

Documentation is available at db_messages.php

  1. <?php
  2. /**
  3. * <b>Database Class : Messages</b><br />
  4. * Provides all database access methods for the audio messages 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 : Messages</b><br />
  17. * Provides all database access methods for the audio messages 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_Messages {
  29. var $grouping = array();
  30. var $bible_list = array();
  31. function DB_Messages() { }
  32. function setGrouping($group) { $this->grouping = $group; }
  33. function setBibleList($blist) { $this->bible_list = $blist; }
  34. function &GetBooksUsed() {
  35. $books = Array();
  36. $ordered_books = Array();
  37. $result = mysql_query("SELECT DISTINCT BookReference FROM Audio
  38. WHERE Category = 'Audio Message' AND BookReference != 'No Reference'");
  39. while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
  40. $books[] = $row['BookReference'];
  41. }
  42. $found_book = false;
  43. foreach($this->bible_list as $bible_book) {
  44. foreach($books as $book) {
  45. if($book == $bible_book && !$found_book) {
  46. $ordered_books[] = $book;
  47. $found_book = true;
  48. }
  49. }
  50. $found_book = false;
  51. }
  52. return $ordered_books;
  53. }
  54. function &GetTopicsUsed() {
  55. $topics = Array();
  56. $result = mysql_query("SELECT DISTINCT Topic FROM Audio
  57. WHERE Category = 'Audio Message' AND Topic != 'No Topic'");
  58. while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
  59. $tok = strtok($row['Topic'],",");
  60. while ($tok) {
  61. $topics[] = trim($tok);
  62. $tok = strtok(",");
  63. }
  64. }
  65. $unique_topics = array_values(array_unique($topics));
  66. sort($unique_topics);
  67. return $unique_topics;
  68. }
  69. function &GroupFunct($item) {
  70. $flag = 0;
  71. foreach($this->grouping as $letter) {
  72. if($item{0} == $letter) { $flag = 1; }
  73. }
  74. return $flag;
  75. }
  76. function &GetTopicsUsedByGroup($group) {
  77. $this->grouping = $group;
  78. $topics = Array();
  79. $result = mysql_query("SELECT DISTINCT Topic FROM Audio
  80. WHERE Category = 'Audio Message' AND Topic != 'No Topic'");
  81. while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
  82. $tok = strtok($row['Topic'],",");
  83. while ($tok) {
  84. $topics[] = trim($tok);
  85. $tok = strtok(",");
  86. }
  87. }
  88. $unique_topics = array_values(array_unique($topics));
  89. $new_arr = array_filter($unique_topics,array($this,"GroupFunct"));
  90. sort($new_arr);
  91. return $new_arr;
  92. }
  93. function &GetMonthsUsedByYear($year) {
  94. $result = mysql_query("select DISTINCT EXTRACT(YEAR_MONTH FROM I.Start) as yearmon,
  95. YEAR(I.Start) as startyear, MONTHNAME(I.Start) as startmon
  96. from Instance I, Audio A
  97. where I.AudioID = A.ID and I.AudioID != 1 and A.Category = 'Audio Message'
  98. and YEAR(I.Start) = $year
  99. order by yearmon asc");
  100. $data = array();
  101. while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
  102. $data[] = $row['startmon']." ".$row['startyear'];
  103. }
  104. return $data;
  105. }
  106. function &GetYearsUsed() {
  107. $result = mysql_query("select DISTINCT YEAR(I.Start) as startyear
  108. from Instance I, Audio A
  109. where I.AudioID = A.ID and I.AudioID != 1 and A.Category = 'Audio Message'
  110. order by startyear desc");
  111. $data = array();
  112. while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
  113. $data[] = $row['startyear'];
  114. }
  115. return $data;
  116. }
  117. function &GetMonthsUsed() {
  118. $result = mysql_query("select DISTINCT EXTRACT(YEAR_MONTH FROM I.Start) as yearmon,
  119. YEAR(I.Start) as startyear, MONTHNAME(I.Start) as startmon
  120. from Instance I, Audio A
  121. where I.AudioID = A.ID and I.AudioID != 1 and A.Category = 'Audio Message'
  122. order by yearmon desc");
  123. $data = array();
  124. while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
  125. $data[] = $row['startyear']." ".$row['startmon'];
  126. }
  127. return $data;
  128. }
  129. //Pass it the ID.
  130. //There must be an ID associated with all of the elements.
  131. function &GetAudioData(&$id) {
  132. $result = mysql_query("select I.ID as IID, I.Title as ITitle, I.Start as IStart, I.Stop as IStop,
  133. C.ID as CID, C.First as CFirst, C.Last as CLast,
  134. C.Title as CTitle, C.ShowMainTitle, C.ShowMainFirstName,C.ShowMainLastName,
  135. C.ShowEmail as CShowEmail, L.ID AS LID, L.Name AS LName,
  136. A.ID, A.Title, A.LinkStream, A.Description, A.BookReference,
  137. A.StartVerse, A.StopVerse, A.Topic, A.LinkDownload,
  138. A.PPTLink, A.PDFLink
  139. from Instance I, Contact C, Location L, Audio A
  140. where A.ID = $id and I.AudioID = $id
  141. and C.ID = I.ContactID and L.ID = I.LocationID
  142. and A.Category = 'Audio Message'
  143. order by I.Start
  144. limit 1");
  145.  
  146. $row = mysql_fetch_array($result, MYSQL_ASSOC);
  147.  
  148. $startstamp = strtotime($row['IStart']);
  149. $stopstamp = strtotime($row['IStop']);
  150. $start = getDate($startstamp);
  151. $stop = getDate($stopstamp);
  152.  
  153. $fullname = "";
  154. if($row['ShowMainTitle']) { $fullname = $row['CTitle']." "; }
  155. if($row['ShowMainFirstName']) { $fullname .= $row['CFirst']." "; }
  156. if($row['ShowMainLastName']) { $fullname .= $row['CLast']; }
  157. $data = new AudioDataDetailed($row['IID'], $row['ITitle'],
  158. $start, $stop, $row['CID'], $row['CShowEmail'], $fullname,
  159. $row['ID'], $row['Title'], $row['LinkStream'], $row['LinkDownload'],
  160. $row['BookReference'],$row['StartVerse'],$row['StopVerse'],
  161. $row['Topic'],$row['LID'], $row['LName'], $row['Description'],
  162. $row['PPTLink'],$row['PDFLink']);
  163. return $data;
  164. }
  165. //There must be an ID associated with all of the elements.
  166. function &GetAllMessages($order="A.ID") {
  167. $data = Array();
  168. $result = mysql_query("select I.ID as IID, I.Start as IStart, I.Stop as IStop,
  169. A.ID, A.Title, A.LinkStream, A.LinkDownload,A.Description,
  170. A.BookReference, A.StartVerse, A.StopVerse, A.Topic,
  171. A.PPTLink, A.PDFLink
  172. from Instance I, Audio A
  173. where I.AudioID = A.ID and I.AudioID != 1 and A.Category = 'Audio Message'
  174. order by $order desc");
  175.  
  176. //Process each row.
  177. while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
  178.  
  179. $startstamp = strtotime($row['IStart']);
  180. $stopstamp = strtotime($row['IStop']);
  181. $start = getDate($startstamp);
  182. $stop = getDate($stopstamp);
  183.  
  184. $data[] = new MessageData($row['IID'], $row['ID'], $start, $stop, $row['Title'], $row['Description'],
  185. $row['LinkStream'],$row['LinkDownload'],
  186. $row['BookReference'],$row['StartVerse'], $row['StopVerse'], $row['Topic'],
  187. $row['PPTLink'],$row['PDFLink']);
  188. }
  189.  
  190. return $data;
  191. }
  192. //There must be an ID associated with all of the elements.
  193. function &GetAllMessagesByLimit($limit,$blimit) {
  194. $data = Array();
  195. $result = mysql_query("select I.ID as IID, I.Start as IStart, I.Stop as IStop,
  196. A.ID, A.Title, A.LinkStream, A.LinkDownload,A.Description,
  197. A.BookReference, A.StartVerse, A.StopVerse, A.Topic,
  198. A.PPTLink, A.PDFLink
  199. from Instance I, Audio A
  200. where I.AudioID = A.ID and I.AudioID != 1 and A.Category = 'Audio Message'
  201. order by A.Title asc
  202. limit $blimit,$limit");
  203.  
  204. //Process each row.
  205. while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
  206.  
  207. $startstamp = strtotime($row['IStart']);
  208. $stopstamp = strtotime($row['IStop']);
  209. $start = getDate($startstamp);
  210. $stop = getDate($stopstamp);
  211.  
  212. $data[] = new MessageData($row['IID'], $row['ID'], $start, $stop, $row['Title'],
  213. $row['Description'],$row['LinkStream'],$row['LinkDownload'],
  214. $row['BookReference'],$row['StartVerse'], $row['StopVerse'], $row['Topic'],
  215. $row['PPTLink'],$row['PDFLink']);
  216. }
  217.  
  218. return $data;
  219. }
  220. //There must be an ID associated with all of the elements.
  221. function &SearchMessagesType(&$item,$atype,$limit,$blimit) {
  222. $data = Array();
  223.  
  224. $query_string = "select DISTINCTROW I.ID as IID, A.ID, A.Title,
  225. A.Description, A.LinkStream, A.LinkDownload, A.Category, A.Topic,
  226. A.BookReference, A.StartVerse, A.StopVerse,
  227. A.PPTLink, A.PDFLink
  228. from Instance I, Audio A
  229. where I.AudioID = A.ID AND
  230. I.AudioID != 1 AND (";
  231.  
  232. foreach($atype as $type) {
  233. if($type == "topic") {
  234. $query_string = $query_string . "A.Topic LIKE '%$item%' OR ";
  235. }
  236. else if($type == "description") {
  237. $query_string = $query_string . "A.Description LIKE '%$item%' OR ";
  238. }
  239. else if($type == "title") {
  240. $query_string = $query_string . "A.Title LIKE '%$item%' OR ";
  241. }
  242. else { die("Invalid Parameters"); }
  243. }
  244. if(count($atype) == 0) { die("Invalid Parameters"); }
  245. $query_string = substr($query_string,0,strlen($query_string)-4);
  246. $query_string = $query_string . ") AND A.Category = 'Audio Message'
  247. order by A.Title
  248. limit $blimit,$limit";
  249. $result = mysql_query($query_string);
  250.  
  251. //Process each row.
  252. while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
  253. $data[] = new MessageData($row['IID'], $row['ID'], "", "", $row['Title'],
  254. $row['Description'],$row['LinkStream'], $row['LinkDownload'],
  255. $row['BookReference'],$row['StartVerse'], $row['StopVerse'], $row['Topic'],
  256. $row['PPTLink'],$row['PDFLink']);
  257. }
  258.  
  259. return $data;
  260. }
  261. //There must be an ID associated with all of the elements.
  262. function &SearchMessagesCount(&$item,$atype) {
  263. $query_string = "SELECT DISTINCTROW COUNT(*)
  264. from Audio A
  265. where (";
  266. foreach($atype as $type) {
  267. if($type == "topic") {
  268. $query_string = $query_string . "A.Topic LIKE '%$item%' OR ";
  269. }
  270. else if($type == "description") {
  271. $query_string = $query_string . "A.Description LIKE '%$item%' OR ";
  272. }
  273. else if($type == "title") {
  274. $query_string = $query_string . "A.Title LIKE '%$item%' OR ";
  275. }
  276. else { $this->Error("Invalid Parameters"); }
  277. }
  278. $query_string = substr($query_string,0,strlen($query_string)-4);
  279. $query_string = $query_string . ") AND A.Category = 'Audio Message'";
  280. $result = mysql_query($query_string);
  281. $row = mysql_fetch_array($result, MYSQL_ASSOC);
  282. foreach($row as $item) { $count = $item; }
  283. return $count;
  284. }
  285.  
  286. //There must be an ID associated with all of the elements.
  287. function &GetAllAudio() {
  288. $data = Array();
  289. $result = mysql_query("select A.ID, A.Title, A.LinkStream, A.LinkDownload,
  290. A.BookReference, A.StartVerse, A.StopVerse, A.Topic,
  291. A.PPTLink, A.PDFLink
  292. from Audio A
  293. order by A.ID desc");
  294.  
  295. //Process each row.
  296. while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
  297. $data[] = new MessageData("", $row['ID'], "", "", $row['Title'],
  298. $row['Description'],$row['LinkStream'], $row['LinkDownload'],
  299. $row['BookReference'],$row['StartVerse'], $row['StopVerse'], $row['Topic'],
  300. $row['PPTLink'],$row['PDFLink']);
  301. }
  302.  
  303. return $data;
  304. }
  305. //There must be an ID associated with all of the elements.
  306. function &GetMessagesRange($first,$last) {
  307. $data = Array();
  308. $result = mysql_query("select I.ID as IID, I.Start as IStart, I.Stop as IStop, A.Description,
  309. A.ID, A.Title, A.LinkStream, A.LinkDownload, A.PPTLink, A.PDFLink,
  310. A.BookReference, A.StartVerse, A.StopVerse, A.Topic
  311. from Instance I, Audio A
  312. where I.AudioID = A.ID and I.AudioID != 1 and A.Category = 'Audio Message'
  313. order by A.ID desc
  314. limit $first,$last");
  315.  
  316. //Process each row.
  317. while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
  318.  
  319. $startstamp = strtotime($row['IStart']);
  320. $stopstamp = strtotime($row['IStop']);
  321. $start = getDate($startstamp);
  322. $stop = getDate($stopstamp);
  323.  
  324. $data[] = new MessageData($row['IID'], $row['ID'], $start, $stop, $row['Title'],
  325. $row['Description'],$row['LinkStream'], $row['LinkDownload'],
  326. $row['BookReference'],$row['StartVerse'], $row['StopVerse'], $row['Topic'],
  327. $row['PPTLink'],$row['PDFLink']);
  328. }
  329.  
  330. return $data;
  331. }
  332. //Pass it the Item & Type.
  333. //There must be an ID associated with all of the elements.
  334. function &GetAudioDataType(&$item, $type) {
  335. $item = addslashes($item);
  336. $data = Array();
  337. $query_string = "select I.ID as IID, I.Title as ITitle, I.Start as IStart, I.Stop as IStop,
  338. C.ID as CID, C.First as CFirst, C.Last as CLast, C.Title as CTitle,
  339. C.ShowMainTitle, C.ShowMainFirstName, C.ShowMainLastName,
  340. C.ShowEmail as CShowEmail, L.ID AS LID, L.Name AS LName,
  341. A.ID, A.Title, A.LinkStream as ALinkStream, A.Description as ADesc,
  342. A.BookReference, A.StartVerse, A.StopVerse, A.Topic, A.LinkDownload,
  343. A.PPTLink, A.PDFLink
  344. from Instance I, Series S, Contact C, Location L, Audio A ";
  345. if($type == "book") {
  346. $query_string = $query_string . "where A.BookReference LIKE '%$item%' ";
  347. }
  348. else if($type == "topic") {
  349. $query_string = $query_string . "where A.Topic LIKE '%$item%' ";
  350. }
  351. else if($type == "date") {
  352. $dateinfo = explode(" ",$item); $year = $dateinfo[0]; $mon = $dateinfo[1];
  353. $query_string = $query_string . "where YEAR(I.Start) = $year AND MONTHNAME(I.Start) = '$mon' ";
  354. }
  355. else { $this->Error('Invalid Parameters'); }
  356. $query_string = $query_string . "and S.ID = I.SeriesID and C.ID = I.ContactID and
  357. L.ID = I.LocationID and A.ID = I.AudioID
  358. and A.Category = 'Audio Message'
  359. and A.Title != 'No Audio Message'
  360. order by I.Start desc";
  361. $result = mysql_query($query_string);
  362.  
  363. //Process each row.
  364. while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
  365.  
  366. $startstamp = strtotime($row['IStart']);
  367. $stopstamp = strtotime($row['IStop']);
  368. $start = getDate($startstamp);
  369. $stop = getDate($stopstamp);
  370.  
  371. $fullname = "";
  372. if($row['ShowMainTitle']) { $fullname = $row['CTitle']." "; }
  373. if($row['ShowMainFirstName']) { $fullname .= $row['CFirst']." "; }
  374. if($row['ShowMainLastName']) { $fullname .= $row['CLast']; }
  375. $data[] = new AudioDataDetailed($row['IID'], $row['ITitle'],
  376. $start, $stop, $row['CID'], $row['CShowEmail'], $fullname,
  377. $row['ID'], $row['Title'], $row['ALinkStream'], $row['LinkDownload'],
  378. $row['BookReference'], $row['StartVerse'], $row['StopVerse'],
  379. $row['Topic'],$row['LID'], $row['LName'], $row['ADesc'],
  380. $row['PPTLink'],$row['PDFLink']);
  381. }
  382.  
  383. return $data;
  384. }
  385. }
  386.  
  387.  
  388. /**
  389. * <b>Database Container Class : Audio Detailed</b><br />
  390. * Contains all of the specific data for an audio message.
  391. * @author Kristen O'Brien <kristen_paristemi-com>
  392. * @copyright Copyright 2004, Kristen O'Brien
  393. * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  394. * @link http://www.paristemi.com Paristemi Main Site
  395. * @package paristemi
  396. * @subpackage paristemi_database_layer
  397. * @since Build 0.5
  398. * @version Build 0.7
  399. * @filesource
  400. */
  401. class AudioDataDetailed {
  402. var $IID;
  403. var $ITitle;
  404. var $Start;
  405. var $Stop;
  406. var $CID;
  407. var $CShowEmail;
  408. var $CName;
  409. var $ID;
  410. var $Title;
  411. var $ALinkStream;
  412. var $ALinkDownload;
  413. var $PPTLink;
  414. var $PDFLink;
  415. var $BookReference;
  416. var $StartVerse;
  417. var $StopVerse;
  418. var $Topic;
  419. var $LID;
  420. var $LName;
  421. var $Description;
  422. function AudioDataDetailed($iid, $ititle, $start, $stop, $cid, $cshowemail, $cname,
  423. $id, $title, $link, $linkdl, $_bookreference, $_startverse,
  424. $_stopverse, $_topic, $lid, $lname, $desc,$pptlink,$pdflink) {
  425. $this->IID = $iid;
  426. $this->ITitle = $ititle;
  427. $this->Start = $start;
  428. $this->Stop = $stop;
  429. $this->CID = $cid;
  430. $this->CShowEmail = $cshowemail;
  431. $this->CName = $cname;
  432. $this->ID = $id;
  433. $this->Title = $title;
  434. $this->ALinkStream = $link;
  435. $this->ALinkDownload = $linkdl;
  436. $this->BookReference = $_bookreference;
  437. $this->StartVerse = $_startverse;
  438. $this->StopVerse = $_stopverse;
  439. $this->Topic = $_topic;
  440. $this->LID = $lid;
  441. $this->LName = $lname;
  442. $this->Description = $desc;
  443. $this->PPTLink = $pptlink;
  444. $this->PDFLink = $pdflink;
  445. }
  446. }
  447.  
  448. /**
  449. * <b>Database Container Class : Message</b><br />
  450. * Contains all of the important data for an audio message.
  451. * @author Kristen O'Brien <kristen_paristemi-com>
  452. * @copyright Copyright 2004, Kristen O'Brien
  453. * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  454. * @link http://www.paristemi.com Paristemi Main Site
  455. * @package paristemi
  456. * @subpackage paristemi_database_layer
  457. * @since Build 0.5
  458. * @version Build 0.7
  459. * @filesource
  460. */
  461. class MessageData {
  462. var $IID;
  463. var $ID;
  464. var $Start;
  465. var $Stop;
  466. var $Title;
  467. var $Description;
  468. var $ALinkStream;
  469. var $ALinkDownload;
  470. var $PPTLink;
  471. var $PDFLink;
  472. var $BookReference;
  473. var $StartVerse;
  474. var $StopVerse;
  475. var $Topic;
  476. function MessageData($iid, $id, $start, $stop, $title, $desc, $alink, $alinkdl, $bookreference,
  477. $startverse, $stopverse, $topic,$pptlink,$pdflink) {
  478. $this->IID = $iid;
  479. $this->ID = $id;
  480. $this->Start = $start;
  481. $this->Stop = $stop;
  482. $this->Title = $title;
  483. $this->Description = $desc;
  484. $this->ALinkStream = $alink;
  485. $this->ALinkDownload = $alinkdl;
  486. $this->BookReference = $bookreference;
  487. $this->StartVerse = $startverse;
  488. $this->StopVerse = $stopverse;
  489. $this->Topic = $topic;
  490. $this->PPTLink = $pptlink;
  491. $this->PDFLink = $pdflink;
  492. }
  493. }
  494.  
  495. ?>

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