1 | <?php |
---|
2 | |
---|
3 | /* Implementation of hook_menu_alter(). |
---|
4 | */ |
---|
5 | function ente_planificador_hierarchical_menu_alter(&$items) { |
---|
6 | //change access to own users |
---|
7 | $items['proyectos_operativos']['page callback'] = 'ente_planificador_hierarchical_search_ac_display'; |
---|
8 | $items['proyectosop/%proyectosop/workflow']['access callback'] = '_ente_planificador_hierarchical_edita_datos_wk_access'; |
---|
9 | } |
---|
10 | |
---|
11 | |
---|
12 | /* |
---|
13 | * Implementation of hook_menu() |
---|
14 | */ |
---|
15 | function ente_planificador_hierarchical_menu() { |
---|
16 | $items = array(); |
---|
17 | $items['ente_planificador_hierarchical_js_util/%'] = array( |
---|
18 | 'title' => 'JS utilities', |
---|
19 | 'page callback' => 'ente_planificador_hierarchical_js_util', |
---|
20 | 'page arguments' => array(1), |
---|
21 | 'access arguments' => array('admin planificador'), |
---|
22 | 'type' => MENU_CALLBACK, |
---|
23 | ); |
---|
24 | $items['ente_planificador_hierarchical/ente_autocomplete'] = array( |
---|
25 | 'title' => 'Ente Planificador', |
---|
26 | 'page callback' => '_ente_planificador_hierarchical_ente_autocomplete', |
---|
27 | 'access arguments' => array('ver planificador'), |
---|
28 | 'type' => MENU_CALLBACK, |
---|
29 | ); |
---|
30 | return $items; |
---|
31 | } |
---|
32 | |
---|
33 | function _ente_planificador_hierarchical_ente_autocomplete($string = '') { |
---|
34 | global $user; |
---|
35 | $matches = array(); |
---|
36 | if ($user->entes && $string) { |
---|
37 | $result = db_query_range("SELECT father.nid, father.level, n.title FROM {ente_planificador_hierarchical} AS father INNER JOIN {node} AS n ON n.nid = father.nid WHERE (father.father = %d OR (father.nid = %d AND father.father = 0)) AND n.status = 1 AND LOWER(n.title) LIKE LOWER('%s%%') ORDER BY n.title", $user->entes, $user->entes, $string, 0, 10); |
---|
38 | while ($ente = db_fetch_object($result)) { |
---|
39 | $matches[$ente->title] = '<div class="reference-autocomplete">' . check_plain($ente->title) . '</div>'; |
---|
40 | } |
---|
41 | |
---|
42 | } |
---|
43 | drupal_json($matches); |
---|
44 | } |
---|
45 | |
---|
46 | /* |
---|
47 | * Implementation of hook_acciones_obtiene_links_alter() |
---|
48 | */ |
---|
49 | function ente_planificador_hierarchical_proyecto_obtiene_links_alter(&$links, $proyecto, $acceso = FALSE) { |
---|
50 | if (!isset($links['proyecto_state'])) { |
---|
51 | if (_ente_planificador_hierarchical_edita_datos_wk_access($proyecto)){ |
---|
52 | $links['proyecto_state'] = array( |
---|
53 | 'data' => l(t('Revisión del Proyecto'), 'proyectosop/' . $proyecto->nid . '/workflow'), |
---|
54 | 'class' => 'proyectos-operativos-estado', |
---|
55 | ); |
---|
56 | } |
---|
57 | } |
---|
58 | } |
---|
59 | |
---|
60 | function _ente_planificador_hierarchical_get_finaciero($node) { |
---|
61 | $financieros = array( |
---|
62 | 'monto' => 0, |
---|
63 | 'porc' => 0, |
---|
64 | ); |
---|
65 | $nids = array(); |
---|
66 | $new_column = array(); |
---|
67 | foreach($node->field_proyecto_accion_esp as $accion) { |
---|
68 | if ($accion['nid'] && $nid != $accion['nid']) { |
---|
69 | $nids[] = $accion['nid']; |
---|
70 | $new_column[] = '%d'; |
---|
71 | } |
---|
72 | } |
---|
73 | $ftypes = array( |
---|
74 | 'p.field_accion_esp_programacion_value', |
---|
75 | 'p.field_accion_esp_programacion_value_1', |
---|
76 | 'p.field_accion_esp_programacion_value_2', |
---|
77 | 'p.field_accion_esp_programacion_value_3', |
---|
78 | 'p.field_accion_esp_programacion_value_4', |
---|
79 | 'p.field_accion_esp_programacion_value_5', |
---|
80 | 'p.field_accion_esp_programacion_value_6', |
---|
81 | 'p.field_accion_esp_programacion_value_7', |
---|
82 | 'p.field_accion_esp_programacion_value_8', |
---|
83 | 'p.field_accion_esp_programacion_value_9', |
---|
84 | 'p.field_accion_esp_programacion_value_10', |
---|
85 | 'p.field_accion_esp_programacion_value_11', |
---|
86 | ); |
---|
87 | if (count($nids)) { |
---|
88 | $sql = "SELECT SUM(" . implode(' + ', $ftypes) . ") AS suma FROM {content_field_accion_esp_programacion} AS p INNER JOIN {node} AS n ON n.nid = p.nid AND n.vid = p.vid WHERE n.status > 0 AND n.nid IN "; |
---|
89 | $sql1 = "SELECT SUM(field_accion_esp_ponderacion_value) AS porc FROM {content_type_accion_especifica} AS p INNER JOIN {node} AS n ON n.nid = p.nid AND n.vid = p.vid WHERE n.status > 0 AND n.nid IN "; |
---|
90 | $implode = '(' . implode(', ', $new_column) . ')'; |
---|
91 | $sql .= $implode; |
---|
92 | $sql1 .= $implode; |
---|
93 | $resul_sum = db_query($sql, $nids); |
---|
94 | $suma = db_fetch_object($resul_sum); |
---|
95 | $resul_porc = db_query($sql1, $nids); |
---|
96 | $porc = db_fetch_object($resul_porc); |
---|
97 | if ($suma) { |
---|
98 | $financieros['monto'] = $suma->suma; |
---|
99 | } |
---|
100 | if ($porc) { |
---|
101 | $financieros['porc'] = $porc->porc; |
---|
102 | } |
---|
103 | } |
---|
104 | return $financieros; |
---|
105 | |
---|
106 | } |
---|
107 | |
---|
108 | /** |
---|
109 | * Implementation of _proyectos_operativos_ver_datos_wk_access() |
---|
110 | * Menu access control callback. Determina si un usuario tiene acceso a editar el flujo de trabajo |
---|
111 | */ |
---|
112 | function _ente_planificador_hierarchical_edita_datos_wk_access($node = NULL) { |
---|
113 | global $user; |
---|
114 | $fecha = FALSE; |
---|
115 | $proyecto = isset($node->data_project) ? $node->data_project : $node; |
---|
116 | if (user_access('admin planificador')) { |
---|
117 | $fecha = TRUE; |
---|
118 | } |
---|
119 | else { |
---|
120 | $ente = usuario_tiene_ente($user->uid); |
---|
121 | if (!count($ente)) { |
---|
122 | return FALSE; |
---|
123 | } |
---|
124 | $current_ente = isset($node->ente) ? $node->ente : $proyecto->field_proyecto_ente[0]['nid']; |
---|
125 | if ($ente->nid == $current_ente) { |
---|
126 | $fecha = TRUE; |
---|
127 | } |
---|
128 | elseif ($current_ente) { |
---|
129 | $fathers = _ente_planificador_hierarchical_get_descbyid($current_ente,1); |
---|
130 | $fecha = isset($fathers[$ente->nid]) ? TRUE : FALSE; |
---|
131 | } |
---|
132 | } |
---|
133 | if (!$fecha) { |
---|
134 | return $fecha; |
---|
135 | } |
---|
136 | $accesso = workflow_node_tab_access($proyecto); |
---|
137 | return $fecha && $accesso && _ente_planificador_hierarchical_datos_financieros_completo($proyecto); |
---|
138 | } |
---|
139 | |
---|
140 | /** |
---|
141 | * Implementation of _proyectos_operativos_edita_datos_financieros_access() |
---|
142 | * Menu access control callback. Determina si un proyecto tiene acceso a los datos financieros. |
---|
143 | * función mas eficiente |
---|
144 | */ |
---|
145 | function _ente_planificador_hierarchical_datos_financieros_completo($node = NULL) { |
---|
146 | if (!isset($node->field_proyecto_accion_esp)) { |
---|
147 | //load AE |
---|
148 | //"" |
---|
149 | } |
---|
150 | $financieros = _ente_planificador_hierarchical_get_finaciero($node); |
---|
151 | $monto_restante = $node->field_proyecto_monto_anual[0]['value'] - $financieros['monto']; |
---|
152 | $et = 100 - $financieros['porc']; |
---|
153 | return (($monto_restante == 0) && ($et == 0)); |
---|
154 | } |
---|
155 | |
---|
156 | |
---|
157 | |
---|
158 | |
---|
159 | /* |
---|
160 | * ente_planificador_hierarchical_js_util |
---|
161 | * Genera las repuestas ajax de los distintos niveles de los entes planificadores |
---|
162 | */ |
---|
163 | |
---|
164 | function ente_planificador_hierarchical_js_util($level) { |
---|
165 | if ($level > 1) { |
---|
166 | $form_state = array('submitted' => FALSE); |
---|
167 | $form_build_id = $_POST['form_build_id']; |
---|
168 | // Add the new element to the stored form. Without adding the element to the |
---|
169 | // form, Drupal is not aware of this new elements existence and will not |
---|
170 | // process it. We retreive the cached form, add the element, and resave. |
---|
171 | $form = form_get_cache($form_build_id, $form_state); |
---|
172 | $hierarchical = variable_get('ente_planificador_hierarchical_count', 2); |
---|
173 | $opens_div = ''; |
---|
174 | for($i = $level; $i < $hierarchical + 1; $i++) { |
---|
175 | $lower_level = $i - 1; |
---|
176 | $next_level = $i + 1; |
---|
177 | |
---|
178 | // $default_value = intval($_POST['ente_planificador_hierarchical_father_' . $i]) > 0 ? intval($_POST['ente_planificador_hierarchical_father_' . $i]) : 0; |
---|
179 | $tipo_text = t(variable_get('ente_planificador_hierarchical_text_' . $i, 'Actor operativo ' . $i)); |
---|
180 | if ($i != $level) { |
---|
181 | $prev_father = 0; |
---|
182 | $childrens = array(); |
---|
183 | $childrens[0] = t('Seleccionar este nivel'); |
---|
184 | $form['ente_planificador_hierarchical_father_' . $i] = array( |
---|
185 | '#prefix' => '<div id = "ente_planificador_hierarchical_' . $i . '">', |
---|
186 | '#title' => $tipo_text, |
---|
187 | '#type' => 'select', |
---|
188 | '#default_value' => $default_value, |
---|
189 | '#options' => $childrens, |
---|
190 | ); |
---|
191 | $opens_div .= '</div>'; |
---|
192 | } |
---|
193 | else { |
---|
194 | $prev_father = intval($_POST['ente_planificador_hierarchical_father_' . $lower_level]) > 0 ? intval($_POST['ente_planificador_hierarchical_father_' . $lower_level]) : 0; |
---|
195 | $childrens = _ente_planificador_hierarchical_get_children($prev_father, $lower_level); |
---|
196 | foreach ($childrens as $children) { |
---|
197 | if ($children['nid']) { |
---|
198 | $options[$children['nid']] = $children['title']; |
---|
199 | } |
---|
200 | } |
---|
201 | if (isset($form['#node']->nid) && isset($options[$form['#node']->nid])) { |
---|
202 | unset($options[$form['#node']->nid]); |
---|
203 | } |
---|
204 | $options[0] = t('Seleccionar este nivel'); |
---|
205 | $form['ente_planificador_hierarchical_father_' . $i] = array( |
---|
206 | '#title' => $tipo_text, |
---|
207 | '#type' => 'select', |
---|
208 | '#default_value' => $default_value, |
---|
209 | '#options' => $options, |
---|
210 | ); |
---|
211 | } |
---|
212 | if ($i == $hierarchical) { |
---|
213 | $form['ente_planificador_hierarchical_father_' . $i]['#suffix'] = $opens_div; |
---|
214 | } |
---|
215 | else { |
---|
216 | $form['ente_planificador_hierarchical_father_' . $i]['#ahah'] = array( |
---|
217 | 'path' => 'ente_planificador_hierarchical_js_util/' . $next_level, |
---|
218 | 'wrapper' => 'ente_planificador_hierarchical_' . $next_level, |
---|
219 | 'method' => 'replace', |
---|
220 | 'progress' => array('type' => 'bar', 'message' => t('Please wait...')), |
---|
221 | ); |
---|
222 | } |
---|
223 | } |
---|
224 | //$form += $new_form; |
---|
225 | form_set_cache($form_build_id, $form, $form_state); |
---|
226 | $form += array( |
---|
227 | '#post' => $_POST, |
---|
228 | '#programmed' => FALSE, |
---|
229 | ); |
---|
230 | // Rebuild the form. |
---|
231 | $form = form_builder($_POST['form_id'], $form, $form_state); |
---|
232 | // Render the new output. |
---|
233 | $new_form = array(); |
---|
234 | for($i = $level; $i < $hierarchical + 1; $i++) { |
---|
235 | $new_form['ente_planificador_hierarchical_father_' . $i] = $form['ente_planificador_hierarchical_father_' . $i]; |
---|
236 | } |
---|
237 | unset($new_form['ente_planificador_hierarchical_father_' . $level]['#prefix'], $new_form['ente_planificador_hierarchical_father_' . $level]['#suffix']); // Prevent duplicate wrappers. |
---|
238 | $output = drupal_render($new_form); |
---|
239 | print drupal_to_js(array('data' => $output, 'status' => true)); |
---|
240 | exit(); |
---|
241 | } |
---|
242 | print ''; |
---|
243 | exit(); |
---|
244 | } |
---|
245 | /* |
---|
246 | * Implementation of hook_nodeapi() |
---|
247 | */ |
---|
248 | function ente_planificador_hierarchical_nodeapi(&$node, $op, $teaser = NULL, $page = NULL) { |
---|
249 | switch ($op) { |
---|
250 | case 'load': |
---|
251 | if ($node->type == 'ente_planificador') { |
---|
252 | $node->ente_planificador_hierarchical = array( |
---|
253 | 'fathers' => _ente_planificador_hierarchical_get_desc($node->nid, 1), |
---|
254 | 'children' => _ente_planificador_hierarchical_get_children($node->nid, $node->tipo), |
---|
255 | ); |
---|
256 | $hierarchical = variable_get('ente_planificador_hierarchical_count', 2); |
---|
257 | $fathers = $node->ente_planificador_hierarchical['fathers']; |
---|
258 | for ($i = 1; $i < $hierarchical + 1; $i++) { |
---|
259 | $node->{'ente_planificador_hierarchical_father_' . $i} = isset($fathers[$i])? $fathers[$i]['nid'] : 0; |
---|
260 | } |
---|
261 | } |
---|
262 | break; |
---|
263 | case 'presave': |
---|
264 | if ($node->type == 'ente_planificador') { |
---|
265 | if (isset($node->ente_planificador_hierarchical_father_1)) { |
---|
266 | $hierarchical = variable_get('ente_planificador_hierarchical_count', 2); |
---|
267 | $level = 0; |
---|
268 | $ente_planificador_hierarchical = array(); |
---|
269 | for($i = 1; $i < $hierarchical + 1; $i++) { |
---|
270 | if (!$level && isset($node->{'ente_planificador_hierarchical_father_' . $i})) { |
---|
271 | //level found |
---|
272 | $level_lower = $i - 1; |
---|
273 | $father = $node->{'ente_planificador_hierarchical_father_' . $i}; |
---|
274 | if ($father == 0) { |
---|
275 | $level = $i; |
---|
276 | $ente_planificador_hierarchical[$i] = $father; |
---|
277 | break; |
---|
278 | } |
---|
279 | $ente_planificador_hierarchical[$i] = $father; |
---|
280 | } |
---|
281 | } |
---|
282 | $node->tipo = $level; |
---|
283 | $node->ente_planificador_hierarchical = $ente_planificador_hierarchical; |
---|
284 | if ($node->tipo == 3) { |
---|
285 | $ente_adscrito = $node->ente_planificador_hierarchical[2] ? $node->ente_planificador_hierarchical[2] : 0; |
---|
286 | $result = db_query("SELECT organismo FROM {ente_planificador} WHERE nid = %d", $ente_adscrito); |
---|
287 | $row = db_fetch_object($result); |
---|
288 | $node->ente_adscrito = $row ? $row->organismo : 0; |
---|
289 | } |
---|
290 | if ($node->tipo >= 4) { |
---|
291 | $node->sub_ente = $node->ente_planificador_hierarchical[3] ? $node->ente_planificador_hierarchical[3] : 0; |
---|
292 | } |
---|
293 | } |
---|
294 | } |
---|
295 | break; |
---|
296 | case 'insert': |
---|
297 | case 'update': |
---|
298 | if ($node->type == 'ente_planificador') { |
---|
299 | if ($node->nid && $node->ente_planificador_hierarchical && is_array($node->ente_planificador_hierarchical) && count($node->ente_planificador_hierarchical)) { |
---|
300 | $query = db_query('DELETE FROM {ente_planificador_hierarchical} WHERE nid = %d', $node->nid); |
---|
301 | foreach($node->ente_planificador_hierarchical as $level => $father) { |
---|
302 | $query = db_query('INSERT INTO {ente_planificador_hierarchical} (nid, level, father) VALUES (%d, %d, %d)', $node->nid, $level, $father); |
---|
303 | } |
---|
304 | } |
---|
305 | } |
---|
306 | break; |
---|
307 | case 'view': |
---|
308 | if ($node->type == 'ente_planificador') { |
---|
309 | if (isset($node->ente_planificador_hierarchical)) { |
---|
310 | if (count($node->ente_planificador_hierarchical['fathers'])) { |
---|
311 | $fathers = ''; |
---|
312 | $sep = ''; |
---|
313 | foreach($node->ente_planificador_hierarchical['fathers'] as $level => $ente) { |
---|
314 | $fathers .= $sep . l($ente['title'], 'node/'. $ente['nid']); |
---|
315 | $sep = ' > '; |
---|
316 | } |
---|
317 | $node->content['ente_planificador_hierarchical_fathers'] = array( |
---|
318 | '#value' => '<div id = "node-fathers"><b>' . t('Fathers') . ':</b> ' . $fathers . '</div>', |
---|
319 | ); |
---|
320 | |
---|
321 | } |
---|
322 | if (count($node->ente_planificador_hierarchical['children'])) { |
---|
323 | $fathers = ''; |
---|
324 | $sep = ''; |
---|
325 | foreach($node->ente_planificador_hierarchical['children'] as $nid => $ente) { |
---|
326 | $fathers .= $sep . l($ente['title'], 'node/'. $nid); |
---|
327 | $sep = ' | '; |
---|
328 | } |
---|
329 | $node->content['ente_planificador_hierarchical_childrens'] = array( |
---|
330 | '#value' => '<div id = "node-childrens"><b>' . t('Childrens') . ':</b> ' . $fathers . '</div>', |
---|
331 | ); |
---|
332 | |
---|
333 | } |
---|
334 | } |
---|
335 | } |
---|
336 | break; |
---|
337 | } |
---|
338 | } |
---|
339 | /** |
---|
340 | * |
---|
341 | */ |
---|
342 | function ente_planificador_hierarchical_obtiene_tipos_alter(&$tipos) { |
---|
343 | $hierarchical = variable_get('ente_planificador_hierarchical_count', 2); |
---|
344 | for ($i = 1; $i < $hierarchical + 1; $i++) { |
---|
345 | if ($i == 1) { |
---|
346 | $tipos[$i] = t(variable_get('ente_planificador_hierarchical_text_' . $i, 'Actor estratégico-táctico')); |
---|
347 | } |
---|
348 | else { |
---|
349 | $tipos[$i] = t(variable_get('ente_planificador_hierarchical_text_' . $i, 'Actor operativo ' . $i)); |
---|
350 | } |
---|
351 | } |
---|
352 | } |
---|
353 | |
---|
354 | /* |
---|
355 | * hook_form_alter |
---|
356 | */ |
---|
357 | function ente_planificador_hierarchical_form_alter(&$form, $form_state, $form_id) { |
---|
358 | if ($form_id == 'proyectos_operativos_admin_workflow_settings') { |
---|
359 | $wid = workflow_get_workflow_for_type('proyectos_operativos'); |
---|
360 | if ($wid){ |
---|
361 | $states = workflow_get_states($wid); |
---|
362 | $form['buttons']['#weight'] = 1000; |
---|
363 | if (count($states)) { |
---|
364 | $form['workflow_formuladores'] = array( |
---|
365 | '#type' => 'fieldset', |
---|
366 | '#title' => t('Flujos de Formuladores'), |
---|
367 | '#collapsible' => TRUE, |
---|
368 | '#collapsed' => FALSE, |
---|
369 | ); |
---|
370 | $hierarchical = variable_get('ente_planificador_hierarchical_count', 2); |
---|
371 | for ($i = 1; $i < $hierarchical + 1; $i++) { |
---|
372 | $form['workflow_formuladores']['proyectos_operativos_state_form_' . $i] = array( |
---|
373 | '#type' => 'select', |
---|
374 | '#options' => $states, |
---|
375 | '#default_value' => variable_get('proyectos_operativos_state_form_' . $i, 0), |
---|
376 | '#title' => t('Estado formulador del nivel (@nivel)', array('@nivel' => $i)), |
---|
377 | '#multiple' => FALSE, |
---|
378 | ); |
---|
379 | } |
---|
380 | } |
---|
381 | } |
---|
382 | } |
---|
383 | |
---|
384 | if ($form_id == 'workflow_tab_form') { |
---|
385 | if ($form['node']['#value']->type == 'proyectos_operativos') { |
---|
386 | $nombre = check_plain((t($form['#wf']->name))); |
---|
387 | $ente_planificador = ente_planificador_leer_ente_planificadores($form['node']['#value']->field_proyecto_ente[0]['nid']); |
---|
388 | $hierarchical = variable_get('ente_planificador_hierarchical_count', 2); |
---|
389 | for ($i = 1; $i < $hierarchical + 1; $i++) { |
---|
390 | if ($ente_planificador->tipo != $i) { |
---|
391 | $estado = variable_get('proyectos_operativos_state_form_' . $i, 0); |
---|
392 | if (isset($form['workflow'][$nombre]['#options'][$estado])) { |
---|
393 | unset($form['workflow'][$nombre]['#options'][$estado]); |
---|
394 | } |
---|
395 | } |
---|
396 | } |
---|
397 | } |
---|
398 | } |
---|
399 | |
---|
400 | |
---|
401 | |
---|
402 | if ($form_id == 'user_profile_form' && arg(2) != 'chgpwd' && user_access('administer users')) { |
---|
403 | if (isset($form['_account']['#value']->entes) && $form['_account']['#value']->entes[0]['nid']) { |
---|
404 | $ente_planificador = $form['#ente_planificador_load'] ? $form['#ente_planificador_load'] : ente_planificador_leer_ente_planificadores($form['_account']['#value']->entes[0]['nid']); |
---|
405 | if($ente_planificador && $ente_planificador->tipo) { |
---|
406 | $roles_type = _ente_planificador_hierarchical_get_roles_type($ente_planificador->tipo); |
---|
407 | $roles = user_roles(); |
---|
408 | $hierarchical = variable_get('ente_planificador_hierarchical_count', 2); |
---|
409 | foreach($roles_type as $rol => $text) { |
---|
410 | $rol_ente = variable_get('ente_planificador_hierarchical_rol_' . $rol . '_' . $ente_planificador->tipo, 2); |
---|
411 | |
---|
412 | if ($rol_ente && isset($roles[$rol_ente])) { |
---|
413 | $form['account']['roles']['#options'][$rol_ente] = $text; |
---|
414 | } |
---|
415 | |
---|
416 | } |
---|
417 | } |
---|
418 | |
---|
419 | } |
---|
420 | } |
---|
421 | |
---|
422 | if ($form_id == 'user_register') { |
---|
423 | $ente_planificador = FALSE; |
---|
424 | //get ente planificador |
---|
425 | if (arg(4) && is_numeric(arg(4))) { |
---|
426 | |
---|
427 | $ente_planificador = $form['#ente_planificador_load'] ? $form['#ente_planificador_load'] : ente_planificador_leer_ente_planificadores(arg(4)); |
---|
428 | if($ente_planificador && $ente_planificador->tipo) { |
---|
429 | $roles_type = _ente_planificador_hierarchical_get_roles_type($ente_planificador->tipo); |
---|
430 | $roles = user_roles(); |
---|
431 | $hierarchical = variable_get('ente_planificador_hierarchical_count', 2); |
---|
432 | foreach($roles_type as $rol => $text) { |
---|
433 | $rol_ente = variable_get('ente_planificador_hierarchical_rol_' . $rol . '_' . $ente_planificador->tipo, 2); |
---|
434 | |
---|
435 | if ($rol_ente && isset($roles[$rol_ente])) { |
---|
436 | $form['account']['roles']['#options'][$rol_ente] = $text; |
---|
437 | } |
---|
438 | |
---|
439 | } |
---|
440 | } |
---|
441 | } |
---|
442 | } |
---|
443 | //change ente_planificador_admin_settings |
---|
444 | if ($form_id == 'ente_planificador_admin_settings') { |
---|
445 | $roles_type = _ente_planificador_hierarchical_get_roles_type(); |
---|
446 | $roles = user_roles(); |
---|
447 | $roles[0] = t('No aplica'); |
---|
448 | unset($roles[1]); |
---|
449 | $hierarchical_count = array(); |
---|
450 | for($i = 2; $i <= 15; $i++) { |
---|
451 | $hierarchical_count[$i] = $i; |
---|
452 | } |
---|
453 | $form['ente_planificador_hierarchical'] = array( |
---|
454 | '#type' => 'fieldset', |
---|
455 | '#title' => t('Entes jerarquicos'), |
---|
456 | '#collapsible' => TRUE, |
---|
457 | '#collapsed' => FALSE, |
---|
458 | ); |
---|
459 | $hierarchical = variable_get('ente_planificador_hierarchical_count', 2); |
---|
460 | $form['ente_planificador_hierarchical']['ente_planificador_hierarchical_count'] = array( |
---|
461 | '#title' => t('Cantidad de tipos de entes planificacdores'), |
---|
462 | '#type' => 'select', |
---|
463 | '#default_value' => $hierarchical, |
---|
464 | '#description' => t('Introduzca la cantidad de tipos de entes planificadores'), |
---|
465 | '#options' => $hierarchical_count, |
---|
466 | ); |
---|
467 | for($i = 1; $i < $hierarchical + 1; $i++) { |
---|
468 | $hierarchical_text = $i == 1 ? variable_get('ente_planificador_hierarchical_text_' . $i, 'Actor estratégico-táctico') : variable_get('ente_planificador_hierarchical_text_' . $i, 'Actor operativo ' . $i); |
---|
469 | $form['ente_planificador_hierarchical']['type_' . $i] = array( |
---|
470 | '#type' => 'fieldset', |
---|
471 | '#title' => t('Tipo de ente') . ' ' . $i, |
---|
472 | '#collapsible' => TRUE, |
---|
473 | '#collapsed' => FALSE, |
---|
474 | ); |
---|
475 | $form['ente_planificador_hierarchical']['type_' . $i]['ente_planificador_hierarchical_text_' . $i] = array( |
---|
476 | '#type' => 'textfield', |
---|
477 | '#title' => t('Nombre del tipo de ente') . ' ' . $i, |
---|
478 | '#default_value' => $hierarchical_text, |
---|
479 | '#size' => 60, |
---|
480 | '#maxlength' => 244, |
---|
481 | '#description' => t('Introduzca el nombre del tipo de actor'), |
---|
482 | '#required' => TRUE, |
---|
483 | ); |
---|
484 | foreach($roles_type as $rol => $text) { |
---|
485 | $form['ente_planificador_hierarchical']['type_' . $i]['ente_planificador_hierarchical_rol_' . $rol . '_' . $i] = array( |
---|
486 | '#type' => 'select', |
---|
487 | '#title' => t('Rol para el tipo de ente (#rol_type)', array('#rol_type' => $text)), |
---|
488 | '#default_value' => variable_get('ente_planificador_hierarchical_rol_' . $rol . '_' . $i, 0), |
---|
489 | '#options' => $roles, |
---|
490 | ); |
---|
491 | } |
---|
492 | } |
---|
493 | $form['ente_planificador_hierarchical_extras'] = array( |
---|
494 | '#type' => 'fieldset', |
---|
495 | '#title' => t('Hierarchical entes extra'), |
---|
496 | '#collapsible' => TRUE, |
---|
497 | '#collapsed' => FALSE, |
---|
498 | ); |
---|
499 | $form['ente_planificador_hierarchical_extras']['create_roles'] = array( |
---|
500 | '#type' => 'submit', |
---|
501 | '#value' => t('Create roles by each hierarchical ente'), |
---|
502 | '#submit' => array('_ente_planificador_hierarchical_create_roles'), |
---|
503 | ); |
---|
504 | |
---|
505 | |
---|
506 | } |
---|
507 | |
---|
508 | if ($form_id == 'ente_planificador_node_form') { |
---|
509 | if (isset($form['#node']->ente_planificador_hierarchical)) { |
---|
510 | $fathers = $form['#node']->ente_planificador_hierarchical['fathers']; |
---|
511 | } |
---|
512 | $hierarchical = variable_get('ente_planificador_hierarchical_count', 2); |
---|
513 | $opens_div = ''; |
---|
514 | $prev_father = 0; |
---|
515 | for($i = 1; $i < $hierarchical + 1; $i++) { |
---|
516 | $options = array(); |
---|
517 | $default_value = isset($fathers[$i])? $fathers[$i]['nid'] : 0; |
---|
518 | $lower_level = $i - 1; |
---|
519 | $next_level = $i + 1; |
---|
520 | if ($i == 1) { |
---|
521 | $tipo_text = t(variable_get('ente_planificador_hierarchical_text_' . $i, 'Actor estratégico-táctico')); |
---|
522 | $query = db_query("SELECT d.nid, n.title FROM {ente_planificador} AS d INNER JOIN {node} AS n ON n.nid = d.nid WHERE tipo = 1"); |
---|
523 | while ($father = db_fetch_object($query)) { |
---|
524 | $options[$father->nid] = $father->title; |
---|
525 | } |
---|
526 | } |
---|
527 | else { |
---|
528 | $tipo_text = t(variable_get('ente_planificador_hierarchical_text_' . $i, 'Actor operativo ' . $i)); |
---|
529 | $childrens = _ente_planificador_hierarchical_get_children($prev_father, $lower_level); |
---|
530 | foreach ($childrens as $children) { |
---|
531 | if ($children['nid']) { |
---|
532 | $options[$children['nid']] = $children['title']; |
---|
533 | } |
---|
534 | } |
---|
535 | } |
---|
536 | |
---|
537 | if (isset($form['#node']->nid) && isset($options[$form['#node']->nid])) { |
---|
538 | unset($options[$form['#node']->nid]); |
---|
539 | } |
---|
540 | $macros = array(); |
---|
541 | $macros = $options; |
---|
542 | $macros[0] = t('Seleccionar este nivel'); |
---|
543 | $opens_div .= '</div>'; |
---|
544 | $form['ente_planificador_hierarchical_father_' . $i] = array( |
---|
545 | '#prefix' => '<div id = "ente_planificador_hierarchical_' . $i . '">', |
---|
546 | '#title' => $tipo_text, |
---|
547 | '#type' => 'select', |
---|
548 | '#default_value' => $default_value, |
---|
549 | '#options' => $macros, |
---|
550 | ); |
---|
551 | if ($i == $hierarchical) { |
---|
552 | $form['ente_planificador_hierarchical_father_' . $i]['#suffix'] = $opens_div; |
---|
553 | } |
---|
554 | else { |
---|
555 | $form['ente_planificador_hierarchical_father_' . $i]['#ahah'] = array( |
---|
556 | 'path' => 'ente_planificador_hierarchical_js_util/' . $next_level, |
---|
557 | 'wrapper' => 'ente_planificador_hierarchical_' . $next_level, |
---|
558 | 'method' => 'replace', |
---|
559 | 'progress' => array('type' => 'bar', 'message' => t('Please wait...')), |
---|
560 | ); |
---|
561 | } |
---|
562 | $prev_father = $default_value; |
---|
563 | } |
---|
564 | //remove current tipo field in form |
---|
565 | if (isset($form['tipo'])) { |
---|
566 | $form['tipo']['#access'] = FALSE; |
---|
567 | } |
---|
568 | if (module_exists('ente_planificador_sector')) { |
---|
569 | $form['nivel']['ente_adscrito']['#access'] = FALSE; |
---|
570 | $form['nivel']['sub_ente']['#access'] = FALSE; |
---|
571 | if (!($form['#node']->tipo == 2) || !$form['#node']->nid){ |
---|
572 | $form['nivel']['sector']['#access'] = FALSE; |
---|
573 | $form['nivel']['#access'] = FALSE; |
---|
574 | } |
---|
575 | |
---|
576 | } |
---|
577 | } |
---|
578 | } |
---|
579 | |
---|
580 | /** |
---|
581 | * Submit hook for the settings form. |
---|
582 | */ |
---|
583 | function _ente_planificador_hierarchical_create_roles($form, &$form_state) { |
---|
584 | $hierarchical = variable_get('ente_planificador_hierarchical_count', 2); |
---|
585 | for($i = 1; $i < $hierarchical + 1; $i++) { |
---|
586 | $roles_type = _ente_planificador_hierarchical_get_roles_type($i); |
---|
587 | foreach($roles_type as $rol => $text1) { |
---|
588 | $text = t('Ente tipo @number (@type)', array('@number' => $i, '@type' => $text1)); |
---|
589 | db_query("INSERT INTO {role} (name) VALUES ('%s')", $text); |
---|
590 | } |
---|
591 | } |
---|
592 | drupal_set_message(t('The roles has been added.')); |
---|
593 | } |
---|
594 | |
---|
595 | function _ente_planificador_hierarchical_get_roles_type($tipo = 0) { |
---|
596 | $roles_type =array(); |
---|
597 | $roles_type['for'] = t('Enlace Formulador'); |
---|
598 | $roles_type['enl'] = t('Enlace Revisor'); |
---|
599 | $roles_type['sup'] = t('Supervisor'); |
---|
600 | return $roles_type; |
---|
601 | } |
---|
602 | |
---|
603 | function _ente_planificador_hierarchical_get_desc($nid, $get_father = 1, $level = 0) { |
---|
604 | $fathers = array(); |
---|
605 | //get fathers |
---|
606 | if ($get_father) { |
---|
607 | $sql = 'SELECT father.father as nid, father.level, n.title FROM {ente_planificador_hierarchical} AS father INNER JOIN {node} AS n ON n.nid = father.father WHERE father.nid = %d'; |
---|
608 | } |
---|
609 | else { |
---|
610 | //get childrens |
---|
611 | $sql = 'SELECT father.nid, father.level, n.title FROM {ente_planificador_hierarchical} AS father INNER JOIN {node} AS n ON n.nid = father.nid WHERE father.father = %d'; |
---|
612 | } |
---|
613 | $inputs = array(); |
---|
614 | $inputs[] = $nid; |
---|
615 | if ($level) { |
---|
616 | $sql .= ' AND father.level = %d'; |
---|
617 | $inputs[] = $level; |
---|
618 | } |
---|
619 | $sql .= ' ORDER BY father.level, n.title'; |
---|
620 | $query = db_query($sql, $inputs); |
---|
621 | while ($father = db_fetch_object($query)) { |
---|
622 | if ($get_father) { |
---|
623 | $fathers[$father->level] = array( |
---|
624 | 'title' => $father->title, |
---|
625 | 'nid' => $father->nid, |
---|
626 | 'level' => $father->level, |
---|
627 | ); |
---|
628 | } |
---|
629 | else { |
---|
630 | $fathers[$father->nid] = array( |
---|
631 | 'title' => $father->title, |
---|
632 | 'nid' => $father->nid, |
---|
633 | 'level' => $father->level, |
---|
634 | ); |
---|
635 | } |
---|
636 | } |
---|
637 | return $fathers; |
---|
638 | } |
---|
639 | function _ente_planificador_hierarchical_get_descbyid($nid, $father = 1, $level = 0) { |
---|
640 | $fathers = array(); |
---|
641 | //get fathers |
---|
642 | if ($father) { |
---|
643 | $sql = 'SELECT father.father as nid, father.level, n.title FROM {ente_planificador_hierarchical} AS father INNER JOIN {node} AS n ON n.nid = father.father WHERE father.nid = %d'; |
---|
644 | } |
---|
645 | else { |
---|
646 | //get childrens |
---|
647 | $sql = 'SELECT father.nid, father.level, n.title FROM {ente_planificador_hierarchical} AS father INNER JOIN {node} AS n ON n.nid = father.nid WHERE father.father = %d'; |
---|
648 | } |
---|
649 | $inputs = array(); |
---|
650 | $inputs[] = $nid; |
---|
651 | if ($level) { |
---|
652 | $sql .= ' AND father.level = %d'; |
---|
653 | $inputs[] = $level; |
---|
654 | } |
---|
655 | $sql .= ' ORDER BY father.level, n.title'; |
---|
656 | $query = db_query($sql, $inputs); |
---|
657 | while ($father = db_fetch_object($query)) { |
---|
658 | $fathers[$father->nid] = array( |
---|
659 | 'title' => $father->title, |
---|
660 | 'nid' => $father->nid, |
---|
661 | ); |
---|
662 | } |
---|
663 | return $fathers; |
---|
664 | } |
---|
665 | |
---|
666 | function _ente_planificador_hierarchical_get_children($nid, $level = 0) { |
---|
667 | $fathers = array(); |
---|
668 | $sql = 'SELECT father.nid, father.level, n.title FROM {ente_planificador_hierarchical} AS father INNER JOIN {node} AS n ON n.nid = father.nid INNER JOIN {ente_planificador} AS ep ON ep.nid = father.nid WHERE father.father = %d AND father.level = %d AND ep.tipo = father.level + 1'; |
---|
669 | $inputs = array(); |
---|
670 | $inputs[] = $nid; |
---|
671 | $inputs[] = $level; |
---|
672 | $sql .= ' ORDER BY father.level, n.title'; |
---|
673 | $query = db_query($sql, $inputs); |
---|
674 | while ($father = db_fetch_object($query)) { |
---|
675 | $fathers[$father->nid] = array( |
---|
676 | 'title' => $father->title, |
---|
677 | 'nid' => $father->nid, |
---|
678 | 'level' => $father->level + 1, |
---|
679 | ); |
---|
680 | } |
---|
681 | return $fathers; |
---|
682 | } |
---|
683 | |
---|
684 | |
---|
685 | /** |
---|
686 | * Implementation of proyectos_operativos_search_ac_display(). |
---|
687 | * Muestra la lista de proyectos disponibles. |
---|
688 | */ |
---|
689 | function ente_planificador_hierarchical_search_ac_display() { |
---|
690 | global $user; |
---|
691 | //add breadcrumb |
---|
692 | $breadcrumb = array(); |
---|
693 | $breadcrumb[] = l(t('Home'), '<front>'); |
---|
694 | $breadcrumb[] = t('Proyectos Operativos'); |
---|
695 | drupal_set_breadcrumb($breadcrumb); |
---|
696 | $current_time = time(); |
---|
697 | $tipo_plan = 'proyectos_operativos_formular'; |
---|
698 | $fecha = FALSE; |
---|
699 | $ente = usuario_tiene_ente($user->uid); |
---|
700 | $ente_planificador = 0; |
---|
701 | if ($ente && $ente->nid) { |
---|
702 | $ente_planificador = ente_planificador_leer_ente_planificadores($ente->nid); |
---|
703 | } |
---|
704 | $mi_fecha = ente_planificador_user_acceso_proceso($tipo_plan, $ente_planificador); |
---|
705 | if ($mi_fecha[1] + 86399 > $current_time && $mi_fecha[0] < $current_time) { |
---|
706 | $fecha = TRUE; |
---|
707 | } |
---|
708 | if (!$fecha) { |
---|
709 | muestra_mensaje($tipo_plan, $ente_planificador); |
---|
710 | } |
---|
711 | if ($fecha && $ente->nid) { |
---|
712 | muestra_mensaje($tipo_plan, $ente_planificador, 0); |
---|
713 | } |
---|
714 | if ($fecha && !$ente_planificador && !user_access('admin planificador')) { |
---|
715 | $fecha = FALSE; |
---|
716 | } |
---|
717 | $view_id = variable_get('ente_planificador_hierarchical_view', 'ente_planificador_hierarchical'); |
---|
718 | $view = views_get_view($view_id); |
---|
719 | $display_id = variable_get('ente_planificador_hierarchical_display', 'default'); |
---|
720 | $view->set_display($display_id); |
---|
721 | $view->override_path = $_GET['q']; |
---|
722 | $view->pre_execute(); |
---|
723 | $view->execute(); |
---|
724 | $output = $view->render(); |
---|
725 | if ($fecha) { |
---|
726 | $links = array(); |
---|
727 | drupal_alter('proyecto_obtiene_agregar_links', $links); |
---|
728 | $output .= '<div id="ente-planificador-agregar-proyecto">' . theme('item_list', $links) . '</div>'; |
---|
729 | } |
---|
730 | return $output; |
---|
731 | } |
---|
732 | |
---|
733 | /** |
---|
734 | * Implementation of hook_views_api(). |
---|
735 | */ |
---|
736 | function ente_planificador_hierarchical_views_api() { |
---|
737 | return array( |
---|
738 | 'api' => '2.0', |
---|
739 | 'path' => drupal_get_path('module', 'ente_planificador_hierarchical') . '/views', |
---|
740 | ); |
---|
741 | } |
---|
742 | |
---|
743 | /** |
---|
744 | * Implementation of hook_obtiene_macro_alter() |
---|
745 | */ |
---|
746 | function ente_planificador_hierarchical_obtiene_macro_alter(&$actor_macr0, $ente_planificador) { |
---|
747 | if (count($ente_planificador->ente_planificador_hierarchical['children'])) { |
---|
748 | if ($ente_planificador->tipo <= variable_get('situacion_actual_preliminar_hierarchical_count', 2)) { |
---|
749 | $actor_macr0 = $ente_planificador->nid; |
---|
750 | } |
---|
751 | } |
---|
752 | else if (count($ente_planificador->ente_planificador_hierarchical['fathers'])) { |
---|
753 | $pos = variable_get('situacion_actual_preliminar_hierarchical_count', 2); |
---|
754 | $actor_macr0 = $ente_planificador->ente_planificador_hierarchical['fathers'][$pos]; |
---|
755 | } |
---|
756 | } |
---|