File size: 2,442 Bytes
07c3cdd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<?php
if (! isset( $_REQUEST['action'] )) {
    $res['success'] = 'failure';
    $res['message'] = 'You may request an action';
    print G::json_encode( $res );
    die();
}
if (! function_exists( $_REQUEST['action'] ) || !G::isUserFunction($_REQUEST['action'])) {
    $res['success'] = 'failure';
    $res['message'] = 'The requested action does not exist';
    header( "Content-Type: application/json" );
    print G::json_encode( $res );
    die();
}

$functionName = $_REQUEST['action'];
$functionParams = isset( $_REQUEST['params'] ) ? $_REQUEST['params'] : array ();

$functionName( $functionParams );

function getExtJSParams ()
{
    $validParams = array ('callback' => '','dir' => 'DESC','sort' => '','start' => 0,'limit' => 25,'filter' => '','search' => '','action' => '','xaction' => '','data' => '','status' => '','query' => '','fields' => "");
    $result = array ();
    foreach ($validParams as $paramName => $paramDefault) {
        $result[$paramName] = isset( $_REQUEST[$paramName] ) ? $_REQUEST[$paramName] : isset( $_REQUEST[$paramName] ) ? $_REQUEST[$paramName] : $paramDefault;
    }
    return $result;
}

function sendJsonResultGeneric ($response, $callback)
{
    header( "Content-Type: application/json" );
    $finalResponse = G::json_encode( $response );
    if ($callback != '') {
        print $callback . "($finalResponse);";
    } else {
        print $finalResponse;
    }
}

function getNotesList ()
{
    extract( getExtJSParams() );
    if ((isset( $_REQUEST['appUid'] )) && (trim( $_REQUEST['appUid'] ) != "")) {
        $appUid = $_REQUEST['appUid'];
    } else {
        $appUid = $_SESSION['APPLICATION'];
    }
    $usrUid = (isset( $_SESSION['USER_LOGGED'] )) ? $_SESSION['USER_LOGGED'] : "";
    $appNotes = new AppNotes();
    $response = $appNotes->getNotesList( $appUid, '', $start, $limit );

    sendJsonResultGeneric( $response['array'], $callback );
}

function postNote ()
{
    extract( getExtJSParams() );
    if ((isset( $_REQUEST['appUid'] )) && (trim( $_REQUEST['appUid'] ) != "")) {
        $appUid = $_REQUEST['appUid'];
    } else {
        $appUid = $_SESSION['APPLICATION'];
    }
    $usrUid = (isset( $_SESSION['USER_LOGGED'] )) ? $_SESSION['USER_LOGGED'] : "";

    $noteContent = addslashes( $_POST['noteText'] );

    $appNotes = new AppNotes();
    $response = $appNotes->postNewNote( $appUid, $usrUid, $noteContent );

    sendJsonResultGeneric( $response, $callback );
}