db->fetchObjectList($sql); } public function formatYear($year) { $out = ''; $sql = sprintf("SELECT * FROM sprit_log WHERE EXTRACT(YEAR from date) = %d ORDER BY date ASC", $year);; $total_km = 0; $total_liter = 0; $total_price = 0; foreach ($this->db->fetchObjectList($sql) as $row) { $out .= sprintf('%s%s%s' . '%.2f%.2f%.2f' . '%d%d', $row->id, assert_german_date($row->date), $row->city, $row->tankstelle, $row->price_liter, $row->liter,$row->price, $row->km, $row->km_total); $total_km += $row->km; $total_liter += $row->liter; $total_price += $row->price; } if (strlen($out)) { $out = '' . '' . '' . '' . '' . '' . $out . '' . '' . '' . sprintf('', $total_liter, $total_price, $total_km). '' . '
DatumOrtTankstelleEUR/llEURkmgesamt
Summe%.2f%.2f%d 
'; } return $out; } public function ajaxList(Array $data) { return array('html' => array('list_'.$data['year'] => $this->formatYear($data['year']))); } public function ajaxAdd(Array $data) { $data = array('machine' => intval($data['machine']), 'date' => assert_iso_date($data['date']), 'city' => $data['city'], 'tankstelle' => $data['tankstelle'], 'price_liter' => str_replace(',','.',$data['price_liter']), 'liter' => str_replace(',','.',$data['liter']), 'price' => str_replace(',','.',$data['price']), 'km' => intval($data['km']), 'km_total' => intval($data['km_total']), 'sys_edit' => 'now()', 'sys_user' => $_SERVER['REMOTE_USER']); foreach ($data as $k => $v) if (empty($v)) return ajax_error(sprintf('Field %s must not be empty', $k)); if (empty($data['id'])) { $ok = $this->db->insertInto('sprit_log', $data); } else { $ok = $this->db->update('sprit_log', $data, 'id = ' . intval($data['id'])); } $d = explode('-', $data['date']); return array('status' => $ok, 'year' => $d[0]); } public function ajaxSuggestCity(Array $data) { $data['query'] .= '%'; $sql = sprintf("SELECT DISTINCT city FROM sprit_log WHERE lower(city) LIKE %s ORDER BY city", $this->quote(strtolower($data['query']))); $list = array(); foreach ($this->fetchObjectList($sql) as $row) $list[] = array('value' => $row->city, 'data' => $row->city); return array('suggestions' => $list); } public function ajaxSuggestTankstelle(Array $data) { $data['query'] .= '%'; $sql = sprintf("SELECT DISTINCT tankstelle FROM sprit_log WHERE city = %s AND lower(tankstelle) LIKE %s ORDER BY tankstelle", $this->quote($data['city']), $this->quote(strtolower($data['query']))); $list = array(); foreach ($this->fetchObjectList($sql) as $row) $list[] = array('value' => $row->tankstelle, 'data' => $row->tankstelle); return array('suggestions' => $list); } }