/** * delete a team (and all it's ServiceContracts,CommandSets,Commands) * @static * @param int $teamidToDelete * @return bool */ public static function delete($teamidToDelete) { try { $team = TeamCache::getInstance()->getTeam($teamidToDelete); $idlist = array_keys($team->getCommands()); foreach ($idlist as $id) { Command::delete($id); } $idlist = array_keys($team->getCommandSetList()); foreach ($idlist as $id) { CommandSet::delete($id); } $idlist = array_keys($team->getServiceContractList()); foreach ($idlist as $id) { ServiceContract::delete($id); } $query = "DELETE FROM `codev_team_project_table` WHERE team_id = {$teamidToDelete};"; $result = SqlWrapper::getInstance()->sql_query($query); if (!$result) { echo "<span style='color:red'>ERROR: Query FAILED</span>\n"; exit; } $query = "DELETE FROM `codev_team_user_table` WHERE team_id = {$teamidToDelete};"; $result = SqlWrapper::getInstance()->sql_query($query); if (!$result) { echo "<span style='color:red'>ERROR: Query FAILED</span>\n"; exit; } $query = "DELETE FROM `codev_team_table` WHERE id = {$teamidToDelete};"; $result = SqlWrapper::getInstance()->sql_query($query); if (!$result) { echo "<span style='color:red'>ERROR: Query FAILED</span>\n"; exit; } } catch (Exception $e) { return false; } return true; }
protected function display() { if (Tools::isConnectedUser()) { if (0 == $this->teamid || $this->session_user->isTeamCustomer($this->teamid)) { $this->smartyHelper->assign('isEditGranted', FALSE); } else { // only managers can edit the SC $isManager = $this->session_user->isTeamManager($this->teamid); if (!$isManager) { return; } $this->smartyHelper->assign('isEditGranted', true); // use the commandsetid set in the form, if not defined (first page call) use session commandsetid $commandsetid = 0; if (isset($_POST['commandsetid'])) { $commandsetid = $_POST['commandsetid']; $_SESSION['commandsetid'] = $commandsetid; } else { if (isset($_GET['commandsetid'])) { $commandsetid = $_GET['commandsetid']; $_SESSION['commandsetid'] = $commandsetid; } else { if (isset($_SESSION['commandsetid'])) { $commandsetid = $_SESSION['commandsetid']; } } } $action = filter_input(INPUT_POST, 'action'); if (0 == $commandsetid) { // -------- CREATE CMDSET ------- if ("createCmdset" == $action) { if (self::$logger->isDebugEnabled()) { self::$logger->debug("create new CommandSet for team {$this->teamid}<br>"); } $cmdsetName = Tools::escape_string($_POST['commandsetName']); try { $commandsetid = CommandSet::create($cmdsetName, $this->teamid); $cmdset = CommandSetCache::getInstance()->getCommandSet($commandsetid); } catch (Exception $e) { // Smartify echo "Can't create the CommandSet because the CommandSet name is already used"; } } // Display Empty Command Form // Note: this will be overridden by the 'update' section if the 'createCommandset' action has been called. $this->smartyHelper->assign('cmdsetInfoFormBtText', T_('Create')); $this->smartyHelper->assign('cmdsetInfoFormAction', 'createCmdset'); } if (0 != $commandsetid) { // -------- UPDATE CMDSET ------- $cmdset = CommandSetCache::getInstance()->getCommandSet($commandsetid); // ------ Actions if ("addCommand" == $action) { # TODO $cmdid = SmartyTools::checkNumericValue($_POST['cmdid']); if (0 == $cmdid) { #$_SESSION['cmdid'] = 0; header('Location:command_edit.php?cmdid=0'); } else { $cmdset->addCommand($cmdid, Command::type_general); } } else { if ("removeCmd" == $action) { $cmdid = SmartyTools::checkNumericValue($_POST['cmdid']); $cmdset->removeCommand($cmdid); } else { if ("updateCmdsetInfo" == $action) { $this->updateCommandSetInfo($cmdset); header('Location:commandset_info.php'); } else { if ("deleteCommandSet" == $action) { if (self::$logger->isDebugEnabled()) { self::$logger->debug("delete CommandSet {$commandsetid} (" . $cmdset->getName() . ")"); } CommandSet::delete($commandsetid); unset($_SESSION['commandsetid']); header('Location:commandset_info.php'); } } } } // Display CommandSet $this->smartyHelper->assign('commandsetid', $commandsetid); $this->smartyHelper->assign('cmdsetInfoFormBtText', T_('Save')); $this->smartyHelper->assign('cmdsetInfoFormAction', 'updateCmdsetInfo'); $this->smartyHelper->assign('isAddCmdForm', true); $cmdCandidates = $this->getCmdSetCandidates($cmdset, $this->session_user); $this->smartyHelper->assign('cmdCandidates', $cmdCandidates); $this->smartyHelper->assign('isAddCmdSetForm', true); // set CommandSets I belong to $this->smartyHelper->assign('parentContracts', CommandSetTools::getParentContracts($cmdset)); $isManager = $this->session_user->isTeamManager($cmdset->getTeamid()); CommandSetTools::displayCommandSet($this->smartyHelper, $cmdset, $isManager); } // you can create OR move SC only to managed teams $mTeamList = $this->session_user->getManagedTeamList(); $this->smartyHelper->assign('grantedTeams', SmartyTools::getSmartyArray($mTeamList, $this->teamid)); } } }