RT# 82949 - changes section name from fees to pricing, better opiton
[freeside.git] / fs_selfservice / wordpress / services_new.php
1 <?php
2
3 require( dirname( __FILE__ ) . '/wp-blog-header.php' );
4
5 $freeside = new FreesideSelfService();
6
7 if ( isset($_POST['pkgpart_svcpart']) && $_POST['pkgpart_svcpart'] ) {
8
9   $results = array();
10
11   $params = array( 'custnum', 'pkgpart' );
12
13   $matches = array();
14   if ( preg_match( '/^(\d+)_(\d+)$/', $_POST['pkgpart_svcpart'], $matches ) ) {
15     $_POST['pkgpart'] = $matches[1];
16     $_POST['svcpart'] = $matches[2];
17     $params[] = 'svcpart';
18     $svcdb = $_POST['svcdb'];
19     if ( $svcdb == 'svc_acct' ) { $params[] = 'domsvc'; }
20   } else {
21     $svcdb = 'svc_acct';
22   }
23
24   if ( $svcdb == 'svc_acct' ) {
25
26     array_push($params, 'username', '_password', '_password2', 'sec_phrase', 'popnum' );
27
28     if ( strlen($_POST['_password']) == 0 ) {
29       $results['error'] = 'Empty password';
30     }
31     if ( $_POST['_password'] != $_POST['_password2'] ) {
32       $results['error'] = 'Passwords do not match';
33       $_POST['_password'] = '';
34       $_POST['_password2'] = '';
35     }
36
37   } elseif ( $svcdb == 'svc_phone' ) {
38
39     array_push($params, 'phonenum', 'sip_password', 'pin', 'phone_name' );
40
41   } else {
42     die("$svcdb not handled on process_order_pkg yet");
43   }
44
45   if ( ! $results['error'] ) {
46     $order_pkg = array(
47       'session_id' => $_COOKIE['freeside_session_id'],
48     );
49
50     foreach ( $params AS $param ) {
51       $order_pkg[$param] = $_POST[$param];
52     }
53
54     $results = $freeside->order_pkg($order_pkg);
55
56   }
57
58   if ( isset($results['error']) && $results['error'] ) {
59     $_REQUEST['freeside_error'] = $results['error'];
60   } else {
61     #$pkgnum = $results['pkgnum'];
62     #wp_redirect("services.php"); # #pkgnum ?
63     #wp_redirect("service_order_success.php"); # #pkgnum ?
64     wp_redirect("example_selfservice.php"); # #pkgnum ?
65     die();
66   }
67
68 }
69
70 $pkgselect = $freeside->mason_comp( [
71     'session_id' => $_COOKIE['freeside_session_id'],
72     'comp'       => '/edit/cust_main/first_pkg/select-part_pkg.html',
73     'args'       => [ 'password_verify', 1,
74                       'onchange'       , 'enable_order_pkg()',
75                       #'relurls'        , 1,
76                       'empty_label'    , 'Select package',
77                       'form_name'      , 'OrderPkgForm',
78                       'pkgpart_svcpart', $_POST['pkgpart_svcpart'],
79                       'username'       , $_POST['username'],
80                       'password'       , $_POST['_password'],
81                       'password2'      , $_POST['_password2'],
82                       'popnum'         , $_POST['popnum'],
83                       'saved_domsvc'   , $_POST['domsvc'],
84                     ],
85 ]);
86
87 get_header();
88
89 ?>
90
91 <h3>Order a new service</h3>
92
93 <SCRIPT TYPE="text/javascript">
94 function enable_order_pkg () {
95   if ( document.OrderPkgForm.pkgpart_svcpart.selectedIndex > 0 ) {
96     document.OrderPkgForm.submit.disabled = false;
97   } else {
98     document.OrderPkgForm.submit.disabled = true;
99   }
100 }
101 </SCRIPT>
102
103 <?php include(dirname(__FILE__).'/elements/error.php'); ?>
104
105 <FORM NAME="OrderPkgForm" ACTION="services_new.php" METHOD=POST>
106
107 <?php echo $pkgselect['output']; ?>
108
109 <BR>
110 <INPUT NAME="submit" TYPE="submit" VALUE="Purchase" <?php if ( ! $_POST['pkgpart_svcpart'] ) { echo 'DISABLED'; } ?>>
111 </FORM>
112
113 <?php get_footer(); ?>