'JS utilities',
'page callback' => 'ente_planificador_hierarchical_js_util',
'page arguments' => array(1),
'access arguments' => array('admin planificador'),
'type' => MENU_CALLBACK,
);
$items['ente_planificador_hierarchical/ente_autocomplete'] = array(
'title' => 'Ente Planificador',
'page callback' => '_ente_planificador_hierarchical_ente_autocomplete',
'access arguments' => array('ver planificador'),
'type' => MENU_CALLBACK,
);
return $items;
}
function _ente_planificador_hierarchical_ente_autocomplete($string = '') {
global $user;
$matches = array();
if ($user->entes && $string) {
$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);
while ($ente = db_fetch_object($result)) {
$matches[$ente->title] = '
' . check_plain($ente->title) . '
';
}
}
drupal_json($matches);
}
/*
* Implementation of hook_acciones_obtiene_links_alter()
*/
function ente_planificador_hierarchical_proyecto_obtiene_links_alter(&$links, $proyecto, $acceso = FALSE) {
if (!isset($links['proyecto_state'])) {
if (_ente_planificador_hierarchical_edita_datos_wk_access($proyecto)){
$links['proyecto_state'] = array(
'data' => l(t('Revisión del Proyecto'), 'proyectosop/' . $proyecto->nid . '/workflow'),
'class' => 'proyectos-operativos-estado',
);
}
}
}
function _ente_planificador_hierarchical_get_finaciero($node) {
$financieros = array(
'monto' => 0,
'porc' => 0,
);
$nids = array();
$new_column = array();
foreach($node->field_proyecto_accion_esp as $accion) {
if ($accion['nid'] && $nid != $accion['nid']) {
$nids[] = $accion['nid'];
$new_column[] = '%d';
}
}
$ftypes = array(
'p.field_accion_esp_programacion_value',
'p.field_accion_esp_programacion_value_1',
'p.field_accion_esp_programacion_value_2',
'p.field_accion_esp_programacion_value_3',
'p.field_accion_esp_programacion_value_4',
'p.field_accion_esp_programacion_value_5',
'p.field_accion_esp_programacion_value_6',
'p.field_accion_esp_programacion_value_7',
'p.field_accion_esp_programacion_value_8',
'p.field_accion_esp_programacion_value_9',
'p.field_accion_esp_programacion_value_10',
'p.field_accion_esp_programacion_value_11',
);
if (count($nids)) {
$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 ";
$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 ";
$implode = '(' . implode(', ', $new_column) . ')';
$sql .= $implode;
$sql1 .= $implode;
$resul_sum = db_query($sql, $nids);
$suma = db_fetch_object($resul_sum);
$resul_porc = db_query($sql1, $nids);
$porc = db_fetch_object($resul_porc);
if ($suma) {
$financieros['monto'] = $suma->suma;
}
if ($porc) {
$financieros['porc'] = $porc->porc;
}
}
return $financieros;
}
/**
* Implementation of _proyectos_operativos_ver_datos_wk_access()
* Menu access control callback. Determina si un usuario tiene acceso a editar el flujo de trabajo
*/
function _ente_planificador_hierarchical_edita_datos_wk_access($node = NULL) {
global $user;
$fecha = FALSE;
$proyecto = isset($node->data_project) ? $node->data_project : $node;
if (user_access('admin planificador')) {
$fecha = TRUE;
}
else {
$ente = usuario_tiene_ente($user->uid);
if (!count($ente)) {
return FALSE;
}
$current_ente = isset($node->ente) ? $node->ente : $proyecto->field_proyecto_ente[0]['nid'];
if ($ente->nid == $current_ente) {
$fecha = TRUE;
}
elseif ($current_ente) {
$fathers = _ente_planificador_hierarchical_get_descbyid($current_ente,1);
$fecha = isset($fathers[$ente->nid]) ? TRUE : FALSE;
}
}
if (!$fecha) {
return $fecha;
}
$accesso = workflow_node_tab_access($proyecto);
return $fecha && $accesso && _ente_planificador_hierarchical_datos_financieros_completo($proyecto);
}
/**
* Implementation of _proyectos_operativos_edita_datos_financieros_access()
* Menu access control callback. Determina si un proyecto tiene acceso a los datos financieros.
* función mas eficiente
*/
function _ente_planificador_hierarchical_datos_financieros_completo($node = NULL) {
if (!isset($node->field_proyecto_accion_esp)) {
//load AE
//""
}
$financieros = _ente_planificador_hierarchical_get_finaciero($node);
$monto_restante = $node->field_proyecto_monto_anual[0]['value'] - $financieros['monto'];
$et = 100 - $financieros['porc'];
return (($monto_restante == 0) && ($et == 0));
}
/*
* ente_planificador_hierarchical_js_util
* Genera las repuestas ajax de los distintos niveles de los entes planificadores
*/
function ente_planificador_hierarchical_js_util($level) {
if ($level > 1) {
$form_state = array('submitted' => FALSE);
$form_build_id = $_POST['form_build_id'];
// Add the new element to the stored form. Without adding the element to the
// form, Drupal is not aware of this new elements existence and will not
// process it. We retreive the cached form, add the element, and resave.
$form = form_get_cache($form_build_id, $form_state);
$hierarchical = variable_get('ente_planificador_hierarchical_count', 2);
$opens_div = '';
for($i = $level; $i < $hierarchical + 1; $i++) {
$lower_level = $i - 1;
$next_level = $i + 1;
// $default_value = intval($_POST['ente_planificador_hierarchical_father_' . $i]) > 0 ? intval($_POST['ente_planificador_hierarchical_father_' . $i]) : 0;
$tipo_text = t(variable_get('ente_planificador_hierarchical_text_' . $i, 'Actor operativo ' . $i));
if ($i != $level) {
$prev_father = 0;
$childrens = array();
$childrens[0] = t('Seleccionar este nivel');
$form['ente_planificador_hierarchical_father_' . $i] = array(
'#prefix' => '',
'#title' => $tipo_text,
'#type' => 'select',
'#default_value' => $default_value,
'#options' => $childrens,
);
$opens_div .= '
';
}
else {
$prev_father = intval($_POST['ente_planificador_hierarchical_father_' . $lower_level]) > 0 ? intval($_POST['ente_planificador_hierarchical_father_' . $lower_level]) : 0;
$childrens = _ente_planificador_hierarchical_get_children($prev_father, $lower_level);
if (isset($form['#node']->nid) && isset($childrens[$form['#node']->nid])) {
unset($childrens[$form['#node']->nid]);
}
$childrens[0] = t('Seleccionar este nivel');
$form['ente_planificador_hierarchical_father_' . $i] = array(
'#title' => $tipo_text,
'#type' => 'select',
'#default_value' => $default_value,
'#options' => $childrens,
);
}
if ($i == $hierarchical) {
$form['ente_planificador_hierarchical_father_' . $i]['#suffix'] = $opens_div;
}
else {
$form['ente_planificador_hierarchical_father_' . $i]['#ahah'] = array(
'path' => 'ente_planificador_hierarchical_js_util/' . $next_level,
'wrapper' => 'ente_planificador_hierarchical_' . $next_level,
'method' => 'replace',
'progress' => array('type' => 'bar', 'message' => t('Please wait...')),
);
}
}
//$form += $new_form;
form_set_cache($form_build_id, $form, $form_state);
$form += array(
'#post' => $_POST,
'#programmed' => FALSE,
);
// Rebuild the form.
$form = form_builder($_POST['form_id'], $form, $form_state);
// Render the new output.
$new_form = array();
for($i = $level; $i < $hierarchical + 1; $i++) {
$new_form['ente_planificador_hierarchical_father_' . $i] = $form['ente_planificador_hierarchical_father_' . $i];
}
unset($new_form['ente_planificador_hierarchical_father_' . $level]['#prefix'], $new_form['ente_planificador_hierarchical_father_' . $level]['#suffix']); // Prevent duplicate wrappers.
$output = drupal_render($new_form);
print drupal_to_js(array('data' => $output, 'status' => true));
exit();
}
print '';
exit();
}
/*
* Implementation of hook_nodeapi()
*/
function ente_planificador_hierarchical_nodeapi(&$node, $op, $teaser = NULL, $page = NULL) {
switch ($op) {
case 'load':
if ($node->type == 'ente_planificador') {
$node->ente_planificador_hierarchical = array(
'fathers' => _ente_planificador_hierarchical_get_desc($node->nid, 1),
'children' => _ente_planificador_hierarchical_get_desc($node->nid, 0),
);
}
break;
case 'presave':
if ($node->type == 'ente_planificador') {
if (isset($node->ente_planificador_hierarchical_father_1)) {
$hierarchical = variable_get('ente_planificador_hierarchical_count', 2);
$level = 0;
$ente_planificador_hierarchical = array();
for($i = 1; $i < $hierarchical + 1; $i++) {
if (!$level && isset($node->{'ente_planificador_hierarchical_father_' . $i})) {
//level found
$level_lower = $i - 1;
$father = $node->{'ente_planificador_hierarchical_father_' . $i};
if ($father == 0) {
$level = $i;
$ente_planificador_hierarchical[$i] = $father;
break;
}
$ente_planificador_hierarchical[$i] = $father;
}
}
$node->tipo = $level;
$node->ente_planificador_hierarchical = $ente_planificador_hierarchical;
if ($node->tipo == 3) {
$ente_adscrito = $node->ente_planificador_hierarchical[2] ? $node->ente_planificador_hierarchical[2] : 0;
$result = db_query("SELECT organismo FROM {ente_planificador} WHERE nid = %d", $ente_adscrito);
$row = db_fetch_object($result);
$node->ente_adscrito = $row ? $row->organismo : 0;
}
if ($node->tipo >= 4) {
$node->sub_ente = $node->ente_planificador_hierarchical[3] ? $node->ente_planificador_hierarchical[3] : 0;
}
}
}
break;
case 'insert':
case 'update':
if ($node->type == 'ente_planificador') {
if ($node->nid && $node->ente_planificador_hierarchical && is_array($node->ente_planificador_hierarchical) && count($node->ente_planificador_hierarchical)) {
$query = db_query('DELETE FROM {ente_planificador_hierarchical} WHERE nid = %d', $node->nid);
foreach($node->ente_planificador_hierarchical as $level => $father) {
$query = db_query('INSERT INTO {ente_planificador_hierarchical} (nid, level, father) VALUES (%d, %d, %d)', $node->nid, $level, $father);
}
}
}
break;
case 'view':
if ($node->type == 'ente_planificador') {
if (isset($node->ente_planificador_hierarchical)) {
if (count($node->ente_planificador_hierarchical['fathers'])) {
$fathers = '';
$sep = '';
foreach($node->ente_planificador_hierarchical['fathers'] as $level => $ente) {
$fathers .= $sep . l($ente['title'], 'node/'. $ente['nid']);
$sep = ' > ';
}
$node->content['ente_planificador_hierarchical_fathers'] = array(
'#value' => '' . t('Fathers') . ': ' . $fathers . '
',
);
}
if (count($node->ente_planificador_hierarchical['children'])) {
$fathers = '';
$sep = '';
foreach($node->ente_planificador_hierarchical['children'] as $level => $ente) {
$fathers .= $sep . l($ente['title'], 'node/'. $ente['nid']);
$sep = ' > ';
}
$node->content['ente_planificador_hierarchical_childrens'] = array(
'#value' => '' . t('Childrens') . ': ' . $fathers . '
',
);
}
}
}
break;
}
}
function ente_planificador_hierarchical_obtiene_tipos_alter(&$tipos) {
$hierarchical = variable_get('ente_planificador_hierarchical_count', 2);
for($i = 1; $i < $hierarchical + 1; $i++) {
if ($i == 1) {
$tipos[$i] = t(variable_get('ente_planificador_hierarchical_text_' . $i, 'Actor estratégico-táctico'));
}
else {
$tipos[$i] = t(variable_get('ente_planificador_hierarchical_text_' . $i, 'Actor operativo ' . $i));
}
}
}
/*
* hook_form_alter
*/
function ente_planificador_hierarchical_form_alter(&$form, $form_state, $form_id) {
if ($form_id == 'proyectos_operativos_admin_workflow_settings') {
$wid = workflow_get_workflow_for_type('proyectos_operativos');
if ($wid){
$states = workflow_get_states($wid);
$form['buttons']['#weight'] = 1000;
if (count($states)) {
$form['workflow_formuladores'] = array(
'#type' => 'fieldset',
'#title' => t('Flujos de Formuladores'),
'#collapsible' => TRUE,
'#collapsed' => FALSE,
);
$hierarchical = variable_get('ente_planificador_hierarchical_count', 2);
for($i = 1; $i < $hierarchical + 1; $i++) {
$form['workflow_formuladores']['proyectos_operativos_state_form_' . $i] = array(
'#type' => 'select',
'#options' => $states,
'#default_value' => variable_get('proyectos_operativos_state_form_' . $i, 0),
'#title' => t('Estado formulador del nivel (@nivel)', array('@nivel' => $i)),
'#multiple' => FALSE,
);
}
}
}
}
if ($form_id == 'workflow_tab_form') {
if ($form['node']['#value']->type == 'proyectos_operativos') {
$nombre = check_plain((t($form['#wf']->name)));
$ente_planificador = ente_planificador_leer_ente_planificadores($form['node']['#value']->field_proyecto_ente[0]['nid']);
$hierarchical = variable_get('ente_planificador_hierarchical_count', 2);
for($i = 1; $i < $hierarchical + 1; $i++) {
//print_r($ente_planificador);
if ($ente_planificador->tipo != $i) {
$estado = variable_get('proyectos_operativos_state_form_' . $i, 0);
if (isset($form['workflow'][$nombre]['#options'][$estado])) {
unset($form['workflow'][$nombre]['#options'][$estado]);
}
}
}
}
}
if ($form_id == 'user_profile_form' && arg(2) != 'chgpwd' && user_access('administer users')) {
if (isset($form['_account']['#value']->entes) && $form['_account']['#value']->entes[0]['nid']) {
$ente_planificador = $form['#ente_planificador_load'] ? $form['#ente_planificador_load'] : ente_planificador_leer_ente_planificadores($form['_account']['#value']->entes[0]['nid']);
if($ente_planificador && $ente_planificador->tipo) {
$roles_type = _ente_planificador_hierarchical_get_roles_type($ente_planificador->tipo);
$roles = user_roles();
$hierarchical = variable_get('ente_planificador_hierarchical_count', 2);
foreach($roles_type as $rol => $text) {
$rol_ente = variable_get('ente_planificador_hierarchical_rol_' . $rol . '_' . $ente_planificador->tipo, 2);
if ($rol_ente && isset($roles[$rol_ente])) {
$form['account']['roles']['#options'][$rol_ente] = $text;
}
}
}
}
}
if ($form_id == 'user_register') {
$ente_planificador = FALSE;
//get ente planificador
if (arg(4) && is_numeric(arg(4))) {
$ente_planificador = $form['#ente_planificador_load'] ? $form['#ente_planificador_load'] : ente_planificador_leer_ente_planificadores(arg(4));
if($ente_planificador && $ente_planificador->tipo) {
$roles_type = _ente_planificador_hierarchical_get_roles_type($ente_planificador->tipo);
$roles = user_roles();
$hierarchical = variable_get('ente_planificador_hierarchical_count', 2);
foreach($roles_type as $rol => $text) {
$rol_ente = variable_get('ente_planificador_hierarchical_rol_' . $rol . '_' . $ente_planificador->tipo, 2);
if ($rol_ente && isset($roles[$rol_ente])) {
$form['account']['roles']['#options'][$rol_ente] = $text;
}
}
}
}
}
//change ente_planificador_admin_settings
if ($form_id == 'ente_planificador_admin_settings') {
$roles_type = _ente_planificador_hierarchical_get_roles_type();
$roles = user_roles();
$roles[0] = t('No aplica');
unset($roles[1]);
$hierarchical_count = array();
for($i = 2; $i <= 15; $i++) {
$hierarchical_count[$i] = $i;
}
$form['ente_planificador_hierarchical'] = array(
'#type' => 'fieldset',
'#title' => t('Entes jerarquicos'),
'#collapsible' => TRUE,
'#collapsed' => FALSE,
);
$hierarchical = variable_get('ente_planificador_hierarchical_count', 2);
$form['ente_planificador_hierarchical']['ente_planificador_hierarchical_count'] = array(
'#title' => t('Cantidad de tipos de entes planificacdores'),
'#type' => 'select',
'#default_value' => $hierarchical,
'#description' => t('Introduzca la cantidad de tipos de entes planificadores'),
'#options' => $hierarchical_count,
);
for($i = 1; $i < $hierarchical + 1; $i++) {
$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);
$form['ente_planificador_hierarchical']['type_' . $i] = array(
'#type' => 'fieldset',
'#title' => t('Tipo de ente') . ' ' . $i,
'#collapsible' => TRUE,
'#collapsed' => FALSE,
);
$form['ente_planificador_hierarchical']['type_' . $i]['ente_planificador_hierarchical_text_' . $i] = array(
'#type' => 'textfield',
'#title' => t('Nombre del tipo de ente') . ' ' . $i,
'#default_value' => $hierarchical_text,
'#size' => 60,
'#maxlength' => 244,
'#description' => t('Introduzca el nombre del tipo de actor'),
'#required' => TRUE,
);
foreach($roles_type as $rol => $text) {
$form['ente_planificador_hierarchical']['type_' . $i]['ente_planificador_hierarchical_rol_' . $rol . '_' . $i] = array(
'#type' => 'select',
'#title' => t('Rol para el tipo de ente (#rol_type)', array('#rol_type' => $text)),
'#default_value' => variable_get('ente_planificador_hierarchical_rol_' . $rol . '_' . $i, 0),
'#options' => $roles,
);
}
}
$form['ente_planificador_hierarchical_extras'] = array(
'#type' => 'fieldset',
'#title' => t('Hierarchical entes extra'),
'#collapsible' => TRUE,
'#collapsed' => FALSE,
);
$form['ente_planificador_hierarchical_extras']['create_roles'] = array(
'#type' => 'submit',
'#value' => t('Create roles by each hierarchical ente'),
'#submit' => array('_ente_planificador_hierarchical_create_roles'),
);
}
if ($form_id == 'ente_planificador_node_form') {
if (isset($form['#node']->ente_planificador_hierarchical)) {
$fathers = $form['#node']->ente_planificador_hierarchical['fathers'];
}
$hierarchical = variable_get('ente_planificador_hierarchical_count', 2);
$opens_div = '';
$prev_father = 0;
for($i = 1; $i < $hierarchical + 1; $i++) {
$childrens = array();
$default_value = isset($fathers[$i])? $fathers[$i]['nid'] : 0;
$lower_level = $i - 1;
$next_level = $i + 1;
if ($i == 1) {
$tipo_text = t(variable_get('ente_planificador_hierarchical_text_' . $i, 'Actor estratégico-táctico'));
$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");
while ($father = db_fetch_object($query)) {
$childrens[$father->nid] = $father->title;
}
}
else {
$tipo_text = t(variable_get('ente_planificador_hierarchical_text_' . $i, 'Actor operativo ' . $i));
$childrens = _ente_planificador_hierarchical_get_children($prev_father, $lower_level);
}
if (isset($form['#node']->nid) && isset($childrens[$form['#node']->nid])) {
unset($childrens[$form['#node']->nid]);
}
$macros = array();
$macros = $childrens;
$macros[0] = t('Seleccionar este nivel');
$opens_div .= '';
$form['ente_planificador_hierarchical_father_' . $i] = array(
'#prefix' => '',
'#title' => $tipo_text,
'#type' => 'select',
'#default_value' => $default_value,
'#options' => $macros,
);
if ($i == $hierarchical) {
$form['ente_planificador_hierarchical_father_' . $i]['#suffix'] = $opens_div;
}
else {
$form['ente_planificador_hierarchical_father_' . $i]['#ahah'] = array(
'path' => 'ente_planificador_hierarchical_js_util/' . $next_level,
'wrapper' => 'ente_planificador_hierarchical_' . $next_level,
'method' => 'replace',
'progress' => array('type' => 'bar', 'message' => t('Please wait...')),
);
}
$prev_father = $default_value;
}
//remove current tipo field in form
if (isset($form['tipo'])) {
$form['tipo']['#access'] = FALSE;
}
if (module_exists('ente_planificador_sector')) {
$form['nivel']['ente_adscrito']['#access'] = FALSE;
$form['nivel']['sub_ente']['#access'] = FALSE;
if (!($form['#node']->tipo == 2) || !$form['#node']->nid){
$form['nivel']['sector']['#access'] = FALSE;
$form['nivel']['#access'] = FALSE;
}
}
}
}
/**
* Submit hook for the settings form.
*/
function _ente_planificador_hierarchical_create_roles($form, &$form_state) {
$hierarchical = variable_get('ente_planificador_hierarchical_count', 2);
for($i = 1; $i < $hierarchical + 1; $i++) {
$roles_type = _ente_planificador_hierarchical_get_roles_type($i);
foreach($roles_type as $rol => $text1) {
$text = t('Ente tipo @number (@type)', array('@number' => $i, '@type' => $text1));
db_query("INSERT INTO {role} (name) VALUES ('%s')", $text);
}
}
drupal_set_message(t('The roles has been added.'));
}
function _ente_planificador_hierarchical_get_roles_type($tipo = 0) {
$roles_type =array();
$roles_type['for'] = t('Enlace Formulador');
$roles_type['enl'] = t('Enlace Revisor');
$roles_type['sup'] = t('Supervisor');
return $roles_type;
}
function _ente_planificador_hierarchical_get_desc($nid, $father = 1, $level = 0) {
$fathers = array();
//get fathers
if ($father) {
$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';
}
else {
//get childrens
$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';
}
$inputs = array();
$inputs[] = $nid;
if ($level) {
$sql .= ' AND father.level = %d';
$inputs[] = $level;
}
$sql .= ' ORDER BY father.level, n.title';
$query = db_query($sql, $inputs);
while ($father = db_fetch_object($query)) {
$fathers[$father->level] = array(
'title' => $father->title,
'nid' => $father->nid,
);
}
return $fathers;
}
function _ente_planificador_hierarchical_get_descbyid($nid, $father = 1, $level = 0) {
$fathers = array();
//get fathers
if ($father) {
$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';
}
else {
//get childrens
$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';
}
$inputs = array();
$inputs[] = $nid;
if ($level) {
$sql .= ' AND father.level = %d';
$inputs[] = $level;
}
$sql .= ' ORDER BY father.level, n.title';
$query = db_query($sql, $inputs);
while ($father = db_fetch_object($query)) {
$fathers[$father->nid] = array(
'title' => $father->title,
'nid' => $father->nid,
);
}
return $fathers;
}
function _ente_planificador_hierarchical_get_children($nid, $level = 0) {
$fathers = array();
$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';
$inputs = array();
$inputs[] = $nid;
$inputs[] = $level;
$sql .= ' ORDER BY father.level, n.title';
$query = db_query($sql, $inputs);
while ($father = db_fetch_object($query)) {
$fathers[$father->nid] = $father->title;
}
return $fathers;
}
/**
* Implementation of proyectos_operativos_search_ac_display().
* Muestra la lista de proyectos disponibles.
*/
function ente_planificador_hierarchical_search_ac_display() {
global $user;
//add breadcrumb
$breadcrumb = array();
$breadcrumb[] = l(t('Home'), '
');
$breadcrumb[] = t('Proyectos Operativos');
drupal_set_breadcrumb($breadcrumb);
$current_time = time();
$tipo_plan = 'proyectos_operativos_formular';
$fecha = FALSE;
$ente = usuario_tiene_ente($user->uid);
$ente_planificador = 0;
if ($ente && $ente->nid) {
$ente_planificador = ente_planificador_leer_ente_planificadores($ente->nid);
}
$mi_fecha = ente_planificador_user_acceso_proceso($tipo_plan, $ente_planificador);
if ($mi_fecha[1] + 86399 > $current_time && $mi_fecha[0] < $current_time) {
$fecha = TRUE;
}
if (!$fecha) {
muestra_mensaje($tipo_plan, $ente_planificador);
}
if ($fecha && $ente->nid) {
muestra_mensaje($tipo_plan, $ente_planificador, 0);
}
if ($fecha && !$ente_planificador && !user_access('admin planificador')) {
$fecha = FALSE;
}
$view_id = variable_get('ente_planificador_hierarchical_view', 'ente_planificador_hierarchical');
$view = views_get_view($view_id);
$display_id = variable_get('ente_planificador_hierarchical_display', 'default');
$view->set_display($display_id);
$view->override_path = $_GET['q'];
$view->pre_execute();
$view->execute();
$output = $view->render();
if ($fecha) {
$links = array();
drupal_alter('proyecto_obtiene_agregar_links', $links);
$output .= '' . theme('item_list', $links) . '
';
}
return $output;
}
/**
* Implementation of hook_views_api().
*/
function ente_planificador_hierarchical_views_api() {
return array(
'api' => '2.0',
'path' => drupal_get_path('module', 'ente_planificador_hierarchical') . '/views',
);
}