PageRenderTime 27ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/data/rss.php

https://github.com/tlezotte/ePOS
PHP | 314 lines | 202 code | 46 blank | 66 comment | 14 complexity | 11cda2cda7de47f1deb18e323621b2cb 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. if (array_key_exists('p', $_GET) OR array_key_exists('d', $_GET) OR array_key_exists('e', $_GET)) {
  31. /* ========== Custom RSS feed ========== */
  32. // Example: http://www.yourdomain.com/go/Request/PO/rss.php?e=MDEzNTI%3D
  33. /* --- Custom RSS feed by employee --- */
  34. if (array_key_exists('a', $_GET) AND array_key_exists('e', $_GET)) {
  35. $search_query = "a." . $_GET['a'] . "='" . base64_decode(urldecode($_GET['e'])) . "'";
  36. } else if (array_key_exists('e', $_GET)) {
  37. $search_query = "p.req='" . base64_decode(urldecode($_GET['e'])) . "'";
  38. }
  39. /* --- Custom RSS feed by plant --- */
  40. if (array_key_exists('p', $_GET)) {
  41. $search_query = "p.plant='" . $_GET['p'] . "'";
  42. }
  43. /* --- Custom RSS feed by department --- */
  44. if (array_key_exists('d', $_GET)) {
  45. $search_query = "p.department='" . $_GET['d'] . "'";
  46. }
  47. /* ----- Getting career postings from Intranet ----- */
  48. $sql = <<< SQL
  49. SELECT p.id AS _id, p.purpose, p.hot, e.fst, e.lst, e.email, l.name AS _plant, d.name AS _dept, v.BTNAME AS _vendor, DATE_FORMAT(FROM_UNIXTIME( p.reqDate),'%a, %d %b %Y %T') AS postdate
  50. FROM PO p
  51. LEFT JOIN Standards.Employees e ON e.eid=p.req
  52. LEFT JOIN Standards.Plants l ON l.id=p.plant
  53. LEFT JOIN Standards.Department d ON d.id=p.department
  54. LEFT JOIN Standards.Vendor v ON v.BTVEND=p.sup
  55. LEFT JOIN Authorization a ON a.type_id=p.id
  56. WHERE $search_query AND p.status='N'
  57. ORDER BY p.id DESC
  58. SQL;
  59. $query = $dbh->prepare($sql);
  60. echo $sql;
  61. /* ------------------ END DATABASE CONNECTIONS ----------------------- */
  62. /* ------------------ START VARIABLES ----------------------- */
  63. /* Generate at RFC 2822 formatted date */
  64. $pubDate = date("r");
  65. /* ------------------ END VARIABLES ----------------------- */
  66. /* ------------------------------------------ CREATE RSS 2.0 FILE ----------------------------------------- */
  67. header('Content-Type: text/xml');
  68. header('Pragma: public');
  69. header('Cache-control: private');
  70. header('Expires: -1');
  71. $rss = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n";
  72. $rss .= "<rss version=\"2.0\">\n";
  73. $rss .= " <channel>\n";
  74. $rss .= " <title>Purchase Requisition System - Custom</title>\n";
  75. $rss .= " <link>http://www.yourdomain.com/go/Request/index.php</link>\n";
  76. $rss .= " <description>Custom Purchase Requisition System RSS Feed</description>\n";
  77. $rss .= " <pubDate>$pubDate</pubDate>\n";
  78. $rss .= " <copyright>2007 Your Company, LLC.</copyright>\n";
  79. $rss .= " <webMaster>tlezotte@Company.com</webMaster>\n";
  80. $rss .= " <image>\n";
  81. $rss .= " <title>Your Company, LLC.</title>\n";
  82. $rss .= " <url>http://www.Company.com/images/CompanyRSS.gif</url>\n";
  83. $rss .= " <width>144</width>\n";
  84. $rss .= " <height>48</height>\n";
  85. $rss .= " <link>http://www.Company.com</link>\n";
  86. $rss .= " </image>\n";
  87. $sth = $dbh->execute($query);
  88. while($sth->fetchInto($POST)) {
  89. $hot = ($POST['hot'] == 'yes') ? Hot : Normal;
  90. $rss .= " <item>\n";
  91. $rss .= " <title><![CDATA[(" . $POST['_id'] . ") " . html_entity_decode($POST['purpose']) . "]]></title>\n";
  92. $rss .= " <link><![CDATA[http://www.yourdomain.com/go/Request/PO/detail.php?id=" . $POST['_id'] . "]]></link>\n";
  93. $rss .= " <author>" . $POST['email'] . " (" . ucwords(strtolower($POST['fst'])) . " " . ucwords(strtolower($POST['lst'])) .")</author>\n";
  94. $rss .= " <description><![CDATA[" . html_entity_decode($POST['purpose']) . "]]></description>\n";
  95. $rss .= " <category>" . ucwords(strtolower($POST['_plant'])) . "</category>\n";
  96. $rss .= " <category>" . ucwords(strtolower($POST['_dept'])) . "</category>\n";
  97. $rss .= " <category><![CDATA[" . html_entity_decode(ucwords(strtolower($POST['_vendor']))) . "]]></category>\n";
  98. $rss .= " <category>" . $hot . "</category>\n";
  99. $rss .= " <pubDate>" . $POST['postdate'] . " -0400</pubDate>\n";
  100. $rss .= " </item>\n";
  101. }
  102. $rss .= " </channel>\n";
  103. $rss .= "</rss>\n";
  104. /* ------------------------------------------ CREATE RSS 2.0 FILE ----------------------------------------- */
  105. print $rss;
  106. } else {
  107. /* ========== Standard RSS feed ========== */
  108. $rss_type = 'PO'; //Type of RSS feed
  109. switch ($rss_type) {
  110. case 'CER':
  111. $DATABASE = 'CER';
  112. $LABEL = 'Capital Acquisitions';
  113. break;
  114. case 'PO':
  115. $DATABASE = 'PO';
  116. $LABEL = 'Purchase Requests';
  117. break;
  118. }
  119. /* ------------------ START DATABASE CONNECTIONS ----------------------- */
  120. $rss_items = $default['rss_items'] / 2;
  121. /* Getting Submitted PO information */
  122. $submitted_query = <<< SQL
  123. SELECT id, purpose, reqDate, req, company
  124. FROM $DATABASE
  125. ORDER BY reqDate DESC
  126. LIMIT $rss_items
  127. SQL;
  128. $submitted_sql = $dbh->prepare($submitted_query);
  129. /* Getting Approved PO information */
  130. $approved_query = <<< SQL
  131. SELECT p.id, p.purpose, p.req, p.company, a.issuer, a.issuerDate
  132. FROM $DATABASE p, Authorization a
  133. WHERE p.id = a.type_id AND a.type = '$DATABASE' AND a.issuerDate IS NOT NULL
  134. ORDER BY a.issuerDate DESC
  135. LIMIT $rss_items
  136. SQL;
  137. $approved_sql = $dbh->prepare($approved_query);
  138. /* Getting Denied PO information */
  139. $denied_query = <<< SQL
  140. SELECT p.id, p.purpose, p.req, p.company, a.app1Date
  141. FROM $DATABASE p, Authorization a
  142. WHERE p.id = a.type_id AND a.type = '$DATABASE' AND (a.app1yn = 'no' OR a.app2yn = 'no')
  143. ORDER BY a.app1Date DESC
  144. LIMIT $rss_items
  145. SQL;
  146. $denied_sql = $dbh->prepare($denied_query);
  147. /* Get Employee names from Standards database */
  148. $EMPLOYEES = $dbh->getAssoc("SELECT e.eid, CONCAT(e.fst,' ',e.lst) AS name ".
  149. "FROM Users u, Standards.Employees e ".
  150. "WHERE e.eid = u.eid");
  151. /* Get Companies names from Standards database */
  152. $COMPANY = $dbh->getAssoc("SELECT id, name FROM Standards.Companies WHERE id > 0");
  153. /* ------------------ END DATABASE CONNECTIONS ----------------------- */
  154. /* ------------------ START VARIABLES ----------------------- */
  155. /* Generate at RFC 2822 formatted date */
  156. $pubDate = date("r");
  157. $filename = $default['rss_file'];
  158. /* ------------------ END VARIABLES ----------------------- */
  159. /* ------------------------------------------ CREATE RSS 2.0 FILE ----------------------------------------- */
  160. //header('Content-Type: text/xml');
  161. $rss = "<?xml version=\"1.0\"?>\n";
  162. $rss .= "<rss version=\"2.0\">\n";
  163. $rss .= " <channel>\n";
  164. $rss .= " <title>$LABEL</title>\n";
  165. $rss .= " <link>".$default['URL_HOME']."/index.php</link>\n";
  166. $rss .= " <description>List of $LABEL transactions using the $default[title1]</description>\n";
  167. $rss .= " <pubDate>$pubDate</pubDate>\n";
  168. $rss .= " <copyright>2004 Your Company</copyright>\n";
  169. $rss .= " <webMaster>webmaster@".$default['email_domain']."</webMaster>\n";
  170. $rss .= " <category>$default[title1]</category>\n";
  171. $rss .= " <image>\n";
  172. $rss .= " <title>Your Company</title>\n";
  173. $rss .= " <url>$default[rss_image]</url>\n";
  174. $rss .= " <width>150</width>\n";
  175. $rss .= " <height>50</height>\n";
  176. $rss .= " <link>http://intranet.Company.com/</link>\n";
  177. $rss .= " </image>\n";
  178. $submitted_sth = $dbh->execute($submitted_sql);
  179. while($submitted_sth->fetchInto($SUBMITTED)) {
  180. $title = $SUBMITTED['purpose'];
  181. $company = caps($COMPANY[$SUBMITTED['company']]);
  182. $author = caps($EMPLOYEES[$SUBMITTED['req']]);
  183. $rss .= " <item>\n";
  184. $rss .= " <title>".str_replace("&", "and", $title)."</title>\n";
  185. $rss .= " <link>".$default['URL_HOME']."/$DATABASE/detail.php?id=$SUBMITTED[id]</link>\n";
  186. $rss .= " <author>$author</author>\n";
  187. $rss .= " <description>".str_replace("&", "and", $title)."</description>\n";
  188. $rss .= " <category>Submitted</category>\n";
  189. // $rss .= " <category>$company</category>\n";
  190. $rss .= " <pubDate>$SUBMITTED[reqDate]</pubDate>\n";
  191. $rss .= " </item>\n";
  192. }
  193. $approved_sth = $dbh->execute($approved_sql);
  194. while($approved_sth->fetchInto($APPROVED)) {
  195. $title = $APPROVED['purpose'];
  196. $company = caps($COMPANY[$APPROVED[company]]);
  197. $author = caps($EMPLOYEES[$APPROVED[req]]);
  198. $rss .= " <item>\n";
  199. $rss .= " <title>".str_replace("&", "and", $title)."</title>\n";
  200. $rss .= " <link>".$default['URL_HOME']."/$DATABASE/detail.php?id=$APPROVED[id]</link>\n";
  201. $rss .= " <author>$author</author>\n";
  202. $rss .= " <description>".str_replace("&", "and", $title)."</description>\n";
  203. $rss .= " <category>Approved</category>\n";
  204. // $rss .= " <category>$company</category>\n";
  205. $rss .= " <pubDate>$APPROVED[reqDate]</pubDate>\n";
  206. $rss .= " </item>\n";
  207. }
  208. $denied_sth = $dbh->execute($denied_sql);
  209. while($denied_sth->fetchInto($DENIED)) {
  210. $title = $DENIED['purpose'];
  211. $company = caps($COMPANY[$DENIED[company]]);
  212. $author = caps($EMPLOYEES[$DENIED[req]]);
  213. $rss .= " <item>\n";
  214. $rss .= " <title>".str_replace("&", "and", $title)."</title>\n";
  215. $rss .= " <link>".$default['URL_HOME']."/$DATABASE/detail.php?id=$DENIED[id]</link>\n";
  216. $rss .= " <author>$author</author>\n";
  217. $rss .= " <description>".str_replace("&", "and", $title)."</description>\n";
  218. $rss .= " <category>Denied</category>\n";
  219. // $rss .= " <category>$company</category>\n";
  220. $rss .= " <pubDate>$DENIED[app1Date]</pubDate>\n";
  221. $rss .= " </item>\n";
  222. }
  223. $rss .= " </channel>\n";
  224. $rss .= "</rss>\n";
  225. /* ------------------------------------------ CREATE RSS 2.0 FILE ----------------------------------------- */
  226. if ($debug) {
  227. echo "RSS_ITEMS: ".$rss_items."<br>";
  228. echo "DEFAULT: ".$default['rss_items']."<br>";
  229. echo "QUERY: <br>".$submitted_query."<br>";
  230. echo "FILENAME: ".$filename."<br>";
  231. echo "RSS: <BR>".$rss;
  232. exit;
  233. }
  234. /* ------------------ START RSS.XML FILE ----------------------- */
  235. // Let's make sure the file exists and is writable first.
  236. if (is_writable($filename)) {
  237. // Open $filename for writing
  238. if (!$handle = fopen($filename, 'w')) {
  239. $_SESSION['error'] = "Cannot open file ($filename)";
  240. header("Location: ../error.php");
  241. exit;
  242. }
  243. // Write $rss to our opened file.
  244. if (fwrite($handle, $rss) === FALSE) {
  245. $_SESSION['error'] = "Cannot write to file ($filename)";
  246. header("Location: ../error.php");
  247. exit;
  248. }
  249. //echo "Success, wrote ($somecontent) to file ($filename)";
  250. fclose($handle);
  251. } else {
  252. $_SESSION['error'] = "The file $filename is not writable";
  253. header("Location: ../error.php");
  254. exit;
  255. }
  256. /* ------------------ END RSS.XML FILE ----------------------- */
  257. /* Forward user to list.php after RSS file is created */
  258. header("Location: list.php?action=my&access=0");
  259. }
  260. /**
  261. * - Display Debug Information
  262. */
  263. include_once('debug/footer.php');
  264. /**
  265. * - Disconnect from database
  266. */
  267. $dbh->disconnect();
  268. ?>