<?php
$pgMod="extra";
$pgAct="view";
if(isset($_GET['action']) && trim($_GET['action'])!='')
		$pgAct=strtolower($_GET['action']);

if(isset($_POST['add']))
{
      $ch = curl_init();
     
        $data = array("linkname"=>$_POST['linkname'],"heading"=>$_POST['heading']);
 
        $url = "https://bps.savarnacloudtech.com/api/extra_menu.php";
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_POST, true);
        curl_setopt($ch, CURLOPT_POSTFIELDS,$data);
        $responce = curl_exec($ch);

        redirect(URL_ADMIN_HOME.getQueryString(array("src"=>"website", "page_id"=>$pgMod)));
}

if(isset($_POST['edit']))
{
    
      $ch = curl_init();
     
        $data = array("linkname"=>$_POST['linkname'],"heading"=>$_POST['heading'],"id"=>$_POST['id']);
 

        $url = "https://bps.savarnacloudtech.com/api/extra_menu.php?actions='edit'";
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_POST, true);
        curl_setopt($ch, CURLOPT_POSTFIELDS,$data);
        $responce = curl_exec($ch);

        redirect(URL_ADMIN_HOME.getQueryString(array("src"=>"website", "page_id"=>$pgMod)));
}

if(isset($_POST['extra_add']))
{
      $ch = curl_init();
      $id=$_GET['id'];
      $cfile = new CURLFile($_FILES['image']['tmp_name'], $_FILES['image']['type'], $_FILES['image']['name']);
        $data = array("title"=>$_POST['title'],"description"=>$_POST['description'],"myimage"=>$cfile,"id"=>$id);
//  print_r($data);
//  die();
        $url = "https://bps.savarnacloudtech.com/api/submenu.php";
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_POST, true);
        curl_setopt($ch, CURLOPT_POSTFIELDS,$data);
        $responce = curl_exec($ch);

        redirect(URL_ADMIN_HOME.getQueryString(array("src"=>"website", "page_id"=>$pgMod)));
}

if(isset($_POST['extra_edit']))
{
    
    
      $ch = curl_init();
      
       $cfile = new CURLFile($_FILES['image']['tmp_name'], $_FILES['image']['type'], $_FILES['image']['name']);
       
if($_FILES['image']['name'] !=""){
    $data = array("title"=>$_POST['title'],"description"=>$_POST['description'],"id"=>$_POST['id'],"myimage"=>$cfile);
}
        else{
            $data = array("title"=>$_POST['title'],"description"=>$_POST['description'],"id"=>$_POST['id']);
        }

        $url = "https://bps.savarnacloudtech.com/api/submenu.php?actions='edit'";
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_POST, true);
        curl_setopt($ch, CURLOPT_POSTFIELDS,$data);
        $responce = curl_exec($ch);

        redirect(URL_ADMIN_HOME.getQueryString(array("src"=>"website", "page_id"=>$pgMod)));
}


if($pgAct=="delete" && isset($_GET['id']) && trim($_GET['id'])!='')
{
            $ch = curl_init();
            $data = array("image"=>$_GET['img'],"action"=>$_GET['action'],"id"=>$_GET['id'],"page_id"=>"extra_menu");
            $url = "https://bps.savarnacloudtech.com/api/delete.php";
            curl_setopt($ch, CURLOPT_URL, $url);
            curl_setopt($ch, CURLOPT_POST, true);
            curl_setopt($ch, CURLOPT_POSTFIELDS,$data);
            $responce = curl_exec($ch);
            redirect(URL_ADMIN_HOME.getQueryString(array("src"=>"website", "page_id"=>$pgMod)));

} 
if($pgAct=="viewdelete" && isset($_GET['id']) && trim($_GET['id'])!='')
{
    $ch = curl_init();
            $data = array("image"=>$_GET['img'],"action"=>$_GET['action'],"id"=>$_GET['id'],"page_id"=>"extra_menu_data");
            $url = "https://bps.savarnacloudtech.com/api/delete.php";
            curl_setopt($ch, CURLOPT_URL, $url);
            curl_setopt($ch, CURLOPT_POST, true);
            curl_setopt($ch, CURLOPT_POSTFIELDS,$data);
            $responce = curl_exec($ch);
            redirect(URL_ADMIN_HOME.getQueryString(array("src"=>"website", "page_id"=>$pgMod)));
} 

if(isset($_SESSION['msg']) && $_SESSION['msg']!="")
{
	?>
	<div class="alert alert-success">
	  <a class="close" data-dismiss="alert">×</a>
	  <i class="icon icon-thumbs-up-alt"></i> <b>Notice</b><?php echo $_SESSION['msg'] ?></i>
	</div>
	<?php
	unset($_SESSION["msg"]);
}
if(is_array($alert_err) && count($alert_err)>0)
{
	?>
	<div class="alert alert-error">
	  <a class="close" data-dismiss="alert">×</a>
	  <i class="icon icon-warning-sign"></i> <b>Notice</b> <?php echo $alert_err[0] ?></i>
	</div>
	<?php
}
// if($pgAct=="edit" && $_GET["id"]!="")
// {   
   
   
// 	$aryForm=$db->getRow("SELECT * FROM extra_menu WHERE  id='".$_GET['id']."'");
// }
// if($pgAct=="viewedit" && $_GET["id"]!="")
// {   
   
   
// 	$aryForm=$db->getRow("SELECT * FROM extra_menu_data WHERE  id='".$_GET['id']."'");
// }




