gforge-commits
[Top][All Lists]
Advanced

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

[Gforge-commits] gforge/www/survey/admin graphs.php, NONE, 1.1 question.


From: hunkim
Subject: [Gforge-commits] gforge/www/survey/admin graphs.php, NONE, 1.1 question.php, NONE, 1.1 survey.php, NONE, 1.1 index.php, 1.4, 1.5 show_results.php, 1.4, 1.5
Date: Thu, 19 Feb 2004 19:23:56 -0600

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

Modified Files:
        index.php show_results.php 
Added Files:
        graphs.php question.php survey.php 
Log Message:
 * Rewrite the Survey module
 * Added a general graph module for Survey results



--- NEW FILE: graphs.php ---
<?php
/**
  *
  * General Graph showing module for Survey
  *
  * This script produces PNG image which shows graph of SCM metrics
  *
  *
  */

/**
 * Expecting data
 *  @ legend[] - array of legends
 *  @ value[]  - array of values
 *  @ type - grap type. We support pie and vertical bar graph (pie, vbar)
 *  @ width
 *  @ hight 
 */ 

require_once('pre.php');

// Check if we have jpgraph
if (!file_exists($sys_path_to_jpgraph.'/jpgraph.php')) {
    //# TODO: Need to show the message as a image file
    exit_error('Error', 'Package JPGraph not installed');
}

// Read jPGraph libraries. Make sure the $sys_path_to_jpgraph is correct in 
local.inc
require_once($sys_path_to_jpgraph.'/jpgraph.php');
require_once($sys_path_to_jpgraph.'/jpgraph_line.php');
require_once($sys_path_to_jpgraph.'/jpgraph_bar.php');
require_once($sys_path_to_jpgraph.'/jpgraph_pie.php');
require_once($sys_path_to_jpgraph.'/jpgraph_pie3d.php');

if ($type=='pie') {
    ShowPie($legend, $value);
} else {
    ShowHBar($legend, $value); 
}

/**
 * Show 3D Pie graph
 */ 
function ShowPie(&$legend, &$value) {
  
    $graph = new PieGraph(330,200,"auto");
    $graph->SetFrame(false);
    //$graph->title->Set("A simple 3D Pie plot");
    //$graph->title->SetFont(FF_FONT1,FS_BOLD);
    
    $p1 = new PiePlot3D($value);
    $p1->ExplodeSlice(1);
    $p1->SetCenter(0.45);
    $p1->SetLegends($legend);
    $graph->legend->SetPos(0.01,0.01,'right','top');

    $graph->Add($p1);
    $graph->Stroke();
}


/**
 * Show Horizontal Bar graph
 */ 
function ShowHBar(&$legend, &$value) {
    
    $height=50+count($value)*18;
    $width=500;
    
    // Set the basic parameters of the graph
    $graph = new Graph($width,$height,'auto');
    
    $graph->SetScale("textlin");
    $top = 30;
    $bottom = 20;
    $left = 100;
    $right = 50;
    $graph->Set90AndMargin($left,$right,$top,$bottom);
    $graph->xaxis->SetTickLabels($legend);
    $graph->SetFrame(false);

    // Label align for X-axis
    $graph->xaxis->SetLabelAlign('right','center','right');
    
    // Label align for Y-axis
    $graph->yaxis->SetLabelAlign('center','bottom');
    
    // Create a bar pot
    $bplot = new BarPlot($value);
    $bplot->SetFillColor("orange");
    $bplot->SetWidth(0.5);
    // We want to display the value of each bar at the top
    $graph->yaxis->scale->SetGrace(10);
    $graph->yaxis->SetLabelAlign('center','bottom');
    $graph->yaxis->SetLabelFormat('%d');
        
    $bplot->value->Show();
    $bplot->value->SetFormat('%.d votes');
    // Setup color for gradient fill style
    $bplot->SetFillGradient("navy","lightsteelblue",GRAD_MIDVER);
 
    $graph->Add($bplot);
    
    $graph->Stroke();
}
?>

