Advertisement
Guest User

Untitled

a guest
Aug 17th, 2017
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.32 KB | None | 0 0
  1. // Code written by Lauri Orgla a.k.a OrX
  2. // If you have any questions u can either email, or msn me: TheOrX@hotmail.com
  3. <?php
  4. class CheckSystem {
  5.     private $iDBhost, $iDBusername, $iDBpassword, $iDBname;
  6.     public $iDebug;
  7.     public $iMasterTable;
  8.    
  9.    
  10.    
  11.     function Debug($boolean) {
  12.         $this->iDebug = $boolean;
  13.        
  14.     }
  15.    
  16.     function __construct($MasterTable) {
  17.         $this->Debug(false);
  18.         $this->iMasterTable = $MasterTable;
  19.         @ob_end_clean();
  20.         if($this->iMasterTable == ""){ die("Set Up the Master Table. Example: object = new CheckSystem('table name here') <br />"); }
  21.     }
  22.    
  23.     function SQL($DBhost, $DBusername, $DBpassword, $DBname){/* start sql connecting function */
  24.         $this->iDBhost = $DBhost;
  25.         $this->iDBusername = $DBusername;
  26.         $this->iDBpassword = $DBpassword;
  27.         $this->iDBname = $DBname;
  28.         mysql_connect($this->iDBhost,$this->iDBusername,$this->iDBpassword)or die("Could not connect to database! <br />");
  29.         mysql_select_db($this->iDBname)or die("Could not select the database! <br />");
  30.                 if($this->iDebug == true){ echo "If no errors, then DB is selected, connected <br />"; }
  31.     }
  32.    
  33.     function PrintDataTable($received, $clean){ // print either checks that are payed for or not
  34.             if($clean == false){}else{ob_end_clean();}
  35.             if($received == true){$str = "WHERE payment_received = 'true'";}else{$str = "";}
  36.         $numrows = mysql_num_rows(mysql_query("SELECT * FROM ".$this->iMasterTable.""));
  37.         $x = 0;
  38.         echo "<center><h1>List of checks</h1></center>";
  39.             while($x < $numrows){
  40.                 $inf = mysql_fetch_array(mysql_query("SELECT * FROM ".$this->iMasterTable." ".$str." ORDER BY id LIMIT $x, 1000000"));
  41.                     echo "<center><div align='left' style='background-color:#f5f5f5; border:1px; border-style:solid; width:700px; margin-bottom:5px;'>";
  42.                     echo $inf['check_number']." | ".$inf['check_prefix']." | ".$inf['print_date']." | ".$inf['check_tax']."€ | ".$inf['check_total']."€ | ".$inf['payment_received']." | ".$inf['payment_amount']."€";
  43.                     echo "</div></center>";
  44.                 $x++;
  45.             }
  46.    
  47.     }
  48.    
  49.     function DisplayInsertForm() {
  50.        
  51.         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>
  52.             <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>
  53.             <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>";
  54.        
  55.         if($_POST){
  56.         echo "<br /> Check has been Added! <br />";
  57.         $check_number = $_POST['check_number'];
  58.         $check_prefix = $_POST['check_prefix'];
  59.         $print_date = $_POST['print_date'];
  60.         $check_tax = $_POST['check_tax'];
  61.         $check_total = $_POST['check_total'];
  62.         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());
  63.        
  64.         }
  65.     }
  66.    
  67.     function DisplayStatistics() {
  68.             $checks_count = mysql_num_rows(mysql_query("SELECT * FROM ".$this->iMasterTable.""));
  69.             $info = mysql_query("SELECT * FROM ".$this->iMasterTable."");
  70.             $total_worth = 0;
  71.             $total_tax = 0;
  72.             $total_rec = 0;
  73.                 while($row = mysql_fetch_array($info)){
  74.                     $total_worth = $total_worth + $row['check_total'];
  75.                     $total_tax = $total_tax + $row['check_tax'];
  76.                     $total_rec = $total_rec + $row['payment_received'];
  77.                 }
  78.             print("<h1>System Statistics</h1>");
  79.             print("Checks in system: <b>".$checks_count."</b><br />");
  80.             print("Checks total worth: <b>".$total_worth."</b><br />");
  81.             print("Checks total taxes: <b>".$total_tax."</b><br />");
  82.             print("Checks 50% of taxes: <b>".($total_tax / 2)."</b><br />");
  83.             print("Total payments received: <b>".$total_rec." / ".($total_tax / 2)."</b><br />");
  84.     }
  85.    
  86.     function DisplayNavBar(){
  87.    
  88.     echo "<center>
  89.             <center>
  90.             <a href='?add=1' style='text-decoration:none;'>Add Checks</a>
  91.             <a href='?list=1' style='text-decoration:none;'>Check List</a>
  92.             <a href='?stats=1' style='text-decoration:none;'>Statistics</a>
  93.             <a href='?install=1' style='text-decoration:none;'>Install</a>
  94.             </center>";
  95.                 if(@$_GET['add']){ $this->DisplayInsertForm();}
  96.                 if(@$_GET['list']){ $this->PrintDataTable(false, false);}
  97.                 if(@$_GET['stats']){ $this->DisplayStatistics();}
  98.                 if(@$_GET['install']){ $this->SystemInstall();}
  99.         echo "<br /> <center><h5>System By OrX</h5></center> </center>";
  100.     }
  101.    
  102.     function SystemInstall(){
  103.    
  104.     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 />");
  105.     echo "System sucessfully installed, It is now ready to use!";
  106.     }
  107.    
  108.  
  109. }
  110.  
  111. $tsekk = new CheckSystem("data");
  112. $tsekk->Debug(false);
  113. $tsekk->SQL("localhost", "root", "", "test");
  114. $tsekk->DisplayNavBar();
  115.  
  116. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement