source: sipp/0.3-stable-modules/proyectos_operativos/accion_especifica.module @ 1576823

0.3-stable
Last change on this file since 1576823 was 1576823, checked in by José Gregorio Puentes <jpuentes@…>, 9 años ago

se agrego la validacion de la cantidad de ponderaciones como minimo permitidas

  • Propiedad mode establecida a 100755
File size: 47.5 KB
Línea 
1<?php
2
3  /**
4  * Sistema Integral de Planificación y Presupuesto (SIPP)
5  * @file accion_especifica.module
6  * Drupal part Module to Sistema Integral de Planificación y Presupuesto (SIPP)
7  * Copyright 2013 Sistema Automatizado para la Planificación Estratégico-Situacional en la Administración Pública Venezolana (CENDITEL)
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
22  *
23  * @author Cenditel Merida - Msc. Juan Vizcarrondo
24  * @date 2013-02-02 // (a&#241;o-mes-dia)
25  * @version 0.1 // (0.1)
26  *
27  */
28
29/*
30 * Implementation of hook_node_info()
31 */
32function accion_especifica_node_info() {
33  return array(
34    'accion_especifica' => array(
35      'name' => t('Acciones Especificas'),
36      'description' => '',
37      'has_title' => TRUE,
38      'title_label' => 'Nombre de la acción especifica',
39      'has_body' => FALSE,
40      'body_label' => 'Cuerpo',
41      'module' => 'accion_especifica',
42    ),
43  );
44}
45
46/*
47 * hook_form_alter()
48 */
49function accion_especifica_form_alter(&$form, $form_state, $form_id) {
50  if ($form_id == 'proyectos_operativos_admin_settings') {
51    $node_type = content_types('accion_especifica');
52    $fields = $node_type['fields'];
53    $campos = array();
54    foreach($fields as $id => $field) {
55      if ($field['module'] == 'number') {
56        $campos[$id] = $field['widget']['label'];
57      }
58    }
59    $form['accion_especifica'] = array(
60      '#type' => 'fieldset',
61      '#title' => t('Accion Específica'),
62      '#collapsible' => TRUE,
63      '#collapsed' => FALSE,
64      '#weight' => 0,
65    );
66    $form['accion_especifica']['accion_especifica_allow_ponderation'] = array(
67      '#title' => t('Permitir Acciones Especificas con igual ponderación'),
68      '#type' => 'checkbox',
69      '#default_value' => variable_get('accion_especifica_allow_ponderation', 0),
70    );
71    $form['accion_especifica']['accion_especifica_100_ponderation'] = array(
72      '#title' => t('No permitir Acciones Especificas con ponderación mayor o igual a 100'),
73      '#type' => 'checkbox',
74      '#default_value' => variable_get('accion_especifica_100_ponderation', 0),
75    );
76    $accion_especifica_number_fields = variable_get('accion_especifica_number_fields', 4);
77    $numbers = array();
78    for($i = 1; $i < 21; $i++) {
79      $numbers[$i] = $i;
80
81    }
82    $form['accion_especifica']['financiamiento'] = array(
83      '#type' => 'fieldset',
84      '#title' => t('Financiamiento'),
85      '#collapsible' => TRUE,
86      '#collapsed' => FALSE,
87    );
88    $form['accion_especifica']['financiamiento']['accion_especifica_number_fields'] = array(
89      '#title' => t('Cantidad de Campos'),
90      '#type' => 'select',
91      '#default_value' => $accion_especifica_number_fields,
92      '#options' => $numbers,
93    );
94
95    if ($accion_especifica_number_fields) {
96      for($i = 0; $i < $accion_especifica_number_fields; $i++) {
97       $form['accion_especifica']['financiamiento']['financiamiento_' . $i] = array(
98          '#type' => 'fieldset',
99          '#title' => t('field %number', array('%number' => $i + 1)),
100          '#collapsible' => TRUE,
101          '#collapsed' => FALSE,
102        );
103        $form['accion_especifica']['financiamiento']['financiamiento_' . $i]['accion_especifica_financiamiento_label_' . $i] = array(
104          '#type' => 'textfield',
105          '#title' => t('Titulo del financiamiento'),
106          //'#required' => TRUE,
107          '#weight' => -9,
108          '#default_value' => variable_get('accion_especifica_financiamiento_label_' . $i, ''),
109        );
110         $form['accion_especifica']['financiamiento']['financiamiento_' . $i]['accion_especifica_financiamiento_options_' . $i] = array(
111            '#type' => 'checkboxes',
112            '#options' => $campos,
113            '#default_value' => variable_get('accion_especifica_financiamiento_options_' . $i, array()),
114            '#title' => t('Campos a recolectar'),
115            '#multiple' => TRUE,
116          );
117    //print_r(variable_get('accion_especifica_financiamiento_options_' . $i, array()));
118
119      }
120    }
121//print "</pre>";
122/*
123    print "<pre>";
124    print_r($campos);
125    print "</pre>";
126*/
127  }
128
129
130
131}
132
133
134/*
135 * Implementation of hook_form()
136 */
137function accion_especifica_form(&$node, $form_state) {
138  return node_content_form($node, $form_state);
139}
140
141/*
142 * Implementation of hook_access()
143 */
144function accion_especifica_access($op, $node, $account) {
145  if ($op == 'view') {
146    return user_access('admin planificador');
147  }
148  if ($op == 'create') {
149    return user_access('admin planificador');
150  }
151  if ($op == 'update') {
152    return user_access('admin planificador');
153  }
154  if ($op == 'delete') {
155    return user_access('admin planificador');
156  }
157}
158
159/**
160 * Implementation of hook_theme().
161 */
162function accion_especifica_theme() {
163  return array(
164    'proyectos_operativos_accion_especifica_crear_form' => array(
165      'arguments' => array('form' => NULL),
166    ),
167  );
168}
169
170/**
171 * Implementation of proyectos_operativos_accion_especifica_crear_form().
172 * Crear formulario de accion especifica
173 */
174function proyectos_operativos_accion_especifica_crear_form(&$form_state, $proyecto = 0, $ae = 0) {
175  if (!$ae) {
176    drupal_set_title('Nueva Acción Especifica');
177    $ae_leido = new stdClass();
178    $ae_leido->type = 'accion_especifica';
179    $nid = 0;
180  }
181  else {
182    $ae_leido = $ae;
183    $ae_leido->field_accion_titulo[0]['value'] = trim($ae_leido->field_accion_titulo[0]['value']) == '' ? $ae_leido->title : $ae_leido->field_accion_titulo[0]['value'];
184    $nid = $ae->nid;
185    drupal_set_title(t('Acción Especifica: @titulo', array('@titulo' => $ae_leido->field_accion_titulo[0]['value'])));
186  }
187  $proyectos_operativos_path = drupal_get_path('module', 'proyectos_operativos');
188  drupal_add_js($proyectos_operativos_path . '/js/proyectos_operativos_extra.js');
189  drupal_add_js($proyectos_operativos_path . '/js/proyectos_operativos.js');
190  drupal_add_js($proyectos_operativos_path . '/js/accion_especifica.js');
191  $format_number = array(
192    'decimals' => variable_get('proyectos_operativos_number_decimals', 0),
193    'dec_point' => variable_get('proyectos_operativos_number_dec_point', ','),
194    'thousands_sep' => variable_get('proyectos_operativos_number_thousands_sep', '.'),
195  );
196  $form = array();
197  $form['#format_number'] = array('format_number' => $format_number);
198  drupal_add_js($form['#format_number'], 'setting');
199  $form['#node'] = $ae_leido;
200  $form['#proyecto'] = $proyecto;
201  $fields_form = array();
202  $ejecucion = 0;
203  $acciones_especificas = array();
204  $montos = 0;
205  $porcentajes = array();
206  foreach($proyecto->field_proyecto_accion_esp as $accion) {
207    if ($accion['nid'] && $nid != $accion['nid']) {
208      $accion_load = node_load($accion['nid']);
209      if ($accion_load && $accion_load->type == 'accion_especifica') {
210        if ($accion_load->field_accion_esp_programacion[0]['tid']) {
211          foreach($accion_load->field_accion_esp_programacion as $programacion) {
212            foreach($programacion as $id_value => $mesp){
213              if ($id_value != 'tid') {
214                $montos +=$mesp;
215              }
216            }
217          }
218        }
219        $acciones_especificas[$accion_load->nid] = $accion_load;
220        $porcentajes[$accion_load->field_accion_esp_ponderacion[0]['value']] = 1;
221        $ejecucion += $accion_load->field_accion_esp_ponderacion[0]['value'];
222      }
223    }
224    elseif($nid == $accion['nid']) {
225      $acciones_especificas[$ae->nid] = $ae;
226    }
227  }
228  $monto_restante = $form['#proyecto']->field_proyecto_monto_anual[0]['value'] - $montos;
229  $et = 100 - $ejecucion;
230  $form['#mensaje_mostrar'] =  t('Quedan @asignar % de ponderación a asignar y @montos BS por asignar en las Acciones Específicas.', array('@asignar' => $et, '@montos' => number_format($monto_restante, $form['#format_number']['format_number']['decimals'], $form['#format_number']['format_number']['dec_point'], $form['#format_number']['format_number']['thousands_sep'])));
231  $form['#monto_restante'] =  $monto_restante;
232  $form['#ejecucion'] =  $ejecucion;
233  $form['#porcentajes'] =  $porcentajes;
234  $form['#montos'] =  $montos;
235  $form['#acciones_especificas'] =  $acciones_especificas;
236  $node_type = content_types('accion_especifica');
237  $fields = $node_type['fields'];
238  $field_form = array();
239  $arreglo = array(
240    'field_accion_titulo' => 'field_accion_titulo',
241    'field_accion_esp_fechai' => 'field_accion_esp_fechai',
242    'field_accion_esp_fechaf' => 'field_accion_esp_fechaf',
243    'field_accion_esp_ejecutor' => 'field_accion_esp_ejecutor',
244    'field_accion_esp_bien' => 'field_accion_esp_bien',
245  );
246  if (is_array($fields) && count($fields)) {
247    foreach($fields as $field_id => $field) {
248      if (array_key_exists($field_id, $arreglo)) {
249        $field_form[] = $field_id;
250        $fields_form[] = $field_id;
251      }
252      elseif (variable_get('proyectos_operativos_ac_d_' . $field_id, FALSE)) {
253        $field_form[] = $field_id;
254        $fields_form[] = $field_id;
255      }
256    }
257  }
258  /*caMBIAR*/
259/*
260  $form['title'] = array(
261    '#type' => 'textfield',
262    '#title' => t('Nombre de la Acción'),
263    '#required' => TRUE,
264    '#default_value' => $form['#node']->title,
265    '#maxlength' => 255,
266    '#weight' => -5,
267  );
268*/
269  if (is_array($field_form) && count($field_form)) {
270    module_load_include('inc', 'content', 'includes/content.node_form');
271    foreach ($field_form as $field_id) {
272      $field = content_fields($field_id, 'accion_especifica');
273      $form['#field_info'][$field_id] = $field;
274      $form += (array) content_field_form($form, $form_state, $field);
275    }
276  }
277  $field_form = array();
278  $arreglo = array(
279    'field_accion_esp_unidadm' => 'field_accion_esp_unidadm',
280    'field_accion_esp_ponderacion' => 'field_accion_esp_ponderacion',
281    'field_accion_esp_metaf' => 'field_accion_esp_metaf',
282  );
283  if (is_array($fields) && count($fields)) {
284    foreach($fields as $field_id => $field) {
285      if (array_key_exists($field_id, $arreglo)) {
286        $field_form[] = $field_id;
287        $fields_form[] = $field_id;
288      }
289      elseif (variable_get('proyectos_operativos_ac_di_' . $field_id, FALSE)) {
290        $field_form[] = $field_id;
291        $fields_form[] = $field_id;
292      }
293    }
294  }
295  if (is_array($field_form) && count($field_form)) {
296    module_load_include('inc', 'content', 'includes/content.node_form');
297    foreach ($field_form as $field_id) {
298      $field = content_fields($field_id, 'accion_especifica');
299      $form['#field_info'][$field_id] = $field;
300      $form += (array) content_field_form($form, $form_state, $field);
301    }
302  }
303  $field_form = array();
304  $arreglo = array(
305    'field_accion_esp_programacion' => 'field_accion_esp_programacion',
306  );
307  if (is_array($fields) && count($fields)) {
308    foreach($fields as $field_id => $field) {
309      if (array_key_exists($field_id, $arreglo)) {
310        $field_form[] = $field_id;
311        $fields_form[] = $field_id;
312      }
313      elseif (variable_get('proyectos_operativos_ac_p_' . $field_id, FALSE)) {
314        $field_form[] = $field_id;
315        $fields_form[] = $field_id;
316      }
317    }
318  }
319  if (is_array($field_form) && count($field_form)) {
320    module_load_include('inc', 'content', 'includes/content.node_form');
321    foreach ($field_form as $field_id) {
322      $field = content_fields($field_id, 'accion_especifica');
323      $form['#field_info'][$field_id] = $field;
324      $form += (array) content_field_form($form, $form_state, $field);
325    }
326  }
327  //financiamiento
328  $arreglo_financiamiento = array();
329  $accion_especifica_number_fields = variable_get('accion_especifica_number_fields', 4);
330  if ($accion_especifica_number_fields > 0) {
331    for($i = 0; $i < $accion_especifica_number_fields; $i++) {
332      $arreglo_financiamiento['financiamiento_' . $i] = variable_get('accion_especifica_financiamiento_label_' . $i, '') ? variable_get('accion_especifica_financiamiento_label_' . $i, '') : '';
333      $arreglo_financiamiento_fields['financiamiento_' . $i] = variable_get('accion_especifica_financiamiento_options_' . $i, array());
334    }
335  }
336/*
337  $arreglo_financiamiento = array(
338    'ordinarios' => t('Recursos Ordinarios'),
339    'propios' => t('Recursos Propios'),
340    'transferencias' => t('Transferencias'),
341    'otros' => t('Otros'),
342  );
343  $arreglo_financiamiento_fields = array();
344  $arreglo_financiamiento_fields['ordinarios'] = array(
345    'field_accion_esp_transferencias' => 'field_accion_esp_transferencias',
346    'field_accion_esp_creditosa' => 'field_accion_esp_creditosa',
347    'field_accion_esp_mcti' => 'field_accion_esp_mcti',
348  );
349  $arreglo_financiamiento_fields['propios'] = array(
350    'field_accion_esp_venta_act' => 'field_accion_esp_venta_act',
351    'field_accion_esp_activos' => 'field_accion_esp_activos',
352    'field_accion_esp_flujocaja' => 'field_accion_esp_flujocaja',
353    'field_accion_esp_ventapro' => 'field_accion_esp_ventapro',
354  );
355  $arreglo_financiamiento_fields['transferencias'] = array(
356    'field_accion_esp_donaciones' => 'field_accion_esp_donaciones',
357  );
358  $arreglo_financiamiento_fields['otros'] = array(
359    'field_accion_esp_gobernacion' => 'field_accion_esp_gobernacion',
360    'field_accion_esp_misionc' => 'field_accion_esp_misionc',
361    'field_accion_esp_bid_fona' => 'field_accion_esp_bid_fona',
362    'field_accion_esp_fonacit' => 'field_accion_esp_fonacit',
363    'field_accion_esp_fonden' => 'field_accion_esp_fonden',
364    'field_accion_esp_locti' => 'field_accion_esp_locti',
365    'field_accion_esp_fondoidi' => 'field_accion_esp_fondoidi',
366    'field_accion_esp_capitalrie' => 'field_accion_esp_capitalrie',
367    'field_accion_esp_infocentro' => 'field_accion_esp_infocentro',
368    'field_accion_esp_fidetel' => 'field_accion_esp_fidetel',
369  );
370*/
371  $total_financiamiento = 0;
372  $fields_financiamiento = array();
373
374  foreach($arreglo_financiamiento as $id_items => $titulo) {
375    if (is_array($arreglo_financiamiento_fields[$id_items]) && count($arreglo_financiamiento_fields[$id_items])) {
376      $form[$id_items] = array(
377        '#type' => 'fieldset',
378        '#title' => $titulo,
379      );
380      $field_form = array();
381/*
382  $arreglo = array(
383    'field_accion_esp_transferencias' => 'field_accion_esp_transferencias',
384    'field_accion_esp_creditosa' => 'field_accion_esp_creditosa',
385    'field_accion_esp_mcti' => 'field_accion_esp_mcti',
386  );
387*/
388      if (is_array($fields) && count($fields)) {
389        foreach($fields as $field_id => $field) {
390          if (array_key_exists($field_id, $arreglo_financiamiento_fields[$id_items]) && $arreglo_financiamiento_fields[$id_items][$field_id]) {
391            $field_form[] = $field_id;
392            $fields_form[] = $field_id;
393            $fields_financiamiento[] = $field_id;
394          }
395        }
396      }
397      $total_local = 0;
398      if (is_array($field_form) && count($field_form)) {
399        module_load_include('inc', 'content', 'includes/content.node_form');
400        foreach ($field_form as $field_id) {
401          if (isset($form['#node']->{$field_id}[0]['value'])) {
402            $total_local += $form['#node']->{$field_id}[0]['value'];
403          }
404          $field = content_fields($field_id, 'accion_especifica');
405          $form['#field_info'][$field_id] = $field;
406          $form[$id_items] += (array) content_field_form($form, $form_state, $field);
407        }
408      }
409      $form['#campo_' . $id_items] = $field_form;
410      $form['total_' . $id_items] = array(
411        '#type' => 'textfield',
412        '#title' => t('SUBTOTAL'),
413        '#default_value' => $total_local,
414        '#size' => 25,
415        '#attributes' => array('class' => 'totales-financieros subtotales'),
416      );
417      $total_financiamiento += $total_local;
418    }
419  }
420/*
421
422
423
424
425
426
427
428
429
430
431  $form['ordinarios'] = array(
432    '#type' => 'fieldset',
433    '#title' => t('Recursos Ordinarios'),
434  );
435  $fields_financiamiento = array();
436  $field_form = array();
437  $arreglo = array(
438    'field_accion_esp_transferencias' => 'field_accion_esp_transferencias',
439    'field_accion_esp_creditosa' => 'field_accion_esp_creditosa',
440    'field_accion_esp_mcti' => 'field_accion_esp_mcti',
441  );
442  if (is_array($fields) && count($fields)) {
443    foreach($fields as $field_id => $field) {
444      if (array_key_exists($field_id, $arreglo)) {
445        $field_form[] = $field_id;
446        $fields_form[] = $field_id;
447        $fields_financiamiento[] = $field_id;
448      }
449      elseif (variable_get('proyectos_operativos_ac_fo_' . $field_id, FALSE)) {
450        $field_form[] = $field_id;
451        $fields_form[] = $field_id;
452        $fields_financiamiento[] = $field_id;
453      }
454    }
455  }
456  $total_ordinarios = 0;
457  if (is_array($field_form) && count($field_form)) {
458    module_load_include('inc', 'content', 'includes/content.node_form');
459    foreach ($field_form as $field_id) {
460      if (isset($form['#node']->{$field_id}[0]['value'])) {
461        $total_ordinarios += $form['#node']->{$field_id}[0]['value'];
462      }
463      $field = content_fields($field_id, 'accion_especifica');
464      $form['#field_info'][$field_id] = $field;
465      $form['ordinarios'] += (array) content_field_form($form, $form_state, $field);
466    }
467  }
468  $form['#campo_ordinarios'] = $field_form;
469  $form['total_ordinarios'] = array(
470    '#type' => 'textfield',
471    '#title' => t('SUBTOTAL'),
472    '#default_value' => $total_ordinarios,
473    '#size' => 25,
474    '#attributes' => array('class' => 'totales-financieros subtotales'),
475  );
476
477
478
479
480
481  $form['propios'] = array(
482    '#type' => 'fieldset',
483    '#title' => t('Recursos Propios'),
484  );
485  $field_form = array();
486  $arreglo = array(
487    'field_accion_esp_venta_act' => 'field_accion_esp_venta_act',
488    'field_accion_esp_activos' => 'field_accion_esp_activos',
489    'field_accion_esp_flujocaja' => 'field_accion_esp_flujocaja',
490    'field_accion_esp_ventapro' => 'field_accion_esp_ventapro',
491  );
492  if (is_array($fields) && count($fields)) {
493    foreach($fields as $field_id => $field) {
494      if (array_key_exists($field_id, $arreglo)) {
495        $field_form[] = $field_id;
496        $fields_form[] = $field_id;
497        $fields_financiamiento[] = $field_id;
498      }
499      elseif (variable_get('proyectos_operativos_ac_fp_' . $field_id, FALSE)) {
500        $field_form[] = $field_id;
501        $fields_form[] = $field_id;
502        $fields_financiamiento[] = $field_id;
503      }
504    }
505  }
506  $total_propios = 0;
507  if (is_array($field_form) && count($field_form)) {
508    module_load_include('inc', 'content', 'includes/content.node_form');
509    foreach ($field_form as $field_id) {
510      if (isset($form['#node']->{$field_id}[0]['value'])) {
511        $total_propios += $form['#node']->{$field_id}[0]['value'];
512      }
513      $field = content_fields($field_id, 'accion_especifica');
514      $form['#field_info'][$field_id] = $field;
515      $form['propios'] += (array) content_field_form($form, $form_state, $field);
516    }
517  }
518  $form['#campo_propios'] = $field_form;
519  $form['total_propios'] = array(
520    '#type' => 'textfield',
521    '#title' => t('SUBTOTAL'),
522    '#default_value' => $total_propios,
523    '#size' => 25,
524    '#attributes' => array('class' => 'totales-financieros subtotales'),
525  );
526  $form['transferencias'] = array(
527    '#type' => 'fieldset',
528    '#title' => t('Transferencias'),
529  );
530  $field_form = array();
531  $arreglo = array(
532    'field_accion_esp_donaciones' => 'field_accion_esp_donaciones',
533  );
534  if (is_array($fields) && count($fields)) {
535    foreach($fields as $field_id => $field) {
536      if (array_key_exists($field_id, $arreglo)) {
537        $field_form[] = $field_id;
538        $fields_form[] = $field_id;
539        $fields_financiamiento[] = $field_id;
540      }
541      elseif (variable_get('proyectos_operativos_ac_fd_' . $field_id, FALSE)) {
542        $field_form[] = $field_id;
543        $fields_form[] = $field_id;
544        $fields_financiamiento[] = $field_id;
545      }
546    }
547  }
548  $total_transferencias = 0;
549  if (is_array($field_form) && count($field_form)) {
550    module_load_include('inc', 'content', 'includes/content.node_form');
551    foreach ($field_form as $field_id) {
552      if (isset($form['#node']->{$field_id}[0]['value'])) {
553        $total_transferencias += $form['#node']->{$field_id}[0]['value'];
554      }
555      $field = content_fields($field_id, 'accion_especifica');
556      $form['#field_info'][$field_id] = $field;
557      $form['transferencias'] += (array) content_field_form($form, $form_state, $field);
558    }
559  }
560  $form['#campo_transferencias'] = $field_form;
561  $form['total_transferencias'] = array(
562    '#type' => 'textfield',
563    '#title' => t('SUBTOTAL'),
564    '#default_value' => $total_transferencias,
565    '#size' => 25,
566    '#attributes' => array('class' => 'totales-financieros subtotales'),
567  );
568  $form['otros'] = array(
569    '#type' => 'fieldset',
570    '#title' => t('Otros'),
571  );
572  $field_form = array();
573  $arreglo = array(
574    'field_accion_esp_gobernacion' => 'field_accion_esp_gobernacion',
575    'field_accion_esp_misionc' => 'field_accion_esp_misionc',
576    'field_accion_esp_bid_fona' => 'field_accion_esp_bid_fona',
577    'field_accion_esp_fonacit' => 'field_accion_esp_fonacit',
578    'field_accion_esp_fonden' => 'field_accion_esp_fonden',
579    'field_accion_esp_locti' => 'field_accion_esp_locti',
580    'field_accion_esp_fondoidi' => 'field_accion_esp_fondoidi',
581    'field_accion_esp_capitalrie' => 'field_accion_esp_capitalrie',
582    'field_accion_esp_infocentro' => 'field_accion_esp_infocentro',
583    'field_accion_esp_fidetel' => 'field_accion_esp_fidetel',
584  );
585  if (is_array($fields) && count($fields)) {
586    foreach($fields as $field_id => $field) {
587      if (array_key_exists($field_id, $arreglo)) {
588        $field_form[] = $field_id;
589        $fields_form[] = $field_id;
590        $fields_financiamiento[] = $field_id;
591      }
592      elseif (variable_get('proyectos_operativos_ac_fo_' . $field_id, FALSE)) {
593        $field_form[] = $field_id;
594        $fields_form[] = $field_id;
595        $fields_financiamiento[] = $field_id;
596      }
597    }
598  }
599  $total_otros = 0;
600  $clase = 'total_otros';
601  if (is_array($field_form) && count($field_form)) {
602    module_load_include('inc', 'content', 'includes/content.node_form');
603    foreach ($field_form as $field_id) {
604      if (isset($form['#node']->{$field_id}[0]['value'])) {
605        $total_otros += $form['#node']->{$field_id}[0]['value'];
606      }
607      $field = content_fields($field_id, 'accion_especifica');
608      $form['#field_info'][$field_id] = $field;
609      $form['otros'] += (array) content_field_form($form, $form_state, $field);
610    }
611  }
612  $form['#campo_otros'] = $field_form;
613  $form['total_otros'] = array(
614    '#type' => 'textfield',
615    '#title' => t('SUBTOTAL'),
616    '#default_value' => $total_otros,
617    '#size' => 25,
618    '#attributes' => array('class' => 'totales-financieros subtotales'),
619  );
620*/
621  //$total_financiamiento = $total_otros + $total_transferencias + $total_propios + $total_ordinarios;
622  $form['total_financiamiento'] = array(
623    '#type' => 'textfield',
624    '#default_value' => $total_financiamiento,
625    '#size' => 25,
626    '#attributes' => array('class' => 'totales-financieros'),
627  );
628  $field_form = array();
629  $arreglo = array(
630    'field_accion_esp_localizacion' => 'field_accion_esp_localizacion',
631    'field_accion_esp_latitud' => 'field_accion_esp_latitud',
632    'field_accion_esp_longitud' => 'field_accion_esp_longitud',
633  );
634  if (is_array($fields) && count($fields)) {
635    foreach($fields as $field_id => $field) {
636      if (array_key_exists($field_id, $arreglo)) {
637        $field_form[] = $field_id;
638        $fields_form[] = $field_id;
639      }
640      elseif (variable_get('proyectos_operativos_ac_fp_' . $field_id, FALSE)) {
641        $field_form[] = $field_id;
642        $fields_form[] = $field_id;
643      }
644    }
645  }
646  if (is_array($field_form) && count($field_form)) {
647    module_load_include('inc', 'content', 'includes/content.node_form');
648    foreach ($field_form as $field_id) {
649      $field = content_fields($field_id, 'accion_especifica');
650      $form['#field_info'][$field_id] = $field;
651      $form += (array) content_field_form($form, $form_state, $field);
652    }
653  }
654  $form['#arreglo_financiamiento'] = $arreglo_financiamiento;
655  $form['#arreglo_financiamiento_fields'] = $arreglo_financiamiento_fields;
656
657  $form['#fields_financiamiento'] = $fields_financiamiento;
658  $form['#proyectos_operativos_fields'] = $fields_form;
659  $form['buttons'] = array(
660    '#prefix' => '<div class="container-inline">',
661    '#suffix' => '</div>',
662  );
663  $form['buttons']['registrar'] = array(
664    '#type' => 'submit',
665    '#default_value' => t('Aceptar'),
666    '#weight' => 100,
667  );
668  $form['buttons']['cancelar'] = array(
669    '#type' => 'submit',
670    '#default_value' => t('Cancelar'),
671    '#attributes' => array('onClick' => 'window.location="' . base_path() .$_GET['q'] . '"; return false;'),
672    '#weight' => 101,
673  );
674  $form['#proyecto_completed'] = FALSE;
675  $form['#after_build'] = array('proyectos_operativos_accion_especifica_crear_form_after_build');
676  if (!isset($form['#node']->nid) && $form['#ejecucion'] >= 100 && $form['#monto_restante'] == 0){
677    //add aditional variables
678    $aux_form = array();
679    $aux_form['#node'] = $form['#node'];
680    $aux_form['#proyecto'] = $form['#proyecto'];
681    $aux_form['#mensaje_mostrar'] = $form['#mensaje_mostrar'];
682    $aux_form['#ejecucion'] =  $form['#ejecucion'];
683    $aux_form['#porcentajes'] =  $form['#porcentajes'];
684    $aux_form['#montos'] =  $form['#montos'];
685    $aux_form['#acciones_especificas'] =  $form['#acciones_especificas'];
686
687    $aux_form['#campo_ordinarios'] = $form['#campo_ordinarios'];
688    $aux_form['#campo_propios'] = $form['#campo_propios'];
689    $aux_form['#campo_transferencias'] = $form['#campo_transferencias'];
690    $aux_form['#campo_otros'] = $form['#campo_otros'];
691
692    $aux_form['#fields_financiamiento'] = $form['#fields_financiamiento'];
693
694    $form = $aux_form;
695    $form['buttons'] = array(
696      '#prefix' => '<div class="container-inline">',
697      '#suffix' => '</div>',
698    );
699    $form['buttons']['siguiente'] = array(
700      '#type' => 'submit',
701      '#default_value' => t('Terminar'),
702      '#weight' => 100,
703    );
704    $form['buttons']['cancelar'] = array(
705      '#type' => 'submit',
706      '#default_value' => t('Cancelar'),
707      '#attributes' => array('onClick' => 'window.location="' . base_path() .$_GET['q'] . '"; return false;'),
708      '#weight' => 101,
709    );
710    $form['#proyecto_completed'] = TRUE;
711  }
712  $form['#submit'] = array('proyectos_operativos_accion_especifica_crear_form_submit');
713  return $form;
714}
715
716/*
717 * proyectos_operativos_accion_especifica_crear_form_after_build
718 * Funcion para agregar funciones javascript al formulario
719 */
720function proyectos_operativos_accion_especifica_crear_form_after_build($form, &$form_state) {
721  if (is_array($form['#arreglo_financiamiento']) && count($form['#arreglo_financiamiento'])) {
722    foreach ($form['#arreglo_financiamiento'] as $id => $macro) {
723      $nuid = str_replace('_', '-', $id);
724      if (is_array($form['#campo_' . $id]) && count($form['#campo_' . $id])) {
725        foreach ($form['#campo_' . $id] as $field_id) {
726          $form[$id][$field_id][0]['value']['#attributes']['class'] .= ' total-' . $nuid;
727          if (!isset($form[$id][$field_id]['value']['#attributes']['onchange'])) {
728            $form[$id][$field_id][0]['value']['#attributes']['onchange'] = "sumarff('" . $nuid . "');sumarff1('subtotales');";
729          }
730          else {
731            $form[$id][$field_id][0]['value']['#attributes']['onchange'] .= ";sumarff('" . $nuid . "');sumarff1('subtotales');";
732          }
733        }
734      }
735    }
736  }
737  return $form;
738}
739
740/*
741 * proyectos_operativos_accion_especifica_crear_form_validate
742 * Validar accion especifica
743 */
744function proyectos_operativos_accion_especifica_crear_form_validate($form, &$form_state) {
745  $op = isset($form_state['values']['op']) ? $form_state['values']['op'] : '';
746  if ($op == t('Cancelar') || $op == t('Terminar')) {
747    return;
748  }
749  $proyectos_operativos_path = drupal_get_path('module', 'proyectos_operativos');
750  drupal_add_js($proyectos_operativos_path . '/js/proyectos_operativos_extra.js');
751  drupal_add_js($proyectos_operativos_path . '/js/proyectos_operativos.js');
752  drupal_add_js($proyectos_operativos_path . '/js/accion_especifica.js');
753  drupal_add_js($form['#format_number'], 'setting');
754  //validamos que el porc sea mayor que cero
755  if (!$form_state['values']['field_accion_esp_ponderacion'][0]['value'] && $form_state['values']['field_accion_esp_ponderacion'][0]['value'] >= 100) {
756    form_set_error('field_accion_esp_ponderacion', t('La ponderaciones de la Acción especifica debe ser menor que 100'));
757  }
758
759  //validamos que el porc sea mayor que cero
760  if (!$form_state['values']['field_accion_esp_ponderacion'][0]['value'] && $form_state['values']['field_accion_esp_ponderacion'][0]['value'] <= 0) {
761    form_set_error('field_accion_esp_ponderacion', t('La ponderaciones de la Acción especifica debe ser mayor que cero'));
762  }
763  //validamos que la ponderacion no sea mayor a 100
764  $suma_porc = $form['#ejecucion'] + $form_state['values']['field_accion_esp_ponderacion'][0]['value'];
765  if ($suma_porc > 100) {
766    form_set_error('field_accion_esp_ponderacion', t('La suma de las ponderaciones de la Acción especifica debe ser menor o igual a 100%'));
767  }
768  if (variable_get('accion_especifica_100_ponderation', 0) && $form_state['values']['field_accion_esp_ponderacion'][0]['value'] >= 100) {
769    form_set_error('field_accion_esp_ponderacion', t('La ponderación de la Acción especifica debe ser menor o igual a 100%'));
770  }
771  //validamos que la ponderacion no se encuentre repetida
772  if (!variable_get('accion_especifica_allow_ponderation', 0) && isset($form['#porcentajes'][$form_state['values']['field_accion_esp_ponderacion'][0]['value']])) {
773    form_set_error('field_accion_esp_ponderacion', t('Ya existe una acción especifica con esta ponderación'));
774  }
775  //validamos que las fechas esten dentro de la del proyecto
776  if ($form_state['values']['field_accion_esp_fechai'][0]['value'] > $form_state['values']['field_accion_esp_fechai'][0]['value']) {
777    form_set_error('field_accion_esp_fechai', t('La fecha de inicio de la Acción especifica debe ser menor a la fecha de fin'));
778  }
779  if ($form['#proyecto']->field_proyecto_fecha_i[0]['value'] > $form_state['values']['field_accion_esp_fechai'][0]['value']) {
780    form_set_error('field_accion_esp_fechai', t('La fecha de inicio de la Acción especifica debe ser mayor o igual a la fecha de inicio del proyecto @fecha', array('@fecha' => $form['#proyecto']->field_proyecto_fecha_i[0]['value'])));
781  }
782  if ($form['#proyecto']->field_proyecto_fecha_f[0]['value'] < $form_state['values']['field_accion_esp_fechai'][0]['value']) {
783    form_set_error('field_accion_esp_fechai', t('La fecha de inicio de la Acción especifica debe ser mayor o igual a la fecha de fin del proyecto @fecha', array('@fecha' => $form['#proyecto']->field_proyecto_fecha_f[0]['value'])));
784  }
785  if ($form['#proyecto']->field_proyecto_fecha_i[0]['value'] > $form_state['values']['field_accion_esp_fechaf'][0]['value']) {
786    form_set_error('field_accion_esp_fechaf', t('La fecha de fin de la Acción especifica debe ser menor o igual a la fecha de inicio del proyecto @fecha', array('@fecha' => $form['#proyecto']->field_proyecto_fecha_i[0]['value'])));
787  }
788  if ($form['#proyecto']->field_proyecto_fecha_f[0]['value'] < $form_state['values']['field_accion_esp_fechaf'][0]['value']) {
789    form_set_error('field_accion_esp_fechaf', t('La fecha de fin de la Acción especifica debe ser menor o igual a la fecha de fin del proyecto @fecha', array('@fecha' => $form['#proyecto']->field_proyecto_fecha_f[0]['value'])));
790  }
791  //obtener la fecha de inicio y fin
792  $mes = explode('-', $form_state['values']['field_accion_esp_fechai'][0]['value']);
793  $mes_inicio = 0;
794  if (count($mes)) {
795    $mes_inicio = $mes[1] - 1;
796  }
797  //obtener la fecha de inicio y fin
798  $mes = explode('-', $form_state['values']['field_accion_esp_fechaf'][0]['value']);
799  $mes_final = 0;
800  if (count($mes)) {
801    $mes_final = $mes[1] - 1;
802  }
803  if (isset($form_state['values']['field_accion_esp_metaf'])) {
804    $suma = 0;
805    for ($i = 0; $i < 12; $i++) {
806      if ($mes_inicio <= $i && $mes_final >= $i) {
807        $valor = $i ? 'value_' . $i : 'value';
808        $suma += $form_state['values']['field_accion_esp_metaf'][0][$valor];
809      }
810    }
811    if (!$suma) {
812      form_set_error('field_accion_esp_metaf', t('La Distribución de la Meta Fisíca de la Acción especifica debe tener al menos un resultado'));
813    }
814  }
815  //validamos la accion especifica
816  if (isset($form_state['values']['field_accion_esp_programacion']) && count($form_state['values']['field_accion_esp_programacion'])) {
817    $sumap = 0;
818    foreach($form_state['values']['field_accion_esp_programacion'] as $id_programacion => $programacion) {
819      if (is_numeric($id_programacion)) {
820        for ($i = 0; $i < 12; $i++) {
821          if ($mes_inicio <= $i && $mes_final >= $i) {
822            $valor = $i ? 'value_' . $i : 'value';
823            $sumap += (float) $programacion[$valor];
824          }
825        }
826      }
827    }
828    if (!$sumap) {
829      form_set_error('field_accion_esp_programacion', t('La Programación Financiera de la Acción especifica debe tener al menos un valor'));
830    }
831  }
832  $sumaf = 0;
833  //validamos el financiamiento
834  $first_field = FALSE;
835  if (count($form['#fields_financiamiento'])) {
836    foreach($form['#fields_financiamiento'] as $field_id) {
837      $start = (float) $form_state['values'][$field_id][0]['value'];
838      $start = number_format($start, $form['#format_number']['format_number']['decimals'], '.', '');
839      $value = preg_replace('@[^-0-9]@', '', $start);
840      if ($start && $start != $value) {
841        form_set_error($field_id, t('Solo números enteros son permitidos en la fuente de financiamiento.'));
842      }
843      if ($value < 0) {
844        form_set_error($field_id, t('Solo números positivos son permitidos en la fuente de financiamiento.'));
845      }
846      if (!$first_field) {
847        $first_field = $field_id;
848      }
849      if (isset($form_state['values'][$field_id][0]['value'])) {
850        $sumaf += $form_state['values'][$field_id][0]['value'];
851      }
852    }
853  }
854  if ($first_field && $sumaf != $sumap) {
855    form_set_error($first_field, t('Las fuentes de financiamiento (@f_financiamiento) deben ser igual a la programación presupuestaria (@fuente)', array('@fuente' => number_format($sumap, $form['#format_number']['format_number']['decimals'], $form['#format_number']['format_number']['dec_point'], $form['#format_number']['format_number']['thousands_sep']), '@f_financiamiento' => number_format($sumaf, $form['#format_number']['format_number']['decimals'], $form['#format_number']['format_number']['dec_point'], $form['#format_number']['format_number']['thousands_sep']))));
856  }
857  //validamos que la suma de la programacion financiera sea + las otras acciones sean inferiores o iguales a la suma total del proyecto
858  $sumaT = $form['#montos'] +$sumap;
859  if ($sumaT > $form['#proyecto']->field_proyecto_monto_anual[0]['value']) {
860    form_set_error('field_accion_esp_programacion', t('La suma de los montos de las acciones especificas (@monto) debe ser menor o igual al monto anual del proyecto (@fuente)', array('@fuente' => number_format($form['#proyecto']->field_proyecto_monto_anual[0]['value'], $form['#format_number']['format_number']['decimals'], $form['#format_number']['format_number']['dec_point'], $form['#format_number']['format_number']['thousands_sep']), '@monto' => number_format($sumaT, $form['#format_number']['format_number']['decimals'], $form['#format_number']['format_number']['dec_point'], $form['#format_number']['format_number']['thousands_sep']))));
861  }
862  if ($suma_porc == 100 && $sumaT < $form['#proyecto']->field_proyecto_monto_anual[0]['value']) {
863    form_set_error('field_accion_esp_programacion', t('La suma de los montos de las acciones especificas (@monto) debe ser menor igual al monto anual del proyecto (@fuente) cuando las ponderaciones de las Acciones Específicas sume 100%', array('@fuente' => number_format($form['#proyecto']->field_proyecto_monto_anual[0]['value'], $form['#format_number']['format_number']['decimals'], $form['#format_number']['format_number']['dec_point'], $form['#format_number']['format_number']['thousands_sep']), '@monto' => number_format($sumaT, $form['#format_number']['format_number']['decimals'], $form['#format_number']['format_number']['dec_point'], $form['#format_number']['format_number']['thousands_sep']))));   
864  }
865  elseif($suma_porc < 100 && $sumaT == $form['#proyecto']->field_proyecto_monto_anual[0]['value']) {
866    form_set_error('field_accion_esp_ponderacion', t('La suma de las ponderaciones de la Acción especifica debe ser menor o igual a 100% (@suma_porc % alcanzado) y el monto por asignar no es suficiente para nuevas Acciones (Monto Asignado: @monto_asignado Bs, Monto del proyecto: @monto_proyecto Bs)', array('@suma_porc' => number_format($suma_porc, $form['#format_number']['format_number']['decimals'], $form['#format_number']['format_number']['dec_point'], $form['#format_number']['format_number']['thousands_sep']), '@monto_asignado' => number_format($sumaT, $form['#format_number']['format_number']['decimals'], $form['#format_number']['format_number']['dec_point'], $form['#format_number']['format_number']['thousands_sep']), '@monto_proyecto' => number_format($form['#proyecto']->field_proyecto_monto_anual[0]['value'], $form['#format_number']['format_number']['decimals'], $form['#format_number']['format_number']['dec_point'], $form['#format_number']['format_number']['thousands_sep']))));
867  }
868}
869
870/*
871 * proyectos_operativos_accion_especifica_crear_form_submit
872 * Guardar accion especifica
873 */
874function proyectos_operativos_accion_especifica_crear_form_submit($form, &$form_state) {
875  $op = isset($form_state['values']['op']) ? $form_state['values']['op'] : '';
876  if ($op == t('Cancelar')) {
877    drupal_set_message(t('Se cancelo el ingreso de la AE.'));
878    $form_state['redirect'] = 'proyectosopedit/' . $form['#proyecto']->nid;
879    return;
880  }
881  if ($op == t('Terminar')) {
882    $form_state['redirect'] = 'proyectosopedit/' . $form['#proyecto']->nid . '/finacieros';
883    return;
884  }
885  if (module_exists('hs_content_taxonomy')) {
886    foreach ($form['#field_info'] as $field_name => $field_info) {
887      if ($field_info['widget']['type'] == 'content_taxonomy_hs') {
888        // Change format of values to the one Content Taxonomy expects
889        if (is_array($form_state['values'][$field_name]['tids'])) {
890          $values = array();
891          foreach($form_state['values'][$field_name]['tids'] as $tid) {
892            $values[] = array('value' => $tid);
893            array_unshift($form_state['values'][$field_name], array('value' => $tid));
894          }
895          $form_state['values'][$field_name]['tids'] = $values;
896        }
897        else {
898          $values[] = array('value' => $form_state['values'][$field_name]['tids']);
899          array_unshift($form_state['values'][$field_name],array('value' => $form_state['values'][$field_name]['tids']));
900          $form_state['values'][$field_name]['tids'] = $values;
901        }
902      }
903    }
904  }
905  global $user;
906  $field_form = $form['#proyectos_operativos_fields'];
907  module_load_include('inc', 'node', 'node.pages');
908  $node_load = $form['#node'];
909  //obtener la fecha de inicio y fin
910  $mes = explode('-', $form_state['values']['field_accion_esp_fechai'][0]['value']);
911  $mes_inicio = 0;
912  if (count($mes)) {
913    $mes_inicio = $mes[1] - 1;
914  }
915  //obtener la fecha de inicio y fin
916  $mes = explode('-', $form_state['values']['field_accion_esp_fechaf'][0]['value']);
917  $mes_final = 0;
918  if (count($mes)) {
919    $mes_final = $mes[1] - 1;
920  }
921  if (isset($form_state['values']['field_accion_esp_metaf'])) {
922    $suma = 0;
923    for ($i = 0; $i < 12; $i++) {
924      $valor = $i ? 'value_' . $i : 'value';
925      if ($mes_inicio <= $i && $mes_final >= $i) {
926        $suma += $form_state['values']['field_accion_esp_metaf'][0][$valor];
927      }
928      else {
929        $form_state['values']['field_accion_esp_metaf'][0][$valor] = 0;
930      }
931    }
932  }
933  if (isset($form_state['values']['field_accion_esp_programacion'])) {
934    $suma = 0;
935    foreach($form_state['values']['field_accion_esp_programacion'] as $id => $programacion) {
936      for ($i = 0; $i < 12; $i++) {
937        $valor = $i ? 'value_' . $i : 'value';
938        if ($mes_inicio <= $i && $mes_final >= $i) {
939          $suma += $form_state['values']['field_accion_esp_metaf'][$id][$valor];
940        }
941        else {
942          $form_state['values']['field_accion_esp_programacion'][$id][$valor] = 0;
943        }
944      }
945    }
946  }
947  $form_values = $form_state['values'];
948  //cambiar
949  $node_load->title = t('Acción Específica del proyecto @nombreproyecto', array('@nombreproyecto' => $form['#proyecto']->title));
950  if (is_array($field_form) && count($field_form)) {
951    foreach ($field_form as $field_id) {
952      if (isset($form_values[$field_id]) && is_array($form_values[$field_id])) {
953        foreach($form_values[$field_id] as $id => $value) {
954          if (is_numeric($id) && isset($form_values[$field_id][$id]['_error_element'])) {
955            unset($form_values[$field_id][$id]['_error_element']);
956          }
957        }
958        $node_load->{$field_id} = $form_values[$field_id];
959      }
960    }
961  }
962  $nid = FALSE;
963  if ($node_load->nid) {
964    $nid = TRUE;
965    $texto = t('Modificada la Acción especifica del proyecto');
966    $node_load->log = $texto;
967    drupal_set_message($texto);
968  }
969  else {
970    //se agrega el enlace al proyecto
971    $node_load->uid = $user->uid;
972    $node_load->field_accion_esp_proyecto = array();
973    $node_load->field_accion_esp_proyecto[] = array('nid' => $form['#proyecto']->nid);
974    $node_load->field_accion_esp_ente = array();
975    $node_load->field_accion_esp_ente[] = array('nid' => $form['#proyecto']->field_proyecto_ente[0]['nid']);
976    $texto = t('Agregada la Acción especifica del proyecto');
977    $node_load->log = $texto;
978    drupal_set_message($texto);
979  }
980  $node_load->revision = 1;
981  node_save($node_load);
982  if (!$nid) {
983    $proyecto = $form['#proyecto'];
984    if (!$proyecto->field_proyecto_accion_esp[0]['nid']) {
985      $proyecto->field_proyecto_accion_esp = array();
986    }
987    $proyecto->field_proyecto_accion_esp[] = array('nid' => $node_load->nid);
988    $proyecto->revision = 1;
989    $proyecto->log = t('Agregada Acción especifica del proyecto');
990    node_save($proyecto);
991  }
992  if (!$_REQUEST['destination']) {
993    // add redirect
994    $form_state['redirect'] = 'proyectosopedit/' . $form['#proyecto']->nid . '/ae';
995  }
996}
997
998/**
999 * @ingroup themeable
1000 * @see proyectos_operativos_accion_especifica_crear_form
1001 */
1002function theme_proyectos_operativos_accion_especifica_crear_form($form) {
1003  $output = '';
1004  if (!$form['#proyecto_completed']) {
1005    $output .= '<div id="mensaje-mostrar" class="mensaje mensaje-mostrar" style="color:red;font-weight: bold;">' . $form['#mensaje_mostrar'] . '</div>';
1006    $output .= '<fieldset><legend>' . t('Definición de la Acción Especifica') . '</legend>' . drupal_render($form['field_accion_titulo']) . drupal_render($form['field_accion_esp_fechai']) . drupal_render($form['field_accion_esp_fechaf']) . drupal_render($form['field_accion_esp_ejecutor']) . drupal_render($form['field_accion_esp_bien']) . '</fieldset>';
1007    $output .= '<fieldset><legend>' . t('Distribución de la Meta Fisica de la acción Especifica') . '</legend>' . drupal_render($form['field_accion_esp_unidadm']) . drupal_render($form['field_accion_esp_ponderacion']) . drupal_render($form['field_accion_esp_metaf']) . '</fieldset>';
1008    $output .= drupal_render($form['distribucion']);
1009    $output .= '<fieldset><legend>' . t('Programación Financiera de la Acción') . '</legend>' . drupal_render($form['field_accion_esp_programacion']);
1010    $ftypes = array(
1011      'tid' => t('Account'),
1012      'value' => t('Ene'),
1013      'value_1' => t('Feb'),
1014      'value_2' => t('Mar'),
1015      'value_3' => t('Abr'),
1016      'value_4' => t('May'),
1017      'value_5' => t('Jun'),
1018      'value_6' => t('Jul'),
1019      'value_7' => t('Aug'),
1020      'value_8' => t('Sep'),
1021      'value_9' => t('Oct'),
1022      'value_10' => t('Nov'),
1023      'value_11' => t('Dic'),
1024    );
1025    $output .= '<div style="width:2250px">';
1026    $i = -1;
1027    foreach ($ftypes as $ftype => $label) {
1028      if($ftype != 'tid') {
1029        $output .= '<div class = "field_accion_esp_programacion_m' . $i . '_field_total field_accion_esp_programacion_totales" style = "width:143px;float:left;margin-left:10px; border: 1px solid #D5D5D5;text-align:center;overflow:auto">0</div>';
1030      }
1031      else {
1032        $output .= '<div style = "width:180px;float:left;margin-left:5px;text-align:right"><b>' . t('TOTAL') . '</b></div>';
1033      }
1034      $i++;
1035    }
1036    $output .= '<div class = "field_accion_esp_programacion_dato_field_total" style = "width:143px;float:left;margin-left:10px; border: 1px solid #D5D5D5;text-align:center;overflow:auto">0</div>';
1037    $output .= '</div></fieldset>';
1038    $rows = array();
1039    $row = array();
1040    $row1 = array();
1041    $cantidad_campos = count($form['#arreglo_financiamiento']);
1042    if (is_array($form['#arreglo_financiamiento']) && count($form['#arreglo_financiamiento'])) {
1043      foreach ($form['#arreglo_financiamiento'] as $id => $macro) {
1044        $row[] = array('data' => drupal_render($form[$id]), );
1045        $row1[] = array('data' => drupal_render($form['total_' . $id]), );
1046      }
1047      $rows[] = $row;
1048      $rows[] = $row1;
1049      $row = array();
1050      $row[] = array('data' => '<b>' . t('TOTAL') . ':</b>', 'colspan' => $cantidad_campos - 1, 'align' => 'right');
1051      $row[] = array('data' => drupal_render($form['total_financiamiento']), );
1052      $rows[] = $row;
1053      $output .= '<fieldset><legend>' . t('Fuentes de Financiamiento') . '</legend>' . theme('table', array(), $rows) . '</fieldset>';
1054    }
1055    $output .= '<fieldset><legend>' . t('Localización Geográfica') . '</legend>' . drupal_render($form['field_accion_esp_localizacion']) . drupal_render($form['field_accion_esp_latitud']) . drupal_render($form['field_accion_esp_longitud']) . '</fieldset>';
1056    $output .= drupal_render($form);
1057  }
1058  $header = array();
1059  $cab = 6;
1060  $header[] = array('data' => t('Nro'));
1061  $header[] = array('data' => t('Nombre'));
1062  $header[] = array('data' => t('Fecha de inicio'));
1063  $header[] = array('data' => t('Fecha de Fin')); 
1064  $header[] = array('data' => t('%'));
1065  $header[] = array('data' => t('Acción'));
1066  $rows = array();
1067  $i = 1;
1068  if (count($form['#acciones_especificas'])) {
1069    $suma = 0;
1070    foreach($form['#acciones_especificas'] as $accion) {
1071      if (isset($accion->nid)) {
1072        $row = array();
1073        $row[] = array('data' => $i,);
1074        $row[] = array('data' => $accion->titulo_asignado,);
1075        //Se cambia el formato de la fecha
1076        $fecha = explode(' ', $accion->field_accion_esp_fechai[0]['value']);
1077        $formato = explode('-', $fecha[0]);
1078        $row[] = array('data' => $formato[2] . '/' . $formato[1] . '/' . $formato[0],);
1079        //Se cambia el formato de la fecha
1080        $fecha = explode(' ', $accion->field_accion_esp_fechaf[0]['value']);
1081        $formato = explode('-', $fecha[0]);
1082        $row[] = array('data' => $formato[2] . '/' . $formato[1] . '/' . $formato[0],);
1083        $suma += $accion->field_accion_esp_ponderacion[0]['value'];
1084        $row[] = array('data' => $accion->field_accion_esp_ponderacion[0]['value'],);
1085        $links = array();
1086        $links[] = l(t('Modificar'), 'proyectosopedit/' . $form['#proyecto']->nid . '/ae/' . $accion->nid . '/edit');
1087        $links[] = l(t('Eliminar'), 'proyectosopedit/' . $form['#proyecto']->nid . '/ae/' . $accion->nid . '/remove');
1088        $row[] = array('data' => theme('item_list', $links),);
1089        $rows[] = $row;
1090        $i++;
1091      }
1092    }
1093  }
1094  if (count($rows)) {
1095    $output .= theme('table', $header, $rows);
1096  }
1097  //no mostrar el formulario si ya se alcanzo lo asignado
1098  if ($form['#proyecto_completed']) {
1099    $output .= drupal_render($form);
1100  }
1101  $output .= l('Agregar nueva Acción Especifica', 'proyectosopedit/' . $form['#proyecto']->nid . '/ae/');
1102
1103  return $output;
1104}
Nota: Vea TracBrowser para ayuda de uso del navegador del repositorio.