<?php
#
# Copyright 2003 James Seng. See LICENSE for the Software License.
#

class attrib_base extends module_base {
    var $id;
    var $container;

    function getid() {
        return $this->id;
    }

    function setid($id) {
        $this->id = $id;
    }

    function assignid() {
        global $config;

        $id = $config->get('ID');
        $id++;
        $this->id = $id;
        $config->set('ID',$id);
        return $id;
    }

    function get() {
        return $this->container;
    }

    function set($c) {
        $this->container = $c;
    }

    function init_attrib($arr,$id) {
        global $modules;

        $name = get_class($this);
        if (!isset($modules[$name])) return 0;
        if (get_parent_class($modules[$name]) != "attrib_base") return 0;
        //$this->class = $modules[$name]->class;

        $this->setid($id);
        if (isset($arr[$name])) $this->set($arr[$name]);

        if (isset($modules[$name]->submod)) {
            foreach ($modules[$name]->submod as $subatt => $v) {
                $this->submod[$subatt] = new $subatt;
                $this->submod[$subatt]->init_attrib($arr,$id);
            }
        }
    }

    function deinit_attrib() {
        if (!isset($this->submod)) return 0;
        foreach ($this->submod as $subatt => $v) {
            $this->submod[$subatt]->deinit_attrib();
            unset($this->submod[$subatt]);
        }
    }

    function parse_request() {
        $this->module_invoke_sub("attrib_base","parse_request");
        $name = get_class($this).$this->getid();
        if (!isset($_REQUEST[$name])) return;
        $this->set($_REQUEST[$name]);
    }

    function opml_outline_profile($type, $indent = 2) {
        $container = htmlspecialchars($this->get());
        $type = htmlspecialchars(get_class($this));
        $id = $this->getid();
        $space1 = str_pad("",$indent*2);
        return "$space1<outline text=\"$type\" id=\"$id\" value=\"$container\">\n";
    }

    function get_help() {
        return get_class($this);
    }

    function html_form_profile() {
        $short = firstupper($this->get_help('short'));
        $help = $this->get_help('long');
        $type = htmlspecialchars(get_class($this));
        $get = htmlspecialchars($this->get());
        $id = $this->getid();

        return <<<_HTML_FORM_PROFILE_
<tr>
  <td valign="middle" width="20">
    <input type="checkbox" name="_$id">
  <td valign="middle" width="250" align="left">
    <font class="help">$help</font>
    </td>
  <td valign="top" align="left">
    <font class="title">$short</font><br>
    <input class="text" name="$type$id" value="$get">
    </td>
  </tr>

_HTML_FORM_PROFILE_;
    }

    function xmlrpc_profile() {
        $class = get_class($this);
        $data = $this->get();
        return new xmlrpcval(
            array($class => new xmlrpcval($data, "string")),"struct");
    }
}

?>
