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 : 3.137.171.71
Current Path : /var/www/oasis/src_old/ |
| Current File : /var/www/oasis/src_old/create_all_schema_files.php |
<?php
function CreateAllSchemaFiles($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 internal_code={$schema_id} ";
}
mkdir($aobj_context->main_src."/schema");
$get_schema_id="select internal_code as schema_id,module_name,display_module_name
from s_user_schema where (menu_function='' or menu_function is null) {$schema_cond}";
$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[schema_id];
$module_name=$schema_value[module_name];
$display_module_name=$schema_value[display_module_name];
$t_module_name=getReplaceModuleName($schema_value[module_name]);
$class_name="t_".$t_module_name;
$filename = $aobj_context->main_src."//schema//".$class_name.".php";
$data="";
$data.="<?PHP
class t_{$t_module_name}
{
\tfunction __construct()\n\t{
";
$get_qry ="select suse.internal_code,concat('module_',ref_s_user_schema_code) as table_name,
name,system_name,ref_s_user_schema_code,
db_field,concat('module_',ref_module_code) ref_module_table,
if(ref_s_user_schema_group_code>0,
concat('user_schema_',ref_s_user_schema_code,'_group_',ref_s_user_schema_group_code),0) as group_table,
if(ref_s_user_schema_group_code>0,concat('user_schema_',ref_s_user_schema_code,'_entry_',ref_s_user_schema_group_code),0) as entry_table
from s_user_schema_elements suse inner join
s_user_schema sus on sus.internal_code=ref_s_user_schema_code
where module_name='{$module_name}' order by ifnull(ref_s_user_schema_group_code,-999),suse.sequence";
$lobj_get_qry = $aobj_context->mobj_db->GetAll($get_qry);
$inner_data="";
$inner_data.="\$this->{$t_module_name}_table='{$lobj_get_qry[0][table_name]}'; \n\n";
$inner_data.="\t\t\$this->{$t_module_name}_table_id='{$lobj_get_qry[0][ref_s_user_schema_code]}'; \n\n";
// To Form Group Table Details
$get_group_qry ="select s.module_name,sg.internal_code as group_id,name as group_name,
concat('user_schema_',ref_s_user_schema_code,'_group_',sg.internal_code) as group_table,
concat('user_schema_',ref_s_user_schema_code,'_entry_',sg.internal_code) as entry_table
from s_user_schema_group sg
inner join s_user_schema s on s.internal_code=sg.ref_s_user_schema_code
where multiple=1
and s.internal_code={$module_id}";
$lobj_get_group_qry = $aobj_context->mobj_db->GetAll($get_group_qry);
foreach($lobj_get_group_qry as $pgk=>$pgv)
{
$module_name=getReplaceModuleName($pgv[module_name]);
$group_name=getReplaceModuleName($pgv[group_name]);
$group_table=getReplaceModuleName($pgv[group_table]);
$entry_table=getReplaceModuleName($pgv[entry_table]);
$group_id=($pgv[group_id]);
$inner_data.="\t\t\$this->{$module_name}_{$group_name}_group_table='{$group_table}'; \n\n";
$inner_data.="\t\t\$this->{$module_name}_{$group_name}_entry_table='{$entry_table}'; \n\n";
$inner_data.="\t\t\$this->{$module_name}_{$group_name}_group_id='{$group_id}'; \n\n";
}
foreach($lobj_get_qry as $pk=>$pv)
{
$db_field=getReplaceModuleName($pv[db_field]);
$system_field=getReplaceModuleName($pv[system_name]);
$inner_data.="\t\t\$this->{$system_field}='{$db_field}'; \n\n";
}
$data.=$inner_data."\t} \n }";
if (!$handle = fopen($filename, 'w')) {
echo "Cannot open file ($filename)";
exit;
}
// Write $somecontent to our opened file.
if (fwrite($handle, $data) === FALSE) {
echo "Cannot write to file ($filename)";
exit;
}
//echo "Success, wrote ($somecontent) to file ($filename)";
fclose($handle);
}
$data['details']=$lobj_details;
if(empty($schema_id))
{
$data="Schema Generated Successfully";
echo $aobj_context->mobj_output->ToJSONEnvelope($data,0,"success");
return;
}
}
function getReplaceModuleName($name)
{
$spl_char = array("*","/","~","!","@","#","$","%","^","&",":",";","?","/","\\","_","-","'"," ",".");
$view_name = strtolower(str_replace($spl_char,"_",$name));
return strtolower(str_ireplace("__","_",$view_name));
}
?>
|