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->setPeriod($this->getMonthName($datarow['period_start_month'])." ".$datarow['period_start_year']." - ".$this->getMonthName($datarow['period_end_month'])." ".$datarow['period_end_year']); $this->setCalculation(unserialize($datarow['calculation'])); } public function getProgress() { return $this->progress; } public function setProgress($dt) { $this->progress = $dt; } public function getIsOrg() { return $this->isOrg; } public function getMonthName($nr) { if ($nr>0 && $nr<=12) { $months = array('jaanuar','veebruar','märts','aprill','mai','juuni','juuli','august','september','oktoober','november','detsember'); return $months[$nr-1]; } return false; } public function getPeriod() { return $this->period; } public function setPeriod($dt) { $this->period = $dt; } 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 getComponents() { $cmps = 0; foreach ($this->getCalculation() as $c) { if ($c['answered']) { $cmps = $cmps + $c['answered']; } } return $cmps; } public function setFootprintPP($dt) { $this->footprint_pp = $dt; } public function getCent1($index) { $cts = array('elektrienergia kasutamises', 'soojusenergia kasutamises', 'vee kasutamises', 'inimeste transpordis', 'jäätmetekkes ', 'kaupade transpordis'); return $cts[$index]; } public function getCent2($index) { $cts = array('elektrienergia', 'soojusenergia', 'vesi', 'inimeste transport', 'jäätmed', 'kaupade transport'); return $cts[$index]; } public function checkPercent($p) { if ($p<1) { return "alla 1" ; } return $p; } public function getOrder() { $order = array(); $fpt = $this->getFootprint(); if ($fpt>0) { $io = $this->getIsOrg(); $od = $this->getCalculation(); $i = 0; foreach ($od as $o=>$d) { $order[$i] = round($d['calc']/$fpt*100); $i++; } $ri = 1; if (!$io) { array_pop($order); $ri = 2; } arsort($order); $orders = array(); $inx = 0; foreach ($order as $o=>$r) { $orders []= $o; } $ordercent = "Sinu kodu"; if ($this->getIsOrg()) { $ordercent = "Sinu organisatsiooni"; } $ordercent .= " kõige suurem mõju keskkonnale avaldub "; $ordercent .= $this->getCent1($orders[0])." (".$this->checkPercent($order[$orders[0]])."%). "; $ordercent .= "Tähtsuselt järgmised on "; $ordercent .= $this->getCent2($orders[1])." (".$this->checkPercent($order[$orders[1]])."%) "; $ordercent .= "ja "; $ordercent .= $this->getCent2($orders[2])." (".$this->checkPercent($order[$orders[2]])."%). "; $ordercent .= "Kõige väiksema osatähtsusega on "; $ordercent .= $this->getCent2($orders[count($order)-$ri+1])." (".$this->checkPercent($order[$orders[count($order)-$ri+1]])."%) "; $ordercent .= "ja "; $ordercent .= $this->getCent2($orders[count($order)-$ri])." (".$this->checkPercent($order[$orders[count($order)-$ri]])."%). "; return $ordercent; } return ""; } } if ( isset($_GET['reset']) ) { global $kdb; $kdb->query("DELETE FROM users WHERE id=".$_SESSION['userid']." AND !registred"); session_destroy(); header("Location:index.php"); } $fp = new Progress($_SESSION['userid'], $_SESSION['cid']); $kesa->setTemplate("calculation_progress.html"); $kesa->setPage($fp); ?>