<?php
/*
  $Id: boxes.php,v 1.2 2006/07/16 05:09:34 ryu Exp $

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

  Copyright (c) 2003 osCommerce

  Released under the GNU General Public License
  
  modified for Koshoten.net2
  http://www.koshoten.net/
*/

  class listingBox {
    var $listing_parameters = 'class="listBox"';
    var $listing_row_parameters = '';
    var $listing_data_parameters = '';

    function listingBox($contents, $direct_output = false, $use_header = true) {
      $listingBox_string = '<table';
      if (tep_not_null($this->listing_parameters)) $listingBox_string .= ' ' . $this->listing_parameters;
      $listingBox_string .= '>' . "\n";

      if($use_header == true) {
        $listingBox_string .= '  <tr';
        if (tep_not_null($this->listing_row_parameters)) $listingBox_string .= ' ' . $this->listing_row_parameters;
        if (isset($contents[0]['params']) && tep_not_null($contents[0]['params'])) $listingBox_string .= ' ' . $contents[0]['params'];
        $listingBox_string .= '>' . "\n";

        if (is_array($contents[0][0])) {
          for ($x=0, $n2=sizeof($contents[0]); $x<$n2; $x++) {
            if (isset($contents[0][$x]['text']) && tep_not_null($contents[0][$x]['text'])) {
              $listingBox_string .= '    <th';
              if (isset($contents[0][$x]['params']) && tep_not_null($contents[0][$x]['params'])) {
                $listingBox_string .= ' ' . $contents[0][$x]['params'];
              } elseif (tep_not_null($this->listing_data_parameters)) {
                $listingBox_string .= ' ' . $this->listing_data_parameters;
              }
              $listingBox_string .= '>' . $contents[0][$x]['text'] . '</th>' . "\n";
            }
          }
        } else {
          $listingBox_string .= '    <th';
          if (isset($contents[0]['params']) && tep_not_null($contents[0]['params'])) {
            $listingBox_string .= ' ' . $contents[0]['params'];
          } elseif (tep_not_null($this->listing_data_parameters)) {
            $listingBox_string .= ' ' . $this->listing_data_parameters;
          }
          $listingBox_string .= '>' . $contents[0]['text'] . '</th>' . "\n";
        }

        $listingBox_string .= '  </tr>' . "\n";
        $data_start = 1;
      } else {
        $data_start = 0;
      }

      for ($i=$data_start, $n=sizeof($contents); $i<$n; $i++) {
        $listingBox_string .= '  <tr';
        if (tep_not_null($this->listing_row_parameters)) $listingBox_string .= ' ' . $this->listing_row_parameters;
        if (isset($contents[$i]['params']) && tep_not_null($contents[$i]['params'])) $listingBox_string .= ' ' . $contents[$i]['params'];
        $listingBox_string .= '>' . "\n";

        if (is_array($contents[$i][0])) {
          for ($x=0, $n2=sizeof($contents[$i]); $x<$n2; $x++) {
            if (isset($contents[$i][$x]['text']) && tep_not_null($contents[$i][$x]['text'])) {
              $listingBox_string .= '    <td';
              if (isset($contents[$i][$x]['params']) && tep_not_null($contents[$i][$x]['params'])) {
                $listingBox_string .= ' ' . $contents[$i][$x]['params'];
              } elseif (tep_not_null($this->listing_data_parameters)) {
                $listingBox_string .= ' ' . $this->listing_data_parameters;
              }
              $listingBox_string .= '>' . $contents[$i][$x]['text'] . '</td>' . "\n";
            }
          }
        } else {
          $listingBox_string .= '    <td';
          if (isset($contents[$i]['params']) && tep_not_null($contents[$i]['params'])) {
            $listingBox_string .= ' ' . $contents[$i]['params'];
          } elseif (tep_not_null($this->listing_data_parameters)) {
            $listingBox_string .= ' ' . $this->listing_data_parameters;
          }
          $listingBox_string .= '>' . $contents[$i]['text'] . '</td>' . "\n";
        }

        $listingBox_string .= '  </tr>' . "\n";
      }

      $listingBox_string .= '</table>' . "\n";

      if ($direct_output == true) echo $listingBox_string;

      return $listingBox_string;
    }
  }

  class divBox {
    var $div_parameters = '';
    var $div_header_parameters = '';
    var $div_content_parameters = '';
    var $div_data_parameters = '';
    var $div_footer_parameters = '';

    function divBox($cssid, $contents, $header = '', $footer = '', $direct_output = true) {
      // Box
      $divBox_string = '<div';
      if (tep_not_null($this->div_parameters)) $divBox_string .= ' ' . $this->div_parameters;
      if (isset($cssid) && tep_not_null($cssid)) $divBox_string .= ' id="' . $cssid . '"';
      $divBox_string .= '>' . "\n";

      // Box Header
      if (tep_not_null($header)) {
        $divBox_string .= '<h3';
        if (tep_not_null($this->div_header_parameters)) $divBox_string .= ' ' . $this->div_header_parameters;
        $divBox_string .= '>' . $header . "</h3>\n";
      }

      // Box Content
      if (is_array($contents[0][0])) {
        $divBox_string .= '<table';
        if (tep_not_null($this->div_content_parameters)) $divBox_string .= ' ' . $this->div_content_parameters;
        $divBox_string .= '>' . "\n";
        for ($i=0, $n=sizeof($contents); $i<$n; $i++) {
          $divBox_string .= '<tr>' . "\n";
          for ($x=0, $n2=sizeof($contents[$i]); $x<$n2; $x++) {
            if (isset($contents[$i][$x]['text']) && tep_not_null($contents[$i][$x]['text'])) {
              $divBox_string .= '<td';
              if (isset($contents[$i][$x]['params']) && tep_not_null($contents[$i][$x]['params'])) {
                $divBox_string .= ' ' . $contents[$i][$x]['params'];
              } elseif (tep_not_null($this->div_data_parameters)) {
                $divBox_string .= ' ' . $this->div_data_parameters;
              }
              $divBox_string .= ">\n";
              if (isset($contents[$i][$x]['form']) && tep_not_null($contents[$i][$x]['form'])) $divBox_string .= $contents[$i][$x]['form'];
              $divBox_string .= $contents[$i][$x]['text'];
              if (isset($contents[$i][$x]['form']) && tep_not_null($contents[$i][$x]['form'])) $divBox_string .= '</form>';
              $divBox_string .= '</td>' . "\n";
            }
          }
          $divBox_string .= '</tr>' . "\n";
        }
        $divBox_string .= '</table>' . "\n";
      } else {
        for ($i=0, $n=sizeof($contents); $i<$n; $i++) {
          $divBox_string .= '<div';
          if (tep_not_null($this->div_content_parameters)) $divBox_string .= ' ' . $this->div_content_parameters;
          if (isset($contents[$i]['params']) && tep_not_null($contents[$i]['params'])) $divBox_string .= ' ' . $contents[$i]['params'];
          $divBox_string .= '>' . "\n";
          if (isset($contents[$i]['form']) && tep_not_null($contents[$i]['form'])) $divBox_string .= $contents[$i]['form'] . "\n";
          $divBox_string .= $contents[$i]['text'] . "\n";
          if (isset($contents[$i]['form']) && tep_not_null($contents[$i]['form'])) $divBox_string .= '</form>' . "\n";
          $divBox_string .= '</div>' . "\n";
        }
      }

      // Box Footer
      if (tep_not_null($footer)) {
        $divBox_string .= '<div';
        if (tep_not_null($this->div_footer_parameters)) $divBox_string .= ' ' . $this->div_footer_parameters;
        $divBox_string .= '>' . $footer . "</div>\n";
      }

      $divBox_string .= "</div>\n";

      if ($direct_output == true) echo $divBox_string;

      return $divBox_string;
    }
  }
  
  class infoBox extends divBox {
    function infoBox($cssid, $contents, $header = '', $footer = '') {
      $this->div_header_parameters = 'class="infoBoxHeader"';
      $this->div_content_parameters = 'class="infoBoxContents"';
      $this->div_footer_parameters = 'class="infoBoxFooter"';
      $this->divBox($cssid, $contents, $header, $footer, true);
    }
  }

  class contentBox extends divBox {
    function contentBox($cssid, $contents, $header = '', $footer = '') {
      $this->div_header_parameters = 'class="contentBoxHeader"';
      $this->div_content_parameters = 'class="contentBoxContents"';
      $this->div_footer_parameters = 'class="contentBoxFooter"';
      $this->divBox($cssid, $contents, $header, $footer, true);
    }
  }
?>
