1 | <?php |
---|
2 | /** |
---|
3 | * Sistema Automatizado para la Planificación Estratégico-Situacional en la Administración Pública Venezolana |
---|
4 | * @file entes_planificadores_toolbar.install |
---|
5 | * Drupal part Module to code ente planificador module |
---|
6 | * Copyright 2011 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. Luis Gerardo Peña Camacho |
---|
23 | * @date 2013-01-31 // (año-mes-dia) |
---|
24 | * @version 0.1 // (0.1) |
---|
25 | * |
---|
26 | */ |
---|
27 | |
---|
28 | module_load_include('module', 'workflow', 'workflow'); |
---|
29 | |
---|
30 | /* |
---|
31 | * Implementación del hook_install del ente_planificador_sipp |
---|
32 | */ |
---|
33 | function ente_planificador_sipp_install() { |
---|
34 | //colocar el modulo ente planificador sipp de los ultimos a leer |
---|
35 | db_query("UPDATE {system} SET weight = 6 WHERE name = 'ente_planificador_sipp'"); |
---|
36 | |
---|
37 | create_roles_sipp(); |
---|
38 | create_permission_roles_sipp(); |
---|
39 | |
---|
40 | //Nombre del Flujo de trabajo, estados y transición de Proyectos Operativos |
---|
41 | $name_wf_po="Proyectos_Operativos"; |
---|
42 | $states_wf_po=array( |
---|
43 | Preingresado, |
---|
44 | Ingresado, |
---|
45 | Enviado_a_supervisor, |
---|
46 | Enviado_a_control, |
---|
47 | Aprobado, |
---|
48 | Devuelto_a_control, |
---|
49 | Devuelto_a_enlace, |
---|
50 | Anulado |
---|
51 | ); |
---|
52 | //Definición de las reglas de trasnsición Proyectos Operativos |
---|
53 | $reglas_transicion_po[t('(creation)')]['Preingresado']['author'] = 1; |
---|
54 | $reglas_transicion_po[t('(creation)')]['Preingresado']['Enlace'] = 1; |
---|
55 | $reglas_transicion_po['Ingresado']['Anulado']['Enlace'] = 1; |
---|
56 | $reglas_transicion_po['Ingresado']['Enviado_a_supervisor']['Enlace'] = 1; |
---|
57 | $reglas_transicion_po['Enviado_a_supervisor']['Devuelto_a_enlace']['Supervisor'] = 1; |
---|
58 | $reglas_transicion_po['Enviado_a_supervisor']['Enviado_a_control']['Supervisor'] = 1; |
---|
59 | $reglas_transicion_po['Enviado_a_control']['Aprobado']['Control'] = 1; |
---|
60 | $reglas_transicion_po['Enviado_a_control']['Devuelto_a_enlace']['Control'] = 1; //Hacer envio de mensaje a supervisor (notificación) |
---|
61 | $reglas_transicion_po['Aprobado']['Devuelto_a_control']['Administrador'] = 1; //Solo Administrador puede des-aprobar un proyecto operativo |
---|
62 | $reglas_transicion_po['Devuelto_a_control']['Aprobado']['Control'] = 1; |
---|
63 | $reglas_transicion_po['Devuelto_a_control']['Devuelto_a_enlace']['Control'] = 1; |
---|
64 | $reglas_transicion_po['Devuelto_a_enlace']['Anulado']['Enlace'] = 1; |
---|
65 | $reglas_transicion_po['Devuelto_a_enlace']['Enviado_a_supervisor']['Enlace'] = 1; |
---|
66 | $reglas_transicion_po['Anulado']['Preingresado']['Administrador'] = 1; |
---|
67 | |
---|
68 | $tab_roles_po=array( |
---|
69 | Administrador, |
---|
70 | Enlace, |
---|
71 | Supervisor, |
---|
72 | Control |
---|
73 | ); |
---|
74 | |
---|
75 | //Nombre del Flujo de trabajo, estados y transición de Acciones Centralizadas |
---|
76 | $name_wf_ac="Acciones_Centralizadas"; |
---|
77 | $states_wf_ac=array( |
---|
78 | Ingresadas, |
---|
79 | Enviadas_a_supervisor, |
---|
80 | Devueltas_a_enlace, |
---|
81 | Enviadas_a_control, |
---|
82 | Aprobadas, |
---|
83 | Devueltas_a_control, |
---|
84 | Anulada |
---|
85 | ); |
---|
86 | //Definición de las reglas de trasnsición Acciones Centralizadas |
---|
87 | $reglas_transicion_ac[t('(creation)')]['Ingresadas']['author'] = 1; |
---|
88 | $reglas_transicion_ac[t('(creation)')]['Ingresadas']['Enlace'] = 1; |
---|
89 | $reglas_transicion_ac['Ingresadas']['Enviadas_a_supervisor']['Enlace'] = 1; |
---|
90 | $reglas_transicion_ac['Enviadas_a_supervisor']['Enviadas_a_control']['Supervisor'] = 1; //enviadas a Supervisor -> enviadas a control (supervisor) |
---|
91 | $reglas_transicion_ac['Enviadas_a_supervisor']['Devueltas_a_enlace']['Supervisor'] = 1; |
---|
92 | $reglas_transicion_ac['Enviadas_a_control']['Aprobadas']['Control'] = 1; //enviadas a control -> aprobadas (control) |
---|
93 | $reglas_transicion_ac['Enviadas_a_control']['Devueltas_a_enlace']['Control'] = 1; //enviadas a control -> devueltas a enlace (control) |
---|
94 | $reglas_transicion_ac['Devueltas_a_enlace']['Enviadas_a_supervisor']['Enlace'] = 1; |
---|
95 | $reglas_transicion_ac['Aprobadas']['Devueltas_a_control']['Administrador'] = 1; |
---|
96 | $reglas_transicion_ac['Devueltas_a_control']['Devueltas_a_enlace']['Control'] = 1; //Devueltas_a_control -> devueltas a enlace (control) |
---|
97 | $reglas_transicion_ac['Devueltas_a_control']['Aprobadas']['Control'] = 1; |
---|
98 | |
---|
99 | $tab_roles_ac=array( |
---|
100 | Administrador, |
---|
101 | Enlace, |
---|
102 | Supervisor, |
---|
103 | Control |
---|
104 | ); |
---|
105 | |
---|
106 | //Creando el Workflow de Proyectos Operativos del proyecto SIPP |
---|
107 | $wid_po=create_workflow_sipp($name_wf_po, $states_wf_po); |
---|
108 | //Generando las transiciones del Workflow |
---|
109 | workflow_transition_for_sipp($wid_po,$reglas_transicion_po); |
---|
110 | update_tab_roles_workflow($wid_po, $tab_roles_po); |
---|
111 | |
---|
112 | //Creando el Workflow de Acciones Centralizadas del proyecto SIPP |
---|
113 | $wid_ac=create_workflow_sipp($name_wf_ac, $states_wf_ac); |
---|
114 | //Generando las transiciones del Workflow |
---|
115 | workflow_transition_for_sipp($wid_ac,$reglas_transicion_ac); |
---|
116 | update_tab_roles_workflow($wid_ac, $tab_roles_ac); |
---|
117 | content_notify('install', 'ente_planificador_sipp'); |
---|
118 | } |
---|
119 | |
---|
120 | /* |
---|
121 | * Implementacion del hook_uninstall() del ente_planificador_sipp |
---|
122 | */ |
---|
123 | function ente_planificador_sipp_uninstall() { |
---|
124 | db_query("DELETE FROM {variable} WHERE name LIKE '%s'", 'ente_planificador_sipp_%'); |
---|
125 | content_notify('uninstall', 'ente_planificador_sipp'); |
---|
126 | //Eliminando permisos y roles del SIPP |
---|
127 | $roles = array("Administrador", "Enlace", "Supervisor", "Control"); |
---|
128 | foreach ($roles as $rol) { |
---|
129 | $rid_role = get_rid_role_sipp($rol); |
---|
130 | if (!is_null($rid_role)){ |
---|
131 | db_query('DELETE FROM {permission} WHERE rid = %d', $rid_role); |
---|
132 | db_query("DELETE FROM {role} WHERE rid = %d", $rid_role); |
---|
133 | drupal_set_message(t('Se elimino el rol @name_rol y sus permisos asignados en el sistema SIPP', array('@name_rol' => $rol),'status')); |
---|
134 | } |
---|
135 | }; |
---|
136 | //Eliminado Workflow del SIPP |
---|
137 | $workflow_sipp = array("Proyectos_Operativos", "Acciones_Centralizadas"); |
---|
138 | foreach ($workflow_sipp as $name_wf){ |
---|
139 | $wid_workflow = get_wid_workflow_sipp($name_wf); |
---|
140 | if (!is_null($wid_workflow)){ |
---|
141 | workflow_deletewf($wid_workflow); |
---|
142 | drupal_set_message(t('Se elimino el Workflow @wf con workflow id(wid): @wid', array('@wf' => $name_wf, '@wid' => $wid_workflow ),'status')); |
---|
143 | |
---|
144 | } |
---|
145 | //$wid_workflow = db_result(db_query("SELECT wid FROM {workflows} WHERE name = '%s'", $name_wf)); |
---|
146 | |
---|
147 | }; |
---|
148 | } |
---|
149 | |
---|
150 | function create_workflow_sipp($name_wf, $states_wf){ |
---|
151 | $wid = workflow_create($name_wf); |
---|
152 | foreach($states_wf as $i => $value) { |
---|
153 | $state_wf = array('wid' => $wid, 'state' => $value, 'weight' => $i+1); |
---|
154 | $sid = workflow_state_save($state_wf); |
---|
155 | } |
---|
156 | variable_set('ente_planificador_sipp_wf_' . $name_wf, $wid); |
---|
157 | return $wid; |
---|
158 | } |
---|
159 | |
---|
160 | function workflow_transition_for_sipp($wid,$reglas_transicion){ |
---|
161 | $transition = array(); |
---|
162 | $roles = workflow_get_roles(); |
---|
163 | $states = workflow_get_states($wid); |
---|
164 | |
---|
165 | foreach ($states as $state_id => $name) { |
---|
166 | foreach ($states as $nested_state_id => $nested_name) { |
---|
167 | if ($nested_name == t('(creation)')) { |
---|
168 | // Don't allow transition TO (creation). |
---|
169 | continue; |
---|
170 | } |
---|
171 | if ($nested_state_id != $state_id) { |
---|
172 | // Need to generate checkboxes for transition from $state to $nested_state. |
---|
173 | $from = $state_id; |
---|
174 | $to = $nested_state_id; |
---|
175 | foreach ($roles as $rid => $role_name) { |
---|
176 | if($reglas_transicion[$name][$nested_name][$role_name] == 1){ |
---|
177 | $transition[$from][$to][$rid]=TRUE; |
---|
178 | } |
---|
179 | else |
---|
180 | $transition[$from][$to][$rid]=0; |
---|
181 | } |
---|
182 | } |
---|
183 | } |
---|
184 | } |
---|
185 | workflow_update_transitions($transition); |
---|
186 | } |
---|
187 | |
---|
188 | function update_tab_roles_workflow($wid, $tab_roles_wf){ |
---|
189 | $tab_roles = array(); |
---|
190 | $roles = workflow_get_roles(); |
---|
191 | foreach ($tab_roles_wf as $id_role_wf => $name_role_wf){ |
---|
192 | foreach ($roles as $rid => $role_name){ |
---|
193 | if($name_role_wf == $role_name){ |
---|
194 | $tab_roles[$id_role_wf]=$rid; |
---|
195 | } |
---|
196 | } |
---|
197 | } |
---|
198 | db_query("UPDATE {workflows} SET tab_roles = '%s' WHERE wid = %d", implode(',', $tab_roles), $wid); |
---|
199 | } |
---|
200 | |
---|
201 | function create_roles_sipp(){ |
---|
202 | db_query("INSERT INTO {role} (rid, name) VALUES (3, '%s')", 'Administrador'); |
---|
203 | db_query("INSERT INTO {role} (rid, name) VALUES (4, '%s')", 'Enlace'); |
---|
204 | db_query("INSERT INTO {role} (rid, name) VALUES (5, '%s')", 'Supervisor'); |
---|
205 | db_query("INSERT INTO {role} (rid, name) VALUES (6, '%s')", 'Control'); |
---|
206 | } |
---|
207 | |
---|
208 | function create_permission_roles_sipp(){ |
---|
209 | db_query("INSERT INTO {permission} (rid, perm, tid) VALUES (4, 'edit own planificador, ver planificador, access user profiles, change own username', 0)"); |
---|
210 | db_query("INSERT INTO {permission} (rid, perm, tid) VALUES (5, 'edit own planificador, ver planificador, access user profiles, change own username', 0)"); |
---|
211 | db_query("INSERT INTO {permission} (rid, perm, tid) VALUES (6, 'admin planificador, edit own planificador, ver planificador, access user profiles, change own username', 0)"); |
---|
212 | } |
---|
213 | |
---|
214 | |
---|
215 | function get_rid_role_sipp($role) { |
---|
216 | $result = db_query("SELECT rid FROM {role} WHERE name = '%s'",$role); |
---|
217 | $rid = NULL; |
---|
218 | if ($obj_role = db_fetch_object($result)) { |
---|
219 | $rid = $obj_role->rid; |
---|
220 | }; |
---|
221 | return $rid; |
---|
222 | } |
---|
223 | |
---|
224 | |
---|
225 | function get_wid_workflow_sipp($name_wf) { |
---|
226 | $wid_workflow = db_query("SELECT wid FROM {workflows} WHERE name = '%s'", $name_wf); |
---|
227 | $wid = NULL; |
---|
228 | if ($obj_wid = db_fetch_object($wid_workflow)) { |
---|
229 | $wid = $obj_wid->wid; |
---|
230 | }; |
---|
231 | return $wid; |
---|
232 | } |
---|