--- NEW FILE: question.php ---
<?php
/**
  *
  * GForge Survey Facility: Question handle program
  *
  * Copyright 2004 (c) GForge
  * http://gforge.org
  *
  *
  */
require_once('pre.php');
require_once('common/survey/SurveyQuestion.class');
require_once('common/survey/SurveyQuestionFactory.class');
require_once('www/survey/include/SurveyHTML.class');

/* We need a group_id */ 
if (!$group_id) {
    exit_no_group();
}

$g =& group_get_object($group_id);
if (!$g || !is_object($g) || $g->isError()) {
    exit_no_group();
}

$is_admin_page='y';
$sh = new  SurveyHtml();
$sh->header(array('title'=>$Language->getText('survey_add_question','title'),'pagename'=>'survey_admin_add_question'));

if (!session_loggedin() || !user_ismember($group_id,'A')) {
    echo "<h1>".$Language->getText('survey_error','permission_denied')."</h1>";
    $sh->footer(array());
    exit;
}

/* Create a Survey Question for general purpose */
$sq = new SurveyQuestion($g, $question_id);
if (!$sq || !is_object($sq)) {
    echo "<h3>".$Language->getText('general','error'). ' Can not get Survey 
Question' ."</H3>";
} else if ( $sq->isError()) {
    echo "<h3>".$Language->getText('general','error'). $sq->getErrorMessage() 
."</H3>";
}

/* Delete a question */
if ($delete=="Y" && $question_id) {
     $sq->delete();

    /* Error */
    if ( $sq->isError()) {
        $msg = $Language->getText('survey_edit','delete_failed').' 
'.$sq->getErrorMessage();
    } else {
        $msg = $Language->getText('survey_edit','delete_successful');
    }
    echo "<H3>".$msg ."</H3>";
} else if ($post=="Y") {
    /* Modification */
    if ($question_id) {
        $sq->update($question, $question_type);
        $msg = $Language->getText('survey_edit_question','update_successful');
    } else { /* adding new question */
        $sq->create($question, $question_type);
        $msg = $Language->getText('survey_add_question', 'question_added'); 
    }
    
    /* Error */
    if ( $sq->isError()) {
        $msg = $sq->getErrorMessage();
    }
    
    echo "<H3>".$msg ."</H3>";

    /* Add now Question */
    $sq = false;
}

/* Show Add/Modify form 
 * If $question is null it is add form, otherwise modify 
 */
echo($sh->showAddQuestionForm($sq));

/* Show existing questions 
 */
$sqf = new SurveyQuestionFactory($g);
$sqs = & $sqf->getSurveyQuestions();
if (!$sqs) {
    echo ($Language->getText('survey_error', 'no_questions_found'));
} else {
    echo($sh->showQuestions($sqs));
}

$sh->footer(array());
?>

--- NEW FILE: survey.php ---
<?php

/**
  *
  * GForge Survey Facility: Question handle program
  *
  * Copyright 2004 (c) GForge
  * http://gforge.org
  *
  *
  */
require_once('pre.php');
require_once('common/survey/Survey.class');
require_once('common/survey/SurveyFactory.class');
require_once('common/survey/SurveyQuestion.class');
require_once('common/survey/SurveyQuestionFactory.class');
require_once('www/survey/include/SurveyHTML.class');

/* We need a group_id */ 
if (!$group_id) {
    exit_no_group();
}

$g =& group_get_object($group_id);
if (!$g || !is_object($g) || $g->isError()) {
    exit_no_group();
}

$is_admin_page='y';
$sh = new  SurveyHtml();
$s = new Survey($g, $survey_id);

$sh->header(array('title'=>$Language->getText('survey_add_survey','title'),'pagename'=>'survey_admin_add_survey'));

