コード例 #1
1
ファイル: responses.php プロジェクト: mfavetti/LimeSurvey
 /**
  * View a single response in detail
  *
  * @param mixed $iSurveyID
  * @param mixed $iId
  * @param mixed $sBrowseLang
  */
 public function view($iSurveyID, $iId, $sBrowseLang = '')
 {
     if (Permission::model()->hasSurveyPermission($iSurveyID, 'responses', 'read')) {
         $aData = $this->_getData(array('iId' => $iId, 'iSurveyId' => $iSurveyID, 'browselang' => $sBrowseLang));
         $sBrowseLanguage = $aData['language'];
         extract($aData);
         $aViewUrls = array();
         $fieldmap = createFieldMap($iSurveyID, 'full', false, false, $aData['language']);
         $bHaveToken = $aData['surveyinfo']['anonymized'] == "N" && tableExists('tokens_' . $iSurveyID);
         // Boolean : show (or not) the token
         if (!Permission::model()->hasSurveyPermission($iSurveyID, 'tokens', 'read')) {
             unset($fieldmap['token']);
             $bHaveToken = false;
         }
         //add token to top of list if survey is not private
         if ($bHaveToken) {
             $fnames[] = array("token", gT("Token ID"), 'code' => 'token');
             $fnames[] = array("firstname", gT("First name"), 'code' => 'firstname');
             // or token:firstname ?
             $fnames[] = array("lastname", gT("Last name"), 'code' => 'lastname');
             $fnames[] = array("email", gT("Email"), 'code' => 'email');
         }
         $fnames[] = array("submitdate", gT("Submission date"), gT("Completed"), "0", 'D', 'code' => 'submitdate');
         $fnames[] = array("completed", gT("Completed"), "0");
         foreach ($fieldmap as $field) {
             if ($field['fieldname'] == 'lastpage' || $field['fieldname'] == 'submitdate') {
                 continue;
             }
             if ($field['type'] == 'interview_time') {
                 continue;
             }
             if ($field['type'] == 'page_time') {
                 continue;
             }
             if ($field['type'] == 'answer_time') {
                 continue;
             }
             //$question = $field['question'];
             $question = viewHelper::getFieldText($field);
             if ($field['type'] != "|") {
                 $fnames[] = array($field['fieldname'], viewHelper::getFieldText($field), 'code' => viewHelper::getFieldCode($field, array('LEMcompat' => true)));
             } elseif ($field['aid'] !== 'filecount') {
                 $qidattributes = getQuestionAttributeValues($field['qid']);
                 for ($i = 0; $i < $qidattributes['max_num_of_files']; $i++) {
                     $filenum = sprintf(gT("File %s"), $i + 1);
                     if ($qidattributes['show_title'] == 1) {
                         $fnames[] = array($field['fieldname'], "{$filenum} - {$question} (" . gT('Title') . ")", 'code' => viewHelper::getFieldCode($field) . '(title)', "type" => "|", "metadata" => "title", "index" => $i);
                     }
                     if ($qidattributes['show_comment'] == 1) {
                         $fnames[] = array($field['fieldname'], "{$filenum} - {$question} (" . gT('Comment') . ")", 'code' => viewHelper::getFieldCode($field) . '(comment)', "type" => "|", "metadata" => "comment", "index" => $i);
                     }
                     $fnames[] = array($field['fieldname'], "{$filenum} - {$question} (" . gT('File name') . ")", 'code' => viewHelper::getFieldCode($field) . '(name)', "type" => "|", "metadata" => "name", "index" => $i);
                     $fnames[] = array($field['fieldname'], "{$filenum} - {$question} (" . gT('File size') . ")", 'code' => viewHelper::getFieldCode($field) . '(size)', "type" => "|", "metadata" => "size", "index" => $i);
                     //$fnames[] = array($field['fieldname'], "File ".($i+1)." - ".$field['question']." (extension)", "type"=>"|", "metadata"=>"ext",     "index"=>$i);
                 }
             } else {
                 $fnames[] = array($field['fieldname'], gT("File count"));
             }
         }
         $nfncount = count($fnames) - 1;
         if ($iId < 1) {
             $iId = 1;
         }
         $exist = SurveyDynamic::model($iSurveyID)->exist($iId);
         $next = SurveyDynamic::model($iSurveyID)->next($iId, true);
         $previous = SurveyDynamic::model($iSurveyID)->previous($iId, true);
         $aData['exist'] = $exist;
         $aData['next'] = $next;
         $aData['previous'] = $previous;
         $aData['id'] = $iId;
         $aViewUrls[] = 'browseidheader_view';
         if ($exist) {
             $oPurifier = new CHtmlPurifier();
             //SHOW INDIVIDUAL RECORD
             $oCriteria = new CDbCriteria();
             if ($bHaveToken) {
                 $oCriteria = SurveyDynamic::model($iSurveyID)->addTokenCriteria($oCriteria);
             }
             $oCriteria->addCondition("id = {$iId}");
             $iIdresult = SurveyDynamic::model($iSurveyID)->findAllAsArray($oCriteria);
             foreach ($iIdresult as $iIdrow) {
                 $iId = $iIdrow['id'];
                 $rlanguage = $iIdrow['startlanguage'];
             }
             $aData['bHasFile'] = false;
             if (isset($rlanguage)) {
                 $aData['rlanguage'] = $rlanguage;
             }
             foreach ($iIdresult as $iIdrow) {
                 $highlight = false;
                 for ($i = 0; $i < $nfncount + 1; $i++) {
                     if ($fnames[$i][0] != 'completed' && is_null($iIdrow[$fnames[$i][0]])) {
                         continue;
                         // irrelevant, so don't show
                     }
                     $inserthighlight = '';
                     if ($highlight) {
                         $inserthighlight = "class='highlight'";
                     }
                     if ($fnames[$i][0] == 'completed') {
                         if ($iIdrow['submitdate'] == NULL || $iIdrow['submitdate'] == "N") {
                             $answervalue = "N";
                         } else {
                             $answervalue = "Y";
                         }
                     } else {
                         if (isset($fnames[$i]['type']) && $fnames[$i]['type'] == "|") {
                             $index = $fnames[$i]['index'];
                             $metadata = $fnames[$i]['metadata'];
                             $phparray = json_decode_ls($iIdrow[$fnames[$i][0]]);
                             if (isset($phparray[$index])) {
                                 switch ($metadata) {
                                     case "size":
                                         $answervalue = sprintf(gT("%s KB"), intval($phparray[$index][$metadata]));
                                         break;
                                     case "name":
                                         $answervalue = CHtml::link($oPurifier->purify(rawurldecode($phparray[$index][$metadata])), $this->getController()->createUrl("/admin/responses", array("sa" => "actionDownloadfile", "surveyid" => $surveyid, "iResponseId" => $iId, "sFileName" => $phparray[$index][$metadata])));
                                         break;
                                     default:
                                         $answervalue = htmlspecialchars(strip_tags(stripJavaScript($phparray[$index][$metadata])));
                                 }
                                 $aData['bHasFile'] = true;
                             } else {
                                 $answervalue = "";
                             }
                         } else {
                             $answervalue = htmlspecialchars(strip_tags(stripJavaScript(getExtendedAnswer($iSurveyID, $fnames[$i][0], $iIdrow[$fnames[$i][0]], $sBrowseLanguage))), ENT_QUOTES);
                         }
                     }
                     $aData['answervalue'] = $answervalue;
                     $aData['inserthighlight'] = $inserthighlight;
                     $aData['fnames'] = $fnames;
                     $aData['i'] = $i;
                     $aViewUrls['browseidrow_view'][] = $aData;
                 }
             }
         } else {
             Yii::app()->session['flashmessage'] = gT("This response ID is invalid.");
         }
         $aViewUrls[] = 'browseidfooter_view';
         $aData['sidemenu']['state'] = false;
         $aData['menu']['edition'] = true;
         $aData['menu']['view'] = true;
         $aData['menu']['close'] = true;
         // This resets the url on the close button to go to the upper view
         $aData['menu']['closeurl'] = $this->getController()->createUrl("admin/responses/sa/browse/surveyid/" . $iSurveyId);
         $this->_renderWrappedTemplate('', $aViewUrls, $aData);
     } else {
         $aData = array();
         $aData['surveyid'] = $iSurveyID;
         $message = array();
         $message['title'] = gT('Access denied!');
         $message['message'] = gT('You do not have permission to access this page.');
         $message['class'] = "error";
         $this->_renderWrappedTemplate('survey', array("message" => $message), $aData);
     }
 }
コード例 #2
0
ファイル: welcome.php プロジェクト: mfavetti/LimeSurvey
                <?php 
    }
    ?>

                <?php 
    if ($showLastQuestion) {
        ?>
                    <span id="last_question" class="rotateHidden">
                    <?php 
        eT("Last visited question:");
        ?>
                    <a href="<?php 
        echo $last_question_link;
        ?>
" class=""><?php 
        echo viewHelper::flatEllipsizeText($last_question_name, true, 60);
        ?>
</a>
                    </span>
                <?php 
    }
    ?>
                </div>
                <br/><br/>
            </div>
        </div>
    <?php 
}
?>

    <!-- Rendering all boxes in database -->
コード例 #3
0
ファイル: apply_form.php プロジェクト: sea75300/affiliat_r
print utf8_decode($antiSpamQuestion);
?>
                    </td>
                </tr>    
                <tr>
                    <td class="afltr-public-label"></td>
                    <td class="afltr-public-content">
                        <input type="text" class="afltr-public-input-text" name="antiSpamAnswer" size="25" maxlength="255" value="<?php 
print $value;
?>
">
                    </td>
                </tr>                   
                <tr>
                    <td colspan="2" class="afltr-public-button-line">
                        <?php 
viewHelper::submitButton('submsave', language::returnLanguageConstant('AFFILIATE_PUB_SUBMIT'), $isNotUtf8);
?>
                        <?php 
viewHelper::resetButton('subreset', $isNotUtf8);
?>
                    </td>
                </tr>
            </table>
    </div>
</form>

<!-- Powered by Affiliat*r <?php 
print $systemVersion;
?>
 - http://nobody-knows.org/download/affiliatr/ -->
