/** * check if values $_REQUEST[''] exist - then get friend by id (existing friend) * if values not exist then create a new friend (new friend) * @return array */ protected function run() { if (array_key_exists('id', $_REQUEST) and $_REQUEST['id'] > 0) { $friend = Friends::getFriendByID($_REQUEST['id']); } else { $friend = new Friend(); } /** * if $_POST_[""] is not empty then set the values into the template * else set error massage if one of the $_POST[""] is empty */ if (!empty($_POST["name"]) and !empty($_POST["adress"]) and !empty($_POST["email"])) { $friend->setName($_POST["name"]); $friend->setAdress($_POST["adress"]); $friend->setEmail($_POST["email"]); /** * records can be saved after editing or creating * exit the program after a successful storage * error massage when email address exists because email address is unique */ if ($friend->save()) { header('location:index.php?module=listoffriends'); exit; } else { $var = array('fehler' => "Die Person existiert bereits in der Datenbank"); } } elseif (!empty($_POST["name"]) or !empty($_POST["adress"]) or !empty($_POST["email"])) { $var = array('fehler' => "Es sind nicht alle Datenfelder ausgefüllt"); } $var['friend'] = $friend; return $var; }