PageRenderTime 45ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/PO/rss.php

https://github.com/tlezotte/ePOS
PHP | 220 lines | 136 code | 31 blank | 53 comment | 6 complexity | accc8df822e7c61df46b9266766b0fbc MD5 | raw file
  1. <?php
  2. /**
  3. * Request System
  4. *
  5. * rss.php generates RSS feed.
  6. *
  7. * @version 1.5
  8. * @link http://www.yourdomain.com/go/Request/
  9. * @author Thomas LeZotte (tom@lezotte.net)
  10. *
  11. * @package PO
  12. * @filesource
  13. *
  14. * PHP Debug
  15. * @link http://phpdebug.sourceforge.net/
  16. */
  17. /**
  18. * - Set debug mode
  19. */
  20. $debug_page = false;
  21. include_once('debug/header.php');
  22. /**
  23. * - Database Connection
  24. */
  25. require_once('../Connections/connDB.php');
  26. /**
  27. * - Config Information
  28. */
  29. require_once('../include/config.php');
  30. $rss_type = 'PO'; //Type of RSS feed
  31. switch ($rss_type) {
  32. case 'CER':
  33. $DATABASE = 'CER';
  34. $LABEL = 'Capital Acquisitions';
  35. break;
  36. case 'PO':
  37. $DATABASE = 'PO';
  38. $LABEL = 'Purchase Requests';
  39. break;
  40. }
  41. /* ------------------ START DATABASE CONNECTIONS ----------------------- */
  42. $rss_items = $default['rss_items'] / 2;
  43. /* Getting Submitted PO information */
  44. $submitted_query = <<< SQL
  45. SELECT id, purpose, reqDate, req, company
  46. FROM $DATABASE
  47. ORDER BY reqDate DESC
  48. LIMIT $rss_items
  49. SQL;
  50. $submitted_sql = $dbh->prepare($submitted_query);
  51. /* Getting Approved PO information */
  52. $approved_query = <<< SQL
  53. SELECT p.id, p.purpose, p.req, p.company, a.issuer, a.issuerDate
  54. FROM $DATABASE p, Authorization a
  55. WHERE p.id = a.type_id AND a.type = '$DATABASE' AND a.issuerDate IS NOT NULL
  56. ORDER BY a.issuerDate DESC
  57. LIMIT $rss_items
  58. SQL;
  59. $approved_sql = $dbh->prepare($approved_query);
  60. /* Getting Denied PO information */
  61. $denied_query = <<< SQL
  62. SELECT p.id, p.purpose, p.req, p.company, a.app1Date
  63. FROM $DATABASE p, Authorization a
  64. WHERE p.id = a.type_id AND a.type = '$DATABASE' AND (a.app1yn = 'no' OR a.app2yn = 'no')
  65. ORDER BY a.app1Date DESC
  66. LIMIT $rss_items
  67. SQL;
  68. $denied_sql = $dbh->prepare($denied_query);
  69. /* Get Employee names from Standards database */
  70. $EMPLOYEES = $dbh->getAssoc("SELECT e.eid, CONCAT(e.fst,' ',e.lst) AS name ".
  71. "FROM Users u, Standards.Employees e ".
  72. "WHERE e.eid = u.eid");
  73. /* Get Companies names from Standards database */
  74. $COMPANY = $dbh->getAssoc("SELECT id, name FROM Standards.Companies WHERE id > 0");
  75. /* ------------------ END DATABASE CONNECTIONS ----------------------- */
  76. /* ------------------ START VARIABLES ----------------------- */
  77. /* Generate at RFC 2822 formatted date */
  78. $pubDate = date("r");
  79. $filename = $default['rss_file'];
  80. /* ------------------ END VARIABLES ----------------------- */
  81. /* ------------------------------------------ CREATE RSS 2.0 FILE ----------------------------------------- */
  82. //header('Content-Type: text/xml');
  83. $rss = "<?xml version=\"1.0\"?>\n";
  84. $rss .= "<rss version=\"2.0\">\n";
  85. $rss .= " <channel>\n";
  86. $rss .= " <title>$LABEL</title>\n";
  87. $rss .= " <link>".$default['URL_HOME']."/index.php</link>\n";
  88. $rss .= " <description>List of $LABEL transactions using the $default[title1]</description>\n";
  89. $rss .= " <pubDate>$pubDate</pubDate>\n";
  90. $rss .= " <copyright>2004 Your Company</copyright>\n";
  91. $rss .= " <webMaster>webmaster@".$default['email_domain']."</webMaster>\n";
  92. $rss .= " <category>$default[title1]</category>\n";
  93. $rss .= " <image>\n";
  94. $rss .= " <title>Your Company</title>\n";
  95. $rss .= " <url>$default[rss_image]</url>\n";
  96. $rss .= " <width>150</width>\n";
  97. $rss .= " <height>50</height>\n";
  98. $rss .= " <link>http://intranet.Company.com/</link>\n";
  99. $rss .= " </image>\n";
  100. $submitted_sth = $dbh->execute($submitted_sql);
  101. while($submitted_sth->fetchInto($SUBMITTED)) {
  102. $title = $SUBMITTED['purpose'];
  103. $company = caps$COMPANY[$SUBMITTED['company']]);
  104. $author = caps($EMPLOYEES[$SUBMITTED['req']]);
  105. $rss .= " <item>\n";
  106. $rss .= " <title>".str_replace("&", "and", $title)."</title>\n";
  107. $rss .= " <link>".$default['URL_HOME']."/$DATABASE/detail.php?id=$SUBMITTED[id]</link>\n";
  108. $rss .= " <author>$author</author>\n";
  109. $rss .= " <description>".str_replace("&", "and", $title)."</description>\n";
  110. $rss .= " <category>Submitted</category>\n";
  111. // $rss .= " <category>$company</category>\n";
  112. $rss .= " <pubDate>$SUBMITTED[reqDate]</pubDate>\n";
  113. $rss .= " </item>\n";
  114. }
  115. $approved_sth = $dbh->execute($approved_sql);
  116. while($approved_sth->fetchInto($APPROVED)) {
  117. $title = $APPROVED['purpose'];
  118. $company = caps($COMPANY[$APPROVED[company]]);
  119. $author = caps($EMPLOYEES[$APPROVED[req]]);
  120. $rss .= " <item>\n";
  121. $rss .= " <title>".str_replace("&", "and", $title)."</title>\n";
  122. $rss .= " <link>".$default['URL_HOME']."/$DATABASE/detail.php?id=$APPROVED[id]</link>\n";
  123. $rss .= " <author>$author</author>\n";
  124. $rss .= " <description>".str_replace("&", "and", $title)."</description>\n";
  125. $rss .= " <category>Approved</category>\n";
  126. // $rss .= " <category>$company</category>\n";
  127. $rss .= " <pubDate>$APPROVED[reqDate]</pubDate>\n";
  128. $rss .= " </item>\n";
  129. }
  130. $denied_sth = $dbh->execute($denied_sql);
  131. while($denied_sth->fetchInto($DENIED)) {
  132. $title = $DENIED['purpose'];
  133. $company = caps($COMPANY[$DENIED[company]]);
  134. $author = caps($EMPLOYEES[$DENIED[req]]);
  135. $rss .= " <item>\n";
  136. $rss .= " <title>".str_replace("&", "and", $title)."</title>\n";
  137. $rss .= " <link>".$default['URL_HOME']."/$DATABASE/detail.php?id=$DENIED[id]</link>\n";
  138. $rss .= " <author>$author</author>\n";
  139. $rss .= " <description>".str_replace("&", "and", $title)."</description>\n";
  140. $rss .= " <category>Denied</category>\n";
  141. // $rss .= " <category>$company</category>\n";
  142. $rss .= " <pubDate>$DENIED[app1Date]</pubDate>\n";
  143. $rss .= " </item>\n";
  144. }
  145. $rss .= " </channel>\n";
  146. $rss .= "</rss>\n";
  147. /* ------------------------------------------ CREATE RSS 2.0 FILE ----------------------------------------- */
  148. if ($debug) {
  149. echo "RSS_ITEMS: ".$rss_items."<br>";
  150. echo "DEFAULT: ".$default['rss_items']."<br>";
  151. echo "QUERY: <br>".$submitted_query."<br>";
  152. echo "FILENAME: ".$filename."<br>";
  153. echo "RSS: <BR>".$rss;
  154. exit;
  155. }
  156. /* ------------------ START RSS.XML FILE ----------------------- */
  157. // Let's make sure the file exists and is writable first.
  158. if (is_writable($filename)) {
  159. // Open $filename for writing
  160. if (!$handle = fopen($filename, 'w')) {
  161. $_SESSION['error'] = "Cannot open file ($filename)";
  162. header("Location: ../error.php");
  163. exit;
  164. }
  165. // Write $rss to our opened file.
  166. if (fwrite($handle, $rss) === FALSE) {
  167. $_SESSION['error'] = "Cannot write to file ($filename)";
  168. header("Location: ../error.php");
  169. exit;
  170. }
  171. //echo "Success, wrote ($somecontent) to file ($filename)";
  172. fclose($handle);
  173. } else {
  174. $_SESSION['error'] = "The file $filename is not writable";
  175. header("Location: ../error.php");
  176. exit;
  177. }
  178. /* ------------------ END RSS.XML FILE ----------------------- */
  179. /* Forward user to list.php after RSS file is created */
  180. header("Location: list.php?action=my&access=0");
  181. /**
  182. * - Display Debug Information
  183. */
  184. include_once('debug/footer.php');
  185. /**
  186. * - Disconnect from database
  187. */
  188. $dbh->disconnect();
  189. ?>