<h1><?php 
echo $page_title;?></h1>
<?php 
include("ClassRole.php");
if($_REQUEST['Save']!='')
{
	
	
	
  $fstatus=true;
	
 
 
  if($_REQUEST['ticket_title']=='')
  {
  	  $msgErr[]="Please Enter Title"	;
      $fstatus=false;
  }	
  
  
  if($_REQUEST['product_id']=='')
  {
  	  $msgErr[]="Please Enter Product Name"	;
      $fstatus=false;
  }
  if($_REQUEST['hours']=='')
{
$msgErr[]="Please Enter the Hours"	;
      $fstatus=false;
	
}
	 
   if($_REQUEST['groupid']=='')
  {
  	  $msgErr[]="Please Enter the Group Name"	;
      $fstatus=false;
  }
  if($_REQUEST['accountname']=='')
  {
  $msgErr[]="Please Enter the Account Name"	;
      $fstatus=false;
  	
  }
  
  
 
  
  
}





  
 
		
		
   
   if($_REQUEST['action']=='AddNew' && $fstatus)
   {
   	
	$data['ticket_no']  =$_REQUEST['ticket_no'];
		$data['groupname']  =$_REQUEST['groupname']; 
		$data['parent_id']  =$_REQUEST['parent_id'];
		$data['product_id']  =$_REQUEST['itemcode'];
		$data['priority']  =$_REQUEST['priority'];
		$data['severity']  =$_REQUEST['severity'];
		$data['status']  =$_REQUEST['status'];
		$data['category']  =$_REQUEST['category'];
		$data['ticket_title']  =$_REQUEST['ticket_title'];
		$data['hours']  =$_REQUEST['hours'];
		$data['days']  =$_REQUEST['days'];
		$data['accountid']  =$_REQUEST['accountid'];
		$data['terms_conditions']  =$_REQUEST['terms_conditions'];
		$data['purchaseorder']  =$_REQUEST['purchaseorder'];
		$data['mode_of_complaint']  =$_REQUEST['mode_of_complaint'];
		$data['CompanyId']  =$_SESSION['ACGCompanyId'];
		$data['created_by']=trim($_SESSION['UserID']);
		$data['groupid']=trim(implode(',',$_REQUEST['groupid']));
		$data['leaduserid']=trim(implode(',',$_REQUEST['leaduserid']));
		
	$s->RecordInsert('support_troubletickets', $data);
	prnMsg(_('Inserted Successfully'),'Success');
	 echo  "<script>location.href='index.php?route=Support/ListTroubleTicket&modid=".$_REQUEST['modid']."&frmid=".$_REQUEST['frmid']."'</script>";
	
	
	
   }

if($_REQUEST['action']=='Edit')
   {
		echo $sql="select * from support_troubletickets where ticketid='".$_REQUEST['ticketid']."' ";
 		$result=DB_query($sql,$db);
		$myrow=DB_fetch_array($result);
		$ticket_no=$myrow['ticket_no'];
		$groupname=$myrow['groupname']; 
		$parent_id=$myrow['parent_id'];
		$product_id=$myrow['product_id'];
		$priority=$myrow['priority'];
		$severity=$myrow['severity'];
		$status=$myrow['status'];
		$category=$myrow['category'];
		$ticket_title=$myrow['ticket_title'];
		$hours=$myrow['hours'];
		$days=$myrow['days'];
		$accountid=$myrow['accountid'];
		$terms_conditions=$myrow['terms_conditions'];
		$purchaseorder=$myrow['purchaseorder'];
		$mode_of_complaint=$myrow['mode_of_complaint'];
		$groupid=$myrow['groupid'];
		$leaduserid=$myrow['leaduserid'];
		
		
		
		}
