Esempio n. 1
0
function renderLocationSelectTree($selected_id = NULL)
{
    echo '<option value=0>-- NONE --</option>';
    $locationlist = listCells('location');
    foreach (treeFromList($locationlist) as $location) {
        echo "<option value={$location['id']} style='font-weight: bold' ";
        if ($location['id'] == $selected_id) {
            echo ' selected';
        }
        echo ">{$location['name']}</option>";
        printLocationChildrenSelectOptions($location, 0, $selected_id);
    }
    echo '</select>';
}
Esempio n. 2
0
function getLocationSelectAJAX()
{
    $locationlist = listCells('location');
    $locationtree = treeFromList($locationlist);
    // adds ['trace'] keys into $locationlist items
    $options = array();
    $selected_id = '';
    if (!isset($_REQUEST['locationid'])) {
        $options['error'] = "Sorry, param 'locationid' is empty. Reload page and try again";
    } elseif (!preg_match("/locationid_(\\d+)/i", $_REQUEST['locationid'], $m)) {
        $options['error'] = "Sorry, wrong format locationid:'" . $_REQUEST['locationid'] . "'. Reload page and try again";
    } else {
        $current_location_id = $m[1];
        $selected_id = $locationlist[$current_location_id]['parent_id'];
        echo $selected_id;
        echo "<option value=0>-- NONE --</option>";
    }
    foreach ($locationtree as $location) {
        if ($location['id'] == $current_location_id) {
            continue;
        }
        echo "<option value={$location['id']} ";
        if ($location['id'] == $selected_id) {
            echo 'selected ';
        }
        echo "style='font-weight: bold'>{$location['name']}</option>";
        if ($location['kidc'] > 0) {
            printLocationChildrenSelectOptions($location, 0, $selected_id, $current_location_id);
        }
    }
}