Beispiel #1
0
 function data()
 {
     // Sanitize the GET variables here.
     $cfg = array('columns' => array(), 'order' => array(), 'start' => 0, 'length' => -1, 'draw' => 0, 'search' => '', 'where' => '', 'mrColNotEmpty' => '');
     //echo '<pre>';print_r($_GET);return;
     $searchcols = array();
     // Process $_POST array
     foreach ($_POST as $k => $v) {
         if ($k == 'search') {
             $cfg['search'] = $v['value'];
         } elseif (isset($cfg[$k])) {
             $cfg[$k] = $v;
         }
     }
     // endforeach
     // Add columns to config
     $cfg['search_cols'] = $searchcols;
     //echo '<pre>';print_r($cfg);
     try {
         // Get model
         $obj = new Tablequery($cfg);
         //echo '<pre>';print_r($obj->fetch($cfg));
         echo json_encode($obj->fetch($cfg));
         // If there is an encoding error, show it
         if (json_last_error() != JSON_ERROR_NONE) {
             echo json_last_error_msg();
             print_r($obj->fetch($cfg));
         }
     } catch (Exception $e) {
         echo json_encode(array('error' => $e->getMessage(), 'draw' => intval($cfg['draw'])));
     }
 }
Beispiel #2
0
 function data()
 {
     // Sanitize the GET variables here.
     $cfg = array('iDisplayStart' => 0, 'iDisplayLength' => 0, 'sEcho' => 0, 'iColumns' => 0, 'iSortingCols' => 0, 'sSearch' => '', 'mrColNotEmpty' => '');
     $sortcols = $searchcols = array();
     // Process $_GET array
     foreach ($_GET as $k => $v) {
         if (isset($cfg[$k])) {
             $cfg[$k] = $v;
         } elseif (preg_match('/^mDataProp_(\\d+)/', $k, $matches)) {
             // Get colname from mDataProp_xx
             $cols[$matches[1]] = $v;
         } elseif (preg_match('/^iSortCol_(\\d+)/', $k, $matches)) {
             $col = $matches[1];
             if (!isset($_GET["bSortable_{$v}"])) {
                 continue;
             }
             if ($_GET["bSortable_{$v}"] == "true") {
                 $sortcols[$v] = 'DESC';
                 if (isset($_GET["sSortDir_{$col}"])) {
                     if ($_GET["sSortDir_{$col}"] === 'asc') {
                         $sortcols[$v] = 'ASC';
                     }
                 }
             }
         } elseif (preg_match('/^sSearch_(\\d+)/', $k, $matches)) {
             $col = $matches[1];
             if (!isset($_GET["bSearchable_{$col}"])) {
                 continue;
             }
             if ($_GET["bSearchable_{$col}"] == "true" && $v) {
                 $searchcols[$col] = $v;
             }
         }
     }
     // Add columns to config
     $cfg['cols'] = $cols;
     $cfg['sort_cols'] = $sortcols;
     $cfg['search_cols'] = $searchcols;
     //print_r($cfg);
     try {
         // Get model
         $obj = new Tablequery($cfg);
         echo json_encode($obj->fetch($cfg));
     } catch (Exception $e) {
         echo json_encode(array('error' => $e->getMessage(), 'sEcho' => intval($cfg['sEcho'])));
     }
 }