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.117.254.202
<?php
function CreateView($aobj_context)
{
$aobj_context->mobj_db->SetFetchMode(ADODB_FETCH_ASSOC);
$schema_id =$aobj_context->mobj_data["schema_id"];
$schema_cond='';
if(!($schema_id==0 or $schema_id=='0'))
{
$schema_cond=" and s.internal_code={$schema_id} ";
}
if($schema_id==1)
{
$schema_cond="";// and s.internal_code=39
}
$get_schema_id="SELECT s.internal_code,s.module_name
from s_user_schema s inner join s_ref_type t
on t.internal_code=s.module_type
where is_menu_only=0 and value<>'Reports'
{$schema_cond}
order by 1
";
//echo $get_schema_id;
// die();
$lobj_get_schema_id = $aobj_context->mobj_db->GetAll($get_schema_id);
foreach($lobj_get_schema_id as $key1=>$schema_value)
{
$module_id=$schema_value['internal_code'];
$module_name=$schema_value['module_name'];
CreateGeneralMasterView($aobj_context,$module_id,$module_name);
CreateGroupView($aobj_context,$module_id,$module_name);
}
if(($schema_id==0 or $schema_id=='0'))
{
$data="Views Created Successfully";
echo $aobj_context->mobj_output->ToJSONEnvelope($data,0,"success");
return;
}
}
function getViewName($name)
{
$spl_char = array("*","/","~","!","@","#","$","%","^","&",":",";","?","/","\\","_","-","'"," ",".");
$view_name = strtolower(str_replace($spl_char,"_",$name));
return str_ireplace("__","_",$view_name);
}
function CreateGeneralMasterView($aobj_context,$schema_id,$module_name)
{
$view_name =getViewName($module_name);
$aobj_context->mobj_db->execute("SET @@session.group_concat_max_len=100000");
$aobj_context->mobj_db->execute("set @a:=0");
$table_name="module_{$schema_id}";
$select_ref_module_code="select
GROUP_CONCAT(join_table_name SEPARATOR ' ') as qry from
(select @a:=@a+1,ref_module_code,
concat(' left join module_',ref_module_code, ' as module_',ref_module_code,'_',internal_code,' on module_',ref_module_code,'_',internal_code,'.internal_code =module_',ref_s_user_schema_code,'.m_',ref_s_user_schema_code, '_ele_',internal_code) as join_table_name
from s_user_schema_elements
where ref_s_user_schema_code={$schema_id}
and is_multiple_group=0 and ref_module_code>0)j";
$obj_select_ref_module_code = $aobj_context->mobj_db->GetRow($select_ref_module_code);
$join_qry=(count($obj_select_ref_module_code)>0)?$obj_select_ref_module_code[qry]:'';
$get_display_cols="select GROUP_CONCAT(field_name) as field_name from
(select table_name,name,field_name as grid_field_name,
if(ref_module_code=0,
concat('module_',internal_code,'.',field_name,' as ', name),
concat(\"concat(\",f1,f2,\") as \",name,',module_',internal_code,'.',field_name, ' as ref_',name,'_code')) as field_name
,ref_module_code from
(select s.internal_code, su.internal_code as ele_id,
ref_module_code,concat('module_',s.internal_code) as table_name ,
field_id,
if(ifnull(field_id1,'')!='',concat('module_',ref_module_code,'_',su.internal_code,'.',field_id1),'') as f1,
if(ifnull(field_id2,'')!='',concat(',\'-\',module_',ref_module_code,'_',su.internal_code,'.',field_id2),'') as f2,
LCASE(REPLACE(REPLACE(REPLACE(REPLACE(su.system_name,' ','_'),'.','_'),'&','_'),'/','_')) as name
,
ifnull(multiple,0) as multiple,ifnull(ug.name,'0None') as group_name,
concat('m_',s.internal_code,'_ele_',su.internal_code) as field_name
from s_user_schema s inner join s_user_schema_elements su on
su.ref_s_user_schema_code=s.internal_code
inner join s_ref_type t on t.internal_code=su.s_ref_type_meta
left join s_user_schema_group ug on ug.internal_code=su.ref_s_user_schema_group_code
left join module_meta_columns mmc on mmc.module_id=su.ref_module_code
where s.internal_code={$schema_id} and t.value='Meta'
and (ug.parent_group_code is null or ug.parent_group_code=0)
order by ug.sequence,su.sequence,su.internal_code ) l
where multiple=0
) a ";
$lobj_get_display_cols = $aobj_context->mobj_db->GetRow($get_display_cols);
$field_name=$lobj_get_display_cols[field_name];
$SQL = " create view {$view_name} as select {$table_name}.internal_code,{$field_name},
{$table_name}.created_by,
{$table_name}.created_date,
{$table_name}.modified_by,
{$table_name}.modified_date
from {$table_name} {$join_qry}";
//if($table_name == 'module_30')
$drop_view="DROP VIEW IF EXISTS {$view_name}";
$lobj_drop_view = $aobj_context->mobj_db->Execute($drop_view);
$lobj_SQL= $aobj_context->mobj_db->Execute($SQL);
//echo mysql_error();
}
function CreateGroupView_old($aobj_context,$schema_id,$module_name)
{
$get_groups="select internal_code,name
from s_user_schema_group
where ref_s_user_schema_code={$schema_id}
and multiple=1";
$lobj_get_groups = $aobj_context->mobj_db->GetAll($get_groups);
foreach($lobj_get_groups as $key=>$val)
{
$fields='';
$join_qry='';
$group_id=$val[internal_code];
$group_name=$val[name];
$group_view_name=getViewName($module_name."_".$group_name);
$entry_view_name=getViewName($module_name."_".$group_name."_entry");
$group_table_name="user_schema_{$schema_id}_group_{$group_id}";
$entry_table_name="user_schema_{$schema_id}_entry_{$group_id}";
$aobj_context->mobj_db->execute("SET @@session.group_concat_max_len=10000");
$select_ref_module_code="select GROUP_CONCAT(join_table_name SEPARATOR ' ') as qry from
(select ref_module_code,
concat('u_',{$schema_id},'_g_',{$group_id},'_ele_',internal_code) as field_id,
concat(' left join module_',ref_module_code, ' on module_',ref_module_code,'.internal_code =u_',{$schema_id},'_g_',{$group_id},'_ele_',internal_code) as join_table_name
from s_user_schema_elements
where ref_s_user_schema_code={$schema_id}
and ref_s_user_schema_group_code={$group_id} and ref_module_code>0)j";
$obj_select_ref_module_code = $aobj_context->mobj_db->GetRow($select_ref_module_code);
$join_qry=(count($obj_select_ref_module_code)>0)?$obj_select_ref_module_code[qry]:'';
// to form the fields dynamically
$select_field_ids="select
concat('u_',{$schema_id},'_g_',{$group_id},'_ele_',internal_code) as field_id,
LCASE(REPLACE(REPLACE(REPLACE(REPLACE(system_name,' ','_'),'.','_'),'&','_'),'/','_')) as name,
ref_module_code from
s_user_schema_elements
where ref_s_user_schema_code={$schema_id}
and ref_s_user_schema_group_code={$group_id}
order by internal_code";
$lobj_select_field_ids = $aobj_context->mobj_db->GetAll($select_field_ids);
foreach($lobj_select_field_ids as $key =>$value)
{
if($value[ref_module_code]=='0')
{
$fields.=$value[field_id]." as $value[name],";
}
else
{
$aobj_context->mobj_db->execute("SET @@session.group_concat_max_len=10000");
$qry=" select concat('module_',schema_id) as table_name,GROUP_CONCAT(name SEPARATOR '-ele-') as name,
GROUP_CONCAT(field_name separator ',\'-\',') as field_name from
(select * from
(select s.internal_code as schema_id,su.name,ifnull(multiple,0) as multiple,ifnull(ug.name,'0None') as group_name,
concat('m_',s.internal_code,'_ele_',su.internal_code) as field_name
from s_user_schema s inner join s_user_schema_elements su on
su.ref_s_user_schema_code=s.internal_code
inner join s_ref_type t on t.internal_code=su.s_ref_type_meta
left join s_user_schema_group ug on ug.internal_code=su.ref_s_user_schema_group_code
where s.internal_code=$value[ref_module_code] and t.value='Meta'
order by ug.sequence,su.sequence,su.internal_code ) l where multiple=0 limit 2) a group by schema_id";
$lobj_rs = $aobj_context->mobj_db->GetRow($qry);
$fields.="concat(".$lobj_rs[field_name].") as {$value[name]}".", {$value[field_id]} as ref_{$value[name]}_code ,";
}
}
$fields=substr($fields,0,strlen($fields)-1);
$create_group_view=" create view {$group_view_name} as
select {$group_table_name}.internal_code ,ref_s_ref_data_code,{$fields}
from
{$group_table_name}
{$join_qry}";
$drop_view="DROP VIEW IF EXISTS {$group_view_name}";
$lobj_drop_view = $aobj_context->mobj_db->Execute($drop_view);
$lobj_SQL= $aobj_context->mobj_db->Execute($create_group_view);
$create_entry_view=" create view {$entry_view_name} as
select {$entry_table_name}.internal_code ,login_cnt,group_int_code,
ref_s_ref_data_code,{$fields}
from
{$entry_table_name}
{$join_qry}";
$drop_entry_view="DROP VIEW IF EXISTS {$entry_view_name}";
$lobj_drop_view = $aobj_context->mobj_db->Execute($drop_entry_view);
$lobj_SQL= $aobj_context->mobj_db->Execute($create_entry_view);
}
}
function CreateGroupView($aobj_context,$schema_id,$module_name)
{
$get_groups="select internal_code,name
from s_user_schema_group
where ref_s_user_schema_code={$schema_id}
and multiple=1";
$lobj_get_groups = $aobj_context->mobj_db->GetAll($get_groups);
foreach($lobj_get_groups as $key=>$val)
{
$fields='';
$join_qry='';
$group_id=$val[internal_code];
$group_name=$val[name];
$group_view_name=getViewName($module_name."_".$group_name);
$entry_view_name=getViewName($module_name."_".$group_name."_entry");
$group_table_name="user_schema_{$schema_id}_group_{$group_id}";
$entry_table_name="user_schema_{$schema_id}_entry_{$group_id}";
$aobj_context->mobj_db->execute("SET @@session.group_concat_max_len=10000");
/* $select_ref_module_code="select GROUP_CONCAT(join_table_name SEPARATOR ' ') as qry from
(select ref_module_code,
concat('u_',{$schema_id},'_g_',{$group_id},'_ele_',internal_code) as field_id,
concat(' left join module_',ref_module_code, ' on module_',ref_module_code,'.internal_code =u_',{$schema_id},'_g_',{$group_id},'_ele_',internal_code) as join_table_name
from s_user_schema_elements
where ref_s_user_schema_code={$schema_id}
and ref_s_user_schema_group_code={$group_id} and ref_module_code>0)j";
$obj_select_ref_module_code = $aobj_context->mobj_db->GetRow($select_ref_module_code);
$join_qry=(count($obj_select_ref_module_code)>0)?$obj_select_ref_module_code[qry]:'';
// to form the fields dynamically
$select_field_ids="select
concat('u_',{$schema_id},'_g_',{$group_id},'_ele_',internal_code) as field_id,
LCASE(REPLACE(REPLACE(REPLACE(REPLACE(system_name,' ','_'),'.','_'),'&','_'),'/','_')) as name,
ref_module_code from
s_user_schema_elements
where ref_s_user_schema_code={$schema_id}
and ref_s_user_schema_group_code={$group_id}
order by internal_code";
$lobj_select_field_ids = $aobj_context->mobj_db->GetAll($select_field_ids);
foreach($lobj_select_field_ids as $key =>$value)
{
if($value[ref_module_code]=='0')
{
$fields.=$value[field_id]." as $value[name],";
}
else
{
$aobj_context->mobj_db->execute("SET @@session.group_concat_max_len=10000");
$qry=" select concat('module_',schema_id) as table_name,GROUP_CONCAT(name SEPARATOR '-ele-') as name,
GROUP_CONCAT(field_name separator ',\'-\',') as field_name from
(select * from
(select s.internal_code as schema_id,su.name,ifnull(multiple,0) as multiple,ifnull(ug.name,'0None') as group_name,
concat('m_',s.internal_code,'_ele_',su.internal_code) as field_name
from s_user_schema s inner join s_user_schema_elements su on
su.ref_s_user_schema_code=s.internal_code
inner join s_ref_type t on t.internal_code=su.s_ref_type_meta
left join s_user_schema_group ug on ug.internal_code=su.ref_s_user_schema_group_code
where s.internal_code=$value[ref_module_code] and t.value='Meta'
order by ug.sequence,su.sequence,su.internal_code ) l where multiple=0 limit 2) a group by schema_id";
$lobj_rs = $aobj_context->mobj_db->GetRow($qry);
$fields.="concat(".$lobj_rs[field_name].") as {$value[name]}".", {$value[field_id]} as ref_{$value[name]}_code ,";
}
}
$fields=substr($fields,0,strlen($fields)-1); */
$group_qry=getGroupDetailsViewQry($aobj_context,$schema_id,$group_id,$group_table_name);
$create_group_view=" create view {$group_view_name} as
select {$group_table_name}.internal_code ,ref_s_ref_data_code,{$group_qry}";
$drop_view="DROP VIEW IF EXISTS {$group_view_name}";
$lobj_drop_view = $aobj_context->mobj_db->Execute($drop_view);
$lobj_SQL= $aobj_context->mobj_db->Execute($create_group_view);
$entry_group_qry=getGroupDetailsViewQry($aobj_context,$schema_id,$group_id,$entry_table_name);
$create_entry_view=" create view {$entry_view_name} as
select {$entry_table_name}.internal_code ,login_cnt,group_int_code,
ref_s_ref_data_code,{$entry_group_qry}
";
$drop_entry_view="DROP VIEW IF EXISTS {$entry_view_name}";
$lobj_drop_view = $aobj_context->mobj_db->Execute($drop_entry_view);
$lobj_SQL= $aobj_context->mobj_db->Execute($create_entry_view);
}
}
function getGroupDetailsViewQry($aobj_context,$schema_id,$group_id,$table_name)
{
$aobj_context->mobj_db->execute("SET @@session.group_concat_max_len=10000");
$aobj_context->mobj_db->execute("set @a:=0");
$select_ref_module_code="select
GROUP_CONCAT(join_table_name SEPARATOR ' ') as qry from
(select parent_group_code,ref_s_user_schema_group_code, @a:=@a+1,ref_module_code,
concat(' left join module_',suse.ref_module_code, ' as module_',suse.ref_module_code,'_',suse.internal_code,' on module_',suse.ref_module_code,'_',suse.internal_code,'.internal_code =',suse.db_field) as join_table_name
from s_user_schema_elements suse
inner join s_user_schema_group ug on ug.internal_code=suse.ref_s_user_schema_group_code
where suse.ref_s_user_schema_code={$schema_id}
and (is_multiple_group=1 or parent_group_code<>0)
and (ref_s_user_schema_group_code={$group_id})
and ref_module_code>0)j";
$obj_select_ref_module_code = $aobj_context->mobj_db->GetRow($select_ref_module_code);
$join_qry=(count($obj_select_ref_module_code)>0)?$obj_select_ref_module_code[qry]:'';
$get_display_cols="select GROUP_CONCAT(field_name) as field_name from
(select table_name,name,field_name as grid_field_name,
if(ref_module_code=0,
concat(field_name, ' as ',name) ,
concat(\"concat(\",f1,f2,\") as \",name,' , ',field_name, ' as ref_',name,'_code')) as field_name
,ref_module_code from
(select s.internal_code, su.internal_code as ele_id,
ref_module_code,concat('module_',s.internal_code) as table_name ,
field_id,
if(ifnull(field_id1,'')!='',concat('module_',ref_module_code,'_',su.internal_code,'.',field_id1),'') as f1,
if(ifnull(field_id2,'')!='',concat(',\'-\',module_',ref_module_code,'_',su.internal_code,'.',field_id2),'') as f2,
LCASE(REPLACE(REPLACE(REPLACE(REPLACE(su.system_name,' ','_'),'.','_'),'&','_'),'/','_')) as name
,ifnull(multiple,0) as multiple,ifnull(ug.name,'0None') as group_name,
db_field as field_name
from s_user_schema s inner join s_user_schema_elements su on
su.ref_s_user_schema_code=s.internal_code
inner join s_ref_type t on t.internal_code=su.s_ref_type_meta
left join s_user_schema_group ug on ug.internal_code=su.ref_s_user_schema_group_code
left join module_meta_columns mmc on mmc.module_id=su.ref_module_code
where s.internal_code={$schema_id} and t.value='Meta'
and (ug.internal_code={$group_id} or
(parent_group_code={$group_id} and is_grid_edit = '0' and is_multiple_group=0)
)
order by ifnull(ug.sequence,0),su.sequence,su.internal_code ) l
) a ";
$lobj_get_display_cols = $aobj_context->mobj_db->GetRow($get_display_cols);
$qry = "{$lobj_get_display_cols[field_name]},
{$table_name}.created_by,
{$table_name}.created_date,
{$table_name}.modified_by,
{$table_name}.modified_date from
{$table_name} {$join_qry}";
return $qry;
}
?>
|