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