source: sipes/0.3-modules/proyectos_operativos/accion_especifica.module @ de9b283

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

se modifico el theme de las fuentes de Financiamiento

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