PageRenderTime 25ms CodeModel.GetById 26ms RepoModel.GetById 0ms app.codeStats 0ms

/CER/rss.php

https://github.com/tlezotte/ePOS
PHP | 202 lines | 120 code | 30 blank | 52 comment | 6 complexity | e7daf26299d08e0beaf6524fd07cbb84 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 CER
  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. * - Check User Access
  28. */
  29. require_once('../security/check_user.php');
  30. /**
  31. * - Config Information
  32. */
  33. require_once('../include/config.php');
  34. $rss_type = 'CER'; //Type of RSS feed
  35. switch ($rss_type) {
  36. case 'CER':
  37. $DATABASE = 'CER';
  38. $LABEL = 'Capital Exprense';
  39. break;
  40. case 'PO':
  41. $DATABASE = 'PO';
  42. $LABEL = 'Purchase Orders';
  43. break;
  44. }
  45. /* ------------------ START DATABASE CONNECTIONS ----------------------- */
  46. $rss_items = $default['rss_items'] / 2;
  47. /* Getting Submitted CER information */
  48. $submitted_query = <<< SQL
  49. SELECT id, purpose, reqDate, req, company, summary
  50. FROM $DATABASE
  51. ORDER BY reqDate DESC
  52. LIMIT $rss_items
  53. SQL;
  54. $submitted_sql = $dbh->prepare($submitted_query);
  55. /* Getting Approved CER information */
  56. $approved_query = <<< SQL
  57. SELECT c.id, c.purpose, c.req, c.company, c.summary, a.issuer, a.issuerDate
  58. FROM $DATABASE c, Authorization a
  59. WHERE c.id = a.type_id AND a.type = '$DATABASE' AND issuerDate IS NOT NULL
  60. ORDER BY a.issuerDate DESC
  61. LIMIT $rss_items
  62. SQL;
  63. $approved_sql = $dbh->prepare($approved_query);
  64. /* Get Employee names from Standards database */
  65. $EMPLOYEES = $dbh->getAssoc("SELECT e.eid, CONCAT(e.fst,' ',e.lst) AS name ".
  66. "FROM Users u, Standards.Employees e ".
  67. "WHERE e.eid = u.eid");
  68. /* Get Companies names from Standards database */
  69. $COMPANY = $dbh->getAssoc("SELECT id, name FROM Standards.Companies WHERE id > 0");
  70. /* ------------------ END DATABASE CONNECTIONS ----------------------- */
  71. /* ------------------ START VARIABLES ----------------------- */
  72. /* Generate at RFC 2822 formatted date */
  73. $pubDate = date("r");
  74. $URL = "http://$_SERVER[HTTP_HOST]$default[url_home]";
  75. $filename = $default['rss_file'];
  76. /* ------------------ END VARIABLES ----------------------- */
  77. /* ------------------------------------------ CREATE RSS 2.0 FILE ----------------------------------------- */
  78. //header('Content-Type: text/xml');
  79. $rss = "<?xml version=\"1.0\"?>\n";
  80. $rss .= "<rss version=\"2.0\">\n";
  81. $rss .= " <channel>\n";
  82. $rss .= " <title>$LABEL</title>\n";
  83. $rss .= " <link>$URL/index.php</link>\n";
  84. $rss .= " <description>List of $LABEL transactions using the $default[title1]</description>\n";
  85. $rss .= " <pubDate>$pubDate</pubDate>\n";
  86. $rss .= " <copyright>2004 Your Company</copyright>\n";
  87. $rss .= " <webMaster>webmaster@".$default['email_domain']."</webMaster>\n";
  88. $rss .= " <category>$default[title1]</category>\n";
  89. $rss .= " <image>\n";
  90. $rss .= " <title>Your Company</title>\n";
  91. $rss .= " <url>$default[rss_image]</url>\n";
  92. $rss .= " <width>150</width>\n";
  93. $rss .= " <height>50</height>\n";
  94. $rss .= " <link>http://intranet.Company.com/</link>\n";
  95. $rss .= " </image>\n";
  96. $submitted_sth = $dbh->execute($submitted_sql);
  97. while($submitted_sth->fetchInto($SUBMITTED)) {
  98. $title = stripslashes($SUBMITTED['purpose']);
  99. $description = stripslashes($SUBMITTED['summary']);
  100. $company = ucwords(strtolower($COMPANY[$SUBMITTED['company']]));
  101. $author = ucwords(strtolower($EMPLOYEES[$SUBMITTED['req']]));
  102. $rss .= " <item>\n";
  103. $rss .= " <title>".str_replace("&", "and", $title)."</title>\n";
  104. $rss .= " <link>$URL/$DATABASE/detail.php?id=$SUBMITTED[id]</link>\n";
  105. $rss .= " <author>$author</author>\n";
  106. $rss .= " <description>$description</description>\n";
  107. $rss .= " <category>Submitted</category>\n";
  108. $rss .= " <category>$company</category>\n";
  109. $rss .= " <pubDate>$SUBMITTED[reqDate]</pubDate>\n";
  110. $rss .= " </item>\n";
  111. }
  112. $approved_sth = $dbh->execute($approved_sql);
  113. while($approved_sth->fetchInto($APPROVED)) {
  114. $title = stripslashes($APPROVED['purpose']);
  115. $description = stripslashes($APPROVED['summary']);
  116. $company = ucwords(strtolower($COMPANY[$APPROVED[company]]));
  117. $author = ucwords(strtolower($EMPLOYEES[$APPROVED[req]]));
  118. $rss .= " <item>\n";
  119. $rss .= " <title>".str_replace("&", "and", $title)."</title>\n";
  120. $rss .= " <link>$URL/$DATABASE/detail.php?id=$APPROVED[id]</link>\n";
  121. $rss .= " <author>$author</author>\n";
  122. $rss .= " <description>$description</description>\n";
  123. $rss .= " <category>Approved</category>\n";
  124. $rss .= " <category>$company</category>\n";
  125. $rss .= " <pubDate>$APPROVED[reqDate]</pubDate>\n";
  126. $rss .= " </item>\n";
  127. }
  128. $rss .= " </channel>\n";
  129. $rss .= "</rss>\n";
  130. /* ------------------------------------------ CREATE RSS 2.0 FILE ----------------------------------------- */
  131. if ($debug) {
  132. echo "RSS_ITEMS: ".$rss_items."<br>";
  133. echo "DEFAULT: ".$default['rss_items']."<br>";
  134. echo "QUERY: <br>".$submitted_query."<br>";
  135. echo "FILENAME: ".$filename."<br>";
  136. echo "RSS: <BR>".$rss;
  137. exit;
  138. }
  139. /* ------------------ START RSS.XML FILE ----------------------- */
  140. // Let's make sure the file exists and is writable first.
  141. if (is_writable($filename)) {
  142. // Open $filename for writing
  143. if (!$handle = fopen($filename, 'w')) {
  144. $_SESSION['error'] = "Cannot open file ($filename)";
  145. header("Location: ../error.php");
  146. exit;
  147. }
  148. // Write $rss to our opened file.
  149. if (fwrite($handle, $rss) === FALSE) {
  150. $_SESSION['error'] = "Cannot write to file ($filename)";
  151. header("Location: ../error.php");
  152. exit;
  153. }
  154. //echo "Success, wrote ($somecontent) to file ($filename)";
  155. fclose($handle);
  156. } else {
  157. $_SESSION['error'] = "The file $filename is not writable";
  158. header("Location: ../error.php");
  159. exit;
  160. }
  161. /* ------------------ END RSS.XML FILE ----------------------- */
  162. /* Forward user to list.php after RSS file is created */
  163. header("Location: list.php?action=my");
  164. /**
  165. * - Display Debug Information
  166. */
  167. include_once('debug/footer.php');
  168. /**
  169. * - Disconnect from database
  170. */
  171. $dbh->disconnect();
  172. ?>