<?php 
	$array_countries = array (
      'AF' => 'AFGHANISTAN',
      'AX' => 'ÅLAND ISLANDS',
      'AL' => 'ALBANIA',
      
      'DZ' => 'ALGERIA (El Djazaïr)',
      'AS' => 'AMERICAN SAMOA',
      'AD' => 'ANDORRA',
      'AO' => 'ANGOLA',
      'AI' => 'ANGUILLA',
      'AQ' => 'ANTARCTICA',
      'AG' => 'ANTIGUA AND BARBUDA',
      'AR' => 'ARGENTINA',
      'AM' => 'ARMENIA',
      'AW' => 'ARUBA',
      
      'AU' => 'AUSTRALIA',
      'AT' => 'AUSTRIA',
      'AZ' => 'AZERBAIJAN',
      'BS' => 'BAHAMAS',
      'BH' => 'BAHRAIN',
      'BD' => 'BANGLADESH',
      'BB' => 'BARBADOS',
      'BY' => 'BELARUS',
      'BE' => 'BELGIUM',
      'BZ' => 'BELIZE',
      'BJ' => 'BENIN',
      'BM' => 'BERMUDA',
      'BT' => 'BHUTAN',
      'BO' => 'BOLIVIA',
      
      'BA' => 'BOSNIA AND HERZEGOVINA',
      'BW' => 'BOTSWANA',
      'BV' => 'BOUVET ISLAND',
      'BR' => 'BRAZIL',

      'BN' => 'BRUNEI DARUSSALAM',
      'BG' => 'BULGARIA',
      'BF' => 'BURKINA FASO',
      'BI' => 'BURUNDI',
      'KH' => 'CAMBODIA',
      'CM' => 'CAMEROON',
      'CA' => 'CANADA',
      'CV' => 'CAPE VERDE',
      'KY' => 'CAYMAN ISLANDS',
      'CF' => 'CENTRAL AFRICAN REPUBLIC',
      'CD' => 'CONGO, THE DEMOCRATIC REPUBLIC OF THE (formerly Zaire)',
      'CL' => 'CHILE',
      'CN' => 'CHINA',
      'CX' => 'CHRISTMAS ISLAND',
      
      'CO' => 'COLOMBIA',
      'KM' => 'COMOROS',
      'CG' => 'CONGO, REPUBLIC OF',
      'CK' => 'COOK ISLANDS',
      'CR' => 'COSTA RICA',
      'CI' => 'CÔTE D\'IVOIRE (Ivory Coast)',
      'HR' => 'CROATIA (Hrvatska)',
      'CU' => 'CUBA',
      'CW' => 'CURAÇAO',
      'CY' => 'CYPRUS',
      'CZ' => 'ZECH REPUBLIC',
      'DK' => 'DENMARK',
      'DJ' => 'DJIBOUTI',
      'DM' => 'DOMINICA',
      'DC' => 'DOMINICAN REPUBLIC',
      'EC' => 'ECUADOR',
      'EG' => 'EGYPT',
      'SV' => 'EL SALVADOR',
      'GQ' => 'EQUATORIAL GUINEA',
      'ER' => 'ERITREA',
      'EE' => 'ESTONIA',
      'ET' => 'ETHIOPIA',
      'FO' => 'FAEROE ISLANDS',

      'FJ' => 'FIJI',
      'FI' => 'FINLAND',
      'FR' => 'FRANCE',
      'GF' => 'FRENCH GUIANA',
      
      'GA' => 'GABON',
      'GM' => 'GAMBIA, THE',
      'GE' => 'GEORGIA',
      'DE' => 'GERMANY (Deutschland)',
      'GH' => 'GHANA',
      'GI' => 'GIBRALTAR',
      // 'GB' => 'UNITED KINGDOM',
      'GR' => 'GREECE',
      'GL' => 'GREENLAND',
      'GD' => 'GRENADA',
      'GP' => 'GUADELOUPE',
      'GU' => 'GUAM',
      'GT' => 'GUATEMALA',
      'GG' => 'GUERNSEY',
      'GN' => 'GUINEA',
      'GW' => 'GUINEA-BISSAU',
      'GY' => 'GUYANA',
      'HT' => 'HAITI',
      
      'HN' => 'HONDURAS',
      'HK' => 'HONG KONG (Special Administrative Region of China)',
      'HU' => 'HUNGARY',
      'IS' => 'ICELAND',
      'IN' => 'INDIA',
      'ID' => 'INDONESIA',
      'IR' => 'IRAN (Islamic Republic of Iran)',
      'IQ' => 'IRAQ',
      'IE' => 'IRELAND',
      'IM' => 'ISLE OF MAN',
      'IL' => 'ISRAEL',
      'IT' => 'ITALY',
      'JM' => 'JAMAICA',
      'JP' => 'JAPAN',
      'JE' => 'JERSEY',
      'JO' => 'JORDAN (Hashemite Kingdom of Jordan)',
      'KZ' => 'KAZAKHSTAN',
      'KE' => 'KENYA',
      'KI' => 'KIRIBATI',
      'KP' => 'KOREA (Democratic Peoples Republic of [North] Korea)',
      'KR' => 'KOREA (Republic of [South] Korea)',
      'KW' => 'KUWAIT',
      'KG' => 'KYRGYZSTAN',
      
      'LV' => 'LATVIA',
      'LB' => 'LEBANON',
      'LS' => 'LESOTHO',
      'LR' => 'LIBERIA',
      'LY' => 'LIBYA (Libyan Arab Jamahirya)',
      'LI' => 'LIECHTENSTEIN (Fürstentum Liechtenstein)',
      'LT' => 'LITHUANIA',
      'LU' => 'LUXEMBOURG',
      'MO' => 'MACAO (Special Administrative Region of China)',
      'MK' => 'MACEDONIA (Former Yugoslav Republic of Macedonia)',
      'MG' => 'MADAGASCAR',
      'MW' => 'MALAWI',
      'MY' => 'MALAYSIA',
      'MV' => 'MALDIVES',
      'ML' => 'MALI',
      'MT' => 'MALTA',
      'MH' => 'MARSHALL ISLANDS',
      'MQ' => 'MARTINIQUE',
      'MR' => 'MAURITANIA',
      'MU' => 'MAURITIUS',
      'YT' => 'MAYOTTE',
      'MX' => 'MEXICO',
      'FM' => 'MICRONESIA (Federated States of Micronesia)',
      'MD' => 'MOLDOVA',
      'MC' => 'MONACO',
      'MN' => 'MONGOLIA',
      'ME' => 'MONTENEGRO',
      'MS' => 'MONTSERRAT',
      'MA' => 'MOROCCO',
      'MZ' => 'MOZAMBIQUE (Moçambique)',
      'MM' => 'MYANMAR (formerly Burma)',
      'NA' => 'NAMIBIA',
      'NR' => 'NAURU',
      'NP' => 'NEPAL',
      'NL' => 'NETHERLANDS',
      'AN' => 'NETHERLANDS ANTILLES (obsolete)',
      'NC' => 'NEW CALEDONIA',
      'NZ' => 'NEW ZEALAND',
      'NI' => 'NICARAGUA',
      'NE' => 'NIGER',
      'NG' => 'NIGERIA',
      'NU' => 'NIUE',
      'NF' => 'NORFOLK ISLAND',
      'MP' => 'NORTHERN MARIANA ISLANDS',
      'ND' => 'NORWAY',
      'OM' => 'OMAN',
      'PK' => 'PAKISTAN',
      'PW' => 'PALAU',
      'PS' => 'PALESTINIAN TERRITORIES',
      'PA' => 'PANAMA',
      'PG' => 'PAPUA NEW GUINEA',
      'PY' => 'PARAGUAY',
      'PE' => 'PERU',
      'PH' => 'PHILIPPINES',
      'PN' => 'PITCAIRN',
      'PL' => 'POLAND',
      'PT' => 'PORTUGAL',
      'PR' => 'PUERTO RICO',
      'QA' => 'QATAR',
      'RE' => 'RÉUNION',
      'RO' => 'ROMANIA',
      'RU' => 'RUSSIAN FEDERATION',
      'RW' => 'RWANDA',
      'BL' => 'SAINT BARTHÉLEMY',
      'SH' => 'SAINT HELENA',
      'KN' => 'SAINT KITTS AND NEVIS',
      'LC' => 'SAINT LUCIA',
      
      'PM' => 'SAINT PIERRE AND MIQUELON',
      'VC' => 'SAINT VINCENT AND THE GRENADINES',
      'WS' => 'SAMOA (formerly Western Samoa)',
      'SM' => 'SAN MARINO (Republic of)',
      'ST' => 'SAO TOME AND PRINCIPE',
      'SA' => 'SAUDI ARABIA (Kingdom of Saudi Arabia)',
      'SN' => 'SENEGAL',
      'RS' => 'SERBIA (Republic of Serbia)',
      'SC' => 'SEYCHELLES',
      'SL' => 'SIERRA LEONE',
      'SG' => 'SINGAPORE',
      'SX' => 'SINT MAARTEN',
      'SK' => 'SLOVAKIA (Slovak Republic)',
      'SI' => 'SLOVENIA',
      'SB' => 'SOLOMON ISLANDS',
      'SO' => 'SOMALIA',
      'ZA' => 'ZAMBIA (formerly Northern Rhodesia)',
      'GS' => 'SOUTH GEORGIA AND THE SOUTH SANDWICH ISLANDS',
      'SS' => 'SOUTH SUDAN',
      'ES' => 'SPAIN (España)',
      'LK' => 'SRI LANKA (formerly Ceylon)',
      'SD' => 'SUDAN',
      'SR' => 'SURINAME',
      'SJ' => 'SVALBARD AND JAN MAYE',
      'SZ' => 'SWAZILAND',
      'SE' => 'SWEDEN',
      'CH' => 'SWITZERLAND (Confederation of Helvetia)',
      'SY' => 'SYRIAN ARAB REPUBLIC',
      'TW' => 'TAIWAN ("Chinese Taipei" for IOC)',
      'TJ' => 'TAJIKISTAN',
      'TZ' => 'TANZANIA',
      'TH' => 'THAILAND',
      'TL' => 'TIMOR-LESTE (formerly East Timor)',
      'TG' => 'TOGO',
      'TK' => 'TOKELAU',
      'TO' => 'TONGA',
      'TT' => 'TRINIDAD AND TOBAGO',
      'TN' => 'TUNISIA',
      'TR' => 'TURKEY',
      'TM' => 'TURKMENISTAN',
      'TC' => 'TURKS AND CAICOS ISLANDS',
      'TV' => 'TUVALU',
      'UG' => 'UGANDA',
      'UA' => 'UKRAINE',
      'AE' => 'UNITED ARAB EMIRATES',
      'US' => 'UNITED STATES',
      'UM' => 'UNITED STATES MINOR OUTLYING ISLANDS',
      'UK' => 'UNITED KINGDOM',
      'UY' => 'URUGUAY',
      'UZ' => 'UZBEKISTAN',
      'VU' => 'VANUATU',
      'VA' => 'VATICAN CITY (Holy See)',
      'VN' => 'VIET NAM',
      'VG' => 'VIRGIN ISLANDS, BRITISH',
      'VI' => 'VIRGIN ISLANDS, U.S.',
      'WF' => 'WALLIS AND FUTUNA',
      'EH' => 'WESTERN SAHARA (formerly Spanish Sahara)',
      'YE' => 'YEMEN (Yemen Arab Republic)',
      'ZW' => 'ZIMBABWE'
    );
    
    $daily_browsers = json_encode(array());
    if(isset($url_details['analytics']['day']['browsers']))
	   $daily_browsers = json_encode($url_details['analytics']['day']['browsers']);

    $table_for_daily_referrer = "";
    if(isset($url_details['analytics']['day']['referrers'])){
       $daily_referrer_str = "<table class='table table-striped'> <tr><th>Referrer</th><th>Click</th></tr>";
	   $daily_referrers = $url_details['analytics']['day']['referrers'];
       foreach($daily_referrers as $daily_referrer)
       {
           $daily_referrer_str .= "<tr><td>".$daily_referrer['id']."</td><td>".$daily_referrer['count']."</td></tr>";
       }
       $daily_referrer_str .= "</table>";
       $table_for_daily_referrer = $daily_referrer_str;

    }

    $daily_os = json_encode(array());
    if(isset($url_details['analytics']['day']['platforms']))
       $daily_os = json_encode($url_details['analytics']['day']['platforms']);

	$table_for_daily_contries = "";
    if(isset($url_details['analytics']['day']['countries'])){
       $daily_country_str = "<table class='table table-striped'> <tr><th>Country</th><th>Click</th></tr>";
	   $daily_countries = $url_details['analytics']['day']['countries'];
       foreach($daily_countries as $daily_country)
       {
           $daily_country_str .= "<tr><td>".$array_countries[$daily_country['id']]."</td><td>".$daily_country['count']."</td></tr>";
       }
       $daily_country_str .= "</table>";
       $table_for_daily_contries = $daily_country_str;
    }

