/**
  * Load the data for a request
  * 
  * This demo emulates loading data from a database and performing
  * a count of the total results, limiting them, ordering them, and
  * searching if a search term is passed in.
  * 
  * @see DataTable_DataTable::loadData()
  */
 public function loadData(DataTable_Request $request)
 {
     // get the name of the sort property that was passed in
     $sortProperty = $this->config->getColumns()->get($request->getSortColumnIndex())->getSortKey();
     // check if a search term was passed in
     if ($request->hasSearch()) {
         // call the searchAll() service method
         $results = $this->browserService->searchAll($request->getSearch(), $this->getSearchableColumnNames(), $request->getDisplayStart(), $request->getDisplayLength(), $sortProperty, $request->getSortDirection());
         // get the total number of results (for pagination)
         $totalLength = $this->browserService->searchAll($request->getSearch(), $this->getSearchableColumnNames(), $request->getDisplayStart(), $request->getDisplayLength(), $sortProperty, $request->getSortDirection(), true);
     } else {
         // call the getAll() service method
         $results = $this->browserService->getAll($request->getDisplayStart(), $request->getDisplayLength(), $sortProperty, $request->getSortDirection());
         // get the total number of results (for pagination)
         $totalLength = $this->browserService->getAll($request->getDisplayStart(), $request->getDisplayLength(), $sortProperty, $request->getSortDirection(), true);
     }
     // return the final result set
     return new DataTable_DataResult($results, $totalLength, $totalLength);
 }
Beispiel #2
0
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
*/
define('_HOMEREXEC', "1");
/* MAIN CLASS modules */
include "class/index.php";
// register the DataTable autoloader
include 'DataTable/Autoloader.php';
spl_autoload_register(array('DataTable_Autoloader', 'autoload'));
// include the Demo DataTable class
include_once 'SipDataTable.php';
// build a Browser Service object based on the type that was selected
include_once 'SipSearchService.php';
$sipService = new SipSearchService($db->hostname_homer);
// instatiate new DataTable
$table = new SipDataTable();
$table->setBrowserService($sipService);
$tmpdata = json_decode($_REQUEST['data'], true);
$data = array();
foreach ($tmpdata as $k => $v) {
    $data[$v['name']] = $v['value'];
}
$request = new DataTable_Request();
$request->fromPhpRequest($data);
// render the JSON data string
echo $table->renderJson($request);
Beispiel #3
0
 /**
  * Call the implementing loadData() method to load static data
  * for a non-AJAX table
  * 
  * @return array
  */
 protected function loadStaticData()
 {
     // find the default sort column and direction from the config
     foreach ($this->config->getColumns() as $index => $column) {
         if ($column->isDefaultSort()) {
             $sortColumnIndex = $index;
             $sortDirection = $column->getDefaultSortDirection();
         }
     }
     // make a fake request object
     $request = new DataTable_Request();
     $request->setDisplayStart(0);
     $request->setDisplayLength($this->config->getStaticMaxLength());
     $request->setSortColumnIndex($sortColumnIndex);
     $request->setSortDirection($sortDirection);
     // load data
     $dataResult = $this->loadData($request);
     // just return the entity array
     return $dataResult->getData();
 }
