source: sipes/0.3-modules/ente_planificador_hierarchical/ente_planificador_hierarchical.module @ a81a52d

version-3.0
Last change on this file since a81a52d was a81a52d, checked in by Cenditel <root@…>, 7 años ago

se agrego el codigo para corregir el bug referente al editar los datos basicos del ente

  • Propiedad mode establecida a 100755
File size: 27.9 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('Revisión del Proyecto'), '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        $hierarchical = variable_get('ente_planificador_hierarchical_count', 2);
252        $fathers = $node->ente_planificador_hierarchical['fathers'];
253        for ($i = 1; $i < $hierarchical + 1; $i++) {
254          $node->{'ente_planificador_hierarchical_father_' . $i} = isset($fathers[$i])? $fathers[$i]['nid'] : 0;
255        }
256      }
257
258    break;
259    case 'presave':
260      if ($node->type == 'ente_planificador') {
261        if (isset($node->ente_planificador_hierarchical_father_1)) {
262          $hierarchical = variable_get('ente_planificador_hierarchical_count', 2);
263          $level = 0;
264          $ente_planificador_hierarchical = array();
265          for($i = 1; $i < $hierarchical + 1; $i++) {
266            if (!$level && isset($node->{'ente_planificador_hierarchical_father_' . $i})) {
267              //level found
268              $level_lower = $i - 1;
269              $father = $node->{'ente_planificador_hierarchical_father_' . $i};
270              if ($father == 0) {
271                $level = $i;
272                $ente_planificador_hierarchical[$i] = $father;
273                break;
274              }
275              $ente_planificador_hierarchical[$i] = $father;
276            }
277          }
278          $node->tipo = $level;
279          $node->ente_planificador_hierarchical = $ente_planificador_hierarchical;
280          if ($node->tipo == 3) {
281            $ente_adscrito = $node->ente_planificador_hierarchical[2] ? $node->ente_planificador_hierarchical[2] : 0;
282            $result = db_query("SELECT organismo FROM {ente_planificador} WHERE nid = %d", $ente_adscrito);
283            $row = db_fetch_object($result);
284            $node->ente_adscrito = $row ? $row->organismo : 0;
285          }
286          if ($node->tipo >= 4) {
287            $node->sub_ente = $node->ente_planificador_hierarchical[3] ? $node->ente_planificador_hierarchical[3] : 0;
288          }
289        }
290      }
291    break;
292    case 'insert':
293    case 'update':
294      if ($node->type == 'ente_planificador') {
295        if ($node->nid && $node->ente_planificador_hierarchical && is_array($node->ente_planificador_hierarchical) && count($node->ente_planificador_hierarchical)) {
296          $query = db_query('DELETE FROM {ente_planificador_hierarchical} WHERE nid = %d', $node->nid);
297          foreach($node->ente_planificador_hierarchical as $level => $father) {
298            $query = db_query('INSERT INTO {ente_planificador_hierarchical} (nid, level, father) VALUES (%d, %d, %d)', $node->nid, $level, $father);
299          }
300        }
301      }
302    break;
303    case 'view':
304      if ($node->type == 'ente_planificador') {
305        if (isset($node->ente_planificador_hierarchical)) {
306          if (count($node->ente_planificador_hierarchical['fathers'])) {
307            $fathers = '';
308            $sep = '';
309            foreach($node->ente_planificador_hierarchical['fathers'] as $level => $ente) {
310              $fathers .= $sep . l($ente['title'], 'node/'. $ente['nid']);
311              $sep = ' > ';
312            }
313          $node->content['ente_planificador_hierarchical_fathers'] = array(
314            '#value' => '<div id = "node-fathers"><b>' . t('Fathers') . ':</b> ' . $fathers . '</div>',
315          );
316
317          }
318          if (count($node->ente_planificador_hierarchical['children'])) {
319            $fathers = '';
320            $sep = '';
321            foreach($node->ente_planificador_hierarchical['children'] as $level => $ente) {
322              $fathers .= $sep . l($ente['title'], 'node/'. $ente['nid']);
323              $sep = ' > ';
324            }
325          $node->content['ente_planificador_hierarchical_childrens'] = array(
326            '#value' => '<div id = "node-childrens"><b>' . t('Childrens') . ':</b> ' . $fathers . '</div>',
327          );
328
329          }
330        }
331      }
332    break;
333  }
334}
335
336
337
338function ente_planificador_hierarchical_obtiene_tipos_alter(&$tipos) {
339  $hierarchical = variable_get('ente_planificador_hierarchical_count', 2);
340  for($i = 1; $i < $hierarchical + 1; $i++) {
341    if ($i == 1) {
342      $tipos[$i] = t(variable_get('ente_planificador_hierarchical_text_' . $i, 'Actor estratégico-táctico'));
343    }
344    else {
345      $tipos[$i] = t(variable_get('ente_planificador_hierarchical_text_' . $i, 'Actor operativo ' . $i));
346    }
347  }
348}
349
350/*
351 * hook_form_alter
352 */
353function ente_planificador_hierarchical_form_alter(&$form, $form_state, $form_id) {
354  if ($form_id == 'proyectos_operativos_admin_workflow_settings') {
355    $wid = workflow_get_workflow_for_type('proyectos_operativos');
356    if ($wid){
357      $states = workflow_get_states($wid);
358
359      $form['buttons']['#weight'] = 1000;
360      if (count($states)) {
361        $form['workflow_formuladores'] = array(
362          '#type' => 'fieldset',
363          '#title' => t('Flujos de Formuladores'),
364          '#collapsible' => TRUE,
365          '#collapsed' => FALSE,
366        );
367        $hierarchical = variable_get('ente_planificador_hierarchical_count', 2);
368        for($i = 1; $i < $hierarchical + 1; $i++) {
369          $form['workflow_formuladores']['proyectos_operativos_state_form_' . $i] = array(
370            '#type' => 'select',
371            '#options' => $states,
372            '#default_value' => variable_get('proyectos_operativos_state_form_' . $i, 0),
373            '#title' => t('Estado formulador del nivel (@nivel)', array('@nivel' => $i)),
374            '#multiple' => FALSE,
375          );
376
377
378        }
379      }
380    }
381  }
382
383  if ($form_id == 'workflow_tab_form') {
384    if ($form['node']['#value']->type == 'proyectos_operativos') {
385      $nombre = check_plain((t($form['#wf']->name)));
386      $ente_planificador = ente_planificador_leer_ente_planificadores($form['node']['#value']->field_proyecto_ente[0]['nid']);
387      $hierarchical = variable_get('ente_planificador_hierarchical_count', 2);
388      for($i = 1; $i < $hierarchical + 1; $i++) {
389//print_r($ente_planificador);
390        if ($ente_planificador->tipo != $i) {
391          $estado = variable_get('proyectos_operativos_state_form_' . $i, 0);
392          if (isset($form['workflow'][$nombre]['#options'][$estado])) {
393            unset($form['workflow'][$nombre]['#options'][$estado]);
394          }
395        }
396      }
397    }
398  }
399
400
401
402  if ($form_id == 'user_profile_form' && arg(2) != 'chgpwd' && user_access('administer users')) {
403    if (isset($form['_account']['#value']->entes) && $form['_account']['#value']->entes[0]['nid']) {
404      $ente_planificador = $form['#ente_planificador_load'] ? $form['#ente_planificador_load'] : ente_planificador_leer_ente_planificadores($form['_account']['#value']->entes[0]['nid']);
405      if($ente_planificador && $ente_planificador->tipo) {
406        $roles_type = _ente_planificador_hierarchical_get_roles_type($ente_planificador->tipo);
407        $roles = user_roles();
408        $hierarchical = variable_get('ente_planificador_hierarchical_count', 2);
409        foreach($roles_type as $rol => $text) {
410            $rol_ente = variable_get('ente_planificador_hierarchical_rol_' . $rol . '_' . $ente_planificador->tipo, 2);
411
412            if ($rol_ente && isset($roles[$rol_ente])) {
413              $form['account']['roles']['#options'][$rol_ente] = $text;
414            }
415
416        }
417      }
418
419    }
420  }
421
422  if ($form_id == 'user_register') {
423    $ente_planificador = FALSE;
424    //get ente planificador       
425    if (arg(4) && is_numeric(arg(4))) {
426
427      $ente_planificador = $form['#ente_planificador_load'] ? $form['#ente_planificador_load'] : ente_planificador_leer_ente_planificadores(arg(4));
428      if($ente_planificador && $ente_planificador->tipo) {
429        $roles_type = _ente_planificador_hierarchical_get_roles_type($ente_planificador->tipo);
430        $roles = user_roles();
431        $hierarchical = variable_get('ente_planificador_hierarchical_count', 2);
432        foreach($roles_type as $rol => $text) {
433            $rol_ente = variable_get('ente_planificador_hierarchical_rol_' . $rol . '_' . $ente_planificador->tipo, 2);
434
435            if ($rol_ente && isset($roles[$rol_ente])) {
436              $form['account']['roles']['#options'][$rol_ente] = $text;
437            }
438
439        }
440      }
441    }
442  }
443  //change ente_planificador_admin_settings
444  if ($form_id == 'ente_planificador_admin_settings') {
445    $roles_type = _ente_planificador_hierarchical_get_roles_type();
446    $roles = user_roles();
447    $roles[0] = t('No aplica');
448    unset($roles[1]);
449    $hierarchical_count = array();
450    for($i = 2; $i <= 15; $i++) {
451      $hierarchical_count[$i] = $i;
452    }
453    $form['ente_planificador_hierarchical'] = array(
454      '#type' => 'fieldset',
455      '#title' => t('Entes jerarquicos'),
456      '#collapsible' => TRUE,
457      '#collapsed' => FALSE,
458    );
459    $hierarchical = variable_get('ente_planificador_hierarchical_count', 2);
460    $form['ente_planificador_hierarchical']['ente_planificador_hierarchical_count'] = array(
461      '#title' => t('Cantidad de tipos de entes planificacdores'),
462      '#type' => 'select',
463      '#default_value' => $hierarchical,
464      '#description' => t('Introduzca la cantidad de tipos de entes planificadores'),
465      '#options' => $hierarchical_count,
466    );
467    for($i = 1; $i < $hierarchical + 1; $i++) {
468      $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);
469      $form['ente_planificador_hierarchical']['type_' . $i] = array(
470        '#type' => 'fieldset',
471        '#title' => t('Tipo de ente') . ' '  . $i,
472        '#collapsible' => TRUE,
473        '#collapsed' => FALSE,
474      );
475      $form['ente_planificador_hierarchical']['type_' . $i]['ente_planificador_hierarchical_text_' . $i] = array(
476        '#type' => 'textfield',
477        '#title' => t('Nombre del tipo de ente') . ' '  . $i,
478        '#default_value' => $hierarchical_text,
479        '#size' => 60,
480        '#maxlength' => 244,
481        '#description' => t('Introduzca el nombre del tipo de actor'),
482        '#required'       => TRUE,
483      );
484      foreach($roles_type as $rol => $text) {
485        $form['ente_planificador_hierarchical']['type_' . $i]['ente_planificador_hierarchical_rol_' . $rol . '_' . $i] = array(
486          '#type' => 'select',
487          '#title' => t('Rol para el tipo de ente (#rol_type)', array('#rol_type' => $text)),
488          '#default_value' => variable_get('ente_planificador_hierarchical_rol_' . $rol . '_' . $i, 0),
489          '#options' => $roles,
490        );
491      }
492    }
493    $form['ente_planificador_hierarchical_extras'] = array(
494      '#type' => 'fieldset',
495      '#title' => t('Hierarchical entes extra'),
496      '#collapsible' => TRUE,
497      '#collapsed' => FALSE,
498    );
499    $form['ente_planificador_hierarchical_extras']['create_roles'] = array(
500      '#type'  => 'submit',
501      '#value' => t('Create roles by each hierarchical ente'),
502      '#submit' => array('_ente_planificador_hierarchical_create_roles'),
503    );
504
505
506  }
507
508  if ($form_id == 'ente_planificador_node_form') {
509    if (isset($form['#node']->ente_planificador_hierarchical)) {
510      $fathers = $form['#node']->ente_planificador_hierarchical['fathers'];
511    }
512    $hierarchical = variable_get('ente_planificador_hierarchical_count', 2);
513    $opens_div = '';
514    $prev_father = 0;
515    for($i = 1; $i < $hierarchical + 1; $i++) {
516      $childrens = array();
517      $default_value = isset($fathers[$i])? $fathers[$i]['nid'] : 0;
518      $lower_level = $i - 1;
519      $next_level = $i + 1;
520      if ($i == 1) {
521        $tipo_text = t(variable_get('ente_planificador_hierarchical_text_' . $i, 'Actor estratégico-táctico'));
522        $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");
523        while ($father = db_fetch_object($query)) {
524          $childrens[$father->nid] = $father->title;
525        }
526      }
527      else {
528        $tipo_text = t(variable_get('ente_planificador_hierarchical_text_' . $i, 'Actor operativo ' . $i));
529        $childrens = _ente_planificador_hierarchical_get_children($prev_father, $lower_level);
530      }
531      if (isset($form['#node']->nid) && isset($childrens[$form['#node']->nid])) {
532        unset($childrens[$form['#node']->nid]);
533      }
534      $macros = array();
535      $macros = $childrens;
536      $macros[0] = t('Seleccionar este nivel');
537      $opens_div .= '</div>';
538      $form['ente_planificador_hierarchical_father_' . $i] = array(
539        '#prefix' => '<div id = "ente_planificador_hierarchical_' . $i . '">',
540        '#title' => $tipo_text,
541        '#type' => 'select',
542        '#default_value' => $default_value,
543        '#options' => $macros,
544      );
545      if ($i == $hierarchical) {
546        $form['ente_planificador_hierarchical_father_' . $i]['#suffix'] = $opens_div;
547      }
548      else {
549        $form['ente_planificador_hierarchical_father_' . $i]['#ahah'] = array(
550          'path' => 'ente_planificador_hierarchical_js_util/' . $next_level,
551          'wrapper' => 'ente_planificador_hierarchical_' . $next_level,
552          'method' => 'replace',
553          'progress' => array('type' => 'bar', 'message' => t('Please wait...')),
554        );
555      }
556      $prev_father = $default_value;
557    }
558    //remove current tipo field in form
559    if (isset($form['tipo'])) {
560      $form['tipo']['#access'] = FALSE;
561    }
562    if (module_exists('ente_planificador_sector')) {
563      $form['nivel']['ente_adscrito']['#access'] = FALSE;
564      $form['nivel']['sub_ente']['#access'] = FALSE;
565      if (!($form['#node']->tipo == 2) || !$form['#node']->nid){
566        $form['nivel']['sector']['#access'] = FALSE;
567        $form['nivel']['#access'] = FALSE;
568      }
569
570    }
571  }
572}
573
574/**
575 * Submit hook for the settings form.
576 */
577function _ente_planificador_hierarchical_create_roles($form, &$form_state) {
578  $hierarchical = variable_get('ente_planificador_hierarchical_count', 2);
579  for($i = 1; $i < $hierarchical + 1; $i++) {
580    $roles_type = _ente_planificador_hierarchical_get_roles_type($i);
581    foreach($roles_type as $rol => $text1) {
582      $text = t('Ente tipo @number (@type)', array('@number' => $i, '@type' => $text1));
583      db_query("INSERT INTO {role} (name) VALUES ('%s')", $text);
584    }
585  }
586  drupal_set_message(t('The roles has been added.'));
587}
588
589function _ente_planificador_hierarchical_get_roles_type($tipo = 0) {
590  $roles_type =array();
591  $roles_type['for'] = t('Enlace Formulador');
592  $roles_type['enl'] = t('Enlace Revisor');
593  $roles_type['sup'] = t('Supervisor');
594  return $roles_type;
595}
596
597function _ente_planificador_hierarchical_get_desc($nid, $father = 1, $level = 0) {
598  $fathers = array();
599  //get fathers
600  if ($father) {
601    $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';
602  }
603  else {
604  //get childrens
605    $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';
606  }
607  $inputs = array();
608  $inputs[] = $nid;
609  if ($level) {
610    $sql .= ' AND father.level = %d';
611    $inputs[] = $level;
612  }
613  $sql .= ' ORDER BY father.level, n.title';
614  $query = db_query($sql, $inputs);
615  while ($father = db_fetch_object($query)) {
616    $fathers[$father->level] = array(
617      'title' => $father->title,
618      'nid' =>  $father->nid,
619    );
620  }
621  return $fathers;
622}
623function _ente_planificador_hierarchical_get_descbyid($nid, $father = 1, $level = 0) {
624  $fathers = array();
625  //get fathers
626  if ($father) {
627    $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';
628  }
629  else {
630  //get childrens
631    $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';
632  }
633  $inputs = array();
634  $inputs[] = $nid;
635  if ($level) {
636    $sql .= ' AND father.level = %d';
637    $inputs[] = $level;
638  }
639  $sql .= ' ORDER BY father.level, n.title';
640  $query = db_query($sql, $inputs);
641  while ($father = db_fetch_object($query)) {
642    $fathers[$father->nid] = array(
643      'title' => $father->title,
644      'nid' =>  $father->nid,
645    );
646  }
647  return $fathers;
648}
649
650function _ente_planificador_hierarchical_get_children($nid, $level = 0) {
651  $fathers = array();
652  $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';
653  $inputs = array();
654  $inputs[] = $nid;
655  $inputs[] = $level;
656  $sql .= ' ORDER BY father.level, n.title';
657  $query = db_query($sql, $inputs);
658  while ($father = db_fetch_object($query)) {
659    $fathers[$father->nid] = $father->title;
660  }
661  return $fathers;
662}
663
664
665/**
666 * Implementation of proyectos_operativos_search_ac_display().
667 * Muestra la lista de proyectos disponibles.
668 */
669function ente_planificador_hierarchical_search_ac_display() {
670  global $user;
671  //add breadcrumb
672  $breadcrumb = array();
673  $breadcrumb[] = l(t('Home'), '<front>');
674  $breadcrumb[] = t('Proyectos Operativos');
675  drupal_set_breadcrumb($breadcrumb);
676  $current_time = time();
677  $tipo_plan = 'proyectos_operativos_formular';
678  $fecha = FALSE;
679  $ente = usuario_tiene_ente($user->uid);
680  $ente_planificador = 0;
681  if ($ente && $ente->nid) {
682    $ente_planificador = ente_planificador_leer_ente_planificadores($ente->nid);
683  }
684  $mi_fecha = ente_planificador_user_acceso_proceso($tipo_plan, $ente_planificador);
685  if ($mi_fecha[1]  + 86399 > $current_time && $mi_fecha[0] < $current_time) {
686    $fecha = TRUE;
687  }
688  if (!$fecha) {
689    muestra_mensaje($tipo_plan, $ente_planificador);
690  }
691  if ($fecha && $ente->nid) {
692    muestra_mensaje($tipo_plan, $ente_planificador, 0);
693  }
694  if ($fecha && !$ente_planificador && !user_access('admin planificador')) {
695    $fecha = FALSE;
696  }
697  $view_id = variable_get('ente_planificador_hierarchical_view', 'ente_planificador_hierarchical');
698  $view = views_get_view($view_id);
699  $display_id = variable_get('ente_planificador_hierarchical_display', 'default');
700  $view->set_display($display_id);
701  $view->override_path = $_GET['q'];
702  $view->pre_execute();
703  $view->execute();
704  $output = $view->render();
705  if ($fecha) {
706    $links = array();
707    drupal_alter('proyecto_obtiene_agregar_links', $links);
708    $output .= '<div id="ente-planificador-agregar-proyecto">' . theme('item_list', $links) . '</div>';
709  }
710  return $output;
711}
712
713/**
714 * Implementation of hook_views_api().
715 */
716function ente_planificador_hierarchical_views_api() {
717  return array(
718    'api' => '2.0',
719    'path' => drupal_get_path('module', 'ente_planificador_hierarchical') . '/views',
720  );
721}
Nota: Vea TracBrowser para ayuda de uso del navegador del repositorio.