public function do_execute()
 {
     /* Prepare variables */
     try {
         $project_id = $this->getProvidedArgument('projectid');
         $project_row = TBGProjectsTable::getTable()->getById($project_id, false);
         TBGContext::setScope(new TBGScope($project_row[TBGProjectsTable::SCOPE]));
         $project = new TBGProject($project_id, $project_row);
     } catch (Exception $e) {
         throw $e;
         $this->cliEcho("The project with the ID " . $this->getProvidedArgument('projectid') . " does not exist\n", 'red', 'bold');
         exit;
     }
     $author = $this->getProvidedArgument('author');
     $new_rev = $this->getProvidedArgument('revno');
     $commit_msg = $this->getProvidedArgument('log');
     $changed = $this->getProvidedArgument('changed');
     $old_rev = $this->getProvidedArgument('oldrev', null);
     $date = $this->getProvidedArgument('date', null);
     $branch = $this->getProvidedArgument('branch', null);
     if (TBGSettings::get('access_method_' . $project->getKey()) == TBGVCSIntegration::ACCESS_HTTP) {
         $this->cliEcho("This project uses the HTTP access method, and so access via the CLI has been disabled\n", 'red', 'bold');
         exit;
     }
     if ($old_rev === null && !is_integer($new_rev)) {
         $this->cliEcho("Error: if only the new revision is specified, it must be a number so that old revision can be calculated from it (by substracting 1 from new revision number).");
     } else {
         if ($old_rev === null) {
             $old_rev = $new_rev - 1;
         }
     }
     $output = TBGVCSIntegration::processCommit($project, $commit_msg, $old_rev, $new_rev, $date, $changed, $author, $branch);
     $this->cliEcho($output);
 }
 public function postConfigSettings(TBGRequest $request)
 {
     $settings = array('use_web_interface', 'vcs_passkey');
     foreach ($settings as $setting) {
         if ($request->hasParameter($setting)) {
             $this->saveSetting($setting, $request->getParameter($setting));
         }
     }
     foreach (TBGProject::getAll() as $aProduct) {
         if ($request->hasParameter('web_path_' . $aProduct->getID())) {
             // github is always at github.com
             if ($request->hasParameter('web_type_' . $aProduct->getID()) && $request->getParameter('web_type_' . $aProduct->getID()) == 'github') {
                 $this->saveSetting('web_path_' . $aProduct->getID(), 'http://github.com');
             } else {
                 $this->saveSetting('web_path_' . $aProduct->getID(), $request->getParameter('web_path_' . $aProduct->getID()));
             }
         }
         if ($request->hasParameter('web_type_' . $aProduct->getID())) {
             $this->saveSetting('web_type_' . $aProduct->getID(), $request->getParameter('web_type_' . $aProduct->getID()));
         }
         if ($request->hasParameter('web_repo_' . $aProduct->getID())) {
             $this->saveSetting('web_repo_' . $aProduct->getID(), $request->getParameter('web_repo_' . $aProduct->getID()));
         }
     }
 }
Example #3
0
 public function runListProjects(TBGRequest $request)
 {
     $projects = TBGProject::getAll();
     $return_array = array();
     foreach ($projects as $project) {
         $return_array[$project->getKey()] = $project->getName();
     }
     $this->projects = $return_array;
 }
Example #4
0
 public function runProjectCommits(TBGRequest $request)
 {
     $this->selected_project = TBGProject::getByKey($request['project_key']);
     TBGContext::setCurrentProject($this->selected_project);
     if (TBGContext::getModule('vcs_integration')->getSetting('vcs_mode_' . TBGContext::getCurrentProject()->getID()) == TBGVCSIntegration::MODE_DISABLED) {
         return $this->return404(TBGContext::getI18n()->__('VCS Integration has been disabled for this project'));
     }
     $offset = $request->getParameter('offset', 0);
     $this->commits = TBGVCSIntegrationCommit::getByProject($this->selected_project->getID(), 40, $offset);
     if ($offset) {
         return $this->renderJSON(array('content' => $this->getTemplateHTML('vcs_integration/projectcommits', array('commits' => $this->commits, 'selected_project' => $this->selected_project)), 'offset' => $offset + 40));
     }
 }
Example #5
0
 /**
  * Pre-execute function
  *
  * @param TBGRequest $request
  */
 public function preExecute(TBGRequest $request, $action)
 {
     $this->article = null;
     $this->article_name = $request['article_name'];
     $this->article_id = (int) $request['article_id'];
     $this->special = false;
     if ($request->hasParameter('article_name') && mb_strpos($request['article_name'], ':') !== false) {
         $this->article_name = $this->_getArticleNameDetails($request['article_name']);
     } else {
         try {
             if ($project_key = $request['project_key']) {
                 $this->selected_project = TBGProject::getByKey($project_key);
             } elseif ($project_id = (int) $request['project_id']) {
                 $this->selected_project = TBGProjectsTable::getTable()->selectById($project_id);
             }
         } catch (Exception $e) {
         }
     }
     if (!$this->special) {
         if ($this->article_id) {
             $this->article = TBGArticlesTable::getTable()->selectById($this->article_id);
         } elseif ($this->article_name) {
             $this->article = TBGArticlesTable::getTable()->getArticleByName($this->article_name);
         }
         if (!$this->article instanceof TBGWikiArticle) {
             $this->article = new TBGWikiArticle();
             if ($this->article_name) {
                 $this->article->setName($this->article_name);
             } elseif ($request->hasParameter('parent_article_name')) {
                 $this->article->setParentArticle(TBGArticlesTable::getTable()->getArticleByName($request['parent_article_name']));
                 $this->_getArticleNameDetails($request['parent_article_name']);
                 if ($this->article->getParentArticle() instanceof TBGWikiArticle) {
                     if ($this->article->getParentArticle()->getArticleType() == TBGWikiArticle::TYPE_WIKI) {
                         $this->article->setName($this->article->getParentArticle()->getName() . ':');
                     }
                     $this->article->setArticleType($this->article->getParentArticle()->getArticleType());
                 }
             }
             $this->article->setContentSyntax($this->getUser()->getPreferredWikiSyntax(true));
         }
     }
     if ($this->selected_project instanceof TBGProject) {
         if (!$this->selected_project->hasAccess()) {
             $this->forward403();
         } else {
             TBGContext::setCurrentProject($this->selected_project);
         }
     }
 }
 public function componentArchivedProjects()
 {
     if (!isset($this->target)) {
         $this->projects = TBGProject::getAllRootProjects(true);
         $this->project_count = count($this->projects);
     } elseif ($this->target == 'team') {
         $this->team = TBGContext::factory()->TBGTeam($this->id);
         $projects = array();
         foreach (TBGProject::getAllByOwner($this->team) as $project) {
             $projects[$project->getID()] = $project;
         }
         foreach (TBGProject::getAllByLeader($this->team) as $project) {
             $projects[$project->getID()] = $project;
         }
         foreach (TBGProject::getAllByQaResponsible($this->team) as $project) {
             $projects[$project->getID()] = $project;
         }
         foreach ($this->team->getAssociatedProjects() as $project_id => $project) {
             $projects[$project_id] = $project;
         }
         $final_projects = array();
         foreach ($projects as $project) {
             if ($project->isArchived()) {
                 $final_projects[] = $project;
             }
         }
         $this->projects = $final_projects;
     } elseif ($this->target == 'client') {
         $this->client = TBGContext::factory()->TBGClient($this->id);
         $projects = TBGProject::getAllByClientID($this->client->getID());
         $final_projects = array();
         foreach ($projects as $project) {
             if (!$project->isArchived()) {
                 $final_projects[] = $project;
             }
         }
         $this->projects = $final_projects;
     } elseif ($this->target == 'project') {
         $this->parent = TBGContext::factory()->TBGProject($this->id);
         $this->projects = $this->parent->getChildren(true);
     }
     $this->project_count = count($this->projects);
 }
 /**
  * Pre-execute function
  *
  * @param TBGRequest 	$request
  * @param string		$action
  */
 public function preExecute(TBGRequest $request, $action)
 {
     if ($project_key = $request->getParameter('project_key')) {
         try {
             $this->selected_project = TBGProject::getByKey($project_key);
         } catch (Exception $e) {
         }
     } elseif ($project_id = $request->getParameter('project_id')) {
         try {
             $this->selected_project = TBGContext::factory()->TBGProject($project_id);
         } catch (Exception $e) {
         }
     }
     if ($this->selected_project instanceof TBGProject) {
         TBGContext::setCurrentProject($this->selected_project);
         $this->project_key = $this->selected_project->getKey();
     } else {
         $this->return404(TBGContext::getI18n()->__('This project does not exist'));
     }
 }
Example #8
0
 public function runSaveIncomingAccount(TBGRequest $request)
 {
     $project = null;
     if ($project_key = $request['project_key']) {
         try {
             $project = TBGProject::getByKey($project_key);
         } catch (Exception $e) {
         }
     }
     if ($project instanceof TBGProject) {
         try {
             $account_id = $request['account_id'];
             $account = $account_id ? new TBGIncomingEmailAccount($account_id) : new TBGIncomingEmailAccount();
             $account->setIssuetype((int) $request['issuetype']);
             $account->setProject($project);
             $account->setPort((int) $request['port']);
             $account->setName($request['name']);
             $account->setFoldername($request['folder']);
             $account->setKeepEmails($request['keepemail']);
             $account->setServer($request['servername']);
             $account->setUsername($request['username']);
             $account->setPassword($request['password']);
             $account->setSSL((bool) $request['ssl']);
             $account->setIgnoreCertificateValidation((bool) $request['ignore_certificate_validation']);
             $account->setUsePlaintextAuthentication((bool) $request['plaintext_authentication']);
             $account->setServerType((int) $request['account_type']);
             $account->save();
             if (!$account_id) {
                 return $this->renderTemplate('mailing/incomingemailaccount', array('project' => $project, 'account' => $account));
             } else {
                 return $this->renderJSON(array('name' => $account->getName()));
             }
         } catch (Exception $e) {
             $this->getResponse()->setHttpStatus(400);
             return $this->renderJSON(array('error' => $this->getI18n()->__('This is not a valid mailing account')));
         }
     } else {
         $this->getResponse()->setHttpStatus(400);
         return $this->renderJSON(array('error' => $this->getI18n()->__('This is not a valid project')));
     }
 }
 public function runAddFilter(TBGRequest $request)
 {
     if ($request->getParameter('filter_name') == 'project_id' && count(TBGProject::getAll()) == 0) {
         return $this->renderJSON(array('failed' => true, 'error' => TBGContext::getI18n()->__('No projects exist so this filter can not be added')));
     } elseif (in_array($request->getParameter('filter_name'), TBGIssuesTable::getValidSearchFilters()) || TBGCustomDatatype::doesKeyExist($request->getParameter('filter_name'))) {
         return $this->renderJSON(array('failed' => false, 'content' => $this->getComponentHTML('search/filter', array('filter' => $request->getParameter('filter_name'), 'key' => $request->getParameter('key', 0)))));
     } else {
         return $this->renderJSON(array('failed' => true, 'error' => TBGContext::getI18n()->__('This is not a valid search field')));
     }
 }
 public function hasProjectsAvailable()
 {
     return $this->getMaxProjects() ? TBGProject::getProjectsCount() < $this->getMaxProjects() : true;
 }
 protected function _upgrade()
 {
     switch ($this->_version) {
         case "1.0":
             // Upgrade tables
             \b2db\Core::getTable('TBGVCSIntegrationCommitsTable')->create();
             \b2db\Core::getTable('TBGVCSIntegrationFilesTable')->create();
             \b2db\Core::getTable('TBGVCSIntegrationIssueLinksTable')->create();
             TBGVCSIntegrationCommitsTable::getTable()->createIndexes();
             TBGVCSIntegrationFilesTable::getTable()->createIndexes();
             TBGVCSIntegrationIssueLinksTable::getTable()->createIndexes();
             // Migrate data from old table to new tables
             $crit = new \b2db\Criteria();
             $crit->addOrderBy(TBGVCSIntegrationTable::DATE, \b2db\Criteria::SORT_DESC);
             $results = TBGVCSIntegrationTable::getTable()->doSelect($crit);
             if ($results instanceof \b2db\Resultset && $results->count() > 0) {
                 $commits = array();
                 while ($row = $results->getNextRow()) {
                     $rev = $row->get(TBGVCSIntegrationTable::NEW_REV);
                     if (array_key_exists($rev, $commits)) {
                         // Add a new file or issue to the commit data
                         $commits[$rev]['files'][$row->get(TBGVCSIntegrationTable::FILE_NAME)] = array('file_name' => $row->get(TBGVCSIntegrationTable::FILE_NAME), 'action' => $row->get(TBGVCSIntegrationTable::ACTION));
                         $commits[$rev]['issues'][$row->get(TBGVCSIntegrationTable::ISSUE_NO)] = $row->get(TBGVCSIntegrationTable::ISSUE_NO);
                     } else {
                         // All issues will be of the same project, so use one issue
                         $issue = TBGContext::factory()->TBGIssue($results->get(TBGVCSIntegrationTable::ISSUE_NO));
                         // Add details of a new commit
                         $commits[$rev] = array('commit' => array(), 'files' => array(), 'issues' => array());
                         $commits[$rev]['commit'] = array('new_rev' => $rev, 'old_rev' => $row->get(TBGVCSIntegrationTable::OLD_REV), 'author' => $row->get(TBGVCSIntegrationTable::AUTHOR), 'date' => $row->get(TBGVCSIntegrationTable::DATE), 'log' => $row->get(TBGVCSIntegrationTable::LOG), 'scope' => $row->get(TBGVCSIntegrationTable::SCOPE), 'project' => $issue->getProject());
                         $commits[$rev]['files'][$row->get(TBGVCSIntegrationTable::FILE_NAME)] = array('file_name' => $row->get(TBGVCSIntegrationTable::FILE_NAME), 'action' => $row->get(TBGVCSIntegrationTable::ACTION));
                         $commits[$rev]['issues'][$row->get(TBGVCSIntegrationTable::ISSUE_NO)] = $row->get(TBGVCSIntegrationTable::ISSUE_NO);
                     }
                 }
                 foreach ($commits as $commit) {
                     $files = array();
                     $issues = array();
                     $scope = TBGContext::factory()->TBGScope($commit['commit']['scope']);
                     try {
                         $author = TBGContext::factory()->TBGUser($commit['commit']['author']);
                     } catch (Exception $e) {
                         $author = TBGContext::factory()->TBGUser(TBGSettings::getDefaultUserID());
                     }
                     if (!$author instanceof TBGUser) {
                         $author = TBGContext::factory()->TBGUser(TBGSettings::getDefaultUserID());
                     }
                     // Add the commit
                     $inst = new TBGVCSIntegrationCommit();
                     $inst->setAuthor($author);
                     $inst->setDate($commit['commit']['date']);
                     $inst->setLog($commit['commit']['log']);
                     $inst->setPreviousRevision($commit['commit']['old_rev']);
                     $inst->setRevision($commit['commit']['new_rev']);
                     $inst->setProject($commit['commit']['project']);
                     $inst->setScope($scope);
                     $inst->save();
                     // Process issue list, remove duplicates
                     $issues = $commit['issues'];
                     $files = $commit['files'];
                     $commit = $inst;
                     foreach ($files as $file) {
                         // Add affected files
                         $inst = new TBGVCSIntegrationFile();
                         $inst->setCommit($commit);
                         $inst->setFile($file['file_name']);
                         $inst->setAction($file['action']);
                         $inst->setScope($scope);
                         $inst->save();
                     }
                     foreach ($issues as $issue) {
                         // Add affected issues
                         $issue = TBGContext::factory()->TBGIssue($issue);
                         $inst = new TBGVCSIntegrationIssueLink();
                         $inst->setIssue($issue);
                         $inst->setCommit($commit);
                         $inst->setScope($scope);
                         $inst->save();
                     }
                 }
             }
             // Migrate settings to new format
             $access_method = $this->getSetting('use_web_interface');
             $passkey = $this->getSetting('vcs_passkey');
             foreach (TBGProject::getAll() as $project) {
                 $projectId = $project->getID();
                 $web_path = $this->getSetting('web_path_' . $projectId);
                 $web_repo = $this->getSetting('web_repo_' . $projectId);
                 // Check if enabled
                 if ($web_path == '') {
                     continue;
                 }
                 switch ($this->getSetting('web_type_' . $projectId)) {
                     case 'viewvc':
                         $base_url = $web_path . '/' . '?root=' . $web_repo;
                         $link_rev = '&amp;view=rev&amp;revision=%revno';
                         $link_file = '&amp;view=log';
                         $link_diff = '&amp;r1=%revno&amp;r2=%oldrev';
                         $link_view = '&amp;revision=%revno&amp;view=markup';
                         break;
                     case 'viewvc_repo':
                         $base_url = $web_path;
                         $link_rev = '/?view=rev&amp;revision=%revno';
                         $link_file = '/%file?view=log';
                         $link_diff = '/%file?r1=%revno&amp;r2=%oldrev';
                         $link_view = '/%file?revision=%revno&amp;view=markup';
                         break;
                     case 'websvn':
                         $base_url = $web_path;
                         $link_rev = '/revision.php?repname=' . $web_repo . '&amp;isdir=1&amp;rev=%revno';
                         $link_file = '/log.php?repname=' . $web_repo . '&amp;path=/$%file';
                         $link_diff = '/comp.php?repname=' . $web_repo . '&amp;compare[]=/%file@%revno&amp;compare[]=/%file@%oldrev';
                         $link_view = '/filedetails.php?repname=' . $web_repo . '&path=/%file&amp;rev=%revno';
                         break;
                     case 'websvn_mv':
                         $base_url = $web_path;
                         $link_rev = '/' . '?repname=' . $web_repo . '&amp;op=log&isdir=1&amp;rev=%revno';
                         $link_file = '/%file?repname=' . $web_repo;
                         $link_diff = '/%file?repname=' . $web_repo . '&amp;compare[]=/%file@%revno&amp;compare[]=/%file@%oldrev';
                         $link_view = '/%file?repname=' . $web_repo . '&amp;rev=%revno';
                         break;
                     case 'loggerhead':
                         $base_url = $web_path . '/' . $web_repo;
                         $link_rev = '/revision/%revno';
                         $link_file = '/changes';
                         $link_diff = '/revision/%revno?compare_revid=%oldrev';
                         $link_view = '/annotate/head:/%file';
                         break;
                     case 'gitweb':
                         $base_url = $web_path . '/' . '?p=' . $web_repo;
                         $link_rev = ';a=commitdiff;h=%revno';
                         $link_file = ';a=history;f=%file;hb=HEAD';
                         $link_diff = ';a=blobdiff;f=%file;hb=%revno;hpb=%oldrev';
                         $link_view = ';a=blob;f=%file;hb=%revno';
                         break;
                     case 'cgit':
                         $base_url = $web_path . '/' . $web_repo;
                         $link_rev = '/commit/?id=%revno';
                         $link_file = '/log';
                         $link_diff = '/diff/%file?id=%revno?id2=%oldrev';
                         $link_view = '/tree/%file?id=%revno';
                         break;
                     case 'hgweb':
                         $base_url = $web_path . '/' . $web_repo;
                         $link_rev = '/rev/%revno';
                         $link_file = '/log/tip/%file';
                         $link_diff = '/diff/%revno/%file';
                         $link_view = '/file/%revno/%file';
                         break;
                     case 'github':
                         $base_url = 'http://github.com/' . $web_repo;
                         $link_rev = '/commit/%revno';
                         $link_file = '/commits/master/%file';
                         $link_diff = '/commit/%revno';
                         $link_view = '/blob/%revno/%file';
                         break;
                     case 'gitlab':
                         $base_url = $web_path . '/' . $web_repo;
                         $link_rev = '/commit/%revno';
                         $link_file = '/commits/%branch/%file';
                         $link_diff = '/commit/%revno';
                         $link_view = '/blob/%revno/%file';
                         break;
                     case 'bitbucket':
                         $base_url = 'https://bitbucket.org/' . $web_repo;
                         $link_rev = '/changeset/%revno';
                         $link_file = '/history/%file';
                         $link_diff = '/changeset/%revno#chg-%file';
                         $link_view = '/src/%revno/%file';
                         break;
                     case 'gitorious':
                         $base_url = $web_path . '/' . $web_repo;
                         $link_rev = '/commit/%revno';
                         $link_file = '/blobs/history/master/%file';
                         $link_diff = '/commit/%revno';
                         $link_view = '/blobs/%revno/%file';
                         break;
                     case 'rhodecode':
                         $base_url = $web_path . '/' . $web_repo;
                         $link_rev = '/changeset/%revno';
                         $link_file = '/changelog/%revno/%file';
                         $link_diff = '/diff/%file?diff2=%revno&amp;diff1=%oldrev&amp;fulldiff=1&amp;diff=diff';
                         $link_view = '/files/%revno/%file';
                         break;
                 }
                 $this->saveSetting('browser_url_' . $projectId, $base_url);
                 $this->saveSetting('log_url_' . $projectId, $link_file);
                 $this->saveSetting('blob_url_' . $projectId, $link_diff);
                 $this->saveSetting('diff_url_' . $projectId, $link_view);
                 $this->saveSetting('commit_url_' . $projectId, $link_rev);
                 // Access method
                 $this->saveSetting('access_method_' . $projectId, $access_method);
                 if ($access_method == self::ACCESS_HTTP) {
                     $this->saveSetting('access_passkey_' . $projectId, $passkey);
                 }
                 // Enable VCS Integration
                 $this->saveSetting('vcs_mode_' . $projectId, self::MODE_ISSUECOMMITS);
                 // Remove old settings
                 $this->deleteSetting('web_type_' . $projectId);
                 $this->deleteSetting('web_path_' . $projectId);
                 $this->deleteSetting('web_repo_' . $projectId);
             }
             // Remove old settings
             $this->deleteSetting('use_web_interface');
             $this->deleteSetting('vcs_passkey');
             // Upgrade module version
             $this->_version = $this->_module_version;
             $this->save();
             break;
     }
 }
 public function getReplacedTargetID(TBGProject $project)
 {
     return str_replace('%project_key%', $project->getKey(), $this->_target_id);
 }
