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.groups.php
<?php
/**
 * This file contains the iwp_groups class
 *
 * @version $Id$
 * 
 *
 * @package IWP
 * @subpackage IWP_API
 */

/**
 * IWP Groups Class
 * This class handles all operations pertaining to the user groups within the application
 *
 * @package IWP
 * @subpackage IWP_API
 */

class iwp_groups extends iwp_engine {
	/**
	 * primaryKey
	 * This is the name of the field that is the primary key for this table. It is a private and final variable
	 *
	 * @var primaryKey
	 **/
	protected $primaryKey = 'groupid';

	/**
	 * baseTableName
	 * This is the name of the table without its prefix. This is a final private class variable and cannot be changed.
	 *
	 * @var baseTableName
	 **/
	protected $baseTableName = 'groups';

	/**
	 * data
	 * The data array of the current row held in the class memory. It should be the same structure as _columns.
	 *
	 * @var data
	 *
	 * @see Save
	 * @see Load
	 * @see LoadMulti
	 **/
	protected $data = array();

	/**
	 * This static variable contains permissions that are available to be chosen for setting User Groups permissions.
	 *
	 * @var Array
	 */
	public static $PermissionOptions;

	/**
	 * 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 iwp_groups 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 iwp_groups Returns the instantiated object
	 **/
	public static function getInstance(){
		if(!isset(self::$Instance)){
			self::$Instance = new self();
		}
		return self::$Instance;
	}

	/**
	* Constructor method for this class
	*
	* @return iwp_groups
	*/
	public function __construct(){
		parent::__construct();
	}

	/**
	* A function to return the static set of permission objects for this class. For use with call_user_func.
	*
	* @return Array Returns self::$PermissionOptions
	*/
	public static function GetPermissionOptions () {
		return self::$PermissionOptions;
	}

	/**
	* Load
	* Loads the data from the database table based upon the current primary key name and value
	*
	* @param $id integer This is optional if the class has an ID set already, or if you want to override it use this.
	*
	* @return boolean
	*/
	public function Load ($id=null) {
		if($id === null){
			if($this->ValidId()){
				$id = $this->GetId();
			}else{
				return false;
			}
		}
		parent::Load($id);
		return true;
	}

	/**
	 * Will retrieve the provided group's permissions and return as list of associative arrays
	 *
	 * @param Integer $groupId
	 * @return Array
	 */
	public function GetGroupPermissions ($groupId, $languageLookup = false)
	{
		$return = array();

		if ((int)$groupId < 1) {
			throw new iwp_exception_groups(GetLang('InvalidGroupID'));
		}

		$res = $this->db->Query("SELECT SQL_CALC_FOUND_ROWS * FROM " . IWP_TABLE_GROUPPERMS . " WHERE `groupid`='" . $this->db->Quote($groupId) . "' ORDER BY `flag` DESC, `permid` ASC");
		$total = (int)$this->db->FetchOne("SELECT found_rows()");

		if ($res && strlen($this->db->GetErrorMsg()) < 1) {
			while ($row = $this->db->Fetch($res)) {
				$row['itemcsv'] = iwp_validation::FilterCsvToArray($row['itemcsv'], false);
				if ($languageLookup && count($row['itemcsv'])) {
					$scopeClass = iwp_permissionoption::GetScopeClassName($row['scopetype'], $row['scopename']);
					if (class_exists($scopeClass) && is_callable(array($scopeClass, 'getTitleList'))) {
						$row['itemcsv'] = call_user_func_array(array($scopeClass, 'getTitleList'), array(&$row['itemcsv']));
					} else if (strstr($scopeClass, 'iwp_admin_') === false) {
						//	try loading the admin class and looking at that instead
						$scopeClass = str_replace('iwp_', 'iwp_admin_', $scopeClass);
						if (class_exists($scopeClass) && is_callable(array($scopeClass, 'getTitleList'))) {
							$row['itemcsv'] = call_user_func_array(array($scopeClass, 'getTitleList'), array(&$row['itemcsv']));
						}
					}
				}

				$row['catcsv'] = iwp_validation::FilterCsvToArray($row['catcsv']);
				if ($languageLookup && count($row['catcsv']))
					$row['catcsv'] = iwp_categories::GetTitleList($row['catcsv']);

				$row['granularity'] = iwp_validation::FilterCsvToArray($row['granularity'], false);
				array_push($return, $row);
			}
			$this->db->FreeResult($res);
		} else {
			throw new iwp_exception_groups(GetLang('InvalidGroupID'));
		}

		if ($languageLookup) {
			foreach ($return as &$item) {
				$item['scopetypelang'] = iwp_permissionoption::GetScopeTypeLang($item['scopetype']);
				$item['scopenamelang'] = iwp_permissionoption::GetScopeNameLang($item['scopetype'], $item['scopename']);
				$item['scopeitemlang'] = iwp_permissionoption::GetScopeItemLang($item['scopetype'], $item['scopename'], $item['scopeitem']);
			}
		}

		return $return;
	}

	/**
	 * Returns a list of group titles for a supplied list of group IDs
	 *
	 * @param Array $ids
	 * @return array
	 */
	public static function getTitleList ($ids) {
		$list = array();
		if (count($ids)) {
			$me = self::getInstance();
			$sql = sprintf("SELECT groupid as `value`, `name` as `text` FROM %s WHERE groupid IN (%s) ORDER BY `name`", IWP_TABLE_GROUPS, implode(',', $ids));
			$result = $me->db->Query($sql);
			while ($row = $me->db->Fetch($result)) {
				$row['value'] = (int)$row['value'];
				array_push($list, $row);
			}
		}
		return $list;
	}

	/**
	 * Returns a granularity list for this class.
	 *
	 * @param Integer $total Total will be populated with number of rows found in query (by reference)
	 * @param String $filter Filter string, optional
	 * @param Integer $page Page number of records to return, optional
	 * @return Array List of value/text pairs
	 */
	public static function getGranularityList (&$total, &$page, $filter = '')
	{
		$limitStart = ($page * IWP_PERMISSIONGRANULARITEMS_PER_PAGE) - IWP_PERMISSIONGRANULARITEMS_PER_PAGE;
		$where = '';
		if ($filter) {
			$filter = '%'. self::getInstance()->db->Quote($filter) .'%';
			$where = sprintf("WHERE (`name` LIKE '%s')", $filter);
		}
		$result = self::getInstance()->db->Query(sprintf("SELECT SQL_CALC_FOUND_ROWS groupid AS `value`, `name` AS `text` FROM %s %s ORDER BY `name` LIMIT %d, %d", IWP_TABLE_GROUPS, $where, $limitStart, IWP_PERMISSIONGRANULARITEMS_PER_PAGE));
		$total = self::getInstance()->db->FetchOne('SELECT found_rows()');
		$list = array();
		if ($result) {
			while ($row = self::getInstance()->db->Fetch($result)) {
				$row['value'] = (int)$row['value'];
				array_push($list, $row);
			}
			self::getInstance()->db->FreeResult($result);
		}
		return $list;
	}
}

iwp_groups::$PermissionOptions = array(
	'full'			=> new iwp_permissionoption(true, false, false),
	'create'		=> new iwp_permissionoption(false, false, false),
	'delete'		=> new iwp_permissionoption(true, false, false),
	'edit'			=> new iwp_permissionoption(true, false, false),
	'permissions'	=> new iwp_permissionoption(true, false, false)
);