コード例 #4
0
 function index($subaction, $iSurveyID = null, $gid = null, $qid = null)
 {
     $iSurveyID = sanitize_int($iSurveyID);
     $gid = sanitize_int($gid);
     $qid = sanitize_int($qid);
     $imageurl = Yii::app()->getConfig("adminimageurl");
     Yii::app()->loadHelper("database");
     $aData['sidemenu']['state'] = false;
     $surveyinfo = Survey::model()->findByPk($iSurveyID)->surveyinfo;
     $aData['title_bar']['title'] = $surveyinfo['surveyls_title'] . "(" . gT("ID") . ":" . $iSurveyID . ")";
     $aData['questionbar']['closebutton']['url'] = 'admin/questions/sa/view/surveyid/' . $iSurveyID . '/gid/' . $gid . '/qid/' . $qid;
     // Close button
     $aData['questionbar']['buttons']['conditions'] = TRUE;
     switch ($subaction) {
         case 'editconditionsform':
             $aData['questionbar']['buttons']['condition']['edit'] = TRUE;
             break;
         case 'conditions':
             $aData['questionbar']['buttons']['condition']['conditions'] = TRUE;
             break;
         case 'copyconditionsform':
             $aData['questionbar']['buttons']['condition']['copyconditionsform'] = TRUE;
             break;
         default:
             $aData['questionbar']['buttons']['condition']['edit'] = TRUE;
             break;
     }
     if (!empty($_POST['subaction'])) {
         $subaction = Yii::app()->request->getPost('subaction');
     }
     //BEGIN Sanitizing POSTed data
     if (!isset($iSurveyID)) {
         $iSurveyID = returnGlobal('sid');
     }
     if (!isset($qid)) {
         $qid = returnGlobal('qid');
     }
     if (!isset($gid)) {
         $gid = returnGlobal('gid');
     }
     if (!isset($p_scenario)) {
         $p_scenario = returnGlobal('scenario');
     }
     if (!isset($p_cqid)) {
         $p_cqid = returnGlobal('cqid');
         if ($p_cqid == '') {
             $p_cqid = 0;
         }
         // we are not using another question as source of condition
     }
     if (!isset($p_cid)) {
         $p_cid = returnGlobal('cid');
     }
     if (!isset($p_subaction)) {
         if (isset($_POST['subaction'])) {
             $p_subaction = $_POST['subaction'];
         } else {
             $p_subaction = $subaction;
         }
     }
     if (!isset($p_cquestions)) {
         $p_cquestions = returnGlobal('cquestions');
     }
     if (!isset($p_csrctoken)) {
         $p_csrctoken = returnGlobal('csrctoken');
     }
     if (!isset($p_prevquestionsgqa)) {
         $p_prevquestionsgqa = returnGlobal('prevQuestionSGQA');
     }
     if (!isset($p_canswers)) {
         if (isset($_POST['canswers']) && is_array($_POST['canswers'])) {
             foreach ($_POST['canswers'] as $key => $val) {
                 $p_canswers[$key] = preg_replace("/[^_.a-zA-Z0-9]@/", "", $val);
             }
         }
     }
     // this array will be used soon,
     // to explain wich conditions is used to evaluate the question
     if (Yii::app()->getConfig('stringcomparizonoperators') == 1) {
         $method = array("<" => gT("Less than"), "<=" => gT("Less than or equal to"), "==" => gT("Equals"), "!=" => gT("Not equal to"), ">=" => gT("Greater than or equal to"), ">" => gT("Greater than"), "RX" => gT("Regular expression"), "a<b" => gT("Less than (Strings)"), "a<=b" => gT("Less than or equal to (Strings)"), "a>=b" => gT("Greater than or equal to (Strings)"), "a>b" => gT("Greater than (Strings)"));
     } else {
         $method = array("<" => gT("Less than"), "<=" => gT("Less than or equal to"), "==" => gT("equals"), "!=" => gT("Not equal to"), ">=" => gT("Greater than or equal to"), ">" => gT("Greater than"), "RX" => gT("Regular expression"));
     }
     if (isset($_POST['method'])) {
         if (!in_array($_POST['method'], array_keys($method))) {
             $p_method = "==";
         } else {
             $p_method = trim($_POST['method']);
         }
     }
     if (isset($_POST['newscenarionum'])) {
         $p_newscenarionum = sanitize_int($_POST['newscenarionum']);
     }
     //END Sanitizing POSTed data
     //include_once("login_check.php");
     include_once "database.php";
     // Caution (lemeur): database.php uses autoUnescape on all entries in $_POST
     // Take care to not use autoUnescape on $_POST variables after this
     $br = CHtml::openTag('br /');
     //MAKE SURE THAT THERE IS A SID
     if (!isset($iSurveyID) || !$iSurveyID) {
         $conditionsoutput = gT("You have not selected a survey") . str_repeat($br, 2);
         $conditionsoutput .= CHtml::submitButton(gT("Main admin screen", 'unescaped'), array('onclick' => "window.open('" . $this->getController()->createUrl("admin/") . "', '_top')")) . $br;
         safeDie($conditionsoutput);
         return;
     }
     if (isset($p_subaction) && $p_subaction == "resetsurveylogic") {
         $resetsurveylogicoutput = $br;
         $resetsurveylogicoutput .= CHtml::openTag('table', array('class' => 'alertbox'));
         $resetsurveylogicoutput .= CHtml::openTag('tr') . CHtml::openTag('td', array('colspan' => '2'));
         $resetsurveylogicoutput .= CHtml::tag('font', array('size' => '1'), CHtml::tag('strong', array(), gT("Reset Survey Logic")));
         $resetsurveylogicoutput .= CHtml::closeTag('td') . CHtml::closeTag('tr');
         if (!isset($_GET['ok'])) {
             $button_yes = CHtml::submitButton(gT("Yes", 'unescaped'), array('onclick' => "window.open('" . $this->getController()->createUrl("admin/conditions/sa/index/subaction/resetsurveylogic/surveyid/{$iSurveyID}") . "?ok=Y" . "', '_top')"));
             $button_cancel = CHtml::submitButton(gT("Cancel", 'unescaped'), array('onclick' => "window.open('" . $this->getController()->createUrl("admin/survey/sa/view/surveyid/{$iSurveyID}") . "', '_top')"));
             $messagebox_content = gT("You are about to delete all conditions on this survey's questions") . "({$iSurveyID})" . $br . gT("We recommend that before you proceed, you export the entire survey from the main administration screen.") . $br . gT("Continue?") . $br . $button_yes . $button_cancel;
             $this->_renderWrappedTemplate('conditions', array('message' => array('title' => gT("Warning"), 'message' => $messagebox_content)));
             exit;
         } else {
             LimeExpressionManager::RevertUpgradeConditionsToRelevance($iSurveyID);
             Condition::model()->deleteRecords("qid in (select qid from {{questions}} where sid={$iSurveyID})");
             Yii::app()->setFlashMessage(gT("All conditions in this survey have been deleted."));
             $this->getController()->redirect(array('admin/survey/sa/view/surveyid/' . $iSurveyID));
         }
     }
     // MAKE SURE THAT THERE IS A QID
     if (!isset($qid) || !$qid) {
         $conditionsoutput = gT("You have not selected a question") . str_repeat($br, 2);
         $conditionsoutput .= CHtml::submitButton(gT("Main admin screen", 'unescaped'), array('onclick' => "window.open('" . $this->getController()->createUrl("admin/") . "', '_top')")) . $br;
         safeDie($conditionsoutput);
         return;
     }
     // If we made it this far, then lets develop the menu items
     // add the conditions container table
     $extraGetParams = "";
     if (isset($qid) && isset($gid)) {
         $extraGetParams = "/gid/{$gid}/qid/{$qid}";
     }
     $conditionsoutput_action_error = "";
     // defined during the actions
     $markcidarray = array();
     if (isset($_GET['markcid'])) {
         $markcidarray = explode("-", $_GET['markcid']);
     }
     //BEGIN PROCESS ACTIONS
     // ADD NEW ENTRY IF THIS IS AN ADD
     if (isset($p_subaction) && $p_subaction == "insertcondition") {
         if (!isset($p_canswers) && !isset($_POST['ConditionConst']) && !isset($_POST['prevQuestionSGQA']) && !isset($_POST['tokenAttr']) && !isset($_POST['ConditionRegexp']) || !isset($p_cquestions) && !isset($p_csrctoken)) {
             $conditionsoutput_action_error .= CHtml::script("\n<!--\n alert(\"" . gT("Your condition could not be added! It did not include the question and/or answer upon which the condition was based. Please ensure you have selected a question and an answer.", "js") . "\")\n //-->\n");
         } else {
             if (isset($p_cquestions) && $p_cquestions != '') {
                 $conditionCfieldname = $p_cquestions;
             } elseif (isset($p_csrctoken) && $p_csrctoken != '') {
                 $conditionCfieldname = $p_csrctoken;
             }
             $condition_data = array('qid' => $qid, 'scenario' => $p_scenario, 'cqid' => $p_cqid, 'cfieldname' => $conditionCfieldname, 'method' => $p_method);
             if (isset($p_canswers)) {
                 foreach ($p_canswers as $ca) {
                     //First lets make sure there isn't already an exact replica of this condition
                     $condition_data['value'] = $ca;
                     $result = Condition::model()->findAllByAttributes($condition_data);
                     $count_caseinsensitivedupes = count($result);
                     if ($count_caseinsensitivedupes == 0) {
                         $result = Condition::model()->insertRecords($condition_data);
                     }
                 }
             }
             unset($posted_condition_value);
             // Please note that autoUnescape is already applied in database.php included above
             // so we only need to db_quote _POST variables
             if (isset($_POST['ConditionConst']) && isset($_POST['editTargetTab']) && $_POST['editTargetTab'] == "#CONST") {
                 $posted_condition_value = Yii::app()->request->getPost('ConditionConst');
             } elseif (isset($_POST['prevQuestionSGQA']) && isset($_POST['editTargetTab']) && $_POST['editTargetTab'] == "#PREVQUESTIONS") {
                 $posted_condition_value = Yii::app()->request->getPost('prevQuestionSGQA');
             } elseif (isset($_POST['tokenAttr']) && isset($_POST['editTargetTab']) && $_POST['editTargetTab'] == "#TOKENATTRS") {
                 $posted_condition_value = Yii::app()->request->getPost('tokenAttr');
             } elseif (isset($_POST['ConditionRegexp']) && isset($_POST['editTargetTab']) && $_POST['editTargetTab'] == "#REGEXP") {
                 $posted_condition_value = Yii::app()->request->getPost('ConditionRegexp');
             }
             if (isset($posted_condition_value)) {
                 $condition_data['value'] = $posted_condition_value;
                 $result = Condition::model()->insertRecords($condition_data);
             }
         }
         LimeExpressionManager::UpgradeConditionsToRelevance(NULL, $qid);
     }
     // UPDATE ENTRY IF THIS IS AN EDIT
     if (isset($p_subaction) && $p_subaction == "updatecondition") {
         if (!isset($p_canswers) && !isset($_POST['ConditionConst']) && !isset($_POST['prevQuestionSGQA']) && !isset($_POST['tokenAttr']) && !isset($_POST['ConditionRegexp']) || !isset($p_cquestions) && !isset($p_csrctoken)) {
             $conditionsoutput_action_error .= CHtml::script("\n<!--\n alert(\"" . gT("Your condition could not be added! It did not include the question and/or answer upon which the condition was based. Please ensure you have selected a question and an answer.", "js") . "\")\n //-->\n");
         } else {
             if (isset($p_cquestions) && $p_cquestions != '') {
                 $conditionCfieldname = $p_cquestions;
             } elseif (isset($p_csrctoken) && $p_csrctoken != '') {
                 $conditionCfieldname = $p_csrctoken;
             }
             if (isset($p_canswers)) {
                 foreach ($p_canswers as $ca) {
                     // This is an Edit, there will only be ONE VALUE
                     $updated_data = array('qid' => $qid, 'scenario' => $p_scenario, 'cqid' => $p_cqid, 'cfieldname' => $conditionCfieldname, 'method' => $p_method, 'value' => $ca);
                     $result = Condition::model()->insertRecords($updated_data, TRUE, array('cid' => $p_cid));
                 }
             }
             unset($posted_condition_value);
             // Please note that autoUnescape is already applied in database.php included above
             // so we only need to db_quote _POST variables
             if (isset($_POST['ConditionConst']) && isset($_POST['editTargetTab']) && $_POST['editTargetTab'] == "#CONST") {
                 $posted_condition_value = Yii::app()->request->getPost('ConditionConst');
             } elseif (isset($_POST['prevQuestionSGQA']) && isset($_POST['editTargetTab']) && $_POST['editTargetTab'] == "#PREVQUESTIONS") {
                 $posted_condition_value = Yii::app()->request->getPost('prevQuestionSGQA');
             } elseif (isset($_POST['tokenAttr']) && isset($_POST['editTargetTab']) && $_POST['editTargetTab'] == "#TOKENATTRS") {
                 $posted_condition_value = Yii::app()->request->getPost('tokenAttr');
             } elseif (isset($_POST['ConditionRegexp']) && isset($_POST['editTargetTab']) && $_POST['editTargetTab'] == "#REGEXP") {
                 $posted_condition_value = Yii::app()->request->getPost('ConditionRegexp');
             }
             if (isset($posted_condition_value)) {
                 $updated_data = array('qid' => $qid, 'scenario' => $p_scenario, 'cqid' => $p_cqid, 'cfieldname' => $conditionCfieldname, 'method' => $p_method, 'value' => $posted_condition_value);
                 $result = Condition::model()->insertRecords($updated_data, TRUE, array('cid' => $p_cid));
             }
         }
         LimeExpressionManager::UpgradeConditionsToRelevance(NULL, $qid);
     }
     // DELETE ENTRY IF THIS IS DELETE
     if (isset($p_subaction) && $p_subaction == "delete") {
         LimeExpressionManager::RevertUpgradeConditionsToRelevance(NULL, $qid);
         // in case deleted the last condition
         $result = Condition::model()->deleteRecords(array('cid' => $p_cid));
         LimeExpressionManager::UpgradeConditionsToRelevance(NULL, $qid);
     }
     // DELETE ALL CONDITIONS IN THIS SCENARIO
     if (isset($p_subaction) && $p_subaction == "deletescenario") {
         LimeExpressionManager::RevertUpgradeConditionsToRelevance(NULL, $qid);
         // in case deleted the last condition
         $result = Condition::model()->deleteRecords(array('qid' => $qid, 'scenario' => $p_scenario));
         LimeExpressionManager::UpgradeConditionsToRelevance(NULL, $qid);
     }
     // UPDATE SCENARIO
     if (isset($p_subaction) && $p_subaction == "updatescenario" && isset($p_newscenarionum)) {
         $result = Condition::model()->insertRecords(array('scenario' => $p_newscenarionum), TRUE, array('qid' => $qid, 'scenario' => $p_scenario));
         LimeExpressionManager::UpgradeConditionsToRelevance(NULL, $qid);
     }
     // DELETE ALL CONDITIONS FOR THIS QUESTION
     if (isset($p_subaction) && $p_subaction == "deleteallconditions") {
         LimeExpressionManager::RevertUpgradeConditionsToRelevance(NULL, $qid);
         // in case deleted the last condition
         $result = Condition::model()->deleteRecords(array('qid' => $qid));
     }
     // RENUMBER SCENARIOS
     if (isset($p_subaction) && $p_subaction == "renumberscenarios") {
         $query = "SELECT DISTINCT scenario FROM {{conditions}} WHERE qid=:qid ORDER BY scenario";
         $result = Yii::app()->db->createCommand($query)->bindParam(":qid", $qid, PDO::PARAM_INT)->query() or safeDie("Couldn't select scenario<br />{$query}<br />");
         $newindex = 1;
         foreach ($result->readAll() as $srow) {
             // new var $update_result == old var $result2
             $update_result = Condition::model()->insertRecords(array('scenario' => $newindex), TRUE, array('qid' => $qid, 'scenario' => $srow['scenario']));
             $newindex++;
         }
         LimeExpressionManager::UpgradeConditionsToRelevance(NULL, $qid);
         Yii::app()->setFlashMessage(gT("All conditions scenarios were renumbered."));
     }
     // COPY CONDITIONS IF THIS IS COPY
     if (isset($p_subaction) && $p_subaction == "copyconditions") {
         $qid = returnGlobal('qid');
         $copyconditionsfrom = returnGlobal('copyconditionsfrom');
         $copyconditionsto = returnGlobal('copyconditionsto');
         if (isset($copyconditionsto) && is_array($copyconditionsto) && isset($copyconditionsfrom) && is_array($copyconditionsfrom)) {
             //Get the conditions we are going to copy
             foreach ($copyconditionsfrom as &$entry) {
                 $entry = Yii::app()->db->quoteValue($entry);
             }
             $query = "SELECT * FROM {{conditions}}\n" . "WHERE cid in (";
             $query .= implode(", ", $copyconditionsfrom);
             $query .= ")";
             $result = Yii::app()->db->createCommand($query)->query() or safeDie("Couldn't get conditions for copy<br />{$query}<br />");
             foreach ($result->readAll() as $row) {
                 $proformaconditions[] = array("scenario" => $row['scenario'], "cqid" => $row['cqid'], "cfieldname" => $row['cfieldname'], "method" => $row['method'], "value" => $row['value']);
             }
             // while
             foreach ($copyconditionsto as $copyc) {
                 list($newsid, $newgid, $newqid) = explode("X", $copyc);
                 foreach ($proformaconditions as $pfc) {
                     //TIBO
                     //First lets make sure there isn't already an exact replica of this condition
                     $conditions_data = array('qid' => $newqid, 'scenario' => $pfc['scenario'], 'cqid' => $pfc['cqid'], 'cfieldname' => $pfc['cfieldname'], 'method' => $pfc['method'], 'value' => $pfc['value']);
                     $result = Condition::model()->findAllByAttributes($conditions_data);
                     $count_caseinsensitivedupes = count($result);
                     $countduplicates = 0;
                     if ($count_caseinsensitivedupes != 0) {
                         foreach ($result as $ccrow) {
                             if ($ccrow['value'] == $pfc['value']) {
                                 $countduplicates++;
                             }
                         }
                     }
                     if ($countduplicates == 0) {
                         $result = Condition::model()->insertRecords($conditions_data);
                         $conditionCopied = true;
                     } else {
                         $conditionDuplicated = true;
                     }
                 }
             }
             if (isset($conditionCopied) && $conditionCopied === true) {
                 if (isset($conditionDuplicated) && $conditionDuplicated == true) {
                     $CopyConditionsMessage = CHtml::tag('div', array('class' => 'partialheader'), '(' . gT("Condition successfully copied (some were skipped because they were duplicates)") . ')');
                     Yii::app()->setFlashMessage(gT("Condition successfully copied (some were skipped because they were duplicates)"), 'warning');
                 } else {
                     $CopyConditionsMessage = CHtml::tag('div', array('class' => 'successheader'), '(' . gT("Condition successfully copied") . ')');
                     Yii::app()->setFlashMessage(gT("Condition successfully copied"));
                 }
             } else {
                 $CopyConditionsMessage = CHtml::tag('div', array('class' => 'warningheader'), '(' . gT("No conditions could be copied (due to duplicates)") . ')');
                 Yii::app()->setFlashMessage(gT("No conditions could be copied (due to duplicates)"), 'error');
             }
         }
         LimeExpressionManager::UpgradeConditionsToRelevance($iSurveyID);
         // do for whole survey, since don't know which questions affected.
     }
     //END PROCESS ACTIONS
     $cquestions = array();
     $canswers = array();
     //BEGIN: GATHER INFORMATION
     // 1: Get information for this question
     // @todo : use viewHelper::getFieldText and getFieldCode for 2.06 for string show to user
     if (!isset($qid)) {
         $qid = returnGlobal('qid');
     }
     if (!isset($iSurveyID)) {
         $iSurveyID = returnGlobal('sid');
     }
     $thissurvey = getSurveyInfo($iSurveyID);
     $qresult = Question::model()->with('groups')->findByAttributes(array('qid' => $qid, 'parent_qid' => 0, 'language' => Survey::model()->findByPk($iSurveyID)->language));
     $questiongroupname = $qresult->groups->group_name;
     $questiontitle = $qresult['title'];
     $sCurrentFullQuestionText = $qresult['question'];
     $questiontype = $qresult['type'];
     // 2: Get all other questions that occur before this question that are pre-determined answer types
     // To avoid natural sort order issues,
     // first get all questions in natural sort order
     // , and find out which number in that order this question is
     $qresult = Question::model()->with(array('groups' => array('condition' => 'groups.language = :lang', 'params' => array(':lang' => Survey::model()->findByPk($iSurveyID)->language))))->findAllByAttributes(array('parent_qid' => 0, 'sid' => $iSurveyID, 'language' => Survey::model()->findByPk($iSurveyID)->language));
     $qrows = array();
     foreach ($qresult as $k => $v) {
         $qrows[$k] = array_merge($v->attributes, $v->groups->attributes);
     }
     // Perform a case insensitive natural sort on group name then question title (known as "code" in the form) of a multidimensional array
     usort($qrows, 'groupOrderThenQuestionOrder');
     $position = "before";
     // Go through each question until we reach the current one
     foreach ($qrows as $qrow) {
         if ($qrow["qid"] != $qid && $position == "before") {
             // remember all previous questions
             // all question types are supported.
             $questionlist[] = $qrow["qid"];
         } elseif ($qrow["qid"] == $qid) {
             break;
         }
     }
     // Now, using the same array which is now properly sorted by group then question
     // Create an array of all the questions that appear AFTER the current one
     $position = "before";
     foreach ($qrows as $qrow) {
         if ($qrow["qid"] == $qid) {
             $position = "after";
             //break;
         } elseif ($qrow["qid"] != $qid && $position == "after") {
             $postquestionlist[] = $qrow['qid'];
         }
     }
     $theserows = array();
     $postrows = array();
     if (isset($questionlist) && is_array($questionlist)) {
         foreach ($questionlist as $ql) {
             $result = Question::model()->with(array('groups' => array('condition' => 'groups.language = :lang', 'params' => array(':lang' => Survey::model()->findByPk($iSurveyID)->language))))->findAllByAttributes(array('qid' => $ql, 'parent_qid' => 0, 'sid' => $iSurveyID, 'language' => Survey::model()->findByPk($iSurveyID)->language));
             $thiscount = count($result);
             // And store again these questions in this array...
             foreach ($result as $myrows) {
                 //key => value
                 $theserows[] = array("qid" => $myrows['qid'], "sid" => $myrows['sid'], "gid" => $myrows['gid'], "question" => $myrows['question'], "type" => $myrows['type'], "mandatory" => $myrows['mandatory'], "other" => $myrows['other'], "title" => $myrows['title']);
             }
         }
     }
     if (isset($postquestionlist) && is_array($postquestionlist)) {
         foreach ($postquestionlist as $pq) {
             $result = Question::model()->with(array('groups' => array('condition' => 'groups.language = :lang', 'params' => array(':lang' => Survey::model()->findByPk($iSurveyID)->language))))->findAllByAttributes(array('qid' => $pq, 'parent_qid' => 0, 'sid' => $iSurveyID, 'language' => Survey::model()->findByPk($iSurveyID)->language));
             $postcount = count($result);
             foreach ($result as $myrows) {
                 $postrows[] = array("qid" => $myrows['qid'], "sid" => $myrows['sid'], "gid" => $myrows['gid'], "question" => $myrows['question'], "type" => $myrows['type'], "mandatory" => $myrows['mandatory'], "other" => $myrows['other'], "title" => $myrows['title']);
             }
             // while
         }
         $postquestionscount = count($postrows);
     }
     $questionscount = count($theserows);
     if (isset($postquestionscount) && $postquestionscount > 0) {
         //Build the array used for the questionNav and copyTo select boxes
         foreach ($postrows as $pr) {
             $pquestions[] = array("text" => $pr['title'] . ": " . substr(strip_tags($pr['question']), 0, 80), "fieldname" => $pr['sid'] . "X" . $pr['gid'] . "X" . $pr['qid']);
         }
     }
     // Previous question parsing ==> building cquestions[] and canswers[]
     if ($questionscount > 0) {
         $X = "X";
         foreach ($theserows as $rows) {
             $shortquestion = $rows['title'] . ": " . strip_tags($rows['question']);
             if ($rows['type'] == "A" || $rows['type'] == "B" || $rows['type'] == "C" || $rows['type'] == "E" || $rows['type'] == "F" || $rows['type'] == "H") {
                 $aresult = Question::model()->findAllByAttributes(array('parent_qid' => $rows['qid'], 'language' => Survey::model()->findByPk($iSurveyID)->language), array('order' => 'question_order ASC'));
                 foreach ($aresult as $arows) {
                     $shortanswer = "{$arows['title']}: [" . flattenText($arows['question']) . "]";
                     $shortquestion = $rows['title'] . ":{$shortanswer} " . flattenText($rows['question']);
                     $cquestions[] = array($shortquestion, $rows['qid'], $rows['type'], $rows['sid'] . $X . $rows['gid'] . $X . $rows['qid'] . $arows['title']);
                     switch ($rows['type']) {
                         case "A":
                             //Array 5 buttons
                             for ($i = 1; $i <= 5; $i++) {
                                 $canswers[] = array($rows['sid'] . $X . $rows['gid'] . $X . $rows['qid'] . $arows['title'], $i, $i);
                             }
                             break;
                         case "B":
                             //Array 10 buttons
                             for ($i = 1; $i <= 10; $i++) {
                                 $canswers[] = array($rows['sid'] . $X . $rows['gid'] . $X . $rows['qid'] . $arows['title'], $i, $i);
                             }
                             break;
                         case "C":
                             //Array Y/N/NA
                             $canswers[] = array($rows['sid'] . $X . $rows['gid'] . $X . $rows['qid'] . $arows['title'], "Y", gT("Yes"));
                             $canswers[] = array($rows['sid'] . $X . $rows['gid'] . $X . $rows['qid'] . $arows['title'], "U", gT("Uncertain"));
                             $canswers[] = array($rows['sid'] . $X . $rows['gid'] . $X . $rows['qid'] . $arows['title'], "N", gT("No"));
                             break;
                         case "E":
                             //Array >/=/<
                             $canswers[] = array($rows['sid'] . $X . $rows['gid'] . $X . $rows['qid'] . $arows['title'], "I", gT("Increase"));
                             $canswers[] = array($rows['sid'] . $X . $rows['gid'] . $X . $rows['qid'] . $arows['title'], "S", gT("Same"));
                             $canswers[] = array($rows['sid'] . $X . $rows['gid'] . $X . $rows['qid'] . $arows['title'], "D", gT("Decrease"));
                             break;
                         case "F":
                             //Array Flexible Row
                         //Array Flexible Row
                         case "H":
                             //Array Flexible Column
                             $fresult = Answer::model()->findAllByAttributes(array('qid' => $rows['qid'], "language" => Survey::model()->findByPk($iSurveyID)->language, 'scale_id' => 0), array('order' => 'sortorder, code'));
                             foreach ($fresult as $frow) {
                                 $canswers[] = array($rows['sid'] . $X . $rows['gid'] . $X . $rows['qid'] . $arows['title'], $frow['code'], $frow['answer']);
                             }
                             break;
                     }
                     // Only Show No-Answer if question is not mandatory
                     if ($rows['mandatory'] != 'Y') {
                         $canswers[] = array($rows['sid'] . $X . $rows['gid'] . $X . $rows['qid'] . $arows['title'], "", gT("No answer"));
                     }
                 }
                 //while
             } elseif ($rows['type'] == ":" || $rows['type'] == ";") {
                 // Multiflexi
                 // Get the Y-Axis
                 $fquery = "SELECT sq.*, q.other" . " FROM {{questions sq}}, {{questions q}}" . " WHERE sq.sid={$iSurveyID} AND sq.parent_qid=q.qid " . "AND q.language=:lang1" . " AND sq.language=:lang2" . " AND q.qid=:qid\n                    AND sq.scale_id=0\n                    ORDER BY sq.question_order";
                 $sLanguage = Survey::model()->findByPk($iSurveyID)->language;
                 $y_axis_db = Yii::app()->db->createCommand($fquery)->bindParam(":lang1", $sLanguage, PDO::PARAM_STR)->bindParam(":lang2", $sLanguage, PDO::PARAM_STR)->bindParam(":qid", $rows['qid'], PDO::PARAM_INT)->query();
                 // Get the X-Axis
                 $aquery = "SELECT sq.*\n                    FROM {{questions q}}, {{questions sq}}\n                    WHERE q.sid={$iSurveyID}\n                    AND sq.parent_qid=q.qid\n                    AND q.language=:lang1\n                    AND sq.language=:lang2\n                    AND q.qid=:qid\n                    AND sq.scale_id=1\n                    ORDER BY sq.question_order";
                 $x_axis_db = Yii::app()->db->createCommand($aquery)->bindParam(":lang1", $sLanguage, PDO::PARAM_STR)->bindParam(":lang2", $sLanguage, PDO::PARAM_STR)->bindParam(":qid", $rows['qid'], PDO::PARAM_INT)->query() or safeDie("Couldn't get answers to Array questions<br />{$aquery}<br />");
                 foreach ($x_axis_db->readAll() as $frow) {
                     $x_axis[$frow['title']] = $frow['question'];
                 }
                 foreach ($y_axis_db->readAll() as $yrow) {
                     foreach ($x_axis as $key => $val) {
                         $shortquestion = $rows['title'] . ":{$yrow['title']}:{$key}: [" . strip_tags($yrow['question']) . "][" . strip_tags($val) . "] " . flattenText($rows['question']);
                         $cquestions[] = array($shortquestion, $rows['qid'], $rows['type'], $rows['sid'] . $X . $rows['gid'] . $X . $rows['qid'] . $yrow['title'] . "_" . $key);
                         if ($rows['mandatory'] != 'Y') {
                             $canswers[] = array($rows['sid'] . $X . $rows['gid'] . $X . $rows['qid'] . $yrow['title'] . "_" . $key, "", gT("No answer"));
                         }
                     }
                 }
                 unset($x_axis);
             } elseif ($rows['type'] == "1") {
                 $aresult = Question::model()->findAllByAttributes(array('parent_qid' => $rows['qid'], 'language' => Survey::model()->findByPk($iSurveyID)->language), array('order' => 'question_order desc'));
                 foreach ($aresult as $arows) {
                     $attr = getQuestionAttributeValues($rows['qid']);
                     $sLanguage = Survey::model()->findByPk($iSurveyID)->language;
                     // dualscale_header are allways set, but can be empty
                     $label1 = empty($attr['dualscale_headerA'][$sLanguage]) ? gT('Scale 1') : $attr['dualscale_headerA'][$sLanguage];
                     $label2 = empty($attr['dualscale_headerB'][$sLanguage]) ? gT('Scale 2') : $attr['dualscale_headerB'][$sLanguage];
                     $shortanswer = "{$arows['title']}: [" . strip_tags($arows['question']) . "][{$label1}]";
                     $shortquestion = $rows['title'] . ":{$shortanswer} " . strip_tags($rows['question']);
                     $cquestions[] = array($shortquestion, $rows['qid'], $rows['type'], $rows['sid'] . $X . $rows['gid'] . $X . $rows['qid'] . $arows['title'] . "#0");
                     $shortanswer = "{$arows['title']}: [" . strip_tags($arows['question']) . "][{$label2}]";
                     $shortquestion = $rows['title'] . ":{$shortanswer} " . strip_tags($rows['question']);
                     $cquestions[] = array($shortquestion, $rows['qid'], $rows['type'], $rows['sid'] . $X . $rows['gid'] . $X . $rows['qid'] . $arows['title'] . "#1");
                     // first label
                     $lresult = Answer::model()->findAllByAttributes(array('qid' => $rows['qid'], 'scale_id' => 0, 'language' => Survey::model()->findByPk($iSurveyID)->language), array('order' => 'sortorder, answer'));
                     foreach ($lresult as $lrows) {
                         $canswers[] = array($rows['sid'] . $X . $rows['gid'] . $X . $rows['qid'] . $arows['title'] . "#0", "{$lrows['code']}", "{$lrows['code']}");
                     }
                     // second label
                     $lresult = Answer::model()->findAllByAttributes(array('qid' => $rows['qid'], 'scale_id' => 1, 'language' => Survey::model()->findByPk($iSurveyID)->language), array('order' => 'sortorder, answer'));
                     foreach ($lresult as $lrows) {
                         $canswers[] = array($rows['sid'] . $X . $rows['gid'] . $X . $rows['qid'] . $arows['title'] . "#1", "{$lrows['code']}", "{$lrows['code']}");
                     }
                     // Only Show No-Answer if question is not mandatory
                     if ($rows['mandatory'] != 'Y') {
                         $canswers[] = array($rows['sid'] . $X . $rows['gid'] . $X . $rows['qid'] . $arows['title'] . "#0", "", gT("No answer"));
                         $canswers[] = array($rows['sid'] . $X . $rows['gid'] . $X . $rows['qid'] . $arows['title'] . "#1", "", gT("No answer"));
                     }
                 }
                 //while
             } elseif ($rows['type'] == "K" || $rows['type'] == "Q") {
                 $aresult = Question::model()->findAllByAttributes(array("parent_qid" => $rows['qid'], "language" => Survey::model()->findByPk($iSurveyID)->language), array('order' => 'question_order desc'));
                 foreach ($aresult as $arows) {
                     $shortanswer = "{$arows['title']}: [" . strip_tags($arows['question']) . "]";
                     $shortquestion = $rows['title'] . ":{$shortanswer} " . strip_tags($rows['question']);
                     $cquestions[] = array($shortquestion, $rows['qid'], $rows['type'], $rows['sid'] . $X . $rows['gid'] . $X . $rows['qid'] . $arows['title']);
                     // Only Show No-Answer if question is not mandatory
                     if ($rows['mandatory'] != 'Y') {
                         $canswers[] = array($rows['sid'] . $X . $rows['gid'] . $X . $rows['qid'] . $arows['title'], "", gT("No answer"));
                     }
                 }
                 //while
             } elseif ($rows['type'] == "R") {
                 $aresult = Answer::model()->findAllByAttributes(array("qid" => $rows['qid'], "scale_id" => 0, "language" => Survey::model()->findByPk($iSurveyID)->language), array('order' => 'sortorder, answer'));
                 $acount = count($aresult);
                 foreach ($aresult as $arow) {
                     $theanswer = addcslashes($arow['answer'], "'");
                     $quicky[] = array($arow['code'], $theanswer);
                 }
                 for ($i = 1; $i <= $acount; $i++) {
                     $cquestions[] = array("{$rows['title']}: [RANK {$i}] " . strip_tags($rows['question']), $rows['qid'], $rows['type'], $rows['sid'] . $X . $rows['gid'] . $X . $rows['qid'] . $i);
                     foreach ($quicky as $qck) {
                         $canswers[] = array($rows['sid'] . $X . $rows['gid'] . $X . $rows['qid'] . $i, $qck[0], $qck[1]);
                     }
                     // Only Show No-Answer if question is not mandatory
                     if ($rows['mandatory'] != 'Y') {
                         $canswers[] = array($rows['sid'] . $X . $rows['gid'] . $X . $rows['qid'] . $i, " ", gT("No answer"));
                     }
                 }
                 unset($quicky);
             } elseif ($rows['type'] == "M" || $rows['type'] == "P") {
                 $shortanswer = " [" . gT("Group of checkboxes") . "]";
                 $shortquestion = $rows['title'] . ":{$shortanswer} " . strip_tags($rows['question']);
                 $cquestions[] = array($shortquestion, $rows['qid'], $rows['type'], $rows['sid'] . $X . $rows['gid'] . $X . $rows['qid']);
                 $aresult = Question::model()->findAllByAttributes(array("parent_qid" => $rows['qid'], "language" => Survey::model()->findByPk($iSurveyID)->language), array('order' => 'question_order desc'));
                 foreach ($aresult as $arows) {
                     $theanswer = addcslashes($arows['question'], "'");
                     $canswers[] = array($rows['sid'] . $X . $rows['gid'] . $X . $rows['qid'], $arows['title'], $theanswer);
                     $shortanswer = "{$arows['title']}: [" . strip_tags($arows['question']) . "]";
                     $shortanswer .= "[" . gT("Single checkbox") . "]";
                     $shortquestion = $rows['title'] . ":{$shortanswer} " . strip_tags($rows['question']);
                     $cquestions[] = array($shortquestion, $rows['qid'], $rows['type'], "+" . $rows['sid'] . $X . $rows['gid'] . $X . $rows['qid'] . $arows['title']);
                     $canswers[] = array("+" . $rows['sid'] . $X . $rows['gid'] . $X . $rows['qid'] . $arows['title'], 'Y', gT("checked"));
                     $canswers[] = array("+" . $rows['sid'] . $X . $rows['gid'] . $X . $rows['qid'] . $arows['title'], '', gT("not checked"));
                 }
             } elseif ($rows['type'] == "X") {
                 //Just ignore this questiontype
             } else {
                 $cquestions[] = array($shortquestion, $rows['qid'], $rows['type'], $rows['sid'] . $X . $rows['gid'] . $X . $rows['qid']);
                 switch ($rows['type']) {
                     case "Y":
                         // Y/N/NA
                         $canswers[] = array($rows['sid'] . $X . $rows['gid'] . $X . $rows['qid'], "Y", gT("Yes"));
                         $canswers[] = array($rows['sid'] . $X . $rows['gid'] . $X . $rows['qid'], "N", gT("No"));
                         // Only Show No-Answer if question is not mandatory
                         if ($rows['mandatory'] != 'Y') {
                             $canswers[] = array($rows['sid'] . $X . $rows['gid'] . $X . $rows['qid'], " ", gT("No answer"));
                         }
                         break;
                     case "G":
                         //Gender
                         $canswers[] = array($rows['sid'] . $X . $rows['gid'] . $X . $rows['qid'], "F", gT("Female"));
                         $canswers[] = array($rows['sid'] . $X . $rows['gid'] . $X . $rows['qid'], "M", gT("Male"));
                         // Only Show No-Answer if question is not mandatory
                         if ($rows['mandatory'] != 'Y') {
                             $canswers[] = array($rows['sid'] . $X . $rows['gid'] . $X . $rows['qid'], " ", gT("No answer"));
                         }
                         break;
                     case "5":
                         // 5 choice
                         for ($i = 1; $i <= 5; $i++) {
                             $canswers[] = array($rows['sid'] . $X . $rows['gid'] . $X . $rows['qid'], $i, $i);
                         }
                         // Only Show No-Answer if question is not mandatory
                         if ($rows['mandatory'] != 'Y') {
                             $canswers[] = array($rows['sid'] . $X . $rows['gid'] . $X . $rows['qid'], " ", gT("No answer"));
                         }
                         break;
                     case "N":
                         // Simple Numerical questions
                         // Only Show No-Answer if question is not mandatory
                         if ($rows['mandatory'] != 'Y') {
                             $canswers[] = array($rows['sid'] . $X . $rows['gid'] . $X . $rows['qid'], " ", gT("No answer"));
                         }
                         break;
                     default:
                         $aresult = Answer::model()->findAllByAttributes(array('qid' => $rows['qid'], 'scale_id' => 0, 'language' => Survey::model()->findByPk($iSurveyID)->language), array('order' => 'sortorder, answer'));
                         foreach ($aresult as $arows) {
                             $theanswer = addcslashes($arows['answer'], "'");
                             $canswers[] = array($rows['sid'] . $X . $rows['gid'] . $X . $rows['qid'], $arows['code'], $theanswer);
                         }
                         if ($rows['type'] == "D") {
                             // Only Show No-Answer if question is not mandatory
                             if ($rows['mandatory'] != 'Y') {
                                 $canswers[] = array($rows['sid'] . $X . $rows['gid'] . $X . $rows['qid'], " ", gT("No answer"));
                             }
                         } elseif ($rows['type'] != "M" && $rows['type'] != "P" && $rows['type'] != "J" && $rows['type'] != "I") {
                             // For dropdown questions
                             // optinnaly add the 'Other' answer
                             if (($rows['type'] == "L" || $rows['type'] == "!") && $rows['other'] == "Y") {
                                 $canswers[] = array($rows['sid'] . $X . $rows['gid'] . $X . $rows['qid'], "-oth-", gT("Other"));
                             }
                             // Only Show No-Answer if question is not mandatory
                             if ($rows['mandatory'] != 'Y') {
                                 $canswers[] = array($rows['sid'] . $X . $rows['gid'] . $X . $rows['qid'], " ", gT("No answer"));
                             }
                         }
                         break;
                 }
                 //switch row type
             }
             //else
         }
         //foreach theserows
     }
     //if questionscount > 0
     //END Gather Information for this question
     $questionNavOptions = CHtml::openTag('optgroup', array('class' => 'activesurveyselect', 'label' => gT("Before", "js")));
     foreach ($theserows as $row) {
         $question = $row['question'];
         $question = strip_tags($question);
         $questionselecter = viewHelper::flatEllipsizeText($question, true, '40');
         $questionNavOptions .= CHtml::tag('option', array('value' => $this->getController()->createUrl("/admin/conditions/sa/index/subaction/editconditionsform/surveyid/{$iSurveyID}/gid/{$row['gid']}/qid/{$row['qid']}")), strip_tags($row['title']) . ':' . $questionselecter);
     }
     $questionNavOptions .= CHtml::closeTag('optgroup');
     $questionNavOptions .= CHtml::openTag('optgroup', array('class' => 'activesurveyselect', 'label' => gT("Current", "js")));
     $question = strip_tags($sCurrentFullQuestionText);
     $questiontextshort = viewHelper::flatEllipsizeText($question, true, '40');
     $questionNavOptions .= CHtml::tag('option', array('value' => $this->getController()->createUrl("/admin/conditions/sa/index/subaction/editconditionsform/surveyid/{$iSurveyID}/gid/{$gid}/qid/{$qid}"), 'selected' => 'selected'), $questiontitle . ': ' . $questiontextshort);
     $questionNavOptions .= CHtml::closeTag('optgroup');
     $questionNavOptions .= CHtml::openTag('optgroup', array('class' => 'activesurveyselect', 'label' => gT("After", "js")));
     foreach ($postrows as $row) {
         $question = $row['question'];
         $question = strip_tags($question);
         $questionselecter = viewHelper::flatEllipsizeText($question, true, '40');
         $questionNavOptions .= CHtml::tag('option', array('value' => $this->getController()->createUrl("/admin/conditions/sa/index/subaction/editconditionsform/surveyid/{$iSurveyID}/gid/{$row['gid']}/qid/{$row['qid']}")), strip_tags($row['title']) . ':' . $questionselecter);
     }
     $questionNavOptions .= CHtml::closeTag('optgroup');
     //Now display the information and forms
     //BEGIN: PREPARE JAVASCRIPT TO SHOW MATCHING ANSWERS TO SELECTED QUESTION
     $javascriptpre = CHtml::openTag('script', array('type' => 'text/javascript')) . "<!--\n" . "\tvar Fieldnames = new Array();\n" . "\tvar Codes = new Array();\n" . "\tvar Answers = new Array();\n" . "\tvar QFieldnames = new Array();\n" . "\tvar Qcqids = new Array();\n" . "\tvar Qtypes = new Array();\n";
     $jn = 0;
     if (isset($canswers)) {
         foreach ($canswers as $can) {
             $an = ls_json_encode(flattenText($can[2]));
             $javascriptpre .= "Fieldnames[{$jn}]='{$can[0]}';\n" . "Codes[{$jn}]='{$can[1]}';\n" . "Answers[{$jn}]={$an};\n";
             $jn++;
         }
     }
     $jn = 0;
     if (isset($cquestions)) {
         foreach ($cquestions as $cqn) {
             $javascriptpre .= "QFieldnames[{$jn}]='{$cqn['3']}';\n" . "Qcqids[{$jn}]='{$cqn['1']}';\n" . "Qtypes[{$jn}]='{$cqn['2']}';\n";
             $jn++;
         }
     }
     //  record a JS variable to let jQuery know if survey is Anonymous
     if ($thissurvey['anonymized'] == 'Y') {
         $javascriptpre .= "isAnonymousSurvey = true;";
     } else {
         $javascriptpre .= "isAnonymousSurvey = false;";
     }
     $javascriptpre .= "//-->\n" . CHtml::closeTag('script');
     //END: PREPARE JAVASCRIPT TO SHOW MATCHING ANSWERS TO SELECTED QUESTION
     $aViewUrls = array();
     $oQuestion = Question::model()->find('qid=:qid', array(':qid' => $qid));
     $aData['oQuestion'] = $oQuestion;
     $aData['surveyid'] = $iSurveyID;
     $aData['qid'] = $qid;
     $aData['gid'] = $gid;
     $aData['imageurl'] = $imageurl;
     $aData['extraGetParams'] = $extraGetParams;
     $aData['questionNavOptions'] = $questionNavOptions;
     $aData['conditionsoutput_action_error'] = $conditionsoutput_action_error;
     $aData['javascriptpre'] = $javascriptpre;
     $aViewUrls['conditionshead_view'][] = $aData;
     //BEGIN DISPLAY CONDITIONS FOR THIS QUESTION
     if ($subaction == 'index' || $subaction == 'editconditionsform' || $subaction == 'insertcondition' || $subaction == "editthiscondition" || $subaction == "delete" || $subaction == "updatecondition" || $subaction == "deletescenario" || $subaction == "renumberscenarios" || $subaction == "deleteallconditions" || $subaction == "updatescenario" || $subaction == 'copyconditionsform' || $subaction == 'copyconditions' || $subaction == 'conditions') {
         //3: Get other conditions currently set for this question
         $conditionscount = 0;
         $conditionsList = array();
         $s = 0;
         $criteria = new CDbCriteria();
         $criteria->select = 'scenario';
         // only select the 'scenario' column
         $criteria->condition = 'qid=:qid';
         $criteria->params = array(':qid' => $qid);
         $criteria->order = 'scenario';
         $criteria->group = 'scenario';
         $scenarioresult = Condition::model()->findAll($criteria);
         $scenariocount = count($scenarioresult);
         $aData['conditionsoutput'] = '';
         $aData['extraGetParams'] = $extraGetParams;
         $aData['questionNavOptions'] = $questionNavOptions;
         $aData['conditionsoutput_action_error'] = $conditionsoutput_action_error;
         $aData['javascriptpre'] = $javascriptpre;
         $aData['onlyshow'] = sprintf(gT("Only show question %s IF"), $questiontitle . ': ' . $sCurrentFullQuestionText);
         $aData['sCurrentQuestionText'] = $questiontitle . ': ' . viewHelper::flatEllipsizeText($sCurrentFullQuestionText, true, '120');
         $aData['subaction'] = $subaction;
         $aData['scenariocount'] = $scenariocount;
         $aViewUrls['conditionslist_view'][] = $aData;
         if ($scenariocount > 0) {
             $this->registerScriptFile('ADMIN_SCRIPT_PATH', 'checkgroup.js');
             foreach ($scenarioresult as $scenarionr) {
                 $scenariotext = "";
                 if ($s == 0 && $scenariocount > 1) {
                     $scenariotext = " -------- <i>Scenario {$scenarionr['scenario']}</i> --------";
                 }
                 if ($s > 0) {
                     $scenariotext = " -------- <i>" . gT("OR") . " Scenario {$scenarionr['scenario']}</i> --------";
                 }
                 if ($subaction == "copyconditionsform" || $subaction == "copyconditions") {
                     $initialCheckbox = "<td><input type='checkbox' id='scenarioCbx{$scenarionr['scenario']}' checked='checked'/>\n" . "<script type='text/javascript'>\$(document).ready(function () { \$('#scenarioCbx{$scenarionr['scenario']}').checkgroup({ groupName:'aConditionFromScenario{$scenarionr['scenario']}'}); });</script>" . "</td><td>&nbsp;</td>\n";
                 } else {
                     $initialCheckbox = "";
                 }
                 if ($scenariotext != "" && ($subaction == "editconditionsform" || $subaction == "insertcondition" || $subaction == "updatecondition" || $subaction == "editthiscondition" || $subaction == "renumberscenarios" || $subaction == "updatescenario" || $subaction == "deletescenario" || $subaction == "delete")) {
                     $img_tag = '<span class="glyphicon glyphicon-trash"></span>';
                     $additional_main_content = CHtml::link($img_tag, '#', array('onclick' => "if ( confirm('" . gT("Are you sure you want to delete all conditions set in this scenario?", "js") . "')) { document.getElementById('deletescenario{$scenarionr['scenario']}').submit();}"));
                     $img_tag = '<span class="glyphicon glyphicon-pencil"></span>';
                     $additional_main_content .= CHtml::link($img_tag, '#', array('id' => 'editscenariobtn' . $scenarionr['scenario'], 'onclick' => "\$('#editscenario{$scenarionr['scenario']}').toggle('slow');"));
                     $aData['additional_content'] = $additional_main_content;
                 }
                 $aData['initialCheckbox'] = $initialCheckbox;
                 $aData['scenariotext'] = $scenariotext;
                 $aData['scenarionr'] = $scenarionr;
                 if (!isset($aViewUrls['output'])) {
                     $aViewUrls['output'] = '';
                 }
                 $aViewUrls['output'] .= $this->getController()->renderPartial('/admin/conditions/includes/conditions_scenario', $aData, TRUE);
                 unset($currentfield);
                 $query = "SELECT count(*) as recordcount\n                    FROM {{conditions}} c, {{questions}} q, {{groups}} g\n                    WHERE c.cqid=q.qid " . "AND q.gid=g.gid " . "AND q.parent_qid=0 " . "AND q.language=:lang1 " . "AND g.language=:lang2 " . "AND c.qid=:qid " . "AND c.scenario=:scenario " . "AND c.cfieldname NOT LIKE '{%' ";
                 // avoid catching SRCtokenAttr conditions
                 $sLanguage = Survey::model()->findByPk($iSurveyID)->language;
                 $result = Yii::app()->db->createCommand($query)->bindValue(":scenario", $scenarionr['scenario'])->bindValue(":qid", $qid, PDO::PARAM_INT)->bindValue(":lang1", $sLanguage, PDO::PARAM_STR)->bindValue(":lang2", $sLanguage, PDO::PARAM_STR)->queryRow();
                 $conditionscount = (int) $result['recordcount'];
                 $query = "SELECT c.cid, c.scenario, c.cqid, c.cfieldname, c.method, c.value, q.type\n                    FROM {{conditions}} c, {{questions}} q, {{groups}} g\n                    WHERE c.cqid=q.qid " . "AND q.gid=g.gid " . "AND q.parent_qid=0 " . "AND q.language=:lang1 " . "AND g.language=:lang2 " . "AND c.qid=:qid " . "AND c.scenario=:scenario " . "AND c.cfieldname NOT LIKE '{%' " . "ORDER BY g.group_order, q.question_order, c.cfieldname";
                 $sLanguage = Survey::model()->findByPk($iSurveyID)->language;
                 $result2 = Yii::app()->db->createCommand($query)->bindValue(":scenario", $scenarionr['scenario'])->bindValue(":qid", $qid, PDO::PARAM_INT)->bindValue(":lang1", $sLanguage, PDO::PARAM_STR)->bindValue(":lang2", $sLanguage, PDO::PARAM_STR)->query() or safeDie("Couldn't get other conditions for question {$qid}<br />{$query}<br />");
                 $result2 = $result2->readAll();
                 $querytoken = "SELECT count(*) as recordcount " . "FROM {{conditions}} " . "WHERE " . " {{conditions}}.qid=:qid " . "AND {{conditions}}.scenario=:scenario " . "AND {{conditions}}.cfieldname LIKE '{%' ";
                 // only catching SRCtokenAttr conditions
                 $resulttoken = Yii::app()->db->createCommand($querytoken)->bindValue(":scenario", $scenarionr['scenario'], PDO::PARAM_INT)->bindValue(":qid", $qid, PDO::PARAM_INT)->queryRow() or safeDie("Couldn't get other conditions for question {$qid}<br />{$query}<br />");
                 $conditionscounttoken = (int) $resulttoken['recordcount'];
                 $querytoken = "SELECT {{conditions}}.cid, " . "{{conditions}}.scenario, " . "{{conditions}}.cqid, " . "{{conditions}}.cfieldname, " . "{{conditions}}.method, " . "{{conditions}}.value, " . "'' AS type " . "FROM {{conditions}} " . "WHERE " . " {{conditions}}.qid=:qid " . "AND {{conditions}}.scenario=:scenario " . "AND {{conditions}}.cfieldname LIKE '{%' " . "ORDER BY {{conditions}}.cfieldname";
                 $resulttoken = Yii::app()->db->createCommand($querytoken)->bindValue(":scenario", $scenarionr['scenario'], PDO::PARAM_INT)->bindValue(":qid", $qid, PDO::PARAM_INT)->query() or safeDie("Couldn't get other conditions for question {$qid}<br />{$query}<br />");
                 $conditionscount = $conditionscount + $conditionscounttoken;
                 ////////////////// BUILD CONDITIONS DISPLAY
                 if ($conditionscount > 0) {
                     $aConditionsMerged = array();
                     foreach ($resulttoken->readAll() as $arow) {
                         $aConditionsMerged[] = $arow;
                     }
                     foreach ($result2 as $arow) {
                         $aConditionsMerged[] = $arow;
                     }
                     foreach ($aConditionsMerged as $rows) {
                         if ($rows['method'] == "") {
                             $rows['method'] = "==";
                         }
                         //Fill in the empty method from previous versions
                         $markcidstyle = "oddrow";
                         if (array_search($rows['cid'], $markcidarray) !== FALSE) {
                             // This is the style used when the condition editor is called
                             // in order to check which conditions prevent a question deletion
                             $markcidstyle = "markedrow";
                         }
                         if ($subaction == "editthiscondition" && isset($p_cid) && $rows['cid'] === $p_cid) {
                             // Style used when editing a condition
                             $markcidstyle = "editedrow";
                         }
                         if (isset($currentfield) && $currentfield != $rows['cfieldname']) {
                             $aViewUrls['output'] .= "<tr class='evenrow'>\n" . "\t<td colspan='2' class='operator'>\n" . gT("and") . "</td></tr>";
                         } elseif (isset($currentfield)) {
                             $aViewUrls['output'] .= "<tr class='evenrow'>\n" . "\t<td colspan='2' class='operator'>\n" . gT("or") . "</td></tr>";
                         }
                         $aViewUrls['output'] .= "\t<tr class='{$markcidstyle}'>\n" . "\t<td colspan='2'>" . CHtml::form(array("/admin/conditions/sa/index/subaction/{$subaction}/surveyid/{$iSurveyID}/gid/{$gid}/qid/{$qid}/"), 'post', array('id' => "conditionaction{$rows['cid']}", 'name' => "conditionaction{$rows['cid']}")) . "<table class='table' id='conditionstable'>\n" . "\t<tr class='active'>\n";
                         if ($subaction == "copyconditionsform" || $subaction == "copyconditions") {
                             $aViewUrls['output'] .= "<td>&nbsp;&nbsp;</td>" . "<td class='scenariotd'>\n" . "\t<input type='checkbox' name='aConditionFromScenario{$scenarionr['scenario']}' id='cbox{$rows['cid']}' value='{$rows['cid']}' checked='checked'/>\n" . "</td>\n";
                         }
                         $aViewUrls['output'] .= "" . "<td class='col-md-4' id='questionnamecol'>\n" . "\t<span>\n";
                         $leftOperandType = 'unknown';
                         // prevquestion, tokenattr
                         if ($thissurvey['anonymized'] != 'Y' && preg_match('/^{TOKEN:([^}]*)}$/', $rows['cfieldname'], $extractedTokenAttr) > 0) {
                             $leftOperandType = 'tokenattr';
                             $aTokenAttrNames = getTokenFieldsAndNames($iSurveyID);
                             if (isset($aTokenAttrNames[strtolower($extractedTokenAttr[1])])) {
                                 $thisAttrName = HTMLEscape($aTokenAttrNames[strtolower($extractedTokenAttr[1])]['description']);
                             } else {
                                 $thisAttrName = HTMLEscape($extractedTokenAttr[1]);
                             }
                             if (tableExists("{{tokens_{$iSurveyID}}}")) {
                                 $thisAttrName .= " [" . gT("From token table") . "]";
                             } else {
                                 $thisAttrName .= " [" . gT("Inexistant token table") . "]";
                             }
                             $aViewUrls['output'] .= "\t{$thisAttrName}\n";
                             // TIBO not sure this is used anymore !!
                             $conditionsList[] = array("cid" => $rows['cid'], "text" => $thisAttrName);
                         } else {
                             $leftOperandType = 'prevquestion';
                             foreach ($cquestions as $cqn) {
                                 if ($cqn[3] == $rows['cfieldname']) {
                                     $aViewUrls['output'] .= "\t{$cqn['0']} (qid{$rows['cqid']})\n";
                                     $conditionsList[] = array("cid" => $rows['cid'], "text" => $cqn[0] . " ({$rows['value']})");
                                 } else {
                                     //$aViewUrls['output'] .= "\t<font color='red'>ERROR: Delete this condition. It is out of order.</font>\n";
                                 }
                             }
                         }
                         $aViewUrls['output'] .= "\t</span></td>\n" . "\t<td class='col-md-2' id='operatornametd'>\n" . "<span>\n" . $method[trim($rows['method'])] . "</span>\n" . "\t</td>\n" . "\n" . "\t<td class='col-md-3' id='questionanswertd'>\n" . "<span>\n";
                         // let's read the condition's right operand
                         // determine its type and display it
                         $rightOperandType = 'unknown';
                         // predefinedAnsw,constantVal, prevQsgqa, tokenAttr, regexp
                         if ($rows['method'] == 'RX') {
                             $rightOperandType = 'regexp';
                             $aViewUrls['output'] .= "" . HTMLEscape($rows['value']) . "\n";
                         } elseif (preg_match('/^@([0-9]+X[0-9]+X[^@]*)@$/', $rows['value'], $matchedSGQA) > 0) {
                             // SGQA
                             $rightOperandType = 'prevQsgqa';
                             $textfound = false;
                             foreach ($cquestions as $cqn) {
                                 if ($cqn[3] == $matchedSGQA[1]) {
                                     $matchedSGQAText = $cqn[0];
                                     $textfound = true;
                                     break;
                                 }
                             }
                             if ($textfound === false) {
                                 $matchedSGQAText = $rows['value'] . ' (' . gT("Not found") . ')';
                             }
                             $aViewUrls['output'] .= "" . HTMLEscape($matchedSGQAText) . "\n";
                         } elseif ($thissurvey['anonymized'] != 'Y' && preg_match('/^{TOKEN:([^}]*)}$/', $rows['value'], $extractedTokenAttr) > 0) {
                             $rightOperandType = 'tokenAttr';
                             $aTokenAttrNames = getTokenFieldsAndNames($iSurveyID);
                             if (count($aTokenAttrNames) != 0) {
                                 $thisAttrName = HTMLEscape($aTokenAttrNames[strtolower($extractedTokenAttr[1])]['description']) . " [" . gT("From token table") . "]";
                             } else {
                                 $thisAttrName = HTMLEscape($extractedTokenAttr[1]) . " [" . gT("Inexistant token table") . "]";
                             }
                             $aViewUrls['output'] .= "\t{$thisAttrName}\n";
                         } elseif (isset($canswers)) {
                             foreach ($canswers as $can) {
                                 if ($can[0] == $rows['cfieldname'] && $can[1] == $rows['value']) {
                                     $aViewUrls['output'] .= "{$can['2']} ({$can['1']})\n";
                                     $rightOperandType = 'predefinedAnsw';
                                 }
                             }
                         }
                         // if $rightOperandType is still unknown then it is a simple constant
                         if ($rightOperandType == 'unknown') {
                             $rightOperandType = 'constantVal';
                             if ($rows['value'] == ' ' || $rows['value'] == '') {
                                 $aViewUrls['output'] .= "" . gT("No answer") . "\n";
                             } else {
                                 $aViewUrls['output'] .= "" . HTMLEscape($rows['value']) . "\n";
                             }
                         }
                         $aViewUrls['output'] .= "\t</span></td>\n" . "\t<td class='text-right'>\n";
                         if ($subaction == "editconditionsform" || $subaction == "insertcondition" || $subaction == "updatecondition" || $subaction == "editthiscondition" || $subaction == "renumberscenarios" || $subaction == "deleteallconditions" || $subaction == "updatescenario" || $subaction == "deletescenario" || $subaction == "delete") {
                             // show single condition action buttons in edit mode
                             $aData['rows'] = $rows;
                             $aData['sImageURL'] = Yii::app()->getConfig('adminimageurl');
                             //$aViewUrls['includes/conditions_edit'][] = $aData;
                             $aViewUrls['output'] .= $this->getController()->renderPartial('/admin/conditions/includes/conditions_edit', $aData, TRUE);
                             // now sets e corresponding hidden input field
                             // depending on the leftOperandType
                             if ($leftOperandType == 'tokenattr') {
                                 $aViewUrls['output'] .= CHtml::hiddenField('csrctoken', HTMLEscape($rows['cfieldname']), array('id' => 'csrctoken' . $rows['cid']));
                             } else {
                                 $aViewUrls['output'] .= CHtml::hiddenField('cquestions', HTMLEscape($rows['cfieldname']), array('id' => 'cquestions' . $rows['cid']));
                             }
                             // now set the corresponding hidden input field
                             // depending on the rightOperandType
                             // This is used when editing a condition
                             if ($rightOperandType == 'predefinedAnsw') {
                                 $aViewUrls['output'] .= CHtml::hiddenField('EDITcanswers[]', HTMLEscape($rows['value']), array('id' => 'editModeTargetVal' . $rows['cid']));
                             } elseif ($rightOperandType == 'prevQsgqa') {
                                 $aViewUrls['output'] .= CHtml::hiddenField('EDITprevQuestionSGQA', HTMLEscape($rows['value']), array('id' => 'editModeTargetVal' . $rows['cid']));
                             } elseif ($rightOperandType == 'tokenAttr') {
                                 $aViewUrls['output'] .= CHtml::hiddenField('EDITtokenAttr', HTMLEscape($rows['value']), array('id' => 'editModeTargetVal' . $rows['cid']));
                             } elseif ($rightOperandType == 'regexp') {
                                 $aViewUrls['output'] .= CHtml::hiddenField('EDITConditionRegexp', HTMLEscape($rows['value']), array('id' => 'editModeTargetVal' . $rows['cid']));
                             } else {
                                 $aViewUrls['output'] .= CHtml::hiddenField('EDITConditionConst', HTMLEscape($rows['value']), array('id' => 'editModeTargetVal' . $rows['cid']));
                             }
                         }
                         $aViewUrls['output'] .= CHtml::closeTag('td') . CHtml::closeTag('tr') . CHtml::closeTag('table') . CHtml::closeTag('form') . CHtml::closeTag('td') . CHtml::closeTag('tr');
                         $currentfield = $rows['cfieldname'];
                     }
                 }
                 $s++;
             }
             // If we have a condition, allways reset the condition, this can fix old import (see #09344)
             LimeExpressionManager::UpgradeConditionsToRelevance(NULL, $qid);
         } else {
             // no condition ==> disable delete all conditions button, and display a simple comment
             // no_conditions
             $aViewUrls['output'] = $this->getController()->renderPartial('/admin/conditions/no_condition', $aData, true);
         }
         $aViewUrls['output'] .= CHtml::closeTag('table');
         //// To close the div opened in condition header....  see : https://goo.gl/BY7gUJ
         $aViewUrls['afteroutput'] = '</div></div></div>';
     }
     //END DISPLAY CONDITIONS FOR THIS QUESTION
     //// NICE COMMENTS : but a subaction copy would be even nicer
     // BEGIN: DISPLAY THE COPY CONDITIONS FORM
     if ($subaction == "copyconditionsform" || $subaction == "copyconditions") {
         $aViewUrls['output'] .= "<tr class=''><td colspan='3'>\n" . CHtml::form(array("/admin/conditions/sa/index/subaction/copyconditions/surveyid/{$iSurveyID}/gid/{$gid}/qid/{$qid}/"), 'post', array('id' => "copyconditions", 'name' => "copyconditions")) . "<h3>" . gT("Copy conditions") . "</h3>\n";
         //CopyConditionsMessage
         if (isset($CopyConditionsMessage)) {
             $aViewUrls['output'] .= "<div class='messagebox ui-corner-all'>\n" . "{$CopyConditionsMessage}\n" . "</div>\n";
         }
         if (count($conditionsList)) {
             // Multiselect is not working, so better to disable (as in 2.06)
             //App()->getClientScript()->registerCssFile(Yii::app()->getConfig('publicstyleurl') . 'jquery.multiselect.filter.css');
             //$this->registerScriptFile( 'SCRIPT_PATH', 'jquery.multiselect.min.js');
             $this->registerScriptFile('ADMIN_SCRIPT_PATH', 'checkgroup.js');
             // TODO
             $aViewUrls['output'] .= "<script type='text/javascript'>\$(document).ready(function () { \$('#copytomultiselect').multiselect( { autoOpen: true, noneSelectedText: '" . gT("No questions selected") . "', checkAllText: '" . gT("Check all") . "', uncheckAllText: '" . gT("Uncheck all") . "', selectedText: '# " . gT("selected") . "', beforeclose: function(){ return false;},height: 200 } ); });</script>";
             $aViewUrls['output'] .= "\t<div class='conditioncopy-tbl-row'>\n" . "\t<div class='condition-tbl-left'>" . gT("Copy the selected conditions to") . ":</div>\n" . "\t<div class='condition-tbl-right'>\n" . "\t\t<select class='form-control' name='copyconditionsto[]' id='copytomultiselect'  multiple='multiple' >\n";
             if (isset($pquestions) && count($pquestions) != 0) {
                 foreach ($pquestions as $pq) {
                     $aViewUrls['output'] .= "\t\t<option value='{$pq['fieldname']}'>" . $pq['text'] . "</option>\n";
                 }
             }
             $aViewUrls['output'] .= "\t\t</select>\n" . "\t</div>\n" . "\t</div>\n";
             if (!isset($pquestions) || count($pquestions) == 0) {
                 $disableCopyCondition = " disabled='disabled'";
             } else {
                 $disableCopyCondition = " ";
             }
             $aViewUrls['output'] .= "\t<div class='condition-tbl-full'>\n" . "<br/>\t\t<input class='btn btn-default' type='submit' value='" . gT("Copy conditions") . "' onclick=\"prepareCopyconditions(); return true;\" {$disableCopyCondition}/>\n" . "<input type='hidden' name='subaction' value='copyconditions' />\n" . "<input type='hidden' name='sid' value='{$iSurveyID}' />\n" . "<input type='hidden' name='gid' value='{$gid}' />\n" . "<input type='hidden' name='qid' value='{$qid}' />\n" . "</div>\n";
             $aViewUrls['output'] .= "<script type=\"text/javascript\">\n" . "function prepareCopyconditions()\n" . "{\n" . "\t\$(\"input:checked[name^='aConditionFromScenario']\").each(function(i,val)\n" . "\t{\n" . "var thecid = val.value;\n" . "var theform = document.getElementById('copyconditions');\n" . "addHiddenElement(theform,'copyconditionsfrom[]',thecid);\n" . "return true;\n" . "\t});\n" . "}\n" . "</script>\n";
         } else {
             $aViewUrls['output'] .= "<div class='messagebox ui-corner-all'>\n" . "<div class='partialheader'>" . gT("There are no existing conditions in this survey.") . "</div><br />\n" . "</div>\n";
         }
         $aViewUrls['output'] .= "</form></td></tr>\n";
     }
     // END: DISPLAY THE COPY CONDITIONS FORM
     if (isset($cquestions)) {
         if (count($cquestions) > 0 && count($cquestions) <= 10) {
             $qcount = count($cquestions);
         } else {
             $qcount = 9;
         }
     } else {
         $qcount = 0;
     }
     //BEGIN: DISPLAY THE ADD or EDIT CONDITION FORM
     if ($subaction == "editconditionsform" || $subaction == "insertcondition" || $subaction == "updatecondition" || $subaction == "deletescenario" || $subaction == "renumberscenarios" || $subaction == "deleteallconditions" || $subaction == "updatescenario" || $subaction == "editthiscondition" || $subaction == "delete") {
         $mytitle = $subaction == "editthiscondition" && isset($p_cid) ? gT("Edit condition") : gT("Add condition");
         $scenario = '';
         $showScenario = $subaction != "editthiscondition" && isset($scenariocount) && ($scenariocount == 1 || $scenariocount == 0) || $subaction == "editthiscondition" && $scenario == 1 ? true : false;
         $aDataEditconditions = array('subaction' => $subaction, 'iSurveyID' => $iSurveyID, 'gid' => $gid, 'qid' => $qid, 'mytitle' => $mytitle, 'showScenario' => $showScenario, 'qcountI' => $qcount + 1);
         $aViewUrls['output'] .= $this->getController()->renderPartial('/admin/conditions/includes/form_editconditions_header', $aDataEditconditions, true);
         //form_editconditions_header
         if (isset($cquestions)) {
             $js_getAnswers_onload = "";
             foreach ($cquestions as $cqn) {
                 $aViewUrls['output'] .= "<option value='{$cqn['3']}' title=\"" . htmlspecialchars($cqn[0]) . "\"";
                 if (isset($p_cquestions) && $cqn[3] == $p_cquestions) {
                     $aViewUrls['output'] .= " selected";
                     if (isset($p_canswers)) {
                         $canswersToSelect = "";
                         foreach ($p_canswers as $checkval) {
                             $canswersToSelect .= ";{$checkval}";
                         }
                         $canswersToSelect = substr($canswersToSelect, 1);
                         $js_getAnswers_onload .= "\$('#canswersToSelect').val('{$canswersToSelect}');\n";
                     }
                 }
                 $aViewUrls['output'] .= ">{$cqn['0']}</option>\n";
             }
         }
         $aViewUrls['output'] .= "</select>\n" . "</div>\n";
         // Source token Tab
         $aViewUrls['output'] .= "<div id='SRCTOKENATTRS' class='tab-pane fade in'><select class='form-control' name='csrctoken' id='csrctoken' >\n";
         foreach (getTokenFieldsAndNames($iSurveyID) as $tokenattr => $tokenattrName) {
             // Check to select
             if (isset($p_csrctoken) && $p_csrctoken == '{TOKEN:' . strtoupper($tokenattr) . '}') {
                 $selectThisSrcTokenAttr = "selected=\"selected\"";
             } else {
                 $selectThisSrcTokenAttr = "";
             }
             $aViewUrls['output'] .= "<option value='{TOKEN:" . strtoupper($tokenattr) . "}' {$selectThisSrcTokenAttr}>" . HTMLEscape($tokenattrName['description']) . "</option>\n";
         }
         $aViewUrls['output'] .= "</select>\n            </div>\n\n";
         $aViewUrls['output'] .= "\t</div>\n";
         // end conditionsource div
         $aViewUrls['output'] .= "\t</div>\n";
         // end tab-content div
         $aViewUrls['output'] .= "</div>\n            </div>\n";
         // Begin "Comparison operator" row
         $aViewUrls['output'] .= "<div class='condition-tbl-row'>\n" . "<div class='condition-tbl-left'>" . gT("Comparison operator") . "</div>\n" . "<div class='condition-tbl-right'>\n" . "<select class='form-control' name='method' id='method'>\n";
         foreach ($method as $methodCode => $methodTxt) {
             $selected = $methodCode == "==" ? " selected='selected'" : "";
             $aViewUrls['output'] .= "\t<option value='" . $methodCode . "'{$selected}>" . $methodTxt . "</option>\n";
         }
         $aViewUrls['output'] .= "</select>\n" . "</div>\n" . "</div>\n";
         // Begin "Answer" row
         $aViewUrls['output'] .= "<div class='condition-tbl-row'>\n" . "<div class='condition-tbl-left'>" . gT("Answer") . "</div>\n";
         if ($subaction == "editthiscondition") {
             $multipletext = "";
             if (isset($_POST['EDITConditionConst']) && $_POST['EDITConditionConst'] != '') {
                 $EDITConditionConst = HTMLEscape($_POST['EDITConditionConst']);
             } else {
                 $EDITConditionConst = "";
             }
             if (isset($_POST['EDITConditionRegexp']) && $_POST['EDITConditionRegexp'] != '') {
                 $EDITConditionRegexp = HTMLEscape($_POST['EDITConditionRegexp']);
             } else {
                 $EDITConditionRegexp = "";
             }
         } else {
             $multipletext = "multiple";
             if (isset($_POST['ConditionConst']) && $_POST['ConditionConst'] != '') {
                 $EDITConditionConst = HTMLEscape($_POST['ConditionConst']);
             } else {
                 $EDITConditionConst = "";
             }
             if (isset($_POST['ConditionRegexp']) && $_POST['ConditionRegexp'] != '') {
                 $EDITConditionRegexp = HTMLEscape($_POST['ConditionRegexp']);
             } else {
                 $EDITConditionRegexp = "";
             }
         }
         $aViewUrls['output'] .= "" . "<div class='condition-tbl-right'>\n" . "<div id=\"conditiontarget\">\n" . "\t<ul class='nav nav-tabs'>\n" . "\t\t<li role='presentation' class='active'><a data-toggle='tab' href=\"#CANSWERSTAB\"><span>" . gT("Predefined") . "</span></a></li>\n" . "\t\t<li role='presentation'><a data-toggle='tab' href=\"#CONST\"><span>" . gT("Constant") . "</span></a></li>\n" . "\t\t<li role='presentation'><a data-toggle='tab' href=\"#PREVQUESTIONS\"><span>" . gT("Questions") . "</span></a></li>\n" . "\t\t<li role='presentation'><a data-toggle='tab' href=\"#TOKENATTRS\"><span>" . gT("Token fields") . "</span></a></li>\n" . "\t\t<li role='presentation'><a data-toggle='tab' href=\"#REGEXP\"><span>" . gT("RegExp") . "</span></a></li>\n" . "\t</ul>\n";
         // Predefined answers tab
         $aViewUrls['output'] .= "\t<div class='tab-content'>\n";
         $aViewUrls['output'] .= "\t<div id='CANSWERSTAB'  class='tab-pane fade in active'>\n" . "\t\t<select class='form-control'  name='canswers[]' {$multipletext} id='canswers' size='7'>\n" . "\t\t</select>\n" . "\t\t<br /><span id='canswersLabel'>" . gT("Predefined answer options for this question") . "</span>\n" . "\t</div>\n";
         // Constant tab
         $aViewUrls['output'] .= "\t<div id='CONST' class='tab-pane fade in'>\n" . "\t\t<textarea name='ConditionConst' id='ConditionConst' rows='5' cols='113'>{$EDITConditionConst}</textarea>\n" . "\t\t<br /><div id='ConditionConstLabel'>" . gT("Constant value") . "</div>\n" . "\t</div>\n";
         // Previous answers tab @SGQA@ placeholders
         $aViewUrls['output'] .= "\t<div id='PREVQUESTIONS'  class='tab-pane fade in'>\n" . "\t\t<br /><label for='prevQuestionSGQA'>" . gT("Answer from previous question") . "</label>\n" . "\t\t<select class='form-control' name='prevQuestionSGQA' id='prevQuestionSGQA' size='7'>\n";
         foreach ($cquestions as $cqn) {
             // building the @SGQA@ placeholders options
             if ($cqn[2] != 'M' && $cqn[2] != 'P') {
                 // Type M or P aren't real fieldnames and thus can't be used in @SGQA@ placehodlers
                 $aViewUrls['output'] .= "\t\t<option value='@{$cqn['3']}@' title=\"" . htmlspecialchars($cqn[0]) . "\"";
                 if (isset($p_prevquestionsgqa) && $p_prevquestionsgqa == "@" . $cqn[3] . "@") {
                     $aViewUrls['output'] .= " selected='selected'";
                 }
                 $aViewUrls['output'] .= ">{$cqn['0']}</option>\n";
             }
         }
         $aViewUrls['output'] .= "\t\t</select>\n" . "\t</div>\n";
         // Token tab
         $aViewUrls['output'] .= "\t<div id='TOKENATTRS'  class='tab-pane fade in'>\n" . "\t\t<br /><label for='tokenAttr'>" . gT("Attributes of the survey participant") . "</label>\n" . "\t\t<select class='form-control' name='tokenAttr' id='tokenAttr' size='7'>\n";
         foreach (getTokenFieldsAndNames($iSurveyID) as $tokenattr => $tokenattrName) {
             $aViewUrls['output'] .= "\t\t<option value='{TOKEN:" . strtoupper($tokenattr) . "}'>" . HTMLEscape($tokenattrName['description']) . "</option>\n";
         }
         $aViewUrls['output'] .= "\t\t</select>\n" . "\t</div>\n";
         // Regexp Tab
         $aViewUrls['output'] .= "\t<div id='REGEXP' class='tab-pane fade in'>\n" . "\t\t<textarea name='ConditionRegexp' id='ConditionRegexp' rows='5' cols='113'>{$EDITConditionRegexp}</textarea>\n" . "\t\t<br /><div id='ConditionRegexpLabel'><a href=\"http://manual.limesurvey.org/wiki/Using_regular_expressions\" target=\"_blank\">" . gT("Regular expression") . "</a></div>\n" . "\t</div>\n";
         $aViewUrls['output'] .= "</div>\n";
         // end conditiontarget div
         $this->registerScriptFile('ADMIN_SCRIPT_PATH', 'conditions.js');
         if ($subaction == "editthiscondition" && isset($p_cid)) {
             $submitLabel = gT("Update condition");
             $submitSubaction = "updatecondition";
             $submitcid = sanitize_int($p_cid);
         } else {
             $submitLabel = gT("Add condition");
             $submitSubaction = "insertcondition";
             $submitcid = "";
         }
         $aViewUrls['output'] .= "</div>\n" . "</div>\n";
         // Begin buttons row
         $aViewUrls['output'] .= "<div class='condition-tbl-full'>\n" . "\t<input type='reset' class='btn btn-default' id='resetForm' value='" . gT("Clear") . "' />\n" . "\t<input type='submit' class='btn btn-default' value='" . $submitLabel . "' />\n" . "<input type='hidden' name='sid' value='{$iSurveyID}' />\n" . "<input type='hidden' name='gid' value='{$gid}' />\n" . "<input type='hidden' name='qid' value='{$qid}' />\n" . "<input type='hidden' name='subaction' value='{$submitSubaction}' />\n" . "<input type='hidden' name='cqid' id='cqid' value='' />\n" . "<input type='hidden' name='cid' id='cid' value='" . $submitcid . "' />\n" . "<input type='hidden' name='editTargetTab' id='editTargetTab' value='' />\n" . "<input type='hidden' name='editSourceTab' id='editSourceTab' value='' />\n" . "<input type='hidden' name='canswersToSelect' id='canswersToSelect' value='' />\n" . "</div>\n" . "</form>\n";
         if (!isset($js_getAnswers_onload)) {
             $js_getAnswers_onload = '';
         }
         $aViewUrls['output'] .= "<script type='text/javascript'>\n" . "<!--\n" . "\t" . $js_getAnswers_onload . "\n";
         if (isset($p_method)) {
             $aViewUrls['output'] .= "\tdocument.getElementById('method').value='" . $p_method . "';\n";
         }
         if ($subaction == "editthiscondition") {
             // in edit mode we read previous values in order to dusplay them in the corresponding inputs
             if (isset($_POST['EDITConditionConst']) && $_POST['EDITConditionConst'] != '') {
                 // In order to avoid issues with backslash escaping, I don't use javascript to set the value
                 // Thus the value is directly set when creating the Textarea element
                 //$aViewUrls['output'] .= "\tdocument.getElementById('ConditionConst').value='".HTMLEscape($_POST['EDITConditionConst'])."';\n";
                 $aViewUrls['output'] .= "\tdocument.getElementById('editTargetTab').value='#CONST';\n";
             } elseif (isset($_POST['EDITprevQuestionSGQA']) && $_POST['EDITprevQuestionSGQA'] != '') {
                 $aViewUrls['output'] .= "\tdocument.getElementById('prevQuestionSGQA').value='" . HTMLEscape($_POST['EDITprevQuestionSGQA']) . "';\n";
                 $aViewUrls['output'] .= "\tdocument.getElementById('editTargetTab').value='#PREVQUESTIONS';\n";
             } elseif (isset($_POST['EDITtokenAttr']) && $_POST['EDITtokenAttr'] != '') {
                 $aViewUrls['output'] .= "\tdocument.getElementById('tokenAttr').value='" . HTMLEscape($_POST['EDITtokenAttr']) . "';\n";
                 $aViewUrls['output'] .= "\tdocument.getElementById('editTargetTab').value='#TOKENATTRS';\n";
             } elseif (isset($_POST['EDITConditionRegexp']) && $_POST['EDITConditionRegexp'] != '') {
                 // In order to avoid issues with backslash escaping, I don't use javascript to set the value
                 // Thus the value is directly set when creating the Textarea element
                 //$aViewUrls['output'] .= "\tdocument.getElementById('ConditionRegexp').value='".HTMLEscape($_POST['EDITConditionRegexp'])."';\n";
                 $aViewUrls['output'] .= "\tdocument.getElementById('editTargetTab').value='#REGEXP';\n";
             } elseif (isset($_POST['EDITcanswers']) && is_array($_POST['EDITcanswers'])) {
                 // was a predefined answers post
                 $aViewUrls['output'] .= "\tdocument.getElementById('editTargetTab').value='#CANSWERSTAB';\n";
                 $aViewUrls['output'] .= "\t\$('#canswersToSelect').val('" . $_POST['EDITcanswers'][0] . "');\n";
             }
             if (isset($_POST['csrctoken']) && $_POST['csrctoken'] != '') {
                 $aViewUrls['output'] .= "\tdocument.getElementById('csrctoken').value='" . HTMLEscape($_POST['csrctoken']) . "';\n";
                 $aViewUrls['output'] .= "\tdocument.getElementById('editSourceTab').value='#SRCTOKENATTRS';\n";
             } else {
                 if (isset($_POST['cquestions']) && $_POST['cquestions'] != '') {
                     $aViewUrls['output'] .= "\tdocument.getElementById('cquestions').value='" . HTMLEscape($_POST['cquestions']) . "';\n";
                     $aViewUrls['output'] .= "\tdocument.getElementById('editSourceTab').value='#SRCPREVQUEST';\n";
                 }
             }
         } else {
             // in other modes, for the moment we do the same as for edit mode
             if (isset($_POST['ConditionConst']) && $_POST['ConditionConst'] != '') {
                 // In order to avoid issues with backslash escaping, I don't use javascript to set the value
                 // Thus the value is directly set when creating the Textarea element
                 //$aViewUrls['output'] .= "\tdocument.getElementById('ConditionConst').value='".HTMLEscape($_POST['ConditionConst'])."';\n";
                 $aViewUrls['output'] .= "\tdocument.getElementById('editTargetTab').value='#CONST';\n";
             } elseif (isset($_POST['prevQuestionSGQA']) && $_POST['prevQuestionSGQA'] != '') {
                 $aViewUrls['output'] .= "\tdocument.getElementById('prevQuestionSGQA').value='" . HTMLEscape($_POST['prevQuestionSGQA']) . "';\n";
                 $aViewUrls['output'] .= "\tdocument.getElementById('editTargetTab').value='#PREVQUESTIONS';\n";
             } elseif (isset($_POST['tokenAttr']) && $_POST['tokenAttr'] != '') {
                 $aViewUrls['output'] .= "\tdocument.getElementById('tokenAttr').value='" . HTMLEscape($_POST['tokenAttr']) . "';\n";
                 $aViewUrls['output'] .= "\tdocument.getElementById('editTargetTab').value='#TOKENATTRS';\n";
             } elseif (isset($_POST['ConditionRegexp']) && $_POST['ConditionRegexp'] != '') {
                 // In order to avoid issues with backslash escaping, I don't use javascript to set the value
                 // Thus the value is directly set when creating the Textarea element
                 //$aViewUrls['output'] .= "\tdocument.getElementById('ConditionRegexp').value='".HTMLEscape($_POST['ConditionRegexp'])."';\n";
                 $aViewUrls['output'] .= "\tdocument.getElementById('editTargetTab').value='#REGEXP';\n";
             } else {
                 // was a predefined answers post
                 if (isset($_POST['cquestions'])) {
                     $aViewUrls['output'] .= "\tdocument.getElementById('cquestions').value='" . HTMLEscape($_POST['cquestions']) . "';\n";
                 }
                 $aViewUrls['output'] .= "\tdocument.getElementById('editTargetTab').value='#CANSWERSTAB';\n";
             }
             if (isset($_POST['csrctoken']) && $_POST['csrctoken'] != '') {
                 $aViewUrls['output'] .= "\tdocument.getElementById('csrctoken').value='" . HTMLEscape($_POST['csrctoken']) . "';\n";
                 $aViewUrls['output'] .= "\tdocument.getElementById('editSourceTab').value='#SRCTOKENATTRS';\n";
             } else {
                 if (isset($_POST['cquestions'])) {
                     $aViewUrls['output'] .= "\tdocument.getElementById('cquestions').value='" . javascriptEscape($_POST['cquestions']) . "';\n";
                 }
                 $aViewUrls['output'] .= "\tdocument.getElementById('editSourceTab').value='#SRCPREVQUEST';\n";
             }
         }
         if (isset($p_scenario)) {
             $aViewUrls['output'] .= "\tdocument.getElementById('scenario').value='" . $p_scenario . "';\n";
         }
         $aViewUrls['output'] .= "-->\n" . "</script>\n";
     }
     //END: DISPLAY THE ADD or EDIT CONDITION FORM
     $conditionsoutput = $aViewUrls['output'];
     $aData['conditionsoutput'] = $conditionsoutput;
     $this->_renderWrappedTemplate('conditions', $aViewUrls, $aData);
     // TMSW Condition->Relevance:  Must call LEM->ConvertConditionsToRelevance() whenever Condition is added or updated - what is best location for that action?
 }