if($pgAct=="add" || ($pgAct=="edit" && isset($_GET['id']) && trim($_GET['id']) !=''))
{
    if($pgAct=="edit" ){
           $aryPgAct=array("src"=>"website", "page_id"=>$pgMod,"action"=>"add");
             $id=$_GET["id"];
            $url = "https://bps.savarnacloudtech.com/api/edit_extra_menu.php?id=$id";

            $context  = stream_context_create($options);
            $result = file_get_contents($url, false, $context);

            $aryForm = json_decode($result,true);
            // $aryList = $temp['slider'];
      }
?>
<!-- Forms --> 
	<div class="row-fluid">
        <form method="post" action="" enctype="multipart/form-data">
			<!-- Forms: Box -->
			<div class="span12">

				<!-- Forms: Top Bar -->
				<div class="top-bar">
					<h3><i class="icon-cog"></i> Create a New Submenu</h3>
				</div>
				<!-- / Forms: Top Bar -->

				<!-- Forms: Content -->
				<div class="well no-padding">

						
                        
                       
                        <div class="control-group">
                            	<input type="hidden" id="id" name="id" class="input-block-level" value="<?php echo $aryForm['id'] ?>">
							<label class="control-label" for="heading">Link Name</label>
							<div class="controls">
								<input type="text" id="image" name="linkname" class="input-block-level" value="<?php echo $aryForm['linkname']; ?>">
							</div>
						</div>
                        <div class="control-group">
							<label class="control-label" for="heading">Heading</label>
							<div class="controls">
								<input type="text" id="image" name="heading" class="input-block-level"  value="<?php echo $aryForm['heading']; ?>">
							</div>
						</div>
                        

						<div class="form-actions">
                        
							<button type="submit" <?php if($pgAct=="edit"){?>	name="edit" <?php	}else{ ?>	name="add" <?php } ?> class="btn btn-primary"> Save</button>
							<button type="button" class="btn"> Cancel</button>
						</div>
                        
				</div>
				<!-- / Forms: Content -->

			</div>
			<!-- / Forms: Box -->

        </form>
	</div>
<?php   



}

elseif($pgAct=="adddata" || ($pgAct=="viewedit" && isset($_GET['id']) && trim($_GET['id']) !='')){
  if($pgAct=="viewedit" ){
           $aryPgAct=array("src"=>"website", "page_id"=>$pgMod,"action"=>"add");
             $id=$_GET["id"];
            $url = "https://bps.savarnacloudtech.com/api/edit_submenu.php?id=$id";

            $context  = stream_context_create($options);
            $result = file_get_contents($url, false, $context);

            $aryForm = json_decode($result,true);
            // $aryList = $temp['slider'];
      }
?>
<!-- Forms --> 
	<div class="row-fluid">
        <form method="post" action="" enctype="multipart/form-data">
			<!-- Forms: Box -->
			<div class="span12">

				<!-- Forms: Top Bar -->
				<div class="top-bar">
					<h3><i class="icon-cog"></i> Add  New Data</h3>
				</div>
				<!-- / Forms: Top Bar -->

				<!-- Forms: Content -->
				<div class="well no-padding">

					
                        
                        <div class="control-group">
                            	<input type="hidden" id="id" name="id" class="input-block-level" value="<?php echo $aryForm['id'] ?>">
							<label class="control-label" for="heading">Image</label>
							<div class="controls">
								<input type="file" id="image" name="image" class="input-block-level" value="<?php echo $aryForm['image'] ?>" >
							<?php if(isset($aryForm['image'])){?>
								<img src="<?php echo $aryForm['image'] ?>" style="width:10%" >
								<?php } ?>
							</div>
						</div>
						
						<div class="control-group">
							<label class="control-label" for="heading"> Title</label>
							<div class="controls">
								<input type="text" id="image" name="title" class="input-block-level" value="<?php echo $aryForm['title'] ?>">
							</div>
						</div>
						
						<div class="control-group">
							<label class="control-label" for="heading">Description</label>
							<div class="controls">
								<input type="text" id="image" name="description" class="input-block-level" value="<?php echo $aryForm['description']?>" >
							</div>
						</div>
                        

					<div class="form-actions">
                        
							<button type="submit" <?php if($pgAct=="viewedit"){?>	name="extra_edit" <?php	}else{ ?>	name="extra_add" <?php } ?> class="btn btn-primary"> Save</button>
							<button type="button" class="btn"> Cancel</button>
						</div>
                        
				</div>
				<!-- / Forms: Content -->

			</div>
			<!-- / Forms: Box -->

        </form>
	</div>
<?php   



}


