4c56a297c892b9ab54024c1dcb3c26e9cea5666d
[freeradius.git] / dialup_admin / lib / sql / user_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 $user_exists = 'no';
17
18 $cn = '-';
19 $cn_lang = '-';
20 $address = '-';
21 $address_lang = '-';
22 $homeaddress = '-';
23 $homeaddress_lang = '-';
24 $fax = '-';
25 $url = '-';
26 $ou = '-';
27 $ou_lang = '-';
28 $title = '-';
29 $title_lang = '-';
30 $telephonenumber = '-';
31 $homephone = '-';
32 $mobile = '-';
33 $mail = '-';
34 $mailalt = '-';
35 $user_password_exists = 'no';
36
37 unset($item_vals);
38 unset($tmp);
39 $link = @da_sql_pconnect($config);
40 if ($link){
41         $res = @da_sql_query($link,$config,
42         "SELECT attribute,value $op FROM $config[sql_check_table] WHERE username = '$login';");
43         if ($res){
44                 if (@da_sql_num_rows($res,$config))
45                         $user_exists = 'yes';
46                 while(($row = @da_sql_fetch_array($res,$config))){
47                         $attr = $row[attribute];
48                         $val = $row[value];
49                         if ($attr == $config[sql_password_attribute] && $val != '')
50                                 $user_password_exists = 'yes';
51                         if ($use_op){
52                                 $oper = $row[op];
53                                 $tmp["$attr"][operator][]="$oper";
54                         }
55                         $tmp["$attr"][]="$val";
56                         $tmp["$attr"][count]++;
57                 }
58                 $res = @da_sql_query($link,$config,
59                 "SELECT attribute,value $op FROM $config[sql_reply_table] WHERE username = '$login';");
60                 if ($res){
61                         if (@da_sql_num_rows($res,$config))
62                                 $user_exists = 'yes';
63                         while(($row = @da_sql_fetch_array($res,$config))){
64                                 $attr = $row[attribute];
65                                 $val = $row[value];
66                                 if ($use_op){
67                                         $oper = $row[op];
68                                         $tmp["$attr"][operator][]="$oper";
69                                 }
70                                 $tmp["$attr"][] = "$val";
71                                 $tmp["$attr"][count]++;
72                         }
73                         if ($config[sql_use_user_info_table] == 'true'){
74                                 $res = @da_sql_query($link,$config,
75                                 "SELECT * FROM $config[sql_user_info_table] WHERE username = '$login';");
76                                 if ($res){
77                                         if (@da_sql_num_rows($res,$config)){
78                                                 $user_exists = 'yes';
79                                                 $user_info = 1;
80                                         }
81                                         if (($row = @da_sql_fetch_array($res,$config))){        
82                                                 $cn = ($row[name] != '') ? $row[name] : '-';
83                                                 $telephonenumber = ($row[workphone] != '') ? $row[workphone] : '-';
84                                                 $homephone = ($row[homephone] != '') ? $row[homephone] : '-';
85                                                 $ou = ($row[department] != '') ? $row[department] : '-';
86                                                 $mail = ($row[mail] != '') ? $row[mail] : '-';
87                                                 $mobile = ($row[mobile] != '') ? $row[mobile] : '-';
88                                         }
89                                 }                       
90                                 else
91                                         echo "<b>Database query failed partially: " . da_sql_error($link,$config) . "</b><br>\n";
92                         }
93                 }
94                 else
95                         echo "<b>Database query failed partially: " . da_sql_error($link,$config) . "</b><br>\n";
96                 if (isset($tmp)){
97                         foreach(array_keys($tmp) as $val){
98                                 if ($val == '')
99                                         continue;
100                                 $key = $rev_attrmap["$val"];
101                                 if ($key == ''){
102                                         $key = $val;
103                                         $attrmap["$key"] = $val;
104                                         $attr_type["$key"] = 'replyItem';
105                                         $rev_attrmap["$val"] = $key;
106                                 }
107                                 $item_vals["$key"] = $tmp[$val];
108                                 $item_vals["$key"][count] = $tmp[$val][count];
109                                 if ($use_op)
110                                         $item_vals["$key"][operator] = $tmp[$val][operator];
111                         }
112                 }
113
114         }
115         else
116                 echo "<b>Database query failed: " . da_sql_error($link,$config) . "</b><br>\n";
117 }
118 else
119         echo "<b>Could not connect to SQL database</b><br>\n";
120 ?>