mirror of
https://github.com/fspc/biketree.git
synced 2026-09-16 14:31:36 -04:00
First commit of biketree to github!
This commit is contained in:
Executable
BIN
Binary file not shown.
Executable
+340
@@ -0,0 +1,340 @@
|
||||
<?php
|
||||
/*===========================================================================*/
|
||||
/* PHP Barcode Image Generator v1.0 [9/28/2000]
|
||||
Copyright (C)2000 by Charles J. Scheffold - cs@wsia.fm
|
||||
|
||||
|
||||
---
|
||||
UPDATE 09/21/2002 by Laurent NAVARRO - ln@altidev.com - http://www.altidev.com
|
||||
Updated to be compatible with register_globals = off and on
|
||||
---
|
||||
UPDATE 4/6/2001 - Important Note! This script was written with the assumption
|
||||
that "register_globals = On" is defined in your PHP.INI file! It will not
|
||||
work as-is and as described unless this is set. My PHP came with this
|
||||
enabled by default, but apparently many people have turned it off. Either
|
||||
turn it on or modify the startup code to pull the CGI variables in the old
|
||||
fashioned way (from the HTTP* arrays). If you just want to use the functions
|
||||
and pass the variables yourself, well then go on with your bad self.
|
||||
---
|
||||
|
||||
This code is hereby released into the public domain.
|
||||
Use it, abuse it, just don't get caught using it for something stupid.
|
||||
|
||||
|
||||
The only barcode type currently supported is Code 3 of 9. Don't ask about
|
||||
adding support for others! This is a script I wrote for my own use. I do
|
||||
plan to add more types as time permits but currently I only require
|
||||
Code 3 of 9 for my purposes. Just about every scanner on the market today
|
||||
can read it.
|
||||
|
||||
|
||||
PARAMETERS:
|
||||
-----------
|
||||
$barcode = [required] The barcode you want to generate
|
||||
|
||||
|
||||
$type = (default=0) It's 0 for Code 3 of 9 (the only one supported)
|
||||
|
||||
$width = (default=160) Width of image in pixels. The image MUST be wide
|
||||
enough to handle the length of the given value. The default
|
||||
value will probably be able to display about 6 digits. If you
|
||||
get an error message, make it wider!
|
||||
|
||||
|
||||
$height = (default=80) Height of image in pixels
|
||||
|
||||
$format = (default=jpeg) Can be "jpeg", "png", or "gif"
|
||||
|
||||
$quality = (default=100) For JPEG only: ranges from 0-100
|
||||
|
||||
|
||||
$text = (default='') 0 Enter any string to be displayed
|
||||
|
||||
|
||||
|
||||
NOTE: You must have GD-1.8 or higher compiled into PHP
|
||||
in order to use PNG and JPEG. GIF images only work with
|
||||
GD-1.5 and lower. (http://www.boutell.com)
|
||||
|
||||
|
||||
ANOTHER NOTE: If you actually intend to print the barcodes
|
||||
and scan them with a scanner, I highly recommend choosing
|
||||
JPEG with a quality of 100. Most browsers can't seem to print
|
||||
a PNG without mangling it beyond recognition.
|
||||
|
||||
|
||||
USAGE EXAMPLES FOR ANY PLAIN OLD HTML DOCUMENT:
|
||||
-----------------------------------------------
|
||||
|
||||
|
||||
<IMG SRC="barcode.php?barcode=HELLO&quality=75">
|
||||
|
||||
|
||||
<IMG SRC="barcode.php?barcode=123456&width=320&height=200">
|
||||
|
||||
|
||||
*/
|
||||
/*=============================================================================*/
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Startup code
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
|
||||
if(isset($_GET["text"])) $text=$_GET["text"];
|
||||
if(isset($_GET["format"])) $format=$_GET["format"];
|
||||
if(isset($_GET["quality"])) $quality=$_GET["quality"];
|
||||
if(isset($_GET["width"])) $width=$_GET["width"];
|
||||
if(isset($_GET["height"])) $height=$_GET["height"];
|
||||
if(isset($_GET["type"])) $type=$_GET["type"];
|
||||
if(isset($_GET["barcode"])) $barcode=$_GET["barcode"];
|
||||
|
||||
|
||||
|
||||
|
||||
if (!isset ($text)) $text = '';
|
||||
if (!isset ($type)) $type = 1;
|
||||
if (empty ($quality)) $quality = 100;
|
||||
if (empty ($width)) $width = 160;
|
||||
if (empty ($height)) $height = 80;
|
||||
if (!empty ($format)) $format = strtoupper ($format);
|
||||
else $format="PNG";
|
||||
|
||||
|
||||
switch ($type)
|
||||
{
|
||||
default:
|
||||
$type = 1;
|
||||
case 1:
|
||||
Barcode39 ($barcode, $width, $height, $quality, $format, $text);
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Generate a Code 3 of 9 barcode
|
||||
//-----------------------------------------------------------------------------
|
||||
function Barcode39 ($barcode, $width, $height, $quality, $format, $text)
|
||||
{
|
||||
switch ($format)
|
||||
{
|
||||
default:
|
||||
$format = "JPEG";
|
||||
case "JPEG":
|
||||
header ("Content-type: image/jpeg");
|
||||
break;
|
||||
case "PNG":
|
||||
header ("Content-type: image/png");
|
||||
break;
|
||||
case "GIF":
|
||||
header ("Content-type: image/gif");
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
$im = ImageCreate ($width, $height)
|
||||
or die ("Cannot Initialize new GD image stream");
|
||||
$White = ImageColorAllocate ($im, 255, 255, 255);
|
||||
$Black = ImageColorAllocate ($im, 0, 0, 0);
|
||||
//ImageColorTransparent ($im, $White);
|
||||
ImageInterLace ($im, 1);
|
||||
|
||||
|
||||
|
||||
$NarrowRatio = 20;
|
||||
$WideRatio = 55;
|
||||
$QuietRatio = 35;
|
||||
|
||||
|
||||
$nChars = (strlen($barcode)+2) * ((6 * $NarrowRatio) + (3 * $WideRatio) + ($QuietRatio));
|
||||
$Pixels = $width / $nChars;
|
||||
$NarrowBar = (int)(20 * $Pixels);
|
||||
$WideBar = (int)(55 * $Pixels);
|
||||
$QuietBar = (int)(35 * $Pixels);
|
||||
|
||||
|
||||
$ActualWidth = (($NarrowBar * 6) + ($WideBar*3) + $QuietBar) * (strlen ($barcode)+2);
|
||||
|
||||
if (($NarrowBar == 0) || ($NarrowBar == $WideBar) || ($NarrowBar == $QuietBar) || ($WideBar == 0) || ($WideBar == $QuietBar) || ($QuietBar == 0))
|
||||
{
|
||||
ImageString ($im, 1, 0, 0, "Image is too small!", $Black);
|
||||
OutputImage ($im, $format, $quality);
|
||||
exit;
|
||||
}
|
||||
|
||||
$CurrentBarX = (int)(($width - $ActualWidth) / 2);
|
||||
$Color = $White;
|
||||
$BarcodeFull = "*".strtoupper ($barcode)."*";
|
||||
settype ($BarcodeFull, "string");
|
||||
|
||||
$FontNum = 3;
|
||||
$FontHeight = ImageFontHeight ($FontNum);
|
||||
$FontWidth = ImageFontWidth ($FontNum);
|
||||
|
||||
if ($text != '')
|
||||
{
|
||||
$CenterLoc = (int)(($width) / 2) - (int)(($FontWidth * strlen($text)) / 2);
|
||||
ImageString ($im, $FontNum, $CenterLoc, $height-$FontHeight, "$text", $Black);
|
||||
}
|
||||
|
||||
|
||||
for ($i=0; $i<strlen($BarcodeFull); $i++)
|
||||
{
|
||||
$StripeCode = Code39 ($BarcodeFull[$i]);
|
||||
|
||||
|
||||
for ($n=0; $n < 9; $n++)
|
||||
{
|
||||
if ($Color == $White) $Color = $Black;
|
||||
else $Color = $White;
|
||||
|
||||
|
||||
switch ($StripeCode[$n])
|
||||
{
|
||||
case '0':
|
||||
ImageFilledRectangle ($im, $CurrentBarX, 0, $CurrentBarX+$NarrowBar, $height-1-$FontHeight-2, $Color);
|
||||
$CurrentBarX += $NarrowBar;
|
||||
break;
|
||||
|
||||
|
||||
case '1':
|
||||
ImageFilledRectangle ($im, $CurrentBarX, 0, $CurrentBarX+$WideBar, $height-1-$FontHeight-2, $Color);
|
||||
$CurrentBarX += $WideBar;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$Color = $White;
|
||||
ImageFilledRectangle ($im, $CurrentBarX, 0, $CurrentBarX+$QuietBar, $height-1-$FontHeight-2, $Color);
|
||||
$CurrentBarX += $QuietBar;
|
||||
}
|
||||
|
||||
|
||||
OutputImage ($im, $format, $quality);
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Output an image to the browser
|
||||
//-----------------------------------------------------------------------------
|
||||
function OutputImage ($im, $format, $quality)
|
||||
{
|
||||
switch ($format)
|
||||
{
|
||||
case "JPEG":
|
||||
ImageJPEG ($im, "", $quality);
|
||||
break;
|
||||
case "PNG":
|
||||
ImagePNG ($im);
|
||||
break;
|
||||
case "GIF":
|
||||
ImageGIF ($im);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Returns the Code 3 of 9 value for a given ASCII character
|
||||
//-----------------------------------------------------------------------------
|
||||
function Code39 ($Asc)
|
||||
{
|
||||
switch ($Asc)
|
||||
{
|
||||
case ' ':
|
||||
return "011000100";
|
||||
case '$':
|
||||
return "010101000";
|
||||
case '%':
|
||||
return "000101010";
|
||||
case '*':
|
||||
return "010010100"; // * Start/Stop
|
||||
case '+':
|
||||
return "010001010";
|
||||
case '|':
|
||||
return "010000101";
|
||||
case '.':
|
||||
return "110000100";
|
||||
case '/':
|
||||
return "010100010";
|
||||
case '0':
|
||||
return "000110100";
|
||||
case '1':
|
||||
return "100100001";
|
||||
case '2':
|
||||
return "001100001";
|
||||
case '3':
|
||||
return "101100000";
|
||||
case '4':
|
||||
return "000110001";
|
||||
case '5':
|
||||
return "100110000";
|
||||
case '6':
|
||||
return "001110000";
|
||||
case '7':
|
||||
return "000100101";
|
||||
case '8':
|
||||
return "100100100";
|
||||
case '9':
|
||||
return "001100100";
|
||||
case 'A':
|
||||
return "100001001";
|
||||
case 'B':
|
||||
return "001001001";
|
||||
case 'C':
|
||||
return "101001000";
|
||||
case 'D':
|
||||
return "000011001";
|
||||
case 'E':
|
||||
return "100011000";
|
||||
case 'F':
|
||||
return "001011000";
|
||||
case 'G':
|
||||
return "000001101";
|
||||
case 'H':
|
||||
return "100001100";
|
||||
case 'I':
|
||||
return "001001100";
|
||||
case 'J':
|
||||
return "000011100";
|
||||
case 'K':
|
||||
return "100000011";
|
||||
case 'L':
|
||||
return "001000011";
|
||||
case 'M':
|
||||
return "101000010";
|
||||
case 'N':
|
||||
return "000010011";
|
||||
case 'O':
|
||||
return "100010010";
|
||||
case 'P':
|
||||
return "001010010";
|
||||
case 'Q':
|
||||
return "000000111";
|
||||
case 'R':
|
||||
return "100000110";
|
||||
case 'S':
|
||||
return "001000110";
|
||||
case 'T':
|
||||
return "000010110";
|
||||
case 'U':
|
||||
return "110000001";
|
||||
case 'V':
|
||||
return "011000001";
|
||||
case 'W':
|
||||
return "111000000";
|
||||
case 'X':
|
||||
return "010010001";
|
||||
case 'Y':
|
||||
return "110010000";
|
||||
case 'Z':
|
||||
return "011010000";
|
||||
default:
|
||||
return "011000100";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
?>
|
||||
Executable
+586
@@ -0,0 +1,586 @@
|
||||
<?php
|
||||
|
||||
class db_functions
|
||||
{
|
||||
//class variable that represents the database connection.
|
||||
var $conn;
|
||||
var $lang;
|
||||
var $tblprefix;
|
||||
//var $sec;
|
||||
|
||||
var $table_bgcolor,$cellspacing,$cellpadding,$border_style,$border_width,
|
||||
$border_color,$header_rowcolor,$header_text_color,$headerfont_face,$headerfont_size,
|
||||
$rowcolor,$rowcolor2,$rowcolor_text,$rowfont_face,$rowfont_size;
|
||||
|
||||
//user-defined constructor
|
||||
function db_functions($server,$username,$password,$database,$tableprefix,$theme,$language)
|
||||
{
|
||||
//pre: parameters must be correct in order to connect to database.
|
||||
//post: connects to database.
|
||||
|
||||
//$sec=new security_functions($this,'Sales Clerk',$lang);
|
||||
$this->tblprefix=$tableprefix;
|
||||
$this->lang=$language;
|
||||
$this->conn = mysql_connect("$server", "$username", "$password") or die("Could not connect : " . mysql_error());
|
||||
mysql_select_db("$database",$this->conn) or die("Could not select database <b>$database</b>");
|
||||
|
||||
switch($theme)
|
||||
{
|
||||
//add more themes
|
||||
|
||||
case $theme=='serious':
|
||||
$this->table_bgcolor='white';
|
||||
$this->cellspacing='1';
|
||||
$this->cellpadding='0';
|
||||
$this->border_style='solid';
|
||||
$this->border_width='1';
|
||||
$this->border_color='black';
|
||||
|
||||
$this->header_rowcolor='black';
|
||||
$this->header_text_color='white';
|
||||
$this->headerfont_face='arial';
|
||||
$this->headerfont_size='2';
|
||||
|
||||
|
||||
$this->rowcolor='#DDDDDD';
|
||||
$this->rowcolor_text='black';
|
||||
$this->rowfont_face='geneva';
|
||||
$this->rowfont_size='2';
|
||||
break;
|
||||
|
||||
case $theme=='big blue':
|
||||
|
||||
$this->table_bgcolor='white';
|
||||
$this->cellspacing='1';
|
||||
$this->cellpadding='0';
|
||||
$this->border_style='solid';
|
||||
$this->border_width='1';
|
||||
$this->border_color='black';
|
||||
|
||||
$this->header_rowcolor='navy';
|
||||
$this->header_text_color='white';
|
||||
$this->headerfont_face='arial';
|
||||
$this->headerfont_size='2';
|
||||
|
||||
|
||||
$this->rowcolor='#15759B';
|
||||
$this->rowcolor_text='white';
|
||||
$this->rowfont_face='geneva';
|
||||
$this->rowfont_size='2';
|
||||
|
||||
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
function getUserID($username,$password)
|
||||
{
|
||||
//pre: $username is a string and $password (encrypted) is the user's encrypted password.
|
||||
//post: returns the id of the user with the specific username and password supplied.
|
||||
|
||||
$tablename = "$this->tblprefix".'users';
|
||||
$result = mysql_query("SELECT * FROM $tablename WHERE username=\"$username\" and password=\"$password\"",$this->conn);
|
||||
$row = mysql_fetch_assoc($result);
|
||||
|
||||
return $row['id'];
|
||||
}
|
||||
|
||||
function getAllElements($tablename,$field,$orderby)
|
||||
{
|
||||
//pre: $tablename,$field,$orderby must be valid
|
||||
/*post: returns all elements in an array of specified table
|
||||
and sets first position to an empty string. This function will be used for filling
|
||||
select fields, which requires the first position for the selected value
|
||||
*/
|
||||
|
||||
$result = mysql_query("SELECT $field FROM $tablename ORDER BY $orderby",$this->conn);
|
||||
$numRows = mysql_num_rows($result);
|
||||
$data = array();
|
||||
|
||||
$data[0]='';
|
||||
for($k=1; $k< $numRows+1; $k++)
|
||||
{
|
||||
$data[$k]= mysql_result($result,$k-1);
|
||||
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
function idToField($tablename,$field,$id)
|
||||
{
|
||||
//pre: $tablename, field, and id all must be valid
|
||||
//post: returns a specified field based on the ID from a specified table.
|
||||
|
||||
$result = mysql_query("SELECT $field FROM $tablename WHERE id=\"$id\"",$this->conn);
|
||||
|
||||
$row = mysql_fetch_assoc($result);
|
||||
|
||||
return $row[$field];
|
||||
}
|
||||
|
||||
function fieldToid($tablename,$field,$value)
|
||||
{
|
||||
//pre: $tablename, field, and value all must be valid
|
||||
//post: returns a specified id based on the field from a specified table.
|
||||
|
||||
$result = mysql_query("SELECT * FROM $tablename WHERE $field=\"$value\"",$this->conn);
|
||||
|
||||
$row=mysql_fetch_assoc($result);
|
||||
|
||||
return $row['id'];
|
||||
|
||||
}
|
||||
|
||||
function getFields($database,$tablename)
|
||||
{
|
||||
//returns fields in table
|
||||
|
||||
$fields=array();
|
||||
$fieldsRef=mysql_list_fields ($database, $tablename);
|
||||
$columns=mysql_num_fieldsfieldsRef;
|
||||
|
||||
for($k=0;$k<$columns;$k++)
|
||||
{
|
||||
$fields[]=mysql_field_name($fieldsRef,$k);
|
||||
}
|
||||
|
||||
return $fields;
|
||||
}
|
||||
|
||||
function insert($field_names,$field_data,$tablename,$output)
|
||||
{
|
||||
//pre: $field_names and $field_data are pararell arrays and $tablename is a string.
|
||||
//post: creates a query then executes it.
|
||||
|
||||
if(!($this->isValidData($field_data)))
|
||||
{
|
||||
echo "{$this->lang->invalidCharactor}";
|
||||
exit();
|
||||
}
|
||||
|
||||
$query = "INSERT INTO $tablename ($field_names[0]";
|
||||
|
||||
for($k=1;$k< count($field_names);$k++)
|
||||
{
|
||||
$query.=', '."$field_names[$k]";
|
||||
|
||||
}
|
||||
|
||||
$query.=") VALUES (\"$field_data[0]\"";
|
||||
|
||||
for($k=1;$k< count($field_data);$k++)
|
||||
{
|
||||
$query.=', '."\"$field_data[$k]\"";
|
||||
|
||||
}
|
||||
$query.=')';
|
||||
mysql_query($query,$this->conn);
|
||||
|
||||
|
||||
if($output)
|
||||
{
|
||||
echo "<center><b>{$this->lang->successfullyAdded} $tablename</b></center><br>";
|
||||
|
||||
echo "<center><table width=350 cellspacing=$this->cellspacing cellpadding=$this->cellpadding bgcolor=$this->table_bgcolor style=\"border: $this->border_style $this->border_color $this->border_width px\">
|
||||
<tr bgcolor=$this->header_rowcolor>
|
||||
<th align='left'><font color='$this->header_text_color' face='$this->headerfont_face' size='$this->headerfont_size'>{$this->lang->field}</th></font>
|
||||
<th align='left'><font color='$this->header_text_color' face='$this->headerfont_face' size='$this->headerfont_size'>{$this->lang->data}</th></font>
|
||||
</tr>";
|
||||
for($k=0;$k<count($field_names);$k++)
|
||||
{
|
||||
//certain fields I do not want displayed.
|
||||
if($field_names[$k]!="password")
|
||||
{
|
||||
echo "<tr bgcolor=$this->rowcolor><td width='120'><font color='$this->rowcolor_text' face='$this->rowfont_face' size='$this->rowfont_size'>$field_names[$k]". '</font></td>'."<td><font color='$this->rowcolor_text' face='$this->rowfont_face' size='$this->rowfont_size'>$field_data[$k]</font></td></tr>\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
echo "<tr bgcolor=$this->rowcolor><td width='120'><font color='$this->rowcolor_text' face='$this->rowfont_face' size='$this->rowfont_size'>$field_names[$k]". '</font></td>'."<td><font color='$this->rowcolor_text' face='$this->rowfont_face' size='$this->rowfont_size'>*******</font></td></tr>\n";
|
||||
|
||||
}
|
||||
}
|
||||
echo '</table></center>';
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
function update($field_names,$field_data,$tablename,$id,$output)
|
||||
{
|
||||
//pre: $field_names and $field_data are pararell arrays and tablename and id are strings.
|
||||
//post: creates a query then executes it limites based on id.
|
||||
|
||||
if($id=='')
|
||||
{
|
||||
echo "{$this->lang->didNotEnterID}";
|
||||
exit();
|
||||
}
|
||||
if(!($this->isValidData($field_data)))
|
||||
{
|
||||
echo "{$this->lang->invalidCharactor}";
|
||||
exit();
|
||||
}
|
||||
$query="UPDATE $tablename SET $field_names[0]=\"$field_data[0]\"";
|
||||
|
||||
for($k=1;$k< count($field_names);$k++)
|
||||
{
|
||||
$query.=', '."$field_names[$k]=\"$field_data[$k]\"";
|
||||
|
||||
}
|
||||
|
||||
$sales_items_table=$this->tblprefix.'sales_items';
|
||||
if($output)
|
||||
{
|
||||
$query.=" WHERE id=\"$id\"";
|
||||
//echo "Here: $query";
|
||||
}
|
||||
else
|
||||
{
|
||||
$query.=" WHERE sale_id=\"$id\"";
|
||||
}
|
||||
|
||||
|
||||
mysql_query($query,$this->conn);
|
||||
|
||||
|
||||
if($output)
|
||||
{
|
||||
echo "<center><b>{$this->lang->successfullyUpdated} $tablename</b></center><br>";
|
||||
|
||||
echo "<center><table width=350 cellspacing=$this->cellspacing cellpadding=$this->cellpadding bgcolor=$this->table_bgcolor style=\"border: $this->border_style $this->border_color $this->border_width px\">
|
||||
<tr bgcolor=$this->header_rowcolor>
|
||||
<th align='left'><font color='$this->header_text_color' face='$this->headerfont_face' size='$this->headerfont_size'>{$this->lang->field}</th></font>
|
||||
<th align='left'><font color='$this->header_text_color' face='$this->headerfont_face' size='$this->headerfont_size'>{$this->lang->data}</th></font>
|
||||
</tr>";
|
||||
for($k=0;$k<count($field_names);$k++)
|
||||
{
|
||||
//certain fields I do not want displayed.
|
||||
if($field_names[$k]!="password")
|
||||
{
|
||||
echo "<tr bgcolor=$this->rowcolor><td width='120'><font color='$this->rowcolor_text' face='$this->rowfont_face' size='$this->rowfont_size'>$field_names[$k]". '</font></td>'."<td><font color='$this->rowcolor_text' face='$this->rowfont_face' size='$this->rowfont_size'>$field_data[$k]</font></td></tr>\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
echo "<tr bgcolor=$this->rowcolor><td width='120'><font color='$this->rowcolor_text' face='$this->rowfont_face' size='$this->rowfont_size'>$field_names[$k]". '</font></td>'."<td><font color='$this->rowcolor_text' face='$this->rowfont_face' size='$this->rowfont_size'>*******</font></td></tr>\n";
|
||||
|
||||
}
|
||||
}
|
||||
echo '</table></center>';
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
function deleteRow($tablename,$id)
|
||||
{
|
||||
//pre: $tablename and id are strings.
|
||||
//post: Does extensive error checking and then deletes row is allowed.
|
||||
|
||||
if($this->tblprefix=='')
|
||||
{
|
||||
$baseTable=$tablename;
|
||||
}
|
||||
else
|
||||
{
|
||||
$splitTable= explode ("$this->tblprefix",$tablename);
|
||||
$baseTable=$splitTable[1];
|
||||
}
|
||||
|
||||
$canDelete=true;
|
||||
$errmessage='';
|
||||
|
||||
if($id=='')
|
||||
{
|
||||
echo "{$this->lang->didNotEnterID}";
|
||||
exit();
|
||||
}
|
||||
elseif($baseTable=='brands')
|
||||
{
|
||||
|
||||
$checkTable = "$this->tblprefix".'items';
|
||||
$result = mysql_query("SELECT brand_id FROM $checkTable WHERE brand_id=\"$id\"",$this->conn);
|
||||
if(@mysql_num_rows($result) >= 1)
|
||||
{
|
||||
$canDelete=false;
|
||||
$errmessage="{$this->lang->cantDeleteBrand}";
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
elseif($baseTable=='categories')
|
||||
{
|
||||
$checkTable = "$this->tblprefix".'items';
|
||||
$result = mysql_query("SELECT category_id FROM $checkTable WHERE category_id=\"$id\"",$this->conn);
|
||||
|
||||
if(@mysql_num_rows($result) >= 1)
|
||||
{
|
||||
$canDelete=false;
|
||||
$errmessage="{$this->lang->cantDeleteCategory}";
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
elseif($baseTable=='customers')
|
||||
{
|
||||
$checkTable = "$this->tblprefix".'sales';
|
||||
$result = mysql_query("SELECT customer_id FROM $checkTable WHERE customer_id=\"$id\"",$this->conn);
|
||||
|
||||
if(@mysql_num_rows($result) >= 1)
|
||||
{
|
||||
$canDelete=false;
|
||||
$errmessage="{$this->lang->cantDeleteCustomer}";
|
||||
}
|
||||
|
||||
}
|
||||
elseif($baseTable=='items')
|
||||
{
|
||||
$checkTable = "$this->tblprefix".'sales_items';
|
||||
$result = mysql_query("SELECT item_id FROM $checkTable WHERE item_id=\"$id\"",$this->conn);
|
||||
|
||||
if(@mysql_num_rows($result) >= 1)
|
||||
{
|
||||
$canDelete=false;
|
||||
$errmessage="{$this->lang->cantDeleteItem}";
|
||||
}
|
||||
|
||||
}
|
||||
elseif($baseTable=='suppliers')
|
||||
{
|
||||
|
||||
$checkTable = "$this->tblprefix".'items';
|
||||
$result = mysql_query("SELECT supplier_id FROM $checkTable WHERE supplier_id=\"$id\"",$this->conn);
|
||||
if(@mysql_num_rows($result) >= 1)
|
||||
{
|
||||
$canDelete=false;
|
||||
$errmessage="{$this->lang->cantDeleteSupplier}";
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
elseif($baseTable=='sales')
|
||||
{
|
||||
$sales_items_table="$this->tblprefix".'sales_items';
|
||||
$items_table="$this->tblprefix".'items';
|
||||
$result=mysql_query("SELECT * FROM $sales_items_table WHERE sale_id=\"$id\"");
|
||||
|
||||
while($row=mysql_fetch_assoc($result))
|
||||
{
|
||||
$quantityToAdd =$row['quantity_purchased'];
|
||||
$newQuantity=$this->idToField($items_table,'quantity',"$row[item_id]")+$quantityToAdd;
|
||||
$this->updateItemQuantity($row['item_id'],$newQuantity);
|
||||
}
|
||||
mysql_query("DELETE FROM $sales_items_table WHERE sale_id=\"$id\"",$this->conn);
|
||||
}
|
||||
elseif($baseTable=='users')
|
||||
{
|
||||
|
||||
$checkTable = "$this->tblprefix".'sales';
|
||||
|
||||
$result = mysql_query("SELECT sold_by FROM $checkTable WHERE sold_by=\"$id\"",$this->conn);
|
||||
if($_SESSION['session_user_id']==$id)
|
||||
{
|
||||
$canDelete=false;
|
||||
$errmessage="{$this->lang->cantDeleteUserLoggedIn}";
|
||||
|
||||
|
||||
}
|
||||
elseif(@mysql_num_rows($result) >= 1)
|
||||
{
|
||||
$canDelete=false;
|
||||
$errmessage="{$this->lang->cantDeleteUserEnteredSales}";
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
if($canDelete==true)
|
||||
{
|
||||
$query="DELETE FROM $tablename WHERE id=\"$id\"";
|
||||
mysql_query($query,$this->conn);
|
||||
|
||||
echo "<center>{$this->lang->successfullyDeletedRow} <b>$id</b> {$this->lang->fromThe} <b>$tablename</b> {$this->lang->table}</center>";
|
||||
}
|
||||
else
|
||||
{
|
||||
echo "<center>$errmessage</center><br>";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function isValidData($data_to_check)
|
||||
{
|
||||
//checks data for errors
|
||||
|
||||
for($k=0;$k<count($data_to_check);$k++)
|
||||
{
|
||||
if(ereg('\"',$data_to_check[$k]) or ereg('<',$data_to_check[$k]) or ereg('>',$data_to_check[$k]) )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
function isValidItem($item)
|
||||
{
|
||||
$table=$this->tblprefix.'items';
|
||||
$result=mysql_query("SELECT id FROM $table WHERE id=\"$item\"",$this->conn);
|
||||
|
||||
if(mysql_num_rows($result)==0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
function isItemOnDiscount($itemID)
|
||||
{
|
||||
$table=$this->tblprefix.'discounts';
|
||||
$query="SELECT item_id FROM $table WHERE item_id=\"$itemID\"";
|
||||
$result=mysql_query($query,$this->conn);
|
||||
|
||||
if(mysql_num_rows($result) >0)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
function getPercentDiscount($itemID)
|
||||
{
|
||||
$table=$this->tblprefix.'discounts';
|
||||
$query="SELECT percent_off FROM $table WHERE item_id=\"$itemID\"";
|
||||
$result=mysql_query($query,$this->conn);
|
||||
|
||||
if(mysql_num_rows($result) >0)
|
||||
{
|
||||
$row=mysql_fetch_assoc($result);
|
||||
return $row['percent_off'];
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
function getDiscountedPrice($itemID)
|
||||
{
|
||||
$itemtable=$this->tblprefix.'items';
|
||||
$discounttable=$this->tblprefix.'discounts';
|
||||
|
||||
$query1="SELECT * FROM $discounttable WHERE item_id=\"$itemID\"";
|
||||
$row=mysql_fetch_assoc(mysql_query($query1,$this->conn));
|
||||
$percent_off=$row['percent_off'];
|
||||
|
||||
$query2="SELECT * FROM $itemtable WHERE id=\"$itemID\"";
|
||||
$row=mysql_fetch_assoc(mysql_query($query2,$this->conn));
|
||||
$discounted_price=$row['unit_price']*(1-($percent_off/100));
|
||||
|
||||
return number_format($discounted_price,2,'.', '');
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
function isValidCustomer($customer)
|
||||
{
|
||||
$table=$this->tblprefix.'customers';
|
||||
$result=mysql_query("SELECT id FROM $table WHERE id=\"$customer\"",$this->conn);
|
||||
|
||||
if(mysql_num_rows($result)==0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
function getNumRows($table)
|
||||
{
|
||||
//gets the number of rows in a table
|
||||
|
||||
$query="SELECT id FROM $table";
|
||||
$result=mysql_query($query,$this->conn);
|
||||
|
||||
return mysql_num_rows($result);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
function updateSaleTotals($sale_id)
|
||||
{
|
||||
//updates the totals for a sale
|
||||
|
||||
$sales_items_table=$this->tblprefix.'sales_items';
|
||||
$sales_table=$this->tblprefix.'sales';
|
||||
|
||||
$query="SELECT item_total_cost,item_total_tax,quantity_purchased FROM $sales_items_table WHERE sale_id=\"$sale_id\"";
|
||||
|
||||
$result=mysql_query($query,$this->conn);
|
||||
|
||||
|
||||
|
||||
if(@mysql_num_rows($result) > 0)
|
||||
{
|
||||
$sale_sub_total=0;
|
||||
$sale_total_cost=0;
|
||||
$items_purchased=0;
|
||||
|
||||
while($row=mysql_fetch_assoc($result))
|
||||
{
|
||||
$sale_sub_total+=$row['item_total_cost']-$row['item_total_tax'];
|
||||
$sale_total_cost+=$row['item_total_cost'];
|
||||
$items_purchased+=$row['quantity_purchased'];
|
||||
}
|
||||
|
||||
$sale_sub_total=number_format($sale_sub_total,2,'.', '');
|
||||
$sale_total_cost=number_format($sale_total_cost,2,'.', '');
|
||||
|
||||
$query2="UPDATE $sales_table SET sale_sub_total=\"$sale_sub_total\",sale_total_cost=\"$sale_total_cost\",items_purchased=\"$items_purchased\" WHERE id=\"$sale_id\"";
|
||||
mysql_query($query2,$this->conn);
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->deleteRow($sales_table,$sale_id);
|
||||
}
|
||||
}
|
||||
|
||||
function updateItemQuantity($item_id,$newQuantity)
|
||||
{
|
||||
$items_table=$this->tblprefix.'items';
|
||||
$query="UPDATE $items_table SET quantity=\"$newQuantity\" WHERE id=\"$item_id\"";
|
||||
mysql_query($query,$this->conn);
|
||||
|
||||
}
|
||||
|
||||
function optimizeTables()
|
||||
{
|
||||
//optimizes the sales
|
||||
|
||||
$tableprefix=$this->tblprefix;
|
||||
$brandsTable="$tableprefix".'brands';
|
||||
$categorieTable="$tableprefix".'categories';
|
||||
$customersTable="$tableprefix".'customers';
|
||||
$itemsTable="$tableprefix".'items';
|
||||
$salesTable="$tableprefix".'sales';
|
||||
$sales_itemsTable="$tableprefix".'sales_items';
|
||||
$suppliersTable="$tableprefix".'suppliers';
|
||||
$usersTable="$tableprefix".'users';
|
||||
$booksTable="$tableprefix".'books';
|
||||
|
||||
$query="OPTIMIZE TABLE $brandsTable, $categorieTable, $customersTable, $itemsTable, $salesTable, $sales_itemsTable,$suppliersTable, $usersTable, $booksTable";
|
||||
mysql_query($query,$this->conn);
|
||||
}
|
||||
|
||||
function closeDBlink()
|
||||
{
|
||||
mysql_close($this->conn);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
Executable
+887
@@ -0,0 +1,887 @@
|
||||
<?php
|
||||
|
||||
class display
|
||||
{
|
||||
|
||||
var $conn;
|
||||
var $lang;
|
||||
var $title_color,$list_of_color,$table_bgcolor,$cellspacing,$cellpadding,$border_style,$border_width,
|
||||
$border_color,$header_rowcolor,$header_text_color,$headerfont_face,$headerfont_size,
|
||||
$rowcolor1,$rowcolor2,$rowcolor_text,$rowfont_face,$rowcolor_link,$rowfont_size,$sale_bg;
|
||||
|
||||
function display($connection,$theme,$currency_symbol,$language)
|
||||
{
|
||||
$this->conn=$connection;
|
||||
$this->lang=$language;
|
||||
$this->currency_symbol=$currency_symbol;
|
||||
switch($theme)
|
||||
{
|
||||
case $theme=='big blue':
|
||||
|
||||
$this->title_color='#005B7F';
|
||||
$this->list_of_color='#247392';
|
||||
|
||||
$this->table_bgcolor='white';
|
||||
$this->cellspacing='1';
|
||||
$this->cellpadding='0';
|
||||
$this->border_style='solid';
|
||||
$this->border_width='1';
|
||||
$this->border_color='#0A6184';
|
||||
|
||||
$this->header_rowcolor='navy';
|
||||
$this->header_text_color='white';
|
||||
$this->headerfont_face='arial';
|
||||
$this->headerfont_size='2';
|
||||
|
||||
|
||||
$this->rowcolor1='#15759B';
|
||||
$this->rowcolor2='#0A6184';
|
||||
$this->rowcolor_text='white';
|
||||
$this->rowfont_face='geneva';
|
||||
$this->rowcolor_link='CCCCCC';
|
||||
$this->rowfont_size='2';
|
||||
$this->sale_bg='#015B7E';
|
||||
|
||||
break;
|
||||
|
||||
case $theme=='serious':
|
||||
|
||||
$this->title_color='black';
|
||||
$this->list_of_color='black';
|
||||
|
||||
$this->table_bgcolor='white';
|
||||
$this->cellspacing='1';
|
||||
$this->cellpadding='0';
|
||||
$this->border_style='solid';
|
||||
$this->border_width='1';
|
||||
$this->border_color='black';
|
||||
|
||||
$this->header_rowcolor='black';
|
||||
$this->header_text_color='white';
|
||||
$this->headerfont_face='arial';
|
||||
$this->headerfont_size='2';
|
||||
|
||||
|
||||
$this->rowcolor1='#DDDDDD';
|
||||
$this->rowcolor2='#CCCCCC';
|
||||
$this->rowcolor_text='black';
|
||||
$this->rowfont_face='geneva';
|
||||
$this->rowcolor_link='black';
|
||||
$this->rowfont_size='2';
|
||||
$this->sale_bg='#999999';
|
||||
break;
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
function displayTitle($title)
|
||||
{
|
||||
//pre: Title must be a string.
|
||||
//post: Applys title to page.
|
||||
|
||||
echo "<center><h3><font color='$this->title_color'>$title</font></h3></center>";
|
||||
}
|
||||
|
||||
function idToField($tablename,$field,$id)
|
||||
{
|
||||
//pre: $tablename, field, and id all must be valid
|
||||
//post: returns a specified field based on the ID from a specified table.
|
||||
|
||||
$result = mysql_query("SELECT $field FROM $tablename WHERE id=\"$id\"",$this->conn);
|
||||
|
||||
$row = mysql_fetch_assoc($result);
|
||||
|
||||
return $row[$field];
|
||||
}
|
||||
|
||||
function getNumRows($table)
|
||||
{
|
||||
$query="SELECT id FROM $table";
|
||||
$result=mysql_query($query,$this->conn);
|
||||
|
||||
return mysql_num_rows($result);
|
||||
|
||||
}
|
||||
|
||||
function displayManageTable($tableprefix,$tablename,$tableheaders,$tablefields,$wherefield,$wheredata,$orderby)
|
||||
{
|
||||
//pre:params must be right type
|
||||
//post: outputs a nice looking table that is used for manage parts of the program
|
||||
|
||||
if($tablename=='brands' or $tablename=='categories')
|
||||
{
|
||||
$tablewidth='35%';
|
||||
}
|
||||
else
|
||||
{
|
||||
$tablewidth='95%';
|
||||
}
|
||||
|
||||
$table="$tableprefix"."$tablename";
|
||||
echo "\n".'<center>';
|
||||
|
||||
if($wherefield=='quantity' and $wheredata=='outofstock')
|
||||
{
|
||||
$result = mysql_query("SELECT * FROM $table WHERE quantity < 1 ORDER BY $orderby",$this->conn);
|
||||
}
|
||||
elseif($wherefield=='quantity' and $wheredata=='reorder')
|
||||
{
|
||||
$result = mysql_query("SELECT * FROM $table WHERE quantity <= reorder_level ORDER BY $orderby",$this->conn);
|
||||
|
||||
}
|
||||
elseif($wherefield!='' and $wheredata!='')
|
||||
{
|
||||
$result = mysql_query("SELECT * FROM $table WHERE $wherefield like \"%$wheredata%\" ORDER BY $orderby",$this->conn);
|
||||
}
|
||||
elseif($this->getNumRows($table) >200)
|
||||
{
|
||||
$result = mysql_query("SELECT * FROM $table ORDER BY $orderby LIMIT 0,200",$this->conn);
|
||||
echo "{$this->lang->moreThan200} $tableprefix $table".'\'s'."{$this->lang->first200Displayed}";
|
||||
}
|
||||
else
|
||||
{
|
||||
$result = mysql_query("SELECT * FROM $table ORDER BY $orderby",$this->conn);
|
||||
}
|
||||
echo '<hr>';
|
||||
if(@mysql_num_rows($result) ==0)
|
||||
{
|
||||
echo "<div align='center'>{$this->lang->noDataInTable} <b>$table</b> {$this->lang->table}.</div>";
|
||||
exit();
|
||||
}
|
||||
echo "<center><h4><font color='$this->list_of_color'>{$this->lang->listOf}";
|
||||
if ($tablename == "customers"){ echo " Members</font></h4></center>"; } else { echo " $tablename</font></h4></center>"; }
|
||||
|
||||
echo "<table cellspacing='$this->cellspacing' cellpadding='$this->cellpadding' bgcolor='$this->table_bgcolor' width='$tablewidth' style=\"border: $this->border_style $this->border_color $this->border_width px\">
|
||||
|
||||
<tr bgcolor=$this->header_rowcolor>\n\n";
|
||||
for($k=0;$k< count($tableheaders);$k++)
|
||||
{
|
||||
echo "<th align='center'>\n<font color='$this->header_text_color' face='$this->headerfont_face' size='$this->headerfont_size'>$tableheaders[$k]</font>\n</th>\n";
|
||||
}
|
||||
echo '</tr>'."\n\n";
|
||||
|
||||
$rowCounter=0;
|
||||
while($row=mysql_fetch_assoc($result))
|
||||
{
|
||||
if($rowCounter%2==0)
|
||||
{
|
||||
echo "\n<tr bgcolor=$this->rowcolor1>\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
echo "\n<tr bgcolor=$this->rowcolor2>\n";
|
||||
}
|
||||
$rowCounter++;
|
||||
for($k=0;$k<count($tablefields);$k++)
|
||||
{
|
||||
$field=$tablefields[$k];
|
||||
$data=$this->formatData($field,$row[$field],$tableprefix);
|
||||
|
||||
|
||||
echo "\n<td align='center'>\n<font color='$this->rowcolor_text' face='$this->rowfont_face' size='$this->rowfont_size'>$data</font>\n</td>\n";
|
||||
}
|
||||
if($tablename == "customers")
|
||||
{
|
||||
echo "<td align='center'>\n<a href=\"../members/add.php?userID=$row[id]\"><font color='$this->rowcolor_link'>{$this->lang->update}</font></a></td>
|
||||
<td align='center'>\n<a href=\"javascript:decision('{$this->lang->confirmDelete} $table {$this->lang->table}?','process_form_$tablename.php?action=delete&id=$row[id]')\"><font color='$this->rowcolor_link'>{$this->lang->delete}</font></a></td>\n
|
||||
<td align='center'>\n<a href=\"../members/getinfo.php?userID=$row[id]\"><font color='$this->rowcolor_link'>{$this->lang->getinfo}</font></a></td>
|
||||
|
||||
</tr>\n\n";
|
||||
} else {
|
||||
echo "<td align='center'>\n<a href=\"form_$tablename.php?action=update&id=$row[id]\"><font color='$this->rowcolor_link'>{$this->lang->update}</font></a></td>
|
||||
<td align='center'>\n<a href=\"javascript:decision('{$this->lang->confirmDelete} $table {$this->lang->table}?','process_form_$tablename.php?action=delete&id=$row[id]')\"><font color='$this->rowcolor_link'>{$this->lang->delete}</font></a></td>\n</tr>\n\n";
|
||||
}
|
||||
}
|
||||
echo '</table>'."\n";
|
||||
}
|
||||
|
||||
function displayReportTable($tableprefix,$tablename,$tableheaders,$tablefields,$wherefield,$wheredata,$date1,$date2,$orderby,$subtitle)
|
||||
{
|
||||
echo "<center><h4><font color='$this->list_of_color'>$subtitle</font></h4></center>";
|
||||
$tablewidth='85%';
|
||||
|
||||
$table="$tableprefix"."$tablename";
|
||||
echo "\n".'<center>';
|
||||
if($wherefield!='' and $wheredata!='' and $date1=='' and $date2=='')
|
||||
{
|
||||
$result = mysql_query("SELECT * FROM $table WHERE $wherefield = \"$wheredata\" ORDER BY $orderby",$this->conn);
|
||||
}
|
||||
elseif($wherefield!='' and $wheredata!='' and $date1!='' and $date2!='')
|
||||
{
|
||||
$result = mysql_query("SELECT * FROM $table WHERE $wherefield = \"$wheredata\" and date between \"$date1\" and \"$date2\" ORDER BY $orderby",$this->conn);
|
||||
}
|
||||
elseif($date1!='' and $date2!='')
|
||||
{
|
||||
$result = mysql_query("SELECT * FROM $table WHERE date between \"$date1\" and \"$date2\" ORDER BY $orderby",$this->conn);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
$result = mysql_query("SELECT * FROM $table ORDER BY $orderby",$this->conn);
|
||||
}
|
||||
echo '<hr>';
|
||||
if(@mysql_num_rows($result) ==0)
|
||||
{
|
||||
echo "<div align='center'>{$this->lang->noDataInTable} <b>$table</b> {$this->lang->table}.</div>";
|
||||
exit();
|
||||
}
|
||||
echo "<table cellspacing='$this->cellspacing' cellpadding='$this->cellpadding' bgcolor='$this->table_bgcolor' width='$tablewidth' style=\"border: $this->border_style $this->border_color $this->border_width px\">
|
||||
|
||||
<tr bgcolor=$this->header_rowcolor>\n\n";
|
||||
for($k=0;$k< count($tableheaders);$k++)
|
||||
{
|
||||
echo "<th align='center'>\n<font color='$this->header_text_color' face='$this->headerfont_face' size='$this->headerfont_size'>$tableheaders[$k]</font>\n</th>\n";
|
||||
}
|
||||
echo '</tr>'."\n\n";
|
||||
|
||||
|
||||
$rowCounter=0;
|
||||
while($row=mysql_fetch_assoc($result))
|
||||
{
|
||||
if($rowCounter%2==0)
|
||||
{
|
||||
echo "\n<tr bgcolor=$this->rowcolor1>\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
echo "\n<tr bgcolor=$this->rowcolor2>\n";
|
||||
}
|
||||
$rowCounter++;
|
||||
for($k=0;$k<count($tablefields);$k++)
|
||||
{
|
||||
$field=$tablefields[$k];
|
||||
|
||||
if($field=='sale_details')
|
||||
{
|
||||
$temp_customer_id=$row['customer_id'];
|
||||
$temp_date=$row['date'];
|
||||
$temp_sale_id=$row['id'];
|
||||
$data="<a href=\"javascript:popUp('show_details.php?sale_id=$temp_sale_id&sale_customer_id=$temp_customer_id&sale_date=$temp_date')\"><font color='$this->rowcolor_link'>{$this->lang->showSaleDetails}</font></a>";
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
if($field=='brand_id' or $field=='category_id' or $field=='supplier_id')
|
||||
{
|
||||
$field_data=$this->idToField("$tableprefix".'items',"$field",$row['item_id']);
|
||||
$data=$this->formatData($field,$field_data,$tableprefix);
|
||||
}
|
||||
else
|
||||
{
|
||||
$data=$this->formatData($field,$row[$field],$tableprefix);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
echo "\n<td align='center'>\n<font color='$this->rowcolor_text' face='$this->rowfont_face' size='$this->rowfont_size'>$data</font>\n</td>\n";
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
echo '</table>'."\n";
|
||||
|
||||
}
|
||||
|
||||
function displaySaleManagerTable($tableprefix,$where1,$where2)
|
||||
{
|
||||
$tablewidth='85%';
|
||||
$sales_table="$tableprefix"."sales";
|
||||
$sales_items_table="$tableprefix"."sales_items";
|
||||
|
||||
if($where1!='' and $where2!='')
|
||||
{
|
||||
|
||||
$sale_query="SELECT * FROM $sales_table WHERE id between \"$where1\" and \"$where2\" ORDER BY id DESC";
|
||||
$sale_result=mysql_query($sale_query,$this->conn);
|
||||
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
$sale_query="SELECT * FROM $sales_table ORDER BY id DESC";
|
||||
$sale_result=mysql_query($sale_query,$this->conn);
|
||||
|
||||
}
|
||||
|
||||
$sales_tableheaders=array("{$this->lang->date}","{$this->lang->customerName}","{$this->lang->itemsPurchased}","{$this->lang->paidWith}","{$this->lang->soldBy}","{$this->lang->saleSubTotal}","{$this->lang->saleTotalCost}","{$this->lang->saleComment}");
|
||||
$sales_tablefields=array('date','customer_id','items_purchased','paid_with','sold_by','sale_sub_total','sale_total_cost','comment');
|
||||
|
||||
$sales_items_tableheaders=array("{$this->lang->itemName}","{$this->lang->brand}","{$this->lang->category}","{$this->lang->supplier}","{$this->lang->quantityPurchased}","{$this->lang->unitPrice}","{$this->lang->tax}","{$this->lang->itemTotalCost}","{$this->lang->updateItem}","{$this->lang->deleteItem}");
|
||||
$sales_items_tablefields=array('item_id','brand_id','category_id','supplier_id','quantity_purchased','item_unit_price','item_total_tax','item_total_cost');
|
||||
|
||||
|
||||
if(@mysql_num_rows($sale_result) < 1)
|
||||
{
|
||||
echo "<div align='center'>You do not have any data in the <b>sales</b> tables.</div>";
|
||||
exit();
|
||||
}
|
||||
|
||||
$rowCounter1=0;
|
||||
echo "<center><table cellspacing='$this->cellspacing' cellpadding='$this->cellpadding' bgcolor='$this->table_bgcolor' width='$tablewidth' style=\"border: $this->border_style $this->border_color 3 px\"><tr><td><br>";
|
||||
while($row=mysql_fetch_assoc($sale_result))
|
||||
{
|
||||
|
||||
echo "<table align='center' cellspacing='$this->cellspacing' cellpadding='$this->cellpadding' bgcolor='$this->table_bgcolor' width='$tablewidth' style=\"border: $this->border_style $this->border_color $this->border_width px\"><tr><td align='center'><br><b>{$this->lang->saleID} $row[id]</b>
|
||||
[<a href='update_sale.php?id=$row[id]'>{$this->lang->updateSale}</a>]
|
||||
[<a href=\"javascript:decision('{$this->lang->confirmDelete} $sales_table {$this->lang->table}?','delete_sale.php?id=$row[id]')\">{$this->lang->deleteEntireSale}]</a>
|
||||
<table cellspacing='$this->cellspacing' cellpadding='$this->cellpadding' bgcolor='$this->table_bgcolor' width='$tablewidth' style=\"border: $this->border_style $this->border_color $this->border_width px\">
|
||||
|
||||
<tr bgcolor=$this->header_rowcolor>\n\n";
|
||||
|
||||
for($k=0;$k< count($sales_tableheaders);$k++)
|
||||
{
|
||||
echo "<th align='center'>\n<font color='$this->header_text_color' face='$this->headerfont_face' size='$this->headerfont_size'>$sales_tableheaders[$k]</font>\n</th>\n";
|
||||
}
|
||||
|
||||
echo '</tr>'."\n\n";
|
||||
if($rowCounter1%2==0)
|
||||
{
|
||||
echo "\n<tr bgcolor=$this->rowcolor1>\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
echo "\n<tr bgcolor=$this->rowcolor2>\n";
|
||||
}
|
||||
$rowCounter1++;
|
||||
for($k=0;$k<count($sales_tablefields);$k++)
|
||||
{
|
||||
$field=$sales_tablefields[$k];
|
||||
$data=$this->formatData($field,$row[$field],$tableprefix);
|
||||
|
||||
echo "\n<td align='center'>\n<font color='$this->rowcolor_text' face='$this->rowfont_face' size='$this->rowfont_size'>$data</font>\n</td>\n";
|
||||
|
||||
|
||||
}
|
||||
|
||||
echo '</tr></table>';
|
||||
$sale_items_query="SELECT * FROM $sales_items_table WHERE sale_id=\"$row[id]\"";
|
||||
$sale_items_result=mysql_query($sale_items_query,$this->conn);
|
||||
echo "<br><b>{$this->lang->itemsInSale}</b><table cellspacing='$this->cellspacing' cellpadding='$this->cellpadding' bgcolor='$this->table_bgcolor' width='$tablewidth' style=\"border: $this->border_style $this->border_color $this->border_width px\">
|
||||
<tr bgcolor=$this->header_rowcolor>\n\n";
|
||||
|
||||
for($k=0;$k<count($sales_items_tableheaders);$k++)
|
||||
{
|
||||
echo "<th align='center'>\n<font color='$this->header_text_color' face='$this->headerfont_face' size='$this->headerfont_size'>$sales_items_tableheaders[$k]</font>\n</th>\n";
|
||||
}
|
||||
echo '</tr>';
|
||||
|
||||
$rowCounter2=0;
|
||||
while($newrow=mysql_fetch_assoc($sale_items_result))
|
||||
{
|
||||
if($rowCounter2%2==0)
|
||||
{
|
||||
echo "\n<tr bgcolor=$this->rowcolor1>\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
echo "\n<tr bgcolor=$this->rowcolor2>\n";
|
||||
}
|
||||
|
||||
|
||||
$rowCounter2++;
|
||||
for($k=0;$k<count($sales_items_tablefields);$k++)
|
||||
{
|
||||
$field=$sales_items_tablefields[$k];
|
||||
if($field=='brand_id' or $field=='category_id' or $field=='supplier_id')
|
||||
{
|
||||
$field_data=$this->idToField("$tableprefix".'items',"$field",$newrow['item_id']);
|
||||
$data=$this->formatData($field,$field_data,$tableprefix);
|
||||
}
|
||||
else
|
||||
{
|
||||
$data=$this->formatData($field,$newrow[$field],$tableprefix);
|
||||
}
|
||||
echo "\n<td align='center'>\n<font color='$this->rowcolor_text' face='$this->rowfont_face' size='$this->rowfont_size'>$data</font>\n</td>\n";
|
||||
}
|
||||
|
||||
echo "<td align='center'>\n<a href=\"update_item.php?sale_id=$newrow[sale_id]&item_id=$newrow[item_id]&row_id=$newrow[id]\"><font color='$this->rowcolor_link'>{$this->lang->update}</font></a></td>
|
||||
<td align='center'>\n<a href=\"javascript:decision('{$this->lang->confirmDelete} $sales_items_table {$this->lang->table}?','delete_item.php?sale_id=$newrow[sale_id]&item_id=$newrow[item_id]&row_id=$newrow[id]')\"><font color='$this->rowcolor_link'>{$this->lang->delete}</font></a></td>\n</tr>\n\n";
|
||||
|
||||
echo '</tr>'."\n\n";
|
||||
}
|
||||
echo '</table><br></table><br>';
|
||||
}
|
||||
echo "</table></td></tr></table></center>";
|
||||
}
|
||||
function displayTotalsReport($tableprefix,$total_type,$tableheaders,$date1,$date2,$where1,$where2)
|
||||
{
|
||||
$sales_table="$tableprefix".'sales';
|
||||
$sales_items_table="$tableprefix".'sales_items';
|
||||
$items_table="$tableprefix".'items';
|
||||
$brands_table="$tableprefix".'brands';
|
||||
$categories_table="$tableprefix".'categories';
|
||||
$suppliers_table="$tableprefix".'suppliers';
|
||||
$customer_table="$tableprefix".'customers';
|
||||
$users_table="$tableprefix".'users';
|
||||
|
||||
|
||||
if($total_type=='customers')
|
||||
{
|
||||
echo "<center><b>{$this->lang->totalsShownBetween} $date1 {$this->lang->and} $date2</b></center>";
|
||||
echo "<table align='center' cellspacing='$this->cellspacing' cellpadding='$this->cellpadding' bgcolor='$this->table_bgcolor' width='60%' style=\"border: $this->border_style $this->border_color $this->border_width px\">";
|
||||
|
||||
echo "<tr bgcolor=$this->header_rowcolor>\n\n";
|
||||
|
||||
for($k=0;$k< count($tableheaders);$k++)
|
||||
{
|
||||
echo "<th align='center'>\n<font color='$this->header_text_color' face='$this->headerfont_face' size='$this->headerfont_size'>$tableheaders[$k]</font>\n</th>\n";
|
||||
}
|
||||
|
||||
echo '</tr>'."\n\n";
|
||||
|
||||
$query="SELECT * FROM $customer_table ORDER BY last_name";
|
||||
$customer_result=mysql_query($query,$this->conn);
|
||||
$temp_cust_id=0;
|
||||
|
||||
$accum_sub_total=0;
|
||||
$accum_total_cost=0;
|
||||
$accum_items_purhcased=0;
|
||||
$row_counter=0;
|
||||
while($row=mysql_fetch_assoc($customer_result))
|
||||
{
|
||||
$temp_cust_id=$row['id'];
|
||||
$customer_name=$this->formatData('customer_id',$temp_cust_id,$tableprefix);
|
||||
$query2="SELECT * FROM $sales_table WHERE customer_id=\"$temp_cust_id\" and date between \"$date1\" and \"$date2\"";
|
||||
$result2=mysql_query($query2,$this->conn);
|
||||
|
||||
$sub_total=0;
|
||||
$total_cost=0;
|
||||
$items_purchased=0;
|
||||
|
||||
while($row2=mysql_fetch_assoc($result2))
|
||||
{
|
||||
$sub_total+=$row2['sale_sub_total'];
|
||||
$accum_sub_total+=$row2['sale_sub_total'];
|
||||
|
||||
$total_cost+=$row2['sale_total_cost'];
|
||||
$accum_total_cost+=$row2['sale_total_cost'];
|
||||
|
||||
$items_purchased+=$row2['items_purchased'];
|
||||
$accum_items_purhcased+=$row2['items_purchased'];
|
||||
}
|
||||
$row_counter++;
|
||||
|
||||
$sub_total=number_format($sub_total,2,'.', '');
|
||||
$total_cost=number_format($total_cost,2,'.', '');
|
||||
|
||||
|
||||
if($row_counter%2==0)
|
||||
{
|
||||
echo "\n<tr bgcolor=$this->rowcolor1>\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
echo "\n<tr bgcolor=$this->rowcolor2>\n";
|
||||
}
|
||||
|
||||
echo "<td align='center'>\n<font color='$this->rowcolor_text' face='$this->rowfont_face' size='$this->rowfont_size'>$customer_name</font>\n</td>
|
||||
<td align='center'>\n<font color='$this->rowcolor_text' face='$this->rowfont_face' size='$this->rowfont_size'>$items_purchased</font>\n</td>
|
||||
<td align='center'>\n<font color='$this->rowcolor_text' face='$this->rowfont_face' size='$this->rowfont_size'>$this->currency_symbol$sub_total</font>\n</td>
|
||||
<td align='center'>\n<font color='$this->rowcolor_text' face='$this->rowfont_face' size='$this->rowfont_size'>$this->currency_symbol$total_cost</font>\n</td>
|
||||
</tr>";
|
||||
}
|
||||
echo '</table>';
|
||||
$accum_sub_total=number_format($accum_sub_total,2,'.', '');
|
||||
$accum_total_cost=number_format($accum_total_cost,2,'.', '');
|
||||
|
||||
echo "<br><table align='right' cellspacing='$this->cellspacing' cellpadding='$this->cellpadding' bgcolor='$this->table_bgcolor' width='60%' border=0>";
|
||||
echo "<tr><td>{$this->lang->totalItemsPurchased}: <b>$accum_items_purhcased</b></td></tr>
|
||||
<tr><td>{$this->lang->totalWithOutTax}: <b>$this->currency_symbol$accum_sub_total</b></td></tr>
|
||||
<tr><td>{$this->lang->totalWithTax}: <b>$this->currency_symbol$accum_total_cost</b></td></tr></table>";
|
||||
}
|
||||
elseif($total_type=='employees')
|
||||
{
|
||||
echo "<center><b>{$this->lang->totalsShownBetween} $date1 {$this->lang->and} $date2</b></center>";
|
||||
echo "<table align='center' cellspacing='$this->cellspacing' cellpadding='$this->cellpadding' bgcolor='$this->table_bgcolor' width='60%' style=\"border: $this->border_style $this->border_color $this->border_width px\">";
|
||||
|
||||
echo "<tr bgcolor=$this->header_rowcolor>\n\n";
|
||||
|
||||
for($k=0;$k< count($tableheaders);$k++)
|
||||
{
|
||||
echo "<th align='center'>\n<font color='$this->header_text_color' face='$this->headerfont_face' size='$this->headerfont_size'>$tableheaders[$k]</font>\n</th>\n";
|
||||
}
|
||||
|
||||
echo '</tr>'."\n\n";
|
||||
|
||||
$query="SELECT * FROM $users_table ORDER BY last_name";
|
||||
$employee_result=mysql_query($query,$this->conn);
|
||||
$temp_cust_id=0;
|
||||
|
||||
$accum_sub_total=0;
|
||||
$accum_total_cost=0;
|
||||
$accum_items_purhcased=0;
|
||||
$row_counter=0;
|
||||
while($row=mysql_fetch_assoc($employee_result))
|
||||
{
|
||||
$temp_empl_id=$row['id'];
|
||||
$employee_name=$this->formatData('user_id',$temp_empl_id,$tableprefix);
|
||||
$query2="SELECT * FROM $sales_table WHERE sold_by=\"$temp_empl_id\" and date between \"$date1\" and \"$date2\"";
|
||||
$result2=mysql_query($query2,$this->conn);
|
||||
|
||||
$sub_total=0;
|
||||
$total_cost=0;
|
||||
$items_purchased=0;
|
||||
|
||||
while($row2=mysql_fetch_assoc($result2))
|
||||
{
|
||||
$sub_total+=$row2['sale_sub_total'];
|
||||
$accum_sub_total+=$row2['sale_sub_total'];
|
||||
|
||||
$total_cost+=$row2['sale_total_cost'];
|
||||
$accum_total_cost+=$row2['sale_total_cost'];
|
||||
|
||||
$items_purchased+=$row2['items_purchased'];
|
||||
$accum_items_purhcased+=$row2['items_purchased'];
|
||||
}
|
||||
$row_counter++;
|
||||
|
||||
$sub_total=number_format($sub_total,2,'.', '');
|
||||
$total_cost=number_format($total_cost,2,'.', '');
|
||||
|
||||
|
||||
if($row_counter%2==0)
|
||||
{
|
||||
echo "\n<tr bgcolor=$this->rowcolor1>\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
echo "\n<tr bgcolor=$this->rowcolor2>\n";
|
||||
}
|
||||
|
||||
echo "<td align='center'>\n<font color='$this->rowcolor_text' face='$this->rowfont_face' size='$this->rowfont_size'>$employee_name</font>\n</td>
|
||||
<td align='center'>\n<font color='$this->rowcolor_text' face='$this->rowfont_face' size='$this->rowfont_size'>$items_purchased</font>\n</td>
|
||||
<td align='center'>\n<font color='$this->rowcolor_text' face='$this->rowfont_face' size='$this->rowfont_size'>$this->currency_symbol$sub_total</font>\n</td>
|
||||
<td align='center'>\n<font color='$this->rowcolor_text' face='$this->rowfont_face' size='$this->rowfont_size'>$this->currency_symbol$total_cost</font>\n</td>
|
||||
</tr>";
|
||||
}
|
||||
echo '</table>';
|
||||
$accum_sub_total=number_format($accum_sub_total,2,'.', '');
|
||||
$accum_total_cost=number_format($accum_total_cost,2,'.', '');
|
||||
|
||||
echo "<br><table align='right' cellspacing='$this->cellspacing' cellpadding='$this->cellpadding' bgcolor='$this->table_bgcolor' width='60%' border=0>";
|
||||
echo "<tr><td>{$this->lang->totalItemsPurchased}:<b> $accum_items_purhcased</b></td></tr>
|
||||
<tr><td>{$this->lang->totalWithOutTax}: <b>$this->currency_symbol$accum_sub_total</b></td></tr>
|
||||
<tr><td>{$this->lang->totalWithTax}: <b> $this->currency_symbol$accum_total_cost</b></td></tr></table>";
|
||||
|
||||
|
||||
|
||||
}
|
||||
elseif($total_type=='items')
|
||||
{
|
||||
echo "<center><b>{$this->lang->totalsShownBetween} $date1 {$this->lang->and} $date2</b></center>";
|
||||
echo "<table align='center' cellspacing='$this->cellspacing' cellpadding='$this->cellpadding' bgcolor='$this->table_bgcolor' width='70%' style=\"border: $this->border_style $this->border_color $this->border_width px\">";
|
||||
|
||||
echo "<tr bgcolor=$this->header_rowcolor>\n\n";
|
||||
|
||||
for($k=0;$k< count($tableheaders);$k++)
|
||||
{
|
||||
echo "<th align='center'>\n<font color='$this->header_text_color' face='$this->headerfont_face' size='$this->headerfont_size'>$tableheaders[$k]</font>\n</th>\n";
|
||||
}
|
||||
|
||||
echo '</tr>'."\n\n";
|
||||
|
||||
|
||||
$query="SELECT * FROM $items_table ORDER BY item_name";
|
||||
$item_result=mysql_query($query,$this->conn);
|
||||
$temp_item_id=0;
|
||||
|
||||
$accum_sub_total=0;
|
||||
$accum_total_cost=0;
|
||||
$accum_items_purhcased=0;
|
||||
$row_counter=0;
|
||||
while($row=mysql_fetch_assoc($item_result))
|
||||
{
|
||||
$temp_item_id=$row['id'];
|
||||
$item_name=$this->formatData('item_id',$temp_item_id,$tableprefix);
|
||||
$temp_brand=$this->idToField($brands_table,'brand',$this->idToField($items_table,'brand_id',$temp_item_id));
|
||||
$temp_category=$this->idToField($categories_table,'category',$this->idToField($items_table,'category_id',$temp_item_id));
|
||||
$temp_supplier=$this->idToField($suppliers_table,'supplier',$this->idToField($items_table,'supplier_id',$temp_item_id));
|
||||
|
||||
$query2=mysql_query("SELECT * FROM $sales_table WHERE date between \"$date1\" and \"$date2\" ORDER by id ASC",$this->conn);
|
||||
$sale_row1=mysql_fetch_assoc($query2);
|
||||
$low_sale_id=$sale_row1['id'];
|
||||
|
||||
$query3=mysql_query("SELECT * FROM $sales_table WHERE date between \"$date1\" and \"$date2\" ORDER by id DESC",$this->conn);
|
||||
$sale_row2=mysql_fetch_assoc($query3);
|
||||
$high_sale_id=$sale_row2['id'];
|
||||
|
||||
|
||||
$query4="SELECT * FROM $sales_items_table WHERE item_id=\"$temp_item_id\" and sale_id between \"$low_sale_id\" and \"$high_sale_id\"";
|
||||
$result4=mysql_query($query4,$this->conn);
|
||||
|
||||
$sub_total=0;
|
||||
$total_cost=0;
|
||||
$items_purchased=0;
|
||||
|
||||
while($row2=mysql_fetch_assoc($result4))
|
||||
{
|
||||
$sub_total+=$row2['item_total_cost']-$row2['item_total_tax'];
|
||||
$accum_sub_total+=$row2['item_total_cost']-$row2['item_total_tax'];
|
||||
|
||||
$total_cost+=$row2['item_total_cost'];
|
||||
$accum_total_cost+=$row2['item_total_cost'];
|
||||
|
||||
$items_purchased+=$row2['quantity_purchased'];
|
||||
$accum_items_purhcased+=$row2['quantity_purchased'];
|
||||
}
|
||||
$row_counter++;
|
||||
|
||||
$sub_total=number_format($sub_total,2,'.', '');
|
||||
$total_cost=number_format($total_cost,2,'.', '');
|
||||
|
||||
|
||||
if($row_counter%2==0)
|
||||
{
|
||||
echo "\n<tr bgcolor=$this->rowcolor1>\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
echo "\n<tr bgcolor=$this->rowcolor2>\n";
|
||||
}
|
||||
|
||||
echo "<td align='center'>\n<font color='$this->rowcolor_text' face='$this->rowfont_face' size='$this->rowfont_size'>$item_name</font>\n</td>
|
||||
<td align='center'>\n<font color='$this->rowcolor_text' face='$this->rowfont_face' size='$this->rowfont_size'>$temp_brand</font>\n</td>
|
||||
<td align='center'>\n<font color='$this->rowcolor_text' face='$this->rowfont_face' size='$this->rowfont_size'>$temp_category</font>\n</td>
|
||||
<td align='center'>\n<font color='$this->rowcolor_text' face='$this->rowfont_face' size='$this->rowfont_size'>$temp_supplier</font>\n</td>
|
||||
<td align='center'>\n<font color='$this->rowcolor_text' face='$this->rowfont_face' size='$this->rowfont_size'>$items_purchased</font>\n</td>
|
||||
<td align='center'>\n<font color='$this->rowcolor_text' face='$this->rowfont_face' size='$this->rowfont_size'>$this->currency_symbol$sub_total</font>\n</td>
|
||||
<td align='center'>\n<font color='$this->rowcolor_text' face='$this->rowfont_face' size='$this->rowfont_size'>$this->currency_symbol$total_cost</font>\n</td>
|
||||
|
||||
|
||||
|
||||
</tr>";
|
||||
}
|
||||
echo '</table>';
|
||||
$accum_sub_total=number_format($accum_sub_total,2,'.', '');
|
||||
$accum_total_cost=number_format($accum_total_cost,2,'.', '');
|
||||
|
||||
echo "<br><table align='right' cellspacing='$this->cellspacing' cellpadding='$this->cellpadding' bgcolor='$this->table_bgcolor' width='60%' border=0>";
|
||||
echo "<tr><td>{$this->lang->totalItemsPurchased}:<b> $accum_items_purhcased</b></td></tr>
|
||||
<tr><td>{$this->lang->totalWithOutTax}: <b>$this->currency_symbol$accum_sub_total</b></td></tr>
|
||||
<tr><td>{$this->lang->totalWithTax}: <b> $this->currency_symbol$accum_total_cost</b></td></tr></table>";
|
||||
}
|
||||
elseif($total_type=='item')
|
||||
{
|
||||
echo "<center><b>{$this->lang->totalsShownBetween} $date1 {$this->lang->and} $date2</b></center>";
|
||||
echo "<table align='center' cellspacing='$this->cellspacing' cellpadding='$this->cellpadding' bgcolor='$this->table_bgcolor' width='60%' style=\"border: $this->border_style $this->border_color $this->border_width px\">";
|
||||
|
||||
echo "<tr bgcolor=$this->header_rowcolor>\n\n";
|
||||
|
||||
for($k=0;$k< count($tableheaders);$k++)
|
||||
{
|
||||
echo "<th align='center'>\n<font color='$this->header_text_color' face='$this->headerfont_face' size='$this->headerfont_size'>$tableheaders[$k]</font>\n</th>\n";
|
||||
}
|
||||
|
||||
echo '</tr>'."\n\n";
|
||||
|
||||
$query="SELECT * FROM $items_table WHERE $where1=\"$where2\" ORDER BY item_name";
|
||||
$item_result=mysql_query($query,$this->conn);
|
||||
$row=mysql_fetch_assoc($item_result);
|
||||
$temp_item_id=$row['id'];
|
||||
$item_name=$this->formatData('item_id',$temp_item_id,$tableprefix);
|
||||
$temp_brand=$this->idToField($brands_table,'brand',$this->idToField($items_table,'brand_id',$temp_item_id));
|
||||
$temp_category=$this->idToField($categories_table,'category',$this->idToField($items_table,'category_id',$temp_item_id));
|
||||
$temp_supplier=$this->idToField($suppliers_table,'supplier',$this->idToField($items_table,'supplier_id',$temp_item_id));
|
||||
|
||||
$item_name=$this->formatData('item_id',$temp_item_id,$tableprefix);
|
||||
|
||||
$query2=mysql_query("SELECT * FROM $sales_table WHERE date between \"$date1\" and \"$date2\" ORDER by id ASC",$this->conn);
|
||||
$sale_row1=mysql_fetch_assoc($query2);
|
||||
$low_sale_id=$sale_row1['id'];
|
||||
|
||||
$query3=mysql_query("SELECT * FROM $sales_table WHERE date between \"$date1\" and \"$date2\" ORDER by id DESC",$this->conn);
|
||||
$sale_row2=mysql_fetch_assoc($query3);
|
||||
$high_sale_id=$sale_row2['id'];
|
||||
|
||||
|
||||
$query4="SELECT * FROM $sales_items_table WHERE item_id=\"$temp_item_id\" and sale_id between \"$low_sale_id\" and \"$high_sale_id\"";
|
||||
$result4=mysql_query($query4,$this->conn);
|
||||
|
||||
|
||||
$sub_total=0;
|
||||
$total_cost=0;
|
||||
$items_purchased=0;
|
||||
|
||||
while($row2=mysql_fetch_assoc($result4))
|
||||
{
|
||||
$sub_total+=$row2['item_total_cost']-$row2['item_total_tax'];
|
||||
$total_cost+=$row2['item_total_cost'];
|
||||
$items_purchased+=$row2['quantity_purchased'];
|
||||
}
|
||||
|
||||
$sub_total=number_format($sub_total,2,'.', '');
|
||||
$total_cost=number_format($total_cost,2,'.', '');
|
||||
|
||||
|
||||
echo "\n<tr bgcolor=$this->rowcolor1>\n";
|
||||
|
||||
echo "<td align='center'>\n<font color='$this->rowcolor_text' face='$this->rowfont_face' size='$this->rowfont_size'>$item_name</font>\n</td>
|
||||
<td align='center'>\n<font color='$this->rowcolor_text' face='$this->rowfont_face' size='$this->rowfont_size'>$temp_brand</font>\n</td>
|
||||
<td align='center'>\n<font color='$this->rowcolor_text' face='$this->rowfont_face' size='$this->rowfont_size'>$temp_category</font>\n</td>
|
||||
<td align='center'>\n<font color='$this->rowcolor_text' face='$this->rowfont_face' size='$this->rowfont_size'>$temp_supplier</font>\n</td>
|
||||
<td align='center'>\n<font color='$this->rowcolor_text' face='$this->rowfont_face' size='$this->rowfont_size'>$items_purchased</font>\n</td>
|
||||
<td align='center'>\n<font color='$this->rowcolor_text' face='$this->rowfont_face' size='$this->rowfont_size'>$this->currency_symbol$sub_total</font>\n</td>
|
||||
<td align='center'>\n<font color='$this->rowcolor_text' face='$this->rowfont_face' size='$this->rowfont_size'>$this->currency_symbol$total_cost</font>\n</td>
|
||||
|
||||
|
||||
</tr>";
|
||||
|
||||
echo '</table>';
|
||||
|
||||
}
|
||||
elseif($total_type=='profit')
|
||||
{
|
||||
|
||||
|
||||
echo "<center><b>{$this->lang->totalsShownBetween} $date1 {$this->lang->and} $date2</b></center>";
|
||||
echo "<table align='center' cellspacing='$this->cellspacing' cellpadding='$this->cellpadding' bgcolor='$this->table_bgcolor' width='40%' style=\"border: $this->border_style $this->border_color $this->border_width px\">";
|
||||
|
||||
echo "<tr bgcolor=$this->header_rowcolor>\n\n";
|
||||
|
||||
for($k=0;$k< count($tableheaders);$k++)
|
||||
{
|
||||
echo "<th align='center'>\n<font color='$this->header_text_color' face='$this->headerfont_face' size='$this->headerfont_size'>$tableheaders[$k]</font>\n</th>\n";
|
||||
}
|
||||
|
||||
echo '</tr>'."\n\n";
|
||||
|
||||
$query="SELECT DISTINCT date FROM $sales_table WHERE date between \"$date1\" and \"$date2\" ORDER by date ASC";
|
||||
$result=mysql_query($query);
|
||||
|
||||
$amount_sold=0;
|
||||
$profit=0;
|
||||
$total_amount_sold=0;
|
||||
$total_profit=0;
|
||||
while($row=mysql_fetch_assoc($result))
|
||||
{
|
||||
|
||||
$amount_sold=0;
|
||||
$profit=0;
|
||||
|
||||
$distinct_date=$row['date'];
|
||||
$result2=mysql_query("SELECT * FROM $sales_table WHERE date=\"$distinct_date\"",$this->conn);
|
||||
|
||||
echo "\n<tr bgcolor=$this->rowcolor1>\n";
|
||||
|
||||
echo "<td align='center'>\n<font color='$this->rowcolor_text' face='$this->rowfont_face' size='$this->rowfont_size'>$distinct_date</font>\n</td>";
|
||||
|
||||
while($row2=mysql_fetch_assoc($result2))
|
||||
{
|
||||
$amount_sold+=$row2['sale_sub_total'];
|
||||
$total_amount_sold+=$row2['sale_sub_total'];
|
||||
$profit+=$this->getProfit($row2['id'],$tableprefix);
|
||||
$total_profit+=$this->getProfit($row2['id'],$tableprefix);
|
||||
|
||||
}
|
||||
|
||||
$amount_sold=number_format($amount_sold,2,'.', '');
|
||||
$profit=number_format($profit,2,'.', '');
|
||||
|
||||
echo "<td align='center'>\n<font color='$this->rowcolor_text' face='$this->rowfont_face' size='$this->rowfont_size'>$this->currency_symbol$amount_sold</font>\n</td>";
|
||||
echo "<td align='center'>\n<font color='$this->rowcolor_text' face='$this->rowfont_face' size='$this->rowfont_size'>$this->currency_symbol$profit</font>\n</td>";
|
||||
|
||||
|
||||
echo "</tr>";
|
||||
}
|
||||
|
||||
echo '</table>';
|
||||
|
||||
|
||||
$total_amount_sold=number_format($total_amount_sold,2,'.', '');
|
||||
$total_profit=number_format($total_profit,2,'.', '');
|
||||
|
||||
echo "<br><table align='right' cellspacing='$this->cellspacing' cellpadding='$this->cellpadding' bgcolor='$this->table_bgcolor' width='60%' border=0>";
|
||||
echo "<tr><td>{$this->lang->totalAmountSold}: <b>$this->currency_symbol$total_amount_sold</b></td></tr>
|
||||
<tr><td>{$this->lang->totalProfit}: <b>$this->currency_symbol$total_profit</b></td></tr>
|
||||
</table>";
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
function getProfit($sale_id,$tableprefix)
|
||||
{
|
||||
$sales_items_table="$tableprefix".'sales_items';
|
||||
$query="SELECT * FROM $sales_items_table WHERE sale_id=\"$sale_id\"";
|
||||
$result=mysql_query($query,$this->conn);
|
||||
|
||||
$profit=0;
|
||||
while($row=mysql_fetch_assoc($result))
|
||||
{
|
||||
$profit+=($row['item_unit_price']-$row['item_buy_price'])*$row['quantity_purchased'];
|
||||
}
|
||||
|
||||
return $profit;
|
||||
}
|
||||
|
||||
function formatData($field,$data,$tableprefix)
|
||||
{
|
||||
if($field=='unit_price' or $field=='total_cost' or $field=='buy_price' or $field=='sale_sub_total' or $field=='sale_total_cost' or $field=='item_unit_price' or $field=='item_total_cost' or $field=='item_total_tax' )
|
||||
{
|
||||
return "$this->currency_symbol"."$data";
|
||||
}
|
||||
elseif($field=='tax_percent' or $field=='percent_off')
|
||||
{
|
||||
return "$data".'%';
|
||||
}
|
||||
elseif($field=='brand_id')
|
||||
{
|
||||
return $this->idToField("$tableprefix".'brands','brand',$data);
|
||||
}
|
||||
elseif($field=='category_id')
|
||||
{
|
||||
return $this->idToField("$tableprefix".'categories','category',$data);
|
||||
}
|
||||
elseif($field=='supplier_id')
|
||||
{
|
||||
return $this->idToField("$tableprefix".'suppliers','supplier',$data);
|
||||
}
|
||||
elseif($field=='customer_id')
|
||||
{
|
||||
$field_first_name=$this->idToField("$tableprefix".'customers','first_name',$data);
|
||||
$field_last_name=$this->idToField("$tableprefix".'customers','last_name',$data);
|
||||
return $field_first_name.' '.$field_last_name;
|
||||
}
|
||||
elseif($field=='user_id')
|
||||
{
|
||||
$field_first_name=$this->idToField("$tableprefix".'users','first_name',$data);
|
||||
$field_last_name=$this->idToField("$tableprefix".'users','last_name',$data);
|
||||
return $field_first_name.' '.$field_last_name;
|
||||
}
|
||||
elseif($field=='item_id')
|
||||
{
|
||||
return $this->idToField("$tableprefix".'items','item_name',$data);
|
||||
}
|
||||
elseif($field=='sold_by')
|
||||
{
|
||||
$field_first_name=$this->idToField("$tableprefix".'users','first_name',$data);
|
||||
$field_last_name=$this->idToField("$tableprefix".'users','last_name',$data);
|
||||
return $field_first_name.' '.$field_last_name;
|
||||
}
|
||||
elseif($field=='supplier_id')
|
||||
{
|
||||
return $this->idToField("$tableprefix".'suppliers','supplier',$data);
|
||||
}
|
||||
elseif($field=='password')
|
||||
{
|
||||
return '*******';
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
return "$data";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
?>
|
||||
Executable
+309
@@ -0,0 +1,309 @@
|
||||
<?php
|
||||
|
||||
class form
|
||||
{
|
||||
var $row_color,$text_color;
|
||||
var $lang;
|
||||
|
||||
function form($form_action,$form_method,$form_name,$table_width,$theme,$language)
|
||||
{
|
||||
//pre: all parameters are strings.
|
||||
//post: sets up the form header along with the table to display form
|
||||
|
||||
$this->lang=$language;
|
||||
$getType=explode('_',$form_action);
|
||||
$type=$getType[0];
|
||||
|
||||
if($type=='manage')
|
||||
{
|
||||
$url=$_SERVER['PHP_SELF'];
|
||||
|
||||
if(isset($_POST['search']) or isset($_GET['outofstock']) or isset($_GET['reorder']))
|
||||
{
|
||||
echo "<center><a href='$url'>[{$this->lang->clearSearch}]</a></center>";
|
||||
}
|
||||
|
||||
echo "<form action='$form_action' method='$form_method' name='$form_name'>
|
||||
<center>\n<table border='0' width='$table_width' cellspacing='2' cellpadding='0'>";
|
||||
}
|
||||
else
|
||||
{
|
||||
echo "<form action='$form_action' method='$form_method' name='$form_name'>
|
||||
<center><b>*{$this->lang->itemsInBoldRequired}</b>\n<table border='0' width='$table_width' cellspacing='2' cellpadding='0'>";
|
||||
}
|
||||
|
||||
switch($theme)
|
||||
{
|
||||
//add more themes
|
||||
case $theme=='serious':
|
||||
$this->row_color='#DDDDDD';
|
||||
$this->text_color='black';
|
||||
|
||||
break;
|
||||
|
||||
case $theme=='big blue':
|
||||
$this->row_color='#15759B';
|
||||
$this->text_color='white';
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
function formBreak ($table_width,$theme)
|
||||
{
|
||||
|
||||
{
|
||||
echo "<table border='0' width='$table_width' cellspacing='2' cellpadding='0'>";
|
||||
}
|
||||
|
||||
switch($theme)
|
||||
{
|
||||
//add more themes
|
||||
case $theme=='serious':
|
||||
$this->row_color='#DDDDDD';
|
||||
$this->text_color='black';
|
||||
|
||||
break;
|
||||
|
||||
case $theme=='big blue':
|
||||
$this->row_color='#15759B';
|
||||
$this->text_color='white';
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function createInputField($field_title,$input_type,$input_name,$input_value,$input_size,$td_width,$disabled=NULL)
|
||||
{
|
||||
//pre: all parameters are strings.
|
||||
//post: creates in inputField based on parameters.
|
||||
|
||||
echo"
|
||||
<tr bgcolor=$this->row_color>
|
||||
<td width='$td_width'><font color='$this->text_color'>$field_title</font></td>
|
||||
<td><input type='$input_type' name='$input_name' value='$input_value' size='$input_size' $disabled></td>
|
||||
</tr>\n";
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
function createCheckboxField($field_title,$check_name,$td_width,$disabled=NULL,$checked=NULL,$postlabel=NULL)
|
||||
{
|
||||
//pre: all parameters are strings option selected value is at pos 0.
|
||||
//post: creates in CheckboxField based on parameters.
|
||||
|
||||
echo "
|
||||
<tr bgcolor=$this->row_color>
|
||||
<td width='$td_width'><font color='$this->text_color'>$field_title</font></td>
|
||||
<td>";
|
||||
|
||||
echo"<input type=checkbox name=$check_name $checked $disabled/>$postlabel<br />";
|
||||
}
|
||||
|
||||
function createRadioField($field_title,$radio_name,$option_values,$option_titles,$td_width,$disabled=NULL,$selected=NULL)
|
||||
{
|
||||
//pre: all parameters are strings option selected value is at pos 0.
|
||||
//post: creates in selectField based on parameters.
|
||||
|
||||
echo "
|
||||
<tr bgcolor=$this->row_color>
|
||||
<td width='$td_width'><font color='$this->text_color'>$field_title</font></td>
|
||||
<td>";
|
||||
|
||||
if($option_values[0]!='')
|
||||
{
|
||||
echo"<input type=radio name=$radio_name value=$option_values[0] $disabled>$option_titles[0]<br>";
|
||||
}
|
||||
for($k=1;$k< count($option_values); $k++)
|
||||
{
|
||||
if($option_values[$k]!=$option_values[0] )
|
||||
{
|
||||
if($selected==$option_values[$k]){
|
||||
echo "<input type=radio name=$radio_name value=$option_values[$k] $disabled CHECKED>$option_titles[$k]<br>";
|
||||
}
|
||||
else {
|
||||
echo"<input type=radio name=$radio_name value=$option_values[$k] $disabled>$option_titles[$k]<br>";;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
echo '</select>
|
||||
</td>
|
||||
</tr>'."\n";
|
||||
|
||||
}
|
||||
|
||||
|
||||
function createSelectField($field_title,$select_name,$option_values,$option_titles,$td_width,$disabled=NULL,$selected=NULL)
|
||||
{
|
||||
//pre: all parameters are strings option selected value is at pos 0.
|
||||
//post: creates in selectField based on parameters.
|
||||
|
||||
echo "
|
||||
<tr bgcolor=$this->row_color>
|
||||
<td width='$td_width'><font color='$this->text_color'>$field_title</font></td>
|
||||
<td><select name='$select_name' $disabled>";
|
||||
|
||||
if($option_values[0]!='')
|
||||
{
|
||||
echo"<option value=\"$option_values[0]\">$option_titles[0]</option>";
|
||||
}
|
||||
for($k=1;$k< count($option_values); $k++)
|
||||
{
|
||||
if($option_values[$k]!=$option_values[0] )
|
||||
{
|
||||
if($selected==$option_values[$k]){ echo "<option value='$option_values[$k]' SELECTED>$option_titles[$k]</option>"; }
|
||||
else { echo "<option value='$option_values[$k]'>$option_titles[$k]</option>"; }
|
||||
}
|
||||
}
|
||||
|
||||
echo '</select>
|
||||
</td>
|
||||
</tr>'."\n";
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
function createDateSelectField()
|
||||
{
|
||||
?>
|
||||
<tr bgcolor=<?php echo $this->row_color ?> ><td><b><font color=<?php echo $this->text_color ?>><?php echo" {$this->lang->fromMonth}"; ?>:</font></b> <select name=month1>
|
||||
<?php
|
||||
for($k=1;$k<=12;$k++)
|
||||
if($k==date("n"))
|
||||
echo "<option selected value=\"".$k."\">".date("M",mktime(0,0,0,$k,1,0))."</option>";
|
||||
else
|
||||
echo "<option value=\"".$k."\">".date("M",mktime(0,0,0,$k,1,0))."</option>";
|
||||
?>
|
||||
</select></td>
|
||||
<td><b><font color=<?php echo $this->text_color ?>><?php echo" {$this->lang->day}"; ?>:</font></b> <select name=day1>
|
||||
<?php
|
||||
for($k=1;$k<=31;$k++)
|
||||
if($k==date("j"))
|
||||
echo "<option selected value=\"".$k."\">".$k."</option>";
|
||||
else
|
||||
echo "<option value=\"".$k."\">".$k."</option>";
|
||||
?>
|
||||
</select></td>
|
||||
<td><b><font color=<?php echo $this->text_color ?>><?php echo" {$this->lang->year}"; ?>:</font></b> <select name=year1>
|
||||
<?php
|
||||
for($k=2003;$k<=date("Y");$k++)
|
||||
if($k==date("Y"))
|
||||
echo "<option selected value=\"".$k."\">".$k."</option>";
|
||||
else
|
||||
echo "<option value=\"".$k."\">".$k."</option>";
|
||||
?>
|
||||
</select></td>
|
||||
<td><b><font color=<?php echo $this->text_color ?>><?php echo" {$this->lang->toMonth}"; ?>:</font> <select name=month2>
|
||||
<?php
|
||||
for($k=1;$k<=12;$k++)
|
||||
if($k==date("n"))
|
||||
echo "<option selected value=\"".$k."\">".date("M",mktime(0,0,0,$k,1,0))."</option>";
|
||||
else
|
||||
echo "<option value=\"".$k."\">".date("M",mktime(0,0,0,$k,1,0))."</option>";
|
||||
?>
|
||||
</select></td>
|
||||
<td><b><font color=<?php echo $this->text_color ?>><?php echo" {$this->lang->day}"; ?>:</font></b> <select name=day2>
|
||||
<?php
|
||||
for($k=1;$k<=31;$k++)
|
||||
if($k==date("j"))
|
||||
echo "<option selected value=\"".$k."\">".$k."</option>";
|
||||
else
|
||||
echo "<option value=\"".$k."\">".$k."</option>";
|
||||
?>
|
||||
</select></td>
|
||||
<td><b><font color=<?php echo $this->text_color ?>><?php echo" {$this->lang->year}"; ?>:</font></b> <select name=year2>
|
||||
<?php
|
||||
for($k=2003;$k<=date("Y");$k++)
|
||||
if($k==date("Y"))
|
||||
echo "<option selected value=\"".$k."\">".$k."</option>";
|
||||
else
|
||||
echo "<option value=\"".$k."\">".$k."</option>";
|
||||
?>
|
||||
</select></td></tr>
|
||||
<?php
|
||||
}
|
||||
|
||||
function createSingleDateSelectField($selname=NULL)
|
||||
{
|
||||
?>
|
||||
<tr bgcolor=<?php echo $this->row_color ?> ><td width='$td_width'><font color='<?php echo $this->text_color ?>'><?php echo $selname ?></font></td>
|
||||
<td><select name=month>
|
||||
<?php
|
||||
for($k=1;$k<=12;$k++)
|
||||
if($k==date("n"))
|
||||
echo "<option selected value=\"".$k."\">".date("M",mktime(0,0,0,$k,1,0))."</option>";
|
||||
else
|
||||
echo "<option value=\"".$k."\">".date("M",mktime(0,0,0,$k,1,0))."</option>";
|
||||
?>
|
||||
</select>
|
||||
<select name=day>
|
||||
<?php
|
||||
for($k=1;$k<=31;$k++)
|
||||
if($k==date("j"))
|
||||
echo "<option selected value=\"".$k."\">".$k."</option>";
|
||||
else
|
||||
echo "<option value=\"".$k."\">".$k."</option>";
|
||||
?>
|
||||
</select>
|
||||
<select name=year>
|
||||
<?php
|
||||
$thisyear = date("Y");
|
||||
for($k=$thisyear;$k<=date("Y");$k++)
|
||||
if($k==date("Y"))
|
||||
echo "<option selected value=\"".$k."\">".$k."</option>";
|
||||
else
|
||||
echo "<option value=\"".$k."\">".$k."</option>";
|
||||
?>
|
||||
</select></td>
|
||||
</tr>
|
||||
<?php
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
function createTextareaField($field_title,$textarea_name,$textarea_rows,$textarea_cols,$textarea_value,$td_width)
|
||||
{
|
||||
//pre: all parameters are strings.
|
||||
//post: creates a textarea field.
|
||||
|
||||
echo "
|
||||
<tr bgcolor=$this->row_color>
|
||||
<td width='$td_width' valign='top'><font color='$this->text_color'>$field_title</font></td>
|
||||
<td><textarea name='$textarea_name' rows='$textarea_rows' cols='$textarea_cols'>$textarea_value</textarea>";
|
||||
}
|
||||
|
||||
function endForm()
|
||||
{
|
||||
//adds submit button and ends remainings tags.
|
||||
echo "
|
||||
<tr>
|
||||
<td colspan=2 align=center>$altbutton<input type=submit value=Submit></td>
|
||||
|
||||
</tr>
|
||||
</table>
|
||||
</center>
|
||||
</form>";
|
||||
}
|
||||
|
||||
function endLibraryForm()
|
||||
{
|
||||
//adds submit button and ends remainings tags.
|
||||
echo "
|
||||
<tr>
|
||||
<td colspan=2 align=center><input type=submit name=signin value='Sign Bike In/Out'></td>
|
||||
|
||||
</tr>
|
||||
</table>
|
||||
</center>
|
||||
</form>";
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
?>
|
||||
Executable
+258
@@ -0,0 +1,258 @@
|
||||
<?php
|
||||
|
||||
class security_functions
|
||||
{
|
||||
var $conn;
|
||||
var $lang;
|
||||
var $tblprefix;
|
||||
|
||||
//defalt constructor which first checks if page is accessable.
|
||||
function security_functions($dbf,$page_type,$language)
|
||||
{
|
||||
//pre: $dbf must be a db_functions object and $page_type must be a string
|
||||
//post: denies access to page and stops php processing
|
||||
|
||||
//$page_type will be either: Public, Admin, Sales Clerk or Report Viewer.
|
||||
//$usertype will be either: Admin, Sales Clerk or Report Viewer.
|
||||
//Their must be a session present in order to execute authoization.
|
||||
|
||||
//sets class variables.
|
||||
$this->conn=$dbf->conn;
|
||||
$this->lang=$language;
|
||||
$this->tblprefix=$dbf->tblprefix;
|
||||
|
||||
if(isset($_SESSION['session_user_id']))
|
||||
{
|
||||
$user_id=$_SESSION['session_user_id'];
|
||||
|
||||
$tablename="$this->tblprefix".'users';
|
||||
$result = mysql_query("SELECT * FROM $tablename WHERE id=\"$user_id\"",$this->conn);
|
||||
//echo "$result";
|
||||
$row = mysql_fetch_assoc($result);
|
||||
$usertype= $row['type'];
|
||||
//echo "stupid";
|
||||
|
||||
|
||||
//If the page is not public or the user is not an Admin, investigation must continue.
|
||||
if($page_type!='Public' or $usertype!='Admin')
|
||||
{
|
||||
if($usertype!='Admin' and $usertype!='Sales Clerk' and $usertype!='Report Viewer')
|
||||
{
|
||||
//makes sure $usertype is not anything but Admin, Sales Clerk, Report Viewer
|
||||
|
||||
echo "{$this->lang->attemptedSecurityBreech}";
|
||||
exit();
|
||||
}
|
||||
elseif($page_type!='Public' and $page_type!='Admin' and $page_type!='Sales Clerk' and $page_type!='Report Viewer')
|
||||
{
|
||||
//makes sure $page_type is not anything but Public, Admin, Sales Clerk or Report Viewer.
|
||||
|
||||
echo "{$this->lang->attemptedSecurityBreech}";
|
||||
exit();
|
||||
|
||||
}
|
||||
elseif($usertype!='Admin' and $page_type=='Admin')
|
||||
{
|
||||
//if page is only intented for Admins but the user is not an admin, access is denied.
|
||||
|
||||
echo "{$this->lang->mustBeAdmin}";
|
||||
exit();
|
||||
}
|
||||
elseif(($usertype=='Sales Clerk') and $page_type =='Report Viewer')
|
||||
{
|
||||
//Page is only intented for Report Viewers and Admins.
|
||||
|
||||
echo "{$this->lang->mustBeReportOrAdmin}";
|
||||
exit();
|
||||
}
|
||||
elseif(($usertype=='Report Viewer') and $page_type =='Sales Clerk')
|
||||
{
|
||||
//Page is only intented for Sales Clerks and Admins.
|
||||
|
||||
echo "{$this->lang->mustBeSalesClerkOrAdmin}";
|
||||
exit();
|
||||
}
|
||||
}
|
||||
}
|
||||
/*if(!$this->isLoggedIn()){
|
||||
header("location: ../login.php");
|
||||
exit();
|
||||
}
|
||||
if(!$this->isOpen()){
|
||||
header("location: ../books/openshop.php");
|
||||
exit();
|
||||
}*/
|
||||
}
|
||||
|
||||
function isLoggedIn()
|
||||
{
|
||||
//returns boolean based on if user is logged in.
|
||||
|
||||
if(isset($_SESSION['session_user_id']))
|
||||
{
|
||||
$user_id=$_SESSION['session_user_id'];
|
||||
$tablename="$this->tblprefix".'users';
|
||||
$result = mysql_query ("SELECT * FROM $tablename WHERE id=\"$user_id\"",$this->conn);
|
||||
$num = @mysql_num_rows($result);
|
||||
if($num> 0)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function checkLogin($username,$password)
|
||||
{
|
||||
//pre: $username and $password must be strings. ($password is encrypted)
|
||||
//post: returns boolean based on if their login was succesfull.
|
||||
|
||||
$tablename="$this->tblprefix".'users';
|
||||
$result = mysql_query ("SELECT * FROM $tablename WHERE username=\"$username\" and password=\"$password\"",$this->conn);
|
||||
$num = @mysql_num_rows($result);
|
||||
|
||||
if($num > 0)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
function closeSale()
|
||||
{
|
||||
//deletes sessions vars
|
||||
session_unregister('items_in_sale');
|
||||
session_unregister('current_sale_customer_id');
|
||||
session_unregister('current_item_search');
|
||||
session_unregister('current_customer_search');
|
||||
}
|
||||
|
||||
function checkMembership($userID)
|
||||
{
|
||||
global $cfg_membershipID;
|
||||
// Construct the join query
|
||||
$memquery = "SELECT sales.id, sales_items.sale_id, sales_items.item_id, DATE_ADD( sales.date, INTERVAL 1 YEAR ) AS expires
|
||||
FROM sales, sales_items
|
||||
WHERE sales.id = sales_items.sale_id
|
||||
AND sales_items.item_id=$cfg_membershipID
|
||||
AND sales.customer_id=$userID
|
||||
ORDER BY sales.date DESC
|
||||
LIMIT 1;";
|
||||
//"SELECT sales.id, sales_items.sale_id, sales_items.item_id, DATE_ADD(sales.date, INTERVAL 1 YEAR) as expires ".
|
||||
//"FROM sales, sales_items "."WHERE sales.id = sales_items.sale_id AND sales_items.item_id = '$cfg_membershipID' AND sales.customer_id = '$userID'";
|
||||
$memresult = mysql_query($memquery) or die(mysql_error());
|
||||
|
||||
if(mysql_num_rows($memresult) < 1){
|
||||
return false;
|
||||
}
|
||||
// Get expiry date
|
||||
$today = date('Y-m-d');
|
||||
$row = mysql_fetch_array($memresult);
|
||||
$expires = $row['expires'];
|
||||
if($row[item_id] == "1" && $expires >= $today){
|
||||
return true;
|
||||
}else{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
function checkWaiver($userID)
|
||||
{
|
||||
// If Membership is ok, check waiver
|
||||
$waiverresult = mysql_query("SELECT waiver FROM customers WHERE id='$userID'");
|
||||
if (!$waiverresult) { die("Query to check on status of liability waiver failed"); }
|
||||
while ($waiverrow = mysql_fetch_array($waiverresult)) {
|
||||
if ($waiverrow[waiver] == 0 || $waiverrow[waiver] == ""){ return false; } else { return true; }
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
function signinMember($userID, $intime, $activity)
|
||||
{
|
||||
global $cfg_reqmembership;
|
||||
$isinresult = mysql_query("SELECT userID FROM visits WHERE endout IS NULL");
|
||||
if (!$isinresult) { die("Query to show fields from table failed"); }
|
||||
|
||||
while($isinrow = mysql_fetch_array($isinresult)){
|
||||
if($userID == "$isinrow[userID]"){
|
||||
die("<b>Bike Error!! User is already signed in...</b>");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// MAKE SURE THEY'VE PAID THEIR MEMBERSHIP (IF REQUIRED BY CONFIG FILE)
|
||||
if($cfg_reqmembership == "1" && !$this->checkMembership($userID)){
|
||||
echo "Membership not paid or expired!<br /><a href=\"../home.php\">Go Home --></a>";
|
||||
die('');
|
||||
}
|
||||
|
||||
// Have you been a naughty schoolchild and not signed your waiver? PUNISH!
|
||||
if(!$this->checkWaiver($userID)){
|
||||
echo "Waiver not signed. Sign waiver, or no shop access you naughty boy!<br /><a href=\"../home.php\">Go Home --></a>";
|
||||
die('');
|
||||
}
|
||||
|
||||
|
||||
|
||||
// ADD IT TO THE VISITS DATABASE
|
||||
|
||||
$in = mktime($_POST[hour], $_POST[minute], 0, $_POST[month], $_POST[day], $_POST[year]);
|
||||
$tdin = date('Y-m-d H:i:s');
|
||||
//$activity = $_POST[activity];
|
||||
|
||||
if($userID){
|
||||
$query = "INSERT INTO `visits` (`userID` ,`intime` ,`activity`) VALUES ('$userID', '$tdin', '$activity')";
|
||||
// echo "IT FJDSFDSA $query";
|
||||
mysql_query($query);
|
||||
}
|
||||
}
|
||||
|
||||
function isOpen()
|
||||
{
|
||||
//include("settings.php");
|
||||
//echo "must open = $cfg_company";
|
||||
//if($cfg_mustOpen == "yes"){
|
||||
//echo "$this->conn";
|
||||
//return false;
|
||||
//}
|
||||
//return false;
|
||||
//$tablename="$this->tblprefix".'users';
|
||||
//$result = mysql_query("SELECT * FROM $tablename WHERE id=\"$user_id\"",$this->conn);
|
||||
|
||||
/*$today = date("Y-m-d");
|
||||
$le = mysql_query("SELECT event, date FROM books WHERE event='1' OR event='2' ORDER BY listID DESC LIMIT 1", $this->conn);
|
||||
//$le = mysql_query("SELECT * FROM books");//, $this->conn) or die(mysql_error());// WHERE event='1' OR event='2' ORDER BY listID DESC LIMIT 1", $this->conn);
|
||||
$lastevent = mysql_fetch_assoc($le);
|
||||
if(!$lastevent || $lastevent['event'] == 2 || $lastevent[date] != $today){// || !mysql_num_rows(mysql_query("SELECT * FROM books WHERE date='$today' AND event='1'"))){
|
||||
return false;
|
||||
}*/return true;
|
||||
//}
|
||||
return true;
|
||||
}
|
||||
|
||||
function isMechanicHere()
|
||||
{
|
||||
return mysql_fetch_array(mysql_query("SELECT userID FROM visits WHERE endout IS NULL AND activity='Mechanic'"));
|
||||
}
|
||||
|
||||
|
||||
function vaildMailman ($host)
|
||||
{
|
||||
$valid = @fsockopen("$host", 80, $errno, $errstr, 30);
|
||||
if ($valid) return TRUE;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
Reference in New Issue
Block a user