Ok ho avuto tempo in questi giorni di correggere qualcosa e ora mi trovo in questa situazione:
in risultato.php è presente la sola classe, ecco il codice:
codice:
<?php
class Goptimeze {
public $mLen=5800;
public $result=[];
public $html='';
public function CreateForm(){
if(empty($this->input->post())){
$this->load->view('CreateForm');
}else{
$this->load->view('ParseRequest',['data'=>$this->input->post('np')]);
}
}
public function parseRequest(){
$data=[];
foreach ($_POST['data'] as $k=>$v){
$v['len']+=10; //aggiungo 10mm per il taglio
$data[]=[$v['qta'],$v['len']]; //aggiungo all'array
}
echo $this->creaLen($data)->html;
}
public function __construct() {
ini_set('memory_limit',-1);
}
public function creaLen($data){
$bs=[];
foreach ($data as $k=>$v){
!isset($bs[$v[1]])?$bs[$v[1]]=$v[0]:$bs[$v[1]]+=$v[0];
}
krsort($bs);
$data=[];
foreach ($bs as $k=>$v){
$data[]=[$v,$k];
}
foreach ($data as $items){
$this->creaTravi($items);
}
$this->createOutput();
return $this;
}
public function creaTravi($data){
for($i=0;$i<$data[0];$i++){
if($this->findInPath($data))$this->findLocation($data[1]);
}
}
public function findInPath($data){
$num=$data[0];
$el=0;
foreach ($this->result as $k=>$v){
foreach ($v['values'] as $items){
if($items==$data[1])$el++;
}
}
if($el>=$num)return false;
else return true;
}
public function findLocation($len){
if(empty($this->result))$this->Trave($len);
else{
$loc=false;
foreach ($this->result as $k=>$v){
if(!$loc && $this->result[$k]['len']-$len>=0){
$this->result[$k]['values'][]=$len;
$this->result[$k]['len']-=$len;
$loc=true;
}
}
if(!$loc)$this->Trave($len);
}
}
public function Trave($in){
$this->result[]=['values'=>[$in],'len'=>$this->mLen-$in];
}
public function createOutput(){
$table='<table border="1" bgcolor="#ffffff" bordercolor="black">
<thead><tr><th>Verga</th><th>Elementi</th><th></th><th>N Pezzi</th><th></th><th>Sfrido</th></tr></thead><tbody></tbody>';
$all_t=0;
$sf=0;
foreach ($this->result as $k=>$v){
$table.='<tr><td>'.($k+1).'</td><td><ul>';
$all_t+=count($v['values']);
foreach ($v['values'] as $items){
$items-=10;
$table.='<li>'.$items.'</li>';
}
$table.='</ul></td><th></th><td>'.count($v['values']).'</td><th></th><td>'.$v['len'].'</td></tr>';
$sf+=$v['len'];
}
$table.='</tbody>';
$table.='<tfoot><tr><th>Verghe utilizzate: '.count($this->result).'</th>
<th></th><th>Pezzi tagliati : '.$all_t.'</th><th></th><th>Scarto totale : '.$sf.'</th><th><a href="CreateForm.php"><img src="home.jpg"></a></tr></tfoot>';
$table.='</table>';
return $this->html=$table;
}
}
?>
Ho creato un altro file chiamato run_class.php che mi esegue correttamente la classe e dovrebbe poi passare i valori a excel.php che mi apre la tabella generata su excel, ma non capisco come mai in excel.php non ci entra proprio.
Di seguito i codici:
run_class.php
codice:
<html>
<body background="macchina.jpg">
<?php
include('risultato.php');
$user=$_POST['user'];
$filename = $_POST['file'];
$res=new Goptimeze();
$res->parseRequest();
?>
<form action="excel.php" method="post">
<input type="hidden" name="user" value="<?php echo $user; ?>" />
<input type="hidden" name="file" value="<?php echo $filename; ?>" />
<input type="button" value="Crea XLS">
</form>
<div style="position: absolute; top:10px; right: 10px">
<img src="x.png">
</div>
<div style="position: absolute; position:fixed; bottom:5px; right: 10px">
<a target="_blank" href="https://www"><font color="blue" size="3">x</font></a>
<a target="_blank" href="https://www"><font color="blue" size="3">x</font></a>
</div>
<br><br>
</body>
</html>
excel.php
codice:
<?php
$filename = $_POST['file'];
$user=$_POST['user'];
require_once('risultato.php');
include('run_class.php');
header("Content-Type: application/vnd.ms-excel");
header("Content-Disposition: inline; filename=".$user."-".$filename);
$res->parseRequest();
?>