From 736694fa356dccd6067c024181590d89afd5f261 Mon Sep 17 00:00:00 2001 From: Jason Cleeland Date: Fri, 9 Apr 2004 06:56:04 +0000 Subject: [PATCH] Completely reworked. Now contains 4 major functions - "retrieveAnswers" which returns answer texts and input names, "mandatory_popup" which determines if the popup message about mandatory questions should show, "create_mandatorylist" which creates an array list of all mandatory questions being displayed and "retrieveConditionInfo" which returns an array containing information about any conditions for questions about to be displayed. Subsequent modifications made to question.php, group.php and survey.php to call the script just once, and call the functions within it as they iterate through display questions. git-svn-id: file:///Users/Shitiz/Downloads/lssvn/trunk/unstable@979 b72ed6b6-b9f8-46b5-92b4-906544132732 --- qanda.php | 2313 +++++++++++++++++++++++++++++------------------------ 1 file changed, 1264 insertions(+), 1049 deletions(-) diff --git a/qanda.php b/qanda.php index f8b19070702..e4015acbe3e 100644 --- a/qanda.php +++ b/qanda.php @@ -33,1176 +33,1391 @@ # Suite 330, Boston, MA 02111-1307, USA. # ############################################################# */ -//MANDATORY (for single answer questions) (multi answer questions in select) -if (!$dropdownthreshold) {$dropdownthreshold=25;} +/* + * Let's explain what this strange $ia var means + * + * $ia[0] => question id + * $ia[1] => fieldname + * $ia[2] => title + * $ia[3] => question text + * $ia[4] => type -- text, radio, select, array, etc + * $ia[5] => group id + * $ia[6] => mandatory Y || N + * $ia[7] => conditions ?? + * + */ +function retrieveConditionInfo($ia) + { + global $dbprefix; + if ($ia[7] == "Y") + { //DEVELOP CONDITIONS ARRAY FOR THIS QUESTION + $cquery = "SELECT {$dbprefix}conditions.qid, " + ."{$dbprefix}conditions.cqid, " + ."{$dbprefix}conditions.cfieldname, " + ."{$dbprefix}conditions.value, " + ."{$dbprefix}questions.type, " + ."{$dbprefix}questions.sid, " + ."{$dbprefix}questions.gid " + ."FROM {$dbprefix}conditions, " + ."{$dbprefix}questions " + ."WHERE {$dbprefix}conditions.cqid={$dbprefix}questions.qid " + ."AND {$dbprefix}conditions.qid=$ia[0] " + ."ORDER BY {$dbprefix}conditions.cqid"; + $cresult = mysql_query($cquery) or die ("OOPS
$cquery
".mysql_error()); + while ($crow = mysql_fetch_array($cresult)) + { + $conditions[] = array ($crow['qid'], $crow['cqid'], $crow['cfieldname'], $crow['value'], $crow['type'], $crow['sid']."X".$crow['gid']."X".$crow['cqid']); + } + return $conditions; + } + else + { + return null; + } + } -if ($ia[4] == "5" || $ia[4] == "D" || $ia[4] == "G" || $ia[4] == "L" || $ia[4] == "O" || $ia[4] == "N" || $ia[4] == "Y" || $ia[4] == "T" || $ia[4] == "S") +function create_mandatorylist($ia) { - if ($ia[6] == "Y" && $ia[7] != "Y") //Question is mandatory. Add to mandatory array + //Checks current question and returns required mandatory arrays if required + if ($ia[6] == "Y") { - $mandatorys[]=$ia[1]; - $mandatoryfns[]=$ia[1]; + switch($ia[4]) + { + case "R": + $thismandatory=setman_ranking($ia); + break; + case "M": + case "P": + case "Q": + case "A": + case "B": + case "C": + case "E": + case "F": + case "H": + $thismandatory=setman_questionandcode($ia); + break; + default: + $thismandatory=setman_normal($ia); + } + if ($ia[7] != "Y") //Question is not conditional - addto mandatory arrays + { + $mandatory=$thismandatory; + } + if ($ia[7] == "Y") //Question IS conditional - add to conmandatory arrays + { + $conmandatory=$thismandatory; + } } - if ($ia[6] == "Y" && $ia[7] == "Y") + + if (isset($mandatory)) + { + return array($mandatory, null); + } + elseif (isset($conmandatory)) { - $conmandatorys[]=$ia[1]; - $conmandatoryfns[]=$ia[1]; + return array(null, $conmandatory); + } + else + { + return array(null, null); } } - -//DISPLAY -$display = $ia[7]; -if ($ia[7] == "Y") - { //DEVELOP CONDITIONS ARRAY FOR THIS QUESTION - $cquery = "SELECT {$dbprefix}conditions.qid, " - ."{$dbprefix}conditions.cqid, " - ."{$dbprefix}conditions.cfieldname, " - ."{$dbprefix}conditions.value, " - ."{$dbprefix}questions.type, " - ."{$dbprefix}questions.sid, " - ."{$dbprefix}questions.gid " - ."FROM {$dbprefix}conditions, " - ."{$dbprefix}questions " - ."WHERE {$dbprefix}conditions.cqid={$dbprefix}questions.qid " - ."AND {$dbprefix}conditions.qid=$ia[0] " - ."ORDER BY {$dbprefix}conditions.cqid"; - $cresult = mysql_query($cquery) or die ("OOPS
$cquery
".mysql_error()); - while ($crow = mysql_fetch_array($cresult)) + +function setman_normal($ia) + { + $mandatorys[]=$ia[1]; + $mandatoryfns[]=$ia[1]; + return array($mandatorys, $mandatoryfns); + } + +function setman_ranking($ia) + { + global $dbprefix; + $ansquery = "SELECT * FROM {$dbprefix}answers WHERE qid={$ia[0]} ORDER BY sortorder, answer"; + $ansresult = mysql_query($ansquery); + $anscount = mysql_num_rows($ansresult); + for ($i=1; $i<=$anscount; $i++) { - $conditions[] = array ($crow['qid'], $crow['cqid'], $crow['cfieldname'], $crow['value'], $crow['type'], $crow['sid']."X".$crow['gid']."X".$crow['cqid']); + $mandatorys[]=$ia[1].$i; + $mandatoryfns[]=$ia[1]; } + return array($mandatorys, $mandatoryfns); } -//QUESTION NAME -$name = $ia[0]; -//GET HELP -$hquery="SELECT help FROM {$dbprefix}questions WHERE qid=$ia[0]"; -$hresult=mysql_query($hquery); -$hcount=mysql_num_rows($hresult); -if ($hcount > 0) +function setman_questionandcode($ia) { - while ($hrow=mysql_fetch_array($hresult)) {$help=$hrow['help'];} + global $dbprefix; + $qquery = "SELECT other FROM {$dbprefix}questions WHERE qid=".$ia[0]; + $qresult = mysql_query($qquery); + while($qrow = mysql_fetch_array($qresult)) {$other = $qrow['other'];} + $ansquery = "SELECT * FROM {$dbprefix}answers WHERE qid={$ia[0]} ORDER BY sortorder, answer"; + $ansresult = mysql_query($ansquery); + $anscount = mysql_num_rows($ansresult); + while ($ansrow = mysql_fetch_array($ansresult)) + { + $mandatorys[]=$ia[1].$ansrow['code']; + $mandatoryfns[]=$ia[1]; + } + if ($other == "Y") + { + $mandatorys[]=$ia[1]."other"; + $mandatoryfns[]=$ia[1]; + } + return array($mandatorys, $mandatoryfns); } -else + +function retrieveAnswers($ia, $notanswered=null) { - $help=""; + //This function returns an array containing the "question/answer" html display + //and a list of the question/answer fieldnames associated. It is called from + //question.php, group.php or survey.php + + //globalise required config variables + global $dbprefix, $shownoanswer; //These are from the confir.php file + //----- + global $surveyformat, $gl; //These are set by index.php + + //DISPLAY + $display = $ia[7]; + + //QUESTION NAME + $name = $ia[0]; + + $qtitle=$ia[3]; + + //GET HELP + $hquery="SELECT help FROM {$dbprefix}questions WHERE qid=$ia[0]"; + $hresult=mysql_query($hquery); + $hcount=mysql_num_rows($hresult); + if ($hcount > 0) + { + while ($hrow=mysql_fetch_array($hresult)) {$help=$hrow['help'];} + } + else + { + $help=""; + } + + //A bit of housekeeping to stop PHP Notices + $answer = ""; + if (!isset($_SESSION[$ia[1]])) {$_SESSION[$ia[1]] = "";} + + //Create the question/answer html + switch ($ia[4]) + { + case "X": //BOILERPLATE QUESTION + $values=do_boilerplate($ia); + break; + case "5": //5 POINT CHOICE radio-buttons + $values=do_5pointchoice($ia); + break; + case "D": //DATE + $values=do_date($ia); + break; + case "L": //LIST drop-down/radio-button list + $values=do_list($ia); + $qtitle .= "
\n" + . _INSTRUCTION_LIST.""; + break; + case "O": //LIST WITH COMMENT drop-down/radio-button list + textarea + $values=do_listwithcomment($ia); + $qtitle .= "
\n
" + . _INSTRUCTION_LIST.""; + break; + case "R": //RANKING STYLE + $values=do_ranking($ia); + break; + case "M": //MULTIPLE OPTIONS checkbox + $values=do_multiplechoice($ia); + $qtitle .= "
\n
" + . _INSTRUCTION_MULTI.""; + break; + case "P": //MULTIPLE OPTIONS WITH COMMENTS checkbox + text + $values=do_multiplechoice_withcomments($ia); + $qtitle .= "
\n
" + . _INSTRUCTION_MULTI.""; + break; + case "Q": //MULTIPLE SHORT TEXT + $values=do_multipleshorttext($ia); + break; + case "N": //NUMERICAL QUESTION TYPE + $values=do_numerical($ia); + break; + case "S": //SHORT FREE TEXT + $values=do_shortfreetext($ia); + break; + case "T": //LONG FREE TEXT + $values=do_longfreetext($ia); + break; + case "Y": //YES/NO radio-buttons + $values=do_yesno($ia); + break; + case "G": //GENDER drop-down list + $values=do_gender($ia); + break; + case "A": //ARRAY (5 POINT CHOICE) radio-buttons + $values=do_array_5point($ia); + break; + case "B": //ARRAY (10 POINT CHOICE) radio-buttons + $values=do_array_10point($ia); + break; + case "C": //ARRAY (YES/UNCERTAIN/NO) radio-buttons + $values=do_array_yesnouncertain($ia); + break; + case "E": //ARRAY (Increase/Same/Decrease) radio-buttons + $values=do_array_increasesamedecrease($ia); + break; + case "F": //ARRAY (Flexible) - Row Format + $values=do_array_flexible($ia); + break; + case "H": //ARRAY (Flexible) - Column Format + $values=do_array_flexiblecolumns($ia); + break; + } //End Switch + + if (isset($values)) //Break apart $values array returned from switch + { + //$answer is the html code to be printed + //$inputnames is an array containing the names of each input field + list($answer, $inputnames)=$values; + } + + $answer .= "\n\t\t\t\n"; //for conditional mandatory questions + + //If this question is mandatory but wasn't answered in the last page + //add a message HIGHLIGHTING the question + $qtitle .= mandatory_message($ia); + + $qanda=array($qtitle, $answer, $help, $display, $name, $ia[2], $gl[0]); + //New Return + return array($qanda, $inputnames); } -//BUILD FIELDLIST -//BUILD ANSWERS -$answer = ""; -if (!isset($_SESSION[$ia[1]])) {$_SESSION[$ia[1]] = "";} -switch ($ia[4]) + +function mandatory_message($ia) { - case "X": //BOILERPLATE QUESTION - $answer.=""; - $inputnames[]=""; - break; - case "5": //5 POINT CHOICE radio-buttons - for ($fp=1; $fp<=5; $fp++) - { - $answer .= "\t\t\t\n"; - } - $answer .= "\t\t\t\n"; - $inputnames[]=$ia[1]; - break; - case "D": //DATE - $answer .= "\t\t\t\n" - . "\t\t\t\n" - . "\t\t\t\t\n" - . "\t\t\t\t\t\n" - . "\t\t\t\t\n" - . "\t\t\t
\n" - . "\t\t\t\t\t\t"._DATEFORMAT."
\n" - . "\t\t\t\t\t\t"._DATEFORMATEG."\n" - . "\t\t\t\t\t
\n"; - $inputnames[]=$ia[1]; - break; - case "L": //LIST drop-down/radio-button list - if (isset($defexists)) {unset ($defexists);} - $query = "SELECT other FROM {$dbprefix}questions WHERE qid=".$ia[0]; - $result = mysql_query($query); - while($row = mysql_fetch_array($result)) {$other = $row['other'];} - $ansquery = "SELECT * FROM {$dbprefix}answers WHERE qid=$ia[0] ORDER BY sortorder, answer"; - $ansresult = mysql_query($ansquery) or die("Couldn't get answers
$ansquery
".mysql_error()); - $anscount = mysql_num_rows($ansresult); - if (($dropdowns == "L" || !$dropdowns || $anscount > $dropdownthreshold) && $other != "Y") - { - while ($ansrow = mysql_fetch_array($ansresult)) - { - $answer .= "\t\t\t\t\t\t\n";} - $answer .= "\t\t\t\t\t\n"; - $answer = "\n\t\t\t\t\t\n"; - $answer .= "
\n"; - $inputnames[]=$thisfieldname; - } - if ($ia[6] != "Y" && $shownoanswer == 1) - { - $answer .= "\t\t\t\t\t\t "._NOANSWER."\n"; - } - $answer .= "\t\t\t\t\t\t\t\n" - . "\t\t\t\t\t\t\n" - . "\t\t\t\t\t\t\n" - . "\t\t\t\t\t\n"; - } - $inputnames[]=$ia[1]; - break; - case "O": //LIST WITH COMMENT drop-down/radio-button list + textarea - if (!isset($maxoptionsize)) {$maxoptionsize=35;} - $ansquery = "SELECT * FROM {$dbprefix}answers WHERE qid={$ia[0]} ORDER BY sortorder, answer"; - $ansresult = mysql_query($ansquery); - $anscount = mysql_num_rows($ansresult); - if ($lwcdropdowns == "R" && $anscount <= $dropdownthreshold) + //This function checks to see if this question is mandatory and + //is being re-displayed because it wasn't answered. It returns + global $notanswered; + $qtitle=""; + if (isset($notanswered) && is_array($notanswered)) //ADD WARNINGS TO QUESTIONS IF THEY WERE MANDATORY BUT NOT ANSWERED + { + global $mandatorypopup, $popup; + if (in_array($ia[1], $notanswered)) { - $answer .= "\t\t\t\n" - . "\t\t\t\t\n" - . "\t\t\t\t\t\n" - . "\t\t\t\t\t\n" - . "\t\t\t\t\n" - . "\t\t\t\t\n" - . "\t\t\t\t\t\n"; - $fname2 = $ia[1]."comment"; - if ($anscount > 8) {$tarows = $anscount/1.2;} else {$tarows = 4;} - $answer .= "\t\t\t\t\t\n" - . "\t\t\t\t\n" - . "\t\t\t\t\n" - . "\t\t\t
"._CHOOSEONE.":"._ENTERCOMMENT.":
\n"; - - while ($ansrow=mysql_fetch_array($ansresult)) - { - $answer .= "\t\t\t\t\t\t\n"; - } - $answer .= "\t\t\t\t\t\n" - . "\t\t\t\t\t\t\n" - . "\t\t\t\t\t
\n"; - $inputnames[]=$ia[1]; - $inputnames[]=$ia[1]."comment"; + case "A": + case "B": + case "C": + case "Q": + case "F": + case "H": + $qtitle .= "
\n"._MANDATORY_PARTS."."; + break; + case "R": + $qtitle .= "
\n"._MANDATORY_RANK."."; + break; + case "M": + case "P": + $qtitle .= "
\n"._MANDATORY_CHECK."."; + break; + } // end switch + $qtitle .= "
\n"; } - else //Dropdown list + } + return $qtitle; + } + +function mandatory_popup($ia, $notanswered=null) + { + //This sets the mandatory popup message to show if required + //Called from question.php, group.php or surveyo.php + if ($notanswered === null) {unset($notanswered);} + $qtitle=""; + if (isset($notanswered) && is_array($notanswered)) //ADD WARNINGS TO QUESTIONS IF THEY WERE MANDATORY BUT NOT ANSWERED + { + global $mandatorypopup, $popup; + //POPUP WARNING + if (!isset($mandatorypopup)) { - $answer .= "\t\t\t\n" - . "\t\t\t\t\n" - . "\t\t\t\t\t\n" - . "\t\t\t\t\n" - . "\t\t\t\t\n"; - $fname2 = $ia[1]."comment"; - if ($anscount > 8) {$tarows = $anscount/1.2;} else {$tarows = 4;} - if ($tarows > 15) {$tarows=15;} - $maxoptionsize=$maxoptionsize*0.72; - if ($maxoptionsize < 33) {$maxoptionsize=33;} - if ($maxoptionsize > 70) {$maxoptionsize=70;} - $answer .= "\t\t\t\t\t\n" - . "\t\t\t\t\n" - . "\t\t\t\t\n" - . "\t\t\t
\n" - . "\t\t\t\t\t\n" - . "\t\t\t\t\t
\n"; - $answer .= "\t\t\t\t\t\t\n" - . "\t\t\t\t\t
\n"; - $inputnames[]=$ia[1]; - $inputnames[]=$ia[1]."comment"; + $popup="\n"; + $mandatorypopup="Y"; } - break; - case "R": //RANKING STYLE - $ansquery = "SELECT * FROM {$dbprefix}answers WHERE qid={$ia[0]} ORDER BY sortorder, answer"; - $ansresult = mysql_query($ansquery); - $anscount = mysql_num_rows($ansresult); - $answer .= "\t\t\t\n"; - unset($answers); - //unset($inputnames); - unset($chosen); - $ranklist=""; + return array($mandatorypopup, $popup); + } + else + { + return false; + } + } + +//QUESTION METHODS +function do_boilerplate($ia) + { + $answer=""; + $inputnames[]=""; + return array($answer, $inputnames); + } + +function do_5pointchoice($ia) + { + $answer=""; + for ($fp=1; $fp<=5; $fp++) + { + $answer .= "\t\t\t\n"; + } + $answer .= "\t\t\t\n"; + $inputnames[]=$ia[1]; + return array($answer, $inputnames); + } + +function do_date($ia) + { + $answer = "\t\t\t\n" + . "\t\t\t\n" + . "\t\t\t\t\n" + . "\t\t\t\t\t\n" + . "\t\t\t\t\n" + . "\t\t\t
\n" + . "\t\t\t\t\t\t"._DATEFORMAT."
\n" + . "\t\t\t\t\t\t"._DATEFORMATEG."\n" + . "\t\t\t\t\t
\n"; + $inputnames[]=$ia[1]; + return array($answer, $inputnames); + } + +function do_list($ia) + { + global $dbprefix, $dropdowns, $dropdownthreshold, $lwcdropdowns; + global $shownoanswer; + $answer=""; + if (isset($defexists)) {unset ($defexists);} + $query = "SELECT other FROM {$dbprefix}questions WHERE qid=".$ia[0]; + $result = mysql_query($query); + while($row = mysql_fetch_array($result)) {$other = $row['other'];} + $ansquery = "SELECT * FROM {$dbprefix}answers WHERE qid=$ia[0] ORDER BY sortorder, answer"; + $ansresult = mysql_query($ansquery) or die("Couldn't get answers
$ansquery
".mysql_error()); + $anscount = mysql_num_rows($ansresult); + if (($dropdowns == "L" || !$dropdowns || $anscount > $dropdownthreshold) && $other != "Y") + { while ($ansrow = mysql_fetch_array($ansresult)) { - $answers[] = array($ansrow['code'], $ansrow['answer']); - } - $existing=0; - for ($i=1; $i<=$anscount; $i++) - { - $myfname=$ia[1].$i; - if (isset($_SESSION[$myfname]) && $_SESSION[$myfname]) + $answer .= "\t\t\t\t\t\t\n";} + $answer .= "\t\t\t\t\t\n"; + $answer = "\n\t\t\t\t\t\n"; - $ranklist .= "\t\t\t\t\t\t\n"; - $ranklist .= "\t\t\t\t\t\t"._REMOVEITEM."
\n"; - $inputnames[]=$myfname; + elseif ($ansrow['default_value'] == "Y") {$answer .= " checked"; $defexists = "Y";} + $answer .= " onClick='checkconditions(this.value, this.name, this.type)' />
\n"; } - - $choicelist = "\t\t\t\t\t\t $maxselectlength) {$maxselectlength = strlen($ans[1]);} - } + $answer .= " checked"; } + $answer .= " onClick='checkconditions(this.value, this.name, this.type)' />\n"; + $answer .= "
\n"; + $inputnames[]=$thisfieldname; } - else + if ($ia[6] != "Y" && $shownoanswer == 1) { - foreach ($answers as $ans) + $answer .= "\t\t\t\t\t\t $maxselectlength) {$maxselectlength = strlen($ans[1]);} - } + $answer .= " checked"; //Check the "no answer" radio button if there is no default, and user hasn't answered this. } + $answer .=" onClick='checkconditions(this.value, this.name, this.type)' />" + . "\n"; } - $choicelist .= "\t\t\t\t\t\t\n"; + $answer .= "\t\t\t\t\t\t\t\n" + . "\t\t\t\t\t\t\n" + . "\t\t\t\t\t\t\n" + . "\t\t\t\t\t\n"; + } + $inputnames[]=$ia[1]; + return array($answer, $inputnames); + } - $answer .= "\t\t\t\n" +function do_listwithcomment($ia) + { + global $maxoptionsize, $dbprefix, $dropdowns, $dropdownthreshold, $lwcdropdowns; + global $shownoanswer; + $answer=""; + if (!isset($maxoptionsize)) {$maxoptionsize=35;} + $ansquery = "SELECT * FROM {$dbprefix}answers WHERE qid={$ia[0]} ORDER BY sortorder, answer"; + $ansresult = mysql_query($ansquery); + $anscount = mysql_num_rows($ansresult); + if ($lwcdropdowns == "R" && $anscount <= $dropdownthreshold) + { + $answer .= "\t\t\t
\n" . "\t\t\t\t\n" - . "\t\t\t\t\t\n" + . "\t\t\t\t\t\n" + . "\t\t\t\t\t\n" . "\t\t\t\t\n" . "\t\t\t\t\n" - . "\t\t\t\t\t\n"; - if (isset($maxselectlength) && $maxselectlength > 60) - { - $ranklist = str_replace("\n" - . "\t\t\t\t\t\t  "._YOURRANKING.":
\n"; - } - else + . "\t\t\t\t\t\n" - . "\t\t\t\t\n" - . "\t\t\t\t\t\n" - . "\t\t\t\t\n" - . "\t\t\t
\n" - . "\t\t\t\t\t\t"._RANK_1."
" - . "\t\t\t\t\t\t"._RANK_2 - . "\t\t\t\t\t
"._CHOOSEONE.":"._ENTERCOMMENT.":
\n" - . "\t\t\t\t\t\t  "._YOURCHOICES.":
\n" - . " ".$choicelist - . "\t\t\t\t\t 
\n"; + + while ($ansrow=mysql_fetch_array($ansresult)) { - $answer .= "\t\t\t\t\t\n" - . "\t\t\t\t\t\t     "._YOURRANKING.":
\n"; + $answer .= "\t\t\t\t\t\t\n" - . "\t\t\t\t
\n" - . "\t\t\t\t\t\t"._RANK_3."
" - . "\t\t\t\t\t\t"._RANK_4."" - . "\t\t\t\t\t
\n"; - break; - case "M": //MULTIPLE OPTIONS checkbox - $answer .= "\t\t\t\n" - . "\t\t\t\t\n" - . "\t\t\t\t\t\n" - . "\t\t\t\t\t\n"; + $fname2 = $ia[1]."comment"; + if ($anscount > 8) {$tarows = $anscount/1.2;} else {$tarows = 4;} + $answer .= "\t\t\t\t\t\n" . "\t\t\t\t\n" + . "\t\t\t\t\n" . "\t\t\t
 \n"; - $qquery = "SELECT other FROM {$dbprefix}questions WHERE qid=".$ia[0]; - $qresult = mysql_query($qquery); - while($qrow = mysql_fetch_array($qresult)) {$other = $qrow['other'];} - $ansquery = "SELECT * FROM {$dbprefix}answers WHERE qid={$ia[0]} ORDER BY sortorder, answer"; - $ansresult = mysql_query($ansquery); - $anscount = mysql_num_rows($ansresult); - if ($other == "Y") {$anscount++;} //COUNT OTHER AS AN ANSWER FOR MANDATORY CHECKING! - $answer .= "\t\t\t\t\t\n"; - $fn = 1; - if (!isset($multifields)) {$multifields="";} - while ($ansrow = mysql_fetch_array($ansresult)) + if ($ia[6] != "Y" && $shownoanswer == 1) { - $myfname = $ia[1].$ansrow['code']; - //LOOK HERE: TAKE OUT/MODIFY - //$multifields .= "$fname{$ansrow['code']}|"; - $answer .= "\t\t\t\t\t\t\n"; } - if ($other == "Y") + $answer .= "\t\t\t\t\t\n" + . "\t\t\t\t\t\t\n" + . "\t\t\t\t\t
