Location: PHPKode > projects > Modularized Information Environment > mie/includes/controls.inc
<?php
/**
 * @file includes/controls.inc
 * @brief Controls Library
 * @author Kenneth Smith <hide@address.com>
 *
 * Modularized Information Environment (MIE)
 * Copyright (C) 2005-2006 by Kenneth Smith. All rights reserved.
 *
 * This program is free software; you can redistribute it and/or modify it under
 * the terms of the GNU General Public License as published by the Free Software
 * Foundation; either version 2 of the License, or (at your option) any later
 * version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
 * details.
 *
 * You should have received a copy of the GNU General Public License along with
 * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
 * Place - Suite 330, Boston, MA 02111-1307, USA.
 */

defined('VALIE_MIE') || die(_('Direct access not allowed'));
defined('CONTROLS_INC') && exit;
define('CONTROLS_INC', true);

class LINK extends TAG {
	function __construct($_path, $_query) {
		global $db;
		parent::__construct('a');
		$sql = $db->rewrite('SELECT k{id} k{id}, k{name} k{name}, k{title} k{title}, k{path} k{path} FROM t{pages} WHERE k{path} = %c', $_path);
		$result = $db->result($sql);
		if($result) {
			$this->href = mie_page($result['path'], $_query);
			$this->title = $result['title'];
			$this->append($result['name']);
		}
		else {
			$this->append('[' . _('invalid link') . ']');
		}
	}
}

class GO extends TAG {
	function __construct($_path, $_query = array()) {
		global $db;
		parent::__construct('a');
		$sql = $db->rewrite('SELECT * FROM t{pages} WHERE k{path} = %c', $_path);
		$result = $db->result($sql);
		if($result) {
			$this->href = mie_page($result['path'], $_query);
			$this->title = $result['title'];
			$this->append(new TAG('img', array('src'=>mie_base(mie_theme('media/go.png')), 'alt'=>$result['name'])));
		}
		else {
			$this->append('[' . _('invalid link') . ']');
		}
	}
}

class PAGER extends TAG {
	public $index;
	public $record;
	public $records;
	public $rows;
	public $sheets;
	public $fore;
	public $next;

	function __construct($_records) {
		parent::__construct('div', array('class'=>'pager'));
		$this->append(_('Sheet') . ': ');
		$this->fore = new TAG('a');
		$this->fore->append(new TAG('img', array('src'=>mie_base(mie_theme('media/fore.png')), 'alt'=>_('fore'), 'title'=>_('fore'))));
		$this->next = new TAG('a');
		$this->next->append(new TAG('img', array('src'=>mie_base(mie_theme('media/next.png')), 'alt'=>_('next'), 'title'=>_('next'))));

		$this->records = intval($_records);
		if($this->records < 0) {
			$this->records = 0;
		}

		$this->rows = intval(mie_conf('pager_rows', 12));
		if($this->rows < 1) {
			$this->rows = 1;
		}

		$this->sheets = ceil($this->records / $this->rows);

		$this->index = isset($_GET['sheet']) ? intval($_GET['sheet']) : 1;
		if($this->index > $this->sheets) {
			$this->index = $this->sheets;
		}
		if($this->index < 1) {
			$this->index = 1;
		}

		$this->record = ($this->index - 1) * $this->rows;

		if($this->index != 1) {
			$this->append($this->fore);
		}
		$this->append($this->index);
		if($this->index != $this->sheets) {
			$this->append($this->next);
		}
		$this->append(' ' . _('of') . ' ' . $this->sheets);
	}
}

class SELECT extends TAG {
	function __construct($_options, $_selected = null, $_name) {
		parent::__construct('select', array('name'=>$_name));
		foreach($_options as $k => $v) {
			if($k == $_selected) {
				$this->append(new TAG('option', array('value'=>$k, 'selected'=>'selected'), $v));
			}
			else {
				$this->append(new TAG('option', array('value'=>$k), $v));
			}
		}
	}
}

class RESULT_EDIT extends TAG {
	function __construct($_result, $_headings, $_key, $_selected, $_input) {
		parent::__construct('table', array('class'=>'result'));

		// Add headings
		$this->append($tr = new TAG('tr'));
		foreach($_headings as $r) {
			$tr->append(new TAG('th', null, $r['title']));
		}

		// Add content
		foreach($_result as $r) {
			$this->append($tr = new TAG('tr'));
			if($r[$_key] == $_selected) {
				// Selected for edit
				foreach($_headings as $h) {
					print_r($h);
					if(isset($_input[$h])) {
						switch($_input[$h]['type']) {
							default: case 'text':
								$this->append(new TAG('input', array('value'=>$r[$h['id']])));
							break; case 'select':
								$this->append(new SELECT($_input[$h]['options']));
						}
					}
					else {
						$this->append(new TAG('td', null, $r[$h['id']]));
					}
				}
			}
			else {
				// Just display
				foreach($_headings as $h) {
					$this->append(new TAG('td', null, $r[$h['id']]));
				}
			}
		}
	}
}

?>
Return current item: Modularized Information Environment