コード例 #5
0
 /**
  * Get the complete HTML from a string
  * @param string $sExpression : the string to parse
  * @param array $aReplacement : optionnal array of replacemement
  * @param string $sDebugSource : optionnal debug source (for templatereplace)
  * @uses ExpressionValidate::$iSurveyId
  * @uses ExpressionValidate::$sLang
  *
  * @author Denis Chenu
  * @version 1.0
  */
 private function getHtmlExpression($sExpression, $aReplacement = array(), $sDebugSource = __CLASS__)
 {
     $LEM = LimeExpressionManager::singleton();
     $LEM::SetDirtyFlag();
     // Not sure it's needed
     $LEM::SetPreviewMode('logic');
     $aReData = array();
     if ($this->iSurveyId) {
         $LEM::StartSurvey($this->iSurveyId, 'survey', array('hyperlinkSyntaxHighlighting' => true));
         // replace QCODE
         $aReData['thissurvey'] = getSurveyInfo($this->iSurveyId, $this->sLang);
     }
     // TODO : Find error in class name, style etc ....
     // need: templatereplace without any filter and find if there are error but $bHaveError=$LEM->em->HasErrors() is Private
     $oFilter = new CHtmlPurifier();
     templatereplace($oFilter->purify(viewHelper::filterScript($sExpression)), $aReplacement, $aReData, $sDebugSource, false, null, array(), true);
     return $LEM::GetLastPrettyPrintExpression();
 }
