کسی نیست کمک کنه

کد:
<?php

/**
 * 
 * */

require_once (IBSINC . "generator/creator.php");

class ReportCreator extends Creator {
	function ReportCreator() {
		// initilized variables
		$this->init();
	}

	function create() {
		// Reports
		$this->reports = array ();
		if ($this->canShowReports())
			$this->reports = &$this->getReports();

		if ($this->getRegisteredValue("errorOccured"))
			$this->generator = &$this->controller->getWebGenerator();
		
		else {
			$this->generator = &$this->controller->getGenerator();
			if (isset ($this->results))
				$this->generator->results = &$this->results;

			$this->doFormatting($this->generator);
		}
		$this->generator->creator = &$this;

		// show information
		$this->generator->dispose();
	}

	/**
	 * formating report with Formatter($gen)
	 * 
	 * @param Generator $gen formatter
	 * @param reports mixed object that must be formt
	 * */
	function doFormatting(&$gen)
	{
		foreach ($this->reports as $report)
			/**
			 * filtering $report
			 * to get information that must be shown 
			 * */
			$gen->doArray($this->__getFilteredOutputReport($report));
	}


	/**
	 * this method initializes variables
	 * */
	function init() {
		parent :: init();
		/**
		 * variables of report creator
		 * overiden variables store in __variables
		 * 
		 * @access private $__variables 
		 * */
		$this->__variables = array ();

		// register informations
		$this->register("formula_prefixes", array ());
		$this->register("root_node_name", "report_root");
		$this->register("inRequestVariable", "NotAssignedYet");
		$this->register("errorOccured", FALSE);

		// set smarty
		$this->smarty = new IBSSmarty();

		// collect conditions
		$this->conds = &$this->collectConditions();

		// get selectors (information that said which information 
		// must be shown and which not)
		$this->report_selectors = &$this->getReportSelectors();

		// create controller
		$this->controller = &$this->createController();

		$this->output_generators_name = $this->controller->getOutputGeneratorsName();
	}

	/**
	 * get & create controller
	 * @return Controller
	 * */
	function createController() {
		$controller = &$this->getController();
	
		$controller->setViewOuputSelectedName($this->getViewOuputSelectedName());

		// set selectors for controller
		$controller->setReportSelectors($this->report_selectors);

		// set Smarty of controller
		$controller->setSmarty($this->smarty);

		return $controller;
	}

	/**
	 * this method get result (one row of results) 
	 * and return reported information(needed information for output viewing)
	 * @param mixed $result given information
	 * @return mixed needed information for reporting
	 * */
	function __getFilteredOutputReport($result_row) {
		// filtering information
		$report = array (
			$this->getRegisteredValue("root_node_name") => $this->getReportInformationFromRow($result_row), 
			"other" => $this->getUsefulInformation($result_row));
		return $report;
	}

	/**
	 * get viewing information from $log (filtering $log to get all needed information)
	 * @access public
	 * @return mixed reporeted log (any thing that needed for viewing)
	 * */
	function getReportInformationFromRow($row) {
		$report_log = array ();

		foreach ($this->report_selectors as $formual => $field_name) {
			// cut substr that is finish with '|' from $field_name_index
			if (($pos = strpos($field_name, "|")) !== false)
				$field_name = substr($field_name, 0, $pos);

			// get field value from log
			$report_row = $this->getFieldFromRow($row, $field_name);

			// cut first substr that is finish with ','
			if (($pos = strpos($field_name, ",")) !== false)
				$field_name = substr($field_name, 0, $pos);

			// delete prefix from field_name.
			// it contains any thing like this show__info_ 
			$field_name = deletePrefixFromFormula($this->getRegisteredValue("formula_prefixes"), $field_name);

			// collecting
			$report_log[$field_name] = $report_row;
		}

		return $report_log;
	}

	/**
	 * get value of field ($field_name_index) in object ($row_report)
	 * @param mix $row_report
	 * @param string $field_name_index like foo1,foo2,foo3
	 * */
	function getFieldFromRow($row_report, $field_name_index) {
		$ret = array ();
		// separate variables with ','
		// foo1,foo2,foo3 => foo1 foo2 foo3
		$field_name_indexs = explode(",", $field_name_index);

		// get value of each field
		foreach ($field_name_indexs as $field_name)
			// get value of field
			$ret[] = $this->getFieldValue($row_report, $field_name);

		return implode(" ", $ret);
	
	}

	/**
	 * getting useful information
	 * */
	function getUsefulInformation($report) {
		return array ();
	}

	/**
	 * for any variable of REQUEST if it start with $selector_expression then is added to return array.
	 * example :
	 * 		getReportSelectors("show__") return an array that contains this variables 
	 * 		"show__details_username", "show__derails_userid", ... that this variables come from
	 * 		REQUEST.
	 * 
	 * @param string $begin_expression like this : show__details_ each var that start with this 
	 * 		expression will be selected 
	 * @return array 
	 * */
	function getReportSelectors($begin_expression) {
		$selectors = array ();

		// searching in REQUEST and find selectors each selector start with $selector_start
		foreach ($_REQUEST as $field_name => $field_formula)
			if (ereg("^" . $begin_expression . ".*", $field_formula))
				$selectors[str_replace("_", " ", $field_name)] = $field_formula;

		return $selectors;
	}

	/**
	 * can I show results
	 * @return boolean TRUE means that show result
	 * */
	function canShowReports() {
		return isInRequest($this->getRegisteredValue("inRequestVariable"));
	}

	/**
	 * example :
	 *   register("inRequestVariable", "search")
	 * 
	 * register variable with it's value
	 * @param string $var
	 * @param mix $value value for $var
	 * */
	function register($var, $value) {
		$this->variables[$var] = $value;
	}

	/**
	 * get registered value of $var
	 * 
	 * TODO if it is possible throw an Exception when there is no variable associate for $var
	 * @param string $var
	 * @return mixed if there is no associated variable for $var return "NotAssignedValue"
	 * */

	function getRegisteredValue($var) {
		if (isset ($this->variables[$var]) and !is_null($this->variables[$var]))
			return $this->variables[$var];

		toLog("Undefine property : " . $var . " you must overide this variable in drived class\n");
		return "NotAssignedValue";
	}

	// TODO: Actually define the functions that should be overriden and do something if they aren't overrided
	// TODO: Convert all variables to register style. It's ugly to override on every child

	/*
	 * this methods must be overrided
	 * 
	 * controller use this function to show output
	 * function getViewOuputSelectedName()
	 * 
	 * 
	 * which variable must be exist in REQUEST
	 * for creating results
	 * canShowReport will be used this function 
	 * 
	 * 
	 * collect conditions
	 * function collectConditions()
	 * 
	 * getting reports
	 * @return mixed
	 * function getReports()
	 * 
	 * get controller
	 * @return Controller
	 * function getController()
	 * 
	 * get Report Selectors
	 * @return mixed selectors
	 * function getReportSelectors()
	 * 
	 * get value of field
	 * @param mixed $row_report
	 * @param string $attribute_name name of attribute
	 * function getFieldValue($row_report, $attribute_name)
	 *
	 * 
	 * $formala_prefixes array of prefixes
	 * for deleting prefix of one formula
	 * show__details__formula_name == deleting==> formaula_name
	 * it is used for deletePrefixFromFormula($this->formula_prefixes, $formula_name)
	 *  
	 * 
	 * which variable must be exist in request
	 * for creating result 
	 * string inRequestVariable
	 *
	 * */

}
?>