if (!session_loggedin() || !user_ismember($group_id,'A')) {
        echo "<h1>". 
$Language->getText('survey_add_question','permission_denied')."</h1>";
        $sh->footer(array());
        exit;
}

if ($post=="Y") {
    if ($survey_id) { /* Modify */
        $s->update($survey_title, $to_add, $to_del, $is_active);
        $feedback = $Language->getText('survey_edit','update_successful');
    }  else {  /* Add */
        $s->create($survey_title, $to_add, $is_active);
        $feedback = $Language->getText('survey_add_survey', 'survey_inserted');
    }
}

/* Order changes */
if ($updown=="Y") {
    $s->updateOrder($question_id, $is_up);
    $feedback = $Language->getText('survey_edit','update_successful');
}

/* Error on previous transactions? */
if ($s->isError()) {
    $feedback = $s->getErrorMessage();
} 

echo ($sh->ShowAddSurveyForm($s));

/* Show list of Servey */
$sf = new SurveyFactory($g);
$ss = & $sf->getSurveys();
if (!$ss) {
    echo ($Language->getText('survey_error', 'no_question_found'));
} else {
    echo($sh->ShowSurveys($ss, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1));
}

$sh->footer(array());
?>

Index: index.php
===================================================================
RCS file: /cvsroot/gforge/gforge/www/survey/admin/index.php,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- index.php   21 Feb 2003 21:38:58 -0000      1.4
+++ index.php   20 Feb 2004 01:23:53 -0000      1.5
@@ -13,38 +13,39 @@
 
 
 require_once('pre.php');
-require_once('www/survey/survey_utils.php');
+require_once('www/survey/include/SurveyHTML.class');
 
 $is_admin_page='y';
-survey_header(array('title'=>$Language->getText('survey_admin_index','title'),'pagename'=>'survey_admin'));
+$sh = new  SurveyHtml();
+$sh->header(array('title'=>$Language->getText('survey_admin_index','title'),'pagename'=>'survey_admin'));
 
 if (!session_loggedin() || !user_ismember($group_id,'A')) {
        echo 
'<h1>'.$Language->getText('survey_admin_index','permission_denied').'</h1>';
-       survey_footer(array());
+       $sh->footer(array());
        exit;
 }
 
 ?>
 
 <p>
-<a href="/survey/admin/add_survey.php?group_id=<?php echo $group_id; ?>"><?php 
echo $Language->getText('survey_admin_index','add_survey'); ?></a><br />
-<a href="/survey/admin/edit_survey.php?group_id=<?php echo $group_id; 
?>"><?php echo $Language->getText('survey_admin_index','edir_existing_survey'); 
?></a><br />
-<a href="/survey/admin/add_question.php?group_id=<?php echo $group_id; 
?>"><?php echo $Language->getText('survey_admin_index','add_question'); 
?></a><br />
-<a href="/survey/admin/show_questions.php?group_id=<?php echo $group_id; 
?>"><?php echo 
$Language->getText('survey_admin_index','edit_existing_question'); ?></a><br />
-<a href="/survey/admin/show_results.php?group_id=<?php echo $group_id; 
?>"><?php echo $Language->getText('survey_admin_index','show_results'); 
?></a><br />
+<UL>
+<LI><a href="/survey/admin/question.php?group_id=<?php echo $group_id; 
?>"><?php echo $Language->getText('survey_admin_index','add_question'); 
?></a><br />
+<LI><a href="/survey/admin/survey.php?group_id=<?php echo $group_id; ?>"><?php 
echo $Language->getText('survey_admin_index','add_survey'); ?></a><br />
+<LI><a href="/survey/admin/show_results.php?group_id=<?php echo $group_id; 
?>"><?php echo $Language->getText('survey_admin_index','show_results'); 
?></a><br />
+</UL>
 </p>
 <?php echo $Language->getText('survey_admin_index','its_simple_to_create', 
array('<p><strong>/survey/survey.php?group_id='.$group_id.'&survey_id=XX</strong>'));
 ?>
 </li>
 </ol>
 </p>
 
