<?php
/*
  $Id: countries.php,v 1.28 2003/06/29 22:50:51 hpdl Exp $

  osCommerce, Open Source E-Commerce Solutions
  http://www.oscommerce.com

  Copyright (c) 2003 osCommerce

  Released under the GNU General Public License
*/

  require('includes/application_top.php');

  $action = (isset($HTTP_GET_VARS['action']) ? $HTTP_GET_VARS['action'] : '');

  if (tep_not_null($action)) {
    switch ($action) {
      case 'insert':
        $method_name = tep_db_prepare_input($HTTP_POST_VARS['method_name']);
        $is_active = tep_db_prepare_input($HTTP_POST_VARS['is_active']);
        if($method_name)tep_db_query("insert into heard_about (method, active) values ('" . tep_db_input($method_name) . "', '" . (int)$is_active . "')");
        tep_redirect(tep_href_link(FILENAME_HEARDABOUT));
        break;
      case 'save':
        $method_id = tep_db_prepare_input($HTTP_GET_VARS['method_id']);
        $method_name = tep_db_prepare_input($HTTP_POST_VARS['method_name']);
        $is_active = tep_db_prepare_input($HTTP_POST_VARS['is_active']);
        if($method_name)tep_db_query("update heard_about set method = '" . tep_db_input($method_name) . "', active = '" . (int)$is_active . "' where method_id = '" . (int)$method_id . "'");
        tep_redirect(tep_href_link(FILENAME_HEARDABOUT, 'page=' . $HTTP_GET_VARS['page'] . '&method_id=' . $method_id));
        break;
    }
  }
?>
<!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/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>
    <td width="<?php echo BOX_WIDTH; ?>" valign="top"><table border="0" width="<?php echo BOX_WIDTH; ?>" cellspacing="1" cellpadding="1" class="columnLeft">
<!-- left_navigation //-->
<?php require(DIR_WS_INCLUDES . 'column_left.php'); ?>
<!-- left_navigation_eof //-->
    </table></td>
<!-- 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="0">
          <tr>
            <td class="pageHeading"><?php echo HEADING_TITLE; ?></td>
            <td class="pageHeading" align="right"><?php echo tep_draw_separator('pixel_trans.gif', HEADING_IMAGE_WIDTH, HEADING_IMAGE_HEIGHT); ?></td>
          </tr>
        </table></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 class="dataTableHeadingContent" align="left"><?php echo TABLE_HEADING_METHOD_NAME; ?></td>
                <td class="dataTableHeadingContent" align="right"><?php echo TABLE_HEADING_CUSTOMERS; ?>&nbsp;</td>
                <td class="dataTableHeadingContent" align="right">&nbsp;</td>
              </tr>
              <tr class="dataTableRow" onmouseover="rowOverEffect(this)" onmouseout="rowOutEffect(this)">
                <td class="dataTableContent"><?php echo TABLE_DATA_NOT_SPECIFIED; ?></td>
                <td class="dataTableContent" align="right" width="40"><?php 
                $m = 0;
                $method_sql = "select customers_id from " . TABLE_CUSTOMERS . " where heard_method_id = '' or heard_method_id is null";
                $method_qry = tep_db_query($method_sql);
                while ($mcount = tep_db_fetch_array($method_qry)) {
                 $m++;
                }
               print max($m,0);
                ?>&nbsp;</td>
                <td class="dataTableContent" align="right">&nbsp;</td>
              </tr>
<?php
  $rows = 1;
  $heard_methods = "select * from " . TABLE_HEARDABOUT . " order by method";
  $heard_query = tep_db_query($heard_methods);
  while ($heard = tep_db_fetch_array($heard_query)) {
    if ((!isset($HTTP_GET_VARS['method_id']) || (isset($HTTP_GET_VARS['method_id']) && ($HTTP_GET_VARS['method_id'] == $heard['method_id']))) && !isset($mInfo) && (substr($action, 0, 3) != 'new')) {
      $mInfo = new objectInfo($heard);
    }
    if (isset($mInfo) && is_object($mInfo) && ($heard['method_id'] == $mInfo->method_id)) {
      echo '                  <tr id="defaultSelected" class="dataTableRowSelected" onmouseover="rowOverEffect(this)" onmouseout="rowOutEffect(this)" onclick="document.location.href=\'' . tep_href_link(FILENAME_HEARDABOUT, 'page=' . $HTTP_GET_VARS['page'] . '&method_id=' . $mInfo->method_id . '&action=edit') . '\'">' . "\n";
    } else {
      echo '                  <tr class="dataTableRow" onmouseover="rowOverEffect(this)" onmouseout="rowOutEffect(this)" onclick="document.location.href=\'' . tep_href_link(FILENAME_HEARDABOUT, 'page=' . $HTTP_GET_VARS['page'] . '&method_id=' . $heard['method_id']) . '\'">' . "\n";
    }
?>
                <td class="dataTableContent"><?php echo $heard['method']; ?></td>
                <td class="dataTableContent" align="right" width="40"><?php 
                $m = 0;
                $method_sql = "select customers_id from " . TABLE_CUSTOMERS . " where heard_method_id = " . $heard['method_id'];
                $method_qry = tep_db_query($method_sql);
                while ($mcount = tep_db_fetch_array($method_qry)) {
                 $m++;
                }
               print max($m,0);
                ?>&nbsp;</td>
                <td class="dataTableContent" align="right"><?php if (isset($mInfo) && is_object($mInfo) && ($heard['method_id'] == $mInfo->method_id) ) { echo tep_image(DIR_WS_IMAGES . 'icon_arrow_right.gif', ''); } else { echo '<a href="' . tep_href_link(FILENAME_HEARDABOUT, 'page=' . $HTTP_GET_VARS['page'] . '&method_id=' . $heard['method_id']) . '">' . tep_image(DIR_WS_IMAGES . 'icon_info.gif', IMAGE_ICON_INFO) . '</a>'; } ?>&nbsp;</td>
              </tr>
<?php
  }
