<?php
    /**
     * Plugin Name:         Club Alpin Suisse de Sion
     * Plugin URI:          https://www.digitalteamacademy.ch/
     * Description:         Module spécifique à la gestion du Club Alpin Suisse de Sion.
     * Version:             1.0.0
     * Text Domain:         wp-cass
     * Author:              DTA - Digital Team Academy
     * Author URI: https://www.digitalteamacademy.ch/   
     * Domain Path: /public/lang
     * Requires at least: 6.0
     * Require PHP: 5.6  
     */

    //Defines
    require_once plugin_dir_path(__FILE__) . 'ressources/extern/autoload.php';

    //Required files
    require_once plugin_dir_path(__FILE__) . 'src/admin/dashboard-menu.php';
    require_once plugin_dir_path(__FILE__) . 'src/admin/user-profile-extension.php';
    require_once plugin_dir_path(__FILE__) . 'src/default/default.php';
    require_once plugin_dir_path(__FILE__) . 'config.php';
    require_once plugin_dir_path(__FILE__) . 'src/database/initialize.php';
    require_once plugin_dir_path(__FILE__) . 'src/database/drop.php';
    require_once plugin_dir_path(__FILE__) . 'src/database/insert.php';
    require_once plugin_dir_path(__FILE__) . 'src/admin/views/group/view-group-list.php';
    require_once plugin_dir_path(__FILE__) . 'src/admin/views/group/view-group-edit.php';
    require_once plugin_dir_path(__FILE__) . 'src/admin/views/material/view-material-list.php';
    require_once plugin_dir_path(__FILE__) . 'src/admin/views/material/view-material-edit.php';
    require_once plugin_dir_path(__FILE__) . 'src/admin/views/dashboard/view-dashboard.php';
    require_once plugin_dir_path(__FILE__) . 'src/admin/views/season/view-season-list.php';
    require_once plugin_dir_path(__FILE__) . 'src/admin/views/season/view-season-edit.php';
    require_once plugin_dir_path(__FILE__) . 'src/admin/views/type/view-type-list.php';
    require_once plugin_dir_path(__FILE__) . 'src/admin/views/type/view-type-edit.php';
    require_once plugin_dir_path(__FILE__) . 'src/admin/views/race/view-race-list.php';
    require_once plugin_dir_path(__FILE__) . 'src/admin/views/member/view-member-list.php';
    require_once plugin_dir_path(__FILE__) . 'src/admin/views/race/view-race-edit.php';
    require_once plugin_dir_path(__FILE__) . 'src/admin/views/race_user/view-race-user-list.php';
    require_once plugin_dir_path(__FILE__) . 'src/admin/views/race_user/view-race-user-edit.php';
    require_once plugin_dir_path(__FILE__) . 'src/admin/views/race_leader/view-race-leader-list.php';
    require_once plugin_dir_path(__FILE__) . 'src/admin/views/race_leader/view-race-leader-all-courses-list.php';
    require_once plugin_dir_path(__FILE__) . 'src/admin/views/race_user/view-race-user-all-courses-list.php';
    require_once plugin_dir_path(__FILE__) . 'src/admin/views/race/view-race-editmaterial.php';
    require_once plugin_dir_path(__FILE__) . 'src/admin/views/setting/view-setting-edit.php';
    require_once plugin_dir_path(__FILE__) . 'src/frontend/cass-shortcode-calendar-global.php';
    require_once plugin_dir_path(__FILE__) . 'src/frontend/actions/cass-shortcode-member-register.php';
    require_once plugin_dir_path(__FILE__) . 'src/frontend/cass-shortcode-member-register.php';
    require_once plugin_dir_path(__FILE__) . 'src/class/setting/Setting.php';
    require_once plugin_dir_path(__FILE__) . 'src/class/group/Group.php';
    require_once plugin_dir_path(__FILE__) . 'src/class/Type/Type.php';
    require_once plugin_dir_path(__FILE__) . 'src/class/level/Level.php';
    require_once plugin_dir_path(__FILE__) . 'src/class/material/Material.php';
    require_once plugin_dir_path(__FILE__) . 'src/class/race/Race_User.php';
    require_once plugin_dir_path(__FILE__) . 'src/class/race/Race_Material.php';
    require_once plugin_dir_path(__FILE__) . 'src/class/race/Race.php';
    
    require_once plugin_dir_path(__FILE__) . 'src/class/member/Member.php';
    require_once plugin_dir_path(__FILE__) . 'src/class/season/Season.php';
    require_once plugin_dir_path(__FILE__) . 'src/library/functions.php';
    require_once plugin_dir_path(__FILE__) . 'src/frontend/cass-shortcode-calendar-global.php';
    require_once plugin_dir_path(__FILE__) . 'src/frontend/cass-shortcode-member-courses-list-subscribed.php';
    require_once plugin_dir_path(__FILE__) . 'src/admin/views/level/view-level-edit.php';
    require_once plugin_dir_path(__FILE__) . 'src/admin/views/level/view-level-list.php';
    require_once plugin_dir_path(__FILE__) . 'src/frontend/cass-shortcode-course-info.php';
    require_once plugin_dir_path(__FILE__) . 'src/frontend/actions/cass-shortcode-course-info.php';
    

    require_once plugin_dir_path(__FILE__) . 'src/class/mailer/mailer.php';
    require_once plugin_dir_path(__FILE__) . 'src/class/dashboard/Dashboard.php';

    require_once plugin_dir_path(__FILE__) . 'ressources/extern/simplexlsxgen/SimpleXLSXGen.php';
    require_once plugin_dir_path(__FILE__) . 'ressources/extern/simplexlsx/SimpleXLSX.php';

    require_once plugin_dir_path(__FILE__) . 'src/api/api-cass-global.php';
    require_once plugin_dir_path(__FILE__) . 'src/api/api-cass-signedup.php';
    require_once plugin_dir_path(__FILE__) . 'src/api/dashboard.php';
    require_once plugin_dir_path(__FILE__) . 'src/api/security.php';

    require_once plugin_dir_path(__FILE__) . 'src/api/api-cass-shortcode-member-courses-list.php';

    // If this file is called directly, abort.
    if (!defined('WPINC')) {
        die;
    }

    //cass_database_drop();

    //Configuration of plugin
    CASS_Config::execute();

    //Configure the default actions of environnement (activation, deactivation,...)
    CASS_Default::execute();

    //Configure the settings page of settings section of admin dashboard
    //CASS_Settings::execute(); --> Use the menu page

    //Configure the menus of admin dashboard
    CASS_Dashboard_Menu::execute();

    //Extend the user profile page
    CASS_User_Profile_Extention::execute();

    //Execute temporary the sql script
    cass_database_initialize();

    //cass_database_sample_insert();




    //Test
    add_role("CASS_RL", "CASS - Chef de course");
    add_role("CASS_MEMBER", "CASS - Membre");


    global $wp_roles;
    $wp_roles->roles['CASS_MEMBER']['name'] = 'CASS - Membre';
    $wp_roles->roles['CASS_RL']['name'] = 'CASS - Chef de course';
    $wp_roles->roles['CASS_ADMIN']['name'] = 'CASS - Administrateur';

    $role = get_role("CASS_MEMBER");
    $role->add_cap("read"); //Access to dashboard

    //Add CSS
    wp_enqueue_style('cass-style', plugins_url('public/css/cass.css', __FILE__), false, '1.0', 'all'); // Inside a plugin
    //wp_enqueue_style( 'bootstrap', plugins_url( 'public/css/bootstrap.min.css', __FILE__ ), false, '1.0', 'all' ); // Inside a plugin
    wp_enqueue_style('purecss', plugins_url('public/css/pure-min.css', __FILE__), false, '1.0', 'all'); // Inside a plugin

