Location: PHPKode > projects > Itshomi PHP Framework > itshomi/components/configurator/Configurator.php
<?php
/*
 * Configurator.php
 * Copyright ALM Software Technologies
 * Created by fm 
 * Date created Jul 21, 2008
 * Description:
 * 
 */
class Configurator extends ImiComponent{
    function play(){
		if(($task=$this->getTask())){ 
			switch($task){
				case 'vconfig': 
					$this->adminOnly();
					$this->addView($this->compPath().'ShowConfig.php');
				break;
			}
		}
	}
	
	function &onStartup(){
		global $config;
		$tbl = $this->navigator->getInstance("dbtable");
		$tbl->useTable('application');
		$rows = $tbl->getRows("loadonstartup=1");
		$configuration = array();
		foreach($rows as $row){
			if($row['varname']=='component'){
				if(!isset($config['components']['web']) || !is_array($config['components']['web']))
					$config['components']['web'] = array();
				$config['components']['web'][count($config['components']['web'])]=$row['varval'];
				error_log('loaded comp.:'.$row['varval'].' and c:'.count($config['components']['web']));	
			}else
				$configuration[$row['varname']]=$row['varval'];
		}
		$tbl->useTable('workflow');
		$rows = $tbl->getRows("evtype=1 or task='".$this->getTask()."' or task='ON_LOAD' or task='BF_RENDER' or task='PAGE_TOP_MENU'");
		foreach($rows as $row){
			$n = count($configuration['events'][$row['task']]['listeners']);
			$configuration['events'][$row['task']]['listeners'][$n]=$row['component'];
		}
		$configuration['events']['applogs']['listeners'][0]='logview';
		$configuration['events']['viewlog']['listeners'][0]='logview';
		$configuration['events']['test']['listeners'][0]='tests';
		$configuration['events']['installmenu']['listeners'][0]='mainmenu';
		$configuration['events']['nxmlcomp']['listeners'][0]='codegen';
		$configuration['events']['compinstall']['listeners'][0]='compinstaller';
		return $configuration;
	}
	
	/**
	* persists a configuration parameter
	*/
	function setCfgParam($varname,$value){
		$tbl = $this->navigator->getInstance("dbtable");
		$tbl->useTable('application');
		$rows = $tbl->execQuery("select count(*) from application where varname='".$varname."'");
		if($rows[0][0]>0){
			$sql = "update application set varval='".$value."' where varname='".$varname."'";
		}else{
			$sql = "insert into application(varname,varval) values('".$varname."','".$value."')";
		}
		return $tbl->execStmt($sql);
	}
	
	function saveConfig($cfg){
		$tbl = $this->navigator->getInstance("dbtable");
		$tbl->useTable('application');
		$tbl->delRows();
		$sql = "insert into application(varname,varval) values";
		$sep = "";
		foreach($cfg as $key => $val){
			$sql.=$sep."('".$key."','".$val."')";
			$sep=",";
		}
		$tbl->execQuery($sql);
	}
}				
Return current item: Itshomi PHP Framework