gforge-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Gforge-commits] gforge/www/survey/include SurveyHTML.class, NONE, 1.1


From: hunkim
Subject: [Gforge-commits] gforge/www/survey/include SurveyHTML.class, NONE, 1.1
Date: Thu, 19 Feb 2004 19:23:56 -0600

Update of /cvsroot/gforge/gforge/www/survey/include
In directory db.perdue.net:/tmp/cvs-serv31475/www/survey/include

Added Files:
        SurveyHTML.class 
Log Message:
 * Rewrite the Survey module
 * Added a general graph module for Survey results



--- NEW FILE: SurveyHTML.class ---
<?php
/**
 * GForge Survey HTML Facility
 *
 * Copyright 2004 GForge, LLC
 * http://gforge.org/
 *
 */

/*
        Survey related HTML
        By Sung Kim, GForge, 02/2004
*/

require_once('pre.php');
require_once('note.php');

/**
 * Survey HTML related functions
 */
class SurveyHTML extends Error {

        /**
         * Dummy constructor 
         */
        function SurveyHTML() {
                return true;
        }

        /**
         * Show survey header 
         */
        function header($params) {
                global 
$group_id,$is_admin_page,$DOCUMENT_ROOT,$Language,$sys_use_survey;

                if (!$sys_use_survey) {
                        exit_disabled();
                }
                
                $params['toptab']='surveys';
                $params['group']=$group_id;
                
                if ($project =& group_get_object($group_id)){
                        if (!$project->usesSurvey()) {
                        exit_error($Language->getText('general','error'), 
$Language->getText('survey_utils','error_this_group_has_turned_off'));
                        }
                        
                        site_project_header($params);
                        
                        echo "<p><strong><a 
href=\"/survey/admin/?group_id=$group_id\">".$Language->getText('survey_utils','admin')."</a>";
                        
                        if ($is_admin_page && $group_id) {
                                echo " | <a 
href=\"/survey/admin/survey.php?group_id=$group_id\">".$Language->getText('survey_utils','add_edit_survey')."</a>";
                                echo " | <a 
href=\"/survey/admin/question.php?group_id=$group_id\">".$Language->getText('survey_utils','add_edit_question')."</a>";
                                echo " | <a 
href=\"/survey/admin/show_results.php?group_id=$group_id\">".$Language->getText('survey_utils','show_results')."</a></strong>";
                        }
                        
                        echo "</p>";
                }// end if (valid group id)
        }
        
        /**
         * Show Survey footer
         */
        function footer($params) {
                site_project_footer($params);
        }

        /**
         * Show Add/Modify Question Forums
         * @param Survey Question Question Object
         * Return string 
         */
        function showAddQuestionForm( &$q ) {
                global $Language;
                global $group_id;

                /* Default is add */
                $title = $Language->getText('survey_add_question','title');
                $question_button = 
$Language->getText('survey_add_question','add_this_question');
                
                /* If we have a question object, it is a Modify */
                if ($q && is_object($q) && !$q->isError() && $q->getID()) {
                        $title = 
$Language->getText('survey_edit_question','title');
                        $warning = '<h3><span style="color:red">'. 
                                
$Language->getText('survey_edit_question','warning_change_after_response').
                                '</span></h3>';
                        $question_id = $q->getID();
                        $question = $q->getQuestion();
                        $question_type = $q->getQuestionType();
                        $question_button = $Language->getText('survey_edit', 
'submit_changes');
                }

                $ret = '<h2>'. $title. '</h2>';
                $ret.= $warning;
                $ret.='<form action="'.$PHP_SELF.'" method="post">';
                $ret.='<input type="hidden" name="post" value="Y" />';
                $ret.='<input type="hidden" name="group_id" 
value="'.$group_id.'" />';
                $ret.='<input type="hidden" name="question_id" 
value="'.$question_id.'" />';
                
                
$ret.=$Language->getText('survey_add_question','question').':<br />';
                $ret.='<input type="text" name="question" value="'.$question.'" 
size="60" maxlength="150" />';
                $ret.='<p>'. 
$Language->getText('survey_edit_question','question_type').':<br />';
        
                $sql="SELECT * from survey_question_types";
                $result=db_query($sql);
                $ret.= 
html_build_select_box($result,'question_type',$question_type,false);

                $ret.='</p><p><input type="submit" name="submit" 
value="'.$question_button.'"></p>';
                $ret.='</form>';
                
                return $ret;
        }
        
