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




<?cs def:print_title(title) ?>
 <tr><td colspan="2">
 <div class="survey_title_box">
 <div class="survey_title">
   <?cs var:title.content ?>
 </div>
 </div>
 </td></tr>
<?cs /def ?>







<?cs def:print_empty_row() ?>
  <tr><td colspan="2">&nbsp;</td></tr>
<?cs /def ?>







<?cs def:print_question(data, number) ?>
 <tr>
  <td colspan="2" class="question">
   <span class="bold_num"><?cs var:number ?>. </span> <?cs var:data.content ?>
  </td>
 </tr>
<?cs /def ?>








<?cs def:print_likert(question) ?>
  <?cs call:print_question(question, question.order) ?>
  <tr>
    <td>&nbsp;&nbsp;</td>
    <td>
      <table>
         <tr>
           <td class="sub_ques"><?cs var:question.left_value ?>
             <?cs loop:x = #1, question.steps, #1 ?>
              <input type="radio" name="<?cs var:question.id ?>" value="<?cs var:x ?>" />
             <?cs /loop ?>
             <?cs var:question.right_value ?>
          </td>
       </tr>
     </table>
   </td>
 </tr>
 <?cs call:print_empty_row() ?>
<?cs /def ?>







<?cs def:print_memo(question) ?>
  <?cs call:print_question(question, question.order) ?>
  <tr>
     <td>&nbsp;&nbsp;</td>
     <td>
       <textarea cols="<?cs var:question.cols ?>" rows="<?cs var:question.rows ?>" name="<?cs var:question.id ?>"></textarea>
     </td>
   </tr>
 <?cs call:print_empty_row() ?>
<?cs /def ?>






<?cs def:print_text(question) ?>
  <?cs call:print_question(question, question.order) ?>
  <tr>
   <td>&nbsp;&nbsp;</td>
   <td><input type="text" name="<?cs var:question.id ?>" /></td>
  </tr>
 <?cs call:print_empty_row() ?>
<?cs /def ?>






<?cs def:print_custom(data) ?>
 <tr>
  <td colspan="2" class="question">
    <?cs var:data.content ?>
  </td>
 </tr>
 <?cs call:print_empty_row() ?>
<?cs /def ?>






<?cs def:print_choice(question) ?>
  <?cs call:print_question(question, question.order) ?>
  <?cs set:x = 1 ?>
  <?cs each:mychoice = question.choice ?>
  <tr><td>&nbsp;&nbsp;</td>
      <td class="sub_ques">
      <?cs if:question.multi == "yes" ?>
        <input type="checkbox" name="<?cs var:question.id ?>" value="<?cs var:x ?>" /><?cs var:mychoice ?>
      <?cs else ?> 
	<input type="radio" name="<?cs var:question.id ?>" value="<?cs var:x ?>" /><?cs var:mychoice ?>
      <?cs /if ?> 
	</td>
 </tr>
 <?cs set:x = x + #1 ?>
 <?cs /each ?>
 <?cs call:print_empty_row() ?>
<?cs /def ?>

 





<?cs def:show_survey() ?>
<table width="100%">
  <tr><td align="center">
  <table>
<?cs each:element = item ?>
    <?cs if:element.type == "heading" ?> 
      <?cs call:print_title(element) ?>
    <?cs elif:element.type == "multi-choice" ?>
      <?cs call:print_choice(element) ?>
    <?cs elif:element.type == "likert" ?>
      <?cs call:print_likert(element) ?>
    <?cs elif:element.type == "memo" ?>
      <?cs call:print_memo(element) ?>
    <?cs elif:element.type == "short-answer" ?>
      <?cs call:print_text(element) ?>
    <?cs elif:element.type == "custom" ?>
      <?cs call:print_custom(element) ?>
   <?cs /if ?>
 <?cs /each ?>
 </table>
</td></tr>
</table>
<?cs /def ?>





<?cs def:handle_take_classroom_delivered() ?>
  <?cs if:allow_submit == #0 ?>
     <?cs if:is_faculty ?>
         <body onload="alert('<?cs var:lang.survey_page.teacher_cannot_submit ?>')">
     <?cs else ?>
         <body onload="alert('<?cs var:lang.survey_page.student_already_took_survey ?>')">
     <?cs /if ?>
     <form>
  <?cs else ?>
     <body>  
     <form method="post" action="survey_class_submit" onsubmit="return window.confirm('<?cs var:lang.survey_page.submit_confirmation ?>')" >
     <div>
      <input type="hidden" name="crs" value="<?cs var:Query.crs ?>" />
      <input type="hidden" name="id" value="<?cs var:Query.id ?>" />
      <input type="hidden" name="inf" value="<?cs var:Query.inf ?>" />
      <input type="hidden" name="sender" value="<?cs var:Query.sender ?>" />
      </div>
  <?cs /if ?>

  <?cs call:show_survey() ?>
 
   <?cs if:allow_submit == #1 ?>
      <div class="center_msg">
        <input type="submit" value="<?cs var:lang.survey_page.submit ?>" />
       </div>
   <?cs /if ?>
