<?/*
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">Edit Support People<div class="athenatitle">Edit Support People</div></div>
<br />

<?php
  require 'dd.php';
  require_once 'person.php';
  require_once 'server_functions.php';

  globalize_request_keys('person_id', 'submit', 'first_name', 'last_name',
    'middle_initial', 'email', 'home_phone', 'work_phone', 'cell_phone',
    'privacy_level', 'pager_num', 'address1', 'address2', 'city', 'state',
    'zip', 'escalated_drop_down', 'support_drop_down', 'modify_tickets',
    'username', 'password', 'person_type');

  $person_p  = new Person ();

  $is_super_admin = $person_p->Is_Super_Admin ();

  if (!$is_super_admin) {
    return;
  }

  ## important to lookup up info so when the update runs fields that we don't
  ## change remain the same, i.e. person_type
  if ($person_id) {
    $person = $person_p->Info_by_Person_CRM_ID ($person_id, $REMOTE_USER_CRM_ID);

    ## make sure they are in this RMS
    if (!$is_super_admin && ($person->Get('base_person_type') != 'User')) $person_id = '';
  }
?>

<a href="<?php echo $_SERVER['PHP_SELF']; ?>">« Start Over</a>
<br />
<br />
Person Types (used for login access):
<ul>
  <li>Support - Allows 'normal' access to Athena</li>
  <li>Support Admin - Allows access to the admin area (you still need Support selected if they are to do 'normal' stuff as well)</li>
  <li>Escalated Support and User - do nothing right now</li>
</ul>

Drop-down selections are used for having people show up in the various drop-down menus in the site.

<form action="<?php echo $_SERVER['PHP_SELF'];?>" method="post">

<?php
  if (!$person_id) {

    print '<font color="red">Make sure you have at least 1 person in each type or your RMS will not work.</font><br />';

    print "<br />\n";
    print Sub_Heading ('Support');

    if (is_null($a = $person_p->List_By ('Support', 2)))
      die('person_edit.php: ' . $person_p->error);

    #print_r($a);
    #exit;

      print '<table width="100%" border="0" cellpadding="4" cellspacing="0"><tr><td class="text" align="left" nowrap="nowrap" width="100%"><ul class="text">';

    foreach ($a as $r) {
      if (!$is_super_admin && ($r['base_person_type'] != 'User')) continue;

      print ' <li><a href="' . $_SERVER['PHP_SELF'] . "?person_id=$r[person_id]\">$r[last_name], $r[first_name]";
      print "</a></li>\n";
    }

      print "</ul></td></tr></table>\n";

      print "<br />\n";
    print Sub_Heading ('Escalated Support');

    $a = $person_p->List_By ('Escalated Support', 2);

      print '<table width="100%" border="0" cellpadding="4" cellspacing="0"><tr><td class="text" align="left" nowrap="nowrap" width="100%"><ul class="text">';

    foreach ($a as $r) {
      if (!$is_super_admin && ($r['base_person_type'] != 'User')) continue;

      print '<li><a href="'. $_SERVER['PHP_SELF'] . "?person_id=$r[person_id]\">$r[last_name], $r[first_name]";
      print "</a></li>\n";
    }

    print "</ul></td></tr></table>\n";
    print "</form>\n";

    return;
  }

  if ($submit == 'Update') {
    foreach (array (
      'first_name',
      'last_name',
      'middle_initial',
      'email',
      'home_phone',
      'work_phone',
      'cell_phone',
      'privacy_level',
      'pager_num',
      'address1',
      'address2',
      'city',
      'state',
      'zip',
      'escalated_drop_down',
      'support_drop_down',
      'modify_tickets',
    ) as $set) {
      $person->Set ($set, $$set);
    }

    $person->Update_All ();

    $person->Set_Username ($person->Get ('person_id'), $username);

    $pcrm_map_id = $person->Get('pcrm_map_id');

    if ($password) {
      $person->Update_Password ($person->Get ('person_id'), md5($password));
    }

    $person->Set_Types ($person_type, $pcrm_map_id);

    if (!count($person_type)) {
      redirect('/person_edit',1);
    }

    $person = $person_p->Info_by_Person_CRM_ID ($person_id, $REMOTE_USER_CRM_ID);
  }

?>

<input type="hidden" name="person_id" value="<?php echo $person_id; ?>" />
<table cellpadding="2" cellspacing="0" width="540">
<tr>
  <td class="text">First Name:</td>
  <td class="text"><?php echo $person->Get ('first_name'); ?></td>
  <td class="text"><input type="text" name="first_name" value="<?php echo $person->Get ('first_name'); ?>" /></td>
</tr>
<tr>
  <td class="text">Last Name:</td>
  <td class="text"><?php echo $person->Get ('last_name'); ?></td>
  <td class="text"><input type="text" name="last_name" value="<?php echo $person->Get ('last_name'); ?>" /></td>
</tr>
<tr>
  <td class="text">Middle Initial:</td>
  <td class="text"><?php echo $person->Get ('middle_initial'); ?></td>
  <td class="text"><input type="text" name="middle_initial" value="<?php echo $person->Get ('middle_initial'); ?>" maxlength="1" size="1" /></td>
</tr>
<tr>
  <td class="text">Email:</td>
  <td class="text"><?php echo $person->Get ('email'); ?></td>
  <td class="text"><input type="text" name="email" value="<?php echo $person->Get ('email'); ?>" /></td>
</tr>
<tr>
  <td class="text">Home Phone:</td>
  <td class="text"><?php echo $person->Get ('home_phone'); ?></td>
  <td class="text"><input type="text" name="home_phone" value="<?php echo $person->Get ('home_phone'); ?>" /></td>
</tr>
<tr>
  <td class="text">Work Ext:</td>
  <td class="text"><?php echo $person->Get ('work_phone'); ?></td>
  <td class="text"><input type="text" name="work_phone" value="<?php echo $person->Get ('work_phone'); ?>" /></td>
</tr>
<tr>
  <td class="text">Cell Phone:</td>
  <td class="text"><?php echo $person->Get ('cell_phone'); ?></td>
  <td class="text"><input type="text" name="cell_phone" value="<?php echo $person->Get ('cell_phone'); ?>" /></td>
</tr>
<tr>
  <td class="text">Pager:</td>
  <td class="text"><?php echo $person->Get ('pager_num'); ?></td>
  <td class="text"><input type="text" name="pager_num" value="<?php echo $person->Get ('pager_num'); ?>" /></td>
</tr>
<tr>
  <td class="text">Address:</td>
  <td class="text"><?php echo $person->Get ('address1'); ?></td>
  <td class="text"><input type="text" name="address1" value="<?php echo $person->Get ('address1'); ?>" /></td>
</tr>
<tr>
  <td class="text">Address:</td>
  <td class="text"><?php echo $person->Get ('address2'); ?></td>
  <td class="text"><input type="text" name="address2" value="<?php echo $person->Get ('address2'); ?>" /></td>
</tr>
<tr>
  <td class="text">City:</td>
  <td class="text"><?php echo $person->Get ('city'); ?></td>
  <td class="text"><input type="text" name="city" value="<?php echo $person->Get ('city'); ?>" /></td>
</tr>
<tr>
  <td class="text">State:</td>
  <td class="text"><?php echo $person->Get ('state'); ?></td>
  <td class="text"><select name="state"><?php echo $dd->state ($person->Get ('state')); ?></select></td>
</tr>
<tr>
  <td class="text">Zip:</td>
  <td class="text"><?php echo $person->Get ('zip'); ?></td>
  <td class="text"><input type="text" name="zip" value="<?php echo $person->Get ('zip'); ?>" /></td>
</tr>
<tr valign="top">
  <td class="text">Person Types:<br />(Login Access)</td>
  <td class="text"><?php print implode ("<br />\n", $person->Get_Types ()); ?></td>
  <td class="text"><select name="person_type[]" multiple="multiple"><?php echo $dd->person_type ( $person->Get_Types () ); ?></select></td>
</tr>
<tr>
  <td class="text">In Support Drop-down:</td>
  <td class="text"><?php echo $person->Get ('support_drop_down'); ?></td>
  <td class="text"><select name="support_drop_down"><?php echo $dd->yes_no ($person->Get ('support_drop_down')); ?></select></td>
</tr>
<tr>
  <td class="text">In Escalated Drop-down:</td>
  <td class="text"><?php echo $person->Get ('escalated_drop_down'); ?></td>
  <td class="text"><select name="escalated_drop_down"><?php echo $dd->yes_no ($person->Get ('escalated_drop_down')); ?></select></td>
</tr>
<tr>
  <td class="text">Modify Tickets:</td>
  <td class="text"><?php echo $person->Get ('modify_tickets'); ?></td>
  <td class="text"><select name="modify_tickets"><?php echo $dd->modify_ticket_types ($person->Get ('modify_tickets')); ?></select></td>
</tr>
<tr>
  <td class="text">Username (cannot be all numbers):</td>
  <td class="text"><?php echo $person->To_Username ($person->Get ('person_id')); ?></td>
  <td class="text"><input type="text" name="username" value="<?php echo $person->To_Username ($person->Get ('person_id')); ?>" /></td>
</tr>
<tr>
  <td colspan="2">Password (only enter new one):</td>
  <td class="text"><input type="text" name="password" /></td>
</tr>
<tr>
  <td class="text"><br /></td>
</tr>
<tr>
  <td colspan="3" align="center"><input type="submit" name="submit_button" value="Update" /></td>
</tr>
</table>
<input type="hidden" name="submit" value="Update" />
</form>