        /**
         * Show Add/Modify Question Forums
         * @param Survey Question Question Object
         * Return string 
         */
        function showAddSurveyForm( &$s) {
                global $Language;
                global $group_id;
                global $survey_id;

                /* Default is add */
                $title = $Language->getText('survey_add_survey','title');
                $survey_button = 
$Language->getText('survey_add_survey','add_this_survey');
                $active = ' checked="checked" ';
                $inactive = '';

                /* If we have a survey object, it is a Modify */
                if ($s && is_object($s) && !$s->isError() && $s->getID()) {
                        $title = $Language->getText('survey_edit','title');
                        $warning = '<h3><span style="color:red">'. 
                                
$Language->getText('survey_edit','warning_survey_after_response').'</span></h3>';
                        $survey_id = $s->getID();
                        $survey_title = $s->getTitle();
                        $survey_questions = $s->getQuestionString();
                        $survey_button = $Language->getText('survey_edit', 
'submit_changes');
                        if (!$s->isActive()) {
                                $inactive = 'checked ="checked" ';
                                $active ='';
                        }
                }

                $ret = '<h2>'. $title. '</h2>';
                $ret.= $warning;
                $ret.='<form action="'.$PHP_SELF.'" method="post">';
                $ret.='<input type="hidden" name="post" value="Y" />';
                $ret.='<input type="hidden" name="group_id" 
value="'.$group_id.'" />';
                $ret.='<input type="hidden" name="survey_id" 
value="'.$survey_id.'" />';
                $ret.='<input type="hidden" name="survey_questions" 
value="'.$survey_questions.'" />';
                
                $ret.='<strong>'. 
$Language->getText('survey_add_survey','name_of_survey').'</strong>' 
.utils_requiredField();
                $ret.= '<input type="text" name="survey_title" 
value="'.$survey_title.'" length="60" maxlength="150" /><p>';
                
                $ret.='<p><strong>'. 
$Language->getText('survey_add_survey','is_active').'</strong>';
                $ret.='<br /><input type="radio" name="is_active" value="1"' 
.$active. '/>'.$Language->getText('survey_add_survey','yes');
                $ret.='<br /><input type="radio" name="is_active" value="0"' 
.$inactive. '/>'.$Language->getText('survey_add_survey','no');

                $arr_to_add = & $s->getAddableQuestionInstances();
                $arr_to_del = & $s->getQuestionInstances();
                
                if (count($arr_to_add)>0) {
                        $ret.='<p><strong>'. 
$Language->getText('survey_edit','addable_question').'</strong>';
                        $title_arr[] = "&nbsp;";
                        $title_arr[] = $Language->getText('survey_index', 
'survey_questions');
                        $title_arr[] = "&nbsp;";
                        $ret.=$GLOBALS['HTML']->listTableTop ($title_arr);
                }

                for($i = 0;  $i  <  count($arr_to_add);  $i++)  {
                        
                        if ($arr_to_add[$i]->isError()) {
                                echo $arr_to_add[$i]->getErrorMessage();
                                continue;
                        }

                        if ($i%3==0) {
                                $ret.= "<tr ". 
$GLOBALS['HTML']->boxGetAltRowStyle($j++) .">\n";
                        }
                        
                        $ret.= '<td><input type="checkbox" name="to_add[]" 
value="'.$arr_to_add[$i]->getID().'">'.
                                $arr_to_add[$i]->getQuestion().'('.
                                
$arr_to_add[$i]->getQuestionStringType().')</td>';
                        
                        if ($i%3==2) {
                                $ret.= "</tr>";
                        }
                }

                if (count($arr_to_add)>0) {
                        /* Fill the remain cells */
                        if ($i%3==1) {
                                $ret.='<td>&nbsp;</td><td>&nbsp;</td></tr>';
                        } else if ($i%3==2) {
                                $ret.='<td>&nbsp;</td></tr>';
                        }
                
                        $ret.= $GLOBALS['HTML']->listTableBottom();
                }
        
                /* Deletable questions */
                if (count($arr_to_del) > 0) {
                        $ret.='<p><strong>'. 
$Language->getText('survey_edit','existing_question').'</strong>';
                        $title_arr = array('Question ID', 'Question', 'Type', 
'Order', 'Delete from this Survey');
                        $ret.=$GLOBALS['HTML']->listTableTop ($title_arr);
                }
                        
                for($i = 0;  $i  <  count($arr_to_del);  $i++)  {
                        if ($arr_to_del[$i]->isError()) {
                                echo $arr_to_del[$i]->getErrorMessage();
                                continue;
                        }
                        
                        
                        $ret.= "<tr ". $GLOBALS['HTML']->boxGetAltRowStyle($i) 
.">\n";
                        
                        $ret.= '<td>'.$arr_to_del[$i]->getID().'</td>';
                        $ret.= '<td>'.$arr_to_del[$i]->getQuestion().'</td>';
                        $ret.= 
'<td>'.$arr_to_del[$i]->getQuestionStringType().'</td>';
                        $ret.= '<td><center>[<a 
href="survey.php?group_id='.$group_id.'&amp;survey_id='.
                                $survey_id.'&amp;is_up=1&amp;updown=Y'.
                                
'&amp;question_id='.$arr_to_del[$i]->getID().'">Up</a>]';
                        $ret.= '[<a 
href="/survey/admin/survey.php?group_id='.$group_id.'&amp;survey_id='.
                                $survey_id.'&amp;is_up=0&amp;updown=Y'.
                                
'&amp;question_id='.$arr_to_del[$i]->getID().'">Down</a>]</center></td>';
                        
                        $ret.= '<td><center><input type="checkbox" 
name="to_del[]" value="'.$arr_to_del[$i]->getID().'"></center></td>';
                        $ret.= '</tr>';
                        
                }
                
                if (count($arr_to_del)) {
                        $ret.= $GLOBALS['HTML']->listTableBottom();
                }
        
                /* Privous style question input text box. deprecated.           
                $ret.= 
$Language->getText('survey_add_survey','list_questions_numbers');
                $ret.='<br /><input type="text" name="survey_questions" 
value="" length="90" maxlength="1500" /></p>';
                */
                                
                $ret.='<p><input type="submit" name="submit" 
value="'.$survey_button.'"></p>';
                $ret.='</form>';
                
                return $ret;
        }

