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 | if (isset($form['#node']->nid) && isset($childrens[$form['#node']->nid])) { |
---|
197 | unset($childrens[$form['#node']->nid]); |
---|
198 | } |
---|
199 | $childrens[0] = t('Seleccionar este nivel'); |
---|
200 | $form['ente_planificador_hierarchical_father_' . $i] = array( |
---|
201 | '#title' => $tipo_text, |
---|
202 | '#type' => 'select', |
---|
203 | '#default_value' => $default_value, |
---|
204 | '#options' => $childrens, |
---|
205 | ); |
---|
206 | } |
---|
207 | if ($i == $hierarchical) { |
---|
208 | $form['ente_planificador_hierarchical_father_' . $i]['#suffix'] = $opens_div; |
---|
209 | } |
---|
210 | else { |
---|
211 | $form['ente_planificador_hierarchical_father_' . $i]['#ahah'] = array( |
---|
212 | 'path' => 'ente_planificador_hierarchical_js_util/' . $next_level, |
---|
213 | 'wrapper' => 'ente_planificador_hierarchical_' . $next_level, |
---|
214 | 'method' => 'replace', |
---|
215 | 'progress' => array('type' => 'bar', 'message' => t('Please wait...')), |
---|
216 | ); |
---|
217 | } |
---|
218 | } |
---|
219 | //$form += $new_form; |
---|
220 | form_set_cache($form_build_id, $form, $form_state); |
---|
221 | $form += array( |
---|
222 | '#post' => $_POST, |
---|
223 | '#programmed' => FALSE, |
---|
224 | ); |
---|
225 | // Rebuild the form. |
---|
226 | $form = form_builder($_POST['form_id'], $form, $form_state); |
---|
227 | // Render the new output. |
---|
228 | $new_form = array(); |
---|
229 | for($i = $level; $i < $hierarchical + 1; $i++) { |
---|
230 | $new_form['ente_planificador_hierarchical_father_' . $i] = $form['ente_planificador_hierarchical_father_' . $i]; |
---|
231 | } |
---|
232 | unset($new_form['ente_planificador_hierarchical_father_' . $level]['#prefix'], $new_form['ente_planificador_hierarchical_father_' . $level]['#suffix']); // Prevent duplicate wrappers. |
---|
233 | $output = drupal_render($new_form); |
---|
234 | print drupal_to_js(array('data' => $output, 'status' => true)); |
---|
235 | exit(); |
---|
236 | } |
---|
237 | print ''; |
---|
238 | exit(); |
---|
239 | } |
---|
240 | /* |
---|
241 | * Implementation of hook_nodeapi() |
---|
242 | */ |
---|
243 | function ente_planificador_hierarchical_nodeapi(&$node, $op, $teaser = NULL, $page = NULL) { |
---|
244 | switch ($op) { |
---|
245 | case 'load': |
---|
246 | if ($node->type == 'ente_planificador') { |
---|
247 | $node->ente_planificador_hierarchical = array( |
---|
248 | 'fathers' => _ente_planificador_hierarchical_get_desc($node->nid, 1), |
---|
249 | 'children' => _ente_planificador_hierarchical_get_desc($node->nid, 0), |
---|
250 | ); |
---|
251 | } |
---|
252 | |
---|
253 | break; |
---|
254 | case 'presave': |
---|
255 | if ($node->type == 'ente_planificador') { |
---|
256 | if (isset($node->ente_planificador_hierarchical_father_1)) { |
---|
257 | $hierarchical = variable_get('ente_planificador_hierarchical_count', 2); |
---|
258 | $level = 0; |
---|
259 | $ente_planificador_hierarchical = array(); |
---|
260 | for($i = 1; $i < $hierarchical + 1; $i++) { |
---|
261 | if (!$level && isset($node->{'ente_planificador_hierarchical_father_' . $i})) { |
---|
262 | //level found |
---|
263 | $level_lower = $i - 1; |
---|
264 | $father = $node->{'ente_planificador_hierarchical_father_' . $i}; |
---|
265 | if ($father == 0) { |
---|
266 | $level = $i; |
---|
267 | $ente_planificador_hierarchical[$i] = $father; |
---|
268 | break; |
---|
269 | } |
---|
270 | $ente_planificador_hierarchical[$i] = $father; |
---|
271 | } |
---|
272 | } |
---|
273 | $node->tipo = $level; |
---|
274 | $node->ente_planificador_hierarchical = $ente_planificador_hierarchical; |
---|
275 | if ($node->tipo == 3) { |
---|
276 | $ente_adscrito = $node->ente_planificador_hierarchical[2] ? $node->ente_planificador_hierarchical[2] : 0; |
---|
277 | $result = db_query("SELECT organismo FROM {ente_planificador} WHERE nid = %d", $ente_adscrito); |
---|
278 | $row = db_fetch_object($result); |
---|
279 | $node->ente_adscrito = $row ? $row->organismo : 0; |
---|
280 | } |
---|
281 | if ($node->tipo >= 4) { |
---|
282 | $node->sub_ente = $node->ente_planificador_hierarchical[3] ? $node->ente_planificador_hierarchical[3] : 0; |
---|
283 | } |
---|
284 | } |
---|
285 | } |
---|
286 | break; |
---|
287 | case 'insert': |
---|
288 | case 'update': |
---|
289 | if ($node->type == 'ente_planificador') { |
---|
290 | if ($node->nid && $node->ente_planificador_hierarchical && is_array($node->ente_planificador_hierarchical) && count($node->ente_planificador_hierarchical)) { |
---|
291 | $query = db_query('DELETE FROM {ente_planificador_hierarchical} WHERE nid = %d', $node->nid); |
---|
292 | foreach($node->ente_planificador_hierarchical as $level => $father) { |
---|
293 | $query = db_query('INSERT INTO {ente_planificador_hierarchical} (nid, level, father) VALUES (%d, %d, %d)', $node->nid, $level, $father); |
---|
294 | } |
---|
295 | } |
---|
296 | } |
---|
297 | break; |
---|
298 | case 'view': |
---|
299 | if ($node->type == 'ente_planificador') { |
---|
300 | if (isset($node->ente_planificador_hierarchical)) { |
---|
301 | if (count($node->ente_planificador_hierarchical['fathers'])) { |
---|
302 | $fathers = ''; |
---|
303 | $sep = ''; |
---|
304 | foreach($node->ente_planificador_hierarchical['fathers'] as $level => $ente) { |
---|
305 | $fathers .= $sep . l($ente['title'], 'node/'. $ente['nid']); |
---|
306 | $sep = ' > '; |
---|
307 | } |
---|
308 | $node->content['ente_planificador_hierarchical_fathers'] = array( |
---|
309 | '#value' => '<div id = "node-fathers"><b>' . t('Fathers') . ':</b> ' . $fathers . '</div>', |
---|
310 | ); |
---|
311 | |
---|
312 | } |
---|
313 | if (count($node->ente_planificador_hierarchical['children'])) { |
---|
314 | $fathers = ''; |
---|
315 | $sep = ''; |
---|
316 | foreach($node->ente_planificador_hierarchical['children'] as $level => $ente) { |
---|
317 | $fathers .= $sep . l($ente['title'], 'node/'. $ente['nid']); |
---|
318 | $sep = ' > '; |
---|
319 | } |
---|
320 | $node->content['ente_planificador_hierarchical_childrens'] = array( |
---|
321 | '#value' => '<div id = "node-childrens"><b>' . t('Childrens') . ':</b> ' . $fathers . '</div>', |
---|
322 | ); |
---|
323 | |
---|
324 | } |
---|
325 | } |
---|
326 | } |
---|
327 | break; |
---|
328 | } |
---|
329 | } |
---|
330 | |
---|
331 | |
---|
332 | |
---|
333 | function ente_planificador_hierarchical_obtiene_tipos_alter(&$tipos) { |
---|
334 | $hierarchical = variable_get('ente_planificador_hierarchical_count', 2); |
---|
335 | for($i = 1; $i < $hierarchical + 1; $i++) { |
---|
336 | if ($i == 1) { |
---|
337 | $tipos[$i] = t(variable_get('ente_planificador_hierarchical_text_' . $i, 'Actor estratégico-táctico')); |
---|
338 | } |
---|
339 | else { |
---|
340 | $tipos[$i] = t(variable_get('ente_planificador_hierarchical_text_' . $i, 'Actor operativo ' . $i)); |
---|
341 | } |
---|
342 | } |
---|
343 | } |
---|
344 | |
---|
345 | /* |
---|
346 | * hook_form_alter |
---|
347 | */ |
---|
348 | function ente_planificador_hierarchical_form_alter(&$form, $form_state, $form_id) { |
---|
349 | if ($form_id == 'proyectos_operativos_admin_workflow_settings') { |
---|
350 | $wid = workflow_get_workflow_for_type('proyectos_operativos'); |
---|
351 | if ($wid){ |
---|
352 | $states = workflow_get_states($wid); |
---|
353 | |
---|
354 | $form['buttons']['#weight'] = 1000; |
---|
355 | if (count($states)) { |
---|
356 | $form['workflow_formuladores'] = array( |
---|
357 | '#type' => 'fieldset', |
---|
358 | '#title' => t('Flujos de Formuladores'), |
---|
359 | '#collapsible' => TRUE, |
---|
360 | '#collapsed' => FALSE, |
---|
361 | ); |
---|
362 | $hierarchical = variable_get('ente_planificador_hierarchical_count', 2); |
---|
363 | for($i = 1; $i < $hierarchical + 1; $i++) { |
---|
364 | $form['workflow_formuladores']['proyectos_operativos_state_form_' . $i] = array( |
---|
365 | '#type' => 'select', |
---|
366 | '#options' => $states, |
---|
367 | '#default_value' => variable_get('proyectos_operativos_state_form_' . $i, 0), |
---|
368 | '#title' => t('Estado formulador del nivel (@nivel)', array('@nivel' => $i)), |
---|
369 | '#multiple' => FALSE, |
---|
370 | ); |
---|
371 | |
---|
372 | |
---|
373 | } |
---|
374 | } |
---|
375 | } |
---|
376 | } |
---|
377 | |
---|
378 | if ($form_id == 'workflow_tab_form') { |
---|
379 | if ($form['node']['#value']->type == 'proyectos_operativos') { |
---|
380 | $nombre = check_plain((t($form['#wf']->name))); |
---|
381 | $ente_planificador = ente_planificador_leer_ente_planificadores($form['node']['#value']->field_proyecto_ente[0]['nid']); |
---|
382 | $hierarchical = variable_get('ente_planificador_hierarchical_count', 2); |
---|
383 | for($i = 1; $i < $hierarchical + 1; $i++) { |
---|
384 | //print_r($ente_planificador); |
---|
385 | if ($ente_planificador->tipo != $i) { |
---|
386 | $estado = variable_get('proyectos_operativos_state_form_' . $i, 0); |
---|
387 | if (isset($form['workflow'][$nombre]['#options'][$estado])) { |
---|
388 | unset($form['workflow'][$nombre]['#options'][$estado]); |
---|
389 | } |
---|
390 | } |
---|
391 | } |
---|
392 | } |
---|
393 | } |
---|
394 | |
---|
395 | |
---|
396 | |
---|
397 | if ($form_id == 'user_profile_form' && arg(2) != 'chgpwd' && user_access('administer users')) { |
---|
398 | if (isset($form['_account']['#value']->entes) && $form['_account']['#value']->entes[0]['nid']) { |
---|
399 | $ente_planificador = $form['#ente_planificador_load'] ? $form['#ente_planificador_load'] : ente_planificador_leer_ente_planificadores($form['_account']['#value']->entes[0]['nid']); |
---|
400 | if($ente_planificador && $ente_planificador->tipo) { |
---|
401 | $roles_type = _ente_planificador_hierarchical_get_roles_type($ente_planificador->tipo); |
---|
402 | $roles = user_roles(); |
---|
403 | $hierarchical = variable_get('ente_planificador_hierarchical_count', 2); |
---|
404 | foreach($roles_type as $rol => $text) { |
---|
405 | $rol_ente = variable_get('ente_planificador_hierarchical_rol_' . $rol . '_' . $ente_planificador->tipo, 2); |
---|
406 | |
---|
407 | if ($rol_ente && isset($roles[$rol_ente])) { |
---|
408 | $form['account']['roles']['#options'][$rol_ente] = $text; |
---|
409 | } |
---|
410 | |
---|
411 | } |
---|
412 | } |
---|
413 | |
---|
414 | } |
---|
415 | } |
---|
416 | |
---|
417 | if ($form_id == 'user_register') { |
---|
418 | $ente_planificador = FALSE; |
---|
419 | //get ente planificador |
---|
420 | if (arg(4) && is_numeric(arg(4))) { |
---|
421 | |
---|
422 | $ente_planificador = $form['#ente_planificador_load'] ? $form['#ente_planificador_load'] : ente_planificador_leer_ente_planificadores(arg(4)); |
---|
423 | if($ente_planificador && $ente_planificador->tipo) { |
---|
424 | $roles_type = _ente_planificador_hierarchical_get_roles_type($ente_planificador->tipo); |
---|
425 | $roles = user_roles(); |
---|
426 | $hierarchical = variable_get('ente_planificador_hierarchical_count', 2); |
---|
427 | foreach($roles_type as $rol => $text) { |
---|
428 | $rol_ente = variable_get('ente_planificador_hierarchical_rol_' . $rol . '_' . $ente_planificador->tipo, 2); |
---|
429 | |
---|
430 | if ($rol_ente && isset($roles[$rol_ente])) { |
---|
431 | $form['account']['roles']['#options'][$rol_ente] = $text; |
---|
432 | } |
---|
433 | |
---|
434 | } |
---|
435 | } |
---|
436 | } |
---|
437 | } |
---|
438 | //change ente_planificador_admin_settings |
---|
439 | if ($form_id == 'ente_planificador_admin_settings') { |
---|
440 | $roles_type = _ente_planificador_hierarchical_get_roles_type(); |
---|
441 | $roles = user_roles(); |
---|
442 | $roles[0] = t('No aplica'); |
---|
443 | unset($roles[1]); |
---|
444 | $hierarchical_count = array(); |
---|
445 | for($i = 2; $i <= 15; $i++) { |
---|
446 | $hierarchical_count[$i] = $i; |
---|
447 | } |
---|
448 | $form['ente_planificador_hierarchical'] = array( |
---|
449 | '#type' => 'fieldset', |
---|
450 | '#title' => t('Entes jerarquicos'), |
---|
451 | '#collapsible' => TRUE, |
---|
452 | '#collapsed' => FALSE, |
---|
453 | ); |
---|
454 | $hierarchical = variable_get('ente_planificador_hierarchical_count', 2); |
---|
455 | $form['ente_planificador_hierarchical']['ente_planificador_hierarchical_count'] = array( |
---|
456 | '#title' => t('Cantidad de tipos de entes planificacdores'), |
---|
457 | '#type' => 'select', |
---|
458 | '#default_value' => $hierarchical, |
---|
459 | '#description' => t('Introduzca la cantidad de tipos de entes planificadores'), |
---|
460 | '#options' => $hierarchical_count, |
---|
461 | ); |
---|
462 | for($i = 1; $i < $hierarchical + 1; $i++) { |
---|
463 | $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); |
---|
464 | $form['ente_planificador_hierarchical']['type_' . $i] = array( |
---|
465 | '#type' => 'fieldset', |
---|
466 | '#title' => t('Tipo de ente') . ' ' . $i, |
---|
467 | '#collapsible' => TRUE, |
---|
468 | '#collapsed' => FALSE, |
---|
469 | ); |
---|
470 | $form['ente_planificador_hierarchical']['type_' . $i]['ente_planificador_hierarchical_text_' . $i] = array( |
---|
471 | '#type' => 'textfield', |
---|
472 | '#title' => t('Nombre del tipo de ente') . ' ' . $i, |
---|
473 | '#default_value' => $hierarchical_text, |
---|
474 | '#size' => 60, |
---|
475 | '#maxlength' => 244, |
---|
476 | '#description' => t('Introduzca el nombre del tipo de actor'), |
---|
477 | '#required' => TRUE, |
---|
478 | ); |
---|
479 | foreach($roles_type as $rol => $text) { |
---|
480 | $form['ente_planificador_hierarchical']['type_' . $i]['ente_planificador_hierarchical_rol_' . $rol . '_' . $i] = array( |
---|
481 | '#type' => 'select', |
---|
482 | '#title' => t('Rol para el tipo de ente (#rol_type)', array('#rol_type' => $text)), |
---|
483 | '#default_value' => variable_get('ente_planificador_hierarchical_rol_' . $rol . '_' . $i, 0), |
---|
484 | '#options' => $roles, |
---|
485 | ); |
---|
486 | } |
---|
487 | } |
---|
488 | $form['ente_planificador_hierarchical_extras'] = array( |
---|
489 | '#type' => 'fieldset', |
---|
490 | '#title' => t('Hierarchical entes extra'), |
---|
491 | '#collapsible' => TRUE, |
---|
492 | '#collapsed' => FALSE, |
---|
493 | ); |
---|
494 | $form['ente_planificador_hierarchical_extras']['create_roles'] = array( |
---|
495 | '#type' => 'submit', |
---|
496 | '#value' => t('Create roles by each hierarchical ente'), |
---|
497 | '#submit' => array('_ente_planificador_hierarchical_create_roles'), |
---|
498 | ); |
---|
499 | |
---|
500 | |
---|
501 | } |
---|
502 | |
---|
503 | if ($form_id == 'ente_planificador_node_form') { |
---|
504 | if (isset($form['#node']->ente_planificador_hierarchical)) { |
---|
505 | $fathers = $form['#node']->ente_planificador_hierarchical['fathers']; |
---|
506 | } |
---|
507 | $hierarchical = variable_get('ente_planificador_hierarchical_count', 2); |
---|
508 | $opens_div = ''; |
---|
509 | $prev_father = 0; |
---|
510 | for($i = 1; $i < $hierarchical + 1; $i++) { |
---|
511 | $childrens = array(); |
---|
512 | $default_value = isset($fathers[$i])? $fathers[$i]['nid'] : 0; |
---|
513 | $lower_level = $i - 1; |
---|
514 | $next_level = $i + 1; |
---|
515 | if ($i == 1) { |
---|
516 | $tipo_text = t(variable_get('ente_planificador_hierarchical_text_' . $i, 'Actor estratégico-táctico')); |
---|
517 | $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"); |
---|
518 | while ($father = db_fetch_object($query)) { |
---|
519 | $childrens[$father->nid] = $father->title; |
---|
520 | } |
---|
521 | } |
---|
522 | else { |
---|
523 | $tipo_text = t(variable_get('ente_planificador_hierarchical_text_' . $i, 'Actor operativo ' . $i)); |
---|
524 | $childrens = _ente_planificador_hierarchical_get_children($prev_father, $lower_level); |
---|
525 | } |
---|
526 | if (isset($form['#node']->nid) && isset($childrens[$form['#node']->nid])) { |
---|
527 | unset($childrens[$form['#node']->nid]); |
---|
528 | } |
---|
529 | $macros = array(); |
---|
530 | $macros = $childrens; |
---|
531 | $macros[0] = t('Seleccionar este nivel'); |
---|
532 | $opens_div .= '</div>'; |
---|
533 | $form['ente_planificador_hierarchical_father_' . $i] = array( |
---|
534 | '#prefix' => '<div id = "ente_planificador_hierarchical_' . $i . '">', |
---|
535 | '#title' => $tipo_text, |
---|
536 | '#type' => 'select', |
---|
537 | '#default_value' => $default_value, |
---|
538 | '#options' => $macros, |
---|
539 | ); |
---|
540 | if ($i == $hierarchical) { |
---|
541 | $form['ente_planificador_hierarchical_father_' . $i]['#suffix'] = $opens_div; |
---|
542 | } |
---|
543 | else { |
---|
544 | $form['ente_planificador_hierarchical_father_' . $i]['#ahah'] = array( |
---|
545 | 'path' => 'ente_planificador_hierarchical_js_util/' . $next_level, |
---|
546 | 'wrapper' => 'ente_planificador_hierarchical_' . $next_level, |
---|
547 | 'method' => 'replace', |
---|
548 | 'progress' => array('type' => 'bar', 'message' => t('Please wait...')), |
---|
549 | ); |
---|
550 | } |
---|
551 | $prev_father = $default_value; |
---|
552 | } |
---|
553 | //remove current tipo field in form |
---|
554 | if (isset($form['tipo'])) { |
---|
555 | $form['tipo']['#access'] = FALSE; |
---|
556 | } |
---|
557 | if (module_exists('ente_planificador_sector')) { |
---|
558 | $form['nivel']['ente_adscrito']['#access'] = FALSE; |
---|
559 | $form['nivel']['sub_ente']['#access'] = FALSE; |
---|
560 | if (!($form['#node']->tipo == 2) || !$form['#node']->nid){ |
---|
561 | $form['nivel']['sector']['#access'] = FALSE; |
---|
562 | $form['nivel']['#access'] = FALSE; |
---|
563 | } |
---|
564 | |
---|
565 | } |
---|
566 | } |
---|
567 | } |
---|
568 | |
---|
569 | /** |
---|
570 | * Submit hook for the settings form. |
---|
571 | */ |
---|
572 | function _ente_planificador_hierarchical_create_roles($form, &$form_state) { |
---|
573 | $hierarchical = variable_get('ente_planificador_hierarchical_count', 2); |
---|
574 | for($i = 1; $i < $hierarchical + 1; $i++) { |
---|
575 | $roles_type = _ente_planificador_hierarchical_get_roles_type($i); |
---|
576 | foreach($roles_type as $rol => $text1) { |
---|
577 | $text = t('Ente tipo @number (@type)', array('@number' => $i, '@type' => $text1)); |
---|
578 | db_query("INSERT INTO {role} (name) VALUES ('%s')", $text); |
---|
579 | } |
---|
580 | } |
---|
581 | drupal_set_message(t('The roles has been added.')); |
---|
582 | } |
---|
583 | |
---|
584 | function _ente_planificador_hierarchical_get_roles_type($tipo = 0) { |
---|
585 | $roles_type =array(); |
---|
586 | $roles_type['for'] = t('Enlace Formulador'); |
---|
587 | $roles_type['enl'] = t('Enlace Revisor'); |
---|
588 | $roles_type['sup'] = t('Supervisor'); |
---|
589 | return $roles_type; |
---|
590 | } |
---|
591 | |
---|
592 | function _ente_planificador_hierarchical_get_desc($nid, $father = 1, $level = 0) { |
---|
593 | $fathers = array(); |
---|
594 | //get fathers |
---|
595 | if ($father) { |
---|
596 | $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'; |
---|
597 | } |
---|
598 | else { |
---|
599 | //get childrens |
---|
600 | $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'; |
---|
601 | } |
---|
602 | $inputs = array(); |
---|
603 | $inputs[] = $nid; |
---|
604 | if ($level) { |
---|
605 | $sql .= ' AND father.level = %d'; |
---|
606 | $inputs[] = $level; |
---|
607 | } |
---|
608 | $sql .= ' ORDER BY father.level, n.title'; |
---|
609 | $query = db_query($sql, $inputs); |
---|
610 | while ($father = db_fetch_object($query)) { |
---|
611 | $fathers[$father->level] = array( |
---|
612 | 'title' => $father->title, |
---|
613 | 'nid' => $father->nid, |
---|
614 | ); |
---|
615 | } |
---|
616 | return $fathers; |
---|
617 | } |
---|
618 | function _ente_planificador_hierarchical_get_descbyid($nid, $father = 1, $level = 0) { |
---|
619 | $fathers = array(); |
---|
620 | //get fathers |
---|
621 | if ($father) { |
---|
622 | $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'; |
---|
623 | } |
---|
624 | else { |
---|
625 | //get childrens |
---|
626 | $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'; |
---|
627 | } |
---|
628 | $inputs = array(); |
---|
629 | $inputs[] = $nid; |
---|
630 | if ($level) { |
---|
631 | $sql .= ' AND father.level = %d'; |
---|
632 | $inputs[] = $level; |
---|
633 | } |
---|
634 | $sql .= ' ORDER BY father.level, n.title'; |
---|
635 | $query = db_query($sql, $inputs); |
---|
636 | while ($father = db_fetch_object($query)) { |
---|
637 | $fathers[$father->nid] = array( |
---|
638 | 'title' => $father->title, |
---|
639 | 'nid' => $father->nid, |
---|
640 | ); |
---|
641 | } |
---|
642 | return $fathers; |
---|
643 | } |
---|
644 | |
---|
645 | function _ente_planificador_hierarchical_get_children($nid, $level = 0) { |
---|
646 | $fathers = array(); |
---|
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 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'; |
---|
648 | $inputs = array(); |
---|
649 | $inputs[] = $nid; |
---|
650 | $inputs[] = $level; |
---|
651 | $sql .= ' ORDER BY father.level, n.title'; |
---|
652 | $query = db_query($sql, $inputs); |
---|
653 | while ($father = db_fetch_object($query)) { |
---|
654 | $fathers[$father->nid] = $father->title; |
---|
655 | } |
---|
656 | return $fathers; |
---|
657 | } |
---|
658 | |
---|
659 | |
---|
660 | /** |
---|
661 | * Implementation of proyectos_operativos_search_ac_display(). |
---|
662 | * Muestra la lista de proyectos disponibles. |
---|
663 | */ |
---|
664 | function ente_planificador_hierarchical_search_ac_display() { |
---|
665 | global $user; |
---|
666 | //add breadcrumb |
---|
667 | $breadcrumb = array(); |
---|
668 | $breadcrumb[] = l(t('Home'), '<front>'); |
---|
669 | $breadcrumb[] = t('Proyectos Operativos'); |
---|
670 | drupal_set_breadcrumb($breadcrumb); |
---|
671 | $current_time = time(); |
---|
672 | $tipo_plan = 'proyectos_operativos_formular'; |
---|
673 | $fecha = FALSE; |
---|
674 | $ente = usuario_tiene_ente($user->uid); |
---|
675 | $ente_planificador = 0; |
---|
676 | if ($ente && $ente->nid) { |
---|
677 | $ente_planificador = ente_planificador_leer_ente_planificadores($ente->nid); |
---|
678 | } |
---|
679 | $mi_fecha = ente_planificador_user_acceso_proceso($tipo_plan, $ente_planificador); |
---|
680 | if ($mi_fecha[1] + 86399 > $current_time && $mi_fecha[0] < $current_time) { |
---|
681 | $fecha = TRUE; |
---|
682 | } |
---|
683 | if (!$fecha) { |
---|
684 | muestra_mensaje($tipo_plan, $ente_planificador); |
---|
685 | } |
---|
686 | if ($fecha && $ente->nid) { |
---|
687 | muestra_mensaje($tipo_plan, $ente_planificador, 0); |
---|
688 | } |
---|
689 | if ($fecha && !$ente_planificador && !user_access('admin planificador')) { |
---|
690 | $fecha = FALSE; |
---|
691 | } |
---|
692 | $view_id = variable_get('ente_planificador_hierarchical_view', 'ente_planificador_hierarchical'); |
---|
693 | $view = views_get_view($view_id); |
---|
694 | $display_id = variable_get('ente_planificador_hierarchical_display', 'default'); |
---|
695 | $view->set_display($display_id); |
---|
696 | $view->override_path = $_GET['q']; |
---|
697 | $view->pre_execute(); |
---|
698 | $view->execute(); |
---|
699 | $output = $view->render(); |
---|
700 | if ($fecha) { |
---|
701 | $links = array(); |
---|
702 | drupal_alter('proyecto_obtiene_agregar_links', $links); |
---|
703 | $output .= '<div id="ente-planificador-agregar-proyecto">' . theme('item_list', $links) . '</div>'; |
---|
704 | } |
---|
705 | return $output; |
---|
706 | } |
---|
707 | |
---|
708 | /** |
---|
709 | * Implementation of hook_views_api(). |
---|
710 | */ |
---|
711 | function ente_planificador_hierarchical_views_api() { |
---|
712 | return array( |
---|
713 | 'api' => '2.0', |
---|
714 | 'path' => drupal_get_path('module', 'ente_planificador_hierarchical') . '/views', |
---|
715 | ); |
---|
716 | } |
---|