<?cs /def ?>






<?cs def:handle_take_mymanhattan() ?>
<?cs if:allow_submit == #0 ?>
     <body onload="alert('<?cs var:lang.survey_page.right_to_submit ?>')">
<?cs else ?>
<body>
<?cs /if ?>

<?cs if:Query.mode != 0 ?>   <?cs ## see notes on Query.mode below ### ?>
<?cs ### insert skip this survey button #### ?>
  <div>
  <form method="post" action="survey_clean_up" onsubmit="return window.confirm('<?cs var:lang.survey_page.skip_survey_confirmation ?>')">
  <div>
    <input type="hidden" name="id" value="<?cs var:Query.id ?>" />
    <input type="hidden" name="count" value="<?cs var:Query.count ?>" />
  </div>
  <div class="center_msg">
    <input type="submit" value="<?cs var:lang.survey_page.skip_survey_button ?>" title="<?cs var:lang.skip_survey_button_title ?>"  />
  </div>
  </form>
   </div>
<?cs /if ?>

<?cs ## start survey form ?>
  <div>
  <form method="post" action="survey_submit" 
         onsubmit="return window.confirm('<?cs if:Query.mode== 0 ?><?cs var:lang.survey_page.not_intended_for_teachers ?><?cs else ?><?cs var:lang.survey_page.submit_confirmation ?><?cs /if ?>')" >
  <input type="hidden" name="id" value="<?cs var:Query.id ?>" />
  <input type="hidden" name="crs" value="<?cs var:Query.crs ?>" />
  <input type="hidden" name="mode" value="<?cs var:Query.mode ?>" />
  <input type="hidden" name="count" value="<?cs var:Query.count ?>" />

 <?cs call:show_survey() ?>
  <?cs if:allow_submit == #1 ?>
   <div class="center_msg">
    <input type="submit" value="<?cs var:lang.survey_page.submit ?>" />
  </div>
 <?cs /if ?>
  </form>
  </div>
<?cs /def ?>




<?cs def:handle_preview() ?>
<body>
  <div>
   <form method="post" action="survey_submit" onsubmit="return window.confirm('<?cs var:lang.survey_page.preview_confirmation ?>')" >
   <div>
   <input type="hidden" name="id" value="<?cs var:Query.id ?>" />
   <input type="hidden" name="crs" value="<?cs var:Query.crs ?>" />
   <input type="hidden" name="mode" value="<?cs var:Query.mode ?>" />
   <input type="hidden" name="count" value="<?cs var:Query.count ?>" />
   </div>

    <?cs call:show_survey() ?>

   </form>
   </div>

 <?cs if:!Query.username ?>
   <div class="center_msg">
     <form action="">
      <div><input type="button" value="<?cs var:lang.survey_page.window_close ?>" onclick="window.close()" /></div>
     </form>
   </div>
 <?cs /if ?>
<?cs /def ?>






<?cs def:handle_web_delivered() ?>
<body>
<div><form method="post" action="survey_www_submit" >
<input type="hidden" name="id" value="<?cs var:Query.id ?>" />

 <?cs call:show_survey() ?>

<div class="center_msg">
    <input type="submit" value="<?cs var:lang.survey_page.submit ?>" />
</div>

</form></div>
<?cs /def ?>








<?cs call:html_heading() ?>
<head>
      <title><?cs var:lang.survey_page.page_title ?></title>
   <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
   <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"  />
   <style type="text/css">
     body { background-color: <?cs var:bgcolor ?>; }
   </style>
</head>

	


<?cs ##### VALUES for Query.mode  

    0 - Survey was delivered via My Manhattan page, and the survey has been configured so teachers can
        only view the survey (i.e. the results are not saved), and this is a teacher viewing the survey.

    1 - User is taking survey from MyManhattan.

    2 - User is taking a survey delivered via the web (outside of Manhattan environment)

    3 - User is taking a survey delivered within a classroom's Surveys module

    4 - User is PREVIEWING either a PUBLIC or WEB DELIVERED survey

    5 - User is PREVIEWING a PRIVATE survey
############  ?>


<?cs if:(Query.mode == 0) || (Query.mode == 1) ?>
   <?cs call:handle_take_mymanhattan() ?>
<?cs elif:Query.mode == 2 ?>
   <?cs call:handle_web_delivered() ?>
<?cs elif:Query.mode == 3 ?>   
   <?cs call:handle_take_classroom_delivered() ?>
<?cs elif:(Query.mode == 4) || (Query.mode == 5) ?>
   <?cs call:handle_preview() ?>
<?cs /if ?>


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