File: 0.01.0a/customer/index.php (View as HTML)

  1: <?php
  2: /* -------------------------------------------------------------
  3: This file is part of FreeDESK
  4: 
  5: FreeDESK is (C) Copyright 2012 David Cutting
  6: 
  7: FreeDESK is free software: you can redistribute it and/or modify
  8: it under the terms of the GNU General Public License as published by
  9: the Free Software Foundation, either version 3 of the License, or
 10: (at your option) any later version.
 11: 
 12: FreeDESK is distributed in the hope that it will be useful,
 13: but WITHOUT ANY WARRANTY; without even the implied warranty of
 14: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 15: GNU General Public License for more details.
 16: 
 17: You should have received a copy of the GNU General Public License
 18: along with FreeDESK.  If not, see www.gnu.org/licenses
 19: 
 20: For more information see www.purplepixie.org/freedesk/
 21: -------------------------------------------------------------- */
 22: 
 23: 
 24: if (!isset($_REQUEST['sid']))
 25: {
 26: 	header("Location: login.php");
 27: 	exit();
 28: }
 29: require("../core/FreeDESK.php");
 30: $DESK = new FreeDESK("../");
 31: $DESK->Start();
 32: if (!$DESK->ContextManager->Open(ContextType::Customer, $_REQUEST['sid']))
 33: {
 34: 	header("Location: login.php?e=expired");
 35: 	exit();
 36: }
 37: 
 38: if (isset($_REQUEST['action']))
 39: {
 40: 	if ($_REQUEST['action'] == "updaterequest")
 41: 	{
 42: 		$rid = $_REQUEST['requestid'];
 43: 		$req = $DESK->RequestManager->Fetch($rid);
 44: 		if ($rid !== false && $req->Get("customerid")==$DESK->ContextManager->Session->username)
 45: 		{
 46: 			$req->Update($_REQUEST['update']);
 47: 		}
 48: 	}
 49: 	else if ($_REQUEST['action'] == "createrequest")
 50: 	{
 51: 		$req = $DESK->RequestManager->CreateById("");
 52: 		$rid=$req->Create($DESK->ContextManager->Session->username,
 53: 			$_REQUEST['update'],
 54: 			"",
 55: 			1 );
 56: 		$loc="./?mode=request&requestid=".$rid."&sid=".$_REQUEST['sid'];
 57: 		header("Location: ".$loc);
 58: 		exit();
 59: 	}
 60: }
 61: 
 62: ?>
 63: <!DOCTYPE html>
 64: <html>
 65: <head>
 66: <link rel="stylesheet" type="text/css" href="customer.css" />
 67: <title>FreeDESK Customer Interface</title>
 68: </head>
 69: <body>
 70: <div class="container">
 71: 
 72: <div class="header">FreeDESK Customer Interface</div>
 73: <div class="menu">
 74: <a href="./?mode=new&sid=<?php echo $_REQUEST['sid']; ?>">New Request</a> | 
 75: <a href="./?mode=myrequests&sid=<?php echo $_REQUEST['sid']; ?>">My Requests</a> | 
 76: <a href="../">Logout</a>
 77: </div>
 78: <?php
 79: if (!isset($_REQUEST['mode']))
 80: {
 81: ?>
 82: <div class="contents">
 83: Welcome to the FreeDESK customer interface.<br /><br />
 84: Please select an option from above.<br /><br />
 85: </div>
 86: <?php
 87: }
 88: else if ($_REQUEST['mode'] == "myrequests")
 89: {
 90: 	$data = array();
 91: 	$data[]=array("field"=>"customer", "value"=>$DESK->ContextManager->Session->username);
 92: 	$pris = $DESK->RequestManager->GetPriorityList();
 93: 	$stats = $DESK->RequestManager->StatusList();
 94: 	$reqs = $DESK->RequestManager->SearchRequests($data);
 95: 	echo "<table class=\"requestlist\">\n";
 96: 	foreach($reqs as $req)
 97: 	{
 98: 		echo "<tr>\n";
 99: 		echo "<td><a href=\"./?mode=request&requestid=".$req['requestid']."&sid=".$_REQUEST['sid']."\">ID ".$req['requestid']."</a></td>\n";
100: 		echo "<td>".$req['openeddt']."</td>\n";
101: 		echo "<td>";
102: 		if (isset($pris[$req['priority']]))
103: 			echo $pris[$req['priority']]['priorityname'];
104: 		else
105: 			echo "-";
106: 		echo "</td>\n";
107: 		echo "<td>";
108: 		if (isset($stats[$req['status']]))
109: 			echo $stats[$req['status']];
110: 		else
111: 			echo "-";
112: 		echo "</td>\n";
113: 		echo "</tr>\n";
114: 	}
115: 	echo "</table>";
116: }
117: else if ($_REQUEST['mode'] == "request")
118: {
119: 	$req = $DESK->RequestManager->Fetch($_REQUEST['requestid']);
120: 	$cid = $req->Get("customerid");
121: 	//echo $cid;
122: 	if ($req === false)
123: 	{
124: 		echo "<h3>Request not found</h3>";
125: 	}
126: 	else if ($cid != $DESK->ContextManager->Session->username) // not our request (naughty!)
127: 	{
128: 		echo "<h3>Access to request denied</h3>";
129: 	}
130: 	else
131: 	{
132: 		echo "<table class=\"reqdetails\">\n";
133: 		echo "<tr>\n";
134: 		echo "<td>ID</td>\n";
135: 		echo "<td>".$req->ID."</td></tr>\n";
136: 		echo "<tr>\n";
137: 		echo "<td>Opened</td>\n";
138: 		echo "<td>".$req->Get("openeddt")."</td></tr>\n";
139: 		echo "</table>\n";
140: 		
141: 		echo "<br /><br />\n";
142: 		
143: 		$req->LoadUpdates();
144: 		$updates=$req->GetUpdates();
145: 		
146: 		echo "<table class=\"requpdates\">\n";
147: 		foreach($updates as $update)
148: 		{
149: 			echo "<tr><td class=\"updatehead\">";
150: 			echo $update['updatedt']." : ".$update['updateby']."\n";
151: 			echo "</td></tr>\n";
152: 			echo "<tr><td>\n";
153: 			echo nl2br($update['update']);
154: 			echo "</td></tr>";
155: 		}
156: 		echo "</table>\n";
157: 		
158: 		echo "<br /><br />";
159: 		
160: 		if ($req->Get("status")>0)
161: 		{
162: 			echo "<form id=\"requestupdate\" action=\"./\" method=\"post\">\n";
163: 			echo "<input type=\"hidden\" name=\"action\" value=\"updaterequest\" />\n";
164: 			echo "<input type=\"hidden\" name=\"requestid\" value=\"".$_REQUEST['requestid']."\" />\n";
165: 			echo "<input type=\"hidden\" name=\"mode\" value=\"request\" />\n";
166: 			echo "<input type=\"hidden\" name=\"sid\" value=\"".$_REQUEST['sid']."\" />\n";
167: 			echo "<h3>Update Request</h3>\n";
168: 			echo "<textarea name=\"update\" rows=\"10\" cols=\"50\"></textarea><br />\n";
169: 			echo "<input type=\"submit\" value=\"Update Request\" />\n";
170: 			echo "</form>\n";
171: 		}
172: 		else
173: 		{
174: 			echo "<h3>Request is closed - contact Service Desk to reopen</h3>\n";
175: 		}
176: 		
177: 		echo "<br /><br />";
178: 	}
179: }
180: else if ($_REQUEST['mode'] == "new")
181: {
182: 	echo "<h3>New Request</h3>\n";
183: 	echo "Please enter as much information about the request as possible.<br /><br />";
184: 	echo "<form id=\"requestcreate\" action=\"./\" method=\"post\">\n";
185: 	echo "<input type=\"hidden\" name=\"action\" value=\"createrequest\" />\n";
186: 	echo "<input type=\"hidden\" name=\"sid\" value=\"".$_REQUEST['sid']."\" />\n";
187: 	echo "<textarea name=\"update\" rows=\"10\" cols=\"50\"></textarea><br />\n";
188: 	echo "<input type=\"submit\" value=\"Create Request\" />\n";
189: 	echo "</form>\n";
190: }
191: ?>
192: </div>
193: </body>
194: </html>
195: 
196: