ソースを参照

move to trunk/apps.

Mark Crane 13 年 前
コミット
593fcc08d9

+ 5 - 0
tickets/README

@@ -0,0 +1,5 @@
+This Module brought to you by the Letters Ken Rice <krice at tollfreegateway dot com>
+
+See the Wiki for more information.
+
+Simple Ticket Tracking System To allow customer Support

+ 3 - 0
tickets/bad_ticket_id.php

@@ -0,0 +1,3 @@
+<div>
+	<strong>Ticket Does Not Exist</strong>
+</div>

+ 31 - 0
tickets/errors.php

@@ -0,0 +1,31 @@
+<?php
+/*
+	FusionPBX
+      	Version: MPL 1.1
+
+	The contents of this file are subject to the Mozilla Public License Version
+	1.1 (the "License"); you may not use this file except in compliance with
+	the License. You may obtain a copy of the License at
+	http://www.mozilla.org/MPL/
+
+	Software distributed under the License is distributed on an "AS IS" basis,
+	WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+	for the specific language governing rights and limitations under the
+	License.
+
+	The Original Code is FusionPBX
+
+	The Initial Developer of the Original Code is
+	Mark J Crane <[email protected]>
+	Portions created by the Initial Developer are Copyright (C) 2008-2010
+	the Initial Developer. All Rights Reserved.
+
+	Contributor(s):
+	Ken Rice <[email protected]>
+	Mark J Crane <[email protected]>
+*/
+echo "<div align='center'>\n";
+echo "<table><tr><td>\n";
+echo $error . "\n";
+echo "</td></tr></table>\n";
+?>

+ 55 - 0
tickets/manager_main.php

@@ -0,0 +1,55 @@
+<div align='center'>
+
+<table width="100%" border="0" cellpadding="6" cellspacing="0">
+  <tr>
+	<td align='left'><b>XMPP Manager</b><br>
+		Utilizes the Jingle protocol. Jingle is an extension to the Jabber/XMPP protocol.
+	</td>
+  </tr>
+</table>
+<br />
+
+<table width='100%' border='0' cellpadding='0' cellspacing='0'>
+<tr>
+	<th>Profile</th>
+	<th>Context</th>
+	<th>State</th>
+	<th>Enabled</th>
+	<th>Description</th>
+<td align='right' width='42'>
+	<?php if (permission_exists('xmpp_add')) { ?>
+		<a href='v_profile_edit.php' alt='add'><?php echo $v_link_label_add; ?></a>
+	<?php } ?>
+</td>
+</tr>
+<?php
+foreach($profiles_array as $profile){
+?>
+<tr>
+	<td><?php echo $profile['profile_name']; ?></td>
+	<td><?php echo $profile['context']; ?></td>
+        <td><?php echo $profile['status']; ?></td>
+	<td><?php echo $profile['enabled']; ?></td>
+	<td><?php echo $profile['description']; ?></td>
+<td align='right' width='42'>
+	<?php if (permission_exists('xmpp_edit')) { ?>
+	<a href='v_profile_edit.php?id=<?php echo $profile['xmpp_profile_id']; ?>' alt='edit'><?php echo $v_link_label_edit; ?></a>
+	<?php } ?>
+	<?php if (permission_exists('xmpp_delete')) { ?>
+	<a href='v_profile_delete.php?id=<?php echo $profile['xmpp_profile_id']; ?>' onclick="return confirm('Do you really want to delete this?')" 
+		alt='delete'><?php echo $v_link_label_delete; ?></a>
+	<?php } ?>
+</td>
+</tr>
+<?php 
+}
+?>
+<tr>
+<td colspan='6' align='right' width='42'>
+	<?php if (permission_exists('xmpp_add')) { ?>
+		<a href='v_profile_edit.php' alt='add'><?php echo $v_link_label_add; ?></a>
+	<?php } ?>
+</td>
+</tr>
+</table>
+</div>

+ 51 - 0
tickets/root.php

@@ -0,0 +1,51 @@
+<?php
+/*
+	FusionPBX
+      	Version: MPL 1.1
+
+	The contents of this file are subject to the Mozilla Public License Version
+	1.1 (the "License"); you may not use this file except in compliance with
+	the License. You may obtain a copy of the License at
+	http://www.mozilla.org/MPL/
+
+	Software distributed under the License is distributed on an "AS IS" basis,
+	WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+	for the specific language governing rights and limitations under the
+	License.
+
+	The Original Code is FusionPBX
+
+	The Initial Developer of the Original Code is
+	Mark J Crane <[email protected]>
+	Portions created by the Initial Developer are Copyright (C) 2008-2010
+	the Initial Developer. All Rights Reserved.
+
+	Contributor(s):
+	Ken Rice <[email protected]>
+	Mark J Crane <[email protected]>
+*/
+
+// make sure the PATH_SEPARATOR is defined
+	if (!defined("PATH_SEPARATOR")) {
+		if ( strpos( $_ENV[ "OS" ], "Win" ) !== false ) { define("PATH_SEPARATOR", ";"); } else { define("PATH_SEPARATOR", ":"); }
+	}
+
+// make sure the document_root is set
+	$_SERVER["SCRIPT_FILENAME"] = str_replace("\\", "/", $_SERVER["SCRIPT_FILENAME"]);
+	$_SERVER["DOCUMENT_ROOT"] = str_replace($_SERVER["PHP_SELF"], "", $_SERVER["SCRIPT_FILENAME"]);
+	$_SERVER["DOCUMENT_ROOT"] = realpath($_SERVER["DOCUMENT_ROOT"]);
+	//echo "DOCUMENT_ROOT: ".$_SERVER["DOCUMENT_ROOT"]."<br />\n";
+	//echo "PHP_SELF: ".$_SERVER["PHP_SELF"]."<br />\n";
+	//echo "SCRIPT_FILENAME: ".$_SERVER["SCRIPT_FILENAME"]."<br />\n";
+
+// if the project directory exists then add it to the include path otherwise add the document root to the include path
+	if (is_dir($_SERVER["DOCUMENT_ROOT"].'/fusionpbx')){
+		define('PROJECT_PATH', '/fusionpbx');
+		set_include_path( get_include_path() . PATH_SEPARATOR . $_SERVER["DOCUMENT_ROOT"].'/fusionpbx' );
+	}
+	else {
+		define('PROJECT_PATH', '');
+		set_include_path( get_include_path() . PATH_SEPARATOR . $_SERVER['DOCUMENT_ROOT'] );
+	}
+
+?>

+ 66 - 0
tickets/ticket_create.php

@@ -0,0 +1,66 @@
+<div align='center'>
+<table width='100%' border='0' cellpadding='0' cellspacing='2'>
+
+<tr class='border'>
+  <td align="left">
+      <br>
+
+<form method='post' name='ifrm' action=''>
+
+<div align='center'> 
+<table width='100%'  border='0' cellpadding='6' cellspacing='0'> 
+<tr> 
+<td colspan='2'> 
+<table width="100%" border="0" cellpadding="0" cellspacing="0"> 
+	<tr> 
+		<td align='left' width="50%"> 
+			<strong>Create a new Ticket</strong><br> 
+		</td>		<td width='50%' align='right'> 
+			<input type='submit' name='submit' class='btn' value='Save'> 
+			<input type='button' class='btn' name='' alt='back' onclick="window.location='v_xmpp.php'" value='Back'> 
+		</td> 
+	</tr>	
+</table> 
+<br /> 
+</td> 
+</tr> 
+<tr> 
+<td width="30%" class='vncellreq' valign='top' align='left' nowrap='nowrap'> 
+    Subject:
+</td> 
+<td width="70%" class='vtable' align='left'> 
+    <input class='formfld' type='text' name='subject' maxlength='255' value="<?php echo $profile['subject']; ?>"> 
+<br /> 
+1 line Description of problem
+</td> 
+</tr> 
+<tr> 
+<td width="30%" class='vncellreq' valign='top' align='left' nowrap='nowrap'> 
+    Department:
+</td> 
+<td width="70%" class='vtable' align='left'>
+	<select name="queue_id">
+	<?php foreach($queues as $queue) {
+		echo "<option value='" . $queue['queue_id'] . "'>". $queue['queue_name'] . "</option>\n";
+	} ?>
+	</select>
+</td> 
+</tr> 
+<tr> 
+<td class='vncellreq' valign='top' align='left' nowrap='nowrap'> 
+    Detailed Description:
+</td> 
+<td class='vtable' align='left'> 
+    <textarea rows='15' cols='80' class='formfld' type='text' name='problem_description'><?php echo $profile['problem_description'];?></textarea>
+<br /> 
+Enter the a Detailed Description of the problem here.<br/>
+Please include any addition contact information as may be required for us to work this ticket.
+</td> 
+</tr> 
+	<tr> 
+		<td colspan='2' align='right'> 
+				<input type='hidden' name='profile_id' value='<?php echo $profile['xmpp_profile_id']; ?>'> 
+				<input type='submit' name='submit' class='btn' value='Save'> 
+		</td> 
+	</tr></table></form>	</td>	</tr></table></div>
+

+ 59 - 0
tickets/ticket_list.php

@@ -0,0 +1,59 @@
+<div align='center'>
+
+<table width="100%" border="0" cellpadding="6" cellspacing="0">
+  <tr>
+	<td align='left'><b>Active Tickets</b><br>
+		Open Tickets
+	</td>
+  </tr>
+</table>
+<br />
+
+<table width='100%' border='0' cellpadding='0' cellspacing='0'>
+<tr>
+	<th>Ticket Number</th>
+	<th>Queue</th>
+	<th>Status</th>
+	<th>Last Update</th>
+	<th>Subject</th>
+<td align='right' width='42'>
+	<?php if (permission_exists('ticket_add')) { ?>
+		<a href='v_ticket_create.php' alt='Create Ticket'><?php echo $v_link_label_add; ?></a>
+	<?php } ?>
+</td>
+</tr>
+<?php
+$rowstyle[0] = 'rowstyle0';
+$rowstyle[1] = 'rowstyle1';
+$rs = 1;
+foreach($tickets as $ticket){
+if ($rs == 1) { $rs = 0; } else { $rs = 1; }
+?>
+<tr>
+	<td class="<?php echo $rowstyle[$rs]; ?>"><?php echo $ticket['ticket_number']; ?></td>
+	<td class="<?php echo $rowstyle[$rs]; ?>"><?php echo $queues[$ticket['queue_id']]; ?></td>
+        <td class="<?php echo $rowstyle[$rs]; ?>"><?php echo $statuses[$ticket['ticket_status']]; ?></td>
+	<td class="<?php echo $rowstyle[$rs]; ?>"><?php echo $ticket['last_update_stamp']; ?></td>
+	<td class="<?php echo $rowstyle[$rs]; ?>"><?php echo $ticket['subject']; ?></td>
+<td align='right' width='42'>
+	<?php if (permission_exists('ticket_update')) { ?>
+	<a href='v_ticket_update.php?id=<?php echo $ticket['ticket_id']; ?>' alt='Update Ticket'><?php echo $v_link_label_edit; ?></a>
+	<?php } ?>
+	<?php if (permission_exists('ticket_delete')) { ?>
+	<a href='v_profile_delete.php?id=<?php echo $ticket['ticket_id']; ?>' onclick="return confirm('Do you really want to delete this?')" 
+		alt='delete'><?php echo $v_link_label_delete; ?></a>
+	<?php } ?>
+</td>
+</tr>
+<?php 
+}
+?>
+<tr>
+<td colspan='6' align='right' width='42'>
+	<?php if (permission_exists('ticket_add')) { ?>
+		<a href='v_ticket_create.php' alt='Create Ticket'><?php echo $v_link_label_add; ?></a>
+	<?php } ?>
+</td>
+</tr>
+</table>
+</div>

+ 118 - 0
tickets/ticket_manager.php

@@ -0,0 +1,118 @@
+<div align='center'>
+<table width='100%' border='0' cellpadding='0' cellspacing='2'>
+
+<tr class='border'>
+  <td align=\"left\">
+      <br>
+
+<form method='post' name='ifrm' action=''>
+
+<div align='center'> 
+<table width='100%'  border='0' cellpadding='6' cellspacing='0'> 
+<tr> 
+<td colspan='2'> 
+<table width="100%" border="0" cellpadding="0" cellspacing="0"> 
+	<tr> 
+		<td align='left' colspan="2">
+			<strong>Ticket Module Manager</strong><br> 
+		</td>		
+	</tr>
+</table> 
+</td> 
+</tr> 
+<tr>
+	<td colspan="2">
+		<table width='100%' border="0" cellpadding="0" cellspacing="0">
+		<tr><td width="47%" valign="top">
+			<table width='100%' border="0" cellpadding="0" cellspacing="0">
+<!-- <tr><td colspan='2'>Queues</td></tr> -->
+<tr><th>ID</th><th>Queue Name</th><th>Queue Email</th><td></td></tr>
+<?php 
+$rowstyle[0] = 'rowstyle0';
+$rowstyle[1] = 'rowstyle1';
+$rs = 0;
+foreach ($queues as $queue) { 
+if ($rs == 1) { $rs = 0; } else { $rs = 1; }
+?>
+<form method='post' name='ifrm' action=''>
+<tr>
+<td width="10%" class='<?php echo $rowstyle[$rs]; ?>' align="center"><?php echo $queue['queue_id']; ?>
+	<input type="hidden" name="queue_id" value="<?php echo $queue['queue_id']; ?>"/>
+</td>
+<td width="20%" class='<?php echo $rowstyle[$rs]; ?>' align='left' nowrap='nowrap'> 
+	<input class='formfld' style="width:100%" type="text" name="queue_name" value="<?php echo $queue['queue_name']; ?>"/>
+</td> 
+<td width="70%" class='<?php echo $rowstyle[$rs]; ?>' align='left'> 
+	<input class='formfld' style="width:100%" type="text" name="queue_email" value="<?php echo $queue['queue_email']; ?>"/>
+</td>
+<td align='left' nowrap='nowrap'>
+	<input type="submit" value="update">
+</td>
+</tr> 
+</form>
+<?php } 
+if ($rs == 1) { $rs = 0; } else { $rs = 1; }
+?>
+<form method='post' name='ifrm' action=''>
+<tr>
+<td width="10%" class='<?php echo $rowstyle[$rs]; ?>' align="center" nowrap='nowrap'>
+</td>
+<td width="20%" class='<?php echo $rowstyle[$rs]; ?>' align='left' nowrap='nowrap'> 
+	<input class='formfld' style="width:100%" type="text" name="queue_name" />
+</td> 
+<td width="70%" class='<?php echo $rowstyle[$rs]; ?>' align='left'> 
+	<input class='formfld' style="width:100%" type="text" name="queue_email" />
+</td>
+<td align='left' nowrap='nowrap'>
+	<input type="submit" value="Add">
+</td>
+</tr> 
+</form>
+	</table>
+	</td>
+	</td>
+	<td width="6%">
+
+	</td>
+	<td width="47%" valign="top">
+		<table width='100%' border="0" cellpadding="0" cellspacing="0">
+<!-- <tr><th colspan='2'>Statuses</th></tr> -->
+<tr><th>Status ID</th><th>Status Name</th><td></td></tr>
+<?php 
+foreach ($statuses as $status) { 
+if ($rs == 1) { $rs = 0; } else { $rs = 1; }
+?>
+<form method='post' name='ifrm' action=''>
+<tr> 
+<td class='<?php echo $rowstyle[$rs]; ?>' align='left' nowrap='nowrap' width="20%"> 
+	<input type="hidden" name="status_id" value="<?php echo $status['status_id']; ?>"/>
+	<?php echo $status['status_id']; ?>
+</td> 
+<td class='<?php echo $rowstyle[$rs]; ?>' align='left'> 
+	<input class='formfld' type="text" style="width:100%" name="status_name" value="<?php echo $status['status_name']; ?>"/>
+</td> 
+<td align='left' nowrap='nowrap'>
+	<input type="submit" value="update">
+</td>
+</tr>
+</form>
+<?php } 
+if ($rs == 1) { $rs = 0; } else { $rs = 1; }
+?>
+<form method='post' name='ifrm' action=''>
+<tr> 
+<td class='<?php echo $rowstyle[$rs]; ?>' align='left' nowrap='nowrap' width="20%"> 
+</td> 
+<td class='<?php echo $rowstyle[$rs]; ?>' align='left'> 
+	<input class='formfld' type="text" style="width:100%" name="status_name"/>
+</td> 
+<td align='left' nowrap='nowrap'>
+	<input type="submit" value="Add">
+</td>
+</tr>
+</form>
+		</table>
+	</td>
+	</table>
+	</td>
+</table></form>	</td>	</tr></table></div>

+ 198 - 0
tickets/ticket_update.php

@@ -0,0 +1,198 @@
+<div align='center'>
+<table width='100%' border='0' cellpadding='0' cellspacing='2'>
+
+<tr class='border'>
+  <td align=\"left\">
+      <br>
+
+<form method='post' name='ifrm' action=''>
+
+<div align='center'> 
+<table width='100%'  border='0' cellpadding='6' cellspacing='0'> 
+<tr> 
+<td colspan='2'> 
+<table width="100%" border="0" cellpadding="0" cellspacing="0"> 
+	<tr> 
+		<td align='left' width="50%"> 
+			<strong>Update Ticket</strong><br> 
+		</td>		
+		<td width='50%' align='right'> 
+			<input type='submit' name='submit' class='btn' value='Save'> 
+			<input type='button' class='btn' name='' alt='back' onclick="window.location='v_tickets.php'" value='Back'> 
+		</td> 
+	</tr>
+</table> 
+</td> 
+</tr> 
+<tr>
+	<td colspan="2">
+		<table width='100%' border="0" cellpadding="0" cellspacing="0">
+		<tr><td width="47%" valign="top">
+			<table width='100%' border="0" cellpadding="0" cellspacing="0">
+<tr><th colspan='2'>Ticket Info</th></tr>
+<tr> 
+<td width="30%" class='vncell' valign='top' align='left' nowrap='nowrap'> 
+	Subject: 
+</td> 
+<td width="70%" class='vtable' align='left'> 
+	<?php echo $ticket_header['subject']; ?>
+</td> 
+</tr> 
+<tr> 
+<td class='vncell' valign='top' align='left' nowrap='nowrap'> 
+	Requestor: 
+</td> 
+<td class='vtable' align='left'> 
+	<?php echo $ticket_header['username']; ?>
+</td> 
+</tr> 
+<tr> 
+<td class='vncell' valign='top' align='left' nowrap='nowrap'> 
+	Created: 
+</td> 
+<td class='vtable' align='left'> 
+	<?php echo $ticket_header['create_stamp']; ?> by <?php echo $ticket_header['create_username']; ?>
+</td> 
+</tr> 
+<tr> 
+<td class='vncell' valign='top' align='left' nowrap='nowrap'> 
+	Last Update: 
+</td> 
+<td class='vtable' align='left'> 
+	<?php echo $ticket_header['last_update_stamp']; ?> by <?php echo $ticket_header['last_update_username']; ?>
+</td> 
+</tr> 
+<tr> 
+<td class='vncell' valign='top' align='left' nowrap='nowrap'> 
+	Ticket Number: 
+</td> 
+<td class='vtable' align='left'> 
+	<?php echo $ticket_header['ticket_number']; ?>
+</td> 
+</tr> 
+<tr> 
+<td class='vncell' valign='top' align='left' nowrap='nowrap'> 
+	Customer Ticket Number: 
+</td> 
+<td class='vtable' align='left'> 
+	<input class='formfld' type='text' name='customer_ticket_number' maxlength='255' value="<?php echo $ticket_header['customer_ticket_number']; ?>">
+</td> 
+</tr> 
+	</table>
+	</td>
+	</td>
+	<td width="6%">
+
+	</td>
+	<td width="47%" valign="top">
+		<table width='100%' border="0" cellpadding="0" cellspacing="0">
+<tr><th colspan='2'>Ticket Status</th></tr>
+<?php if ($isadmin) { ?>
+<tr> 
+<td class='vncell' valign='top' align='left' nowrap='nowrap'> 
+	Ticket Owner: 
+</td> 
+<td class='vtable' align='left'> 
+	<select name="ticket_owner">
+		<option value=''>--</option>
+		<?php foreach ($queue_members as $qm) {
+			echo "<option value='" . $qm['user_id'] . "' ";
+			if ($qm['user_id'] == $ticket_header['ticket_owner']) echo "selected='selected'";
+			echo ">" . $qm['username'] . "</option>\n";
+		}
+		?>
+	</select>
+</td> 
+</tr> 
+<?php } ?>
+<tr> 
+<td class='vncell' valign='top' align='left' nowrap='nowrap'> 
+	Ticket status: 
+</td> 
+<td class='vtable' align='left'> 
+	<?php if ($isadmin) { ?>
+	<select name="ticket_status">
+		<?php foreach ($ticket_statuses as $ts) {
+			echo "<option value='" . $ts['status_id'] . "' ";
+			if ($ts['status_id'] == $ticket_header['ticket_status']) echo "selected='selected'";
+			echo ">" . $ts['status_name'] . "</option>\n";
+		}
+		?>
+	</select>
+	<?php } else { 
+		foreach($ticket_statuses as $ts) {
+			if ($ts['status_id'] == $ticket_header['ticket_status']) echo $ts['status_name'];
+		}
+	      } ?>
+</td> 
+</tr> 
+<tr> 
+<td class='vncell' valign='top' align='left' nowrap='nowrap'> 
+	Ticket Queue: 
+</td> 
+<td class='vtable' align='left'>
+	<?php if ($isadmin) { ?>
+	<select name="queue_id">
+		<?php foreach ($ticket_queues as $tq) {
+			echo "<option value='" . $tq['queue_id'] . "' ";
+			if ($tq['queue_id'] == $ticket_header['queue_id']) echo "selected='selected'";
+			echo ">" . $tq['queue_name'] . "</option>\n";
+		}
+		?>
+	</select>
+	<?php } else {
+		foreach ($ticket_queues as $tq) {
+			if ($tq['queue_id'] == $ticket_header['queue_id']) echo $tq['queue_name'];
+		}
+	} ?>
+</td> 
+</tr> 
+		</table>
+	</td>
+	</table>
+	</td>
+</tr>
+	<tr> 
+		<td colspan='2' align='right'> 
+				<input type='hidden' name='id' value='<?php echo $ticket_header['ticket_id']; ?>'/> 
+				<input type='submit' name='submit' class='btn' value='Save'/> 
+		</td> 
+	</tr>
+<tr><td colspan='2'><table width='100%' border="0" cellpadding="0" cellspacing="0">
+	<tr><th colspan='2'>Ticket Notes</th></tr>
+	<tr>
+	<td width="30%" class='rowstyle0' valign='top' align='left' nowrap='nowrap'>
+			<input type="checkbox" name="alert_user" value="1"/>Alert User<br>
+			Attach File<br />
+			<input type="file" name="file" id="file" />
+	</td>
+	<td class='rowstyle0' align='left'>
+		<textarea rows='5' cols='80' class='formfld' type='text' name='new_note'></textarea>
+	</td>
+	</tr>
+	<?php 
+$rowstyle[0] = 'rowstyle0';
+$rowstyle[1] = 'rowstyle1';
+$rs = 0;
+foreach($ticket_notes as $tn) { 
+if ($rs == 1) { $rs = 0; } else { $rs = 1; }
+?>
+	<tr>
+		<td width="30%" class="<?php echo $rowstyle[$rs]; ?>" valign='top' align='left' nowrap='nowrap'>
+			Updated: <?php echo $tn['create_stamp']; ?><br/>By: <?php echo $ticket_header['username']; ?>
+			<?php if (strlen($tn['file_pointer']) > 1) echo "<br>File Attachment: " . $tn['file_pointer']; ?>
+		</td>
+		<td class="<?php echo $rowstyle[$rs]; ?>" align='left'>
+			<?php echo base64_decode($tn['ticket_note']); ?>
+		</td>
+	</tr>
+	<?php }?>
+</table></td></tr>
+	<tr> 
+		<td colspan='2' align='right'> 
+				<input type='hidden' name='id' value='<?php echo $ticket_header['ticket_id']; ?>'/>
+				<input type='submit' name='submit' class='btn' value='Save'/> 
+		</td> 
+	</tr>
+</table></form>	</td>	</tr></table></div>
+

+ 11 - 0
tickets/update_complete.php

@@ -0,0 +1,11 @@
+<meta http-equiv="refresh" content="2;url=v_tickets.php">
+<div align='center'>
+<?php 
+if ($action == "add") {
+	echo "Create Complete\n";
+}
+if ($action == "update") {
+	echo "Update Complete\n";
+}
+?>
+</div>

+ 231 - 0
tickets/v_config.php

@@ -0,0 +1,231 @@
+<?php
+	//application details
+		$apps[$x]['name'] = "Ticket Tracker";
+		$apps[$x]['guid'] = '375715DC-F852-4A7B-B5C4-32FF163B3953';
+		$apps[$x]['category'] = '';
+		$apps[$x]['subcategory'] = '';
+		$apps[$x]['version'] = '';
+		$apps[$x]['license'] = 'Mozilla Public License 1.1';
+		$apps[$x]['url'] = 'http://www.fusionpbx.com';
+		$apps[$x]['description']['en'] = 'Simple Ticket Tracking System';
+
+	//menu details
+		$apps[$x]['menu'][0]['title']['en'] = 'Ticket Tracker';
+		$apps[$x]['menu'][0]['guid'] = '77048E9F-B946-AD35-5D6B-7838DD9EA81E';
+		$apps[$x]['menu'][0]['parent_guid'] = '';
+		$apps[$x]['menu'][0]['category'] = 'internal';
+		$apps[$x]['menu'][0]['path'] = '/mod/tickets/v_tickets.php';
+		//$apps[$x]['menu'][0]['groups'][] = 'user';
+		//$apps[$x]['menu'][0]['groups'][] = 'admin';
+		//$apps[$x]['menu'][0]['groups'][] = 'superadmin';
+
+		$apps[$x]['menu'][1]['title']['en'] = 'My Tickets';
+		$apps[$x]['menu'][1]['guid'] = '5BFA588D-5880-5A9D-206E-C876403D9161';
+		$apps[$x]['menu'][1]['parent_guid'] = '77048E9F-B946-AD35-5D6B-7838DD9EA81E';
+		$apps[$x]['menu'][1]['category'] = 'internal';
+		$apps[$x]['menu'][1]['path'] = '/mod/tickets/v_tickets.php';
+		$apps[$x]['menu'][1]['groups'][] = 'user';
+		$apps[$x]['menu'][1]['groups'][] = 'admin';
+		$apps[$x]['menu'][1]['groups'][] = 'superadmin';
+
+		$apps[$x]['menu'][2]['title']['en'] = 'Create Ticket';
+		$apps[$x]['menu'][2]['guid'] = '87A8F1E7-CF47-29DB-8A5F-46318E119D67';
+		$apps[$x]['menu'][2]['parent_guid'] = '77048E9F-B946-AD35-5D6B-7838DD9EA81E';
+		$apps[$x]['menu'][2]['category'] = 'internal';
+		$apps[$x]['menu'][2]['path'] = '/mod/tickets/v_ticket_create.php';
+		$apps[$x]['menu'][2]['groups'][] = 'user';
+		$apps[$x]['menu'][2]['groups'][] = 'admin';
+		$apps[$x]['menu'][2]['groups'][] = 'superadmin';
+
+		$apps[$x]['menu'][3]['title']['en'] = 'Ticket System Manager';
+		$apps[$x]['menu'][3]['guid'] = 'A4F3B307-BD62-1D04-E3AD-43DA091FA2F8';
+		$apps[$x]['menu'][3]['parent_guid'] = '77048E9F-B946-AD35-5D6B-7838DD9EA81E';
+		$apps[$x]['menu'][3]['category'] = 'internal';
+		$apps[$x]['menu'][3]['path'] = '/mod/tickets/v_manager.php';
+		$apps[$x]['menu'][3]['groups'][] = 'admin';
+		$apps[$x]['menu'][3]['groups'][] = 'superadmin';
+
+	//permission details
+		$apps[$x]['permissions'][0]['name'] = 'ticket_view';
+		$apps[$x]['permissions'][0]['groups'][] = 'user';
+		$apps[$x]['permissions'][0]['groups'][] = 'admin';
+		$apps[$x]['permissions'][0]['groups'][] = 'superadmin';
+
+		$apps[$x]['permissions'][1]['name'] = 'ticket_add';
+		$apps[$x]['permissions'][1]['groups'][] = 'user';
+		$apps[$x]['permissions'][1]['groups'][] = 'admin';
+		$apps[$x]['permissions'][1]['groups'][] = 'superadmin';
+
+		$apps[$x]['permissions'][2]['name'] = 'ticket_update';
+		$apps[$x]['permissions'][2]['groups'][] = 'user';
+		$apps[$x]['permissions'][2]['groups'][] = 'admin';
+		$apps[$x]['permissions'][2]['groups'][] = 'superadmin';
+
+		$apps[$x]['permissions'][3]['name'] = 'ticket_delete';
+		$apps[$x]['permissions'][3]['groups'][] = 'superadmin';
+
+		$apps[$x]['permissions'][4]['name'] = 'ticket_assign_queue';
+		$apps[$x]['permissions'][4]['groups'][] = 'admin';
+		$apps[$x]['permissions'][4]['groups'][] = 'superadmin';
+	
+		$apps[$x]['permissions'][5]['name'] = 'ticket_config';
+		$apps[$x]['permissions'][5]['groups'][] = 'admin';
+		$apps[$x]['permissions'][5]['groups'][] = 'superadmin';
+	
+		$apps[$x]['permissions'][6]['name'] = 'ticket_queue_view';
+		$apps[$x]['permissions'][6]['groups'][] = 'admin';
+		$apps[$x]['permissions'][6]['groups'][] = 'superadmin';
+
+		$apps[$x]['permissions'][7]['name'] = 'ticket_queue_add';
+		$apps[$x]['permissions'][7]['groups'][] = 'admin';
+		$apps[$x]['permissions'][7]['groups'][] = 'superadmin';
+
+		$apps[$x]['permissions'][8]['name'] = 'ticket_queue_update';
+		$apps[$x]['permissions'][8]['groups'][] = 'admin';
+		$apps[$x]['permissions'][8]['groups'][] = 'superadmin';
+
+		$apps[$x]['permissions'][9]['name'] = 'ticket_queue_delete';
+		$apps[$x]['permissions'][9]['groups'][] = 'admin';
+		$apps[$x]['permissions'][9]['groups'][] = 'superadmin';
+	
+	// CREATE TABLE v_ticket_notes 
+		$apps[$x]['db'][0]['table'] = 'v_ticket_notes';
+		$apps[$x]['db'][0]['fields'][0]['name'] = 'note_id';
+		$apps[$x]['db'][0]['fields'][0]['type']['pgsql'] = 'serial';
+		$apps[$x]['db'][0]['fields'][0]['type']['sqlite'] = 'integer PRIMARY KEY';
+		$apps[$x]['db'][0]['fields'][0]['type']['mysql'] = 'INT NOT NULL AUTO_INCREMENT PRIMARY KEY';
+		$apps[$x]['db'][0]['fields'][0]['description'] = '';
+		$apps[$x]['db'][0]['fields'][1]['name'] = 'ticket_id';
+		$apps[$x]['db'][0]['fields'][1]['type'] = 'integer';
+		$apps[$x]['db'][0]['fields'][1]['description'] = '';
+		$apps[$x]['db'][0]['fields'][2]['name'] = 'create_stamp';
+		$apps[$x]['db'][0]['fields'][2]['type']['pgsql'] = 'timestamp with time zone';
+		$apps[$x]['db'][0]['fields'][2]['type']['sqlite'] = 'datetime';
+		$apps[$x]['db'][0]['fields'][2]['type']['mysql'] = 'timestamp';
+		$apps[$x]['db'][0]['fields'][2]['description'] = '';
+		$apps[$x]['db'][0]['fields'][3]['name'] = 'create_user_id';
+		$apps[$x]['db'][0]['fields'][3]['type'] = 'integer';
+		$apps[$x]['db'][0]['fields'][3]['description'] = '';
+		$apps[$x]['db'][0]['fields'][4]['name'] = 'ticket_note';
+		$apps[$x]['db'][0]['fields'][4]['type'] = 'text';
+		$apps[$x]['db'][0]['fields'][4]['description'] = '';
+		$apps[$x]['db'][0]['fields'][5]['name'] = 'file_pointer';
+		$apps[$x]['db'][0]['fields'][5]['type']['pgsql'] = 'character varying';
+		$apps[$x]['db'][0]['fields'][5]['type']['sqlite'] = 'text';
+		$apps[$x]['db'][0]['fields'][5]['type']['mysql'] = 'text';
+		$apps[$x]['db'][0]['fields'][5]['description'] = '';
+
+	// CREATE TABLE v_ticket_queue_members 
+		$apps[$x]['db'][1]['table'] = 'v_ticket_queue_members';
+		$apps[$x]['db'][1]['fields'][0]['name'] = 'queue_member_id';
+		$apps[$x]['db'][1]['fields'][0]['type']['pgsql'] = 'serial';
+		$apps[$x]['db'][1]['fields'][0]['type']['sqlite'] = 'integer PRIMARY KEY';
+		$apps[$x]['db'][1]['fields'][0]['type']['mysql'] = 'INT NOT NULL AUTO_INCREMENT PRIMARY KEY';
+		$apps[$x]['db'][1]['fields'][0]['description'] = '';
+		$apps[$x]['db'][1]['fields'][1]['name'] = 'queue_id';
+		$apps[$x]['db'][1]['fields'][1]['type'] = 'integer';
+		$apps[$x]['db'][1]['fields'][1]['description'] = '';
+		$apps[$x]['db'][1]['fields'][2]['name'] = 'user_id';
+		$apps[$x]['db'][1]['fields'][2]['type'] = 'integer';
+		$apps[$x]['db'][1]['fields'][2]['description'] = '';
+
+	// CREATE TABLE v_ticket_queues 
+		$apps[$x]['db'][2]['table'] = 'v_ticket_queues';
+		$apps[$x]['db'][2]['fields'][0]['name'] = 'queue_id';
+		$apps[$x]['db'][2]['fields'][0]['type']['pgsql'] = 'serial';
+		$apps[$x]['db'][2]['fields'][0]['type']['sqlite'] = 'integer PRIMARY KEY';
+		$apps[$x]['db'][2]['fields'][0]['type']['mysql'] = 'INT NOT NULL AUTO_INCREMENT PRIMARY KEY';
+		$apps[$x]['db'][2]['fields'][0]['description'] = '';
+		$apps[$x]['db'][2]['fields'][1]['name'] = 'queue_name';
+		$apps[$x]['db'][2]['fields'][1]['type']['pgsql'] = 'character varying';
+		$apps[$x]['db'][2]['fields'][1]['type']['sqlite'] = 'text';
+		$apps[$x]['db'][2]['fields'][1]['type']['mysql'] = 'text';
+		$apps[$x]['db'][2]['fields'][1]['description'] = '';
+		$apps[$x]['db'][2]['fields'][2]['name'] = 'queue_email';
+		$apps[$x]['db'][2]['fields'][2]['type']['pgsql'] = 'character varying';
+		$apps[$x]['db'][2]['fields'][2]['type']['sqlite'] = 'text';
+		$apps[$x]['db'][2]['fields'][2]['type']['mysql'] = 'text';
+		$apps[$x]['db'][2]['fields'][2]['description'] = '';
+		$apps[$x]['db'][2]['fields'][3]['name'] = 'v_id';
+		$apps[$x]['db'][2]['fields'][3]['type'] = 'integer';
+		$apps[$x]['db'][2]['fields'][3]['description'] = '';
+
+	// CREATE TABLE v_ticket_statuses 
+		$apps[$x]['db'][3]['table'] = 'v_ticket_statuses';
+		$apps[$x]['db'][3]['fields'][0]['name'] = 'status_id';
+		$apps[$x]['db'][3]['fields'][0]['type']['pgsql'] = 'serial';
+		$apps[$x]['db'][3]['fields'][0]['type']['sqlite'] = 'integer PRIMARY KEY';
+		$apps[$x]['db'][3]['fields'][0]['type']['mysql'] = 'INT NOT NULL AUTO_INCREMENT PRIMARY KEY';
+		$apps[$x]['db'][3]['fields'][0]['description'] = '';
+		$apps[$x]['db'][3]['fields'][1]['name'] = 'status_name';
+		$apps[$x]['db'][3]['fields'][1]['type']['pgsql'] = 'character varying';
+		$apps[$x]['db'][3]['fields'][1]['type']['sqlite'] = 'text';
+		$apps[$x]['db'][3]['fields'][1]['type']['mysql'] = 'text';
+		$apps[$x]['db'][3]['fields'][1]['description'] = '';
+		$apps[$x]['db'][3]['fields'][2]['name'] = 'v_id';
+		$apps[$x]['db'][3]['fields'][2]['type'] = 'integer';
+		$apps[$x]['db'][3]['fields'][2]['description'] = '';
+
+	// CREATE TABLE v_tickets 
+		$apps[$x]['db'][4]['table'] = 'v_tickets';
+		$apps[$x]['db'][4]['fields'][0]['name'] = 'ticket_id';
+		$apps[$x]['db'][4]['fields'][0]['type']['pgsql'] = 'serial';
+		$apps[$x]['db'][4]['fields'][0]['type']['sqlite'] = 'integer PRIMARY KEY';
+		$apps[$x]['db'][4]['fields'][0]['type']['mysql'] = 'INT NOT NULL AUTO_INCREMENT PRIMARY KEY';
+		$apps[$x]['db'][4]['fields'][0]['description'] = '';
+		$apps[$x]['db'][4]['fields'][1]['name'] = 'queue_id';
+		$apps[$x]['db'][4]['fields'][1]['type'] = 'integer';
+		$apps[$x]['db'][4]['fields'][1]['description'] = '';
+		$apps[$x]['db'][4]['fields'][2]['name'] = 'v_id';
+		$apps[$x]['db'][4]['fields'][2]['type'] = 'integer';
+		$apps[$x]['db'][4]['fields'][2]['description'] = '';
+		$apps[$x]['db'][4]['fields'][3]['name'] = 'user_id';
+		$apps[$x]['db'][4]['fields'][3]['type'] = 'integer';
+		$apps[$x]['db'][4]['fields'][3]['description'] = '';
+		$apps[$x]['db'][4]['fields'][4]['name'] = 'customer_id';
+		$apps[$x]['db'][4]['fields'][4]['type'] = 'integer';
+		$apps[$x]['db'][4]['fields'][4]['description'] = '';
+		$apps[$x]['db'][4]['fields'][5]['name'] = 'subject';
+		$apps[$x]['db'][4]['fields'][5]['type']['pgsql'] = 'character varying';
+		$apps[$x]['db'][4]['fields'][5]['type']['sqlite'] = 'text';
+		$apps[$x]['db'][4]['fields'][5]['type']['mysql'] = 'text';
+		$apps[$x]['db'][4]['fields'][5]['description'] = '';
+		$apps[$x]['db'][4]['fields'][6]['name'] = 'create_stamp';
+		$apps[$x]['db'][4]['fields'][6]['type']['pgsql'] = 'timestamp with time zone';
+		$apps[$x]['db'][4]['fields'][6]['type']['sqlite'] = 'datetime';
+		$apps[$x]['db'][4]['fields'][6]['type']['mysql'] = 'timestamp';
+		$apps[$x]['db'][4]['fields'][6]['description'] = '';
+		$apps[$x]['db'][4]['fields'][7]['name'] = 'create_user_id';
+		$apps[$x]['db'][4]['fields'][7]['type'] = 'integer';
+		$apps[$x]['db'][4]['fields'][7]['description'] = '';
+		$apps[$x]['db'][4]['fields'][8]['name'] = 'ticket_status';
+		$apps[$x]['db'][4]['fields'][8]['type'] = 'integer';
+		$apps[$x]['db'][4]['fields'][8]['description'] = '';
+		$apps[$x]['db'][4]['fields'][9]['name'] = 'last_update_stamp';
+		$apps[$x]['db'][4]['fields'][9]['type']['pgsql'] = 'timestamp with time zone';
+		$apps[$x]['db'][4]['fields'][9]['type']['sqlite'] = 'datetime';
+		$apps[$x]['db'][4]['fields'][9]['type']['mysql'] = 'timestamp';
+		$apps[$x]['db'][4]['fields'][9]['description'] = '';
+		$apps[$x]['db'][4]['fields'][10]['name'] = 'last_update_user_id';
+		$apps[$x]['db'][4]['fields'][10]['type'] = 'integer';
+		$apps[$x]['db'][4]['fields'][10]['description'] = '';
+		$apps[$x]['db'][4]['fields'][11]['name'] = 'ticket_uuid';
+		$apps[$x]['db'][4]['fields'][11]['type']['pgsql'] = 'character varying';
+		$apps[$x]['db'][4]['fields'][11]['type']['sqlite'] = 'text';
+		$apps[$x]['db'][4]['fields'][11]['type']['mysql'] = 'text';
+		$apps[$x]['db'][4]['fields'][11]['description'] = '';
+		$apps[$x]['db'][4]['fields'][12]['name'] = 'ticket_number';
+		$apps[$x]['db'][4]['fields'][12]['type']['pgsql'] = 'character varying';
+		$apps[$x]['db'][4]['fields'][12]['type']['sqlite'] = 'text';
+		$apps[$x]['db'][4]['fields'][12]['type']['mysql'] = 'text';
+		$apps[$x]['db'][4]['fields'][12]['description'] = '';
+		$apps[$x]['db'][4]['fields'][13]['name'] = 'customer_ticket_number';
+		$apps[$x]['db'][4]['fields'][13]['type']['pgsql'] = 'character varying';
+		$apps[$x]['db'][4]['fields'][13]['type']['sqlite'] = 'text';
+		$apps[$x]['db'][4]['fields'][13]['type']['mysql'] = 'text';
+		$apps[$x]['db'][4]['fields'][13]['description'] = '';
+		$apps[$x]['db'][4]['fields'][14]['name'] = 'ticket_owner';
+		$apps[$x]['db'][4]['fields'][14]['type'] = 'integer';
+		$apps[$x]['db'][4]['fields'][14]['description'] = '';
+
+?>

