function gs_prov_group_del($id) { $id = (int) $id; if ($id < 1) { return new GsError('Invalid group ID.'); } $DB = gs_db_master_connect(); if (!$DB) { return new GsError('Could not connect to database.'); } $mptt = new YADB_MPTT($DB, 'user_groups', 'lft', 'rgt', 'id'); return $mptt->delete($id, true); }
function gs_prov_groups_get() { $DB = gs_db_master_connect(); if (!$DB) { return new GsError('Could not connect to database.'); } $mptt = new YADB_MPTT($DB, 'user_groups', 'lft', 'rgt', 'id'); $groups = $mptt->get_tree_as_list(null); if (!is_array($groups)) { return new GsError('Failed to get the list of groups'); } return $groups; }
function gs_prov_params_get($username, $phone_type) { if (!preg_match('/^[a-z0-9\\-_.]+$/', $username)) { return new GsError('User must be alphanumeric.'); } if (!preg_match('/^[a-z0-9\\-_]+$/', $phone_type)) { return new GsError('Phone type be alphanumeric.'); } # connect to db # $db = gs_db_master_connect(); if (!$db) { return new GsError('Could not connect to database.'); } # get user # $rs = $db->execute('SELECT `id`, `group_id` ' . 'FROM `users` ' . 'WHERE `user`=\'' . $db->escape($username) . '\''); if (!$rs) { return new GsError('DB error.'); } $user = $rs->fetchRow(); if (!$user) { return new GsError('No such user.'); } # get keys for nested groups # $params = array(); if ($user['group_id'] > 0) { $mptt = new YADB_MPTT($db, 'user_groups', 'lft', 'rgt', 'id'); $path = @$mptt->get_path_to_node($user['group_id'], true); if (!is_array($path)) { return new GsError('DB error.'); } foreach ($path as $group) { if ($group['prov_param_profile_id'] > 0) { //echo 'Get group\'s prov param profile, id '. $group['prov_param_profile_id'] ."\n"; $rs = $db->execute('SELECT `param`, `index`, `value` ' . 'FROM `prov_params` ' . 'WHERE ' . '`profile_id`=' . $group['prov_param_profile_id'] . ' AND ' . '`phone_type`=\'' . $db->escape($phone_type) . '\' ' . 'ORDER BY `param`, `index`'); while ($r = $rs->fetchRow()) { $r['_set_by'] = 'g'; $r['_setter'] = $user['group_id']; $params[$r['param']][$r['index']] = $r['value']; } } } } return $params; }
function gs_prov_group_del($id) { $id = (int) $id; if ($id < 1) { return new GsError('Invalid group ID.'); } $DB = gs_db_master_connect(); if (!$DB) { return new GsError('Could not connect to database.'); } $mptt = new YADB_MPTT($DB, 'user_groups', 'lft', 'rgt', 'id'); if (GS_BUTTONDAEMON_USE == false) { return $mptt->delete($id, true); } else { $ret = $mptt->delete($id, true); if (!isGsError($ret) && $ret) { gs_usergroup_remove_ui($id); } return $ret; } }
<br /> <?php echo '<input type="hidden" name="u_prv_grp_ed" value="yes" />', "\n"; ?> <table cellspacing="1"> <tbody> <tr> <th style="width:180px;"> <?php echo __('Provisioning-Gruppe'); ?> </th> <td style="width:280px;"> <?php $mptt = new YADB_MPTT($DB, 'user_groups', 'lft', 'rgt', 'id'); $u_prv_groups = $mptt->get_tree_as_list(null); echo '<select name="u_prv_grp_id">', "\n"; echo '<option value=""'; if ($r['group_id'] == '') { echo ' selected="selected"'; } echo '>- ', __('keine'), ' -</option>', "\n"; if (is_array($u_prv_groups)) { $is_root_node = true; $root_level = 0; foreach ($u_prv_groups as $u_prv_group) { if ($is_root_node) { # skip root node $root_level = $u_prv_group['__mptt_level']; $is_root_node = false;
function gs_prov_group_change($id, $parent_id, $name_new, $title, $softkey_profile_id = null, $prov_param_profile_id = null, $show_ext_modules = 255) { $id = (int) $id; if ($id < 1) { $id = 0; } # add $parent_id = (int) $parent_id; if ($parent_id < 1) { $parent_id = null; } $name_new = preg_replace('/[^a-z0-9\\-_]/', '', strToLower($name_new)); if (!preg_match('/^[a-z0-9\\-_]+$/', $name_new)) { return new GsError('Invalid group name.'); } $title = trim($title); $softkey_profile_id = (int) $softkey_profile_id; if ($softkey_profile_id < 1) { $softkey_profile_id = null; } $prov_param_profile_id = (int) $prov_param_profile_id; if ($prov_param_profile_id < 1) { $prov_param_profile_id = null; } if ($show_ext_modules === null) { $show_ext_modules = 255; } else { $show_ext_modules = (int) $show_ext_modules; if ($show_ext_modules > 255 || $show_ext_modules < 0) { $show_ext_modules = 255; } } # connect to db # $DB = gs_db_master_connect(); if (!$DB) { return new GsError('Could not connect to database.'); } $mptt = new YADB_MPTT($DB, 'user_groups', 'lft', 'rgt', 'id'); if ($id < 1) { # add if ($parent_id < 1) { //return new GsError( 'Failed to add group without parent.' ); $root_node = $mptt->find_root_node(); if (!is_array($root_node)) { return new GsError('Failed to find top-level group.'); } $parent_id = (int) @$root_node['id']; if ($parent_id < 1) { return new GsError('Failed to add group without parent.'); } } $id = (int) $mptt->insert($parent_id, array('name' => $name_new, 'title' => $title, 'softkey_profile_id' => $softkey_profile_id, 'prov_param_profile_id' => $prov_param_profile_id, 'show_ext_modules' => $show_ext_modules)); if ($id < 1) { return new GsError('Failed to add group.'); } } if ($id > 0) { $ok = $DB->execute('UPDATE `user_groups` SET ' . '`name`=\'' . $DB->escape($name_new) . '\', ' . '`title`=\'' . $DB->escape($title) . '\', ' . '`softkey_profile_id`=' . ($softkey_profile_id > 0 ? $softkey_profile_id : 'NULL') . ', ' . '`prov_param_profile_id`=' . ($prov_param_profile_id > 0 ? $prov_param_profile_id : 'NULL') . ', ' . '`show_ext_modules`=' . $show_ext_modules . ' ' . 'WHERE `id`=' . $id); if (!$ok) { return new GsError('Failed to change group.'); } return $id; } return false; }
function gs_keys_get_by_profile_or_user($profile_id, $username, $phone_type) { $profile_id = (int) $profile_id; if ($profile_id < 1 && $username == '') { return new GsError('Neither profile_id nor user specified.'); } if ($profile_id > 0 && $username != '') { return new GsError('Both profile_id and user specified.'); } if (!preg_match('/^[a-z0-9\\-_]+$/', $phone_type)) { return new GsError('Phone type must be alphanumeric.'); } //gs_log( GS_LOG_DEBUG, "Getting keys: profile_id: $profile_id, user: $username, " ); # connect to db # $db = gs_db_master_connect(); if (!$db) { return new GsError('Could not connect to database.'); } $user_id = 0; $group_id = 0; # get user # if ($username != '') { $rs = $db->execute('SELECT `id`, `group_id`, `softkey_profile_id` ' . 'FROM `users` ' . 'WHERE `user`=\'' . $db->escape($username) . '\''); if (!$rs) { return new GsError('DB error.'); } $r = $rs->fetchRow(); if (!$r) { return new GsError("User {$username} not found."); } $user_id = (int) $r['id']; $group_id = (int) $r['group_id']; $profile_id = (int) $r['softkey_profile_id']; //gs_log( GS_LOG_DEBUG, "Getting keys: profile_id: $profile_id, user_id: $user_id, group_id: $group_id" ); } if ($profile_id < 1 && $user_id < 1) { return new GsError('Neither profile_id nor user_id specified.'); } # is it a user's profile? # if ($user_id > 0) { $is_user_profile = true; } else { $rs = $db->execute('SELECT `is_user_profile` ' . 'FROM `softkey_profiles` ' . 'WHERE `id`=' . $profile_id); if (!($r = $rs->getRow())) { return new GsError('Softkey profile not found.'); } $is_user_profile = (bool) (int) $r['is_user_profile']; } # check if we should inherit from any groups # if ($is_user_profile) { # user profile if ($user_id < 1) { # find the user which this profile belongs to and the group of # this user $rs = $db->execute('SELECT `id`, `group_id` ' . 'FROM `users` ' . 'WHERE `softkey_profile_id`=' . $profile_id); if ($rs->numRows() == 1) { # profile belongs to exactly one user. find parent groups. $r = $rs->fetchRow(); $group_id = (int) $r['group_id']; /* if ($user_id !== (int)$r['id']) { gs_log( GS_LOG_WARNING, "Function probably called with wrong user_id" ); } */ $user_id = (int) $r['id']; } else { # profile belongs to no user or to more than one user or # to an unknown number of users. can't find parent groups. gs_log(GS_LOG_WARNING, "Softkey profile {$profile_id} belongs to more than one user"); } //gs_log( GS_LOG_DEBUG, "Getting keys: profile_id: $profile_id, user_id: $user_id, group_id: $group_id" ); } /* else { # find the group and profile_id of this user $rs = $db->execute( 'SELECT `softkey_profile_id`, `group_id` '. 'FROM `users` '. 'WHERE `id`='. $user_id ); $r = $rs->fetchRow(); if (! $r) { return new GsError( "User $user_id not found." ); } $group_id = (int)$r['group_id']; if ($profile_id !== (int)$r['softkey_profile_id']) { gs_log( GS_LOG_WARNING, "Function probably called with wrong profile_id" ); } $profile_id = (int)$r['softkey_profile_id']; //gs_log( GS_LOG_DEBUG, "Getting keys: profile_id: $profile_id, user_id: $user_id, group_id: $group_id" ); } */ } else { # group profile # find the group(s) which this profile belongs to (if any) $rs = $db->execute('SELECT `id` ' . 'FROM `user_groups` ' . 'WHERE `softkey_profile_id`=' . $profile_id); if ($rs->numRows() == 1) { # profile belongs to exactly one group. find parent groups. $group_id = (int) $rs->getField('id'); } else { # profile belongs to no group or to more than one group or # to an unknown number of groups. can't find parent groups. } //gs_log( GS_LOG_DEBUG, "Getting keys: profile_id: $profile_id, user_id: $user_id, group_id: $group_id" ); } $keys = array(); if ($group_id > 0) { # find parent groups $mptt = new YADB_MPTT($db, 'user_groups', 'lft', 'rgt', 'id'); $path = @$mptt->get_path_to_node($group_id, true); if (!is_array($path)) { return new GsError('DB error.'); } foreach ($path as $group) { if ($group['softkey_profile_id'] > 0) { //gs_log( GS_LOG_DEBUG, "Getting keys: group_id: ".$group['id']." (profile_id: ".$group['softkey_profile_id'].")" ); $rs = $db->execute('SELECT `key`, `function`, `data`, `label`, `user_writeable` ' . 'FROM `softkeys` ' . 'WHERE ' . '`profile_id`=' . $group['softkey_profile_id'] . ' AND ' . '`phone_type`=\'' . $db->escape($phone_type) . '\' ' . 'ORDER BY `key`'); while ($r = $rs->fetchRow()) { if ($r['function'] === '') { continue; } # inherited /* $keyname = $r['key']; unset($r['key']); $keys[$keyname] = $r; */ $r['_set_by'] = 'g'; $r['_setter'] = $group['id']; if ($group['id'] != $group_id) { # inherited $keys[$r['key']]['inh'] = $r; } else { # defined by this group if (!$is_user_profile) { $keys[$r['key']]['slf'] = $r; } else { $keys[$r['key']]['inh'] = $r; } } } } } } if (($is_user_profile || $group_id < 1) && $profile_id > 0) { //gs_log( GS_LOG_DEBUG, "Getting keys: user_id: $user_id, profile_id: $profile_id" ); $rs = $db->execute('SELECT `key`, `function`, `data`, `label`, `user_writeable` ' . 'FROM `softkeys` ' . 'WHERE ' . '`profile_id`=' . $profile_id . ' AND ' . '`phone_type`=\'' . $db->escape($phone_type) . '\' ' . 'ORDER BY `key`'); while ($r = $rs->fetchRow()) { if (array_key_exists($r['key'], $keys) && array_key_exists('inh', $keys[$r['key']]) && !$keys[$r['key']]['inh']['user_writeable']) { # user not allowed to overwrite key continue; } /* $keyname = $r['key']; unset($r['key']); $keys[$keyname] = $r; */ if ($is_user_profile) { $r['_set_by'] = 'u'; $r['_setter'] = $user_id; } else { $r['_set_by'] = 'g'; $r['_setter'] = $group_id; } $keys[$r['key']]['slf'] = $r; } } return $keys; }
echo '<td> <br />', "\n"; echo '<select name="group-0-show_ext_modules">', "\n"; for ($num_e_m = 0; $num_e_m <= 3; ++$num_e_m) { echo '<option value="', $num_e_m, '"'; echo '>', $num_e_m, '</option>', "\n"; } echo '<option value="255" selected="selected">', __('alle'), '</option>', "\n"; echo '</select>', "\n"; echo '</td>', "\n"; echo '<td class="r"> <br />', "\n"; echo '<button type="submit" class="plain" title="', __('Speichern'), '"><img alt="', __('Speichern'), '" src="', GS_URL_PATH, 'crystal-svg/16/act/filesave.png" /></button>'; echo '</td>', "\n"; echo '</tr>', "\n"; ++$i; } ?> </tbody> </table> </form> <?php echo '<br /><br />', "\n"; echo '<small>DB-Analyse', ':', "\n"; $mptt = new YADB_MPTT($DB, 'user_groups', 'lft', 'rgt', 'id'); echo 'MPTT-Struktur ist ', $mptt->quick_sanity_check() ? 'in Ordnung' : 'FEHLERHAFT', '</small><br />', "\n"; echo '<br />', "\n"; echo '<p class="text small"><sup>[1]</sup> ', __('Bestimmt wieviele Telefon-Erweiterungsmodule/-Beistellmodule in der Benutzer-Tastenbelegungsmaske angezeigt werden.'), '</p>', "\n"; } ##################################################################### # view } #####################################################################