Exemplo n.º 1
0
/**
 * Add group and "registration group" to accesspoint
 * 
 * @author Alberto Basso
 */
function sumo_add_accesspoint_group($groups_exist = array(), $name = '', $enabled = TRUE)
{
    global $SUMO;
    $group_exist = is_array($groups_exist) ? '' : $groups_exist;
    $groups_exist = !is_array($groups_exist) ? array($groups_exist) : $groups_exist;
    $group_name = sumo_get_grouplevel(sumo_get_user_available_group($SUMO['user']['user']), TRUE);
    $name = $name ? $name : 'newgroup';
    $disabled = $enabled ? '' : ' disabled';
    $available = FALSE;
    $list = "<select name='" . $name . "'" . $disabled . ">\n" . "<option value='" . $group_exist . "'>" . $group_exist . "</option>\n";
    for ($g = 0; $g < count($group_name); $g++) {
        if ($group_name[$g] == 'sumo') {
            $available_group = sumo_get_available_group();
            //$list = "<select name='".$name."'>\n<option></option>\n";
            //if(!in_array('sumo', $group_exist)) $list .= "<option value='sumo' style='color:#BB0000'>sumo</option>\n";
            for ($g = 0; $g < count($available_group); $g++) {
                //if(!in_array($available_group[$g], $group_exist) && $available_group[$g] != 'sumo')
                if (!in_array($available_group[$g], $groups_exist)) {
                    $style = $available_group[$g] == 'sumo' ? " style='color:#BB0000'" : "";
                    $list .= "<option value='" . $available_group[$g] . "'{$style}>" . $available_group[$g] . "</option>\n";
                }
            }
            $available = TRUE;
            break;
        } else {
            if (!in_array($group_name[$g], $group_exist)) {
                $list .= "<option value='" . $group_name[$g] . "'>" . $group_name[$g] . "</option>\n";
                $available = TRUE;
            }
        }
    }
    $list .= "</select>";
    if (!$available) {
        $list = '';
    }
    return $list;
}
Exemplo n.º 2
0
/**
 * Combo box to add group and relative level to user
 */
function sumo_add_user_grouplevel($form_name = '', $group_exist = array())
{
    global $SUMO;
    $groups_array = sumo_get_grouplevel(sumo_get_user_available_group($SUMO['user']['user']));
    $groups_name = array_keys($groups_array);
    $form_name = $form_name ? $form_name : ucfirst($_SESSION['action']) . ucfirst($_SESSION['module']);
    $available = FALSE;
    $script = "";
    $change = "n=document.forms['{$form_name}'].group;\n" . "l=document.forms['{$form_name}'].newgroup;\n" . "gr=n.options[n.selectedIndex].value;\n" . "ls=g[gr];l.options.length=0;if(!gr)return;\n" . "for(i=0;i<ls.length;i+=2){l.options[i/2]=new Option(ls[i],ls[i+1]);}\n";
    $list = "<select name='group' onchange=\"" . $change . "\">\n<option></option>\n";
    for ($g = 0; $g < count($groups_name); $g++) {
        // ...administrator can add all groups
        if ($groups_name[$g] == 'sumo') {
            $available_group = sumo_get_available_group();
            // ...to display 'sumo' group on top
            //if(!in_array('sumo', $group_exist))
            //	$list .= " <option value='sumo' style='color:#BB0000'>sumo</option>\n";
            for ($g = 0; $g < count($available_group); $g++) {
                // create levels
                for ($l = 1; $l <= 7; $l++) {
                    $value[$l] = $l . ",'" . $available_group[$g] . ":" . $l . "'";
                    if ($available_group[$g] == 'sumo' && $SUMO['user']['group_level']['sumo'] <= $l) {
                        break;
                    }
                }
                $script .= "g['" . $available_group[$g] . "']=new Array(" . implode(',', $value) . ");\n";
                //
                if (!in_array($available_group[$g], $group_exist)) {
                    $list .= " <option value='" . $available_group[$g] . "'>" . $available_group[$g] . "</option>\n";
                }
            }
            $available = TRUE;
            break;
        } else {
            // create levels
            for ($l = 1; $l <= $groups_array[$groups_name[$g]]; $l++) {
                $value[$l] = $l . ",'" . $groups_name[$g] . ":" . $l . "'";
            }
            $script .= "g['" . $groups_name[$g] . "']=new Array(" . implode(',', $value) . ");";
            //
            if (!in_array($groups_name[$g], $group_exist)) {
                $list .= " <option value='" . $groups_name[$g] . "'>" . $groups_name[$g] . "</option>\n";
                $available = TRUE;
            }
        }
    }
    $list .= "</select>&nbsp;:&nbsp;<select name='newgroup'></select>";
    $list = str_replace("onchange=\"", "onchange=\"g=new Array();" . $script, $list);
    return $available ? $list : '';
}