+ 110 - 0
tickets/v_manager.php

@@ -0,0 +1,110 @@
+<?php
+/* $Id$ */
+/*
+	FusionPBX
+      	Version: MPL 1.1
+
+	The contents of this file are subject to the Mozilla Public License Version
+	1.1 (the "License"); you may not use this file except in compliance with
+	the License. You may obtain a copy of the License at
+	http://www.mozilla.org/MPL/
+
+	Software distributed under the License is distributed on an "AS IS" basis,
+	WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+	for the specific language governing rights and limitations under the
+	License.
+
+	The Original Code is FusionPBX
+
+	The Initial Developer of the Original Code is
+	Mark J Crane <[email protected]>
+	Portions created by the Initial Developer are Copyright (C) 2008-2010
+	the Initial Developer. All Rights Reserved.
+
+	Contributor(s):
+	Ken Rice     <[email protected]>
+	Mark J Crane <[email protected]>
+*/
+include "root.php";
+require_once "includes/config.php";
+require_once "includes/checkauth.php";
+if (permission_exists('xmpp_view')) {
+	//access granted
+}
+else {
+	echo "access denied";
+	exit;
+}
+require_once "includes/header.php";
+require_once "includes/paging.php";
+
+if (isset($_REQUEST)) {
+	foreach ($_REQUEST as $field => $data){
+        	$request[$field] = check_str($data);
+	}
+}
+
+$sql = "";
+if (isset($_REQUEST['queue_name'])) {
+	if (isset($_REQUEST['queue_id'])){
+		//do Queue Update
+		$sql .= "UPDATE v_ticket_queues SET ";
+		$sql .= "queue_name = '" . $request['queue_name'] . "', ";
+		$sql .= "queue_email = '" . $request['queue_email'] . "', ";
+		$sql .= "WHERE queue_id = " . $request['queue_id'] . " ";
+	} else {
+		//do Queue Create
+		$sql .= "INSERT into v_ticket_queues (queue_name, queue_email, v_id) values ";
+		$sql .= "('" . $request['queue_name'] . "', '" . $request['queue_email'] . "', $v_id) ";
+	}
+	$db->exec($sql);
+}
+
+if (isset($_REQUEST['status_name'])) {
+	if (isset($_REQUEST['status_id'])){
+		//do Status Update
+		$sql .= "UPDATE v_ticket_statuses SET ";
+		$sql .= "status_name = '" . $request['status_name'] . "' ";
+		$sql .= "WHERE status_id = " . $request['status_id'] . " ";
+	} else {
+		//do Status Create
+		$sql .= "INSERT into v_ticket_statuses (status_name, v_id) values ";
+		$sql .= "('" . $request['status_name'] . "', $v_id) ";
+	}
+	$db->exec($sql);
+}
+
+// Get a List of the Ticket Statuses
+$sql = "";
+$sql .= "select * from v_ticket_statuses ";
+$sql .= "where v_id = $v_id ";
+$sql .= "order by status_id ";
+$prepstatement = $db->prepare(check_sql($sql));
+$prepstatement->execute();
+$x = 0;
+$result = $prepstatement->fetchAll();
+foreach ($result as &$row) {
+	$statuses[$row['status_id']] = $row;
+}
+unset ($prepstatement);
+
+$sql = "";
+$sql .= "select * from v_ticket_queues ";
+$sql .= "where v_id = $v_id ";
+$sql .= "order by queue_id ";
+$prepstatement = $db->prepare(check_sql($sql));
+$prepstatement->execute();
+$x = 0;
+$result = $prepstatement->fetchAll();
+foreach ($result as &$row) {
+	$queues[$row['queue_id']] = $row;
+}
+unset ($prepstatement);
+
+//include the view
+include "ticket_manager.php";
+
+//include the footer
+require_once "includes/footer.php";
+
+?>

+ 97 - 0
tickets/v_profile_delete.php

@@ -0,0 +1,97 @@
+<?php
+/* $Id$ */
+/*
+	FusionPBX
+      	Version: MPL 1.1
+
+	The contents of this file are subject to the Mozilla Public License Version
+	1.1 (the "License"); you may not use this file except in compliance with
+	the License. You may obtain a copy of the License at
+	http://www.mozilla.org/MPL/
+
+	Software distributed under the License is distributed on an "AS IS" basis,
+	WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+	for the specific language governing rights and limitations under the
+	License.
+
+	The Original Code is FusionPBX
+
+	The Initial Developer of the Original Code is
+	Mark J Crane <[email protected]>
+	Portions created by the Initial Developer are Copyright (C) 2008-2010
+	the Initial Developer. All Rights Reserved.
+
+	Contributor(s):
+	Ken Rice <[email protected]>
+	Mark J Crane <[email protected]>
+*/
+include "root.php";
+require_once "includes/config.php";
+require_once "includes/checkauth.php";
+if (permission_exists('xmpp_delete')) {
+        //access granted
+}
+else {
+        echo "access denied";
+        exit;
+}
+
+require_once "includes/header.php";
+
+$v_domain = $_SESSION['domains'][$v_id]['domain'];
+
+$profile_id = $_REQUEST['id'];
+
+$sql = "";
+$sql .= "select * from v_xmpp ";
+$sql .= "where v_id = '$v_id' ";
+$sql .= "and xmpp_profile_id = '$profile_id' ";
+
+$prepstatement = $db->prepare(check_sql($sql));
+$prepstatement->execute();
+
+$x = 0;
+$result = $prepstatement->fetchAll();
+foreach ($result as &$row) {
+	$profiles_array[$x] = $row;
+	$x++;
+}
+
+$profile = $profiles_array[0];
+unset ($prepstatement);
+
+$sql = "";
+$sql .= "delete from v_xmpp ";
+$sql .= "where v_id = '$v_id' ";
+$sql .= "and xmpp_profile_id = '$profile_id' ";
+
+$db->exec(check_sql($sql));
+
+$filename = $v_conf_dir . "/jingle_profiles/" . "v_" . $v_domain . "_" . 
+	preg_replace("/[^A-Za-z0-9]/", "", $profile['profile_name']) . "_" . $profile_id . ".xml";
+
+unlink($filename);
+
+$fp = event_socket_create($_SESSION['event_socket_ip_address'], $_SESSION['event_socket_port'], $_SESSION['event_socket_password']);
+if ($fp) {
+	//reload the XML Configs
+	$tmp_cmd = 'api reloadxml';
+	$response = event_socket_request($fp, $tmp_cmd);
+	unset($tmp_cmd);
+
+	//Tell mod_dingaling to reload is config
+	$tmp_cmd = 'api dingaling reload';
+	$response = event_socket_request($fp, $tmp_cmd);
+	unset($tmp_cmd);
+
+	//close the connection
+	fclose($fp);
+}
+
+include "update_complete.php";
+
+end:
+//show the footer
+require_once "includes/footer.php";
+
+?>

+ 195 - 0
tickets/v_ticket_create.php

