<?php
class DirigeantController extends Zend_Controller_Action
{
	protected $siret;
	protected $id;

	public function init()
	{
		$request = $this->getRequest();
		$this->siret = $request->getParam('siret');
		$this->id = $request->getParam('id', 0);

		require_once 'Scores/WsScores.php';
	}

	/**
	 * Affichage de la liste des dirigeants
	 */
	public function listeAction()
	{
		$request = $this->getRequest();
		$autrePage = $this->getRequest()->getParam('apage');

		$siren = substr($this->siret, 0, 9);

		if (empty($autrePage)) {
			$this->view->headTitle()->prepend('Liste des dirigeants');
			$this->view->headTitle()->prepend('Siret '.$this->siret);
		}

		$ws = new WsScores();
		$infos = $ws->getDirigeants($siren);

		if ($infos === false){
			$this->forward('soap', 'error');
		}

		$dirigeants = $infos->result->item;

		$user = new Scores_Utilisateur();
		$session = new Scores_Session_Entreprise($this->siret, $this->id);

		if ($user->checkPerm('dirigeantsop')){
			$href = $this->view->url(array('controller'=>'dirigeant', 'action'=>'op', 'siret'=>$this->siret));
			$this->view->assign('dirigeantsop', $href);
		}

		$this->view->assign('edition', $user->checkModeEdition());
		$this->view->assign('accessWorldCheck', $user->checkPerm('WORLDCHECK'));

		$this->view->assign('siren', $siren);
		$this->view->assign('siret', $this->siret);
		$this->view->assign('raisonSociale', $session->getRaisonSociale());
		$this->view->assign('dirigeants', $dirigeants);
		$this->view->assign('exportObjet', $dirigeants);

		$this->view->assign('AutrePage', $this->getRequest()->getParam('apage'));
		$this->view->assign('surveillance', $user->checkPerm('survdirigeants'));
	}

	/**
	 * Affichage de l'historiques des dirigeants
	 */
	public function histoAction()
	{
		$siren = substr($this->siret, 0, 9);

		$this->view->headTitle()->prepend('Historique des dirigeants');
		$this->view->headTitle()->prepend('Siret '.$this->siret);

		$ws = new WsScores();
		$infos = $ws->getDirigeants($siren, true);

		if ($infos === false){
			$this->_forward('soap', 'error');
		}

		$dirigeants = $infos->result->item;

		$session = new Scores_Session_Entreprise($this->siret, $this->id);

		$this->view->assign('dirigeants', $dirigeants);
		$this->view->assign('exportObjet', $dirigeants);
		$this->view->assign('siren', $siren);
		$this->view->assign('siret', $this->siret);
		$this->view->assign('raisonSociale', $session->getRaisonSociale());
		$this->view->assign('infos', $infos);

		$user = new Scores_Utilisateur();
		$this->view->assign('surveillance', $user->checkPerm('survdirigeants'));
	}

	public function opAction()
	{
		$siren = substr($this->siret, 0, 9);

		$this->view->headTitle()->prepend('Liste des dirigeants opérationnels');
		$this->view->headTitle()->prepend('Siret '.$this->siret);

		$ws = new WsScores();
		$infos = $ws->getDirigeantsOp($siren);

		if ($infos === false){
			$this->_forward('soap', 'error');
		}

		$dirigeants = $infos->item;

		$session = new Scores_Session_Entreprise($this->siret, $this->id);

		$this->view->assign('siren', $siren);
		$this->view->assign('siret', $this->siret);
		$this->view->assign('raisonSociale', $session->getRaisonSociale());
		$this->view->assign('dirigeants', $dirigeants);
		$this->view->assign('exportObjet', $dirigeants);

		$this->view->assign('AutrePage', $this->getRequest()->getParam('apage'));

		$user = new Scores_Utilisateur();
		$this->view->assign('surveillance', $user->checkPerm('survdirigeants'));
	}
}