default to a session cookie instead of setting an explicit timeout, weird timezone...
[freeside.git] / ng_selfservice / services_new.php
1 <? $title ='Order a new service'; include('elements/header.php'); ?>
2 <? $current_menu = 'services_new.php'; include('elements/menu.php'); ?>
3 <?
4
5 if ( isset($_POST['pkgpart_svcpart']) && $_POST['pkgpart_svcpart'] ) {
6
7   $results = array();
8
9   $params = array( 'custnum', 'pkgpart' );
10
11   $matches = array();
12   if ( preg_match( '/^(\d+)_(\d+)$/', $_POST['pkgpart_svcpart'], $matches ) ) {
13     $_POST['pkgpart'] = $matches[1];
14     $_POST['svcpart'] = $matches[2];
15     $params[] = 'svcpart';
16     $svcdb = $_POST['svcdb'];
17     if ( $svcdb == 'svc_acct' ) { $params[] = 'domsvc'; }
18   } else {
19     $svcdb = 'svc_acct';
20   }
21
22   if ( $svcdb == 'svc_acct' ) {
23
24     array_push($params, 'username', '_password', '_password2', 'sec_phrase', 'popnum' );
25
26     if ( strlen($_POST['_password']) == 0 ) {
27       $results['error'] = 'Empty password';
28     }
29     if ( $_POST['_password'] != $_POST['_password2'] ) {
30       $results['error'] = 'Passwords do not match';
31       $_POST['_password'] = '';
32       $_POST['_password2'] = '';
33     }
34
35   } elseif ( $svcdb == 'svc_phone' ) {
36
37     array_push($params, 'phonenum', 'sip_password', 'pin', 'phone_name' );
38
39   } else {
40     die("$svcdb not handled on process_order_pkg yet");
41   }
42
43   if ( ! $results['error'] ) {
44
45     $order_pkg = array(
46       'session_id' => $_COOKIE['session_id'],
47     );
48
49     foreach ( $params AS $param ) {
50       $order_pkg[$param] = $_POST[$param];
51     }
52
53     $results = $freeside->order_pkg($order_pkg);
54
55   }
56
57   #  if ( $results->{'error'} ) {
58   #    $action = 'customer_order_pkg';
59   #    return {
60   #      $cgi->Vars,
61   #      %{customer_order_pkg()},
62   #      'error' => '<FONT COLOR="#FF0000">'. $results->{'error'}. '</FONT>',
63   #    };
64   #  } else {
65   #    return $results;
66   #  }
67
68   if ( isset($results['error']) && $results['error'] ) {
69     $error = $results['error'];
70   } else {
71     #$pkgnum = $results['pkgnum'];
72     header("Location:services.php"); # #pkgnum ?
73     die();
74   }
75
76 }
77
78 //sub customer_order_pkg {
79 //  my $init_data = signup_info( 'customer_session_id' => $session_id );
80 //  return $init_data if ( $init_data->{'error'} );
81 //
82 //  my $customer_info = customer_info( 'session_id' => $session_id );
83 //  return $customer_info if ( $customer_info->{'error'} );
84
85 $pkgselect = $freeside->mason_comp( array(
86     'session_id' => $_COOKIE['session_id'],
87     'comp'       => '/edit/cust_main/first_pkg/select-part_pkg.html',
88     'args'       => array( 'password_verify', 1,
89                            'onchange'       , 'enable_order_pkg()',
90                            'relurls'        , 1,
91                            'empty_label'    , 'Select package',
92                            'form_name'      , 'OrderPkgForm',
93                            'pkgpart_svcpart', $_POST['pkgpart_svcpart'],
94                            'username'       , $_POST['username'],
95                            'password'       , $_POST['_password'],
96                            'password2'      , $_POST['_password2'],
97                            'popnum'         , $_POST['popnum'],
98                            'saved_domsvc'   , $_POST['domsvc'],
99                          ),
100 ));
101 if ( isset($pkgselect['error']) && $pkgselect['error'] ) {
102   $error = $pkgselect['error'];
103   header('Location:index.php?error='. urlencode($pkgselect));
104   die();
105 }
106
107 //  return {
108 //    ( map { $_ => $init_data->{$_} }
109 //          qw( part_pkg security_phrase svc_acct_pop ),
110 //    ),
111 //    %$customer_info,
112 //    'pkg_selector' => $pkgselect,
113 //  };
114 //}
115
116 ?>
117 <SCRIPT TYPE="text/javascript">
118 function enable_order_pkg () {
119   if ( document.OrderPkgForm.pkgpart_svcpart.selectedIndex > 0 ) {
120     document.OrderPkgForm.submit.disabled = false;
121   } else {
122     document.OrderPkgForm.submit.disabled = true;
123   }
124 }
125 </SCRIPT>
126
127 <? include('elements/error.php'); ?>
128
129 <FORM NAME="OrderPkgForm" ACTION="services_new.php" METHOD=POST>
130 <TABLE BGCOLOR="#cccccc" BORDER=0 CELLSPACING=0>
131
132 <TR>
133   <TD COLSPAN=2>
134     <TABLE><TR><TD> <? echo $pkgselect['output']; ?>
135
136   </TD>
137 </TR>
138
139 </TABLE>
140 <BR>
141 <INPUT NAME="submit" TYPE="submit" VALUE="Purchase" <? if ( ! $_POST['pkgpart_svcpart'] ) { echo 'DISABLED'; } ?>>
142 </FORM>
143
144 <? include('elements/menu_footer.php'); ?>
145 <? include('elements/footer.php'); ?>