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