<?php
require_once ("../config.inc.php");
require_once ("../includes/adminlogincheck.inc.php");
require_once ("../includes/mysql.inc.php");
require_once ("../includes/Pager/Pager.php");

$message	= "";
$pages		= "";
$data		= array();
$array		= array();
$page		= isset($_REQUEST['page'])	?	trim($_REQUEST['page'])	:	"1";

$image='<img src="../images/bgar.gif"></img>';
if($order=='DESC') {

    $image='<img src="../images/descar.gif"></img>';
}

else if($order=='ASC') {

    $image='<img src="../images/ascrar.gif" ></img>';

}

if (!$objDB) 
{
	$message	= "Unable to Locate Database Server.";
}//end if
else 
{
        if(isset($_GET['msgflag']))
        {
            $msgFlag=trim($_GET['msgflag']);
            if($msgFlag==1)
            {
                $message = "<font color='green'>Mobile Service Provider details updated successfully</font>.";
            }
            elseif($msgFlag==2)
            {
                $message = "<font color='green'>Mobile Service Provider added successfully</font>.";
            }
        }
	//delete Country
	if(isset($_POST['ids']) && $_POST['ids']!='')
	{
		foreach ($_POST['ids'] as $val)
		{
			//fetch provider name
			$pName=mysql_query("select vSMSgateway from ".TABLEPREFIX."gateways WHERE id='".$val."'") or die(mysql_error());
			if(mysql_num_rows($pName)>0)
			{
				$pName=mysql_result($pName,0,'vSMSgateway');
			}//end if

			//check if it in use
			$check_category=mysql_query("SELECT * FROM ".TABLEPREFIX."user WHERE vProvider='".$pName."'") or die (mysql_error());
			if(mysql_num_rows($check_category)>0)
			{
				$message = "This Mobile Service Provider cannot be deleted since it is in use!";
			}//end if
			else
			{
				$sqlDel = mysql_query("DELETE FROM ".TABLEPREFIX."gateways WHERE id='".$val."'") or die(mysql_error());
				$message = "<font color='green'>Mobile Service Provider deleted successfully</font>.";
			}//end else
		}//end foreach
	}//end if

        

	//all country listing
	$query = "SELECT * FROM ".TABLEPREFIX."gateways ";
         if($title!=''){
                $query.=" ORDER BY ".$title." ".$order;
            }
            else{
               $query.=" ORDER BY provider";
            }
            

	$res=mysql_query($query) or die(mysql_error());

	if (@mysql_num_rows($res) > 0) 
	{
		while($row = @mysql_fetch_array($res)) 
		{
			$array[]	= $row;
		}//end while loop
		@mysql_free_result($res);
	}//end if
	
	$params 	= array(
		'mode'      => 'Sliding',
		'perPage'   => PAGESIZE,
		'urlVar'    => 'page',
		'extraVars' => array(),
		'itemData'  => $array
	);
	$objP 		= & Pager::factory($params);
	$data  		= $objP->getPageData();
	if (empty($data))
		$message	.= "No record(s) exists.<br>";
}//end else

include_once('title.inc.php');
?>
<script language="javascript" type="text/javascript">
function confirm_check()
{
	var chkVar;
	for (var i = 0; i < document.form1.elements.length; i++) 
	{
		var e = document.form1.elements[i];
		if (e.name == "ids[]") 
		{
			if(e.checked==true)
			{
				chkVar=true;
			}//end if
		}//end if
	}//end for loop

	 if(chkVar==true)
	{
		 var where_to= confirm("Do you really want to delete these Mobile Service Provider for permenantly??");
		 if (where_to== true)
		 {
		   return true;
		 }
		 else
		 {
		  return false;
		  }
	}//end if
}
function showAddSms(){
    $('#div_sms').hide();
    $('#div_add_sms').show();
}
function displayEditSms(id,page){
        var data 	= 'id='  + id+'&page='+page;
        $.ajax({
                url: "add_sms.php",
                type: "POST",
                data: data,
                cache: false,
                success: function (html) {
                    $('#tcontent12').html(html);
                }
        });
    }