Example #13
0
 public function runConfigureProject(TBGRequest $request)
 {
     try {
         // Build list of valid targets for the subproject dropdown
         // The following items are banned from the list: current project, children of the current project
         // Any further tests and things get silly, so we will trap it when building breadcrumbs
         $valid_subproject_targets = TBGProject::getValidSubprojects($this->selected_project);
         $content = $this->getComponentHTML('project/projectconfig', array('valid_subproject_targets' => $valid_subproject_targets, 'project' => $this->selected_project, 'access_level' => $this->access_level, 'section' => 'hierarchy'));
         return $this->renderJSON(array('content' => $content));
     } catch (Exception $e) {
         $this->getResponse()->setHttpStatus(400);
         return $this->renderJSON(array('error' => $e->getMessage()));
     }
 }
Example #14
0
 public function runDoImportCSV(TBGRequest $request)
 {
     try {
         if ($request['csv_data'] == '') {
             throw new Exception($this->getI18n()->__('No data supplied to import'));
         }
         $csv = str_replace("\r\n", "\n", $request['csv_data']);
         $csv = html_entity_decode($csv);
         $headerrow = null;
         $data = array();
         $errors = array();
         // Parse CSV
         $handle = fopen("php://memory", 'r+');
         fputs($handle, $csv);
         rewind($handle);
         $i = 0;
         while (($row = fgetcsv($handle, 1000)) !== false) {
             if (!$headerrow) {
                 $headerrow = $row;
             } else {
                 if (count($headerrow) == count($row)) {
                     $data[] = array_combine($headerrow, $row);
                 } else {
                     $errors[] = $this->getI18n()->__('Row %row does not have the same number of elements as the header row', array('%row' => $i));
                 }
             }
             $i++;
         }
         fclose($handle);
         if (empty($data)) {
             throw new Exception($this->getI18n()->__('Insufficient data to import'));
         }
         // Verify required columns are present based on type
         $requiredcols = array(self::CSV_TYPE_CLIENTS => array(self::CSV_CLIENT_NAME), self::CSV_TYPE_PROJECTS => array(self::CSV_PROJECT_NAME), self::CSV_TYPE_ISSUES => array(self::CSV_ISSUE_TITLE, self::CSV_ISSUE_PROJECT, self::CSV_ISSUE_ISSUE_TYPE));
         if (!isset($requiredcols[$request['type']])) {
             throw new Exception('Sorry, this type is unimplemented');
         }
         foreach ($requiredcols[$request['type']] as $col) {
             if (!in_array($col, $headerrow)) {
                 $errors[] = $this->getI18n()->__('Required column \'%col\' not found in header row', array('%col' => $col));
             }
         }
         // Check if rows are long enough and fields are not empty
         for ($i = 0; $i != count($data); $i++) {
             $activerow = $data[$i];
             // Check if fields are empty
             foreach ($activerow as $col => $val) {
                 if (strlen($val) == 0) {
                     $errors[] = $this->getI18n()->__('Row %row column %col has no value', array('%col' => $col, '%row' => $i + 1));
                 }
             }
         }
         if (count($errors) == 0) {
             // Check if fields are valid
             switch ($request['type']) {
                 case self::CSV_TYPE_PROJECTS:
                     for ($i = 0; $i != count($data); $i++) {
                         $activerow = $data[$i];
                         // Check if project exists
                         $key = str_replace(' ', '', $activerow[self::CSV_PROJECT_NAME]);
                         $key = mb_strtolower($key);
                         $tmp = TBGProject::getByKey($key);
                         if ($tmp !== null) {
                             $errors[] = $this->getI18n()->__('Row %row: A project with this name already exists', array('%row' => $i + 1));
                         }
                         // First off are booleans
                         $boolitems = array(self::CSV_PROJECT_SCRUM, self::CSV_PROJECT_ALLOW_REPORTING, self::CSV_PROJECT_AUTOASSIGN, self::CSV_PROJECT_FREELANCE, self::CSV_PROJECT_EN_BUILDS, self::CSV_PROJECT_EN_COMPS, self::CSV_PROJECT_EN_EDITIONS, self::CSV_PROJECT_SHOW_SUMMARY);
                         foreach ($boolitems as $boolitem) {
                             if (array_key_exists($boolitem, $activerow) && isset($activerow[$boolitem]) && $activerow[$boolitem] != 1 && $activerow[$boolitem] != 0) {
                                 $errors[] = $this->getI18n()->__('Row %row column %col: invalid value (must be 1/0)', array('%col' => $boolitem, '%row' => $i + 1));
                             }
                         }
                         // Now identifiables
                         $identifiableitems = array(array(self::CSV_PROJECT_QA, self::CSV_PROJECT_QA_TYPE), array(self::CSV_PROJECT_LEAD, self::CSV_PROJECT_LEAD_TYPE), array(self::CSV_PROJECT_OWNER, self::CSV_PROJECT_OWNER_TYPE));
                         foreach ($identifiableitems as $identifiableitem) {
                             if (!array_key_exists($identifiableitem[1], $activerow) && array_key_exists($identifiableitem[0], $activerow) || array_key_exists($identifiableitem[1], $activerow) && !array_key_exists($identifiableitem[0], $activerow)) {
                                 $errors[] = $this->getI18n()->__('Row %row: Both the type and item ID must be supplied for owner/lead/qa fields', array('%row' => $i + 1));
                                 continue;
                             }
                             if (array_key_exists($identifiableitem[1], $activerow) && isset($activerow[$identifiableitem[1]]) !== null && $activerow[$identifiableitem[1]] != self::CSV_IDENTIFIER_TYPE_USER && $activerow[$identifiableitem[1]] != self::CSV_IDENTIFIER_TYPE_TEAM) {
                                 $errors[] = $this->getI18n()->__('Row %row column %col: invalid value (must be 1 for a user or 2 for a team)', array('%col' => $identifiableitem[1], '%row' => $i + 1));
                             }
                             if (array_key_exists($identifiableitem[0], $activerow) && isset($activerow[$identifiableitem[0]]) && !is_numeric($activerow[$identifiableitem[0]])) {
                                 $errors[] = $this->getI18n()->__('Row %row column %col: invalid value (must be a number)', array('%col' => $identifiableitem[0], '%row' => $i + 1));
                             } elseif (array_key_exists($identifiableitem[0], $activerow) && isset($activerow[$identifiableitem[0]]) && is_numeric($activerow[$identifiableitem[0]])) {
                                 // check if they exist
                                 switch ($activerow[$identifiableitem[1]]) {
                                     case self::CSV_IDENTIFIER_TYPE_USER:
                                         try {
                                             TBGContext::factory()->TBGUser($activerow[$identifiableitem[0]]);
                                         } catch (Exception $e) {
                                             $errors[] = $this->getI18n()->__('Row %row column %col: user does not exist', array('%col' => $identifiableitem[0], '%row' => $i + 1));
                                         }
                                         break;
                                     case self::CSV_IDENTIFIER_TYPE_TEAM:
                                         try {
                                             TBGContext::factory()->TBGTeam($activerow[$identifiableitem[0]]);
                                         } catch (Exception $e) {
                                             $errors[] = $this->getI18n()->__('Row %row column %col: team does not exist', array('%col' => $identifiableitem[0], '%row' => $i + 1));
                                         }
                                         break;
                                 }
                             }
                         }
                         // Now check client exists
                         if (array_key_exists(self::CSV_PROJECT_CLIENT, $activerow) && isset($activerow[self::CSV_PROJECT_CLIENT])) {
                             if (!is_numeric($activerow[self::CSV_PROJECT_CLIENT])) {
                                 $errors[] = $this->getI18n()->__('Row %row column %col: invalid value (must be a number)', array('%col' => self::CSV_PROJECT_CLIENT, '%row' => $i + 1));
                             } else {
                                 try {
                                     TBGContext::factory()->TBGClient($activerow[self::CSV_PROJECT_CLIENT]);
                                 } catch (Exception $e) {
                                     $errors[] = $this->getI18n()->__('Row %row column %col: client does not exist', array('%col' => self::CSV_PROJECT_CLIENT, '%row' => $i + 1));
                                 }
                             }
                         }
                         // Now check if workflow exists
                         if (array_key_exists(self::CSV_PROJECT_WORKFLOW_ID, $activerow) && isset($activerow[self::CSV_PROJECT_WORKFLOW_ID])) {
                             if (!is_numeric($activerow[self::CSV_PROJECT_WORKFLOW_ID])) {
                                 $errors[] = $this->getI18n()->__('Row %row column %col: invalid value (must be a number)', array('%col' => self::CSV_PROJECT_WORKFLOW_ID, '%row' => $i + 1));
                             } else {
                                 try {
                                     TBGContext::factory()->TBGWorkflowScheme($activerow[self::CSV_PROJECT_WORKFLOW_ID]);
                                 } catch (Exception $e) {
                                     $errors[] = $this->getI18n()->__('Row %row column %col: workflow scheme does not exist', array('%col' => self::CSV_PROJECT_WORKFLOW_ID, '%row' => $i + 1));
                                 }
                             }
                         }
                         // Now check if issuetype scheme
                         if (array_key_exists(self::CSV_PROJECT_ISSUETYPE_SCHEME, $activerow) && isset($activerow[self::CSV_PROJECT_ISSUETYPE_SCHEME])) {
                             if (!is_numeric($activerow[self::CSV_PROJECT_ISSUETYPE_SCHEME])) {
                                 $errors[] = $this->getI18n()->__('Row %row column %col: invalid value (must be a number)', array('%col' => self::CSV_PROJECT_ISSUETYPE_SCHEME, '%row' => $i + 1));
                             } else {
                                 try {
                                     TBGContext::factory()->TBGIssuetypeScheme($activerow[self::CSV_PROJECT_ISSUETYPE_SCHEME]);
                                 } catch (Exception $e) {
                                     $errors[] = $this->getI18n()->__('Row %row column %col: issuetype scheme does not exist', array('%col' => self::CSV_PROJECT_ISSUETYPE_SCHEME, '%row' => $i + 1));
                                 }
                             }
                         }
                         // Finally check if the summary type is valid. At this point, your error list has probably become so big it has eaten up all your available RAM...
                         if (array_key_exists(self::CSV_PROJECT_SUMMARY_TYPE, $activerow) && isset($activerow[self::CSV_PROJECT_SUMMARY_TYPE])) {
                             if ($activerow[self::CSV_PROJECT_SUMMARY_TYPE] != 'issuetypes' && $activerow[self::CSV_PROJECT_SHOW_SUMMARY] != 'milestones') {
                                 $errors[] = $this->getI18n()->__('Row %row column %col: invalid value (must be \'issuetypes\' or \'milestones\')', array('%col' => self::CSV_PROJECT_SUMMARY_TYPE, '%row' => $i + 1));
                             }
                         }
                     }
                     break;
                 case self::CSV_TYPE_ISSUES:
                     for ($i = 0; $i != count($data); $i++) {
                         $activerow = $data[$i];
                         // Check if project exists
                         try {
                             $prjtmp = TBGContext::factory()->TBGProject($activerow[self::CSV_ISSUE_PROJECT]);
                         } catch (Exception $e) {
                             $errors[] = $this->getI18n()->__('Row %row column %col: Project does not exist', array('%col' => self::CSV_ISSUE_PROJECT, '%row' => $i + 1));
                             break;
                         }
                         // First off are booleans
                         $boolitems = array(self::CSV_ISSUE_STATE, self::CSV_ISSUE_BLOCKING);
                         foreach ($boolitems as $boolitem) {
                             if (array_key_exists($boolitem, $activerow) && isset($activerow[$boolitem]) && $activerow[$boolitem] != 1 && $activerow[$boolitem] != 0) {
                                 $errors[] = $this->getI18n()->__('Row %row column %col: invalid value (must be 1/0)', array('%col' => $boolitem, '%row' => $i + 1));
                             }
                         }
                         // Now numerics
                         $numericitems = array(self::CSV_ISSUE_VOTES, self::CSV_ISSUE_PERCENTAGE, self::CSV_ISSUE_ISSUENO);
                         foreach ($numericitems as $numericitem) {
                             if (array_key_exists($numericitem, $activerow) && isset($activerow[$numericitem]) && !is_numeric($activerow[$numericitem])) {
                                 $errors[] = $this->getI18n()->__('Row %row column %col: invalid value (must be a number)', array('%col' => $numericitem, '%row' => $i + 1));
                             }
                         }
                         // Percentage must be 0-100
                         if (array_key_exists(self::CSV_ISSUE_PERCENTAGE, $activerow) && isset($activerow[self::CSV_ISSUE_PERCENTAGE]) && ($activerow[self::CSV_ISSUE_PERCENTAGE] < 0 || $activerow[self::CSV_ISSUE_PERCENTAGE] > 100)) {
                             $errors[] = $this->getI18n()->__('Row %row column %col: Percentage must be from 0 to 100 inclusive', array('%col' => self::CSV_ISSUE_PERCENTAGE, '%row' => $i + 1));
                         }
                         // Now identifiables
                         $identifiableitems = array(array(self::CSV_ISSUE_OWNER, self::CSV_ISSUE_OWNER_TYPE), array(self::CSV_ISSUE_ASSIGNED, self::CSV_ISSUE_ASSIGNED_TYPE));
                         foreach ($identifiableitems as $identifiableitem) {
                             if (!array_key_exists($identifiableitem[1], $activerow) && array_key_exists($identifiableitem[0], $activerow) || array_key_exists($identifiableitem[1], $activerow) && !array_key_exists($identifiableitem[0], $activerow)) {
                                 $errors[] = $this->getI18n()->__('Row %row: Both the type and item ID must be supplied for owner/lead/qa fields', array('%row' => $i + 1));
                                 continue;
                             }
                             if (array_key_exists($identifiableitem[1], $activerow) && isset($activerow[$identifiableitem[1]]) && $activerow[$identifiableitem[1]] != self::CSV_IDENTIFIER_TYPE_USER && $activerow[$identifiableitem[1]] != self::CSV_IDENTIFIER_TYPE_TEAM) {
                                 $errors[] = $this->getI18n()->__('Row %row column %col: invalid value (must be 1 for a user or 2 for a team)', array('%col' => $identifiableitem[1], '%row' => $i + 1));
                             }
                             if (array_key_exists($identifiableitem[0], $activerow) && isset($activerow[$identifiableitem[0]]) && !is_numeric($activerow[$identifiableitem[0]])) {
                                 $errors[] = $this->getI18n()->__('Row %row column %col: invalid value (must be a number)', array('%col' => $identifiableitem[0], '%row' => $i + 1));
                             } elseif (array_key_exists($identifiableitem[0], $activerow) && isset($activerow[$identifiableitem[0]]) && is_numeric($activerow[$identifiableitem[0]])) {
                                 // check if they exist
                                 switch ($activerow[$identifiableitem[1]]) {
                                     case self::CSV_IDENTIFIER_TYPE_USER:
                                         try {
                                             TBGContext::factory()->TBGUser($activerow[$identifiableitem[0]]);
                                         } catch (Exception $e) {
                                             $errors[] = $this->getI18n()->__('Row %row column %col: user does not exist', array('%col' => $identifiableitem[0], '%row' => $i + 1));
                                         }
                                         break;
                                     case self::CSV_IDENTIFIER_TYPE_TEAM:
                                         try {
                                             TBGContext::factory()->TBGTeam($activerow[$identifiableitem[0]]);
                                         } catch (Exception $e) {
                                             $errors[] = $this->getI18n()->__('Row %row column %col: team does not exist', array('%col' => $identifiableitem[0], '%row' => $i + 1));
                                         }
                                         break;
                                 }
                             }
                         }
                         // Now timestamps
                         if (array_key_exists(self::CSV_ISSUE_POSTED, $activerow) && isset($activerow[self::CSV_ISSUE_POSTED]) && (string) (int) $activerow[self::CSV_ISSUE_POSTED] !== $activerow[self::CSV_ISSUE_POSTED] && $activerow[self::CSV_ISSUE_POSTED] >= PHP_INT_MAX && $activerow[self::CSV_ISSUE_POSTED] <= ~PHP_INT_MAX) {
                             $errors[] = $this->getI18n()->__('Row %row column %col: invalid value (must be a Unix timestamp)', array('%col' => self::CSV_ISSUE_POSTED, '%row' => $i + 1));
                         }
                         // Now check user exists for postedby
                         if (array_key_exists(self::CSV_ISSUE_POSTED_BY, $activerow) && isset($activerow[self::CSV_ISSUE_POSTED_BY])) {
                             if (!is_numeric($activerow[self::CSV_ISSUE_POSTED_BY])) {
                                 $errors[] = $this->getI18n()->__('Row %row column %col: invalid value (must be a number)', array('%col' => self::CSV_ISSUE_POSTED_BY, '%row' => $i + 1));
                             } else {
                                 try {
                                     TBGContext::factory()->TBGUser($activerow[self::CSV_ISSUE_POSTED_BY]);
                                 } catch (Exception $e) {
                                     $errors[] = $this->getI18n()->__('Row %row column %col: user does not exist', array('%col' => self::CSV_ISSUE_POSTED_BY, '%row' => $i + 1));
                                 }
                             }
                         }
                         // Now check milestone exists and is valid
                         if (array_key_exists(self::CSV_ISSUE_MILESTONE, $activerow) && isset($activerow[self::CSV_ISSUE_MILESTONE])) {
                             if (!is_numeric($activerow[self::CSV_ISSUE_MILESTONE])) {
                                 $errors[] = $this->getI18n()->__('Row %row column %col: invalid value (must be a number)', array('%col' => self::CSV_ISSUE_MILESTONE, '%row' => $i + 1));
                             } else {
                                 try {
                                     $milestonetmp = TBGContext::factory()->TBGMilestone($activerow[self::CSV_ISSUE_MILESTONE]);
                                     if ($milestonetmp->getProject()->getID() != $activerow[self::CSV_ISSUE_PROJECT]) {
                                         $errors[] = $this->getI18n()->__('Row %row column %col: milestone does not apply to the specified project', array('%col' => self::CSV_ISSUE_MILESTONE, '%row' => $i + 1));
                                     }
                                 } catch (Exception $e) {
                                     $errors[] = $this->getI18n()->__('Row %row column %col: milestone does not exist', array('%col' => self::CSV_ISSUE_MILESTONE, '%row' => $i + 1));
                                 }
                             }
                         }
                         // status
                         if (array_key_exists(self::CSV_ISSUE_STATUS, $activerow) && isset($activerow[self::CSV_ISSUE_STATUS])) {
                             if (!is_numeric($activerow[self::CSV_ISSUE_STATUS])) {
                                 $errors[] = $this->getI18n()->__('Row %row column %col: invalid value (must be a number)', array('%col' => self::CSV_ISSUE_STATUS, '%row' => $i + 1));
                             } else {
                                 try {
                                     TBGContext::factory()->TBGStatus($activerow[self::CSV_ISSUE_STATUS]);
                                 } catch (Exception $e) {
                                     $errors[] = $this->getI18n()->__('Row %row column %col: status does not exist', array('%col' => self::CSV_ISSUE_STATUS, '%row' => $i + 1));
                                 }
                             }
                         }
                         // resolution
                         if (array_key_exists(self::CSV_ISSUE_RESOLUTION, $activerow) && isset($activerow[self::CSV_ISSUE_RESOLUTION])) {
                             if (!is_numeric($activerow[self::CSV_ISSUE_RESOLUTION])) {
                                 $errors[] = $this->getI18n()->__('Row %row column %col: invalid value (must be a number)', array('%col' => self::CSV_ISSUE_RESOLUTION, '%row' => $i + 1));
                             } else {
                                 try {
                                     TBGContext::factory()->TBGResolution($activerow[self::CSV_ISSUE_RESOLUTION]);
                                 } catch (Exception $e) {
                                     $errors[] = $this->getI18n()->__('Row %row column %col: resolution does not exist', array('%col' => self::CSV_ISSUE_RESOLUTION, '%row' => $i + 1));
                                 }
                             }
                         }
                         // priority
                         if (array_key_exists(self::CSV_ISSUE_PRIORITY, $activerow) && isset($activerow[self::CSV_ISSUE_PRIORITY])) {
                             if (!is_numeric($activerow[self::CSV_ISSUE_PRIORITY])) {
                                 $errors[] = $this->getI18n()->__('Row %row column %col: invalid value (must be a number)', array('%col' => self::CSV_ISSUE_PRIORITY, '%row' => $i + 1));
                             } else {
                                 try {
                                     TBGContext::factory()->TBGPriority($activerow[self::CSV_ISSUE_PRIORITY]);
                                 } catch (Exception $e) {
                                     $errors[] = $this->getI18n()->__('Row %row column %col: priority does not exist', array('%col' => self::CSV_ISSUE_PRIORITY, '%row' => $i + 1));
                                 }
                             }
                         }
                         // category
                         if (array_key_exists(self::CSV_ISSUE_CATEGORY, $activerow) && isset($activerow[self::CSV_ISSUE_CATEGORY])) {
                             if (!is_numeric($activerow[self::CSV_ISSUE_CATEGORY])) {
                                 $errors[] = $this->getI18n()->__('Row %row column %col: invalid value (must be a number)', array('%col' => self::CSV_ISSUE_CATEGORY, '%row' => $i + 1));
                             } else {
                                 try {
                                     TBGContext::factory()->TBGCategory($activerow[self::CSV_ISSUE_CATEGORY]);
                                 } catch (Exception $e) {
                                     $errors[] = $this->getI18n()->__('Row %row column %col: category does not exist', array('%col' => self::CSV_ISSUE_CATEGORY, '%row' => $i + 1));
                                 }
                             }
                         }
                         // severity
                         if (array_key_exists(self::CSV_ISSUE_SEVERITY, $activerow) && isset($activerow[self::CSV_ISSUE_SEVERITY])) {
                             if (!is_numeric($activerow[self::CSV_ISSUE_SEVERITY])) {
                                 $errors[] = $this->getI18n()->__('Row %row column %col: invalid value (must be a number)', array('%col' => self::CSV_ISSUE_SEVERITY, '%row' => $i + 1));
                             } else {
                                 try {
                                     TBGContext::factory()->TBGSeverity($activerow[self::CSV_ISSUE_SEVERITY]);
                                 } catch (Exception $e) {
                                     $errors[] = $this->getI18n()->__('Row %row column %col: severity does not exist', array('%col' => self::CSV_ISSUE_SEVERITY, '%row' => $i + 1));
                                 }
                             }
                         }
                         // reproducability
                         if (array_key_exists(self::CSV_ISSUE_REPRODUCIBILITY, $activerow) && isset($activerow[self::CSV_ISSUE_REPRODUCIBILITY])) {
                             if (!is_numeric($activerow[self::CSV_ISSUE_REPRODUCIBILITY])) {
                                 $errors[] = $this->getI18n()->__('Row %row column %col: invalid value (must be a number)', array('%col' => self::CSV_ISSUE_REPRODUCIBILITY, '%row' => $i + 1));
                             } else {
                                 try {
                                     TBGContext::factory()->TBGReproducability($activerow[self::CSV_ISSUE_REPRODUCIBILITY]);
                                 } catch (Exception $e) {
                                     $errors[] = $this->getI18n()->__('Row %row column %col: reproducability does not exist', array('%col' => self::CSV_ISSUE_REPRODUCIBILITY, '%row' => $i + 1));
                                 }
                             }
                         }
                         // type
                         if (array_key_exists(self::CSV_ISSUE_ISSUE_TYPE, $activerow) && isset($activerow[self::CSV_ISSUE_ISSUE_TYPE])) {
                             if (!is_numeric($activerow[self::CSV_ISSUE_ISSUE_TYPE])) {
                                 $errors[] = $this->getI18n()->__('Row %row column %col: invalid value (must be a number)', array('%col' => self::CSV_ISSUE_ISSUE_TYPE, '%row' => $i + 1));
                             } else {
                                 try {
                                     $typetmp = TBGContext::factory()->TBGIssuetype($activerow[self::CSV_ISSUE_ISSUE_TYPE]);
                                     if (!$prjtmp->getIssuetypeScheme()->isSchemeAssociatedWithIssuetype($typetmp)) {
                                         $errors[] = $this->getI18n()->__('Row %row column %col: this project does not support issues of this type (%type)', array('%type' => $typetmp->getName(), '%col' => self::CSV_ISSUE_ISSUE_TYPE, '%row' => $i + 1));
                                     }
                                 } catch (Exception $e) {
                                     $errors[] = $this->getI18n()->__('Row %row column %col: issue type does not exist', array('%col' => self::CSV_ISSUE_ISSUE_TYPE, '%row' => $i + 1));
                                 }
                             }
                         }
                     }
                     break;
             }
         }
         // Handle errors
         if (count($errors) != 0) {
             $errordiv = '<ul>';
             foreach ($errors as $error) {
                 $errordiv .= '<li>' . $error . '</li>';
             }
             $errordiv .= '</ul>';
             $this->getResponse()->setHttpStatus(400);
             return $this->renderJSON(array('errordetail' => $errordiv, 'error' => $this->getI18n()->__('Errors occured while importing, see the error list in the import screen for further details')));
         }
     } catch (Exception $e) {
         $this->getResponse()->setHttpStatus(400);
         return $this->renderJSON(array('errordetail' => $e->getMessage(), 'error' => $e->getMessage()));
     }
     if ($request['csv_dry_run']) {
         return $this->renderJSON(array('message' => $this->getI18n()->__('Dry-run successful, you can now uncheck the dry-run box and import your data.')));
     } else {
         switch ($request['type']) {
             case self::CSV_TYPE_CLIENTS:
                 for ($i = 0; $i != count($data); $i++) {
                     try {
                         $activerow = $data[$i];
                         $client = new TBGClient();
                         $client->setName($activerow[self::CSV_CLIENT_NAME]);
                         if (isset($activerow[self::CSV_CLIENT_EMAIL])) {
                             $client->setEmail($activerow[self::CSV_CLIENT_EMAIL]);
                         }
                         if (isset($activerow[self::CSV_CLIENT_WEBSITE])) {
                             $client->setWebsite($activerow[self::CSV_CLIENT_WEBSITE]);
                         }
                         if (isset($activerow[self::CSV_CLIENT_FAX])) {
                             $client->setFax($activerow[self::CSV_CLIENT_FAX]);
                         }
                         if (isset($activerow[self::CSV_CLIENT_TELEPHONE])) {
                             $client->setTelephone($activerow[self::CSV_CLIENT_TELEPHONE]);
                         }
                         $client->save();
                     } catch (Exception $e) {
                         $errors[] = $this->getI18n()->__('Row %row failed: %err', array('%row' => $i + 1, '%err' => $e->getMessage()));
                     }
                 }
                 break;
             case self::CSV_TYPE_PROJECTS:
                 for ($i = 0; $i != count($data); $i++) {
                     try {
                         $activerow = $data[$i];
                         $project = new TBGProject();
                         $project->setName($activerow[self::CSV_PROJECT_NAME]);
                         $project->save();
                         if (isset($activerow[self::CSV_PROJECT_PREFIX])) {
                             $project->setPrefix($activerow[self::CSV_PROJECT_PREFIX]);
                             $project->setUsePrefix(true);
                         }
                         if (isset($activerow[self::CSV_PROJECT_SCRUM])) {
                             if ($activerow[self::CSV_PROJECT_SCRUM] == '1') {
                                 $project->setUsesScrum(true);
                             }
                         }
                         if (isset($activerow[self::CSV_PROJECT_OWNER]) && isset($activerow[self::CSV_PROJECT_OWNER_TYPE])) {
                             switch ($activerow[self::CSV_PROJECT_OWNER_TYPE]) {
                                 case self::CSV_IDENTIFIER_TYPE_USER:
                                     $user = new TBGUser($activerow[self::CSV_PROJECT_OWNER]);
                                     $project->setOwner($user);
                                     break;
                                 case self::CSV_IDENTIFIER_TYPE_TEAM:
                                     $team = new TBGTeam($activerow[self::CSV_PROJECT_OWNER]);
                                     $project->setOwner($team);
                                     break;
                             }
                         }
                         if (isset($activerow[self::CSV_PROJECT_LEAD]) && isset($activerow[self::CSV_PROJECT_LEAD_TYPE])) {
                             switch ($activerow[self::CSV_PROJECT_LEAD_TYPE]) {
                                 case self::CSV_IDENTIFIER_TYPE_USER:
                                     $user = new TBGUser($activerow[self::CSV_PROJECT_LEAD]);
                                     $project->setLeader($user);
                                     break;
                                 case self::CSV_IDENTIFIER_TYPE_TEAM:
                                     $team = new TBGTeam($activerow[self::CSV_PROJECT_LEAD]);
                                     $project->setLeader($team);
                                     break;
                             }
                         }
                         if (isset($activerow[self::CSV_PROJECT_QA]) && isset($activerow[self::CSV_PROJECT_QA_TYPE])) {
                             switch ($activerow[self::CSV_PROJECT_QA_TYPE]) {
                                 case self::CSV_IDENTIFIER_TYPE_USER:
                                     $user = new TBGUser($activerow[self::CSV_PROJECT_QA]);
                                     $project->setQaResponsible($user);
                                     break;
                                 case self::CSV_IDENTIFIER_TYPE_TEAM:
                                     $team = new TBGTeam($activerow[self::CSV_PROJECT_QA]);
                                     $project->setQaResponsible($team);
                                     break;
                             }
                         }
                         if (isset($activerow[self::CSV_PROJECT_DESCR])) {
                             $project->setDescription($activerow[self::CSV_PROJECT_DESCR]);
                         }
                         if (isset($activerow[self::CSV_PROJECT_DOC_URL])) {
                             $project->setDocumentationUrl($activerow[self::CSV_PROJECT_DOC_URL]);
                         }
                         if (isset($activerow[self::CSV_PROJECT_WIKI_URL])) {
                             $project->setWikiUrl($activerow[self::CSV_PROJECT_WIKI_URL]);
                         }
                         if (isset($activerow[self::CSV_PROJECT_FREELANCE])) {
                             if ($activerow[self::CSV_PROJECT_FREELANCE] == '1') {
                                 $project->setChangeIssuesWithoutWorkingOnThem(true);
                             }
                         }
                         if (isset($activerow[self::CSV_PROJECT_EN_BUILDS])) {
                             if ($activerow[self::CSV_PROJECT_EN_BUILDS] == '1') {
                                 $project->setBuildsEnabled(true);
                             }
                         }
                         if (isset($activerow[self::CSV_PROJECT_EN_COMPS])) {
                             if ($activerow[self::CSV_PROJECT_EN_COMPS] == '1') {
                                 $project->setComponentsEnabled(true);
                             }
                         }
                         if (isset($activerow[self::CSV_PROJECT_EN_EDITIONS])) {
                             if ($activerow[self::CSV_PROJECT_EN_EDITIONS] == '1') {
                                 $project->setEditionsEnabled(true);
                             }
                         }
                         if (isset($activerow[self::CSV_PROJECT_CLIENT])) {
                             $project->setClient(TBGContext::factory()->TBGClient($activerow[self::CSV_PROJECT_CLIENT]));
                         }
                         if (isset($activerow[self::CSV_PROJECT_SHOW_SUMMARY])) {
                             if ($activerow[self::CSV_PROJECT_SHOW_SUMMARY] == '1') {
                                 $project->setFrontpageSummaryVisibility(true);
                             }
                         }
                         if (isset($activerow[self::CSV_PROJECT_SUMMARY_TYPE])) {
                             $project->setFrontpageSummaryType($activerow[self::CSV_PROJECT_SUMMARY_TYPE]);
                         }
                         if (isset($activerow[self::CSV_PROJECT_ALLOW_REPORTING])) {
                             $project->setLocked($activerow[self::CSV_PROJECT_ALLOW_REPORTING]);
                         }
                         if (isset($activerow[self::CSV_PROJECT_AUTOASSIGN])) {
                             $project->setAutoassign($activerow[self::CSV_PROJECT_AUTOASSIGN]);
                         }
                         if (isset($activerow[self::CSV_PROJECT_ISSUETYPE_SCHEME])) {
                             $project->setIssuetypeScheme(TBGContext::factory()->TBGIssuetypeScheme($activerow[self::CSV_PROJECT_ISSUETYPE_SCHEME]));
                         }
                         if (isset($activerow[self::CSV_PROJECT_WORKFLOW_ID])) {
                         }
                         $project->setWorkflowScheme(TBGContext::factory()->TBGWorkflowScheme($activerow[self::CSV_PROJECT_WORKFLOW_ID]));
                         $project->save();
                     } catch (Exception $e) {
                         $errors[] = $this->getI18n()->__('Row %row failed: %err', array('%row' => $i + 1, '%err' => $e->getMessage()));
                     }
                 }
                 break;
             case self::CSV_TYPE_ISSUES:
                 for ($i = 0; $i != count($data); $i++) {
                     try {
                         $activerow = $data[$i];
                         $issue = new TBGIssue();
                         $issue->setTitle($activerow[self::CSV_ISSUE_TITLE]);
                         $issue->setProject($activerow[self::CSV_ISSUE_PROJECT]);
                         $issue->setIssuetype($activerow[self::CSV_ISSUE_ISSUE_TYPE]);
                         $issue->save();
                         if (isset($activerow[self::CSV_ISSUE_DESCR])) {
                             $issue->setDescription($activerow[self::CSV_ISSUE_DESCR]);
                         }
                         if (isset($activerow[self::CSV_ISSUE_REPRO])) {
                             $issue->setReproductionSteps($activerow[self::CSV_ISSUE_REPRO]);
                         }
                         if (isset($activerow[self::CSV_ISSUE_STATE])) {
                             $issue->setState($activerow[self::CSV_ISSUE_STATE]);
                         }
                         if (isset($activerow[self::CSV_ISSUE_STATUS])) {
                             $issue->setStatus($activerow[self::CSV_ISSUE_STATUS]);
                         }
                         if (isset($activerow[self::CSV_ISSUE_POSTED_BY])) {
                             $issue->setPostedBy(TBGContext::factory()->TBGUser($activerow[self::CSV_ISSUE_POSTED_BY]));
                         }
                         if (isset($activerow[self::CSV_ISSUE_OWNER]) && isset($activerow[self::CSV_ISSUE_OWNER_TYPE])) {
                             switch ($activerow[self::CSV_ISSUE_OWNER_TYPE]) {
                                 case self::CSV_IDENTIFIER_TYPE_USER:
                                     $user = new TBGUser($activerow[self::CSV_ISSUE_OWNER]);
                                     $issue->setOwner($user);
                                     break;
                                 case self::CSV_IDENTIFIER_TYPE_TEAM:
                                     $team = new TBGTeam($activerow[self::CSV_ISSUE_OWNER]);
                                     $issue->setOwner($team);
                                     break;
                             }
                         }
                         if (isset($activerow[self::CSV_ISSUE_ASSIGNED]) && isset($activerow[self::CSV_ISSUE_ASSIGNED_TYPE])) {
                             switch ($activerow[self::CSV_ISSUE_ASSIGNED_TYPE]) {
                                 case self::CSV_IDENTIFIER_TYPE_USER:
                                     $user = new TBGUser($activerow[self::CSV_ISSUE_ASSIGNED]);
                                     $issue->setAssignee($user);
                                     break;
                                 case self::CSV_IDENTIFIER_TYPE_TEAM:
                                     $team = new TBGTeam($activerow[self::CSV_ISSUE_ASSIGNED]);
                                     $issue->setAssignee($team);
                                     break;
                             }
                         }
                         if (isset($activerow[self::CSV_ISSUE_RESOLUTION])) {
                             $issue->setResolution($activerow[self::CSV_ISSUE_RESOLUTION]);
                         }
                         if (isset($activerow[self::CSV_ISSUE_PRIORITY])) {
                             $issue->setPriority($activerow[self::CSV_ISSUE_PRIORITY]);
                         }
                         if (isset($activerow[self::CSV_ISSUE_CATEGORY])) {
                             $issue->setCategory($activerow[self::CSV_ISSUE_CATEGORY]);
                         }
                         if (isset($activerow[self::CSV_ISSUE_BLOCKING])) {
                             $issue->setBlocking($activerow[self::CSV_ISSUE_BLOCKING]);
                         }
                         if (isset($activerow[self::CSV_ISSUE_SEVERITY])) {
                             $issue->setSeverity($activerow[self::CSV_ISSUE_SEVERITY]);
                         }
                         if (isset($activerow[self::CSV_ISSUE_REPRODUCIBILITY])) {
                             $issue->setReproducability($activerow[self::CSV_ISSUE_REPRODUCIBILITY]);
                         }
                         if (isset($activerow[self::CSV_ISSUE_VOTES])) {
                             $issue->setVotes($activerow[self::CSV_ISSUE_VOTES]);
                         }
                         if (isset($activerow[self::CSV_ISSUE_PERCENTAGE])) {
                             $issue->setPercentCompleted($activerow[self::CSV_ISSUE_PERCENTAGE]);
                         }
                         if (isset($activerow[self::CSV_ISSUE_ISSUENO])) {
                             $issue->setIssueNo((int) $activerow[self::CSV_ISSUE_ISSUENO]);
                         }
                         if (isset($activerow[self::CSV_ISSUE_MILESTONE])) {
                             $issue->setMilestone($activerow[self::CSV_ISSUE_MILESTONE]);
                         }
                         if (isset($activerow[self::CSV_ISSUE_POSTED])) {
                             $issue->setPosted((int) $activerow[self::CSV_ISSUE_POSTED]);
                         }
                         $issue->save();
                     } catch (Exception $e) {
                         $errors[] = $this->getI18n()->__('Row %row failed: %err', array('%row' => $i + 1, '%err' => $e->getMessage()));
                     }
                 }
                 break;
         }
         // Handle errors
         if (count($errors) != 0) {
             $errordiv = '<ul>';
             foreach ($errors as $error) {
                 $errordiv .= '<li>' . $error . '</li>';
             }
             $errordiv .= '</ul>';
             $this->getResponse()->setHttpStatus(400);
             return $this->renderJSON(array('errordetail' => $errordiv, 'error' => $this->getI18n()->__('Errors occured while importing, see the error list in the import screen for further details')));
         } else {
             return $this->renderJSON(array('message' => $this->getI18n()->__('Successfully imported %num rows!', array('%num' => count($data)))));
         }
     }
 }
 /**
  * Set the currently selected project
  * 
  * @param TBGProject $project The project, or null if none
  */
 public static function setCurrentProject($project)
 {
     self::getResponse()->setBreadcrumb(null);
     self::$_selected_project = $project;
     if ($project instanceof TBGProject) {
         $projectsubmenulinks = null;
         $clientsubmenulinks = null;
         if (count(TBGProject::getAll()) > 1) {
             $projectsubmenulinks = array();
             foreach (TBGProject::getAll() as $existing_project) {
                 if (!$project->hasClient() || $existing_project->hasClient() && $project->getClient()->getID() == $existing_project->getClient()->getID()) {
                     $projectsubmenulinks[] = array('url' => self::getRouting()->generate('project_dashboard', array('project_key' => $existing_project->getKey())), 'title' => $existing_project->getName());
                 }
             }
         }
         if (self::$_selected_project->hasClient()) {
             $clientsubmenulinks = array();
             foreach (TBGClient::getAll() as $client) {
                 if ($client->hasAccess()) {
                     $clientsubmenulinks[] = array('url' => self::getRouting()->generate('client_dashboard', array('client_id' => $client->getID())), 'title' => $client->getName());
                 }
             }
             self::setCurrentClient(self::$_selected_project->getClient());
         }
         if (strtolower(TBGSettings::getTBGname()) != strtolower($project->getName()) || self::isClientContext()) {
             self::getResponse()->addBreadcrumb(TBGSettings::getTBGName(), self::getRouting()->generate('home'));
             if (self::isClientContext()) {
                 self::getResponse()->addBreadcrumb(self::getCurrentClient()->getName(), self::getRouting()->generate('client_dashboard', array('client_id' => self::getCurrentClient()->getID())), $clientsubmenulinks);
             }
         }
         self::getResponse()->addBreadcrumb($project->getName(), self::getRouting()->generate('project_dashboard', array('project_key' => TBGContext::getCurrentProject()->getKey())), $projectsubmenulinks, 'selected_project');
     } else {
         self::getResponse()->addBreadcrumb(TBGSettings::getTBGName(), self::getRouting()->generate('home'));
     }
 }
 /**
  * Return if the user can assign scrum user stories
  *
  * @param TBGProject $project
  *
  * @return boolean
  */
 public function canAssignScrumUserStories(TBGProject $project)
 {
     return (bool) ($this->hasPermission('canassignscrumuserstoriestosprints', $project->getID(), 'core', true) || $this->hasPermission('candoscrumplanning', $project->getID(), 'core', true) || $this->hasPermission('canassignscrumuserstoriestosprints', 0, 'core', true) || $this->hasPermission('candoscrumplanning', 0, 'core', true));
 }
