t('Seleccione.'),
1 => t('Organismo rector en planificación.'),
2 => t('Organismo público.'),
3 => t('Ente adscrito a un organismo público.'),
4 => t('Ente adscrito a otro ente adscrito (sub-ente adscrito).'),
);
drupal_alter('obtiene_tipos', $nivels);
if ($nivel && is_numeric($nivel) && $nivels[$nivel]) {
return $nivels[$nivel];
}
elseif($nivel) {
return FALSE;
}
return $nivels;
}
/*
* Agrega los cuatro roles de planificacion.
* Lista los roles de Planificacion.
*/
function ente_planificador_sector_roles_planificacion($rol= 0) {
$roles = array(
0 => t('Seleccione.'),
1 => t('Control.'),
2 => t('Enlace Formulador.'),
3 => t('Enlace Revisor.'),
4 => t('Supervisor.'),
);
if ($rol && is_numeric($rol) && $roles[$rol]) {
return $roles[$rol];
}
elseif($rol) {
return FALSE;
}
return $roles;
}
/*
* Seleciona el rol de planificacion del usuario
*/
function ente_planificador_sector_mi_rol_planificacion($uid = 0) {
$query = db_query("SELECT rol_planificacion FROM ente_user_planificador WHERE usuario=%d", $uid);
$row = db_fetch_object($query);
return $row->rol_planificacion;
}
/*
* Implementation of hook_menu()
*/
function ente_planificador_sector_menu() {
$items = array();
$items['fechas_planificacion/notificacion/sector'] = array(
'title' => 'Modificar Fechas por sectores.',
'page callback' => 'fecha_procesos_sector_notificacion',
'access arguments' => array('admin planificador'),
'type' => MENU_LOCAL_TASK,
);
$items['fechas_planificacion/notificacion/ambito'] = array(
'title' => 'Modificar Fechas por Ambito.',
'page callback' => 'fecha_procesos_ambito_notificacion',
'access arguments' => array('admin planificador'),
'type' => MENU_LOCAL_TASK,
);
$items['fechas_planificacion/edit/sector'] = array(
'title' => 'Modificar las fechas para los procesos de planificación por Sectores.',
'page callback' => 'fecha_procesos_sector_fecha_planificacion_edit',
'access arguments' => array('admin planificador'),
'type' => MENU_CALLBACK,
);
$items['fechas_planificacion/edit/ambito'] = array(
'title' => 'Modificar las fechas para los procesos de planificación por Sectores.',
'page callback' => 'fecha_procesos_ambito_fecha_planificacion_edit',
'access arguments' => array('admin planificador'),
'type' => MENU_CALLBACK,
);
$items['fechas_planificacion/sectores/edit/%/%'] = array(
'title' => 'Modificar las fechas para los procesos de planificación por Sectores.',
'page callback' => 'fecha_procesos_sector_notificacion_edit_form_sectores_planificacion',
'access arguments' => array('admin planificador'),
'page arguments' => array(3,4),
'type' => MENU_CALLBACK,
);
$items['fechas_planificacion/ambitos_sector/edit/%/%'] = array(
'title' => 'Modificar las fechas para los procesos de planificación por Ambito.',
'page callback' => 'fecha_procesos_sector_notificacion_edit_form_planificacion_by_ambitos',
'access arguments' => array('admin planificador'),
'page arguments' => array(3,4),
'type' => MENU_CALLBACK,
);
//opcion de configuracion del ambito
$items['admin/settings/ente_planificador/agregar_ambitos'] = array(
'title' => t('Agregar Ambitos'),
'page callback' => 'drupal_get_form',
'page arguments' => array('ente_planificador_sector_form_ambito'),
'access arguments' => array('admin planificador'),
'weight' => -6,
'type' => MENU_LOCAL_TASK,
);
//lista de los ambitos registrados
$items['lista_ambitos_y_sectores_asociados'] = array(
'title' => t('Lista de los Ambitos y Sectores Asociados'),
'page callback' => 'ente_planificador_sector_lista_ambito',
'access arguments' => array('admin planificador'),
'weight' => -6,
'type' => MENU_LOCAL_TASK,
);
//lista de los ambitos registrados
$items['admin/settings/ente_planificador/lista_sectores/%'] = array(
'title' => t('Lista Sectores Asociados a un ambito'),
'page callback' => 'ente_planificador_sector_lista_sectores',
'access arguments' => array('admin planificador'),
'page arguments' => array(4),
'weight' => -6,
);
//lista de los ambitos registrados
$items['admin/settings/ente_planificador/agregar_sectores'] = array(
'title' => t('Agregar Sectores'),
'page callback' => 'drupal_get_form',
'page arguments' => array('ente_planificador_sector_form_sector'),
'access arguments' => array('admin planificador'),
'weight' => -6,
'type' => MENU_LOCAL_TASK,
);
$items['ente_planificador_sector_util'] = array(
'title' => 'JS utilities form',
'page callback' => 'ente_planificador_sector_js_util',
'access arguments' => array('admin planificador'),
'type' => MENU_CALLBACK,
);
return $items;
}
/**
* Crea una tabla de opciones para modificar las fechas de notificacion por ambito
*/
function fecha_procesos_ambito_notificacion() {
drupal_set_title(t('Modificar las Fecha de los Procesos por Ambitos'));
$view = FALSE;
if (user_access('admin planificador')) {
$view = TRUE;
}
$header = array();
$header[] = array('data' => t('Listado de los procesos de planificación'));
$procesos_status = ente_planificador_procesos('status');
$procesos = ente_planificador_procesos();
$procesos_ordenados = ente_planificador_ordena_procesos($procesos_status, $procesos);
$procesos_status = $procesos_ordenados['status'];
$nuevo_proceso = $procesos_ordenados['normal'];
$rows = array();
if (is_array($procesos_status) && count($procesos_status)) {
foreach ($procesos_status as $id => $valores) {
$row = array();
$row[] = array('data' => '' . $procesos_status[$id]['title'] . '', 'colspan' => 1, 'align' => 'center');
$rows[] = $row;
if (is_array($nuevo_proceso[$id]) && count($nuevo_proceso[$id])) {
$items = array();
$item = array();
foreach ($nuevo_proceso[$id] as $type_url_str => $proceso) {
if ($view) {
$item[] = array(
'data'=> l(t('Modificar la fecha de inicio para %name', array('%name' => $proceso['title'])), 'fechas_planificacion/edit/ambito/' . $type_url_str, array('html' => true, 'query' => 'destination=fechas_planificacion/notificacion/ambito')),
);
}
}
if (sizeof($item)) {
$items[] = theme('item_list', $item);
$rows[] = $items;
}
else {
$row[] = array(
'data' => t('No se encontrarón Procesos'),
);
}
}
}
}
if (sizeof($rows)) {
$output.= '
'.theme('table', $header, $rows);
$output .= theme('pager', NULL);
}
else {
$row[] = array(
'data' => t('No se encontrarón Procesos'),
);
}
return $output;
}
/**
* Editar las fechas de planificacion por sectores
*/
function fecha_procesos_sector_notificacion_edit_form_planificacion_by_ambitos($term = 0, $type_node = '') {
$procesos = ente_planificador_procesos();
if (isset($procesos[$type_node])) {
return drupal_get_form('fecha_procesos_sector_notificacion_edit_form_ambitos_planificacion', $term, $type_node);
}
return NULL;
}
/*
* Lista los sectores por ambito para modificar los procesos que la componen
*/
function fecha_procesos_sector_notificacion_edit_form_ambitos_planificacion($form_state, $ambito = 0, $type_node = '') {
$view = FALSE;
$form = array();
$procesos = ente_planificador_procesos();
$procesos_status = ente_planificador_procesos('status');
$procesos_ordenados = ente_planificador_ordena_procesos($procesos_status, $procesos);
$procesos_status = $procesos_ordenados['status'];
$nuevo_proceso = $procesos_ordenados['normal'];
$tid = variable_get('ente_planificador_sector_Ambitos', 0);
if(is_numeric($ambito)) {
$termino = taxonomy_get_term($ambito);
}
$terms = taxonomy_get_children($termino->tid);
drupal_set_title(t('Modificar las Fecha para %proceso', array('%proceso' => $procesos[$type_node]['title'])));
if (user_access('admin planificador')) {
$view = TRUE;
}
if (!(is_numeric($ambito)) && ($ambito == 'administrador')) {
$FIPM = variable_get('ente_planificador_' . $type_node . '_admin_from', $now);
$FFPM = variable_get('ente_planificador_' . $type_node . '_admin_until', $now);
$name_ambito = 'Especial del usuario Administrador';
}
if (!(is_numeric($ambito)) && ($ambito == 'control')) {
$FIPM = variable_get('ente_planificador_' . $type_node . '_control_from', $now);
$FFPM = variable_get('ente_planificador_' . $type_node . '_control_until', $now);
$name_ambito = 'Especial del usuario Control';
}
//agregando el formulrio para editar las fechas
$now = time();
if ($view) {
if (is_numeric($ambito)) {
$term = taxonomy_get_term($ambito);
drupal_set_title(t('Fecha de Planificación para el Ambito %ambito', array('%ambito' => $term->name)));
$FIPM = variable_get('ente_planificador_' . $type_node . '_all_from_' . $termino->tid, $now);
$FFPM = variable_get('ente_planificador_' . $type_node . '_all_until_' . $termino->tid, $now);
$name_ambito = $term->name;
}
$form['fechas'] = array(
'#type' => 'fieldset',
'#title' => t(' Modificar la fecha de inicio para %proceso del ambito %ambito',array('%proceso' => $procesos[$type_node]['title'], '%ambito' => $name_ambito )),
'#collapsible' => FALSE,
'#collapsed' => TRUE,
);
$f1 = explode("-", format_date($FIPM, 'custom', 'Y-m-d'));
settype($f1[0], "integer");
settype($f1[1], "integer");
settype($f1[2], "integer");
$f2 = explode("-", format_date($FFPM, 'custom', 'Y-m-d'));
settype($f2[0], "integer");
settype($f2[1], "integer");
settype($f2[2], "integer");
$form['fechas']['from'] = array(
'#type' => 'date',
'#title' => t('Fecha de Inicio'),
'#default_value' => array(
'day' => $f1[2],
'month' => $f1[1],
'year' => $f1[0],
),
'#description' => t('Seleccione la fecha de inicio'),
);
$form['fechas']['until'] = array(
'#type' => 'date',
'#title' => t('Fecha de Fin'),
'#default_value' => array(
'day' => $f2[2],
'month' => $f2[1],
'year' => $f2[0],
),
'#description' => t('Seleccione la fecha de culminación'),
);
if ((is_numeric($ambito)) && (($ambito != 'administrador') || ($ambito != 'control'))) {
$form['fechas']['term'] = array(
'#type' => 'hidden',
'#default_value' => $termino->tid,
);
}
if (!(is_numeric($ambito)) && ($ambito == 'administrador')) {
$form['fechas']['term'] = array(
'#type' => 'hidden',
'#default_value' => $ambito,
);
}
if (!(is_numeric($ambito)) && ($ambito == 'control')) {
$form['fechas']['term'] = array(
'#type' => 'hidden',
'#default_value' => $ambito,
);
}
$form['fechas']['proceso'] = array(
'#type' => 'hidden',
'#default_value' => $type_node,
);
$form['submit'] = array(
'#type' => 'submit',
'#default_value' => t("Guardar"),
'#validate' => array('ente_planificador_sector_fecha_planificacion_edit_notificacion_validate'),
'#submit' => array('fecha_procesos_sector_notificacion_edit_form_ambito_submit'),
);
$enlace = base_path() . 'fechas_planificacion/edit/ambito/'.$type_node;
$form['cancel'] = array(
'#type' => 'submit',
'#attributes' => array('onClick' => 'window.location="' . $enlace . '"; return false;'),
'#value' => t('Cancel'),
);
if ((is_numeric($ambito)) && ($ambito != 'administrador') && ($ambito != 'control')) {
$form['fechas']['help'] = array(
'#value' => t('Esta acción Afectara todas las fechas especificadas para el proceso de registro por Sectores del ambito %ambito' , array('%ambito' => $term->name)),
'#prefix' => '
',
'#suffix' => '
',
);
}
}
if ((is_numeric($ambito)) && ($ambito != 'administrador') && ($ambito != 'control')) {
$header = array();
$header[] = array('data' => t('Lista de los Sectores para el ambito %ambito', array('%ambito' => $termino->name)), 'colspan' => 1, 'align' => 'center');
$header[] = array('data' => t('Fecha de Inicio'), 'colspan' => 1, 'align' => 'center');
$header[] = array('data' => t('Fecha de Culminación'), 'colspan' => 1, 'align' => 'center');
$now = time();
foreach ($terms as $term) {
$FIPMI = variable_get('ente_planificador_' . $type_node . '_from_' . $term->tid, $now);
$FFPMF = variable_get('ente_planificador_' . $type_node . '_until_' . $term->tid, $now);
$row = array();
$row[] = array(
'data'=> t('%sector', array('%sector' => $term->name)),
);
$row[] = array(
'data'=> format_date($FIPMI, 'long'),
);
$row[] = array(
'data'=> format_date($FFPMF),
);
$rows[] = $row;
}
if (sizeof($rows)) {
$output.= '
'.theme('table', $header, $rows);
$output .= theme('pager', NULL);
}
else {
$row[] = array(
'data' => t('No se encontrarón Sectores Asociados'),
'colspan' => 3,
);
$rows[] = $row;
$output.= '
'.theme('table', $header, $rows);
$output .= theme('pager', NULL);
}
}
//anadiendo las fechas de los sectores para su visualizacion
$form['sectores_hidden'] = array(
'#value' => '
' . $output,
);
//$form['#submit'][] = 'fecha_procesos_sector_notificacion_edit_form_ambito_submit';
return $form;
}
/*
* agrega las fechas de planificacion por ambito, aplicandola a todos los hijos que la conforman
*/
function fecha_procesos_sector_notificacion_edit_form_ambito_submit($form, &$form_state) {
$fi = mktime(
0,
0,
0,
$form_state['values']['from']['month'],
$form_state['values']['from']['day'],
$form_state['values']['from']['year']
);
$ff = mktime(
0,
0,
0,
$form_state['values']['until']['month'],
$form_state['values']['until']['day'],
$form_state['values']['until']['year']
);
//estableciendo las fechas para cada sector
$ambito = $form_state['values']['term'];
$proceso = $form_state['values']['proceso'];
if (is_numeric($ambito)) {
$ambito = taxonomy_get_term($ambito);
$terms = taxonomy_get_children($ambito->tid, $ambito->vid);
if ($terms) {
foreach ($terms as $term) {
variable_set('ente_planificador_' . $proceso . '_all_from_' . $ambito->tid, $fi);
variable_set('ente_planificador_' . $proceso . '_all_until_' . $ambito->tid, $ff);
//actualizando las fechas por sector social
variable_set('ente_planificador_' . $proceso . '_from_' . $term->tid, $fi);
variable_set('ente_planificador_' . $proceso . '_until_' . $term->tid, $ff);
drupal_set_message(t('Se han guardado los cambios para el sector %sector' , array('%sector' => $term->name)));
}
}
else {
variable_set('ente_planificador_' . $proceso . '_all_from_' . $ambito->tid, $fi);
variable_set('ente_planificador_' . $proceso . '_all_until_' . $ambito->tid, $ff);
}
drupal_set_message(t('Se han guardado los cambios para el Ambito %sector' , array('%sector' => $ambito->name)));
}
if (!(is_numeric($ambito)) && ($ambito == 'administrador')) {
variable_set('ente_planificador_' . $proceso . '_admin_from', $fi);
variable_set('ente_planificador_' . $proceso . '_admin_until', $ff);
drupal_set_message(t('Se han guardado las fechas del ambito especial del usuario administrador'));
}
if (!(is_numeric($ambito)) && ($ambito == 'control')) {
variable_set('ente_planificador_' . $proceso . '_control_from', $fi);
variable_set('ente_planificador_' . $proceso . '_control_until', $ff);
drupal_set_message(t('Se han guardado las fechas del ambito especial del usuario Control'));
}
}
/**
* Crea una tabla de las fechas validas de los procesos de planificacion por ambito
*/
function fecha_procesos_ambito_fecha_planificacion_edit($type_node = '') {
$procesos = ente_planificador_procesos();
$view = FALSE;
$items = array();
$item = array();
if (user_access('admin planificador')) {
$view = TRUE;
}
drupal_set_title(t('Modificar la fecha de inicio para %proceso por Ambitos', array('%proceso' => $procesos[$type_node]['title'])));
$now = time();
if (isset($procesos[$type_node])) {
$header = array();
$header[] = array('data' => t('Ambito'), 'sort' => 'asc');
$header[] = array('data' => t('Fecha de Inicio'), 'sort' => 'asc');
$header[] = array('data' => t('Fecha de Fin'), 'sort' => 'asc');
if ($view) {
$header[] = array('data' => t('Modificar'), );
}
//recorer todos los ambitos
$tid = variable_get('ente_planificador_sector_Ambitos', 0);
$terms = taxonomy_get_tree($tid);
foreach ($terms as $term) {
$row = array();
if ($term->depth == 0) { //si el termino es padre (AMBITO)
$fechas[0] = variable_get('ente_planificador_' . $type_node . '_all_from_' . $term->tid, $now);
$fechas[1] = variable_get('ente_planificador_' . $type_node . '_all_until_' . $term->tid, $now);
$FIPM = $fechas[0];
$FFPM = $fechas[1];
$row[] = array(
'data'=> t('%ambito', array('%ambito' => $term->name)),
);
$row[] = format_date($FIPM);
$row[] = format_date($FFPM);
if ($view) {
$row[] = l(t('Modificar'), 'fechas_planificacion/ambitos_sector/edit/'.$term->tid.'/'.$type_node, array('html' => true, 'query' => 'destination=fechas_planificacion/edit/ambito/'.$type_node));
}
}
$rows[] = $row;
}
// fin de la estructura de repeticion
if (!count($rows)) {
$row = array();
$row[] = array('data' => t('No se encontrarón Sectores'), 'colspan' => 3);
$rows[] = $row;
$fechas_display = FALSE;
}
$aux = "";
if (module_exists('proyectos_operativos_mail')) {
$aux = l(t("Enviar Correo Electrónico a los entes planificadores por Ambito Social."), 'fechas_planificacion/notificacion/envia_email/ambito/' . $type_node);
}
if (user_access('admin planificador')) {
$FIPMA = variable_get('ente_planificador_' . $type_node . '_admin_from', $now);
$FFPMA = variable_get('ente_planificador_' . $type_node . '_admin_until', $now);
$header2 = array();
$header2[] = array('data' => t('Ambito'), 'sort' => 'asc');
$header2[] = array('data' => t('Fecha de Inicio'), 'sort' => 'asc');
$header2[] = array('data' => t('Fecha de Fin'), 'sort' => 'asc');
$header2[] = array('data' => t('Modificar'), );
$row2 = array();
$row2[] = t('Ambito Especial');
$row2[] = format_date($FIPMA);
$row2[] = format_date($FFPMA);
$row2[] = '
' . l(t("Mofidicar"), 'fechas_planificacion/ambitos_sector/edit/administrador/'. $type_node , array('html' => true, 'query' => 'destination=fechas_planificacion/edit/ambito/'.$type_node));
$rows2[] = $row2;
if (!count($rows2)) {
$row2 = array();
$row2[] = array('data' => t('No se han establecido Fechas'), 'colspan' => 3);
$rows2[] = $row;
$fechas_display = FALSE;
}
$aux .= '' . t('Modificar la fecha de inicio para %proceso para el usuario Administrador', array('%proceso' => $procesos[$type_node]['title'])).'
';
$aux .= theme('table', $header2, $rows2);
}
if (user_access('admin planificador')) { //si es control
$FIPMA = variable_get('ente_planificador_' . $type_node . '_control_from', $now);
$FFPMA = variable_get('ente_planificador_' . $type_node . '_control_until', $now);
$header3 = array();
$header3[] = array('data' => t('Ambito'), 'sort' => 'asc');
$header3[] = array('data' => t('Fecha de Inicio'), 'sort' => 'asc');
$header3[] = array('data' => t('Fecha de Fin'), 'sort' => 'asc');
$header3[] = array('data' => t('Modificar'), );
$row3 = array();
$row3[] = t('Ambito Especial');
$row3[] = format_date($FIPMA);
$row3[] = format_date($FFPMA);
$row3[] = '
' . l(t("Mofidicar"), 'fechas_planificacion/ambitos_sector/edit/control/'. $type_node , array('html' => true, 'query' => 'destination=fechas_planificacion/edit/ambito/'.$type_node));
$rows3[] = $row3;
if (!count($rows3)) {
$row3 = array();
$row3[] = array('data' => t('No se han establecido Fechas'), 'colspan' => 3);
$rows3[] = $row;
$fechas_display = FALSE;
}
$aux .= '' . t('Modificar la fecha de inicio para %proceso para el usuario Control', array('%proceso' => $procesos[$type_node]['title'])).'
';
$aux .= theme('table', $header3, $rows3);
}
return theme('table', $header, $rows) . $aux;
}
}
/*
* Crea una tabla de opciones para modificar las Fecha de notificacion por sectores
*/
function fecha_procesos_sector_notificacion() {
drupal_set_title(t('Modificar las Fecha de los Procesos por Sectores'));
$view = FALSE;
if (user_access('admin planificador')) {
$view = TRUE;
}
$header = array();
$header[] = array('data' => t('Listado de los procesos de planificación'));
$procesos_status = ente_planificador_procesos('status');
$procesos = ente_planificador_procesos();
$procesos_ordenados = ente_planificador_ordena_procesos($procesos_status, $procesos);
$procesos_status = $procesos_ordenados['status'];
$nuevo_proceso = $procesos_ordenados['normal'];
$rows = array();
if (is_array($procesos_status) && count($procesos_status)) {
foreach ($procesos_status as $id => $valores) {
$row = array();
$row[] = array('data' => '' . $procesos_status[$id]['title'] . '', 'colspan' => 1, 'align' => 'center');
$rows[] = $row;
if (is_array($nuevo_proceso[$id]) && count($nuevo_proceso[$id])) {
$items = array();
$item = array();
foreach ($nuevo_proceso[$id] as $type_url_str => $proceso) {
if ($view) {
$item[] = array(
'data'=> l(t('Modificar la fecha de inicio para %name', array('%name' => $proceso['title'])), 'fechas_planificacion/edit/sector/' . $type_url_str, array('html' => true, 'query' => 'destination=fechas_planificacion/notificacion/sector')),
);
}
}
if (sizeof($item)) {
$items[] = theme('item_list', $item);
$rows[] = $items;
}
else {
$row[] = array(
'data' => t('No se encontrarón Procesos'),
);
}
}
}
}
if (sizeof($rows)) {
$output.= '
'.theme('table', $header, $rows);
$output .= theme('pager', NULL);
}
else {
$row[] = array(
'data' => t('No se encontrarón Procesos'),
);
}
return $output;
}
/*
* ente_planificador_fecha_planificacion_edit
* Editar una fecha de planificacion
*/
function fecha_procesos_sector_fecha_planificacion_edit($type_node = '') {
$procesos = ente_planificador_procesos();
$view = FALSE;
if (user_access('admin planificador')) {
$view = TRUE;
}
drupal_set_title(t('Modificar la fecha de inicio para %proceso por Sectores', array('%proceso' => $procesos[$type_node]['title'])));
if (isset($procesos[$type_node])) {
$header = array();
$header[] = array('data' => t('Sector'), 'sort' => 'asc');
$header[] = array('data' => t('Fecha de Inicio'), 'sort' => 'asc');
$header[] = array('data' => t('Fecha de Fin'), 'sort' => 'asc');
if ($view) {
$header[] = array('data' => t('Modificar'), );
}
$tid = variable_get('ente_planificador_sector_Ambitos', 0);
$terms = taxonomy_get_tree($tid);
foreach ($terms as $term) {
if ($term->depth == 1) { //si el termino es use sector (nivel 1)
$fechas[0] = variable_get('ente_planificador_' . $type_node . '_from_'.$term->tid, date('Y/M/D'));
$fechas[1] = variable_get('ente_planificador_' . $type_node . '_until_'.$term->tid, date('Y/M/D'));
$row[0] = $term->name;
$row[1] = format_date($fechas[0]);
$row[2] = format_date($fechas[1]);
if ($view) {
$row[3] = l(t('modificar'), 'fechas_planificacion/sectores/edit/' . $term->tid . '/' . $type_node, array('html' => true, 'query' => 'destination=fechas_planificacion/edit/sector/' . $type_node));
}
$rows[] = array('data' => $row);
}
}
if (!count($rows)) {
$row = array();
$row[] = array('data' => t('No se encontrarón Sectores'), 'colspan' => 3);
$rows[] = $row;
$fechas_display = FALSE;
}
if (module_exists('proyectos_operativos_mail')) {
$aux = l(t("Enviar Correo Electrónico a los entes planificadores por Sector Social."), 'fechas_planificacion/notificacion/envia_email/sector/' . $type_node);
}
return theme('table', $header, $rows) . $aux;
}
}
/**
* editar las fechas de planificacion por sectores
*/
function fecha_procesos_sector_notificacion_edit_form_sectores_planificacion($term = 0, $type_node = '') {
$procesos = ente_planificador_procesos();
if (isset($procesos[$type_node])) {
return drupal_get_form('fecha_procesos_sector_notificacion_edit_form', $term, $type_node);
}
return NULL;
}
/*
* Modifica la fecha por sector social
*/
function fecha_procesos_sector_notificacion_edit_form(&$form_state, $sector = 0, $type_node = NULL) {
$procesos = ente_planificador_procesos();
$term= taxonomy_get_term($sector);
drupal_set_title(t('Fecha de Planificación para el Sector %sector', array('%sector' => $term->name)));
$form = array();
$form['fechas'] = array(
'#type' => 'fieldset',
'#title' => t(' Modificar la fecha de inicio para %proceso del Sector %sector',array('%proceso' => $procesos[$type_node]['title'], '%sector' => $term->name)),
'#collapsible' => FALSE,
'#collapsed' => TRUE,
);
$now = time();
$FIPM = variable_get('ente_planificador_' . $type_node . '_from_' . $term->tid);
$FIPM = $FIPM ? $FIPM : $now;
$f1 = explode("-", format_date($FIPM, 'custom', 'Y-m-d'));
settype($f1[0], "integer");
settype($f1[1], "integer");
settype($f1[2], "integer");
$FFPM = variable_get('ente_planificador_' . $type_node . '_until_' . $term->tid);
$FFPM = $FFPM ? $FFPM : $now;
$f2 = explode("-", format_date($FFPM, 'custom', 'Y-m-d'));
settype($f2[0], "integer");
settype($f2[1], "integer");
settype($f2[2], "integer");
$form['fechas']['from'] = array(
'#type' => 'date',
'#title' => t('Fecha de Inicio'),
'#default_value' => array(
'day' => $f1[2],
'month' => $f1[1],
'year' => $f1[0],
),
'#description' => t('Seleccione la fecha de inicio'),
);
$form['fechas']['until'] = array(
'#type' => 'date',
'#title' => t('Fecha de Culminación'),
'#default_value' => array(
'day' => $f2[2],
'month' => $f2[1],
'year' => $f2[0],
),
'#description' => t('Seleccione la fecha de culminación'),
);
$form['fechas']['term'] = array(
'#type' => 'hidden',
'#default_value' => $term->tid,
);
$form['fechas']['proceso'] = array(
'#type' => 'hidden',
'#default_value' => $type_node,
);
$form['submit'] = array(
'#type' => 'submit',
'#default_value' => t("Guardar"),
'#validate' => array('ente_planificador_sector_fecha_planificacion_edit_notificacion_validate'),
'#submit' => array('fecha_procesos_sector_notificacion_edit_form_submit'),
);
$enlace = base_path() . 'fechas_planificacion';
$form['cancel'] = array(
'#type' => 'submit',
'#weight'=>'8615',
'#attributes' => array('onClick' => 'window.location="' . $enlace . '"; return false;'),
'#value' => t('Cancel'),
);
return $form;
}
/*
* ente_planificador_fecha_planificacion_edit_notificacion_validate
* Validar la informacion de modificar las fechas de notificacion de planificacion
*/
function ente_planificador_sector_fecha_planificacion_edit_notificacion_validate($form, &$form_state){
$fi = mktime(
0,
0,
0,
$form_state['values']['from']['month'],
$form_state['values']['from']['day'],
$form_state['values']['from']['year']
);
$ff = mktime(
0,
0,
0,
$form_state['values']['until']['month'],
$form_state['values']['until']['day'],
$form_state['values']['until']['year']
);
$term = $form_state['values']['term'];
$proceso = $form_state['values']['proceso'];
$term = taxonomy_get_term($term);
$fathers = taxonomy_get_parents($term->tid);
$tipo = 'Sector Social';
foreach ($fathers as $tid => $terms) {
$father = $terms;
$tipo = 'Ambito';
}
if ($fi > $ff) {
form_set_error('from',
t('La fecha de notificación (@fi) para el ' . $tipo . ' %sector debe ser Menor a la fecha de culminación (@ff)', array(
'@fi' => format_date($fi, 'custom', 'Y-m-d'),
'%sector' => $term->name,
'@ff' => format_date($ff, 'custom', 'Y-m-d'),
))
);
}
if ($father) {
$FIPMI = variable_get('ente_planificador_' . $proceso . '_all_from_' . $father->tid);
$FIPMF = variable_get('ente_planificador_' . $proceso . '_all_until_' . $father->tid);
if ($fi < $FIPMI) {
form_set_error('from',
t('La fecha de notificación para el sector %sector (@fi_s) debe ser Mayor a la fecha de notificación del ambito %ambito (@fi_a)', array(
'%sector' => $term->name,
'@fi_s' => format_date($fi, 'custom', 'Y-m-d'),
'%ambito' => $father->name,
'@fi_a' => format_date($FIPMI, 'custom', 'Y-m-d'),
))
);
}
if ($ff > $FIPMF) {
form_set_error('until',
t('La fecha de notificación para el sector %sector (@ff_s) debe ser Menor a la fecha de notificación del ambito %ambito (@ff_a)', array(
'%sector' => $term->name,
'@ff_s' => format_date($ff, 'custom', 'Y-m-d'),
'%ambito' => $father->name,
'@ff_a' => format_date($FIPMF, 'custom', 'Y-m-d'),
))
);
}
}
}
/*
* agrega las fechas de planificacion por sectores
*/
function fecha_procesos_sector_notificacion_edit_form_submit($form, &$form_state) {
$fi = mktime(
0,
0,
0,
$form_state['values']['from']['month'],
$form_state['values']['from']['day'],
$form_state['values']['from']['year']
);
$ff = mktime(
0,
0,
0,
$form_state['values']['until']['month'],
$form_state['values']['until']['day'],
$form_state['values']['until']['year']
);
$term = $form_state['values']['term'];
$term = taxonomy_get_term($term);
$proceso = $form_state['values']['proceso'];
variable_set('ente_planificador_' . $proceso . '_from_' . $term->tid, $fi);
variable_set('ente_planificador_' . $proceso . '_until_' . $term->tid, $ff);
drupal_set_message(t('Se han guardado los cambios para el Sector %sector' , array('%sector' => $term->name)));
}
/*
* Impletations of hook_form_alter()
*/
function ente_planificador_sector_form_alter(&$form, $form_state, $form_id) {
if (($form_id == 'views_exposed_form') && ($form['#id'] == 'views-exposed-form-lista-de-los-actores-planificado-page-1')) {
global $user;
if ($form['ambito'] && ($ente_planificador->tipo == 1)) {
$rolesa = variable_get('roles_exclude_ambito', 0);
if ($rolesa) {
foreach ($rolesa as $keya => $rola) {
if (($user->roles[$keya])) {
$form['#info']['filter-ambito']['label'] = t('Ambito del ente Planificador');
$form['ambito']['#access'] = 1;
}
else {
$form['#info']['filter-ambito']['label'] = 0;
$form['ambito']['#access'] = 0;
}
}
}
}
global $user;
$ente_planificador = node_load($user->entes);
if ($form['organismo'] && ($ente_planificador->tipo == 2)) {
$roles2 = variable_get('roles_exclude_organismo', 0);
if ($roles2) {
foreach ($roles2 as $key2 => $rol2) {
if ($user->roles[$key2]) {
$form['#info']['filter-organismo']['label'] = 0;
$form['organismo']['#access'] = 0;
$form['#info']['filter-sector']['label'] = 0;
$form['sector']['#access'] = 0;
$form['#info']['filter-sub_sector']['label'] = 0;
$form['sub_sector']['#access'] = 0;
$form['#info']['filter-ambito']['label'] = 0;
$form['ambito']['#access'] = 0;
}
}
}
}
if ($form['sector'] && ($ente_planificador->tipo == 1)) {
$roless = variable_get('roles_exclude_sector_social', 0);
if ($roless) {
foreach ($roless as $keys => $rols) {
if (($user->roles[$keys])) {
$form['#info']['filter-sector']['label'] = t('Sector Social del Ente Planificador');
$form['sector']['#access'] = 1;
}
}
}
}
if ($form['sub_sector'] && ($ente_planificador->tipo == 1)) {
$roless = variable_get('roles_exclude_sub_sector_social', 0);
if ($rolesb) {
foreach ($rolesb as $keysb => $rolsb) {
if (($user->roles[$keysb])) {
$form['#info']['filter-sub_sector']['label'] = t('Sub-Sector Social del Ente Planificador');
$form['sub_sector']['#access'] = 1;
}
}
}
}
}
if ($form_id == "proyectos_operativos_admin_settings") {
$options = array(
'ambito' => t('Fechas por Ambitos'),
'sector' => t('Fechas por Sector Social'),
);
$form['days']['ente_planificador_sector_optiones_fecha'] = array(
'#type' => 'radios',
'#title' => t('Tipo de Fechas de Proceso de Planificación'),
'#description' => t('Seleccione la Opción para establecer las fechas de los procesos de Planificación'),
'#options' => $options,
'#required' => 1,
'#default_value' => variable_get('ente_planificador_sector_optiones_fecha', 'ambito'),
);
}
if ($form_id == "ente_planificador_node_form") {
drupal_add_js(drupal_get_path('module', 'ente_planificador_sector') . '/js/ente_planificador_sector.js');
//anadiendo el campo nivel de planificacion
$nivel_planificacion = ente_planificador_sector_nivel_planificacion();
//SOLO DEJE A UN ENTE SER ENTE PLANIFICADOR MACRO
if (db_result(db_query("SELECT nid FROM {ente_planificador} where tipo = '1'")) > 0) {
unset($nivel_planificacion[1]);
}
$default = array(0);
if ($form['#node']->nid) {
$nid = $form['#node']->nid;
$query =db_query("SELECT tipo FROM {ente_planificador} WHERE nid = %d", $nid);
$entes = db_fetch_object($query);
$default = $entes->tipo;
}
$form['nivel'] = array(
'#type' => 'fieldset',
'#prefix' => '',
'#suffix' => '
',
);
$form['tipo'] = array(
'#type' => 'select',
'#title' => t('Nivel de Planificación'),
'#default_value' => $default,
'#options' => $nivel_planificacion,
'#description' => t("Seleccione el nivel de Planificación en el que se encuentra el Ente Planificador."),
'#required' => TRUE,
'#weight' => -1,
'#ahah' => array(
'event' => 'change',
'path' => 'ente_planificador_sector_util',
'wrapper' => 'ente-planificador-sector-wrapper',
'method' => 'replace',
'progress' => array('type' => 'bar', 'message' => t('Please wait...')),
),
'#prefix' => '',
'#suffix' => '
',
);
//anadiendo el campo sector
$options = array();
if ($form['#node']->nid) {
$nid = $form['#node']->nid;
$query = db_query("SELECT sector FROM {ente_planificador} WHERE nid = %d", $nid);
$entes = db_fetch_object($query);
$default = $entes->sector;
}
$tid = variable_get('ente_planificador_sector_Ambitos', 0);
$terms = taxonomy_get_tree($tid);
$options['0']= "seleccione";
foreach ($terms as $term) {
if ($term->depth == 1) { //si el termino es padre
$options[$term->tid] .= $term->name;
}
}
$parent = 0;
$parent = taxonomy_get_parents($default);
$form['nivel']['ambito'] = array(
'#type' => 'hidden',
'#value' => key($parent),
);
$form['nivel']['sector'] = array(
'#type' => 'select',
'#title' => t('Sector Social'),
'#default_value' => $default,
'#required' => TRUE,
'#options' => $options,
'#prefix' => '',
'#suffix' => '
',
);
//anadiendo el campo organismos_publicos
$options = array();
$options[0] = "seleccione";
$tid = variable_get('ente_planificador_sector_organismos', 0);
$terms = taxonomy_get_tree($tid);
$default = 0;
if ($form['#node']->nid) {
$default = db_result(db_query("SELECT organismo FROM {ente_planificador} WHERE nid = %d", $form['#node']->nid));
}
foreach ($terms as $term) {
$options[$term->tid] = $term->name;
}
$form['nivel']['ente_adscrito'] = array(
'#type' => 'select',
'#title' => t('Organismo Publico al que se esta adscrito'),
'#default_value' => $default,
'#required' => TRUE,
'#options' => $options,
'#prefix' => '',
'#suffix' => '
',
);
//anadiendo el campo sub-ente
$options = array();
$options['0']= "seleccione";
$result = db_query("SELECT n.nid, n.title FROM {node} AS n INNER JOIN {ente_planificador} AS e ON n.nid = e.nid WHERE e.ente_adscrito != 0");
while ($rows = db_fetch_object($result)) {
$options[$rows->nid] = $rows->title;
}
$default = 0;
if ($form['#node']->nid) {
$default = db_result(db_query("SELECT sub_ente FROM {ente_planificador} WHERE nid = %d", $form['#node']->nid));
}
$form['nivel']['sub_ente'] = array(
'#type' => 'select',
'#title' => t('Ente al cual se esta adscrito'),
'#default_value' => $default,
'#required' => TRUE,
'#options' => $options,
'#prefix' => '',
'#suffix' => '
',
);
}
}
/*
* Agregar los ambitos
*/
function ente_planificador_sector_form_ambito(&$form_state) {
$form = array();
$form['ente_planificador'] = array(
'#type' => 'fieldset',
'#title' => t('Configuración del Ambito'),
'#collapsible' => TRUE,
'#collapsed' => FALSE,
);
$form['ente_planificador']['ente_planificador_ambito'] = array(
'#type' => 'textfield',
'#title' => t('Nombre del Ambito'),
'#required' => TRUE,
);
//lista de ambitos
$header = array();
$header[] = array('data' => t('Lista por Ambitos'), 'colspan' => 3);
$tid = variable_get('ente_planificador_sector_Ambitos', 0);
$terms = taxonomy_get_tree($tid);
foreach ($terms as $term) {
$row = array();
$items = array();
$item = array();
$hij = 0;
$hijos = taxonomy_get_children($term->tid, $term->vid);
foreach ($hijos as $hijo) {
$hij = 1;
}
if ($hij == 1) {
if ($term->depth == 0) { //si el termino es padre (AMBITO)
$row[] = array('data' => '' . l(t($term->name), 'admin/settings/ente_planificador/lista_sectores/'.$term->tid, array('html' => true, 'query' => 'destination=lista_ambitos_y_sectores_asociados')) . '', 'colspan' => 1, 'align' => 'left');
$row[] = array('data' => '' . l(t('Consultar Sectores'), 'admin/settings/ente_planificador/lista_sectores/'.$term->tid, array('html' => true, 'query' => 'destination=lista_ambitos_y_sectores_asociados')) . '', 'colspan' => 1, 'align' => 'left');
}
}
else {
if ($term->depth == 0) { //si el termino es padre (AMBITO)
$row[] = array('data' => '' . t($term->name) . '', 'colspan' => 1, 'align' => 'left');
$row[] = array('data' => '' . t('No posee Sectores asociados') . '', 'colspan' => 1, 'align' => 'left');
}
}
$rows[] = $row;
if (sizeof($item)) {
$items[] = theme('item_list', $item);
$rows[] = $items;
}
else {
$row[] = array(
'data' => t('No se encontrarón Sectores Asociados'),
);
}
}
if (sizeof($rows)) {
$output.= '
'.theme('table', $header, $rows);
$output .= theme('pager', NULL);
}
else {
$output.= '' . t('No se encontrarón Ambitos Registrados') .'
';
}
$form['ente_planificador']['marcador'] = array(
'#value' => $output,
);
$form['submit'] = array(
'#type' => 'submit',
'#default_value' => t("Guardar"),
);
return $form;
}
/*
* Agregar los sectores
*/
function ente_planificador_sector_form_sector(&$form_state) {
$form = array();
$form['ente_planificador'] = array(
'#type' => 'fieldset',
'#title' => t('Configuración del Sector'),
'#collapsible' => TRUE,
'#collapsed' => FALSE,
);
$form['ente_planificador']['sector'] = array(
'#type' => 'textfield',
'#title' => t('Nombre del Sector'),
'#description' => t('Nombre del sector al que pertenece el ambito.'),
'#required' => TRUE,
);
$form['ente_planificador']['tid'] = array(
'#type' => 'hierarchical_select',
'#config' => array(
'module' => 'hs_content_taxonomy',
'params' => array(
'vid' => variable_get('ente_planificador_sector_Ambitos', 0),
'tid' => 0,
'depth' => 1,
),
'level_labels' => array(
'status' => 1,
'labels' => array(
0 => t('Ambito'),
),
),
),
'#required' => TRUE,
'#description' => t('Nombre del ambito al que pertenece el sector.'),
);
$header = array();
$header[] = array('data' => t('Lista por Ambitos'), 'colspan' => 3);
$tid = variable_get('ente_planificador_sector_Ambitos', 0);
$terms = taxonomy_get_tree($tid);
foreach ($terms as $term) {
$row = array();
$items = array();
$item = array();
$hij = 0;
$hijos = taxonomy_get_children($term->tid, $term->vid);
foreach ($hijos as $hijo) {
$hij = 1;
}
if ($hij == 1) {
if ($term->depth == 0) { //si el termino es padre (AMBITO)
$row[] = array('data' => '' . l(t($term->name), 'admin/settings/ente_planificador/lista_sectores/'.$term->tid, array('html' => true, 'query' => 'destination=lista_ambitos_y_sectores_asociados')) . '', 'colspan' => 1, 'align' => 'left');
$row[] = array('data' => '' . l(t('Consultar Sectores'), 'admin/settings/ente_planificador/lista_sectores/'.$term->tid, array('html' => true, 'query' => 'destination=lista_ambitos_y_sectores_asociados')) . '', 'colspan' => 1, 'align' => 'left');
}
}
else {
if ($term->depth == 0) { //si el termino es padre (AMBITO)
$row[] = array('data' => '' . t($term->name) . '', 'colspan' => 1, 'align' => 'left');
$row[] = array('data' => '' . t('No posee Sectores asociados') . '', 'colspan' => 1, 'align' => 'left');
}
}
$rows[] = $row;
if (sizeof($item)) {
$items[] = theme('item_list', $item);
$rows[] = $items;
}
else {
$row[] = array(
'data' => t('No se encontrarón Sectores Asociados'),
);
}
}
if (sizeof($rows)) {
$output.= '
'.theme('table', $header, $rows);
$output .= theme('pager', NULL);
}
else {
$output.= '' . t('No se encontrarón Ambitos Registrados') .'
';
}
$form['ente_planificador']['marcador'] = array(
'#value' => $output,
);
$form['submit'] = array(
'#type' => 'submit',
'#default_value' => t("Guardar"),
'#submit' => array('ente_planificador_sector_form_sectores_submit'),
);
return $form;
}
/**
* Implementation of ente_planificador_agregar_ambitos_form_submit().
* Save ambitos values
*/
function ente_planificador_sector_form_ambito_submit($form, &$form_state) {
$vocabulary = taxonomy_vocabulary_load(variable_get('ente_planificador_sector_Ambitos', 0));
$term1 = array(
'vid' => $vocabulary->vid, // Voacabulary ID
'name' => check_plain($form_state['values']['ente_planificador_ambito']), // Term Name
);
taxonomy_save_term($term1);
drupal_set_message(t('El Ambito %ambito ha sido agregado', array('%ambito' => $tem1->name)));
$form_state['redirect'] = 'admin/settings/ente_planificador/agregar_ambitos';
}
/*
* Lista todas los ambitos y sectores asociados
*/
function ente_planificador_sector_lista_ambito() {
drupal_set_title(t('Lista de ambitos'));
$view = FALSE;
if (user_access('admin planificador')) {
$view = TRUE;
}
$header = array();
$header[] = array('data' => t('Lista por Ambitos'), 'colspan' => 3);
$procesos_status = ente_planificador_procesos('status');
$procesos = ente_planificador_procesos();
$procesos_ordenados = ente_planificador_ordena_procesos($procesos_status, $procesos);
$procesos_status = $procesos_ordenados['status'];
$nuevo_proceso = $procesos_ordenados['normal'];
$tid = variable_get('ente_planificador_sector_Ambitos', 0);
$terms = taxonomy_get_tree($tid);
foreach ($terms as $term) {
$row = array();
$items = array();
$item = array();
$hij = 0;
$hijos = taxonomy_get_children($term->tid, $term->vid);
foreach ($hijos as $hijo) {
$hij = 1;
}
if ($hij == 1) {
if ($term->depth == 0) { //si el termino es padre (AMBITO)
$row[] = array('data' => '' . l(t($term->name), 'admin/settings/ente_planificador/lista_sectores/' . $term->tid, array('html' => true, 'query' => 'destination=lista_ambitos_y_sectores_asociados')) . '', 'colspan' => 1, 'align' => 'left');
$row[] = array('data' => '' . l(t('Consultar Sectores'), 'admin/settings/ente_planificador/lista_sectores/' . $term->tid, array('html' => true, 'query' => 'destination=lista_ambitos_y_sectores_asociados')) . '', 'colspan' => 1, 'align' => 'left');
$row[] = array('data' => l(t('Modificar Ambito'), 'admin/content/taxonomy/edit/term/' . $term->tid, array('html' => true, 'query' => 'destination=lista_ambitos_y_sectores_asociados')) . '', 'colspan' => 1, 'align' => 'left');
}
}
else {
if ($term->depth == 0) { //si el termino es padre (AMBITO)
$row[] = array('data' => '' . t($term->name) . '', 'colspan' => 1, 'align' => 'left');
$row[] = array('data' => '' . t('No posee Sectores asociados') . '', 'colspan' => 1, 'align' => 'left');
$row[] = array('data' => l(t('Modificar Ambito'), 'admin/content/taxonomy/edit/term/' . $term->tid, array('html' => true, 'query' => 'destination=lista_ambitos_y_sectores_asociados')) . '', 'colspan' => 1, 'align' => 'left');
}
}
$rows[] = $row;
if (sizeof($item)) {
$items[] = theme('item_list', $item);
$rows[] = $items;
}
else {
$row[] = array(
'data' => t('No se encontrarón Sectores Asociados'),
);
}
}
if (sizeof($rows)) {
$output.= '
'.theme('table', $header, $rows);
$output .= theme('pager', NULL);
}
else {
$output.= '' . t('No se encontrarón Ambitos Registrados') .'
';
}
return $output;
}
/*
* Lista todas los ambitos y sectores asociados
*/
function ente_planificador_sector_lista_sectores($ambito = 0) {
$view = FALSE;
if (user_access('admin planificador')) {
$view = TRUE;
}
$term = taxonomy_get_term($ambito);
drupal_set_title(t("Lista de Sectores asociados al ambito %ambito", array('%ambito' => $term->name)));
$terms = taxonomy_get_children($term->tid, $term->vid);
$header = array();
$header[] = array('data' => t('Lista de los Sectores Asociados al Ambito '. $term->name), 'colspan' => 2, 'align' => 'center');
foreach ($terms as $term) {
$row = array();
$items = array();
$item = array();
$hij = 0;
$hijos = taxonomy_get_children($term->tid, $term->vid);
foreach ($hijos as $hijo) { //anadiendo los hijos del sector
$item[] = array(
'data'=> t('%sector', array('%sector' => $hijo->name)),
);
$hij = 1;
}
if ($hij == 0) { //no posee hijos
$row[] = array('data' => '' . t($term->name) . theme('item_list', $item) . '' , 'colspan' => 1, 'align' => 'left');
}
else {
$row[] = array('data' => '' . l(t($term->name) . theme('item_list', $item), 'admin/settings/ente_planificador/lista_sectores/'.$term->tid, array('html' => true, 'query' => 'destination=lista_ambitos_y_sectores_asociados')) . '' , 'colspan' => 1, 'align' => 'left');
}
$row[] = array('data' => '' . l(t('Modificar Sector'), 'admin/content/taxonomy/edit/term/'.$term->tid, array('html' => true, 'query' => 'destination=admin/settings/ente_planificador/lista_sectores/'.$ambito)) . '', 'colspan' => 1, 'align' => 'left');
$rows[] = $row;
}
if (sizeof($rows)) {
$output.= '
'.theme('table', $header, $rows);
$output .= theme('pager', NULL);
}
else {
$output.= '' . t('No se encontrarón Sectores Registrados') .'
';
}
return $output;
}
/**
* Implementation of ente_planificador_agregar_ambitos_form_submit().
* Save ambitos values
*/
function ente_planificador_sector_form_sectores_submit($form, &$form_state) {
$tems = taxonomy_get_term($form_state['values']['tid']);
$vocabulary = taxonomy_vocabulary_load(variable_get('ente_planificador_sector_Ambitos', 0));
$tems = taxonomy_get_term($tems->tid);
$term1 = array(
'vid' => $vocabulary->vid, // Voacabulary ID
'name' => check_plain($form_state['values']['sector']),
'parent' => array($tems->tid),
);
taxonomy_save_term($term1);
drupal_set_message(t('El Ambito %ambito y los sectores han sido agregados', array('%ambito' => $tem1->name)));
$form_state['redirect'] = 'admin/settings/ente_planificador/agregar_sectores';
}
/**
* Implementation of hook_views_api().
*/
function ente_planificador_sector_views_api() {
return array(
'api' => '2.0',
'path' => drupal_get_path('module', 'ente_planificador_sector') . '/includes/views',
);
}
/*
* Implementation of hook_nodeapi()
*/
function ente_planificador_sector_nodeapi(&$node, $op, $arg = 0) {
//tipo de contenido ente planificador
if ($node->type == 'ente_planificador') {
//agregando el sector a la vista del nodo
if ($op == 'presave') {
$level = 0;
$hierarchical = variable_get('ente_planificador_hierarchical_count', 2);
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;
}
}
if (($level) > 2) {
if (!$node->ambito) {
$level_lower = $level - 1;
$father = $node->{'ente_planificador_hierarchical_father_' . $level_lower};
$node_father = node_load($father);
$node->ambito = $node_father->ambito;
$node->sector = $node_father->sector;
}
}
else {
if (isset($node->sector)) {
$parent = taxonomy_get_parents($node->sector);
$node->ambito = key($parent);
}
}
}
if ($op == 'view') {
if ($node->content['title1']) {
$node->content['title1']['#prefix'] = '';
}
if ($node->tipo > 1 && $node->sector && $node->ambito) {
$term = taxonomy_get_term($node->ambito);
$node->content['ambito'] = array(
'#prefix'=>'
',
'#value' => "" . t('Ambito:') . " " . $term->name . "
",
'#weight' => 2,
'#suffix'=>'
',
);
$tid = check_plain($node->sector);
$term = taxonomy_get_term($tid);
$node->content['sector'] = array(
'#prefix'=>'',
'#value' => "" . t('Sector:') . " " . $term->name . "
",
'#weight' => 2,
'#suffix'=>'
',
);
}
if ($node->tipo) {
$node->content['tipo'] = array(
'#prefix'=>'',
'#value' => "" . t('Nivel de Planificación: ') . "" . ente_planificador_sector_nivel_planificacion($node->tipo) . "
",
'#weight' => 1,
'#suffix'=>'
',
);
}
/*
if ($node->organismo) {
$term = taxonomy_get_term($node->organismo);
$node->content['organismo'] = array(
'#prefix'=>'',
'#value' => "" . t('Organismo Público: ') . "" . $term->name . "
",
'#weight' => 3,
'#suffix'=>'
',
);
}
if ($node->sub_ente) {
$result = db_result(db_query("SELECT title FROM {node} WHERE nid = %d", $node->sub_ente));
$node->content['sub_ente'] = array(
'#prefix'=>'',
'#value' => "" . t('Ente al cual se está adscrito: ') . "" . $result . "
",
'#weight' => 5,
'#suffix'=>'
',
);
}
*/
if (user_access('admin all planificador')) {
$node->content['link_add_ente'] = array(
'#prefix'=>'',
'#value' => "" . l(t('Agregar un nuevo Ente planificador'),'node/add/ente-planificador'),
'#weight' => 999999,
'#suffix'=>'
',
);
}
}
//anadiendo el sector al que pertence el ente planificador
if ($op == 'insert' || $op == 'update') {
db_query("UPDATE {ente_planificador} set ambito = %d, sector = %d WHERE nid = %d", $node->ambito, $node->sector, $node->nid);
if ($node->tipo == 1) { //Organismo público.
db_query("UPDATE {ente_planificador} set organismo = %d, ente_adscrito = %d, sub_ente = %d WHERE nid = %d", 0, 0, 0, $node->nid);
}
if ($node->tipo == 2) { //Organismo público.
$vocabulary = taxonomy_vocabulary_load(variable_get('ente_planificador_sector_organismos', 0));
if ($op == 'update') {
$organismo = db_result(db_query("SELECT organismo FROM {ente_planificador} WHERE nid = %d", $node->nid));
$term = array(
'vid' => $vocabulary->vid, // Voacabulary ID
'name' => $node->title, // Term Name
'tid' => $organismo,
);
}
if ($op == 'insert') {
$term = array(
'vid' => $vocabulary->vid, // Voacabulary ID
'name' => $node->title, // Term Name
);
}
taxonomy_save_term($term);
$organismo = $term['tid'];
db_query("UPDATE {ente_planificador} set organismo = %d, ente_adscrito = %d, sub_ente = %d WHERE nid = %d", $organismo, 0, 0, $node->nid);
}
if ($node->ente_adscrito && $node->tipo == 3) { //Ente adscrito a un organismo público.
$ente_adscrito = $node->ente_adscrito;
db_query("UPDATE {ente_planificador} set ente_adscrito = %d, sub_ente = %d, organismo = %d WHERE nid = %d", $ente_adscrito, 0, $ente_adscrito, $node->nid);
}
if ($node->sub_ente && $node->tipo == 4) { //Ente adscrito a otro ente adscrito (sub-ente adscrito).
$sub_ente = $node->sub_ente;
$result = db_query("SELECT organismo FROM {ente_planificador} WHERE nid = %d", $node->sub_ente);
$row = db_fetch_object($result);
if ($row) {
db_query("UPDATE {ente_planificador} set sub_ente = %d, ente_adscrito = %d, organismo = %d WHERE nid = %d", $sub_ente, $sub_ente, $row->organismo, $node->nid);
}
}
}
}
}
/*
* Implementation of hook_views_default_views_alter().
*/
function ente_planificador_sector_views_default_views_alter(&$views) {
foreach ($views as $view) {
if ($view->name == 'planificacionM') { //modificacion de la vista Consultar datos de los actores planificadores (APM/APMS)
//style options sector
$view->display['default']->display_options['filters']['sector'] = array(
'operator' => 'or',
'value' => NULL,
'group' => '0',
'exposed' => TRUE,
'expose' => array(
'use_operator' => 0,
'operator' => 'sector_op',
'identifier' => 'sector',
'label' => 'Sector Social',
'optional' => 1,
'single' => 1,
'remember' => 0,
'reduce' => 0,
),
'id' => 'sector',
'table' => 'ente_planificador',
'field' => 'sector',
'override' => array(
'button' => 'Override',
),
);
//definition field sector
$sector = array(
'label' => 'Sector Social',
'alter' => array(
'alter_text' => 0,
'text' => '',
'make_link' => 0,
'path' => '',
'link_class' => '',
'alt' => '',
'prefix' => '',
'suffix' => '',
'target' => '',
'help' => '',
'trim' => 0,
'max_length' => '',
'word_boundary' => 1,
'ellipsis' => 1,
'html' => 0,
'strip_tags' => 0,
),
'empty' => '',
'hide_empty' => 0,
'empty_zero' => 0,
'exclude' => 0,
'link_to_node' => 0,
'id' => 'estado',
'table' => 'ente_planificador',
'field' => 'sector',
'relationship' => 'none',
);
//ordenando el campo
$view->display['default']->display_options['style_options']['columns']['sector'] = 'sector';
$sort = array(
'sortable' => 1,
'separator' => "",
);
$style = array_pop($view->display['default']->display_options['style_options']);
$view->display['default']->display_options['style_options']['info']['sector'] = $sort;
$view->display['default']->display_options['style_options']['nothing'] = $style;
// add field
$nothing = array_pop($view->display['default']->display_options['fields']);
$view->display['default']->display_options['fields']['sector'] = $sector;
$view->display['default']->display_options['fields']['nothing'] = $nothing;
} //end find view planificacionM
}
}
/**
* Implmentations of hook_menu_alter
*/
function ente_planificador_menu_alter(&$items) {
// $items['administrar/entes_planificadores']['page callback'] = 'ente_planificador_sector_lista_entes_redirect';
// $items['administrar_usuarios']['page callback'] = 'ente_planificador_sector_lista_usuarios_redirect';
}
/**
* Redirigir a la vista lista de los entes planificadores
*/
function ente_planificador_sector_lista_entes_redirect() {
drupal_goto('administrar/entes_planificadores/lista');
}
/**
* Redirigir a la vista lista de los usuarios
*/
function ente_planificador_sector_lista_usuarios_redirect() {
drupal_goto('administrar_usuarios/lista');
}
/**
* genera el ahah alregistrar los entes planificadores
*/
function ente_planificador_sector_js_util() {
$tipo = 'nivel';
$form_state = array('submitted' => FALSE);
$form_build_id = $_POST['form_build_id'];
// Add the new element to the stored form. Without adding the element tothe
// 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);
if ($_POST['tipo'] != 1) {
$new_form['nivel'] = array(
'#type' => 'fieldset',
);
}
if ($_POST['tipo'] == 2) {
$options = array();
$tid = variable_get('ente_planificador_sector_Ambitos', 0);
$terms = taxonomy_get_tree($tid);
$options['0']= "seleccione";
foreach ($terms as $term) {
if ($term->depth == 1) { //si el termino es padre
$options[$term->tid] = $term->name;
}
}
$new_form['nivel']['sector'] = array(
'#title' => t('Sector Social'),
'#type' => 'select',
'#required' => TRUE,
'#options' => $options,
'#prefix' => '',
'#suffix' => '
',
);
$form[$tipo]['sector'] = $new_form['sector'];
}
if ($_POST['tipo'] == 3) {
$options = array();
$options[0] = "seleccione";
$tid = variable_get('ente_planificador_sector_organismos', 0);
$terms = taxonomy_get_tree($tid);
foreach ($terms as $term) {
$options[$term->tid] = $term->name;
}
$new_form['nivel']['ente_adscrito'] = array(
'#type' => 'select',
'#title' => t('Organismo Publico al que se esta adscrito'),
'#required' => TRUE,
'#options' => $options,
'#prefix' => '',
'#suffix' => '
',
);
$form[$tipo]['ente_adscrito'] = $new_form['ente_adscrito'];
}
if ($_POST['tipo'] == 4) {
$options = array();
$options['0']= "seleccione";
$result = db_query("SELECT n.nid, n.title FROM {node} AS n INNER JOIN {ente_planificador} AS e ON n.nid = e.nid WHERE e.ente_adscrito != 0");
while ($rows = db_fetch_object($result)) {
$options[$rows->nid] = $rows->title;
}
$new_form['nivel']['sub_ente'] = array(
'#type' => 'select',
'#title' => t('Ente al cual se esta adscrito'),
'#required' => TRUE,
'#options' => $options,
'#prefix' => '',
'#suffix' => '
',
);
$form[$tipo]['sub_ente'] = $new_form['sub_ente'];
}
$form[$tipo] = $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 = $form[$tipo];
unset($new_form['#prefix'], $new_form['#suffix']); // Prevent duplicate wrappers.
// Rebuild the form.
$form = form_builder($_POST['form_id'], $form, $form_state);
// Render the new output.
$new_form = array();
$output = drupal_render($new_form);
print drupal_to_js(array('data' => $output, 'status' => true));
exit();
}
/**
* Implementation of hook_ente_planificador_proceso_user_acceso_alter
*/
function ente_planificador_sector_ente_planificador_proceso_user_acceso_alter(&$fechas, $conf) {
$ente_planificador = $conf['ente_planificador'];
$type_proceso = $conf['proceso'];
$now = time();
global $user;
$rol_macro = variable_get('ActorPlanificadorMacro', 0);
$options = variable_get('ente_planificador_sector_optiones_fecha', 'ambito');
if ($type_proceso) {
if ((is_object($ente_planificador))) {
if ($ente_planificador->ambito) {
if ($options == 'sector') {
$term = taxonomy_get_term($ente_planificador->sector);
$FIPMI = variable_get('ente_planificador_' . $type_proceso . '_from_' . $term->tid, $now);
$FIPMF = variable_get('ente_planificador_' . $type_proceso . '_until_' . $term->tid, $now);
}
if ($options == 'ambito') {
$term = taxonomy_get_term($ente_planificador->ambito);
$FIPMI = variable_get('ente_planificador_' . $type_proceso . '_all_from_' . $term->tid, $now);
$FIPMF = variable_get('ente_planificador_' . $type_proceso . '_all_until_' . $term->tid, $now);
}
}
elseif(isset($user->ambito_user) && $ente_planificador->tipo == 1 && !(in_array($rol_macro, array_keys($user->roles)))) {
$term = taxonomy_get_term($user->ambito_user);
$FIPMI = variable_get('ente_planificador_' . $type_proceso . '_all_from_' . $term->tid, $now);
$FIPMF = variable_get('ente_planificador_' . $type_proceso . '_all_until_' . $term->tid, $now);
}
}
if (is_numeric($ente_planificador) || user_access('admin all planificador')) { //si es el administrador se aplica la fecha especial
$FIPMI = variable_get('ente_planificador_' . $type_proceso . '_admin_from', $now);
$FIPMF = variable_get('ente_planificador_' . $type_proceso . '_admin_until', $now);
}
if (in_array($rol_macro, array_keys($user->roles))) { //es usuario control
$FIPMI = variable_get('ente_planificador_' . $type_proceso . '_control_from', $now);
$FIPMF = variable_get('ente_planificador_' . $type_proceso . '_control_until', $now);
}
if ($FIPMI) {
$fechas[0] = $FIPMI;
}
if ($FIPMF) {
$fechas[1] = $FIPMF;
}
}
}
/**
* Implementation of hook_ente_planificador_muestra_mensaje_alter
*/
function ente_planificador_sector_ente_planificador_muestra_mensaje_alter(&$new_mensaje, $conf) {
$type_proceso = $conf['plan_tipo'];
$procesos = ente_planificador_procesos();
$ente_planificador = $conf['ente_planificador'];
$ambito_text = "Ambito Especial de Administración";
$sector_text = "Sector Especial";
$now = time();
global $user;
$rol_macro = variable_get('ActorPlanificadorMacro', 0);
$expire = $conf['expire'];
if ($type_proceso) {
if (is_object($ente_planificador)) {
if ($ente_planificador->ambito) {
$sector = taxonomy_get_term($ente_planificador->sector);
$ambito = taxonomy_get_term($ente_planificador->ambito);
$mi_fecha = array(
variable_get('ente_planificador_' . $type_proceso . '_all_from_' . $ambito->tid, $now),
variable_get('ente_planificador_' . $type_proceso . '_all_until_' . $ambito->tid, $now),
);
if ($expire) {
$new_mensaje = t('Registrar y/o modificar la fase de "@title" para el Ambito %ambito en el Sector %sector no se encuentra disponible, se podra realizar desde el %fechaI hasta %fechaF', array('%ambito' => strtoupper($ambito->name), '%sector' => strtoupper($sector->name), '%fechaI' => format_date($mi_fecha[0]), '%fechaF' => format_date($mi_fecha[1]), '@title' => $procesos[$type_proceso]['title']));
}
else {
$new_mensaje = t('Se podra registrar y/o modificar la fase de "@title" para el Ambito %ambito en el Sector %sector desde el %fechaI hasta %fechaF', array('%ambito' => strtoupper($ambito->name), '%sector' => strtoupper($sector->name), '%fechaI' => format_date($mi_fecha[0]), '%fechaF' => format_date($mi_fecha[1]), '@title' => $procesos[$type_proceso]['title']));
}
}
elseif(isset($user->ambito_user) && $ente_planificador->tipo == 1 && !(in_array($rol_macro, array_keys($user->roles)))) {
if (empty($user->ambito_user)) {
drupal_set_message(t('Especifique el ambito del usuario supervisor.'), 'warning');
}
$ambito = taxonomy_get_term($user->ambito_user);
$FIPMI = variable_get('ente_planificador_' . $type_proceso . '_all_from_' . $ambito->tid, $now);
$FIPMF = variable_get('ente_planificador_' . $type_proceso . '_all_until_' . $ambito->tid, $now);
if ($expire) {
$new_mensaje = t('Registrar y/o modificar la fase de "@title" para el Ambito %ambito no se encuentra disponible, se podra realizar desde el %fechaI hasta %fechaF', array('%ambito' => strtoupper($ambito->name), '%fechaI' => format_date($FIPMI), '%fechaF' => format_date($FIPMF), '@title' => $procesos[$type_proceso]['title']));
}
else {
$new_mensaje = t('Se podra registrar y/o modificar la fase de "@title" para el Ambito %ambito desde el %fechaI hasta %fechaF', array('%ambito' => strtoupper($ambito->name), '%fechaI' => format_date($FIPMI), '%fechaF' => format_date($FIPMF), '@title' => $procesos[$type_proceso]['title']));
}
}
}
if (is_numeric($ente_planificador) || user_access('admin all planificador')) { //si es el administrador se aplica la fecha especial
$mi_fecha = array(
variable_get('ente_planificador_' . $type_proceso . '_admin_from', $now),
variable_get('ente_planificador_' . $type_proceso . '_admin_until', $now),
);
$new_mensaje = t("Como usuario administrador puede acceder desde %fechaI hasta %fechaF", array('%fechaI' => format_date($mi_fecha[0]), '%fechaF' => format_date($mi_fecha[1])));
}
if (in_array($rol_macro, array_keys($user->roles))) { //es usuario control
$mi_fecha = array(
variable_get('ente_planificador_' . $type_proceso . '_control_from', $now),
variable_get('ente_planificador_' . $type_proceso . '_control_until', $now),
);
$new_mensaje = t("Como usuario Control puede acceder desde %fechaI hasta %fechaF", array('%fechaI' => format_date($mi_fecha[0]), '%fechaF' => format_date($mi_fecha[1])));
}
}
}