</script>
<table width="100%"  border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td valign="top" class="white"><table width="100%"  border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td width="72%" valign="top"><?php include_once('tophtml.php');?>
			<table width="100%"  border="0" cellspacing="0" cellpadding="5">
          <tr>
            <td><table width="100%"  border="0" cellspacing="0" cellpadding="5">
              <tr>
                <td width="32%"></td>
                <td width="68%" align="right"><a href="#" onclick="showAddSms()" class="add-btn">Add New Mobile Service Provider</a></td>
              </tr>
            </table></td>
          </tr>
        </table>
		<form name="form1" method="post" action="" onSubmit="return confirm_check();">
          <table width="100%"  border="0" cellspacing="0" cellpadding="5">
            <tr>
              <td><table width="100%"  border="0" cellspacing="1" cellpadding="0" class="listing_tbl_admin">
					<?php 	if(isset($message) && $message!='')
							{
					?>
                <tr align="left">
                  <td align="center" class="maintext2">&nbsp;</td>
                  <td colspan="5" class="maintext2 warning"><?php echo $message;?></td>
                  </tr>
					<?php  	}//end if
				      if ($objDB) 
					  { 
                 			if (!empty($data)) 
							{ 
				?>
                <tr align="left">
				<th class="maintext2"></td>
                  <th align="center" class="maintext2">#</th>
                  <th class="maintext2">Provider Name<a href="settings.php?form=sms&title=provider&order=<?php echo $order == 'ASC' ? 'DESC' : 'ASC'?>"><?php echo $image ?></a></th>
                  <th class="maintext2">SMS Gateway<a href="settings.php?form=sms&title=vSMSgateway&order=<?php echo $order == 'ASC' ? 'DESC' : 'ASC'?>"><?php echo $image ?></a></th>
                  <th class="maintext2" align="center">Active<a href="settings.php?form=sms&title=vActive&order=<?php echo $order == 'ASC' ? 'DESC' : 'ASC'?>"><?php echo $image ?></a></th>
                  <th class="maintext2" align="center">Action</th>
                  
                  </tr>
					<?php  	foreach ($data as $key => $value) 
							{ 
				?>
                <tr align="left">
				   <td width="5%" align="center" class="maintext2"><input name="ids[]" type="checkbox" value="<?php echo $value['id']?>"></td>
                  <td width="5%" align="center" class="maintext2"><?php echo $key+1;?></td>
                  <td width="26%" class="maintext2"><?php echo htmlspecialchars(stripslashes($value['provider']))?></td>
                  <td width="24%" class="maintext2"><?php echo $value['vSMSgateway']?></td>
                  <td width="15%" align="center" class="maintext2"><?php if($value['vActive']=='1'){echo 'Yes';}else{echo 'No';}?></td>
                  <td width="12%" align="center" class="maintext2">
                      <!--<a href="add_sms.php?id=<?php echo $value['id']?>&page=<?php echo $objP->getCurrentPageID()?>" class="signupbuttonlink">Edit</a>-->
                      <a onClick="displayEditSms(<?php echo $value['id'];?>,<?php echo $objP->getCurrentPageID();?>);" class="signupbuttonlink">Edit</a>
                  </td>
               
                  </tr>
				<?php 			
						}//end foreach
				?>
			  <!-- <tr align="left">
                  <td align="center" class="maintext2">&nbsp;</td>
                  <td colspan="4" class="maintext2">&nbsp;</td>
                  <td align="center" class="maintext2"><input type="submit" name="DelNow" value="Delete" class="loginbutton"></td>
                </tr>-->
			   <?php
					 		}//end if
						}//end first if
				?>
              </table>
			  <table width="100%" cellspacing="1" cellpadding="1" border="0" style="margin-top:10px;">
			  <tr align="left">
                 
                  <td colspan="0" height="40" align="left">
        <input type="submit" name="DelNow" value="Delete" class="loginbutton"></td>
		<td width="18%"><?php if(!empty($data))
					  {
				?>
                <table width="100%"  border="0" cellspacing="0" cellpadding="0">
                  <tr>
                    <td width="82%">&nbsp;</td>
                    <td width="18%"><table width="100%"  border="0" cellspacing="2" cellpadding="0" class="pagination_style">
                        <tr align="center" class="textbox">
                          <td><?php echo $objP->links;?></td>
                          </tr>
                    </table></td>
                  </tr>
                </table><?php }//end if?></td>
                </tr>
				
			  </table>
				
                <table width="100%"  border="0" cellspacing="0" cellpadding="0">
                  <tr>
                    <td align="right"><table width="100%"  border="0" cellspacing="0" cellpadding="0">
                      <tr>
                        <td>&nbsp;</td>
                      </tr>
                    </table>
                     </td>
                  </tr>
                </table></td>
            </tr>
          </table></form></td>
        </tr>
    </table>      
    </td>
  </tr>
</table>
