<?php use_helper('UrlFunctions'); 
$parametros = str_replace("=&","=-1&",$parametros);
?>
<script src="/carlin/web/hc/code/highcharts.js"></script>
<script src="/carlin/web/hc/code/highcharts-3d.js"></script>
<script src="/carlin/web/hc/code/modules/data.js"></script>
<script src="/carlin/web/hc/carlin//hc/code/modules/exporting.js"></script>
<script src="/carlin/hc/web/carlin//hc/code/modules/export-data.js"></script>
<script type="text/javascript">
/*	
	document.addEventListener('DOMContentLoaded', function () {
    var options = {
        chart: {
            type: 'spline'
        },
        series: [{}]
    };
    Highcharts.ajax({  
        url: 'http://localhost/hc/p_json.json',  
        success: function(data) {
            options.series[0].data = data;
            Highcharts.Chart('container', options);
        }  
    });		
});
*/




function showResponse(originalRequest)
{
	//put returned XML in the textarea
	//alert(originalRequest);
	
	
	//data = JSON.parse(originalRequest.responseText);
	
	/*
	data = originalRequest.responseText;
	$("container").innerHTML = data;
	data = JSON.parse(data);
	*/
	data = originalRequest.responseText;
	data = data.evalJSON(true);
	
	//data = originalRequest.responseJSON;
	//data = Object.evalJSON(data)
	//data = JSON.parse(data);
		
	//data = data.evalJSON(true);

	//var data = '{ "name": "Violet", "occupation": "character" }'.evalJSON();
	//$("container").innerHTML = data;
	
	/* Otra alternativa que funciona
	data = originalRequest.responseText;
	data = data.evalJSON(true);
	*/
	
	var objects =[];
	console.log(data.titulo);
	var TextTitulo = data.titulo;
	var TextSubTitulo = data.subtitulo;
	var TextTiuloYAxis = data.tiuloyaxis;
	var TextCategories = data.categories;
	//alert("****");
	console.log(TextCategories);
	const it = (obj, tabSize = 0) => {
		var objects =[];
		for (let k in obj) {
			const v = obj[k];
			if (Object.prototype.toString.call(v) === '[object Object]') {
			  //console.log(`${k}:`);
			  //console.log(v);
			  objects.push(v);
			  it(v, tabSize + 1);
			} else {
			  //console.log(`${'\t--'.repeat(tabSize)}${k}: ${v}`);
			}
			//objects.push(obj);
		}
	return objects;
	};
	data = data.datos;
	objects = it(data);
	
	console.log(objects);
	
	//alert("****");
	/*
	var datos = [{
		name: 'Name',
		data: objects      
	}];
	*/     
		
Highcharts.chart('container', {
	chart: {
        type: 'column',
        options3d: {
            enabled: true,
            alpha: 3,
            beta: 25,
            depth: 70
        }
    },
	lang: {
        downloadCSV:"Descarga CSV",       
        viewFullscreen:"Ver en pantalla completa",
        printChart:"Imprimir Imagen",
        downloadPNG:"Descargar Imagen en PNG",
        downloadXLS:"Descargar valores en Excel"
    },
	
        exporting: {
            filename: 'export_xlsx_example',
            buttons: {
                contextButton: {
                    enabled: true,
                    menuItems: [{
                        text: 'Exportar XLSX',
                        onclick: function() {
                            this.downloadXLS();
                        }
                    }, {
                        text: 'Exportar CSV',
                        onclick: function() {
                            this.downloadCSV();
                        }
                    }, {
                        text: 'Exportar PNG',
                        onclick: function() {
                            this.exportChart({
                                type: 'image/png'
                            });
                        }
                    }, {
                        text: 'Exportar PDF',
                        onclick: function() {
                            this.exportChart({
                                type: 'application/pdf'
                            });
                        }
                    }]
                }
            },
            csv: {
                // dateFormat: '%Y%m'
            },
            xlsx: {
                worksheet: {
                    autoFitColumns: true,
                    categoryColumnTitle: 'Month',
                    dateFormat: 'yyyy-mm',
                    name: 'Export XLSX Test'
                },
                workbook: {
                    fileProperties: {
                        Author: "File Author",
                        Company: "File Company",
                        CreatedDate: new Date(Date.now())
                    }
                }
            }
        },
	title: {
		text: TextTitulo
	},
	subtitle: {
		text: TextSubTitulo
	},
	xAxis: {
		categories: TextCategories,
		labels: {
            skew3d: true,
            style: {
                fontSize: '16px'
            }
        }
	},
	yAxis: {
		/*min: 10,*/
		title: {
			text: TextTiuloYAxis
		}
	},
    credits: {
        enabled: false
    }/*,
	tooltip: {
		headerFormat: '<span style="font-size:10px">{point.key}</span><table>',
		pointFormat: '<tr><td style="color:{series.color};padding:0">{series.name}: </td>' +
			'<td style="padding:0"><b>{point.y:.1f} mm</b></td></tr>',
		footerFormat: '</table>',
		shared: true,
		useHTML: true
	},
	plotOptions: {
		column: {
			pointPadding: 0.2,
			borderWidth: 0
		}
	}*/
    ,
    plotOptions: {
        column: {
            depth: 25
        }
    },    
		series: objects
	})                          
	
	
}

