<?php

class MYPDF extends TCPDF {
    public function Footer() {
        $this->SetY(-10);
        $this->SetFont('helvetica', 'N', 7);
        $this->Cell(0, 15, "Oprogramowanie dostarcza: www.technix.pl", 0, false, 'L', 0, '', 0, false, 'T', 'M');
        $this->Cell(0, 15, 'Strona '.$this->getAliasNumPage().'/'.$this->getAliasNbPages(), 0, false, 'R', 0, '', 0, false, 'T', 'M');
    }
}

class AnalysisController extends Zend_Controller_Action {


		
	function generate_comparepdf($save = false){
	
		$db = Zend_Registry::get('db');		
		$v = $this->_request->getParams();		
		$vPost = $this->_request->getPost();
		$this->_helper->viewRenderer->setNoRender();

		
		$searchp = '';
		
		foreach( $v['project_id'] as $k => $vvv ){
		
			if( $searchp == '' ){
				$searchp = 'p.project_id = '.$k;
			}else{
				$searchp = $searchp.' OR p.project_id = '.$k;			
			}
		
		}
		
/*		
		$html .= '
<table border="1" cellpadding="1" cellspacing="0">
	<tbody>
		';
		
for( $i = 0; $i != 5; $i++ ){
	$html .= '<tr>';
	for( $i2 = 101; $i2 != 181; $i2++ ){
		$html .= '<td style="text-align:center;font-size:5pt;">'.$i2.'</td>';
	}
	$html .= '</tr>';
}

		$html .= '	
	</tbody>	
</table>	
		';	
*/






		
		$ask = "
			SELECT 
			*,
			p.project_id AS project_id,
			
			(SELECT COUNT(*) AS d_rob FROM analysis_project_plan_row appr WHERE appr.analysis_project_plan_id = app.analysis_project_plan_id) AS d_rob,
			
			(SELECT COUNT(*) AS d_robz FROM analysis_project_ist_row apir WHERE apir.analysis_project_ist_id = api.analysis_project_ist_id AND apir.analysis_project_ist_row_real = 0) AS d_robz,
			
			(SELECT COUNT(*) AS d_robz FROM analysis_project_istplan_row apipr WHERE apipr.analysis_project_istplan_id = apip.analysis_project_istplan_id AND apipr.analysis_project_istplan_row_real = 0) AS d_robzp,

			(SELECT SUM(calendar_work_time) AS o_godz FROM analysis_project_plan_row appr, calendar c WHERE appr.calendar_id = c.calendar_id AND appr.analysis_project_plan_id = app.analysis_project_plan_id) AS o_godz,
			
			(SELECT MAX(analysis_project_istplan_row_employee_count) AS max_pr FROM analysis_project_istplan_row apipr WHERE apipr.analysis_project_istplan_id = apip.analysis_project_istplan_id AND apipr.analysis_project_istplan_row_real = 0) AS max_pr,

			(SELECT MAX(calendar_date) AS max_d FROM analysis_project_ist_row apir, calendar c WHERE apir.calendar_id = c.calendar_id AND apir.analysis_project_ist_id = api.analysis_project_ist_id) AS max_ist_date,

			(SELECT MAX(calendar_date) AS max_d FROM analysis_project_istplan_row apipr, calendar c WHERE apipr.calendar_id = c.calendar_id AND apipr.analysis_project_istplan_id = apip.analysis_project_istplan_id AND apipr.analysis_project_istplan_row_real = 0) AS max_istplan_date
			
			FROM 
			project p LEFT JOIN
			analysis_project_ist api 
			ON
			p.project_id = api.project_id
			LEFT JOIN
			analysis_project_istplan apip 
			ON 
			p.project_id = apip.project_id
			LEFT JOIN
			analysis_project_plan app 
			ON 
			p.project_id = app.project_id
			WHERE
			p.project_status = 0
			AND 
			p.project_activ_analysis = 1
			AND
			(".$searchp.")
			ORDER BY
			project_nr ASC	
		";
		$dataTableProject = $db->query($ask)->fetchAll();	


		$j = 0;
		
		$html = '';
		
	//	for( $i = 0; $i!=10; $i++ )
		foreach( $dataTableProject as $k => $val ){
		
		$j++;
		$analysis_project_plan_date_start = '';
		if($val['analysis_project_plan_date_start'] != NULL AND $val['analysis_project_plan_date_start'] != '0000-00-00') $analysis_project_plan_date_start = $val['analysis_project_plan_date_start'];
		
		$analysis_project_plan_date_stop = '';
		if($val['analysis_project_plan_date_stop'] != NULL AND $val['analysis_project_plan_date_stop'] != '0000-00-00') $analysis_project_plan_date_stop = $val['analysis_project_plan_date_stop'];
		
		$sum = '';
		if($val['project_h'] != -1 AND $val['project_h_add'] != -1){
			$sum = $val['project_h']+$val['project_h_add']; 
		}		
		if($val['project_h'] != -1 AND $val['project_h_add'] == -1){
			$sum = $val['project_h']; 
		}		
		if($val['project_h'] == -1 AND $val['project_h_add'] != -1){
			$sum = $val['project_h_add']; 
		}		
		if($val['project_h'] == -1 AND $val['project_h_add'] == -1){
			$sum = '-'; 
		}

		if( $sum != '-' ) $sum2 = $sum-$val['analysis_project_ist_time_work_sum'];
		else $sum2 = $sum;
		
		if( isset($val['max_pr']) ) $max_pr = $val['max_pr']; else $max_pr = '&nbsp;';
		
		
		if( $val['analysis_project_employee'] > ceil($val['analysis_project_ist_employee_avg']) ){
			$classAvg = ' bgcolor="#ff4747"';
		}elseif( $val['analysis_project_employee'] == ceil($val['analysis_project_ist_employee_avg']) ){
			$classAvg = ' bgcolor="#ffffff"';//' bgcolor="#ffff98"';
		}elseif( $val['analysis_project_employee'] < ceil($val['analysis_project_ist_employee_avg']) ){
			$classAvg = ' bgcolor="#5aff5a"';
		}
		
		
		$d_r = Lib_Date::dateBetween($val['analysis_project_plan_date_stop'],$val['max_ist_date']);
				
		if( $d_r == 0 ) $class_1 = ' bgcolor="#ffffff"';//' bgcolor="#ffff98"';
		elseif( $d_r == 1 ) $class_1 = ' bgcolor="#5aff5a"';
		elseif( $d_r == 2 ) $class_1 = ' bgcolor="#ff4747"';
		else $class_1 = '';
		
		$d_r = Lib_Date::dateBetween($val['analysis_project_plan_date_stop'],$val['max_istplan_date']);
				
		if( $d_r == 0 ) $class_2 = ' bgcolor="#ffffff"';//' bgcolor="#ffff98"';
		elseif( $d_r == 1 ) $class_2 = ' bgcolor="#5aff5a"';
		elseif( $d_r == 2 ) $class_2 = ' bgcolor="#ff4747"';
		else $class_2 = '';
		
		
		$html = 
		$html.'		
			<table border="1" cellpadding="8" cellspacing="0">
			
				<thead>
				
					<tr>
						<th></th>
						<th colspan="6" bgcolor="#dddddd" style="text-align:center;font-size:x-large;"><b>'.@LANG_analysis_list_0.'</b></th>
						<th colspan="5" bgcolor="#dddddd" style="text-align:center;font-size:x-large;"><b>'.@LANG_analysis_list_1_0.'</b></th>
					</tr>
				
					<tr>
						<th bgcolor="#eeeeee"><b>'.@LANG_analysis_list_1.'</b></th>
						<th bgcolor="#eeeeee"><b>'.@LANG_analysis_list_2.'</b></th>
						<th bgcolor="#eeeeee"><b>'.@LANG_analysis_list_3.'</b></th>
						<th bgcolor="#eeeeee"><b>'.@LANG_analysis_list_4.'</b></th>
						<th bgcolor="#eeeeee"><b>'.@LANG_analysis_list_5.'</b></th>
						<th bgcolor="#eeeeee"><b>'.@LANG_analysis_list_6.'</b></th>
						<th bgcolor="#eeeeee"><b>'.@LANG_analysis_list_7.'</b></th>					
						
						<th bgcolor="#eeeeee"><b>'.@LANG_analysis_list_1_1.'</b></th>
						<th bgcolor="#eeeeee"><b>'.@LANG_analysis_list_1_2.'</b></th>
						<th bgcolor="#eeeeee"><b>'.@LANG_analysis_list_1_3.'</b></th>
						<th bgcolor="#eeeeee"><b>'.@LANG_analysis_list_1_4.'</b></th>
						<th bgcolor="#eeeeee"><b>'.@LANG_analysis_list_1_5.'</b></th>
					</tr>
				
				</thead>
				';
				
				
		if( $sum != '-' ) $sum = Lib_Analysis::number_format_unchanged_precision($sum);
		if( $sum2 != '-' ) $sum2 = Lib_Analysis::number_format_unchanged_precision($sum2);		
			
		$html = 
		$html.'		
				<tbody>
				
					<tr style="border-top:5px;">
					
						<td rowspan="2">'.$val['project_nr'].'</td>
						<td rowspan="2">'.$analysis_project_plan_date_start.'</td>
						<td rowspan="2">'.$analysis_project_plan_date_stop.'</td>
						<td rowspan="2">'.$val['d_rob'].'</td>
						<td rowspan="2">'.$sum.'</td>
						<td rowspan="2">'.Lib_Analysis::number_format_unchanged_precision($val['o_godz']).'</td>
						<td rowspan="2">'.$val['analysis_project_employee'].'</td>
						<td rowspan="2">'.Lib_Analysis::number_format_unchanged_precision($val['analysis_project_ist_time_work_sum']).'</td>
						<td rowspan="1" '.$classAvg.'>'.ceil($val['analysis_project_ist_employee_avg']).'</td>
						<td rowspan="2">'.$sum2.'</td>
						<td rowspan="1" '.$class_1.'>'.$val['d_robz'].'</td>
						<td rowspan="1" '.$class_1.'>'.$val['max_ist_date'].'</td>
				
					</tr>
					
					<tr>
					
						<td>'.$max_pr.'</td>
						<td '.$class_2.'>'.$val['d_robzp'].'</td>	
						<td '.$class_2.'>'.$val['max_istplan_date'].'</td>					
					
					</tr>
				
				</tbody>
			
			</table>
			
			<br />
			<br />
			<br />
			<br />
			<br />
			<br />
		';
		
		
		
		
		
		
		}
		
		
		
		
		
		
		


		

		$name = mb_strtolower (@LANG_pdf_analysis, 'UTF-8');
		$nameFile = str_replace(" ","-",$name).'_'.date('d-m-Y_H-i-s');
		
		$pdf = new MYPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
		
		// set document information
		$pdf->SetCreator(PDF_CREATOR);
		$pdf->SetAuthor('www.TECHNIX.pl');
		$pdf->SetTitle($nameFile);
		$pdf->SetSubject($nameFile);
		$pdf->SetKeywords($nameFile);
		$pdf->setPrintHeader(false);
		
		// set default header data
		$pdf->setFooterData(array(0,64,0), array(0,64,128));

		// set header and footer fonts
		$pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));

		// set default monospaced font
		$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);

		// set margins
		$pdf->SetMargins(5, 15, 5);

		// set auto page breaks
		$pdf->SetAutoPageBreak(TRUE, 5);
		
		// set image scale factor
		$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);

		// ---------------------------------------------------------

		// set default font subsetting mode
		$pdf->setFontSubsetting(true);

		// Set font
		// dejavusans is a UTF-8 Unicode font, if you only need to
		// print standard ASCII chars, you can use core fonts like
		// helvetica or times to reduce file size.
		$pdf->SetFont('dejavusans', '', 7, '', true);

		// Add a page
		// This method has several options, check the source code documentation for more information.
		$pdf->AddPage('P','A3');
		
		$pdf->writeHTML($html, true, 0, true, true);

		ob_end_clean();
		if( $save == false ) $pdf->Output($nameFile.'.pdf', 'I');
		else{
			$file = $_SERVER['DOCUMENT_ROOT'].'raport/'.$nameFile.'.pdf';
			$pdf->Output($file, 'F');
			return $file;
		}

		
	}





















	public function init() {
		$information = new Zend_Session_Namespace('information');	
		if( Lib_Permission::CheckPermission('analysis') != true ){
			$information->permissionError = true;
			$this->_helper->redirector('index','index');		
		}
		
		$admin = new Zend_Session_Namespace('admin');
		if( $admin->admin_auth != true ){
			$this->_helper->redirector('index','login');
		}			
	}	
	
	public function indexAction() {	
		$db = Zend_Registry::get('db');	

	//	Lib_Analysis::deleteAnalysis();
	//	Lib_Analysis::generatePlan();
	//	Lib_Analysis::generateIst();	
	
		$AnalysisInfo = new AnalysisInfo();	
		
		$select = $db->select();
		$select->from('analysis_info',array('MAX(analysis_info_ins) as analysis_info_ins_max', 'analysis_info_ins')); 
		$stmt = $db->query($select);
		$data = $stmt->fetchAll();	
		$analysisInfoIns = $data[0]['analysis_info_ins_max'];		
		$analysis_info_ins_next = date("Y-m-d H:00:00", strtotime('+1 hours'));
		
		$this->view->analysis_info_ins_max =  $analysisInfoIns;
		$this->view->analysis_info_ins_next =  $analysis_info_ins_next;
		
		$ask = "
			SELECT 
			*,
			p.project_id AS project_id,
			
			(SELECT COUNT(*) AS d_rob FROM analysis_project_plan_row appr WHERE appr.analysis_project_plan_id = app.analysis_project_plan_id) AS d_rob,
			
			(SELECT COUNT(*) AS d_robz FROM analysis_project_ist_row apir WHERE apir.analysis_project_ist_id = api.analysis_project_ist_id AND apir.analysis_project_ist_row_real = 0) AS d_robz,
			
			(SELECT COUNT(*) AS d_robz FROM analysis_project_istplan_row apipr WHERE apipr.analysis_project_istplan_id = apip.analysis_project_istplan_id AND apipr.analysis_project_istplan_row_real = 0) AS d_robzp,

			(SELECT SUM(calendar_work_time) AS o_godz FROM analysis_project_plan_row appr, calendar c WHERE appr.calendar_id = c.calendar_id AND appr.analysis_project_plan_id = app.analysis_project_plan_id) AS o_godz,
			
			(SELECT MAX(analysis_project_istplan_row_employee_count) AS max_pr FROM analysis_project_istplan_row apipr WHERE apipr.analysis_project_istplan_id = apip.analysis_project_istplan_id AND apipr.analysis_project_istplan_row_real = 0) AS max_pr,

			(SELECT MAX(calendar_date) AS max_d FROM analysis_project_ist_row apir, calendar c WHERE apir.calendar_id = c.calendar_id AND apir.analysis_project_ist_id = api.analysis_project_ist_id) AS max_ist_date,

			(SELECT MAX(calendar_date) AS max_d FROM analysis_project_istplan_row apipr, calendar c WHERE apipr.calendar_id = c.calendar_id AND apipr.analysis_project_istplan_id = apip.analysis_project_istplan_id AND apipr.analysis_project_istplan_row_real = 0) AS max_istplan_date
			
			FROM 
			project p LEFT JOIN
			analysis_project_ist api 
			ON
			p.project_id = api.project_id
			LEFT JOIN
			analysis_project_istplan apip 
			ON 
			p.project_id = apip.project_id
			LEFT JOIN
			analysis_project_plan app 
			ON 
			p.project_id = app.project_id
			WHERE
			p.project_status = 0
			AND 
			p.project_activ_analysis = 1
			ORDER BY
			project_nr ASC		
		";
		$dataTable = $db->query($ask)->fetchAll();	
		
		$this->view->projectData =  $dataTable;
		
	}
	
	
	public function employeebusyAction() {	
		$db = Zend_Registry::get('db');	
		$v = $this->_request->getParams();

		if( !isset($v['m']) ){
			$this->_helper->redirector('employeebusy','analysis',null,array('m' => date('m-Y')));	
		}
		
		$m = explode("-",$v['m']);
		$iloscm = date("t", mktime(0,0,0,(int)$m[0],1,$m[1])); 
	//	var_dump($iloscm);
		
		$d = $m[1].'-'.$m[0];
		$ask = "
			SELECT 
			
			*,
			WEEK(calendar_date,1) AS calendar_date_week,
			YEAR(calendar_date) AS calendar_date_year,
            
			CASE WHEN c.calendar_date > CURDATE() 
				THEN 'true'
				ELSE 'false'
			END AS dateIsInFututre,
			
			( 
			SELECT COUNT(*) FROM employee e WHERE 
				e.employee_activ = 0 AND 
				(e.employee_activ_order = 0 AND e.employee_activ_order2 = 0 AND e.employee_activ_analysis = 0)
			) AS employee_count,

			(
				SELECT COUNT(*) FROM employee_alert ea 
				WHERE 
				ea.employee_alert_start <= c.calendar_date
				AND ea.employee_alert_stop >= c.calendar_date
			) AS employee_alert,
			
			(
			SELECT SUM(analysis_project_ist_row_employee_count) FROM analysis_project_ist_row apir, analysis_project_ist api, project p, calendar apir_c WHERE
				apir.analysis_project_ist_id = api.analysis_project_ist_id
                AND api.project_id = p.project_id
				AND apir.calendar_id = apir_c.calendar_id
				AND apir_c.calendar_id = c.calendar_id
                AND p.project_analysis_nch = 0
			) AS employee_count_busy,

			(
				SELECT COUNT(DISTINCT(employee_id)) FROM employee_settlement es, project p 
				WHERE 
                es.project_id = p.project_id
				AND es.employee_settlement_date = c.calendar_date
                AND p.project_analysis_nch = 0
			) AS employee_in_job   

			FROM 
			calendar c

			WHERE
			c.calendar_date >= '".$d."-01'
			AND
			c.calendar_date <= '".$d."-".$iloscm."'
			ORDER BY c.calendar_date	
		";
		//echo$ask;
		$dataTable = $db->query($ask)->fetchAll();		
		
		$this->view->chData = $dataTable;
		$this->view->m = $v['m'];
		
		$ask = "
			SELECT COUNT(*) AS i FROM employee e WHERE 
				e.employee_activ = 0 AND 
				(e.employee_activ_order = 0 AND e.employee_activ_order2 = 0 AND e.employee_activ_analysis = 0)		
		";
		$dataTableCount = $db->query($ask)->fetchAll();	
		$this->view->iE = $dataTableCount[0]['i'];
		
		$m_p = date('m-Y', strtotime($d."-01". '-1 days'));
		$m_n = date('m-Y', strtotime($d."-".$iloscm. '+1 days'));
		
		$this->view->m_p = $m_p;
		$this->view->m_n = $m_n;
	}
	
	
	public function analysisupdateAction() {
		$db = Zend_Registry::get('db');	
		$v = $this->_request->getParams();
		
		Lib_Analysis::deleteAnalysis();
		Lib_Analysis::generatePlan();
		Lib_Analysis::generateIst();	
		Lib_Analysis::updateDateGeneration();	
        $this->_helper->viewRenderer->setNoRender();
			
		if( $v['return'] ) $this->_helper->redirector($v['return'],'analysis',null,array($v['return_n'] => $v['return_id'], $v['return2_n'] => $v['return2_id']));
		
		if( $v['returnlink'] ){
			header('Location: '.$v['returnlink']);
			die();
		}
		
		if( !$v['return'] ) $this->_helper->redirector('index','analysis');
	}
	
	
	public function projectAction() {	
		$db = Zend_Registry::get('db');	
		$v = $this->_request->getParams();
		
		if( !isset($v['id']) ){
			$this->_helper->redirector('index','analysis');			
		}
		
		
		
		
		$this->view->project_id =  $v['id'];
		
	
		$AnalysisInfo = new AnalysisInfo();	
		
		$select = $db->select();
		$select->from('analysis_info',array('MAX(analysis_info_ins) as analysis_info_ins_max', 'analysis_info_ins')); 
		$stmt = $db->query($select);
		$data = $stmt->fetchAll();	
		$analysisInfoIns = $data[0]['analysis_info_ins_max'];		
		$analysis_info_ins_next = date("Y-m-d H:00:00", strtotime('+1 hours'));
		
		$this->view->analysis_info_ins_max =  $analysisInfoIns;
		$this->view->analysis_info_ins_next =  $analysis_info_ins_next;
		
		$ask = "
			SELECT 
			*,
			p.project_id AS project_id,
			
			(SELECT COUNT(*) AS d_rob FROM analysis_project_plan_row appr WHERE appr.analysis_project_plan_id = app.analysis_project_plan_id) AS d_rob,
			
			(SELECT COUNT(*) AS d_robz FROM analysis_project_ist_row apir WHERE apir.analysis_project_ist_id = api.analysis_project_ist_id AND apir.analysis_project_ist_row_real = 0) AS d_robz,
			
			(SELECT COUNT(*) AS d_robz FROM analysis_project_istplan_row apipr WHERE apipr.analysis_project_istplan_id = apip.analysis_project_istplan_id AND apipr.analysis_project_istplan_row_real = 0) AS d_robzp,

			(SELECT SUM(calendar_work_time) AS o_godz FROM analysis_project_plan_row appr, calendar c WHERE appr.calendar_id = c.calendar_id AND appr.analysis_project_plan_id = app.analysis_project_plan_id) AS o_godz,
			
			(SELECT MAX(analysis_project_istplan_row_employee_count) AS max_pr FROM analysis_project_istplan_row apipr WHERE apipr.analysis_project_istplan_id = apip.analysis_project_istplan_id AND apipr.analysis_project_istplan_row_real = 0) AS max_pr,

			(SELECT MAX(calendar_date) AS max_d FROM analysis_project_ist_row apir, calendar c WHERE apir.calendar_id = c.calendar_id AND apir.analysis_project_ist_id = api.analysis_project_ist_id) AS max_ist_date,

			(SELECT MAX(calendar_date) AS max_d FROM analysis_project_istplan_row apipr, calendar c WHERE apipr.calendar_id = c.calendar_id AND apipr.analysis_project_istplan_id = apip.analysis_project_istplan_id AND apipr.analysis_project_istplan_row_real = 0) AS max_istplan_date
			
			FROM 
			project p LEFT JOIN
			analysis_project_ist api 
			ON
			p.project_id = api.project_id
			LEFT JOIN
			analysis_project_istplan apip 
			ON 
			p.project_id = apip.project_id
			LEFT JOIN
			analysis_project_plan app 
			ON 
			p.project_id = app.project_id
			WHERE
			p.project_status = 0
			AND 
			p.project_activ_analysis = 1
			AND
			p.project_id = ".$v['id']."
			ORDER BY
			project_nr ASC	
			LIMIT 1
		";
		$dataTable = $db->query($ask)->fetchAll();	
	//	$dataTable = $db->fetchRow($ask);
		
		$this->view->projectData =  $dataTable;
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
			//COALESCE(api.analysis_project_ist_date_stop_ist, "2035-01-01"), 
			//COALESCE(app.analysis_project_plan_date_stop, "2035-01-01"),
/*			
			COALESCE(NULLIF(api.analysis_project_ist_date_stop_ist,0), "0000-00-00"),
*/	
		$ask = '
			SELECT 

			MIN(LEAST(
				COALESCE(NULLIF(app.analysis_project_plan_date_start,0), "2035-01-01"),	
				COALESCE(NULLIF(app.analysis_project_plan_date_stop,0), "2035-01-01"),				 
				COALESCE(NULLIF(api.analysis_project_ist_date_min,0), "2035-01-01"), 
				COALESCE(NULLIF(api.analysis_project_ist_date_max,0), "2035-01-01"), 
				COALESCE(NULLIF(apip.analysis_project_istplan_date_min,0), "2035-01-01"), 
				COALESCE(NULLIF(apip.analysis_project_istplan_date_max,0), "2035-01-01")
			)) AS minDate, 

			MAX(GREATEST(
				COALESCE(app.analysis_project_plan_date_start, "0000-00-00"), 
				COALESCE(app.analysis_project_plan_date_stop, "0000-00-00"), 
				COALESCE(api.analysis_project_ist_date_min, "0000-00-00"), 
				COALESCE(api.analysis_project_ist_date_max, "0000-00-00"), 
				COALESCE(api.analysis_project_ist_date_stop_ist, "0000-00-00"),
				COALESCE(apip.analysis_project_istplan_date_min, "0000-00-00"), 
				COALESCE(apip.analysis_project_istplan_date_max, "0000-00-00")
			)) AS maxDate

			FROM 
			project p LEFT JOIN
			analysis_project_ist api 
			ON
			p.project_id = api.project_id
			LEFT JOIN
			analysis_project_istplan apip 
			ON 
			p.project_id = apip.project_id
			LEFT JOIN
			analysis_project_plan app 
			ON 
			p.project_id = app.project_id
			WHERE
			p.project_status = 0
			AND 
			p.project_activ_analysis = 1

			AND
			p.project_id = '.$v['id'].'
			
			ORDER BY
			project_nr ASC
		';
		
		$fR = $db->fetchRow($ask);
		
	/*	
		var_dump($fR);
		echo'<br /><br />'.$ask;
		die();
	*/	

		$this->view->minDate = $fR['minDate'];
		$this->view->maxDate = $fR['maxDate'];
		
		if( !isset($fR['minDate']) AND !isset($fR['maxDate']) ){
			$this->_helper->redirector('index','analysis');			
		}
		
		if( $fR['minDate'] != '2035-01-01' AND $fR['maxDate'] != '0000-00-00' AND $fR['minDate'] != $fR['maxDate'] ){		
			// zapytanie kalendarza
			$this->view->bd = false;	
			
			$ask = "
				SELECT
					c.*,
					WEEK(calendar_date,1) AS calendar_date_week,
					YEAR(calendar_date) AS calendar_date_year,
					(SELECT COUNT(*) FROM calendar c2 WHERE WEEK(c2.calendar_date,1) = calendar_date_week AND YEAR(c2.calendar_date) = calendar_date_year AND c2.calendar_date >= '".$fR['minDate']."' AND c2.calendar_date <= '".$fR['maxDate']."') AS calendar_date_week_count,
					appr.*,
					apir.*,
					apipr.*,
					apipmr.*,
					(SELECT analysis_project_plan_date_stop FROM analysis_project_plan WHERE project_id = ".$v['id'].") AS analysis_project_plan_date_stop
				FROM

					calendar c 
					
					LEFT JOIN
					analysis_project_plan_row appr 
						INNER JOIN
						analysis_project_plan app
						ON appr.analysis_project_plan_id = app.analysis_project_plan_id AND app.project_id = ".$v['id']."
					ON c.calendar_id = appr.calendar_id
					
					LEFT JOIN
					analysis_project_ist_row apir 
						INNER JOIN
						analysis_project_ist api
						ON apir.analysis_project_ist_id = api.analysis_project_ist_id AND api.project_id = ".$v['id']."
					ON c.calendar_id = apir.calendar_id
					
					LEFT JOIN
					analysis_project_istplan_row apipr 
						INNER JOIN
						analysis_project_istplan apip
						ON apipr.analysis_project_istplan_id = apip.analysis_project_istplan_id AND apip.project_id = ".$v['id']."
					ON c.calendar_id = apipr.calendar_id
					
					LEFT JOIN
					analysis_project_istplanman_row apipmr 
						INNER JOIN
						analysis_project_istplanman apipm
						ON apipmr.analysis_project_istplanman_id = apipm.analysis_project_istplanman_id AND apipm.project_id = ".$v['id']."
					ON c.calendar_id = apipmr.calendar_id
					
					
				WHERE

					c.calendar_date >= '".$fR['minDate']."'
					AND
					c.calendar_date <= '".$fR['maxDate']."'
			";		
		
			$dataTable = $db->query($ask)->fetchAll();			
			$this->view->analysisData = $dataTable;
		//	print_r($dataTable);
		
		}else{		
			// brak wynikow
			$this->view->bd = true;		
		}
	}
	
	
	
	
	

	
	
	public function compareAction() {	
		$db = Zend_Registry::get('db');	
		$v = $this->_request->getParams();
		
		if( count($v['project_id']) == 0 ){
			$this->_helper->redirector('index','analysis');			
		}
		
		$actual_link = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
	//	echo$actual_link;
		
		$this->view->actual_link = urlencode($actual_link);
		$this->view->url_this_page = $actual_link;	
		
		$searchp = '';
		
		foreach( $v['project_id'] as $k => $vvv ){
		
			if( $searchp == '' ){
				$searchp = 'p.project_id = '.$k;
			}else{
				$searchp = $searchp.' OR p.project_id = '.$k;			
			}
		
		}
		
	
		if( !isset($v['details']) ){
			$v['details'] = 0;			
		}
		
		$this->view->details =  $v['details'];		
		$this->view->project_id =  $v['project_id'];
		
	
		$AnalysisInfo = new AnalysisInfo();	
		
		$select = $db->select();
		$select->from('analysis_info',array('MAX(analysis_info_ins) as analysis_info_ins_max', 'analysis_info_ins')); 
		$stmt = $db->query($select);
		$data = $stmt->fetchAll();	
		$analysisInfoIns = $data[0]['analysis_info_ins_max'];		
		$analysis_info_ins_next = date("Y-m-d H:00:00", strtotime('+1 hours'));
		
		$this->view->analysis_info_ins_max =  $analysisInfoIns;
		$this->view->analysis_info_ins_next =  $analysis_info_ins_next;
		
		$ask = "
			SELECT 
			*,
			p.project_id AS project_id,
			
			(SELECT COUNT(*) AS d_rob FROM analysis_project_plan_row appr WHERE appr.analysis_project_plan_id = app.analysis_project_plan_id) AS d_rob,
			
			(SELECT COUNT(*) AS d_robz FROM analysis_project_ist_row apir WHERE apir.analysis_project_ist_id = api.analysis_project_ist_id AND apir.analysis_project_ist_row_real = 0) AS d_robz,
			
			(SELECT COUNT(*) AS d_robz FROM analysis_project_istplan_row apipr WHERE apipr.analysis_project_istplan_id = apip.analysis_project_istplan_id AND apipr.analysis_project_istplan_row_real = 0) AS d_robzp,

			(SELECT SUM(calendar_work_time) AS o_godz FROM analysis_project_plan_row appr, calendar c WHERE appr.calendar_id = c.calendar_id AND appr.analysis_project_plan_id = app.analysis_project_plan_id) AS o_godz,
			
			(SELECT MAX(analysis_project_istplan_row_employee_count) AS max_pr FROM analysis_project_istplan_row apipr WHERE apipr.analysis_project_istplan_id = apip.analysis_project_istplan_id AND apipr.analysis_project_istplan_row_real = 0) AS max_pr,

			(SELECT MAX(calendar_date) AS max_d FROM analysis_project_ist_row apir, calendar c WHERE apir.calendar_id = c.calendar_id AND apir.analysis_project_ist_id = api.analysis_project_ist_id) AS max_ist_date,

			(SELECT MAX(calendar_date) AS max_d FROM analysis_project_istplan_row apipr, calendar c WHERE apipr.calendar_id = c.calendar_id AND apipr.analysis_project_istplan_id = apip.analysis_project_istplan_id AND apipr.analysis_project_istplan_row_real = 0) AS max_istplan_date
			
			FROM 
			project p LEFT JOIN
			analysis_project_ist api 
			ON
			p.project_id = api.project_id
			LEFT JOIN
			analysis_project_istplan apip 
			ON 
			p.project_id = apip.project_id
			LEFT JOIN
			analysis_project_plan app 
			ON 
			p.project_id = app.project_id
			WHERE
			p.project_status = 0
			AND 
			p.project_activ_analysis = 1
			AND
			(".$searchp.")
			ORDER BY
			project_nr ASC	
		";
		$dataTableProject = $db->query($ask)->fetchAll();	
	//	$dataTable = $db->fetchRow($ask);
		
		$this->view->projectData =  $dataTableProject;
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
			//COALESCE(api.analysis_project_ist_date_stop_ist, "2035-01-01"), 
			//COALESCE(app.analysis_project_plan_date_stop, "2035-01-01"),
/*			
			COALESCE(NULLIF(api.analysis_project_ist_date_stop_ist,0), "0000-00-00"),
*/	
		$ask = '
			SELECT 

			MIN(LEAST(
				COALESCE(NULLIF(app.analysis_project_plan_date_start,0), "2035-01-01"),	
				COALESCE(NULLIF(app.analysis_project_plan_date_stop,0), "2035-01-01"),				 
				COALESCE(NULLIF(api.analysis_project_ist_date_min,0), "2035-01-01"), 
				COALESCE(NULLIF(api.analysis_project_ist_date_max,0), "2035-01-01"), 
				COALESCE(NULLIF(apip.analysis_project_istplan_date_min,0), "2035-01-01"), 
				COALESCE(NULLIF(apip.analysis_project_istplan_date_max,0), "2035-01-01")
			)) AS minDate, 

			MAX(GREATEST(
				COALESCE(app.analysis_project_plan_date_start, "0000-00-00"), 
				COALESCE(app.analysis_project_plan_date_stop, "0000-00-00"), 
				COALESCE(api.analysis_project_ist_date_min, "0000-00-00"), 
				COALESCE(api.analysis_project_ist_date_max, "0000-00-00"), 
				COALESCE(api.analysis_project_ist_date_stop_ist, "0000-00-00"),
				COALESCE(apip.analysis_project_istplan_date_min, "0000-00-00"), 
				COALESCE(apip.analysis_project_istplan_date_max, "0000-00-00")
			)) AS maxDate

			FROM 
			project p LEFT JOIN
			analysis_project_ist api 
			ON
			p.project_id = api.project_id
			LEFT JOIN
			analysis_project_istplan apip 
			ON 
			p.project_id = apip.project_id
			LEFT JOIN
			analysis_project_plan app 
			ON 
			p.project_id = app.project_id
			WHERE
			p.project_status = 0
			AND 
			p.project_activ_analysis = 1

			AND
			('.$searchp.')
			
			ORDER BY
			project_nr ASC
		';
		
		$fR = $db->fetchRow($ask);
		
/*		
		var_dump($fR);
		echo'<br /><br />'.$ask;
		die();
*/			
	
		if( $v['startd'] ){
			$fR['minDate'] = $v['startd'];
		}
	
		if( $v['stopd'] ){
			$fR['maxDate'] = $v['stopd'];
		}

		$this->view->minDate = $fR['minDate'];
		$this->view->maxDate = $fR['maxDate'];
		
	
		if( !isset($fR['minDate']) AND !isset($fR['maxDate']) ){
			$this->_helper->redirector('index','analysis');			
		}
		
		
		if( $fR['minDate'] != '2035-01-01' AND $fR['maxDate'] != '0000-00-00' AND $fR['minDate'] != $fR['maxDate'] ){
		
			$this->view->bd = false;
		
			$ask = "
					SELECT
						c.*,
						WEEK(calendar_date,1) AS calendar_date_week,
						YEAR(calendar_date) AS calendar_date_year,
						(SELECT COUNT(*) FROM calendar c2 WHERE WEEK(c2.calendar_date,1) = calendar_date_week AND YEAR(c2.calendar_date) = calendar_date_year AND c2.calendar_date >= '".$fR['minDate']."' AND c2.calendar_date <= '".$fR['maxDate']."') AS calendar_date_week_count
					FROM
						calendar c 
					WHERE
						c.calendar_date >= '".$fR['minDate']."'
						AND
						c.calendar_date <= '".$fR['maxDate']."'
			";
			$dataTable = $db->query($ask)->fetchAll();			
			$this->view->calendarData = $dataTable;
			
			
			
			
			
			foreach( $dataTableProject as $k => $val ){

				$ask = "
					SELECT
						c.*,
						WEEK(calendar_date,1) AS calendar_date_week,
						YEAR(calendar_date) AS calendar_date_year,
						(SELECT COUNT(*) FROM calendar c2 WHERE WEEK(c2.calendar_date,1) = calendar_date_week AND YEAR(c2.calendar_date) = calendar_date_year AND c2.calendar_date >= '".$fR['minDate']."' AND c2.calendar_date <= '".$fR['maxDate']."') AS calendar_date_week_count,
						appr.*,
						apir.*,
						apipr.*,
						apipmr.*,
						(SELECT analysis_project_plan_date_stop FROM analysis_project_plan WHERE project_id = ".$val['project_id'].") AS analysis_project_plan_date_stop
					FROM

						calendar c 
						
						LEFT JOIN
						analysis_project_plan_row appr 
							INNER JOIN
							analysis_project_plan app
							ON appr.analysis_project_plan_id = app.analysis_project_plan_id AND app.project_id = ".$val['project_id']."
						ON c.calendar_id = appr.calendar_id
						
						LEFT JOIN
						analysis_project_ist_row apir 
							INNER JOIN
							analysis_project_ist api
							ON apir.analysis_project_ist_id = api.analysis_project_ist_id AND api.project_id = ".$val['project_id']."
						ON c.calendar_id = apir.calendar_id
						
						LEFT JOIN
						analysis_project_istplan_row apipr 
							INNER JOIN
							analysis_project_istplan apip
							ON apipr.analysis_project_istplan_id = apip.analysis_project_istplan_id AND apip.project_id = ".$val['project_id']."
						ON c.calendar_id = apipr.calendar_id						
					
						LEFT JOIN
						analysis_project_istplanman_row apipmr 
							INNER JOIN
							analysis_project_istplanman apipm
							ON apipmr.analysis_project_istplanman_id = apipm.analysis_project_istplanman_id AND apipm.project_id = ".$val['project_id']."
						ON c.calendar_id = apipmr.calendar_id
						
						
					WHERE

						c.calendar_date >= '".$fR['minDate']."'
						AND
						c.calendar_date <= '".$fR['maxDate']."'
				";		
			
				$dataTableAnalysis[$val['project_id']] = $db->query($ask)->fetchAll();				
			
			}
			
				
			$this->view->dataTableAnalysis = $dataTableAnalysis;
			
			
		}else{		
			// brak wynikow
			$this->view->bd = true;		
		}

	/*	
		if( $fR['minDate'] != '2035-01-01' AND $fR['maxDate'] != '0000-00-00' AND $fR['minDate'] != $fR['maxDate'] ){		
			// zapytanie kalendarza
			$this->view->bd = false;	
			
			$ask = "
				SELECT
					c.*,
					WEEK(calendar_date,1) AS calendar_date_week,
					YEAR(calendar_date) AS calendar_date_year,
					(SELECT COUNT(*) FROM calendar c2 WHERE WEEK(c2.calendar_date,1) = calendar_date_week AND YEAR(c2.calendar_date) = calendar_date_year AND c2.calendar_date >= '".$fR['minDate']."' AND c2.calendar_date <= '".$fR['maxDate']."') AS calendar_date_week_count,
					appr.*,
					apir.*,
					apipr.*,
					(SELECT analysis_project_plan_date_stop FROM analysis_project_plan WHERE project_id = ".$v['id'].") AS analysis_project_plan_date_stop
				FROM

					calendar c 
					
					LEFT JOIN
					analysis_project_plan_row appr 
						INNER JOIN
						analysis_project_plan app
						ON appr.analysis_project_plan_id = app.analysis_project_plan_id AND app.project_id = ".$v['id']."
					ON c.calendar_id = appr.calendar_id
					
					LEFT JOIN
					analysis_project_ist_row apir 
						INNER JOIN
						analysis_project_ist api
						ON apir.analysis_project_ist_id = api.analysis_project_ist_id AND api.project_id = ".$v['id']."
					ON c.calendar_id = apir.calendar_id
					
					LEFT JOIN
					analysis_project_istplan_row apipr 
						INNER JOIN
						analysis_project_istplan apip
						ON apipr.analysis_project_istplan_id = apip.analysis_project_istplan_id AND apip.project_id = ".$v['id']."
					ON c.calendar_id = apipr.calendar_id
					
					
				WHERE

					c.calendar_date >= '".$fR['minDate']."'
					AND
					c.calendar_date <= '".$fR['maxDate']."'
			";		
		
			$dataTable = $db->query($ask)->fetchAll();			
			$this->view->analysisData = $dataTable;
		//	print_r($dataTable);
		
		}else{		
			// brak wynikow
			$this->view->bd = true;		
		}
		*/
	}	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	public function comparepdfAction() {	
		$v = $this->_request->getParams();		
		$vPost = $this->_request->getPost();	
		$this->_helper->viewRenderer->setNoRender();
			
		$this->generate_comparepdf();		
	}
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
		//	$objPHPExcel->getActiveSheet()->freezePane("A2");
	
	public function comparexlsAction() {	
		$this->_helper->viewRenderer->setNoRender();
		
		
		
		
		$analysis_td_yellow = array('type' => PHPExcel_Style_Fill::FILL_SOLID, 'startcolor' => array('rgb' => 'ffffff'/*'ffff98'*/));
		$analysis_td_green = array('type' => PHPExcel_Style_Fill::FILL_SOLID, 'startcolor' => array('rgb' => '5aff5a'));
		$analysis_td_red = array('type' => PHPExcel_Style_Fill::FILL_SOLID, 'startcolor' => array('rgb' => 'ff4747'),'font' => array('color' => array('rgb' => 'ffffff')));
		
		$analysis_td_error = array();
		
		
		
		
		
		$admin = new Zend_Session_Namespace('admin');
		$information = new Zend_Session_Namespace('information');
		$db = Zend_Registry::get('db');		
		
		$v = $this->_request->getParams();		
		$vPost = $this->_request->getPost();
	
		if( !isset($v['details']) ){
			$v['details'] = 0;			
		}
		
		$searchp = '';
		
		foreach( $v['project_id'] as $k => $vvv ){
		
			if( $searchp == '' ){
				$searchp = 'p.project_id = '.$k;
			}else{
				$searchp = $searchp.' OR p.project_id = '.$k;			
			}
		
		}

		$objPHPExcel = new PHPExcel;


		$col_width = 30;
		/*
		$objPHPExcel->getActiveSheet()->getColumnDimension('A')->setWidth($col_width);
		$objPHPExcel->getActiveSheet()->getColumnDimension('B')->setWidth($col_width);
		$objPHPExcel->getActiveSheet()->getColumnDimension('C')->setWidth($col_width);
		$objPHPExcel->getActiveSheet()->getColumnDimension('D')->setWidth($col_width);
		$objPHPExcel->getActiveSheet()->getColumnDimension('E')->setWidth($col_width);
		$objPHPExcel->getActiveSheet()->getColumnDimension('F')->setWidth($col_width);		
		*/
		
		$i = 0;		
		
		// nagłówki - początek
		if( $v['details'] == 1 ){
			$i++;
			$objPHPExcel->setActiveSheetIndex(0)	
				->setCellValue('B'.$i, @LANG_analysis_list_0)			
				->setCellValue('H'.$i, @LANG_analysis_list_1_0);	
			
			$objPHPExcel->getActiveSheet()->mergeCells('B'.$i.':G'.$i.'');
			$objPHPExcel->getActiveSheet()->mergeCells('H'.$i.':L'.$i.'');
			
			
			$objPHPExcel->getActiveSheet()->getStyle('B'.$i.':L'.$i)->getFill()->applyFromArray(array(
				'type' => PHPExcel_Style_Fill::FILL_SOLID,
				'startcolor' => array(
					'rgb' => 'dddddd'
				)
			));
			
			$objPHPExcel->getActiveSheet()->getStyle("G1:G3")->applyFromArray(
				array(
					'borders' => array(
						'right' => array(
							'style' => PHPExcel_Style_Border::BORDER_MEDIUM,
							'color' => array('rgb' => '337AB7')
						)
					)
				)
			);			
			
			$i++;
			$objPHPExcel->setActiveSheetIndex(0)
				->setCellValue('A'.$i, @LANG_analysis_list_1)	
				->setCellValue('B'.$i, @LANG_analysis_list_2)		
				->setCellValue('C'.$i, @LANG_analysis_list_3)
				->setCellValue('D'.$i, @LANG_analysis_list_4)						
				->setCellValue('E'.$i, @LANG_analysis_list_5)
				->setCellValue('F'.$i, @LANG_analysis_list_6)
				->setCellValue('G'.$i, @LANG_analysis_list_7)	
				
				->setCellValue('H'.$i, @LANG_analysis_list_1_1)		
				->setCellValue('I'.$i, @LANG_analysis_list_1_2)
				->setCellValue('J'.$i, @LANG_analysis_list_1_3)						
				->setCellValue('K'.$i, @LANG_analysis_list_1_4)
				->setCellValue('L'.$i, @LANG_analysis_list_1_5);				
				
			$LAST_COL = 11;
		}else{
		
			$i++;
			$i++;
			$objPHPExcel->setActiveSheetIndex(0)
				->setCellValue('A'.$i, @LANG_analysis_list_1);	
				
			$LAST_COL = 0;
		}
		// nagłówki - koniec

		for( $iTemp = 0; $iTemp != $LAST_COL + 2; $iTemp++ ){
			$objPHPExcel->getActiveSheet()->mergeCells(Lib_Data::Col($iTemp).$i.':'.Lib_Data::Col($iTemp).($i+1).'');		
		}

		$col_width = 12;
		for( $iTemp = 0; $iTemp != $LAST_COL + 1; $iTemp++ ){
			$objPHPExcel->getActiveSheet()->getColumnDimension(Lib_Data::Col($iTemp))->setWidth($col_width);	
		}
		$objPHPExcel->getActiveSheet()->getColumnDimension('A')->setWidth(15);
		
		

		$ask = '
			SELECT 

			MIN(LEAST(
				COALESCE(NULLIF(app.analysis_project_plan_date_start,0), "2035-01-01"),	
				COALESCE(NULLIF(app.analysis_project_plan_date_stop,0), "2035-01-01"),				 
				COALESCE(NULLIF(api.analysis_project_ist_date_min,0), "2035-01-01"), 
				COALESCE(NULLIF(api.analysis_project_ist_date_max,0), "2035-01-01"), 
				COALESCE(NULLIF(apip.analysis_project_istplan_date_min,0), "2035-01-01"), 
				COALESCE(NULLIF(apip.analysis_project_istplan_date_max,0), "2035-01-01")
			)) AS minDate, 

			MAX(GREATEST(
				COALESCE(app.analysis_project_plan_date_start, "0000-00-00"), 
				COALESCE(app.analysis_project_plan_date_stop, "0000-00-00"), 
				COALESCE(api.analysis_project_ist_date_min, "0000-00-00"), 
				COALESCE(api.analysis_project_ist_date_max, "0000-00-00"), 
				COALESCE(api.analysis_project_ist_date_stop_ist, "0000-00-00"),
				COALESCE(apip.analysis_project_istplan_date_min, "0000-00-00"), 
				COALESCE(apip.analysis_project_istplan_date_max, "0000-00-00")
			)) AS maxDate

			FROM 
			project p LEFT JOIN
			analysis_project_ist api 
			ON
			p.project_id = api.project_id
			LEFT JOIN
			analysis_project_istplan apip 
			ON 
			p.project_id = apip.project_id
			LEFT JOIN
			analysis_project_plan app 
			ON 
			p.project_id = app.project_id
			WHERE
			p.project_status = 0
			AND 
			p.project_activ_analysis = 1

			AND
			('.$searchp.')
			
			ORDER BY
			project_nr ASC
		';
		
		$fR = $db->fetchRow($ask);	

	//	var_dump($fR);die();
	
		if( $v['startd'] ){
			$fR['minDate'] = $v['startd'];
		}
	
		if( $v['stopd'] ){
			$fR['maxDate'] = $v['stopd'];
		}		
		
		if( !isset($fR['minDate']) AND !isset($fR['maxDate']) ){
			$this->_helper->redirector('index','analysis');			
		}
		
		if( $fR['minDate'] != '2035-01-01' AND $fR['maxDate'] != '0000-00-00' AND $fR['minDate'] != $fR['maxDate'] ){
		
			$ask = "
					SELECT
						c.*,
						WEEK(calendar_date,1) AS calendar_date_week,
						YEAR(calendar_date) AS calendar_date_year,
						(SELECT COUNT(*) FROM calendar c2 WHERE WEEK(c2.calendar_date,1) = calendar_date_week AND YEAR(c2.calendar_date) = calendar_date_year AND c2.calendar_date >= '".$fR['minDate']."' AND c2.calendar_date <= '".$fR['maxDate']."') AS calendar_date_week_count
					FROM
						calendar c 
					WHERE
						c.calendar_date >= '".$fR['minDate']."'
						AND
						c.calendar_date <= '".$fR['maxDate']."'
			";
			$calendarData = $db->query($ask)->fetchAll();	
			//echo count($calendarData).'<br /<hr><pre>' , var_dump($calendarData) , '</pre>';die();
			
			$colNr = $LAST_COL + 1;
			
			/*
			foreach( $calendarData as $key => $val ){			
				$colNr = $colNr + 1;				
				$colN = Lib_Data::Col($colNr);
				echo$colNr.' '.$val['calendar_day'].' '.$colN.'<br />';
			}
			die();
			*/
			$headerWeekNameTemp = '';
			foreach( $calendarData as $key => $val ){
				
				// naglowki - nazwa dnia - poczatek
				switch ( $val['calendar_day'] ) {
					case 1:
					case 2:
					case 3:
					case 4:
					case 5:
						$dayClass = '';
						$colorDay = '';
						break;
					case 6:
						$dayClass = 'cccccc';
						$colorDay = '0000ff';
						break;
					case 7:
						$dayClass = 'cccccc';
						$colorDay = 'ff0000';
						break;
				}
				$dayName = @constant(@LANG_analysis_day_.$val['calendar_day']);
				$day = Lib_Date::convertDate($val['calendar_date'], 'Y-m-d', 'd/m');
				
				$colNr = $colNr + 1;
				
				$colN = Lib_Data::Col($colNr);
				$objPHPExcel->setActiveSheetIndex(0)
					->setCellValue($colN.'2', $dayName);
				$objPHPExcel->setActiveSheetIndex(0)
					->setCellValue($colN.'3', $day);
					
				if( $colorDay != '' ){
					$objPHPExcel->getActiveSheet()->getStyle($colN."2:".$colN."3")->applyFromArray(
						array(
						/*
							'type' => PHPExcel_Style_Fill::FILL_SOLID, 
							'startcolor' => array('rgb' => $dayClass),
						*/
						'font'  => array(
								'color' => array('rgb' => $colorDay)
							)
						)
					);
					$objPHPExcel->getActiveSheet()->getStyle($colN."2:".$colN."3")->getFill()->applyFromArray(array('type' => PHPExcel_Style_Fill::FILL_SOLID, 'startcolor' => array('rgb' => $dayClass)));	
				}
			
				// naglowki - nazwa dnia - koniec
				
				
				
				// naglowki - nr tygodnia - poczatek
				if( $headerWeekNameTemp != $val['calendar_date_week'].' '.$val['calendar_date_year'] ){	
				
					$tit = str_replace(array("#WEEK#","#YEAR#"),array($val['calendar_date_week'],$val['calendar_date_year']),@LANG_analysis_week_xls);		
					
					$objPHPExcel->getActiveSheet()->mergeCells($colN.'1:'.Lib_Data::Col($colNr+$val['calendar_date_week_count']-1).'1');	
					$objPHPExcel->getActiveSheet()->setCellValue($colN.'1', $tit);			
				}
				$headerWeekNameTemp = $val['calendar_date_week'].' '.$val['calendar_date_year'];
				// naglowki - nr tygodnia - koniec
			
			}

		
			if( $v['details'] == 1 ){
				$objPHPExcel->getActiveSheet()->getStyle("A1:H1")->getFont()->setSize(14)->setBold(true);
			}else{
			
			}
			
			$objPHPExcel->getActiveSheet()->getStyle("A2:".$colN."3")->getFont()->setSize(8);
			
			$objPHPExcel->getActiveSheet()->getStyle(Lib_Data::Col($LAST_COL+1)."1:".$colN."1")->getFont()->setSize(8);
			
			$objPHPExcel->getActiveSheet()->getStyle(Lib_Data::Col($LAST_COL+1)."2:".$colN."2")->getFont()->setSize(14)->setBold(true);
			
			$objPHPExcel->getActiveSheet()->getStyle(Lib_Data::Col($LAST_COL+1)."3:".$colN."3")->getFont()->setSize(10);
			
						
		
		/*
			$objPHPExcel->getActiveSheet()->getStyle(Lib_Data::Col($LAST_COL+2)."2:".$colN."3")->getFill()->applyFromArray(array(
				'type' => PHPExcel_Style_Fill::FILL_SOLID,
				'startcolor' => array(
					'rgb' => 'eeeeee'
				)
			));
		*/	
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			

		
			$ask = "
				SELECT 
				*,
				p.project_id AS project_id,
				
				(SELECT COUNT(*) AS d_rob FROM analysis_project_plan_row appr WHERE appr.analysis_project_plan_id = app.analysis_project_plan_id) AS d_rob,
				
				(SELECT COUNT(*) AS d_robz FROM analysis_project_ist_row apir WHERE apir.analysis_project_ist_id = api.analysis_project_ist_id AND apir.analysis_project_ist_row_real = 0) AS d_robz,
				
				(SELECT COUNT(*) AS d_robz FROM analysis_project_istplan_row apipr WHERE apipr.analysis_project_istplan_id = apip.analysis_project_istplan_id AND apipr.analysis_project_istplan_row_real = 0) AS d_robzp,

				(SELECT SUM(calendar_work_time) AS o_godz FROM analysis_project_plan_row appr, calendar c WHERE appr.calendar_id = c.calendar_id AND appr.analysis_project_plan_id = app.analysis_project_plan_id) AS o_godz,
				
				(SELECT MAX(analysis_project_istplan_row_employee_count) AS max_pr FROM analysis_project_istplan_row apipr WHERE apipr.analysis_project_istplan_id = apip.analysis_project_istplan_id AND apipr.analysis_project_istplan_row_real = 0) AS max_pr,

				(SELECT MAX(calendar_date) AS max_d FROM analysis_project_ist_row apir, calendar c WHERE apir.calendar_id = c.calendar_id AND apir.analysis_project_ist_id = api.analysis_project_ist_id) AS max_ist_date,

				(SELECT MAX(calendar_date) AS max_d FROM analysis_project_istplan_row apipr, calendar c WHERE apipr.calendar_id = c.calendar_id AND apipr.analysis_project_istplan_id = apip.analysis_project_istplan_id AND apipr.analysis_project_istplan_row_real = 0) AS max_istplan_date
				
				FROM 
				project p LEFT JOIN
				analysis_project_ist api 
				ON
				p.project_id = api.project_id
				LEFT JOIN
				analysis_project_istplan apip 
				ON 
				p.project_id = apip.project_id
				LEFT JOIN
				analysis_project_plan app 
				ON 
				p.project_id = app.project_id
				WHERE
				p.project_status = 0
				AND 
				p.project_activ_analysis = 1
				AND
				(".$searchp.")
				ORDER BY
				project_nr ASC	
			";
			$dataTableProject = $db->query($ask)->fetchAll();			
		//	print_r($dataTableProject);die();
			
			foreach( $dataTableProject as $k => $val ){

				$ask = "
					SELECT
						c.*,
						WEEK(calendar_date,1) AS calendar_date_week,
						YEAR(calendar_date) AS calendar_date_year,
						(SELECT COUNT(*) FROM calendar c2 WHERE WEEK(c2.calendar_date,1) = calendar_date_week AND YEAR(c2.calendar_date) = calendar_date_year AND c2.calendar_date >= '".$fR['minDate']."' AND c2.calendar_date <= '".$fR['maxDate']."') AS calendar_date_week_count,
						appr.*,
						apir.*,
						apipr.*,
						(SELECT analysis_project_plan_date_stop FROM analysis_project_plan WHERE project_id = ".$val['project_id'].") AS analysis_project_plan_date_stop
					FROM

						calendar c 
						
						LEFT JOIN
						analysis_project_plan_row appr 
							INNER JOIN
							analysis_project_plan app
							ON appr.analysis_project_plan_id = app.analysis_project_plan_id AND app.project_id = ".$val['project_id']."
						ON c.calendar_id = appr.calendar_id
						
						LEFT JOIN
						analysis_project_ist_row apir 
							INNER JOIN
							analysis_project_ist api
							ON apir.analysis_project_ist_id = api.analysis_project_ist_id AND api.project_id = ".$val['project_id']."
						ON c.calendar_id = apir.calendar_id
						
						LEFT JOIN
						analysis_project_istplan_row apipr 
							INNER JOIN
							analysis_project_istplan apip
							ON apipr.analysis_project_istplan_id = apip.analysis_project_istplan_id AND apip.project_id = ".$val['project_id']."
						ON c.calendar_id = apipr.calendar_id
						
						
					WHERE

						c.calendar_date >= '".$fR['minDate']."'
						AND
						c.calendar_date <= '".$fR['maxDate']."'
				";		
			
				$dataTableAnalysis[$val['project_id']] = $db->query($ask)->fetchAll();	
			
			}
			
			
			
			
			
			$i++;
			
			foreach ($dataTableProject as $key => $val){
					
				$i++;					
					
				$objPHPExcel->getActiveSheet()->mergeCells('A'.$i.':A'.($i+2));		
				$objPHPExcel->getActiveSheet()->setCellValue('A'.$i, $val['project_nr']);	
				
				
				if( $v['details'] == 1 ){
				
					$c = 'B';
					$objPHPExcel->getActiveSheet()->mergeCells($c.$i.':'.$c.($i+2));	
					if($val['analysis_project_plan_date_start'] != NULL AND $val['analysis_project_plan_date_start'] != '0000-00-00'){
						$objPHPExcel->getActiveSheet()->setCellValue($c.''.$i, $val['analysis_project_plan_date_start']);		
					}
				
					$c = 'C';
					$objPHPExcel->getActiveSheet()->mergeCells($c.$i.':'.$c.($i+2));	
					if($val['analysis_project_plan_date_stop'] != NULL AND $val['analysis_project_plan_date_stop'] != '0000-00-00'){
						$objPHPExcel->getActiveSheet()->setCellValue($c.''.$i, $val['analysis_project_plan_date_stop']);		
					}
				
					$c = 'D';
					$objPHPExcel->getActiveSheet()->mergeCells($c.$i.':'.$c.($i+2));
					$objPHPExcel->getActiveSheet()->setCellValue($c.''.$i, $val['d_rob']);

				
					if($val['project_h'] != -1 AND $val['project_h_add'] != -1){
						$sum = $val['project_h']+$val['project_h_add']; 
					}
					
					if($val['project_h'] != -1 AND $val['project_h_add'] == -1){
						$sum = $val['project_h']; 
					}
					
					if($val['project_h'] == -1 AND $val['project_h_add'] != -1){
						$sum = $val['project_h_add']; 
					}
					
					if($val['project_h'] == -1 AND $val['project_h_add'] == -1){
						$sum = '-'; 
					}			
					$c = 'E';
					$objPHPExcel->getActiveSheet()->mergeCells($c.$i.':'.$c.($i+2));
					$objPHPExcel->getActiveSheet()->setCellValue($c.''.$i, $sum);	
				
				
					$c = 'F';
					$objPHPExcel->getActiveSheet()->mergeCells($c.$i.':'.$c.($i+2));					
					$objPHPExcel->getActiveSheet()->setCellValue($c.''.$i, $val['o_godz']);	
				
					$c = 'G';
					$objPHPExcel->getActiveSheet()->mergeCells($c.$i.':'.$c.($i+2));
					$objPHPExcel->getActiveSheet()->setCellValue($c.''.$i, $val['analysis_project_employee']);	
				
					$c = 'H';
					$objPHPExcel->getActiveSheet()->mergeCells($c.$i.':'.$c.($i+2));
					$objPHPExcel->getActiveSheet()->setCellValue($c.''.$i, $val['analysis_project_ist_time_work_sum']);
				
					$c = 'I';
					$objPHPExcel->getActiveSheet()->mergeCells($c.$i.':'.$c.($i+1));					
					$objPHPExcel->getActiveSheet()->setCellValue($c.''.$i, ceil($val['analysis_project_ist_employee_avg']));					
					if( $val['analysis_project_employee'] > ceil($val['analysis_project_ist_employee_avg']) ){
						$class = $analysis_td_red;
					}elseif( $val['analysis_project_employee'] == ceil($val['analysis_project_ist_employee_avg']) ){
						$class = $analysis_td_yellow;
					}elseif( $val['analysis_project_employee'] < ceil($val['analysis_project_ist_employee_avg']) ){
						$class = $analysis_td_green;
					}
					$objPHPExcel->getActiveSheet()->getStyle($c.''.$i)->getFill()->applyFromArray($class);
					$objPHPExcel->getActiveSheet()->getStyle($c.''.$i)->applyFromArray($class);
					
					if( isset($val['max_pr']) ) $max_pr = $val['max_pr']; else $max_pr ='';
					$objPHPExcel->getActiveSheet()->setCellValue($c.''.($i+2), $max_pr);
					
					$c = 'J';
					if( $sum != '-' ) $sumTemp = $sum-$val['analysis_project_ist_time_work_sum'];
					else $sumTemp = $sum;
					$objPHPExcel->getActiveSheet()->mergeCells($c.$i.':'.$c.($i+2));
					$objPHPExcel->getActiveSheet()->setCellValue($c.''.$i, $sumTemp);
					
					
					
					
					
					
				
					$c = 'K';
					$c2 = 'L';
					$objPHPExcel->getActiveSheet()->mergeCells($c.$i.':'.$c.($i+1));					
					$objPHPExcel->getActiveSheet()->setCellValue($c.''.$i, ceil($val['d_robz']));
					$objPHPExcel->getActiveSheet()->mergeCells($c2.$i.':'.$c2.($i+1));					
					$objPHPExcel->getActiveSheet()->setCellValue($c2.''.$i, $val['max_ist_date']);
					
					$d_r = Lib_Date::dateBetween($val['analysis_project_plan_date_stop'],$val['max_ist_date']);
					
					if( $d_r == 0 ) $class = $analysis_td_yellow;
					elseif( $d_r == 1 ) $class = $analysis_td_green;
					elseif( $d_r == 2 ) $class = $analysis_td_red;
					else $class = $analysis_td_error;
					
					$objPHPExcel->getActiveSheet()->getStyle($c.''.$i)->getFill()->applyFromArray($class);
					$objPHPExcel->getActiveSheet()->getStyle($c.''.$i)->applyFromArray($class);	
					$objPHPExcel->getActiveSheet()->getStyle($c2.''.$i)->getFill()->applyFromArray($class);
					$objPHPExcel->getActiveSheet()->getStyle($c2.''.$i)->applyFromArray($class);		
					
					
					$objPHPExcel->getActiveSheet()->setCellValue($c.''.($i+2), $val['d_robzp']);
					$objPHPExcel->getActiveSheet()->setCellValue($c2.''.($i+2), $val['max_istplan_date']);
					
					$d_r = Lib_Date::dateBetween($val['analysis_project_plan_date_stop'],$val['max_istplan_date']);
					
					if( $d_r == 0 ) $class = $analysis_td_yellow;
					elseif( $d_r == 1 ) $class = $analysis_td_green;
					elseif( $d_r == 2 ) $class = $analysis_td_red;
					else $class = $analysis_td_error;
					
					$objPHPExcel->getActiveSheet()->getStyle($c.''.($i+2))->getFill()->applyFromArray($class);
					$objPHPExcel->getActiveSheet()->getStyle($c.''.($i+2))->applyFromArray($class);
					$objPHPExcel->getActiveSheet()->getStyle($c2.''.($i+2))->getFill()->applyFromArray($class);
					$objPHPExcel->getActiveSheet()->getStyle($c2.''.($i+2))->applyFromArray($class);
					
			
				$objPHPExcel->getActiveSheet()->getStyle("A".$i.":".$colN.$i)->applyFromArray(
					array(
						'borders' => array(
							'top' => array(
								'style' => PHPExcel_Style_Border::BORDER_MEDIUM,
								'color' => array('rgb' => '337AB7')
							)
						)
					)
				);	
			
				$objPHPExcel->getActiveSheet()->getStyle("G".$i.":G".($i+2))->applyFromArray(
					array(
						'borders' => array(
							'right' => array(
								'style' => PHPExcel_Style_Border::BORDER_MEDIUM,
								'color' => array('rgb' => '337AB7')
							)
						)
					)
				);	

					$c = 'M';	
					
				}else{
				
					$c = 'B';	

				}
				
				$objPHPExcel->getActiveSheet()->setCellValue($c.''.$i, @LANG_analysis_project_1);
				$objPHPExcel->getActiveSheet()->setCellValue($c.''.($i+1), @LANG_analysis_project_2);
				$objPHPExcel->getActiveSheet()->setCellValue($c.''.($i+2), @LANG_analysis_project_3);
					
				$objPHPExcel->getActiveSheet()->getStyle($c.''.$i.':'.$c.''.($i+2))->getFill()->applyFromArray(array('type' => PHPExcel_Style_Fill::FILL_SOLID, 'startcolor' => array('rgb' => 'dddddd')));				
				$objPHPExcel->getActiveSheet()->getStyle($c.''.$i.':'.$c.''.($i+2))->getFont()->setBold(true);	
				
				$objPHPExcel->getActiveSheet()->getStyle('A'.$i.':'.$c.''.($i+2))->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_TOP);
				$objPHPExcel->getActiveSheet()->getStyle($c.$i.':'.$c.''.($i+2))->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
				$objPHPExcel->getActiveSheet()->getStyle('A'.$i.':'.$c.''.($i+2))->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
				
				
				
				
				
				
				
				
				
				
				// wyświetlanie kolejnych dni - poczatek				
				
				$colNr = $LAST_COL + 1;
				foreach( $dataTableAnalysis[$val['project_id']] as $key1 => $val1 ){

					$colNr = $colNr + 1;				
					$colN = Lib_Data::Col($colNr);
					
	
	
					switch ( $val1['calendar_day'] ) {
						case 1:
						case 2:
						case 3:
						case 4:
						case 5:
							$dayClass = '';
							break;
						case 6:
							$dayClass = 'dddddd';
							break;
						case 7:
							$dayClass = 'dddddd';
							break;
					}
					
					// PLAN - pocztek
					$nameField = 'analysis_project_plan_row_employee_count';
					$nameFieldPlan = $nameField;
					if( $val1[$nameField] != null AND $val1[$nameField] > 0 ){
						$objPHPExcel->getActiveSheet()->setCellValue($colN.$i, $val1[$nameField]);
						$objPHPExcel->getActiveSheet()->getStyle($colN.$i)->getFill()->applyFromArray($analysis_td_yellow);
					}
					else{
					
					}
					// PLAN - koniec				
				

	
					// IST - pocztek
					$nameField = 'analysis_project_ist_row_employee_count';
					
					if( $val1[$nameField] < $val1[$nameFieldPlan] ) $class = $analysis_td_red;
					elseif( $val1[$nameField] > $val1[$nameFieldPlan] ) $class = $analysis_td_green;
					else $class = $analysis_td_yellow;
					
					if( $val1['analysis_project_plan_date_stop'] != '0000-00-00' AND Lib_Date::dateBetween($val1['calendar_date'],$val1['analysis_project_plan_date_stop']) == 1 ){
						$class = $analysis_td_red;
					}
					
					if( $val1[$nameField] != null AND $val1[$nameField] > 0 ){
					//	$empIst = $empIst.'<td class="'.$class.' dayCenter">'.$val1[$nameField].'</td>';
						$objPHPExcel->getActiveSheet()->setCellValue($colN.($i+1), $val1[$nameField]);
						$objPHPExcel->getActiveSheet()->getStyle($colN.($i+1))->getFill()->applyFromArray($class);
						$objPHPExcel->getActiveSheet()->getStyle($colN.($i+1))->applyFromArray($class);				
						if( $val1[str_replace('employee_count','real',$nameField)] == 1 ){

							$objPHPExcel->getActiveSheet()->getStyle($colN.($i+1))->getFont()->setBold(true)->setUnderline(PHPExcel_Style_Font::UNDERLINE_DOUBLEACCOUNTING);
						
						}
					}
					else{
					
					}
					// IST - koniec

	
	
					// ISTPLAN - pocztek
					$nameField = 'analysis_project_istplan_row_employee_count';
					
					if( $val1[$nameField] < $val1[$nameFieldPlan] ) $class = $analysis_td_red;
					elseif( $val1[$nameField] > $val1[$nameFieldPlan] ) $class = $analysis_td_green;
					else $class = $analysis_td_yellow;
					
					if( $val1['analysis_project_plan_date_stop'] != '0000-00-00' AND Lib_Date::dateBetween($val1['calendar_date'],$val1['analysis_project_plan_date_stop']) == 1 ){
						$class = $analysis_td_red;
					}
					
					if( $val1[$nameField] != null AND $val1[$nameField] > 0 ){
					//	$empIstPlan = $empIstPlan.'<td class="'.$class.' dayCenter">'.$val1[$nameField].'</td>';					
						$objPHPExcel->getActiveSheet()->setCellValue($colN.($i+2), $val1[$nameField]);
						$objPHPExcel->getActiveSheet()->getStyle($colN.($i+2))->getFill()->applyFromArray($class);
						$objPHPExcel->getActiveSheet()->getStyle($colN.($i+2))->applyFromArray($class);
							
						if( $val1[str_replace('employee_count','real',$nameField)] == 1 ){

							$objPHPExcel->getActiveSheet()->getStyle($colN.($i+2))->getFont()->setBold(true)->setUnderline(PHPExcel_Style_Font::UNDERLINE_DOUBLEACCOUNTING);
						
						}
						
					}else{
					
					}
					// ISTPLAN - koniec
	
	
	
				
				}

				// wyświetlanie kolejnych dni - koniec	
				
				
				
				
				
				
				
				
				
				$i = $i+2;
			}
			
			
		
			$colN0 = Lib_Data::Col($LAST_COL + 2);
		//	var_dump($colN0.$i.':'.$colN.''.($i+2));die();
			
			$objPHPExcel->getActiveSheet()->getStyle($colN0.'4:'.$colN.''.($i))->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
			
			$objPHPExcel->getActiveSheet()->getStyle($colN0.'4:'.$colN.''.($i))->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
				
			
			
		//	$objPHPExcel->getActiveSheet()->getStyle('A1:'.$c.$i)->getAlignment()->setIndent(1);
			
			
			
			
			
			
			
			
		
		
		}else{		
			// brak wynikow
			
		}
		

		$objPHPExcel->getActiveSheet()->getStyle("A1:".$colN."3")->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
		
		$objPHPExcel->getActiveSheet()->getStyle("A1:".$colN."3")->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
	
	
		

		$col_width = 6;
		for( $iTemp = $LAST_COL+2; $iTemp != $colNr+1; $iTemp++ ){
			$objPHPExcel->getActiveSheet()->getColumnDimension(Lib_Data::Col($iTemp))->setWidth($col_width);	
		}		
		
		$objPHPExcel->getActiveSheet()->getStyle('A1'.':'.Lib_Data::Col($colNr)."3")->getAlignment()->setWrapText(true);
	
		$objPHPExcel->getActiveSheet()->freezePane(Lib_Data::Col($LAST_COL+2)."4");

		$objPHPExcel->getActiveSheet()->getDefaultRowDimension()->setRowHeight(25);
		
		$name = mb_strtolower (@LANG_xls_analysis, 'UTF-8');
		$nameFile = str_replace(" ","-",$name).'_'.date('d-m-Y_H-i-s');		

		// Set active sheet index to the first sheet, so Excel opens this as the first sheet
		$objPHPExcel->setActiveSheetIndex(0);
		
		// Redirect output to a clientâ€™s web browser (Excel5)
		header('Content-Type: application/vnd.ms-excel');
		header('Content-Disposition: attachment;filename="'.$nameFile.'.xls"');
		header('Cache-Control: max-age=0');
		// If you're serving to IE 9, then the following may be needed
		header('Cache-Control: max-age=1');

		// If you're serving to IE over SSL, then the following may be needed
		header ('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past
		header ('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT'); // always modified
		header ('Cache-Control: cache, must-revalidate'); // HTTP/1.1
		header ('Pragma: public'); // HTTP/1.0

		$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
		$objWriter->save('php://output');	
		
		/*
		header('Content-Type: application/vnd.ms-excel');
		header('Content-Disposition: attachment;filename="'.$nameFile.'.xlsx"');
		header('Cache-Control: max-age=0');
		// If you're serving to IE 9, then the following may be needed
		header('Cache-Control: max-age=1');

		// If you're serving to IE over SSL, then the following may be needed
		header ('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past
		header ('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT'); // always modified
		header ('Cache-Control: cache, must-revalidate'); // HTTP/1.1
		header ('Pragma: public'); // HTTP/1.0
		
		$objWriter = new PHPExcel_Writer_Excel2007($objPHPExcel);
		$objWriter->save('php://output');
		*/
	}
	
	
	
	public function projectchangeanalysisAction() {	
		$this->_helper->viewRenderer->setNoRender();
		$v = $this->_request->getParams();
		
		$Project = new Project();	
		
		$data = array(
			'project_analysis_nch' => $v['pVal']
		);
		$Project->update( $data, 'project_id = '.$v['pid'] );	
	
	}
	
	
	public function testAction() {	
		$this->_helper->viewRenderer->setNoRender();
	
	
		for( $i = 0; $i != 20000; $i++ ){
			echo $i.'='.Lib_Data::Col2($i).'<br />';
		}
	
	}
	
	
	
	
	
	
	
/*	
	public function calendarmapgeneratorAction() {	
		$db = Zend_Registry::get('db');	
		
		$Calendar = new Calendar();
		
		// data startu
		$day = '2010-01-01';
		
		// data stop +1 dzień
		$stop = '2036-01-01';
		
		for( $iDay = 1; $day != $stop; $i++ ){
		
			$day_number = date('N',strtotime($day));
			$month_number = date('n',strtotime($day));
			
			$work_time = 0;
			if( $day_number != 6 AND $day_number != 7 ){
				$work_time = 10;			
				if( $month_number >= 11 OR $month_number <= 2 ) $work_time = 8;
			}
			
		//	echo$day.' / '.$day_number.' / '.$work_time;
		//	echo'<br />';
			
			unset($data);
			$data = array(
				'calendar_date' => $day,
				'calendar_day' => $day_number,
				'calendar_special' => 0,
				'calendar_work_time' => $work_time
			);
		///	$idIns = $Calendar->insert($data);
			
			$day = date('Y-m-d', strtotime($day. '+1 days'));
		
		}
		
		echo'gotowe';
        $this->_helper->viewRenderer->setNoRender();
	}
*/

}
