Seats booking system - php

So, i made a seat booking system where there are checkboxes in every seat and the user select this boxes and the seats are considered reserved.
But now i want make the user be able to give each marked seat a name. How can i do that?
seats.php
<?php include("login.php"); ?>
<html>
<head>
<title>Tickets</title>
<style>
* {
font-size: 11px;
font-family: arial;
}
</style>
<script>
function reserveSeats() {
var selectedList = getSelectedList('Reserve Seats');
if (selectedList) {
if (confirm('Do you want to reserve
selected seat/s '
+ selectedList + '?')) {
document.forms[0].oldStatusCode.value=0;
document.forms[0].newStatusCode.value=1;
document.forms[0].action='bookseats.php';
document.forms[0].submit();
} else {
clearSelection();
}
}
}
function cancelSeats() {
var selectedList = getSelectedList('Cancel Reservation');
if (selectedList) {
if (confirm('Do you want to cancel reserved seat/s ' + selectedList + '?')) {
document.forms[0].oldStatusCode.value=1;
document.forms[0].newStatusCode.value=0;
document.forms[0].action='bookseats.php';
document.forms[0].submit();
} else {
clearSelection();
}
}
}
function confirmSeats() {
var selectedList = getSelectedList('Confirm Reservation');
if (selectedList) {
if (confirm('Do you want to confirm reserved seat/s ' + selectedList + '?')) {
document.forms[0].oldStatusCode.value=1;
document.forms[0].newStatusCode.value=2;
document.forms[0].action='bookseats.php';
document.forms[0].submit();
} else {
clearSelection();
}
}
}
function getSelectedList(actionSelected) {
// get selected list
var obj = document.forms[0].elements;
var selectedList = '';
for (var i = 0; i < obj.length; i++) {
if (obj[i].checked && obj[i].name == 'seats[]') {
selectedList += obj[i].value + ', ';
}
}
// no selection error
if (selectedList == '') {
alert('Please select a seat before clicking ' + actionSelected);
return false;
} else {
return selectedList;
}
}
function clearSelection() {
var obj = document.forms[0].elements;
for (var i = 0; i < obj.length; i++) {
if (obj[i].checked) {
obj[i].checked = false;
}
}
}
function refreshView() {
clearSelection();
document.forms[0].action='<?php echo $_SERVER['PHP_SELF']; ?>';
document.forms[0].submit();
}
</script>
</head>
<body>
<table>
<tr><td width="100%" align="center">
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<input type="hidden" name="oldStatusCode" value=""/>
<input type="hidden" name="newStatusCode" value=""/>
<table width='100%' border='0'>
<tr><td align='center'>
<input type='button' value='Refresh View' onclick='refreshView();'/>
</td></tr>
</table>
</td></tr>
<tr><td width="100%" align="center">
<table width='100%' border='0'>
<tr><td align='center'>
<input type='button' value='Reserve Seats' onclick='reserveSeats()'/>
<input type='button' value='Confirm Reservation' onclick='confirmSeats()'/>
<input type='button' value='Cancel Reservation' onclick='cancelSeats()'/>
</td></tr>
</table>
</td></tr>
<tr><td width="100%" align="center">
<table width='100%' border='0'>
<tr><td align='center'>
<input type='button' value='Clear Selection' onclick='clearSelection()'/></td>
</tr>
</table>
</td></tr>
<tr><td width="100%" align="center">
<?php
/*
* Created on Mar 17, 2007
* Author: dayg
*/
$linkID = # mysql_connect("localhost", "tickets", "tickets") or die("Could not connect to MySQL server");
# mysql_select_db("tickets") or die("Could not select database");
/* Create and execute query. */
$query = "SELECT * from seats order by rowId, columnId desc";
$result = mysql_query($query);
$prevRowId = null;
$seatColor = null;
$tableRow = false;
//echo $result;
echo "<table width='100%' border='0' cellpadding='3' cellspacing='3'>";
while (list($rowId, $columnId, $status, $updatedby) = mysql_fetch_row($result))
{
if ($prevRowId != $rowId) {
if ($rowId != 'A') {
echo "</tr></table></td>";
echo "\n</tr>";
}
$prevRowId = $rowId;
echo "\n<tr><td align='center'><table border='1' cellpadding='8' cellspacing='8'><tr>";
} else {
$tableRow = false;
}
if ($status == 0) {
$seatColor = "lightgreen";
} else if ($status == 1 && $updatedby == 'user1') {
$seatColor = "FFCC99";
} else if ($status == 1 && $updatedby == 'user2') {
$seatColor = "FFCCFF";
} else if ($status == 2 && $updatedby == 'user1') {
$seatColor = "FF9999";
} else if ($status == 2 && $updatedby == 'user2') {
$seatColor = "CC66FF";
} else {
$seatColor = "red";
}
echo "\n<td bgcolor='$seatColor' align='center'>";
echo "$rowId$columnId";
if ($status == 0 || ($status == 1 && $updatedby == $_SERVER['PHP_AUTH_USER'])) {
echo "<input type='checkbox' name='seats[]' value='$rowId$columnId'></checkbox>";
}
echo "</td>";
if (($rowId == 'A' && $columnId == 7)
|| ($rowId == 'B' && $columnId == 9)
|| ($rowId == 'C' && $columnId == 9)
|| ($rowId == 'D' && $columnId == 10)
|| ($rowId == 'E' && $columnId == 8)
|| ($rowId == 'F' && $columnId == 5)
|| ($rowId == 'G' && $columnId == 13)
|| ($rowId == 'H' && $columnId == 14)
|| ($rowId == 'I' && $columnId == 14)
|| ($rowId == 'J' && $columnId == 12)
|| ($rowId == 'K' && $columnId == 14)
|| ($rowId == 'L' && $columnId == 13)
|| ($rowId == 'M' && $columnId == 9)) {
// This fragment is for adding a blank cell which represent the "center aisle"
echo "<td> </td>";
}
}
echo "</tr></table></td>";
echo "</tr>";
echo "</table>";
/* Close connection to database server. */
mysql_close();
?>
</td></tr>
<tr><td> </td></tr>
<tr><td width="100%" align="center">
<table border="1" cellspacing="8" cellpadding="8">
<tr>
<td bgcolor='lightgreen'>Available</td>
<td bgcolor='FFCC99'>Reserved user1</td>
<td bgcolor='FF9999'>Confirmed user1</td>
<td bgcolor='FFCCFF'>Reserved user2</td>
<td bgcolor='CC66FF'>Confirmed user2</td>
</tr>
</table>
</td></tr>
<tr><td> </td></tr>
<tr><td width="100%" align="center">
View Layout
</td></tr>
</table>
</form>
</body>
</html>
bookseats.php
<html>
<head>
<title>Book Seats</title>
<style>
* {
font-size: 14px;
font-family: arial;
}
</style>
</head>
<body>
<?php include("login.php"); ?>
<center>
<br/>
<br/>
<br/>
<?php
if (isset($_POST['seats']))
{
$user = $_SERVER['PHP_AUTH_USER'];
$newStatusCode = $_POST['newStatusCode'];
$oldStatusCode = $_POST['oldStatusCode'];
// open database connection
$linkID = # mysql_connect("localhost", "tickets", "tickets") or die("Could not connect to MySQL server");
# mysql_select_db("tickets") or die("Could not select database");
// prepare select statement
$selectQuery = "SELECT rowId, columnId from seats where (";
$count = 0;
foreach($_POST['seats'] AS $seat) {
if ($count > 0) {
$selectQuery .= " || ";
}
$selectQuery .= " ( rowId = '" . substr($seat, 0, 1) . "'";
$selectQuery .= " and columnId = " . substr($seat, 1) . " ) ";
$count++;
}
$selectQuery .= " ) and status = $oldStatusCode";
if ($oldStatusCode == 1) {
$selectQuery .= " and updatedby = '$user'";
}
//echo $selectQuery;
// execute select statement
$result = mysql_query($selectQuery);
//echo $result;
$selectedSeats = mysql_num_rows($result);
//echo "<br/>" . $selectedSeats;
if ($selectedSeats != $count) {
$problem = "<h3>There was a problem executing your request. No seat/s were updated.</h3>";
$problem .= "Possible problems are:";
$problem .= "<ul>";
$problem .= "<li>Another process was able to book the same seat while you were still browsing.</li>";
$problem .= "<li>You were trying to Confirm an unreserved Seat.</li>";
$problem .= "<li>You were trying to Cancel an unreserved Seat.</li>";
$problem .= "<li>You were trying to Reserve a reserved Seat.</li>";
$problem .= "<li>There was a problem connecting to the database.</li>";
$problem .= "</ul>";
$problem .= "<a href='seats.php'>View Seat Plan</a>";
die ($problem);
}
// prepare update statement
$newStatusCode = $_POST['newStatusCode'];
$oldStatusCode = $_POST['oldStatusCode'];
$updateQuery = "UPDATE seats set status=$newStatusCode, updatedby='$user' where ( ";
$count = 0;
foreach($_POST['seats'] AS $seat) {
if ($count > 0) {
$updateQuery .= " || ";
}
$updateQuery .= " ( rowId = '" . substr($seat, 0, 1) . "'";
$updateQuery .= " and columnId = " . substr($seat, 1) . " ) ";
$count++;
}
$updateQuery .= " ) and status = $oldStatusCode";
if ($oldStatusCode == 1) {
$updateQuery .= " and updatedby = '$user'";
}
// perform update
$result = mysql_query($updateQuery);
$updatedSeats = mysql_affected_rows();
if ($result && $updatedSeats == $count) {
//$mysql->commit();
echo "<h3>";
echo "You have successfully updated $updatedSeats seat/s: ";
echo "[";
foreach($_POST['seats'] AS $seat) {
$rowId = substr($seat, 0, 1);
$columnId = substr($seat, 1);
echo $rowId . $columnId . ", ";
}
echo "]";
echo "...</h3>";
} else {
//$mysql->rollback();
echo "<h3>There was a problem executing your request. No seat/s were updated.</h3>";
echo "Possible problems are:";
echo "<ul>";
echo "<li>Another process was able to book the same seat while you were still browsing.</li>";
echo "<li>You were trying to Confirm an unreserved Seat.</li>";
echo "<li>You were trying to Cancel an unreserved Seat.</li>";
echo "<li>You were trying to Reserve a reserved Seat.</li>";
echo "<li>There was a problem connecting to the database.</li>";
echo "</ul>";
}
echo "<a href='seats.php'>View Seat Plan</a>";
// Enable the autocommit feature
//$mysqldb->autocommit(TRUE);
// Recuperate the query resources
//$result->free();
mysql_close();
}
?>
</center>
</body>
</html>
EDIT:
I tried the following:
When the user submit the checkboxes, this is included:
name.php
<?php
//$mysql->commit();
session_start();
$_SESSION['rowId'] = $_POST['rowId'];
$_SESSION['columnId'] = $_POST['columnId'];
echo "<h3>";
echo "Please enter the name for each seat:<br><p>&nbsp</p>";
echo "";
foreach($_POST['seats'] AS $seat) {
$rowId = substr($seat, 0, 1);
$columnId = substr($seat, 1);
echo $rowId . $columnId . '</br><form method="post" name="input" action="pt2.php" >
<input name="name" type="text"/></br>';
}
?>
<input type="submit" name="Submit" value="insert" />
</form>
pt2.php:
<?php
// Connect to MySQL
mysql_connect("localhost", "root", "root") or die("Connection Failed");
mysql_select_db("tickets")or die("Connection Failed");
$name = $_POST['name'];
session_start();
$rowId = $_SESSION['rowId'];
$columnId = $_SESSION['columnId'];
$result = mysql_query("UPDATE seats SET updatedby='".$name."' WHERE rowId='".$rowId."' AND columnId='".$columnId."'")
or die(mysql_error());
?>
If the user selects only one seat, this code works like a charm. But when there's two or more, the $columnId and the $rowId doesn't change as it should, and only the name of the last checked seat is changed.

