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/spire.komma-mediadesign.nl/wwwroot/kms/app/models/m_sorter.php
<?php

/*

	Handles all sortable list

*/

class sorter
{
	private $_pdo, $_template, $_pages, $_pageinfo;
	
	private $_tableName;
	private $_columnName;

	public function __construct($pageId, $tn = '', $cn = '')
	{
		global $pdo, $template, $pages;
		
		$this->_pdo = $pdo;
		$this->_template = $template;
		$this->_pages = $pages;
		$this->_pageinfo = $this->_pages->get($pageId);
	
		$this->_tableName = $tn;
		$this->_columnName = $cn;
	}

	/**
	* Updates the order of the givin array
	*
	* @access public
	* @param array
	* @return null
	*/
	function update($ids)
	{
		// build query
		$query = 'UPDATE '.$this->_tableName.' SET '.$this->_columnName.' = ? WHERE id = ? LIMIT 1';
		
		// prepare statement
		if($st = $this->_pdo->prepare($query))
		{
			$st->bindParam(1, $order);
			$st->bindParam(2, $id);
			
			foreach($ids as $index => $itemId)
			{
				$id = intval($itemId);
				$order = $index+1;
				
				$st->execute();
			}		
			
			$this->_template->setAlert($this->_template->lang['sorter_success']);
		}
	}
	
	/**
	* Updates the order of the givin array of images
	*
	* @access public
	* @param array, array
	* @return null
	*/
	function updateImages($keys,$imageSession)
	{
		$temp = array();
		foreach($keys as $index => $oldkey)
		{
			$temp[$index] = $imageSession->get('key',$oldkey);
			
		}
		$imageSession->set($temp);
		$this->_template->setAlert($this->_template->lang['sorter_success']);
	}
	
	
	/*
	
		CREATE PAGE OUTPUT
	
	*/
	
	
	/**
	* Returns a string containing a sortable itemlist  
	*
	* @access public
	* @param array
	* @return string
	*/
	public function createList($data)
	{
		$output = $this->_template->lang['general_no_items_found'];
		$ids = array();
		if($data != NULL)
		{			
			$output = '';
			// catch problems when only one 1 item is in data
			$keys = array_keys($data);
			if( is_string($keys[0]) )
			{
				$info = $data;
				$data = array($info);
			}
			foreach($data as $info)
			{
				$ids[] = $info['id'];
			
				$output .= '<li title="'.$info['id'].'">';
					$output .= $info['title'];
				$output .= '</li>';
			}
		}
		
		$this->_template->setData('list_ids',$ids,TRUE);
		$this->_template->setData('sortable_list',$output,TRUE);
	}
	
	/**
	* Returns a string containing a sortable list of thumbnails  
	*
	* @access public
	* @param array
	* @return string
	*/
	public function createThumbList($data)
	{
		$output = $this->_template->lang['general_no_items_found'];
		$ids = array();
		if($data != NULL)
		{			
			$output = '';
			foreach($data as $key => $info)
			{
				$ids[] = $key;
			
				$output .= '<li class="thumb" title="'.$key.'">';
					$output .= '<img src="'.IMAGE_ROOT.'uploads/'.$info['kmsthumb'].'" alt="image '.$info['shortcode'].'" />';
				$output .= '</li>';
			}
		}
		
		$this->_template->setData('list_ids',$ids,TRUE);
		$this->_template->setData('sortable_list',$output,TRUE);
	}
}