<input type="hidden" name="<% $widget %>|update_cb" value="1">

<%perl>
my $rightText = $m->scomp( '/widgets/profile/imageSubmit.mc',
  formName => "theForm",
  callback => $widget . "|trail_cb",
  image    => "view_trail_teal"
) . '&nbsp;';

$rightText .= $m->scomp( '/widgets/profile/imageSubmit.mc',
  formName => "theForm",
  callback => $widget . "|notes_cb",
  image    => %{ $media->get_notes } ? 'note_fill' : "note",
  useGlobalImage => 1,
  value    => 'edit'
);

$m->comp("/widgets/wrappers/sharky/table_top.mc",
         caption => "Information",
         number  => $num++,
         id        => 'mediainfo',
         rightText => $rightText

);

</%perl>

<table border="0" width="578" cellpadding="0" cellspacing="0">
  <tr>
  <td class="medHeader"><img src="/media/images/spacer.gif" height="18" width="1" /></td>
  <td width="<% $infoIndent %>" align="right" class="medHeader"><span class="label"><%$lang->maketext('ID')%>:&nbsp;</span></td>
  <td width="470">&nbsp;<% $id %></td>
  </tr>
  <tr>
  <td bgcolor="white"><img src="/media/images/spacer.gif" width="1" height="1" /></td>
  </tr>
  <tr>
  <td class="medHeader"><img src="/media/images/spacer.gif" height="18" width="1" /></td>
  <td width="<% $infoIndent %>" align="right" class="medHeader"><span class="label"><%$lang->maketext('Media Type Element')%>:&nbsp;</span></td>
  <td width="470">&nbsp;<% $media->get_element_name() %></td>
  </tr>
  <tr>
  <td bgcolor="white"><img src="/media/images/spacer.gif" width="1" height="1" /></td>
  </tr>
  <tr>
  <td class="medHeader"><img src="/media/images/spacer.gif" height="18" width="1" /></td>
  <td width="<% $infoIndent %>" align="right" class="medHeader"><span class="label"><% $lang->maketext('Current Version') %>:&nbsp;</span></td>
  <td width="470">&nbsp;<% $media->get_current_version() %></td>
  </tr>
  <tr>
  <td bgcolor="white"><img src="/media/images/spacer.gif" width="1" height="1" /></td>
  </tr>
  <tr>
  <td class="medHeader"><img src="/media/images/spacer.gif" height="18" width="1" /></td>
  <td width="<% $infoIndent %>" align="right" class="medHeader"><span class="label"><% $lang->maketext('Published Version') %>:&nbsp;</span></td>
  <td width="470">&nbsp;<% $media->get_published_version || '' %></td>
  </tr>
  <tr>
  <td bgcolor="white"><img src="/media/images/spacer.gif" width="1" height="1" /></td>
  </tr>
  <tr>
  <td class="medHeader"><img src="/media/images/spacer.gif" height="18" width="1" /></td>
  <td width="<% $infoIndent %>" align="right" class="medHeader"><span class="label"><% $lang->maketext('First Published') %>:&nbsp;</span></td>
  <td width="470">&nbsp;<% $media->get_first_publish_date || '' %></td>
  </tr>
  <tr>
  <td bgcolor="white"><img src="/media/images/spacer.gif" width="1" height="1" /></td>
  </tr>
  <tr>
  <td class="medHeader"><img src="/media/images/spacer.gif" height="18" width="1" /></td>
  <td width="<% $infoIndent %>" align="right" class="medHeader"><span class="label"><% $lang->maketext('Last Published') %>:&nbsp;</span></td>
  <td width="470">&nbsp;<% $media->get_publish_date || '' %></td>
  </tr>

  <tr>
  <td bgcolor="white"><img src="/media/images/spacer.gif" width="1" height="1" /></td>
  </tr>
  <tr>
  <td class="medHeader"><img src="/media/images/spacer.gif" height="18" width="1" /></td>
  <td width="<% $infoIndent %>" align="right" class="medHeader"><span class="label"><% $lang->maketext('URI') %>:&nbsp;</span></td>
