<?php



/**
 * @copyright (c) Kufer Software GmbH, Loisachstrasse 4, D-84453 Mühldorf 
 */





class FeedbackMobilePageContainer extends DefaultMobilePageContainer{
  public function __construct($pTitle){
    parent::__construct($pTitle, TOOL_MOB_FEEDBACK);
    
    $toolsection = GetOperations::getVarValue('toolsection_id');
    
    if(SessionOperations::getUserID() === 0)
      $toolsection = 363;
      
    switch($toolsection) {
      default:
      case 362: 
				
                if (SecurityOperations::checkToolAccess(SessionOperations::getUserID(), TOOL_MOB_FEEDBACK, 362)) {
                  $objsettings = ToolSettingsAPI::getToolSettings( TOOL_MOB_FEEDBACK );
                  $title = trim( $objsettings->kursuebersicht_ueberschrift );
                  if( $title == '' ) {
                    $title = 'Teilnehmerumfrage starten';
                  }
                  $feedbackPage = new FeedbackMobilePage( $title );
                } else {
                  $feedbackPage = new HomeMobilePage();
                }
                
                $this->navBarLinks = $this->getMobileToolLinks($feedbackPage);
                if (sizeof($this->navBarLinks) > 1) {
                  $feedbackPage->addHomeButtonToHeader();
                }
                $feedbackPage->addLogoutButtonToHeader(); 
                break;
      case 363: 
                $feedbackPage = $this->handleFeedBackFormular();
                break;
    }
    $feedbackPage->body->content = $feedbackPage->getMobileHtml();

    $this->addPage($feedbackPage, false);
    
    if ($toolsection == 362 || $toolsection === "") {
      $feedbackPage->addNavBarToHeader();
    }
  }
  
  private function handleFeedBackFormular()
  {
    
    if(SessionOperations::getVarValueWTIntern('showNeustart','X') == 'X') {
      
      
      $dbwTools = new DBWorkTools();
      SessionOperations::setVarValueWTIntern('showNeustart', $dbwTools->privilegAllowed(SessionOperations::getUserID(),TOOL_MOB_FEEDBACK,'363.0.1'));
      SessionOperations::setVarValueWTIntern('showVorzeitigAbsenden', $dbwTools->privilegAllowed(SessionOperations::getUserID(),TOOL_MOB_FEEDBACK,'363.0.2'));
    }
    
    $action = GetOperations::getVarValue('action');
    
    if($action=='abbruch') { 
      $feedbackPage = new FeedbackAbbruchDialog();
    }
    else if($action=='abschicken') { 
      $feedbackPage = new FeedbackBeendenDialog();
    }
    else {
      if($action=='new') { 
        SessionOperations::setVarValueWTIntern('feedbackAntworten', '');
      }
      $feedbackPage = new FeedbackStartMobilePage();
      
      
      
      
      if(!SessionOperations::getVarValueWTIntern('feedback_bogenID', GetOperations::getVarValue('bogennr',  ($feedbackPage->getFeedbackBogenCount() < 2) ? true : false ))) {
        $href = 'index.php?tool_id=31&toolsection_id=362&';
        foreach($_GET as $param=>$value) {
        if($param != 'toolsection_id' && $param != 'tool_id' && $param != 'nr')
          $href .= $param.'='.$value.'&';
        }
        $href = rtrim($href, '&');
        $feedbackPage->addBackButtonToHeader($href);
      } else { 
        if( DBWorkBASysSettings::isChemnitz() ) {
          $befragungAbbrechenText = 'Dozent: abbrechen';
          $fragebogenAbsendenText = 'Dozent: absenden';
        } else {
          $befragungAbbrechenText = 'Befragung abbrechen';
          $fragebogenAbsendenText = 'Fragebogen absenden';
        }
        
        $feedbackPage->header->content .= '<a href="'.$_SERVER['REQUEST_URI'].'&action=abbruch" data-rel="dialog" data-icon="delete">' . $befragungAbbrechenText . '</a>';
        if(SessionOperations::getVarValueWTIntern('showVorzeitigAbsenden') == 2)
          $feedbackPage->header->content .= '<a href="'.$_SERVER['REQUEST_URI'].'&action=abschicken" data-rel="dialog" data-icon="check">' . $fragebogenAbsendenText . '</a>';
      }
    }
    return $feedbackPage;
  }
}
?>