array( 'name' => t('Acciones Centralizadas'), 'description' => '', 'has_title' => TRUE, 'title_label' => 'Acciones Centralizadas', 'has_body' => FALSE, 'body_label' => 'Cuerpo', 'module' => 'acciones_centralizadas', ), ); } /* * Implementation of hook_form() */ function acciones_centralizadas_form(&$node, $form_state) { $acciones_centralizadas_path = drupal_get_path('module', 'acciones_centralizadas'); drupal_add_js($acciones_centralizadas_path . '/js/acciones_centralizadas.js'); $ente_planificador = node_load($node->field_acciones_ente[0]['nid']); $format_number = array( 'decimals' => variable_get('acciones_centralizadas_number_decimals', 0), 'dec_point' => variable_get('acciones_centralizadas_number_dec_point', ','), 'thousands_sep' => variable_get('acciones_centralizadas_number_thousands_sep', '.'), ); drupal_add_js(array('format_number' => $format_number), 'setting'); $current_time = time(); $tipo_plan = 'acciones_centralizadas_formular'; $mi_fecha = ente_planificador_user_acceso_proceso($tipo_plan, $ente_planificador); $fecha = FALSE; $ente = usuario_tiene_ente($user->uid); if ($mi_fecha[1] + 86399 > $current_time && $mi_fecha[0] < $current_time) { $fecha = TRUE; } if (!$fecha) { muestra_mensaje($tipo_plan, $ente_planificador); } else { if ($ente->nid == $ente_planificador->nid) { muestra_mensaje($tipo_plan, $ente_planificador, 0); $fecha = TRUE; } elseif (!user_access('admin planificador')) { return FALSE; } } if (!$fecha) { return FALSE; } return node_content_form($node, $form_state); } /* * Implementation of hook_access() */ function acciones_centralizadas_access($op, $node, $account) { global $user; if ($op == 'view') { return user_access('ver planificador') || user_access('admin planificador'); } if ($op == 'create') { $current_time = time(); $tipo_plan = 'acciones_centralizadas_formular'; $ente = usuario_tiene_ente($user->uid); $ente_planificador = 0; if ($ente && $ente->nid) { $ente_planificador = ente_planificador_leer_ente_planificadores($ente->nid); } elseif (user_access('admin planificador') && $enteagregar) { $ente_planificador = ente_planificador_leer_ente_planificadores($enteagregar); } if (!$ente_planificador) { return FALSE; } $mi_fecha = ente_planificador_user_acceso_proceso($tipo_plan, $ente_planificador); $fecha = FALSE; if ($mi_fecha[1] + 86399 > $current_time && $mi_fecha[0] < $current_time) { $fecha = TRUE; } if (!$fecha) { return FALSE; } if ($user->entes) { $result = db_query("SELECT ac.nid FROM {accion_centralizada} AS ac INNER JOIN {workflow_node} AS w ON w.nid = ac.nid WHERE ac.ente = %d AND year = %d AND w.sid <> %d", $user->entes, variable_get('acciones_centralizadas_anho_creacion', 0), variable_get('acciones_centralizadas_state_naprobado', NULL)); $acciones_centralizadas = db_fetch_object($result); return !$acciones_centralizadas; } elseif(user_access('admin planificador')) { $entes = array(); $result = db_query('SELECT e.nid FROM {ente_planificador} AS e INNER JOIN {node} AS n ON n.nid = e.nid WHERE n.status = 1'); while($ente = db_fetch_object($result)) { $entes[$ente->nid] = $ente->nid; } $result = db_query("SELECT ac.ente as nid FROM {accion_centralizada} AS ac INNER JOIN {workflow_node} AS w ON w.nid = ac.nid WHERE year = %d AND w.sid <> %d", variable_get('acciones_centralizadas_anho_creacion', 0), variable_get('acciones_centralizadas_state_naprobado', NULL)); while($ente = db_fetch_object($result)) { if (isset($entes[$ente->nid])) { unset($entes[$ente->nid]); } } return count($entes); } return FALSE; } if ($op == 'update') { $estado_aprobado = variable_get('acciones_centralizadas_state_aprobado', NULL); if ($node->_workflow == $estado_aprobado) { return FALSE; } if ($node->anhoaccion_centralizada != variable_get('acciones_centralizadas_anho_creacion', 0)) { return FALSE; } $ente_planificador = node_load($node->field_acciones_ente[0]['nid']); $current_time = time(); $add_reformular = _acciones_centralizadas_reformula_node_add_tab_access($node); $tipo_plan = 'acciones_centralizadas_formular'; $mi_fecha = ente_planificador_user_acceso_proceso($tipo_plan, $ente_planificador); $fecha = FALSE; $ente = usuario_tiene_ente($user->uid); if ($mi_fecha[1] + 86399 > $current_time && $mi_fecha[0] < $current_time) { $fecha = TRUE; } if ($fecha) { if ($ente->nid == $ente_planificador->nid) { $fecha = TRUE; } elseif (!user_access('admin planificador')) { $fecha = FALSE; } } $roles_perm = TRUE; if ($fecha && !user_access('admin planificador')) { $roles_perm = FALSE; $roles_allow = variable_get('acciones_centralizadas_state_m_' . $node->_workflow, array()); $roles = array_keys($user->roles); if (count($roles)) { foreach($roles as $rol) { if($roles_allow[$rol]) { $roles_perm = TRUE; } } } } return $fecha && $roles_perm; } //solo deje al administrador borrar if ($op == 'delete') { return (user_access('admin planificador')); } } /* * Implementation of _acciones_centralizadas_reformula_obtiene_estados() * Obtiene estados del flujo de trabajo para acciones centralizadas */ function _acciones_centralizadas_reformula_obtiene_estados() { $estados = array(); $wid = 0; if (module_exists('workflow')) { $wid = workflow_get_workflow_for_type('accion_centralizada'); if ($wid){ $estados = workflow_get_states($wid); } } return array( 'wid' => $wid, 'states' => $estados, ); } /* * Implementation of hook_ente_procesos_alter() */ function acciones_centralizadas_ente_procesos_alter(&$procesos, $type) { /* if ($type == 'status') { $procesos['acciones_centralizadas'] = array( 'title' => t('Acciones Centralizadas'), 'description' => t('Definición de Proyectos Direccionales'), 'weight' => -9, ); } else { $procesos['acciones_centralizadas_formular'] = array( 'title' => t('Formular Acciones Centralizadas'), 'description' => t('Permite agregar, modificar y eliminar posibles las Acciones Centralizadas'), 'message' => 'Se podrá registrar y/o modificar las acciones centralizadas desde %fecha hasta la fecha %fecha1', 'message_expire' => 'Registrar y/o modificar las acciones centralizadas no se encuentra disponible, se podra realizar desde %fecha hasta la fecha %fecha1)', 'weight' => 3, 'proceso' => 'acciones_centralizadas', ); $procesos['acciones_centralizadas_reformular'] = array( 'title' => t('Reformular Acciones Centralizadas'), 'description' => t('Permite reformular las acciones centralizadas'), 'message' => 'Se podrá registrar y/o modificar la reformulación de las acciones centralizadas desde %fecha hasta la fecha %fecha1', 'message_expire' => 'Registrar y/o modificar la reformulación de las acciones centralizadas no se encuentra disponible, se podra realizar desde %fecha hasta la fecha %fecha1)', 'weight' => 3, 'proceso' => 'acciones_centralizadas', ); $procesos['acciones_centralizadas_seguimiento'] = array( 'title' => t('Seguimiento Acciones Centralizadas'), 'description' => t('Permite el seguimiento de las Acciones Centralizadas'), 'message' => 'Se podrá registrar y/o modificar el seguimiento de las Acciones Centralizadas desde %fecha hasta la fecha %fecha1', 'message_expire' => 'Registrar y/o modificar el seguimiento de las Acciones Centralizadas no se encuentra disponible, se podra realizar desde %fecha hasta la fecha %fecha1)', 'weight' => 3, 'proceso' => 'acciones_centralizadas', ); } */ } /* * Implementation of acciones_centralizadas_status_planificacion_acciones_centralizadas() */ function acciones_centralizadas_status_planificacion_acciones_centralizadas($ente_planificador, $tipo = 2) { $datos_acciones_centralizadas_status = array(); $tipo_plan = 'acciones_centralizadas_formular'; $mi_fecha = ente_planificador_user_acceso_proceso($tipo_plan, $ente_planificador); $new_ente_planificador = node_load($ente_planificador); $year = variable_get('acciones_centralizadas_anho_creacion', 0); $estado_aprobado = variable_get('acciones_centralizadas_state_aprobado', NULL); $result = db_query("SELECT ac.nid FROM {accion_centralizada} AS ac INNER JOIN {workflow_node} AS w ON w.nid = ac.nid WHERE ac.ente = %d AND year = %d AND w.sid = %d", $ente_planificador, $year, $estado_aprobado); $acciones_centralizadas = db_fetch_object($result); //se verifica que exista la planificacion, si existe al menos los datos de familiarizacion fueron ingresados $datos_acciones_centralizadas_status['acciones_centralizadas_formular']['value'] = isset($acciones_centralizadas->nid) ? 1 : 0; $datos_acciones_centralizadas_status['acciones_centralizadas_formular']['title'] = t('Registrar Acciones Centralizadas para el año @year', array('@year' => $year)); $datos_acciones_centralizadas_status['acciones_centralizadas_formular']['link'] = isset($acciones_centralizadas->nid) ? 'node/' . $acciones_centralizadas->nid : 'node/add/accion-centralizada'; $datos_acciones_centralizadas_status['acciones_centralizadas_formular']['mylink'] = isset($acciones_centralizadas->nid) ? 'node/' . $acciones_centralizadas->nid : 'node/add/accion-centralizada'; $datos_acciones_centralizadas_status['acciones_centralizadas_formular']['weight'] = -10; $funciones = array(); //si existe al menos una reformulacion en estado aprobado la reformulacion se puede considerar terminado $reformular = FALSE; if (isset($acciones_centralizadas->nid)) { $result = db_query('SELECT COUNT(id_ref) AS cantidad FROM {accion_reformular} re INNER JOIN {users} u ON u.uid = re.uid WHERE nid = %d AND estado <> %d', $acciones_centralizadas->nid, $estado_naprobado); $reformular = db_fetch_object($result); } $datos_acciones_centralizadas_status['acciones_centralizadas_reformular']['value'] = $reformular && $reformular->cantidad ? 1 : 0; $datos_acciones_centralizadas_status['acciones_centralizadas_reformular']['title'] = t('Reformulaciones para el año @year', array('@year' => $year)); $datos_acciones_centralizadas_status['acciones_centralizadas_reformular']['link'] = isset($acciones_centralizadas->nid) ? 'node/' . $acciones_centralizadas->nid . '/reformular' : 'node/add/accion-centralizada'; $datos_acciones_centralizadas_status['acciones_centralizadas_reformular']['mylink'] = isset($acciones_centralizadas->nid) ? 'node/' . $acciones_centralizadas->nid . '/reformular' : 'node/add/accion-centralizada'; $datos_acciones_centralizadas_status['acciones_centralizadas_reformular']['weight'] = -9; //Seguimiento $year = variable_get('acciones_centralizadas_anho_seguimiento', 0); $mes_segu = variable_get('acciones_centralizadas_mes_seguimiento', 0); $estado_naprobado = variable_get('acciones_centralizadas_state_naprobado', NULL); if ($ente_planificador) { $result = db_query("SELECT max(ase.id_seg) AS id FROM {accion_seguimiento} AS ase INNER JOIN {accion_centralizada} AS ac ON ac.nid = ase.nid WHERE ac.ente = %d AND ac.year = %d AND ase.mes = %d AND ase.estado <> %d", $ente_planificador, $year, $mes, $mes_segu, $estado_naprobado); $seguimiento_id = db_fetch_object($result); $seguimiento = NULL; if ($seguimiento_id->id) { $result = db_query("SELECT * FROM {accion_seguimiento} WHERE id_seg = %d", $seguimiento_id->id); $seguimiento = db_fetch_object($result); } else { $result = db_query("SELECT ac.* FROM {accion_centralizada} AS ac INNER JOIN {workflow_node} AS w ON w.nid = ac.nid WHERE ac.ente = %d AND ac.year = %d AND w.sid <> %d ORDER BY ac.nid DESC", $ente_planificador, $year, $estado_naprobado); $seguimiento = db_fetch_object($result); } } $ftypes = array( 0 => t('Seleccione'), '1' => t('January'), '2' => t('February'), '3' => t('March'), '4' => t('April'), '5' => t('May'), '6' => t('June'), '7' => t('July'), '8' => t('August'), '9' => t('September'), '10' => t('Octuber'), '11' => t('November'), '12' => t('December'), ); $datos_acciones_centralizadas_status['acciones_centralizadas_seguimiento']['value'] = $seguimiento && $seguimiento_id->id && isset($seguimiento->nid) ? 1 : 0; $datos_acciones_centralizadas_status['acciones_centralizadas_seguimiento']['title'] = t('Seguimiento para el mes: @mes, año: @year', array('@year' => $year, '@mes' => $ftypes[$mes_segu])); $datos_acciones_centralizadas_status['acciones_centralizadas_seguimiento']['link'] = $seguimiento && isset($seguimiento->nid) ? 'node/' . $seguimiento->nid . '/seguimiento' : 'node/add/accion-centralizada'; $datos_acciones_centralizadas_status['acciones_centralizadas_seguimiento']['mylink'] = $seguimiento && isset($seguimiento->nid) ? 'node/' . $seguimiento->nid . '/seguimiento' : 'node/add/accion-centralizada'; $datos_acciones_centralizadas_status['acciones_centralizadas_seguimiento']['weight'] = -9; return $datos_acciones_centralizadas_status; } /** * Menu access control callback. Determine access to reformulacion tab. */ function _acciones_centralizadas_reformula_node_add_tab_access($node = NULL) { global $user; $year = variable_get('acciones_centralizadas_anho_creacion', 0); $estado_aprobado = variable_get('acciones_centralizadas_state_aprobado', NULL); if ($node->type != 'accion_centralizada' || $node->anhoaccion_centralizada != $year) { return FALSE; } if ($estado_aprobado && $node->_workflow != $estado_aprobado) { return FALSE; } $ente_planificador = node_load($node->field_acciones_ente[0]['nid']); $current_time = time(); $tipo_plan = 'acciones_centralizadas_reformular'; $mi_fecha = ente_planificador_user_acceso_proceso($tipo_plan, $ente_planificador); $fecha = FALSE; $ente = usuario_tiene_ente($user->uid); if ($mi_fecha[1] + 86399 > $current_time && $mi_fecha[0] < $current_time) { $fecha = TRUE; } if ($fecha) { if ($ente->nid == $ente_planificador->nid) { $fecha = TRUE; } elseif (!user_access('admin planificador')) { return FALSE; } } if (!$fecha) { return FALSE; } $estado_naprobado = variable_get('acciones_centralizadas_state_naprobado', NULL); $result = db_query("SELECT count(ar.id_ref) AS cantidad FROM {accion_centralizada} AS ac INNER JOIN {accion_reformular} AS ar ON ar.nid = ac.nid WHERE (ar.estado <> %d AND ar.estado <> %d) AND ac.ente = %d AND ac.year = %d", $estado_aprobado, $estado_naprobado, $node->field_acciones_ente[0]['nid'], $year); $accion_centralizada = db_fetch_array($result); return !$accion_centralizada['cantidad']; } /** * Menu access control callback. Determine access to editar reformulacion tab. */ function _acciones_centralizadas_reformula_node_edit_tab_access($node = NULL, $reformulacion) { global $user; $year = variable_get('acciones_centralizadas_anho_creacion', 0); $estado_aprobado = variable_get('acciones_centralizadas_state_aprobado', NULL); if ($node->type != 'accion_centralizada' || $node->anhoaccion_centralizada != $year) { return FALSE; } if ($estado_aprobado && $node->_workflow != $estado_aprobado) { return FALSE; } $ente_planificador = node_load($node->field_acciones_ente[0]['nid']); $current_time = time(); $tipo_plan = 'acciones_centralizadas_reformular'; $mi_fecha = ente_planificador_user_acceso_proceso($tipo_plan, $ente_planificador); $fecha = FALSE; $ente = usuario_tiene_ente($user->uid); if ($mi_fecha[1] + 86399 > $current_time && $mi_fecha[0] < $current_time) { $fecha = TRUE; } if ($fecha) { if ($ente->nid == $ente_planificador->nid) { $fecha = TRUE; } elseif (!user_access('admin planificador')) { return FALSE; } } if (!$fecha) { return FALSE; } if ($reformulacion->estado == $estado_aprobado) { return FALSE; } $roles_allow = variable_get('acciones_centralizadas_state_r_' . $reformulacion->estado, array()); if ($user->uid == 1 || ($user->uid == $reformulacion->uid && $roles_allow[-1])) { return TRUE; } $roles = array_keys($user->roles); if (count($roles)) { foreach($roles as $rol) { if($roles_allow[$rol]) { return TRUE; } } } return FALSE; } /** * Menu access control callback. Determine access to reformula tab. */ function _acciones_centralizadas_reformula_node_tab_access($node = NULL) { $estado_aprobado = variable_get('acciones_centralizadas_state_aprobado', NULL); return ($node->type == 'accion_centralizada' && $node->_workflow == $estado_aprobado); } /** * Menu access control callback. Determine access to seguimiento tab. */ function _acciones_centralizadas_seguimiento_node_tab_access($node = NULL) { $estado_aprobado = variable_get('acciones_centralizadas_state_aprobado', NULL); return ($node->type == 'accion_centralizada'); } /** * Menu access control callback. Determine access to seguimiento mes tab. */ function _acciones_centralizadas_seguimiento_node_tab_mes_access($node, $campo = '', $mes) { global $user; $year = variable_get('acciones_centralizadas_anho_seguimiento', 0); if ($node->anhoaccion_centralizada != $year || $node->type != 'accion_centralizada') { return FALSE; } $estado_aprobado = variable_get('acciones_centralizadas_state_aprobado', NULL); if ($node->_workflow != $estado_aprobado) { return FALSE; } $ente_planificador = node_load($node->field_acciones_ente[0]['nid']); $current_time = time(); $tipo_plan = 'acciones_centralizadas_seguimiento'; $mi_fecha = ente_planificador_user_acceso_proceso($tipo_plan, $ente_planificador); $fecha = FALSE; $ente = usuario_tiene_ente($user->uid); if ($mi_fecha[1] + 86399 > $current_time && $mi_fecha[0] < $current_time) { $fecha = TRUE; } if ($fecha) { if ($ente->nid == $ente_planificador->nid) { $fecha = TRUE; } elseif (!user_access('admin planificador')) { $fecha = FALSE; } } $acceso = FALSE; $mes_segu = variable_get('acciones_centralizadas_mes_seguimiento', 0); $workflow = variable_get('acciones_centralizadas_state_seguimiento', NULL) ? variable_get('acciones_centralizadas_state_seguimiento', NULL) : FALSE; if ($fecha && $mes == $mes_segu - 1) { $acceso = TRUE; } $result = db_query("SELECT * FROM {accion_seguimiento} WHERE nid = %d AND mes = %d", $node->nid, $mes); $seguimiento = db_fetch_array($result); if (!isset($seguimiento['estado'])) { $states = _acciones_centralizadas_reformula_obtiene_estados(); $first_state = 0; if ($states['wid']) { $seguimiento['estado'] = _workflow_creation_state($states['wid']); } } $estado_naprobado = variable_get('acciones_centralizadas_state_naprobado', NULL); if ($seguimiento['estado'] == $estado_naprobado || $seguimiento['estado'] == $estado_aprobado) { return FALSE; } $valor_texto = $mes == 0 ? 'value' : 'value_' . $mes; $suma = 0; if ($campo && !is_array($campo) && $node->{$campo}[0]['tid']) { $campo = acciones_centralizadas_menu_campo_load($campo); } $hay_campos = FALSE; if (is_array($campo) && isset($campo['values']) && count($campo['values'])) { foreach($campo['values'] as $partida) { $hay_campos = TRUE; $suma += $partida[$valor_texto]; } } if (!$hay_campos) { return FALSE; } $roles_allow = variable_get('acciones_centralizadas_state_s_' . $seguimiento['estado'], array()); if ($user->uid == 1) { return TRUE; } $roles = array_keys($user->roles); $proles = FALSE; if (count($roles)) { foreach($roles as $rol) { if($roles_allow[$rol]) { $proles = TRUE; } } } return $fecha && $acceso && $proles; } /** * Menu access control callback. Determine access to wk tab. */ function _acciones_centralizadas_reformula_wk_node_tab_access($node = NULL, $reformulacion, $state = 0) { global $user; $year = variable_get('acciones_centralizadas_anho_creacion', 0); $estado_aprobado = variable_get('acciones_centralizadas_state_aprobado', NULL); if ($node->type != 'accion_centralizada' || $node->anhoaccion_centralizada != $year) { return FALSE; } if ($estado_aprobado && $node->_workflow != $estado_aprobado) { return FALSE; } $ente = usuario_tiene_ente($user->uid); $ente_planificador = node_load($node->field_acciones_ente[0]['nid']); if ($ente->nid != $ente_planificador->nid && !user_access('admin planificador')) { return FALSE; } $estado_aprobado = variable_get('acciones_centralizadas_state_aprobado', NULL); $estado_naprobado = variable_get('acciones_centralizadas_state_naprobado', NULL); if ($reformulacion->estado == $estado_naprobado) { return FALSE; } $states = _acciones_centralizadas_reformula_obtiene_estados(); $first_state = 0; if ($states['wid']) { $first_state = _workflow_creation_state($states['wid']); } $roles = array_keys($user->roles); if ($user->uid == 1) { // Superuser is special. $roles_transition = 'ALL'; } else { $roles_transition = $roles; if ($user->uid == $reformulacion->uid && $reformulacion->uid > 0) { $roles_transition += array('author' => 'author'); } } $transitions = array(); if ($states['wid']) { $transitions = workflow_allowable_transitions($reformulacion->estado, 'to', $roles_transition); } if ($first_state && $reformulacion->estado == $first_state) { unset($transitions[$reformulacion->estado]); } if (isset($transitions[$state])) { return TRUE; } return FALSE; } /* * Implementation of hook_nodeapi() */ function acciones_centralizadas_nodeapi(&$node, $op, $teaser = NULL, $page = NULL) { switch ($op) { case 'insert': if ($node->type == 'accion_centralizada') { $year = variable_get('acciones_centralizadas_anho_creacion', 0) ? variable_get('acciones_centralizadas_anho_creacion', 0) : date("Y"); db_query('INSERT INTO {accion_centralizada} (nid, year, ente) VALUES (%d, %d, %d)', $node->nid, $year, $node->field_acciones_ente[0]['nid']); } break; case 'load': if ($node->type == 'accion_centralizada') { $result = db_query("SELECT year FROM {accion_centralizada} WHERE nid = %d", $node->nid); if (!($accion_centralizada = db_fetch_array($result))){ $year = variable_get('acciones_centralizadas_anho_creacion', 0) ? variable_get('acciones_centralizadas_anho_creacion', 0) : date("Y"); db_query('INSERT INTO {accion_centralizada} (nid, year) VALUES (%d, %d)', $node->nid, $year); $result = db_query("SELECT year FROM {accion_centralizada} WHERE nid = %d", $node->nid); $accion_centralizada = db_fetch_array($result); } $node->anhoaccion_centralizada = $accion_centralizada['year']; } case 'view': if ($node->type == 'accion_centralizada') { $node_aux = $node; if ($node_aux->field_acciones_ente[0]['nid']) { $output1 = '
' . t('Datos de la Acción Centralizada') . ''; $ente_planificador = node_load($node_aux->field_acciones_ente[0]['nid']); $output1 .= '
' . t('Ente') . ':
' . l($ente_planificador->title, 'node/' . $ente_planificador->nid) . '
'; $output1 .= '
' . t('Año') . ':
' . $node->anhoaccion_centralizada . '
'; $output1 .= '
' . t('Autor') . ':
' . l($node->name, 'user/' . $node->uid) . '
'; $output1 .= '
' . t('Fecha de creación') . ':
' . format_date($node->created) . '
'; $output1 .= '
' . t('Fecha de la última actualización') . ':
' . format_date($node->changed) . '
'; if (module_exists('workflow')) { $states = _acciones_centralizadas_reformula_obtiene_estados(); $first_state = _workflow_creation_state($states['wid']); $estado = $node->_workflow == $first_state ? t('Ingresado') : $states['states'][$node->_workflow]; $output1 .= '
' . t('Estado de la Acción Centralizada') . ':
' . $estado . '
'; } $output1 .= '
'; $node->content['acciones_centralizadas_ver'] = array( '#value' => $output1, '#weight' => 0, ); } if ($page) { $node->content['acciones_centralizadas_partidas'] = array( '#value' => '
' . t('Partidas de la Acción Especifica') . '' . _acciones_centralizadas_reformula_tab_page_ver($node_aux, 0, FALSE, FALSE) . '
', '#weight' => 1, ); } } break; case 'validate': if ($node->type == 'accion_centralizada') { $acciones_centralizadas_path = drupal_get_path('module', 'acciones_centralizadas'); drupal_add_js($acciones_centralizadas_path . '/js/acciones_centralizadas.js'); $format_number = array( 'decimals' => variable_get('acciones_centralizadas_number_decimals', 0), 'dec_point' => variable_get('acciones_centralizadas_number_dec_point', ','), 'thousands_sep' => variable_get('acciones_centralizadas_number_thousands_sep', '.'), ); drupal_add_js(array('format_number' => $format_number), 'setting'); $array = array( 'field_ac_ac1_ae1', 'field_ac_ac1_ae2', 'field_ac_ac2_ae2', 'field_ac_ac2_ae3', 'field_ac_ac3_ae1', 'field_ac_ac4_ae1', ); $ftypes = array( 'value' => t('January'), 'value_1' => t('February'), 'value_2' => t('March'), 'value_3' => t('April'), 'value_4' => t('May'), 'value_5' => t('June'), 'value_6' => t('July'), 'value_7' => t('August'), 'value_8' => t('September'), 'value_9' => t('Octuber'), 'value_10' => t('November'), 'value_11' => t('December'), ); $un_campo = FALSE; $campo_a = ''; foreach($array as $campo) { $campo_a = $campo; foreach($node->{$campo} as $valores) { if ($valores['tid'] != 0) { foreach($ftypes as $mes => $nombre) { if ($valores[$mes]) { $un_campo = TRUE; } } } } } if (!$un_campo && $campo_a) { form_set_error($campo_a, t('Debe ingresar al menos una partida.')); } } break; case 'delete': db_query('DELETE FROM {accion_centralizada} WHERE nid = %d', $node->nid); db_query('DELETE FROM {accion_reformula} WHERE nid = %d', $node->nid); db_query('DELETE FROM {accion_reformular_state} WHERE nid = %d', $node->nid); db_query('DELETE FROM {accion_seguimiento} WHERE nid = %d', $node->nid); db_query('DELETE FROM {accion_segu_partida} WHERE nid = %d', $node->nid); db_query('DELETE FROM {accion_seguimiento_state} WHERE nid = %d', $node->nid); break; } } /* * Implementation of hook_menu() */ function acciones_centralizadas_menu() { $items = array(); $items['acciones_centralizadas'] = array( 'title' => t('Ver Acciones Centralizadas'), 'page callback' => 'acciones_centralizadas_search_ac_display', 'access arguments' => array('ver planificador'), 'type' => MENU_NORMAL_ITEM, ); $items['node/%node/reformular'] = array( 'title' => 'Reformular', 'type' => MENU_LOCAL_TASK, 'access callback' => '_acciones_centralizadas_reformula_node_tab_access', 'access arguments' => array(1), 'page callback' => '_acciones_centralizadas_reformula_list_page', 'page arguments' => array(1), 'weight' => 2, ); $items['node/%node/reformular/list'] = array( 'title' => 'Reformulaciones', 'type' => MENU_DEFAULT_LOCAL_TASK, 'weight' => -10 ); $items['node/%node/reformular/add'] = array( 'title' => 'Agregar', 'type' => MENU_LOCAL_TASK, 'access callback' => '_acciones_centralizadas_reformula_node_add_tab_access', 'access arguments' => array(1), 'page callback' => 'drupal_get_form', 'page arguments' => array('acciones_centralizadas_reformula_tab_page_form', 1), 'weight' => 2, ); $items['node/%node/reformular/%acciones_centralizadas_menu_reformulacion/view'] = array( 'title' => 'Ver', 'type' => MENU_LOCAL_TASK, 'access callback' => '_acciones_centralizadas_reformula_node_tab_access', 'access arguments' => array(1), 'page callback' => '_acciones_centralizadas_reformula_tab_page_ver', 'page arguments' => array(1, 3), 'weight' => 2, ); $items['node/%node/reformular/%acciones_centralizadas_menu_reformulacion/edit'] = array( 'title' => 'Editar', 'type' => MENU_LOCAL_TASK, 'access callback' => '_acciones_centralizadas_reformula_node_edit_tab_access', 'access arguments' => array(1, 3), 'page callback' => 'drupal_get_form', 'page arguments' => array('acciones_centralizadas_reformula_tab_page_form', 1, 3), 'weight' => 3, ); $items['node/%node/reformular/%acciones_centralizadas_menu_reformulacion/workflow/%acciones_centralizadas_wk_menu'] = array( 'title' => 'Workflow', 'type' => MENU_LOCAL_TASK, 'access callback' => '_acciones_centralizadas_reformula_wk_node_tab_access', 'access arguments' => array(1, 3, 5), 'page callback' => 'drupal_get_form', 'page arguments' => array('acciones_centralizadas_reformula_wk_tab_page_form', 1, 3, 5), 'weight' => 3, ); $items['node/%node/seguimiento'] = array( 'title' => 'Seguimiento', 'type' => MENU_LOCAL_TASK, 'access callback' => '_acciones_centralizadas_seguimiento_node_tab_access', 'access arguments' => array(1), 'page callback' => 'acciones_centralizadas_seguimiento_tab_page', 'page arguments' => array(1), 'weight' => 2, ); $items['node/%node/seguimiento/fase/%acciones_centralizadas_menu_mes'] = array( 'title' => 'Fase de Seguimiento', 'type' => MENU_CALLBACK, 'access callback' => '_acciones_centralizadas_seguimiento_node_tab_access', 'access arguments' => array(1), 'page callback' => 'acciones_centralizadas_seguimiento_nodo_fase_seguimiento', 'page arguments' => array(1, 4), ); $items['node/%node/seguimiento/%acciones_centralizadas_menu_campo/%acciones_centralizadas_menu_mes'] = array( 'title' => 'Seguimiento', 'type' => MENU_LOCAL_TASK, 'access callback' => '_acciones_centralizadas_seguimiento_node_tab_access', 'access arguments' => array(1), 'page callback' => 'acciones_centralizadas_seguimiento_partida_tab_page', 'page arguments' => array(1, 3, 4), 'weight' => 2, ); $items['node/%node/seguimiento/%acciones_centralizadas_menu_campo/%acciones_centralizadas_menu_mes/view'] = array( 'title' => 'Seguimiento', 'type' => MENU_DEFAULT_LOCAL_TASK, 'weight' => -10 ); $items['node/%node/seguimiento/%acciones_centralizadas_menu_campo/%acciones_centralizadas_menu_mes/edit'] = array( 'title' => 'Seguimiento', 'type' => MENU_LOCAL_TASK, 'access callback' => '_acciones_centralizadas_seguimiento_node_tab_mes_access', 'access arguments' => array(1, 3, 4), 'page callback' => 'drupal_get_form', 'page arguments' => array('acciones_centralizadas_seguimiento_tab_page_form', 1, 3, 4), 'weight' => 2, ); $items['node/%node/seguimiento/%acciones_centralizadas_menu_campo/%acciones_centralizadas_menu_mes/workflow/%acciones_centralizadas_wk_menu'] = array( 'title' => 'Seguimiento', 'type' => MENU_LOCAL_TASK, 'access callback' => '_acciones_centralizadas_seguimiento_wk_node_tab_mes_access', 'access arguments' => array(1, 3, 4, 6), 'page callback' => 'drupal_get_form', 'page arguments' => array('acciones_centralizadas_seguimiento_wk_tab_page_form', 1, 3, 4, 6), 'weight' => 2, ); $items['admin/settings/ente_planificador/acciones_centralizadas'] = array( 'title' => t('Acciones Centralizadas'), 'page callback' => 'drupal_get_form', 'page arguments' => array('acciones_centralizadas_admin_settings'), 'access arguments' => array('admin planificador'), 'weight' => -6, 'type' => MENU_LOCAL_TASK, 'file' => 'acciones_centralizadas.admin.inc', ); return $items; } /* * Implementation of _acciones_centralizadas_reformula_obtiene_list_page() */ function _acciones_centralizadas_reformula_obtiene_list_page($node, $muestra = TRUE) { global $user; $format_number = array( 'decimals' => variable_get('acciones_centralizadas_number_decimals', 0), 'dec_point' => variable_get('acciones_centralizadas_number_dec_point', ','), 'thousands_sep' => variable_get('acciones_centralizadas_number_thousands_sep', '.'), ); $ente_planificador = node_load($node->field_acciones_ente[0]['nid']); $current_time = time(); $add_reformular = _acciones_centralizadas_reformula_node_add_tab_access($node); $tipo_plan = 'acciones_centralizadas_reformular'; $mi_fecha = ente_planificador_user_acceso_proceso($tipo_plan, $ente_planificador); $fecha = FALSE; $ente = usuario_tiene_ente($user->uid); if ($mi_fecha[1] + 86399 > $current_time && $mi_fecha[0] < $current_time) { $fecha = TRUE; } if (!$fecha) { if ($muestra) { muestra_mensaje($tipo_plan, $ente_planificador); } } else { if ($ente->nid == $ente_planificador->nid) { $fecha = TRUE; if ($muestra) { muestra_mensaje($tipo_plan, $ente_planificador, 0); } } elseif (!user_access('admin planificador')) { $fecha = FALSE; } } $enlaces_estados = TRUE; if ($ente->nid != $ente_planificador->nid && !user_access('admin planificador')) { $enlaces_estados = FALSE; } $states = _acciones_centralizadas_reformula_obtiene_estados(); $first_state = 0; if ($states['wid']) { $first_state = _workflow_creation_state($states['wid']); } $estado_naprobado = variable_get('acciones_centralizadas_state_naprobado', NULL); $result = db_query('SELECT re.*, u.name, u.uid FROM {accion_reformular} re INNER JOIN {users} u ON u.uid = re.uid WHERE nid = %d AND estado <> %d ORDER BY id_ref DESC', $node->nid, $estado_naprobado); $header = array(); $header[] = array('data' => t('Fecha')); $header[] = array('data' => t('Estado Actual')); $header[] = array('data' => t('Estado Anterior')); $header[] = array('data' => t('Monto (Bs)')); $header[] = array('data' => t('Variación (Bs)')); $header[] = array('data' => t('Total monto (Bs)')); $header[] = array('data' => t('Usuario')); $header[] = array('data' => t('Acción')); $rows = array(); $i = 1; $roles = array_keys($user->roles); $estado_aprobado = variable_get('acciones_centralizadas_state_aprobado', NULL); $editar = ($node->_workflow == $estado_aprobado); while($reformular = db_fetch_object($result)) { if ($user->uid == 1) { // Superuser is special. $roles_transition = 'ALL'; } else { $roles_transition = $roles; if ($user->uid == $reformular->uid && $reformular->uid > 0) { $roles_transition += array('author' => 'author'); } } $transitions = array(); if ($states['wid']) { $transitions = workflow_allowable_transitions($reformular->estado, 'to', $roles_transition); } unset($transitions[$reformular->estado]); $acciones = array(); $row = array(); $row[] = array('data' => format_date($reformular->date),); $estado = isset($states['states'][$reformular->estado]) ? $states['states'][$reformular->estado] : 'N/A'; $row[] = array('data' => $estado,); $estado = isset($states['states'][$reformular->estado_ant]) ? $states['states'][$reformular->estado_ant] : 'N/A'; $row[] = array('data' => $estado,); $row[] = array('data' => number_format($reformular->monto, $format_number['decimals'], $format_number['dec_point'], $format_number['thousands_sep']),); $row[] = array('data' => number_format($reformular->variacion, $format_number['decimals'], $format_number['dec_point'], $format_number['thousands_sep']),); $total = $reformular->monto + $reformular->variacion; $row[] = array('data' => number_format($total, $format_number['decimals'], $format_number['dec_point'], $format_number['thousands_sep']),); $row[] = array('data' => l($reformular->name, 'user/' . $reformular->uid),); //display options if ($editar) { $acciones[] = l(t('Ver'), 'node/' . $node->nid . '/reformular/' . $reformular->id_ref . '/view'); } if ($add_reformular) { $acciones[] = l(t('Agregar nueva reformulación'), 'node/' . $node->nid . '/reformular/add'); } if ($editar && $fecha && $reformular->estado != $estado_naprobado && $reformular->estado != $estado_aprobado && $reformular->id_ref) { $acciones[] = l(t('Modificar'), 'node/' . $node->nid . '/reformular/' . $reformular->id_ref . '/edit'); } if ($enlaces_estados && count($transitions)) { foreach($transitions as $id => $transition) { $acciones[] = l(t('Enviar a @state', array('@state' => $transition)), 'node/' . $node->nid . '/reformular/' . $reformular->id_ref . '/workflow/' . $id); } } $row[] = array('data' => theme('item_list', $acciones),); $rows[] = $row; $i++; } if (!count($rows)) { $row[] = array('data' => 'No existen reformulaciones para este ente', 'colspan' => 8); $rows[] = $row; } $output = ''; if ($node->field_acciones_ente[0]['nid']) { $output = '
' . t('Datos de la Acción Centralizada') . ''; $ente_planificador = node_load($node->field_acciones_ente[0]['nid']); $output .= '
' . t('Ente') . ':
' . l($ente_planificador->title, 'node/' . $ente_planificador->nid) . '
'; $output .= '
' . t('Año') . ':
' . $node->anhoaccion_centralizada . '
'; $output .= '
' . t('Autor') . ':
' . l($node->name, 'user/' . $node->uid) . '
'; $output .= '
' . t('Fecha de creación') . ':
' . format_date($node->created) . '
'; $output .= '
' . t('Fecha de la última actualización') . ':
' . format_date($node->changed) . '
'; if (module_exists('workflow')) { $states = _acciones_centralizadas_reformula_obtiene_estados(); $first_state = _workflow_creation_state($states['wid']); $estado = $node->_workflow == $first_state ? t('Ingresado') : $states['states'][$node->_workflow]; $output .= '
' . t('Estado de la Acción Centralizada') . ':
' . $estado . '
'; } $output .= '
'; } $output .= '
' . t('Reformulaciones de la Acción Centralizada') . ''; $output .= theme('table', $header, $rows) . '
'; return $output; } /* * Implementation of _acciones_centralizadas_reformula_tab_page_ver() */ function _acciones_centralizadas_reformula_tab_page_ver($node, $reformulacion_load = 0, $show_variacion = TRUE, $muestra = TRUE) { global $user; $format_number = array( 'decimals' => variable_get('acciones_centralizadas_number_decimals', 0), 'dec_point' => variable_get('acciones_centralizadas_number_dec_point', ','), 'thousands_sep' => variable_get('acciones_centralizadas_number_thousands_sep', '.'), ); $ente_planificador = node_load($node->field_acciones_ente[0]['nid']); $current_time = time(); $add_reformular = _acciones_centralizadas_reformula_node_add_tab_access($node); $tipo_plan = 'acciones_centralizadas_reformular'; $mi_fecha = ente_planificador_user_acceso_proceso($tipo_plan, $ente_planificador); $fecha = FALSE; $ente = usuario_tiene_ente($user->uid); if ($mi_fecha[1] + 86399 > $current_time && $mi_fecha[0] < $current_time) { $fecha = TRUE; } if (!$fecha) { if ($muestra) { muestra_mensaje($tipo_plan, $ente_planificador); } } else { if ($ente->nid == $ente_planificador->nid) { $fecha = TRUE; if ($muestra) { muestra_mensaje($tipo_plan, $ente_planificador, 0); } } elseif (!user_access('admin planificador')) { $fecha = FALSE; } } $enlaces_estados = TRUE; if ($ente->nid != $ente_planificador->nid && !user_access('admin planificador')) { $enlaces_estados = FALSE; } $id_ref = $reformulacion_load ? $reformulacion_load->id_ref : 0; $format_number = array( 'decimals' => variable_get('acciones_centralizadas_number_decimals', 0), 'dec_point' => variable_get('acciones_centralizadas_number_dec_point', ','), 'thousands_sep' => variable_get('acciones_centralizadas_number_thousands_sep', '.'), ); //drupal_add_js(array('format_number' => $format_number), 'setting'); drupal_set_title(t('Acciones Centralizadas')); if ($show_variacion) { $planificado = t('planificado'); $variacion = t('variación'); $total_texto = t('total'); } $reformula = _acciones_centralizadas_reformula_load($node, $id_ref); $variaciones = _acciones_centralizadas_reformula_all_partidas_load($node, $id_ref); $mes = date('n'); $grupos = fieldgroup_groups('accion_centralizada'); $grupos_form = array(); $grupos_fields = array(); foreach($grupos as $id => $grupo) { if (count($grupo['fields'])) { foreach($grupo['fields'] as $id_field => $field) { $grupos_fields[$id_field] = $id; } } } $array = array( 'field_ac_ac1_ae1', 'field_ac_ac1_ae2', 'field_ac_ac2_ae2', 'field_ac_ac2_ae3', 'field_ac_ac3_ae1', 'field_ac_ac4_ae1', ); $ftypes = array( 'value' => t('January'), 'value_1' => t('February'), 'value_2' => t('March'), 'value_3' => t('April'), 'value_4' => t('May'), 'value_5' => t('June'), 'value_6' => t('July'), 'value_7' => t('August'), 'value_8' => t('September'), 'value_9' => t('Octuber'), 'value_10' => t('November'), 'value_11' => t('December'), ); $valores = array(); foreach($ftypes as $id_field => $texto) { $valores[$id_field] = 0; } $partidas_nodo = array(); foreach ($array as $id) { if (count($node->{$id})) { foreach($node->{$id} as $partida) { if(!empty($partida['tid'])) { $partidas_nodo[$id][$partida['tid']] = $partida['tid']; } } } } if (count($variaciones)) { foreach($variaciones as $field_l => $partidas) { if (count($partidas)) { foreach($partidas as $tid => $partida) { if (!isset($partidas_nodo[$field_l][$tid])) { $valores['tid'] = $tid; $node->{$field_l}[] = $valores; $partidas_nodo[$field_l][$tid] = $tid; } } } } } if (count($reformula)) { foreach($reformula as $field_l => $partidas) { if (count($partidas)) { foreach($partidas as $tid => $partida) { if (!isset($partidas_nodo[$field_l][$tid])) { $valores['tid'] = $tid; $node->{$field_l}[] = $valores; $partidas_nodo[$field_l][$tid] = $tid; } } } } } $fields_title = array(); $field_form = array(); $total_accion = 0; $headers = array(); $header = array(); $estado_aprobado = variable_get('acciones_centralizadas_state_aprobado', NULL); $editar = ($node->_workflow == $estado_aprobado); if ($show_variacion) { $header[] = array('data' => t('Partidas'), 'colspan' => '2'); } else { $header[] = array('data' => t('Partidas'),); } foreach($ftypes as $texto) { $header[] = array('data' => $texto); } $output = ''; $outputs = array(); $header[] = array('data' => t('Total')); foreach ($array as $id) { if (count($node->{$id})) { $field_load = content_fields($id, 'accion_centralizada'); $fields_title[$id] = $field_load['widget']['label']; $rows = array(); $totales_partidas = array(); foreach($ftypes as $id_field => $texto) { $totales_partidas[$id_field] = 0; } $totales_partidas_total = 0; foreach($node->{$id} as $partida) { if(!empty($partida['tid'])) { $term = taxonomy_get_term($partida['tid']); $partida['term'] = $term; $field_form[$id][] = $partida; $row = array(); $row1 = array(); $row2 = array(); if ($show_variacion) { $row[] = array('data' => $partida['term']->name, 'rowspan' => '3'); $row[] = array('data' => $planificado,); $row1[] = array('data' => $variacion,); $row2[] = array('data' => $total_texto,); } else { $row[] = array('data' => $partida['term']->name,); } $total = 0; $total1 = 0; $i = 1; foreach($ftypes as $id_field => $texto) { $varia = isset($variaciones[$id][$partida['tid']][$id_field]) ? $variaciones[$id][$partida['tid']][$id_field] : 0; $min = isset($partida[$id_field]) ? $partida[$id_field] : 0; $min += $varia; $total += $min; $total_accion += $min; $valor = isset($reformula[$id][$partida['tid']][$id_field])? $reformula[$id][$partida['tid']][$id_field] : 0; $total1 += $valor; //$row[] = array('data' => number_format($min, $format_number['decimals'], $format_number['dec_point'], $format_number['thousands_sep']),); $totales_partidas[$id_field] += (float) $min; $totales_partidas[$id_field] += (float) $valor; $totales_partidas_total += (float) $min; $totales_partidas_total += (float) $valor; if (!$show_variacion) { $row[] = array('data' => number_format($min + $valor, $format_number['decimals'], $format_number['dec_point'], $format_number['thousands_sep']),); } else { $sing = ''; if ($valor > 0) { $sing = '+'; } $row[] = array('data' => number_format($min, $format_number['decimals'], $format_number['dec_point'], $format_number['thousands_sep']),); $row1[] = array('data' => $sing . number_format($valor, $format_number['decimals'], $format_number['dec_point'], $format_number['thousands_sep']),); // $totales_partidas_total += (float) $valor; $row2[] = array('data' => number_format($min + $valor, $format_number['decimals'], $format_number['dec_point'], $format_number['thousands_sep']),); } $i++; } $row[] = array('data' => number_format($total, $format_number['decimals'], $format_number['dec_point'], $format_number['thousands_sep']),); $rows[] = $row; if ($show_variacion) { $row1[] = array('data' => number_format($total1, $format_number['decimals'], $format_number['dec_point'], $format_number['thousands_sep']),); $rows[] = $row1; $row2[] = array('data' => number_format($total + $total1, $format_number['decimals'], $format_number['dec_point'], $format_number['thousands_sep']),); $rows[] = $row2; } } } if (!isset($outputs[$grupos_fields[$id]])) { $outputs[$grupos_fields[$id]] = array(); } if(count($rows)) { $row = array(); $row[] = array('data' => '' . t('TOTAL') . '', 'align' => 'right', 'colspan' => $show_variacion ? 2 : 1); foreach($ftypes as $id_field => $texto) { $row[] = array('data' => number_format($totales_partidas[$id_field], $format_number['decimals'], $format_number['dec_point'], $format_number['thousands_sep']),); } $row[] = array('data' => number_format($totales_partidas_total, $format_number['decimals'], $format_number['dec_point'], $format_number['thousands_sep']),); $rows[] = $row; $outputs[$grupos_fields[$id]][] = '
' . $fields_title[$id] . '
' . theme('table', $header, $rows); $rows = array(); } } } foreach($grupos as $id => $grupo) { if (isset($outputs[$id]) && count($outputs[$id])) { $output .= '
' . $grupo['label'] . '' . implode('', $outputs[$id]). '
'; } } $states = array(); if (module_exists('workflow')) { $states = _acciones_centralizadas_reformula_obtiene_estados(); $header = array(); $header[] = array('data' => t('Fecha'),); $header[] = array('data' => t('Estado'),); $header[] = array('data' => t('Estado anterior'),); $header[] = array('data' => t('Comentario'),); $header[] = array('data' => t('Usuario'),); $rows = array(); $result = db_query('SELECT re.*, u.name, u.uid FROM {accion_reformular_state} re INNER JOIN {users} u ON u.uid = re.uid WHERE nid = %d AND id_ref = %d ORDER BY date DESC', $node->nid, $id_ref); while($history = db_fetch_object($result)) { $row = array(); $row[] = array('data' => format_date($history->date),); $row[] = array('data' => $states['states'][$history->estado],); $row[] = array('data' => $states['states'][$history->estado_ant],); $row[] = array('data' => $history->comentario,); $row[] = array('data' => l($history->name, 'user/' . $history->uid),); $rows[] = $row; } if (count($rows)) { $output .= '
' . t('Historial') . ':
' . theme('table', $header, $rows) . '
'; } else { $output .= '
' . t('Historial') . ':
' . t('No existe historial para esta reformulación') . '
'; } } if ($show_variacion) { $links = array(); if ($editar) { $links[] = l(t('Reformulaciones'), 'node/' . $node->nid . '/reformular'); } if ($add_reformular) { $links[] = l(t('Agregar nueva reformulación'), 'node/' . $node->nid . '/reformular/add'); } if (isset($states['wid'])) { $estado_naprobado = variable_get('acciones_centralizadas_state_naprobado', NULL); if ($editar && $fecha && $reformulacion_load->estado != $estado_naprobado && $reformulacion_load->estado != $estado_aprobado && $reformulacion_load->id_ref) { $links[] = l(t('Modificar'), 'node/' . $node->nid . '/reformular/' . $reformulacion_load->id_ref . '/edit'); } $first_state = 0; if ($states['wid']) { $first_state = _workflow_creation_state($states['wid']); } if ($user->uid == 1) { // Superuser is special. $roles = 'ALL'; } else { $roles = array_keys($user->roles); $roles_transition = $roles; if ($user->uid == $reformulacion_load->uid && $reformulacion_load->uid > 0) { $roles += array('author' => 'author'); } } $transitions = array(); if ($states['wid']) { $transitions = workflow_allowable_transitions($reformulacion_load->estado, 'to', $roles); } unset($transitions[$reformulacion_load->estado]); if ($enlaces_estados && count($transitions)) { foreach($transitions as $id => $transition) { $links[] = l(t('Enviar a @state', array('@state' => $transition)), 'node/' . $node->nid . '/reformular/' . $reformulacion_load->id_ref . '/workflow/' . $id); } } } $output .= '
' . t('Acciones') . ':
' . implode(' | ', $links) . '
'; } return $output; } /* * Implementation of _accion_centralizada_obtiene_campos() */ function _accion_centralizada_obtiene_campos() { $fields = array(); $node_type = content_types('accion_centralizada'); if (count($node_type['fields'])) { foreach($node_type['fields'] as $field) { if ($field['type'] == 'cck_plan_fields_field') { $fields[$field['field_name']] = $field['field_name']; } } } return $fields; } /* * Implementation of _acciones_centralizadas_reformula_list_page() */ function _acciones_centralizadas_reformula_list_page($node) { $output = ''; $output .= _acciones_centralizadas_reformula_obtiene_list_page($node, TRUE); return $output; } /** * Implementation of acciones_centralizadas_menu_mes_load(). * Menu loader callback. Load a mes. */ function acciones_centralizadas_menu_mes_load($mes = 0) { settype($mes, "integer"); if ($mes >= 0 && $mes < 12) { return $mes; } return FALSE; } /** * Implementation of acciones_centralizadas_menu_reformulacion_load(). * Menu loader callback. Load a mes. */ function acciones_centralizadas_menu_reformulacion_load($id_ref = 0) { $reformula = FALSE; if ($id_ref && arg(1) && is_numeric(arg(1))) { $result = db_query("SELECT * FROM {accion_reformular} WHERE nid = %d AND id_ref = %d", arg(1), $id_ref); $reformula = db_fetch_object($result); } return $reformula; } /** * Implementation of acciones_centralizadas_menu_campo_load(). * Menu loader callback. Load a accion. */ function acciones_centralizadas_menu_campo_load($campo = '') { $array = array( 'field_ac_ac1_ae1' => 'field_ac_ac1_ae1', 'field_ac_ac1_ae2' => 'field_ac_ac1_ae2', 'field_ac_ac2_ae2' => 'field_ac_ac2_ae2', 'field_ac_ac2_ae3' => 'field_ac_ac2_ae3', 'field_ac_ac3_ae1' => 'field_ac_ac3_ae1', 'field_ac_ac4_ae1' => 'field_ac_ac4_ae1', ); if ($campo && array_key_exists($campo, $array) && is_numeric(arg(1)) && $node_load = node_load(arg(1))) { if (isset($node_load->{$campo})) { $campos = array( 'field' => $campo, 'values' => $node_load->{$campo}, ); return $campos; } } return FALSE; } /* * Implementation of acciones_centralizadas_wk_menu_load() */ function acciones_centralizadas_wk_menu_load($state = 0) { $states = _acciones_centralizadas_reformula_obtiene_estados(); if (isset($states['states'][$state])) { return $state; } return FALSE; } /** * Implementation of hook_theme().accion_centralizada_node_form */ function acciones_centralizadas_theme() { return array( 'acciones_centralizadas_reformula_tab_page_form' => array( 'arguments' => array('form' => NULL), ), 'acciones_centralizadas_seguimiento_tab_page_form' => array( 'arguments' => array('form' => NULL), ), 'accion_centralizada_node_form' => array( 'arguments' => array('form' => NULL), ), ); } /* * Implementation of _acciones_centralizadas_reformula_all_partidas_load() */ function _acciones_centralizadas_reformula_all_partidas_load($node, $id_ref = 0) { $variaciones = array(); $ftypes = array( 'value' => t('January'), 'value_1' => t('February'), 'value_2' => t('March'), 'value_3' => t('April'), 'value_4' => t('May'), 'value_5' => t('June'), 'value_6' => t('July'), 'value_7' => t('August'), 'value_8' => t('September'), 'value_9' => t('Octuber'), 'value_10' => t('November'), 'value_11' => t('December'), ); $load_reformulaciones = array(); $reformulaciones = _acciones_centralizadas_reformula_all_load($node, $id_ref); if ($id_ref) { foreach($reformulaciones as $id => $value) { if ($id < $id_ref) { $load_reformulaciones[$id] = $values; } } } else { $load_reformulaciones = $reformulaciones; } if(count($load_reformulaciones)) { foreach($load_reformulaciones as $id => $value) { $nueva_variacion = _acciones_centralizadas_reformula_load($node, $id); if(count($nueva_variacion)) { foreach($nueva_variacion as $id_campo => $campo) { if(count($campo)) { foreach($campo as $id_partida => $partida) { if($partida['partida']) { if (!isset($variaciones[$id_campo][$id_partida]['partida'])) { $variaciones[$id_campo][$id_partida]['partida'] = $partida['partida']; } foreach($ftypes as $idc => $valor) { if (!isset($variaciones[$id_campo][$id_partida][$idc])) { $variaciones[$id_campo][$id_partida][$idc] = 0; } $variaciones[$id_campo][$id_partida][$idc] += $partida[$idc]; } } } } } } } } return $variaciones; } /* * Implementation of _acciones_centralizadas_reformula_all_load() */ function _acciones_centralizadas_reformula_all_load($node, $id_ref = 0) { $reformulaciones = array(); $estado_aprobado = variable_get('acciones_centralizadas_state_aprobado', NULL); $result = db_query("SELECT * FROM {accion_reformular} WHERE nid = %d AND estado = %d ORDER BY id_ref DESC", $node->nid, $estado_aprobado); while($reformula = db_fetch_array($result)) { $reformulaciones[$reformula['id_ref']] = $reformula; } return $reformulaciones; } /* * Implementation of _acciones_centralizadas_reformula_load() */ function _acciones_centralizadas_reformula_load($node, $id_ref = 0) { $reformula = array(); $inputs = array(); $sql = "SELECT * FROM {accion_reformula} WHERE nid = %d"; $inputs[] = $node->nid; if ($id_ref) { $sql .= ' AND id_ref = %d'; $inputs[] = $id_ref; $result = db_query($sql, $inputs); while($partida = db_fetch_array($result)) { $reformula[$partida['field_name']][$partida['partida']] = $partida; } } return $reformula; } /* * Implementation of _acciones_centralizadas_seguimiento_load() */ function _acciones_centralizadas_seguimiento_load($node, $campo = '', $mes = 0) { $estado_aprobado = variable_get('acciones_centralizadas_state_aprobado', NULL); $estado_naprobado = variable_get('acciones_centralizadas_state_naprobado', NULL); $result = db_query("SELECT max(a.id_seg) AS id FROM {accion_seguimiento} AS a INNER JOIN {accion_centralizada} AS ac ON a.nid = ac.nid WHERE a.nid = %d AND a.mes = %d AND a.campo = '%s' AND a.estado <> %d AND ac.year = %d", $node->nid, $mes, $campo, $estado_naprobado, $node->anhoaccion_centralizada); $seguimiento = array(); $seg = db_fetch_array($result); if ($seg['id']) { $result = db_query("SELECT * FROM {accion_seguimiento} WHERE nid = %d AND id_seg = %d", $node->nid, $seg['id']); $seg_load = db_fetch_array($result); $result = db_query("SELECT * FROM {accion_segu_partida} WHERE id_seg = %d", $seg['id']); $seguimiento['values'] = $seg_load; $valor = $mes > 0 ? 'value_' . $mes : 'value'; while($partida = db_fetch_array($result)) { $seguimiento['comprometido'][$campo][$partida['partida']][$valor] = $partida['comprometido']; $seguimiento['causado'][$campo][$partida['partida']][$valor] = $partida['causado']; $seguimiento['pagado'][$campo][$partida['partida']][$valor] = $partida['pagado']; } } return $seguimiento; } /* * Implementation of acciones_centralizadas_reformula_tab_page_form() */ function acciones_centralizadas_reformula_tab_page_form($form_state, $node, $reformulacion_load = 0) { global $user; $form = array(); $node_type = content_types('accion_centralizada'); $fields = $node_type['fields']; $ente_planificador = node_load($node->field_acciones_ente[0]['nid']); $current_time = time(); $add_reformular = _acciones_centralizadas_reformula_node_add_tab_access($node); $tipo_plan = 'acciones_centralizadas_reformular'; $mi_fecha = ente_planificador_user_acceso_proceso($tipo_plan, $ente_planificador); $fecha = FALSE; $ente = usuario_tiene_ente($user->uid); if ($mi_fecha[1] + 86399 > $current_time && $mi_fecha[0] < $current_time) { $fecha = TRUE; } if (!$fecha) { muestra_mensaje($tipo_plan, $ente_planificador); } else { if ($ente->nid == $ente_planificador->nid) { $fecha = TRUE; muestra_mensaje($tipo_plan, $ente_planificador, 0); } elseif (!user_access('admin planificador')) { $fecha = FALSE; } } $id_ref = $reformulacion_load ? $reformulacion_load->id_ref : 0; $acciones_centralizadas_path = drupal_get_path('module', 'acciones_centralizadas'); drupal_add_js($acciones_centralizadas_path . '/js/acciones_centralizadas.js'); drupal_set_title(t('Acciones Centralizadas')); $format_number = array( 'decimals' => variable_get('acciones_centralizadas_number_decimals', 0), 'dec_point' => variable_get('acciones_centralizadas_number_dec_point', ','), 'thousands_sep' => variable_get('acciones_centralizadas_number_thousands_sep', '.'), ); $form['#format_number'] = array('format_number' => $format_number); drupal_add_js($form['#format_number'], 'setting'); $reformula = _acciones_centralizadas_reformula_load($node, $id_ref); $variaciones = _acciones_centralizadas_reformula_all_partidas_load($node, $id_ref); $mes = variable_get('acciones_centralizadas_anho_seguimiento', 0) == $node->anhoaccion_centralizada ? variable_get('acciones_centralizadas_mes_seguimiento', 0) + 1 : 1; $grupos = fieldgroup_groups('accion_centralizada'); $grupos_form = array(); $grupos_fields = array(); foreach($grupos as $id => $grupo) { if (count($grupo['fields'])) { foreach($grupo['fields'] as $id_field => $field) { $grupos_fields[$id_field] = $id; } } } $array = array( 'field_ac_ac1_ae1', 'field_ac_ac1_ae2', 'field_ac_ac2_ae2', 'field_ac_ac2_ae3', 'field_ac_ac3_ae1', 'field_ac_ac4_ae1', ); $ftypes = array( 'value' => t('January'), 'value_1' => t('February'), 'value_2' => t('March'), 'value_3' => t('April'), 'value_4' => t('May'), 'value_5' => t('June'), 'value_6' => t('July'), 'value_7' => t('August'), 'value_8' => t('September'), 'value_9' => t('Octuber'), 'value_10' => t('November'), 'value_11' => t('December'), ); $exclude_partidas = array(); foreach ($array as $id) { if (count($node->{$id})) { $field_load = content_fields($id, 'accion_centralizada'); $fields_title[$id] = $field_load['widget']['label']; foreach($node->{$id} as $partida) { if(!empty($partida['tid'])) { $exclude_partidas[$id][$partida['tid']] = $partida['tid']; } } } } $partidas_nodo = array(); foreach ($array as $id) { if (count($node->{$id})) { foreach($node->{$id} as $partida) { if(!empty($partida['tid'])) { $partidas_nodo[$id][$partida['tid']] = $partida['tid']; } } } } $valores = array(); foreach($ftypes as $id_field => $texto) { $valores[$id_field] = 0; } if (count($variaciones)) { foreach($variaciones as $field_l => $partidas) { if (count($partidas)) { foreach($partidas as $tid => $partida) { if (!isset($partidas_nodo[$field_l][$tid])) { $valores['tid'] = $tid; $node->{$field_l}[] = $valores; $partidas_nodo[$field_l][$tid] = $tid; } } } } } if (count($reformula)) { foreach($reformula as $field_l => $partidas) { if (count($partidas)) { foreach($partidas as $tid => $partida) { if (!isset($partidas_nodo[$field_l][$tid])) { $valores['tid'] = $tid; $node->{$field_l}[] = $valores; $partidas_nodo[$field_l][$tid] = $tid; } } } } } $fields_title = array(); $field_form = array(); $total_accion = 0; foreach ($array as $id) { if (count($node->{$id})) { $field_load = content_fields($id, 'accion_centralizada'); $fields_title[$id] = $field_load['widget']['label']; foreach($node->{$id} as $partida) { if(!empty($partida['tid'])) { $term = taxonomy_get_term($partida['tid']); $partida['term'] = $term; $field_form[$id][] = $partida; $total = 0; $total1 = 0; $i = 1; foreach($ftypes as $id_field => $texto) { $disabled = FALSE; // $disabled = ($i < $mes)? TRUE : FALSE; $total += $partida[$id_field]; $varia = isset($variaciones[$id][$partida['tid']][$id_field]) ? $variaciones[$id][$partida['tid']][$id_field] : 0; $min = $partida[$id_field] + $varia; $total_accion += $min; $valor = isset($reformula[$id][$partida['tid']][$id_field])? $reformula[$id][$partida['tid']][$id_field] : 0; $total1 += $valor; $idformu = $id . '_' . $partida['tid'] . 'r_' . $id_field; $idformuj = str_replace('_', '-', $idformu); $form[$idformu] = array( '#type' => 'textfield', '#default_value' => $valor, '#size' => 15, '#disabled' => $disabled, '#attributes' => array('class' => $id . '_m' . ($i - 1) . 'p_' . $partida['tid'] . '_field ' . $id . '_' . $partida['tid'] . 'r ' . $id . '_m' . ($i - 1) . '_field ' . $id . '_dato_field numberref', 'onchange' => "valminimo('" . $idformuj . "', '" . $min . "');sumaref('" . $id . '_' . $partida['tid'] . 'r' . "');sumatexto('" . $id . '_m' . ($i - 1) . 'p_' . $partida['tid'] . '_field' . "');sumatexto('" . $id . '_m' . ($i - 1) . '_field' . "');sumatexto('" . $id . '_dato_field' . "');sumatoria_textos('" . $id .'p' . $partida['tid'] . '_field' . "');", 'valor' => $min, 'partida_campo' => $id . '_m' . ($i - 1) . 'p_' . $partida['tid'] . '_field'), ); $i++; } $form[$id . '_' . $partida['tid'] . 'r_total'] = array( '#type' => 'textfield', '#default_value' => $total1, '#size' => 15, '#disabled' => TRUE, '#attributes' => array('class' => $id . '_' . $partida['tid'] . 'r' . '_total totales'), ); } } } } $accion_aux = new stdClass(); $accion_aux->type = 'accion_centralizada'; $accion_aux->title = ''; $node_type = content_types('accion_centralizada'); $fields = $node_type['fields']; $field_form1 = array(); $fields_form = array(); $arreglo1 = array( 'field_ac_ac1_ae1' => 'field_ac_ac1_ae1', 'field_ac_ac1_ae2' => 'field_ac_ac1_ae2', 'field_ac_ac2_ae2' => 'field_ac_ac2_ae2', 'field_ac_ac2_ae3' => 'field_ac_ac2_ae3', 'field_ac_ac3_ae1' => 'field_ac_ac3_ae1', 'field_ac_ac4_ae1' => 'field_ac_ac4_ae1', ); if (is_array($fields) && count($fields)) { foreach($fields as $field_id => $field) { if (array_key_exists($field_id, $arreglo1)) { $field_form1[] = $field_id; $fields_form[] = $field_id; } elseif (variable_get('accion_centralizada_aR_' . $field_id, FALSE)) { $field_form1[] = $field_id; $fields_form[] = $field_id; } } } $form['#node'] = $accion_aux; if (is_array($field_form1) && count($field_form1)) { module_load_include('inc', 'content', 'includes/content.node_form'); foreach ($field_form1 as $field_id) { $field = content_fields($field_id, 'accion_centralizada'); $form['#field_info'][$field_id] = $field; $form += (array) content_field_form($form, $form_state, $field); } } $form['#total_accion'] = $total_accion; $form['#id_ref'] = $id_ref; $form['#node'] = $node; $form['#variaciones'] = $variaciones; $form['#field_form'] = $field_form; $form['#grupos_fields'] = $grupos_fields; $form['#grupos'] = $grupos; $form['#fields_title'] = $fields_title; $form['#mes'] = $mes; $form['#reformula'] = $reformula; $form['#state_creation'] = -1; //get first state if (module_exists('workflow')) { $wid = workflow_get_workflow_for_type('accion_centralizada'); if ($wid) { $form['#state_creation'] = _workflow_creation_state($wid); } } if (count($field_form)) { $form['buttons'] = array( '#prefix' => '
', '#suffix' => '
', ); $form['buttons']['submit'] = array( '#type' => 'submit', '#value' => t('Crear Reformulación'), ); $cancel = $id_ref ? 'node/' . $form['#node']->nid . '/reformular/' . $id_ref . '/view' : 'node/' . $form['#node']->nid . '/reformular'; $form['buttons']['cancel'] = array('#value' => l('Cancelar', $cancel)); } return $form; } /* * Implementation of theme_accion_centralizada_node_form() * Tema para el formulario del formulario de las acciones centralizadas */ function theme_accion_centralizada_node_form($form) { $ftypes = array( 'tid' => t('Account'), 'value' => t('Ene'), 'value_1' => t('Feb'), 'value_2' => t('Mar'), 'value_3' => t('Abr'), 'value_4' => t('May'), 'value_5' => t('Jun'), 'value_6' => t('Jul'), 'value_7' => t('Aug'), 'value_8' => t('Sep'), 'value_9' => t('Oct'), 'value_10' => t('Nov'), 'value_11' => t('Dic'), ); $output = ''; $output .= '
' . $form['group_ac_ac1']['#title'] . ''; $output .= drupal_render($form['group_ac_ac1']['field_ac_ac1_ae1']); unset($form['group_ac_ac1']); $output .= '
'; $i = -1; foreach ($ftypes as $ftype => $label) { if($ftype != 'tid') { $output .= '
0
'; } else { $output .= '
' . t('TOTAL') . '
'; } $i++; } $output .= '
5000
'; $output .= '
'; $form_aux['field_ac_ac2_ae2'] = $form['group_ac_ac2']['field_ac_ac2_ae2']; $form_aux['field_ac_ac2_ae3'] = $form['group_ac_ac2']['field_ac_ac2_ae3']; $output .= '
' . $form['group_ac_ac2']['#title'] . ''; $output .= drupal_render($form['group_ac_ac2']['field_ac_ac1_ae2']); $output .= '
'; $i = -1; foreach ($ftypes as $ftype => $label) { if($ftype != 'tid') { $output .= '
0
'; } else { $output .= '
' . t('TOTAL') . '
'; } $i++; } $output .= '
0
'; $output .= '
'; $output .= '
'; $output .= drupal_render($form['group_ac_ac2']['field_ac_ac2_ae2']); $output .= '
'; $i = -1; foreach ($ftypes as $ftype => $label) { if($ftype != 'tid') { $output .= '
0
'; } else { $output .= '
' . t('TOTAL') . '
'; } $i++; } $output .= '
0
'; $output .= '
'; $output .= '
'; $output .= drupal_render($form['group_ac_ac2']['field_ac_ac2_ae3']); $output .= '
'; $i = -1; foreach ($ftypes as $ftype => $label) { if($ftype != 'tid') { $output .= '
0
'; } else { $output .= '
' . t('TOTAL') . '
'; } $i++; } $output .= '
0
'; unset($form['group_ac_ac2']); $output .= '
'; $output .= '
' . $form['group_ac_ac3']['#title'] . ''; $output .= drupal_render($form['group_ac_ac3']['field_ac_ac3_ae1']); unset($form['group_ac_ac3']); $output .= '
'; $i = -1; foreach ($ftypes as $ftype => $label) { if($ftype != 'tid') { $output .= '
0
'; } else { $output .= '
' . t('TOTAL') . '
'; } $i++; } $output .= '
0
'; $output .= '
'; $output .= '
' . $form['group_ac_ac4']['#title'] . ''; $output .= drupal_render($form['group_ac_ac4']['field_ac_ac4_ae1']); unset($form['group_ac_ac4']); $output .= '
'; $i = -1; foreach ($ftypes as $ftype => $label) { if($ftype != 'tid') { $output .= '
0
'; } else { $output .= '
' . t('TOTAL') . '
'; } $i++; } $output .= '
0
'; $output .= '
'; $output .= drupal_render($form['field_acciones_ente']); return $output . drupal_render($form); } /* * Implementation of theme_acciones_centralizadas_reformula_tab_page_form() */ function theme_acciones_centralizadas_reformula_tab_page_form($form) { $planificado = t('planificado'); $variacion = t('variación'); $total_texto = t('total'); $field_form = $form['#field_form']; $fields_title = $form['#fields_title']; $grupos_fields = $form['#grupos_fields']; $grupos = $form['#grupos']; $ftypes = array( 'value' => t('January'), 'value_1' => t('February'), 'value_2' => t('March'), 'value_3' => t('April'), 'value_4' => t('May'), 'value_5' => t('June'), 'value_6' => t('July'), 'value_7' => t('August'), 'value_8' => t('September'), 'value_9' => t('Octuber'), 'value_10' => t('November'), 'value_11' => t('December'), ); $headers = array(); $header = array(); $header[] = array('data' => t('Partidas'), 'colspan' => '2'); foreach($ftypes as $texto) { $header[] = array('data' => $texto); } $output = ''; $outputs = array(); $header[] = array('data' => t('Total')); $variaciones = $form['#variaciones']; $totales_partidas = array(); if (count($field_form)) { foreach($field_form as $id_field => $fields) { if (!isset($totales_partidas[$id_field])) { $totales_partidas[$id_field] = array(); } $rows = array(); foreach($fields as $field) { $row = array(); $row1 = array(); $row2 = array(); $row[] = array('data' => $field['term']->name, 'rowspan' => '3'); $row[] = array('data' => $planificado,); $row1[] = array('data' => $variacion,); $row2[] = array('data' => $total_texto,); $total = 0; $total1 = 0; $total2 = 0; $i = 0; foreach($ftypes as $id =>$texto) { if (!isset($totales_partidas[$id_field][$id])) { $totales_partidas[$id_field][$id] = 0; } $varia = isset($variaciones[$id_field][$field['tid']][$id]) ? $variaciones[$id_field][$field['tid']][$id] : 0; $min = $field[$id] + $varia; $total += $min; $row[] = array('data' => number_format($min, $form['#format_number']['format_number']['decimals'], $form['#format_number']['format_number']['dec_point'], $form['#format_number']['format_number']['thousands_sep']), 'align' => 'center'); $value_box = $form[$id_field . '_' . $field['tid'] . 'r_' . $id]['#default_value']; $totales_partidas[$id_field][$id] += $min + $value_box; $row1[] = array('data' => drupal_render($form[$id_field . '_' . $field['tid'] . 'r_' . $id]),); $total2 += $min + $value_box; $row2[] = array('data' => '
' . number_format($min + $value_box, $form['#format_number']['format_number']['decimals'], $form['#format_number']['format_number']['dec_point'], $form['#format_number']['format_number']['thousands_sep']) . '
',); $i++; } $row[] = array('data' => number_format($total, $form['#format_number']['format_number']['decimals'], $form['#format_number']['format_number']['dec_point'], $form['#format_number']['format_number']['thousands_sep']),); $row1[] = array('data' => drupal_render($form[$id_field . '_' . $field['tid'] . 'r_total']),); $row2[] = array('data' => '
' . number_format($total2, $form['#format_number']['format_number']['decimals'], $form['#format_number']['format_number']['dec_point'], $form['#format_number']['format_number']['thousands_sep']) . '
',); $rows[] = $row; $rows[] = $row1; $rows[] = $row2; } if (!isset($outputs[$grupos_fields[$id_field]])) { $outputs[$grupos_fields[$id_field]] = array(); } $suma_partida = 0; if (count($rows)) { $row = array(); $row[] = array('data' => '' . t('TOTAL') . '', 'colspan' => '2', 'align' => 'right'); $i = 0; foreach($ftypes as $id =>$texto) { $suma_partida += $totales_partidas[$id_field][$id]; $row[] = array('data' => '
' . number_format($totales_partidas[$id_field][$id], $form['#format_number']['format_number']['decimals'], $form['#format_number']['format_number']['dec_point'], $form['#format_number']['format_number']['thousands_sep']) . '
',); $i++; } $row[] = array('data' => '
' . number_format($suma_partida, $form['#format_number']['format_number']['decimals'], $form['#format_number']['format_number']['dec_point'], $form['#format_number']['format_number']['thousands_sep']) . '
',); $rows[] = $row; } $outputs[$grupos_fields[$id_field]][] = '
' . $fields_title[$id_field] . '
' . theme('table', $header, $rows); } } $output2 = ''; foreach($grupos as $id => $grupo) { if (isset($outputs[$id]) && count($outputs[$id])) { $output .= '
' . $grupo['label'] . '' . implode('', $outputs[$id]). '
'; } if (count($grupo['fields'])) { if ($output2 == '') { $output2 .= '
' . t('Nuevas partidas') . ''; } $output2 .= '
' . $grupo['label'] . ''; foreach($grupo['fields'] as $id_field => $field) { $output2 .= drupal_render($form[$id_field]); } $output2 .= '
'; } } if ($output2 != '') { $output2 .= '
'; $output .= $output2; } $output .= '
' . drupal_render($form) .'
'; return $output; } /* * Implementation of acciones_centralizadas_reformula_tab_page_form_validate() */ function acciones_centralizadas_reformula_tab_page_form_validate($form, &$form_state) { $acciones_centralizadas_path = drupal_get_path('module', 'acciones_centralizadas'); drupal_add_js($acciones_centralizadas_path . '/js/acciones_centralizadas.js'); $ftypes = array( 'value' => t('January'), 'value_1' => t('February'), 'value_2' => t('March'), 'value_3' => t('April'), 'value_4' => t('May'), 'value_5' => t('June'), 'value_6' => t('July'), 'value_7' => t('August'), 'value_8' => t('September'), 'value_9' => t('Octuber'), 'value_10' => t('November'), 'value_11' => t('December'), ); drupal_add_js($form['#format_number'], 'setting'); $valida_valor = FALSE; $campo_valor = ''; foreach($form['#field_form'] as $id => $partidas) { $check_partidas = array(); foreach($partidas as $partida) { $check_partidas[$partida['tid']] = $partida['tid']; $i = 1; foreach($ftypes as $ids =>$texto) { $disabled = TRUE; // $disabled = ($i >= $form['#mes'])? TRUE : FALSE; if ($disabled) { $start = $form_state['values'][$id . '_' . $partida['tid'] .'r_' . $ids]; $value = preg_replace('@[^-0-9]@', '', $start); if ($start != $value) { form_set_error($id . '_' . $partida['tid'] .'r_' . $ids, t('Solo números enteros son permitidos.')); } $campo_valor = $id . '_' . $partida['tid'] .'r_' . $ids; if ($value) { $valida_valor = TRUE; } } if ($disabled && !is_numeric($form_state['values'][$id . '_' . $partida['tid'] .'r_' . $ids])) { form_set_error($id . '_' . $partida['tid'] .'r_' . $ids, t('Amount should be a number')); } elseif($disabled && ($form_state['values'][$id . '_' . $partida['tid'] .'r_' . $ids] + $partida[$ids] < 0)) { form_set_error($id . '_' . $partida['tid'] .'r_' . $ids, t('Amount should be min')); } $i++; } } foreach($form_state['values'][$id] as $idf => $partida) { if (isset($check_partidas[$partida['tid']])) { $existe = FALSE; foreach($ftypes as $ids =>$texto) { if ($partida[$ids] && is_numeric($partida[$ids])) { $existe = TRUE; } } if ($existe) { form_set_error($id . '][' . $idf . '][tid', t('La nueva partida ya se encuentra en la planificación')); } } else { foreach($ftypes as $ids =>$texto) { if ($partida[$ids] && is_numeric($partida[$ids])) { $valida_valor = TRUE; } } } } } if (!$valida_valor) { form_set_error($campo_valor, t('Debe ingresar al menos un valor para alguna partida para registrar una reformulación.')); } } /* * Implementation of acciones_centralizadas_reformula_tab_page_form_submit() */ function acciones_centralizadas_reformula_tab_page_form_submit($form, &$form_state) { global $user; $ftypes = array( 'value' => t('January'), 'value_1' => t('February'), 'value_2' => t('March'), 'value_3' => t('April'), 'value_4' => t('May'), 'value_5' => t('June'), 'value_6' => t('July'), 'value_7' => t('August'), 'value_8' => t('September'), 'value_9' => t('Octuber'), 'value_10' => t('November'), 'value_11' => t('December'), ); $id_ref = $form['#id_ref']; db_query("DELETE FROM {accion_reformula} WHERE nid = %d AND id_ref = %d", $form['#node']->nid, $id_ref); if(!$id_ref) { db_query("INSERT INTO {accion_reformular} (uid, nid, estado, date, estado_ant, monto, variacion) VALUES (%d, %d, %d, %d, 0, %f, -1)", $user->uid, $form['#node']->nid, $form['#state_creation'], time(), $form['#total_accion']); $id_ref = db_last_insert_id('accion_reformular', 'id_ref'); } $total_accion = 0; foreach($form['#field_form'] as $id => $partidas) { foreach($partidas as $partida) { $field = array(); $field[] = $id_ref; $field[] = $id; $field[] = $partida['tid']; $field[] = $form['#node']->nid; $i = 1; foreach($ftypes as $ids =>$texto) { $disabled = TRUE; // $disabled = ($i >= $form['#mes'])? TRUE : FALSE; $reformula = isset($form['#reformula'][$id][$partida['tid']][$ids]) ? $form['#reformula'][$id][$partida['tid']][$ids] : 0; $total = $disabled ? $form_state['values'][$id . '_' . $partida['tid'] .'r_' . $ids] : $reformula; $field[] = $total; $total_accion += $total; $i++; } db_query("INSERT INTO {accion_reformula} (id_ref, field_name, partida, nid, value, value_1, value_2, value_3, value_4, value_5, value_6, value_7, value_8, value_9, value_10, value_11) VALUES (%d, '%s', %d, %d, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f)", $field); } } $arreglo1 = array( 'field_ac_ac1_ae1' => 'field_ac_ac1_ae1', 'field_ac_ac1_ae2' => 'field_ac_ac1_ae2', 'field_ac_ac2_ae2' => 'field_ac_ac2_ae2', 'field_ac_ac2_ae3' => 'field_ac_ac2_ae3', 'field_ac_ac3_ae1' => 'field_ac_ac3_ae1', 'field_ac_ac4_ae1' => 'field_ac_ac4_ae1', ); foreach($arreglo1 as $id) { foreach($form_state['values'][$id] as $idf => $partida) { $total = 0; if ($partida['tid']) { $field = array(); $field[] = $id_ref; $field[] = $id; $field[] = $partida['tid']; $field[] = $form['#node']->nid; $existe = FALSE; foreach($ftypes as $ids =>$texto) { $total += $partida[$ids]; $field[] = $partida[$ids]; if ($partida[$ids] && is_numeric($partida[$ids])) { $existe = TRUE; } } if ($existe) { $total_accion += $total; db_query("INSERT INTO {accion_reformula} (id_ref, field_name, partida, nid, value, value_1, value_2, value_3, value_4, value_5, value_6, value_7, value_8, value_9, value_10, value_11) VALUES (%d, '%s', %d, %d, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f)", $field); } } } } db_query('UPDATE {accion_reformular} SET variacion = %d WHERE nid = %d AND id_ref = %d', $total_accion, $form['#node']->nid, $id_ref); $form_state['redirect'] = 'node/' . $form['#node']->nid . '/reformular/' . $id_ref . '/view'; } /* * Implementation of _display_acciones_centralizadas_seguimiento_tab_page() */ function _display_acciones_centralizadas_seguimiento_tab_page($node) { global $user; $format_number = array( 'decimals' => variable_get('acciones_centralizadas_number_decimals', 0), 'dec_point' => variable_get('acciones_centralizadas_number_dec_point', ','), 'thousands_sep' => variable_get('acciones_centralizadas_number_thousands_sep', '.'), ); $states = _acciones_centralizadas_reformula_obtiene_estados(); $acciones_centralizadas_seguimiento_node_tab_access = _acciones_centralizadas_seguimiento_node_tab_access($node); if (module_exists('workflow')) { if (isset($states['wid'])) { $first_state = 0; if ($states['wid']) { $first_state = _workflow_creation_state($states['wid']); } if ($user->uid == 1) { // Superuser is special. $roles = 'ALL'; } else { $roles = array_keys($user->roles); } } } $year = variable_get('acciones_centralizadas_anho_seguimiento', 0); $mes_segu = variable_get('acciones_centralizadas_mes_seguimiento', 0); $estado_aprobado = variable_get('acciones_centralizadas_state_aprobado', NULL); $estado_naprobado = variable_get('acciones_centralizadas_state_naprobado', NULL); $output = ''; $ftypes = array( 'value' => t('January'), 'value_1' => t('February'), 'value_2' => t('March'), 'value_3' => t('April'), 'value_4' => t('May'), 'value_5' => t('June'), 'value_6' => t('July'), 'value_7' => t('August'), 'value_8' => t('September'), 'value_9' => t('Octuber'), 'value_10' => t('November'), 'value_11' => t('December'), ); $id_ref = $reformulacion_load ? $reformulacion_load->id_ref : 0; $variaciones = _acciones_centralizadas_reformula_all_partidas_load($node, $id_ref); $reformula = _acciones_centralizadas_reformula_load($node); $actual = array(); $meses = array( 0 => t('January'), 1 => t('February'), 2 => t('March'), 3 => t('April'), 4 => t('May'), 5 => t('June'), 6 => t('July'), 7 => t('August'), 8 => t('September'), 9 => t('Octuber'), 10 => t('November'), 11 => t('December'), ); $array = array( 'field_ac_ac1_ae1' => 'field_ac_ac1_ae1', 'field_ac_ac1_ae2' => 'field_ac_ac1_ae2', 'field_ac_ac2_ae2' => 'field_ac_ac2_ae2', 'field_ac_ac2_ae3' => 'field_ac_ac2_ae3', 'field_ac_ac3_ae1' => 'field_ac_ac3_ae1', 'field_ac_ac4_ae1' => 'field_ac_ac4_ae1', ); $valores = array(); foreach($ftypes as $id_field => $texto) { $valores[$id_field] = 0; } $vacio = array(); $partidas_nodo = array(); foreach ($array as $id) { if (!$node->{$id}[0]['tid']) { $node->{$id} = array(); } if (count($node->{$id})) { foreach($node->{$id} as $partida) { if(!empty($partida['tid'])) { $partidas_nodo[$id][$partida['tid']] = $partida['tid']; } } } } if (count($variaciones)) { foreach($variaciones as $field_l => $partidas) { if (count($partidas)) { foreach($partidas as $tid => $partida) { if (!isset($partidas_nodo[$field_l][$tid])) { if (empty($node->{$field_l}[0]['tid']) || !$node->{$field_l}[0]['tid']) { $node->{$field_l} = array(); } $valores['tid'] = $tid; $node->{$field_l}[] = $valores; $partidas_nodo[$field_l][$tid] = $tid; } } } } } if (count($reformula)) { foreach($reformula as $field_l => $partidas) { if (count($partidas)) { foreach($partidas as $tid => $partida) { if (!isset($partidas_nodo[$field_l][$tid])) { if (empty($node->{$field_l}[0]['tid']) || !$node->{$field_l}[0]['tid']) { $node->{$field_l} = array(); } $valores['tid'] = $tid; $node->{$field_l}[] = $valores; $partidas_nodo[$field_l][$tid] = $tid; } } } } } $currents_estados = array(); foreach($meses as $mes => $nombre) { $valor = $mes > 0 ? 'value_' . $mes : 'value'; foreach($array as $ids) { $actualP = _acciones_centralizadas_seguimiento_load($node, $ids, $mes); $mensajes[$ids][$valor] = $actualP['values']; if (isset($actualP['comprometido'][$ids])) { foreach($actualP['comprometido'][$ids] as $tid => $value) { $actual['comprometido'][$ids][$tid][$valor] = $value[$valor]; } foreach($actualP['pagado'][$ids] as $tid => $value) { $actual['pagado'][$ids][$tid][$valor] = $value[$valor]; } foreach($actualP['causado'][$ids] as $tid => $value) { $actual['causado'][$ids][$tid][$valor] = $value[$valor]; } $currents_estados[$ids][$actualP['values']['mes']]['value'] = isset($actualP['values']) && isset($actualP['values']['estado']) ? $actualP['values']['estado'] : -1; $currents_estados[$ids][$actualP['values']['mes']]['texto'] = isset($states['states'][$currents_estados[$ids][$actualP['values']['mes']]['value']]) ? $states['states'][$currents_estados[$ids][$actualP['values']['mes']]['value']] : t('No ingresado'); } $author[$ids][$actualP['values']['mes']] = isset($actualP['values']) && isset($actualP['values']['uid']) ? $actualP['values']['uid'] : 0; } } $comprometido = isset($actual['comprometido']) ? $actual['comprometido'] : array(); $causado = isset($actual['causado']) ? $actual['causado'] : array(); $pagado = isset($actual['pagado']) ? $actual['pagado'] : array(); $grupos = fieldgroup_groups('accion_centralizada'); $header = array(); $header[] = array('data' => t('Mes')); $header[] = array('data' => t('Asignado')); $header[] = array('data' => t('Comprometido')); $header[] = array('data' => t('Causado')); $header[] = array('data' => t('Pagado')); $header[] = array('data' => t('% de inversión')); $header[] = array('data' => t('Estatus de la inversión')); $header[] = array('data' => t('Información complementaria')); $header[] = array('data' => t('Estado')); $header[] = array('data' => t('Opciones Disponibles'),); $grupos_form = array(); $grupos_fields = array(); $colores = array(); $colores[0] = array( 'texto' => variable_get('acciones_centralizadas_texto_default', 'No hay planificación'), 'tcolor' => variable_get('acciones_centralizadas_colort_default', '#FFFFFF'), 'color' => variable_get('acciones_centralizadas_color_default', '#633303'), ); $colores[1] = array( 'texto' => variable_get('acciones_centralizadas_texto_critica', 'Zona crítica'), 'tcolor' => variable_get('acciones_centralizadas_colort_critica', '#FFFFFF'), 'color' => variable_get('acciones_centralizadas_color_critica', '#fd0002'), ); $colores[2] = array( 'texto' => variable_get('acciones_centralizadas_texto_discreta', 'Zona discreta'), 'tcolor' => variable_get('acciones_centralizadas_colort_discreta', '#FFFFFF'), 'color' => variable_get('acciones_centralizadas_color_discreta', '#cc6733'), ); $colores[3] = array( 'texto' => variable_get('acciones_centralizadas_texto_moderada', 'Zona moderada'), 'tcolor' => variable_get('acciones_centralizadas_colort_moderada', '#000000'), 'color' => variable_get('acciones_centralizadas_color_moderada', '#fdff00'), ); $colores[4] = array( 'texto' => variable_get('acciones_centralizadas_texto_optima', 'Zona optima'), 'tcolor' => variable_get('acciones_centralizadas_colort_optima', '#000000'), 'color' => variable_get('acciones_centralizadas_color_optima', '#20ff21'), ); $colores[5] = array( 'texto' => variable_get('acciones_centralizadas_texto_sejecucion', 'Sobre ejecución'), 'tcolor' => variable_get('acciones_centralizadas_colort_sejecucion', '#000000'), 'color' => variable_get('acciones_centralizadas_color_sejecucion', '#9966cd'), ); $output = ''; foreach($grupos as $id => $grupo) { $tablas = array(); if (count($grupo['fields'])) { foreach($grupo['fields'] as $id_field => $field) { $rows = array(); $suma = array(); $sumaC = array(); $sumaCa = array(); $sumaP = array(); $sumaT = 0; $sumaTC = 0; $sumaTCa = 0; $sumaTP = 0; $field_load = content_fields($id_field, 'accion_centralizada'); if (array_key_exists($id_field, $array) && $node->{$id_field}[0]['tid']) { foreach($node->{$id_field} as $values) { foreach($ftypes as $ids =>$texto) { if (!isset($suma[$ids])) { $suma[$ids] = 0; } $comprometido[$id_field][$values['tid']][$ids] = isset($comprometido[$id_field]) && isset($comprometido[$id_field][$values['tid']]) ? $comprometido[$id_field][$values['tid']][$ids] : 0; $causado[$id_field][$values['tid']][$ids] = isset($causado[$id_field]) && isset($causado[$id_field][$values['tid']]) ? $causado[$id_field][$values['tid']][$ids] : 0; $pagado[$id_field][$values['tid']][$ids] = isset($pagado[$id_field]) && isset($pagado[$id_field][$values['tid']]) ? $pagado[$id_field][$values['tid']][$ids] : 0; $varia[$id_field][$values['tid']][$ids] = isset($variaciones[$id_field][$values['tid']][$ids]) ? $variaciones[$id_field][$values['tid']][$ids] : 0; $sumaC[$ids] += $comprometido[$id_field][$values['tid']][$ids]; $sumaCa[$ids] += $causado[$id_field][$values['tid']][$ids]; $sumaP[$ids] += $pagado[$id_field][$values['tid']][$ids]; $valor = $values[$ids] + $varia[$id_field][$values['tid']][$ids]; $suma[$ids] += $valor; } } } if (count($suma)) { $rows = array(); $i = 0; foreach($ftypes as $ids =>$texto) { $zonacritica = $suma[$ids] ? $sumaCa[$ids]/$suma[$ids] : -1; $porczonacritica = $zonacritica >= 0 ? ($zonacritica * 100) . '%' : -1; $colorzona = $colores[0]['color']; $colorfontzona = $colores[0]['tcolor']; $textozona = $colores[0]['texto']; if ($porczonacritica >= 0 && $porczonacritica < 11) { $colorzona = $colores[1]['color']; $colorfontzona = $colores[1]['tcolor']; $textozona = $colores[1]['texto']; } elseif ($porczonacritica >= 11 && $porczonacritica < 51) { $colorzona = $colores[2]['color']; $colorfontzona = $colores[2]['tcolor']; $textozona = $colores[2]['texto']; } elseif ($porczonacritica >= 51 && $porczonacritica < 80) { $colorzona = $colores[3]['color']; $colorfontzona = $colores[3]['tcolor']; $textozona = $colores[3]['texto']; } elseif ($porczonacritica >= 51 && $porczonacritica <= 100) { $colorzona = $colores[4]['color']; $colorfontzona = $colores[4]['tcolor']; $textozona = $colores[4]['texto']; } elseif ($porczonacritica > 100) { $colorzona = $colores[5]['color']; $colorfontzona = $colores[5]['tcolor']; $textozona = $colores[5]['texto']; } if ($porczonacritica < 0) { $porczonacritica = 'N/A'; } else { $porczonacritica = number_format($porczonacritica, $format_number['decimals'], $format_number['dec_point'], $format_number['thousands_sep']); } $row = array(); $row[] = array('data' => $texto,); $row[] = array('data' => number_format($suma[$ids], $format_number['decimals'], $format_number['dec_point'], $format_number['thousands_sep']),); $row[] = array('data' => number_format($sumaC[$ids], $format_number['decimals'], $format_number['dec_point'], $format_number['thousands_sep']),); $row[] = array('data' => number_format($sumaCa[$ids], $format_number['decimals'], $format_number['dec_point'], $format_number['thousands_sep']),); $row[] = array('data' => number_format($sumaP[$ids], $format_number['decimals'], $format_number['dec_point'], $format_number['thousands_sep']),); $row[] = array('data' => $porczonacritica,); $row[] = array('data' => $textozona, 'style' => 'font-weight: bold;background:' . $colorzona . '; color:' . $colorfontzona); $mensaje = isset($mensajes[$id_field][$ids]['comentario']) ? $mensajes[$id_field][$ids]['comentario'] : ''; $row[] = array('data' => $mensaje,); $style_estado = ''; if ($node->anhoaccion_centralizada == $year && $mes_segu == ($i + 1) && isset($currents_estados[$id_field][$i]['value']) && $currents_estados[$id_field][$i]['value'] != $estado_aprobado && $currents_estados[$id_field][$i]['value'] != $estado_naprobado) { $style_estado = 'color:red'; } $estado = isset($currents_estados[$id_field][$i]['texto']) ? $currents_estados[$id_field][$i]['texto'] : 'No ingresado'; $row[] = array('data' => '
' . $estado . '
',); $links = array(); $links[] = l(t('Consultar Seguimiento'), 'node/' . $node->nid . '/seguimiento/' . $id_field . '/' . $i . '/view'); if ($acciones_centralizadas_seguimiento_node_tab_access && $node->anhoaccion_centralizada == $year && $mes_segu == ($i + 1)) { $links[] = l(t('Fase de Seguimiento (@nombre_mes)', array('@nombre_mes' => $meses[$i])), 'node/' . $node->nid . '/seguimiento/fase/' . $i); } if ($suma[$ids] && $node->anhoaccion_centralizada == $year && $mes_segu == ($i + 1) && _acciones_centralizadas_seguimiento_node_tab_mes_access($node, $id_field,$i)) { $links[] = l(t('Modificar el Seguimiento'), 'node/' . $node->nid . '/seguimiento/'. $id_field . '/' . ($mes_segu - 1) . '/edit', array('query' => array('destination' => $_GET['q']))); } $current_estado = isset($currents_estados[$id_field][$i]['value']) ? $currents_estados[$id_field][$i]['value'] : -1; if ($suma[$ids] && $node->anhoaccion_centralizada == $year && $mes_segu == ($i + 1)) { if ($states['wid']) { $roles1 = (array) $roles; echo $author[$id_field][$i]; if ($user->uid != 1 && $user->uid == $author[$id_field][$i] && $author[$id_field][$i] > 0) { $roles1 += array('author' => 'author'); } $transitions = workflow_allowable_transitions($current_estado, 'to', $roles1); } unset($transitions[$current_estado]); if (count($transitions) && $estado_aprobado != $current_estado) { foreach($transitions as $id => $transition) { $links[] = l(t('Enviar a @state', array('@state' => $transition)), 'node/' . $node->nid . '/seguimiento/' . $id_field . '/' . $mes . '/workflow/' . $id, array('query' => array('destination' => $_GET['q']))); } } } $row[] = array('data' => theme('item_list', $links),); $sumaT += $suma[$ids]; $sumaTC += $sumaC[$ids]; $sumaTCa += $sumaCa[$ids]; $sumaTP += $sumaP[$ids]; $rows[] = $row; $i++; } $row = array(); $row[] = array('data' => t('Acumulado'),); $row[] = array('data' => number_format($sumaT, $format_number['decimals'], $format_number['dec_point'], $format_number['thousands_sep']),); $row[] = array('data' => number_format($sumaTC, $format_number['decimals'], $format_number['dec_point'], $format_number['thousands_sep']),); $row[] = array('data' => number_format($sumaTCa, $format_number['decimals'], $format_number['dec_point'], $format_number['thousands_sep']),); $row[] = array('data' => number_format($sumaTP, $format_number['decimals'], $format_number['dec_point'], $format_number['thousands_sep']),); $row[] = array('data' => '', 'colspan' => 5); $sumaT += $suma[$ids]; $sumaTC += $sumaC[$ids]; $sumaTCa += $sumaCa[$ids]; $sumaTP += $sumaP[$ids]; $rows[] = $row; $tablas[]= '
' . $field_load['widget']['label'] . '
' . theme('table', $header, $rows); } } } if (count($tablas)) { $output .= '
' . $grupo['label'] . '' . implode('', $tablas). '
'; $descripcion = array( 0 => '', 1 => '(' . t('De 0 a 10.99 %') . ')', 2 => '(' . t('De 11 a 50.99 %') . ')', 3 => '(' . t('De 51 a 79.99 %') . ')', 4 => '(' . t('De 80 a 100 %') . ')', 5 => '(' . t('Mas de 100 %') . ')', ); $output .= ''; for($i = 0; $i < 6; $i++) { $output .= ''; } $output .= '
' . $colores[$i]['texto'] . ' ' . $descripcion[$i] . '' . '

'; } } if ($output == '') { $output .= t('La acción Centralizada no tiene partidas asignadas.'); } return $output; } /* * Implementation of acciones_centralizadas_seguimiento_tab_page() */ function acciones_centralizadas_seguimiento_tab_page($node) { global $user; drupal_set_title(t('Seguimiento y Control de Acción Centralizada')); $ente_planificador = node_load($node->field_acciones_ente[0]['nid']); $current_time = time(); $tipo_plan = 'acciones_centralizadas_seguimiento'; $mi_fecha = ente_planificador_user_acceso_proceso($tipo_plan, $ente_planificador); $fecha = FALSE; $ente = usuario_tiene_ente($user->uid); if ($mi_fecha[1] + 86399 > $current_time && $mi_fecha[0] < $current_time) { $fecha = TRUE; } if (!$fecha) { muestra_mensaje($tipo_plan, $ente_planificador); } else { if ($ente->nid == $ente_planificador->nid) { $fecha = TRUE; muestra_mensaje($tipo_plan, $ente_planificador, 0); } elseif (!user_access('admin planificador')) { $fecha = FALSE; } } $output = _display_acciones_centralizadas_seguimiento_tab_page($node); return $output; } /* * Implementation of acciones_centralizadas_seguimiento_partida_tab_page() */ function acciones_centralizadas_seguimiento_partida_tab_page($node, $campo = '', $mes = 0) { $acciones_centralizadas_seguimiento_node_tab_access = _acciones_centralizadas_seguimiento_node_tab_access($node); global $user; $format_number = array( 'decimals' => variable_get('acciones_centralizadas_number_decimals', 0), 'dec_point' => variable_get('acciones_centralizadas_number_dec_point', ','), 'thousands_sep' => variable_get('acciones_centralizadas_number_thousands_sep', '.'), ); $ente_planificador = node_load($node->field_acciones_ente[0]['nid']); $current_time = time(); $tipo_plan = 'acciones_centralizadas_seguimiento'; $mi_fecha = ente_planificador_user_acceso_proceso($tipo_plan, $ente_planificador); $fecha = FALSE; $ente = usuario_tiene_ente($user->uid); if ($mi_fecha[1] + 86399 > $current_time && $mi_fecha[0] < $current_time) { $fecha = TRUE; } if (!$fecha) { muestra_mensaje($tipo_plan, $ente_planificador); } else { if ($ente->nid == $ente_planificador->nid) { $fecha = TRUE; muestra_mensaje($tipo_plan, $ente_planificador, 0); } elseif (!user_access('admin planificador')) { $fecha = FALSE; } } drupal_set_title(t('Seguimiento y Control de Acción Centralizada')); $year = variable_get('acciones_centralizadas_anho_creacion', 0); $output = ''; $meses = array( 0 => t('January'), 1 => t('February'), 2 => t('March'), 3 => t('April'), 4 => t('May'), 5 => t('June'), 6 => t('July'), 7 => t('August'), 8 => t('September'), 9 => t('Octuber'), 10 => t('November'), 11 => t('December'), ); $ftypes = array( 'value' => t('January'), 'value_1' => t('February'), 'value_2' => t('March'), 'value_3' => t('April'), 'value_4' => t('May'), 'value_5' => t('June'), 'value_6' => t('July'), 'value_7' => t('August'), 'value_8' => t('September'), 'value_9' => t('Octuber'), 'value_10' => t('November'), 'value_11' => t('December'), ); $id_ref = $reformulacion_load ? $reformulacion_load->id_ref : 0; $variaciones = _acciones_centralizadas_reformula_all_partidas_load($node, $id_ref); $reformula = _acciones_centralizadas_reformula_load($node); $array = array( 'field_ac_ac1_ae1', 'field_ac_ac1_ae2', 'field_ac_ac2_ae2', 'field_ac_ac2_ae3', 'field_ac_ac3_ae1', 'field_ac_ac4_ae1', ); $valores = array(); foreach($ftypes as $id_field => $texto) { $valores[$id_field] = 0; } $partidas_nodo = array(); foreach ($array as $id) { if (count($node->{$id})) { foreach($node->{$id} as $partida) { if(!empty($partida['tid'])) { $partidas_nodo[$id][$partida['tid']] = $partida['tid']; } } } } if (count($variaciones)) { foreach($variaciones as $field_l => $partidas) { if (count($partidas)) { foreach($partidas as $tid => $partida) { if (!isset($partidas_nodo[$field_l][$tid])) { $valores['tid'] = $tid; $node->{$field_l}[] = $valores; if ($field_l == $campo['field']) { $campo['values'][] = $valores; } } } } } } if (count($reformula)) { foreach($reformula as $field_l => $partidas) { if (count($partidas)) { foreach($partidas as $tid => $partida) { if (!isset($partidas_nodo[$field_l][$tid])) { $valores['tid'] = $tid; $node->{$field_l}[] = $valores; if ($field_l == $campo['field']) { $campo['values'][] = $valores; } } } } } } $actual = _acciones_centralizadas_seguimiento_load($node, $campo['field'], $mes); $comprometido = isset($actual['comprometido']) ? $actual['comprometido'] : array(); $causado = isset($actual['causado']) ? $actual['causado'] : array(); $pagado = isset($actual['pagado']) ? $actual['pagado'] : array(); $grupos = fieldgroup_groups('accion_centralizada'); $header = array(); $header[] = array('data' => t('Partida')); $header[] = array('data' => t('Asignado')); $header[] = array('data' => t('Comprometido')); $header[] = array('data' => t('Causado')); $header[] = array('data' => t('Pagado')); $header[] = array('data' => t('% de inversión')); $header[] = array('data' => t('Estatus de la inversión')); $grupos = fieldgroup_groups('accion_centralizada'); $grupos_fields = array(); foreach($grupos as $id => $grupo) { if (count($grupo['fields'])) { foreach($grupo['fields'] as $id_field => $field) { if ($id_field == $campo['field']) { $grupos_fields = $grupos[$id]; } } } } $field_load = content_fields($campo['field'], 'accion_centralizada'); $colores = array(); $colores[0] = array( 'texto' => variable_get('acciones_centralizadas_texto_default', 'No hay planificación'), 'tcolor' => variable_get('acciones_centralizadas_colort_default', '#FFFFFF'), 'color' => variable_get('acciones_centralizadas_color_default', '#633303'), ); $colores[1] = array( 'texto' => variable_get('acciones_centralizadas_texto_critica', 'Zona crítica'), 'tcolor' => variable_get('acciones_centralizadas_colort_critica', '#FFFFFF'), 'color' => variable_get('acciones_centralizadas_color_critica', '#fd0002'), ); $colores[2] = array( 'texto' => variable_get('acciones_centralizadas_texto_discreta', 'Zona discreta'), 'tcolor' => variable_get('acciones_centralizadas_colort_discreta', '#FFFFFF'), 'color' => variable_get('acciones_centralizadas_color_discreta', '#cc6733'), ); $colores[3] = array( 'texto' => variable_get('acciones_centralizadas_texto_moderada', 'Zona moderada'), 'tcolor' => variable_get('acciones_centralizadas_colort_moderada', '#000000'), 'color' => variable_get('acciones_centralizadas_color_moderada', '#fdff00'), ); $colores[4] = array( 'texto' => variable_get('acciones_centralizadas_texto_optima', 'Zona optima'), 'tcolor' => variable_get('acciones_centralizadas_colort_optima', '#000000'), 'color' => variable_get('acciones_centralizadas_color_optima', '#20ff21'), ); $colores[5] = array( 'texto' => variable_get('acciones_centralizadas_texto_sejecucion', 'Sobre ejecución'), 'tcolor' => variable_get('acciones_centralizadas_colort_sejecucion', '#000000'), 'color' => variable_get('acciones_centralizadas_color_sejecucion', '#9966cd'), ); foreach ($campo['values'] as $partida) { if ($partida['tid']) { $term = taxonomy_get_term($partida['tid']); // If this term's vocabulary supports localization. if (module_exists('i18ntaxonomy') && i18ntaxonomy_vocabulary($term->vid) == I18N_TAXONOMY_LOCALIZE) { $term->name = tt("taxonomy:term:$term->tid:name", $term->name); } $valor = $mes > 0 ? 'value_' . $mes : 'value'; $varia = isset($variaciones[$campo['field']][$partida['tid']][$valor]) ? $variaciones[$campo['field']][$partida['tid']][$valor] : 0; $comprometidov = isset($comprometido[$campo['field']]) && isset($comprometido[$campo['field']][$partida['tid']]) ? $comprometido[$campo['field']][$partida['tid']][$valor] : 0; $causadov = isset($causado[$campo['field']]) && isset($causado[$campo['field']][$partida['tid']]) ? $causado[$campo['field']][$partida['tid']][$valor] : 0; $pagadov = isset($pagado[$campo['field']]) && isset($pagado[$campo['field']][$partida['tid']]) ? $pagado[$campo['field']][$partida['tid']][$valor] : 0; $sumaC += $comprometidov; $sumaCa += $causadov; $sumaP += $pagadov; $valorreal = (string) ($partida[$valor] + $varia); $suma += $valorreal; $zonacritica = $valorreal ? $causadov/$valorreal : -1; $porczonacritica = $zonacritica >= 0 ? ($zonacritica * 100) . '%' : -1; $colorzona = $colores[0]['color']; $colorfontzona = $colores[0]['tcolor']; $textozona = $colores[0]['texto']; if ($porczonacritica >= 0 && $porczonacritica < 11) { $colorzona = $colores[1]['color']; $colorfontzona = $colores[1]['tcolor']; $textozona = $colores[1]['texto']; } elseif ($porczonacritica >= 11 && $porczonacritica < 51) { $colorzona = $colores[2]['color']; $colorfontzona = $colores[2]['tcolor']; $textozona = $colores[2]['texto']; } elseif ($porczonacritica >= 51 && $porczonacritica < 80) { $colorzona = $colores[3]['color']; $colorfontzona = $colores[3]['tcolor']; $textozona = $colores[3]['texto']; } elseif ($porczonacritica >= 51 && $porczonacritica <= 100) { $colorzona = $colores[4]['color']; $colorfontzona = $colores[4]['tcolor']; $textozona = $colores[4]['texto']; } elseif ($porczonacritica > 100) { $colorzona = $colores[5]['color']; $colorfontzona = $colores[5]['tcolor']; $textozona = $colores[5]['texto']; } if ($porczonacritica < 0) { $porczonacritica = 'N/A'; } else { $porczonacritica = number_format($porczonacritica, $format_number['decimals'], $format_number['dec_point'], $format_number['thousands_sep']); } $row = array(); $row[] = array('data' => $term->name,); $row[] = array('data' => number_format($valorreal, $format_number['decimals'], $format_number['dec_point'], $format_number['thousands_sep']),); $row[] = array('data' => number_format($comprometidov, $format_number['decimals'], $format_number['dec_point'], $format_number['thousands_sep']),); $row[] = array('data' => number_format($causadov, $format_number['decimals'], $format_number['dec_point'], $format_number['thousands_sep']),); $row[] = array('data' => number_format($pagadov, $format_number['decimals'], $format_number['dec_point'], $format_number['thousands_sep']),); $row[] = array('data' => $porczonacritica,); $row[] = array('data' => $textozona, 'style' => 'font-weight: bold;background:' . $colorzona . '; color:' . $colorfontzona); $rows[] = $row; } } $row = array(); $row[] = array('data' => t('Acumulado'),); $row[] = array('data' => number_format($suma, $format_number['decimals'], $format_number['dec_point'], $format_number['thousands_sep']),); $row[] = array('data' => number_format($sumaC, $format_number['decimals'], $format_number['dec_point'], $format_number['thousands_sep']),); $row[] = array('data' => number_format($sumaCa, $format_number['decimals'], $format_number['dec_point'], $format_number['thousands_sep']),); $row[] = array('data' => $sumaP,); $row[] = array('data' => '', 'colspan' => 2); $rows[] = $row; $output = ''; $grupo = explode('-', $grupos_fields['label']); $output .= '
' . t('Datos de la Acción Centralizada a la que pertenece la acción especifica') . '' . '
' . t('Código de la AC:') . ' ' . $grupo[0] . '
' . '
' . t('Nombre de la AC:') . ' ' . $grupo[1] . '
' . '
'; $output .= '
' . t('Datos de la Acción') . '' . '
' . t('Nombre de la Acción Especifica:') . ' ' . $field_load['widget']['label'] . '
'. '
'; $output .= '
' . t('Seguimiento de partidas de la Acción Especifica') . '' . '
' . t('Mes de Seguimiento Actual:') . ' ' . $meses[$mes] . '
' . theme('table', $header, $rows) . '
'; $acceso = _acciones_centralizadas_seguimiento_node_tab_mes_access($node, $campo['field'], $mes); $estado_aprobado = variable_get('acciones_centralizadas_state_aprobado', NULL); $estado_naprobado = variable_get('acciones_centralizadas_state_naprobado', NULL); $current_estado = isset($actual['values']) && isset($actual['values']['estado']) ? $actual['values']['estado'] : -1; $cid_seg = isset($actual['values']) && isset($actual['values']['id_seg']) ? $actual['values']['id_seg'] : 0; $states = _acciones_centralizadas_reformula_obtiene_estados(); if (module_exists('workflow')) { $states = _acciones_centralizadas_reformula_obtiene_estados(); if ($cid_seg) { $header = array(); $header[] = array('data' => t('Fecha'),); $header[] = array('data' => t('Estado'),); $header[] = array('data' => t('Estado anterior'),); $header[] = array('data' => t('Comentario'),); $header[] = array('data' => t('Usuario'),); $rows = array(); $result = db_query('SELECT re.*, u.name, u.uid FROM {accion_seguimiento_state} re INNER JOIN {users} u ON u.uid = re.uid WHERE nid = %d AND id_seg = %d ORDER BY date DESC', $node->nid, $cid_seg); while($history = db_fetch_object($result)) { $row = array(); $row[] = array('data' => format_date($history->date),); $row[] = array('data' => $states['states'][$history->estado],); $row[] = array('data' => $states['states'][$history->estado_ant],); $row[] = array('data' => $history->comentario,); $row[] = array('data' => l($history->name, 'user/' . $history->uid),); $rows[] = $row; } if (count($rows)) { $output .= '
' . t('Historial') . ':
' . theme('table', $header, $rows) . '
'; $row[] = array('data' => t('No existe historial para este mes de seguimiento'), 'colspan' => 5); } } } $descripcion = array( 0 => '', 1 => '(' . t('De 0 a 10.99 %') . ')', 2 => '(' . t('De 11 a 50.99 %') . ')', 3 => '(' . t('De 51 a 79.99 %') . ')', 4 => '(' . t('De 80 a 100 %') . ')', 5 => '(' . t('Mas de 100 %') . ')', ); $output .= ''; for($i = 0; $i < 6; $i++) { $output .= ''; } $output .= '
' . $colores[$i]['texto'] . ' ' . $descripcion[$i] . '' . '
'; $links = array(); if ($fecha && $current_estado != $estado_aprobado && $current_estado != $estado_naprobado && $acceso) { $links[] = l(t('Modificar seguimiento'), 'node/' . $node->nid . '/seguimiento/' . $campo['field'] . '/' . $mes . '/edit'); } $author = isset($actual['values']) && isset($actual['values']['uid']) ? $actual['values']['uid'] : 0; if ($suma > 0 && module_exists('workflow')) { if (isset($states['wid'])) { $first_state = 0; if ($states['wid']) { $first_state = _workflow_creation_state($states['wid']); } if ($user->uid == 1) { // Superuser is special. $roles = 'ALL'; } else { $roles = array_keys($user->roles); if ($user->uid == $author && $author > 0) { $roles += array('author' => 'author'); } } $transitions = array(); if ($states['wid']) { $transitions = workflow_allowable_transitions($current_estado, 'to', $roles); } unset($transitions[$current_estado]); if (count($transitions) && $estado_aprobado != $current_estado) { foreach($transitions as $id => $transition) { $links[] = l(t('Enviar a @state', array('@state' => $transition)), 'node/' . $node->nid . '/seguimiento/' . $campo['field'] . '/' . $mes . '/workflow/' . $id); } } } } if ($acciones_centralizadas_seguimiento_node_tab_access) { $links[] = l(t('Fase de Seguimiento (@nombre_mes)', array('@nombre_mes' => $meses[$mes])), 'node/' . $node->nid . '/seguimiento/fase/' . $mes); $links[] = l(t('Seguimiento de la AC'), 'node/' . $node->nid . '/seguimiento'); } $header = array(); $header[] = array('data' => t('Opciones Disponibles'),); $rows = array(); $row = array(); $row[] = array('data' => implode(' | ', $links),); $rows[] = $row; $output .= theme('table', $header, $rows); $texto = array(); if($mes > 0 && $mes < 12) { $texto[] = l(t('Consultar mes anterior'), 'node/' . $node->nid . '/seguimiento/' . $campo['field'] . '/' . ($mes - 1) . '/view'); if ($mes < 11) { $texto[] = l(t('Consultar mes proximo'), 'node/' . $node->nid . '/seguimiento/' . $campo['field'] . '/' . ($mes + 1) . '/view'); } } elseif ($mes == 0) { $texto[] = l(t('Consultar mes proximo'), 'node/' . $node->nid . '/seguimiento/' . $campo['field'] . '/' . ($mes + 1) . '/view'); } $output = '

' . implode(' | ', $texto) . "

" . $output; return $output; } /* * Implementation of acciones_centralizadas_seguimiento_tab_page_form() */ function acciones_centralizadas_seguimiento_tab_page_form($form_state, $node, $campo = '', $mes = 0) { global $user; $ente_planificador = node_load($node->field_acciones_ente[0]['nid']); $current_time = time(); $tipo_plan = 'acciones_centralizadas_seguimiento'; $mi_fecha = ente_planificador_user_acceso_proceso($tipo_plan, $ente_planificador); $fecha = FALSE; $ente = usuario_tiene_ente($user->uid); if ($mi_fecha[1] + 86399 > $current_time && $mi_fecha[0] < $current_time) { $fecha = TRUE; } if (!$fecha) { muestra_mensaje($tipo_plan, $ente_planificador); } else { if ($ente->nid == $ente_planificador->nid) { $fecha = TRUE; muestra_mensaje($tipo_plan, $ente_planificador, 0); } elseif (!user_access('admin planificador')) { $fecha = FALSE; } } $acciones_centralizadas_path = drupal_get_path('module', 'acciones_centralizadas'); drupal_add_js($acciones_centralizadas_path . '/js/acciones_centralizadas.js'); $settings['acciones_centralizadas'] = array( 0 => array( 'color' => variable_get('acciones_centralizadas_color_default', '#633303'), 'tcolor' => variable_get('acciones_centralizadas_colort_default', '#FFFFFF'), 'texto' => variable_get('acciones_centralizadas_texto_default', 'No hay planificación'), ), 1 => array( 'color' => variable_get('acciones_centralizadas_color_critica', '#fd0002'), 'tcolor' => variable_get('acciones_centralizadas_colort_critica', '#FFFFFF'), 'texto' => variable_get('acciones_centralizadas_texto_critica', 'Zona crítica'), ), 2 => array( 'color' => variable_get('acciones_centralizadas_color_discreta', '#cc6733'), 'tcolor' => variable_get('acciones_centralizadas_colort_discreta', '#FFFFFF'), 'texto' => variable_get('acciones_centralizadas_texto_discreta', 'Zona discreta'), ), 3 => array( 'color' => variable_get('acciones_centralizadas_color_moderada', '#fdff00'), 'tcolor' => variable_get('acciones_centralizadas_colort_moderada', '#000000'), 'texto' => variable_get('acciones_centralizadas_texto_moderada', 'Zona moderada'), ), 4 => array( 'color' => variable_get('acciones_centralizadas_color_optima', '#20ff21'), 'tcolor' => variable_get('acciones_centralizadas_colort_moderada', '#000000'), 'texto' => variable_get('acciones_centralizadas_texto_optima', 'Zona optima'), ), 5 => array( 'color' => variable_get('acciones_centralizadas_color_sejecucion', '#9966cd'), 'tcolor' => variable_get('acciones_centralizadas_colort_sejecucion', '#000000'), 'texto' => variable_get('acciones_centralizadas_texto_sejecucion', 'Sobre ejecución'), ), ); drupal_add_js($settings, 'setting'); drupal_set_title(t('Seguimiento y Control de Acción Específica de Acción Centralizada')); $form = array(); $format_number = array( 'decimals' => variable_get('acciones_centralizadas_number_decimals', 0), 'dec_point' => variable_get('acciones_centralizadas_number_dec_point', ','), 'thousands_sep' => variable_get('acciones_centralizadas_number_thousands_sep', '.'), ); $form['#format_number'] = array('format_number' => $format_number); drupal_add_js($form['#format_number'], 'setting'); $id_ref = $reformulacion_load ? $reformulacion_load->id_ref : 0; $variaciones = _acciones_centralizadas_reformula_all_partidas_load($node, $id_ref); $reformula = _acciones_centralizadas_reformula_load($node); $grupos = fieldgroup_groups('accion_centralizada'); $grupos_fields = array(); foreach($grupos as $id => $grupo) { if (count($grupo['fields'])) { foreach($grupo['fields'] as $id_field => $field) { if ($id_field == $campo['field']) { $grupos_fields = $grupos[$id]; } } } } $form['#field_load'] = content_fields($campo['field'], 'accion_centralizada'); $form['#grupo'] = $grupos_fields; $form['#ftypes'] = array( 'value' => t('January'), 'value_1' => t('February'), 'value_2' => t('March'), 'value_3' => t('April'), 'value_4' => t('May'), 'value_5' => t('June'), 'value_6' => t('July'), 'value_7' => t('August'), 'value_8' => t('September'), 'value_9' => t('Octuber'), 'value_10' => t('November'), 'value_11' => t('December'), ); $output = ''; $reformula = _acciones_centralizadas_reformula_load($node); $actual = _acciones_centralizadas_seguimiento_load($node, $campo['field'], $mes); $estado = (isset($actual['values']) && isset($actual['values']['estado'])) ? $actual['values']['estado'] : -1; $form['#state_creation'] = $estado; $form['#id_seg'] = (isset($actual['values']) && isset($actual['values']['id_seg'])) ? $actual['values']['id_seg'] : 0; //get first state if ($estado == -1 && module_exists('workflow')) { $wid = workflow_get_workflow_for_type('accion_centralizada'); if ($wid) { $form['#state_creation'] = _workflow_creation_state($wid); } } $comprometido = isset($actual['comprometido']) ? $actual['comprometido'] : array(); $causado = isset($actual['causado']) ? $actual['causado'] : array(); $pagado = isset($actual['pagado']) ? $actual['pagado'] : array(); $header = array(); $header[] = array('data' => t('Partida')); $header[] = array('data' => t('Asignado')); $header[] = array('data' => t('Comprometido')); $header[] = array('data' => t('Causado')); $header[] = array('data' => t('Pagado')); $header[] = array('data' => t('% de inversión')); $header[] = array('data' => t('Estatus de la inversión')); $header[] = array('data' => t('Información complementaria')); $grupos_form = array(); $valores = array(); $array = array( 'field_ac_ac1_ae1', 'field_ac_ac1_ae2', 'field_ac_ac2_ae2', 'field_ac_ac2_ae3', 'field_ac_ac3_ae1', 'field_ac_ac4_ae1', ); foreach($form['#ftypes'] as $id_field => $texto) { $valores[$id_field] = 0; } $partidas_nodo = array(); foreach ($array as $id) { if (count($node->{$id})) { foreach($node->{$id} as $partida) { if(!empty($partida['tid'])) { $partidas_nodo[$id][$partida['tid']] = $partida['tid']; } } } } if (count($variaciones)) { foreach($variaciones as $field_l => $partidas) { if (count($partidas)) { foreach($partidas as $tid => $partida) { if (!isset($partidas_nodo[$field_l][$tid])) { $valores['tid'] = $tid; $node->{$field_l}[] = $valores; if ($field_l == $campo['field']) { $campo['values'][] = $valores; } } } } } } $form['#acciones_centralizadas'] = $settings['acciones_centralizadas']; $form['#node'] = $node; $form['#campo'] = $campo; $form['#mes'] = $mes; if (count($reformula)) { foreach($reformula as $field_l => $partidas) { if (count($partidas)) { foreach($partidas as $tid => $partida) { if (!isset($partidas_nodo[$field_l][$tid])) { $valores['tid'] = $tid; $node->{$field_l}[] = $valores; if ($field_l == $campo['field']) { $campo['values'][] = $valores; } } } } } } foreach ($campo['values'] as $partida) { if ($partida['tid']) { $term = taxonomy_get_term($partida['tid']); // If this term's vocabulary supports localization. if (module_exists('i18ntaxonomy') && i18ntaxonomy_vocabulary($term->vid) == I18N_TAXONOMY_LOCALIZE) { $term->name = tt("taxonomy:term:$term->tid:name", $term->name); } $valor = $mes > 0 ? 'value_' . $mes : 'value'; $comprometidov = isset($comprometido[$campo['field']]) && isset($comprometido[$campo['field']][$partida['tid']]) ? $comprometido[$campo['field']][$partida['tid']][$valor] : 0; $causadov = isset($causado[$campo['field']]) && isset($causado[$campo['field']][$partida['tid']]) ? (float) $causado[$campo['field']][$partida['tid']][$valor] : 0; $pagadov = isset($pagado[$campo['field']]) && isset($pagado[$campo['field']][$partida['tid']]) ? (float) $pagado[$campo['field']][$partida['tid']][$valor] : 0; $varia = isset($variaciones[$campo['field']][$partida['tid']][$valor]) ? (float) $variaciones[$campo['field']][$partida['tid']][$valor] : 0; $sumaC += $comprometidov; $sumaCa += $causadov; $sumaP = $pagadov; $valor = (float) $partida[$valor]; $valor += (float) $varia; $suma += $valor; $zonacritica = $valor ? $causadov/$valor : -1; $porczonacritica = $zonacritica >= 0 ? number_format(($zonacritica * 100), $form['#format_number']['format_number']['decimals'], $form['#format_number']['format_number']['dec_point'], $form['#format_number']['format_number']['thousands_sep']) . '%' : -1; $form[$partida['tid'] . '_asignado'] = array( '#type' => 'textfield', '#default_value' => number_format($valor, $form['#format_number']['format_number']['decimals'], $form['#format_number']['format_number']['dec_point'], $form['#format_number']['format_number']['thousands_sep']), '#size' => 5, '#attributes' => array('class' => 'campo-asignado'), ); $disabled = $valor == 0 ? TRUE : FALSE; $disabled = FALSE; $form[$partida['tid'] . '_comprometido'] = array( '#type' => 'textfield', '#default_value' => $comprometidov, '#size' => 5, '#disabled' => $disabled, '#attributes' => array('onchange' => "valpositivo('" . $partida['tid'] . '-comprometido' . "');", 'class' => 'number'), ); $form[$partida['tid'] . '_causado'] = array( '#type' => 'textfield', '#default_value' => $causadov, '#size' => 5, '#disabled' => $disabled, '#attributes' => array('onchange' => "valpositivo('" . $partida['tid'] . '-causado' . "');calculaporc('" . $partida['tid'] . "');", 'class' => 'number'), ); $form[$partida['tid'] . '_pagado'] = array( '#type' => 'textfield', '#default_value' => $pagadov, '#size' => 5, '#disabled' => $disabled, '#attributes' => array('onchange' => "valpositivo('" . $partida['tid'] . '-pagado' . "');", 'class' => 'number'), ); $form[$partida['tid'] . '_porcen'] = array( '#type' => 'textfield', '#default_value' => $porczonacritica, '#size' => 5, '#attributes' => array('class' => 'campo-asignado'), ); } } $form['comentario'] = array( '#title' => t('Comentario'), '#type' => 'textarea', '#default_value' => '', ); $form['buttons'] = array( '#prefix' => '
', '#suffix' => '
', ); $form['buttons']['submit'] = array( '#type' => 'submit', '#value' => t('Guardar'), ); $redirect = isset($_GET['destination']) ? l('Cancelar', $_GET['destination']) : l('Cancelar', 'node/' . $form['#node']->nid . '/seguimiento/' . $form['#campo']['field'] . '/' . $form['#mes'] . '/view'); $form['buttons']['cancel'] = array('#value' => $redirect); return $form; } /* * Implementation of theme_acciones_centralizadas_seguimiento_tab_page_form() */ function theme_acciones_centralizadas_seguimiento_tab_page_form($form) { $meses = array( 0 => t('January'), 1 => t('February'), 2 => t('March'), 3 => t('April'), 4 => t('May'), 5 => t('June'), 6 => t('July'), 7 => t('August'), 8 => t('September'), 9 => t('Octuber'), 10 => t('November'), 11 => t('December'), ); $header = array(); $header[] = array('data' => t('Partida')); $header[] = array('data' => t('Asignado')); $header[] = array('data' => t('Comprometido')); $header[] = array('data' => t('Causado')); $header[] = array('data' => t('Pagado')); $header[] = array('data' => t('% de inversión')); $header[] = array('data' => t('Estatus de la inversión')); $campo = $form['#campo']; $rows = array(); foreach ($campo['values'] as $partida) { if ($partida['tid']) { $term = taxonomy_get_term($partida['tid']); // If this term's vocabulary supports localization. if (module_exists('i18ntaxonomy') && i18ntaxonomy_vocabulary($term->vid) == I18N_TAXONOMY_LOCALIZE) { $term->name = tt("taxonomy:term:$term->tid:name", $term->name); } $porczonacritica = $form[$partida['tid'] . '_porcen']['#value']; $colorzona = $form['#acciones_centralizadas'][0]['color']; $colorfontzona = $form['#acciones_centralizadas'][0]['tcolor']; $textozona = $form['#acciones_centralizadas'][0]['texto']; if ($porczonacritica >= 0 && $porczonacritica < 11) { $colorzona = $form['#acciones_centralizadas'][1]['color']; $textozona = $form['#acciones_centralizadas'][1]['texto']; $colorfontzona = $form['#acciones_centralizadas'][1]['tcolor']; } elseif ($porczonacritica >= 11 && $porczonacritica < 51) { $colorzona = $form['#acciones_centralizadas'][2]['color']; $textozona = $form['#acciones_centralizadas'][2]['texto']; $colorfontzona = $form['#acciones_centralizadas'][2]['tcolor']; } elseif ($porczonacritica >= 51 && $porczonacritica < 80) { $colorzona = $form['#acciones_centralizadas'][3]['color']; $textozona = $form['#acciones_centralizadas'][3]['texto']; $colorfontzona = $form['#acciones_centralizadas'][3]['tcolor']; } elseif ($porczonacritica >= 51 && $porczonacritica <= 100) { $colorzona = $form['#acciones_centralizadas'][4]['color']; $textozona = $form['#acciones_centralizadas'][4]['texto']; $colorfontzona = $form['#acciones_centralizadas'][4]['tcolor']; } elseif ($porczonacritica > 100) { $colorzona = $form['#acciones_centralizadas'][5]['color']; $textozona = $form['#acciones_centralizadas'][5]['texto']; $colorfontzona = $form['#acciones_centralizadas'][5]['tcolor']; } if ($porczonacritica < 0) { $porczonacritica = 'N/A'; $form[$partida['tid'] . '_porcen']['#value'] = 'N/A'; } $row = array(); $row[] = array('data' => $term->name,); $row[] = array('data' => drupal_render($form[$partida['tid'] . '_asignado']),); $row[] = array('data' => drupal_render($form[$partida['tid'] . '_comprometido']),); $row[] = array('data' => drupal_render($form[$partida['tid'] . '_causado']),); $row[] = array('data' => drupal_render($form[$partida['tid'] . '_pagado']),); $row[] = array('data' => drupal_render($form[$partida['tid'] . '_porcen']),); $row[] = array('data' => $textozona, 'style' => 'font-weight: bold;background:' . $colorzona . '; color:' . $colorfontzona, 'id' => $partida['tid'] . '-inversion-form',); $rows[] = $row; } } $output = ''; $grupo = explode('-', $form['#grupo']['label']); $output .= '
' . t('Datos de la Acción Centralizada a la que pertenece la acción especifica') . '' . '
' . t('Código de la AC:') . ' ' . $grupo[0] . '
' . '
' . t('Nombre de la AC:') . ' ' . $grupo[1] . '
' . '
'; $output .= '
' . t('Datos de la Acción') . '' . '
' . t('Nombre de la Acción Especifica:') . ' ' . $form['#field_load']['widget']['label'] . '
'. '
'; $output .= '
' . t('Seguimiento de partidas de la Acción Especifica') . '' . '
' . t('Mes de Seguimiento Actual:') . ' ' . $meses[$form['#mes']] . '
' . theme('table', $header, $rows) . '
'; //SE MUESTRA LA LEYENDA $output .= '

' . t('Nota: La relación entre las cantidades debe ser: \'Comprometido\' >= \'Causado\' >= \'Pagado\'') . '

