function setVariable($variablename) { global $db, $engine, $language; $this->completevariablename = $variablename; $this->variablename = getBasicName($this->completevariablename); $variabledescriptive = $engine->getVariableDescriptive($this->variablename); $this->array = $variabledescriptive->isArray(); $this->answertype = $variabledescriptive->getAnswerType(); $this->language = $language; if ($variabledescriptive == null) { return false; } return true; }
function doEnd($savestate = false) { /* if already state of other sections before this one, then this is not the first section * if it is, then do the end part */ if ($this->isMainSection() == true) { $this->endofsurvey = true; $this->setAnswer(VARIABLE_END, date("Y-m-d H:i:s", time())); /* check if we need to reset non-keep variable answers */ if ($this->survey->getDataKeepOnly() == DATA_KEEP_ONLY_YES) { $vars = $this->state->getVariableNames(); $this->currentaction = ACTION_SURVEY_END; foreach ($vars as $var) { //echo "<br>CHECK: " . $var; $vd = $this->getVariableDescriptive(getBasicName($var)); if ($vd->getDataKeep() == DATA_KEEP_NO) { //echo 'everybody do their share'; $this->setAnswer($var, null); } } } doCommit(); /* save data record */ $this->getDataRecord()->saveRecord(); /* $savestate == true if we are reaching doEnd by going next on a last action in the base module * and there are no more actions left in the _next table. */ if ($savestate == true) { $this->saveState(false); } else { /* get any last things we did from the current state */ $assign = $this->state->getAssignments(); $data = $this->state->getAllData(); /* load the last state we had, update it with any actions we did and save it */ if ($this->loadLastState()) { $this->state->setAllData($data); $this->state->setAssignments($assign); $this->saveState(false); } } /* set interview data as completed */ $this->getDataRecord()->setToComplete(); /* unlock */ $this->unlock(); if ($this->getFlooding()) { $this->stop = true; return; } /* show end and exit */ echo $this->display->showEndSurvey(); doExit(); } else { /* get current state */ $seid = $this->getParentSeid(); $mainseid = $this->getMainSeid(); $assign = $this->state->getAssignments(); $data = $this->state->getAllData(); $prefix = ""; $this->getDataRecord()->saveRecord(); $this->datarecord = null; unset($this->datarecord); $this->clearContext(); /* get engine */ global $engine; $engine = loadEngine($this->getSuid(), $this->primkey, $this->phpid, $this->version, $seid, false, true); /* transfer current state with updated details for section we are going back to */ $engine->setState($this->state); $engine->setSeid($seid); $engine->setMainSeid($mainseid); $engine->setPrefix($this->getParentPrefix()); $engine->setForward($this->getForward()); $engine->setFlooding($this->getFlooding()); /* go into parent section again */ $engine->endSection(); if ($this->getFlooding()) { $this->stop = true; return; } doExit(); } }
function addCSVRecord($primkey, $record = null) { $line = ""; $skipped = array(); for ($i = 0; $i < $this->variablenumber; $i++) { $fieldname = $this->variablenames[$i]; $variableobject = null; $value = null; // skip variable if (inArray(strtoupper($fieldname), $this->skipvariables)) { $value = $skipped[strtoupper($fieldname)]; } else { if (isset($this->withsuffix[strtoupper($fieldname)])) { $binary = $this->setofenumeratedbinary[strtoupper($fieldname)]; $last = strrpos($fieldname, $this->withsuffix[strtoupper($fieldname)]); $num = str_replace("s", "", $this->withsuffix[strtoupper($fieldname)]); $fieldname = substr($fieldname, 0, $last); $value = $this->getValue($primkey, $record, $fieldname); //if ($value != null && !inArray($value, array(ANSWER_DK, ANSWER_RF, ANSWER_NA))) { if ($value != null && !inArray($value, array("", ANSWER_DK, ANSWER_RF, ANSWER_NA, $this->asked))) { $arr = array(); if (contains($value, SEPARATOR_SETOFENUMERATED)) { $arr = explode(SEPARATOR_SETOFENUMERATED, $value); } else { if (contains($value, SEPARATOR_SETOFENUMERATED_OLD)) { $arr = explode(SEPARATOR_SETOFENUMERATED_OLD, $value); } else { $arr[] = $value; } } if (inArray($num, $arr)) { $value = $num; if ($binary == SETOFENUMERATED_BINARY) { $value = 1; } } else { $value = ""; // set to "", so it appears as just empty rather than skipped (since it was not skipped, just not selected) if ($binary == SETOFENUMERATED_BINARY) { $value = "0"; } } } } else { $value = $this->getValue($primkey, $record, $fieldname); } } // we have a value, then check for serialized array answer if ($value != null) { // variable is an instance of an array variable if (inArray(strtoupper(getBasicName($fieldname)), $this->arrayfields)) { // this is a compressed string! $v = gzuncompress($value); if ($v !== false) { // this is a serialized string! if (unserialize($v) !== false) { $v1 = unserialize(gzuncompress($value)); // the unserialized is an array or object, then output empty string so it appears as empty (not skipped) if (is_array($v1) || is_object($v1)) { $value = ""; } } } } } // primary key encryption if ($fieldname == VARIABLE_PRIMKEY && $this->getProperty(DATA_OUTPUT_PRIMARY_KEY_ENCRYPTION) != "") { $value = encryptC($value, $this->getProperty(DATA_OUTPUT_PRIMARY_KEY_ENCRYPTION)); } // write variable $stringobj = ""; if ($value == ANSWER_RF) { $stringobj = ".r"; } else { if ($value == ANSWER_DK) { $stringobj = ".d"; } else { if ($value == ANSWER_NA) { $stringobj = ".n"; } else { if (!inArray($value, array("", null, $this->asked))) { $stringobj = $value; } else { if ($value == $this->asked) { if ($this->getProperty(DATA_OUTPUT_MARK_EMPTY) == MARKEMPTY_IN_VARIABLE) { $stringobj = ".e"; } else { if ($this->getProperty(DATA_OUTPUT_MARK_EMPTY) == MARKEMPTY_IN_SKIP_VARIABLE) { if (isset($this->skipvariables[strtoupper($this->variablenames[$i])])) { $skipped[strtoupper($this->skipvariables[strtoupper($this->variablenames[$i])])] = 1; } } } } } } } } /* add separator */ if ($line != "" || $i > 0 && $i + 1 < $this->recordcount) { $line .= $this->separator; } $stringobj = str_replace("\"", "\"\"", $stringobj); $stringobj = str_replace("\r", "", $stringobj); $stringobj = str_replace("\n", "", $stringobj); $stringobj = str_replace("\r\n", "", $stringobj); $line .= '"' . $stringobj . '"'; $stringobj = null; unset($stringobj); } fwrite($this->csvhandle, $line . "\n"); $line = null; unset($line); //exit; }
function checkArray($str, &$messages) { // http://stackoverflow.com/questions/2938137/is-there-way-to-keep-delimiter-while-using-php-explode-or-other-similar-function $parts = preg_split('/([\\[\\., \\]])/', $str, -1, PREG_SPLIT_DELIM_CAPTURE); //print_r($parts); //echo "<hr><hr>"; //$sentences = array(); //for ($i = 0, $n = count($parts) - 1; $i < $n; $i+=2) { // $sentences[] = $parts[$i] . $parts[$i + 1]; //} //if ($parts[$n] != '') { // $sentences[] = $parts[$n]; //} for ($i = 0; $i < sizeof($parts); $i++) { $s = $parts[$i]; // not a delimiter if (!inArray($s, array("[", "]", ".", " ", ","))) { // see if this is a variable $v = $this->survey->getVariableDescriptiveByName(getBasicName($s)); if ($v->getVsid() != "") { if ($parts[$i + 1] == "[") { // bracket reference if ($v->isArray() == false) { $messages[] = Language::messageCheckerVariableNotArray($s); } } else { //echo $s; if ($v->isArray() == true) { $messages[] = Language::messageCheckerVariableArray($s); } } } } } }
function addQuestion(&$node, $instruction) { $rule = trim($instruction->getRule()); $rgid = trim($instruction->getRgid()); $excluded = array(); $rule = excludeText($rule, $excluded); // check for .INLINE $inline = false; if (endsWith($rule, ROUTING_IDENTIFY_INLINE)) { $inline = true; //echo $rule; $pos = strrpos($rule, ROUTING_IDENTIFY_INLINE); //echo $pos; $rule = substr($rule, 0, $pos); } //echo $rule; // hide module dot notations $rule = hideModuleNotations($rule, TEXT_MODULE_DOT); //echo $rule; $rule = includeText($rule, $excluded); $var = $this->survey->getVariableDescriptiveByName(getBasicName($rule)); if ($var->getVsid() != "") { if ($var->isHiddenRouting() == false) { if (trim($var->getDescription()) != "") { $this->addToStatements("<div class='uscic-paperversion-question uscic-paperversion-nesting" . $this->nesting . "'><div class='uscic-paperversion-question-name'><b>" . $var->getName() . "</b> (" . $this->prepareText($var->getDescription()) . ")"); } else { $this->addToStatements("<div class='uscic-paperversion-question uscic-paperversion-nesting" . $this->nesting . "'><div class='uscic-paperversion-question-name'>" . $var->getName() . ""); } $this->addToStatements('</div>'); if (trim($var->getQuestion()) != "") { $this->addToStatements("<div class='uscic-paperversion-questiontext'>" . $this->prepareText($var->getQuestion()) . "</div>", 15); } $answertype = $var->getAnswerType(); if ($answertype == SETTING_FOLLOW_TYPE) { $type = $this->survey->getType($var->getTyd()); $answertype = $type->getAnswerType(); } if (inArray($answertype, array(ANSWER_TYPE_ENUMERATED, ANSWER_TYPE_SETOFENUMERATED, ANSWER_TYPE_DROPDOWN, ANSWER_TYPE_MULTIDROPDOWN))) { $this->addToStatements("<div class='uscic-paperversion-question-categories'>" . $this->prepareText(str_replace("\r\n", "<br/>", $var->getOptionsText())) . "</div>"); } elseif ($answertype == ANSWER_TYPE_STRING || $answertype == ANSWER_TYPE_OPEN) { $this->addToStatements('STRING'); } elseif ($answertype == ANSWER_TYPE_RANGE) { $this->addToStatements('RANGE ' . $var->getMinimum() . '..' . $var->getMaximum()); } $this->addToStatements("</div>", 6); } } }
function isArrayReference($name) { $pos = strrpos($name, "."); $posbracket = strrpos($name, "["); // dots and brackets if ($pos > -1 && $posbracket > -1) { // bracket comes before dot, then strip away brackets and get basic name of result if ($posbracket < $pos) { $posendbracket = strpos($name, "]", $posbracket + 1); // bracket closes before dot: mod1[cnt].Q1 if ($posendbracket < $pos) { $name = substr($name, strrpos($name, "]") + 1); return isArrayReference($name); } else { $name = substr($name, 0, strpos($name, "[")); return getBasicName($name); } } else { $name = substr($name, $pos + 1); return isArrayReference($name); } } else { if ($pos > -1) { return false; } else { if ($posbracket > -1) { return true; } } } return false; }
function updateVariables(&$node) { $subs = $node->getSubNodeNames(); if (sizeof($subs) == 0) { return; } // child nodes for ($i = 0; $i < sizeof($subs); $i++) { //echo 'PPPPPPPPPPPPP'; $subnode = $node->{$subs}[$i]; // name node: this could be a variable if ($subnode instanceof PHPParser_Node_Name) { $name = $subnode->getFirst(); // restore any brackets! $name = str_replace(TEXT_BRACKET_LEFT, "[", $name); $name = str_replace(TEXT_BRACKET_RIGHT, "]", $name); // restore any dot notations! $name = str_replace(TEXT_MODULE_DOT, ".", $name); //echo '<br/>UPDATING NAME ' . $name; //$var = new VariableDescriptive(); $var = $this->survey->getVariableDescriptiveByName(getBasicName($name)); // new VariableDescriptive(); //echo "<hr>getting: " . $name . '----' . getBasicName($name); if (strtoupper($name) == VARIABLE_VALUE_NULL) { $stmt = new PHPParser_Node_Scalar_String(VARIABLE_VALUE_NULL); $node->{$subs}[$i] = $stmt; } else { if (strtoupper($name) == VARIABLE_VALUE_DK) { $stmt = new PHPParser_Node_Scalar_String(VARIABLE_VALUE_DK); $node->{$subs}[$i] = $stmt; } else { if (strtoupper($name) == VARIABLE_VALUE_RF) { $stmt = new PHPParser_Node_Scalar_String(VARIABLE_VALUE_RF); $node->{$subs}[$i] = $stmt; } else { if (strtoupper($name) == VARIABLE_VALUE_NA) { $stmt = new PHPParser_Node_Scalar_String(VARIABLE_VALUE_NA); $node->{$subs}[$i] = $stmt; } else { if (strtoupper($name) == VARIABLE_VALUE_RESPONSE) { $stmt = new PHPParser_Node_Scalar_String(VARIABLE_VALUE_RESPONSE); $node->{$subs}[$i] = $stmt; } else { if (strtoupper($name) == VARIABLE_VALUE_EMPTY) { $stmt = new PHPParser_Node_Scalar_String(VARIABLE_VALUE_EMPTY); $node->{$subs}[$i] = $stmt; } else { if (strtoupper($name) == VARIABLE_VALUE_INARRAY) { /* do nothing */ //} else if ($var->setVariableDescriptive(getBasicName($name))) { } else { if ($var->getVsid() != "") { $answertype = $var->getAnswerType(); //echo '<hr>maybe: ' . $var->getName() . '---' . $answertype; if (inArray($answertype, array(ANSWER_TYPE_DROPDOWN, ANSWER_TYPE_ENUMERATED, ANSWER_TYPE_MULTIDROPDOWN, ANSWER_TYPE_SETOFENUMERATED))) { //echo '<hr>LAST: ' . $var->getName(); $this->lastvar = $var; } // an array, but not an array statement //if ($var->isArray() == true) { // $this->addErrorMessage(Language::errorArray(getBasicName($name))); //} $args = array(); $args[] = new PHPParser_Node_Arg(new PHPParser_Node_Scalar_String($name)); $stmt = new PHPParser_Node_Expr_MethodCall(new PHPParser_Node_Expr_Variable(VARIABLE_THIS), new PHPParser_Node_Name(array(FUNCTION_GET_ANSWER)), $args); $node->{$subs}[$i] = $stmt; } else { if ($this->fillclass == true && startsWith($name, VARIABLE_VALUE_FILL)) { //echo $name . " <hr>"; $line = trim(str_ireplace(VARIABLE_VALUE_FILL, "", $name)); if ($line != "") { $args = array(); $args[] = new PHPParser_Node_Arg(new PHPParser_Node_Scalar_String($this->currentfillvariable)); if (!is_numeric($line)) { $parser = new PHPParser_Parser(new PHPParser_Lexer()); try { $stmtsleft = $parser->parse("<?php " . $line . "?>"); $temp = new PHPParser_Node_Arg($stmtsleft[0]); // encapsulate in fake Argument object, since updateVariables looks only at children of entered node $this->updateVariables($temp); if ($temp->value instanceof PHPParser_Node_Expr_MethodCall) { $args[] = $temp->value->args[0]; //print_r($temp->value->args[0]); } else { /* not a constant, which happens if the counter field does not exist */ if ($temp->value->name instanceof PHPParser_Node_Expr_MethodCall) { $args[] = $temp->value->name; //print_r($temp->value->name->args[0]); } } } catch (Exception $e) { $this->addErrorMessage(Language::errorAssignmentInvalid()); return; } } else { $args[] = new PHPParser_Node_Arg(new PHPParser_Node_Scalar_LNumber($line)); } $stmt = new PHPParser_Node_Expr_MethodCall(new PHPParser_Node_Expr_Variable(VARIABLE_THIS), new PHPParser_Node_Name(array(FUNCTION_GET_FILL_TEXT_BY_LINE)), $args); $node->{$subs}[$i] = $stmt; } } else { if ($this->checkclass && (startsWith($name, VARIABLE_VALUE_SOFT_ERROR) || startsWith($name, VARIABLE_VALUE_HARD_ERROR))) { $type = ERROR_HARD; echo $line . '----'; if (startsWith($name, VARIABLE_VALUE_SOFT_ERROR)) { $line = trim(str_ireplace(VARIABLE_VALUE_SOFT_ERROR, "", $name)); } else { $type = ERROR_SOFT; $line = trim(str_ireplace(VARIABLE_VALUE_HARD_ERROR, "", $name)); } if ($line != "") { $args = array(); $args[] = new PHPParser_Node_Arg(new PHPParser_Node_Scalar_String($this->currentfillvariable)); if (!is_numeric($line)) { $parser = new PHPParser_Parser(new PHPParser_Lexer()); try { $stmtsleft = $parser->parse("<?php " . $line . "?>"); $temp = new PHPParser_Node_Arg($stmtsleft[0]); // encapsulate in fake Argument object, since updateVariables looks only at children of entered node $this->updateVariables($temp); if ($temp->value instanceof PHPParser_Node_Expr_MethodCall) { $args[] = $temp->value->args[0]; //print_r($temp->value->args[0]); } else { /* not a constant, which happens if the counter field does not exist */ if ($temp->value->name instanceof PHPParser_Node_Expr_MethodCall) { $args[] = $temp->value->name; //print_r($temp->value->name->args[0]); } } } catch (Exception $e) { $this->addErrorMessage(Language::errorAssignmentInvalid()); return; } } else { $args[] = new PHPParser_Node_Arg(new PHPParser_Node_Scalar_LNumber($line)); } $args[] = new PHPParser_Node_Arg(new PHPParser_Node_Scalar_LNumber($type)); $stmt = new PHPParser_Node_Expr_MethodCall(new PHPParser_Node_Expr_Variable(VARIABLE_THIS), new PHPParser_Node_Name(array(FUNCTION_GET_ERROR_TEXT_BY_LINE)), $args); $node->{$subs}[$i] = $stmt; } } else { if ($this->lastvar != null) { //echo "<hr>1: " . $name . '----' . $this->lastvar->getName(); $vc = $this->lastvar->getOptionCodeByAcronym($name); if ($vc > 0) { $stmt = new PHPParser_Node_Scalar_String($vc); $node->{$subs}[$i] = $stmt; } else { /* fill that is not present (or something else), then return the * text representation of whatever was inputted */ if (!inArray($name, array("true", "false"))) { $this->messages[] = $this->addErrorMessage(Language::errorVariableNotFound($name)); } $stmt = new PHPParser_Node_Scalar_String($name); $node->{$subs}[$i] = $stmt; } } else { //echo "<hr>2: " . $name; /* fill that is not present (or something else), then return the * text representation of whatever was inputted */ if (!inArray($name, array("true", "false"))) { $this->messages[] = $this->addErrorMessage(Language::errorVariableNotFound($name)); } $stmt = new PHPParser_Node_Scalar_String($name); $node->{$subs}[$i] = $stmt; } } } } } } } } } } } } else { if ($subnode instanceof PHPParser_Node_Expr_FuncCall) { /* check if function name is actually a question; if yes, then * this is actually a bracket Q1[cnt], which we are processing * as Q1(cnt) so the PHPParser doesn't break */ /* get function name */ $namenode = $subnode->name; $name = $namenode->getFirst(); //echo '<br/>FUNCTION callll' . $name; // $name = str_replace(TEXT_MODULE_DOT, ".", $name); // real function call if (function_exists($name)) { $args = $subnode->args; for ($j = 0; $j < sizeof($args); $j++) { $this->updateVariables($args[$j]); } } else { // not a real function call, but a bracket statement //$var = new VariableDescriptive(); $var = $this->survey->getVariableDescriptiveByName(getBasicName($name)); // new VariableDescriptive(); //if ($var->setVariableDescriptive(getBasicName($name))) { if ($var->getVsid() != "") { // array statement, so question should be an array if ($var->isArray() == false) { $this->addErrorMessage(Language::errorNotArray(strtolower(getBasicName($name)))); } /* go through 'function' arguments * and change them to "[" . $this-getValue("field") . "]" */ $answertype = $var->getAnswerType(); //echo '<hr>maybe: ' . $var->getName() . '---' . $answertype; if (inArray($answertype, array(ANSWER_TYPE_DROPDOWN, ANSWER_TYPE_ENUMERATED, ANSWER_TYPE_MULTIDROPDOWN, ANSWER_TYPE_SETOFENUMERATED))) { //echo '<hr>LAST: ' . $var->getName(); $this->lastvar = $var; } $args = array(); $args[] = $this->handleBracketExpression($subnode, $name); $stmt = new PHPParser_Node_Expr_MethodCall(new PHPParser_Node_Expr_Variable(VARIABLE_THIS), new PHPParser_Node_Name(array(FUNCTION_GET_ANSWER)), $args); $node->{$subs}[$i] = $stmt; } else { /* fill that is not present (or something else), then return the * text representation of whatever was inputted */ $stmt = new PHPParser_Node_Scalar_String($name); $node->{$subs}[$i] = $stmt; if (!inArray($name, array("true", "false"))) { $this->messages[] = $this->addErrorMessage(Language::errorVariableNotFound($name)); } } } } else { if ($subnode instanceof PHPParser_Node_Expr_Array) { $items = $subnode->items; for ($j = 0; $j < sizeof($items); $j++) { $this->updateVariables($items[$j]); } } else { // check children if real node itself (not an array part) if ($subnode instanceof PHPParser_NodeAbstract) { $this->updateVariables($subnode); } } } } } }
$answer = null; } $this->data[strtoupper($variablename)] = $answer; return $this->data[strtoupper($variablename)]; } return null; } function setData($variablename, $answer, $clean = 1) { /* variable in memory */ if (isset($this->variables[strtoupper($variablename)])) { $variable = $this->variables[strtoupper($variablename)]; } else { $variable = new Variable(); if (!$variable->setVariable($variablename)) { $variable = null; } } /* we have variable */ if ($variable != null) { $variable->setDirty($clean); /* check for EMPTY */ if (strtoupper($answer) == VARIABLE_VALUE_EMPTY || is_array($answer) && sizeof($answer) == 0 || !is_array($answer) && trim($answer) == "") { $answer = null; } if ($variable->setAnswer($this->primkey, $answer)) { /* update in-memory */ $this->variables[strtoupper($variablename)] = $variable; $this->data[strtoupper($variablename)] = $answer; //echo 'set ' . $variablename . ' to ' . $answer; /* update state memory if array update * (this does not happen in variable.php via $engine->setAnswer() * in order to avoid an infinite loop) */ global $engine; $var = $engine->getVariableDescriptive($variablename); if ($var->isArray() && contains($variablename, "[")) { //echo 'set ' . $variablename . ' to ' . $answer; $arr = $this->getData(getBasicName($variablename)); $index = str_replace("]", "", substr($variablename, strrpos($variablename, "[") + 1)); // update array $arr[$index] = $answer; // flatten array $arr = flatten($arr); // flatten array $this->data[strtoupper(getBasicName($variablename))] = $arr; //print_r($arr); } else { if (($var->getAnswerType() == ANSWER_TYPE_SETOFENUMERATED || $var->getAnswerType() == ANSWER_TYPE_MULTIDROPDOWN) && !contains($variablename, "_")) { $options = $var->getOptions(); $values = explode(SEPARATOR_SETOFENUMERATED, $answer); foreach ($options as $o) { $code = $o["code"]; if (isset($this->data[strtoupper($variablename . "_" . $code . "_")])) { if (!inArray($code, $values)) { $this->data[strtoupper($variablename . "_" . $code . "_")] = null; } } else { if (inArray($code, $values)) { $this->data[strtoupper($variablename . "_" . $code . "_")] = $code; } }
function getRespondentActionButtons($respondentOrHousehold, $refpage) { $content = ''; if ($respondentOrHousehold->hasFinalCode() && $respondentOrHousehold->isCompleted()) { //if not completed: can still be assigned to different iwer $content = $this->displayInfo(Language::labelSupervisorFinalCodeAssigned()); } else { if ($respondentOrHousehold instanceof Household) { // $content .= '<form method="post">'; // $content .= setSessionParamsPost(array('page' => 'supervisor.interviewer.respondent.reassign', 'primkey' => $respondentOrHousehold->getPrimkey())); $users = new Users(); $users = $users->getUsersBySupervisor($_SESSION['URID']); // $content .= $this->displayUsers($users, $respondentOrHousehold->getUrid()); // $content .= '<br/>'; // $content .= '<input type="submit" class="btn btn-default" value="Reassign"/>'; // $content .= '</form>'; $content .= $this->showActionBar(Language::labelSupervisorAssignToInterviewer(), $this->displayUsers($users, $respondentOrHousehold->getUrid(), 'uridsel', false, true), 'Reassign', setSessionParamsPost(array('page' => 'supervisor.interviewer.household.reassign', 'primkey' => $respondentOrHousehold->getPrimkey())), confirmAction('Are you sure you want to reassign this household? Make sure the intervier data for this household has been uploaded, otherwise data wil be lost! Type YES to continue.', 'YES')); if (!$respondentOrHousehold->hasFinalCode()) { $content .= $this->showActionBar(Language::labelSupervisorAssignFinalStatus(), $this->displayFinalStatusCodesSelect($respondentOrHousehold->getUrid()), 'Set status', setSessionParamsPost(array('page' => 'supervisor.interviewer.household.contact.setstatus', 'primkey' => $respondentOrHousehold->getPrimkey())), confirmAction('Are you sure you want to reassign this household? Type YES to continue.', 'YES')); } } else { if (!$respondentOrHousehold->hasFinalCode()) { $content .= $this->showActionBar(Language::labelSupervisorAssignFinalStatus(), $this->displayFinalStatusCodesSelect($users, $respondentOrHousehold->getUrid()), 'Set status', setSessionParamsPost(array('page' => 'supervisor.interviewer.household.respondent.contact.setstatus', 'primkey' => $respondentOrHousehold->getPrimkey())), confirmAction('Are you sure you want to assign a final status code to this respondent? Type YES to continue.', 'YES')); } else { $content = $this->displayInfo(Language::labelSupervisorFinalCodeAssigned()); } } } //NEEDS VALIDATION? if ($respondentOrHousehold instanceof Respondent) { if ($respondentOrHousehold->needsValidation()) { $beforeText = '<button type="button" class="btn btn-warning" data-toggle="modal" data-target="#myModal">' . Language::labelSupervisorCheckAnswers() . '</button>'; $content .= ' <!-- Modal --> <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"> <div class="modal-dialog"> <div class="modal-content"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span><span class="sr-only">Close</span></button> <h4 class="modal-title" id="myModalLabel">' . Language::labelSupervisorCheckRespondentAnswers() . '</h4> </div> <div class="modal-body"> <table> <thead><tr><th>' . Language::labelSupervisorCheckRespondentQuestion() . '</th><th>' . Language::labelSupervisorCheckRespondentAnswer() . '</th></tr></thead> <tbody>'; $validationQuestions = Language::validationQuestions(); $survey = new Survey(2); foreach ($validationQuestions as $question) { $var = $survey->getVariableDescriptiveByName(getBasicName($question)); $content .= '<tr><td>' . $question . ': ' . $var->getDescription() . '</td><td>'; $content .= '</td></tr>'; } $content .= '</tbody></table>'; // $content .= json_encode($survey); $content .= ' </div> <div class="modal-footer"> <button type="button" class="btn btn-default" data-dismiss="modal">' . Language::buttonClose() . '</button> </div> </div> </div> </div> '; $content .= $this->showActionBar(Language::labelSupervisorCheckRespondentValidate(), $this->displayValidationStatus(Language::optionsSupervisorValidation(), $respondentOrHousehold->getUrid(), 'validationsel', false, $beforeText), 'Set validation status', setSessionParamsPost(array('page' => 'supervisor.interviewer.household.respondent.setvalidation', 'primkey' => $respondentOrHousehold->getPrimkey()))); } } return $content; }
function addForLoop($instruction) { $rule = trim($instruction->getRule()); $rgid = trim($instruction->getRgid()); $rgidafter = $rgid; // hide text $excluded = array(); $rule = excludeText($rule, $excluded); // hide module dot notations $rule = hideModuleNotations($rule, TEXT_MODULE_DOT); // strip FOR $reversefor = 1; if (startsWith($rule, ROUTING_IDENTIFY_FORREVERSE)) { $rule = substr($rule, stripos($rule, ROUTING_IDENTIFY_FORREVERSE) + strlen(ROUTING_IDENTIFY_FORREVERSE)); $reversefor = 2; } else { $rule = substr($rule, stripos($rule, ROUTING_IDENTIFY_FOR) + strlen(ROUTING_IDENTIFY_FOR)); } /* multi-line for */ //if ($pos < 0) { if (endsWith(strtoupper($rule), ROUTING_IDENTIFY_DO) == false) { for ($cnt = $this->cnt + 1; $cnt <= sizeof($this->instructions); $cnt++) { if (isset($this->instructions[$cnt])) { $text = trim($this->instructions[$cnt]->getRule()); if (startsWith($text, "/*")) { $this->skipComments($cnt, $cnt); } else { if (startsWith($text, "//")) { } else { //$pos = strripos($text, ROUTING_IDENTIFY_DO); $rule .= " " . $text; //if ($pos > -1) { if (endsWith(strtoupper($rule), ROUTING_IDENTIFY_DO) == true) { $this->cnt = $cnt; $rgidafter = $this->instructions[$cnt]->getRgid(); break; } } } } } } $pos = strripos(strtoupper($rule), ROUTING_IDENTIFY_DO); if ($pos < 1) { $this->addErrorMessage(Language::errorForLoopMissingDo()); return; } // strip do $rule = trim(substr($rule, 0, $pos)); if (!contains(strtoupper($rule), " TO ")) { $this->addErrorMessage(Language::errorForLoopMissingTo()); return; } if (!contains(strtoupper($rule), ":=")) { $this->addErrorMessage(Language::errorForLoopMissingAssignment()); return; } // determine min and max $bounds = preg_split("/ to /i", $rule); $counterplusstart = splitString("/:=/", $bounds[0]); //print_r($excluded); $counterfield = includeText($counterplusstart[0], $excluded); $minimum = includeText($counterplusstart[1], $excluded); $maximum = includeText($bounds[1], $excluded); // check for array if (!is_numeric($minimum)) { $var = $this->survey->getVariableDescriptiveByName(getBasicName($minimum)); // new VariableDescriptive(); if ($var->isArray()) { if (!contains($minimum, "[")) { $this->addErrorMessage(Language::errorVariableNoArrayIndex(strtolower(getBasicName($minimum)))); } } } if (!is_numeric($maximum)) { $var = $this->survey->getVariableDescriptiveByName(getBasicName($maximum)); // new VariableDescriptive(); if ($var->isArray()) { if (!contains($maximum, "[")) { $this->addErrorMessage(Language::errorVariableNoArrayIndex(strtolower(getBasicName($maximum)))); } } } // replace [ and ] with ( and ), so the parser doesn't break // (we deal with these cases in the updateVariables function) $counterfield = str_replace("[", TEXT_BRACKET_LEFT, $counterfield); $counterfield = str_replace("]", TEXT_BRACKET_RIGHT, $counterfield); $minimum = str_replace("[", TEXT_BRACKET_LEFT, $minimum); $minimum = str_replace("]", TEXT_BRACKET_RIGHT, $minimum); $maximum = str_replace("[", TEXT_BRACKET_LEFT, $maximum); $maximum = str_replace("]", TEXT_BRACKET_RIGHT, $maximum); $parser = new PHPParser_Parser(new PHPParser_Lexer()); try { $stmts = $parser->parse("<?php " . $minimum . "?>"); // only one statement (no ; allowed in loop minimum) $stmt = $stmts[0]; $stmt = new PHPParser_Node_Arg($stmt); // encapsulate in fake Argument object, since updateVariables looks only at children of entered node $this->updateVariables($stmt); $min = $stmt; //echo 'min: ' . $minimum; $stmts = $parser->parse("<?php " . $maximum . "?>"); // only one statement (no ; allowed in loop maximum) $stmt = $stmts[0]; $stmt = new PHPParser_Node_Arg($stmt); // encapsulate in fake Argument object, since updateVariables looks only at children of entered node $this->updateVariables($stmt); $max = $stmt; //echo 'max: ' . $maximum; $stmts = $parser->parse("<?php " . $counterfield . "?>"); // only one statement (no ; allowed in loop maximum) $stmt = $stmts[0]; $stmt = new PHPParser_Node_Arg($stmt); // encapsulate in fake Argument object, since updateVariables looks only at children of entered node $this->updateVariables($stmt); //print_r($stmt); if ($stmt->value instanceof PHPParser_Node_Expr_MethodCall) { $counter = $stmt->value->var; } else { /* not a constant, which happens if the counter field does not exist */ if ($stmt->value->name instanceof PHPParser_Node_Expr_MethodCall) { $counter = $stmt->value->name->var; } else { $counter = new PHPParser_Node_Expr_Variable($counterfield); } } } catch (PHPParser_Error $e) { $this->addErrorMessage(Language::errorForLoopInvalid()); return; } // create for loop $temp = new PHPParser_Node_Expr_MethodCall($counter, FUNCTION_XI_GET_ANSWER, array($min)); $temp1 = new PHPParser_Node_Expr_MethodCall($counter, FUNCTION_XI_GET_ANSWER, array()); $temp2 = new PHPParser_Node_Expr_SmallerOrEqual($temp1, $max->value); $temp4 = new PHPParser_Node_Expr_Plus($temp1, new PHPParser_Node_Scalar_LNumber(1)); $temp3 = new PHPParser_Node_Expr_MethodCall($counter, FUNCTION_XI_GET_ANSWER, array($temp4)); $fillcall = "for (" . $this->printer->prettyPrint(array($temp)) . " " . $this->printer->prettyPrint(array($temp2)) . " " . $this->printer->prettyPrint(array($temp3)); // clean up $fillcall = str_replace(" . (", "", $fillcall); $fillcall = str_replace(" . ])", "]", $fillcall); $fillcall = str_replace("\n", "", trim(substr($fillcall, 0, strlen($fillcall) - 1))) . ") {\r\n"; // remove closing "}" $this->routing_output[$this->seid][] = $fillcall; }