?>

<div role="tabpanel" class="tab-pane active" id="todays_report">	
	<div class="row">
		<div class="col-xs-12 col-sm-6 col-md-6 col-lg-6">
			<!-- AREA CHART -->
			<div class="box box-primary">
				<div class="box-header with-border">
				<h3 class="box-title" style="color: blue; word-spacing: 4px;"><i class="fa fa-firefox"></i> <?php echo $this->lang->line('browser report'); ?></h3>
					<div class="box-tools pull-right">
						<button class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-minus"></i></button>
						<button class="btn btn-box-tool" data-widget="remove"><i class="fa fa-times"></i></button>
					</div>
				</div>
				<div class="box-body">
					<div class="chart">
						<div class="chart" id="daily_browser_report_bar_chart" style="height: 300px;"></div>
					</div>
				</div><!-- /.box-body -->
			</div><!-- /.box -->
		</div>

		<div class="col-xs-12 col-sm-6 col-md-6 col-lg-6">
			<div class="box box-primary">
				<div class="box-header with-border">
					<h3 style="color: blue; word-spacing: 4px;" class="box-title"><i class="fa fa-flag"></i> <?php echo $this->lang->line('country report'); ?></h3>
					<div class="box-tools pull-right">
						<button data-widget="collapse" class="btn btn-box-tool"><i class="fa fa-minus"></i></button>
						<button data-widget="remove" class="btn btn-box-tool"><i class="fa fa-times"></i></button>
					</div>
				</div>
				<div class="box-body">
                    <div class="table table-responsive" style="height:300px;">
                        <?php echo $table_for_daily_contries; ?>
                    </div>
				</div>
			</div> <!-- end box -->			
		</div>

	</div>

	<div class="row">
		<div class="col-xs-12 col-sm-6 col-md-6 col-lg-6">
			<div class="box box-primary">
				<div class="box-header with-border">
					<h3 style="color: blue; word-spacing: 4px;" class="box-title"><i class="fa fa-desktop"></i> <?php echo $this->lang->line('platform report'); ?></h3>
					<div class="box-tools pull-right">
						<button data-widget="collapse" class="btn btn-box-tool"><i class="fa fa-minus"></i></button>
						<button data-widget="remove" class="btn btn-box-tool"><i class="fa fa-times"></i></button>
					</div>
				</div>
				<div class="box-body">
					<div class="chart">
                        <div class="chart" id="daily_os_report_bar_chart" style="height: 300px;"></div>
                    </div>
				</div>
			</div> <!-- end box -->			
		</div>

		<div class="col-xs-12 col-sm-6 col-md-6 col-lg-6">
			<!-- AREA CHART -->
			<div class="box box-primary">
				<div class="box-header with-border">
				<h3 class="box-title" style="color: blue; word-spacing: 4px;"><i class="fa fa-arrow-circle-down"></i> <?php echo $this->lang->line('referrer report'); ?></h3>
					<div class="box-tools pull-right">
						<button class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-minus"></i></button>
						<button class="btn btn-box-tool" data-widget="remove"><i class="fa fa-times"></i></button>
					</div>
				</div>
				<div class="box-body">					
                    <div class="table table-responsive" style="height:300px;">
                        <?php echo $table_for_daily_referrer; ?>
                    </div>
				</div><!-- /.box-body -->
			</div><!-- /.box -->
		</div>
	</div>
</div>
<script>
	var daily_char_data = '<?php echo $daily_browsers; ?>';
	//BAR CHART
    if(daily_char_data != '[]'){

        var daily_borwser_bar = new Morris.Bar({
          element: 'daily_browser_report_bar_chart',
          resize: true,
          data: JSON.parse(daily_char_data),
          barColors: ['#EC7022'],
          xkey: 'id',
          ykeys: ['count'],
          labels: ['Click'],
          hideHover: 'auto'
        });
    }


    var daily_os_data = '<?php echo $daily_os; ?>';
	//BAR CHART
    if(daily_os_data != '[]'){
        
        var daily_os_bar = new Morris.Bar({
          element: 'daily_os_report_bar_chart',
          resize: true,
          data: JSON.parse(daily_os_data),
          barColors: ['#129793'],
          xkey: 'id',
          ykeys: ['count'],
          labels: ['Click'],
          hideHover: 'auto'
        });
    }


</script>