'; $descripcion = array( 0 => '', 1 => '(' . t('De 0 a 10.99 %') . ')', 2 => '(' . t('De 11 a 50.99 %') . ')', 3 => '(' . t('De 51 a 79.99 %') . ')', 4 => '(' . t('De 80 a 100 %') . ')', 5 => '(' . t('Mas de 100 %') . ')', ); $output .= ''; for($i = 0; $i < 6; $i++) { $output .= ''; } $output .= '
' . $form['#acciones_centralizadas'][$i]['texto'] . ' ' . $descripcion[$i] . '' . '
'; $output .= drupal_render($form); return $output; } /* * Implementation of acciones_centralizadas_seguimiento_tab_page_form_validate() */ function acciones_centralizadas_seguimiento_tab_page_form_validate($form, &$form_state) { $acciones_centralizadas_path = drupal_get_path('module', 'acciones_centralizadas'); drupal_add_js($acciones_centralizadas_path . '/js/acciones_centralizadas.js'); drupal_add_js($form['#format_number'], 'setting'); $settings['acciones_centralizadas'] = array( 0 => array( 'color' => variable_get('acciones_centralizadas_color_default', '#633303'), 'tcolor' => variable_get('acciones_centralizadas_colort_default', '#FFFFFF'), 'texto' => variable_get('acciones_centralizadas_texto_default', 'No hay planificación'), ), 1 => array( 'color' => variable_get('acciones_centralizadas_color_critica', '#fd0002'), 'tcolor' => variable_get('acciones_centralizadas_colort_critica', '#FFFFFF'), 'texto' => variable_get('acciones_centralizadas_texto_critica', 'Zona crítica'), ), 2 => array( 'color' => variable_get('acciones_centralizadas_color_discreta', '#cc6733'), 'tcolor' => variable_get('acciones_centralizadas_colort_discreta', '#FFFFFF'), 'texto' => variable_get('acciones_centralizadas_texto_discreta', 'Zona discreta'), ), 3 => array( 'color' => variable_get('acciones_centralizadas_color_moderada', '#fdff00'), 'tcolor' => variable_get('acciones_centralizadas_colort_moderada', '#000000'), 'texto' => variable_get('acciones_centralizadas_texto_moderada', 'Zona moderada'), ), 4 => array( 'color' => variable_get('acciones_centralizadas_color_optima', '#20ff21'), 'tcolor' => variable_get('acciones_centralizadas_colort_moderada', '#000000'), 'texto' => variable_get('acciones_centralizadas_texto_optima', 'Zona optima'), ), 5 => array( 'color' => variable_get('acciones_centralizadas_color_sejecucion', '#9966cd'), 'tcolor' => variable_get('acciones_centralizadas_colort_sejecucion', '#000000'), 'texto' => variable_get('acciones_centralizadas_texto_sejecucion', 'Sobre ejecución'), ), ); drupal_add_js($settings, 'setting'); foreach ($form['#campo']['values'] as $partida) { $start = $form_state['values'][$partida['tid'] . '_comprometido']; $value = preg_replace('@[^-0-9]@', '', $start); if ($start != $value) { form_set_error($partida['tid'] . '_comprometido', t('Solo números enteros son permitidos.')); } if ($form_state['values'][$partida['tid'] . '_comprometido'] < 0) { form_set_error($partida['tid'] . '_comprometido', t('El valor comprometido deberia ser mayor o igual a cero')); } $start = $form_state['values'][$partida['tid'] . '_causado']; $value = preg_replace('@[^-0-9]@', '', $start); if ($start != $value) { form_set_error($partida['tid'] . '_causado', t('Solo números enteros son permitidos.')); } if ($form_state['values'][$partida['tid'] . '_causado'] < 0) { form_set_error($partida['tid'] . '_causado', t('El valor causado deberia ser mayor o igual a cero')); } $start = $form_state['values'][$partida['tid'] . '_pagado']; $value = preg_replace('@[^-0-9]@', '', $start); if ($start != $value) { form_set_error($partida['tid'] . '_pagado', t('Solo números enteros son permitidos.')); } if ($form_state['values'][$partida['tid'] . '_pagado'] < 0) { form_set_error($partida['tid'] . '_pagado', t('El valor pagado deberia ser mayor o igual a cero')); } //se valida que comprometido sea mayor o igual que causado if ($form_state['values'][$partida['tid'] . '_comprometido'] < $form_state['values'][$partida['tid'] . '_causado']) { form_set_error($partida['tid'] . '_causado', t('El valor causado deberia ser menor o igual al comprometido')); } //se valida que comprometido sea mayor o igual que causado if ($form_state['values'][$partida['tid'] . '_causado'] < $form_state['values'][$partida['tid'] . '_pagado']) { form_set_error($partida['tid'] . '_causado', t('El valor pagado deberia ser menor o igual al causado')); } } } /* * Implementation of acciones_centralizadas_seguimiento_tab_page_form_submit() */ function acciones_centralizadas_seguimiento_tab_page_form_submit($form, &$form_state) { global $user; db_query("INSERT INTO {accion_seguimiento} (nid, mes, comentario, campo, fecha, estado, uid) VALUES (%d, %d, '%s', '%s', %d, %d, %d)", $form['#node']->nid, $form['#mes'], check_plain($form_state['values']['comentario']), $form['#campo']['field'], time(), $form['#state_creation'], $user->uid); $id_seg = db_last_insert_id('accion_seguimiento', 'id_seg'); foreach ($form['#campo']['values'] as $partida) { $suma = $form_state['values'][$partida['tid'] . '_comprometido'] + $form_state['values'][$partida['tid'] . '_causado'] +$form_state['values'][$partida['tid'] . '_pagado']; if ($partida['tid']) { db_query("INSERT INTO {accion_segu_partida} (id_seg, partida, comprometido, causado, pagado, nid) VALUES (%d, %d, %f, %f, %f, %d)", $id_seg, $partida['tid'], $form_state['values'][$partida['tid'] . '_comprometido'], $form_state['values'][$partida['tid'] . '_causado'], $form_state['values'][$partida['tid'] . '_pagado'], $form['#node']->nid); } } //herede los estados anteriores del seguimiento if ($form['#id_seg']) { db_query('UPDATE {accion_seguimiento_state} SET id_seg = %d WHERE id_seg = %d', $id_seg, $form['#id_seg']); } if (!$_REQUEST['destination']) { // add redirect $form_state['redirect'] = 'node/' . $form['#node']->nid . '/seguimiento/' . $form['#campo']['field'] . '/' . $form['#mes'] . '/view'; } } /* * Implementation of hook_form_alter() */ function acciones_centralizadas_form_alter(&$form, $form_state, $form_id) { if ($form_id == 'workflow_tab_form') { if (isset($form['#wf']->name) && isset($form['workflow'][$form['#wf']->name]['#options'])) { $form['workflow'][$form['#wf']->name]['#title'] = t('Enviar a'); } } if (isset($form['type']) && isset($form['#node']) && $form['type']['#value'] .'_node_form' == $form_id && $form['type']['#value'] == 'accion_centralizada'){ //just remove title field $form['buttons']['#weight'] = 1200; $form['title']['#value'] = 'Accion Centralizada'; $form['title']['#type'] = 'value'; $form['title']['#required'] = FALSE; $form['buttons']['#prefix'] = '
'; $form['buttons']['#suffix'] = '
'; $form['buttons']['preview']['#access'] = FALSE; $form['buttons']['cancel'] = array('#weight' => 120, '#value' => l('Cancelar', 'node/' . $form['#node']->nid)); if (isset($form['#node']->nid)){ $form['field_acciones_ente']['#access'] = FALSE; } else{ $form['field_acciones_ente']['#pre_render'][] = 'acciones_centralizadas_nodereference_field_pre_render'; } } } /* * Implementation of acciones_centralizadas_nodereference_field_pre_render() * Change element */ function acciones_centralizadas_nodereference_field_pre_render($element) { global $user; if (!((user_access('edit all planificador'))||(user_access('admin planificador')))) { $entes = obtener_mis_ente_planificador($user->uid); $options = array(); if (count($entes)) { foreach($entes as $ente){ $options[$ente['nid']] = $element['nid']['nid']['#options'][$ente['nid']]; } } $element['nid']['nid']['#options'] = $options; } else { $options = $element['nid']['nid']['#options']; $result = db_query("SELECT ac.ente AS nid FROM {accion_centralizada} AS ac INNER JOIN {workflow_node} AS w ON w.nid = ac.nid WHERE year = %d AND w.sid <> %d", variable_get('acciones_centralizadas_anho_creacion', 0), variable_get('acciones_centralizadas_state_naprobado', NULL)); while($ente = db_fetch_object($result)) { if (isset($options[$ente->nid])) { unset($options[$ente->nid]); } } $element['nid']['nid']['#options'] = $options; } return $element; } /* * Implementation of acciones_centralizadas_reformula_wk_tab_page_form() */ function acciones_centralizadas_reformula_wk_tab_page_form($form_state, $node, $reformulacion_load = 0, $state = 0) { $estados = _acciones_centralizadas_reformula_obtiene_estados(); $form = array(); $form['#node'] = $node; $form['#nuevo_estado'] = $state; $form['#estados'] = $estados['states']; $form['#reformulacion'] = $reformulacion_load; $form['comentario'] = array( '#title' => t('Comentario'), '#type' => 'textarea', '#default_value' => '', ); $message = t('Esta seguro de cambiar la reformulación al estado %nombre_estado?', array('%nombre_estado' => $estados['states'][$state])); $caption = '

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

