00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059 abstract class aliroFriendlyBase {
00060
00061 protected function getTableInfo ($tablename) {
00062 $database = call_user_func(array($this->DBname, 'getInstance'));
00063 return $database->getAllFieldInfo($tablename);
00064 }
00065
00066 protected function __call ($method, $args) {
00067 return call_user_func_array(array(aliroRequest::getInstance(), $method), $args);
00068 }
00069
00070 protected function __get ($property) {
00071 if ('option' == $property) return aliroRequest::getInstance()->getOption();
00072 $info = criticalInfo::getInstance();
00073 if (isset($info->$property)) return $info->$property;
00074 trigger_error(sprintf(T_('Invalid criticalInfo property %s requested through aliroFriendlyBase'), $property));
00075 }
00076
00077 protected final function getCfg ($property) {
00078 return aliroCore::getInstance()->getCfg($property);
00079 }
00080
00081 protected final function getParam ($array, $key, $default=null, $mask=0) {
00082 return aliroRequest::getInstance()->getParam ($array, $key, $default, $mask);
00083 }
00084
00085 protected final function getStickyParam ($array, $key, $default=null, $mask=0) {
00086 return aliroRequest::getInstance()->getStickyParam ($array, $key, $default, $mask);
00087 }
00088
00089 protected final function redirect ($url, $message='', $severity=_ALIRO_ERROR_INFORM) {
00090 aliroRequest::getInstance()->redirect($url, $message, $severity);
00091 }
00092
00093 protected final function getUser () {
00094 $user = aliroUser::getInstance();
00095 return $user;
00096 }
00097
00098 protected function formatDate ($time=null, $format=null) {
00099 return aliroLanguage::getInstance()->formatDate($time, $format);
00100 }
00101
00102 }
00103
00108 abstract class aliroComponentManager extends aliroFriendlyBase {
00109 protected $name = '';
00110 protected $formalname = '';
00111 protected $barename = '';
00112 protected $system = '';
00113 protected $system_version = '';
00114
00115 protected function __construct ($component, $system, $version) {
00116 $this->name = $component->name;
00117 $this->formalname = $component->option;
00118 $parts = explode('_', $this->formalname);
00119 $this->barename = isset($parts[1]) ? $parts[1] : $this->formalname;
00120 $this->system = $system;
00121 $this->system_version = $version;
00122 if(file_exists($this->absolute_path."/components/$this->formalname/language/".$this->getCfg('lang').'.php')) {
00123 require_once($this->absolute_path."/components/$this->formalname/language/".$this->getCfg('lang').'.php');
00124 }
00125 else if (file_exists($this->absolute_path."/components/$this->formalname/language/english.php")) {
00126 require_once($this->absolute_path."/components/$this->formalname/language/english.php");
00127 }
00128 }
00129
00130 protected function __clone () {
00131
00132 }
00133
00134 protected function noMagicQuotes () {
00135
00136 if (get_magic_quotes_gpc()) {
00137
00138 $_REQUEST = $this->remove_magic_quotes($_REQUEST);
00139 $_GET = $this->remove_magic_quotes($_GET);
00140 $_POST = $this->remove_magic_quotes($_POST);
00141 $_FILES = $this->remove_magic_quotes($_FILES, 'tmp_name');
00142 }
00143 }
00144
00145 private function &remove_magic_quotes ($array, $exclude='') {
00146 foreach ($array as $k => $v) {
00147 if (is_array($v)) $array[$k] = $this->remove_magic_quotes($v, $exclude);
00148 elseif ($k != $exclude) $array[$k] = stripslashes(stripslashes($v));
00149 }
00150 return $array;
00151 }
00152
00153 }
00154
00159 abstract class aliroComponentUserManager extends aliroComponentManager {
00160 private $func;
00161 private $method;
00162 private $classname;
00163 private $controller;
00164 public $menu = null;
00165 public $limit = 10;
00166 public $limitstart = 0;
00167
00168 public function __construct ($component, $control_name, $alternatives, $default, $title, $system, $version, $menu) {
00169 parent::__construct($component, $system, $version);
00170 $this->menu = $menu;
00171 $this->SetPageTitle($title);
00172 $this->func = $this->getParam ($_REQUEST, $control_name, $default);
00173 if (isset($alternatives[$this->func])) $this->method = $alternatives[$this->func];
00174 else $this->method = $this->func;
00175 $this->classname = $this->barename.'_'.$this->method.'_Controller';
00176
00177 if (class_exists($this->classname)) $this->controller = call_user_func(array($this->classname, 'getInstance'), $this);
00178 else trigger_error(sprintf(T_('Aliro error in %s: class not found %s'), $this->formalname, $this->classname));
00179 }
00180
00181 public function activate() {
00182 $this->noMagicQuotes();
00183 $cmethod = $this->method;
00184 if (method_exists($this->controller,$cmethod)) $this->controller->$cmethod($this->func);
00185 else trigger_error (sprintf(T_('Component %s error: attempt to use non-existent method %s in %s'), $this->formalname, $this->method, $this->classname));
00186 }
00187
00188 }
00189
00190 abstract class aliroComponentControllers extends aliroFriendlyBase {
00191 protected $authoriser = null;
00192 protected $user;
00193 protected $menu;
00194 protected $params;
00195 protected $manager;
00196 protected $idparm;
00197 public $pageNav;
00198
00199 protected function __construct ($manager) {
00200 $this->manager = $manager;
00201 $this->authoriser = aliroAuthoriser::getInstance();
00202 $this->menu = isset($manager->menu) ? $manager->menu : null;
00203 if ($this->menu) $this->params = new aliroParameters($this->menu->params, $this->menu->name);
00204 else $this->params = new aliroParameters();
00205 $this->user = aliroUser::getInstance();
00206 $this->idparm = $this->getParam($_REQUEST, 'id', 0);
00207 }
00208
00209 protected function __clone () {
00210
00211 }
00212
00213 public function makePageNav ($total) {
00214 $limit = $this->getUserStateFromRequest($this->option.'_page_limit', 'limit', intval($this->getCfg('list_limit')));
00215 $limitstart = $this->getUserStateFromRequest($this->option.'_page_limitstart', 'limitstart', 0 );
00216 $this->pageNav = new aliroPageNav($total, $limitstart, $limit );
00217 }
00218
00219 }