Location: PHPKode > projects > ConPortal > conportal/inc/perms/display.php
<?
/*
 *  ConPortal - Pomona College ITS scheduling appplication
 *  Copyright (C) 2005-2006  Pomona College
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of version 2 of the GNU General Public License
 *  as published by the Free Software Foundation.
 *
 *  This program 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., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 */

function draw_dual_selects($name, $avail, $selected, $data_cb, $sortFunc)
{
    /*
     * precalculate the max height (# of elements) and width (strlen + 1 in ems)
     * of the two select boxes. This way, there's no dynamic resizing, which
     * I think looks ugly.
     */
    sort ($avail);
    sort ($selected);

    $size = count($avail)+count($selected);
    if ($size < 4) $size = 4;
    $width = 0;

    foreach (array_keys($avail) as $i) {
        $avail[$i] = call_user_func($data_cb, $avail[$i]);
        $width = max($width, strlen($avail[$i]['name']));
    }
    foreach (array_keys($selected) as $i) {
        $selected[$i] = call_user_func($data_cb, $selected[$i]);
        $width = max($width, strlen($selected[$i]['name']));
    }

    if ($width < 8) $width = 8;
    
    // sort the two arrays
	$avail    = call_user_func($sortFunc, $avail);
	$selected = call_user_func($sortFunc, $selected);
?>
    <table class='permsTable' id='<?= $name ?>'>
        <tr>
            <th class='avail'><label for='avail<?= $name ?>'>Available</label>
            </th>
            <td></td>
            <th class='sel'><label for='sel<?= $name ?>'>Selected</label></th>
        </tr>
        <tr>
            <td>
                <select size='<?= $size ?>' style='width: <?=$width?>em'
                 id='avail<?=$name?>' name='avail<?=$name?>[]'
                 multiple='multiple' ondblclick="moveOptions('avail<?= $name ?>', 'sel<?= $name ?>')">
<?
    foreach ($avail as $a) {
        echo "                    ".
             "<option value='".$a['pid']."'>".$a['name']."</option>\n";
    }
?>
                </select>
            </td>
            <td class='moveButtons'>
                <button onclick="moveOptions('avail<?= $name ?>',
                                             'sel<?= $name ?>'); return false">
                    Add &gt;&gt;
                </button>
                <button onclick="moveOptions('sel<?= $name ?>',
                                             'avail<?= $name ?>'); return false">
                    &lt;&lt; Remove
                </button> 
            </td>
            <td>
                <select size='<?= $size ?>' style='width: <?=$width?>em'
                 id='sel<?=$name?>' name='sel<?=$name?>[]' multiple='multiple'
                 ondblclick="moveOptions('sel<?= $name ?>', 'avail<?= $name ?>')">
<?
    foreach ($selected as $s) {
        echo "                <option value='".$s['pid']."'>".$s['name']."</option>\n";
    }

?>
                </select>
            </td>
        </tr>
    </table>
<?
}

?>
Return current item: ConPortal