diff --git a/app/models/CustPlantAttrModel.php b/app/models/CustPlantAttrModel.php index eb4e948b..9068b3e6 100644 --- a/app/models/CustPlantAttrModel.php +++ b/app/models/CustPlantAttrModel.php @@ -82,9 +82,16 @@ public static function interpretContent($content, $datatype) public static function addAttribute($plant, $label, $datatype, $content) { try { + $user = UserModel::getAuthUser(); + if (!$user) { + throw new \Exception('Invalid user'); + } + static::raw('INSERT INTO `' . self::tableName() . '` (plant, label, datatype, content) VALUES(?, ?, ?, ?)', [ $plant, $label, $datatype, static::interpretContent($content, $datatype) ]); + + LogModel::addLog($user->get('id'), $plant, $label . ' (' . $datatype . ')', $content, url('/plants/details/' . $plant)); } catch (\Exception $e) { throw $e; } @@ -102,9 +109,16 @@ public static function addAttribute($plant, $label, $datatype, $content) public static function editAttribute($id, $plant, $label, $datatype, $content) { try { + $user = UserModel::getAuthUser(); + if (!$user) { + throw new \Exception('Invalid user'); + } + static::raw('UPDATE `' . self::tableName() . '` SET label = ?, datatype = ?, content = ? WHERE id = ?', [ $label, $datatype, static::interpretContent($content, $datatype), $id ]); + + LogModel::addLog($user->get('id'), $plant, $label . ' (' . $datatype . ')', $content, url('/plants/details/' . $plant)); } catch (\Exception $e) { throw $e; } diff --git a/app/views/layout.php b/app/views/layout.php index 526269e8..b951ef3e 100644 --- a/app/views/layout.php +++ b/app/views/layout.php @@ -1262,6 +1262,7 @@