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