source: sipp/0.3-stable-modules/sipp_pdf/sipp_pdf.module @ 4b7848a

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

Se agregaron los nuevos cambios a los modulos

  • Propiedad mode establecida a 100644
File size: 60.7 KB
Línea 
1<?php
2
3function _sipp_pdf_pdf_init() {
4  $author = variable_get('site_name', '');
5  $path = libraries_get_path('tcpdf');
6  if (($path) && (file_exists($path . 'config/lang/spa.php'))) {
7    require_once($path . '/config/lang/spa.php');
8  }
9  else {
10    drupal_set_message(t('TCPDF library not found!'), 'error');
11    return FALSE;
12  }
13
14  if (($path) && (file_exists($path . '/tcpdf.php'))) {
15    require_once($path . '/tcpdf.php');
16  }
17  else {
18    drupal_set_message(t('TCPDF library not found!'), 'error');
19    return FALSE;
20  }
21  // create new PDF documentsite_slogan
22  $pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
23  // set document information
24  $pdf->SetCreator($author);
25  $pdf->SetAuthor($author);
26  // set default header data
27  $pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE, PDF_HEADER_STRING);
28  // set header and footer fonts
29  $pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
30  $pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));
31  // set default monospaced font
32  $pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
33  //set margins
34  $pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
35  $pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
36  $pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
37  //set auto page breaks
38  $pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
39  //set image scale factor
40  $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
41  //set some language-dependent strings
42  $pdf->setLanguageArray($l);
43  // ---------------------------------------------------------
44  // set font
45  $font_size = variable_get('sipp_pdf_font_size', 8);
46  $pdf->SetFont('dejavusans', '', $font_size);
47  // add a page
48  $pdf->AddPage();
49  return $pdf;
50}
51
52/*
53 * Implementation of hook_proyecto_obtiene_links_alter()
54 */
55function sipp_pdf_proyecto_obtiene_links_alter(&$links, $proyecto, $acceso = FALSE) {
56  $node_accion = node_load($proyecto->nid);
57  if(_sipp_pdf_ver_datos_wk_access($node_accion)){
58    $links[] = array(
59      'data' => l(t('Obtener Campos del Proyecto en PDF'), 'proyectosop/' . $proyecto->nid . '/pdf'),
60      'class' => 'proyectos-operativos-ver-pdf',
61    );
62  }
63  if(_proyectos_operativos_ver_datos_wk_access($node_accion)){
64    $links[] = array(
65      'data' => l(t('Obtener Acciones Específicas del Proyecto en PDF'), 'proyectosop/' . $proyecto->nid . '/ae/pdf'),
66      'class' => 'proyectos-operativos-ver-ae-pdf',
67    );
68    $links[] = array(
69      'data' => l(t('Obtener Datos Financieros del Proyecto en PDF'), 'proyectosop/' . $proyecto->nid . '/finacieros/pdf'),
70      'class' => 'proyectos-operativos-ver-datos-financieros-pdf',
71    );
72  }
73  if(_proyectos_reformulacion_reformula_node_tab_access($node_accion)){
74    $links[] = array(
75      'data' => l(t('Obtener Reformulaciones del Proyecto en PDF'), 'proyectosop/' . $proyecto->nid . '/reformular/pdf'),
76      'class' => 'proyectos-operativos-reformulaciones-pdf',
77    );
78  }
79
80}
81
82/*
83 * Implementation of hook_proyecto_accion_obtiene_links_alter()
84 */
85function sipp_pdf_proyecto_accion_obtiene_links_alter(&$links, $proyecto, $accion, $acceso = FALSE) {
86
87  if(_proyectos_operativos_ver_datos_wk_access($proyecto)){
88    $links[] = array(
89      'data' => l(t('Obtener Acción específica en PDF'), 'proyectosop/' . $proyecto->nid . '/ae/' . $accion->nid . '/pdf'),
90      'class' => 'proyectos-operativos-acciones_especificas-pdf',
91    );
92  }
93}
94/*
95 * Implementation of hook_proyecto_accion_obtiene_links_alter()
96 */
97function sipp_pdf_proyecto_reformula_obtiene_links_alter(&$links, $proyecto, $reformular, $acceso = FALSE) {
98
99  if(_proyectos_reformulacion_reformula_node_tab_access($proyecto)){
100    $links[] = array(
101      'data' => l(t('Obtener Reformulación en PDF'), 'proyectosop/' . $proyecto->nid . '/reformular/' . $reformular->id_ref . '/pdf'),
102      'class' => 'proyectos-operativos-ver-reformulacion-pdf',
103    );
104  }
105}
106
107/*
108 * Implementation of hook_proyecto_accion_obtiene_links_alter()
109 */
110function sipp_pdf_proyecto_reformula_accion_obtiene_links_alter(&$links, $proyecto, $reformular, $accion, $acceso = FALSE) {
111
112  if(_proyectos_reformulacion_reformula_node_tab_access($proyecto, $reformular)){
113    $links[] = array(
114      'data' => l(t('Obtener Reformulación de la Acción Específica en PDF'), 'proyectosop/' . $proyecto->nid . '/reformular/' . $reformular->id_ref . '/ae/' . $accion->nid . '/pdf'),
115      'class' => 'proyectos-operativos-ver-reformulacion-accion-pdf',
116    );
117  }
118}
119
120
121/**
122 * Implementation of hook_theme().accioncent_ver_pdfaccioncent_seguimiento_pdf
123*/
124function sipp_pdf_theme() {
125  $sipp_pdf_path = drupal_get_path('module', 'sipp_pdf') . '/templates';
126  return array(
127    'accioncent_ver_pdf' => array(
128      'arguments' => array(
129        'accion' => array(),
130      ),
131      'template' => 'accioncent-ver-pdf',
132      'path' => $sipp_pdf_path,
133    ),
134    'accioncent_reformulaciones_pdf' => array(
135      'arguments' => array(
136        'accion' => array(),
137      ),
138      'template' => 'accioncent-reformulaciones-pdf',
139      'path' => $sipp_pdf_path,
140    ),
141    'accioncent_reformulaciones_ver_pdf' => array(
142      'arguments' => array(
143        'accion' => array(),
144        'reformulacion_load' => array(),
145      ),
146      'template' => 'accioncent-reformulaciones-ver-pdf',
147      'path' => $sipp_pdf_path,
148    ),
149    'accioncent_seguimiento_pdf' => array(
150      'arguments' => array(
151        'accion' => array(),
152      ),
153      'template' => 'accioncent-seguimiento-pdf',
154      'path' => $sipp_pdf_path,
155    ),
156    'accioncent_seguimiento_ver_campos_pdf' => array(
157      'arguments' => array(
158        'accion' => array(),
159        'campo' => '',
160        'mes' => 0,
161      ),
162      'template' => 'accioncent-seguimiento-ver-campos-pdf',
163      'path' => $sipp_pdf_path,
164    ),
165    'proyecto_campos_ver_pdf' => array(
166      'arguments' => array(
167        'proyecto' => array(),
168        'campos' => array(),
169      ),
170      'template' => 'proyecto-campos-ver-pdf',
171      'path' => $sipp_pdf_path,
172    ),
173    'proyectos_operativos_datos_ae_list_pdf' => array(
174      'arguments' => array(
175        'proyecto' => array(),
176      ),
177      'template' => 'proyectos-operativos-datos-ae-list-pdf',
178      'path' => $sipp_pdf_path,
179    ),
180    'proyectos_operativos_datos_financieros_pdf' => array(
181      'arguments' => array(
182        'proyecto' => array(),
183      ),
184      'template' => 'proyectos-operativos-datos-financieros-pdf',
185      'path' => $sipp_pdf_path,
186    ),
187    'proyectos_reformulacion_reformula_obtiene_list_pdf' => array(
188      'arguments' => array(
189        'proyecto' => array(),
190      ),
191      'template' => 'proyecto-reformulacion-lista-pdf',
192      'path' => $sipp_pdf_path,
193    ),
194    'proyectos_reformulacion_reformula_tab_page_pdf' => array(
195      'arguments' => array(
196        'proyecto' => array(),
197        'reformulacion_load' => array(),
198        'id_ref' => 0,
199        'reformula' => array(),
200        'variaciones' => array(),
201      ),
202      'template' => 'proyectos-ver-reformulacion-pdf',
203      'path' => $sipp_pdf_path,
204    ),
205    'proyectos_reformulacion_reformula_tab_ae_page_pdf' => array(
206      'arguments' => array(
207        'proyecto' => array(),
208        'reformulacion_load' => array(),
209        'ae' => array(),
210        'id_ref' => 0,
211        'reformula' => array(),
212        'variaciones' => array(),
213      ),
214      'template' => 'proyectos-ver-reformulacion-ae-pdf',
215      'path' => $sipp_pdf_path,
216    ),
217  );
218}
219
220function _sipp_pdf_ver_datos_wk_access($node) {
221  return (isset($_SESSION['proyectos_operativos_mostrar_campos']) && count($_SESSION['proyectos_operativos_mostrar_campos']) && _proyectos_operativos_ver_datos_wk_access($node));
222}
223
224function _acciones_centralizadas_verpdf($node) {
225  return ($node->type == 'accion_centralizada' && (user_access('ver planificador') || user_access('admin planificador')));
226}
227
228
229
230
231
232/*
233 * Implementation of hook_menu()
234 */
235function sipp_pdf_menu() {
236  $items = array();
237  //Acciones centralizadas
238  $items['node/%node/pdf'] = array(
239    'title' => 'Ver en pdf',
240    'type' => MENU_LOCAL_TASK,
241    'access callback' => '_acciones_centralizadas_verpdf',
242    'access arguments' => array(1),
243    'page callback' => '_sipp_pdf_accionesp_ver_pdf',
244    'page arguments' => array(1),
245    'weight' => 2,
246  );
247
248  $items['node/%node/reformular/pdf'] = array(
249    'title' => 'Reformulaciones PDF',
250    'type' => MENU_LOCAL_TASK,
251    'access callback' => '_acciones_centralizadas_reformula_node_tab_access',
252    'access arguments' => array(1),
253    'page callback' => '_sipp_pdf_reformulaciones_accioncent',
254    'page arguments' => array(1),
255    'weight' => 2,
256  );
257
258  $items['node/%node/reformular/%acciones_centralizadas_menu_reformulacion/pdf'] = array(
259    'title' => 'AC PDF',
260    'type' => MENU_LOCAL_TASK,
261    'access callback' => '_acciones_centralizadas_reformula_node_tab_access',
262    'access arguments' => array(1),
263    'page callback' => '_sipp_pdf_reformulaciones_accioncent_ver',
264    'page arguments' => array(1, 3),
265    'weight' => 3,
266  );
267  $items['node/%node/seguimiento/list'] = array(
268    'title' =>  t('Seguimiento'),
269    'type' => MENU_DEFAULT_LOCAL_TASK,
270    'weight' => -10
271  );
272  $items['node/%node/seguimiento/pdf'] = array(
273    'title' => 'Seguimientos PDF',
274    'type' => MENU_LOCAL_TASK,
275    'access callback' => '_acciones_centralizadas_seguimiento_node_tab_access',
276    'access arguments' => array(1),
277    'page callback' => '_sipp_pdf_seguimiento_accioncent',
278    'page arguments' => array(1),
279    'weight' => 2,
280  );
281  $items['node/%node/seguimiento/%acciones_centralizadas_menu_campo/%acciones_centralizadas_menu_mes/pdf'] = array(
282    'title' => 'Seguimiento Mes PDF',
283    'type' => MENU_LOCAL_TASK,
284    'access callback' => '_acciones_centralizadas_seguimiento_node_tab_access',
285    'access arguments' => array(1),
286    'page callback' => '_sipp_pdf_seguimiento_ver_campos_accioncent',
287    'page arguments' => array(1, 3, 4),
288    'weight' => 2,
289  );
290
291  //proyectos operativos
292  $items['proyectosop/%proyectosop/pdf'] = array(
293    'title' => t('Ver en PDF'),
294    'page callback' => '_sipp_pdf_proyecto_campos_pdf',
295    'page arguments' => array(1),
296    'access callback' => '_sipp_pdf_ver_datos_wk_access',
297    'access arguments' => array(1),
298    'weight' => -7,
299    'type' => MENU_LOCAL_TASK,
300  );
301  $items['proyectosop/%proyectosop/ae/%accion_especifical/pdf'] = array(
302    'title' => t('Ver AE en PDF'),
303    'page callback' => '_sipp_pdf_datosaeview',
304    'page arguments' => array(3),
305    'access callback' => '_proyectos_operativos_ver_datos_wk_access',
306    'access arguments' => array(1),
307    'weight' => -4,
308    'type' => MENU_LOCAL_TASK,
309  );
310
311
312  $items['proyectosop/%proyectosop/ae/ver'] = array(
313    'title' =>  t('AES'),
314    'type' => MENU_DEFAULT_LOCAL_TASK,
315    'weight' => -10
316  );
317
318  $items['proyectosop/%proyectosop/ae/pdf'] = array(
319    'title' => t('AE PDF'),
320    'page callback' => '_sipp_pdf_datosaelist',
321    'page arguments' => array(1),
322    'access callback' => '_proyectos_operativos_ver_datos_wk_access',
323    'access arguments' => array(1),
324    'weight' => -5,
325    'type' => MENU_LOCAL_TASK,
326  );
327
328
329  $items['proyectosop/%proyectosop/finacieros/ver'] = array(
330    'title' =>  t('Datos Financieros'),
331    'type' => MENU_DEFAULT_LOCAL_TASK,
332    'weight' => -10
333  );
334  //consulta proyecto operativo (datos financieros)
335  $items['proyectosop/%proyectosop/finacieros/pdf'] = array(
336    'title' => t('Datos Financieros PDF'),
337    'page callback' => '_sipp_pdf_datosfinancierosview',
338    'page arguments' => array(1),
339    'access callback' => '_proyectos_operativos_ver_datos_wk_access',
340    'access arguments' => array(1),
341    'weight' => -4,
342    'type' => MENU_LOCAL_TASK,
343  );
344  $items['proyectosop/%proyectosop/reformular/%proyectosop_menu_reformulacion/ae/%accionesp_menu_r/pdf'] = array(
345    'title' => 'AEs PDF',
346    'type' => MENU_LOCAL_TASK,
347    'access callback' => '_proyectos_reformulacion_reformula_node_tab_access',
348    'access arguments' => array(1, 3),
349    'page callback' => '_sipp_pdf_aeview',
350    'page arguments' => array(1, 3, 5),
351    'weight' => 3,
352  );
353  $items['proyectosop/%proyectosop/reformular/%proyectosop_menu_reformulacion/pdf'] = array(
354    'title' => 'Reformulación PDF',
355    'type' => MENU_LOCAL_TASK,
356    'access callback' => '_proyectos_reformulacion_reformula_node_tab_access',
357    'access arguments' => array(1),
358    'page callback' => '_sipp_pdf_reformulaview',
359    'page arguments' => array(1, 3),
360    'weight' => 2,
361  );
362  $items['proyectosop/%proyectosop/reformular/pdf'] = array(
363    'title' => 'Reformulaciones PDF',
364    'type' => MENU_LOCAL_TASK,
365    'access callback' => '_proyectos_reformulacion_reformula_node_tab_access',
366    'access arguments' => array(1),
367    'page callback' => '_proyectos_reformulacion_reformula_list_pdf',
368    'page arguments' => array(1),
369    'weight' => 2,
370  );
371  return $items;
372}
373
374function _sipp_pdf_reformulaciones_accioncent($node) {
375  $pdf = _sipp_pdf_pdf_init();
376  $html = theme('accioncent_reformulaciones_pdf', $node);
377  if ($pdf) {
378    $title = t('Acciones Centralizada');
379    $pdf->SetTitle($title);
380    $pdf->SetSubject($title);
381    $pdf->writeHTML($html, true, false, true, false, '');
382    $pdf->lastPage();
383    header('Content-type: text/plain');
384    $name = 'acciones_centralizada_' . $node->nid . '.pdf';
385    header('Content-Disposition: attachment; filename="' . $name . '"');
386    print $pdf->Output($name, 'I');
387    exit();
388  }
389  else {
390    return $html;
391  }
392}
393
394
395function template_preprocess_accioncent_reformulaciones_pdf(&$variables) {
396  $accion = $variables['accion'];
397  $ente_planificador = node_load($accion->field_acciones_ente[0]['nid']);
398  $variables['ente_planificador'] = $ente_planificador;
399  $variables['states'] = _acciones_centralizadas_reformula_obtiene_estados();
400
401  $first_state = 0;
402  if ($states['wid']) {
403    $first_state = _workflow_creation_state($states['wid']);
404  }
405  $variables['first_state'] = $first_state;
406  $estado_naprobado = variable_get('acciones_centralizadas_state_naprobado', NULL);
407  $result = db_query('SELECT re.*, u.name, u.uid FROM {accion_reformular} re INNER JOIN {users} u ON u.uid = re.uid WHERE nid = %d AND estado <> %d ORDER BY id_ref DESC', $accion->nid, $estado_naprobado);
408  $reformulaciones = array();
409  while($reformular = db_fetch_object($result)) {
410    $reformulaciones[$reformular->id_ref] = $reformular;
411  }
412  $variables['reformulaciones'] = $reformulaciones;
413}
414
415
416function _sipp_pdf_reformulaciones_accioncent_ver($node, $reformulacion_load) {
417  $pdf = _sipp_pdf_pdf_init();
418  $html = theme('accioncent_reformulaciones_ver_pdf', $node, $reformulacion_load);
419  if ($pdf) {
420    $title = t('Acción Centralizada');
421    $pdf->SetTitle($title);
422    $pdf->SetSubject($title);
423    $pdf->writeHTML($html, true, false, true, false, '');
424    $pdf->lastPage();
425    header('Content-type: text/plain');
426    $name = 'acciones_centralizada_' . $node->nid . '_reformulacion.pdf';
427    header('Content-Disposition: attachment; filename="' . $name . '"');
428    print $pdf->Output($name, 'I');
429    exit();
430  }
431  else {
432    return $html;
433  }
434}
435
436function template_preprocess_accioncent_reformulaciones_ver_pdf(&$variables) {
437  $accion = $variables['accion'];
438  $ente_planificador = node_load($accion->field_acciones_ente[0]['nid']);
439  $variables['ente_planificador'] = $ente_planificador;
440  $reformulacion_load = $variables['reformulacion_load'];
441  $ente_planificador = node_load($accion->field_acciones_ente[0]['nid']);
442  $id_ref = $reformulacion_load ? $reformulacion_load->id_ref : 0;
443  $reformula = _acciones_centralizadas_reformula_load($accion, $id_ref);
444  $variaciones = _acciones_centralizadas_reformula_all_partidas_load($accion, $id_ref);
445  $variables['id_ref'] = $id_ref;
446  $variables['reformula'] = $reformula;
447  $variables['variaciones'] = $variaciones;
448  $grupos = fieldgroup_groups('accion_centralizada');
449  $grupos_form = array();
450  $grupos_fields = array();
451  foreach($grupos as $id => $grupo) {
452    if (count($grupo['fields'])) {
453      foreach($grupo['fields'] as $id_field => $field) {
454        $grupos_fields[$id_field] = $id;
455      }
456    }
457  }
458  $variables['grupos'] = $grupos;
459  $variables['grupos_fields'] = $grupos_fields;
460  $campos = array(
461    'field_ac_ac1_ae1',
462    'field_ac_ac1_ae2',
463    'field_ac_ac2_ae2',
464    'field_ac_ac2_ae3',
465    'field_ac_ac3_ae1',
466    'field_ac_ac4_ae1',
467  );
468  $variables['campos'] = $campos;
469  $ftypes = array(
470    'value' => t('January'),
471    'value_1' => t('February'),
472    'value_2' => t('March'),
473    'value_3' => t('April'),
474    'value_4' => t('May'),
475    'value_5' => t('June'),
476    'value_6' => t('July'),
477    'value_7' => t('August'),
478    'value_8' => t('September'),
479    'value_9' => t('Octuber'),
480    'value_10' => t('November'),
481    'value_11' => t('December'),
482  );
483  $variables['ftypes'] = $ftypes;
484  $valores = array();
485  foreach($ftypes as $id_field => $texto) {
486    $valores[$id_field] = 0;
487
488  }
489  $partidas_nodo = array();
490  foreach ($campos as $id) {
491    if (count($accion->{$id})) {
492      foreach($accion->{$id} as $partida) {
493        if(!empty($partida['tid'])) {
494          $partidas_nodo[$id][$partida['tid']] = $partida['tid'];
495        }
496      }
497    }
498  }
499  if (count($variaciones)) {
500    foreach($variaciones as $field_l => $partidas) {
501      if (count($partidas)) {
502        foreach($partidas as $tid => $partida) {
503          if (!isset($partidas_nodo[$field_l][$tid])) {
504            $valores['tid'] = $tid;
505            $accion->{$field_l}[] = $valores;
506            $partidas_nodo[$field_l][$tid] = $tid;
507          }
508        }
509      }
510    }
511  }
512  if (count($reformula)) {
513    foreach($reformula as $field_l => $partidas) {
514      if (count($partidas)) {
515        foreach($partidas as $tid => $partida) {
516          if (!isset($partidas_nodo[$field_l][$tid])) {
517            $valores['tid'] = $tid;
518            $accion->{$field_l}[] = $valores;
519            $partidas_nodo[$field_l][$tid] = $tid;
520          }
521        }
522      }
523    }
524  }
525  $fields_title = array();
526  foreach ($campos as $id) {
527    $field_load = content_fields($id, 'accion_centralizada');
528    $fields_title[$id] = $field_load['widget']['label'];
529  }
530  $variables['fields_title'] = $fields_title;
531  $variables['accion'] = $accion;
532  $historys = array();
533  $states = array();
534  if (module_exists('workflow')) {
535    $states = _acciones_centralizadas_reformula_obtiene_estados();
536    $result = db_query('SELECT re.*, u.name, u.uid FROM {accion_reformular_state} re INNER JOIN {users} u ON u.uid = re.uid WHERE nid = %d AND id_ref = %d ORDER BY date DESC', $accion->nid, $id_ref);
537    while($history = db_fetch_object($result)) {
538      $historys[] = $history;
539    }
540  }
541  $variables['historys'] = $historys;
542  $variables['states'] = $states;
543  $partida_nombre = array();
544  foreach ($campos as $id) {
545    if (count($accion->{$id})) {
546      foreach($accion->{$id} as $partida) {
547        if(!empty($partida['tid'])) {
548          $term = taxonomy_get_term($partida['tid']);
549          $partida_nombre[$partida['tid']] = $term->name;
550        }
551      }
552    }
553  }
554  $variables['partida_nombre'] = $partida_nombre;
555}
556
557
558
559
560function _sipp_pdf_seguimiento_accioncent($node) {
561  $pdf = _sipp_pdf_pdf_init();
562  $html = theme('accioncent_seguimiento_pdf', $node);
563  if ($pdf) {
564    $title = t('Acciones Centralizada');
565    $pdf->SetTitle($title);
566    $pdf->SetSubject($title);
567    $pdf->writeHTML($html, true, false, true, false, '');
568    $pdf->lastPage();
569    header('Content-type: text/plain');
570    $name = 'acciones_centralizada_' . $node->nid . '_seguimiento.pdf';
571    header('Content-Disposition: attachment; filename="' . $name . '"');
572    print $pdf->Output($name, 'I');
573    exit();
574  }
575  else {
576    return $html;
577  }
578}
579
580
581
582
583function template_preprocess_accioncent_seguimiento_pdf(&$variables) {
584  $accion = $variables['accion'];
585  $ente_planificador = node_load($accion->field_acciones_ente[0]['nid']);
586  $variables['ente_planificador'] = $ente_planificador;
587  $reformulacion_load = $variables['reformulacion_load'];
588  $year = variable_get('acciones_centralizadas_anho_seguimiento', 0);
589  $variables['year'] = $year;
590  $mes_segu = variable_get('acciones_centralizadas_mes_seguimiento', 0);
591  $variables['mes_segu'] = $mes_segu;
592  $output = '';
593  $ftypes = array(
594    'value' => t('January'),
595    'value_1' => t('February'),
596    'value_2' => t('March'),
597    'value_3' => t('April'),
598    'value_4' => t('May'),
599    'value_5' => t('June'),
600    'value_6' => t('July'),
601    'value_7' => t('August'),
602    'value_8' => t('September'),
603    'value_9' => t('Octuber'),
604    'value_10' => t('November'),
605    'value_11' => t('December'),
606  );
607  $variables['ftypes'] = $ftypes;
608  $id_ref = $reformulacion_load ? $reformulacion_load->id_ref : 0;
609  $variaciones = _acciones_centralizadas_reformula_all_partidas_load($accion, $id_ref);
610  $reformula = _acciones_centralizadas_reformula_load($accion);
611  $variables['id_ref'] = $id_ref;
612  $variables['reformula'] = $reformula;
613  $variables['variaciones'] = $variaciones;
614  $actual = array();
615  $meses = array(
616    0 => t('January'),
617    1 => t('February'),
618    2 => t('March'),
619    3 => t('April'),
620    4 => t('May'),
621    5 => t('June'),
622    6 => t('July'),
623    7 => t('August'),
624    8 => t('September'),
625    9 => t('Octuber'),
626    10 => t('November'),
627    11 => t('December'),
628  );
629  $variables['meses'] = $meses;
630  $campos = array(
631    'field_ac_ac1_ae1' => 'field_ac_ac1_ae1',
632    'field_ac_ac1_ae2' => 'field_ac_ac1_ae2',
633    'field_ac_ac2_ae2' => 'field_ac_ac2_ae2',
634    'field_ac_ac2_ae3' => 'field_ac_ac2_ae3',
635    'field_ac_ac3_ae1' => 'field_ac_ac3_ae1',
636    'field_ac_ac4_ae1' => 'field_ac_ac4_ae1',
637  );
638  $variables['campos'] = $campos;
639  $valores = array();
640  foreach($ftypes as $id_field => $texto) {
641    $valores[$id_field] = 0;
642
643  }
644  $partidas_nodo = array();
645  $campos_f = array();
646  foreach ($campos as $id) {
647    $field_load = content_fields($id, 'accion_centralizada');
648    $campos_f[$id] = $field_load;
649    if (!$accion->{$id}[0]['tid']) {
650      $accion->{$id} = array();
651    }
652    if (count($accion->{$id})) {
653      foreach($accion->{$id} as $partida) {
654        if(!empty($partida['tid'])) {
655          $partidas_nodo[$id][$partida['tid']] = $partida['tid'];
656        }
657      }
658    }
659  }
660  $variables['campos_f'] = $campos_f;
661  if (count($variaciones)) {
662    foreach($variaciones as $field_l => $partidas) {
663      if (count($partidas)) {
664        foreach($partidas as $tid => $partida) {
665          if (!isset($partidas_nodo[$field_l][$tid])) {
666            if (empty($accion->{$field_l}[0]['tid']) || !$accion->{$field_l}[0]['tid']) {
667              $accion->{$field_l} = array();
668            }
669            $valores['tid'] = $tid;
670            $accion->{$field_l}[] = $valores;
671            $partidas_nodo[$field_l][$tid] = $tid;
672          }
673        }
674      }
675    }
676  }
677  if (count($reformula)) {
678    foreach($reformula as $field_l => $partidas) {
679      if (count($partidas)) {
680        foreach($partidas as $tid => $partida) {
681          if (!isset($partidas_nodo[$field_l][$tid])) {
682            if (empty($accion->{$field_l}[0]['tid']) || !$accion->{$field_l}[0]['tid']) {
683              $accion->{$field_l} = array();
684            }
685            $valores['tid'] = $tid;
686            $accion->{$field_l}[] = $valores;
687            $partidas_nodo[$field_l][$tid] = $tid;
688          }
689        }
690      }
691    }
692  }
693  foreach($meses as $mes => $nombre) {
694    $valor = $mes > 0 ? 'value_' . $mes : 'value';
695    foreach($campos as $ids) {
696      $actualP = _acciones_centralizadas_seguimiento_load($accion, $ids, $mes);
697      $mensajes[$ids][$valor] =  $actualP['values'];
698      if (isset($actualP['comprometido'][$ids])) {
699        foreach($actualP['comprometido'][$ids] as $tid => $value) {
700          $actual['comprometido'][$ids][$tid][$valor] = $value[$valor];
701        }
702        foreach($actualP['pagado'][$ids] as $tid => $value) {
703          $actual['pagado'][$ids][$tid][$valor] = $value[$valor];
704        }
705        foreach($actualP['causado'][$ids] as $tid => $value) {
706          $actual['causado'][$ids][$tid][$valor] = $value[$valor];
707        }
708      }
709    }
710  }
711  $variables['mensajes'] = $mensajes;
712  $variables['actual'] = $actual;
713  $comprometido = isset($actual['comprometido']) ? $actual['comprometido'] : array();
714  $causado = isset($actual['causado']) ? $actual['causado'] : array();
715  $pagado = isset($actual['pagado']) ? $actual['pagado'] : array();
716  $variables['comprometido'] = $comprometido;
717  $variables['causado'] = $causado;
718  $variables['pagado'] = $pagado;
719  $grupos = fieldgroup_groups('accion_centralizada');
720  $variables['grupos'] = $grupos;
721  $colores = array();
722  $colores[0] = array(
723    'texto' => variable_get('acciones_centralizadas_texto_default', 'No hay planificación'),
724    'tcolor' => variable_get('acciones_centralizadas_colort_default', '#FFFFFF'),
725    'color' => variable_get('acciones_centralizadas_color_default', '#633303'),
726  );
727  $colores[1] = array(
728    'texto' => variable_get('acciones_centralizadas_texto_critica', 'Zona crítica'),
729    'tcolor' => variable_get('acciones_centralizadas_colort_critica', '#FFFFFF'),
730    'color' => variable_get('acciones_centralizadas_color_critica', '#fd0002'),
731  );
732  $colores[2] = array(
733    'texto' => variable_get('acciones_centralizadas_texto_discreta', 'Zona discreta'),
734    'tcolor' => variable_get('acciones_centralizadas_colort_discreta', '#FFFFFF'),
735    'color' => variable_get('acciones_centralizadas_color_discreta', '#cc6733'),
736  );
737  $colores[3] = array(
738    'texto' => variable_get('acciones_centralizadas_texto_moderada', 'Zona moderada'),
739    'tcolor' => variable_get('acciones_centralizadas_colort_moderada', '#000000'),
740    'color' => variable_get('acciones_centralizadas_color_moderada', '#fdff00'),
741  );
742  $colores[4] = array(
743    'texto' => variable_get('acciones_centralizadas_texto_optima', 'Zona optima'),
744    'tcolor' => variable_get('acciones_centralizadas_colort_optima', '#000000'),
745    'color' => variable_get('acciones_centralizadas_color_optima', '#20ff21'),
746  );
747  $colores[5] = array(
748    'texto' => variable_get('acciones_centralizadas_texto_sejecucion', 'Sobre ejecución'),
749    'tcolor' => variable_get('acciones_centralizadas_colort_sejecucion', '#000000'),
750    'color' => variable_get('acciones_centralizadas_color_sejecucion', '#9966cd'),
751  );
752  $variables['colores'] = $colores;
753  $variables['accion'] = $accion;
754}
755
756
757function _sipp_pdf_seguimiento_ver_campos_accioncent($node, $campo = '', $mes = 0) {
758  $pdf = _sipp_pdf_pdf_init();
759  $meses = array(
760    0 => t('January'),
761    1 => t('February'),
762    2 => t('March'),
763    3 => t('April'),
764    4 => t('May'),
765    5 => t('June'),
766    6 => t('July'),
767    7 => t('August'),
768    8 => t('September'),
769    9 => t('Octuber'),
770    10 => t('November'),
771    11 => t('December'),
772  );
773  $html = theme('accioncent_seguimiento_ver_campos_pdf', $node, $campo, $mes);
774  if ($pdf) {
775    $title = t('Acciones Centralizada para el mes: #mes_load', array('#mes_load' => $meses[$mes]));
776    $pdf->SetTitle($title);
777    $pdf->SetSubject($title);
778    $pdf->writeHTML($html, true, false, true, false, '');
779    $pdf->lastPage();
780    header('Content-type: text/plain');
781    $name = 'acciones_centralizada_' . $node->nid . '_seguimiento.pdf';
782    header('Content-Disposition: attachment; filename="' . $name . '"');
783    print $pdf->Output($name, 'I');
784    exit();
785  }
786  else {
787    return $html;
788  }
789}
790
791function template_preprocess_accioncent_seguimiento_ver_campos_pdf(&$variables) {
792  $campo = $variables['campo'];
793  $node = $variables['accion'];
794
795  $mes = $variables['mes'];
796  $variables['campo'] = $campo;
797  $ente_planificador = node_load($node->field_acciones_ente[0]['nid']);
798  $variables['ente_planificador'] = $ente_planificador;
799  $year = variable_get('acciones_centralizadas_anho_creacion', 0);
800  $variables['year'] = $year;
801  $meses = array(
802    0 => t('January'),
803    1 => t('February'),
804    2 => t('March'),
805    3 => t('April'),
806    4 => t('May'),
807    5 => t('June'),
808    6 => t('July'),
809    7 => t('August'),
810    8 => t('September'),
811    9 => t('Octuber'),
812    10 => t('November'),
813    11 => t('December'),
814  );
815  $ftypes = array(
816    'value' => t('January'),
817    'value_1' => t('February'),
818    'value_2' => t('March'),
819    'value_3' => t('April'),
820    'value_4' => t('May'),
821    'value_5' => t('June'),
822    'value_6' => t('July'),
823    'value_7' => t('August'),
824    'value_8' => t('September'),
825    'value_9' => t('Octuber'),
826    'value_10' => t('November'),
827    'value_11' => t('December'),
828  );
829  $variables['meses'] = $meses;
830  $variables['ftypes'] = $ftypes;
831  $id_ref = 0;
832  $variaciones = _acciones_centralizadas_reformula_all_partidas_load($node, $id_ref);
833  $reformula = _acciones_centralizadas_reformula_load($node);
834  $variables['id_ref'] = $id_ref;
835  $variables['variaciones'] = $variaciones;
836  $variables['reformula'] = $reformula;
837  $campos = array(
838    'field_ac_ac1_ae1',
839    'field_ac_ac1_ae2',
840    'field_ac_ac2_ae2',
841    'field_ac_ac2_ae3',
842    'field_ac_ac3_ae1',
843    'field_ac_ac4_ae1',
844  );
845  $valores = array();
846  foreach($ftypes as $id_field => $texto) {
847    $valores[$id_field] = 0;
848  }
849  $partidas_nodo = array();
850  foreach ($campos as $id) {
851    if (count($node->{$id})) {
852      foreach($node->{$id} as $partida) {
853        if(!empty($partida['tid'])) {
854          $partidas_nodo[$id][$partida['tid']] = $partida['tid'];
855        }
856      }
857    }
858  }
859  if (count($variaciones)) {
860    foreach($variaciones as $field_l => $partidas) {
861      if (count($partidas)) {
862        foreach($partidas as $tid => $partida) {
863          if (!isset($partidas_nodo[$field_l][$tid])) {
864            $valores['tid'] = $tid;
865            $node->{$field_l}[] = $valores;
866            if ($field_l == $campo['field']) {
867              $campo['values'][] = $valores;
868            }
869          }
870        }
871      }
872    }
873  }
874  if (count($reformula)) {
875    foreach($reformula as $field_l => $partidas) {
876      if (count($partidas)) {
877        foreach($partidas as $tid => $partida) {
878          if (!isset($partidas_nodo[$field_l][$tid])) {
879            $valores['tid'] = $tid;
880            $node->{$field_l}[] = $valores;
881            if ($field_l == $campo['field']) {
882              $campo['values'][] = $valores;
883            }
884          }
885        }
886      }
887    }
888  }
889  $actual = _acciones_centralizadas_seguimiento_load($node, $campo['field'], $mes);
890  $comprometido = isset($actual['comprometido']) ? $actual['comprometido'] : array();
891  $causado = isset($actual['causado']) ? $actual['causado'] : array();
892  $pagado = isset($actual['pagado']) ? $actual['pagado'] : array();
893  $variables['actual'] = $actual;
894  $variables['comprometido'] = $comprometido;
895  $variables['causado'] = $causado;
896  $variables['pagado'] = $pagado;
897  $grupos = fieldgroup_groups('accion_centralizada');
898  $variables['grupos'] = $grupos;
899  $field_load = content_fields($campo['field'], 'accion_centralizada');
900  $variables['field_load'] = $field_load;
901  $colores = array();
902  $colores[0] = array(
903    'texto' => variable_get('acciones_centralizadas_texto_default', 'No hay planificación'),
904    'tcolor' => variable_get('acciones_centralizadas_colort_default', '#FFFFFF'),
905    'color' => variable_get('acciones_centralizadas_color_default', '#633303'),
906  );
907  $colores[1] = array(
908    'texto' => variable_get('acciones_centralizadas_texto_critica', 'Zona crítica'),
909    'tcolor' => variable_get('acciones_centralizadas_colort_critica', '#FFFFFF'),
910    'color' => variable_get('acciones_centralizadas_color_critica', '#fd0002'),
911  );
912  $colores[2] = array(
913    'texto' => variable_get('acciones_centralizadas_texto_discreta', 'Zona discreta'),
914    'tcolor' => variable_get('acciones_centralizadas_colort_discreta', '#FFFFFF'),
915    'color' => variable_get('acciones_centralizadas_color_discreta', '#cc6733'),
916  );
917  $colores[3] = array(
918    'texto' => variable_get('acciones_centralizadas_texto_moderada', 'Zona moderada'),
919    'tcolor' => variable_get('acciones_centralizadas_colort_moderada', '#000000'),
920    'color' => variable_get('acciones_centralizadas_color_moderada', '#fdff00'),
921  );
922  $colores[4] = array(
923    'texto' => variable_get('acciones_centralizadas_texto_optima', 'Zona optima'),
924    'tcolor' => variable_get('acciones_centralizadas_colort_optima', '#000000'),
925    'color' => variable_get('acciones_centralizadas_color_optima', '#20ff21'),
926  );
927  $colores[5] = array(
928    'texto' => variable_get('acciones_centralizadas_texto_sejecucion', 'Sobre ejecución'),
929    'tcolor' => variable_get('acciones_centralizadas_colort_sejecucion', '#000000'),
930    'color' => variable_get('acciones_centralizadas_color_sejecucion', '#9966cd'),
931  );
932  $variables['colores'] = $colores;
933  $partidas_nombre = array();
934  foreach ($campo['values'] as $partida) {
935    if ($partida['tid']) {
936      $term = taxonomy_get_term($partida['tid']);
937      // If this term's vocabulary supports localization.
938      if (module_exists('i18ntaxonomy') && i18ntaxonomy_vocabulary($term->vid) == I18N_TAXONOMY_LOCALIZE) {
939        $term->name = t("taxonomy:term:$term->tid:name", $term->name);
940      }
941    $partidas_nombre[$partida['tid']] = $term->name;
942    }
943  }
944  $variables['partidas_nombre'] = $partidas_nombre;
945  $variables['accion'] = $node;
946  $variables['campo'] = $campo;
947  $grupos_fields = array();
948  foreach($grupos as $id => $grupo) {
949    if (count($grupo['fields'])) {
950      foreach($grupo['fields'] as $id_field => $field) {
951        if ($id_field == $campo['field']) {
952          $grupos_fields = $grupos[$id];
953        }
954      }
955    }
956  }
957  $variables['grupos_fields'] = $grupos_fields;
958  $historys = array();
959  $states = array();
960  if (module_exists('workflow')) {
961    $cid_seg = isset($actual['values']) && isset($actual['values']['id_seg']) ? $actual['values']['id_seg'] : 0;
962    $states = _acciones_centralizadas_reformula_obtiene_estados();
963    if ($cid_seg) {
964      $result = db_query('SELECT re.*, u.name, u.uid FROM {accion_seguimiento_state} re INNER JOIN {users} u ON u.uid = re.uid WHERE nid = %d AND id_seg = %d ORDER BY date DESC', $node->nid, $cid_seg);
965      while($history = db_fetch_object($result)) {
966        $historys[] = $history;
967      }
968    }
969  }
970  $variables['states'] = $states;
971  $variables['historys'] = $historys;
972  $variables['estado_aprobado'] = variable_get('acciones_centralizadas_state_aprobado', NULL);
973  $variables['estado_naprobado']= variable_get('acciones_centralizadas_state_naprobado', NULL);
974  $variables['current_estado']= isset($actual['values']) && isset($actual['values']['estado']) ? $actual['values']['estado'] : -1;
975  $variables['cid_seg']= isset($actual['values']) && isset($actual['values']['id_seg']) ? $actual['values']['id_seg'] : 0;
976  $variables['grupo'] = explode('-', $grupos_fields['label']);
977}
978
979
980
981function _sipp_pdf_accionesp_ver_pdf($ac) {
982  $pdf = _sipp_pdf_pdf_init();
983  $html = theme('accioncent_ver_pdf', $ac);
984  if ($pdf) {
985    $title = t('Acción Centralizada : @ac', array('@proyecto' => check_plain($ac->title)));
986    $pdf->SetTitle($title);
987    $pdf->SetSubject($title);
988    $pdf->writeHTML($html, true, false, true, false, '');
989    $pdf->lastPage();
990    header('Content-type: text/plain');
991    $name = 'accion_centralizada_' . $ac->nid . '.pdf';
992    header('Content-Disposition: attachment; filename="' . $name . '"');
993    print $pdf->Output($name, 'I');
994    exit();
995  }
996  else {
997    return $html;
998  }
999}
1000
1001
1002
1003function _sipp_pdf_proyecto_campos_pdf($node) {
1004  $pdf = _sipp_pdf_pdf_init();
1005  $html = theme('proyecto_campos_ver_pdf', $node, $_SESSION['proyectos_operativos_mostrar_campos']);
1006  if ($pdf) {
1007    $title = t('Proyecto Operativo : @title', array('@title' => check_plain($node->title)));
1008    $pdf->SetTitle($title);
1009    $pdf->SetSubject($title);
1010    $pdf->writeHTML($html, true, false, true, false, '');
1011    $pdf->lastPage();
1012    header('Content-type: text/plain');
1013    $name = 'proyecto_operativo_' . $node->nid . '.pdf';
1014    header('Content-Disposition: attachment; filename="' . $name . '"');
1015    print $pdf->Output($name, 'I');
1016    exit();
1017  }
1018  else {
1019    return $html;
1020  }
1021}
1022
1023function _sipp_pdf_datosaeview($ae) {
1024  $pdf = _sipp_pdf_pdf_init();
1025  $html = node_view($ae);
1026  if ($pdf) {
1027    $title = t('Acción Específica : @ae', array('@proyecto' => check_plain($ae->title)));
1028    $pdf->SetTitle($title);
1029    $pdf->SetSubject($title);
1030    $pdf->writeHTML($html, true, false, true, false, '');
1031    $pdf->lastPage();
1032    header('Content-type: text/plain');
1033    $name = 'accion_especifica_' . $ae->nid . '.pdf';
1034    header('Content-Disposition: attachment; filename="' . $name . '"');
1035    print $pdf->Output($name, 'I');
1036    exit();
1037  }
1038  else {
1039    return $html;
1040  }
1041}
1042
1043function _sipp_pdf_datosaelist($node) {
1044  $pdf = _sipp_pdf_pdf_init();
1045  $html = theme('proyectos_operativos_datos_ae_list_pdf', $node);
1046  if ($pdf) {
1047    $title = t('Acciones Específicas del Proyecto: @proyecto', array('@proyecto' => check_plain($node->title)));
1048    $pdf->SetTitle($title);
1049    $pdf->SetSubject($title);
1050    $pdf->writeHTML($html, true, false, true, false, '');
1051    $pdf->lastPage();
1052    header('Content-type: text/plain');
1053    $name = 'acciones_especificas_' . $node->nid . '.pdf';
1054    header('Content-Disposition: attachment; filename="' . $name . '"');
1055    print $pdf->Output($name, 'I');
1056    exit();
1057  }
1058  else {
1059    return $html;
1060  }
1061}
1062
1063function template_preprocess_proyectos_operativos_datos_ae_list_pdf(&$variables) {
1064  $proyecto = $variables['proyecto'];
1065  $acciones_especificas = array();
1066  foreach($proyecto->field_proyecto_accion_esp as $accion) {
1067    if ($accion['nid'] && $nid != $accion['nid']) {
1068      $accion_load = node_load($accion['nid']);
1069      if ($accion_load && $accion_load->type == 'accion_especifica') {
1070        $acciones_especificas[$accion_load->nid] = $accion_load;
1071        $ejecucion += $accion_load->field_accion_esp_ponderacion[0]['value'];
1072      }
1073    }
1074    elseif($nid = $accion['nid']) {
1075      $acciones_especificas[$ae->nid] = $ae;
1076    }
1077  }
1078  $variables['acciones_especificas'] = $acciones_especificas;
1079  $ente_planificador = node_load($proyecto->field_proyecto_ente[0]['nid']);
1080  $variables['ente_planificador'] = $ente_planificador;
1081}
1082
1083
1084function _sipp_pdf_datosfinancierosview($node) {
1085  $pdf = _sipp_pdf_pdf_init();
1086  $html = theme('proyectos_operativos_datos_financieros_pdf', $node);
1087  if ($pdf) {
1088    $title = t('Datos Financieros del Proyecto: @proyecto', array('@proyecto' => check_plain($node->title)));
1089    $pdf->SetTitle($title);
1090    $pdf->SetSubject($title);
1091    $pdf->writeHTML($html, true, false, true, false, '');
1092    $pdf->lastPage();
1093    header('Content-type: text/plain');
1094    $name = 'datosfinancieros_' . $node->nid . '.pdf';
1095    header('Content-Disposition: attachment; filename="' . $name . '"');
1096    print $pdf->Output($name, 'I');
1097    exit();
1098  }
1099  else {
1100    return $html;
1101  }
1102}
1103
1104function template_preprocess_proyectos_operativos_datos_financieros_pdf(&$variables) {
1105  global $user;
1106  $proyecto = $variables['proyecto'];
1107  $ejecucion = 0;
1108  $acciones_especificas = array();
1109  $arreglo_anual = array();
1110  $arreglo_partida = array();
1111  $titles = array();
1112  $partidas = array();
1113  $node_type = content_types('accion_especifica');
1114  $fields = $node_type['fields'];
1115  $title = array();
1116  $title['ordinarios'] = t('Recursos Ordinarios');
1117  $fields_financiamiento = array();
1118  $fields_financiamiento['ordinarios'] = array();
1119  $titulos_campos = array();
1120  $valores = array();
1121  $campos = array();
1122  $arreglo = array(
1123    'field_accion_esp_transferencias' => 'field_accion_esp_transferencias',
1124    'field_accion_esp_creditosa' => 'field_accion_esp_creditosa',
1125    'field_accion_esp_mcti' => 'field_accion_esp_mcti',
1126  );
1127  if (is_array($fields) && count($fields)) {
1128    foreach($fields as $field_id => $field) {
1129      if (array_key_exists($field_id, $arreglo)) {
1130        $fields_financiamiento['ordinarios'][] = $field_id;
1131        $valores[$field_id] = 0;
1132        $campos[] = $field_id;
1133        $titulos_campos[$field_id] = $field['widget']['label'];
1134      }
1135      elseif (variable_get('proyectos_operativos_ac_fo_' . $field_id, FALSE)) {
1136        $fields_financiamiento['ordinarios'][] = $field_id;
1137        $valores[$field_id] = 0;
1138        $campos[] = $field_id;
1139        $titulos_campos[$field_id] = $field['widget']['label'];
1140      }
1141    }
1142  }
1143  $title['propios'] = t('Recursos Propios');
1144  $fields_financiamiento['propios'] = array();
1145  $arreglo = array(
1146    'field_accion_esp_venta_act' => 'field_accion_esp_venta_act',
1147    'field_accion_esp_activos' => 'field_accion_esp_activos',
1148    'field_accion_esp_flujocaja' => 'field_accion_esp_flujocaja',
1149    'field_accion_esp_ventapro' => 'field_accion_esp_ventapro',
1150  );
1151  if (is_array($fields) && count($fields)) {
1152    foreach($fields as $field_id => $field) {
1153      if (array_key_exists($field_id, $arreglo)) {
1154        $fields_financiamiento['propios'][] = $field_id;
1155        $valores[$field_id] = 0;
1156        $campos[] = $field_id;
1157        $titulos_campos[$field_id] = $field['widget']['label'];
1158      }
1159      elseif (variable_get('proyectos_operativos_ac_fp_' . $field_id, FALSE)) {
1160        $fields_financiamiento['propios'][] = $field_id;
1161        $valores[$field_id] = 0;
1162        $campos[] = $field_id;
1163        $titulos_campos[$field_id] = $field['widget']['label'];
1164      }
1165    }
1166  }
1167  $title['transferencias'] = t('Transferencias');
1168  $fields_financiamiento['transferencias'] = array();
1169  $arreglo = array(
1170    'field_accion_esp_donaciones' => 'field_accion_esp_donaciones',
1171  );
1172  if (is_array($fields) && count($fields)) {
1173    foreach($fields as $field_id => $field) {
1174      if (array_key_exists($field_id, $arreglo)) {
1175        $fields_financiamiento['transferencias'][] = $field_id;
1176        $valores[$field_id] = 0;
1177        $campos[] = $field_id;
1178        $titulos_campos[$field_id] = $field['widget']['label'];
1179      }
1180      elseif (variable_get('proyectos_operativos_ac_fd_' . $field_id, FALSE)) {
1181        $fields_financiamiento['transferencias'][] = $field_id;
1182        $valores[$field_id] = 0;
1183        $campos[] = $field_id;
1184        $titulos_campos[$field_id] = $field['widget']['label'];
1185      }
1186    }
1187  }
1188  $title['otros'] = t('Otros');
1189  $fields_financiamiento['otros'] = array();
1190  $arreglo = array(
1191    'field_accion_esp_gobernacion' => 'field_accion_esp_gobernacion',
1192    'field_accion_esp_misionc' => 'field_accion_esp_misionc',
1193    'field_accion_esp_bid_fona' => 'field_accion_esp_bid_fona',
1194    'field_accion_esp_fonacit' => 'field_accion_esp_fonacit',
1195    'field_accion_esp_fonden' => 'field_accion_esp_fonden',
1196    'field_accion_esp_locti' => 'field_accion_esp_locti',
1197    'field_accion_esp_fondoidi' => 'field_accion_esp_fondoidi',
1198    'field_accion_esp_capitalrie' => 'field_accion_esp_capitalrie',
1199    'field_accion_esp_infocentro' => 'field_accion_esp_infocentro',
1200    'field_accion_esp_fidetel' => 'field_accion_esp_fidetel',
1201  );
1202  if (is_array($fields) && count($fields)) {
1203    foreach($fields as $field_id => $field) {
1204      if (array_key_exists($field_id, $arreglo)) {
1205        $fields_financiamiento['otros'][] = $field_id;
1206        $valores[$field_id] = 0;
1207        $campos[] = $field_id;
1208        $titulos_campos[$field_id] = $field['widget']['label'];
1209      }
1210      elseif (variable_get('proyectos_operativos_ac_fo_' . $field_id, FALSE)) {
1211        $fields_financiamiento['otros'][] = $field_id;
1212        $valores[$field_id] = 0;
1213        $campos[] = $field_id;
1214        $titulos_campos[$field_id] = $field['widget']['label'];
1215      }
1216    }
1217  }
1218  $variables['fields_financiamiento'] = $fields_financiamiento;
1219  $variables['campos'] = $campos;
1220  $variables['titulos_campos'] = $titulos_campos;
1221  foreach($proyecto->field_proyecto_accion_esp as $accion) {
1222    if ($accion['nid']) {
1223      $accion_load = node_load($accion['nid']);
1224      if ($accion_load && $accion_load->type == 'accion_especifica') {
1225        foreach($campos as $field) {
1226          $valores[$field] += $accion_load->{$field}[0]['value'];
1227        }
1228        $titles[$accion_load->nid] = $accion_load->title;
1229        $acciones_especificas[$accion_load->nid] = $accion_load;
1230        $ejecucion += $accion_load->field_accion_esp_ponderacion[0]['value'];
1231        foreach($accion_load->field_accion_esp_programacion as $accion) {
1232          if ($accion['tid']) {
1233            $partidas[$accion['tid']] = $accion['tid'];
1234            for ($i = 0; $i < 12; $i++) {
1235              $valor = $i ? 'value_' . $i : 'value';
1236              if (!isset($arreglo_partida[$accion_load->nid][$accion['tid']])) {
1237                $arreglo_partida[$accion_load->nid][$accion['tid']] = 0;
1238              }
1239              if (!isset($arreglo_anual[$accion_load->nid][$valor])) {
1240                $arreglo_anual[$accion_load->nid][$valor] = 0;
1241              }
1242              $arreglo_partida[$accion_load->nid][$accion['tid']] += $accion[$valor];
1243              $arreglo_anual[$accion_load->nid][$valor] += $accion[$valor];
1244            }
1245          }
1246        }
1247      }
1248    }
1249  }
1250  $variables['valores'] = $valores;
1251  $variables['arreglo_anual'] = $arreglo_anual;
1252  $variables['arreglo_partida'] = $arreglo_partida;
1253  $variables['partidas'] = $partidas;
1254  $variables['titles'] = $titles;
1255  $ftypes = array(
1256    'value' => t('ENE'),
1257    'value_1' => t('FEB'),
1258    'value_2' => t('MAR'),
1259    'value_3' => t('ABR'),
1260    'value_4' => t('MAY'),
1261    'value_5' => t('JUN'),
1262    'value_6' => t('JUL'),
1263    'value_7' => t('AGO'),
1264    'value_8' => t('SEP'),
1265    'value_9' => t('OCT'),
1266    'value_10' => t('NOV'),
1267    'value_11' => t('DEC'),
1268  );
1269  $variables['ftypes'] = $ftypes;
1270
1271  $partidas_nombres = array();
1272  foreach($partidas as $valor) {
1273    $term = taxonomy_get_term($valor);
1274    // If this term's vocabulary supports localization.
1275    if (module_exists('i18ntaxonomy') && i18ntaxonomy_vocabulary($term->vid) == I18N_TAXONOMY_LOCALIZE) {
1276      $term->name = tt("taxonomy:term:$term->tid:name", $term->name);
1277    }
1278    $partidas_nombres[$valor] = $term->name;
1279  }
1280  $variables['partidas_nombres'] = $partidas_nombres;
1281}
1282
1283function _proyectos_reformulacion_reformula_list_pdf($node) {
1284  $pdf = _sipp_pdf_pdf_init();
1285  $html = theme('proyectos_reformulacion_reformula_obtiene_list_pdf', $node);
1286  if ($pdf) {
1287    $title = t('Reformulaciones Proyecto: @proyecto', array('@proyecto' => check_plain($node->title)));
1288    $pdf->SetTitle($title);
1289    $pdf->SetSubject($title);
1290    $pdf->writeHTML($html, true, false, true, false, '');
1291    $pdf->lastPage();
1292    header('Content-type: text/plain');
1293    $name = 'reformulaciones_' . $node->nid . '.pdf';
1294    header('Content-Disposition: attachment; filename="' . $name . '"');
1295    print $pdf->Output($name, 'I');
1296    exit();
1297  }
1298  else {
1299    return $html;
1300  }
1301}
1302
1303/*
1304 * Implementation of _proyectos_reformulacion_reformula_obtiene_list_page()
1305 */
1306function template_preprocess_proyectos_reformulacion_reformula_obtiene_list_pdf(&$variables) {
1307  global $user;
1308  $node = $variables['proyecto'];
1309  $ente_planificador = node_load($node->field_proyecto_ente[0]['nid']);
1310  $states = _proyectos_operativos_reformulacion_obtiene_estados();
1311
1312  $estado_naprobado = variable_get('proyectos_operativos_state_naprobado', NULL);
1313  $result = db_query('SELECT re.*, u.name, u.uid FROM {proyectos_reformular} re INNER JOIN {users} u ON u.uid = re.uid WHERE nid = %d AND estado <> %d ORDER BY id_ref DESC', $node->nid, $estado_naprobado);
1314  while($reformular = db_fetch_object($result)) {
1315    $reformulaciones[] = $reformular;
1316  }
1317  $variables['reformulaciones'] = $reformulaciones;
1318  $variables['states'] = $states;
1319  $variables['ente_planificador'] = $ente_planificador;
1320}
1321
1322function _sipp_pdf_reformulaview($node, $reformulacion_load = 0) {
1323  $pdf = _sipp_pdf_pdf_init();
1324  $id_ref = $reformulacion_load ? $reformulacion_load->id_ref : 0;
1325  $reformula = _proyectos_reformulacion_load($node, $id_ref);
1326  $variaciones = _proyectos_reformula_all_partidas_load($node, $id_ref);
1327  $html = theme('proyectos_reformulacion_reformula_tab_page_pdf', $node, $reformulacion_load, $id_ref, $reformula, $variaciones);
1328  if ($pdf) {
1329    $title = t('Reformulación Proyecto: @proyecto (@date)', array('@date' => format_date($reformulacion_load->date), '@proyecto' => check_plain($node->title)));
1330    $pdf->SetTitle($title);
1331    $pdf->SetSubject($title);
1332    $pdf->writeHTML($html, true, false, true, false, '');
1333    $pdf->lastPage();
1334    header('Content-type: text/plain');
1335    $name = 'reformulacion_' . $reformulacion_load->id_ref . '.pdf';
1336    header('Content-Disposition: attachment; filename="' . $name . '"');
1337    print $pdf->Output($name, 'I');
1338    exit();
1339  }
1340  else {
1341    return $html;
1342  }
1343}
1344
1345function template_preprocess_proyectos_reformulacion_reformula_tab_page_pdf(&$variables) {
1346  global $user;
1347  $node = $variables['proyecto'];
1348  $id_ref = $variables['id_ref'];
1349  $reformula = $variables['reformula'];
1350  $variaciones = $variables['variaciones'];
1351  $ente_planificador = node_load($node->field_proyecto_ente[0]['nid']);
1352  $variables['ente_planificador'] = $ente_planificador;
1353  $field = content_fields('field_accion_esp_unidadm', 'accion_especifica');
1354  $unidadesm = array();
1355  $tree = taxonomy_get_tree($field['vid']);
1356  if ($tree) {
1357    foreach ($tree as $term) {
1358      $unidadesm[$term->tid] = $term->name;
1359    }
1360  }
1361  $variables['unidadesm'] = $unidadesm;
1362  $grupos = array();
1363  if ($node->field_proyecto_accion_esp[0]['nid']) {
1364    foreach($node->field_proyecto_accion_esp as $ae) {
1365      $grupos[$ae['nid']] = node_load($ae['nid']);
1366    }
1367  }
1368  $variables['grupos'] = $grupos;
1369  //get first state
1370  $estados = array();
1371  if (module_exists('workflow')) {
1372    $estados = _proyectos_operativos_reformulacion_obtiene_estados();
1373  }
1374  $variables['estados'] = $estados;
1375  $ftypes = array(
1376    'value' => t('January'),
1377    'value_1' => t('February'),
1378    'value_2' => t('March'),
1379    'value_3' => t('April'),
1380    'value_4' => t('May'),
1381    'value_5' => t('June'),
1382    'value_6' => t('July'),
1383    'value_7' => t('August'),
1384    'value_8' => t('September'),
1385    'value_9' => t('Octuber'),
1386    'value_10' => t('November'),
1387    'value_11' => t('December'),
1388  );
1389  $variables['ftypes'] = $ftypes;
1390  $historys = array();
1391  if (module_exists('workflow')) {
1392    $result = db_query('SELECT re.*, u.name, u.uid FROM {proyectos_reformular_state} re INNER JOIN {users} u ON u.uid = re.uid WHERE nid = %d AND id_ref = %d ORDER BY date DESC', $node->nid, $id_ref);
1393    while($history = db_fetch_object($result)) {
1394      $historys[] = $history;
1395    }
1396  }
1397  $variables['historys'] = $historys;
1398}
1399
1400function _sipp_pdf_aeview($node, $reformulacion_load = 0, $ae = 0) {
1401  $pdf = _sipp_pdf_pdf_init();
1402  $id_ref = $reformulacion_load ? $reformulacion_load->id_ref : 0;
1403  $reformula = _proyectos_reformulacion_load($node, $id_ref);
1404  $variaciones = _proyectos_reformula_all_partidas_load($node, $id_ref);
1405  $html = theme('proyectos_reformulacion_reformula_tab_ae_page_pdf', $node, $reformulacion_load, $ae, $id_ref, $reformula, $variaciones);
1406  if ($pdf) {
1407    $pdf->SetTitle('AE ' . $ae->title);
1408    $pdf->SetSubject('AE: ' . $ae->title);
1409    $pdf->writeHTML($html, true, false, true, false, '');
1410    $pdf->lastPage();
1411    header('Content-type: text/plain');
1412    $name = 'accionespecifica_' . $ae->nid . '.pdf';
1413    header('Content-Disposition: attachment; filename="' . $name . '"');
1414    print $pdf->Output('accionespecifica_' . $ae->nid . '.pdf', 'I');
1415    exit();
1416  }
1417  else {
1418    return $html;
1419  }
1420}
1421
1422function template_preprocess_proyectos_reformulacion_reformula_tab_ae_page_pdf(&$variables) {
1423  $id_ref = $variables['id_ref'];
1424  $reformula = $variables['reformula'];
1425  $variaciones = $variables['variaciones'];
1426  $proyecto = $variables['proyecto'];
1427  $ente_planificador = node_load($proyecto->field_proyecto_ente[0]['nid']);
1428  $variables['ente_planificador'] = $ente_planificador;
1429  $ftypes = array(
1430    'value' => t('January'),
1431    'value_1' => t('February'),
1432    'value_2' => t('March'),
1433    'value_3' => t('April'),
1434    'value_4' => t('May'),
1435    'value_5' => t('June'),
1436    'value_6' => t('July'),
1437    'value_7' => t('August'),
1438    'value_8' => t('September'),
1439    'value_9' => t('Octuber'),
1440    'value_10' => t('November'),
1441    'value_11' => t('December'),
1442  );
1443  $variables['ftypes'] = $ftypes;
1444  $ae = $variables['ae'];
1445  $partidas_nodo = array();
1446  foreach ($ae->field_accion_esp_programacion as $partida) {
1447    if(!empty($partida['tid'])) {
1448      $partidas_nodo[$partida['tid']] = $partida;
1449    }
1450  }
1451  $variables['partidas_nodo'] = $partidas_nodo;
1452  $field = content_fields('field_accion_esp_programacion', 'accion_especifica');
1453  $tree = taxonomy_get_tree($field['vid']);
1454  $vtid = $field['vtid'];
1455  $partidas = array();
1456  if ($tree) {
1457    foreach ($tree as $term) {
1458      if (isset($vtid[$term->tid])) {
1459        $partidas[$term->tid] = $term->name;
1460      }
1461    }
1462  }
1463  $variables['partidas'] = $partidas;
1464  $arreglo = array();
1465  $titles = array(
1466    'ordinarios' => t('Recursos Ordinarios'),
1467    'propios' => t('Recursos Propios'),
1468    'transferencias' => t('Donaciones'),
1469    'otros' => t('Otros'),
1470  );
1471  $titles_field = array(
1472    'field_accion_esp_transferencias' => t('Recursos Ordinarios'),
1473    'field_accion_esp_creditosa' => t('Recursos Propios'),
1474    'transferencias' => t('Donaciones'),
1475    'otros' => t('Otros'),
1476  );
1477  $variables['titles_field'] = $titles_field;
1478
1479  $arreglo['ordinarios'] = array(
1480    'field_accion_esp_transferencias' => 'field_accion_esp_transferencias',
1481    'field_accion_esp_creditosa' => 'field_accion_esp_creditosa',
1482    'field_accion_esp_mcti' => 'field_accion_esp_mcti',
1483  );
1484  $arreglo['propios'] = array(
1485    'field_accion_esp_venta_act' => 'field_accion_esp_venta_act',
1486    'field_accion_esp_activos' => 'field_accion_esp_activos',
1487    'field_accion_esp_flujocaja' => 'field_accion_esp_flujocaja',
1488    'field_accion_esp_ventapro' => 'field_accion_esp_ventapro',
1489  );
1490  $arreglo['transferencias'] = array(
1491    'field_accion_esp_donaciones' => 'field_accion_esp_donaciones',
1492  );
1493  $arreglo['otros'] = array(
1494    'field_accion_esp_gobernacion' => 'field_accion_esp_gobernacion',
1495    'field_accion_esp_misionc' => 'field_accion_esp_misionc',
1496    'field_accion_esp_bid_fona' => 'field_accion_esp_bid_fona',
1497    'field_accion_esp_fonacit' => 'field_accion_esp_fonacit',
1498    'field_accion_esp_fonden' => 'field_accion_esp_fonden',
1499    'field_accion_esp_locti' => 'field_accion_esp_locti',
1500    'field_accion_esp_fondoidi' => 'field_accion_esp_fondoidi',
1501    'field_accion_esp_capitalrie' => 'field_accion_esp_capitalrie',
1502    'field_accion_esp_infocentro' => 'field_accion_esp_infocentro',
1503    'field_accion_esp_fidetel' => 'field_accion_esp_fidetel',
1504  );
1505  $variables['arreglo'] = $arreglo;
1506}
1507
1508
1509
1510
1511function _proyectos_reformulacion_reformula_tab_page_ver_ae_pdf($node, $reformulacion_load = 0, $ae = 0) {
1512  $planificado = t('planificado');
1513  $variacion = t('variación');
1514  $ftypes = array(
1515    'value' => t('January'),
1516    'value_1' => t('February'),
1517    'value_2' => t('March'),
1518    'value_3' => t('April'),
1519    'value_4' => t('May'),
1520    'value_5' => t('June'),
1521    'value_6' => t('July'),
1522    'value_7' => t('August'),
1523    'value_8' => t('September'),
1524    'value_9' => t('Octuber'),
1525    'value_10' => t('November'),
1526    'value_11' => t('December'),
1527  );
1528  $partidas_nodo = array();
1529  foreach ($ae->field_accion_esp_programacion as $partida) {
1530    if(!empty($partida['tid'])) {
1531      $partidas_nodo[$partida['tid']] = $partida;
1532    }
1533  }
1534
1535  $id_ref = $reformulacion_load ? $reformulacion_load->id_ref : 0;
1536  $reformula = _proyectos_reformulacion_load($node, $id_ref);
1537  $variaciones = _proyectos_reformula_all_partidas_load($node, $id_ref);
1538  $field = content_fields('field_accion_esp_programacion', 'accion_especifica');
1539  $tree = taxonomy_get_tree($field['vid']);
1540  $vtid = $field['vtid'];
1541  $partidas = array();
1542  if ($tree) {
1543    foreach ($tree as $term) {
1544      if (isset($vtid[$term->tid])) {
1545        $partidas[$term->tid] = $term->name;
1546      }
1547    }
1548  }
1549
1550  $arreglo = array();
1551  $titles = array(
1552    'ordinarios' => t('Recursos Ordinarios'),
1553    'propios' => t('Recursos Propios'),
1554    'transferencias' => t('Donaciones'),
1555    'otros' => t('Otros'),
1556  );
1557  $titles_field = array(
1558    'field_accion_esp_transferencias' => t('Recursos Ordinarios'),
1559    'field_accion_esp_creditosa' => t('Recursos Propios'),
1560    'transferencias' => t('Donaciones'),
1561    'otros' => t('Otros'),
1562  );
1563
1564
1565  $arreglo['ordinarios'] = array(
1566    'field_accion_esp_transferencias' => 'field_accion_esp_transferencias',
1567    'field_accion_esp_creditosa' => 'field_accion_esp_creditosa',
1568    'field_accion_esp_mcti' => 'field_accion_esp_mcti',
1569  );
1570  $arreglo['propios'] = array(
1571    'field_accion_esp_venta_act' => 'field_accion_esp_venta_act',
1572    'field_accion_esp_activos' => 'field_accion_esp_activos',
1573    'field_accion_esp_flujocaja' => 'field_accion_esp_flujocaja',
1574    'field_accion_esp_ventapro' => 'field_accion_esp_ventapro',
1575  );
1576  $arreglo['transferencias'] = array(
1577    'field_accion_esp_donaciones' => 'field_accion_esp_donaciones',
1578  );
1579  $arreglo['otros'] = array(
1580    'field_accion_esp_gobernacion' => 'field_accion_esp_gobernacion',
1581    'field_accion_esp_misionc' => 'field_accion_esp_misionc',
1582    'field_accion_esp_bid_fona' => 'field_accion_esp_bid_fona',
1583    'field_accion_esp_fonacit' => 'field_accion_esp_fonacit',
1584    'field_accion_esp_fonden' => 'field_accion_esp_fonden',
1585    'field_accion_esp_locti' => 'field_accion_esp_locti',
1586    'field_accion_esp_fondoidi' => 'field_accion_esp_fondoidi',
1587    'field_accion_esp_capitalrie' => 'field_accion_esp_capitalrie',
1588    'field_accion_esp_infocentro' => 'field_accion_esp_infocentro',
1589    'field_accion_esp_fidetel' => 'field_accion_esp_fidetel',
1590  );
1591  $output = '';
1592  $ente_planificador = node_load($node->field_proyecto_ente[0]['nid']);
1593  //$output .= '<fieldset><legend>' . t('Resumen del Proyecto') . '</legend>';
1594  $output .= '<div class="field"><div class="field-label">' . t('Código Único del Proyecto') . ':</div>' . $node->field_proyecto_codigo[0]['value'] . '</div>';
1595  $output .= '<div class="field"><div class="field-label">' . t('Nombre del Proyecto') . ':</div>' . $node->title . '</div>';
1596  $output .= '<div class="field"><div class="field-label">' . t('Organismo') . ':</div>' . $ente_planificador->title . '</div>';
1597  //$output .= '</fieldset>';
1598
1599
1600  //$output .= '<fieldset><legend>' . t('Resumen Financiero de las Acciones') . '</legend>';
1601  $output .= '<div class="field"><div class="field-label">' . t('Resumen Financiero de las Acciones') . ':</div>'. '</div>';
1602  $header = array();
1603  $header[] = array('data' => t('Partidas'), 'colspan' => 2);
1604  foreach($ftypes as $id_field => $texto) {
1605    $header[] = array('data' => $texto);
1606  }
1607  $header[] = array('data' => t('TOTAL'));
1608  $rows = array();
1609  $rowsF = array();
1610  $i = 0;
1611  $totales = array();
1612  $totalT = 0;
1613  $plant = array();
1614  $sumaplan = 0;
1615  $sumaplanm = array();
1616  foreach($partidas as $tid => $grupo) {
1617    $i++;
1618    $total = 0;
1619    $total1 = 0;
1620    $row = array();
1621    $row1 = array();
1622    $row[] = array('data' => $grupo, 'rowspan' => 2);
1623    $row[] = array('data' => $planificado, );
1624    $row1[] = array('data' => $variacion, );
1625    foreach($ftypes as $id_field => $texto) {
1626      $varia = isset($variaciones['field_accion_esp_programacion_' . $ae->nid][$tid][$id_field]) ? $variaciones['field_accion_esp_programacion_' . $ae->nid][$tid][$id_field] : 0;
1627      $min = $partidas_nodo[$tid][$id_field] + $varia;
1628      $valor = isset($reformula['field_accion_esp_programacion_' . $ae->nid][$tid][$id_field])? $reformula['field_accion_esp_programacion_' . $ae->nid][$tid][$id_field] : 0;
1629      $total1 += $valor;
1630      $totalT += $min + $valor;
1631      if (!isset($plant[$tid])) {
1632        $plant[$tid] = 0;
1633      }
1634      $plant[$tid] += $min;
1635      $sumaplan += $min;
1636      if (!isset($totales[$id_field])) {
1637        $totales[$id_field] = 0;
1638      }
1639      if (!isset($sumaplanm[$id_field])) {
1640        $sumaplanm[$id_field] = 0;
1641      }
1642      $sumaplanm[$id_field] += $min;
1643      $totales[$id_field] += $min + $valor;
1644      $idformu = $ae->nid . '_field_accion_esp_programacion_' . $tid . '_' . $id_field;
1645      $idformuj = str_replace('_', '-', $idformu);
1646      $row[] = array('data' => $min, );
1647      $row1[] = array('data' => $valor, );
1648    }
1649    $row[] = array('data' => $plant[$tid], );
1650    $row1[] = array('data' => $total1, );
1651    $rows[] = $row;
1652    $rows[] = $row1;
1653  }
1654  $row = array();
1655  $row[] = array('data' => '<b>' . t('TOTAL') . '</b>', 'colspan' => 2, 'align' => 'right');
1656  foreach($ftypes as $id_field => $texto) {
1657    $row[] = array('data' => $totales[$id_field], );
1658  }
1659  $row[] = array('data' => $totalT, );
1660  $rows[] = $row;
1661  $output .= theme('table', $header, $rows, array('border' => '1'));
1662 // $output .= '</fieldset>';
1663  $rows = array();
1664  $row = array();
1665  $row1 = array();
1666  $sumalT = 0;
1667  foreach($arreglo as $id => $arreglo1) {
1668    $sumal = 0;
1669    $output1 = '';
1670    foreach($arreglo1 as $id1) {
1671      $field = content_fields($id1, 'accion_especifica');
1672      $varia = isset($variaciones[$id1 . '_' . $ae->nid][0]['value']) ? $variaciones[$id1 . '_' . $ae->nid][0]['value'] : 0;
1673      $min = $ae->{$id1}[0]['value'] + $varia;
1674      if (!isset($sumafinm[$id])) {
1675        $sumafinm[$id] = 0;
1676      }
1677      $sumafinm[$id] += $min;
1678      $sumatotalf += $min;
1679      $field = content_fields($id1, 'accion_especifica');
1680      $valor = isset($reformula[$id1 . '_' . $ae->nid][0]['value'])? $reformula[$id1 . '_' . $ae->nid][0]['value'] : 0;
1681      $total1 += $valor;
1682      $total += $valor;
1683      $sumal += $min + $valor;
1684      $sumalT += $min + $valor;
1685      $idformuj = str_replace('_', '-', $id1);
1686      $output1 .= '<p><b>' . $field['widget']['label'] . ':</b>' . '<br><b>' . t('Planificado') . ':</b> ' . $min . '<br><b>' . t('Variación') . ':</b> ' . $valor .  '</p>';
1687    }
1688    $row[] = array('data' => $output1, );
1689    $row1[] = array('data' => $sumal, );
1690  }
1691  $rows[] = $row;
1692  $rows[] = $row1;
1693  $row = array();
1694  $row[] = array('data' => '<b>' . t('TOTAL') . ':</b>', 'colspan' => 3, 'align' => 'right');
1695  $row[] = array('data' => $sumalT, );
1696  $rows[] = $row;
1697  $output .= '<div class="field"><div class="field-label">' . t('Distribución por fuentes de Financiamiento') . ':</div>'. '</div>';
1698  $output .= theme('table', array(), $rows, array('border' => '1'));
1699  return $output;
1700}
Nota: Vea TracBrowser para ayuda de uso del navegador del repositorio.