SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Member
    Join Date
    Mar 2013
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Adding switches to the subscribers account settings

    I am trying to add a 'switch' feature to a company's website in the admin pages. Basically, this company sends out monthly reports to a number of subscribers. They use a database to store all the companies and subscribers info, and in the admin pages of their website they can add new companies and subscribers. When the subscription date is almost ended, then the subscribers get sent an automatic expiry reminder email. However, they want to be able to choose if the subscriber receives the expiry email. So on the admin page where they can edit the subscribers info, I want to put a switch which can set whether they receive it or not. I am trying to work out the best way to do this and which php pages need altering.

    If you want to see some code from likely php pages (e.g. admin/index.php, etc) then let me know

    Thanks

  2. #2
    SitePoint Member
    Join Date
    Mar 2013
    Location
    Pennsylvania
    Posts
    17
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Why don't you add a field to your database table? Then, you can add it to your admin function and allow them to check it or uncheck it.

  3. #3
    SitePoint Member
    Join Date
    Mar 2013
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    For the first part of the problem, I have added a new row (called 'expiry_reminder')to the Subscriber table in the database. I also put in a select box on the admin 'update subsciber' page. However, I cannot seem to find the correct function which would update the 'expiry_reminder' in the database.

    Here is the class formSubscriber (i added the expiry_reminder):

    Code:
    class formSubscriber extends form {
    		
    	/**
    	 * Setup definition
    	 *
    	 */
    	public function __construct()
    	{
    		$this->action = "/az/admin/index.php?page=" . $_GET["page"];
    		$this->formID = "formSubscriber";
    		$this->definition = array(
    			"id" => array(
    				"type" => "hidden",
    				//"value" => getVar('id'),
    			),
    			"companyid" => array(
    				"label" => "Company",
    				"type" => "select",
    				"options" => $this->company->getAllSelect(),
    				//"selected" => getVar('companyid'),
    			),
    			"name" => array(
    				"label" => "Name",
    				"validationEvents" => array("keyup", "blur"),
    				"validation" => array(
    					array("type" => "regexp", "rule" => "[a-z 0-9]{2,128}", "error" => "invalid name"),
    				),
    				//"value" => getVar('name'),
    			),
    			"email" => array(
    				"label" => "Email",
    				"validationEvents" => array("keyup", "blur"),
    				"validation" => array(
    					array("type" => "email"),
    				),
    				//"value" => getVar('email'),
    			),
    			"extra" => array(
    				"label" => "Extra Subscriber",
    				"type" => "select",
    				"class" => "input",
    				"options" => array("No", "Yes"),
    			),
    			"expiry_reminder" => array(
    				"label" => "Expiry Reminder",
    				"type" => "select",
    				"class" => "input",
    				"options" => array("Yes", "No"),
    			),
    			
    			"datetime_added" => array(
    				"label" => "Subscribe Date",
    				"type" => "date",
    				"class" => "input",
    				"selected" => array(
    					date("d"),date("m"),date("Y")
    				),
    				"style" => array(
    					"width:50px;margin-right:3px", 
    					"width:100px;margin-right:3px", 
    					"width:80px;margin-right:10px", 
    					"width:50px;margin-right:3px", 
    					"width:50px;margin-right:3px", 
    					"width:50px;margin-right:3px"
    				),
    			),
    			"datetime_expire" => array(
    				"label" => "Expiry Date",
    				"type" => "date",
    				"class" => "input",
    				"selected" => array(
    					date("d"),date("m"),date("Y")
    				),
    				"style" => array(
    					"width:50px;margin-right:3px", 
    					"width:100px;margin-right:3px", 
    					"width:80px;margin-right:10px", 
    					"width:50px;margin-right:3px", 
    					"width:50px;margin-right:3px", 
    					"width:50px;margin-right:3px"
    				),
    			),
    			"verifySubmit" => array(
    				"type" => "submit",
    				"value" => "Save",
    				"class" => "submit",
    				"style" => "margin-left:100px",
    			),
    			"reset" => array(
    				"type" => "reset",
    				"value" => "Cancel",
    				"class" => "submit",
    				"style" => "margin-left:16px",
    			)
    		);
    	}	
    }
    And then here is the section of index.php from the admin files which relates to the 'subscriber-update':

    Code:
    case 'subscriber-update':
    	
    		// check if form validates		
    		$_FORMSUBSCRIBER = new formSubscriber();
    		if ($_FORMSUBSCRIBER->submitted() && $_FORMSUBSCRIBER->validate($_POST)) {				
    			// update database
    			$_SUBSCRIBER = new subscriber();
    			$_SUBSCRIBER->update($_FORMSUBSCRIBER->prepareData($_POST),array("verifySubmit","reset"));
    			header("Location: /az/admin/subscriber-list/".$_POST['companyid']);
    			exit;
    		}
    	
    		$content = array('subscriber_update.php');
    	break;
    And here is the code from subscriber_update.php:

    Code:
    <?php
    
    //make sure companyid exists
    $companyid = array_key_exists("companyid",$_REQUEST) ? $_REQUEST['companyid'] : exit('no company id');
    
    // initiate objects
    $_SUBSCRIBER = new subscriber();
    $_FORMSUBSCRIBER = new formSubscriber();
    
    // if id exists, get data
    if(array_key_exists('subscriberid',$_REQUEST)){
    	$data = $_SUBSCRIBER->getByID($_REQUEST['subscriberid'],$_REQUEST['companyid']);
    	$_FORMSUBSCRIBER->setFormValues($data, true);
    	$h1 = "Edit Subscriber";
    }else{
    	$data = array("companyid"=>$companyid);
    	$_FORMSUBSCRIBER->setFormValues($data, true);
    	$h1 = "Add Subscriber";
    }
    ?>
    <h1><?= $h1; ?></h1>
    <?
    
    
    $_FORMSUBSCRIBER->outputHTML();
    echo $_FORMSUBSCRIBER->defaultJavaScriptSetup();
    
    ?>
    I cannot see what else I need to modify to enable the expiry_reminder row to be updated.

  4. #4
    SitePoint Member
    Join Date
    Mar 2013
    Location
    Pennsylvania
    Posts
    17
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    To start with, look at the formSubscriber() class and make sure that it includes your new field (expiry_reminder)

  5. #5
    SitePoint Member
    Join Date
    Mar 2013
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    have i not already done that in the definition array of formSubscriber class:
    Code:
    "expiry_reminder" => array(
    				"label" => "Expiry Reminder",
    				"type" => "select",
    				"class" => "input",
    				"options" => array("Yes", "No"),
    			),


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •