提交 63dfc8f4 authored 作者: Raymond Chandler's avatar Raymond Chandler

adding group support to user directory

git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk/contrib@15127 d0543943-73ff-0310-b7d9-9358b9ac24b2
上级 06380a9f
......@@ -64,6 +64,7 @@ class fs_directory extends fs_curl {
*/
private function get_directory() {
$directory_array = array();
$join_clause = '';
if (!array_key_exists('domain', $this -> request)) {
$this -> comment('domain not passed');
$this -> file_not_found();
......@@ -74,6 +75,11 @@ class fs_directory extends fs_curl {
if (array_key_exists('user', $this -> request)) {
$where_array[] = sprintf("username='%s'", $this -> user);
}
if (array_key_exists('group', $this->request)) {
$where_array[] = sprintf("group_name='%s'", $this->request['group']);
$join_clause = "JOIN directory_group_user_map dgum ON d.id=dgum.user_id ";
$join_clause .= "JOIN directory_groups dg ON dgum.group_id=dg.group_id ";
}
if (!empty($where_array)) {
$this -> comment('where array has contents');
if (count($where_array) > 1) {
......@@ -84,8 +90,8 @@ class fs_directory extends fs_curl {
} else {
$where_clause = '';
}
$query = sprintf("SELECT * FROM directory %s ORDER BY username"
, $where_clause
$query = sprintf("SELECT * FROM directory d %s ORDER BY username"
, $join_clause, $where_clause
);
$res = $this -> db -> queryAll($query);
if (FS_PDO::isError($res)) {
......@@ -219,7 +225,8 @@ class fs_directory extends fs_curl {
* @return void
*/
private function write_gateways($user_id) {
if (array_key_exists($user_id, $this->users_gateways)
if (is_array($this->users_gateways)
&& array_key_exists($user_id, $this->users_gateways)
&& is_array($this -> users_gateways[$user_id])) {
$this -> xmlw -> startElement('gateways');
$gateway_count = count($this -> users_gateways[$user_id]);
......@@ -296,6 +303,9 @@ class fs_directory extends fs_curl {
$param_count = count($res);
$this -> xmlw -> startElement('params');
for ($i=0; $i<$param_count; $i++) {
if (empty($res[$i['var_name']])) {
continue;
}
$this -> xmlw -> startElement('param');
$this -> xmlw -> writeAttribute('name', $res[$i]['param_name']);
$this -> xmlw -> writeAttribute('value', $res[$i]['param_value']);
......@@ -325,6 +335,9 @@ class fs_directory extends fs_curl {
$param_count = count($res);
$this -> xmlw -> startElement('variables');
for ($i=0; $i<$param_count; $i++) {
if (empty($res[$i['var_name']])) {
continue;
}
$this -> xmlw -> startElement('variable');
$this -> xmlw -> writeAttribute('name', $res[$i]['var_name']);
$this -> xmlw -> writeAttribute('value', $res[$i]['var_value']);
......@@ -359,17 +372,30 @@ class fs_directory extends fs_curl {
$this -> write_global_params();
$this -> write_global_vars();
$this->xmlw->startElement('groups');
$this->xmlw->startElement('group');
if (array_key_exists('group', $this->request)) {
$this->xmlw->writeAttribute('name', $this->request['group']);
} else {
$this->xmlw->writeAttribute('name', 'default');
}
$this->xmlw->startElement('users');
for ($i=0; $i<$directory_count; $i++) {
$username = $directory[$i]['username'];
$mailbox = empty($directory[$i]['mailbox']) ? $username : $directory[$i]['mailbox'];
$this -> xmlw -> startElement('user');
$this -> xmlw -> writeAttribute('id', $username);
$this -> xmlw -> writeAttribute('mailbox', $mailbox);
$this -> write_params($directory[$i]['id']);
$this -> write_variables($directory[$i]['id']);
$this -> write_gateways($directory[$i]['id']);
if (empty($directory[$i]['group_name'])) {
$this -> write_params($directory[$i]['id']);
$this -> write_variables($directory[$i]['id']);
$this -> write_gateways($directory[$i]['id']);
} else {
$this->xmlw->writeAttribute('type', 'pointer');
}
$this -> xmlw -> endElement();
}
$this->xmlw->endElement();
$this->xmlw->endElement();
$this -> xmlw -> endElement();
$this -> xmlw -> endElement();
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论