Beispiel #4
0
function basicFeautures($type, $data)
{
    global $obj, $auth, $search, $db;
    $answer = array();
    switch ($type) {
        case 'session':
            if (!isset($data->username) || !isset($data->password)) {
                if ($auth->checkSession()) {
                    $answer['auth'] = 'true';
                    $answer['status'] = 'ok';
                    $answer['sid'] = session_id();
                } else {
                    $answer['sid'] = session_id();
                    $answer['auth'] = 'false';
                    $answer['status'] = 'wrong-session';
                }
            } else {
                $answer['user'] = $auth->logIn($data);
                if (empty($answer['user'])) {
                    $answer['message'] = 'bad password or username';
                    $answer['status'] = 'wrong-credentials';
                } else {
                    $answer['status'] = 'ok';
                }
            }
            break;
        case 'user':
            $answer['user'] = $auth->getUser();
            if (count($answer['user'])) {
                $answer['status'] = 'ok';
            } else {
                $answer['status'] = 'no-auth';
            }
            break;
            /* SEARCH CALLS */
        /* SEARCH CALLS */
        case 'search/messages/all':
            include 'DataTable/Autoloader.php';
            spl_autoload_register(array('DataTable_Autoloader', 'autoload'));
            include_once 'DataTable/sip/SipDataTable.php';
            include_once 'DataTable/sip/SipSearchService.php';
            $sipService = new SipSearchService($db->hostname_homer);
            $table = new SipDataTable();
            $table->setBrowserService($sipService);
            $tmpdata = array();
            foreach ($data as $k => $v) {
                $tmpdata[$v->name] = $v->value;
            }
            $dt_request = new DataTable_Request();
            $dt_request->fromPhpRequest($tmpdata);
            echo $table->renderJson($dt_request);
            exit;
            break;
            /* messages */
        /* messages */
        case 'message/all/last':
            if ($resp = $search->showMessageAll($data, 0)) {
                $answer['status'] = 'ok';
                $answer['data'] = $resp;
            } else {
                $answer['status'] = 'not good';
                $answer['data'] = array();
            }
            break;
        case 'rtcp/report/all':
            if ($resp = $search->showRtcpAll($data, 0)) {
                $answer['status'] = 'ok';
                $answer['data'] = $resp;
            } else {
                //$answer['status'] = 'not good';
                $answer['status'] = 'not good';
                $answer['data'] = array();
            }
            break;
        case 'cdr/report/all':
            if ($resp = $search->showCdrAll($data, 0)) {
                $answer['status'] = 'ok';
                $answer['data'] = $resp;
            } else {
                $answer['status'] = 'not good';
                $answer['data'] = array();
            }
            break;
            /* statistic */
        /* statistic */
        case 'statistic/method/all':
        case 'statistic/method/total':
            $reqkey = preg_replace('/statistic\\/method\\//', '', $obj->getRURI());
            if ($reqkey == "all") {
                $total = 0;
            } else {
                $total = 1;
            }
            if ($resp = $search->statisticMethod($data, $total)) {
                $answer['status'] = 'ok';
                $answer['data'] = $resp;
            } else {
                $answer['status'] = 'not good';
                $answer['data'] = array();
            }
            break;
        case 'statistic/data/all':
        case 'statistic/data/total':
            $reqkey = preg_replace('/statistic\\/data\\//', '', $obj->getRURI());
            if ($reqkey == "all") {
                $total = 0;
            } else {
                $total = 1;
            }
            if ($resp = $search->statisticData($data, $total)) {
                $answer['status'] = 'ok';
                $answer['data'] = $resp;
            } else {
                $answer['status'] = 'not good';
                $answer['data'] = array();
            }
            break;
        case 'statistic/ip/all':
        case 'statistic/ip/total':
            $reqkey = preg_replace('/statistic\\/ip\\//', '', $obj->getRURI());
            if ($reqkey == "all") {
                $total = 0;
            } else {
                $total = 1;
            }
            if ($resp = $search->statisticIP($data, $total)) {
                $answer['status'] = 'ok';
                $answer['data'] = $resp;
            } else {
                $answer['status'] = 'not good';
                $answer['data'] = array();
            }
            break;
        case 'statistic/useragent/all':
        case 'statistic/useragent/total':
            $reqkey = preg_replace('/statistic\\/useragent\\//', '', $obj->getRURI());
            if ($reqkey == "all") {
                $total = 0;
            } else {
                $total = 1;
            }
            if ($resp = $search->statisticUserAgent($data, $total)) {
                $answer['status'] = 'ok';
                $answer['data'] = $resp;
            } else {
                $answer['status'] = 'not good';
                $answer['data'] = array();
            }
            break;
        case 'alarm/data/all':
        case 'alarm/data/total':
        case 'alarm/data/short':
            $reqkey = preg_replace('/alarm\\/data\\//', '', $obj->getRURI());
            if ($reqkey == "all") {
                $total = 0;
            } else {
                if ($reqkey == "short") {
                    $total = 2;
                } else {
                    $total = 1;
                }
            }
            if ($resp = $search->alarmData($data, $total)) {
                $answer['status'] = 'ok';
                $answer['data'] = $resp;
            } else {
                $answer['status'] = 'not good';
                $answer['data'] = array();
            }
            break;
        case 'alarm/update':
            if ($resp = $search->replaceAlarm($data)) {
                $answer['status'] = 'ok';
                $answer['data'] = $resp;
            } else {
                $answer['status'] = 'not good';
                $answer['data'] = array();
            }
            break;
        case 'alarm/delete':
            if ($resp = $search->deleteAlarm($data)) {
                $answer['status'] = 'ok';
                $answer['data'] = $resp;
            } else {
                $answer['status'] = 'not good';
                $answer['data'] = array();
            }
            break;
        case 'alarm/delete/all':
            if ($resp = $search->deleteAllAlarms()) {
                $answer['status'] = 'ok';
                $answer['data'] = $resp;
            } else {
                $answer['status'] = 'not good';
                $answer['data'] = array();
            }
            break;
        case 'alarm/ack/all':
            console . log("Want to ACK all alarms");
            if ($resp = $search->ackAllAlarms()) {
                $answer['status'] = 'ok';
                $answer['data'] = $resp;
            } else {
                $answer['status'] = 'not good';
                $answer['data'] = array();
            }
            break;
        case 'export/pcap/callid':
        case 'export/text/callid':
            include_once "class/pcap.php";
            /* Call Search */
            $export = new Export();
            $export->setDB($db);
            $text = 0;
            if ($obj->getRURI() == "export/text/callid") {
                $text = 1;
            }
            $resp = $export->generatePcap($data, $text);
            if (!empty($resp)) {
                sendFile(200, $resp[0], $resp[1], $resp[2]);
                exit;
            } else {
                $answer['status'] = 'ok';
                $answer['data'] = array();
                exit;
            }
            break;
            /* ALARMS */
        /* ALARMS */
        default:
            $answer['status'] = 'not good';
            $answer['message'] = 'Unknown get call: [' . $request . ']';
            $answer['data'] = array();
            break;
    }
    return $answer;
}
Beispiel #5
0
 *  
 * This demonstrates how your DataTable doesn't need to be tied to any specific database implementation, etc.
 * Thus, you can use your application's existing ORM, services, etc. to deal with the data 
 * and your DataTable doesn't need to care about where the data came from as long as it's
 * provided an array of entity objects.
 */
// register the DataTable autoloader
include '../src/DataTable/Autoloader.php';
spl_autoload_register(array('DataTable_Autoloader', 'autoload'));
// include the Demo DataTable class
include_once 'DemoDataTable.php';
// define the Browser Service to use for this demo
// either 'db' or 'csv'
define('SERVICE_TO_USE', 'csv');
// build a Browser Service object based on the type that was selected
if (SERVICE_TO_USE == 'db') {
    include_once 'DbBrowserService.php';
    $browserService = new DbBrowserService('localhost', 'browsers', 'root', '');
} elseif (SERVICE_TO_USE == 'csv') {
    include_once 'CsvBrowserService.php';
    $browserService = new CsvBrowserService('data/browsers.csv');
}
// instatiate new DataTable
$table = new DemoDataTable();
// set selected Browser Service to the demo DataTable
$table->setBrowserService($browserService);
// convert DataTable AJAX parameters in request to a DataTable_Request
$request = new DataTable_Request();
$request->fromPhpRequest($_REQUEST);
// render the JSON data string
echo $table->renderJson($request);