Example #1
0
<?php

//RECUPERACIO D'UNA TAULA LA BASE DE DADES//
////////////////////////////////////////////
//Carregar codi de la Classe client
require 'classes/client.class.php';
if ($_GET['action'] == 'ClientList') {
    //Instància de l'objecte
    $obj_client = new client();
    //Invocar mètode (Recollir tots les incidencies)
    $consulta = $obj_client->getClientList();
    //Cal que el primer index sigui 1 (per poder usar foreach en JS)
    for ($i = 1; $dades[$i] = mysql_fetch_array($consulta); $i++) {
    }
    array_pop($dades);
    //Eliminar l'últim ja que crea un últim element buid
    //Enviar capaçalera indicant JSON
    header('Content-type: application/json');
    //Codificar en JSON i retornar petició en un array entenible per JS
    echo json_encode($dades);
}
if ($_GET['action'] == 'InserirClient') {
    $client = json_decode($_GET['client']);
    $obj_client = new client();
    $obj_client->add($client);
}
     if ($client->fails()) {
         $app->view->setData('error', "1");
         $app->view->setData('msg', $client->getError());
         $app->render(new u('msg'));
     } else {
         $app->view->setData('success', "1");
         $app->view->setData('msg', "Successfully Client Added");
         $app->render(new u('msg'));
     }
 });
 //Show
 $app->get('/view', function () use($app) {
     $getclientList = new client();
     // $dues = $getclientList->sumDueLimit();
     // $app->view->setData('sumdues',$dues );
     $cols = $getclientList->getClientList();
     $app->view->setData('rows', $cols);
     $app->render(new u('client.view'));
 });
 /******************Add Balance Data Processing **************************************************/
 $app->post('/confirm_add_balance', function () use($app) {
     $POST = $app->request()->post();
     $client = new client($POST);
     $client->saveAddBalance();
     if ($client->fails()) {
         $app->view->setData('error', "1");
         $app->view->setData('msg', $client->getError());
         $app->render(new u('msg'));
     } else {
         $app->view->setData('success', "1");
         $app->view->setData('msg', "Successfully Balance Added");