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/SBogers10/komma-mediadesign.nl/wwwroot/beheer/app/models/m_pages.php
<?php 


/*

	Pages 
	
	Handles all tasks regarding the pages
	
*/

class Pages
{
	private $_pdo, $_template;
	
	public function __construct()
	{
		global $pdo, $template;
		$this->_pdo = $pdo;
		$this->_template = $template;
	}

	
	/* 
	
	 	GETTERS / SETTERS
	
	*/

	
	/**
	* Returns an array containg list items
	*
	* @access public
	* @param id / string /
	* @return array
	*/
	public function get($id = NULL)
	{
		$data = array();
		if($id != NULL && is_numeric($id))
		{
			// get info from one page by id		
			if($st = $this->_pdo->prepare('SELECT label, linkname FROM kms_pages WHERE id = ?'))
			{
				$st->bindParam(1,$id);
				$st->execute();
				
				$result = $st->fetch(PDO::FETCH_OBJ);
				
				if($st->rowCount() > 0)
				{
					if(empty($linkname)) $linkname = $this->_template->encodeUrl($result->label);
					$data['id'] = $id;
					$data['label'] = $result->label;
					$data['linkname'] = $result->linkname;
				}
			}
		}	
		if($id != NULL && is_string($id))
		{
			// get info from one page by linkname
			$linkname = $this->_template->encodeUrl($id);
			
			if($st = $this->_pdo->prepare('SELECT id, label, linkname FROM kms_pages WHERE id = ?'))
			{
				$st->bindParam(1,$linkname);
				$st->execute();
				
				$result = $st->fetch(PDO::FETCH_OBJ);
				
				if($st->rowCount() > 0)
				{
					if(empty($linkname)) $linkname = $this->_template->encodeUrl($result->label);
					$data['id'] = $id;
					$data['label'] = $result->label;
					$data['linkname'] = $result->linkname;
				}
			}
		}
		else
		{
			// get info from all pages
			
			if($st = $this->_pdo->query('SELECT id, label FROM kms_pages WHERE extention = 0 ORDER BY pageOrder DESC'))
			{
				while($result = $st->fetch(PDO::FETCH_OBJ))
				{	
					$linkname = $this->_template->encodeUrl($result->label);
					$data[]	= array('id' => $result->id, 'label' => $result->label, 'linkname' => $linkname);
				}
			}	
		}
		
		return $data;
	}
	
	

	/* 
	
	 	PAGE OUTPUT
	
	*/
	
	
	/**
	* Returns a string containing list items 
	*
	* @access public
	* @param 
	* @return string
	*/
	public function createList()
	{
		$data = $this->get();
		if( ! empty($data))
		{
			$output = '';
			foreach($data as $info)
			{
				$linkname = $this->_template->encodeUrl($info['label']);
				$output .= '<li'; 
				if(isset($_GET['page']) && $_GET['page'] == $linkname) $output .= ' class="active"';
				$output .= '><a href="'.SITE_ROOT.$linkname.'/" title="Link naar '.$info['label'].'" >'.$info['label'].'</a></li>';
			}
			$this->_template->setData('pages_list',$output,TRUE);
		}
	}	
}