@@ -0,0 +1,195 @@
+<?php
+/* $Id$ */
+/*
+	FusionPBX
+      	Version: MPL 1.1
+
+	The contents of this file are subject to the Mozilla Public License Version
+	1.1 (the "License"); you may not use this file except in compliance with
+	the License. You may obtain a copy of the License at
+	http://www.mozilla.org/MPL/
+
+	Software distributed under the License is distributed on an "AS IS" basis,
+	WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+	for the specific language governing rights and limitations under the
+	License.
+
+	The Original Code is FusionPBX
+
+	The Initial Developer of the Original Code is
+	Mark J Crane <[email protected]>
+	Portions created by the Initial Developer are Copyright (C) 2008-2010
+	the Initial Developer. All Rights Reserved.
+
+	Contributor(s):
+	Ken Rice <[email protected]>
+	Mark J Crane <[email protected]>
+*/
+
+include "root.php";
+require_once "includes/config.php";
+require_once "includes/checkauth.php";
+
+if (permission_exists('ticket_add') || permission_exists('ticket_update')) {
+	//access granted
+}
+else {
+	echo "access denied";
+	exit;
+}
+
+require_once "includes/header.php";
+
+$v_domain = $_SESSION['domains'][$v_id]['domain'];
+
+//get a list of Available Queues
+$sql = "";
+$sql .= "select * from v_ticket_queues ";
+$sql .= "where v_id = '$v_id' ";
+$sql .= "order by queue_name ";
+$prepstatement = $db->prepare(check_sql($sql));
+$prepstatement->execute();
+$x = 0; 
+$result = $prepstatement->fetchAll();
+foreach ($result as &$row) { 
+        $queues[$x] = $row;
+        $x++;
+}
+unset ($prepstatement);
+
+//add or update the database
+if (isset($_REQUEST["id"])) {
+	$action = "update";
+	$profile_id = check_str($_REQUEST["id"]);
+} else {  
+	$action = "add";
+}
+
+
+if ($action == "update") {
+	// TODO: Check to see if Ticket Exists and user has access to that ticket then redirect to that ticket else Display Ticket Error
+
+}
+
+if ((!isset($_REQUEST['submit'])) || ($_REQUEST['submit'] != 'Save')) {
+	// If we arent saving a Profile Display the form.
+	include "ticket_create.php";	
+	goto end;
+}
+
+foreach ($_REQUEST as $field => $data){
+	$request[$field] = check_str($data);
+}
+
+// DataChecking Goes Here
+$error = "";
+if (strlen($request['subject']) < 1) $error .= "Ticket Subject is a Required Field<br />\n";
+if (strlen($request['problem_description']) < 1) $error .= "Ticket Body is a Required Field<br />\n";
+if (strlen($error) > 0) { 
+	include "errors.php";
+	$profile = $request;
+	include "profile_edit.php";	
+	goto end;
+}
+
+// Save New Entry
+if ($action == "add" && permission_exists('ticket_add')) {
+	$ticket_uuid = guid();
+	$sql = "";
+	$sql .= "insert into v_tickets (";
+ 	$sql .= "v_id, ";
+ 	$sql .= "queue_id, ";
+ 	$sql .= "user_id, ";
+ 	$sql .= "customer_id, ";
+ 	$sql .= "subject, ";
+ 	$sql .= "create_user_id, ";
+ 	$sql .= "create_stamp, ";
+ 	$sql .= "last_update_user_id, ";
+ 	$sql .= "last_update_stamp, ";
+ 	$sql .= "ticket_uuid, ";
+ 	$sql .= "ticket_status, ";
+ 	$sql .= "customer_ticket_number ";
+	$sql .= ") values (";
+ 	$sql .= "$v_id, ";
+ 	$sql .= "'" . $request['queue_id'] . "', ";
+ 	$sql .= "'" . $_SESSION['user_id'] . "', ";
+ 	$sql .= "'" . $_SESSION['customer_id'] . "', ";
+ 	$sql .= "'" . $request['subject'] . "', ";
+ 	$sql .= "'" . $_SESSION['user_id'] . "', ";
+ 	$sql .= "now(), ";
+ 	$sql .= "'" . $_SESSION['user_id'] . "', ";
+ 	$sql .= "now(), ";
+ 	$sql .= "'" . $ticket_uuid . "', ";
+ 	$sql .= "'1', ";
+ 	$sql .= "'" . $request['customer_ticket_number'] . "'";
+	$sql .= ") ";
+	if ($db_type == "pgsql") {
+	 	$sql .= "RETURNING ticket_id;";
+		$prepstatement = $db->prepare(check_sql($sql));
+		$prepstatement->execute();
+        	$result = $prepstatement->fetchAll();
+		$ticket_id = $result[0]['ticket_id'];
+	} elseif ($db_type == "sqlite" || $db_type == "mysql" ) {
+                $db->exec(check_sql($sql));
+		$ticket_id = $db->lastInsertId();
+	}
+
+	$ticket_number = date("ymd") . "-" . sprintf("%03d", substr($ticket_id, -3));
+	
+	$sql = "UPDATE v_tickets set ticket_number = '". $ticket_number. "' where ticket_id = " . $ticket_id . " ";
+	$db->exec(check_sql($sql));
+
+	$sql = "";
+	$sql .= "INSERT into v_ticket_notes (";
+	$sql .= "ticket_id, ";
+	$sql .= "create_user_id, ";
+	$sql .= "create_stamp, ";
+	$sql .= "ticket_note ";
+	$sql .= ") VALUES ( ";
+	$sql .= "$ticket_id, ";
+	$sql .= "'" . $_SESSION['user_id'] . "', ";
+	$sql .= "now(), ";
+	$sql .= "'" . base64_encode($request['problem_description']) . "' ";
+	$sql .= ") ";
+	$db->exec(check_sql($sql));
+	
+
+	$sql = "";
+	$sql .= "SELECT * from v_ticket_queues ";
+	$sql .= "where queue_id = " . $request['queue_id'] . " ";
+	$sql .= "and v_id = $v_id ";
+	$prepstatement = $db->prepare(check_sql($sql));
+	$prepstatement->execute();
+	$x = 0; 
+	$result = $prepstatement->fetchAll();
+	foreach ($result as &$row) { 
+        	$queue = $row;
+        	break;
+	}
+	
+	$subject = sprintf("[%s] New Ticket: %s", $queue['queue_name'], $request['subject']);
+	$to = $queue['queue_email'];
+	$message = "";
+	$message .= "Ticket Number $ticketnumber has been created by $username in " . $queue['queue_name'] . "\n";
+	$message .= "Ticket Link: http://" . $_SESSION['v_domain'] . PROJECT_PATH . "/mod/tickets/v_ticket_update.php?uuid=" . urlencode($ticket_uuid). "\n";
+	$message .= "Ticket body: \n";
+	$message .= $request['problem_description'] . "\n";
+	$from = "From: " . $_SESSION['support_email'];
+	mail($to, $subject, $message, $from);
+
+unset ($prepstatement);
+
+
+
+
+	goto writeout;
+
+} 
+writeout:
+include "update_complete.php";
+
+end:
+//show the footer
+require_once "includes/footer.php";
+
+?>

+ 267 - 0
tickets/v_ticket_update.php

