1<?php
2/**
3 * ThunderSnarf
4 *
5 * @author Ricardo H.F. Sette P. <ricardohfsp@gmail.com>
6 * @link http://www.freebsdbrasil.com.br/
7 * @copyright Copyright &copy; 2010 - FreeBSD Brasil LTDA
8 * @license licença GNU/GPL v2.0 http://www.gnu.org/licenses/gpl-2.0.html
9 */
10?>
11<?php
12$this->breadcrumbs=array(
13	'Ips'=>array('index'),
14	'Informações',
15);
16function formatBytes($bytes, $precision = 2) {
17	    $units = array('B', 'KB', 'MB', 'GB', 'TB');
18
19	    $bytes = max($bytes, 0);
20	    $pow = floor(($bytes ? log($bytes) : 0) / log(1024));
21	    $pow = min($pow, count($units) - 1);
22
23	    $bytes /= pow(1024, $pow);
24
25	    return round($bytes, $precision) . '' . $units[$pow];
26	}
27
28/*$this->menu=array(
29	array('label'=>'List Ip', 'url'=>array('index')),
30	array('label'=>'Create Ip', 'url'=>array('create')),
31);*/
32
33Yii::app()->clientScript->registerScript('search', "
34$('.search-button').click(function(){
35	$('.search-form').toggle();
36	return false;
37});
38$('.search-form form').submit(function(){
39	$.fn.yiiGridView.update('ip-grid', {
40		data: $(this).serialize()
41	});
42	return false;
43});
44");
45?>
46
47<h1>Informações por Ip</h1>
48
49<?php echo CHtml::link('Filtro','#',array('class'=>'search-button')); ?>
50
51<?php echo CHtml::dropDownList(
52				'pageSize',
53				Yii::app()->user->getState('pageSize',Yii::app()->params['defaultPageSize']),
54				array(5=>'5 por página',20=>'20 por página',50=>'50 por página',100=>'100 por página'),
55	            array('class'=>'change-pagesize','style'=>'margin-left:10px')
56			);
57?>
58<?php echo CHtml::dropDownList(
59				'tipoTrafego',
60				isset($_GET['tipoTrafego'])?$_GET['tipoTrafego']:'',
61				array('E'=>'Somente Estático','D'=>'Somente Dinâmico'),
62				array('empty'=>'Estáticos e Dinâmicos','class'=>'change-tipoTrafego')
63			);
64?>
65
66<div class="search-form" style="display:none">
67<?php $this->renderPartial('_search',array(
68	'model'=>$model,
69)); ?>
70</div><!-- search-form -->
71
72<?php
73if(isset($_GET['eficienciaDynamic']) AND $_GET['eficienciaDynamic']=='2')
74	$valorEficienciaDynamic = '$data->hit_dynamic>0 ? \'<b>\'.number_format(((100*$data->hit_dynamic)/($data->hit_dynamic + $data->miss_dynamic)),2,",","").\'%</b>\' : \'<b>0%</b>\'';
75else
76	$valorEficienciaDynamic = '$data->cache_dynamic>0 ? \'<b>\'.number_format(((100*$data->cache_dynamic)/($data->cache_dynamic + $data->traffic_dynamic)),2,",","").\'%</b>\' : \'<b>0%</b>\'';
77
78if(isset($_GET['eficienciaStatic']) AND $_GET['eficienciaStatic']=='2')
79	$valorEficienciaStatic = '$data->hit_static>0 ? \'<b>\'.number_format(((100*$data->hit_static)/($data->hit_static + $data->miss_static)),2,",","").\'%</b>\' : \'<b>0%</b>\'';
80else
81	$valorEficienciaStatic = '$data->cache_static>0 ? \'<b>\'.number_format(((100*$data->cache_static)/($data->cache_static + $data->traffic_static)),2,",","").\'%</b>\' : \'<b>0%</b>\'';
82
83$colunasCGridView = array(
84	array(
85		'name'=>'id',
86		'value'=>'CHtml::link(CHtml::encode($data->id), array("view", "id"=>$data->id))',
87		'type'=>'html'
88	),
89	'ip',
90	array(
91        'name'=>'cache_static',
92        'value'=>'formatBytes($data->cache_static)',
93    ),
94	array(
95        'name'=>'traffic_static',
96        'value'=>'formatBytes($data->traffic_static)',
97    ),
98	array(
99        'name'=>'Total',
100        'value'=>'formatBytes($data->cache_static + $data->traffic_static)',
101    ),
102	'hit_static',
103	'miss_static',
104	array(
105        'name'=>'Total',
106        'value'=>'$data->hit_static + $data->miss_static',
107    ),
108	array(
109        'header'=>CHtml::label('Eficiência E',false,array("title"=>"Eficiencia Estática")).CHtml::dropDownList(
110						"eficienciaStatic",
111						isset($_GET['eficienciaStatic']) ? $_GET['eficienciaStatic'] : '1',
112						array("1"=>"Cache","2"=>"Hit"),
113			            array("class"=>"change-eficienciaStatic")
114					),
115        'value'=>$valorEficienciaStatic,
116		'type'=>'html'
117    ),
118	array(
119        'name'=>'cache_dynamic',
120        'value'=>'formatBytes($data->cache_dynamic)',
121    ),
122	array(
123        'name'=>'traffic_dynamic',
124        'value'=>'formatBytes($data->traffic_dynamic)',
125    ),
126	array(
127        'name'=>'Total',
128        'value'=>'formatBytes($data->cache_dynamic + $data->traffic_dynamic)',
129    ),
130	'hit_dynamic',
131	'miss_dynamic',
132	array(
133        'name'=>'Total',
134        'value'=>'$data->hit_dynamic + $data->miss_dynamic',
135    ),
136	array(
137        'header'=>CHtml::label('Eficiência D',false,array("title"=>"Eficiencia Dinâmica")).CHtml::dropDownList(
138						"eficienciaDynamic",
139						isset($_GET['eficienciaDynamic']) ? $_GET['eficienciaDynamic'] : '1',
140						array("1"=>"Cache","2"=>"Hit"),
141			            array("class"=>"change-eficienciaDynamic")
142					),
143        'value'=>$valorEficienciaDynamic,
144		'type'=>'html'
145    ),
146	array(
147    	'header'=>CHtml::label("Nro Reqs",false,array("title"=>"Número de Requisições")),
148    	'name'=>'requested',
149    	'value'=>'$data->requested',
150    ),
151);
152if(isset($_GET["tipoTrafego"]) and $_GET["tipoTrafego"]=="E"){
153	unset($colunasCGridView[9]);
154	unset($colunasCGridView[10]);
155	unset($colunasCGridView[11]);
156	unset($colunasCGridView[12]);
157	unset($colunasCGridView[13]);
158	unset($colunasCGridView[14]);
159	unset($colunasCGridView[15]);
160}else if(isset($_GET["tipoTrafego"]) and $_GET["tipoTrafego"]=="D"){
161	unset($colunasCGridView[2]);
162	unset($colunasCGridView[3]);
163	unset($colunasCGridView[4]);
164	unset($colunasCGridView[5]);
165	unset($colunasCGridView[6]);
166	unset($colunasCGridView[7]);
167	unset($colunasCGridView[8]);
168}else{
169	unset($colunasCGridView[4]);
170	unset($colunasCGridView[7]);
171	unset($colunasCGridView[11]);
172	unset($colunasCGridView[14]);
173}
174$this->widget('zii.widgets.grid.CGridView', array(
175	'id'=>'ip-grid',
176	'dataProvider'=>$model->search(),
177	//'filter'=>$model,
178	'summaryText'=>'Exibindo {start} até {end} de {count} resultado(s).',
179	'columns'=>$colunasCGridView,
180)); ?>
181<?php Yii::app()->clientScript->registerScript('initPageSize',<<<EOD
182    $('.change-pagesize').bind('change', function() {
183        $.fn.yiiGridView.update('ip-grid',{ data:{ pageSize: $(this).val() }});
184    });
185EOD
186,CClientScript::POS_READY); ?>
187<?php Yii::app()->clientScript->registerScript('tipoTrafego',<<<EOD
188    $('.change-tipoTrafego').bind('change', function() {
189        $.fn.yiiGridView.update('ip-grid',{ data:{ tipoTrafego: $(this).val() }});
190    });
191EOD
192,CClientScript::POS_READY); ?>
193<?php Yii::app()->clientScript->registerScript('eficienciaDynamic',<<<EOD
194    $('.change-eficienciaDynamic').live('change', function() {
195        $.fn.yiiGridView.update('ip-grid',{ data:{ eficienciaDynamic: $(this).val() }});
196    });
197EOD
198,CClientScript::POS_READY); ?>
199<?php Yii::app()->clientScript->registerScript('eficienciaStatic',<<<EOD
200    $('.change-eficienciaStatic').live('change', function() {
201        $.fn.yiiGridView.update('ip-grid',{ data:{ eficienciaStatic: $(this).val() }});
202    });
203EOD
204,CClientScript::POS_READY); ?>
205