Linux ip-172-26-7-228 5.4.0-1103-aws #111~18.04.1-Ubuntu SMP Tue May 23 20:04:10 UTC 2023 x86_64
Your IP : 18.227.183.161
<?php
/*
Author : M.Srikanth
Date : 2009-08-25
Module : GRN
*/
class gGridModel
{
public $login_ctr;
public $user_id;
public $aobj_context;
public $module_id;
public $table_cols=array();
//Start : Constructor
function __construct($aobj_context)
{
session_start();
$this->aobj_context=$aobj_context;
$aobj_context->mobj_db->SetFetchMode(ADODB_FETCH_ASSOC);
require_once("json.php");
$this->user_id = $_SESSION['user_id'];
$this->login_ctr=$aobj_context->mobj_data["login_ctr"];
$this->module_id=$aobj_context->mobj_data["module_id"];
$this->table_name="module_{$this->module_id}_{$this->login_ctr}";
$get_data_cols=" desc {$this->table_name}";
$lobj_create_table = $this->aobj_context->mobj_db->GetAll($get_data_cols);
foreach($lobj_create_table as $key=>$val)
{
array_push($this->table_cols,$val[Field]);
}
}
//End : Constructor
function CreateggridTempTable()
{
$get_query="select internal_code,s_grid_query from s_user_schema
where internal_code={$this->module_id}";
$lobj_get_query = $this->aobj_context->mobj_db->GetRow($get_query);
if($lobj_get_query)
{
$grid_query= $lobj_get_query['s_grid_query'];
$this->aobj_context->mobj_db->Execute("drop table {$this->table_name}");
$function_exists=strpos($grid_query,'select');
if ($function_exists === false)
{
require_once($this->aobj_context->main_src."/custom_src/ggridGetQuery.php");
$grid_query= call_user_func($grid_query,$this->aobj_context);
}
else
{
eval("\$grid_query = \"$grid_query\";");
}
$create_table="create table if not exists {$this->table_name}
{$grid_query}";
$lobj_create_table = $this->aobj_context->mobj_db->Execute($create_table);
}
}
function viewUserSchemaGGridDetails()
{
$json = new Services_JSON();
$limit = $_GET['rows'];
$sidx = $_GET['sidx'];
$sord = $_GET['sord'];
$page = $_GET['page'];
if(!$sidx)
$sidx =1;
$search =$this->aobj_context->mobj_data["_search"];
$filter_toolbal_cond="";
if($search=='true')
{
foreach($this->aobj_context->mobj_data as $search_k=>$search_v)
{
$s_val=trim($search_v);
if(in_array($search_k,$this->table_cols))
$filter_toolbal_cond.=" and {$search_k} like '{$s_val}%' ";
}
}
if($search=='true')
{
$count_id="select count(*) as count from
{$this->table_name}
where 1=1 {$filter_toolbal_cond}";
}
else
{
$count_id="select count(*) as count from
{$this->table_name}";
}
$result = mysql_query($count_id);
$row = mysql_fetch_array($result,MYSQL_ASSOC);
$count = $row['count'];
// calculation of total pages for the query
if( $count >0 )
{
$total_pages = ceil($count/$limit);
}
else
{
$total_pages = 0;
}
if ($page > $total_pages)
$page=$total_pages;
$start = $limit*$page - $limit;
if($start <0)
$start = 0;
// the actual query for the grid data
if($search=='true')
{
$SQL="select * from {$this->table_name}
where 1=1 {$filter_toolbal_cond}
ORDER BY $sidx $sord LIMIT $start,$limit";
// echo $SQL;
}
else
{
$SQL = "select * from {$this->table_name}
where 1=1
ORDER BY $sidx $sord LIMIT $start , $limit";
}
$lobj_rs =$this->aobj_context->mobj_db->GetAll($SQL);
$responce->page = $page;
$responce->total = $total_pages;
$responce->records = $count;
foreach($lobj_rs as $key =>$value)
{
$val='';
$responce->rows[$key]['id']=$value[id];
$l=0;
foreach($value as $key1 =>$value1)
{
if($key1!='id'){
$val[$l]=$value[$key1];
$l++;
}
}
$responce->rows[$key]['cell']=($val);
}
echo $json->encode($responce);
// return the formated data
}
function getGGridGroupDetailsRowData()
{
$id=$this->aobj_context->mobj_data["id"];
$get_data="select * from {$this->table_name} where id={$id}";
$lobj_get_data = $this->aobj_context->mobj_db->GetRow($get_data);
return $lobj_get_data;
}
function UpdateGGridRowModuleDetails()
{
$id=$this->aobj_context->mobj_data["id"];
$is_multiple_update=$this->aobj_context->mobj_data["is_multiple_update"];
$selected_rows=$this->aobj_context->mobj_data["selected_rows"];
$lstr_param = stripcslashes($this->aobj_context->mobj_data["GGridUpdatearr"]);
$json = new Services_JSON();
$mobj_jsondata = $json->decode($lstr_param);
$larr_GGridUpdatearr = get_object_vars($mobj_jsondata);
$desc_table="desc {$this->table_name}";
$lobj_desc_table = $this->aobj_context->mobj_db->GetAll($desc_table);
$grid_row_colour=0;
$table_ids=($is_multiple_update>0)?$selected_rows:$id;
foreach($lobj_desc_table as $dk=>$dv)
{
if($dv['Field']=='grid_row_colour')
{
$grid_row_colour=1;
break;
}
}
if(empty($larr_GGridUpdatearr))
{
$lstr_param = $this->aobj_context->mobj_data["GGridUpdatearr"];
$mobj_jsondata = $json->decode($lstr_param);
$larr_GGridUpdatearr = get_object_vars($mobj_jsondata);
}
$update_cond="";
foreach($larr_GGridUpdatearr as $key=>$val)
{
foreach($val as $k=>$v);if(empty($k)) continue;
$update_cond.=" {$k}='".addslashes($v)."' ,";
}
$update_cond=substr($update_cond,0,strlen($update_cond)-1);
$update_table="update {$this->table_name} set {$update_cond}
where id in({$table_ids})";
//echo $update_table; die();
$lobj_update_table = $this->aobj_context->mobj_db->Execute($update_table);
if($grid_row_colour)
{
$update_color_field="update {$this->table_name} set grid_row_colour='1'
where id in({$table_ids})";
$lobj_update_color_field = $this->aobj_context->mobj_db->Execute($update_color_field);
}
if($lobj_update_table)
{
$data="Successfully Updated";
echo $this->aobj_context->mobj_output->ToJSONEnvelope($data,0,"success");
}
else
{
$data="Updation Failed ->".mysql_error();
echo $this->aobj_context->mobj_output->ToJSONEnvelope($data,0,"success");
}
}
function UpdateGandhiWithCellEdit()
{
$internal_code = $this->aobj_context->mobj_data["internal_code"];
$this->table_name = $this->aobj_context->mobj_data["table_name"];
$val = $this->aobj_context->mobj_data["val"];
$system_name = $this->aobj_context->mobj_data["system_name"];
$update_gandhi_grid_table="update {$this->table_name} set {$system_name}='{$val}'
where id={$internal_code}";
$lobj_update_gandhi_grid_table = $this->aobj_context->mobj_db->Execute($update_gandhi_grid_table);
$grid_row_colour=0;
if(!empty($lobj_update_gandhi_grid_table))
{
$desc_table="desc {$this->table_name}";
$lobj_desc_table = $this->aobj_context->mobj_db->GetAll($desc_table);
foreach($lobj_desc_table as $dk=>$dv)
{
if($dv['Field']=='grid_row_colour')
{
$grid_row_colour=1;
break;
}
}
if($grid_row_colour)
{
$update_color_field="update {$this->table_name} set grid_row_colour='1'
where id={$internal_code}";
$lobj_update_color_field = $this->aobj_context->mobj_db->Execute($update_color_field);
}
$data="Row Updated Successfully";
echo $this->aobj_context->mobj_output->ToJSONEnvelope($data,0,"success");
}
else
{
$data="Updation Failed";
echo $this->aobj_context->mobj_output->ToJSONEnvelope($data,-1,"failure");
}
}
}
function CreateggridTempTable($aobj_context)
{
$class_obj=new gGridModel($aobj_context);
$aobj_context->mobj_db->SetFetchMode(ADODB_FETCH_ASSOC);
$class_obj->CreateggridTempTable();
$data="true";
echo $aobj_context->mobj_output->ToJSONEnvelope($data,0,"success");
}
function viewUserSchemaGGridDetails($aobj_context)
{
$class_obj=new gGridModel($aobj_context);
$aobj_context->mobj_db->SetFetchMode(ADODB_FETCH_ASSOC);
$class_obj->viewUserSchemaGGridDetails();
}
function getGGridGroupDetailsRowData($aobj_context)
{
$class_obj=new gGridModel($aobj_context);
$aobj_context->mobj_db->SetFetchMode(ADODB_FETCH_ASSOC);
$lobj_get_data=$class_obj->getGGridGroupDetailsRowData();
echo $aobj_context->mobj_output->ToJSONEnvelope($lobj_get_data,0,"success");
}
function UpdateGGridRowModuleDetails($aobj_context)
{
$class_obj=new gGridModel($aobj_context);
$aobj_context->mobj_db->SetFetchMode(ADODB_FETCH_ASSOC);
$lobj_update_data=$class_obj->UpdateGGridRowModuleDetails();
}function UpdateGandhiWithCellEdit($aobj_context)
{
$class_obj=new gGridModel($aobj_context);
$aobj_context->mobj_db->SetFetchMode(ADODB_FETCH_ASSOC);
$lobj_update_data=$class_obj->UpdateGandhiWithCellEdit();
}
?>
|