<?php session_start();
require_once('../../../config/config.php');
require_once (dirname(__FILE__).'/../../../clean_input.php');
	check_input(); 
include("../../common_pages/paging_crm.php");
include("../../common_pages/common_functions.php");
require_once('constants.php');
refresh_access();
if($_SESSION['admin_code']<=0)
	die("Error : Seesion timeout, Please re Login");
if($_SESSION['is_panel_access']<=0)	
	die("Error : Access Denied");
require_once("../../common_pages/enc.php");
$converter = new Encryption($_SESSION['unique_enc_id']);
?>
<?php 

if (isset($_REQUEST))

{
	 
		
	// print_r($_REQUEST);
	switch($_REQUEST['task'])
	{

		case'GeneralDetails':
		{
		
			//print_r($_REQUEST);
			
			$searchtext = mysql_real_escape_string($_REQUEST['searchtext']);
			//$prtstatus = $_REQUEST['status'];
			//$prtcat = $_REQUEST['instructions'];
			$searchtext = trim($searchtext);
			$where = '';			
			$fields = array('mobile_no','text_message');

			if(!empty($searchtext))
			{
				foreach($fields as $field)
				{
				
					if($where=="")
						$where = ' WHERE ( ';
					else
						$where .= ' OR ';
					$where .= $field." LIKE '%".$searchtext."%' ";
				}
				$where .=')';
			}
					
				
			 
			
			/*if($_REQUEST['s_mtype']<>"")
			{
				 $where .= " and mtype='".$_REQUEST['s_mtype']."'";
			}	
				
			if($_REQUEST['s_team']<>"")
			{
				 $where .= " and team='".$_REQUEST['s_mtype']."'";
			}	
			if($_REQUEST['s_se']>0)
			{
				 $where .= " and sale_employee_code<=0 ";
			}
			if($_REQUEST['s_sale_employee_code']>0)
			{
				 $where .= " and  sale_employee_code='".$_REQUEST['s_sale_employee_code']."'";
			}
			if($_REQUEST['s_status_c']>0)
			{
				 $where .= " and  customer_calling_status='".$_REQUEST['s_status_c']."'";
			}
			if($_REQUEST['s_sms']<>"")
			{
				 $where .= " and  sms='".$_REQUEST['s_sms']."'";
			}	
*/
			
		  		



			

			$q = "SELECT s.*  FROM ".TABLE_NAME." s    $where order by code desc ";
			
			
			?> 
            
 			<table id="datatable1" class="table display responsive nowrap" width="100%">
              
            <thead>
             
            <tr>
              <th>SrNo</th>
                
              <th>Name</th> 
              
              <th>Mobile Number</th> 	 	 	
              <th>Message</th> 	 	 	
              <th>Submitted @</th> 	 	 	
              <th>Schedule Date/Time</th> 	 	 	
              <th>Status</th>
              <th>Gateway</th> 	 	 	 
              <th></th> 	
              
               
            </tr> </thead><tbody>
            <?php	
			//print_r($p);
        	$i = 1;
			if($p['Page']!="1")
				$i = $p['Page'] * $p['Per_Page'] - $p['Per_Page']+ 1;//$i = $p[current] * $p[perPage] - $p[perPage]+ 1;
           
		   if(is_numeric($_REQUEST['page']) && $_REQUEST['page']>1)
				$_SESSION['page'] = $_REQUEST['page'];
			else
				$_SESSION['page'] = 1;
					//echo $q;
			//Paging New Script //
			if($_REQUEST['s_all_records']==1)
				$p = paging_prepare($q,$_SESSION['page'],999999999);
			else
				$p = paging_prepare($q,$_SESSION['page']);
			
			$p['task'] = 'GeneralDetails';
			$p['div'] = 'main_result_div';
			$p['response_file'] = 'response_index';
			$i =0;
		 	
			//echo $q;
			$q .= " LIMIT ".$p['Page_Start'].",".$p['Per_Page']." ";
			 
			//end of Pageing
			$qr = mysql_query($q) or die('Error: '.mysql_error());
		   
		    $i = ($p['Page_Start']+1);
			$status_array = array();
			$status_array[0] = '<div class="box_small alert-warning">Pending</div>';
			$status_array[1] = '<div class="box_small alert-success">Sent</div>';
			
			while ($rows=mysql_fetch_array($qr))
            {             	
			?>
            <tr <?php	if(($i%2)==0) echo 'class="alt_new"';?>>
             <td><?=$i;?></td>
             <!--<td><span onclick="move_order('<?=$rows['code']; ?>','main_result_div','<?=$p['Page'];?>','0','<?=TABLE_NAME;?>');" class="link_a" title="Click Here to Move Up" ><img src="../../images/up_arrow.png" border="0" align="absmiddle" /></span>
	                               <span onclick="move_order('<?=$rows['code']; ?>','main_result_div','<?=$p['Page'];?>','1','<?=TABLE_NAME;?>');" class="link_a"   title="Click Here to Move down" ><img src="../../images/down_arrow.png" border="0" align="absmiddle" /></span></td>-->
             
			  <td><?=display_feild('customer','name','code',$rows['m_code']); ?></td> 
              <td><?=$rows['mobile_no']; ?></td> 
              <td><textarea style="width:200px; height:auto;    "><?=$rows['text_message']; ?></textarea></td> 
              <td><?php
              			if($rows['sent_date_time']=='0000-00-00 00:00:00')
							$rows['sent_date_time'] = $rows['date'];
					echo date("d-M-y h:ia",strtotime($rows['date']));			
			  			 ?></td> 
              <td><?=date("d-M-y h:ia",strtotime($rows['sent_date_time'])); ?></td> 
                <td><?=$status_array[$rows['sent_flag']]; ?></td>
                <td><?=$rows['remarks_gateway'];?></td> 
                <td class="controler">
               <span onclick="add_edit('<?=$rows['code']; ?>','main_result_div','<?=$p['Page'];?>');" class="  btn-info btn-icon rounded-circle btn-sm  " title="Edit"><div><i class="fa fa-edit"></i></div></span> 
              
              <?php //if(isdelete('policy_list',"customer_code",$rows['customer_code'],$where=' and is_deleted=0 ')) { ?> 
                  <!--<span onclick="delete_row('<?=$rows['code']; ?>','main_result_div','<?=$p['Page'];?>');" class="  btn-danger btn-icon rounded-circle btn-sm  " title="Delete"><div><i class="fa fa-close"></i></div></span>-->
              
                
              
              <?php // } ?>
               
              
              </td> 
              
            </tr>
            <?php
			$i++;
			}
       ?>
         
       </tbody>
          </table>
           
 <?php paging_new('',$p); ?>
		 

    <?php			

    #-------------> Pagination Finish			

		

		
		}

		break;

		 
		case 'add_edit':
		{
		    $i =3;
			$key = array_keys($_REQUEST);	
			$n = count($_REQUEST);					
			while($i<=($n))
			{
				
				$s = $s."&".$key[$i]."=".$_REQUEST[$key[$i]]."";
				$i++;
			}
			require_once("index.class.php");
			$objpl=new General();
			$objpl->add_edit(fetch_details(TABLE_NAME,'code',$_REQUEST['id']),$_REQUEST);	
		}
		break;
		 
		case 'save_key':
		{
			 
			
			 if(strlen(trim($_REQUEST['mobile_no']))<=9)
			 {
			 	echo '1|0|Error : Please enter 10 digits Mobile Number!!';
				return;
			 }
			 
			 if(trim($_REQUEST['template'])=="")
			 {
			 	echo '1|0|Error : Please enter Message!!';
				return;
			 }
			  
			 $s = "select * from customer where mobile='".$_REQUEST['mobile_no']."'" ;
			 $r = mysql_query($s);
			 $customer = mysql_fetch_assoc($r);
			  
			 sms_jshine($customer['code'],trim($_REQUEST['mobile_no']),$_REQUEST['template'],1,$_REQUEST['sender_id']);
			 
			 echo '1|1|SMS Sent Successfully';			
			// print_r($_REQUEST);
			
			
		
			
		}
		break;
		
		case 'delete_row':
		{
			//print_r($_REQUEST);
			if($_REQUEST['id']>0)
			{
				$sql = "Select * from  ".TABLE_NAME." where code = '".$_REQUEST['id']."'";
				$res = mysql_query($sql);
				$rows = mysql_fetch_assoc($res);
							
								
				 if(isdelete('policy_list',"customer_code",$rows['customer_code'],$where=' and is_deleted=0 '))
				 { 
					 $sql = "update ".TABLE_NAME." SET is_deleted=1 WHERE code='".$_REQUEST['id']."' ";
					if(mysql_query($sql))
					{	
						create_log(TABLE_NAME,$_REQUEST,'code');	
						echo '1|1|Record Deleted';
						return true;
					}
					else
					{	echo '0|0|Error : while deleting this record!!';	
						return true;
					}
				 }
			 }
					echo '0|0|Error : Can\'t Delete record!!';
		}
		break;
		
		
	};

	

}

?>

