PHP Classes

File: example.php

Recommend this page to a friend!
  Classes of Dave Smith   noSQL Packages   example.php   Download  
File: example.php
Role: Example script
Content type: text/plain
Description: Example Usage
Class: noSQL Packages
Manage the approval of packages stored in files
Author: By
Last change:
Date: 8 years ago
Size: 6,807 bytes
 

Contents

Class file image Download
<?php
/*
example usage script
member of docStat class - document oriented noSQL approval system
version 0.1 beta 10/28/2015
*/
$includeDeleted = false;

include(
'docstat.class.php');
$docStat = new docStat('',$includeDeleted);
if( !empty(
$docStat->error) ){
   
    die(
$docStat->error);
   
}

$status = ( empty($_REQUEST['status']) ) ? 1 : $_REQUEST['status'];

$statusSelect = '<select name="status">';
foreach(
$docStat->statusText as $key=>$value ){
   
    if(
$key == 0 ){ continue; }
   
   
$selected = ( $status == $key ) ? ' selected' : '';
   
   
$statusSelect .= '<option value="'.$key.'"'.$selected.'>'.$value.'</option>';
   
}
$statusSelect .= '</select>';

if( !empty(
$_REQUEST['formPosted']) ){
   
   
$title = ( empty($_REQUEST['title']) ) ? '' : $_REQUEST['title'];
   
$userID = ( empty($_REQUEST['userID']) ) ? 0 : $_REQUEST['userID'];
   
$packageID = ( empty($_REQUEST['packageID']) ) ? null : $_REQUEST['packageID'];
   
$lastID = ( empty($_REQUEST['lastID']) ) ? 0 : $_REQUEST['lastID'];
   
$recordCount = ( empty($_REQUEST['recordCount']) ) ? 0 : $_REQUEST['recordCount'];
   
    if( empty(
$_REQUEST['action']) ){
       
       
$docStat->error = 'No action selected';
       
    }else{
       
        switch(
$_REQUEST['action'] ){
           
            case
'create':
               
$result = $docStat->createPackage($title,$userID,$status,$packageID);
                break;
               
            case
'read':
               
$result = $docStat->readPackage($packageID);
                break;
               
            case
'update':
               
$result = $docStat->updatePackage($packageID,$status,$userID,$title);
                break;
           
            case
'list':
               
$result = $docStat->packageList($status,$lastID,$recordCount);
                break;
           
            case
'readHistory':
               
$result = $docStat->readPackageHistory($packageID);
                break;
           
            case
'clearHistory':
               
$result = $docStat->clearPackageHistory($packageID,$userID);
                break;
           
        }
       
    }
   
}

?>
<!DOCTYPE html>
<html>
    <head>
        <title>docstat Usage Example</title>
    </head>
    <body>
        <h3>docstat Usage Example</h3>
        <h4>returned results are shown at bottom of the page</h4>
<?php
if( !empty($docStat->error) ){
?>
<hr>
        <h4 style="color: red;">Errors reported</h4>
        <div><?PHP echo $docStat->error;?></div>
<?php
}
?>
<hr>
        <h4>Package</h4>
        <form method="POST">
            <label for="title">Package Title:</label><br>
            (string)<br>
            <input type="text" name="title" value="<?PHP echo ( empty($_REQUEST['title']) ) ? '' : $_REQUEST['title'];?>"><br><br>
            <label for="status">Status:</label><br>
            (deleted files will <?PHP echo ( empty($includeDeleted) ) ? 'NOT' : '';?> be processed)<br>
            <?PHP echo $statusSelect;?><br><br>
            <label for="userID">User/Admin ID:</label><br>
            (numeric id - leave blank if not needed)<br>
            <input type="text" name="userID" value="<?PHP echo ( empty($_REQUEST['userID']) ) ? '' : $_REQUEST['userID'];?>"><br><br>
            <label for="packageID">Package ID:</label><br>
            (numeric id - new package will auto-increment last record if not supplied)<br>
            <input type="text" name="packageID" value="<?PHP echo ( empty($_REQUEST['packageID']) ) ? '' : $_REQUEST['packageID'];?>"><br><br>
            Action: (select one)<br>
            <input type="radio" name="action" value="create"> Create new package - object->createPackage(title[,userID=0][,status=1][,id=0])<br>
            <input type="radio" name="action" value="read"> Read package data - object->readPackage(id)<br>
            <input type="radio" name="action" value="update"> Update package - object->updatePackage(id,[,status=0][,userID=0][,title=''])<br>
            <input type="radio" name="action" value="delete" disabled="true"> Delete package - use update package with a deleted status - remove package folder to permanantly delete<br>
            <br><input type="hidden" name="formPosted" value="1"><input type="submit" name="formSubmit" value="Go">
        </form>
        <hr>
        <h4>Package List</h4>
        <form method="POST">
            <label for="status">Status:</label><br>
            (deleted files are <?PHP echo ( empty($includeDeleted) ) ? 'NOT' : '';?> included)<br>
            <?PHP echo $statusSelect;?><br><br>
            <label for="lastID">Last record ID:</label><br>
            (numeric id - indicates the last record accessed, useful for paging - leave blank to start at first record)<br>
            <input type="text" name="lastID" value="<?PHP echo ( empty($_REQUEST['lastID']) ) ? '' : $_REQUEST['lastID'];?>"><br><br>
            <label for="recordCount">Records to return:</label><br>
            (numeric id - number of records to return, useful for paging - leave blank to return all records)<br>
            <input type="text" name="recordCount" value="<?PHP echo ( empty($_REQUEST['recordCount']) ) ? '' : $_REQUEST['recordCount'];?>"><br><br>
            object->packageList([status=0][,lastID=0][,recordCount=0])
            <br><input type="hidden" name="action" value="list"><input type="hidden" name="formPosted" value="1"><input type="submit" name="formSubmit" value="Go">
        </form>
        <hr>
        <h4>History</h4>
        <form method="POST">
            <label for="packageID">Package ID:</label><br>
            (numeric id)<br>
            <input type="text" name="packageID" value="<?PHP echo ( empty($_REQUEST['packageID']) ) ? '' : $_REQUEST['packageID'];?>"><br><br>
            <label for="userID">User/Admin ID:</label><br>
            (numeric id - used to log who cleared history - leave blank if not needed)<br>
            <input type="text" name="userID" value="<?PHP echo ( empty($_REQUEST['userID']) ) ? '' : $_REQUEST['userID'];?>"><br><br>
            Action: (select one)<br>
            <input type="radio" name="action" value="readHistory"> Read history data - object->readPackageHistory(id)<br>
            <input type="radio" name="action" value="clearHistory"> Clear history data - object->clearPackageHistory(id[,userID])<br>
            <br><input type="hidden" name="formPosted" value="1"><input type="submit" name="formSubmit" value="Go">
        </form>
        <hr>
        <h4>Result</h4>
<?php
if( !empty($result) ){
?>
<div><?PHP var_dump($result);?></div>
<?php
}
?>
</body>
</html>