</script>
<script>
findControl = function(){
  
  concatValueStr();
  
}

exportFindControl = function(action){
  strFormSerialize = returnQueryStringForm();
  executeFind(strFormSerialize, action);
}

executeFind = function(str, action){
  if(typeof(action) == 'undefined'){
	  url = "<?=buildUrl('resumdiario/show', "block=".$block)?>";
	}else{
	  switch (action){
	    case 'excel': parent.objMainTab.reqBody('<?=buildUrl('rcd/excel')?>','001&'+str); break;
	    case 'pdf': parent.objMainTab.reqBody('<?=buildUrl('rcd/pdf')?>','001&'+str); break;	    
	    case 'pdf_supervisor': parent.objMainTab.reqBody('<?=buildUrl('rcd/pdf_supervisor')?>','001&'+str); break;	    
	    case 'pdf_moroso': parent.objMainTab.reqBody('<?=buildUrl('rcd/pdf_moroso')?>','001&'+str); break;
	  }
	  
	  return;
	}
  //str = str + '&block=001';
  url = "<?=buildUrl('resumdiario/show', "block=".$block)?>";
	var myAjax  = new Ajax.Updater(
                                	"resultGrtid",
                                	url,
                                	{
                                		asynchronous:	true,
                                		method			: 'get',
                                		parameters	: str,
                                		evalScripts	: true,
                                		onLoading   : cargandoImagenSerch(),
                                		onComplete	: function(){
                                			//objMainTab.showMenu();
                                		}
                                	});
}

concatValueStr = function(){
  strFormSerialize = returnQueryStringForm();
  if(arguments[0]){
    strFormSerialize += '&'+arguments[0];
  }
  executeFind(strFormSerialize);
}

function returnQueryStringForm(){
  cadenaFormulario = $('form1').serialize();
             var posicion = new Array();
             var a_pars = new Array();
             var miArray = new Array();
             posicion=[];
             a_pars=[];
             miArray=[];
             miArray = cadenaFormulario.split('&');
             x=0;
             for (i = 0; i < miArray.length; i++){
            	   posicion[i] = miArray[i].indexOf('=');
            	   if(typeof(miArray[i-1])!='undefined'){
            				if(miArray[i].substring(posicion[i],0)== miArray[i-1].substring(posicion[i-1],0) ){
           					 porcion = miArray[i].substring((1+posicion[i]));
           					 a_pars[x-1]+='@'+porcion;
           				}else{
          					 a_pars[x]= miArray[i];
         					 x++;
          				}
          		}else{
          			 a_pars[x]= miArray[i];
          			  x++;
          		}
           }
  cadenaFormulario = a_pars.join('&');
  cadenaFormulario += '&id_form=frmFindFedu';
  return(cadenaFormulario);
}

function cargandoImagenSerch(){
	//disabledWin.setPathImage('/images/common/progress.gif');
	disabledWin.show(true,true,'resultGrtid');
}

