Exemple #1
0
 /**
  * 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;
 }
Exemple #2
0
 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 servicecontractid set in the form, if not defined (first page call) use session servicecontractid
             $servicecontractid = 0;
             if (isset($_POST['servicecontractid'])) {
                 $servicecontractid = Tools::getSecurePOSTIntValue('servicecontractid');
                 $_SESSION['servicecontractid'] = $servicecontractid;
             } else {
                 if (isset($_GET['servicecontractid'])) {
                     $servicecontractid = Tools::getSecureGETIntValue('servicecontractid');
                     $_SESSION['servicecontractid'] = $servicecontractid;
                 } else {
                     if (isset($_SESSION['servicecontractid'])) {
                         $servicecontractid = $_SESSION['servicecontractid'];
                     }
                 }
             }
             $action = filter_input(INPUT_POST, 'action');
             if (0 == $servicecontractid) {
                 //  CREATE service contract
                 if ("createContract" == $action) {
                     if (self::$logger->isDebugEnabled()) {
                         self::$logger->debug("create new ServiceContract for team {$this->teamid}<br>");
                     }
                     $contractName = Tools::getSecurePOSTStringValue('servicecontractName');
                     try {
                         $servicecontractid = ServiceContract::create($contractName, $this->teamid);
                         $contract = ServiceContractCache::getInstance()->getServiceContract($servicecontractid);
                     } catch (Exception $e) {
                         // Smartify
                         echo "Can't create the ServiceContract because the ServiceContract 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('contractInfoFormBtText', T_('Create'));
                 $this->smartyHelper->assign('contractInfoFormAction', 'createContract');
                 // Note: StateList is empty, uncomment following lines if ServiceContract::$stateNames is used
                 //$this->smartyHelper->assign('servicecontractStateList', ServiceContractTools::getServiceContractStateList($contract));
             }
             // Edited or created just before
             if (0 != $servicecontractid) {
                 // UPDATE CMDSET
                 $contract = ServiceContractCache::getInstance()->getServiceContract($servicecontractid);
                 // Actions
                 if ("addCommandSet" == $action) {
                     # TODO
                     $commandsetid = Tools::getSecurePOSTIntValue('commandsetid');
                     if (0 == $commandsetid) {
                         #$_SESSION['commandsetid'] = 0;
                         header('Location:command_edit.php?commandsetid=0');
                     } else {
                         $contract->addCommandSet($commandsetid, CommandSet::type_general);
                     }
                 } else {
                     if ("removeCmdSet" == $action) {
                         $commandsetid = Tools::getSecurePOSTIntValue('commandsetid');
                         $contract->removeCommandSet($commandsetid);
                     } else {
                         if ("updateContractInfo" == $action) {
                             $this->updateServiceContractInfo($contract);
                             header('Location:servicecontract_info.php');
                         } else {
                             if ("addProject" == $action) {
                                 # TODO
                                 $projectid = Tools::getSecurePOSTIntValue('projectid');
                                 if (0 != $projectid) {
                                     $contract->addSidetaskProject($projectid, Project::type_sideTaskProject);
                                 }
                             } else {
                                 if ("removeProject" == $action) {
                                     $projectid = Tools::getSecurePOSTIntValue('projectid');
                                     $contract->removeSidetaskProject($projectid);
                                 } else {
                                     if ("deleteContract" == $action) {
                                         if (self::$logger->isDebugEnabled()) {
                                             self::$logger->debug("delete ServiceContract servicecontractid (" . $contract->getName() . ")");
                                         }
                                         ServiceContract::delete($servicecontractid);
                                         unset($_SESSION['servicecontractid']);
                                         header('Location:servicecontract_info.php');
                                     }
                                 }
                             }
                         }
                     }
                 }
                 // Display ServiceContract
                 $this->smartyHelper->assign('servicecontractid', $servicecontractid);
                 $this->smartyHelper->assign('contractInfoFormBtText', T_('Save'));
                 $this->smartyHelper->assign('contractInfoFormAction', 'updateContractInfo');
                 $commandsetCandidates = $this->getCmdSetCandidates($contract, $this->session_user);
                 $this->smartyHelper->assign('commandsetCandidates', $commandsetCandidates);
                 $projectCandidates = $this->getProjectCandidates($contract);
                 $this->smartyHelper->assign('projectCandidates', $projectCandidates);
                 $projects = $this->getProjects($contract);
                 $this->smartyHelper->assign('projectList', $projects);
                 $isManager = $this->session_user->isTeamManager($contract->getTeamid());
                 ServiceContractTools::displayServiceContract($this->smartyHelper, $contract, $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));
         }
     }
 }