\n"; - break; - case "P": //MULTIPLE OPTIONS WITH COMMENTS checkbox + text + $inputnames[]=$ia[1]; + $inputnames[]=$ia[1]."comment"; + } + else //Dropdown list + { $answer .= "\t\t\t\n" . "\t\t\t\t\n" - . "\t\t\t\t\t\n" - . "\t\t\t\t\t\n" - . "\t\t\t\t\t\n" . "\t\t\t\t\n" - . "\t\t\t
 \n"; - $qquery = "SELECT other FROM {$dbprefix}questions WHERE qid=".$ia[0]; - $qresult = mysql_query($qquery); - while ($qrow = mysql_fetch_array($qresult)) {$other = $qrow['other'];} - $ansquery = "SELECT * FROM {$dbprefix}answers WHERE qid={$ia[0]} ORDER BY sortorder, answer"; - $ansresult = mysql_query($ansquery); - $anscount = mysql_num_rows($ansresult)*2; - $answer .= "\t\t\t\t\t\n" - . "\t\t\t\t\t\t\n"; - $fn = 1; - while ($ansrow = mysql_fetch_array($ansresult)) + . "\t\t\t\t\t\n" - . "\t\t\t\t\t\t\t\t\n" - . "\t\t\t\t\n"; - $fn++; - $answer .= "\t\t\t\t\t\t\t\t\n" - . "\t\t\t\t\t\t\t\n"; - $fn++; - $inputnames[]=$myfname; - $inputnames[]=$myfname2; - if ($ia[6] == "Y" && $ia[7] != "Y") //Question is mandatory. Add to mandatory array - { - $mandatorys[]=$myfname; - $mandatoryfns[]=$ia[1]; - } - if ($ia[6] == "Y" && $ia[7] == "Y") + $answer .= "\t\t\t\t\t\t\n" - . "\t\t\t\t\t\t\t\t\n" - . "\t\t\t\t\t\t\t\n"; - $inputnames[]=$myfname; - $inputnames[]=$myfname2; - if ($ia[6] == "Y" && $ia[7] != "Y") //Question is mandatory. Add to mandatory array + if ((!$_SESSION[$ia[1]] && !$defexists) ||($_SESSION[$ia[1]] == ' ' && !$defexists)) { - $mandatorys[]=$myfname; - $mandatoryfns[]=$ia[1]; + $answer .= "\t\t\t\t\t\t\n"; } - if ($ia[6] == "Y" && $ia[7] == "Y") + elseif ($_SESSION[$ia[1]] && !$defexists) { - $conmandatorys[]=$myfname; - $conmandatoryfns[]=$ia[1]; + $answer .= "\t\t\t\t\t\t\n"; } } - $answer .= "\t\t\t\t\t\t
