<?cs include:"util.cs" ?>


<?cs def:print_row(label, value) ?>
     <tr>
        <td><?cs var:label ?></td>  
        <td><?cs var:value ?></td>  
     </tr>
<?cs /def ?>







<?cs ### prints a table of info for surveys 
     ### delivered via MyManhattan or externally via
     ### the web
?>

<?cs def:mymanhat_www_info_table() ?>
  <div class="center_msg"><?cs var:survey.title ?></div>
  <table width="100%">
   <tr><td align="center">
     <table border="1" cellspacing="0">
      <?cs call:print_row(lang.survey_bar_graph.num_response, survey.num_response) ?>
      
      <?cs if:survey.type != "www_accessible" ?>
         <?cs call:print_row(lang.survey_bar_graph.num_expected_takers, survey.num_expect_takers) ?>
         <?cs call:print_row(lang.survey_bar_graph.rate, survey.rate) ?>
      <?cs /if ?>

      <?cs if:survey.type == "mymanhattan" ?>
            <?cs call:print_row(lang.survey_bar_graph.survey_type_label, lang.survey_bar_graph.mymanhattan_survey) ?>
      <?cs elif:survey.type == "www_accessible" ?>
            <?cs call:print_row(lang.survey_bar_graph.survey_type_label, lang.survey_bar_graph.www_survey) ?>
      <?cs /if ?>
      </table>
   </td></tr>
 </table>
<?cs /def ?> 





<?cs ### prints a table of info for surveys
     ### delivered within a classroom's 
     ### Surveys module
?>

<?cs def:survey_module_info_table() ?>
  <table width="100%">
   <tr><td align="center">
     <table border="1" cellspacing="0">
         <?cs call:print_row(lang.survey_bar_graph.id, survey.id) ?>
         <?cs call:print_row(lang.survey_bar_graph.subject, survey.subject) ?>
         <?cs call:print_row(lang.survey_bar_graph.posted, survey.sender_name) ?>
         <?cs call:print_row(lang.survey_bar_graph.send_time, survey.send_time) ?>
         <?cs call:print_row(lang.survey_bar_graph.result_time, survey.result_time) ?>
         <?cs call:print_row(lang.survey_bar_graph.can_view_results, lang.survey_bar_graph.yes_no[survey.student_view_result]) ?>
         <?cs call:print_row(lang.survey_bar_graph.can_view_again, lang.survey_bar_graph.yes_no[survey.student_view_again]) ?>
        <?cs if:survey.num_response ?>
         <?cs call:print_row(lang.survey_bar_graph.num_response, survey.num_response) ?>
         <?cs call:print_row(lang.survey_bar_graph.num_expected_takers, survey.num_expect_takers) ?>
         <?cs call:print_row(lang.survey_bar_graph.rate, survey.rate) ?>
        <?cs /if ?>
    </table>
  </td></tr>
</table>
<?cs /def ?>







<?cs ### Defines the width of the graph in pixels.  
     ### Parameter 'n' is the number of choices in the multiple-choice question,
     ### or the number of steps in a likert question
?>

<?cs def:graph_width(n) ?><?cs set:x = n * #30 + #10 ?><?cs var:x ?><?cs /def ?>     








<?cs ### Defines the height of the graph in pixels 
     ###
?>


<?cs def:graph_height() ?>200<?cs /def ?>    






<?cs ### Defines the 'scale' of the graph.  E.g. a value
     ### of 10 means the Y axis will be labeled 0, 10, 20, etc.
?>

<?cs def:graph_scale() ?>10<?cs /def ?>