i think you shouldn't use jquery for this part. try using php with an html form ( show an input next to the seat it has the checkbox ) then save the data into mysql seatid, seat_userId, seat_name etc... then just pull the data and do whatever you want with it.

Related

This code is supposed to output a temperature converting table for the user once they input a start end and increment temp

My error because the user inputted a non numerical value, the if else statement to change the value of the incrementing value to a positive number if the user inputs a negative value and the change if the start value is greater that the stop value is not working either.
<?php
$banner = "Self-referring Forms w/Data Validation";
include ("./header.php");
$start = "";
$stop = "";
$incr = "";
$error = "";
$output = "";
$checkResult = false;
$MAX_ITERATIONS = 100;
?>
<h2><?php echo $output; ?></h2>
<h3><?php echo $error; ?></h3>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST" >
<p id="para6">Starting Temperature: <input
type="text" name="starting_number" size="12"<?php ?>/><br/>
<p id="para6">Stop Temperature :
<input type="text" name="stop_number" size="12" /><br/>
<p id="para6">Temperature Increment: <input type="text"
name="increment_number" size="12" /><br/></p>
<input id="para6" type="submit" value="Create Temperature Conversion Table" name="calculate"/>
<?php
error_reporting(E_ERROR | E_PARSE);
try
{
if($_SERVER["REQUEST_METHOD"] == "GET"){
$start = "";
$stop = "";
$incr = "";
}
else if($_SERVER["REQUEST_METHOD"] == "POST")
{
$start=(double)trim($_POST["starting_number"]);
$stop=(double)trim($_POST["stop_number"]);
$incr=(double)trim($_POST["increment_number"]);
$num = (double)($stop-$start)/$incr;
if($start == "" || $stop == "" || $incr == "" || $num == "")
{
//means the user did not enter anything
$error .= "The text boxes cannot be blank.";
echo $error;
}
else if($num>$MAX_ITERATIONS)
{
$error .= "The conditions will cause too many iterations (max. 100), therefore (for the
sake of server resources) your request is denied.";
echo $error;
}
This is where I need help
else if($start >= $stop)
{
$start == $stop;
$stop == $start;
}
else if($incr == "0")
{
$error .= "You must enter a non-zero increment.";
echo $error;
}
else if($incr < "0")
{
$incr == $incr * (-1);
}
else if($start == input type="text" || $stop == input type="text" ||$incr == input
type="text" || $num == input type="text")
{
$error .= "You must enter a numerical value";
echo $error;
}
The rest is just for you to see what the rest of my code looks like
else
{
echo "<table border='1'>";
echo "<tr>";
echo "<th>Celcius</th>";
echo "<th>Fahrenheit</th>";
echo "</tr>";
for($i=$start; $i<=$stop; $i += $incr)
{
echo "<tr>";
echo "<td>". $i . "°</td>";
echo "<td>". (($i * 9/5) + 32 ). "°</td>";
echo "</tr>";
}
echo "</table>";
}
if($error == "")
{
$output = "";
}
else
{
$error .= "<br/>Please try again.";
}
}
}
catch(DivisionByZeroError $e)
{
echo "The text boxes cannot be blank.";
}
catch(Exception $e)
{
echo 'Please Enter correctly';
}
?>
</form>
<?php
include ("./footer.php");
?>