Example #17
0
 protected function _upgradeFrom3dot1()
 {
     // Add classpath for existing old tables used for upgrade
     TBGContext::addAutoloaderClassPath(THEBUGGENIE_MODULES_PATH . 'installation' . DS . 'classes' . DS . 'upgrade_3.1');
     TBGContext::addAutoloaderClassPath(THEBUGGENIE_MODULES_PATH . 'mailing' . DS . 'classes' . DS . 'B2DB');
     TBGContext::addAutoloaderClassPath(THEBUGGENIE_MODULES_PATH . 'mailing' . DS . 'classes');
     TBGContext::addAutoloaderClassPath(THEBUGGENIE_MODULES_PATH . 'publish' . DS . 'classes' . DS . 'B2DB');
     TBGContext::addAutoloaderClassPath(THEBUGGENIE_MODULES_PATH . 'publish' . DS . 'classes');
     // Create new tables
     TBGDashboardViewsTable::getTable()->create();
     TBGOpenIdAccountsTable::getTable()->create();
     TBGProjectAssignedUsersTable::getTable()->create();
     TBGProjectAssignedTeamsTable::getTable()->create();
     TBGEditionAssignedUsersTable::getTable()->create();
     TBGEditionAssignedTeamsTable::getTable()->create();
     TBGComponentAssignedUsersTable::getTable()->create();
     TBGComponentAssignedTeamsTable::getTable()->create();
     TBGRolePermissionsTable::getTable()->create();
     TBGUserScopesTable::getTable()->create();
     // Upgrade existing tables
     TBGProjectsTable::getTable()->upgrade(TBGProjectsTable3dot1::getTable());
     TBGUsersTable::getTable()->upgrade(TBGUsersTable3dot1::getTable());
     TBGIssuesTable::getTable()->upgrade(TBGIssuesTable3dot1::getTable());
     TBGIssueTypesTable::getTable()->upgrade(TBGIssueTypesTable3dot1::getTable());
     TBGListTypesTable::getTable()->upgrade(TBGListTypesTable3dot1::getTable());
     TBGEditionsTable::getTable()->upgrade(TBGEditionsTable3dot1::getTable());
     TBGBuildsTable::getTable()->upgrade(TBGBuildsTable3dot1::getTable());
     TBGCommentsTable::getTable()->upgrade(TBGCommentsTable3dot1::getTable());
     TBGComponentsTable::getTable()->upgrade(TBGComponentsTable3dot1::getTable());
     TBGCustomFieldsTable::getTable()->upgrade(TBGCustomFieldsTable3dot1::getTable());
     TBGCustomFieldOptionsTable::getTable()->upgrade(TBGCustomFieldOptionsTable3dot1::getTable());
     TBGIssueCustomFieldsTable::getTable()->upgrade(TBGIssueCustomFieldsTable3dot1::getTable());
     // Create new module tables
     TBGIncomingEmailAccountTable::getTable()->create();
     // Add new indexes
     TBGArticlesTable::getTable()->createIndexes();
     TBGCommentsTable::getTable()->createIndexes();
     TBGIssueAffectsBuildTable::getTable()->createIndexes();
     TBGIssueAffectsComponentTable::getTable()->createIndexes();
     TBGIssueAffectsEditionTable::getTable()->createIndexes();
     TBGIssueFieldsTable::getTable()->createIndexes();
     TBGIssueFilesTable::getTable()->createIndexes();
     TBGIssuesTable::getTable()->createIndexes();
     TBGIssuetypeSchemesTable::getTable()->createIndexes();
     TBGPermissionsTable::getTable()->createIndexes();
     TBGProjectsTable::getTable()->createIndexes();
     TBGSettingsTable::getTable()->createIndexes();
     TBGTeamMembersTable::getTable()->createIndexes();
     TBGUserIssuesTable::getTable()->createIndexes();
     TBGUsersTable::getTable()->createIndexes();
     TBGUserScopesTable::getTable()->createIndexes();
     if (TBGContext::getRequest()->getParameter('fix_my_timestamps', false)) {
         $this->_fixTimestamps();
     }
     foreach (TBGScope::getAll() as $scope) {
         TBGRole::loadFixtures($scope);
         foreach (TBGDatatype::getTypes() as $type => $class) {
             TBGContext::setPermission('set_datatype_' . $type, 0, 'core', 0, 0, 0, true, $scope->getID());
         }
         TBGContext::setPermission('page_confirm_scope_access', 0, 'core', 0, 0, 0, true, $scope->getID());
         if (!TBGSettings::get(TBGSettings::SETTING_DEFAULT_WORKFLOW, 'core', $scope->getID())) {
             $workflow_id = TBGWorkflowsTable::getTable()->getFirstIdByScope($scope->getID());
             if ($workflow_id) {
                 TBGSettings::saveSetting(TBGSettings::SETTING_DEFAULT_WORKFLOW, $workflow_id, 'core', $scope->getID());
             } else {
                 TBGWorkflow::loadFixtures($scope);
             }
         }
         if (!TBGSettings::get(TBGSettings::SETTING_DEFAULT_WORKFLOWSCHEME, 'core', $scope->getID())) {
             $workflow_scheme_id = TBGWorkflowSchemesTable::getTable()->getFirstIdByScope($scope->getID());
             if ($workflow_scheme_id) {
                 TBGSettings::saveSetting(TBGSettings::SETTING_DEFAULT_WORKFLOWSCHEME, $workflow_scheme_id, 'core', $scope->getID());
             } else {
                 TBGWorkflowScheme::loadFixtures($scope);
             }
         }
         if (!TBGSettings::get(TBGSettings::SETTING_DEFAULT_ISSUETYPESCHEME, 'core', $scope->getID())) {
             $issuetype_scheme_id = TBGIssuetypeSchemesTable::getTable()->getFirstIdByScope($scope->getID());
             if ($issuetype_scheme_id) {
                 TBGSettings::saveSetting(TBGSettings::SETTING_DEFAULT_ISSUETYPESCHEME, $issuetype_scheme_id, 'core', $scope->getID());
             } else {
                 TBGIssuetypeScheme::loadFixtures($scope);
             }
         }
         TBGSettings::saveSetting(TBGSettings::SETTING_FAVICON_ID, 0, 'core', $scope->getID());
         TBGSettings::saveSetting(TBGSettings::SETTING_FAVICON_TYPE, 0, 'core', $scope->getID());
         TBGSettings::saveSetting(TBGSettings::SETTING_HEADER_ICON_ID, 0, 'core', $scope->getID());
         TBGSettings::saveSetting(TBGSettings::SETTING_HEADER_ICON_TYPE, 0, 'core', $scope->getID());
     }
     $linkstable = TBGLinksTable::getTable();
     $crit = $linkstable->getCriteria();
     $crit->addUpdate(TBGLinksTable::URL, 'http://issues.thebuggenie.com');
     $crit->addWhere(TBGLinksTable::URL, 'http://thebuggenie.com/thebuggenie');
     $crit->addOr(TBGLinksTable::URL, 'http://www.thebuggenie.com/thebuggenie');
     $linkstable->doUpdate($crit);
     $listtypestable = TBGListTypesTable::getTable();
     $crit = $listtypestable->getCriteria();
     $crit->addUpdate(TBGListTypesTable::ITEMTYPE, 'role');
     $crit->addWhere(TBGListTypesTable::ITEMTYPE, 'projectrole');
     $listtypestable->doUpdate($crit);
     $crit = $listtypestable->getCriteria();
     $crit->addUpdate(TBGListTypesTable::ITEMTYPE, 'priority');
     $crit->addWhere(TBGListTypesTable::ITEMTYPE, 'b2_prioritytypes');
     $listtypestable->doUpdate($crit);
     TBGWorkflowTransitionsTable::getTable()->upgradeFrom3dot1();
     TBGSettings::saveSetting(TBGSettings::SETTING_ICONSET, TBGSettings::get(TBGSettings::SETTING_THEME_NAME));
     TBGContext::setPermission('readarticle', 0, 'publish', 0, 0, 0, true);
     foreach (TBGProject::getAll() as $project) {
         TBGDashboardViewsTable::getTable()->setDefaultViews($project->getID(), TBGDashboardViewsTable::TYPE_PROJECT);
         if (!$project->getKey()) {
             $project->setName($project->getName());
         }
     }
     $this->upgrade_complete = true;
 }
