Scott M. Mcdermott

UNIX Systems & Network Administrator
available for contract or salaried positions

inputs.php

<?

/*
 * This file consists of things which use HTML inputs for display (and
 * optionally, input as well).  Any page using these routines will want to
 * include this file.
 */

/*
 * Each text input in the table appears this long.  Actual max length for the
 * input string is a parameter into the display method.  Each text input
 * displays at the same length for uniformity (to avoid ragged-edge appearance
 * on the page).
 */
define("INPUTLEN", 40);

/*
 * Each attribute we display (whether we can modify it or not) uses an input,
 * for display of this page.  Each input consists of a class which tells name
 * of the data as displayed for the user, the name of the data required to get
 * the information out of LDAP, and whether or not the data is modifiable by
 * the user (or used just for display purposes)
 */
class input
{
        var $name;
        var $ldapattr;
        var $readonly;
}

/*
 * Most of our data are just simple strings.
 */
class text_input
extends input
{
        var $maxlen;
        var $chkfuncs;
        var $multival;
        var $nodelete;
        var $displayfunc;
        var $modfunc;
        var $prefix;
        var $helplink;

        function
        text_input ($name, $ldapattr, $readonly, $multival, $nodelete,
                    $maxlen, $chkfuncs, $displayfunc, $modfunc, $prefix,
                    $helplink)
        {
                $this->name             = $name;
                $this->multival         = $multival;
                $this->ldapattr         = $ldapattr;
                $this->readonly         = $readonly;
                $this->nodelete         = $nodelete;
                $this->maxlen           = $maxlen;
                $this->chkfuncs         = $chkfuncs;
                $this->displayfunc      = $displayfunc;
                $this->modfunc          = $modfunc;
                $this->prefix           = $prefix;
                $this->helplink         = $helplink;
        }

        function
        display ($arg)
        {
                $displayfunc = $this->displayfunc;
                $arg = $displayfunc($arg);
                for ($i = 0; $i < sizeof($arg); $i++) {
?>                      <tr>
                        <td valign=top>
                        <input type=text size="<?echo(INPUTLEN)?>"
                                maxlength="<?echo($this->maxlen)?>"
                                name="submitvals[<?echo($this->name)?>][<?echo($i)?>]"
                                value="<?echo($arg[$i])?>"
<?                              if ($this->readonly)
                                        echo("readonly");
?>                      >
                        </td>


                        <td valign=top>
<?                      if ($this->readonly || $this->nodelete)
                                echo("&nbsp;");
                        else {
?>                              <input
                                        type=submit
                                        name="what[<?echo($this->name)?>][<?echo($i)?>]"
                                        value=delete
                                >
<?                      }
?>                      </td>

                        </tr>
<?              }
                if ($this->multival) {
?>                      <tr>
                        <td valign=top>
                        <input type=text size="<?echo(INPUTLEN)?>"
                                maxlength="<?echo($this->maxlen)?>"
                                name="submitvals[<?echo($this->name)?>][<?echo($i)?>]"
                                value=""
                        >
                        </td>

                        <td colspan=2 valign=top align=left>
                        <input
                                type=submit
                                name="what[<?echo($this->name)?>][<?echo($i)?>]"
                                value=add
                        >
                        </td>
<!--                    <td> &nbsp; </td> -->
                        </tr>
<?              }
        }
}

/*
 * Radio inputs are used for things like employment status for which multiple
 * values would not make sense.
 */
class radio_input
extends input
{
        var $buttons;
        var $chkfuncs;
        var $displayfunc;
        var $modfunc;
        var $prefix;
        var $helplink;

//      var $nbuttons;

        function
        radio_input ($name, $ldapattr, $readonly, $buttons,
                     $chkfuncs, $displayfunc, $modfunc, $prefix, $helplink)
        {
                $this->name             = $name;
                $this->ldapattr         = $ldapattr;
                $this->readonly         = $readonly;
                $this->buttons          = $buttons;
                $this->chkfuncs         = $chkfuncs;
                $this->displayfunc      = $displayfunc;
                $this->modfunc          = $modfunc;
                $this->prefix           = $prefix;
                $this->helplink         = $helplink;
        }

        function
        display ($arg)
        {
                $displayfunc = $this->displayfunc;
                $arg = $displayfunc($arg);
                $nbuttons = sizeof($this->buttons);

?>              <tr>
                <td valign=top>
<?
                for ($i = 0; $i < $nbuttons; $i++) {
?>                      <input type=radio name="submitvals[<?echo($this->name)?>][0]"
<?                              if ($this->readonly)
                                        echo(" disabled ");
                                $button = $this->buttons[$i];
                                if (!strcmp($button, $arg[0])) {
                                        echo(" checked ");
                                        $oldval = $button;
                                }
?>                              value="<?echo($button)?>"
                        >
<?                      echo($button);
?>                      <br>
                        <input type=hidden
                                name="oldvals[<?echo($this->name)?>][0]"
<?                              if (isset($oldval)) {
?>                                      value="<?echo($oldval)?>"
<?                              } else {
?>                                      value=""
<?                              }
?>                      >
<?              }
?>              </td>

                <td valign=middle>
<?              if ($this->readonly)
                        echo("&nbsp;");
                else {
?>                      <input align=right
                                type=submit
                                name="what[<?echo($this->name)?>][0]"
                                value=change
                        >

<?              }
?>              </td>

                </tr>
<?      }
}

/*
 * a multival selector input, which can only select one entry, but can list
 * many to select among
 */
class select_single_input
extends input
{
        var $nvals;

        function
        select_single_input ($name, $ldapattr, $readonly)
        {
                $this->name     = $name;
                $this->ldapattr = $ldapattr;
                $this->readonly = $readonly;
        }
        function
        display ($selectors)
        {
                $nvals = sizeof($selectors);
?>              <select name="<?echo($this->name)?>"
<?                      if ($this->readonly)
                                echo(" disabled ");
?>                      size="<?echo($nvals)?>"
                >
<?              for ($i = 0; $i < $nvals; $i++) {
?>                      <option>
<?                      if (isset($selectors[$i]))
                                echo($selectors[$i]);
?>                      </option>
<?              }
?>              </select>
<?      }
}

?>