1 | <?php |
---|
2 | /** |
---|
3 | * Modulo para la gestión de los entes planificadores |
---|
4 | * Sistema Automatizado para la Planificación Estratégico-Situacional en la Administración Pública Venezolana |
---|
5 | * @file ente_planificador.module |
---|
6 | * Drupal part Module to code ente planificador module |
---|
7 | * Copyright 2011 Sistema Automatizado para la Planificación Estratégico-Situacional en la Administración Pública Venezolana (CENDITEL) |
---|
8 | * |
---|
9 | * This program is free software; you can redistribute it and/or modify |
---|
10 | * it under the terms of the GNU General Public License as published by |
---|
11 | * the Free Software Foundation; either version 2 of the License, or |
---|
12 | * (at your option) any later version. |
---|
13 | * |
---|
14 | * This program is distributed in the hope that it will be useful, |
---|
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
17 | * GNU General Public License for more details. |
---|
18 | * |
---|
19 | * You should have received a copy of the GNU General Public License |
---|
20 | * along with this program; if not, write to the Free Software |
---|
21 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
---|
22 | * |
---|
23 | * @author Cenditel Merida - Msc. Juan Vizcarrondo |
---|
24 | * Modificado por: Msc. Juan Vizcarrondo @date 2011-04-27. |
---|
25 | * Modificado por: Msc. Juan Vizcarrondo @date 2011-06-10. |
---|
26 | * Modificado por: Msc. Juan Vizcarrondo @date 2011-12-05. |
---|
27 | * Modificado por: Msc. Juan Vizcarrondo @date 2012-02-16. |
---|
28 | * Modificado por: Ing. Luis G. Peña C @date 2012-03-15 |
---|
29 | * Modificado por: Msc. Juan Vizcarrondo @date 2012-03-26. |
---|
30 | * Modificado por: Msc. Juan Vizcarrondo @date 2012-04-17. |
---|
31 | * @date 2010-04-27 // (año-mes-dia) |
---|
32 | * @version 0.2 // (0.1) |
---|
33 | * |
---|
34 | */ |
---|
35 | |
---|
36 | /* |
---|
37 | * entes_planificadores_obtiene_tipos |
---|
38 | * Lista los tipos de entes |
---|
39 | */ |
---|
40 | function entes_planificadores_obtiene_tipos($tipo = 0) { |
---|
41 | $tipos = array( |
---|
42 | 2 => t('Actor Micro'), |
---|
43 | 1 => t('Actor Macro'), |
---|
44 | ); |
---|
45 | drupal_alter('obtiene_tipos', $tipos); |
---|
46 | |
---|
47 | if ($tipo && is_numeric($tipo) && $tipos[$tipo]) { |
---|
48 | return $tipos[$tipo]; |
---|
49 | } |
---|
50 | elseif($tipo) { |
---|
51 | return FALSE; |
---|
52 | } |
---|
53 | |
---|
54 | return $tipos; |
---|
55 | } |
---|
56 | |
---|
57 | /* |
---|
58 | * ente_planificador_ente_macro() |
---|
59 | * Obtiene el ente macro de un ente micro, actualmente esta funcion regresa el unico ente macro permitido en el sistema |
---|
60 | * pero podria modificarse en un futuro con otro modulo invocando el hook_obtiene_macro_alter |
---|
61 | */ |
---|
62 | function ente_planificador_ente_macro($ente_planificador = 0) { |
---|
63 | $actor_macro = FALSE; |
---|
64 | $result = db_query("SELECT d.nid FROM {ente_planificador} AS d INNER JOIN {node} AS n ON n.nid = d.nid WHERE tipo = 1"); |
---|
65 | $macro = db_fetch_object($result); |
---|
66 | if ($macro->nid){ |
---|
67 | $actor_macr0 = $macro->nid; |
---|
68 | } |
---|
69 | drupal_alter('obtiene_macro', $actor_macr0, $ente_planificador); |
---|
70 | return $actor_macr0; |
---|
71 | } |
---|
72 | |
---|
73 | /* |
---|
74 | * Implementation of hook_menu() |
---|
75 | */ |
---|
76 | function ente_planificador_menu() { |
---|
77 | $items = array(); |
---|
78 | $items['administrar/entes_planificadores'] = array( |
---|
79 | 'title' => 'Consultar lista de actores planificadores', |
---|
80 | 'page callback' => 'entes_planificadores', |
---|
81 | 'access arguments' => array('ver planificador'), |
---|
82 | 'type' => MENU_NORMAL_ITEM, |
---|
83 | ); |
---|
84 | $items['entes_planificadores/registrar'] = array( |
---|
85 | 'title' => 'Registrar Actores Planificadores', |
---|
86 | 'page callback' => 'entes_planificadores_agregar', |
---|
87 | 'page arguments' => array(1), |
---|
88 | 'access arguments' => array('admin planificador'), |
---|
89 | 'type' => MENU_NORMAL_ITEM, |
---|
90 | ); |
---|
91 | $items['ente_planificador_js_util/%'] = array( |
---|
92 | 'title' => 'JS utilities', |
---|
93 | 'page callback' => 'ente_planificador_js_util', |
---|
94 | 'page arguments' => array(1), |
---|
95 | 'access arguments' => array('access content'), |
---|
96 | 'type' => MENU_CALLBACK, |
---|
97 | ); |
---|
98 | $items['administrar/entes_planificadores/registrar'] = array( |
---|
99 | 'title' => 'Registrar Actores Planificadores', |
---|
100 | 'page callback' => 'entes_planificadores_agregar', |
---|
101 | 'page arguments' => array(1), |
---|
102 | 'access arguments' => array('admin planificador'), |
---|
103 | 'type' => MENU_NORMAL_ITEM, |
---|
104 | ); |
---|
105 | $items['administrar/entes_planificadores/lista'] = array( |
---|
106 | 'title' => t('List'), |
---|
107 | 'type' => MENU_DEFAULT_LOCAL_TASK, |
---|
108 | 'weight' => -10 |
---|
109 | ); |
---|
110 | $items['node/%/datos_basicos'] = array( |
---|
111 | 'title' => 'Editar datos del actor planificador', |
---|
112 | 'page callback' => 'ente_planificador_datos_basicos', |
---|
113 | 'page arguments' => array(1), |
---|
114 | 'access callback' => 'nodo_es_ente_planificador', |
---|
115 | 'access arguments' => array(1), |
---|
116 | 'type' => MENU_LOCAL_TASK, |
---|
117 | ); |
---|
118 | $items['node/%/usuarios'] = array( |
---|
119 | 'title' => 'Usuarios Asignados', |
---|
120 | 'page callback' => 'entes_planificadores_usuarios', |
---|
121 | 'page arguments' => array(1), |
---|
122 | 'access callback' => 'nodo_es_ente_planificador', |
---|
123 | 'access arguments' => array(1), |
---|
124 | 'type' => MENU_LOCAL_TASK, |
---|
125 | ); |
---|
126 | $items['node/%/planificacion'] = array( |
---|
127 | 'title' => 'Planificación', |
---|
128 | 'page callback' => 'entes_planificadores_planificacion', |
---|
129 | 'page arguments' => array(1), |
---|
130 | 'access callback' => 'nodo_es_ente_planificador', |
---|
131 | 'access arguments' => array(1), |
---|
132 | 'type' => MENU_LOCAL_TASK, |
---|
133 | ); |
---|
134 | $items['administrar_usuarios'] = array( |
---|
135 | 'title' => 'Consultar Listado de Usuarios', |
---|
136 | 'page callback' => 'entes_planificadores_listar_usuarios', |
---|
137 | 'access arguments' => array('admin planificador'), |
---|
138 | 'type' => MENU_NORMAL_ITEM, |
---|
139 | ); |
---|
140 | $items['fechas_planificacion'] = array( |
---|
141 | 'title' => 'Consultar listado de fechas de las procesos de planificación', |
---|
142 | 'page callback' => 'ente_planificador_fecha_planificacion', |
---|
143 | 'access arguments' => array('ver planificador'), |
---|
144 | 'type' => MENU_NORMAL_ITEM, |
---|
145 | ); |
---|
146 | $items['fechas_planificacion/envia_email'] = array( |
---|
147 | 'title' => 'Enviar Correo Electronico de la fecha de Planificación', |
---|
148 | 'page callback' => 'ente_planificador_fecha_planificacion_correo', |
---|
149 | 'access callback' => 'usuario_tiene_permisos', |
---|
150 | 'type' => MENU_NORMAL_ITEM, |
---|
151 | ); |
---|
152 | $items['fechas_planificacion/edit'] = array( |
---|
153 | 'title' => 'Modificar las fechas para los procesos de planificación.', |
---|
154 | 'page callback' => 'ente_planificador_fecha_planificacion_edit', |
---|
155 | 'access arguments' => array('admin planificador'), |
---|
156 | 'type' => MENU_CALLBACK, |
---|
157 | ); |
---|
158 | $items['fechas_planificacion/todas_edit'] = array( |
---|
159 | 'title' => 'Modificar todas las fechas para los procesos de planificación.', |
---|
160 | 'page callback' => 'drupal_get_form', |
---|
161 | 'page arguments' => array('ente_planificador_fecha_planificacion_edit_todas'), |
---|
162 | 'access arguments' => array('admin planificador'), |
---|
163 | 'type' => MENU_NORMAL_ITEM, |
---|
164 | ); |
---|
165 | $items['fechas_planificacion/notificacion'] = array( |
---|
166 | 'title' => 'Fecha de notificación.', |
---|
167 | 'page callback' => 'drupal_get_form', |
---|
168 | 'page arguments' => array('ente_planificador_fecha_planificacion_edit_notificacion'), |
---|
169 | 'access arguments' => array('admin planificador'), |
---|
170 | 'type' => MENU_NORMAL_ITEM, |
---|
171 | ); |
---|
172 | $items['admin/settings/ente_planificador'] = array( |
---|
173 | 'title' => t('Configuración Ente Planificador'), |
---|
174 | 'description' => t('Configuración del Ente Planificador.'), |
---|
175 | 'page callback' => 'drupal_get_form', |
---|
176 | 'page arguments' => array('ente_planificador_admin_settings'), |
---|
177 | 'access arguments' => array('admin planificador'), |
---|
178 | 'type' => MENU_NORMAL_ITEM, |
---|
179 | ); |
---|
180 | $items['admin/settings/ente_planificador/view'] = array( |
---|
181 | 'title' => t('Configuración Ente Planificador'), |
---|
182 | 'type' => MENU_DEFAULT_LOCAL_TASK, |
---|
183 | 'weight' => -10 |
---|
184 | ); |
---|
185 | $items['admin/settings/ente_planificador/actividades'] = array( |
---|
186 | 'title' => t('Actividades'), |
---|
187 | 'page callback' => 'ente_planificador_view_actividades', |
---|
188 | 'access arguments' => array('admin planificador'), |
---|
189 | 'weight' => -8, |
---|
190 | 'type' => MENU_LOCAL_TASK, |
---|
191 | ); |
---|
192 | $items['admin/settings/ente_planificador/agregar_actividades'] = array( |
---|
193 | 'title' => t('Agregar Actividad'), |
---|
194 | 'page callback' => 'drupal_get_form', |
---|
195 | 'page arguments' => array('ente_planificador_agregar_actividades_form'), |
---|
196 | 'access arguments' => array('admin planificador'), |
---|
197 | 'weight' => -8, |
---|
198 | 'type' => MENU_LOCAL_TASK, |
---|
199 | ); |
---|
200 | $items['admin/settings/ente_planificador/actividades/%actividad_menu/edit'] = array( |
---|
201 | 'title' => t('Modificar'), |
---|
202 | 'page callback' => 'drupal_get_form', |
---|
203 | 'page arguments' => array('ente_planificador_edit_actividad_form',4), |
---|
204 | 'access arguments' => array('admin planificador'), |
---|
205 | 'type' => MENU_CALLBACK, |
---|
206 | ); |
---|
207 | $items['admin/settings/ente_planificador/actividades/%actividad_menu/remove'] = array( |
---|
208 | 'title' => t('Modificar'), |
---|
209 | 'page callback' => 'drupal_get_form', |
---|
210 | 'page arguments' => array('ente_planificador_eliminar_actividad_form',4), |
---|
211 | 'access arguments' => array('admin planificador'), |
---|
212 | 'type' => MENU_CALLBACK, |
---|
213 | ); |
---|
214 | $items['planificacion/%ente_planificador_menu'] = array( |
---|
215 | 'title' => t('Planificación'), |
---|
216 | 'page callback' => 'ente_planificador_view_planning', |
---|
217 | 'page arguments' => array(1), |
---|
218 | 'access arguments' => array('ver planificador'), |
---|
219 | 'weight' => -10, |
---|
220 | 'type' => MENU_CALLBACK, |
---|
221 | ); |
---|
222 | $items['planificacion/%ente_planificador_menu/view'] = array( |
---|
223 | 'title' => 'View', |
---|
224 | 'type' => MENU_DEFAULT_LOCAL_TASK, |
---|
225 | 'weight' => -10 |
---|
226 | ); |
---|
227 | $items['mi_ente_planificador'] = array( |
---|
228 | 'title' => 'Mi ente planificador', |
---|
229 | 'page callback' => 'mis_entes_planificadores', |
---|
230 | 'access callback' => 'ente_planificador_usuario_ve_ente', |
---|
231 | 'type' => MENU_NORMAL_ITEM, |
---|
232 | ); |
---|
233 | $items['mi_ente_planificador/view'] = array( |
---|
234 | 'title' => 'View', |
---|
235 | 'type' => MENU_DEFAULT_LOCAL_TASK, |
---|
236 | 'weight' => -10 |
---|
237 | ); |
---|
238 | $items['mi_ente_planificador/datos_basicos'] = array( |
---|
239 | 'title' => 'Editar datos del actor planificador', |
---|
240 | 'page callback' => 'mis_entes_planificadores_datos_basicos', |
---|
241 | 'access callback' => 'ente_planificador_usuario_ve_ente', |
---|
242 | 'type' => MENU_LOCAL_TASK, |
---|
243 | ); |
---|
244 | $items['mi_ente_planificador/usuarios'] = array( |
---|
245 | 'title' => 'Usuarios Asignados', |
---|
246 | 'page callback' => 'mis_entes_planificadores_usuarios', |
---|
247 | 'access callback' => 'ente_planificador_usuario_ve_ente', |
---|
248 | 'type' => MENU_LOCAL_TASK, |
---|
249 | ); |
---|
250 | $items['mi_ente_planificador/planificacion'] = array( |
---|
251 | 'title' => 'Mi planificación', |
---|
252 | 'page callback' => 'mis_entes_planificadores_planificacion', |
---|
253 | 'access callback' => 'ente_planificador_usuario_ve_ente', |
---|
254 | 'type' => MENU_LOCAL_TASK, |
---|
255 | ); |
---|
256 | $items['mi_ente_planificador/planificacion/view'] = array( |
---|
257 | 'title' => 'View', |
---|
258 | 'type' => MENU_DEFAULT_LOCAL_TASK, |
---|
259 | 'weight' => -10 |
---|
260 | ); |
---|
261 | return $items; |
---|
262 | } |
---|
263 | |
---|
264 | /* |
---|
265 | * Implementation of ente_planificador_usuario_ve_ente() |
---|
266 | */ |
---|
267 | function ente_planificador_usuario_ve_ente() { |
---|
268 | global $user; |
---|
269 | if (user_access('edit own planificador')) { |
---|
270 | $ente = usuario_tiene_ente($user->uid); |
---|
271 | if ($ente->nid) { |
---|
272 | return TRUE; |
---|
273 | } |
---|
274 | } |
---|
275 | return FALSE; |
---|
276 | } |
---|
277 | |
---|
278 | /* |
---|
279 | * Implementation of mis_entes_planificadores_datos_basicos() |
---|
280 | */ |
---|
281 | function mis_entes_planificadores_datos_basicos() { |
---|
282 | global $user; |
---|
283 | $output = ''; |
---|
284 | $ente = usuario_tiene_ente($user->uid); |
---|
285 | if ($ente->nid) { |
---|
286 | $output .= ente_planificador_datos_basicos($ente->nid); |
---|
287 | } |
---|
288 | return $output; |
---|
289 | } |
---|
290 | |
---|
291 | /* |
---|
292 | * Implementation of mis_entes_planificadores_usuarios() |
---|
293 | */ |
---|
294 | function mis_entes_planificadores_usuarios() { |
---|
295 | global $user; |
---|
296 | $output = ''; |
---|
297 | $ente = usuario_tiene_ente($user->uid); |
---|
298 | if ($ente->nid) { |
---|
299 | $output .= entes_planificadores_usuarios($ente->nid); |
---|
300 | } |
---|
301 | return $output; |
---|
302 | } |
---|
303 | |
---|
304 | /* |
---|
305 | * Implementation of mis_entes_planificadores_planificacion() |
---|
306 | */ |
---|
307 | function mis_entes_planificadores_planificacion() { |
---|
308 | global $user; |
---|
309 | $output = ''; |
---|
310 | $ente = usuario_tiene_ente($user->uid); |
---|
311 | if ($ente->nid) { |
---|
312 | $ente = ente_planificador_leer($ente->nid); |
---|
313 | $output .= ente_planificador_view_planning($ente); |
---|
314 | } |
---|
315 | return $output; |
---|
316 | } |
---|
317 | |
---|
318 | /** |
---|
319 | * Implementation of actividad_menu_load(). |
---|
320 | * Menu loader callback. Load actividad. |
---|
321 | */ |
---|
322 | function actividad_menu_load($actividad) { |
---|
323 | if ($actividad) { |
---|
324 | $resul_act = db_query("SELECT * FROM {ente_actividad} where id_actividad = %d", $actividad); |
---|
325 | $actividad = db_fetch_object($resul_act); |
---|
326 | return $actividad; |
---|
327 | } |
---|
328 | return FALSE; |
---|
329 | } |
---|
330 | |
---|
331 | /* |
---|
332 | * Implementation of ente_planificador_view_actividades() |
---|
333 | */ |
---|
334 | function ente_planificador_view_actividades() { |
---|
335 | $header = array(); |
---|
336 | $header[] = array('data' => t('Name')); |
---|
337 | $header[] = array('data' => t('Action'), 'colspan' => 2); |
---|
338 | $actividades = ente_planificador_obtener_actividades(); |
---|
339 | $rows = array(); |
---|
340 | foreach($actividades as $id => $actividad) { |
---|
341 | $row = array(); |
---|
342 | $row[] = array('data' => t($actividad), ); |
---|
343 | $row[] = array( |
---|
344 | 'data' => l(t('Update'), 'admin/settings/ente_planificador/actividades/' . $id . '/edit'), |
---|
345 | ); |
---|
346 | $row[] = array( |
---|
347 | 'data' => l(t('Remove'),'admin/settings/ente_planificador/actividades/' . $id . '/remove'), |
---|
348 | ); |
---|
349 | $rows[] = $row; |
---|
350 | } |
---|
351 | if (!count($rows)) { |
---|
352 | $row = array(); |
---|
353 | $row[] = array( |
---|
354 | 'data' => t('No se encontrarón actividades'), |
---|
355 | 'colspan' => 3 |
---|
356 | ); |
---|
357 | $rows[] = $row; |
---|
358 | } |
---|
359 | return theme('table', $header, $rows); |
---|
360 | } |
---|
361 | |
---|
362 | /** |
---|
363 | * Implementation of webforms_countries_menu_country_load(). |
---|
364 | * Menu loader callback. Load a country. |
---|
365 | */ |
---|
366 | function ente_planificador_menu_load($ente_planificador_menu) { |
---|
367 | $ente = ente_planificador_leer($ente_planificador_menu); |
---|
368 | if ($ente) { |
---|
369 | return $ente; |
---|
370 | } |
---|
371 | return FALSE; |
---|
372 | } |
---|
373 | |
---|
374 | /* |
---|
375 | * Implementation of ente_planificador_agregar_actividades_form() |
---|
376 | */ |
---|
377 | function ente_planificador_agregar_actividades_form(&$form_state) { |
---|
378 | $form = array(); |
---|
379 | $form['nombre'] = array( |
---|
380 | '#title' => t('Actividad'), |
---|
381 | '#type' => 'textfield', |
---|
382 | '#default_value' => $actividad_menu->nombre, |
---|
383 | '#required' => TRUE, |
---|
384 | '#maxlength' => 1024, |
---|
385 | ); |
---|
386 | $form['submit'] = array( |
---|
387 | '#type' => 'submit', |
---|
388 | '#value' => t('Save Actividad'), |
---|
389 | '#weight' => 40, |
---|
390 | ); |
---|
391 | return $form; |
---|
392 | } |
---|
393 | |
---|
394 | /** |
---|
395 | * Implementation of ente_planificador_agregar_actividades_form_submit(). |
---|
396 | * Save actividad values |
---|
397 | */ |
---|
398 | function ente_planificador_agregar_actividades_form_submit($form, &$form_state) { |
---|
399 | db_query("INSERT INTO {ente_actividad} (nombre) VALUES ('%s')", check_plain($form_state['values']['nombre'])); |
---|
400 | drupal_set_message(t('Actividad %name_actividad agregada', array('%name_actividad' => $form_state['values']['nombre']))); |
---|
401 | $form_state['redirect'] = 'admin/settings/ente_planificador/actividades'; |
---|
402 | } |
---|
403 | |
---|
404 | /** |
---|
405 | * Implementation of ente_planificador_edit_actividad_form(). |
---|
406 | * Edit a actividad data. |
---|
407 | */ |
---|
408 | function ente_planificador_edit_actividad_form(&$form_state, $actividad_menu) { |
---|
409 | $form['id_actividad'] = array( |
---|
410 | '#type' => 'hidden', |
---|
411 | '#value' => $actividad_menu->id_actividad, |
---|
412 | ); |
---|
413 | $form['nombre'] = array( |
---|
414 | '#title' => t('Actividad'), |
---|
415 | '#type' => 'textfield', |
---|
416 | '#default_value' => $actividad_menu->nombre, |
---|
417 | '#required' => TRUE, |
---|
418 | '#maxlength' => 1024, |
---|
419 | ); |
---|
420 | $form['submit'] = array( |
---|
421 | '#type' => 'submit', |
---|
422 | '#value' => t('Save Actividad'), |
---|
423 | '#weight' => 40, |
---|
424 | ); |
---|
425 | return $form; |
---|
426 | } |
---|
427 | |
---|
428 | /* |
---|
429 | * Implementation of ente_planificador_edit_actividad_form_submit() |
---|
430 | */ |
---|
431 | function ente_planificador_edit_actividad_form_submit($form, &$form_state) { |
---|
432 | db_query("UPDATE {ente_actividad} SET nombre = '%s' WHERE id_actividad = %d", check_plain($form_state['values']['nombre']), $form_state['values']['id_actividad']); |
---|
433 | drupal_set_message(t('Actividad %name_actividad modificada', array('%name_actividad' => $form_state['values']['nombre']))); |
---|
434 | $form_state['redirect'] = 'admin/settings/ente_planificador/actividades'; |
---|
435 | } |
---|
436 | |
---|
437 | /* |
---|
438 | * Implementation of ente_planificador_eliminar_actividad_form() |
---|
439 | */ |
---|
440 | function ente_planificador_eliminar_actividad_form(&$form_state, $actividad_menu) { |
---|
441 | $form['id_actividad'] = array('#type' => 'value', '#value' => $actividad_menu->id_actividad); |
---|
442 | $form['nombre'] = array('#type' => 'value', '#value' => $actividad_menu->nombre); |
---|
443 | $message = t('Are you sure you want to delete actividad %name_actividad?', array('%name_actividad' => $actividad_menu->nombre)); |
---|
444 | $caption = '<p>'. t('This action cannot be undone.') .'</p>'; |
---|
445 | $return_path = 'admin/settings/ente_planificador/actividades'; |
---|
446 | return confirm_form($form, $message, $return_path, $caption, t('Delete')); |
---|
447 | } |
---|
448 | |
---|
449 | /* |
---|
450 | * Implementation of ente_planificador_eliminar_actividad_form_submit() |
---|
451 | */ |
---|
452 | function ente_planificador_eliminar_actividad_form_submit($form, &$form_state) { |
---|
453 | db_query("DELETE FROM {ente_actividad} WHERE id_actividad = %d", $form_state['values']['id_actividad']); |
---|
454 | drupal_set_message(t('Actividad %name_actividad borrada'.$form_state['values']['id_actividad'], array('%name_actividad' => $form_state['values']['nombre']))); |
---|
455 | $form_state['redirect'] = 'admin/settings/ente_planificador/actividades'; |
---|
456 | } |
---|
457 | |
---|
458 | /* |
---|
459 | * Implementation of ente_planificador_leer() |
---|
460 | */ |
---|
461 | function ente_planificador_leer($nid) { |
---|
462 | if (isset($nid) && is_numeric($nid)) { |
---|
463 | $ente = node_load($nid); |
---|
464 | if ($ente->type == 'ente_planificador') { |
---|
465 | return $ente; |
---|
466 | } |
---|
467 | } |
---|
468 | return FALSE; |
---|
469 | } |
---|
470 | |
---|
471 | /* |
---|
472 | * Implementation of ente_planificador_obtiene_resumen_planificacion() |
---|
473 | */ |
---|
474 | function ente_planificador_obtiene_resumen_planificacion($nid, $type = "all") { |
---|
475 | $planificacion = array(); |
---|
476 | $estados = ente_planificador_status_planificacion($nid); |
---|
477 | $total_suma = 0; |
---|
478 | $total_ejecutado = 0; |
---|
479 | if (count($estados)) { |
---|
480 | foreach($estados as $id_estado => $estado) { |
---|
481 | $etapas = count($estado['value']); |
---|
482 | if ($etapas) { |
---|
483 | $suma = 0; |
---|
484 | foreach($estado['value'] as $value) { |
---|
485 | $total_suma++; |
---|
486 | if ($value['value']) { |
---|
487 | $suma++; |
---|
488 | } |
---|
489 | } |
---|
490 | $total_ejecutado += $suma; |
---|
491 | $porc = ($suma * 100) / $etapas; |
---|
492 | if ($type == "all") { |
---|
493 | $planificacion['etapas'][] = l($estado['title'] . ' (' . round($porc, 2) . '%).', 'planificacion/' . $nid . '/' . $id_estado); |
---|
494 | } |
---|
495 | else { |
---|
496 | $planificacion['etapas'][] = l($estado['title'] . ' (' . round($porc, 2) . '%).', 'mi_ente_planificador/planificacion/' . $id_estado); |
---|
497 | } |
---|
498 | } |
---|
499 | $planificacion['total'] = ($total_suma > 0) ? ($total_ejecutado * 100) / $total_suma : 0; |
---|
500 | } |
---|
501 | } |
---|
502 | return $planificacion; |
---|
503 | } |
---|
504 | |
---|
505 | /* |
---|
506 | * Implementation of hook_planificador_block() |
---|
507 | */ |
---|
508 | function ente_planificador_block($op = 'list', $delta = 0, $edit = array()) { |
---|
509 | if ($op == 'list') { |
---|
510 | $blocks[0] = array( |
---|
511 | 'info' => t('Mi planificación'), |
---|
512 | 'cache' => BLOCK_CACHE_PER_USER, |
---|
513 | ); |
---|
514 | $blocks[1] = array( |
---|
515 | 'info' => t('Planificación del Ente'), |
---|
516 | 'cache' => BLOCK_CACHE_PER_PAGE, |
---|
517 | ); |
---|
518 | return $blocks; |
---|
519 | } |
---|
520 | else if ($op == 'view') { |
---|
521 | switch ($delta) { |
---|
522 | case 0: |
---|
523 | global $user; |
---|
524 | $ente = usuario_tiene_ente($user->uid); |
---|
525 | if ($ente->nid) { |
---|
526 | $planificacion = ente_planificador_obtiene_resumen_planificacion($ente->nid); |
---|
527 | if (count($planificacion)) { |
---|
528 | $output = '<p><b>' . l(t('Porcentaje de Avance'), 'mi_ente_planificador/planificacion') . ':</b> ' . round($planificacion['total'], 2) . '%</p>'; |
---|
529 | if (count($planificacion['etapas'])) { |
---|
530 | $output .= '<ul>'; |
---|
531 | foreach($planificacion['etapas'] as $texto) { |
---|
532 | $output .= '<li>' . $texto . '</li>'; |
---|
533 | } |
---|
534 | $output .= '</ul>'; |
---|
535 | } |
---|
536 | $block = array( |
---|
537 | 'subject' => t('Mi planificación'), |
---|
538 | 'content' => $output, |
---|
539 | ); |
---|
540 | } |
---|
541 | } |
---|
542 | break; |
---|
543 | case 1: |
---|
544 | if((arg(0) == 'node' && is_numeric(arg(1))) || (arg(0) == 'planificacion' && is_numeric(arg(1)))) { |
---|
545 | $ente_planificador = node_load(arg(1)); |
---|
546 | $planificacion = ente_planificador_obtiene_resumen_planificacion(arg(1)); |
---|
547 | if (count($planificacion)) { |
---|
548 | $output = '<p><b>' . l(t('Porcentaje de Avance'), 'planificacion/' . $ente_planificador->nid) . ':</b> ' . round($planificacion['total'], 2) . '%</p>'; |
---|
549 | if (count($planificacion['etapas'])) { |
---|
550 | $output .= '<ul>'; |
---|
551 | foreach($planificacion['etapas'] as $texto) { |
---|
552 | $output .= '<li>' . $texto . '</li>'; |
---|
553 | } |
---|
554 | $output .= '</ul>'; |
---|
555 | } |
---|
556 | $block = array( |
---|
557 | 'subject' => t('Planificación del ente @ente', array('@ente' => $ente_planificador->title)), |
---|
558 | 'content' => $output, |
---|
559 | ); |
---|
560 | } |
---|
561 | } |
---|
562 | break; |
---|
563 | } |
---|
564 | return $block; |
---|
565 | } |
---|
566 | } |
---|
567 | |
---|
568 | /* |
---|
569 | * Implementation of ente_planificador_view_planning() |
---|
570 | */ |
---|
571 | function ente_planificador_view_planning($ente_planificador) { |
---|
572 | $output = '<p>' . t('Ente planificador: @ente', array('@ente' => $ente_planificador->title)) . '</p>'; |
---|
573 | $estados = ente_planificador_status_planificacion($ente_planificador->nid, $ente_planificador->tipo); |
---|
574 | $header = array(); |
---|
575 | $header[] = array('data' => t('Etapa')); |
---|
576 | $header[] = array('data' => t('Estado')); |
---|
577 | $rows = array(); |
---|
578 | $total_suma = 0; |
---|
579 | $total_ejecutado = 0; |
---|
580 | if (count($estados)) { |
---|
581 | foreach($estados as $estado) { |
---|
582 | $row = array(); |
---|
583 | $row[] = array( |
---|
584 | 'data' => '<b>' . $estado['title'] . '</b>', |
---|
585 | 'colspan' => '2', |
---|
586 | 'align' => 'center' |
---|
587 | ); |
---|
588 | $rows[] = $row; |
---|
589 | $porc = 0; |
---|
590 | $etapas = count($estado['value']); |
---|
591 | if ($etapas) { |
---|
592 | $suma = 0; |
---|
593 | foreach($estado['value'] as $value) { |
---|
594 | $total_suma++; |
---|
595 | $row = array(); |
---|
596 | $valor = $value['value'] ? t('Comenzada') : t('Por comenzar'); |
---|
597 | $row[] = array('data' => l($value['title'], $value['link']) ,); |
---|
598 | $row[] = array('data' => $valor,); |
---|
599 | $rows[] = $row; |
---|
600 | if ($value['value']) { |
---|
601 | $suma++; |
---|
602 | } |
---|
603 | } |
---|
604 | $total_ejecutado += $suma; |
---|
605 | $porc = ($suma * 100) / $etapas; |
---|
606 | } |
---|
607 | $row = array(); |
---|
608 | $row[] = array( |
---|
609 | 'data' => '<b>' . t('Porcentaje') . '</b>', |
---|
610 | 'align' => 'right', |
---|
611 | ); |
---|
612 | $row[] = array('data' => '<b>' . round($porc, 2) . ' %' . '</b>',); |
---|
613 | $rows[] = $row; |
---|
614 | } |
---|
615 | $total_porcentaje = ($total_suma > 0) ? ($total_ejecutado * 100) / $total_suma : 0; |
---|
616 | $row = array(); |
---|
617 | $row[] = array( |
---|
618 | 'data' => '<b>' . t('Porcentaje Total : ') . round($total_porcentaje, 2) . ' %</b>', |
---|
619 | 'colspan' => '2', |
---|
620 | 'align' => 'center', |
---|
621 | ); |
---|
622 | $rows[] = $row; |
---|
623 | } |
---|
624 | if (!count($rows)) { |
---|
625 | $row = array(); |
---|
626 | $row[] = array( |
---|
627 | 'data' => t('No se ha podido calcular el estado de planificación del ente: @ente', |
---|
628 | array( |
---|
629 | '@ente' => $ente_planificador->title |
---|
630 | )), |
---|
631 | 'colspan' => '2', |
---|
632 | 'align' => 'center' |
---|
633 | ); |
---|
634 | $rows[] = $row; |
---|
635 | } |
---|
636 | $output .= theme('table', $header, $rows); |
---|
637 | return $output; |
---|
638 | } |
---|
639 | |
---|
640 | /* |
---|
641 | * usuario_tiene_permisos |
---|
642 | * Verifica si el usuario actual tiene permisos de administracion o editar todos los entes |
---|
643 | */ |
---|
644 | function usuario_tiene_permisos() { |
---|
645 | global $user; |
---|
646 | if ($user->ui == 1 || user_access('edit all planificador') || user_access('admin planificador')) { |
---|
647 | return TRUE; |
---|
648 | } |
---|
649 | return FALSE; |
---|
650 | } |
---|
651 | |
---|
652 | /* |
---|
653 | * ente_planificador_fecha_planificacion_edit_notificacion |
---|
654 | * Permite editar las fechas de notificacion de planificacion |
---|
655 | */ |
---|
656 | function ente_planificador_fecha_planificacion_edit_notificacion($form_state) { |
---|
657 | $procesos_status = ente_planificador_procesos('status'); |
---|
658 | $procesos = ente_planificador_procesos(); |
---|
659 | $procesos_ordenados = ente_planificador_ordena_procesos($procesos_status, $procesos); |
---|
660 | $i = 0; |
---|
661 | $procesos = $procesos_ordenados['normal']; |
---|
662 | $procesos_status = $procesos_ordenados['status']; |
---|
663 | if (is_array($procesos_status) && count($procesos_status)) { |
---|
664 | foreach($procesos_status as $id => $valores) { |
---|
665 | $form[$id] = array( |
---|
666 | '#type' => 'fieldset', |
---|
667 | '#title' => check_plain($valores['title']), |
---|
668 | ); |
---|
669 | if (is_array($procesos[$id]) && count($procesos[$id])) { |
---|
670 | foreach ($procesos[$id] as $type_url_str => $proceso) { |
---|
671 | $FIPMI = variable_get('ente_planificador_' . $type_url_str . "_cron", 0); |
---|
672 | $form[$id][$type_url_str] = array( |
---|
673 | '#type' => 'fieldset', |
---|
674 | '#title' => t('Fecha de %name', array('%name' => $proceso['title'],)), |
---|
675 | ); |
---|
676 | $now = time(); |
---|
677 | $FIPM = $FIPMI ? $FIPMI : $now; |
---|
678 | $FFPM = $FIPMF ? $FIPMF : $now; |
---|
679 | $f1 = explode("-", gmdate("Y-m-d", $FIPM)); |
---|
680 | settype($f1[0], "integer"); |
---|
681 | settype($f1[1], "integer"); |
---|
682 | settype($f1[2], "integer"); |
---|
683 | $form[$id][$type_url_str][$type_url_str] = array( |
---|
684 | '#type' => 'date', |
---|
685 | '#title' => t('Fecha de notificacion'), |
---|
686 | '#default_value' => array( |
---|
687 | 'day' => $f1[2], |
---|
688 | 'month' => $f1[1], |
---|
689 | 'year' => $f1[0], |
---|
690 | ), |
---|
691 | '#description' => t('Seleccione la fecha'), |
---|
692 | ); |
---|
693 | $i++; |
---|
694 | } |
---|
695 | } |
---|
696 | } |
---|
697 | } |
---|
698 | if (!$i) { |
---|
699 | global $user; |
---|
700 | drupal_set_message(t('No existen procesos que planificar')); |
---|
701 | drupal_goto('user/' . $user->uid); |
---|
702 | return array(); |
---|
703 | } |
---|
704 | else { |
---|
705 | $form['submit'] = array( |
---|
706 | '#type' => 'submit', |
---|
707 | '#validate' =>array('ente_planificador_fecha_planificacion_edit_notificacion_validate'), |
---|
708 | '#submit' => array('ente_planificador_fecha_planificacion_edit_notificacion_submit'), |
---|
709 | '#default_value' => t("Guardar"), |
---|
710 | ); |
---|
711 | $enlace = base_path() . 'fechas_planificacion'; |
---|
712 | $form['cancel'] = array( |
---|
713 | '#type' => 'submit', |
---|
714 | '#weight'=>'8615', |
---|
715 | '#attributes' => array('onClick' => 'window.location="' . $enlace . '"; return false;'), |
---|
716 | '#value' => t('Cancel'), |
---|
717 | ); |
---|
718 | return $form; |
---|
719 | } |
---|
720 | } |
---|
721 | |
---|
722 | /* |
---|
723 | * ente_planificador_fecha_planificacion_edit_notificacion_validate |
---|
724 | * Validar la informacion de modificar las fechas de notificacion de planificacion |
---|
725 | */ |
---|
726 | function ente_planificador_fecha_planificacion_edit_notificacion_validate($form, &$form_state){ |
---|
727 | $procesos = ente_planificador_procesos(); |
---|
728 | foreach ($procesos as $key => $proceso) { |
---|
729 | $fn = mktime( |
---|
730 | 0, |
---|
731 | 0, |
---|
732 | 0, |
---|
733 | $form_state['values'][$key]['month'], |
---|
734 | $form_state['values'][$key]['day'], |
---|
735 | $form_state['values'][$key]['year'] |
---|
736 | ); |
---|
737 | $ff = variable_get('ente_planificador_' . $key . "_until", 0); |
---|
738 | if ($ff <= $fn) { |
---|
739 | form_set_error( |
---|
740 | $key, |
---|
741 | t('La fecha de notificación para %name debe ser mayor a la fecha de culminación @ff @fi', array( |
---|
742 | '%name' => $proceso['title'], |
---|
743 | '@ff' => format_date($ff), |
---|
744 | '@fi' => format_date($fn), |
---|
745 | )) |
---|
746 | ); |
---|
747 | } |
---|
748 | } |
---|
749 | } |
---|
750 | |
---|
751 | /* |
---|
752 | * ente_planificador_fecha_planificacion_edit_notificacion_submit |
---|
753 | * Guardar la informacion de modificar las fechas de notificacion de planificacion |
---|
754 | */ |
---|
755 | function ente_planificador_fecha_planificacion_edit_notificacion_submit($form, &$form_state){ |
---|
756 | $procesos = ente_planificador_procesos(); |
---|
757 | foreach ($procesos as $type_url_str => $proceso) { |
---|
758 | $fn = mktime( |
---|
759 | 0, |
---|
760 | 0, |
---|
761 | 0, |
---|
762 | $form_state['values'][$type_url_str]['month'], |
---|
763 | $form_state['values'][$type_url_str]['day'], |
---|
764 | $form_state['values'][$type_url_str]['year'] |
---|
765 | ); |
---|
766 | variable_set('ente_planificador_' . $type_url_str . '_cron', $fn); |
---|
767 | } |
---|
768 | drupal_set_message(t('Se han guardado los cambios')); |
---|
769 | } |
---|
770 | |
---|
771 | /* |
---|
772 | * ente_planificador_fecha_planificacion_edit_todas |
---|
773 | * Permite editar todas las fechas de planificacion |
---|
774 | */ |
---|
775 | function ente_planificador_fecha_planificacion_edit_todas($form_state) { |
---|
776 | $procesos_status = ente_planificador_procesos('status'); |
---|
777 | $procesos = ente_planificador_procesos(); |
---|
778 | $procesos_ordenados = ente_planificador_ordena_procesos($procesos_status, $procesos); |
---|
779 | $i = 0; |
---|
780 | $procesos = $procesos_ordenados['normal']; |
---|
781 | $procesos_status = $procesos_ordenados['status']; |
---|
782 | if (is_array($procesos_status) && count($procesos_status)) { |
---|
783 | foreach($procesos_status as $id => $valores) { |
---|
784 | $form[$id] = array( |
---|
785 | '#type' => 'fieldset', |
---|
786 | '#title' => check_plain($valores['title']), |
---|
787 | ); |
---|
788 | if (is_array($procesos[$id]) && count($procesos[$id])) { |
---|
789 | foreach ($procesos[$id] as $type_url_str => $proceso) { |
---|
790 | $FIPMI = variable_get('ente_planificador_' . $type_url_str . "_from", 0); |
---|
791 | $FIPMF = variable_get('ente_planificador_' . $type_url_str . "_until", 0); |
---|
792 | $form[$id][$type_url_str] = array( |
---|
793 | '#type' => 'fieldset', |
---|
794 | '#title' => t('Fecha de %name', array('%name' => $proceso['title'],)), |
---|
795 | ); |
---|
796 | $now = time(); |
---|
797 | $FIPM = $FIPMI ? $FIPMI : $now; |
---|
798 | $FFPM = $FIPMF ? $FIPMF : $now; |
---|
799 | $f1 = explode("-", gmdate("Y-m-d", $FIPM)); |
---|
800 | settype($f1[0], "integer"); |
---|
801 | settype($f1[1], "integer"); |
---|
802 | settype($f1[2], "integer"); |
---|
803 | $form[$id][$type_url_str][$type_url_str . '_from'] = array( |
---|
804 | '#type' => 'date', |
---|
805 | '#title' => t('Fecha de Inicio'), |
---|
806 | '#default_value' => array( |
---|
807 | 'day' => $f1[2], |
---|
808 | 'month' => $f1[1], |
---|
809 | 'year' => $f1[0], |
---|
810 | ), |
---|
811 | '#description' => t('Seleccione la fecha'), |
---|
812 | ); |
---|
813 | $f1 = explode("-", gmdate("Y-m-d", $FFPM)); |
---|
814 | settype($f1[0], "integer"); |
---|
815 | settype($f1[1], "integer"); |
---|
816 | settype($f1[2], "integer"); |
---|
817 | $form[$id][$type_url_str][$type_url_str . '_until'] = array( |
---|
818 | '#type' => 'date', |
---|
819 | '#title' => t('Fecha de Culminación'), |
---|
820 | '#default_value' => array( |
---|
821 | 'day' => $f1[2], |
---|
822 | 'month' => $f1[1], |
---|
823 | 'year' => $f1[0], |
---|
824 | ), |
---|
825 | '#description' => t('Seleccione la fecha'), |
---|
826 | ); |
---|
827 | $i++; |
---|
828 | } |
---|
829 | } |
---|
830 | } |
---|
831 | } |
---|
832 | if (!$i) { |
---|
833 | global $user; |
---|
834 | drupal_set_message(t('No existen procesos que planificar')); |
---|
835 | drupal_goto('user/' . $user->uid); |
---|
836 | return array(); |
---|
837 | } |
---|
838 | else { |
---|
839 | $form['submit'] = array( |
---|
840 | '#type' => 'submit', |
---|
841 | '#validate' =>array('ente_planificador_fecha_planificacion_edit_todas_validate'), |
---|
842 | '#submit' => array('ente_planificador_fecha_planificacion_edit_todas_submit'), |
---|
843 | '#default_value' => t("Guardar"), |
---|
844 | ); |
---|
845 | $enlace = base_path() . 'fechas_planificacion'; |
---|
846 | $form['cancel'] = array( |
---|
847 | '#type' => 'submit', |
---|
848 | '#weight'=>'8615', |
---|
849 | '#attributes' => array('onClick' => 'window.location="' . $enlace . '"; return false;'), |
---|
850 | '#value' => t('Cancel'), |
---|
851 | ); |
---|
852 | return $form; |
---|
853 | } |
---|
854 | } |
---|
855 | |
---|
856 | /* |
---|
857 | * ente_planificador_fecha_planificacion_edit_todas_validate |
---|
858 | * Validar la informacion de modificar todas las fechas de planificacion |
---|
859 | */ |
---|
860 | function ente_planificador_fecha_planificacion_edit_todas_validate($form, &$form_state){ |
---|
861 | $procesos = ente_planificador_procesos(); |
---|
862 | foreach ($procesos as $key => $proceso) { |
---|
863 | $fi = mktime( |
---|
864 | 0, |
---|
865 | 0, |
---|
866 | 0, |
---|
867 | $form_state['values'][$key . '_from']['month'], |
---|
868 | $form_state['values'][$key . '_from']['day'], |
---|
869 | $form_state['values'][$key . '_from']['year'] |
---|
870 | ); |
---|
871 | $ff = mktime( |
---|
872 | 0, |
---|
873 | 0, |
---|
874 | 0, |
---|
875 | $form_state['values'][$key . '_until']['month'], |
---|
876 | $form_state['values'][$key . '_until']['day'], |
---|
877 | $form_state['values'][$key . '_until']['year'] |
---|
878 | ); |
---|
879 | if ($ff <= $fi) { |
---|
880 | form_set_error( |
---|
881 | $key . '_from', |
---|
882 | t('La fecha de culminación para %name debe ser mayor a la fecha de inicio @ff @fi', array( |
---|
883 | '%name' => $proceso['title'], |
---|
884 | '@ff' => format_date($ff), |
---|
885 | '@fi' => format_date($fi), |
---|
886 | )) |
---|
887 | ); |
---|
888 | } |
---|
889 | } |
---|
890 | } |
---|
891 | |
---|
892 | /* |
---|
893 | * ente_planificador_fecha_planificacion_edit_todas_submit |
---|
894 | * Guardar la informacion de modificar todas las fechas de planificacion |
---|
895 | */ |
---|
896 | function ente_planificador_fecha_planificacion_edit_todas_submit($form, &$form_state){ |
---|
897 | $procesos = ente_planificador_procesos(); |
---|
898 | foreach ($procesos as $type_url_str => $proceso) { |
---|
899 | $fi = mktime( |
---|
900 | 0, |
---|
901 | 0, |
---|
902 | 0, |
---|
903 | $form_state['values'][$type_url_str . '_from']['month'], |
---|
904 | $form_state['values'][$type_url_str . '_from']['day'], |
---|
905 | $form_state['values'][$type_url_str . '_from']['year'] |
---|
906 | ); |
---|
907 | $ff = mktime( |
---|
908 | 0, |
---|
909 | 0, |
---|
910 | 0, |
---|
911 | $form_state['values'][$type_url_str . '_until']['month'], |
---|
912 | $form_state['values'][$type_url_str . '_until']['day'], |
---|
913 | $form_state['values'][$type_url_str . '_until']['year'] |
---|
914 | ); |
---|
915 | variable_set('ente_planificador_' . $type_url_str . '_from', $fi); |
---|
916 | variable_set('ente_planificador_' . $type_url_str . '_until', $ff); |
---|
917 | } |
---|
918 | drupal_set_message(t('Se han guardado los cambios')); |
---|
919 | } |
---|
920 | |
---|
921 | /* |
---|
922 | * Implementation of hook_cron() |
---|
923 | */ |
---|
924 | function ente_planificador_cron() { |
---|
925 | $procesos_cron = array(); |
---|
926 | $now = time(); |
---|
927 | $procesos = ente_planificador_procesos(); |
---|
928 | $cuerpoMi = t("Fechas de Planificación") . "\n"; |
---|
929 | foreach ($procesos as $type_url_str => $name) { |
---|
930 | $FIPMC = variable_get('ente_planificador_' . $type_url_str . "_cron", 0); |
---|
931 | $FIPMI = variable_get('ente_planificador_' . $type_url_str . "_from", 0); |
---|
932 | $FIPMF = variable_get('ente_planificador_' . $type_url_str . "_until", 0); |
---|
933 | if ($FIPMI) { |
---|
934 | $FIPMI = format_date($FIPMI); |
---|
935 | } |
---|
936 | else { |
---|
937 | $FIPMI = t("N/A"); |
---|
938 | } |
---|
939 | if ($FIPMF) { |
---|
940 | $FIPMF = format_date($FIPMF); |
---|
941 | } |
---|
942 | else { |
---|
943 | $FIPMF = t("N/A"); |
---|
944 | } |
---|
945 | $cuerpoMi .= ' ' . t(check_plain($name)) . " : " . t("Fecha de Inicio: ") . $FIPMI . t("Fecha de Culminación: ") . $FFPMF . "\n"; |
---|
946 | if ($FIPMC +3600 < $now && $FIPMC > now) { |
---|
947 | $procesos_cron[] = $type_url_str; |
---|
948 | } |
---|
949 | } |
---|
950 | if (!count($procesos_cron)) { |
---|
951 | return; |
---|
952 | } |
---|
953 | $default_from = variable_get('site_mail', ini_get('sendmail_from')); |
---|
954 | $emails = array(); |
---|
955 | $plan = array(); |
---|
956 | $result = db_query("select u.mail, e.nid from {users} u, {ente_user_planificador} e where e.usuario = u.uid AND status > 1"); |
---|
957 | while($usuarios = db_fetch_object($result)) { |
---|
958 | $emails[$usuarios->nid][] = $usuarios->email; |
---|
959 | } |
---|
960 | foreach($emails as $id => $value) { |
---|
961 | $planificacion = ente_planificador_obtiene_resumen_planificacion($id); |
---|
962 | if ($planificacion['total'] >= 100) { |
---|
963 | unset($emails[$id]); |
---|
964 | } |
---|
965 | else { |
---|
966 | $plan[$id] = $planificacion['total']; |
---|
967 | } |
---|
968 | } |
---|
969 | $cuerpo = t( |
---|
970 | 'Estimado usuario le recordamos que la fecha de planificación para los procesos (@procesos) se encuentra llegando a su fin', |
---|
971 | array( |
---|
972 | '@procesos' => implode(',', $procesos_cron) |
---|
973 | ) |
---|
974 | ) . "\n"; |
---|
975 | foreach($emails as $id => $value) { |
---|
976 | $text_emails = implode(',', $value); |
---|
977 | $cuerpo1 = t('Su ente ha alcanzado hasta la fecha un porcentaje de avance de @avance %', array('@avance' => $plan[$id])) . "\n"; |
---|
978 | $cuerpoF = $cuerpo . $cuerpo1 . $cuerpoMi; |
---|
979 | $message = array( |
---|
980 | 'to' => $text_emails, |
---|
981 | 'subject' => t('Fechas de Planificación'), |
---|
982 | 'body' => $cuerpo1, |
---|
983 | 'headers' => array('From' => $default_from), |
---|
984 | ); |
---|
985 | drupal_mail_send($message); |
---|
986 | } |
---|
987 | drupal_set_message(t("Se han enviado los correo")); |
---|
988 | } |
---|
989 | |
---|
990 | |
---|
991 | /* |
---|
992 | * ente_planificador_fecha_planificacion_correo |
---|
993 | * Enviar correo electronico de las fechas de planificacion |
---|
994 | */ |
---|
995 | function ente_planificador_fecha_planificacion_correo() { |
---|
996 | $result = db_query("select u.mail from {users} u, {ente_user_planificador} e where e.usuario = u.uid AND status > 1"); |
---|
997 | $emails = array(); |
---|
998 | while($usuarios = db_fetch_object($result)) { |
---|
999 | $emails[] = $usuarios->email; |
---|
1000 | } |
---|
1001 | if (!count($emails)) { |
---|
1002 | drupal_goto('fechas_planificacion'); |
---|
1003 | return; |
---|
1004 | } |
---|
1005 | $text_emails = implode(',',$emails); |
---|
1006 | $default_from = variable_get('site_mail', ini_get('sendmail_from')); |
---|
1007 | $cuerpo = t('Estimado usuario a continuación le enviamos las fechas de Inicio y culminación de las distintas etapas de planificación') . "\n"; |
---|
1008 | $cuerpoMi = t("Fechas de Planificación") . "\n"; |
---|
1009 | $procesos = ente_planificador_procesos(); |
---|
1010 | $procesos_status = ente_planificador_procesos('status'); |
---|
1011 | $procesos = ente_planificador_procesos(); |
---|
1012 | $procesos_ordenados = ente_planificador_ordena_procesos($procesos_status, $procesos); |
---|
1013 | $i = 0; |
---|
1014 | $procesos = $procesos_ordenados['normal']; |
---|
1015 | $procesos_status = $procesos_ordenados['status']; |
---|
1016 | if (is_array($procesos_status) && count($procesos_status)) { |
---|
1017 | foreach($procesos_status as $id => $valores) { |
---|
1018 | $cuerpoMi .= t('Etapa') . ' ' . check_plain($valores['title']) . "\n"; |
---|
1019 | if (is_array($procesos[$id]) && count($procesos[$id])) { |
---|
1020 | foreach ($procesos[$id] as $type_url_str => $proceso) { |
---|
1021 | $FIPMI = variable_get('ente_planificador_' . $type_url_str . "_from", 0); |
---|
1022 | $FIPMF = variable_get('ente_planificador_' . $type_url_str . "_until", 0); |
---|
1023 | if ($FIPMI) { |
---|
1024 | $FIPMI = format_date($FIPMI); |
---|
1025 | } |
---|
1026 | else { |
---|
1027 | $FIPMI = t("N/A"); |
---|
1028 | } |
---|
1029 | if ($FIPMF) { |
---|
1030 | $FIPMF = format_date($FIPMF); |
---|
1031 | } |
---|
1032 | else { |
---|
1033 | $FIPMF = t("N/A"); |
---|
1034 | } |
---|
1035 | $cuerpoMi .= ' ' . t(check_plain($proceso['title'])) . " : " . t("Fecha de Inicio: ") . $FIPMI . t("Fecha de Culminación: ") . $FFPMF . "\n"; |
---|
1036 | } |
---|
1037 | } |
---|
1038 | } |
---|
1039 | } |
---|
1040 | $cuerpo .= $cuerpoMi; |
---|
1041 | $message = array( |
---|
1042 | 'to' => $text_emails, |
---|
1043 | 'subject' => t('Fechas de Planificación'), |
---|
1044 | 'body' => $cuerpo, |
---|
1045 | 'headers' => array('From' => $default_from), |
---|
1046 | ); |
---|
1047 | drupal_mail_send($message); |
---|
1048 | drupal_set_message(t("Se ha enviado el correo")); |
---|
1049 | drupal_goto('fechas_planificacion'); |
---|
1050 | } |
---|
1051 | |
---|
1052 | /* |
---|
1053 | * ente_planificador_fecha_planificacion_edit |
---|
1054 | * Editar una fecha de planificacion |
---|
1055 | */ |
---|
1056 | function ente_planificador_fecha_planificacion_edit($type_node = '') { |
---|
1057 | $procesos = ente_planificador_procesos(); |
---|
1058 | if (isset($procesos[$type_node])) { |
---|
1059 | return drupal_get_form('ente_planificador_fecha_planificacion_edit_form', $type_node); |
---|
1060 | } |
---|
1061 | return NULL; |
---|
1062 | } |
---|
1063 | |
---|
1064 | /* |
---|
1065 | * ente_planificador_fecha_planificacion_edit_form |
---|
1066 | * Editar una fecha de planificacion |
---|
1067 | */ |
---|
1068 | function ente_planificador_fecha_planificacion_edit_form($form_state, $type_node = NULL) { |
---|
1069 | $procesos = ente_planificador_procesos(); |
---|
1070 | $tipos_fecha = array( |
---|
1071 | 'from' => t('Inicio'), |
---|
1072 | 'until' => t('Fin'), |
---|
1073 | ); |
---|
1074 | $FIPMI = variable_get('ente_planificador_' . $type_node . "_from", 0); |
---|
1075 | $f1 = explode("-", gmdate("Y-m-d", $FIPMI)); |
---|
1076 | settype($f1[0], "integer"); |
---|
1077 | settype($f1[1], "integer"); |
---|
1078 | settype($f1[2], "integer"); |
---|
1079 | $FIPMF = variable_get('ente_planificador_' . $type_node . "_until", 0); |
---|
1080 | $f2 = explode("-", gmdate("Y-m-d", $FIPMF)); |
---|
1081 | settype($f2[0], "integer"); |
---|
1082 | settype($f2[1], "integer"); |
---|
1083 | settype($f2[2], "integer"); |
---|
1084 | $form = array(); |
---|
1085 | $form['type_page_node'] = array( |
---|
1086 | '#type' => 'hidden', |
---|
1087 | '#default_value' => $type_node, |
---|
1088 | ); |
---|
1089 | $form['from'] = array( |
---|
1090 | '#type' => 'date', |
---|
1091 | '#title' => t('Modificar la fecha de inicio para %name', array('%name' => $procesos[$type_node]['title'])), |
---|
1092 | '#default_value' => array( |
---|
1093 | 'day' => $f1[2], |
---|
1094 | 'month' => $f1[1], |
---|
1095 | 'year' => $f1[0], |
---|
1096 | ), |
---|
1097 | '#description' => t('Seleccione la fecha'), |
---|
1098 | ); |
---|
1099 | $form['until'] = array( |
---|
1100 | '#type' => 'date', |
---|
1101 | '#title' => t('Modificar la fecha de culminación para %name', array('%name' => $procesos[$type_node]['title'])), |
---|
1102 | '#default_value' => array( |
---|
1103 | 'day' => $f2[2], |
---|
1104 | 'month' => $f2[1], |
---|
1105 | 'year' => $f2[0], |
---|
1106 | ), |
---|
1107 | '#description' => t('Seleccione la fecha'), |
---|
1108 | ); |
---|
1109 | $form['submit'] = array( |
---|
1110 | '#type' => 'submit', |
---|
1111 | '#default_value' => t("Guardar"), |
---|
1112 | ); |
---|
1113 | $enlace = base_path() . 'fechas_planificacion'; |
---|
1114 | $form['cancel'] = array( |
---|
1115 | '#type' => 'submit', |
---|
1116 | '#weight'=>'8615', |
---|
1117 | '#attributes' => array('onClick' => 'window.location="' . $enlace . '"; return false;'), |
---|
1118 | '#value' => t('Cancel'), |
---|
1119 | ); |
---|
1120 | return $form; |
---|
1121 | } |
---|
1122 | |
---|
1123 | /* |
---|
1124 | * ente_planificador_fecha_planificacion_edit_form_validate |
---|
1125 | * Validar una fecha de planificacion |
---|
1126 | */ |
---|
1127 | function ente_planificador_fecha_planificacion_edit_form_validate($form, &$form_state) { |
---|
1128 | $key = $form_state['values']['type_page_node']; |
---|
1129 | $procesos = ente_planificador_procesos(); |
---|
1130 | if (isset($procesos[$key])) { |
---|
1131 | $fi = mktime(0, 0, 0, $form_state['values']['from']['month'], $form_state['values']['from']['day'], $form_state['values']['from']['year']); |
---|
1132 | $ff = mktime(0, 0, 0, $form_state['values']['until']['month'], $form_state['values']['until']['day'], $form_state['values']['until']['year']); |
---|
1133 | if ($ff <= $fi) { |
---|
1134 | form_set_error('until', t('La fecha de culminación para %name debe ser mayor a la fecha de inicio @ff @fi', array('%name' => $procesos[$key], '@ff' => format_date($ff), '@fi' => format_date($fi), ))); |
---|
1135 | } |
---|
1136 | } |
---|
1137 | else { |
---|
1138 | form_set_error('until', t('La fecha final para %name debe ser mayor a la inicial @ff @fi', array('%name' => $name, '@ff' => format_date($ff), '@fi' => format_date($fi), ))); |
---|
1139 | drupal_set_message(t("Ocurrio un error al intentar almacenar la fecha")); |
---|
1140 | drupal_goto('fechas_planificacion'); |
---|
1141 | } |
---|
1142 | } |
---|
1143 | |
---|
1144 | /* |
---|
1145 | * ente_planificador_fecha_planificacion_edit_form_submit |
---|
1146 | * Guardar una fecha de planificacion |
---|
1147 | */ |
---|
1148 | function ente_planificador_fecha_planificacion_edit_form_submit($form, &$form_state) { |
---|
1149 | $fi = mktime( |
---|
1150 | 0, |
---|
1151 | 0, |
---|
1152 | 0, |
---|
1153 | $form_state['values']['from']['month'], |
---|
1154 | $form_state['values']['from']['day'], |
---|
1155 | $form_state['values']['from']['year'] |
---|
1156 | ); |
---|
1157 | $ff = mktime( |
---|
1158 | 0, |
---|
1159 | 0, |
---|
1160 | 0, |
---|
1161 | $form_state['values']['until']['month'], |
---|
1162 | $form_state['values']['until']['day'], |
---|
1163 | $form_state['values']['until']['year'] |
---|
1164 | ); |
---|
1165 | $key = $form_state['values']['type_page_node']; |
---|
1166 | $procesos = ente_planificador_procesos(); |
---|
1167 | variable_set('ente_planificador_' . $key . '_from', $fi); |
---|
1168 | variable_set('ente_planificador_' . $key . '_until', $ff); |
---|
1169 | drupal_set_message(t("Actualizadas las fechas para %name", array('%name' => $procesos[$key]['title']))); |
---|
1170 | drupal_goto('fechas_planificacion'); |
---|
1171 | } |
---|
1172 | |
---|
1173 | /* |
---|
1174 | * Implementation of ente_planificador_procesos() |
---|
1175 | * Lista los procesos de la planificacion |
---|
1176 | */ |
---|
1177 | function ente_planificador_procesos($type = 'normal') { |
---|
1178 | $procesos = array(); |
---|
1179 | drupal_alter('ente_procesos', $procesos, $type); |
---|
1180 | return $procesos; |
---|
1181 | } |
---|
1182 | |
---|
1183 | /* |
---|
1184 | * Implementation of ente_planificador_ordena_procesos() |
---|
1185 | * Ordena los procesos por pesos(weight) |
---|
1186 | */ |
---|
1187 | function ente_planificador_ordena_procesos($procesos_status, $procesos) { |
---|
1188 | $nuevo_proceso = array(); |
---|
1189 | $reemplazo = array(); |
---|
1190 | //se añade cada uno de los procesos a su categorÃa con su peso |
---|
1191 | if (is_array($procesos) && count($procesos)) { |
---|
1192 | foreach($procesos as $id => $arreglo) { |
---|
1193 | $nuevo_proceso[$arreglo['proceso']][$arreglo['weight']][$id] = $arreglo; |
---|
1194 | } |
---|
1195 | foreach($nuevo_proceso as $id => $arreglo) { |
---|
1196 | ksort($nuevo_proceso[$id]); |
---|
1197 | } |
---|
1198 | foreach($nuevo_proceso as $id => $valores) { |
---|
1199 | foreach($valores as $valor) { |
---|
1200 | foreach ($valor as $ids => $proceso) { |
---|
1201 | $reemplazo[$id][$ids] = $proceso; |
---|
1202 | } |
---|
1203 | } |
---|
1204 | } |
---|
1205 | } |
---|
1206 | $nuevo_proceso = $reemplazo; |
---|
1207 | $indices = array(); |
---|
1208 | $reemplazo = array(); |
---|
1209 | if (is_array($procesos_status) && count($procesos_status)) { |
---|
1210 | foreach($procesos_status as $id => $arreglo) { |
---|
1211 | $indices[$arreglo['weight']][] = $id; |
---|
1212 | } |
---|
1213 | ksort($indices); |
---|
1214 | foreach($indices as $weight => $valores) { |
---|
1215 | foreach($valores as $valor) { |
---|
1216 | $reemplazo[$valor] = $procesos_status[$valor]; |
---|
1217 | } |
---|
1218 | } |
---|
1219 | } |
---|
1220 | $procesos_status = $reemplazo; |
---|
1221 | return array( |
---|
1222 | 'normal' => $nuevo_proceso, |
---|
1223 | 'status' => $procesos_status, |
---|
1224 | ); |
---|
1225 | } |
---|
1226 | |
---|
1227 | /* |
---|
1228 | * ente_planificador_fecha_planificacion |
---|
1229 | * Mostrar las fechas de planificacion |
---|
1230 | */ |
---|
1231 | function ente_planificador_fecha_planificacion($type = '') { |
---|
1232 | $view = FALSE; |
---|
1233 | if (user_access('admin planificador')) { |
---|
1234 | $view = TRUE; |
---|
1235 | } |
---|
1236 | $header[] = array('data' => t('Name')); |
---|
1237 | $header[] = array('data' => t('Fecha de Inicio')); |
---|
1238 | $header[] = array('data' => t('Fecha de Culminación')); |
---|
1239 | if ($view) { |
---|
1240 | $header[] = array('data' => t('Operación')); |
---|
1241 | } |
---|
1242 | $procesos_status = ente_planificador_procesos('status'); |
---|
1243 | $procesos = ente_planificador_procesos(); |
---|
1244 | $procesos_ordenados = ente_planificador_ordena_procesos($procesos_status, $procesos); |
---|
1245 | $procesos_status = $procesos_ordenados['status']; |
---|
1246 | $nuevo_proceso = $procesos_ordenados['normal']; |
---|
1247 | $rows = array(); |
---|
1248 | $fechas_agregar = TRUE; |
---|
1249 | if (is_array($procesos_status) && count($procesos_status)) { |
---|
1250 | foreach($procesos_status as $id => $valores) { |
---|
1251 | $row = array(); |
---|
1252 | $row[] = array('data' => '<b>' . $procesos_status[$id]['title'] . '</b>', 'colspan' => 4, 'align' => 'center'); |
---|
1253 | $rows[] = $row; |
---|
1254 | if (is_array($nuevo_proceso[$id]) && count($nuevo_proceso[$id])) { |
---|
1255 | foreach ($nuevo_proceso[$id] as $type_url_str => $proceso) { |
---|
1256 | $FIPMI = variable_get('ente_planificador_' . $type_url_str . "_from", 0); |
---|
1257 | $FIPMF = variable_get('ente_planificador_' . $type_url_str . "_until", 0); |
---|
1258 | if ($view) { |
---|
1259 | if ($FIPMI) { |
---|
1260 | $fechas_agregar = FALSE; |
---|
1261 | $FIPMI = format_date($FIPMI); |
---|
1262 | } |
---|
1263 | else { |
---|
1264 | $FIPMI = t("N/A"); |
---|
1265 | } |
---|
1266 | if ($FIPMF) { |
---|
1267 | $fechas_agregar = FALSE; |
---|
1268 | $FIPMF = format_date($FIPMF); |
---|
1269 | } |
---|
1270 | else { |
---|
1271 | $FIPMF = t("N/A"); |
---|
1272 | } |
---|
1273 | } |
---|
1274 | else { |
---|
1275 | if ($FIPMI) { |
---|
1276 | $fechas_agregar = FALSE; |
---|
1277 | $FIPMI = format_date($FIPMI); |
---|
1278 | } |
---|
1279 | else { |
---|
1280 | $FIPMI = t("N/A"); |
---|
1281 | } |
---|
1282 | if ($FIPMF) { |
---|
1283 | $fechas_agregar = FALSE; |
---|
1284 | $FIPMF = format_date($FIPMF); |
---|
1285 | } |
---|
1286 | else { |
---|
1287 | $FIPMF = t("N/A"); |
---|
1288 | } |
---|
1289 | } |
---|
1290 | $row = array(); |
---|
1291 | $row[] = array('data' => t(check_plain($proceso['title'])), ); |
---|
1292 | $row[] = array('data' => $FIPMI, ); |
---|
1293 | $row[] = array('data' => $FIPMF, ); |
---|
1294 | if ($view) { |
---|
1295 | $row[] = array('data' => l(t('Modificar'), 'fechas_planificacion/edit/' . $type_url_str), ); |
---|
1296 | } |
---|
1297 | $rows[] = $row; |
---|
1298 | } |
---|
1299 | } |
---|
1300 | } |
---|
1301 | } |
---|
1302 | $fechas_display = TRUE; |
---|
1303 | if (!count($rows)) { |
---|
1304 | $row = array(); |
---|
1305 | $row[] = array('data' => t('No se encontrarón fechas para planificar'), 'colspan' => 4); |
---|
1306 | $rows[] = $row; |
---|
1307 | $fechas_display = FALSE; |
---|
1308 | } |
---|
1309 | $aux = ""; |
---|
1310 | if (user_access('admin planificador') && $fechas_display) { |
---|
1311 | if ($fechas_agregar) { |
---|
1312 | $aux = l(t("Agregar las fechas para los procesos de planificación."), 'fechas_planificacion/todas_edit'); |
---|
1313 | } |
---|
1314 | $aux .= '<br>' . l(t("Enviar Correo Electrónico a los entes planificadores"), 'fechas_planificacion/envia_email'); |
---|
1315 | $aux .= '<br>' . l(t("Fecha para reportar mensaje de alerta respecto al registro o modificación de información"), 'fechas_planificacion/notificacion'); |
---|
1316 | } |
---|
1317 | return theme('table', $header, $rows).$aux; |
---|
1318 | } |
---|
1319 | |
---|
1320 | /* |
---|
1321 | * ente_planificador_admin_settings |
---|
1322 | * Configurar entes planificadores |
---|
1323 | */ |
---|
1324 | function ente_planificador_admin_settings() { |
---|
1325 | $form = array(); |
---|
1326 | $roles = user_roles(TRUE); |
---|
1327 | unset($roles[2]); |
---|
1328 | if (count($roles)) { |
---|
1329 | $form['ActorPlanificadorMacro'] = array( |
---|
1330 | '#type' => 'select', |
---|
1331 | '#title' => t('Rol para el Actor Macro'), |
---|
1332 | '#default_value' => variable_get('ActorPlanificadorMacro', 2), |
---|
1333 | '#options' => $roles, |
---|
1334 | '#description' => t('Seleccione el rol para el Actor Macro'), |
---|
1335 | ); |
---|
1336 | $form['ActorPlanificadorMicro'] = array( |
---|
1337 | '#type' => 'select', |
---|
1338 | '#title' => t('Rol para el Actor Operativo'), |
---|
1339 | '#default_value' => variable_get('ActorPlanificadorMicro', 2), |
---|
1340 | '#options' => $roles, |
---|
1341 | '#description' => t('Seleccione el rol para el Actor Operativo'), |
---|
1342 | ); |
---|
1343 | return system_settings_form($form); |
---|
1344 | } |
---|
1345 | } |
---|
1346 | |
---|
1347 | /* |
---|
1348 | * entes_planificadores_listar_usuarios |
---|
1349 | * Listar todos los usuarios asociados a entes planificadores |
---|
1350 | */ |
---|
1351 | function entes_planificadores_listar_usuarios() { |
---|
1352 | global $user; |
---|
1353 | $step = 10; |
---|
1354 | $output = ''; |
---|
1355 | $ente = NULL; |
---|
1356 | $Lista_entes = array(); |
---|
1357 | $sqlcount = "select count(u.uid) from {users} u, {ente_user_planificador} up, {node} n where u.uid = up.usuario and up.nid =n.nid"; |
---|
1358 | $sql = "select n.title, n.nid, u.name, u.nombres, u.apellidos, u.cedula, u.uid from {users} u, {ente_user_planificador} up, {node} n where u.uid = up.usuario and up.nid =n.nid"; |
---|
1359 | $headers_table[] = array('data' => t('Nombre de Usuario'), 'sort' => 'asc', 'field' => 'u.name'); |
---|
1360 | $headers_table[] = array('data' => t('Nombres'), 'sort' => 'asc', 'field' => 'u.nombres'); |
---|
1361 | $headers_table[] = array('data' => t('Apellidos'), 'sort' => 'asc', 'field' => 'u.apellidos'); |
---|
1362 | $headers_table[] = array('data' => t('Cédula de Identidad'), 'sort' => 'asc', 'field' => 'u.cedula'); |
---|
1363 | $headers_table[] = array('data' => t('Ente Planificador'), 'sort' => 'asc', 'field' => 'n.title'); |
---|
1364 | $headers_table[] = array('data' => t('Consultar')); |
---|
1365 | $headers_table[] = array('data' => t('Modificar')); |
---|
1366 | $headers_table[] = array('data' => t('Eliminar')); |
---|
1367 | $sql.= tablesort_sql($headers_table); |
---|
1368 | $result = pager_query($sql, $step, 0, $sqlcount,$user->uid); |
---|
1369 | while($ente = db_fetch_object($result)) { |
---|
1370 | $Lista_entes[] = array( |
---|
1371 | 'name'=>l($ente->name, 'user/' . $ente->uid, array('html' => true, 'query' => 'destination=administrar_usuarios')), |
---|
1372 | 'nombres' => l($ente->nombres, 'user/' . $ente->uid, array('html' => true, 'query' => 'destination=administrar_usuarios')), |
---|
1373 | 'apellidos' => l($ente->apellidos, 'user/' . $ente->uid, array('html' => true, 'query' => 'destination=administrar_usuarios')), |
---|
1374 | 'cedula'=>l($ente->cedula, 'user/' . $ente->uid, array('html' => true, 'query' => 'destination=administrar_usuarios')), |
---|
1375 | 'ente' => l($ente->title, 'node/' . $ente->nid, array('html' => true, 'query' => 'destination=administrar_usuarios')), |
---|
1376 | 'consultar' => l(t("Consultar"), 'user/' . $ente->uid, array('html' => true, 'query' => 'destination=administrar_usuarios')), |
---|
1377 | 'modificar' => l(t("Modificar"), 'user/' . $ente->uid . "/edit", array('html' => true, 'query' => 'destination=administrar_usuarios')), |
---|
1378 | 'eliminar' => l(t("Eliminar"), 'user/' . $ente->uid . "/delete", array('html' => true, 'query' => 'destination=administrar_usuarios')), |
---|
1379 | ); |
---|
1380 | } |
---|
1381 | if (sizeof($Lista_entes)) { |
---|
1382 | $output.= theme('table', $headers_table, $Lista_entes); |
---|
1383 | $output .= theme('pager', NULL); |
---|
1384 | } |
---|
1385 | else { |
---|
1386 | $output.= '<p>' . t('No se encontraron usuarios en el sistema') . '</p>'; |
---|
1387 | } |
---|
1388 | return $output; |
---|
1389 | } |
---|
1390 | |
---|
1391 | /* |
---|
1392 | * mis_entes_planificadores |
---|
1393 | * Listar todos los entes planificadores asociados al usuario actual |
---|
1394 | */ |
---|
1395 | function mis_entes_planificadores() { |
---|
1396 | global $user; |
---|
1397 | $step = 10; |
---|
1398 | $output = ''; |
---|
1399 | $ente = usuario_tiene_ente($user->uid); |
---|
1400 | if ($ente->nid) { |
---|
1401 | $ente = ente_planificador_leer($ente->nid); |
---|
1402 | $output .= node_view($ente); |
---|
1403 | $estados = ente_planificador_status_planificacion($ente->nid, $ente->tipo); |
---|
1404 | $header = array(); |
---|
1405 | $header[] = array('data' => t('Etapa')); |
---|
1406 | $header[] = array('data' => t('Estado')); |
---|
1407 | $rows = array(); |
---|
1408 | $total_suma = 0; |
---|
1409 | $total_ejecutado = 0; |
---|
1410 | if (count($estados)) { |
---|
1411 | foreach($estados as $estado) { |
---|
1412 | $row = array(); |
---|
1413 | $row[] = array( |
---|
1414 | 'data' => '<b>' . $estado['title'] . '</b>', |
---|
1415 | 'colspan' => '2', |
---|
1416 | 'align' => 'center' |
---|
1417 | ); |
---|
1418 | $rows[] = $row; |
---|
1419 | $porc = 0; |
---|
1420 | $etapas = count($estado['value']); |
---|
1421 | if ($etapas) { |
---|
1422 | $suma = 0; |
---|
1423 | foreach($estado['value'] as $value) { |
---|
1424 | $total_suma++; |
---|
1425 | $row = array(); |
---|
1426 | $valor = $value['value'] ? t('Si') : t('No'); |
---|
1427 | $row[] = array('data' => l($value['title'], $value['link']),); |
---|
1428 | $row[] = array('data' => $valor,); |
---|
1429 | $rows[] = $row; |
---|
1430 | if ($value['value']) { |
---|
1431 | $suma++; |
---|
1432 | } |
---|
1433 | } |
---|
1434 | $total_ejecutado += $suma; |
---|
1435 | $porc = ($suma * 100) / $etapas; |
---|
1436 | } |
---|
1437 | $row = array(); |
---|
1438 | $row[] = array( |
---|
1439 | 'data' => '<b>' . t('Porcentaje') . '</b>', |
---|
1440 | 'align' => 'right', |
---|
1441 | ); |
---|
1442 | $row[] = array( |
---|
1443 | 'data' => '<b>' . round($porc, 2) . ' %' . '</b>', |
---|
1444 | ); |
---|
1445 | $rows[] = $row; |
---|
1446 | } |
---|
1447 | $total_porcentaje = ($total_suma > 0) ? ($total_ejecutado * 100) / $total_suma : 0; |
---|
1448 | $row = array(); |
---|
1449 | $row[] = array( |
---|
1450 | 'data' => '<b>' . t('Porcentaje Total : ') . round($total_porcentaje, 2) . ' %</b>', |
---|
1451 | 'colspan' => '2', |
---|
1452 | 'align' => 'center', |
---|
1453 | ); |
---|
1454 | $rows[] = $row; |
---|
1455 | } |
---|
1456 | if (!count($rows)) { |
---|
1457 | $row = array(); |
---|
1458 | $row[] = array( |
---|
1459 | 'data' => t('No se ha podido calcular el estado de planificación del ente: @ente', |
---|
1460 | array( |
---|
1461 | '@ente' => $ente_planificador->title |
---|
1462 | ) |
---|
1463 | ), |
---|
1464 | 'colspan' => '2', |
---|
1465 | 'align' => 'center' |
---|
1466 | ); |
---|
1467 | $rows[] = $row; |
---|
1468 | } |
---|
1469 | } |
---|
1470 | $output .= theme('table', $header, $rows); |
---|
1471 | $ente = NULL; |
---|
1472 | $Lista_entes = array(); |
---|
1473 | $sqlcount = "SELECT count(u1.nid) FROM {node} n, {ente_user_planificador} u1 WHERE u1.usuario = %d AND u1.nid = n.nid"; |
---|
1474 | $sql = "SELECT n.title, n.nid FROM {node} n, {ente_user_planificador} u1 WHERE u1.usuario = %d AND u1.nid = n.nid"; |
---|
1475 | $headers_table[] = array( |
---|
1476 | 'data' => t('Ente Planificador'), |
---|
1477 | 'sort' => 'asc', |
---|
1478 | 'field' => 'n.title' |
---|
1479 | ); |
---|
1480 | $headers_table[] = array( |
---|
1481 | 'data' => t('Consultar') |
---|
1482 | ); |
---|
1483 | $headers_table[] = array( |
---|
1484 | 'data' => t('Modificar') |
---|
1485 | ); |
---|
1486 | $sql.= tablesort_sql($headers_table); |
---|
1487 | $result = pager_query($sql, $step, 0, $sqlcount,$user->uid); |
---|
1488 | while($ente = db_fetch_object($result)) { |
---|
1489 | $Lista_entes[] = array( |
---|
1490 | 'ente' => l($ente->title, 'node/' . $ente->nid, array('html' => true, 'query' => 'destination=mienteplanificador')), |
---|
1491 | 'consultar' => l(t("Consultar"), 'node/' . $ente->nid, array('html' => true, 'query' => 'destination=mienteplanificador')), |
---|
1492 | 'modificar' => l(t("Modificar"), 'node/edit/' . $ente->nid, array('html' => true, 'query' => 'destination=mienteplanificador')), |
---|
1493 | ); |
---|
1494 | } |
---|
1495 | if (sizeof($Lista_entes)) { |
---|
1496 | $output.= theme('table', $headers_table, $Lista_entes); |
---|
1497 | $output .= theme('pager', NULL); |
---|
1498 | } |
---|
1499 | else { |
---|
1500 | $output.= '<p>' . t('No se encontraron entes asignados al usuario') . '</p>'; |
---|
1501 | } |
---|
1502 | return $output; |
---|
1503 | } |
---|
1504 | |
---|
1505 | /* |
---|
1506 | * entes_planificadores_agregar |
---|
1507 | * Agregar un ente planificador |
---|
1508 | */ |
---|
1509 | function entes_planificadores_agregar() { |
---|
1510 | drupal_goto('node/add/ente-planificador' , 'destination=administrar/entes_planificadores'); |
---|
1511 | } |
---|
1512 | |
---|
1513 | /* |
---|
1514 | * entes_planificadores_obtener_filtros |
---|
1515 | * Generar filtros |
---|
1516 | */ |
---|
1517 | function entes_planificadores_obtener_filtros($filtro = array()) { |
---|
1518 | $filters['nombre'] = array( |
---|
1519 | '#type' => 'textfield', |
---|
1520 | '#title' => t('Nombre'), |
---|
1521 | '#size' => 20, |
---|
1522 | ); |
---|
1523 | $filters['razon_social'] = array( |
---|
1524 | '#type' => 'textfield', |
---|
1525 | '#title' => t('Razón Social'), |
---|
1526 | '#size' => 20, |
---|
1527 | ); |
---|
1528 | $filters['rif'] = array( |
---|
1529 | '#type' => 'textfield', |
---|
1530 | '#title' => t('RIF'), |
---|
1531 | '#size' => 20, |
---|
1532 | '#maxlength' => 12, |
---|
1533 | ); |
---|
1534 | $filters['direccion'] = array( |
---|
1535 | '#type' => 'textfield', |
---|
1536 | '#title' => t('Dirección'), |
---|
1537 | '#size' => 20, |
---|
1538 | '#maxlength' => 243, |
---|
1539 | ); |
---|
1540 | $filters['ciudad'] = array( |
---|
1541 | '#type' => 'textfield', |
---|
1542 | '#title' => t('Ciudad'), |
---|
1543 | '#size' => 20, |
---|
1544 | '#maxlength' => 243, |
---|
1545 | ); |
---|
1546 | //Se buscan las entidades |
---|
1547 | $entidades = ente_planificador_obtener_lista_entidad(); |
---|
1548 | $estado = "01"; |
---|
1549 | if ($filtro['estado']) { |
---|
1550 | $estado = $filtro['estado']; |
---|
1551 | } |
---|
1552 | $filters['estado'] = array( |
---|
1553 | '#type' => 'select', |
---|
1554 | '#title' => t('Estado').$form['estado'], |
---|
1555 | '#options' => $entidades, |
---|
1556 | '#ahah' => array( |
---|
1557 | 'event' => 'change', |
---|
1558 | 'path' => 'ente_planificador_js_util/municipio_select', |
---|
1559 | 'wrapper' => 'edit-municipio-wrapper', |
---|
1560 | 'method' => 'replace', |
---|
1561 | ), |
---|
1562 | ); |
---|
1563 | $municipio = $filtro['municipio']; |
---|
1564 | $parroquia = $filtro['parroquia']; |
---|
1565 | $filters['municipio'] = ente_planificador_obtener_form_municipio( |
---|
1566 | t('Municipio'), |
---|
1567 | $municipio, |
---|
1568 | t('seleccione el municipio.'), |
---|
1569 | $estado, |
---|
1570 | $display = 'name', |
---|
1571 | TRUE |
---|
1572 | ); |
---|
1573 | $filters['parroquia'] = ente_planificador_obtener_form_parroquia(t('Parroquia'), $parroquia, t('seleccione la parroquia.'), $municipio, TRUE); |
---|
1574 | $filters['municipio']['#required'] = FALSE; |
---|
1575 | $filters['parroquia']['#required'] = FALSE; |
---|
1576 | //Se buscan las actividades |
---|
1577 | $actividades = ente_planificador_obtener_actividades(); |
---|
1578 | $filters['actividad'] = array( |
---|
1579 | '#type' => 'select', |
---|
1580 | '#title' => t('Actividades'), |
---|
1581 | '#default_value' => $ente_planificador->actividad, |
---|
1582 | '#options' => $actividades, |
---|
1583 | '#description' => t('Seleccione una actividad.'), |
---|
1584 | ); |
---|
1585 | return $filters; |
---|
1586 | } |
---|
1587 | |
---|
1588 | /* |
---|
1589 | * ente_planificador_datos_basicos |
---|
1590 | * Obtener formulario de los datos basicos |
---|
1591 | */ |
---|
1592 | function ente_planificador_datos_basicos($nid = '') { |
---|
1593 | $output = ''; |
---|
1594 | $output .= drupal_get_form('ente_planificador_datos_basicos_forma', $nid); |
---|
1595 | return $output; |
---|
1596 | } |
---|
1597 | |
---|
1598 | /* |
---|
1599 | * ente_planificador_datos_basicos_forma |
---|
1600 | * Obtener formulario de los datos basicos |
---|
1601 | */ |
---|
1602 | function ente_planificador_datos_basicos_forma(&$form_state, $nid = NULL) { |
---|
1603 | $ente_planificador = NULL; |
---|
1604 | if (is_numeric($nid)) { |
---|
1605 | $ente_planificador = node_load($nid); |
---|
1606 | } |
---|
1607 | $form = array(); |
---|
1608 | if ($ente_planificador) { |
---|
1609 | $form['ente_planificador_nid'] = array( |
---|
1610 | '#type' => 'hidden', |
---|
1611 | '#default_value' => $ente_planificador->nid, |
---|
1612 | ); |
---|
1613 | $form['razon_social'] = array( |
---|
1614 | '#type' => 'textfield', |
---|
1615 | '#title' => t('Razón Social'), |
---|
1616 | '#default_value' => $ente_planificador->razon_social, |
---|
1617 | '#size' => 20, |
---|
1618 | '#description' => t("Introduzca la Razón Social"), |
---|
1619 | '#required' => TRUE, |
---|
1620 | ); |
---|
1621 | $form['rif'] = array( |
---|
1622 | '#type' => 'textfield', |
---|
1623 | '#title' => t('RIF'), |
---|
1624 | '#default_value' => $ente_planificador->rif, |
---|
1625 | '#size' => 20, |
---|
1626 | '#maxlength' => 12, |
---|
1627 | '#description' => t("Introduzca el RIF"), |
---|
1628 | '#required' => TRUE, |
---|
1629 | ); |
---|
1630 | $form['direccion'] = array( |
---|
1631 | '#type' => 'textfield', |
---|
1632 | '#title' => t('Dirección'), |
---|
1633 | '#default_value' => $ente_planificador->direccion, |
---|
1634 | '#size' => 20, |
---|
1635 | '#maxlength' => 243, |
---|
1636 | '#description' => t("Introduzca la dirección"), |
---|
1637 | '#required' => TRUE, |
---|
1638 | ); |
---|
1639 | $form['ciudad'] = array( |
---|
1640 | '#type' => 'textfield', |
---|
1641 | '#title' => t('Ciudad'), |
---|
1642 | '#default_value' => $ente_planificador->ciudad, |
---|
1643 | '#size' => 20, |
---|
1644 | '#maxlength' => 243, |
---|
1645 | '#description' => t("Introduzca la ciudad"), |
---|
1646 | '#required' => TRUE, |
---|
1647 | ); |
---|
1648 | //Se buscan las entidades |
---|
1649 | $entidades = ente_planificador_obtener_lista_entidad(); |
---|
1650 | if ($ente_planificador->estado) { |
---|
1651 | $estado = $ente_planificador->estado; |
---|
1652 | } |
---|
1653 | else { |
---|
1654 | $estado = '01'; |
---|
1655 | } |
---|
1656 | $form['estado'] = array( |
---|
1657 | '#type' => 'select', |
---|
1658 | '#title' => t('Estado').$form['estado'], |
---|
1659 | '#default_value' => $estado, |
---|
1660 | '#options' => $entidades, |
---|
1661 | '#description' => t('seleccione el estado.'), |
---|
1662 | '#required' => TRUE, |
---|
1663 | '#ahah' => array( |
---|
1664 | 'event' => 'change', |
---|
1665 | 'path' => 'ente_planificador_js_util/municipio_select', |
---|
1666 | 'wrapper' => 'edit-municipio-wrapper', |
---|
1667 | 'method' => 'replace', |
---|
1668 | ), |
---|
1669 | ); |
---|
1670 | if (!$ente_planificador->municipio) { |
---|
1671 | $municipio = '0101'; |
---|
1672 | } |
---|
1673 | else { |
---|
1674 | $municipio = $ente_planificador->municipio; |
---|
1675 | } |
---|
1676 | $form['municipio'] = ente_planificador_obtener_form_municipio(t('Municipio'), $ente_planificador->municipio, t('seleccione el municipio.'), $estado, $display = 'name', TRUE); |
---|
1677 | $form['parroquia'] = ente_planificador_obtener_form_parroquia(t('Parroquia'), $ente_planificador->parroquia, t('seleccione la parroquia.'), $ente_planificador->municipio, name, TRUE); |
---|
1678 | $node_type = content_types('ente_planificador'); |
---|
1679 | $fields = $node_type['fields']; |
---|
1680 | $field_form = array(); |
---|
1681 | if (is_array($fields) && count($fields)) { |
---|
1682 | foreach($fields as $field_id => $field) { |
---|
1683 | if (variable_get('ente_planificador_' . $field_id, FALSE)) { |
---|
1684 | $field_form[] = $field_id; |
---|
1685 | } |
---|
1686 | } |
---|
1687 | } |
---|
1688 | $form['#ente_planificador_fields_datos'] = $field_form; |
---|
1689 | if (is_array($field_form) && count($field_form)) { |
---|
1690 | module_load_include('inc', 'content', 'includes/content.node_form'); |
---|
1691 | $form['#node'] = $ente_planificador; |
---|
1692 | foreach ($field_form as $field_id) { |
---|
1693 | $field = content_fields($field_id, 'ente_planificador'); |
---|
1694 | $form['#field_info'][$field_id] = $field; |
---|
1695 | $form += (array) content_field_form($form, $form_state, $field); |
---|
1696 | } |
---|
1697 | } |
---|
1698 | //Se buscan las actividades |
---|
1699 | $actividades = ente_planificador_obtener_actividades(); |
---|
1700 | $form['actividad'] = array( |
---|
1701 | '#type' => 'select', |
---|
1702 | '#title' => t('Actividades'), |
---|
1703 | '#default_value' => $ente_planificador->actividad, |
---|
1704 | '#options' => $actividades, |
---|
1705 | '#description' => t('Seleccione una actividad.'), |
---|
1706 | '#multiple' => TRUE, |
---|
1707 | '#required' => TRUE, |
---|
1708 | ); |
---|
1709 | //add taxonomy if exist |
---|
1710 | if (module_exists('taxonomy')) { |
---|
1711 | if (!isset($ente_planificador->taxonomy)) { |
---|
1712 | $terms = empty($ente_planificador->nid) ? array() : taxonomy_node_get_terms($ente_planificador); |
---|
1713 | } |
---|
1714 | else { |
---|
1715 | // After a preview or form reload, the terms must be converted to objects. |
---|
1716 | reset($ente_planificador->taxonomy); |
---|
1717 | if (!is_object(current($ente_planificador->taxonomy))) { |
---|
1718 | $ente_planificador->taxonomy = taxonomy_preview_terms($ente_planificador); |
---|
1719 | } |
---|
1720 | $terms = $ente_planificador->taxonomy; |
---|
1721 | } |
---|
1722 | $c = db_query(db_rewrite_sql("SELECT v.* FROM {vocabulary} v INNER JOIN {vocabulary_node_types} n ON v.vid = n.vid WHERE n.type = '%s' ORDER BY v.weight, v.name", 'v', 'vid'), $ente_planificador->type); |
---|
1723 | while ($vocabulary = db_fetch_object($c)) { |
---|
1724 | if ($vocabulary->tags) { |
---|
1725 | if (isset($form_state['node_preview'])) { |
---|
1726 | // Typed string can be changed by the user before preview, |
---|
1727 | // so we just insert the tags directly as provided in the form. |
---|
1728 | $typed_string = $ente_planificador->taxonomy['tags'][$vocabulary->vid]; |
---|
1729 | } |
---|
1730 | else { |
---|
1731 | $typed_string = taxonomy_implode_tags($terms, $vocabulary->vid) . (array_key_exists('tags', $terms) ? $terms['tags'][$vocabulary->vid] : NULL); |
---|
1732 | } |
---|
1733 | if ($vocabulary->help) { |
---|
1734 | $help = filter_xss_admin($vocabulary->help); |
---|
1735 | } |
---|
1736 | else { |
---|
1737 | $help = t('A comma-separated list of terms describing this content. Example: funny, bungee jumping, "Company, Inc.".'); |
---|
1738 | } |
---|
1739 | $form['taxonomy']['tags'][$vocabulary->vid] = array('#type' => 'textfield', |
---|
1740 | '#title' => $vocabulary->name, |
---|
1741 | '#description' => $help, |
---|
1742 | '#required' => $vocabulary->required, |
---|
1743 | '#default_value' => $typed_string, |
---|
1744 | '#autocomplete_path' => 'taxonomy/autocomplete/'. $vocabulary->vid, |
---|
1745 | '#weight' => $vocabulary->weight, |
---|
1746 | '#maxlength' => 1024, |
---|
1747 | ); |
---|
1748 | } |
---|
1749 | else { |
---|
1750 | // Extract terms belonging to the vocabulary in question. |
---|
1751 | $default_terms = array(); |
---|
1752 | foreach ($terms as $term) { |
---|
1753 | // Free tagging has no default terms and also no vid after preview. |
---|
1754 | if (isset($term->vid) && $term->vid == $vocabulary->vid) { |
---|
1755 | $default_terms[$term->tid] = $term; |
---|
1756 | } |
---|
1757 | } |
---|
1758 | $form['taxonomy'][$vocabulary->vid] = taxonomy_form($vocabulary->vid, array_keys($default_terms), filter_xss_admin($vocabulary->help)); |
---|
1759 | $form['taxonomy'][$vocabulary->vid]['#weight'] = $vocabulary->weight; |
---|
1760 | $form['taxonomy'][$vocabulary->vid]['#required'] = $vocabulary->required; |
---|
1761 | } |
---|
1762 | } |
---|
1763 | if (!empty($form['taxonomy']) && is_array($form['taxonomy'])) { |
---|
1764 | if (count($form['taxonomy']) > 1) { |
---|
1765 | // Add fieldset only if form has more than 1 element. |
---|
1766 | $form['taxonomy'] += array( |
---|
1767 | '#type' => 'fieldset', |
---|
1768 | '#title' => t('Vocabularies'), |
---|
1769 | '#collapsible' => TRUE, |
---|
1770 | '#collapsed' => FALSE, |
---|
1771 | ); |
---|
1772 | } |
---|
1773 | $form['taxonomy']['#weight'] = 8; |
---|
1774 | $form['taxonomy']['#tree'] = TRUE; |
---|
1775 | } |
---|
1776 | } |
---|
1777 | $form['buttons']['#weight'] = 100; |
---|
1778 | $form['buttons']['submit'] = array( |
---|
1779 | '#type' => 'submit', |
---|
1780 | '#default_value' => t("Agregar los datos basicos del ente"), |
---|
1781 | '#weight' => 100, |
---|
1782 | ); |
---|
1783 | } |
---|
1784 | if ($ente_planificador) { |
---|
1785 | $enlace = base_path() . 'node/' . $ente_planificador->nid; |
---|
1786 | } |
---|
1787 | else { |
---|
1788 | $enlace = base_path() . 'administrar/entes_planificadores'; |
---|
1789 | } |
---|
1790 | return $form; |
---|
1791 | } |
---|
1792 | |
---|
1793 | /* |
---|
1794 | * ente_planificador_datos_basicos_forma |
---|
1795 | * Validar formulario de los datos basicos |
---|
1796 | */ |
---|
1797 | function ente_planificador_datos_basicos_forma_validate($form, &$form_state) { |
---|
1798 | $form_values = $form_state['values']; |
---|
1799 | if (!preg_match("/^(V|E|P|J|G){1}-([0-9]){8}-([0-9]){1}$/",$form_values['rif']) && !preg_match("/^(V|E){1}-([0-9]){8}$/",$form_values['rif'])) { |
---|
1800 | form_set_error('rif', t('El formato del rif debe tener el siguiente formato G-00000000-0.')); |
---|
1801 | } |
---|
1802 | if (!($form_values['municipio'] > 0)) { |
---|
1803 | form_set_error('municipio', t('Debe seleccionar un municipio.')); |
---|
1804 | } |
---|
1805 | if (!($form_values['parroquia'] > 0)) { |
---|
1806 | form_set_error('parroquia', t('Debe seleccionar una parroquia.')); |
---|
1807 | } |
---|
1808 | } |
---|
1809 | |
---|
1810 | /* |
---|
1811 | * ente_planificador_datos_basicos_forma_submit |
---|
1812 | * Guardar formulario de los datos basicos |
---|
1813 | */ |
---|
1814 | function ente_planificador_datos_basicos_forma_submit($form, &$form_state) { |
---|
1815 | $form_values = $form_state['values']; |
---|
1816 | $resultado1 =db_query("select nid from {ente_planificador} where nid = %d", $form_values['ente_planificador_nid']); |
---|
1817 | $entes = db_fetch_object($resultado1); |
---|
1818 | if ($entes->nid) { |
---|
1819 | $result = db_query("update {ente_planificador} set razon_social = '%s', rif = '%s', direccion = '%s', estado = %d, municipio = %d, parroquia = %d, ciudad = '%s' where nid = %d",$form_values['razon_social'], $form_values['rif'], $form_values['direccion'], $form_values['estado'], $form_values['municipio'], $form_values['parroquia'], $form_values['ciudad'], $form_values['ente_planificador_nid']); |
---|
1820 | } |
---|
1821 | else { |
---|
1822 | $result = db_query("INSERT INTO {ente_planificador} (nid, razon_social, rif, direccion, estado, municipio, parroquia, ciudad) VALUES (%d,'%s', '%s', '%s', %d, %d, %d, '%s', '%s')", $form_values['ente_planificador_nid'], $form_values['razon_social'], $form_values['rif'], $form_values['direccion'], $form_values['estado'], $form_values['municipio'], $form_values['parroquia'], $form_values['ciudad']); |
---|
1823 | } |
---|
1824 | $result = db_query("delete from {ente_actividad_ente} where nid = %d", $form_values['ente_planificador_nid']); |
---|
1825 | $cant = count($form_values['actividad']); |
---|
1826 | if ($cant) { |
---|
1827 | foreach ($form_values['actividad'] as $actividad) { |
---|
1828 | if ($actividad) { |
---|
1829 | db_query("insert into {ente_actividad_ente} (nid, actividad) values (%d, %d)", $form_values['ente_planificador_nid'], $actividad); |
---|
1830 | } |
---|
1831 | } |
---|
1832 | } |
---|
1833 | //add extra cck fields |
---|
1834 | $field_form = $form['#ente_planificador_fields_datos']; |
---|
1835 | module_load_include('inc', 'node', 'node.pages'); |
---|
1836 | node_object_prepare($node_load); |
---|
1837 | $node_load = node_load($form_values['ente_planificador_nid']); |
---|
1838 | if (isset($form_state['values']['taxonomy'])) { |
---|
1839 | $node_load->taxonomy = $form_state['values']['taxonomy']; |
---|
1840 | } |
---|
1841 | if (is_array($field_form) && count($field_form)) { |
---|
1842 | foreach ($field_form as $field_id) { |
---|
1843 | if (isset($form_state['values'][$field_id]) && is_array($form_state['values'][$field_id])) { |
---|
1844 | foreach($form_state['values'][$field_id] as $id => $value) { |
---|
1845 | if (is_numeric($id) && isset($form_state['values'][$field_id][$id]['_error_element'])) { |
---|
1846 | unset($form_state['values'][$field_id][$id]['_error_element']); |
---|
1847 | } |
---|
1848 | } |
---|
1849 | $node_load->{$field_id} = $form_state['values'][$field_id]; |
---|
1850 | } |
---|
1851 | } |
---|
1852 | } |
---|
1853 | $node_load->log = t('Modificados los datos del actor planificador'); |
---|
1854 | $node_load->revision = 1; |
---|
1855 | node_save($node_load); |
---|
1856 | drupal_set_message(t("Se agrego la información de datos basicos")); |
---|
1857 | drupal_goto('node/' . $form_values['ente_planificador_nid']); |
---|
1858 | } |
---|
1859 | |
---|
1860 | /* |
---|
1861 | * nodo_es_ente_planificador |
---|
1862 | * identifica si el nodo es ente planificador |
---|
1863 | */ |
---|
1864 | function nodo_es_ente_planificador($nid = 0) { |
---|
1865 | global $user; |
---|
1866 | if ((user_access('edit all planificador')) || (user_access('admin planificador')) || (user_access('edit own planificador'))) { |
---|
1867 | if (is_numeric($nid)) { |
---|
1868 | $ente_planificador = node_load($nid); |
---|
1869 | if ($ente_planificador->type == "ente_planificador") { |
---|
1870 | if ((user_access('edit all planificador')) || (user_access('admin planificador'))) { |
---|
1871 | return TRUE; |
---|
1872 | } |
---|
1873 | if ((user_access('edit own planificador'))) { |
---|
1874 | if (!$ente_planificador->usuarios[$user->uid]) { |
---|
1875 | return FALSE; |
---|
1876 | } |
---|
1877 | } |
---|
1878 | return TRUE; |
---|
1879 | } |
---|
1880 | } |
---|
1881 | } |
---|
1882 | return FALSE; |
---|
1883 | } |
---|
1884 | |
---|
1885 | /* |
---|
1886 | * entes_planificadores |
---|
1887 | * Listar entes planificador |
---|
1888 | */ |
---|
1889 | function entes_planificadores() { |
---|
1890 | $output = ''; |
---|
1891 | $step = 10; |
---|
1892 | $sqlcount = "SELECT count(n.nid) from {node} n, {node_revisions} rv where n.vid = rv.vid AND (n.type in ('ente_planificador')) AND (n.status <> 0)"; |
---|
1893 | $sql = "SELECT n.nid as nid, n.title as title from {node} n, {node_revisions} rv where n.vid = rv.vid AND (n.type in ('ente_planificador')) AND (n.status <> 0)"; |
---|
1894 | $headers_table[] = array('data' => t('Ente Planificador'), 'sort' => 'asc', 'field' => 'n.title'); |
---|
1895 | if ((user_access('edit all planificador'))||(user_access('admin planificador'))) { |
---|
1896 | $headers_table[] = array('data' => t('Usuarios')); |
---|
1897 | $headers_table[] = array('data' => t('Modificar')); |
---|
1898 | $headers_table[] = array('data' => t('Datos Basicos')); |
---|
1899 | $headers_table[] = array('data' => t('eliminar')); |
---|
1900 | } |
---|
1901 | $sql.= tablesort_sql($headers_table); |
---|
1902 | $result = pager_query($sql, $step, 0, $sqlcount); |
---|
1903 | while($entes = db_fetch_object($result)) { |
---|
1904 | $arregloente['title'] = l($entes->title, 'node/' . $entes->nid); |
---|
1905 | if ((user_access('edit all planificador')) || (user_access('admin planificador'))) { |
---|
1906 | $arregloente['usuarios'] = l(t('Agregar usuarios al actor planificador'), 'admin/user/user/create/' . $entes->nid); |
---|
1907 | $arregloente['editar'] = l(t('Modificar'), 'node/' . $entes->nid.'/edit', array('html' => true, 'query' => 'destination=administrar/entes_planificadores')); |
---|
1908 | $arregloente['datos_basicos'] = l(t('Editar datos del actor planificador'), 'node/' . $entes->nid . '/datos_basicos', array('html' => true, 'query' => 'destination=administrar/entes_planificadores')); |
---|
1909 | $arregloente['eliminar'] = l(t('Eliminar'), 'node/' . $entes->nid.'/delete', array('html' => true, 'query' => 'destination=administrar/entes_planificadores')); |
---|
1910 | } |
---|
1911 | $Lista_entes[] = $arregloente; |
---|
1912 | unset($arregloente); |
---|
1913 | } |
---|
1914 | if (sizeof($Lista_entes)) { |
---|
1915 | $output.= theme('table', $headers_table, $Lista_entes); |
---|
1916 | $output .= theme('pager', NULL); |
---|
1917 | } |
---|
1918 | else { |
---|
1919 | $output.= '<p>' . t('No se encontraron entes planificadores registrados en el sistema') . '</p>'; |
---|
1920 | } |
---|
1921 | return $output; |
---|
1922 | } |
---|
1923 | |
---|
1924 | /* |
---|
1925 | * ente_planificador_js_util |
---|
1926 | * Genera las repuestas ajax de municipios y parroquias |
---|
1927 | */ |
---|
1928 | function ente_planificador_js_util($func) { |
---|
1929 | switch ($func) { |
---|
1930 | case 'municipio_select': |
---|
1931 | $entidad_id = intval($_POST['estado']) > 0 ? intval($_POST['estado']) : 0; |
---|
1932 | if ($entidad_id<10) { |
---|
1933 | $entidad_id = "0" . $entidad_id; |
---|
1934 | } |
---|
1935 | $title = isset($_POST['title']) ? check_plain($_POST['title']) : NULL; |
---|
1936 | $display = isset($_POST['display']) ? check_plain($_POST['display']) : 'name'; |
---|
1937 | $select = ente_planificador_obtener_form_municipio(t('Municipio'), NULL, t('seleccione el municipio.'), $entidad_id, 'name', TRUE); |
---|
1938 | $output = ahah_render($select, 'municipio'); |
---|
1939 | print drupal_to_js(array('data' => $output, 'status' => true)); |
---|
1940 | exit(); |
---|
1941 | break; |
---|
1942 | case 'parroquia_select': |
---|
1943 | $muncipio_id = intval($_POST['municipio']) > 0 ? intval($_POST['municipio']) : 0; |
---|
1944 | if ($muncipio_id<1000) { |
---|
1945 | $muncipio_id = "0" . $muncipio_id; |
---|
1946 | } |
---|
1947 | $title = isset($_POST['title']) ? check_plain($_POST['title']) : NULL; |
---|
1948 | $display = isset($_POST['display']) ? check_plain($_POST['display']) : 'name'; |
---|
1949 | $select = ente_planificador_obtener_form_parroquia(t('Parroquia'), NULL, t('seleccione la parroquia.'), $muncipio_id, 'name', TRUE); |
---|
1950 | $output = ahah_render($select, 'parroquia'); |
---|
1951 | print drupal_to_js(array('data' => $output, 'status' => true)); |
---|
1952 | exit(); |
---|
1953 | } |
---|
1954 | print $output; |
---|
1955 | exit(); |
---|
1956 | } |
---|
1957 | |
---|
1958 | /** |
---|
1959 | * ahah_render... |
---|
1960 | */ |
---|
1961 | function ahah_render($fields, $name) { |
---|
1962 | $form_state = array('submitted' => FALSE); |
---|
1963 | $form_build_id = $_POST['form_build_id']; |
---|
1964 | // Add the new element to the stored form. Without adding the element to the |
---|
1965 | // form, Drupal is not aware of this new elements existence and will not |
---|
1966 | // process it. We retreive the cached form, add the element, and resave. |
---|
1967 | $form = form_get_cache($form_build_id, $form_state); |
---|
1968 | $form[$name] = $fields; |
---|
1969 | form_set_cache($form_build_id, $form, $form_state); |
---|
1970 | $form += array( |
---|
1971 | '#post' => $_POST, |
---|
1972 | '#programmed' => FALSE, |
---|
1973 | ); |
---|
1974 | // Rebuild the form. |
---|
1975 | $form = form_builder($_POST['form_id'], $form, $form_state); |
---|
1976 | // Render the new output. |
---|
1977 | $new_form = $form[$name]; |
---|
1978 | return drupal_render($new_form); |
---|
1979 | } |
---|
1980 | |
---|
1981 | /* |
---|
1982 | * usuario_tiene_ente |
---|
1983 | * retorna los entes que tiene un usuario |
---|
1984 | */ |
---|
1985 | function usuario_tiene_ente($uid) { |
---|
1986 | $ente = db_fetch_object(db_query("SELECT n.title, n.nid FROM {node} n, {ente_user_planificador} u1 WHERE u1.usuario = %d AND u1.nid = n.nid", $uid)); |
---|
1987 | return $ente; |
---|
1988 | } |
---|
1989 | |
---|
1990 | /* |
---|
1991 | * Implementation of hook_perm |
---|
1992 | */ |
---|
1993 | function ente_planificador_perm() { |
---|
1994 | return array( |
---|
1995 | 'ver planificador', |
---|
1996 | 'edit own planificador', |
---|
1997 | 'edit all planificador', |
---|
1998 | 'admin planificador', |
---|
1999 | ); |
---|
2000 | } |
---|
2001 | |
---|
2002 | /* |
---|
2003 | * Implementation of hook_node_info |
---|
2004 | */ |
---|
2005 | function ente_planificador_node_info() { |
---|
2006 | return array( |
---|
2007 | 'ente_planificador' => array( |
---|
2008 | 'name' => t('Ente Planificador'), |
---|
2009 | 'description' => t('Ente Planificador'), |
---|
2010 | 'has_body' => FALSE, |
---|
2011 | 'has_title' => TRUE, |
---|
2012 | 'module' => 'ente_planificador', |
---|
2013 | ), |
---|
2014 | ); |
---|
2015 | } |
---|
2016 | |
---|
2017 | /* |
---|
2018 | * Implementation of hook_node_load |
---|
2019 | */ |
---|
2020 | function ente_planificador_load($node) { |
---|
2021 | $additions = db_fetch_object(db_query('SELECT * FROM {ente_planificador} WHERE nid = %d', $node->nid)); |
---|
2022 | //se obtienen los usuarios del ente planificador |
---|
2023 | if ($additions->estado && $additions->estado < 10) { |
---|
2024 | $additions->estado = '0' . $additions->estado; |
---|
2025 | } |
---|
2026 | if ($additions->municipio && $additions->municipio < 1000) { |
---|
2027 | $additions->municipio = '0' . $additions->municipio; |
---|
2028 | } |
---|
2029 | if ($additions->parroquia && $additions->parroquia < 100000) { |
---|
2030 | $additions->parroquia = '0' . $additions->parroquia; |
---|
2031 | } |
---|
2032 | $array_usuario = array(); |
---|
2033 | $additions1 = db_query('SELECT p.usuario, u.mail FROM {ente_user_planificador} p, {users} u WHERE nid = %d and p.usuario = u.uid', $node->nid); |
---|
2034 | while ($usuarios = db_fetch_object($additions1)) { |
---|
2035 | $array_usuario[$usuarios->usuario] = $usuarios->mail; |
---|
2036 | } |
---|
2037 | $array_actividades = array(); |
---|
2038 | $additions1 = db_query('SELECT actividad FROM {ente_actividad_ente} WHERE nid = %d', $node->nid); |
---|
2039 | while ($actividad = db_fetch_object($additions1)) { |
---|
2040 | $array_actividades[] = $actividad->actividad; |
---|
2041 | } |
---|
2042 | $additions->usuarios = $array_usuario; |
---|
2043 | $additions->actividad = $array_actividades; |
---|
2044 | return $additions; |
---|
2045 | } |
---|
2046 | |
---|
2047 | /* |
---|
2048 | * Implementation of hook_form |
---|
2049 | */ |
---|
2050 | function ente_planificador_form(&$node, $form_state) { |
---|
2051 | $form = array(); |
---|
2052 | $form['title'] = array( |
---|
2053 | '#type' => 'textfield', |
---|
2054 | '#title' => t('Nombre del ente planificador'), |
---|
2055 | '#default_value' => $node->title, |
---|
2056 | '#size' => 20, |
---|
2057 | '#description' => t("Introduzca el nombre del ente planificador"), |
---|
2058 | '#required' => TRUE, |
---|
2059 | ); |
---|
2060 | $tipos_entes = entes_planificadores_obtiene_tipos(); |
---|
2061 | //SOLO DEJE A UN ENTE SER ENTE PLANIFICADOR MACRO |
---|
2062 | if (db_result(db_query("SELECT nid FROM {ente_planificador} where tipo = '1'")) > 0) { |
---|
2063 | unset($tipos_entes[1]); |
---|
2064 | } |
---|
2065 | if (!$node->nid) { |
---|
2066 | $form['tipo'] = array( |
---|
2067 | '#type' => 'select', |
---|
2068 | '#title' => t('Tipo de rol'), |
---|
2069 | '#default_value' => $node->tipo, |
---|
2070 | '#options' => $tipos_entes, |
---|
2071 | '#description' => t("Seleccione el tipo de rol desempeñado por el actor planificador"), |
---|
2072 | '#required' => TRUE, |
---|
2073 | ); |
---|
2074 | } |
---|
2075 | return $form; |
---|
2076 | } |
---|
2077 | |
---|
2078 | /* |
---|
2079 | * hook_form_alter |
---|
2080 | */ |
---|
2081 | function ente_planificador_form_alter(&$form, $form_state, $form_id) { |
---|
2082 | if ($form_id == 'user_pass_reset') { |
---|
2083 | $form['user_pass_reset'] = array( |
---|
2084 | '#type' => 'hidden', |
---|
2085 | '#value' => TRUE, |
---|
2086 | ); |
---|
2087 | } |
---|
2088 | |
---|
2089 | |
---|
2090 | if ($form_id == 'views_exposed_form') { |
---|
2091 | $form['submit']['#value'] = t("Buscar"); |
---|
2092 | } |
---|
2093 | if ($form_id == 'views_exposed_form' && $form['#id'] == 'views-exposed-form-planificacionM-page-1') { |
---|
2094 | $form['nid']['#type'] = 'select'; |
---|
2095 | $entes_options = obtener_ente_planificador(); |
---|
2096 | $entes_options[''] = t("Seleccione"); |
---|
2097 | $form['nid']['#options'] = $entes_options; |
---|
2098 | unset($form['nid']['#size']); |
---|
2099 | } |
---|
2100 | if ($form['#node']->type == 'ente_planificador') { |
---|
2101 | //just remove cck fields in datos basicos |
---|
2102 | if ($form_id == 'ente_planificador_node_form'){ |
---|
2103 | if (isset($form['taxonomy'])) { |
---|
2104 | $form['taxonomy']['#access'] = FALSE; |
---|
2105 | } |
---|
2106 | $node_type = content_types('ente_planificador'); |
---|
2107 | $fields = $node_type['fields']; |
---|
2108 | $field_form = array(); |
---|
2109 | if (is_array($fields) && count($fields)) { |
---|
2110 | foreach($fields as $field_id => $field) { |
---|
2111 | if (variable_get('ente_planificador_' . $field_id, FALSE)) { |
---|
2112 | if (isset($form[$field_id])) { |
---|
2113 | $form[$field_id]['#access'] = FALSE; |
---|
2114 | } |
---|
2115 | } |
---|
2116 | } |
---|
2117 | } |
---|
2118 | } |
---|
2119 | unset($form['buttons']['preview']); |
---|
2120 | $form['buttons']['cancel'] = array( |
---|
2121 | '#type' => 'submit', |
---|
2122 | '#weight'=>'8120', |
---|
2123 | '#attributes' => array('onClick' => 'window.location="' . base_path() . $_GET['destination'] . '"; return false;'), |
---|
2124 | '#value' => t('Cancel'), |
---|
2125 | ); |
---|
2126 | } |
---|
2127 | // Deshabilitando los campos Vision y Misión del Ente |
---|
2128 | $form['field_ente_vision']['#access'] = FALSE; |
---|
2129 | $form['field_ente_mision']['#access'] = FALSE;$form['field_ente_vision']['#access'] = FALSE; |
---|
2130 | switch ($form_id) { |
---|
2131 | case 'user_profile_form': |
---|
2132 | if (arg(0) == 'user' && is_numeric(arg(1)) && arg(2) == 'edit') { |
---|
2133 | $form['account']['pass']['#access'] = FALSE; |
---|
2134 | $form['account']['status']['#access'] = FALSE; |
---|
2135 | } |
---|
2136 | //eliminar la confirmación de password si el usuario olvido la contraseña |
---|
2137 | if (isset($_SESSION['nuevo_password']) && $_SESSION['nuevo_password']) { |
---|
2138 | $form['account']['passold']['#access'] = FALSE; |
---|
2139 | } |
---|
2140 | unset($form['timezone']); |
---|
2141 | $form['locale']['#type'] = "hidden"; |
---|
2142 | $form['locale']['language']['#type'] = "hidden"; |
---|
2143 | $form['cancel'] = array( |
---|
2144 | '#type' => 'submit', |
---|
2145 | '#weight'=>'961500000', |
---|
2146 | '#attributes' => array('onClick' => 'window.location="' . base_path() . $_GET['destination'] . '"; return false;'), |
---|
2147 | '#value' => t('Cancel'), |
---|
2148 | ); |
---|
2149 | break; |
---|
2150 | case 'user_register': |
---|
2151 | if (variable_get('genpass_mode',0) == 2) { |
---|
2152 | $form['account']['pass']['#type'] = 'hidden'; |
---|
2153 | } |
---|
2154 | if (arg(4) && is_numeric(arg(4))) { |
---|
2155 | $ente_planificador = node_load(arg(4)); |
---|
2156 | } |
---|
2157 | if (isset($form['account']) && is_array($form['account']) && !$form_state['post']) { |
---|
2158 | if ($ente_planificador->nid) { |
---|
2159 | $form['destination']['#value'] = 'node/' . $ente_planificador->nid . "/usuarios"; |
---|
2160 | } |
---|
2161 | if (trim($form['account']['name']['#value']) == "") { |
---|
2162 | $regex = '#[^()]*\((([^()]+|(?R))*)\)[^()]*#'; |
---|
2163 | $replacement = '\1'; |
---|
2164 | $texto_aux = preg_replace($regex, $replacement, $ente_planificador->title); |
---|
2165 | if (!$texto_aux) { |
---|
2166 | $texto_aux = 'ente' . $ente_planificador->nid; |
---|
2167 | } |
---|
2168 | $sqlcount = db_query("select count(u.uid) as cantidad from {users} u"); |
---|
2169 | $ente = db_fetch_object($sqlcount); |
---|
2170 | $ente->cantidad++; |
---|
2171 | $texto_aux.=$ente->cantidad; |
---|
2172 | $form['account']['name']['#value'] = $texto_aux; |
---|
2173 | } |
---|
2174 | if ($ente_planificador) { |
---|
2175 | if($ente_planificador->tipo && $ente_planificador->tipo == 2) { |
---|
2176 | $variable_get = 'ActorPlanificadorMicro'; |
---|
2177 | } |
---|
2178 | if($ente_planificador->tipo && $ente_planificador->tipo == 1) { |
---|
2179 | $variable_get = 'ActorPlanificadorMacro'; |
---|
2180 | } |
---|
2181 | if (sizeof($form['account']['roles']['#options'])) { |
---|
2182 | foreach($form['account']['roles']['#options'] as $a=>$b) { |
---|
2183 | if (($a!=variable_get($variable_get, 2))) { |
---|
2184 | unset($form['account']['roles']['#options'][$a]); |
---|
2185 | } |
---|
2186 | } |
---|
2187 | $form['account']['roles']['#default_value'] = array(variable_get($variable_get, 2)); |
---|
2188 | } |
---|
2189 | } |
---|
2190 | $form['account']['status']['#value'] = 1; |
---|
2191 | $form['account']['status']['#type'] = "hidden"; |
---|
2192 | $form['account']['notify']['#value'] = 1; |
---|
2193 | $form['account']['notify']['#type'] = "hidden"; |
---|
2194 | $form['locale']['#type'] = "hidden"; |
---|
2195 | $form['locale']['language']['#type'] = "hidden"; |
---|
2196 | } |
---|
2197 | if ($ente_planificador) { |
---|
2198 | $enlace = base_path() . 'node/' . $ente_planificador->nid; |
---|
2199 | } |
---|
2200 | else { |
---|
2201 | $enlace = base_path() . 'administrar/entes_planificadores'; |
---|
2202 | } |
---|
2203 | $form['cancel'] = array( |
---|
2204 | '#type' => 'submit', |
---|
2205 | '#weight'=>'8615', |
---|
2206 | '#attributes' => array('onClick' => 'window.location="' . $enlace . '"; return false;'), |
---|
2207 | '#value' => t('Cancel'), |
---|
2208 | ); |
---|
2209 | break; |
---|
2210 | } |
---|
2211 | } |
---|
2212 | |
---|
2213 | /* |
---|
2214 | * ente_planificador_form_cancel |
---|
2215 | * Redireccionar al momento de cancelar |
---|
2216 | */ |
---|
2217 | function ente_planificador_form_cancel(){ |
---|
2218 | drupal_goto(âdestinationpageâ); |
---|
2219 | } |
---|
2220 | |
---|
2221 | /** |
---|
2222 | * ente_planificador_obtener_form_municipio... |
---|
2223 | * Retorna el select de municipios... |
---|
2224 | */ |
---|
2225 | function ente_planificador_obtener_form_municipio($title = NULL, $default = NULL, $description = NULL, $entidad_id = "", $display = 'name', $required = FALSE) { |
---|
2226 | $municipios = ente_planificador_obtener_lista_municipio($entidad_id); |
---|
2227 | $disabled = FALSE; |
---|
2228 | if (count($municipios) == 1) { |
---|
2229 | $municipios = array(-1 => t('Not applicable')); |
---|
2230 | } |
---|
2231 | return array( |
---|
2232 | '#type' => 'select', |
---|
2233 | '#title' => $title, |
---|
2234 | '#default_value' => $default, |
---|
2235 | '#options' => $municipios, |
---|
2236 | '#description' => $description, |
---|
2237 | '#required' => $required, |
---|
2238 | '#disabled' => isset($municipios[-1]) ? TRUE : FALSE, |
---|
2239 | '#suffix' => '<span class="municipio-throbber"></span>', |
---|
2240 | '#ahah' => array( |
---|
2241 | 'event' => 'change', |
---|
2242 | 'path' => 'ente_planificador_js_util/parroquia_select', |
---|
2243 | 'wrapper' => 'edit-parroquia-wrapper', |
---|
2244 | 'method' => 'replace', |
---|
2245 | 'progress' => array('type' => 'bar', 'message' => t('Please wait...')), |
---|
2246 | ), |
---|
2247 | ); |
---|
2248 | } |
---|
2249 | |
---|
2250 | /** |
---|
2251 | * ente_planificador_obtener_form_parroquia... |
---|
2252 | * Retorna el select de parroquias... |
---|
2253 | */ |
---|
2254 | function ente_planificador_obtener_form_parroquia($title = NULL, $default = NULL, $description = NULL, $municipio_id = "", $display = 'name', $required = FALSE) { |
---|
2255 | $parroquias = ente_planificador_obtener_lista_parroquia($municipio_id); |
---|
2256 | $disabled = FALSE; |
---|
2257 | if (count($parroquias) == 1) { |
---|
2258 | $parroquias = array(-1 => t('Not applicable')); |
---|
2259 | } |
---|
2260 | return array( |
---|
2261 | '#type' => 'select', |
---|
2262 | '#title' => $title, |
---|
2263 | '#default_value' => $default, |
---|
2264 | '#options' => $parroquias, |
---|
2265 | '#description' => $description, |
---|
2266 | '#required' => $required, |
---|
2267 | '#disabled' => isset($parroquias[-1]) ? TRUE : FALSE, |
---|
2268 | '#suffix' => '<span class="parroquia-throbber"></span>', |
---|
2269 | ); |
---|
2270 | } |
---|
2271 | |
---|
2272 | /** |
---|
2273 | * ente_planificador_obtener_lista_parroquia... |
---|
2274 | * Retorna una lista de parroquias... |
---|
2275 | */ |
---|
2276 | function ente_planificador_obtener_lista_parroquia($municipio = 0) { |
---|
2277 | $parroquias = array('0' => "Seleccione"); |
---|
2278 | if ($municipio) { |
---|
2279 | $municipioL = ente_planificador_obtener_municipio($municipio); |
---|
2280 | if ($municipioL->codigo) { |
---|
2281 | $resul_act = db_query("SELECT codigo, nombre FROM {parroquia} where municipio = '%s'", $municipioL->codigo); |
---|
2282 | while ($parroquia = db_fetch_object($resul_act)) { |
---|
2283 | $parroquias[$parroquia->codigo] = $parroquia->nombre; |
---|
2284 | } |
---|
2285 | if ($parroquias) { |
---|
2286 | return $parroquias; |
---|
2287 | } |
---|
2288 | } |
---|
2289 | } |
---|
2290 | return $parroquias; |
---|
2291 | } |
---|
2292 | |
---|
2293 | /** |
---|
2294 | * ente_planificador_obtener_municipio... |
---|
2295 | * Retorna un municipio... |
---|
2296 | */ |
---|
2297 | function ente_planificador_obtener_municipio($municipio = 0) { |
---|
2298 | if ($municipio) { |
---|
2299 | $resul_act = db_query("SELECT codigo, nombre FROM {municipio} where codigo = '%s'", $municipio); |
---|
2300 | $municipio = db_fetch_object($resul_act); |
---|
2301 | } |
---|
2302 | return $municipio; |
---|
2303 | } |
---|
2304 | |
---|
2305 | /** |
---|
2306 | * ente_planificador_obtener_parroquia... |
---|
2307 | * Retorna un parroquia... |
---|
2308 | */ |
---|
2309 | function ente_planificador_obtener_parroquia($parroquia = 0) { |
---|
2310 | if ($parroquia) { |
---|
2311 | $resul_act = db_query("SELECT codigo, nombre FROM {parroquia} where codigo = '%s'", $parroquia); |
---|
2312 | $parroquia = db_fetch_object($resul_act); |
---|
2313 | } |
---|
2314 | return $parroquia; |
---|
2315 | } |
---|
2316 | |
---|
2317 | /** |
---|
2318 | * ente_planificador_obtener_entidad... |
---|
2319 | * Retorna una entidad... |
---|
2320 | */ |
---|
2321 | function ente_planificador_obtener_entidad($entidad = "") { |
---|
2322 | $entidadL = NULL; |
---|
2323 | if ($entidad) { |
---|
2324 | $resul_act = db_query("SELECT codigo, nombre FROM {entidad} where codigo = '%s'", $entidad); |
---|
2325 | $entidadL = db_fetch_object($resul_act); |
---|
2326 | } |
---|
2327 | return $entidadL; |
---|
2328 | } |
---|
2329 | |
---|
2330 | /** |
---|
2331 | * ente_planificador_obtener_lista_municipio... |
---|
2332 | * Retorna una lista de muncipios... |
---|
2333 | */ |
---|
2334 | function ente_planificador_obtener_lista_municipio($entidad = "") { |
---|
2335 | $municipios = array(0 => "Seleccione"); |
---|
2336 | if ($entidad) { |
---|
2337 | $entidadL = ente_planificador_obtener_entidad($entidad); |
---|
2338 | if ($entidadL->codigo) { |
---|
2339 | $resul_act = db_query("SELECT codigo, nombre FROM {municipio} where entidad = '%s'", $entidad); |
---|
2340 | while ($municipio = db_fetch_object($resul_act)) { |
---|
2341 | $municipios[$municipio->codigo] = $municipio->nombre; |
---|
2342 | } |
---|
2343 | if ($municipios) { |
---|
2344 | return $municipios; |
---|
2345 | } |
---|
2346 | } |
---|
2347 | } |
---|
2348 | return $municipios; |
---|
2349 | } |
---|
2350 | |
---|
2351 | /** |
---|
2352 | * ente_planificador_obtener_lista_entidad... |
---|
2353 | * Retorna una lista de entidades... |
---|
2354 | */ |
---|
2355 | function ente_planificador_obtener_lista_entidad() { |
---|
2356 | $resul_act = db_query('SELECT codigo, nombre FROM {entidad}'); |
---|
2357 | while ($entidad = db_fetch_object($resul_act)) { |
---|
2358 | $entidades[$entidad->codigo] = $entidad->nombre; |
---|
2359 | } |
---|
2360 | return $entidades; |
---|
2361 | } |
---|
2362 | |
---|
2363 | /** |
---|
2364 | * ente_planificador_obtener_actividades... |
---|
2365 | * Retorna una lista de actividades... |
---|
2366 | */ |
---|
2367 | function ente_planificador_obtener_actividades() { |
---|
2368 | $actividades = array(); |
---|
2369 | $resul_act = db_query('SELECT id_actividad, nombre FROM {ente_actividad} ORDER BY nombre'); |
---|
2370 | while ($actividad = db_fetch_object($resul_act)) { |
---|
2371 | $actividades[$actividad->id_actividad] = $actividad->nombre; |
---|
2372 | } |
---|
2373 | return $actividades; |
---|
2374 | } |
---|
2375 | |
---|
2376 | /** |
---|
2377 | * ente_planificador_obtener_municipio... |
---|
2378 | * Retorna un municipio... |
---|
2379 | */ |
---|
2380 | function ente_planificador_obtener_actividad($actividad = 0) { |
---|
2381 | if ($actividad) { |
---|
2382 | $resul_act = db_query("SELECT nombre FROM {ente_actividad} where id_actividad = '%s'", $actividad); |
---|
2383 | $actividad = db_fetch_object($resul_act); |
---|
2384 | } |
---|
2385 | return $actividad->nombre; |
---|
2386 | } |
---|
2387 | |
---|
2388 | /* |
---|
2389 | * Implementation of hook_insert |
---|
2390 | */ |
---|
2391 | function ente_planificador_insert($node) { |
---|
2392 | if ($node->tipo) { |
---|
2393 | db_query("INSERT INTO {ente_planificador} (nid, tipo) VALUES (%d, %d)", $node->nid, $node->tipo); |
---|
2394 | } |
---|
2395 | } |
---|
2396 | |
---|
2397 | /* |
---|
2398 | * Implementation of hook_update |
---|
2399 | */ |
---|
2400 | function ente_planificador_update($node) { |
---|
2401 | if ($node->nid && $node->tipo) { |
---|
2402 | db_query("UPDATE {ente_planificador} SET tipo = %d WHERE nid = %d", $node->tipo, $node->nid); |
---|
2403 | } |
---|
2404 | } |
---|
2405 | |
---|
2406 | /* |
---|
2407 | * Implementation of hook_delete |
---|
2408 | */ |
---|
2409 | function ente_planificador_delete($node) { |
---|
2410 | // Notice that we're matching all revision, by using the node's nid. |
---|
2411 | if ($node->nid) { |
---|
2412 | db_query('DELETE FROM {ente_planificador} WHERE nid = %d', $node->nid); |
---|
2413 | db_query('DELETE FROM {ente_actividad_ente} WHERE nid = %d', $node->nid); |
---|
2414 | } |
---|
2415 | } |
---|
2416 | |
---|
2417 | /* |
---|
2418 | * Implementation of hook_view |
---|
2419 | */ |
---|
2420 | function ente_planificador_view($node,$teaser,$page) { |
---|
2421 | $node = node_prepare($node, $teaser); |
---|
2422 | $node->content['title1'] = array( |
---|
2423 | '#prefix'=>'<p align="center"><b>', |
---|
2424 | '#value' => "<b>" . t('Nombre del ente planificador:') . "</b> " . check_plain($node->title) . "<br>", |
---|
2425 | '#weight' => -2, |
---|
2426 | '#suffix'=>'</b></p>', |
---|
2427 | ); |
---|
2428 | $node->content['tipo'] = array( |
---|
2429 | '#value' => "<p><b>" . t('Tipo de Actor Planificador:') . "</b> " . entes_planificadores_obtiene_tipos($node->tipo) . "</b></p>", |
---|
2430 | '#weight' => -1, |
---|
2431 | ); |
---|
2432 | //Se añade la estadistica vista al nodo |
---|
2433 | $fecha = time(); |
---|
2434 | if ($node->razon_social) { |
---|
2435 | $node->content['Razon_social'] = array( |
---|
2436 | '#value' => "<b>" . t('Razón Social:') . "</b> " . check_plain($node->razon_social) . "<br>", |
---|
2437 | '#weight' => 0, |
---|
2438 | ); |
---|
2439 | } |
---|
2440 | if ($node->razon_rif) { |
---|
2441 | $node->content['RIF'] = array( |
---|
2442 | '#value' => "<b>" . t('RIF:') . "</b> " . check_plain($node->rif) . "<br>", |
---|
2443 | '#weight' => 1, |
---|
2444 | ); |
---|
2445 | } |
---|
2446 | if ($node->direccion) { |
---|
2447 | $node->content['direccion'] = array( |
---|
2448 | '#value' => "<b>" . t('Dirección:') . "</b> " . check_plain($node->direccion) . "<br>", |
---|
2449 | '#weight' => 2, |
---|
2450 | ); |
---|
2451 | } |
---|
2452 | if ($node->ciudad) { |
---|
2453 | $node->content['ciudad'] = array( |
---|
2454 | '#value' => "<b>" . t('Ciudad:') . "</b> " . check_plain($node->ciudad) . "<br>", |
---|
2455 | '#weight' => 6, |
---|
2456 | ); |
---|
2457 | } |
---|
2458 | if ($node->estado) { |
---|
2459 | $estado = ente_planificador_obtener_entidad($node->estado); |
---|
2460 | $node->content['estado'] = array( |
---|
2461 | '#prefix'=>'<p align="center"><b>' . t('Domicilio Fiscal') . '</b></p>', |
---|
2462 | '#value' => "<b>" . t('Estado:') . "</b> " . $estado->nombre . "<br>", |
---|
2463 | '#weight' => 3, |
---|
2464 | ); |
---|
2465 | } |
---|
2466 | if ($node->municipio) { |
---|
2467 | $municipio = ente_planificador_obtener_municipio($node->municipio); |
---|
2468 | $node->content['municipio'] = array( |
---|
2469 | '#value' => "<b>" . t('Municipio:') . "</b> " . $municipio->nombre . "<br>", |
---|
2470 | '#weight' => 4, |
---|
2471 | ); |
---|
2472 | } |
---|
2473 | if ($node->parroquia) { |
---|
2474 | $parroquia = ente_planificador_obtener_parroquia($node->parroquia); |
---|
2475 | $node->content['parroquia'] = array( |
---|
2476 | '#value' => "<b>" . t('Parroquia:') . "</b> " . $parroquia->nombre . "<br>", |
---|
2477 | '#weight' => 5, |
---|
2478 | ); |
---|
2479 | } |
---|
2480 | $actividad = $node->actividad; |
---|
2481 | for($i=0;$i<sizeof($actividad);$i++) { |
---|
2482 | $actividad[$i] = ente_planificador_obtener_actividad($actividad[$i]); |
---|
2483 | } |
---|
2484 | if (sizeof($actividad)) { |
---|
2485 | $actidades = count($actividad) > 1 ? implode(' , ', $actividad) . '': $actividad[0]; |
---|
2486 | } |
---|
2487 | else { |
---|
2488 | $actidades = t("No seleccionada"); |
---|
2489 | } |
---|
2490 | $node->content['actividad'] = array( |
---|
2491 | '#prefix'=>'<p align="center"><b>' . t('Actividades del Ente') . '</b></p>', |
---|
2492 | '#value' => "<b>" . t('Actividad:') . "</b> ( " . $actidades . " )<br>", |
---|
2493 | '#weight' => 6, |
---|
2494 | ); |
---|
2495 | return $node; |
---|
2496 | } |
---|
2497 | |
---|
2498 | /* |
---|
2499 | * Implementation of hook_access |
---|
2500 | */ |
---|
2501 | function ente_planificador_access($op, $node, $account) { |
---|
2502 | if ($op == 'view') { |
---|
2503 | return user_access('ver planificador'); |
---|
2504 | } |
---|
2505 | if ($op == 'create') { |
---|
2506 | return ((user_access('edit all planificador'))||(user_access('admin planificador'))); |
---|
2507 | } |
---|
2508 | if ($op == 'update') { |
---|
2509 | if (user_access('edit all planificador') ||user_access('admin planificador') || (user_access('edit own planificador') && ($account->uid == $node->usuarios[$account->uid]))) { |
---|
2510 | return TRUE; |
---|
2511 | } |
---|
2512 | } |
---|
2513 | if ($op == 'delete') { |
---|
2514 | return ((user_access('edit all planificador'))||(user_access('admin planificador'))); |
---|
2515 | } |
---|
2516 | } |
---|
2517 | |
---|
2518 | /* |
---|
2519 | * obtener_ente_planificador |
---|
2520 | * retorna una lista de entes planificadores publicados |
---|
2521 | */ |
---|
2522 | function obtener_ente_planificador() { |
---|
2523 | $resultado = db_query("select nid, title from {node} where type='ente_planificador' and status = 1"); |
---|
2524 | while ($ente = db_fetch_object($resultado)) { |
---|
2525 | $entes[$ente->nid] = $ente->title; |
---|
2526 | } |
---|
2527 | if (!sizeof($entes)) { |
---|
2528 | $entes = array(0 => "Seleccione"); |
---|
2529 | } |
---|
2530 | return $entes; |
---|
2531 | } |
---|
2532 | |
---|
2533 | /* |
---|
2534 | * obtener_mis_ente_planificador |
---|
2535 | * retorna una lista de mis entes planificadores publicados |
---|
2536 | */ |
---|
2537 | function obtener_mis_ente_planificador($uid = 0) { |
---|
2538 | if ($uid) { |
---|
2539 | $resultado = db_query("select n.nid, n.title, p.rif,p.direccion from {node} n,{ente_user_planificador} u, {ente_planificador} p where u.usuario = %d and u.nid = n.nid and n.type='ente_planificador' and u.nid = p.nid and n.status = 1", $uid); |
---|
2540 | while ($ente = db_fetch_object($resultado)) { |
---|
2541 | $entes[] = array('title' => $ente->title, 'nid' => $ente->nid, 'rif' => $ente->rif, 'direccion' => $ente->direccion); |
---|
2542 | } |
---|
2543 | } |
---|
2544 | return $entes; |
---|
2545 | } |
---|
2546 | |
---|
2547 | /* |
---|
2548 | * Implementation of hook_user |
---|
2549 | */ |
---|
2550 | function ente_planificador_user($op, &$edit, &$user, $category = NULL) { |
---|
2551 | switch ($op) { |
---|
2552 | case 'login': |
---|
2553 | $_REQUEST['destination'] = 'administrar/entes_planificadores'; |
---|
2554 | if (isset($edit['nuevo_password']) && $edit['nuevo_password']) { |
---|
2555 | $_SESSION['nuevo_password'] = TRUE; |
---|
2556 | } |
---|
2557 | break; |
---|
2558 | case 'load': |
---|
2559 | $entes = obtener_mis_ente_planificador($user->uid); |
---|
2560 | $user->entes = $entes; |
---|
2561 | break; |
---|
2562 | case 'validate': |
---|
2563 | if(array_key_exists('passold', $edit)) { |
---|
2564 | if($user->pass!=md5($edit['passold'])) { |
---|
2565 | form_set_error('passold', t('La contraseña actual no coincide con la suministrada.')); |
---|
2566 | } |
---|
2567 | } |
---|
2568 | if(array_key_exists('cedula', $edit) && !array_key_exists('passold', $edit)) { |
---|
2569 | if(!preg_match("/^(V|E){1}([0-9]){8}$/",$edit['cedula'])) { |
---|
2570 | form_set_error('cedula', t('La cédula de identidad debe tener el formato V00000000 sin puntos.')); |
---|
2571 | } |
---|
2572 | } |
---|
2573 | break; |
---|
2574 | case 'view': |
---|
2575 | $entes = array(); |
---|
2576 | $contenido = '<p align="justify"><b>' . t("Correo Electrónico") . ':</b> ' . $user->mail . '</p>'; |
---|
2577 | if ($user->nombres) { |
---|
2578 | $contenido = '<p align="justify"><b>' . t("Nombres") . ':</b> ' . $user->nombres . '</p>'; |
---|
2579 | } |
---|
2580 | if ($user->apellidos) { |
---|
2581 | $contenido .= '<p align="justify"><b>' . t("Apellidos") . ':</b> ' . $user->apellidos . '</p>'; |
---|
2582 | } |
---|
2583 | if ($user->cedula) { |
---|
2584 | $contenido .= '<p align="justify"><b>' . t("Cédula de Identidad") . ':</b> ' . $user->cedula . '</p>'; |
---|
2585 | } |
---|
2586 | $header = array( |
---|
2587 | array('data' => t('Ente Planificador')), |
---|
2588 | array('data' => t('RIF')), |
---|
2589 | array('data' => t('Dirección')), |
---|
2590 | ); |
---|
2591 | for ($i=0;$i<sizeof($user->entes);$i++) { |
---|
2592 | $entes[]= array(l($user->entes[$i]['title'], 'node/' . $user->entes[$i]['nid']), $user->entes[$i]['rif'], $user->entes[$i]['direccion']); |
---|
2593 | } |
---|
2594 | if (sizeof($entes)>0) { |
---|
2595 | $contenido .= theme('table', $header, $entes); |
---|
2596 | } |
---|
2597 | $user->content['user_picture']=array('user_picture' => array ('#value' =>$contenido, '#weight' => -10 )); |
---|
2598 | break; |
---|
2599 | case 'insert': |
---|
2600 | if(array_key_exists('entes', $edit) && $edit['entes']) { |
---|
2601 | $rolenames = user_roles(); |
---|
2602 | $ente_planificador = node_load($edit['entes']); |
---|
2603 | if ($ente_planificador->tipo) { |
---|
2604 | if($ente_planificador->tipo && $ente_planificador->tipo == 2) { |
---|
2605 | $variable_get = 'ActorPlanificadorMicro'; |
---|
2606 | } |
---|
2607 | if($ente_planificador->tipo && $ente_planificador->tipo == 1) { |
---|
2608 | $variable_get = 'ActorPlanificadorMacro'; |
---|
2609 | } |
---|
2610 | $edit['roles'][2] = $rolenames[2]; |
---|
2611 | if ($rolenames[variable_get($variable_get, 2)]) { |
---|
2612 | $edit['roles'][variable_get($variable_get, 2)] = $rolenames[variable_get($variable_get, 2)]; |
---|
2613 | } |
---|
2614 | db_query("delete from {ente_user_planificador} where usuario = %d",$edit['uid']); |
---|
2615 | $result = db_query("insert into {ente_user_planificador} (nid, usuario) values (%d,%d)", $edit['entes'], $edit['uid']); |
---|
2616 | } |
---|
2617 | } |
---|
2618 | break; |
---|
2619 | case 'update': |
---|
2620 | if(array_key_exists('entes', $edit) && $edit['entes']) { |
---|
2621 | db_query("delete from {ente_user_planificador} where usuario = %d", $user->uid); |
---|
2622 | $result = db_query("insert into {ente_user_planificador} (nid, usuario) values (%d,%d)", $edit['entes'], $user->uid); |
---|
2623 | } |
---|
2624 | $result = db_query("update {users} set nombres = '%s', apellidos = '%s', cedula = '%s' where uid = %d", $edit['nombres'], $edit['apellidos'], $edit['cedula'], $user->uid); |
---|
2625 | break; |
---|
2626 | case 'form': |
---|
2627 | // CHECK THAT USER UPDATE NO ANONYMOUS |
---|
2628 | if ($user->uid > 0) { |
---|
2629 | $form['usuario_planificacion']= array( |
---|
2630 | '#type' => 'fieldset', |
---|
2631 | '#title' => t("Datos del usuario"), |
---|
2632 | ); |
---|
2633 | if (user_access('admin planificador')) { |
---|
2634 | $entes = obtener_ente_planificador(); |
---|
2635 | if (user_access('administer users')) { |
---|
2636 | $entes[0] = t('No asignar ente'); |
---|
2637 | } |
---|
2638 | $default_entes = $user->entes[0]['nid'] ? $user->entes[0]['nid'] : 0; |
---|
2639 | $form['usuario_planificacion']['entes'] = array( |
---|
2640 | '#type' => 'select', |
---|
2641 | '#title' => t('Entes'), |
---|
2642 | '#default_value' => $default_entes, |
---|
2643 | '#options' => $entes, |
---|
2644 | '#weight' => 3, |
---|
2645 | ); |
---|
2646 | } |
---|
2647 | $form['usuario_planificacion']['nombres'] = array( |
---|
2648 | '#type' => 'textfield', |
---|
2649 | '#title' => t('Nombres'), |
---|
2650 | '#default_value' => $user->nombres, |
---|
2651 | '#size' => 60, |
---|
2652 | '#maxlength' => 244, |
---|
2653 | '#description' => t('Introduzca los nombres del actor'), |
---|
2654 | '#required' => TRUE, |
---|
2655 | '#weight' => 4, |
---|
2656 | ); |
---|
2657 | $form['usuario_planificacion']['apellidos'] = array( |
---|
2658 | '#type' => 'textfield', |
---|
2659 | '#title' => t('Apellidos'), |
---|
2660 | '#default_value' => $user->apellidos, |
---|
2661 | '#size' => 60, |
---|
2662 | '#maxlength' => 244, |
---|
2663 | '#description' => t('Introduzca los apellidos del actor'), |
---|
2664 | '#required' => TRUE, |
---|
2665 | '#weight' => 5, |
---|
2666 | ); |
---|
2667 | $form['usuario_planificacion']['cedula'] = array( |
---|
2668 | '#type' => 'textfield', |
---|
2669 | '#title' => t('Cédula de Identidad'), |
---|
2670 | '#default_value' => $user->cedula, |
---|
2671 | '#size' => 60, |
---|
2672 | '#maxlength' => 244, |
---|
2673 | '#description' => t('Introduzca la Cédula de Identidad'), |
---|
2674 | '#required' => TRUE, |
---|
2675 | '#weight' => 6, |
---|
2676 | ); |
---|
2677 | return $form; |
---|
2678 | } |
---|
2679 | break; |
---|
2680 | case 'register': |
---|
2681 | // CHECK THAT USER UPDATE NO ANONYMOUS |
---|
2682 | // DISPLAY ELEMENT FORM TO SELECT TO USE INTRANET |
---|
2683 | if (user_access('admin planificador')) { |
---|
2684 | $ente_planificador = object; |
---|
2685 | if (arg(4) && is_numeric(arg(4))) { |
---|
2686 | $ente_planificador = node_load(arg(4)); |
---|
2687 | } |
---|
2688 | if ($ente_planificador->nid) { |
---|
2689 | $form['actor_planificacion']['entes'] = array( |
---|
2690 | '#type' => 'hidden', |
---|
2691 | '#default_value' => $ente_planificador->nid, |
---|
2692 | ); |
---|
2693 | } |
---|
2694 | else { |
---|
2695 | $entes = obtener_ente_planificador(); |
---|
2696 | if (user_access('administer users')) { |
---|
2697 | $entes[0] = t('No asignar ente'); |
---|
2698 | } |
---|
2699 | $form['entes'] = array( |
---|
2700 | '#type' => 'select', |
---|
2701 | '#title' => t('Entes'), |
---|
2702 | '#default_value' => 0, |
---|
2703 | '#options' => $entes, |
---|
2704 | ); |
---|
2705 | } |
---|
2706 | } |
---|
2707 | return $form; |
---|
2708 | break; |
---|
2709 | } |
---|
2710 | } |
---|
2711 | |
---|
2712 | /* |
---|
2713 | * Implementation of entes_planificadores_planificacion() |
---|
2714 | */ |
---|
2715 | function entes_planificadores_planificacion($planificador = 0) { |
---|
2716 | drupal_goto('planificacion/' . $planificador); |
---|
2717 | } |
---|
2718 | |
---|
2719 | /* |
---|
2720 | * entes_planificadores_usuarios |
---|
2721 | * Mostrar usuarios de un ente planificador |
---|
2722 | */ |
---|
2723 | function entes_planificadores_usuarios($planificador = 0) { |
---|
2724 | $ente_planificador = node_load($planificador); |
---|
2725 | $output = ''; |
---|
2726 | $step = 10; |
---|
2727 | if ($ente_planificador->nid && $ente_planificador->type == 'ente_planificador') { |
---|
2728 | $sqlcount = "SELECT count(u.uid) FROM {users} u, {ente_user_planificador} u1 WHERE u1.usuario = %d AND u1.nid = u.uid"; |
---|
2729 | $sql = "SELECT u.uid, u.name, u.nombres, u.apellidos, u.cedula, u.mail FROM {users} u, {ente_user_planificador} u1 WHERE u1.nid = %d AND u1.usuario = u.uid"; |
---|
2730 | $headers_table[] = array( |
---|
2731 | 'data' => t('Nombre de usuario'), |
---|
2732 | 'sort' => 'asc', |
---|
2733 | 'field' => 'u.name' |
---|
2734 | ); |
---|
2735 | $headers_table[] = array( |
---|
2736 | 'data' => t('Nombres'), |
---|
2737 | 'field' => 'u.nombres' |
---|
2738 | ); |
---|
2739 | $headers_table[] = array( |
---|
2740 | 'data' => t('Apellidos') , |
---|
2741 | 'field' => 'u.apellidos' |
---|
2742 | ); |
---|
2743 | $headers_table[] = array( |
---|
2744 | 'data' => t('Cédula de Identidad'), |
---|
2745 | 'field' => 'u.cedula' |
---|
2746 | ); |
---|
2747 | $headers_table[] = array( |
---|
2748 | 'data' => t('Correo electrónico'), |
---|
2749 | 'field' => 'u.mail' |
---|
2750 | ); |
---|
2751 | $sql.= tablesort_sql($headers_table); |
---|
2752 | $result = pager_query($sql, $step, 0, $sqlcount, $ente_planificador->nid); |
---|
2753 | while($usuario = db_fetch_object($result)) { |
---|
2754 | if (trim($usuario->nombres) == "") { |
---|
2755 | $usuario->nombres = "N/A"; |
---|
2756 | } |
---|
2757 | if (trim($usuario->apellidos) == "") { |
---|
2758 | $usuario->apellidos = "N/A"; |
---|
2759 | } |
---|
2760 | if (trim($usuario->cedula) == "") { |
---|
2761 | $usuario->cedula = "N/A"; |
---|
2762 | } |
---|
2763 | $Lista_usuarios[] = array( |
---|
2764 | 'usuario'=>l($usuario->name, 'user/' . $usuario->uid), |
---|
2765 | 'nombres' => $usuario->nombres, |
---|
2766 | 'apellidos' => $usuario->pellidos, |
---|
2767 | 'cedula' => $usuario->cedula, |
---|
2768 | 'mail' => $usuario->mail |
---|
2769 | ); |
---|
2770 | } |
---|
2771 | if (sizeof($Lista_usuarios)) { |
---|
2772 | $output.= theme('table', $headers_table, $Lista_usuarios); |
---|
2773 | $output .= theme('pager', NULL); |
---|
2774 | } |
---|
2775 | else { |
---|
2776 | $output .= '<p>' . t('No se encontraron usuarios asignados en el planificadores registrados en el sistema') . '</p>'; |
---|
2777 | } |
---|
2778 | if ((user_access('edit all planificador'))||(user_access('admin planificador'))) { |
---|
2779 | $output .= '<p>' . l(t('Agregar usuarios al actor planificador'), 'admin/user/user/create/' . $ente_planificador->nid) . "</p>"; |
---|
2780 | } |
---|
2781 | return $output; |
---|
2782 | } |
---|
2783 | else { |
---|
2784 | drupal_set_message(t("Ente planificador no encontrado")); |
---|
2785 | drupal_goto('entes_planificadores'); |
---|
2786 | } |
---|
2787 | } |
---|
2788 | |
---|
2789 | /** |
---|
2790 | * Implementation of hook_views_api(). |
---|
2791 | */ |
---|
2792 | function ente_planificador_views_api() { |
---|
2793 | return array( |
---|
2794 | 'api' => '2.0', |
---|
2795 | 'path' => drupal_get_path('module', 'ente_planificador') . '/views', |
---|
2796 | ); |
---|
2797 | } |
---|
2798 | |
---|
2799 | /* |
---|
2800 | * planificacion_submenu_interfaz |
---|
2801 | * Generar el menu de explicación situacional |
---|
2802 | */ |
---|
2803 | function ente_planificador_status_planificacion($nid, $tipo = 2) { |
---|
2804 | $procesos_status = array(); |
---|
2805 | $orden = array(); |
---|
2806 | if (is_numeric($nid)) { |
---|
2807 | $ente_planificador = node_load($nid); |
---|
2808 | if ($ente_planificador->type == "ente_planificador") { |
---|
2809 | $procesos = ente_planificador_procesos('status'); |
---|
2810 | $procesos_ordenados = ente_planificador_ordena_procesos($procesos, array()); |
---|
2811 | $procesos = $procesos_ordenados['status']; |
---|
2812 | if (count($procesos)) { |
---|
2813 | foreach($procesos as $id => $proceso) { |
---|
2814 | $proceso_status = array(); |
---|
2815 | foreach (module_list() as $module) { |
---|
2816 | if ($data = module_invoke($module, 'status_planificacion_' . $id, $nid, $tipo)) { |
---|
2817 | $proceso_status = array_merge_recursive($data, $proceso_status); |
---|
2818 | } |
---|
2819 | } |
---|
2820 | $procesos_status[$id]['value'] = $proceso_status; |
---|
2821 | $procesos_status[$id]['title'] = $proceso['title']; |
---|
2822 | } |
---|
2823 | } |
---|
2824 | } |
---|
2825 | } |
---|
2826 | foreach($procesos_status as $id => $arreglo) { |
---|
2827 | $indices = array(); |
---|
2828 | foreach($arreglo['value'] as $ids => $valor) { |
---|
2829 | $weight = isset($valor['weight']) ? $valor['weight'] : 0; |
---|
2830 | $indices[$weight][] = $ids; |
---|
2831 | } |
---|
2832 | ksort($indices); |
---|
2833 | $reemplazo = array(); |
---|
2834 | foreach($indices as $ids => $valores) { |
---|
2835 | foreach($valores as $valor) { |
---|
2836 | |
---|
2837 | $reemplazo[$valor] = $procesos_status[$id]['value'][$valor]; |
---|
2838 | } |
---|
2839 | } |
---|
2840 | unset($procesos_status[$id]['value']); |
---|
2841 | $procesos_status[$id]['value'] = $reemplazo; |
---|
2842 | } |
---|
2843 | return $procesos_status; |
---|
2844 | } |
---|
2845 | |
---|
2846 | /* |
---|
2847 | * planificacion_submenu_interfaz |
---|
2848 | * Generar el menu de explicación situacional |
---|
2849 | */ |
---|
2850 | function planificacion_submenu_interfaz() { |
---|
2851 | $submenu = array(); |
---|
2852 | $smenu = array(); |
---|
2853 | $i = 0; |
---|
2854 | $submenu[$i] = array( |
---|
2855 | 'name'=> t("Explicación situacional"), |
---|
2856 | 'description' => t("Explicación situacional"), |
---|
2857 | 'call' => "explicacion_situacional" |
---|
2858 | ); |
---|
2859 | $aux_menu = array(); |
---|
2860 | foreach (module_list() as $module) { |
---|
2861 | if ($data = module_invoke($module, 'items_menu_planificacion_' . $submenu[$i]['call'])) { |
---|
2862 | $aux_menu = array_merge_recursive($data, $aux_menu); |
---|
2863 | } |
---|
2864 | } |
---|
2865 | $smenu[$i] = $aux_menu; |
---|
2866 | $i++; |
---|
2867 | unset($aux_menu); |
---|
2868 | // LOAD THE REST OF MENUS |
---|
2869 | foreach (module_list() as $module) { |
---|
2870 | if ($data = module_invoke($module, 'menu_planificacion', $valores)) { |
---|
2871 | $submenu[$i] = $data; |
---|
2872 | $aux_menu = array(); |
---|
2873 | foreach (module_list() as $module) { |
---|
2874 | if ($data1 = module_invoke($module, 'items_menu_planificacion_' . $submenu[$i]['call'])) { |
---|
2875 | $aux_menu = array_merge_recursive($data1, $aux_menu); |
---|
2876 | } |
---|
2877 | } |
---|
2878 | $i++; |
---|
2879 | unset($aux_menu); |
---|
2880 | } |
---|
2881 | } |
---|
2882 | return theme('planificacion_submenu_interfaz', $submenu, $smenu); |
---|
2883 | } |
---|
2884 | |
---|
2885 | /* |
---|
2886 | * ente_planificador_theme |
---|
2887 | * Theme de la funcion de ente planificacion |
---|
2888 | */ |
---|
2889 | function ente_planificador_theme() { |
---|
2890 | $theme['planificacion_submenu_interfaz']= array('arguments' => array($menuD => array(), $smenuD => array())); |
---|
2891 | return $theme; |
---|
2892 | } |
---|
2893 | |
---|
2894 | /* |
---|
2895 | * theme_planificacion_submenu_interfaz |
---|
2896 | * Plantilla de ente planificacion |
---|
2897 | */ |
---|
2898 | function theme_planificacion_submenu_interfaz($menuD, $smenuD) { |
---|
2899 | $output = ''; |
---|
2900 | if (sizeof($menuD) > 0) { |
---|
2901 | $output .='<div class="admin clear-block"><div class="clear-block">'; |
---|
2902 | for ($i=0;$i<sizeof($menuD);$i++) { |
---|
2903 | if (($menuD[$i]['name']) && ($menuD[$i]['description'])) { |
---|
2904 | $output .= '<div class="admin-panel">'; |
---|
2905 | $output .= '<h3>'; |
---|
2906 | $output .= $menuD[$i]['name']; |
---|
2907 | $output .= '</h3>'; |
---|
2908 | $output .= '<div class="body">'; |
---|
2909 | $output .= '<p class="description">'; |
---|
2910 | $output .= $menuD[$i]['description']; |
---|
2911 | $output .= '</p>'; |
---|
2912 | $output .= '<dl class="admin-list">'; |
---|
2913 | for ($j = 0; $j < sizeof($smenuD[$i]); $j++) { |
---|
2914 | if (($smenuD[$i][$j]['name']) && ($smenuD[$i][$j]['path']) && ($smenuD[$i][$j]['description'])) { |
---|
2915 | $output .= '<dt>' . l($smenuD[$i][$j]['name'], $smenuD[$i][$j]['path']) . '</a></dt><dd>' . $smenuD[$i][$j]['description'] . '</dd>'; |
---|
2916 | } |
---|
2917 | } |
---|
2918 | $output .= '</dl>'; |
---|
2919 | $output .= '</div></div>'; |
---|
2920 | } |
---|
2921 | } |
---|
2922 | $output .= '</div></div>'; |
---|
2923 | } |
---|
2924 | return $output; |
---|
2925 | } |
---|
2926 | |
---|
2927 | /* |
---|
2928 | * access_ente_planificador |
---|
2929 | * Verifica si el usuario tiene acceso al ente planificador |
---|
2930 | */ |
---|
2931 | function access_ente_planificador($type_url_str = "", $user = object) { |
---|
2932 | global $user; |
---|
2933 | if ($user->uid != 1 && !sizeof($user->entes)) { |
---|
2934 | return FALSE; |
---|
2935 | } |
---|
2936 | if ($user->uid !=1) { |
---|
2937 | $ente_planificador = node_load($user->entes); |
---|
2938 | $type_url_str1 = $type_url_str; |
---|
2939 | $type_url_str = str_replace('_', '-', $type_url_str); |
---|
2940 | $fecha_tipo[1]['FI'] = "FIPMA"; |
---|
2941 | $fecha_tipo[1]['FF'] = "FFPMA"; |
---|
2942 | $fecha_tipo[2]['FI'] = "FIPMI"; |
---|
2943 | $fecha_tipo[2]['FF'] = "FFPMI"; |
---|
2944 | $validFI = variable_get('ente_planificador_' . $type_url_str . $fecha_tipo[$ente_planificador->tipo]['FI'], 0); |
---|
2945 | $validFF = variable_get('ente_planificador_' . $type_url_str . $fecha_tipo[$ente_planificador->tipo]['FF'], 0); |
---|
2946 | $current_time = time(); |
---|
2947 | if ($validFI && $current_time < $validFI) { |
---|
2948 | return FALSE; |
---|
2949 | } |
---|
2950 | elseif ($validFF && $current_time > $validFF + 86399) { |
---|
2951 | return FALSE; |
---|
2952 | } |
---|
2953 | else { |
---|
2954 | return TRUE; |
---|
2955 | } |
---|
2956 | } |
---|
2957 | return TRUE; |
---|
2958 | } |
---|
2959 | |
---|
2960 | /* |
---|
2961 | * muestra_mensaje |
---|
2962 | * Desplegar mensaje al usuario de acuerdo al tiempo de planificacion |
---|
2963 | */ |
---|
2964 | function muestra_mensaje($type_url_str = "", $ente_tipo = 0, $expire = 1) { |
---|
2965 | $mi_fecha = ente_planificador_user_acceso_proceso($type_url_str, $ente_tipo); |
---|
2966 | $procesos = ente_planificador_procesos(); |
---|
2967 | $tipos = entes_planificadores_obtiene_tipos(); |
---|
2968 | if ($expire) { |
---|
2969 | drupal_set_message( |
---|
2970 | t($procesos[$type_url_str]['message_expire'], |
---|
2971 | array( |
---|
2972 | '%tipo_ente' => $tipos[$ente_tipo], |
---|
2973 | '%fecha' => format_date($mi_fecha[0]), |
---|
2974 | '%fecha1' => format_date($mi_fecha[1] + 86399) |
---|
2975 | ) |
---|
2976 | ) |
---|
2977 | ); |
---|
2978 | } |
---|
2979 | else { |
---|
2980 | drupal_set_message( |
---|
2981 | t($procesos[$type_url_str]['message'], |
---|
2982 | array( |
---|
2983 | '%tipo_ente' => $tipos[$ente_tipo], |
---|
2984 | '%fecha' => format_date($mi_fecha[0]), |
---|
2985 | '%fecha1' => format_date($mi_fecha[1] + 86399) |
---|
2986 | ) |
---|
2987 | ) |
---|
2988 | ); |
---|
2989 | } |
---|
2990 | } |
---|
2991 | |
---|
2992 | /* |
---|
2993 | * ente_planificador_user_acceso_proceso |
---|
2994 | * Devuelve la fechas permitidas para un proceso de planificacion |
---|
2995 | */ |
---|
2996 | function ente_planificador_user_acceso_proceso($proceso = '', $tipo) { |
---|
2997 | $fechas = array(); |
---|
2998 | $etapas = array('from', 'until'); |
---|
2999 | if ($proceso) { |
---|
3000 | foreach ($etapas as $etapa) { |
---|
3001 | $fechas[] = variable_get('ente_planificador_' . $proceso . '_' . $etapa, 0); |
---|
3002 | } |
---|
3003 | } |
---|
3004 | drupal_alter('user_acceso_proceso', $fechas); |
---|
3005 | return $fechas; |
---|
3006 | } |
---|
3007 | |
---|
3008 | /** |
---|
3009 | * Implementation of hook_form_FORM_ID_alter(): content_field_edit_form. |
---|
3010 | */ |
---|
3011 | function ente_planificador_form_content_field_edit_form_alter(&$form, $form_state) { |
---|
3012 | if ($form['#field']['type_name'] == 'ente_planificador') { |
---|
3013 | $form['widget']['ente_planificador'] = array( |
---|
3014 | '#title' => 'ente planificador', |
---|
3015 | '#type' => 'checkbox', |
---|
3016 | '#default_value' => variable_get('ente_planificador_' . $form['#field']['field_name'], FALSE), |
---|
3017 | '#return_value' => '1', |
---|
3018 | ); |
---|
3019 | $form['#submit'][] = 'ente_planificador_content_field_edit_form_submit'; |
---|
3020 | } |
---|
3021 | } |
---|
3022 | |
---|
3023 | /* |
---|
3024 | * Implementation of ente_planificador_content_field_edit_form_submit() |
---|
3025 | */ |
---|
3026 | function ente_planificador_content_field_edit_form_submit($form, &$form_state) { |
---|
3027 | variable_set('ente_planificador_' . $form_state['values']['field_name'], $form_state['values']['ente_planificador']); |
---|
3028 | } |
---|
3029 | |
---|
3030 | /** |
---|
3031 | * Implementation of hook_theme_registry_alter() |
---|
3032 | */ |
---|
3033 | function ente_planificador_theme_registry_alter(&$theme_registry) { |
---|
3034 | if (!empty($theme_registry['content_view_multiple_field'])) { |
---|
3035 | $theme_registry['content_view_multiple_field']['function'] = 'ente_planificador_content_view_multiple_field'; |
---|
3036 | } |
---|
3037 | } |
---|
3038 | |
---|
3039 | /* |
---|
3040 | * Implementation of ente_planificador_content_view_multiple_field() |
---|
3041 | */ |
---|
3042 | function ente_planificador_content_view_multiple_field($items, $field, $values) { |
---|
3043 | $output = ''; |
---|
3044 | $i = 0; |
---|
3045 | foreach ($items as $item) { |
---|
3046 | if (!empty($item) || $item == '0') { |
---|
3047 | $tipo = $i % 2 ? 'odd' : 'even'; |
---|
3048 | $output .= '<div class="field-item field-item-'. $i .' field-label-inline-' . $tipo . '">'. $item .'</div>'; |
---|
3049 | $i++; |
---|
3050 | } |
---|
3051 | } |
---|
3052 | return $output; |
---|
3053 | } |
---|