Example #18
0
?>
><?php 
echo __('No, use regular index page');
?>
</option>
			</select>
		</td>
	</tr>
	<tr>
		<td class="config_explanation" colspan="2">
			<?php 
echo __('In single project tracker mode, The Bug Genie will display the homepage for the first project as the main page instead of the regular index page');
?>
<br>
			<?php 
if (count(TBGProject::getAll()) > 1) {
    ?>
				<br>
				<b class="more_than_one_project_warning"><?php 
    echo __('More than one project exists. When in "single project" mode, accessing other projects than the first will become harder.');
    ?>
</b>
			<?php 
}
?>
		</td>
	</tr>
	<tr>
		<td><label for="showprojectsoverview"><?php 
echo __('Show project list on frontpage');
?>
Example #19
0
 /**
  * Return if the user can assign scrum user stories
  *
  * @param TBGProject $project
  *
  * @return boolean
  */
 public function canAssignScrumUserStories(TBGProject $project)
 {
     if ($project->isArchived()) {
         return false;
     }
     if ($this->canSaveConfiguration(TBGSettings::CONFIGURATION_SECTION_PROJECTS)) {
         return true;
     }
     if ($project->getOwner() instanceof TBGUser && $project->getOwner()->getID() == $this->getID()) {
         return true;
     }
     $retval = $this->hasPermission('canassignscrumuserstoriestosprints', $project->getID());
     $retval = $retval !== null ? $retval : $this->hasPermission('candoscrumplanning', $project->getID());
     $retval = $retval !== null ? $retval : $this->hasPermission('canassignscrumuserstoriestosprints', 0);
     $retval = $retval !== null ? $retval : $this->hasPermission('candoscrumplanning', 0);
     return (bool) ($retval !== null) ? $retval : false;
 }
