PHP Classes

File: aededl_example.php

Recommend this page to a friend!
  Classes of Sjon   AEDEDL   aededl_example.php   Download  
File: aededl_example.php
Role: Example script
Content type: text/plain
Description: Example page.
Class: AEDEDL
Author: By
Last change:
Date: 23 years ago
Size: 5,161 bytes
 

Contents

Class file image Download
<?php
/**********************************************************************
 * Sjon's PHP Classes Library -> AEDEDL (AddEditDeleteEnableDisableListing)
 * Written by SJONdaMON, SPG2000. http://www.sjondamon.org/?KW=PHP
 * All Rights Reserved. Licenced GPL. http://www.sjondamon.org/?KW=GPL
 **********************************************************************/
   
require "aededl.php";

/*
    The following code is an basic example of how to use aededl.
    Just update the connection data, and create a table called 'aededl_examle'
    with the following sql_query:

        CREATE TABLE aededl_example (
            id int(8) unsigned not null auto_increment,
            name varchar(64) not null,
            email varchar(128) not null,
            website varchar(128) not null,
            active enum('0', '1') default '1' not null,
            primary key (id),
            unique (id)
        );

    Quick Data Filler:

        INSERT INTO aededl_example VALUES ('', 'Name 1', 'mail@domain1.com', 'http://www.domain1.com/', '1');
        INSERT INTO aededl_example VALUES ('', 'Name 2', 'mail@domain2.com', 'http://www.domain2.com/', '1');
        INSERT INTO aededl_example VALUES ('', 'Name 3', 'mail@domain3.com', 'http://www.domain3.com/', '1');
        INSERT INTO aededl_example VALUES ('', 'Name 4', 'mail@domain4.com', 'http://www.domain4.com/', '1');
        INSERT INTO aededl_example VALUES ('', 'Name 5', 'mail@domain5.com', 'http://www.domain5.com/', '1');
        INSERT INTO aededl_example VALUES ('', 'Name 6', 'mail@domain6.com', 'http://www.domain6.com/', '0');
        INSERT INTO aededl_example VALUES ('', 'Name 7', 'mail@domain7.com', 'http://www.domain7.com/', '0');
        INSERT INTO aededl_example VALUES ('', 'Name 8', 'mail@domain8.com', 'http://www.domain8.com/', '0');
        INSERT INTO aededl_example VALUES ('', 'Name 9', 'mail@domain9.com', 'http://www.domain9.com/', '0');
        INSERT INTO aededl_example VALUES ('', 'Name 10', 'mail@domain10.com', 'http://www.domain10.com/', '1');
*/

   
class aededl_example extends aededl {
        var
$table_name = "aededl_example";
        var
$table_conf = array ('id' => 0, 'name' => '', 'email' => '', 'website' => '', 'active' => 1);
        var
$data = array(); // get's filled by constructor
       
var $report = ""; // get's filled by parent-class functions. (mysql_insert_id, mysql_num_rows, mysql_affected_rows)
       
var $error = ""; // get's filled by parent-class functions. (mysql_error)

       
function aededl_example () {
           
// You only need to make all variables used GLOBAL here. All other functions use the internal $this->data variable...
           
GLOBAL $id, $name, $email, $website, $active;

           
// Edit these to get a valid connection to your mysql database...
           
$this->dblink = mysql_connect("localhost", "username", "password");
           
mysql_select_db("test", $this->dblink);

           
// This will load either submitted data or their defaults into $this->data
            // If you add variables or change their names, be shure to update this part... : )
           
$this->data['id'] = (empty($id)) ? "":$id;
           
$this->data['name'] = (empty($name)) ? "":$name;
           
$this->data['email'] = (empty($email)) ? "":$email;
           
$this->data['website'] = (empty($website)) ? "":$website;
           
$this->data['active'] = (empty($active)) ? "1":$active;
        }

        function
form () {
           
// just for documentation's sake... :)
           
echo "Report: ".$this->report."<BR>\n";
            echo
"Error: ".$this->error."<BR>\n";
?>
<FORM METHOD="POST">
<INPUT TYPE="hidden" NAME="id" VALUE="<? echo $this->data['id']; ?>"><BR>
Name : <INPUT TYPE="text" NAME="name" VALUE="<? echo $this->data['name']; ?>"><BR>
Email : <INPUT TYPE="text" NAME="email" VALUE="<? echo $this->data['email']; ?>"><BR>
Website : <INPUT TYPE="text" NAME="website" VALUE="<? echo $this->data['website']; ?>"><BR>
Active : <INPUT TYPE="text" NAME="active" VALUE="<? echo $this->data['active']; ?>"><BR>
<INPUT TYPE="submit" VALUE="Send"><BR>
</FORM>
<?
       
}

        function
listing_item () {
            GLOBAL
$PHP_SELF;
           
$endis = (empty($this->data['active'])) ? "enable":"disable"; // empty($i) returns true when $i = 0, false otherwise...
?>
<TR>
    <TD><A HREF="mailto:<? echo $this->data['email']; ?>"><? echo $this->data['name']; ?></A></TD>
    <TD><A HREF="<? echo $this->data['website']; ?>"><? echo $this->data['website']; ?></A></TD>
    <TD><A HREF="<? echo $PHP_SELF."?action=edit&id=".$this->data['id']; ?>">edit</A></TD>
    <TD><A HREF="<? echo $PHP_SELF."?action=delete&id=".$this->data['id']; ?>">delete</A></TD>
    <TD><A HREF="<? echo $PHP_SELF."?action=".$endis."&id=".$this->data['id']."\">".$endis; ?></A></TD>
</TR>
<?
       
}
    }




   
// Start of actual program...

   
$action = (isset($action)) ? $action:"none";
   
$CP = new aededl_example();

    echo
"<HTML>\n<BODY>\n<CENTER>\n<A HREF=".$PHP_SELF.">List All</A> - <A HREF=".$PHP_SELF."?action=add>Add Entry</A><P>\n<TABLE>\n\n";

    switch (
$action) {
        case
"add":
           
$CP->add();
            break;
        case
"edit":
           
$CP->edit();
            break;
        case
"delete":
           
$CP->delete();
            break;
        case
"enable":
           
$CP->enable();
            break;
        case
"disable":
           
$CP->disable();
            break;
        default:
           
$CP->listing();
    }

    echo
"\n\n</TABLE>\n</CENTER>\n</BODY>\n</HTML>";
?>