<?php

  //get formatted name and email from account by id
  function getFormattedEmailFromAccounById($id) {
    if(!isset($id) || $id == '') return false;
    require_once('modules/Accounts/Account.php');
    $acc = new Account();
    $acc->retrieve($id);
    if(isset($acc->id) && $acc->id != '') {
      return $acc->name.' <'.$acc->email1.'>; ';
    }
    return '';
  }
  
  //get formatted name and email from user
  function getFormattedEmailFromUserId($id) {
    if(!isset($id) || $id == '') return false;
    require_once('modules/Users/User.php');
    $us = new User();
    $us->retrieve($id);
    if(isset($us->id) && $us->id != '') {
      return $us->full_name.' <'.$us->email1.'>; ';
    }
    return '';
  }

  //get info from module by Id
  function getInfoFromModuleById($module, $id, $arr = '') {
    if(!isset($id) || $id == '') return false;
    global $beanFiles, $beanList;
    require_once($beanFiles[$beanList[$module]]);
    $bean = new $beanList[$module]();
    $bean->retrieve($id);
    if(isset($bean->id) && $bean->id != '') {
      $arr = explode('|', $arr);
      $tmp = array();
      for($i=0; $i<count($arr); $i++) 
        $tmp[$arr[$i]] = htmlspecialchars_decode($bean->$arr[$i]);
      $json = getJSONobj(); 
      return '['.$json->encode($tmp).']';
    }
    return '';
  }

  

  if(isset($_REQUEST['data']) && $_REQUEST['data'] == 'EFA' && isset($_REQUEST['id']) && $_REQUEST['id'] != '') 

    echo getFormattedEmailFromAccounById($_REQUEST['id']);

  

  if(isset($_REQUEST['data']) && $_REQUEST['data'] == 'EFAUID' && isset($_REQUEST['id']) && $_REQUEST['id'] != '') 

    echo getFormattedEmailFromUserId($_REQUEST['id']);



  if(isset($_REQUEST['gdData']) && $_REQUEST['gdData'] != '' && isset($_REQUEST['gdId']) && $_REQUEST['gdId'] != '' && isset($_REQUEST['gdData']) && $_REQUEST['gdData'] != '') 

    echo getInfoFromModuleById($_REQUEST['gdModule'],$_REQUEST['gdId'],$_REQUEST['gdData']);



?>

