· 6 years ago · Jun 26, 2019, 06:10 PM
1<?php
2/*
3 * Plugin Name: subvention
4 * Plugin URI: http://localhost
5 * Description: This is a plugin to handle and manage the subvention
6 * Version: 1.0
7 * Author: BAH Mamadou Mountagha
8 * Author URI: http://localhost
9 *
10 * */
11
12
13function subvention_create_table(){
14 global $wpdb;
15 $form_table_name = $wpdb->prefix.'db7_forms';
16 $table_name = $wpdb->prefix.'subvention';
17 $charset_collate = $wpdb->get_charset_collate();
18
19
20 $sql = "CREATE TABLE IF NOT EXISTS $table_name (
21 subvention_id bigint(20) NOT NULL AUTO_INCREMENT,
22 form_id bigint(20) NOT NULL,
23 subvention_somme bigint(20),
24 PRIMARY KEY (subvention_id),
25 FOREIGN KEY (form_id) REFERENCES $form_table_name(form_id)
26 )$charset_collate;";
27
28 require_once( ABSPATH . 'wp-admin/includes/upgrade.php');
29 dbDelta($sql);
30
31}
32
33function subvention_on_activate(){
34
35 subvention_create_table();
36}
37
38register_activation_hook(__FILE__, 'subvention_on_activate');
39
40function subvention_on_deactivate(){
41
42 global $wpdb;
43 $wpdb->query("DROP TABLE IF EXISTS {$wpdb->prefix}subvention;");
44}
45
46//register_deactivation_hook(__FILE__, 'subvention_on_deactivate');
47
48function test_hook_cfdb7(){
49 global $wpdb;
50 $table_cfdb7 = $wpdb->prefix.'db7_forms';
51 $row = $wpdb->get_row("SELECT * FROM $table_cfdb7 ORDER BY form_id DESC LIMIT 1;");
52 $form_id = $row->form_id;
53 $wpdb->insert("{$wpdb->prefix}subvention", array('form_id' => $form_id, 'subvention_somme' => 0));
54}
55add_action('cfdb7_after_save_data', 'test_hook_cfdb7');
56
57
58function subvention_menu(){
59 add_menu_page('Subventions', 'Subventions', 'administrator', 'subvention.php', 'subvention_setting_page');
60 // create sub menus
61 //add_submenu_page('subvention.php', 'Subventions', 'All', 'administrator', 'subvention_all_slug', 'subvention_setting_page');
62 add_submenu_page('subvention.php', 'Subventions', 'Subventioner', 'administrator', 'subvention_confirm_form.php','subvention_form');
63}
64add_action('admin_menu', 'subvention_menu', 11);
65
66require_once('subvention_list_table.php');
67//require_once ('subvention_form_details.php');
68require_once ('subvention_delete_sub_links.php');
69
70function subvention_setting_page(){
71
72 if ( !is_plugin_active('contact-form-cfdb7/contact-form-cfdb-7.php') ) {
73 die('Vous devez activer le plugin contact form database');
74 }
75
76 $subvention_list_table = new Subvention_List_Table();
77
78 $form_id = $_GET['form_id'];
79 $action = $_GET['action'];
80
81 if(isset($form_id) && isset($action))
82 {
83 //new subvention_form_details();
84 //return;
85 //new subvention_delete_sub_links();
86 $subvention_list_table->process_actions($form_id,$action);
87 return;
88 }
89
90 //$subvention_list_table = new Subvention_List_Table();
91
92 $subvention_list_table->prepare_items();
93 ?>
94 <div class="wrap">
95 <div id="icon-users" class="icon32"></div>
96 <h2>Subventions</h2>
97 <?php $subvention_list_table->display(); ?>
98 </div>
99 <?php
100
101}
102add_action('template_redirect', 'subvention_form');
103function subvention_form()
104{
105 wp_safe_redirect("https://localhost/rel/wp-admin/admin.php?page=subvention_confirm_form.php", 301);
106 exit();
107}
108?>