Icontem

File: examples/4gl/ex_groupContainer.lib

Recommend this page to a friend!
  Classes of philippe thomassigny  >  WAJAF  >  examples/4gl/ex_groupContainer.lib  >  Download  
File: examples/4gl/ex_groupContainer.lib
Role: Auxiliary data
Content type: text/plain
Description: Auxiliary data
Class: WAJAF
Build single page applications
Author: By
Last change: patch 2.00.02
Date: 5 years ago
Size: 1,769 bytes
 

Contents

Class file image Download
<?php

/* We simulate a table with 10 records.
   We simulate insert, update, delete but do not do it really
*/
class ex_groupContainer
{

  function myform()
  {
    $order = null;
    if (isset($_POST['order']))
      $order = $_POST['order'];
    if (isset($_POST['key']))
      $key = $_POST['key'];
    if (isset($_POST['mode']))
      $mode = $_POST['mode'];
    if (!$order || !$mode)
      return json_encode( array('error' => true, 'errormessage' => 'Error: there is no order or mode to listen to the form' ));

    switch($order)
    {
      case 'getrecord':
        $r = $this->getRecord($key);
        return json_encode($r);
      case 'first':
        $r = $this->getRecord(1);
        return json_encode($r);
      case 'last':
        $r = $this->getRecord(10);
        return json_encode($r);
      case 'previous':
        if ($key > 1)
          $key--;
        $r = $this->getRecord($key);
        return json_encode($r);
      case 'next':
        if ($key < 10)
          $key++;
        $r = $this->getRecord($key);
        return json_encode($r);
      case 'submit':
        break;
    }

    // randomly return a sucess or an error
    if (rand(0, 1000) < 500)
      return json_encode( array('success' => true ));
    return json_encode( array('success' => false, 'messages' => array('text' => 'Error: This is a simulated error from the server. It happens randomly to show how the errors are handled.')));
  }

  function getRecord($key)
  {
    if (!$key || !is_numeric($key) || $key < 1 || $key > 10)
      $key = rand(1,10);
    return array($key => array('key' => $key, 'fullname' => 'Juan Perez Hernandez '.$key, 'address1' => "Street $key, num $key, int. $key", 'address2' => "City of city$key, State of state$key, Mexico"));
  }
}

?>