uid = $uid; $this->isOrg = $user->isOrg(); $this->aid = $aid; $datarow = $kdb->getCalculationProgress($uid, $aid); $this->setProgress($datarow); $this->setFootprint($datarow['footprint']); $this->setFootprintPP($datarow['footprint_pp']); $this->setShared($datarow['shared']); $this->setComment($datarow['comment']); $this->setCalculation(unserialize($datarow['calculation'])); // older footprints $fps = $kdb->getFootprintsByUserId($uid); if (count($fps)>0) { $this->footprints = $fps; } } public function getCID() { return $this->aid; } public function getProgress() { return $this->progress; } public function setProgress($dt) { $this->progress = $dt; } public function getIsOrg() { return $this->isOrg; } public function getCalculation() { return $this->calculation; } public function setCalculation($dt) { $this->calculation = $dt; } public function getFootprint() { return $this->footprint; } public function setFootprint($dt) { $this->footprint = $dt; } public function getFootprintPP() { return $this->footprint_pp; } public function setFootprintPP($dt) { $this->footprint_pp = $dt; } public function getShared() { return $this->shared; } public function setShared($dt) { $this->shared = $dt; } public function getComment() { return $this->comment; } public function setComment($dt) { $this->comment = $dt; } public function getTitles() { $titles = array('Elektrienergia'=>array('Põlevkivi'=>'fifth', 'Roheline energia'=>'sixth'), 'Soojusenergia'=>array('Kivisüsi'=>'fifth', 'Nafta'=>'seventh', 'Maagaas'=>'ninth', 'Tuuleenergia'=>'eighth', 'Päikeseenergia'=>'soojus', 'Biomass'=>'sixth', 'Hüdroenergia'=>'third'), 'Vesi'=>array('Vesi'=>'eighth'), 'Inimeste transport'=>array('Autotransport'=>'seventh', 'Takso'=>'soojus', 'Bussitransport'=>'fifth', 'Rongitransport'=>'sixth', 'Laevatransport'=>'third', 'Lennutransport'=>'eighth'), 'Jäätmed'=>array('Taaskasutusse suunatud paber ja papp'=>'sixth', 'Taaskasutusse suunatud pakendid'=>'fifth', 'Taaskasutusse suunatud klaasijäätmed'=>'eighth', 'Taaskasutusse suunatud plastijäätmed'=>'soojus', 'Taaskasutusse suunatud metall'=>'ninth', 'Olmeprügi (prügilasse)'=>'second'), 'Kaupade transport'=>array('Maanteetransport'=>'seventh', 'Laevatransport'=>'third', 'Rongitransport'=>'sixth', 'Lennutransport'=>'eighth') ); if (!$this->getIsOrg()) { array_pop($titles); } return $titles; } public function getPercents() { $fpt = $this->getFootprint(); $calc = $this->getCalculation(); $percs = array(); $width = 440; $lwidth = 186; $po = 0; $cal = 0; $total_perc = 0; $total_percs = array(); if ($fpt && $calc) { foreach ($calc as $ca) { $pr = 0; $lpr = 0; $pro = 0; $pos = 0; $cal = $ca['calc']; if ($cal) { $pro = $cal/$fpt*100; $pr = round($pro)*$width/100; $lpr = round($pro)*$lwidth/100; if ($pro<1) { $pro = "alla 1"; } else { $pro = round($pro); } } if ($pr > 0) { if ($pr<10){ $pr = 10; $pos = $po; } else { $pos = $po + ($pr/2)-5; } if ($lpr<4){ $lpr = 4; } } $po = $po + $pr; $cfpt = 0; $cprs = array(); $total_c_perc = 0; foreach ($ca['data'] as $cd) { $cfpt = $cd['fpt']; $pros = 0; $cpr = 0; if ($cfpt) { $pros = $cfpt/$cal*100; $cpr = $pros*$width/100; if ($pros<1) { $pros = "alla 1"; } else if ($pros>99 && $pros<99.999) { $pros = "üle 99"; } else { $pros = round($pros); } if ($cpr<5 && $cpr!=0){ $cpr = 5; } } $total_c_perc = $total_c_perc + $cpr; $cprs []= array('val'=>$cpr, 'pros'=>$pros); } $total_perc = $total_perc + $pr; $total_percs []= round($total_c_perc); $percs []= array('perc'=>$pr, 'lperc'=>$lpr, 'pos'=>$pos, 'cperc'=>$cprs, 'val'=>$ca['val'], 'pros'=>$pro); } if (!$this->getIsOrg()) { array_pop($percs); } if ($total_perc!=$width && $total_perc>0) { $p_index = 0; $cut_off_perc = $width/$total_perc; foreach ($percs as $p_cut) { $new_perc = $cut_off_perc*$p_cut['perc']; $new_pos = $cut_off_perc*$p_cut['pos']; $percs[$p_index]['perc'] = $new_perc; $percs[$p_index]['pos'] = $new_pos; $p_index++; } } $p_index = 0; foreach ($total_percs as $t_perc) { if ($t_perc!=$width && $t_perc>0) { $cut_off_perc = $width/$t_perc; $pc_index = 0; $check_it = 0; foreach ($percs[$p_index]['cperc'] as $cperc) { $new_perc = $cut_off_perc*$cperc['val']; $check_it = $check_it + round($new_perc); $percs[$p_index]['cperc'][$pc_index]['val'] = $new_perc; $pc_index++; } if ($check_it<$width) { $percs[$p_index]['cperc'][0]['val'] = $percs[$p_index]['cperc'][0]['val'] + $width-$check_it; } } $p_index++; } return $percs; } return false; } public function getComponents() { $cmps = 0; $gcalc = $this->getCalculation(); if ( $gcalc ) { foreach ($this->getCalculation() as $c) { if ($c['answered']) { $cmps = $cmps + $c['answered']; } } } return $cmps; } function getUrl() { return CALC_URL; } } if ( isset($_GET['reset']) ) { global $kdb; $kdb->query("DELETE FROM users WHERE id=".$_SESSION['userid']." AND !registred"); session_destroy(); header("Location:index.php"); } if ( isset($_POST['actionShare']) ) { global $kdb; if ( isset($_POST['sharefootprint'])) { $kdb->query("UPDATE answers SET shared=1, comment='".$_POST['sharecomment']."' WHERE id=".$_SESSION['cid']); } else { $kdb->query("UPDATE answers SET shared=0 WHERE id=".$_SESSION['cid']); } header("Location:index.php"); } else if ( isset($_POST['actionRegister']) ) { header("Location:index.php?register"); } $fp = new FootPrint($_SESSION['userid'], $_SESSION['cid']); $kesa->setTemplate("footprint.html"); $kesa->setPage($fp); ?>