'; $return_path = 'node/' . $node->nid . '/reformular/' . $reformulacion_load->id_ref . '/view'; return confirm_form($form, $message, $return_path, $caption, t('Cambiar')); return $form; } /** * Implementation of acciones_centralizadas_reformula_wk_tab_page_form_submit(). * Process funcion delete confirm form. */ function acciones_centralizadas_reformula_wk_tab_page_form_submit($form, &$form_state) { global $user; $nuevo_estado = $form['#datos_institucionales_funcion']; db_query('UPDATE {accion_reformular} SET estado = %d, estado_ant = %d WHERE nid = %d AND id_ref = %d', $form['#nuevo_estado'], $form['#reformulacion']->estado, $form['#node']->nid, $form['#reformulacion']->id_ref); db_query("INSERT INTO {accion_reformular_state} (nid, estado, estado_ant, comentario, date, id_ref, uid) VALUES (%d, %d, %d, '%s', %d, %d, %d)", $form['#node']->nid, $form['#nuevo_estado'], $form['#reformulacion']->estado, check_plain($form_state['values']['comentario']), time(), $form['#reformulacion']->id_ref, $user->uid); //REMOVE DATA drupal_set_message(t('La reformulación fue cambiada al estado @nombre_estado', array('@nombre_estado' => $form['#estados'][$form['#nuevo_estado']]))); $form_state['redirect'] = 'node/' . $form['#node']->nid . '/reformular/' . $form['#reformulacion']->id_ref . '/view'; } /* * Implementation of _acciones_centralizadas_seguimiento_wk_node_tab_mes_access() */ function _acciones_centralizadas_seguimiento_wk_node_tab_mes_access($node, $campo = '', $mes = 0, $state = 0) { global $user; $actual = _acciones_centralizadas_seguimiento_load($node, $campo['field'], $mes); if (!isset($actual['values'])) { return FALSE; } $estado = (isset($actual['values']) && isset($actual['values']['estado'])) ? $actual['values']['estado'] : -1; $year = variable_get('acciones_centralizadas_anho_seguimiento', 0); $estado_aprobado = variable_get('acciones_centralizadas_state_aprobado', NULL); if ($node->type != 'accion_centralizada' || $node->anhoaccion_centralizada != $year) { if ($estado_aprobado && $node->_workflow != $estado_aprobado) { return FALSE; } } $ente = usuario_tiene_ente($user->uid); $ente_planificador = node_load($node->field_acciones_ente[0]['nid']); if ($ente->nid != $ente_planificador->nid && !user_access('admin planificador')) { return FALSE; } $estado_aprobado = variable_get('acciones_centralizadas_state_aprobado', NULL); $estado_naprobado = variable_get('acciones_centralizadas_state_naprobado', NULL); if ($estado == $estado_naprobado || $estado == $estado_aprobado) { return FALSE; } $states = _acciones_centralizadas_reformula_obtiene_estados(); $first_state = 0; if ($states['wid']) { $first_state = _workflow_creation_state($states['wid']); } $roles = array_keys($user->roles); if ($user->uid == 1) { // Superuser is special. $roles_transition = 'ALL'; } else { $roles_transition = $roles; if ($user->uid == $actual['values']['uid'] && $actual['values']['uid'] > 0) { $roles_transition += array('author' => 'author'); } } $transitions = array(); if ($states['wid']) { $transitions = workflow_allowable_transitions($estado, 'to', $roles_transition); } if ($first_state && $estado == $first_state) { unset($transitions[$estado]); } if (isset($transitions[$state])) { return TRUE; } return FALSE; } /* * Implementation of acciones_centralizadas_seguimiento_wk_tab_page_form() */ function acciones_centralizadas_seguimiento_wk_tab_page_form($form_state, $node, $campo = '', $mes = 0, $state) { $estados = _acciones_centralizadas_reformula_obtiene_estados(); $actual = _acciones_centralizadas_seguimiento_load($node, $campo['field'], $mes); $form = array(); $form['#node'] = $node; $form['#actual'] = $actual['values']; $form['#nuevo_estado'] = $state; $form['#estados'] = $estados['states']; $form['#campo'] = $campo; $form['#mes'] = $mes; $form['comentario'] = array( '#title' => t('Comentario'), '#type' => 'textarea', '#default_value' => '', ); $message = t('Esta seguro de cambiar el seguimiento al estado %nombre_estado?', array('%nombre_estado' => $estados['states'][$state])); $caption = '

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

