Example #1
0
 public function processExpense()
 {
     if ($this->post->name == '' || $this->post->cost == '') {
         $this->set('message', 'Name and cost must be entered');
         $this->render('core_error.tpl');
         return;
     }
     if (!is_numeric($this->post->cost)) {
         $this->set('message', 'Cost must be a numeric amount, no symbols');
         $this->render('core_error.tpl');
         return;
     }
     if ($this->post->action == 'addexpense') {
         # Make sure it doesn't exist
         if (FinanceData::GetExpenseByName($this->post->name)) {
             $this->set('message', 'Expense already exists!');
             $this->render('core_error.tpl');
             return;
         }
         $ret = FinanceData::AddExpense($this->post->name, $this->post->cost, $this->post->type);
         $this->set('message', 'The expense "' . $this->post->name . '" has been added');
         FinanceData::setExpensesforMonth(time());
         LogData::addLog(Auth::$userinfo->pilotid, 'Added expense "' . $this->post->name . '"');
     } elseif ($this->post->action == 'editexpense') {
         $ret = FinanceData::EditExpense($this->post->id, $this->post->name, $this->post->cost, $this->post->type);
         $this->set('message', 'The expense "' . $this->post->name . '" has been edited');
         FinanceData::setExpensesforMonth(time());
         LogData::addLog(Auth::$userinfo->pilotid, 'Edited expense "' . $this->post->name . '"');
     }
     if (!$ret) {
         $this->set('message', 'Error: ' . DB::error());
         $this->render('core_error.tpl');
         return;
     }
     $this->render('core_success.tpl');
 }