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

  globalize_request_keys('add_person_id', 'add', 'crm_id');

  if (!$add_person_id and !$add) {
    print "no people supplied\n";
    return;
  }

  $person = new Person ();

  $is_admin = $person->Is_Super_Admin();

  if (!$is_admin or !$crm_id) {
    $crm_id = $REMOTE_USER_CRM_ID;
  }

  if ($add) {

    foreach ($add as $pid => $ary) {

      $in_crm = $person->Is_In_CRM($pid, $crm_id);

      if (!$is_admin && !$in_crm) {
        print "Skipping $pid, it's not in your crm.<br/>\n";
        continue;
      }

      if ($in_crm) {
	$pr = $person->Info_by_Person_CRM_ID($pid, $crm_id);
	if (!$pr || !($map_id = $pr->pcrm_map_id))
	  print "Failed to find Map ID for Person ID in CRM ID: $crm_id<br/>\n";
      } else {
	$ary['CRM_ID'] = $crm_id;
	$ary['PERSON_ID'] = $pid;

	if ($map_id = $person->Add_Map ($ary)) print "Added Person ID: $pid.\n";
	else print "Failed to add Person ID: $pid<br/>\n";
      }

      if ($map_id) {
	$person->Set_Types ($ary['JOB_TYPES'], $map_id);
	print "Types set for Person ID: $pid<br/>\n";
      }
    }

    return;
  }

  require_once 'dd.php';
?>

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">
<input type="hidden" name="crm_id" value="<?php echo $crm_id; ?>" />

<table border="1" cellpadding="4" cellspacing="0">
<tr valign="bottom">
  <th rowspan="2" align="left">Name</th>
  <th colspan="2" align="center">In Drop-Down?</th>
  <th rowspan="2" align="center">Modify<br />Tickets</th>
  <th rowspan="2">Make Current CRM?</th>
  <th rowspan="2">Login Access</th>
</tr>
<tr>
  <th>Support</th>
  <th>Escalated</th>
</tr>

<?php
  $sdd = $dd->yes_no ('Y');
  $edd = $dd->yes_no ('Y');
  $mtdd = $dd->yes_no ('Y');
  $currdd = $dd->yes_no ('N');
  $types = $person->Array_Drop_Down ($person->List_All_Types (), 'Support');

  foreach ($add_person_id as $pid => $name) {
    print <<<END
<tr>
  <td>$name</td>
  <td align="center"><select name="add[$pid][SUPPORT_DROP_DOWN]">$sdd</select></td>
  <td align="center"><select name="add[$pid][ESCALATED_DROP_DOWN]">$edd</select></td>
  <td align="center"><select name="add[$pid][MODIFY_TICKETS]">$mtdd</select></td>
  <td align="center"><select name="add[$pid][CURRENT]">$currdd</select></td>
  <td align="center"><select name="add[$pid][JOB_TYPES][]" size="3" multiple="multiple">$types</select></td>
</tr>
END;
  }
?>

</table>

<br />
<input type="submit" name="submit" value="Submit" />

</form>

