<?php
/*
Plugin Name: Dashboard Builder
Plugin URI: https://dashboardbuilder.net/
Description: Dashboard Builder is a data visualization plugin for WordPress that offers all major charts and graphs templates, which enables you to retrives your own data from WordPress or MySQL database  to display charts and graphs on your WordPress website. For more information visit https://dashboardbuilder.net
Version: 1.5.3
Author: Dashboard Builder
Author URI: https://dashboardbuilder.net
License: GPL
*/

//Hooks a function to a filter action, 'the_content' being the action

	if (is_admin() ){
	/* Call the html code */
	add_action('admin_menu', 'dashboardbuilderMenu');
    function dashboardbuilderMenu(){
        add_options_page( 'DashboardBuilder WP setting page', 'DashboardBuilder', 'manage_options', 'DashboardBuilder', 'dashboardbuilderAdmin' );
    }
	}
  
    function dashboardbuilderAdmin(){
        include_once('dashboardbuilder-admin.php');
    }

	function dashboardbuilderShowChart(){
			$host = esc_html__(get_option('dashboardbuilder-host'));
			$user = esc_html__(get_option('dashboardbuilder-user'));
			$password = esc_html__(get_option('dashboardbuilder-password'));
			$dbname = esc_html__(get_option('dashboardbuilder-name'));
			$sql = esc_html__(get_option('dashboardbuilder-sql'));
			$xaxis = esc_html__(get_option('dashboardbuilder-xaxis1'));
			$yaxis = esc_html__(get_option('dashboardbuilder-yaxis1'));
			$xtitle = esc_html__(get_option('dashboardbuilder-xtitle1'));
			$ytitle = esc_html__(get_option('dashboardbuilder-ytitle1'));
			$type = esc_html__(get_option('dashboardbuilder-type'));
			
			include_once ( plugin_dir_path( __FILE__ ) . "inc/dashboard_dist.php");

			// for chart #1
			$data = new dashboardbuilder(); 
			$data->type[0]=  $type;

			$data->source =  "Database"; 
			$data->rdbms =  "mysql"; 
			$data->servername =  $host;
			$data->username =  $user;
			$data->password =  $password;
			$data->dbname =  $dbname;
			$data->xaxisSQL[0]=  $sql;
			$data->xaxisCol[0]=  $xaxis;
			$data->yaxisSQL[0]=  $sql;
			$data->yaxisCol[0]=  $yaxis;

			$data->name = "0";
			$data->orientation = "v";
			$data->xaxistitle = $xtitle;
			$data->yaxistitle = $ytitle;
			$data->showgrid = "true";
			$data->showline = "true";
			$data->height = "";
			$data->width = "";
			$data->col = "0";
			return $data->result();	
    }
      
    function dashboardbuilderGetChart() {
        //return get_option('dashboardbuilder-access-token');
    }
    
	function wptuts_scripts()
	{
		wp_register_script( 'script', plugins_url( '/assets/dashboard.min.js', __FILE__ ),array(), null, false );
		wp_enqueue_script( 'script' );
	}
	
	add_action( 'wp_enqueue_scripts', 'wptuts_scripts' );
	
    add_shortcode('show-dashboardbuilder', 'dashboardbuilderShowChart');

?>