<?php

/*

  osCommRes, Services Online
  http://www.oscommres.com

  Copyright (c) 2005 osCommRes

  Released under the GNU General Public License
  
  Freeway eCommerce from ZacWare
http://www.zac-ware.com/freeway

Copyright 2007 ZacWare Pty. Ltd
*/

  require('includes/application_top.php');
  
  // get the type of action
  $action = (isset($HTTP_GET_VARS['action']) ? $HTTP_GET_VARS['action'] : '');


?>
<!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN">
<html <?php echo HTML_PARAMS; ?>>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=<?php echo CHARSET; ?>">
<title><?php echo TITLE; ?></title>
<link rel="stylesheet" type="text/css" href="includes/stylesheet.css">
<script language="javascript" src="includes/menu.js"></script>
<script language="javascript" src="includes/general.js"></script>
</head>
<body marginwidth="0" marginheight="0" topmargin="0" bottommargin="0" leftmargin="0" rightmargin="0" bgcolor="#FFFFFF" onLoad="SetFocus();">
<!-- header //-->
<?php require(DIR_WS_INCLUDES . 'header.php'); ?>
<!-- header_eof //-->
<!-- body //-->
<table border="0" width="100%" cellspacing="2" cellpadding="2">
	<tr> 
		<!-- body_text //-->
		<td width="100%" valign="top">
		<table border="0" width="100%" cellspacing="0" cellpadding="2">
    <tr><td><table border="0" width="100%" cellspacing="0" cellpadding="2">
	      <tr>
		<td><table border="0" width="100%" cellspacing="0" cellpadding="0">
		  <tr><td class="pageHeading"><?php echo HEADING_TITLE ; ?></td></tr>
		</table></td>
	      </tr>
    	      <tr><td><?php echo tep_draw_separator('pixel_trans.gif', '2', '10'); ?></td></tr>
              <tr>
        	<td><table border="0" width="100%" cellspacing="0" cellpadding="0">
          	<tr>
            	   <td valign="top"><table border="0" width="100%" cellspacing="0" cellpadding="2">
                       <tr class="dataTableHeadingRow">
	                     <td>
			     <td class="dataTableHeadingContent" width=100><?php echo TABLE_HEADING_TITLE; ?></td>
			     <td class="dataTableHeadingContent" align="left"><?php echo TABLE_HEADING_DESCRIPTION; ?></td>
			     <td class="dataTableHeadingContent" align="left"><?php echo TABLE_HEADING_ANSWER; ?>&nbsp;</td>
		             <td>
                       </tr>
<script language=javascript>
function validateForm(){
  var error_result="";
  if (document.pop_questions.question_title.value.length<=0){
      error_result="<?php echo TEXT_ERR_NULL_QUESTION_TITLE; ?>";}
  else if (document.pop_questions.question_description.value.length<=0){
      error_result="<?php echo TEXT_ERR_NULL_QUESTION_DESC; ?>";}

  if (error_result!=""){
     alert(error_result);
     return false;
  }
  return true;
}
</script>
<?php
    echo tep_draw_form('pop_questions',FILENAME_POP_QUESTIONS,'action=update','post','onSubmit="return validateForm()"');
    $question_count = 0;

    $question_query=tep_db_query("select question_id,question_title,question_description,answer_type from " . TABLE_POP_QUESTIONS . ' order by question_title');

    $question_array=array();
    $question_array[]=array('id'=>'T','text'=>'Text');
    $question_array[]=array('id'=>'N','text'=>'Number');    
    $question_array[]=array('id'=>'D','text'=>'Date');
    
    while ($questions = tep_db_fetch_array($question_query)) {
      $question_count++;
      $rows++;
      if ($question_id==0) $question_id=$questions['question_id'];
      if ($questions['question_id'] == $question_id){
         $select_question_title=$questions['question_title'];
	 $select_question_description=$questions['question_description'];
	 $select_answer_type=$questions['answer_type'];
        }
	  
      if ($questions['question_id'] == $question_id) {
        echo '              <tr id="defaultSelected" class="dataTableRowSelected" onmouseover="rowOverEffect(this)" onmouseout="rowOutEffect(this)" onclick="">';
	$selected=true;
      } else {
        echo '              <tr class="dataTableRow" onmouseover="rowOverEffect(this)" onmouseout="rowOutEffect(this)" onClick="document.location.href=\'' . tep_href_link(FILENAME_POP_QUESTIONS,'qID=' . $questions['question_id']) . '\'">';
	$selected=false;
      }
      if ($questions['answer_type']=='T')
         $qtype='Text';
      elseif ($questions['answer_type']=='N')
         $qtype="Number";
      else
         $qtype="Date";
      echo "<td class='dataTableContent'>" . tep_draw_radio_field('question_id',$questions['question_id'],'','',$selected) . '</td>';
      echo "<td class='dataTableContent'>" . $questions['question_title'] . '</td>';
      echo "<td class='dataTableContent'>" . $questions['question_description'] . '</td>';      
      echo "<td class='dataTableContent'>" . $qtype . '</td>';
      } ?>
	  <tr><td><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td></tr>
	  <tr>
<script language=javascript>
function doProcess(ldata)
{
 if (ldata==1)
     document.pop_questions.update_action.value="insert_pop_question";
 else
     document.pop_questions.update_action.value="update_pop_question";
 document.pop_questions.submit;
}
</script>
              <td>
	      <td><?php echo tep_draw_input_field('question_title',$select_question_title,'size=40');?>
	      <td><?php echo tep_draw_input_field('question_description',$select_question_description,'size=60');?>
	      <td><?php echo tep_draw_pull_down_menu('answer_type',$question_array,$select_answer_type); ?>
	      <input type=hidden name='update_action' id='process_value'>
           </table></td></tr>
    	   <tr><td><?php echo tep_draw_separator('pixel_trans.gif', '2', '10'); ?></td></tr>
                  <tr><td><table border="0" width="100%" cellspacing="0" cellpadding="5">
                  <tr>
                    <td class="smallText" align=left>
		    <?php
	              echo tep_image_submit('button_new.gif',IMAGE_NEW,"onClick='doProcess(1)'");
		         if ($question_count>0 && $question_id!=0)
			 {
			    echo "<td align=right>";
			    echo tep_image_submit('button_update.gif',IMAGE_BUTTON_UPDATE,"onClick='doProcess(2)'") . tep_draw_separator('pixel_trans.gif', '5', '1');
			    echo "<a href='" . tep_href_link(FILENAME_POP_QUESTIONS,"&action=delete_pop_question&qID=" . $question_id) . "'>" . tep_image_button('button_delete.gif',IMAGE_BUTTON_DELETE) . "</a>";
			 }
		      ?>
                  </tr></form>
		  <tr>
			<td><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
		  </tr>
                </table></td>
              </tr>
            </table></td>
          </tr>
        </table></td>
      </tr>
    </table>
    </td>
<!-- body_text_eof //-->
  </tr>
</table>
<!-- body_eof //-->

<!-- footer //-->
<?php require(DIR_WS_INCLUDES . 'footer.php'); ?>
<!-- footer_eof //-->
</body>
</html>
<?php require(DIR_WS_INCLUDES . 'application_bottom.php'); ?>