1 | <?php |
---|
2 | /** |
---|
3 | * Sistema de Planificación y Presupuesto - SIPP |
---|
4 | * @file ente_planificador_sipp.module |
---|
5 | * Drupal part Module to code ente planificador module |
---|
6 | * Copyright 2013 Sistema de Planificación y Presupuesto - SIPP |
---|
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. Luis Gerardo Peña Camacho |
---|
23 | * @date 2013-01-10 // (año-mes-dia) |
---|
24 | * @version 0.1 // (0.1) |
---|
25 | * |
---|
26 | */ |
---|
27 | |
---|
28 | /* |
---|
29 | * hook_form_alter |
---|
30 | */ |
---|
31 | function ente_planificador_sipp_form_alter(&$form, $form_state, $form_id) { |
---|
32 | /* |
---|
33 | * Configuración del ente planificador SIPP |
---|
34 | * Creación del Rol para el Actor Enlace |
---|
35 | */ |
---|
36 | if ($form_id == 'ente_planificador_admin_settings') { |
---|
37 | $form['ActorPlanificadorEnlace'] = $form['ActorPlanificadorMacro']; |
---|
38 | $form['ActorPlanificadorEnlace']['#default_value'] = variable_get('ActorPlanificadorEnlace', 2); |
---|
39 | $form['ActorPlanificadorEnlace']['#title'] = 'Rol para el Actor Enlace'; |
---|
40 | $form['ActorPlanificadorEnlace']['#description'] = 'Seleccione el rol para el Actor Enlace'; |
---|
41 | $form['buttons']['#weight'] = 10; |
---|
42 | } |
---|
43 | |
---|
44 | /* |
---|
45 | * Modificando el Registro de Usuarios presentando los roles disponibles: |
---|
46 | * Supervisor |
---|
47 | * Enlace |
---|
48 | */ |
---|
49 | if ($form_id == 'user_register') { |
---|
50 | $roles = user_roles(); |
---|
51 | $rolenlace = variable_get('ActorPlanificadorEnlace', 2); |
---|
52 | $rolsupervisor = variable_get('ActorPlanificadorMicro', 2); |
---|
53 | $ente_planificador = FALSE; |
---|
54 | if (arg(4) && is_numeric(arg(4))) { |
---|
55 | $ente_planificador = node_load(arg(4)); |
---|
56 | } |
---|
57 | if($ente_planificador->tipo && $ente_planificador->tipo == 2) { |
---|
58 | if (isset($roles[$rolenlace])) { |
---|
59 | $form['account']['roles']['#default_value'] = array(2); |
---|
60 | $form['account']['roles']['#options'][$rolenlace] = $roles[$rolenlace]; |
---|
61 | } |
---|
62 | } |
---|
63 | } |
---|
64 | } |
---|
65 | |
---|
66 | /* |
---|
67 | * hook_user |
---|
68 | * Verificando que se inserte el Rol seleccionado en el Registro del usuario |
---|
69 | * Si el Rol es Enlace se elimina el Rol Supervisor(Micro) que viene por |
---|
70 | * defecto del modulo ente_planificador en la función: ente_planificador_user |
---|
71 | */ |
---|
72 | function ente_planificador_sipp_user($op, &$edit, &$user, $category = NULL) { |
---|
73 | switch ($op) { |
---|
74 | case 'insert': |
---|
75 | if(array_key_exists('entes', $edit) && $edit['entes']) { |
---|
76 | $roles = user_roles(); |
---|
77 | $ente_planificador = node_load($edit['entes']); |
---|
78 | $rolenlace = variable_get('ActorPlanificadorEnlace', 2); |
---|
79 | $rolsupervisor = variable_get('ActorPlanificadorMicro', 2); |
---|
80 | //Si se han creado los roles |
---|
81 | if(isset($roles[$rolenlace]) && isset($roles[$rolsupervisor])){ |
---|
82 | if ($ente_planificador->tipo) { |
---|
83 | if($ente_planificador->tipo && $ente_planificador->tipo == 2) { |
---|
84 | $edit['roles'][2] = $roles[2]; |
---|
85 | // Si se selecciona el rol Enlace |
---|
86 | if(isset($edit['roles'][$rolenlace])){ |
---|
87 | //Elimina el rol supervisor |
---|
88 | unset($edit['roles'][$rolsupervisor]); |
---|
89 | } |
---|
90 | /* |
---|
91 | if(isset($edit['roles'][$rolsupervisor])){ |
---|
92 | unset($edit['roles'][$rolenlace]); |
---|
93 | */ |
---|
94 | } |
---|
95 | } |
---|
96 | } |
---|
97 | } |
---|
98 | break; |
---|
99 | } |
---|
100 | } |
---|