Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Code written by Lauri Orgla a.k.a OrX
- // If you have any questions u can either email, or msn me: TheOrX@hotmail.com
- <?php
- class CheckSystem {
- private $iDBhost, $iDBusername, $iDBpassword, $iDBname;
- public $iDebug;
- public $iMasterTable;
- function Debug($boolean) {
- $this->iDebug = $boolean;
- }
- function __construct($MasterTable) {
- $this->Debug(false);
- $this->iMasterTable = $MasterTable;
- @ob_end_clean();
- if($this->iMasterTable == ""){ die("Set Up the Master Table. Example: object = new CheckSystem('table name here') <br />"); }
- }
- function SQL($DBhost, $DBusername, $DBpassword, $DBname){/* start sql connecting function */
- $this->iDBhost = $DBhost;
- $this->iDBusername = $DBusername;
- $this->iDBpassword = $DBpassword;
- $this->iDBname = $DBname;
- mysql_connect($this->iDBhost,$this->iDBusername,$this->iDBpassword)or die("Could not connect to database! <br />");
- mysql_select_db($this->iDBname)or die("Could not select the database! <br />");
- if($this->iDebug == true){ echo "If no errors, then DB is selected, connected <br />"; }
- }
- function PrintDataTable($received, $clean){ // print either checks that are payed for or not
- if($clean == false){}else{ob_end_clean();}
- if($received == true){$str = "WHERE payment_received = 'true'";}else{$str = "";}
- $numrows = mysql_num_rows(mysql_query("SELECT * FROM ".$this->iMasterTable.""));
- $x = 0;
- echo "<center><h1>List of checks</h1></center>";
- while($x < $numrows){
- $inf = mysql_fetch_array(mysql_query("SELECT * FROM ".$this->iMasterTable." ".$str." ORDER BY id LIMIT $x, 1000000"));
- echo "<center><div align='left' style='background-color:#f5f5f5; border:1px; border-style:solid; width:700px; margin-bottom:5px;'>";
- echo $inf['check_number']." | ".$inf['check_prefix']." | ".$inf['print_date']." | ".$inf['check_tax']."€ | ".$inf['check_total']."€ | ".$inf['payment_received']." | ".$inf['payment_amount']."€";
- echo "</div></center>";
- $x++;
- }
- }
- function DisplayInsertForm() {
- echo " <form action='' method='post' name='".$this->iMasterTable."'><table><tr><td>Check Number</td><td><input type='text' name='check_number'></td></tr><tr><td>Prefix</td><td><input type='text' name='check_prefix'></td></tr>
- <tr><td>Print Date</td><td><input type='text' name='print_date'></td></tr><tr><td>Tax Amount</td><td><input type='text' name='check_tax'></td></tr><tr>
- <td>Total Amount</td><td><input type='text' name='check_total'></td></tr><tr><td><input type='submit' value='Insert!'></td><td></td></tr></table></form>";
- if($_POST){
- echo "<br /> Check has been Added! <br />";
- $check_number = $_POST['check_number'];
- $check_prefix = $_POST['check_prefix'];
- $print_date = $_POST['print_date'];
- $check_tax = $_POST['check_tax'];
- $check_total = $_POST['check_total'];
- mysql_query("INSERT INTO ".$this->iMasterTable." (id, check_number, check_prefix, print_date, check_tax, check_total, payment_received, payment_amount) VALUES(NULL, '$check_number', '$check_prefix', '$print_date', '$check_tax', '$check_total', 'False', '0' )")or die(mysql_error());
- }
- }
- function DisplayStatistics() {
- $checks_count = mysql_num_rows(mysql_query("SELECT * FROM ".$this->iMasterTable.""));
- $info = mysql_query("SELECT * FROM ".$this->iMasterTable."");
- $total_worth = 0;
- $total_tax = 0;
- $total_rec = 0;
- while($row = mysql_fetch_array($info)){
- $total_worth = $total_worth + $row['check_total'];
- $total_tax = $total_tax + $row['check_tax'];
- $total_rec = $total_rec + $row['payment_received'];
- }
- print("<h1>System Statistics</h1>");
- print("Checks in system: <b>".$checks_count."</b><br />");
- print("Checks total worth: <b>".$total_worth."</b><br />");
- print("Checks total taxes: <b>".$total_tax."</b><br />");
- print("Checks 50% of taxes: <b>".($total_tax / 2)."</b><br />");
- print("Total payments received: <b>".$total_rec." / ".($total_tax / 2)."</b><br />");
- }
- function DisplayNavBar(){
- echo "<center>
- <center>
- <a href='?add=1' style='text-decoration:none;'>Add Checks</a>
- <a href='?list=1' style='text-decoration:none;'>Check List</a>
- <a href='?stats=1' style='text-decoration:none;'>Statistics</a>
- <a href='?install=1' style='text-decoration:none;'>Install</a>
- </center>";
- if(@$_GET['add']){ $this->DisplayInsertForm();}
- if(@$_GET['list']){ $this->PrintDataTable(false, false);}
- if(@$_GET['stats']){ $this->DisplayStatistics();}
- if(@$_GET['install']){ $this->SystemInstall();}
- echo "<br /> <center><h5>System By OrX</h5></center> </center>";
- }
- function SystemInstall(){
- mysql_query("CREATE TABLE IF NOT EXISTS `".$this->iMasterTable."` (`id` int(50) NOT NULL AUTO_INCREMENT,`check_number` int(50) NOT NULL,`check_prefix` text NOT NULL,`print_date` date NOT NULL,`check_tax` int(50) NOT NULL,`check_total` int(50) NOT NULL, `payment_received` text NOT NULL,`payment_amount` int(50) NOT NULL,PRIMARY KEY (`id`)) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=20")or die("First connect to the database using class->SQL(host, user, pass, database) <br />");
- echo "System sucessfully installed, It is now ready to use!";
- }
- }
- $tsekk = new CheckSystem("data");
- $tsekk->Debug(false);
- $tsekk->SQL("localhost", "root", "", "test");
- $tsekk->DisplayNavBar();
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement