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

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

se agregaron los modulos

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