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