/**
     * Action loads an IFrame for the email, when settings are set IFRAME and HTML
     * the template getIframeSuccess.php adds the needed fields to the iframe
     * @param sfWebRequest $request
     * @return <type>
     */

    public function executeGetIFrame(sfWebRequest $request) {
        sfLoader::loadHelpers('Url', 'I18N');
        $serverUrl  = str_replace('/layout', '', url_for('layout/index', true));
        $versionId = $request->getParameter('versionid');
        $templateId = $request->getParameter('workflowid');
        $userId = $request->getParameter('userid');
        $userSettings = new UserMailSettings($userId);
        $context = sfContext::getInstance();

        $sf_i18n = $context->getI18N();
        $sf_i18n->setCulture($userSettings->userSettings['language']);


        $this->linkto = $context->getI18N()->__('Direct link to workflow' ,null,'sendstationmail');
        

        $wfSettings = WorkflowVersionTable::instance()->getWorkflowVersionById($versionId);
        $workflow = $wfSettings[0]->getWorkflowTemplate()->toArray();

        $detailObj = new WorkflowDetail(false);
        $detailObj->setServerUrl($serverUrl);
        $detailObj->setCulture($userSettings->userSettings['language']);
        $detailObj->setContext($context);
        

        $editObj = new WorkflowEdit(false);
        $editObj->setServerUrl($serverUrl);
        $editObj->setContext($context);
        $editObj->setCulture($userSettings->userSettings['language']);
        $editObj->setUserId($userId);
        $this->slots = $editObj->buildSlots($wfSettings , $versionId);


        $content['workflow'][0] = $context->getI18N()->__('You have to fill out the fields in the workflow' ,null,'sendstationmail');
        $content['workflow'][1] = $workflow[0]['name'];
        $content['workflow'][2] = $context->getI18N()->__('Slot' ,null,'sendstationmail');
        $content['workflow'][3] = $context->getI18N()->__('Yes' ,null,'sendstationmail');
        $content['workflow'][4] = $context->getI18N()->__('No' ,null,'sendstationmail');
        $content['workflow'][5] = $context->getI18N()->__('Field' ,null,'sendstationmail');
        $content['workflow'][6] = $context->getI18N()->__('Value' ,null,'sendstationmail');
        $content['workflow'][7] = $context->getI18N()->__('File' ,null,'sendstationmail');
        $content['workflow'][8] = $context->getI18N()->__('Accept Workflow' ,null,'sendstationmail');
        $content['workflow'][9] = $context->getI18N()->__('Deny Workflow' ,null,'sendstationmail');
        $content['workflow'][10] = $context->getI18N()->__('Save' ,null,'sendstationmail');

        $this->error = $request->getParameter('error',0);
        $this->serverPath = $serverUrl;
        $this->workflowverion = $versionId;
        $this->userid  = $userId;
        $this->workflow  = $templateId;
        $this->text = $content;
	$this->setLayout(false);
	$this->setTemplate('getIFrame');
        return sfView::SUCCESS;
    }
    /**
     * Load all data, wich is needed to fill out an workflow
     * generalData like sender, creation date is loaded
     * slotData, all slots to fill out
     * workflowAttachment, load public attachments
     * userData: tree on left side, to show current process
     * showName: flag if users can be shown in the left side or not
     *
     * @param sfWebRequest $request
     * @return <type>
     */
    public function executeLoadWorkflowData(sfWebRequest $request) {
        sfLoader::loadHelpers('EndAction');
        $detailsObj = new WorkflowDetail();
        $detailsObj->setUser($this->getUser());
        $detailsObj->setCulture($this->getUser()->getCulture());
        $detailsObj->setContext($this->getContext());
        $workflowsettings = WorkflowVersionTable::instance()->getWorkflowVersionById($request->getParameter('versionid'));
        $generalData = $detailsObj->buildHeadLine($workflowsettings);
        $attachments = $detailsObj->buildAttachments($workflowsettings, $request->getParameter('versionid'));
        $userData = $detailsObj->buildUserData($workflowsettings, $request->getParameter('versionid'));
        $workflowDecission = WorkflowTemplateTable::instance()->getWorkflowTemplateById($workflowsettings[0]->getWorkflowtemplateId())->toArray();        
        $endAction = getEndAction($workflowDecission[0]['endaction']);

        $slotObj = new WorkflowEdit();
        $slotObj->setUser($this->getUser());
        $slotObj->setCulture($this->getUser()->getCulture());
        $slotObj->setContext($this->getContext());
        $slotData = $slotObj->buildSlots($workflowsettings, $request->getParameter('versionid'));
        
        $this->renderText('{"generalData":'.json_encode($generalData).',"slotData":'.json_encode($slotData).', "workflowAttachment" : '.json_encode($attachments).', "userData" : '.json_encode($userData).',"showName": '.$endAction[0].'}');
        return sfView::NONE;
    }
 private function getFields(WorkflowSlot $slot, $versionid) {
     $result = array();
     $a = 0;
     $fields = WorkflowSlotFieldTable::instance()->getWorkflowSlotFieldBySlotIdWithValues($slot->getId());
     $workflowDetail = new WorkflowDetail($this->helperFlag);
     $workflowDetail->setServerUrl($this->serverUrl);
     $column = 'LEFT';
     foreach($fields as $field) {
         $docField = $field->getField()->toArray();
         $result[$a]['workflowslotfield_id'] = $field->getId();
         $result[$a]['workflowslot_id'] = $field->getWorkflowslotId();
         $result[$a]['fieldname'] = $docField[0]['title'];
         $result[$a]['type'] = $docField[0]['type'];
         if($column == 'LEFT') {
             $column = 'RIGHT';
             $result[$a]['column'] = 'LEFT';
         }
         else {
             $column = 'LEFT';
             $result[$a]['column'] = 'RIGHT';
         }
         $result[$a]['writeprotected'] = $docField[0]['writeprotected'];
         $result[$a]['color'] = $docField[0]['color'];
         $result[$a]['items'] = $workflowDetail->getFieldItems($field,$docField[0]['type'], $this->context, $versionid);
         $a++;
         
     }
     return $result;
 }
    /**
     * Save the selected station from the popup
     *
     * @param sfWebRequest $request
     * @return <type>
     */
    public function executeSetNewStation(sfWebRequest $request) {
        sfLoader::loadHelpers('Url');
        $context = sfContext::getInstance();
        $context->getConfiguration()->loadHelpers('Partial', 'I18N', 'Url', 'Date', 'CalculateDate', 'ColorBuilder', 'Icon', 'EndAction');
        $calc = new SetStation($request->getParameter('versionid'),$request->getParameter('newworkflowuserslotid'), $request->getParameter('currentworkflowuserslotid'), $request->getParameter('direction'), $context, str_replace('/layout', '', url_for('layout/index',true)));


        $detailsObj = new WorkflowDetail();
        $detailsObj->setUser($this->getUser());
        $detailsObj->setCulture($this->getUser()->getCulture());
        $detailsObj->setContext($this->getContext());

        $workflowsettings = WorkflowVersionTable::instance()->getWorkflowVersionById($request->getParameter('versionid'));
        $userData = $detailsObj->buildUserData($workflowsettings, $request->getParameter('versionid'));
        $this->renderText('{"detailData" : '.json_encode($userData).'}');
        return sfView::NONE;
    }