PluginProbe
ANAC XML Bandi di Gara / trunk
ANAC XML Bandi di Gara vtrunk
7.8 trunk 0.1 1.0.0.1 1.0.1 1.0.2 1.0.3 1.0.4 1.1 1.1.1 1.1.2 2.0 2.0.1 2.0.2 2.0.3 2.1 2.2 2.3 2.3.1 3 3.0.1 3.1 3.1.1 3.1.2 3.1.3 All 57 releases
avcp / avcp.php

avcp.php in ANAC XML Bandi di Gara trunk, at avcp.php

424 lines 18.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /*
3 Plugin Name: ANAC XML Bandi di Gara
4 Plugin URI: https://wordpress.org/plugins/avcp
5 Description: Generatore XML per ANAC (ex AVCP) e gestione bandi di gara e contratti (Legge 190/2012 art. 1.32 & D.Lgs 33/2013)
6 Author: Marco Milesi
7 Version: 7.8
8 Author URI: https://www.marcomilesi.com
9 */
10
11 add_action( 'init', 'register_cpt_avcp' );
12
13 function register_cpt_avcp() {
14
15 $labels = array(
16 'name' => 'Bandi di gara',
17 'singular_name' => _x( 'Gara', 'avcp' ),
18 'add_new' => _x( 'Nuova voce', 'avcp' ),
19 'add_new_item' => _x( 'Nuovo bando', 'avcp' ),
20 'edit_item' => _x( 'Modifica Gara', 'avcp' ),
21 'new_item' => _x( 'Nuovo Bando', 'avcp' ),
22 'view_item' => _x( 'Vedi Gara', 'avcp' ),
23 'search_items' => _x( 'Cerca Gara', 'avcp' ),
24 'not_found' => _x( 'Nessuna voce trovata', 'avcp' ),
25 'not_found_in_trash' => _x( 'Nessuna voce trovata', 'avcp' ),
26 'parent_item_colon' => _x( 'Parent Gara:', 'avcp' ),
27 'menu_name' => 'Bandi'
28 );
29
30 $get_avcp_abilita_ruoli = get_option('avcp_abilita_ruoli');
31 if ($get_avcp_abilita_ruoli == '1') {
32 $avcp_capability_type = 'gare_avcp';
33 $avcp_map_meta_cap_var = 'true';
34 $avcp_capabilities_array = array(
35 'publish_posts' => 'pubblicare_gara_avcp',
36 'edit_posts' => 'modificare_propri_gara_avcp',
37 'edit_others_posts' => 'modificare_altri_gara_avcp',
38 'delete_posts' => 'eliminare_propri_gara_avcp',
39 'delete_others_posts' => 'modificare_altri_gara_avcp',
40 'read_private_posts' => 'read_private_avcp',
41 'edit_post' => 'modificare_gara_avcp',
42 'delete_post' => 'eliminare_gara_avcp',
43 'read_post' => 'leggere_gara_avcp',
44 );
45 } else {
46 $avcp_capability_type = 'post';
47 $avcp_map_meta_cap_var = 'false';
48 }
49
50 $args = array(
51 'labels' => $labels,
52 'hierarchical' => false,
53 'description' => 'Gare AVCP',
54 'supports' => array( 'title', 'custom-fields', 'editor', 'revisions', 'post_tag' ),
55 'taxonomies' => array( 'ditte' ),
56 'public' => true,
57 'show_ui' => true,
58 'show_in_menu' => true,
59 'menu_position' => 37,
60 'menu_icon' => 'dashicons-portfolio',
61 'show_in_nav_menus' => false,
62 'publicly_queryable' => true,
63 'exclude_from_search' => false,
64 'has_archive' => true,
65 'query_var' => true,
66 'can_export' => true,
67 'rewrite' => true,
68 'capability_type' => $avcp_capability_type,
69 'map_meta_cap' => $avcp_map_meta_cap_var
70 );
71
72 register_post_type( 'avcp', $args );
73 }
74
75 add_action( 'init', function () {
76
77 register_taxonomy(
78 'ditte',
79 array('avcp'),
80 array(
81 'labels' => array(
82 'name' => _x( 'Ditte partecipanti', 'ditte' ),
83 'singular_name' => _x( 'Ditte', 'ditte' ),
84 'search_items' => _x( 'Cerca Ditta', 'ditte' ),
85 'popular_items' => _x( 'Ditte più usate', 'ditte' ),
86 'all_items' => _x( 'Tutte le ditte', 'ditte' ),
87 'parent_item' => _x( 'Parent Ditte', 'ditte' ),
88 'parent_item_colon' => _x( 'Parent Ditte:', 'ditte' ),
89 'edit_item' => _x( 'Edit Ditte', 'ditte' ),
90 'update_item' => _x( 'Update Ditte', 'ditte' ),
91 'add_new_item' => _x( 'Nuova Ditta', 'ditte' ),
92 'new_item_name' => _x( 'Nuova Ditte', 'ditte' ),
93 'separate_items_with_commas' => _x( 'Separate ditta with commas', 'ditte' ),
94 'add_or_remove_items' => _x( 'Add or remove ditta', 'ditte' ),
95 'choose_from_most_used' => _x( 'Choose from the most used ditta', 'ditte' ),
96 'menu_name' => _x( 'Ditte', 'ditte' ),
97 ),
98 'public' => true,
99 'show_in_nav_menus' => false,
100 'show_ui' => true,
101 'show_tagcloud' => false,
102 'show_admin_column' => true,
103 'hierarchical' => true,
104 'rewrite' => true,
105 'query_var' => true
106 )
107 );
108
109
110 register_taxonomy(
111 'annirif',
112 array('avcp'),
113 array(
114 'labels' => array(
115 'name' => _x( 'Anno Riferimento', 'annirif' ),
116 'singular_name' => _x( 'Anno Riferimento', 'annirif' ),
117 'search_items' => _x( 'Cerca Anno', 'annirif' ),
118 'popular_items' => _x( 'Anni più Usati', 'annirif' ),
119 'all_items' => _x( 'Tutti gli anni', 'annirif' ),
120 'parent_item' => _x( 'Parent Anni', 'annirif' ),
121 'parent_item_colon' => _x( 'Parent Anno:', 'annirif' ),
122 'edit_item' => _x( 'Modifica Anno', 'annirif' ),
123 'update_item' => _x( 'Aggiorna Anno', 'annirif' ),
124 'add_new_item' => _x( 'Nuovo Anno', 'annirif' ),
125 'new_item_name' => _x( 'Nuovo Anno', 'annirif' ),
126 'separate_items_with_commas' => _x( 'Separate anno with commas', 'annirif' ),
127 'add_or_remove_items' => _x( 'Add or remove anno', 'annirif' ),
128 'choose_from_most_used' => _x( 'Choose from the most used years', 'annirif' ),
129 'menu_name' => _x( 'Anni', 'annirif' ),
130 ),
131 'public' => true,
132 'show_in_nav_menus' => true,
133 'show_ui' => true,
134 'show_tagcloud' => false,
135 'show_admin_column' => true,
136 'hierarchical' => true,
137 'rewrite' => true,
138 'capabilities' => array('manage_terms' => 'blocked_avcp','edit_terms' => 'blocked_avcp','delete_terms' => 'blocked_avcp'),
139 'query_var' => true
140 )
141 );
142
143 register_taxonomy(
144 'areesettori',
145 array('incarico', 'spesa', 'avcp', 'amm-trasparente'),
146 array(
147 'labels' => array(
148 'name' => _x( 'Uffici - Settori - Centri di costo', 'areesettori' ),
149 'singular_name' => _x( 'Settore - Centro di costo', 'areesettori' ),
150 'search_items' => _x( 'Cerca in Settori - Centri di costo', 'areesettori' ),
151 'popular_items' => _x( 'Settori - Centri di costo Più usati', 'areesettori' ),
152 'all_items' => _x( 'Tutti i Centri di costo', 'areesettori' ),
153 'parent_item' => _x( 'Parent Settore - Centro di costo', 'areesettori' ),
154 'parent_item_colon' => _x( 'Parent Settore - Centro di costo:', 'areesettori' ),
155 'edit_item' => _x( 'Modifica Settore - Centro di costo', 'areesettori' ),
156 'update_item' => _x( 'Aggiorna Settore - Centro di costo', 'areesettori' ),
157 'add_new_item' => _x( 'Aggiungi Nuovo Settore - Centro di costo', 'areesettori' ),
158 'new_item_name' => _x( 'Nuovo Settore - Centro di costo', 'areesettori' ),
159 'separate_items_with_commas' => _x( 'Separate settori - centri di costo with commas', 'areesettori' ),
160 'add_or_remove_items' => _x( 'Add or remove settori - centri di costo', 'areesettori' ),
161 'choose_from_most_used' => _x( 'Choose from the most used settori - centri di costo', 'areesettori' ),
162 'menu_name' => _x( 'Uffici & Settori', 'areesettori' ),
163 ),
164 'public' => true,
165 'show_in_nav_menus' => false,
166 'show_ui' => true,
167 'show_tagcloud' => false,
168 'show_admin_column' => true,
169 'hierarchical' => true,
170
171 'rewrite' => true,
172 'query_var' => true
173 )
174 );
175 } );
176
177 add_action('save_post', 'save_at_gara_posts',10,2);
178 function save_at_gara_posts($post_id) {
179
180 if ( (get_option('avcp_autopublish') == '1') && (get_post_type($post_id ) == 'avcp') ) {
181
182 $terms = wp_get_post_terms($post_id, 'annirif');
183
184 $verificafilecreati = '';
185 if ( count($terms) > 0 ) {
186 //require_once(plugin_dir_path(__FILE__) . 'avcp_xml_generator.php');
187 foreach ( $terms as $term ) {
188 creafilexml ($term->name);
189 $verificafilecreati = $term->name . ' &bull; ' . $verificafilecreati;
190 }
191 anac_add_log('Generazione automatica: '.$verificafilecreati, 0);
192
193 }
194 }
195 }
196
197 /* =========== Cambio Titolo Custom Post =========== */
198 add_filter('enter_title_here', function($title) {
199 $screen = get_current_screen();
200 if ('avcp' == $screen->post_type) {
201 $title = 'Oggetto del Bando di Gara';
202 }
203 return $title;
204 });
205
206 /* =========== SHORTCODE ============ */
207
208 function avcp_func($atts)
209 {
210 extract(shortcode_atts(array('anno' => 'all'), $atts));
211
212 ob_start();
213 include(plugin_dir_path(__FILE__) . 'tablegen.php');
214 $atshortcode = ob_get_clean();
215 return $atshortcode;
216 }
217 add_shortcode('avcp', 'avcp_func');
218 add_shortcode('anac', 'avcp_func');
219 add_shortcode('gare', 'avcp_func');
220
221 function anac_add_log($azione, $errore) {
222 if ($errore) { $err = ' style="color:red;"'; } else { $err = ''; }
223 update_option('anac_log', get_option('anac_log') . '<br>' . current_time('d/m/Y - H:i') . ' <strong'.$err.'>'.$azione.'</strong>');
224 }
225
226 add_action( 'init', 'atg_caricamoduli' );
227 function atg_caricamoduli() {
228 require_once(plugin_dir_path(__FILE__) . 'avcp_create_taxonomy.php');
229 require_once(plugin_dir_path(__FILE__) . 'tax-meta-class/Tax-meta-class.php');
230 require_once(plugin_dir_path(__FILE__) . 'avcp_taxonomy_fields.php');
231 require_once(plugin_dir_path(__FILE__) . 'avcp_metabox_generator.php');
232 require_once(plugin_dir_path(__FILE__) . 'avcp_index_generator.php');
233 require_once(plugin_dir_path(__FILE__) . 'singlehack.php');
234 require_once(plugin_dir_path(__FILE__) . 'avcp_xml_generator.php');
235 require_once(plugin_dir_path(__FILE__) . 'opendata/loader.php');
236
237 //Funzioni
238 require_once(plugin_dir_path(__FILE__) . 'getsommeliquidate.php');
239
240 //Include sistemi di validazione
241 require_once(plugin_dir_path(__FILE__) . 'valid_page.php');
242 global $typenow;
243 if ($typenow == 'avcp') {
244 add_filter( 'manage_posts_custom_column', 'avcp_modify_post_table_row', 10, 2 );
245 add_filter( 'manage_posts_custom_column', 'avcp_modify_post_table' );
246 }
247 }
248
249
250 add_action('admin_enqueue_scripts', function( $hook ) {
251
252 global $post;
253 if ( ('post-new.php' == $hook || 'post.php' == $hook) && 'avcp' === $post->post_type ) {
254 wp_register_style( 'avcp_style', plugins_url('avcp/includes/avcp_admin.css') );
255 wp_enqueue_style( 'avcp_style');
256
257 wp_enqueue_script( 'avcp_functions', plugins_url('avcp/includes/avcp_functions.js'), array( 'jquery' ) );
258
259
260 wp_register_script('avcp_searchTaxonomyGT_at_js', plugins_url('includes/searchTaxonomyGT.js', __FILE__));
261 wp_enqueue_script('avcp_searchTaxonomyGT_at_js');
262 }
263 });
264
265 add_action('admin_notices', function() {
266 global $current_user ;
267 global $current_screen;
268 $user_id = $current_user->ID;
269
270 if (get_option('avcp_denominazione_ente') == null || get_option('avcp_codicefiscale_ente') == null) {
271 echo '<div class="error"><p><strong>ANAC XML</strong>: alcuni dati dell\'ente non sono stati specificati in <strong>WPGov.it >> XML Bandi di Gara</strong></b></a></div>';
272 }
273
274 if ( 'ditte' == $current_screen->taxonomy ) {
275 echo '<div class="updated"><p>Attenzione: ogni modifica effettuata a una ditta si applica anche alle gare già pubblicate!<br/>Nel caso di cambio partita iva o denominazione, creare una nuova ditta.</p></div>';
276 } else if ( 'areesettori' == $current_screen->taxonomy ) {
277 echo '<div class="updated"><p>Attenzione: ogni modifica effettuata a un settore-centro di costo si applica anche alle gare già pubblicate!</p></div>';
278 }
279 });
280
281 add_action( 'admin_init', 'AVCP_ADMIN_LOAD');
282 function AVCP_ADMIN_LOAD () {
283
284 require_once(plugin_dir_path(__FILE__) . 'taxfilteringbackend.php');
285
286 register_setting( 'avcp_options', 'avcp_version_number');
287 register_setting( 'avcp_options', 'avcp_denominazione_ente');
288 register_setting( 'avcp_options', 'avcp_codicefiscale_ente');
289 register_setting( 'avcp_options', 'avcp_autopublish');
290 register_setting( 'avcp_options', 'avcp_dis_archivioditte');
291 register_setting( 'avcp_options', 'avcp_dis_archivioanni');
292 register_setting( 'avcp_options', 'avcp_tab_jqueryui');
293 register_setting( 'avcp_options', 'avcp_showxml');
294 register_setting( 'avcp_options', 'avcp_showlove');
295 register_setting( 'avcp_options', 'avcp_enable_editor');
296 register_setting( 'avcp_options', 'avcp_abilita_ruoli');
297 register_setting( 'avcp_options', 'avcp_centricosto');
298 register_setting( 'avcp_options', 'avcp_export');
299 register_setting( 'avcp_options', 'avcp_dataset_capability');
300
301
302
303 require_once(plugin_dir_path(__FILE__) . 'pannelli/import.php');
304
305 //Controllo Versione e Utilità
306 $arraya_anac_v = get_plugin_data ( __FILE__ );
307 $nuova_versione_anac = $arraya_anac_v['Version'];
308
309 $versione_attuale_anac = get_option('avcp_version_number');
310 if ($versione_attuale_anac == '') {
311 update_option( 'avcp_version_number', $nuova_versione_anac );
312 crea_anni();
313 avcp_activate();
314 } else if (version_compare($versione_attuale_anac, $nuova_versione_anac, '<') == '1') {
315 crea_anni();
316 avcp_activate();
317 require_once(plugin_dir_path(__FILE__) . 'update.php');
318 update_option( 'avcp_version_number', $nuova_versione_anac );
319 anac_add_log('Aggiornato plugin ' . $nuova_versione_anac, 0);
320 }
321 delete_option('avcp_invalid');
322 }
323
324 function crea_anni() {
325
326 for( $x = 2013; $x <= 2030; $x++) {
327 $termcheck = term_exists( (string) $x, 'annirif' );
328 if ( ! $termcheck ) {
329 wp_insert_term( $x, 'annirif');
330 anac_add_log('Aggiunto anno di riferimento <strong>'.$x.'</strong>', 0);
331 }
332 }
333 }
334
335 add_action('admin_menu', function() {
336
337 if ( !wp_count_posts( 'avcp' ) || wp_count_posts( 'avcp')->publish == 0 ) {
338 add_submenu_page('edit.php?post_type=avcp', 'Importa', 'Importa', 'manage_options', 'anac_import', 'anac_import_load');
339 }
340
341 if (!get_option('avcp_dataset_capability')) {
342 $anac_menu_cap = 'manage_options';
343 } else {
344 $anac_menu_cap = get_option('avcp_dataset_capability');
345 }
346
347 add_submenu_page('edit.php?post_type=avcp', 'Validazione', 'Validazione', $anac_menu_cap, 'avcp_v_dataset', 'avcp_v_dataset_load'); //valid_page.php
348
349 add_submenu_page( 'edit.php?post_type=avcp', 'Impostazioni', 'Impostazioni', 'publish_posts', 'wpgov_avcp', function() { include(plugin_dir_path(__FILE__) . 'settings.php'); } );
350
351 });
352
353 function avcp_activate() {
354 $srcfile= ABSPATH . 'wp-content/plugins/avcp/includes/index.php.null';
355 $dstfile= avcp_get_basexmlpath() . 'index.php';
356 if ( ! is_dir( dirname( $dstfile ) ) ) {
357 mkdir( dirname( $dstfile ), 0755, true );
358 }
359 copy($srcfile, $dstfile);
360 chmod($dstfile, 0755);
361 }
362
363 function avcp_deactivate() {
364 unlink(ABSPATH . 'avcp/index.php');
365 }
366 register_deactivation_hook( __FILE__, 'avcp_deactivate' );
367
368
369 function avcp_get_contraente($input) {
370 $tipi_contraente = array(
371 array('01','01-PROCEDURA APERTA'),
372 array('02','02-PROCEDURA RISTRETTA'),
373 array('03','03-PROCEDURA NEGOZIATA PREVIA PUBBLICAZIONE'),
374 array('04','04-PROCEDURA NEGOZIATA SENZA PREVIA PUBBLICAZIONE'),
375 array('05','05-DIALOGO COMPETITIVO'),
376 array('06','06-PROCEDURA NEGOZIATA SENZA PREVIA INDIZIONE DI GARA (SETTORI SPECIALI)'),
377 array('07','07-SISTEMA DINAMICO DI ACQUISIZIONE'),
378 array('08','08-AFFIDAMENTO IN ECONOMIA - COTTIMO FIDUCIARIO'),
379 array('14','14-PROCEDURA SELETTIVA EX ART 238 C.7, D.LGS. 163/2006'),
380 array('17','17-AFFIDAMENTO DIRETTO EX ART. 5 DELLA LEGGE 381/91'),
381 array('21','21-PROCEDURA RISTRETTA DERIVANTE DA AVVISI CON CUI SI INDICE LA GARA'),
382 array('22','22-PROCEDURA NEGOZIATA CON PREVIA INDIZIONE DI GARA (SETTORI SPECIALI)'),
383 array('23','23-AFFIDAMENTO DIRETTO'),
384 array('24','24-AFFIDAMENTO DIRETTO A SOCIETA\' IN HOUSE'),
385 array('25','25-AFFIDAMENTO DIRETTO A SOCIETA\' RAGGRUPPATE/CONSORZIATE O CONTROLLATE NELLE CONCESSIONI E NEI PARTENARIATI'),
386 array('26','26-AFFIDAMENTO DIRETTO IN ADESIONE AD ACCORDO QUADRO/CONVENZIONE'),
387 array('27','27-CONFRONTO COMPETITIVO IN ADESIONE AD ACCORDO QUADRO/CONVENZIONE'),
388 array('28','28-PROCEDURA AI SENSI DEI REGOLAMENTI DEGLI ORGANI COSTITUZIONALI'),
389 array('29','29-PROCEDURA RISTRETTA SEMPLIFICATA'),
390 array('30','30-PROCEDURA DERIVANTE DA LEGGE REGIONALE'),
391 array('31','31-AFFIDAMENTO DIRETTO PER VARIANTE SUPERIORE AL 20% DELL\'IMPORTO CONTRATTUALE'),
392 array('32','32-AFFIDAMENTO RISERVATO'),
393 array('33','33-PROCEDURA NEGOZIATA PER AFFIDAMENTI SOTTO SOGLIA'),
394 array('34','34-PROCEDURA ART.16 COMMA 2-BIS DPR 380/2001 PER OPERE URBANIZZAZIONE A SCOMPUTO PRIMARIE SOTTO SOGLIA COMUNITARIA'),
395 array('35','35-PARTERNARIATO PER L’INNOVAZIONE'),
396 array('36','36-AFFIDAMENTO DIRETTO PER LAVORI, SERVIZI O FORNITURE SUPPLEMENTARI'),
397 array('37','37-PROCEDURA COMPETITIVA CON NEGOZIAZIONE'),
398 array('38','38-PROCEDURA DISCIPLINATA DA REGOLAMENTO INTERNO PER SETTORI SPECIALI'),
399 );
400 foreach ( $tipi_contraente as $tc ) {
401 if ( substr($input, 0, 2) == $tc[0] ) {
402 return $tc[1];
403 }
404 }
405 return "Non definito";
406 }
407 function avcp_get_basexmlurl($year = 0) {
408 $base = apply_filters( 'anac_filter_basexmlurl', get_site_url() . '/avcp/' );
409 if ( $year ) {
410 return $base . $year.'.xml';
411 } else {
412 return $base;
413 }
414 }
415 function avcp_get_basexmlpath($year = 0) {
416 $base = apply_filters( 'anac_filter_basexmlpath', ABSPATH . 'avcp/' );
417 if ( $year ) {
418 return $base . $year . '.xml';
419 } else {
420 return $base;
421 }
422 }
423
424 ?>