-<p><?php echo 
$Language->getText('survey_admin_index','you_can_now_activate',array('<a 
href="/survey/admin/edit_survey.php?group_id='.$group_id.'">','</a>')); ?>
+<p><?php echo 
$Language->getText('survey_admin_index','you_can_now_activate',array('<a 
href="/survey/admin/survey.php?group_id='.$group_id.'">','</a>')); ?>
 
 </p>
 <p>
 <?php
 
-survey_footer(array());
+$sh->footer(array());
 
 ?>
 </p>

Index: show_results.php
===================================================================
RCS file: /cvsroot/gforge/gforge/www/survey/admin/show_results.php,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- show_results.php    21 Feb 2003 21:38:58 -0000      1.4
+++ show_results.php    20 Feb 2004 01:23:53 -0000      1.5
@@ -13,162 +13,111 @@
 
 
 require_once('pre.php');
-require_once('www/survey/survey_utils.php');
-$is_admin_page='y';
-survey_header(array('title'=>$Language->getText('survey_show_results','title'),'pagename'=>'survey_admin_show_results'));
-
-if (!session_loggedin() || !user_ismember($group_id,'A')) {
-       echo 
"<h1>".$Language->getText('survey_show_results','permission_denied')."</h1>";
-       survey_footer(array());
-       exit;
-}
-
-Function  ShowResultsSurvey($result) {
-       global $group_id,$PHP_SELF;
-       $rows  =  db_numrows($result);
-       $cols  =  db_numfields($result);
-       echo "<h3>$rows" 
.$Language->getText('survey_show_results','found')."</h3>";
-
-       echo /*"<table bgcolor=\"NAVY\"><tr><td bgcolor=\"NAVY\">*/ "<table 
border=\"0\">\n";
-       /*  Create  the  headers  */
-       echo "<tr style=\"background=color:$GLOBALS[COLOR_MENUBARBACK]\">\n";
-
-       for($i  =  0;  $i  <  $cols;  $i++)  {
-               printf( "<th><span 
style=\"color:white\"><strong>%s</strong></span></th>\n",  
db_fieldname($result,$i));
-       }
-       echo "</tr>";
-
-       for($j  =  0;  $j  <  $rows;  $j++)  {
-
-               if ($j%2==0) {
-                       $row_bg="white";
-               } else {
-                       $row_bg="$GLOBALS[COLOR_LTBACK1]";
-               }
-
-               echo "<tr style=\"background-color:$row_bg\">\n";
-
-               echo "<td><a 
href=\"$PHP_SELF?group_id=$group_id&amp;survey_id=".db_result($result,$j,"survey_id")."\">".db_result($result,$j,"survey_id")."</a></td>\n";
 
-               for($i  =  1;  $i  <  $cols;  $i++)  {
-                       printf("<td>%s</td>\n",db_result($result,$j,$i));
-               }
+require_once('common/survey/Survey.class');
+require_once('common/survey/SurveyFactory.class');
+require_once('common/survey/SurveyQuestion.class');
+require_once('common/survey/SurveyQuestionFactory.class');
+require_once('common/survey/SurveyResponse.class');
+require_once('common/survey/SurveyResponseFactory.class');
+require_once('www/survey/include/SurveyHTML.class');
 
-               echo "</tr>";
-       }
-       echo "</table>"; //</td></tr></TABLE>";
+/* We need a group_id */ 
+if (!$group_id) {
+    exit_no_group();
 }
 
+$g =& group_get_object($group_id);
+if (!$g || !is_object($g) || $g->isError()) {
+    exit_no_group();
+}
 
-Function  ShowResultsAggregate($result) {
-       global $group_id;
-       global $Language;
-       $rows  =  db_numrows($result);
-       $cols  =  db_numfields($result);
-       echo "<h3>$rows" 
.$Language->getText('survey_show_results','found')."</h3>";
-
-       echo /*"<table bgcolor=\"NAVY\"><tr><td bgcolor=\"NAVY\">*/ "<table 
border=\"0\">\n";
-       /*  Create  the  headers  */
-       echo "<tr style=\"background=color:$GLOBALS[COLOR_MENUBARBACK]\">\n";
-
-       for($i  =  0;  $i  <  $cols;  $i++)  {
-               printf( "<th><span 
style=\"color:white\"><strong>%s</strong></span></th>\n",  
db_fieldname($result,$i));
-       }
-       echo "</tr>";
-
-       for($j  =  0;  $j  <  $rows;  $j++)  {
-
-               if ($j%2==0) {
-                       $row_bg="white";
-               } else {
-                       $row_bg="$GLOBALS[COLOR_LTBACK1]";
-               }
-
-               echo "<tr style=\"background-color:$row_bg\">\n";
-
-               echo "<td><a 
href=\"show_results_aggregate.php?group_id=$group_id&amp;survey_id=".db_result($result,$j,"survey_id")."\">".db_result($result,$j,"survey_id")."</a></td>\n";
+$is_admin_page='y';
+$sh = new  SurveyHtml();
 
-               for($i  =  1;  $i  <  $cols;  $i++)  {
-                       printf("<td>%s</td>\n",db_result($result,$j,$i));
-               }
+$is_admin_page='y';
+$sh->header(array('title'=>$Language->getText('survey_show_results','title'),'pagename'=>'survey_admin_show_results'));
 
-               echo "</tr>";
-       }
-       echo "</table>"; //</td></tr></TABLE>";
+if (!session_loggedin() || !user_ismember($group_id,'A')) {
+       echo 
"<h1>".$Language->getText('survey_show_results','permission_denied')."</h1>";
+       $sh->footer(array());
+       exit;
 }
 
+/* Show detailed results of a survey */
+if ($survey_id) {
+    $s = new Survey($g, $survey_id);
+               
+    if (!$s || !is_object($s)) {
+       echo "<h3>".$Language->getText('general','error'). ' Can not get 
Survey' ."</H3>";
+       $sh->footer(array());
+       exit;
+    } else if ( $s->isError()) {
+       echo "<h3>".$Language->getText('general','error'). 
$s->getErrorMessage() ."</H3>";
+       $sh->footer(array());
+       exit;
+    }
 
-Function  ShowResultsCustomer($result) {
-       global $survey_id,$group_id;
-       global $Language;
-       $rows  =  db_numrows($result);
-       $cols  =  db_numfields($result);
-       echo 
"<h3>$rows".$Language->getText('survey_show_results','found')."</h3>";
-
-       echo /*"<table bgcolor=\"NAVY\"><tr><td bgcolor=\"NAVY\">*/ "<table 
border=\"0\">\n";
-       /*  Create  the  headers  */
-       echo "<tr style=\"background=color:$GLOBALS[COLOR_MENUBARBACK]\">\n";
-
-       for($i  =  0;  $i  <  $cols;  $i++)  {
-               printf( "<th><span 
style=\"color:white\"><strong>%s</strong></span></th>\n",  
db_fieldname($result,$i));
+    /* A specific question */
+    if ($question_id) {
+       /* Create a Survey Question for general purpose */
+       $sq = new SurveyQuestion($g, $question_id);
+       if (!$sq || !is_object($sq)) {
+           echo "<h3>".$Language->getText('general','error'). ' Can not get 
Survey Question' ."</H3>";
+       } else if ( $sq->isError()) {
+           echo "<h3>".$Language->getText('general','error'). 
$sq->getErrorMessage() ."</H3>";
+       } else {
+           showResult($sh, $s, $sq, 1, 0, $graph);
        }
-       echo "</tr>";
-
-       for($j  =  0;  $j  <  $rows;  $j++)  {
-
-               if ($j%2==0) {
-                       $row_bg="white";
-               } else {
-                       $row_bg="$GLOBALS[COLOR_LTBACK1]";
-               }
-
-               echo "<tr style=\"background-color:$row_bg\">\n";
-
-               echo "<td><a 
href=\"show_results_individual.php?group_id=$group_id&amp;survey_id=$survey_id&amp;customer_id=".db_result($result,$j,"cust_id")."\">".db_result($result,$j,"cust_id")."</a></td>\n";
+       
+    } else {
+       echo '<h2>'.$s->getTitle().' ( '. $s->getNumberOfVotes() .' Votes 
)</h2><p/>';
 
-               for($i  =  1;  $i  <  $cols;  $i++)  {
-                       printf("<td>%s</td>\n",db_result($result,$j,$i));
+       /* Get questions of this survey */
+       $questions = & $s->getQuestionInstances();
+       
+       $question_number = 1;
+       for ($i=0; $i<count($questions); $i++) {
+           if ($questions[$i]->isError()) {
+               echo $questions[$i]->getErrorMessage();
+           } else {
+               if ($questions[$i]->getQuestionType()!='4') {
+                   showResult($sh, $s, $questions[$i], $show_comment, 
$question_number++, $graph);
                }
-
-               echo "</tr>";
+           }
        }
-       echo "</table>"; //</td></tr></TABLE>";
+    }
 }
 
+/* Show list of Surveys with result link */
+/* Show list of Servey */
+$sf = new SurveyFactory($g);
+$ss = & $sf->getSurveys();
+if (!$ss) {
+    echo ($Language->getText('survey_error', 'no_question_found'));
+} else {
+    echo($sh->ShowSurveys($ss, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1));
+}
 
+$sh->footer(array());
 
-if (!$survey_id) {
-
-       /*
-               Select a list of surveys, so they can click in and view a 
particular set of responses
-       */
-
-       $sql="SELECT survey_id,survey_title FROM surveys WHERE 
group_id='$group_id'";
-
-       $result=db_query($sql);
-
-//     echo "\n<h2>View Individual Responses</h2>\n\n";
-//     ShowResultsSurvey($result);
-
-       echo 
"\n<h2>".$Language->getText('survey_show_results','view_aggregate_responses')."</h2>\n\n";
-       ShowResultsAggregate($result);
-
-} /* else {
-
-       / *
-               Pull up a list of customer IDs for people that responded to 
this survey
-       * /
-
-       $sql="select people.cust_id, people.first_name, people.last_name ".
-               "FROM people,responses where 
responses.customer_id=people.cust_id AND responses.survey_id='$survey_id' ".
-               "GROUP BY people.cust_id, people.first_name, people.last_name";
-
-       $result=db_query($sql);
-
-       ShowResultsCustomer($result);
-
-} */
-
-survey_footer(array());
-
+/**
+ * ShowResult - Get Result from Survey and Question. Pass the reuslt to Show 
Result HTML class
+ *
+ *  @param object a survey object
+ *  @param object a qustsion object
+ *  @param int    wheather print out export(csv) format
+ */
+function ShowResult(&$SurveyHTML, &$Survey, &$Question, $show_comment=0, 
$q_num="", $graph=0) {
+    /* Get results */
+    $srf = new SurveyResponseFactory(&$Survey, &$Question);
+    if (!$srf || !is_object($srf)) {
+       echo "<h3>".$Language->getText('general','error'). ' Can not get Survey 
Response Factory' ."</H3>";
+    } else if ( $srf->isError()) {
+       echo "<h3>".$Language->getText('general','error'). 
$srf->getErrorMessage() ."</H3>";
+    } else {
+        /* Show result in HTML*/ 
+       echo ($SurveyHTML->ShowResult($srf, $show_comment, $q_num, $graph));
+    }
+}
 ?>





reply via email to

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