/*    wp_register_script('popper', plugin_dir_url(__FILE__) . 'public/js/popper.min.js');
    WP_enqueue_script('popper');;

    wp_register_script('tippy', plugin_dir_url(__FILE__) . 'public/js/tippy-bundle.umd.min.js');
    WP_enqueue_script('tippy');*/

    wp_register_script('cassjs', 'https://cdn.jsdelivr.net/npm/vue/dist/vue.min.js');
    WP_enqueue_script('cassjs');


    wp_register_script('vuejs', plugin_dir_url(__FILE__) . 'public/js/cass.js');
    WP_enqueue_script('vuejs');
    
    wp_register_script('tinymce', plugin_dir_url(__FILE__) . 'public/tinymce/tinymce.min.js');
    WP_enqueue_script('tinymce');


    wp_register_script('axioshttp', 'https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js');
    WP_enqueue_script('axioshttp');

    wp_register_script('chartjs', plugin_dir_url(__FILE__) . 'public/js/chart.js');
    WP_enqueue_script('chartjs');

    wp_register_script('calendarjs', plugin_dir_url(__FILE__) . 'public/js/calendarjs.js');
    WP_enqueue_script('calendarjs');

    wp_register_script('shortcode_member_courses_list_subscribed', plugin_dir_url(__FILE__) . 'src/frontend/cass-shortcode-member-courses-list-subscribed.js', array(), null, true);
    wp_enqueue_script('shortcode_member_courses_list_subscribed');

    wp_register_script('shortcode_calendar_global', plugin_dir_url(__FILE__) . 'src/frontend/cass-shortcode-calendar-global.js', array(), null, true);
    wp_enqueue_script('shortcode_calendar_global');

    wp_register_script('shortcode_info_course', plugin_dir_url(__FILE__) . 'src/frontend/cass-shortcode-course-info.js', array(), null, true);
    wp_enqueue_script('shortcode_info_course');


    wp_register_script('cass_member_register', plugin_dir_url(__FILE__) . 'src/frontend/cass-shortcode-member-register.js', array(), null, true);
    wp_enqueue_script('cass_member_register');

    wp_register_script('cass_admin_dashboard', plugin_dir_url(__FILE__) . 'src/admin/views/dashboard/view-dashboard.js', array(), null, true);
    wp_enqueue_script('cass_admin_dashboard');



    function add_cass_capabilities() {
        $role = get_role('administrator');
        $role->add_cap('cass_admin');
        $role->add_cap('cass_rl');

        $role = get_role('CASS_RL');
        $role->add_cap('cass_rl');

        $role = get_role('CASS_ADMIN');
        $role->add_cap('cass_admin');
        $role->add_cap('cass_rl');
    }

    // Action pour exécuter la fonction lors de l'initialisation de WordPress
    add_action('init', 'add_cass_capabilities');

