<?/*
Copyright (C) 2003 Media Net Link, Inc. Danville, CA 94526 USA

This file is part of AthenaRMS.

AthenaRMS is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

AthenaRMS is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/?>
<?php

require_once 'base_object.php';
require_once 'server_functions.php';

class HTML extends Base_Object {

  function HTML () {
    $this->Set_Edit_Flag (1);
  }

  function set_match ($match='') {
    $this->match = $match;
  }

  function Set_Edit_Flag ($edits) {
    if (!$edits) {
      $this->edit_flag = 0;
    } else {
      $this->edit_flag = 1;
    }
  }

  function Editable () {
    notices_off();
    $bool = ($this->edit_flag or !isset($this->edit_flag));
    notices_on();

    return $bool;
  }

  function generate_option ($val, $disp='') {
    if (!$disp) $disp = $val;

    $html_val = htmlentities ($val);
    $disp = htmlentities ($disp);
    $html = '';

    if ($val == $this->match) {
      if ($this->Editable () or !isset($this->edit_flag)) {
        $html .= '  <option value="'.$html_val.'" selected="selected">'.$disp."</option>\n";
      } else {
        $html .= $disp."\n";
      }
    ## should be just else?
    } elseif ($this->Editable () or !isset($this->edit_flag)) {
      $html .= '  <option value="'.$html_val.'">'.$disp."</option>\n";
    }

    return $html;
  }

  function Array_Drop_Down ($ary, $match='') {
    $this->set_match ($match);
    $html = '';

    foreach ($ary as $v) {
      $html .= $this->generate_option ($v);
    }

    return $html;
  }

  function Multi_Array_Drop_Down ($ary, $match='') {
    $this->set_match ($match);
    $html = '';

    foreach ($ary as $rec) {
      $html .= $this->generate_option ($rec[0], $rec[1]);
    }

    return $html;
  }

  function Multi_Array_Drop_Down_Omit_Vals ($ary, $match='', $omit_ary) {
    $this->set_match ($match);
    $html = '';

    foreach ($ary as $rec) {
      if (in_array ($rec[0], $omit_ary)) continue;

      $html .= $this->generate_option ($rec[0], $rec[1]);
    }

    return $html;
  }

  function Query_String($ary) {
    $result = array();

    foreach ($ary as $key => $val) {
      if (is_array($val)) {
	foreach ($val as $item) {
	  array_push($result, urlencode($key) . '[]=' . urlencode($item));
	}
      } else {
	array_push($result, urlencode($key) . '=' . urlencode($val));
      }
    }

    return join(ini_get('arg_separator.output'), $result);
  }

}
?>
