<%  if !@issue.blank? && User.current.allowed_to?(:view_helpdesk_tickets, @project) %>
<span id="cusomer_profile_and_issues">
    <div id="customer_profile">
      <div class="contextual">
        <%= link_to l(:button_update),
          {:controller => 'helpdesk_tickets',
          :action => 'edit',
          :issue_id => @issue},
          :remote => true if User.current.allowed_to?(:edit_helpdesk_tickets, @project) %>

       </div>
      <h3><%= l(:label_helpdesk_contact) %></h3>
      <% unless !(@show_form == "true") %>
        <%= form_for @helpdesk_ticket, :url => {:controller => 'helpdesk_tickets',
                                :action => 'update',
                               :issue_id => @issue},
                            :html => {:id => 'ticket_data_form',
                                      :method => :put} do |f| %>

        <% unless @helpdesk_ticket.new_record? %>
          <div class="contextual">
          <%= link_to image_tag('link_break.png'),
                                  {:controller => 'helpdesk_tickets', :action => 'destroy', :id => @helpdesk_ticket},
                                  :method => :delete,
                                  :data => {:confirm => l(:text_are_you_sure)},
                                  :title => l(:label_relation_delete) %>
          </div>
        <% end %>
        <p class="contact_auto_complete"><%= label_tag :helpdesk_ticket_contact_id,  l(:label_helpdesk_contact)%><br>
          <%= select_contact_tag('helpdesk_ticket[contact_id]', @helpdesk_ticket.customer, :is_select => Contact.visible.by_project(ContactsSetting.cross_project_contacts? ? nil : @project).count < 50, :include_blank => false, :add_contact => true, :display_field => @helpdesk_ticket.customer.blank?) %>
        </p>

        <p><%= label_tag :helpdesk_ticket_source,  l(:label_helpdesk_ticket_source)%><br>
          <%= f.select :source, helpdesk_tickets_source_for_select %></p>

        <p><%= f.text_field :ticket_date, :size => 12, :required => true, :value => @helpdesk_ticket.ticket_date.to_date, :label => l(:label_helpdesk_ticket_date) %> <%= f.text_field :ticket_time, :value => @helpdesk_ticket.ticket_date.to_s(:time), :size => 5 %><%= calendar_for('helpdesk_ticket_ticket_date') %> </p>

        <p>
          <%= label_tag :helpdesk_ticket_cc_address,  l(:label_helpdesk_cc_address) %><br>
          <% @cc_address = @helpdesk_ticket.cc_address.try(:split, ',') || [] %>
          <%= f.select :cc_address, options_for_select(@cc_address.map { |email|[email, email] }, @cc_address), {}, {:multiple => true } %>
          <br>
        </p>

        <%= submit_tag l(:button_update) %>
        <%= link_to l(:button_cancel), {}, :onclick => "$('#ticket_data_form').hide(); return false;" %>

        <% end %>

      <% end %>
      <span class="small-card">
        <%= render :partial => 'contacts/contact_card', :object => @issue.customer if @issue.customer %>
      </span>
    </div>

    <% if @issue.customer && (customer_issues = @issue.customer.all_tickets.preload(:status, :tracker, :helpdesk_ticket).visible.order_by_status.to_a).count - 1 > 0 %>
    <div id="customer_previous_issues">
      <div class="contextual">
        <%= link_to l(:label_helpdesk_all) + " (#{customer_issues.count})", {:controller => 'issues',
                 :action => 'index',
                 :set_filter => 1,
                 :f => [:customer, :status_id],
                 :v => {:customer => [@issue.customer.id]},
                 :op => {:customer => '=', :status_id => '*'}} %>
      </div>

      <h3><%= l(:label_helpdesk_contact_activity) %> </h3>

      <ul>
        <% (customer_issues.first(5)).each do |issue| %>
        <li title="<%= "#{issue.tracker} (#{issue.status})" if issue.tracker && issue.status %>" >
          <span class="icon <%= helpdesk_ticket_source_icon(issue.helpdesk_ticket) %>"></span>
          <span class="ticket-title <%= 'selected' if @issue == issue %>">
          <%= link_to_issue(issue, :truncate => 60, :project => (@project != issue.project), :tracker => false) %>
          </span>
          <span class="ticket-meta">
            <%= format_time(issue.created_on) %>
            <%= "- #{issue.assigned_to.name}" if issue.assigned_to %>
          </span>
         </li>
        <% end %>
      </ul>
    </div>
    <% end %>

  </span>
<% end %>