\n" + . "\t\t\t\t\t
\n" - . "\t\t\t\t\t\t\t\t\t" - . $ansrow['answer']."\n" - . "\t\t\t\t\t\t\t\t\n" - . "\t\t\t\t\t\t\t\t\t\n" - . "\t\t\t\t\t\t\t\t
\n" - . "\t\t\t\t\t\t\t\t\t"._OTHER.":\n" - . "\t\t\t\t\t\t\t\t\n" - . "\t\t\t\t\t\t\t\t\t\n" - . "\t\t\t\t\t\t\t\t
\n" + $answer .= "\t\t\t\t\t\n" . "\t\t\t\t\t
 
\n"; - break; - case "Q": //MULTIPLE SHORT TEXT - $ansquery = "SELECT * FROM {$dbprefix}answers WHERE qid={$ia[0]} ORDER BY sortorder, answer"; - $ansresult = mysql_query($ansquery); - $anscount = mysql_num_rows($ansresult)*2; - //$answer .= "\t\t\t\t\t\n"; - $fn = 1; - $answer .= "\t\t\t\t\t\t\n"; - while ($ansrow = mysql_fetch_array($ansresult)) + . "\t\t\t\t\n"; + $fname2 = $ia[1]."comment"; + if ($anscount > 8) {$tarows = $anscount/1.2;} else {$tarows = 4;} + if ($tarows > 15) {$tarows=15;} + $maxoptionsize=$maxoptionsize*0.72; + if ($maxoptionsize < 33) {$maxoptionsize=33;} + if ($maxoptionsize > 70) {$maxoptionsize=70;} + $answer .= "\t\t\t\t\t
\n"; + $answer .= "\t\t\t\t\t\t\n"; - $inputnames[]=$ia[1]; - break; - case "Y": //YES/NO radio-buttons - $answer .= "\t\t\t\n" - . "\t\t\t\t\n" - . "\t\t\t\t\t\n" + $answer .= "\n" + . "\t\t\t\t\t\n" . "\t\t\t\t\n" - . "\t\t\t\t\n" + . "\t\t\t\t\n" . "\t\t\t
\n" - . "\t\t\t\t\t\t
\n" - . "\t\t\t\t\t\t
\n"; - if ($ia[6] != "Y" && $shownoanswer == 1) - { - $answer .= "\t\t\t\t\t\t
\n"; + $answer .= str_replace("\\", "", $_SESSION[$fname2]); } - $answer .= "\t\t\t\t\t
\n"; $inputnames[]=$ia[1]; - break; - case "G": //GENDER drop-down list - $answer .= "\t\t\t\n" - . "\t\t\t\t\n" - . "\t\t\t\t\t\n" - . "\t\t\t\t\n" - . "\t\t\t\t\n" - . "\t\t\t
\n" - . "\t\t\t\t\t\t"._FEMALE."
\n" - . "\t\t\t\t\t\t
\n"; - if ($ia[6] != "Y" && $shownoanswer == 1) + $inputnames[]=$ia[1]."comment"; + } + return array($answer, $inputnames); + } + +function do_ranking($ia) + { + global $dbprefix; + $answer=""; + $ansquery = "SELECT * FROM {$dbprefix}answers WHERE qid={$ia[0]} ORDER BY sortorder, answer"; + $ansresult = mysql_query($ansquery); + $anscount = mysql_num_rows($ansresult); + $answer .= "\t\t\t\n"; + unset($answers); + //unset($inputnames); + unset($chosen); + $ranklist=""; + while ($ansrow = mysql_fetch_array($ansresult)) + { + $answers[] = array($ansrow['code'], $ansrow['answer']); + } + $existing=0; + for ($i=1; $i<=$anscount; $i++) + { + $myfname=$ia[1].$i; + if (isset($_SESSION[$myfname]) && $_SESSION[$myfname]) { - $answer .= "\t\t\t\t\t\t\n"; + $existing++; } - $answer .= "\t\t\t\t\t
\n"; - $inputnames[]=$ia[1]; - break; - case "A": //ARRAY (5 POINT CHOICE) radio-buttons - $qquery = "SELECT other FROM {$dbprefix}questions WHERE qid=".$ia[0]; - $qresult = mysql_query($qquery); - while($qrow = mysql_fetch_array($qresult)) {$other = $qrow['other'];} - $ansquery = "SELECT * FROM {$dbprefix}answers WHERE qid={$ia[0]} ORDER BY sortorder, answer"; - $ansresult = mysql_query($ansquery); - $anscount = mysql_num_rows($ansresult); - $fn = 1; - $answer .= "\t\t\t\n" - . "\t\t\t\t\n" - . "\t\t\t\t\t\n"; - for ($xc=1; $xc<=5; $xc++) + } + for ($i=1; $i<=$anscount; $i++) + { + $myfname = $ia[1].$i; + if (isset($_SESSION[$myfname]) && $_SESSION[$myfname]) { - $answer .= "\t\t\t\t\t\n"; + foreach ($answers as $ans) + { + if ($ans[0] == $_SESSION[$myfname]) + { + $thiscode=$ans[0]; + $thistext=$ans[1]; + } + } } - if ($ia[6] != "Y") //Question is not mandatory + $ranklist .= "\t\t\t\t\t\t $i: \n"; + $ranklist .= " value='"; + $ranklist .= $thistext; + $ranklist .= "'"; } - $answer .= "\t\t\t\t\n"; - while ($ansrow = mysql_fetch_array($ansresult)) - { - $myfname = $ia[1].$ansrow['code']; - if (!isset($trbc) || $trbc == "array1" || !$trbc) {$trbc = "array2";} else {$trbc = "array1";} - $answer .= "\t\t\t\t\n" - . "\t\t\t\t\t\n"; - for ($i=1; $i<=5; $i++) - { - $answer .= "\t\t\t\t\t
$xc
{$ansrow['answer']}\n"; - $fn++; - $inputnames[]=$myfname; - if ($ia[6] == "Y" && $ia[7] != "Y") //Question is mandatory. Add to mandatory array - { - $mandatorys[]=$myfname; - $mandatoryfns[]=$ia[1]; - } - if ($ia[6] == "Y" && $ia[7] == "Y") - { - $conmandatorys[]=$myfname; - $conmandatoryfns[]=$ia[1]; - } - } - - $answer .= "\t\t\t
\n"; - break; - case "B": //ARRAY (10 POINT CHOICE) radio-buttons - $qquery = "SELECT other FROM {$dbprefix}questions WHERE qid=".$ia[0]; - $qresult = mysql_query($qquery); - while($qrow = mysql_fetch_array($qresult)) {$other = $qrow['other'];} - $ansquery = "SELECT * FROM {$dbprefix}answers WHERE qid={$ia[0]} ORDER BY sortorder, answer"; - $ansresult = mysql_query($ansquery); - $anscount = mysql_num_rows($ansresult); - $fn = 1; - $answer .= "\t\t\t\n" - . "\t\t\t\t\n" - . "\t\t\t\t\t\n"; - for ($xc=1; $xc<=10; $xc++) + $ranklist .= " onFocus=\"this.blur()\">\n"; + $ranklist .= "\t\t\t\t\t\t$xc\n"; + $ranklist .= $thiscode; + $chosen[]=array($thiscode, $thistext); } - if ($ia[6] != "Y") //Question is not mandatory + $ranklist .= "' />\n"; + $ranklist .= "\t\t\t\t\t\t"._REMOVEITEM."\n"; + $ranklist .= "style='display:none'"; } - $answer .= "\t\t\t\t\n"; - while ($ansrow = mysql_fetch_array($ansresult)) + $ranklist .= " id='cut_{$ia[0]}$i' name='cut$i' onClick=\"deletethis_{$ia[0]}(document.phpsurveyor.RANK_{$ia[0]}$i.value, document.phpsurveyor.fvalue_{$ia[0]}$i.value, document.phpsurveyor.RANK_{$ia[0]}$i.name, this.id)\">
\n"; + $inputnames[]=$myfname; + } + + $choicelist = "\t\t\t\t\t\t\n"; - $answer .= "\t\t\t\t\t\n"; - for ($i=1; $i<=10; $i++) - { - $answer .= "\t\t\t\t\t\t\n" - . "\t\t\t\t\n"; - $inputnames[]=$myfname; - $fn++; - if ($ia[6] == "Y" && $ia[7] != "Y") //Question is mandatory. Add to mandatory array - { - $mandatorys[]=$myfname; - $mandatoryfns[]=$ia[1]; - } - if ($ia[6] == "Y" && $ia[7] == "Y") - { - $conmandatoryfns[]=$ia[1]; - $conmandatorys[]=$myfname; - } - } - $answer .= "\t\t\t
{$ansrow['answer']} $maxselectlength) {$maxselectlength = strlen($ans[1]);} } - $answer .= "\t\t\t\t
\n"; - break; - case "C": //ARRAY (YES/UNCERTAIN/NO) radio-buttons - $qquery = "SELECT other FROM {$dbprefix}questions WHERE qid=".$ia[0]; - $qresult = mysql_query($qquery); - while($qrow = mysql_fetch_array($qresult)) {$other = $qrow['other'];} - $ansquery = "SELECT * FROM {$dbprefix}answers WHERE qid={$ia[0]} ORDER BY sortorder, answer"; - $ansresult = mysql_query($ansquery); - $anscount = mysql_num_rows($ansresult); - $fn = 1; - $answer .= "\t\t\t\n" - . "\t\t\t\t\n" - . "\t\t\t\t\t\n" - . "\t\t\t\t\t\n" - . "\t\t\t\t\t\n" - . "\t\t\t\t\t\n"; - if ($ia[6] != "Y") //Question is not mandatory - { - $answer .= "\t\t\t\t\t\n"; } - $answer .= "\t\t\t\t\n"; - while ($ansrow = mysql_fetch_array($ansresult)) + } + else + { + foreach ($answers as $ans) { - $myfname = $ia[1].$ansrow['code']; - if (!isset($trbc) || $trbc == "array1") {$trbc = "array2";} else {$trbc = "array1";} - $answer .= "\t\t\t\t\n" - . "\t\t\t\t\t\n" - . "\t\t\t\t\t\t\n" - . "\t\t\t\t\n"; - $inputnames[]=$myfname; - $fn++; - if ($ia[6] == "Y" && $ia[7] != "Y") //Question is mandatory. Add to mandatory array - { - $mandatorys[]=$myfname; - $mandatoryfns[]=$ia[1]; - } - if ($ia[6] == "Y" && $ia[7] == "Y") - { - $conmandatorys[]=$myfname; - $conmandatoryfns[]=$ia[1]; - } - } - $answer .= "\t\t\t
"._YES.""._UNCERTAIN.""._NO.""._NOTAPPLICABLE."
{$ansrow['answer']} $maxselectlength) {$maxselectlength = strlen($ans[1]);} } - $answer .= "\t\t\t\t
\n"; - break; - case "E": //ARRAY (Increase/Same/Decrease) radio-buttons - $qquery = "SELECT other FROM {$dbprefix}questions WHERE qid=".$ia[0]; - $qresult = mysql_query($qquery); - while($qrow = mysql_fetch_array($qresult)) {$other = $qrow['other'];} - $ansquery = "SELECT * FROM {$dbprefix}answers WHERE qid={$ia[0]} ORDER BY sortorder, answer"; - $ansresult = mysql_query($ansquery); - $anscount = mysql_num_rows($ansresult); - $fn = 1; - $answer .= "\t\t\t\n" - . "\t\t\t\t\n" - . "\t\t\t\t\t\n" - . "\t\t\t\t\t\n" - . "\t\t\t\t\t\n" - . "\t\t\t\t\t\n"; - if ($ia[6] != "Y") //Question is not mandatory - { - $answer .= "\t\t\t\t\t\n"; } - $answer .= "\t\t\t\t\n"; - while ($ansrow = mysql_fetch_array($ansresult)) + } + $choicelist .= "\t\t\t\t\t\t\n"; + + $answer .= "\t\t\t
"._INCREASE.""._SAME.""._DECREASE.""._NOTAPPLICABLE."
\n" + . "\t\t\t\t\n" + . "\t\t\t\t\t\n" + . "\t\t\t\t\n" + . "\t\t\t\t\n" + . "\t\t\t\t\t\n"; + if (isset($maxselectlength) && $maxselectlength > 60) + { + $ranklist = str_replace("\n" + . "\t\t\t\t\t\t  "._YOURRANKING.":
\n"; + } + else + { + $answer .= "\t\t\t\t\t\n" + . "\t\t\t\t\n" + . "\t\t\t\t\n" + . "\t\t\t\t\t\n" + . "\t\t\t\t\n" + . "\t\t\t
\n" + . "\t\t\t\t\t\t"._RANK_1."
" + . "\t\t\t\t\t\t"._RANK_2 + . "\t\t\t\t\t
\n" + . "\t\t\t\t\t\t  "._YOURCHOICES.":
\n" + . " ".$choicelist + . "\t\t\t\t\t 
\n" + . "\t\t\t\t\t\t     "._YOURRANKING.":
\n"; + } + $answer .= $ranklist + . "\t\t\t\t\t
\n" + . "\t\t\t\t\t\t"._RANK_3."
" + . "\t\t\t\t\t\t"._RANK_4."" + . "\t\t\t\t\t
\n"; + + return array($answer, $inputnames); + } + +function do_multiplechoice($ia) + { + global $dbprefix; + + $answer = "\t\t\t\n" + . "\t\t\t\t\n" + . "\t\t\t\t\t\n" + . "\t\t\t\t\t\n" + . "\t\t\t\t\t\n" + . "\t\t\t\t\n" + . "\t\t\t
 \n"; + $qquery = "SELECT other FROM {$dbprefix}questions WHERE qid=".$ia[0]; + $qresult = mysql_query($qquery); + while($qrow = mysql_fetch_array($qresult)) {$other = $qrow['other'];} + $ansquery = "SELECT * FROM {$dbprefix}answers WHERE qid={$ia[0]} ORDER BY sortorder, answer"; + $ansresult = mysql_query($ansquery); + $anscount = mysql_num_rows($ansresult); + if ($other == "Y") {$anscount++;} //COUNT OTHER AS AN ANSWER FOR MANDATORY CHECKING! + $answer .= "\t\t\t\t\t\n"; + $fn = 1; + if (!isset($multifields)) {$multifields="";} + while ($ansrow = mysql_fetch_array($ansresult)) + { + $myfname = $ia[1].$ansrow['code']; + //LOOK HERE: TAKE OUT/MODIFY + //$multifields .= "$fname{$ansrow['code']}|"; + $answer .= "\t\t\t\t\t\t\n"; + $inputnames[]=$myfname; + $anscount++; + } + $answer .= "\t\t\t\t\t 
