<?php
/*
Plugin Name: Click Bar  (GOLD)
Plugin URI: 
Description: Call to action bar with countdown timer
Version: 1.0
Author: ClickBar
Author URI: 
License: All Rights Reserved
*/


/* Runs when plugin is activated */
register_activation_hook(__FILE__,'clickbar_install');

function clickbar_install() {
                                global $wpdb;
                                require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
                                
                                include('create_database.php');

                            } 


if ( is_admin() ){
                 /* Call the html code */
                 add_action('admin_menu', 'clickbar_admin_menu');

                 function clickbar_admin_menu() {
                                                  add_menu_page('ClickBar Gold', 'ClickBar Gold', 'administrator','clickbar', 'clickbar_admin');
                                                  }
                 }


function clickbar_admin() { 
                              global $wpdb;
                              $PGPath=plugins_url()."/clickbar_gold/";
                              wp_register_script('op_jq', 'http://ajax.googleapis.com/ajax/libs/jquery/1.6.0/jquery.min.js'); 
                              wp_enqueue_script('op_jq');
                              
                              wp_register_script('op_jqu', 'http://code.jquery.com/ui/1.10.3/jquery-ui.js'); 
                              wp_enqueue_script('op_jqu');
                              
                              wp_register_script('flip_clock', $PGPath.'FlipClock/compiled/flipclock.js'); 
                              wp_enqueue_script('flip_clock');
                              
                              wp_register_script('js_color_picker', $PGPath.'jscolor/jscolor.js'); 
                              wp_enqueue_script('js_color_picker');
                              
                              wp_register_style('op_jqus', 'http://code.jquery.com/ui/1.10.1/themes/base/jquery-ui.css'); 
                              wp_enqueue_style('op_jqus');
                              
                              wp_register_style('flip_css', $PGPath.'FlipClock/compiled/flipclock.css'); 
                              wp_enqueue_style('flip_css');
                              
                              include('main.php');
                              
                             } 
                             
add_shortcode('clickbar', 'show_clickbar' );            
 
 function show_clickbar($atts){
                               if (!is_admin()){
                                                global $wpdb;
                                                $ID=$atts['id'];
                                                $PGPath=plugins_url()."/clickbar_gold/";
                                                $re=" SELECT * FROM ".$wpdb->prefix . "clickbar WHERE C_ID='$ID' ";
                                                $row = $wpdb -> get_results($re);
                                                foreach( $row as $rows ) {
                                                                          $Position=$rows->Position;
                                                                         }
                                                $DateX=date('m/d/Y');
                                                $wpdb->insert( 
	                                                            $wpdb->prefix . "clickbar_hits", 
	                                                                                       array( 
		                                                                                           'DateX' => $DateX,
                                                                                               'ForBar'=>$ID 
	                                                                                            ));                         
                                                echo "
                                                      <div style='position:fixed;
                                                     ";
                                                
                                                if ($Position=="1"){echo "bottom";}else{echo "top";}
                                                     
                                                echo ":0px; left:0px; width:100%; height:100px; z-index:9999;'>
                                                       <iframe src='$PGPath"."display.php?id=$ID' scrolling='no' frameborder='no' width='100%' height='100'></iframe>
                                                      </div>
                                                     ";
                                               }      
                              }                                

?>