Use course setting for "student"
[moodle.git] / mod / survey / graph.php
1 <?PHP // $Id$
3     require("../../config.php");
4     require("$CFG->libdir/graphlib.php");
5     require("lib.php");
7     require_variable($id);    // Course Module ID
8     require_variable($type);  // Graph Type
9     optional_variable($sid);  // Student ID
11     if (! $cm = get_record("course_modules", "id", $id)) {
12         error("Course Module ID was incorrect");
13     }
15     if (! $course = get_record("course", "id", $cm->course)) {
16         error("Course is misconfigured");
17     }
19     require_login($course->id);
21     if (!isteacher($course->id) && !isadmin()) {
22         if (! ($type == "student.png" && $sid == $USER->id) ) {
23             error("Sorry, you aren't allowed to see this.");
24         }
25     }
27     if (! $survey = get_record("survey", "id", $cm->instance)) {
28         error("Survey ID was incorrect");
29     }
31     $stractual = get_string("actual", "survey");
32     $stractualclass = get_string("actualclass", "survey");
33     $stractualstudent = get_string("actualstudent", "survey", $course->student);
35     $strpreferred = get_string("preferred", "survey");
36     $strpreferredclass = get_string("preferredclass", "survey");
37     $strpreferredstudent = get_string("preferredstudent", "survey", $course->student);
39     switch ($type) {
41      case "question.png":
43        $question = get_record("survey_questions", "id", $qid);
44        $question->text = get_string($question->text, "survey");
45        $question->options = get_string($question->options, "survey");
46   
47        $options = explode(",",$question->options);
49        while (list($key,) = each($options)) {
50            $buckets1[$key] = 0;
51            $buckets2[$key] = 0;
52        }
54        $aa = $db->Execute("SELECT * FROM survey_answers WHERE survey = $cm->instance AND question = $qid");
56        while (!$aa->EOF) {
57            if ($a1 = $aa->fields["answer1"]) {
58                $buckets1[$a1 - 1]++;
59            }
60            if ($a2 = $aa->fields["answer2"]) {
61                $buckets2[$a2 - 1]++;
62            }
63            $aa->MoveNext();
64        }
66        
67        $maxbuckets1 = max($buckets1);
68        $maxbuckets2 = max($buckets2);
69        $maxbuckets = ($maxbuckets1 > $maxbuckets2) ? $maxbuckets1 : $maxbuckets2;
71        $graph = new graph($SURVEY_GWIDTH,$SURVEY_GHEIGHT);
72        $graph->parameter['title'] = "$question->text";
74        $graph->x_data               = $options;
76        $graph->y_data['answers1']   = $buckets1;
77        $graph->y_format['answers1'] = array('colour' => 'ltblue','bar' => 'fill','legend' =>$stractual,'bar_size' => 0.4);
78        $graph->y_data['answers2']   = $buckets2;
79        $graph->y_format['answers2'] = array('colour' =>'ltorange','bar' => 'fill','legend' =>$strpreferred,'bar_size' => 0.2);
81        $graph->parameter['legend']        = 'outside-top';
82        $graph->parameter['legend_border'] = 'black';
83        $graph->parameter['legend_offset'] = 4;
85        if (($maxbuckets1 > 0.0) && ($maxbuckets2 > 0.0)) {
86            $graph->y_order = array('answers1', 'answers2');
87        } else if ($maxbuckets1 > 0.0) {
88            $graph->y_order = array('answers1');
89        } else {
90            $graph->y_order = array('answers2');
91        }
92        
93        $graph->parameter['y_axis_gridlines']= $maxbuckets + 1;
94        $graph->parameter['y_resolution_left']= 1;
95        $graph->parameter['y_decimal_left']  = 0;
96        $graph->parameter['x_axis_angle']    = 0;
97        $graph->parameter['shadow']          = 'none';
99        $graph->draw_stack();
101        break;
105      case "multiquestion.png":
107        $question  = get_record("survey_questions", "id", $qid);
108        $question->text = get_string($question->text, "survey");
109        $question->options = get_string($question->options, "survey");
111        $options = explode(",",$question->options);
112        $questionorder = explode( ",", $question->multi);
114        $qqq = get_records_sql("SELECT * FROM survey_questions WHERE id in ($question->multi)");
116        foreach ($questionorder as $i => $val) {
117            $names[$i] = get_string($qqq["$val"]->shorttext, "survey");
118            $buckets1[$i] = 0;
119            $buckets2[$i] = 0;
120            $count1[$i] = 0;
121            $count2[$i] = 0;
122            $indexof[$val] = $i;
123        }
125        $aaa = get_records_sql("SELECT * FROM survey_answers WHERE ((survey = $cm->instance) AND (question in ($question->multi)))");
127        foreach ($aaa as $a) {
128            $index = $indexof[$a->question];
129            if ($a->answer1) {
130                $buckets1[$index] += $a->answer1;
131                $count1[$index]++;
132            }
133            if ($a->answer2) {
134                $buckets2[$index] += $a->answer2;
135                $count2[$index]++;
136            }
137        }
139        foreach ($questionorder as $i => $val) {
140            if ($count1[$i]) {
141                $buckets1[$i] = (float)$buckets1[$i] / (float)$count1[$i];
142            }
143            if ($count2[$i]) {
144                $buckets2[$i] = (float)$buckets2[$i] / (float)$count2[$i];
145            }
146        }
148        foreach ($aaa as $a) {
149            $index = $indexof[$a->question];
150            if ($a->answer1) {
151                $difference = (float) ($a->answer1 - $buckets1[$index]);
152                $stdev1[$index] += ($difference * $difference);
153            }
154            if ($a->answer2) {
155                $difference = (float) ($a->answer2 - $buckets2[$index]);
156                $stdev2[$index] += ($difference * $difference);
157            }
158        }
160        foreach ($questionorder as $i => $val) {
161            if ($count1[$i]) {
162                $stdev1[$i] = sqrt( (float)$stdev1[$i] / ((float)$count1[$i]));
163            }
164            if ($count2[$i]) {
165                $stdev2[$i] = sqrt( (float)$stdev2[$i] / ((float)$count2[$i]));
166            }
167            $buckets1[$i] = $buckets1[$i] - 1;
168            $buckets2[$i] = $buckets2[$i] - 1;
169        }
171        
173        $maxbuckets1 = max($buckets1);
174        $maxbuckets2 = max($buckets2);
177        $graph = new graph($SURVEY_GWIDTH,$SURVEY_GHEIGHT);
178        $graph->parameter['title'] = "$question->text";
180        $graph->x_data               = $names;
181        $graph->y_data['answers1']   = $buckets1;
182        $graph->y_format['answers1'] = array('colour' => 'ltblue', 'line' => 'line',  'point' => 'square', 
183                                             'shadow_offset' => 4, 'legend' => $stractual);
184        $graph->y_data['answers2']   = $buckets2;
185        $graph->y_format['answers2'] = array('colour' => 'ltorange', 'line' => 'line', 'point' => 'square', 
186                                                 'shadow_offset' => 4, 'legend' => $strpreferred);
187        $graph->y_data['stdev1']   = $stdev1;
188        $graph->y_format['stdev1'] = array('colour' => 'ltltblue', 'bar' => 'fill', 
189                                             'shadow_offset' => '4', 'legend' => 'none', 'bar_size' => 0.3);
190        $graph->y_data['stdev2']   = $stdev2;
191        $graph->y_format['stdev2'] = array('colour' => 'ltltorange', 'bar' => 'fill', 
192                                             'shadow_offset' => '4', 'legend' => 'none', 'bar_size' => 0.2);
193        $graph->offset_relation['stdev1'] = 'answers1';
194        $graph->offset_relation['stdev2'] = 'answers2';
196        $graph->parameter['bar_size']    = 0.15;
198        $graph->parameter['legend']        = 'outside-top';
199        $graph->parameter['legend_border'] = 'black';
200        $graph->parameter['legend_offset'] = 4;
202        $graph->y_tick_labels = $options;
204        if (($maxbuckets1 > 0.0) && ($maxbuckets2 > 0.0)) {
205               $graph->y_order = array('stdev1', 'answers1', 'stdev2', 'answers2');
206        } else if ($maxbuckets1 > 0.0) {
207            $graph->y_order = array('stdev1', 'answers1');
208        } else {
209            $graph->y_order = array('stdev2', 'answers2');
210        }
211        
212        $graph->parameter['y_max_left']= count($options) - 1;
213        $graph->parameter['y_axis_gridlines']= count($options);
214        $graph->parameter['y_resolution_left']= 1;
215        $graph->parameter['y_decimal_left']= 1;
216        $graph->parameter['x_axis_angle']  = 0;
218        $graph->draw();
220        break;
223     
224      case "overall.png":
226        $qqq = get_records_sql("SELECT * FROM survey_questions WHERE id in ($survey->questions) AND multi <> ''");
228        foreach ($qqq as $key => $qq) {
229            $qqq[$key]->text = get_string($qq->text, "survey");
230            $qqq[$key]->options = get_string($qq->options, "survey");
231            if ($qq->type < 0) {
232                $virtualscales = true;
233            }
234        }
235        foreach ($qqq as $qq) {         // if any virtual, then use JUST virtual, else use JUST nonvirtual
236            if ($virtualscales && $qq->type < 0) {
237                $question[] = $qq;
238            } else if (!$virtualscales && $qq->type > 0) {
239                $question[] = $qq;
240            }
241        }
242        $numquestions = count($question);
244        $options = explode(",",$question[0]->options);
245        $numoptions = count($options);
247        for ($i=0; $i<$numquestions; $i++) {
248            $names[$i] = $question[$i]->text;
249            $buckets1[$i] = 0.0;
250            $buckets2[$i] = 0.0;
251            $stdev1[$i] = 0.0;
252            $stdev2[$i] = 0.0;
253            $count1[$i] = 0;
254            $count2[$i] = 0;
255            $subquestions = $question[$i]->multi;   // otherwise next line doesn't work
256            $aaa = get_records_sql("SELECT * FROM survey_answers WHERE ((survey = $cm->instance) AND (question in ($subquestions)))");
258            foreach ($aaa as $a) {
259                if ($a->answer1) {
260                    $buckets1[$i] += $a->answer1;
261                    $count1[$i]++;
262                }
263                if ($a->answer2) {
264                    $buckets2[$i] += $a->answer2;
265                    $count2[$i]++;
266                }
267            }
269            if ($count1[$i]) {
270                $buckets1[$i] = (float)$buckets1[$i] / (float)$count1[$i];
271            }
272            if ($count2[$i]) {
273                $buckets2[$i] = (float)$buckets2[$i] / (float)$count2[$i];
274            }
276            // Calculate the standard devaiations
277            foreach ($aaa as $a) {
278                if ($a->answer1) {
279                    $difference = (float) ($a->answer1 - $buckets1[$i]);
280                    $stdev1[$i] += ($difference * $difference);
281                }
282                if ($a->answer2) {
283                    $difference = (float) ($a->answer2 - $buckets2[$i]);
284                    $stdev2[$i] += ($difference * $difference);
285                }
286            }
288            if ($count1[$i]) {
289                $stdev1[$i] = sqrt( (float)$stdev1[$i] / ((float)$count1[$i]));
290            }
291            if ($count2[$i]) {
292                $stdev2[$i] = sqrt( (float)$stdev2[$i] / ((float)$count2[$i]));
293            }
295            $buckets1[$i] = $buckets1[$i] - 1;         // Hack because there should not be ANY 0 values in the data.
296            $buckets2[$i] = $buckets2[$i] - 1;
297            
298        }
300        $maxbuckets1 = max($buckets1);
301        $maxbuckets2 = max($buckets2);
304        $graph = new graph($SURVEY_GWIDTH,$SURVEY_GHEIGHT);
305        $graph->parameter['title'] = "$survey->name";
307        $graph->x_data               = $names;
309        $graph->y_data['answers1']   = $buckets1;
310        $graph->y_format['answers1'] = array('colour' => 'ltblue', 'line' => 'line',  'point' => 'square', 
311                                             'shadow_offset' => 4, 'legend' => $stractual);
312        $graph->y_data['answers2']   = $buckets2;
313        $graph->y_format['answers2'] = array('colour' => 'ltorange', 'line' => 'line', 'point' => 'square', 
314                                                 'shadow_offset' => 4, 'legend' => $strpreferred);
316        $graph->y_data['stdev1']   = $stdev1;
317        $graph->y_format['stdev1'] = array('colour' => 'ltltblue', 'bar' => 'fill', 
318                                             'shadow_offset' => '4', 'legend' => 'none', 'bar_size' => 0.3);
319        $graph->y_data['stdev2']   = $stdev2;
320        $graph->y_format['stdev2'] = array('colour' => 'ltltorange', 'bar' => 'fill', 
321                                             'shadow_offset' => '4', 'legend' => 'none', 'bar_size' => 0.2);
322        $graph->offset_relation['stdev1'] = 'answers1';
323        $graph->offset_relation['stdev2'] = 'answers2';
325        $graph->parameter['legend']        = 'outside-top';
326        $graph->parameter['legend_border'] = 'black';
327        $graph->parameter['legend_offset'] = 4;
329        $graph->y_tick_labels = $options;
331        if (($maxbuckets1 > 0.0) && ($maxbuckets2 > 0.0)) {
332               $graph->y_order = array('stdev1', 'answers1', 'stdev2', 'answers2');
333        } else if ($maxbuckets1 > 0.0) {
334            $graph->y_order = array('stdev1', 'answers1');
335        } else {
336            $graph->y_order = array('stdev2', 'answers2');
337        }
338        
339        $graph->parameter['y_max_left']= $numoptions - 1;
340        $graph->parameter['y_axis_gridlines']= $numoptions;
341        $graph->parameter['y_resolution_left']= 1;
342        $graph->parameter['y_decimal_left']= 1;
343        $graph->parameter['x_axis_angle']  = 0;
345        $graph->draw();
347        break;
351      case "student.png":
353        $qqq = get_records_sql("SELECT * FROM survey_questions WHERE id in ($survey->questions) AND multi <> ''");
355        foreach ($qqq as $key => $qq) {
356            $qqq[$key]->text = get_string($qq->text, "survey");
357            $qqq[$key]->options = get_string($qq->options, "survey");
358            if ($qq->type < 0) {
359                $virtualscales = true;
360            }
361        }
362        foreach ($qqq as $qq) {         // if any virtual, then use JUST virtual, else use JUST nonvirtual
363            if ($virtualscales && $qq->type < 0) {
364                $question[] = $qq;
365            } else if (!$virtualscales && $qq->type > 0) {
366                $question[] = $qq;
367            }
368        }
369        $numquestions= count($question);
371        $options = explode(",",$question[0]->options);
372        $numoptions = count($options);
374        for ($i=0; $i<$numquestions; $i++) {
375            $names[$i] = $question[$i]->text;
376            $buckets1[$i] = 0.0;
377            $buckets2[$i] = 0.0;
378            $count1[$i] = 0;
379            $count2[$i] = 0;
380            $studbuckets1[$i] = 0.0;
381            $studbuckets2[$i] = 0.0;
382            $studcount1[$i] = 0;
383            $studcount2[$i] = 0;
384            $subquestions = $question[$i]->multi;   // otherwise next line doesn't work
385            $aaa = get_records_sql("SELECT * FROM survey_answers WHERE ((survey = $cm->instance) AND (question in ($subquestions)))");
387            foreach ($aaa as $a) {
388                if ($a->user == $sid) {
389                    if ($a->answer1) {
390                        $studbuckets1[$i] += $a->answer1;
391                        $studcount1[$i]++;
392                    }
393                    if ($a->answer2) {
394                        $studbuckets2[$i] += $a->answer2;
395                        $studcount2[$i]++;
396                    }
397                }
398                if ($a->answer1) {
399                    $buckets1[$i] += $a->answer1;
400                    $count1[$i]++;
401                }
402                if ($a->answer2) {
403                    $buckets2[$i] += $a->answer2;
404                    $count2[$i]++;
405                }
406            }
408            if ($count1[$i]) {
409                $buckets1[$i] = (float)$buckets1[$i] / (float)$count1[$i];
410            }
411            if ($count2[$i]) {
412                $buckets2[$i] = (float)$buckets2[$i] / (float)$count2[$i];
413            }
414            if ($studcount1[$i]) {
415                $studbuckets1[$i] = (float)$studbuckets1[$i] / (float)$studcount1[$i];
416            }
417            if ($studcount2[$i]) {
418                $studbuckets2[$i] = (float)$studbuckets2[$i] / (float)$studcount2[$i];
419            }
421            // Calculate the standard devaiations
422            foreach ($aaa as $a) {
423                if ($a->answer1) {
424                    $difference = (float) ($a->answer1 - $buckets1[$i]);
425                    $stdev1[$i] += ($difference * $difference);
426                }
427                if ($a->answer2) {
428                    $difference = (float) ($a->answer2 - $buckets2[$i]);
429                    $stdev2[$i] += ($difference * $difference);
430                }
431            }
433            if ($count1[$i]) {
434                $stdev1[$i] = sqrt( (float)$stdev1[$i] / ((float)$count1[$i]));
435            }
436            if ($count2[$i]) {
437                $stdev2[$i] = sqrt( (float)$stdev2[$i] / ((float)$count2[$i]));
438            }
440            $buckets1[$i] = $buckets1[$i] - 1;         // Hack because there should not be ANY 0 values in the data.
441            $buckets2[$i] = $buckets2[$i] - 1;
442            $studbuckets1[$i] = $studbuckets1[$i] - 1;
443            $studbuckets2[$i] = $studbuckets2[$i] - 1;
445        }
447        $maxbuckets1 = max($buckets1);
448        $maxbuckets2 = max($buckets2);
451        $graph = new graph($SURVEY_GWIDTH,$SURVEY_GHEIGHT);
452        $graph->parameter['title'] = "$survey->name";
454        $graph->x_data               = $names;
456        $graph->y_data['answers1']   = $buckets1;
457        $graph->y_format['answers1'] = array('colour' => 'ltblue', 'line' => 'line',  'point' => 'square', 
458                                             'shadow_offset' => 0.1, 'legend' => $stractualclass);
459        $graph->y_data['answers2']   = $buckets2;
460        $graph->y_format['answers2'] = array('colour' => 'ltorange', 'line' => 'line', 'point' => 'square', 
461                                                 'shadow_offset' => 0.1, 'legend' => $strpreferredclass);
462        $graph->y_data['studanswers1']   = $studbuckets1;
463        $graph->y_format['studanswers1'] = array('colour' => 'blue', 'line' => 'line',  'point' => 'square', 
464                                             'shadow_offset' => 4, 'legend' => $stractualstudent);
465        $graph->y_data['studanswers2']   = $studbuckets2;
466        $graph->y_format['studanswers2'] = array('colour' => 'orange', 'line' => 'line', 'point' => 'square', 
467                                                 'shadow_offset' => 4, 'legend' => $strpreferredstudent);
468        $graph->y_data['stdev1']   = $stdev1;
469        $graph->y_format['stdev1'] = array('colour' => 'ltltblue', 'bar' => 'fill', 
470                                             'shadow_offset' => 0.1, 'legend' => 'none', 'bar_size' => 0.3);
471        $graph->y_data['stdev2']   = $stdev2;
472        $graph->y_format['stdev2'] = array('colour' => 'ltltorange', 'bar' => 'fill', 
473                                             'shadow_offset' => 0.1, 'legend' => 'none', 'bar_size' => 0.2);
474        $graph->offset_relation['stdev1'] = 'answers1';
475        $graph->offset_relation['stdev2'] = 'answers2';
477        $graph->y_tick_labels = $options;
479        $graph->parameter['bar_size']    = 0.15;
481        $graph->parameter['legend']        = 'outside-top';
482        $graph->parameter['legend_border'] = 'black';
483        $graph->parameter['legend_offset'] = 4;
485        if (($maxbuckets1 > 0.0) && ($maxbuckets2 > 0.0)) {
486               $graph->y_order = array('stdev1', 'stdev2', 'answers1', 'answers2', 'studanswers1', 'studanswers2');
487        } else if ($maxbuckets1 > 0.0) {
488            $graph->y_order = array('stdev1', 'answers1', 'studanswers1');
489        } else {
490            $graph->y_order = array('stdev2', 'answers2', 'studanswers2');
491        }
492        
493        $graph->parameter['y_max_left']= $numoptions - 1;
494        $graph->parameter['y_axis_gridlines']= $numoptions;
495        $graph->parameter['y_resolution_left']= 1;
496        $graph->parameter['y_decimal_left']= 1;
497        $graph->parameter['x_axis_angle']  = 0;
499        $graph->draw();
500        break;
504      case "studentmultiquestion.png":
506        $question  = get_record("survey_questions", "id", $qid);
507        $question->text = get_string($question->text, "survey");
508        $question->options = get_string($question->options, "survey");
510        $options = explode(",",$question->options);
511        $questionorder = explode( ",", $question->multi);
513        $qqq = get_records_sql("SELECT * FROM survey_questions WHERE id in ($question->multi)");
515        foreach ($questionorder as $i => $val) {
516            $names[$i] = get_string($qqq[$val]->shorttext, "survey");
517            $buckets1[$i] = 0;
518            $buckets2[$i] = 0;
519            $count1[$i] = 0;
520            $count2[$i] = 0;
521            $indexof[$val] = $i;
522            $studbuckets1[$i] = 0.0;
523            $studbuckets2[$i] = 0.0;
524            $studcount1[$i] = 0;
525            $studcount2[$i] = 0;
526        }
528        $aaa = get_records_sql("SELECT * FROM survey_answers WHERE ((survey = $cm->instance) AND (question in ($question->multi)))");
530        foreach ($aaa as $a) {
531            $index = $indexof[$a->question];
532                if ($a->user == $sid) {
533                    if ($a->answer1) {
534                        $studbuckets1[$index] += $a->answer1;
535                        $studcount1[$index]++;
536                    }
537                    if ($a->answer2) {
538                        $studbuckets2[$index] += $a->answer2;
539                        $studcount2[$index]++;
540                    }
541                }
542            if ($a->answer1) {
543                $buckets1[$index] += $a->answer1;
544                $count1[$index]++;
545            }
546            if ($a->answer2) {
547                $buckets2[$index] += $a->answer2;
548                $count2[$index]++;
549            }
550        }
552        foreach ($questionorder as $i => $val) {
553            if ($count1[$i]) {
554                $buckets1[$i] = (float)$buckets1[$i] / (float)$count1[$i];
555            }
556            if ($count2[$i]) {
557                $buckets2[$i] = (float)$buckets2[$i] / (float)$count2[$i];
558            }
559            if ($studcount1[$i]) {
560                $studbuckets1[$i] = (float)$studbuckets1[$i] / (float)$studcount1[$i];
561            }
562            if ($studcount2[$i]) {
563                $studbuckets2[$i] = (float)$studbuckets2[$i] / (float)$studcount2[$i];
564            }
565        }
567        foreach ($aaa as $a) {
568            $index = $indexof[$a->question];
569            if ($a->answer1) {
570                $difference = (float) ($a->answer1 - $buckets1[$index]);
571                $stdev1[$index] += ($difference * $difference);
572            }
573            if ($a->answer2) {
574                $difference = (float) ($a->answer2 - $buckets2[$index]);
575                $stdev2[$index] += ($difference * $difference);
576            }
577        }
579        foreach ($questionorder as $i => $val) {
580            if ($count1[$i]) {
581                $stdev1[$i] = sqrt( (float)$stdev1[$i] / ((float)$count1[$i]));
582            }
583            if ($count2[$i]) {
584                $stdev2[$i] = sqrt( (float)$stdev2[$i] / ((float)$count2[$i]));
585            }
586            $buckets1[$i] = $buckets1[$i] - 1;         // Hack because there should not be ANY 0 values in the data.
587            $buckets2[$i] = $buckets2[$i] - 1;
588            $studbuckets1[$i] = $studbuckets1[$i] - 1;
589            $studbuckets2[$i] = $studbuckets2[$i] - 1;
590        }
592        
594        $maxbuckets1 = max($buckets1);
595        $maxbuckets2 = max($buckets2);
598        $graph = new graph($SURVEY_GWIDTH,$SURVEY_GHEIGHT);
599        $graph->parameter['title'] = "$question->text";
601        $graph->x_data               = $names;
602        $graph->y_data['answers1']   = $buckets1;
603        $graph->y_format['answers1'] = array('colour' => 'ltblue', 'line' => 'line',  'point' => 'square', 
604                                             'shadow_offset' => 0.1, 'legend' => $stractualclass);
605        $graph->y_data['answers2']   = $buckets2;
606        $graph->y_format['answers2'] = array('colour' => 'ltorange', 'line' => 'line', 'point' => 'square', 
607                                                 'shadow_offset' => 0.1, 'legend' => $strpreferredclass);
608        $graph->y_data['studanswers1']   = $studbuckets1;
609        $graph->y_format['studanswers1'] = array('colour' => 'blue', 'line' => 'line',  'point' => 'square', 
610                                             'shadow_offset' => 4, 'legend' => $stractualstudent);
611        $graph->y_data['studanswers2']   = $studbuckets2;
612        $graph->y_format['studanswers2'] = array('colour' => 'orange', 'line' => 'line', 'point' => 'square', 
613                                                 'shadow_offset' => 4, 'legend' => $strpreferredstudent);
614        $graph->y_data['stdev1']   = $stdev1;
615        $graph->y_format['stdev1'] = array('colour' => 'ltltblue', 'bar' => 'fill', 
616                                             'shadow_offset' => 0.1, 'legend' => 'none', 'bar_size' => 0.3);
617        $graph->y_data['stdev2']   = $stdev2;
618        $graph->y_format['stdev2'] = array('colour' => 'ltltorange', 'bar' => 'fill', 
619                                             'shadow_offset' => 0.1, 'legend' => 'none', 'bar_size' => 0.2);
620        $graph->offset_relation['stdev1'] = 'answers1';
621        $graph->offset_relation['stdev2'] = 'answers2';
623        $graph->parameter['bar_size']    = 0.15;
625        $graph->parameter['legend']        = 'outside-top';
626        $graph->parameter['legend_border'] = 'black';
627        $graph->parameter['legend_offset'] = 4;
629        $graph->y_tick_labels = $options;
631        if (($maxbuckets1 > 0.0) && ($maxbuckets2 > 0.0)) {
632               $graph->y_order = array('stdev1', 'stdev2', 'answers1', 'answers2', 'studanswers1', 'studanswers2');
633        } else if ($maxbuckets1 > 0.0) {
634            $graph->y_order = array('stdev1', 'answers1', 'studanswers1');
635        } else {
636            $graph->y_order = array('stdev2', 'answers2', 'studanswers2');
637        }
638        
639        $graph->parameter['y_max_left']= count($options)-1;
640        $graph->parameter['y_axis_gridlines']= count($options);
641        $graph->parameter['y_resolution_left']= 1;
642        $graph->parameter['y_decimal_left']= 1;
643        $graph->parameter['x_axis_angle']  = 0;
645        $graph->draw();
647        break;
649      default:
650        break;
651    }
653    exit;
655          
656 ?>