if($_REQUEST['Save']!='' && $_REQUEST['action']=='Edit')
{

		$data1['priority']  =$_REQUEST['priority'];
		$data11['severity']  =$_REQUEST['severity'];
		$data1['status']  =$_REQUEST['status'];
		$data1['category']  =$_REQUEST['category'];
		
		$data1['hours']  =$_REQUEST['hours'];
		$data1['days']  =$_REQUEST['days'];
		
		
		
		
		
		
		
		$cond="ticketid='".$_REQUEST['ticketid']."'";
		$s->RecordEdit('support_troubletickets', $data1,$cond);
		prnMsg(_('Updated Successully'),'Success');
		 echo  "<script>location.href='index.php?route=Support/ListTroubleTicket&modid=".$_REQUEST['modid']."&frmid=".$_REQUEST['frmid']."'</script>";
		
		
		
		
		
		 
   }
   ?>
   <script type="text/javascript">
   
   function openPopupProfile(i)
{ 
		window.open("CrmSupportItems.php?rowcount="+i,"profiles_popup_window","height=425,width=640,toolbar=no,menubar=no,dependent=yes,resizable=yes");
}
function openPopupProfile1(i)
{ 
		window.open("CrmAccountNames.php?rowcount="+i,"profiles_popup_window1","height=425,width=640,toolbar=no,menubar=no,dependent=yes,resizable=yes");
}


   
   
   </script>

<form name="form1" method="post" action="">
<fieldset align="left">
  <legend><strong>TICKET INFORMATION:</strong></legend>
<table width="100%" border="0">
	<?php
	if(count($msgErr)>0)
	{?>
		<tr>
	<td colspan="4">
		<?php 
		for($i=0;$i<count($msgErr);$i++)
		{
		echo "<div class='error'>".$msgErr[$i]."</div>";	
		}?>
		</td>
		</tr>
		<?php
	}
	
	?>
	
	
	
	
	
  <tr>
    <td>Title</td><td> <input name="ticket_title" type="text" value="<?php  echo $ticket_title?>" size="50"></td> 
    <td>Product Name&nbsp;</td>
    
   <?php $ItemName=$s->getField('item_master','id',$product_id,'StockID');?>
    
	<td> <input name="product_id" id="product_id" type="text" value="<?php  echo $ItemName?>" readonly size="45">
		<input name="itemcode" type="hidden" id="itemcode">
		<?php if($_REQUEST['action']=='Edit')
		{
			
		}
		else
		{
			
		?>
		
		<input type="button" name="profile_popup" value="+" id="profile_popup"  onclick="openPopupProfile(this.id)" /> 
		
		<?php }?></td>
  </tr>
   <tr>
    <td> Priority </td><td> 
	<?php $priority1=array( 'Low','Normal','High','Urgent')?>
	<select name="priority"  style="width:150px;">
 	<?php for($k=0;$k<count($priority1);$k++)
	{?>
	<option value="<?php  echo $priority1[$k];?>" <?php  echo $priority==$priority1[$k]?'selected':''?> ><?php  echo $priority1[$k];?></option>
	<?php 
	}
	?>
	</select> 
	
	 </td>
    <td>Hours </td><td> <input name="hours" type="text" value="<?php  echo $hours?>" size="50"></td>
  </tr>
  <tr>
    <td> Severity </td><td> 
	<?php $severity1=array( 'Minor','Major','Featured','Critical')?>
	<select name="severity"  style="width:150px;">
 	<?php for($k=0;$k<count($severity1);$k++)
	{?>
	<option value="<?php  echo $severity1[$k];?>" <?php  echo $severity==$severity1[$k]?'selected':''?>><?php  echo $severity1[$k];?></option>
	<?php 
	}
	?>
	</select> 
	
	 </td>
    <td>Days </td><td> <input name="days" type="text" value="<?php  echo $days?>" size="50"></td>
  </tr>
  <tr>
  <td>Status</td><td> 
  <?php $status1=array( 'Open','In Progress','Wait For Responses','')?>
	<select name="status"  style="width:150px;">
 	<?php for($k=0;$k<count($status1);$k++)
	{?>
	<option value="<?php  echo $status1[$k];?>" <?php  echo $status==$status1[$k]?'selected':''?> ><?php  echo $status1[$k];?>  </option>
	<?php 
	}
	?>
	</select> </td>
    <td> Category </td><td> 
	<?php $category1=array( 'Big','Small','Other')?>
	<select name="category"  style="width:150px;">
 	<?php for($k=0;$k<count($category1);$k++)
	{?>
	<option value="<?php  echo $category1[$k];?>" <?php  echo $category==$category1[$k]?'selected':''?> ><?php  echo $category1[$k];?> Problem</option>
	<?php 
	}
	?>
	</select> 
	
	 </td>
  </tr>
  <tr>
  	<?php 
 	  $TicketSql=DB_query("Select MAX(ticketid) from support_troubletickets",$db);
	  $TicketRow=DB_fetch_array($TicketSql);
      $TicketId=$TicketRow['MAX(ticketid)'];
	  
      $TicketNo=$TicketId+1;
	  $TichetFinal='TIC-00'.$TicketNo;
	 
	 
	
  	?>
    <td>Ticket No	&nbsp;</td><td> <input name="ticket_no" type="text"  readonly="true" value="<?php  echo $TichetFinal?>" size="50"></td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  </table>
  
  </fieldset>
