Ejemplo n.º 1
0
 public static function storeUnit()
 {
     $params = $_POST;
     //Kint::dump($params);
     $attributes = array('waybill_id' => $params['waybill_id'], 'productname' => $params['productname'], 'weight' => $params['weight'], 'velocity' => $params['velocity'], 'demand' => $params['demand'], 'un_number' => $params['un_number'], 'loading_format' => $params['loading_format'], 'info' => $params['info']);
     $unit = new unit($attributes);
     $errors = $unit->errors();
     if (count($errors) == 0) {
         $unit->save();
         Redirect::to('/waybill/' . $unit->waybill_id . '/show', array('message' => 'Uusi tuote on lisätty onnistuneesti!'));
     } else {
         $waybill = $this->find($unit->waybill_id);
         View::make('waybill/' . $unit->waybill_id . 'unit.html', array('errors' => $errors, 'attributes' => $attributes, 'waybill' => $waybill));
     }
 }
$error_level = 0;
switch ($_POST['action']) {
    case 'save_data':
        // When action==save_data: verify entered data and save if OK / set errorlevel when NOK
        //
        // Check for data format and required fields
        // change action when not everything is filled-in
        if ($_POST['units_name'] == '') {
            $_POST['action'] = 'enter_data';
            $error_level = 1;
            // No units_name
        } else {
            // OK, entry can be saved
            $administration_unit = new unit($_POST['units_id']);
            $administration_unit->fill($_POST['units_name'], $_POST['units_description']);
            $administration_unit->save();
            // Clear all values except mPath
            foreach ($_POST as $key => $value) {
                if ($key != 'mPath') {
                    unset($_POST[$key]);
                }
            }
        }
        break;
    case 'delete_entry':
        // Check for dependencies
        $administration_unit = new unit($_POST['units_id']);
        if ($administration_unit->has_dependencies()) {
            $error_level = 2;
            // Related tariff(s) exist
            $_POST['action'] = '';