0

Hello,
I am having a problem getting variables in my function. Below is my code and an explanation of how it is being called.

1. I set the vars:

error_reporting(2047);
require_once('XML\RPC.php');
define("SITECODE", 000000);
define("REQUEST_URL", "/external/request.php");
define("REQUEST_SERVER", "domain.com");
define("REQUEST_PORT", 443);
define("XML_DEBUG", 0);
$software_name = "domain.com";
$messages = array();
$errors = array();
$plan_array = array("60" => "File",
"61" => "Data",
"62" => "Data & Files",
"63" => "Server",
"64" => "Ultimate",
);
$partner_type = 0; 
$msg = null;
$user =& JFactory::getUser();
$uid = $user->get('id');
$uname = $user->get('username');
include("function.php");

2. Use a switch to pull what function to call:

switch($action){
	case "subaccount_delete":
		subaccount_delete;
		break;
	case "account_switch_plan":
		account_switch_plan();
		break;
	case "update_password":
		update_password();
		break;
	case "addresses":
		addresses();
		break;
	case "update_addresses":
		update_addresses();
		break;
	case "subaccount":		
		sub();
		break;
	case "subaccount_new":  //This is the case for testing.
		subaccount_new();
		break;
	case "confirm_delete":
		cdelete();
		break;
	case "subaccounts":
		subaccounts();
		break;
	case "update_subaccount_emails":
		update_subaccount_emails();
		break;
	default:
		header('index.php?' . $action);
		break;
}

3. The function is located in the function file:

function subaccount_new(){
            $params = array(new XML_RPC_Value(SITECODE, 'int'));
            $params[] = new XML_RPC_Value($uname, 'string');
            $params[] = new XML_RPC_Value(JRequest::getVar('name'), 'string');
            switch (JRequest::getVar('type')) {
                case 0:
                    break;
                case 1:
                    if (JRequest::getVar('1password1') != JRequest::getVar('password2')) {
                        $errors[] = "Passwords do not match.";
                    } else {
                        $params[] = new XML_RPC_Value(JRequest::getVar('email'), 'string');
                        $params[] = new XML_RPC_Value(JRequest::getVar('telephone'), 'string');
                        $params[] = new XML_RPC_Value(JRequest::getVar('1password1'), 'string');
                    }
                    break;
                default:
                    $errors[] = "Invalid subaccount type.";
                    break;
            }
            if (count($errors) == 0) {
				echo 'here';
                $msg = new XML_RPC_Message('account.new_subaccount', $params);
                $cli = new XML_RPC_Client(REQUEST_URL, REQUEST_SERVER, REQUEST_PORT);
                $cli->setDebug(XML_DEBUG);
                $resp = $cli->send($msg);

                if (!$resp) {
                    $errors[] = "Failed to create the subaccount.";
                } else {
                    if (!$resp->faultCode()) {
                        JRequest::getVar('name') == "";
                        JRequest::getVar('email') == "";
                        JRequest::getVar('telephone') == "";
                        $messages[] = "Subaccount created.";
                    } else {
                        $errors[] = "Failed to create the subaccount: " . $resp->faultString();
                    }
                }
            }
			chkerrors($errors, $messages);
            $page = "subaccounts";
}
function chkerrors($errors, $messages){
	$msg1 = "";
    if (count($messages) > 0) {
        $msg1;
        foreach($messages as $message) {
            $msg1 .= "&raquo;&nbsp;" . $message . "<br>";
        }
        msgBox("Messages:",$msg1);
    }

    if (count($errors) > 0) {
        $msg1;
        foreach($errors as $error) {
            $msg1 = "&raquo;&nbsp;" . $error . "<br>";
        }
        msgBox("Error",$msg1);
    }
}

The results I am currently getting:

Notice: Undefined variable: uname in C:\xampp\htdocs\MyHomeSys\components\com_backup\changfunc.php on line 298

Notice: Undefined variable: errors in C:\xampp\htdocs\MyHomeSys\components\com_backup\changfunc.php on line 316
here
Notice: Undefined variable: request_url in C:\xampp\htdocs\MyHomeSys\components\com_backup\changfunc.php on line 319

Notice: Undefined variable: request_server in C:\xampp\htdocs\MyHomeSys\components\com_backup\changfunc.php on line 319

Notice: Undefined variable: request_port in C:\xampp\htdocs\MyHomeSys\components\com_backup\changfunc.php on line 319

Notice: Undefined variable: xml_debug in C:\xampp\htdocs\MyHomeSys\components\com_backup\changfunc.php on line 320

Notice: Undefined variable: messages in C:\xampp\htdocs\MyHomeSys\components\com_backup\changfunc.php on line 336

I have been banging my head over this for a couple days now.

Thanks

Edited by ProfessorPC: n/a

1
Contributor
1
Reply
2
Views
7 Years
Discussion Span
Last Post by ProfessorPC
0

After fighting and fighting with this i have given into just adding the function into the case. This has fixed the problem although not really the way i wanted it to work.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.