source: sipes/0.3-modules/ente_planificador_sector/ente_planificador_sector.module @ fbe146b

stableversion-3.0
Last change on this file since fbe146b was fbe146b, checked in by lhernandez <lhernandez@…>, 8 años ago

se agrego la validacion para la opcion de agregar ente planificador

  • Propiedad mode establecida a 100755
File size: 68.5 KB
Línea 
1<?php
2  /**
3  * Modulo para la gestión de los entes planificadores por sectores sociales
4  * Sistema Automatizado para la Planificación Estratégico-Situacional en la Administración Pública Venezolana
5  * @file ente_planificador_sector.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 - Ing. Jose Puentes
24  * @date 2014-11-03 // (a&#241;o-mes-dia)
25  * @version 0.2 // (0.1)
26  *
27  */
28 
29/*
30 * Agrega los cuatro niveles de planificacion.
31 * Lista los niveles de Planificacion.
32 */
33function ente_planificador_sector_nivel_planificacion($nivel = 0) {
34  $nivels = array(
35    0 => t('Seleccione.'),
36    1 => t('Organismo rector en planificación.'),
37    2 => t('Organismo público.'),
38    3 => t('Ente adscrito a un organismo público.'),
39    4 => t('Ente adscrito a otro ente adscrito (sub-ente adscrito).'),
40  );
41  drupal_alter('obtiene_tipos', $nivels);
42  if ($nivel && is_numeric($nivel) && $nivels[$nivel]) {
43    return $nivels[$nivel];
44  }
45  elseif($nivel) {
46    return FALSE;
47  }
48  return $nivels;
49}
50
51/*
52 * Agrega los cuatro roles de planificacion.
53 * Lista los roles de Planificacion.
54 */
55function ente_planificador_sector_roles_planificacion($rol= 0) {
56  $roles = array(
57    0 => t('Seleccione.'),
58    1 => t('Control.'),
59    2 => t('Enlace Formulador.'),
60    3 => t('Enlace Revisor.'),
61    4 => t('Supervisor.'),
62  );
63  if ($rol && is_numeric($rol) && $roles[$rol]) {
64    return $roles[$rol];
65  }
66  elseif($rol) {
67    return FALSE;
68  }
69  return $roles;
70}
71
72/*
73 * Seleciona el rol de planificacion del usuario
74 */
75function ente_planificador_sector_mi_rol_planificacion($uid = 0) {
76  $query = db_query("SELECT rol_planificacion FROM ente_user_planificador WHERE usuario=%d", $uid);
77  $row = db_fetch_object($query);
78  return $row->rol_planificacion;
79}
80 
81 /*
82  * Implementation of hook_menu()
83  */
84function ente_planificador_sector_menu() {
85  $items = array();
86  $items['fechas_planificacion/notificacion/sector'] = array(
87    'title' => 'Modificar Fechas por sectores.',
88    'page callback' => 'fecha_procesos_sector_notificacion',
89    'access arguments' => array('admin planificador'),
90    'type' => MENU_LOCAL_TASK,
91  );
92  $items['fechas_planificacion/notificacion/ambito'] = array(
93    'title' => 'Modificar Fechas por Ambito.',
94    'page callback' => 'fecha_procesos_ambito_notificacion',
95    'access arguments' => array('admin planificador'),
96    'type' => MENU_LOCAL_TASK,
97  );
98  $items['fechas_planificacion/edit/sector'] = array(
99    'title' => 'Modificar las fechas para los procesos de planificación por Sectores.',
100    'page callback' => 'fecha_procesos_sector_fecha_planificacion_edit',
101    'access arguments' => array('admin planificador'),
102    'type' => MENU_CALLBACK,
103  );   
104  $items['fechas_planificacion/edit/ambito'] = array(
105    'title' => 'Modificar las fechas para los procesos de planificación por Sectores.',
106    'page callback' => 'fecha_procesos_ambito_fecha_planificacion_edit',
107    'access arguments' => array('admin planificador'),
108    'type' => MENU_CALLBACK,
109  ); 
110  $items['fechas_planificacion/sectores/edit/%/%'] = array(
111    'title' => 'Modificar las fechas para los procesos de planificación por Sectores.',
112    'page callback' => 'fecha_procesos_sector_notificacion_edit_form_sectores_planificacion',
113    'access arguments' => array('admin planificador'),
114    'page arguments' => array(3,4),
115    'type' => MENU_CALLBACK,
116  );
117  $items['fechas_planificacion/ambitos_sector/edit/%/%'] = array(
118    'title' => 'Modificar las fechas para los procesos de planificación por Ambito.',
119    'page callback' => 'fecha_procesos_sector_notificacion_edit_form_planificacion_by_ambitos',
120    'access arguments' => array('admin planificador'),
121    'page arguments' => array(3,4),
122    'type' => MENU_CALLBACK,
123  );
124  //opcion de configuracion del ambito
125  $items['admin/settings/ente_planificador/agregar_ambitos'] = array(
126    'title' => t('Agregar Ambitos'),
127    'page callback' => 'drupal_get_form',
128    'page arguments' => array('ente_planificador_sector_form_ambito'),
129    'access arguments' => array('admin planificador'),
130    'weight' => -6,
131    'type' => MENU_LOCAL_TASK,
132  );
133  //lista de los ambitos registrados
134  $items['lista_ambitos_y_sectores_asociados'] = array(
135    'title' => t('Lista de los Ambitos y Sectores Asociados'),
136    'page callback' => 'ente_planificador_sector_lista_ambito',
137    'access arguments' => array('admin planificador'),
138    'weight' => -6,
139    'type' => MENU_LOCAL_TASK,
140  );
141  //lista de los ambitos registrados
142  $items['admin/settings/ente_planificador/lista_sectores/%'] = array(
143    'title' => t('Lista Sectores Asociados a un ambito'),
144    'page callback' => 'ente_planificador_sector_lista_sectores',
145    'access arguments' => array('admin planificador'),
146    'page arguments' => array(4),
147    'weight' => -6,
148  );
149  //lista de los ambitos registrados
150  $items['admin/settings/ente_planificador/agregar_sectores']   = array(
151    'title' => t('Agregar Sectores'),
152    'page callback' => 'drupal_get_form',
153    'page arguments' => array('ente_planificador_sector_form_sector'),
154    'access arguments' => array('admin planificador'),
155    'weight' => -6,
156    'type' => MENU_LOCAL_TASK,
157  );
158  $items['ente_planificador_sector_util'] = array(
159    'title' => 'JS utilities form',
160    'page callback' => 'ente_planificador_sector_js_util',
161    'access arguments' => array('admin planificador'),
162    'type' => MENU_CALLBACK,
163  );
164  return $items;
165}
166
167/**
168 * Crea una tabla de opciones para modificar las fechas de notificacion por ambito
169 */
170function fecha_procesos_ambito_notificacion() {
171  drupal_set_title(t('Modificar las Fecha de los Procesos por Ambitos'));
172  $view = FALSE;
173  if (user_access('admin planificador')) {
174    $view = TRUE;
175  }
176  $header = array();
177  $header[] = array('data' => t('Listado de los procesos de planificación'));
178  $procesos_status = ente_planificador_procesos('status');
179  $procesos = ente_planificador_procesos();
180  $procesos_ordenados = ente_planificador_ordena_procesos($procesos_status, $procesos);
181  $procesos_status = $procesos_ordenados['status'];
182  $nuevo_proceso = $procesos_ordenados['normal'];
183  $rows = array();
184  if (is_array($procesos_status) && count($procesos_status)) {
185    foreach ($procesos_status as $id => $valores) {
186      $row = array();
187      $row[] = array('data' => '<b>' . $procesos_status[$id]['title'] . '</b>', 'colspan' => 1, 'align' => 'center');
188      $rows[] = $row;
189      if (is_array($nuevo_proceso[$id]) && count($nuevo_proceso[$id])) {
190        $items = array();
191        $item = array();
192        foreach ($nuevo_proceso[$id] as $type_url_str => $proceso) {
193          if ($view) {
194            $item[] = array(
195              'data'=> l(t('Modificar la fecha de inicio para %name', array('%name' => $proceso['title'])), 'fechas_planificacion/edit/ambito/' . $type_url_str, array('html' => true, 'query' => 'destination=fechas_planificacion/notificacion/ambito')),
196            );
197          }
198        }
199        if (sizeof($item)) {
200          $items[] = theme('item_list', $item);
201          $rows[] = $items;
202        }
203        else {
204          $row[] = array(
205            'data' => t('No se encontrarón Procesos'),
206          );
207        }
208      }
209    }
210  }
211  if (sizeof($rows)) {
212    $output.= '<br>'.theme('table', $header, $rows);
213    $output .= theme('pager', NULL);
214  }
215  else {
216    $row[] = array(
217      'data' => t('No se encontrarón Procesos'),
218    );
219  }
220  return $output; 
221}
222 
223/**
224 * Editar las fechas de planificacion por sectores
225 */
226function fecha_procesos_sector_notificacion_edit_form_planificacion_by_ambitos($term = 0, $type_node = '') {
227  $procesos = ente_planificador_procesos();
228  if (isset($procesos[$type_node])) {
229    return drupal_get_form('fecha_procesos_sector_notificacion_edit_form_ambitos_planificacion', $term, $type_node);
230  }
231  return NULL;
232}
233
234
235/*
236 * Lista los sectores por ambito para modificar los procesos que la componen
237 */
238 function fecha_procesos_sector_notificacion_edit_form_ambitos_planificacion($form_state, $ambito = 0, $type_node = '') {   
239   $view = FALSE;
240   $form = array();
241   $procesos = ente_planificador_procesos();
242   $procesos_status = ente_planificador_procesos('status');
243   $procesos_ordenados = ente_planificador_ordena_procesos($procesos_status, $procesos);
244   $procesos_status = $procesos_ordenados['status'];
245   $nuevo_proceso = $procesos_ordenados['normal'];
246   $tid = variable_get('ente_planificador_sector_Ambitos', 0);
247   if(is_numeric($ambito)) {
248     $termino = taxonomy_get_term($ambito);
249   }
250
251   $terms = taxonomy_get_children($termino->tid);
252   drupal_set_title(t('Modificar las Fecha para %proceso', array('%proceso' => $procesos[$type_node]['title'])));
253   
254   if (user_access('admin planificador')) {
255     $view = TRUE;
256   }
257   if (!(is_numeric($ambito)) && ($ambito == 'administrador')) {
258     $FIPM = variable_get('ente_planificador_' . $type_node . '_admin_from', $now);
259     $FFPM = variable_get('ente_planificador_' . $type_node . '_admin_until', $now);
260     $name_ambito = 'Especial del usuario Administrador';
261   }
262   if (!(is_numeric($ambito)) && ($ambito == 'control')) {
263     $FIPM = variable_get('ente_planificador_' . $type_node . '_control_from', $now);
264     $FFPM = variable_get('ente_planificador_' . $type_node . '_control_until', $now);
265     $name_ambito = 'Especial del usuario Control';
266   }
267   //agregando el formulrio para editar las fechas
268   $now = time();
269   if ($view) {
270     if (is_numeric($ambito)) {
271       $term = taxonomy_get_term($ambito);
272       drupal_set_title(t('Fecha de Planificación para el Ambito %ambito', array('%ambito' => $term->name)));
273       $FIPM = variable_get('ente_planificador_' . $type_node . '_all_from_' . $termino->tid, $now);
274       $FFPM = variable_get('ente_planificador_' . $type_node . '_all_until_' . $termino->tid, $now);
275       $name_ambito = $term->name;
276     }
277     $form['fechas'] = array(
278       '#type' => 'fieldset',
279       '#title' => t(' Modificar la fecha de inicio para %proceso del ambito %ambito',array('%proceso' => $procesos[$type_node]['title'], '%ambito' => $name_ambito )),
280       '#collapsible' => FALSE,
281       '#collapsed' => TRUE,
282     );
283
284     $f1 = explode("-", format_date($FIPM, 'custom', 'Y-m-d'));
285     settype($f1[0], "integer");
286     settype($f1[1], "integer");
287     settype($f1[2], "integer");
288     $f2 = explode("-", format_date($FFPM, 'custom', 'Y-m-d'));
289     settype($f2[0], "integer");
290     settype($f2[1], "integer");
291     settype($f2[2], "integer");
292
293     $form['fechas']['from'] = array(
294       '#type' => 'date',
295       '#title' => t('Fecha de Inicio'),
296       '#default_value' => array(
297         'day' => $f1[2],
298         'month' => $f1[1],
299         'year' => $f1[0],
300       ),
301       '#description' => t('Seleccione la fecha de inicio'),
302     );
303     $form['fechas']['until'] = array(
304       '#type' => 'date',
305       '#title' => t('Fecha de Fin'),
306       '#default_value' => array(
307         'day' => $f2[2],
308         'month' => $f2[1],
309         'year' => $f2[0],
310       ),
311       '#description' => t('Seleccione la fecha de culminación'),
312     );
313     if ((is_numeric($ambito)) && (($ambito != 'administrador') || ($ambito != 'control'))) {
314       $form['fechas']['term'] = array(
315         '#type' => 'hidden',
316         '#default_value' => $termino->tid,
317       );
318 
319     }
320     if (!(is_numeric($ambito)) && ($ambito == 'administrador')) {
321       $form['fechas']['term'] = array(
322         '#type' => 'hidden',
323         '#default_value' => $ambito,
324       );
325     }
326     if (!(is_numeric($ambito)) && ($ambito == 'control')) {
327       $form['fechas']['term'] = array(
328         '#type' => 'hidden',
329         '#default_value' => $ambito,
330       );
331     }
332     $form['fechas']['proceso'] = array(
333       '#type' => 'hidden',
334       '#default_value' => $type_node,
335     );
336     $form['submit'] = array(
337       '#type' => 'submit',
338       '#default_value' => t("Guardar"),
339       '#validate' => array('ente_planificador_sector_fecha_planificacion_edit_notificacion_validate'),
340       '#submit' => array('fecha_procesos_sector_notificacion_edit_form_ambito_submit'),
341     );
342     $enlace = base_path() . 'fechas_planificacion/edit/ambito/'.$type_node;
343     $form['cancel'] = array(
344       '#type' => 'submit',
345       '#attributes' => array('onClick' => 'window.location="' . $enlace . '"; return false;'),
346       '#value' => t('Cancel'),
347     );
348     if  ((is_numeric($ambito)) && ($ambito != 'administrador') && ($ambito != 'control')) {
349       $form['fechas']['help'] = array(
350         '#value' => t('Esta acción Afectara todas las fechas especificadas para el proceso de registro por Sectores del ambito %ambito' , array('%ambito' => $term->name)),
351         '#prefix' => '<div class="warning">',
352         '#suffix' => '</div>',
353       );
354     }
355   }
356   if ((is_numeric($ambito)) && ($ambito != 'administrador') && ($ambito != 'control')) {
357     $header = array();
358     $header[] = array('data' => t('Lista de los Sectores para el ambito %ambito', array('%ambito' => $termino->name)), 'colspan' => 1, 'align' => 'center');
359     $header[] = array('data' => t('Fecha de Inicio'), 'colspan' => 1, 'align' => 'center');
360     $header[] = array('data' => t('Fecha de Culminación'), 'colspan' => 1, 'align' => 'center');
361     $now = time();
362     foreach ($terms as $term) {
363       $FIPMI = variable_get('ente_planificador_' . $type_node . '_from_' . $term->tid, $now);
364       $FFPMF = variable_get('ente_planificador_' . $type_node . '_until_' . $term->tid, $now);
365       $row = array();
366       $row[] = array(
367         'data'=> t('%sector', array('%sector' => $term->name)),
368       );
369       $row[] = array(
370         'data'=> format_date($FIPMI, 'long'),
371       );
372       $row[] = array(
373         'data'=> format_date($FFPMF),
374       );
375       $rows[] = $row;
376     }
377     if (sizeof($rows)) {
378       $output.= '<br>'.theme('table', $header, $rows);
379       $output .= theme('pager', NULL);
380     }
381     else {
382       $row[] = array(
383         'data' => t('No se encontrarón Sectores Asociados'),
384                     'colspan' => 3,
385       );
386                   $rows[] = $row;
387       $output.= '<br>'.theme('table', $header, $rows);
388       $output .= theme('pager', NULL);
389    }
390  }
391  //anadiendo las fechas de los sectores para su visualizacion
392  $form['sectores_hidden'] = array(
393    '#value' => '<br>' . $output,
394  );
395        //$form['#submit'][] = 'fecha_procesos_sector_notificacion_edit_form_ambito_submit';
396  return $form;
397}
398 
399/*
400 * agrega las fechas de planificacion por ambito, aplicandola a todos los hijos que la conforman
401 */
402function fecha_procesos_sector_notificacion_edit_form_ambito_submit($form, &$form_state) {
403
404  $fi =  mktime(
405    0,
406    0,
407    0,
408    $form_state['values']['from']['month'],
409    $form_state['values']['from']['day'],
410    $form_state['values']['from']['year']
411  );
412  $ff =  mktime(
413    0,
414    0,
415    0,
416    $form_state['values']['until']['month'],
417    $form_state['values']['until']['day'],
418    $form_state['values']['until']['year']
419  );
420  //estableciendo las fechas para cada sector
421  $ambito = $form_state['values']['term'];
422  $proceso = $form_state['values']['proceso'];
423  if (is_numeric($ambito)) {
424    $ambito = taxonomy_get_term($ambito);
425    $terms = taxonomy_get_children($ambito->tid, $ambito->vid);
426    if ($terms) {
427            foreach ($terms as $term) {
428        variable_set('ente_planificador_' . $proceso . '_all_from_' . $ambito->tid, $fi);
429        variable_set('ente_planificador_' . $proceso . '_all_until_' . $ambito->tid, $ff);
430        //actualizando las fechas por sector social
431        variable_set('ente_planificador_' . $proceso . '_from_' . $term->tid, $fi);
432        variable_set('ente_planificador_' . $proceso . '_until_' . $term->tid, $ff);
433        drupal_set_message(t('Se han guardado los cambios para el sector %sector' , array('%sector' => $term->name)));
434      }
435        }
436        else {
437      variable_set('ente_planificador_' . $proceso . '_all_from_' . $ambito->tid, $fi);
438      variable_set('ente_planificador_' . $proceso . '_all_until_' . $ambito->tid, $ff);
439        }
440    drupal_set_message(t('Se han guardado los cambios para el Ambito %sector' , array('%sector' => $ambito->name)));
441  }
442  if (!(is_numeric($ambito)) && ($ambito == 'administrador')) {
443    variable_set('ente_planificador_' . $proceso . '_admin_from', $fi);
444    variable_set('ente_planificador_' . $proceso . '_admin_until', $ff);
445    drupal_set_message(t('Se han guardado las fechas del ambito especial del usuario administrador'));
446  }
447  if (!(is_numeric($ambito)) && ($ambito == 'control')) {
448    variable_set('ente_planificador_' . $proceso . '_control_from', $fi);
449    variable_set('ente_planificador_' . $proceso . '_control_until', $ff);
450    drupal_set_message(t('Se han guardado las fechas del ambito especial del usuario Control'));
451  }
452
453}
454
455/**
456 * Crea una tabla de las fechas validas de los procesos de planificacion por ambito
457 */
458function fecha_procesos_ambito_fecha_planificacion_edit($type_node = '') {
459  $procesos = ente_planificador_procesos();
460  $view = FALSE;
461  $items = array();
462  $item = array();
463  if (user_access('admin planificador')) {
464    $view = TRUE;
465  }
466  drupal_set_title(t('Modificar la fecha de inicio para %proceso por Ambitos', array('%proceso' => $procesos[$type_node]['title'])));
467  $now = time();
468  if (isset($procesos[$type_node])) {
469    $header = array();
470    $header[] = array('data' => t('Ambito'), 'sort' => 'asc');
471    $header[] = array('data' => t('Fecha de Inicio'), 'sort' => 'asc');
472    $header[] = array('data' => t('Fecha de Fin'), 'sort' => 'asc');
473    if ($view) {
474      $header[] = array('data' => t('Modificar'), );
475    }
476    //recorer todos los ambitos
477    $tid = variable_get('ente_planificador_sector_Ambitos', 0);
478    $terms = taxonomy_get_tree($tid);
479    foreach ($terms as $term) {           
480      $row = array();
481      if ($term->depth == 0) { //si el termino es padre (AMBITO)
482        $fechas[0] = variable_get('ente_planificador_' . $type_node . '_all_from_' . $term->tid, $now);
483        $fechas[1] = variable_get('ente_planificador_' . $type_node . '_all_until_' . $term->tid, $now);
484        $FIPM = $fechas[0];
485        $FFPM = $fechas[1];
486        $row[] = array(
487          'data'=> t('%ambito', array('%ambito' => $term->name)),
488        );   
489        $row[] = format_date($FIPM); 
490        $row[] = format_date($FFPM); 
491        if ($view) {
492          $row[] = l(t('Modificar'), 'fechas_planificacion/ambitos_sector/edit/'.$term->tid.'/'.$type_node, array('html' => true, 'query' => 'destination=fechas_planificacion/edit/ambito/'.$type_node));     
493        }
494      }
495      $rows[] = $row;
496    }
497    // fin de la estructura de repeticion
498    if (!count($rows)) {
499      $row = array();
500      $row[] = array('data' => t('No se encontrarón Sectores'), 'colspan' => 3);
501      $rows[] = $row;
502      $fechas_display = FALSE;
503    }
504    $aux = "";
505    if (module_exists('proyectos_operativos_mail')) {
506      $aux = l(t("Enviar Correo Electrónico a los entes planificadores por Ambito Social."), 'fechas_planificacion/notificacion/envia_email/ambito/' . $type_node);
507    }
508    if (user_access('admin planificador')) {
509      $FIPMA = variable_get('ente_planificador_' . $type_node . '_admin_from', $now);
510      $FFPMA = variable_get('ente_planificador_' . $type_node . '_admin_until', $now);
511      $header2 = array();
512      $header2[] = array('data' => t('Ambito'), 'sort' => 'asc');
513      $header2[] = array('data' => t('Fecha de Inicio'), 'sort' => 'asc');
514      $header2[] = array('data' => t('Fecha de Fin'), 'sort' => 'asc');
515      $header2[] = array('data' => t('Modificar'), );
516      $row2 = array();
517      $row2[] = t('Ambito Especial'); 
518      $row2[] = format_date($FIPMA);
519      $row2[] = format_date($FFPMA);
520      $row2[] = '<br>' . l(t("Mofidicar"), 'fechas_planificacion/ambitos_sector/edit/administrador/'. $type_node , array('html' => true, 'query' => 'destination=fechas_planificacion/edit/ambito/'.$type_node));
521      $rows2[] = $row2;
522      if (!count($rows2)) {
523        $row2 = array();
524        $row2[] = array('data' => t('No se han establecido Fechas'), 'colspan' => 3);
525        $rows2[] = $row;
526        $fechas_display = FALSE;
527      }
528      $aux .= '<h2>' . t('Modificar la fecha de inicio para %proceso para el usuario Administrador', array('%proceso' => $procesos[$type_node]['title'])).'</h2>';
529      $aux .= theme('table', $header2, $rows2);
530    }
531    if (user_access('admin planificador')) { //si es control
532      $FIPMA = variable_get('ente_planificador_' . $type_node . '_control_from', $now);
533      $FFPMA = variable_get('ente_planificador_' . $type_node . '_control_until', $now);
534      $header3 = array();
535      $header3[] = array('data' => t('Ambito'), 'sort' => 'asc');
536      $header3[] = array('data' => t('Fecha de Inicio'), 'sort' => 'asc');
537      $header3[] = array('data' => t('Fecha de Fin'), 'sort' => 'asc');
538      $header3[] = array('data' => t('Modificar'), );
539      $row3 = array();
540      $row3[] = t('Ambito Especial'); 
541      $row3[] = format_date($FIPMA);
542      $row3[] = format_date($FFPMA);
543      $row3[] = '<br>' . l(t("Mofidicar"), 'fechas_planificacion/ambitos_sector/edit/control/'. $type_node , array('html' => true, 'query' => 'destination=fechas_planificacion/edit/ambito/'.$type_node));
544      $rows3[] = $row3;
545      if (!count($rows3)) {
546        $row3 = array();
547        $row3[] = array('data' => t('No se han establecido Fechas'), 'colspan' => 3);
548        $rows3[] = $row;
549        $fechas_display = FALSE;
550      }
551      $aux .= '<h2>' . t('Modificar la fecha de inicio para %proceso para el usuario Control', array('%proceso' => $procesos[$type_node]['title'])).'</h2>';
552      $aux .= theme('table', $header3, $rows3);
553    }
554    return theme('table', $header, $rows) . $aux;
555  } 
556}
557 
558/*
559 * Crea una tabla de opciones para modificar las Fecha de notificacion por sectores
560 */
561function fecha_procesos_sector_notificacion() {
562  drupal_set_title(t('Modificar las Fecha de los Procesos por Sectores'));
563  $view = FALSE;
564  if (user_access('admin planificador')) {
565    $view = TRUE;
566  }
567  $header = array();
568  $header[] = array('data' => t('Listado de los procesos de planificación'));
569  $procesos_status = ente_planificador_procesos('status');
570  $procesos = ente_planificador_procesos();
571  $procesos_ordenados = ente_planificador_ordena_procesos($procesos_status, $procesos);
572  $procesos_status = $procesos_ordenados['status'];
573  $nuevo_proceso = $procesos_ordenados['normal'];
574  $rows = array();
575  if (is_array($procesos_status) && count($procesos_status)) {
576    foreach ($procesos_status as $id => $valores) {
577      $row = array();
578      $row[] = array('data' => '<b>' . $procesos_status[$id]['title'] . '</b>', 'colspan' => 1, 'align' => 'center');
579      $rows[] = $row;
580      if (is_array($nuevo_proceso[$id]) && count($nuevo_proceso[$id])) {
581        $items = array();
582        $item = array();
583        foreach ($nuevo_proceso[$id] as $type_url_str => $proceso) {
584          if ($view) {
585            $item[] = array(
586              'data'=> l(t('Modificar la fecha de inicio para %name', array('%name' => $proceso['title'])), 'fechas_planificacion/edit/sector/' . $type_url_str, array('html' => true, 'query' => 'destination=fechas_planificacion/notificacion/sector')),
587            );
588          }
589        }
590        if (sizeof($item)) {
591          $items[] = theme('item_list', $item);
592          $rows[] = $items;
593        }
594        else {
595          $row[] = array(
596            'data' => t('No se encontrarón Procesos'),
597          );
598        }
599      }
600    }
601  }
602  if (sizeof($rows)) {
603    $output.= '<br>'.theme('table', $header, $rows);
604    $output .= theme('pager', NULL);
605  }
606  else {
607    $row[] = array(
608      'data' => t('No se encontrarón Procesos'),
609    );
610  }
611  return $output;   
612}
613
614/*
615 * ente_planificador_fecha_planificacion_edit
616 * Editar una fecha de planificacion
617 */
618function fecha_procesos_sector_fecha_planificacion_edit($type_node = '') {
619  $procesos = ente_planificador_procesos();
620  $view = FALSE;
621  if (user_access('admin planificador')) {
622    $view = TRUE;
623  }
624  drupal_set_title(t('Modificar la fecha de inicio para %proceso por Sectores', array('%proceso' => $procesos[$type_node]['title'])));
625  if (isset($procesos[$type_node])) {
626    $header = array();
627    $header[] = array('data' => t('Sector'), 'sort' => 'asc');
628    $header[] = array('data' => t('Fecha de Inicio'), 'sort' => 'asc');
629    $header[] = array('data' => t('Fecha de Fin'), 'sort' => 'asc');
630    if ($view) {
631      $header[] = array('data' => t('Modificar'), );
632    }
633    $tid = variable_get('ente_planificador_sector_Ambitos', 0);
634    $terms = taxonomy_get_tree($tid);
635    foreach ($terms as $term) {
636      if ($term->depth == 1) { //si el termino es use sector (nivel 1)
637        $fechas[0] = variable_get('ente_planificador_' . $type_node . '_from_'.$term->tid, date('Y/M/D'));
638        $fechas[1] = variable_get('ente_planificador_' . $type_node . '_until_'.$term->tid, date('Y/M/D'));
639        $row[0] = $term->name;       
640        $row[1] = format_date($fechas[0]); 
641        $row[2] = format_date($fechas[1]); 
642        if ($view) {
643          $row[3] = l(t('modificar'), 'fechas_planificacion/sectores/edit/' . $term->tid . '/' . $type_node, array('html' => true, 'query' => 'destination=fechas_planificacion/edit/sector/' . $type_node));     
644        }
645        $rows[] = array('data' => $row);
646      }
647    }
648    if (!count($rows)) {
649      $row = array();
650      $row[] = array('data' => t('No se encontrarón Sectores'), 'colspan' => 3);
651      $rows[] = $row;
652      $fechas_display = FALSE;
653    }
654    if (module_exists('proyectos_operativos_mail')) {
655      $aux = l(t("Enviar Correo Electrónico a los entes planificadores por Sector Social."), 'fechas_planificacion/notificacion/envia_email/sector/' . $type_node);
656                }
657    return theme('table', $header, $rows) . $aux;
658  }
659}
660
661/**
662 * editar las fechas de planificacion por sectores
663 */
664function fecha_procesos_sector_notificacion_edit_form_sectores_planificacion($term = 0, $type_node = '') {
665  $procesos = ente_planificador_procesos();
666  if (isset($procesos[$type_node])) { 
667    return drupal_get_form('fecha_procesos_sector_notificacion_edit_form', $term, $type_node);
668  }
669  return NULL;
670}
671
672/*
673 * Modifica la fecha por sector social
674 */
675function fecha_procesos_sector_notificacion_edit_form(&$form_state, $sector = 0, $type_node = NULL) {
676  $procesos = ente_planificador_procesos();
677  $term= taxonomy_get_term($sector);
678  drupal_set_title(t('Fecha de Planificación para el Sector %sector', array('%sector' => $term->name)));
679  $form = array();
680  $form['fechas'] = array(
681    '#type' => 'fieldset',
682    '#title' => t(' Modificar la fecha de inicio para %proceso del Sector %sector',array('%proceso' => $procesos[$type_node]['title'], '%sector' => $term->name)),
683    '#collapsible' => FALSE,
684    '#collapsed' => TRUE,
685  );
686  $now = time();
687  $FIPM = variable_get('ente_planificador_' . $type_node . '_from_' . $term->tid);
688  $FIPM = $FIPM ? $FIPM : $now;
689  $f1 = explode("-", format_date($FIPM, 'custom', 'Y-m-d'));
690  settype($f1[0], "integer");
691  settype($f1[1], "integer");
692  settype($f1[2], "integer");
693
694  $FFPM = variable_get('ente_planificador_' . $type_node . '_until_' . $term->tid);
695  $FFPM = $FFPM ? $FFPM : $now;
696  $f2 = explode("-", format_date($FFPM, 'custom', 'Y-m-d'));
697  settype($f2[0], "integer");
698  settype($f2[1], "integer");
699  settype($f2[2], "integer");
700
701  $form['fechas']['from'] = array(
702    '#type' => 'date',
703    '#title' => t('Fecha de Inicio'),
704    '#default_value' => array(
705      'day' => $f1[2],
706      'month' => $f1[1],
707      'year' => $f1[0],
708    ),
709    '#description' => t('Seleccione la fecha de inicio'),
710  );
711  $form['fechas']['until'] = array(
712    '#type' => 'date',
713    '#title' => t('Fecha de Culminación'),
714    '#default_value' => array(
715      'day' => $f2[2],
716      'month' => $f2[1],
717      'year' => $f2[0],
718    ),
719    '#description' => t('Seleccione la fecha de culminación'),
720  );
721  $form['fechas']['term'] = array(
722    '#type' => 'hidden',
723    '#default_value' => $term->tid,
724  );
725  $form['fechas']['proceso'] = array(
726    '#type' => 'hidden',
727    '#default_value' => $type_node,
728  );
729  $form['submit'] = array(
730    '#type' => 'submit',
731    '#default_value' => t("Guardar"),
732    '#validate' => array('ente_planificador_sector_fecha_planificacion_edit_notificacion_validate'),
733     '#submit' => array('fecha_procesos_sector_notificacion_edit_form_submit'),
734  );
735  $enlace = base_path() . 'fechas_planificacion';
736  $form['cancel'] = array(
737    '#type' => 'submit',
738    '#weight'=>'8615',
739    '#attributes' => array('onClick' => 'window.location="' . $enlace . '"; return false;'),
740    '#value' => t('Cancel'),
741  );
742  return $form;   
743}
744
745/*
746 * ente_planificador_fecha_planificacion_edit_notificacion_validate
747 * Validar la informacion de modificar las fechas de notificacion de planificacion
748 */
749function ente_planificador_sector_fecha_planificacion_edit_notificacion_validate($form, &$form_state){
750  $fi =  mktime(
751    0,
752    0,
753    0,
754    $form_state['values']['from']['month'],
755    $form_state['values']['from']['day'],
756    $form_state['values']['from']['year']
757  );
758  $ff  =  mktime(
759    0,
760    0,
761    0,
762    $form_state['values']['until']['month'],
763    $form_state['values']['until']['day'],
764    $form_state['values']['until']['year']
765  );
766  $term = $form_state['values']['term'];
767  $proceso = $form_state['values']['proceso'];
768  $term = taxonomy_get_term($term);
769  $fathers = taxonomy_get_parents($term->tid);
770  $tipo = 'Sector Social';
771  foreach ($fathers as $tid => $terms) {
772    $father = $terms;
773    $tipo = 'Ambito';
774  }
775  if ($fi  > $ff) {
776    form_set_error('from',
777      t('La fecha de notificación (@fi) para el ' . $tipo . ' %sector debe ser Menor a la fecha de culminación (@ff)', array(
778        '@fi' => format_date($fi, 'custom', 'Y-m-d'),
779        '%sector' => $term->name,
780        '@ff' => format_date($ff, 'custom', 'Y-m-d'),
781      ))
782    );
783  }
784  if ($father) {
785    $FIPMI = variable_get('ente_planificador_' . $proceso . '_all_from_' . $father->tid);
786    $FIPMF = variable_get('ente_planificador_' . $proceso . '_all_until_' . $father->tid);
787    if ($fi < $FIPMI) {
788      form_set_error('from',
789        t('La fecha de notificación para el sector %sector (@fi_s) debe ser Mayor a la fecha de notificación del ambito %ambito (@fi_a)', array(
790          '%sector' => $term->name,
791          '@fi_s' => format_date($fi, 'custom', 'Y-m-d'),
792                                '%ambito' => $father->name,
793          '@fi_a' => format_date($FIPMI, 'custom', 'Y-m-d'),
794        ))
795      );
796    }
797    if ($ff > $FIPMF) {
798      form_set_error('until',
799        t('La fecha de notificación para el sector %sector (@ff_s) debe ser Menor a la fecha de notificación del ambito %ambito (@ff_a)', array(
800          '%sector' => $term->name,
801          '@ff_s' => format_date($ff, 'custom', 'Y-m-d'),
802                                '%ambito' => $father->name,
803          '@ff_a' => format_date($FIPMF, 'custom', 'Y-m-d'),
804        ))
805      );
806    }
807  }
808}
809
810/*
811 * agrega las fechas de planificacion por sectores
812 */
813function fecha_procesos_sector_notificacion_edit_form_submit($form, &$form_state) {
814  $fi =  mktime(
815    0,
816    0,
817    0,
818    $form_state['values']['from']['month'],
819    $form_state['values']['from']['day'],
820    $form_state['values']['from']['year']
821  );
822  $ff =  mktime(
823    0,
824    0,
825    0,
826    $form_state['values']['until']['month'],
827    $form_state['values']['until']['day'],
828    $form_state['values']['until']['year']
829  );
830  $term = $form_state['values']['term'];
831  $term = taxonomy_get_term($term);
832  $proceso = $form_state['values']['proceso'];
833  variable_set('ente_planificador_' . $proceso . '_from_' . $term->tid, $fi);
834  variable_set('ente_planificador_' . $proceso . '_until_' . $term->tid, $ff);
835  drupal_set_message(t('Se han guardado los cambios para el Sector %sector' , array('%sector' => $term->name)));
836}
837
838/*
839 * Impletations of hook_form_alter()
840 */
841function ente_planificador_sector_form_alter(&$form, $form_state, $form_id) {
842  if (($form_id == 'views_exposed_form') && ($form['#id'] == 'views-exposed-form-lista-de-los-actores-planificado-page-1')) {
843    global $user;
844    if ($form['ambito'] && ($ente_planificador->tipo ==  1)) {
845      $rolesa = variable_get('roles_exclude_ambito', 0);
846      if ($rolesa) {
847        foreach ($rolesa as $keya => $rola) {
848          if (($user->roles[$keya])) {
849            $form['#info']['filter-ambito']['label'] = t('Ambito del ente Planificador');
850            $form['ambito']['#access'] = 1;
851          }
852          else {
853            $form['#info']['filter-ambito']['label'] = 0;
854            $form['ambito']['#access'] = 0;
855          }
856        }
857      }
858    }
859    global $user;
860    $ente_planificador = node_load($user->entes);
861    if ($form['organismo'] && ($ente_planificador->tipo == 2)) {
862      $roles2 = variable_get('roles_exclude_organismo', 0);
863      if ($roles2) {
864        foreach ($roles2 as $key2 => $rol2) {
865          if ($user->roles[$key2]) {
866            $form['#info']['filter-organismo']['label'] = 0;
867            $form['organismo']['#access'] = 0;
868            $form['#info']['filter-sector']['label'] = 0;
869            $form['sector']['#access'] = 0;
870            $form['#info']['filter-sub_sector']['label'] = 0;
871            $form['sub_sector']['#access'] = 0;
872            $form['#info']['filter-ambito']['label'] = 0;
873            $form['ambito']['#access'] = 0;
874          }
875        }
876      }
877    }
878    if ($form['sector'] && ($ente_planificador->tipo ==  1)) {
879      $roless = variable_get('roles_exclude_sector_social', 0);
880      if ($roless) {
881        foreach ($roless as $keys => $rols) {
882          if (($user->roles[$keys])) {
883            $form['#info']['filter-sector']['label'] = t('Sector Social del Ente Planificador');
884            $form['sector']['#access'] = 1;
885          }
886        }
887      }
888    }
889    if ($form['sub_sector'] && ($ente_planificador->tipo ==  1)) {
890      $roless = variable_get('roles_exclude_sub_sector_social', 0);
891      if ($rolesb) {
892        foreach ($rolesb as $keysb => $rolsb) {
893          if (($user->roles[$keysb])) {
894            $form['#info']['filter-sub_sector']['label'] = t('Sub-Sector Social del Ente Planificador');
895            $form['sub_sector']['#access'] = 1;
896          }
897        }
898      }
899    }
900  }
901
902  if ($form_id == "proyectos_operativos_admin_settings") {
903    $options = array(
904      'ambito' =>  t('Fechas por Ambitos'),
905      'sector' => t('Fechas por Sector Social'),
906    );
907    $form['days']['ente_planificador_sector_optiones_fecha'] = array(
908      '#type' => 'radios',
909      '#title' => t('Tipo de Fechas de Proceso de Planificación'),
910      '#description' => t('Seleccione la Opción para establecer las fechas de los procesos de Planificación'),
911      '#options' => $options,
912      '#required' => 1,
913      '#default_value' => variable_get('ente_planificador_sector_optiones_fecha', 'ambito'),
914    );
915  }
916  if ($form_id == "ente_planificador_node_form") {
917    drupal_add_js(drupal_get_path('module', 'ente_planificador_sector') . '/js/ente_planificador_sector.js');
918
919    //anadiendo el campo nivel de planificacion
920    $nivel_planificacion = ente_planificador_sector_nivel_planificacion();
921    //SOLO DEJE A UN ENTE SER ENTE PLANIFICADOR MACRO
922    if (db_result(db_query("SELECT nid FROM {ente_planificador} where tipo = '1'")) > 0) {
923      unset($nivel_planificacion[1]);
924    }
925    $default = array(0);
926    if ($form['#node']->nid) {
927      $nid = $form['#node']->nid;
928      $query =db_query("SELECT tipo FROM {ente_planificador} WHERE nid = %d", $nid);
929      $entes = db_fetch_object($query);
930      $default = $entes->tipo;
931    }
932    $form['nivel'] = array(
933      '#type' => 'fieldset',
934      '#prefix' => '<div id="ente-planificador-sector-wrapper">',
935      '#suffix' => '</div>',
936    );         
937    $form['tipo'] = array(
938      '#type' => 'select',
939      '#title' => t('Nivel de Planificación'),
940      '#default_value' => $default,
941      '#options' => $nivel_planificacion,
942      '#description' => t("Seleccione el nivel de Planificación en el que se encuentra el Ente Planificador."),
943      '#required' => TRUE,
944      '#weight' => -1,
945      '#ahah' => array(
946        'event' => 'change',
947        'path' => 'ente_planificador_sector_util',
948        'wrapper' => 'ente-planificador-sector-wrapper',
949        'method' => 'replace',
950        'progress' => array('type' => 'bar', 'message' => t('Please wait...')),
951      ),
952      '#prefix' => '<div id="nivel">',
953      '#suffix' => '</div>',
954    );
955       
956    //anadiendo el campo sector
957    $options = array();
958    if ($form['#node']->nid) {
959      $nid = $form['#node']->nid;
960      $query = db_query("SELECT sector FROM {ente_planificador} WHERE nid = %d", $nid);
961      $entes = db_fetch_object($query);
962      $default = $entes->sector;
963    }
964    $tid = variable_get('ente_planificador_sector_Ambitos', 0);
965    $terms = taxonomy_get_tree($tid);
966    $options['0']= "seleccione";
967    foreach ($terms as $term) {
968      if ($term->depth == 1) { //si el termino es padre
969        $options[$term->tid] .= $term->name;
970      }
971    }
972    $parent = 0;
973    $parent = taxonomy_get_parents($default);
974
975    $form['nivel']['ambito'] = array(
976      '#type' => 'hidden',
977      '#value' => key($parent),
978    );
979    $form['nivel']['sector'] = array(
980      '#type' => 'select',
981      '#title' => t('Sector Social'),
982      '#default_value' => $default,
983      '#required' => TRUE,
984      '#options' => $options,
985      '#prefix' => '<div id="sector_ente_planificador">',
986      '#suffix' => '</div>',
987    );
988    //anadiendo el campo organismos_publicos
989    $options = array();
990    $options[0] = "seleccione";
991    $tid = variable_get('ente_planificador_sector_organismos', 0);
992    $terms = taxonomy_get_tree($tid);
993    $default = 0;
994    if ($form['#node']->nid) {
995      $default = db_result(db_query("SELECT organismo FROM {ente_planificador} WHERE nid = %d", $form['#node']->nid));
996    }
997    foreach ($terms as $term) {
998      $options[$term->tid] = $term->name;
999    }
1000    $form['nivel']['ente_adscrito'] = array(
1001      '#type' => 'select',
1002      '#title' => t('Organismo Publico al que se esta adscrito'),
1003      '#default_value' => $default,
1004      '#required' => TRUE,
1005      '#options' => $options,
1006      '#prefix' => '<div id="organismo">',
1007      '#suffix' => '</div>',
1008    );
1009    //anadiendo el campo sub-ente
1010    $options = array();
1011    $options['0']= "seleccione";
1012    $result = db_query("SELECT n.nid, n.title FROM {node} AS n INNER JOIN {ente_planificador} AS e ON n.nid = e.nid WHERE e.ente_adscrito != 0");
1013    while ($rows = db_fetch_object($result)) {
1014      $options[$rows->nid] = $rows->title;
1015    }
1016    $default = 0;
1017    if ($form['#node']->nid) {
1018      $default = db_result(db_query("SELECT sub_ente FROM {ente_planificador} WHERE nid = %d", $form['#node']->nid));
1019    }
1020    $form['nivel']['sub_ente'] = array(
1021      '#type' => 'select',
1022      '#title' => t('Ente al cual se esta adscrito'),
1023      '#default_value' => $default,     
1024      '#required' => TRUE,
1025      '#options' => $options,
1026      '#prefix' => '<div id="sub_ente">',
1027      '#suffix' => '</div>',
1028    ); 
1029  }
1030}
1031
1032/*
1033 * Agregar los ambitos
1034 */
1035function ente_planificador_sector_form_ambito(&$form_state) {
1036  $form = array();
1037  $form['ente_planificador'] = array(
1038    '#type' => 'fieldset',
1039    '#title' => t('Configuración del Ambito'),
1040    '#collapsible' => TRUE,
1041    '#collapsed' => FALSE,
1042  );
1043  $form['ente_planificador']['ente_planificador_ambito'] = array(
1044    '#type' => 'textfield',
1045    '#title' => t('Nombre del Ambito'),
1046    '#required' => TRUE,
1047  );
1048  //lista de ambitos
1049  $header = array();
1050  $header[] = array('data' => t('Lista por Ambitos'), 'colspan' => 3);
1051  $tid = variable_get('ente_planificador_sector_Ambitos', 0);
1052  $terms = taxonomy_get_tree($tid);
1053  foreach ($terms as $term) {
1054    $row = array();
1055    $items = array();
1056    $item = array();
1057    $hij = 0;
1058    $hijos = taxonomy_get_children($term->tid, $term->vid);
1059    foreach ($hijos as $hijo) {
1060      $hij = 1;
1061    }
1062    if ($hij == 1) {
1063     if ($term->depth == 0) { //si el termino es padre (AMBITO)
1064       $row[] = array('data' => '<b>' . l(t($term->name), 'admin/settings/ente_planificador/lista_sectores/'.$term->tid, array('html' => true, 'query' => 'destination=lista_ambitos_y_sectores_asociados')) . '</b>', 'colspan' => 1, 'align' => 'left');
1065                         $row[] = array('data' => '<b>' . l(t('Consultar Sectores'), 'admin/settings/ente_planificador/lista_sectores/'.$term->tid, array('html' => true, 'query' => 'destination=lista_ambitos_y_sectores_asociados')) . '</b>', 'colspan' => 1, 'align' => 'left');
1066     }
1067   }
1068   else {
1069     if ($term->depth == 0) { //si el termino es padre (AMBITO)
1070       $row[] = array('data' => '<b>' . t($term->name) . '</b>', 'colspan' => 1, 'align' => 'left');
1071       $row[] = array('data' => '<b>' . t('No posee Sectores asociados') . '</b>', 'colspan' => 1, 'align' => 'left');
1072                        }
1073   }
1074   $rows[] = $row;
1075   if (sizeof($item)) {
1076     $items[] = theme('item_list', $item);
1077     $rows[] = $items;
1078   }
1079   else {
1080     $row[] = array(
1081       'data' => t('No se encontrarón Sectores Asociados'),
1082     );
1083   }
1084  }
1085  if (sizeof($rows)) {
1086    $output.= '<br>'.theme('table', $header, $rows);
1087    $output .= theme('pager', NULL);
1088  }
1089  else {
1090    $output.= '<p>' .  t('No se encontrarón Ambitos Registrados') .'</p>';
1091  }
1092  $form['ente_planificador']['marcador'] = array(
1093    '#value' => $output,
1094  );
1095  $form['submit'] = array(
1096    '#type' => 'submit',
1097    '#default_value' => t("Guardar"),
1098  );
1099  return $form;
1100}
1101
1102/*
1103 * Agregar los sectores
1104 */
1105function ente_planificador_sector_form_sector(&$form_state) {
1106  $form = array();
1107  $form['ente_planificador'] = array(
1108    '#type' => 'fieldset',
1109    '#title' => t('Configuración del Sector'),
1110    '#collapsible' => TRUE,
1111    '#collapsed' => FALSE,
1112  );
1113  $form['ente_planificador']['sector'] = array(
1114    '#type' => 'textfield',
1115    '#title' => t('Nombre del Sector'),
1116    '#description' => t('Nombre del sector al que pertenece el ambito.'),
1117    '#required' => TRUE,
1118  );
1119  $form['ente_planificador']['tid'] = array(
1120    '#type' => 'hierarchical_select',
1121    '#config' => array(
1122      'module' => 'hs_content_taxonomy',
1123      'params' => array(
1124        'vid' => variable_get('ente_planificador_sector_Ambitos', 0),
1125        'tid' => 0,
1126        'depth' => 1,
1127      ),
1128      'level_labels' => array(
1129        'status' => 1,
1130        'labels' => array(
1131          0 => t('Ambito'),
1132        ),
1133      ),
1134    ),
1135    '#required' => TRUE,
1136    '#description' => t('Nombre del ambito al que pertenece el sector.'),
1137  );
1138 
1139  $header = array();
1140  $header[] = array('data' => t('Lista por Ambitos'), 'colspan' => 3);
1141  $tid = variable_get('ente_planificador_sector_Ambitos', 0);
1142  $terms = taxonomy_get_tree($tid);
1143  foreach ($terms as $term) {
1144    $row = array();
1145    $items = array();
1146    $item = array();
1147    $hij = 0;
1148    $hijos = taxonomy_get_children($term->tid, $term->vid);
1149    foreach ($hijos as $hijo) {
1150      $hij = 1;
1151    }
1152    if ($hij == 1) {
1153     if ($term->depth == 0) { //si el termino es padre (AMBITO)
1154       $row[] = array('data' => '<b>' . l(t($term->name), 'admin/settings/ente_planificador/lista_sectores/'.$term->tid, array('html' => true, 'query' => 'destination=lista_ambitos_y_sectores_asociados')) . '</b>', 'colspan' => 1, 'align' => 'left');
1155                         $row[] = array('data' => '<b>' . l(t('Consultar Sectores'), 'admin/settings/ente_planificador/lista_sectores/'.$term->tid, array('html' => true, 'query' => 'destination=lista_ambitos_y_sectores_asociados')) . '</b>', 'colspan' => 1, 'align' => 'left');
1156     }
1157   }
1158   else {
1159     if ($term->depth == 0) { //si el termino es padre (AMBITO)
1160       $row[] = array('data' => '<b>' . t($term->name) . '</b>', 'colspan' => 1, 'align' => 'left');
1161       $row[] = array('data' => '<b>' . t('No posee Sectores asociados') . '</b>', 'colspan' => 1, 'align' => 'left');
1162                        }
1163   }
1164   $rows[] = $row;
1165   if (sizeof($item)) {
1166     $items[] = theme('item_list', $item);
1167     $rows[] = $items;
1168   }
1169   else {
1170     $row[] = array(
1171       'data' => t('No se encontrarón Sectores Asociados'),
1172     );
1173   }
1174  }
1175  if (sizeof($rows)) {
1176    $output.= '<br>'.theme('table', $header, $rows);
1177    $output .= theme('pager', NULL);
1178  }
1179  else {
1180    $output.= '<p>' .  t('No se encontrarón Ambitos Registrados') .'</p>';
1181  }
1182  $form['ente_planificador']['marcador'] = array(
1183    '#value' => $output,
1184  );
1185  $form['submit'] = array(
1186    '#type' => 'submit',
1187    '#default_value' => t("Guardar"),
1188    '#submit' => array('ente_planificador_sector_form_sectores_submit'),
1189  );
1190  return $form;
1191}
1192
1193
1194/**
1195 * Implementation of ente_planificador_agregar_ambitos_form_submit().
1196 * Save ambitos values
1197 */
1198function ente_planificador_sector_form_ambito_submit($form, &$form_state) {
1199  $vocabulary = taxonomy_vocabulary_load(variable_get('ente_planificador_sector_Ambitos', 0));
1200  $term1 = array(
1201    'vid' => $vocabulary->vid, // Voacabulary ID
1202    'name' => check_plain($form_state['values']['ente_planificador_ambito']), // Term Name
1203  );
1204  taxonomy_save_term($term1);
1205  drupal_set_message(t('El Ambito %ambito ha sido agregado', array('%ambito' => $tem1->name)));
1206  $form_state['redirect'] = 'admin/settings/ente_planificador/agregar_ambitos';
1207}
1208
1209/*
1210 * Lista todas los ambitos y sectores asociados
1211 */
1212function ente_planificador_sector_lista_ambito() {
1213  drupal_set_title(t('Lista de ambitos'));
1214  $view = FALSE;
1215  if (user_access('admin planificador')) {
1216    $view = TRUE;
1217  }
1218  $header = array();
1219  $header[] = array('data' => t('Lista por Ambitos'), 'colspan' => 3);
1220  $procesos_status = ente_planificador_procesos('status');
1221  $procesos = ente_planificador_procesos();
1222  $procesos_ordenados = ente_planificador_ordena_procesos($procesos_status, $procesos);
1223  $procesos_status = $procesos_ordenados['status'];
1224  $nuevo_proceso = $procesos_ordenados['normal'];
1225  $tid = variable_get('ente_planificador_sector_Ambitos', 0);
1226  $terms = taxonomy_get_tree($tid);
1227  foreach ($terms as $term) {
1228    $row = array();
1229    $items = array();
1230    $item = array();
1231    $hij = 0;
1232    $hijos = taxonomy_get_children($term->tid, $term->vid);
1233    foreach ($hijos as $hijo) {
1234      $hij = 1;
1235    }
1236    if ($hij == 1) {
1237     if ($term->depth == 0) { //si el termino es padre (AMBITO)
1238       $row[] = array('data' => '<b>' . l(t($term->name), 'admin/settings/ente_planificador/lista_sectores/' . $term->tid, array('html' => true, 'query' => 'destination=lista_ambitos_y_sectores_asociados')) . '</b>', 'colspan' => 1, 'align' => 'left');
1239                         $row[] = array('data' => '<b>' . l(t('Consultar Sectores'), 'admin/settings/ente_planificador/lista_sectores/' . $term->tid, array('html' => true, 'query' => 'destination=lista_ambitos_y_sectores_asociados')) . '</b>', 'colspan' => 1, 'align' => 'left');
1240                         $row[] = array('data' => l(t('Modificar Ambito'), 'admin/content/taxonomy/edit/term/' . $term->tid, array('html' => true, 'query' => 'destination=lista_ambitos_y_sectores_asociados')) . '</b>', 'colspan' => 1, 'align' => 'left');
1241     }
1242   }
1243   else {
1244     if ($term->depth == 0) { //si el termino es padre (AMBITO)
1245       $row[] = array('data' => '<b>' . t($term->name) . '</b>', 'colspan' => 1, 'align' => 'left');
1246       $row[] = array('data' => '<b>' . t('No posee Sectores asociados') . '</b>', 'colspan' => 1, 'align' => 'left');
1247                         $row[] = array('data' => l(t('Modificar Ambito'), 'admin/content/taxonomy/edit/term/' . $term->tid, array('html' => true, 'query' => 'destination=lista_ambitos_y_sectores_asociados')) . '</b>', 'colspan' => 1, 'align' => 'left');
1248     }
1249   }
1250   $rows[] = $row;
1251   if (sizeof($item)) {
1252     $items[] = theme('item_list', $item);
1253     $rows[] = $items;
1254   }
1255   else {
1256     $row[] = array(
1257       'data' => t('No se encontrarón Sectores Asociados'),
1258     );
1259   }
1260  }
1261  if (sizeof($rows)) {
1262    $output.= '<br>'.theme('table', $header, $rows);
1263    $output .= theme('pager', NULL);
1264  }
1265  else {
1266    $output.= '<p>' .  t('No se encontrarón Ambitos Registrados') .'</p>';
1267  }
1268  return $output;
1269}
1270
1271/*
1272 * Lista todas los ambitos y sectores asociados
1273 */
1274function ente_planificador_sector_lista_sectores($ambito = 0) {
1275  $view = FALSE;
1276  if (user_access('admin planificador')) {
1277    $view = TRUE;
1278  }
1279  $term = taxonomy_get_term($ambito);
1280  drupal_set_title(t("Lista de Sectores asociados al ambito %ambito", array('%ambito' => $term->name)));
1281  $terms = taxonomy_get_children($term->tid, $term->vid);
1282  $header = array();
1283  $header[] = array('data' => t('Lista de los Sectores Asociados al Ambito '. $term->name), 'colspan' => 2, 'align' => 'center');
1284
1285  foreach ($terms as $term) {
1286    $row = array();
1287    $items = array();
1288    $item = array();
1289    $hij = 0;
1290    $hijos = taxonomy_get_children($term->tid, $term->vid);
1291    foreach ($hijos as $hijo) { //anadiendo los hijos del sector
1292      $item[] = array(
1293        'data'=> t('%sector', array('%sector' => $hijo->name)),
1294      );
1295      $hij = 1;
1296    }
1297    if ($hij == 0) { //no posee hijos
1298      $row[] = array('data' => '<b>' . t($term->name) . theme('item_list', $item) . '</b>' , 'colspan' => 1, 'align' => 'left');
1299    }
1300    else {
1301      $row[] = array('data' => '<b>' . l(t($term->name) . theme('item_list', $item), 'admin/settings/ente_planificador/lista_sectores/'.$term->tid, array('html' => true, 'query' => 'destination=lista_ambitos_y_sectores_asociados')) . '</b>' , 'colspan' => 1, 'align' => 'left');
1302    }
1303    $row[] = array('data' => '<b>' . l(t('Modificar Sector'), 'admin/content/taxonomy/edit/term/'.$term->tid, array('html' => true, 'query' => 'destination=admin/settings/ente_planificador/lista_sectores/'.$ambito)) . '</b>', 'colspan' => 1, 'align' => 'left');
1304    $rows[] = $row;
1305  }
1306  if (sizeof($rows)) {
1307    $output.= '<br>'.theme('table', $header, $rows);
1308    $output .= theme('pager', NULL);
1309  }
1310  else {
1311    $output.= '<p>' .  t('No se encontrarón Sectores Registrados') .'</p>';
1312  }
1313  return $output;
1314}
1315
1316/**
1317 * Implementation of ente_planificador_agregar_ambitos_form_submit().
1318 * Save ambitos values
1319 */
1320function ente_planificador_sector_form_sectores_submit($form, &$form_state) {
1321  $tems = taxonomy_get_term($form_state['values']['tid']);
1322  $vocabulary = taxonomy_vocabulary_load(variable_get('ente_planificador_sector_Ambitos', 0));
1323  $tems = taxonomy_get_term($tems->tid);
1324  $term1 = array(
1325    'vid' => $vocabulary->vid, // Voacabulary ID
1326    'name' => check_plain($form_state['values']['sector']),
1327    'parent' => array($tems->tid),
1328  );
1329  taxonomy_save_term($term1);
1330  drupal_set_message(t('El Ambito %ambito y los sectores han sido agregados', array('%ambito' => $tem1->name)));
1331  $form_state['redirect'] = 'admin/settings/ente_planificador/agregar_sectores';
1332}
1333
1334/**
1335 * Implementation of hook_views_api().
1336 */
1337function ente_planificador_sector_views_api() {
1338  return array(
1339    'api' => '2.0',
1340    'path' => drupal_get_path('module', 'ente_planificador_sector') . '/includes/views',
1341  );
1342}
1343
1344/*
1345 * Implementation of hook_nodeapi()
1346 */
1347function ente_planificador_sector_nodeapi(&$node, $op, $arg = 0) {
1348  //tipo de contenido ente planificador
1349  if ($node->type == 'ente_planificador') {
1350    //agregando el sector a la vista del nodo
1351    if ($op == 'presave') {
1352      $level = 0;
1353      $hierarchical = variable_get('ente_planificador_hierarchical_count', 2);
1354      for($i = 1; $i < $hierarchical + 1; $i++) {
1355        if (!$level && isset($node->{'ente_planificador_hierarchical_father_' . $i})) {
1356         //level found
1357         $level_lower = $i - 1;
1358         $father = $node->{'ente_planificador_hierarchical_father_' . $i};
1359         if ($father == 0) {
1360           $level = $i;
1361           $ente_planificador_hierarchical[$i] = $father;
1362           break;
1363         }
1364         $ente_planificador_hierarchical[$i] = $father;
1365        }
1366      }
1367      if (($level) > 2) {
1368        if (!$node->ambito) {
1369          $level_lower = $level - 1;
1370          $father = $node->{'ente_planificador_hierarchical_father_' . $level_lower};
1371          $node_father = node_load($father);
1372          $node->ambito = $node_father->ambito;
1373          $node->sector = $node_father->sector;
1374        }
1375      }
1376      else {
1377        if (isset($node->sector)) {
1378          $parent = taxonomy_get_parents($node->sector);
1379          $node->ambito = key($parent);
1380        }
1381      }
1382    }
1383    if ($op == 'view') {
1384      if ($node->content['title1']) {
1385        $node->content['name_ente']  = array(
1386          '#prefix'=>'<p align="left">',
1387          '#value' => "<b>" . t('Nombre del ente planificador:') . "</b> " . check_plain($node->title) . "<br>",
1388          '#weight' => 0,
1389          '#suffix'=>'</p>',     
1390        );
1391      }
1392      if ($node->tipo > 1 && $node->sector && $node->ambito) {
1393        $tid = check_plain($node->sector);
1394        $term = taxonomy_get_term($tid);
1395        $node->content['sector']  = array(
1396          '#prefix'=>'<p align="left">',
1397          '#value' => "<b>" . t('Sector:') . "</b> " . $term->name . "<br>",
1398          '#weight' => 1,
1399          '#suffix'=>'</p>',     
1400        );
1401        $term = taxonomy_get_term($node->ambito);
1402        $node->content['ambito']  = array(
1403          '#prefix'=>'<p align="left">',
1404          '#value' => "<b>" . t('Ambito:') . "</b> " . $term->name . "<br>",
1405          '#weight' => 1,
1406          '#suffix'=>'</p>',     
1407        );
1408      }
1409      if ($node->tipo) {
1410        $node->content['tipo']  = array(
1411          '#prefix'=>'<p align="left">',
1412          '#value' => "<b>" . t('Nivel de Planificación: ') . "</b>" . ente_planificador_sector_nivel_planificacion($node->tipo) . "<br>",
1413          '#weight' => 2,
1414          '#suffix'=>'</p>',     
1415        );
1416      }
1417      if ($node->organismo) {
1418        $term = taxonomy_get_term($node->organismo);
1419        $node->content['organismo']  = array(
1420          '#prefix'=>'<p align="left">',
1421          '#value' => "<b>" . t('Organismo Público: ') . "</b>" . $term->name . "<br>",
1422          '#weight' => 3,
1423          '#suffix'=>'</p>',     
1424        );
1425      }
1426      if ($node->sub_ente) {
1427        $result = db_result(db_query("SELECT title FROM {node} WHERE nid = %d", $node->sub_ente));
1428        $node->content['sub_ente']  = array(
1429          '#prefix'=>'<p align="left">',
1430          '#value' => "<b>" . t('Ente al cual se está adscrito: ') . "</b>" . $result . "<br>",
1431          '#weight' => 5,
1432          '#suffix'=>'</p>',     
1433        );
1434      }
1435      if (user_access('admin all planificador')) {
1436        $node->content['link_add_ente'] = array(
1437          '#prefix'=>'<p align="left">',
1438          '#value' => "<b>" . l(t('Agregar un nuevo Ente planificador'),'node/add/ente-planificador'),
1439          '#weight' => 999999,
1440          '#suffix'=>'</p>', 
1441        );
1442      }
1443    }
1444    //anadiendo el sector al que pertence el ente planificador
1445    if ($op == 'insert' || $op == 'update') {
1446      db_query("UPDATE {ente_planificador} set ambito = %d, sector = %d WHERE nid = %d", $node->ambito, $node->sector, $node->nid);
1447      if ($node->tipo == 1) { //Organismo público.
1448        db_query("UPDATE {ente_planificador} set organismo = %d, ente_adscrito = %d, sub_ente = %d WHERE nid = %d", 0, 0, 0, $node->nid);
1449      }
1450      if ($node->tipo == 2) { //Organismo público.
1451        $vocabulary = taxonomy_vocabulary_load(variable_get('ente_planificador_sector_organismos', 0));
1452        if ($op == 'update') {
1453          $organismo = db_result(db_query("SELECT organismo FROM {ente_planificador} WHERE nid = %d", $node->nid));
1454          $term = array(
1455            'vid' => $vocabulary->vid, // Voacabulary ID
1456            'name' => $node->title, // Term Name
1457            'tid' => $organismo,
1458          );
1459        }
1460        if ($op == 'insert') {
1461          $term = array(
1462            'vid' => $vocabulary->vid, // Voacabulary ID
1463            'name' => $node->title, // Term Name
1464          );
1465        }
1466        taxonomy_save_term($term);
1467        $organismo = $term['tid'];             
1468        db_query("UPDATE {ente_planificador} set organismo = %d, ente_adscrito = %d, sub_ente = %d WHERE nid = %d", $organismo, 0, 0, $node->nid);
1469      }
1470      if ($node->ente_adscrito && $node->tipo == 3) {  //Ente adscrito a un organismo público.
1471        $ente_adscrito = $node->ente_adscrito;
1472        db_query("UPDATE {ente_planificador} set ente_adscrito = %d, sub_ente = %d, organismo = %d WHERE nid = %d", $ente_adscrito, 0, $ente_adscrito, $node->nid);
1473      }
1474      if ($node->sub_ente && $node->tipo == 4) {  //Ente adscrito a otro ente adscrito (sub-ente adscrito).
1475        $sub_ente = $node->sub_ente;
1476        $result = db_query("SELECT organismo FROM {ente_planificador} WHERE nid = %d", $node->sub_ente);
1477        $row = db_fetch_object($result);
1478        if ($row) {
1479          db_query("UPDATE {ente_planificador} set sub_ente = %d, ente_adscrito = %d, organismo = %d WHERE nid = %d", $sub_ente, $sub_ente, $row->organismo, $node->nid);
1480        }
1481      }
1482    }
1483  }
1484}
1485
1486/*
1487 * Implementation of hook_views_default_views_alter().
1488 */
1489function ente_planificador_sector_views_default_views_alter(&$views) {
1490  foreach ($views as $view) {
1491    if ($view->name == 'planificacionM') { //modificacion de la vista Consultar datos de los actores planificadores (APM/APMS)
1492     //style options sector
1493     $view->display['default']->display_options['filters']['sector'] = array(
1494       'operator' => 'or',
1495       'value' => NULL,
1496       'group' => '0',
1497       'exposed' => TRUE,
1498       'expose' => array(
1499         'use_operator' => 0,
1500         'operator' => 'sector_op',
1501         'identifier' => 'sector',
1502         'label' => 'Sector Social',
1503         'optional' => 1,
1504         'single' => 1,
1505         'remember' => 0,
1506         'reduce' => 0,
1507       ),
1508       'id' => 'sector',
1509       'table' => 'ente_planificador',
1510       'field' => 'sector',
1511       'override' => array(
1512         'button' =>  'Override',
1513       ),
1514     );
1515     //definition field sector
1516     $sector = array(
1517       'label' => 'Sector Social',
1518       'alter' => array(
1519          'alter_text' => 0,
1520          'text' => '',
1521          'make_link' => 0,
1522          'path' => '',
1523          'link_class' => '',
1524          'alt' => '',
1525          'prefix' => '',
1526          'suffix' => '',
1527          'target' => '',
1528          'help' => '',
1529          'trim' => 0,
1530          'max_length' => '',
1531          'word_boundary' => 1,
1532          'ellipsis' => 1,
1533          'html' => 0,
1534          'strip_tags' => 0,
1535        ),
1536        'empty' => '',
1537        'hide_empty' => 0,
1538        'empty_zero' => 0,
1539        'exclude' => 0,
1540        'link_to_node' => 0,
1541        'id' => 'estado',
1542        'table' => 'ente_planificador',
1543        'field' => 'sector',
1544        'relationship' => 'none',
1545      );   
1546      //ordenando el campo
1547      $view->display['default']->display_options['style_options']['columns']['sector'] = 'sector';
1548      $sort = array(
1549        'sortable' => 1,
1550        'separator' => "",
1551      );
1552      $style = array_pop($view->display['default']->display_options['style_options']);
1553      $view->display['default']->display_options['style_options']['info']['sector'] = $sort;
1554      $view->display['default']->display_options['style_options']['nothing'] = $style;
1555      // add field
1556      $nothing = array_pop($view->display['default']->display_options['fields']);
1557      $view->display['default']->display_options['fields']['sector'] = $sector;
1558      $view->display['default']->display_options['fields']['nothing'] = $nothing;
1559    }  //end find view planificacionM
1560  }
1561}
1562
1563/**
1564 * Implmentations of hook_menu_alter
1565 */
1566
1567function ente_planificador_menu_alter(&$items) {
1568 // $items['administrar/entes_planificadores']['page callback'] = 'ente_planificador_sector_lista_entes_redirect';
1569 // $items['administrar_usuarios']['page callback'] = 'ente_planificador_sector_lista_usuarios_redirect';
1570}
1571
1572/**
1573 * Redirigir a la vista lista de los entes planificadores
1574 */
1575function ente_planificador_sector_lista_entes_redirect() {
1576  drupal_goto('administrar/entes_planificadores/lista');
1577}
1578
1579/**
1580 * Redirigir a la vista lista de los usuarios
1581 */
1582function ente_planificador_sector_lista_usuarios_redirect() {
1583  drupal_goto('administrar_usuarios/lista');
1584}
1585
1586/**
1587 * genera el ahah alregistrar los entes planificadores
1588 */
1589function ente_planificador_sector_js_util() {
1590  $tipo = 'nivel';
1591  $form_state = array('submitted' => FALSE);
1592  $form_build_id = $_POST['form_build_id'];
1593  // Add the new element to the stored form. Without adding the element tothe
1594  // form, Drupal is not aware of this new elements existence and will not
1595  // process it. We retreive the cached form, add the element, and resave.
1596  $form = form_get_cache($form_build_id, $form_state);
1597  if ($_POST['tipo'] != 1) {   
1598    $new_form['nivel'] = array(
1599      '#type' => 'fieldset',   
1600    );
1601  }     
1602  if ($_POST['tipo'] == 2) {
1603    $options = array();
1604    $tid = variable_get('ente_planificador_sector_Ambitos', 0);
1605    $terms = taxonomy_get_tree($tid);
1606    $options['0']= "seleccione";
1607    foreach ($terms as $term) {
1608      if ($term->depth == 1) { //si el termino es padre
1609        $options[$term->tid] = $term->name;
1610      }
1611    }
1612    $new_form['nivel']['sector'] = array(
1613      '#title' => t('Sector Social'),
1614      '#type' => 'select',
1615      '#required' => TRUE,
1616      '#options' => $options,
1617      '#prefix' => '<div id="sector_ente_planificador">',
1618      '#suffix' => '</div>',
1619    );
1620    $form[$tipo]['sector'] = $new_form['sector'];
1621  }
1622  if ($_POST['tipo'] == 3) {
1623    $options = array();
1624    $options[0] = "seleccione";
1625    $tid = variable_get('ente_planificador_sector_organismos', 0);
1626    $terms = taxonomy_get_tree($tid);
1627    foreach ($terms as $term) {
1628      $options[$term->tid] = $term->name;
1629    }
1630    $new_form['nivel']['ente_adscrito'] = array(
1631      '#type' => 'select',
1632      '#title' => t('Organismo Publico al que se esta adscrito'),
1633      '#required' => TRUE,
1634      '#options' => $options,
1635      '#prefix' => '<div id="organismo">',
1636      '#suffix' => '</div>',
1637    );
1638    $form[$tipo]['ente_adscrito'] = $new_form['ente_adscrito'];
1639  }
1640  if ($_POST['tipo'] == 4) {
1641    $options = array();
1642    $options['0']= "seleccione";
1643    $result = db_query("SELECT n.nid, n.title FROM {node} AS n INNER JOIN {ente_planificador} AS e ON n.nid = e.nid WHERE e.ente_adscrito != 0");
1644    while ($rows = db_fetch_object($result)) {
1645      $options[$rows->nid] = $rows->title;
1646    }
1647    $new_form['nivel']['sub_ente'] = array(
1648      '#type' => 'select',
1649      '#title' => t('Ente al cual se esta adscrito'),
1650      '#required' => TRUE,
1651      '#options' => $options,
1652      '#prefix' => '<div id="sub_ente">',
1653      '#suffix' => '</div>',
1654    );
1655    $form[$tipo]['sub_ente'] = $new_form['sub_ente'];
1656  }
1657  $form[$tipo] = $new_form;
1658  form_set_cache($form_build_id, $form, $form_state);
1659  $form += array(
1660    '#post' => $_POST,
1661    '#programmed' => FALSE,
1662  );
1663  // Rebuild the form.
1664  $form = form_builder($_POST['form_id'], $form, $form_state);
1665  // Render the new output.
1666  $new_form = $form[$tipo];
1667  unset($new_form['#prefix'], $new_form['#suffix']); // Prevent duplicate wrappers.
1668
1669  // Rebuild the form.
1670  $form = form_builder($_POST['form_id'], $form, $form_state);
1671  // Render the new output.
1672  $new_form = array();
1673
1674  $output = drupal_render($new_form);
1675  print drupal_to_js(array('data' => $output, 'status' => true));
1676  exit();
1677}
1678
1679
1680/**
1681 * Implementation of hook_ente_planificador_proceso_user_acceso_alter
1682 */
1683function ente_planificador_sector_ente_planificador_proceso_user_acceso_alter(&$fechas, $conf) {
1684  $ente_planificador = $conf['ente_planificador'];
1685  $type_proceso = $conf['proceso'];
1686  $now = time();
1687  global $user;
1688  $rol_macro = variable_get('ActorPlanificadorMacro', 0);
1689  $options = variable_get('ente_planificador_sector_optiones_fecha', 'ambito');
1690  if ($type_proceso) {
1691    if ((is_object($ente_planificador))) {
1692      if ($ente_planificador->ambito) {
1693        if ($options == 'sector') {
1694          $term = taxonomy_get_term($ente_planificador->sector);
1695          $FIPMI = variable_get('ente_planificador_' . $type_proceso . '_from_' . $term->tid, $now);
1696          $FIPMF = variable_get('ente_planificador_' . $type_proceso . '_until_' . $term->tid, $now);
1697       }
1698       if ($options == 'ambito') {
1699          $term = taxonomy_get_term($ente_planificador->ambito);
1700          $FIPMI = variable_get('ente_planificador_' . $type_proceso . '_all_from_' . $term->tid, $now);
1701          $FIPMF = variable_get('ente_planificador_' . $type_proceso . '_all_until_' . $term->tid, $now);
1702        }
1703      }
1704      elseif(isset($user->ambito_user)  && $ente_planificador->tipo == 1 && !(in_array($rol_macro, array_keys($user->roles)))) {
1705        $term = taxonomy_get_term($user->ambito_user);
1706        $FIPMI = variable_get('ente_planificador_' . $type_proceso . '_all_from_' . $term->tid, $now);
1707        $FIPMF = variable_get('ente_planificador_' . $type_proceso . '_all_until_' . $term->tid, $now);
1708      }
1709    }
1710    if (is_numeric($ente_planificador) || user_access('admin all planificador')) { //si es el administrador se aplica la fecha especial
1711      $FIPMI = variable_get('ente_planificador_' . $type_proceso . '_admin_from', $now);
1712      $FIPMF = variable_get('ente_planificador_' . $type_proceso . '_admin_until', $now);
1713    }
1714    if (in_array($rol_macro, array_keys($user->roles))) { //es usuario control
1715      $FIPMI = variable_get('ente_planificador_' . $type_proceso . '_control_from', $now);
1716      $FIPMF = variable_get('ente_planificador_' . $type_proceso . '_control_until', $now);
1717    }
1718    if ($FIPMI) {
1719      $fechas[0] = $FIPMI;
1720    }
1721    if ($FIPMF) {
1722      $fechas[1] = $FIPMF;
1723    }
1724  }
1725}
1726
1727/**
1728 * Implementation of hook_ente_planificador_muestra_mensaje_alter
1729 */
1730function ente_planificador_sector_ente_planificador_muestra_mensaje_alter(&$new_mensaje, $conf) {
1731  $type_proceso = $conf['plan_tipo'];
1732  $procesos = ente_planificador_procesos();
1733  $ente_planificador = $conf['ente_planificador'];
1734  $ambito_text = "Ambito Especial de Administración";
1735  $sector_text = "Sector Especial";
1736  $now = time();
1737  global $user;
1738  $rol_macro = variable_get('ActorPlanificadorMacro', 0);
1739  $expire = $conf['expire'];
1740  if ($type_proceso) {
1741    if (is_object($ente_planificador)) {
1742      if ($ente_planificador->ambito) {
1743        $sector = taxonomy_get_term($ente_planificador->sector);
1744        $ambito = taxonomy_get_term($ente_planificador->ambito);
1745        $mi_fecha = array(
1746          variable_get('ente_planificador_' . $type_proceso . '_all_from_' . $ambito->tid, $now),
1747          variable_get('ente_planificador_' . $type_proceso . '_all_until_' . $ambito->tid, $now),
1748        );
1749        if ($expire) {
1750          $new_mensaje = t("Registrar y/o modificar los Proyectos Operativos para el Ambito %ambito en el Sector %sector no se encuentra disponible, se podra realizar desde el %fechaI hasta %fechaF", array('%ambito' => strtoupper($ambito->name), '%sector' => strtoupper($sector->name), '%fechaI' => format_date($mi_fecha[0]), '%fechaF' => format_date($mi_fecha[1])));
1751        }
1752        else {
1753          $new_mensaje = t("Se podra registrar y/o modificar los Proyectos Operativos para el Ambito %ambito en el Sector %sector desde el %fechaI hasta %fechaF", array('%ambito' => strtoupper($ambito->name), '%sector' => strtoupper($sector->name), '%fechaI' => format_date($mi_fecha[0]), '%fechaF' => format_date($mi_fecha[1])));
1754        }
1755      }
1756      elseif(isset($user->ambito_user)  && $ente_planificador->tipo == 1 && !(in_array($rol_macro, array_keys($user->roles)))) {
1757        if (empty($user->ambito_user)) {
1758//          drupal_set_message(t('Especifique el ambito del usuario supervisor.'), 'warning');         
1759        }
1760        $ambito = taxonomy_get_term($user->ambito_user);
1761        $FIPMI = variable_get('ente_planificador_' . $type_proceso . '_all_from_' . $ambito->tid, $now);
1762        $FIPMF = variable_get('ente_planificador_' . $type_proceso . '_all_until_' . $ambito->tid, $now);
1763
1764        if ($expire) {
1765          $new_mensaje = t("Registrar y/o modificar los Proyectos Operativos para el Ambito %ambito no se encuentra disponible, se podra realizar desde el %fechaI hasta %fechaF", array('%ambito' => strtoupper($ambito->name), '%fechaI' => format_date($FIPMI), '%fechaF' => format_date($FIPMF)));
1766        }
1767        else {
1768          $new_mensaje = t("Se podra registrar y/o modificar los Proyectos Operativos para el Ambito %ambito desde el %fechaI hasta %fechaF", array('%ambito' => strtoupper($ambito->name), '%fechaI' => format_date($FIPMI), '%fechaF' => format_date($FIPMF)));
1769        }
1770      }
1771    }
1772    if (is_numeric($ente_planificador) || user_access('admin all planificador')) { //si es el administrador se aplica la fecha especial
1773      $mi_fecha = array(
1774        variable_get('ente_planificador_' . $type_proceso . '_admin_from', $now),
1775        variable_get('ente_planificador_' . $type_proceso . '_admin_until', $now),
1776      );
1777      $new_mensaje = t("Como usuario administrador puede acceder desde %fechaI hasta %fechaF", array('%fechaI' => format_date($mi_fecha[0]), '%fechaF' => format_date($mi_fecha[1])));
1778    }
1779    if (in_array($rol_macro, array_keys($user->roles))) { //es usuario control
1780      $mi_fecha = array(
1781        variable_get('ente_planificador_' . $type_proceso . '_control_from', $now),
1782        variable_get('ente_planificador_' . $type_proceso . '_control_until', $now),
1783      );
1784      $new_mensaje = t("Como usuario Control puede acceder desde %fechaI hasta %fechaF", array('%fechaI' => format_date($mi_fecha[0]), '%fechaF' => format_date($mi_fecha[1])));
1785    }
1786  }
1787}
Nota: Vea TracBrowser para ayuda de uso del navegador del repositorio.