'; $return_path = 'node/' . $node->nid . '/seguimiento/' . $form['#campo']['field'] . '/' . $form['#mes'] . '/view'; return confirm_form($form, $message, $return_path, $caption, t('Cambiar')); } /** * Implementation of acciones_centralizadas_seguimiento_wk_tab_page_form_submit(). * Process funcion delete confirm form. */ function acciones_centralizadas_seguimiento_wk_tab_page_form_submit($form, &$form_state) { global $user; $nuevo_estado = $form['#datos_institucionales_funcion']; db_query('UPDATE {accion_seguimiento} SET estado = %d, estado_ant = %d WHERE nid = %d AND id_seg = %d', $form['#nuevo_estado'], $form['#actual']['estado'], $form['#node']->nid, $form['#actual']['id_seg']); db_query("INSERT INTO {accion_seguimiento_state} (nid, estado, estado_ant, comentario, date, id_seg, uid) VALUES (%d, %d, %d, '%s', %d, %d, %d)", $form['#node']->nid, $form['#nuevo_estado'], $form['#actual']['estado'], check_plain($form_state['values']['comentario']), time(), $form['#actual']['id_seg'], $user->uid); drupal_set_message(t('El seguimiento fue cambiado al estado @nombre_estado', array('@nombre_estado' => $form['#estados'][$form['#nuevo_estado']]))); $form_state['redirect'] = 'node/' . $form['#node']->nid . '/seguimiento/' . $form['#campo']['field'] . '/' . $form['#mes'] . '/view'; } /* * Implementation of acciones_centralizadas_search_ac_display() */ function acciones_centralizadas_search_ac_display() { global $user; $current_time = time(); $ente = usuario_tiene_ente($user->uid); $tipo_plan = 'acciones_centralizadas_formular'; $ente_planificador = 0; if ($ente && $ente->nid) { $ente_planificador = ente_planificador_leer_ente_planificadores($ente->nid); } elseif (user_access('admin planificador') && $enteagregar) { $ente_planificador = ente_planificador_leer_ente_planificadores($enteagregar); } $mi_fecha = ente_planificador_user_acceso_proceso($tipo_plan, $ente_planificador); $fecha = FALSE; if ($mi_fecha[1] + 86399 > $current_time && $mi_fecha[0] < $current_time) { $fecha = TRUE; } if (!$fecha) { muestra_mensaje($tipo_plan, $ente_planificador); } if ($fecha && $user->entes) { muestra_mensaje($tipo_plan, $ente_planificador); $result = db_query("SELECT ac.nid FROM {accion_centralizada} AS ac INNER JOIN {workflow_node} AS w ON w.nid = ac.nid WHERE ac.ente = %d AND year = %d AND w.sid <> %d", $user->entes, variable_get('acciones_centralizadas_anho_creacion', 0), variable_get('acciones_centralizadas_state_naprobado', NULL)); $acciones_centralizadas = db_fetch_object($result); $fecha = !$acciones_centralizadas; } elseif($fecha && user_access('admin planificador')) { $entes = array(); $result = db_query('SELECT e.nid FROM {ente_planificador} AS e INNER JOIN {node} AS n ON n.nid = e.nid WHERE n.status = 1'); while($ente = db_fetch_object($result)) { $entes[$ente->nid] = $ente->nid; } $result = db_query("SELECT ac.ente as nid FROM {accion_centralizada} AS ac INNER JOIN {workflow_node} AS w ON w.nid = ac.nid WHERE year = %d AND w.sid <> %d", variable_get('acciones_centralizadas_anho_creacion', 0), variable_get('acciones_centralizadas_state_naprobado', NULL)); while($ente = db_fetch_object($result)) { if (isset($entes[$ente->nid])) { unset($entes[$ente->nid]); } } $fecha = count($entes); } $states = array(); $first_state = 0; if (module_exists('workflow')) { $states = _acciones_centralizadas_reformula_obtiene_estados(); if ($states['wid']) { $first_state = _workflow_creation_state($states['wid']); } } $output = drupal_get_form('acciones_centralizadas_search_ac_form'); $inputs = array(); $sql = ''; if (!user_access('admin planificador') && $user->entes) { $inputs[] = $user->entes; $inputs[] = variable_get('acciones_centralizadas_state_naprobado', NULL); $sql .= "SELECT ac.nid, ac.year, w.sid, n.created, u.name, n.uid, e.title AS ente FROM {accion_centralizada} AS ac INNER JOIN {node} AS n ON n.nid = ac.nid INNER JOIN {users} AS u ON u.uid = n.uid INNER JOIN {node} as e ON e.nid = ac.ente INNER JOIN {workflow_node} AS w ON w.nid = ac.nid WHERE ac.ente = %d AND w.sid <> %d"; } elseif (user_access('admin planificador')) { $inputs[] = variable_get('acciones_centralizadas_state_naprobado', NULL); $sql .= "SELECT ac.nid, ac.year, ac.ente, w.sid, n.created, u.name, n.uid, e.title AS enten FROM {accion_centralizada} AS ac INNER JOIN {node} AS n ON n.nid = ac.nid INNER JOIN {users} AS u ON u.uid = n.uid INNER JOIN {node} as e ON e.nid = ac.ente INNER JOIN {workflow_node} AS w ON w.nid = ac.nid WHERE w.sid <> %d"; $acciones_centralizadas_search_ac_ente = isset($_SESSION['acciones_centralizadas']) && isset($_SESSION['acciones_centralizadas']['ente']) ? $_SESSION['acciones_centralizadas']['ente'] : 0; if ($acciones_centralizadas_search_ac_ente) { $inputs[] = $acciones_centralizadas_search_ac_ente; $sql .= ' AND ac.ente = %d'; } } $acciones_centralizadas_search_ac_anho_creacion = isset($_SESSION['acciones_centralizadas']) && isset($_SESSION['acciones_centralizadas']['anho']) ? $_SESSION['acciones_centralizadas']['anho'] : 0; if ($acciones_centralizadas_search_ac_anho_creacion) { $sql .= ' AND ac.year = %d'; $inputs[] = $acciones_centralizadas_search_ac_anho_creacion; } $sql .= ' ORDER BY ac.year DESC, ac.ente'; $header = array(); $cab = 6; if (user_access('admin planificador')) { $header[] = array('data' => t('Ente.')); $cab++; } $header[] = array('data' => t('Año')); $header[] = array('data' => t('Estado')); $header[] = array('data' => t('Fecha de creación')); $header[] = array('data' => t('Autor')); $header[] = array('data' => t('Acción')); $result = db_query($sql, $inputs); $rows = array(); while($ac = db_fetch_object($result)) { $row = array(); if (user_access('admin planificador')) { $row[] = array('data' => l($ac->enten, 'node/' . $ac->ente),); } $row[] = array('data' => $ac->year,); $estad0 = $ac->sid == $first_state? t('Ingresado') : $states['states'][$ac->sid]; $row[] = array('data' => $estad0,); $row[] = array('data' => format_date($ac->created),); $row[] = array('data' => l($ac->name, 'user/' . $ac->uid),); $links = array(); drupal_alter('acciones_obtiene_links', $links, $ac, $fecha); $row[] = array('data' => theme('item_list', $links),); $rows[] = $row; } if (!count($rows)) { $row[] = array('data' => 'No existen Acciones centralizadas', 'colspan' => $cab); $rows[] = $row; } $output .= theme('table', $header, $rows); if ($fecha) { $output .= '

