1 | <?php |
---|
2 | /** |
---|
3 | * Sistema Integral de Planificación y Presupuesto (SIPP) |
---|
4 | * @file reportes_sipp.module |
---|
5 | * Drupal part Module to Sistema Integral de Planificación y Presupuesto (SIPP) |
---|
6 | * Copyright 2013 Sistema Automatizado para la Planificación Estratégico-Situacional en la Administración Pública Venezolana (CENDITEL) |
---|
7 | * |
---|
8 | * This program is free software; you can redistribute it and/or modify |
---|
9 | * it under the terms of the GNU General Public License as published by |
---|
10 | * the Free Software Foundation; either version 2 of the License, or |
---|
11 | * (at your option) any later version. |
---|
12 | * |
---|
13 | * This program is distributed in the hope that it will be useful, |
---|
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
16 | * GNU General Public License for more details. |
---|
17 | * |
---|
18 | * You should have received a copy of the GNU General Public License |
---|
19 | * along with this program; if not, write to the Free Software |
---|
20 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
---|
21 | * |
---|
22 | * @author Cenditel Merida - Ing. Diego Uzcátegui (diego.uzc [at] gmail [dot] com) |
---|
23 | * @date 2013-05-01 // (año-mes-dia) |
---|
24 | * @version 0.1 // (0.1) |
---|
25 | * |
---|
26 | */ |
---|
27 | |
---|
28 | /* |
---|
29 | * Pagina que muestra el reporte áreas estratégicas del ministerio |
---|
30 | * Implementado por: Ing. Diego Uzcátegui, |
---|
31 | * Inicio de codificación: 30-05-13 |
---|
32 | */ |
---|
33 | |
---|
34 | function areas_estrategicas_del_ministerio_reporte_formulario_microinforme_page(){ |
---|
35 | |
---|
36 | $output .= drupal_get_form('consulta_areas_estrategicas_del_ministerio_reporte_formulario_microinforme_form'); |
---|
37 | |
---|
38 | return $output; |
---|
39 | |
---|
40 | } |
---|
41 | |
---|
42 | //************************************************************************************************ |
---|
43 | |
---|
44 | /** |
---|
45 | * Implementation of consulta_areas_estrategicas_del_ministerio_reporte_formulario_microinforme_form(). |
---|
46 | */ |
---|
47 | function consulta_areas_estrategicas_del_ministerio_reporte_formulario_microinforme_form($form_state) { |
---|
48 | |
---|
49 | $primerformulario = (count($_SESSION['datos_para_generar_nuevomicroinforme_aem']) > 1)? false: true; |
---|
50 | |
---|
51 | $form = array(); |
---|
52 | |
---|
53 | //años disponibles |
---|
54 | $anno_actual = date("Y"); |
---|
55 | for($i = $anno_actual - 10; $i <= $anno_actual; $i++) { |
---|
56 | $annos[$i] = $i; |
---|
57 | } |
---|
58 | $anno_seleccionado_para_reporte = isset($_SESSION['datos_para_generar_nuevomicroinforme_aem']) && isset($_SESSION['datos_para_generar_nuevomicroinforme_aem']['anho']) ? $_SESSION['datos_para_generar_nuevomicroinforme_aem']['anho'] : date('Y'); |
---|
59 | $form['anno_seleccionado_para_reporte'] = array( |
---|
60 | '#title' => t('Año'), |
---|
61 | '#type' => 'select', |
---|
62 | '#default_value' => $anno_seleccionado_para_reporte, |
---|
63 | '#options' => $annos, |
---|
64 | '#disabled' => !$primerformulario, |
---|
65 | ); |
---|
66 | |
---|
67 | //areas estratégicas del ministerio |
---|
68 | $areas = array(); |
---|
69 | $result = db_query("SELECT td.tid AS tid, td.name AS name FROM {vocabulary} AS v, {term_data} AS td WHERE v.name = 'MPPCTI' AND v.vid = td.vid "); |
---|
70 | while($area = db_fetch_object($result)) { |
---|
71 | $areas[$area->tid] = $area->name; |
---|
72 | } |
---|
73 | $area_seleccionada_para_reporte = isset($_SESSION['datos_para_generar_nuevomicroinforme_aem']) && isset($_SESSION['datos_para_generar_nuevomicroinforme_aem']['area']) ? $_SESSION['datos_para_generar_nuevomicroinforme_aem']['area'] : 0; |
---|
74 | $form['area_seleccionada_para_reporte'] = array( |
---|
75 | '#title' => t('Ãrea Estratégica del Ministerio'), |
---|
76 | '#type' => 'select', |
---|
77 | '#default_value' => $area_seleccionada_para_reporte, |
---|
78 | '#options' => $areas, |
---|
79 | '#disabled' => !$primerformulario, |
---|
80 | ); |
---|
81 | |
---|
82 | if($primerformulario){ |
---|
83 | |
---|
84 | drupal_set_title(t('Nuevo Microinforme')); |
---|
85 | |
---|
86 | }else{ |
---|
87 | |
---|
88 | $nombre_estrategia = taxonomy_get_term($area_seleccionada_para_reporte)->name; |
---|
89 | drupal_set_title(t('Microinforme para la Estratégia <i>'.$nombre_estrategia.'</i> en el año <i>'.$anno_seleccionado_para_reporte.'</i>')); |
---|
90 | |
---|
91 | $form['informacion_textual'] = array( |
---|
92 | '#type' => 'textarea', |
---|
93 | '#title' => t('Información Textual para Microinforme'), |
---|
94 | '#default_value' => '', |
---|
95 | ); |
---|
96 | |
---|
97 | |
---|
98 | module_load_include('inc', 'reportes_sipp' , 'includes/aem/funciones_tablas_graficas.pages'); |
---|
99 | |
---|
100 | $tipografico_selec = t('Columnas'); |
---|
101 | $datos_cargados = calcular_datos_para_aem_reporte_page($anno_seleccionado_para_reporte, $area_seleccionada_para_reporte, $tipografico_selec); |
---|
102 | $contenidohtml .= generar_grafica_producciontrimestres($datos_cargados['datos_anho_actual'], $datos_cargados['param']); |
---|
103 | $contenidohtml .= generar_tabla_produccion_trimestres($datos_cargados['datos_anho_actual'], $datos_cargados['param']); |
---|
104 | $contenidohtml .= generar_grafica_historicos($datos_cargados); |
---|
105 | $contenidohtml .= '<br><br>'; |
---|
106 | |
---|
107 | $form['#datos_cargados'] = serialize($datos_cargados); |
---|
108 | |
---|
109 | $form['contenidohtml_tablas_graficos'] = array( |
---|
110 | '#value' => $contenidohtml, |
---|
111 | ); |
---|
112 | |
---|
113 | } |
---|
114 | |
---|
115 | //boton de enviar consulta |
---|
116 | $form['buttons'] = array( |
---|
117 | '#prefix' => '<div class="container-inline">', |
---|
118 | '#suffix' => '</div>', |
---|
119 | ); |
---|
120 | $nombre_boton = $primerformulario ? t('Cargar datos para Crear Microinforme'): t('Crear Microinforme'); |
---|
121 | $form['buttons']['submit'] = array( |
---|
122 | '#type' => 'submit', |
---|
123 | '#value' => $nombre_boton, |
---|
124 | ); |
---|
125 | if(!$primerformulario){ |
---|
126 | $form['buttons']['submit_reiniciar'] = array( |
---|
127 | '#type' => 'submit', |
---|
128 | '#value' => 'Reiniciar', |
---|
129 | ); |
---|
130 | } |
---|
131 | |
---|
132 | return $form; |
---|
133 | } |
---|
134 | |
---|
135 | /** |
---|
136 | * Implementation of consulta_areas_estrategicas_del_ministerio_reporte_formulario_microinforme_form_submit(). |
---|
137 | */ |
---|
138 | function consulta_areas_estrategicas_del_ministerio_reporte_formulario_microinforme_form_submit($form, &$form_state) { |
---|
139 | |
---|
140 | if($form_state['clicked_button']['#value'] == $form_state['values']['submit']){//if button 1 is clicked |
---|
141 | |
---|
142 | //verificar que no este creado el microinforme |
---|
143 | $sql1 = "SELECT"; |
---|
144 | $sql_campos = " COUNT(*) AS cant"; |
---|
145 | $sql_tablas = " FROM {microinformes_area_estrategica_mcti}"; |
---|
146 | $sql_condiciones = " WHERE anho = %d AND id_area_estrategica = %d"; |
---|
147 | $inputs = array(); |
---|
148 | $inputs[] = $form_state['values']['anno_seleccionado_para_reporte']; |
---|
149 | $inputs[] = $form_state['values']['area_seleccionada_para_reporte']; |
---|
150 | $sql1 .= $sql_campos.$sql_tablas.$sql_condiciones; |
---|
151 | |
---|
152 | $queryResult1 = db_query ( $sql1, $inputs); |
---|
153 | $resultado_consult_tabla = db_fetch_array ( $queryResult1 ); |
---|
154 | |
---|
155 | if(count($_SESSION['datos_para_generar_nuevomicroinforme_aem']) > 1){//si es 2do formulario |
---|
156 | |
---|
157 | global $user; |
---|
158 | if(($resultado_consult_tabla['cant']>0)){//ya existe |
---|
159 | |
---|
160 | drupal_set_message(t('¡El MicroInforme ya existe!')); |
---|
161 | |
---|
162 | }else{//guardar microinforme |
---|
163 | //insertar |
---|
164 | $exe_query = db_query("INSERT INTO {microinformes_area_estrategica_mcti} (anho, id_area_estrategica, informacion_textual, datos_graficas_y_tablas, fecha_creacion, uid) VALUES (%d, %d, '%s', '%s', %d, %d)", $form_state['values']['anno_seleccionado_para_reporte'], $form_state['values']['area_seleccionada_para_reporte'], check_plain($form_state['values']['informacion_textual']), $form['#datos_cargados'], time(), $user->uid); |
---|
165 | $id_microinforme = db_last_insert_id('microinformes_area_estrategica_mcti', 'id_microinforme'); |
---|
166 | $form_state['redirect'] = 'reportes_sipp/areas_estrategicas_ministerio/mi/lista_microinformes'; |
---|
167 | drupal_set_message(t('El MicroInforme se ha creado con éxito con el id: '.$id_microinforme)); |
---|
168 | } |
---|
169 | |
---|
170 | //reiniciar las variables de sesión |
---|
171 | $_SESSION['datos_para_generar_nuevomicroinforme_aem'] = array(); |
---|
172 | $_SESSION['datos_para_generar_nuevomicroinforme_aem']['ya existe'] = true; |
---|
173 | }else{//1er formulario |
---|
174 | $_SESSION['datos_para_generar_nuevomicroinforme_aem'] = array(); |
---|
175 | |
---|
176 | if(($resultado_consult_tabla['cant']>0)){//ya existe |
---|
177 | $_SESSION['datos_para_generar_nuevomicroinforme_aem']['ya existe'] = true; |
---|
178 | drupal_set_message(t('¡El MicroInforme ya existe! puede encontrarlo con la opción consultar')); |
---|
179 | }else{ |
---|
180 | |
---|
181 | $_SESSION['datos_para_generar_nuevomicroinforme_aem']['anho'] = $form_state['values']['anno_seleccionado_para_reporte']; |
---|
182 | $_SESSION['datos_para_generar_nuevomicroinforme_aem']['area'] = $form_state['values']['area_seleccionada_para_reporte']; |
---|
183 | } |
---|
184 | } |
---|
185 | |
---|
186 | }elseif($form_state['clicked_button']['#value'] == $form_state['values']['submit_reiniciar']){ //if button 2 is clicked |
---|
187 | |
---|
188 | $_SESSION['datos_para_generar_nuevomicroinforme_aem'] = array(); |
---|
189 | |
---|
190 | } |
---|
191 | } |
---|