ON/OFF value status always offline

I have this code and when i click button "off"status is always off but in db is on
example
i click on at galery query in db set to value = 1 (on) but status says off
if i click off still say is off
show.php
<?php
$mysqli = new mysqli("localhost", "root", "pass", "strona");
//----------
function topnews()
{
$query="SELECT topnews FROM opcje";
$topnews=$result=mysql_query($query);
if($topnews == 1)
{
echo "<div id='on'>wlączone</div>";
}
else if($topnews == 0)
{
echo "<div id='off'>wyłączone</div>";
}
}
//------------
function galeria()
{
$query2="SELECT galeria FROM opcje";
$galeria=$result=mysql_query($query2);
if($galeria == 1)
{
echo "<div id='on'>wlączone</div>";
}
else
{
echo "<div id='off'>wyłączone</div>";
}
}
//--------------
function logowanie()
{
$query3="SELECT logowanie FROM opcje";
$logowanie=$result=mysql_query($query3);
if($logowanie == 1)
{
echo "<div id='on'>wlączone</div>";
}
else
{
echo "<div id='off'>wyłączone</div>";
}
}
//--------------
function rejestracja()
{
$query4="SELECT rejestracja FROM opcje";
$rejestracja=$result=mysql_query($query4);
if($rejestracja == 1)
{
echo "<div id='on'>wlączone</div>";
}
else
{
echo "<div id='off'>wyłączone</div>";
}
}
$mysqli->close();
?>
<form action="onoff.php" method="post">
<tr>
<td><p><h3>Okienka na głównej</h3></p><hr></td>
</tr>
<tr>
<td>Status<br></td>
<td><?php topnews(); ?><br></td>
<td><input type="submit" value="wlacz" name="on"/></td>
<td><input type="submit" value="wylącz" name="off"/></td>
</tr>
<tr>
<td><p><h3><hr>Galeria</h3></p><hr></td>
</tr>
<tr>
<td>Status<br></td>
<td><?php galeria(); ?><br></td>
<td><input type="submit" value="wlacz" name="on2"/></td>
<td><input type="submit" value="wylącz" name="off2"/></td>
</tr>
<tr>
<td><p><h3><hr>Logowanie</h3></p><hr></td>
</tr>
<tr>
<td>Status<br></td>
<td><?php logowanie(); ?><br></td>
<td><input type="submit" value="wlacz" name="on3"/></td>
<td><input type="submit" value="wylącz" name="off3"/></td>
</tr>
<tr>
<td><p><h3><hr>Rejestracja</h3></p><hr></td>
</tr>
<tr>
<td>Status<br></td>
<td><?php rejestracja(); ?><br></td>
<td><input type="submit" value="wlacz" name="on4"/></td>
<td><input type="submit" value="wylącz" name="off4"/></td>
</tr>
</form>
onoff.php
<?php
$con=mysqli_connect("localhost","root","pass","strona");
// Check connection
if (mysqli_connect_errno()) {
echo "Błąd podczas łączenia z bazą danych: " . mysqli_connect_error();
}
//===========//top news//===============//
if(isset($_POST['on']))
{
$on = $_POST['on'];
$sql = "UPDATE opcje SET topnews = '1'";
echo "<script>alert('Włączono Pomyslnie');</script>";
header("Refresh: 1; url=wlwyl.php");
}
else if(isset($_POST['off']))
{
$off = $_POST['off'];
$sql = "UPDATE opcje SET topnews = '0'";
echo "<script>alert('Wyłączono Pomyslnie');</script>";
header("Refresh: 1; url=wlwyl.php");
}
//===========//galeria//===============//
if(isset($_POST['on2']))
{
$on2 = $_POST['on2'];
$sql = "UPDATE opcje SET galeria = '1'";
echo "<script>alert('Włączono Pomyslnie');</script>";
header("Refresh: 1; url=wlwyl.php");
}
else if(isset($_POST['off2']))
{
$off2 = $_POST['off2'];
$sql = "UPDATE opcje SET galeria = '0'";
echo "<script>alert('Wyłączono Pomyslnie');</script>";
header("Refresh: 1; url=wlwyl.php");
}
//===========//logowanie//===============//
if(isset($_POST['on3']))
{
$on3 = $_POST['on'];
$sql = "UPDATE opcje SET logowanie = '1'";
echo "<script>alert('Włączono Pomyslnie');</script>";
header("Refresh: 1; url=wlwyl.php");
}
else if(isset($_POST['off3']))
{
$off3 = $_POST['off'];
$sql = "UPDATE opcje SET logowanie = '0'";
echo "<script>alert('Wyłączono Pomyslnie');</script>";
header("Refresh: 1; url=wlwyl.php");
}
//===========//rejestracja//===============//
if(isset($_POST['on4']))
{
$on4 = $_POST['on'];
$sql = "UPDATE opcje SET rejestracja = '1'";
echo "<script>alert('Włączono Pomyslnie');</script>";
header("Refresh: 1; url=wlwyl.php");
}
else if(isset($_POST['off4']))
{
$off4 = $_POST['off'];
$sql = "UPDATE opcje SET rejestracja = '0'";
echo "<script>alert('Wyłączono Pomyslnie');</script>";
header("Refresh: 1; url=wlwyl.php");
}
//============//kiedys cos//==============//
if (!mysqli_query($con,$sql)) {
die('Error: ' . mysqli_error($con));
}
mysqli_close($con);
?>
Your code has a ton of these in them:
if($topnews = 1)
This isn't what you want to do - It's assigning the value of 1 to $topnews, so this if statement is always true and is always executed. You're looking for:
if($topnews == 1)
Now, onto your code:
$topnews=$result=mysql_query($query);
You shouldn't be using mysql_* functions anymore. But, the value of $topnews is a MySQL result object, and doesn't have the value from the database. You need to fetch it, something similar to:
$result = mysql_query( $query);
$row = mysql_fetch_array($result);
$topnews = $row['topnews'];
You're using the wrong comparison operators.
Use == or === in the if statement.
To make it even safer, swap the constant and the variable!
if (1 == $galeria)
is safer than
if ($galeria == 1)

Keeping Dynamic Table Rows shown after form post errors

I have a dynamic HTML table that allows users to enter receipt items in, and they can add as many rows as necessary.
If they forget to fill out a field upon form POST, I want all those rows with the data to stay shown, instead what happens, is they dynamic rows disappear and no values are saved in the one row that shows on default.
How can I achieve having those dynamic table rows shown with the values they've entered to avoid them having to enter all the data again?
<?php
if(isset($saveAdd))
{
$expenseType = safeDataMySQL($_POST['expenseType']);
//Save page, redirect to same page but increment receipt number.
if(empty($_POST['expenseNumber']))
{
//New expense so no records have been created as of yet. Otherwise, this would be stored in hidden field.
$getRef = mysql_query("SELECT CAST(SUBSTRING(refNumber,4) AS UNSIGNED INTEGER) AS referenceNumber FROM expense_main ORDER BY referenceNumber DESC LIMIT 1") or die("Ref No: " . mysql_error());
if(mysql_num_rows($getRef) > 0)
{
while($refData = mysql_fetch_array($getRef))
{
//Expense Number!
$refNumber = $refData['referenceNumber'];
$refNumber = ($refNumber + 1);
}
$ins = mysql_query("INSERT INTO `expense_main` (`respid`, `refNumber`, `dateCreated`, `draftMode`, `expenseType`) VALUES ('".$respid."', 'USA".$refNumber."', NOW(), '1', '".$expenseType."')") or die("Expense Insert: " . mysql_error());
$expClaimNumber = 'USA'.$refNumber;
}
}
else
{
$expClaimNumber = safeDataMySQL($_POST['expenseNumber']);
}
//Get the next receipt in line as well
$getRec = mysql_query("SELECT receiptNumber FROM expense_details ORDER BY receiptNumber DESC LIMIT 1") or die("Get Receipt: " . mysql_error());
if(mysql_num_rows($getRec) > 0)
{
while($recData = mysql_fetch_array($getRec))
{
$receiptNumber = $recData['receiptNumber'];
$receiptNumber = ($receiptNumber + 1);
}
}
$fields = array('recLineDate_', 'recLineCategory_', 'recLineDescr_', 'recLineAmount_');
foreach ($fields as $field)
{
foreach ($_POST[$field] as $key=>$line)
{
$returnArray[$key][$field] = $line;
}
}
foreach ($returnArray as $lineItem)
{
if(empty($lineItem['recLineDate_']))
{
$Errors[] = 'You forgot to enter the receipt date.';
}
else
{
$recDate = safeDataMySQL($lineItem['recLineDate_']);
}
if(empty($lineItem['recLineCategory_']))
{
$Errors[] = 'You forgot to enter a category.';
}
else
{
$recCategory = safeDataMySQL($lineItem['recLineCategory_']);
}
if(empty($lineItem['recLineDescr_']))
{
$Errors[] = 'You forgot to enter a description.';
}
else
{
$recDescr = safeDataMySQL($lineItem['recLineDescr_']);
}
if(empty($lineItem['recLineAmount_']))
{
$Errors[] = 'You forgot to enter your receipt amount.';
}
else
{
$recAmount = safeDataMySQL($lineItem['recLineAmount_']);
}
if(empty($_POST['alternateBranch']))
{
$alternateBranch = '0';
}
else
{
$alternateBrach = $_POST['alternateBranch'];
}
if(!isset($Errors))
{
$recDate = date("Y-m-d", strtotime($recDate));
$ins = mysql_query("INSERT INTO `expense_details` (`receiptNumber`, `claimId`, `alternateBranch`, `dateAdded`, `expenseDate`, `expenseDescription`, `expenseAmount`, `categoryId`)
VALUES ('".$receiptNumber."', '".$expClaimNumber."', '".$alternateBranch."', NOW(), '".$recDate."', '".$recDescr."', '".$recAmount."', '".$recCategory."')") or die("Could not insert receipt: " . mysql_error());
$nextReceipt = ($receiptNumber + 1);
//Redirect to same page, incrementing the receipt number by 1.
header('Location: createExpense.php?expenseNumber='.$expClaimNumber.'&receiptNum='.$nextReceipt);
}
}
}
$expenseNumber = safeData($_GET['expenseNumber']);
$receiptNumber = safeData($_GET['receiptNum']);
if (isset($Errors))
{
echo "<div align='center'><span class='errormessagered'><ul class='errors'>";
foreach ($Errors as $Error)
{
echo "<li>".$Error."</li>";
echo '<br />';
}
echo "</ul></span></div>";
}
?>
<form name="createNew" method="POST" action="">
<div id="row">
<div id="left">
<strong>Receipt Items:</strong>
</div>
<div id="right">
<i>Only add another line to the receipt below IF you have multiple items on one receipt.</i>
<br /><br />
<table border="0" width="825px" cellspacing="0" cellpadding="5" name="receipts" id = "receipts">
<thead>
<tr>
<th class="colheader" width="120px">Date</th>
<th class="colheader" width="120px">Category</th>
<th class="colheader" width="120px">Description</th>
<th class="colheader" width="120px">Amount</th>
<th class="colheader" width="145px"><span class="boldblacklinks">[Add +]</span></th>
</tr>
</thead>
<tbody class="lineBdy">
<tr id="line_1" class="spacer">
<td><input type="text" class="date fieldclasssm" id="recLineDate[]" name="recLineDate_[]" size="10" value = "<?=date("m/d/Y", strtotime($today))?>"/></td>
<td><select name="recLineCategory_[]" class="fieldclasssm">
<option value = "">Select a Category...</option>
<?php //Get Categories
$getCats = mysql_query("SELECT id, nominalName FROM expense_nominalCodes ORDER BY id") or die("Get Cats: " . mysql_error());
if(mysql_num_rows($getCats) > 0)
{
while($catData = mysql_fetch_array($getCats))
{
echo '<option value = "'.$catData['id'].'"'; if($catData['id'] == $_POST['recLineCategory_']) { echo "Selected = 'SELECTED'"; } echo '>'.$catData['nominalName'] . '</option>';
}
}
?>
</select>
</td>
<td><input type="text" class="lineDescr fieldclasssm" name="recLineDescr_[]" id="recLineDescr[]" value = "<?=$_POST['recLineDescr']?>" size="40" /></td>
<td colspan = "2"><input type="text" class="sum lineAmount fieldclasssm" name="recLineAmount_[]" id="recLineAmount[]" value = "<?=$_POST['recLineAmount']?>" size="12" /></td>
</tr>
</tbody>
</table>
</div>
" />
" />
<script type="text/javascript">
$(document).ready(function () {
$('.date').change(function () {
$('.date').val($('.date:nth-of-type(1)').val());
});
});
//Add new table row & clone date field
$('#add').on('click', function(){
addReceiptItem();
$('.date').focus(function() {
$(this).select();
});
$('.receipt').focus(function() {
$(this).select();
});
});
function addReceiptItem(){
var lastID = $('tr[id*="line_"]').length,
newTds = $('tr[id="line_' + lastID + '"] td').clone(),
newRow = document.createElement('tr');
// add new id and class to row, append cloned tds
$(newRow)
.attr('id', 'line_' + (lastID + 1 ))
.attr('class', 'spacer')
.append(newTds);
$(newRow).find('input').not(':eq(0)').val('');
// $(newRow).find('class').not(':eq(0)').not(':eq(0)').val('');
//add the new row to the table body
$('tbody.lineBdy').append(newRow);
$('.receipt').attr('readonly', true);
$('.date').attr('readonly', true);
};
</script>
Just to get you started. You can add the rows from $_POST["rows"]
foreach ($_POST["rows"] as $rowstring) {
list($date, $cat, $desc, $amt) = explode(",", $rowstring)
?>
<td><?php echo $date; ?></td>
<td><?php echo $cat; ?></td>
<td><?php echo $desc; ?></td>
<td><?php echo $amt; ?></td>
<td> </td>
<?php
}
Assuming you add a hidden input with a comma delimited string each time a dynamic row is added.
FWIW, I would also recommend doing all of the database queries (ie $getCats = ...) prior to rendering anything to the screen so that in case the 'or die()' happens, you wont get a half rendered page.

PHP image upload in admin section only allowing client to upload 19 images

I've been working on a client's admin panel (A photography company uploading images to a client's gallery), when I took on the role as web developer, it only allowed him to upload 30 images, even though there was 100 file upload boxes. This was fixed simply by changing the for loop to run 100 times. This fixed this problem.
But recently, without even touching the code, my client can only upload 19 images.. I haven't changed this form, he has previously uploaded 40+ images, so I don't quite understand what could have happened.. I've checked the code over and over, and can't quite seem to pinpoint the issue. Could this be server side, as I've recently moved from his old developer's host to my hostgator account. Maybe something in the htaccess? I add this because the image label's update, but not the image itself (I can't find it uploaded either, after it has been posted, but my browser shows it uploading)
Here is the edit gallery code itself, if it gives any assistance to the problem:
<?php
require_once("../conn.php");
require_once("access.php");
require_once("GalleryNavigation.php");
require_once("dThumbMaker.inc.php");
/////////////common varilable
$__table = "devbg_gallery";
$__page = $_SERVER['PHP_SELF'];
$__page2 = "AddGallery.php";
$__id = "ItemID";
$__pagetitle = "GALLERY";
$__uploadfolder = "../myimages/";
$__thumbuploadfolder = "../myimages/thumbs/";
$__imageprefix = "Gallery";
$Thumb_Imgwidth = 200;
$Thumb_Imgheight = 77;
/////////////
if(isset($_POST[ds]))
{
if(count($_POST['DelItem']) > '0')
{
while(list(, $value) = each($_POST['DelItem']))
{
$DelInfo = $value;
$r2 = mysql_query("select * from ".$__table." where ".$__id." = '$DelInfo' ") or die(mysql_error());
$a2 = mysql_fetch_array($r2);
for($i=1;$i<=100;$i++)
{
if(file_exists($__uploadfolder.$a2['ItemImage'.$i]))
{
unlink($__uploadfolder.$a2['ItemImage'.$i]);
unlink($__thumbuploadfolder.$a2['ItemImage'.$i]);
}
}
//delete the product
mysql_query("delete from ".$__table." where ".$__id." = '".$DelInfo."' ") or die(mysql_error());
}
}
}
if(isset($_POST[s100]))
{
$MyProductName = mysql_escape_string(trim(stripslashes(strip_tags($_POST[ProductName]))));
$Description = mysql_escape_string(trim(strip_tags(stripslashes($_POST['Description']))));
$Link = trim(strip_tags(stripslashes($_POST['Link'])));
$TopLabel = cleaninput($_POST['TopLabel'],"mres|he|tr");
$status = $_POST['status'];
$NewTopLabelName = $TopLabel;
if(!empty($_FILES['TopImage']['name']))
{
$NewTopImageName = $__imageprefix.$t.$_FILES['TopImage']['name'];
if(is_uploaded_file($_FILES['TopImage']['tmp_name']))
{
move_uploaded_file($_FILES['TopImage']['tmp_name'], $__uploadfolder.$NewTopImageName);
$NewTopImageName = $NewTopImageName;
$NewTopLabelName = $TopLabel;
//lets make the thumb
$tm = new dThumbMaker;
$load = $tm->loadFile($__uploadfolder.$NewTopImageName);
if($load === true)
{ // Note three '='
$tm->cropCenter($Thumb_Imgwidth, $Thumb_Imgheight);
$tm->build($__thumbuploadfolder.$NewTopImageName);
}
else
{
// Error returned.
$error .= "Could not open the file '".$NewTopImageName."'.\n";
$error .= "The error returned was: ";
$error .= $load;
}
}
}
else
{
$NewTopImageName = $_POST['OldTopImage'];
$NewTopLabelName = $NewTopLabelName;
}
for($i=1;$i<=100;$i++) //This is where I believe the problem is --------------------------------------------------------------------
{
${'NewsItemLabel'.$i} = cleaninput($_POST['ItemLabel'.$i],"mres|he|tr");
$ItemLabels .= "ItemLabel".$i ." = '". cleaninput($_POST['ItemLabel'.$i],"mres|he|tr") ."',";
if(!empty($_FILES['ItemImage'.$i]['name']))
{
${'NewImageName'.$i} = $__imageprefix.$t.$_FILES['ItemImage'.$i]['name'];
if(is_uploaded_file($_FILES['ItemImage'.$i]['tmp_name']))
{
move_uploaded_file($_FILES['ItemImage'.$i]['tmp_name'], $__uploadfolder.${'NewImageName'.$i});
//lets make the thumb
$tm = new dThumbMaker;
$load = $tm->loadFile($__uploadfolder.${'NewImageName'.$i});
if($load === true)
{ // Note three '='
$tm->cropCenter($Thumb_Imgwidth, $Thumb_Imgheight);
$tm->build($__thumbuploadfolder.${'NewImageName'.$i});
$ItemImages .= "ItemImage".$i ." = '". ${'NewImageName'.$i} ."',";
}
else
{
// Error returned.
$error .= "Could not open the file '".${'NewImageName'.$i}."'.\n";
$error .= "The error returned was: ";
$error .= $load;
}
} else { }
}
else
{
${'NewImageName'.$i} = $_POST['OldItemImage'.$i];
}
}
if(empty($error))
{
//update the database
$q1 = "update ".$__table." set
ItemName = '".$MyProductName."',
Description = '".$Description."',
Link = '".$Link."',
TopImage = '$NewTopImageName',
Toplabel = '$NewTopLabelName',
".$ItemImages.$ItemLabels."
status = '".$status."'
where ".$__id." = '".$_POST[$__id]."' ";
mysql_query($q1) or die(mysql_error());
echo "<br><br><center>Gallery Updated</center>";
}
}
if(!empty($_GET[$__id]))
{
$_POST[$__id] = $_GET[$__id];
}
if(!empty($_POST[$__id]))
{
//get the product info
$r1 = mysql_query("select * from devbg_gallery where ".$__id." = '".$_POST[$__id]."' ") or die(mysql_error());
$a1 = mysql_fetch_array($r1);
echo $error;
?>
<form method=post action=EditGallery.php enctype="multipart/form-data">
<table align=center width=740>
<caption align=center><b>Gallery Name:</b></caption>
<tr>
<td align='right'>Event Name:</td>
<td><input type=text class=input name="ProductName" value="<?php echo $a1['ItemName'];?>"></td>
</tr>
<TR>
<td align='right'>Description:</td>
<td><textarea name="Description"cols=60 rows=10><?php echo $a1['Description'];?></textarea></td>
</TR>
<?php
if(!empty($a1['TopImage']))
{
$v = $a1['TopImage'];
echo "<tr>";
echo "<td></td><td><img src='".$__uploadfolder.$v."' width='72' border='0'><br><a href='DeleteImage.php?".$__id."=".$a1[$__id]."&Type=gallery&file=".$v."&img=top'>Delete Image</a></td>";
echo "</tr>";
}
?>
<tr>
<td align='right'>Top Image:</td>
<td><input type=file name=TopImage></td>
</tr>
<tr>
<td align='right'>Top Image Label:</td>
<td><input type=text name=TopLabel value="<?php echo $a1['TopLabel'];?>"></td>
</tr>
<?php
for($i = 1; $i <= 100; $i++)
{
if($a1['ItemImage'.$i] != "")
{
echo "<tr>";
echo "<td></td><td><img src='".$__uploadfolder.$a1['ItemImage'.$i]."' width='72' border='0'><br><a href='DeleteImage.php?".$__id."=".$a1[$__id]."&Type=gallery&file=".$a1['ItemImage'.$i]."&id=".$i."'>Delete Image</a></td>";
echo "</tr>";
}
echo "<TR><TD align='right'>Image $i: </TD><TD><input type=file name='ItemImage$i'></TD></TR>\n\t";
echo "<TR><TD align='right'>Label $i: </td><TD><input type=text name='ItemLabel".$i."' value='".cleaninput($a1['ItemLabel'.$i],"ss|hd|tr")."' size='79'></TD></TR>\n\t";
echo "<input type='hidden' name='OldImage$i' value='".$a1['ItemImage'.$i]."'>";
echo "<input type='hidden' name='OldLabel$i' value='".cleaninput($a1['ItemLabel'.$i],"ss|hd|tr")."'>";
}
?>
<tr>
<td></td>
<td>
<input type="hidden" name="OldTopImage" value="<?php echo $a1['TopImage'];?>">
<input type="hidden" name="OldTopLabel" value="<?php echo $a1['TopLabel'];?>">
<input type="hidden" name=<?php echo $__id;?> value="<?php echo $_POST[$__id];?>">
<input type="submit" name="s100" value="Edit Gallery">
</td>
</tr>
</form>
<?php
exit();
}
if(!empty($_GET[Start]))
{
$Start = $_GET[Start];
}
else
{
$Start = '0';
}
$ByPage = "10";
//get the products list
$r1 = mysql_query("select * from devbg_gallery order by ordering_id ASC limit $Start,$ByPage") or die(mysql_error());
if(mysql_num_rows($r1) == '0')
{
echo "<center>You have no items at the database!</center>";
exit();
}
?>
<form method=post>
<table align=center width=500 cellspacing="0" cellpadding="3">
<tr style="background-color:#b5c3ce; color:white; font-family:verdana; font-size:11; font-weight:bold">
<td>Title</td>
<td>User</td>
<td align='center'>Edit</td>
<td align='center'>Delete</td>
</tr>
<?php
$col = "white";
$i=0;
while($a1 = mysql_fetch_array($r1))
{
$r2 = mysql_query("select * from tbl_register where GID = '".$a1['ItemID']."'") or die(mysql_error());
$a2 = mysql_fetch_array($r2);
$name = $a2['firstname'] . " " . $a2['lastname'];
$i++;
if($col == "white" )
{
$col = "#f3f6f8";
}
else
{
$col = "white";
}
echo "<tr bgcolor=$col>
<td>".$a1['ItemName']."</td>
<td>".$name."</td>";
echo "<td align=center><input type=radio name='".$__id."' value='".$a1[$__id]."'></td>
<td align='center'><input type='checkbox' name='DelItem[]' value='".$a1[$__id]."'></td>
</tr>\n\n";
}
echo "<tr>
<td colspan=4 align=right><br>\n\t<input class=input type=submit name=ds value='Edit Selected'> <input type='submit' class='input' name='ds' value='Delete Selected'></td>
</tr>
</table>
</form>\n\n";
//build the "next" - "prev" navigatioin
$qnav = "select * from ".$__table." order by ItemName ";
$rnav = mysql_query($qnav) or die(mysql_error());
$rows = mysql_num_rows($rnav);
echo "<br><table align=center width=600>";
echo "<td align=center><font face=verdana size=2> | ";
$pages = ceil($rows/$ByPage);
for($i = 0; $i <= ($pages); $i++)
{
$PageStart = $ByPage*$i;
$i2 = $i + 1;
if($PageStart == $Start)
{
$links[] = " <span class=bodybold>$i2</span>\n\t ";
}
elseif($PageStart < $rows)
{
$links[] = " <a class=bodybold href=EditGallery.php?Start=$PageStart>$i2</a>\n\t ";
}
}
$links2 = implode(" | ", $links);
echo $links2;
echo "| </td>";
echo "</table><br>\n";
?>
<?php include("footer.php");?>
If there's any other information I could provide that would help find a solution, I can post it straight up. This problem has really messed with my head, and my client needs his gallery running! Makes me wish I could have coded this myself and got there before his previous developer. Thanks everybody!
A friend of mine figured out that when I moved host, my max_file_uploads setting in my php.ini was set to 20, and that the code you see above loops each image and tries to upload it, even if there is no image, which explains why even if I only tried to upload 1 by itself, it wouldn't upload any after 19. Just a simple setting overlooked.
Changed this to max_file_uploads = 100 in my ini, everything works fine now, client happy!

PHP prints out 1,458 MYSQL jquery 1072

I am not sure why, but when I run the following MySQL query it returns 1458 results. It then puts those results in a JSON format, which my jQuery script then outputs, but for some reason it is only returning 1072 and also takes around 15 seconds for it to show. Included is the jQuery script I made.
SELECT
customer.customer_id,
customer.HQStatus,
date_format(customer.CreatedTime, '%d-%m-%Y') as CreatedTime,
date_format(customer.ModifiedDate, '%d-%m-%Y') as ModifiedDate,
customer.AMStatus,
customer.LeadOwnerId,
customer.Company,
customer.TradingName,
customer.FirstName,
customer.LastName,
customer.LeadStatus,
customer.Phone,
customer.Email,
user.firstname as stafffirstname,
user.lastname as stafflastname
FROM
customer_detail as customer,
admin_userlogin as user
WHERE user.id = customer.LeadOwnerId
ORDER BY customer.CreatedTime DESC
jQuery code is a little big:
function listallleads(){
$.getScript('js/quicksearch.js', function(data, textStatus){});
$.getScript('js/cornz.js', function(data, textStatus){});
numberofleads = null;
$.getJSON('system/classes/core.php?task=listmyleads&userid='+userid+'&usertype='+usertype+'&callback=?', function(dataleads) {
$.each(dataleads,function(i, myleads){
numberofleads = i;
var businessname = "";
if(myleads.Company == null || myleads.Company == "null" || myleads.Company == "")
{
businessname = myleads.TradingName;
}
else
{
businessname = myleads.Company;
}
if(myleads.ho > 1)
{
myleads.ho = "Complete";
}
else
{
myleads.ho = "Pending";
}
if(myleads.AMStatus == "1")
{
myleads.AMStatus = "Confirmed";
}
else if(myleads.AMStatus == "3")
{
myleads.AMStatus = "Canceled";
}
else if(myleads.AMStatus == "4")
{
myleads.AMStatus = "Does Not Have Mobile";
}
else if(myleads.AMStatus == "5")
{
myleads.AMStatus = "Not Contactable";
}
else if(myleads.AMStatus == "6")
{
myleads.AMStatus = "Re-Send Welcome Pack";
}
else if(myleads.AMStatus == "7")
{
myleads.AMStatus = "Welcome Pack Sent";
}
else if(myleads.AMStatus == "8")
{
myleads.AMStatus = "Swipe Confirmed";
}
else if(myleads.AMStatus == "9")
{
myleads.AMStatus = "Refussed Banking Details";
}
else
{
myleads.AMStatus = "Not Confirmed";
}
leadstatus = leadstatusselect(myleads.LeadStatus);
if(myleads.AMStatus == "1")
{
myleads.AMStatus = "one";
}
if(myleads.AMStatus == "3")
{
myleads.AMStatus = "red";
}
if(myleads.HQStatus == 0)
{
myleads.HQStatus = "Please Select";
}
else if(myleads.HQStatus == 2)
{
myleads.HQStatus = "iNcard Loaded $1";
}
else if(myleads.HQStatus == 3)
{
myleads.HQStatus = "iNcard Loaded $5";
}
else if(myleads.HQStatus == 4)
{
myleads.HQStatus = "Terminal Verified";
}
var s = myleads.Phone;
s = s.replace('(', '');
s = s.replace(')', '');
s = s.replace(/ /g, '');
myleads.Phone = s;
//alert(s);
cssstats = "lead"+myleads.AMStatus;
$("tbody").append('<tr id="'+myleads.customer_id+'" class="'+cssstats+'">'+
' <td id="row" class="small"><input id="'+myleads.customer_id+'" type="checkbox"></td>'+
' <td class="field">'+myleads.CreatedTime+'</td>'+
' <td class="field">'+myleads.stafffirstname+'</td>'+
' <td class="companysize">'+businessname+'</td>'+
' <td class="field">'+myleads.FirstName+' '+myleads.LastName+'</td>'+
' <td class="field">'+myleads.Phone+'</td>'+
' <td class="field" class="leadstatus">'+leadstatus+'</td>'+
' <td class="field" class="hostatus" style="display:hidden;">'+myleads.AMStatus+'</td>'+
' <td class="field" class="hostatus" style="display:hidden;">'+myleads.HQStatus+'</td>'+
' <td class="bigger temail">'+myleads.Email+'</td>'+
' <td class="last field">'+myleads.ModifiedDate+'</td>'+
' </tr>');
});
qs.cache();
});
if(usertype == 3)
{
leadtype = "A/M Status";
}
else
{
leadtype = "Lead Status";
}
$("#todo_bg").hide();
$("#menuarea").html('<a id="gotohome"><div id="backmain" class="backbg">Back</div></a><div id="nav" class="backbgright">Manage Business Lead</div>'+
'<div id="dowithleads"><button id="selectall" class="blackbutton export"><input type="checkbox" class="checkbox checkall" value="Yes" style="float:left;">Select All</button><button id="editlisting" class="blackbutton manage">Edit Listing</button><button id="sendemailout" class="blackbutton manage">Send Message</button> <button id="deletelead" class="blackbutton manage">Delete Lead</button>'+
'<div id="searchbox"><input type="text" name="search" value="" id="searchleads" placeholder="Search" autofocus /></div>'+
'</div>'+
'<div id="dowithleads" style="width:980px; overflow:scroll;"><table cellpadding="0" cellspacing="0" border="0" class="sortable paginated scrollTable" id="manageleads" style="text-align:left;">'+
' <thead class="fixedHeader">'+
' <tr>'+
' <th class="small" id="first"></th>'+
' <th class="field" class="ui-tableFilter-date">Created</th>'+
' <th class="field">Lead Owner</th>'+
' <th class="companysize">Trading Name</th>'+
' <th class="field">Customer Name</th>'+
' <th class="field">Phone No.</th>'+
' <th class="field" class="leadstatus">Lead Status</th>'+
' <th class="field" class="hostatus" style="display:hidden;">A/M Status</th>'+
' <th class="field" class="hostatus" style="display:hidden;">H/Q Status</th>'+
' <th id="emails" class="bigger">Email</th>'+
' <th class="field">Mod Date</th>'+
' </tr>'+
' </thead>'+
' <tbody class="scrollContent"></tbody>'+
'</table></div><div id="noloeads" style="float:right; margin:5px;"></div>');
if(usertype == 1 || usertype == 3 || usertype == 4)
{
$("#dowithleads").append('<button id="printlisting" class="blackbutton manage">Print W/P Letter</button>');
}
if(usertype == 1 || usertype == 3 || usertype == 4)
{
$("#dowithleads").append('<button id="exportlisting" class="blackbutton export">Export</button>');
}
if(usertype == 1)
{
$('.hostatus').show();
}
if(usertype ==3)
{
$('.hostatus').show();
$('.leadstatus').hide();
}
var script = document.createElement('link');
script.href = 'theme/style/manageleads.css';
script.rel = 'stylesheet';
script.type = 'text/css';
document.getElementsByTagName('head')[0].appendChild(script);
if ($.browser.msie && $.browser.version == 8) {
var script = document.createElement('link');
script.href = 'theme/style/ie-manageleads.css';
script.rel = 'stylesheet';
script.type = 'text/css';
document.getElementsByTagName('head')[0].appendChild(script);
}
setTimeout(function(){
setTimeout(function(){
$("table").tableFilter({ dialog: { modal: false } });
updatecounter(numberofleads);
},90);
var qs = $('input#searchleads').quicksearch('table#manageleads tbody tr');
},2000);
}
I fixed the issue by the following. I will say this is NOT the best way to do it.
function listallleads(){
$.getScript('js/quicksearch.js', function(data, textStatus){});
$.getScript('js/cornz.js', function(data, textStatus){});
var number;
$.getJSON('system/classes/core.php?task=listmyleads&userid='+userid+'&usertype='+usertype+'&callback=?', function(dataleads) {
number = dataleads.length;
$.each(dataleads,function(i, myleads){
numberofleads = i;
var businessname = "";
if(myleads.Company == null || myleads.Company == "null" || myleads.Company == "")
{
businessname = myleads.TradingName;
}
else
{
businessname = myleads.Company;
}
if(myleads.ho > 1)
{
myleads.ho = "Complete";
}
else
{
myleads.ho = "Pending";
}
if(myleads.AMStatus == "1")
{
myleads.AMStatus = "Confirmed";
}
else if(myleads.AMStatus == "3")
{
myleads.AMStatus = "Canceled";
}
else if(myleads.AMStatus == "4")
{
myleads.AMStatus = "Does Not Have Mobile";
}
else if(myleads.AMStatus == "5")
{
myleads.AMStatus = "Not Contactable";
}
else if(myleads.AMStatus == "6")
{
myleads.AMStatus = "Re-Send Welcome Pack";
}
else if(myleads.AMStatus == "7")
{
myleads.AMStatus = "Welcome Pack Sent";
}
else if(myleads.AMStatus == "8")
{
myleads.AMStatus = "Swipe Confirmed";
}
else if(myleads.AMStatus == "9")
{
myleads.AMStatus = "Refussed Banking Details";
}
else
{
myleads.AMStatus = "Not Confirmed";
}
leadstatus = leadstatusselect(myleads.LeadStatus);
if(myleads.AMStatus == "1")
{
myleads.AMStatus = "one";
}
if(myleads.AMStatus == "3")
{
myleads.AMStatus = "red";
}
if(myleads.HQStatus == 0)
{
myleads.HQStatus = "Please Select";
}
else if(myleads.HQStatus == 2)
{
myleads.HQStatus = "iNcard Loaded $1";
}
else if(myleads.HQStatus == 3)
{
myleads.HQStatus = "iNcard Loaded $5";
}
else if(myleads.HQStatus == 4)
{
myleads.HQStatus = "Terminal Verified";
}
var s = myleads.Phone;
s = s.replace('(', '');
s = s.replace(')', '');
s = s.replace(/ /g, '');
myleads.Phone = s;
//alert(s);
cssstats = "lead"+myleads.AMStatus;
$("tbody").append('<tr id="'+myleads.customer_id+'" class="'+cssstats+'">'+
' <td id="row" class="small"><input id="'+myleads.customer_id+'" type="checkbox"></td>'+
' <td class="field">'+myleads.CreatedTime+'</td>'+
' <td class="field">'+myleads.stafffirstname+'</td>'+
' <td class="companysize">'+businessname+'</td>'+
' <td class="field">'+myleads.FirstName+' '+myleads.LastName+'</td>'+
' <td class="field">'+myleads.Phone+'</td>'+
' <td class="field" class="leadstatus">'+leadstatus+'</td>'+
' <td class="field" class="hostatus" style="display:hidden;">'+myleads.AMStatus+'</td>'+
' <td class="field" class="hostatus" style="display:hidden;">'+myleads.HQStatus+'</td>'+
' <td class="bigger temail">'+myleads.Email+'</td>'+
' <td class="last field">'+myleads.ModifiedDate+'</td>'+
' </tr>');
});
qs.cache();
});
setTimeout(function(){
var n = $('tbody tr:not(.ui-tableFilter-hidden)').size();
checknewleads(n,number);
},7000);
if(usertype == 3)
{
leadtype = "A/M Status";
}
else
{
leadtype = "Lead Status";
}
$("#todo_bg").hide();
$("#menuarea").html('<a id="gotohome"><div id="backmain" class="backbg">Back</div></a><div id="nav" class="backbgright">Manage Business Lead</div>'+
'<div id="dowithleads"><div style="width:100px;float:left;"><input type="checkbox" class="checkbox checkall" value="Yes" style="float:left;">Select All</div><button id="editlisting" class="blackbutton manage">Edit Listing</button><button id="sendemailout" class="blackbutton manage">Send Message</button> <button id="deletelead" class="blackbutton manage">Delete Lead</button>'+
'<div id="searchbox"><input type="text" name="search" value="" id="searchleads" placeholder="Search" autofocus /></div>'+
'</div>'+
'<div id="dowithleads" style="width:980px; overflow:scroll;"><table cellpadding="0" cellspacing="0" border="0" class="sortable paginated scrollTable" id="manageleads" style="text-align:left;">'+
' <thead class="fixedHeader">'+
' <tr>'+
' <th class="small" id="first"></th>'+
' <th class="field" class="ui-tableFilter-date">Created</th>'+
' <th class="field">Lead Owner</th>'+
' <th class="companysize">Trading Name</th>'+
' <th class="field">Customer Name</th>'+
' <th class="field">Phone No.</th>'+
' <th class="field" class="leadstatus">Lead Status</th>'+
' <th class="field" class="hostatus" style="display:hidden;">A/M Status</th>'+
' <th class="field" class="hostatus" style="display:hidden;">H/Q Status</th>'+
' <th id="emails" class="bigger">Email</th>'+
' <th class="field">Mod Date</th>'+
' </tr>'+
' </thead>'+
' <tbody class="scrollContent"></tbody>'+
'</table></div><div id="noloeads" style="float:right; margin:5px;"></div>');
if(usertype == 1 || usertype == 3 || usertype == 4)
{
$("#dowithleads").append('<button id="printlisting" class="blackbutton manage">Print W/P Letter</button>');
}
if(usertype == 1 || usertype == 3 || usertype == 4)
{
$("#dowithleads").append('<button id="exportlisting" class="blackbutton export">Export</button>');
}
if(usertype == 1)
{
$('.hostatus').show();
}
if(usertype ==3)
{
$('.hostatus').show();
$('.leadstatus').hide();
}
var script = document.createElement('link');
script.href = 'theme/style/manageleads.css';
script.rel = 'stylesheet';
script.type = 'text/css';
document.getElementsByTagName('head')[0].appendChild(script);
if ($.browser.msie && $.browser.version == 8) {
var script = document.createElement('link');
script.href = 'theme/style/ie-manageleads.css';
script.rel = 'stylesheet';
script.type = 'text/css';
document.getElementsByTagName('head')[0].appendChild(script);
}
setTimeout(function(){
setTimeout(function(){
$("table").tableFilter({ dialog: { modal: false } });
//updatecounter(numberofleads);
},90);
var qs = $('input#searchleads').quicksearch('table#manageleads tbody tr');
},2000);
}
function checknewleads(a,e)
{
a = a+1;
$.getJSON('system/classes/core.php?task=checkmyleads&fromid='+a+'&toid='+e+'&userid='+userid+'&usertype='+usertype+'&callback=?', function(dataleadstwo) {
$.each(dataleadstwo,function(i, myleads){
numberofleads = i;
var businessname = "";
if(myleads.Company == null || myleads.Company == "null" || myleads.Company == "")
{
businessname = myleads.TradingName;
}
else
{
businessname = myleads.Company;
}
if(myleads.ho > 1)
{
myleads.ho = "Complete";
}
else
{
myleads.ho = "Pending";
}
if(myleads.AMStatus == "1")
{
myleads.AMStatus = "Confirmed";
}
else if(myleads.AMStatus == "3")
{
myleads.AMStatus = "Canceled";
}
else if(myleads.AMStatus == "4")
{
myleads.AMStatus = "Does Not Have Mobile";
}
else if(myleads.AMStatus == "5")
{
myleads.AMStatus = "Not Contactable";
}
else if(myleads.AMStatus == "6")
{
myleads.AMStatus = "Re-Send Welcome Pack";
}
else if(myleads.AMStatus == "7")
{
myleads.AMStatus = "Welcome Pack Sent";
}
else if(myleads.AMStatus == "8")
{
myleads.AMStatus = "Swipe Confirmed";
}
else if(myleads.AMStatus == "9")
{
myleads.AMStatus = "Refussed Banking Details";
}
else
{
myleads.AMStatus = "Not Confirmed";
}
leadstatus = leadstatusselect(myleads.LeadStatus);
if(myleads.AMStatus == "1")
{
myleads.AMStatus = "one";
}
if(myleads.AMStatus == "3")
{
myleads.AMStatus = "red";
}
if(myleads.HQStatus == 0)
{
myleads.HQStatus = "Please Select";
}
else if(myleads.HQStatus == 2)
{
myleads.HQStatus = "iNcard Loaded $1";
}
else if(myleads.HQStatus == 3)
{
myleads.HQStatus = "iNcard Loaded $5";
}
else if(myleads.HQStatus == 4)
{
myleads.HQStatus = "Terminal Verified";
}
var s = myleads.Phone;
s = s.replace('(', '');
s = s.replace(')', '');
s = s.replace(/ /g, '');
myleads.Phone = s;
//alert(s);
cssstats = "lead"+myleads.AMStatus;
$("tbody").append('<tr id="'+myleads.customer_id+'" class="'+cssstats+'">'+
' <td id="row" class="small"><input id="'+myleads.customer_id+'" type="checkbox"></td>'+
' <td class="field">'+myleads.CreatedTime+'</td>'+
' <td class="field">'+myleads.stafffirstname+'</td>'+
' <td class="companysize">'+businessname+'</td>'+
' <td class="field">'+myleads.FirstName+' '+myleads.LastName+'</td>'+
' <td class="field">'+myleads.Phone+'</td>'+
' <td class="field" class="leadstatus">'+leadstatus+'</td>'+
' <td class="field" class="hostatus" style="display:hidden;">'+myleads.AMStatus+'</td>'+
' <td class="field" class="hostatus" style="display:hidden;">'+myleads.HQStatus+'</td>'+
' <td class="bigger temail">'+myleads.Email+'</td>'+
' <td class="last field">'+myleads.ModifiedDate+'</td>'+
' </tr>');
});
qs.cache();
});
setTimeout(function(){
setTimeout(function(){
$("table").tableFilter({ dialog: { modal: false } });
updatecounter(numberofleads);
},90);
var qs = $('input#searchleads').quicksearch('table#manageleads tbody tr');
},2000);
}

Categories