<?php
/*
BioMa Personnel.php template file

This file should be located in the classes directory
*/

/*
NOTICE OF COPYRIGHT

BioMa - Biodiversity Manager (Manager for biodiversity database)
        http://bioma.sourceforge.net

Copyright (C) 2005 BioMa Development Group

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details:

          http://www.gnu.org/copyleft/gpl.html
*/

/** 
* Provides the necessary functionality to insert information and generate 
* the Personnel template (templates/Personnel/Personnel.xtpl)
*
* @author Mats Mortensen <matsm@stud.cs.uit.no>
* @copyright Copyright (C) 2006 BioMa Development Group
* @access public
*
*/


class PersonnelTemplate extends Common{
	
	private $firstnamelabel;
	private $lastnamelabel;
	private $emaillabel;
	
	/**
	* Constructor for creating a PersonnelTemplate
	* @access public
	* @author Mats Mortensen <matsm@stud.cs.uit.no>
	*/
	public function PersonnelTemplate($xtpl, $lang, $langdir, $tpldir, $servicedir){
		parent::Common($xtpl, $lang, $langdir . 'Personnel/', $tpldir .'Personnel/', $servicedir, 'Personnel');
		$this->_xtpl->assign_file('MainContent', $this->_templateDir . 'Personnel.xtpl');
	}
	
	/**
	* Process all personnel related forms
	* @access public
	* @author Mats Mortensen <matsm@stud.cs.uit.no>
	* @return void
	*/
	public function processForms(){
			switch($_GET['operation']){
				case 'new':
					$this->generateNew();
					break;
				case 'edit':
					$this->generateEdit();
					break;
			}
	}
	
	/**
	* Generates the final template
	* @access private
	* @author Mats Mortensen <matsm@stud.cs.uit.no>
	* @return void
	*/
	public function generate(){
		/* Load the appropriate language strings (looks for lang/en/Personnel.php) when lang=en */
		$this->_lang->load($this->_langDir, 'Personnel');
		
		/*Variaveis do cabeçalho */
		$personnelHeader = $this->_lang->getText('personnel.label_personnel');
		$personnelNew = $this->_lang->getText('personnel.new');
		$this->_xtpl->assign('PersonnelHeader', array('personnelHeader' => $personnelHeader , 'new' => $personnelNew));
		$this->_xtpl->parse('Main.Personnel.PersonnelHeader');
		
		$this->firstnamelabel = $this->_lang->getText('personnel.sort.header_FirstName');
		$this->lastnamelabel = $this->_lang->getText('personnel.sort.header_LastName');
		$this->emaillabel = $this->_lang->getText('personnel.sort.header_Email');
		$submitbutton = $this->_lang->getText('mypage.personnel.button_submit');
		$this->_xtpl->assign('SortbarField', array('firstName' => $this->firstnamelabel,  'lastName' => $this->lastnamelabel , 'email' => $this->emaillabel));
		$this->_xtpl->parse('Main.Personnel.Sortbar.SortbarField');
		$this->_xtpl->parse('Main.Personnel.Sortbar');
		
		$this->generatePersonnels();
		
		$this->_xtpl->parse('Main.Personnel.PersonnelList'); 
				
		$this->_xtpl->assign('FilterField', array('firstName' => $this->firstnamelabel,  'lastName' => $this->lastnamelabel , 'email' => $this->emaillabel));
		$this->_xtpl->parse('Main.Personnel.Filter.FilterField');
		$this->_xtpl->parse('Main.Personnel.Filter');
		
		$this->_xtpl->parse('Main.Personnel');
		if(isset($_GET['action'])){
		switch ($_GET['action']) {
				case 'edit':
					$this->_xtpl->assign('Edit', array ('editHeader' => $this->_lang->getText('personnel.editHeader')));
					$this->generateEdit();
					break;
			}
		
		$this->_xtpl->assign('EditField', array('firstName' =>  $this->firstnamelabel,  'lastName' =>  $this->lastnamelabel , 'email' =>  $this->emaillabel));
		$this->_xtpl->parse('Main.Edit.EditField');
		$this->_xtpl->parse('Main.Edit');
		}
		$this->processForms();
		
	}
	
	private function generatePersonnels(){
		$client = new SoapClient($this->_serviceDir . 'Personnel.wsdl');
		//$personnels = $client->listPersonnel();
		$value['firstname'] = 'teste';
		$value['email'] = 'teste@tttttttt';
		$value['lastname'] = 'aaaaaaaaaa';
		$personnels[] = $value;
		$value['firstname'] = 'teste123';
		$value['lastname'] = 'bbbbbbbbbbbbb';
		$value['email'] = 'teste@tttttttt';
		$personnels[] = $value;
		
		$count = count($personnels);
		$fields = array();
		/* In case no Personnnels to display, just return */
		if(!isset($personnels) || !$personnels || $count == 0 )
			return;

		$i = 0;
		
		/* Loop over each Personnel item */
		foreach($personnels as $value){
			/* Find # of fields count */
			$arraySize = count($value);
			if($arraySize > 0)
				$width = (int) (100/($arraySize+1));

			$this->_xtpl->assign('PersonnelItemField',  $value);
			$this->_xtpl->parse('Main.Personnel.PersonnelList.PersonnelItem.PersonnelItemField');
			/* CSS class for even items */
			if($i % 2 == 0) $class = 'EvenLine';
			/* CSS class for odd items */
			if($i % 2 != 0) $class = 'OddLine';
			
			/* Assign color for the item */
			/* Assign width and link of last field (view specimen) */
			/* Assign language specific */
			$this->_xtpl->assign('PersonnelItem', array(	'class' => $class, 
															'width' => $width, 
															'link' => $fields[0]['link'],
															'listCollection' => $this->_lang->getText('ListSpecimen')));
		
			/* Create item html */
			$this->_xtpl->parse('Main.Personnel.PersonnelList.PersonnelItem');
			
			$i++;
		}
	}
	
	public function generateNew(){
		$this->_xtpl->assign('Edit', array ('editHeader' => $this->_lang->getText('personnel.inputHeader')));
		$this->_xtpl->assign('EditField', array('firstName' => $this->firstnamelabel,  'lastName' => $this->lastnamelabel , 'email' => $this->emaillabel));
		$this->_xtpl->parse('Main.Edit.EditField');
		$this->_xtpl->parse('Main.Edit');
	}
	
	public function generateEdit(){
		$idPersonnel = $_GET['personnel'];
		echo $idPersonnel;
	}
	
	public function inputPersonnel(){
	
	}
	
	public function updatePersonnel(){
	
	}
	
	public function viewPersonnel(){
	
	}
}

?>
