Newer
Older
ubFramework / Portal / docroot / admin / accounts / add_account.php
@Christopher W. Olsen Christopher W. Olsen on 10 Dec 2017 10 KB Cleaning Up Making It A Sub Module
<?php

/*
 * ****************************************************************************************
 * Copyright (c) 2013, 2014 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: add_account.php 940 2017-09-07 20:12:42Z reddawg $
 *
 * ***************************************************************************************
 */

/* Main include info */
ini_set ( 'include_path', $_SERVER ['DOCUMENT_ROOT'] . "/include/" );
include ("config.php");

/* Assign the page title */
$ubF->tpl->assign ( "PAGE_TITLE", "Admin: Accounts - New Account" );

/* Main defines */
$ubF->tpl->define ( array (
    "index" => "admin/wrapper/default.html" 
) );
$ubF->tpl->define ( array (
    "menu" => "admin/accounts/menu.html" 
) );
$ubF->tpl->define ( array (
    "body" => "admin/accounts/add_account.html" 
) );

$ubF->session->Validate ( 'A_G_', 0 );

$query = "SELECT aid, account_number, customer_since, status, company, address, address2, city, state, zipcode, website, title, first_name, last_name, telephone, fax, cell, email FROM accounts WHERE aid = " . $data ['data'] ['aid'];

$res = $ubF->DB['main']->query ( $query );

if ( $res )
  $qData = $res->fetch_assoc ();

$mapFields = array (
    "account_number" => 13,
    "company" => 3,
    "address" => 3,
    "address2" => 0,
    "city" => 3,
    "state" => 2,
    "zipcode" => 5,
    "website" => 9,
    "title" => 3,
    "first_name" => 1,
    "last_name" => 1,
    "telephone" => 10,
    "fax" => 0,
    "cell" => 0,
    "email" => 7 
);

if ( !isset ( $data ['data'] ['account_number'] ) )
  $data ['data'] ['account_number'] = $data->libs['ubf']->genAccountNumber ();

if ( !isset ( $data ['data'] ['customer_since'] ) )
  $data ['data'] ['customer_since'] = time ();

$message = "";