\n"; + return array($answer, $inputnames); + } + +function do_multiplechoice_withcomments($ia) + { + global $dbprefix; + $answer = "\t\t\t\n" + . "\t\t\t\t\n" + . "\t\t\t\t\t\n" + . "\t\t\t\t\t\n" + . "\t\t\t\t\t\n" + . "\t\t\t\t\n" + . "\t\t\t
 \n"; + $qquery = "SELECT other FROM {$dbprefix}questions WHERE qid=".$ia[0]; + $qresult = mysql_query($qquery); + while ($qrow = mysql_fetch_array($qresult)) {$other = $qrow['other'];} + $ansquery = "SELECT * FROM {$dbprefix}answers WHERE qid={$ia[0]} ORDER BY sortorder, answer"; + $ansresult = mysql_query($ansquery); + $anscount = mysql_num_rows($ansresult)*2; + $answer .= "\t\t\t\t\t\n" + . "\t\t\t\t\t\t\n"; + $fn = 1; + while ($ansrow = mysql_fetch_array($ansresult)) + { + $myfname = $ia[1].$ansrow['code']; + $myfname2 = $myfname."comment"; + $answer .= "\t\t\t\t\t\t\t\n" + . "\t\t\t\t\t\t\t\t\n" + . "\t\t\t\t\n"; + $fn++; + $answer .= "\t\t\t\t\t\t\t\t\n" + . "\t\t\t\t\t\t\t\n"; + $fn++; + $inputnames[]=$myfname; + $inputnames[]=$myfname2; + } + if ($other == "Y") + { + $myfname = $ia[1]."other"; + $myfname2 = $myfname."comment"; + $anscount = $anscount + 2; + $answer .= "\t\t\t\t\t\t\t\n" + . "\t\t\t\t\t\t\t\t\n" + . "\t\t\t\t\t\t\t\n"; + $inputnames[]=$myfname; + $inputnames[]=$myfname2; + } + $answer .= "\t\t\t\t\t\t
