source: sipes/0.3-modules/proyectos_operativos_seguimiento/includes/proyecto/cambiodeestado_seg_proyecto_paginaconfirmacion.forms.inc @ 2b3e7ae

stable
Last change on this file since 2b3e7ae was 2b3e7ae, checked in by Sipes Apn <root@…>, 7 años ago

se realizo correciones de acceso

  • Propiedad mode establecida a 100755
File size: 12.6 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 proyecto_operativo_seguimiento.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-02-07 // (anno-mes-dia)
24  * @version 0.1
25  *
26  */
27
28/*
29 * Implementation of acciones_centralizadas_seguimiento_wk_tab_page_form()
30 */
31function cambiodeestado_seg_proyecto_paginaconfirmacion_form($form_state, $proyecto, $mes = 0) {
32  $row[] = array();
33  $form = array();
34  $meses = json_decode(MESES);
35  $estados = _obtener_estados_seguimiento_mes();
36  $consultaseguimientoactual = _seguimiento_mesactual_proyecto_load($proyecto, $mes);
37  $ente_planificador = ente_planificador_leer_ente_planificadores($proyecto->field_proyecto_ente[0]['nid']);
38  $hierarchical = variable_get('ente_planificador_hierarchical_count', 2);
39  $form['#proyecto'] = $proyecto;
40  $form['#segmes'] = $consultaseguimientoactual['segmes'];
41  $form['#nuevo_estado'] = $state;
42  $form['#estados'] = $estados['states'];
43  $mes_seguimiento =  _obtener_mes_fase_seguimiento_proyecto($form['#proyecto']);
44
45  if (!$mes) {
46    $mes  = variable_get('accion_especifica_de_proyecto_seguimiento_mes_seguimiento', 0) ;
47    for ($i=1; $i<=count($meses); $i++) {
48      if (in_array($i, variable_get('seguimiento_proyectos_cantidad_meses_seguimiento', 1))) {
49        if (_mes_habilitado_para_seguimiento($i) && _proyecto_seguimiento_mes_mover_estado_access($form['#proyecto'],  $i)) {
50          $row[$i] = $meses[$i -1];
51
52        }
53      }
54    }
55  }
56  else {
57
58    $row[$mes] = $meses[$mes -1];
59  }
60  $form['#mes'] = $row;
61
62    $choices = _obtener_transiciones_disponibles_proyecto($proyecto, $mes);
63
64  $title =  t('Mes a reportar:');
65  $form['proyecto_meses'] = array(
66     '#value' => theme('item_list', $row, $title),
67  );
68  if (sizeof($choices['transic']) == 1) {
69    $form['prox_estado'] = array(
70      '#type' => 'hidden',
71      '#value' => $form['#segmes']['estado'],
72      '#required' => TRUE,
73    );
74  }
75  else {
76    $form['prox_estado'] = array(
77      '#type' => 'radios',
78      '#title' => 'Cambiar al Estado',
79      '#options' => $choices['transic'],
80      '#default_value' => $form['#segmes']['estado'],
81      '#required' => TRUE,
82      '#ahah' => array(
83        'path' => 'proyectosop/seguimiento/workflow_ahah/callback',
84        'wrapper' => 'box-comment-ahah',
85      ),
86    );
87  }
88
89/*
90print '<pre>';
91print_r($form['prox_estado']);
92print '</pre>';
93*/
94
95  $form['comentario'] = array(
96    '#title' => t('Comentario del Proyecto'),
97    '#type' => 'textarea',
98    '#default_value' => '',
99    '#required' => FALSE,
100    '#prefix' => '<div id="box-comment-ahah">',
101    '#suffix' => '</div>',
102  );
103
104  //aplicar prefijos segun la configuración del modulo
105  if (isset($form['prox_estado']['#options'])) {
106    $current = $consultaseguimientoactual['segmes']['estado'];
107    foreach ($form['prox_estado']['#options'] as $sid => $state) {
108      if (variable_get('proyectos_operativos_state_d_' . $current . '_' . $sid, FALSE)) {
109        $form['#proyectos_operativos_states_d'][$sid] = $sid;
110        $form['prox_estado']['#options'][$sid] = t(variable_get('proyectos_operativos_state_tdevueltos', 'Devuelto a @state'), array('@state' => $form['prox_estado']['#options'][$sid]));
111      }
112      else {
113        $form['prox_estado']['#options'][$sid] = t(variable_get('proyectos_operativos_state_tndevueltos', 'Enviado a @state'), array('@state' => $form['prox_estado']['#options'][$sid]));
114      }
115    }
116  }
117  //excluir los estados de mayor nivel al ente planificador que posee el usuario
118  for ($i = 1; $i < $hierarchical + 1; $i++) {
119    if ($ente_planificador->tipo != $i) {
120      $estado = variable_get('proyectos_operativos_state_form_' . $i, 0);
121      if (isset($form['prox_estado']['#options'][$estado])) {
122        unset($form['prox_estado']['#options'][$estado]);
123      }
124    }
125  }
126  if (!variable_get('accion_especifica_de_proyecto_seguimiento_aesep', 0)) {
127    $acciones = array();
128    $acciones_estado = array();
129    $form['ae'] = array(
130      '#type' => 'fieldset',
131      '#title' => t('Acciones Específicas'),
132      '#collapsible' => TRUE,
133      '#collapsed' => FALSE,
134    );
135    foreach($proyecto->field_proyecto_accion_esp as $accion) {
136      $accion_load = node_load($accion['nid']);
137      $acciones[$accion_load->nid] = $accion_load;
138      $form['ae']['comentario_' . $accion_load->nid] = array(
139        '#title' => t('Comentario de la AE: @nombre', array('@nombre' => $accion_load->titulo_asignado)),
140        '#type' => 'textarea',
141        '#default_value' => '',
142      );
143    }
144    $form['#acciones'] = $acciones;
145  }
146  $form['submit'] = array(
147    '#type' => 'submit',
148    '#value' => t('Cambiar Estado'),
149    '#weight' => 999,
150  );
151  if (!isset($form_state['storage']['confirma'])) {
152    unset($form['#submit']);
153    $form['#submit'] = array();
154    $form['#submit'][] = 'proyectos_operativos_seguimiento_cambia_redirect_paso_submit2';
155    $form['submit']['#value'] = 'Enviar';
156   }
157   elseif ($form_state['storage']['confirma']) {
158     $next = $form_state['storage']['page_one_values']['prox_estado'];
159     drupal_set_title(t("Modificar el estado del Seguimiento"));
160     if (!variable_get('accion_especifica_de_proyecto_seguimiento_aesep', 0)) {
161       $form['ae']['#access'] = false;
162     }
163      $form['comentario']['#access'] = false;
164      $form['prox_estado']['#access'] = false;
165
166      $message = t('¿Está seguro de cambiar el seguimiento del proyecto "@titulo" del estado (@current) al estado (@next) <br>', array("@titulo" => $proyecto->title, '@current' => $choices['nombre_estado_actual'], '@next' => $choices['transic'][$form_state['values']['prox_estado']]));
167      $message .= '<p>'. t('This action cannot be undone.') .'</p>';
168      $form['#attributes'] = array('class' => 'confirmation');
169      $form['description'] = array('#value' => $message,  '#weight' => 0);
170
171      $path = 'proyectosop/' . $proyecto->nid;
172      $cancel = l(t('Cancel'), $path);
173      $form['cancel'] = array('#value' => $cancel);
174      $form['#theme'] = 'confirm_form';
175      $form['actions'] = array('#prefix' => '<div class="container-inline">', '#suffix' => '</div>');
176      $form['submit'] = array('#type' => 'submit', '#value' => $yes ? $yes : t('Confirm'));
177      //submits
178      $new_submit = array();
179      $new_submit[] = 'proyectos_operativos_seguimiento_paginaconfirmacion_form_submit1';
180      if (is_array($form['#submit'])) {
181        foreach($form['#submit']  as $name) {
182          $new_submit[] = $name;
183        }
184      }
185      $new_submit[] = 'proyectos_operativos_seguimiento_paginaconfirmacion_form_submit';
186      $form['#submit'] = $new_submit;
187      $form['#skip_duplicate_check'] = TRUE;
188   }
189   return $form;
190}
191
192/**
193 * Implementation of proyectos_operativos_cambia_redirect_paso_submit.
194 * almacena los valores del formulario y reenvia al formulario de confirmar.
195 */
196function proyectos_operativos_seguimiento_cambia_redirect_paso_submit2($form, &$form_state) {
197  $form_state['storage']['confirma'] = TRUE;
198  $form_state['storage']['page_one_values'] = $form_state['values'];
199  $form_state['rebuild'] = TRUE;
200}
201/**
202 * Implementation of proyectos_operativos_cambia_redirect_paso2_submit.
203 * envia el formulario normalmente.
204 */
205function proyectos_operativos_seguimiento_paginaconfirmacion_form_submit1($form, &$form_state) {
206  $form_state['values'] = $form_state['storage']['page_one_values'];
207  unset($form_state['storage']['page_one_values']);
208  unset($form_state['storage']['confirma']);
209}
210/**
211 * Implementation of acciones_centralizadas_seguimiento_wk_tab_page_form_submit().
212 * Process funcion delete confirm form.
213 */
214function proyectos_operativos_seguimiento_paginaconfirmacion_form_submit($form, &$form_state) {
215  global $user;
216  $wid = workflow_get_workflow_for_type('proyectos_operativos');
217  $states = workflow_get_states($wid);
218  $mes_seguimiento = _obtener_mes_fase_seguimiento_proyecto($form['#proyecto']);
219
220  //$cnt_mes_seguimiento = variable_get('seguimiento_proyectos_cantidad_meses_seguimiento', 1) +1;
221
222
223
224  foreach ($form['#mes'] as $key => $name) {
225    $i = $key;
226//  for ($i=$mes_seguimiento; $i<=$cnt_mes_seguimiento; $i++) {
227    if (_proyecto_seguimiento_mes_mover_estado_access($form['#proyecto'],  $i)) {
228      $consultaseguimientoactual = _seguimiento_mesactual_proyecto_load($form['#proyecto'], $i);
229      $form['#segmes'] = $consultaseguimientoactual['segmes'];
230      db_query("INSERT INTO {seguimiento_proyecto_transiciones_estados} (estado, estado_ant, comentario, date, id_seg, uid) VALUES (%d, %d, '%s', %d, %d, %d)", $form_state['values']['prox_estado'], $form['#segmes']['estado'], check_plain($form_state['values']['comentario']), time(), $form['#segmes']['id_seg'], $user->uid);
231
232      $ultima_id_transicion_seg = db_query("SELECT max(a.id_seg_transicion_estado) AS id FROM {seguimiento_proyecto_transiciones_estados} AS a WHERE a.id_seg = %d", $form['#segmes']['id_seg']);
233      $seg_transicion_estado = db_fetch_object($ultima_id_transicion_seg) ;
234
235      db_query('UPDATE {seguimiento_proyecto} SET estado = %d, id_seg_transicion_estado = %d WHERE id_seg = %d', $form_state['values']['prox_estado'], $seg_transicion_estado->id, $form['#segmes']['id_seg']);
236      //Se actualiza el estado de las AE si no estan separadas
237      if (!variable_get('accion_especifica_de_proyecto_seguimiento_aesep', 0)) {
238        foreach($form['#acciones'] as $accion) {
239          $acciones_estado[$accion->nid] = _seguimiento_mesactual_partida_ae_deproyecto_load($accion, $i);
240          db_query("INSERT INTO {seguimiento_aeproyecto_transiciones_estados} (estado, estado_ant, comentario, date, id_seg, uid) VALUES (%d, %d, '%s', %d, %d, %d)", $form_state['values']['prox_estado'], $form['#segmes']['estado'], check_plain($form_state['values']['comentario_' . $accion->nid]), time(), $acciones_estado[$accion->nid]['segmes']['id_seg'], $user->uid);
241          $ultima_id_transicion_seg = db_query("SELECT max(a.id_seg_transicion_estado) AS id FROM {seguimiento_aeproyecto_transiciones_estados} AS a WHERE a.id_seg = %d", $acciones_estado[$accion->nid]['segmes']['id_seg']);
242          $seg_transicion_estado = db_fetch_object($ultima_id_transicion_seg);
243          db_query('UPDATE {seguimiento_aeproyecto} SET estado = %d, id_seg_transicion_estado = %d WHERE id_seg = %d', $form_state['values']['prox_estado'], $seg_transicion_estado->id, $acciones_estado[$accion->nid]['segmes']['id_seg']);
244        }
245      }
246    }
247  }
248  drupal_set_message(t('El seguimiento fue cambiado al estado @nombre_estado', array('@nombre_estado' => $form['#estados'][$form_state['values']['prox_estado']])));
249  if (!$_REQUEST['destination']) {
250    $form_state['redirect'] = 'proyectosop/' . $form['#proyecto']->nid . '/seguimiento';
251  }
252}
253
254/**
255 * Ahah for coment workflow
256 */
257function ahah_proyectosop_seguimiento_workflow_callback() {
258  $form_state = array('storage' => NULL, 'submitted' => FALSE);
259  $form_build_id = $_POST['form_build_id'];
260  $form = form_get_cache($form_build_id, $form_state);
261  $args = $form['#parameters'];
262  $form_id = array_shift($args);
263  $form['#post'] = $_POST;
264  $form['#programmed'] = FALSE;
265  $form_state['post'] = $_POST;
266
267  //field not required
268  if ($_POST['prox_estado']) {
269    $current = $form['#segmes']['estado'];
270    if (variable_get('proyectos_operativos_state_d_' . $current . '_' . trim($_POST['prox_estado']), FALSE)) {
271      $form['comentario']['#required'] = TRUE;
272    }
273    else {
274      $form['comentario']['#required'] = FALSE;
275    }
276  }
277
278  form_set_cache($form_build_id, $form, $form_state);
279  $form += array(
280    '#post' => $_POST,
281    '#programmed' => FALSE,
282  );
283  // Rebuild the form.
284  $form = form_builder($_POST['form_id'], $form, $form_state);
285
286  $segui_form = array();
287  $segui_form = $form['comentario'];
288
289  unset($segui_form['#prefix'], $segui_form['#suffix']); // Prevent duplicate wrappers.
290  $output = drupal_render($segui_form);
291
292  print drupal_to_js(array('data' => $output, 'status' => true));
293  exit();
294}
Nota: Vea TracBrowser para ayuda de uso del navegador del repositorio.