= 1 y <= 2 tienen version preliminar
$entes_version_min = 1;
$entes_version_max = 2;
//permitir situacion actual del tipo de ente menores o iguales a $entes_situacion_actual
//En este caso $entes_situacion_actual_min = 1 y $entes_situacion_actual_max = 2, solo los entes tipos >= 1 y <= 2 tienen situacion actual
$entes_situacion_actual_min = 1;
$entes_situacion_actual_max = 2;
//permitir interpretacion del tipo de ente mayores o iguales a $entes_interpretacion
//En este caso $entes_version_min = 2 y $entes_version_max = 0, solo los entes tipos >= 2 tienen interpretacion
$entes_interpretacion_min = 3;
$entes_interpretacion_max = 0;
$planns = array(
'interpretacion' => array(
'plan' => 'interpretacion',
'short' => 'vp',
'title' => t('Interpretación'),
'description' => t('Los entes micros añaden su interpretación de la explicación situacional'),
'title_long' => t('Interpretación preliminar de la explicación situacional'),
'title_ente' => t('Interpretación preliminar de la explicación situacional de @ente'),
'hierarchical' => 'children',
'hierarchical_ente' => 1,
'ente_type' => array(),
),
'version' => array(
'plan' => 'version',
'short' => 'vp',
'title' => t('Versión preliminar'),
'description' => t('Los enten macro añaden su versión preliminar de la explicación situacional'),
'title_long' => t('Versión preliminar de la explicación situacional'),
'title_ente' => t('Versión Preliminar de @ente'),
'hierarchical' => 'fathers',
'hierarchical_ente' => -1,
'ente_type' => array(),
),
'situacion_actual' => array(
'plan' => 'situacion_actual',
'short' => 'sa',
'title' => t('Situación Actual'),
'description' => t('Los enten macro añaden su Situación Actual de la explicación situacional'),
'title_long' => t('Situación Actual de la explicación situacional'),
'title_ente' => t('Situación Actual de @ente'),
'hierarchical' => 'fathers',
'hierarchical_ente' => -1,
'ente_type' => array(),
),
);
//se obtienen todos los tipos de entes
$hierarchical = variable_get('ente_planificador_hierarchical_count', 2);
for($i = 1; $i < $hierarchical + 1; $i++) {
if ((!$entes_version_min || $i >= $entes_version_min) && (!$entes_version_max || $i <= $entes_version_max)) {
$planns['version']['ente_type'][$i] = $i;
}
if ((!$entes_situacion_actual_min || $i >= $entes_situacion_actual_min) && (!$entes_situacion_actual_max || $i <= $entes_situacion_actual_max)) {
$planns['situacion_actual']['ente_type'][$i] = $i;
}
if ((!$entes_interpretacion_min || $i >= $entes_interpretacion_min) && (!$entes_interpretacion_max || $i <= $entes_interpretacion_max)) {
$planns['interpretacion']['ente_type'][$i] = $i;
}
}
return $planns;
}
/*
* Implementation of hook_ente_procesos_alter()
*/
function situacion_actual_preliminar_ente_procesos_alter(&$procesos, $type) {
if ($type == 'status') {
$procesos['explicacion'] = array(
'title' => t('Explicación Situacional'),
'description' => t('Explicación Situacional'),
'weight' => -10,
);
}
else {
$planns = _situacion_actual_preliminar_get_planns();
$weight = -10;
foreach ($planns as $plann) {
$procesos[$plann['plan']] = array(
'title' => $plann['title_long'],
'description' => $plann['description'],
'message' => 'Se podrá registrar y/o modificar la interpretación de la ' . $plann['title'] . ' desde %fecha hasta la fecha %fecha1',
'message_expire' => 'Registrar y/o modificar la interpretación de la ' . $plann['title'] . ' no se encuentra disponible, se podra realizar desde %fecha hasta la fecha %fecha1)',
'weight' => $weight,
'proceso' => 'explicacion',
);
$weight++;
}
}
}
/*
* Implementation of hook_menu()
*/
function situacion_actual_preliminar_menu() {
$items = array();
$items['planificacion/%ente_planificador_menu/explicacion'] = array(
'title' => t('Explicación Situacional'),
'page callback' => 'ente_planificador_view_situacion_explicacion',
'page arguments' => array(1, 'version'),
'access callback' => 'tipo_plan_load',
'access arguments' => array('version'),
'weight' => -9,
'type' => MENU_LOCAL_TASK,
);
$planns = _situacion_actual_preliminar_get_planns();
$i = -10;
foreach ($planns as $plann) {
if ($plann['plan'] != 'version') {
$items['planificacion/%ente_planificador_menu/explicacion/' . $plann['plan']] = array(
'title' => $plann['title'],
'page callback' => 'ente_planificador_view_situacion_explicacion',
'page arguments' => array(1, $plann['plan'], 4, 5),
'access callback' => 'tipo_plan_load',
'access arguments' => array($plann['plan']),
'weight' => $i,
'type' => MENU_LOCAL_TASK,
);
$i += 2;
}
else {
$items['planificacion/%ente_planificador_menu/explicacion/' . $plann['plan']] = array(
'title' => $plann['title'],
'type' => MENU_DEFAULT_LOCAL_TASK,
'weight' => -9,
);
}
};
$items['planificacion/%ente_planificador_menu/explicacion/%tipo_plan/agregar/descriptor'] = array(
'title' => t('Agregar descriptor'),
'page callback' => 'drupal_get_form',
'page arguments' => array('ente_planificador_descriptores_editar_form', 1, 3),
'access callback' => '_get_situacion_explicacion_acceso',
'access arguments' => array(1, 3),
'weight' => -8,
'type' => MENU_NORMAL_ITEM,
);
$items['planificacion/%ente_planificador_menu/explicacion/%tipo_plan/%node/descriptor'] = array(
'title' => t('Editar descriptor'),
'page callback' => 'drupal_get_form',
'page arguments' => array('ente_planificador_descriptores_editar_form', 1, 3, 4),
'access callback' => '_get_situacion_explicacion_acceso',
'access arguments' => array(1, 3, 4),
'weight' => -8,
'type' => MENU_NORMAL_ITEM,
);
$items['planificacion/%ente_planificador_menu/explicacion/%tipo_plan/%node/eliminar'] = array(
'title' => t('Eliminar descriptor'),
'page callback' => 'drupal_get_form',
'page arguments' => array('ente_planificador_descriptores_eliminar_form', 1, 3, 4),
'access callback' => '_get_situacion_explicacion_acceso',
'access arguments' => array(1, 3, 4),
'weight' => -8,
'type' => MENU_NORMAL_ITEM,
);
$items['planificacion/%ente_planificador_menu/explicacion/%tipo_plan/%node/causas'] = array(
'title' => t('Causas'),
'page callback' => 'drupal_get_form',
'page arguments' => array('ente_planificador_causas_seleccionar_form', 1, 3, 4),
'access callback' => '_get_situacion_explicacion_acceso',
'access arguments' => array(1, 3, 4),
'weight' => -8,
'type' => MENU_NORMAL_ITEM,
);
$items['planificacion/%ente_planificador_menu/explicacion/%tipo_plan/%node/causas/ver'] = array(
'title' => t('Causas'),
'page callback' => '_ente_planificador_causas_ver',
'page arguments' => array( 1, 3, 4),
'access callback' => '_get_situacion_explicacion_acceso',
'access arguments' => array(1, 3, 4),
'weight' => -8,
'type' => MENU_NORMAL_ITEM,
);
$items['planificacion/%ente_planificador_menu/explicacion/%tipo_plan/%node/causas/agregar'] = array(
'title' => t('Agregar Causas'),
'page callback' => 'drupal_get_form',
'page arguments' => array('ente_planificador_causas_editar_form', 1, 3, 4),
'access callback' => '_get_situacion_explicacion_acceso',
'access arguments' => array(1, 3, 4),
'weight' => -8,
'type' => MENU_NORMAL_ITEM,
);
$items['planificacion/%ente_planificador_menu/explicacion/%tipo_plan/%node/causas/%lcausa'] = array(
'title' => t('Editar Causa'),
'page callback' => 'drupal_get_form',
'page arguments' => array('ente_planificador_causas_editar_form', 1, 3, 4, 6),
'access callback' => '_get_situacion_explicacion_acceso',
'access arguments' => array(1, 3, 4),
'weight' => -8,
'type' => MENU_NORMAL_ITEM,
);
$items['planificacion/%ente_planificador_menu/explicacion/%tipo_plan/%node/cambios'] = array(
'title' => t('Editar descriptor'),
'page callback' => 'drupal_get_form',
'page arguments' => array('ente_planificador_cambios_situacion_actual_seleccionar_form', 1, 3, 4),
'access callback' => '_get_situacion_explicacion_acceso',
'access arguments' => array(1, 3, 4),
'weight' => -8,
'type' => MENU_NORMAL_ITEM,
);
$items['planificacion/%ente_planificador_menu/explicacion/%tipo_plan/%node/cambios/ver'] = array(
'title' => t('Causas'),
'page callback' => '_ente_planificador_cambios_situacion_actual_ver',
'page arguments' => array( 1, 3, 4),
'access callback' => '_get_situacion_explicacion_acceso',
'access arguments' => array(1, 3, 4),
'weight' => -8,
'type' => MENU_NORMAL_ITEM,
);
$items['planificacion/%ente_planificador_menu/explicacion/%tipo_plan/%node/cambios/agregar'] = array(
'title' => t('Agregar Cambios'),
'page callback' => 'drupal_get_form',
'page arguments' => array('ente_planificador_cambios_editar_form', 1, 3, 4),
'access callback' => '_get_situacion_explicacion_acceso',
'access arguments' => array(1, 3, 4),
'weight' => -8,
'type' => MENU_NORMAL_ITEM,
);
$items['planificacion/%ente_planificador_menu/explicacion/%tipo_plan/%node/cambios/%lcambios'] = array(
'title' => t('Editar Cambio'),
'page callback' => 'drupal_get_form',
'page arguments' => array('ente_planificador_cambios_editar_form', 1, 3, 4, 6),
'access callback' => '_get_situacion_explicacion_acceso',
'access arguments' => array(1, 3, 4),
'weight' => -8,
'type' => MENU_NORMAL_ITEM,
);
$items['planificacion_cambios_pdlp_js'] = array(
'title' => 'Ente Planificador',
'page callback' => 'planificacion_cambios_pdlp_js',
'access arguments' => array('ver planificador'),
'type' => MENU_CALLBACK,
);
//configuracion Explicación Situacional
$items['admin/settings/ente_planificador/explicacion'] = array(
'title' => t('Explicación Situacional'),
'page callback' => 'drupal_get_form',
'page arguments' => array('situacional_actual_preliminar_admin_settings'),
'access arguments' => array('admin planificador'),
'type' => MENU_LOCAL_TASK,
'file' => 'situacional_actual_preliminar.admin.inc',
);
$items['admin/settings/ente_planificador/explicacion/configurar'] = array(
'title' => t('Configurar'),
'type' => MENU_DEFAULT_LOCAL_TASK,
);
return $items;
}
/*
* Implementation of tipo_plan_load()
* Lee el tipo de plan para el menu
*/
function tipo_plan_load($id = 0) {
$plan = _situacion_actual_preliminar_get_planns();
return isset($plan[$id]) ? $plan[$id] : FALSE;
}
/*
* Implementation of tipo_plan_load()
* Lee la causa para el menu
*/
function lcausa_load($nid) {
if ($nid && is_numeric($nid)) {
$causa = node_load($nid);
if ($causa && $causa->type == 'causas') {
return $causa;
}
}
return FALSE;
}
/*
* Implementation of tipo_plan_load()
* Lee el cambio para el menu
*/
function lcambios_load($nid) {
if ($nid && is_numeric($nid)) {
$causa = node_load($nid);
if ($causa && $causa->type == 'cambios') {
return $causa;
}
}
return FALSE;
}
/*
* Implementation of ente_planificador_descriptores_editar_form()
* Agregar o editar descriptores
*/
function ente_planificador_descriptores_editar_form($form_state, $ente_planificador, $tipo_plan = array(), $node = 0) {
global $user;
$mi_fecha = ente_planificador_user_acceso_proceso($tipo_plan['plan'], $ente_planificador->tipo);
$current_time = time();
$fecha = FALSE;
if ($mi_fecha[1] + 86399 > $current_time && $mi_fecha[0] < $current_time) {
$fecha = TRUE;
}
if (!$fecha) {
muestra_mensaje($tipo_plan['plan'], $ente_planificador);
}
else {
$ente = usuario_tiene_ente($user->uid);
if ($ente->nid == $ente_planificador->nid) {
muestra_mensaje($tipo_plan['plan'], $ente_planificador, 0);
}
}
$titulo = t('Modificar Descriptor');
if (!$node) {
$titulo = t('Agregar Descriptor');
$node = new stdClass();
$node->body = '';
$node->type = 'descriptores';
$node->uid = $user->uid;
$node->title = 'Descriptor-' . $ente_planificador->nid . '-' . time();
$node->field_descriptores_planificador[0]['nid'] = $ente_planificador->nid;
$campo = 'field_' . $node->type . '_' . $tipo_plan['short'];
$node->{$campo}[0]['value'] = 1;
}
drupal_set_title($titulo);
$form = array();
$form['#ente_planificador'] = $ente_planificador;
$form['#node'] = $node;
if (variable_get('situacion_actual_acronimo', false)) {
$form['title'] = array(
'#type' => 'textfield',
'#title' => t('Acrónimo del Descriptor'),
'#required' => TRUE,
'#default_value' => $node->title,
'#maxlength' => 255,
'#weight' => -5,
'#description' => t('Introduzca el acrónimo del descriptor para facilitar su busqueda. Es deseable que este sea único para facilitar su distinción entre otros descriptores.'),
);
}
$form['descriptor'] = array(
'#type' => 'textarea',
'#title' => t('Descriptor'),
'#description' => t('Introduzca el Descriptor de la situación actual.'),
'#default_value' => $node->body,
'#required' => TRUE,
);
//Se agregan otros campos
$node_type = content_types($form['#node']->type);
$fields = $node_type['fields'];
$field_form = array();
$fields_form = array();
$arreglo = array(
'field_descriptores_clasificacion' => 'field_descriptores_clasificacion',
);
if (is_array($fields) && count($fields)) {
foreach($fields as $field_id => $field) {
if (array_key_exists($field_id, $arreglo)) {
$field_form[] = $field_id;
$fields_form[] = $field_id;
}
}
}
if (is_array($field_form) && count($field_form)) {
module_load_include('inc', 'content', 'includes/content.node_form');
foreach ($field_form as $field_id) {
$field = content_fields($field_id, $form['#node']->type);
$form['#field_info'][$field_id] = $field;
$form += (array) content_field_form($form, $form_state, $field);
}
}
$form['#' . $form['#node']->type . '_campos'] = $fields;
$form['#' . $form['#node']->type . '_fields'] = $fields_form;
$form['buttons']['#weight'] = 100;
$form['buttons']['submit'] = array(
'#type' => 'submit',
'#value' => t('Submit'),
'#weight' => 20
);
$form['buttons']['cancel'] = array(
'#type' => 'submit',
'#value' => t('Cancel'),
'#weight' => 21
);
return $form;
}
/*
* Implementation of ente_planificador_descriptores_editar_form_validate()
* Validar Agregar o editar descriptores
*/
function ente_planificador_descriptores_editar_form_validate($form, &$form_state) {
$op = isset($form_state['values']['op']) ? $form_state['values']['op'] : '';
if ($op == t('Cancel')) {
if ($_REQUEST['destination']) {
$redirect = $_REQUEST['destination'];
}
else {
// add redirect
$redirect = $_GET['q'];
}
drupal_goto($redirect);
return;
}
if (trim($form_state['values']['descriptor']) == '') {
form_set_error('descriptor', t('Debe agregar el Descriptor de la situación actual'));
}
return;
}
/*
* Implementation of ente_planificador_descriptores_editar_form_submit()
*/
function ente_planificador_descriptores_editar_form_submit($form, &$form_state) {
$op = isset($form_state['values']['op']) ? $form_state['values']['op'] : '';
if ($op == t('Cancel')) {
return;
}
module_load_include('inc', 'node', 'node.pages');
$node = $form['#node'];
node_object_prepare($node);
$form_state['values']['descriptor'] = check_plain($form_state['values']['descriptor']);
if (variable_get('situacion_actual_acronimo', false)) {
$node->title = check_plain($form_state['values']['title']);
}
else {
$node->title = substr($form_state['values']['descriptor'], 0, 244);
}
$node->body = $form_state['values']['descriptor'];
//crear una nueva revision
$nuevo = TRUE;
if ($node->nid) {
$nuevo = FALSE;
$node->log = t('Modificados los datos del descriptor @date', array('@date' => date('d-m-Y', time())));
$node->revision = 1;
}
$node->field_descriptores_year[0]['value'] = variable_get('situacional_actual_preliminar_anho_creacion', 0);
$field_form = $form['#' . $form['#node']->type . '_fields'];
if (module_exists('hs_content_taxonomy')) {
foreach ($form['#field_info'] as $field_name => $field_info) {
if ($field_info['widget']['type'] == 'content_taxonomy_hs') {
// Change format of values to the one Content Taxonomy expects
if (is_array($form_state['values'][$field_name]['tids'])) {
$values = array();
foreach($form_state['values'][$field_name]['tids'] as $tid) {
$values[] = array('value' => $tid);
array_unshift($form_state['values'][$field_name], array('value' => $tid));
}
$form_state['values'][$field_name]['tids'] = $values;
}
else {
$values[] = array('value' => $form_state['values'][$field_name]['tids']);
array_unshift($form_state['values'][$field_name],array('value' => $form_state['values'][$field_name]['tids']));
$form_state['values'][$field_name]['tids'] = $values;
}
}
}
}
if (module_exists('hs_content_taxonomy_description')) {
foreach ($form['#field_info'] as $field_name => $field_info) {
if ($field_info['widget']['type'] == 'content_taxonomy_hsd') {
// Change format of values to the one Content Taxonomy expects
if (is_array($form_state['values'][$field_name]['tids'])) {
$values = array();
foreach($form_state['values'][$field_name]['tids'] as $tid) {
$values[] = array('value' => $tid);
array_unshift($form_state['values'][$field_name], array('value' => $tid));
}
$form_state['values'][$field_name]['tids'] = $values;
}
else {
$values[] = array('value' => $form_state['values'][$field_name]['tids']);
array_unshift($form_state['values'][$field_name],array('value' => $form_state['values'][$field_name]['tids']));
$form_state['values'][$field_name]['tids'] = $values;
}
}
}
}
module_load_include('inc', 'node', 'node.pages');
$form_values = $form_state['values'];
if (is_array($field_form) && count($field_form)) {
foreach ($field_form as $field_id) {
if (isset($form_values[$field_id]) && is_array($form_values[$field_id])) {
foreach($form_values[$field_id] as $id => $value) {
if (is_numeric($id) && isset($form_values[$field_id][$id]['_error_element'])) {
unset($form_values[$field_id][$id]['_error_element']);
}
}
$node->{$field_id} = $form_values[$field_id];
}
}
}
node_save($node);
$form['#node'] = $node;
if ($nuevo) {
drupal_set_message(t('Se agregó el descriptor @title', array('@title' => $node->body)));
}
else {
drupal_set_message(t('Se modificó el descriptor @title', array('@title' => $node->body)));
}
}
/**
* Implementation of ente_planificador_descriptores_eliminar_form()
* Eliminar descriptores
*/
function ente_planificador_descriptores_eliminar_form($form_state, $ente_planificador, $tipo_plan = array(), $descriptor = 0) {
global $user;
$mi_fecha = ente_planificador_user_acceso_proceso($tipo_plan['plan'], $ente_planificador->tipo);
$current_time = time();
$fecha = FALSE;
if ($mi_fecha[1] + 86399 > $current_time && $mi_fecha[0] < $current_time) {
$fecha = TRUE;
}
if (!$fecha) {
muestra_mensaje($tipo_plan['plan'], $ente_planificador);
}
else {
$ente = usuario_tiene_ente($user->uid);
if ($ente->nid == $ente_planificador->nid) {
muestra_mensaje($tipo_plan['plan'], $ente_planificador, 0);
}
}
$form = array();
$form['#node'] = $descriptor;
$form['#ente_planificador'] = $ente_planificador;
$form['#tipo_plan'] = $tipo_plan;
$form['#ac'] = $ac;
$message = t('Esta seguro de eliminar el descriptor @nombre?', array('@nombre' => $descriptor->body));
$caption = '
'. t('This action cannot be undone.') .'
';
$return_path = $_REQUEST['destination'] ? $_REQUEST['destination'] : 'planificacion/' . $ente_planificador->nid . '/explicacion/' . $tipo_plan['plan'];
return confirm_form($form, $message, $return_path, $caption, t('Eliminar'));
}
/**
* Implementation of ente_planificador_descriptores_eliminar_form_submit().
* Process funcion delete descriptores.
*/
function ente_planificador_descriptores_eliminar_form_submit($form, &$form_state) {
module_load_include('inc', 'node', 'node.pages');
$descriptor = $form['#node'];
$campo = 'field_descriptores_' . $form['#tipo_plan']['short'];
$descriptor->{$campo}[0]['value'] = 0;
$descriptor->log = t('Se elimino el descriptor de la fase (@fase) @date', array('@fase' => $form['#tipo_plan']['plan'], '@date' => date('d-m-Y', time())));
$descriptor->revision = 1;
node_save($descriptor);
drupal_set_message(t('Se eliminó el descriptor @title', array('@title' => $descriptor->body)));
}
/*
* Implementation of _sap_tipo_causa()
* list causes type
*/
function _sap_tipo_causa() {
$type = array(
'rule' => t('Rule'),
'accumulation' => t('Accumulation'),
'flow' => t('Flow'),
);
return $type;
}
/*
* Implementation of _sap_nivel_control()
* list causes level
*/
function _sap_nivel_control() {
$nivel = array(
'control' => t('Under absolute control of the actors planners'),
'shared' => t('Under shared control with other actors'),
'out' => t('Beyond the control of planners actors'),
);
return $nivel;
}
/*
* Implementation of _ente_planificador_causas_ver()
* Consultar las causas de un descriptor
*/
function _ente_planificador_causas_ver($ente_planificador, $tipo_plan = array(), $descriptor = 0) {
global $user;
$mi_fecha = ente_planificador_user_acceso_proceso($tipo_plan['plan'], $ente_planificador->tipo);
$current_time = time();
$fecha = FALSE;
if ($mi_fecha[1] + 86399 > $current_time && $mi_fecha[0] < $current_time) {
$fecha = TRUE;
}
if (!$fecha) {
muestra_mensaje($tipo_plan['plan'], $ente_planificador);
}
else {
$ente = usuario_tiene_ente($user->uid);
if ($ente->nid == $ente_planificador->nid) {
muestra_mensaje($tipo_plan['plan'], $ente_planificador, 0);
}
}
drupal_set_title(t('Causas del descriptor "@name"', array('@name' => $descriptor->body)));
//se obtienen las causas que han sido seleccionadas
$causas_select = array();
$causas_sql = array();
$causas_input = array();
$acceso = _get_situacion_explicacion_acceso($ente_planificador, $tipo_plan, $descriptor);
$sql = "SELECT c.nid, n.title, nr.body, c.field_tipo_causa_value, c.field_causa_control_value FROM {content_type_causas} AS c INNER JOIN {node} AS n ON c.nid = n.nid AND c.vid = n.vid INNER JOIN {node_revisions} AS nr ON c.nid = nr.nid AND c.vid = nr.vid WHERE c.field_ente_planifiador_nid = %d AND c.field_causas_year_value = %d";
$sql .= ' AND c.field_causas_' . $tipo_plan['short'] . '_value = %d';
$inputs = array();
$inputs[] = $ente_planificador->nid;
$inputs[] = $descriptor->field_descriptores_year[0]['value'];
$inputs[] = 1;
foreach($descriptor->field_descriptores_causa as $causa) {
if ($causa['nid']) {
$causas_select[$causa['nid']] = 1;
$causas_sql[] = '%d';
$inputs[] = $causa['nid'];
}
}
if (count($causas_sql)) {
$sql .= ' AND c.nid IN (' . implode(',', $causas_sql) . ')';
}
$sql .= ' ORDER BY c.nid';
$result = db_query($sql, $inputs);
$causas = array();
$headers_table = array();
$headers_table[] = array('data' => t('Causa Critica'));
$headers_table[] = array('data' => t('Formas de Solución'));
$headers_table[] = array('data' => t('Tipo de Causa'));
$headers_table[] = array('data' => t('Nivel de Control'));
if ($acceso) {
$headers_table[] = array('data' => t('Acción'));
}
$rows = array();
$type = _sap_tipo_causa();
$level = _sap_nivel_control();
while($causa = db_fetch_object($result)) {
if (isset($causas_select[$causa->nid])) {
$causa_load = node_load($causa->nid);
$row = array();
$row[] = array('data' => $causa_load->body);
$solucions = array();
foreach($causa_load->field_causa_solucion as $solucion) {
$solucions[] = $solucion['value'];
}
$row[] = array('data' => theme('item_list', $solucions));
$row[] = array('data' => $type[$causa_load->field_tipo_causa[0]['value']]);
$row[] = array('data' => $level[$causa_load->field_causa_control[0]['value']]);
if ($acceso) {
$url = l(t('Editar Causa'), 'planificacion/' . $ente_planificador->nid . '/explicacion/' . $tipo_plan['plan'] . '/' . $descriptor->nid . '/causas/' . $causa_load->nid . '/editar');
if ($_REQUEST['destination']) {
$url = l(t('Editar Causa'), 'planificacion/' . $ente_planificador->nid . '/explicacion/' . $tipo_plan['plan'] . '/' . $descriptor->nid . '/causas/' . $causa_load->nid . '/editar', array('query' => array('destination' => $_REQUEST['destination'])));
}
$row[] = array('data' => $url);
}
$rows[] = $row;
}
}
if (!count($rows)) {
$row = array();
$row[] = array('data' => t('No se encontrarón causas para este descriptor'), 'colspan' => count($headers_table));
$rows[] = $row;
}
$url = $_REQUEST['destination'] ? $_REQUEST['destination'] : 'planificacion/' . $ente_planificador->nid . '/explicacion/' . $tipo_plan['plan'];
$links = array();
//$links[] = l(t('Modificar Causas'), 'planificacion/' . $ente_planificador->nid . '/explicacion/' . $tipo_plan['plan'] . '/' . $descriptor->nid . '/causas', array('query' => array('destination' => $url)));
$links[] = l(t('Regresar'), $url);
return theme('table', $headers_table, $rows) . theme('item_list', $links);
}
/*
* Implementation of ente_planificador_causas_editar_form()
* Agregar o editar causas a descriptores
*/
function ente_planificador_causas_seleccionar_form($form_state, $ente_planificador, $tipo_plan = array(), $descriptor = 0) {
global $user;
$mi_fecha = ente_planificador_user_acceso_proceso($tipo_plan['plan'], $ente_planificador->tipo);
$current_time = time();
$fecha = FALSE;
if ($mi_fecha[1] + 86399 > $current_time && $mi_fecha[0] < $current_time) {
$fecha = TRUE;
}
if (!$fecha) {
muestra_mensaje($tipo_plan['plan'], $ente_planificador);
}
else {
$ente = usuario_tiene_ente($user->uid);
if ($ente->nid == $ente_planificador->nid) {
muestra_mensaje($tipo_plan['plan'], $ente_planificador, 0);
}
}
drupal_set_title(t('Agregar causas'));
$form = array();
//se obtienen las causas
$causas_select = array();
foreach($descriptor->field_descriptores_causa as $causa) {
if ($causa['nid']) {
$causas_select[$causa['nid']] = 1;
}
}
$sql = "SELECT c.nid, n.title, nr.body, c.field_tipo_causa_value, c.field_causa_control_value FROM {content_type_causas} AS c INNER JOIN {node} AS n ON c.nid = n.nid AND c.vid = n.vid INNER JOIN {node_revisions} AS nr ON c.nid = nr.nid AND c.vid = nr.vid WHERE c.field_ente_planifiador_nid = %d AND c.field_causas_year_value = %d";
$sql .= ' AND c.field_causas_' . $tipo_plan['short'] . '_value = %d ORDER BY c.nid';
$inputs = array();
$inputs[] = $ente_planificador->nid;
$inputs[] = $descriptor->field_descriptores_year[0]['value'];
$inputs[] = 1;
$result = db_query($sql, $inputs);
$causas = array();
$prefijo = '';
$prefijo .= '' . t('Seleccionar') . ' | ' . t('Causa Critica') . ' | ' . t('Formas de Solución') . ' | ' . t('Tipo de Causa') . ' | ' . t('Nivel de Control') . ' | ' . t('Acción') . ' |
';
while($causa = db_fetch_object($result)) {
$causas[$causa->nid] = $causa;
}
$form = array();
$causas_load = array();
if (!count($causas)) {
$prefijo .= '' . t('No se han ingresado causas criticas') . ' |
';
//$prefijo .= '
';
$form['seleccionar'] = array(
'#value' => $prefijo,
);
}
else {
$type = _sap_tipo_causa();
$level = _sap_nivel_control();
foreach($causas as $causa) {
$causa_load = node_load($causa->nid);
if ($causa_load) {
$causas_load[$causa_load->nid] = $causa_load;
$solucions = array();
foreach($causa_load->field_causa_solucion as $solucion) {
$solucions[] = $solucion['value'];
}
$url = l(t('Editar Causa'), 'planificacion/' . $ente_planificador->nid . '/explicacion/' . $tipo_plan['plan'] . '/' . $descriptor->nid . '/causas/' . $causa_load->nid . '/editar');
if ($_REQUEST['destination']) {
$url = l(t('Editar Causa'), 'planificacion/' . $ente_planificador->nid . '/explicacion/' . $tipo_plan['plan'] . '/' . $descriptor->nid . '/causas/' . $causa_load->nid . '/editar', array('query' => array('destination' => $_REQUEST['destination'])));
}
$suffix = '' . $causa_load->body . ' | ' . theme('item_list', $solucions) . ' | ' . $type[$causa_load->field_tipo_causa[0]['value']] . ' | ' . $level[$causa_load->field_causa_control[0]['value']] . ' | ' . $url . ' | ';
$form['seleccionar_' . $causa_load->nid] = array(
'#type' => 'checkbox',
'#title' => '',
'#default_value' => $causas_select[$causa_load->nid],
'#prefix' => $prefijo . '',
'#suffix' =>$suffix,
);
$prefijo = '';
}
}
//$form['seleccionar_' . $causa_load->nid]['#suffix'] .= '';
}
$form['#ente_planificador'] = $ente_planificador;
$form['#descriptor'] = $descriptor;
$form['#tipo_plan'] = $tipo_plan;
$form['#causas_load'] = $causas_load;
$form['#causas_select'] = $causas_select;
$form['buttons']['#weight'] = 100;
$prefijo .= ' |
';
$form['agregar'] = array(
'#type' => 'submit',
'#prefix' => ' |
',
'#suffix' => ' |
',
'#value' => t('Agregar Causas'),
);
if (count($form['#causas_load'])) {
$form['buttons']['submit'] = array(
'#type' => 'submit',
'#value' => t('Seleccionar Causas'),
'#weight' => 100,
);
}
$form['buttons']['cancel'] = array(
'#type' => 'submit',
'#value' => t('Regresar'),
'#weight' => 101,
);
return $form;
}
/*
* Implementation of ente_planificador_causas_editar_form_validate()
* Validar Agregar o editar causas
*/
function ente_planificador_causas_seleccionar_form_validate($form, &$form_state) {
$op = isset($form_state['values']['op']) ? $form_state['values']['op'] : '';
if ($op == t('Regresar') || $op == t('Agregar Causas')) {
return;
}
if (count($form['#causas_load'])) {
$seleccionado = FALSE;
foreach($form['#causas_load'] as $causa) {
if ($form_state['values']['seleccionar_' . $causa->nid]) {
$seleccionado = TRUE;
}
}
if (!$seleccionado) {
form_set_error('seleccionar_' . $causa->nid, t('Debe seleccionara al menos una causa'));
}
}
return;
}
/*
* Implementation of ente_planificador_causas_seleccionar_form_submit()
*/
function ente_planificador_causas_seleccionar_form_submit($form, &$form_state) {
$op = isset($form_state['values']['op']) ? $form_state['values']['op'] : '';
if ($op == t('Regresar')) {
return;
}
if ($op == t('Agregar Causas')) {
if ($_REQUEST['destination']) {
$form_state['redirect'] = url('planificacion/' . $form['#ente_planificador']->nid . '/explicacion/' . $form['#tipo_plan']['plan'] . '/' . $form['#descriptor']->nid . '/causas/agregar',
array(
'query' => array(
'destination' => $_REQUEST['destination'],
),
'absolute' => TRUE,
)
);
unset($_REQUEST['destination']);
}
else {
// add redirect
$form_state['redirect'] = 'planificacion/' . $form['#ente_planificador']->nid . '/explicacion/' . $form['#tipo_plan']['plan'] . '/' . $form['#descriptor']->nid . '/causas/agregar';
}
return;
}
module_load_include('inc', 'node', 'node.pages');
$descriptores_causa = array();
$descriptor = $form['#descriptor'];
if (count($form['#causas_load'])) {
foreach($form['#causas_load'] as $causa) {
if ($form_state['values']['seleccionar_' . $causa->nid]) {
$descriptores_causa[] = array('nid' => $causa->nid);
//se verifica que no ha cambiado la causa
if (!isset($form['#causas_select'][$causa->nid])) {
$causa_load = $form['#causas_load'][$causa->nid];
$causa_load->log = t('Agregado al descriptor @date', array('@date' => date('d-m-Y', time())));
$causa_load->revision = 1;
$causa_load->field_descriptores_causa[]['nid'] = $descriptor->nid;
node_save($causa_load);
}
}
}
}
if (!$encontrado) {
$descriptor->field_descriptores_causa[]['nid'] = $causa->nid;
}
$descriptor->field_descriptores_causa = $descriptores_causa;
$descriptor->log = t('Se seleccionarón las causa del descriptor @date', array('@date' => date('d-m-Y', time())));
$descriptor->revision = 1;
node_save($descriptor);
drupal_set_message(t('Se guardarón las causas del descriptor @title', array('@title' => $descriptor->body)));
}
/*
* Implementation of ente_planificador_causas_editar_form()
* Agregar o editar causas a descriptores
*/
function ente_planificador_causas_editar_form($form_state, $ente_planificador, $tipo_plan = array(), $descriptor = 0, $node = 0) {
global $user;
$mi_fecha = ente_planificador_user_acceso_proceso($tipo_plan['plan'], $ente_planificador->tipo);
$current_time = time();
$fecha = FALSE;
if ($mi_fecha[1] + 86399 > $current_time && $mi_fecha[0] < $current_time) {
$fecha = TRUE;
}
if (!$fecha) {
muestra_mensaje($tipo_plan['plan'], $ente_planificador);
}
else {
$ente = usuario_tiene_ente($user->uid);
if ($ente->nid == $ente_planificador->nid) {
muestra_mensaje($tipo_plan['plan'], $ente_planificador, 0);
}
}
if (!$node) {
$node = new stdClass();
$node->body = '';
$node->type = 'causas';
$node->uid = $user->uid;
$node->title = 'Causa-' . $ente_planificador->nid . '-' . time();
$node->field_ente_planifiador[0]['nid'] = $ente_planificador->nid;
$campo = 'field_' . $node->type . '_' . $tipo_plan['short'];
$node->{$campo}[0]['value'] = 1;
}
$texto = $causa? t('Modificar causa') : t('Agregar causa');
drupal_set_title($texto);
$form['#ente_planificador'] = $ente_planificador;
$form['#descriptor'] = $descriptor;
$form['#node'] = $node;
$form['#tipo_plan'] = $tipo_plan;
if (variable_get('situacion_actual_acronimo', false)) {
$form['title'] = array(
'#type' => 'textfield',
'#title' => t('Acrónimo de la Causa'),
'#required' => TRUE,
'#default_value' => $node->title,
'#maxlength' => 255,
'#weight' => -5,
'#description' => t('Introduzca el acrónimo de la causa para facilitar su busqueda. Es deseable que este sea único para facilitar su distinción entre otros descriptores.'),
);
}
$form['causa'] = array(
'#type' => 'textarea',
'#title' => t('Causa'),
'#description' => t('Introduzca la causa de la situación actual.'),
'#default_value' => $node->body,
'#required' => TRUE,
);
$node_type = content_types('causas');
$fields = $node_type['fields'];
$field_form = array();
$fields_form = array();
$arreglo = array(
'field_causa_solucion' => 'field_causa_solucion',
);
if (is_array($fields) && count($fields)) {
foreach($fields as $field_id => $field) {
if (array_key_exists($field_id, $arreglo)) {
$field_form[] = $field_id;
$fields_form[] = $field_id;
}
}
}
if (is_array($field_form) && count($field_form)) {
module_load_include('inc', 'content', 'includes/content.node_form');
foreach ($field_form as $field_id) {
$field = content_fields($field_id, $form['#node']->type);
$form['#field_info'][$field_id] = $field;
$form += (array) content_field_form($form, $form_state, $field);
}
}
$form['#' . $form['#node']->type . '_campos'] = $fields;
$form['#' . $form['#node']->type . '_fields'] = $fields_form;
$type = _sap_tipo_causa();
$level = _sap_nivel_control();
$form['#type_causa'] = $type;
$form['#type_level'] = $level;
$form['tipo'] = array(
'#type' => 'radios',
'#title' => t('Tipo de Causa'),
'#default_value' => $node->field_tipo_causa[0]['value'],
'#options' => $type,
'#required' => TRUE,
);
$form['level'] = array(
'#type' => 'radios',
'#title' => t('Nivel de Control'),
'#default_value' => $node->field_causa_control[0]['value'],
'#options' => $level,
'#required' => TRUE,
);
$form['buttons']['#weight'] = 100;
$form['buttons']['submit'] = array(
'#type' => 'submit',
'#value' => t('Submit'),
'#weight' => 100,
);
$form['buttons']['cancel'] = array(
'#type' => 'submit',
'#value' => t('Cancel'),
'#weight' => 101,
);
return $form;
}
/*
* Implementation of ente_planificador_causas_editar_form_validate()
* Validar Agregar o editar causas
*/
function ente_planificador_causas_editar_form_validate($form, &$form_state) {
$op = isset($form_state['values']['op']) ? $form_state['values']['op'] : '';
if ($op == t('Cancel')) {
if ($_REQUEST['destination']) {
$redirect = url('planificacion/' . $form['#ente_planificador']->nid . '/explicacion/' . $form['#tipo_plan']['plan'] . '/' . $descriptor->nid . '/causas',
array(
'query' => array(
'destination' => $_REQUEST['destination'],
),
'absolute' => TRUE,
)
);
}
else {
// add redirect
$redirect = 'planificacion/' . $form['#ente_planificador']->nid . '/explicacion/' . $form['#tipo_plan']['plan'] . '/' . $descriptor->nid . '/causas';
}
drupal_goto($redirect);
return;
}
if (trim($form_state['values']['causa']) == '') {
form_set_error('causa', t('Debe agregar la causa de la situación actual'));
}
return;
}
/*
* Implementation of ente_planificador_descriptores_editar_form_submit()
*/
function ente_planificador_causas_editar_form_submit($form, &$form_state) {
$op = isset($form_state['values']['op']) ? $form_state['values']['op'] : '';
if ($op == t('Cancel')) {
return;
}
module_load_include('inc', 'node', 'node.pages');
$causa = $form['#node'];
$descriptor = $form['#descriptor'];
node_object_prepare($descriptor);
$form_state['values']['descriptor'] = check_plain($form_state['values']['descriptor']);
if (variable_get('situacion_actual_acronimo', false)) {
$causa->title = check_plain($form_state['values']['title']);
}
else {
$causa->title = substr($form_state['values']['causa'], 0, 244);
}
$causa->body = $form_state['values']['causa'];
//crear una nueva revision
$nuevo = TRUE;
if ($causa->nid) {
$nuevo = FALSE;
$causa->log = t('Modificados los datos de la causa @date', array('@date' => date('d-m-Y', time())));
$causa->revision = 1;
}
$encontrado = FAlSE;
if (count($causa->field_descriptores_causa)) {
foreach($causa->field_descriptores_causa as $enlace) {
if ($enlace['nid'] == $descriptor->nid) {
$encontrado = TRUE;
}
}
}
if (!$encontrado) {
$causa->field_descriptores_causa[]['nid'] = $form['#descriptor']->nid;
}
$causa->field_causas_year[0]['value'] = variable_get('situacional_actual_preliminar_anho_creacion', 0);
if ($form['#type_causa'][$form_state['values']['tipo']]) {
$causa->field_tipo_causa[0]['value'] = $form_state['values']['tipo'];
}
if ($form['#type_level'][$form_state['values']['level']]) {
$causa->field_causa_control[0]['value'] = $form_state['values']['level'];
}
$field_form = $form['#' . $form['#node']->type . '_fields'];
module_load_include('inc', 'node', 'node.pages');
$node_load = $form['#node'];
$form_values = $form_state['values'];
if (is_array($field_form) && count($field_form)) {
foreach ($field_form as $field_id) {
if (isset($form_values[$field_id]) && is_array($form_values[$field_id])) {
foreach($form_values[$field_id] as $id => $value) {
if (is_numeric($id) && isset($form_values[$field_id][$id]['_error_element'])) {
unset($form_values[$field_id][$id]['_error_element']);
}
}
$causa->{$field_id} = $form_values[$field_id];
}
}
}
node_save($causa);
$form['#causa'] = $causa;
//se agrega la causa al descriptor
$encontrado = FAlSE;
if (count($descriptor->field_descriptores_causa)) {
foreach($descriptor->field_descriptores_causa as $enlace) {
if ($enlace['nid'] == $causa->nid) {
$encontrado = TRUE;
}
}
}
if (!$encontrado) {
$descriptor->field_descriptores_causa[]['nid'] = $causa->nid;
}
$descriptor->log = t('Se agregó una nueva causa al descriptor @date', array('@date' => date('d-m-Y', time())));
$descriptor->revision = 1;
node_save($descriptor);
if ($nuevo) {
drupal_set_message(t('Se agregó la causa @title', array('@title' => $causa->body)));
}
else {
drupal_set_message(t('Se modificó la causa @title', array('@title' => $causa->body)));
}
if ($_REQUEST['destination']) {
$form_state['redirect'] = url('planificacion/' . $form['#ente_planificador']->nid . '/explicacion/' . $form['#tipo_plan']['plan'] . '/' . $descriptor->nid . '/causas',
array(
'query' => array(
'destination' => $_REQUEST['destination'],
),
'absolute' => TRUE,
)
);
unset($_REQUEST['destination']);
}
else {
// add redirect
$form_state['redirect'] = 'planificacion/' . $form['#ente_planificador']->nid . '/explicacion/' . $form['#tipo_plan']['plan'] . '/' . $descriptor->nid . '/causas';
}
}
/*
* Implementation of _situacion_actual_preliminar_get_pdlp()
* Obtiene los objetivos a considerar del plan de la patria
*/
function _situacion_actual_preliminar_get_pdlp() {
return array(
'historico' => t('Objetivo Historico'),
'nacional' => t('Objetivo Nacional'),
'estrategico' => t('Objetivo Estratégico'),
'generales' => t('Objetivo General'),
'metas' => t('Meta del Plan Campaña Carabobo'),
);
}
/*
* Implementation of _ente_planificador_cambios_situacion_actual_ver()
* Consultar los cambios de un descriptor
*/
function _ente_planificador_cambios_situacion_actual_ver($ente_planificador, $tipo_plan = array(), $descriptor = 0) {
global $user;
$mi_fecha = ente_planificador_user_acceso_proceso($tipo_plan['plan'], $ente_planificador->tipo);
$current_time = time();
$fecha = FALSE;
if ($mi_fecha[1] + 86399 > $current_time && $mi_fecha[0] < $current_time) {
$fecha = TRUE;
}
if (!$fecha) {
muestra_mensaje($tipo_plan['plan'], $ente_planificador);
}
else {
$ente = usuario_tiene_ente($user->uid);
if ($ente->nid == $ente_planificador->nid) {
muestra_mensaje($tipo_plan['plan'], $ente_planificador, 0);
}
}
drupal_set_title(t('Cambios en la Situación Actual del descriptor "@name"', array('@name' => $descriptor->body)));
$headers_table = array();
$array = _situacion_actual_preliminar_get_pdlp();
$acceso = _get_situacion_explicacion_acceso($ente_planificador, $tipo_plan, $descriptor);
$headers_table[] = array('data' => t('Descripción del cambio'));
foreach($array as $id_pdp => $texto) {
$headers_table[] = array('data' => $texto);
}
$headers_table[] = array('data' => t('Meta asociada al cambio'), 'rowspan' => 2);
if ($acceso) {
$headers_table[] = array('data' => t('Acción'), 'rowspan' => 2);
}
$rows = array();
foreach($descriptor->field_descriptor_cambio as $cambio) {
if ($cambio['nid']) {
$cambio_load = node_load($cambio['nid']);
$row = array();
$row[] = array('data' => $cambio_load->body);
$k = 0;
foreach($array as $id_pdp => $texto) {
$texto_out = '';
$term_id = 0;
if ($k < 4 && isset($cambio_load->field_cambios_pdp[$k]['value'])) {
$term_id = $cambio_load->field_cambios_pdp[$k]['value'];
}elseif(!$term_id && $k == 4 && isset($cambio_load->field_cambios_carabobo[0]['value'])) {
$term_id = $cambio_load->field_cambios_carabobo[0]['value'];
}
if ($term_id) {
$term = taxonomy_get_term($term_id);
if ($term && $k < 4) {
$texto_out = $term->name . ' ' . $term->description;
}
else {
$valores = term_fields_get_fields_values($term);
$texto_out = $valores && isset($valores['plan_carabobo_meta_value'])? $valores['plan_carabobo_meta_value'] : '';
}
}
$row[] = array('data' => $texto_out);
$k++;
}
$metas = array();
foreach($cambio_load->field_cambios_meta as $meta) {
$unidad = $meta['tid'];
// If this term's vocabulary supports localization.
$term = taxonomy_get_term($meta['tid']);
if (module_exists('i18ntaxonomy') && i18ntaxonomy_vocabulary($term->vid) == I18N_TAXONOMY_LOCALIZE) {
$term->name = tt("taxonomy:term:$term->tid:name", $term->name);
}
$numero = number_format($meta['value'], $format_number['decimals'], $format_number['dec_point'], $format_number['thousands_sep']);
$metas[] = $numero . ' ' . $term->name;
}
$row[] = array('data' => theme('item_list', $metas));
if ($acceso) {
$url = l(t('Editar Cambio en la situación Actual'), 'planificacion/' . $ente_planificador->nid . '/explicacion/' . $tipo_plan['plan'] . '/' . $descriptor->nid . '/cambios/' . $cambio_load->nid . '/editar');
if ($_REQUEST['destination']) {
$url = l(t('Editar Cambio en la situación Actual'), 'planificacion/' . $ente_planificador->nid . '/explicacion/' . $tipo_plan['plan'] . '/' . $descriptor->nid . '/cambios/' . $cambio_load->nid . '/editar', array('query' => array('destination' => $_REQUEST['destination'])));
}
$row[] = array('data' => $url);
}
$rows[] = $row;
}
}
if (!count($rows)) {
$row = array();
$row[] = array('data' => t('No se encontrarón Cambios en la Situación Actual para este descriptor'), 'colspan' => count($headers_table));
$rows[] = $row;
}
$url = $_REQUEST['destination'] ? $_REQUEST['destination'] : 'planificacion/' . $ente_planificador->nid . '/explicacion/' . $tipo_plan['plan'];
$links = array();
$links[] = l(t('Agregar Cambios en la situación actual'), 'planificacion/' . $ente_planificador->nid . '/explicacion/' . $tipo_plan['plan'] . '/' . $descriptor->nid . '/cambios', array('query' => array('destination' => $url)));
$links[] = l(t('Regresar'), $url);
return theme('table', $headers_table, $rows) . theme('item_list', $links);
}
/*
* Implementation of ente_planificador_cambios_situacion_actual_seleccionar_form()
* Seleccionar cambios en la situacion actual en descriptores
*/
function ente_planificador_cambios_situacion_actual_seleccionar_form($form_state, $ente_planificador, $tipo_plan = array(), $descriptor = 0) {
global $user;
$mi_fecha = ente_planificador_user_acceso_proceso($tipo_plan['plan'], $ente_planificador->tipo);
$current_time = time();
$fecha = FALSE;
if ($mi_fecha[1] + 86399 > $current_time && $mi_fecha[0] < $current_time) {
$fecha = TRUE;
}
if (!$fecha) {
muestra_mensaje($tipo_plan['plan'], $ente_planificador);
}
else {
$ente = usuario_tiene_ente($user->uid);
if ($ente->nid == $ente_planificador->nid) {
muestra_mensaje($tipo_plan['plan'], $ente_planificador, 0);
}
}
drupal_set_title(t('Agregar Cambios en la Situación Actual'));
$form = array();
$cambios_select = array();
foreach($descriptor->field_descriptor_cambio as $cambio) {
if ($cambio['nid']) {
$cambios_select[$cambio['nid']] = 1;
}
}
$array_pdlp = _situacion_actual_preliminar_get_pdlp();
$prefijo = '';
$header = array();
$header[] = t('Eliminar');
$header[] = t('Descripción del cambio');
foreach($array_pdlp as $id_pdp => $texto) {
$header[] = $texto;
}
$header[] = t('Meta asociada al cambio');
$header[] = t('Acción');
$prefijo .= implode(' | ', $header) . ' |
';
$form = array();
$form['#tipo_plan'] = $tipo_plan;
$cambios_load = array();
if (!count($cambios_select)) {
$prefijo .= '' . t('No se han ingresado Cambios en la Situación Actual del descriptor') . ' |
';
$form['seleccionar'] = array(
'#value' => $prefijo,
);
}
else {
foreach($descriptor->field_descriptor_cambio as $cambio) {
$cambio_load = node_load($cambio['nid']);
if ($cambio_load) {
$cambios_load[$cambio_load->nid] = $cambio_load;
$metas = array();
$suffix = '' . $cambio_load->body . ' | ';
$k = 0;
foreach($array_pdlp as $id_pdp => $texto) {
$texto_out = '';
$term_id = 0;
if ($k < 4 && isset($cambio_load->field_cambios_pdp[$k]['value'])) {
$term_id = $cambio_load->field_cambios_pdp[$k]['value'];
}elseif(!$term_id && $k == 4 && isset($cambio_load->field_cambios_carabobo[0]['value'])) {
$term_id = $cambio_load->field_cambios_carabobo[0]['value'];
}
if ($term_id) {
$term = taxonomy_get_term($term_id);
if ($term && $k < 4) {
$texto_out = $term->name . ' ' . $term->description;
}
else {
$valores = term_fields_get_fields_values($term);
$texto_out = $valores && isset($valores['plan_carabobo_meta_value'])? $valores['plan_carabobo_meta_value'] : '';
}
}
$suffix .= '' . $texto_out . ' | ';
$k++;
}
foreach($cambio_load->field_cambios_meta as $meta) {
$unidad = $meta['tid'];
// If this term's vocabulary supports localization.
$term = taxonomy_get_term($meta['tid']);
if (module_exists('i18ntaxonomy') && i18ntaxonomy_vocabulary($term->vid) == I18N_TAXONOMY_LOCALIZE) {
$term->name = tt("taxonomy:term:$term->tid:name", $term->name);
}
$numero = number_format($meta['value'], $format_number['decimals'], $format_number['dec_point'], $format_number['thousands_sep']);
$metas[] = $numero . ' ' . $term->name;
}
$suffix .= '' . theme('item_list', $metas) . ' | ';
$url = l(t('Editar Cambio en la situación Actual'), 'planificacion/' . $ente_planificador->nid . '/explicacion/' . $form['#tipo_plan']['plan'] . '/' . $descriptor->nid . '/cambios/' . $cambio_load->nid . '/editar');
if ($_REQUEST['destination']) {
$url = l(t('Editar Cambio en la situación Actual'), 'planificacion/' . $ente_planificador->nid . '/explicacion/' . $form['#tipo_plan']['plan'] . '/' . $descriptor->nid . '/cambios/' . $cambio_load->nid . '/editar', array('query' => array('destination' => $_REQUEST['destination'])));
}
$suffix .= '' . $url . ' | ';
$pdlp = '';
if (isset($cambio_load->field_cambios_pdp[$cant - 1]['value'])) {
$term = taxonomy_get_term($cambio_load->field_cambios_pdp[$cant - 1]['value']);
if ($term) {
$pdlp = $term->name . ' ' . $term->description;
}
}
$carabobo = '';
if (isset($cambio_load->field_cambios_carabobo[0]['value'])) {
$term = taxonomy_get_term($cambio_load->field_cambios_carabobo[0]['value']);
if ($term) {
$valores = term_fields_get_fields_values($term);
if ($valores && isset($valores['plan_carabobo_meta_value'])) {
$carabobo = $valores['plan_carabobo_meta_value'];
}
}
}
$form['seleccionar_' . $cambio_load->nid] = array(
'#type' => 'checkbox',
'#title' => '',
'#default_value' => 0,
'#prefix' => $prefijo . '',
'#suffix' =>$suffix,
);
$prefijo = '';
}
}
//$form['seleccionar_' . $cambio_load->nid]['#suffix'] .= ' |
';
}
$form['#ente_planificador'] = $ente_planificador;
$form['#descriptor'] = $descriptor;
$form['#array_pdlp'] = $array_pdlp;
$form['#cambios_load'] = $cambios_load;
$form['#cambios_select'] = $cambios_select;
$form['buttons']['#weight'] = 1000;
$form['agregar'] = array(
'#type' => 'submit',
'#prefix' => '',
'#suffix' => ' |
',
'#value' => t('Agregar Cambio en la Situación Actual'),
);
if (count($form['#cambios_load'])) {
$form['buttons']['submit'] = array(
'#type' => 'submit',
'#value' => t('Eliminar Cambios en la Situación Actual'),
'#weight' => 99,
);
}
$form['buttons']['cancel'] = array(
'#type' => 'submit',
'#value' => t('Regresar'),
'#weight' => 101,
);
return $form;
}
/*
* Implementation of ente_planificador_cambios_situacion_actual_seleccionar_form_validate()
* Validar Agregar o editar cambios
*/
function ente_planificador_cambios_situacion_actual_seleccionar_form_validate($form, &$form_state) {
$op = isset($form_state['values']['op']) ? $form_state['values']['op'] : '';
if ($op == t('Regresar') || $op == t('Agregar Cambio en la Situación Actual')) {
return;
}
if (count($form['#cambios_load'])) {
$seleccionado = FALSE;
foreach($form['#cambios_load'] as $cambio) {
if ($form_state['values']['seleccionar_' . $cambio->nid]) {
$seleccionado = TRUE;
}
}
if (!$seleccionado) {
form_set_error('seleccionar_' . $cambio->nid, t('Debe seleccionar al menos un Cambio en la Situación Actual para eliminar'));
}
}
return;
}
/*
* Implementation of ente_planificador_cambios_situacion_actual_seleccionar_form_submit()
*/
function ente_planificador_cambios_situacion_actual_seleccionar_form_submit($form, &$form_state) {
$op = isset($form_state['values']['op']) ? $form_state['values']['op'] : '';
if ($op == t('Regresar')) {
return;
}
if ($op == t('Agregar Cambio en la Situación Actual')) {
if ($_REQUEST['destination']) {
$form_state['redirect'] = url('planificacion/' . $form['#ente_planificador']->nid . '/explicacion/' . $form['#tipo_plan']['plan'] . '/' . $form['#descriptor']->nid . '/cambios/agregar',
array(
'query' => array(
'destination' => $_REQUEST['destination'],
),
'absolute' => TRUE,
)
);
unset($_REQUEST['destination']);
}
else {
// add redirect
$form_state['redirect'] = 'planificacion/' . $form['#ente_planificador']->nid . '/explicacion/' . $form['#tipo_plan']['plan'] . '/' . $form['#descriptor']->nid . '/cambios/agregar';
}
return;
}
module_load_include('inc', 'node', 'node.pages');
$descriptores_cambio = array();
$descriptor = $form['#descriptor'];
$borrados = array();
if (count($form['#cambios_load'])) {
foreach($form['#cambios_load'] as $cambio) {
if (!$form_state['values']['seleccionar_' . $cambio->nid]) {
$descriptores_cambio[] = array('nid' => $cambio->nid);
}
else {
$borrados[] = $cambio->nid;
}
}
}
if (count($borrados)) {
$descriptor->field_descriptor_cambio = $descriptores_cambio;
$descriptor->log = t('Se eliminarón los Cambios en la Situación Actual (@borrados) del descriptor @date', array('@borrados' => implode(', ', $borrados),'@date' => date('d-m-Y', time())));
}
$descriptor->revision = 1;
node_save($descriptor);
drupal_set_message(t('Se guardarón los Cambios en la Situación Actual del descriptor @title', array('@title' => $descriptor->body)));
}
/*
* Implementation of _ente_planificador_cambios_taxonomy()
* Obtiene los terminos hijos de un termino dado y su taxonomia
*/
function _ente_planificador_cambios_taxonomy($vid = 0, $tid = 0) {
$result = db_query(db_rewrite_sql('SELECT t.tid, t.*, parent FROM {term_data} t INNER JOIN {term_hierarchy} h ON t.tid = h.tid WHERE t.vid = %d AND h.parent = %d ORDER BY weight, name', 't', 'tid'), $vid, $tid);
$terms = array();
while ($term = db_fetch_object($result)) {
$terms[$term->tid] = $term->name . ' ' . $term->description;
}
return $terms;
}
/*
* planificacion_cambios_pdlp_js
* Genera el plan de la patria
*/
function planificacion_cambios_pdlp_js($func) {
$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);
$array = $form['#pdlp'];
$opens_div = '';
$i = 0;
$term_id = 0;
$encontrado = FALSE;
$new_form = array();
$terms = array();
$node_type = content_types('cambios');
$fields = $form['#' . $form['#node']->type . '_campos'];
$vid = $fields['field_cambios_pdp']['vid'];
$inputs_metas = array();
$inputs_metas_sql = array();
$inputs = array();
$inputs[] = $vid;
foreach ($array as $id => $texto) {
$valor = intval($_POST[$id]);
if (!$encontrado && $valor > 0) {
$inputs[] = $valor;
$inputs_metas_sql[] = '%d';
}
if ($encontrado) {
if ($id != 'metas') {
$terms = array(0 => t('Seleccione'),);
if ($term_id || $i == 0) {
$terms += _ente_planificador_cambios_taxonomy($vid, $term_id);
}
$form['pdlp'][$id] = array(
'#type' => 'select',
'#title' => t('Objetivo @tipo', array('@tipo' => $texto)),
'#default_value' => $term_id,
'#options' => $terms,
'#description' => t('Seleccione el Objetivo @tipo.', array('@tipo' => $texto)),
'#required' => TRUE,
'#ahah' => array(
'event' => 'change',
'path' => 'planificacion_cambios_pdlp_js/' . $id,
'wrapper' => 'situacion_preliminar_' . $id,
'method' => 'replace',
'progress' => array('type' => 'bar', 'message' => t('Please wait...')),
),
);
$term_id = 0;
$ant_term = 0;
}
else {
$terms = array(0 => t('Seleccione'),);
if (count($inputs)) {
$sql = 'SELECT f.plan_carabobo_meta_value AS meta, f.tid FROM {term_fields_term} AS f INNER JOIN {term_data} AS t ON t.tid = f.plan_carabobo_relations_value AND t.vid = %d WHERE f.plan_carabobo_relations_value IN (' . implode(', ', $inputs_metas_sql) . ')';
$result = db_query($sql, $inputs);
$j = 1;
while ($termino = db_fetch_object($result)) {
$meta = trim($termino->meta);
if ($meta != '') {
$terms[$termino->tid] = '(' . $j . ') ' . $meta;
$j++;
}
}
}
$form['pdlp'][$id] = array(
'#type' => 'select',
'#title' => t('@texto_metas (cantidad de metas: @metas)', array('@texto_metas' => $texto, '@metas' => $j - 1)),
'#default_value' => 0,
'#options' => $terms,
'#description' => t('Seleccione la meta del Plan Campaña de Carabobo.'),
);
}
$form['pdlp'][$id]['#prefix'] = '';
$opens_div .= '
';
$i++;
}
if ($id == $func) {
$encontrado = TRUE;
$term_id = intval($_POST[$id]) > 0 ? intval($_POST[$id]) : 0;
}
}
if ($encontrado) {
$form['pdlp'][$id]['#suffix'] = $opens_div;
}
//$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);
$encontrado = FALSE;
$new_form = array();
foreach ($array as $id => $texto) {
if ($id == $func) {
$encontrado = TRUE;
}
if ($encontrado) {
$new_form[$id] = $form['pdlp'][$id];
}
}
$output = drupal_render($new_form);
print drupal_to_js(array('data' => $output, 'status' => true));
exit();
}
/*
* Implementation of ente_planificador_cambios_editar_form()
* Agregar o editar Cambio en la Situacion Actual
*/
function ente_planificador_cambios_editar_form($form_state, $ente_planificador, $tipo_plan = array(), $descriptor = 0, $node = 0) {
global $user;
$mi_fecha = ente_planificador_user_acceso_proceso($tipo_plan['plan'], $ente_planificador->tipo);
$current_time = time();
$fecha = FALSE;
if ($mi_fecha[1] + 86399 > $current_time && $mi_fecha[0] < $current_time) {
$fecha = TRUE;
}
if (!$fecha) {
muestra_mensaje($tipo_plan['plan'], $ente_planificador);
}
else {
$ente = usuario_tiene_ente($user->uid);
if ($ente->nid == $ente_planificador->nid) {
muestra_mensaje($tipo_plan['plan'], $ente_planificador, 0);
}
}
$texto = $node ? t('Modificar Cambio en la Situación Actual') : t('Agregar Cambio en la Situación Actual');
drupal_set_title($texto);
if (!$node) {
$node = new stdClass();
$node->body = '';
$node->type = 'cambios';
$node->uid = $user->uid;
$node->title = 'Cambios-' . $ente_planificador->nid . '-' . time();
$node->field_cambios_ente[0]['nid'] = $ente_planificador->nid;
$campo = 'field_' . $node->type . '_' . $tipo_plan['short'];
$node->{$campo}[0]['value'] = 1;
}
$form['#tipo_plan'] = $tipo_plan;
$form['#ente_planificador'] = $ente_planificador;
$form['#descriptor'] = $descriptor;
$form['#node'] = $node;
if (variable_get('situacion_actual_acronimo', false)) {
$form['title'] = array(
'#type' => 'textfield',
'#title' => t('Acrónimo del Cambio de la situación Actual'),
'#required' => TRUE,
'#default_value' => $node->title,
'#maxlength' => 255,
'#weight' => -5,
'#description' => t('Introduzca el acrónimo del cambio Situación Actual para facilitar su busqueda. Es deseable que este sea único para facilitar su distinción entre otros descriptores.'),
);
}
$form['cambio'] = array(
'#type' => 'textarea',
'#title' => t('Cambio de la Situación Actual'),
'#description' => t('Introduzca el cambio de la Situación Actual.'),
'#default_value' => $node->body,
'#required' => TRUE,
);
//se agrega el plan de la patria
$form['pdlp'] = array(
'#type' => 'fieldset',
'#title' => t('Plan de la Patria'),
);
$array = _situacion_actual_preliminar_get_pdlp();
$opens_div = '';
$i = 0;
$ant_term = 0;
$node_type = content_types('cambios');
$fields = $node_type['fields'];
$vid = $fields['field_cambios_pdp']['vid'];
$inputs = array();
$inputs[] = $vid;
$inputs_metas_sql = array();
foreach ($array as $id => $texto) {
if ($id != 'metas') {
$term_id = $node->field_cambios_pdp[$i]['value'] ? $node->field_cambios_pdp[$i]['value'] : 0;
$terms = array(0 => t('Seleccione'),);
if ($ant_term || $i == 0) {
$terms += _ente_planificador_cambios_taxonomy($vid, $ant_term);
}
$ant_term = $term_id;
if ($term_id) {
$inputs[] = $term_id;
$inputs_metas_sql[] = '%d';
}
$form['pdlp'][$id] = array(
'#type' => 'select',
'#title' => $texto,
'#default_value' => $term_id,
'#options' => $terms,
'#description' => t('Seleccione el Objetivo @tipo.', array('@tipo' => $texto)),
'#required' => TRUE,
'#ahah' => array(
'event' => 'change',
'path' => 'planificacion_cambios_pdlp_js/' . $id,
'wrapper' => 'situacion_preliminar_' . $id,
'method' => 'replace',
'progress' => array('type' => 'bar', 'message' => t('Please wait...')),
),
);
}
else {
$terms = array(
0 => t('Seleccione'),
);
if (count($inputs)) {
$sql = 'SELECT f.plan_carabobo_meta_value AS meta, f.tid FROM {term_fields_term} AS f INNER JOIN {term_data} AS t ON t.tid = f.plan_carabobo_relations_value AND t.vid = %d WHERE f.plan_carabobo_relations_value IN (' . implode(', ', $inputs_metas_sql) . ')';
$result = db_query($sql, $inputs);
$j = 1;
while ($termino = db_fetch_object($result)) {
$meta = trim($termino->meta);
if ($meta != '') {
$terms[$termino->tid] = '(' . $j . ') ' . $meta;
$j++;
}
}
}
$term_id = $node->field_cambios_carabobo[0]['value'] ? $node->field_cambios_carabobo[0]['value'] : 0;
$form['pdlp'][$id] = array(
'#type' => 'select',
'#title' => t('@texto_metas (cantidad de metas: @metas)', array('@texto_metas' => $texto, '@metas' => $j - 1)),
'#default_value' => $term_id,
'#options' => $terms,
'#description' => t('Seleccione la meta del Plan Campaña de Carabobo.'),
);
}
$form['pdlp'][$id]['#prefix'] = '';
$opens_div .= '
';
$i++;
}
$form['pdlp'][$id]['#suffix'] = $opens_div;
//se agrega otros campos de interes
$field_form = array();
$fields_form = array();
$arreglo = array(
'field_cambios_meta' => 'field_cambios_meta',
);
if (is_array($fields) && count($fields)) {
foreach($fields as $field_id => $field) {
if (array_key_exists($field_id, $arreglo)) {
$field_form[] = $field_id;
$fields_form[] = $field_id;
}
}
}
if (is_array($field_form) && count($field_form)) {
module_load_include('inc', 'content', 'includes/content.node_form');
foreach ($field_form as $field_id) {
$field = content_fields($field_id, $form['#node']->type);
$form['#field_info'][$field_id] = $field;
$form += (array) content_field_form($form, $form_state, $field);
}
}
$form['#' . $form['#node']->type . '_campos'] = $fields;
$form['#' . $form['#node']->type . '_fields'] = $fields_form;
$form['#pdlp'] = $array;
$form['buttons']['#weight'] = 100;
$form['buttons']['submit'] = array(
'#type' => 'submit',
'#value' => t('Submit'),
'#weight' => 100,
);
$form['buttons']['cancel'] = array(
'#type' => 'submit',
'#value' => t('Cancel'),
'#weight' => 101,
);
return $form;
}
/*
* Implementation of ente_planificador_cambios_editar_form_validate()
* Validar Agregar o editar Cambio en la Situacion Actual
*/
function ente_planificador_cambios_editar_form_validate($form, &$form_state) {
$op = isset($form_state['values']['op']) ? $form_state['values']['op'] : '';
if ($op == t('Cancel')) {
if ($_REQUEST['destination']) {
$redirect = url('planificacion/' . $form['#ente_planificador']->nid . '/explicacion/' . $form['#tipo_plan']['plan'] . '/' . $descriptor->nid . '/cambios',
array(
'query' => array(
'destination' => $_REQUEST['destination'],
),
'absolute' => TRUE,
)
);
}
else {
// add redirect
$redirect = 'planificacion/' . $form['#ente_planificador']->nid . '/explicacion/' . $form['#tipo_plan']['plan'] . '/' . $descriptor->nid . '/cambios';
}
drupal_goto($redirect);
return;
}
if (trim($form_state['values']['cambio']) == '') {
form_set_error('cambios', t('Debe agregar el cambio de la Situación Actual'));
}
if (count($form['pdlp']['metas']['#options']) > 1 && !$form_state['values']['metas']) {
form_set_error('metas', t('Debe Indicar una meta del Plan Campaña de Carabobo'));
}
return;
}
/*
* Implementation of ente_planificador_cambios_editar_form_submit()
*/
function ente_planificador_cambios_editar_form_submit($form, &$form_state) {
$op = isset($form_state['values']['op']) ? $form_state['values']['op'] : '';
if ($op == t('Cancel')) {
return;
}
module_load_include('inc', 'node', 'node.pages');
$cambio = $form['#node'];
$descriptor = $form['#descriptor'];
node_object_prepare($descriptor);
$form_state['values']['descriptor'] = check_plain($form_state['values']['descriptor']);
if (variable_get('situacion_actual_acronimo', false)) {
$cambio->title = check_plain($form_state['values']['title']);
}
else {
$cambio->title = substr($form_state['values']['cambio'], 0, 244);
}
$cambio->body = $form_state['values']['cambio'];
//crear una nueva revision
$nuevo = TRUE;
if ($cambio->nid) {
$nuevo = FALSE;
$cambio->log = t('Modificados los datos del cambio en la situación actual @date', array('@date' => date('d-m-Y', time())));
$cambio->revision = 1;
}
$encontrado = FAlSE;
if (count($cambio->field_cambios_descriptor)) {
foreach($cambio->field_cambios_descriptor as $enlace) {
if ($enlace['nid'] == $descriptor->nid) {
$encontrado = TRUE;
}
}
}
if (!$encontrado) {
$cambio->field_cambios_descriptor[]['nid'] = $descriptor->nid;
}
$field_form = $form['#' . $form['#node']->type . '_fields'];
module_load_include('inc', 'node', 'node.pages');
$node_load = $form['#node'];
$form_values = $form_state['values'];
//$node_load->title = check_plain($form_values['title']);
if (is_array($field_form) && count($field_form)) {
foreach ($field_form as $field_id) {
if (isset($form_values[$field_id]) && is_array($form_values[$field_id])) {
foreach($form_values[$field_id] as $id => $value) {
if (is_numeric($id) && isset($form_values[$field_id][$id]['_error_element'])) {
unset($form_values[$field_id][$id]['_error_element']);
}
}
$cambio->{$field_id} = $form_values[$field_id];
}
}
}
//se incluye el plan de la patria
$i = 0;
foreach ($form['#pdlp'] as $id => $texto) {
if ($form_values[$id]) {
if ($id == 'metas') {
$cambio->field_cambios_carabobo[0]['value'] = $form_values[$id];
}
else {
$cambio->field_cambios_pdp[$i]['value'] = $form_values[$id];
}
}
$i++;
}
node_save($cambio);
$form['#cambio'] = $cambio;
//se agrega el cambio al descriptor
$encontrado = FAlSE;
if (count($descriptor->field_descriptor_cambio)) {
foreach($descriptor->field_descriptor_cambio as $enlace) {
if ($enlace['nid'] == $cambio->nid) {
$encontrado = TRUE;
}
}
}
if (!$encontrado) {
$descriptor->field_descriptor_cambio[]['nid'] = $cambio->nid;
}
$descriptor->log = t('Se agregó un nuevo cambio en la situación actual al descriptor @date', array('@date' => date('d-m-Y', time())));
$descriptor->revision = 1;
node_save($descriptor);
if ($nuevo) {
drupal_set_message(t('Se agregó el cambio en la situación actual @title', array('@title' => $cambio->body)));
}
else {
drupal_set_message(t('Se modificó el cambio en la situación actual @title', array('@title' => $cambio->body)));
}
if ($_REQUEST['destination']) {
$form_state['redirect'] = url('planificacion/' . $form['#ente_planificador']->nid . '/explicacion/' . $form['#tipo_plan']['plan'] . '/' . $descriptor->nid . '/cambios',
array(
'query' => array(
'destination' => $_REQUEST['destination'],
),
'absolute' => TRUE,
)
);
unset($_REQUEST['destination']);
}
else {
// add redirect
$form_state['redirect'] = 'planificacion/' . $form['#ente_planificador']->nid . '/explicacion/' . $form['#tipo_plan']['plan'] . '/' . $descriptor->nid . '/cambios';
}
}
/*
* Implementation of mis_entes_planificadores_planificacion_explicacion()
*/
function mis_entes_planificadores_planificacion_explicacion() {
global $user;
$output = '';
$ente = usuario_tiene_ente($user->uid);
if ($ente->nid) {
drupal_goto('planificacion/' . $ente->nid . '/explicacion');
}
drupal_goto('mi_ente_planificador/planificacion');
return $output;
}
/*
* Implementation of situacion_actual_preliminar_status_planificacion_explicacion()
*/
function situacion_actual_preliminar_status_planificacion_explicacion($ente_planificador, $tipo = 2) {
$estado_preliminar = array();
$planns = _situacion_actual_preliminar_get_planns();
foreach ($planns as $id => $plann) {
if (isset($plann['ente_type'][$tipo]) && $plann['ente_type'][$tipo]) {
$descriptores = _get_situacion_actual_listar_all_descriptores($ente_planificador, $plann['plan'], variable_get('situacional_actual_preliminar_anho_creacion', 0));
$estado_preliminar['situacion_actual_' . $plann['plan']] = array(
'value' => count($descriptores) ? 1 : 0,
'title' => $plann['title_long'],
'link' => 'planificacion/' . $ente_planificador . '/explicacion/' . $plann['short'],
'mylink' => 'mi_ente_planificador/planificacion/explicacion/' . $plann['short'],
'weight' => 1,
);
}
}
return $estado_preliminar;
}
/*
* Implementation of hook_access()
*/
function situacion_actual_preliminar_access($op, $node, $account) {
global $user;
if ($op == 'view') {
return user_access('ver planificador');
}
if ($op == 'create' ) {
return (user_access('admin planificador'));
}
if ($op == 'delete') {
return (user_access('admin planificador'));
}
}
/*
* Implementation of _get_situacion_actual_listar_all_descriptores()
* Get ente's descriptores
* Inputs:
- $ente_planificador (integer): ente planificador nid
- $tipo (integer): plann type
- $year (integer): descriptor year creation, if no available 'situacional_actual_preliminar_anho_creacion' variable will be used
* Outputs:
- Descriptores (array nid descriptor):
+ body: Description descriptor
+ title: Acronimo
+ nid: Descriptor nid node reference
+ year: descriptor year creation
+ clasificacion: descriptor type
/ tid: taxonomy term
+ causas: causas list (array nid causa-descriptor):
/ body: Description causa
/ title: Acronimo causa
/ nid: Causa nid node reference
/ descriptor: Descriptor nid node reference
+ solucion: solucion list (array nid solucion-descriptor):
/ body: Description solucion
/ title: Acronimo solucion
/ nid: Solucion nid node reference
/ descriptor: Descriptor nid node reference
*/
function _get_situacion_actual_listar_all_descriptores($ente_planificador, $tipo_plan = array(), $year = 0) {
//se obtienen los descriptores
$descriptores = array();
$sql = "SELECT c.nid, n.title, nr.body FROM {content_type_descriptores} AS c INNER JOIN {node} AS n ON c.nid = n.nid AND c.vid = n.vid INNER JOIN {node_revisions} AS nr ON c.nid = nr.nid AND c.vid = nr.vid WHERE c.field_descriptores_planificador_nid = %d AND c.field_descriptores_year_value = %d";
$inputs = array();
$inputs[] = $ente_planificador;
$year_display = $year? $year: variable_get('situacional_actual_preliminar_anho_creacion', 0);
$inputs[] = $year_display;
if ($tipo_plan['short']) {
$sql .= ' AND c.field_descriptores_' . $tipo_plan['short'] . '_value = %d';
$inputs[] = 1;
}
$sql .=' ORDER BY c.nid';
$result = db_query($sql, $inputs);
$inpunts = array();
$inpunts_values = array();
$solucion = array();
while($descriptor = db_fetch_object($result)) {
$descriptores[$descriptor->nid] = array(
'body' => $descriptor->body,
'title' => $descriptor->title,
'nid' => $descriptor->nid,
'year' => $year_display,
'clasificacion' => array(),
'causas' => array(),
'cambios' => array(),
);
$inpunts[] = '%d';
$inpunts_values[] = $descriptor->nid;
}
if (count($inpunts)) {
$implode = implode(',',$inpunts);
//Se obtienen la clasificacion de los descriptores
$sql = 'SELECT c.field_descriptores_clasificacion_value AS tid, c.nid FROM {content_field_descriptores_clasificacion} AS c INNER JOIN {node} AS n ON n.nid = c.nid AND n.vid = c.vid WHERE c.nid IN (' . $implode . ')';
$result = db_query($sql, $inpunts_values);
while($clasificacion = db_fetch_object($result)) {
$descriptores[$clasificacion->nid]['clasificacion'][$clasificacion->tid] = $clasificacion->tid;
}
//se obtienen las causas
//field_descriptores_causa
$sql = "SELECT c.field_descriptores_causa_nid as nid, c.nid as descriptor, n.title, nr.body FROM {content_field_descriptores_causa} AS c INNER JOIN {node} AS n ON c.field_descriptores_causa_nid = n.nid INNER JOIN {node} AS n1 ON c.nid = n1.nid AND c.vid = n1.vid INNER JOIN {node_revisions} AS nr ON n.nid = nr.nid AND n.vid = nr.vid WHERE c.nid IN (" . $implode . ") ORDER BY c.field_descriptores_causa_nid";
$result = db_query($sql, $inpunts_values);
while($causa = db_fetch_object($result)) {
$descriptores[$causa->descriptor]['causas'][$causa->nid] = array(
'body' => $causa->body,
'nid' => $causa->nid,
'title' => $causa->title,
'descriptor' => $causa->descriptor,
);
}
//se obtienen los cambios
//field_descriptor_cambio_nid
$sql = "SELECT c.field_descriptor_cambio_nid as nid, c.nid as descriptor, n.title, nr.body FROM {content_field_descriptor_cambio} AS c INNER JOIN {node} AS n ON c.field_descriptor_cambio_nid = n.nid INNER JOIN {node} AS n1 ON c.nid = n1.nid AND c.vid = n1.vid INNER JOIN {node_revisions} AS nr ON n.nid = nr.nid AND n.vid = nr.vid WHERE c.nid IN (" . $implode . ") ORDER BY c.field_descriptor_cambio_nid";
$result = db_query($sql, $inpunts_values);
while($meta = db_fetch_object($result)) {
$descriptores[$meta->descriptor]['cambios'][$meta->nid] = array(
'body' => $meta->body,
'nid' => $meta->nid,
'title' => $meta->title,
'descriptor' => $meta->descriptor,
);
}
}
return $descriptores;
}
/*
* Implementation of _display_situacion_actual_listar_all_descriptores()
*/
function _display_situacion_actual_listar_all_descriptores($ente_planificador = 0, $tipo_plan = array(), $acceso = FALSE, $year = 0) {
$descriptores = _get_situacion_actual_listar_all_descriptores($ente_planificador, $tipo_plan, $year);
$output = '';
$headers_table = array();
$headers_table[] = array('data' => t('Descriptores'));
$headers_table[] = array('data' => t('Categorización'));
$headers_table[] = array('data' => t('Causas'));
$headers_table[] = array('data' => t('Cambios de la situación actual'));
$year = $year? $year : variable_get('situacional_actual_preliminar_anho_creacion', 0);
if ($acceso) {
$headers_table[] = array('data' => t('Acciones'));
}
if (count($descriptores)) {
$rows = array();
foreach($descriptores as $descriptor) {
$row = array();
$row[] = array('data' => $descriptor['body']);
$clasificiacion = array();
foreach($descriptor['clasificacion'] as $id) {
$term_load = taxonomy_get_term($id);
if ($term_load) {
$clasificiacion[] = $term_load->name;
}
}
$row[] = array('data' => theme('item_list', $clasificiacion));
$causas = array();
foreach ($descriptor['causas'] as $causa) {
$causas[] = $causa['body'];
}
$output = count($causas)? theme('item_list', $causas) : t('No se han agregado causas al descriptor');
$row[] = array('data' => $output);
$solucion = array();
foreach ($descriptor['cambios'] as $cambio) {
$solucion[] = $cambio['body'];
}
$output = count($solucion)? theme('item_list', $solucion) : t('No se encontrarón cambios en la situación actual del descriptor');
$row[] = array('data' => $output);
$redirect = $_GET["q"];
if ($acceso && $descriptor['year'] == $year) {
$acciones = array();
$acciones[] = l(t('Editar Descriptor'), 'planificacion/' . $ente_planificador . '/explicacion/' . $tipo_plan['plan'] . '/' . $descriptor['nid'] . '/descriptor', array('query' => array('destination' => $redirect)));
$acciones[] = l(t('Consultar Causas'), 'planificacion/' . $ente_planificador . '/explicacion/' . $tipo_plan['plan'] . '/' . $descriptor['nid'] . '/causas/ver', array('query' => array('destination' => $redirect)));
$acciones[] = l(t('Agregar Causas'), 'planificacion/' . $ente_planificador . '/explicacion/' . $tipo_plan['plan'] . '/' . $descriptor['nid'] . '/causas', array('query' => array('destination' => $redirect)));
$acciones[] = l(t('Consultar Cambios en la situación actual'), 'planificacion/' . $ente_planificador . '/explicacion/' . $tipo_plan['plan'] . '/' . $descriptor['nid'] . '/cambios/ver', array('query' => array('destination' => $redirect)));
$acciones[] = l(t('Agregar Cambios en la situación actual'), 'planificacion/' . $ente_planificador . '/explicacion/' . $tipo_plan['plan'] . '/' . $descriptor['nid'] . '/cambios', array('query' => array('destination' => $redirect)));
$acciones[] = l(t('Eliminar Descriptor'), 'planificacion/' . $ente_planificador . '/explicacion/' . $tipo_plan['plan'] . '/' . $descriptor['nid'] . '/eliminar', array('query' => array('destination' => $redirect)));
$row[] = array('data' => theme('item_list', $acciones));
}
$rows[] = $row;
}
}
else {
$row = array();
$row[] = array('data' => t('No se encontrarón descriptores para este ente'), 'colspan' => count($headers_table));
$rows[] = $row;
}
return theme('table', $headers_table, $rows);
}
/*
* Implementation of _get_situacion_explicacion_acceso()
* Obtiene el acceso de modificar descriptores
*/
function _get_situacion_explicacion_acceso_hijos($ente_planificador, $tipo_plan = 'interpretacion', $descriptor = 0) {
global $user;
$mi_fecha = ente_planificador_user_acceso_proceso($tipo_plan, $ente_planificador['level']);
$current_time = time();
$ente = usuario_tiene_ente($user->uid);
$mi_ente = user_access('admin all planificador') || ($ente && $ente->nid && $ente->nid == $ente_planificador['nid']);
return $mi_ente && (($mi_fecha[1] + 86399 > $current_time) && ($mi_fecha[0] < $current_time) && (!$descriptor || ($descriptor->type == 'descriptores' && $descriptor->field_descriptores_year[0]['value'] == variable_get('situacional_actual_preliminar_anho_creacion', 0))));
}
/*
* Implementation of _get_situacion_explicacion_acceso()
* Obtiene el acceso de modificar descriptores
*/
function _get_situacion_explicacion_acceso($ente_planificador, $tipo_plan = array(), $descriptor = 0) {
global $user;
$mi_fecha = ente_planificador_user_acceso_proceso($tipo_plan['plan'], $ente_planificador->tipo);
$current_time = time();
$ente = usuario_tiene_ente($user->uid);
$campo = 'field_descriptores_' . $tipo_plan['short'];
$mi_ente = user_access('admin all planificador') || ($ente && $ente->nid && $ente->nid == $ente_planificador->nid);
return $mi_ente && (($mi_fecha[1] + 86399 > $current_time) && ($mi_fecha[0] < $current_time) && (!$descriptor || ($descriptor->type == 'descriptores' && $descriptor->{$campo}[0]['value'] && $descriptor->field_descriptores_year[0]['value'] == variable_get('situacional_actual_preliminar_anho_creacion', 0))));
}
/*
* Implementation of _get_situacion_actual_listar_descriptores_all()
* Obtiene todos los descriptores de un ente planificador
*/
function _get_situacion_actual_listar_descriptores_all($ente_planificador, $tipo_plan = array(), $micro = 0, $year = 0) {
global $user;
$title = t($tipo_plan['title_long']);
$contenido_ente = '';
$redirect = $_GET["q"];
if (isset($tipo_plan['ente_type'][$ente_planificador->tipo]) && $tipo_plan['ente_type'][$ente_planificador->tipo]) {
$acceso = _get_situacion_explicacion_acceso($ente_planificador, $tipo_plan);
$title = t($tipo_plan['title_ente'], array('@ente' => $ente_planificador->title));
$contenido_ente = _display_situacion_actual_listar_all_descriptores($ente_planificador->nid, $tipo_plan, $acceso, $year);
if ($acceso) {
$agregar = l(t('Agregar Descriptor'), 'planificacion/' . $ente_planificador->nid . '/explicacion/' . $tipo_plan['plan'] . '/agregar/descriptor', array('query' => array('destination' => $redirect)));
}
$contenido_ente .= '' . $contenido . $agregar . '
';
}
//se muestran las herencias de entes
$links = array();
if (isset($ente_planificador->ente_planificador_hierarchical[$tipo_plan['hierarchical']])) {
$tipo_allow = $ente_planificador->tipo + $tipo_plan['hierarchical_ente'];
$entes = array();
if ($tipo_allow > 0 && $tipo_allow <= variable_get('ente_planificador_hierarchical_count', 2)) {
$entes = array();
$levels = array();
$hierarchical = $ente_planificador->ente_planificador_hierarchical[$tipo_plan['hierarchical']];
foreach($hierarchical as $ente){
$levels[$ente['level']] = $ente;
if ($ente['level'] == $tipo_allow) {
$entes[$ente['nid']] = $ente['title'];
}
}
}
//en caso de que $tipo_allow no se encuentrem se muestra el siguiente nivel si tiene el tipo
if (!count($entes) && $tipo_plan['hierarchical'] == 'fathers') {
$tipo_allow += $tipo_plan['hierarchical_ente'];
$encontrado = FALSE;
while(!$encontrado && $tipo_allow >= 0 && $tipo_allow <= variable_get('ente_planificador_hierarchical_count', 2)) {
if (isset($levels[$tipo_allow]) && isset($tipo_plan['ente_type'][$tipo_allow])) {
$entes[$ente['nid']] = $ente['title'];
$encontrado = TRUE;
}
$tipo_allow += $tipo_plan['hierarchical_ente'];
}
}
$links = array();
foreach($entes as $nid => $ente) {
$contenido .= '';
$contenido_hijos = '';
if ($nid == $micro) {
$acceso_hijo = _get_situacion_explicacion_acceso_hijos($nid, $tipo_plan['plan']);
$contenido_hijos .= _display_situacion_actual_listar_all_descriptores($nid, $tipo_plan, $acceso_hijo, $year);
$agregar = '';
if ($acceso_hijo) {
$agregar = l(t('Agregar Descriptor'), 'planificacion/' . $nid . '/explicacion/' . $tipo_plan['plan'] . '/agregar/descriptor', array('query' => array('destination' => $redirect)));
}
$contenido_hijos .= '' . $contenido_version . $agregar . '
';
}
$enlace = l($ente, 'planificacion/' . $ente_planificador->nid . '/explicacion/' . $tipo_plan['plan'] . '/' . $nid);
$links[] = $enlace . $contenido_hijos;
}
}
if (count($links)) {
$contenido_hijos = $ente_planificador->tipo < $tipo_allow ? '' . t('Interpretación preliminar de la explicación situacional de mis entes adscriptos') . '
' : '';
$contenido_hijos .= theme('item_list', $links);
}
drupal_set_title($title);
return $contenido_ente . $contenido_hijos;
}
/*
* Implementation of ente_planificador_view_situacion_explicacion()
* Display Versión Preliminar page
*/
function ente_planificador_view_situacion_explicacion($ente_planificador, $tipo_plan = 'interpretacion', $children = 0, $year = 0) {
global $user;
$mi_fecha = ente_planificador_user_acceso_proceso($tipo_plan, $ente_planificador->tipo);
$current_time = time();
$fecha = FALSE;
if ($mi_fecha[1] + 86399 > $current_time && $mi_fecha[0] < $current_time) {
$fecha = TRUE;
}
if (!$fecha) {
muestra_mensaje($tipo_plan, $ente_planificador);
}
else {
$ente = usuario_tiene_ente($user->uid);
if ($ente->nid == $ente_planificador->nid) {
muestra_mensaje($tipo_plan, $ente_planificador, 0);
}
}
$planns = _situacion_actual_preliminar_get_planns();
$plan = $planns[$tipo_plan];
$year = $year? $year : variable_get('situacional_actual_preliminar_anho_creacion', 0);
$output = _get_situacion_actual_listar_descriptores_all($ente_planificador, $plan, $children, $year);
return $output;
}
/*
* Implementation of hook_node_info()
*/
function situacion_actual_preliminar_node_info() {
return array(
//se agrega el nodo causas
'causas' => array(
'name' => t('Causas'),
'description' => '',
'has_body' => TRUE,
'title_label' => 'Acrónimo de la causa',
'has_title' => TRUE,
'body_label' => 'Causa',
'module' => 'situacion_actual_preliminar',
),
//se agrega el nodo descriptores
'descriptores' => array(
'name' => t('Descriptores'),
'description' => '',
'has_body' => TRUE,
'title_label' => 'Acrónimo del descriptor',
'has_title' => TRUE,
'body_label' => 'Descriptor',
'module' => 'situacion_actual_preliminar',
),
//se agrega el nodo cambios en la situacion actual
'cambios' => array(
'name' => t('Cambios en la Situación Actual'),
'description' => '',
'has_body' => TRUE,
'title_label' => 'Acrónimo del cambio',
'has_title' => TRUE,
'body_label' => 'Descripción del cambio',
'module' => 'situacion_actual_preliminar',
),
);
}
/*
* Implementation of hook_form()
*/
function situacion_actual_preliminar_form(&$node, $form_state) {
return node_content_form($node, $form_state);
}