\n" + . "\t\t\t\t\t\t\t\t\t" + . $ansrow['answer']."\n" + . "\t\t\t\t\t\t\t\t\n" + . "\t\t\t\t\t\t\t\t\t\n" + . "\t\t\t\t\t\t\t\t
\n" + . "\t\t\t\t\t\t\t\t\t"._OTHER.":\n" + . "\t\t\t\t\t\t\t\t\n" + . "\t\t\t\t\t\t\t\t\t\n" + . "\t\t\t\t\t\t\t\t
\n" + . "\t\t\t\t\t
 
\n"; + return array($answer, $inputnames); + } + +function do_multipleshorttext($ia) + { + global $dbprefix; + + $ansquery = "SELECT * FROM {$dbprefix}answers WHERE qid={$ia[0]} ORDER BY sortorder, answer"; + $ansresult = mysql_query($ansquery); + $anscount = mysql_num_rows($ansresult)*2; + //$answer .= "\t\t\t\t\t\n"; + $fn = 1; + $answer = "\t\t\t\t\t\t\n"; + while ($ansrow = mysql_fetch_array($ansresult)) + { + $myfname = $ia[1].$ansrow['code']; + $answer .= "\t\t\t\t\t\t\t\n" + . "\t\t\t\t\t\t\t\t\n" + . "\t\t\t\t\t\t\t\t\n" + . "\t\t\t\t\t\t\t\n"; + $fn++; + $inputnames[]=$myfname; + } + $answer .= "\t\t\t\t\t\t
\n" + . "\t\t\t\t\t\t\t\t\t{$ansrow['answer']}\n" + . "\t\t\t\t\t\t\t\t\n" + . "\t\t\t\t\t\t\t\t\t\n" + . "\t\t\t\t\t\t\t\t
\n"; + return array($answer, $inputnames); + } + +function do_numerical($ia) + { + $answer = keycontroljs() + . "\t\t\t
\n" + . "\t\t\t"._NUMERICAL_PS."\n"; + $inputnames[]=$ia[1]; + $mandatory=null; + return array($answer, $inputnames, $mandatory); + } + +function do_shortfreetext($ia) + { + $answer = "\t\t\t\n"; + $inputnames[]=$ia[1]; + return array($answer, $inputnames); + } + +function do_longfreetext($ia) + { + $answer = "\n"; + $inputnames[]=$ia[1]; + return array($answer, $inputnames); + } + +function do_yesno($ia) + { + global $shownoanswer; + $answer = "\t\t\t\n" + . "\t\t\t\t\n" + . "\t\t\t\t\t\n" + . "\t\t\t\t\n" + . "\t\t\t\t\n" + . "\t\t\t
\n" + . "\t\t\t\t\t\t
\n" + . "\t\t\t\t\t\t
\n"; + if ($ia[6] != "Y" && $shownoanswer == 1) + { + $answer .= "\t\t\t\t\t\t
\n"; + } + $answer .= "\t\t\t\t\t
\n"; + $inputnames[]=$ia[1]; + return array($answer, $inputnames); + } + +function do_gender($ia) + { + global $shownoanswer; + $answer = "\t\t\t\n" + . "\t\t\t\t\n" + . "\t\t\t\t\t\n" + . "\t\t\t\t\n" + . "\t\t\t\t\n" + . "\t\t\t
\n" + . "\t\t\t\t\t\t"._FEMALE."
\n" + . "\t\t\t\t\t\t
\n"; + if ($ia[6] != "Y" && $shownoanswer == 1) + { + $answer .= "\t\t\t\t\t\t\n"; + } + $answer .= "\t\t\t\t\t
\n"; + $inputnames[]=$ia[1]; + return array($answer, $inputnames); + } + +function do_array_5point($ia) + { + global $dbprefix; + $qquery = "SELECT other FROM {$dbprefix}questions WHERE qid=".$ia[0]; + $qresult = mysql_query($qquery); + while($qrow = mysql_fetch_array($qresult)) {$other = $qrow['other'];} + $ansquery = "SELECT * FROM {$dbprefix}answers WHERE qid={$ia[0]} ORDER BY sortorder, answer"; + $ansresult = mysql_query($ansquery); + $anscount = mysql_num_rows($ansresult); + $fn = 1; + $answer = "\t\t\t\n" + . "\t\t\t\t\n" + . "\t\t\t\t\t\n"; + for ($xc=1; $xc<=5; $xc++) + { + $answer .= "\t\t\t\t\t\n"; + } + if ($ia[6] != "Y") //Question is not mandatory + { + $answer .= "\t\t\t\t\t\n"; + } + $answer .= "\t\t\t\t\n"; + while ($ansrow = mysql_fetch_array($ansresult)) + { + $myfname = $ia[1].$ansrow['code']; + if (!isset($trbc) || $trbc == "array1" || !$trbc) {$trbc = "array2";} else {$trbc = "array1";} + $answer .= "\t\t\t\t\n" + . "\t\t\t\t\t\n"; + for ($i=1; $i<=5; $i++) { - $myfname = $ia[1].$ansrow['code']; - if (!isset($trbc) || $trbc == "array1") {$trbc = "array2";} else {$trbc = "array1";} - $answer .= "\t\t\t\t\n" - . "\t\t\t\t\t\n" - . "\t\t\t\t\t\t
$xc"._NOTAPPLICABLE."
{$ansrow['answer']}
{$ansrow['answer']}\n"; - $inputnames[]=$myfname; - $fn++; - if ($ia[6] == "Y" && $ia[7] != "Y") //Question is mandatory. Add to mandatory array - { - $mandatorys[]=$myfname; - $mandatoryfns[]=$ia[1]; - } - if ($ia[6] == "Y" && $ia[7] == "Y") - { - $conmandatorys[]=$myfname; - $conmandatoryfns[]=$ia[1]; - } - } - $answer .= "\t\t\t
\n"; - break; - case "F": //ARRAY (Flexible) - Row Format - $qquery = "SELECT other, lid FROM {$dbprefix}questions WHERE qid=".$ia[0]; - $qresult = mysql_query($qquery); - while($qrow = mysql_fetch_array($qresult)) {$other = $qrow['other']; $lid = $qrow['lid'];} - $lquery = "SELECT * FROM {$dbprefix}labels WHERE lid=$lid ORDER BY sortorder, code"; - //echo $lquery; - $lresult = mysql_query($lquery); - while ($lrow=mysql_fetch_array($lresult)) - { - $labelans[]=$lrow['title']; - $labelcode[]=$lrow['code']; } - $cellwidth=60/count($labelans); - if ($ia[6] != "Y") {$cellwidth++;} - //$cellwidth=sprintf("%02d", 60/$cellwidth); - $ansquery = "SELECT * FROM {$dbprefix}answers WHERE qid={$ia[0]} ORDER BY sortorder, answer"; - $ansresult = mysql_query($ansquery); - $anscount = mysql_num_rows($ansresult); - $fn=1; - $answer .= "\t\t\t\n" - . "\t\t\t\t\n" - . "\t\t\t\t\t\n"; - foreach ($labelans as $ld) + if ($ia[6] != "Y") { - $answer .= "\t\t\t\t\t\n"; + $answer .= "\t\t\t\t\t
".$ld."\n"; + $fn++; + $inputnames[]=$myfname; + } + + $answer .= "\t\t\t
\n"; + return array($answer, $inputnames); + } + +function do_array_10point($ia) + { + global $dbprefix; + $qquery = "SELECT other FROM {$dbprefix}questions WHERE qid=".$ia[0]; + $qresult = mysql_query($qquery); + while($qrow = mysql_fetch_array($qresult)) {$other = $qrow['other'];} + $ansquery = "SELECT * FROM {$dbprefix}answers WHERE qid={$ia[0]} ORDER BY sortorder, answer"; + $ansresult = mysql_query($ansquery); + $anscount = mysql_num_rows($ansresult); + $fn = 1; + $answer = "\t\t\t\n" + . "\t\t\t\t\n" + . "\t\t\t\t\t\n"; + for ($xc=1; $xc<=10; $xc++) + { + $answer .= "\t\t\t\t\t\n"; + } + if ($ia[6] != "Y") //Question is not mandatory + { + $answer .= "\t\t\t\t\t\n"; + } + $answer .= "\t\t\t\t\n"; + while ($ansrow = mysql_fetch_array($ansresult)) + { + $myfname = $ia[1].$ansrow['code']; + if (!isset($trbc) || $trbc == "array1" || !$trbc) {$trbc = "array2";} else {$trbc = "array1";} + $answer .= "\t\t\t\t\n"; + $answer .= "\t\t\t\t\t\n"; + for ($i=1; $i<=10; $i++) { - $answer .= "\t\t\t\t\t\n"; + $answer .= "\t\t\t\t\t\t\n" + . "\t\t\t\t\n"; + $inputnames[]=$myfname; + $fn++; + } + $answer .= "\t\t\t
$xc"._NOTAPPLICABLE."
{$ansrow['answer']}"._NOTAPPLICABLE." 54) {$percwidth=60;} - elseif ($ansrowavg < 5) {$percwidth=5;} - //elseif ($ansrowavg > 25) {$percwidth=30;} - else {$percwidth=$ansrowavg*1.2;} - $otherwidth=(100-$percwidth)/$cellwidth; - $ansresult = mysql_query($ansquery); - while ($ansrow = mysql_fetch_array($ansresult)) + $answer .= "\t\t\t\t
\n"; + return array($answer, $inputnames); + } + +function do_array_yesnouncertain($ia) + { + global $dbprefix; + $qquery = "SELECT other FROM {$dbprefix}questions WHERE qid=".$ia[0]; + $qresult = mysql_query($qquery); + while($qrow = mysql_fetch_array($qresult)) {$other = $qrow['other'];} + $ansquery = "SELECT * FROM {$dbprefix}answers WHERE qid={$ia[0]} ORDER BY sortorder, answer"; + $ansresult = mysql_query($ansquery); + $anscount = mysql_num_rows($ansresult); + $fn = 1; + $answer = "\t\t\t\n" + . "\t\t\t\t\n" + . "\t\t\t\t\t\n" + . "\t\t\t\t\t\n" + . "\t\t\t\t\t\n" + . "\t\t\t\t\t\n"; + if ($ia[6] != "Y") //Question is not mandatory + { + $answer .= "\t\t\t\t\t\n"; + } + $answer .= "\t\t\t\t\n"; + while ($ansrow = mysql_fetch_array($ansresult)) + { + $myfname = $ia[1].$ansrow['code']; + if (!isset($trbc) || $trbc == "array1") {$trbc = "array2";} else {$trbc = "array1";} + $answer .= "\t\t\t\t\n" + . "\t\t\t\t\t\n" + . "\t\t\t\t\t\t\n"; - foreach ($labelcode as $ld) - { - $answer .= "\t\t\t\t\t
"._YES.""._UNCERTAIN.""._NO.""._NOTAPPLICABLE."
{$ansrow['answer']}{$ansrow['answer']}"; - $answer .= "\n"; - $inputnames[]=$myfname; - $fn++; - if ($ia[6] == "Y" && $ia[7] != "Y") //Question is mandatory. Add to mandatory array - { - $mandatorys[]=$myfname; - $mandatoryfns[]=$ia[1]; - } - if ($ia[6] == "Y" && $ia[7] == "Y") - { - $conmandatorys[]=$myfname; - $conmandatoryfns[]=$ia[1]; - } + $answer .= "\t\t\t\t\t\n"; + $inputnames[]=$myfname; + $fn++; + } + $answer .= "\t\t\t
\n"; + return array($answer, $inputnames); + } + +function do_array_increasesamedecrease($ia) + { + global $dbprefix; + $qquery = "SELECT other FROM {$dbprefix}questions WHERE qid=".$ia[0]; + $qresult = mysql_query($qquery); + while($qrow = mysql_fetch_array($qresult)) {$other = $qrow['other'];} + $ansquery = "SELECT * FROM {$dbprefix}answers WHERE qid={$ia[0]} ORDER BY sortorder, answer"; + $ansresult = mysql_query($ansquery); + $anscount = mysql_num_rows($ansresult); + $fn = 1; + $answer = "\t\t\t\n" + . "\t\t\t\t\n" + . "\t\t\t\t\t\n" + . "\t\t\t\t\t\n" + . "\t\t\t\t\t\n" + . "\t\t\t\t\t\n"; + if ($ia[6] != "Y") //Question is not mandatory + { + $answer .= "\t\t\t\t\t\n"; + } + $answer .= "\t\t\t\t\n"; + while ($ansrow = mysql_fetch_array($ansresult)) + { + $myfname = $ia[1].$ansrow['code']; + if (!isset($trbc) || $trbc == "array1") {$trbc = "array2";} else {$trbc = "array1";} + $answer .= "\t\t\t\t\n" + . "\t\t\t\t\t\n" + . "\t\t\t\t\t\t\n" + . "\t\t\t\t\n"; + $inputnames[]=$myfname; + $fn++; + } + $answer .= "\t\t\t
"._INCREASE.""._SAME.""._DECREASE.""._NOTAPPLICABLE."
{$ansrow['answer']}$lrow['title'], "code"=>$lrow['code']); + $answer .= "\t\t\t\t\t_NOTAPPLICABLE, "code"=>""); + $answer .= "\t\t\t\t
\n"; + return array($answer, $inputnames); + } + +function do_array_flexible($ia) + { + global $dbprefix; + $qquery = "SELECT other, lid FROM {$dbprefix}questions WHERE qid=".$ia[0]; + $qresult = mysql_query($qquery); + while($qrow = mysql_fetch_array($qresult)) {$other = $qrow['other']; $lid = $qrow['lid'];} + $lquery = "SELECT * FROM {$dbprefix}labels WHERE lid=$lid ORDER BY sortorder, code"; + //echo $lquery; + $lresult = mysql_query($lquery); + while ($lrow=mysql_fetch_array($lresult)) + { + $labelans[]=$lrow['title']; + $labelcode[]=$lrow['code']; } - - $ansquery = "SELECT * FROM {$dbprefix}answers WHERE qid={$ia[0]} ORDER BY sortorder, answer"; - $ansresult = mysql_query($ansquery); - $anscount = mysql_num_rows($ansresult); - $fn=1; - $answer .= "\t\t\t\n" - . "\t\t\t\t\n" - . "\t\t\t\t\t\n"; - $cellwidth=$anscount; - //if ($ia[6] != "Y") {$cellwidth++;} - $cellwidth=60/$cellwidth; - while ($ansrow = mysql_fetch_array($ansresult)) + $cellwidth=60/count($labelans); + if ($ia[6] != "Y") {$cellwidth++;} + //$cellwidth=sprintf("%02d", 60/$cellwidth); + $ansquery = "SELECT * FROM {$dbprefix}answers WHERE qid={$ia[0]} ORDER BY sortorder, answer"; + $ansresult = mysql_query($ansquery); + $anscount = mysql_num_rows($ansresult); + $fn=1; + $answer = "\t\t\t
\n" + . "\t\t\t\t\n" + . "\t\t\t\t\t\n"; + foreach ($labelans as $ld) + { + $answer .= "\t\t\t\t\t\n"; + } + if ($ia[6] != "Y") //Question is not mandatory + { + $answer .= "\t\t\t\t\t\n"; + } + $answer .= "\t\t\t\t\n"; + $ansrowcount=0; + $ansrowtotallength=0; + while ($ansrow = mysql_fetch_array($ansresult)) + { + $ansrowcount++; + $ansrowtotallength=$ansrowtotallength+strlen($ansrow['answer']); + } + $ansrowavg=(($ansrowtotallength/$ansrowcount)/2); + if ($ansrowavg > 54) {$percwidth=60;} + elseif ($ansrowavg < 5) {$percwidth=5;} + //elseif ($ansrowavg > 25) {$percwidth=30;} + else {$percwidth=$ansrowavg*1.2;} + $otherwidth=(100-$percwidth)/$cellwidth; + $ansresult = mysql_query($ansquery); + while ($ansrow = mysql_fetch_array($ansresult)) + { + $myfname = $ia[1].$ansrow['code']; + if (!isset($trbc) || $trbc == "array1") {$trbc = "array2";} else {$trbc = "array1";} + $answer .= "\t\t\t\t\n" + . "\t\t\t\t\t\n"; + foreach ($labelcode as $ld) { - $anscode[]=$ansrow['code']; - $answers[]=$ansrow['answer']; + $answer .= "\t\t\t\t\t\n"; + $answer .= "\t\t\t\t\t
".$ld.""._NOTAPPLICABLE."
{$ansrow['answer']}"; + $answer .= "\n"; + $inputnames[]=$myfname; + $fn++; + } + $answer .= "\t\t\t
\n"; + unset($labelans); + unset($labelcode); + return array($answer, $inputnames); + } + +function do_array_flexiblecolumns($ia) + { + global $dbprefix; + $qquery = "SELECT other, lid FROM {$dbprefix}questions WHERE qid=".$ia[0]; + $qresult = mysql_query($qquery); + while($qrow = mysql_fetch_array($qresult)) {$other = $qrow['other']; $lid = $qrow['lid'];} + $lquery = "SELECT * FROM {$dbprefix}labels WHERE lid=$lid ORDER BY sortorder, code"; + $lresult = mysql_query($lquery); + while ($lrow=mysql_fetch_array($lresult)) + { + $labelans[]=$lrow['title']; + $labelcode[]=$lrow['code']; + $labels[]=array("answer"=>$lrow['title'], "code"=>$lrow['code']); + } + if ($ia[6] != "Y") { + $labelcode[]=""; + $labelans[]=_NOTAPPLICABLE; + $labels[]=array("answer"=>_NOTAPPLICABLE, "code"=>""); + } + + $ansquery = "SELECT * FROM {$dbprefix}answers WHERE qid={$ia[0]} ORDER BY sortorder, answer"; + $ansresult = mysql_query($ansquery); + $anscount = mysql_num_rows($ansresult); + $fn=1; + $answer = "\t\t\t\n" + . "\t\t\t\t\n" + . "\t\t\t\t\t\n"; + $cellwidth=$anscount; + //if ($ia[6] != "Y") {$cellwidth++;} + $cellwidth=60/$cellwidth; + while ($ansrow = mysql_fetch_array($ansresult)) + { + $anscode[]=$ansrow['code']; + $answers[]=$ansrow['answer']; + } + foreach ($answers as $ld) + { + if (!isset($trbc) || $trbc == "array1") {$trbc = "array2";} else {$trbc = "array1";} + $answer .= "\t\t\t\t\t\n"; + } + unset($trbc); + $answer .= "\t\t\t\t\n"; + $ansrowcount=0; + $ansrowtotallength=0; + while ($ansrow = mysql_fetch_array($ansresult)) + { + $ansrowcount++; + $ansrowtotallength=$ansrowtotallength+strlen($ansrow['answer']); + } + foreach($labels as $ansrow) + { + //$myfname = $ia[1].$ansrow['code']; + $answer .= "\t\t\t\t\n" + . "\t\t\t\t\t\n"; + foreach ($anscode as $ld) { - $ansrowcount++; - $ansrowtotallength=$ansrowtotallength+strlen($ansrow['answer']); + if (!isset($trbc) || $trbc == "array1") {$trbc = "array2";} else {$trbc = "array1";} + $myfname=$ia[1].$ld; + $answer .= "\t\t\t\t\t\n"; - foreach ($anscode as $ld) + if ($ar && $ar !== null) { - if (!isset($trbc) || $trbc == "array1") {$trbc = "array2";} else {$trbc = "array1";} - $myfname=$ia[1].$ld; - $answer .= "\t\t\t\t\t
".$ld."
{$ansrow['answer']}"; + $answer .= "{$ansrow['answer']}"; - $answer .= ""; - break; - case "M": - case "P": - $qtitle .= "
\n
" - . _INSTRUCTION_MULTI.""; - break; - + } + return $array1; } -if (isset($notanswered) && is_array($notanswered)) //ADD WARNINGS TO QUESTIONS IF THEY WERE MANDATORY BUT NOT ANSWERED +function remove_nulls_from_array($array) { - if (in_array($ia[1], $notanswered)) + foreach ($array as $ar) + { + if ($ar !== null) + { + $return[]=$ar; + } + } + if (isset($return)) { - $qtitle = ""._MANDATORY."."; - if ($ia[4] == "A" || $ia[4] == "B" || $ia[4] == "C" || $ia[4] == "Q" || $ia[4] == "F") - { $qtitle .= "
\n"._MANDATORY_PARTS."."; } - if ($ia[4] == "M" || $ia[4] == "P") - { $qtitle .= "
\n"._MANDATORY_CHECK.".";} - if ($ia[4] == "R") - { $qtitle .= "
\n"._MANDATORY_RANK."."; } - $qtitle .= "

\n"; - $qtitle .= $ia[3]; + return $return; } - //POPUP WARNING - if (!isset($mandatorypopup)) + else { - $popup="\n"; - $mandatorypopup="Y"; + return false; } } - -$qanda[]=array($qtitle, $answer, $help, $display, $name, $ia[2], $gl[0]); ?> \ No newline at end of file