import from branch_1_1:
[freeradius.git] / dialup_admin / lib / sql / group_info.php3
1 <?php
2 require('../lib/sql/attrmap.php3');
3 if (is_file("../lib/sql/drivers/$config[sql_type]/functions.php3"))
4         include_once("../lib/sql/drivers/$config[sql_type]/functions.php3");
5 else{
6         echo "<b>Could not include SQL library</b><br>\n";
7         exit();
8 }
9 if ($config[sql_use_operators] == 'true'){
10         $op = ',op';
11         $use_op = 1;
12 }else{
13         $op = "";
14         $use_op = 0;
15 }
16 $group_exists = 'no';
17 $link = @da_sql_pconnect($config);
18 if ($link){
19         if ($login == ''){
20                 unset($existing_groups);
21
22                 $res = @da_sql_query($link,$config,
23                 "SELECT COUNT(*) as counter,groupname FROM $config[sql_usergroup_table]
24                 GROUP BY groupname;");
25                 if ($res){
26                         while(($row = @da_sql_fetch_array($res,$config))){
27                                 $name = $row[groupname];
28                                 $existing_groups["$name"] = $row[counter];
29                         }
30                         if (isset($existing_groups))
31                                 ksort($existing_groups);
32                 }
33                 else
34                         echo "<b>Database query failed: " . da_sql_error($link,$config) . "</b><br>\n";
35         }
36         else{
37                 unset($item_vals);
38                 unset($tmp);
39                 unset($group_members);
40                 unset($existing_groups);
41
42                 $res = @da_sql_query($link,$config,
43                 "SELECT attribute,value $op FROM $config[sql_groupcheck_table] WHERE groupname = '$login';");
44                 if ($res){
45                         if (@da_sql_num_rows($res,$config))
46                                 $group_exists = 'yes';
47                         while(($row = @da_sql_fetch_array($res,$config))){
48                                 $attr = $row[attribute];
49                                 $val = $row[value];
50                                 if ($use_op){
51                                         $oper = $row[op];
52                                         $tmp["$attr"][operator][]="$oper";
53                                 }
54                                 $tmp["$attr"][]="$val";
55                                 $tmp["$attr"][count]++;
56                         }
57                         $res = @da_sql_query($link,$config,
58                         "SELECT attribute,value $op FROM $config[sql_groupreply_table] WHERE groupname = '$login';");
59                         if ($res){
60                                 if (@da_sql_num_rows($res,$config))
61                                         $group_exists = 'yes';
62                                 while(($row = @da_sql_fetch_array($res,$config))){
63                                         $attr = $row[attribute];
64                                         $val = $row[value];
65                                         if ($use_op){
66                                                 $oper = $row[op];
67                                                 $tmp["$attr"][operator][]="$oper";
68                                         }
69                                         $tmp["$attr"][] = "$val";
70                                         $tmp["$attr"][count]++;
71                                 }
72                         }
73                         else
74                                 echo "<b>Database query failed partially: " . da_sql_error($link,$config) . "</b><br>\n";
75                         $res = @da_sql_query($link,$config,
76                         "SELECT username FROM $config[sql_usergroup_table] WHERE groupname = '$login' ORDER BY username;");
77                         if ($res){
78                                 if (@da_sql_num_rows($res,$config))
79                                         $group_exists = 'yes';
80                                 while(($row = @da_sql_fetch_array($res,$config))){
81                                         $member = $row[username];
82                                         $group_members[] = "$member";
83                                 }
84                         }
85                         else
86                                 echo "<b>Database query failed partially: " . da_sql_error($link,$config) . "</b><br>\n";
87                         if (isset($tmp)){
88                                 foreach(array_keys($tmp) as $val){
89                                         if ($val == '')
90                                                 continue;
91                                         $key = $rev_attrmap["$val"];
92                                         if ($key == ''){
93                                                 $key = $val;
94                                                 $attrmap["$key"] = $val;
95                                                 $attr_type["$key"] = 'replyItem';
96                                                 $rev_attrmap["$val"] = $key;
97                                         }
98                                         $item_vals["$key"] = $tmp[$val];
99                                         $item_vals["$key"][count] = $tmp[$val][count];
100                                         if ($use_op)
101                                                 $item_vals["$key"][operator] = $tmp[$val][operator];
102                                 }
103                         }
104                 }
105                 else
106                         echo "<b>Database query failed: " . da_sql_error($link,$config) . "</b><br>\n";
107         }
108 }
109 else
110         echo "<b>Could not connect to SQL database</b><br>\n";
111 ?>