</script>
<script>
findControl = function(){
  datastart = '';
  dataend = '';
  var pars = 'startDate=' + datastart + '&endDate=' + dataend;
  
	disabledWin.setPathImage('/images/common/progress.gif');
	disabledWin.show(true,true,'resultGrtid');
  
	url = "<?=buildUrl('resumdiario/gridshow', "block=".$block)?>";
	var myAjax  = new Ajax.Updater(
	"resultGrtid",
	url,
	{
		asynchronous:	true,
		method			: 'get',
		parameters	: pars,
		evalScripts	: true,
		onLoading		: function(){
			//$('contentMenu').innerHTML = $('messageLoadMenu').innerHTML;
		},
		onComplete	: function(){
			//objMainTab.showMenu();
			datastart = '';
			dataend = '';
			tipo = '';
			

			//var url = "http://localhost/hc/p_json.php";
			var url = "<?=buildUrl('ajax/request')?>";
			//var pars = $('form1').serialize();
			//var pars = 'startDate=' + datastart + '&endDate=' + dataend;
			var pars = '<?php echo "type=graficarResumenDiario&".$parametros."&Idsucursal=".$Idsucursal."&Campo=".$Campo;?>';
			var pars = pars;

			var myAjax = new Ajax.Request(
				url, 
				{
					method: 'post', 
					evalJSON: 'force',
					requestHeaders:
					{
						Accept: 'application/json'
					},
					parameters: pars, 
					onComplete: showResponse
				});
		}
	});
  
}

deleteRegistro = function(id,codigo){
  //buildUrl('rcd/delete/id/'block=001'
  if(confirm("�Esta seguro de eliminar la ficha del docente con codigo : "+codigo+ " ?")){
      //objMainTab.reqBody('<? //=buildUrl('rcd/add')?>','block=001&delete=1&id='+id);   
      parent.objMainTab.reqBody('<?=buildUrl('rcd/delete')?>','&delete=1&cod=jj&id='+id);
  }
  
}

acutalizarEspecialidad = function(destino,elm){
  $(destino).options.length = 1;
  var url = '<?=buildUrl('ajax/request')?>';
  var pars = 'type=getEspecialidad&nombreElm='+destino+'&value='+elm.value;
  
	var myAjax = new Ajax.Request(
                            		url, 
                            		{
                            			method: 'get', 
                            			parameters: pars, 
                            			onComplete: actualizaJSON
                            		});
}

</script>
<script>
actualizaJSON = function(request, json){
  var numeroElementos = json.length;
  for (var i = 0; i < numeroElementos; i++){
    if($(json[i][0])){
  	  switch ($(json[i][0]).tagName){
  	    case 'TD'      : Element.update(json[i][0], json[i][1]); break;
  	    case 'INPUT'   : $(json[i][0]).value=json[i][1]; break;
  	    case 'SELECT'  : 
  	      var objDDL = $(json[i][0]);
  	      if(typeof(cont) == 'undefined'){
  	        var cont = 0;
  	        objDDL.options.length = 1;
  	      }
  	      var a_contentValues = json[i][1].split("_;_");
      		var value	= a_contentValues[0];
      		var text	= a_contentValues[1];
  	      var option	= new Option(text,value);
      		try{
      			objDDL.add(option,null);
      		}catch (e){
      			objDDL.add(option,-1);
      		}
  	      cont++;
  	    break;
  	  }
    }else{
      if(json[i][0].indexOf("function") > -1){
        eval("scriptEval = "+json[i][0]);
        scriptEval();
      }
    }
  }
}
</script>

<?php
//Carga los Mercado
/*
print_r($_GET);
echo $id;
echo $Campo;
echo "<br>";
echo $Idsucursal;
//echo $parametros;

echo $parametros;
*/
?>

<img src="/images/common/spacer.gif" width="10">
<table class="cuerpo" style="background: #E3E9E2" width="99%" border="0" cellpadding="0" cellspacing="0">
  <tr>
    <td valign="top">
       <div id="resultGrtid">
      	
        </div>
    </td>
  </tr>
</table>
<script>
	findControl();
</script>

