<?php /* * **************************************************************************************** * Copyright (c) 2013, 2014, 2016 Christopher W. Olsen <cwolsen@ubixtechnologies.com> * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are * permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this list of * conditions, the following disclaimer and the list of authors. Redistributions in binary * form must reproduce the above copyright notice, this list of conditions, the following * disclaimer and the list of authors in the documentation and/or other materials provided * with the distribution. Neither the name of the uBix Cube Project nor the names of its * contributors may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL * THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * $Id: index_json.php 943 2017-09-07 20:16:43Z reddawg $ * * *************************************************************************************** */ /* Main include info */ ini_set ( 'include_path', $_SERVER ['DOCUMENT_ROOT'] . "/include/" ); include ("config.php"); $ubF->session->Validate_JSON ( 'A_V_', 1 ); switch ($form_data ['req']) { case 'accounts' : $query = "SELECT aid,account_number,company,status,customer_since,contract_start,contract_end,pastdue_balance,current_balance FROM accounts ORDER BY status, company"; $res = $ubF->DB ['main']->query ( $query ); $rows = array (); while ( $qData = $res->fetch_assoc () ) { switch ($qData ['status']) { case 0 : $status = "Inactive"; break; case 1 : $status = "Active"; break; case 2 : $status = "Suspended"; break; default : $status = "Invalid"; break; } $rows [] = array ( '<a id="' . $qData ['account_number'] . '" class="edit_account">' . $qData ['account_number'] . '</a>', $qData ['company'], $status, date ( "m/d/Y", $qData ['customer_since'] ), date ( "m/d/Y", $qData ['contract_start'] ), date ( "m/d/Y", $qData ['contract_end'] ), '$' . number_format ( $qData ['pastdue_balance'], 2 ), '$' . number_format ( $qData ['current_balance'], 2 ) ); } $rData ['data'] = $rows; $res->free (); break; case "account_info" : $query = "SELECT * FROM accounts WHERE account_number = '" . $form_data ['account_number'] . "'"; $res = $ubF->DB ['main']->query ( $query ); $rData ['data'] = $res->fetch_assoc (); $res->free (); break; case "account_update" : $query = "UPDATE accounts SET status = " . $form_data ['status'] . ", company = '" . $form_data ['company'] . "', address = '" . $form_data ['address'] . "', address2 = '" . $form_data ['address2'] . "', city = '" . $form_data ['city'] . "', state = '" . $form_data ['state'] . "', zipcode = '" . $form_data ['zipcode'] . "', title = '" . $form_data ['title'] . "', first_name = '" . $form_data ['first_name'] . "', last_name = '" . $form_data ['last_name'] . "', telephone = '" . $form_data ['telephone'] . "', fax = '" . $form_data ['fax'] . "', cell = '" . $form_data ['cell'] . "', email = '" . $form_data ['email'] . "' WHERE account_number = '" . $form_data ['account_number'] . "'"; if ($ubF->DB ['main']->query ( $query ) === false) { $rData ['data'] = Array ( 'ret' => 0, 'ret_string' => 'Error Updating Account. Please Try Again.' ); } else { $rData ['data'] = Array ( 'ret' => 1, 'ret_string' => 'Account Updated Successfully' ); } break; case "account_numberGen" : $rData ['data'] ['account_number'] = $ubF->libs ['ubf']->genAccountNumber (); $rData ['data'] ['customer_since'] = date ( "Y-m-d" ); break; case "account_add" : $rData ['data'] ['ret'] = 0; $mapFields = array ( "account_number" => array ( 13, 'Account Number' ), "company" => array ( 3, 'Company' ), "address" => array ( 3, 'Address' ), "address2" => array ( 0, 'Address 2' ), "city" => array ( 3, 'City' ), "state" => array ( 2, 'State' ), "zipcode" => array ( 5, 'Zip Code' ), "website" => array ( 9, 'Web Site' ), "title" => array ( 3, 'Title' ), "first_name" => array ( 1, 'First Name' ), "last_name" => array ( 1, 'Last Name' ), "telephone" => array ( 10, 'Telephone' ), "fax" => array ( 0, 'Fax' ), "cell" => array ( 0, 'Cell' ), "email" => array ( 7, 'E-Mail' ) ); $message = ""; /* Verify Fields Data */ foreach ( $mapFields as $key => $val ) if (strlen ( $form_data [$key] ) < $val [0]) $message .= $val [1] . " is invalid.\n"; if (strlen ( $message ) == 0) { $lup = time (); $accountCode = $ubF->libs ['voip']->genAccountCode (); $query = "INSERT INTO accounts (last_update,account_number,customer_since,status,company,address,address2,city,state,zipcode,website,title,first_name,last_name,telephone,fax,cell,email,contract_start,contract_end,account_code,voip_code,system_version) VALUES($lup,'" . $form_data ['account_number'] . "',$lup,1,'" . $form_data ['company'] . "','" . $form_data ['address'] . "','" . $form_data ['address2'] . "','" . $form_data ['city'] . "','" . $form_data ['state'] . "','" . $form_data ['zipcode'] . "','" . $form_data ['website'] . "','" . $form_data ['title'] . "','" . $form_data ['first_name'] . "','" . $form_data ['last_name'] . "','" . $form_data ['telephone'] . "','" . $form_data ['fax'] . "','" . $form_data ['cell'] . "','" . $form_data ['email'] . "',$lup,$lup,'" . $accountcode . "','" . $accountCode . "',2)"; system ( "echo " . $query . " >> /tmp/SPBX.log" ); if ($ubF->DB ['main']->query ( $query ) === true) { $rData ['data'] ['ret'] = 1; $password = $ubF->libs ['ubf']->generatePassword ( 8 ); /* Defaults For Master Account */ $acls = array ( 'U_A_' => 1, 'U_B_' => 1, 'U_C_' => 1, 'U_P_' => 1, 'U_V_' => 1, 'U_D_' => 1 ); $master_acl = json_decode ( '{"A_G_":[0,"General"],"A_A_":[0,"Accounts"],"A_B_":[0,"Billing"],"A_C_":[0,"uBix Cube"],"A_P_":[0,"Platform"],"A_V_":[0,"VoIP"],"A_D_":[0,"ubDialin"],"A_F_":[0,"ubFaxin"],"A_S_":[0,"Secure PDF"],"U_G_":[0,"General"],"U_A_":[0,"My Account"],"U_B_":[0,"Billing"],"U_C_":[0,"uBix Cube"],"U_P_":[0,"Platform"],"U_V_":[0,"VoIP"],"U_D_":[0,"Dialer"],"U_F_":[0,"ubFaxin"],"U_S_":[0,"Secure PDF"]}' ); foreach ( $master_acl as $acl_code => $acl_val ) if ($acl_val [0] == 1) $session_acl .= $acl_code . ","; $query = "INSERT INTO users (email, password, first_name, last_name, account_number, session_acl, master_acl, status, account_type, created, last_updated) VALUES('" . $form_data ['email'] . "', '" . hash ( "SHA256", $password ) . "', '" . $form_data ['first_name'] . "', '" . $form_data ['last_name'] . "', '" . $form_data ['account_number'] . "', '" . $session_acl . "', '" . json_encode ( $master_acl ) . "', 1, 5, " . time () . ", " . time () . ")"; system ( "echo " . $query . " >> /tmp/SPBX.log" ); if ($ubF->DB ['main']->query ( $query ) === false) { $message = "Account Created - Error Creating User"; $e_message = "Welcome aboard " . $form_data ['first_name'] . ",<br>\n<br>\n"; $e_message .= "Thank you for choosing SpherePBX as well rounded communications partner for " . $form_data ['company'] . ". As we continue to activate your services you will receive updates letting you know that they are available along with basic instructions on how to use them.<br>\n<br>\n"; $e_message .= "Please keep the following information for your records as it will help expedite all support requests.<br>\n<br>\n"; $e_message .= "Account Number: " . $form_data ['account_number'] . "<br>\n"; $e_message .= "Account Manager: Douglas Goldstein<br>\n"; $e_message .= "Account Manager E-Mail: dgoldstein@SpherePBX.com<br>\n"; $e_message .= "Account Manager Direct Line: 631-438-0612<br>\n"; $e_message .= "Service Line: 888-609-VoIP (8647)<br>\n<br>\n"; $e_message .= "If you have any questions concerning your new services please contact your account manager. If you need to request support please call our service line or e-mail support@SpherePBX.com.<br>\n<br>\n"; $recipient = $form_data ['first_name'] . " " . $form_data ['last_name'] . " <" . $form_data ['email'] . ">"; $ubF->libs ['ubf']->sendMail ( "Welcome to SpherePBX", $e_message, $recipient, "sales@SpherePBX.com", "newaccount@SpherePBX.com" ); } else { $message = "Account Created - User Created"; $e_message = "Welcome aboard " . $form_data ['first_name'] . ",<br>\n<br>\n"; $e_message .= "Thank you for choosing SpherePBX as well rounded communications partner for " . $form_data ['company'] . ". As we continue to activate your services you will receive updates letting you know that they are available along with basic instructions on how to use them.<br>\n<br>\n"; $e_message .= "Please keep the following information for your records as it will help expedite all support requests.<br>\n<br>\n"; $e_message .= "Account Number: " . $form_data ['account_number'] . "<br>\n"; $e_message .= "Account Manager: Douglas Goldstein<br>\n"; $e_message .= "Account Manager E-Mail: dgoldstein@SpherePBX.com<br>\n"; $e_message .= "Account Manager Direct Line: 631-438-0612<br>\n"; $e_message .= "Service Line: 888-609-VoIP (8647)<br>\n<br>\n"; $e_message .= "Portal Information:<br>\n<br>\n"; $e_message .= "Portal Address: <a href=\"https://portal.spherepbx.com/\">https://portal.spherepbx.com</a><br>\n"; $e_message .= "Portal Username: " . $form_data ['email'] . "<br>\n"; $e_message .= "Portal Temporary Password: " . $password . "<br>\n<br>\n"; $e_message .= "If you have any questions concerning your new services please contact your account manager. If you need to request support please call our service line or e-mail support@SpherePBX.com.<br>\n<br>\n"; $recipient = $form_data ['first_name'] . " " . $form_data ['last_name'] . " <" . $form_data ['email'] . ">"; $ubF->libs ['ubf']->sendMail ( "Welcome to SpherePBX", $e_message, $recipient, "sales@SpherePBX.com", "newaccount@SpherePBX.com" ); } } } $rData ['data'] ['ret_string'] = $message; break; default : $rData ['data'] = array ( 0 ); break; } print (json_encode ( $rData )) ; ?>