/**
  * Wyświetlenie ankiety do wypełnienia
  */
 public function pokazAction()
 {
     $pool = new Ankiety();
     $question = new Pytania();
     $answer = new Odpowiedzi();
     $variants = new WariantyOdpowiedzi();
     $filledPool = new WypelnioneAnkiety();
     $db = $question->getAdapter();
     unset($_POST['send']);
     if (strtolower($_SERVER['REQUEST_METHOD']) == 'post') {
         $data = array('id_ankieta' => $this->_getParam('ankieta'));
         $idFilledPool = $filledPool->insert($data);
         foreach ($_POST as $questionId => $answerT) {
             if (is_array($answerT)) {
                 foreach ($answerT as $answerId => $value) {
                     $data = array('id_wypelniona_ankieta' => $idFilledPool, 'id_pytanie' => $questionId, 'odpowiedz' => $answerId);
                     $id = $answer->insert($data);
                 }
             } else {
                 $data = array('id_wypelniona_ankieta' => $idFilledPool, 'id_pytanie' => $questionId, 'odpowiedz' => $answerT);
                 $id = $answer->insert($data);
             }
             echo '<br>';
         }
     }
     $this->view->pool = $pool->find($this->_getParam('ankieta'));
     $temp = $question->findAllWithAnkietaId($this->_getParam('ankieta'));
     $var = array();
     foreach ($temp as $row) {
         $where = $db->quoteInto('id_pytanie = ?', $row->idPytanie);
         $order = 'kolejnosc';
         $var[$row->idPytanie] = $variants->fetchAll($where, $order);
     }
     $this->view->questions = $temp;
     $this->view->variants = $var;
     $this->view->message = 'Dziękujemy za wypełnienie ankiety';
     $this->display();
 }
 /**
  * Ustala nową kolejność pytań
  */
 public function ajaxswapAction()
 {
     $post = new Zend_Filter_Input($_POST);
     $obj = new Hamster_JQuery_Sortables();
     $obj->setHash($post->getRaw('hash'));
     $list = $obj->getSortArray();
     $question = new Pytania();
     $ranking = 1;
     if (isset($list)) {
         foreach ($list as $question_id) {
             $row = $question->find($question_id);
             $row->kolejnosc = $ranking;
             $row->save();
             $ranking++;
         }
     }
 }
 /**
  * Akcja dla	:http://raport/tabelaryczny
  * i			:http://raport/tabelaryczny/ankieta/#id
  */
 public function tabelarycznyAction($excel = 0, $id_ankieta = 0)
 {
     $poll = new Ankiety();
     $db = $poll->getAdapter();
     if (!$excel) {
         $post = new Zend_Filter_Input($_POST);
         $pollId = $this->_getParam('ankieta');
         if (empty($pollId)) {
             $pollId = $post->getInt('ankieta_id');
         }
     } else {
         $pollId = $id_ankieta;
     }
     /*
     $pytanie=false;
     $queId=$this->_getParam('pytanie');
     if  (empty($queId)) $queId = $post->getInt('pytanie_id');
     if (!empty($queId)) {$this->view->queId=$queId; $pytanie=true;}
     */
     $this->view->pollId = $pollId;
     $this->view->pool = $poll->find($pollId);
     $question = new Pytania();
     $this->view->questions = $question->findAllWithAnkietaId($pollId);
     $this->view->qV = array('jednokrotne' => 0, 'wielokrotne' => 1, 'otwarte' => 2);
     $rap = new Raporty();
     $this->view->info = $rap->FindInformationsAboutAnkietaId($pollId);
     $this->view->fill = $rap->AmountOfFilledId($pollId);
     $this->view->ques = $rap->AmountOfQuestionsId($pollId);
     $this->view->body = $this->view->render('/raport/raportTabelaryczny.php');
     /*if ($pytanie) { 
      		$this->view->queInfo=$rap->InfoAboutQuestionId($queId);
      		if ($this->view->queInfo["nazwa_typu"]!='otwarte') {
      			$this->view->ansInfo=$rap->InfoAboutAnswersId($queId);
      			$this->view->body.=$this->view->render('/raport/PytZamkniete.php');
      		} else {
      			$this->view->ansInfo=$rap->AnswersOpened($queId);
      			$this->view->body.=$this->view->render('/raport/PytOtwarte.php');
      		}
      			
      	}
      	*/
     foreach ($this->view->questions as $row) {
         $queId = $row->idPytanie;
         $this->view->queInfo = $rap->InfoAboutQuestionId($queId);
         if ($this->view->queInfo["nazwa_typu"] != 'otwarte') {
             $this->view->ansInfo = $rap->InfoAboutAnswersId($queId);
             $ilResp = $rap->AmountOfRespondentsWhoAnsweredId($queId);
             $this->view->ilResp = $ilResp["ilresp"];
             $this->view->body .= $this->view->render('/raport/PytZamkniete.php');
         } else {
             $this->view->ansInfo = $rap->AnswersOpened($queId);
             $this->view->queId = $queId;
             $this->view->excel = $excel;
             $this->view->limit = 2;
             //tu decydujemy ile ma sie wyswietalc odpowiedzi otwartych
             $this->view->body .= $this->view->render('/raport/PytOtwarte.php');
             SaveToFile("/documents/raporty/OA_{$queId}.txt", $this->view->ansInfo);
         }
     }
     if (!$excel) {
         $this->display();
     } else {
         return $this->view->body;
     }
 }