Example #1
0
function tickets_my_tasks_dropdown()
{
    echo '<li class="header"><a href="' . get_url('tickets', 'index') . '">' . lang('tickets') . '</a></li>';
    if (ProjectTicket::canAdd(logged_user(), active_project())) {
        echo '<li><a href="' . get_url('tickets', 'add_ticket') . '">' . lang('add ticket') . '</a></li>';
    }
    // if
}
 /**
  * Add ticket
  *
  * @access public
  * @param void
  * @return null
  */
 function add_ticket()
 {
     $this->setTemplate('add_ticket');
     if (!ProjectTicket::canAdd(logged_user(), active_project())) {
         flash_error(lang('no access permissions'));
         $this->redirectToReferer(get_url('tickets'));
     }
     // if
     $ticket = new ProjectTicket();
     $ticket->setProjectId(active_project()->getId());
     $ticket_data = array_var($_POST, 'ticket');
     if (!is_array($ticket_data)) {
         $ticket_data = array('is_private' => config_option('default_private', false));
         // array
     }
     tpl_assign('ticket', $ticket);
     tpl_assign('ticket_data', $ticket_data);
     if (is_array(array_var($_POST, 'ticket'))) {
         try {
             $uploaded_files = ProjectFiles::handleHelperUploads(active_project());
         } catch (Exception $e) {
             $uploaded_files = null;
         }
         // try
         try {
             $ticket->setFromAttributes($ticket_data);
             $assigned_to = explode(':', array_var($ticket_data, 'assigned_to', ''));
             $ticket->setAssignedToCompanyId(array_var($assigned_to, 0, 0));
             $ticket->setAssignedToUserId(array_var($assigned_to, 1, 0));
             // Options are reserved only for members of owner company
             if (!logged_user()->isMemberOfOwnerCompany()) {
                 $ticket->setIsPrivate(false);
             }
             // if
             DB::beginWork();
             $ticket->save();
             if (is_array($uploaded_files)) {
                 foreach ($uploaded_files as $uploaded_file) {
                     $ticket->attachFile($uploaded_file);
                     $uploaded_file->setIsPrivate($ticket->isPrivate());
                     $uploaded_file->setIsVisible(true);
                     $uploaded_file->setExpirationTime(EMPTY_DATETIME);
                     $uploaded_file->save();
                 }
                 // if
             }
             // if
             ApplicationLogs::createLog($ticket, active_project(), ApplicationLogs::ACTION_ADD);
             DB::commit();
             // Try to send notifications but don't break submission in case of an error
             try {
                 if ($ticket->getAssignedToUserId()) {
                     $ticket_data['notify_user_' . $ticket->getAssignedToUserId()] = 'checked';
                 }
                 $notify_people = array();
                 $project_companies = active_project()->getCompanies();
                 foreach ($project_companies as $project_company) {
                     $company_users = $project_company->getUsersOnProject(active_project());
                     if (is_array($company_users)) {
                         foreach ($company_users as $company_user) {
                             if (array_var($ticket_data, 'notify_company_' . $project_company->getId()) == 'checked' || array_var($ticket_data, 'notify_user_' . $company_user->getId())) {
                                 $ticket->subscribeUser($company_user);
                                 // subscribe
                                 $notify_people[] = $company_user;
                             }
                             // if
                         }
                         // if
                     }
                     // if
                 }
                 // if
                 Notifier::ticket($ticket, $notify_people, 'new_ticket', $ticket->getCreatedBy());
             } catch (Exception $e) {
             }
             // try
             flash_success(lang('success add ticket', $ticket->getSummary()));
             $this->redirectTo('tickets');
             // Error...
         } catch (Exception $e) {
             DB::rollback();
             if (is_array($uploaded_files)) {
                 foreach ($uploaded_files as $uploaded_file) {
                     $uploaded_file->delete();
                 }
                 // foreach
             }
             // if
             $ticket->setNew(true);
             tpl_assign('error', $e);
         }
         // try
     }
     // if
 }
Example #3
0
<?php

$canEdit = $ticket->canEdit(logged_user());
// Set page title and set crumbs to index
$title = $canEdit ? 'edit ticket' : 'view ticket';
set_page_title(lang($title));
project_tabbed_navigation(PROJECT_TAB_TICKETS);
if (ProjectTicket::canAdd(logged_user(), active_project())) {
    add_page_action(lang('delete ticket'), $ticket->getDeleteUrl());
}
$crumbs = array(array(lang('tickets'), get_url('tickets')));
if ($ticket->isClosed()) {
    $crumbs[] = array(lang('closed tickets'), ProjectTickets::getIndexUrl(true));
}
$crumbs[] = array(lang($title));
project_crumbs($crumbs);
add_stylesheet_to_page('project/tickets.css');
add_stylesheet_to_page('application_logs.css');
if ($ticket->isPrivate()) {
    ?>
    <div class="private" title="<?php 
    echo lang('private ticket');
    ?>
"><span><?php 
    echo lang('private ticket');
    ?>
</span></div>
<?php 
}
// if
?>