Advertisement
fsnoya

export to excel al PDF

Aug 19th, 2017
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 9.88 KB | None | 0 0
  1. <?
  2. #error_reporting(E_ALL & ~E_NOTICE);
  3. ini_set("display_errors","on");
  4.  
  5.  
  6. //CONEXION
  7. include("./../../../lib/php/conexion_total.php");
  8. include("./../../../lib/php/datos_entidad.php");
  9.  
  10. include("./../../phpgrid-full-v2.2/lib/inc/jqgrid_dist.php");
  11.  
  12.  
  13.     //para rellenar el campo semana_1 y domingo
  14.     $sql = "SELECT * FROM entidad LIMIT 0,1";
  15.     $resultado = mysql_query($sql, $conn);
  16.     $fila_entidad = mysql_fetch_array($resultado);
  17.     $nombre_opciones = $fila_entidad['nombre_opciones'];
  18.    
  19.  
  20. //PROBLEMAS CON EXPORT
  21. // discriminacios dias de la semana actual y la siguiente
  22.         include("../../../lib/php/mayus_minus_capital.inc.php");   
  23.         include("../../../lib/php/arrays_semana.php");
  24.  
  25.  
  26. //LISTADO TOTALES
  27. // nombre del archivo excel
  28. $n_archivo_l = 'lista_residentes_' . $n_dia . '_' . date('d-m-y');
  29.  
  30. $g = new jqgrid();
  31.  
  32.  
  33. // export PDF file params
  34. $grid["export"] = array("filename"=>$n_archivo_l, "heading"=>$n_archivo_l, "orientation"=>"portrait", "paper"=>"a4");
  35. // for excel, sheet header
  36. $grid["export"]["sheetname"] = $n_archivo_l;
  37.  
  38.  
  39. // export filtered data or all data
  40. $grid["export"]["range"] = "filtered"; // or "all"
  41.  
  42. // excel visual params
  43. $grid["cellEdit"] = true; // inline cell editing, like spreadsheet
  44. $grid["rownumbers"] = false;
  45. $grid["rownumWidth"] = 15;
  46.  
  47. // excel visual params
  48. $grid["cellEdit"] = true; // inline cell editing, like spreadsheet
  49. $grid["rownumbers"] = false;
  50. $grid["rownumWidth"] = 15;
  51.  
  52.  
  53. $grid["responsive"] = true;
  54.  
  55. // $grid["url"] = ""; // your paramterized URL -- defaults to REQUEST_URI
  56. $grid["rowNum"] = '30'; // by default 20
  57. $grid["sortname"] = 'nombre'; // by default sort grid by this field
  58. $grid["sortorder"] = "asc"; // ASC or DESC
  59. $grid["caption"] = "Lista de residentes"; // caption of grid
  60. $grid["autowidth"] = true; // expand grid to screen width
  61. //$grid["width"] = 600;
  62. $grid["height"] = 410;
  63. $grid["multiselect"] = true; // allow you to multi-select through checkboxes
  64. $grid["hiddengrid"] = false;
  65. $grid["rowactions"] = false;
  66.  
  67. $grid["add_options"]["beforeInitData"] = "function(formid) { $('#hola').jqGrid('setColProp','sin_comedor',{editable:false}); }";
  68. $grid["add_options"]["afterShowForm"] = "function(formid) { $('#hola').jqGrid('setColProp','sin_comedor',{editable:false}); }";
  69. $grid["edit_options"]["beforeSubmit"] = "function(post,form){ return validate_form_once(post,form); }";
  70. $grid["add_options"]["beforeSubmit"] = "function(post,form){ return validate_form_once(post,form); }";
  71.  
  72. $g->set_options($grid);
  73.  
  74.  
  75.  
  76. $g->set_actions(array( 
  77.                         "add"=>true, // allow/disallow add
  78.                         "edit"=>true, // allow/disallow edit
  79.                         "delete"=>true, // allow/disallow delete
  80.                         "rowactions"=>false, // show/hide row wise edit/del/save option
  81.                         "export_excel"=>true, // show/hide export to excel option - must set export xlsx params
  82.                         "export_pdf"=>true, // show/hide export to pdf option - must set pdf params
  83.                         "autofilter" => true, // show/hide autofilter for search
  84.                         "search" => 'simple', // show single/multi field search condition (e.g. simple or advance)
  85.                         "showhidecolumns" => false // show single/multi field search condition (e.g. simple or advance)
  86.                     )
  87.                 );
  88.  
  89.  
  90.  
  91. // you can provide custom SQL query to display data
  92. $g->select_command =  "SELECT
  93.             id,
  94.             nick,
  95.             clave,
  96.             nombre,
  97.             apellidos,
  98.             CONCAT(nombre, ' ', apellidos) as nombre_total,
  99.             habitacion,
  100.             semana_1,
  101.             domingo,
  102.             res_opciones_por_defecto,
  103.             regimen,
  104.             registro,
  105.             email,
  106.             curso,
  107.             sin_comedor,
  108.             'enviar' as enviar_email
  109.            
  110.             FROM residentes  WHERE nick != '' AND nombre != ''";
  111.  
  112. // this db table will be used for add,edit,delete
  113. $g->table = "residentes";
  114.  
  115.  
  116. $col = array();
  117. $col["title"] = "id";
  118. $col["name"] = "id";
  119. $col["width"] = "2";
  120. $col["export"] = false;
  121. $col["hidden"] = true; // hide column by default
  122. $cols[] = $col;
  123.  
  124. $col = array();
  125. $col["title"] = "nick";
  126. $col["name"] = "nick";
  127. $col["width"] = "1";
  128. $col["export"] = false;
  129. $col["hidden"] = false; // hide column by default
  130. $col["editable"] = true;
  131. $col["search"] = true;
  132. $col["visible"] = "xl";
  133. $cols[] = $col;
  134.  
  135. $col = array();
  136. $col["title"] = "curso";
  137. $col["name"] = "curso";
  138. $col["width"] = "1";
  139. $col["export"] = false;
  140. $col["hidden"] = false; // hide column by default
  141. $col["editable"] = true;
  142. $col["search"] = true;
  143. $col["visible"] = "xl";
  144. $cols[] = $col;
  145.  
  146. $col = array();
  147. $col["title"] = "clave";
  148. $col["name"] = "clave";
  149. $col["width"] = "1";
  150. //$col["align"] = "center";
  151. $col["editable"] = true;
  152. $col["export"] = true;
  153. $col["hidden"] = false ; // hide column by default
  154. $col["search"] = true; // this column is not searchable
  155. $col["editable"] = true;
  156. $col["visible"] = "xl";
  157. $cols[] = $col;
  158.  
  159. $col = array();
  160. $col["title"] = "habitación";
  161. $col["name"] = "habitacion";
  162. $col["width"] = "1";
  163. //$col["align"] = "center";
  164. $col["editable"] = true;
  165. $col["export"] = true;
  166. $col["hidden"] = false ; // hide column by default
  167. $col["search"] = true; // this column is not searchable
  168. $cols[] = $col;
  169.  
  170. $col = array();
  171. $col["title"] = "nombre";
  172. $col["name"] = "nombre";
  173. $col["editable"] = true;
  174. $col["width"] = "2";
  175. $col["export"] = true;
  176. $col["visible"] = "xl";
  177. $col["search"] = true;
  178. $cols[] = $col;
  179.  
  180.  
  181. $col = array();
  182. $col["title"] = "apellidos";
  183. $col["name"] = "apellidos";
  184. $col["width"] = "3";
  185. $col["editable"] = true;
  186. $col["export"] = true;
  187. $col["visible"] = "xl";
  188. $col["search"] = true;
  189. $cols[] = $col;
  190.  
  191. $col = array();
  192. $col["title"] = "nombre residente";
  193. $col["name"] = "nombre_total";
  194. $col["editable"] = true;
  195. $col["width"] = "3";
  196. $col["export"] = true;
  197. $col["visible"] = "xs+";
  198. $col["search"] = true;
  199. $cols[] = $col;
  200.  
  201.  
  202. $col = array();
  203. $col["title"] = "email";
  204. $col["name"] = "email";
  205. $col["width"] = "3";
  206. $col["editable"] = true;
  207. $col["export"] = true;
  208. $col["visible"] = "xs+";
  209. $col["search"] = true;
  210. $cols[] = $col;
  211.  
  212. $col = array();
  213. $col["title"] = "Regimen";
  214. $col["name"] = "regimen";
  215. $col["width"] = "1";
  216. $col["editable"] = true;
  217. $col["export"] = true;
  218. $col["search"] = true;
  219. $col["align"] = "center";
  220. $col["visible"] = "xl";
  221. $cols[] = $col;
  222.  
  223. $col = array();
  224. $col["title"] = "semana_1";
  225. $col["name"] = "semana_1";
  226. $col["width"] = "1";
  227. $col["editable"] = true;
  228. $col["export"] = true;
  229. $col["search"] = true;
  230. $col["align"] = "center";
  231. $col["hidden"] = true;
  232. $col["editoptions"] = array("defaultValue"=>$opciones_por_defecto);
  233. $cols[] = $col;
  234.  
  235. $col = array();
  236. $col["title"] = "domingo";
  237. $col["name"] = "domingo";
  238. $col["width"] = "1";
  239. $col["editable"] = true;
  240. $col["export"] = true;
  241. $col["search"] = true;
  242. $col["align"] = "center";
  243. $col["hidden"] = true;
  244. $col["editoptions"] = array("defaultValue"=>$opciones_por_defecto);
  245. $cols[] = $col;
  246.  
  247. $col = array();
  248. $col["title"] = "opciones_por_defecto";
  249. $col["name"] = "res_opciones_por_defecto";
  250. $col["width"] = "1";
  251. $col["editable"] = true;
  252. $col["export"] = true;
  253. $col["search"] = true;
  254. $col["align"] = "center";
  255. $col["hidden"] = true;
  256. $col["editoptions"] = array("defaultValue"=>$opciones_por_defecto);
  257. $cols[] = $col;
  258.  
  259. //escoger día sin comedor
  260. $col = array();
  261. $col["title"] = "sin comedor*";
  262. $col["name"] = "sin_comedor";
  263. $col["width"] = "3";
  264. $col["editable"] = true; // this column is editable
  265. $col["formatter"] = "date"; // format as date
  266. $col["formatoptions"] = array("srcformat"=>'Y-m-d',"newformat"=>'d/m/Y'); // http://docs.jquery.com/UI/Datepicker/formatDate
  267. $col["visible"] = "xl";
  268. $cols[] = $col;
  269.  
  270.  
  271. //enviar email_sin comida
  272. $col = array();
  273. $col["title"] = "Envía email**";
  274. $col["name"] = "enviar_email";
  275. $col["width"] = "2";
  276. $col["link"] = "./residentes/email_sin_comida.php?id={id}";
  277. $col["linkoptions"] = "target='_blank'"; // extra params with <a> tag
  278. $col["align"] = "center";
  279. $col["visible"] = "xl";
  280. $cols[] = $col;
  281.  
  282.  
  283. // pass the cooked columns to grid
  284. $g->set_columns($cols);
  285.  
  286. // generate grid output, with unique grid name as 'list1'
  287. $residentes = $g->render('hola');
  288.  
  289. ?>
  290. <body>
  291.  
  292.     <style type="text/css">
  293.        input[type=checkbox] {
  294.            display: block;
  295.             width:15px;
  296.            height: 15px;
  297.         }
  298.     </style>
  299.  <div id="div_lista_residentes" style=" width:100%; margin: 0 auto; clear:both; float:left; padding:10px 0 20px 0;" >
  300.  <? echo $residentes ?>
  301.  </div>
  302.  
  303.  <div style=" float:left">
  304.  (*) Es el día en que se deja a un usuario sin acceso al comedor. Después de seleccinar el día, hay que pulsar en otro campo para que se guarde el dato.<br>
  305.  En la lista de comidas de ese día no se contará a este residente.<br>
  306.  (**) Envía un email al usuario informándole de que en el dia seleccionado no tendrá comidas en el comedor.
  307.  </div>
  308. <script>
  309.     function my_validation(value,label)
  310.     {
  311.         if (value > 100)
  312.             return [true,""];
  313.         else
  314.             return [false,label+": Should be greater than 100"];
  315.     }
  316.    
  317.     function validate_form_once(post,form)
  318.     {
  319.         var str=[];
  320.        
  321.         if (post.nick== "")
  322.             str[str.length] = " NICK necesario";
  323.        
  324.         if (post.clave== "")
  325.             str[str.length] = " CLAVE necesaria";
  326.        
  327.         if (post.nombre== "")          
  328.             str[str.length] = " NOMBRE necesario";
  329.        
  330.         if (post.apellidos== "")
  331.             str[str.length] = " APELLIDOS necesarios";
  332.        
  333.         if (post.habitacion== "")
  334.             str[str.length] = " HABITACIÓN necesaria";
  335.        
  336.         if (post.email== "")
  337.             str[str.length] = " EMAIL necesario";
  338.        
  339.         if (str.length == 0)
  340.             return [true,""];
  341.         else
  342.             return [false,"ERRORES:<br>" + str];
  343.     }
  344.    
  345.     // enable form validation in inline edit
  346.     jQuery.extend(jQuery.jgrid.inlineEdit, {
  347.             beforeSaveRow: function (o,rowid) {
  348.                 data = [];
  349.                 jQuery(".editable").each(function(){ data[jQuery(this).attr('name')] = jQuery(this).val(); });
  350.                 ret = validate_form_once(data);
  351.                 if (!ret[0])
  352.                     jQuery.jgrid.info_dialog(jQuery.jgrid.errors.errcap,
  353.                                             '<div class="ui-state-error" style="text-align:left;padding:5px">'+ ret[1] +'</div>',
  354.                                             jQuery.jgrid.edit.bClose,{buttonalign:'right'});
  355.                 jQuery("#info_dialog").abscenter();
  356.                 return ret[0];
  357.             }
  358.         });
  359.    
  360.     </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement