PHP Classes
elePHPant
Icontem

File: AdvATE/AdvATEexample2.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Andrew Sullivan  >  Ajax Table Edit  >  AdvATE/AdvATEexample2.php  >  Download  
File: AdvATE/AdvATEexample2.php
Role: Example script
Content type: text/plain
Description: Another example for AdvATE
Class: Ajax Table Edit
Edit data in an HTML table using AJAX
Author: By
Last change:
Date: 8 years ago
Size: 2,711 bytes
 

Contents

Class file image Download
<?php
//ini_set("display_errors", "1");
//ini_set("error_reporting", "E_ALL");

/*
    This is another example...closer to "real world" usage.
    I created a small address book type thing, that is updated completely
    by ajax. You can add on to this by including links for add/remove...I'm
    working on integrating this into the next version.
*/

include("./AdvATE.class.php");
$at = new TableEditor;

extract($_POST);

if (
$FormRequest) {

   
$at->SetForm('name','text');
   
$at->SetForm('address','area');
   
$at->SetForm('phone','text');
   
$at->SetForm('phonetype','radio',array('Home' => 'Home', 'Work' => 'Work', 'Cell' => 'Cell'));
   
$at->SetForm('sex','radio', array('Male' => 'Male', 'Female' => 'Female'));

    echo
$at->HandleFormRequest($_POST['type'], $_POST['old']);
   
} else if (
$FormSave) {
   
   
$data = file_get_contents("./test2.txt");
   
$data = unserialize($data);

   
$data[$rowid][$colid] = $new;

   
$open = fopen("./test2.txt", 'w');
   
fwrite($open, serialize($data));
   
fclose($open);
   
    echo
$new;
   
} else {
   
   
//the display properties for the odd and even rows
   
$odd = array('style' => 'background-color: #CCCCCC;');
   
$even = array('style' => 'background-color: #EEEEEE;');

   
//the display properties for the overall table
   
$table = array('align' => 'center', 'cellpadding' => '3', 'cellspacing' => '0', 'width' => '50%');

   
//table column header information
   
$headers = array("Name", "Address", "Phone", "Type", "Sex");
   
$headerattrib = array('style' => 'background-color: skyblue');
   
   
$at->SetEvenRowAttribs($even);
   
$at->SetOddRowAttribs($odd);
   
   
$at->SetTableAttribs($table);
   
   
$at->SetHeaderAttribs($headerattrib);
   
$at->SetHeaders($headers);
   
   
$at->SetSubmit("AdvATEexample2.php");
   
    if (
file_exists("./test2.txt")) {
       
$example = file_get_contents("./test2.txt");
       
$example = unserialize($example);
    } else {
        include(
"example2data.php");
       
$example = $data;
    }
   
   
/*
        for this example, I formated the data similar to how it would come from
        a database query...do a print_r on it to see
       
        because of that, we have to do some prep first
       
    */
   
   
$data = array();
   
    foreach (
$example as $id => $row) {
       
$data[$id]['name'] = array('data' => $row['name'], 'input' => 'name');
       
$data[$id]['address'] = array('data' => $row['address'], 'input' => 'address');
       
$data[$id]['phone'] = array('data' => $row['phone'], 'input' => 'phone');
       
$data[$id]['phonetype'] = array('data' => $row['phonetype'], 'input' => 'phonetype');
       
$data[$id]['sex'] = array('data' => $row['sex'], 'input' => 'sex');
    }
   
   
$at->SetData($data);
   
    echo
$at->GenerateTable();
   
   
//echo "<pre>";
    //print_r($data);

}

?>