HEX
Server: Microsoft-IIS/8.5
System: Windows NT YDAWBH120 6.3 build 9600 (Windows Server 2012 R2 Standard Edition) AMD64
User: tentjecom_web (0)
PHP: 7.4.14
Disabled: NONE
Upload Files
File: D:/HostingSpaces/PvdBoogaard/indoorski.nl/backup/oude-site/cms/api/class.modulevars.php
<?php
/**
 * This file contains the iwp_modulevars class
 *
 * @version $Id$
 * 
 *
 * @package IWP
 * @subpackage IWP_API
 */

/**
 * IWP Module Variables Class
 * This is the class that manages the variables for a module. Its instantiated as a member variable for the modules class
 *
 * @package IWP
 * @subpackage IWP_API
 */
class iwp_modulevars  extends iwp_engine {
	/**
	 * The primary key of the module variables table
	 *
	 * @var string
	 */
	protected $primaryKey = 'varid';

	/**
	 * The table name without the preifx of the module variabled table
	 *
	 * @var string
	 */
	protected $baseTableName = 'modulevars';

	/**
	 * The array with the current data for the current module
	 *
	 * @var array
	 */
	protected $data = array();

	/**
	 * The default values for the $data array
	 *
	 * @var array
	 */
	protected $_columns = array(
							'modulecodename' => '',
							'name' => '',
							'value' => ''
						);

	/**
	 * Instance
	 * This static variable holds the current instance of this object being loaded.
	 * So using the getInstance function anywhere will return the very same instance.
	 *
	 * @var object Instance
	 */
	public static $Instance;

	/**
	 * getInstance
	 * This is a static function that sets up the class instance and stores it to the static variable. It will then return that instantiation in the future.
	 *
	 * @return object Returns the instantiated object
	 **/
	public static function getInstance(){
		if(!isset(self::$Instance)){
			self::$Instance = new self();
		}
		return self::$Instance;
	}

	/**
	 * Constructor
	 */

	function __construct(){
		parent::__construct();
	}

	/**
	 * For autoloading vars when Get is called
	 *
	 * @var bool.
	 */
	private $Loaded = false;

	/**
	 * Runs the LoadMulti() function
	 *
	 * @param integer $codename The codename to load the database by
	 */
	public function Load($codename){
		$this->LoadMulti('modulecodename', $codename);
		$this->Loaded = true;
	}

	/**
	 * Set a module variable and its value
	 *
	 * @param string $name
	 * @param string $value
	 * @param string $codename
	 *
	 * @return void
	 */
	public function Set($name, $value, $codename){
		//if($this->ValidColumn($name)){
		$InsertData = array();
		$InsertData['modulecodename'] = $codename;
		$InsertData['name']     = $name;
		$InsertData['value']    = $value;

		if($this->Exists($name, $codename)) {
			$id = $this->db->UpdateQuery($this->GetTableName(), $InsertData, '`name`="'. $this->db->Quote($name) .'" and `modulecodename`="'. $this->db->Quote($codename) .'"');
		}else{
			$id = $this->db->InsertQuery($this->GetTableName(), $InsertData);
		}
		$this->data[$id] = $InsertData;
		//}
	}

	/**
	 * This function Gets the module variables by a specific name and the module ID
	 *
	 * @param string $name The name of the variable to get
	 * @param string $codename The codename of the module to get
	 *
	 * @return mixed It will be a string if the value exists, false if it doesn't
	 */

	public function Get($name, $codename) {
		if (!$this->Loaded) {
			$this->Load($codename);
		}
		foreach($this->data as $_key=>$val) {
			if ($name == $val['name'] && $codename == $val['modulecodename']){
				return $val['value'];
			}
		}
		return false;
	}

	public function Exists($name, $codename){
		if (!$this->Loaded) {
			$this->Load($codename);
		}
		foreach($this->data as $_key=>$val) {
			if ($name == $val['name'] && $codename == $val['modulecodename']){
				return true;
			}
		}
		return false;
	}

	public function Delete($name, $codename){
		foreach($this->data as $key=>$val){
			if($name == $val['name'] && $codename == $val['modulecodename']){
				$key = $val[$this->primaryKey];
				unset($this->data[$key]);
				break;
			}
		}

		$this->db->Query("delete from" . $this->GetTableName() . ' where `'.$this->primaryKey.'`="'.$key.'" limit 1');
	}

}