source: sipes/0.3-modules/proyectos_operativos_mcti/proyectos_operativos_mcti.module @ 2fa3319

stableversion-3.0
Last change on this file since 2fa3319 was 303fae2, checked in by José Gregorio Puentes <jpuentes@…>, 9 años ago

se agregaron los modulos

  • Propiedad mode establecida a 100755
File size: 146.2 KB
Línea 
1<?php
2  /**
3  * Sistema Integral de Planificación y Presupuesto (SIPP)
4  * @file proyectos_operativos_mcti.module
5  * Drupal part Module to Sistema Integral de Planificación y Presupuesto (SIPP)
6  * Copyright 2013 Sistema Automatizado para la Planificación Estratégico-Situacional en la Administración Pública Venezolana (CENDITEL)
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
21  *
22  * @author Cenditel Merida - Ing. Jose Puentes
23  * @date 2014-12-04 // (a&#241;o-mes-dia)
24  * @version 0.1 // (0.1)
25  *
26  */
27
28/*
29 * Implementation of hook_menu()
30 */
31function proyectos_operativos_mcti_menu()  {
32  $items = array();
33  $items['proyectos_operativos_mcti_proyecto_generales_agrega_talento_js_util'] = array(
34    'title' => 'JS utilities',
35    'page callback' => 'proyectos_operativos_mcti_proyecto_generales_agrega_talento_js_util',
36    'access arguments' => array('ver planificador'),
37    'type' => MENU_CALLBACK,
38  );
39  $items['proyectos_operativos_mcti_agrega_indicadores_js_util'] = array(
40    'title' => 'JS utilities',
41    'page callback' => 'proyectos_operativos_mcti_agrega_indicadores_js_util',
42    'access arguments' => array('ver planificador'),
43    'type' => MENU_CALLBACK,
44  );
45  $items['proyectos_operativos_mcti_proyecto_basico_form_responsables'] = array(
46    'title' => 'JS utilities',
47    'page callback' => 'proyectos_operativos_mcti_proyecto_basico_form_responsables_js_util',
48    'access arguments' => array('ver planificador'),
49    'type' => MENU_CALLBACK,
50  );
51  $items['proyectos_operativos_mcti_proyecto_basico_form_cargar_responsables'] = array(
52    'title' => 'JS utilities',
53    'page callback' => 'proyectos_operativos_mcti_proyecto_basico_form_cargar_responsables_js_util',
54    'access arguments' => array('ver planificador'),
55    'type' => MENU_CALLBACK,
56  );
57  return $items;
58}
59
60/**
61 * Implementation of hook_theme().
62 */
63function proyectos_operativos_mcti_theme() {
64  $proyectos_operativos_path = drupal_get_path('module', 'proyectos_operativos_mcti') . '/templates';
65  return array(
66    'proyectos_operativos_mcti_ficha_proyecto' => array(
67      'arguments' => array(
68        'proyecto' => array(),
69      ),
70      'template' => 'proyectos-operativos-mcti-ficha-proyecto',
71      'path' => $proyectos_operativos_path,
72    ),
73  );
74}
75
76/*
77 * Impletations of hook_form_alter()
78 */
79function proyectos_operativos_mcti_form_alter(&$form, $form_state, $form_id) {
80  if (($form_id == 'views_exposed_form') && ($form['#id'] == 'views-exposed-form-ente-planificador-hierarchical-default')) {
81    global $user;
82    $ente_planificador = node_load($user->entes);
83    if ($form['organismo'] && ($ente_planificador->tipo == 2)) {
84      $roles2 = variable_get('roles_exclude_organismo', 0);
85      if ($roles2) {
86        foreach ($roles2 as $key2 => $rol2) {
87          if ($user->roles[$key2]) {
88            $form['#info']['filter-organismo']['label'] = 0;
89            $form['organismo']['#access'] = 0;
90            $form['#info']['filter-sector']['label'] = 0;
91            $form['sector']['#access'] = 0;
92            $form['#info']['filter-sub_sector']['label'] = 0;
93            $form['sub_sector']['#access'] = 0;
94            $form['#info']['filter-ambito']['label'] = 0;
95            $form['ambito']['#access'] = 0;
96          }
97        }
98      }
99    }
100    if ($form['ente_adscrito'] && ($ente_planificador->tipo == 3)) { //tercer nivel de Planificacion
101      $rolest3 = variable_get('roles_exclude_ente_asdcrito', 0);
102      if ($rolest3) {
103        foreach ($rolest3 as $key3 => $rol3) {
104          if ($user->roles[$key3]) {
105            $form['#info']['filter-organismo']['label'] = 0;
106            $form['organismo']['#access'] = 0;
107            $form['#info']['filter-ente_adscrito']['label'] = 0;
108            $form['ente_adscrito']['#access'] = 0;
109            $form['#info']['filter-sector']['label'] = 0;
110            $form['sector']['#access'] = 0;
111            $form['#info']['filter-sub_sector']['label'] = 0;
112            $form['sub_sector']['#access'] = 0;
113            $form['#info']['filter-ambito']['label'] = 0;
114            $form['ambito']['#access'] = 0;
115          }
116        }
117      }
118    }
119    if ($form['sub_ente_adscrito'] && ($ente_planificador->tipo == 4)) { //cuarto nivel de planificacion
120      $rolest4 = variable_get('roles_exclude_sub_ente_asdcrito', 0);
121      if ($rolest4) {
122        foreach ($rolest4 as $key4 => $rol4) {
123          if ($user->roles[$key4]) {
124            $form['#info']['filter-organismo']['label'] = 0;
125            $form['organismo']['#access'] = 0;
126            $form['#info']['filter-ente_adscrito']['label'] = 0;
127            $form['ente_adscrito']['#access'] = 0;
128            $form['#info']['filter-sub_ente_adscrito']['label'] = '';
129            $form['sub_ente_adscrito']['#access'] = 0;
130            $form['#info']['filter-sector']['label'] = 0;
131            $form['sector']['#access'] = 0;
132            $form['#info']['filter-sub_sector']['label'] = 0;
133            $form['sub_sector']['#access'] = 0;
134            $form['#info']['filter-ambito']['label'] = 0;
135            $form['ambito']['#access'] = 0;
136          }
137        }
138      }
139    }
140    if ($form['sub_sub_ente_adscrito'] && ($ente_planificador->tipo == 5)) { //quinto nivel de planificacion
141      $rolest5 = variable_get('roles_exclude_sub_sub_ente_adscrito', 0);
142      if ($rolest5) {
143        foreach ($rolest5 as $key5 => $rol5) {
144          if (!($user->roles[$key5])) {
145            $form['#info']['filter-organismo']['label'] = 0;
146            $form['organismo']['#access'] = 0;
147            $form['#info']['filter-ente_adscrito']['label'] = 0;
148            $form['ente_adscrito']['#access'] = 0;
149            $form['#info']['filter-sub_sub_ente_adscrito']['label'] = '';
150            $form['sub_sub_ente_adscrito']['#access'] = 0;
151            $form['#info']['filter-sub_ente_adscrito']['label'] = '';
152            $form['sub_ente_adscrito']['#access'] = 0;
153            $form['#info']['filter-sector']['label'] = 0;
154            $form['sector']['#access'] = 0;
155            $form['#info']['filter-sub_sector']['label'] = 0;
156            $form['sub_sector']['#access'] = 0;
157            $form['#info']['filter-ambito']['label'] = 0;
158            $form['ambito']['#access'] = 0;
159          }
160        }
161      }
162    }
163    if ($form['ambito'] && ($ente_planificador->tipo ==  1)) {
164      $rolesa = variable_get('roles_exclude_ambito', 0);
165      if ($rolesa) {
166        foreach ($rolesa as $keya => $rola) {
167          if (($user->roles[$keya])) {
168            $form['#info']['filter-ambito']['label'] = t('Ambito del ente Planificador');
169            $form['ambito']['#access'] = 1;
170          }
171          else {
172            $form['#info']['filter-ambito']['label'] = 0;
173            $form['ambito']['#access'] = 0;
174          }
175        }
176      }
177    }
178    if ($form['sector'] && ($ente_planificador->tipo ==  1)) {
179      $roless = variable_get('roles_exclude_sector_social', 0);
180      if ($roless) {
181        foreach ($roless as $keys => $rols) {
182          if (($user->roles[$keys])) {
183            $form['#info']['filter-sector']['label'] = t('Sector Social del Ente Planificador');
184            $form['sector']['#access'] = 1;
185          }
186        }
187      }
188    }
189    if ($form['sub_sector'] && ($ente_planificador->tipo ==  1)) {
190      $roless = variable_get('roles_exclude_sub_sector_social', 0);
191      if ($rolesb) {
192        foreach ($rolesb as $keysb => $rolsb) {
193          if (($user->roles[$keysb])) {
194            $form['#info']['filter-sub_sector']['label'] = t('Sub-Sector Social del Ente Planificador');
195            $form['sub_sector']['#access'] = 1;
196          }
197        }
198      }
199    }
200  }
201  $name_workflow = $form['#wf']->name;
202  if ($form_id == 'workflow_tab_form' && $name_workflow == 'nuevo Proyecto') {
203    drupal_add_js(drupal_get_path('module', 'proyectos_operativos_mcti') . '/js/proyectos_operativos_mcti_datos_basicos.js'); 
204  }
205  //mostrar Balance Estimado Nacional de Servicios Energéticos
206  if ($form_id == 'proyectos_operativos_admin_settings') {
207    // formulario datos basicos
208    $form['basicos']['proyectos_operativos_muestra_proyecto_descripcion'] = array(
209      '#type' => 'checkbox',
210      '#title' => t('Recolectar la descripcion del proyecto.'),
211      '#weight' => 0,
212      '#default_value' => variable_get('proyectos_operativos_muestra_proyecto_descripcion', TRUE),
213    );
214    $form['basicos']['comuna'] = array(
215      '#title' => t('Comunas'),
216      '#type' => 'fieldset',
217      '#prefix' => '<div id="fields_datos_basicos_de_las_comunas">',
218      '#siffix' => '</div>',
219    );
220    $form['basicos']['comuna']['proyectos_operativos_muestra_codig_comuna'] = array(
221      '#type' => 'checkbox',
222      '#title' => t('Recolectar el codigo de la comuna.'),
223      '#default_value' => variable_get('proyectos_operativos_muestra_codig_comuna', TRUE),
224    );
225    $form['basicos']['comuna']['proyectos_operativos_muestra_ubicacin_comuna'] = array(
226      '#type' => 'checkbox',
227      '#title' => t('Recolectar la ubicacion de la comuna.'),
228      '#default_value' => variable_get('proyectos_operativos_muestra_ubicacin_comuna', TRUE),
229    );
230    $form['basicos']['comuna']['proyectos_operativos_muestra_name_comuna'] = array(
231      '#type' => 'checkbox',
232      '#title' => t('Recolectar el nombre de la comuna.'),
233      '#default_value' => variable_get('proyectos_operativos_muestra_name_comuna', TRUE),
234    );
235    $form['basicos']['responsables']['proyectos_operativos_muestra_responsables'] = array(
236      '#type' => 'checkbox',
237      '#title' => t('Recolectar los responsables del proyeto.'),
238      '#default_value' => variable_get('proyectos_operativos_muestra_responsables', TRUE),
239    );
240    $form['basicos']['proyectos_operativos_muestra_causas_abordadas'] = array(
241      '#type' => 'checkbox',
242      '#title' => t('Recolectar las causas abordadas.'),
243      '#weight' => 0,
244      '#default_value' => variable_get('proyectos_operativos_muestra_causas_abordadas', TRUE),
245          );
246          $form['basicos']['proyectos_operativos_muestra_problemas_abordados'] = array(
247      '#type' => 'checkbox',
248      '#title' => t('Recolectar los problemas abordados.'),
249      '#weight' => 0,
250      '#default_value' => variable_get('proyectos_operativos_muestra_problemas_abordados', TRUE),
251          );
252    // formulario datos generales
253    $form['generales']['proyectos_operativos_muestra_impacto_ambiental'] = array(
254      '#type' => 'checkbox',
255      '#title' => t('Recolectar el Impacto Ambiental del Proyecto.'),
256      '#default_value' => variable_get('proyectos_operativos_muestra_impacto_ambiental', TRUE),
257    );
258    $form['generales']['proyectos_operativos_muestra_servicios_balance'] = array(
259      '#type' => 'checkbox',
260      '#title' => t('Recolectar Balance Estimado Nacional de Servicios Energéticos.'),
261      '#default_value' => variable_get('proyectos_operativos_muestra_servicios_balance', TRUE),
262    );
263    $form['generales']['proyectos_operativos_muestra_programacion_anual'] = array(
264      '#type' => 'checkbox',
265      '#title' => t('Recolectar Programacion Anual por Consumidor.'),
266      '#default_value' => variable_get('proyectos_operativos_muestra_programacion_anual', TRUE),
267    );
268  }
269
270  if ($form_id == "proyectos_operativos_proyecto_genera_campos_form") {
271    $node_type = content_types('proyectos_operativos');
272    $fields = $node_type['fields'];
273    //programacion anual
274    if (variable_get('proyectos_operativos_muestra_impacto_ambiental', TRUE)) {
275      $arrreglo['impacto']['factor'] = array(
276        'field_tipo_factores' => 'field_tipo_factores',
277        'field_factor_impact_multifc' => 'field_factor_impact_multifc',
278        'field_factor_segun_origen' => 'field_factor_segun_origen',
279        'field_factor_impact_multiog' => 'field_factor_impact_multiog',
280        'field_factor_naturaleza' => 'field_factor_naturaleza',
281        'field_factor_intensidad' => 'field_factor_intensidad',
282        'field_factor_extension' => 'field_factor_extension',
283        'field_factor_momento' => 'field_factor_momento',
284        'field_factor_persistencia' => 'field_factor_persistencia',
285        'field_factor_reversibilidad' => 'field_factor_reversibilidad',
286        'field_factor_sinergismo' => 'field_factor_sinergismo',
287        'field_factor_acumulacion' => 'field_factor_acumulacion',
288        'field_factor_relacion' =>'field_factor_relacion',
289        'field_factor_recuperabilidad' => 'field_factor_recuperabilidad',
290        'field_factor_importancia' => 'field_factor_importancia',
291        'field_factor_medids_impact' => 'field_factor_medids_impact',
292      );
293    }
294    if (variable_get('proyectos_operativos_muestra_servicios_balance', TRUE)) {
295      $arrreglo['servicios']['balance'] = array(
296       'field_balnc_progrmn_anu' => 'field_balnc_progrmn_anu',
297        'field_balance_fuente' => 'field_balance_fuente',
298        'field_balanc_tipofuent' => 'field_balanc_tipofuent',
299        'field_balanc_tipoProd' => 'field_balanc_tipoProd',
300        'field_balanc_unidMed' => 'field_balanc_unidMed',
301        'field_balanc_capacid' => 'field_balanc_capacid',
302        'field_balanc_anho' => 'field_balanc_anho',
303      );
304    }
305    if (variable_get('proyectos_operativos_muestra_responsables', TRUE)) {
306      $arreglo['responsables']['gerente'] = array(
307        'field_proyecto_nombre_gere' => 'field_proyecto_nombre_gere',
308        'field_proyecto_cedul_gere' => 'field_proyecto_cedul_gere',
309        'field_proyecto_corre_gere' => 'field_proyecto_corre_gere',
310        'field_proyecto_telef_gere' => 'field_proyecto_telef_gere',
311      );
312      $arreglo['responsables']['tecnico'] = array(
313        'field_proyecto_nom_r_tec' => 'field_proyecto_nom_r_tec',
314        'field_proyecto_ced_r_tec' => 'field_proyecto_ced_r_tec',
315        'field_proyecto_cor_r_tec' => 'field_proyecto_cor_r_tec',
316        'field_proyecto_tel_r_tec' => 'field_proyecto_cor_r_tec',
317        'field_proyecto_und_r_tec' => 'field_proyecto_und_r_tec',
318      );
319      $arreglo['responsables']['registrador'] = array(
320        'field_proyecto_nom_r_reg' => 'field_proyecto_nom_r_reg',
321        'field_proyecto_ced_r_reg' => 'field_proyecto_ced_r_reg',
322        'field_proyecto_cor_r_reg' => 'field_proyecto_cor_r_reg',
323        'field_proyecto_tel_r_reg' => 'field_proyecto_tel_r_reg',
324      );
325      $arreglo['responsables']['administrativo'] = array(
326        'field_proyecto_nom_r_adm' => 'field_proyecto_nom_r_adm',
327        'field_proyecto_ced_r_adm' => 'field_proyecto_ced_r_adm',
328        'field_proyecto_cor_r_adm' => 'field_proyecto_cor_r_adm',
329        'field_proyecto_tel_r_adm' => 'field_proyecto_tel_r_adm',
330        'field_proyecto_und_r_adm' => 'field_proyecto_und_r_adm',
331      );
332    }
333    if (!isset($_SESSION['proyectos_operativos_mostrar_campos'][$form['#node']->nid]) || !count($_SESSION['proyectos_operativos_mostrar_campos'][$form['#node']->nid])) {
334      if (count($fields)) {
335        foreach ($fields as $id => $field) {
336          if (!$field['display_settings']['full']['exclude']) {
337            //programacion anual
338            if (array_key_exists($id, $arrreglo['servicios']['balance'])) {
339              $arreglo['servicios'][$id] = $field['widget']['label'];
340            }
341            if (array_key_exists($id, $arrreglo['impacto']['factor'])) {
342              $arreglo['impacto'][$id] = $field['widget']['label'];
343            }
344            if (array_key_exists($id, $arreglo['responsables']['gerente'])) {
345              $arreglo['gerente'][$id] = $field['widget']['label'];
346            }           
347            if (array_key_exists($id, $arreglo['responsables']['tecnico'])) {
348              $arreglo['tecnico'][$id] = $field['widget']['label'];
349            }
350            if (array_key_exists($id, $arreglo['responsables']['registrador'])) {
351              $arreglo['registrador'][$id] = $field['widget']['label'];
352            }
353            if (array_key_exists($id, $arreglo['responsables']['administrativo'])) {
354              $arreglo['administrativo'][$id] = $field['widget']['label'];
355            }
356          }
357          elseif (array_key_exists($id,  $arrreglo['servicios']['balance'])) {  //programacion anual
358           unset($arreglo['servicios'][$id]);
359          }
360          elseif (array_key_exists($id,  $arrreglo['impacto']['factor'])) {  //programacion anual
361            unset($arreglo['impacto'][$id]);
362          }
363          elseif (array_key_exists($id, $arreglo['responsables']['gerente'])) {  //gerente
364            unset($arreglo['gerente'][$id]);
365          }
366          elseif (array_key_exists($id,  $arreglo['responsables']['tecnico'])) {  //tecnico
367            unset($arreglo['tecnico'][$id]);
368          }
369          elseif (array_key_exists($id, $arreglo['responsables']['registrador'])) {  //registrador
370            unset($arreglo['registrador'][$id]);
371          }
372          elseif (array_key_exists($id, $arreglo['responsables']['administrativo'])) {  //administrativo
373            unset($arreglo['administrativo'][$id]);
374          }
375        }
376      }
377    }
378    $servicios = count($arreglo['servicios']);
379    $impacto = count($arreglo['impacto']);
380    $gerente = count($arreglo['gerente']);
381    $tecnico = count($arreglo['tecnico']);
382    $registrador = count($arreglo['registrador']);
383    $administrador = count($arreglo['administrativo']);
384    if($gerente) {
385      $form['db']['gerenteg'] = array(
386        '#type' => 'checkboxes',
387        '#options' => $arreglo['gerente'],
388        '#default_value' => array(),
389        '#title' => t('Datos del Gerente'),
390        '#multiple' => TRUE,
391      );
392      $title_combos['gerenteg']['title'] = t('Datos del Gerente.');
393    }
394    if($tecnico) {
395      $form['db']['gerentet'] = array(
396        '#type' => 'checkboxes',
397        '#options' => $arreglo['tecnico'],
398        '#default_value' => array(),
399        '#title' => t('Responsable Tecnico'),
400        '#multiple' => TRUE,
401      );
402      $title_combos['gerentet']['title'] = t('Responsable Tecnico.');
403    }
404    if ($registrador) {
405      $form['db']['gerenter'] = array(
406        '#type' => 'checkboxes',
407        '#options' => $arreglo['registrador'],
408        '#default_value' => array(),
409        '#title' => t('Responsable Registrador'),
410        '#multiple' => TRUE,
411      );
412      $title_combos['gerenter']['title'] = t('Responsable Registrador.');
413    }
414    if ($administrador) {
415      $form['db']['gerentea'] = array(
416        '#type' => 'checkboxes',
417        '#options' => $arreglo['administrativo'],
418        '#default_value' => array(),
419        '#title' => t('Responsable administrativo'),
420        '#multiple' => TRUE,
421      );
422      $title_combos['gerentea']['title'] = t('Responsable Administativo.');
423    }
424    if ($servicios) { ////Balance Estimado Nacional de Servicios Energéticos
425      $form['ip']['servicios'] = array(
426        '#type' => 'checkboxes',
427        '#options' => $arreglo['servicios'],
428        '#default_value' => array(),
429        '#title' => t('Balance Estimado Nacional de Servicios Energéticos'),
430        '#multiple' => TRUE,
431      );
432      $title_combos['servicios']['title'] = t('Balance Estimado Nacional de Servicios Energéticos');
433     }
434     if ($impacto) { //Impacto Ambiental del Proyecto
435      $form['ip']['impacto'] = array(
436        '#type' => 'checkboxes',
437        '#options' => $arreglo['impacto'],
438        '#default_value' => array(),
439        '#title' => t('Impacto Ambiental del Proyecto'),
440        '#multiple' => TRUE,
441      );
442      $title_combos['impacto']['title'] = t('Impacto Ambiental del Proyecto');
443    }
444    $form['#title_combos'] += $title_combos;
445    //$form['#submit'][] = 'proyectos_operativos_proyecto_genera_campos_form_submit';
446  }
447
448   // formulario indicadores del proyecto
449  if ($form_id == "proyectos_operativos_proyecto_indicadores_form") {
450    foreach ($form['#parameters'] as $id => $proyecto) {
451      if ($proyecto->type == 'proyectos_operativos') {
452        $proyecto = $proyecto;
453      }
454    }
455    if (!$proyecto) {
456      $proyecto_leido = new stdClass();
457      $proyecto_leido->type = 'proyectos_operativos';
458    }
459    else {
460      $proyecto_leido = $proyecto;
461    }
462    //$form['#node'] = $proyecto_leido;
463    $node_type = content_types('proyectos_operativos');
464    $fields = $node_type['fields'];
465    //$form['#proyecto_fields'] = $fields;
466    $field_form = array();
467    $fields_form = array();
468    $fields_extra_form = array();
469    //Programacion anual por consumidor
470    $programacion = variable_get('proyectos_operativos_muestra_programacion_anual', TRUE);
471    $current_year = date("Y");
472    $years[0] = t('Seleccione');
473    for ($i = $current_year - 10; $i <= $current_year; $i++) {
474       $years[$i] = $i;
475    }
476    if ($programacion) {
477      $arrreglo['programacion'] = array(
478        'field_progrmcn_anual_prog' => 'field_progrmcn_anual_prog',
479        'field_progrmcn_anual_unid' => 'field_progrmcn_anual_unid',
480        'field_progrmcn_anual_cap' => 'field_progrmcn_anual_cap',
481        'field_progrmcn_anual_anho' => 'field_progrmcn_anual_anho',
482      );
483      $form['programacion'] = array(
484        '#type' => 'fieldset',
485        '#title' => t('Programacion Anual por Consumidor'),
486        '#weight' => -1,
487      );
488      $prefixC = '';
489      $fields_extra_form1 = array();
490      foreach ($arrreglo['programacion'] as $field_id => $field) {
491        $fields_extra_form1[] = $field_id;
492        $prefixC .= '<th>' . $fields[$field_id]['widget']['label'] . '</th>';
493      }
494      $fields_extra_form['programacion'] = $fields_extra_form1;
495      $tamano_array = array();
496      foreach ($arrreglo['programacion'] as $field_id => $field) { 
497        $tamano_array[] = count($proyecto_leido->{$field_id});
498      }
499      $cantidad = max($tamano_array);
500      $prefix = '';
501      $aux = '';
502      $aui = '';
503      for ($i = 0; $i < $cantidad; $i++) {
504        if ($i == 0) {
505          $prefix = '<div id="programacion-anual-modificar"><table><tr>' . $prefixC . '</tr><tr><td>';
506        }
507        else {
508          $prefix .= '<tr><td>';
509        }
510        foreach ($arrreglo['programacion'] as $field_id => $field) {
511          if ($field == 'field_progrmcn_anual_anho') {
512            $valor = isset($proyecto_leido->{$field_id}[$i]) ? $proyecto_leido->{$field_id}[$i]['value'] : '';
513            $form['programacion'][$field . '_' . $i] = array(
514              '#type' => 'select',
515              '#default_value' => $valor,
516              '#size' => $fields[$field_id]['size'],
517              '#maxlength' => $fields[$field_id]['max_length'],
518                                                        '#required' => $fields[$field_id]['required'],
519                                                        '#options' => $years,
520                                                        '#prefix' => $prefix,
521              '#suffix' => '</td>',
522            );
523          }
524                elseif ($field == 'field_progrmcn_anual_cap') {
525            $valor = isset($proyecto_leido->{$field_id}[$i]) ? $proyecto_leido->{$field_id}[$i]['value'] : '';
526            $form['programacion'][$field . '_' . $i] = array(
527              '#type' => 'textfield',
528              '#default_value' => $valor,
529              '#size' => $fields[$field_id]['size'],
530              '#maxlength' => $fields[$field_id]['max_length'],     
531              '#prefix' => $prefix,
532              '#suffix' => '</td>',
533            );
534          }
535          else {
536            $options = optionwidgets_options($fields[$field_id], FALSE);
537            $valor = isset($proyecto_leido->{$field_id}[$i]) ? $proyecto_leido->{$field_id}[$i]['value'] : 0;
538            $form['programacion'][$field . '_' . $i] = array(
539              '#type' => 'select',   
540              '#default_value' => $valor,
541              '#options' => $options,         
542              '#prefix' => $prefix,
543              '#suffix' => '</td>',
544            );
545          }
546          $aux = $field_id;
547          $aui = $i;
548          $prefix = '<td>';
549        }
550        $form['programacion'][$aux . '_' . $aui]['#suffix'] .= '</tr>';
551      }
552      $form['programacion'][$aux . '_' . $aui]['#suffix'] .= '</table>';
553      $form['programacion']['cantidad_programacion'] = array('#type' => 'hidden', '#value' => $cantidad, '#suffix' => '</div>');
554      $form['programacion']['agrega_' . 'programacion'] = array(
555        '#type' => 'submit',
556        '#value' => t('Agregar otro campo'),
557        '#weight' => 100,
558        '#ahah' => array(
559          'path' => 'proyectos_operativos_mcti_agrega_indicadores_js_util/programacion',
560          'wrapper' => 'programacion-anual-modificar',
561          'method' => 'replace',
562          'progress' => array('type' => 'bar', 'message' => t('Please wait...')),
563        ),
564      );
565    }
566    //Balance Estimado Nacional de Servicios Energéticos
567    $balance = variable_get('proyectos_operativos_muestra_servicios_balance', TRUE);
568    if ($balance) {
569      $arrreglo['servicios'] = array(
570        'field_balnc_progrmn_anu' => 'field_balnc_progrmn_anu',
571        'field_balance_fuente' => 'field_balance_fuente',
572        'field_balanc_tipofuent' => 'field_balanc_tipofuent',
573        'field_balanc_tipoProd' => 'field_balanc_tipoProd',
574        'field_balanc_unidMed' => 'field_balanc_unidMed',
575        'field_balanc_capacid' => 'field_balanc_capacid',
576        'field_balanc_anho' => 'field_balanc_anho',
577     );
578     $form['balance'] = array(
579       '#type' => 'fieldset',
580       '#title' => t('Balance Estimado Nacional de Servicios Energéticos'),
581       '#weight' => -1,
582     );
583     $prefixC = '';
584     $fields_extra_form1 = array();
585     foreach ($arrreglo['servicios'] as $field_id => $field) {
586       $fields_extra_form1[] = $field_id;
587       $prefixC .= '<th>' . $fields[$field_id]['widget']['label'] . '</th>';
588     }
589     $fields_extra_form['balance'] = $fields_extra_form1;
590     $tamano_array = array();
591     foreach ($arrreglo['servicios'] as $field_id => $field) { 
592       $tamano_array[] = count($proyecto_leido->{$field_id});
593     }
594     $cantidad = max($tamano_array);
595     $prefix = '';
596     $aux = '';
597     $aui = '';
598     for ($i = 0; $i < $cantidad; $i++) {
599       if ($i == 0) {
600         $prefix = '<div id="balance-servicios-modificar"><table><tr>' . $prefixC . '</tr><tr><td>';
601       }
602       else {
603         $prefix .= '<tr><td>';
604       }
605       foreach ($arrreglo['servicios'] as $field_id => $field) {
606             if ($field == 'field_balanc_anho') {
607           $valor = isset($proyecto_leido->{$field_id}[$i]) ? $proyecto_leido->{$field_id}[$i]['value'] : '';
608           $form['balance'][$field . '_' . $i] = array(
609             '#type' => 'select',
610             '#default_value' => $valor,
611             '#maxlength' => $fields[$field_id]['max_length'],
612                                                 '#required' => $fields[$field_id]['required'],
613             '#options' => $years,
614                                                 '#prefix' => $prefix,
615             '#suffix' => '</td>',
616           );
617         }
618               elseif ($field == 'field_balanc_capacid') {
619           $valor = isset($proyecto_leido->{$field_id}[$i]) ? $proyecto_leido->{$field_id}[$i]['value'] : '';
620           $form['balance'][$field . '_' . $i] = array(
621             '#type' => 'textfield',
622             '#default_value' => $valor,
623             '#size' => $fields[$field_id]['size'],
624             '#maxlength' => $fields[$field_id]['max_length'],     
625             '#prefix' => $prefix,
626             '#suffix' => '</td>',
627           );
628         }
629         else {
630           $options = optionwidgets_options($fields[$field_id], FALSE);
631           $valor = isset($proyecto_leido->{$field_id}[$i]) ? $proyecto_leido->{$field_id}[$i]['value'] : 0;
632           $form['balance'][$field . '_' . $i] = array(
633             '#type' => 'select',   
634             '#default_value' => $valor,
635             '#options' => $options,         
636             '#prefix' => $prefix,
637             '#suffix' => '</td>',
638           );
639         }
640         $aux = $field_id;
641         $aui = $i;
642         $prefix = '<td>';
643       }
644       $form['balance'][$aux . '_' . $aui]['#suffix'] .= '</tr>';
645     }
646     $form['balance'][$aux . '_' . $aui]['#suffix'] .= '</table>';
647     $form['balance']['cantidad_balance'] = array('#type' => 'hidden', '#value' => $cantidad, '#suffix' => '</div>');
648     $form['balance']['agrega_' . 'balance'] = array(
649       '#type' => 'submit',
650       '#value' => t('Agregar otro campo'),
651       '#weight' => 100,
652       '#ahah' => array(
653         'path' => 'proyectos_operativos_mcti_agrega_indicadores_js_util/balance',
654         'wrapper' => 'balance-servicios-modificar',
655         'method' => 'replace',
656         'progress' => array('type' => 'bar', 'message' => t('Please wait...')),
657        ),
658      );
659    }
660    $form['#proyectos_operativos_fields_extra'][] = $fields_extra_form;
661    //impacto ambiental del proyecto
662    $servicios = variable_get('proyectos_operativos_muestra_impacto_ambiental', TRUE);
663    $arrreglo['factor']  = array();
664    if ($servicios) {
665      $field_form = array();
666      $fields_form = array();
667      $arrreglo['factor'] = array(
668        'field_tipo_factores' => 'field_tipo_factores',
669        'field_factor_impact_multifc' => 'field_factor_impact_multifc',
670        'field_factor_segun_origen' => 'field_factor_segun_origen',
671        'field_factor_impact_multiog' => 'field_factor_impact_multiog',
672        'field_factor_naturaleza' => 'field_factor_naturaleza',
673        'field_factor_intensidad' => 'field_factor_intensidad',
674        'field_factor_extension' => 'field_factor_extension',
675        'field_factor_momento' => 'field_factor_momento',
676        'field_factor_persistencia' => 'field_factor_persistencia',
677        'field_factor_reversibilidad' => 'field_factor_reversibilidad',
678        'field_factor_sinergismo' => 'field_factor_sinergismo',
679        'field_factor_acumulacion' => 'field_factor_acumulacion',
680        'field_factor_relacion' =>'field_factor_relacion',
681        'field_factor_recuperabilidad' => 'field_factor_recuperabilidad',
682        'field_factor_importancia' => 'field_factor_importancia',
683        'field_factor_medids_impact' => 'field_factor_medids_impact',
684      );
685      $fields_form_factor = array();
686      if (is_array($fields) && count($fields)) {
687        foreach ($fields as $field_id => $field) {
688          if (array_key_exists($field_id, $arrreglo['factor'])) {
689            $field_form[] = $field_id;
690            $fields_form[] = $field_id;
691          }
692          elseif (variable_get('proyectos_operativos_muestra_factor_' . $field_id, FALSE)) {
693            $fields_form_factor[$field_id] = $field_id;
694            $field_form[] = $field_id;
695            $fields_form[] = $field_id;
696          }
697        }
698      }
699      $form['#impacto_ambientales'] = $fields_form_factor;
700    }
701    $form['#proyectos_operativos_fields'] = array_merge($form['#proyectos_operativos_fields'], $fields_form);
702   
703    if (is_array($field_form) && count($field_form)) {
704      module_load_include('inc', 'content', 'includes/content.node_form');
705      foreach ($field_form as $field_id) {
706        $field = content_fields($field_id, 'proyectos_operativos');
707        $form['#field_info'][$field_id] = $field;
708        $form += (array) content_field_form($form, $form_state, $field);
709      }
710    }
711    $form['#submit'][] = 'proyectos_operativos_mcti_agrega_indicadores_form_submit';
712  }
713  //formulario datos basicos de los proyectos operativos
714  if ($form_id == "proyectos_operativos_proyecto_basico_form") {
715    drupal_add_js(drupal_get_path('module', 'proyectos_operativos_mcti') . '/js/proyectos_operativos_mcti_datos_basicos.js');
716    $node_type = content_types('proyectos_operativos');
717    $fields = $node_type['fields'];
718    $field_form = array();
719    $fields_form = array();
720    $fields_extra_form = array();
721    $fields_extra_form1 = array();
722    //nid node
723    foreach ($form['#parameters'] as $id => $proyecto) {
724      if ($proyecto->type == 'proyectos_operativos') {
725        $proyecto = $proyecto;
726      }
727    }
728    if (!$proyecto) {
729      $proyecto_leido = new stdClass();
730      $proyecto_leido->type = 'proyectos_operativos';
731    }
732    else {
733      $proyecto_leido = $proyecto;
734    }
735    //responsables de los proyectos
736        $responsables_proye = variable_get('proyectos_operativos_muestra_responsables', TRUE);
737    if ($responsables_proye) {
738      $arreglo = array();
739      $field_form = array();
740      $fields_form = array();
741      $fields_extra_form1 = array();
742      global $user;
743      $form['responsables'] = array(
744        '#title' => t(''),
745        '#type' => 'fieldset',
746        '#prefix' => '<div id="wrapper-proyectos-resposab">',
747        '#suffix' => '</div>',
748      );
749      /*creando en campo field_proyecto_ente dentro de responsables
750      unset($form['field_proyecto_ente']);
751      $query_ins = db_query("SELECT nid, title FROM {node} WHERE type='ente_planificador' AND status=1 ORDER BY title");
752      while ($row = db_fetch_object($query_ins)) {
753              $instituciones[$row->nid] = $row->title;
754      }
755      $ente[$user->entes] = $instituciones[$user->entes]; //se establece la institucion por defecto
756      $form['responsables']['field_proyecto_ente'] = array(
757        '#title' => t('Insitución'),
758        '#type' => 'select',
759        //'#options' => $instituciones,
760        '#options' => $ente,
761        /*'#ahah' => array(
762          'path' => 'proyectos_operativos_mcti_proyecto_basico_form_responsables/responsables',
763          'wrapper' => 'wrapper-proyectos-resposab',
764          'method' => 'replace',
765          'progress' => array('type' => 'throbber', 'message' => t('Please wait...')),
766        ),*
767        '#default_value' => $ente,
768        '#prefix' => '<div id="field_proyecto_ente_datos_basicos">',
769        '#suffix' => '</div>',
770      );
771      if (!user_access('admin planificador')) {
772        $form['responsables']['field_proyecto_ente']['#pre_render'][] = 'proyectos_operativos_proyecto_ente_field_pre_render';
773      }*/
774      $ente_agregar = $form['#parameters'][3];
775      $ente_planificador = 0;
776      if ($proyecto && $proyecto->nid && $proyecto->field_proyecto_ente[0]['nid']) {
777        $ente_planificador = ente_planificador_leer_ente_planificadores($proyecto->field_proyecto_ente[0]['nid']);
778      }
779      else {
780        $ente = usuario_tiene_ente($user->uid);
781        if ($ente && $ente->nid) {
782          $ente_planificador = ente_planificador_leer_ente_planificadores($ente->nid);
783        }
784        elseif($ente_agregar && user_access('admin planificador')) {
785          $ente_planificador = ente_planificador_leer_ente_planificadores($ente_agregar);
786        }
787      }
788      $options[$ente_planificador->nid] = $ente_planificador->title;
789      $form['responsables']['field_proyecto_entes'] = array(
790        '#title' => t('Insitución'),
791        '#type' => 'select',
792        //'#options' => $instituciones,
793        '#options' => $options,
794        '#default_value' => $options,
795        '#prefix' => '<div id="field_proyecto_ente_datos_basicos">',
796        '#suffix' => '</div>',
797      );
798      $arreglo = array();
799      $tipos = array(
800        'gerente' => 'gerente',
801        'tecnico' => 'tecnico',
802        'registrador' => 'registrador',
803        'administrativo' => 'administrativo',
804      );
805      $arreglo['gerente'] = array(
806        0 => 'field_proyecto_nombre_gere',
807        1 => 'field_proyecto_cedul_gere',
808        2 => 'field_proyecto_corre_gere',
809        3 => 'field_proyecto_telef_gere',
810      );
811      $arreglo['tecnico'] = array(
812        0 => 'field_proyecto_nom_r_tec',
813        1 => 'field_proyecto_ced_r_tec',
814        2 => 'field_proyecto_cor_r_tec',
815        3 => 'field_proyecto_tel_r_tec',
816        4 => 'field_proyecto_und_r_tec',
817      );
818      $arreglo['registrador'] = array(
819        0 => 'field_proyecto_nom_r_reg',
820        1 => 'field_proyecto_ced_r_reg',
821        2 => 'field_proyecto_cor_r_reg',
822        3 => 'field_proyecto_tel_r_reg',
823      );
824      $arreglo['administrativo'] = array(
825        0 => 'field_proyecto_nom_r_adm',
826        1 => 'field_proyecto_ced_r_adm',
827        2 => 'field_proyecto_cor_r_adm',
828        3 => 'field_proyecto_tel_r_adm',
829        4 => 'field_proyecto_und_r_adm',
830      );   
831      $fields_form_administrativo = array();
832     
833      $query["gerente"] = db_query("SELECT DISTINCT(pp.field_proyecto_cedul_gere_value) as field_proyecto_cedul_gere, pp.vid, pp.field_proyecto_nombre_gere_value as field_proyecto_nombre_gere  FROM {node} as n INNER JOIN {proyectos_operativos} as p ON n.nid=p.nid INNER JOIN {content_type_proyectos_operativos} as pp ON pp.nid = p.nid WHERE n.type='proyectos_operativos' AND p.ente=%d AND n.vid=pp.vid AND n.status=1 ORDER BY pp.vid DESC", $user->entes); 
834      $query["tecnico"] = db_query("SELECT pp.vid, pp.field_proyecto_nom_r_tec_value as field_proyecto_nom_r_tec, pp.field_proyecto_ced_r_tec_value as field_proyecto_ced_r_tec FROM {node} as n INNER JOIN {proyectos_operativos} as p ON n.nid=p.nid INNER JOIN {content_type_proyectos_operativos} as pp ON pp.nid = p.nid WHERE n.type='proyectos_operativos' AND p.ente=%d AND n.vid=pp.vid AND n.status=1 ORDER BY pp.vid DESC", $user->entes);
835      $query["registrador"] = db_query("SELECT pp.vid, pp.field_proyecto_nom_r_reg_value as field_proyecto_nom_r_reg, pp.field_proyecto_ced_r_reg_value as field_proyecto_ced_r_reg FROM {node} as n INNER JOIN {proyectos_operativos} as p ON n.nid=p.nid INNER JOIN {content_type_proyectos_operativos} as pp ON pp.nid = p.nid WHERE n.type='proyectos_operativos' AND p.ente=%d AND n.vid=pp.vid AND n.status=1 ORDER BY pp.vid DESC", $user->entes);
836      $query["administrativo"] = db_query("SELECT pp.vid, pp.field_proyecto_nom_r_adm_value as field_proyecto_nom_r_adm, field_proyecto_ced_r_adm_value as field_proyecto_ced_r_adm FROM {node} as n INNER JOIN {proyectos_operativos} as p ON n.nid=p.nid INNER JOIN {content_type_proyectos_operativos} as pp ON pp.nid = p.nid WHERE n.type='proyectos_operativos' AND p.ente=%d AND n.vid=pp.vid AND n.status=1 ORDER BY pp.vid DESC", $user->entes);
837     
838      $field_form = array();
839      $fields_form = array();
840      $fields_extra_form1 = array();
841      $fields_extra_form1[] = 'field_proyecto_ente';
842     
843      foreach ($tipos as $tips => $tip) {
844              $tam = '';
845        $prefixC = '';
846                    $count = 0;
847        $options = array();
848        $options[0] = t('Seleccione');
849        while ($row = db_fetch_object($query[$tip])) {
850          if ($row->$arreglo[$tip][0] != '' && $row->$arreglo[$tip][1] != '') {
851            $options[$row->vid] = $row->$arreglo[$tip][0] .'('. $row->$arreglo[$tip][1] .')';
852          }
853        }
854        $tamano = array_keys($options);
855        $tamano = $tamano[1]+1;
856        $options[$tamano] = t('Nuevo');
857        $form['responsables']['default_'.$tip] = array(
858          '#type' => 'select',
859          '#title' => t('Cargar datos del '.$tip),
860          '#default_value' => $form['#node']->vid,
861          '#options' => $options,
862          '#prefix' => '<fieldset id="wrapper-'.$tip.'-datos"><legend>' . t('Responsable '.$tip ) . '</legend>',
863        );
864        $tam['tamano']['default_'.$tip] = $tamano;
865        drupal_add_js($tam, 'setting');
866
867        if (count($fields)) {
868                foreach ($arreglo[$tip] as $field_id => $field) {
869            $fields_extra_form1[] = $field;
870            $prefixC .= '<th>' . $fields[$field]['widget']['label'] . '</th>';
871          }
872          $fields_extra_form[$tip] = $fields_extra_form1;
873          foreach ($arreglo[$tip] as $field_id => $field) {
874                                  if ($proyecto_leido->{$field}) {
875                                        foreach($proyecto_leido->{$field} as $id => $campo) {
876                                        if ($proyecto_leido->{$field}[$id]['value']) {
877                                                        $default = $proyecto_leido->{$field}[$id]['value'];     
878                                        }
879                                        elseif ($proyecto_leido->{$field}[$id]['email']) {
880                                        $default = $proyecto_leido->{$field}[$id]['email'];
881                                  }
882                                  else {
883                                            $default = $form_state['values'][$field];
884                                        }
885                          }
886                                  }
887                  $consulta['valores'][$tip][$id] = $default;
888                  drupal_add_js($consulta, 'setting');
889               
890                        $prefix = '';
891                        if ($count == 0) {
892              $prefix = '<div id="default_'.$tip.'"><table><tr>' . $prefixC . '</tr><tr><td>';
893            }
894            else {
895              $prefix .= '<td>';
896            }
897            $form['responsables'][$field] = array(
898              '#type' => 'textfield',
899              '#required' => $fields[$field]['required'],
900              '#maxlength' => $fields[$field]['max_length'],
901              '#size' => $fields[$field]['size'],
902              '#weight' => $fields[$field]['weight'],
903              '#description' => $fields[$field]['description'],
904              '#default_value' => $default,
905              '#prefix' => $prefix,
906              '#suffix' => '</td>',
907            );
908            if($field == 'field_proyecto_cedul_gere' || $field == 'field_proyecto_ced_r_tec' || $field == 'field_proyecto_ced_r_reg' || $field == 'field_proyecto_ced_r_adm') {
909              $form['responsables'][$field]['#attributes'] = array(
910                'placeholder' => t( 'VXXXXXXXX' ),
911              );
912                                  }
913            if($field == 'field_proyecto_telef_gere' || $field == 'field_proyecto_tel_r_tec' || $field == 'field_proyecto_tel_r_reg' || $field == 'field_proyecto_tel_r_adm') {
914              $form['responsables'][$field]['#attributes'] = array(
915                'placeholder' => t( 'xxxx-xxxx-xxx' ),
916              );
917                        }
918            $aux = $field;
919                        $count++;
920          }
921          $form['responsables'][$aux]['#suffix'] .= '</tr>';
922          $form['responsables'][$aux]['#suffix'] .= '</table></div></fieldset>';
923        }
924      } //fin del foreach
925     
926      $form['responsables'][$aux]['#suffix'] .= '</div>';
927      foreach ($tipos as $tips => $tip) {
928        if (is_array($fields) && count($fields)) {
929                                  foreach ($fields as $field_id => $field) {
930            foreach ($arreglo[$tip] as $clave => $campo) {
931                                if ($campo == $field_id) {
932                $field_form[] = $field_id;
933                $fields_form[] = $field_id;
934                                  }
935              elseif (variable_get('proyectos_operativos_muestra_gerente_' . $field_id, FALSE)) {
936                $fields_form_tipos_gerentes[$field_id] = $field_id;
937                $field_form[] = $field_id;
938                $fields_form[] = $field_id;
939              }
940                          }
941          }
942        }
943      }
944      $field_form = array();
945            $form['#fields_form_tipos'] = $fields_form_tipos_gerentes;
946   
947      //tipos resposanbles del proyecto
948      $resposables = array(
949        0 => 'gerente',
950        1 => 'tecnico',
951        2 => 'registrador',
952        3 => 'administrativo',
953      );
954      $resposables['responsables'] = drupal_to_js($resposables);
955      drupal_add_js($resposables, 'setting');
956   
957      //pasando los datos a javascript en formato JSON
958      $proyectos = array();
959      $query = db_query("SELECT DISTINCT(pp.vid), n.title, p.ente, pp.field_proyecto_nombre_gere_value, pp.field_proyecto_cedul_gere_value, pp.field_proyecto_corre_gere_email, pp.field_proyecto_telef_gere_value FROM {node} as n INNER JOIN {proyectos_operativos} as p ON n.nid=p.nid INNER JOIN {content_type_proyectos_operativos} as pp ON pp.nid = p.nid WHERE n.type='proyectos_operativos' AND n.vid=pp.vid AND n.status=1 ORDER BY pp.vid DESC");
960      while($row = db_fetch_object($query)) {
961        //estructura del gerente => nid del proyecto, ente o institucion, nombre, cedula, correo, telefono
962        $proyectg[] = array($row->vid, $row->ente, $row->field_proyecto_nombre_gere_value, $row->field_proyecto_cedul_gere_value, $row->field_proyecto_corre_gere_email, $row->field_proyecto_telef_gere_value);
963      }
964      $proyectos['gerente'] = drupal_to_js($proyectg);
965      drupal_add_js($proyectos, 'setting');
966   
967      $proyectos = array();
968      $query = db_query("SELECT DISTINCT(pp.vid), n.title, p.ente, pp.field_proyecto_nom_r_tec_value, pp.field_proyecto_ced_r_tec_value, pp.field_proyecto_cor_r_tec_email, pp.field_proyecto_tel_r_tec_value, pp.field_proyecto_und_r_tec_value FROM {node} as n INNER JOIN {proyectos_operativos} as p ON n.nid=p.nid INNER JOIN {content_type_proyectos_operativos} as pp ON pp.nid = p.nid WHERE n.type='proyectos_operativos' AND n.vid=pp.vid AND n.status=1 ORDER BY pp.vid DESC");
969      while($row = db_fetch_object($query)) {
970         //estructura del gerente => nid del proyecto, ente o institucion, nombre, cedula, correo, telefono
971        $proyectt[] = array($row->vid, $row->ente, $row->field_proyecto_nom_r_tec_value, $row->field_proyecto_ced_r_tec_value, $row->field_proyecto_cor_r_tec_email, $row->field_proyecto_tel_r_tec_value, $row->field_proyecto_und_r_tec_value);
972      }
973      $proyectos['tecnico'] = drupal_to_js($proyectt);
974      drupal_add_js($proyectos, 'setting');
975   
976      $proyectos = array();
977      $query = db_query("SELECT DISTINCT(pp.vid), n.title, p.ente, pp.field_proyecto_nom_r_reg_value, pp.field_proyecto_ced_r_reg_value, pp.field_proyecto_cor_r_reg_email, pp.field_proyecto_tel_r_reg_value FROM {node} as n INNER JOIN {proyectos_operativos} as p ON n.nid=p.nid INNER JOIN {content_type_proyectos_operativos} as pp ON pp.nid = p.nid WHERE n.type='proyectos_operativos' AND n.vid=pp.vid AND n.status=1 ORDER BY pp.vid DESC");
978      while($row = db_fetch_object($query)) {
979        //estructura del gerente => nid del proyecto, ente o institucion, nombre, cedula, correo, telefono
980        $proyectr[] = array($row->vid, $row->ente, $row->field_proyecto_nom_r_reg_value, $row->field_proyecto_ced_r_reg_value, $row->field_proyecto_cor_r_reg_email     , $row->field_proyecto_tel_r_reg_value);
981      }
982      $proyectos['registrador'] = drupal_to_js($proyectr);
983      drupal_add_js($proyectos, 'setting');
984   
985      $proyectos = array();
986      $query = db_query("SELECT DISTINCT(pp.vid), n.title, p.ente, pp.field_proyecto_nom_r_adm_value, pp.field_proyecto_ced_r_adm_value, pp.field_proyecto_cor_r_adm_email, pp.field_proyecto_tel_r_adm_value, pp.field_proyecto_und_r_adm_value FROM {node} as n INNER JOIN {proyectos_operativos} as p ON n.nid=p.nid INNER JOIN {content_type_proyectos_operativos} as pp ON pp.nid = p.nid WHERE n.type='proyectos_operativos' AND n.vid=pp.vid AND n.status=1 ORDER BY pp.vid DESC");
987      while($row = db_fetch_object($query)) {
988        //estructura del gerente => nid del proyecto, ente o institucion, nombre, cedula, correo, telefono
989        $proyecta[] = array($row->vid, $row->ente, $row->field_proyecto_nom_r_adm_value, $row->field_proyecto_ced_r_adm_value, $row->field_proyecto_cor_r_adm_email, $row->field_proyecto_tel_r_adm_value, $row->field_proyecto_und_r_adm_value);
990      }
991      $proyectos['administrativo'] = drupal_to_js($proyecta);
992      drupal_add_js($proyectos, 'setting');
993   
994      $form['#proyectos_operativos_fields'] = array_merge($form['#proyectos_operativos_fields'], $fields_form);
995      if (is_array($field_form) && count($field_form)) {
996        module_load_include('inc', 'content', 'includes/content.node_form');
997        foreach ($field_form as $field_id) {
998          $field = content_fields($field_id, 'proyectos_operativos');
999          $form['#field_info'][$field_id] = $field;
1000          $form += (array) content_field_form($form, $form_state, $field);
1001        }
1002      }
1003      //agregando los niveles a los campos ubicacion y comuna
1004                  /*$form['field_proyecto_ubicaci_comu']['tids']['#config']['level_labels'][ 'status'] = 1;
1005      $form['field_proyecto_ubicaci_comu']['tids']['#config']['level_labels'][ 'labels'][1] = t('Municipio');
1006      $form['field_proyecto_ubicaci_comu']['tids']['#config']['level_labels'][ 'labels'][2] = t('Parroquia');
1007                  $form['field_proyecto_ubicaci_inter']['tids']['#config']['level_labels'][ 'status'] = 1;
1008      $form['field_proyecto_ubicaci_inter']['tids']['#config']['level_labels'][ 'labels'][1] = t('País');
1009      $form['field_proyecto_ubicaci_inter']['tids']['#config']['level_labels'][ 'labels'][2] = t('Estado');
1010      $form['field_proyecto_ubicaci_inter']['tids']['#config']['level_labels'][ 'labels'][3] = t('Municipio');
1011      $form['field_proyecto_ubicaci_inter']['tids']['#config']['level_labels'][ 'labels'][4] = t('Parroquia');*/
1012      $form['#validate'][] = 'proyectos_operativos_mcti_proyecto_basico_form_responsables_validate';
1013    }//end responsables
1014
1015    //datos de la comuna
1016    $field_form = array();
1017    $fields_form = array();
1018    $fields_extra_form1 = array();
1019    $arreglo = array();
1020    $codig_comuna = variable_get('proyectos_operativos_muestra_codig_comuna', TRUE);
1021    if ($codig_comuna) {
1022            $fields_extra_form1[] = 'field_proyecto_codigo_comu';
1023            $fields_extra_form['ubicacion'] = $fields_extra_form1;
1024      $arreglo['field_proyecto_codigo_comu'] = 'field_proyecto_codigo_comu';
1025    }
1026    $ubicacin_comuna = variable_get('proyectos_operativos_muestra_ubicacin_comuna', TRUE);
1027    if ($ubicacin_comuna) {
1028            $fields_extra_form1[] = 'field_proyecto_ubicaci_comu';
1029            $fields_extra_form['ubicacion'] = $fields_extra_form1;
1030      $arreglo['field_proyecto_ubicaci_comu'] = 'field_proyecto_ubicaci_comu';
1031    }
1032    $nombre_comuna = variable_get('proyectos_operativos_muestra_name_comuna', TRUE);
1033    if ($nombre_comuna) {
1034            $fields_extra_form1[] = 'field_proyecto_nombres_cum';
1035            $fields_extra_form['ubicacion'] = $fields_extra_form1;
1036      $arreglo['field_proyecto_nombres_cum'] = 'field_proyecto_nombres_cum';
1037    }
1038    if ($codig_comuna || $ubicacin_comuna || $nombre_comuna) {
1039      $fields_form_comuna = array();
1040      if (is_array($fields) && count($fields)) {
1041        foreach ($fields as $field_id => $field) {
1042          if (array_key_exists($field_id, $arreglo)) {
1043            $field_form[] = $field_id;
1044            $fields_form[] = $field_id;
1045          }
1046          elseif (variable_get('proyectos_operativos_muestra_comuna_' . $field_id, FALSE)) {
1047            $fields_form_comuna[$field_id] = $field_id;
1048            $field_form[] = $field_id;
1049            $fields_form[] = $field_id;
1050          }
1051        }
1052      }
1053      $form['#fields_form_comuna'] = $fields_form_comuna;
1054    }
1055    //localizacion internacional del proyecto
1056    $arreglo = array();
1057    $localizacion = variable_get('proyectos_operativos_muestra_ubicaci_interna', TRUE);
1058    if ($localizacion) {
1059          $fields_extra_form1[] = 'field_proyecto_ubicaci_inter';
1060          $fields_extra_form['ubicacion'] = $fields_extra_form1;
1061      $arreglo['field_proyecto_ubicaci_inter'] = 'field_proyecto_ubicaci_inter';
1062      $fields_form_geo = array();
1063      if (is_array($fields) && count($fields)) {
1064        foreach ($fields as $field_id => $field) {
1065          if (array_key_exists($field_id, $arreglo)) {
1066            $field_form[] = $field_id;
1067            $fields_form[] = $field_id;
1068          }
1069          elseif (variable_get('proyectos_operativos_muestra_ubicaci_inter_' . $field_id, FALSE)) {
1070            $fields_form_geo[$field_id] = $field_id;
1071            $field_form[] = $field_id;
1072            $fields_form[] = $field_id;
1073          }
1074        }
1075      }
1076      $form['#fields_form_geo'] = $fields_form_geo;
1077    }
1078    $descripcion = variable_get('proyectos_operativos_muestra_proyecto_descripcion', TRUE);
1079    if ($descripcion) {
1080      $arreglo['field_descripcin_proyect'] = 'field_descripcin_proyect';
1081            $fields_extra_form1[] = 'field_descripcin_proyect';
1082    }
1083    $causas = variable_get('proyectos_operativos_muestra_causas_abordadas', TRUE);
1084    if ($causas) {
1085      $arreglo['field_proyect_cau_abord'] = 'field_proyect_cau_abord';
1086            $fields_extra_form1[] = 'field_proyect_cau_abord';
1087    }
1088    $problemas = variable_get('proyectos_operativos_muestra_problemas_abordados', TRUE);
1089    if ($problemas) {
1090      $arreglo['field_proyect_probl_abord'] = 'field_proyect_probl_abord';
1091          $fields_extra_form1[] = 'field_proyect_probl_abord';
1092    }
1093    if ($descripcion || $causas || $problemas) {
1094      $fields_form_basico = array();
1095            $fields_extra_form['otros_datos'] = $fields_extra_form1;
1096      if (is_array($fields) && count($fields)) {
1097        foreach ($fields as $field_id => $field) {
1098          if (array_key_exists($field_id, $arreglo)) {
1099            $field_form[] = $field_id;
1100            $fields_form[] = $field_id;
1101          }
1102          elseif (variable_get('proyectos_operativos_muestra_otros_' . $field_id, FALSE)) {
1103            $fields_form_basico[$field_id] = $field_id;
1104            $field_form[] = $field_id;
1105            $fields_form[] = $field_id;
1106          }
1107        }
1108      }
1109      $form['#fields_form_basico'] = $fields_form_basico;
1110    }
1111    //campos causas y problemas abordados con el proyecto
1112    $form['#proyectos_operativos_fields_extra'][] = $fields_extra_form;
1113    $form['#proyectos_operativos_fields'] = array_merge($form['#proyectos_operativos_fields'], $fields_form);
1114    if (is_array($field_form) && count($field_form)) {
1115      module_load_include('inc', 'content', 'includes/content.node_form');
1116      foreach ($field_form as $field_id) {
1117        $field = content_fields($field_id, 'proyectos_operativos');
1118        $form['#field_info'][$field_id] = $field;
1119        $form += (array) content_field_form($form, $form_state, $field);
1120      }
1121    }
1122    //Monto Total del Proyecto para el año en curso.
1123        $form['field_proyecto_monto_anual']['#pre_render'] = array('proyectos_operativos_mcti_field_proyecto_monto_anual_field_pre_render');
1124          $form['field_proyecto_monto_anual'][0]['#required'] = 0;
1125
1126          foreach ($form['#validate'] as $id => $name) {
1127            if ($name == 'proyectos_operativos_proyecto_basico_form_validate') {
1128                    $form['#validate'][$id] = 'proyectos_operativos_mcti_proyecto_basico_form_validate';
1129            }
1130          }
1131    $form['#submit'][] = 'proyectos_operativos_mcti_proyecto_basico_form_responsables_submit';
1132  }//fin del datos basicos
1133  if ($form_id == 'views_bulk_operations_form_asignar_proyectos_organismo_page_1') { //modificando el campo usuario a un campo del tipo select
1134    $options = array();
1135    global $user;
1136    $ente_planificador = node_load($user->entes);
1137          $options[0] = 'Seleccione';
1138    $role1 = variable_get('ActorPlanificadorcoordinador1', 0);
1139    if ($ente_planificador->tipo == 1 && $role1) {
1140      $rol = $role1;
1141    }
1142    $role2 = variable_get('ActorPlanificadorevisor2', 0);
1143    if ($ente_planificador->tipo == 2) {
1144      $rol = $role2;
1145    }
1146    $role3 = variable_get('ActorPlanificadorevisor3', 0);
1147    if ($ente_planificador->tipo == 3 && $role3) {
1148      $rol = $role3;
1149    }
1150    $role4 = variable_get('ActorPlanificadorevisor4', 0);
1151    if ($ente_planificador->tipo == 4 && $role4) {
1152      $rol = $role4;
1153    }
1154    $title = 0;
1155    $op_tt = '!=';
1156          $var[0] = $rol;
1157          $var[1] = $title;
1158    //agregando el campo usuarios
1159    if (isset($_GET['title']) && $_GET['title'] != 0) {
1160      $op_tt = 'LIKE';
1161      $var[1] = $_GET['title'];
1162    }
1163    $sql = "SELECT u.name, u.uid, u.nombres, u.apellidos, u.cedula FROM {users} as u INNER JOIN {ente_user_planificador} as e ON u.uid=e.usuario INNER JOIN {ente_planificador} as p ON p.nid=e.nid INNER JOIN {node} as n ON n.nid = p.nid INNER JOIN {users_roles} as r ON r.uid = u.uid WHERE r.rid = %d AND n.title " .$op_tt. " '%s'";
1164    if (isset($_GET['ambito']) && $_GET['ambito'] != 0) {
1165      $op_ab = '=';
1166      $var[2] = $_GET['ambito'];
1167      $sql .= " AND p.ambito " .$op_ab;
1168    }
1169    $var[3] = 0;
1170    if (isset($_GET['sector']) && $_GET['sector'] != 0 ) {
1171      $op_st = '=';
1172      $var[3] = $_GET['sector'];
1173      $sql .= " AND p.sector " .$op_st;
1174    }
1175    $query = db_query($sql, implode(',', $var));
1176    while ($rows = db_fetch_object($query)) { //datos del usuario a mostrar
1177      if ($rows->nombres || $rows->apellidos || $rows->cedula) {
1178        $name = $rows->name . ', ' . $rows->nombres . ' ' . $rows->apellidos . '(' . $rows->cedula . ')';
1179      }
1180      else {
1181        $name = $rows->name;
1182      }
1183      $options[$rows->uid] = $name;
1184    }
1185    $form['owner_name'] = array(
1186      '#type' => 'select',
1187      '#title' => t('Nombre de Usuario que ha de revisar el Proyecto'),
1188      '#options' => $options,
1189      '#description' => t('Nombre de usuario que se le ha de asignar el proyecto para su revisión.'),
1190    );
1191  }
1192
1193  if ($form_id == 'proyectos_operativos_proyecto_generales_form') {
1194    //modificando el tipo de campo sector
1195    $form['field_proyecto_sector']['tids']['#config']['level_labels']['status'] = 1;
1196    $form['field_proyecto_sector']['tids']['#config']['level_labels']['labels'][1] = t('Sub-Sector');
1197    //Empleos Generados
1198    drupal_add_js(drupal_get_path('module', 'proyectos_operativos_mcti') . '/js/proyectos_operativos_mcti_generales.js');
1199    $form['field_proyecto_efdirecto']['#title'] = t('Empleos Directos Nuevos Femeninos');
1200    $form['field_proyecto_efindirecto']['#title'] = t('Empleos Directos Sostenidos Femeninos');
1201    $form['field_proyecto_emindirecto']['#title'] = t('Empleos Directos Nuevos Masculinos');
1202    $form['field_proyecto_emdirecto']['#title'] = t('Empleos Directos Sostenidos Masculinos');
1203    //total empleos indirectos
1204    $arregloI = array(
1205      'field_proyecto_emindirecto' => 'field_proyecto_emindirecto',
1206      'field_proyecto_efindirecto' => 'field_proyecto_efindirecto',
1207    );
1208    foreach ($arregloI as $id) {
1209      $form[$id]['#pre_render'][] = 'proyectos_operativos_mcti_agregaclaseI_field_pre_render';
1210    }
1211    //total de empleos directos
1212    $arregloD = array(
1213      'field_proyecto_emdirecto' => 'field_proyecto_emdirecto',
1214      'field_proyecto_efdirecto' => 'field_proyecto_efdirecto',
1215    );
1216     foreach ($arregloD as $id) {
1217       $form[$id]['#pre_render'][] = 'proyectos_operativos_mcti_agregaclaseD_field_pre_render';
1218     }
1219     //total empleos directos femeninos
1220     $arregloDf = array(
1221       'field_proyecto_efindirecto' => 'field_proyecto_efindirecto',
1222       'field_proyecto_efdirecto' => 'field_proyecto_efdirecto',
1223     );
1224     foreach ($arregloDf as $id) {
1225       $form[$id]['#pre_render'][] = 'proyectos_operativos_mcti_agregaclaseDF_field_pre_render';
1226     }
1227     //total empleos directos masculinos
1228     $arregloDf = array(
1229       'field_proyecto_emdirecto' => 'field_proyecto_emdirecto',
1230       'field_proyecto_emindirecto' => 'field_proyecto_emindirecto',
1231     );
1232     foreach ($arregloDf as $id) {
1233       $form[$id]['#pre_render'][] = 'proyectos_operativos_mcti_agregaclaseDM_field_pre_render';
1234     }
1235     //cargando los valores por defecto.
1236     $sumas['empleos']['empleos_estimadosDf'] = 'empleos_estimadosDf';
1237     $sumas['empleos']['empleos_estimadosDm'] = 'empleos_estimadosDm';
1238     $sumas['empleos']['empleos_estimadosD'] = 'empleos_estimadosD';
1239     $sumas['empleos']['empleos_estimadosI'] = 'empleos_estimadosI';
1240     drupal_add_js($sumas, 'setting');
1241     //modificando la tabla beneficiario
1242     foreach ($form['#parameters'] as $id => $proyecto) {
1243       if ($proyecto->type == 'proyectos_operativos') {
1244         $proyecto = $proyecto;
1245       }
1246     }
1247     if (!$proyecto) {
1248       $proyecto_leido = new stdClass();
1249       $proyecto_leido->type = 'proyectos_operativos';
1250     }
1251     else {
1252       $proyecto_leido = $proyecto;
1253     }
1254     if (variable_get('proyectos_operativos_muestra_beneficiario', TRUE)) {
1255       $arreglo = array(
1256         'field_proyecto_beneficiario' => 'field_proyecto_beneficiario',
1257         'field_proyectos_masculino_d' => 'field_proyectos_masculino_d',
1258       );
1259       $labels = array(
1260         'field_proyecto_beneficiario' => 'Beneficiario ',
1261         'field_proyectos_masculino_d' => 'Número estimado de beneficiarios masculinos',
1262         'field_proyectos_femenino_i' => 'Número estimado de beneficiarios femeninos',
1263       );
1264       if (variable_get('proyectos_operativos_muestra_beneficiarios_indirectos', TRUE)) {
1265        $arreglo['field_proyectos_femenino_i'] = 'field_proyectos_femenino_i';
1266      }
1267      $prefixC = '';
1268      foreach ($arreglo as $field_id => $field) {
1269        $prefixC .= '<th>'.$labels[$field_id].'</th>';
1270      }
1271      $prefixC .= '<th>' . t('Total') . '</th>';
1272      $node_type = content_types('proyectos_operativos');
1273      $fields = $node_type['fields'];
1274      $tamano_array = array();
1275      foreach ($arreglo as $field_id => $field) {
1276        $tamano_array[] = count($proyecto_leido->{$field_id});
1277      }
1278      $cantidad_beneficiario = max($tamano_array);
1279      for ($i = 0; $i < $cantidad_beneficiario; $i++) {
1280        $prefix = '';
1281        if ($i == 0) {
1282          $prefix = '<div id="beneficiario-modificar"><table align="center"><tr>' . $prefixC . '</tr><tr><td>';
1283        }
1284        else {
1285          $prefix .= '<tr><td>';
1286        }
1287        foreach ($arreglo as $field_id => $field) {
1288          $form['beneficiario'][$field_id . '_' . $i]['#prefix'] = $prefix;
1289          if ($field_id != 'field_proyecto_beneficiario') {
1290            if (!isset($total_arreglo[$field_id])) {
1291              $total_arreglo[$field_id] = 0;
1292            }
1293            $subtotal += (int) $valor;
1294            $totales += (int) $valor;
1295            $total_arreglo[$field_id] += (int) $valor;
1296           }
1297           $aux = $field_id;
1298           $aui = $i;
1299           $prefix = '<td align="center">';
1300         }
1301        //total masculino y femenino
1302       
1303        //excluir los siguientes campos.
1304        $form['beneficiario']['field_proyectos_masculino_i'. '_' . $i]['#access'] = false;
1305        $form['beneficiario']['field_proyectos_femenino_d'. '_' . $i]['#access'] = false;
1306        $form['beneficiario']['field_proyectos_masculino_i'. '_' . $i]['#value'] = 0;
1307        $form['beneficiario']['field_proyectos_femenino_d'. '_' . $i]['#value'] = 0;
1308       
1309        unset($form['beneficiario'][$aux . '_' . $aui]['#suffix']);
1310        $form['beneficiario'][$aux . '_' . $aui]['#suffix'] .= '<td align="center"><div class="beneficiario_' . $i . '_total">' . $subtotal . '</div></td>';
1311        $form['beneficiario'][$aux . '_' . $aui]['#suffix'] .= '</tr>';
1312      }
1313      $form['beneficiario'][$aux . '_' . $aui]['#suffix'] .= '<tr align="right"><td><b>' . t('TOTAL DE BENEFICIARIOS') . '</b></td>';
1314      foreach ($arreglo as $field_id => $field) {
1315        if ($field_id != 'field_proyecto_beneficiario') {
1316          $sumas['beneficiarios']['beneficiarios_' . $field_id] = 'beneficiarios_' . $field_id;
1317          $form['beneficiario'][$aux . '_' . $aui]['#suffix'] .= '<td align="center"><div class="beneficiarios_' . $field_id . '_total">' . $total_arreglo[$field_id] . '</div></td>';
1318        }
1319      }
1320      $form['beneficiario'][$aux . '_' . $aui]['#suffix'] .= '<td align="center"><div class="todosbeneficiarios_total">' . $totales . '</div></td></tr>';
1321      $form['beneficiario'][$aux . '_' . $aui]['#suffix'] .= '</table>';
1322      $form['beneficiario']['agrega_' . 'beneficiario']['#ahah'][ 'path'] = 'proyectos_operativos_mcti_proyecto_generales_agrega_talento_js_util/beneficiario';
1323      foreach ($form['#validate'] as $key => $name) {
1324        if ($name == 'proyectos_operativos_proyecto_generales_form_validate'){
1325          $form['#validate'][$key] = 'proyectos_operativos_mcti_proyecto_generales_form_validate';
1326        }
1327      }
1328    }
1329  }
1330}
1331
1332/**
1333 * Implementation of proyectos_operativos_proyecto_generales_form_validate().
1334 * Validar formulario de datos generales (proyectos operativos).
1335 */
1336function proyectos_operativos_mcti_proyecto_generales_form_validate($form, &$form_state) {
1337  $op = isset($form_state['values']['op']) ? $form_state['values']['op'] : '';
1338  if ($op == t('Cancelar')) {
1339    return;
1340  }
1341  $proyectos_operativos_path = drupal_get_path('module', 'proyectos_operativos');
1342  drupal_add_js($form['#format_number'], 'setting');
1343  drupal_add_js($proyectos_operativos_path . '/js/proyectos_operativos_extra.js');
1344  drupal_add_js($proyectos_operativos_path . '/js/proyectos_operativos_generales.js');
1345  drupal_add_js($form['#sumas'], 'setting');
1346  if (count($form['#proyectos_operativos_fields_extra'])) {
1347    foreach($form['#proyectos_operativos_fields_extra'] as $id => $arreglo) {
1348      $all_null = TRUE;
1349      unset($arreglo[2]);
1350      unset($arreglo[3]);
1351      $cantidad = $form_state['values']['cantidad_' . $id];
1352      for($i = 0; $i < $cantidad; $i++) {
1353        $null = TRUE;
1354        $first_campo = FALSE;
1355        foreach($arreglo as $campo) {
1356          if (!$first_campo) {
1357            $first_campo = $campo;
1358          }
1359          if ($form_state['values'][$campo . '_' . $i] && trim($form_state['values'][$campo . '_' . $i]) != '') {
1360            $all_null = FALSE;
1361            $null = FALSE;
1362          }
1363          if ($campo == 'field_proyecto_esfuerzo' || $campo == 'field_proyectos_masculino_d' || $campo == 'field_proyectos_masculino_i' || $campo == 'field_proyectos_femenino_d' || $campo == 'field_proyectos_femenino_i') {
1364            $start = $form_state['values'][$campo . '_' . $i];
1365            $value = (int) $start;
1366            if ($start != $value) {
1367              form_set_error($campo . '_' . $i, t('Solo números enteros son permitidos en el campo %field.' . $start, array('%field' => t($form['#proyecto_fields'][$campo]['widget']['label']))));
1368            }
1369            elseif ($value < 0) {
1370              form_set_error($campo . '_' . $i, t('Solo números enteros positivos son permitidos en el campo %field.' . $start, array('%field' => t($form['#proyecto_fields'][$campo]['widget']['label']))));
1371            }
1372          }
1373        }
1374        if (!$null) {
1375          foreach($arreglo as $campo) {
1376            $campos = $form['#proyecto_fields'][$campo]['widget']['label']= 0;
1377            if ($campo == 'field_proyectos_masculino_d') {
1378              $campos == 'Número estimado de beneficiarios masculinos';
1379            }
1380            if ($campo == 'field_proyectos_femenino_i') {
1381              $campos == 'Número estimado de beneficiarios femeninos';
1382            }
1383            if (trim($form_state['values'][$campo . '_' . $i]) == '') {
1384              form_set_error($campo . '_' . $i, t('El campo @campo_name no puede estar vacio', array('@campo_name' => $campos)));
1385            }
1386          }
1387        }
1388      }
1389      if ($all_null) {
1390        form_set_error($first_campo . '_0', t('Debe llenar al menos un campo'));
1391      }
1392    }
1393  }
1394}
1395
1396/**
1397 * Guarda los datos de los indicadores
1398 */
1399function proyectos_operativos_mcti_agrega_indicadores_form_submit($form, &$form_state) {
1400  //agregando el Balance Estimado Nacional de Servicios Energéticos 
1401  $op = isset($form_state['values']['op']) ? $form_state['values']['op'] : '';
1402  if ($op != t('Cancelar')) {
1403    $tipos = array('programacion', 'balance');
1404    $field_form = $form['#proyectos_operativos_fields'];
1405    module_load_include('inc', 'node', 'node.pages');
1406    $node_load = $form['#node'];
1407    if (count($form['#proyectos_operativos_fields_extra'])) {
1408      foreach ($form['#proyectos_operativos_fields_extra'] as $id => $arreglo) {
1409        foreach ($tipos as $keys => $tipo) {
1410          if ($arreglo[$tipo]) {
1411            foreach ($arreglo[$tipo] as $campo) {
1412              $node_load->{$campo} = array();
1413            }       
1414            $all_null = TRUE;
1415            $cantidad = $form_state['values']['cantidad_'.$tipo];
1416            for ($i = 0; $i < $cantidad; $i++) {
1417              $null = TRUE;
1418              $first_campo = FALSE;
1419              foreach ($arreglo[$tipo] as $campo) {
1420                if (!$first_campo) {
1421                  $first_campo = $campo;
1422                }
1423                if (trim($form_state['values'][$campo . '_' . $i]) != '') {
1424                  $all_null = FALSE;
1425                  $null = FALSE;
1426                }
1427              }
1428              if (!$null) {
1429                foreach ($arreglo[$tipo]  as $campo) {
1430                  $node_load->{$campo}[] = array('value' => trim($form_state['values'][$campo . '_' . $i]));
1431                }
1432              }
1433            }
1434          }
1435        }
1436      }
1437    }
1438    $form_values = $form_state['values'];
1439    if (is_array($field_form) && count($field_form)) {
1440      foreach ($field_form as $field_id) {
1441        if (isset($form_values[$field_id]) && is_array($form_values[$field_id])) {
1442          foreach ($form_values[$field_id] as $id => $value) {
1443            if (is_numeric($id) && isset($form_values[$field_id][$id]['_error_element'])) {
1444              unset($form_values[$field_id][$id]['_error_element']);
1445            }
1446          }
1447          $node_load->{$field_id} = $form_values[$field_id];
1448        }
1449      }
1450    }
1451    $node_load->revision = 1;
1452    node_save($node_load);
1453  }
1454}
1455
1456/**
1457 * valida las entradas de los responsables del proyecto en el formulario de datos basicos
1458 */
1459function proyectos_operativos_mcti_proyecto_basico_form_responsables_validate($form, &$form_state) {
1460  $op = isset($form_state['values']['op']) ? $form_state['values']['op'] : '';
1461  if ($op == t('Cancelar')) {
1462    return;
1463  }
1464  if (trim($form_state['values']['field_proyecto_corre_gere']) && !valid_email_address(trim($form_state['values']['field_proyecto_corre_gere']))) {
1465    form_set_error('field_proyecto_corre_gere', t('"%mail" is not a valid email address',array('%mail' => $form_state['values']['field_proyecto_corre_gere'])));
1466  }
1467  if (trim($form_state['values']['field_proyecto_cor_r_tec']) && !valid_email_address(trim($form_state['values']['field_proyecto_cor_r_tec']))) {
1468    form_set_error('field_proyecto_cor_r_tec', t('"%mail" is not a valid email address',array('%mail' => $form_state['values']['field_proyecto_cor_r_tec'])));
1469  }
1470  if (trim($form_state['values']['field_proyecto_cor_r_reg']) && !valid_email_address(trim($form_state['values']['field_proyecto_cor_r_reg']))) {
1471    form_set_error('field_proyecto_cor_r_reg', t('"%mail" is not a valid email address',array('%mail' => $form_state['values']['field_proyecto_cor_r_reg'])));
1472  }
1473  if (trim($form_state['values']['field_proyecto_cor_r_adm']) && !valid_email_address(trim($form_state['values']['field_proyecto_cor_r_adm']))) {
1474    form_set_error('field_proyecto_cor_r_adm', t('"%mail" is not a valid email address',array('%mail' => $form_state['values']['field_proyecto_cor_r_adm'])));
1475  }
1476  //validacion de la cedula
1477  if (!preg_match("/^(V|E){1}([0-9]){8}$/",$form_state['values']['field_proyecto_cedul_gere'])) {
1478    form_set_error('field_proyecto_cedul_gere', t('La cédula de identidad %cedula debe tener el formato V00000000 sin puntos.',array('%cedula' => $form_state['values']['field_proyecto_cedul_gere'])));
1479  }
1480  if (!preg_match("/^(V|E){1}([0-9]){8}$/",$form_state['values']['field_proyecto_ced_r_tec'])) {
1481    form_set_error('field_proyecto_ced_r_tec', t('La cédula de identidad %cedula debe tener el formato V00000000 sin puntos.',array('%cedula' => $form_state['values']['field_proyecto_ced_r_tec'])));
1482  }
1483  if (!preg_match("/^(V|E){1}([0-9]){8}$/",$form_state['values']['field_proyecto_ced_r_reg'])) {
1484    form_set_error('field_proyecto_ced_r_reg', t('La cédula de identidad %cedula debe tener el formato V00000000 sin puntos.',array('%cedula' => $form_state['values']['field_proyecto_ced_r_reg'])));
1485  }
1486  if (!preg_match("/^(V|E){1}([0-9]){8}$/",$form_state['values']['field_proyecto_ced_r_adm'])) {
1487    form_set_error('field_proyecto_ced_r_adm', t('La cédula de identidad %cedula debe tener el formato V00000000 sin puntos.',array('%cedula' => $form_state['values']['field_proyecto_ced_r_adm'])));
1488  }
1489}
1490
1491/*
1492 * Implementation of proyectos_operativos_proyecto_basico_form_validate()
1493 * Validar formulario de datos basicos (proyectos operativos).
1494 */
1495function proyectos_operativos_mcti_proyecto_basico_form_validate($form, &$form_state) {
1496  $op = isset($form_state['values']['op']) ? $form_state['values']['op'] : '';
1497  if ($op == t('Cancelar')) {
1498    return;
1499  }
1500  $proyectos_operativos_path = drupal_get_path('module', 'proyectos_operativos');
1501  drupal_add_js($proyectos_operativos_path . '/js/proyectos_operativos_extra.js');
1502  drupal_add_js($proyectos_operativos_path . '/js/proyectos_operativos2.js');
1503  //drupal_add_js($form['#format_number'], 'setting');
1504  $form_state['values']['field_proyecto_monto_anual'][0]['value'] = str_replace("", $form['#format_number']['format_number']['thousands_sep'], $form_state['values']['field_proyecto_monto_anual'][0]['value']);
1505  $form_state['values']['field_proyecto_monto_anual'][0]['value'] = str_replace(".", $form['#format_number']['format_number']['dec_point'], $form_state['values']['field_proyecto_monto_anual'][0]['value']);
1506  $form_state['values']['field_proyecto_total'][0]['value'] = str_replace("", $form['#format_number']['format_number']['thousands_sep'], $form_state['values']['field_proyecto_total'][0]['value']);
1507  $form_state['values']['field_proyecto_total'][0]['value'] = str_replace(".", $form['#format_number']['format_number']['dec_point'], $form_state['values']['field_proyecto_total'][0]['value']);
1508
1509  // garantizar el formato numerico y no exponencial con numeros grandes
1510  if ($form_state['values']['field_proyecto_monto_anual'][0]['value'] != 0)  {
1511    $form_state['values']['field_proyecto_monto_anual'][0]['value'] = number_format($form_state['values']['field_proyecto_monto_anual'][0]['value'], $form['#format_number']['format_number']['decimals'], '.', '');
1512  }
1513  $form_state['values']['field_proyecto_total'][0]['value'] = number_format($form_state['values']['field_proyecto_total'][0]['value'], $form['#format_number']['format_number']['decimals'], '.', '');
1514  if (trim($form_state['values']['field_proyecto_correo'][0]['email']) && !valid_email_address(trim($form_state['values']['field_proyecto_correo'][0]['email']))) {
1515    form_set_error('field_proyecto_correo', t('"%mail" is not a valid email address',array('%mail' => $form_state['values']['field_proyecto_correo'][0]['email'])));
1516  }
1517  if ($form_state['values']['field_proyecto_monto_anual'][0]['value'] < 0) {
1518    form_set_error('field_proyecto_monto_anual', t('El monto anual del proyecto no puede ser negativo'));
1519  }
1520  $start = $form_state['values']['field_proyecto_total'][0]['value'];
1521  $value = preg_replace('@[^-0-9]@', '', $start);
1522  if ($start != $value) {
1523    form_set_error('field_proyecto_total', t('Solo números enteros son permitidos en el monto anual del proyecto.'));
1524  }
1525  $start = $form_state['values']['field_proyecto_monto_anual'][0]['value'];
1526  $value = preg_replace('@[^-0-9]@', '', $start);
1527  if ($start != $value) {
1528    form_set_error('field_proyecto_monto_anual', t('Solo números enteros son permitidos en el monto total del proyecto'));
1529  }
1530  if ($form['#count_ae'] && $form['#montos_asignados'] > $value) {
1531    form_set_error('field_proyecto_monto_anual', t('El monto anual del proyecto (@monto_proyecto Bs.) es inferior al asignado a las Acciones Específicas (@monto_asignado Bs.)', array('@monto_proyecto' => number_format($value, $form['#format_number']['format_number']['decimals'], $form['#format_number']['format_number']['dec_point'], $form['#format_number']['format_number']['thousands_sep']), '@monto_asignado' => number_format($form['#montos_asignados'], $form['#format_number']['format_number']['decimals'], $form['#format_number']['format_number']['dec_point'], $form['#format_number']['format_number']['thousands_sep']))));
1532  }
1533  if ($form_state['values']['field_proyecto_total'][0]['value'] < 0) {
1534    form_set_error('field_proyecto_total', t('El monto anual del proyecto no puede ser negativo'));
1535  }
1536  if ($form_state['values']['field_proyecto_monto_anual'][0]['value'] > $form_state['values']['field_proyecto_total'][0]['value']) {
1537    form_set_error('field_proyecto_monto_anual', t('El monto anual debe ser menor o igual al monto total del proyecto'));
1538  }
1539  //lamentablemente date no valida que from sea menor que to
1540  if ($form_state['values']['field_proyecto_fecha_i'][0]['value'] > $form_state['values']['field_proyecto_fecha_f'][0]['value']) {
1541    form_set_error('field_proyecto_fecha_i', t('La fecha de inicio debe ser menor a la fecha de culminación'));
1542  }
1543  //validamos el añofield_proyecto_plurianual
1544  $fecha = explode('-', $form_state['values']['field_proyecto_fecha_i'][0]['value']);
1545  if (is_array($fecha) && count($fecha)) {
1546    if ($form['#proyecto_anho'] != $fecha[0]) {
1547      form_set_error('field_proyecto_fecha_i',t('El año de inicio del proyecto debe ser igual a @year', array('@year' => $form['#proyecto_anho'])));
1548    }
1549  }
1550  if ($form['#count_ae'] && $form['#fechas_validacion']['inicio'] < $form_state['values']['field_proyecto_fecha_i'][0]['value']) {
1551    $fecha_dia = explode(' ', $fecha[2]);
1552    form_set_error('field_proyecto_fecha_i',t('La fecha de inicio del proyecto (@fecha_inicio) es mayor a la menor fecha de inicio de las Acciones Específicas (@fecha_aei)', array('@fecha_inicio' => $fecha_dia[0] . '-' . $fecha[1] . '-' . $fecha[0], '@fecha_aei' => $form['#fechas_validacion']['inicio_texto'])));
1553  }
1554  $fecha = explode('-', $form_state['values']['field_proyecto_fecha_f'][0]['value']);
1555  if (is_array($fecha) && count($fecha)) {
1556    if ($form['#proyecto_anho'] != $fecha[0]) {
1557      form_set_error('field_proyecto_fecha_f',t('El año de finalización del debe ser igual a @year', array('@year' => $form['#proyecto_anho'])));
1558    }
1559  }
1560  if ($form['#count_ae'] && $form['#fechas_validacion']['fin'] > $form_state['values']['field_proyecto_fecha_f'][0]['value']) {
1561    $fecha_dia = explode(' ', $fecha[2]);
1562    form_set_error('field_proyecto_fecha_f',t('La fecha de culminación del proyecto (@fecha_inicio) es menor a la menor fecha de inicio de las Acciones Específicas (@fecha_aei)', array('@fecha_inicio' => $fecha_dia[0] . '-' . $fecha[1] . '-' . $fecha[0], '@fecha_aei' => $form['#fechas_validacion']['fin_texto'])));
1563  }
1564}
1565
1566/**
1567 * Agrega los responsables del proyecto
1568 */
1569function proyectos_operativos_mcti_proyecto_basico_form_responsables_submit($form, &$form_state) {
1570  //agregando los responsables del proyecto
1571  $op = isset($form_state['values']['op']) ? $form_state['values']['op'] : '';
1572  if ($op != t('Cancelar')) {
1573    $tipos = array('gerente', 'tecnico', 'registrador', 'administrativo', 'ubicacion', 'otros_datos');
1574    $field_form = $form['#proyectos_operativos_fields'];
1575    module_load_include('inc', 'node', 'node.pages');
1576    $node_load = $form['#node'];
1577    $form_values = $form_state['values'];
1578    foreach ($form['#proyectos_operativos_fields_extra'] as $id => $arreglo) {
1579      foreach ($tipos as $keys => $tipo) {
1580        foreach ($arreglo[$tipo] as $campo) {
1581          if (is_array($field_form) && count($field_form)) {
1582                                  if (isset($form_values[$campo])) {
1583              if ($campo == 'field_proyecto_cor_r_adm' || $campo == 'field_proyecto_cor_r_tec' || $campo == 'field_proyecto_cor_r_reg' || $campo == 'field_proyecto_corre_gere') {
1584                        $node_load->{$campo}[0]['email'] = $form_values[$campo];
1585             }
1586             elseif ($campo == 'field_descripcin_proyect' || $campo == 'field_proyecto_ubicaci_comu' || $campo == 'field_proyecto_nombres_cum' || $campo == 'field_proyecto_codigo_comu' || $campo == 'field_proyecto_ubicaci_inter' || $campo == 'field_proyect_probl_abord' || $campo == 'field_proyect_cau_abord') {
1587                foreach ($form_values[$campo] as $id => $value) {
1588                  if (is_numeric($id) && isset($form_values[$campo][$id]['_error_element'])) {
1589                    unset($form_values[$campo][$id]['_error_element']);
1590                  }
1591                }
1592                $node_load->{$campo} = $form_values[$campo];
1593              }
1594                          /*elseif ($campo == 'field_proyecto_ente') {
1595                                  $node_load->{$campo}[0]['nid'] = $form_values[$campo];
1596                                }*/
1597                          else {
1598                            $node_load->{$campo}[0]['value'] = $form_values[$campo];
1599                          }
1600                  }
1601                }
1602        } 
1603            }
1604    }
1605    $node_load->revision = 1;
1606    node_save($node_load);
1607  }
1608}
1609
1610
1611/**
1612 * Agrega los instituciones responsables
1613 */
1614function proyectos_operativos_proyecto_ente_field_pre_render($element) {
1615  global $user;
1616  if ($ente) {
1617    if (count($element['nid']['nid']['#options'])) {
1618      foreach ($element['nid']['nid']['#options'] as $id => $entes){
1619        if ($ente->nid != $id) {
1620          unset($element['nid']['nid']['#options'][$id]);
1621        }
1622      }
1623    }
1624  }
1625  return $element;
1626}
1627/*
1628 * Total de empleos Directos
1629 */
1630function proyectos_operativos_mcti_agregaclaseD_field_pre_render($element) {
1631  $element[0]['value']['#attributes']['class'] .= ' empleos_estimadosD';
1632  $element[0]['value']['#attributes']['onchange'] .= ";sumaempleos('empleos_estimadosD');";
1633  return $element;
1634}
1635 
1636/**
1637 * Total empleos directos masculinos
1638 */
1639function proyectos_operativos_mcti_agregaclaseDF_field_pre_render($element) {
1640  $element[0]['value']['#attributes']['class'] .= ' empleos_estimadosDf';
1641  $element[0]['value']['#attributes']['onchange'] .= ";sumaempleos('empleos_estimadosDf');";
1642  return $element;
1643}
1644
1645/**
1646 * Total de empleos directos masculinos
1647 */
1648function proyectos_operativos_mcti_agregaclaseDM_field_pre_render($element) {
1649  $element[0]['value']['#attributes']['class'] .= ' empleos_estimadosDm';
1650  $element[0]['value']['#attributes']['onchange'] .= ";sumaempleos('empleos_estimadosDm');";
1651  return $element;
1652}
1653
1654/**
1655 * Total de empleos indirectos
1656 */
1657function proyectos_operativos_mcti_agregaclaseI_field_pre_render($element) {
1658  $element[0]['value']['#attributes']['class'] .= ' empleos_estimadosI';
1659  $element[0]['value']['#attributes']['onchange'] .= ";sumaempleos('empleos_estimadosI');";
1660  return $element;
1661}
1662
1663/**
1664 * Agrega una clase CSS y ahah a la estructura del campo nid para la institucion de datos basicos
1665 */
1666function proyectos_operativos_mcti_field_proyecto_monto_anual_field_pre_render($element) {
1667  $element[0]['value']['#attributes']['disabled'] = 'disabled';
1668  return $element;
1669}
1670
1671/**
1672 * Agrega ahah al campo
1673 */
1674function proyectos_operativos_mcti_field_proyecto_monto_total_field_pre_render($element) {
1675  $element['value']['NO']['#ahah'] = array(
1676    'event' => 'change',
1677          'path' => 'proyectos_operativos_mcti_proyecto_monto_anual_js/no',
1678    'wrapper' => 'field-proyecto-total-wrraper',
1679    'method' => 'replace',
1680    'progress' => array('type' => 'bar', 'message' => t('Please wait...')),
1681        );
1682        $element['value']['SI']['#ahah'] = array(
1683    'event' => 'change',
1684          'path' => 'proyectos_operativos_mcti_proyecto_monto_anual_js/si',
1685    'wrapper' => 'field-proyecto-total-wrraper',
1686    'method' => 'replace',
1687    'progress' => array('type' => 'bar', 'message' => t('Please wait...')),
1688        );
1689  // this part may be naughty
1690  form_expand_ahah($element['value']['NO']);
1691  form_expand_ahah($element['value']['SI']);
1692  return $element;
1693}
1694
1695/**
1696 * Implementation of hook_action_info().
1697 * asignar los proyectos operativos a los usuarios.
1698 */
1699 function proyectos_operativos_mcti_action_info() {
1700   return array(
1701     'proyectos_operativos_mcti_action' => array(
1702       'description' => t('Asignar Proyectos para su revision a usuarios'),
1703       'type' => 'node',
1704       'configurable' => true,
1705     ),
1706   );
1707 }
1708
1709/**
1710 * Agrega los datos de la accion
1711 */
1712 function proyectos_operativos_mcti_action(&$node, $context) {
1713   $owner_name = db_result(db_query("SELECT name FROM {users} WHERE uid = %d", $context['owner_uid']));
1714   $ente_name = db_result(db_query("SELECT title FROM {node} WHERE nid = %d", $context['row']->nid, $context['owner_uid']));
1715   db_query("DELETE FROM {proyectos_operativos_asignados} WHERE nid_node = %d", $context['row']->nid);
1716   db_query("INSERT INTO {proyectos_operativos_asignados} (nid_node, uid_users) VALUES(%d, %d)", $context['row']->nid, $context['owner_uid']);
1717   drupal_set_message(t('Se asigno el Ente Planificador %ente al usuario %user' , array('%ente'=> $ente_name, '%user' => $owner_name)));
1718 }
1719
1720/**
1721 * Implementation of a configurable Drupal action.
1722 */
1723function proyectos_operativos_mcti_action_form($context) {
1724  module_load_include('inc', 'content', 'includes/content.node_form');
1725  $form = array();
1726  $form['#settings'] = $context['settings'];   
1727  $form_state = array();
1728  $weight = -100;
1729  $fields = array();
1730  // Get the content types of the selected nodes if any. Otherwise, get all types.
1731  if (!empty($context['selection']) && isset($context['view'])) {
1732    $fields = proyectos_operativos_mcti_action_fields();
1733  }
1734  foreach ($fields as $field) {
1735    // The field info and widget.
1736    $form += (array)$field['form'];
1737    if (is_array($form['#node']->{$field['field_name']})) {
1738      foreach ($form['#node']->{$field['field_name']} as $v_key => $v_item) {
1739        $form[$field['field_name']][$v_key]['#default_value'] = $v_item;
1740      }
1741    }
1742    else {
1743      $form[$field['field_name']]['#default_value'] = $form['#node']->{$field['field_name']};
1744    }
1745    if (empty($form[$field['field_name']])) continue;
1746  } //end foreach
1747  return $form;
1748}
1749
1750/**
1751 * Defincion de los campos que han de estar disponibles durante la implementacion del hook_action_info
1752 */
1753function proyectos_operativos_mcti_action_fields($type = NULL) {
1754  $fields = array();
1755  $fields['owner_name'] = array(
1756    'label' => t('user'),
1757    'form' => array(
1758      'owner_name' => array(
1759      '#type' => 'textfield',
1760      '#title' => t('Nombre de Usuario'),
1761      '#autocomplete_path' => 'user/autocomplete',
1762      '#size' => '30',
1763      '#maxlength' => '60',
1764      '#description' => t('Nombre de usuario al que desea asignar el proyecto'),
1765      ),
1766    ),
1767  );
1768  return $fields;
1769}
1770
1771/**
1772 * validando el nombre del usuario
1773 */
1774function proyectos_operativos_mcti_action_validate($form, $form_state) {
1775  $count = db_result(db_query("SELECT COUNT(uid) FROM {users} WHERE uid = '%s'", $form_state['values']['owner_name']));
1776  if (intval($count) != 1) {
1777    form_set_error('owner_name', t('Please enter a valid username.'));
1778  }
1779}
1780 
1781/**
1782 * implementacion del hook_action_submit()
1783 */
1784function proyectos_operativos_mcti_action_submit($form, $form_state) {
1785  // Username can change, so we need to store the ID, not the username.
1786  $uid = db_result(db_query("SELECT uid from {users} WHERE uid = '%s'", $form_state['values']['owner_name']));
1787  return array('owner_uid' => $uid);
1788}
1789
1790/*
1791 * Creando el permiso para revisar los proyectos
1792 */
1793function proyectos_operativos_mcti_perm() {
1794  return array('review proyectos operativos');
1795}
1796
1797/**
1798 * Implementation of hook_views_api().
1799 */
1800function proyectos_operativos_mcti_views_api() {
1801  return array(
1802    'api' => '2.0',
1803    'path' => drupal_get_path('module', 'proyectos_operativos_mcti') . '/includes/views',
1804  );
1805}
1806
1807/**
1808 * Implementation of hook_theme_registry_alter().
1809 */
1810function proyectos_operativos_mcti_theme_registry_alter(&$theme_registry) {
1811  if ($theme_registry['proyectos_operativos_proyecto_generales_form']) {   
1812    $theme_registry['proyectos_operativos_proyecto_generales_form']['function'] = 'theme_proyectos_operativos_mcti_proyecto_generales_form';
1813  }
1814  if ($theme_registry['proyectos_operativos_proyecto_indicadores_form']) {   
1815    $theme_registry['proyectos_operativos_proyecto_indicadores_form']['function'] = 'theme_proyectos_operativos_mcti_proyecto_indicadores_form';
1816  }
1817  if ($theme_registry['proyectos_operativos_proyecto_basico_form']) {   
1818    $theme_registry['proyectos_operativos_proyecto_basico_form']['function'] = 'theme_proyectos_operativos_mcti_proyecto_basico_form';
1819  }
1820}
1821
1822/**
1823 * Agrega los nuevos campos en el formulario proyecto en la pestanha generales
1824 */
1825function theme_proyectos_operativos_mcti_proyecto_generales_form($form) {
1826  $output = '';
1827  if ($form['#count_ae'] && $form['#montos_asignados']!= $form['#node']->field_proyecto_monto_anual[0]['value']) {
1828    $link_acciones = l(t('Modificar Acciones específicas'), 'proyectosopedit/' . $form['#node']->nid . '/ae');
1829    $link_proyecto = l(t('Modificar Monto del Proyecto'), 'proyectosopedit/' . $form['#node']->nid);
1830    $format_number = array(
1831      'decimals' => variable_get('proyectos_operativos_number_decimals', 0),
1832      'dec_point' => variable_get('proyectos_operativos_number_dec_point', ','),
1833      'thousands_sep' => variable_get('proyectos_operativos_number_thousands_sep', '.'),
1834    );
1835    $mensaje_mostrar = t('Existen @count_ae Acciones Específicas asignadas con un monto total de @montos_asignados Bs, el cual difiere con el monto asignado en el proyecto para el @title_monto_total_proyecto_year (@monto_proyecto). Modifique los montos de las Acciones Específicas en !link_acciones o el monto del proyecto !link_proyecto para poder cerrar el proyecto operativo @nombre_proyecto', array('@count_ae' => $form['#count_ae'], '@montos_asignados' => number_format($form['#montos_asignados'], $format_number['decimals'], $format_number['dec_point'], $format_number['thousands_sep']), '@title_monto_total_proyecto_year' => $form['#proyecto_fields']['field_proyecto_monto_anual']['widget']['label'], '@monto_proyecto' => number_format($form['#node']->field_proyecto_monto_anual[0]['value'], $format_number['decimals'], $format_number['dec_point'], $format_number['thousands_sep']), '!link_acciones' => $link_acciones, '!link_proyecto' => $link_proyecto, '@nombre_proyecto' => $form['#node']->titulo_asignado,));
1836    $output .= '<div id="mensaje-mostrar-monto" class="mensaje mensaje-mostrar" style="color:red;font-weight: bold;">' . $mensaje_mostrar . '</div>';
1837  }
1838  if ($form['#count_ae'] && $fechas_validacion['inicio'] && $fechas_validacion['fin'] && ($fechas_validacion['inicio_time'] < $fechas_validacion['inicio_current_time'] || $fechas_validacion['fin_current_time'] < $fechas_validacion['fin_time'])) {
1839    $link_acciones = l(t('Modificar Acciones específicas'), 'proyectosopedit/' . $form['#node']->nid . '/ae');
1840    $link_proyecto = l(t('Modificar Monto del Proyecto'), 'proyectosopedit/' . $form['#node']->nid);
1841    $mensaje_mostrar = t('Existen @count_ae Acciones Específicas asignadas que difieren con la @title_fecha_de_inicio o @title_fecha_de_final del Proyecto. Modifique los montos de las Acciones Específicas en !link_acciones o el monto del proyecto !link_proyecto para poder cerrar el proyecto operativo @nombre_proyecto', array('@count_ae' => $form['#count_ae'], '@title_fecha_de_inicio' => $form['#proyecto_fields']['field_proyecto_fecha_i']['widget']['label'], '@title_fecha_de_final' => $form['#proyecto_fields']['field_proyecto_fecha_f']['widget']['label'], '!link_acciones' => $link_acciones, '!link_proyecto' => $link_proyecto, '@nombre_proyecto' => $form['#node']->titulo_asignado,));
1842    $output .= '<div id="mensaje-mostrar-time" class="mensaje mensaje-mostrar" style="color:red;font-weight: bold;">' . $mensaje_mostrar . '</div>';
1843  }
1844  $output .= '<fieldset><legend>' . t('Clasificación Sectorial del Gasto ONAPRE') . '</legend>' . drupal_render($form['field_proyecto_sector']);
1845  if (count($form['#fields_form_dg_se'])) {
1846    foreach ($form['#fields_form_dg_se'] as $id_c) {
1847      $output .= drupal_render($form[$id_c]);
1848    }
1849  }
1850  $output .= '</fieldset>';
1851
1852  if (variable_get('proyectos_operativos_muestra_talento', TRUE)) {
1853    $output .= drupal_render($form['talento']);
1854  }
1855  if (variable_get('proyectos_operativos_muestra_capacidades', TRUE)) {
1856    $output .= drupal_render($form['capacidades']);
1857  }
1858  $output .= '<fieldset><legend>' . t('Instituciones') . '</legend>' . drupal_render($form['field_proyecto_relacion']);
1859  if (count($form['#fields_form_dg_r'])) {
1860    foreach($form['#fields_form_dg_r'] as $id_c) {
1861      $output .= drupal_render($form[$id_c]);
1862    }
1863  }
1864
1865  $output .= '</fieldset>';
1866  $output .= '<fieldset><legend>' . t('Empleos Generados') . '</legend>' . t('Nro Estimados de Empleos:');
1867  $output .= '<table>';
1868 
1869  $output1 = '<tr>';
1870  $arreglo = array(
1871    'field_proyecto_efindirecto' => 'field_proyecto_efindirecto',
1872    'field_proyecto_emindirecto' => 'field_proyecto_emindirecto',
1873  );
1874  foreach($arreglo as $empleo) {
1875    $output1 .= '<th>' . $form[$empleo]['#title'] . '</th>';
1876    $form[$empleo][0]['value']['#title'] = '';
1877    $output1 .= '<td>' . drupal_render($form[$empleo]) . '</td>';
1878  }
1879  $output1 .= '<th>' . t('Total empleos directos Nuevos') . '</th>';
1880  $output1 .= '<td><div class="empleos_estimadosI_totales"></div></td>';
1881  $output1 .= '</tr>';
1882   
1883  $output1 .= '<tr>';
1884  $arreglo = array(
1885    'field_proyecto_efdirecto' => 'field_proyecto_efdirecto',
1886    'field_proyecto_emdirecto' => 'field_proyecto_emdirecto',
1887  );
1888  foreach($arreglo as $empleo) {
1889    $output1 .= '<th>' . $form[$empleo]['#title'] . '</th>';
1890    $form[$empleo][0]['value']['#title'] = '';
1891    $output1 .= '<td>' . drupal_render($form[$empleo]) . '</td>';
1892  }
1893  $output1 .= '<th>' . t('Total empleos Directos Sostenidos') . '</th>';
1894  $output1 .= '<td colspan="3"><div class="empleos_estimadosD_totales"></div></td>';
1895  $output1 .= '</tr>';
1896
1897  $output1 .= '<tr>';
1898  $output1 .= '<th>' . t('Total empleos directos Femeninos') . '</th>';
1899  $output1 .= '<td><div class="empleos_estimadosDf_totalesDf"></div></td>';
1900  $output1 .= '<th>' . t('Total Empleos directos Masculinos') . '</th>';
1901  $output1 .= '<td><div class="empleos_estimadosDm_totalesDm"></div></td>';
1902  $output1 .= '<th>' . t('Total empleos directos') . '</th>';
1903  $output1 .= '<td><div class="empleos_generados_total"></div></td>';
1904  $output1 .= '</tr>';
1905 
1906  $output .= $output1 .'</table></fieldset>';
1907  if (variable_get('proyectos_operativos_muestra_beneficiario', TRUE)) {
1908    $output .= drupal_render($form['beneficiario']);
1909  }
1910  $output .= '<fieldset><legend>' . t('Objetivos del Proyecto') . '</legend>' . drupal_render($form['field_proyecto_og']) . drupal_render($form['field_proyecto_oe']);
1911  if (count($form['#fields_form_dg_o'])) {
1912    foreach($form['#fields_form_dg_o'] as $id_c) {
1913      $output .= drupal_render($form[$id_c]);
1914    }
1915  }
1916  $output .= '</fieldset>';
1917
1918  $output .= drupal_render($form);
1919  return $output;
1920}
1921
1922/**
1923 * Agrega los nuevos campos en el formulario proyecto en la pestanha datos basicos
1924 */
1925function theme_proyectos_operativos_mcti_proyecto_basico_form($form) {
1926$output = '';
1927  $fecha_inicio = $form['#fechas_validacion']['inicio'];
1928  if ($form['#count_ae']) {
1929    $format_number = array(
1930      'decimals' => variable_get('proyectos_operativos_number_decimals', 0),
1931      'dec_point' => variable_get('proyectos_operativos_number_dec_point', ','),
1932      'thousands_sep' => variable_get('proyectos_operativos_number_thousands_sep', '.'),
1933    );
1934    $mensaje_mostrar = t('Existen @count_ae Acciones Específicas asignadas, con un monto total de @montos_asignados Bs asignados. y fechas de Inicio  @inicio y fin  @fin. Tome en consideración estos valores al momento de modificar los valores de los campos @title_fecha_i, @final title_fecha_f y @title_monto_total_proyecto_year', array('@count_ae' => $form['#count_ae'], '@montos_asignados' => number_format($form['#montos_asignados'], $format_number['decimals'], $format_number['dec_point'], $format_number['thousands_sep']), '@inicio' => $form['#fechas_validacion']['inicio_texto'], '@fin' => $form['#fechas_validacion']['fin_texto'], '@title_fecha_i' => $form['field_proyecto_fecha_i']['#title'], '@final title_fecha_f' => $form['field_proyecto_fecha_f']['#title'], '@title_monto_total_proyecto_year' => $form['field_proyecto_monto_anual']['#title'] ));
1935    $output .= '<div id="mensaje-mostrar" class="mensaje mensaje-mostrar" style="color:red;font-weight: bold;">' . $mensaje_mostrar . '</div>';
1936  }
1937  $output .= '<fieldset><legend>' . t('Datos Básicos de Identificación del Proyecto');
1938  $output .= '</legend>' . drupal_render($form['field_proyecto_titulo']);
1939  if (isset($form['field_proyecto_codigo']) && $form['field_proyecto_codigo']['#access']) {
1940    $output .= drupal_render($form['field_proyecto_codigo']);
1941  } 
1942  $descripcion = variable_get('proyectos_operativos_muestra_proyecto_descripcion', TRUE);
1943  if ($descripcion) {
1944    $output .= drupal_render($form['field_descripcin_proyect']);
1945  }
1946  if (isset($form['field_proyecto_fecha_i']) && $form['field_proyecto_fecha_i']['#access']) {
1947    $output .= drupal_render($form['field_proyecto_fecha_i']);
1948  }
1949  if (isset($form['field_proyecto_fecha_f']) && $form['field_proyecto_fecha_f']['#access']) {
1950    $output .=  drupal_render($form['field_proyecto_fecha_f']);
1951  }
1952  if (isset($form['field_proyecto_status']) && $form['field_proyecto_status']['#access']) {
1953    $output .= drupal_render($form['field_proyecto_status']);
1954  }
1955  if (isset($form['field_proyecto_situacion_p']) && $form['field_proyecto_situacion_p']['#access']) {
1956    $output .= drupal_render($form['field_proyecto_situacion_p']);
1957  }
1958  if (isset($form['field_proyecto_plurianual']) && $form['field_proyecto_plurianual']['#access']) {
1959    $output .= drupal_render($form['field_proyecto_plurianual']);
1960  }
1961  if (isset($form['field_proyecto_monto_anual']) && $form['field_proyecto_monto_anual']['#access']) {
1962    $output .= drupal_render($form['field_proyecto_monto_anual']);
1963  }
1964  if (isset($form['field_proyecto_total']) && $form['field_proyecto_total']['#access']) {
1965    $output .= drupal_render($form['field_proyecto_total']);
1966  }
1967  if (isset($form['field_proyecto_poan']) && $form['field_proyecto_poan']['#access']) {
1968    $output .= drupal_render($form['field_proyecto_poan']);
1969  }
1970  if (is_array($form['#fields_form_ac_d']) && count($form['#fields_form_ac_d'])) {
1971    foreach($form['#fields_form_ac_d'] as $id_a) {
1972      $output .= drupal_render($form[$id_a]);
1973    }
1974  }
1975  $output .= '</fieldset>';
1976
1977  $output .= '<fieldset><legend>' . t('Responsable del Proyecto') . '</legend>';
1978  $output .= '<div id="edit-field-proyecto-ente-nid-nid-wrapper" class="form-item"><label for="edit-field-proyecto-ente-nid-nid">Institucion:</label>' . check_plain($form['#ente_planificador']->title) . '</div>';
1979
1980  //responsables del proyecto
1981  $responsables_proye = variable_get('proyectos_operativos_muestra_responsables', TRUE);
1982  if ($responsables_proye) {
1983    $output .= drupal_render($form['responsables']);
1984  } 
1985
1986  $gerentes = variable_get('proyectos_operativos_muestra_gerentes', TRUE);
1987  if ($gerentes) {
1988    $output .= '<fieldset><legend>' . t('Gerente del Proyecto') . '</legend>';
1989    $output .= '<div id="edit-field-proyecto-ente-nid-nid-wrapper" class="form-item"><label for="edit-field-proyecto-ente-nid-nid">Institucion:</label>' . check_plain($form['#ente_planificador']->title) . '</div>';
1990    if (isset($form['field_proyecto_ente']) && $form['field_proyecto_ente']['#access']) {
1991      $output .= drupal_render($form['field_proyecto_ente']);
1992    }
1993    if (isset($form['field_proyecto_autoridad']) && $form['field_proyecto_autoridad']['#access']) {
1994      $output .= drupal_render($form['field_proyecto_autoridad']);
1995    }
1996    if (isset($form['field_proyecto_lider']) && $form['field_proyecto_lider']['#access']) {
1997      $output .= drupal_render($form['field_proyecto_lider']);
1998    }
1999    if (isset($form['field_proyecto_unidad_a']) && $form['field_proyecto_unidad_a']['#access']) {
2000      $output .= drupal_render($form['field_proyecto_unidad_a']);
2001    }
2002    if (isset($form['field_proyecto_cargo']) && $form['field_proyecto_cargo']['#access']) {
2003      $output .= drupal_render($form['field_proyecto_cargo']);
2004    }
2005    if (isset($form['field_proyecto_telefono']) && $form['field_proyecto_telefono']['#access']) {
2006      $output .= drupal_render($form['field_proyecto_telefono']);
2007    }
2008    if (isset($form['field_proyecto_correo']) && $form['field_proyecto_correo']['#access']) {
2009      $output .= drupal_render($form['field_proyecto_correo']);
2010    }
2011  }
2012  $output .= '</fieldset>';
2013
2014  $pndes = variable_get('proyectos_operativos_muestra_pndes', TRUE);
2015  $mcti = variable_get('proyectos_operativos_muestra_mcti', TRUE);
2016  $count_ac_p = count($form['#fields_form_ac_p']);
2017  $causas = variable_get('proyectos_operativos_muestra_causas_abordadas', TRUE);
2018  $problemas = variable_get('proyectos_operativos_muestra_problemas_abordados', TRUE);
2019  if ($pndes || $mcti || $count_ac_p || $causas || $problemas) {
2020    $output .= '<fieldset><legend>' . t('Área Estrategica') . '</legend>';
2021    if ($pndes) {
2022      $output .= drupal_render($form['field_proyecto_pndes']);
2023    }
2024    if ($mcti) {
2025      $output .= drupal_render($form['field_proyecto_mcti']);
2026    }
2027    if ($count_ac_p) {
2028      foreach($form['#fields_form_ac_p'] as $id_a) {
2029        $output .= drupal_render($form[$id_a]);
2030      }
2031    }
2032    if($problemas || $causas) {
2033      $output .= '<fieldset> Problemas y causas Abordadas';
2034      if($problemas) {
2035        $output .= drupal_render($form['field_proyect_probl_abord']);
2036      }
2037      if($causas) { 
2038        $output .= drupal_render($form['field_proyect_cau_abord']);
2039      }
2040      $output .= '</fieldset>';
2041    }
2042    $output .= '</fieldset>';
2043  }
2044  //area estrategica
2045 
2046  //ubicacion internacional
2047  if (variable_get('proyectos_operativos_muestra_ubicaci_interna', TRUE)) {
2048    $output .= '<fieldset id="proyectos_ubicacion"><legend>' . t('Localización del Proyecto') . '</legend>';
2049    $output .= '<fieldset><legend>' . t('Localización Internacional o Nacional') . '</legend>';
2050    $output .=  drupal_render($form['field_proyecto_ubicaci_inter']);
2051  }
2052  $output .= '</fieldset>';
2053  //ubicacion comunal
2054  $codig_comuna = variable_get('proyectos_operativos_muestra_codig_comuna', TRUE);
2055  $ubicacin_comuna = variable_get('proyectos_operativos_muestra_ubicacin_comuna', TRUE);
2056  $nombre_comuna = variable_get('proyectos_operativos_muestra_name_comuna', TRUE);
2057  if($codig_comuna || $ubicacin_comuna || $nombre_comuna) {
2058    $output .= '<fieldset><legend>' . t('Localización Comunal') . '</legend>';
2059    $output .= drupal_render($form['field_proyecto_codigo_comu']);
2060    $output .= drupal_render($form['field_proyecto_nombres_cum']);
2061    $output .= drupal_render($form['field_proyecto_ubicaci_comu']);
2062    $output .= '</fieldset>';
2063  }
2064  $output .= '</fieldset>';
2065 
2066  $output .= drupal_render($form);
2067  return $output;
2068}
2069
2070/**
2071 * Agrega los nuevos campos en el formulario proyecto en la pestanha indicadores
2072 */
2073function theme_proyectos_operativos_mcti_proyecto_indicadores_form($form) {
2074
2075  $output = '';
2076  if ($form['#count_ae'] && $form['#montos_asignados']!= $form['#node']->field_proyecto_monto_anual[0]['value']) {
2077    $format_number = array(
2078      'decimals' => variable_get('proyectos_operativos_number_decimals', 0),
2079      'dec_point' => variable_get('proyectos_operativos_number_dec_point', ','),
2080      'thousands_sep' => variable_get('proyectos_operativos_number_thousands_sep', '.'),
2081    );
2082    $link_acciones = l(t('Modificar Acciones específicas'), 'proyectosopedit/' . $form['#node']->nid . '/ae');
2083    $link_proyecto = l(t('Modificar Monto del Proyecto'), 'proyectosopedit/' . $form['#node']->nid);
2084    $mensaje_mostrar = t('Existen @count_ae Acciones Específicas asignadas con un monto total de @montos_asignados Bs, el cual difiere con el monto asignado en el proyecto para el @title_monto_total_proyecto_year (@monto_proyecto). Modifique los montos de las Acciones Específicas en !link_acciones o el monto del proyecto !link_proyecto para poder cerrar el proyecto operativo @nombre_proyecto', array('@count_ae' => $form['#count_ae'], '@montos_asignados' => number_format($form['#montos_asignados'], $format_number['decimals'], $format_number['dec_point'], $format_number['thousands_sep']), '@title_monto_total_proyecto_year' => $form['#proyecto_fields']['field_proyecto_monto_anual']['widget']['label'], '@monto_proyecto' => number_format($form['#node']->field_proyecto_monto_anual[0]['value'], $format_number['decimals'], $format_number['dec_point'], $format_number['thousands_sep']), '!link_acciones' => $link_acciones, '!link_proyecto' => $link_proyecto, '@nombre_proyecto' => $form['#node']->titulo_asignado,));
2085    $output .= '<div id="mensaje-mostrar-monto" class="mensaje mensaje-mostrar" style="color:red;font-weight: bold;">' . $mensaje_mostrar . '</div>';
2086  }
2087  if ($form['#count_ae'] && $fechas_validacion['inicio'] && $fechas_validacion['fin'] && ($fechas_validacion['inicio_time'] < $fechas_validacion['inicio_current_time'] || $fechas_validacion['fin_current_time'] < $fechas_validacion['fin_time'])) {
2088    $link_acciones = l(t('Modificar Acciones específicas'), 'proyectosopedit/' . $form['#node']->nid . '/ae');
2089    $link_proyecto = l(t('Modificar Monto del Proyecto'), 'proyectosopedit/' . $form['#node']->nid);
2090    $mensaje_mostrar = t('Existen @count_ae Acciones Específicas asignadas que difieren con la @title_fecha_de_inicio o @title_fecha_de_final del Proyecto. Modifique los montos de las Acciones Específicas en !link_acciones o el monto del proyecto !link_proyecto para poder cerrar el proyecto operativo @nombre_proyecto', array('@count_ae' => $form['#count_ae'], '@title_fecha_de_inicio' => $form['#proyecto_fields']['field_proyecto_fecha_i']['widget']['label'], '@title_fecha_de_final' => $form['#proyecto_fields']['field_proyecto_fecha_f']['widget']['label'], '!link_acciones' => $link_acciones, '!link_proyecto' => $link_proyecto, '@nombre_proyecto' => $form['#node']->titulo_asignado,));
2091    $output .= '<div id="mensaje-mostrar-time" class="mensaje mensaje-mostrar" style="color:red;font-weight: bold;">' . $mensaje_mostrar . '</div>';
2092  }
2093  if (variable_get('proyectos_operativos_muestra_enunciado_problema', TRUE)) {
2094    $output .= '<fieldset><legend>' . t('Enunciado del Problema') . '</legend>' . drupal_render($form['field_proyecto_causas']) . drupal_render($form['field_proyecto_problemas']) . drupal_render($form['field_proyecto_consecuencias']);
2095    if (count($form['#fields_form_ip_in'])) {
2096      foreach($form['#fields_form_ip_in'] as $id_c) {
2097        $output .= drupal_render($form[$id_c]);
2098      }
2099    }
2100    $output .= '</fieldset>';
2101  }
2102  if (variable_get('proyectos_operativos_muestra_justicacion', TRUE)) {
2103    $output .= '<fieldset><legend>' . t('Justificación del Proyecto') . '</legend>' . drupal_render($form['field_proyecto_justificacion']);
2104    if (count($form['#fields_form_ip_ju'])) {
2105      foreach($form['#fields_form_ip_ju'] as $id_c) {
2106        $output .= drupal_render($form[$id_c]);
2107      }
2108    }
2109    $output .= '</fieldset>';
2110  }
2111  if (variable_get('proyectos_operativos_muestra_alcance', TRUE)) {
2112    $output .= '<fieldset><legend>' . t('Alcance del Proyecto') . '</legend>' . drupal_render($form['field_proyecto_alcance']);
2113    if (count($form['#fields_form_ip_al'])) {
2114      foreach($form['#fields_form_ip_al'] as $id_c) {
2115        $output .= drupal_render($form[$id_c]);
2116      }
2117    }
2118    $output .= '</fieldset>';
2119  }
2120  $sa = variable_get('proyectos_operativos_muestra_sa', TRUE);
2121  $so = variable_get('proyectos_operativos_muestra_so', TRUE);
2122  if ($sa || $so) {
2123    $output .= drupal_render($form['indicador']);
2124  }
2125  $output .= '<fieldset><legend>' . t('Indicador del resultado del Proyecto') . '</legend>' ;
2126  $output .= drupal_render($form['field_proyecto_descripcion_bien']);
2127  $output .= drupal_render($form['field_proyecto_unidadm']);
2128  if (isset($form['field_proyecto_meta_m']) && $form['field_proyecto_meta_f']) {
2129    $output .= '<div id="meta-unidm-pers"><table id="unidm-persona" style="width:400px"><tr><th>' . $form['field_proyecto_meta_m']['#title'] . '</th><th>' . $form['field_proyecto_meta_f']['#title'] . '</th><th>' . t('Total') . '</th></tr><tr>';
2130    $form['field_proyecto_meta_m'][0]['value']['#title'] = '';
2131    $form['field_proyecto_meta_f'][0]['value']['#title'] = '';
2132    $total = $form['field_proyecto_meta_m'][0]['#value']['value'] + $form['field_proyecto_meta_f'][0]['#value']['value'];
2133    $output .= '<td>' . drupal_render($form['field_proyecto_meta_m']) . '</td>';
2134    $output .= '<td>' . drupal_render($form['field_proyecto_meta_f']) . '</td>';
2135   
2136    $output .= '<td style="width:100px; text-align: center"><div class="unidad_personas_total">' . number_format($total, $format_number['decimals'], $format_number['dec_point'], $format_number['thousands_sep']) . '</div></td></tr></table></div>';
2137  }
2138
2139  $output .= drupal_render($form['field_proyecto_meta_fisica']);
2140
2141  if (count($form['#fields_form_ip_re'])) {
2142    foreach($form['#fields_form_ip_re'] as $id_c) {
2143      $output .= drupal_render($form[$id_c]);
2144    }
2145  }
2146  $output .= '</fieldset>';
2147  //agregando el efecto hide y show
2148  drupal_add_js(drupal_get_path('module', 'proyectos_operativos_mcti') . '/js/proyectos_operativos_mcti_generales.js');
2149  $form['field_tipo_factores']['value']['#attributes'] = array(
2150     'class' => ' field_tipo_factores',
2151     'onchange' => ";ocultarCampo('field_tipo_factores', 'field_factor_impact_multifc');",
2152  );
2153  $form['field_factor_segun_origen']['value']['#attributes'] = array(
2154     'class' => ' field_factor_segun_origen',
2155     'onchange' => ";ocultarCampo('field_factor_segun_origen', 'field_factor_impact_multiog');",
2156  );
2157  $form['field_factor_impact_multifc']['#prefix'] = '<div class="field_factor_impact_multifc">';
2158  $form['field_factor_impact_multifc']['#suffix'] = '</div>';
2159  $form['field_factor_impact_multiog']['#prefix'] = '<div class="field_factor_impact_multiog">';
2160  $form['field_factor_impact_multiog']['#suffix'] = '</div>';
2161
2162  //agregando la sesion Impacto Ambiental del Proyecto
2163  $servicios = variable_get('proyectos_operativos_muestra_impacto_ambiental', TRUE);
2164  $arrreglo['impacto']['factor1'] = array(
2165    'field_factor_naturaleza' => 'field_factor_naturaleza',
2166    'field_factor_intensidad' => 'field_factor_intensidad',
2167    'field_factor_momento' => 'field_factor_momento',
2168    'field_factor_persistencia' => 'field_factor_persistencia',
2169    'field_factor_reversibilidad' => 'field_factor_reversibilidad',
2170  );
2171  $arrreglo['impacto']['factor2'] = array(
2172    'field_factor_extension' => 'field_factor_extension',
2173    'field_factor_sinergismo' => 'field_factor_sinergismo',
2174    'field_factor_acumulacion' => 'field_factor_acumulacion',
2175    'field_factor_relacion' =>'field_factor_relacion',
2176    'field_factor_recuperabilidad' => 'field_factor_recuperabilidad',
2177  );
2178  $arrreglo['impacto']['factor3'] = array(
2179    'field_factor_importancia' => 'field_factor_importancia',
2180    'field_factor_medids_impact' => 'field_factor_medids_impact',
2181  );
2182  $arrreglo['impacto']['tipo'] = array(
2183    'field_tipo_factores' => 'field_tipo_factores',
2184    'field_factor_impact_multifc' => 'field_factor_impact_multifc',
2185    'field_factor_segun_origen' => 'field_factor_segun_origen',
2186    'field_factor_impact_multiog' => 'field_factor_impact_multiog',
2187  );
2188  if ($servicios) {
2189    $output_fa = '<table><tr>';
2190    $output_fb = '<tr>';
2191    $output_fc = '<tr>';
2192    $output .= '<fieldset><legend>' . t('Impacto Ambiental del Proyecto') . '</legend>';
2193    if (count($form['#proyectos_operativos_fields'])) {
2194      foreach ($form['#proyectos_operativos_fields'] as $key => $id_c) {
2195        if (array_key_exists($id_c,  $arrreglo['impacto']['factor1'])) {
2196          $output_fa .= '<th> '. $form[$id_c]['#title'] .'</th>';
2197        }
2198        if (array_key_exists($id_c,  $arrreglo['impacto']['factor2'])) {
2199          $output_fb .= '<th> '. $form[$id_c]['#title'] .'</th>';
2200        }
2201        if (array_key_exists($id_c,  $arrreglo['impacto']['factor3'])) {
2202          $row = '';
2203          if ($id_c == 'field_factor_medids_impact') {
2204            $row = 'colspan = 4';
2205          }
2206          $output_fc .= '<th '.$row.'>'. $form[$id_c]['#title'] .'</th>';
2207        }
2208      }
2209      $output_fa .= '</tr><tr>';
2210      $output_fb .= '</tr><tr>';
2211      $output_fc .= '</tr><tr>';
2212      foreach ($form['#proyectos_operativos_fields'] as $key => $id_c) {
2213        if (array_key_exists($id_c,  $arrreglo['impacto']['tipo'])) {
2214          $output1 .= drupal_render($form[$id_c]);
2215        }
2216        //eliminando los labels de los campos
2217        unset($form[$id_c]['value']['#title']);
2218        unset($form[$id_c][0]['value']['#title']);
2219        if (array_key_exists($id_c,  $arrreglo['impacto']['factor1'])) {
2220          $output_fa .= '<td>'.drupal_render($form[$id_c]).'</td>';
2221        }
2222        if (array_key_exists($id_c,  $arrreglo['impacto']['factor2'])) {
2223          $output_fb .= '<td>'.drupal_render($form[$id_c]).'</td>';
2224        }
2225        if (array_key_exists($id_c,  $arrreglo['impacto']['factor3'])) {
2226          $row = '';
2227          if ($id_c == 'field_factor_medids_impact') {
2228            $row = 'colspan = 4';
2229          }
2230          $output_fc .= '<td '.$row.'>'.drupal_render($form[$id_c]).'</td>';
2231        }
2232      }
2233      $output_fa .= '</tr>';
2234      $output_fb .= '</tr>';
2235      $output_fc .= '</tr></table>';
2236      $output2 = $output_fa . $output_fb . $output_fc;
2237      $output .= '<fieldset><legend>' . t('Tipo de impacto') . '</legend>';
2238      $output1.= '<div id="wrapper_field_tipo_factores"></div>';
2239      $output1 .= '<div id="wrapper_field_factor_segun_origen"></div>';
2240      $output .= $output1 . '</fieldset>';
2241      $output .= '<fieldset><legend>' . t('Caracterización cualitativa de los efectos') . '</legend>';
2242      $output .= $output2 . '</fieldset>';
2243    }
2244    $output .= '</fieldset>';
2245  }
2246  //Balance Estimado Nacional de Servicios Energéticos
2247  $balance = variable_get('proyectos_operativos_muestra_servicios_balance', TRUE);
2248  if ($balance) {
2249    $output .= '<div>' . drupal_render($form['balance']) . '</div>';
2250  }
2251  //Programacion anual por consumidor
2252  $programacion = variable_get('proyectos_operativos_muestra_programacion_anual', TRUE);
2253  if ($programacion) {
2254    $output .= '<div>' . drupal_render($form['programacion']) . '</div>';
2255  }
2256  $output .= drupal_render($form);
2257  return $output;
2258}
2259
2260/**
2261 * Agrega mas campos
2262 */
2263function proyectos_operativos_mcti_proyecto_generales_agrega_talento_js_util($tipo) {
2264  $arreglov['talento'] = array(
2265    'field_proyecto_institucionth' => 'field_proyecto_institucionth',
2266    'field_proyecto_nombres_a' => 'field_proyecto_nombres_a',
2267    'field_proyecto_cargo_th' => 'field_proyecto_cargo_th',
2268    'field_proyecto_rol_th' => 'field_proyecto_rol_th',
2269    'field_proyecto_esfuerzo' => 'field_proyecto_esfuerzo',
2270    'field_proyecto_formacion' => 'field_proyecto_formacion',
2271  );
2272  $arreglov['capacidades'] = array(
2273    'field_proyecto_institucion_alc' => 'field_proyecto_institucion_alc',
2274    'field_proyecto_infraestructura' => 'field_proyecto_infraestructura',
2275    'field_proyecto_equipos' => 'field_proyecto_equipos',
2276    'field_proyecto_insumos' => 'field_proyecto_insumos',
2277    'field_proyectos_servicios' => 'field_proyectos_servicios',
2278  );
2279  $arreglov['beneficiario'] = array(
2280    'field_proyecto_beneficiario' => 'field_proyecto_beneficiario',
2281    'field_proyectos_masculino_d' => 'field_proyectos_masculino_d',
2282   // 'field_proyectos_femenino_d' => 'field_proyectos_femenino_d',
2283  //  'field_proyectos_masculino_i' => 'field_proyectos_masculino_i',
2284    'field_proyectos_femenino_i' => 'field_proyectos_femenino_i',
2285  );
2286  $labels = array(
2287    'field_proyecto_beneficiario' => 'Beneficiario ',
2288    'field_proyectos_masculino_d' => 'Número estimado de beneficiarios masculinos',
2289    'field_proyectos_femenino_i' => 'Número estimado de beneficiarios femeninos',
2290  );
2291  if (array_key_exists($tipo, $arreglov)) {
2292    $arreglo = $arreglov[$tipo];
2293  }
2294  else {
2295    drupal_not_found();
2296  }
2297  $cantidad = intval($_POST['cantidad_' . $tipo]) > 0 ? intval($_POST['cantidad_' . $tipo]) : 0;
2298  $form_state = array('submitted' => FALSE);
2299  $form_build_id = $_POST['form_build_id'];
2300  // Add the new element to the stored form. Without adding the element to the
2301  // form, Drupal is not aware of this new elements existence and will not
2302  // process it. We retreive the cached form, add the element, and resave.
2303  $form = form_get_cache($form_build_id, $form_state);
2304  $node_type = content_types('proyectos_operativos');
2305  $fields = $node_type['fields'];
2306  foreach ($arreglo as $field_id => $field) {
2307    $fields_extra_form1[] = $field_id;
2308    $prefixC .= '<th>' . $labels[$field_id] . '</th>';
2309  }
2310  $cantidad++;
2311  if ($tipo == 'talento' || $tipo == 'capacidades') {
2312    for ($i = 0; $i < $cantidad; $i++) {
2313      $prefix = '';
2314      if ($i == 0) {
2315        $prefix = '<table align="center"><tr>' . $prefixC . '</tr><tr><td>';
2316      }
2317      else {
2318        $prefix .= '<tr><td>';
2319      }
2320      $aux = '';
2321      $aui = '';
2322      foreach ($arreglo as $field_id => $field) {
2323        $new_form[$field_id . '_' . $i] = array(
2324          '#type' => 'textfield',
2325          '#size' => 10,
2326          '#maxlength' => 255,
2327          '#prefix' => $prefix,
2328          '#suffix' => '</td>',
2329        );
2330        if ($field_id == 'field_proyecto_esfuerzo') {
2331          $form[$field_id . '_' . $i]['#element_validate'] = array('proyectos_operativos_number_integer_validate2',);
2332        }
2333        $aux = $field_id;
2334        $aui = $i;
2335        $prefix = '<td>';
2336      }
2337      $new_form[$aux . '_' . $aui]['#suffix'] .= '</tr>';
2338    }
2339    $new_form[$aux . '_' . $aui]['#suffix'] .= '</table>';
2340    $new_form['cantidad_' . $tipo] = array('#type' => 'hidden', '#value' => $cantidad);
2341  }
2342  elseif ($tipo == 'beneficiario') {
2343    $prefixC .= '<th>' . t('Total') . '</th>';
2344    $vid = variable_get('proyectos_operativos_extra_bene', 0);
2345    $tree = taxonomy_get_tree($vid);
2346    $options = array();
2347    $options[''] = t('Seleccionar');
2348    if ($tree) {
2349      foreach ($tree as $term) {
2350        $options[$term->name] = $term->name;
2351      }
2352    }
2353    for ($i = 0; $i < $cantidad; $i++) {
2354      $subtotal = 0;
2355      $prefix = '';
2356      if ($i == 0) {
2357        $prefix = '<table align="center"><tr>' . $prefixC . '</tr><tr><td>';
2358      }
2359      else {
2360        $prefix .= '<tr><td>';
2361      }
2362      $aux = '';
2363      $aui = '';
2364      foreach ($arreglo as $field_id => $field) {
2365        $_POST[$field_id . '_' . $i] = str_replace('.', '', $_POST[$field_id . '_' . $i]);
2366        $valor = intval($_POST[$field_id . '_' . $i]) > 0 ? intval($field_id . '_' . $i) : 0;
2367        if ($field_id == 'field_proyecto_beneficiario') {
2368          $new_form[$field_id . '_' . $i] = array(
2369            '#type' => 'select',
2370            '#default_value' => $valor,
2371            '#options' => $options,
2372            '#prefix' => $prefix,
2373            '#suffix' => '</td>',
2374          );
2375        }
2376        else {
2377          $new_form[$field_id . '_' . $i] = array(
2378            '#type' => 'textfield',
2379            '#default_value' => $valor,
2380            '#size' => 10,
2381            '#maxlength' => 255,
2382            '#prefix' => $prefix,
2383            '#suffix' => '</td>',
2384          );
2385        }
2386        if ($field_id != 'field_proyecto_beneficiario') {
2387          if (!isset($total_arreglo[$field_id])) {
2388            $total_arreglo[$field_id] = 0;
2389          }
2390          $subtotal += (int) $valor;
2391          $totales += (int) $valor;
2392          $total_arreglo[$field_id] += (int) $valor;
2393          $sumas['beneficiarios']['beneficiario_' . $i] = 'beneficiario_' . $i;
2394          $new_form[$field_id . '_' . $i]['#element_validate'] = array('proyectos_operativos_number_integer_validate2',);
2395          $new_form[$field_id . '_' . $i]['#attributes'] = array('class' => 'number beneficiario_' . $i . ' todosbeneficiarios beneficiarios_' . $field_id, 'onchange' => "sumabeneficiario('beneficiario_$i');sumabeneficiario('todosbeneficiarios');sumabeneficiario('beneficiarios_$field_id');");
2396        }
2397        $aux = $field_id;
2398        $aui = $i;
2399        $prefix = '<td align="center">';
2400      }
2401      $new_form[$aux . '_' . $aui]['#suffix'] .= '<td align="center"><div class="beneficiario_' . $i . '_total">' . $subtotal . '</div></td>';
2402      $new_form[$aux . '_' . $aui]['#suffix'] .= '</tr>';
2403    }
2404    $new_form[$aux . '_' . $aui]['#suffix'] .= '<tr align="right"><td><b>' . t('TOTAL DE BENEFICIARIOS') . '</b></td>';
2405    foreach ($arreglo as $field_id => $field) {
2406      if ($field_id != 'field_proyecto_beneficiario') {
2407        $sumas['beneficiarios']['beneficiarios_' . $field_id] = 'beneficiarios_' . $field_id;
2408        $new_form[$aux . '_' . $aui]['#suffix'] .= '<td align="center"><div class="beneficiarios_' . $field_id . '_total">' . $total_arreglo[$field_id] . '</div></td>';
2409      }
2410    }
2411    $sumas['beneficiarios']['todosbeneficiarios'] = 'todosbeneficiarios';
2412    $sumas['beneficiarios']['empleos_generados'] = 'empleos_generados';
2413    $new_form[$aux . '_' . $aui]['#suffix'] .= '<td align="center"><div class="todosbeneficiarios_total">' . $totales . '</div></td></tr>';
2414    $new_form[$aux . '_' . $aui]['#suffix'] .= '</table>';
2415    $new_form['cantidad_' . $tipo] = array('#type' => 'hidden', '#value' => $cantidad);
2416  }
2417  $form[$tipo] = $new_form;
2418  form_set_cache($form_build_id, $form, $form_state);
2419  $form += array(
2420    '#post' => $_POST,
2421    '#programmed' => FALSE,
2422  );
2423  // Rebuild the form.
2424  $form = form_builder($_POST['form_id'], $form, $form_state);
2425  // Render the new output.
2426  $new_form = $form[$tipo];
2427
2428  if ($tipo == 'talento' || $tipo == 'capacidades') {
2429    for ($i = 0; $i < $cantidad; $i++) {
2430      if ($i == 0) {
2431        $prefix = '<table align="center"><tr>' . $prefixC . '</tr><tr><td>';
2432      }
2433      foreach($arreglo as $field_id => $field) {
2434        $new_form[$field_id . '_' . $i] = $form[$tipo][$field_id . '_' . $i];
2435        if ($prefix != '') {
2436          $new_form[$field_id . '_' . $i]['#prefix'] = $prefix;
2437        }
2438        $prefix = '';
2439        $aux = $field_id;
2440        $aui = $i;
2441        $new_form[$aux . '_' . $aui] = $form[$tipo][$aux . '_' . $aui];
2442      }
2443      $new_form[$aux . '_' . $aui] = $form[$tipo][$aux . '_' . $aui];
2444    }
2445    $new_form[$aux . '_' . $aui]['#suffix'] .= '</table>';
2446    $new_form['cantidad_' . $tipo] = array('#type' => 'hidden', '#value' => $cantidad);
2447  }
2448
2449  $new_form['cantidad_' . $tipo] = $form[$tipo]['cantidad_' . $tipo];
2450  unset($new_form['cantidad_' . $tipo]['#suffix']);
2451  unset($new_form['#prefix'], $new_form['#suffix']); // Prevent duplicate wrappers.
2452  //unset($new_form['agrega_' . $tipo]);
2453  $output = drupal_render($new_form);
2454  print drupal_to_js(array('data' => $output, 'status' => true));
2455  exit();
2456}
2457
2458/**
2459 * Agrega mas campos para indicadores form
2460 */
2461function proyectos_operativos_mcti_agrega_indicadores_js_util($tipo) {
2462  $arreglov['balance'] = array(
2463    'field_balnc_progrmn_anu' => 'field_balnc_progrmn_anu',
2464    'field_balance_fuente' => 'field_balance_fuente',
2465    'field_balanc_tipofuent' => 'field_balanc_tipofuent',
2466    'field_balanc_tipoProd' => 'field_balanc_tipoProd',
2467    'field_balanc_unidMed' => 'field_balanc_unidMed',
2468    'field_balanc_capacid' => 'field_balanc_capacid',
2469    'field_balanc_anho' => 'field_balanc_anho',
2470  );
2471  $arreglov['programacion'] = array(
2472    'field_progrmcn_anual_prog' => 'field_progrmcn_anual_prog',
2473    'field_progrmcn_anual_unid' => 'field_progrmcn_anual_unid',
2474    'field_progrmcn_anual_cap' => 'field_progrmcn_anual_cap',
2475    'field_progrmcn_anual_anho' => 'field_progrmcn_anual_anho',
2476  );
2477  if (array_key_exists($tipo, $arreglov)) {
2478    $arreglo = $arreglov[$tipo];
2479  }
2480  else {
2481    drupal_not_found();
2482  }
2483  //anho para las opciones balance y programacion
2484  $current_year = date("Y");
2485        $years[0] = t('Seleccione');
2486  for ($i = $current_year - 10; $i <= $current_year; $i++) {
2487    $years[$i] = $i;
2488  }
2489
2490  $form_state = array('submitted' => FALSE);
2491  $form_build_id = $_POST['form_build_id'];
2492  // Add the new element to the stored form. Without adding the element to the
2493  // form, Drupal is not aware of this new elements existence and will not
2494  // process it. We retreive the cached form, add the element, and resave.
2495  $form = form_get_cache($form_build_id, $form_state);
2496  $node_type = content_types('proyectos_operativos');
2497  $fields = $node_type['fields'];   
2498  $prefixC = '';
2499  $fields_extra_form1 = array();
2500  foreach ($arreglo as $field_id => $field) {
2501    $fields_extra_form1[] = $field_id;
2502    $prefixC .= '<th>' . $fields[$field_id]['widget']['label'] . '</th>';
2503  }
2504  $cantidad = intval($_POST['cantidad_'.$tipo]) > 0 ? intval($_POST['cantidad_'.$tipo]) : 0;
2505  $cantidad++;
2506  $prefix = '';
2507  $aux = '';
2508  $aui = '';
2509
2510  for ($i = 0; $i < $cantidad; $i++) {
2511    if ($i == 0) {
2512      $prefix = '<table><tr>' . $prefixC . '</tr><tr><td>';
2513    }
2514    else {
2515      $prefix .= '<tr><td>';
2516    }
2517    foreach ($arreglo as $field_id => $field) {   
2518      if ($field_id == 'field_progrmcn_anual_cap' && $tipo == 'programacion') {
2519        $new_form[$field_id . '_' . $i] = array(
2520          '#type' => 'textfield',
2521          '#size' => $fields[$field_id]['size'],
2522          '#maxlength' => $fields[$field_id]['max_length'],   
2523          '#prefix' => $prefix,
2524          '#suffix' => '</td>',
2525         );
2526       }
2527           elseif (($field_id == 'field_balanc_anho' || $field_id == 'field_progrmcn_anual_anho') && ($tipo == 'balance' || $tipo == 'programacion')) {
2528                   $new_form[$field_id . '_' . $i] = array(
2529         '#type' => 'select',
2530         '#maxlength' => $fields[$field_id]['max_length'],
2531                         '#required' => $fields[$field_id]['required'],
2532         '#options' => $years,
2533                         '#prefix' => $prefix,
2534         '#suffix' => '</td>',
2535             );
2536           }
2537     else {
2538         $options = optionwidgets_options($fields[$field_id], FALSE);
2539         $new_form[$field_id . '_' . $i] = array(
2540           '#type' => 'select',
2541           '#options' => $options,
2542           '#prefix' => $prefix,
2543           '#suffix' => '</td>',
2544         );
2545       }
2546       $aux = $field_id;
2547       $aui = $i;
2548       $prefix = '<td>';
2549     }
2550     $new_form[$aux . '_' . $aui]['#suffix'] .= '</tr>';
2551   }
2552   $new_form[$aux . '_' . $aui]['#suffix'] .= '</table>';
2553   $new_form['cantidad_'.$tipo] = array('#type' => 'hidden', '#value' => $cantidad);
2554   
2555   $form[$tipo] = $new_form;
2556   form_set_cache($form_build_id, $form, $form_state);
2557   $form += array(
2558     '#post' => $_POST,
2559     '#programmed' => FALSE,
2560   );
2561   // Rebuild the form.
2562   $form = form_builder($_POST['form_id'], $form, $form_state);
2563   // Render the new output.
2564   $new_form = $form[$tipo];
2565   unset($new_form['#prefix'], $new_form['#suffix']); // Prevent duplicate wrappers.
2566   $output = drupal_render($new_form);
2567   print drupal_to_js(array('data' => $output, 'status' => true));
2568   exit();
2569}
2570
2571/**
2572 * Carga los datos de los responsables del proyecto
2573 */
2574function proyectos_operativos_mcti_proyecto_basico_form_responsables_js_util($tipo) {
2575  $form_state = array(
2576    'submitted' => FALSE,
2577  );
2578  $form_build_id = $_POST['form_build_id'];
2579  // Add the new element to the stored form. Without adding the element to the
2580  // form, Drupal is not aware of this new elements existence and will not
2581  // process it. We retreive the cached form, add the element, and resave.
2582  $form = form_get_cache($form_build_id, $form_state);
2583 
2584  $nid = $_POST['field_proyecto_ente'];
2585  $node_type = content_types('proyectos_operativos');
2586  $fields = $node_type['fields'];
2587  $query_ins = db_query("SELECT nid, title FROM {node} WHERE type='ente_planificador' AND status=1");
2588  while ($row = db_fetch_object($query_ins)) {
2589          $instituciones[$row->nid] = $row->title;
2590  }
2591 
2592  $new_form['responsables'] = array(
2593    '#title' => t(''),
2594    '#type' => 'fieldset',
2595  );
2596  /*$new_form['responsables']['field_proyecto_ente'] = array(
2597    '#title' => t('Insitución'),
2598    '#type' => 'select',
2599    '#options' => $instituciones,
2600    '#ahah' => array(
2601      'path' => 'proyectos_operativos_mcti_proyecto_basico_form_responsables/responsables',
2602      'wrapper' => 'wrapper-proyectos-resposab',
2603      'method' => 'replace',
2604      'progress' => array('type' => 'throbber', 'message' => t('Please wait...')),
2605    ),
2606    '#prefix' => '<div id="field_proyecto_ente_datos_basicos">',
2607    '#suffix' => '</div>',
2608  );
2609      */
2610  $arreglo = array();
2611  $tipos = array(
2612    'gerente' => 'gerente',
2613    'tecnico' => 'tecnico',
2614    'registrador' => 'registrador',
2615    'administrativo' => 'administrativo',
2616  );
2617  $arreglo['gerente'] = array(
2618    0 => 'field_proyecto_nombre_gere',
2619    1 => 'field_proyecto_cedul_gere',
2620    2 => 'field_proyecto_corre_gere',
2621    3 => 'field_proyecto_telef_gere',
2622  );
2623  $arreglo['tecnico'] = array(
2624    0 => 'field_proyecto_nom_r_tec',
2625    1 => 'field_proyecto_ced_r_tec',
2626    2 => 'field_proyecto_cor_r_tec',
2627    3 => 'field_proyecto_tel_r_tec',
2628    4 => 'field_proyecto_und_r_tec',
2629  );
2630  $arreglo['registrador'] = array(
2631    0 => 'field_proyecto_nom_r_reg',
2632    1 => 'field_proyecto_ced_r_reg',
2633    2 => 'field_proyecto_cor_r_reg',
2634    3 => 'field_proyecto_tel_r_reg',
2635  );
2636  $arreglo['administrativo'] = array(
2637    0 => 'field_proyecto_nom_r_adm',
2638    1 => 'field_proyecto_ced_r_adm',
2639    2 => 'field_proyecto_cor_r_adm',
2640    3 => 'field_proyecto_tel_r_adm',
2641    4 => 'field_proyecto_und_r_adm',
2642  ); 
2643 
2644  $query['gerente'] = db_query("SELECT DISTINCT(pp.vid), pp.field_proyecto_nombre_gere_value as field_proyecto_nombre_gere, pp.field_proyecto_cedul_gere_value as field_proyecto_cedul_gere FROM {node} as n INNER JOIN {proyectos_operativos} as p ON n.nid=p.nid INNER JOIN {content_type_proyectos_operativos} as pp ON pp.nid = p.nid WHERE n.type='proyectos_operativos' AND p.ente=%d AND n.vid=pp.vid AND n.status=1 ORDER BY pp.vid asc", $nid);
2645  $query['tecnico'] = db_query("SELECT DISTINCT(pp.vid), pp.field_proyecto_nom_r_tec_value as field_proyecto_nom_r_tec, pp.field_proyecto_ced_r_tec_value as field_proyecto_ced_r_tec FROM {node} as n INNER JOIN {proyectos_operativos} as p ON n.nid=p.nid INNER JOIN {content_type_proyectos_operativos} as pp ON pp.nid = p.nid WHERE n.type='proyectos_operativos' AND p.ente=%d AND n.vid=pp.vid AND n.status=1 ORDER BY pp.vid asc", $nid);
2646  $query['registrador'] = db_query("SELECT DISTINCT(pp.vid), pp.field_proyecto_nom_r_reg_value as field_proyecto_nom_r_reg, pp.field_proyecto_ced_r_reg_value as field_proyecto_ced_r_reg FROM {node} as n INNER JOIN {proyectos_operativos} as p ON n.nid=p.nid INNER JOIN {content_type_proyectos_operativos} as pp ON pp.nid = p.nid WHERE n.type='proyectos_operativos' AND p.ente=%d AND n.vid=pp.vid AND n.status=1 ORDER BY pp.vid asc", $nid);
2647  $query['administrativo'] = db_query("SELECT DISTINCT(pp.vid), pp.field_proyecto_nom_r_adm_value as field_proyecto_nom_r_adm, pp.field_proyecto_ced_r_adm_value as field_proyecto_ced_r_adm FROM {node} as n INNER JOIN {proyectos_operativos} as p ON n.nid=p.nid INNER JOIN {content_type_proyectos_operativos} as pp ON pp.nid = p.nid WHERE n.type='proyectos_operativos' AND p.ente=%d AND n.vid=pp.vid AND n.status=1 ORDER BY pp.vid asc", $nid);
2648
2649  foreach ($tipos as $tip) {
2650                $options = array();
2651    $options[0] = t('Seleccione');
2652                $count = 0;
2653                $prefixC = '';
2654                while ($row = db_fetch_object($query[$tip]) ) {
2655                  if ($row->$arreglo[$tip][0] != null || $row->$arreglo[$tip][1] != null) {
2656        $options[$row->vid] = $row->$arreglo[$tip][0] . '('. $row->$arreglo[$tip][1] .')';
2657                  }
2658    }
2659    $options[$row->vid + 1] = t('Nuevo');
2660    $new_form['responsables']['default_'.$tip] = array(
2661      '#type' => 'select',
2662      '#title' => t('Cargar datos del '.$tip),
2663      '#options' => $options,
2664      '#prefix' => '<fieldset id="wrapper-'.$tip.'-datos"><legend>' . t('Responsable '.$tip ) . '</legend>',
2665    );
2666    $new_form['responsables']['default_'.$tip]['#prefix'] .= '<div id="default_'.$tip.'_select">';
2667    $new_form['responsables']['default_'.$tip]['#suffix'] .= '</div>';
2668    if (count($fields)) {
2669          foreach ($arreglo[$tip] as $field_id => $field) {
2670        $prefixC .= '<th>' . $fields[$field]['widget']['label'] . '</th>';
2671          }
2672          foreach ($arreglo[$tip] as $field_id => $field) {
2673        $prefix = '';
2674            if ($count == 0) {
2675          $prefix = '<div id="default_'.$tip.'"><table><tr>' . $prefixC . '</tr><tr><td>';
2676        }
2677        else {
2678          $prefix .= '<td>';
2679        }
2680        $new_form['responsables'][$field] = array(
2681          '#type' => 'textfield',
2682          '#required' => $fields[$field]['required'],
2683          '#maxlength' => $fields[$field]['max_length'],
2684          '#size' => $fields[$field]['size'],
2685          '#weight' => $fields[$field]['weight'],
2686          '#description' => $fields[$field]['description'],
2687          '#prefix' => $prefix,
2688          '#suffix' => '</td>',
2689        );
2690        $aux = $field;
2691        $count++;
2692      }
2693      $new_form['responsables'][$aux]['#suffix'] .= '</tr>';
2694      $new_form['responsables'][$aux]['#suffix'] .= '</table></div></fieldset>';
2695    }
2696  }
2697 
2698  $form[$tipo] = $new_form;
2699  form_set_cache($form_build_id, $form, $form_state);
2700  $form += array(
2701    '#post' => $_POST,
2702    '#programmed' => FALSE,
2703  );
2704  // Rebuild the form.
2705 
2706  $form = form_builder($_POST['form_id'], $form, $form_state);
2707  // Render the new output.
2708  $new_form = $form[$tipo];
2709  unset($new_form['#prefix'], $new_form['#suffix']); // Prevent duplicate wrappers.
2710  $output = drupal_render($new_form);
2711  print drupal_to_js(array('data' => $output, 'status' => true));
2712  exit();
2713}
2714
2715/**
2716 * Implementation of proyectos_operativos_search_ac_display().
2717 * Muestra la lista de proyectos disponibles.
2718 */
2719function proyectos_operativos_mcti_search_ac_display() {
2720  global $user;
2721  $current_time = time();
2722  $tipo_plan = 'proyectos_operativos_formular';
2723  $mi_fecha = ente_planificador_user_acceso_proceso($tipo_plan, 2);
2724  $fecha = FALSE;
2725  $ente = usuario_tiene_ente($user->uid);
2726  if ($mi_fecha[1]  + 86399 > $current_time && $mi_fecha[0] < $current_time) {
2727    $fecha = TRUE;
2728  }
2729  if (!$fecha) {
2730    muestra_mensaje($tipo_plan, 2);
2731  }
2732  if ($fecha && $ente->nid) {
2733    muestra_mensaje($tipo_plan, 2, 0);
2734  }
2735  $states = array();
2736  $first_state = 0;
2737  if (module_exists('workflow')) {
2738    $states = _proyectos_operativos_reformula_obtiene_estados();
2739    if ($states['wid']) {
2740      $first_state = _workflow_creation_state($states['wid']);
2741    }
2742  }
2743  $output = drupal_get_form('proyectos_operativos_mcti_search_ac_form');
2744  $mi_ambito = db_result(db_query("SELECT ambito FROM {ente_user_planificador} where usuario = %d", $user->uid));
2745  $inputs = array();
2746  $sql = '';
2747  if (!user_access('admin planificador') && $user->entes) {
2748    $inputs[] = $user->entes;
2749    $inputs[] = variable_get('proyectos_operativos_state_naprobado', NULL);
2750    $sql .= "SELECT ac.nid, ac.year, w.sid, n.created, n.title as nombre, u.name, n.uid, e.title AS ente, ctpo.field_proyecto_titulo_value, ent.ambito, ent.sector, ent.organismo, ent.ente_adscrito, ent.sub_ente, ctpo.field_proyecto_sector_value, ctpo.field_proyecto_pndes_value FROM {proyectos_operativos} AS ac INNER JOIN {node} AS n ON n.nid = ac.nid INNER JOIN {users} AS u ON u.uid = n.uid INNER JOIN {node} as e ON e.nid = ac.ente INNER JOIN {workflow_node} AS w ON w.nid = ac.nid INNER JOIN {ente_planificador} AS ent ON ac.ente = ent.nid LEFT JOIN {content_type_proyectos_operativos} AS ctpo ON ctpo.nid = n.nid AND ctpo.vid = n.vid  WHERE ac.ente = %d AND w.sid <> %d";
2751//    $sql .= "SELECT ac.nid, ac.year, w.sid, n.created, n.title as nombre, u.name, n.uid, e.title AS ente FROM {proyectos_operativos} AS ac INNER JOIN {node} AS n ON n.nid = ac.nid INNER JOIN {users} AS u ON u.uid = n.uid INNER JOIN {node} as e ON e.nid = ac.ente INNER JOIN {workflow_node} AS w ON w.nid = ac.nid WHERE ac.ente = %d AND w.sid <> %d";
2752  }
2753  elseif (user_access('admin planificador')) {
2754    $inputs[] = variable_get('proyectos_operativos_state_naprobado', NULL);
2755    $sql .= "SELECT ac.nid, ac.year, ac.ente, w.sid, n.created, n.title as nombre,  u.name, n.uid, e.title AS enten, ctpo.field_proyecto_titulo_value, ent.ambito, ent.sector, ent.organismo, ent.ente_adscrito, ent.sub_ente, ctpo.field_proyecto_sector_value, ctpo.field_proyecto_pndes_value FROM {proyectos_operativos} AS ac INNER JOIN {node} AS n ON n.nid = ac.nid INNER JOIN {users} AS u ON u.uid = n.uid INNER JOIN {node} as e ON e.nid = ac.ente INNER JOIN {workflow_node} AS w ON w.nid = ac.nid INNER JOIN {ente_planificador} AS ent ON ac.ente = ent.nid LEFT JOIN {content_type_proyectos_operativos} AS ctpo ON ctpo.nid = n.nid AND ctpo.vid = n.vid WHERE w.sid <> %d";
2756//    $sql .= "SELECT ac.nid, ac.year, ac.ente, w.sid, n.created, n.title as nombre,  u.name, n.uid, e.title AS enten FROM {proyectos_operativos} AS ac INNER JOIN {node} AS n ON n.nid = ac.nid INNER JOIN {users} AS u ON u.uid = n.uid INNER JOIN {node} as e ON e.nid = ac.ente INNER JOIN {workflow_node} AS w ON w.nid = ac.nid WHERE w.sid <> %d";
2757    $proyectos_operativos_search_ac_ente = isset($_SESSION['proyectos_operativos']) && isset($_SESSION['proyectos_operativos']['ente']) ? $_SESSION['proyectos_operativos']['ente'] : 0;
2758    if ($proyectos_operativos_search_ac_ente) {
2759      $inputs[] = $proyectos_operativos_search_ac_ente;
2760      $sql .= ' AND ac.ente = %d';
2761    }
2762  }
2763  $proyectos_operativos_search_ac_anho_creacion = isset($_SESSION['proyectos_operativos']) && isset($_SESSION['proyectos_operativos']['anho']) ? $_SESSION['proyectos_operativos']['anho'] : 0;
2764  if ($proyectos_operativos_search_ac_anho_creacion) {
2765    $sql .= ' AND ac.year = %d';
2766    $inputs[] = $proyectos_operativos_search_ac_anho_creacion;
2767  }
2768  //ambito
2769  $proyectos_operativos_search_ac_ambito = isset($_SESSION['proyectos_operativos']) && isset($_SESSION['proyectos_operativos']['ambito']) ? $_SESSION['proyectos_operativos']['ambito'] : 0;
2770  if ($proyectos_operativos_search_ac_ambito) {
2771    $sql .= ' AND ent.ambito = %d';
2772    $inputs[] = $proyectos_operativos_search_ac_ambito;
2773    if ($supervisor && $nivel1) {
2774      $sql .= ' AND ent.ambito = %d';
2775      $inputs[] = $mi_ambito;
2776    }
2777  }
2778  //sectores
2779  $proyectos_operativos_search_ac_sectores = isset($_SESSION['proyectos_operativos']) && isset($_SESSION['proyectos_operativos']['sectores']) ? $_SESSION['proyectos_operativos']['sectores'] : 0;
2780  if ($proyectos_operativos_search_ac_sectores) {
2781    $sql .= ' AND ctpo.field_proyecto_sector_value = %d';
2782    $inputs[] = $proyectos_operativos_search_ac_sectores;
2783  }
2784  //pndes
2785  $proyectos_operativos_search_ac_pndes = isset($_SESSION['proyectos_operativos']) && isset($_SESSION['proyectos_operativos']['pndes']) ? $_SESSION['proyectos_operativos']['pndes'] : 0;
2786  if ($proyectos_operativos_search_ac_pndes) {
2787    $sql .= ' AND ctpo.field_proyecto_pndes_value = %d';
2788    $inputs[] = $proyectos_operativos_search_ac_pndes;
2789  }
2790  //ente adscrito
2791  $proyectos_operativos_search_ac_ente_adscrito = isset($_SESSION['proyectos_operativos']) && isset($_SESSION['proyectos_operativos']['ente_adscrito']) ? $_SESSION['proyectos_operativos']['ente_adscrito'] : 0;
2792  if ($proyectos_operativos_search_ac_ente_adscrito) {
2793    $sql .= ' AND ent.ente_adscrito = %d';
2794    $inputs[] = $proyectos_operativos_search_ac_ente_adscrito;
2795    if ($enlace_f && $nivel3) {
2796      $sql .= ' AND ac.ente = %d';
2797      $inputs[] = $user->ente_adscrito;
2798    }
2799  }
2800  //sub-ente adscrito
2801  $proyectos_operativos_search_ac_sub_ente = isset($_SESSION['proyectos_operativos']) && isset($_SESSION['proyectos_operativos']['sub_ente']) ? $_SESSION['proyectos_operativos']['sub_ente'] : 0;
2802  if ($proyectos_operativos_search_ac_sub_ente) {
2803    $sql .= ' AND ac.ente = %d';
2804    $inputs[] = $proyectos_operativos_search_ac_sub_ente;
2805  }
2806
2807  $sql .= ' ORDER BY ac.year DESC, ac.ente';
2808  $header = array();
2809  $cab = 6;
2810  if (user_access('admin planificador')) {
2811    $header[] = array('data' => t('Ente.'));
2812    $cab++;
2813  }
2814  $header[] = array('data' => t('Proyecto'));
2815  $header[] = array('data' => t('Año'));
2816  $header[] = array('data' => t('Estado'));
2817  $header[] = array('data' => t('Fecha de creación'));
2818  $header[] = array('data' => t('Autor'));
2819  $header[] = array('data' => t('Acción'));
2820  $result = db_query($sql, $inputs);
2821  $rows = array();
2822  while($ac = db_fetch_object($result)) {
2823    $row = array();
2824    if (user_access('admin planificador')) {
2825      $row[] = array('data' => l($ac->enten, 'node/' . $ac->ente),);
2826    }
2827    $nombre_proyecto = $ac->field_proyecto_titulo_value ? $ac->field_proyecto_titulo_value : $ac->nombre;
2828    $row[] = array('data' => $nombre_proyecto,);
2829//    $row[] = array('data' => $ac->nombre,);
2830    $row[] = array('data' => $ac->year,);
2831    $estad0 = $ac->sid == $first_state ? t('Ingresado') : $states['states'][$ac->sid];
2832    $row[] = array('data' => $estad0,);
2833    $row[] = array('data' => format_date($ac->created),);
2834    $row[] = array('data' => l($ac->name, 'user/' . $ac->uid),);
2835    $links = array();
2836    drupal_alter('proyecto_obtiene_links', $links, $ac, $fecha);
2837    $row[] = array('data' => theme('item_list', $links),);
2838    $rows[] = $row;
2839  }
2840  if (!count($rows)) {
2841    $row[] = array('data' => t('No existen Proyectos Operativos'), 'colspan' => $cab);
2842    $rows[] = $row;
2843  }
2844  $output .= theme('table', $header, $rows);
2845  if ($fecha) {
2846    $output .= '<p>' . l(t('Agregar proyectos operativos'), 'agregarproyectosop') . '</p>';
2847  }
2848  $form['#submit'][] = 'proyectos_operativos_mcti_search_ac_form_submit';
2849  return $output;
2850}
2851
2852/**
2853 * Implementation of proyectos_operativos_search_ac_form().
2854 * Formulario de busqueda de proyecto.
2855 */
2856function proyectos_operativos_mcti_search_ac_form($form_state) {
2857  $form = array();
2858  global $user;
2859  foreach ($user->roles as $id => $name) {
2860    if ($name == 'Supervisor') {
2861      $supervisor = $id;
2862    }
2863    if ($name == 'Enlace Revisor') {
2864      $enlace_r = $id;
2865    }
2866    if ($name == 'Enlace Formulador') {
2867      $enlace_f = $id;
2868    }
2869    if ($name == 'Control') {
2870      $control = $id;
2871    }
2872    if ($name == 'Administrador') {
2873      $admin = $id;
2874    }
2875  }
2876  $nivel1 = db_result(db_query("SELECT ente_planificador FROM {ente_planificador} where tipo = %d", 1));
2877  $nivel2 = db_result(db_query("SELECT ente_planificador FROM {ente_planificador} where tipo = %d", 2));
2878  $nivel3 = db_result(db_query("SELECT ente_planificador FROM {ente_planificador} where tipo = %d", 3));
2879  $nivel4 = db_result(db_query("SELECT ente_planificador FROM {ente_planificador} where tipo = %d", 4));
2880
2881  if (user_access('admin planificador') || $control || ($supervisor && $nivel1) || ($supervisor && $nivel2)) {
2882    $entes = array();
2883    $result = db_query('SELECT e.nid, n.title FROM {ente_planificador} AS e INNER JOIN {node} AS n ON n.nid = e.nid WHERE n.status = 1');
2884    $entes[0] = t('Todos');
2885    while ($ente = db_fetch_object($result)) {
2886      $entes[$ente->nid] = $ente->title;
2887    }
2888    $proyectos_operativos_search_ac_ente = isset($_SESSION['proyectos_operativos']) && isset($_SESSION['proyectos_operativos']['ente']) ? $_SESSION['proyectos_operativos']['ente'] : 0;
2889    $form['proyectos_operativos_search_ac_ente'] = array(
2890      '#title' => t('Ente Planificador'),
2891      '#type' => 'select',
2892      '#default_value' => $proyectos_operativos_search_ac_ente,
2893      '#options' => $entes,
2894    );
2895  } 
2896  if ($control || ($supervisor && $nivel2) || ($supervisor && $nivel1) || ($supervisor && $nivel3) || ($supervisor && $nivel4) || ($enlace_f && $nivel1) || ($enlace_f && $nivel2) || ($enlace_f && $nivel3) || ($enlace_f && $nivel4) || ($enlace_r && $nivel1) || ($enlace_r && $nivel2) || ($enlace_r && $nivel3)) {
2897    $years = array();
2898    $years[0] = t('Todos');
2899    $current_year = date("Y");
2900    for ($i = $current_year - 10; $i <= $current_year; $i++) {
2901      $years[$i] = $i;
2902    }
2903    $proyectos_operativos_search_ac_anho_creacion = isset($_SESSION['proyectos_operativos']) && isset($_SESSION['proyectos_operativos']['anho']) ? $_SESSION['proyectos_operativos']['anho'] : 0;
2904    $form['proyectos_operativos_search_ac_anho_creacion'] = array(
2905      '#title' => t('Proyectos Operativos para el año'),
2906      '#type' => 'select',
2907      '#default_value' => $proyectos_operativos_search_ac_anho_creacion,
2908      '#options' => $years,
2909    );
2910  }
2911  if ($control) {
2912    $vocabulary = variable_get('ente_planificador_sector_Ambitos', 0);
2913    $terms = taxonomy_get_tree($vocabulary);
2914    $ambitos[0] = t('Selecione');
2915    foreach ($terms as $term) {
2916      if ($term->depth == 0) { //si el termino es padre
2917      $ambitos[$term->tid] = $term->name;
2918      }
2919    }
2920    $proyectos_operativos_search_ac_ambito = isset($_SESSION['proyectos_operativos']) && isset($_SESSION['proyectos_operativos']['ambito']) ? $_SESSION['proyectos_operativos']['ambito'] : 0;
2921    $form['proyectos_operativos_search_ac_ambito'] = array(
2922      '#title' => t('Ambito del ente planificador'),
2923      '#type' => 'select',
2924      '#default_value' => $proyectos_operativos_search_ac_ambito,
2925      '#options' => $ambitos,
2926    );
2927  }
2928  if ($control || ($supervisor && $nivel2)) {
2929    $vocabulary = variable_get('proyectos_operativos_extra_sector', 0);
2930    $proyectos_operativos_search_ac_sectores = isset($_SESSION['proyectos_operativos']) && isset($_SESSION['proyectos_operativos']['sectores']) ? $_SESSION['proyectos_operativos']['sectores'] : 0;
2931    $form['proyectos_operativos_search_ac_sectores'] = array(
2932      '#title' => t('Sector social del Proyecto'),
2933                        '#type' => 'hierarchical_select',
2934        '#config' => array(
2935        'module' => 'hs_content_taxonomy',
2936        'params' => array(
2937                'vid' => variable_get('proyectos_operativos_extra_sector', 0),
2938                'tid' => 0,
2939                'depth' => 2,
2940        ),
2941        'level_labels' => array(
2942                'status' => 1,
2943                'labels' => array(
2944                1 => t('Sub-Sector'),
2945                ),
2946        ),
2947        ),
2948                        '#default_value' => $proyectos_operativos_search_ac_sectores,
2949    );
2950  }
2951  if ($control || ($supervisor && $nivel2) || ($supervisor && $nivel3) || ($supervisor && $nivel4) || ($enlace_f && $nivel1) || ($enlace_f && $nivel2) || ($enlace_f && $nivel3) || ($enlace_f && $nivel4) || ($enlace_r && $nivel1) || ($enlace_r && $nivel2) || ($enlace_r && $nivel3)) {
2952    $vocabulary = variable_get('proyectos_operativos_PNDES', 0);
2953    $terms = taxonomy_get_tree($vocabulary);
2954    $pndes[0] = t('Selecione');
2955    foreach ($terms as $term) {
2956      if ($term->depth == 0) { //si el termino es padre
2957        $pndes[$term->tid] = $term->name;
2958      }
2959    }
2960    $proyectos_operativos_search_ac_pndes = isset($_SESSION['proyectos_operativos']) && isset($_SESSION['proyectos_operativos']['pndes']) ? $_SESSION['proyectos_operativos']['pndes'] : 0;
2961    $form['proyectos_operativos_search_ac_pndes'] = array(
2962      '#title' => t('PNDES'),
2963      '#type' => 'select',
2964      '#default_value' => $proyectos_operativos_search_ac_pndes,
2965      '#options' => $pndes,
2966    );
2967  }
2968  if ($control || ($supervisor && $nivel2) || ($supervisor && $nivel1) || ($enlace_r && $nivel2)) {
2969    $nivel = 3; //Ente adscrito
2970    $result = db_query('SELECT e.nid, n.title FROM {ente_planificador} AS e INNER JOIN {node} AS n ON n.nid = e.nid WHERE n.status = 1 AND e.tipo=%d AND e.ente_adscrito != %d', $nivel, 0);
2971    $entes_ad[0] = t('Seleccione');
2972    while ($ente = db_fetch_object($result)) {
2973      $entes_ad[$ente->nid] = $ente->title;
2974    }
2975    $proyectos_operativos_search_ac_ente_adscrito = isset($_SESSION['proyectos_operativos']) && isset($_SESSION['proyectos_operativos']['ente_adscrito']) ? $_SESSION['proyectos_operativos']['ente_adscrito'] : 0;
2976    $form['proyectos_operativos_search_ac_ente_adscrito'] = array(
2977      '#title' => t('Ente adscrito a un organismo publico.'),
2978      '#type' => 'select',
2979      '#default_value' => $proyectos_operativos_search_ac_ente_adscrito,
2980      '#options' => $entes_ad,
2981    );
2982  }
2983  if ($control || ($supervisor && $nivel1) || ($supervisor && $nivel2) || ($supervisor && $nivel3) || ($enlace_r && $nivel2) || ($enlace_r && $nivel3)) {
2984    $nivel = 4; //sub-ente planificador adscrito
2985    $result = db_query('SELECT n.nid, n.title FROM {ente_planificador} AS e INNER JOIN {node} AS n ON n.nid = e.nid WHERE n.status = 1 AND e.tipo = %d AND e.sub_ente != %d', $nivel, 0);
2986    $sub_entes[0] = t('Seleccione');
2987    while ($ente = db_fetch_object($result)) {
2988      $sub_entes[$ente->nid] = $ente->title;
2989    }
2990    $proyectos_operativos_search_ac_sub_ente = isset($_SESSION['proyectos_operativos']) && isset($_SESSION['proyectos_operativos']['sub_ente']) ? $_SESSION['proyectos_operativos']['sub_ente'] : 0;
2991    $form['proyectos_operativos_search_ac_sub_ente'] = array(
2992      '#title' => t('Ente adscrito a otro ente adscrito.'),
2993      '#type' => 'select',
2994      '#default_value' => $proyectos_operativos_search_ac_sub_ente,
2995      '#options' => $sub_entes,
2996    );
2997  }
2998  $form['buttons'] = array(
2999    '#prefix' => '<div class="container-inline">',
3000    '#suffix' => '</div>',
3001  );
3002  $form['buttons']['submit'] = array(
3003    '#type' => 'submit',
3004    '#value' => t('Buscar'),
3005  );
3006  $form['#submit'][] = 'proyectos_operativos_mcti_search_ac_form_submit';
3007  return $form;
3008}
3009
3010/**
3011 * Implementation of proyectos_operativos_mcti_search_ac_form_submit().
3012 * cambia el filtro de busqueda de proyectos.
3013 */
3014function proyectos_operativos_mcti_search_ac_form_submit($form, &$form_state) {
3015  $_SESSION['proyectos_operativos'] = array();
3016  if ($form_state['values']['proyectos_operativos_search_ac_ambito']) {
3017    $_SESSION['proyectos_operativos']['ambito'] = $form_state['values']['proyectos_operativos_search_ac_ambito'];
3018  }
3019  if ($form_state['values']['proyectos_operativos_search_ac_sectores']) {
3020    $_SESSION['proyectos_operativos']['sectores'] = $form_state['values']['proyectos_operativos_search_ac_sectores'];
3021  }
3022  if ($form_state['values']['proyectos_operativos_search_ac_pndes']) {
3023    $_SESSION['proyectos_operativos']['pndes'] = $form_state['values']['proyectos_operativos_search_ac_pndes'];
3024  }
3025  if ($form_state['values']['proyectos_operativos_search_ac_ente_adscrito']) {
3026    $_SESSION['proyectos_operativos']['ente_adscrito'] = $form_state['values']['proyectos_operativos_search_ac_ente_adscrito'];
3027  }
3028  if ($form_state['values']['proyectos_operativos_search_ac_sub_ente']) {
3029    $_SESSION['proyectos_operativos']['sub_ente'] = $form_state['values']['proyectos_operativos_search_ac_sub_ente'];
3030  }
3031}
3032
3033/**
3034 * Implementation of hook_menu_alter
3035 */
3036function proyectos_operativos_mcti_menu_alter(&$items) {
3037  $items['proyectos_operativos']['page callback'] = 'proyectos_operativos_mcti_search_ac_display';
3038  $items['proyectosopedit/%proyectosop/ficha']['page callback'] = '_proyectos_operativos_mcti_proyecto_ficha_proyecto';
3039  $items['proyectosop/%proyectosop/ficha']['page callback'] = '_proyectos_operativos_mcti_proyecto_ficha_proyecto';
3040}
3041
3042/**
3043 * Implementation of _proyectos_operativos_proyecto_financieros().
3044 * Ver datos financieros (proyectos operativos).
3045 */
3046function _proyectos_operativos_mcti_proyecto_ficha_proyecto($proyecto = 0) {
3047  drupal_set_title(t('Ficha del Proyecto'));
3048  return theme('proyectos_operativos_mcti_ficha_proyecto', $proyecto);
3049}
Nota: Vea TracBrowser para ayuda de uso del navegador del repositorio.