% if (my $uri = $media->get_primary_uri) {
%     if (@ocs == 1) {
  <td width="470">&nbsp;<% $m->comp('/widgets/profile/preview_link.mc',
                                    type  => 'media',
                                    title => $media->get_primary_uri,
                                    doc   => $media,
                                    style => 'blackUnderlinedLink') %></td>
  </tr>
% } else {
  <td width="470">&nbsp;<% $uri %></td>
  </tr>
  <tr>
  <td bgcolor="white"><img src="/media/images/spacer.gif" width="1" height="1" /></td>
  </tr>
  <tr>
  <td class="medHeader"><img src="/media/images/spacer.gif" height="18" width="1" /></td>
  <td width="<% $infoIndent %>" align="right" class="medHeader"><span class="label"><% $lang->maketext('Preview in') %>:&nbsp;</span></td>
  <td width="470" valign="middle">&nbsp;<% $oc_select %>&nbsp;<a href="#" onClick="window.open('/workflow/profile/preview/media/<% $id %>/' + window.document.theForm.ocSelect.options[window.document.theForm.ocSelect.selectedIndex].value, 'preview_<% SERVER_WINDOW_NAME %>');return false;"><img src="/media/images/<% $lang_key %>/preview_lgreen.gif" alt="Preview" border="0" width="74" height="20"></a></td>
  </tr>
%     }
% }
  <tr>
  <td bgcolor="white"><img src="/media/images/spacer.gif" width="1" height="1" /></td>
  </tr>
  <tr>
  <td class="medHeader"><img src="/media/images/spacer.gif" height="18" width="1" /></td>
  <td width="<% $infoIndent %>" align="right" class="medHeader"><span class="label"><% $lang->maketext('Site') %>:&nbsp;</span></td>
  <td width="470">&nbsp;<% Bric::Biz::Site->lookup({id => $media->get_site_id})->
  get_name() %></td>
  </tr>
  <tr>
  <td class="medHeader" colspan=3><img src="/media/images/spacer.gif" height="1" width="1" /></td>
  </tr>
</table>
<% $ieSpacer %>
<& '/widgets/profile/displayFormElement.mc',
   objref => $media,
   key => 'title',
&>

<% $ieSpacer %>

<& '/widgets/profile/displayFormElement.mc',
   objref => $media,
   key => 'description',
&>

<% $ieSpacer %>

<& '/widgets/select_object/select_object.mc',
  object   => 'source',
  name     => "$widget|source__id",
  field    => 'source_name',
  selected => $media->get_source__id,
  indent   => 0,
  useTable => 1,
  disp     => "Source"
&>

% unless (ENABLE_CATEGORY_BROWSER) {
<% $ieSpacer %>
<& '/widgets/select_object/select_object.mc',
  object        => 'category',
  constrain => { site_id => $media->get_site_id },
  name          => "$widget|category__id",
  field         => "uri",
  sort_field    => "uri",
  selected      => $media->get_category__id,
  indent        => 0,
  req           => 1,
  useTable      => 1,
  exclude       => sub { ! chk_authz($_[0], READ, 1) },
  disp          => "Category"
&>
% }  # unless ENABLE_CATEGORY_BROWSER

<% $ieSpacer %>
<& '/widgets/profile/displayFormElement.mc',
   objref => $media,
   key => 'priority',
&>
<% $ieSpacer %>
<& '/widgets/profile/displayFormElement.mc',
   objref => $media,
   key => 'cover_date',
&>
<% $ieSpacer %>
<& '/widgets/profile/displayFormElement.mc',
   objref => $media,
   key => 'expire_date',
&>
<% $ieSpacer %>
<%perl>;
$m->comp("/widgets/wrappers/sharky/table_bottom.mc");
$m->comp('file_section.mc',
         media     => $media,
         widget    => $widget,
         num       => $num++,
         read_only => $media->get_alias_id,
         indent    => $infoIndent
        );
$num = $m->comp( '/widgets/container_prof/container_prof.mc',
        tile        => $tile,
        tile_type   => 'media',
        action      => $media->get_alias_id ? 'view' : 'edit',
        num         => $num,
        title       => 'Content',
        start_count => 6
);

if (ENABLE_OC_ASSET_ASSOCIATION) {
    $m->comp('/widgets/profile/asset_ocs.mc',
             asset  => $media,
             widget => $widget,
             ocs    => \@ocs,
             num    => $num++,
             at_ocs => \@aocs
         );
}

$m->out("$ieSpacer<br />\n");

$m->comp("/widgets/wrappers/sharky/table_top.mc",
         caption => "Associations",
         number => $num++);
</%perl>

<table border=0 width=578 cellpadding=0 cellspacing=0>
<tr>
  <td width=120 align=right valign=top><span class=label><% $lang->maketext('Category') %>:&nbsp;</span></td>
  <td width=378 valign=top>
<%perl>
my $cat = $media->get_category;
$m->out($cat->get_name);
</%perl>
  </td>
  <td width=80 align="center" valign=top><& '/widgets/profile/imageSubmit.mc',
             formName => "theForm",
             callback => "$widget|category_cb",
             image    => "edit_lgreen",
             vspace   => 4
&></td>
</tr>
</table>

<table border=0 cellpadding=0 cellspacing=0 width=578>
<tr><td class="medHeader"><img src="/media/images/spacer.gif" width="578" height="1" /></td></tr>
</table>

<table border=0 width=578 cellpadding=0 cellspacing=0>
<tr>
  <td width=120 align=right valign=top><span class=label><% $lang->maketext('Keywords') %>:&nbsp;</span></td>
  <td width=378 valign=top>
<%perl>
my @keywords;
foreach my $kw ($media->get_keywords) {
    push @keywords, $kw->get_name;
}

$m->out(scalar(@keywords) ? join(", ", @keywords) : $lang->maketext("No keywords defined."));

</%perl>
  </td>
  <td width=80 align="center" valign=top><& '/widgets/profile/imageSubmit.mc',
             formName => "theForm",
             callback => "$widget|keywords_cb",
             image    => "edit_lgreen",
             vspace   => 4
&></td>
</tr>
</table>

<table border=0 cellpadding=0 cellspacing=0 width=578>
<tr><td class="medHeader"><img src="/media/images/spacer.gif" width="578" height="1" /></td></tr>
</table>

<table border=0 cellpadding=0 cellspacing=0 width=578>
<tr>
  <td align=right width=120 valign=top><span class=label><% $lang->maketext('Contributors') %>:&nbsp;</span></td>
  <td width=378 valign=top>

<%perl>
my @contribs;
foreach my $cntr ($media->get_contributors) {
    push @contribs,  $cntr->get_name;
}
$m->out(scalar(@contribs) ? join(", ", @contribs) : $lang->maketext("No contributors defined."));

</%perl>
  </td>
  <td width="80" align="center" valign="top">
% if ($media->get_alias_id) {
<img src="/media/images/spacer.gif" height="20" />
% } else {
<& /widgets/profile/imageSubmit.mc,
   formName => "theForm",
   callback => $widget . "|contributors_cb",
   image    => "edit_lgreen",
   vspace   => 3
&>
% }
</td>
</tr>
</table>
<%perl>
$m->comp("/widgets/wrappers/sharky/table_bottom.mc");

$m->comp("/widgets/profile/buttonBar.mc",
         widget      => $widget,
         desks       => $desks,
         cd          => $cd,
         obj         => $media,
);

</%perl>

%#-- Args Section --#
<%args>
$widget
</%args>

%#-- Init Section --#
<%init>

my $media = get_state_data($widget, 'media');
my $tile = $media->get_tile();

set_state_data('container_prof', 'tile', $tile);

my $wf_id = get_state_data($widget, 'work_id');
$wf_id = $media->get_workflow_id() unless $wf_id;
my $wf = Bric::Biz::Workflow->lookup( { id => $wf_id });
my $desks = $wf->allowed_desks();
my $cd = $media->get_current_desk();
$cd = $wf->get_start_desk() unless $cd;
my $id = $media->get_id;

# Set up a formatting variable
my $agent = detect_agent();
my $infoIndent = $agent->nav4 ? FIELD_INDENT - 5 : FIELD_INDENT + 8;
my $num = 1;
my $ieSpacer = $agent->ie ?
  qq{<table><tr><td><img src="/media/images/spacer.gif" width="578" } .
  qq{height="5" /></td></tr></table>}
  : '';

# get output channel info
my $at = $media->get_element__id;
my $asset_type = Bric::Biz::AssetType->lookup({id => $at});
my @aocs = $asset_type->get_output_channels;
my @ocs = $media->get_output_channels;
my $primocid = $media->get_primary_oc_id;

my $oc_select = '<select name="ocSelect">';
foreach my $oc (@ocs) {
    my $ocid = $oc->get_id;
    my $selected = $ocid == $primocid ? ' selected' : '';
    $oc_select .= qq{<option value="$ocid"$selected>} . $oc->get_name . '</option>';
}
$oc_select .= '</select>';
</%init>

