1 | <?php |
---|
2 | /** |
---|
3 | * Sistema Automatizado para la Planificación Estratégico-Situacional en la Administración Pública Venezolana |
---|
4 | * @file causas_criticas.module |
---|
5 | * Drupal part Module to code ente planificador module |
---|
6 | * Copyright 2011 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 - Msc. Juan Vizcarrondo |
---|
23 | * @date 2011-12-01 // (año-mes-dia) |
---|
24 | * @date 2017-08-01 // (año-mes-dia) |
---|
25 | * @version 0.2 // (0.2) |
---|
26 | * |
---|
27 | */ |
---|
28 | |
---|
29 | define("CAUSA_CRITICA_PLAN", 'situacion_actual'); |
---|
30 | |
---|
31 | /* |
---|
32 | * Implementation of hook_ente_procesos_alter() |
---|
33 | */ |
---|
34 | function causas_criticas_ente_procesos_alter(&$procesos, $type) { |
---|
35 | if ($type != 'status') { |
---|
36 | $procesos['causas_criticas'] = array( |
---|
37 | 'title' => t('Causas crÃticas'), |
---|
38 | 'description' => t('Permite editar las causas crÃticas.'), |
---|
39 | 'message' => 'Se podrán registrar y/o modificar las causas crÃticas desde %fecha hasta la fecha %fecha1', |
---|
40 | 'message_expire' => 'Registrar y/o modificar las causas crÃticas no se encuentra disponible, se podra realizar desde %fecha hasta la fecha %fecha1)', |
---|
41 | 'weight' => 4, |
---|
42 | 'proceso' => 'explicacion', |
---|
43 | ); |
---|
44 | } |
---|
45 | } |
---|
46 | |
---|
47 | /* |
---|
48 | * Implementation of _get_causa_critica_acceso() |
---|
49 | * Obtiene el acceso de modificar causas criticas |
---|
50 | */ |
---|
51 | function _get_causa_critica_acceso($ente_planificador, $tipo_plan = array(), $causa = 0) { |
---|
52 | global $user; |
---|
53 | $mi_fecha = ente_planificador_user_acceso_proceso("causas_criticas", $ente_planificador); |
---|
54 | $current_time = time(); |
---|
55 | $ente = usuario_tiene_ente($user->uid); |
---|
56 | $tipo_plan = CAUSA_CRITICA_PLAN; |
---|
57 | $planns = _situacion_actual_preliminar_get_planns(); |
---|
58 | $plan = $planns[$tipo_plan]; |
---|
59 | $campo = 'field_causas_' . $plan['short']; |
---|
60 | $mi_ente = user_access('admin all planificador') || ($ente && $ente->nid && $ente->nid == $ente_planificador->nid); |
---|
61 | return $plan['ente_type'][$ente_planificador->tipo] && $mi_ente && (($mi_fecha[1] + 86399 > $current_time) && ($mi_fecha[0] < $current_time) && (!$causa || ($causa->type == 'causas' && $causa->{$campo}[0]['value'] && $causa->field_causas_year[0]['value'] == variable_get('situacional_actual_preliminar_anho_creacion', 0)))); |
---|
62 | } |
---|
63 | |
---|
64 | /* |
---|
65 | * Implementation of hook_menu() |
---|
66 | */ |
---|
67 | function causas_criticas_menu() { |
---|
68 | $items = array(); |
---|
69 | $items['planificacion/%ente_planificador_menu/explicacion/causas'] = array( |
---|
70 | 'title' => t('Causas CrÃticas'), |
---|
71 | 'page callback' => 'ente_planificador_view_causas_criticas', |
---|
72 | 'page arguments' => array(1), |
---|
73 | 'access callback' => '_get_causa_critica_acceso', |
---|
74 | 'access arguments' => array(1), |
---|
75 | 'weight' => -5, |
---|
76 | 'type' => MENU_LOCAL_TASK, |
---|
77 | ); |
---|
78 | $items['planificacion/%ente_planificador_menu/explicacion/causas/view'] = array( |
---|
79 | 'title' => t('Causas CrÃticas'), |
---|
80 | 'type' => MENU_DEFAULT_LOCAL_TASK, |
---|
81 | 'weight' => -10 |
---|
82 | ); |
---|
83 | $items['planificacion/%ente_planificador_menu/explicacion/causas/relaciones'] = array( |
---|
84 | 'title' => t('Relaciones entre causas'), |
---|
85 | 'page callback' => 'causas_criticas_view_seleccionar', |
---|
86 | 'page arguments' => array(1), |
---|
87 | 'access callback' => '_get_causa_critica_acceso', |
---|
88 | 'access arguments' => array(1), |
---|
89 | 'weight' => -8, |
---|
90 | 'type' => MENU_LOCAL_TASK, |
---|
91 | ); |
---|
92 | $items['planificacion/%ente_planificador_menu/explicacion/causas/relaciones/%node/%lcausa'] = array( |
---|
93 | 'title' => t('Relaciones entre causas'), |
---|
94 | 'page callback' => 'drupal_get_form', |
---|
95 | 'page arguments' => array('causas_criticas_view_select_form', 1, 5, 6), |
---|
96 | 'access callback' => '_get_causa_critica_acceso', |
---|
97 | 'access arguments' => array(1, 6), |
---|
98 | 'weight' => -8, |
---|
99 | ); |
---|
100 | $items['planificacion/%ente_planificador_menu/explicacion/causas/posibles'] = array( |
---|
101 | 'title' => t('Posibles Causas crÃticas'), |
---|
102 | 'page callback' => 'drupal_get_form', |
---|
103 | 'page arguments' => array('causas_criticas_posibles_view_form', 1), |
---|
104 | 'access callback' => '_get_causa_critica_acceso', |
---|
105 | 'access arguments' => array(1), |
---|
106 | 'weight' => -8, |
---|
107 | 'type' => MENU_LOCAL_TASK, |
---|
108 | ); |
---|
109 | $items['planificacion/%ente_planificador_menu/explicacion/causas/posibles/view'] = array( |
---|
110 | 'title' => t('Situación Actual'), |
---|
111 | 'page callback' => 'ente_planificador_view_causas_relaciones_posibles_view', |
---|
112 | 'page arguments' => array(1), |
---|
113 | 'access callback' => '_get_causa_critica_acceso', |
---|
114 | 'access arguments' => array(1), |
---|
115 | 'weight' => -8, |
---|
116 | 'type' => MENU_LOCAL_TASK, |
---|
117 | ); |
---|
118 | $items['planificacion/%ente_planificador_menu/explicacion/causas/select'] = array( |
---|
119 | 'title' => t('Situación Actual'), |
---|
120 | 'page callback' => 'drupal_get_form', |
---|
121 | 'page arguments' => array('causas_criticas_select_causas_form', 1), |
---|
122 | 'access callback' => '_get_causa_critica_acceso', |
---|
123 | 'access arguments' => array(1), |
---|
124 | 'weight' => -8, |
---|
125 | 'type' => MENU_LOCAL_TASK, |
---|
126 | ); |
---|
127 | $items['planificacion/%ente_planificador_menu/explicacion/causas/description'] = array( |
---|
128 | 'title' => t('Situación Actual'), |
---|
129 | 'page callback' => 'ente_planificador_view_causas_criticas_description', |
---|
130 | 'page arguments' => array(1), |
---|
131 | 'access callback' => '_get_causa_critica_acceso', |
---|
132 | 'access arguments' => array(1), |
---|
133 | 'weight' => -8, |
---|
134 | 'type' => MENU_LOCAL_TASK, |
---|
135 | ); |
---|
136 | $items['planificacion/%ente_planificador_menu/explicacion/causas/description/%lcausa'] = array( |
---|
137 | 'title' => t('Situación Actual'), |
---|
138 | 'page callback' => 'drupal_get_form', |
---|
139 | 'page arguments' => array('causas_criticas_select_causas_descriptores_form', 1, 5), |
---|
140 | 'access callback' => '_get_causa_critica_acceso', |
---|
141 | 'access arguments' => array(1, 5), |
---|
142 | 'weight' => -8, |
---|
143 | 'type' => MENU_LOCAL_TASK, |
---|
144 | ); |
---|
145 | $items['planificacion/%ente_planificador_menu/explicacion/situacion_objetivo'] = array( |
---|
146 | 'title' => t('Situación Objetivo'), |
---|
147 | 'page callback' => 'ente_planificador_view_situacion_objetivo', |
---|
148 | 'page arguments' => array(1), |
---|
149 | 'access callback' => '_get_causa_critica_acceso', |
---|
150 | 'access arguments' => array(1), |
---|
151 | 'weight' => -4, |
---|
152 | 'type' => MENU_LOCAL_TASK, |
---|
153 | ); |
---|
154 | $items['planificacion/%ente_planificador_menu/explicacion/situacion_objetivo/view'] = array( |
---|
155 | 'title' => t('Descripción de la Situación Objetivo'), |
---|
156 | 'type' => MENU_DEFAULT_LOCAL_TASK, |
---|
157 | 'weight' => 0, |
---|
158 | ); |
---|
159 | return $items; |
---|
160 | } |
---|
161 | |
---|
162 | /* |
---|
163 | * Implementation of causas_criticas_status_planificacion_explicacion() |
---|
164 | */ |
---|
165 | function causas_criticas_status_planificacion_explicacion($ente_planificador, $tipo = 2) { |
---|
166 | $causas_criticas = array(); |
---|
167 | if ($tipo == 1) { |
---|
168 | $mi_fecha = ente_planificador_user_acceso_proceso('causas', $tipo); |
---|
169 | //muestre el estado de la explicacion situacional |
---|
170 | //Get current causas |
---|
171 | $sql_query = "SELECT c.nid FROM {content_type_causas} AS c INNER JOIN {node} AS n ON c.nid = n.nid AND c.vid = n.vid WHERE c.field_ente_planifiador_nid = %d AND n.created >= %d AND n.created <= %d"; |
---|
172 | $sql_variables = array(); |
---|
173 | $sql_variables[] = $ente_planificador; |
---|
174 | $sql_variables[] = $mi_fecha[0]; |
---|
175 | $sql_variables[] = $mi_fecha[1] + 86399; |
---|
176 | $result = db_query($sql_query, $sql_variables); |
---|
177 | $causas = array(); |
---|
178 | $relacions = array(); |
---|
179 | while($causa = db_fetch_object($result)) { |
---|
180 | $causas[$causa->nid] = node_load($causa->nid); |
---|
181 | } |
---|
182 | if (count($causas)) { |
---|
183 | foreach ($causas as $idy => $itemy) { |
---|
184 | if (count($itemy->field_causas_relacion)) { |
---|
185 | foreach($itemy->field_causas_relacion as $relacion){ |
---|
186 | if ($relacion['nid']) { |
---|
187 | $relacions[$relacion['nid']] = 1; |
---|
188 | } |
---|
189 | } |
---|
190 | } |
---|
191 | } |
---|
192 | } |
---|
193 | $causas_criticas['causa_relacion']['value'] = count($relacions) ? 1 : 0; |
---|
194 | $causas_criticas['causa_relacion']['title'] = t('Relación entre causas'); |
---|
195 | $causas_criticas['causa_relacion']['link'] = 'planificacion/' . $ente_planificador . '/explicacion/causas/posibles/relaciones'; |
---|
196 | $causas_criticas['causa_relacion']['mylink'] = 'mi_ente_planificador/planificacion/explicacion/causas/posibles/relaciones'; |
---|
197 | $causas_criticas['causa_relacion']['weight'] = 1; |
---|
198 | $sql_query = "SELECT c.nid FROM {content_type_causas} AS c INNER JOIN {node} AS n ON c.nid = n.nid AND c.vid = n.vid WHERE c.field_ente_planifiador_nid = %d AND c.field_causa_posible_value = '1' AND n.created >= %d AND n.created <= %d"; |
---|
199 | $result = db_query($sql_query, $sql_variables); |
---|
200 | $causas = array(); |
---|
201 | $rows = array(); |
---|
202 | while($causa = db_fetch_object($result)) { |
---|
203 | $causas[] = $causa; |
---|
204 | } |
---|
205 | $causas_criticas['causa_posibles']['value'] = count($causas) ? 1 : 0; |
---|
206 | $causas_criticas['causa_posibles']['title'] = t('Posibles Causas CrÃticas'); |
---|
207 | $causas_criticas['causa_posibles']['link'] = 'planificacion/' . $ente_planificador . '/explicacion/causas/posibles/view'; |
---|
208 | $causas_criticas['causa_posibles']['mylink'] = 'mi_ente_planificador/planificacion/explicacion/causas/posibles/view'; |
---|
209 | $causas_criticas['causa_posibles']['weight'] = 1; |
---|
210 | //Get current causas |
---|
211 | $sql_query = "SELECT c.nid FROM {content_type_causas} AS c INNER JOIN {node} AS n ON c.nid = n.nid AND c.vid = n.vid WHERE c.field_ente_planifiador_nid = %d AND c.field_causa_posible_value = '1' AND n.created >= %d AND n.created <= %d"; |
---|
212 | $result = db_query($sql_query, $sql_variables); |
---|
213 | $causas = array(); |
---|
214 | while($causa = db_fetch_object($result)) { |
---|
215 | $causas[] = node_load($causa->nid); |
---|
216 | } |
---|
217 | $causas_criticas['causa_seleccionar']['value'] = count($causas) ? 1 : 0; |
---|
218 | $causas_criticas['causa_seleccionar']['title'] = t('Seleccionar Causas CrÃticas'); |
---|
219 | $causas_criticas['causa_seleccionar']['link'] = 'planificacion/' . $ente_planificador . '/explicacion/causas/select'; |
---|
220 | $causas_criticas['causa_seleccionar']['mylink'] = 'mi_ente_planificador/planificacion/explicacion/causas/select'; |
---|
221 | $causas_criticas['causa_seleccionar']['weight'] = 1; |
---|
222 | $describir = array(); |
---|
223 | if (count($causas)) { |
---|
224 | foreach($causas as $causa) { |
---|
225 | if (isset($causa->field_causa_descriptores[0]['value']) && $causa->field_causa_descriptores[0]['value'] && trim($causa->field_causa_descriptores[0]['value']) != '') { |
---|
226 | $describir[] = $causa->field_causa_descriptores[0]['value']; |
---|
227 | } |
---|
228 | } |
---|
229 | } |
---|
230 | $causas_criticas['causa_describir']['value'] = count($describir) ? 1 : 0; |
---|
231 | $causas_criticas['causa_describir']['title'] = t('Describir Causas CrÃticas'); |
---|
232 | $causas_criticas['causa_describir']['link'] = 'planificacion/' . $ente_planificador . '/explicacion/causas/description'; |
---|
233 | $causas_criticas['causa_describir']['mylink'] = 'mi_ente_planificador/planificacion/explicacion/causas/description'; |
---|
234 | $causas_criticas['causa_describir']['weight'] = 1; |
---|
235 | } |
---|
236 | return $causas_criticas; |
---|
237 | } |
---|
238 | |
---|
239 | /** |
---|
240 | * Implementation of hook_theme(). |
---|
241 | */ |
---|
242 | function causas_criticas_theme() { |
---|
243 | return array( |
---|
244 | 'causas_criticas_view_form' => array( |
---|
245 | 'arguments' => array('form' => NULL), |
---|
246 | ), |
---|
247 | 'causas_criticas_tapir_table' => array( |
---|
248 | 'arguments' => array('form' => NULL), |
---|
249 | ), |
---|
250 | ); |
---|
251 | } |
---|
252 | |
---|
253 | /** |
---|
254 | * Themes form data into a table for display. |
---|
255 | * |
---|
256 | * @param $form |
---|
257 | * The array of form information needing to be rendered into the table. |
---|
258 | * @return |
---|
259 | * The table output rendered in HTML. |
---|
260 | * @ingroup themeable |
---|
261 | */ |
---|
262 | function theme_causas_criticas_tapir_table($element) { |
---|
263 | $header = array(); |
---|
264 | $rows = array(); |
---|
265 | $count = 0; |
---|
266 | // Loop through the columns and create the header array. |
---|
267 | foreach ($element['#columns'] as $col_id => $col_data) { |
---|
268 | // Add the cell if available. |
---|
269 | |
---|
270 | |
---|
271 | if (!isset($col_data['access']) || $col_data['access'] !== FALSE) { |
---|
272 | $count++; |
---|
273 | $header[] = array('data' => $col_data['cell']); |
---|
274 | } |
---|
275 | } |
---|
276 | $row = array(); |
---|
277 | $row[] = array('data' => '<b>' . t('Causas Productoras') . '</b>', 'align' => 'center'); |
---|
278 | $row[] = array('data' => '<b>' . t('Causas Derivadas') . '</b>', 'colspan' => $count - 1, 'align' => 'center'); |
---|
279 | $rows[] = $row; |
---|
280 | // Loop through the row data and create rows with the data in the right order. |
---|
281 | foreach ($element['#rows'] as $data) { |
---|
282 | $attributes = array(); |
---|
283 | $row = array(); |
---|
284 | // Loop through each column in the header. |
---|
285 | foreach ($element['#columns'] as $col_id => $col_data) { |
---|
286 | // If this row defines cell data for the current column... |
---|
287 | if ((!isset($col_data['access']) || $col_data['access'] !== FALSE) && isset($data[$col_id])) { |
---|
288 | $cell = array(); |
---|
289 | if (isset($data[$col_id]['#cell_attributes']) && is_array($data[$col_id]['#cell_attributes'])) { |
---|
290 | foreach ($data[$col_id]['#cell_attributes'] as $property => $value) { |
---|
291 | if ($property == 'colspan' && $value == 'full') { |
---|
292 | // Extend full-width cells to the number of columns actually |
---|
293 | // displayed. |
---|
294 | $value = count($header); |
---|
295 | } |
---|
296 | $cell[$property] = $value; |
---|
297 | } |
---|
298 | $cell['data'] = drupal_render($data[$col_id]); |
---|
299 | } |
---|
300 | else { |
---|
301 | $cell = drupal_render($data[$col_id]); |
---|
302 | } |
---|
303 | // Add it to the row array. |
---|
304 | $row[] = $cell; |
---|
305 | } |
---|
306 | } |
---|
307 | // Merge the row data into a single row array along with the attributes. |
---|
308 | $row = array_merge(array('data' => $row), (array)$data['#attributes']); |
---|
309 | // Add the current row to the table rows array. |
---|
310 | $rows[] = $row; |
---|
311 | } |
---|
312 | // Return the rendered table. |
---|
313 | return theme('table', $header, $rows, (array)$element['#attributes'], $element['#title']) . (isset($element['#children']) ? $element['#children'] : ''); |
---|
314 | } |
---|
315 | |
---|
316 | /* |
---|
317 | * Implementation of _get_causas_derivadas() |
---|
318 | * Obtiene las causas derivadas por tipo de plan |
---|
319 | */ |
---|
320 | function _get_causas_derivadas($ente_planificador = 0, $tipo_plan = array(), $year = 0){ |
---|
321 | $sql = "SELECT d.nid AS descriptor, cr.* FROM {content_type_descriptores} AS d INNER JOIN {content_field_descriptores_causa} AS dc ON dc.nid = d.nid AND dc.vid = d.vid INNER JOIN {content_field_causas_relacion} AS cr ON cr.nid = dc.field_descriptores_causa_nid INNER JOIN {node} AS n ON cr.nid = n.nid AND cr.vid = n.vid WHERE d.field_descriptores_planificador_nid = %d AND d.field_descriptores_year_value = %d"; |
---|
322 | $inputs = array(); |
---|
323 | $inputs[] = $ente_planificador; |
---|
324 | $inputs[] = $year; |
---|
325 | if ($tipo_plan['short']) { |
---|
326 | $sql .= ' AND d.field_descriptores_' . $tipo_plan['short'] . '_value = %d'; |
---|
327 | $inputs[] = 1; |
---|
328 | } |
---|
329 | $result = db_query($sql, $inputs); |
---|
330 | $relaciones = array(); |
---|
331 | while($causa = db_fetch_object($result)) { |
---|
332 | $relaciones[$causa->descriptor][$causa->nid][$causa->field_causas_relacion_nid] = $causa->field_causas_relacion_nid; |
---|
333 | } |
---|
334 | return $relaciones; |
---|
335 | } |
---|
336 | |
---|
337 | |
---|
338 | /* |
---|
339 | * Implementation of causas_criticas_view_form() |
---|
340 | */ |
---|
341 | function causas_criticas_view_seleccionar($ente_planificador) { |
---|
342 | global $user; |
---|
343 | $breadcrumb[] = l(t('Home'), '<front>'); |
---|
344 | $breadcrumb[] = l(t('Explicación Situacional'), 'planificacion/' . $ente_planificador->nid . '/explicacion'); |
---|
345 | $breadcrumb[] = l(t('Causas CrÃticas'), 'planificacion/' . $ente_planificador->nid . '/explicacion/causas'); |
---|
346 | $texto = t('Relaciones entre causas'); |
---|
347 | $breadcrumb[] = $texto; |
---|
348 | drupal_set_breadcrumb($breadcrumb); |
---|
349 | drupal_set_title($texto); |
---|
350 | $mi_fecha = ente_planificador_user_acceso_proceso("causas_criticas", $ente_planificador); |
---|
351 | $current_time = time(); |
---|
352 | $fecha = FALSE; |
---|
353 | if ($mi_fecha[1] + 86399 > $current_time && $mi_fecha[0] < $current_time) { |
---|
354 | $fecha = TRUE; |
---|
355 | } |
---|
356 | if (!$fecha) { |
---|
357 | muestra_mensaje("causas_criticas", $ente_planificador); |
---|
358 | } |
---|
359 | else { |
---|
360 | $ente = usuario_tiene_ente($user->uid); |
---|
361 | if (user_access('admin all planificador') || $ente->nid == $ente_planificador->nid) { |
---|
362 | muestra_mensaje("causas_criticas", $ente_planificador, 0); |
---|
363 | $ente_has_acceso = TRUE; |
---|
364 | } |
---|
365 | } |
---|
366 | $year = variable_get('situacional_actual_preliminar_anho_creacion', 0); |
---|
367 | $tipo_plan = CAUSA_CRITICA_PLAN; |
---|
368 | $planns = _situacion_actual_preliminar_get_planns(); |
---|
369 | $plan = $planns[$tipo_plan]; |
---|
370 | $descriptores = _get_situacion_actual_listar_all_descriptores($ente_planificador->nid, $plan, $year); |
---|
371 | $acceso = TRUE; |
---|
372 | $derivadas = _get_causas_derivadas($ente_planificador->nid, $plan, $year); |
---|
373 | $headers_table = array(); |
---|
374 | $headers_table[] = array('data' => t('Descriptores')); |
---|
375 | $headers_table[] = array('data' => t('Causas Productoras')); |
---|
376 | $headers_table[] = array('data' => t('Causas Derivadas')); |
---|
377 | $rows = array(); |
---|
378 | foreach($descriptores as $descriptor) { |
---|
379 | $row = array(); |
---|
380 | $cuenta_causa = count($descriptor['causas']); |
---|
381 | $row[] = array('data' => $descriptor['body'], 'rowspan' => $cuenta_causa); |
---|
382 | foreach ($descriptor['causas'] as $causa) { |
---|
383 | $row[] = array('data' => $causa['body'],); |
---|
384 | $causas = array(); |
---|
385 | if (isset($derivadas[$descriptor['nid']][$causa['nid']]) && count($derivadas[$descriptor['nid']][$causa['nid']])) { |
---|
386 | foreach($derivadas[$descriptor['nid']][$causa['nid']] as $id => $causa_d){ |
---|
387 | if (isset($descriptor['causas'][$id])) { |
---|
388 | $causas[$id] = $descriptor['causas'][$id]['body']; |
---|
389 | } |
---|
390 | |
---|
391 | } |
---|
392 | } |
---|
393 | $lista = count($causas)? theme('item_list', $causas) : t('No existen causas derivadas.'); |
---|
394 | if ($acceso && $cuenta_causa > 1) { |
---|
395 | $lista .= '<br>' .l(t("Agregar Relación"), 'planificacion/' . $ente_planificador->nid . '/explicacion/causas/relaciones/' . $descriptor['nid'] . '/' . $causa['nid'], array('query' => array('destination' => $_GET['q']))); |
---|
396 | } |
---|
397 | $row[] = array('data' => $lista); |
---|
398 | $rows[] = $row; |
---|
399 | $row = array(); |
---|
400 | } |
---|
401 | } |
---|
402 | if (!count($rows)) { |
---|
403 | $row = array(); |
---|
404 | $row[] = array('data' => t('No se encontrarón descriptores para este ente'), 'colspan' => count($headers_table)); |
---|
405 | $rows[] = $row; |
---|
406 | } |
---|
407 | return theme('table', $headers_table, $rows); |
---|
408 | } |
---|
409 | |
---|
410 | /** |
---|
411 | * form relations of causas |
---|
412 | */ |
---|
413 | function causas_criticas_view_select_form($form_state, $ente_planificador, $descriptor, $causa) { |
---|
414 | global $user; |
---|
415 | $breadcrumb[] = l(t('Home'), '<front>'); |
---|
416 | $breadcrumb[] = l(t('Explicación Situacional'), 'planificacion/' . $ente_planificador->nid . '/explicacion'); |
---|
417 | $breadcrumb[] = l(t('Causas CrÃticas'), 'planificacion/' . $ente_planificador->nid . '/explicacion/causas'); |
---|
418 | $breadcrumb[] = l(t('Relaciones entre Causas'), 'planificacion/' . $ente_planificador->nid . '/explicacion/causas/relaciones'); |
---|
419 | $texto = t('Agregar relación'); |
---|
420 | $breadcrumb[] = $texto; |
---|
421 | drupal_set_breadcrumb($breadcrumb); |
---|
422 | drupal_set_title(t('Relaciones de la causa @causa', array('@causa' => $causa->body))); |
---|
423 | $mi_fecha = ente_planificador_user_acceso_proceso("causas_criticas", $ente_planificador); |
---|
424 | $current_time = time(); |
---|
425 | $fecha = FALSE; |
---|
426 | if ($mi_fecha[1] + 86399 > $current_time && $mi_fecha[0] < $current_time) { |
---|
427 | $fecha = TRUE; |
---|
428 | } |
---|
429 | if (!$fecha) { |
---|
430 | muestra_mensaje("causas_criticas", $ente_planificador); |
---|
431 | } |
---|
432 | else { |
---|
433 | $ente = usuario_tiene_ente($user->uid); |
---|
434 | if (user_access('admin all planificador') || $ente->nid == $ente_planificador->nid) { |
---|
435 | muestra_mensaje("causas_criticas", $ente_planificador, 0); |
---|
436 | $ente_has_acceso = TRUE; |
---|
437 | } |
---|
438 | } |
---|
439 | $form = array(); |
---|
440 | $form['#ente_planificador'] = $ente_planificador; |
---|
441 | $form['#descriptor'] = $descriptor; |
---|
442 | $form['#causa'] = $causa; |
---|
443 | $causas_options = array(); |
---|
444 | $inpunts_values = array(); |
---|
445 | $inpunts_values[] = $descriptor->nid; |
---|
446 | $sql = "SELECT c.field_descriptores_causa_nid as nid, nr.body FROM {content_field_descriptores_causa} AS c INNER JOIN {node} AS n ON c.field_descriptores_causa_nid = n.nid INNER JOIN {node} AS n1 ON c.nid = n1.nid AND c.vid = n1.vid INNER JOIN {node_revisions} AS nr ON n.nid = nr.nid AND n.vid = nr.vid WHERE c.nid = %d ORDER BY nr.body"; |
---|
447 | $result = db_query($sql, $inpunts_values); |
---|
448 | while($causa_sql = db_fetch_object($result)) { |
---|
449 | if ($causa->nid != $causa_sql->nid) { |
---|
450 | $causas[$causa_sql->nid] = $causa_sql->body; |
---|
451 | } |
---|
452 | } |
---|
453 | $default_value = array(); |
---|
454 | $default_nid = array(); |
---|
455 | $causas_relacion = array(); |
---|
456 | foreach($causa->field_causas_relacion as $causa_r) { |
---|
457 | if ($causa_r['nid'] && isset($causas[$causa_r['nid']])) { |
---|
458 | $default_value[$causa_r['nid']] = $causa_r['nid']; |
---|
459 | $default_nid[]['nid'] = $causa_r['nid']; |
---|
460 | } |
---|
461 | $causas_relacion[$causa_r['nid']] = $causa_r['nid']; |
---|
462 | $default_nid[]['nid'] = $causa_r['nid']; |
---|
463 | } |
---|
464 | $form['#causas_relacion'] = $causas_relacion; |
---|
465 | $form['causa_name'] = array( |
---|
466 | '#value' => '<br><b>' . t('Descriptor:') . '</b> ' . $descriptor->body . '<br><b>' . t('Causa Productora:') . '</b> ' . $causa->body, |
---|
467 | ); |
---|
468 | $form['causas_select'] = array( |
---|
469 | '#title' => t('Causas Derivadas'), |
---|
470 | '#type' => 'checkboxes', |
---|
471 | '#default_value' => $default_value, |
---|
472 | '#options' => $causas, |
---|
473 | '#required' => FALSE, |
---|
474 | ); |
---|
475 | if ($ente_has_acceso) { |
---|
476 | $form['buttons']['submit'] = array( |
---|
477 | '#type' => 'submit', |
---|
478 | '#value' => t('Submit'), |
---|
479 | '#weight' => 20 |
---|
480 | ); |
---|
481 | $form['buttons']['cancel'] = array( |
---|
482 | '#type' => 'submit', |
---|
483 | '#value' => t('Cancel'), |
---|
484 | '#weight' => 21 |
---|
485 | ); |
---|
486 | } |
---|
487 | return $form; |
---|
488 | } |
---|
489 | |
---|
490 | /* |
---|
491 | * Implementation of causas_criticas_view_form_submit() |
---|
492 | */ |
---|
493 | function causas_criticas_view_select_form_submit($form, &$form_state) { |
---|
494 | if (!$_REQUEST['destination']) { |
---|
495 | // add redirect |
---|
496 | $form_state['redirect'] = 'planificacion/' . $form['#ente_planificador']->nid . '/explicacion/causas/relaciones'; |
---|
497 | } |
---|
498 | $op = isset($form_state['values']['op']) ? $form_state['values']['op'] : ''; |
---|
499 | if ($op == t('Cancel')) { |
---|
500 | return; |
---|
501 | } |
---|
502 | $causa = $form['#causa']; |
---|
503 | $default_nid = $form['#default_nid']; |
---|
504 | $causas_relacion = $form['#causas_relacion']; |
---|
505 | foreach($form_state['values']['causas_select'] as $id => $idc) { |
---|
506 | if ($idc && !isset($causas_relacion[$idc])) { |
---|
507 | $causas_relacion[$idc] = $idc; |
---|
508 | } |
---|
509 | else if (!$idc && isset($causas_relacion[$id])) { |
---|
510 | unset($causas_relacion[$id]); |
---|
511 | } |
---|
512 | } |
---|
513 | $relaciones = array(); |
---|
514 | foreach($causas_relacion as $id) { |
---|
515 | $relaciones[]['nid'] = $id; |
---|
516 | } |
---|
517 | module_load_include('inc', 'content', 'includes/content.node_form'); |
---|
518 | $causa->field_causas_relacion = $relaciones; |
---|
519 | $causa = node_submit($causa); |
---|
520 | $causa->log = t('Modificada la relación entre las causas'); |
---|
521 | $causa->revision = 1; |
---|
522 | node_save($causa); |
---|
523 | drupal_set_message(t('Se han agregado las relaciones de la posible causa crÃtica')); |
---|
524 | } |
---|
525 | |
---|
526 | /* |
---|
527 | * Implementation of causas_criticas_view_form() |
---|
528 | */ |
---|
529 | function causas_criticas_view_form($form_state, $ente_planificador) { |
---|
530 | global $user; |
---|
531 | global $user; |
---|
532 | $breadcrumb[] = l(t('Home'), '<front>'); |
---|
533 | $breadcrumb[] = l(t('Explicación Situacional'), 'planificacion/' . $ente_planificador->nid . '/explicacion'); |
---|
534 | $breadcrumb[] = l(t('Causas CrÃticas'), 'planificacion/' . $ente_planificador->nid . '/explicacion/causas'); |
---|
535 | $texto = t('Relaciones entre causas'); |
---|
536 | $breadcrumb[] = $texto; |
---|
537 | drupal_set_breadcrumb($breadcrumb); |
---|
538 | drupal_set_title($texto); |
---|
539 | $ente = usuario_tiene_ente($user->uid); |
---|
540 | $ente_has_acceso = FALSE; |
---|
541 | $mi_fecha = ente_planificador_user_acceso_proceso('causas_causas', $ente_planificador); |
---|
542 | $current_time = time(); |
---|
543 | $fecha = FALSE; |
---|
544 | if ($mi_fecha[1] + 86399 > $current_time && $mi_fecha[0] < $current_time) { |
---|
545 | $fecha = TRUE; |
---|
546 | } |
---|
547 | if (!$fecha) { |
---|
548 | muestra_mensaje('causas_causas', $ente_planificador); |
---|
549 | } |
---|
550 | else { |
---|
551 | if ($ente->nid == $ente_planificador->nid) { |
---|
552 | muestra_mensaje('causas_causas', $ente_planificador, 0); |
---|
553 | } |
---|
554 | } |
---|
555 | if ($fecha && (user_access('admin planificador') || $ente->nid == $ente_planificador->nid)) { |
---|
556 | $ente_has_acceso = TRUE; |
---|
557 | } |
---|
558 | if ($ente_planificador->tipo > 1) { |
---|
559 | $ente_has_acceso = FALSE; |
---|
560 | if (module_exists('ente_planificador_hierarchical')) { |
---|
561 | if ($ente_planificador->tipo <= variable_get('situacion_actual_preliminar_hierarchical_count', 2)) { |
---|
562 | if (count($ente_planificador->ente_planificador_hierarchical['fathers'])) { |
---|
563 | $ente_has_acceso = TRUE; |
---|
564 | } |
---|
565 | } |
---|
566 | } |
---|
567 | $macro = ente_planificador_ente_macro($ente_planificador); |
---|
568 | if ($macro) { |
---|
569 | $ente_planificador = node_load($macro); |
---|
570 | } |
---|
571 | } |
---|
572 | $form = array(); |
---|
573 | $form['items'] = array( |
---|
574 | '#type' => 'causas_criticas_tapir_table', |
---|
575 | '#tree' => TRUE, |
---|
576 | ); |
---|
577 | $form['#ente_planificador'] = $ente_planificador; |
---|
578 | //Get current causas |
---|
579 | $mi_fecha = ente_planificador_user_acceso_proceso('causas', $ente_planificador); |
---|
580 | $sql_query = "SELECT c.nid FROM {content_type_causas} AS c INNER JOIN {node} AS n ON c.nid = n.nid AND c.vid = n.vid WHERE c.field_ente_planifiador_nid = %d AND n.created >= %d AND n.created <= %d"; |
---|
581 | $sql_query = "SELECT n.nid as nid FROM {content_type_causas} AS c INNER JOIN {node} AS n ON c.nid = n.nid AND c.vid = n.vid WHERE c.field_ente_planifiador_nid = %d AND n.created >= %d AND n.created <= %d"; |
---|
582 | $sql_variables = array(); |
---|
583 | $sql_variables[] = $ente_planificador->nid; |
---|
584 | $sql_variables[] = $mi_fecha[0]; |
---|
585 | $sql_variables[] = $mi_fecha[1] + 86399; |
---|
586 | $result = db_query($sql_query, $sql_variables); |
---|
587 | $causas = array(); |
---|
588 | while($causa = db_fetch_object($result)) { |
---|
589 | $causa_load = node_load($causa->nid); |
---|
590 | if (is_array($causa_load->field_descriptores_causa) && count($causa_load->field_descriptores_causa) && $causa_load->field_descriptores_causa[0]['nid']) { |
---|
591 | $causas[$causa->nid] = $causa_load; |
---|
592 | } |
---|
593 | } |
---|
594 | foreach ($causas as $idy => $itemy) { |
---|
595 | $relacions = array(); |
---|
596 | if (count($itemy->field_causas_relacion)){ |
---|
597 | foreach($itemy->field_causas_relacion as $relacion) { |
---|
598 | $relacions[$relacion['nid']] = 1; |
---|
599 | } |
---|
600 | } |
---|
601 | $element = array(); |
---|
602 | $element['title_nid'] = array( |
---|
603 | '#value' => '<b>' . $itemy->title . '</b>', |
---|
604 | '#cell_attributes' => |
---|
605 | array( |
---|
606 | 'align' => 'center', |
---|
607 | 'class' => 'causa_title' |
---|
608 | ) |
---|
609 | ); |
---|
610 | foreach ($causas as $idx => $itemx) { |
---|
611 | if ($idy == $idx) { |
---|
612 | $element['causa_' . $idx] = array( |
---|
613 | '#value' => '<b>' . '-' . '</b>', |
---|
614 | '#cell_attributes' => array( |
---|
615 | 'align' => 'center', |
---|
616 | 'class' => 'causa' |
---|
617 | ) |
---|
618 | ); |
---|
619 | } |
---|
620 | else { |
---|
621 | if ($ente_has_acceso) { |
---|
622 | $default_value = isset($relacions[$idx]) ? 1 : 0; |
---|
623 | $element['causa_' . $idx] = array( |
---|
624 | '#type' => 'checkbox', |
---|
625 | '#default_value' => $default_value, |
---|
626 | '#cell_attributes' => array( |
---|
627 | 'align' => 'center', |
---|
628 | 'class' => 'causa' |
---|
629 | ) |
---|
630 | ); |
---|
631 | } |
---|
632 | else { |
---|
633 | $default_value = isset($relacions[$idx]) ? t('SI') : t('NO'); |
---|
634 | $element['causa_' . $idx] = array( |
---|
635 | '#value' => '<b>' . $default_value . '</b>', |
---|
636 | '#cell_attributes' => array( |
---|
637 | 'align' => 'center', |
---|
638 | 'class' => 'causa' |
---|
639 | ) |
---|
640 | ); |
---|
641 | } |
---|
642 | } |
---|
643 | } |
---|
644 | $form['items'][$idy] = $element; |
---|
645 | } |
---|
646 | $form['items']['#causas'] = $causas; |
---|
647 | $form['#causas'] = $causas; |
---|
648 | $form['items'] = causas_tapir_get_table('causas_criticas_view_table', $form['items']); |
---|
649 | unset($form['items']['#causas']); |
---|
650 | if ($ente_has_acceso) { |
---|
651 | $form['buttons']['submit'] = array( |
---|
652 | '#type' => 'submit', |
---|
653 | '#value' => t('Submit'), |
---|
654 | '#weight' => 20 |
---|
655 | ); |
---|
656 | $form['buttons']['cancel'] = array( |
---|
657 | '#type' => 'submit', |
---|
658 | '#value' => t('Cancel'), |
---|
659 | '#weight' => 21 |
---|
660 | ); |
---|
661 | } |
---|
662 | return $form; |
---|
663 | } |
---|
664 | |
---|
665 | /* |
---|
666 | * Implementation of causas_criticas_view_form_validate() |
---|
667 | */ |
---|
668 | function causas_criticas_view_form_validate($form, &$form_state) { |
---|
669 | $op = isset($form_state['values']['op']) ? $form_state['values']['op'] : ''; |
---|
670 | $ente_planificador = $form['#ente_planificador']; |
---|
671 | if ($op == t('Cancel')) { |
---|
672 | drupal_goto('planificacion/' . $ente_planificador->nid . '/explicacion/causas'); |
---|
673 | return; |
---|
674 | } |
---|
675 | } |
---|
676 | |
---|
677 | /* |
---|
678 | * Implementation of causas_criticas_view_form_submit() |
---|
679 | */ |
---|
680 | function causas_criticas_view_form_submit($form, &$form_state) { |
---|
681 | $causas = $form['#causas']; |
---|
682 | $causas_values = $form_state['values']['items']; |
---|
683 | $ente_planificador = $form['#ente_planificador']; |
---|
684 | module_load_include('inc', 'content', 'includes/content.node_form'); |
---|
685 | foreach ($causas as $idy => $itemy) { |
---|
686 | $element = array(); |
---|
687 | $itemy->field_causas_relacion = array(); |
---|
688 | $itemy->field_causa_posible = array(); |
---|
689 | $itemy->field_causa_posible[]['value'] = 0; |
---|
690 | $itemy->field_causa_critica = array(); |
---|
691 | $itemy->field_causa_critica[]['value'] = 0; |
---|
692 | foreach ($causas as $idx => $itemx) { |
---|
693 | if ($idx != $idy && $causas_values[$idy]['causa_' . $idx]) { |
---|
694 | $itemy->field_causas_relacion[] = array('nid' => $idx); |
---|
695 | } |
---|
696 | } |
---|
697 | $itemy = node_submit($itemy); |
---|
698 | $itemy->log = t('Modificada la relación entre las causas'); |
---|
699 | $itemy->revision = 1; |
---|
700 | node_save($itemy); |
---|
701 | } |
---|
702 | drupal_set_message(t('Se han agregado las relaciones de las posibles causas crÃticas')); |
---|
703 | drupal_goto('planificacion/' . $ente_planificador->nid . '/explicacion/causas/posibles/posibles'); |
---|
704 | } |
---|
705 | |
---|
706 | /** |
---|
707 | * Load a table element for use in the Forms API or simply drupal_render(). |
---|
708 | * |
---|
709 | * @param $table_id |
---|
710 | * The string identifying the table you want to display, like a form ID. |
---|
711 | * @param ... |
---|
712 | * Any additional arguments will be passed on to the table builder function |
---|
713 | * specified as the $table_id. |
---|
714 | * @return |
---|
715 | * The table form element. |
---|
716 | */ |
---|
717 | function causas_tapir_get_table($table_id) { |
---|
718 | // Get any additional arguments. |
---|
719 | $args = func_get_args(); |
---|
720 | array_shift($args); |
---|
721 | // Retrieve the table data and allow modules to alter it. |
---|
722 | $table = call_user_func_array($table_id, $args); |
---|
723 | array_unshift($args, $table_id); |
---|
724 | $data = &$table; |
---|
725 | // Pass the arguments in the table so that alter functions can use them. |
---|
726 | $data['#parameters'] = $args; |
---|
727 | drupal_alter('tapir_table', $data, $table_id); |
---|
728 | return $table; |
---|
729 | } |
---|
730 | |
---|
731 | /** |
---|
732 | * List the products in the cart in a TAPIr table. |
---|
733 | */ |
---|
734 | function causas_criticas_view_table($table) { |
---|
735 | $table['#attributes'] = array('width' => '100%', 'align' => 'center', 'border' => '1'); |
---|
736 | $causas = $table['#causas']; |
---|
737 | $table['#columns'] = array(); |
---|
738 | $row = array(); |
---|
739 | $row['title_nid'] = array( |
---|
740 | 'cell' => t('Causas'), |
---|
741 | 'weight' => 0, |
---|
742 | 'align' => 'center', |
---|
743 | 'colspan' => '2', |
---|
744 | ); |
---|
745 | foreach ($causas as $idy => $itemy) { |
---|
746 | $row['causa_' . $idy] = array( |
---|
747 | 'cell' => $itemy->title, |
---|
748 | 'weight' => 0, |
---|
749 | ); |
---|
750 | } |
---|
751 | $table['#columns'] = $row; |
---|
752 | return $table; |
---|
753 | } |
---|
754 | /** |
---|
755 | * Implementation of hook_elements(). |
---|
756 | */ |
---|
757 | function causas_criticas_elements() { |
---|
758 | $types = array(); |
---|
759 | $types['causas_criticas_tapir_table'] = array( |
---|
760 | '#columns' => array(), |
---|
761 | '#rows' => array(), |
---|
762 | '#tree' => TRUE, |
---|
763 | '#value' => NULL, |
---|
764 | '#pre_render' => array('causas_criticas_tapir_gather_rows'), |
---|
765 | '#process' => 'form_expand_ahah', |
---|
766 | ); |
---|
767 | return $types; |
---|
768 | } |
---|
769 | |
---|
770 | /** |
---|
771 | * Pre-render callback for tapir_table elements. |
---|
772 | * |
---|
773 | * Gathers children of the tapir_table element into the #rows array. This |
---|
774 | * allows the element to render the children within the table as rows. Non-row |
---|
775 | * children are rendered after the table. |
---|
776 | */ |
---|
777 | function causas_criticas_tapir_gather_rows($element) { |
---|
778 | foreach (element_children($element) as $row) { |
---|
779 | foreach (array_keys($element['#columns']) as $col_id) { |
---|
780 | $element['#rows'][$row][$col_id] = $element[$row][$col_id]; |
---|
781 | unset($element[$row][$col_id]); |
---|
782 | } |
---|
783 | $element['#rows'][$row]['#attributes'] = isset($element[$row]['#attributes']) ? $element[$row]['#attributes'] : array(); |
---|
784 | } |
---|
785 | return $element; |
---|
786 | } |
---|
787 | |
---|
788 | |
---|
789 | |
---|
790 | /** |
---|
791 | * @ingroup themeable |
---|
792 | * @see causas_criticas_view_form() |
---|
793 | */ |
---|
794 | function theme_causas_criticas_view_form($form) { |
---|
795 | $output = '<div id="causas-criticas-form-causas">' . drupal_render($form['items']) .'</div>'; |
---|
796 | $output .= '<div id="causas-criticas-form-buttons">'. drupal_render($form) .'</div>'; |
---|
797 | return $output; |
---|
798 | } |
---|
799 | |
---|
800 | /* |
---|
801 | * Implementation of ente_planificador_view_causas_criticas() |
---|
802 | */ |
---|
803 | function ente_planificador_view_causas_criticas($ente_planificador) { |
---|
804 | global $user; |
---|
805 | $breadcrumb[] = l(t('Home'), '<front>'); |
---|
806 | $breadcrumb[] = l(t('Explicación Situacional'), 'planificacion/' . $ente_planificador->nid . '/explicacion'); |
---|
807 | $texto = t('Causas CrÃticas'); |
---|
808 | $breadcrumb[] = $texto; |
---|
809 | drupal_set_breadcrumb($breadcrumb); |
---|
810 | drupal_set_title($texto); |
---|
811 | $submenu = array(); |
---|
812 | $smenu = array(); |
---|
813 | $i = 0; |
---|
814 | $submenu[$i] = array( |
---|
815 | 'name'=> t("Posibles Causas CrÃticas"), |
---|
816 | 'description' => t("Gestiona las posibles causas crÃticas"), |
---|
817 | 'call' => "explicacion_causas_criticas" |
---|
818 | ); |
---|
819 | $aux_menu = array(); |
---|
820 | foreach (module_list() as $module) { |
---|
821 | if ($data = module_invoke($module, 'items_menu_situacion_' . $submenu[$i]['call'], $ente_planificador)) { |
---|
822 | $aux_menu = array_merge_recursive($data, $aux_menu); |
---|
823 | } |
---|
824 | } |
---|
825 | $smenu[$i] = $aux_menu; |
---|
826 | if (!isset($i)) { |
---|
827 | $i = -1; |
---|
828 | } |
---|
829 | $i++; |
---|
830 | $submenu[$i] = array( |
---|
831 | 'name'=> t("Causas CrÃticas"), |
---|
832 | 'description' => t("Lista las causas crÃticas"), |
---|
833 | 'call' => "explicacion_causas" |
---|
834 | ); |
---|
835 | $aux_menu = array(); |
---|
836 | foreach (module_list() as $module) { |
---|
837 | if ($data = module_invoke($module, 'items_menu_situacion_' . $submenu[$i]['call'], $ente_planificador)) { |
---|
838 | $aux_menu = array_merge_recursive($data, $aux_menu); |
---|
839 | } |
---|
840 | } |
---|
841 | $smenu[$i] = $aux_menu; |
---|
842 | return theme('planificacion_submenu_interfaz', $submenu, $smenu); |
---|
843 | } |
---|
844 | |
---|
845 | /* |
---|
846 | * Implementation of hook_items_menu_planificacion_explicacion_situacional() |
---|
847 | * Add menus items in explicación Situacional |
---|
848 | */ |
---|
849 | function causas_criticas_items_menu_situacion_explicacion_causas_criticas($ente_planificador) { |
---|
850 | $resultado = array(); |
---|
851 | $resultado[] = array( |
---|
852 | 'name' => t('Relaciones entre Causas'), |
---|
853 | 'path' => 'planificacion/' . $ente_planificador->nid . '/explicacion/causas/relaciones', |
---|
854 | 'description' => t('Relaciones entre Causas CrÃticas') |
---|
855 | ); |
---|
856 | $children = FALSE; |
---|
857 | if (module_exists('ente_planificador_hierarchical')) { |
---|
858 | if ($ente_planificador->tipo <= variable_get('situacion_actual_preliminar_hierarchical_count', 2)) { |
---|
859 | if (count($ente_planificador->ente_planificador_hierarchical['fathers'])) { |
---|
860 | $children = TRUE; |
---|
861 | } |
---|
862 | } |
---|
863 | } |
---|
864 | if ($ente_planificador->tipo == 1 || $children) { |
---|
865 | $resultado[] = array( |
---|
866 | 'name' => t('Seleccionar Posibles Causas CrÃticas'), |
---|
867 | 'path' => 'planificacion/' . $ente_planificador->nid . '/explicacion/causas/posibles', |
---|
868 | 'description' => t('Seleccionar Posibles Causas CrÃticas') |
---|
869 | ); |
---|
870 | $resultado[] = array( |
---|
871 | 'name' => t('Posibles Causas CrÃticas'), |
---|
872 | 'path' => 'planificacion/' . $ente_planificador->nid . '/explicacion/causas/posibles/view', |
---|
873 | 'description' => t('Posibles Causas CrÃticas') |
---|
874 | ); |
---|
875 | } |
---|
876 | return $resultado; |
---|
877 | } |
---|
878 | |
---|
879 | /* |
---|
880 | * Implementation of hook_items_menu_planificacion_explicacion_situacional() |
---|
881 | * Add menus items in explicación Situacional |
---|
882 | */ |
---|
883 | function causas_criticas_items_menu_situacion_explicacion_causas($ente_planificador) { |
---|
884 | $resultado = array(); |
---|
885 | $children = FALSE; |
---|
886 | if (module_exists('ente_planificador_hierarchical')) { |
---|
887 | if ($ente_planificador->tipo <= variable_get('situacion_actual_preliminar_hierarchical_count', 2)) { |
---|
888 | if (count($ente_planificador->ente_planificador_hierarchical['fathers'])) { |
---|
889 | $children = TRUE; |
---|
890 | } |
---|
891 | } |
---|
892 | } |
---|
893 | if ($ente_planificador->tipo == 1 || $children) { |
---|
894 | $resultado[] = array( |
---|
895 | 'name' => t('Seleccionar Causas CrÃticas'), |
---|
896 | 'path' => 'planificacion/' . $ente_planificador->nid . '/explicacion/causas/select', |
---|
897 | 'description' => t('Seleccionar Causas CrÃticas') |
---|
898 | ); |
---|
899 | } |
---|
900 | $resultado[] = array( |
---|
901 | 'name' => t('Consultar Causas CrÃticas'), |
---|
902 | 'path' => 'planificacion/' . $ente_planificador->nid . '/explicacion/causas/description', |
---|
903 | 'description' => t('Muestra las Causas CrÃticas') |
---|
904 | ); |
---|
905 | return $resultado; |
---|
906 | } |
---|
907 | |
---|
908 | function causas_criticas_obtiene_algoritmo(){ |
---|
909 | $algoritmo = module_invoke_all('algoritmo'); |
---|
910 | return $algoritmo; |
---|
911 | } |
---|
912 | |
---|
913 | function causas_criticas_algoritmo() { |
---|
914 | return array('cc' => t('Causa Critica')); |
---|
915 | } |
---|
916 | |
---|
917 | /* |
---|
918 | * Implementation of causas_criticas_posibles_view_form() |
---|
919 | */ |
---|
920 | function causas_criticas_posibles_view_form($form_state, $ente_planificador) { |
---|
921 | global $user; |
---|
922 | $breadcrumb[] = l(t('Home'), '<front>'); |
---|
923 | $breadcrumb[] = l(t('Explicación Situacional'), 'planificacion/' . $ente_planificador->nid . '/explicacion'); |
---|
924 | $breadcrumb[] = l(t('Causas CrÃticas'), 'planificacion/' . $ente_planificador->nid . '/explicacion/causas'); |
---|
925 | $texto = t('Seleccionar Posibles Causas CrÃticas'); |
---|
926 | $breadcrumb[] = $texto; |
---|
927 | drupal_set_breadcrumb($breadcrumb); |
---|
928 | drupal_set_title($texto); |
---|
929 | $mi_fecha = ente_planificador_user_acceso_proceso("causas_criticas", $ente_planificador); |
---|
930 | $current_time = time(); |
---|
931 | $fecha = FALSE; |
---|
932 | if ($mi_fecha[1] + 86399 > $current_time && $mi_fecha[0] < $current_time) { |
---|
933 | $fecha = TRUE; |
---|
934 | } |
---|
935 | if (!$fecha) { |
---|
936 | muestra_mensaje("causas_criticas", $ente_planificador); |
---|
937 | } |
---|
938 | else { |
---|
939 | $ente = usuario_tiene_ente($user->uid); |
---|
940 | if (user_access('admin all planificador') || $ente->nid == $ente_planificador->nid) { |
---|
941 | muestra_mensaje("causas_criticas", $ente_planificador, 0); |
---|
942 | $ente_has_acceso = TRUE; |
---|
943 | } |
---|
944 | } |
---|
945 | $year = variable_get('situacional_actual_preliminar_anho_creacion', 0); |
---|
946 | $tipo_plan = CAUSA_CRITICA_PLAN; |
---|
947 | $planns = _situacion_actual_preliminar_get_planns(); |
---|
948 | $plan = $planns[$tipo_plan]; |
---|
949 | $descriptores = _get_situacion_actual_listar_all_descriptores($ente_planificador->nid, $plan, $year); |
---|
950 | $acceso = TRUE; |
---|
951 | $derivadas = _get_causas_derivadas($ente_planificador->nid, $plan, $year); |
---|
952 | $headers_table = array(); |
---|
953 | $headers_table[] = array('data' => t('Descriptores')); |
---|
954 | $headers_table[] = array('data' => t('Causas Productoras')); |
---|
955 | $headers_table[] = array('data' => t('Causas Derivadas')); |
---|
956 | $rows = array(); |
---|
957 | $causas_to_load = array(); |
---|
958 | foreach($descriptores as $descriptor) { |
---|
959 | $row = array(); |
---|
960 | $cuenta_causa = count($descriptor['causas']); |
---|
961 | $row[] = array('data' => $descriptor['body'], 'rowspan' => $cuenta_causa); |
---|
962 | foreach ($descriptor['causas'] as $causa) { |
---|
963 | $causas_to_load[$causa['nid']] = $causa; |
---|
964 | $row[] = array('data' => $causa['body'],); |
---|
965 | $causas = array(); |
---|
966 | if (isset($derivadas[$descriptor['nid']][$causa['nid']]) && count($derivadas[$descriptor['nid']][$causa['nid']])) { |
---|
967 | foreach($derivadas[$descriptor['nid']][$causa['nid']] as $id => $causa_d){ |
---|
968 | if (isset($descriptor['causas'][$id])) { |
---|
969 | $causas[$id] = $descriptor['causas'][$id]['body']; |
---|
970 | } |
---|
971 | |
---|
972 | } |
---|
973 | } |
---|
974 | $lista = count($causas)? theme('item_list', $causas) : t('No existen causas derivadas.'); |
---|
975 | $row[] = array('data' => $lista); |
---|
976 | $rows[] = $row; |
---|
977 | $row = array(); |
---|
978 | } |
---|
979 | } |
---|
980 | if (!count($rows)) { |
---|
981 | $row = array(); |
---|
982 | $row[] = array('data' => t('No se encontrarón descriptores para este ente'), 'colspan' => count($headers_table)); |
---|
983 | $rows[] = $row; |
---|
984 | } |
---|
985 | $html = theme('table', $headers_table, $rows); |
---|
986 | $form['muestra_causas']['#value'] = $html; |
---|
987 | $form['#descriptores'] = $descriptores; |
---|
988 | $form['#derivadas'] = $derivadas; |
---|
989 | $form['#causas_to_load'] = $causas_to_load; |
---|
990 | $form['#ente_planificador'] = $ente_planificador; |
---|
991 | $options = causas_criticas_obtiene_algoritmo(); |
---|
992 | $form['algoritm'] = array( |
---|
993 | '#prefix' => t('@cantidad causas encontradas', array('@cantidad' => count($form['#causas_to_load']))), |
---|
994 | '#type' => 'select', |
---|
995 | '#default_value' => 'cc', |
---|
996 | '#options' => $options, |
---|
997 | '#title' => t('Seleccione el algoritmo que desee utilizar para seleccionar las posibles causas crÃticas'), |
---|
998 | ); |
---|
999 | if ($ente_has_acceso) { |
---|
1000 | $form['buttons']['submit'] = array( |
---|
1001 | '#type' => 'submit', |
---|
1002 | '#value' => t('Calcular'), |
---|
1003 | '#weight' => 20 |
---|
1004 | ); |
---|
1005 | $form['buttons']['cancel'] = array( |
---|
1006 | '#type' => 'submit', |
---|
1007 | '#value' => t('Cancel'), |
---|
1008 | '#weight' => 21 |
---|
1009 | ); |
---|
1010 | } |
---|
1011 | return $form; |
---|
1012 | } |
---|
1013 | |
---|
1014 | /* |
---|
1015 | * Implementation of causas_criticas_posibles_view_form_submit() |
---|
1016 | */ |
---|
1017 | function causas_criticas_posibles_view_form_submit($form, &$form_state) { |
---|
1018 | if (!$_REQUEST['destination']) { |
---|
1019 | // add redirect |
---|
1020 | $form_state['redirect'] = 'planificacion/' . $form['#ente_planificador']->nid . '/explicacion/causas/posibles/view'; |
---|
1021 | } |
---|
1022 | $op = isset($form_state['values']['op']) ? $form_state['values']['op'] : ''; |
---|
1023 | if ($op == t('Cancel')) { |
---|
1024 | return; |
---|
1025 | } |
---|
1026 | |
---|
1027 | |
---|
1028 | $causas = $form['#causas']; |
---|
1029 | if (function_exists('causas_criticas_posibles_algoritm_' . $form_state['values']['algoritm'])) { |
---|
1030 | module_load_include('inc', 'node', 'node.pages'); |
---|
1031 | $causas_arg = array(); |
---|
1032 | $causas_arg[] = array( |
---|
1033 | 'descriptores' => $form['#descriptores'], |
---|
1034 | 'derivadas' => $form['#derivadas'], |
---|
1035 | ); |
---|
1036 | $causa_to_descriptor = array(); |
---|
1037 | $causas_criticas = call_user_func_array('causas_criticas_posibles_algoritm_' . $form_state['values']['algoritm'], $causas_arg); |
---|
1038 | foreach($form['#descriptores'] as $nid => $descriptores) { |
---|
1039 | $posibles = array(); |
---|
1040 | foreach ($causas_criticas[$nid] as $cnid => $valor) { |
---|
1041 | $posibles[]['nid'] = $cnid; |
---|
1042 | $causa_to_descriptor[$cnid][]['nid'] = $nid; |
---|
1043 | } |
---|
1044 | $node = node_load($nid); |
---|
1045 | if ($node->nid) { |
---|
1046 | $node->field_descriptores_posibles = $posibles; |
---|
1047 | $node->field_descriptores_criticas = array(); |
---|
1048 | node_object_prepare($node); |
---|
1049 | $node->log = t('Causas seleccionada como posible por el algoritmo @algoritmo', array('@algoritmo' => $form_state['values']['algoritm'])); |
---|
1050 | $node->revision = 1; |
---|
1051 | node_save($node); |
---|
1052 | } |
---|
1053 | } |
---|
1054 | foreach($form['#causas_to_load'] as $nid => $value) { |
---|
1055 | $node = node_load($nid); |
---|
1056 | if ($node->nid) { |
---|
1057 | $node->field_causa_posible = array(); |
---|
1058 | $cuenta = count($causa_to_descriptor[$node->nid]) ? 1 : 0; |
---|
1059 | $node->field_causa_posible[]['value'] = (string) $cuenta; |
---|
1060 | $node->field_causas_posibles = $cuenta ? $causa_to_descriptor[$node->nid] : array(); |
---|
1061 | $node->field_causa_critica = array(); |
---|
1062 | $node->field_causa_critica[]['value'] = 0; |
---|
1063 | $node->field_causas_criticos = array(); |
---|
1064 | node_object_prepare($node); |
---|
1065 | if ($valor) { |
---|
1066 | $node->log = t('Causa seleccionada como posible por el algoritmo @algoritmo', array('@algoritmo' => $form_state['values']['algoritm'])); |
---|
1067 | } |
---|
1068 | $node->revision = 1; |
---|
1069 | node_save($node); |
---|
1070 | } |
---|
1071 | } |
---|
1072 | } |
---|
1073 | drupal_set_message(t('Se han seleccionado las posibles causas crÃticas con el algoritmo')); |
---|
1074 | } |
---|
1075 | |
---|
1076 | /* |
---|
1077 | * Implementation of causas_criticas_posibles_algoritm_cc() |
---|
1078 | */ |
---|
1079 | function causas_criticas_posibles_algoritm_cc($causas = array()) { |
---|
1080 | $descriptores = $causas['descriptores']; |
---|
1081 | $derivadas = $causas['derivadas']; |
---|
1082 | $causas_criticas = array(); |
---|
1083 | foreach($descriptores as $descriptor) { |
---|
1084 | $sum = array(); |
---|
1085 | $sumy = array(); |
---|
1086 | foreach ($descriptor['causas'] as $causa) { |
---|
1087 | $causas = array(); |
---|
1088 | if (isset($derivadas[$descriptor['nid']][$causa['nid']]) && count($derivadas[$descriptor['nid']][$causa['nid']])) { |
---|
1089 | foreach($derivadas[$descriptor['nid']][$causa['nid']] as $id => $causa_d){ |
---|
1090 | if (isset($descriptor['causas'][$id])) { |
---|
1091 | $sum[$causa['nid']]++; |
---|
1092 | $sumy[$id]++; |
---|
1093 | } |
---|
1094 | } |
---|
1095 | } |
---|
1096 | } |
---|
1097 | $cuenta_causa = count($descriptor['causas']); |
---|
1098 | if ($cuenta_causa){ |
---|
1099 | $avg = array_sum($sum)/$cuenta_causa; |
---|
1100 | $avgy = array_sum($sumy)/$cuenta_causa; |
---|
1101 | foreach ($descriptor['causas'] as $causa) { |
---|
1102 | if ($sum[$causa['nid']] >= $avg && $sumy[$causa['nid']] <= $avg) { |
---|
1103 | $causas_criticas[$descriptor['nid']][$causa['nid']] = 1; |
---|
1104 | } |
---|
1105 | elseif($sum[$causa['nid']] >= 0 && $sumy[$causa['nid']] == 0) { |
---|
1106 | $causas_criticas[$descriptor['nid']][$causa['nid']] = 1; |
---|
1107 | } |
---|
1108 | } |
---|
1109 | } |
---|
1110 | } |
---|
1111 | return $causas_criticas; |
---|
1112 | } |
---|
1113 | |
---|
1114 | /* |
---|
1115 | * Implementation of _get_causas_all_causas() |
---|
1116 | * Obtiene las causas derivadas por tipo de plan |
---|
1117 | */ |
---|
1118 | function _get_causas_all_causas($ente_planificador = 0, $tipo_plan = array(), $year = 0, $tipo = 'posibles'){ |
---|
1119 | $tabla = ($tipo == 'posibles')? 'content_field_descriptores_posibles' : 'content_field_descriptores_criticas'; |
---|
1120 | $campo = 'field_descriptores_' . $tipo . '_nid'; |
---|
1121 | $sql = "SELECT d.*, ds." . $campo . " AS causa FROM {" . $tabla . "} AS ds INNER JOIN {content_type_descriptores} AS d ON d.nid = ds.nid AND d.vid = ds.vid INNER JOIN {node} AS n ON n.nid = ds.nid AND n.vid = ds.vid WHERE d.field_descriptores_planificador_nid = %d AND d.field_descriptores_year_value = %d"; |
---|
1122 | |
---|
1123 | $inputs = array(); |
---|
1124 | $inputs[] = $ente_planificador; |
---|
1125 | $inputs[] = $year; |
---|
1126 | if ($tipo_plan['short']) { |
---|
1127 | $sql .= ' AND d.field_descriptores_' . $tipo_plan['short'] . '_value = %d'; |
---|
1128 | $inputs[] = 1; |
---|
1129 | } |
---|
1130 | $result = db_query($sql, $inputs); |
---|
1131 | $descriptores = array(); |
---|
1132 | while($descriptor = db_fetch_object($result)) { |
---|
1133 | if ($descriptor->nid && $descriptor->causa) { |
---|
1134 | $descriptores[$descriptor->nid][$descriptor->causa] = $descriptor->causa; |
---|
1135 | } |
---|
1136 | } |
---|
1137 | return $descriptores; |
---|
1138 | } |
---|
1139 | |
---|
1140 | /* |
---|
1141 | * Implementation of ente_planificador_view_causas_relaciones_posibles_view() |
---|
1142 | */ |
---|
1143 | function ente_planificador_view_causas_relaciones_posibles_view($ente_planificador) { |
---|
1144 | global $user; |
---|
1145 | $breadcrumb[] = l(t('Home'), '<front>'); |
---|
1146 | $breadcrumb[] = l(t('Explicación Situacional'), 'planificacion/' . $ente_planificador->nid . '/explicacion'); |
---|
1147 | $breadcrumb[] = l(t('Causas CrÃticas'), 'planificacion/' . $ente_planificador->nid . '/explicacion/causas'); |
---|
1148 | $texto = t('Posibles Causas CrÃticas'); |
---|
1149 | $breadcrumb[] = $texto; |
---|
1150 | drupal_set_breadcrumb($breadcrumb); |
---|
1151 | drupal_set_title($texto); |
---|
1152 | $mi_fecha = ente_planificador_user_acceso_proceso("causas_criticas", $ente_planificador); |
---|
1153 | $current_time = time(); |
---|
1154 | $fecha = FALSE; |
---|
1155 | if ($mi_fecha[1] + 86399 > $current_time && $mi_fecha[0] < $current_time) { |
---|
1156 | $fecha = TRUE; |
---|
1157 | } |
---|
1158 | if (!$fecha) { |
---|
1159 | muestra_mensaje("causas_criticas", $ente_planificador); |
---|
1160 | } |
---|
1161 | else { |
---|
1162 | $ente = usuario_tiene_ente($user->uid); |
---|
1163 | if (user_access('admin all planificador') || $ente->nid == $ente_planificador->nid) { |
---|
1164 | muestra_mensaje("causas_criticas", $ente_planificador, 0); |
---|
1165 | } |
---|
1166 | } |
---|
1167 | $year = variable_get('situacional_actual_preliminar_anho_creacion', 0); |
---|
1168 | $tipo_plan = CAUSA_CRITICA_PLAN; |
---|
1169 | $planns = _situacion_actual_preliminar_get_planns(); |
---|
1170 | $plan = $planns[$tipo_plan]; |
---|
1171 | $descriptores = _get_situacion_actual_listar_all_descriptores($ente_planificador->nid, $plan, $year); |
---|
1172 | $posibles = _get_causas_all_causas($ente_planificador->nid, $plan, $year); |
---|
1173 | drupal_set_title(t('Posibles Causas CrÃticas')); |
---|
1174 | $headers_table = array(); |
---|
1175 | $headers_table[] = array('data' => t('Descriptor')); |
---|
1176 | $headers_table[] = array('data' => t('Causas')); |
---|
1177 | $headers_table[] = array('data' => t('Posibles Causas CrÃtica')); |
---|
1178 | $rows = array(); |
---|
1179 | foreach($descriptores as $descriptor) { |
---|
1180 | $row = array(); |
---|
1181 | $row[] = array('data' => $descriptor['body'],); |
---|
1182 | $criticas = array(); |
---|
1183 | $causas = array(); |
---|
1184 | foreach ($descriptor['causas'] as $causa) { |
---|
1185 | $causas[$causa['nid']] = $causa['body']; |
---|
1186 | if (isset($posibles[$descriptor['nid']][$causa['nid']])) { |
---|
1187 | $criticas[$causa['nid']] = $causa['body']; |
---|
1188 | } |
---|
1189 | } |
---|
1190 | $row[] = array('data' => theme('item_list', $causas)); |
---|
1191 | $row[] = array('data' => theme('item_list', $criticas)); |
---|
1192 | $rows[] = $row; |
---|
1193 | } |
---|
1194 | if (!count($rows)) { |
---|
1195 | $row = array(); |
---|
1196 | $row[] = array('data' => t('No se encontrarón descriptores para este ente'), 'colspan' => count($headers_table)); |
---|
1197 | $rows[] = $row; |
---|
1198 | } |
---|
1199 | return theme('table', $headers_table, $rows); |
---|
1200 | } |
---|
1201 | |
---|
1202 | /* |
---|
1203 | * Implementation of causas_criticas_select_causas_form() |
---|
1204 | */ |
---|
1205 | function causas_criticas_select_causas_form($form_state, $ente_planificador) { |
---|
1206 | global $user; |
---|
1207 | $breadcrumb[] = l(t('Home'), '<front>'); |
---|
1208 | $breadcrumb[] = l(t('Explicación Situacional'), 'planificacion/' . $ente_planificador->nid . '/explicacion'); |
---|
1209 | $breadcrumb[] = l(t('Causas CrÃticas'), 'planificacion/' . $ente_planificador->nid . '/explicacion/causas'); |
---|
1210 | $texto = t('Seleccionar Causas CrÃticas'); |
---|
1211 | $breadcrumb[] = $texto; |
---|
1212 | drupal_set_breadcrumb($breadcrumb); |
---|
1213 | drupal_set_title($texto); |
---|
1214 | $mi_fecha = ente_planificador_user_acceso_proceso("causas_criticas", $ente_planificador); |
---|
1215 | $current_time = time(); |
---|
1216 | $fecha = FALSE; |
---|
1217 | if ($mi_fecha[1] + 86399 > $current_time && $mi_fecha[0] < $current_time) { |
---|
1218 | $fecha = TRUE; |
---|
1219 | } |
---|
1220 | if (!$fecha) { |
---|
1221 | muestra_mensaje("causas_criticas", $ente_planificador); |
---|
1222 | } |
---|
1223 | else { |
---|
1224 | $ente = usuario_tiene_ente($user->uid); |
---|
1225 | if (user_access('admin all planificador') || $ente->nid == $ente_planificador->nid) { |
---|
1226 | muestra_mensaje("causas_criticas", $ente_planificador, 0); |
---|
1227 | $ente_has_acceso = TRUE; |
---|
1228 | } |
---|
1229 | } |
---|
1230 | $year = variable_get('situacional_actual_preliminar_anho_creacion', 0); |
---|
1231 | $tipo_plan = CAUSA_CRITICA_PLAN; |
---|
1232 | $planns = _situacion_actual_preliminar_get_planns(); |
---|
1233 | $plan = $planns[$tipo_plan]; |
---|
1234 | $descriptores = _get_situacion_actual_listar_all_descriptores($ente_planificador->nid, $plan, $year); |
---|
1235 | $posibles = _get_causas_all_causas($ente_planificador->nid, $plan, $year); |
---|
1236 | $seleccionadas = _get_causas_all_causas($ente_planificador->nid, $plan, $year, 'criticas'); |
---|
1237 | $header = array(); |
---|
1238 | $header[] = t('Descriptores'); |
---|
1239 | $header[] = t('Causa'); |
---|
1240 | $header[] = t('Posibles Causas Critica Seleccionadas por el Sistema'); |
---|
1241 | $header[] = t('Seleccionar Causas Criticas'); |
---|
1242 | $prefijo = '<table width="100%" style="border: 0;"><tr>'; |
---|
1243 | foreach($header as $texto) { |
---|
1244 | $prefijo .= '<th>' . $texto . ' </th>'; |
---|
1245 | } |
---|
1246 | $c_criticas = array(); |
---|
1247 | $c_posibles = array(); |
---|
1248 | $causas = array(); |
---|
1249 | $causas = array(); |
---|
1250 | $causas_load = array(); |
---|
1251 | $prefijo .= '</tr>'; |
---|
1252 | $form = array(); |
---|
1253 | if (!count($descriptores)) { |
---|
1254 | $prefijo .= '<tr><td colspan="' . count($header) . '">' . t('No se han ingresado Descriptores') . ' </td></tr></table>'; |
---|
1255 | $form['seleccionar'] = array( |
---|
1256 | '#value' => $prefijo, |
---|
1257 | ); |
---|
1258 | } |
---|
1259 | else { |
---|
1260 | foreach($descriptores as $descriptor) { |
---|
1261 | foreach ($descriptor['causas'] as $causa) { |
---|
1262 | $causas[$descriptor['nid']][$causa['nid']] = $causa['body']; |
---|
1263 | $causas_load[$causa['nid']] = $causa['body']; |
---|
1264 | if (isset($posibles[$descriptor['nid']][$causa['nid']])) { |
---|
1265 | $c_posibles[$descriptor['nid']][$causa['nid']] = $causa['body']; |
---|
1266 | } |
---|
1267 | if (isset($seleccionadas[$descriptor['nid']][$causa['nid']])) { |
---|
1268 | $c_criticas[$descriptor['nid']][$causa['nid']] = $causa['nid']; |
---|
1269 | } |
---|
1270 | } |
---|
1271 | $prefijo .= '<tr><td>' . $descriptor['body'] . '</td><td>' . theme('item_list', $causas[$descriptor['nid']]) . '</td><td>' . theme('item_list', $c_posibles[$descriptor['nid']]) . ' </td>'; |
---|
1272 | $form['seleccionar_' . $descriptor['nid']] = array( |
---|
1273 | '#type' => 'checkboxes', |
---|
1274 | '#title' => '', |
---|
1275 | '#options' => $causas[$descriptor['nid']], |
---|
1276 | '#default_value' => $c_criticas[$descriptor['nid']], |
---|
1277 | '#prefix' => $prefijo . '<td>', |
---|
1278 | '#suffix' => '</td></tr>', |
---|
1279 | '#multiple' => TRUE, |
---|
1280 | ); |
---|
1281 | $prefijo = ''; |
---|
1282 | } |
---|
1283 | $form['seleccionar_' . $descriptor['nid']]['#suffix'] .= '</table>'; |
---|
1284 | } |
---|
1285 | $form['#descriptores'] = $descriptores; |
---|
1286 | $form['#causas'] = $causas; |
---|
1287 | $form['#posibles'] = $posibles; |
---|
1288 | $form['#criticas'] = $criticas; |
---|
1289 | $form['#ente_planificador'] = $ente_planificador; |
---|
1290 | $form['#causas_load'] = $causas_load; |
---|
1291 | if (count($descriptores) && $ente_has_acceso){ |
---|
1292 | $form['buttons']['submit'] = array( |
---|
1293 | '#type' => 'submit', |
---|
1294 | '#value' => t('Seleccionar'), |
---|
1295 | '#weight' => 20 |
---|
1296 | ); |
---|
1297 | $form['buttons']['cancel'] = array( |
---|
1298 | '#type' => 'submit', |
---|
1299 | '#value' => t('Cancel'), |
---|
1300 | '#weight' => 21 |
---|
1301 | ); |
---|
1302 | } |
---|
1303 | return $form; |
---|
1304 | } |
---|
1305 | |
---|
1306 | /* |
---|
1307 | * Implementation of causas_criticas_select_causas_form_submit() |
---|
1308 | */ |
---|
1309 | function causas_criticas_select_causas_form_submit($form, &$form_state) { |
---|
1310 | if (!$_REQUEST['destination']) { |
---|
1311 | // add redirect |
---|
1312 | $form_state['redirect'] = 'planificacion/' . $form['#ente_planificador']->nid . '/explicacion/causas/description'; |
---|
1313 | } |
---|
1314 | $op = isset($form_state['values']['op']) ? $form_state['values']['op'] : ''; |
---|
1315 | if ($op == t('Cancel')) { |
---|
1316 | return; |
---|
1317 | } |
---|
1318 | $ente_planificador = $form['#ente_planificador']; |
---|
1319 | $causas_values = $form_state['values']; |
---|
1320 | module_load_include('inc', 'node', 'node.pages'); |
---|
1321 | $causa_to_descriptor = array(); |
---|
1322 | foreach($form['#descriptores'] as $nid => $descriptor) { |
---|
1323 | $criticas = array(); |
---|
1324 | foreach ($form['#causas'][$nid] as $cnid => $causa) { |
---|
1325 | if (isset($form_state['values']['seleccionar_' . $nid][$cnid]) && $form_state['values']['seleccionar_' . $nid][$cnid]) { |
---|
1326 | $criticas[]['nid'] = $cnid; |
---|
1327 | $causa_to_descriptor[$cnid][]['nid'] = $nid; |
---|
1328 | } |
---|
1329 | } |
---|
1330 | $node = node_load($nid); |
---|
1331 | if ($node->nid) { |
---|
1332 | $node->field_descriptores_criticas = $criticas; |
---|
1333 | node_object_prepare($node); |
---|
1334 | $node->log = t('Causas seleccionadas como criticas'); |
---|
1335 | $node->revision = 1; |
---|
1336 | node_save($node); |
---|
1337 | } |
---|
1338 | } |
---|
1339 | foreach($form['#causas_load'] as $nid => $value) { |
---|
1340 | $node = node_load($nid); |
---|
1341 | if ($node->nid) { |
---|
1342 | $node->field_causa_critica = array(); |
---|
1343 | $cuenta = count($causa_to_descriptor[$node->nid]) ? 1 : 0; |
---|
1344 | $node->field_causa_critica[]['value'] = (string) $cuenta; |
---|
1345 | $node->field_causas_criticos = $cuenta ? $causa_to_descriptor[$node->nid] : array(); |
---|
1346 | node_object_prepare($node); |
---|
1347 | $node->log = t('Causa seleccionada como critica'); |
---|
1348 | $node->revision = 1; |
---|
1349 | node_save($node); |
---|
1350 | } |
---|
1351 | } |
---|
1352 | drupal_set_message(t('Se han seleccionado las causas crÃticas')); |
---|
1353 | } |
---|
1354 | |
---|
1355 | function ente_planificador_view_situacion_objetivo($ente_planificador, $tipo = 'situacion_objetivo') { |
---|
1356 | global $user; |
---|
1357 | $breadcrumb[] = l(t('Home'), '<front>'); |
---|
1358 | $breadcrumb[] = l(t('Explicación Situacional'), 'planificacion/' . $ente_planificador->nid . '/explicacion'); |
---|
1359 | $texto = t('Situación Objetivo'); |
---|
1360 | $breadcrumb[] = $texto; |
---|
1361 | drupal_set_breadcrumb($breadcrumb); |
---|
1362 | drupal_set_title($texto); |
---|
1363 | $ente = usuario_tiene_ente($user->uid); |
---|
1364 | $ente_has_acceso = FALSE; |
---|
1365 | $mi_fecha = ente_planificador_user_acceso_proceso('causas_criticas', $ente_planificador); |
---|
1366 | $current_time = time(); |
---|
1367 | $fecha = FALSE; |
---|
1368 | if ($mi_fecha[1] + 86399 > $current_time && $mi_fecha[0] < $current_time) { |
---|
1369 | $fecha = TRUE; |
---|
1370 | } |
---|
1371 | if (!$fecha) { |
---|
1372 | muestra_mensaje('causas_criticas', $ente_planificador); |
---|
1373 | } |
---|
1374 | else { |
---|
1375 | if ($ente->nid == $ente_planificador->nid) { |
---|
1376 | muestra_mensaje('causas_criticas', $ente_planificador, 0); |
---|
1377 | } |
---|
1378 | } |
---|
1379 | if ($fecha && (user_access('admin planificador') || $ente->nid == $ente_planificador->nid)) { |
---|
1380 | $ente_has_acceso = TRUE; |
---|
1381 | } |
---|
1382 | if ($ente_planificador->tipo > 1) { |
---|
1383 | $ente_has_acceso = FALSE; |
---|
1384 | if (module_exists('ente_planificador_hierarchical')) { |
---|
1385 | if ($ente_planificador->tipo <= variable_get('situacion_actual_preliminar_hierarchical_count', 2)) { |
---|
1386 | if (count($ente_planificador->ente_planificador_hierarchical['fathers'])) { |
---|
1387 | $ente_has_acceso = TRUE; |
---|
1388 | } |
---|
1389 | } |
---|
1390 | } |
---|
1391 | $macro = ente_planificador_ente_macro($ente_planificador); |
---|
1392 | if ($macro) { |
---|
1393 | $ente_planificador = node_load($macro); |
---|
1394 | } |
---|
1395 | } |
---|
1396 | $tipos = array( |
---|
1397 | 'situacion_objetivo' => t('Situación Objetivo'), |
---|
1398 | ); |
---|
1399 | |
---|
1400 | if ($view_id = variable_get('situacion_actual_preliminar_' . $tipo . '_' . $tipo, 0)) { |
---|
1401 | $view = views_get_view($view_id); |
---|
1402 | $display_id = variable_get('situacion_actual_preliminar_display_views_' . $tipo . '_' . $tipo, 'default'); |
---|
1403 | $view->set_display($display_id); |
---|
1404 | |
---|
1405 | $title = $tipos[$tipo]; |
---|
1406 | |
---|
1407 | $view->override_path = $_GET['q']; |
---|
1408 | $view->pre_execute(); |
---|
1409 | $view->execute(); |
---|
1410 | $output = $view->render(); |
---|
1411 | } |
---|
1412 | else { |
---|
1413 | $output = t("No se ha realizado la configuración de la vista Para este tipo de proceso") . '. ' . l(t("Configurar"), 'admin/settings/ente_planificador/explicacion'); |
---|
1414 | } |
---|
1415 | $url = $_REQUEST['destination'] ? $_REQUEST['destination'] : 'planificacion/' . $ente_planificador->nid . '/explicacion/' . $tipo; |
---|
1416 | $links = array(); |
---|
1417 | $links[] = l(t('Regresar'), $url); |
---|
1418 | return $output . theme('item_list', $links); |
---|
1419 | } |
---|
1420 | |
---|
1421 | /* |
---|
1422 | * Implementation of ente_planificador_view_causas_criticas_description() |
---|
1423 | */ |
---|
1424 | function ente_planificador_view_causas_criticas_description($ente_planificador) { |
---|
1425 | global $user; |
---|
1426 | $breadcrumb[] = l(t('Home'), '<front>'); |
---|
1427 | $breadcrumb[] = l(t('Explicación Situacional'), 'planificacion/' . $ente_planificador->nid . '/explicacion'); |
---|
1428 | $breadcrumb[] = l(t('Causas CrÃticas'), 'planificacion/' . $ente_planificador->nid . '/explicacion/causas'); |
---|
1429 | $texto = t('Consultar Causas CrÃticas'); |
---|
1430 | $breadcrumb[] = $texto; |
---|
1431 | drupal_set_breadcrumb($breadcrumb); |
---|
1432 | drupal_set_title($texto); |
---|
1433 | $mi_fecha = ente_planificador_user_acceso_proceso("causas_criticas", $ente_planificador); |
---|
1434 | $current_time = time(); |
---|
1435 | $fecha = FALSE; |
---|
1436 | if ($mi_fecha[1] + 86399 > $current_time && $mi_fecha[0] < $current_time) { |
---|
1437 | $fecha = TRUE; |
---|
1438 | } |
---|
1439 | if (!$fecha) { |
---|
1440 | muestra_mensaje("causas_criticas", $ente_planificador); |
---|
1441 | } |
---|
1442 | else { |
---|
1443 | $ente = usuario_tiene_ente($user->uid); |
---|
1444 | if (user_access('admin all planificador') || $ente->nid == $ente_planificador->nid) { |
---|
1445 | muestra_mensaje("causas_criticas", $ente_planificador, 0); |
---|
1446 | $ente_has_acceso = TRUE; |
---|
1447 | } |
---|
1448 | } |
---|
1449 | $description = variable_get('causas_criticas_description', FALSE); |
---|
1450 | $header = array(); |
---|
1451 | $header[] = array('data' => t('Descriptores')); |
---|
1452 | $header[] = array('data' => t('Causa Critica')); |
---|
1453 | $header[] = array('data' => t('Formas de Solución')); |
---|
1454 | if ($description) { |
---|
1455 | $header[] = array('data' => t('Metas')); |
---|
1456 | $header[] = array('data' => t('Sectores')); |
---|
1457 | $header[] = array('data' => t('Formas de Solución')); |
---|
1458 | $header[] = array('data' => t('Palabras claves')); |
---|
1459 | } |
---|
1460 | if ($description && $ente_has_acceso) { |
---|
1461 | $header[] = array('data' => t('Action')); |
---|
1462 | } |
---|
1463 | $year = variable_get('situacional_actual_preliminar_anho_creacion', 0); |
---|
1464 | $tipo_plan = CAUSA_CRITICA_PLAN; |
---|
1465 | $planns = _situacion_actual_preliminar_get_planns(); |
---|
1466 | $plan = $planns[$tipo_plan]; |
---|
1467 | $descriptores = _get_situacion_actual_listar_all_descriptores($ente_planificador->nid, $plan, $year); |
---|
1468 | $seleccionadas = _get_causas_all_causas($ente_planificador->nid, $plan, $year, 'criticas'); |
---|
1469 | $rows = array(); |
---|
1470 | $causas_load = array(); |
---|
1471 | foreach($descriptores as $descriptor) { |
---|
1472 | $row = array(); |
---|
1473 | $row[] = array('data' => $descriptor['body'], 'rowspan' => count($seleccionadas[$descriptor['nid']])); |
---|
1474 | foreach($seleccionadas[$descriptor['nid']] as $nid) { |
---|
1475 | if (!isset($causas_load[$nid])) { |
---|
1476 | $causas_load[$nid] = node_load($nid); |
---|
1477 | } |
---|
1478 | $causa = $causas_load[$nid]; |
---|
1479 | $row[] = array('data' => $causa->body,); |
---|
1480 | $campos = array( |
---|
1481 | 'field_causa_solucion' => 'field_causa_solucion', |
---|
1482 | ); |
---|
1483 | if ($description) { |
---|
1484 | $campos['field_causa_metas'] = 'field_causa_metas'; |
---|
1485 | $campos['field_causa_sectores'] = 'field_causa_sectores'; |
---|
1486 | $campos['field_causa_solucion'] = 'field_causa_solucion'; |
---|
1487 | $campos['field_causa_palabras'] = 'field_causa_palabras'; |
---|
1488 | } |
---|
1489 | foreach($campos as $campo) { |
---|
1490 | $lista = array(); |
---|
1491 | if (is_array($causa->{$campo}) && count($causa->{$campo})) { |
---|
1492 | foreach ($causa->{$campo} as $valor) { |
---|
1493 | $lista[] = $valor['value']; |
---|
1494 | } |
---|
1495 | } |
---|
1496 | $row[] = array('data' => theme('item_list', $lista),); |
---|
1497 | } |
---|
1498 | if (variable_get('causas_criticas_description', FALSE) && $ente_has_acceso) { |
---|
1499 | $row[] = array( |
---|
1500 | 'data' => l(t('Describir causa'), 'planificacion/' . $ente_planificador->nid . '/explicacion/causas/description/' . $causa->nid) |
---|
1501 | ); |
---|
1502 | } |
---|
1503 | $rows[] = $row; |
---|
1504 | $row = array(); |
---|
1505 | } |
---|
1506 | } |
---|
1507 | if (!count($rows)) { |
---|
1508 | $row = array(); |
---|
1509 | $row[] = array( |
---|
1510 | 'data' => t('No se han seleccionados las posibles causas crÃticas'), |
---|
1511 | 'colspan' => count($header), |
---|
1512 | 'align' => 'center' |
---|
1513 | ); |
---|
1514 | $rows[] = $row; |
---|
1515 | } |
---|
1516 | return theme('table', $header, $rows); |
---|
1517 | } |
---|
1518 | |
---|
1519 | /* |
---|
1520 | * Implementation of causas_criticas_select_causas_descriptores_form() |
---|
1521 | */ |
---|
1522 | function causas_criticas_select_causas_descriptores_form($form_state, $ente_planificador, $node) { |
---|
1523 | global $user; |
---|
1524 | if (!variable_get('causas_criticas_description', FALSE)) { |
---|
1525 | drupal_not_found(); |
---|
1526 | } |
---|
1527 | $breadcrumb[] = l(t('Home'), '<front>'); |
---|
1528 | $breadcrumb[] = l(t('Explicación Situacional'), 'planificacion/' . $ente_planificador->nid . '/explicacion'); |
---|
1529 | $breadcrumb[] = l(t('Causas CrÃticas'), 'planificacion/' . $ente_planificador->nid . '/explicacion/causas'); |
---|
1530 | $breadcrumb[] = l(t('Consultar Causas CrÃticas'), 'planificacion/' . $ente_planificador->nid . '/explicacion/causas/description'); |
---|
1531 | $texto = t('Describir causa'); |
---|
1532 | $breadcrumb[] = $texto; |
---|
1533 | drupal_set_breadcrumb($breadcrumb); |
---|
1534 | drupal_set_title(t('Describir la causa critica @causa', array('@causa' => $node->body))); |
---|
1535 | $mi_fecha = ente_planificador_user_acceso_proceso("causas_criticas", $ente_planificador); |
---|
1536 | $current_time = time(); |
---|
1537 | $fecha = FALSE; |
---|
1538 | if ($mi_fecha[1] + 86399 > $current_time && $mi_fecha[0] < $current_time) { |
---|
1539 | $fecha = TRUE; |
---|
1540 | } |
---|
1541 | if (!$fecha) { |
---|
1542 | muestra_mensaje("causas_criticas", $ente_planificador); |
---|
1543 | } |
---|
1544 | else { |
---|
1545 | $ente = usuario_tiene_ente($user->uid); |
---|
1546 | if (user_access('admin all planificador') || $ente->nid == $ente_planificador->nid) { |
---|
1547 | muestra_mensaje("causas_criticas", $ente_planificador, 0); |
---|
1548 | } |
---|
1549 | } |
---|
1550 | $form = array(); |
---|
1551 | $form['#node'] = $node; |
---|
1552 | $form['#ente_planificador'] = $ente_planificador; |
---|
1553 | module_load_include('inc', 'content', 'includes/content.node_form'); |
---|
1554 | $fields = array('field_causa_descriptores', 'field_causa_metas', 'field_causa_sectores', 'field_causa_solucion', 'field_causa_palabras'); |
---|
1555 | module_load_include('inc', 'content', 'includes/content.node_form'); |
---|
1556 | foreach($fields as $campo) { |
---|
1557 | $field = content_fields($campo, $form['#node']->type); |
---|
1558 | $form['#field_info'][$campo] = $field; |
---|
1559 | $form += (array) content_field_form($form, $form_state, $field); |
---|
1560 | } |
---|
1561 | $form['#fields_causas'] = $fields; |
---|
1562 | $form['buttons']['#weight'] = 100; |
---|
1563 | $form['buttons']['submit'] = array( |
---|
1564 | '#type' => 'submit', |
---|
1565 | '#value' => t('Submit'), |
---|
1566 | '#weight' => 100, |
---|
1567 | ); |
---|
1568 | $form['buttons']['cancel'] = array( |
---|
1569 | '#type' => 'submit', |
---|
1570 | '#value' => t('Cancel'), |
---|
1571 | '#weight' => 101, |
---|
1572 | ); |
---|
1573 | return $form; |
---|
1574 | } |
---|
1575 | |
---|
1576 | /* |
---|
1577 | * Implementation of causas_criticas_select_causas_descriptores_form_submit() |
---|
1578 | */ |
---|
1579 | function causas_criticas_select_causas_descriptores_form_submit($form, &$form_state) { |
---|
1580 | if (!$_REQUEST['destination']) { |
---|
1581 | // add redirect |
---|
1582 | $form_state['redirect'] = 'planificacion/' . $form['#ente_planificador']->nid . '/explicacion/causas/description'; |
---|
1583 | } |
---|
1584 | $op = isset($form_state['values']['op']) ? $form_state['values']['op'] : ''; |
---|
1585 | if ($op == t('Cancel')) { |
---|
1586 | return; |
---|
1587 | } |
---|
1588 | $causa_load = $form['#node']; |
---|
1589 | //se obtienen los descriptores |
---|
1590 | $field_form = $form['#fields_causas']; |
---|
1591 | $form_values = $form_state['values']; |
---|
1592 | if (is_array($field_form) && count($field_form)) { |
---|
1593 | foreach ($field_form as $field_id) { |
---|
1594 | if (isset($form_values[$field_id]) && is_array($form_values[$field_id])) { |
---|
1595 | foreach($form_values[$field_id] as $id => $value) { |
---|
1596 | if (is_numeric($id) && isset($form_values[$field_id][$id]['_error_element'])) { |
---|
1597 | unset($form_values[$field_id][$id]['_error_element']); |
---|
1598 | } |
---|
1599 | } |
---|
1600 | $causa_load->{$field_id} = $form_values[$field_id]; |
---|
1601 | } |
---|
1602 | } |
---|
1603 | } |
---|
1604 | module_load_include('inc', 'node', 'node.pages'); |
---|
1605 | node_object_prepare($causa_load); |
---|
1606 | $causa_load->log = t('Modificada la descripción de la causa'); |
---|
1607 | $causa_load->revision = 1; |
---|
1608 | node_save($causa_load); |
---|
1609 | drupal_set_message(t('Se agregaron los descriptores de la causa crÃtica')); |
---|
1610 | if (!$_REQUEST['destination']) { |
---|
1611 | // add redirect |
---|
1612 | $form_state['redirect'] = 'planificacion/' . $form['#ente_planificador']->nid . '/explicacion/causas/description'; |
---|
1613 | } |
---|
1614 | } |
---|
1615 | |
---|
1616 | /* |
---|
1617 | * hook_form_alter() |
---|
1618 | */ |
---|
1619 | function causas_criticas_form_alter(&$form, $form_state, $form_id) { |
---|
1620 | //impedir que los campos sean borrados con la interfaz |
---|
1621 | if ($form_id == 'content_field_overview_form' && $form['#type_name'] == 'causas'){ |
---|
1622 | $arreglo = array('field_causas_relacion', 'field_causa_posible', 'field_causa_critica', 'field_causa_descriptores', 'field_causa_metas', 'field_causa_sectores', 'field_causa_solucion', 'field_causa_palabras'); |
---|
1623 | foreach ($arreglo as $valor) { |
---|
1624 | if (isset($form[$valor]['remove']['#value'])) { |
---|
1625 | $form[$valor]['remove']['#value'] = ''; |
---|
1626 | } |
---|
1627 | } |
---|
1628 | } |
---|
1629 | if ($form_id == 'content_field_remove_form' && $form['type_name']['#value'] == 'causas'){ |
---|
1630 | $arreglo = array('field_causas_relacion', 'field_causa_posible', 'field_causa_critica', 'field_causa_descriptores', 'field_causa_metas', 'field_causa_sectores', 'field_causa_solucion', 'field_causa_palabras'); |
---|
1631 | foreach ($arreglo as $valor) { |
---|
1632 | if($form['field_name']['#value'] == $valor) { |
---|
1633 | $form['actions']['submit']['#access'] = FALSE; |
---|
1634 | $form['description']['#value'] = t('Acción no permitida este campo ha sido agregado por un modulo.'); |
---|
1635 | } |
---|
1636 | } |
---|
1637 | } |
---|
1638 | if ($form_id == 'situacional_actual_preliminar_admin_settings') { |
---|
1639 | $form['causas_criticas_description'] = array( |
---|
1640 | '#type' => 'checkbox', |
---|
1641 | '#title' => t('Permitir agregar Descripción de las Causas Criticas.'), |
---|
1642 | '#default_value' => variable_get('causas_criticas_description', FALSE), |
---|
1643 | '#weight' => -10, |
---|
1644 | ); |
---|
1645 | $planns = array( |
---|
1646 | 'situacion_objetivo' => t('Situación Objetivo'), |
---|
1647 | ); |
---|
1648 | $tipos = array( |
---|
1649 | 'situacion_objetivo' => t('Situación Objetivo'), |
---|
1650 | ); |
---|
1651 | $options = array('_none' => 'Ninguna'); |
---|
1652 | $views = views_get_all_views(); |
---|
1653 | foreach ($views as $view) { |
---|
1654 | $options[$view->name] = $view->human_name; |
---|
1655 | } |
---|
1656 | foreach ($planns as $plan => $title) { |
---|
1657 | $tipo = $plan; |
---|
1658 | $form['situacional_actual_preliminar_views']['situacion_actual_preliminar_' . $plan] = array( |
---|
1659 | '#title' => $title, |
---|
1660 | '#type' => 'fieldset', |
---|
1661 | ); |
---|
1662 | foreach ($tipos as $name => $value) { |
---|
1663 | $sap_name = 'situacion_actual_preliminar_' . $plan; |
---|
1664 | $form['situacional_actual_preliminar_views'][$sap_name][$sap_name . '_' . $name] = array( |
---|
1665 | '#title' => $value, |
---|
1666 | '#type' => 'select', |
---|
1667 | '#default_value' => variable_get($sap_name . '_' . $name, 0), |
---|
1668 | '#description' => t('Seleccione la vista para el proceso de <strong> @plan</strong>', array('@plan' => $title)), |
---|
1669 | '#options' => $options, |
---|
1670 | '#ahah' => array( |
---|
1671 | 'event' => 'change', |
---|
1672 | 'path' => 'situacional_actual_preliminar_views_js/' . $plan. '/' . $name, |
---|
1673 | 'wrapper' => 'situacion_actual_preliminar_display_views_' . $plan . '_' . $name, |
---|
1674 | 'method' => 'replace', |
---|
1675 | 'progress' => array('type' => 'bar', 'message' => t('Please wait...')), |
---|
1676 | ), |
---|
1677 | ); |
---|
1678 | if (!variable_get('situacion_actual_preliminar_display_views_' . $plan . '_' . $name, 0)) { |
---|
1679 | $form['situacional_actual_preliminar_views'][$sap_name]['situacion_actual_preliminar_display_views_' . $plan . '_' . $name] = array( |
---|
1680 | '#prefix' => '<div id="situacion_actual_preliminar_display_views_' . $plan . '_' . $name . '">', |
---|
1681 | '#suffix' => '</div>', |
---|
1682 | '#type' => 'hidden', |
---|
1683 | ); |
---|
1684 | } |
---|
1685 | else { |
---|
1686 | $view = views_get_view(variable_get($sap_name . '_' . $name, 0)); |
---|
1687 | foreach ($view->display as $key => $display) { |
---|
1688 | $options_display[$key] = $display->display_title; |
---|
1689 | } |
---|
1690 | $form['situacional_actual_preliminar_views'][$sap_name]['situacion_actual_preliminar_display_views_' . $plan . '_' . $name] = array( |
---|
1691 | '#title' => t("Seleccione el display de la vista"), |
---|
1692 | '#type' => 'select', |
---|
1693 | '#default_value' => variable_get('situacion_actual_preliminar_display_views_' . $plan . '_' . $name, 0), |
---|
1694 | '#options' => $options_display, |
---|
1695 | '#prefix' => '<div id="situacion_actual_preliminar_display_views_' . $plan . '_' . $name . '">', |
---|
1696 | '#suffix' => '</div>', |
---|
1697 | ); |
---|
1698 | } |
---|
1699 | } |
---|
1700 | } |
---|
1701 | } |
---|
1702 | } |
---|