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

stableversion-3.0
Last change on this file since 2db5c18 was a0cf94c, checked in by eramirez <eramirez@…>, 8 años ago

se modifico el modulo de proyectos operativos

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