function execute($param, $post) { if (count($param) > 0 && $param[0] == "act") { $obj = json_decode($post["json"]); $group = GetSingleByCondition(DRINKERCYCLE_TABLE, array("Name" => $obj->Name)); if ($group instanceof DrinkerCycle) { if ($obj->Action == "exists") { $groupRela = GetSingleByCondition(DRINKERCYCLESDRINKERSRELATION_TABLE, array("DrinkerCycleId" => $group->Id)); return ReturnBoolean($groupRela != null); } else { if ($obj->Action == "add") { $drinker = GetSingleByCondition(DRINKER_TABLE, array("Guid" => $obj->Guid)); if ($drinker instanceof Drinker) { $presGroupRelation = GetSingleByCondition(DRINKERCYCLESDRINKERSRELATION_TABLE, array("DrinkerCycleId" => $group->Id, "DrinkerId" => $drinker->Id)); if ($presGroupRelation == null) { $groupRela = GetSingleByCondition(DRINKERCYCLESDRINKERSRELATION_TABLE, array("DrinkerCycleId" => $group->Id)); $newRela = new DrinkerCyclesDrinkersRelation(); $newRela->DrinkerId = $drinker->Id; $newRela->DrinkerCycleId = $group->Id; $newRela->IsAuthenticated = $groupRela == null; return ReturnBoolean(Insert(DRINKERCYCLESDRINKERSRELATION_TABLE, $newRela)); } return ReturnBoolean(true); } else { return ReturnNotFound($obj->Guid, "Drinker"); } } else { if ($obj->Action == "remove") { $drinker = GetSingleByCondition(DRINKER_TABLE, array("Guid" => $obj->Guid)); if ($drinker instanceof Drinker) { $groupRela = GetSingleByCondition(DRINKERCYCLESDRINKERSRELATION_TABLE, array("DrinkerCycleId" => $group->Id, "DrinkerId" => $drinker->Id)); if ($groupRela instanceof DrinkerCyclesDrinkersRelation) { return ReturnBoolean(DeleteById(DRINKERCYCLESDRINKERSRELATION_TABLE, $groupRela->Id)); } else { return RelationNotFound($group->Id, $drinker->Id, DRINKERCYCLESDRINKERSRELATION_TABLE); } } else { return ReturnNotFound($obj->Guid, DRINKER_TABLE); } } else { if ($obj->Action == "authenticate" || $obj->Action == "deauthenticate") { $newVal = true; if ($obj->Action == "deauthenticate") { $newVal = false; } $drinker = GetSingleByCondition(DRINKER_TABLE, array("Guid" => $obj->Guid)); if ($drinker instanceof Drinker) { $groupRela = GetSingleByCondition(DRINKERCYCLESDRINKERSRELATION_TABLE, array("DrinkerCycleId" => $group->Id, "DrinkerId" => $drinker->Id)); if ($groupRela instanceof DrinkerCyclesDrinkersRelation) { //can change others status if ($groupRela->IsAuthenticated) { $otherDrinker = GetSingleByCondition(DRINKER_TABLE, array("Guid" => $obj->AuthGuid)); if ($otherDrinker instanceof Drinker) { $otherGroupRela = GetSingleByCondition(DRINKERCYCLESDRINKERSRELATION_TABLE, array("DrinkerCycleId" => $group->Id, "DrinkerId" => $otherDrinker->Id)); if ($otherGroupRela instanceof DrinkerCyclesDrinkersRelation) { $otherGroupRela->IsAuthenticated = $newVal; return ReturnBoolean(Update(DRINKERCYCLESDRINKERSRELATION_TABLE, $otherGroupRela)); } else { return RelationNotFound($group->Id, $otherDrinker->Id, DRINKERCYCLESDRINKERSRELATION_TABLE); } } else { return ReturnNotFound($obj->AuthGuid, "Drinker"); } } else { //not authenticated return ReturnBoolean(false); } } else { return RelationNotFound($group->Id, $drinker->Id, DRINKERCYCLESDRINKERSRELATION_TABLE); } } else { return ReturnNotFound($obj->Guid, "Drinker"); } } else { if ($obj->Action == "removeforeign") { $drinker = GetSingleByCondition(DRINKER_TABLE, array("Guid" => $obj->Guid)); if ($drinker instanceof Drinker) { $groupRela = GetSingleByCondition(DRINKERCYCLESDRINKERSRELATION_TABLE, array("DrinkerCycleId" => $group->Id, "DrinkerId" => $drinker->Id)); if ($groupRela instanceof DrinkerCyclesDrinkersRelation) { //can change others status if ($groupRela->IsAuthenticated) { $otherDrinker = GetSingleByCondition(DRINKER_TABLE, array("Guid" => $obj->AuthGuid)); if ($otherDrinker instanceof Drinker) { $otherGroupRela = GetSingleByCondition(DRINKERCYCLESDRINKERSRELATION_TABLE, array("DrinkerCycleId" => $group->Id, "DrinkerId" => $otherDrinker->Id)); if ($otherGroupRela instanceof DrinkerCyclesDrinkersRelation) { return ReturnBoolean(Delete(DRINKERCYCLESDRINKERSRELATION_TABLE, $otherGroupRela)); } else { return RelationNotFound($group->Id, $otherDrinker->Id, DRINKERCYCLESDRINKERSRELATION_TABLE); } } else { return ReturnNotFound($obj->AuthGuid, "Drinker"); } } else { //not authenticated return ReturnBoolean(false); } } else { return RelationNotFound($group->Id, $drinker->Id, DRINKERCYCLESDRINKERSRELATION_TABLE); } } else { return ReturnNotFound($obj->Guid, "Drinker"); } } else { return ReturnError(LINK_INVALID); } } } } } } if ($obj->Action == "exists") { return ReturnBoolean(false); } else { if ($obj->Action == "add") { $newGroup = new DrinkerCycle(); $newGroup->Name = $obj->Name; $newGroup->Guid = GenerateGuid(); if (Insert(DRINKERCYCLE_TABLE, $newGroup)) { return $this->execute($param, $post); } else { return ReturnCrudError($newGroup, "add"); } } else { return ReturnNotFound($obj->Guid, DRINKERCYCLE_TABLE); } } } else { if (ValidateGuid($param[0])) { //construct model puh $drinker = GetByGuid("Drinker", $param[0]); if ($drinker != null && $drinker instanceof Drinker) { $relations = GetAllByCondition(DRINKERCYCLESDRINKERSRELATION_TABLE, array("DrinkerId" => $drinker->Id)); $cyclesEnt = array(); $cycles = array(); $authCycles = array(); foreach ($relations as $relation) { if ($relation instanceof DrinkerCyclesDrinkersRelation) { $cycle = GetById(DRINKERCYCLE_TABLE, $relation->DrinkerCycleId); if ($cycle instanceof DrinkerCycle) { if ($relation->IsAuthenticated) { $cycl = new DrinkerCycleEntity($cycle); $cycl->IsAuthenticated = true; $authCycles[] = $cycle; $cyclesEnt[] = $cycl; } else { $cycles[] = $cycle; $cycl = new DrinkerCycleEntity($cycle); $cycl->IsAuthenticated = false; $cyclesEnt[] = $cycl; } } } } $drinkers = array(); foreach ($authCycles as $cycle) { $userRelations = GetAllByCondition(DRINKERCYCLESDRINKERSRELATION_TABLE, array("DrinkerCycleId" => $cycle->Id)); foreach ($userRelations as $userRelation) { if ($userRelation instanceof DrinkerCyclesDrinkersRelation) { //exclude self if ($drinker->Id != $userRelation->DrinkerId) { if (!isset($drinkers[$userRelation->DrinkerId])) { $user = GetById(DRINKER_TABLE, $userRelation->DrinkerId); if ($user instanceof Drinker) { $drinkers[$userRelation->DrinkerId] = new DrinkerEntity($user); } } if ($drinkers[$userRelation->DrinkerId] instanceof DrinkerEntity) { if ($userRelation->IsAuthenticated) { $drinkers[$userRelation->DrinkerId]->AuthDrinkerCycles[] = $cycle->Guid; } else { $drinkers[$userRelation->DrinkerId]->NonAuthDrinkerCycles[] = $cycle->Guid; } } } } } } $coll = new DrinkerCycleResponse(); $coll->DrinkerCycles = $cyclesEnt; foreach ($drinkers as $drinker) { $coll->Drinkers[] = $drinker; } return json_encode($coll); } else { return ReturnNotFound($param[0], "Drinker"); } } else { return ReturnError(LINK_INVALID); } } }
/** * Methode zum Anzeigen des Contents. * * @return String Content der Applikation. */ public function Display() { $view = $this->NotFound(); if (count($this->params) == 0 || $this->params[0] == "") { $view = new GenericView("settings"); if (isset($this->request["changepass"])) { if ($this->request["Password1"] == $this->request["Password2"]) { if (CheckPassword($this->request["Password1"])) { $params = array(); $params["Id"] = GetActiveUser()->Id; $params["PasswordHash"] = $this->request["Password1"]; if (AddOrUpdate("admins", $params)) { DoLog("Das Passwort wurde erfolgreich geändert", LOG_LEVEL_INFO); } else { DoLog("Das Passwort konnte nicht geändert werden", LOG_LEVEL_SYSTEM_ERROR); } } else { //log was done by CheckAdminPass } } else { DoLog("Die beiden Passwörter stimmen nicht überein", LOG_LEVEL_USER_ERROR); } if ($this->request["no-replace"] == true) { exit; } } $view->assign('admins', GetAllOrderedBy("admins", "Id")); } else { if ($this->params[0] == "Admin") { $view = new GenericCrudView($this->params[1], array("add" => "edit"), "settings", "Admin"); if ($this->params[1] == "add") { if (isset($this->request["add"]) && $this->request["add"] == "true") { unset($this->request["add"]); $res = AddAdmin($this->request); if ($res) { $obj = GetById("admins", $res); if ($obj !== false) { DoLog("Admin wurde hinzugefügt, E-Mail wurde versendet.", LOG_LEVEL_INFO); } else { DoLog("Admin wurde hinzugefügt, E-Mail wurde versendet.", LOG_LEVEL_SYSTEM_ERROR); } } } $view->assign("obj", null); } else { if ($this->params[1] == "edit") { if (isset($this->request["edit"]) && $this->request["edit"] == "true") { unset($this->request["edit"]); $this->request["Id"] = $this->params[2]; $res = Update("admins", $this->request); if ($res) { DoLog("Admin wurde bearbeitet", LOG_LEVEL_INFO); } else { $view = new MessageView("Admin konnte nicht bearbeitet werden.", LOG_LEVEL_SYSTEM_ERROR); } } $obj = GetById("admins", $this->params[2]); if ($obj !== false) { $view->assign("obj", $obj); } else { $view = new MessageView("Admin wurde nicht gefunden.", LOG_LEVEL_SYSTEM_ERROR); } } else { if ($this->params[1] == "delete" && isset($this->params[2]) && is_numeric($this->params[2])) { if (isset($this->request["delete"]) && $this->request["delete"] == "true") { $res = DeleteById("admins", $this->params[2]); if ($res) { $view = new MessageView("Admin wurde gelöscht", LOG_LEVEL_INFO); } else { $view = new MessageView("Admin konnte nicht gelöscht werden.", LOG_LEVEL_SYSTEM_ERROR); } } else { $obj = GetById("admins", $this->params[2]); if ($obj !== false) { $view->assign("obj", $obj); } else { $view = new MessageView("Admin wurde nicht gefunden.", LOG_LEVEL_SYSTEM_ERROR); } } } else { $view = $this->NotFound(); } } } } else { if ($this->params[0] == "download") { if ($this->params[1] == "database") { DownloadDatabaseAndExit(); } } } } return $view->loadTemplate(); }