Fixing jqgrid queries

skala
Julio Montoya 15 years ago
parent ca8508a2d9
commit 01c273e183
  1. 25
      main/inc/ajax/model.ajax.php
  2. 32
      main/inc/lib/database.lib.php
  3. 8
      main/inc/lib/model.lib.php

@ -1,4 +1,7 @@
<?php
/* For licensing terms, see /license.txt */
//@todo this could be integrated in the inc/lib/model.lib.php
$action = $_GET['a'];
require_once '../global.inc.php';
@ -11,7 +14,7 @@ $table = '';
$page = intval($_REQUEST['page']); //page
$limit = intval($_REQUEST['rows']); // quantity of rows
$sidx = intval($_REQUEST['sidx']); //index to filter
$sidx = $_REQUEST['sidx']; //index to filter
$sord = $_REQUEST['sord']; //asc or desc
if (!in_array($sord, array('asc','desc'))) {
$sord = 'desc';
@ -37,10 +40,11 @@ switch ($action) {
exit;
}
if( $count >0 ) {
$total_pages = ceil($count/$limit);
} else {
$total_pages = 0;
$total_pages = 0;
if ($count >0) {
if (!empty($limit)) {
$total_pages = ceil($count/$limit);
}
}
if ($page > $total_pages) {
@ -56,6 +60,9 @@ switch ($action) {
$obj->delete($_REQUEST['id']);
}
$columns = array('name', 'description', 'actions');
if(!in_array($sidx, $columns)) {
$sidx = 'name';
}
$result = Database::select('*', $obj->table, array('order'=>"$sidx $sord", 'LIMIT'=> "$start , $limit"));
break;
case 'get_promotions':
@ -63,16 +70,16 @@ switch ($action) {
$obj->delete($_REQUEST['id']);
}
$columns = array('name', 'career', 'description', 'actions');
$result = Database::select('p.id, p.name, p.description, c.name as career', "$obj->table p LEFT JOIN ".Database::get_main_table(TABLE_CAREER)." c ON c.id = p.career_id ", array('order' =>"$sidx $sord", 'LIMIT'=> "$start , $limit"));
if(!in_array($sidx, $columns)) {
$sidx = 'name';
}
$result = Database::select('p.id,p.name, p.description, c.name as career', "$obj->table p LEFT JOIN ".Database::get_main_table(TABLE_CAREER)." c ON c.id = p.career_id ", array('order' =>"$sidx $sord", 'LIMIT'=> "$start , $limit"));
break;
default:
exit;
}
//echo '<pre>';
if (in_array($action, array('get_careers','get_promotions'))) {
//3. Creating an obj to return a json
$responce = new stdClass();

@ -1349,7 +1349,7 @@ class Database {
}
$sql = "SELECT $clean_columns FROM $table_name $conditions";
$sql = "SELECT $clean_columns FROM $table_name $conditions";
@ -1381,6 +1381,7 @@ class Database {
}
$return_value = '';
foreach ($conditions as $type_condition => $condition_data) {
$type_condition = strtolower($type_condition);
switch($type_condition) {
case 'where':
foreach ($condition_data as $condition => $value_array) {
@ -1405,7 +1406,34 @@ class Database {
}
break;
case 'order':
$return_value .= " ORDER BY $condition_data";
$order_array = explode(' ', $condition_data);
if (!empty($order_array)) {
if (count($order_array) > 1) {
$order_array[0] = self::escape_string($order_array[0]);
if (!empty($order_array[1])) {
$order_array[1] = strtolower($order_array[1]);
$order = 'desc';
if (in_array($order_array[1], array('desc', 'asc'))) {
$order = $order_array[1];
}
}
$return_value .= ' ORDER BY '.$order_array[0].' '.$order;
} else {
$return_value .= ' ORDER BY '.$order_array[0].' DESC ';
}
}
break;
case 'limit':
$limit_array = explode(',', $condition_data);
if (!empty($limit_array)) {
if (count($limit_array) > 1) {
$return_value .= ' LIMIT '.intval($limit_array[0]).' , '.intval($limit_array[1]);
} else {
$return_value .= ' LIMIT '.intval($limit_array[0]);
}
}
break;
}

@ -13,8 +13,13 @@ class Model {
var $columns;
public function __construct() {
}
public function find() {
}
/**
* Delets an item
@ -76,8 +81,7 @@ class Model {
* @return unknown
*
*/
function javascript()
{
function javascript() {
}

Loading…
Cancel
Save