Beispiel #1
0
 private function _showReorderForm($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;
     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'] = 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);
 }
    ?>
</td>
<td><?php 
    echo $assess['maximum'];
    ?>
</td>
<td><?php 
    $aReplacementData = array();
    templatereplace($assess['name'], array(), $aReplacementData, 'Unspecified', false, $assess['sid']);
    echo FlattenText(LimeExpressionManager::GetLastPrettyPrintExpression(), true);
    ?>
</td>
<td><?php 
    $aReplacementData = array();
    templatereplace($assess['message'], array(), $aReplacementData, 'Unspecified', false, $assess['sid']);
    echo FlattenText(LimeExpressionManager::GetLastPrettyPrintExpression(), true);
    ?>
</td>

</tr>
<?php 
}
?>
</tbody></table>

<?php 
if (Permission::model()->hasSurveyPermission($surveyid, 'assessments', 'update') && $actionvalue == "assessmentupdate" || Permission::model()->hasSurveyPermission($surveyid, 'assessments', 'create') && $actionvalue == "assessmentadd") {
    ?>
<br />
<?php 
    echo CHtml::form(array("admin/assessments/sa/index/surveyid/{$surveyid}"), 'post', array('class' => 'form30', 'id' => 'assessmentsform', 'name' => 'assessmentsform'));
templatereplace(flattenText($surveyinfo['surveyls_welcometext']));
echo LimeExpressionManager::GetLastPrettyPrintExpression();
?>
        </td>
    </tr>
    <tr>
        <td>
            <strong><?php 
$clang->eT("End message:");
?>
</strong>
        </td>
        <td>
            <?php 
templatereplace(flattenText($surveyinfo['surveyls_endtext']));
echo LimeExpressionManager::GetLastPrettyPrintExpression();
?>
        </td>
    </tr>
    <tr>
        <td>
            <strong><?php 
$clang->eT("Administrator:");
?>
</strong>
        </td>
        <td>
            <?php 
echo flattenText("{$surveyinfo['admin']} ({$surveyinfo['adminemail']})");
?>
        </td>
    /**
     * Unit test strings containing expressions
     */
    static function UnitTestProcessStringContainingExpressions()
    {
        $vars = array('name' => array('sgqa' => 'name', 'code' => 'Peter', 'jsName' => 'java61764X1X1', 'readWrite' => 'N', 'type' => 'X', 'question' => 'What is your first/given name?', 'qseq' => 10, 'gseq' => 1), 'surname' => array('sgqa' => 'surname', 'code' => 'Smith', 'jsName' => 'java61764X1X1', 'readWrite' => 'Y', 'type' => 'X', 'question' => 'What is your last/surname?', 'qseq' => 20, 'gseq' => 1), 'age' => array('sgqa' => 'age', 'code' => 45, 'jsName' => 'java61764X1X2', 'readWrite' => 'Y', 'type' => 'X', 'question' => 'How old are you?', 'qseq' => 30, 'gseq' => 2), 'numKids' => array('sgqa' => 'numKids', 'code' => 2, 'jsName' => 'java61764X1X3', 'readWrite' => 'Y', 'type' => 'X', 'question' => 'How many kids do you have?', 'relevance' => '1', 'qid' => '40', 'qseq' => 40, 'gseq' => 2), 'numPets' => array('sgqa' => 'numPets', 'code' => 1, 'jsName' => 'java61764X1X4', 'readWrite' => 'Y', 'type' => 'X', 'question' => 'How many pets do you have?', 'qseq' => 50, 'gseq' => 2), 'gender' => array('sgqa' => 'gender', 'code' => 'M', 'jsName' => 'java61764X1X5', 'readWrite' => 'Y', 'type' => 'X', 'shown' => 'Male', 'question' => 'What is your gender (male/female)?', 'qseq' => 110, 'gseq' => 2), 'notSetYet' => array('sgqa' => 'notSetYet', 'code' => '?', 'jsName' => 'java61764X3X6', 'readWrite' => 'Y', 'type' => 'X', 'shown' => 'Unknown', 'question' => 'Who will win the next election?', 'qseq' => 200, 'gseq' => 3), '61764X1X1' => array('sgqa' => '61764X1X1', 'code' => '<Sergei>', 'jsName' => '', 'readWrite' => 'N', 'type' => 'X', 'qseq' => 70, 'gseq' => 2), '61764X1X2' => array('sgqa' => '61764X1X2', 'code' => 45, 'jsName' => '', 'readWrite' => 'N', 'type' => 'X', 'qseq' => 80, 'gseq' => 2), '61764X1X3' => array('sgqa' => '61764X1X3', 'code' => 2, 'jsName' => '', 'readWrite' => 'N', 'type' => 'X', 'qseq' => 15, 'gseq' => 1), '61764X1X4' => array('sgqa' => '61764X1X4', 'code' => 1, 'jsName' => '', 'readWrite' => 'N', 'type' => 'X', 'qseq' => 100, 'gseq' => 2), 'TOKEN:ATTRIBUTE_1' => array('code' => 'worker', 'jsName' => '', 'readWrite' => 'N', 'type' => 'X'));
        $tests = <<<EOD
This example shows escaping of the curly braces: \\{\\{test\\}\\} {if(1==1,'{{test}}', '1 is not 1?')} should not throw any errors.
<b>Here is an example of OK syntax with tooltips</b><br />Hello {if(gender=='M','Mr.','Mrs.')} {surname}, it is now {date('g:i a',time())}.  Do you know where your {sum(numPets,numKids)} chidren and pets are?
<b>Here are common errors so you can see the tooltips</b><br />Variables used before they are declared:  {notSetYet}<br />Unknown Function:  {iff(numPets>numKids,1,2)}<br />Unknown Variable: {sum(age,num_pets,numKids)}<br />Wrong # parameters: {sprintf()},{if(1,2)},{date()}<br />Assign read-only-vars:{TOKEN:ATTRIBUTE_1+=10},{name='Sally'}<br />Unbalanced parentheses: {pow(3,4},{(pow(3,4)},{pow(3,4))}
<b>Here is some of the unsupported syntax</b><br />No support for '++', '--', '%',';': {min(++age, --age,age % 2);}<br />Nor '|', '&', '^': {(sum(2 | 3,3 & 4,5 ^ 6)}}<br />Nor arrays: {name[2], name['mine']}
<b>Inline JavaScipt that forgot to add spaces after curly brace</b><br />[script type="text/javascript" language="Javascript"] var job='{TOKEN:ATTRIBUTE_1}'; if (job=='worker') {document.write('BOSSES');}[/script]
<b>Unknown/Misspelled Variables, Functions, and Operators</b><br />{if(sex=='M','Mr.','Mrs.')} {surname}, next year you will be {age++} years old.
<b>Warns if use = instead of == or perform value assignments</b><br>Hello, {if(gender='M','Mr.','Mrs.')} {surname}, next year you will be {age+=1} years old.
<b>Wrong number of arguments for functions:</b><br />{if(gender=='M','Mr.','Mrs.','Other')} {surname}, sum(age,numKids,numPets)={sum(age,numKids,numPets,)}
<b>Mismatched parentheses</b><br />pow(3,4)={pow(3,4)}<br />but these are wrong: {pow(3,4}, {(((pow(3,4)}, {pow(3,4))}
<b>Unsupported syntax</b><br />No support for '++', '--', '%',';': {min(++age, --age, age % 2);}<br />Nor '|', '&', '^':  {(sum(2 | 3, 3 & 4, 5 ^ 6)}}<br />Nor arrays:  {name[2], name['mine']}
<b>Invalid assignments</b><br />Assign values to equations or strings:  {(3 + 4)=5}, {'hi'='there'}<br />Assign read-only vars:  {TOKEN:ATTRIBUTE_1='boss'}, {name='Sally'}
<b>Values:</b><br />name={name}; surname={surname}<br />gender={gender}; age={age}; numPets={numPets}<br />numKids=INSERTANS:61764X1X3={numKids}={INSERTANS:61764X1X3}<br />TOKEN:ATTRIBUTE_1={TOKEN:ATTRIBUTE_1}
<b>Question attributes:</b><br />numKids.question={numKids.question}; Question#={numKids.qid}; .relevance={numKids.relevance}
<b>Math:</b><br/>5+7={5+7}; 2*pi={2*pi()}; sin(pi/2)={sin(pi()/2)}; max(age,numKids,numPets)={max(age,numKids,numPets)}
<b>Text Processing:</b><br />{str_replace('like','love','I like LimeSurvey')}<br />{ucwords('hi there')}, {name}<br />{implode('--',name,'this is','a convenient way','way to','concatenate strings')}
<b>Dates:</b><br />{name}, the current date/time is: {date('F j, Y, g:i a',time())}
<b>Conditional:</b><br />Hello, {if(gender=='M','Mr.','Mrs.')} {surname}, may I call you {name}?
<b>Tailored Paragraph:</b><br />{name}, you said that you are {age} years old, and that you have {numKids} {if((numKids==1),'child','children')} and {numPets} {if((numPets==1),'pet','pets')} running around the house. So, you have {numKids + numPets} wild {if((numKids + numPets ==1),'beast','beasts')} to chase around every day.<p>Since you have more {if((numKids > numPets),'children','pets')} than you do {if((numKids > numPets),'pets','children')}, do you feel that the {if((numKids > numPets),'pets','children')} are at a disadvantage?</p>
<b>EM processes within strings:</b><br />Here is your picture [img src='images/users_{name}_{surname}.jpg' alt='{if(gender=='M','Mr.','Mrs.')} {name} {surname}'/];
<b>EM doesn't process curly braces like these:</b><br />{name}, { this is not an expression}<br />{nor is this }, { nor  this }<br />\\{nor this\\},{this\\},\\{or this }
{INSERTANS:61764X1X1}, you said that you are {INSERTANS:61764X1X2} years old, and that you have {INSERTANS:61764X1X3} {if((INSERTANS:61764X1X3==1),'child','children')} and {INSERTANS:61764X1X4} {if((INSERTANS:61764X1X4==1),'pet','pets')} running around the house.  So, you have {INSERTANS:61764X1X3 + INSERTANS:61764X1X4} wild {if((INSERTANS:61764X1X3 + INSERTANS:61764X1X4 ==1),'beast','beasts')} to chase around every day.
Since you have more {if((INSERTANS:61764X1X3 > INSERTANS:61764X1X4),'children','pets')} than you do {if((INSERTANS:61764X1X3 > INSERTANS:61764X1X4),'pets','children')}, do you feel that the {if((INSERTANS:61764X1X3 > INSERTANS:61764X1X4),'pets','children')} are at a disadvantage?
{INSERTANS:61764X1X1}, you said that you are {INSERTANS:61764X1X2} years old, and that you have {INSERTANS:61764X1X3} {if((INSERTANS:61764X1X3==1),'child','children','kiddies')} and {INSERTANS:61764X1X4} {if((INSERTANS:61764X1X4==1),'pet','pets')} running around the house.  So, you have {INSERTANS:61764X1X3 + INSERTANS:61764X1X4} wild {if((INSERTANS:61764X1X3 + INSERTANS:61764X1X4 ==1),'beast','beasts')} to chase around every day.
This line should throw errors since the curly-brace enclosed functions do not have linefeeds after them (and before the closing curly brace): var job='{TOKEN:ATTRIBUTE_1}'; if (job=='worker') { document.write('BOSSES') } else { document.write('WORKERS') }
This line has a script section, but if you look at the source, you will see that it has errors: <script type="text/javascript" language="Javascript">var job='{TOKEN:ATTRIBUTE_1}'; if (job=='worker') {document.write('BOSSES')} else {document.write('WORKERS')} </script>.
Substitions that begin or end with a space should be ignored: { name} {age }
EOD;
        $alltests = explode("\n", $tests);
        $javascript1 = <<<EOST
                    var job='{TOKEN:ATTRIBUTE_1}';
                    if (job=='worker') {
                    document.write('BOSSES')
                    } else {
                    document.write('WORKERS')
                    }
EOST;
        $javascript2 = <<<EOST
var job='{TOKEN:ATTRIBUTE_1}';
    if (job=='worker') {
       document.write('BOSSES')
    } else { document.write('WORKERS')  }
EOST;
        $alltests[] = 'This line should have no errors - the Javascript has curly braces followed by line feeds:' . $javascript1;
        $alltests[] = 'This line should also be OK: ' . $javascript2;
        $alltests[] = 'This line has a hidden script: <script type="text/javascript" language="Javascript">' . $javascript1 . '</script>';
        $alltests[] = 'This line has a hidden script: <script type="text/javascript" language="Javascript">' . $javascript2 . '</script>';
        LimeExpressionManager::StartProcessingPage();
        LimeExpressionManager::StartProcessingGroup(1);
        $LEM =& LimeExpressionManager::singleton();
        $LEM->tempVars = $vars;
        $LEM->questionId2questionSeq = array();
        $LEM->questionId2groupSeq = array();
        $_SESSION[$LEM->sessid]['relevanceStatus'] = array();
        foreach ($vars as $var) {
            if (isset($var['qseq'])) {
                $LEM->questionId2questionSeq[$var['qseq']] = $var['qseq'];
                $LEM->questionId2groupSeq[$var['qseq']] = $var['gseq'];
                $_SESSION[$LEM->sessid]['relevanceStatus'][$var['qseq']] = 1;
            }
        }
        print "<h3>Note, if the <i>Vars Used</i> column is red, then at least one error was found in the <b>Source</b>. In such cases, the <i>Vars Used</i> list may be missing names of variables from sub-expressions containing errors</h3>";
        print '<table class="table" border="1"><tr><th>Source</th><th>Pretty Print</th><th>Result</th><th>Vars Used</th></tr>';
        for ($i = 0; $i < count($alltests); ++$i) {
            $test = $alltests[$i];
            $result = LimeExpressionManager::ProcessString($test, 40, NULL, false, 1, 1);
            $prettyPrint = LimeExpressionManager::GetLastPrettyPrintExpression();
            $varsUsed = $LEM->em->GetAllVarsUsed();
            if (count($varsUsed) > 0) {
                sort($varsUsed);
                $varList = implode(',<br />', $varsUsed);
            } else {
                $varList = '&nbsp;';
            }
            print "<tr><td>" . htmlspecialchars($test, ENT_QUOTES) . "</td>\n";
            print "<td>" . $prettyPrint . "</td>\n";
            print "<td>" . $result . "</td>\n";
            if ($LEM->em->HasErrors()) {
                print "<td style='background-color:  red'>";
            } else {
                print "<td>";
            }
            print $varList . "</td>\n";
            print "</tr>\n";
        }
        print '</table>';
        LimeExpressionManager::FinishProcessingGroup();
        LimeExpressionManager::FinishProcessingPage();
    }
                                                        </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;?>
Beispiel #6
0
        //            . "<td align='right' valign='top'><strong>"
        //            . $clang->gT("Other questions having conditions on this question:")
        //            . "</strong></td>\n<td align='left' valign='bottom'>\n";
        //            foreach ($condarray[$qid] as $depqid => $depcid)
        //            {
        //                $listcid=implode("-",$depcid);
        //                $questionsummary .= " <a href='#' onclick=\"window.open('admin.php?sid=".$surveyid."&amp;qid=".$depqid."&amp;action=conditions&amp;markcid=".$listcid."','_top')\">[QID: ".$depqid."]</a>";
        //            }
        //            $questionsummary .= "</td></tr>";
        //        }
        if (is_null($qrrow['relevance']) || trim($qrrow['relevance']) == '') {
            $rel2show = 1;
        } else {
            LimeExpressionManager::ProcessString("{" . $qrrow['relevance'] . "}", $qid);
            // tests Relevance equation so can pretty-print it
            $rel2show = LimeExpressionManager::GetLastPrettyPrintExpression();
            $questionsummary .= "<tr>" . "<td align='right' valign='top'><strong>" . $clang->gT("Relevance:") . "</strong></td>\n" . "<td align='left'>";
            $questionsummary .= $rel2show;
            $questionsummary .= "</td></tr>\n";
        }
        $questionsummary .= "</table>";
    }
}
LimeExpressionManager::FinishProcessingPage();
// ============= EDIT ANSWER OPTIONS=====================================
if ($action == 'editansweroptions') {
    include "editansweroptions.php";
}
// ============= EDIT SUBQUESTIONS ======================================
if ($action == 'editsubquestions') {
    include "editsubquestions.php";
 /**
  * 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);
 }
Beispiel #8
0
        }
        $orderquestions .= "</select>\n";
        $orderquestions .= "\t<input style='float:right;";
        if ($i == 0) {
            $orderquestions .= "visibility:hidden;";
        }
        $orderquestions .= "' type='image' src='{$imageurl}/up.png' name='btnup_{$i}' onclick=\"\$('#sortorder').val('{$oqarray[$i]['question_order']}');\$('#questionordermethod').val('up');\" " . $updisabled . "/>\n";
        if ($i < $questioncount - 1) {
            // Fill the sortorder hiddenfield so we know what field is moved down
            $orderquestions .= "\t<input type='image' src='{$imageurl}/down.png' style='float:right;' name='btndown_{$i}' onclick=\"\$('#sortorder').val('{$oqarray[$i]['question_order']}');\$('#questionordermethod').val('down')\" " . $downdisabled . "/>\n";
        }
        $orderquestions .= "<a href='admin.php?sid={$surveyid}&amp;gid={$gid}&amp;qid={$oqarray[$i]['qid']}' title='" . $clang->gT("View Question") . "'>" . $oqarray[$i]['title'] . "</a>: ";
        $relevance = $oqarray[$i]['relevance'] == '' ? 1 : $oqarray[$i]['relevance'];
        $showme = '[{' . $relevance . '}] ' . $oqarray[$i]['question'];
        LimeExpressionManager::ProcessString($showme, $oqarray[$i]['qid']);
        $orderquestions .= FlattenText(LimeExpressionManager::GetLastPrettyPrintExpression(), false, 'UTF-8', true, true);
        $orderquestions .= "</li>\n";
    }
    $orderquestions .= "</ul>\n" . "<input type='hidden' name='questionmovefrom' />\n" . "<input type='hidden' name='questionordermethod' id='questionordermethod' />\n" . "<input type='hidden' name='questionmoveto' />\n" . "\t<input type='hidden' id='sortorder' name='sortorder' />" . "\t<input type='hidden' name='action' value='orderquestions' />" . "</form>";
    $orderquestions .= "<br />";
    LimeExpressionManager::FinishProcessingGroup();
    LimeExpressionManager::FinishProcessingPage();
}
function questionjavascript($type)
{
    $newquestionoutput = "<script type='text/javascript'>\n" . "if (navigator.userAgent.indexOf(\"Gecko\") != -1)\n" . "window.addEventListener(\"load\", init_gecko_select_hack, false);\n";
    $jc = 0;
    $newquestionoutput .= "\tvar qtypes = new Array();\n";
    $newquestionoutput .= "\tvar qnames = new Array();\n\n";
    $newquestionoutput .= "\tvar qhelp = new Array();\n\n";
    $newquestionoutput .= "\tvar qcaption = new Array();\n\n";