Example #20
0
</th>
									<th><?php 
echo __('ID');
?>
</th>
								</tr>
							</thead>
							<tbody>
						<?php 
foreach (TBGIssuetypeScheme::getAll() as $item) {
    echo '<tr><td>' . __('Issue type scheme') . '</td><td>' . $item->getName() . '</td><td>' . $item->getID() . '</td></tr>';
}
foreach (TBGWorkflowScheme::getAll() as $item) {
    echo '<tr><td>' . __('Workflow scheme') . '</td><td>' . $item->getName() . '</td><td>' . $item->getID() . '</td></tr>';
}
foreach (TBGProject::getAll() as $item) {
    echo '<tr><td>' . __('Project') . '</td><td>' . $item->getName() . '</td><td>' . $item->getID() . '</td></tr>';
    foreach (TBGMilestone::getAllByProjectID($item->getID()) as $item2) {
        echo '<tr><td>' . __('Milestone for project') . ' ' . $item->getID() . '</td><td>' . $item2->getName() . '</td><td>' . $item2->getID() . '</td></tr>';
    }
}
foreach (TBGReproducability::getAll() as $item) {
    echo '<tr><td>' . __('Reproducability') . '</td><td>' . $item->getName() . '</td><td>' . $item->getID() . '</td></tr>';
}
foreach (TBGSeverity::getAll() as $item) {
    echo '<tr><td>' . __('Severity') . '</td><td>' . $item->getName() . '</td><td>' . $item->getID() . '</td></tr>';
}
foreach (TBGCategory::getAll() as $item) {
    echo '<tr><td>' . __('Category') . '</td><td>' . $item->getName() . '</td><td>' . $item->getID() . '</td></tr>';
}
foreach (TBGPriority::getAll() as $item) {
 public function getProject()
 {
     $namespaces = $this->getNamespaces();
     if (count($namespaces) > 0) {
         $key = $namespaces[0];
         $project = TBGProject::getByKey($key);
         return $project;
     }
 }
Example #22
0
 public function runFilterGetDynamicChoices(TBGRequest $request)
 {
     $subproject_ids = explode(',', $request['subprojects']);
     $existing_ids = $request['existing_ids'];
     $results = array();
     $projects = $request['project_id'] != '' ? TBGProject::getAllByIDs(explode(',', $request['project_id'])) : TBGProject::getAll();
     $items = array('build' => array(), 'edition' => array(), 'component' => array(), 'milestone' => array());
     foreach ($projects as $project) {
         foreach ($project->getBuilds() as $build) {
             $items['build'][$build->getID()] = $build;
         }
         foreach ($project->getEditions() as $edition) {
             $items['edition'][$edition->getID()] = $edition;
         }
         foreach ($project->getComponents() as $component) {
             $items['component'][$component->getID()] = $component;
         }
         foreach ($project->getMilestones() as $milestone) {
             $items['milestone'][$milestone->getID()] = $milestone;
         }
     }
     $filters = array();
     $filters['build'] = TBGSearchFilter::createFilter('build');
     $filters['edition'] = TBGSearchFilter::createFilter('edition');
     $filters['component'] = TBGSearchFilter::createFilter('component');
     $filters['milestone'] = TBGSearchFilter::createFilter('milestone');
     if (isset($existing_ids['build'])) {
         foreach (TBGBuildsTable::getTable()->getByIDs($existing_ids['build']) as $build) {
             $items['build'][$build->getID()] = $build;
         }
         $filters['build']->setValue(join(',', $existing_ids['build']));
     }
     if (isset($existing_ids['edition'])) {
         foreach (TBGEditionsTable::getTable()->getByIDs($existing_ids['edition']) as $edition) {
             $items['edition'][$edition->getID()] = $edition;
         }
         $filters['edition']->setValue(join(',', $existing_ids['edition']));
     }
     if (isset($existing_ids['component'])) {
         foreach (TBGComponentsTable::getTable()->getByIDs($existing_ids['component']) as $component) {
             $items['component'][$component->getID()] = $component;
         }
         $filters['component']->setValue(join(',', $existing_ids['component']));
     }
     if (isset($existing_ids['milestone'])) {
         foreach (TBGMilestonesTable::getTable()->getByIDs($existing_ids['milestone']) as $milestone) {
             $items['milestone'][$milestone->getID()] = $milestone;
         }
         $filters['milestone']->setValue(join(',', $existing_ids['milestone']));
     }
     foreach (array('build', 'edition', 'component', 'milestone') as $k) {
         $results[$k] = $this->getTemplateHTML('search/interactivefilterdynamicchoicelist', array('filter' => $filters[$k], 'items' => $items[$k]));
     }
     return $this->renderJSON(compact('results'));
 }
		</ul>
	</div>
	<div id="<?php 
echo $base_id;
?>
_tab_projects_pane" class="tab_pane" style="display: none;">
		<p><?php 
echo __('These permissions control what you can do, and which pages you can access in The Bug Genie - on a project-specific basis. Some of these permissions are also available as site-wide permissions, from the "%general_permissions%" tab.', array('%general_permissions%' => '<i>' . __('General permissions') . '</i>'));
?>
</p>
		<?php 
if (count(TBGProject::getAll()) > 0) {
    ?>
			<ul>
				<?php 
    foreach (TBGProject::getAll() as $project) {
        ?>
					<li>
						<a href="javascript:void(0);" onclick="$('project_permission_details_<?php 
        echo $project->getID();
        ?>
').toggle();"><?php 
        echo image_tag('icon_project_permissions.png', array('style' => 'float: right;'));
        echo $project->getName();
        ?>
 <span class="faded_out smaller"><?php 
        echo $project->getKey();
        ?>
</span></a>
						<ul style="display: none;" id="project_permission_details_<?php 
        echo $project->getID();
 /**
  * Move issues from one step to another for a given issue type and conversions
  * @param TBGProject $project
  * @param TBGIssuetype $type
  * @param array $conversions
  * 
  * $conversions should be an array containing arrays:
  * array (
  * 		array(oldstep, newstep)
  * 		...
  * )
  */
 public function convertIssueStepByIssuetype(TBGProject $project, TBGIssuetype $type, array $conversions)
 {
     foreach ($conversions as $conversion) {
         $crit = $this->getCriteria();
         $crit->addWhere(self::PROJECT_ID, $project->getID());
         $crit->addWhere(self::ISSUE_TYPE, $type->getID());
         $crit->addWhere(self::WORKFLOW_STEP_ID, $conversion[0]);
         $crit->addUpdate(self::WORKFLOW_STEP_ID, $conversion[1]);
         $this->doUpdate($crit);
     }
 }
 /**
  *
  * @param \b2db\Criteria $crit
  * @param array|TBGSearchFilter $filters
  * @param \b2db\Criterion $ctn
  * @return null
  */
 public function addToCriteria($crit, $filters, $ctn = null)
 {
     $filter_key = $this->getFilterKey();
     if (in_array($this['operator'], array('=', '!=', '<=', '>=', '<', '>'))) {
         if ($filter_key == 'text') {
             if ($this['value'] != '') {
                 $searchterm = mb_strpos($this['value'], '%') !== false ? $this['value'] : "%{$this['value']}%";
                 if ($this['operator'] == '=') {
                     if ($ctn === null) {
                         $ctn = $crit->returnCriterion(TBGIssuesTable::TITLE, $searchterm, Criteria::DB_LIKE);
                     }
                     $ctn->addOr(TBGIssuesTable::DESCRIPTION, $searchterm, Criteria::DB_LIKE);
                     $ctn->addOr(TBGIssuesTable::REPRODUCTION_STEPS, $searchterm, Criteria::DB_LIKE);
                     $ctn->addOr(TBGIssueCustomFieldsTable::OPTION_VALUE, $searchterm, Criteria::DB_LIKE);
                 } else {
                     if ($ctn === null) {
                         $ctn = $crit->returnCriterion(TBGIssuesTable::TITLE, $searchterm, Criteria::DB_NOT_LIKE);
                     }
                     $ctn->addWhere(TBGIssuesTable::DESCRIPTION, $searchterm, Criteria::DB_NOT_LIKE);
                     $ctn->addWhere(TBGIssuesTable::REPRODUCTION_STEPS, $searchterm, Criteria::DB_NOT_LIKE);
                     $ctn->addOr(TBGIssueCustomFieldsTable::OPTION_VALUE, $searchterm, Criteria::DB_NOT_LIKE);
                 }
                 return $ctn;
             }
         } elseif (in_array($filter_key, self::getValidSearchFilters())) {
             if ($filter_key == 'subprojects') {
                 if (TBGContext::isProjectContext()) {
                     if ($ctn === null) {
                         $ctn = $crit->returnCriterion(TBGIssuesTable::PROJECT_ID, TBGContext::getCurrentProject()->getID());
                     }
                     if ($this->hasValue()) {
                         foreach ($this->getValues() as $value) {
                             switch ($value) {
                                 case 'all':
                                     $subprojects = TBGProject::getIncludingAllSubprojectsAsArray(TBGContext::getCurrentProject());
                                     foreach ($subprojects as $subproject) {
                                         if ($subproject->getID() == TBGContext::getCurrentProject()->getID()) {
                                             continue;
                                         }
                                         $ctn->addOr(TBGIssuesTable::PROJECT_ID, $subproject->getID());
                                     }
                                     break;
                                 case 'none':
                                 case '':
                                     break;
                                 default:
                                     $ctn->addOr(TBGIssuesTable::PROJECT_ID, (int) $value);
                                     break;
                             }
                         }
                     }
                     return $ctn;
                 }
             } elseif (in_array($filter_key, array('build', 'edition', 'component'))) {
                 switch ($filter_key) {
                     case 'component':
                         $tbl = TBGIssueAffectsComponentTable::getTable();
                         $fk = TBGIssueAffectsComponentTable::ISSUE;
                         break;
                     case 'edition':
                         $tbl = TBGIssueAffectsEditionTable::getTable();
                         $fk = TBGIssueAffectsEditionTable::ISSUE;
                         break;
                     case 'build':
                         $tbl = TBGIssueAffectsBuildTable::getTable();
                         $fk = TBGIssueAffectsBuildTable::ISSUE;
                         break;
                 }
                 $crit->addJoin($tbl, $fk, TBGIssuesTable::ID, array(array($tbl->getB2DBAlias() . '.' . $filter_key, $this->getValues())), \b2db\Criteria::DB_INNER_JOIN);
                 return null;
             } else {
                 if ($filter_key == 'project_id' && in_array('subprojects', $filters)) {
                     return null;
                 }
                 $values = $this->getValues();
                 $num_values = 0;
                 if ($filter_key == 'status') {
                     if ($this->hasValue('open')) {
                         $c = $crit->returnCriterion(TBGIssuesTable::STATE, TBGIssue::STATE_OPEN);
                         $num_values++;
                     }
                     if ($this->hasValue('closed')) {
                         $num_values++;
                         if (isset($c)) {
                             $c->addWhere(TBGIssuesTable::STATE, TBGIssue::STATE_CLOSED);
                         } else {
                             $c = $crit->returnCriterion(TBGIssuesTable::STATE, TBGIssue::STATE_CLOSED);
                         }
                     }
                     if (isset($c)) {
                         if (count($values) == $num_values) {
                             return $c;
                         } else {
                             $crit->addWhere($c);
                         }
                     }
                 }
                 $dbname = TBGIssuesTable::getTable()->getB2DBName();
                 foreach ($values as $value) {
                     $operator = $this['operator'];
                     $or = true;
                     if ($filter_key == 'status' && in_array($value, array('open', 'closed'))) {
                         continue;
                     } else {
                         $field = $dbname . '.' . $filter_key;
                         if ($operator == '!=' || in_array($filter_key, array('posted', 'last_updated'))) {
                             $or = false;
                         }
                     }
                     if ($ctn === null) {
                         $ctn = $crit->returnCriterion($field, $value, urldecode($operator));
                     } elseif ($or) {
                         $ctn->addOr($field, $value, urldecode($operator));
                     } else {
                         $ctn->addWhere($field, $value, urldecode($operator));
                     }
                 }
                 return $ctn;
             }
         } elseif (TBGCustomDatatype::doesKeyExist($filter_key)) {
             $customdatatype = TBGCustomDatatype::getByKey($filter_key);
             if (in_array($this->getFilterType(), TBGCustomDatatype::getInternalChoiceFieldsAsArray())) {
                 $tbl = clone TBGIssueCustomFieldsTable::getTable();
                 $crit->addJoin($tbl, TBGIssueCustomFieldsTable::ISSUE_ID, TBGIssuesTable::ID, array(array($tbl->getB2DBAlias() . '.customfields_id', $customdatatype->getID()), array($tbl->getB2DBAlias() . '.customfieldoption_id', $this->getValues())), \b2db\Criteria::DB_INNER_JOIN);
                 return null;
             } else {
                 foreach ($this->getValues() as $value) {
                     if ($customdatatype->hasCustomOptions()) {
                         if ($ctn === null) {
                             $ctn = $crit->returnCriterion(TBGIssueCustomFieldsTable::CUSTOMFIELDS_ID, $customdatatype->getID());
                             $ctn->addWhere(TBGIssueCustomFieldsTable::CUSTOMFIELDOPTION_ID, $value, $this['operator']);
                         } else {
                             $ctn->addOr(TBGIssueCustomFieldsTable::CUSTOMFIELDOPTION_ID, $value, $this['operator']);
                         }
                     } else {
                         if ($ctn === null) {
                             $ctn = $crit->returnCriterion(TBGIssueCustomFieldsTable::CUSTOMFIELDS_ID, $customdatatype->getID());
                             $ctn->addWhere(TBGIssueCustomFieldsTable::OPTION_VALUE, $value, $this['operator']);
                         } else {
                             $ctn->addOr(TBGIssueCustomFieldsTable::OPTION_VALUE, $value, $this['operator']);
                         }
                     }
                 }
                 return $ctn;
             }
         }
     }
 }
Example #26
0
 public static function populateBreadcrumbs()
 {
     $childbreadcrumbs = array();
     if (self::$_selected_project instanceof TBGProject) {
         $t = self::$_selected_project;
         $hierarchy_breadcrumbs = array();
         $projects_processed = array();
         while ($t instanceof TBGProject) {
             if (array_key_exists($t->getKey(), $projects_processed)) {
                 // We have a cyclic dependency! Oh no!
                 // If this happens, throw an exception
                 throw new Exception(TBGContext::geti18n()->__('A loop has been found in the project heirarchy. Go to project configuration, and alter the subproject setting for this project so that this project is not a subproject of one which is a subproject of this one.'));
                 continue;
             } else {
                 $all_projects = array_merge(TBGProject::getAllRootProjects(true), TBGProject::getAllRootProjects(false));
                 // If this is a root project, display a list of other root projects, then t is null
                 if (!$t->hasParent() && count($all_projects) > 1) {
                     $itemsubmenulinks = array();
                     foreach ($all_projects as $child) {
                         if (!$child->hasAccess()) {
                             continue;
                         }
                         $itemsubmenulinks[] = array('url' => self::getRouting()->generate('project_dashboard', array('project_key' => $child->getKey())), 'title' => $child->getName());
                     }
                     $hierarchy_breadcrumbs[] = array($t, $itemsubmenulinks);
                     $projects_processed[$t->getKey()] = $t;
                     $t = null;
                     continue;
                 } elseif (!$t->hasParent()) {
                     $hierarchy_breadcrumbs[] = array($t, null);
                     $projects_processed[$t->getKey()] = $t;
                     $t = null;
                     continue;
                 } else {
                     // What we want to do here is to build a list of the children of the parent unless we are the only one
                     $parent = $t->getParent();
                     $children = $parent->getChildren();
                     $itemsubmenulinks = null;
                     if ($parent->hasChildren() && count($children) > 1) {
                         $itemsubmenulinks = array();
                         foreach ($children as $child) {
                             if (!$child->hasAccess()) {
                                 continue;
                             }
                             $itemsubmenulinks[] = array('url' => self::getRouting()->generate('project_dashboard', array('project_key' => $child->getKey())), 'title' => $child->getName());
                         }
                     }
                     $hierarchy_breadcrumbs[] = array($t, $itemsubmenulinks);
                     $projects_processed[$t->getKey()] = $t;
                     $t = $parent;
                     continue;
                 }
             }
         }
         $clientsubmenulinks = null;
         if (self::$_selected_project->hasClient()) {
             $clientsubmenulinks = array();
             foreach (TBGClient::getAll() as $client) {
                 if ($client->hasAccess()) {
                     $clientsubmenulinks[] = array('url' => self::getRouting()->generate('client_dashboard', array('client_id' => $client->getID())), 'title' => $client->getName());
                 }
             }
             self::setCurrentClient(self::$_selected_project->getClient());
         }
         if (mb_strtolower(TBGSettings::getTBGname()) != mb_strtolower(self::$_selected_project->getName()) || self::isClientContext()) {
             self::getResponse()->addBreadcrumb(TBGSettings::getTBGName(), self::getRouting()->generate('home'));
             if (self::isClientContext()) {
                 self::getResponse()->addBreadcrumb(self::getCurrentClient()->getName(), self::getRouting()->generate('client_dashboard', array('client_id' => self::getCurrentClient()->getID())), $clientsubmenulinks);
             }
         }
         // Add root breadcrumb first, so reverse order
         $hierarchy_breadcrumbs = array_reverse($hierarchy_breadcrumbs);
         foreach ($hierarchy_breadcrumbs as $breadcrumb) {
             $class = null;
             if ($breadcrumb[0]->getKey() == self::getCurrentProject()->getKey()) {
                 $class = 'selected_project';
             }
             self::getResponse()->addBreadcrumb($breadcrumb[0]->getName(), self::getRouting()->generate('project_dashboard', array('project_key' => $breadcrumb[0]->getKey())), $breadcrumb[1], $class);
         }
     } else {
         self::getResponse()->addBreadcrumb(TBGSettings::getTBGName(), self::getRouting()->generate('home'));
     }
 }
 public function _postSave($is_new)
 {
     if ($is_new) {
         self::$_num_projects = null;
         self::$_projects = null;
         TBGContext::setPermission("canseeproject", $this->getID(), "core", TBGContext::getUser()->getID(), 0, 0, true);
         TBGContext::setPermission("canseeprojecthierarchy", $this->getID(), "core", TBGContext::getUser()->getID(), 0, 0, true);
         TBGContext::setPermission("canmanageproject", $this->getID(), "core", TBGContext::getUser()->getID(), 0, 0, true);
         TBGContext::setPermission("page_project_allpages_access", $this->getID(), "core", TBGContext::getUser()->getID(), 0, 0, true);
         TBGContext::setPermission("canvoteforissues", $this->getID(), "core", TBGContext::getUser()->getID(), 0, 0, true);
         TBGContext::setPermission("canlockandeditlockedissues", $this->getID(), "core", TBGContext::getUser()->getID(), 0, 0, true);
         TBGContext::setPermission("cancreateandeditissues", $this->getID(), "core", TBGContext::getUser()->getID(), 0, 0, true);
         TBGContext::setPermission("caneditissue", $this->getID(), "core", TBGContext::getUser()->getID(), 0, 0, true);
         TBGContext::setPermission("caneditissuecustomfields", $this->getID(), "core", TBGContext::getUser()->getID(), 0, 0, true);
         TBGContext::setPermission("canaddextrainformationtoissues", $this->getID(), "core", TBGContext::getUser()->getID(), 0, 0, true);
         TBGContext::setPermission("canpostseeandeditallcomments", $this->getID(), "core", TBGContext::getUser()->getID(), 0, 0, true);
         TBGEvent::createNew('core', 'TBGProject::createNew', $this)->trigger();
     }
     if ($this->_dodelete) {
         TBGIssuesTable::getTable()->markIssuesDeletedByProjectID($this->getID());
         $this->_dodelete = false;
     }
 }
            include_component('project/overview', array('project' => $aProject));
            ?>
</li>
						<?php 
        }
        ?>
						</ul>
						<div class="header" style="margin: 5px 5px 5px 0;"><?php 
        echo __('Milestones / sprints');
        ?>
</div>
						<?php 
        $milestone_cc = 0;
        ?>
						<?php 
        foreach (TBGProject::getAllByClientID($client->getID()) as $project) {
            ?>
							<?php 
            foreach ($project->getUpcomingMilestonesAndSprints() as $milestone) {
                ?>
								<?php 
                if ($milestone->isScheduled()) {
                    ?>
									<?php 
                    include_template('main/milestonedashboardbox', array('milestone' => $milestone));
                    ?>
									<?php 
                    $milestone_cc++;
                    ?>
								<?php 
                }
 public function runDoImportCSV(TBGRequest $request)
 {
     try {
         if ($request->getParameter('csv_data') == '') {
             throw new Exception(TBGContext::getI18n()->__('No data supplied to import'));
         }
         // Split data into individual lines
         $data = str_replace("\r\n", "\n", $request->getParameter('csv_data'));
         $data = explode("\n", $data);
         if (count($data) <= 1) {
             throw new Exception(TBGContext::getI18n()->__('Insufficient data to import'));
         }
         $headerrow = $data[0];
         $headerrow = html_entity_decode($headerrow, ENT_QUOTES);
         $headerrow = explode(',', $headerrow);
         $headerrow2 = array();
         for ($i = 0; $i != count($headerrow); $i++) {
             $headerrow2[$i] = trim($headerrow[$i], '" ');
         }
         $errors = array();
         // inspect for correct rows
         switch ($request->getParameter('type')) {
             case 'clients':
                 $namecol = null;
                 $emailcol = null;
                 $telephonecol = null;
                 $faxcol = null;
                 $websitecol = null;
                 for ($i = 0; $i != count($headerrow2); $i++) {
                     if ($headerrow2[$i] == 'name') {
                         $namecol = $i;
                     } elseif ($headerrow2[$i] == 'email') {
                         $emailcol = $i;
                     } elseif ($headerrow2[$i] == 'telephone') {
                         $telephonecol = $i;
                     } elseif ($headerrow2[$i] == 'fax') {
                         $faxcol = $i;
                     } elseif ($headerrow2[$i] == 'website') {
                         $websitecol = $i;
                     }
                 }
                 $rowlength = count($headerrow2);
                 if ($namecol === null) {
                     $errors[] = TBGContext::getI18n()->__('Required column \'%col%\' not found in header row', array('%col%' => 'name'));
                 }
                 break;
             case 'projects':
                 $namecol = null;
                 $prefix = null;
                 $scrum = null;
                 $owner = null;
                 $owner_type = null;
                 $lead = null;
                 $lead_type = null;
                 $qa = null;
                 $qa_type = null;
                 $descr = null;
                 $doc_url = null;
                 $freelance = null;
                 $en_builds = null;
                 $en_comps = null;
                 $en_editions = null;
                 $workflow_id = null;
                 $client = null;
                 $show_summary = null;
                 $summary_type = null;
                 $issuetype_scheme = null;
                 $allow_reporting = null;
                 $autoassign = null;
                 for ($i = 0; $i != count($headerrow2); $i++) {
                     if ($headerrow2[$i] == 'name') {
                         $namecol = $i;
                     } elseif ($headerrow2[$i] == 'prefix') {
                         $prefix = $i;
                     } elseif ($headerrow2[$i] == 'scrum') {
                         $scrum = $i;
                     } elseif ($headerrow2[$i] == 'owner') {
                         $owner = $i;
                     } elseif ($headerrow2[$i] == 'owner_type') {
                         $owner_type = $i;
                     } elseif ($headerrow2[$i] == 'lead') {
                         $lead = $i;
                     } elseif ($headerrow2[$i] == 'lead_type') {
                         $lead_type = $i;
                     } elseif ($headerrow2[$i] == 'qa') {
                         $qa = $i;
                     } elseif ($headerrow2[$i] == 'qa_type') {
                         $qa_type = $i;
                     } elseif ($headerrow2[$i] == 'descr') {
                         $descr = $i;
                     } elseif ($headerrow2[$i] == 'doc_url') {
                         $doc_url = $i;
                     } elseif ($headerrow2[$i] == 'freelance') {
                         $freelance = $i;
                     } elseif ($headerrow2[$i] == 'en_builds') {
                         $en_builds = $i;
                     } elseif ($headerrow2[$i] == 'en_comps') {
                         $en_comps = $i;
                     } elseif ($headerrow2[$i] == 'en_editions') {
                         $en_editions = $i;
                     } elseif ($headerrow2[$i] == 'workflow_id') {
                         $workflow_id = $i;
                     } elseif ($headerrow2[$i] == 'client') {
                         $client = $i;
                     } elseif ($headerrow2[$i] == 'show_summary') {
                         $show_summary = $i;
                     } elseif ($headerrow2[$i] == 'summary_type') {
                         $summary_type = $i;
                     } elseif ($headerrow2[$i] == 'issuetype_scheme') {
                         $issuetype_scheme = $i;
                     } elseif ($headerrow2[$i] == 'allow_reporting') {
                         $allow_reporting = $i;
                     } elseif ($headerrow2[$i] == 'autoassign') {
                         $autoassign = $i;
                     }
                 }
                 $rowlength = count($headerrow2);
                 if ($namecol === null) {
                     $errors[] = TBGContext::getI18n()->__('Required column \'%col%\' not found in header row', array('%col%' => 'name'));
                 }
                 break;
             case 'issues':
                 $title = null;
                 $project = null;
                 $descr = null;
                 $repro = null;
                 $state = null;
                 $status = null;
                 $posted_by = null;
                 $owner = null;
                 $owner_type = null;
                 $assigned = null;
                 $assigned_type = null;
                 $resolution = null;
                 $issue_type = null;
                 $priority = null;
                 $category = null;
                 $severity = null;
                 $reproducability = null;
                 $votes = null;
                 $percentage = null;
                 $blocking = null;
                 $milestone = null;
                 for ($i = 0; $i != count($headerrow2); $i++) {
                     if ($headerrow2[$i] == 'title') {
                         $title = $i;
                     } elseif ($headerrow2[$i] == 'project') {
                         $project = $i;
                     } elseif ($headerrow2[$i] == 'assigned') {
                         $assigned = $i;
                     } elseif ($headerrow2[$i] == 'repro') {
                         $repro = $i;
                     } elseif ($headerrow2[$i] == 'state') {
                         $state = $i;
                     } elseif ($headerrow2[$i] == 'status') {
                         $status = $i;
                     } elseif ($headerrow2[$i] == 'posted_by') {
                         $posted_by = $i;
                     } elseif ($headerrow2[$i] == 'owner') {
                         $owner = $i;
                     } elseif ($headerrow2[$i] == 'owner_type') {
                         $owner_type = $i;
                     } elseif ($headerrow2[$i] == 'assigned') {
                         $assigned = $i;
                     } elseif ($headerrow2[$i] == 'assigned_type') {
                         $assigned_type = $i;
                     } elseif ($headerrow2[$i] == 'resolution') {
                         $resolution = $i;
                     } elseif ($headerrow2[$i] == 'issue_type') {
                         $issue_type = $i;
                     } elseif ($headerrow2[$i] == 'priority') {
                         $priority = $i;
                     } elseif ($headerrow2[$i] == 'category') {
                         $category = $i;
                     } elseif ($headerrow2[$i] == 'severity') {
                         $severity = $i;
                     } elseif ($headerrow2[$i] == 'reproducability') {
                         $reproducability = $i;
                     } elseif ($headerrow2[$i] == 'votes') {
                         $votes = $i;
                     } elseif ($headerrow2[$i] == 'percentage') {
                         $percentage = $i;
                     } elseif ($headerrow2[$i] == 'blocking') {
                         $blocking = $i;
                     } elseif ($headerrow2[$i] == 'type') {
                         $issue_type = $i;
                     } elseif ($headerrow2[$i] == 'milestone') {
                         $milestone = $i;
                     }
                 }
                 $rowlength = count($headerrow2);
                 if ($title === null) {
                     $errors[] = TBGContext::getI18n()->__('Required column \'%col%\' not found in header row', array('%col%' => 'title'));
                 }
                 if ($project === null) {
                     $errors[] = TBGContext::getI18n()->__('Required column \'%col%\' not found in header row', array('%col%' => 'project'));
                 }
                 if ($issue_type === null) {
                     $errors[] = TBGContext::getI18n()->__('Required column \'%col%\' not found in header row', array('%col%' => 'issue_type'));
                 }
                 break;
             default:
                 throw new Exception('Sorry, this type is unimplemented');
                 break;
         }
         // Check if rows are long enough
         for ($i = 1; $i != count($data); $i++) {
             $activerow = $data[$i];
             $activerow = html_entity_decode($activerow, ENT_QUOTES);
             $activerow = explode(',', $activerow);
             if (count($activerow) != $rowlength) {
                 $errors[] = TBGContext::getI18n()->__('Row %row% does not have the same number of elements as the header row', array('%row%' => $i + 1));
             }
         }
         reset($data);
         // Check if fields are empty
         for ($i = 1; $i != count($data); $i++) {
             $activerow = $data[$i];
             $activerow = html_entity_decode($activerow, ENT_QUOTES);
             $activerow = explode(',', $activerow);
             for ($j = 0; $j != count($activerow); $j++) {
                 if ($activerow[$j] == '' || $activerow[$j] == '""') {
                     $errors[] = TBGContext::getI18n()->__('Row %row% column %col% has no value', array('%col%' => $j + 1, '%row%' => $i + 1));
                 }
             }
         }
         if (count($errors) == 0) {
             // Check if fields are valid
             switch ($request->getParameter('type')) {
                 case 'projects':
                     for ($i = 1; $i != count($data); $i++) {
                         $activerow = $data[$i];
                         $activerow = html_entity_decode($activerow, ENT_QUOTES);
                         $activerow = explode(',', $activerow);
                         // Check if project exists
                         $key = trim($activerow[$namecol], '" ');
                         $key = str_replace(' ', '', $key);
                         $key = strtolower($key);
                         $tmp = TBGProject::getByKey($key);
                         if ($tmp !== null) {
                             $errors[] = TBGContext::getI18n()->__('Row %row%: A project with this name already exists', array('%row%' => $i + 1));
                         }
                         // First off are booleans
                         $boolitems = array($scrum, $allow_reporting, $autoassign, $freelance, $en_builds, $en_comps, $en_editions, $show_summary);
                         foreach ($boolitems as $boolitem) {
                             if ($boolitem !== null && trim($activerow[$boolitem], '"') != 0 && trim($activerow[$boolitem], '"') != 1) {
                                 $errors[] = TBGContext::getI18n()->__('Row %row% column %col%: invalid value (must be 1/0)', array('%col%' => $boolitem + 1, '%row%' => $i + 1));
                             }
                         }
                         // Now identifiables
                         $identifiableitems = array(array($qa, $qa_type), array($lead, $lead_type), array($owner, $owner_type));
                         foreach ($identifiableitems as $identifiableitem) {
                             if (($identifiableitem[0] === null || $identifiableitem[1] === null) && !($identifiableitem[0] === null && $identifiableitem[1] === null)) {
                                 $errors[] = TBGContext::getI18n()->__('Row %row%: Both the type and item ID must be supplied for owner/lead/qa fields', array('%row%' => $i + 1));
                                 continue;
                             }
                             if ($identifiableitem[1] !== null && trim($activerow[$identifiableitem[1]], '"') != 1 && trim($activerow[$identifiableitem[1]], '"') != 2) {
                                 $errors[] = TBGContext::getI18n()->__('Row %row% column %col%: invalid value (must be 1 for a user or 2 for a team)', array('%col%' => $identifiableitem[1] + 1, '%row%' => $i + 1));
                             }
                             if ($identifiableitem[0] !== null && !is_numeric(trim($activerow[$identifiableitem[0]], '"'))) {
                                 $errors[] = TBGContext::getI18n()->__('Row %row% column %col%: invalid value (must be a number)', array('%col%' => $identifiableitem[0] + 1, '%row%' => $i + 1));
                             } elseif ($identifiableitem[0] !== null && is_numeric(trim($activerow[$identifiableitem[0]], '"'))) {
                                 // check if they exist
                                 switch (trim($activerow[$identifiableitem[1]], '"')) {
                                     case 1:
                                         try {
                                             TBGContext::factory()->TBGUser(trim($activerow[$identifiableitem[0]], '" '));
                                         } catch (Exception $e) {
                                             $errors[] = TBGContext::getI18n()->__('Row %row% column %col%: user does not exist', array('%col%' => $identifiableitem[0] + 1, '%row%' => $i + 1));
                                         }
                                         break;
                                     case 2:
                                         try {
                                             TBGContext::factory()->TBGTeam(trim($activerow[$identifiableitem[0]], '" '));
                                         } catch (Exception $e) {
                                             $errors[] = TBGContext::getI18n()->__('Row %row% column %col%: team does not exist', array('%col%' => $identifiableitem[0] + 1, '%row%' => $i + 1));
                                         }
                                         break;
                                 }
                             }
                         }
                         // Now check client exists
                         if ($client !== null) {
                             if (!is_numeric(trim($activerow[$client], '"'))) {
                                 $errors[] = TBGContext::getI18n()->__('Row %row% column %col%: invalid value (must be a number)', array('%col%' => $client + 1, '%row%' => $i + 1));
                             } else {
                                 try {
                                     TBGContext::factory()->TBGClient(trim($activerow[$client], '" '));
                                 } catch (Exception $e) {
                                     $errors[] = TBGContext::getI18n()->__('Row %row% column %col%: client does not exist', array('%col%' => $client + 1, '%row%' => $i + 1));
                                 }
                             }
                         }
                         // Now check if workflow exists
                         if ($workflow_id !== null) {
                             if (!is_numeric(trim($activerow[$workflow_id], '"'))) {
                                 $errors[] = TBGContext::getI18n()->__('Row %row% column %col%: invalid value (must be a number)', array('%col%' => $workflow_id + 1, '%row%' => $i + 1));
                             } else {
                                 try {
                                     TBGContext::factory()->TBGWorkflowScheme(trim($activerow[$workflow_id], '" '));
                                 } catch (Exception $e) {
                                     $errors[] = TBGContext::getI18n()->__('Row %row% column %col%: workflow scheme does not exist', array('%col%' => $workflow_id + 1, '%row%' => $i + 1));
                                 }
                             }
                         }
                         // Now check if issuetype scheme
                         if ($issuetype_scheme !== null) {
                             if (!is_numeric(trim($activerow[$issuetype_scheme], '"'))) {
                                 $errors[] = TBGContext::getI18n()->__('Row %row% column %col%: invalid value (must be a number)', array('%col%' => $issuetype_scheme + 1, '%row%' => $i + 1));
                             } else {
                                 try {
                                     TBGContext::factory()->TBGIssuetypeScheme(trim($activerow[$issuetype_scheme], '" '));
                                 } catch (Exception $e) {
                                     $errors[] = TBGContext::getI18n()->__('Row %row% column %col%: issuetype scheme does not exist', array('%col%' => $issuetype_scheme + 1, '%row%' => $i + 1));
                                 }
                             }
                         }
                         // Finally check if the summary type is valid. At this point, your error list has probably become so big it has eaten up all your available RAM...
                         if ($summary_type !== null) {
                             if (trim($activerow[$summary_type], '"') != 'issuetypes' && trim($activerow[$summary_type], '"') != 'milestones') {
                                 $errors[] = TBGContext::getI18n()->__('Row %row% column %col%: invalid value (must be \'issuetypes\' or \'milestones\')', array('%col%' => $summary_type + 1, '%row%' => $i + 1));
                             }
                         }
                     }
                     break;
                 case 'issues':
                     for ($i = 1; $i != count($data); $i++) {
                         $activerow = $data[$i];
                         $activerow = html_entity_decode($activerow, ENT_QUOTES);
                         $activerow = explode(',', $activerow);
                         // Check if project exists
                         try {
                             $prjtmp = TBGContext::factory()->TBGProject($activerow[$project]);
                         } catch (Exception $e) {
                             $errors[] = TBGContext::getI18n()->__('Row %row% column %col%: Project does not exist', array('%col%' => $project + 1, '%row%' => $i + 1));
                             break;
                         }
                         // First off are booleans
                         $boolitems = array($state, $blocking);
                         foreach ($boolitems as $boolitem) {
                             if ($boolitem !== null && trim($activerow[$boolitem], '"') != 0 && trim($activerow[$boolitem], '"') != 1) {
                                 $errors[] = TBGContext::getI18n()->__('Row %row% column %col%: invalid value (must be 1/0)', array('%col%' => $boolitem + 1, '%row%' => $i + 1));
                             }
                         }
                         // Now numerics
                         $numericitems = array($votes, $percentage);
                         foreach ($numericitems as $numericitem) {
                             if ($numericitem !== null && !is_numeric(trim($activerow[$numericitem], '"'))) {
                                 $errors[] = TBGContext::getI18n()->__('Row %row% column %col%: invalid value (must be a number)', array('%col%' => $numericitem + 1, '%row%' => $i + 1));
                             }
                         }
                         // Percentage must be 0-100
                         if ($numericitem !== null && (trim($activerow[$percentage], '"') < 0 || trim($activerow[$percentage], '"') > 100)) {
                             $errors[] = TBGContext::getI18n()->__('Row %row% column %col%: Percentage must be from 0 to 100 inclusive', array('%col%' => $percentage + 1, '%row%' => $i + 1));
                         }
                         // Now identifiables
                         $identifiableitems = array(array($owner, $owner_type), array($assigned, $assigned_type));
                         foreach ($identifiableitems as $identifiableitem) {
                             if (($identifiableitem[0] === null || $identifiableitem[1] === null) && !($identifiableitem[0] === null && $identifiableitem[1] === null)) {
                                 $errors[] = TBGContext::getI18n()->__('Row %row%: Both the type and item ID must be supplied for owner/lead/qa fields', array('%row%' => $i + 1));
                                 continue;
                             }
                             if ($identifiableitem[1] !== null && trim($activerow[$identifiableitem[1]], '"') != 1 && trim($activerow[$identifiableitem[1]], '"') != 2) {
                                 $errors[] = TBGContext::getI18n()->__('Row %row% column %col%: invalid value (must be 1 for a user or 2 for a team)', array('%col%' => $identifiableitem[1] + 1, '%row%' => $i + 1));
                             }
                             if ($identifiableitem[0] !== null && !is_numeric(trim($activerow[$identifiableitem[0]], '"'))) {
                                 $errors[] = TBGContext::getI18n()->__('Row %row% column %col%: invalid value (must be a number)', array('%col%' => $identifiableitem[0] + 1, '%row%' => $i + 1));
                             } elseif ($identifiableitem[0] !== null && is_numeric(trim($activerow[$identifiableitem[0]], '"'))) {
                                 // check if they exist
                                 switch (trim($activerow[$identifiableitem[1]], '"')) {
                                     case 1:
                                         try {
                                             TBGContext::factory()->TBGUser(trim($activerow[$identifiableitem[0]], '" '));
                                         } catch (Exception $e) {
                                             $errors[] = TBGContext::getI18n()->__('Row %row% column %col%: user does not exist', array('%col%' => $identifiableitem[0] + 1, '%row%' => $i + 1));
                                         }
                                         break;
                                     case 2:
                                         try {
                                             TBGContext::factory()->TBGTeam(trim($activerow[$identifiableitem[0]], '" '));
                                         } catch (Exception $e) {
                                             $errors[] = TBGContext::getI18n()->__('Row %row% column %col%: team does not exist', array('%col%' => $identifiableitem[0] + 1, '%row%' => $i + 1));
                                         }
                                         break;
                                 }
                             }
                         }
                         // Now check user exists for postedby
                         if ($posted_by !== null) {
                             if (!is_numeric(trim($activerow[$posted_by], '"'))) {
                                 $errors[] = TBGContext::getI18n()->__('Row %row% column %col%: invalid value (must be a number)', array('%col%' => $posted_by + 1, '%row%' => $i + 1));
                             } else {
                                 try {
                                     TBGContext::factory()->TBGUser(trim($activerow[$posted_by], '" '));
                                 } catch (Exception $e) {
                                     $errors[] = TBGContext::getI18n()->__('Row %row% column %col%: user does not exist', array('%col%' => $posted_by + 1, '%row%' => $i + 1));
                                 }
                             }
                         }
                         // Now check milestone exists and is valid
                         if ($milestone !== null) {
                             if (!is_numeric(trim($activerow[$milestone], '"'))) {
                                 $errors[] = TBGContext::getI18n()->__('Row %row% column %col%: invalid value (must be a number)', array('%col%' => $milestone + 1, '%row%' => $i + 1));
                             } else {
                                 try {
                                     $milestonetmp = TBGContext::factory()->TBGMilestone(trim($activerow[$milestone], '" '));
                                     if ($milestonetmp->getProject()->getID() != $activerow[$project]) {
                                         $errors[] = TBGContext::getI18n()->__('Row %row% column %col%: milestone does not apply to the specified project', array('%col%' => $milestone + 1, '%row%' => $i + 1));
                                     }
                                 } catch (Exception $e) {
                                     $errors[] = TBGContext::getI18n()->__('Row %row% column %col%: milestone does not exist', array('%col%' => $milestone + 1, '%row%' => $i + 1));
                                 }
                             }
                         }
                         // status
                         if ($status !== null) {
                             if (!is_numeric(trim($activerow[$status], '"'))) {
                                 $errors[] = TBGContext::getI18n()->__('Row %row% column %col%: invalid value (must be a number)', array('%col%' => $status + 1, '%row%' => $i + 1));
                             } else {
                                 try {
                                     TBGContext::factory()->TBGStatus(trim($activerow[$status], '" '));
                                 } catch (Exception $e) {
                                     $errors[] = TBGContext::getI18n()->__('Row %row% column %col%: status does not exist', array('%col%' => $status + 1, '%row%' => $i + 1));
                                 }
                             }
                         }
                         // resolution
                         if ($resolution !== null) {
                             if (!is_numeric(trim($activerow[$resolution], '"'))) {
                                 $errors[] = TBGContext::getI18n()->__('Row %row% column %col%: invalid value (must be a number)', array('%col%' => $resolution + 1, '%row%' => $i + 1));
                             } else {
                                 try {
                                     TBGContext::factory()->TBGResolution(trim($activerow[$resolution], '" '));
                                 } catch (Exception $e) {
                                     $errors[] = TBGContext::getI18n()->__('Row %row% column %col%: resolution does not exist', array('%col%' => $resolution + 1, '%row%' => $i + 1));
                                 }
                             }
                         }
                         // priority
                         if ($priority !== null) {
                             if (!is_numeric(trim($activerow[$priority], '"'))) {
                                 $errors[] = TBGContext::getI18n()->__('Row %row% column %col%: invalid value (must be a number)', array('%col%' => $priority + 1, '%row%' => $i + 1));
                             } else {
                                 try {
                                     TBGContext::factory()->TBGPriority(trim($activerow[$priority], '" '));
                                 } catch (Exception $e) {
                                     $errors[] = TBGContext::getI18n()->__('Row %row% column %col%: priority does not exist', array('%col%' => $priority + 1, '%row%' => $i + 1));
                                 }
                             }
                         }
                         // category
                         if ($category !== null) {
                             if (!is_numeric(trim($activerow[$category], '"'))) {
                                 $errors[] = TBGContext::getI18n()->__('Row %row% column %col%: invalid value (must be a number)', array('%col%' => $category + 1, '%row%' => $i + 1));
                             } else {
                                 try {
                                     TBGContext::factory()->TBGCategory(trim($activerow[$category], '" '));
                                 } catch (Exception $e) {
                                     $errors[] = TBGContext::getI18n()->__('Row %row% column %col%: category does not exist', array('%col%' => $category + 1, '%row%' => $i + 1));
                                 }
                             }
                         }
                         // severity
                         if ($severity !== null) {
                             if (!is_numeric(trim($activerow[$severity], '"'))) {
                                 $errors[] = TBGContext::getI18n()->__('Row %row% column %col%: invalid value (must be a number)', array('%col%' => $severity + 1, '%row%' => $i + 1));
                             } else {
                                 try {
                                     TBGContext::factory()->TBGSeverity(trim($activerow[$severity], '" '));
                                 } catch (Exception $e) {
                                     $errors[] = TBGContext::getI18n()->__('Row %row% column %col%: severity does not exist', array('%col%' => $severity + 1, '%row%' => $i + 1));
                                 }
                             }
                         }
                         // reproducability
                         if ($reproducability !== null) {
                             if (!is_numeric(trim($activerow[$reproducability], '"'))) {
                                 $errors[] = TBGContext::getI18n()->__('Row %row% column %col%: invalid value (must be a number)', array('%col%' => $reproducability + 1, '%row%' => $i + 1));
                             } else {
                                 try {
                                     TBGContext::factory()->TBGReproducability(trim($activerow[$reproducability], '" '));
                                 } catch (Exception $e) {
                                     $errors[] = TBGContext::getI18n()->__('Row %row% column %col%: reproducability does not exist', array('%col%' => $reproducability + 1, '%row%' => $i + 1));
                                 }
                             }
                         }
                         // type
                         if ($issue_type !== null) {
                             if (!is_numeric(trim($activerow[$issue_type], '"'))) {
                                 $errors[] = TBGContext::getI18n()->__('Row %row% column %col%: invalid value (must be a number)', array('%col%' => $issue_type + 1, '%row%' => $i + 1));
                             } else {
                                 try {
                                     $typetmp = TBGContext::factory()->TBGIssuetype(trim($activerow[$issue_type], '" '));
                                     if (!$prjtmp->getIssuetypeScheme()->isSchemeAssociatedWithIssuetype($typetmp)) {
                                         $errors[] = TBGContext::getI18n()->__('Row %row% column %col%: this project does not support issues of this type (%type%)', array('%type%' => $typetmp->getName(), '%col%' => $issue_type + 1, '%row%' => $i + 1));
                                     }
                                 } catch (Exception $e) {
                                     $errors[] = TBGContext::getI18n()->__('Row %row% column %col%: issue type does not exist', array('%col%' => $issue_type + 1, '%row%' => $i + 1));
                                 }
                             }
                         }
                     }
                     break;
             }
         }
         // Handle errors
         if (count($errors) != 0) {
             $errordiv = '<ul>';
             foreach ($errors as $error) {
                 $errordiv .= '<li>' . $error . '</li>';
             }
             $errordiv .= '</ul>';
             $this->getResponse()->setHttpStatus(400);
             return $this->renderJSON(array('failed' => true, 'errordetail' => $errordiv, 'error' => TBGContext::getI18n()->__('Errors occured while importing, see the error list in the import screen for further details')));
         }
     } catch (Exception $e) {
         $this->getResponse()->setHttpStatus(400);
         return $this->renderJSON(array('failed' => true, 'errordetail' => $e->getMessage(), 'error' => $e->getMessage()));
     }
     if ($request->getParameter('csv_dry_run')) {
         return $this->renderJSON(array('failed' => false, 'message' => TBGContext::getI18n()->__('Dry-run successful, you can now uncheck the dry-run box and import your data.')));
     } else {
         switch ($request->getParameter('type')) {
             case 'clients':
                 for ($i = 1; $i != count($data); $i++) {
                     try {
                         $activerow = $data[$i];
                         $activerow = html_entity_decode($activerow, ENT_QUOTES);
                         $activerow = explode(',', $activerow);
                         $client = new TBGClient();
                         $client->setName(trim($activerow[$namecol], '" '));
                         if ($emailcol !== null) {
                             $client->setEmail(trim($activerow[$emailcol], '" '));
                         }
                         if ($websitecol !== null) {
                             $client->setWebsite(trim($activerow[$websitecol], '" '));
                         }
                         if ($faxcol !== null) {
                             $client->setFax(trim($activerow[$faxcol], '" '));
                         }
                         if ($telephonecol !== null) {
                             $client->setTelephone(trim($activerow[$telephonecol], '" '));
                         }
                         $client->save();
                     } catch (Exception $e) {
                         $errors[] = TBGContext::getI18n()->__('Row %row% failed: %err%', array('%row%' => $i + 1, '%err%' => $e->getMessage()));
                     }
                 }
                 break;
             case 'projects':
                 for ($i = 1; $i != count($data); $i++) {
                     try {
                         $activerow = $data[$i];
                         $activerow = html_entity_decode($activerow, ENT_QUOTES);
                         $activerow = explode(',', $activerow);
                         $project = new TBGProject();
                         $project->setName(trim($activerow[$namecol], '" '));
                         if ($prefix !== null) {
                             $project->setPrefix(trim($activerow[$prefix], '" '));
                             $project->setUsePrefix(true);
                         }
                         if ($scrum !== null) {
                             if (trim($activerow[$websitecol], '"') == '1') {
                                 $project->setUseScrum(true);
                             }
                         }
                         if ($owner !== null && $owner_type !== null) {
                             switch (trim($activerow[$owner_type], '"')) {
                                 case TBGIdentifiableClass::TYPE_USER:
                                     $user = new TBGUser(trim($activerow[$owner], '" '));
                                     $project->setOwner($user);
                                     break;
                                 case TBGIdentifiableClass::TYPE_TEAM:
                                     $team = new TBGTeam(trim($activerow[$owner], '" '));
                                     $project->setOwner($team);
                                     break;
                             }
                         }
                         if ($lead !== null && $lead_type !== null) {
                             switch (trim($activerow[$lead_type], '"')) {
                                 case TBGIdentifiableClass::TYPE_USER:
                                     $user = new TBGUser(trim($activerow[$lead], '" '));
                                     $project->setLeader($user);
                                     break;
                                 case TBGIdentifiableClass::TYPE_TEAM:
                                     $team = new TBGTeam(trim($activerow[$lead], '" '));
                                     $project->setLeader($team);
                                     break;
                             }
                         }
                         if ($qa !== null && $qa_type !== null) {
                             switch (trim($activerow[$qa_type], '"')) {
                                 case TBGIdentifiableClass::TYPE_USER:
                                     $user = new TBGUser(trim($activerow[$qa], '" '));
                                     $project->setQaResponsible($user);
                                     break;
                                 case TBGIdentifiableClass::TYPE_TEAM:
                                     $team = new TBGTeam(trim($activerow[$qa], '" '));
                                     $project->setQaResponsible($team);
                                     break;
                             }
                         }
                         if ($descr !== null) {
                             $project->setDescription(trim($activerow[$descr], '" '));
                         }
                         if ($doc_url !== null) {
                             $project->setDocumentationUrl(trim($activerow[$doc_url], '" '));
                         }
                         if ($freelance !== null) {
                             if (trim($activerow[$freelance], '"') == '1') {
                                 $project->setChangeIssuesWithoutWorkingOnThem(true);
                             }
                         }
                         if ($en_builds !== null) {
                             if (trim($activerow[$en_builds], '"') == '1') {
                                 $project->setBuildsEnabled(true);
                             }
                         }
                         if ($en_comps !== null) {
                             if (trim($activerow[$en_comps], '"') == '1') {
                                 $project->setComponentsEnabled(true);
                             }
                         }
                         if ($en_editions !== null) {
                             if (trim($activerow[$en_editions], '"') == '1') {
                                 $project->setEditionsEnabled(true);
                             }
                         }
                         if ($workflow_id !== null) {
                             $workflow = TBGContext::factory()->TBGWorkflowScheme(trim($activerow[$workflow_id], '" '));
                             $project->setWorkflowScheme($workflow);
                         }
                         if ($client !== null) {
                             $client_object = TBGContext::factory()->TBGWorkflowScheme(trim($activerow[$client], '" '));
                             $project->setClient($client_object);
                         }
                         if ($show_summary !== null) {
                             if (trim($activerow[$show_summary], '"') == '1') {
                                 $project->setFrontpageSummaryVisibility(true);
                             }
                         }
                         if ($summary_type !== null) {
                             $project->setFrontpageSummaryType(trim($activerow[$summary_type], '" '));
                         }
                         if ($issuetype_scheme !== null) {
                             $project->setIssuetypeScheme(TBGContext::factory()->TBGIssuetypeScheme(trim($activerow[$issuetype_scheme], '"')));
                         }
                         if ($allow_reporting !== null) {
                             $project->setLocked(trim($activerow[$allow_reporting], '" '));
                         }
                         if ($autoassign !== null) {
                             $project->setAutoassign(trim($activerow[$autoassign], '" '));
                         }
                         $project->save();
                     } catch (Exception $e) {
                         $errors[] = TBGContext::getI18n()->__('Row %row% failed: %err%', array('%row%' => $i + 1, '%err%' => $e->getMessage()));
                     }
                 }
                 break;
             case 'issues':
                 for ($i = 1; $i != count($data); $i++) {
                     try {
                         $activerow = $data[$i];
                         $activerow = html_entity_decode($activerow, ENT_QUOTES);
                         $activerow = explode(',', $activerow);
                         $issue = new TBGIssue();
                         $issue->setTitle(trim($activerow[$title], '" '));
                         $issue->setProject(trim($activerow[$project], '" '));
                         $issue->setIssuetype(trim($activerow[$issue_type], '" '));
                         if ($issue_type !== null) {
                             $issue->setIssuetype(trim($activerow[$issue_type], '" '));
                         }
                         if ($descr !== null) {
                             $issue->setDescription(trim($activerow[$descr], '" '));
                         }
                         if ($repro !== null) {
                             $issue->setReproduction(trim($activerow[$repro], '" '));
                         }
                         if ($state !== null) {
                             $issue->setState(trim($activerow[$state], '" '));
                         }
                         if ($status !== null) {
                             $issue->setStatus(trim($activerow[$status], '" '));
                         }
                         if ($posted_by !== null) {
                             $issue->setPostedBy(TBGContext::factory()->TBGUser(trim($activerow[$posted_by], '"')));
                         }
                         if ($owner !== null && $owner_type !== null) {
                             switch (trim($activerow[$owner_type], '"')) {
                                 case TBGIdentifiableClass::TYPE_USER:
                                     $user = new TBGUser(trim($activerow[$owner], '" '));
                                     $issue->setOwner($user);
                                     break;
                                 case TBGIdentifiableClass::TYPE_TEAM:
                                     $team = new TBGTeam(trim($activerow[$owner], '" '));
                                     $issue->setOwner($team);
                                     break;
                             }
                         }
                         if ($assigned !== null && $assigned_type !== null) {
                             switch (trim($activerow[$assigned_type], '"')) {
                                 case TBGIdentifiableClass::TYPE_USER:
                                     $user = new TBGUser(trim($activerow[$assigned], '" '));
                                     $issue->setAssignee($user);
                                     break;
                                 case TBGIdentifiableClass::TYPE_TEAM:
                                     $team = new TBGTeam(trim($activerow[$assigned], '" '));
                                     $issue->setAssignee($team);
                                     break;
                             }
                         }
                         if ($resolution !== null) {
                             $issue->setResolution(trim($activerow[$resolution], '" '));
                         }
                         if ($priority !== null) {
                             $issue->setPriority(trim($activerow[$priority], '" '));
                         }
                         if ($category !== null) {
                             $issue->setCategory(trim($activerow[$category], '" '));
                         }
                         if ($blocking !== null) {
                             $issue->setBlocking(trim($activerow[$blocking], '" '));
                         }
                         if ($severity !== null) {
                             $issue->setSeverity(trim($activerow[$severity], '" '));
                         }
                         if ($reproducability !== null) {
                             $issue->setReproducability(trim($activerow[$reproducability], '" '));
                         }
                         if ($votes !== null) {
                             $issue->setVotes(trim($activerow[$votes], '" '));
                         }
                         if ($percentage !== null) {
                             $issue->setPercentage(trim($activerow[$percentage], '" '));
                         }
                         if ($milestone !== null) {
                             $issue->setMilestone(trim($activerow[$milestone], '" '));
                         }
                         $issue->save();
                     } catch (Exception $e) {
                         $errors[] = TBGContext::getI18n()->__('Row %row% failed: %err%', array('%row%' => $i + 1, '%err%' => $e->getMessage()));
                     }
                 }
                 break;
         }
         // Handle errors
         if (count($errors) != 0) {
             $errordiv = '<ul>';
             foreach ($errors as $error) {
                 $errordiv .= '<li>' . $error . '</li>';
             }
             $errordiv .= '</ul>';
             $this->getResponse()->setHttpStatus(400);
             return $this->renderJSON(array('failed' => true, 'errordetail' => $errordiv, 'error' => TBGContext::getI18n()->__('Errors occured while importing, see the error list in the import screen for further details')));
         } else {
             return $this->renderJSON(array('failed' => false, 'message' => TBGContext::getI18n()->__('Successfully imported %num% rows!', array('%num%' => count($data) - 1))));
         }
     }
 }
 public function componentProjectInfo()
 {
     $this->valid_subproject_targets = TBGProject::getValidSubprojects($this->project);
 }