コード例 #6
0
ファイル: Writer.php プロジェクト: krsandesh/LimeSurvey
 /**
  * Return the question code according to options
  *
  * @param Survey $oSurvey
  * @param FormattingOptions $oOptions
  * @param string $fieldName
  * @return string
  */
 public function getHeadingCode(SurveyObj $oSurvey, FormattingOptions $oOptions, $fieldName)
 {
     if (isset($oSurvey->fieldMap[$fieldName])) {
         return viewHelper::getFieldCode($oSurvey->fieldMap[$fieldName], array('separator' => array('[', ']'), 'LEMcompat' => $oOptions->useEMCode));
     } else {
         return $fieldName;
     }
 }
コード例 #7
0
                                                        </span>
                                                    </div>

                                                <!-- Other questions -->
                                                <?php else: ?>
                                                    <a href="<?php echo $this->createUrl("/admin/questions/sa/view/surveyid/$iSurveyId/gid/".$aGroup->gid."/qid/".$question->qid); ?>" class="question-link" >
                                                        <span class="question-collapse-title">
                                                            <span class="glyphicon glyphicon-list"></span>
                                                            <strong>
                                                                <?php echo sanitize_html_string(strip_tags($question->title));?>
                                                            </strong>
                                                            <br/>
                                                            <em>
                                                                <?php
                                                                    templatereplace($question->question, array(),$aReplacementData,'Unspecified', false ,$question->qid);
                                                                    echo viewHelper::stripTagsEM(LimeExpressionManager::GetLastPrettyPrintExpression());
                                                                ?>
                                                            </em>
                                                        </span>
                                                    </a>
                                                <?php endif; ?>
                                            <?php endif; ?>
                                        <?php endforeach;?>
                                    <?php else:?>
                                        <a href="" onclick="event.preventDefault();" style="cursor: default;">
                                            <?php eT('There are no questions in this group.');?>
                                        </a>
                                    <?php endif;?>
                                </div>
                            </div>
                        <?php endforeach;?>