<fieldset align="left">
  <legend><strong>COMPLAINT DESCRIPTION:-</strong></legend>
<table width="100%" border="0">
  
  <tr>
    <td colspan="4"><strong>Description&nbsp;</strong> </td>
  </tr>
  <tr>
    <td  colspan="4"><textarea name="terms_conditions" cols="50" rows="2"><?php echo $terms_conditions?></textarea></td>
  </tr>
  
</table></fieldset>


<fieldset align="left">
  <legend ><strong>TICKET INFORMATION:</strong></legend>
  <table width="100%" border="0">
  	<?php
  	if($_REQUEST['action']=='Edit')
	{
		?>
		<tr>
	<td>Assigned To</td>
	<?php $GroupName=$s->getField('securityroles','secroleid',$groupid,'secrolename');?>
	<td width="24%"><input type="text" name="groupid1" value="<?php echo $GroupName ?>" readonly></td>	
		<?php $UserName=$s->getField('www_users','id',$leaduserid,'userid');?>
		<td width="26%">Users Name </td>	
		<td width="20%"><input type="text" name="leaduserid1" value="<?php echo $UserName ?>" readonly></td>
			<td>Account &nbsp;</td><td>
				
				<?php $AccountName=$s->getField('accountledger','AccountsID',$accountid,'AccountName');?>
				<input type="text" name="accountname" id="accountname" value="<?php  echo $AccountName?>"  readonly   size="50" >
				
				
				</td>
		</tr>
		
		<?php
		
	}
	else {
		
  	?>
  <tr>
  	
  <th>Assigned To	 <label><font color="#FF0000">*</font></label></th>
   <td width="20%"><?php echo $ClassRole->Role();?>	 </td>
    <th width="20%">Users Name <label><font color="#FF0000">*</font></label></th>
    <td width="20%">
	<div id='hid-Roleid'>
<?php  
 echo "<select name='leaduserid[]' style='width:150px;'>";
echo "<option value='000'>---</option>";
 echo "</select>";
	
?>	
	</div>
    </td>
   <th width="20%">Account</th>
   <td><input type="text" name="accountname" id="accountname" size="50">
	<input name="accountid" type="hidden" value="<?php  echo $accountid?>" id="accountid" readonly >
  	<input type="button"  name="accountname_popup" value="+" id="accountname_popup"  onclick="openPopupProfile1(this.id)" /> 
  </td>
  </tr>
  <?php }
	
	
	
			
	?>
  <tr>
    <td  colspan="4">
      <input type="submit" name="Save" value="Save">
  
    </td>
  </tr>
  
</table>
  
  
</fieldset>
  </form>