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.227.140.251


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

<?php

function populateAllGridFiles($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} ";
			 
		}		
				$get_schema_id="(select distinct internal_code as schema_id,
								module_name,display_module_name,grid_type,s_col_names,s_col_model,grid_default_rows from 
									(select  display_module_name,ifnull(s.grid_default_rows,8) as grid_default_rows, module_name,s.grid_type,s.s_col_names,s.s_col_model,s.internal_code,ifnull(multiple,0) as multiple 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  t.value='Meta' {$schema_cond}  
									order by ug.sequence,su.sequence,su.internal_code ) l 
									where   multiple=0    )
									 ";
				$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];	
			$grid_type=$schema_value['grid_type'];
			$grid_default_rows=$schema_value['grid_default_rows'];
			$ggrid_height=(!empty($grid_default_rows))?($grid_default_rows*22):150;
			$row_num=(!empty($grid_default_rows))?$grid_default_rows:8;
			$include_in_grid_cond="";
			if($grid_type=='Normal') $include_in_grid_cond=" and (include_in_grid=1 or include_group_ele_in_header=1) ";	
			$get_display_cols="(select table_name,name,field_name,grid_width,data_type from 
							(select  concat('module_',s.internal_code) as table_name ,
							su.name,case when
							ifnull(multiple,0)=0  
							then include_in_grid
							when ifnull(multiple,0)=1 then include_group_ele_in_header
							else 
							include_in_grid end as multiple,
							ifnull(ug.name,'0None') as group_name,t1.value as data_type,
							ifnull(su.grid_width,'85') as grid_width,
							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
							inner join s_ref_type t1 on t1.internal_code=su.data_type
							left join s_user_schema_group ug on ug.internal_code=su.ref_s_user_schema_group_code
							where s.internal_code={$schema_value[schema_id]} 
							and t.value='Meta' {$include_in_grid_cond}
							and ifnull(su.is_defined,1)=1
							and ifnull(su.is_visible,1)=1
							and (ug.parent_group_code is null or  ug.parent_group_code=0)							
							order by ifnull(ug.sequence,0),su.sequence,su.internal_code
							) l 
							where   multiple=1 )";
				 	 
			 
		$lobj_get_display_cols = $aobj_context->mobj_db->GetAll($get_display_cols);
	 
		  $grid_header='';
		  $grid_header_val='';
		  $grid_table_name=$lobj_get_display_cols[0][table_name];
		  $first_id=$lobj_get_display_cols[0][field_name];
		  $field_name='';
		  $m=1;
		  $details_arr='';
			
			foreach($lobj_get_display_cols as $key=>$value)
			{
			 if($value[data_type]=='Number') 
			 $align= " align:'right',  "; else $align= " align:'left', ";
			 
			$grid_width=$value[grid_width];
			if($m!=count($lobj_get_display_cols)) {
			if($m==1) $lable_field_name=$lobj_get_display_cols[$key]['name'];
			$grid_header.="'".$lobj_get_display_cols[$key]['name']."',";
			$grid_header_val.="{name:'{$lobj_get_display_cols[$key]['field_name']}',index:'{$lobj_get_display_cols[$key][field_name]}' , {$align} width:{$grid_width}} ,";
			$field_name.=$lobj_get_display_cols[$key]['field_name'].",";
			 
			}
			else {
			$grid_header.="'".$lobj_get_display_cols[$key]['name']."'";
			$grid_header_val.="{name:'{$lobj_get_display_cols[$key]['field_name']}',index:'{$lobj_get_display_cols[$key][field_name]}' , {$align} width:{$grid_width}} ,";
			$field_name.=$lobj_get_display_cols[$key]['field_name'];
			 
			}
			$m++;
			}
 $grid_header.=",'Created By'";
 $grid_header_val.="{name:'created_by',index:'created_by' , {$align} width:60} ";
	 
	 $filename = $aobj_context->main_src."/grid_display_files/".$grid_table_name.".js";
	 //chmod($filename,"777");
	  unlink($filename);
 
	if($schema_value['grid_type']=='Normal')
	{
	$somecontent = "var {$grid_table_name} = jQuery('#table_grid').jqGrid(
			{
			url:\$host_url+'viewUserSchemaModuleDetails.demo&table_name={$grid_table_name}&field_name={$field_name}',
			datatype: 'json',
			colNames:[{$grid_header}],
			colModel:[{$grid_header_val}],
			rowNum:200,
			rowList:[15,30,50,100,200,500,1000],
			imgpath:\$img_path,
			pager: jQuery('#sub_grid_div'),
			sortname: 'id',
			height:'350',
			viewrecords: true,
			sortorder: 'desc',
			multiselect: true,
			width:'850',
			cellEdit: true,
		 
			editurl:\$host_url+'deleteUserSchemaModuleDetails.demo&table_name={$grid_table_name}&delete_table={$module_name}'
			}
			).navGrid('#sub_grid_div',{edit:false,add:false,del:true,search:true},{},{},{},{multipleSearch:true})
			.navButtonAdd('#sub_grid_div',{caption:\"Toggle\",
			buttonicon :'ui-icon-pin-s', onClickButton:function(){ {$grid_table_name}[0].toggleToolbar() } }) 
			.navButtonAdd('#sub_grid_div',{caption:\"Edit\",  
			onClickButton:function()
			{ var gsr = jQuery(\"#table_grid\").getGridParam('selrow');
			if(gsr){ editRecords(gsr); } else { alert(\"Please select Row\") } }
			});
			\n
			{$grid_table_name}.filterToolbar(); \n
			   $(\"#gs_{$first_id}\").focus();
			   $('.ui-search-toolbar').bind('keydown',function(evt) 
				{
					var kC  = (evt.which) ? evt.which : evt.keyCode;
					if(kC==40)
					jQuery('#table_grid').editCell(0,0,false);	
					if(kC==39) 
					 $('#'+evt.target.id).focusNextInputField();
					 if(kC==37) 
					 $('#'+evt.target.id).focusPreviousInputField();					
				} );
			  
			";
		}// jQuery('#table_grid').editCell(0,0,false)
		else
		{
			$s_col_names=$schema_value['s_col_names'];
			$s_col_model=$schema_value['s_col_model'];
			$display_module_name=$schema_value['display_module_name'];
			$module_name=$schema_value['module_name'];
			$somecontent = "var {$grid_table_name} = jQuery('#table_gandhi_grid').jqGrid(
			{
			url:\$host_url+\"viewUserSchemaGGridDetails&module_id={$module_id}&login_ctr=\"+document.getElementById('login_counter').value,
			datatype: 'json',
			colNames:{$s_col_names},
			colModel:{$s_col_model},
			rowNum:200,
			rowList:[5,10,20,50,100,200,500,1000],
			imgpath:\$img_path,
			pager: jQuery('#sub_grid_div'),
			sortname: 'id',
			height:'{$ggrid_height}',
			viewrecords: true,
			sortorder: 'desc',
		 
			multiselect: true,
			cellEdit: true,
			 forceFit : true, 								 
			 cellsubmit: 'clientArray',
			width:'830',
			 	
			afterSaveCell : function(rowid,name,val,iRow,iCol) 
						{ 
						UpdateGandhiWithCellEdit('{$module_id}',rowid,name,val);
						},	
			afterEditCell: function (id,name,val,iRow,iCol)
								{
								GandhiGridAfterEditCell('{$module_name}',id,name,val,iRow,iCol);
								},			
			ondblClickRow: function (id,name,val,iRow,iCol)
				{
				 getGGridGroupDetailsRowData(id);
																 
				},
			caption:'{$display_module_name}' 
			}
			).navGrid('#sub_grid_div',{edit:false,add:false,del:false,search:false},{},{},{},{multipleSearch:true})
			.navButtonAdd('#sub_grid_div',{caption:\"Toggle\",
			buttonicon :'ui-icon-pin-s', onClickButton:function(){ {$grid_table_name}[0].toggleToolbar() } }) 
			 ;
			\n
			{$grid_table_name}.filterToolbar(); \n
			 $(\"#gs_{$first_id}\").focus();
			   $('.ui-search-toolbar').bind('keydown',function(evt) 
				{
					var kC  = (evt.which) ? evt.which : evt.keyCode;
					if(kC==40)
					jQuery('#table_gandhi_grid').editCell(0,0,false);	
					if(kC==39) 
					 $('#'+evt.target.id).focusNextInputField();
					 if(kC==37) 
					 $('#'+evt.target.id).focusPreviousInputField();						
				} );
			";
			 
		}

	// Let's make sure the file exists and is writable first.
	 
	   if (!$handle = fopen($filename, 'w')) {
		
	        echo "Cannot open file ($filename)";
	        exit;
	   }
	 
	   // Write $somecontent to our opened file.
	   if (fwrite($handle, $somecontent) === FALSE) {
	       echo "Cannot write to file ($filename)";
	       exit;
	   }
	   //chmod($filename,"777");
	   //echo "Success, wrote ($somecontent) to file ($filename)";
	   
	   fclose($handle); 
	   }
	   $data['details']=$lobj_details;
          
		if(($schema_id==0 or $schema_id=='0'))
		{
		$data="Grid Files Generated Successfully";
		echo $aobj_context->mobj_output->ToJSONEnvelope($data,0,"success"); 	
		return;	  
		}		  
}	   
?>