@@ -0,0 +1,267 @@
+<?php
+/* $Id$ */
+/*
+	FusionPBX
+      	Version: MPL 1.1
+
+	The contents of this file are subject to the Mozilla Public License Version
+	1.1 (the "License"); you may not use this file except in compliance with
+	the License. You may obtain a copy of the License at
+	http://www.mozilla.org/MPL/
+
+	Software distributed under the License is distributed on an "AS IS" basis,
+	WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+	for the specific language governing rights and limitations under the
+	License.
+
+	The Original Code is FusionPBX
+
+	The Initial Developer of the Original Code is
+	Mark J Crane <[email protected]>
+	Portions created by the Initial Developer are Copyright (C) 2008-2010
+	the Initial Developer. All Rights Reserved.
+
+	Contributor(s):
+	Ken Rice <[email protected]>
+	Mark J Crane <[email protected]>
+*/
+
+include "root.php";
+require_once "includes/config.php";
+require_once "includes/checkauth.php";
+
+if (permission_exists('ticket_view') || permission_exists('ticket_update')) {
+	//access granted
+}
+else {
+	echo "access denied";
+	exit;
+}
+
+require_once "includes/header.php";
+
+$v_domain = $_SESSION['domains'][$v_id]['domain'];
+
+// Check to see if we're an admin and if we are set the $isadmin to true for use in the template and sql query building
+if (ifgroup("superadmin") || ifgroup("admin")){
+	$isadmin = true;
+}
+
+//add or update the database
+if (isset($_REQUEST['id']) || isset($_REQUEST['uuid'])) {
+	$action = "update";
+	if (isset($_REQUEST["id"])) { 
+		$ticket_id = check_str($_REQUEST["id"]);
+	}
+	if (isset($_REQUEST["uuid"])) { 
+		$ticket_uuid = check_str($_REQUEST["uuid"]);
+	}
+} else {  
+	$action = "add";
+	//Redirect back outta here probably
+}
+
+
+if ($action == "update") {
+
+//get the ticket
+	$sql = "";
+	$sql .= "select a.ticket_id, a.queue_id, a.v_id, a.user_id, a.customer_id, a.subject, ";
+	$sql .= "to_char(a.create_stamp, 'MM-DD-YY HH24-MI-SS') as create_stamp, a.create_user_id, ";
+	$sql .= "a.ticket_status, to_char(a.last_update_stamp, 'MM-DD-YY HH24-MI-SS') as last_update_stamp, ";
+	$sql .= "a.last_update_user_id, a.ticket_uuid, a.ticket_number, a.ticket_owner, a.customer_ticket_number, ";
+	$sql .= "b.username, c.username as create_username, d.username as last_update_username ";
+	$sql .= "from v_tickets as a, v_users as b, v_users as c, v_users as d ";
+	$sql .= "where a.user_id = b.id and a.create_user_id = c.id and a.last_update_user_id = d.id ";
+	$sql .= "and a.v_id = '$v_id' ";
+	if (isset($_REQUEST["id"])) { 
+		$sql .= "and a.ticket_id = '$ticket_id' ";
+	}
+	if (isset($_REQUEST["uuid"])) { 
+		$sql .= "and a.ticket_uuid = '$ticket_uuid' ";
+	}
+	if (!$isadmin) {
+		$sql .= "and a.user_id = " . $_SESSION['user_id'] . " ";
+	}
+
+	$prepstatement = $db->prepare(check_sql($sql));
+	$prepstatement->execute();
+	$x = 0;
+	$result = $prepstatement->fetchAll();
+	foreach ($result as &$row) {
+		$ticket_header = $row;
+		$x++;
+		break;
+	}
+	unset ($prepstatement);
+
+	if ($x < 1) {
+		include "bad_ticket_id.php";
+		goto end;
+	}
+	
+	$sql = "";
+	$sql .= "SELECT * from v_ticket_notes ";
+	$sql .= "where ticket_id = " . $ticket_header['ticket_id'] . " ";
+	$sql .= "order by create_stamp ";
+	$prepstatement = $db->prepare(check_sql($sql));
+	$prepstatement->execute();
+	$x = 0;
+	$result = $prepstatement->fetchAll();
+	foreach ($result as &$row) {
+		$ticket_notes[$x] = $row;
+		$x++;
+	}
+	unset ($prepstatement);
+
+	$sql = "";
+	$sql .= "select a.*, c.username from v_ticket_queue_members as a, v_users as c ";
+	$sql .= "where a.user_id = c.id ";
+	$sql .= "and a.queue_id = " . $ticket_header['queue_id'] . " ";
+
+	$prepstatement = $db->prepare(check_sql($sql));
+	$prepstatement->execute();
+	$x = 0;
+	$result = $prepstatement->fetchAll();
+	foreach ($result as &$row) {
+		$queue_members[$x] = $row;
+		$x++;
+	}
+	unset ($prepstatement);
+
+	$sql = "";
+	$sql .= "SELECT * from v_ticket_statuses ";
+	$sql .= "where v_id = $v_id ";
+	$sql .= "ORDER by status_id ";
+	$prepstatement = $db->prepare(check_sql($sql));
+	$prepstatement->execute();
+	$x = 0;
+	$result = $prepstatement->fetchAll();
+	foreach ($result as &$row) {
+		$ticket_statuses[$x] = $row;
+		$x++;
+	}
+	unset ($prepstatement);
+
+	$sql = "";
+	$sql .= "SELECT * from v_ticket_queues ";
+	$sql .= "where v_id = $v_id ";
+	$sql .= "ORDER by queue_name ";
+	$prepstatement = $db->prepare(check_sql($sql));
+	$prepstatement->execute();
+	$x = 0;
+	$result = $prepstatement->fetchAll();
+	foreach ($result as &$row) {
+		$ticket_queues[$x] = $row;
+		$x++;
+	}
+	unset ($prepstatement);
+} 
+
+if ((!isset($_REQUEST['submit'])) || ($_REQUEST['submit'] != 'Save')) {
+	// If we arent saving a Profile Display the form.
+	include "ticket_update.php";	
+	goto end;
+}
+
+foreach ($_REQUEST as $field => $data){
+	$request[$field] = check_str($data);
+}
+
+if ($action == "update" && permission_exists('ticket_update')) {
+	if (strlen($request['new_note']) > 0) {
+		$sql = "";
+		$sql .= "INSERT into v_ticket_notes (";
+		$sql .= "ticket_id, ";
+		$sql .= "create_stamp, ";
+		$sql .= "create_user_id, ";
+		$sql .= "ticket_note ";
+		$sql .= ") values ( ";
+		$sql .= $ticket_header['ticket_id'] . ", ";
+		$sql .= "now(), ";
+		$sql .= $_SESSION['user_id'] . ", ";
+		$sql .= "'" . base64_encode($request['new_note']) . "' ";
+		$sql .= ")";
+		$db->exec(check_sql($sql));
+		$note_added = true;
+	}
+
+	$sql = "";
+	$sql .= "UPDATE v_tickets set ";
+	if ($ticket_header['ticket_owner'] != $request['ticket_owner']) {
+		$sql .= "ticket_owner = " . $request['ticket_owner'] . ", ";
+		if ($_SESSION['user_id'] != $request['ticket_owner']) {
+			$alert_new_owner = true;
+		}
+	}
+	if ($ticket_header['ticket_status'] != $request['ticket_status']) {
+		$sql .= "ticket_status = " . $request['ticket_status'] . ", ";
+	}
+	if ($ticket_header['queue_id'] != $request['queue_id']) {
+		$sql .= "queue_id = " . $request['queue_id'] . ", ";
+	}
+	$sql .= "last_update_user_id = " . $_SESSION['user_id'] . ", ";
+	$sql .= "last_update_stamp = now() ";
+	$sql .= "where ticket_id = " . $ticket_header['ticket_id'] . " ";
+	$db->exec(check_sql($sql));
+
+	if ($note_added && $request['alert_user']) {
+		$sql = "select useremail from v_users where id = . " . $ticket_header['user_id'];
+	        $prepstatement = $db->prepare(check_sql($sql));
+		$prepstatement->execute();
+		$x = 0;
+		$result = $prepstatement->fetchAll();
+		foreach ($result as &$row) {
+			$useremail = $row['useremail'];
+			break;
+		}
+		unset ($prepstatement);
+
+		if (strlen($useremail) > 1) {
+			$subject = sprintf("[%s] Ticket %s Updated", $queue['queue_name'], $ticket_header['ticket_number']);
+			$to = $useremail;
+			$message = "";
+			$message .= "Ticket Number $ticketnumber has been update\n";
+			$message .= "Ticket Link: http://" . $_SESSION['v_domain'] . PROJECT_PATH . "/mod/tickets/v_ticket_update.php?uuid=" . urlencode($ticket_uuid). "\n";
+			$message .= "Ticket update: \n";
+			$message .= $request['new_notes'] . "\n";
+			$from = "From: " . $_SESSION['support_email'];
+			mail($to, $subject, $message, $from);
+		}
+	} 
+	
+	if ($alert_new_owner) {
+		$sql = "select useremail from v_users where id = . " . $request['ticket_owner'];
+	        $prepstatement = $db->prepare(check_sql($sql));
+		$prepstatement->execute();
+		$x = 0;
+		$result = $prepstatement->fetchAll();
+		foreach ($result as &$row) {
+			$useremail = $row['useremail'];
+			break;
+		}
+		unset ($prepstatement);
+
+		if (strlen($useremail) > 1) {
+			$subject = sprintf("[%s] Ticket %s Updated", $queue['queue_name'], $ticket_header['ticket_number']);
+			$to = $useremail;
+			$message = "";
+			$message .= "Ticket Number $ticketnumber has been update\n";
+			$message .= "Ticket Link: http://" . $_SESSION['v_domain'] . PROJECT_PATH . "/mod/tickets/v_ticket_update.php?uuid=" . urlencode($ticket_uuid). "\n";
+			$from = "From: " . $_SESSION['support_email'];
+			mail($to, $subject, $message, $from);
+		}
+		
+	}
+	
+	goto writeout;
+} 
+
+writeout:
+include "update_complete.php";
+
+end:
+//show the footer
+require_once "includes/footer.php";
+
+?>

+ 95 - 0
tickets/v_tickets.php

@@ -0,0 +1,95 @@
+<?php
+/* $Id$ */
+/*
+	FusionPBX
+      	Version: MPL 1.1
+
+	The contents of this file are subject to the Mozilla Public License Version
+	1.1 (the "License"); you may not use this file except in compliance with
+	the License. You may obtain a copy of the License at
+	http://www.mozilla.org/MPL/
+
+	Software distributed under the License is distributed on an "AS IS" basis,
+	WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+	for the specific language governing rights and limitations under the
+	License.
+
+	The Original Code is FusionPBX
+
+	The Initial Developer of the Original Code is
+	Mark J Crane <[email protected]>
+	Portions created by the Initial Developer are Copyright (C) 2008-2010
+	the Initial Developer. All Rights Reserved.
+
+	Contributor(s):
+	Ken Rice     <[email protected]>
+	Mark J Crane <[email protected]>
+*/
+include "root.php";
+require_once "includes/config.php";
+require_once "includes/checkauth.php";
+if (permission_exists('ticket_view')) {
+	//access granted
+}
+else {
+	echo "access denied";
+	exit;
+}
+require_once "includes/header.php";
+require_once "includes/paging.php";
+
+if (isset($_REQUEST['show_closed'])) { 
+	$show_closed = true; 
+}
+
+//get a list of assigned extensions for this user
+$sql = "";
+$sql .= "select * from v_tickets ";
+$sql .= "where v_id = '$v_id' ";
+if (!$show_closed) {
+	$sql .= "and ticket_status < 6 ";
+}
+if (!ifgroup("superadmin") && !ifgroup("admin")){
+	$sql .= "and user_id = " . $_SESSION['user_id'] . " ";
+}
+$sql .= "order by ticket_status, queue_id ";
+$prepstatement = $db->prepare(check_sql($sql));
+$prepstatement->execute();
+$x = 0;
+$result = $prepstatement->fetchAll();
+foreach ($result as &$row) {
+	$tickets[$x] = $row;
+	$x++;
+}
+unset ($prepstatement);
+
+$sql = "";
+$sql .= "select * from v_ticket_statuses ";
+$prepstatement = $db->prepare(check_sql($sql));
+$prepstatement->execute();
+$x = 0;
+$result = $prepstatement->fetchAll();
+foreach ($result as &$row) {
+	$statuses[$row['status_id']] = $row['status_name'];
+}
+unset ($prepstatement);
+
+$sql = "";
+$sql .= "select * from v_ticket_queues ";
+$sql .= "where v_id = $v_id ";
+$prepstatement = $db->prepare(check_sql($sql));
+$prepstatement->execute();
+$x = 0;
+$result = $prepstatement->fetchAll();
+foreach ($result as &$row) {
+	$queues[$row['queue_id']] = $row['queue_name'];
+}
+unset ($prepstatement);
+
+//include the view
+include "ticket_list.php";
+
+//include the footer
+require_once "includes/footer.php";
+
+?>