Example #1
0
// |                                                                      |
// | Free Software Foundation, Inc.                                       |
// | 51 Franklin Street, Suite 330                                          |
// | Boston, MA 02110-1301, USA.                                          |
// +----------------------------------------------------------------------+
// | Authors: Dave Anderson <*****@*****.**>                             |
// +----------------------------------------------------------------------+
require_once dirname(__FILE__) . '/../../init.php';
$tpl = new Template_Helper();
$tpl->setTemplate('manage/email_alias.tpl.html');
Auth::checkAuthentication(APP_COOKIE, null, true);
$role_id = Auth::getCurrentRole();
if ($role_id < User::getRoleID('manager')) {
    $tpl->setTemplate('permission_denied.tpl.html');
    $tpl->displayTemplate();
    exit;
}
$usr_id = $_REQUEST['id'];
if (@$_POST['cat'] == 'save') {
    $res = User::addAlias($usr_id, trim($_POST['alias']));
    Misc::mapMessages($res, array(true => array(ev_gettext('Thank you, the alias was added successfully.'), Misc::MSG_INFO), false => array(ev_gettext('An error occurred while trying to add the alias.'), Misc::MSG_ERROR)));
} elseif (@$_POST['cat'] == 'remove') {
    foreach ($_POST['item'] as $aliastmp) {
        $res = User::removeAlias($usr_id, $aliastmp);
    }
    Misc::mapMessages($res, array(true => array(ev_gettext('Thank you, the alias was removed successfully.'), Misc::MSG_INFO), false => array(ev_gettext('An error occurred while trying to remove the alias.'), Misc::MSG_ERROR)));
}
$tpl->assign('list', User::getAliases($usr_id));
$tpl->assign('username', User::getFullName($usr_id));
$tpl->assign('id', $usr_id);
$tpl->displayTemplate();
Example #2
0
 /**
  * Method used to get the list of users available in the system.
  *
  * @param   boolean $show_customers Whether to return customers or not
  * @return  array The list of users
  */
 public static function getList($show_customers, $show_inactive)
 {
     // FIXME: what about other statuses like "pending"?
     $stmt = 'SELECT
                 *
              FROM
                 {{%user}}
              WHERE
                 usr_id != ?';
     $params = array(APP_SYSTEM_USER_ID);
     if (!$show_inactive) {
         $stmt .= ' AND usr_status != ?';
         $params[] = 'inactive';
     }
     $stmt .= '
             ORDER BY
                 usr_status ASC,
                 usr_full_name ASC';
     try {
         $res = DB_Helper::getInstance()->getAll($stmt, $params);
     } catch (DbException $e) {
         return '';
     }
     $data = array();
     foreach ($res as &$row) {
         $roles = Project::getAssocList($row['usr_id'], false, true);
         $role = current($roles);
         $role = $role['pru_role'];
         if ($show_customers == false && (@$roles[Auth::getCurrentProject()]['pru_role'] == self::getRoleID('Customer') || count($roles) == 1 && $role == self::getRoleID('Customer'))) {
             continue;
         }
         $row['roles'] = $roles;
         if (!empty($row['usr_grp_id'])) {
             $row['group_name'] = Group::getName($row['usr_grp_id']);
         }
         if (!empty($row['usr_par_code'])) {
             $row['partner_name'] = Partner::getName($row['usr_par_code']);
         }
         // add email aliases
         $row['aliases'] = User::getAliases($row['usr_id']);
         $data[] = $row;
     }
     return $data;
 }
 /**
  * Creates or updates local user entry for the specified ID.
  *
  * @param string $login The login or email of the user to create or update
  * @return  bool True if the user was created or updated, false otherwise
  */
 public function updateLocalUserFromBackend($login)
 {
     $remote = $this->getRemoteUserInfo($login);
     if (!$remote) {
         return false;
     }
     $usr_id = $this->getLocalUserId($login, $remote['emails']);
     $data = array('full_name' => $remote['full_name'], 'external_id' => $remote['uid'], 'customer_id' => $remote['customer_id'], 'contact_id' => $remote['contact_id']);
     // if local user found, update it and return usr id
     if ($usr_id) {
         $emails = $this->sortEmails($usr_id, $remote['emails']);
         if (!$emails) {
             throw new AuthException('E-mail is required');
         }
         // use first email as primary from sorted list
         $data['email'] = array_shift($emails);
         // do not clear full name if for some reason it is empty
         if (empty($data['full_name'])) {
             unset($data['full_name']);
         }
         // read in details, and make modification only if data has changed
         $user_details = User::getDetails($usr_id);
         $stored_data = array('full_name' => $user_details['usr_full_name'], 'external_id' => $user_details['usr_external_id'], 'customer_id' => $user_details['usr_customer_id'], 'contact_id' => $user_details['usr_customer_contact_id'], 'email' => $user_details['usr_email']);
         if ($stored_data != $data) {
             User::update($usr_id, $data, false);
         }
         $aliases = User::getAliases($usr_id);
         // as we are only adding aliases (never removing)
         // check only one way
         if (array_diff($emails, $aliases)) {
             $this->updateAliases($usr_id, $emails);
         }
         return $usr_id;
     }
     return $this->createUser($remote);
 }