source: sipes/0.3-modules/gestion_mensajes/gestion_mensajes.module @ 438bcea

stableversion-3.0
Last change on this file since 438bcea was 303fae2, checked in by José Gregorio Puentes <jpuentes@…>, 9 años ago

se agregaron los modulos

  • Propiedad mode establecida a 100755
File size: 29.5 KB
Línea 
1<?php
2  /**
3  * Sistema Automatizado para la Planificación Estratégico-Situacional en la Administración Pública Venezolana
4  * @file gestion_mensajes.module
5  * Drupal part Module to code proyectos operativos module
6  * Copyright 2012 Sistema Automatizado para la Planificación Estratégico-Situacional en la Administración Pública Venezolana (CENDITEL)
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
21  *
22  * @author CENDITEL Merida - Ing. Diego Uzcategui
23  * @date 2013-04-15 // (anno-mes-dia)
24  * @version 0.1
25  *
26  */
27
28/*
29 * Implementation of hook_help()
30 */
31function gestion_mensajes_help($path, $arg) {
32    switch ($path) {
33        case "admin/help/aeproyectoseguimiento":
34        $output = '<p>'.  t("Este modulo se encarga de mostrar los mensajes generados por los cambios de estados") .'</p>';
35            break;
36    }
37    return $output;
38} // function gestion_mensajes_help
39
40/*
41 * Implementation of hook_menu()
42 */
43function gestion_mensajes_menu() {
44  $items = array();
45 
46  $items['ver_lista_de_mensajes_recibidos/%identif_usuario'] = array(
47    'title' => 'Mis Mensajes',
48    'type' => MENU_CALLBACK,
49    'access callback' => '_bandeja_entrada_access',
50    'access arguments' => array(1),
51    'page callback' => 'mis_mensajes_sipp_page',
52    'page arguments' => array(1),
53    'weight' => 2,
54  );
55 
56  $items['ver_mensaje/%identif_msj'] = array(
57    'title' => 'Mensaje',
58    'type' => MENU_CALLBACK,
59    'access callback' => '_gestion_mensajes_access',
60    'page callback' => 'ver_el_mensaje_sipp_page',
61    'page arguments' => array(1),
62    'weight' => 2,
63  );
64
65  return $items;
66}
67
68//**************************************************************************************************************************************************
69//permisos de acceso a las paginas
70
71/**
72 * verificar ...
73 */
74function _gestion_mensajes_access() {
75  return true;
76} // function _gestion_mensajes_access
77
78/**
79 * verificar ...
80 */
81function _bandeja_entrada_access($id_usuario) {
82  global $user;
83  if(($user->uid ==1) || ($user->uid == $id_usuario)){
84    return true;
85  }
86  return false;
87} // function _gestion_mensajes_access
88
89//carga de campos en las urls
90/**
91 * Implementation of identif_msj_load().
92 * Menu loader callback. Load a mes.
93 */
94function identif_msj_load($idmsj = 0) {
95  settype($idmsj, "integer");
96  if ($idmsj >= 0) {
97    return $idmsj;
98  }
99  return FALSE;
100}
101
102function identif_usuario_load($id_usuario = 0) {
103  settype($id_usuario, "integer");
104  if ($id_usuario >= 0) {
105    return $id_usuario;
106  }
107  return FALSE;
108}
109
110//**************************************************************************************************************************************************
111//pagina de mensajes del usuario
112
113/**
114 * Función que crea y envia el msj segun el cambio de estadolos estados
115 */
116function _crear_y_enviar_msj_en_db($mensaje) {
117
118  //segun usuarios relacionados con el ente planificador asociado al nodo
119  $lista_de_usuarios = _obtener_posibles_destinatarios_del_msj($mensaje['nid']);
120 
121  //crear mensaje
122  $id_msj = _crear_mensaje_en_bd($mensaje);
123 
124  //obtener los roles que deben recibir mensaje, segun el cambio de estado
125  $roles_receptores_de_msj = _obtener_roles_que_recibiran_mensaje_segun_cambio_estado($mensaje);
126 
127  //realizar envío
128  if($roles_receptores_de_msj['enlace']==1){
129    foreach($lista_de_usuarios['tipo_enlace'] as $usuario_ente){
130      _enviar_mensaje_en_bd($usuario_ente['id_usuario'], $id_msj);
131    }
132  }
133  if($roles_receptores_de_msj['supervisor']==1){
134    foreach($lista_de_usuarios['tipo_supervisor'] as $usuario_ente){
135      _enviar_mensaje_en_bd($usuario_ente['id_usuario'], $id_msj);
136    }
137  }
138  if($roles_receptores_de_msj['control']==1){
139    foreach($lista_de_usuarios['tipo_control'] as $usuario_ente){
140      _enviar_mensaje_en_bd($usuario_ente['id_usuario'], $id_msj);
141    }
142  }
143
144  return true;
145}
146
147
148/**
149 * Función que obtiene la lista de posibles destinatarios segun el nodo asociado
150 */
151function _obtener_posibles_destinatarios_del_msj($id_nodo_asociado) {
152//function _enviar_msj_por_cambio_de_estado($mensaje) {
153 
154  //obtener nodo asociado
155  if(isset($id_nodo_asociado)){
156    $node = node_load($id_nodo_asociado);
157  }
158   
159  //identificar tipo de nodo, para buscar el ente planificador
160  if($node->type == 'proyectos_operativos'){
161    $ente_planificador = node_load($node->field_proyecto_ente[0]['nid']);
162  }elseif($node->type == 'accion_especifica'){
163    $nodo_proyecto = node_load($node->field_accion_esp_proyecto[0]['nid']);
164    $ente_planificador = node_load($nodo_proyecto->field_proyecto_ente[0]['nid']);
165  }elseif($node->type == 'accion_centralizada'){
166    $ente_planificador = node_load($node->field_acciones_ente[0]['nid']);
167  }else{
168    $ente_planificador = NULL;
169  }
170 
171  //cargar usuarios del ente planificador asociado al nodo
172  $usuarios_enlace = array();
173  $usuarios_supervisor = array();
174  if($ente_planificador != NULL){
175    if ($ente_planificador->nid && $ente_planificador->type == 'ente_planificador') {
176     
177      $sql = "SELECT * FROM {ente_user_planificador} WHERE nid = %d";
178      $queryResult =  db_query ( $sql, $ente_planificador->nid);
179      while ($usuarios_del_ente = db_fetch_array ( $queryResult ) ){
180       
181        $usuario_ente = array(
182          'id_usuario' => $usuarios_del_ente['usuario'],
183          'id_ente' => $ente_planificador->nid,
184        );
185       
186        $sql1 = "SELECT r.name FROM {users_roles} ur, {role} r  WHERE ur.uid = %d AND ur.rid = r.rid";
187        $queryResult1 =  db_query ( $sql1, $usuarios_del_ente['usuario']);
188        while ($roles = db_fetch_array ( $queryResult1 ) ){
189         
190          if($roles['name']=='Enlace'){
191            $usuarios_enlace[] = $usuario_ente;
192            break;
193          }elseif($roles['name']=='Supervisor'){
194            $usuarios_supervisor[] = $usuario_ente;
195            break;
196          }
197         
198        }
199      }
200    }
201  }
202  //cargar usuario control
203  $usuarios_control = array();
204  $sql2 = "SELECT ep.nid as idnodo_ente, eup.usuario as uid_usuariocontrol FROM {ente_planificador} ep, {ente_user_planificador} eup  WHERE ep.tipo = 1 AND ep.nid = eup.nid";
205  $queryResult2 =  db_query ( $sql2);
206  while ($usuarios_del_ente_macro = db_fetch_array ( $queryResult2 ) ){
207
208    $usuario_ente = array(
209      'id_usuario' => $usuarios_del_ente_macro['uid_usuariocontrol'],
210      'id_ente' => $usuarios_del_ente_macro['idnodo_ente'],
211    );
212    $usuarios_control[] = $usuario_ente;
213  }
214  //lista de usuarios: posibles destinatarios
215  $lista_de_usuarios = array(
216    'tipo_enlace' => $usuarios_enlace,
217    'tipo_supervisor' => $usuarios_supervisor,
218    'tipo_control' => $usuarios_control,
219  );
220
221  return $lista_de_usuarios;
222}
223
224
225/**
226 * Función que crea el mensaje en base de datos
227 */
228function _crear_mensaje_en_bd($mensaje) {
229 
230  db_query("INSERT INTO {bandejaentrada_usuario_mensajes} (fecha, nid, tipo_proceso, euid, estado, mensaje) VALUES (%d, %d, %d, %d, %d, '%s')", $mensaje['fecha'], $mensaje['nid'], $mensaje['tipo_proceso'], $mensaje['euid'], $mensaje['estado'], check_plain($mensaje['mensaje']));
231  $ultimo_mensaje_creado = db_query("SELECT max(a.id_msj) AS id FROM {bandejaentrada_usuario_mensajes} AS a WHERE a.nid = %d AND a.tipo_proceso = %d", $mensaje['nid'], $mensaje['tipo_proceso']);
232  $id_mensaje_creado = db_fetch_object($ultimo_mensaje_creado) ;
233  $id_msj = $id_mensaje_creado->id;
234
235  return $id_msj;
236}
237
238
239/**
240 * Función que obtiene la lista de posibles destinatarios segun el nodo asociado
241 */
242function _obtener_roles_que_recibiran_mensaje_segun_cambio_estado($mensaje) {
243 
244  $roles_receptores_de_msj = array(
245    'enlace' => 0,
246    'supervisor' => 0,
247    'control' => 0,
248  );
249 
250  //obtener nombres de estados
251  $estados = _obtener_estados_seguimiento_mes();
252  $estados_2 = _obtener_estados_seguimiento_mes_2();
253  if(isset($mensaje['estado_ant'])){
254    $nombre_estado_anterior = $estados['states'][$mensaje['estado_ant']];
255    if(!isset($nombre_estado_anterior)){
256      $nombre_estado_anterior = $estados_2['states'][$mensaje['estado_ant']]; 
257    }
258  }
259  if(isset($mensaje['estado'])){
260    $nombre_estado_actual = $estados['states'][$mensaje['estado']];
261    if(!isset($nombre_estado_actual)){
262      $nombre_estado_actual = $estados_2['states'][$mensaje['estado']];
263    }
264  }
265
266  //enviar mensaje a los respectivos usuarios segun cambio de estados
267  if (preg_match('/(nviad)(([a-z]|[_])*)(upervisor)/i',$nombre_estado_actual)){//estado 'Enviado_a_Supervisor';
268    //Enviar msj a Supervisor
269    $roles_receptores_de_msj['supervisor'] = 1;
270  }
271
272  if (preg_match('/(nviad)(([a-z]|[_])*)(ontrol)/i',$nombre_estado_actual)){//estado 'Enviado_a_Control';
273    //Enviar msj a Control
274    $roles_receptores_de_msj['control'] = 1;
275  }
276
277  if (preg_match('/(probad)/i',$nombre_estado_actual)){//estado 'Aprobado';
278    //Enviar msj a Enlace
279    $roles_receptores_de_msj['enlace'] = 1;
280    //Enviar msj a Supervisor
281    $roles_receptores_de_msj['supervisor'] = 1;
282  }
283
284  if (preg_match('/(evuelt)(([a-z]|[_])*)(ontrol)/i',$nombre_estado_actual)){//estado 'Devuelto_a_Control';
285    //Enviar msj a Control (proyecto desaprobado)
286    $roles_receptores_de_msj['control'] = 1;
287    //Enviar msj a Enlace (proyecto desaprobado)
288    $roles_receptores_de_msj['enlace'] = 1;
289    //Enviar msj a Supervisor (proyecto desaprobado)
290    $roles_receptores_de_msj['supervisor'] = 1;
291  }
292
293  if (preg_match('/(evuelt)(([a-z]|[_])*)(nlace)/i',$nombre_estado_actual)){//estado 'Devuelto_a_Enlace';
294    //Enviar msj a Enlace
295    $roles_receptores_de_msj['enlace'] = 1;
296    if (preg_match('/(nviad|evuelt)(([a-z]|[_])*)(ontrol)/i',$nombre_estado_anterior)){
297      //Enviar msj a Supervisor
298      $roles_receptores_de_msj['supervisor'] = 1;
299    }
300  }
301
302  if (preg_match('/(nulad)/i',$nombre_estado_actual)){//estado 'Anulado';
303    if (!preg_match('/(ngresad)/i',$nombre_estado_anterior)){//si se anula, y el estado anterior no es ingresado
304      //Enviar msj a Enlace
305      $roles_receptores_de_msj['enlace'] = 1;
306      //Enviar msj a Supervisor
307      $roles_receptores_de_msj['supervisor'] = 1;
308    }
309  } 
310 
311  return $roles_receptores_de_msj;
312}
313
314/**
315 * Función que envia el mensaje en base de datos
316 */
317function _enviar_mensaje_en_bd($id_usuario_destinatario, $id_msj) {
318 
319  db_query("INSERT INTO {bandejaentrada_usuario} (buid, id_msj) VALUES (%d, %d)", $id_usuario_destinatario, $id_msj); 
320
321  return true;
322}
323
324//**************************************************************************************************************************************
325//consulta de los mensajes
326/**
327 * Pagina que muestra los mensajes
328 */
329function mis_mensajes_sipp_page($id_usuario = 0) {
330
331  drupal_set_title(t('Mis Mensajes'));
332 
333  $tipos_de_nodo = array(
334    1 => 'Acción Específica de Proyecto',
335    2 => 'Proyecto Operativo',
336    3 => 'Acciones Centralizadas',
337  );
338 
339  $tipos_de_proceso = array(
340    1 => 'Formulación',
341    2 => 'Reformulación',
342    3 => 'Seguimiento',
343  );
344 
345  $output = '';
346  $output .= '<br>';
347
348  $tablas = array();
349 
350  $header = array();
351  $header[] = array('data' => t('Fecha'));
352  $header[] = array('data' => t('Tipo de Proceso'));
353  $header[] = array('data' => t('Tipo de Nodo'));
354  $header[] = array('data' => t('Acción Ejecutada'));
355  $header[] = array('data' => t('Usuario Ejecutor'));
356  $header[] = array('data' => t('Opciones Disponibles'));
357 
358  global $user;
359 
360  if($id_usuario > 1){//para un usuario
361    $consulta_sql0 = "SELECT count(id_bandeja_msj) as total from {bandejaentrada_usuario} as bandeja, {bandejaentrada_usuario_mensajes} as mensaje where bandeja.id_msj=mensaje.id_msj and bandeja.buid=%d and bandeja.visto_por_destinatario=0 ";//consulta mensajes
362    $Resultado_consulta0 =  db_query ($consulta_sql0, $id_usuario);
363    $mensajes_usuario = db_fetch_array ( $Resultado_consulta0 );
364    $cant_mensajes_usuario = $mensajes_usuario['total'];
365   
366    $consulta_sql = "SELECT * from {bandejaentrada_usuario} as bandeja, {bandejaentrada_usuario_mensajes} as mensaje where bandeja.id_msj=mensaje.id_msj and bandeja.buid=%d order by id_bandeja_msj desc ";//consulta mensajes
367    $Resultado_consulta =  db_query ($consulta_sql, $id_usuario);
368   
369  }elseif($id_usuario == 1){//usuario administrador (todos los mensajes)
370    $consulta_sql0 = "SELECT count(id_msj) as total from {bandejaentrada_usuario_mensajes} as mensaje where mensaje.visto_por_admin=0 ";//consulta mensajes
371    $Resultado_consulta0 =  db_query ($consulta_sql0, $id_usuario);
372    $mensajes_usuario = db_fetch_array ( $Resultado_consulta0 );
373    $cant_mensajes_usuario = $mensajes_usuario['total'];
374 
375    $consulta_sql = "SELECT * from {bandejaentrada_usuario_mensajes} as mensaje order by id_msj desc ";//consulta mensajes
376    $Resultado_consulta =  db_query ($consulta_sql);
377  }
378 
379  if($user->uid == $id_usuario){
380    if($cant_mensajes_usuario > 0){
381      $output .= $cant_mensajes_usuario > 1? '<b>Hay ('.$cant_mensajes_usuario.') mensajes nuevos</b><br>' : '<b>Hay (1) mensaje nuevo</b><br>';
382    }else{
383      $output .= '<b>No hay mensajes nuevos</b><br>';
384    }
385  }else{
386    drupal_set_title(t('Mensajes para usuario ').$id_usuario);
387  }
388 
389  $rows = array();
390  while($mensajes_usuario = db_fetch_array ( $Resultado_consulta )){
391    $row = array();
392   
393    //verificar si es admin
394    $mensajes_usuario_visto = $user->uid == 1? $mensajes_usuario['visto_por_admin']: $mensajes_usuario['visto_por_destinatario'];
395   
396    //fecha
397    $fecha_formato_cambio_estado = format_date($mensajes_usuario['fecha']);
398    $row[] = array('data' => $fecha_formato_cambio_estado, );
399
400    //tipo de proceso
401    $t_proc = $mensajes_usuario['tipo_proceso'];
402    $tipo_proceso = $tipos_de_proceso[$t_proc];
403    $row[] = array('data' => $tipo_proceso, );
404     
405    //tipo de nodo
406    $nodo_asociado = node_load($mensajes_usuario['nid']);
407    if($nodo_asociado->type == 'accion_especifica'){
408      $tipo_nodo = $tipos_de_nodo[1]; 
409    }elseif($nodo_asociado->type == 'proyectos_operativos'){
410      $tipo_nodo = $tipos_de_nodo[2];
411    }elseif($nodo_asociado->type == 'accion_centralizada'){
412      $tipo_nodo = $tipos_de_nodo[3];
413    }else{
414      $tipo_nodo = '';
415    }
416    $row[] = array('data' => $tipo_nodo, );
417   
418    //accion ejecutada
419    $estados = _obtener_estados_seguimiento_mes();
420    $estados_2 = _obtener_estados_seguimiento_mes_2();
421    $nombre_estado = $estados['states'][$mensajes_usuario['estado']];
422    if(!isset($nombre_estado)){
423      $nombre_estado = $estados_2['states'][$mensajes_usuario['estado']]; 
424    }
425    $accion_realizada = _nombre_accion_segun_estado($nombre_estado);
426    $row[] = array('data' => $accion_realizada, );
427   
428    //usuario que realizo la acción
429    $nodo_usuario_ejec = user_load($mensajes_usuario['euid']);
430    $row[] = array('data' => $nodo_usuario_ejec->name, );
431   
432    $links = array();
433    $enlace_ver_nuevo = l(t('Leer mensaje (**nuevo**)'), 'ver_mensaje/' . $mensajes_usuario['id_msj']);
434    $enlace_ver = l(t('Leer mensaje'), 'ver_mensaje/' . $mensajes_usuario['id_msj']);
435    $links[] = $mensajes_usuario_visto == 0 ? array('data' => $enlace_ver_nuevo, 'style' => 'font-weight: bold;',) : array('data' => $enlace_ver, );
436    $row[] = array('data' => theme('item_list', $links),);
437   
438    $rows[] = $row;
439  }
440 
441  $tablas[]= theme('table', $header, $rows);
442 
443  if (count($tablas)) {
444    $output .= '<fieldset><legend>Mensajes Recibidos</legend>';
445    $output .= implode('', $tablas).'</fieldset>';
446  }
447
448  return $output;
449}
450
451//*************************************************************************************************************************
452//un mensaje particular
453
454/**
455 * Pagina que muestra un mensaje
456 */
457function ver_el_mensaje_sipp_page($idmsj = 0) {
458 
459  $tipos_de_nodo = array(
460    1 => 'Acción Específica de Proyecto',
461    2 => 'Proyecto Operativo',
462    3 => 'Acciones Centralizadas',
463  );
464 
465  $tipos_de_proceso = array(
466    1 => 'Formulación',
467    2 => 'Reformulación',
468    3 => 'Seguimiento',
469  );
470 
471  $output='';
472 
473  global $user;
474 
475  $consulta_sql = "SELECT * from {bandejaentrada_usuario_mensajes} WHERE id_msj=%d ";//consulta mensajes
476  $Resultado_consulta =  db_query ($consulta_sql, $idmsj);
477  $mensajes_usuario = db_fetch_array ( $Resultado_consulta );
478  $consulta_sql1 = "SELECT * from {bandejaentrada_usuario} WHERE id_msj=%d AND buid=%d ";//consulta mensajes en bandeja de entrada
479  $Resultado_consulta1 =  db_query ($consulta_sql1, $idmsj, $user->uid);
480  $mensajes_usuario_bandeja = db_fetch_array ( $Resultado_consulta1 );
481
482  if(($user->uid==1)&&($mensajes_usuario['visto_por_admin']==0)){
483    $exe_query = db_query("UPDATE {bandejaentrada_usuario_mensajes} SET visto_por_admin = %d WHERE id_msj = %d", 1, $mensajes_usuario['id_msj'] ); 
484  }elseif(($user->uid > 1) && ($mensajes_usuario_bandeja['visto_por_destinatario']==0)){
485    $exe_query = db_query("UPDATE {bandejaentrada_usuario} SET visto_por_destinatario = %d WHERE id_bandeja_msj = %d ", 1, $mensajes_usuario_bandeja['id_bandeja_msj']); 
486  }else{
487    if(($user->uid!=1) && !isset($mensajes_usuario_bandeja['id_bandeja_msj']) ){
488      //un usuario al que no se le envio el msj
489      return $output;
490    }
491  }
492 
493  $tablas = array();
494  $header = array();
495  $rows = array();
496       
497  //fecha
498  $row = array();
499  $row[] = array('data' => 'Fecha: ', 'style' => 'font-weight: bold;',);
500  $fecha_formato_cambio_estado = format_date($mensajes_usuario['fecha']);
501  $row[] = array('data' => $fecha_formato_cambio_estado, );
502  $rows[] = $row;
503 
504  //tipo de nodo
505  $nodo_asociado = node_load($mensajes_usuario['nid']);
506  if($nodo_asociado->type == 'accion_especifica'){
507    $tipo_nodo = $tipos_de_nodo[1]; 
508  }elseif($nodo_asociado->type == 'proyectos_operativos'){
509    $tipo_nodo = $tipos_de_nodo[2];
510  }elseif($nodo_asociado->type == 'accion_centralizada'){
511    $tipo_nodo = $tipos_de_nodo[3];
512  }else{
513    $tipo_nodo = '';
514  }
515 
516  //tipo de proceso
517  $row = array();
518  $row[] = array('data' => 'Tipo de Proceso - Nodo: ', 'style' => 'font-weight: bold;',);
519  $t_proc = $mensajes_usuario['tipo_proceso'];
520  $tipo_proceso = $tipos_de_proceso[$t_proc];
521  $row[] = array('data' => $tipo_proceso.' - '.$tipo_nodo, );
522  $rows[] = $row;
523   
524  //accion ejecutada
525  $row = array();
526  $row[] = array('data' => 'Acción Ejecutada: ', 'style' => 'font-weight: bold;',);
527  $estados = _obtener_estados_seguimiento_mes();
528  $estados_2 = _obtener_estados_seguimiento_mes_2();
529  $nombre_estado = $estados['states'][$mensajes_usuario['estado']];
530  if(!isset($nombre_estado)){
531    $nombre_estado = $estados_2['states'][$mensajes_usuario['estado']]; 
532  }
533  $accion_realizada = _nombre_accion_segun_estado($nombre_estado);
534  $row[] = array('data' => $accion_realizada, );
535  $rows[] = $row;
536   
537  //usuario que realizo la acción
538  $row = array();
539  $row[] = array('data' => 'Usuario Ejecutor: ', 'style' => 'font-weight: bold;',);
540  $nodo_usuario_ejec = user_load($mensajes_usuario['euid']);
541  $row[] = array('data' => $nodo_usuario_ejec->name, );
542  $rows[] = $row;
543 
544  //Mensaje
545  $row = array();
546  $row[] = array('data' => 'Contenido Mensaje: ', 'style' => 'font-weight: bold;',);
547  $row[] = array('data' => $mensajes_usuario['mensaje'], );
548  $rows[] = $row;
549
550  //enlaces
551  $row = array();
552  $row[] = array('data' => 'Enlaces Relacionados: ', 'style' => 'font-weight: bold;',); 
553  $links = _obtener_enlaces_relacionados_segun_tiponodo_y_proceso($mensajes_usuario['nid'], $t_proc);
554  $row[] = array('data' => theme('item_list', $links),);
555  $rows[] = $row;
556 
557  $tablas[]= theme('table', $header, $rows);
558 
559  if (count($tablas)) {
560    $output .= '<fieldset><legend>Mensaje</legend>';
561    $output .= implode('', $tablas);
562    $output .= '<br><center>'.l(t('Regresar (Mis Mensajes)'), 'ver_lista_de_mensajes_recibidos/' . $user->uid).'</center>';
563
564    $output .= '</fieldset>';
565  }
566 
567  return $output;
568}
569
570//----------------------------------------------------------------------------------------------------------------------------
571
572function _nombre_accion_segun_estado($nombre_estado='') {
573 
574  if (preg_match('/(ngresad)/i',$nombre_estado)){
575    $expresion_titulo = t('Ingresado');
576  }elseif (preg_match('/(nviad|evuelt)(([a-z]|[_])*)(nlace)/i',$nombre_estado)){
577    $expresion_titulo = t('Enviado a Enlace');
578  }elseif (preg_match('/(nviad|evuelt)(([a-z]|[_])*)(upervisor)/i',$nombre_estado)){
579    $expresion_titulo = t('Enviado a Supervisor');
580  }elseif (preg_match('/(nviad)(([a-z]|[_])*)(ontrol)/i',$nombre_estado)){
581    $expresion_titulo = t('Enviado a Control');
582  }elseif (preg_match('/(evuelt)(([a-z]|[_])*)(ontrol)/i',$nombre_estado)){
583    $expresion_titulo = t('Enviado a Control (Desaprobado)');
584  }elseif (preg_match('/(probad)/i',$nombre_estado)){
585    $expresion_titulo = t('Aprobado');
586  }elseif (preg_match('/(nulad)/i',$nombre_estado)){
587    $expresion_titulo = t('Anulado');
588  }else{
589    $expresion_titulo = $nombre_estado;
590  }
591
592  return $expresion_titulo;
593}
594
595function _obtener_enlaces_relacionados_segun_tiponodo_y_proceso($id_nodo = 0, $tipo_de_proc = 1) {
596 
597  //tipo de nodo
598  $tipos_de_nodo = array(
599    1 => 'Acción Específica de Proyecto',
600    2 => 'Proyecto Operativo',
601    3 => 'Acciones Centralizadas',
602  );
603  $nodo_asociado = node_load($id_nodo);
604  if($nodo_asociado->type == 'accion_especifica'){
605    $tipo_nodo = $tipos_de_nodo[1]; 
606  }elseif($nodo_asociado->type == 'proyectos_operativos'){
607    $tipo_nodo = $tipos_de_nodo[2];
608  }elseif($nodo_asociado->type == 'accion_centralizada'){
609    $tipo_nodo = $tipos_de_nodo[3];
610  }else{
611    $tipo_nodo = '';
612  }
613 
614  //tipo de proceso
615  $tipos_de_proceso = array(
616    1 => 'Formulación',
617    2 => 'Reformulación',
618    3 => 'Seguimiento',
619  );
620  $tipo_proc = $tipos_de_proceso[$tipo_de_proc];
621
622  $links = array();
623  if(($tipo_proc == 'Formulación')&&($tipo_nodo == 'Proyecto Operativo')){
624    //(1) Formulación de Proyecto Operativo (definición)
625    $enlace = l(t('Consultar Proyecto'), 'proyectosop/' . $id_nodo);
626    $links[] = array('data' => $enlace, );
627    $enlace = l(t('Flujo de trabajo del proyecto'), 'proyectosop/' . $id_nodo . '/workflow');
628    $links[] = array('data' => $enlace, );
629   
630  }elseif(($tipo_proc == 'Formulación')&&($tipo_nodo == 'Acciones Centralizadas')){
631    //(2) Formulación de Acciones Centralizadas (definición)
632    $enlace = l(t('Consultar Acciones Centralizadas'), 'node/' . $id_nodo );
633    $links[] = array('data' => $enlace, );
634    $enlace = l(t('Flujo de trabajo de las Acciones Centralizadas'), 'node/' . $id_nodo . '/workflow');
635    $links[] = array('data' => $enlace, );
636       
637  }elseif(($tipo_proc == 'Seguimiento')&&($tipo_nodo == 'Proyecto Operativo')){
638    //(3) Seguimiento de Proyecto Operativo
639    $enlace = l(t('Consultar Proyecto'), 'proyectosop/' . $id_nodo);
640    $links[] = array('data' => $enlace, );
641    $enlace = l(t('Consultar seguimiento del proyecto'), 'node/' . $id_nodo . '/seguimiento_proyecto');
642    $links[] = array('data' => $enlace, );
643   
644  }elseif(($tipo_proc == 'Seguimiento')&&($tipo_nodo == 'Acción Específica de Proyecto')){
645    //(4) Seguimiento de Acción Específica de Proyecto
646    $nodo_proyecto = node_load($nodo_asociado->field_accion_esp_proyecto[0]['nid']);
647    $enlace = l(t('Consultar Acción Específica de Proyecto'), 'proyectosop/' . $nodo_proyecto->nid . '/ae/' . $id_nodo . '/ver');
648    $links[] = array('data' => $enlace, );
649    $enlace = l(t('Consultar seguimiento de la acción específica de proyecto'), 'node/' . $id_nodo . '/seguimiento_aeproyecto');
650    $links[] = array('data' => $enlace, );
651   
652  }elseif(($tipo_proc == 'Seguimiento')&&($tipo_nodo == 'Acciones Centralizadas')){
653    //(5) Seguimiento de Acciones Centralizadas
654    $enlace = l(t('Consultar Acciones Centralizadas'), 'node/' . $id_nodo->nid );
655    $links[] = array('data' => $enlace, );
656    $enlace = l(t('Consultar seguimiento de las acciones centralizadas'), 'node/' . $id_nodo . '/seguimiento');
657    $links[] = array('data' => $enlace, );
658   
659  }elseif(($tipo_proc == 'Reformulación')&&($tipo_nodo == 'Proyecto Operativo')){
660    //(6) Reformulación de Proyecto Operativo
661    $enlace = l(t('Consultar Proyecto'), 'proyectosop/' . $id_nodo);
662    $links[] = array('data' => $enlace, );
663    $enlace = l(t('Ver lista de reformulaciones del proyecto'), 'proyectosop/' . $id_nodo . '/reformular');
664    $links[] = array('data' => $enlace, );
665   
666  }elseif(($tipo_proc == 'Reformulación')&&($tipo_nodo == 'Acciones Centralizadas')){
667    //(7) Reformulación de Acciones Centralizadas
668    $enlace = l(t('Consultar Acciones Centralizadas'), 'node/' . $id_nodo);
669    $links[] = array('data' => $enlace, );
670    $enlace = l(t('Ver lista de reformulaciones de las acciones centralizadas'), 'node/' . $id_nodo . '/reformular');
671    $links[] = array('data' => $enlace, );
672  }
673 
674  return $links;
675}
676
677
678/*
679 * hook_form_alter()
680 * funcion que sirve para identificar el formulario (y luego el proceso) en el que se ejecuto el cambio de estado
681 */
682function gestion_mensajes_form_alter(&$form, $form_state, $form_id) {
683 
684  //(1) Formulación de Proyecto Operativo (definición) 
685  if ($form_id == 'workflow_tab_form') {
686    if ($form['node']['#value']->type == 'proyectos_operativos') {
687      $form['#datos_formulario']= array(
688        'numero_proceso' => 1,
689        'ident_formulario' => $form_id,
690      );
691      $form['#submit'][] = 'creacion_mensaje_luego_de_realizar_cambio_de_estado';
692    }
693  }
694
695  //(2) Formulación de Acciones Centralizadas (definición)
696  if ($form_id == 'workflow_tab_form') {
697    if ($form['node']['#value']->type == 'accion_centralizada') {
698      $form['#datos_formulario']= array(
699        'numero_proceso' => 2,
700        'ident_formulario' => $form_id,
701      );
702      $form['#submit'][] = 'creacion_mensaje_luego_de_realizar_cambio_de_estado';
703    }
704  }
705
706  //(3) Seguimiento de Proyecto Operativo
707  if ($form_id == 'cambiodeestado_seg_proyecto_paginaconfirmacion_form') {
708    $form['#datos_formulario']= array(
709      'numero_proceso' => 3,
710      'ident_formulario' => $form_id,
711    );
712    $form['#submit'][] = 'creacion_mensaje_luego_de_realizar_cambio_de_estado';
713  }
714
715  //(4) Seguimiento de Acción Específica de Proyecto
716  if ($form_id == 'cambiodeestado_seg_ae_proyecto_paginaconfirmacion_form') {
717    $form['#datos_formulario']= array(
718      'numero_proceso' => 4,
719      'ident_formulario' => $form_id,
720    );
721    $form['#submit'][] = 'creacion_mensaje_luego_de_realizar_cambio_de_estado';
722  }
723
724  //(5) Seguimiento de Acciones Centralizadas
725  if ($form_id == 'acciones_centralizadas_seguimiento_wk_tab_page_form') {
726    $form['#datos_formulario']= array(
727      'numero_proceso' => 5,
728      'ident_formulario' => $form_id,
729    );
730    $form['#submit'][] = 'creacion_mensaje_luego_de_realizar_cambio_de_estado';
731  }
732
733  //(6) Reformulación de Proyecto Operativo
734  if ($form_id == 'proyectos_reformulacion_reformula_wk_tab_page_form') {
735    $form['#datos_formulario']= array(
736      'numero_proceso' => 6,
737      'ident_formulario' => $form_id,
738    );
739    $form['#submit'][] = 'creacion_mensaje_luego_de_realizar_cambio_de_estado';
740  }
741
742  //(7) Reformulación de Acciones Centralizadas
743  if ($form_id == 'acciones_centralizadas_reformula_wk_tab_page_form') {
744    $form['#datos_formulario']= array(
745      'numero_proceso' => 7,
746      'ident_formulario' => $form_id,
747    );
748    $form['#submit'][] = 'creacion_mensaje_luego_de_realizar_cambio_de_estado';
749  }
750
751
752}
753
754/**
755 * función que crea el mensaje y lo envia.
756 * Luego de tener identificado el formulario (proceso) que ejecuto el cambio de estado en workflow, se contruye el mensaje con los campos específicos
757 */
758
759function creacion_mensaje_luego_de_realizar_cambio_de_estado($form, &$form_state) {
760
761  global $user;
762
763  $enviar_msj = 0;
764
765  if(($form['#datos_formulario']['numero_proceso']==1)||($form['#datos_formulario']['numero_proceso']==2)){
766    $tipo_proceso_i = 1;//formulacion
767    $id_nodo = $form['node']['#value']->nid;
768   
769    if($form['#datos_formulario']['numero_proceso']==1){
770      $estado_ant = $form['workflow']['Proyectos_Operativos']['#default_value'];
771    }else{
772      $estado_ant = $form['workflow']['Acciones_Centralizadas']['#default_value'];
773    }
774   
775    $estado_nuevo = $form['#post']['workflow'];
776    $contenido_comentario = $form['#post']['workflow_comment'];
777    $enviar_msj = 1;
778   
779  }elseif(($form['#datos_formulario']['numero_proceso']==6)||($form['#datos_formulario']['numero_proceso']==7)){
780    $tipo_proceso_i = 2;//reformulacion
781    $id_nodo = $form['#node']->nid;
782    $estado_ant = $form['#reformulacion']->estado;
783    $estado_nuevo = $form['#nuevo_estado'];
784    $contenido_comentario = $form['#post']['comentario'];
785    $enviar_msj = 1;
786   
787  }elseif(($form['#datos_formulario']['numero_proceso']==3)||($form['#datos_formulario']['numero_proceso']==4)||($form['#datos_formulario']['numero_proceso']==5)){
788    $tipo_proceso_i = 3;//seguimiento
789    $id_nodo = $form['#node']->nid;
790   
791    if($form['#datos_formulario']['numero_proceso']==5){
792      $estado_ant = $form['#actual']['estado'];
793    }else{
794      $estado_ant = $form['#segmes']['estado'];
795    }
796    $estado_nuevo = $form['#nuevo_estado'];
797    $contenido_comentario = $form['#post']['comentario'];
798    $enviar_msj = 1;
799  }
800 
801  if($enviar_msj == 1){
802
803    $mensaje = array(
804      'fecha' => time(),
805      'nid' => $id_nodo,
806      'tipo_proceso' => $tipo_proceso_i,
807      'euid' => $user->uid,
808      'estado_ant' => $estado_ant,
809      'estado' => $estado_nuevo,
810      'mensaje' => $contenido_comentario,
811    );
812   
813    $output .= _crear_y_enviar_msj_en_db($mensaje);
814  }
815
816}
Nota: Vea TracBrowser para ayuda de uso del navegador del repositorio.