コード例 #8
0
 /**
  * displayResults builds html output to display the actual results from a survey
  *
  * @param mixed $outputs
  * @param INT $results The number of results being displayed overall
  * @param mixed $rt
  * @param mixed $outputType
  * @param mixed $surveyid
  * @param mixed $sql
  * @param mixed $usegraph
  *
  *
  */
 protected function displayResults($outputs, $results, $rt, $outputType, $surveyid, $sql, $usegraph, $browse, $sLanguage)
 {
     /* Set up required variables */
     $TotalCompleted = 0;
     //Count of actually completed answers
     $statisticsoutput = "";
     $sDatabaseType = Yii::app()->db->getDriverName();
     $tempdir = Yii::app()->getConfig("tempdir");
     $tempurl = Yii::app()->getConfig("tempurl");
     $firstletter = substr($rt, 0, 1);
     $astatdata = array();
     if ($usegraph == 1 && $outputType != 'html') {
         //for creating graphs we need some more scripts which are included here
         require_once APPPATH . '/third_party/pchart/pchart/pChart.class';
         require_once APPPATH . '/third_party/pchart/pchart/pData.class';
         require_once APPPATH . '/third_party/pchart/pchart/pCache.class';
         $MyCache = new pCache($tempdir . '/');
     }
     switch ($outputType) {
         case 'xls':
             $xlsTitle = sprintf(gT("Field summary for %s"), html_entity_decode($outputs['qtitle'], ENT_QUOTES, 'UTF-8'));
             $xlsDesc = html_entity_decode($outputs['qquestion'], ENT_QUOTES, 'UTF-8');
             $this->xlsRow++;
             $this->xlsRow++;
             $this->xlsRow++;
             $this->sheet->write($this->xlsRow, 0, $xlsTitle);
             $this->xlsRow++;
             $this->sheet->write($this->xlsRow, 0, $xlsDesc);
             $footXLS = array();
             break;
         case 'pdf':
             $sPDFQuestion = flattenText($outputs['qquestion'], false, true);
             $pdfTitle = $this->pdf->delete_html(sprintf(gT("Field summary for %s"), html_entity_decode($outputs['qtitle'], ENT_QUOTES, 'UTF-8')));
             $titleDesc = $sPDFQuestion;
             $this->pdf->AddPage('P', 'A4');
             $this->pdf->Bookmark($sPDFQuestion, 1, 0);
             $this->pdf->titleintopdf($pdfTitle, $sPDFQuestion);
             $tablePDF = array();
             $footPDF = array();
             break;
         case 'html':
             // output now generated in subview _statisticsoutuput_header
             break;
         default:
             break;
     }
     //loop though the array which contains all answer data
     $ColumnName_RM = array();
     //echo '<pre>'; var_dump($outputs['alist']); echo '</pre>';die;
     foreach ($outputs['alist'] as $al) {
         //picks out answer list ($outputs['alist']/$al)) that come from the multiple list above
         if (isset($al[2]) && $al[2]) {
             //handling for "other" option
             if ($al[0] == gT("Other")) {
                 if ($outputs['qtype'] == '!' || $outputs['qtype'] == 'L') {
                     // It is better for single choice question types to filter on the number of '-oth-' entries, than to
                     // just count the number of 'other' values - that way with failing Javascript the statistics don't get messed up
                     /* This query selects a count of responses where "other" has been selected */
                     $query = "SELECT count(*) FROM {{survey_{$surveyid}}} WHERE " . Yii::app()->db->quoteColumnName(substr($al[2], 0, strlen($al[2]) - 5)) . "='-oth-'";
                 } else {
                     //get data - select a count of responses where no answer is provided
                     $query = "SELECT count(*) FROM {{survey_{$surveyid}}} WHERE ";
                     $query .= $sDatabaseType == "mysql" ? Yii::app()->db->quoteColumnName($al[2]) . " != ''" : "NOT (" . Yii::app()->db->quoteColumnName($al[2]) . " LIKE '')";
                 }
             } elseif ($outputs['qtype'] == "U" || $outputs['qtype'] == "T" || $outputs['qtype'] == "S" || $outputs['qtype'] == "Q" || $outputs['qtype'] == ";") {
                 $sDatabaseType = Yii::app()->db->getDriverName();
                 //free text answers
                 if ($al[0] == "Answer") {
                     $query = "SELECT count(*) FROM {{survey_{$surveyid}}} WHERE ";
                     $query .= $sDatabaseType == "mysql" ? Yii::app()->db->quoteColumnName($al[2]) . " != ''" : "NOT (" . Yii::app()->db->quoteColumnName($al[2]) . " LIKE '')";
                 } elseif ($al[0] == "NoAnswer") {
                     $query = "SELECT count(*) FROM {{survey_{$surveyid}}} WHERE ( ";
                     $query .= $sDatabaseType == "mysql" ? Yii::app()->db->quoteColumnName($al[2]) . " = '')" : " (" . Yii::app()->db->quoteColumnName($al[2]) . " LIKE ''))";
                 }
             } elseif ($outputs['qtype'] == "O") {
                 $query = "SELECT count(*) FROM {{survey_{$surveyid}}} WHERE ( ";
                 $query .= $sDatabaseType == "mysql" ? Yii::app()->db->quoteColumnName($al[2]) . " <> '')" : " (" . Yii::app()->db->quoteColumnName($al[2]) . " NOT LIKE ''))";
                 // all other question types
             } else {
                 $query = "SELECT count(*) FROM {{survey_{$surveyid}}} WHERE " . Yii::app()->db->quoteColumnName($al[2]) . " =";
                 //ranking question?
                 if (substr($rt, 0, 1) == "R") {
                     $query .= " '{$al['0']}'";
                 } else {
                     $query .= " 'Y'";
                 }
             }
         } else {
             if ($al[0] != "") {
                 //get more data
                 $sDatabaseType = Yii::app()->db->getDriverName();
                 if ($sDatabaseType == 'mssql' || $sDatabaseType == 'sqlsrv' || $sDatabaseType == 'dblib') {
                     // mssql cannot compare text blobs so we have to cast here
                     $query = "SELECT count(*) FROM {{survey_{$surveyid}}} WHERE cast(" . Yii::app()->db->quoteColumnName($rt) . " as varchar)= '{$al['0']}'";
                 } else {
                     $query = "SELECT count(*) FROM {{survey_{$surveyid}}} WHERE " . Yii::app()->db->quoteColumnName($rt) . " = '{$al['0']}'";
                 }
             } else {
                 // This is for the 'NoAnswer' case
                 // We need to take into account several possibilities
                 // * NoAnswer cause the participant clicked the NoAnswer radio
                 //  ==> in this case value is '' or ' '
                 // * NoAnswer in text field
                 //  ==> value is ''
                 // * NoAnswer due to conditions, or a page not displayed
                 //  ==> value is NULL
                 if ($sDatabaseType == 'mssql' || $sDatabaseType == 'sqlsrv' || $sDatabaseType == 'dblib') {
                     // mssql cannot compare text blobs so we have to cast here
                     //$query = "SELECT count(*) FROM {{survey_$surveyid}} WHERE (".sanitize_int($rt)." IS NULL "
                     $query = "SELECT count(*) FROM {{survey_{$surveyid}}} WHERE ( " . "cast(" . Yii::app()->db->quoteColumnName($rt) . " as varchar) = '' " . "OR cast(" . Yii::app()->db->quoteColumnName($rt) . " as varchar) = ' ' )";
                 } elseif ($sDatabaseType == 'pgsql') {
                     $query = "SELECT count(*) FROM {{survey_{$surveyid}}} WHERE ( " . " " . Yii::app()->db->quoteColumnName($rt) . "::text = '' " . "OR " . Yii::app()->db->quoteColumnName($rt) . "::text = ' ') ";
                 } else {
                     $query = "SELECT count(*) FROM {{survey_{$surveyid}}} WHERE ( " . " " . Yii::app()->db->quoteColumnName($rt) . " = '' " . "OR " . Yii::app()->db->quoteColumnName($rt) . " = ' ') ";
                 }
             }
         }
         //check filter option
         if (incompleteAnsFilterState() == "incomplete") {
             $query .= " AND submitdate is null";
         } elseif (incompleteAnsFilterState() == "complete") {
             $query .= " AND submitdate is not null";
         }
         //check for any "sql" that has been passed from another script
         if (!empty($sql)) {
             $query .= " AND {$sql}";
         }
         //get data
         $row = Yii::app()->db->createCommand($query)->queryScalar();
         //store temporarily value of answer count of question type '5' and 'A'.
         $tempcount = -1;
         //count can't be less han zero
         //increase counter
         $TotalCompleted += $row;
         //"no answer" handling
         if ($al[0] === "") {
             $fname = gT("No answer");
         } elseif ($al[0] === gT("Other") || $al[0] === "Answer" || $outputs['qtype'] === "O" && $al[0] === gT("Comments") || $outputs['qtype'] === "P") {
             if ($outputs['qtype'] == "P") {
                 $sColumnName = $al[2] . "comment";
             } else {
                 $sColumnName = $al[2];
             }
             $ColumnName_RM[] = $sColumnName;
             if ($outputs['qtype'] == 'O') {
                 $TotalCompleted -= $row;
             }
             $fname = "{$al['1']}";
             if ($browse === true) {
                 $fname .= " <input type='button' class='statisticsbrowsebutton btn btn-default btn-large' value='" . gT("Browse") . "' id='{$sColumnName}' />";
             }
             if ($browse === true && isset($_POST['showtextinline']) && $outputType == 'pdf') {
                 $headPDF2 = array();
                 $headPDF2[] = array(gT("ID"), gT("Response"));
                 $tablePDF2 = array();
                 $result2 = $this->_listcolumn($surveyid, $sColumnName);
                 foreach ($result2 as $row2) {
                     $tablePDF2[] = array($row2['id'], $row2['value']);
                 }
             }
             if ($browse === true && isset($_POST['showtextinline']) && $outputType == 'xls') {
                 $headXLS = array();
                 $tableXLS = array();
                 $headXLS[] = array(gT("ID"), gT("Response"));
                 $result2 = $this->_listcolumn($surveyid, $sColumnName);
                 foreach ($result2 as $row2) {
                     $tableXLS[] = array($row2['id'], $row2['value']);
                 }
             }
         } elseif ($outputs['qtype'] == "S" || $outputs['qtype'] == "U" || $outputs['qtype'] == "T" || $outputs['qtype'] == "Q") {
             $headPDF = array();
             $headPDF[] = array(gT("Answer"), gT("Count"), gT("Percentage"));
             //show free text answers
             if ($al[0] == "Answer") {
                 $fname = "{$al['1']}";
                 if ($browse === true) {
                     $fname .= " <input type='button'  class='statisticsbrowsebutton btn btn-default btn-large' value='" . gT("Browse") . "' id='{$sColumnName}' />";
                 }
             } elseif ($al[0] == "NoAnswer") {
                 $fname = "{$al['1']}";
             }
             $bShowCount = true;
             $bShowPercentage = true;
             $bAnswer = true;
             // For view
             $bSum = false;
             if ($browse === true && isset($_POST['showtextinline']) && $outputType == 'pdf') {
                 $headPDF2 = array();
                 $headPDF2[] = array(gT("ID"), gT("Response"));
                 $tablePDF2 = array();
                 $result2 = $this->_listcolumn($surveyid, $sColumnName);
                 foreach ($result2 as $row2) {
                     $tablePDF2[] = array($row2['id'], $row2['value']);
                 }
             }
         } elseif (Yii::app()->getConfig('showaggregateddata') == 1) {
             if (!isset($showheadline) || $showheadline != false) {
                 if ($outputs['qtype'] == "5" || $outputs['qtype'] == "A") {
                     switch ($outputType) {
                         case 'xls':
                             $this->xlsRow++;
                             $this->sheet->write($this->xlsRow, 0, gT("Answer"));
                             $this->sheet->write($this->xlsRow, 1, gT("Count"));
                             $this->sheet->write($this->xlsRow, 2, gT("Percentage"));
                             $this->sheet->write($this->xlsRow, 3, gT("Sum"));
                             break;
                         case 'pdf':
                             $headPDF = array();
                             $headPDF[] = array(gT("Answer"), gT("Count"), gT("Percentage"), gT("Sum"));
                             break;
                         case 'html':
                             //four columns
                             $bShowCount = true;
                             $bShowPercentage = true;
                             $bAnswer = true;
                             $bSum = true;
                             break;
                         default:
                             break;
                     }
                     $showheadline = false;
                 } else {
                     switch ($outputType) {
                         case 'xls':
                             $this->xlsRow++;
                             $this->sheet->write($this->xlsRow, 0, gT("Answer"));
                             $this->sheet->write($this->xlsRow, 1, gT("Count"));
                             $this->sheet->write($this->xlsRow, 2, gT("Percentage"));
                             break;
                         case 'pdf':
                             $headPDF = array();
                             $headPDF[] = array(gT("Answer"), gT("Count"), gT("Percentage"));
                             break;
                         case 'html':
                             //three columns
                             $bAnswer = true;
                             // For view
                             $bSum = false;
                             $bShowCount = true;
                             $bShowPercentage = true;
                             break;
                         default:
                             break;
                     }
                     $showheadline = false;
                 }
             }
             //text for answer column is always needed
             $fname = "{$al['1']} ({$al['0']})";
         } else {
             if (!isset($showheadline) || $showheadline != false) {
                 switch ($outputType) {
                     case 'xls':
                         $this->xlsRow++;
                         $this->sheet->write($this->xlsRow, 0, gT("Answer"));
                         $this->sheet->write($this->xlsRow, 1, gT("Count"));
                         $this->sheet->write($this->xlsRow, 2, gT("Percentage"));
                         break;
                     case 'pdf':
                         $headPDF = array();
                         $headPDF[] = array(gT("Answer"), gT("Count"), gT("Percentage"));
                         break;
                     case 'html':
                         //three columns
                         $bAnswer = true;
                         // For view
                         $bSum = false;
                         $bShowCount = true;
                         $bShowPercentage = true;
                         break;
                     default:
                         break;
                 }
                 $showheadline = false;
             }
             //answer text
             $fname = "{$al['1']} ({$al['0']})";
         }
         //are there some results to play with?
         if ($results > 0) {
             //calculate percentage
             $gdata[] = $row / $results * 100;
         } else {
             //no data!
             $gdata[] = "N/A";
         }
         //put absolute data into array
         $grawdata[] = $row;
         if (!(in_array('is_comment', $al) || in_array('is_no_answer', $al))) {
             $grawdata_percents[] = $row;
         }
         //var_dump($grawdata); die();
         //put question title and code into array
         $label[] = $fname;
         //put only the code into the array
         $justcode[] = $al[0];
         //edit labels and put them into antoher array
         //first check if $tempcount is > 0. If yes, $row has been modified and $tempcount has the original count.
         if ($tempcount > -1) {
             $flatLabel = wordwrap(FlattenText("{$al['1']}"), 25, "\n");
             // If the flatten label is empty (like for picture, or HTML, etc.)
             // We replace it by the subquestion code
             if ($flatLabel == '') {
                 $flatLabel = $al[0];
             }
             // For legend
             $lbl[$flatLabel] = $tempcount;
         } else {
             $flatLabel = wordwrap(FlattenText("{$al['1']}"), 25, "\n");
             // If the flatten label is empty (like for picture, or HTML, etc.)
             // We replace it by the subquestion code
             if ($flatLabel == '') {
                 $flatLabel = $al[0];
             }
             $lbl[$flatLabel] = $row;
         }
         // For Graph labels
         switch ($_POST['graph_labels']) {
             case 'qtext':
                 $aGraphLabels[] = $sFlatLabel = $flatLabel;
                 break;
             case 'both':
                 $aGraphLabels[] = $sFlatLabel = $al[0] . ': ' . $flatLabel;
                 break;
             default:
                 $aGraphLabels[] = $sFlatLabel = $al[0];
                 break;
         }
         if (!(in_array('is_comment', $al) || in_array('is_no_answer', $al))) {
             $aGraphLabelsPercent[] = $sFlatLabel;
             $lblPercent[$flatLabel] = $lbl[$flatLabel];
         }
     }
     //end foreach -> loop through answer data
     //no filtering of incomplete answers and NO multiple option questions
     //if ((incompleteAnsFilterState() != "complete") and ($outputs['qtype'] != "M") and ($outputs['qtype'] != "P"))
     //error_log("TIBO ".print_r($showaggregated_indice_table,true));
     if ($outputs['qtype'] != "M" and $outputs['qtype'] != "P") {
         //is the checkbox "Don't consider NON completed responses (only works when Filter incomplete answers is Disable)" checked?
         //if (isset($_POST[''noncompleted']) and ($_POST['noncompleted'] == 1) && (isset(Yii::app()->getConfig('showaggregateddata')) && Yii::app()->getConfig('showaggregateddata') == 0))
         // TIBO: TODO WE MUST SKIP THE FOLLOWING SECTION FOR TYPE A and 5 when
         // showaggreagated data is set and set to 1
         if (isset($_POST['noncompleted']) and $_POST['noncompleted'] == 1) {
             //counter
             $i = 0;
             while (isset($gdata[$i])) {
                 if (isset($showaggregated_indice_table[$i]) && $showaggregated_indice_table[$i] == "aggregated") {
                     // do nothing, we don't rewrite aggregated results
                     // or at least I don't know how !!! (lemeur)
                 } else {
                     //we want to have some "real" data here
                     if ($gdata[$i] != "N/A") {
                         //calculate percentage
                         $gdata[$i] = $grawdata[$i] / $TotalCompleted * 100;
                     }
                 }
                 //increase counter
                 $i++;
             }
             //end while (data available)
         } else {
             //calculate total number of incompleted records
             $TotalIncomplete = $results - $TotalCompleted;
             //output
             if (incompleteAnsFilterState() != "complete") {
                 $fname = gT("Not completed or Not displayed");
             } else {
                 $fname = gT("Not displayed");
             }
             //we need some data
             if ($results > 0) {
                 //calculate percentage
                 $gdata[] = $TotalIncomplete / $results * 100;
             } else {
                 $gdata[] = "N/A";
             }
             //put data of incompleted records into array
             $grawdata[] = $TotalIncomplete;
             //put question title ("Not completed") into array
             $label[] = $fname;
             //put the code ("Not completed") into the array
             $justcode[] = $fname;
             //edit labels and put them into another array
             if (incompleteAnsFilterState() != "complete") {
                 $flatLabel = gT("Not completed or Not displayed");
                 // If the flatten label is empty (like for picture, or HTML, etc.)
                 // We replace it by the subquestion code
                 if ($flatLabel == '') {
                     $flatLabel = $al[0];
                 }
                 $lbl[$flatLabel] = $TotalIncomplete;
             } else {
                 $flatLabel = gT("Not displayed");
                 // If the flatten label is empty (like for picture, or HTML, etc.)
                 // We replace it by the subquestion code
                 if ($flatLabel == '') {
                     $flatLabel = $al[0];
                 }
                 $lbl[$flatLabel] = $TotalIncomplete;
             }
         }
         //end else -> noncompleted NOT checked
     }
     // For multi question type, we have to check non completed with ALL sub question set to NULL
     if ($outputs['qtype'] == "M" or $outputs['qtype'] == "P") {
         $criteria = new CDbCriteria();
         foreach ($outputs['alist'] as $al) {
             $criteria->addCondition(Yii::app()->db->quoteColumnName($al[2]) . " IS NULL");
         }
         if (incompleteAnsFilterState() == "incomplete") {
             $criteria->addCondition("submitdate IS NULL");
         } elseif (incompleteAnsFilterState() == "complete") {
             $criteria->addCondition("submitdate IS NOT NULL");
         }
         $multiNotDisplayed = SurveyDynamic::model($surveyid)->count($criteria);
         if (isset($_POST['noncompleted']) and $_POST['noncompleted'] == 1) {
             //counter
             $i = 0;
             while (isset($gdata[$i])) {
                 //we want to have some "real" data here
                 if ($gdata[$i] != "N/A") {
                     //calculate percentage
                     if ($results > $multiNotDisplayed) {
                         $gdata[$i] = $grawdata[$i] / ($results - $multiNotDisplayed) * 100;
                     } else {
                         $gdata[$i] = "N/A";
                     }
                 }
                 $i++;
             }
         } else {
             // Add a line with not displayed %
             if ($multiNotDisplayed > 0) {
                 if (incompleteAnsFilterState() != "complete") {
                     $fname = gT("Not completed or Not displayed");
                 } else {
                     $fname = gT("Not displayed");
                 }
                 $label[] = $fname;
                 $lbl[$fname] = $multiNotDisplayed;
                 //we need some data
                 if ($results > 0) {
                     //calculate percentage
                     $gdata[] = $multiNotDisplayed / $results * 100;
                 } else {
                     $gdata[] = "N/A";
                 }
                 //put data of incompleted records into array
                 $grawdata[] = $multiNotDisplayed;
             }
         }
     }
     // Columns
     $statsColumns = $_POST['stats_columns'];
     switch ($statsColumns) {
         case "1":
             $nbcols = "12";
             $canvaWidth = "1150";
             $canvaHeight = "800";
             break;
         case "3":
             $nbcols = "4";
             $canvaWidth = "333";
             $canvaHeight = "500";
             break;
         default:
             $nbcols = "6";
             $canvaWidth = "500";
             $canvaHeight = "500";
             break;
     }
     //
     //counter
     $i = 0;
     //we need to know which item we are editing
     $itemcounter = 1;
     $aData['nbcols'] = $nbcols;
     $aData['canvaWidth'] = $canvaWidth;
     $aData['canvaHeight'] = $canvaHeight;
     $aData['outputs'] = isset($outputs) ? $outputs : '';
     $aData['bSum'] = isset($bSum) ? $bSum : false;
     $aData['bAnswer'] = isset($bAnswer) ? $bAnswer : false;
     $aData['bShowCount'] = isset($bShowCount) ? $bShowCount : false;
     $aData['bShowPercentage'] = isset($bShowPercentage) ? $bShowPercentage : false;
     $statisticsoutput = Yii::app()->getController()->renderPartial('/admin/export/generatestats/_statisticsoutput_header', $aData, true);
     //loop through all available answers
     ////
     while (isset($gdata[$i])) {
         $aData['i'] = $i;
         ///// We'll render at the end of this loop statisticsoutput_answer
         //repeat header (answer, count, ...) for each new question
         unset($showheadline);
         /*
          * there are 3 colums:
          *
          * 1 (50%) = answer (title and code in brackets)
          * 2 (25%) = count (absolute)
          * 3 (25%) = percentage
          */
         /*
          * If there is a "browse" button in this label, let's make sure there's an extra row afterwards
          * to store the columnlist
          *
          * */
         if (strpos($label[$i], "statisticsbrowsebutton")) {
             $extraline = "<tr><td class='statisticsbrowsecolumn' colspan='3' style='display: none'>";
             if ($outputs['qtype'] == 'P') {
                 $extraline .= "<div class='statisticsbrowsecolumn' id='columnlist_{$ColumnName_RM[$i]}'></div></td></tr>\n";
                 $sColumnNameForView = $ColumnName_RM[$i];
             } else {
                 $extraline .= "<div class='statisticsbrowsecolumn' id='columnlist_{$sColumnName}'></div></td></tr>\n";
                 $sColumnNameForView = $sColumnName;
             }
         }
         //no data
         if ($gdata[$i] === "N/A") {
             switch ($outputType) {
                 case 'xls':
                     $label[$i] = flattenText($label[$i]);
                     $this->xlsRow++;
                     $this->sheet->write($this->xlsRow, 0, $label[$i]);
                     $this->sheet->writeNumber($this->xlsRow, 1, $grawdata[$i]);
                     $this->sheet->writeNumber($this->xlsRow, 2, $gdata[$i] / 100, $this->xlsPercents);
                     break;
                 case 'pdf':
                     $tablePDF[] = array(flattenText($label[$i]), $grawdata[$i], sprintf("%01.2f", $gdata[$i]) . "%", "");
                     break;
                 case 'html':
                     //output when having no data
                     /// _statisticsoutput_answer
                     $bNAgData = true;
                     if (isset($extraline)) {
                         $bNAgDataExtraLine = $extraline;
                     }
                     break;
                 default:
                     break;
             }
         } else {
             //check if data should be aggregated
             if (Yii::app()->getConfig('showaggregateddata') == 1 && ($outputs['qtype'] == "5" || $outputs['qtype'] == "A")) {
                 //mark that we have done soemthing special here
                 $aggregated = true;
                 if ($results - $grawdata[5] > 0) {
                     $percentage = $grawdata[$i] / ($results - $grawdata[5]) * 100;
                     // Only answered
                 } else {
                     $percentage = 0;
                 }
                 switch ($itemcounter) {
                     case 1:
                         if ($results - $grawdata[5] > 0) {
                             $aggregatedPercentage = ($grawdata[0] + $grawdata[1]) / ($results - $grawdata[5]) * 100;
                         } else {
                             $aggregatedPercentage = 0;
                         }
                         break;
                     case 3:
                         $aggregatedPercentage = $percentage;
                         break;
                     case 5:
                         if ($results - $grawdata[5] > 0) {
                             $aggregatedPercentage = ($grawdata[3] + $grawdata[4]) / ($results - $grawdata[5]) * 100;
                         } else {
                             $aggregatedPercentage = 0;
                         }
                         break;
                     case 6:
                     case 7:
                         if ($results - $grawdata[5] > 0) {
                             $percentage = $grawdata[$i] / $results * 100;
                             // All results
                         } else {
                             $percentage = 0;
                         }
                     default:
                         $aggregatedPercentage = 'na';
                         break;
                 }
                 switch ($outputType) {
                     case 'xls':
                         $label[$i] = flattenText($label[$i]);
                         $this->xlsRow++;
                         $this->sheet->write($this->xlsRow, 0, $label[$i]);
                         $this->sheet->writeNumber($this->xlsRow, 1, $grawdata[$i]);
                         $this->sheet->writeNumber($this->xlsRow, 2, $percentage / 100, $this->xlsPercents);
                         if ($aggregatedPercentage !== 'na') {
                             $this->sheet->writeNumber($this->xlsRow, 3, $aggregatedPercentage / 100, $this->xlsPercents);
                         }
                         break;
                     case 'pdf':
                         $label[$i] = flattenText($label[$i]);
                         if ($aggregatedPercentage !== 'na') {
                             $tablePDF[] = array($label[$i], $grawdata[$i], sprintf("%01.2f", $percentage) . "%", sprintf("%01.2f", $aggregatedPercentage) . "%");
                         } else {
                             $tablePDF[] = array($label[$i], $grawdata[$i], sprintf("%01.2f", $percentage) . "%", "");
                         }
                         break;
                     case 'html':
                         //output percentage
                         $bNAgData = true;
                         if ($aggregatedPercentage !== 'na') {
                             $showAggregatedPercentage = true;
                         } else {
                             $showEmptyAggregatedPercentage = true;
                         }
                         break;
                     default:
                         break;
                 }
                 if ($itemcounter == 5) {
                     // new row "sum"
                     //calculate sum of items 1-5
                     $sumitems = $grawdata[0] + $grawdata[1] + $grawdata[2] + $grawdata[3] + $grawdata[4];
                     //special treatment for zero values
                     if ($sumitems > 0) {
                         $sumpercentage = "100.00";
                     } else {
                         $sumpercentage = "0";
                     }
                     //special treatment for zero values
                     if ($TotalCompleted > 0) {
                         $casepercentage = "100.00";
                     } else {
                         $casepercentage = "0";
                     }
                     switch ($outputType) {
                         case 'xls':
                             $footXLS[] = array(gT("Sum") . " (" . gT("Answers") . ")", $sumitems, $sumpercentage . "%", $sumpercentage . "%");
                             $footXLS[] = array(gT("Number of cases"), $TotalCompleted, $casepercentage . "%", "");
                             $this->xlsRow++;
                             $this->sheet->write($this->xlsRow, 0, gT("Sum") . " (" . gT("Answers") . ")");
                             $this->sheet->writeNumber($this->xlsRow, 1, $sumitems);
                             $this->sheet->writeNumber($this->xlsRow, 2, $sumpercentage / 100, $this->xlsPercents);
                             $this->sheet->writeNumber($this->xlsRow, 3, $sumpercentage / 100, $this->xlsPercents);
                             $this->xlsRow++;
                             $this->sheet->write($this->xlsRow, 0, gT("Number of cases"));
                             $this->sheet->writeNumber($this->xlsRow, 1, $TotalCompleted);
                             $this->sheet->writeNumber($this->xlsRow, 2, $casepercentage / 100, $this->xlsPercents);
                             break;
                         case 'pdf':
                             $footPDF[] = array(gT("Sum") . " (" . gT("Answers") . ")", $sumitems, $sumpercentage . "%", $sumpercentage . "%");
                             $footPDF[] = array(gT("Number of cases"), $TotalCompleted, $casepercentage . "%", "");
                             break;
                         case 'html':
                             $bShowSumAnswer = true;
                             break;
                         default:
                             break;
                     }
                 }
             } else {
                 switch ($outputType) {
                     case 'xls':
                         $label[$i] = flattenText($label[$i]);
                         $this->xlsRow++;
                         $this->sheet->write($this->xlsRow, 0, $label[$i]);
                         $this->sheet->writeNumber($this->xlsRow, 1, $grawdata[$i]);
                         $this->sheet->writeNumber($this->xlsRow, 2, $gdata[$i] / 100, $this->xlsPercents);
                         break;
                     case 'pdf':
                         $label[$i] = flattenText($label[$i]);
                         $tablePDF[] = array($label[$i], $grawdata[$i], sprintf("%01.2f", $gdata[$i]) . "%", "");
                         break;
                     case 'html':
                         //output percentage
                         $bNAgData = true;
                         if (isset($extraline)) {
                             $bNAgDataExtraLine = $extraline;
                         }
                         break;
                     default:
                         break;
                 }
             }
         }
         //end else -> $gdata[$i] != "N/A"
         //increase counter
         $i++;
         $itemcounter++;
         //Clear extraline
         unset($extraline);
         // Convert grawdata_percent to percent
         if (isset($grawdata_percents)) {
             $pTotal = array_sum($grawdata_percents);
             if ($pTotal > 0) {
                 foreach ($grawdata_percents as $key => $data) {
                     $grawdata_percents[$key] = round($data / $pTotal * 100, 2);
                 }
             }
         } else {
             $grawdata_percents = array();
         }
         ///// HERE RENDER statisticsoutput_answer
         $aData['label'] = $label;
         $aData['grawdata'] = $grawdata;
         $aData['grawdata_percent'] = $grawdata_percents;
         $aData['gdata'] = $gdata;
         $aData['extraline'] = isset($extraline) ? $extraline : false;
         $aData['aggregated'] = isset($aggregated) ? $aggregated : false;
         $aData['aggregatedPercentage'] = isset($aggregatedPercentage) ? $aggregatedPercentage : false;
         $aData['sumitems'] = isset($sumitems) ? $sumitems : false;
         $aData['sumpercentage'] = isset($sumpercentage) ? $sumpercentage : false;
         $aData['TotalCompleted'] = isset($TotalCompleted) ? $TotalCompleted : false;
         $aData['casepercentage'] = isset($casepercentage) ? $casepercentage : false;
         $aData['bNAgData'] = isset($bNAgData) ? $bNAgData : false;
         $aData['bNAgDataExtraLine'] = isset($bNAgDataExtraLine) ? $bNAgDataExtraLine : false;
         $aData['showAggregatedPercentage'] = isset($showAggregatedPercentage) ? $showAggregatedPercentage : false;
         $aData['showEmptyAggregatedPercentage'] = isset($showEmptyAggregatedPercentage) ? $showEmptyAggregatedPercentage : false;
         $aData['bShowSumAnswer'] = isset($bShowSumAnswer) ? $bShowSumAnswer : false;
         // Generate answer
         // _statisticsoutput_answer
         $statisticsoutput .= Yii::app()->getController()->renderPartial('/admin/export/generatestats/_statisticsoutput_answer', $aData, true);
         $extraline = false;
         $aggregated = false;
         $aggregatedPercentage = false;
         $sumitems = false;
         $sumpercentage = false;
         $TotalCompleted = false;
         $casepercentage = false;
         $bNAgData = false;
         $bNAgDataExtraLine = false;
         $showAggregatedPercentage = false;
         $showEmptyAggregatedPercentage = false;
         $bShowSumAnswer = false;
     }
     //end while
     $aData['showaggregateddata'] = false;
     //only show additional values when this setting is enabled
     if (Yii::app()->getConfig('showaggregateddata') == 1) {
         //it's only useful to calculate standard deviation and arithmetic means for question types
         //5 = 5 Point Scale
         //A = Array (5 Point Choice)
         if ($outputs['qtype'] == "5" || $outputs['qtype'] == "A") {
             $stddev = 0;
             $stddevarray = array_slice($grawdata, 0, 5, true);
             $am = 0;
             //calculate arithmetic mean
             if (isset($sumitems) && $sumitems > 0) {
                 //calculate and round results
                 //there are always 5 items
                 for ($x = 0; $x < 5; $x++) {
                     //create product of item * value
                     $am += ($x + 1) * $stddevarray[$x];
                 }
                 //prevent division by zero
                 if (isset($stddevarray) && array_sum($stddevarray) > 0) {
                     $am = round($am / array_sum($stddevarray), 2);
                 } else {
                     $am = 0;
                 }
                 //calculate standard deviation -> loop through all data
                 /*
                  * four steps to calculate the standard deviation
                  * 1 = calculate difference between item and arithmetic mean and multiply with the number of elements
                  * 2 = create sqaure value of difference
                  * 3 = sum up square values
                  * 4 = multiply result with 1 / (number of items)
                  * 5 = get root
                  */
                 for ($j = 0; $j < 5; $j++) {
                     //1 = calculate difference between item and arithmetic mean
                     $diff = $j + 1 - $am;
                     //2 = create square value of difference
                     $squarevalue = square($diff);
                     //3 = sum up square values and multiply them with the occurence
                     //prevent divison by zero
                     if ($squarevalue != 0 && $stddevarray[$j] != 0) {
                         $stddev += $squarevalue * $stddevarray[$j];
                     }
                 }
                 //4 = multiply result with 1 / (number of items (=5))
                 //There are two different formulas to calculate standard derivation
                 //$stddev = $stddev / array_sum($stddevarray);        //formula source: http://de.wikipedia.org/wiki/Standardabweichung
                 //prevent division by zero
                 if (array_sum($stddevarray) - 1 != 0 && $stddev != 0) {
                     $stddev = $stddev / (array_sum($stddevarray) - 1);
                     //formula source: http://de.wikipedia.org/wiki/Empirische_Varianz
                 } else {
                     $stddev = 0;
                 }
                 //5 = get root
                 $stddev = sqrt($stddev);
                 $stddev = round($stddev, 2);
             }
             switch ($outputType) {
                 case 'xls':
                     $this->xlsRow++;
                     $this->sheet->write($this->xlsRow, 0, gT("Arithmetic mean"));
                     $this->sheet->writeNumber($this->xlsRow, 1, $am);
                     $this->xlsRow++;
                     $this->sheet->write($this->xlsRow, 0, gT("Standard deviation"));
                     $this->sheet->writeNumber($this->xlsRow, 1, $stddev);
                     break;
                 case 'pdf':
                     $tablePDF[] = array(gT("Arithmetic mean"), $am, '', '');
                     $tablePDF[] = array(gT("Standard deviation"), $stddev, '', '');
                     break;
                 case 'html':
                     //calculate standard deviation
                     $aData['am'] = $am;
                     $aData['stddev'] = $stddev;
                     $statisticsoutput .= Yii::app()->getController()->renderPartial('/admin/export/generatestats/_statisticsoutput_arithmetic', $aData, true);
                     break;
                 default:
                     break;
             }
         }
     }
     if ($outputType == 'pdf') {
         //$tablePDF = array();
         $tablePDF = array_merge_recursive($tablePDF, $footPDF);
         if (!isset($headPDF)) {
             // TODO: Why is $headPDF sometimes undefined here?
             $headPDF = array();
         }
         $this->pdf->headTable($headPDF, $tablePDF);
         //$this->pdf->tableintopdf($tablePDF);
         //                if(isset($footPDF))
         //                foreach($footPDF as $foot)
         //                {
         //                    $footA = array($foot);
         //                    $this->pdf->tablehead($footA);
         //                }
         if (isset($headPDF2)) {
             $this->pdf->headTable($headPDF2, $tablePDF2);
         }
     }
     if ($outputType == 'xls' && (isset($headXLS) || isset($tableXLS))) {
         if (isset($headXLS)) {
             $this->xlsRow++;
             $this->xlsRow++;
             foreach ($headXLS as $aRow) {
                 $this->xlsRow++;
                 $iColumn = 0;
                 foreach ($aRow as $sValue) {
                     $this->sheet->write($this->xlsRow, $iColumn, $sValue, $this->formatBold);
                     $iColumn++;
                 }
             }
         }
         if (isset($tableXLS)) {
             foreach ($tableXLS as $aRow) {
                 $this->xlsRow++;
                 $iColumn = 0;
                 foreach ($aRow as $sValue) {
                     $this->sheet->write($this->xlsRow, $iColumn, $sValue);
                     $iColumn++;
                 }
             }
         }
     }
     if ($outputType == 'html') {
     }
     // _statisticsoutput_graphs.php
     //-------------------------- PCHART OUTPUT ----------------------------
     list($qsid, $qgid, $qqid) = explode("X", $rt, 3);
     $qsid = $surveyid;
     $aattr = getQuestionAttributeValues($outputs['parentqid'], substr($rt, 0, 1));
     //PCHART has to be enabled and we need some data
     //
     if ($usegraph == 1) {
         $bShowGraph = $aattr["statistics_showgraph"] == "1";
         $bAllowPieChart = $outputs['qtype'] != "M" && $outputs['qtype'] != "P";
         $bAllowMap = isset($aattr["location_mapservice"]) && $aattr["location_mapservice"] == "1";
         $bShowMap = $bAllowMap && $aattr["statistics_showmap"] == "1";
         $bShowPieChart = $bAllowPieChart && (isset($aattr["statistics_graphtype"]) && $aattr["statistics_graphtype"] == "1");
         $astatdata[$rt] = array('id' => $rt, 'sg' => $bShowGraph, 'ap' => $bAllowPieChart, 'am' => $bAllowMap, 'sm' => $bShowMap, 'sp' => $bShowPieChart);
         $stats = Yii::app()->session['stats'];
         $stats[$rt] = array('lbl' => $lbl, 'gdata' => $gdata, 'grawdata' => $grawdata);
         Yii::app()->session['stats'] = $stats;
         if ($bShowGraph == true) {
             $cachefilename = '';
             if ($outputType == 'xls' || $outputType == 'pdf') {
                 $cachefilename = createChart($qqid, $qsid, $bShowPieChart, $lbl, $gdata, $grawdata, $MyCache, $sLanguage, $outputs['qtype']);
             }
             if ($cachefilename || $outputType == 'html') {
                 //introduce new counter
                 if (!isset($ci)) {
                     $ci = 0;
                 }
                 //increase counter, start value -> 1
                 $ci++;
                 switch ($outputType) {
                     case 'xls':
                         /**
                          * No Image for Excel...
                          */
                         break;
                     case 'pdf':
                         $this->pdf->AddPage('P', 'A4');
                         $this->pdf->titleintopdf($pdfTitle, $titleDesc);
                         $this->pdf->Image($tempdir . "/" . $cachefilename, 0, 70, 180, 0, '', Yii::app()->getController()->createUrl("admin/survey/sa/view/surveyid/" . $surveyid), 'B', true, 150, 'C', false, false, 0, true);
                         break;
                     case 'html':
                         if (isset($aattr["statistics_graphtype"])) {
                             $req_chart_type = $aattr["statistics_graphtype"];
                         }
                         //// If user forced the chartype from statistics_view
                         if (isset($_POST['charttype']) && $_POST['charttype'] != 'default') {
                             $req_chart_type = $_POST['charttype'];
                         }
                         //// The value of the select box in the question advanced setting is numerical. So we need to translate it.
                         if (isset($req_chart_type)) {
                             switch ($req_chart_type) {
                                 case '1':
                                     $charttype = "Pie";
                                     break;
                                 case '2':
                                     $charttype = "Radar";
                                     break;
                                 case '3':
                                     $charttype = "Line";
                                     break;
                                 case '4':
                                     $charttype = "PolarArea";
                                     break;
                                 case '5':
                                     $charttype = "Doughnut";
                                     break;
                                 default:
                                     $charttype = "Bar";
                                     break;
                             }
                         }
                         //// Here the 72 colors of the original limesurvey palette.
                         //// This could be change by some user palette coming from database.
                         $COLORS_FOR_SURVEY = array('20,130,200', '232,95,51', '34,205,33', '210,211,28', '134,179,129', '201,171,131', '251,231,221', '23,169,161', '167,187,213', '211,151,213', '147,145,246', '147,39,90', '250,250,201', '201,250,250', '94,0,94', '250,125,127', '0,96,201', '201,202,250', '0,0,127', '250,0,250', '250,250,0', '0,250,250', '127,0,127', '127,0,0', '0,125,127', '0,0,250', '0,202,250', '201,250,250', '201,250,201', '250,250,151', '151,202,250', '251,149,201', '201,149,250', '250,202,151', '45,96,250', '45,202,201', '151,202,0', '250,202,0', '250,149,0', '250,96,0', '184,230,115', '102,128,64', '220,230,207', '134,191,48', '184,92,161', '128,64,112', '230,207,224', '191,48,155', '230,138,115', '128,77,64', '230,211,207', '191,77,48', '80,161,126', '64,128,100', '207,230,220', '48,191,130', '25,25,179', '18,18,125', '200,200,255', '145,145,255', '255,178,0', '179,125,0', '255,236,191', '255,217,128', '255,255,0', '179,179,0', '255,255,191', '255,255,128', '102,0,153', '71,0,107', '234,191,255', '213,128,255');
                         //// $lbl is generated somewhere upthere by the original code. We translate it for chartjs.
                         $labels = array();
                         foreach ($lbl as $name => $lb) {
                             $labels[] = $name;
                         }
                         if (isset($lblPercent)) {
                             foreach ($lblPercent as $name => $lb) {
                                 $labels_percent[] = $name;
                             }
                         } else {
                             $labels_percent = array();
                         }
                         break;
                     default:
                         break;
                 }
             }
         }
     }
     //close table/output
     if ($outputType == 'html') {
         // show this block only when we show graphs and are not in the public statics controller
         if ($usegraph == 1 && $bShowGraph && get_class(Yii::app()->getController()) !== 'Statistics_userController') {
             // We clean the labels
             $iMaxLabelLength = 0;
             // We clean the labels
             // Labels for graphs
             $iMaxLabelLength = 0;
             foreach ($aGraphLabels as $key => $label) {
                 $cleanLabel = $label;
                 $cleanLabel = viewHelper::flatEllipsizeText($cleanLabel, true, 20);
                 $graph_labels[$key] = $cleanLabel;
                 $iMaxLabelLength = strlen($cleanLabel) > $iMaxLabelLength ? strlen($cleanLabel) : $iMaxLabelLength;
             }
             if (isset($aGraphLabelsPercent)) {
                 foreach ($aGraphLabelsPercent as $key => $label) {
                     $cleanLabel = $label;
                     $cleanLabel = viewHelper::flatEllipsizeText($cleanLabel, true, 20);
                     $graph_labels_percent[$key] = $cleanLabel;
                 }
             } else {
                 $graph_labels_percent = array();
             }
             $iCanvaHeight = $iMaxLabelLength * 3;
             $aData['iCanvaHeight'] = $iCanvaHeight > 150 ? $iCanvaHeight : 150;
             $qqid = str_replace('#', '_', $qqid);
             $aData['rt'] = $rt;
             $aData['qqid'] = $qqid;
             $aData['graph_labels'] = $graph_labels;
             $aData['graph_labels_percent'] = $labels_percent;
             $aData['labels'] = $labels;
             //$aData['COLORS_FOR_SURVEY'] = COLORS_FOR_SURVEY;
             $aData['charttype'] = isset($charttype) ? $charttype : 'Bar';
             $aData['sChartname'] = '';
             $aData['grawdata'] = $grawdata;
             $aData['color'] = rand(0, 70);
             $aData['COLORS_FOR_SURVEY'] = $COLORS_FOR_SURVEY;
             $aData['lbl'] = $lbl;
             ///
             $statisticsoutput .= Yii::app()->getController()->renderPartial('/admin/export/generatestats/_statisticsoutput_graphs', $aData, true);
         }
         $statisticsoutput .= "</table></div> <!-- in statistics helper --> \n";
     }
     return array("statisticsoutput" => $statisticsoutput, "pdf" => $this->pdf, "astatdata" => $astatdata);
 }
 /**
  * Returns the adapted heading using parent function
  *
  * @param Survey $survey
  * @param FormattingOptions $oOptions
  * @param string $fieldName
  * @return string (or false)
  */
 public function getFullHeading(SurveyObj $survey, FormattingOptions $oOptions, $fieldName)
 {
     $sQuestion = "";
     static $aColumnDone = array();
     switch ($this->oldHeadFormat) {
         case 'abbreviated':
             $sQuestion = parent::getAbbreviatedHeading($survey, $fieldName);
             break;
         case 'full':
             $sQuestion = parent::getFullHeading($survey, $oOptions, $fieldName);
             break;
         default:
         case 'code':
             if (isset($survey->fieldMap[$fieldName])) {
                 $sQuestion = viewHelper::getFieldCode($survey->fieldMap[$fieldName]);
             } else {
                 // Token field
                 $sQuestion = $column;
             }
             break;
     }
     if ($oOptions->headerSpacesToUnderscores) {
         $sQuestion = str_replace(' ', '_', $sQuestion);
     }
     if ($this->exportAnswerPosition == 'aseperatecodetext') {
         if (isset($survey->fieldMap[$fieldName])) {
             $aField = $survey->fieldMap[$fieldName];
             if (!self::sameTextAndCode($aField['type'], $fieldName)) {
                 if (!array_key_exists($fieldName, $aColumnDone)) {
                     // Code export
                     $sQuestion = $this->beforeHeadColumnCode . $sQuestion . $this->afterHeadColumnCode;
                     $aColumnDone[$fieldName] = 1;
                 } else {
                     // Text export
                     $sQuestion = $this->beforeHeadColumnFull . $sQuestion . $this->afterHeadColumnFull;
                     unset($aColumnDone[$fieldName]);
                 }
             } else {
                 $sQuestion = $sQuestion;
             }
         } else {
             $sQuestion = $sQuestion;
         }
     }
     return $sQuestion;
 }
