source: sipes/0.3-modules/ente_planificador_hierarchical/ente_planificador_hierarchical.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: 25.8 KB
Línea 
1<?php
2
3/* Implementation of hook_menu_alter().
4*/
5function ente_planificador_hierarchical_menu_alter(&$items) {
6  //change access to own users
7  $items['proyectos_operativos']['page callback'] = 'ente_planificador_hierarchical_search_ac_display';
8  $items['proyectosop/%proyectosop/workflow']['access callback'] = '_ente_planificador_hierarchical_edita_datos_wk_access';
9}
10
11
12/*
13 * Implementation of hook_menu()
14 */
15function ente_planificador_hierarchical_menu() {
16  $items = array();
17  $items['ente_planificador_hierarchical_js_util/%'] = array(
18    'title' => 'JS utilities',
19    'page callback' => 'ente_planificador_hierarchical_js_util',
20    'page arguments' => array(1),
21    'access arguments' => array('admin planificador'),
22    'type' => MENU_CALLBACK,
23  );
24  $items['ente_planificador_hierarchical/ente_autocomplete'] = array(
25    'title' => 'Ente Planificador',
26    'page callback' => '_ente_planificador_hierarchical_ente_autocomplete',
27    'access arguments' => array('ver planificador'),
28    'type' => MENU_CALLBACK,
29  );
30  return $items;
31}
32
33function _ente_planificador_hierarchical_ente_autocomplete($string = '') {
34  global $user;
35  $matches = array();
36  if ($user->entes && $string) {
37    $result = db_query_range("SELECT father.nid, father.level, n.title FROM {ente_planificador_hierarchical} AS father INNER JOIN {node} AS n ON n.nid = father.nid WHERE (father.father = %d OR (father.nid = %d AND father.father = 0)) AND n.status = 1 AND LOWER(n.title) LIKE LOWER('%s%%') ORDER BY n.title", $user->entes, $user->entes, $string, 0, 10);
38    while ($ente = db_fetch_object($result)) {
39      $matches[$ente->title] = '<div class="reference-autocomplete">' . check_plain($ente->title) . '</div>';
40    }
41
42  }
43  drupal_json($matches);
44}
45
46/*
47 * Implementation of hook_acciones_obtiene_links_alter()
48*/
49function ente_planificador_hierarchical_proyecto_obtiene_links_alter(&$links, $proyecto, $acceso = FALSE) {
50  if (!isset($links['proyecto_state'])) {
51    if (_ente_planificador_hierarchical_edita_datos_wk_access($proyecto)){
52      $links['proyecto_state'] = array(
53        'data' => l(t('Cambiar el estado'), 'proyectosop/' . $proyecto->nid . '/workflow'),
54        'class' => 'proyectos-operativos-estado',
55      );
56    }
57  }
58}
59
60function _ente_planificador_hierarchical_get_finaciero($node) {
61  $financieros = array(
62    'monto' => 0,
63    'porc' => 0,
64  );
65  $nids = array();
66  $new_column = array();
67  foreach($node->field_proyecto_accion_esp as $accion) {
68    if ($accion['nid'] && $nid != $accion['nid']) {
69      $nids[] =  $accion['nid'];
70      $new_column[] = '%d';
71    }
72  }
73  $ftypes = array(
74    'p.field_accion_esp_programacion_value',
75    'p.field_accion_esp_programacion_value_1',
76    'p.field_accion_esp_programacion_value_2',
77    'p.field_accion_esp_programacion_value_3',
78    'p.field_accion_esp_programacion_value_4',
79    'p.field_accion_esp_programacion_value_5',
80    'p.field_accion_esp_programacion_value_6',
81    'p.field_accion_esp_programacion_value_7',
82    'p.field_accion_esp_programacion_value_8',
83    'p.field_accion_esp_programacion_value_9',
84    'p.field_accion_esp_programacion_value_10',
85    'p.field_accion_esp_programacion_value_11',
86  );
87  if (count($nids)) {
88    $sql = "SELECT SUM(" . implode(' + ', $ftypes) . ") AS suma FROM {content_field_accion_esp_programacion} AS p INNER JOIN {node} AS n ON n.nid = p.nid AND n.vid = p.vid WHERE n.status > 0 AND n.nid IN ";
89    $sql1 = "SELECT SUM(field_accion_esp_ponderacion_value) AS porc FROM {content_type_accion_especifica} AS p INNER JOIN {node} AS n ON n.nid = p.nid AND n.vid = p.vid WHERE n.status > 0 AND n.nid IN ";
90    $implode = '(' . implode(', ', $new_column) . ')';
91    $sql .= $implode;
92    $sql1 .= $implode;
93    $resul_sum = db_query($sql, $nids);
94    $suma = db_fetch_object($resul_sum);
95    $resul_porc = db_query($sql1, $nids);
96    $porc = db_fetch_object($resul_porc);
97    if ($suma) {
98      $financieros['monto'] = $suma->suma;
99    }
100    if ($porc) {
101       $financieros['porc'] = $porc->porc;
102    }
103  }
104  return $financieros;
105
106}
107
108/**
109 * Implementation of _proyectos_operativos_ver_datos_wk_access()
110 * Menu access control callback. Determina si un usuario tiene acceso a editar el flujo de trabajo
111*/
112function _ente_planificador_hierarchical_edita_datos_wk_access($node = NULL) {
113  global $user;
114  $fecha = FALSE;
115  $proyecto = isset($node->data_project) ? $node->data_project : $node;
116  if (user_access('admin planificador')) {
117    $fecha = TRUE;
118  }
119  else {
120    $ente = usuario_tiene_ente($user->uid);
121    if (!count($ente)) {
122      return FALSE;
123    }
124    $current_ente = isset($node->ente) ? $node->ente : $proyecto->field_proyecto_ente[0]['nid'];
125    if ($ente->nid == $current_ente) {
126      $fecha = TRUE;
127    }
128    elseif ($current_ente) {
129      $fathers = _ente_planificador_hierarchical_get_descbyid($current_ente,1);
130      $fecha = isset($fathers[$ente->nid]) ? TRUE : FALSE;
131    }
132  }
133  if (!$fecha) {
134    return $fecha;
135  }
136  $accesso = workflow_node_tab_access($proyecto);
137  return $fecha && $accesso && _ente_planificador_hierarchical_datos_financieros_completo($proyecto);
138}
139
140/**
141 * Implementation of _proyectos_operativos_edita_datos_financieros_access()
142 * Menu access control callback. Determina si un proyecto tiene acceso a los datos financieros.
143 * función mas eficiente
144 */
145function _ente_planificador_hierarchical_datos_financieros_completo($node = NULL) {
146  if (!isset($node->field_proyecto_accion_esp)) {
147    //load AE
148    //""
149  }
150  $financieros = _ente_planificador_hierarchical_get_finaciero($node);
151  $monto_restante = $node->field_proyecto_monto_anual[0]['value'] - $financieros['monto'];
152  $et = 100 - $financieros['porc'];
153  return (($monto_restante == 0) && ($et == 0));
154}
155
156
157
158
159/*
160 * ente_planificador_hierarchical_js_util
161 * Genera las repuestas ajax de los distintos niveles de los entes planificadores
162 */
163
164function ente_planificador_hierarchical_js_util($level) {
165  if ($level > 1) {
166    $form_state = array('submitted' => FALSE);
167    $form_build_id = $_POST['form_build_id'];
168    // Add the new element to the stored form. Without adding the element to the
169    // form, Drupal is not aware of this new elements existence and will not
170    // process it. We retreive the cached form, add the element, and resave.
171    $form = form_get_cache($form_build_id, $form_state);
172    $hierarchical = variable_get('ente_planificador_hierarchical_count', 2);
173    $opens_div = '';
174    for($i = $level; $i < $hierarchical + 1; $i++) {
175      $lower_level = $i - 1;
176      $next_level = $i + 1;
177
178     // $default_value = intval($_POST['ente_planificador_hierarchical_father_' . $i]) > 0 ? intval($_POST['ente_planificador_hierarchical_father_' . $i]) : 0;
179      $tipo_text = t(variable_get('ente_planificador_hierarchical_text_' . $i, 'Actor operativo ' . $i));
180      if ($i != $level) {
181        $prev_father = 0;
182        $childrens = array();
183        $childrens[0] = t('Seleccionar este nivel');
184        $form['ente_planificador_hierarchical_father_' . $i] = array(
185          '#prefix' => '<div id = "ente_planificador_hierarchical_' . $i . '">',
186          '#title' => $tipo_text,
187          '#type' => 'select',
188          '#default_value' => $default_value,
189          '#options' => $childrens,
190        );
191        $opens_div .= '</div>';
192      }
193      else {
194        $prev_father = intval($_POST['ente_planificador_hierarchical_father_' . $lower_level]) > 0 ? intval($_POST['ente_planificador_hierarchical_father_' . $lower_level]) : 0;
195        $childrens = _ente_planificador_hierarchical_get_children($prev_father, $lower_level);
196        if (isset($form['#node']->nid) && isset($childrens[$form['#node']->nid])) {
197          unset($childrens[$form['#node']->nid]);
198        }
199        $childrens[0] = t('Seleccionar este nivel');
200        $form['ente_planificador_hierarchical_father_' . $i] = array(
201          '#title' => $tipo_text,
202          '#type' => 'select',
203          '#default_value' => $default_value,
204          '#options' => $childrens,
205        );
206      }
207      if ($i == $hierarchical) {
208        $form['ente_planificador_hierarchical_father_' . $i]['#suffix'] = $opens_div;
209      }
210      else {
211        $form['ente_planificador_hierarchical_father_' . $i]['#ahah'] = array(
212          'path' => 'ente_planificador_hierarchical_js_util/' . $next_level,
213          'wrapper' => 'ente_planificador_hierarchical_' . $next_level,
214          'method' => 'replace',
215          'progress' => array('type' => 'bar', 'message' => t('Please wait...')),
216        );
217      }
218    }
219    //$form += $new_form;
220    form_set_cache($form_build_id, $form, $form_state);
221    $form += array(
222      '#post' => $_POST,
223      '#programmed' => FALSE,
224    );
225    // Rebuild the form.
226    $form = form_builder($_POST['form_id'], $form, $form_state);
227    // Render the new output.
228    $new_form = array();
229    for($i = $level; $i < $hierarchical + 1; $i++) {
230      $new_form['ente_planificador_hierarchical_father_' . $i] = $form['ente_planificador_hierarchical_father_' . $i];
231    }
232    unset($new_form['ente_planificador_hierarchical_father_' . $level]['#prefix'], $new_form['ente_planificador_hierarchical_father_' . $level]['#suffix']); // Prevent duplicate wrappers.
233    $output = drupal_render($new_form);
234    print drupal_to_js(array('data' => $output, 'status' => true));
235    exit();
236  }
237  print '';
238  exit();
239}
240/*
241 * Implementation of hook_nodeapi()
242 */
243function ente_planificador_hierarchical_nodeapi(&$node, $op, $teaser = NULL, $page = NULL) {
244  switch ($op) {
245    case 'load':
246      if ($node->type == 'ente_planificador') {
247        $node->ente_planificador_hierarchical = array(
248          'fathers' => _ente_planificador_hierarchical_get_desc($node->nid, 1),
249          'children' => _ente_planificador_hierarchical_get_desc($node->nid, 0),
250        );
251      }
252
253    break;
254    case 'presave':
255      if ($node->type == 'ente_planificador') {
256        if (isset($node->ente_planificador_hierarchical_father_1)) {
257          $hierarchical = variable_get('ente_planificador_hierarchical_count', 2);
258          $level = 0;
259          $ente_planificador_hierarchical = array();
260          for($i = 1; $i < $hierarchical + 1; $i++) {
261            if (!$level && isset($node->{'ente_planificador_hierarchical_father_' . $i})) {
262              //level found
263              $level_lower = $i - 1;
264              $father = $node->{'ente_planificador_hierarchical_father_' . $i};
265              if ($father == 0) {
266                $level = $i;
267                $ente_planificador_hierarchical[$i] = $father;
268                break;
269              }
270              $ente_planificador_hierarchical[$i] = $father;
271            }
272          }
273          $node->tipo = $level;
274          $node->ente_planificador_hierarchical = $ente_planificador_hierarchical;
275          if ($node->tipo == 3) {
276            $ente_adscrito = $node->ente_planificador_hierarchical[2] ? $node->ente_planificador_hierarchical[2] : 0;
277            $result = db_query("SELECT organismo FROM {ente_planificador} WHERE nid = %d", $ente_adscrito);
278            $row = db_fetch_object($result);
279            $node->ente_adscrito = $row ? $row->organismo : 0;
280          }
281          if ($node->tipo >= 4) {
282            $node->sub_ente = $node->ente_planificador_hierarchical[3] ? $node->ente_planificador_hierarchical[3] : 0;
283          }
284        }
285      }
286    break;
287    case 'insert':
288    case 'update':
289      if ($node->type == 'ente_planificador') {
290        if ($node->nid && $node->ente_planificador_hierarchical && is_array($node->ente_planificador_hierarchical) && count($node->ente_planificador_hierarchical)) {
291          $query = db_query('DELETE FROM {ente_planificador_hierarchical} WHERE nid = %d', $node->nid);
292          foreach($node->ente_planificador_hierarchical as $level => $father) {
293            $query = db_query('INSERT INTO {ente_planificador_hierarchical} (nid, level, father) VALUES (%d, %d, %d)', $node->nid, $level, $father);
294          }
295        }
296      }
297    break;
298    case 'view':
299      if ($node->type == 'ente_planificador') {
300        if (isset($node->ente_planificador_hierarchical)) {
301          if (count($node->ente_planificador_hierarchical['fathers'])) {
302            $fathers = '';
303            $sep = '';
304            foreach($node->ente_planificador_hierarchical['fathers'] as $level => $ente) {
305              $fathers .= $sep . l($ente['title'], 'node/'. $ente['nid']);
306              $sep = ' > ';
307            }
308          $node->content['ente_planificador_hierarchical_fathers'] = array(
309            '#value' => '<div id = "node-fathers"><b>Fathers:</b> ' . $fathers . '</div>',
310          );
311
312          }
313          if (count($node->ente_planificador_hierarchical['children'])) {
314            $fathers = '';
315            $sep = '';
316            foreach($node->ente_planificador_hierarchical['children'] as $level => $ente) {
317              $fathers .= $sep . l($ente['title'], 'node/'. $ente['nid']);
318              $sep = ' > ';
319            }
320          $node->content['ente_planificador_hierarchical_childrens'] = array(
321            '#value' => '<div id = "node-childrens"><b>Childrens:</b> ' . $fathers . '</div>',
322          );
323
324          }
325        }
326      }
327    break;
328  }
329}
330
331
332
333function ente_planificador_hierarchical_obtiene_tipos_alter(&$tipos) {
334  $hierarchical = variable_get('ente_planificador_hierarchical_count', 2);
335  for($i = 1; $i < $hierarchical + 1; $i++) {
336    if ($i == 1) {
337      $tipos[$i] = t(variable_get('ente_planificador_hierarchical_text_' . $i, 'Actor estratégico-táctico'));
338    }
339    else {
340      $tipos[$i] = t(variable_get('ente_planificador_hierarchical_text_' . $i, 'Actor operativo ' . $i));
341    }
342  }
343}
344
345/*
346 * hook_form_alter
347 */
348function ente_planificador_hierarchical_form_alter(&$form, $form_state, $form_id) {
349  if ($form_id == 'user_profile_form' && arg(2) != 'chgpwd' && user_access('administer users')) {
350    if (isset($form['_account']['#value']->entes) && $form['_account']['#value']->entes[0]['nid']) {
351      $ente_planificador = $form['#ente_planificador_load'] ? $form['#ente_planificador_load'] : ente_planificador_leer_ente_planificadores($form['_account']['#value']->entes[0]['nid']);
352      if($ente_planificador && $ente_planificador->tipo) {
353        $roles_type = _ente_planificador_hierarchical_get_roles_type($ente_planificador->tipo);
354        $roles = user_roles();
355        $hierarchical = variable_get('ente_planificador_hierarchical_count', 2);
356        foreach($roles_type as $rol => $text) {
357            $rol_ente = variable_get('ente_planificador_hierarchical_rol_' . $rol . '_' . $ente_planificador->tipo, 2);
358
359            if ($rol_ente && isset($roles[$rol_ente])) {
360              $form['account']['roles']['#options'][$rol_ente] = $text;
361            }
362
363        }
364      }
365
366    }
367  }
368
369  if ($form_id == 'user_register') {
370    $ente_planificador = FALSE;
371    //get ente planificador       
372    if (arg(4) && is_numeric(arg(4))) {
373
374      $ente_planificador = $form['#ente_planificador_load'] ? $form['#ente_planificador_load'] : ente_planificador_leer_ente_planificadores(arg(4));
375      if($ente_planificador && $ente_planificador->tipo) {
376        $roles_type = _ente_planificador_hierarchical_get_roles_type($ente_planificador->tipo);
377        $roles = user_roles();
378        $hierarchical = variable_get('ente_planificador_hierarchical_count', 2);
379        foreach($roles_type as $rol => $text) {
380            $rol_ente = variable_get('ente_planificador_hierarchical_rol_' . $rol . '_' . $ente_planificador->tipo, 2);
381
382            if ($rol_ente && isset($roles[$rol_ente])) {
383              $form['account']['roles']['#options'][$rol_ente] = $text;
384            }
385
386        }
387      }
388    }
389  }
390  //change ente_planificador_admin_settings
391  if ($form_id == 'ente_planificador_admin_settings') {
392    $roles_type = _ente_planificador_hierarchical_get_roles_type();
393    $roles = user_roles();
394    $roles[0] = t('No aplica');
395    unset($roles[1]);
396    $hierarchical_count = array();
397    for($i = 2; $i <= 15; $i++) {
398      $hierarchical_count[$i] = $i;
399    }
400    $form['ente_planificador_hierarchical'] = array(
401      '#type' => 'fieldset',
402      '#title' => t('Entes jerarquicos'),
403      '#collapsible' => TRUE,
404      '#collapsed' => FALSE,
405    );
406    $hierarchical = variable_get('ente_planificador_hierarchical_count', 2);
407    $form['ente_planificador_hierarchical']['ente_planificador_hierarchical_count'] = array(
408      '#title' => t('Cantidad de tipos de entes planificacdores'),
409      '#type' => 'select',
410      '#default_value' => $hierarchical,
411      '#description' => t('Introduzca la cantidad de tipos de entes planificadores'),
412      '#options' => $hierarchical_count,
413    );
414    for($i = 1; $i < $hierarchical + 1; $i++) {
415      $hierarchical_text = $i == 1 ? variable_get('ente_planificador_hierarchical_text_' . $i, 'Actor estratégico-táctico') : variable_get('ente_planificador_hierarchical_text_' . $i, 'Actor operativo ' . $i);
416      $form['ente_planificador_hierarchical']['type_' . $i] = array(
417        '#type' => 'fieldset',
418        '#title' => t('Tipo de ente') . ' '  . $i,
419        '#collapsible' => TRUE,
420        '#collapsed' => FALSE,
421      );
422      $form['ente_planificador_hierarchical']['type_' . $i]['ente_planificador_hierarchical_text_' . $i] = array(
423        '#type' => 'textfield',
424        '#title' => t('Nombre del tipo de ente') . ' '  . $i,
425        '#default_value' => $hierarchical_text,
426        '#size' => 60,
427        '#maxlength' => 244,
428        '#description' => t('Introduzca el nombre del tipo de actor'),
429        '#required'       => TRUE,
430      );
431      foreach($roles_type as $rol => $text) {
432        $form['ente_planificador_hierarchical']['type_' . $i]['ente_planificador_hierarchical_rol_' . $rol . '_' . $i] = array(
433          '#type' => 'select',
434          '#title' => t('Rol para el tipo de ente (#rol_type)', array('#rol_type' => $text)),
435          '#default_value' => variable_get('ente_planificador_hierarchical_rol_' . $rol . '_' . $i, 0),
436          '#options' => $roles,
437        );
438      }
439    }
440    $form['ente_planificador_hierarchical_extras'] = array(
441      '#type' => 'fieldset',
442      '#title' => t('Hierarchical entes extra'),
443      '#collapsible' => TRUE,
444      '#collapsed' => FALSE,
445    );
446    $form['ente_planificador_hierarchical_extras']['create_roles'] = array(
447      '#type'  => 'submit',
448      '#value' => t('Create roles by each hierarchical ente'),
449      '#submit' => array('_ente_planificador_hierarchical_create_roles'),
450    );
451
452
453  }
454
455  if ($form_id == 'ente_planificador_node_form') {
456    if (isset($form['#node']->ente_planificador_hierarchical)) {
457      $fathers = $form['#node']->ente_planificador_hierarchical['fathers'];
458    }
459    $hierarchical = variable_get('ente_planificador_hierarchical_count', 2);
460    $opens_div = '';
461    $prev_father = 0;
462    for($i = 1; $i < $hierarchical + 1; $i++) {
463      $childrens = array();
464      $default_value = isset($fathers[$i])? $fathers[$i]['nid'] : 0;
465      $lower_level = $i - 1;
466      $next_level = $i + 1;
467      if ($i == 1) {
468        $tipo_text = t(variable_get('ente_planificador_hierarchical_text_' . $i, 'Actor estratégico-táctico'));
469        $query = db_query("SELECT d.nid, n.title FROM {ente_planificador} AS d INNER JOIN {node} AS n ON n.nid = d.nid WHERE tipo = 1");
470        while ($father = db_fetch_object($query)) {
471          $childrens[$father->nid] = $father->title;
472        }
473      }
474      else {
475        $tipo_text = t(variable_get('ente_planificador_hierarchical_text_' . $i, 'Actor operativo ' . $i));
476        $childrens = _ente_planificador_hierarchical_get_children($prev_father, $lower_level);
477      }
478      if (isset($form['#node']->nid) && isset($childrens[$form['#node']->nid])) {
479        unset($childrens[$form['#node']->nid]);
480      }
481      $macros = array();
482      $macros = $childrens;
483      $macros[0] = t('Seleccionar este nivel');
484      $opens_div .= '</div>';
485      $form['ente_planificador_hierarchical_father_' . $i] = array(
486        '#prefix' => '<div id = "ente_planificador_hierarchical_' . $i . '">',
487        '#title' => $tipo_text,
488        '#type' => 'select',
489        '#default_value' => $default_value,
490        '#options' => $macros,
491      );
492      if ($i == $hierarchical) {
493        $form['ente_planificador_hierarchical_father_' . $i]['#suffix'] = $opens_div;
494      }
495      else {
496        $form['ente_planificador_hierarchical_father_' . $i]['#ahah'] = array(
497          'path' => 'ente_planificador_hierarchical_js_util/' . $next_level,
498          'wrapper' => 'ente_planificador_hierarchical_' . $next_level,
499          'method' => 'replace',
500          'progress' => array('type' => 'bar', 'message' => t('Please wait...')),
501        );
502      }
503      $prev_father = $default_value;
504    }
505    //remove current tipo field in form
506    if (isset($form['tipo'])) {
507      $form['tipo']['#access'] = FALSE;
508    }
509    if (module_exists('ente_planificador_sector')) {
510      $form['nivel']['ente_adscrito']['#access'] = FALSE;
511      $form['nivel']['sub_ente']['#access'] = FALSE;
512      if (!($form['#node']->tipo == 2) || !$form['#node']->nid){
513        $form['nivel']['sector']['#access'] = FALSE;
514        $form['nivel']['#access'] = FALSE;
515      }
516
517    }
518  }
519}
520
521/**
522 * Submit hook for the settings form.
523 */
524function _ente_planificador_hierarchical_create_roles($form, &$form_state) {
525  $hierarchical = variable_get('ente_planificador_hierarchical_count', 2);
526  for($i = 1; $i < $hierarchical + 1; $i++) {
527    $roles_type = _ente_planificador_hierarchical_get_roles_type($i);
528    foreach($roles_type as $rol => $text1) {
529      $text = t('Ente tipo @number (@type)', array('@number' => $i, '@type' => $text1));
530      db_query("INSERT INTO {role} (name) VALUES ('%s')", $text);
531    }
532  }
533  drupal_set_message(t('The roles has been added.'));
534}
535
536function _ente_planificador_hierarchical_get_roles_type($tipo = 0) {
537  $roles_type =array();
538  $roles_type['for'] = t('Enlace Formulador');
539  $roles_type['enl'] = t('Enlace Revisor');
540  $roles_type['sup'] = t('Supervisor');
541  return $roles_type;
542}
543
544function _ente_planificador_hierarchical_get_desc($nid, $father = 1, $level = 0) {
545  $fathers = array();
546  //get fathers
547  if ($father) {
548    $sql = 'SELECT father.father as nid, father.level, n.title FROM {ente_planificador_hierarchical} AS father INNER JOIN {node} AS n ON n.nid = father.father WHERE father.nid = %d';
549  }
550  else {
551  //get childrens
552    $sql = 'SELECT father.nid, father.level, n.title FROM {ente_planificador_hierarchical} AS father INNER JOIN {node} AS n ON n.nid = father.nid WHERE father.father = %d';
553  }
554  $inputs = array();
555  $inputs[] = $nid;
556  if ($level) {
557    $sql .= ' AND father.level = %d';
558    $inputs[] = $level;
559  }
560  $sql .= ' ORDER BY father.level, n.title';
561  $query = db_query($sql, $inputs);
562  while ($father = db_fetch_object($query)) {
563    $fathers[$father->level] = array(
564      'title' => $father->title,
565      'nid' =>  $father->nid,
566    );
567  }
568  return $fathers;
569}
570function _ente_planificador_hierarchical_get_descbyid($nid, $father = 1, $level = 0) {
571  $fathers = array();
572  //get fathers
573  if ($father) {
574    $sql = 'SELECT father.father as nid, father.level, n.title FROM {ente_planificador_hierarchical} AS father INNER JOIN {node} AS n ON n.nid = father.father WHERE father.nid = %d';
575  }
576  else {
577  //get childrens
578    $sql = 'SELECT father.nid, father.level, n.title FROM {ente_planificador_hierarchical} AS father INNER JOIN {node} AS n ON n.nid = father.nid WHERE father.father = %d';
579  }
580  $inputs = array();
581  $inputs[] = $nid;
582  if ($level) {
583    $sql .= ' AND father.level = %d';
584    $inputs[] = $level;
585  }
586  $sql .= ' ORDER BY father.level, n.title';
587  $query = db_query($sql, $inputs);
588  while ($father = db_fetch_object($query)) {
589    $fathers[$father->nid] = array(
590      'title' => $father->title,
591      'nid' =>  $father->nid,
592    );
593  }
594  return $fathers;
595}
596
597function _ente_planificador_hierarchical_get_children($nid, $level = 0) {
598  $fathers = array();
599  $sql = 'SELECT father.nid, father.level, n.title FROM {ente_planificador_hierarchical} AS father INNER JOIN {node} AS n ON n.nid = father.nid INNER JOIN {ente_planificador} AS ep ON ep.nid = father.nid  WHERE father.father = %d AND father.level = %d AND ep.tipo = father.level + 1';
600  $inputs = array();
601  $inputs[] = $nid;
602  $inputs[] = $level;
603  $sql .= ' ORDER BY father.level, n.title';
604  $query = db_query($sql, $inputs);
605  while ($father = db_fetch_object($query)) {
606    $fathers[$father->nid] = $father->title;
607  }
608  return $fathers;
609}
610
611
612/**
613 * Implementation of proyectos_operativos_search_ac_display().
614 * Muestra la lista de proyectos disponibles.
615 */
616function ente_planificador_hierarchical_search_ac_display() {
617  global $user;
618  //add breadcrumb
619  $breadcrumb = array();
620  $breadcrumb[] = l(t('Home'), '<front>');
621  $breadcrumb[] = t('Proyectos Operativos');
622  drupal_set_breadcrumb($breadcrumb);
623  $current_time = time();
624  $tipo_plan = 'proyectos_operativos_formular';
625  $fecha = FALSE;
626  $ente = usuario_tiene_ente($user->uid);
627  $ente_planificador = 0;
628  if ($ente && $ente->nid) {
629    $ente_planificador = ente_planificador_leer_ente_planificadores($ente->nid);
630  }
631  $mi_fecha = ente_planificador_user_acceso_proceso($tipo_plan, $ente_planificador);
632  if ($mi_fecha[1]  + 86399 > $current_time && $mi_fecha[0] < $current_time) {
633    $fecha = TRUE;
634  }
635  if (!$fecha) {
636    muestra_mensaje($tipo_plan, $ente_planificador);
637  }
638  if ($fecha && $ente->nid) {
639    muestra_mensaje($tipo_plan, $ente_planificador, 0);
640  }
641  if ($fecha && !$ente_planificador && !user_access('admin planificador')) {
642    $fecha = FALSE;
643  }
644  $view_id = variable_get('ente_planificador_hierarchical_view', 'ente_planificador_hierarchical');
645  $view = views_get_view($view_id);
646  $display_id = variable_get('ente_planificador_hierarchical_display', 'default');
647  $view->set_display($display_id);
648  $view->override_path = $_GET['q'];
649  $view->pre_execute();
650  $view->execute();
651  $output = $view->render();
652  if ($fecha) {
653    $links = array();
654    drupal_alter('proyecto_obtiene_agregar_links', $links);
655    $output .= '<div id="ente-planificador-agregar-proyecto">' . theme('item_list', $links) . '</div>';
656  }
657  return $output;
658}
659
660/**
661 * Implementation of hook_views_api().
662 */
663function ente_planificador_hierarchical_views_api() {
664  return array(
665    'api' => '2.0',
666    'path' => drupal_get_path('module', 'ente_planificador_hierarchical') . '/views',
667  );
668}
Nota: Vea TracBrowser para ayuda de uso del navegador del repositorio.