PHP Classes

File: example.php

Recommend this page to a friend!
  Classes of Shannon Wynter   Flow Chart   example.php   Download  
File: example.php
Role: Example script
Content type: text/plain
Description: A basic example
Class: Flow Chart
Generate help desk questions work flow
Author: By
Last change:
Date: 18 years ago
Size: 2,915 bytes
 

Contents

Class file image Download
<?php
@session_start();
require_once(
'Smarty/Smarty.class.php');
require_once(
'FlowChart.class.php');

// Extend the FloeChart class to change the root dir for smarty
class HelpDeskFlowChart extends FlowChart {
    var
$BaseDir = "/var/www/helpdesk/smarty";
}

class
Helpdesk {
   
// Storage for the flowchart
   
var $Flowchart;

   
// Database setup
   
var $MySQLHost = 'localhost';
    var
$MySQLUser = 'helpdesk';
    var
$MySQLPass = 'password';
    var
$MySQLDatabase = 'Helpdesk';
       
    function
Helpdesk () {
       
$this->_MySQL = mysql_connect($this->MySQLHost,$this->MySQLUser,$this->MySQLPass);
       
mysql_select_db($this->MySQLDatabase);
       
       
// Cheating - smarty is already loaded in flowchart
       
$this->Flowchart = new HelpDeskFlowChart();
       
        
$this->DoTickSheet ();
    }
   
    function
DoTickSheet () {
        if (
$this->GetUsername()) {
           
$this->AssignVar('Username',$_SESSION['Helpdesk']['Username']);
            if (
$this->DisplayDetails()) {
                if (
$this->Flowchart->Run()) {
                    if (
$this->GetComments()) {
                       
$this->SendEmail();
                    }
                }
            }
        } else {
           
$this->Flowchart->Smarty->display('username.tpl');
        }
    }
   
    function
AssignVar ($Varname,$Varvalue) {
       
//Cheating function to cut back on typing
       
$this->Flowchart->Smarty->assign($Varname,$Varvalue);
    }
   
    function
GetUsername () {
        if (!isset(
$_SESSION['Helpdesk']['Username'])) {
            if (isset(
$_POST['Submit']) && isset($_POST['Username'])) {
                if (
$_POST['Username'] != 'username@isp.com' && preg_match("/^[A-z0-9][\w\.-]*@[A-z0-9][\w\-\.]+\.[A-z0-9]{2,6}$/",$_POST['Username'])) {
                   
$_SESSION['Helpdesk']['Username'] = $_POST['Username'];
                   
$_SESSION['Helpdesk']['CallStartTime'] = time();
                } else {
                   
$this->AssignVar('Error','That doesn\'t appear to be a valid username');
                }
            }
            if (!isset(
$_SESSION['Helpdesk']['Username'])) {
                return
false;
            }
        }
        return
true;
    }

    function
Cleanup() {
        unset(
$_SESSION['Helpdesk']);
    }
   
    function
GetComments() {
        if (!isset(
$_SESSION['Helpdesk']['Comments'])) {
            if (!isset(
$_POST['Comments'])) {
               
$this->Flowchart->Smarty->display('comments.tpl');
                return
false;
            } else {
               
$_SESSION['Helpdesk']['Comments'] = $_POST['Comments'];
            }
        }
        return
true;
    }
   
    function
SendEmail() {
        echo
"Ticksheet completed<br />\n<pre>";
       
$History = $this->Flowchart->GetHistory();
        print
'Call taken '.date('d-m-Y H:i:s')."\n";
        print
'Username: '.$_SESSION['Helpdesk']['Username']."\n\n";
        print
"Time taken: ".(time() - $_SESSION['Helpdesk']['CallStartTime'])." seconds\n\n";
       
        foreach (
$History as $Name=>$Value) {
            print
$Value['Question'].' -> '.$Value['SelectedValue']."\n";
        }
        print
"\nComments:\n";
        print
$_SESSION['Helpdesk']['Comments']."\n";
        if (
$this->Flowchart->EndType == 4) {
            print
"\nThis call has been flagged for further investiagaion\n";
        }

        print
"</pre>";
        print
'<br /><a href="index.php"> Take new call </a>';
    }

}


$Helpdesk = new Helpdesk();