Skip to content

Instantly share code, notes, and snippets.

@gridphp
Last active June 14, 2020 20:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gridphp/6c88a6666ef4701fdb47837e93f3e104 to your computer and use it in GitHub Desktop.
Save gridphp/6c88a6666ef4701fdb47837e93f3e104 to your computer and use it in GitHub Desktop.
Ticket 16119657 - Master Detail export excel code - https://www.gridphp.com
<?php
/**
* PHP Grid Component
*
* @author Abu Ghufran <gridphp@gmail.com> - http://www.phpgrid.org
* @version 1.5.2
* @license: see license.txt included in package
*/
//Inicializar una sesion de PHP
session_start();
//echo "sesion:" . $_SESSION['tipousuario'];
// include db config
include_once("config.php");
//echo "Tipo Usuario".$_SESSION['tipousuario'];
//echo "Uid".$_SESSION['uid'] ;
// set up DB
mysql_connect('localhost',PHPGRID_DBUSER,PHPGRID_DBPASS);
mysql_select_db(PHPGRID_DBNAME);
// include and create object
include(PHPGRID_LIBPATH."inc/jqgrid_dist.php");
// master grid
$grid = new jqgrid();
$opt["caption"] = "Acciones (en trámite)";
$opt["height"] = "250";
$opt["width"] = "1250";
$opt["add_options"] = array('width'=>'800');
$opt["edit_options"] = array('width'=>'800');
$opt["resizable"] = true;
//$opt["forcefit"] = true;
// following params will enable subgrid -- by default first column (PK) of parent is passed as param 'id'
$opt["detail_grid_id"] = "list2";
// extra params passed to detail grid, column name comma separated
//$opt["subgridparams"] = "idaccion";
$opt["multiselect"] = false;
date_default_timezone_set('America/Mazatlan');
$opt["export"] = array("filename"=>"ads_acciones-Exportado_El-" . date('d-m-Y')."_".date('h')."-".date('i')."_".date('a'), "sheetname"=>"Acciones", "format"=>"xls","heading"=>"Expedientes - Exportado desde ADS Seguimiento a Excel el " . date('d/m/Y h:i:s a'));
//$opt["export"] = array("filename"=>"ads_acciones", "sheetname"=>"Acciones", "format"=>"pdf","heading"=>"Exportando a Excel","orientation"=>"portrait", "paper"=>"letter");
$opt["export"]["range"] = "filtered";
$sinacceso=false;
if ($_SESSION['tipousuario'] == 1) {
$grid->select_command ="SELECT a.idaccion, a.terminado, a.actor, a.expediente, a.fechaingreso, a.montoreclamacion,
a.resguardoexpediente,a.montoconvenio,a.observaciones,
ta.tipoaccion as idtipoaccion, gc.grupoclientes as idgrupoclientes, c.nombrecliente as cliente_idcliente, v.via as via_idvia,
tr.tribunal as tribunal_idtribunal, mat.tipoasunto as idtipoasunto, epa.edoprocesalactual as edoprocesalactual_idedoprocesalactual,
abof.nombreabogado as abogado_idabogadoOficna, abtr.nombreabogado as abogado_idabogadoTribunal
FROM accion a
inner join cliente c on a.cliente_idcliente=c.idcliente
inner join grupoclientes gc on c.grupoclientes_idgrupoclientes=gc.idgrupoclientes
inner join tipoaccion ta on ta.idtipoaccion=a.idtipoaccion
inner join via v on v.idvia=a.via_idvia
inner join tribunal tr on tr.idtribunal=a.tribunal_idtribunal
inner join tipoasunto mat on mat.idtipoasunto=a.idtipoasunto
inner join edoprocesalactual epa on epa.idedoprocesalactual=a.edoprocesalactual_idedoprocesalactual
inner join abogado abof on a.abogado_idabogadoOficna=abof.idabogado
inner join abogado abtr on a.abogado_idabogadoTribunal=abtr.idabogado
where a.terminado=0
";
}
else {
//inner join cliente c on a.cliente_idcliente=c.idcliente
//inner join tribunal tr on a.tribunal_idtribunal=tr.idtribunal
//inner join grupoclientes gc on a.idgrupoclientes=gc.idgrupoclientes
//inner join tipoasunto ta on a.idtipoasunto=ta.idtipoasunto
/*$grid->select_command ="SELECT a.* FROM accion a
inner join abogado abof on a.abogado_idabogadoOficna=abof.idabogado
inner join abogado abtr on a.abogado_idabogadoTribunal=abtr.idabogado
inner join cliente c on a.cliente_idcliente=c.idcliente
inner join grupoclientes gc on c.grupoclientes_idgrupoclientes=gc.idgrupoclientes
WHERE abof.id_usuario=".$_SESSION['uid']. " or abtr.id_usuario=".$_SESSION['uid'];*/
$grid->select_command ="SELECT a.idaccion, a.terminado, a.actor, a.expediente, a.fechaingreso, a.montoreclamacion,
a.resguardoexpediente,a.montoconvenio,a.observaciones,
ta.tipoaccion as idtipoaccion, gc.grupoclientes as idgrupoclientes, c.nombrecliente as cliente_idcliente, v.via as via_idvia,
tr.tribunal as tribunal_idtribunal, mat.tipoasunto as idtipoasunto, epa.edoprocesalactual as edoprocesalactual_idedoprocesalactual,
abof.nombreabogado as abogado_idabogadoOficna, abtr.nombreabogado as abogado_idabogadoTribunal
FROM accion a
inner join cliente c on a.cliente_idcliente=c.idcliente
inner join grupoclientes gc on c.grupoclientes_idgrupoclientes=gc.idgrupoclientes
inner join tipoaccion ta on ta.idtipoaccion=a.idtipoaccion
inner join via v on v.idvia=a.via_idvia
inner join tribunal tr on tr.idtribunal=a.tribunal_idtribunal
inner join tipoasunto mat on mat.idtipoasunto=a.idtipoasunto
inner join edoprocesalactual epa on epa.idedoprocesalactual=a.edoprocesalactual_idedoprocesalactual
inner join abogado abof on a.abogado_idabogadoOficna=abof.idabogado
inner join abogado abtr on a.abogado_idabogadoTribunal=abtr.idabogado
WHERE a.terminado=0 and (abof.id_usuario=".$_SESSION['uid']. " or abtr.id_usuario=".$_SESSION['uid'].")";
$sinacceso=true;
}
$grid->table = "accion";
//AQUI VAN LAS COLUMNAS
$col = array();
$col["title"] = "Id";
$col["name"] = "idaccion";
$col["width"] = "3";
$cols[] = $col;
$col = array();
$col["title"] = "Actor";
$col["name"] = "actor";
$col["width"] = "10";
$col["hidden"] = false;
$col["editable"] = true;
$col["formoptions"] = array("rowpos"=>"1", "colpos"=>"1");
if ($_SESSION['tipousuario'] == 2){
$col["editrules"] = array("readonly"=>true);
}
$col["show"] = array("list"=>true, "add"=>true, "edit"=>true, "view"=>true);
$cols[] = $col;
$col = array();
$col["title"] = "Expediente";
$col["name"] = "expediente";
$col["width"] = "10";
$col["editable"] = true;
$col["formoptions"] = array("rowpos"=>"2", "colpos"=>"1");
if ($_SESSION['tipousuario'] == 2){
$col["editrules"] = array("readonly"=>true);
}
$col["show"] = array("list"=>true, "add"=>true, "edit"=>true, "view"=>true);
$cols[] = $col;
$col = array();
$col["title"] = "Fecha<br>Ingreso (aaaa-mm-d)";
$col["name"] = "fechaingreso";
$col["width"] = "10";
$col["formoptions"] = array("rowpos"=>"3", "colpos"=>"1");
$col["editable"] = true; // this column is editable
$col["editoptions"] = array("size"=>20); // with default display of textbox with size 20
$col["editrules"] = array("required"=>false, "edithidden"=>true); // and is required
$col["searchoptions"]["sopt"] = array("cn"); // contains search for easy searching
# to make it date time
$col["formatter"] = "datetime";
# opts array can have these options: http://trentrichardson.com/examples/timepicker/#tp-options
$col["formatoptions"] = array("srcformat"=>'Y-m-d H:i:s',"newformat"=>'Y-m-d H:i',"opts" => array("timeFormat"=>"HH:mm"));
$col["show"] = array("list"=>true, "add"=>true, "edit"=>true, "view"=>true);
if ($_SESSION['tipousuario'] == 2){
$col["editrules"] = array("readonly"=>true);
}
$cols[] = $col;
$col = array();
$col["title"] = "Acción";
$col["name"] = "idtipoaccion";
$col["dbname"] = "a.idtipoaccion"; // this is required as we need to search in name field, not id
$col["width"] = "11";
$col["align"] = "left";
$col["search"] = true;
$col["editable"] = true;
$col["edittype"] = "select"; // render as select
# fetch data from database, with alias k for key, v for value
$str = $grid->get_dropdown_values("select idtipoaccion as k, tipoaccion as v from tipoaccion order by v");
$col["editoptions"] = array("value"=>":;".$str);
//$col["formatter"] = "select"; // display label, not value
//$col["editoptions"]=array("value"=>":;".$str);
$col["stype"] = "select"; // enable dropdown search
$col["searchoptions"] = array("value" => ":;".$str);
if ($_SESSION['tipousuario'] == 2){
$col["editrules"] = array("readonly"=>true);
}
$col["column"] = "idtipoaccion";
$col["css"] = "'white-space':'normal'";
$col_conditions[]=$col;
$grid->set_conditional_css($col_conditions);
$col["formoptions"] = array("rowpos"=>"4", "colpos"=>"1");
$col["export"] = true;
$cols[] = $col;
$col = array();
$col["title"] = "Monto de<br>Reclamación";
$col["name"] = "montoreclamacion";
$col["width"] = "11";
$col["align"] = "right";
$col["formatter"] = "currency";
$col["formatoptions"] = array("prefix" => "$",
"suffix" => '',
"thousandsSeparator" => ",",
"decimalSeparator" => ".",
"decimalPlaces" => 2);
$col["formoptions"] = array("rowpos"=>"5", "colpos"=>"1");
$col["editable"] = true;
$col["show"] = array("list"=>true, "add"=>true, "edit"=>true, "view"=>true);
$cols[] = $col;
$col = array();
$col["title"] = "Grupo de<br>Clientes";
$col["name"] = "idgrupoclientes";
$col["dbname"] = "a.idgrupoclientes"; // this is required as we need to search in name field, not id
$col["width"] = "10";
$col["align"] = "left";
$col["search"] = true;
$col["editable"] = true;
$col["formoptions"] = array("rowpos"=>"6", "colpos"=>"1");
$col["edittype"] = "select"; // render as select
# fetch data from database, with alias k for key, v for value
$str = $grid->get_dropdown_values("select idgrupoclientes as k, grupoclientes as v from grupoclientes order by v");
# on change, update other dropdown
$col["editoptions"] = array(
"value"=>$str,
"onchange" => array( "sql"=>"select distinct idcliente as k, nombrecliente as v from cliente WHERE grupoclientes_idgrupoclientes = '{idgrupoclientes}' order by v",
"update_field" => "cliente_idcliente" )
);
if ($_SESSION['tipousuario'] == 2){
$col["editrules"] = array("readonly"=>true);
}
//$col["editoptions"] = array("value"=>":;".$str);
//$col["formatter"] = "select"; // display label, not value
$col["stype"] = "select"; // enable dropdown search
$col["searchoptions"] = array("value" => ":;".$str);
$col["column"] = "idgrupoclientes";
$col["css"] = "'white-space':'normal'";
$col_conditions[]=$col;
$grid->set_conditional_css($col_conditions);
$cols[] = $col;
$col = array();
$col["title"] = "Cliente";
$col["name"] = "cliente_idcliente";
$col["dbname"] = "cliente_idcliente"; // this is required as we need to search in name field, not id
$col["width"] = "10";
$col["align"] = "left";
$col["search"] = true;
$col["editable"] = true;
$col["formoptions"] = array("rowpos"=>"7", "colpos"=>"1");
$col["edittype"] = "select"; // render as select
# fetch data from database, with alias k for key, v for value
$str = $grid->get_dropdown_values("select idcliente as k, nombrecliente as v from cliente order by v");
$col["editoptions"] = array("value"=>":;".$str);
if ($_SESSION['tipousuario'] == 2){
$col["editrules"] = array("readonly"=>true);
}
// initially load 'note' of that client_id
//$col["editoptions"]["onload"]["sql"] = "select idcliente as k, nombrecliente as v from cliente WHERE grupoclientes_idgrupoclientes = '{idgrupoclientes}'";
//$col["formatter"] = "select"; // display label, not value
$col["editoptions"]=array("value"=>":;".$str);
$col["stype"] = "select"; // enable dropdown search
$col["searchoptions"] = array("value" => ":;".$str);
$col["column"] = "cliente_idcliente";
$col["css"] = "'white-space':'normal'";
$col_conditions[]=$col;
$grid->set_conditional_css($col_conditions);
$cols[] = $col;
$col = array();
$col["title"] = "Vía";
$col["name"] = "via_idvia";
$col["dbname"] = "via_idvia"; // this is required as we need to search in name field, not id
$col["width"] = "10";
$col["align"] = "left";
$col["search"] = true;
$col["editable"] = true;
$col["formoptions"] = array("rowpos"=>"8", "colpos"=>"1");
$col["edittype"] = "select"; // render as select
# fetch data from database, with alias k for key, v for value
$str = $grid->get_dropdown_values("select idvia as k, via as v from via order by v");
$col["editoptions"] = array("value"=>":;".$str);
//$col["formatter"] = "select"; // display label, not value
$col["stype"] = "select"; // enable dropdown search
$col["searchoptions"] = array("value" => ":;".$str);
if ($_SESSION['tipousuario'] == 2){
$col["editrules"] = array("readonly"=>true);
}
$cols[] = $col;
$col = array();
$col["title"] = "Materia";
$col["name"] = "idtipoasunto";
$col["dbname"] = "idtipoasunto"; // this is required as we need to search in name field, not id
$col["width"] = "10";
$col["align"] = "left";
$col["search"] = true;
$col["editable"] = true;
$col["formoptions"] = array("rowpos"=>"9", "colpos"=>"1");
$col["edittype"] = "select"; // render as select
# fetch data from database, with alias k for key, v for value
$str = $grid->get_dropdown_values("select idtipoasunto as k, tipoasunto as v from tipoasunto order by v");
# on change, update other dropdown
$col["editoptions"] = array(
"value"=>$str,
"onchange" => array( "sql"=>"select distinct idtribunal as k, tribunal as v from tribunal WHERE idtipoasunto = '{idtipoasunto}' order by v",
"update_field" => "tribunal_idtribunal" )
);
if ($_SESSION['tipousuario'] == 2){
$col["editrules"] = array("readonly"=>true);
}
//$col["editoptions"] = array("value"=>":;".$str);
//$col["formatter"] = "select"; // display label, not value
$col["stype"] = "select"; // enable dropdown search
$col["searchoptions"] = array("value" => ":;".$str);
$col["column"] = "idtipoasunto";
$col["css"] = "'white-space':'normal'";
$col_conditions[]=$col;
$grid->set_conditional_css($col_conditions);
$cols[] = $col;
$col = array();
$col["title"] = "Tribunal";
$col["name"] = "tribunal_idtribunal";
$col["dbname"] = "tribunal_idtribunal"; // this is required as we need to search in name field, not id
$col["width"] = "10";
$col["align"] = "left";
$col["search"] = true;
$col["editable"] = true;
$col["formoptions"] = array("rowpos"=>"10", "colpos"=>"1");
$col["edittype"] = "select"; // render as select
# fetch data from database, with alias k for key, v for value
$str = $grid->get_dropdown_values("select idtribunal as k, tribunal as v from tribunal order by v");
$col["editoptions"] = array("value"=>":;".$str);
//$col["formatter"] = "select"; // display label, not value
$col["stype"] = "select"; // enable dropdown search
$col["searchoptions"] = array("value" => ":;".$str);
if ($_SESSION['tipousuario'] == 2){
$col["editrules"] = array("readonly"=>true);
}
$col["column"] = "tribunal_idtribunal";
$col["css"] = "'white-space':'normal'";
$col_conditions[]=$col;
$grid->set_conditional_css($col_conditions);
$cols[] = $col;
$col = array();
$col["title"] = "Edo. Procesal<br>Actual";
$col["name"] = "edoprocesalactual_idedoprocesalactual";
$col["dbname"] = "edoprocesalactual_idedoprocesalactual"; // this is required as we need to search in name field, not id
$col["width"] = "12";
$col["align"] = "left";
$col["search"] = true;
$col["editable"] = true;
$col["formoptions"] = array("rowpos"=>"11", "colpos"=>"1");
$col["edittype"] = "select"; // render as select
# fetch data from database, with alias k for key, v for value
$str = $grid->get_dropdown_values("select idedoprocesalactual as k, edoprocesalactual as v from edoprocesalactual order by edoprocesalactual");
$col["editoptions"] = array("value"=>":;".$str);
//$col["formatter"] = "select"; // display label, not value
$col["stype"] = "select"; // enable dropdown search
$col["searchoptions"] = array("value" => ":;".$str);
$col["column"] = "edoprocesalactual_idedoprocesalactual";
$col["css"] = "'white-space':'normal'";
$col_conditions[]=$col;
$grid->set_conditional_css($col_conditions);
$cols[] = $col;
$col = array();
$col["title"] = "Abogado<br>Oficina";
$col["name"] = "abogado_idabogadoOficna";
$col["dbname"] = "abogado_idabogadoOficna"; // this is required as we need to search in name field, not id
$col["width"] = "10";
$col["align"] = "left";
$col["search"] = true;
$col["editable"] = true;
$col["formoptions"] = array("rowpos"=>"12", "colpos"=>"1");
$col["edittype"] = "select"; // render as select
# fetch data from database, with alias k for key, v for value
$str = $grid->get_dropdown_values("select idabogado as k, nombreabogado as v from abogado order by v");
if ($_SESSION['tipousuario'] == 2){
$col["editrules"] = array("readonly"=>true);
}
$col["editoptions"] = array("value"=>":;".$str);
//$col["formatter"] = "select"; // display label, not value
$col["stype"] = "select"; // enable dropdown search
$col["searchoptions"] = array("value" => ":;".$str);
$col["column"] = "abogado_idabogadoOficna";
$col["css"] = "'white-space':'normal'";
$col_conditions[]=$col;
$grid->set_conditional_css($col_conditions);
$cols[] = $col;
$col = array();
$col["title"] = "Abogado<br>Tribunal";
$col["name"] = "abogado_idabogadoTribunal";
$col["dbname"] = "abogado_idabogadoTribunal"; // this is required as we need to search in name field, not id
$col["width"] = "10";
$col["align"] = "left";
$col["search"] = true;
$col["editable"] = true;
$col["formoptions"] = array("rowpos"=>"13", "colpos"=>"1");
if ($_SESSION['tipousuario'] == 2){
$col["editrules"] = array("readonly"=>true);
}
$col["edittype"] = "select"; // render as select
# fetch data from database, with alias k for key, v for value
$str = $grid->get_dropdown_values("select idabogado as k, nombreabogado as v from abogado order by v");
$col["editoptions"] = array("value"=>":;".$str);
//$col["formatter"] = "select"; // display label, not value
$col["stype"] = "select"; // enable dropdown search
$col["searchoptions"] = array("value" => ":;".$str);
$col["column"] = "abogado_idabogadoTribunal";
$col["css"] = "'white-space':'normal'";
$col_conditions[]=$col;
$grid->set_conditional_css($col_conditions);
$cols[] = $col;
$col = array();
$col["title"] = "Resguardo<br>Expediente";
$col["name"] = "resguardoexpediente";
$col["width"] = "10";
$col["formoptions"] = array("rowpos"=>"14", "colpos"=>"1");
if ($_SESSION['tipousuario'] == 2){
$col["editrules"] = array("readonly"=>true);
}
$col["show"] = array("list"=>true, "add"=>true, "edit"=>true, "view"=>true);
$col["editable"] = true;
$cols[] = $col;
$col = array();
$col["title"] = "Monto de<br>Convenio";
$col["name"] = "montoconvenio";
$col["width"] = "11";
$col["align"] = "right";
$col["formatter"] = "currency";
$col["formatoptions"] = array("prefix" => "$",
"suffix" => '',
"thousandsSeparator" => ",",
"decimalSeparator" => ".",
"decimalPlaces" => 2);
$col["formoptions"] = array("rowpos"=>"15", "colpos"=>"1");
$col["editable"] = true;
$col["show"] = array("list"=>true, "add"=>true, "edit"=>true, "view"=>true);
$cols[] = $col;
$col = array();
$col["title"] = "Observaciones";
$col["name"] = "observaciones";
$col["width"] = "25";
$col["editable"] = true; // this column is not editable
$col["align"] = "left"; // this column is not editable
$col["search"] = true; // this column is not searchable
$col["edittype"] = "textarea";
$col["editoptions"] = array("rows"=>6, "cols"=>80);
$col["formoptions"] = array("rowpos"=>"16", "colpos"=>"1");
$col["column"] = "observaciones";
$col["css"] = "'white-space':'normal !important'";
$col_conditions[]=$col;
$grid->set_conditional_css($col_conditions);
$cols[] = $col;
$col = array();
$col["title"] = "Termi-<br>nado";
$col["name"] = "terminado";
$col["width"] = "7";
$col["editable"] = true;
$col["edittype"] = "checkbox";
$col["formatter"] = "checkbox";
$col["editoptions"] = array("value"=>"1:0");
$col["formoptions"] = array("rowpos"=>"1", "colpos"=>"2");
if ($_SESSION['tipousuario'] == 2){
$col["editrules"] = array("readonly"=>true);
}
//$col["show"] = array("list"=>true, "add"=>true, "edit"=>true, "view"=>true);
$cols[] = $col;
$grid->set_columns($cols);
if ($_SESSION['tipousuario'] == 2){
$grid->set_actions(array(
"add"=>false, // allow/disallow add
"edit"=>true, // allow/disallow edit
"delete"=>false, // allow/disallow delete
"rowactions"=>false, // show/hide row wise edit/del/save option
"export"=>false, // show/hide export to excel option
"autofilter" => true, // show/hide autofilter for search
"search" => "advance" // show single/multi field search condition (e.g. simple or advance)
)
);
}
else
{
$grid->set_actions(array(
"add"=>true, // allow/disallow add
"edit"=>true, // allow/disallow edit
"delete"=>true, // allow/disallow delete
"rowactions"=>false, // show/hide row wise edit/del/save option
"export"=>true, // show/hide export to excel option
"autofilter" => true, // show/hide autofilter for search
"search" => "advance" // show single/multi field search condition (e.g. simple or advance)
)
);
}
$grid->set_options($opt);
$out_master = $grid->render("list1");
unset($opt);
// detail grid
$grid = new jqgrid();
$opt = array();
$opt["sortname"] = 'idaudiencia'; // by default sort grid by this field
$opt["sortorder"] = "desc"; // ASC or DESC
$opt["height"] = ""; // autofit height of subgrid
$opt["width"] = "1130";
$opt["add_options"] = array('width'=>'700');
$opt["edit_options"] = array('width'=>'700');
$opt["caption"] = "Audiencias de la Acción"; // caption of grid
$opt["multiselect"] = true; // allow you to multi-select through checkboxes
$opt["export"] = array("filename"=>"ads_acciones_detalle-Exportado_El-" . date('d-m-Y')."_".date('h')."-".date('i')."_".date('a'), "sheetname"=>"Acciones_detalle", "format"=>"xls","heading"=>"Detalle de audiencias de Expediente - Exportado desde ADS Seguimiento a Excel el " . date('d/m/Y h:i:s a'));
//$opt["export"] = array("filename"=>"ads_acciones", "sheetname"=>"Acciones", "format"=>"pdf","heading"=>"Exportando a Excel","orientation"=>"portrait", "paper"=>"letter");
$opt["export"]["range"] = "filtered";
// Check if master record is selected before detail addition
$opt["add_options"]["beforeInitData"] = "function(formid){ var selr = jQuery('#list1').jqGrid('getGridParam','selrow'); if (!selr) { alert('Por favor sellecione una acción primero'); return false; } }";
$grid->set_options($opt);
$grid->set_actions(array(
"add"=>true, // allow/disallow add
"edit"=>true, // allow/disallow edit
"delete"=>true, // allow/disallow delete
"rowactions"=>true, // show/hide row wise edit/del/save option
"export"=>true, // show/hide export to excel option
"autofilter" => true, // show/hide autofilter for search
"search" => "advance" // show single/multi field search condition (e.g. simple or advance)
)
);
// receive id, selected row of parent grid
$id = intval($_GET["rowid"]);
$gender = $_GET["gender"];
$company = $_GET["company"];
$cid = intval($_GET["idaccion"]);
// for non-int fields as PK
// $id = (empty($_GET["rowid"])?0:$_GET["rowid"]);
// and use in sql for filteration
//$grid->select_command = "SELECT id,client_id,invdate,amount,tax,note,total,'$company' as 'company' FROM invheader WHERE client_id = $id";
$grid->select_command = "SELECT a.actor, a.expediente, a.fechaingreso,c.nombrecliente ,au.audienciaestado_idaudienciaestado, au.idaccion, au.archivo,au.idaudiencia, au.proximaaudiencia, au.observaciones, ae.estado,
au.ultimamodificacion,epa.edoprocesalactual as edoprocesalactual_idedoprocesalactual FROM accion a
inner join audiencia au on au.idaccion=a.idaccion
inner join audienciaestado ae on au.audienciaestado_idaudienciaestado=ae.idaudienciaestado
inner join cliente c on c.idcliente=a.cliente_idcliente
inner join edoprocesalactual epa on epa.idedoprocesalactual=au.edoprocesalactual_idedoprocesalactual
WHERE a.idaccion= $id";
//$grid->select_command = "SELECT idaudiencia, proximaaudiencia, observaciones, audienciaestado_idaudienciaestado, idaccion FROM audiencia WHERE idaccion= $id";
// this db table will be used for add,edit,delete
$grid->table = "audiencia";
unset($cols);
$col = array();
$col["title"] = "Id";
$col["name"] = "idaudiencia";
$col["width"] = "5";
$col["column"] = "idaudiencia";
$col["op"] = "=";
$col["value"] = "20";
$col["cellcss"] = "'background-color':'red'";
//$col["css"] = "'background-color':'#FBEC88', 'color':'green', 'font-weight':'bold'";
$col_conditions[]=$col;
$grid->set_conditional_css($col_conditions);
$cols[] = $col;
$col = array();
$col["title"] = "Fecha de<br>Audiencia (aaaa-mm-d)";
$col["name"] = "proximaaudiencia";
$col["width"] = "15";
$col["formoptions"] = array("rowpos"=>"1", "colpos"=>"1");
$col["editable"] = true; // this column is editable
$col["editoptions"] = array("size"=>20); // with default display of textbox with size 20
$col["editrules"] = array("required"=>true, "edithidden"=>true); // and is required
$col["searchoptions"]["sopt"] = array("cn"); // contains search for easy searching
# to make it date time
$col["formatter"] = "datetime";
# opts array can have these options: http://trentrichardson.com/examples/timepicker/#tp-options
$col["formatoptions"] = array("srcformat"=>'Y-m-d H:i:s',"newformat"=>'Y-m-d H:i:',"opts" => array("timeFormat"=>"HH:mm"));
//$col["formatoptions"] = array("srcformat"=>'Y-m-d H:i:s',"newformat"=>'d-m-Y H:i',"opts" => array("timeFormat"=>"HH:mm"));
$col["show"] = array("list"=>true, "add"=>true, "edit"=>true, "view"=>true);
$cols[] = $col;
$col = array();
$col["title"] = "Estado de<br>Audiencia";
$col["name"] = "audienciaestado_idaudienciaestado";
$col["dbname"] = "audienciaestado_idaudienciaestado"; // this is required as we need to search in name field, not id
$col["width"] = "15";
$col["align"] = "left";
$col["search"] = true;
$col["editable"] = true;
$col["editrules"] = array("required"=>true);
$col["edittype"] = "select"; // render as select
# fetch data from database, with alias k for key, v for value
$str = $grid->get_dropdown_values("select idaudienciaestado as k, estado as v from audienciaestado order by v");
$col["editoptions"] = array("value"=>":;".$str);
$col["formatter"] = "select"; // display label, not value
/*$col["editoptions"] = array(
"value"=>$str,
"onchange" => array(
"sql"=>"select * from audiencia",
"search_on"=>"audienciaestado_idaudienciaestado",
"callback" => "update_fields" )
); */
$col["editoptions"]=array("value"=>":;".$str);
$col["stype"] = "select"; // enable dropdown search
$col["searchoptions"] = array("value" => ":;".$str);
$cols[] = $col;
$col = array();
$col["title"] = "Tipo de<br>Audiencia";
$col["name"] = "edoprocesalactual_idedoprocesalactual";
$col["dbname"] = "edoprocesalactual_idedoprocesalactual"; // this is required as we need to search in name field, not id
$col["width"] = "12";
$col["align"] = "left";
$col["search"] = true;
$col["editable"] = true;
$col["formoptions"] = array("rowpos"=>"11", "colpos"=>"1");
$col["edittype"] = "select"; // render as select
# fetch data from database, with alias k for key, v for value
$str = $grid->get_dropdown_values("select idedoprocesalactual as k, edoprocesalactual as v from edoprocesalactual order by edoprocesalactual");
$col["editoptions"] = array("value"=>":;".$str);
//$col["formatter"] = "select"; // display label, not value
$col["stype"] = "select"; // enable dropdown search
$col["searchoptions"] = array("value" => ":;".$str);
$col["column"] = "edoprocesalactual_idedoprocesalactual";
$col["css"] = "'white-space':'normal'";
$col_conditions[]=$col;
$grid->set_conditional_css($col_conditions);
$col["formoptions"] = array("rowpos"=>"3", "colpos"=>"1");
$cols[] = $col;
// file upload column
$col = array();
$col["title"] = "Documento";
$col["name"] = "archivo";
$col["width"] = "50";
$col["editable"] = true; // this column is editable
$col["edittype"] = "file"; // render as file
$col["upload_dir"] = "archivos"; // upload here
$col["editrules"] = array("ifexist"=>"error"); // "rename", "override" can also be set
$col["show"] = array("list"=>true,"edit"=>true,"add"=>true); // only show in add/edit dialog
$col["formoptions"] = array("rowpos"=>"4", "colpos"=>"1");
$cols[] = $col;
// get upload folder url for display in grid -- change it as per your upload path
$upload_url = explode("/",$_SERVER["REQUEST_URI"]);
array_pop($upload_url);
$upload_url = implode("/",$upload_url)."/";
//$archivonombre=substr({archivo}, strpos({archivo},"/"),strlen({archivo})-strpos({archivo},"/"))
$col = array();
$col["title"] = "Ver/Descargar<br>Documento";
$col["name"] = "archivo";
$col["width"] = "17";
$col["editable"] = false; // this column is not editable
$col["align"] = "left"; // this column is not editable
$col["search"] = true; // this column is not searchable
$col["condition"] = array('$row["archivo"] == ""', "", "<a href='$upload_url/{archivo}' target='_blank'>{archivo}</a>");
$col["show"] = array("list"=>true,"edit"=>true,"add"=>true); // only show in listing & image in edit
// display image in edit dialog
//$col["editoptions"]["dataInit"] = "function(o){jQuery(o).parent().html(o.value);}";
$cols[] = $col;
$col = array();
$col["title"] = "Observaciones";
$col["name"] = "observaciones";
$col["width"] = "78";
$col["editable"] = true; // this column is not editable
$col["align"] = "left"; // this column is not editable
$col["search"] = true; // this column is not searchable
$col["edittype"] = "textarea";
$col["editoptions"] = array("rows"=>5, "cols"=>85);
$col["formoptions"] = array("rowpos"=>"5", "colpos"=>"1");
$col["column"] = "observaciones";
$col["css"] = "'white-space':'normal !important'";
$col_conditions[]=$col;
$grid->set_conditional_css($col_conditions);
$cols[] = $col;
$col = array();
$col["title"] = "Última<br>Modificación";
$col["name"] = "ultimamodificacion";
$col["width"] = "11";
$cols[] = $col;
$col = array();
$col["title"] = "Opciones";
$col["name"] = "act";
$col["width"] = "56";
$cols[] = $col;
// generate grid output, with unique grid name as 'list1'
$grid->set_columns($cols);
$e["on_insert"] = array("add_client", null, true);
$e["on_export"] = array("custom_export", null, false);
$grid->set_events($e);
function add_client(&$data)
{
$id = intval($_GET["rowid"]);
$data["params"]["idaccion"] = $id;
//$data["params"]["password"] = md5($data["params"]["password"]);
}
// params are array(<function-name>,<class-object> or <null-if-global-func>,<continue-default-operation>)
//$e["on_export"] = array("custom_export", null, false);
//$grid->set_events($e);
// custom on_export callback function
function custom_export($param)
{
$sql = $param["sql"]; // the SQL statement for export
$grid = $param["grid"]; // the complete grid object reference
if ($grid->options["export"]["format"] == "xls")
{
function xlsBOF(){
echo pack("ssssss",0x809,0x8,0x0,0x10,0x0,0x0);
return;
}
function xlsEOF(){
echo pack("ss",0x0A,0x00);
return;
}
function xlsWriteNumber($Row,$Col,$Value){
echo pack("sssss",0x203,14,$Row,$Col,0x0);
echo pack("d",$Value);
return;
}
function xlsWriteLabel($Row,$Col,$Value){
$L= strlen($Value);
echo pack("ssssss",0x204,8+$L,$Row,$Col,0x0,$L);
echo $Value;
return;
}
//Query Database
$rs=mysql_query($sql);
//Send Header
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate,post-check=0,pre-check=0");
header("Content-Type: application/force-download");
header("Content-Type: application/vnd.ms-excel");
header("Content-Type: application/download");
header("Content-Disposition: attachment;filename=".$grid->options["export"]["filename"].".xls");
header("Content-Transfer-Encoding: binary");
//XLS Data Cell
xlsBOF();
if(!empty($grid->options["export"]["heading"])){
xlsWriteLabel(0,0,$grid->options["export"]["heading"]);
}
$col=0;
$rs_cols = mysql_fetch_assoc($rs);
foreach($rs_cols as $k=>$v)
{
xlsWriteLabel(2,$col,ucwords($k));
if($col==3){
break;
}
$col++;
}
mysql_data_seek($rs,0);
$total=mysql_num_rows($rs);
$totalcolumnas=mysql_num_fields($rs);
$xlsRow=3;
while($rec = mysql_fetch_row($rs))
{
for($i=0;$i<$totalcolumnas;$i++)
{
//xlsWriteLabel($xlsRow,$i,utf8_decode($rec[$i]));
xlsWriteLabel($xlsRow,$i,utf8_decode($rec[$i]));
if($i==3){
break;
}
}
if($xlsRow==3){
break;
}
$xlsRow++;
}
$col=0;
mysql_data_seek($rs,0);
$rs_cols = mysql_fetch_assoc($rs);
foreach($rs_cols as $k=>$v)
{
//a.actor, a.expediente, a.fechaingreso,c.nombrecliente ,au.audienciaestado_idaudienciaestado, au.idaccion, au.archivo,
if($k=="actor" or $k=="expediente" or $k=="nombrecliente" or $k=="audienciaestado_idaudienciaestado" or $k=="idaccion" or $k=="archivo" or $k=="fechaingreso"){
$col++;
continue;
}
xlsWriteLabel(5,$col-7,ucwords($k));
$col++;
}
mysql_data_seek($rs,0);
$total=mysql_num_rows($rs);
$totalcolumnas=mysql_num_fields($rs);
$xlsRow=6;
while($rec = mysql_fetch_row($rs))
{
for($i=7;$i<$totalcolumnas;$i++)
{
//xlsWriteLabel($xlsRow,$i,utf8_decode($rec[$i]));
xlsWriteLabel($xlsRow,$i-7,utf8_decode($rec[$i]));
}
$xlsRow++;
}
xlsEOF();
exit();
}
}
$out_detail = $grid->render("list2");
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html>
<head>
<link rel="stylesheet" type="text/css" media="screen" href="lib/js/themes/redmond/jquery-ui.custom.css"></link>
<link rel="stylesheet" type="text/css" media="screen" href="lib/js/jqgrid/css/ui.jqgrid.css"></link>
<script src="lib/js/jquery.min.js" type="text/javascript"></script>
<script src="lib/js/jqgrid/js/i18n/grid.locale-es.js" type="text/javascript"></script>
<!-- <script src="lib/js/jqgrid/js/i18n/grid.locale-en.js" type="text/javascript"></script> //-->
<script src="lib/js/jqgrid/js/jquery.jqGrid.min.js" type="text/javascript"></script>
<script src="lib/js/themes/jquery-ui.custom.min.js" type="text/javascript"></script>
<script type="text/javascript" src="lib/js/datepicker-es.js"></script>
</head>
<body>
<div class="menu_grid">
<?
include_once("Login/menuinclude_grid.php");
?>
</div>
<div style="margin:10px">
<?php echo $out_master ?>
<br>
<?php echo $out_detail; ?>
</div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment