<?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_user.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", "My Account - Add User" );
/* Main defines */
$ubF->tpl->define ( array (
"index" => "user/wrapper/default.html"
) );
$ubF->tpl->define ( array (
"menu" => "user/account/menu.html"
) );
$ubF->tpl->define ( array (
"body" => "user/account/add_user.html"
) );
$ubF->session->Validate ( 'U_A_', 0 );
/* Initialize Message */
$message = "";
/*
* $query = "SELECT uid, password FROM users";
* $result = $data['ubix_db']->query($query);
* while ($row = $result->fetch_row()) {
* $query = "UPDATE users SET password = '" . hash("SHA256", $row[1]) . "' WHERE uid = " . $row[0];
* $data['ubix_db']->query($query);
* }
* $result->free();
*/
$acls = array (
'U_A_' => 0,
'U_B_' => 0,
'U_C_' => 0,
'U_P_' => 0,
'U_V_' => 0,
'U_D_' => 0
);
$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"]}' );
if ( isset ( $form_data ['up'] ) && $ubF->session->account_type <= 5 ) {
if ( isset ( $form_data ['acl'] ) ) {
foreach ( array_merge ( $acls, $form_data ['acl'] ) as $acl_code => $acl_val )
$master_acl->{$acl_code} [0] = $acl_val;
foreach ( $master_acl as $acl_code => $acl_val )
if ( $acl_val [0] == 1 )
$session_acl .= $acl_code . ",";
}
if ( strlen ( $form_data ['first_name'] ) < 1 )
$message .= "Invalid First Name!<br />";
if ( strlen ( $form_data ['last_name'] ) < 1 )
$message .= "Invalid Last Name!<br />";
if ( strlen ( $form_data ['email'] ) < 5 )
$message .= "Invalid E-Mail!<br />";
if ( $message == "" ) {
$password = generatePassword ( 8, 8 );
$query = "INSERT INTO users (password, email, first_name, last_name, account_number, session_acl, master_acl, status, account_type, created, last_updated) VALUES('" . hash ( "SHA256", $password ) . "','" . $form_data ['email'] . "','" . $form_data ['first_name'] . "','" . $form_data ['last_name'] . "','" . $ubF->session->account_number . "','" . $session_acl . "','" . json_encode ( $master_acl ) . "',1,10," . time () . "," . time () . ")";
$result = $ubF->DB['main']->query ( $query );
if ( $ubF->DB['main']->affected_rows == 1 ) {
$message = "User Added";
if ( substr ( $ubF->session->company, -1 ) == "s" )
$company = $ubF->session->company . "'";
else
$company = $ubF->session->company . "'s";
$eMsg = "Welcome " . $form_data ['first_name'] . ",<br />\n<br />\n" . $form_data ['session']->first_name . " has added you to " . $company . " uBix Technologies account.<br />\n<br />\nTo access your account please use the following access information:<br />\n<br />\nPortal Address: <a href=\"https://manage.ubixtechnologies.net\">https://manage.ubixtechnologies.net</a><br />\nUsername: " . $form_data ['email'] . "<br />\nTemporary Password: " . $password . "<br />\n";
$data->libs['ubf']->sendMail ( 'Welcome to uBix Technologies', $eMsg, $form_data ['email'], '', 'cwolsen@ubixos.com' );
$form_data ['email'] = "";
$form_data ['first_name'] = "";
$form_data ['last_name'] = "";
}
else
$message = "User Exists";
}
}
else if ( isset ( $form_data ['up'] ) )
$message = "<h2>You're not authorized to add sub accounts!</h2>";
$acl = "";
foreach ( $acls as $acl_code => $val ) {
if ( $form_data ['acl'] [$acl_code] == 1 )
$acl .= "<input type=\"checkbox\" name=\"data[acl][$acl_code]\" value=\"1\" checked>" . $master_acl->{$acl_code} [1] . "<br />\n";
else
$acl .= "<input type=\"checkbox\" name=\"data[acl][$acl_code]\" value=\"1\">" . $master_acl->{$acl_code} [1] . "<br />\n";
}
$ubF->tpl->assign ( "EMAIL", $form_data ['email'] );
$ubF->tpl->assign ( "FIRST_NAME", $form_data ['first_name'] );
$ubF->tpl->assign ( "LAST_NAME", $form_data ['last_name'] );
$ubF->tpl->assign ( "ACLS", $acl );
$ubF->tpl->assign ( "MESSAGE", $message );
/* 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" );
function generatePassword ( $length = 9 ) {
$vowels = "aeuyAEUY";
$consonants = "bdghjmnpqrstvzBDGHJLMNPQRSTVWXZ0123456789!@#$%";
$password = '';
$alt = time () % 2;
for ( $i = 0 ; $i < $length ; $i++ ) {
if ( $alt == 1 ) {
$password .= $consonants [(rand () % strlen ( $consonants ))];
$alt = 0;
}
else {
$password .= $vowels [(rand () % strlen ( $vowels ))];
$alt = 1;
}
}
return $password;
}
?>