Ejemplo n.º 1
0
 public function add_ticket()
 {
     if (!Visitor::current()->group->can("add_ticket")) {
         show_403(__("Access Denied"), __("You do not have sufficient privileges to create tickets.", "progress"));
     }
     if (empty($_POST['title'])) {
         Flash::warning(__("Please provide a summary of the ticket in the form of a title.", "progress"));
     }
     if (empty($_POST['milestone_id'])) {
         Flash::warning(__("No milestone selected.", "progress"));
     }
     $milestone = new Milestone($_POST['milestone_id']);
     if ($milestone->no_results) {
         error(__("Error"), __("Invalid milestone.", "progress"));
     }
     if (Flash::exists()) {
         redirect($milestone->url());
     }
     $ticket = Ticket::add($_POST['title'], $_POST['description'], "new", $_POST['milestone_id'], $_POST['owner_id']);
     $files = array();
     foreach ($_FILES['attachment'] as $key => $val) {
         foreach ($val as $file => $attr) {
             $files[$file][$key] = $attr;
         }
     }
     foreach ($files as $attachment) {
         if ($attachment['error'] != 4) {
             $path = upload($attachment, null, "attachments");
             Attachment::add(basename($path), $path, "ticket", $ticket->id);
         }
     }
     $domain = parse_url(Config::current()->url, PHP_URL_HOST);
     if (!empty($ticket->owner->email) and Visitor::current()->id != $ticket->owner->id) {
         mail($ticket->owner->email, _f("Ticket #%d Created! (%s)", array($ticket->id, $ticket->title), "progress"), _f("%s has created the ticket \"%s\" and assigned the owner to you. Description:<br />\n<br />\n%s", array(oneof($ticket->user->full_name, $ticket->user->login), $ticket->title, $ticket->description)), "MIME-Version: 1.0\r\n" . "Content-type: text/html; charset=utf-8\r\n" . "From: no-reply@" . $domain);
     }
     Flash::notice(__("Ticket added.", "progress"), $ticket->url());
 }