        /**
         * Show list of questions
         */
        function  ShowQuestions(&$questions) {
                global $Language;
                global $group_id;
                
                $ret = "<h3>" . count($questions).' 
'.$Language->getText('survey_show_questions','found',array($rows))."</h3>";
                                
                /* Head information */
                $title_arr = array ('Question ID', 'Question', 'Type', 
'Edit/Delete');
                $ret.=$GLOBALS['HTML']->listTableTop ($title_arr);
                                
                for($i = 0;  $i  <  count($questions);  $i++)  {
                        if ($questions[$i]->isError()) {
                                echo $questions[$i]->getErrorMessage();
                                continue;
                        }

                        $ret.= "<tr ". $GLOBALS['HTML']->boxGetAltRowStyle($i) 
.">\n";
                        $ret.= "<td><a 
href=\"question.php?group_id=$group_id&amp;question_id=".
                                
$questions[$i]->getID()."\">".$questions[$i]->getID()."</a></td>\n";
                        
                        $ret.= '<td>'.$questions[$i]->getQuestion().'</td>';
                        $ret.= 
'<td>'.$questions[$i]->getQuestionStringType().'</td>';

                        /* Edit/Delete Link */
                        $ret.= "<td>[<a 
href=\"question.php?group_id=$group_id&amp;question_id=".$questions[$i]->getID().'">';
                        $ret.= $Language->getText('survey_admin', 
'edit').'</a>] ';
                        $ret.= "[<a 
href=\"question.php?delete=Y&amp;group_id=$group_id&amp;question_id=".$questions[$i]->getID().'">';
                        $ret.= $Language->getText('survey_admin', 
'delete').'</a>]</td>';

                        $ret.= "</tr>";
                }
                $ret.= $GLOBALS['HTML']->listTableBottom();
                return $ret;
        }
        
