* Fix a small bug in lib/sql/create_user.php3 where work and home phone were stored...
[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_lang = '-';
19 $homeaddress = '-';
20 $homeaddress_lang = '-';
21 $fax = '-';
22 $url = '-';
23 $ou_lang = '-';
24 $title = '-';
25 $title_lang = '-';
26 $mailalt = '-';
27
28 unset($item_vals);
29 unset($tmp);
30 $link = @da_sql_pconnect($config);
31 if ($link){
32         $res = @da_sql_query($link,$config,
33         "SELECT Attribute,Value $op FROM $config[sql_check_table] WHERE UserName = '$login';");
34         if ($res){
35                 if (@da_sql_num_rows($res,$config))
36                         $user_exists = 'yes';
37                 while(($row = @da_sql_fetch_array($res,$config))){
38                         $attr = $row[Attribute];
39                         $val = $row[Value];
40                         if ($use_op){
41                                 $oper = $row[op];
42                                 $tmp["$attr"][operator][]="$oper";
43                         }
44                         $tmp["$attr"][]="$val";
45                         $tmp["$attr"][count]++;
46                 }
47                 $res = @da_sql_query($link,$config,
48                 "SELECT Attribute,Value $op FROM $config[sql_reply_table] WHERE UserName = '$login';");
49                 if ($res){
50                         if (@da_sql_num_rows($res,$config))
51                                 $user_exists = 'yes';
52                         while(($row = @da_sql_fetch_array($res,$config))){
53                                 $attr = $row[Attribute];
54                                 $val = $row[Value];
55                                 if ($use_op){
56                                         $oper = $row[op];
57                                         $tmp["$attr"][operator][]="$oper";
58                                 }
59                                 $tmp["$attr"][] = "$val";
60                                 $tmp["$attr"][count]++;
61                         }
62                         if ($config[sql_use_user_info_table] == 'true'){
63                                 $res = @da_sql_query($link,$config,
64                                 "SELECT * FROM $config[sql_user_info_table] WHERE UserName = '$login';");
65                                 if ($res){
66                                         if (@da_sql_num_rows($res,$config))
67                                                 $user_exists = 'yes';
68                                         if (($row = @da_sql_fetch_array($res,$config))){        
69                                                 $cn = ($row[Name]) ? $row[Name] : '-';
70                                                 $telephonenumber = ($row[WorkPhone]) ? $row[WorkPhone] : '-';
71                                                 $homephone = ($row[HomePhone]) ? $row[HomePhone] : '-';
72                                                 $ou = ($row[Department]) ? $row[Department] : '-';
73                                                 $mail = ($row[Mail]) ? $row[Mail] : '-';
74                                                 $mobile = ($row[Mobile]) ? $row[Mobile] : '-';
75                                         }
76                                 }                       
77                         }
78                 }
79                 else
80                         echo "<b>Database query failed partially</b><br>\n";
81                 foreach($attrmap as $key => $val){
82                         if (isset($tmp[$val])){
83                                 $item_vals["$key"] = $tmp[$val];
84                                 $item_vals["$key"][count] = $tmp[$val][count];
85                                 if ($use_op)
86                                         $item_vals["$key"][operator] = $tmp[$val][operator];
87
88                         }
89                 }
90
91         }
92         else
93                 echo "<b>Database query failed</b><br>\n";      
94 }
95 else
96         echo "<b>Could not connect to database</b><br>\n";
97 ?>