<?/*
Copyright (C) 2003 Media Net Link, Inc. Danville, CA 94526 USA

This file is part of AthenaRMS.

AthenaRMS is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

AthenaRMS is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/?>
<table cellpadding="1" border="0" cellspacing="0" width="100%">
<tr class="first">
  <td>
    <table border="0" cellspacing="0" cellpadding="0" width="100%">
    <tr class="first">
      <td nowrap="nowrap" class="hdr-home">&nbsp;Choose Your RMS&nbsp;</td>
      <td align="right" nowrap="nowrap" class="hdr-home">&nbsp;My Open&nbsp;</td>
      <td align="right" nowrap="nowrap" class="hdr-home">&nbsp;All Open&nbsp;</td>
    </tr>

<?php
  require_once 'crm_view.php';
  require_once 'ticket.php';
  require_once 'web_root.php';

  $cv = new CRM_View ();
  $ticket = new Ticket ();
  $list = $cv->List_All ($REMOTE_USER, 1);
  if (!$list) die('home: ' . $cv->error);

  $counts = array ();


  foreach ($ticket->All_My_Open($REMOTE_USER) as $r) {
    $counts[$r['crm_id']]['my'] = $r['total'];
  }

  if (is_null($rmsopen = $ticket->My_RMS_Open($REMOTE_USER)))
    die($ticket->error);

  foreach ($rmsopen as $r) {
    $counts[$r['crm_id']]['all'] = $r['total'];
  }

  $all_open_string = '/support/search/search.php?status[]=Open&status[]=ReOpen';
  $my_open_string = "&support_person_id[]=$REMOTE_USER";
  $my_query_string = '/support/search/my_queries';
  $search_string = '/support/search/search_form';
  $report_string = '/support/reports/';
  $admin_string = '/admin/';
  $add_string = '/user/';

  $session_params = session_name().'='.session_id();

  $i=0;
  foreach ($list as $r) {
    $admin = $r['is_admin'];

    if ($i%2 == 0) {
      $color = 'off';
      $backgr = 'off-large';
      $img_search = "bug-search.gif";
      $img_query = "bug-query.gif";
      $img_reports = "bug-reports.gif";
      $img_ticket = "bug-ticket.gif";
      $img_admin = "bug-admin.gif";
      $img_listview = "bug-listview.gif";
    } else {
      $color = 'on';
      $backgr = 'on-large';
      $img_search = "bug-search-on.gif";
      $img_query = "bug-query-on.gif";
      $img_reports = "bug-reports-on.gif";
      $img_ticket = "bug-ticket-on.gif";
      $img_admin = "bug-admin-on.gif";
      $img_listview = "bug-listview-on.gif";
    }
    $i++;

    if (!array_key_exists($r['crm_id'], $counts)
        || !array_key_exists('my', $counts[$r['crm_id']])
	|| !($my_tickets = $counts[$r['crm_id']]['my'])) $my_tickets = 0;

    if (!array_key_exists($r['crm_id'], $counts)
      	|| !($all_tickets = $counts[$r['crm_id']]['all'])) $all_tickets = 0;

    $crm_name = $r['crm_name'];
    $web_url = 'http'
	     . (array_key_exists('HTTPS', $_SERVER) ? 's' : '')
	     . '://' . $r['web_domain'] 
	     . preg_replace('/\/$/', '', $r['web_path']);

    $all_open_url = $web_url.$all_open_string.'&'.$session_params;
    $my_open_url = $all_open_url.$my_open_string;
    $my_queries_url = $web_url.$my_query_string.'?'.$session_params;
    $search_url = $web_url.$search_string.'?'.$session_params;
    $report_url = $web_url.$report_string.'?'.$session_params;
    $add_url = $web_url.$add_string.'?'.$session_params;

    $all_open_list = $all_open_url."&save_option=list";
    $my_open_list = $my_open_url."&save_option=list";

    if ($admin) {
      $admin_url = $web_url.$admin_string.'?'.$session_params;
      $admin = <<<EOF
  <td valign="top"><a href="$admin_url" class="smlinks"><img src="img/$img_admin" alt="Admin" width="17" height="17" border="0"></a></td>
  <td valign="top"><a href="$admin_url" class="smlinks">admin</a><img src="img/cldot.gif" width="10" height="1" border="0"></td>
EOF;
    }

    print <<<EOF


<tr class="$color">

<td class="$backgr" nowrap="nowrap">&nbsp;<b class="homerms">$crm_name</b>&nbsp;<br>

<table cellpadding="0" cellspacing="0">
<tr>
  <td valign="top"><a href="$search_url" class="smlinks"><img src="img/$img_search" alt="Search" width="10" height="17" border="0"></a></td>
  <td valign="top"><a href="$search_url" class="smlinks">search</a><img src="img/cldot.gif" alt="" width="10" height="1" border="0"></td>
  <td valign="top"><a href="$my_queries_url" class="smlinks"><img src="img/$img_query" alt="Queries" width="11" height="17" border="0"></a></td>
  <td valign="top" nowrap="nowrap"><a href="$my_queries_url" class="smlinks">queries</a><img src="img/cldot.gif" alt="" width="10" height="1" border="0"></td>
  <td valign="top"><a href="$report_url" class="smlinks"><img alt="Reports" src="img/$img_reports" width="17" height="17" border="0"></a></td>
  <td valign="top"><a href="$report_url" class="smlinks">reports</a><img src="img/cldot.gif" alt="" width="10" height="1" border="0"></td>
  <td valign="top"><a href="$add_url" class="smlinks"><img alt="Add Ticket" src="img/$img_ticket" width="10" height="17" border="0"></a></td>
  <td valign="top"><a class="smlinks" href="$add_url">add ticket</a><img src="img/cldot.gif" alt="" width="10" height="1" border="0"></td>
$admin
</tr>
</table>

</td>

<td class="$backgr" align="right">&nbsp;<a href="$my_open_url" class='atextbigger'>$my_tickets</a>&nbsp;&nbsp;&nbsp;<a href="$my_open_list"><img src="img/$img_listview" alt='List View' align="absmiddle" width="13" height="22" border="0"></a>&nbsp;&nbsp;</td>
<td class="$backgr" align="right">&nbsp;<a href="$all_open_url" class='atextbigger'>$all_tickets</a>&nbsp;&nbsp;&nbsp;<a href="$all_open_list"><img src="img/$img_listview" alt='List View' align="absmiddle" width="13" height="22" border="0"></a>&nbsp;&nbsp;</td>
 </tr>

EOF;
  }
?>
</table>
</td>
</tr>
</table>
<!--<font class='textsm'>support@<?php echo $_SERVER[SERVER_NAME]; ?></font>-->