        /**
         * Show list of surveys
         *
         * Show surveys with many options
         * have to set $user_id to get the right show_vote option
         *
         *
         */
        function  ShowSurveys(&$surveys, $show_id=0, $show_questions=0, 
                              $show_number_questions=0, $show_number_votes=0, 
                              $show_vote=0, $show_edit=0, $show_result=0, 
                              $show_result_graph=0, $show_result_comment=0, 
                              $show_inactive=0 ) {
                global $Language;
                global $user_id;
                global $group_id;

                $ret = '<h2>'. 
$Language->getText('survey_edit','existing_surveys'). '</h2>';

                /* Head information */
                if ($show_id) {
                        $title_arr[] = $Language->getText('survey_index', 
'survey_id');
                }

                $title_arr[] = $Language->getText('survey_index', 
'survey_title');
                
                if ($show_questions) {
                        $title_arr[] = $Language->getText('survey_index', 
'survey_questions');
                }
                if ($show_number_questions) {
                        $title_arr[] = $Language->getText('survey_index', 
'survey_number_questions');
                }
                if ($show_number_votes) {
                        $title_arr[] = $Language->getText('survey_index', 
'survey_number_votes');
                }               
                if ($show_vote && $user_id) {
                        $title_arr[] = $Language->getText('survey_index', 
'survey_vote');
                }
                if ($show_edit) {
                        $title_arr[] = $Language->getText('survey_index', 
'survey_edit');
                }
                if ($show_result) {
                        $title_arr[] = $Language->getText('survey_index', 
'survey_result');
                }
                if ($show_result_graph) {
                        $title_arr[] = $Language->getText('survey_index', 
'survey_result_graph');
                }
                if ($show_result_comment) {
                        $title_arr[] = $Language->getText('survey_index', 
'survey_result_comments');
                }

                $ret.=$GLOBALS['HTML']->listTableTop ($title_arr);
                        
                /* Color index for table */
                $color_indxe=0;
                for($i = 0;  $i  <  count($surveys);  $i++)  {
                        if ($surveys[$i]->isError()) {
                                echo $surveys[$i]->getErrorMessage();
                                continue;
                        }
                        
                        if (!$surveys[$i]->isActive()) {
                                if ($show_inactive) {
                                        $strike_open="<strike>";
                                        $strike_close="</strike>";
                                } else {
                                        continue;
                                }
                        } else {
                                $strike_open="";
                                $strike_close="";
                                        
                        }

                        $ret.= "<tr ". 
$GLOBALS['HTML']->boxGetAltRowStyle($color_index++) .">\n";
                        if ($show_id) {
                                $ret.= '<td>'.$surveys[$i]->getID().'</td>';
                        }
                        
                        $ret.= '<td>'.$strike_open.'<a 
href="/survey/survey.php?group_id='.$group_id.'&amp;survey_id='.
                                
$surveys[$i]->getID().'">'.$surveys[$i]->getTitle().'</A>'.$strike_close.'</td>';

                        if ($show_questions) {
                                $ret.= 
'<td>'.$surveys[$i]->getQuestionString().'</td>';
                        }
                        if ($show_number_questions) {
                                $ret.= 
'<td>'.$surveys[$i]->getNumberOfQuestions().'</td>';
                        }
                        if ($show_number_votes) {
                                $ret.= 
'<td>'.$surveys[$i]->getNumberOfVotes().'</td>';
                        }               
                        if ($show_vote && $user_id) {
                                if ($surveys[$i]->isUserVote($user_id)) {
                                        $ret.='<td>YES</td>';
                                } else {
                                        $ret.='<td>NO</td>';
                                }
                        }
                        if ($show_edit) {
                                /* Edit/Delete Link */
                                $ret.= "<td>[<a 
href=\"/survey/admin/survey.php?group_id=$group_id&amp;survey_id=".
                                        $surveys[$i]->getID().'">';
                                $ret.= $Language->getText('survey_admin', 
'edit').'</a>] ';

                                /* We don;t support delete yet. Need to delete 
all results as well */
                                /*
                                $ret.= "[<a 
href=\"/survey/admin/survey.php?delete=Y&amp;group_id=$group_id&amp;survey_id=".
                                        $surveys[$i]->getID().'">';
                                $ret.= $Language->getText('survey_admin', 
'delete').'</a>]
                                */
                                $ret.='</td>';
                        }
                        if ($show_result) {
                                /* Edit/Delete Link */
                                $ret.= "<td>[<a 
href=\"/survey/admin/show_results.php?group_id=$group_id&amp;survey_id=".
                                        $surveys[$i]->getID().'">';
                                $ret.= $Language->getText('survey_index', 
'survey_result').'</a>]</td>';
                        }
                        if ($show_result_graph) {
                                /* Edit/Delete Link */
                                $ret.= "<td>[<a 
href=\"/survey/admin/show_results.php?graph=yes&amp;group_id=$group_id&amp;survey_id=".
                                        $surveys[$i]->getID().'">';
                                $ret.= $Language->getText('survey_index', 
'survey_result_graph').'</a>]</td>';
                        }
                        if ($show_result_comment) {
                                /* Edit/Delete Link */
                                $ret.= "<td>[<a 
href=\"/survey/admin/show_results.php?graph=yes&amp;show_comment=yes&amp;group_id=$group_id&amp;survey_id=".$surveys[$i]->getID().'">';
                                $ret.= $Language->getText('survey_index', 
'survey_result_comments').'</a>]</td>';
                        }
                        $ret.= "</tr>\n";
                }
                
                $ret.= $GLOBALS['HTML']->listTableBottom();
                return $ret;
        }
        