?>
              <tr>
                <td colspan="4"><table border="0" width="100%" cellspacing="0" cellpadding="2">
<?php
  if (empty($action)) {
?>
                  <tr>
                    <td colspan="2" align="right"><?php echo '<a href="' . tep_href_link(FILENAME_HEARDABOUT, 'page=' . $HTTP_GET_VARS['page'] . '&action=new') . '">' . tep_image_button('button_new_method.gif', '') . '</a>'; ?></td>
                  </tr>
<?php
  }
?>
                </table></td>
              </tr>
            </table></td>
<?php
  $heading = array();
  $contents = array();

  switch ($action) {
    case 'new':
      $heading[] = array('text' => '<b>' . TEXT_INFO_HEADING_NEW_METHOD . '</b>');

      $contents = array('form' => tep_draw_form('heard_methods', FILENAME_HEARDABOUT, 'page=' . $HTTP_GET_VARS['page'] . '&action=insert'));
      $contents[] = array('text' => TEXT_INFO_INSERT_INTRO);
      $contents[] = array('text' => '<br>' . TEXT_INFO_METHOD_NAME . ':&nbsp;<br>' . tep_draw_input_field('method_name'));
      $contents[] = array('text' => '<br>' . TEXT_INFO_ACTIVE . ':&nbsp;<br>' . tep_draw_pull_down_menu('is_active', array(array('id'=>'1','text'=>'Yes'),array('id'=>'','text'=>'No')), $mInfo->active));
      $contents[] = array('align' => 'center', 'text' => '<br>' . tep_image_submit('button_insert.gif', IMAGE_INSERT) . '&nbsp;<a href="' . tep_href_link(FILENAME_HEARDABOUT, 'page=' . $HTTP_GET_VARS['page']) . '">' . tep_image_button('button_cancel.gif', IMAGE_CANCEL) . '</a>');
      break;
    case 'edit':
      $heading[] = array('text' => '<b>' . TEXT_INFO_HEADING_EDIT_METHOD . '</b>');

      $contents = array('form' => tep_draw_form('heard_methods', FILENAME_HEARDABOUT, 'page=' . $HTTP_GET_VARS['page'] . '&method_id=' . $mInfo->method_id . '&action=save'));
      $contents[] = array('text' => 'Edit the method');
      $contents[] = array('text' => '<br>' . TEXT_INFO_METHOD_NAME . ':&nbsp;<br>' . tep_draw_input_field('method_name', $mInfo->method));
      $contents[] = array('text' => '<br>' . TEXT_INFO_ACTIVE . ':&nbsp;<br>' . tep_draw_pull_down_menu('is_active', array(array('id'=>'1','text'=>'Yes'),array('id'=>'','text'=>'No')), $mInfo->active));
      $contents[] = array('align' => 'center', 'text' => '<br>' . tep_image_submit('button_update.gif', IMAGE_UPDATE) . '&nbsp;<a href="' . tep_href_link(FILENAME_HEARDABOUT, 'page=' . $HTTP_GET_VARS['page'] . '&method_id=' . $mInfo->method_id) . '">' . tep_image_button('button_cancel.gif', IMAGE_CANCEL) . '</a>');
      break;
    default:
      if (is_object($mInfo)) {
        $heading[] = array('text' => '<b>' . $mInfo->method . '</b>');

        $contents[] = array('align' => 'center', 'text' => '<a href="' . tep_href_link(FILENAME_HEARDABOUT, 'page=' . $HTTP_GET_VARS['page'] . '&method_id=' . $mInfo->method_id . '&action=edit') . '">' . tep_image_button('button_edit.gif', IMAGE_EDIT) . '</a>');
        $contents[] = array('text' => '<br>' . TEXT_INFO_METHOD_NAME . ':&nbsp;' . $mInfo->method);
        $contents[] = array('text' => '<br>' . TEXT_INFO_ACTIVE . ':&nbsp;' . ($mInfo->active?'Yes':'No'));
      }
      break;
  }

  if ( (tep_not_null($heading)) && (tep_not_null($contents)) ) {
    echo '            <td width="25%" valign="top">' . "\n";

    $box = new box;
    echo $box->infoBox($heading, $contents);

    echo '            </td>' . "\n";
  }
?>
          </tr>
        </table></td>
      </tr>
    </table></td>
<!-- body_text_eof //-->
  </tr>
</table>
<!-- body_eof //-->

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