So I’m trying to create a process page that runs the process I need no matter what is submitted to it. So it’ll have multiple functions, and depending which form is put through, it’ll do a certain task (add customer, edit customer)
I’m trying to mock the following script:
[php]<?php /**
- AdminProcess.php
- The AdminProcess class is meant to simplify the task of processing
- admin submitted forms from the admin center, these deal with
- member system adjustments.
- Written by: Jpmaster77 a.k.a. The Grandmaster of C++ (GMC)
- Last Updated: August 15, 2004
*/
include("…/session.php");
class AdminProcess
{
/* Class constructor /
function AdminProcess(){
global $session;
/ Make sure administrator is accessing page /
if(!$session->isAdmin()){
header(“Location: …/main.php”);
return;
}
/ Admin submitted update user level form */
if(isset($_POST[‘subupdlevel’])){
$this->procUpdateLevel();
}
/*Admin submitted update tollfree number form /
if(isset($_POST[‘subupdtele’])){
$this->procUpdateTele();
}
/ Admin submitted delete user form /
else if(isset($_POST[‘subdeluser’])){
$this->procDeleteUser();
}
/ Admin submitted delete inactive users form /
else if(isset($_POST[‘subdelinact’])){
$this->procDeleteInactive();
}
/ Admin submitted ban user form /
else if(isset($_POST[‘subbanuser’])){
$this->procBanUser();
}
/ Admin submitted delete banned user form /
else if(isset($_POST[‘subdelbanned’])){
$this->procDeleteBannedUser();
}
/ Admin submitted delete banned user form /
else if(isset($_POST[‘subupdblurb’])){
$this->procUpdateBlurb();
}
/ Admin submitted update e-mail address form /
else if(isset($_POST[‘subupdemail’])){
$this->procUpdateEmail();
}
/Admin submitted update aim username form/
else if(isset($_POST[‘subupdaim’])){
$this->procUpdateAIM();
}
/Admin submitted update aim username form/
else if(isset($_POST[‘subupdymess’])){
$this->procUpdateYmess();
}
/Admin submitted update aim username form/
else if(isset($_POST[‘subupdblog’])){
$this->procUpdateBlog();
}
/ Admin uploaded headshot form /
else if(isset($_POST[‘subheadshot’])){
$this->procHeadshot();
}
/ Should not get here, redirect to home page */
else{
header(“Location: …/main.php”);
}
}
/**
* procUpdateLevel - If the submitted username is correct,
* their user level is updated according to the admin’s
* request.
/
function procUpdateLevel(){
global $session, $database, $form;
/ Username error checking */
$subuser = $this->checkUsername(“upduser”);
/* Errors exist, have user correct them */
if($form->num_errors > 0){
$_SESSION['value_array'] = $_POST;
$_SESSION['error_array'] = $form->getErrorArray();
header("Location: ".$session->referrer);
}
/* Update user level */
else{
$database->updateUserField($subuser, "userlevel", (int)$_POST['updlevel']);
header("Location: ".$session->referrer);
}
}
A BUNCHOF FUNCTIONS ARE LISTED HERE, I just included one for example…
};
/* Initialize process */
$adminprocess = new AdminProcess;
?>[/php]
Here’s the code I have so far, but it’s crappy. I can’t figure out the class thing, and I’m getting errors for the $this function. when I can work it out without errors, it just doesn’t run the function at all:
[php]<?php include("…/session.php");
/* customer_process.php
This script is meant to add new customers to the database, and to edit customer information */
global $session;
/* Make sure administrator is accessing page */
if(!$session->isAdmin()){
header("Location: ../main.php");
return;
}
/* Admin submitted new customer form */
else if(isset($_POST[‘subcustadd’])){
$this->procAddCustomer();
}
else{header("Location: ../main.php");}
function procAddCustomer(){
global $session, $database, $form;
//Insert into database
$insert = "INSERT INTO customers (customer_lname, customer_fname, customer_nickname, customer_telephone, customer_dob, customer_email, customer_address1, customer_address2, customer_city, customer_state, customer_postcode, customer_password, cc_carrier, cc_number, cc_expire, cc_cvv, customer_comments)
VALUES ('".$_POST['cust_lname']."', '".$_POST['cust_fname']."', '".$_POST['cust_nick']."', '".$_POST['cust_tele']."', '".$_POST['cust_dob']."', '".$_POST['cust_email']."', '".$_POST['cust_address1']."', '".$_POST['cust_address2']."', '".$_POST['cust_city']."', '".$_POST['cust_state']."', '".$_POST['cust_postcode']."', '".$_POST['cust_password']."', '".$_POST['cc_type']."', '".$_POST['cc_number']."', '".$_POST['cc_expire']."', '".$_POST['cc_cvv']."', '".$_POST['cust_comments']."')";
$results = "<h3 align='center'>Customer Added. You will be redirected in 3 seconds.</h3>";
};
?>
Thanks in advance for any guidance you may be able to offer!