        /**
         * Show survey form - Show all forums of Survey
         */
        function ShowSurveyForm( &$s ) {
                global $Language;
                global $group_id;
                global $survey_id;
                
                if (!$s->isActive()) {
                        return '<h3><span style="color:red">'. 
$Language->getText('survey_error','no_vote_for_inactive').'</span></h3>';
                }
                /* Get questions of this survey */
                $questions = & $s->getQuestionInstances();
                
                $ret="";
                if ($s->isUserVote(user_getid())) {
                        $ret.= '<h3><span style="color:red">'. 
$Language->getText('survey','warning_double_vote').'</span></h3>';
                } 
                $ret.= '<form action="/survey/survey_resp.php" method="post">'.
                        '<input type="hidden" name="group_id" 
value="'.$group_id.'" />'.
                        '<input type="hidden" name="survey_id" 
value="'.$survey_id. '" />';

                $ret.= '<h3>'.$s->getTitle().'</h3>';
                $ret.= '<table border="0">';

                /* Keep question numbers */
                $index = 1;
                for($i = 0; $i < count($questions); $i++)  {
                        if ($questions[$i]->isError()) {
                                echo $questions[$i]->getErrorMessage();
                                continue;
                        }
                        $question_type = $questions[$i]->getQuestionType();
                        $question_id = $questions[$i]->getID();
                        $question_title = 
stripslashes($questions[$i]->getQuestion());
                        
                        if ($question_type == '4') {
                                /* Don't show question number if it's just a 
comment */
                                $ret.='<tr><td valign="top">&nbsp;</td><td>';
                        } else {
                                $ret.= '<tr><td valign="top"><strong>';
                                /* If it's a 1-5 question box and first in 
series, move Quest number down a bit */
                                if (($question_type != $last_question_type) && 
(($question_type == '1') || ($question_type == '3'))) {
                                        $ret.= '&nbsp;<br />';
                                }
                                
                                $ret.= $index++.'&nbsp;&nbsp;&nbsp;&nbsp;<br 
/></td><td>';
                        }
                        
                        
                        
                        switch($question_type) {
                        case 1: /* This is a radio-button question. Values 1-5.
                          Show the 1-5 markers only if this is the first in a 
series */
                                if ($question_type != $last_question_type) {
                                        $ret.=' 
<strong>1</strong>'.$Language->getText('survey','low').
                                                '  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
<strong>5</strong>' .
                                                
$Language->getText('survey','high').'<br />';
                                }
                                
                                for ($j=1; $j<=5; $j++) {
                                        $ret.= '<input type="radio" 
name="_'.$question_id.'" value="'.$j.'" />';
                                }
                                
                                $ret.= '&nbsp; '.$question_title;
                                break;
                                
                        case 2: /* This is a text-area question. */
                                $ret.= $question_title.'<br />';
                                $ret.='<textarea name="_'.$question_id.'" 
rows="5" cols="60" wrap="soft"></textarea>';
                                break;
                        case 3: /* This is a Yes/No question. 
                           Show the Yes/No only if this is the first in a 
series */
                                if ($question_type != $last_question_type) {
                                        $ret.= '<strong>Yes / No</strong><br 
/>';
                                }
                                
                                $ret.='<input type="radio" 
name="_'.$question_id.'" value="1" />';
                                $ret.='<input type="radio" 
name="_'.$question_id.'" value="5" />';
                                $ret.='&nbsp; '.$question_title;
                                break;
                        case 4: /* This is a comment only. */
                                $ret.= '&nbsp;<br 
/><strong>'.util_make_links($question_title).'</strong>';
                                $ret.= '<input type="hidden" 
name="_'.$question_id.'" value="-666" />';
                                break;
                        case 5: /* This is a text-field question. */
                                $ret.= $question_title. '<br />';
                                $ret.= '<input type="text" 
name="_'.$question_id.'" size="20" maxlength="70" />';
                                break;
                        default:
                                $ret.= $question_title. '<br />';
                        }
                        
                        $ret.= '</td></tr>';
                        $last_question_type=$question_type;
                }
                
                $ret.='<tr><td align="center" colspan="2">'.
                        '<input type="submit" name="submit" 
value="'.$Language->getText('general','submit').'" />'.
                        '<br /><a 
href="/survey/privacy.php">'.$Language->getText('survey','survey_privacy').'</a>'.
                        '</td></tr></form></table>';
                
                return $ret;
        }

                
        /**
         * Show survey Result
         * 
         *    @param Object a Survey Response Factory
         */
        function ShowResult( &$sr, $show_comment=0, $q_num="", $show_graph=0) {
                global $Language;
                global $group_id;

                $Survey = $sr->getSurvey();
                $Question = $sr->getQuestion();

                $ret='<strong>';
                if ($q_num) {
                        $ret.= $q_num . '. ';
                }
                
                $ret.=$Question->getQuestion().'</strong><br />';
                $results = $sr->getResults();
                if ($sr->isError()){
                        echo ($sr->getErrorMessage());
                }
                
                $totalCount = $sr->getNumberOfSurveyResponsess();
                $votes = $Survey->getNumberOfVotes();
                
                /* No votes, no result to show */
                if ($votes==0) {
                        $ret.= 
'<ul><li/>'.$Language->getText('survey_show_results_aggregate','no_votes').'</ul>';
                        return $ret;
                }

                switch($Question->getQuestionType()) {
                case 1: /* This is a radio-button question. Values 1-5.
                          Show the 1-5 markers only if this is the first in a 
series */
                        $arr_name=array('No Answer', 'Low 1', '2', '3', '4', 
'High 5', 'No Answer');
                        $arr_color=array('black', 'red', 'blue', 'yellow', 
'green', 'brown', 'black');
                        $results[0] =  $votes - $results[1] - $results[2] - 
$results[3] - $results[4] - $results[5];
        
                        if ($show_graph) {
                                $url ='graphs.php?type=vbar';
                                for ($j=5; $j>=0; $j--) {
                                        $percent = sprintf("%02.1f%%", 
(float)$results[$j]*100/$votes);

                                        
$url.='&amp;legend[]='.urlencode($arr_name[$j].' ('. $percent.')');
                                        
$url.='&amp;value[]='.urlencode($results[$j]);
                                }
                                $ret.= '<img border="0"  src="'.$url.'" 
alt="Graph of '.$Question->getQuestion().'"></img>';
                        } else {
                                $ret.= '<dd><table border="0" cellspacing="0" 
cellpadding="0" width=100%>';
                                
                                for ($j=5; $j>=0; $j--) {
                                        $percent = 
(float)$results[$j]*100/$votes;
                                        $ret.= $this->_makeBar($arr_name[$j].' 
('.$results[$j].')', $percent, $arr_color[$j]);
                                }
                                $ret.= '</table></dd>';
                        }
                        $ret.='<p/>';
                        break;

                case 3: /* This is a Yes/No question. */
                        
                        $arr_name=array('', 'YES', 'NO', 'No Answer');
                        $arr_color=array('', 'red', 'blue', 'black');
                        
                        $res[1] = $results[1]; /* Yes */
                        $res[2] =  $results[5]; /* No */
                        $res[3] =  $votes - $res[1] -$res[2];
                
                        if ($show_graph) {
                                $url ='graphs.php?type=pie';
                                for ($j=1; $j<=3; $j++) {
                                        
$url.='&amp;legend[]='.urlencode($arr_name[$j].'('.$res[$j].')');
                                        
$url.='&amp;value[]='.urlencode($res[$j]);
                                }
                                $ret.= '<img border="0"  src="'.$url.'" 
alt="Graph of '.$Question->getQuestion().'"></img>';
                        } else {
                                $ret.= '<dd><table border="0" cellspacing="0" 
cellpadding="0" width=100%>';
                                for ($j=1; $j<=3; $j++) {
                                        $result_per[$j] = 
(float)$res[$j]*100/$votes;
                                        $ret.= $this->_makeBar($arr_name[$j].' 
('.$res[$j].')', $result_per[$j], $arr_color[$j]);
                                }
                                $ret.= '</table></dd>';
                        }
                        $ret.='<p/>';
                        break;
                        
                case 4: /* This is a comment only. */
                        break;

                case 2: /* This is a text-area question. */
                case 5: /* This is a text-field question. */
                        if ($show_comment) {
                                for($j=0; $j<$totalCount; $j++) {
                                        
$ret.='<hr.><strong>'.$Language->getText('survey_show_results_aggregate','comments').
                                                ' # '.($j+1).'/'.$totalCount. 
'</strong><p/>';
                                        $ret.='<pre>'.$results[$j].'</pre>';
                                }
                        } else {
                                $ret.='<ul><li><a 
href="show_results.php?survey_id='.$Survey->getID().
                                        '&amp;question_id='.$Question->getID().
                                        '&amp;group_id='.$group_id.'">'.
                                        
$Language->getText('survey_show_results_aggregate','view_comments', 
$totalCount).
                                        '</a></ul><p/>';
                        }
                
                        break;
                default:
                        break;
                }
        
                return $ret;
        } 

        /**
         * _makeBar - make Precentage bar as a cell in a table. Starts with 
<tr> and ends with </tr>
         *
         * @param String name Name
         * @param int percentage of the name
         * @return string
         */
        function _makeBar($name, $percent, $color) {
                $ret = '<tr><td width="30%">'.$name.'</td><td>';
                $ret.= '<table width="'.$percent.'%" border="0"  
cellspacing="0" cellpadding="0"><tr>';
                if ($percent) {
                        $ret.='<td width="90%" 
bgcolor="'.$color.'">&nbsp;</td>';
                }
                
                $ret.= '<td>'.sprintf("%.2f", 
$percent).'%</td></tr></table></td></tr\>'."\n";
                
                return $ret;
        }
}

// Local Variables:
// mode: php
// c-file-style: "bsd"
// End:
?>





reply via email to

[Prev in Thread] Current Thread [Next in Thread]