コード例 #10
0
ファイル: questions.php プロジェクト: mfavetti/LimeSurvey
 /**
  * Delete multiple questions.
  * Called by ajax from question list.
  * Permission check is done by questions::delete()
  * @return HTML
  */
 public function deleteMultiple()
 {
     $aQidsAndLang = json_decode(Yii::app()->request->getPost('sItems'));
     $aResults = array();
     foreach ($aQidsAndLang as $sQidAndLang) {
         $aQidAndLang = explode(',', $sQidAndLang);
         $iQid = $aQidAndLang[0];
         $sLanguage = $aQidAndLang[1];
         $oQuestion = Question::model()->find('qid=:qid and language=:language', array(":qid" => $iQid, ":language" => $sLanguage));
         if (is_object($oQuestion)) {
             $aResults[$iQid]['question'] = viewHelper::flatEllipsizeText($oQuestion->question, true, 0);
             $aResults[$iQid]['result'] = $this->delete($oQuestion->sid, $oQuestion->gid, $iQid, true);
         }
     }
     Yii::app()->getController()->renderPartial('/admin/survey/Question/massive_actions/_delete_results', array('aResults' => $aResults));
 }
コード例 #11
0
ファイル: logs.php プロジェクト: sea75300/affiliat_r
<?php

if (!defined('VIEW')) {
    die;
}
?>
<form method="post" action="">
    <div class="afltr-acp-top-buttons">
        <?php 
viewHelper::submitButton('submdelete', language::returnLanguageConstant('OPTIONS_CLEAR_LOG'));
?>
    </div>
    <h2><?php 
language::printLanguageConstant('HL_LOGS_SYSTEM');
?>
</h2>    
    <div class="afltr-acp-list">
        <div class="tabs">
                <ul>
                    <li><a href="#tabs-log-php"><?php 
language::printLanguageConstant('HL_LOGS_ERROR');
?>
</a></li>
                    <li><a href="#tabs-log-system"><?php 
language::printLanguageConstant('HL_LOGS_SYSTEM');
?>
</a></li>                   
                </ul>            
            
            <div id="tabs-log-php" class="small-text">
            <?php 
コード例 #12
0
        ?>
</td>
                    <td class="afltr-acp-td-w1 afltr-align-center"><?php 
        if ($affiliate->getAffiliateEditedTime() > 0) {
            print date($dtMask, $affiliate->getAffiliateEditedTime());
        } else {
            print date($dtMask, $affiliate->getAffiliateAddedTime());
        }
        ?>
</td>
                    <td class="afltr-acp-td-w0 afltr-align-center"><?php 
        viewHelper::boolToText($affiliate->affiliateIsMarked());
        ?>
</td>
                    <td class="afltr-acp-td-w0 afltr-align-center"><?php 
        viewHelper::boolToText($affiliate->affiliateIsAccpted());
        ?>
</td>
                    <td class="afltr-acp-td-35px afltr-align-center"><input type="checkbox" class="afltr-checkbox" name="affiliateDelList[]" value="<?php 
        print $affiliate->getId();
        ?>
"></td>
                </tr>  
            <?php 
    }
    ?>
        <?php 
}
?>
        </table>
    </div>
コード例 #13
0
ファイル: start.php プロジェクト: sea75300/affiliat_r
<form method="post" action="index.php?step=1">
    <div class="afltr-acp-top-buttons">
        <?php 
viewHelper::submitButton('continue', language::returnLanguageConstant('NEXT_BTN'));
?>
    </div>
    <h2>Choose your language</h2>
    <div class="afltr-acp-form afltr-align-center"><?php 
viewHelper::select('lang', $languages);
?>
</div>
</form>
コード例 #14
0
?>
:

                <?php 
if ($afieldcount > 255) {
    echo "\t<img src='{$imageurl}/help.gif' alt='" . $clang->gT("Help") . "' onclick='javascript:alert(\"" . $clang->gT("Your survey contains more than 255 columns of responses. Spreadsheet applications such as Excel are limited to loading no more than 255. Select the columns you wish to export in the list below.", "js") . "\")' />";
} else {
    echo "\t<img src='{$imageurl}/help.gif' alt='" . $clang->gT("Help") . "' onclick='javascript:alert(\"" . $clang->gT("Choose the columns you wish to export.", "js") . "\")' />";
}
?>
                <br /><select name='colselect[]' multiple size='20'>
                    <?php 
$i = 1;
foreach ($excesscols as $sFieldName => $fieldinfo) {
    $questiontext = viewHelper::getFieldText($fieldinfo);
    $questioncode = viewHelper::getFieldCode($fieldinfo);
    echo "<option value='{$sFieldName}'";
    if (isset($_POST['summary'])) {
        if (in_array($ec, $_POST['summary'])) {
            echo "selected";
        }
    } elseif ($i < 256) {
        echo " selected";
    }
    echo " title='{$sFieldName} : " . str_replace("'", "&#39;", $questiontext) . "'>" . ellipsize("{$i} : {$questioncode} - " . str_replace(array("\r\n", "\n", "\r"), " ", $questiontext), 45) . "</option>\n";
    $i++;
}
?>
                </select>
                <br />&nbsp;</fieldset>
            <?php 
コード例 #15
0
ファイル: dbconfig.php プロジェクト: sea75300/affiliat_r
    <h2><?php 
language::printLanguageConstant('HL_INSTALL_DBCONNECT');
?>
</h2>
    <div class="afltr-acp-form afltr-align-center">     
        <table class="afltr-acp-table">
            <tr>
                <td class="afltr-td-label afltr-align-right">
                    <?php 
language::printLanguageConstant('INSTALL_DBTYPE');
?>
:
                </td>
                <td class="afltr-padding-left">
                <?php 
viewHelper::select('dbconfig[DBTYPE]', $dbtypes, null, false, false);
?>
                </td>                
            </tr>            
            <?php 
