コード例 #1
0
    public function run($args)
    {
        $funcName = array_shift($args);
        try {
            $func = dTexts::loadFunction($funcName);
            $newStr = $func->run($args);
            if (strtolower($newStr) == 'true') {
                $id = time() . rand(0, 100);
                $hideJS = <<<EOF
\t\t<div id="hide_{$id}" style="display:none;"/>
\t\t<script\ttype="text/javascript">
\t\t \tvar elem = \$('#hide_{$id}').parent();
\t\t \tif(elem.is("li")){
\t\t\t\telem.css('display','none');
\t\t\t}else{
\t\t\t\telem = elem.parent();
\t\t\t\tif(elem.is("li")){
\t\t\t\t\telem.css('display','none');
\t\t\t\t}else{
\t\t\t\t\telem = elem.parent();
\t\t\t\t\tif(elem.is("li")){
\t\t\t\t\t\telem.css('display','none');
\t\t\t\t\t}
\t\t\t\t}\t\t\t
\t\t\t}
\t\t\t
\t\t\t
\t\t</script>
EOF;
                return $hideJS;
            }
        } catch (Exception $e) {
            throw $e;
        }
        return '';
    }
コード例 #2
0
ファイル: qanda.php プロジェクト: nmklong/limesurvey-cdio3
function do_array_dual($ia)
{
    global $dbprefix, $connect, $thissurvey, $clang;
    global $repeatheadings;
    global $notanswered;
    global $minrepeatheadings;

    if ($ia[8] == 'Y')
    {
        $checkconditionFunction = "checkconditions";
    }
    else
    {
        $checkconditionFunction = "noop_checkconditions";
    }

    $inputnames=array();
    $labelans1=array();
    $labelans=array();
    $qquery = "SELECT other FROM {$dbprefix}questions WHERE qid=".$ia[0]." AND language='".$_SESSION['s_lang']."'";
    $other = $connect->GetOne($qquery);    //Checked
    $lquery =  "SELECT * FROM {$dbprefix}answers WHERE scale_id=0 AND qid={$ia[0]} AND language='".$_SESSION['s_lang']."' ORDER BY sortorder, code";
    $lquery1 = "SELECT * FROM {$dbprefix}answers WHERE scale_id=1 AND qid={$ia[0]} AND language='".$_SESSION['s_lang']."' ORDER BY sortorder, code";
    $qidattributes=getQuestionAttributes($ia[0],$ia[4]);

    if ($qidattributes['use_dropdown']==1)
    {
        $useDropdownLayout = true;
    }
    else
    {
        $useDropdownLayout = false;
    }

    if (trim($qidattributes['dualscale_headerA'])!='') {
        $leftheader= $clang->gT($qidattributes['dualscale_headerA']);
    }
    else
    {
        $leftheader ='';
    }

    if (trim($qidattributes['dualscale_headerB'])!='')
    {
        $rightheader= $clang->gT($qidattributes['dualscale_headerB']);
    }
    else {
        $rightheader ='';
    }

    $lresult = db_execute_assoc($lquery); //Checked
    if ($useDropdownLayout === false && $lresult->RecordCount() > 0)
    {

        if (trim($qidattributes['answer_width'])!='')
        {
            $answerwidth=$qidattributes['answer_width'];
        }
        else
        {
            $answerwidth=20;
        }
        $columnswidth = 100 - $answerwidth;


        while ($lrow=$lresult->FetchRow())
        {
            $labelans[]=$lrow['answer'];
            $labelcode[]=$lrow['code'];
        }
        $lresult1 = db_execute_assoc($lquery1); //Checked
        if ($lresult1->RecordCount() > 0)
        {
            while ($lrow1=$lresult1->FetchRow())
            {
                $labelans1[]=$lrow1['answer'];
                $labelcode1[]=$lrow1['code'];
            }
        }
        $numrows=count($labelans) + count($labelans1);
        if ($ia[6] != "Y" && SHOW_NO_ANSWER == 1) {$numrows++;}
        $cellwidth=$columnswidth/$numrows;

        $cellwidth=sprintf("%02d", $cellwidth);

        $ansquery = "SELECT question FROM {$dbprefix}questions WHERE parent_qid=".$ia[0]." and scale_id=0 AND question like '%|%'";
        $ansresult = db_execute_assoc($ansquery);   //Checked
        if ($ansresult->RecordCount()>0)
        {
            $right_exists=true;
        }
        else
        {
            $right_exists=false;
        }
        // $right_exists is a flag to find out if there are any right hand answer parts. If there arent we can leave out the right td column
        if ($qidattributes['random_order']==1) {
            $ansquery = "SELECT * FROM {$dbprefix}questions WHERE parent_qid=$ia[0] AND language='".$_SESSION['s_lang']."' and scale_id=0 ORDER BY ".db_random();
        }
        else
        {
            $ansquery = "SELECT * FROM {$dbprefix}questions WHERE parent_qid=$ia[0] AND language='".$_SESSION['s_lang']."' and scale_id=0 ORDER BY question_order";
        }
        $ansresult = db_execute_assoc($ansquery);   //Checked
        $anscount = $ansresult->RecordCount();
        $fn=1;
        // unselect second scale when using "no answer"
        $answer = "<script type='text/javascript'>\n"
        . "<!--\n"
        . "\tfunction noanswer_checkconditions(value, name, type)\n"
        . "{\n"
        . "\tvar vname;\n"
        . "\tvname = name.replace(/#0/g,\"#1\");\n"
        . "\tfor(var i=0, n=document.getElementsByName(vname).length; i<n; ++i)\n"
        . "\t{\n"
        . "document.getElementsByName(vname)[i].checked=false;\n"
        . "\t}\n"
        . "\t$checkconditionFunction(value, name, type);\n"
        . "}\n"
        . "\tfunction secondlabel_checkconditions(value, name, type)\n"
        . "{\n"
        . "\tvar vname;\n"
        . "\tvname = \"answer\"+name.replace(/#1/g,\"#0-\");\n"
        . "\tif(document.getElementById(vname))\n"
        . "\t{\n"
        . "document.getElementById(vname).checked=false;\n"
        . "\t}\n"
        . "\t$checkconditionFunction(value, name, type);\n"
        . "}\n"
        . " //-->\n"
        . " </script>\n";



        // Header row and colgroups
        $mycolumns = "\t<colgroup class=\"col-responses group-1\">\n"
        ."\t<col class=\"col-answers\" width=\"$answerwidth%\" />\n";


        $myheader2 = "\n<tr class=\"array1 header_row\">\n"
        . "\t<th class=\"header_answer_text\">&nbsp;</th>\n\n";
        $odd_even = '';
        foreach ($labelans as $ld)
        {
            $myheader2 .= "\t<th>".$ld."</th>\n";
            $odd_even = alternation($odd_even);
            $mycolumns .= "<col class=\"$odd_even\" width=\"$cellwidth%\" />\n";
        }
        $mycolumns .= "\t</colgroup>\n";

        if (count($labelans1)>0) // if second label set is used
        {
            $mycolumns .= "\t<colgroup class=\"col-responses group-2\">\n"
            . "\t<col class=\"seperator\" />\n";
            $myheader2 .= "\n\t<td class=\"header_separator\">&nbsp;</td>\n\n"; // Separator
            foreach ($labelans1 as $ld)
            {
                $myheader2 .= "\t<th>".$ld."</th>\n";
                $odd_even = alternation($odd_even);
                $mycolumns .= "<col class=\"$odd_even\" width=\"$cellwidth%\" />\n";
            }

        }
        if ($right_exists)
        {
        	$myheader2 .= "\t<td class=\"header_answer_text_right\">&nbsp;</td>\n";
            $mycolumns .= "\n\t<col class=\"answertextright\" />\n\n";
        }
        if ($ia[6] != 'Y' && SHOW_NO_ANSWER == 1) //Question is not mandatory and we can show "no answer"
        {
        	$myheader2 .= "\t<td class=\"header_separator\">&nbsp;</td>\n"; // Separator
            $myheader2 .= "\t<th class=\"header_no_answer\">".$clang->gT('No answer')."</th>\n";
            $odd_even = alternation($odd_even);
            $mycolumns .= "\n\t<col class=\"seperator\" />\n\n";
            $mycolumns .= "\t<col class=\"col-no-answer $odd_even\" width=\"$cellwidth%\" />\n";
        }

        $mycolumns .= "\t</colgroup>\n";
        $myheader2 .= "</tr>\n";



        // build first row of header if needed
        if ($leftheader != '' || $rightheader !='')
        {
            $myheader1 = "<tr class=\"array1 groups header_row\">\n"
            . "\t<th class=\"header_answer_text\">&nbsp;</th>\n"
            . "\t<th colspan=\"".count($labelans)."\" class=\"dsheader\">$leftheader</th>\n";

            if (count($labelans1)>0)
            {
                $myheader1 .= "\t<td class=\"header_separator\">&nbsp;</td>\n" // Separator
                ."\t<th colspan=\"".count($labelans1)."\" class=\"dsheader\">$rightheader</th>\n";
            }
			if ($right_exists)
			{
				$myheader1 .= "\t<td class=\"header_answer_text_right\">&nbsp;</td>\n";
			}
            if ($ia[6] != 'Y' && SHOW_NO_ANSWER == 1)
            {
            	$myheader1 .= "\t<td class=\"header_separator\">&nbsp;</td>\n"; // Separator
                $myheader1 .= "\t<th class=\"header_no_answer\">&nbsp;</th>\n";
            }
            $myheader1 .= "</tr>\n";
        }
        else
        {
            $myheader1 = '';
        }

        $answer .= "\n<table class=\"question\" summary=\"".str_replace('"','' ,strip_tags($ia[3]))." - a dual array type question\">\n"
        . $mycolumns
        . "\n\t<thead>\n"
        . $myheader1
        . $myheader2
        . "\n\t</thead>\n";

        $trbc = '';
        while ($ansrow = $ansresult->FetchRow())
        {
            // Build repeat headings if needed
            if (isset($repeatheadings) && $repeatheadings > 0 && ($fn-1) > 0 && ($fn-1) % $repeatheadings == 0)
            {
                if ( ($anscount - $fn + 1) >= $minrepeatheadings )
                {
                    $answer .= "<tbody>\n<tr  class=\"repeat\">\n"
                    . "\t<th class=\"header_answer_text\">&nbsp;</th>\n";
                    foreach ($labelans as $ld)
                    {
                        $answer .= "\t<th>".$ld."</th>\n";
                    }
                    if (count($labelans1)>0) // if second label set is used
                    {
                        $answer .= "<th class=\"header_separator\">&nbsp;</th>\n"; // Separator
                        foreach ($labelans1 as $ld)
                        {
                            $answer .= "\t<th>".$ld."</th>\n";
                        }
                    }
					if ($right_exists)
					{
						$answer .= "\t<td class=\"header_answer_text_right\">&nbsp;</td>\n";
					}
                    if ($ia[6] != 'Y' && SHOW_NO_ANSWER == 1) //Question is not mandatory and we can show "no answer"
                    {
                        $answer .= "\t<td class=\"header_separator\">&nbsp;</td>\n"; // Separator
                        $answer .= "\t<th class=\"header_no_answer\">".$clang->gT('No answer')."</th>\n";
                    }
                    $answer .= "</tr>\n</tbody>\n";
                }
            }

            $trbc = alternation($trbc , 'row');
            $answertext=dTexts::run($ansrow['question']);
            $answertextsave=$answertext;

            $dualgroup=0;
            $myfname0= $ia[1].$ansrow['title'];
            $myfname = $ia[1].$ansrow['title'].'#0';
            $myfname1 = $ia[1].$ansrow['title'].'#1'; // new multi-scale-answer
            /* Check if this item has not been answered: the 'notanswered' variable must be an array,
            containing a list of unanswered questions, the current question must be in the array,
            and there must be no answer available for the item in this session. */
            if ((is_array($notanswered)) && (array_search($ia[1], $notanswered) !== FALSE) && (($_SESSION[$myfname] == '') || ($_SESSION[$myfname1] == '')) )
            {
                $answertext = "<span class='errormandatory'>{$answertext}</span>";
            }

            // Get array_filter stuff
            list($htmltbody2, $hiddenfield)=return_array_filter_strings($ia, $qidattributes, $thissurvey, $ansrow, $myfname0, $trbc, $myfname);

            $answer .= $htmltbody2;

            if (strpos($answertext,'|')) {$answertext=substr($answertext,0, strpos($answertext,'|'));}

            array_push($inputnames,$myfname);
            $answer .= "<tr class=\"$trbc\">\n"
            . "\t<th class=\"answertext\">\n"
            . $hiddenfield
            . "$answertext\n"
            . "<input type=\"hidden\" name=\"java$myfname\" id=\"java$myfname\" value=\"";
            if (isset($_SESSION[$myfname])) {$answer .= $_SESSION[$myfname];}
            $answer .= "\" />\n\t</th>\n";
            $hiddenanswers='';
            $thiskey=0;

            foreach ($labelcode as $ld)
            {
                $answer .= "\t<td class=\"answer_cell_1_00$ld\">\n"
                . "<label for=\"answer$myfname-$ld\">\n"
                . "\t<input class=\"radio\" type=\"radio\" name=\"$myfname\" value=\"$ld\" id=\"answer$myfname-$ld\" title=\""
                . html_escape(strip_tags($labelans[$thiskey])).'"';
                if (isset($_SESSION[$myfname]) && $_SESSION[$myfname] == $ld)
                {
                    $answer .= CHECKED;
                }
                // --> START NEW FEATURE - SAVE
                $answer .= " onclick=\"$checkconditionFunction(this.value, this.name, this.type)\" />\n</label>\n";
                // --> END NEW FEATURE - SAVE
                $answer .= "\n\t</td>\n";
                $thiskey++;
            }
            if (count($labelans1)>0) // if second label set is used
            {
                $dualgroup++;
                $hiddenanswers='';
                $answer .= "\t<td class=\"dual_scale_separator\">&nbsp;</td>\n";		// separator
                array_push($inputnames,$myfname1);
                $hiddenanswers .= "<input type=\"hidden\" name=\"java$myfname1\" id=\"java$myfname1\" value=\"";
                if (isset($_SESSION[$myfname1])) {$hiddenanswers .= $_SESSION[$myfname1];}
                $hiddenanswers .= "\" />\n";
                $thiskey=0;
                foreach ($labelcode1 as $ld) // second label set
                {
                    $answer .= "\t<td class=\"answer_cell_2_00$ld\">\n";
                    if ($hiddenanswers!='')
                    {
                        $answer .=$hiddenanswers;
                        $hiddenanswers='';
                    }
                    $answer .= "<label for=\"answer$myfname1-$ld\">\n"
                    . "\t<input class=\"radio\" type=\"radio\" name=\"$myfname1\" value=\"$ld\" id=\"answer$myfname1-$ld\" title=\""
                    . html_escape(strip_tags($labelans1[$thiskey])).'"';
                    if (isset($_SESSION[$myfname1]) && $_SESSION[$myfname1] == $ld)
                    {
                        $answer .= CHECKED;
                    }
                    // --> START NEW FEATURE - SAVE
                    $answer .= " onclick=\"secondlabel_checkconditions(this.value, this.name, this.type)\" />\n</label>\n";
                    // --> END NEW FEATURE - SAVE

                    $answer .= "\t</td>\n";
                    $thiskey++;
                }
            }
            if (strpos($answertextsave,'|'))
            {
                $answertext=substr($answertextsave,strpos($answertextsave,'|')+1);
                $answer .= "\t<td class=\"answertextright\">$answertext</td>\n";
                $hiddenanswers = '';
            }
            elseif ($right_exists)
            {
                $answer .= "\t<td class=\"answertextright\">&nbsp;</td>\n";
            }

            if ($ia[6] != "Y" && SHOW_NO_ANSWER == 1)
            {
                $answer .= "\t<td class=\"dual_scale_separator\">&nbsp;</td>\n"; // separator
				$answer .= "\t<td class=\"dual_scale_no_answer\">\n"
                . "<label for='answer$myfname-'>\n"
                . "\t<input class='radio' type='radio' name='$myfname' value='' id='answer$myfname-' title='".$clang->gT("No answer")."'";
                if (!isset($_SESSION[$myfname]) || $_SESSION[$myfname] == "")
                {
                    $answer .= CHECKED;
                }
                // --> START NEW FEATURE - SAVE
                $answer .= " onclick=\"noanswer_checkconditions(this.value, this.name, this.type)\" />\n"
                . "</label>\n"
                . "\t</td>\n";
                // --> END NEW FEATURE - SAVE
            }

            $answer .= "</tr>\n";
        	$answer .= "\t</tbody>\n";
            // $inputnames[]=$myfname;
            //IF a MULTIPLE of flexi-redisplay figure, repeat the headings
            $fn++;
        }
        $answer .= "</table>\n";
    }
    elseif ($useDropdownLayout === true && $lresult->RecordCount() > 0)
    {

        if (trim($qidattributes['answer_width'])!='')
        {
            $answerwidth=$qidattributes['answer_width'];
        } else {
            $answerwidth=20;
        }
        $separatorwidth=(100-$answerwidth)/10;
        $columnswidth=100-$answerwidth-($separatorwidth*2);

        $answer = "";

        // Get Answers

        //question atribute random_order set?
        if ($qidattributes['random_order']==1) {
            $ansquery = "SELECT * FROM {$dbprefix}questions WHERE parent_qid=$ia[0] and scale_id=0 AND language='".$_SESSION['s_lang']."' ORDER BY ".db_random();
        }

        //no question attributes -> order by sortorder
        else
        {
            $ansquery = "SELECT * FROM {$dbprefix}questions WHERE parent_qid=$ia[0] and scale_id=0 AND language='".$_SESSION['s_lang']."' ORDER BY question_order";
        }
        $ansresult = db_execute_assoc($ansquery);    //Checked
        $anscount = $ansresult->RecordCount();

        if ($anscount==0)
        {
            $inputnames = array();
            $answer .="\n<p class=\"error\">".$clang->gT('Error: This question has no answers.')."</p>\n";
        }
        else
        {

            //already done $lresult = db_execute_assoc($lquery);
            while ($lrow=$lresult->FetchRow())
            {
                $labels0[]=Array('code' => $lrow['code'],
						'title' => $lrow['answer']);
            }
            $lresult1 = db_execute_assoc($lquery1);   //Checked
            while ($lrow1=$lresult1->FetchRow())
            {
                $labels1[]=Array('code' => $lrow1['code'],
						'title' => $lrow1['answer']);
            }


            // Get attributes for Headers and Prefix/Suffix

            if (trim($qidattributes['dropdown_prepostfix'])!='') {
                list ($ddprefix, $ddsuffix) =explode("|",$qidattributes['dropdown_prepostfix']);
                $ddprefix = $ddprefix;
                $ddsuffix = $ddsuffix;
            }
            else
            {
                $ddprefix ='';
                $ddsuffix='';
            }
            if (trim($qidattributes['dropdown_separators'])!='') {
                list ($postanswSep, $interddSep) =explode('|',$qidattributes['dropdown_separators']);
                $postanswSep = $postanswSep;
                $interddSep = $interddSep;
            }
            else {
                $postanswSep = '';
                $interddSep = '';
            }

            $colspan_1 = '';
            $colspan_2 = '';
            $suffix_cell = '';
            $answer .= "\n<table class=\"question\" summary=\"".str_replace('"','' ,strip_tags($ia[3]))." - an dual array type question\">\n\n"
            . "\t<col class=\"answertext\" width=\"$answerwidth%\" />\n";
            if($ddprefix != '')
            {
                $answer .= "\t<col class=\"ddprefix\" />\n";
                $colspan_1 = ' colspan="2"';
            }
            $answer .= "\t<col class=\"dsheader\" />\n";
            if($ddsuffix != '')
            {
                $answer .= "\t<col class=\"ddsuffix\" />\n";
                if(!empty($colspan_1))
                {
                    $colspan_2 = ' colspan="3"';
                }
                $suffix_cell = "\t<td>&nbsp;</td>\n"; // suffix
            }
            $answer .= "\t<col class=\"ddarrayseparator\" width=\"$separatorwidth%\" />\n";
            if($ddprefix != '')
            {
                $answer .= "\t<col class=\"ddprefix\" />\n";
            }
            $answer .= "\t<col class=\"dsheader\" />\n";
            if($ddsuffix != '')
            {
                $answer .= "\t<col class=\"ddsuffix\" />\n";
            };
            // headers
            $answer .= "\n\t<thead>\n"
            . "<tr>\n"
            . "\t<td$colspan_1>&nbsp;</td>\n" // prefix
            . "\n"
            //			. "\t<td align='center' width='$columnswidth%'><span class='dsheader'>$leftheader</span></td>\n"
            . "\t<th>$leftheader</th>\n"
            . "\n"
            . "\t<td$colspan_2>&nbsp;</td>\n" // suffix // Inter DD separator // prefix
            //			. "\t<td align='center' width='$columnswidth%'><span class='dsheader'>$rightheader</span></td>\n"
            . "\t<th>$rightheader</th>\n"
            . $suffix_cell."</tr>\n"
            . "\t</thead>\n\n";

            $trbc = '';
            while ($ansrow = $ansresult->FetchRow())
            {
                $rowname = $ia[1].$ansrow['title'];
                $dualgroup=0;
                $myfname = $ia[1].$ansrow['title']."#".$dualgroup;
                $dualgroup1=1;
                $myfname1 = $ia[1].$ansrow['title']."#".$dualgroup1;

                if ((is_array($notanswered)) && (array_search($ia[1], $notanswered) !== FALSE) && ($_SESSION[$myfname] == "" || $_SESSION[$myfname1] == "") )
                {
                    $answertext="<span class='errormandatory'>".dTexts::run($ansrow['question'])."</span>";
                }
                else
                {
                    $answertext=dTexts::run($ansrow['question']);
                }

                $trbc = alternation($trbc , 'row');

                // Get array_filter stuff
                list($htmltbody2, $hiddenfield)=return_array_filter_strings($ia, $qidattributes, $thissurvey, $ansrow, $rowname, $trbc, $myfname);

                $answer .= $htmltbody2;

                $answer .= "<tr class=\"$trbc\">\n"
                . "\t<th class=\"answertext\">\n"
                . "<label for=\"answer$rowname\">\n"
                . $hiddenfield
                . "$answertext\n"
                . "</label>\n"
                . "\t</th>\n";

                // Label0

                // prefix
                if($ddprefix != '')
                {
                    $answer .= "\t<td class=\"ddprefix\">$ddprefix</td>\n";
                }
                $answer .= "\t<td >\n"
                . "<select name=\"$myfname\" id=\"answer$myfname\" onchange=\"array_dual_dd_checkconditions(this.value, this.name, this.type,$dualgroup,$checkconditionFunction);\">\n";

                if (!isset($_SESSION[$myfname]) || $_SESSION[$myfname] =='')
                {
                    $answer .= "\t<option value=\"\" ".SELECTED.'>'.$clang->gT('Please choose...')."</option>\n";
                }

                foreach ($labels0 as $lrow)
                {
                    $answer .= "\t<option value=\"".$lrow['code'].'" ';
                    if (isset($_SESSION[$myfname]) && $_SESSION[$myfname] == $lrow['code'])
                    {
                        $answer .= SELECTED;
                    }
                    $answer .= '>'.$lrow['title']."</option>\n";
                }
                // If not mandatory and showanswer, show no ans
                if ($ia[6] != 'Y' && SHOW_NO_ANSWER == 1)
                {
                    $answer .= "\t<option value=\"\" ";
                    if (!isset($_SESSION[$myfname]) || $_SESSION[$myfname] == '')
                    {
                        $answer .= SELECTED;
                    }
                    $answer .= '>'.$clang->gT('No answer')."</option>\n";
                }
                $answer .= "</select>\n";

                // suffix
                if($ddsuffix != '')
                {
                    $answer .= "\t<td class=\"ddsuffix\">$ddsuffix</td>\n";
                }
                $answer .= "<input type=\"hidden\" name=\"java$myfname\" id=\"java$myfname\" value=\"";
                if (isset($_SESSION[$myfname]))
                {
                    $answer .= $_SESSION[$myfname];
                }
                $answer .= "\" />\n"
                . "\t</td>\n";

                $inputnames[]=$myfname;

                $answer .= "\t<td class=\"ddarrayseparator\">$interddSep</td>\n"; //Separator

                // Label1

                // prefix
                if($ddprefix != '')
                {
                    $answer .= "\t<td class='ddprefix'>$ddprefix</td>\n";
                }
                //				$answer .= "\t<td align='left' width='$columnswidth%'>\n"
                $answer .= "\t<td>\n"
                . "<select name=\"$myfname1\" id=\"answer$myfname1\" onchange=\"array_dual_dd_checkconditions(this.value, this.name, this.type,$dualgroup1,$checkconditionFunction);\">\n";

                if (!isset($_SESSION[$myfname1]) || $_SESSION[$myfname1] =='')
                {
                    $answer .= "\t<option value=\"\"".SELECTED.'>'.$clang->gT('Please choose...')."</option>\n";
                }

                foreach ($labels1 as $lrow1)
                {
                    $answer .= "\t<option value=\"".$lrow1['code'].'" ';
                    if (isset($_SESSION[$myfname1]) && $_SESSION[$myfname1] == $lrow1['code'])
                    {
                        $answer .= SELECTED;
                    }
                    $answer .= '>'.$lrow1['title']."</option>\n";
                }
                // If not mandatory and showanswer, show no ans
                if ($ia[6] != 'Y' && SHOW_NO_ANSWER == 1)
                {
                    $answer .= "\t<option value='' ";
                    if (!isset($_SESSION[$myfname1]) || $_SESSION[$myfname1] == '')
                    {
                        $answer .= SELECTED;
                    }
                    $answer .= ">".$clang->gT('No answer')."</option>\n";
                }
                $answer .= "</select>\n";

                // suffix
                if($ddsuffix != '')
                {
                    $answer .= "\t<td class=\"ddsuffix\">$ddsuffix</td>\n";
                }
                $answer .= "<input type=\"hidden\" name=\"java$myfname1\" id=\"java$myfname1\" value=\"";
                if (isset($_SESSION[$myfname1]))
                {
                    $answer .= $_SESSION[$myfname1];
                }
                $answer .= "\" />\n"
                . "\t</td>\n";
                $inputnames[]=$myfname1;

                $answer .= "</tr>\n";
				$answer .= "\t</tbody>\n";
            }
        } // End there are answers
        $answer .= "</table>\n";
    }
    else
    {
        $answer = "<p class='error'>".$clang->gT("Error: There are no answer options for this question and/or they don't exist in this language.")."</p>\n";
        $inputnames="";
    }
    return array($answer, $inputnames);
}
コード例 #3
0
ファイル: survey.php プロジェクト: nmklong/limesurvey-cdio3
        if (isset($clienttoken) && $clienttoken)
        {
            submittokens();
        }

        //Send notification to survey administrator
        SendSubmitNotifications();

        $_SESSION['finished']=true;
        $_SESSION['sid']=$surveyid;

        sendcacheheaders();
        if (isset($thissurvey['autoredirect']) && $thissurvey['autoredirect'] == "Y" && $thissurvey['surveyls_url'])
        {

            $url = dTexts::run($thissurvey['surveyls_url']);
            $url = passthruReplace($url, $thissurvey);
            $url=str_replace("{SAVEDID}",$saved_id, $url);			           // to activate the SAVEDID in the END URL
            $url=str_replace("{TOKEN}",$clienttoken, $url);          // to activate the TOKEN in the END URL
            $url=str_replace("{SID}", $surveyid, $url);              // to activate the SID in the END URL
            $url=str_replace("{LANG}", $clang->getlangcode(), $url); // to activate the LANG in the END URL
            //Automatically redirect the page to the "url" setting for the survey
            session_write_close();

            header("Location: {$url}");
        }

        //if($thissurvey['printanswers'] != 'Y' && $thissurvey['usecookie'] != 'Y' && $tokensexist !=1)
        if($thissurvey['printanswers'] != 'Y')
        {
            killSession();
コード例 #4
0
/**
* Send a submit notification to the email address specified in the notifications tab in the survey settings
*/
function SendSubmitNotifications()
{
    global $thissurvey, $debug;
    global $dbprefix, $clang, $emailcharset;
    global $sitename, $homeurl, $surveyid, $publicurl, $maildebug, $tokensexist;
    $bIsHTML = $thissurvey['htmlemail'] == 'Y';
    $aReplacementVars = array();
    if ($thissurvey['allowsave'] == "Y" && isset($_SESSION['scid'])) {
        $aReplacementVars['RELOADURL'] = "{$publicurl}/index.php?sid={$surveyid}&loadall=reload&scid=" . $_SESSION['scid'] . "&loadname=" . urlencode($_SESSION['holdname']) . "&loadpass="******"<a href='{$aReplacementVars['RELOADURL']}'>{$aReplacementVars['RELOADURL']}</a>";
        }
    } else {
        $aReplacementVars['RELOADURL'] = '';
    }
    $aReplacementVars['ADMINNAME'] = $thissurvey['adminname'];
    $aReplacementVars['ADMINEMAIL'] = $thissurvey['adminemail'];
    $aReplacementVars['VIEWRESPONSEURL'] = "{$homeurl}/admin.php?action=browse&sid={$surveyid}&subaction=id&id={$_SESSION['srid']}";
    $aReplacementVars['EDITRESPONSEURL'] = "{$homeurl}/admin.php?action=dataentry&sid={$surveyid}&subaction=edit&surveytable=survey_{$surveyid}&id=" . $_SESSION['srid'];
    $aReplacementVars['STATISTICSURL'] = "{$homeurl}/admin.php?action=statistics&sid={$surveyid}";
    if ($bIsHTML) {
        $aReplacementVars['VIEWRESPONSEURL'] = "<a href='{$aReplacementVars['VIEWRESPONSEURL']}'>{$aReplacementVars['VIEWRESPONSEURL']}</a>";
        $aReplacementVars['EDITRESPONSEURL'] = "<a href='{$aReplacementVars['EDITRESPONSEURL']}'>{$aReplacementVars['EDITRESPONSEURL']}</a>";
        $aReplacementVars['STATISTICSURL'] = "<a href='{$aReplacementVars['STATISTICSURL']}'>{$aReplacementVars['STATISTICSURL']}</a>";
    }
    $aReplacementVars['ANSWERTABLE'] = '';
    $aEmailResponseTo = array();
    $aEmailNotificationTo = array();
    $sResponseData = "";
    if (!empty($thissurvey['emailnotificationto'])) {
        $aRecipient = explode(";", $thissurvey['emailnotificationto']);
        foreach ($aRecipient as $sRecipient) {
            $sRecipient = dTexts::run($sRecipient);
            if (validate_email($sRecipient)) {
                $aEmailNotificationTo[] = $sRecipient;
            }
        }
    }
    if (!empty($thissurvey['emailresponseto'])) {
        if (isset($_SESSION['token']) && $_SESSION['token'] != '' && db_tables_exist($dbprefix . 'tokens_' . $surveyid)) {
            //Gather token data for tokenised surveys
            $_SESSION['thistoken'] = getTokenData($surveyid, $_SESSION['token']);
        } elseif ($_SESSION['insertarray'][0] == 'token') {
            unset($_SESSION['insertarray'][0]);
        }
        //Make an array of email addresses to send to
        $aRecipient = explode(";", $thissurvey['emailresponseto']);
        foreach ($aRecipient as $sRecipient) {
            $sRecipient = dTexts::run($sRecipient);
            if (validate_email($sRecipient)) {
                $aEmailResponseTo[] = $sRecipient;
            }
        }
        $aFullResponseTable = aGetFullResponseTable($surveyid, $_SESSION['srid'], $_SESSION['s_lang']);
        $ResultTableHTML = "<table class='printouttable' >\n";
        $ResultTableText = "\n\n";
        $oldgid = 0;
        $oldqid = 0;
        foreach ($aFullResponseTable as $sFieldname => $fname) {
            if (substr($sFieldname, 0, 4) == 'gid_') {
                $ResultTableHTML .= "\t<tr class='printanswersgroup'><td colspan='2'>{$fname[0]}</td></tr>\n";
                $ResultTableText .= "\n{$fname[0]}\n\n";
            } elseif (substr($sFieldname, 0, 4) == 'qid_') {
                $ResultTableHTML .= "\t<tr class='printanswersquestionhead'><td  colspan='2'>{$fname[0]}</td></tr>\n";
                $ResultTableText .= "\n{$fname[0]}\n";
            } else {
                $ResultTableHTML .= "\t<tr class='printanswersquestion'><td>{$fname[0]} {$fname[1]}</td><td class='printanswersanswertext'>{$fname[2]}</td></tr>";
                $ResultTableText .= "     {$fname[0]} {$fname[1]}: {$fname[2]}\n";
            }
        }
        $ResultTableHTML .= "</table>\n";
        $ResultTableText .= "\n\n";
        if ($bIsHTML) {
            $aReplacementVars['ANSWERTABLE'] = $ResultTableHTML;
        } else {
            $aReplacementVars['ANSWERTABLE'] = $ResultTableText;
        }
    }
    $sFrom = $thissurvey['adminname'] . ' <' . $thissurvey['adminemail'] . '>';
    if (count($aEmailNotificationTo) > 0) {
        $sMessage = templatereplace($thissurvey['email_admin_notification'], $aReplacementVars, $thissurvey['anonymized'] == "Y");
        $sSubject = templatereplace($thissurvey['email_admin_notification_subj'], $aReplacementVars, $thissurvey['anonymized'] == "Y");
        $oMail = new PHPMailer();
        foreach ($aEmailNotificationTo as $sRecipient) {
            if (!SendEmailMessage($oMail, $sMessage, $sSubject, $sRecipient, $sFrom, $sitename, $bIsHTML, getBounceEmail($surveyid))) {
                if ($debug > 0) {
                    echo '<br />Email could not be sent. Reason: ' . $maildebug . '<br/>';
                }
            }
        }
        $oMail->SmtpClose();
    }
    if (count($aEmailResponseTo) > 0) {
        $sMessage = templatereplace($thissurvey['email_admin_responses'], $aReplacementVars);
        $sSubject = templatereplace($thissurvey['email_admin_responses_subj'], $aReplacementVars);
        $mail = new PHPMailer();
        foreach ($aEmailResponseTo as $sRecipient) {
            if (!SendEmailMessage($mail, $sMessage, $sSubject, $sRecipient, $sFrom, $sitename, $bIsHTML, getBounceEmail($surveyid))) {
                if ($debug > 0) {
                    echo '<br />Email could not be sent. Reason: ' . $maildebug . '<br/>';
                }
            }
        }
        $mail->SmtpClose();
    }
}