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

$profile_name;

class name extends attrib_base {
    function get() {
        $n = "";
        if (isset($this->submod['title']))
            $n = $n . $this->submod['title']->get() . " ";

        if (isset($this->submod['firstname']))
            $n = $n . $this->submod['firstname']->get() . " ";

        if (isset($this->submod['lastname']))
            $n = $n . $this->submod['lastname']->get() . " ";

        $n = rtrim($n);
        $n = ltrim($n);

        return $n;
    }

    function set($c) {
        // you don't set name directly. you set the subclass
        // maybe in future we will do it so it will set the subclass
        // intelligently
        return 0;
    }

    function save($fh,$indent) {
        fwrite($fh,$this->opml_outline_profile("name",$indent));
        $this->module_invoke_sub("attrib_base","save",$fh,$indent+1);
        fwrite($fh,$this->opml_outline_end("name",$indent));
    }

    function element_start($parser,$name,$attribs) {
        $this->module_invoke_sub("attrib_base","element_start",
            $parser,$name,$attribs);

        if (strtolower($attribs['TEXT']) != "name") return;
        if (!isset($GLOBALS['profile_load'])) return;

        $id    = $attribs['ID'];
        $value = $attribs['VALUE'];

        $GLOBALS['profile_name'] =& $GLOBALS['profile_load']->add_attrib(
                            "name", array( 'name'  => $value ), $id);
    }

    function element_end($parser,$name) {
        $this->module_invoke_sub("attrib_base","element_end",$parser,$name);

        if (strtolower($attribs['TEXT']) != "name") return;

        unset($GLOBALS['profile_name']);
    }

    function get_help($type) {
        if ($type == 'long')
            return "Enter the name or alias you choose to associate yourself with others.";

        if ($type == 'short')
            return "Name: <i>e.g. James Seng</i>";

        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());

        if (isset($this->submod['title']))
            $title = $this->submod['title']->html_form_profile()."&nbsp;";

        if (isset($this->submod['firstname']))
            $first = $this->submod['firstname']->html_form_profile()."&nbsp;";
            
        if (isset($this->submod['lastname']))
            $last = $this->submod['lastname']->html_form_profile()."&nbsp;";

        $id = $this->getid();

        $str = <<<_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>
    $title $first $last
    </td>
  </tr>

_HTML_FORM_PROFILE_;
        return $str;
    }

    function foaf_profile($fn) {
        $name = $this->get();
        $this->module_invoke_sub("attrib_base","foaf_profile",$fn);
        fwrite($fn,"  <foaf:name>$name</foaf:name>\n");
    }
}

?>