foreach ($fields as $key => $value) {
    ?>
                <tr>
                    <td class="afltr-td-label afltr-align-right">
                        <?php 
    language::printLanguageConstant('INSTALL_' . strtoupper($key));
    ?>
:
                    </td>
                    <td class="afltr-padding-left">
                        <?php 
コード例 #16
0
ファイル: export.php プロジェクト: ambientelivre/LimeSurvey
 private function _surveyexport($action, $iSurveyID)
 {
     viewHelper::disableHtmlLogging();
     if ($action == "exportstructurexml") {
         $fn = "limesurvey_survey_{$iSurveyID}.lss";
         $this->_addHeaders($fn, "text/xml", "Mon, 26 Jul 1997 05:00:00 GMT");
         echo surveyGetXMLData($iSurveyID);
         exit;
     } elseif ($action == "exportstructurejson") {
         $fn = "limesurvey_survey_{$iSurveyID}.json";
         $this->_addHeaders($fn, "application/json", "Mon, 26 Jul 1997 05:00:00 GMT");
         $surveyInXmlFormat = surveyGetXMLData($iSurveyID);
         // now convert this xml into json format and then return
         echo _xmlToJson($surveyInXmlFormat);
         exit;
     } elseif ($action == "exportstructurequexml") {
         if (isset($surveyprintlang) && !empty($surveyprintlang)) {
             $quexmllang = $surveyprintlang;
         } else {
             $quexmllang = Survey::model()->findByPk($iSurveyID)->language;
         }
         if (!(isset($noheader) && $noheader == TRUE)) {
             $fn = "survey_{$iSurveyID}_{$quexmllang}.xml";
             $this->_addHeaders($fn, "text/xml", "Mon, 26 Jul 1997 05:00:00 GMT");
             echo quexml_export($iSurveyID, $quexmllang);
             exit;
         }
     } elseif ($action == 'exportstructuretsv') {
         $this->_exporttsv($iSurveyID);
     } elseif ($action == "exportarchive") {
         $this->_exportarchive($iSurveyID);
     }
 }
コード例 #17
0
ファイル: Writer.php プロジェクト: jdbaltazar/survey-office
 /**
  * This method is made final to prevent extending code from circumventing the
  * initialization process that must take place prior to any of the translation
  * infrastructure to work.
  *
  * The inialization process is dependent upon the survey being passed into the
  * write function and so must be performed when the method is called and not
  * prior to (such as in a constructor).
  *
  * All extending classes must implement the internalWrite function which is
  * the code that is called after all initialization is completed.
  *
  * @param Survey $survey
  * @param string $sLanguageCode
  * @param FormattingOptions $oOptions
  * @param boolean $bOutputHeaders Set if header should be given back
  */
 public final function write(SurveyObj $survey, $sLanguageCode, FormattingOptions $oOptions, $bOutputHeaders = true)
 {
     //Output the survey.
     $headers = array();
     if ($bOutputHeaders) {
         foreach ($oOptions->selectedColumns as $column) {
             //Survey question field, $column value is a field name from the getFieldMap function.
             switch ($oOptions->headingFormat) {
                 case 'abbreviated':
                     $value = $this->getAbbreviatedHeading($survey, $column);
                     break;
                 case 'full':
                     $value = $this->getFullHeading($survey, $oOptions, $column);
                     break;
                 default:
                 case 'code':
                     if (isset($survey->fieldMap[$column])) {
                         $value = viewHelper::getFieldCode($survey->fieldMap[$column]);
                     } else {
                         // Token field
                         $value = $column;
                     }
                     break;
             }
             if ($oOptions->headerSpacesToUnderscores) {
                 $value = str_replace(' ', '_', $value);
             }
             //$this->output.=$this->csvEscape($value).$this->separator;
             $headers[] = $value;
         }
     }
     //Output the results.
     $sFile = '';
     foreach ($survey->responses as $response) {
         $elementArray = array();
         foreach ($oOptions->selectedColumns as $column) {
             $value = $response[$column];
             if (isset($survey->fieldMap[$column]) && $survey->fieldMap[$column]['type'] != 'answer_time' && $survey->fieldMap[$column]['type'] != 'page_time' && $survey->fieldMap[$column]['type'] != 'interview_time') {
                 switch ($oOptions->answerFormat) {
                     case 'long':
                         $elementArray[] = $this->transformResponseValue($survey->getFullAnswer($column, $value, $this->translator, $this->languageCode), $survey->fieldMap[$column]['type'], $oOptions);
                         break;
                     default:
                     case 'short':
                         $elementArray[] = $this->transformResponseValue($value, $survey->fieldMap[$column]['type'], $oOptions);
                         break;
                 }
             } else {
                 $elementArray[] = $value;
             }
         }
         if ($oOptions->output == 'display') {
             $this->outputRecord($headers, $elementArray, $oOptions);
         } else {
             $sFile .= $this->outputRecord($headers, $elementArray, $oOptions);
         }
     }
     return $sFile;
 }
コード例 #18
0
 /**
  * Show side menu for survey view
  * @param array $aData all the needed data
  */
 function _surveysidemenu($aData)
 {
     $iSurveyID = $aData['surveyid'];
     // TODO : create subfunctions
     $sumresult1 = Survey::model()->with(array('languagesettings' => array('condition' => 'surveyls_language=language')))->find('sid = :surveyid', array(':surveyid' => $aData['surveyid']));
     //$sumquery1, 1) ; //Checked
     if (Permission::model()->hasSurveyPermission($iSurveyID, 'surveycontent', 'read')) {
         $aData['permission'] = true;
     } else {
         $aData['gid'] = $gid = null;
         $qid = null;
         $aData['permission'] = false;
     }
     if (!is_null($sumresult1)) {
         $surveyinfo = $sumresult1->attributes;
         $surveyinfo = array_merge($surveyinfo, $sumresult1->defaultlanguage->attributes);
         $surveyinfo = array_map('flattenText', $surveyinfo);
         $aData['activated'] = $surveyinfo['active'] == 'Y';
         // Tokens
         $bTokenExists = tableExists('{{tokens_' . $iSurveyID . '}}');
         if (!$bTokenExists) {
             $aData['tokenmanagement'] = Permission::model()->hasSurveyPermission($iSurveyID, 'surveysettings', 'update') || Permission::model()->hasSurveyPermission($iSurveyID, 'tokens', 'create');
         } else {
             $aData['tokenmanagement'] = Permission::model()->hasSurveyPermission($iSurveyID, 'surveysettings', 'update') || Permission::model()->hasSurveyPermission($iSurveyID, 'tokens', 'create') || Permission::model()->hasSurveyPermission($iSurveyID, 'tokens', 'read') || Permission::model()->hasSurveyPermission($iSurveyID, 'tokens', 'export') || Permission::model()->hasSurveyPermission($iSurveyID, 'tokens', 'import');
             // and export / import ?
         }
         // Question explorer
         $aGroups = QuestionGroup::model()->findAllByAttributes(array('sid' => $iSurveyID, "language" => $sumresult1->defaultlanguage->surveyls_language), array('order' => 'group_order ASC'));
         if (count($aGroups)) {
             foreach ($aGroups as $group) {
                 $group->aQuestions = Question::model()->findAllByAttributes(array("sid" => $iSurveyID, "gid" => $group['gid'], "language" => $sumresult1->defaultlanguage->surveyls_language), array('order' => 'question_order ASC'));
                 foreach ($group->aQuestions as $question) {
                     if (is_object($question)) {
                         $question->question = viewHelper::flatEllipsizeText($question->question, true, 60, '[...]', 0.5);
                     }
                 }
             }
         }
         $aData['aGroups'] = $aGroups;
         $aData['surveycontent'] = Permission::model()->hasSurveyPermission($aData['surveyid'], 'surveycontent', 'read');
         $this->getController()->renderPartial("/admin/super/sidemenu", $aData);
     } else {
         Yii::app()->session['flashmessage'] = gT("Invalid survey ID");
         $this->getController()->redirect(array("admin/index"));
     }
 }
コード例 #19
0
$aColumns[] = array('header' => 'lastpage', 'name' => 'lastpage', 'type' => 'number', 'filter' => TbHtml::textField('SurveyDynamic[lastpage]', $model->lastpage));
$aColumns[] = array('header' => gT("completed"), 'name' => 'completed_filter', 'value' => '$data->completed', 'type' => 'raw', 'filter' => TbHtml::dropDownList('SurveyDynamic[completed_filter]', $model->completed_filter, array('' => gT('All'), 'Y' => gT('Yes'), 'N' => gT('No'))));
//add token to top of list if survey is not private
if ($bHaveToken) {
    $aColumns[] = array('header' => 'token', 'name' => 'token', 'type' => 'raw', 'value' => '$data->tokenForGrid');
    $aColumns[] = array('header' => gT("First name"), 'name' => 'tokens.firstname', 'id' => 'firstname', 'type' => 'raw', 'value' => '$data->firstNameForGrid', 'filter' => TbHtml::textField('SurveyDynamic[firstname_filter]', $model->firstname_filter));
    $aColumns[] = array('header' => gT("Last name"), 'name' => 'tokens.lastname', 'type' => 'raw', 'id' => 'lastname', 'value' => '$data->lastNameForGrid', 'filter' => TbHtml::textField('SurveyDynamic[lastname_filter]', $model->lastname_filter));
    $aColumns[] = array('header' => gT("Email"), 'name' => 'tokens.email', 'id' => 'email', 'filter' => TbHtml::textField('SurveyDynamic[email_filter]', $model->email_filter));
}
$aColumns[] = array('header' => 'startlanguage', 'name' => 'startlanguage');
// The column model must be built dynamically, since the columns will differ from survey to survey, depending on the questions.
// All other columns are based on the questions.
// An array to control unicity of $code (EM code)
foreach ($model->metaData->columns as $column) {
    if (!in_array($column->name, $aDefaultColumns)) {
        $colName = viewHelper::getFieldCode($fieldmap[$column->name], array('LEMcompat' => true));
        // This must be unique ......
        $base64jsonFieldMap = base64_encode(json_encode($fieldmap[$column->name]));
        $aColumns[] = array('header' => '<span data-toggle="tooltip" data-placement="bottom" title="' . quoteText(strip_tags($fieldmap[$column->name]['question'])) . '">' . $colName . ' <br/> ' . ellipsize($fieldmap[$column->name]['question'], $model->ellipsize_header_value) . '</span>', 'headerHtmlOptions' => array('style' => 'min-width: 350px;'), 'name' => $column->name, 'type' => 'raw', 'value' => '$data->getExtendedData("' . $column->name . '", "' . $language . '", "' . $base64jsonFieldMap . '")');
    }
}
$this->widget('bootstrap.widgets.TbGridView', array('dataProvider' => $model->search(), 'filter' => $model, 'columns' => $aColumns, 'itemsCssClass' => 'table-striped', 'id' => 'responses-grid', 'ajaxUpdate' => true, 'ajaxType' => 'POST', 'afterAjaxUpdate' => 'bindScrollWrapper', 'template' => "{items}\n<div id='ListPager'><div class=\"col-sm-4\" id=\"massive-action-container\">{$massiveAction}</div><div class=\"col-sm-4 pager-container \">{pager}</div><div class=\"col-sm-4 summary-container\">{summary}</div></div>", 'summaryText' => gT('Displaying {start}-{end} of {count} result(s).') . ' ' . sprintf(gT('%s rows per page'), CHtml::dropDownList('pageSize', $pageSize, Yii::app()->params['pageSizeOptions'], array('class' => 'changePageSize form-control', 'style' => 'display: inline; width: auto')))));
?>
            </div>

            <!-- To update rows per page via ajax -->
            <script type="text/javascript">
                jQuery(function($) {
                    jQuery(document).on("change", '#pageSize', function(){
                        $.fn.yiiGridView.update('responses-grid',{ data:{ pageSize: $(this).val() }});
                    });
コード例 #20
0
ファイル: banner_list.php プロジェクト: sea75300/affiliat_r
<?php

if (!defined('VIEW')) {
    die;
}
?>
<form method="post" action="">
    <div class="afltr-acp-top-buttons">
        <a href="#" class="buttons show-upload-dialog"><?php 
language::printLanguageConstant('FILES_UPLOAD');
?>
</a>
        <?php 
viewHelper::submitButton('submdelete', language::returnLanguageConstant('DELETE_BTN'), 'submdelete');
?>
    </div>
    <h2><?php 
language::printLanguageConstant('HL_LINKBUTTONS');
?>
</h2>
    <div class="afltr-acp-list">
            <table class="afltr-acp-table">
                <tr>
                    <th class="afltr-padding-left afltr-align-left"><?php 
language::printLanguageConstant('FILES_NAME');
?>
</th>
                    <th class="afltr-acp-td-w4 afltr-align-left"><?php 
language::printLanguageConstant('FILES_METAINFOS');
?>
</th>
コード例 #21
0
 function browse($iSurveyID)
 {
     $aData = $this->_getData($iSurveyID);
     extract($aData);
     $aViewUrls = array();
     $oBrowseLanguage = new Limesurvey_lang($aData['language']);
     $tokenRequest = Yii::app()->request->getParam('token', null);
     //Delete Individual answer using inrow delete buttons/links - checked
     if (Yii::app()->request->getPost('deleteanswer') && Yii::app()->request->getPost('deleteanswer') != '' && Yii::app()->request->getPost('deleteanswer') != 'marked') {
         if (Permission::model()->hasSurveyPermission($iSurveyID, 'responses', 'delete')) {
             $iResponseID = (int) Yii::app()->request->getPost('deleteanswer');
             // sanitize the value
             Response::model($iSurveyID)->findByPk($iResponseID)->delete(true);
             // delete timings if savetimings is set
             if ($aData['surveyinfo']['savetimings'] == "Y") {
                 SurveyTimingDynamic::model($iSurveyID)->deleteByPk($iResponseID);
             }
             Yii::app()->session['flashmessage'] = sprintf(gT("Response ID %s was successfully deleted."), $iResponseID);
         } else {
             Yii::app()->session['flashmessage'] = gT("Access denied!", 'js');
         }
     }
     // Marked responses -> deal with the whole batch of marked responses
     if (Yii::app()->request->getPost('markedresponses') && count(Yii::app()->request->getPost('markedresponses')) > 0) {
         // Delete the marked responses - checked
         if (Yii::app()->request->getPost('deleteanswer') && Yii::app()->request->getPost('deleteanswer') === 'marked') {
             if (Permission::model()->hasSurveyPermission($iSurveyID, 'responses', 'delete')) {
                 foreach (Response::model($iSurveyID)->findAllByPk(Yii::app()->request->getPost('markedresponses')) as $response) {
                     $response->deleteFiles();
                     // delete timings if savetimings is set
                     /**
                      * @todo Move this to the Response model.
                      */
                     if ($aData['surveyinfo']['savetimings'] == "Y") {
                         SurveyTimingDynamic::model($iSurveyID)->deleteByPk($iResponseID);
                     }
                 }
                 Response::model($iSurveyID)->deleteByPk(Yii::app()->request->getPost('markedresponses'));
                 Yii::app()->session['flashmessage'] = sprintf(ngT("%s response was successfully deleted.", "%s responses were successfully deleted.", count(Yii::app()->request->getPost('markedresponses'))), count(Yii::app()->request->getPost('markedresponses')), 'js');
             } else {
                 Yii::app()->session['flashmessage'] = $clang->gT("Access denied!", 'js');
             }
         } elseif (Yii::app()->request->getPost('downloadfile') && Yii::app()->request->getPost('downloadfile') === 'marked') {
             if (Permission::model()->hasSurveyPermission($iSurveyID, 'responses', 'read')) {
                 // Now, zip all the files in the filelist
                 $zipfilename = "Responses_for_survey_{$iSurveyID}.zip";
                 $this->_zipFiles($iSurveyID, Yii::app()->request->getPost('markedresponses'), $zipfilename);
             }
         }
     } elseif (Yii::app()->request->getPost('downloadfile') && Yii::app()->request->getPost('downloadfile') != '' && Yii::app()->request->getPost('downloadfile') !== true) {
         if (Permission::model()->hasSurveyPermission($iSurveyID, 'responses', 'read')) {
             // Now, zip all the files in the filelist
             $zipfilename = "Files_for_responses_" . Yii::app()->request->getPost('downloadfile') . ".zip";
             $this->_zipFiles($iSurveyID, Yii::app()->request->getPost('downloadfile'), $zipfilename);
         }
     } elseif (Yii::app()->request->getParam('downloadindividualfile') != '') {
         if (Permission::model()->hasSurveyPermission($iSurveyID, 'responses', 'read')) {
             $iId = (int) Yii::app()->request->getParam('id');
             $downloadindividualfile = Yii::app()->request->getParam('downloadindividualfile');
             $fieldname = Yii::app()->request->getParam('fieldname');
             $oRow = SurveyDynamic::model($iSurveyID)->findByAttributes(array('id' => $iId));
             $phparray = json_decode_ls($oRow->{$fieldname});
             for ($i = 0; $i < count($phparray); $i++) {
                 if (rawurldecode($phparray[$i]['name']) == rawurldecode($downloadindividualfile)) {
                     $file = Yii::app()->getConfig('uploaddir') . "/surveys/" . $iSurveyID . "/files/" . $phparray[$i]['filename'];
                     if (file_exists($file)) {
                         @ob_clean();
                         header('Content-Description: File Transfer');
                         header('Content-Type: application/octet-stream');
                         header('Content-Disposition: attachment; filename="' . rawurldecode($phparray[$i]['name']) . '"');
                         header('Content-Transfer-Encoding: binary');
                         header('Expires: 0');
                         header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
                         header('Pragma: public');
                         header('Content-Length: ' . filesize($file));
                         readfile($file);
                         exit;
                     } else {
                         Yii::app()->session['flashmessage'] = gT("The requested file does not exist on the server.");
                     }
                     break;
                 }
             }
         }
     }
     /**
      * fnames is used as informational array
      * it containts
      *             $fnames[] = array(<dbfieldname>, <some strange title>, <questiontext>, <group_id>, <questiontype>);
      */
     if (Permission::model()->hasSurveyPermission($iSurveyID, 'responses', 'read')) {
         if (Yii::app()->request->getPost('sql')) {
             $aViewUrls[] = 'browseallfiltered_view';
         }
         //add token to top of list if survey is not private
         if ($aData['surveyinfo']['anonymized'] == "N" && tableExists('tokens_' . $iSurveyID)) {
             if (Permission::model()->hasSurveyPermission($iSurveyID, 'tokens', 'read')) {
                 $fnames[] = array("token", $clang->gT("Token ID"), 'code' => 'token');
                 $fnames[] = array("firstname", $clang->gT("First name"), 'code' => 'firstname');
                 // or token:firstname ?
                 $fnames[] = array("lastname", $clang->gT("Last name"), 'code' => 'lastname');
                 $fnames[] = array("email", $clang->gT("Email"), 'code' => 'email');
             }
         }
         $fnames[] = array("submitdate", $clang->gT("Completed"), $clang->gT("Completed"), "0", 'D');
         $fields = createFieldMap($iSurveyID, 'full', false, false, $aData['language']);
         foreach ($fields as $fielddetails) {
             if ($fielddetails['fieldname'] == 'lastpage' || $fielddetails['fieldname'] == 'submitdate') {
                 continue;
             }
             $question = $fielddetails['question'];
             if ($fielddetails['type'] != "|") {
                 if ($fielddetails['fieldname'] == 'lastpage' || $fielddetails['fieldname'] == 'submitdate' || $fielddetails['fieldname'] == 'token') {
                     continue;
                 }
                 // no headers for time data
                 if ($fielddetails['type'] == 'interview_time') {
                     continue;
                 }
                 if ($fielddetails['type'] == 'page_time') {
                     continue;
                 }
                 if ($fielddetails['type'] == 'answer_time') {
                     continue;
                 }
                 $fnames[] = array($fielddetails['fieldname'], viewHelper::getFieldText($fielddetails), 'code' => viewHelper::getFieldCode($fielddetails, array('LEMcompat' => true)));
             } elseif ($fielddetails['aid'] !== 'filecount') {
                 $qidattributes = getQuestionAttributeValues($fielddetails['qid']);
                 for ($i = 0; $i < $qidattributes['max_num_of_files']; $i++) {
                     $filenum = sprintf($clang->gT("File %s"), $i + 1);
                     if ($qidattributes['show_title'] == 1) {
                         $fnames[] = array($fielddetails['fieldname'], "{$filenum} - {$question} (" . $clang->gT('Title') . ")", 'code' => viewHelper::getFieldCode($fielddetails) . '(title)', "type" => "|", "metadata" => "title", "index" => $i);
                     }
                     if ($qidattributes['show_comment'] == 1) {
                         $fnames[] = array($fielddetails['fieldname'], "{$filenum} - {$question} (" . $clang->gT('Comment') . ")", 'code' => viewHelper::getFieldCode($fielddetails) . '(comment)', "type" => "|", "metadata" => "comment", "index" => $i);
                     }
                     $fnames[] = array($fielddetails['fieldname'], "{$filenum} - {$question} (" . $clang->gT('File name') . ")", 'code' => viewHelper::getFieldCode($fielddetails) . '(name)', "type" => "|", "metadata" => "name", "index" => $i);
                     $fnames[] = array($fielddetails['fieldname'], "{$filenum} - {$question} (" . $clang->gT('File size') . ")", 'code' => viewHelper::getFieldCode($fielddetails) . '(size)', "type" => "|", "metadata" => "size", "index" => $i);
                     //$fnames[] = array($fielddetails['fieldname'], "File ".($i+1)." - ".$fielddetails['question']."(extension)", "type"=>"|", "metadata"=>"ext",     "index"=>$i);
                 }
             } else {
                 $fnames[] = array($fielddetails['fieldname'], $clang->gT("File count"), 'code' => viewHelper::getFieldCode($fielddetails));
             }
         }
         $fncount = count($fnames);
         $start = (int) Yii::app()->request->getParam('start', 0);
         $limit = (int) Yii::app()->request->getParam('limit', 50);
         $order = Yii::app()->request->getParam('order', 'asc');
         if (!$limit) {
             $limit = 50;
         }
         $oCriteria = new CDbCriteria();
         //Create the query
         if ($aData['surveyinfo']['anonymized'] == "N" && tableExists("{{tokens_{$iSurveyID}}}") && Permission::model()->hasSurveyPermission($iSurveyID, 'tokens', 'read')) {
             $oCriteria = SurveyDynamic::model($iSurveyID)->addTokenCriteria($oCriteria);
         }
         if (incompleteAnsFilterState() == "incomplete") {
             $oCriteria->addCondition("submitdate IS NULL");
         } elseif (incompleteAnsFilterState() == "complete") {
             $oCriteria->addCondition("submitdate IS NOT NULL");
         }
         $dtcount = SurveyDynamic::model($iSurveyID)->count($oCriteria);
         // or die("Couldn't get response data<br />");
         if ($limit > $dtcount) {
             $limit = $dtcount;
         }
         //NOW LETS SHOW THE DATA
         if (Yii::app()->request->getPost('sql') && stripcslashes(Yii::app()->request->getPost('sql')) !== "" && Yii::app()->request->getPost('sql') != "NULL") {
             $oCriteria->addCondition(stripcslashes(Yii::app()->request->getPost('sql')));
         }
         if (!is_null($tokenRequest)) {
             $oCriteria->addCondition('t.token = ' . Yii::app()->db->quoteValue($tokenRequest));
         }
         $oCriteria->order = 'id ' . ($order == 'desc' ? 'desc' : 'asc');
         $oCriteria->offset = $start;
         $oCriteria->limit = $limit;
         $dtresult = SurveyDynamic::model($iSurveyID)->findAllAsArray($oCriteria);
         $dtcount2 = count($dtresult);
         $cells = $fncount + 1;
         // Fix start if order is desc, only if actual start is 0
         if ($order == 'desc' && $start == 0) {
             $start = $dtcount - count($dtresult);
         }
         //CONTROL MENUBAR
         $last = $start - $limit;
         $next = $start + $limit;
         $end = $dtcount - $limit;
         if ($end < 0) {
             $end = 0;
         }
         if ($last < 0) {
             $last = 0;
         }
         if ($next >= $dtcount) {
             $next = $dtcount - $limit;
         }
         if ($end < 0) {
             $end = 0;
         }
         $aData['dtcount2'] = $dtcount2;
         $aData['sCompletionStateValue'] = incompleteAnsFilterState();
         $aData['start'] = $start;
         $aData['limit'] = $limit;
         $aData['last'] = $last;
         $aData['next'] = $next;
         $aData['end'] = $end;
         $aData['fncount'] = $fncount;
         $aData['fnames'] = $fnames;
         $aData['bHasFileUploadQuestion'] = hasFileUploadQuestion($iSurveyID);
         $aViewUrls[] = 'browseallheader_view';
         $bgcc = 'even';
         foreach ($dtresult as $dtrow) {
             if ($bgcc == "even") {
                 $bgcc = "odd";
             } else {
                 $bgcc = "even";
             }
             $aData['dtrow'] = $dtrow;
             $aData['bgcc'] = $bgcc;
             $aData['oBrowseLanguage'] = $oBrowseLanguage;
             $aViewUrls['browseallrow_view'][] = $aData;
         }
         $aViewUrls[] = 'browseallfooter_view';
         $this->_renderWrappedTemplate('', $aViewUrls, $aData);
     } else {
         $clang = $this->getController()->lang;
         $aData['surveyid'] = $iSurveyID;
         App()->getClientScript()->registerPackage('jquery-superfish');
         $message['title'] = $clang->gT('Access denied!');
         $message['message'] = $clang->gT('You do not have sufficient rights to access this page.');
         $message['class'] = "error";
         $this->_renderWrappedTemplate('survey', array("message" => $message), $aData);
     }
 }
コード例 #22
0
 /**
  * Show the form for Organize question groups/questions
  *
  * @todo Change function name to _showOrganizeGroupsAndQuestions?
  * @param int $iSurveyID
  * @return void
  */
 private function _showReorderForm($iSurveyID)
 {
     $surveyinfo = Survey::model()->findByPk($iSurveyID)->surveyinfo;
     $aData['title_bar']['title'] = $surveyinfo['surveyls_title'] . "(" . gT("ID") . ":" . $iSurveyID . ")";
     // Prepare data for the view
     $sBaseLanguage = Survey::model()->findByPk($iSurveyID)->language;
     LimeExpressionManager::StartSurvey($iSurveyID, 'survey');
     LimeExpressionManager::StartProcessingPage(true, Yii::app()->baseUrl);
     $aGrouplist = QuestionGroup::model()->getGroups($iSurveyID);
     $initializedReplacementFields = false;
     $aData['organizebar']['savebuttonright'] = true;
     //$aData['organizebar']['returnbutton']['url'] = $this->getController()->createUrl("admin/survey/sa/view/", array('surveyid' => $iSurveyID));
     //$aData['organizebar']['returnbutton']['text'] = gT('Return to survey summary');
     foreach ($aGrouplist as $iGID => $aGroup) {
         LimeExpressionManager::StartProcessingGroup($aGroup['gid'], false, $iSurveyID);
         if (!$initializedReplacementFields) {
             templatereplace("{SITENAME}");
             // Hack to ensure the EM sets values of LimeReplacementFields
             $initializedReplacementFields = true;
         }
         $oQuestionData = Question::model()->getQuestions($iSurveyID, $aGroup['gid'], $sBaseLanguage);
         $qs = array();
         $junk = array();
         foreach ($oQuestionData->readAll() as $q) {
             $relevance = $q['relevance'] == '' ? 1 : $q['relevance'];
             $question = '[{' . $relevance . '}] ' . $q['question'];
             LimeExpressionManager::ProcessString($question, $q['qid']);
             $q['question'] = viewHelper::stripTagsEM(LimeExpressionManager::GetLastPrettyPrintExpression());
             $q['gid'] = $aGroup['gid'];
             $qs[] = $q;
         }
         $aGrouplist[$iGID]['questions'] = $qs;
         LimeExpressionManager::FinishProcessingGroup();
     }
     LimeExpressionManager::FinishProcessingPage();
     $aData['aGroupsAndQuestions'] = $aGrouplist;
     $aData['surveyid'] = $iSurveyID;
     $this->_renderWrappedTemplate('survey', 'organizeGroupsAndQuestions_view', $aData);
 }
コード例 #23
0
 /**
  * Create HTML view of the survey, showing everything that uses EM
  * @param <type> $sid
  * @param <type> $gid
  * @param <type> $qid
  */
 public static function ShowSurveyLogicFile($sid, $gid = NULL, $qid = NULL, $LEMdebugLevel = 0, $assessments = false)
 {
     // Title
     // Welcome
     // G1, name, relevance, text
     // *Q1, name [type], relevance [validation], text, help, default, help_msg
     // SQ1, name [scale], relevance [validation], text
     // A1, code, assessment_value, text
     // End Message
     $LEM =& LimeExpressionManager::singleton();
     $LEM->sPreviewMode = 'logic';
     $aSurveyInfo = getSurveyInfo($sid, $_SESSION['LEMlang']);
     $allErrors = array();
     $warnings = 0;
     $surveyOptions = array('assessments' => $aSurveyInfo['assessments'] == 'Y', 'hyperlinkSyntaxHighlighting' => true);
     $varNamesUsed = array();
     // keeps track of whether variables have been declared
     if (!is_null($qid)) {
         $surveyMode = 'question';
         LimeExpressionManager::StartSurvey($sid, 'question', $surveyOptions, false, $LEMdebugLevel);
         $qseq = LimeExpressionManager::GetQuestionSeq($qid);
         $moveResult = LimeExpressionManager::JumpTo($qseq + 1, true, false, true);
     } else {
         if (!is_null($gid)) {
             $surveyMode = 'group';
             LimeExpressionManager::StartSurvey($sid, 'group', $surveyOptions, false, $LEMdebugLevel);
             $gseq = LimeExpressionManager::GetGroupSeq($gid);
             $moveResult = LimeExpressionManager::JumpTo($gseq + 1, true, false, true);
         } else {
             $surveyMode = 'survey';
             LimeExpressionManager::StartSurvey($sid, 'survey', $surveyOptions, false, $LEMdebugLevel);
             $moveResult = LimeExpressionManager::NavigateForwards();
         }
     }
     $qtypes = getQuestionTypeList('', 'array');
     if (is_null($moveResult) || is_null($LEM->currentQset) || count($LEM->currentQset) == 0) {
         return array('errors' => 1, 'html' => sprintf($LEM->gT('Invalid question - probably missing sub-questions or language-specific settings for language %s'), $_SESSION['LEMlang']));
     }
     $surveyname = templatereplace('{SURVEYNAME}', array('SURVEYNAME' => $aSurveyInfo['surveyls_title']));
     $out = '<div id="showlogicfilediv" ><H3>' . $LEM->gT('Logic File for Survey # ') . '[' . $LEM->sid . "]: {$surveyname}</H3>\n";
     $out .= "<table class='table' id='logicfiletable'>";
     if (is_null($gid) && is_null($qid)) {
         if ($aSurveyInfo['surveyls_description'] != '') {
             $LEM->ProcessString($aSurveyInfo['surveyls_description'], 0);
             $sPrint = $LEM->GetLastPrettyPrintExpression();
             $errClass = $LEM->em->HasErrors() ? 'LEMerror' : '';
             $out .= "<tr class='LEMgroup {$errClass}'><td colspan=2>" . $LEM->gT("Description:") . "</td><td colspan=2>" . $sPrint . "</td></tr>";
         }
         if ($aSurveyInfo['surveyls_welcometext'] != '') {
             $LEM->ProcessString($aSurveyInfo['surveyls_welcometext'], 0);
             $sPrint = $LEM->GetLastPrettyPrintExpression();
             $errClass = $LEM->em->HasErrors() ? 'LEMerror' : '';
             $out .= "<tr class='LEMgroup {$errClass}'><td colspan=2>" . $LEM->gT("Welcome:") . "</td><td colspan=2>" . $sPrint . "</td></tr>";
         }
         if ($aSurveyInfo['surveyls_endtext'] != '') {
             $LEM->ProcessString($aSurveyInfo['surveyls_endtext']);
             $sPrint = $LEM->GetLastPrettyPrintExpression();
             $errClass = $LEM->em->HasErrors() ? 'LEMerror' : '';
             $out .= "<tr class='LEMgroup {$errClass}'><td colspan=2>" . $LEM->gT("End message:") . "</td><td colspan=2>" . $sPrint . "</td></tr>";
         }
         if ($aSurveyInfo['surveyls_url'] != '') {
             $LEM->ProcessString($aSurveyInfo['surveyls_urldescription'] . " - " . $aSurveyInfo['surveyls_url']);
             $sPrint = $LEM->GetLastPrettyPrintExpression();
             $errClass = $LEM->em->HasErrors() ? 'LEMerror' : '';
             $out .= "<tr class='LEMgroup {$errClass}'><td colspan=2>" . $LEM->gT("End URL:") . "</td><td colspan=2>" . $sPrint . "</td></tr>";
         }
     }
     $out .= "<tr><th>#</th><th>" . $LEM->gT('Name [ID]') . "</th><th>" . $LEM->gT('Relevance [Validation] (Default value)') . "</th><th>" . $LEM->gT('Text [Help] (Tip)') . "</th></tr>\n";
     $_gseq = -1;
     foreach ($LEM->currentQset as $q) {
         $gseq = $q['info']['gseq'];
         $gid = $q['info']['gid'];
         $qid = $q['info']['qid'];
         $qseq = $q['info']['qseq'];
         $errorCount = 0;
         //////
         // SHOW GROUP-LEVEL INFO
         //////
         if ($gseq != $_gseq) {
             $LEM->ParseResultCache = array();
             // reset for each group so get proper color coding?
             $_gseq = $gseq;
             $ginfo = $LEM->gseq2info[$gseq];
             $grelevance = '{' . ($ginfo['grelevance'] == '' ? 1 : $ginfo['grelevance']) . '}';
             $gtext = trim($ginfo['description']) == '' ? '&nbsp;' : $ginfo['description'];
             $editlink = Yii::app()->getController()->createUrl('admin/questiongroups/sa/view/surveyid/' . $LEM->sid . '/gid/' . $gid);
             $groupRow = "<tr class='LEMgroup'>" . "<td>G-{$gseq}</td>" . "<td><b>" . $ginfo['group_name'] . "</b><br />[<a target='_blank' href='{$editlink}'>GID " . $gid . "</a>]</td>" . "<td>" . $grelevance . "</td>" . "<td>" . $gtext . "</td>" . "</tr>\n";
             $LEM->ProcessString($groupRow, $qid, NULL, false, 1, 1, false, false);
             $out .= $LEM->GetLastPrettyPrintExpression();
             if ($LEM->em->HasErrors()) {
                 ++$errorCount;
             }
         }
         //////
         // SHOW QUESTION-LEVEL INFO
         //////
         $mandatory = $q['info']['mandatory'] == 'Y' ? "<span class='mandatory'>*</span>" : '';
         $type = $q['info']['type'];
         $typedesc = $qtypes[$type]['description'];
         $sgqas = explode('|', $q['sgqa']);
         if (count($sgqas) == 1 && !is_null($q['info']['default'])) {
             $LEM->ProcessString($q['info']['default'], $qid, NULL, false, 1, 1, false, false);
             // Default value is Y or answer code or go to input/textarea, then we can filter it
             $_default = $LEM->GetLastPrettyPrintExpression();
             if ($LEM->em->HasErrors()) {
                 ++$errorCount;
             }
             $default = '<br />(' . $LEM->gT('Default:') . '  ' . viewHelper::filterScript($_default) . ')';
         } else {
             $default = '';
         }
         $qtext = $q['info']['qtext'] != '' ? $q['info']['qtext'] : '&nbsp';
         $help = $q['info']['help'] != '' ? '<hr/>[' . $LEM->gT("Help:") . ' ' . $q['info']['help'] . ']' : '';
         $prettyValidTip = $q['prettyValidTip'] == '' ? '' : '<hr/>(' . $LEM->gT("Tip:") . ' ' . $q['prettyValidTip'] . ')';
         //////
         // SHOW QUESTION ATTRIBUTES THAT ARE PROCESSED BY EM
         //////
         $attrTable = '';
         $attrs = isset($LEM->qattr[$qid]) ? $LEM->qattr[$qid] : array();
         if (isset($LEM->q2subqInfo[$qid]['preg'])) {
             $attrs['regex_validation'] = $LEM->q2subqInfo[$qid]['preg'];
         }
         if (isset($LEM->questionSeq2relevance[$qseq]['other'])) {
             $attrs['other'] = $LEM->questionSeq2relevance[$qseq]['other'];
         }
         if (count($attrs) > 0) {
             $attrTable = "<table class='table' id='logicfileattributetable'><tr><th>" . $LEM->gT("Question attribute") . "</th><th>" . $LEM->gT("Value") . "</th></tr>\n";
             $count = 0;
             foreach ($attrs as $key => $value) {
                 if (is_null($value) || trim($value) == '') {
                     continue;
                 }
                 switch ($key) {
                     // @todo: Rather compares the current attribute value to the defaults in the question attributes array to decide which ones should show (only the ones that are non-standard)
                     default:
                     case 'exclude_all_others':
                     case 'exclude_all_others_auto':
                     case 'hidden':
                         if ($value == false || $value == '0') {
                             $value = NULL;
                             // so can skip this one - just using continue here doesn't work.
                         }
                         break;
                     case 'time_limit_action':
                         if ($value == '1') {
                             $value = NULL;
                             // so can skip this one - just using continue here doesn't work.
                         }
                     case 'relevance':
                         $value = NULL;
                         // means an outdate database structure
                         break;
                     case 'array_filter':
                     case 'array_filter_exclude':
                     case 'code_filter':
                     case 'date_max':
                     case 'date_min':
                     case 'em_validation_q_tip':
                     case 'em_validation_sq_tip':
                         break;
                     case 'equals_num_value':
                     case 'em_validation_q':
                     case 'em_validation_sq':
                     case 'max_answers':
                     case 'max_num_value':
                     case 'max_num_value_n':
                     case 'min_answers':
                     case 'min_num_value':
                     case 'min_num_value_n':
                     case 'min_num_of_files':
                     case 'max_num_of_files':
                     case 'multiflexible_max':
                     case 'multiflexible_min':
                     case 'slider_accuracy':
                     case 'slider_min':
                     case 'slider_max':
                     case 'slider_default':
                         $value = '{' . $value . '}';
                         break;
                     case 'other_replace_text':
                     case 'show_totals':
                     case 'regex_validation':
                         break;
                     case 'other':
                         if ($value == 'N') {
                             $value = NULL;
                             // so can skip this one
                         }
                         break;
                 }
                 if (is_null($value)) {
                     continue;
                     // since continuing from within a switch statement doesn't work
                 }
                 ++$count;
                 $attrTable .= "<tr><td>{$key}</td><td>{$value}</td></tr>\n";
             }
             $attrTable .= "</table>\n";
             if ($count == 0) {
                 $attrTable = '';
             }
         }
         $LEM->ProcessString($qtext . $help . $prettyValidTip . $attrTable, $qid, NULL, false, 1, 1, false, false);
         $qdetails = viewHelper::filterScript($LEM->GetLastPrettyPrintExpression());
         if ($LEM->em->HasErrors()) {
             ++$errorCount;
         }
         //////
         // SHOW RELEVANCE
         //////
         // Must parse Relevance this way, otherwise if try to first split expressions, regex equations won't work
         $relevanceEqn = $q['info']['relevance'] == '' ? 1 : $q['info']['relevance'];
         if (!isset($LEM->ParseResultCache[$relevanceEqn])) {
             $result = $LEM->em->ProcessBooleanExpression($relevanceEqn, $gseq, $qseq);
             $prettyPrint = $LEM->em->GetPrettyPrintString();
             $hasErrors = $LEM->em->HasErrors();
             $LEM->ParseResultCache[$relevanceEqn] = array('result' => $result, 'prettyprint' => $prettyPrint, 'hasErrors' => $hasErrors);
         }
         $relevance = $LEM->ParseResultCache[$relevanceEqn]['prettyprint'];
         if ($LEM->ParseResultCache[$relevanceEqn]['hasErrors']) {
             ++$errorCount;
         }
         //////
         // SHOW VALIDATION EQUATION
         //////
         // Must parse Validation this way so that regex (preg) works
         $prettyValidEqn = '';
         if ($q['prettyValidEqn'] != '') {
             $validationEqn = $q['validEqn'];
             if (!isset($LEM->ParseResultCache[$validationEqn])) {
                 $result = $LEM->em->ProcessBooleanExpression($validationEqn, $gseq, $qseq);
                 $prettyPrint = $LEM->em->GetPrettyPrintString();
                 $hasErrors = $LEM->em->HasErrors();
                 $LEM->ParseResultCache[$validationEqn] = array('result' => $result, 'prettyprint' => $prettyPrint, 'hasErrors' => $hasErrors);
             }
             $prettyValidEqn = '<hr/>(VALIDATION: ' . $LEM->ParseResultCache[$validationEqn]['prettyprint'] . ')';
             if ($LEM->ParseResultCache[$validationEqn]['hasErrors']) {
                 ++$errorCount;
             }
         }
         //////
         // TEST VALIDITY OF ROOT VARIABLE NAME AND WHETHER HAS BEEN USED
         //////
         $rootVarName = $q['info']['rootVarName'];
         $varNameErrorMsg = '';
         $varNameError = NULL;
         if (isset($varNamesUsed[$rootVarName])) {
             $varNameErrorMsg .= $LEM->gT('This variable name has already been used.');
         } else {
             $varNamesUsed[$rootVarName] = array('gseq' => $gseq, 'qid' => $qid);
         }
         if (!preg_match('/^[a-zA-Z][0-9a-zA-Z]*$/', $rootVarName)) {
             $varNameErrorMsg .= $LEM->gT('Starting in 2.05, variable names should only contain letters and numbers; and may not start with a number. This variable name is deprecated.');
         }
         if ($varNameErrorMsg != '') {
             $varNameError = array('message' => $varNameErrorMsg, 'gseq' => $varNamesUsed[$rootVarName]['gseq'], 'qid' => $varNamesUsed[$rootVarName]['qid'], 'gid' => $gid);
             if (!$LEM->sgqaNaming) {
                 ++$errorCount;
             } else {
                 ++$warnings;
             }
         }
         //////
         // SHOW ALL SUB-QUESTIONS
         //////
         $sqRows = '';
         $i = 0;
         $sawThis = array();
         // array of rowdivids already seen so only show them once
         foreach ($sgqas as $sgqa) {
             if ($LEM->knownVars[$sgqa]['qcode'] == $rootVarName) {
                 continue;
                 // so don't show the main question as a sub-question too
             }
             $rowdivid = $sgqa;
             $varName = $LEM->knownVars[$sgqa]['qcode'];
             switch ($q['info']['type']) {
                 case '1':
                     if (preg_match('/#1$/', $sgqa)) {
                         $rowdivid = NULL;
                         // so that doesn't show same message for second scale
                     } else {
                         $rowdivid = substr($sgqa, 0, -2);
                         // strip suffix
                         $varName = substr($LEM->knownVars[$sgqa]['qcode'], 0, -2);
                     }
                     break;
                 case 'P':
                     if (preg_match('/comment$/', $sgqa)) {
                         $rowdivid = NULL;
                     }
                     break;
                 case ':':
                 case ';':
                     $_rowdivid = $LEM->knownVars[$sgqa]['rowdivid'];
                     if (isset($sawThis[$qid . '~' . $_rowdivid])) {
                         $rowdivid = NULL;
                         // so don't show again
                     } else {
                         $sawThis[$qid . '~' . $_rowdivid] = true;
                         $rowdivid = $_rowdivid;
                         $sgqa_len = strlen($sid . 'X' . $gid . 'X' . $qid);
                         $varName = $rootVarName . '_' . substr($_rowdivid, $sgqa_len);
                     }
             }
             if (is_null($rowdivid)) {
                 continue;
             }
             ++$i;
             $subQeqn = '&nbsp;';
             if (isset($LEM->subQrelInfo[$qid][$rowdivid])) {
                 $sq = $LEM->subQrelInfo[$qid][$rowdivid];
                 $subQeqn = $sq['prettyPrintEqn'];
                 // {' . $sq['eqn'] . '}';  // $sq['prettyPrintEqn'];
                 if ($sq['hasErrors']) {
                     ++$errorCount;
                 }
             }
             $sgqaInfo = $LEM->knownVars[$sgqa];
             $subqText = $sgqaInfo['subqtext'];
             if (isset($sgqaInfo['default']) && $sgqaInfo['default'] !== '') {
                 $LEM->ProcessString(htmlspecialchars($sgqaInfo['default']), $qid, NULL, false, 1, 1, false, false);
                 $_default = viewHelper::filterScript($LEM->GetLastPrettyPrintExpression());
                 if ($LEM->em->HasErrors()) {
                     ++$errorCount;
                 }
                 $subQeqn .= '<br />(' . $LEM->gT('Default:') . '  ' . $_default . ')';
             }
             $sqRows .= "<tr class='LEMsubq'>" . "<td>SQ-{$i}</td>" . "<td><b>" . $varName . "</b></td>" . "<td>{$subQeqn}</td>" . "<td>" . $subqText . "</td>" . "</tr>";
         }
         $LEM->ProcessString($sqRows, $qid, NULL, false, 1, 1, false, false);
         $sqRows = viewHelper::filterScript($LEM->GetLastPrettyPrintExpression());
         if ($LEM->em->HasErrors()) {
             ++$errorCount;
         }
         //////
         // SHOW ANSWER OPTIONS FOR ENUMERATED LISTS, AND FOR MULTIFLEXI
         //////
         $answerRows = '';
         if (isset($LEM->qans[$qid]) || isset($LEM->multiflexiAnswers[$qid])) {
             $_scale = -1;
             if (isset($LEM->multiflexiAnswers[$qid])) {
                 $ansList = $LEM->multiflexiAnswers[$qid];
             } else {
                 $ansList = $LEM->qans[$qid];
             }
             foreach ($ansList as $ans => $value) {
                 $ansInfo = explode('~', $ans);
                 $valParts = explode('|', $value);
                 $valInfo[0] = array_shift($valParts);
                 $valInfo[1] = implode('|', $valParts);
                 if ($_scale != $ansInfo[0]) {
                     $i = 1;
                     $_scale = $ansInfo[0];
                 }
                 $subQeqn = '';
                 $rowdivid = $sgqas[0] . $ansInfo[1];
                 if ($q['info']['type'] == 'R') {
                     $rowdivid = $LEM->sid . 'X' . $gid . 'X' . $qid . $ansInfo[1];
                 }
                 if (isset($LEM->subQrelInfo[$qid][$rowdivid])) {
                     $sq = $LEM->subQrelInfo[$qid][$rowdivid];
                     $subQeqn = ' ' . $sq['prettyPrintEqn'];
                     if ($sq['hasErrors']) {
                         ++$errorCount;
                     }
                 }
                 $answerRows .= "<tr class='LEManswer'>" . "<td>A[" . $ansInfo[0] . "]-" . $i++ . "</td>" . "<td><b>" . $ansInfo[1] . "</b></td>" . "<td>[VALUE: " . $valInfo[0] . "]" . $subQeqn . "</td>" . "<td>" . $valInfo[1] . "</td>" . "</tr>\n";
             }
             $LEM->ProcessString($answerRows, $qid, NULL, false, 1, 1, false, false);
             $answerRows = viewHelper::filterScript($LEM->GetLastPrettyPrintExpression());
             if ($LEM->em->HasErrors()) {
                 ++$errorCount;
             }
         }
         //////
         // FINALLY, SHOW THE QUESTION ROW(S), COLOR-CODING QUESTIONS THAT CONTAIN ERRORS
         //////
         $errclass = $errorCount > 0 ? "class='LEMerror' title='" . $LEM->ngT("This question has at least {n} error.|This question has at least {n} errors.", $errorCount) . "'" : '';
         $questionRow = "<tr class='LEMquestion'>" . "<td {$errclass}>Q-" . $q['info']['qseq'] . "</td>" . "<td><b>" . $mandatory;
         if ($varNameErrorMsg == '') {
             $questionRow .= $rootVarName;
         } else {
             $editlink = Yii::app()->getController()->createUrl('admin/questions/sa/view/surveyid/' . $LEM->sid . '/gid/' . $varNameError['gid'] . '/qid/' . $varNameError['qid']);
             $questionRow .= "<span class='highlighterror' title='" . $varNameError['message'] . "' " . "onclick='window.open(\"{$editlink}\",\"_blank\")'>" . $rootVarName . "</span>";
         }
         $editlink = Yii::app()->getController()->createUrl('admin/questions/sa/view/surveyid/' . $sid . '/gid/' . $gid . '/qid/' . $qid);
         $questionRow .= "</b><br />[<a target='_blank' href='{$editlink}'>QID {$qid}</a>]<br/>{$typedesc} [{$type}]</td>" . "<td>" . $relevance . $prettyValidEqn . $default . "</td>" . "<td>" . $qdetails . "</td>" . "</tr>\n";
         $out .= $questionRow;
         $out .= $sqRows;
         $out .= $answerRows;
         if ($errorCount > 0) {
             $allErrors[$gid . '~' . $qid] = $errorCount;
         }
     }
     $out .= "</table>";
     LimeExpressionManager::FinishProcessingPage();
     if (($LEMdebugLevel & LEM_DEBUG_TIMING) == LEM_DEBUG_TIMING) {
         $out .= LimeExpressionManager::GetDebugTimingMessage();
     }
     if (count($allErrors) > 0) {
         $out = "<p class='LEMerror'>" . $LEM->ngT("{n} question contains errors that need to be corrected.|{n} questions contain errors that need to be corrected.", count($allErrors)) . "</p>\n" . $out;
     } else {
         switch ($surveyMode) {
             case 'survey':
                 $message = $LEM->gT('No syntax errors detected in this survey.');
                 break;
             case 'group':
                 $message = $LEM->gT('This group, by itself, does not contain any syntax errors.');
                 break;
             case 'question':
                 $message = $LEM->gT('This question, by itself, does not contain any syntax errors.');
                 break;
         }
         $out = "<p class='LEMheading'>{$message}</p>\n" . $out . "</div>";
     }
     return array('errors' => $allErrors, 'html' => $out);
 }
コード例 #24
0
ファイル: options.php プロジェクト: sea75300/affiliat_r
 class="afltr-hide"<?php 
    }
    ?>
>
                <td class="afltr-td-label afltr-align-right">
                    <?php 
    language::printLanguageConstant('OPTIONS_' . strtoupper($key));
    ?>
:
                </td>
                <td class="afltr-padding-left afltr-align-left">
                <?php 
    if ($key == 'timeZone') {
        ?>
                    <?php 
        viewHelper::select('options[timeZone]', $timeZones, $value, false, false);
        ?>
                <?php 
    } elseif ($key == 'dateTimeMask') {
        ?>
                                    
                    <input type="text" class="input-text afltr-options-input-<?php 
        print strtolower($key);
        ?>
 ui-state-default ui-corner-all" name="options[<?php 
        print $key;
        ?>
]" size="50" maxlength="255" value="<?php 
        print $value;
        ?>
" title="<?php 
コード例 #25
0
ファイル: responses.php プロジェクト: BertHankes/LimeSurvey
 /**
  * @deprecated
  * */
 function oldbrowse($iSurveyID)
 {
     $aData = $this->_getData($iSurveyID);
     extract($aData);
     $aViewUrls = array();
     $sBrowseLanguage = $aData['language'];
     $tokenRequest = Yii::app()->request->getParam('token', null);
     /**
      * fnames is used as informational array
      * it containts
      *             $fnames[] = array(<dbfieldname>, <some strange title>, <questiontext>, <group_id>, <questiontype>);
      */
     if (Permission::model()->hasSurveyPermission($iSurveyID, 'responses', 'read')) {
         if (Yii::app()->request->getPost('sql')) {
             $aViewUrls[] = 'browseallfiltered_view';
         }
         //add token to top of list if survey is not private
         if ($aData['surveyinfo']['anonymized'] == "N" && tableExists('tokens_' . $iSurveyID)) {
             if (Permission::model()->hasSurveyPermission($iSurveyID, 'tokens', 'read')) {
                 $fnames[] = array("token", gT("Token ID"), 'code' => 'token');
                 $fnames[] = array("firstname", gT("First name"), 'code' => 'firstname');
                 // or token:firstname ?
                 $fnames[] = array("lastname", gT("Last name"), 'code' => 'lastname');
                 $fnames[] = array("email", gT("Email"), 'code' => 'email');
             }
         }
         $fnames[] = array("submitdate", gT("Completed"), gT("Completed"), "0", 'D');
         $fields = createFieldMap($iSurveyID, 'full', false, false, $aData['language']);
         foreach ($fields as $fielddetails) {
             if ($fielddetails['fieldname'] == 'lastpage' || $fielddetails['fieldname'] == 'submitdate') {
                 continue;
             }
             $question = $fielddetails['question'];
             if ($fielddetails['type'] != "|") {
                 if ($fielddetails['fieldname'] == 'lastpage' || $fielddetails['fieldname'] == 'submitdate' || $fielddetails['fieldname'] == 'token') {
                     continue;
                 }
                 // no headers for time data
                 if ($fielddetails['type'] == 'interview_time') {
                     continue;
                 }
                 if ($fielddetails['type'] == 'page_time') {
                     continue;
                 }
                 if ($fielddetails['type'] == 'answer_time') {
                     continue;
                 }
                 $fnames[] = array($fielddetails['fieldname'], viewHelper::getFieldText($fielddetails), 'code' => viewHelper::getFieldCode($fielddetails, array('LEMcompat' => true)));
             } elseif ($fielddetails['aid'] !== 'filecount') {
                 $qidattributes = getQuestionAttributeValues($fielddetails['qid']);
                 for ($i = 0; $i < $qidattributes['max_num_of_files']; $i++) {
                     $filenum = sprintf(gT("File %s"), $i + 1);
                     if ($qidattributes['show_title'] == 1) {
                         $fnames[] = array($fielddetails['fieldname'], "{$filenum} - {$question} (" . gT('Title') . ")", 'code' => viewHelper::getFieldCode($fielddetails) . '(title)', "type" => "|", "metadata" => "title", "index" => $i);
                     }
                     if ($qidattributes['show_comment'] == 1) {
                         $fnames[] = array($fielddetails['fieldname'], "{$filenum} - {$question} (" . gT('Comment') . ")", 'code' => viewHelper::getFieldCode($fielddetails) . '(comment)', "type" => "|", "metadata" => "comment", "index" => $i);
                     }
                     $fnames[] = array($fielddetails['fieldname'], "{$filenum} - {$question} (" . gT('File name') . ")", 'code' => viewHelper::getFieldCode($fielddetails) . '(name)', "type" => "|", "metadata" => "name", "index" => $i);
                     $fnames[] = array($fielddetails['fieldname'], "{$filenum} - {$question} (" . gT('File size') . ")", 'code' => viewHelper::getFieldCode($fielddetails) . '(size)', "type" => "|", "metadata" => "size", "index" => $i);
                     //$fnames[] = array($fielddetails['fieldname'], "File ".($i+1)." - ".$fielddetails['question']."(extension)", "type"=>"|", "metadata"=>"ext",     "index"=>$i);
                 }
             } else {
                 $fnames[] = array($fielddetails['fieldname'], gT("File count"), 'code' => viewHelper::getFieldCode($fielddetails));
             }
         }
         $fncount = count($fnames);
         $start = (int) Yii::app()->request->getParam('start', 0);
         $limit = (int) Yii::app()->request->getParam('limit', 50);
         $order = Yii::app()->request->getParam('order', 'asc');
         if (!$limit) {
             $limit = 50;
         }
         $oCriteria = new CDbCriteria();
         //Create the query
         if ($aData['surveyinfo']['anonymized'] == "N" && tableExists("{{tokens_{$iSurveyID}}}") && Permission::model()->hasSurveyPermission($iSurveyID, 'tokens', 'read')) {
             $oCriteria = SurveyDynamic::model($iSurveyID)->addTokenCriteria($oCriteria);
         }
         if (incompleteAnsFilterState() == "incomplete") {
             $oCriteria->addCondition("submitdate IS NULL");
         } elseif (incompleteAnsFilterState() == "complete") {
             $oCriteria->addCondition("submitdate IS NOT NULL");
         }
         $dtcount = SurveyDynamic::model($iSurveyID)->count($oCriteria);
         // or die("Couldn't get response data<br />");
         if ($limit > $dtcount) {
             $limit = $dtcount;
         }
         //NOW LETS SHOW THE DATA
         if (Yii::app()->request->getPost('sql') && stripcslashes(Yii::app()->request->getPost('sql')) !== "" && Yii::app()->request->getPost('sql') != "NULL") {
             $oCriteria->addCondition(stripcslashes(Yii::app()->request->getPost('sql')));
         }
         if (!is_null($tokenRequest)) {
             $oCriteria->addCondition('t.token = ' . Yii::app()->db->quoteValue($tokenRequest));
         }
         $oCriteria->order = 'id ' . ($order == 'desc' ? 'desc' : 'asc');
         $oCriteria->offset = $start;
         $oCriteria->limit = $limit;
         $dtresult = SurveyDynamic::model($iSurveyID)->findAllAsArray($oCriteria);
         $dtcount2 = count($dtresult);
         $cells = $fncount + 1;
         // Fix start if order is desc, only if actual start is 0
         if ($order == 'desc' && $start == 0) {
             $start = $dtcount - count($dtresult);
         }
         //CONTROL MENUBAR
         $last = $start - $limit;
         $next = $start + $limit;
         $end = $dtcount - $limit;
         if ($end < 0) {
             $end = 0;
         }
         if ($last < 0) {
             $last = 0;
         }
         if ($next >= $dtcount) {
             $next = $dtcount - $limit;
         }
         if ($end < 0) {
             $end = 0;
         }
         $aData['dtcount2'] = $dtcount2;
         $aData['sCompletionStateValue'] = incompleteAnsFilterState();
         $aData['start'] = $start;
         $aData['limit'] = $limit;
         $aData['last'] = $last;
         $aData['next'] = $next;
         $aData['end'] = $end;
         $aData['fncount'] = $fncount;
         $aData['fnames'] = $fnames;
         $aData['bHasFileUploadQuestion'] = hasFileUploadQuestion($iSurveyID);
         $aViewUrls[] = 'browseallheader_view';
         $bgcc = 'even';
         foreach ($dtresult as $dtrow) {
             if ($bgcc == "even") {
                 $bgcc = "odd";
             } else {
                 $bgcc = "even";
             }
             $aData['dtrow'] = $dtrow;
             $aData['bgcc'] = $bgcc;
             $aData['sBrowseLanguage'] = $sBrowseLanguage;
             $aViewUrls['browseallrow_view'][] = $aData;
         }
         $aViewUrls[] = 'browseallfooter_view';
         $this->_renderWrappedTemplate('', $aViewUrls, $aData);
     } else {
         $aData['surveyid'] = $iSurveyID;
         $message['title'] = gT('Access denied!');
         $message['message'] = gT('You do not have sufficient rights to access this page.');
         $message['class'] = "error";
         $this->_renderWrappedTemplate('survey', array("message" => $message), $aData);
     }
 }
コード例 #26
0
ファイル: login.php プロジェクト: sea75300/affiliat_r
<?php

if (!defined('VIEW')) {
    die;
}
?>
<div class="afltr-login-form">
    <form method="post" action="">            
        <?php 
language::printLanguageConstant('LOGIN_PASSWORT');
?>
<br>
        <input type="password" class="input-text ui-state-default ui-corner-all" name="passwd" size="50" maxlength="255" value="<?php 
print $defaultPW;
?>
">
        <?php 
viewHelper::submitButton('submpass', language::returnLanguageConstant('LOGIN_BTN'));
?>
<br>
        <div class="afltr-align-center afltr-padding-top small-text"><?php 
language::printLanguageConstant('LOGIN_RESET_PASSWORD');
?>
</div>
    </form>      
</div>
コード例 #27
0
function group_export($action, $iSurveyID, $gid)
{
    $fn = "limesurvey_group_{$gid}.lsg";
    $xml = getXMLWriter();
    viewHelper::disableHtmlLogging();
    header("Content-Type: application/force-download");
    header("Content-Disposition: attachment; filename={$fn}");
    header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
    // Date in the past
    header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
    header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
    header("Pragma: cache");
    // HTTP/1.0
    $xml->openUri('php://output');
    $xml->setIndent(true);
    $xml->startDocument('1.0', 'UTF-8');
    $xml->startElement('document');
    $xml->writeElement('LimeSurveyDocType', 'Group');
    $xml->writeElement('DBVersion', getGlobalSetting("DBVersion"));
    $xml->startElement('languages');
    $lresult = QuestionGroup::model()->findAllByAttributes(array('gid' => $gid), array('select' => 'language', 'group' => 'language'));
    foreach ($lresult as $row) {
        $xml->writeElement('language', $row->language);
    }
    $xml->endElement();
    groupGetXMLStructure($xml, $gid);
    $xml->endElement();
    // close columns
    $xml->endDocument();
}
コード例 #28
0
 function createStataFieldmap($survey, $sLanguage, $oOptions)
 {
     App()->setLanguage($sLanguage);
     $yvalue = $oOptions->convertY ? $oOptions->yValue : '1';
     // set value for Y if it is set in export settings (needed for correct value label)
     $nvalue = $oOptions->convertN ? $oOptions->nValue : '2';
     // set value for N if it is set in export settings (needed for correct value label)
     //create fieldmap only with the columns (variables) selected
     $aFieldmap['questions'] = array_intersect_key($survey->fieldMap, array_flip($oOptions->selectedColumns));
     //tokens need to be "smuggled" into the fieldmap as additional questions
     $aFieldmap['tokenFields'] = array_intersect_key($survey->tokenFields, array_flip($oOptions->selectedColumns));
     foreach ($aFieldmap['tokenFields'] as $key => $value) {
         $aFieldmap['questions'][$key] = $value;
         $aFieldmap['questions'][$key]['qid'] = '';
         $aFieldmap['questions'][$key]['question'] = $value['description'];
         $aFieldmap['questions'][$key]['fieldname'] = $key;
         $aFieldmap['questions'][$key]['type'] = 'S';
     }
     // add only questions and answers to the fieldmap that are relevant to the selected columns (variables)
     foreach ($aFieldmap['questions'] as $question) {
         $aUsedQIDs[] = $question['qid'];
     }
     $aFieldmap['answers'] = array_intersect_key($survey->answers, array_flip($aUsedQIDs));
     // add per-survey info
     $aFieldmap['info'] = $survey->info;
     // STATA only uses value labels on numerical variables. If the answer codes are not numerical we later replace them with the text-answer
     // here we go through the answers-array and check whether answer-codes are numerical. If they are not, we save the respective QIDs
     // so responses can later be set to full answer test of Question or SQ'
     foreach ($aFieldmap['answers'] as $qid => $aScale) {
         foreach ($aFieldmap['answers'][$qid] as $iScale => $aAnswers) {
             foreach ($aFieldmap['answers'][$qid][$iScale] as $iAnswercode => $aAnswer) {
                 if (!is_numeric($aAnswer['code'])) {
                     $this->aQIDnonumericalAnswers[$aAnswer['qid']] = true;
                 }
             }
         }
     }
     // go through the questions array and create/modify vars for STATA-output
     foreach ($aFieldmap['questions'] as $sSGQAkey => $aQuestion) {
         // STATA does not support attaching value labels to non-numerical values
         // We therefore set a flag in questions array for non-numerical answer codes.
         // The respective codes are later recoded to contain the full answers
         if (array_key_exists($aQuestion['qid'], $this->aQIDnonumericalAnswers)) {
             $aFieldmap['questions'][$sSGQAkey]['nonnumericanswercodes'] = true;
         } else {
             $aFieldmap['questions'][$sSGQAkey]['nonnumericanswercodes'] = false;
         }
         // create 'varname' from Question/Subquestiontitles
         $aQuestion['varname'] = viewHelper::getFieldCode($aFieldmap['questions'][$sSGQAkey]);
         //set field types for standard vars
         if ($aQuestion['varname'] == 'submitdate' || $aQuestion['varname'] == 'startdate' || $aQuestion['varname'] == 'datestamp') {
             $aFieldmap['questions'][$sSGQAkey]['type'] = 'D';
         } elseif ($aQuestion['varname'] == 'startlanguage') {
             $aFieldmap['questions'][$sSGQAkey]['type'] = 'S';
         } elseif ($aQuestion['varname'] == 'token') {
             $aFieldmap['questions'][$sSGQAkey]['type'] = 'S';
         } elseif ($aQuestion['varname'] == 'id') {
             $aFieldmap['questions'][$sSGQAkey]['type'] = 'N';
         } elseif ($aQuestion['varname'] == 'ipaddr') {
             $aFieldmap['questions'][$sSGQAkey]['type'] = 'S';
         } elseif ($aQuestion['varname'] == 'refurl') {
             $aFieldmap['questions'][$sSGQAkey]['type'] = 'S';
         } elseif ($aQuestion['varname'] == 'lastpage') {
             $aFieldmap['questions'][$sSGQAkey]['type'] = 'N';
         }
         //Rename the variables if original name is not STATA-compatible
         $aQuestion['varname'] = $this->STATAvarname($aQuestion['varname']);
         // create variable labels
         $aQuestion['varlabel'] = $aQuestion['question'];
         if (isset($aQuestion['scale'])) {
             $aQuestion['varlabel'] = "[{$aQuestion['scale']}] " . $aQuestion['varlabel'];
         }
         if (isset($aQuestion['subquestion'])) {
             $aQuestion['varlabel'] = "[{$aQuestion['subquestion']}] " . $aQuestion['varlabel'];
         }
         if (isset($aQuestion['subquestion2'])) {
             $aQuestion['varlabel'] = "[{$aQuestion['subquestion2']}] " . $aQuestion['varlabel'];
         }
         if (isset($aQuestion['subquestion1'])) {
             $aQuestion['varlabel'] = "[{$aQuestion['subquestion1']}] " . $aQuestion['varlabel'];
         }
         //write varlabel back to fieldmap
         $aFieldmap['questions'][$sSGQAkey]['varlabel'] = $aQuestion['varlabel'];
         //create value labels for question types with "fixed" answers (YES/NO etc.)
         if (isset($aQuestion['other']) && $aQuestion['other'] == 'Y' || substr($aQuestion['fieldname'], -7) == 'comment') {
             $aFieldmap['questions'][$sSGQAkey]['commentother'] = true;
             //comment/other fields: create flag, so value labels are not attached (in close())
         } else {
             $aFieldmap['questions'][$sSGQAkey]['commentother'] = false;
             if ($aQuestion['type'] == 'M') {
                 $aFieldmap['answers'][$aQuestion['qid']]['0'][$yvalue] = array('code' => $yvalue, 'answer' => gT('Yes'));
                 $aFieldmap['answers'][$aQuestion['qid']]['0']['0'] = array('code' => 0, 'answer' => gT('Not Selected'));
             } elseif ($aQuestion['type'] == "P") {
                 $aFieldmap['answers'][$aQuestion['qid']]['0'][$yvalue] = array('code' => $yvalue, 'answer' => gT('Yes'));
                 $aFieldmap['answers'][$aQuestion['qid']]['0']['0'] = array('code' => 0, 'answer' => gT('Not Selected'));
             } elseif ($aQuestion['type'] == "G") {
                 $aFieldmap['answers'][$aQuestion['qid']]['0']['0'] = array('code' => 'F', 'answer' => gT('Female'));
                 $aFieldmap['answers'][$aQuestion['qid']]['0']['1'] = array('code' => 'M', 'answer' => gT('Male'));
             } elseif ($aQuestion['type'] == "Y") {
                 $aFieldmap['answers'][$aQuestion['qid']]['0'][$yvalue] = array('code' => $yvalue, 'answer' => gT('Yes'));
                 $aFieldmap['answers'][$aQuestion['qid']]['0'][$nvalue] = array('code' => $nvalue, 'answer' => gT('No'));
             } elseif ($aQuestion['type'] == "C") {
                 $aFieldmap['answers'][$aQuestion['qid']]['0']['1'] = array('code' => 1, 'answer' => gT('Yes'));
                 $aFieldmap['answers'][$aQuestion['qid']]['0']['0'] = array('code' => 2, 'answer' => gT('No'));
                 $aFieldmap['answers'][$aQuestion['qid']]['0']['9'] = array('code' => 3, 'answer' => gT('Uncertain'));
             } elseif ($aQuestion['type'] == "E") {
                 $aFieldmap['answers'][$aQuestion['qid']]['0']['1'] = array('code' => 1, 'answer' => gT('Increase'));
                 $aFieldmap['answers'][$aQuestion['qid']]['0']['0'] = array('code' => 2, 'answer' => gT('Same'));
                 $aFieldmap['answers'][$aQuestion['qid']]['0']['-1'] = array('code' => 3, 'answer' => gT('Decrease'));
             }
         }
         // close: no-other/comment variable
         $aFieldmap['questions'][$sSGQAkey]['varname'] = $aQuestion['varname'];
         //write changes back to array
     }
     // close foreach question
     // clean up fieldmap (remove HTML tags, CR/LS, etc.)
     $aFieldmap = $this->stripArray($aFieldmap);
     return $aFieldmap;
 }
コード例 #29
0
ファイル: tokens.php プロジェクト: josetorerobueno/test_repo
 /**
  * This function sends the shared participant info to the share panel using JSON encoding
  * This function is called after the share panel grid is loaded
  * This function returns the json depending on the user logged in by checking it from the session
  * @param it takes the session user data loginID
  * @return JSON encoded string containg sharing information
  */
 function getTokens_json($iSurveyId, $search = null)
 {
     // CHECK TO SEE IF A TOKEN TABLE EXISTS FOR THIS SURVEY
     $bTokenExists = tableExists('{{tokens_' . $iSurveyId . '}}');
     if (!$bTokenExists) {
         $clang->eT("No token table.");
         // return json ? error not treated in js.
         return;
     }
     $clang = $this->getController()->lang;
     if (!Permission::model()->hasSurveyPermission($iSurveyId, 'tokens', 'read')) {
         $clang->eT("We are sorry but you don't have permissions to do this.");
         // return json ? error not treated in js.
         return;
     }
     $page = Yii::app()->request->getPost('page', 1);
     $sidx = Yii::app()->request->getPost('sidx', 'lastname');
     $sord = Yii::app()->request->getPost('sord', 'asc');
     $limit = Yii::app()->request->getPost('rows', 25);
     $aData = new stdClass();
     $aData->page = $page;
     $aSearchArray = Yii::app()->request->getPost('searcharray');
     if (empty($search) && !empty($aSearchArray)) {
         $search = $aSearchArray;
     }
     if (!empty($search)) {
         $condition = TokenDynamic::model($iSurveyId)->getSearchMultipleCondition($search);
     } else {
         $condition = new CDbCriteria();
     }
     $condition->order = $sidx . " " . $sord;
     $condition->offset = ($page - 1) * $limit;
     $condition->limit = $limit;
     $tokens = Token::model($iSurveyId)->findAll($condition);
     $condition->offset = 0;
     $condition->limit = 0;
     $aData->records = Token::model($iSurveyId)->count($condition);
     if ($limit > $aData->records) {
         $limit = $aData->records;
     }
     if ($limit != 0) {
         $aData->total = ceil($aData->records / $limit);
     } else {
         $aData->total = 0;
     }
     Yii::app()->loadHelper("surveytranslator");
     $format = getDateFormatData(Yii::app()->session['dateformat']);
     $aSurveyInfo = Survey::model()->findByPk($iSurveyId)->getAttributes();
     //Get survey settings
     $attributes = getAttributeFieldNames($iSurveyId);
     // Now find all responses for the visible tokens
     $visibleTokens = array();
     $answeredTokens = array();
     if ($aSurveyInfo['anonymized'] == "N" && $aSurveyInfo['active'] == "Y") {
         foreach ($tokens as $token) {
             if (isset($token['token']) && $token['token']) {
                 $visibleTokens[] = $token['token'];
             }
         }
         $answers = SurveyDynamic::model($iSurveyId)->findAllByAttributes(array('token' => $visibleTokens));
         foreach ($answers as $answer) {
             $answeredTokens[$answer['token']] = $answer['token'];
         }
     }
     $bReadPermission = Permission::model()->hasSurveyPermission($iSurveyId, 'responses', 'read');
     $bCreatePermission = Permission::model()->hasSurveyPermission($iSurveyId, 'responses', 'create');
     $bTokenUpdatePermission = Permission::model()->hasSurveyPermission($iSurveyId, 'tokens', 'update');
     $bTokenDeletePermission = Permission::model()->hasSurveyPermission($iSurveyId, 'tokens', 'delete');
     $bGlobalPanelReadPermission = Permission::model()->hasGlobalPermission('participantpanel', 'read');
     foreach ($tokens as $token) {
         $aRowToAdd = array();
         if ((int) $token['validfrom']) {
             $token['validfrom'] = date($format['phpdate'] . ' H:i', strtotime(trim($token['validfrom'])));
         } else {
             $token['validfrom'] = '';
         }
         if ((int) $token['validuntil']) {
             $token['validuntil'] = date($format['phpdate'] . ' H:i', strtotime(trim($token['validuntil'])));
         } else {
             $token['validuntil'] = '';
         }
         $aRowToAdd['id'] = $token['tid'];
         $action = "";
         $action .= "<div class='inputbuttons'>";
         // so we can hide this when edit is clicked
         // Check is we have an answer
         if (in_array($token['token'], $answeredTokens) && $bReadPermission) {
             // @@TODO change link
             $url = $this->getController()->createUrl("admin/responses/sa/browse/surveyid/{$iSurveyId}", array('token' => $token['token']));
             $title = $clang->gT("View response details");
             $action .= CHtml::link(CHtml::image(Yii::app()->getConfig('adminimageurl') . 'token_viewanswer.png', $title, array('title' => $title)), $url, array('class' => 'imagelink'));
         } else {
             $action .= '<div style="width: 20px; height: 16px; float: left;"></div>';
         }
         // Check if the token can be taken
         if ($token['token'] != "" && ($token['completed'] == "N" || $token['completed'] == "" || $aSurveyInfo['alloweditaftercompletion'] == "Y") && $bCreatePermission) {
             $action .= viewHelper::getImageLink('do_16.png', "survey/index/sid/{$iSurveyId}/token/{$token['token']}/lang/{$token['language']}/newtest/Y", $clang->gT("Do survey"), '_blank');
         } else {
             $action .= '<div style="width: 20px; height: 16px; float: left;"></div>';
         }
         if ($bTokenDeletePermission) {
             $attribs = array('onclick' => 'if (confirm("' . $clang->gT("Are you sure you want to delete this entry?") . ' (' . $token['tid'] . ')")) {$("#displaytokens").delRowData(' . $token['tid'] . ');$.post(delUrl,{tid:' . $token['tid'] . '});}');
             $action .= viewHelper::getImageLink('token_delete.png', null, $clang->gT("Delete token entry"), null, 'imagelink btnDelete', $attribs);
         }
         if (strtolower($token['emailstatus']) == 'ok' && $token['email'] && $bTokenUpdatePermission) {
             if ($token['completed'] == 'N' && $token['usesleft'] > 0) {
                 if ($token['sent'] == 'N') {
                     $action .= viewHelper::getImageLink('token_invite.png', "admin/tokens/sa/email/surveyid/{$iSurveyId}/tokenids/" . $token['tid'], $clang->gT("Send invitation email to this person (if they have not yet been sent an invitation email)"), "_blank");
                 } else {
                     $action .= viewHelper::getImageLink('token_remind.png', "admin/tokens/sa/email/action/remind/surveyid/{$iSurveyId}/tokenids/" . $token['tid'], $clang->gT("Send reminder email to this person (if they have already received the invitation email)"), "_blank");
                 }
             } else {
                 $action .= '<div style="width: 20px; height: 16px; float: left;"></div>';
             }
         } else {
             $action .= '<div style="width: 20px; height: 16px; float: left;"></div>';
         }
         if ($bTokenUpdatePermission) {
             $action .= viewHelper::getImageLink('edit_16.png', null, $clang->gT("Edit token entry"), null, 'imagelink token_edit');
         }
         if (!empty($token['participant_id']) && $token['participant_id'] != "" && $bGlobalPanelReadPermission) {
             $action .= viewHelper::getImageLink('cpdb_16.png', null, $clang->gT("View this person in the central participants database"), null, 'imagelink cpdb', array('onclick' => "sendPost('" . $this->getController()->createUrl('admin/participants/sa/displayParticipants') . "','',['searchcondition'],['participant_id||equal||{$token['participant_id']}']);"));
         } else {
             $action .= '<div style="width: 20px; height: 16px; float: left;"></div>';
         }
         $action .= '</div>';
         $aRowToAdd['cell'] = array($token['tid'], $action, $token['firstname'], $token['lastname'], $token['email'], $token['emailstatus'], $token['token'], $token['language'], $token['sent'], $token['remindersent'], $token['remindercount'], $token['completed'], $token['usesleft'], $token['validfrom'], $token['validuntil']);
         foreach ($attributes as $attribute) {
             $aRowToAdd['cell'][] = $token[$attribute];
         }
         $aData->rows[] = $aRowToAdd;
     }
     viewHelper::disableHtmlLogging();
     header("Content-type: application/json");
     echo ls_json_encode($aData);
 }
コード例 #30
0
ファイル: category_list.php プロジェクト: sea75300/affiliat_r
    if (!empty($iconPath)) {
        ?>
<img src="<?php 
        print $iconPath;
        ?>
" alt="<?php 
        print $category->getName();
        ?>
" title="<?php 
        print $category->getName();
        ?>
"><?php 
    }
    ?>
</td>
                    <td class="afltr-acp-td-w2 afltr-align-center"><?php 
    viewHelper::boolToText($category->isPrivate());
    ?>
</td>
                    <td class="afltr-acp-td-35px afltr-align-center afltr-padding-left"><input type="checkbox" class="afltr-checkbox" name="categoryDelList[]" value="<?php 
    print $category->getId();
    ?>
"></td>
                </tr>  
            <?php 
}
?>
             
            </table>
    </div>
</form>