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