<?cs def:print_bar_graph(data) ?>
 <script language="javascript">
   var g = new Graph(<?cs call:graph_width(data.number_choices) ?>, <?cs call:graph_height() ?><?cs if:data.multi ?>,0,1<?cs /if ?>);
   g.scale = <?cs call:graph_scale() ?>;
   g.title = "<?cs var:data.question_number ?>.  <?cs var:data.title ?> <?cs if:data.multi ?> <i>(<?cs var:lang.survey_bar_graph.multi ?> <?cs var:lang.survey_bar_graph.num_response ?> <?cs var:survey.num_response ?>)</i><?cs /if ?>";
   g.xLabel = "<?cs var:lang.survey_bar_graph.xLabel ?>";
   g.yLabel = "<?cs var:lang.survey_bar_graph.yLabel ?>";

   g.addRow(<?cs each:row = data.percent ?><?cs var:row ?><?cs if:name(row) != (data.number_choices - #1) ?>, <?cs /if ?><?cs /each ?>);
   g.setXScaleValues(<?cs each:my_scale = data.XScale ?><?cs var:my_scale ?><?cs if:name(my_scale) != (data.number_choices - #1) ?>,<?cs /if ?><?cs /each ?>);
   <?cs if:data.noanswer ?>
   g.setLegend(<?cs each:ll=data.legend ?>"<?cs var:ll ?>", <?cs /each ?> "<?cs var:lang.survey_bar_graph.no_answer_label ?>");
   <?cs else ?>
   g.setLegend(<?cs each:ll=data.legend ?>"<?cs var:ll ?>"<?cs if:name(ll) != (data.number_choices - #1)?>, <?cs /if ?><?cs /each ?>);
   <?cs /if ?>
   g.setCounts(<?cs each:cc = data.count ?><?cs var:cc ?><?cs if:name(cc) != (data.number_choices - #1) ?>, <?cs /if ?><?cs /each ?>); 
   g.build();
  </script>
<?cs /def ?>
      




<?cs def:print_text(data) ?>
  <tr>
     <td><b><?cs var:data.question_number ?>. <?cs var:data.title ?></b></td>
  </tr>
  <?cs if:data.no_count ?>
   <tr>
     <td>(<?cs var:data.no_count ?> <?cs if:data.no_count == #1 ?><?cs var:lang.survey_bar_graph.person_did_not_answer ?><?cs else ?><?cs var:lang.survey_bar_graph.people_did_not_answer ?><?cs /if ?>)</td>
   </tr>
  <?cs /if ?>
  <tr><td>
  <ul>
  <?cs each:this = data.answer ?>
      <li><?cs var:this ?>  (<?cs var:data.count[name(this)] ?>)</li>
  <?cs /each ?>
 </ul>
 </td>
 </tr>
<?cs /def ?>


<?cs def:page_break(count) ?>
 <?cs if:!(count % #2) ?>
    bar_graph_pagebreak
 <?cs else ?>
    bar_graph
 <?cs /if ?>
<?cs /def ?>







<?cs ###########################
     # HTML starts here
     ###########################
?>

<?cs ### For some bizarre reason, you can't call the
     ### html_heading() function... The graphs screw
     ### up if <!DOCTYPE html ... >
     ### is included here
?>

<!--
   Manhattan version   : <?cs var:about.version ?>
   Program Name        : <?cs var:CGI.ScriptName ?>
   ClearSilver Template: <?cs var:about.cs_file ?>
   Language File(s)    : <?cs each:fname=about.lang_file ?><?cs var:fname ?>
                         <?cs /each ?>
-->
<html>
   <head>
   <title><?cs var:lang.survey_bar_graph.page_title ?></title>
   <link rel="StyleSheet" href="<?cs var:image_path ?>common.css" type="text/css" />
   <link rel="StyleSheet" href="<?cs var:image_path ?>survey.css" type="text/css" />
   <base href="<?cs var:survey.server_string ?><?cs var:image_path ?>index.html" />
   <script language="javascript" src="<?cs var:image_path ?>graph.js"></script>
</head>
<body> 

<?cs if:survey_type == "survey_module" ?>
   <?cs call:course_info() ?>
   <div>
     <a href="javascript:history.back()" title="<?cs var:lang.survey_bar_graph.back_button_title ?>">
     <img src="<?cs var:image_path ?>back_arrow.gif" alt="<?cs var:lang.survey_bar_graph.back_button_title ?>" /></a>
   </div>
   <?cs call:survey_module_info_table() ?>
<?cs else ?>
    <div>
       <a href="javascript:window.close()" title="<?cs var:lang.survey_bar_graph.closewin ?>">
       <img src="<?cs var:image_path ?>close.gif" alt="<?cs var:lang.survey_bar_graph.closewin ?>" /></a>
       <?cs call:mymanhat_www_info_table() ?>
    </div>
<?cs /if ?>



<?cs if:survey.no_data ?>
  <div class="center_msg"><?cs var:lang.survey_bar_graph.no_responses ?></div>
<?cs else ?>
    <?cs set:graphs_printed = #1 ?>
    <?cs each:ques = survey.question ?>
     <?cs if:(ques.type == "multi_choice") || (ques.type == "likert")  ?>
        <div class="<?cs call:page_break(graphs_printed) ?>">
        <?cs call:print_bar_graph(ques) ?>
        <?cs set:graphs_printed = graphs_printed + #1 ?>
         </div>
     <?cs /if ?>
    <?cs /each ?>
   
    <table>
    <?cs each:ques = survey.question ?>
     <?cs if:(ques.type == "short-answer") || (ques.type == "memo")  ?>
      <?cs call:print_text(ques) ?>
     <?cs /if ?>
    <?cs /each ?>
    </table>
<?cs /if ?>


</body>
</html>
<?cs call:runtime() ?>
