--- a/simple-calendar-for-elementor/miga_simple_calendar.php
+++ b/simple-calendar-for-elementor/miga_simple_calendar.php
@@ -10,7 +10,7 @@
* @wordpress-plugin
* Plugin Name: Simple calendar for Elementor
* Description: Simple calendar plugin for Elementor to show e.g. availability on different days.
- * Version: 1.6.6
+ * Version: 1.6.7
* Requires at least: 5.2
* Requires PHP: 7.2
* Author: Michael Gangolf
@@ -112,11 +112,8 @@
add_action("wp_ajax_miga_custom_post_filter_cal", "miga_ajax_functions_cal");
add_action("wp_ajax_nopriv_miga_custom_post_filter_cal", "miga_ajax_functions_cal");
add_action("wp_ajax_miga_editor_cal", "miga_ajax_editor_cal");
-add_action("wp_ajax_nopriv_miga_editor_cal", "miga_ajax_editor_cal");
add_action("wp_ajax_miga_editor_cal_delete", "miga_ajax_editor_cal_delete");
-add_action("wp_ajax_nopriv_miga_editor_cal_delete","miga_ajax_editor_cal_delete");
add_action("wp_ajax_miga_editor_cal_update", "miga_ajax_editor_cal_update");
-add_action("wp_ajax_nopriv_miga_editor_cal_update","miga_ajax_editor_cal_update");
add_shortcode('simple-calendar-for-elementor', 'simple_calendar_for_elementor_shortcode');
--- a/simple-calendar-for-elementor/trunk/miga_simple_calendar.php
+++ b/simple-calendar-for-elementor/trunk/miga_simple_calendar.php
@@ -0,0 +1,229 @@
+<?php
+/**
+ * Plugin Name
+ *
+ * @package PluginPackage
+ * @author Michael Gangolf
+ * @copyright 2022 Michael Gangolf
+ * @license GPL-2.0-or-later
+ *
+ * @wordpress-plugin
+ * Plugin Name: Simple calendar for Elementor
+ * Description: Simple calendar plugin for Elementor to show e.g. availability on different days.
+ * Version: 1.6.7
+ * Requires at least: 5.2
+ * Requires PHP: 7.2
+ * Author: Michael Gangolf
+ * Author URI: https://www.migaweb.de/
+ * License: GPL v2 or later
+ * License URI: http://www.gnu.org/licenses/gpl-2.0.txt
+ * Text Domain: simple-calendar-for-elementor
+ * Domain Path: /languages
+ */
+
+global $wpdb;
+defined("TABLE_NAME_MIGA_CAL_EVENTS") or
+ define("TABLE_NAME_MIGA_CAL_EVENTS", $wpdb->prefix . "miga_calendar_events");
+
+defined("TABLE_NAME_MIGA_CAL_CALENDAR") or
+ define("TABLE_NAME_MIGA_CAL_CALENDAR", $wpdb->prefix . "miga_calendar_calendar");
+
+defined("TABLE_NAME_MIGA_CAL_STATUS") or
+ define("TABLE_NAME_MIGA_CAL_STATUS", $wpdb->prefix . "miga_calendar_status");
+
+use ElementorPlugin;
+
+add_action("init", static function () {
+ if (!did_action("elementor/loaded")) {
+ return false;
+ }
+ require_once __DIR__ . "/widget/includes/month.php";
+ require_once __DIR__ . "/widget/includes/backend_functions.php";
+ require_once __DIR__ . "/widget/elementor_calendar.php";
+ require_once __DIR__ . "/widget/elementor_calendar_legend.php";
+ ElementorPlugin::instance()->widgets_manager->register_widget_type(
+ new MIGA_Simple_Calendar()
+ );
+ ElementorPlugin::instance()->widgets_manager->register_widget_type(
+ new MIGA_Simple_Calendar_Legend()
+ );
+
+ load_plugin_textdomain('simple-calendar-for-elementor', false, dirname(plugin_basename(__FILE__)) . '/languages');
+});
+
+function miga_calendar_events()
+{
+ global $wpdb;
+ $table_name = TABLE_NAME_MIGA_CAL_EVENTS;
+ if ($wpdb->get_var("show tables like '$table_name'") != $table_name) {
+ $charset_collate = $wpdb->get_charset_collate();
+ $sql = "CREATE TABLE $table_name (id INT NOT NULL AUTO_INCREMENT , date DATE NOT NULL , title VARCHAR(255) NULL DEFAULT NULL, status INT NULL DEFAULT NULL, calendar INT NULL DEFAULT NULL , PRIMARY KEY (`id`)) $charset_collate;";
+ require_once ABSPATH . "wp-admin/includes/upgrade.php";
+ dbDelta($sql);
+ }
+}
+
+function miga_calendar_calendar()
+{
+ global $wpdb;
+ $table_name = TABLE_NAME_MIGA_CAL_CALENDAR;
+ if ($wpdb->get_var("show tables like '$table_name'") != $table_name) {
+ $charset_collate = $wpdb->get_charset_collate();
+ $sql = "CREATE TABLE $table_name (id INT NOT NULL AUTO_INCREMENT , title VARCHAR(255) NULL DEFAULT NULL, PRIMARY KEY (`id`)) $charset_collate;";
+ require_once ABSPATH . "wp-admin/includes/upgrade.php";
+ dbDelta($sql);
+
+ $wpdb->insert(
+ $table_name,
+ array(
+ "title" => "default",
+ )
+ );
+ }
+}
+
+function miga_calendar_status()
+{
+ global $wpdb;
+ $table_name = TABLE_NAME_MIGA_CAL_STATUS;
+ if ($wpdb->get_var("show tables like '$table_name'") != $table_name) {
+ $charset_collate = $wpdb->get_charset_collate();
+ $sql = "CREATE TABLE $table_name (id INT NOT NULL AUTO_INCREMENT , status VARCHAR(255) NULL DEFAULT NULL, class VARCHAR(255) NULL DEFAULT NULL, visible BOOLEAN NOT NULL DEFAULT TRUE, fixed BOOLEAN NOT NULL DEFAULT FALSE, PRIMARY KEY (`id`)) $charset_collate;";
+ require_once ABSPATH . "wp-admin/includes/upgrade.php";
+ dbDelta($sql);
+
+ $wpdb->insert($table_name, [
+ "status" => "blocked",
+ "class" => "blocked",
+ "fixed" => 1
+ ]);
+ $wpdb->insert($table_name, [
+ "status" => "half blocked",
+ "class" => "half_blocked",
+ "fixed" => 1
+ ]);
+ }
+}
+
+register_activation_hook(__FILE__, "miga_calendar_events");
+register_activation_hook(__FILE__, "miga_calendar_calendar");
+register_activation_hook(__FILE__, "miga_calendar_status");
+
+add_action("wp_ajax_miga_custom_post_filter_cal", "miga_ajax_functions_cal");
+add_action("wp_ajax_nopriv_miga_custom_post_filter_cal", "miga_ajax_functions_cal");
+add_action("wp_ajax_miga_editor_cal", "miga_ajax_editor_cal");
+add_action("wp_ajax_miga_editor_cal_delete", "miga_ajax_editor_cal_delete");
+add_action("wp_ajax_miga_editor_cal_update", "miga_ajax_editor_cal_update");
+add_shortcode('simple-calendar-for-elementor', 'simple_calendar_for_elementor_shortcode');
+
+
+function simple_calendar_for_elementor_shortcode($atts, $content, $tag)
+{
+ $calendar = "";
+ if (isset($atts["calendar"])) {
+ $calendar = (int)$atts["calendar"];
+ }
+ $showButton = false;
+ wp_register_style("miga_calendar_styles", plugins_url("/styles/main.css", __FILE__));
+ wp_enqueue_style("miga_calendar_styles");
+
+ echo '<div class="miga_calendar" data-calendar="'.$calendar.'" data-year="'.date("Y").'" data-month="'.date("m").'">';
+ echo '<div class="miga_calendar_box">';
+ miga_ajax_functions_cal($calendar, [
+ "showButton" => $showButton,
+ "fixedMonth" => false,
+ "selectedMonth" => -1,
+ "selectedYear" => -1
+ ]);
+ echo '<div class="loading_spinner"></div>';
+ echo '</div>';
+ echo '</div>';
+}
+
+add_action('wp_enqueue_scripts', 'miga_calendar_enqueue_scripts');
+function miga_calendar_enqueue_scripts()
+{
+ wp_register_script("miga_calendar_script", plugin_dir_url(__FILE__) . "./scripts/main.js", [], "1.0.1", true);
+
+ wp_localize_script("miga_calendar_script", "miga_calendar", [
+ "miga_nonce" => wp_create_nonce("miga_nonce"),
+ "wp_url" => admin_url("admin-ajax.php"),
+ ]);
+ wp_enqueue_script('miga_calendar_script');
+}
+
+function miga_calendar_add_page()
+{
+ add_submenu_page(
+ "options-general.php",
+ __("Simple Calendar", "simple-calendar-for-elementor"),
+ __("Simple Calendar", "simple-calendar-for-elementor"),
+ "manage_options",
+ "miga_calendar-page",
+ "miga_calendar_page",
+ 100
+ );
+}
+
+function miga_calendar_register_settings()
+{
+ add_option("miga_calendar_days", "");
+ add_option("eMonth", "");
+ add_option("eYear", "");
+ register_setting("miga_calendar_days_option_group", "miga_calendar_days");
+ register_setting("miga_calendar_days_option_group", "eMonth");
+ register_setting("miga_calendar_days_option_group", "eYear");
+}
+
+function miga_calendar_page()
+{
+ $default_tab = null;
+ $tab = isset($_GET["tab"]) ? sanitize_key($_GET["tab"]) : sanitize_key($default_tab);
+ ?>
+<h1>Simple calendar</h1>
+
+ <nav class="nav-tab-wrapper">
+ <a href="?page=miga_calendar-page" class="nav-tab <?php if (
+ $tab === null || $tab == ""
+ ): ?>nav-tab-active<?php endif; ?>"><?php echo __("Calendars", "simple-calendar-for-elementor"); ?></a>
+ <a href="?page=miga_calendar-page&tab=events" class="nav-tab <?php if (
+ $tab === "events"
+ ): ?>nav-tab-active<?php endif; ?>"><?php echo __("Events", "simple-calendar-for-elementor"); ?></a>
+ <a href="?page=miga_calendar-page&tab=classes" class="nav-tab <?php if (
+ $tab === "classes"
+ ): ?>nav-tab-active<?php endif; ?>"><?php echo __("Status/Classes", "simple-calendar-for-elementor"); ?></a>
+ </nav>
+ <div id="miga_calendar_backend">
+ <?php switch ($tab):
+ case "events":
+ require "widget/includes/backend_events.php";
+ break;
+ case "classes":
+ require "widget/includes/backend_status.php";
+ break;
+ default:
+ require "widget/includes/backend_calendars.php";
+ break;
+ endswitch; ?>
+ </div>
+<?php
+}
+
+function miga_calendar_enqueue()
+{
+ wp_register_style("miga_calendar_styles2", plugins_url("styles/main.css", __FILE__));
+ wp_enqueue_style("miga_calendar_styles2");
+ wp_register_style("miga_calendar_styles", plugins_url("styles/editor.css", __FILE__));
+ wp_enqueue_style("miga_calendar_styles");
+ wp_register_script("miga_calendar_editor_script", plugins_url("scripts/editor.js", __FILE__), ["wp-i18n"], "", true);
+ wp_enqueue_script("miga_calendar_editor_script");
+
+ wp_localize_script("miga_calendar_editor_script", "miga_calendar", [
+ "miga_nonce" => wp_create_nonce("miga_nonce"),
+ "wp_url" => admin_url("admin-ajax.php"),
+ ]);
+}
+
+add_action("admin_enqueue_scripts", "miga_calendar_enqueue");
+add_action("admin_menu", "miga_calendar_add_page", 999);
+add_action("admin_init", "miga_calendar_register_settings");
--- a/simple-calendar-for-elementor/trunk/widget/elementor_calendar.php
+++ b/simple-calendar-for-elementor/trunk/widget/elementor_calendar.php
@@ -0,0 +1,693 @@
+<?php
+
+class MIGA_Simple_Calendar extends ElementorWidget_Base
+{
+ public function __construct($data = [], $args = null)
+ {
+ parent::__construct($data, $args);
+ wp_register_script(
+ "miga_calendar_script",
+ plugin_dir_url(__FILE__) . "../scripts/main.js",
+ [],
+ "1.0.0",
+ true
+ );
+
+ wp_localize_script("miga_calendar_script", "miga_calendar", [
+ "miga_nonce" => wp_create_nonce("miga_nonce"),
+ "wp_url" => admin_url("admin-ajax.php"),
+ ]);
+ }
+
+ public function get_script_depends()
+ {
+ return ["miga_calendar_script"];
+ }
+
+ public function get_name()
+ {
+ return "simple-calendar-for-elementor";
+ }
+
+ public function get_title()
+ {
+ return __("Simple Calendar", "simple-calendar-for-elementor");
+ }
+
+ public function get_icon()
+ {
+ return "eicon-calendar";
+ }
+
+ public function get_categories()
+ {
+ return ["general"];
+ }
+
+ protected function register_controls()
+ {
+ $this->start_controls_section("content_section", [
+ "label" => __("Content", "simple-calendar-for-elementor"),
+ "tab" => ElementorControls_Manager::TAB_CONTENT,
+ ]);
+
+ global $wpdb;
+ $table_name_cal = TABLE_NAME_MIGA_CAL_CALENDAR;
+ $results = $wpdb->get_results(("SELECT * FROM $table_name_cal"));
+ $cal = [];
+ $default = "";
+ if (!empty($results)) {
+ foreach ($results as $row) {
+ $cal[$row->id] = esc_attr($row->title);
+ if (empty($default)) {
+ $default = (int) $row->id;
+ }
+ }
+ }
+
+ $this->add_control("calendar", [
+ "label" => __("Calendar", "simple-calendar-for-elementor"),
+ "type" => ElementorControls_Manager::SELECT,
+ "options" => $cal,
+ "default" => $default,
+ ]);
+
+ $this->add_control("layout", [
+ "label" => __("Layout", "simple-calendar-for-elementor"),
+ "type" => ElementorControls_Manager::SELECT,
+ "options" => [
+ "" => "Default",
+ "miga_calendar_full" => __("Full width", "simple-calendar-for-elementor"),
+ ],
+ "default" => "",
+ ]);
+
+ $this->add_control("squared_days", [
+ "label" => __("Squared days", "simple-calendar-for-elementor"),
+ "type" => ElementorControls_Manager::SWITCHER,
+ "label_on" => __("yes", "simple-calendar-for-elementor"),
+ "label_off" => __("no", "simple-calendar-for-elementor"),
+ "return_value" => "yes",
+ "default" => "no",
+ 'condition' => [
+ 'layout' => "",
+ ],
+ ]);
+
+ $this->add_control("show_legend", [
+ "label" => __("Show legend", "simple-calendar-for-elementor"),
+ "type" => ElementorControls_Manager::SWITCHER,
+ "label_on" => __("Show", "simple-calendar-for-elementor"),
+ "label_off" => __("Hide", "simple-calendar-for-elementor"),
+ "return_value" => "yes",
+ "default" => "no",
+ ]);
+
+ $this->add_control("show_today", [
+ "label" => __("Show today button", "simple-calendar-for-elementor"),
+ "type" => ElementorControls_Manager::SWITCHER,
+ "label_on" => __("Show", "simple-calendar-for-elementor"),
+ "label_off" => __("Hide", "simple-calendar-for-elementor"),
+ "return_value" => "yes",
+ "default" => "yes",
+ ]);
+
+ $this->add_control("legend_position", [
+ "label" => __("Legend position", "simple-calendar-for-elementor"),
+ "type" => ElementorControls_Manager::SELECT,
+ "options" => [
+ "" => __("Side", "simple-calendar-for-elementor"),
+ "legend_below" => __("Below", "simple-calendar-for-elementor"),
+ ],
+ 'condition' => [
+ 'show_legend' => "yes",
+ ],
+ "default" => "",
+ ]);
+
+
+ $this->add_responsive_control(
+ 'day_height',
+ [
+ 'label' => esc_html__('Day height', 'simple-calendar-for-elementor'),
+ 'type' => ElementorControls_Manager::SLIDER,
+ 'size_units' => [ 'px' ],
+ 'range' => [
+ 'px' => [
+ 'min' => 0,
+ 'max' => 200,
+ 'step' => 1,
+ ]
+ ],
+ 'default' => [
+ 'unit' => 'px',
+ 'size' => 50,
+ ],
+ 'selectors' => [
+ '{{WRAPPER}} .calendar__day' => 'height: {{SIZE}}{{UNIT}};',
+ ],
+ ]
+ );
+ $this->add_responsive_control(
+ 'day_width',
+ [
+ 'label' => esc_html__('Day width', 'simple-calendar-for-elementor'),
+ 'type' => ElementorControls_Manager::SLIDER,
+ 'size_units' => [ 'px' ],
+ 'range' => [
+ 'px' => [
+ 'min' => 0,
+ 'max' => 200,
+ 'step' => 1,
+ ]
+ ],
+ 'default' => [
+ 'unit' => 'px',
+ 'size' => 50,
+ ],
+ 'selectors' => [
+ '{{WRAPPER}} .calendar__day, {{WRAPPER}} .calendar__day_name' => 'width: {{SIZE}}{{UNIT}};',
+ ],
+ 'condition' => [
+ 'layout' => "",
+ ],
+ ]
+ );
+
+ $this->add_responsive_control(
+ 'day_gap',
+ [
+ 'label' => esc_html__('Day gap', 'simple-calendar-for-elementor'),
+ 'type' => ElementorControls_Manager::SLIDER,
+ 'size_units' => [ 'px' ],
+ 'range' => [
+ 'px' => [
+ 'min' => 0,
+ 'max' => 100,
+ 'step' => 1,
+ ]
+ ],
+ 'default' => [
+ 'unit' => 'px',
+ 'size' => 2,
+ ],
+ 'selectors' => [
+ '{{WRAPPER}} .calendar__day' => 'margin: {{SIZE}}{{UNIT}};',
+ ],
+ ]
+ );
+
+ $this->add_control(
+ 'show_title',
+ [
+ 'label' => esc_html__('Show event titles when hovering a day', 'simple-calendar-for-elementor'),
+ 'type' => ElementorControls_Manager::SWITCHER,
+ 'label_on' => esc_html__('Show', 'simple-calendar-for-elementor'),
+ 'label_off' => esc_html__('Hide', 'simple-calendar-for-elementor'),
+ 'return_value' => 'yes',
+ 'default' => 'yes',
+ ]
+ );
+ $this->add_control(
+ 'fixed_month',
+ [
+ 'label' => esc_html__('Show a fixed month', 'simple-calendar-for-elementor'),
+ 'type' => ElementorControls_Manager::SWITCHER,
+ 'label_on' => esc_html__('Show', 'simple-calendar-for-elementor'),
+ 'label_off' => esc_html__('Hide', 'simple-calendar-for-elementor'),
+ 'return_value' => 'yes',
+ 'default' => 'no',
+ ]
+ );
+
+ $this->add_control(
+ 'selected_month',
+ [
+ 'label' => esc_html__('Month', 'simple-calendar-for-elementor'),
+ 'type' => ElementorControls_Manager::SELECT,
+ 'description' =>esc_html__('Changes might only be visible in the frontend', 'simple-calendar-for-elementor'),
+ 'default' => '1',
+ 'options' => [
+ '1' => esc_html__('Januar', 'simple-calendar-for-elementor'),
+ '2' => esc_html__('February', 'simple-calendar-for-elementor'),
+ '3' => esc_html__('March', 'simple-calendar-for-elementor'),
+ '4' => esc_html__('April', 'simple-calendar-for-elementor'),
+ '5' => esc_html__('May', 'simple-calendar-for-elementor'),
+ '6' => esc_html__('June', 'simple-calendar-for-elementor'),
+ '7' => esc_html__('July', 'simple-calendar-for-elementor'),
+ '8' => esc_html__('August', 'simple-calendar-for-elementor'),
+ '9' => esc_html__('September', 'simple-calendar-for-elementor'),
+ '10' => esc_html__('October', 'simple-calendar-for-elementor'),
+ '11' => esc_html__('November', 'simple-calendar-for-elementor'),
+ '12' => esc_html__('December', 'simple-calendar-for-elementor'),
+ ],
+ 'selectors' => [
+ '{{WRAPPER}} .your-class' => 'border-style: {{VALUE}};',
+ ],
+ 'condition' => ['fixed_month' => 'yes'],
+ ]
+ );
+ $this->add_control(
+ 'selected_year',
+ [
+ 'label' => esc_html__('Year', 'simple-calendar-for-elementor'),
+ 'type' => ElementorControls_Manager::TEXT,
+ 'default' => date('Y'),
+ 'placeholder' => esc_html__('2023', 'simple-calendar-for-elementor'),
+ 'condition' => ['fixed_month' => 'yes'],
+ ]
+ );
+
+ $this->end_controls_section();
+
+
+ $this->start_controls_section(
+ 'section_style_default',
+ [
+ 'label' => esc_html__('Default styles', 'simple-calendar-for-elementor'),
+ "tab" => ElementorControls_Manager::TAB_STYLE,
+ ]
+ );
+
+ $this->add_control(
+ 'color_lines',
+ [
+ 'label' => esc_html__('Top/bottom line', 'simple-calendar-for-elementor'),
+ 'type' => ElementorControls_Manager::COLOR,
+ 'selectors' => [
+ '{{WRAPPER}} .calendar__dates' => 'border-top-color: {{VALUE}}; border-bottom-color: {{VALUE}}',
+ ],
+ ]
+ );
+
+ $this->add_control(
+ 'color_bg',
+ [
+ 'label' => esc_html__('Background color', 'simple-calendar-for-elementor'),
+ 'type' => ElementorControls_Manager::COLOR,
+ 'selectors' => [
+ '{{WRAPPER}} .miga_calendar_box' => 'background-color: {{VALUE}}',
+ ],
+ ]
+ );
+
+ $this->add_control(
+ 'color_bg_header',
+ [
+ 'label' => esc_html__('Header background color', 'simple-calendar-for-elementor'),
+ 'type' => ElementorControls_Manager::COLOR,
+ 'selectors' => [
+ '{{WRAPPER}} .calendar__header' => 'background-color: {{VALUE}}',
+ ],
+ ]
+ );
+ $this->add_control(
+ 'color_header',
+ [
+ 'label' => esc_html__('Header text color', 'simple-calendar-for-elementor'),
+ 'type' => ElementorControls_Manager::COLOR,
+ 'selectors' => [
+ '{{WRAPPER}} .calendar__header, {{WRAPPER}} .calendar__next, {{WRAPPER}} .calendar__prev' => 'color: {{VALUE}}',
+ ],
+ ]
+ );
+ $this->add_control(
+ 'color_header_hover',
+ [
+ 'label' => esc_html__('Header text color (hover)', 'simple-calendar-for-elementor'),
+ 'type' => ElementorControls_Manager::COLOR,
+ 'selectors' => [
+ ' {{WRAPPER}} .calendar__next:hover, {{WRAPPER}} .calendar__prev:hover' => 'color: {{VALUE}}',
+ ],
+ ]
+ );
+
+ $this->add_group_control(
+ ElementorGroup_Control_Border::get_type(),
+ [
+ 'name' => 'border_cal',
+ // 'label' => esc_html__('Border', 'simple-calendar-for-elementor'),
+ 'selector' => '{{WRAPPER}} .calendar',
+ ]
+ );
+
+
+ $this->add_group_control(
+ ElementorGroup_Control_Typography::get_type(),
+ [
+ 'name' => 'content_typography',
+ 'selector' => '{{WRAPPER}} .calendar',
+ ]
+ );
+
+ $this->end_controls_section();
+ $this->start_controls_section(
+ 'section_style_weekday',
+ [
+ 'label' => esc_html__('Weekdays', 'simple-calendar-for-elementor'),
+ "tab" => ElementorControls_Manager::TAB_STYLE,
+ ]
+ );
+ $this->add_group_control(
+ ElementorGroup_Control_Typography::get_type(),
+ [
+ 'name' => 'content_typography_weekday',
+ 'selector' => '{{WRAPPER}} .calendar__week .calendar__day_name',
+ ]
+ );
+ $this->add_control(
+ 'color_bg_header_days',
+ [
+ 'label' => esc_html__('Days background color', 'simple-calendar-for-elementor'),
+ 'type' => ElementorControls_Manager::COLOR,
+ 'selectors' => [
+ '{{WRAPPER}} .calendar__day_name' => 'background-color: {{VALUE}}',
+ ],
+ ]
+ );
+ $this->add_control(
+ 'color_header_days',
+ [
+ 'label' => esc_html__('Days text color', 'simple-calendar-for-elementor'),
+ 'type' => ElementorControls_Manager::COLOR,
+ 'selectors' => [
+ '{{WRAPPER}} .calendar__day_name' => 'color: {{VALUE}}',
+ ],
+ ]
+ );
+ $this->end_controls_section();
+
+ $this->start_controls_section(
+ 'section_style_buttons',
+ [
+ 'label' => esc_html__('Prev/Next styles', 'simple-calendar-for-elementor'),
+ "tab" => ElementorControls_Manager::TAB_STYLE,
+ ]
+ );
+
+ $this->add_control(
+ 'color_arrows',
+ [
+ 'label' => esc_html__('Arrow color', 'simple-calendar-for-elementor'),
+ 'type' => ElementorControls_Manager::COLOR,
+ 'selectors' => [
+ '{{WRAPPER}} .calendar__next svg, {{WRAPPER}} .calendar__prev svg' => 'fill: {{VALUE}}',
+ ],
+ ]
+ );
+
+ $this->add_group_control(
+ ElementorGroup_Control_Border::get_type(),
+ [
+ 'name' => 'border_next_prev',
+ // 'label' => esc_html__('Border prev/next', 'simple-calendar-for-elementor'),
+ 'selector' => '{{WRAPPER}} .calendar__next, {{WRAPPER}} .calendar__prev',
+ ]
+ );
+
+ $this->add_control(
+ 'color_bg_arrow',
+ [
+ 'label' => esc_html__('Background color', 'simple-calendar-for-elementor'),
+ 'type' => ElementorControls_Manager::COLOR,
+ 'selectors' => [
+ '{{WRAPPER}} .calendar__next, {{WRAPPER}} .calendar__prev' => 'background-color: {{VALUE}}',
+ ],
+ ]
+ );
+
+ $this->end_controls_section();
+
+ $this->start_controls_section(
+ 'section_style_today_day',
+ [
+ 'label' => esc_html__('Today day styles', 'simple-calendar-for-elementor'),
+ "tab" => ElementorControls_Manager::TAB_STYLE,
+ ]
+ );
+
+ $this->add_control(
+ 'color_today_day',
+ [
+ 'label' => esc_html__('Text color', 'simple-calendar-for-elementor'),
+ 'type' => ElementorControls_Manager::COLOR,
+ 'selectors' => [
+ '{{WRAPPER}} .calendar__day--today' => 'color: {{VALUE}}',
+ ],
+ ]
+ );
+
+ $this->add_control(
+ 'color_bg_today_day',
+ [
+ 'label' => esc_html__('Background color', 'simple-calendar-for-elementor'),
+ 'type' => ElementorControls_Manager::COLOR,
+ 'selectors' => [
+ '{{WRAPPER}} .calendar__day--today' => 'background-color: {{VALUE}}',
+ ],
+ ]
+ );
+ $this->add_group_control(
+ ElementorGroup_Control_Border::get_type(),
+ [
+ 'name' => 'color_border_today_day',
+ 'selector' => '{{WRAPPER}} .calendar__day--today',
+ ]
+ );
+
+ $this->end_controls_section();
+
+
+ $this->start_controls_section(
+ 'section_style_today',
+ [
+ 'label' => esc_html__('Today button styles', 'simple-calendar-for-elementor'),
+ "tab" => ElementorControls_Manager::TAB_STYLE,
+ ]
+ );
+ $this->add_group_control(
+ ElementorGroup_Control_Border::get_type(),
+ [
+ 'name' => 'border_today',
+ // 'label' => esc_html__('Border today', 'simple-calendar-for-elementor'),
+ 'selector' => '{{WRAPPER}} .calendar__today',
+ ]
+ );
+
+ $this->add_control(
+ 'color_bg_footer',
+ [
+ 'label' => esc_html__('Today background color', 'simple-calendar-for-elementor'),
+ 'type' => ElementorControls_Manager::COLOR,
+ 'selectors' => [
+ '{{WRAPPER}} .calendar__today' => 'background-color: {{VALUE}}',
+ ],
+ ]
+ );
+ $this->add_control(
+ 'color_bg_footer_hover',
+ [
+ 'label' => esc_html__('Today background color (hover)', 'simple-calendar-for-elementor'),
+ 'type' => ElementorControls_Manager::COLOR,
+ 'selectors' => [
+ '{{WRAPPER}} .calendar__today:hover' => 'background-color: {{VALUE}}',
+ ],
+ ]
+ );
+
+ $this->add_control(
+ 'color_today_font',
+ [
+ 'label' => esc_html__('Today color', 'simple-calendar-for-elementor'),
+ 'type' => ElementorControls_Manager::COLOR,
+ 'selectors' => [
+ '{{WRAPPER}} .calendar__today' => 'color: {{VALUE}}',
+ ],
+ ]
+ );
+
+ $this->add_control(
+ 'color_today_font_hover',
+ [
+ 'label' => esc_html__('Today color (hover)', 'simple-calendar-for-elementor'),
+ 'type' => ElementorControls_Manager::COLOR,
+ 'selectors' => [
+ '{{WRAPPER}} .calendar__today:hover' => 'color: {{VALUE}}',
+ ],
+ ]
+ );
+
+ $this->end_controls_section();
+
+ $this->start_controls_section(
+ 'section_days',
+ [
+ 'label' => esc_html__('Default days', 'simple-calendar-for-elementor'),
+ "tab" => ElementorControls_Manager::TAB_STYLE,
+ ]
+ );
+
+ $this->add_control(
+ 'font_color',
+ [
+ 'label' => esc_html__('Day font color', 'simple-calendar-for-elementor'),
+ 'type' => ElementorControls_Manager::COLOR,
+ 'selectors' => [
+ '{{WRAPPER}} .calendar__day' => 'color: {{VALUE}}',
+ ],
+ ]
+ );
+
+ $this->add_control(
+ 'bg_color_default',
+ [
+ 'label' => esc_html__('Background color day', 'simple-calendar-for-elementor'),
+ 'type' => ElementorControls_Manager::COLOR,
+ 'selectors' => [
+ 'html .miga_calendar' => '--miga-cal-default-day-color: {{VALUE}}',
+ ],
+ ]
+ );
+ $this->add_control(
+ 'bg_color_empty',
+ [
+ 'label' => esc_html__('Background color empty day', 'simple-calendar-for-elementor'),
+ 'type' => ElementorControls_Manager::COLOR,
+ 'selectors' => [
+ 'html .miga_calendar' => '--miga-cal-empty-day-color: {{VALUE}}',
+ ],
+ ]
+ );
+
+ $this->end_controls_section();
+
+ $this->start_controls_section(
+ 'section_days_selection',
+ [
+ 'label' => esc_html__('Days with status', 'simple-calendar-for-elementor'),
+ "tab" => ElementorControls_Manager::TAB_STYLE,
+ ]
+ );
+
+ $this->add_control(
+ 'bg_color',
+ [
+ 'label' => esc_html__('Background Color', 'simple-calendar-for-elementor'),
+ 'type' => ElementorControls_Manager::COLOR,
+ 'selectors' => [
+ 'html .miga_calendar' => '--miga-cal-color: {{VALUE}}',
+ ],
+ ]
+ );
+ $this->add_control(
+ 'bg_color2',
+ [
+ 'label' => esc_html__('Background Color (second)', 'simple-calendar-for-elementor'),
+ 'type' => ElementorControls_Manager::COLOR,
+ 'selectors' => [
+ 'html .miga_calendar' => '--miga-cal-color-second: {{VALUE}}',
+ ],
+ ]
+ );
+
+ $this->add_control(
+ 'font_color2',
+ [
+ 'label' => esc_html__('Font Color with status', 'simple-calendar-for-elementor'),
+ 'type' => ElementorControls_Manager::COLOR,
+ 'selectors' => [
+ '{{WRAPPER}} .calendar__day.calendar__day--hasClass' => 'color: {{VALUE}}',
+ ],
+ ]
+ );
+ $this->end_controls_section();
+
+ require("includes/legend_styles.php");
+ }
+
+ public function get_style_depends()
+ {
+ wp_register_style(
+ "miga_calendar_styles",
+ plugins_url("../styles/main.css", __FILE__)
+ );
+ return ["miga_calendar_styles"];
+ }
+
+ protected function render()
+ {
+ $isEditor = ElementorPlugin::$instance->editor->is_edit_mode();
+ $settings = $this->get_settings_for_display();
+ $calendar = $settings["calendar"];
+ $layout = $settings["layout"];
+ $legend_position = $settings["legend_position"];
+ $round_days = ($settings["squared_days"] == "yes") ? 'miga_calendar_box_squared' : '';
+ $showButton = ($settings["show_today"] == "yes");
+ $fixed_month = ($settings["fixed_month"] == "yes");
+ $show_title = ($settings["show_title"] == "yes");
+ $selected_month = -1;
+ $selected_year = -1;
+
+ if ($fixed_month) {
+ if (isset($settings["selected_month"])) {
+ $selected_month = (int)$settings["selected_month"];
+ } else {
+ $selected_month = 1;
+ }
+ if (isset($settings["selected_year"])) {
+ $selected_year = (int)$settings["selected_year"];
+ } else {
+ $selected_year = date("Y");
+ }
+ $showButton = 0;
+ }
+
+ if ($isEditor) {
+ echo '<input type="hidden" value="'.esc_html($calendar).'" id="currentCalendar"/>';
+ }
+
+ echo '<div class="miga_calendar ' .esc_html($layout).
+ ' ' .esc_html($legend_position) .' '. '" data-year="'.date("Y").'" data-month="'.date("m").'" data-showtitle="'.$show_title.'" data-showbutton="'.$showButton.'" data-calendar="' .
+ esc_html($calendar) .
+ '">';
+ echo '<div class="miga_calendar_box '.$round_days.'">';
+ miga_ajax_functions_cal($calendar, [
+ "showButton" => $showButton,
+ "fixedMonth" => $fixed_month,
+ "selectedMonth" => $selected_month,
+ "selectedYear" => $selected_year,
+ "showTitle" => $show_title,
+ ]);
+ echo '<div class="loading_spinner"></div>';
+ echo '</div>';
+
+ if ($settings["show_legend"] == "yes") {
+ global $wpdb;
+ $table_name = TABLE_NAME_MIGA_CAL_STATUS;
+
+ // if (isset($_POST["submit"])) {
+ // $wpdb->insert($table_name, [
+ // "status" => sanitize_text_field($_POST["status"]),
+ // "class" => sanitize_text_field($_POST["class"]),
+ // ]);
+ // }
+
+ $results = $wpdb->get_results(("SELECT * FROM $table_name"));
+ if (!empty($results)) {
+ echo '<div class="calendar__legend '.$round_days.'">';
+ echo '<div class="calendar__legend_title">' . esc_html__("Legend", "simple-calendar-for-elementor") . "</div>";
+ foreach ($results as $row) {
+ if ($row->visible) {
+ echo '<div class="calendar__legend_row"><div class="calendar__legend_item ' .
+ esc_html($row->class) .
+ '"></div><div class="calendar__legend_row_status">' .
+ esc_html($row->status) .
+ "</div></div>";
+ }
+ }
+ echo "</div>";
+ }
+ }
+ echo "</div>";
+ }
+}
--- a/simple-calendar-for-elementor/trunk/widget/elementor_calendar_legend.php
+++ b/simple-calendar-for-elementor/trunk/widget/elementor_calendar_legend.php
@@ -0,0 +1,102 @@
+<?php
+
+class MIGA_Simple_Calendar_Legend extends ElementorWidget_Base
+{
+ public function get_script_depends()
+ {
+ return ["miga_calendar_script"];
+ }
+
+ public function get_name()
+ {
+ return "simple-calendar-for-elementor-legend";
+ }
+
+ public function get_title()
+ {
+ return __("Simple Calendar (Legend)", "simple-calendar-for-elementor");
+ }
+
+ public function get_icon()
+ {
+ return "eicon-calendar";
+ }
+
+ public function get_categories()
+ {
+ return ["general"];
+ }
+
+ protected function register_controls()
+ {
+ $this->start_controls_section("content_section", [
+ "label" => __("Content", "simple-calendar-for-elementor"),
+ "tab" => ElementorControls_Manager::TAB_CONTENT,
+ ]);
+
+ $this->add_control(
+ 'show_title',
+ [
+ 'label' => esc_html__('Show Title', 'simple-calendar-for-elementor'),
+ 'type' => ElementorControls_Manager::SWITCHER,
+ 'label_on' => esc_html__('Show', 'simple-calendar-for-elementor'),
+ 'label_off' => esc_html__('Hide', 'simple-calendar-for-elementor'),
+ 'return_value' => 'yes',
+ 'default' => 'yes',
+ ]
+ );
+
+ $this->add_control("squared_days", [
+ "label" => __("Squared days", "simple-calendar-for-elementor"),
+ "type" => ElementorControls_Manager::SWITCHER,
+ "label_on" => __("yes", "simple-calendar-for-elementor"),
+ "label_off" => __("no", "simple-calendar-for-elementor"),
+ "return_value" => __("yes", "simple-calendar-for-elementor"),
+ "default" => __("no", "simple-calendar-for-elementor"),
+ ]);
+
+ $this->end_controls_section();
+
+ require("includes/legend_styles.php");
+ }
+
+ public function get_style_depends()
+ {
+ wp_register_style(
+ "miga_calendar_styles",
+ plugins_url("../styles/main.css", __FILE__)
+ );
+ return ["miga_calendar_styles"];
+ }
+
+ protected function render()
+ {
+ $isEditor = ElementorPlugin::$instance->editor->is_edit_mode();
+ $settings = $this->get_settings_for_display();
+ $round_days = ($settings["squared_days"]=="yes") ? 'miga_calendar_box_squared' : '';
+
+
+
+ echo '<div class="miga_calendar">';
+ global $wpdb;
+ $table_name = TABLE_NAME_MIGA_CAL_STATUS;
+ $results =$wpdb->get_results(("SELECT * FROM $table_name"));
+ if (!empty($results)) {
+ echo '<div class="calendar__legend '.$round_days.'">';
+ if ($settings["show_title"]=="yes") {
+ echo '<div class="calendar__legend_title">' . esc_html__("Legend", "simple-calendar-for-elementor") . "</div>";
+ }
+ foreach ($results as $row) {
+ if ($row->visible) {
+ echo '<div class="calendar__legend_row"><div class="calendar__legend_item ' .
+ esc_html($row->class) .
+ '"></div><div class="calendar__legend_row_status">' .
+ esc_html($row->status) .
+ "</div></div>";
+ }
+ }
+ echo "</div>";
+ }
+ echo "</div>";
+ }
+}
--- a/simple-calendar-for-elementor/trunk/widget/includes/Calendar.class.php
+++ b/simple-calendar-for-elementor/trunk/widget/includes/Calendar.class.php
@@ -0,0 +1,214 @@
+<?php
+/**
+ * Calendar class
+ */
+class Miga_calendar_Day
+{
+ private $number;
+ private $date;
+ private $weekday;
+ private $statusClass;
+ private $showTitle = true;
+ private $statusText;
+ private $month;
+ private $year;
+
+ public function __construct($year, $month, $day)
+ {
+ $this->date = strtotime($year . "-" . $month . "-" . $day);
+ $this->month = $month;
+ $this->year = $year;
+ $this->number = date("d", $this->date);
+ $this->weekday = date("w", $this->date); // Sunday = 0
+ }
+
+ public function getNumber()
+ {
+ return (int) $this->number;
+ }
+ public function getDate()
+ {
+ return $this->date;
+ }
+ public function getWeekday()
+ {
+ return (int) $this->weekday;
+ }
+ public function setStatus($statusClass, $statusText)
+ {
+ $this->statusClass = $statusClass;
+ $this->statusText = $statusText;
+ }
+ public function showTitle($val)
+ {
+ $this->showTitle = $val;
+ }
+ public function render()
+ {
+ $hasClass = "";
+ if (!empty($this->statusClass)) {
+ $hasClass = "calendar__day--hasClass";
+ }
+
+ $title = esc_html($this->statusText);
+ $todayClass = "";
+ if ($this->getNumber() == date('d') && $this->month == date('m') && $this->year == date("Y")) {
+ $todayClass = "calendar__day--today";
+ $title = __("today", "simple-calendar-for-elementor");
+ }
+
+ if (!$this->showTitle) {
+ $title = "";
+ }
+ return '<div title="'.$title.'" class="calendar__day '.$todayClass.' '.esc_html($hasClass).' '.esc_html($this->statusClass).'" data-weekday="'.(int) ($this->weekday).'">'.(int) ($this->getNumber())."</div>";
+ }
+}
+
+class Miga_calendar_Month
+{
+ private $month;
+ private $year;
+ private $daysInMonth;
+ private $monthName;
+ private $statusClass;
+ private $statusText;
+
+ public function __construct($month, $year)
+ {
+ $monthNames = [
+ __("Jan", "simple-calendar-for-elementor"),
+ __("Feb", "simple-calendar-for-elementor"),
+ __("Mar", "simple-calendar-for-elementor"),
+ __("Apr", "simple-calendar-for-elementor"),
+ __("May", "simple-calendar-for-elementor"),
+ __("Jun", "simple-calendar-for-elementor"),
+ __("Jul", "simple-calendar-for-elementor"),
+ __("Aug", "simple-calendar-for-elementor"),
+ __("Sep", "simple-calendar-for-elementor"),
+ __("Oct", "simple-calendar-for-elementor"),
+ __("Nov", "simple-calendar-for-elementor"),
+ __("Dec", "simple-calendar-for-elementor"),
+ ];
+ $this->month = $month;
+ $this->year = $year;
+ $this->statusClass = array_fill(0, 35, "");
+ $this->statusText = array_fill(0, 35, "");
+ $this->daysInMonth = cal_days_in_month(
+ CAL_GREGORIAN,
+ $this->month,
+ $this->year
+ );
+ $this->monthName = $monthNames[(int) $this->month - 1];
+ }
+
+ public function setStatus($day, $statusClass, $statusText)
+ {
+ $replace = [(int) $day => $statusClass];
+ $replaceText = [(int) $day => $statusText];
+ $this->statusClass = array_replace($this->statusClass, $replace);
+ $this->statusText = array_replace($this->statusText, $replaceText);
+ }
+ public function getStatusClass($day)
+ {
+ return $this->statusClass[(int) $day];
+ }
+ public function getStatusText($day)
+ {
+ return $this->statusText[(int) $day];
+ }
+
+ public function render($options = null)
+ {
+ $showMenu = isset($options["menu"]) && $options["menu"] == true;
+ $showButton = isset($options["showButton"]) && $options["showButton"] == true;
+ $showEditorMenu = isset($options["editorMenu"]) && $options["editorMenu"] == true;
+ $fixedMonth = isset($options["fixedMonth"]) && $options["fixedMonth"] == true;
+ $showTitle = isset($options["showTitle"]) && $options["showTitle"] == true;
+
+ if ($fixedMonth) {
+ $showMenu = $showButton = $showEditorMenu = false;
+ }
+
+ echo '<div class="calendar">';
+ echo '<div class="calendar__header">';
+ if ($showMenu) {
+ echo '<button class="calendar__prev" onclick="miga_calendar_loadPrev(this); return false;"><svg width="15" height="15" version="1.1" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path transform="matrix(-.2605 .8617 .9721 .2309 6.828 -1.227)" d="m21.73 21.86-23.06-6.178 16.88-16.88 3.089 11.53z"/></svg></button>';
+ } elseif ($showEditorMenu) {
+ echo '<button class="calendar__prev" onclick="miga_calendar_loadEditorPrev(this); return false;"><svg width="15" height="15" version="1.1" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path transform="matrix(-.2605 .8617 .9721 .2309 6.828 -1.227)" d="m21.73 21.86-23.06-6.178 16.88-16.88 3.089 11.53z"/></svg></button>';
+ }
+
+ echo '<div class="calendar__title">' . esc_html($this->monthName) . " " .esc_html($this->year) . "</div>";
+ if ($showMenu) {
+ echo '<button class="calendar__next" onclick="miga_calendar_loadNext(this)"><svg width="15" height="15" version="1.1" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path transform="matrix(.2605 .8617 -.9721 .2309 17.05 -1.227)" d="m21.73 21.86-23.06-6.178 16.88-16.88 3.089 11.53z"/></svg></button>';
+ } elseif ($showEditorMenu) {
+ echo '<button class="calendar__next" onclick="miga_calendar_loadEditorNext(this)"><svg width="15" height="15" version="1.1" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path transform="matrix(.2605 .8617 -.9721 .2309 17.05 -1.227)" d="m21.73 21.86-23.06-6.178 16.88-16.88 3.089 11.53z"/></svg></button>';
+ }
+ echo "</div>";
+
+ echo '<div class="calendar__dates">';
+ echo '<div class="calendar__week">';
+ echo '<div class="calendar__day_name">' .
+ __("Mo", "simple-calendar-for-elementor") .
+ "</div>";
+ echo '<div class="calendar__day_name">' .
+ __("Tu", "simple-calendar-for-elementor") .
+ "</div>";
+ echo '<div class="calendar__day_name">' .
+ __("We", "simple-calendar-for-elementor") .
+ "</div>";
+ echo '<div class="calendar__day_name">' .
+ __("Th", "simple-calendar-for-elementor") .
+ "</div>";
+ echo '<div class="calendar__day_name">' .
+ __("Fr", "simple-calendar-for-elementor") .
+ "</div>";
+ echo '<div class="calendar__day_name">' .
+ __("Sa", "simple-calendar-for-elementor") .
+ "</div>";
+ echo '<div class="calendar__day_name">' .
+ __("Su", "simple-calendar-for-elementor") .
+ "</div>";
+ echo "</div>";
+ echo '<div class="calendar__week">';
+ $lastWeekday = 0;
+ for ($i = 1, $len = $this->daysInMonth; $i <= $len; ++$i) {
+ $d = new Miga_calendar_Day($this->year, $this->month, $i);
+ if ($i == 1) {
+ $end = $d->getWeekday() - 1;
+ if ($end == -1) {
+ $end = 6;
+ }
+ for ($j = 0; $j < $end; ++$j) {
+ echo '<div class="calendar__day calendar__day--empty"></div>';
+ }
+ }
+ if ($i > 1 && $d->getWeekday() == 1) {
+ echo '</div><div class="calendar__week">';
+ }
+ $lastWeekday = $d->getWeekday() - 1;
+ if ($lastWeekday == -1) {
+ $lastWeekday = 6;
+ }
+ $d->showTitle($showTitle);
+ $d->setStatus($this->getStatusClass($d->getNumber()), $this->getStatusText($d->getNumber()));
+ echo $d->render();
+ }
+ for ($j = $lastWeekday; $j < 6; ++$j) {
+ echo '<div class="calendar__day calendar__day--empty"></div>';
+ }
+ echo "</div>";
+ echo "</div>";
+ if ($showButton) {
+ if ($showMenu) {
+ echo '<button class="calendar__today" onclick="miga_calendar_loadToday(this); return false;">' .
+ esc_html__("today", "simple-calendar-for-elementor") .
+ "</button>";
+ } elseif ($showEditorMenu) {
+ echo '<button class="calendar__today" onclick="miga_calendar_loadEditorToday(this); return false;">' .
+ esc_html__("today", "simple-calendar-for-elementor") .
+ "</button>";
+ }
+ }
+ echo "</div>";
+ }
+}
--- a/simple-calendar-for-elementor/trunk/widget/includes/backend_calendars.php
+++ b/simple-calendar-for-elementor/trunk/widget/includes/backend_calendars.php
@@ -0,0 +1,38 @@
+<div class="flex">
+ <div class="miga_calendar_half">
+<?php
+require "custom_table.php";
+
+global $wpdb;
+$table = new Miga_calendar_events_List_Table();
+$table_name = TABLE_NAME_MIGA_CAL_CALENDAR;
+
+if (isset($_POST["submit"])) {
+ if (! isset($_POST['simple_calendar_nonce']) || ! wp_verify_nonce($_POST['simple_calendar_nonce'], 'add_calendar')) {
+ return;
+ }
+ if (!empty($_POST["title"])) {
+ $title = sanitize_text_field($_POST["title"]);
+ $wpdb->insert($table_name, [
+ "title" => esc_attr($title),
+ ]);
+ }
+}
+
+$table->prepare_items();
+$table->display();
+?>
+<br/>
+
+<form method="post" class="miga_calendar_calendar" action="?page=miga_calendar-page">
+<?php wp_nonce_field('add_calendar', 'simple_calendar_nonce'); ?>
+<input type="text" value="" name="title" id="title" placeholder="<?php echo esc_html__("Add calendar", "simple-calendar-for-elementor"); ?>"/>
+<?php echo submit_button(esc_html__("add", "simple-calendar-for-elementor")); ?>
+</form>
+
+</div>
+<div class="miga_calendar_half">
+ <h2><?php echo esc_html__("Calendar", "simple-calendar-for-elementor"); ?></h2>
+ <p><?php echo esc_html__("Create different calendars you can select in the Elementor Calendar widget. Each calendar can have it's own events.", "simple-calendar-for-elementor"); ?></p>
+</div>
+</div>
--- a/simple-calendar-for-elementor/trunk/widget/includes/backend_events.php
+++ b/simple-calendar-for-elementor/trunk/widget/includes/backend_events.php
@@ -0,0 +1,16 @@
+<?php if (!did_action("elementor/loaded")) {
+ echo "Please install and enable Elementor first";
+ return false;
+} ?>
+
+<div class="flex">
+ <div id="miga_calendar_half_cal" class="miga_calendar_half">
+ <?php miga_ajax_editor_cal(); ?>
+</div>
+<div class="miga_calendar_half">
+ <h2><?php echo esc_html__("Events", "simple-calendar-for-elementor"); ?></h2>
+ <p><?php echo wp_kses_post(__("Select a calendar and add an event to a day. To add or change a status go to the <b>Status/Classes</b> tab.", "simple-calendar-for-elementor")); ?></p>
+ <h2><?php echo esc_html__("Custom colors", "simple-calendar-for-elementor"); ?></h2>
+ <p><?php echo wp_kses_post(__("Colors for the custom classes are only visible in the frontend.", "simple-calendar-for-elementor")); ?></p>
+</div>
+</div>
--- a/simple-calendar-for-elementor/trunk/widget/includes/backend_functions.php
+++ b/simple-calendar-for-elementor/trunk/widget/includes/backend_functions.php
@@ -0,0 +1,305 @@
+<?php
+
+function miga_ajax_editor_cal_delete()
+{
+ global $wpdb;
+ $table_name = TABLE_NAME_MIGA_CAL_STATUS;
+ if (! isset($_REQUEST['miga_nonce']) || ! wp_verify_nonce($_REQUEST['miga_nonce'], 'miga_nonce')) {
+ return;
+ }
+ if (current_user_can('edit_others_posts') ) {
+ $wpdb->delete(
+ $table_name, [
+ "id" => (int) $_POST["s"],
+ ]
+ );
+ }
+}
+
+function miga_ajax_editor_cal_update()
+{
+ global $wpdb;
+ $table_name = TABLE_NAME_MIGA_CAL_STATUS;
+ if (! isset($_POST['miga_nonce']) || ! wp_verify_nonce($_POST['miga_nonce'], 'miga_nonce')) {
+ return;
+ }
+ if (current_user_can('edit_others_posts') ) {
+ $wpdb->update(
+ $table_name,
+ [
+ "status" => sanitize_text_field($_POST["n"]),
+ "class" => sanitize_text_field($_POST["c"]),
+ "visible" => (int) $_POST["v"],
+ ],
+ ["id" => (int) $_POST["s"]]
+ );
+ }
+}
+
+function miga_ajax_editor_cal()
+{
+ include_once ABSPATH . "wp-admin/includes/admin.php";
+ global $wpdb;
+ $month = date("m");
+ $year = date("Y");
+
+ if (isset($_POST["m"])) {
+ $month = (int) $_POST["m"];
+ }
+ if (isset($_POST["y"])) {
+ $year = (int) $_POST["y"];
+ }
+ $currentCal = 0;
+
+ if (isset($_GET["cal"])) {
+ $currentCal = (int) $_GET["cal"];
+ }
+
+ if (isset($_POST["c"])) {
+ $currentCal = (int) $_POST["c"];
+ }
+
+ if (isset($_POST["calendar"])) {
+ $currentCal = (int) $_POST["calendar"];
+ }
+
+ $table_name_cal = TABLE_NAME_MIGA_CAL_CALENDAR;
+ $results = $wpdb->get_results(("SELECT * FROM $table_name_cal"));
+ echo '<div class="flex align-middle editor_header">';
+ echo "<b>" . esc_html__("Current calendar", "simple-calendar-for-elementor") . '</b>';
+
+ $cal = [];
+ $hasCalendar = !empty($results);
+ if ($hasCalendar) {
+ echo '<select id="miga_calendar_select" onchange="miga_calendar_onchangeCal();">';
+ if ($currentCal == 0) {
+ $currentCal = $results[0]->id;
+ }
+ foreach ($results as $row) {
+ $sel = "";
+ if ($row->id == $currentCal) {
+ $sel = " selected ";
+ }
+ echo '<option value="' . esc_html($row->id) . '" ' . esc_html($sel) .">" . esc_html($row->title) ."</option>";
+ }
+ echo "</select>";
+ } else {
+ echo '<span id="miga_calendar_select"> - </span>';
+ }
+
+ $days = cal_days_in_month(CAL_GREGORIAN, $month, $year);
+ $status = [];
+ $table_name = TABLE_NAME_MIGA_CAL_EVENTS;
+ $table_name_status = TABLE_NAME_MIGA_CAL_STATUS;
+
+ if (isset($_POST["submit"])) {
+ if (! isset($_POST['simple_calendar_nonce']) || ! wp_verify_nonce($_POST['simple_calendar_nonce'], 'add_calendar_event')) {
+ return;
+ }
+
+ $data = array_map('sanitize_text_field', $_POST["miga_calendar_days"]);
+ $eYear = (int) sanitize_key($_POST["eYear"]);
+ $eMonth = (int) sanitize_key($_POST["eMonth"]);
+ $cal = (int) sanitize_key($_POST["calendar"]);
+
+ foreach ($data as $key => $item) {
+
+ $results =$wpdb->get_results(
+ $wpdb->prepare(
+ "SELECT * FROM $table_name WHERE calendar=%d AND DAY(date)=%d AND MONTH(date)=%d AND YEAR(date)=%d",
+ $cal,
+ $key,
+ $eMonth,
+ $eYear
+ )
+ );
+
+ if (!empty($results)) {
+ $wpdb->update(
+ $table_name,
+ [
+ "date" => date(
+ "Y-m-d",
+ strtotime($eYear . "-" . $eMonth . "-" . $key)
+ ),
+ "status" => esc_html($item),
+ // "title" => $texts[$key],
+ "calendar" => (int) $cal,
+ ],
+ ["id" => $results[0]->id]
+ );
+ } else {
+ if (!empty($item)) {
+ $wpdb->insert(
+ $table_name, [
+ "date" => date(
+ "Y-m-d",
+ strtotime($eYear . "-" . $eMonth . "-" . $key)
+ ),
+ "status" => esc_html($item),
+ "calendar" => (int) $cal,
+ ]
+ );
+ }
+ }
+ }
+ }
+
+ $results =$wpdb->get_results(
+ $wpdb->prepare(
+ "SELECT a.title, a.date, b.id AS statusId,b.visible, b.status, b.class FROM $table_name AS a LEFT JOIN $table_name_status AS b ON a.status = b.id WHERE calendar=%d AND MONTH(date)=%d AND YEAR(date)=%d",
+ $currentCal,
+ $month,
+ $year
+ )
+ );
+
+ if (!empty($results)) {
+ foreach ($results as $row) {
+ $replace = [
+ (int) date("d", strtotime($row->date)) => [
+ "statusId" => (int) $row->statusId,
+ "class" => esc_html($row->class),
+ "title" => esc_html($row->title),
+ "visible" => (int) $row->visible,
+ ],
+ ];
+ $status = array_replace($status, $replace);
+ }
+ }
+
+ echo '<input type="hidden" value="' .
+ esc_html($currentCal) .
+ '" id="currentCalendar"/>';
+ echo "";
+ echo "</div>";
+
+ echo '<div class="flex miga_calendar" data-year="'.date("Y").'" data-month="'.date("m").'">';
+ echo '<div class="static_cal">';
+ include "Calendar.class.php";
+ $m = new Miga_calendar_Month($month, $year);
+ if ($wpdb != null) {
+ $table_name = TABLE_NAME_MIGA_CAL_EVENTS;
+ $table_name_status = TABLE_NAME_MIGA_CAL_STATUS;
+
+ $results =$wpdb->get_results(
+ $wpdb->prepare(
+ "SELECT a.date, b.status, b.class,b.visible FROM $table_name AS a LEFT JOIN $table_name_status AS b ON a.status = b.id WHERE calendar=%d AND MONTH(date)=%d AND YEAR(date)=%d",
+ $currentCal,
+ $month,
+ $year
+ )
+ );
+
+ if (!empty($results)) {
+ foreach ($results as $row) {
+ if ($row->visible) {
+ // only show visible events
+ $m->setStatus(
+ date("d", strtotime($row->date)),
+ $row->class,
+ $row->status
+ );
+ }
+ }
+ }
+ }
+
+ $options = [];
+
+ if ($wpdb != null) {
+ $table_name = TABLE_NAME_MIGA_CAL_STATUS;
+ $results = $wpdb->get_results("SELECT * FROM $table_name");
+ if (!empty($results)) {
+ foreach ($results as $row) {
+ if ($row->visible) {
+ // only add visible options
+ $options[] = [
+ "id" => $row->id,
+ "status" => $row->status,
+ "class" => $row->class,
+ "visible" => $row->visible,
+ ];
+ }
+ }
+ }
+ }
+
+ $m->render(
+ [
+ "editorMenu" => true,
+ ]
+ );
+ echo "</div>";
+ if ($hasCalendar) {
+
+ echo '<form class="miga_calendar_events" method="post" action="?page=miga_calendar-page&tab=events">';
+ settings_fields("miga_calendar_days_option_group");
+ ?>
+ <table>
+ <thead>
+ <tr>
+ <th><?php echo esc_html__("Day", "simple-calendar-for-elementor"); ?></th>
+ <th><?php echo esc_html__("Status", "simple-calendar-for-elementor"); ?></th>
+ <!-- <th><?php /*echo esc_html__("Description", "simple-calendar-for-elementor");*/ ?></th> -->
+ </tr>
+ </thead>
+ <tbody>