if ( isset ( $data ['data'] ['aiu'] ) ) {
  
  /* Verify Fields Data */
  foreach ( $mapFields as $key => $val )
    if ( strlen ( $data ['data'] [$key] ) < $val )
      $message .= "<h5>$key Needs To Be Atleast $val Characters</h5>";
  
  if ( strlen ( $message ) == 0 ) {
    $lup = time ();
    
    $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) VALUES($lup,'" . $data ['data'] ['account_number'] . "',$lup,1,'" . $data ['data'] ['company'] . "','" . $data ['data'] ['address'] . "','" . $data ['data'] ['address2'] . "','" . $data ['data'] ['city'] . "','" . $data ['data'] ['state'] . "','" . $data ['data'] ['zipcode'] . "','" . $data ['data'] ['website'] . "','" . $data ['data'] ['title'] . "','" . $data ['data'] ['first_name'] . "','" . $data ['data'] ['last_name'] . "','" . $data ['data'] ['telephone'] . "','" . $data ['data'] ['fax'] . "','" . $data ['data'] ['cell'] . "','" . $data ['data'] ['email'] . "',$lup,$lup)";
    
    if ( $ubF->DB['main']->query ( $query ) === true ) {
      $password = $data->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('" . $data ['data'] ['email'] . "', '" . hash ( "SHA256", $password ) . "', '" . $data ['data'] ['first_name'] . "', '" . $data ['data'] ['last_name'] . "', '" . $data ['data'] ['account_number'] . "', '" . $session_acl . "', '" . json_encode ( $master_acl ) . "', 1, 5, " . time () . ", " . time () . ")";
      
      if ( $ubF->DB['main']->query ( $query ) === false ) {
        $message = "<h3>Account Created - Error Creating User</h3>";
        
        $e_message = "Welcome aboard " . $data ['data'] ['first_name'] . ",<br>\n<br>\n";
        $e_message .= "Thank you for choosing PSC Tech as your reliable IT partner for " . $data ['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: " . $data ['data'] ['account_number'] . "<br>\n";
        $e_message .= "Account Manager: Douglas Goldstein<br>\n";
        $e_message .= "Account Manager E-Mail: dgoldstein@ubixtechnologies.com<br>\n";
        $e_message .= "Account Manager Direct Line: 516-423-0666<br>\n";
        $e_message .= "Service Line: 844-842-UBIX (8249)<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@ubixtechnologies.com.<br>\n<br>\n";
        
        $recipient = $data ['data'] ['first_name'] . " " . $data ['data'] ['last_name'] . " <" . $data ['data'] ['email'] . ">";
        
        foreach ( $mapFields as $key => $val )
          $data ['data'] [$key] = "";
        
        $data->libs['ubf']->sendMail ( "Welcome to PSC Tech", $e_message, $recipient, "sales@ubixtechnologies.net", "newaccount@ubixtechnologies.net" );
      }
      else {
        $message = "<h3>Account Created - User Created</h3>";
        
        $e_message = "Welcome aboard " . $data ['data'] ['first_name'] . ",<br>\n<br>\n";
        $e_message .= "Thank you for choosing PSC Tech as your reliable IT partner for " . $data ['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: " . $data ['data'] ['account_number'] . "<br>\n";
        $e_message .= "Account Manager: Douglas Goldstein<br>\n";
        $e_message .= "Account Manager E-Mail: dgoldstein@PSCTech.us<br>\n";
        $e_message .= "Account Manager Direct Line: 516-423-0666<br>\n";
        $e_message .= "Service Line: 844-842-UBIX (8249)<br>\n<br>\n";
        $e_message .= "Portal Information:<br>\n<br>\n";
        $e_message .= "Portal Address: <a href=\"https://manage.ubixtechnologies.net/\">https://manage.ubixtechnologies.net</a><br>\n";
        $e_message .= "Portal Username: " . $data ['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@ubixtechnologies.com.<br>\n<br>\n";
        
        $recipient = $data ['data'] ['first_name'] . " " . $data ['data'] ['last_name'] . " <" . $data ['data'] ['email'] . ">";
        
        foreach ( $mapFields as $key => $val )
          $data ['data'] [$key] = "";
        
        $data->libs['ubf']->sendMail ( "Welcome to PSC Tech", $e_message, $recipient, "sales@ubixtechnologies.net", "newaccount@ubixtechnologies.net" );
      }
    }
    else
      $message = "<h3>Error Creating Account</h3>";
  }
}
else {
  /* Populate Fields From Database */
  foreach ( $mapFields as $key => $val )
    if ( !isset ( $data ['data'] [$key] ) )
      $data ['data'] [$key] = $qData [$key];
}

$ubF->tpl->assign ( "AID", $qData ['aid'] );
$ubF->tpl->assign ( "MESSAGE", $message );

/* Account Information */
$ubF->tpl->assign ( "ACCOUNT_NUMBER", $data ['data'] ['account_number'] );
$ubF->tpl->assign ( "CUSTOMER_SINCE", date ( "m/d/Y", $data ['data'] ['customer_since'] ) );
$ubF->tpl->assign ( "STATUS", $data->libs['ubf']->aStatus [$qData [status]] );

/* Company Information */
$ubF->tpl->assign ( "COMPANY", $data ['data'] ['company'] );
$ubF->tpl->assign ( "ADDRESS", $data ['data'] ['address'] );
$ubF->tpl->assign ( "ADDRESS2", $data ['data'] ['address2'] );
$ubF->tpl->assign ( "CITY", $data ['data'] ['city'] );
$ubF->tpl->assign ( "STATE", $data ['data'] ['state'] );
$ubF->tpl->assign ( "ZIPCODE", $data ['data'] ['zipcode'] );
$ubF->tpl->assign ( "WEBSITE", $data ['data'] ['website'] );

/* Account Guarantor */
$ubF->tpl->assign ( "TITLE", $data ['data'] ['title'] );
$ubF->tpl->assign ( "FIRST_NAME", $data ['data'] ['first_name'] );
$ubF->tpl->assign ( "LAST_NAME", $data ['data'] ['last_name'] );
$ubF->tpl->assign ( "TELEPHONE", $data ['data'] ['telephone'] );
$ubF->tpl->assign ( "FAX", $data ['data'] ['fax'] );
$ubF->tpl->assign ( "CELL", $data ['data'] ['cell'] );
$ubF->tpl->assign ( "EMAIL", $data ['data'] ['email'] );

/* Parse and print */
$ubF->tpl->parse ( "MENU", array (
    "menu" 
) );
$ubF->tpl->parse ( "BODY", array (
    "body" 
) );
$ubF->tpl->parse ( "INDEX", array (
    "index" 
) );
$ubF->tpl->FastPrint ( "INDEX" );

?>