Example #1
0
 /**
  * Gets whereSQL and bind_params array using jui_filter_rules class
  *
  * @param $filter_rules
  * @return array
  */
 public function get_whereSQL($filter_rules)
 {
     $conn = $this->get_db_conn();
     if (!$conn) {
         return false;
     }
     $rdbms = $this->db_settings['rdbms'];
     $use_prepared_statements = $this->db_settings['use_prepared_statements'];
     $pst_placeholder = $this->db_settings['pst_placeholder'];
     if (count($filter_rules) == 0) {
         $result = array('sql' => '', 'bind_params' => array());
     } else {
         $jfr = new jui_filter_rules($conn, $use_prepared_statements, $pst_placeholder, $rdbms);
         $res = $jfr->parse_rules($filter_rules);
         $result = array("sql" => $res["sql"], "bind_params" => $res["bind_params"]);
         $last_jfr_error = $jfr->get_last_error();
         if (!is_null($last_jfr_error['error_message'])) {
             $result = $last_jfr_error;
         }
     }
     if ($this->debug_mode) {
         array_push($this->debug_message, 'WHERE  SQL: ' . $result['sql']);
         array_push($this->debug_message, 'BIND PARAMS: ' . print_r($result['bind_params'], true));
         if ($use_prepared_statements) {
             $bind_params_type = '';
             foreach ($res["bind_params"] as $bind_param) {
                 $bind_params_type .= gettype($bind_param) . ' ';
             }
             array_push($this->debug_message, 'BIND PARAMS TYPE: ' . $bind_params_type);
         }
         array_push($this->debug_message, 'PREPARED STATEMENTS: ' . ($use_prepared_statements ? "yes" : "no"));
         if (!is_null($last_jfr_error['error_message'])) {
             array_push($this->debug_message, 'FILTER ERROR: ' . print_r($last_jfr_error['error_message'], true));
         }
     }
     return $result;
 }
 *
 * @version 1.0.7 (08 Apr 2015)
 * @author Christos Pontikis http://pontikis.net
 * @license  http://opensource.org/licenses/MIT MIT license
 **/
// PREVENT DIRECT ACCESS (OPTIONAL) --------------------------------------------
$isAjax = isset($_SERVER['HTTP_X_REQUESTED_WITH']) and strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) === 'xmlhttprequest';
if (!$isAjax) {
    print 'Access denied - not an AJAX request...' . ' (' . __FILE__ . ')';
    exit;
}
// required
require_once '/path/to/dacapo.php';
require_once '/path/to/jui_filter_rules.php';
// Get params
$a_rules = $_POST['a_rules'];
if (count($a_rules) == 0) {
    exit;
}
// create new datasource                                            // CONFIGURE
$db_settings = array('rdbms' => 'MYSQLi', 'db_server' => 'localhost', 'db_user' => 'DB_USER_HERE', 'db_passwd' => 'DB_PASS_HERE', 'db_name' => 'DB_NAME', 'db_port' => '3306', 'charset' => 'utf8', 'use_pst' => true, 'pst_placeholder' => 'question_mark');
$ds = new dacapo($db_settings, null);
// print result
$jfr = new jui_filter_rules($ds);
$jfr->set_allowed_functions(array('date_encode'));
$result = $jfr->parse_rules($a_rules);
$last_error = $jfr->get_last_error();
if (!is_null($last_error['error_message'])) {
    $result['error'] = $last_error;
}
echo json_encode($result);