' . l('Agregar Acción Centralizada', 'node/add/accion-centralizada') . '

'; } return $output; } /* * Implementation of hook_acciones_obtiene_links_alter() */ function acciones_centralizadas_acciones_obtiene_links_alter(&$links, $accion_centralizada, $acceso = FALSE) { $node_accion = node_load($accion_centralizada->nid); if(node_access('view', $node_accion)){ $links[] = array( 'data' => l(t('Consultar'), 'node/' . $accion_centralizada->nid), 'class' => 'acciones-centralizadas-ver', ); } if(node_access('create', $node_accion)){ $links[] = array( 'data' => l(t('Crear Acción Centralizada'), 'node/add'), 'class' => 'acciones-centralizadas-agregar', ); } if(node_access('update', $node_accion)){ $links[] = array( 'data' => l(t('Modificar'), 'node/' . $accion_centralizada->nid . '/edit'), 'class' => 'acciones-centralizadas-modificar', ); } if(node_access('delete', $node_accion)){ $links[] = array( 'data' => l(t('Eliminar'), 'node/' . $accion_centralizada->nid . '/delete'), 'class' => 'acciones-centralizadas-eliminar', ); } if (workflow_node_tab_access($node_accion)) { $links[] = array( 'data' => l(t('Cambiar el estado'), 'node/' . $accion_centralizada->nid . '/workflow'), 'class' => 'proyectos-operativos-estado', ); } if (_acciones_centralizadas_reformula_node_tab_access($node_accion)) { $links[] = array( 'data' => l(t('Fase de reformulación'), 'node/' . $accion_centralizada->nid . '/reformular'), 'class' => 'acciones-centralizadas-reformular', ); } if (_acciones_centralizadas_reformula_node_add_tab_access($node_accion)) { $links[] = array( 'data' => l(t('Agregar nueva reformulación'), 'node/' . $accion_centralizada->nid . '/reformular/add'), 'class' => 'acciones-centralizadas-reformular', ); } if (_acciones_centralizadas_seguimiento_node_tab_access($node_accion)) { $meses = array( 0 => t('January'), 1 => t('February'), 2 => t('March'), 3 => t('April'), 4 => t('May'), 5 => t('June'), 6 => t('July'), 7 => t('August'), 8 => t('September'), 9 => t('Octuber'), 10 => t('November'), 11 => t('December'), ); $year = variable_get('acciones_centralizadas_anho_seguimiento', 0); $mes_segu = variable_get('acciones_centralizadas_mes_seguimiento', 0) - 1; if ($year == $node_accion->anhoaccion_centralizada) { $links[] = array( 'data' => l(t('Fase de Seguimiento (@mes)', array('@mes' => $meses[$mes_segu])), 'node/' . $accion_centralizada->nid . '/seguimiento/fase/' . $mes_segu), 'class' => 'acciones-centralizadas-fase-seguimiento', ); } $links[] = array( 'data' => l(t('Seguimiento de la AC'), 'node/' . $accion_centralizada->nid . '/seguimiento'), 'class' => 'acciones-centralizadas-seguimiento', ); } } /* * Implementation of acciones_centralizadas_search_ac_form() */ function acciones_centralizadas_search_ac_form($form_state) { $form = array(); if (user_access('admin planificador')) { $entes = array(); $result = db_query('SELECT e.nid, n.title FROM {ente_planificador} AS e INNER JOIN {node} AS n ON n.nid = e.nid WHERE n.status = 1'); $entes[] = t('Todos'); while($ente = db_fetch_object($result)) { $entes[$ente->nid] = $ente->title; } $acciones_centralizadas_search_ac_ente = isset($_SESSION['acciones_centralizadas']) && isset($_SESSION['acciones_centralizadas']['ente']) ? $_SESSION['acciones_centralizadas']['ente'] : 0; $form['acciones_centralizadas_search_ac_ente'] = array( '#title' => t('Ente Planificador'), '#type' => 'select', '#default_value' => $acciones_centralizadas_search_ac_ente, '#options' => $entes, ); } $current_year = date("Y"); $years = array(); $years[] = t('Todos'); for($i = $current_year - 10; $i <= $current_year; $i++) { $years[$i] = $i; } $acciones_centralizadas_search_ac_anho_creacion = isset($_SESSION['acciones_centralizadas']) && isset($_SESSION['acciones_centralizadas']['anho']) ? $_SESSION['acciones_centralizadas']['anho'] : 0; $form['acciones_centralizadas_search_ac_anho_creacion'] = array( '#title' => t('Acción centralizada para el año'), '#type' => 'select', '#default_value' => $acciones_centralizadas_search_ac_anho_creacion, '#options' => $years, ); $form['buttons'] = array( '#prefix' => '
', '#suffix' => '
', ); $form['buttons']['submit'] = array( '#type' => 'submit', '#value' => t('Buscar'), ); return $form; } /* * Implementation of acciones_centralizadas_search_ac_form_submit() */ function acciones_centralizadas_search_ac_form_submit($form, &$form_state) { $_SESSION['acciones_centralizadas'] = array(); if (user_access('admin planificador')) { $_SESSION['acciones_centralizadas']['ente'] = $form_state['values']['acciones_centralizadas_search_ac_ente']; } $_SESSION['acciones_centralizadas']['anho'] = $form_state['values']['acciones_centralizadas_search_ac_anho_creacion']; } /** * Implementation of hook_planner_items_toolbar(). */ function acciones_centralizadas_planner_items_toolbar($ente_planificador, $handler_icon) { $link = array(); $icon_path = entes_planificadores_toolbar_get_icon_path('planner', 'accionescentralizadas', $handler_icon); $link[] = array( 'path' => 'acciones_centralizadas', 'icon_path' => $icon_path, 'icon' => theme('image', $icon_path, t('Consultar Información de las acciones centralizadas del actor planificador'), t('Consultar Información de los acciones centralizadas del actor planificador'), array('class' => 'handler-icon-' . $handler_icon)), 'title' => t('Proyectos operativos'), 'description' => t('Consultar Información de las acciones centralizadas del actor planificador'), 'category' => 'planner', ); return $link; } /** * Implementation of hook_admin_items_toolbar(). */ function acciones_centralizadas_admin_items_toolbar($handler_icon) { $link = array(); $icon_path = entes_planificadores_toolbar_get_icon_path('admin', 'accionescentralizadas', $handler_icon); $link[] = array( 'path' => 'acciones_centralizadas', 'icon_path' => $icon_path, 'icon' => theme('image', $icon_path, t('Consultar Información de las acciones centralizadas del actor planificador'), t('Consultar Información de los acciones centralizadas del actor planificador'), array('class' => 'handler-icon-' . $handler_icon)), 'title' => t('Proyectos operativos'), 'description' => t('Consultar Información de las acciones centralizadas del actor planificador'), 'category' => 'planner', ); return $link; } function acciones_centralizadas_seguimiento_nodo_fase_seguimiento($node, $mes = 0) { global $user; $estado_aprobado = variable_get('acciones_centralizadas_state_aprobado', NULL); $estado_naprobado = variable_get('acciones_centralizadas_state_naprobado', NULL); $year = variable_get('acciones_centralizadas_anho_seguimiento', 0); $mes_segu = variable_get('acciones_centralizadas_mes_seguimiento', 0); $meses = array( 0 => t('January'), 1 => t('February'), 2 => t('March'), 3 => t('April'), 4 => t('May'), 5 => t('June'), 6 => t('July'), 7 => t('August'), 8 => t('September'), 9 => t('Octuber'), 10 => t('November'), 11 => t('December'), ); $ftypes = array( 'value' => t('January'), 'value_1' => t('February'), 'value_2' => t('March'), 'value_3' => t('April'), 'value_4' => t('May'), 'value_5' => t('June'), 'value_6' => t('July'), 'value_7' => t('August'), 'value_8' => t('September'), 'value_9' => t('Octuber'), 'value_10' => t('November'), 'value_11' => t('December'), ); $mes_texto = $meses[$mes]; $array = array( 'field_ac_ac1_ae1' => 'field_ac_ac1_ae1', 'field_ac_ac1_ae2' => 'field_ac_ac1_ae2', 'field_ac_ac2_ae2' => 'field_ac_ac2_ae2', 'field_ac_ac2_ae3' => 'field_ac_ac2_ae3', 'field_ac_ac3_ae1' => 'field_ac_ac3_ae1', 'field_ac_ac4_ae1' => 'field_ac_ac4_ae1', ); $id_ref = $reformulacion_load ? $reformulacion_load->id_ref : 0; $variaciones = _acciones_centralizadas_reformula_all_partidas_load($node, $id_ref); $reformula = _acciones_centralizadas_reformula_load($node); $valores = array(); foreach($ftypes as $id_field => $texto) { $valores[$id_field] = 0; } $vacio = array(); $partidas_nodo = array(); foreach ($array as $id) { if (!$node->{$id}[0]['tid']) { $node->{$id} = array(); } if (count($node->{$id})) { foreach($node->{$id} as $partida) { if(!empty($partida['tid'])) { $partidas_nodo[$id][$partida['tid']] = $partida['tid']; } } } } if (count($variaciones)) { foreach($variaciones as $field_l => $partidas) { if (count($partidas)) { foreach($partidas as $tid => $partida) { if (!isset($partidas_nodo[$field_l][$tid])) { if (empty($node->{$field_l}[0]['tid']) || !$node->{$field_l}[0]['tid']) { $node->{$field_l} = array(); } $valores['tid'] = $tid; $node->{$field_l}[] = $valores; $partidas_nodo[$field_l][$tid] = $tid; } } } } } $header = array(); $header[] = array('data' => t('Mes'), 'align' => 'center'); $header[] = array('data' => t('Estado'), 'align' => 'center', 'colspan' => 2); $header[] = array('data' => t('Opciones Disponibles'), 'align' => 'center'); $grupos = fieldgroup_groups('accion_centralizada'); $output = t('Estimado(a) Usuario(a), para ingresar el Seguimiento de las Acciones Centralizadas.'); $states = _acciones_centralizadas_reformula_obtiene_estados(); if (module_exists('workflow')) { if (isset($states['wid'])) { $first_state = 0; if ($states['wid']) { $first_state = _workflow_creation_state($states['wid']); } if ($user->uid == 1) { // Superuser is special. $roles = 'ALL'; } else { $roles = array_keys($user->roles); if ($user->uid == $author && $author > 0) { $roles += array('author' => 'author'); } } } } $mensaje = ''; if ($mes != $mes_segu -1 || $node->anhoaccion_centralizada != $year) { $mensaje = '
' . t('Nota complementaria') . ': ' . t('Mes fuera del período de duración de la acción centralizada.') . '
'; } $mensaje .= t('Para consultar las partidas de esta Acción Centralizada en el mes actual ir a '); foreach($grupos as $id => $grupo) { $tablas = array(); if (count($grupo['fields'])) { foreach($grupo['fields'] as $id_field => $field) { $suma = array(); if (array_key_exists($id_field, $array) && $node->{$id_field}[0]['tid']) { foreach($node->{$id_field} as $values) { foreach($ftypes as $ids =>$texto) { if (!isset($suma[$ids])) { $suma[$ids] = 0; } $varia[$id_field][$values['tid']][$ids] = isset($variaciones[$id_field][$values['tid']][$ids]) ? $variaciones[$id_field][$values['tid']][$ids] : 0; $valor = $values[$ids] + $varia[$id_field][$values['tid']][$ids]; $suma[$ids] += $valor; } } } $field_load = content_fields($id_field, 'accion_centralizada'); $rows = array(); $actual = _acciones_centralizadas_seguimiento_load($node, $id_field, $mes); $current_estado = isset($actual['values']) && isset($actual['values']['estado']) ? $actual['values']['estado'] : -1; $row = array(); $estado = isset($states['states'][$current_estado]) ? $states['states'][$current_estado] : t('No ingresado'); $row[] = array('data' => $mes_texto, 'align' => 'center',); $etiquetas = isset($states['states'][$current_estado]) ? '
' : '-'; $row[] = array('data' => $etiquetas, 'align' => 'center',); $row[] = array('data' => $estado, 'align' => 'center',); $links = array(); $transitions = array(); $texto_value = $mes == 0 ? 'value' : 'value_' . $mes; if (_acciones_centralizadas_seguimiento_node_tab_mes_access($node, $id_field, $mes)) { $links[] = l(t('Modificar seguimiento'), 'node/' . $node->nid . '/seguimiento/' . $id_field . '/' . $mes . '/edit', array('query' => array('destination' => $_GET['q']))); } if ($states['wid']) { $transitions = workflow_allowable_transitions($current_estado, 'to', $roles); } unset($transitions[$current_estado]); if (count($transitions) && $estado_aprobado != $current_estado) { foreach($transitions as $id => $transition) { $links[] = l(t('Enviar a @state', array('@state' => $transition)), 'node/' . $node->nid . '/seguimiento/' . $id_field . '/' . $mes . '/workflow/' . $id, array('query' => array('destination' => $_GET['q']))); } } $row[] = array('data' => theme('item_list', $links),); $rows[] = $row; $tablas[]= '
' . $field_load['widget']['label'] . '
' . theme('table', $header, $rows) . $mensaje . l(t('Seguimiento de la Acción Centralizada'), 'node/' . $node->nid . '/seguimiento/' . $id_field . '/' . $mes . '/view') . '
'; } } if (count($tablas)) { $output .= '
' . $grupo['label'] . '' . implode('', $tablas). '
'; } } if ($output == '') { $output .= t('La acción Centralizada no tiene partidas asignadas.'); } return $output; }