When I click on "lock" I want only the line where I clicked to change the status to true and the lock be locked. When I click on "unlock" I want only the line where I clicked to change the status to false and the released lock.
In my current code:
when I click on a lock on the first line your status changes and also the lock, but the lock of the other lines also change. I need help to fix this.
There is also another thing that I think I should use ajax. When the table is generated and executed for the first time all status will be in false and the lock "open" To mark a line as locked (lock) the status will make is true, and I need to send this "true" pro database and save it through a php script, so that, to reload the page status I had changed continues saved.
I am using the following plugin Context menu:
For better visualization, I put my code in pastebin.
change.js
$(function(){
$.contextMenu({
selector: '.context-menu-one',
items: {
"block": {
name: "Lock",
icon: "edit",
callback: function(key, options){
var m = $(this).text();
var set = block(m, $(this)); // passando - this - como parâmetro de função
}
},
"sep1": "----------",
"unblock": {
name: "Unlock",
icon: "cut",
callback: function(key, options){
var m = $(this).text();
var set = unblock(m, $(this)); // passando - this - como parâmetro de função
}
}
}
});
});
function block(x, thisObj)
{
if (x === "false")
x = "true";
thisObj.html(x);
$(".lock1").html('<i class="fa fa-unlock" aria-hidden="true"></i>');
}
function unblock(x, thisObj)
{
if (x === "true")
x = "false";
thisObj.html(x);
$(".lock1").html('<i class="fa fa-lock" aria-hidden="true"></i>');
}
PasteBin.
network.php
<?php
$con = mysqli_connect("localhost", "root", "", "mydb2");
?>
<ul class="breadcrumb">
<li>Ir para</li>
<li>dashboard</li>
</ul>
<div class="page-content-wrap">
<div class="row">
<div class="col-md-12">
<div class="panel panel-default">
<div class="panel-heading">
<div class="page-title">
<h2><span class="fa fa-hand-spock-o"></span> - Virtual Private Network</h2>
<p id="test">abc</p>
</div>
</div>
<div class="panel-body">
<div class="table-responsive">
<table class="table datatable table-striped">
<thead>
<tr>
<th>Common Name</th>
<th>Real Address</th>
<th>Virtual Address</th>
<th>Bytes Sent</th>
<th>Bytes Received</th>
<th>Since</th>
<th>Status</th>
<th>Blocked</th> <!--inserir a imagem de cliente bloqueado ou não -->
</tr>
</thead>
<tbody>
<tr>
<td class="context-menu-one">orion</td>
<td class="context-menu-one">177.43.212.110</td>
<td class="context-menu-one">172.16.191.145</td>
<td class="context-menu-one">872199</td>
<td class="context-menu-one">860412</td>
<td class="context-menu-one">Wed May 25 07:22:52 2016</td>
<td class="context-menu-one">false</td>
<td class="lock1"><i class="fa fa-unlock" aria-hidden="true"></i></td>
</tr>
<tr>
<td class="context-menu-one">elgin</td>
<td class="context-menu-one">189.10.58.244</td>
<td class="context-menu-one">172.16.6.210</td>
<td class="context-menu-one">301365</td>
<td class="context-menu-one">250459</td>
<td class="context-menu-one">Wed May 25 07:01:37 2016</td>
<td class="context-menu-one">false</td>
<td class="lock1"><i class="fa fa-unlock" aria-hidden="true"></i></td>
</tr>
<tr>
<td class="context-menu-one">databits</td>
<td class="context-menu-one">187.17.235.203</td>
<td class="context-menu-one">172.16.136.217</td>
<td class="context-menu-one">459833</td>
<td class="context-menu-one">409771</td>
<td class="context-menu-one">Wed May 25 06:09:01 2016</td>
<td class="context-menu-one">false</td>
<td class="lock1"><i class="fa fa-unlock" aria-hidden="true"></i></td>
</tr>
<tr>
<td class="context-menu-one">proficio</td>
<td class="context-menu-one">179.213.177.117</td>
<td class="context-menu-one">172.16.196.93</td>
<td class="context-menu-one">1083595</td>
<td class="context-menu-one">945154</td>
<td class="context-menu-one">Tue May 24 21:36:21 2016</td>
<td class="context-menu-one">false</td>
<td class="lock1"><i class="fa fa-unlock" aria-hidden="true"></i></td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
</div>
?>
PasteBin.
My table:
The "lock" option:
It was a fun one!
First, I changed the position of context-menu-one class for the parent's.
And delegated the action on it's tds by this: selector: '.context-menu-one td'.
Because it makes less elements to "watch" for jQuery... And cleans the code.
Then... I modified the callback functions in your items object.
I played with .parent(), siblings() and prev() to target all the right elements.
HTML:
<ul class="breadcrumb">
<li>Ir para</li>
<li>dashboard</li>
</ul>
<div class="page-content-wrap">
<div class="row">
<div class="col-md-12">
<div class="panel panel-default">
<div class="panel-heading">
<div class="page-title">
<h2><span class="fa fa-hand-spock-o"></span> - Virtual Private Network</h2>
<p id="test">abc</p>
</div>
</div>
<div class="panel-body">
<div class="table-responsive">
<table class="table datatable table-striped">
<thead>
<tr>
<th>Common Name</th>
<th>Real Address</th>
<th>Virtual Address</th>
<th>Bytes Sent</th>
<th>Bytes Received</th>
<th>Since</th>
<th>Status</th>
<th>Blocked</th> <!--inserir a imagem de cliente bloqueado ou não -->
</tr>
</thead>
<tbody>
<tr class="context-menu-one row">
<td>orion</td>
<td>177.43.212.110</td>
<td>172.16.191.145</td>
<td>872199</td>
<td>860412</td>
<td>Wed May 25 07:22:52 2016</td>
<td>false</td>
<td class="lock1"><i class="fa fa-unlock" aria-hidden="true"></i></td>
</tr>
<tr class="context-menu-one row">
<td>elgin</td>
<td>189.10.58.244</td>
<td>172.16.6.210</td>
<td>301365</td>
<td>250459</td>
<td>Wed May 25 07:01:37 2016</td>
<td>false</td>
<td class="lock1"><i class="fa fa-unlock" aria-hidden="true"></i></td>
</tr>
<tr class="context-menu-one row">
<td>databits</td>
<td>187.17.235.203</td>
<td>172.16.136.217</td>
<td>459833</td>
<td>409771</td>
<td>Wed May 25 06:09:01 2016</td>
<td>false</td>
<td class="lock1"><i class="fa fa-unlock" aria-hidden="true"></i></td>
</tr>
<tr class="context-menu-one row">
<td>proficio</td>
<td>179.213.177.117</td>
<td>172.16.196.93</td>
<td>1083595</td>
<td>945154</td>
<td>Tue May 24 21:36:21 2016</td>
<td>false</td>
<td class="lock1"><i class="fa fa-unlock" aria-hidden="true"></i></td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
</div>
JavaScript:
$(function(){
$.contextMenu({
selector: '.context-menu-one td',
items: {
"block": {
name: "Lock",
icon: "edit",
callback: function(key, options){
console.log("HERE");
if ($(this).parent().hasClass("row")){
console.log("HERE IF");
thisRowPadlock = $(this).siblings(".lock1");
var m = $(this).siblings(".lock1").prev().text();
console.log(m);
var set = block(m, thisRowPadlock, $(this).siblings(".lock1").prev()); // passando - this - como parâmetro de função
}
}
},
"sep1": "----------",
"unblock": {
name: "Unlock",
icon: "cut",
callback: function(key, options){
console.log("THERE");
if ($(this).parent().hasClass("row")){
thisRowPadlock = $(this).siblings("lock1");
var m = $(this).siblings(".lock1").prev().text();
console.log(m);
var set = unblock(m, thisRowPadlock, $(this).siblings(".lock1").prev()); // passando - this - como parâmetro de função
}
}
}
}
});
});
function block(x, padlock, thisObj)
{
console.log("Function block");
if (x === "false")
x = "true";
thisObj.html(x);
$(padlock).html('<i class="fa fa-unlock" aria-hidden="true"></i>');
}
function unblock(x, padlock, thisObj)
{
console.log("Function unblock");
if (x === "true")
x = "false";
thisObj.html(x);
$(padlock).html('<i class="fa fa-lock" aria-hidden="true"></i>');
}
And a working Fiddle (with some missing CSS, sorry).
Related
I have a tree structure where on hover of the user image it should show some of other user related info but instead of show that info in proper div, its show raw HTML data.
HTML Code
there can be n number of a href
<a href="{{ route('user-binary-tree',[ 'eUserID' => $ERight12]) }}" class="bt-element binary-tree-on-hover" id="{{$ERight12}}">
<img class="rounded-circle" style="width: 50px" src="{{ asset($packageImg) }}">
{{ $Right12[0]->sponsor_code }}
</a>
JavaScript code
$('.binary-tree-on-hover').mouseover(function() {
var userId = this.id;
var $this = $(this);
$.ajax('/binary-tree-ajax/' + userId + '/html', {
method: "GET",
dataType: "html",
success: function(data) {
$this.attr('title', data).mouseover(); //HTML DATA SHOW IN HOVER
}
});
});
Ajax response is
<div class="bt-details">
<table class="table color-table inverse-table">
<thead>
<tr>
<td class="text-center" style="font-size: 100%">Chethan k Test</td>
<td class="text-center" style="font-size: 100%"></td>
<td class="text-center">
<span class="btn btn-danger btn-xs btn-outline" style="border-width: 2px;">Inactive</span>
</td>
</tr>
<tr>
<td class="text-center" style="font-size: 100%">Sponsor ID</td>
<td class="text-center" style="font-size: 100%" colspan="2">UNO187175</td>
</tr>
<tr>
<td class="text-center" style="font-size: 100%">Binary Qualified</td>
<td class="text-center" style="font-size: 100%" colspan="2">
<span class="btn btn-danger btn-xs btn-outline" style="border-width: 2px;">No</span>
</td>
</tr>
<tr>
<th width="40%" class="text-center">Position</th>
<td class="text-center" style="font-size: 95%">Left</td>
<td class="text-center" style="font-size: 95%">Right</td>
</tr>
</thead>
<tbody>
<tr>
<th width="40%" class="text-center">Downline</th>
<td class="text-center">39</td>
<td class="text-center">6</td>
</tr>
<tr>
<th width="40%" class="text-center">Business</th>
<td class="text-center">$0</td>
<td class="text-center">$0</td>
</tr>
<tr>
<th width="40%" class="text-center">Carry</th>
<td class="text-center">$0</td>
<td class="text-center">$0</td>
</tr>
<tr>
<th width="40%" class="text-center" rowspan="2">Binary Generated</th>
<td class="text-center" style="font-size: 95%">Last Day</td>
<td class="text-center" style="font-size: 95%">Till Date</td>
</tr>
<tr>
<td class="text-center">$0</td>
<td class="text-center">$</td>
</tr>
</tbody>
</table>
When i hover on any of the user image its shows row HTML data instead of proper div as seen in 1st image
Also its keep calling the Ajax request infinite times but when i remove $this.attr('title', data).mouseover(); its called Ajax request only once. so i think the infinite calling happening because of this line only.
here how its shows
but i want to show like this
Note : 2nd one is working but its not ajax call and it will fetch all the user info from controller and load on view hence when user increase it will slow down the page so i am trying to call ajax on hover of the image.
End up with using popover function
HTML Code
<div id="popover_html" style="display:none;">
hover_data
</div>
JavaScript Code
jQuery('.binary-tree-on-hover').popover({
title: popoverContent,
html: true,
placement: 'bottom',
trigger: 'hover'
});
function popoverContent() {
var content = '';
var element = $(this);
var id = element.attr("id");
var APP_URL = "{{ url('/')}}";
const adminRoutePrefix = $("#admin_route_prefix").text();
$.ajax({
url: APP_URL + '/' + adminRoutePrefix + '/networks/binary-tree-ajax/' + id + '/html',
method: "GET",
async: false,
// dataType: "HTML",
success: function(data) {
content = $("#popover_html").html();
content = content.replace(/hover_data/g, data);
}
});
return content;
}
recently I,ve been trying to make a modal to pop-up on every element of a list. That list comes from a MySQL Database with this code:
<?php
$page = (int) (!isset($_GET["page"]) ? 1 : $_GET["page"]);
$cadenaSQL = "SELECT idPedido, fecha, fechaActual, nombre, apellido1, apellido2, telefono, email, productos, mensaje, aprobado
FROM pedido
WHERE borrado = 0
ORDER BY -fecha";
$limit = 10;
$page = validatepage($mysqli,$cadenaSQL,$limit,$page);
$startpoint = ($page * $limit) - $limit;
$res= $mysqli->query($cadenaSQL." LIMIT {$startpoint} , {$limit}");
?>
Most of the code above comes from a php class with functions related to the database, so they are called from there.
It shows on a list with the following html-php code, relating almost every field of the database, posting it first on a column with the showed width and then making every line with the values from every entry:
<table class="table table-hover">
<thead>
<tr>
<th scope="col" style="width:8%" class="num-pedido">NºPedido</th>
<th scope="col" style="width:10%" class="fecha">Fecha</th>
<th scope="col" style="width:15%" class="nombre-completo">Nombre</th>
<th scope="col" style="width:12%" class="telefono">Teléfono</th>
<th scope="col" style="width:15%" class="email">Email</th>
<th scope="col" style="width:20%" class="productos">Productos</th>
<th scope="col" style="width:10%" class="aprobado">Aceptado</th>
<th scope="col" style="width:10%" class="accion">Acción</th>
</tr>
</thead>
<tbody>
<?php
while($row=mysqli_fetch_array($res)){
$idPedido = $row['idPedido'];
$id = "P".str_pad($idPedido, 8, "0", STR_PAD_LEFT);
$fecha = $row['fecha'];
$fechaActual = $row['fechaActual'];;
$nombre = $row['nombre'];
$apellido1 = $row['apellido1'];
$apellido2 = $row['apellido2'];
$telefono = $row['telefono'];
$email = $row['email'];
$productos = $row['productos'];
$aprobado = $row['aprobado'].'';
$mensaje = $row['mensaje'];
$nombrecompleto = $nombre." ".$apellido1." ".$apellido2;
?>
<tr class="tabla-fila" <?php if($aprobado==1){echo "style='background:#afd5a2'";}?>>
<td data-label="Nº Pedido">
<a>
<div class="num-pedido" ><div id="myModalBtn"><?=$id?></div></div>
</a>
</td>
<td data-label="Fecha">
<div class="fecha"><?=$fecha?></div>
</td>
<td data-label="Nombre">
<div class="nombre-completo-pedido"><?=$nombrecompleto?></div>
</td>
<td data-label="Telefono">
<div class="telefono"><?=$telefono?></div>
</td>
<td data-label="Email">
<div class="email-pedido"><?=$email?></div>
</td>
<td data-label="Productos">
<div class="productos"><?=$productos?></div>
</td>
<td data-label="Aceptado">
<div class="aprobado"><?php if($aprobado==0){
echo "NO";
}else{
echo "SI";
}?></div>
</td>
<td data-label="Acción">
<div class="accion">
<span class="ti-check" id='<?=$idPedido?>' data-id="<?= $idPedido ?>"></span>
<span class="ti-trash" id='<?=$idPedido?>' data-id='<?= $idPedido ?>'></span>
</div>
</td>
</tr>
<?php } ?>
</tbody>
</table>
The problem comes when I try to call the model with "myModalBtn" (I will post the code a few lines later), as it only shows the last entry of my database. Here is the code:
<div id="myModal" class="modal">
<!-- Modal content -->
<div class="modal-content">
<div class=>
<button class="close">×</button>
</div>
<?php sectionbradcam('Detalles del pedido');?>
<section class="subcaja-central">
<div id = "central" class="container">
<div class="area-contenido">
<p><br>
Id Pedido: <?=$id?><br>
Fecha solicitada: <?=$fecha?><br>
Fecha de la solicitud: <?=$fechaActual?><br>
Nombre completo: <?=$nombrecompleto?><br>
Teléfono: <?=$telefono?><br>
Email: <?=$email?><br>
Productos: <?=$productos?><br>
Mensaje: <?=$mensaje?><br>
</p>
</div>
</div>
</section>
</div>
</div>
And also the json called to make the modal popup:
// Get the modal
var modal = document.getElementById("myModal");
// Get the button that opens the modal
var btn = document.getElementById("myModalBtn");
// Get the <span> element that closes the modal
var span = document.getElementsByClassName("close")[0];
// When the user clicks on the button, open the modal
btn.onclick = function() {
modal.style.display = "block";
}
// When the user clicks on <span> (x), close the modal
span.onclick = function() {
modal.style.display = "none";
}
// When the user clicks anywhere outside of the modal, close it
window.onclick = function(event) {
if (event.target == modal) {
modal.style.display = "none";
}
}
How can I make it on every item of the list I mentioned above? And how would I point each lane of the list to it´s information on the database?
Thanks in advance to everyone who can help me.
i have created a table (using datatables) and in the table a few actions. in the table i have a button to do a function "delete", also using datatables i get pagination.. So for example i am at page 5, and i want to delete a row when i click delete it refreshes the page and goes back to page no 1. How can i make it remain at page 5 after the action delete? Below are my table and controller function
viewStatistics.blade:
<table class="table table-hover demo-table-search table-responsive-block alt-table" id="tableWithSearch">
<thead>
<tr>
<th class="text-center" style="width:80px;">ID</th>
<th class="text-center">Date</th>
<th class="text-center">Question <br> Asked</th>
<th class="text-center">Low <br> Confidence</th>
<th class="text-center">No <br> Answer</th>
<th class="text-center">Missing <br> Intent</th>
<th class="text-center">Webhook <br> Fail</th>
<th class="text-center">Status</th>
<th class="text-center">Action</th>
</tr>
</thead>
<tbody>
#foreach($data as $sessionID => $value)
<tr>
<td class="text-center">{{$value['identifier']}}</td>
<td class="text-center">{{date("d M", strtotime($value['dateAccess']))}}</td>
<td class="text-center">{{$value['total']}}</td> <!-- question asked -->
<td class="text-center">{{$value['low confidence']}}</td> <!-- low confidence -->
<td class="text-center">{{$value['no answer']}}</td> <!-- no answer -->
<td class="text-center">{{$value['missing intent']}}</td> <!-- missing intent -->
<td class="text-center">{{$value['webhook fail']}}</td> <!-- webhook fail -->
<td class="text-center" style="{{$value['status'] == 'Reviewed' ? 'color:green' : 'color:red'}}">
{{$value['status']}}
#if($value['status'] == 'Pending')
<input type="checkbox" name="check" class="check" value="{{$sessionID}}">
#endif
</td> <!-- status -->
<td class="text-center">
<div class="btn-group">
<button type="button" class="btn alt-btn alt-btn-black dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Manage</button>
<ul class="dropdown-menu">
<li>
View
</li>
<li>
Delete
</li>
#if($value['status'] == 'Pending')
<li>
Mark as Done
</li>
#endif
</ul>
</div>
</td> <!-- action -->
</tr>
#endforeach
</tbody>
</table>
Controller:
public function deleteStatistics($companyID, $sessionID)
{
DiraChatLog::where('company_id', $companyID)->where('sessionID', $sessionID)->delete();
return redirect(action('AltHr\Chatbot\TrackerController#viewStatistics', compact('companyID')))->with('notification',[
'status' => 'success',
'title' => 'Statistics Deleted',
'message' => 'The Statistics have been deleted.'
]);
}
There is an option named stateSave in jquery datatables. Please check the code below:
$('#example').dataTable({ stateSave: true });
I posted another question for issue and it was partially solved. I have a table with a single link on each row. The link calls AJAX and outputs in another Bootstrap column. This works fine. When I click the link, the class "highlight" is applied which changes the background color of the row. When I click another link I want the previously clicked clink to have the "highlight" class removed and the new row to have the class applied.
Currently, the add class works but any other link click get the class added but the class is never removed.
<table class="table table-hover unpadded" id="mashed_tab">
<thead>
<tr>
<th class="artcl_hdr text-center" colspan="2">
<p class="big_date top_pad"><i class="fa fa-rss fa-lg concrete"></i> Articles/Keywords for
2016-07-09 - 2016-07-10</p>
</th>
<th><span class="badge bkgcol-wet-asphalt">55</span></th>
</tr>
</thead>
<tbody class="mashed_body">
<tr class="mashed_row">
<td class="bkgcol-sunflower wht-border">
<div class="date_cell">
<span class="asphalt long_date">Sat</span><span class="white day">Jul 09, 2016</span>
</div>
</td>
<td class="linked-title dark unpadded">
<div class="cell_link">
link 1
</div>
</td>
<td class="small-cell">
<i class="fa fa-arrow-right"></i>
</td></tr><tr class="mashed_row">
<td class="bkgcol-sunflower wht-border">
<div class="date_cell">
<span class="asphalt long_date">Sat</span>
<span class="white day">Jul 09, 2016</span>
</div>
</td>
<td class="linked-title dark unpadded">
<div class="cell_link">
Link 2
</div>
</td>
<td class="small-cell">
<i class="fa fa-arrow-right"></i>
</td>
</tr>
<tr class="mashed_row">
<td class="bkgcol-sunflower wht-border">
<div class="date_cell">
<span class="asphalt long_date">Sat</span>
<span class="white day">Jul 09, 2016</span>
</div>
</td>
<td class="linked-title dark unpadded">
<div class="cell_link">
Link 3
</div>
</td>
<td class="small-cell">
<i class="fa fa-arrow-right"></i>
</td>
</tr>
</tbody>
</table>
<script type="text/javascript">
$(document).ready(function() {
attachEvents();
});
function attachEvents() {
var selClass = 'highlight';
$('#mashed_tab tr a').click(function() {
$(this).parent().parent().removeClass(selClass);
$(this).parent().parent().addClass(selClass);
});
};
</script>
Try something like this in your on click function and let me know.
$('tr a').click(function() {
$("#mashed_tab tr").find("." + selClass).removeClass(selClass);
$(this).parent().parent().addClass(selClass); });
i got i problem when the session is expire i does not move to login page but i got error as can not connect to serer as my ajax code looks like
function driver()
{
$this = $(this);
$.ajax(
{
url: 'view/driver/driver.php',
datatype: 'html',
async:true,
success: function(data){
$box = $('#content');
$box.after(data);
$box.remove();
}
});
}
$(document).on('click','#driver',$(this),driver);
and the php url file as
<div id="content" class="span10">
<!-- content starts -->
<div class="row-fluid sortable">
<div class="box span12">
$userid=$_SESSION['USERID'];
if(empty($userid)){
header('location:localhost/test/login.php');
}
<div class="box-header well" data-original-title>
<h2><i class="icon-user"></i> All Driver</h2>
</div>
<div class="box-content">
<table class="table table-striped table-bordered bootstrap-datatable datatable">
<thead>
<tr>
<th>Driver user ID</th>
<th>FName</th>
<th>LName</th>
<th>Phone NO.</th>
<th>Is Verified</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<?php
include '../../config.php';
$query = "select * from driver_user";
$result = mysql_query($query);
while ($row = mysql_fetch_array($result))
{
?>
<tr>
<td style="width: 8%;"><?php echo $row['driver_user_id']; ?></td>
<td style="width: 10%;"><?php echo $row['first_name']; ?></td>
<td style="width: 10%;"><?php echo stripslashes($row['last_name']); ?></td>
<td style="width: 8%;"><?php echo $row['phone_no']; ?></td>
<td style="width: 5%;<?php if($row['isverified'] == 'Verified'){ echo 'color:green;';}
if($row['isverified'] == 'Approval'){ echo 'color:blue;';}
if($row['isverified'] == 'Not Verified'){ echo 'color:red;';}
?>"> <?php echo $row['isverified']; ?></td>
<td style="width:15%;" class="center" itemid="<?php echo $row['driver_user_id']; ?>">
<a class="btn btn-success driver_view" href="#">
<i class="icon-zoom-in icon-white driver_view"></i>
View/ Edit
</a>
<!-- <a class="btn btn-info driver_edit_form" href="#">
<i class="icon-edit icon-white"></i>
Edit
</a>-->
<a class="btn btn-danger delete_driver" href="#">
<i class="icon-trash icon-white"></i>
Delete
</a>
</td>
<?php } ?>
</tr>
</tbody>
</table>
</div>
</div><!--/span-->
</div><!--/row-->
<div class="row-fluid sortable">
</div><!--/row-->
<!-- content ends -->
</div><!--/#content.span10-->
I does not move to login page if session is expire yet it show error can't connect to database in php file first of all i check session
plz help me how to check session before any call of ajax code.
thanks and regards
You cannot use header AFTER sending data to browser, You have started sending data to browser:
<div id="content" class="span10">
Either, Instead of header you use location.href javascript or
Buffer
<? ob_start();?>
<div id="content" class="span10">
.....
if(empty($userid))
{
header('location:localhost/test/login.php');
exit;
}
......
<? ob_flush(); ?>