<?/*
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
*/?>
<?php
  require_once 'db.php';
  require_once 'dd.php';
  require_once 'person.php';
  require_once 'server_functions.php';

  /*
    Returns an array keyed by person_id; value is an array
    ("lastname, firstname", email_address).
  */
  function get_escalated_persons() {
    global $dd;

    $p = new Person();

    $a = $p->List_By('Escalated Support',4);
    $dudes = array();

    foreach ($a as $row) {
      if ($row['email']) $dudes[$row['person_id']] = array($row['name'],$row['email']);
    }

    return $dudes;
  }

  function make_address_book_rows() {
    global $escalated_persons;

    if (count($escalated_persons) == 0) {
      $escalated_persons = get_escalated_persons();
    }

    $i = 0;
    foreach ($escalated_persons as $pid => $a) {
      list($name,$email) = $a;

    if ($i%2 == 0) {
      $color = 'offaddbk';
    } else {
      $color = 'onaddbk';
    }
    $i++;

      $out = <<<EOF
<tr class='$color'>
  <td class='$color'><input type="checkbox" name="to_$email"></td>
  <td class='$color'><input type="checkbox" name="cc_$email"></td>
  <td class='$color'><input type="checkbox" name="bcc_$email"></td>
  <td class='$color'><font class='textsm'>$name</font></td>
  <td class='$color'><font class='textsm'>$email</font></td>
</tr>
EOF;
    }

    return $out;
  }

  $escalated_persons = get_escalated_persons();
?>
<html>
<head>
  <title>Athena Address Book</title>
  <link rel="stylesheet" href="<?= $web_root ?>/includes/css/global.css" type="text/css" />
</head>

<body bgcolor="white" leftmargin="0" topmargin="5" marginwidth="0" marginheight="5">
<script src="address_book_funcs.js"></script>
<script>
</script>
<form name="f">

<div class="athenatitleshadow">&nbsp;&nbsp;Address Book<div class="athenatitle">&nbsp;&nbsp;Address Book</div></div>

<table cellpadding="1" border="0" cellspacing="0" width="100%">
<tr>
  <td colspan='5' class="hdraddbk"><input type="submit" class="btn-on" name="submit" value="Insert Checked Contacts" onClick="update_parent_window(); return false">&nbsp;&nbsp;&nbsp;<input type="submit" class="btn-off" value="Cancel" onClick="window.close()"></td>
</tr>
  <tr>
    <td class="firstrowaddbk">To</td>
    <td class="firstrowaddbk">Cc</td>
    <td class="firstrowaddbk">Bcc</td>
    <td class="firstrowaddbk">Name</td>
    <td class="firstrowaddbk">E-Mail</td>
  </tr>
  <?php print make_address_book_rows(); ?>
<tr>
  <td colspan='5' class="lastaddbk"><a href="#" onClick="check_all();return false" class='smlinks'>Check All</a> <font class='textsm'>-</font> <a href="#" onClick="uncheck_all();return false" class='smlinks'>Clear All</a></td>
</tr>
<tr>
  <td colspan='5' class="hdraddbk"><input type="submit" class="btn-on" name="submit" value="Insert Checked Contacts" onClick="update_parent_window(); return false">&nbsp;&nbsp;&nbsp;<input type="submit" class="btn-off" value="Cancel" onClick="window.close()"></td>
</tr>

</table>

</form>

</body>

</html>
