<link rel="stylesheet" href="css/new_mxerp.css">

<div class="body_contain">
<div class="tab_div">


<h1><?php  echo $page_title;?></h1>
 <?php  $table='crm_picklist_itemdata';
$action=$_REQUEST['action'];
$daction=$_REQUEST['daction'];
$msgErr='';
$status=true;
 $modid=$_REQUEST['modid'];
$frmid=$_REQUEST['frmid'];
$url="&modid=".$modid."&frmid=".$frmid;
$targetpage="index.php?route=".$_REQUEST['route'].$url;
if($_REQUEST['Save'])
{
	if(empty($_REQUEST['picklist_title']))
	{
	   $msgErr[]='Please Enter Title Name';
	   $status=false;
	}
	 
	 
	 	$condition="picklist_title='".$_REQUEST['picklist_title']."'";
		$allready=$s->GetRecord($table,  $condition);
		$row=DB_query($allready,$db);
		if(DB_num_rows($row)>0 && $action!='Edit')
		{
			 $msgErr[]='All Ready Exist';
			 $status=false;
		}
		
} 

//************************Delete*********************************************** 
if( $_REQUEST['enable']==1)
{
	
 
		$darr['status']='N';
		$darr['id']=$_REQUEST['id'];
 		 $condition="id='".$_REQUEST['id']."'";
	  	  $s->EditRecord($table, $data, $cond);
	     $s->pageLocation($targetpage.'daction=Deleted');
 }
 
  
//************************Edit*********************************************** 

if(!$_REQUEST['Save'] &&  $status && $action=='Edit')
{
	$condition="id='".$_REQUEST['id']."'";
	$allready=$s->GetRecord($table,  $condition);
	$Select=DB_query($allready,$db);
	$RData=DB_fetch_array($Select);		
	$mst_pl_subcatid=$RData['mst_pl_subcatid'];
	$mst_pl_catid=$RData['mst_pl_catid'];
	$picklist_title=$RData['picklist_title'];
	$status=$RData['status'];
 			 
}
 

if($_REQUEST['Save'] &&  $status && $action=='Edit')
{
	$data['picklist_title']=$_REQUEST['picklist_title'];
	$data['status']=$_REQUEST['status'];
	$data['mst_pl_catid']=$_REQUEST['mst_pl_catid'];
	$data['mst_pl_subcatid']=$_REQUEST['mst_pl_subcatid'];
	$cond="id='".$_REQUEST['id']."'";
 	$update= $s->EditRecord($table, $data, $cond);
	$row=DB_query($update,$db);
		if(!$row)
		{
		die('Error'.DB_error());
		}
  $s->pageLocation($targetpage.'&daction=Updated');
}
 
//************************INSERT*********************************************** 
if($_REQUEST['Save'] &&  $status && $action=='')
{
 $data['picklist_title']=$_REQUEST['picklist_title'];
 $data['mst_pl_catid']=$_REQUEST['mst_pl_catid'];
 $data['mst_pl_subcatid']=$_REQUEST['mst_pl_subcatid'];

   $data['status']=$_REQUEST['status'];
 	$insert= $s->insertRecord($table, $data);
	$row=DB_query($insert,$db);
	if(!$row)
	{
	   die('Error'.DB_error());
	}
 $s->pageLocation($targetpage.'&daction=Inserted');
}
?>


 <form action="" method="post">
<table width="100%" border="1" cellpadding="3" cellspacing="0" style="border-collapse:collapse; border:#666666 solid 1px;">
   
  <?php if(isset($daction))
  {?>
    <tr>
  
    <td colspan="4" ><div class="success">
	<?php 
	 if($_REQUEST['daction']!=1 && $_REQUEST['daction']!=2)
	 echo "Record ".$_REQUEST['daction']." Successfully";
	 elseif($_REQUEST['daction']==1)
	 	 echo "Can't Delete This Record because AccountName Attatch with LedgerDayBook table ";
	 elseif($_REQUEST['daction']==2)		 
		 echo "Can't Delete This Record. First Delete it's Parent Record   ";
		 ?>
	</div></td>
  </tr>
  <?php }
  if(isset($msgErr)&&$msgErr!='' )
   {?>
    <tr>
  
    <td colspan="4" ><div class="error"><?php 
for($kp=0;$kp<count($msgErr);$kp++)
 {
		echo  $msgErr[$kp].'<br>';
 }
  ?></div></td>
  </tr>
  
   <?php }?>
   
   
  <tr>
    <td class="tabledata">Select Picklist Item</td>
    <td>
	
	   <select name="mst_pl_catid" id="mst_pl_catid"  onChange="ShowDiv(this.value,'hiddiv','disp_picklist.php')" style="width:100%">	  
  <option value="000">----</option>
  <?php 
 	$sqlCate = "select * from  crm_picklist  where    parent_id   = 0";
	$rsCate  = DB_query($sqlCate,$db);
	if(DB_num_rows($rsCate)>0)
	{
		while($rowCate =DB_fetch_array($rsCate))
		{
 			$p='';
			if( $mst_pl_catid== $rowCate['picklist_id'])	 
			$p='selected';
		  ?>
		<option value="<?php echo $rowCate['picklist_id'];?>"  <?php  echo $p;?>> 
		<?php echo  $rowCate['picklist_title'] ;?></option>
 		<?php			
			 
		}
	}
?></select>
	
	 </td>

	 <td class="tabledata">PickList Item Category</td>
    <td> <div id='hiddiv'> 
	<?php //echo $mst_pl_subcatid;?>
   <select name="mst_pl_subcatid" id="mst_pl_subcatid"  style="width:100%">	

  <option value="000">----</option>
  <?php 
         $query=DB_query("select * from crm_picklist where parent_id='".$mst_pl_catid."'",$db);

 		  while($row=DB_fetch_array($query))
		  {
		  $k='';
		  if($mst_pl_subcatid==$row['picklist_id'])
		  {
		  $k="selected";	
		  }
 		  
		 ?>
		<option value="<?php echo $row['picklist_id'] ?>"<?php echo $k; ?> ><?php echo 	 $row['picklist_title'] ?></option>
   	<?php } ?>
  </select>
	</div>
	
	
	
	</td>
  </tr>
    <tr><td class="tabledata">Title</td>
  <td>
  <input name="picklist_title" type="text" value="<?php  echo $picklist_title?>"  style="width:100%"></td>

   <td class="tabledata">Status</td>
    <td> <input name="status" type="radio" value="1" <?php  echo ($status=='1'?'checked':'')?>>
	Active
	<input name="status" type="radio" value="0"<?php  echo ($status=='0'?'checked':'')?>>Inactive
	
     
    
    </td>
  </tr>
</table>

<p align="left" style="padding-lef:10px;"><input type="submit" name="Save" value="Save"></p>

</form>
 
 
 <?php  include('View_PickListData.php');?>


 </div> </div>


 