changed code

Description

I changed the code for the csv-export as stated below
  • example 1

from pages/company.inc.php

function companyList() {
    global $PH;
    global $auth;

    ### create from handle ###
    $PH->defineFromHandle();
	
	$format = get('format');
	
	if($format == 'csv'){
		global $csv_args;
		global $csv_count;
		$csv_count = 0;
		
		$order_str= get("sort_".$PH->cur_page->id."_".$list->id);
		$order_str= str_replace(",",", ", $order_str);
		$companies=Company::getAll(array('order_str'=>$order_str));
		
		$list= new ListBlock_companies();
		$list->format = $format;
		$list->render_list(&$companies);
		
		exportToCSV($csv_args);
	}
	else{
		### set up page and write header ####
		{
			$page= new Page();
			$page->cur_tab='companies';
			$page->title=__("Companies");
			if(!($auth->cur_user->user_rights & RIGHT_VIEWALL)) {
				$page->title_minor=sprintf(__("related projects of %s"), $page->title_minor=$auth->cur_user->name);
			}
			else {
				$page->title_minor=__("admin view");
			}
			$page->type=__("List");
			
			 ### page functions ###
			$page->add_function(new PageFunction(array(
				'target'    =>'companyNew',
				'params'    =>array(),
				'icon'      =>'new',
				'tooltip'   =>__('New Company'),
			)));
	
			/*$page->crumbs[]= new NaviCrumb(array(
				'target_id'     => 'companyList',
			));*/
			$page->options=build_companyList_options();
	
			### render title ###
			echo(new PageHeader);
		}
		echo (new PageContentOpen);
	
		#--- list projects --------------------------------------------------------
		{
	
	
			$list= new ListBlock_companies();
	
			### may user create companies? ###
			if($auth->cur_user->user_rights & RIGHT_COMPANY_CREATE) {
				$list->no_items_html=$PH->getLink('companyNew','',array('person'=>$auth->cur_user->id));
			}
			else {
				$list->no_items_html=__("no companies");
			}
	
	
			$order_str= get("sort_".$PH->cur_page->id."_".$list->id);
	
			$order_str= str_replace(",",", ", $order_str);
			$companies=Company::getAll(array('order_str'=>$order_str));
	
			$list->title= $page->title;
			$list->render_list(&$companies);
			
			## Link to start cvs export
			echo "<div class=description>" . $PH->getLink('companyList', __('Export as CSV'),array('format'=>'csv')) . "</div>";
		}
	
		echo(new PageContentClose);
		echo(new PageHtmlEnd);
	}

}
  • example 2

from render/render_list.inc.php

public function render_list(&$list=NULL)
    {
   		if($this->format == 'csv'){
			$this->renderListCsv($list);
		}
		else{
			$this->renderListHtml($list);
		}
    }
	
	/*
	*format=csv*
	*/
	function renderListCsv(&$list=NULL)
	{
		global $csv_args;
		global $csv_count;
		
		$count = count($this->columns);
		$csv_args[$csv_count++] = $count;
		if($list || !$this->no_items_html) {
			$this->render_thead();
			 if($list) {
			 	foreach($list as $e) {
            		$this->render_trow($e);
        		}
			 }
		}
	}

...
  • example 3

from render/render_list_column_special.inc.php

class ListBlockColDate extends ListBlockCol
{
    public $key= 'modified';

    function __construct($args=NULL) {
        parent::__construct($args);
        if(!$this->name) {
            $this->name= __('Modified');
        }
    }

	function render_tr(&$obj, $style="", $format="html") {
	    global $auth;

		if(!isset($obj) || !is_object($obj)) {
			trigger_error("ListBlockColDate->render_tr() called without valid object", E_USER_WARNING);
   			return;
		}
		
		global $csv_args;
		global $csv_count;
		
		$key= $this->key;
		
		if($format == 'csv'){
			$csv_args[$csv_count++] = $obj->$key;
		}
		else{
			$value_str=renderDateHtml($obj->$key);
			print "<td class='nowrap'>$value_str</td>";
		}        
	}
}

Is it okay like this?