t('Actor operativo'), 1 => t('Actor estratégico-táctico'), ); drupal_alter('obtiene_tipos', $tipos); if ($tipo && is_numeric($tipo) && $tipos[$tipo]) { return $tipos[$tipo]; } elseif($tipo) { return FALSE; } return $tipos; } /* * ente_planificador_ente_macro() * Obtiene el ente macro de un ente micro, actualmente esta funcion regresa el unico ente macro permitido en el sistema * pero podria modificarse en un futuro con otro modulo invocando el hook_obtiene_macro_alter */ function ente_planificador_ente_macro($ente_planificador = 0) { $actor_macro = FALSE; $result = db_query("SELECT d.nid FROM {ente_planificador} AS d INNER JOIN {node} AS n ON n.nid = d.nid WHERE tipo = 1"); $macro = db_fetch_object($result); if ($macro->nid){ $actor_macr0 = $macro->nid; } drupal_alter('obtiene_macro', $actor_macr0, $ente_planificador); return $actor_macr0; } /* * Implementation of hook_menu() */ function ente_planificador_menu() { $items = array(); $items['administrar/entes_planificadores'] = array( 'title' => 'Consultar lista de actores planificadores', 'page callback' => 'entes_planificadores', 'access arguments' => array('ver planificador'), 'type' => MENU_NORMAL_ITEM, ); $items['entes_planificadores/registrar'] = array( 'title' => 'Registrar Actores Planificadores', 'page callback' => 'entes_planificadores_agregar', 'page arguments' => array(1), 'access arguments' => array('admin planificador'), 'type' => MENU_NORMAL_ITEM, ); $items['ente_planificador_js_util/%'] = array( 'title' => 'JS utilities', 'page callback' => 'ente_planificador_js_util', 'page arguments' => array(1), 'access arguments' => array('access content'), 'type' => MENU_CALLBACK, ); $items['administrar/entes_planificadores/registrar'] = array( 'title' => 'Registrar Actores Planificadores', 'page callback' => 'entes_planificadores_agregar', 'page arguments' => array(1), 'access arguments' => array('admin planificador'), 'type' => MENU_NORMAL_ITEM, ); $items['administrar/entes_planificadores/lista'] = array( 'title' => t('List'), 'type' => MENU_DEFAULT_LOCAL_TASK, 'weight' => -10 ); $items['node/%/datos_basicos'] = array( 'title' => 'Editar datos del actor planificador', 'page callback' => 'ente_planificador_datos_basicos', 'page arguments' => array(1), 'access callback' => 'nodo_es_ente_planificador', 'access arguments' => array(1), 'type' => MENU_LOCAL_TASK, ); $items['node/%/usuarios'] = array( 'title' => 'Usuarios Asignados', 'page callback' => 'entes_planificadores_usuarios', 'page arguments' => array(1), 'access callback' => 'nodo_es_ente_planificador', 'access arguments' => array(1), 'type' => MENU_LOCAL_TASK, ); $items['node/%/planificacion'] = array( 'title' => 'Planificación', 'page callback' => 'entes_planificadores_planificacion', 'page arguments' => array(1), 'access callback' => 'nodo_es_ente_planificador', 'access arguments' => array(1), 'type' => MENU_LOCAL_TASK, ); $items['administrar_usuarios'] = array( 'title' => 'Consultar Listado de Usuarios', 'page callback' => 'entes_planificadores_listar_usuarios', 'access arguments' => array('admin planificador'), 'type' => MENU_NORMAL_ITEM, ); $items['fechas_planificacion'] = array( 'title' => 'Consultar listado de fechas de las procesos de planificación', 'page callback' => 'ente_planificador_fecha_planificacion', 'access arguments' => array('ver planificador'), 'type' => MENU_NORMAL_ITEM, ); $items['fechas_planificacion/envia_email'] = array( 'title' => 'Enviar Correo Electronico de la fecha de Planificación', 'page callback' => 'ente_planificador_fecha_planificacion_correo', 'access callback' => 'usuario_tiene_permisos', 'type' => MENU_NORMAL_ITEM, ); $items['fechas_planificacion/edit'] = array( 'title' => 'Modificar las fechas para los procesos de planificación.', 'page callback' => 'ente_planificador_fecha_planificacion_edit', 'access arguments' => array('admin planificador'), 'type' => MENU_CALLBACK, ); $items['fechas_planificacion/todas_edit'] = array( 'title' => 'Modificar todas las fechas para los procesos de planificación.', 'page callback' => 'drupal_get_form', 'page arguments' => array('ente_planificador_fecha_planificacion_edit_todas'), 'access arguments' => array('admin planificador'), 'type' => MENU_NORMAL_ITEM, ); $items['fechas_planificacion/notificacion'] = array( 'title' => 'Fecha de notificación.', 'page callback' => 'drupal_get_form', 'page arguments' => array('ente_planificador_fecha_planificacion_edit_notificacion'), 'access arguments' => array('admin planificador'), 'type' => MENU_NORMAL_ITEM, ); $items['admin/settings/ente_planificador'] = array( 'title' => t('Configuración Ente Planificador'), 'description' => t('Configuración del Ente Planificador.'), 'page callback' => 'drupal_get_form', 'page arguments' => array('ente_planificador_admin_settings'), 'access arguments' => array('admin planificador'), 'type' => MENU_NORMAL_ITEM, ); $items['admin/settings/ente_planificador/view'] = array( 'title' => t('Configuración Ente Planificador'), 'type' => MENU_DEFAULT_LOCAL_TASK, 'weight' => -10 ); $items['admin/settings/ente_planificador/actividades'] = array( 'title' => t('Actividades'), 'page callback' => 'ente_planificador_view_actividades', 'access arguments' => array('admin planificador'), 'weight' => -8, 'type' => MENU_LOCAL_TASK, ); $items['admin/settings/ente_planificador/agregar_actividades'] = array( 'title' => t('Agregar Actividad'), 'page callback' => 'drupal_get_form', 'page arguments' => array('ente_planificador_agregar_actividades_form'), 'access arguments' => array('admin planificador'), 'weight' => -8, 'type' => MENU_LOCAL_TASK, ); $items['admin/settings/ente_planificador/actividades/%actividad_menu/edit'] = array( 'title' => t('Modificar'), 'page callback' => 'drupal_get_form', 'page arguments' => array('ente_planificador_edit_actividad_form',4), 'access arguments' => array('admin planificador'), 'type' => MENU_CALLBACK, ); $items['admin/settings/ente_planificador/actividades/%actividad_menu/remove'] = array( 'title' => t('Modificar'), 'page callback' => 'drupal_get_form', 'page arguments' => array('ente_planificador_eliminar_actividad_form',4), 'access arguments' => array('admin planificador'), 'type' => MENU_CALLBACK, ); $items['planificacion/%ente_planificador_menu'] = array( 'title' => t('Planificación'), 'page callback' => 'ente_planificador_view_planning', 'page arguments' => array(1), 'access arguments' => array('ver planificador'), 'weight' => -10, 'type' => MENU_CALLBACK, ); $items['planificacion/%ente_planificador_menu/view'] = array( 'title' => 'View', 'type' => MENU_DEFAULT_LOCAL_TASK, 'weight' => -10 ); $items['mi_ente_planificador'] = array( 'title' => 'Mi ente planificador', 'page callback' => 'mis_entes_planificadores', 'access callback' => 'ente_planificador_usuario_ve_ente', 'type' => MENU_NORMAL_ITEM, ); $items['mi_ente_planificador/view'] = array( 'title' => 'View', 'type' => MENU_DEFAULT_LOCAL_TASK, 'weight' => -10 ); $items['mi_ente_planificador/datos_basicos'] = array( 'title' => 'Editar datos del actor planificador', 'page callback' => 'mis_entes_planificadores_datos_basicos', 'access callback' => 'ente_planificador_usuario_ve_ente', 'type' => MENU_LOCAL_TASK, ); $items['mi_ente_planificador/usuarios'] = array( 'title' => 'Usuarios Asignados', 'page callback' => 'mis_entes_planificadores_usuarios', 'access callback' => 'ente_planificador_usuario_ve_ente', 'type' => MENU_LOCAL_TASK, ); $items['mi_ente_planificador/planificacion'] = array( 'title' => 'Mi planificación', 'page callback' => 'mis_entes_planificadores_planificacion', 'access callback' => 'ente_planificador_usuario_ve_ente', 'type' => MENU_LOCAL_TASK, ); $items['mi_ente_planificador/planificacion/view'] = array( 'title' => 'View', 'type' => MENU_DEFAULT_LOCAL_TASK, 'weight' => -10 ); return $items; } /* * Implementation of ente_planificador_usuario_ve_ente() */ function ente_planificador_usuario_ve_ente() { global $user; if (user_access('edit own planificador')) { $ente = usuario_tiene_ente($user->uid); if ($ente->nid) { return TRUE; } } return FALSE; } /* * Implementation of mis_entes_planificadores_datos_basicos() */ function mis_entes_planificadores_datos_basicos() { global $user; $output = ''; $ente = usuario_tiene_ente($user->uid); if ($ente->nid) { $output .= ente_planificador_datos_basicos($ente->nid); } return $output; } /* * Implementation of mis_entes_planificadores_usuarios() */ function mis_entes_planificadores_usuarios() { global $user; $output = ''; $ente = usuario_tiene_ente($user->uid); if ($ente->nid) { $output .= entes_planificadores_usuarios($ente->nid); } return $output; } /* * Implementation of mis_entes_planificadores_planificacion() */ function mis_entes_planificadores_planificacion() { global $user; $output = ''; $ente = usuario_tiene_ente($user->uid); if ($ente->nid) { $ente = ente_planificador_leer($ente->nid); $output .= ente_planificador_view_planning($ente); } return $output; } /** * Implementation of actividad_menu_load(). * Menu loader callback. Load actividad. */ function actividad_menu_load($actividad) { if ($actividad) { $resul_act = db_query("SELECT * FROM {ente_actividad} where id_actividad = %d", $actividad); $actividad = db_fetch_object($resul_act); return $actividad; } return FALSE; } /* * Implementation of ente_planificador_view_actividades() */ function ente_planificador_view_actividades() { $header = array(); $header[] = array('data' => t('Name')); $header[] = array('data' => t('Action'), 'colspan' => 2); $actividades = ente_planificador_obtener_actividades(); $rows = array(); foreach($actividades as $id => $actividad) { $row = array(); $row[] = array('data' => t($actividad), ); $row[] = array( 'data' => l(t('Update'), 'admin/settings/ente_planificador/actividades/' . $id . '/edit'), ); $row[] = array( 'data' => l(t('Remove'),'admin/settings/ente_planificador/actividades/' . $id . '/remove'), ); $rows[] = $row; } if (!count($rows)) { $row = array(); $row[] = array( 'data' => t('No se encontrarón actividades'), 'colspan' => 3 ); $rows[] = $row; } return theme('table', $header, $rows); } /** * Implementation of webforms_countries_menu_country_load(). * Menu loader callback. Load a country. */ function ente_planificador_menu_load($ente_planificador_menu) { $ente = ente_planificador_leer($ente_planificador_menu); if ($ente) { return $ente; } return FALSE; } /* * Implementation of ente_planificador_agregar_actividades_form() */ function ente_planificador_agregar_actividades_form(&$form_state) { $form = array(); $form['nombre'] = array( '#title' => t('Actividad'), '#type' => 'textfield', '#default_value' => $actividad_menu->nombre, '#required' => TRUE, '#maxlength' => 1024, ); $form['submit'] = array( '#type' => 'submit', '#value' => t('Save Actividad'), '#weight' => 40, ); return $form; } /** * Implementation of ente_planificador_agregar_actividades_form_submit(). * Save actividad values */ function ente_planificador_agregar_actividades_form_submit($form, &$form_state) { db_query("INSERT INTO {ente_actividad} (nombre) VALUES ('%s')", check_plain($form_state['values']['nombre'])); drupal_set_message(t('Actividad %name_actividad agregada', array('%name_actividad' => $form_state['values']['nombre']))); $form_state['redirect'] = 'admin/settings/ente_planificador/actividades'; } /** * Implementation of ente_planificador_edit_actividad_form(). * Edit a actividad data. */ function ente_planificador_edit_actividad_form(&$form_state, $actividad_menu) { $form['id_actividad'] = array( '#type' => 'hidden', '#value' => $actividad_menu->id_actividad, ); $form['nombre'] = array( '#title' => t('Actividad'), '#type' => 'textfield', '#default_value' => $actividad_menu->nombre, '#required' => TRUE, '#maxlength' => 1024, ); $form['submit'] = array( '#type' => 'submit', '#value' => t('Save Actividad'), '#weight' => 40, ); return $form; } /* * Implementation of ente_planificador_edit_actividad_form_submit() */ function ente_planificador_edit_actividad_form_submit($form, &$form_state) { db_query("UPDATE {ente_actividad} SET nombre = '%s' WHERE id_actividad = %d", check_plain($form_state['values']['nombre']), $form_state['values']['id_actividad']); drupal_set_message(t('Actividad %name_actividad modificada', array('%name_actividad' => $form_state['values']['nombre']))); $form_state['redirect'] = 'admin/settings/ente_planificador/actividades'; } /* * Implementation of ente_planificador_eliminar_actividad_form() */ function ente_planificador_eliminar_actividad_form(&$form_state, $actividad_menu) { $form['id_actividad'] = array('#type' => 'value', '#value' => $actividad_menu->id_actividad); $form['nombre'] = array('#type' => 'value', '#value' => $actividad_menu->nombre); $message = t('Are you sure you want to delete actividad %name_actividad?', array('%name_actividad' => $actividad_menu->nombre)); $caption = '

'. t('This action cannot be undone.') .'

'; $return_path = 'admin/settings/ente_planificador/actividades'; return confirm_form($form, $message, $return_path, $caption, t('Delete')); } /* * Implementation of ente_planificador_eliminar_actividad_form_submit() */ function ente_planificador_eliminar_actividad_form_submit($form, &$form_state) { db_query("DELETE FROM {ente_actividad} WHERE id_actividad = %d", $form_state['values']['id_actividad']); drupal_set_message(t('Actividad %name_actividad borrada'.$form_state['values']['id_actividad'], array('%name_actividad' => $form_state['values']['nombre']))); $form_state['redirect'] = 'admin/settings/ente_planificador/actividades'; } /* * Implementation of ente_planificador_leer() */ function ente_planificador_leer($nid) { if (isset($nid) && is_numeric($nid)) { $ente = ente_planificador_leer_ente_planificadores($nid); if ($ente->type == 'ente_planificador') { return $ente; } } return FALSE; } /* * Implementation of ente_planificador_obtiene_resumen_planificacion() */ function ente_planificador_obtiene_resumen_planificacion($nid, $type = "all") { $planificacion = array(); $estados = ente_planificador_status_planificacion($nid); $total_suma = 0; $total_ejecutado = 0; if (count($estados)) { foreach($estados as $id_estado => $estado) { $etapas = count($estado['value']); if ($etapas) { $suma = 0; foreach($estado['value'] as $value) { $total_suma++; if ($value['value']) { $suma++; } } $total_ejecutado += $suma; $porc = ($suma * 100) / $etapas; if ($type == "all") { $planificacion['etapas'][] = l($estado['title'] . ' (' . round($porc, 2) . '%).', 'planificacion/' . $nid . '/' . $id_estado); } else { $planificacion['etapas'][] = l($estado['title'] . ' (' . round($porc, 2) . '%).', 'mi_ente_planificador/planificacion/' . $id_estado); } } $planificacion['total'] = ($total_suma > 0) ? ($total_ejecutado * 100) / $total_suma : 0; } } return $planificacion; } /* * Implementation of hook_planificador_block() */ function ente_planificador_block($op = 'list', $delta = 0, $edit = array()) { if ($op == 'list') { $blocks[0] = array( 'info' => t('Mi planificación'), 'cache' => BLOCK_CACHE_PER_USER, ); $blocks[1] = array( 'info' => t('Planificación del Ente'), 'cache' => BLOCK_CACHE_PER_PAGE, ); return $blocks; } else if ($op == 'view') { switch ($delta) { case 0: global $user; $ente = usuario_tiene_ente($user->uid); if ($ente->nid) { $planificacion = ente_planificador_obtiene_resumen_planificacion($ente->nid); if (count($planificacion)) { $output = '

' . l(t('Porcentaje de Avance'), 'mi_ente_planificador/planificacion') . ': ' . round($planificacion['total'], 2) . '%

'; if (count($planificacion['etapas'])) { $output .= ''; } $block = array( 'subject' => t('Mi planificación'), 'content' => $output, ); } } break; case 1: if((arg(0) == 'node' && is_numeric(arg(1))) || (arg(0) == 'planificacion' && is_numeric(arg(1)))) { $ente_planificador = ente_planificador_leer_ente_planificadores(arg(1)); $planificacion = ente_planificador_obtiene_resumen_planificacion(arg(1)); if (count($planificacion)) { $output = '

' . l(t('Porcentaje de Avance'), 'planificacion/' . $ente_planificador->nid) . ': ' . round($planificacion['total'], 2) . '%

'; if (count($planificacion['etapas'])) { $output .= ''; } $block = array( 'subject' => t('Planificación del ente @ente', array('@ente' => $ente_planificador->title)), 'content' => $output, ); } } break; } return $block; } } /* * Implementation of ente_planificador_view_planning() */ function ente_planificador_view_planning($ente_planificador) { $output = '

' . t('Ente planificador: @ente', array('@ente' => $ente_planificador->title)) . '

'; $estados = ente_planificador_status_planificacion($ente_planificador->nid, $ente_planificador->tipo); $header = array(); $header[] = array('data' => t('Etapa')); $header[] = array('data' => t('Estado')); $rows = array(); $total_suma = 0; $total_ejecutado = 0; if (count($estados)) { foreach($estados as $estado) { $row = array(); $row[] = array( 'data' => '' . $estado['title'] . '', 'colspan' => '2', 'align' => 'center' ); $rows[] = $row; $porc = 0; $etapas = count($estado['value']); if ($etapas) { $suma = 0; foreach($estado['value'] as $value) { $total_suma++; $row = array(); $valor = $value['value'] ? t('Comenzada') : t('Por comenzar'); $row[] = array('data' => l($value['title'], $value['link']) ,); $row[] = array('data' => $valor,); $rows[] = $row; if ($value['value']) { $suma++; } } $total_ejecutado += $suma; $porc = ($suma * 100) / $etapas; } $row = array(); $row[] = array( 'data' => '' . t('Porcentaje') . '', 'align' => 'right', ); $row[] = array('data' => '' . round($porc, 2) . ' %' . '',); $rows[] = $row; } $total_porcentaje = ($total_suma > 0) ? ($total_ejecutado * 100) / $total_suma : 0; $row = array(); $row[] = array( 'data' => '' . t('Porcentaje Total : ') . round($total_porcentaje, 2) . ' %', 'colspan' => '2', 'align' => 'center', ); $rows[] = $row; } if (!count($rows)) { $row = array(); $row[] = array( 'data' => t('No se ha podido calcular el estado de planificación del ente: @ente', array( '@ente' => $ente_planificador->title )), 'colspan' => '2', 'align' => 'center' ); $rows[] = $row; } $output .= theme('table', $header, $rows); return $output; } /* * usuario_tiene_permisos * Verifica si el usuario actual tiene permisos de administracion o editar todos los entes */ function usuario_tiene_permisos() { global $user; if ($user->ui == 1 || user_access('edit all planificador') || user_access('admin planificador')) { return TRUE; } return FALSE; } /* * ente_planificador_fecha_planificacion_edit_notificacion * Permite editar las fechas de notificacion de planificacion */ function ente_planificador_fecha_planificacion_edit_notificacion($form_state) { $procesos_status = ente_planificador_procesos('status'); $procesos = ente_planificador_procesos(); $procesos_ordenados = ente_planificador_ordena_procesos($procesos_status, $procesos); $i = 0; $procesos = $procesos_ordenados['normal']; $procesos_status = $procesos_ordenados['status']; if (is_array($procesos_status) && count($procesos_status)) { foreach($procesos_status as $id => $valores) { $form[$id] = array( '#type' => 'fieldset', '#title' => check_plain($valores['title']), ); if (is_array($procesos[$id]) && count($procesos[$id])) { foreach ($procesos[$id] as $type_url_str => $proceso) { $FIPMI = variable_get('ente_planificador_' . $type_url_str . "_cron", 0); $form[$id][$type_url_str] = array( '#type' => 'fieldset', '#title' => t('Fecha de %name', array('%name' => $proceso['title'],)), ); $now = time(); $FIPM = $FIPMI ? $FIPMI : $now; $FFPM = $FIPMF ? $FIPMF : $now; $f1 = explode("-", gmdate("Y-m-d", $FIPM)); settype($f1[0], "integer"); settype($f1[1], "integer"); settype($f1[2], "integer"); $form[$id][$type_url_str][$type_url_str] = array( '#type' => 'date', '#title' => t('Fecha de notificacion'), '#default_value' => array( 'day' => $f1[2], 'month' => $f1[1], 'year' => $f1[0], ), '#description' => t('Seleccione la fecha'), ); $i++; } } } } if (!$i) { global $user; drupal_set_message(t('No existen procesos que planificar')); drupal_goto('user/' . $user->uid); return array(); } else { $form['submit'] = array( '#type' => 'submit', '#validate' =>array('ente_planificador_fecha_planificacion_edit_notificacion_validate'), '#submit' => array('ente_planificador_fecha_planificacion_edit_notificacion_submit'), '#default_value' => t("Guardar"), ); $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_fecha_planificacion_edit_notificacion_validate($form, &$form_state){ $procesos = ente_planificador_procesos(); foreach ($procesos as $key => $proceso) { $fn = mktime( 0, 0, 0, $form_state['values'][$key]['month'], $form_state['values'][$key]['day'], $form_state['values'][$key]['year'] ); $ff = variable_get('ente_planificador_' . $key . "_until", 0); if ($ff <= $fn) { form_set_error( $key, t('La fecha de notificación para %name debe ser mayor a la fecha de culminación @ff @fi', array( '%name' => $proceso['title'], '@ff' => format_date($ff), '@fi' => format_date($fn), )) ); } } } /* * ente_planificador_fecha_planificacion_edit_notificacion_submit * Guardar la informacion de modificar las fechas de notificacion de planificacion */ function ente_planificador_fecha_planificacion_edit_notificacion_submit($form, &$form_state){ $procesos = ente_planificador_procesos(); foreach ($procesos as $type_url_str => $proceso) { $fn = mktime( 0, 0, 0, $form_state['values'][$type_url_str]['month'], $form_state['values'][$type_url_str]['day'], $form_state['values'][$type_url_str]['year'] ); variable_set('ente_planificador_' . $type_url_str . '_cron', $fn); } drupal_set_message(t('Se han guardado los cambios')); } /* * ente_planificador_fecha_planificacion_edit_todas * Permite editar todas las fechas de planificacion */ function ente_planificador_fecha_planificacion_edit_todas($form_state) { $procesos_status = ente_planificador_procesos('status'); $procesos = ente_planificador_procesos(); $procesos_ordenados = ente_planificador_ordena_procesos($procesos_status, $procesos); $i = 0; $procesos = $procesos_ordenados['normal']; $procesos_status = $procesos_ordenados['status']; if (is_array($procesos_status) && count($procesos_status)) { foreach($procesos_status as $id => $valores) { $form[$id] = array( '#type' => 'fieldset', '#title' => check_plain($valores['title']), ); if (is_array($procesos[$id]) && count($procesos[$id])) { foreach ($procesos[$id] as $type_url_str => $proceso) { $FIPMI = variable_get('ente_planificador_' . $type_url_str . "_from", 0); $FIPMF = variable_get('ente_planificador_' . $type_url_str . "_until", 0); $form[$id][$type_url_str] = array( '#type' => 'fieldset', '#title' => t('Fecha de %name', array('%name' => $proceso['title'],)), ); $now = time(); $FIPM = $FIPMI ? $FIPMI : $now; $FFPM = $FIPMF ? $FIPMF : $now; $f1 = explode("-", gmdate("Y-m-d", $FIPM)); settype($f1[0], "integer"); settype($f1[1], "integer"); settype($f1[2], "integer"); $form[$id][$type_url_str][$type_url_str . '_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'), ); $f1 = explode("-", gmdate("Y-m-d", $FFPM)); settype($f1[0], "integer"); settype($f1[1], "integer"); settype($f1[2], "integer"); $form[$id][$type_url_str][$type_url_str . '_until'] = array( '#type' => 'date', '#title' => t('Fecha de Culminación'), '#default_value' => array( 'day' => $f1[2], 'month' => $f1[1], 'year' => $f1[0], ), '#description' => t('Seleccione la fecha'), ); $i++; } } } } if (!$i) { global $user; drupal_set_message(t('No existen procesos que planificar')); drupal_goto('user/' . $user->uid); return array(); } else { $form['submit'] = array( '#type' => 'submit', '#validate' =>array('ente_planificador_fecha_planificacion_edit_todas_validate'), '#submit' => array('ente_planificador_fecha_planificacion_edit_todas_submit'), '#default_value' => t("Guardar"), ); $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_todas_validate * Validar la informacion de modificar todas las fechas de planificacion */ function ente_planificador_fecha_planificacion_edit_todas_validate($form, &$form_state){ $procesos = ente_planificador_procesos(); foreach ($procesos as $key => $proceso) { $fi = mktime( 0, 0, 0, $form_state['values'][$key . '_from']['month'], $form_state['values'][$key . '_from']['day'], $form_state['values'][$key . '_from']['year'] ); $ff = mktime( 0, 0, 0, $form_state['values'][$key . '_until']['month'], $form_state['values'][$key . '_until']['day'], $form_state['values'][$key . '_until']['year'] ); if ($ff <= $fi) { form_set_error( $key . '_from', t('La fecha de culminación para %name debe ser mayor a la fecha de inicio @ff @fi', array( '%name' => $proceso['title'], '@ff' => format_date($ff), '@fi' => format_date($fi), )) ); } } } /* * ente_planificador_fecha_planificacion_edit_todas_submit * Guardar la informacion de modificar todas las fechas de planificacion */ function ente_planificador_fecha_planificacion_edit_todas_submit($form, &$form_state){ $procesos = ente_planificador_procesos(); foreach ($procesos as $type_url_str => $proceso) { $fi = mktime( 0, 0, 0, $form_state['values'][$type_url_str . '_from']['month'], $form_state['values'][$type_url_str . '_from']['day'], $form_state['values'][$type_url_str . '_from']['year'] ); $ff = mktime( 0, 0, 0, $form_state['values'][$type_url_str . '_until']['month'], $form_state['values'][$type_url_str . '_until']['day'], $form_state['values'][$type_url_str . '_until']['year'] ); variable_set('ente_planificador_' . $type_url_str . '_from', $fi); variable_set('ente_planificador_' . $type_url_str . '_until', $ff); } drupal_set_message(t('Se han guardado los cambios')); } /* * Implementation of hook_cron() */ function ente_planificador_cron() { $procesos_cron = array(); $now = time(); $procesos = ente_planificador_procesos(); $cuerpoMi = t("Fechas de Planificación") . "\n"; foreach ($procesos as $type_url_str => $name) { $FIPMC = variable_get('ente_planificador_' . $type_url_str . "_cron", 0); $FIPMI = variable_get('ente_planificador_' . $type_url_str . "_from", 0); $FIPMF = variable_get('ente_planificador_' . $type_url_str . "_until", 0); if ($FIPMI) { $FIPMI = format_date($FIPMI); } else { $FIPMI = t("N/A"); } if ($FIPMF) { $FIPMF = format_date($FIPMF); } else { $FIPMF = t("N/A"); } $cuerpoMi .= ' ' . t(check_plain($name)) . " : " . t("Fecha de Inicio: ") . $FIPMI . t("Fecha de Culminación: ") . $FFPMF . "\n"; if ($FIPMC +3600 < $now && $FIPMC > now) { $procesos_cron[] = $type_url_str; } } if (!count($procesos_cron)) { return; } $default_from = variable_get('site_mail', ini_get('sendmail_from')); $emails = array(); $plan = array(); $result = db_query("select u.mail, e.nid from {users} u, {ente_user_planificador} e where e.usuario = u.uid AND status > 1"); while($usuarios = db_fetch_object($result)) { $emails[$usuarios->nid][] = $usuarios->email; } foreach($emails as $id => $value) { $planificacion = ente_planificador_obtiene_resumen_planificacion($id); if ($planificacion['total'] >= 100) { unset($emails[$id]); } else { $plan[$id] = $planificacion['total']; } } $cuerpo = t( 'Estimado usuario le recordamos que la fecha de planificación para los procesos (@procesos) se encuentra llegando a su fin', array( '@procesos' => implode(',', $procesos_cron) ) ) . "\n"; foreach($emails as $id => $value) { $text_emails = implode(',', $value); $cuerpo1 = t('Su ente ha alcanzado hasta la fecha un porcentaje de avance de @avance %', array('@avance' => $plan[$id])) . "\n"; $cuerpoF = $cuerpo . $cuerpo1 . $cuerpoMi; $message = array( 'to' => $text_emails, 'subject' => t('Fechas de Planificación'), 'body' => $cuerpo1, 'headers' => array('From' => $default_from), ); drupal_mail_send($message); } drupal_set_message(t("Se han enviado los correo")); } /* * ente_planificador_fecha_planificacion_correo * Enviar correo electronico de las fechas de planificacion */ function ente_planificador_fecha_planificacion_correo() { $result = db_query("select u.mail from {users} u, {ente_user_planificador} e where e.usuario = u.uid AND status > 0"); $emails = array(); while($usuarios = db_fetch_object($result)) { $emails[] = $usuarios->mail; } if (!count($emails)) { drupal_goto('fechas_planificacion'); return; } $text_emails = implode(',',$emails); $default_from = variable_get('site_mail', ini_get('sendmail_from')); $cuerpo = t('Estimado usuario a continuación le enviamos las fechas de Inicio y culminación de las distintas etapas de planificación') . "\n"; $cuerpoMi = t("Fechas de Planificación") . "\n"; $procesos = ente_planificador_procesos(); $procesos_status = ente_planificador_procesos('status'); $procesos = ente_planificador_procesos(); $procesos_ordenados = ente_planificador_ordena_procesos($procesos_status, $procesos); $i = 0; $procesos = $procesos_ordenados['normal']; $procesos_status = $procesos_ordenados['status']; if (is_array($procesos_status) && count($procesos_status)) { foreach($procesos_status as $id => $valores) { $cuerpoMi .= t('Etapa') . ' ' . check_plain($valores['title']) . "\n"; if (is_array($procesos[$id]) && count($procesos[$id])) { foreach ($procesos[$id] as $type_url_str => $proceso) { $FIPMI = variable_get('ente_planificador_' . $type_url_str . "_from", 0); $FIPMF = variable_get('ente_planificador_' . $type_url_str . "_until", 0); if ($FIPMI) { $FIPMI = format_date($FIPMI); } else { $FIPMI = t("N/A"); } if ($FIPMF) { $FIPMF = format_date($FIPMF); } else { $FIPMF = t("N/A"); } $cuerpoMi .= ' ' . t(check_plain($proceso['title'])) . " : " . t("Fecha de Inicio: ") . $FIPMI . t("Fecha de Culminación: ") . $FIPMF . "\n"; } } } } $cuerpo .= $cuerpoMi; $message = array( 'to' => $text_emails, 'subject' => t('Fechas de Planificación'), 'body' => $cuerpo, 'headers' => array('From' => $default_from), ); drupal_mail_send($message); drupal_set_message(t("Se ha enviado el correo: !usuarios_emails", array('!usuarios_emails' => theme('item_list', $emails)))); drupal_goto('fechas_planificacion'); } /* * ente_planificador_fecha_planificacion_edit * Editar una fecha de planificacion */ function ente_planificador_fecha_planificacion_edit($type_node = '') { $procesos = ente_planificador_procesos(); if (isset($procesos[$type_node])) { return drupal_get_form('ente_planificador_fecha_planificacion_edit_form', $type_node); } return NULL; } /* * ente_planificador_fecha_planificacion_edit_form * Editar una fecha de planificacion */ function ente_planificador_fecha_planificacion_edit_form($form_state, $type_node = NULL) { $procesos = ente_planificador_procesos(); $tipos_fecha = array( 'from' => t('Inicio'), 'until' => t('Fin'), ); $FIPMI = variable_get('ente_planificador_' . $type_node . "_from", 0); $f1 = explode("-", gmdate("Y-m-d", $FIPMI)); settype($f1[0], "integer"); settype($f1[1], "integer"); settype($f1[2], "integer"); $FIPMF = variable_get('ente_planificador_' . $type_node . "_until", 0); $f2 = explode("-", gmdate("Y-m-d", $FIPMF)); settype($f2[0], "integer"); settype($f2[1], "integer"); settype($f2[2], "integer"); $form = array(); $form['type_page_node'] = array( '#type' => 'hidden', '#default_value' => $type_node, ); $form['from'] = array( '#type' => 'date', '#title' => t('Modificar la fecha de inicio para %name', array('%name' => $procesos[$type_node]['title'])), '#default_value' => array( 'day' => $f1[2], 'month' => $f1[1], 'year' => $f1[0], ), '#description' => t('Seleccione la fecha'), ); $form['until'] = array( '#type' => 'date', '#title' => t('Modificar la fecha de culminación para %name', array('%name' => $procesos[$type_node]['title'])), '#default_value' => array( 'day' => $f2[2], 'month' => $f2[1], 'year' => $f2[0], ), '#description' => t('Seleccione la fecha'), ); $form['submit'] = array( '#type' => 'submit', '#default_value' => t("Guardar"), ); $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_form_validate * Validar una fecha de planificacion */ function ente_planificador_fecha_planificacion_edit_form_validate($form, &$form_state) { $key = $form_state['values']['type_page_node']; $procesos = ente_planificador_procesos(); if (isset($procesos[$key])) { $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']); if ($ff <= $fi) { form_set_error('until', t('La fecha de culminación para %name debe ser mayor a la fecha de inicio @ff @fi', array('%name' => $procesos[$key], '@ff' => format_date($ff), '@fi' => format_date($fi), ))); } } else { form_set_error('until', t('La fecha final para %name debe ser mayor a la inicial @ff @fi', array('%name' => $name, '@ff' => format_date($ff), '@fi' => format_date($fi), ))); drupal_set_message(t("Ocurrio un error al intentar almacenar la fecha")); drupal_goto('fechas_planificacion'); } } /* * ente_planificador_fecha_planificacion_edit_form_submit * Guardar una fecha de planificacion */ function ente_planificador_fecha_planificacion_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'] ); $key = $form_state['values']['type_page_node']; $procesos = ente_planificador_procesos(); variable_set('ente_planificador_' . $key . '_from', $fi); variable_set('ente_planificador_' . $key . '_until', $ff); drupal_set_message(t("Actualizadas las fechas para %name", array('%name' => $procesos[$key]['title']))); drupal_goto('fechas_planificacion'); } /* * Implementation of ente_planificador_procesos() * Lista los procesos de la planificacion */ function ente_planificador_procesos($type = 'normal') { $procesos = array(); drupal_alter('ente_procesos', $procesos, $type); return $procesos; } /* * Implementation of ente_planificador_ordena_procesos() * Ordena los procesos por pesos(weight) */ function ente_planificador_ordena_procesos($procesos_status, $procesos) { $nuevo_proceso = array(); $reemplazo = array(); //se añade cada uno de los procesos a su categoría con su peso if (is_array($procesos) && count($procesos)) { foreach($procesos as $id => $arreglo) { $nuevo_proceso[$arreglo['proceso']][$arreglo['weight']][$id] = $arreglo; } foreach($nuevo_proceso as $id => $arreglo) { ksort($nuevo_proceso[$id]); } foreach($nuevo_proceso as $id => $valores) { foreach($valores as $valor) { foreach ($valor as $ids => $proceso) { $reemplazo[$id][$ids] = $proceso; } } } } $nuevo_proceso = $reemplazo; $indices = array(); $reemplazo = array(); if (is_array($procesos_status) && count($procesos_status)) { foreach($procesos_status as $id => $arreglo) { $indices[$arreglo['weight']][] = $id; } ksort($indices); foreach($indices as $weight => $valores) { foreach($valores as $valor) { $reemplazo[$valor] = $procesos_status[$valor]; } } } $procesos_status = $reemplazo; return array( 'normal' => $nuevo_proceso, 'status' => $procesos_status, ); } /* * ente_planificador_fecha_planificacion * Mostrar las fechas de planificacion */ function ente_planificador_fecha_planificacion($type = '') { $view = FALSE; if (user_access('admin planificador')) { $view = TRUE; } $header[] = array('data' => t('Name')); $header[] = array('data' => t('Fecha de Inicio')); $header[] = array('data' => t('Fecha de Culminación')); if ($view) { $header[] = array('data' => t('Operació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(); $fechas_agregar = TRUE; if (is_array($procesos_status) && count($procesos_status)) { foreach($procesos_status as $id => $valores) { $row = array(); $row[] = array('data' => '' . $procesos_status[$id]['title'] . '', 'colspan' => 4, 'align' => 'center'); $rows[] = $row; if (is_array($nuevo_proceso[$id]) && count($nuevo_proceso[$id])) { foreach ($nuevo_proceso[$id] as $type_url_str => $proceso) { $FIPMI = variable_get('ente_planificador_' . $type_url_str . "_from", 0); $FIPMF = variable_get('ente_planificador_' . $type_url_str . "_until", 0); if ($view) { if ($FIPMI) { $fechas_agregar = FALSE; $FIPMI = format_date($FIPMI); } else { $FIPMI = t("N/A"); } if ($FIPMF) { $fechas_agregar = FALSE; $FIPMF = format_date($FIPMF); } else { $FIPMF = t("N/A"); } } else { if ($FIPMI) { $fechas_agregar = FALSE; $FIPMI = format_date($FIPMI); } else { $FIPMI = t("N/A"); } if ($FIPMF) { $fechas_agregar = FALSE; $FIPMF = format_date($FIPMF); } else { $FIPMF = t("N/A"); } } $row = array(); $row[] = array('data' => t(check_plain($proceso['title'])), ); $row[] = array('data' => $FIPMI, ); $row[] = array('data' => $FIPMF, ); if ($view) { $row[] = array('data' => l(t('Modificar'), 'fechas_planificacion/edit/' . $type_url_str), ); } $rows[] = $row; } } } } $fechas_display = TRUE; if (!count($rows)) { $row = array(); $row[] = array('data' => t('No se encontrarón fechas para planificar'), 'colspan' => 4); $rows[] = $row; $fechas_display = FALSE; } $aux = ""; if (user_access('admin planificador') && $fechas_display) { if ($fechas_agregar) { $aux = l(t("Agregar las fechas para los procesos de planificación."), 'fechas_planificacion/todas_edit'); } $aux .= '
' . l(t("Enviar Correo Electrónico a los entes planificadores"), 'fechas_planificacion/envia_email'); $aux .= '
' . l(t("Fecha para reportar mensaje de alerta respecto al registro o modificación de información"), 'fechas_planificacion/notificacion'); } return theme('table', $header, $rows).$aux; } /* * ente_planificador_admin_settings * Configurar entes planificadores */ function ente_planificador_admin_settings() { $form = array(); $roles = user_roles(TRUE); unset($roles[2]); if (count($roles)) { $form['ActorPlanificadorMacro'] = array( '#type' => 'select', '#title' => t('Rol para el Actor estratégico-táctico'), '#default_value' => variable_get('ActorPlanificadorMacro', 2), '#options' => $roles, '#description' => t('Seleccione el rol para el Actor estratégico-táctico'), ); $form['ActorPlanificadorMicro'] = array( '#type' => 'select', '#title' => t('Rol para el Actor operativo'), '#default_value' => variable_get('ActorPlanificadorMicro', 2), '#options' => $roles, '#description' => t('Seleccione el rol para el Actor operativo'), ); return system_settings_form($form); } } /* * entes_planificadores_listar_usuarios * Listar todos los usuarios asociados a entes planificadores */ function entes_planificadores_listar_usuarios() { global $user; $step = 10; $output = ''; $ente = NULL; $Lista_entes = array(); $sqlcount = "select count(u.uid) from {users} u, {ente_user_planificador} up, {node} n where u.uid = up.usuario and up.nid =n.nid"; $sql = "select n.title, n.nid, u.name, u.nombres, u.apellidos, u.cedula, u.uid from {users} u, {ente_user_planificador} up, {node} n where u.uid = up.usuario and up.nid =n.nid"; $headers_table[] = array('data' => t('Nombre de Usuario'), 'sort' => 'asc', 'field' => 'u.name'); $headers_table[] = array('data' => t('Nombres'), 'sort' => 'asc', 'field' => 'u.nombres'); $headers_table[] = array('data' => t('Apellidos'), 'sort' => 'asc', 'field' => 'u.apellidos'); $headers_table[] = array('data' => t('Cédula de Identidad'), 'sort' => 'asc', 'field' => 'u.cedula'); $headers_table[] = array('data' => t('Ente Planificador'), 'sort' => 'asc', 'field' => 'n.title'); $headers_table[] = array('data' => t('Consultar')); $headers_table[] = array('data' => t('Modificar')); $headers_table[] = array('data' => t('Eliminar')); $sql.= tablesort_sql($headers_table); $result = pager_query($sql, $step, 0, $sqlcount,$user->uid); while($ente = db_fetch_object($result)) { $Lista_entes[] = array( 'name'=>l($ente->name, 'user/' . $ente->uid, array('html' => true, 'query' => 'destination=administrar_usuarios')), 'nombres' => l($ente->nombres, 'user/' . $ente->uid, array('html' => true, 'query' => 'destination=administrar_usuarios')), 'apellidos' => l($ente->apellidos, 'user/' . $ente->uid, array('html' => true, 'query' => 'destination=administrar_usuarios')), 'cedula'=>l($ente->cedula, 'user/' . $ente->uid, array('html' => true, 'query' => 'destination=administrar_usuarios')), 'ente' => l($ente->title, 'node/' . $ente->nid, array('html' => true, 'query' => 'destination=administrar_usuarios')), 'consultar' => l(t("Consultar"), 'user/' . $ente->uid, array('html' => true, 'query' => 'destination=administrar_usuarios')), 'modificar' => l(t("Modificar"), 'user/' . $ente->uid . "/edit", array('html' => true, 'query' => 'destination=administrar_usuarios')), 'eliminar' => l(t("Eliminar"), 'user/' . $ente->uid . "/delete", array('html' => true, 'query' => 'destination=administrar_usuarios')), ); } if (sizeof($Lista_entes)) { $output.= theme('table', $headers_table, $Lista_entes); $output .= theme('pager', NULL); } else { $output.= '

' . t('No se encontraron usuarios en el sistema') . '

'; } return $output; } /* * mis_entes_planificadores * Listar todos los entes planificadores asociados al usuario actual */ function mis_entes_planificadores() { global $user; $step = 10; $output = ''; $ente = usuario_tiene_ente($user->uid); if ($ente->nid) { $ente = ente_planificador_leer($ente->nid); $output .= node_view($ente); $estados = ente_planificador_status_planificacion($ente->nid, $ente->tipo); $header = array(); $header[] = array('data' => t('Etapa')); $header[] = array('data' => t('Estado')); $rows = array(); $total_suma = 0; $total_ejecutado = 0; if (count($estados)) { foreach($estados as $estado) { $row = array(); $row[] = array( 'data' => '' . $estado['title'] . '', 'colspan' => '2', 'align' => 'center' ); $rows[] = $row; $porc = 0; $etapas = count($estado['value']); if ($etapas) { $suma = 0; foreach($estado['value'] as $value) { $total_suma++; $row = array(); $valor = $value['value'] ? t('Si') : t('No'); $row[] = array('data' => l($value['title'], $value['link']),); $row[] = array('data' => $valor,); $rows[] = $row; if ($value['value']) { $suma++; } } $total_ejecutado += $suma; $porc = ($suma * 100) / $etapas; } $row = array(); $row[] = array( 'data' => '' . t('Porcentaje') . '', 'align' => 'right', ); $row[] = array( 'data' => '' . round($porc, 2) . ' %' . '', ); $rows[] = $row; } $total_porcentaje = ($total_suma > 0) ? ($total_ejecutado * 100) / $total_suma : 0; $row = array(); $row[] = array( 'data' => '' . t('Porcentaje Total : ') . round($total_porcentaje, 2) . ' %', 'colspan' => '2', 'align' => 'center', ); $rows[] = $row; } if (!count($rows)) { $row = array(); $row[] = array( 'data' => t('No se ha podido calcular el estado de planificación del ente: @ente', array( '@ente' => $ente_planificador->title ) ), 'colspan' => '2', 'align' => 'center' ); $rows[] = $row; } } $output .= theme('table', $header, $rows); $ente = NULL; $Lista_entes = array(); $sqlcount = "SELECT count(u1.nid) FROM {node} n, {ente_user_planificador} u1 WHERE u1.usuario = %d AND u1.nid = n.nid"; $sql = "SELECT n.title, n.nid FROM {node} n, {ente_user_planificador} u1 WHERE u1.usuario = %d AND u1.nid = n.nid"; $headers_table[] = array( 'data' => t('Ente Planificador'), 'sort' => 'asc', 'field' => 'n.title' ); $headers_table[] = array( 'data' => t('Consultar') ); $headers_table[] = array( 'data' => t('Modificar') ); $sql.= tablesort_sql($headers_table); $result = pager_query($sql, $step, 0, $sqlcount,$user->uid); while($ente = db_fetch_object($result)) { $Lista_entes[] = array( 'ente' => l($ente->title, 'node/' . $ente->nid, array('html' => true, 'query' => 'destination=mienteplanificador')), 'consultar' => l(t("Consultar"), 'node/' . $ente->nid, array('html' => true, 'query' => 'destination=mienteplanificador')), 'modificar' => l(t("Modificar"), 'node/edit/' . $ente->nid, array('html' => true, 'query' => 'destination=mienteplanificador')), ); } if (sizeof($Lista_entes)) { $output.= theme('table', $headers_table, $Lista_entes); $output .= theme('pager', NULL); } else { $output.= '

' . t('No se encontraron entes asignados al usuario') . '

'; } return $output; } /* * entes_planificadores_agregar * Agregar un ente planificador */ function entes_planificadores_agregar() { drupal_goto('node/add/ente-planificador' , 'destination=administrar/entes_planificadores'); } /* * entes_planificadores_obtener_filtros * Generar filtros */ function entes_planificadores_obtener_filtros($filtro = array()) { $filters['nombre'] = array( '#type' => 'textfield', '#title' => t('Nombre'), '#size' => 20, ); $filters['razon_social'] = array( '#type' => 'textfield', '#title' => t('Razón Social'), '#size' => 20, ); $filters['rif'] = array( '#type' => 'textfield', '#title' => t('RIF'), '#size' => 20, '#maxlength' => 12, ); $filters['direccion'] = array( '#type' => 'textfield', '#title' => t('Dirección'), '#size' => 20, '#maxlength' => 243, ); $filters['ciudad'] = array( '#type' => 'textfield', '#title' => t('Ciudad'), '#size' => 20, '#maxlength' => 243, ); //Se buscan las entidades $entidades = ente_planificador_obtener_lista_entidad(); $estado = "01"; if ($filtro['estado']) { $estado = $filtro['estado']; } $filters['estado'] = array( '#type' => 'select', '#title' => t('Estado').$form['estado'], '#options' => $entidades, '#ahah' => array( 'event' => 'change', 'path' => 'ente_planificador_js_util/municipio_select', 'wrapper' => 'edit-municipio-wrapper', 'method' => 'replace', ), ); $municipio = $filtro['municipio']; $parroquia = $filtro['parroquia']; $filters['municipio'] = ente_planificador_obtener_form_municipio( t('Municipio'), $municipio, t('seleccione el municipio.'), $estado, $display = 'name', TRUE ); $filters['parroquia'] = ente_planificador_obtener_form_parroquia(t('Parroquia'), $parroquia, t('seleccione la parroquia.'), $municipio, TRUE); $filters['municipio']['#required'] = FALSE; $filters['parroquia']['#required'] = FALSE; //Se buscan las actividades $actividades = ente_planificador_obtener_actividades(); $filters['actividad'] = array( '#type' => 'select', '#title' => t('Actividades'), '#default_value' => $ente_planificador->actividad, '#options' => $actividades, '#description' => t('Seleccione una actividad.'), ); return $filters; } /* * ente_planificador_datos_basicos * Obtener formulario de los datos basicos */ function ente_planificador_datos_basicos($nid = '') { $output = ''; $output .= drupal_get_form('ente_planificador_datos_basicos_forma', $nid); return $output; } /* * ente_planificador_datos_basicos_forma * Obtener formulario de los datos basicos */ function ente_planificador_datos_basicos_forma(&$form_state, $nid = NULL) { $ente_planificador = NULL; if (is_numeric($nid)) { $ente_planificador = ente_planificador_leer_ente_planificadores($nid); } $form = array(); if ($ente_planificador) { $form['ente_planificador_nid'] = array( '#type' => 'hidden', '#default_value' => $ente_planificador->nid, ); $form['razon_social'] = array( '#type' => 'textfield', '#title' => t('Razón Social'), '#default_value' => $ente_planificador->razon_social, '#size' => 20, '#description' => t("Introduzca la Razón Social"), '#required' => TRUE, ); $form['rif'] = array( '#type' => 'textfield', '#title' => t('RIF'), '#default_value' => $ente_planificador->rif, '#size' => 20, '#maxlength' => 12, '#description' => t("Introduzca el RIF"), '#required' => TRUE, ); $form['direccion'] = array( '#type' => 'textfield', '#title' => t('Dirección'), '#default_value' => $ente_planificador->direccion, '#size' => 20, '#maxlength' => 243, '#description' => t("Introduzca la dirección"), '#required' => TRUE, ); $form['ciudad'] = array( '#type' => 'textfield', '#title' => t('Ciudad'), '#default_value' => $ente_planificador->ciudad, '#size' => 20, '#maxlength' => 243, '#description' => t("Introduzca la ciudad"), '#required' => TRUE, ); //Se buscan las entidades $entidades = ente_planificador_obtener_lista_entidad(); if ($ente_planificador->estado) { $estado = $ente_planificador->estado; } else { $estado = '01'; } $form['estado'] = array( '#type' => 'select', '#title' => t('Estado').$form['estado'], '#default_value' => $estado, '#options' => $entidades, '#description' => t('seleccione el estado.'), '#required' => TRUE, '#ahah' => array( 'event' => 'change', 'path' => 'ente_planificador_js_util/municipio_select', 'wrapper' => 'edit-municipio-wrapper', 'method' => 'replace', ), ); if (!$ente_planificador->municipio) { $municipio = '0101'; } else { $municipio = $ente_planificador->municipio; } $form['municipio'] = ente_planificador_obtener_form_municipio(t('Municipio'), $ente_planificador->municipio, t('seleccione el municipio.'), $estado, $display = 'name', TRUE); $form['parroquia'] = ente_planificador_obtener_form_parroquia(t('Parroquia'), $ente_planificador->parroquia, t('seleccione la parroquia.'), $ente_planificador->municipio, name, TRUE); $node_type = content_types('ente_planificador'); $fields = $node_type['fields']; $field_form = array(); if (is_array($fields) && count($fields)) { foreach($fields as $field_id => $field) { if (variable_get('ente_planificador_' . $field_id, FALSE)) { $field_form[] = $field_id; } } } $form['#ente_planificador_fields_datos'] = $field_form; if (is_array($field_form) && count($field_form)) { module_load_include('inc', 'content', 'includes/content.node_form'); $form['#node'] = $ente_planificador; foreach ($field_form as $field_id) { $field = content_fields($field_id, 'ente_planificador'); $form['#field_info'][$field_id] = $field; $form += (array) content_field_form($form, $form_state, $field); } } //Se buscan las actividades $actividades = ente_planificador_obtener_actividades(); $form['actividad'] = array( '#type' => 'select', '#title' => t('Actividades'), '#default_value' => $ente_planificador->actividad, '#options' => $actividades, '#description' => t('Seleccione una actividad.'), '#multiple' => TRUE, '#required' => TRUE, ); //add taxonomy if exist if (module_exists('taxonomy')) { if (!isset($ente_planificador->taxonomy)) { $terms = empty($ente_planificador->nid) ? array() : taxonomy_node_get_terms($ente_planificador); } else { // After a preview or form reload, the terms must be converted to objects. reset($ente_planificador->taxonomy); if (!is_object(current($ente_planificador->taxonomy))) { $ente_planificador->taxonomy = taxonomy_preview_terms($ente_planificador); } $terms = $ente_planificador->taxonomy; } $c = db_query(db_rewrite_sql("SELECT v.* FROM {vocabulary} v INNER JOIN {vocabulary_node_types} n ON v.vid = n.vid WHERE n.type = '%s' ORDER BY v.weight, v.name", 'v', 'vid'), $ente_planificador->type); while ($vocabulary = db_fetch_object($c)) { if ($vocabulary->tags) { if (isset($form_state['node_preview'])) { // Typed string can be changed by the user before preview, // so we just insert the tags directly as provided in the form. $typed_string = $ente_planificador->taxonomy['tags'][$vocabulary->vid]; } else { $typed_string = taxonomy_implode_tags($terms, $vocabulary->vid) . (array_key_exists('tags', $terms) ? $terms['tags'][$vocabulary->vid] : NULL); } if ($vocabulary->help) { $help = filter_xss_admin($vocabulary->help); } else { $help = t('A comma-separated list of terms describing this content. Example: funny, bungee jumping, "Company, Inc.".'); } $form['taxonomy']['tags'][$vocabulary->vid] = array('#type' => 'textfield', '#title' => $vocabulary->name, '#description' => $help, '#required' => $vocabulary->required, '#default_value' => $typed_string, '#autocomplete_path' => 'taxonomy/autocomplete/'. $vocabulary->vid, '#weight' => $vocabulary->weight, '#maxlength' => 1024, ); } else { // Extract terms belonging to the vocabulary in question. $default_terms = array(); foreach ($terms as $term) { // Free tagging has no default terms and also no vid after preview. if (isset($term->vid) && $term->vid == $vocabulary->vid) { $default_terms[$term->tid] = $term; } } $form['taxonomy'][$vocabulary->vid] = taxonomy_form($vocabulary->vid, array_keys($default_terms), filter_xss_admin($vocabulary->help)); $form['taxonomy'][$vocabulary->vid]['#weight'] = $vocabulary->weight; $form['taxonomy'][$vocabulary->vid]['#required'] = $vocabulary->required; } } if (!empty($form['taxonomy']) && is_array($form['taxonomy'])) { if (count($form['taxonomy']) > 1) { // Add fieldset only if form has more than 1 element. $form['taxonomy'] += array( '#type' => 'fieldset', '#title' => t('Vocabularies'), '#collapsible' => TRUE, '#collapsed' => FALSE, ); } $form['taxonomy']['#weight'] = 8; $form['taxonomy']['#tree'] = TRUE; } } $form['buttons']['#weight'] = 100; $form['buttons']['submit'] = array( '#type' => 'submit', '#default_value' => t("Agregar los datos basicos del ente"), '#weight' => 100, ); } if ($ente_planificador) { $enlace = base_path() . 'node/' . $ente_planificador->nid; } else { $enlace = base_path() . 'administrar/entes_planificadores'; } return $form; } /* * ente_planificador_datos_basicos_forma * Validar formulario de los datos basicos */ function ente_planificador_datos_basicos_forma_validate($form, &$form_state) { $form_values = $form_state['values']; if (!preg_match("/^(V|E|P|J|G){1}-([0-9]){8}-([0-9]){1}$/",$form_values['rif']) && !preg_match("/^(V|E){1}-([0-9]){8}$/",$form_values['rif'])) { form_set_error('rif', t('El formato del rif debe tener el siguiente formato G-00000000-0.')); } if (!($form_values['municipio'] > 0)) { form_set_error('municipio', t('Debe seleccionar un municipio.')); } if (!($form_values['parroquia'] > 0)) { form_set_error('parroquia', t('Debe seleccionar una parroquia.')); } } /* * ente_planificador_datos_basicos_forma_submit * Guardar formulario de los datos basicos */ function ente_planificador_datos_basicos_forma_submit($form, &$form_state) { $form_values = $form_state['values']; $resultado1 =db_query("select nid from {ente_planificador} where nid = %d", $form_values['ente_planificador_nid']); $entes = db_fetch_object($resultado1); if ($entes->nid) { $result = db_query("update {ente_planificador} set razon_social = '%s', rif = '%s', direccion = '%s', estado = %d, municipio = %d, parroquia = %d, ciudad = '%s' where nid = %d", check_plain($form_values['razon_social']), check_plain($form_values['rif']), check_plain($form_values['direccion']), $form_values['estado'], $form_values['municipio'], $form_values['parroquia'], check_plain($form_values['ciudad']), $form_values['ente_planificador_nid']); } else { $result = db_query("INSERT INTO {ente_planificador} (nid, razon_social, rif, direccion, estado, municipio, parroquia, ciudad) VALUES (%d,'%s', '%s', '%s', %d, %d, %d, '%s', '%s')", $form_values['ente_planificador_nid'], check_plain($form_values['razon_social']), check_plain($form_values['rif']), check_plain($form_values['direccion']), $form_values['estado'], $form_values['municipio'], $form_values['parroquia'], check_plain($form_values['ciudad'])); } $result = db_query("delete from {ente_actividad_ente} where nid = %d", $form_values['ente_planificador_nid']); $cant = count($form_values['actividad']); if ($cant) { foreach ($form_values['actividad'] as $actividad) { if ($actividad) { db_query("insert into {ente_actividad_ente} (nid, actividad) values (%d, %d)", $form_values['ente_planificador_nid'], $actividad); } } } //add extra cck fields $field_form = $form['#ente_planificador_fields_datos']; module_load_include('inc', 'node', 'node.pages'); node_object_prepare($node_load); $node_load = ente_planificador_leer_ente_planificadores($form_values['ente_planificador_nid']); if (isset($form_state['values']['taxonomy'])) { $node_load->taxonomy = $form_state['values']['taxonomy']; } if (is_array($field_form) && count($field_form)) { foreach ($field_form as $field_id) { if (isset($form_state['values'][$field_id]) && is_array($form_state['values'][$field_id])) { foreach($form_state['values'][$field_id] as $id => $value) { if (is_numeric($id) && isset($form_state['values'][$field_id][$id]['_error_element'])) { unset($form_state['values'][$field_id][$id]['_error_element']); } } $node_load->{$field_id} = $form_state['values'][$field_id]; } } } $node_load->log = t('Modificados los datos del actor planificador'); $node_load->revision = 1; node_save($node_load); drupal_set_message(t("Se agrego la información de datos basicos")); drupal_goto('node/' . $form_values['ente_planificador_nid']); } /* * nodo_es_ente_planificador * identifica si el nodo es ente planificador */ function nodo_es_ente_planificador($nid = 0) { global $user; if ((user_access('edit all planificador')) || (user_access('admin planificador')) || (user_access('edit own planificador'))) { if (is_numeric($nid)) { $ente_planificador = ente_planificador_leer_ente_planificadores($nid); if ($ente_planificador->type == "ente_planificador") { if ((user_access('edit all planificador')) || (user_access('admin planificador'))) { return TRUE; } if ((user_access('edit own planificador'))) { if (!$ente_planificador->usuarios[$user->uid]) { return FALSE; } } return TRUE; } } } return FALSE; } /* * entes_planificadores * Listar entes planificador */ function entes_planificadores() { $output = ''; $step = 10; $sqlcount = "SELECT count(n.nid) from {node} n, {node_revisions} rv where n.vid = rv.vid AND (n.type in ('ente_planificador')) AND (n.status <> 0)"; $sql = "SELECT n.nid as nid, n.title as title from {node} n, {node_revisions} rv where n.vid = rv.vid AND (n.type in ('ente_planificador')) AND (n.status <> 0)"; $headers_table[] = array('data' => t('Ente Planificador'), 'sort' => 'asc', 'field' => 'n.title'); if ((user_access('edit all planificador'))||(user_access('admin planificador'))) { $headers_table[] = array('data' => t('Usuarios')); $headers_table[] = array('data' => t('Modificar')); $headers_table[] = array('data' => t('Datos Basicos')); $headers_table[] = array('data' => t('eliminar')); } $sql.= tablesort_sql($headers_table); $result = pager_query($sql, $step, 0, $sqlcount); while($entes = db_fetch_object($result)) { $arregloente['title'] = l($entes->title, 'node/' . $entes->nid); if ((user_access('edit all planificador')) || (user_access('admin planificador'))) { $arregloente['usuarios'] = l(t('Agregar usuarios al actor planificador'), 'admin/user/user/create/' . $entes->nid); $arregloente['editar'] = l(t('Modificar'), 'node/' . $entes->nid.'/edit', array('html' => true, 'query' => 'destination=administrar/entes_planificadores')); $arregloente['datos_basicos'] = l(t('Editar datos del actor planificador'), 'node/' . $entes->nid . '/datos_basicos', array('html' => true, 'query' => 'destination=administrar/entes_planificadores')); $arregloente['eliminar'] = l(t('Eliminar'), 'node/' . $entes->nid.'/delete', array('html' => true, 'query' => 'destination=administrar/entes_planificadores')); } $Lista_entes[] = $arregloente; unset($arregloente); } if (sizeof($Lista_entes)) { $output.= theme('table', $headers_table, $Lista_entes); $output .= theme('pager', NULL); } else { $output.= '

' . t('No se encontraron entes planificadores registrados en el sistema') . '

'; } return $output; } /* * ente_planificador_js_util * Genera las repuestas ajax de municipios y parroquias */ function ente_planificador_js_util($func) { switch ($func) { case 'municipio_select': $entidad_id = intval($_POST['estado']) > 0 ? intval($_POST['estado']) : 0; if ($entidad_id<10) { $entidad_id = "0" . $entidad_id; } $title = isset($_POST['title']) ? check_plain($_POST['title']) : NULL; $display = isset($_POST['display']) ? check_plain($_POST['display']) : 'name'; $select = ente_planificador_obtener_form_municipio(t('Municipio'), NULL, t('seleccione el municipio.'), $entidad_id, 'name', TRUE); $output = ahah_render($select, 'municipio'); print drupal_to_js(array('data' => $output, 'status' => true)); exit(); break; case 'parroquia_select': $muncipio_id = intval($_POST['municipio']) > 0 ? intval($_POST['municipio']) : 0; if ($muncipio_id<1000) { $muncipio_id = "0" . $muncipio_id; } $title = isset($_POST['title']) ? check_plain($_POST['title']) : NULL; $display = isset($_POST['display']) ? check_plain($_POST['display']) : 'name'; $select = ente_planificador_obtener_form_parroquia(t('Parroquia'), NULL, t('seleccione la parroquia.'), $muncipio_id, 'name', TRUE); $output = ahah_render($select, 'parroquia'); print drupal_to_js(array('data' => $output, 'status' => true)); exit(); } print $output; exit(); } /** * ahah_render... */ function ahah_render($fields, $name) { $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); $form[$name] = $fields; 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[$name]; return drupal_render($new_form); } /* * usuario_tiene_ente * retorna los entes que tiene un usuario */ function usuario_tiene_ente($uid) { $ente = db_fetch_object(db_query("SELECT n.title, n.nid FROM {node} n, {ente_user_planificador} u1 WHERE u1.usuario = %d AND u1.nid = n.nid", $uid)); return $ente; } /* * Implementation of hook_perm */ function ente_planificador_perm() { return array( 'ver planificador', 'edit own planificador', 'edit all planificador', 'admin planificador', 'admin all planificador', ); } /* * Implementation of hook_node_info */ function ente_planificador_node_info() { return array( 'ente_planificador' => array( 'name' => t('Ente Planificador'), 'description' => t('Ente Planificador'), 'has_body' => FALSE, 'has_title' => TRUE, 'module' => 'ente_planificador', ), ); } /* * Implementation of hook_node_load */ function ente_planificador_load($node) { $additions = db_fetch_object(db_query('SELECT * FROM {ente_planificador} WHERE nid = %d', $node->nid)); //se obtienen los usuarios del ente planificador if ($additions->estado && $additions->estado < 10) { $additions->estado = '0' . $additions->estado; } if ($additions->municipio && $additions->municipio < 1000) { $additions->municipio = '0' . $additions->municipio; } if ($additions->parroquia && $additions->parroquia < 100000) { $additions->parroquia = '0' . $additions->parroquia; } $array_usuario = array(); $additions1 = db_query('SELECT p.usuario, u.mail FROM {ente_user_planificador} p, {users} u WHERE nid = %d and p.usuario = u.uid', $node->nid); while ($usuarios = db_fetch_object($additions1)) { $array_usuario[$usuarios->usuario] = $usuarios->mail; } $array_actividades = array(); $additions1 = db_query('SELECT actividad FROM {ente_actividad_ente} WHERE nid = %d', $node->nid); while ($actividad = db_fetch_object($additions1)) { $array_actividades[] = $actividad->actividad; } $additions->usuarios = $array_usuario; $additions->actividad = $array_actividades; return $additions; } /* * Implementation of hook_form */ function ente_planificador_form(&$node, $form_state) { $form = array(); $form['title'] = array( '#type' => 'textfield', '#title' => t('Nombre del ente planificador'), '#default_value' => $node->title, '#size' => 20, '#description' => t("Introduzca el nombre del ente planificador"), '#required' => TRUE, ); $tipos_entes = entes_planificadores_obtiene_tipos(); //SOLO DEJE A UN ENTE SER ENTE PLANIFICADOR MACRO if (db_result(db_query("SELECT nid FROM {ente_planificador} where tipo = '1'")) > 0) { unset($tipos_entes[1]); } if (!$node->nid) { $form['tipo'] = array( '#type' => 'select', '#title' => t('Tipo de rol'), '#default_value' => $node->tipo, '#options' => $tipos_entes, '#description' => t("Seleccione el tipo de rol desempeñado por el actor planificador"), '#required' => TRUE, ); } return $form; } /* * hook_form_alter */ function ente_planificador_form_alter(&$form, $form_state, $form_id) { if ($form_id == 'user_profile_form' && arg(2) == 'chgpwd' && user_access('administer users')) { global $user; if ($form['_account']['#value']->uid != $user->uid) { unset($form['account']['passold']); } } if ($form_id == 'user_pass_reset') { $form['user_pass_reset'] = array( '#type' => 'hidden', '#value' => TRUE, ); } if ($form_id == 'views_exposed_form') { $form['submit']['#value'] = t("Buscar"); } if ($form_id == 'views_exposed_form' && $form['#id'] == 'views-exposed-form-planificacionM-page-1') { $form['nid']['#type'] = 'select'; $entes_options = obtener_ente_planificador(); $entes_options[''] = t("Seleccione"); $form['nid']['#options'] = $entes_options; unset($form['nid']['#size']); } if ($form['#node']->type == 'ente_planificador') { //just remove cck fields in datos basicos if ($form_id == 'ente_planificador_node_form'){ if (isset($form['taxonomy'])) { $form['taxonomy']['#access'] = FALSE; } $node_type = content_types('ente_planificador'); $fields = $node_type['fields']; $field_form = array(); if (is_array($fields) && count($fields)) { foreach($fields as $field_id => $field) { if (variable_get('ente_planificador_' . $field_id, FALSE)) { if (isset($form[$field_id])) { $form[$field_id]['#access'] = FALSE; } } } } } unset($form['buttons']['preview']); $form['buttons']['cancel'] = array( '#type' => 'submit', '#weight'=>'8120', '#attributes' => array('onClick' => 'window.location="' . base_path() . $_GET['destination'] . '"; return false;'), '#value' => t('Cancel'), ); } // Deshabilitando los campos Vision y Misión del Ente $form['field_ente_vision']['#access'] = FALSE; $form['field_ente_mision']['#access'] = FALSE;$form['field_ente_vision']['#access'] = FALSE; switch ($form_id) { case 'user_profile_form': if (arg(0) == 'user' && is_numeric(arg(1)) && arg(2) == 'edit') { $form['account']['pass']['#access'] = FALSE; $form['account']['status']['#access'] = FALSE; $form['#ente_planificador_load'] = FALSE; if (isset($form['_account']['#value']->uid) && $form['_account']['#value']->entes[0]['nid']) { $ente_planificador = ente_planificador_leer_ente_planificadores($form['_account']['#value']->entes[0]['nid']); $form['#ente_planificador_load'] = $ente_planificador; if ($ente_planificador) { if ($ente_planificador->nid) { $form['destination']['#value'] = 'node/' . $ente_planificador->nid . "/usuarios"; } if ($ente_planificador) { if($ente_planificador->tipo && $ente_planificador->tipo == 2) { $variable_get = 'ActorPlanificadorMicro'; } if($ente_planificador->tipo && $ente_planificador->tipo == 1) { $variable_get = 'ActorPlanificadorMacro'; } if (sizeof($form['account']['roles']['#options'])) { foreach($form['account']['roles']['#options'] as $a => $b) { if (($a != variable_get($variable_get, 2))) { unset($form['account']['roles']['#options'][$a]); } } } } //$form['account']['status']['#access'] = FALSE; //$form['account']['status']['#type'] = "hidden"; $form['account']['notify']['#value'] = 1; $form['account']['notify']['#type'] = "hidden"; $form['locale']['#type'] = "hidden"; $form['locale']['language']['#type'] = "hidden"; $enlace = base_path() . 'node/' . $ente_planificador->nid; } } } //eliminar la confirmación de password si el usuario olvido la contraseña if (isset($_SESSION['nuevo_password']) && $_SESSION['nuevo_password']) { $form['account']['passold']['#access'] = FALSE; } unset($form['timezone']); $form['locale']['#type'] = "hidden"; $form['locale']['language']['#type'] = "hidden"; $form['cancel'] = array( '#type' => 'submit', '#weight'=>'961500000', '#attributes' => array('onClick' => 'window.location="' . base_path() . $_GET['destination'] . '"; return false;'), '#value' => t('Cancel'), ); break; case 'user_register': $form['account']['status']['#access'] = FALSE; if (variable_get('genpass_mode',0) == 2) { $form['account']['pass']['#type'] = 'hidden'; } $ente_planificador = FALSE; if (arg(4) && is_numeric(arg(4))) { $ente_planificador = ente_planificador_leer_ente_planificadores(arg(4)); } $form['#ente_planificador_load'] = FALSE; if ($ente_planificador) { $form['#ente_planificador_load'] = $ente_planificador; if ($ente_planificador->nid) { // $form['destination']['#value'] = 'node/' . $ente_planificador->nid . "/usuarios"; } if ($ente_planificador) { if($ente_planificador->tipo && $ente_planificador->tipo == 2) { $variable_get = 'ActorPlanificadorMicro'; } if($ente_planificador->tipo && $ente_planificador->tipo == 1) { $variable_get = 'ActorPlanificadorMacro'; } if (sizeof($form['account']['roles']['#options'])) { foreach($form['account']['roles']['#options'] as $a => $b) { if (($a != variable_get($variable_get, 2))) { unset($form['account']['roles']['#options'][$a]); } } $form['account']['roles']['#default_value'] = array(variable_get($variable_get, 2)); } } $form['account']['status']['#access'] = FALSE; $form['account']['status']['#type'] = "hidden"; $form['account']['notify']['#value'] = 1; $form['account']['notify']['#type'] = "hidden"; $form['locale']['#type'] = "hidden"; $form['locale']['language']['#type'] = "hidden"; $enlace = base_path() . 'node/' . $ente_planificador->nid; if (isset($form['account']) && is_array($form['account']) && !$form_state['post']) { if (trim($form['account']['name']['#value']) == "") { $regex = '#[^()]*\((([^()]+|(?R))*)\)[^()]*#'; $replacement = '\1'; $texto_aux = preg_replace($regex, $replacement, $ente_planificador->title); if (!$texto_aux) { $texto_aux = 'ente' . $ente_planificador->nid; } $sqlcount = db_query("select count(u.uid) as cantidad from {users} u"); $ente = db_fetch_object($sqlcount); $ente->cantidad++; $texto_aux.=$ente->cantidad; $form['account']['name']['#value'] = $texto_aux; } } } else { $enlace = base_path() . 'administrar/entes_planificadores'; } $form['cancel'] = array( '#type' => 'submit', '#weight'=>'8615', '#attributes' => array('onClick' => 'window.location="' . $enlace . '"; return false;'), '#value' => t('Cancel'), ); break; } } /* * ente_planificador_form_cancel * Redireccionar al momento de cancelar */ function ente_planificador_form_cancel(){ drupal_goto(‘destinationpage’); } /** * ente_planificador_obtener_form_municipio... * Retorna el select de municipios... */ function ente_planificador_obtener_form_municipio($title = NULL, $default = NULL, $description = NULL, $entidad_id = "", $display = 'name', $required = FALSE) { $municipios = ente_planificador_obtener_lista_municipio($entidad_id); $disabled = FALSE; if (count($municipios) == 1) { $municipios = array(-1 => t('Not applicable')); } return array( '#type' => 'select', '#title' => $title, '#default_value' => $default, '#options' => $municipios, '#description' => $description, '#required' => $required, '#disabled' => isset($municipios[-1]) ? TRUE : FALSE, '#suffix' => '', '#ahah' => array( 'event' => 'change', 'path' => 'ente_planificador_js_util/parroquia_select', 'wrapper' => 'edit-parroquia-wrapper', 'method' => 'replace', 'progress' => array('type' => 'bar', 'message' => t('Please wait...')), ), ); } /** * ente_planificador_obtener_form_parroquia... * Retorna el select de parroquias... */ function ente_planificador_obtener_form_parroquia($title = NULL, $default = NULL, $description = NULL, $municipio_id = "", $display = 'name', $required = FALSE) { $parroquias = ente_planificador_obtener_lista_parroquia($municipio_id); $disabled = FALSE; if (count($parroquias) == 1) { $parroquias = array(-1 => t('Not applicable')); } return array( '#type' => 'select', '#title' => $title, '#default_value' => $default, '#options' => $parroquias, '#description' => $description, '#required' => $required, '#disabled' => isset($parroquias[-1]) ? TRUE : FALSE, '#suffix' => '', ); } /** * ente_planificador_obtener_lista_parroquia... * Retorna una lista de parroquias... */ function ente_planificador_obtener_lista_parroquia($municipio = 0) { $parroquias = array('0' => "Seleccione"); if ($municipio) { $municipioL = ente_planificador_obtener_municipio($municipio); if ($municipioL->codigo) { $resul_act = db_query("SELECT codigo, nombre FROM {parroquia} where municipio = '%s'", $municipioL->codigo); while ($parroquia = db_fetch_object($resul_act)) { $parroquias[$parroquia->codigo] = $parroquia->nombre; } if ($parroquias) { return $parroquias; } } } return $parroquias; } /** * ente_planificador_obtener_municipio... * Retorna un municipio... */ function ente_planificador_obtener_municipio($municipio = 0) { if ($municipio) { $resul_act = db_query("SELECT codigo, nombre FROM {municipio} where codigo = '%s'", $municipio); $municipio = db_fetch_object($resul_act); } return $municipio; } /** * ente_planificador_obtener_parroquia... * Retorna un parroquia... */ function ente_planificador_obtener_parroquia($parroquia = 0) { if ($parroquia) { $resul_act = db_query("SELECT codigo, nombre FROM {parroquia} where codigo = '%s'", $parroquia); $parroquia = db_fetch_object($resul_act); } return $parroquia; } /** * ente_planificador_obtener_entidad... * Retorna una entidad... */ function ente_planificador_obtener_entidad($entidad = "") { $entidadL = NULL; if ($entidad) { $resul_act = db_query("SELECT codigo, nombre FROM {entidad} where codigo = '%s'", $entidad); $entidadL = db_fetch_object($resul_act); } return $entidadL; } /** * ente_planificador_obtener_lista_municipio... * Retorna una lista de muncipios... */ function ente_planificador_obtener_lista_municipio($entidad = "") { $municipios = array(0 => "Seleccione"); if ($entidad) { $entidadL = ente_planificador_obtener_entidad($entidad); if ($entidadL->codigo) { $resul_act = db_query("SELECT codigo, nombre FROM {municipio} where entidad = '%s'", $entidad); while ($municipio = db_fetch_object($resul_act)) { $municipios[$municipio->codigo] = $municipio->nombre; } if ($municipios) { return $municipios; } } } return $municipios; } /** * ente_planificador_obtener_lista_entidad... * Retorna una lista de entidades... */ function ente_planificador_obtener_lista_entidad() { $resul_act = db_query('SELECT codigo, nombre FROM {entidad}'); while ($entidad = db_fetch_object($resul_act)) { $entidades[$entidad->codigo] = $entidad->nombre; } return $entidades; } /** * ente_planificador_obtener_actividades... * Retorna una lista de actividades... */ function ente_planificador_obtener_actividades() { $actividades = array(); $resul_act = db_query('SELECT id_actividad, nombre FROM {ente_actividad} ORDER BY nombre'); while ($actividad = db_fetch_object($resul_act)) { $actividades[$actividad->id_actividad] = $actividad->nombre; } return $actividades; } /** * ente_planificador_obtener_municipio... * Retorna un municipio... */ function ente_planificador_obtener_actividad($actividad = 0) { if ($actividad) { $resul_act = db_query("SELECT nombre FROM {ente_actividad} where id_actividad = '%s'", $actividad); $actividad = db_fetch_object($resul_act); } return $actividad->nombre; } /* * Implementation of hook_insert */ function ente_planificador_insert($node) { //$node->tipo = !isset($node->tipo) ? 2 : $node->tipo; if ($node->tipo) { db_query("INSERT INTO {ente_planificador} (nid, tipo) VALUES (%d, %d)", $node->nid, $node->tipo); $update = array(); $inputs = array(); if (isset($node->razon_social) && trim($node->razon_social) != '') { $update[] = "razon_social = '%s'"; $inputs[] = check_plain(trim($node->razon_social)); } if (isset($node->rif) && trim($node->rif) != '' && preg_match("/^(V|E|P|J|G){1}-([0-9]){8}-([0-9]){1}$/",$node->rif) && preg_match("/^(V|E){1}-([0-9]){8}$/",$node->rif)) { $update[] = "rif = '%s'"; $inputs[] = check_plain(trim($node->rif)); } if (isset($node->direccion) && trim($node->direccion)) { $update[] = "direccion = '%s'"; $inputs[] = check_plain(trim($node->direccion)); } if (isset($node->ciudad) && trim($node->ciudad) != '') { $update[] = "ciudad = '%s'"; $inputs[] = check_plain(trim($node->ciudad)); } if (isset($node->estado) && $node->estado) { $update[] = "estado = %d"; $inputs[] = $node->estado; } if (isset($node->municipio) && $node->municipio) { $update[] = "municipio = %d"; $inputs[] = $node->municipio; } if (isset($node->parroquia) && $node->parroquia) { $update[] = "parroquia = %d"; $inputs[] = $node->parroquia; } if (count($update)) { $inputs[] = $node->nid; $result = db_query("update {ente_planificador} set " . implode(', ', $update) . " where nid = %d", $inputs); } } } /* * Implementation of hook_update */ function ente_planificador_update($node) { if ($node->nid && $node->tipo) { db_query("UPDATE {ente_planificador} SET tipo = %d WHERE nid = %d", $node->tipo, $node->nid); } } /* * Implementation of hook_delete */ function ente_planificador_delete($node) { // Notice that we're matching all revision, by using the node's nid. if ($node->nid) { db_query('DELETE FROM {ente_planificador} WHERE nid = %d', $node->nid); db_query('DELETE FROM {ente_actividad_ente} WHERE nid = %d', $node->nid); } } /* * Implementation of hook_view */ function ente_planificador_view($node,$teaser,$page) { $node = node_prepare($node, $teaser); $node->content['title1'] = array( '#prefix'=>'

', '#value' => "" . t('Nombre del ente planificador:') . " " . check_plain($node->title) . "
", '#weight' => -2, '#suffix'=>'

', ); $node->content['tipo'] = array( '#value' => "

" . t('Tipo de Actor Planificador:') . " " . entes_planificadores_obtiene_tipos($node->tipo) . "

", '#weight' => -1, ); //Se añade la estadistica vista al nodo $fecha = time(); if ($node->razon_social) { $node->content['Razon_social'] = array( '#value' => "" . t('Razón Social:') . " " . check_plain($node->razon_social) . "
", '#weight' => 0, ); } if ($node->razon_rif) { $node->content['RIF'] = array( '#value' => "" . t('RIF:') . " " . check_plain($node->rif) . "
", '#weight' => 1, ); } if ($node->direccion) { $node->content['direccion'] = array( '#value' => "" . t('Dirección:') . " " . check_plain($node->direccion) . "
", '#weight' => 2, ); } if ($node->ciudad) { $node->content['ciudad'] = array( '#value' => "" . t('Ciudad:') . " " . check_plain($node->ciudad) . "
", '#weight' => 6, ); } if ($node->estado) { $estado = ente_planificador_obtener_entidad($node->estado); $node->content['estado'] = array( '#prefix'=>'

' . t('Domicilio Fiscal') . '

', '#value' => "" . t('Estado:') . " " . $estado->nombre . "
", '#weight' => 3, ); } if ($node->municipio) { $municipio = ente_planificador_obtener_municipio($node->municipio); $node->content['municipio'] = array( '#value' => "" . t('Municipio:') . " " . $municipio->nombre . "
", '#weight' => 4, ); } if ($node->parroquia) { $parroquia = ente_planificador_obtener_parroquia($node->parroquia); $node->content['parroquia'] = array( '#value' => "" . t('Parroquia:') . " " . $parroquia->nombre . "
", '#weight' => 5, ); } $actividad = $node->actividad; for($i=0;$i 1 ? implode(' , ', $actividad) . '': $actividad[0]; } else { $actidades = t("No seleccionada"); } $node->content['actividad'] = array( '#prefix'=>'

' . t('Actividades del Ente') . '

', '#value' => "" . t('Actividad:') . " ( " . $actidades . " )
", '#weight' => 6, ); return $node; } /* * Implementation of hook_access */ function ente_planificador_access($op, $node, $account) { if ($op == 'view') { return user_access('ver planificador'); } if ($op == 'create') { return ((user_access('edit all planificador'))||(user_access('admin planificador'))); } if ($op == 'update') { if (user_access('edit all planificador') ||user_access('admin planificador') || (user_access('edit own planificador') && ($account->uid == $node->usuarios[$account->uid]))) { return TRUE; } } if ($op == 'delete') { return ((user_access('edit all planificador'))||(user_access('admin planificador'))); } } /* * obtener_ente_planificador * retorna una lista de entes planificadores publicados */ function obtener_ente_planificador() { $resultado = db_query("select nid, title from {node} where type='ente_planificador' and status = 1"); while ($ente = db_fetch_object($resultado)) { $entes[$ente->nid] = $ente->title; } if (!sizeof($entes)) { $entes = array(0 => "Seleccione"); } return $entes; } /* * obtener_mis_ente_planificador * retorna una lista de mis entes planificadores publicados */ function obtener_mis_ente_planificador($uid = 0) { if ($uid) { $resultado = db_query("select n.nid, n.title, p.rif,p.direccion from {node} n,{ente_user_planificador} u, {ente_planificador} p where u.usuario = %d and u.nid = n.nid and n.type='ente_planificador' and u.nid = p.nid and n.status = 1", $uid); while ($ente = db_fetch_object($resultado)) { $entes[] = array('title' => $ente->title, 'nid' => $ente->nid, 'rif' => $ente->rif, 'direccion' => $ente->direccion); } } return $entes; } /* * Implementation of hook_user */ function ente_planificador_user($op, &$edit, &$user, $category = NULL) { switch ($op) { case 'login': $_REQUEST['destination'] = 'principal'; if (isset($edit['nuevo_password']) && $edit['nuevo_password']) { $_SESSION['nuevo_password'] = TRUE; } break; case 'load': $entes = obtener_mis_ente_planificador($user->uid); $user->entes = $entes; break; case 'validate': if(array_key_exists('passold', $edit)) { if($user->pass!=md5($edit['passold'])) { form_set_error('passold', t('La contraseña actual no coincide con la suministrada.')); } } if($edit['submit'] != t('Change Password') && array_key_exists('cedula', $edit) && !array_key_exists('passold', $edit)) { if(!preg_match("/^(V|E){1}([0-9]){8}$/",$edit['cedula'])) { form_set_error('cedula', t('La cédula de identidad debe tener el formato V00000000 sin puntos.')); } } break; case 'view': $entes = array(); $contenido = '

' . t("Correo Electrónico") . ': ' . $user->mail . '

'; if ($user->nombres) { $contenido = '

' . t("Nombres") . ': ' . $user->nombres . '

'; } if ($user->apellidos) { $contenido .= '

' . t("Apellidos") . ': ' . $user->apellidos . '

'; } if ($user->cedula) { $contenido .= '

' . t("Cédula de Identidad") . ': ' . $user->cedula . '

'; } $header = array( array('data' => t('Ente Planificador')), array('data' => t('RIF')), array('data' => t('Dirección')), ); for ($i=0;$ientes);$i++) { $entes[]= array(l($user->entes[$i]['title'], 'node/' . $user->entes[$i]['nid']), $user->entes[$i]['rif'], $user->entes[$i]['direccion']); } if (sizeof($entes)>0) { $contenido .= theme('table', $header, $entes); } $user->content['user_picture']=array('user_picture' => array ('#value' =>$contenido, '#weight' => -10 )); break; case 'insert': if(array_key_exists('entes', $edit) && $edit['entes']) { $rolenames = user_roles(); $ente_planificador = ente_planificador_leer_ente_planificadores($edit['entes']); if ($ente_planificador->tipo) { if($ente_planificador->tipo && $ente_planificador->tipo == 2) { $variable_get = 'ActorPlanificadorMicro'; } if($ente_planificador->tipo && $ente_planificador->tipo == 1) { $variable_get = 'ActorPlanificadorMacro'; } $edit['roles'][2] = $rolenames[2]; if ($rolenames[variable_get($variable_get, 2)]) { //$edit['roles'][variable_get($variable_get, 2)] = $rolenames[variable_get($variable_get, 2)]; } db_query("delete from {ente_user_planificador} where usuario = %d",$edit['uid']); $result = db_query("insert into {ente_user_planificador} (nid, usuario) values (%d,%d)", $edit['entes'], $edit['uid']); } } break; case 'update': if(array_key_exists('entes', $edit) && $edit['entes']) { db_query("delete from {ente_user_planificador} where usuario = %d", $user->uid); $result = db_query("insert into {ente_user_planificador} (nid, usuario) values (%d,%d)", $edit['entes'], $user->uid); } $result = db_query("update {users} set nombres = '%s', apellidos = '%s', cedula = '%s' where uid = %d", $edit['nombres'], $edit['apellidos'], $edit['cedula'], $user->uid); break; case 'form': // CHECK THAT USER UPDATE NO ANONYMOUS if ($user->uid > 0) { $form['usuario_planificacion']= array( '#type' => 'fieldset', '#title' => t("Datos del usuario"), ); /* if (user_access('admin all planificador')) { $entes = obtener_ente_planificador(); if (user_access('administer users')) { $entes[0] = t('No asignar ente'); } $default_entes = $user->entes[0]['nid'] ? $user->entes[0]['nid'] : 0; $form['usuario_planificacion']['entes'] = array( '#type' => 'select', '#title' => t('Entes'), '#default_value' => $default_entes, '#options' => $entes, '#weight' => 3, ); } */ $form['usuario_planificacion']['nombres'] = array( '#type' => 'textfield', '#title' => t('Nombres'), '#default_value' => $user->nombres, '#size' => 60, '#maxlength' => 244, '#description' => t('Introduzca los nombres del actor'), '#required' => TRUE, '#weight' => 4, ); $form['usuario_planificacion']['apellidos'] = array( '#type' => 'textfield', '#title' => t('Apellidos'), '#default_value' => $user->apellidos, '#size' => 60, '#maxlength' => 244, '#description' => t('Introduzca los apellidos del actor'), '#required' => TRUE, '#weight' => 5, ); $form['usuario_planificacion']['cedula'] = array( '#type' => 'textfield', '#title' => t('Cédula de Identidad'), '#default_value' => $user->cedula, '#size' => 60, '#maxlength' => 244, '#description' => t('Introduzca la Cédula de Identidad'), '#required' => TRUE, '#weight' => 6, ); return $form; } break; case 'register': // CHECK THAT USER UPDATE NO ANONYMOUS // DISPLAY ELEMENT FORM TO SELECT TO USE INTRANET if (user_access('admin planificador')) { $ente_planificador = object; if (arg(4) && is_numeric(arg(4))) { $ente_planificador = ente_planificador_leer_ente_planificadores(arg(4)); } if ($ente_planificador->nid) { $form['actor_planificacion']['entes'] = array( '#type' => 'hidden', '#default_value' => $ente_planificador->nid, ); } /* else { $entes = obtener_ente_planificador(); if (user_access('administer users')) { $entes[0] = t('No asignar ente'); } $form['entes'] = array( '#type' => 'select', '#title' => t('Entes'), '#default_value' => 0, '#options' => $entes, ); } */ } return $form; break; } } /* * Implementation of entes_planificadores_planificacion() */ function entes_planificadores_planificacion($planificador = 0) { drupal_goto('planificacion/' . $planificador); } /* * entes_planificadores_usuarios * Mostrar usuarios de un ente planificador */ function entes_planificadores_usuarios($planificador = 0) { $ente_planificador = ente_planificador_leer_ente_planificadores($planificador); $output = ''; $step = 10; if ($ente_planificador->nid && $ente_planificador->type == 'ente_planificador') { $sqlcount = "SELECT count(u.uid) FROM {users} u, {ente_user_planificador} u1 WHERE u1.usuario = %d AND u1.uid = u.uid"; $sql = "SELECT u.uid, u.name, u.nombres, u.apellidos, u.cedula, u.mail FROM {users} u, {ente_user_planificador} u1 WHERE u1.nid = %d AND u1.usuario = u.uid"; $headers_table[] = array( 'data' => t('Nombre de usuario'), 'sort' => 'asc', 'field' => 'u.name' ); $headers_table[] = array( 'data' => t('Nombres'), 'field' => 'u.nombres' ); $headers_table[] = array( 'data' => t('Apellidos') , 'field' => 'u.apellidos' ); $headers_table[] = array( 'data' => t('Cédula de Identidad'), 'field' => 'u.cedula' ); $headers_table[] = array( 'data' => t('Correo electrónico'), 'field' => 'u.mail' ); $sql.= tablesort_sql($headers_table); $result = pager_query($sql, $step, 0, $sqlcount, $ente_planificador->nid); while($usuario = db_fetch_object($result)) { if (trim($usuario->nombres) == "") { $usuario->nombres = "N/A"; } if (trim($usuario->apellidos) == "") { $usuario->apellidos = "N/A"; } if (trim($usuario->cedula) == "") { $usuario->cedula = "N/A"; } $Lista_usuarios[] = array( 'usuario'=>l($usuario->name, 'user/' . $usuario->uid), 'nombres' => $usuario->nombres, 'apellidos' => $usuario->pellidos, 'cedula' => $usuario->cedula, 'mail' => $usuario->mail ); } if (sizeof($Lista_usuarios)) { $output.= theme('table', $headers_table, $Lista_usuarios); $output .= theme('pager', NULL); } else { $output .= '

' . t('No se encontraron usuarios asignados en el planificadores registrados en el sistema') . '

'; } if ((user_access('edit all planificador'))||(user_access('admin planificador'))) { $output .= '

' . l(t('Agregar usuarios al actor planificador'), 'admin/user/user/create/' . $ente_planificador->nid) . "

"; } return $output; } else { drupal_set_message(t("Ente planificador no encontrado")); drupal_goto('entes_planificadores'); } } /** * Implementation of hook_views_api(). */ function ente_planificador_views_api() { return array( 'api' => '2.0', 'path' => drupal_get_path('module', 'ente_planificador') . '/views', ); } /* * planificacion_submenu_interfaz * Generar el menu de explicación situacional */ function ente_planificador_status_planificacion($nid, $tipo = 2) { $procesos_status = array(); $orden = array(); if (is_numeric($nid)) { $ente_planificador = ente_planificador_leer_ente_planificadores($nid); if ($ente_planificador->type == "ente_planificador") { $procesos = ente_planificador_procesos('status'); $procesos_ordenados = ente_planificador_ordena_procesos($procesos, array()); $procesos = $procesos_ordenados['status']; if (count($procesos)) { foreach($procesos as $id => $proceso) { $proceso_status = array(); foreach (module_list() as $module) { if ($data = module_invoke($module, 'status_planificacion_' . $id, $nid, $tipo)) { $proceso_status = array_merge_recursive($data, $proceso_status); } } $procesos_status[$id]['value'] = $proceso_status; $procesos_status[$id]['title'] = $proceso['title']; } } } } foreach($procesos_status as $id => $arreglo) { $indices = array(); foreach($arreglo['value'] as $ids => $valor) { $weight = isset($valor['weight']) ? $valor['weight'] : 0; $indices[$weight][] = $ids; } ksort($indices); $reemplazo = array(); foreach($indices as $ids => $valores) { foreach($valores as $valor) { $reemplazo[$valor] = $procesos_status[$id]['value'][$valor]; } } unset($procesos_status[$id]['value']); $procesos_status[$id]['value'] = $reemplazo; } return $procesos_status; } /* * planificacion_submenu_interfaz * Generar el menu de explicación situacional */ function planificacion_submenu_interfaz() { $submenu = array(); $smenu = array(); $i = 0; $submenu[$i] = array( 'name'=> t("Explicación situacional"), 'description' => t("Explicación situacional"), 'call' => "explicacion_situacional" ); $aux_menu = array(); foreach (module_list() as $module) { if ($data = module_invoke($module, 'items_menu_planificacion_' . $submenu[$i]['call'])) { $aux_menu = array_merge_recursive($data, $aux_menu); } } $smenu[$i] = $aux_menu; $i++; unset($aux_menu); // LOAD THE REST OF MENUS foreach (module_list() as $module) { if ($data = module_invoke($module, 'menu_planificacion', $valores)) { $submenu[$i] = $data; $aux_menu = array(); foreach (module_list() as $module) { if ($data1 = module_invoke($module, 'items_menu_planificacion_' . $submenu[$i]['call'])) { $aux_menu = array_merge_recursive($data1, $aux_menu); } } $i++; unset($aux_menu); } } return theme('planificacion_submenu_interfaz', $submenu, $smenu); } /* * ente_planificador_theme * Theme de la funcion de ente planificacion */ function ente_planificador_theme() { $theme['planificacion_submenu_interfaz']= array('arguments' => array($menuD => array(), $smenuD => array())); return $theme; } /* * theme_planificacion_submenu_interfaz * Plantilla de ente planificacion */ function theme_planificacion_submenu_interfaz($menuD, $smenuD) { $output = ''; if (sizeof($menuD) > 0) { $output .='
'; for ($i=0;$i
' . $smenuD[$i][$j]['description'] . '
'; } } $output .= ''; $output .= '
'; } } $output .= ''; } return $output; } /* * access_ente_planificador * Verifica si el usuario tiene acceso al ente planificador */ function access_ente_planificador($type_url_str = "", $user = object) { global $user; if ($user->uid != 1 && !sizeof($user->entes)) { return FALSE; } if ($user->uid !=1) { $ente_planificador = ente_planificador_leer_ente_planificadores($user->entes); $type_url_str1 = $type_url_str; $type_url_str = str_replace('_', '-', $type_url_str); $fecha_tipo[1]['FI'] = "FIPMA"; $fecha_tipo[1]['FF'] = "FFPMA"; $fecha_tipo[2]['FI'] = "FIPMI"; $fecha_tipo[2]['FF'] = "FFPMI"; $validFI = variable_get('ente_planificador_' . $type_url_str . $fecha_tipo[$ente_planificador->tipo]['FI'], 0); $validFF = variable_get('ente_planificador_' . $type_url_str . $fecha_tipo[$ente_planificador->tipo]['FF'], 0); $current_time = time(); if ($validFI && $current_time < $validFI) { return FALSE; } elseif ($validFF && $current_time > $validFF + 86399) { return FALSE; } else { return TRUE; } } return TRUE; } /* * muestra_mensaje * Desplegar mensaje al usuario de acuerdo al tiempo de planificacion */ function muestra_mensaje($type_url_str = "", $ente_planficador = 0, $expire = 1, $mensaje = '') { $mi_fecha = ente_planificador_user_acceso_proceso($type_url_str, $ente_planficador); $procesos = ente_planificador_procesos(); $tipos = entes_planificadores_obtiene_tipos(); $tipo = is_numeric($ente_planficador) ? $ente_planficador: $ente_planficador->tipo; $new_mensaje = ''; if (!$mensaje) { if ($expire) { $new_mensaje = t($procesos[$type_url_str]['message_expire'], array('%tipo_ente' => $tipos[$tipo], '%fecha' => format_date($mi_fecha[0]), '%fecha1' => format_date($mi_fecha[1] + 86399))); } else { $new_mensaje = t($procesos[$type_url_str]['message'], array('%tipo_ente' => $tipos[$tipo], '%fecha' => format_date($mi_fecha[0]), '%fecha1' => format_date($mi_fecha[1] + 86399))); } } else { $new_mensaje = $mensaje; } $conf = array( 'plan_tipo' => $type_url_str, 'ente_planificador' => $ente_planficador, 'expire' => $expire, 'mensaje' => $mensaje, ); drupal_alter('ente_planificador_muestra_mensaje', $new_mensaje, $conf); drupal_set_message($new_mensaje, 'status', FALSE); } /* function muestra_mensaje($type_url_str = "", $ente_tipo = 0, $expire = 1) { $mi_fecha = ente_planificador_user_acceso_proceso($type_url_str, $ente_tipo); $procesos = ente_planificador_procesos(); $tipos = entes_planificadores_obtiene_tipos(); if ($expire) { drupal_set_message( t($procesos[$type_url_str]['message_expire'], array( '%tipo_ente' => $tipos[$ente_tipo], '%fecha' => format_date($mi_fecha[0]), '%fecha1' => format_date($mi_fecha[1] + 86399) ) ) ); } else { drupal_set_message( t($procesos[$type_url_str]['message'], array( '%tipo_ente' => $tipos[$ente_tipo], '%fecha' => format_date($mi_fecha[0]), '%fecha1' => format_date($mi_fecha[1] + 86399) ) ) ); } } */ /* * ente_planificador_user_acceso_proceso * Devuelve la fechas permitidas para un proceso de planificacion */ function ente_planificador_user_acceso_proceso($proceso = '', $ente_planificador = 0) { $fechas = array(); $etapas = array('from', 'until'); if ($proceso) { foreach ($etapas as $etapa) { $fechas[] = variable_get('ente_planificador_' . $proceso . '_' . $etapa, 0); } } $conf = array( 'proceso' => $proceso, 'ente_planificador' => $ente_planificador, ); drupal_alter('ente_planificador_proceso_user_acceso', $fechas, $conf); return $fechas; } /* function ente_planificador_user_acceso_proceso($proceso = '', $tipo) { $fechas = array(); $etapas = array('from', 'until'); if ($proceso) { foreach ($etapas as $etapa) { $fechas[] = variable_get('ente_planificador_' . $proceso . '_' . $etapa, 0); } } drupal_alter('user_acceso_proceso', $fechas, $proceso, $tipo); return $fechas; } */ /** * Implementation of hook_form_FORM_ID_alter(): content_field_edit_form. */ function ente_planificador_form_content_field_edit_form_alter(&$form, $form_state) { if ($form['#field']['type_name'] == 'ente_planificador') { $form['widget']['ente_planificador'] = array( '#title' => 'ente planificador', '#type' => 'checkbox', '#default_value' => variable_get('ente_planificador_' . $form['#field']['field_name'], FALSE), '#return_value' => '1', ); $form['#submit'][] = 'ente_planificador_content_field_edit_form_submit'; } } /* * Implementation of ente_planificador_content_field_edit_form_submit() */ function ente_planificador_content_field_edit_form_submit($form, &$form_state) { variable_set('ente_planificador_' . $form_state['values']['field_name'], $form_state['values']['ente_planificador']); } /** * Implementation of hook_theme_registry_alter() */ function ente_planificador_theme_registry_alter(&$theme_registry) { if (!empty($theme_registry['content_view_multiple_field'])) { $theme_registry['content_view_multiple_field']['function'] = 'ente_planificador_content_view_multiple_field'; } } /* * Implementation of ente_planificador_content_view_multiple_field() */ function ente_planificador_content_view_multiple_field($items, $field, $values) { $output = ''; $i = 0; foreach ($items as $item) { if (!empty($item) || $item == '0') { $tipo = $i % 2 ? 'odd' : 'even'; $output .= '
'. $item .'
'; $i++; } } return $output; } /** * Implementation of hook_feeds_node_processor_targets_alter(). * * @see FeedsNodeProcessor::getMappingTargets() */ function ente_planificador_feeds_node_processor_targets_alter(&$targets, $content_type) { if ($content_type == 'ente_planificador') { $targets['tipo'] = array( 'name' => t('Tipo de ente planificador'), 'callback' => 'ente_planificador_feeds_set_target', ); $targets['razon_social'] = array( 'name' => t('Razón social del ente planificador'), 'callback' => 'ente_planificador_values_feeds_set_target', ); $targets['rif'] = array( 'name' => t('Rif del ente planificador'), 'callback' => 'ente_planificador_values_feeds_set_target', ); $targets['direccion'] = array( 'name' => t('Direccion del ente planificador'), 'callback' => 'ente_planificador_values_feeds_set_target', ); $targets['ciudad'] = array( 'name' => t('Ciudad del ente planificador'), 'callback' => 'ente_planificador_values_feeds_set_target', ); $targets['estado'] = array( 'name' => t('Entidad del ente planificador'), 'callback' => 'ente_planificador_estado_feeds_set_target', ); } } /** * Callback for mapping. Here is where the actual mapping happens. * * When the callback is invoked, $target contains the name of the field the * user has decided to map to and $value contains the value of the feed item * element the user has picked as a source. */ function ente_planificador_feeds_set_target($node, $target, $value) { if (!entes_planificadores_obtiene_tipos($value)) { $value = 2; } $node->tipo = $value; } function ente_planificador_values_feeds_set_target($node, $target, $value) { if (trim($value) != '') { $node->{$target} = $value; } } function ente_planificador_estado_feeds_set_target($node, $target, $value) { if (is_string($value) && $value !== '') { $resul_act = db_query("SELECT codigo, nombre FROM {entidad} where codigo = '%s'", $value); $entidadL = db_fetch_object($resul_act); if ($entidadL) { $node->estado = (int) $entidadL->codigo; } else { $resul_act = db_query("SELECT codigo, nombre FROM {entidad} where nombre = '%s'", $value); $entidadL = db_fetch_object($resul_act); if ($entidadL) { $node->estado = (int) $entidadL->codigo; } } } } /** * Implementation of hook_feeds_node_processor_targets_alter(). * * @see FeedsNodeProcessor::getMappingTargets() */ function ente_planificador_feeds_user_processor_targets_alter(&$targets) { $targets['ente'] = array( 'name' => t('Asignar ente planificador al usuario'), 'callback' => 'ente_planificador_asigna_ente_feeds_set_target', ); } function ente_planificador_asigna_ente_feeds_set_target(&$account, $target, $value) { if (trim($value) != '') { $resul_act = db_query("SELECT nid FROM {node} WHERE title = '%s' AND type = 'ente_planificador'", $value); $ente = db_fetch_object($resul_act); if ($ente && $ente->nid) { $account->entes = $ente->nid; } } } /** * Implementation of ente_planificador_leer_ente_planificadores(). * * funcion para evitar la leida muchas veces de un ente planificador */ function ente_planificador_leer_ente_planificadores($ente_planificador = 0) { static $ente_planificadores; if (!isset($ente_planificadores)) { $ente_planificadores = array(); } $ente_planificador_leido = 0; if (is_numeric($ente_planificador)) { if (isset($ente_planificadores[$ente_planificador])) { $ente_planificador_leido = $ente_planificadores[$ente_planificador]; } else { $ente_planificador_leido = node_load($ente_planificador); if ($ente_planificador_leido->type == 'ente_planificador') { $ente_planificadores[$ente_planificador] = $ente_planificador_leido; } else { $ente_planificador_leido = 0; } } } if ($ente_planificador && $ente_planificador->nid) { $ente_planificadores[$ente_planificador->nid] = $ente_planificador; $ente_planificador_leido = $ente_planificador; } return $ente_planificador_leido; }