Advertisement
Guest User

Untitled

a guest
Jan 11th, 2016
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 6.70 KB | None | 0 0
  1. <?php
  2.    
  3.     session_start();
  4.  
  5.     $host = "localhost";
  6.     $user = "abdoelte_root";
  7.     $pass = "1WR--79.QIy2";
  8.     $database = "abdoelte_db";
  9.    
  10.     $action = $_GET['action'];
  11.    
  12.     if($action == null || $action == ""){
  13.        
  14.         $action = $_POST['action'];
  15.        
  16.     }
  17.    
  18.     $uid = $_SESSION['uid'];
  19.    
  20.     $htop = "";
  21.     $htop.= "<!DOCTYPE html>";
  22.     $htop.= "   <head>";
  23.     $htop.= "       <title>Abdoelmalik login</title>";
  24.     $htop.= '       <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">';
  25.     $htop.= '       <link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet/v0.7.7/leaflet.css" />';
  26.     $htop.= '       <script src="http://cdn.leafletjs.com/leaflet/v0.7.7/leaflet.js"></script>';
  27.     $htop.= '       <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>';
  28.     $htop.= '       <style>';
  29.     $htop.= '           #map { height: 100vh; }';
  30.     $htop.= '       </style>';
  31.     $htop.= "   </head>";
  32.     $htop.= "   <body>";
  33.     $htop.= '       <div class= "container">';
  34.        
  35.     $hbot = "";
  36.     $hbot.= '       </div>';
  37.     $hbot.= "   </body>";
  38.     $hbot.= "</html>";
  39.    
  40.     if($action == "login"){
  41.        
  42.         $username = $_POST['username'];
  43.         $password = $_POST['password'];
  44.        
  45.         $db = mysql_connect($host,$user,$pass);
  46.         mysql_select_db($database) or die("Unable to select database");
  47.         mysql_query("SET NAMES utf8", $db);
  48.         mysql_query( "SET CHARACTER SET utf8", $db );
  49.         mysql_query("");
  50.        
  51.         $sql = "SELECT * FROM users WHERE username='".$username."' AND password=MD5('".$password."') LIMIT 1";
  52.         $res = mysql_query($sql);
  53.        
  54.         if(mysql_numrows($res) > 0){
  55.            
  56.             $_SESSION['uid'] = mysql_result($res, 0, "id");
  57.             header("location: index.php");
  58.    
  59.         }else {
  60.      
  61.             $h = '<h2>Uw gegevens komen niet overeen! Probeer het nog eens.</h2>';
  62.            
  63.             echo $htop;
  64.             echo $h;
  65.             echo $hbot;
  66.            
  67.            
  68.            
  69.         }
  70.     }  
  71.    
  72.     if($action == "logout"){
  73.    
  74.             session_destroy();
  75.             $_SESSION['uid'] = "";
  76.             header("location: index.php");
  77.    
  78.     }
  79.    
  80.     if($uid != null || $uid != ""){
  81.    
  82.         if($action == "json"){
  83.    
  84.             $db = mysql_connect($host,$user,$pass);
  85.             mysql_select_db($database) or die("Unable to select database");
  86.             mysql_query("SET NAMES utf8", $db);
  87.             mysql_query( "SET CHARACTER SET utf8", $db );
  88.             mysql_query("");
  89.            
  90.             $sql = "SELECT * FROM companies";
  91.             $res = mysql_query($sql);
  92.            
  93.             $data = array();
  94.            
  95.             for($i=0;$i<mysql_numrows($res);$i++){
  96.                
  97.                 $loc = array();
  98.                
  99.                 $res1 = mysql_query("SELECT * FROM locations WHERE id='".mysql_result($res,$i,"lID")."'");
  100.                
  101.                 for($q=0;$q<mysql_numrows($res1);$q++){                    
  102.                    
  103.                     $locs = array(
  104.                         "id" => mysql_result($res1,$q,"id"),
  105.                         "lat" => mysql_result($res1,$q,"latitude"),
  106.                         "lon" => mysql_result($res1,$q,"longitude")
  107.                     );
  108.                    
  109.                     array_push($loc, $locs);
  110.                    
  111.                 }
  112.                
  113.                 $item = array(
  114.                     "id" => mysql_result($res,$i,"id"),
  115.                     "name" => mysql_result($res,$i,"name"),
  116.                     "tel" => mysql_result($res,$i,"tel"),
  117.                     "loc" => $loc
  118.                 );
  119.                
  120.                 array_push($data, $item);
  121.                
  122.                
  123.             }
  124.            
  125.             $retval = array(
  126.                 "status" => "200",
  127.                 "url" => "?action=".$action,
  128.                 "data" => $data
  129.             );
  130.             header('Content-Type: application/json');          
  131.             echo json_encode($retval, true);
  132.         }
  133.        
  134.         }elseif($action == "json1"){
  135.            
  136.             $db = mysql_connect($host,$user,$pass);
  137.             mysql_select_db($database) or die("Unable to select database");
  138.             mysql_query("SET NAMES utf8", $db);
  139.             mysql_query( "SET CHARACTER SET utf8", $db );
  140.             mysql_query("");
  141.            
  142.             $sql = "SELECT * FROM winkels";
  143.             $res = mysql_query($sql);
  144.            
  145.             $shop = array();
  146.            
  147.             for($s=0;$s<mysql_numrows($res);$s++){
  148.                
  149.                 $winkel = array();
  150.                
  151.                 $res1 = mysql_query("SELECT * FROM winkelsCategorien WHERE id='".mysql_result($res,$a,"id")."'");
  152.                
  153.                 for($a=0;$a<mysql_numrows($res1);$a++){                    
  154.                    
  155.                     $category = array(
  156.                         "id" => mysql_result($res1,$a,"id"),
  157.                         "name" => mysql_result($res1,$a,"name"),
  158.                     );
  159.                    
  160.                     array_push($winkel, $category);
  161.                    
  162.                 }
  163.                
  164.                 $win = array(
  165.                     "id" => mysql_result($res,$s,"id"),
  166.                     "name" => mysql_result($res,$s,"name"),
  167.                     "email" => mysql_result($res,$s,"email"),
  168.                     "category" => $category
  169.                 );
  170.                
  171.                     array_push($winkel, $win);
  172.             }
  173.                
  174.                
  175.                 $retval = array(
  176.                 "status" => "200",
  177.                 "url" => "?action=".$action,
  178.                 "data" => $shop
  179.                
  180.                 );
  181.                
  182.                 header('Content-Type: application/json');  
  183.                 echo json_encode($retval, true);
  184.                
  185.         }
  186.        
  187.         }else{
  188.        
  189.             $h = "";
  190.            
  191.             $db = mysql_connect($host,$user,$pass);
  192.             mysql_select_db($database) or die("Unable to select database");
  193.             mysql_query("SET NAMES utf8", $db);
  194.             mysql_query( "SET CHARACTER SET utf8", $db );
  195.             mysql_query("");
  196.            
  197.             $sql = "SELECT * FROM locations WHERE status='Y'";
  198.             $res = mysql_query($sql);
  199.            
  200.             $h.= '      <script>';
  201.             $h.= '          jQuery(document).ready(function(){';
  202.             $h.= '              var map = L.map("map").setView([52.9, 4.89098], 17);';
  203.             $h.= '              L.tileLayer("https://api.tiles.mapbox.com/v4/{id}/{z}/{x}/{y}.png?access_token={accessToken}", {';
  204.             $h.= '                  attribution: "Map data &copy; <a href=\'http://openstreetmap.org\'>OpenStreetMap</a> contributors, <a href=\'http://creativecommons.org/licenses/by-sa/2.0/\'>CC-BY-SA</a>, Imagery © <a href=\'http://mapbox.com\'>Mapbox</a>",';
  205.             $h.= '                  maxZoom: 18,';
  206.             $h.= '                  id: "glimworm.cigc127z202zivlm40pxvwa9s",';
  207.             $h.= '                  accessToken: "pk.eyJ1IjoiZ2xpbXdvcm0iLCJhIjoiY2lnYzEyODcyMDJ6dHZ1bTUyemZ5c2N2bSJ9.FDMQQKXFJo6R5cUqoYmUPA"';
  208.             $h.= '              }).addTo(map);';
  209.            
  210.             for($i=0;$i<mysql_numrows($res);$i++){
  211.            
  212.                 $h.= '              var marker = L.marker(['.mysql_result($res, $i, "latitude").', '.mysql_result($res, $i, "longitude").']).addTo(map);';
  213.            
  214.             }
  215.            
  216.             $h.= '          });';
  217.             $h.= '      </script>';
  218.            
  219.             $h.= '<a href="?action=logout" class="btn btn-danger btn-lg">LOGOUT</a> <a href="?action=json" class="btn btn-primary btn-lg">json</a> <a href="?action=json1" class="btn btn-primary btn-lg">json1</a>';
  220.             $h.= '<div id="map"></div>';
  221.            
  222.             echo $htop;
  223.             echo $h;
  224.             echo $hbot;
  225.            
  226.         }
  227.  
  228.     }else{
  229.        
  230.         $h = "";       
  231.         $h.= '<form method="post" action="" class="form-signin">';
  232.         $h.= '  <input type="hidden" name="action" value="login"/><br/><br />';
  233.         $h.= '  <input class="form-control" placeholder="Username" required="" name="username" autofocus="" type="text"> <br/><br />';
  234.         $h.= '  <input class="form-control" placeholder="Password" required="" name="password" type="password"><br /><br />';
  235.         $h.= '  <input class="btn btn-lg btn-primary btn-block" type="submit" value="Log in">';
  236.         $h.= '</form>';
  237.        
  238.         echo $htop;
  239.         echo $h;
  240.         echo $hbot;
  241.            
  242.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement