Exemplo n.º 1
0
 private function runEditor($mode)
 {
     $this->useMarkdown = true;
     $lp = $this->app->linkProvider;
     switch ($mode) {
         case EditorMode::Create:
             $issue = new \Spit\Models\Issue();
             // TODO: allow different template for each tracker.
             $filename = "issue.txt";
             if (file_exists($filename)) {
                 $handle = fopen($filename, "r");
                 $contents = fread($handle, filesize($filename));
                 fclose($handle);
                 $issue->details = $contents;
             }
             if (!$this->userCanCreate()) {
                 return;
             }
             $lp->securityRedirect = $lp->forIssueIndex();
             break;
         case EditorMode::Update:
             $id = $this->getPathPart(2);
             $lp->securityRedirect = $lp->forIssue($id);
             $issueFields = new \Spit\IssueFields($this->app->project->name);
             $issue = $this->ds->getById($id, $this->app->project->id, $issueFields);
             if (!$this->userCanEdit($issue)) {
                 return;
             }
             break;
     }
     if ($this->isJsonGet()) {
         if (isset($_GET["tracker"])) {
             exit($this->getJson($this->getEditorFields($_GET["tracker"], $issue)));
         } else {
             if (isset($_GET["search"])) {
                 exit($this->getJson($this->search($_GET["search"])));
             }
         }
         exit;
     }
     $data["mode"] = $mode;
     $data["issue"] = $issue;
     $data["trackerSelect"] = $this->getTrackerSelect($issue->trackerId);
     if ($this->isPost()) {
         $diff = $this->applyFormValues($issue);
         $issueFields = new \Spit\IssueFields($this->app->project->name);
         // TODO: validation can only run if the user is an advanced editor,
         // since only title and description is only available for basic edit,
         // which is validated by the javascript.
         if ($this->userCanEditAdvanced()) {
             $validateResult = $issueFields->validate($issue, $issue->trackerId);
             if (count($validateResult->invalid) != 0) {
                 var_dump($validateResult);
                 exit;
             }
         }
         switch ($mode) {
             case EditorMode::Create:
                 // HACK: massive hack, hard coded database ids, ugh... this is very
                 // temporary and will definitely screw someone over. this must be
                 // corrected asap!!!
                 if (!$this->userCanEditAdvanced()) {
                     $issue->trackerId = 3;
                     // support
                     $issue->statusId = 1;
                     // new
                     $issue->priorityId = 2;
                     // normal
                 }
                 $this->insert($issue, $diff, $issueFields);
                 break;
             case EditorMode::Update:
                 if (count($diff) != 0) {
                     $this->update($issue, $diff, $issueFields);
                 }
                 break;
         }
         $query = isset($_GET["query"]) ? $_GET["query"] : null;
         header("Location: " . $this->app->linkProvider->forIssue($issue->id, $query));
         exit;
     }
     $title = $mode == EditorMode::Create ? T_("New Issue") : T_("Edit Issue");
     $this->showView("issues/editor", $title, $data);
 }