Example #1
0
 public function select($table, $options = array(), $bind = "")
 {
     $fields = isset($options['fields']) ? $options['fields'] : '*';
     if (strrpos($table, "`") === false) {
         $table = "`{$table}`";
     }
     if (strrpos($fields, "*") === false && strrpos($fields, "`") === false) {
         $cf = '';
         $ex = explode(',', $fields);
         foreach ($ex as $field) {
             $fld_tbl = trim(\cx\app\main_functions::get_db_table($field));
             $safe_tbl = !empty($fld_tbl) ? "`{$fld_tbl}`." : '';
             $cf .= $safe_tbl . '`' . trim(\cx\app\main_functions::get_db_column($field)) . '` , ';
         }
         $fields = rtrim($cf, ", ");
     }
     $other = isset($options['distinct']) ? 'DISTINCT ' : '';
     $other .= isset($options['other']) ? $options['other'] . ' ' : '';
     $sql = "SELECT " . $other . $fields . " FROM " . $table . "";
     if (isset($options['inner_join'])) {
         $sql .= " INNER JOIN " . $options['inner_join'];
     }
     if (isset($options['natural_join'])) {
         $sql .= " NATURAL JOIN " . $options['natural_join'];
     }
     if (isset($options['left_join'])) {
         $sql .= " LEFT JOIN " . $options['left_join'];
     }
     if (isset($options['on'])) {
         $sql .= " ON " . $options['on'];
     }
     if (isset($options['where'])) {
         $sql .= " WHERE " . $options['where'];
     }
     if (isset($options['group_by'])) {
         $sql .= " GROUP BY " . $options['group_by'];
     }
     if (isset($options['having'])) {
         $sql .= " HAVING " . $options['having'];
     }
     if (isset($options['order_by'])) {
         $sql .= " ORDER BY " . $options['order_by'];
     }
     if (isset($options['limit'])) {
         $sql .= " LIMIT " . $options['limit'];
     }
     if (isset($options['pageinator_limit'])) {
         $sql .= $options['pageinator_limit'];
     }
     if (isset($options['procedure'])) {
         $sql .= " PROCEDURE " . $options['procedure'];
     }
     $sql .= ";";
     $fetch_mode = isset($options['fetch']) ? $options['fetch'] : 'all';
     return $this->run($sql, $bind, $fetch_mode);
 }
Example #2
0
function ssp_output($numrows, $obj_model, $columns)
{
    $draw = isset($_GET['draw']) ? $_GET['draw'] : 1;
    echo '{
      "draw": ' . intval($draw) . ',
      "recordsTotal": ' . $numrows . ',
      "recordsFiltered": ' . $numrows . ',			
      ';
    if ($numrows > 0) {
        echo '"data":[';
        $first = true;
        $Column = array();
        $allow_html = true;
        $rows = $obj_model->get_members($allow_html);
        foreach ($rows as $row) {
            if ($first) {
                $first = false;
            } else {
                echo ',';
            }
            foreach ($columns as $column) {
                $db_col = \cx\app\main_functions::get_db_column($column['db']);
                if (isset($column['fn_results']) && function_exists($column['fn_results'])) {
                    $funct = $column['fn_results'];
                    $out = $funct($row[$db_col]);
                } else {
                    $out = $row[$db_col];
                }
                if (isset($column['textsize']) && strlen($row[$db_col]) > $column['textsize']) {
                    $out = substr(strip_tags($out), 0, $column['textsize']);
                }
                if (isset($column['hyper'])) {
                    $hyper = $column['hyper'];
                    if (isset($column['id'])) {
                        $db_id_col = \cx\app\main_functions::get_db_column($column['id']);
                        $hlink = $hyper . $row[$db_id_col];
                    } else {
                        $hlink = $hyper;
                    }
                    $Column[] = "<a href='{$hlink}'>{$out}</a>";
                } else {
                    $Column[] = $out;
                }
            }
            echo json_encode($Column);
            $Column = '';
            $Column = array();
        }
        echo ']}';
    } else {
        echo '"data":[]}';
    }
}