else if($pgAct=="view" && isset($_GET['id']) && trim($_GET['id']) !=''){?>
   	<div class="row-fluid">
    <div class="span12">
    
        <div class="top-bar">
        <h3><i class="icon-eye-open"></i> <?php echo ucwords($pgAct." ".$pgMod); ?></h3>
        <button style="float:right; margin-top:5px" onclick="window.location='./?src=website&page_id=<?php echo $pgMod; ?>&action=adddata&id=<?php echo $_GET['id'] ?>'" class="btn" type="button">Add Data</button>
        </div>
    
        <div class="well no-padding">
        <?php
      $aryPgAct=array("src"=>"website", "page_id"=>$pgMod,"action"=>"add");
$id=$_GET['id'];
            $url = "https://bps.savarnacloudtech.com/api/get_submenu.php?id=$id";

            $context  = stream_context_create($options);
            $result = file_get_contents($url, false, $context);

            $aryList = json_decode($result,true);
            // $aryList = $temp['slider'];
        if(is_array($aryList) && count($aryList)>0)
        {
            ?>
            <table class="table" id="example"> 
                <thead>
                    <tr>
                        <th >S.no</th>
                        <th >Title</th>
                          <th >Description</th>
                        
                           <th >Image</th>
                        <th>Action</th>
                    </tr>
                </thead>
                <tbody>
                <?php foreach($aryList as $clist){ $i++; 
                $aryPgAct["id"]=$clist['id'];
                ?>
                    <tr >
               
      <th  style="font-weight: 600; color: green;padding: 0.75rem;" ><?php echo $i?></th>
      <th style="padding: 0.75rem;" ><?php echo $clist['title'];?></th>
    <th style="padding: 0.75rem;" ><?php echo $clist['description'];?></th>
   
    
    <td style="padding: 0.75rem;">
          <img src="<?php echo $clist["image"]; ?>" alt="Service image" style="height: 100px;">
          </td>
      <td>
          
            <?php $aryPgAct['action']="viewedit"; ?>
                           <a style="float:left" href="<?php echo URL_ADMIN_HOME.getQueryString($aryPgAct); ?>"><button type="button" class="btn btn-info">Edit</button></a>
                            <?php $aryPgAct['action']="viewdelete";
                            $aryPgAct['img']=$clist['image'];
                            ?>
                            <a href="javascript:;" onclick="del('<?php echo URL_ADMIN_HOME.getQueryString($aryPgAct); ?>')" class="confirmation"><button type="button" class="btn btn-danger">Delete</button></a>  
                        </td>
    </tr>
                <?php } ?>
                </tbody>
            </table>
            <?php
        }
        else{
            echo "<script>alert('No record Found')</script>";
        }
        ?>
        </div>
  </div>
</div>
    
<?php }

else{
	?>
	<div class="row-fluid">
    <div class="span12">
    
        <div class="top-bar">
        <h3><i class="icon-eye-open"></i> <?php echo ucwords($pgAct." ".$pgMod); ?></h3>
        <button style="float:right; margin-top:5px" onclick="window.location='./?src=website&page_id=<?php echo $pgMod; ?>&action=add'" class="btn" type="button">Add <?php echo $pgMod; ?></button>
        </div>
    
        <div class="well no-padding">
          <?php
         $aryPgAct=array("src"=>"website", "page_id"=>$pgMod,"action"=>"add");

            $url = "https://bps.savarnacloudtech.com/api/get_extra_menu.php";

            $context  = stream_context_create($options);
            $result = file_get_contents($url, false, $context);

            $temp = json_decode($result,true);
            // $aryList = $temp['slider'];
      
            ?>
            <table class="table" id="example"> 
                <thead>
                    <tr>
                        <th >S.no</th>
                        <th >Linkname</th>
                          <th >Heading</th>
                        
                           <th >Type</th>
                        <th>Action</th>
                    </tr>
                </thead>
                <tbody>
                <?php foreach($temp as $clist){ $i++; 
                $aryPgAct["id"]=$clist['id'];
                ?>
                    <tr >
               
      <th  style="font-weight: 600; color: green;padding: 0.75rem;" ><?php echo $i?></th>
      <th style="padding: 0.75rem;" ><?php echo $clist['linkname'];?></th>
    <th style="padding: 0.75rem;" ><?php echo $clist['heading'];?></th>
   
    
       <th style="padding: 0.75rem;" ><?php echo $clist['type'];?></th>
      <td>
          <?php $aryPgAct['action']="view"; ?>
                           <a style="float:left" href="<?php echo URL_ADMIN_HOME.getQueryString($aryPgAct); ?>"><button type="button" class="btn btn-primary">View</button></a>
            <?php $aryPgAct['action']="edit"; ?>
                           <a style="float:left" href="<?php echo URL_ADMIN_HOME.getQueryString($aryPgAct); ?>"><button type="button" class="btn btn-info">Edit</button></a>
                            <?php $aryPgAct['action']="delete"; ?>
                            <a href="javascript:;" onclick="del('<?php echo URL_ADMIN_HOME.getQueryString($aryPgAct); ?>')" class="confirmation"><button type="button" class="btn btn-danger">Delete</button></a>  
                        </td>
    </tr>
                <?php } ?>
                </tbody>
            </table>
            <?php
        }
        
        ?>
        </div>
  </div>
</div>
