<?/*
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
*/?>
<div class="athenatitleshadow">Queries<div class="athenatitle">Queries</div></div>
<br />

<?php
  require_once 'db.php';
  require_once 'search_query.php';
  require_once 'server_functions.php';

  globalize_request_keys('del', 'confirm', 'name');

  $search_query = new Search_Query ();

  if ($del and $confirm) {
    $search_query->Delete ($del);
  } elseif ($del) {
print <<<EOF
<form action="$_SERVER[PHP_SELF]" method="post">
<font class='errors'>Are you sure you want to delete: <b>$name?</b></font>
<br /><br />
<table cellspacing="0" cellpadding="1" border="0" bgcolor="#de0000">
<tr>
<td><input type="submit" name="submit" value="Yes Delete Now" /></td>
</tr>
</table><br />
<input type="hidden" name="del" value="$del" />
<input type="hidden" name="confirm" value="1" />
</form>

EOF;

    return;

  }
  $r = $search_query->List_Global ();
  if (is_null($r)) pretty_die('my_queries.php: ' . $search_query->error);

  if ($r) {

?>


    <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">&nbsp;Global Queries&nbsp;</td>
                        <td align="right" nowrap="nowrap" class="hdr"><img src='../../img/cldot.gif' width='1' height='1' border='0'></td>
                    </tr>

<?php


  for ($i=0; $i<count($r); $i++) {
    $qid = $r[$i][0];
    $qname = $r[$i][1];

    if ($i%2 == 0) {
      $color = 'off';
      $backgr = 'off-med';
      $img_listview = "bug-listview-notext.gif";
    } else {
      $color = 'on';
      $backgr = 'on-med';
      $img_listview = "bug-listview-notext-on.gif";
    }

    print "<tr class='$color'><td nowrap='nowrap' valign='middle' class='$backgr'>&nbsp;<b><a href=\"search.php?query_id=$qid&amp;type=g\">$qname</a></b>&nbsp;<a href=\"search.php?query_id=$qid&amp;type=g&save_option=list\"><img src='../../img/$img_listview' alt='List View' class='listview-icon' width='12' height='15' border='0'></a>&nbsp;</td>  <td nowrap='nowrap' class='$backgr'><img src='../../img/cldot.gif' width='1' height='1' border='0'></td></tr>\n";
  }
?>

</table>
</td>
</tr>
</table>

<br />
<?php
  }
  $r = $search_query->List_by_Person_ID ();
  if (is_null($r)) pretty_die('my_queries.php: ' . $search_query->error);

  if (!$r) {

    print "<font class='errors'>You have no saved queries at this time. To set up a new query:<ol class='errors'><li class='errors'>Go to the <a href='search_form' class='errorslnk'>search</a> page</li><li class='errors'>Enter your search criteria</li><li class='errors'>Check the <i>'Save Query'</i> box at the bottom of the page</li><li class='errors'>Finish by clicking the <i>'Get Results'</i> button</li></ol></font>\n";
    return;
  }
?>

    <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">&nbsp;My Queries&nbsp;</td>
                        <td align="right" nowrap="nowrap" class="hdr">&nbsp;<!--XXXXXXXXXXXXXXXX-->&nbsp;</td>
                        <td align="center" nowrap="nowrap" class="hdr">&nbsp;Delete&nbsp;</td>
                    </tr>

<?php

  for ($i=0; $i<count($r); $i++) {
    $qid = $r[$i][0];
    $qname = $r[$i][1];

    if ($i%2 == 0) {
      $color = 'off';
      $backgr = 'off-med';
      $img_listview = "bug-listview-notext.gif";
    } else {
      $color = 'on';
      $backgr = 'on-med';
      $img_listview = "bug-listview-notext-on.gif";
    }
    print "<tr class='$color'><td nowrap='nowrap' valign='middle' class='$backgr'>&nbsp;<b><a href=\"search.php?query_id=$qid\">$qname</a></b>&nbsp;<a href=\"search.php?query_id=$qid&save_option=list\"><img src='../../img/$img_listview' alt='List View' class='listview-icon' width='12' height='15' border='0'></a>&nbsp;</td>   <td nowrap='nowrap' class='$backgr'><img src='../../img/cldot.gif' width='1' height='1' border='0'></td><td width='70' align='center' nowrap='nowrap' class='$backgr'>&nbsp;<a href=\"" . $_SERVER['PHP_SELF'] . "?del=$qid&name=$qname\" class=\"deletelnk\"><img src='../../img/btn-delete' alt='Delete this Query' align='middle' hspace='2' width='22' height='22' border='0'></a>&nbsp;</td></tr>\n";
  }
?>
</table>
</td>
</tr>
</table><br />
