Optimize "Customer has a referring customer" condition, RT#74452
[freeside.git] / min_selfservice / login.php
1 <?
2
3 require('freeside.class.php');
4 $freeside = new FreesideSelfService();
5
6 $ip = $_SERVER['REMOTE_ADDR'];
7 # need a routine here to get mac address from radius account table based on ip address.  Every else should be good to go.
8 $mac_addr = '1234567890FF';
9
10 $response = $freeside->login( array( 
11   'username' => $mac_addr, 
12   'domain'   => 'ip_mac',
13 ) );
14
15 #error_log("[login] received response from freeside: $response");
16
17 $error = $response['error'];
18
19 if ( $error ) {
20
21   header('Location:index.php?username='. urlencode($mac).
22                            '&domain='.   urlencode($domain).
23                            '&email='.    urlencode($email).
24                            '&error='.    urlencode($error)
25         );
26   die();
27
28 }
29
30 // sucessful login
31
32 $session_id = $response['session_id'];
33
34 error_log("[login] logged into freeside with session_id=$session_id, setting cookie");
35
36 // now what?  for now, always redirect to the main page (or the select a
37 // customer diversion).
38 // eventually, other options?
39
40 setcookie('session_id', $session_id);
41
42 if ( $response['custnum'] || $response['svcnum'] ) {
43
44   header("Location:main.php");
45   die();
46   //1;
47
48 } elseif ( $response['customers'] ) {
49 var_dump($response['customers']);
50 ?>
51
52   <? $title ='Select customer'; include('elements/header.php'); ?>
53   <? include('elements/error.php'); ?>
54
55   <FORM NAME="SelectCustomerForm" ACTION="process_select_cust.php" METHOD=POST>
56   <INPUT TYPE="hidden" NAME="action" VALUE="switch_cust">
57
58   <TABLE BGCOLOR="#c0c0c0" BORDER=0 CELLSPACING=2 CELLPADDING=0>
59
60     <TR>
61       <TH ALIGN="right">Customer </TH>
62       <TD>
63         <SELECT NAME="custnum" ID="custnum" onChange="custnum_changed()">
64           <OPTION VALUE="">Select a customer
65           <? foreach ( $response['customers'] AS $custnum => $customer ) { ?>
66             <OPTION VALUE="<? echo $custnum ?>"><? echo htmlspecialchars( $customer ) ?>
67           <? } ?>
68         </SELECT>
69       </TD>
70     </TR>
71
72     <TR>
73       <TD COLSPAN=2 ALIGN="center"><INPUT TYPE="submit" ID="submit" VALUE="Select customer" DISABLED></TD>
74     </TR>
75
76   </TABLE>
77   </FORM>
78
79   <SCRIPT TYPE="text/javascript">
80
81   function custnum_changed () {
82     var form = document.SelectCustomerForm;
83     if ( form.custnum.selectedIndex > 0 ) {
84       form.submit.disabled = false;
85     } else {
86       form.submit.disabled = true;
87     }
88   }
89
90   </SCRIPT>
91
92   <? include('elements/footer.php'); ?>
93
94 <?
95
96 // } else {
97 // 
98 //   die 'login successful, but unrecognized info (no custnum, svcnum or customers)';
99   
100 }
101
102 ?>