Example #1
0
 protected function setUp()
 {
     SugarTestHelper::setUp('beanList');
     SugarTestHelper::setUp('beanFiles');
     SugarTestHelper::setUp('current_user');
     $this->currentUser = $GLOBALS['current_user'];
     $this->defaultExportCharset = $this->currentUser->getPreference(self::DEFAULT_EXPORT_CHARSET_PREF_NAME);
     $this->opportunity = SugarTestOpportunityUtilities::createOpportunity();
 }
Example #2
0
 /**
  * Method removes module from global search configurations
  *
  * return bool
  */
 public function uninstall_global_search()
 {
     if (empty($this->installdefs['beans'])) {
         return true;
     }
     if (is_file('custom/modules/unified_search_modules_display.php') == false) {
         return true;
     }
     $user = new User();
     $users = get_user_array();
     $unified_search_modules_display = array();
     require 'custom/modules/unified_search_modules_display.php';
     foreach ($this->installdefs['beans'] as $beanDefs) {
         if (array_key_exists($beanDefs['module'], $unified_search_modules_display) == false) {
             continue;
         }
         unset($unified_search_modules_display[$beanDefs['module']]);
         foreach ($users as $userId => $userName) {
             if (empty($userId)) {
                 continue;
             }
             $user->retrieve($userId);
             $prefs = $user->getPreference('globalSearch', 'search');
             if (array_key_exists($beanDefs['module'], $prefs) == false) {
                 continue;
             }
             unset($prefs[$beanDefs['module']]);
             $user->setPreference('globalSearch', $prefs, 0, 'search');
             $user->savePreferencesToDB();
         }
     }
     if (write_array_to_file("unified_search_modules_display", $unified_search_modules_display, 'custom/modules/unified_search_modules_display.php') == false) {
         global $app_strings;
         $msg = string_format($app_strings['ERR_FILE_WRITE'], array('custom/modules/unified_search_modules_display.php'));
         $GLOBALS['log']->error($msg);
         throw new Exception($msg);
         return false;
     }
     return true;
 }
Example #3
0
    private static function upgradeUserPreferences()
    {
        $users = User::getActiveUsers();
        foreach ($users as $user_id => $user_name) {
            $user = new User();
            $user->retrieve($user_id);

            $preferencePopupReminderTime = $user->getPreference('reminder_time');
            $preferenceEmailReminderTime = $user->getPreference('email_reminder_time');

            $preferencePopupReminderChecked = $preferencePopupReminderTime > -1;
            $preferenceEmailReminderChecked = $preferenceEmailReminderTime > -1;
            $user->setPreference('reminder_checked', $preferencePopupReminderChecked);
            $user->setPreference('email_reminder_checked', $preferenceEmailReminderChecked);

        }
    }
Example #4
0
 /**
  * Toggle the preference.
  * Should not be called directly unless you know what you do
  *
  * @param User   $current_user The user
  * @param string $id           the id of the toggler
  */
 public static function togglePreference(User $current_user, $id)
 {
     $current_user->setPreference('toggle_' . $id, 1 - (int) $current_user->getPreference('toggle_' . $id));
 }
Example #5
0
/**
 * Log the user into the application
 *
 * @param UserAuth array $user_auth -- Set user_name and password (password needs to be
 *      in the right encoding for the type of authentication the user is setup for.  For Base
 *      sugar validation, password is the MD5 sum of the plain text password.
 * @param String $application -- The name of the application you are logging in from.  (Currently unused).
 * @return Array(session_id, error) -- session_id is the id of the session that was
 *      created.  Error is set if there was any error during creation.
 */
function login($user_auth, $application)
{
    global $sugar_config, $system_config;
    $error = new SoapError();
    $user = new User();
    $success = false;
    //rrs
    $system_config = new Administration();
    $system_config->retrieveSettings('system');
    $authController = new AuthenticationController(!empty($sugar_config['authenticationClass']) ? $sugar_config['authenticationClass'] : 'SugarAuthenticate');
    //rrs
    $isLoginSuccess = $authController->login($user_auth['user_name'], $user_auth['password'], array('passwordEncrypted' => true));
    $usr_id = $user->retrieve_user_id($user_auth['user_name']);
    if ($usr_id) {
        $user->retrieve($usr_id);
    }
    if ($isLoginSuccess) {
        if ($_SESSION['hasExpiredPassword'] == '1') {
            $error->set_error('password_expired');
            $GLOBALS['log']->fatal('password expired for user ' . $user_auth['user_name']);
            LogicHook::initialize();
            $GLOBALS['logic_hook']->call_custom_logic('Users', 'login_failed');
            return array('id' => -1, 'error' => $error);
        }
        // if
        if (!empty($user) && !empty($user->id) && !$user->is_group) {
            $success = true;
            global $current_user;
            $current_user = $user;
        }
        // if
    } else {
        if ($usr_id && isset($user->user_name) && $user->getPreference('lockout') == '1') {
            $error->set_error('lockout_reached');
            $GLOBALS['log']->fatal('Lockout reached for user ' . $user_auth['user_name']);
            LogicHook::initialize();
            $GLOBALS['logic_hook']->call_custom_logic('Users', 'login_failed');
            return array('id' => -1, 'error' => $error);
        } else {
            if (function_exists('mcrypt_cbc')) {
                $password = decrypt_string($user_auth['password']);
                $authController = new AuthenticationController(!empty($sugar_config['authenticationClass']) ? $sugar_config['authenticationClass'] : 'SugarAuthenticate');
                if ($authController->login($user_auth['user_name'], $password) && isset($_SESSION['authenticated_user_id'])) {
                    $success = true;
                }
                // if
            }
        }
    }
    // else if
    if ($success) {
        session_start();
        global $current_user;
        //$current_user = $user;
        login_success();
        $current_user->loadPreferences();
        $_SESSION['is_valid_session'] = true;
        $_SESSION['ip_address'] = query_client_ip();
        $_SESSION['user_id'] = $current_user->id;
        $_SESSION['type'] = 'user';
        $_SESSION['avail_modules'] = get_user_module_list($current_user);
        $_SESSION['authenticated_user_id'] = $current_user->id;
        $_SESSION['unique_key'] = $sugar_config['unique_key'];
        $current_user->call_custom_logic('after_login');
        return array('id' => session_id(), 'error' => $error);
    }
    $error->set_error('invalid_login');
    $GLOBALS['log']->fatal('SECURITY: User authentication for ' . $user_auth['user_name'] . ' failed');
    LogicHook::initialize();
    $GLOBALS['logic_hook']->call_custom_logic('Users', 'login_failed');
    return array('id' => -1, 'error' => $error);
}
Example #6
0
 * @Last Modified by:   prpr
 * @Last Modified time: 2016-02-06 23:06:26
 *
 * All textures requests of legacy link will be handle here.
 */
$dir = dirname(__FILE__);
require "{$dir}/includes/autoload.inc.php";
if (isset($_GET['type']) && isset($_GET['uname'])) {
    $user = new User($_GET['uname']);
    if (!$user->is_registered) {
        Utils::raise(1, 'Non-existent user.');
    }
    // Cache friendly
    $if_modified_since = isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) ? strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']) : null;
    if ($_GET['type'] == "skin" || $_GET['type'] == "cape") {
        $model_preferrnce = $user->getPreference() == "default" ? "steve" : "alex";
        $model = isset($_GET['model']) && $_GET['model'] == "" ? $model_preferrnce : $_GET['model'];
        if ($if_modified_since >= $user->getLastModified()) {
            header('HTTP/1.0 304 Not Modified');
        } else {
            if ($_GET['type'] == "cape") {
                echo $user->getBinaryTexture('cape');
            } else {
                echo $user->getBinaryTexture($model);
            }
        }
    } else {
        if ($_GET['type'] == "json") {
            if (isset($_GET['api'])) {
                echo $user->getJsonProfile($_GET['api'] == 'csl' ? 0 : 1);
            } else {
 /**
  * Log the user into the application
  *
  * @param UserAuth array $user_auth -- Set user_name and password (password needs to be
  *      in the right encoding for the type of authentication the user is setup for.  For Base
  *      sugar validation, password is the MD5 sum of the plain text password.
  * @param String $application -- The name of the application you are logging in from.  (Currently unused).
  * @param array $name_value_list -- Array of name value pair of extra parameters. As of today only 'language' and 'notifyonsave' is supported
  * @return Array - id - String id is the session_id of the session that was created.
  * 				 - module_name - String - module name of user
  * 				 - name_value_list - Array - The name value pair of user_id, user_name, user_language, user_currency_id, user_currency_name,
  *                                         - user_default_team_id, user_is_admin, user_default_dateformat, user_default_timeformat
  * @exception 'SoapFault' -- The SOAP error, if any
  */
 public function login($user_auth, $application, $name_value_list = array())
 {
     $GLOBALS['log']->info("Begin: SugarWebServiceImpl->login({$user_auth['user_name']}, {$application}, " . print_r($name_value_list, true) . ")");
     global $sugar_config, $system_config;
     $error = new SoapError();
     $user = new User();
     $success = false;
     //rrs
     $system_config = new Administration();
     $system_config->retrieveSettings('system');
     $authController = new AuthenticationController(!empty($sugar_config['authenticationClass']) ? $sugar_config['authenticationClass'] : 'SugarAuthenticate');
     //rrs
     if (!empty($user_auth['encryption']) && $user_auth['encryption'] === 'PLAIN' && $authController->authController->userAuthenticateClass != "LDAPAuthenticateUser") {
         $user_auth['password'] = md5($user_auth['password']);
     }
     $isLoginSuccess = $authController->login($user_auth['user_name'], $user_auth['password'], array('passwordEncrypted' => true));
     $usr_id = $user->retrieve_user_id($user_auth['user_name']);
     if ($usr_id) {
         $user->retrieve($usr_id);
     }
     if ($isLoginSuccess) {
         if ($_SESSION['hasExpiredPassword'] == '1') {
             $error->set_error('password_expired');
             $GLOBALS['log']->fatal('password expired for user ' . $user_auth['user_name']);
             LogicHook::initialize();
             $GLOBALS['logic_hook']->call_custom_logic('Users', 'login_failed');
             self::$helperObject->setFaultObject($error);
             return;
         }
         if (!empty($user) && !empty($user->id) && !$user->is_group) {
             $success = true;
             global $current_user;
             $current_user = $user;
         }
     } else {
         if ($usr_id && isset($user->user_name) && $user->getPreference('lockout') == '1') {
             $error->set_error('lockout_reached');
             $GLOBALS['log']->fatal('Lockout reached for user ' . $user_auth['user_name']);
             LogicHook::initialize();
             $GLOBALS['logic_hook']->call_custom_logic('Users', 'login_failed');
             self::$helperObject->setFaultObject($error);
             return;
         } else {
             if (function_exists('mcrypt_cbc') && $authController->authController->userAuthenticateClass == "LDAPAuthenticateUser" && (empty($user_auth['encryption']) || $user_auth['encryption'] !== 'PLAIN')) {
                 $password = self::$helperObject->decrypt_string($user_auth['password']);
                 $authController->loggedIn = false;
                 // reset login attempt to try again with decrypted password
                 if ($authController->login($user_auth['user_name'], $password) && isset($_SESSION['authenticated_user_id'])) {
                     $success = true;
                 }
             } else {
                 if ($authController->authController->userAuthenticateClass == "LDAPAuthenticateUser" && (empty($user_auth['encryption']) || $user_auth['encryption'] == 'PLAIN')) {
                     $authController->loggedIn = false;
                     // reset login attempt to try again with md5 password
                     if ($authController->login($user_auth['user_name'], md5($user_auth['password']), array('passwordEncrypted' => true)) && isset($_SESSION['authenticated_user_id'])) {
                         $success = true;
                     } else {
                         $error->set_error('ldap_error');
                         LogicHook::initialize();
                         $GLOBALS['logic_hook']->call_custom_logic('Users', 'login_failed');
                         self::$helperObject->setFaultObject($error);
                         return;
                     }
                 }
             }
         }
     }
     if ($success) {
         session_start();
         global $current_user;
         //$current_user = $user;
         self::$helperObject->login_success($name_value_list);
         $current_user->loadPreferences();
         $_SESSION['is_valid_session'] = true;
         $_SESSION['ip_address'] = query_client_ip();
         $_SESSION['user_id'] = $current_user->id;
         $_SESSION['type'] = 'user';
         $_SESSION['avail_modules'] = self::$helperObject->get_user_module_list($current_user);
         $_SESSION['authenticated_user_id'] = $current_user->id;
         $_SESSION['unique_key'] = $sugar_config['unique_key'];
         $GLOBALS['log']->info('End: SugarWebServiceImpl->login - successful login');
         $current_user->call_custom_logic('after_login');
         $nameValueArray = array();
         global $current_language;
         $nameValueArray['user_id'] = self::$helperObject->get_name_value('user_id', $current_user->id);
         $nameValueArray['user_name'] = self::$helperObject->get_name_value('user_name', $current_user->user_name);
         $nameValueArray['user_language'] = self::$helperObject->get_name_value('user_language', $current_language);
         $cur_id = $current_user->getPreference('currency');
         $nameValueArray['user_currency_id'] = self::$helperObject->get_name_value('user_currency_id', $cur_id);
         $nameValueArray['user_is_admin'] = self::$helperObject->get_name_value('user_is_admin', is_admin($current_user));
         $nameValueArray['user_default_team_id'] = self::$helperObject->get_name_value('user_default_team_id', $current_user->default_team);
         $nameValueArray['user_default_dateformat'] = self::$helperObject->get_name_value('user_default_dateformat', $current_user->getPreference('datef'));
         $nameValueArray['user_default_timeformat'] = self::$helperObject->get_name_value('user_default_timeformat', $current_user->getPreference('timef'));
         $num_grp_sep = $current_user->getPreference('num_grp_sep');
         $dec_sep = $current_user->getPreference('dec_sep');
         $nameValueArray['user_number_seperator'] = self::$helperObject->get_name_value('user_number_seperator', empty($num_grp_sep) ? $sugar_config['default_number_grouping_seperator'] : $num_grp_sep);
         $nameValueArray['user_decimal_seperator'] = self::$helperObject->get_name_value('user_decimal_seperator', empty($dec_sep) ? $sugar_config['default_decimal_seperator'] : $dec_sep);
         $nameValueArray['mobile_max_list_entries'] = self::$helperObject->get_name_value('mobile_max_list_entries', $sugar_config['wl_list_max_entries_per_page']);
         $nameValueArray['mobile_max_subpanel_entries'] = self::$helperObject->get_name_value('mobile_max_subpanel_entries', $sugar_config['wl_list_max_entries_per_subpanel']);
         $currencyObject = new Currency();
         $currencyObject->retrieve($cur_id);
         $nameValueArray['user_currency_name'] = self::$helperObject->get_name_value('user_currency_name', $currencyObject->name);
         $_SESSION['user_language'] = $current_language;
         return array('id' => session_id(), 'module_name' => 'Users', 'name_value_list' => $nameValueArray);
     }
     LogicHook::initialize();
     $GLOBALS['logic_hook']->call_custom_logic('Users', 'login_failed');
     $error->set_error('invalid_login');
     self::$helperObject->setFaultObject($error);
     $GLOBALS['log']->error('End: SugarWebServiceImpl->login - failed login');
 }
Example #8
0
 /**
  * Log the user into the application
  *
  * @param UserAuth array $user_auth -- Set user_name and password (password needs to be
  *      in the right encoding for the type of authentication the user is setup for.  For Base
  *      sugar validation, password is the MD5 sum of the plain text password.
  * @param String $application -- The name of the application you are logging in from.  (Currently unused).
  * @param array $name_value_list -- Array of name value pair of extra parameters. As of today only 'language' and 'notifyonsave' is supported
  * @return Array - id - String id is the session_id of the session that was created.
  * 				 - module_name - String - module name of user
  * 				 - name_value_list - Array - The name value pair of user_id, user_name, user_language, user_currency_id, user_currency_name,
  *                                         - user_default_team_id, user_is_admin, user_default_dateformat, user_default_timeformat
  * @exception 'SoapFault' -- The SOAP error, if any
  */
 public function login($user_auth, $application, $name_value_list)
 {
     $GLOBALS['log']->info('Begin: SugarWebServiceImpl->login');
     global $sugar_config, $system_config;
     $error = new SoapError();
     $user = new User();
     $success = false;
     if (!empty($user_auth['encryption']) && $user_auth['encryption'] === 'PLAIN') {
         $user_auth['password'] = md5($user_auth['password']);
     }
     //rrs
     $system_config = new Administration();
     $system_config->retrieveSettings('system');
     $authController = new AuthenticationController();
     //rrs
     $isLoginSuccess = $authController->login($user_auth['user_name'], $user_auth['password'], array('passwordEncrypted' => true));
     $usr_id = $user->retrieve_user_id($user_auth['user_name']);
     if ($usr_id) {
         $user->retrieve($usr_id);
     }
     if ($isLoginSuccess) {
         if ($_SESSION['hasExpiredPassword'] == '1') {
             $error->set_error('password_expired');
             $GLOBALS['log']->fatal('password expired for user ' . $user_auth['user_name']);
             LogicHook::initialize();
             $GLOBALS['logic_hook']->call_custom_logic('Users', 'login_failed');
             self::$helperObject->setFaultObject($error);
             return;
         }
         if (!empty($user) && !empty($user->id) && !$user->is_group) {
             $success = true;
             global $current_user;
             $current_user = $user;
         }
     } else {
         if ($usr_id && isset($user->user_name) && $user->getPreference('lockout') == '1') {
             $error->set_error('lockout_reached');
             $GLOBALS['log']->fatal('Lockout reached for user ' . $user_auth['user_name']);
             LogicHook::initialize();
             $GLOBALS['logic_hook']->call_custom_logic('Users', 'login_failed');
             self::$helperObject->setFaultObject($error);
             return;
         } else {
             if (function_exists('mcrypt_cbc')) {
                 $password = self::$helperObject->decrypt_string($user_auth['password']);
                 if ($authController->login($user_auth['user_name'], $password) && isset($_SESSION['authenticated_user_id'])) {
                     $success = true;
                 }
             }
         }
     }
     if ($success) {
         session_start();
         global $current_user;
         //$current_user = $user;
         self::$helperObject->login_success($name_value_list);
         $current_user->loadPreferences();
         $_SESSION['is_valid_session'] = true;
         $_SESSION['ip_address'] = query_client_ip();
         $_SESSION['user_id'] = $current_user->id;
         $_SESSION['type'] = 'user';
         $_SESSION['avail_modules'] = self::$helperObject->get_user_module_list($current_user);
         $_SESSION['authenticated_user_id'] = $current_user->id;
         $_SESSION['unique_key'] = $sugar_config['unique_key'];
         $current_user->call_custom_logic('after_login');
         $GLOBALS['log']->info('End: SugarWebServiceImpl->login - succesful login');
         $nameValueArray = array();
         global $current_language;
         $nameValueArray['user_id'] = self::$helperObject->get_name_value('user_id', $current_user->id);
         $nameValueArray['user_name'] = self::$helperObject->get_name_value('user_name', $current_user->user_name);
         $nameValueArray['user_language'] = self::$helperObject->get_name_value('user_language', $current_language);
         $cur_id = $current_user->getPreference('currency');
         $nameValueArray['user_currency_id'] = self::$helperObject->get_name_value('user_currency_id', $cur_id);
         $nameValueArray['user_is_admin'] = self::$helperObject->get_name_value('user_is_admin', is_admin($current_user));
         $nameValueArray['user_default_team_id'] = self::$helperObject->get_name_value('user_default_team_id', $current_user->default_team);
         $nameValueArray['user_default_dateformat'] = self::$helperObject->get_name_value('user_default_dateformat', $current_user->getPreference('datef'));
         $nameValueArray['user_default_timeformat'] = self::$helperObject->get_name_value('user_default_timeformat', $current_user->getPreference('timef'));
         $currencyObject = new Currency();
         $currencyObject->retrieve($cur_id);
         $nameValueArray['user_currency_name'] = self::$helperObject->get_name_value('user_currency_name', $currencyObject->name);
         $_SESSION['user_language'] = $current_language;
         return array('id' => session_id(), 'module_name' => 'Users', 'name_value_list' => $nameValueArray);
     }
     LogicHook::initialize();
     $GLOBALS['logic_hook']->call_custom_logic('Users', 'login_failed');
     $error->set_error('invalid_login');
     self::$helperObject->setFaultObject($error);
     $GLOBALS['log']->info('End: SugarWebServiceImpl->login - failed login');
 }
        if (!$authController->sessionAuthenticate()) {
            // if the object we get back is null for some reason, this will break - like user prefs are corrupted
            $GLOBALS['log']->fatal('User retrieval for ID: (' . $_SESSION['authenticated_user_id'] . ') does not exist in database or retrieval failed catastrophically.  Calling session_destroy() and sending user to Login page.');
            session_destroy();
            header('Location: index.php?action=Login&module=Users');
        }
        $GLOBALS['log']->debug('Current user is: ' . $current_user->user_name);
    }
}
////	END USER LOGIN AUTHENTICATION
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
////	USER TIMEZONE SETTING
// ut=0 => upgrade script set users's timezone
if (isset($_SESSION['authenticated_user_id']) && !empty($_SESSION['authenticated_user_id'])) {
    $ut = $current_user->getPreference('ut');
    if (empty($ut) && $_REQUEST['action'] != 'SaveTimezone') {
        $module = 'Users';
        $action = 'SetTimezone';
        $record = $current_user->id;
    }
}
////	END USER TIMEZONE SETTING
///////////////////////////////////////////////////////////////////////////////
$GLOBALS['log']->debug($_REQUEST);
$skipHeaders = false;
$skipFooters = false;
// Set the current module to be the module that was passed in
if (!empty($module)) {
    $currentModule = $module;
}
 * All Rights Reserved.
 * Contributor(s): ______________________________________.
 ********************************************************************************/
require_once 'include/Sugar_Smarty.php';
require_once 'modules/ACL/ACLController.php';
global $app_list_strings;
$focus = new User();
$focus->retrieve($_REQUEST['record']);
$sugar_smarty = new Sugar_Smarty();
$sugar_smarty->assign('MOD', $mod_strings);
$sugar_smarty->assign('APP', $app_strings);
$sugar_smarty->assign('APP_LIST', $app_list_strings);
$categories = ACLAction::getUserActions($_REQUEST['record'], true);
//clear out any removed tabs from user display
if (!is_admin($current_user)) {
    $tabs = $focus->getPreference('display_tabs');
    global $modInvisList, $modInvisListActivities;
    if (!empty($tabs)) {
        foreach ($categories as $key => $value) {
            if (!in_array($key, $tabs) && !in_array($key, $modInvisList) && !in_array($key, $modInvisListActivities)) {
                unset($categories[$key]);
            }
        }
    }
}
$names = array();
$tdwidth = 10;
$names = ACLAction::setupCategoriesMatrix($categories);
$sugar_smarty->assign('APP', $app_list_strings);
$sugar_smarty->assign('CATEGORIES', $categories);
$sugar_smarty->assign('TDWIDTH', $tdwidth);
Example #11
0
 public function testDeprecatedUserPreferenceInterface()
 {
     User::setPreference('deprecated_pref', 'dog', 0, 'global', $this->_user);
     $this->assertEquals('dog', User::getPreference('deprecated_pref', 'global', $this->_user));
 }
Example #12
0
 /**
  * Changes a password for a user from old to new
  *
  * @param  User   $bean User bean
  * @param  string $old  Old password
  * @param  string $new  New password
  * @return array
  */
 protected function changePassword($bean, $old, $new)
 {
     if ($bean->change_password($old, $new)) {
         return array('valid' => true, 'message' => 'Password updated.', 'expiration' => $bean->getPreference('loginexpiration'));
     }
     //Legacy change_password populates user bean with an error_string on error
     $errorMessage = isset($bean->error_string) ? $bean->error_string : $GLOBALS['app_strings']['LBL_PASSWORD_UPDATE_GENERIC_ISSUE'];
     return array('valid' => false, 'message' => $errorMessage);
 }
Example #13
0
function migrate_sugar_favorite_reports()
{
    require_once 'modules/SugarFavorites/SugarFavorites.php';
    // Need to repair the RC1 instances that have incorrect GUIDS
    $deleteRows = array();
    $res = $GLOBALS['db']->query("select * from sugarfavorites where module='Reports'");
    while ($row = $GLOBALS['db']->fetchByAssoc($res)) {
        $expectedId = SugarFavorites::generateGUID('Reports', $row['record_id'], $row['assigned_user_id']);
        if ($row['id'] != $expectedId) {
            $deleteRows[] = $row['id'];
        }
    }
    $GLOBALS['db']->query("delete from sugarfavorites where id in ('" . implode("','", $deleteRows) . "')");
    // End Repair
    $active_users = array();
    $res = $GLOBALS['db']->query("select id, user_name, deleted, status from users where is_group = 0 and portal_only = 0 and status = 'Active' and deleted = 0");
    while ($row = $GLOBALS['db']->fetchByAssoc($res)) {
        $active_users[] = $row['id'];
    }
    foreach ($active_users as $user_id) {
        $user = new User();
        $user->retrieve($user_id);
        $user_favorites = $user->getPreference('favorites', 'Reports');
        if (!is_array($user_favorites)) {
            $user_favorites = array();
        }
        if (!empty($user_favorites)) {
            foreach ($user_favorites as $report_id => $bool) {
                $fav = new SugarFavorites();
                $record = SugarFavorites::generateGUID('Reports', $report_id, $user_id);
                if (!$fav->retrieve($record, true, false)) {
                    $fav->new_with_id = true;
                }
                $fav->id = $record;
                $fav->module = 'Reports';
                $fav->record_id = $report_id;
                $fav->assigned_user_id = $user->id;
                $fav->created_by = $user->id;
                $fav->modified_user_id = $user->id;
                $fav->deleted = 0;
                $fav->save();
            }
        }
    }
}
Example #14
0
/**
 * upgradeUserPreferences
 * This method updates the user_preferences table and sets the pages/dashlets for users
 * which have ACL access to Trackers so that the Tracker dashlets are set in their user perferences
 *
 */
function upgradeUserPreferences()
{
    global $sugar_config, $sugar_version;
    $uw_strings = return_module_language($GLOBALS['current_language'], 'UpgradeWizard');
    $localization = new Localization();
    $localeCoreDefaults = $localization->getLocaleConfigDefaults();
    // check the current system wide default_locale_name_format and add it to the list if it's not there
    if (empty($sugar_config['name_formats'])) {
        $sugar_config['name_formats'] = $localeCoreDefaults['name_formats'];
        if (!rebuildConfigFile($sugar_config, $sugar_version)) {
            $errors[] = $uw_strings['ERR_UW_CONFIG_WRITE'];
        }
    }
    $currentDefaultLocaleNameFormat = $sugar_config['default_locale_name_format'];
    if ($localization->isAllowedNameFormat($currentDefaultLocaleNameFormat)) {
        upgradeLocaleNameFormat($currentDefaultLocaleNameFormat);
    } else {
        $sugar_config['default_locale_name_format'] = $localeCoreDefaults['default_locale_name_format'];
        if (!rebuildConfigFile($sugar_config, $sugar_version)) {
            $errors[] = $uw_strings['ERR_UW_CONFIG_WRITE'];
        }
        $localization->createInvalidLocaleNameFormatUpgradeNotice();
    }
    $db =& DBManagerFactory::getInstance();
    $result = $db->query("SELECT id FROM users where deleted = '0'");
    while ($row = $db->fetchByAssoc($result)) {
        $current_user = new User();
        $current_user->retrieve($row['id']);
        // get the user's name locale format, check if it's in our list, add it if it's not, keep it as user's default
        $currentUserNameFormat = $current_user->getPreference('default_locale_name_format');
        if ($localization->isAllowedNameFormat($currentUserNameFormat)) {
            upgradeLocaleNameFormat($currentUserNameFormat);
        } else {
            $current_user->setPreference('default_locale_name_format', 's f l', 0, 'global');
            $current_user->savePreferencesToDB();
        }
        $changed = false;
        if (!$current_user->getPreference('calendar_publish_key')) {
            // set publish key if not set already
            $current_user->setPreference('calendar_publish_key', create_guid());
            $changed = true;
        }
        // we need to force save the changes to disk, otherwise we lose them.
        if ($changed) {
            $current_user->savePreferencesToDB();
        }
    }
    //while
}
Example #15
0
$sugar_smarty->assign('REPORTS_TO_ID', $focus->reports_to_id);
$sugar_smarty->assign('REPORTS_TO_NAME', get_assigned_user_name($focus->reports_to_id));
$sugar_smarty->assign('PHONE_HOME', $focus->phone_home);
$sugar_smarty->assign('PHONE_MOBILE', $focus->phone_mobile);
$sugar_smarty->assign('PHONE_WORK', $focus->phone_work);
$sugar_smarty->assign('PHONE_OTHER', $focus->phone_other);
$sugar_smarty->assign('PHONE_FAX', $focus->phone_fax);
$sugar_smarty->assign('EMAIL1', $focus->email1);
$sugar_smarty->assign('EMAIL2', $focus->email2);
$sugar_smarty->assign('ADDRESS_STREET', $focus->address_street);
$sugar_smarty->assign('ADDRESS_CITY', $focus->address_city);
$sugar_smarty->assign('ADDRESS_STATE', $focus->address_state);
$sugar_smarty->assign('ADDRESS_POSTALCODE', $focus->address_postalcode);
$sugar_smarty->assign('ADDRESS_COUNTRY', $focus->address_country);
$sugar_smarty->assign('DESCRIPTION', $focus->description);
$sugar_smarty->assign('EXPORT_DELIMITER', $focus->getPreference('export_delimiter'));
$sugar_smarty->assign('PWDSETTINGS', isset($GLOBALS['sugar_config']['passwordsetting']) ? $GLOBALS['sugar_config']['passwordsetting'] : array());
if (!empty($GLOBALS['sugar_config']['authenticationClass'])) {
    $sugar_smarty->assign('EXTERNAL_AUTH_CLASS_1', $GLOBALS['sugar_config']['authenticationClass']);
    $sugar_smarty->assign('EXTERNAL_AUTH_CLASS', $GLOBALS['sugar_config']['authenticationClass']);
} else {
    if (!empty($GLOBALS['system_config']->settings['system_ldap_enabled'])) {
        $sugar_smarty->assign('EXTERNAL_AUTH_CLASS_1', $mod_strings['LBL_LDAP']);
        $sugar_smarty->assign('EXTERNAL_AUTH_CLASS', $mod_strings['LBL_LDAP_AUTHENTICATION']);
    }
}
if (!empty($focus->external_auth_only)) {
    $sugar_smarty->assign('EXTERNAL_AUTH_ONLY_CHECKED', 'CHECKED');
}
if ($is_current_admin) {
    $sugar_smarty->assign('IS_ADMIN', '1');
$xtpl->assign('PHONE_HOME', $focus->phone_home);
$xtpl->assign('PHONE_MOBILE', $focus->phone_mobile);
$xtpl->assign('PHONE_WORK', $focus->phone_work);
$xtpl->assign('PHONE_OTHER', $focus->phone_other);
$xtpl->assign('PHONE_FAX', $focus->phone_fax);
$xtpl->assign('EMAIL1', $focus->email1);
$xtpl->assign('EMAIL2', $focus->email2);
$xtpl->assign('ADDRESS_STREET', $focus->address_street);
$xtpl->assign('ADDRESS_CITY', $focus->address_city);
$xtpl->assign('ADDRESS_STATE', $focus->address_state);
$xtpl->assign('ADDRESS_POSTALCODE', $focus->address_postalcode);
$xtpl->assign('ADDRESS_COUNTRY', $focus->address_country);
$xtpl->assign('DESCRIPTION', $focus->description);
$xtpl->assign('EXPORT_DELIMITER', getDelimiter());
$xtpl->assign('EXPORT_CHARSET', get_select_options_with_id($locale->availableCharsets, $locale->getExportCharset()));
if ($focus->getPreference('use_real_names') == 'on') {
    $xtpl->assign('USE_REAL_NAMES', 'CHECKED');
}
if ($focus->getPreference('no_opps') == 'on') {
    $xtpl->assign('NO_OPPS', 'CHECKED');
}
///////////////////////////////////////////////////////////////////////////////
////	NEW USER CREATION ONLY
if (empty($focus->id)) {
    $xtpl->assign('LBL_NEW_PASSWORD1', $mod_strings['LBL_NEW_PASSWORD1'] . ': <span class="required">' . $app_strings['LBL_REQUIRED_SYMBOL'] . '</span>');
    $xtpl->assign('LBL_NEW_PASSWORD2', $mod_strings['LBL_NEW_PASSWORD2'] . ': <span class="required">' . $app_strings['LBL_REQUIRED_SYMBOL'] . '</span>');
    $xtpl->assign('NEW_PASSWORD1', '<input id="new_password1" name="new_password1" tabindex="2" type="password" size="25" maxlength="25">');
    $xtpl->assign('NEW_PASSWORD2', '<input id="new_password2" name="new_password2" tabindex="2" type="password" size="25" maxlength="25">');
}
////	END NEW USER CREATION ONLY
///////////////////////////////////////////////////////////////////////////////
Example #17
0
 public function testsetUserPrivGuid()
 {
     //unset and reconnect Db to resolve mysqli fetch exeception
     global $db;
     unset($db->database);
     $db->checkConnection();
     $user = new User();
     $user->retrieve(1);
     $user->setUserPrivGuid();
     $result = $user->getPreference('userPrivGuid', 'global', $user);
     $this->assertTrue(isset($result));
     $this->assertEquals(36, strlen($result));
 }
 /**
  * Get the users default IE account id
  *
  * @param User $user
  * @return string
  */
 function getUsersDefaultOutboundServerId($user)
 {
     $id = $user->getPreference($this->keyForUsersDefaultIEAccount, 'Emails', $user);
     //If no preference has been set, grab the default system id.
     if (empty($id)) {
         $oe = new OutboundEmail();
         $system = $oe->getSystemMailerSettings();
         $id = empty($system->id) ? '' : $system->id;
     }
     return $id;
 }
Example #19
0
 /**
  * Display a report. Choose the report among
  *  - the requested 'select_report'
  *  - the last viewed report (stored in preferences)
  *  - the default report of this tracker
  *
  * If the user request a 'link-artifact-id' then display also manual and recent 
  * panels to ease the selection of artifacts to link
  *
  * @param Tracker_IDisplayTrackerLayout  $layout          Displays the page header and footer
  * @param Codendi_Request                $request         The request
  * @param User                           $current_user    The user who made the request
  *
  * @return void
  */
 public function displayAReport(Tracker_IDisplayTrackerLayout $layout, $request, $current_user)
 {
     $report = null;
     //Does the user wants to change its report?
     if ($request->get('select_report') && $request->isPost()) {
         //Is the report id valid
         if ($report = $this->getReportFactory()->getReportById($request->get('select_report'), $current_user->getid())) {
             $current_user->setPreference('tracker_' . $this->id . '_last_report', $report->id);
         }
     }
     //If no valid report found. Search the last viewed report for the user
     if (!$report) {
         if ($report_id = $current_user->getPreference('tracker_' . $this->id . '_last_report')) {
             $report = $this->getReportFactory()->getReportById($report_id, $current_user->getid());
         }
     }
     //If no valid report found. Take the default one
     if (!$report) {
         $report = $this->getReportFactory()->getDefaultReportsByTrackerId($this->id);
     }
     $link_artifact_id = (int) $request->get('link-artifact-id');
     if ($link_artifact_id && !$request->get('report-only')) {
         $linked_artifact = Tracker_ArtifactFactory::instance()->getArtifactById($link_artifact_id);
         if (!$linked_artifact) {
             $err = "Linked artifact not found or doesn't exist";
             if (!$request->isAjax()) {
                 $GLOBALS['Response']->addFeedback('error', $err);
                 $GLOBALS['Response']->redirect('/');
             }
             die($err);
         }
         if (!$request->isAjax()) {
             //screwed up
             $GLOBALS['Response']->addFeedback('error', 'Something is wrong with your request');
             $GLOBALS['Response']->redirect(TRACKER_BASE_URL . '/?aid=' . $linked_artifact->getId());
         }
         echo $linked_artifact->fetchTitle($GLOBALS['Language']->getText('plugin_tracker_artifactlink', 'title_prefix'));
         echo '<input type="hidden" id="link-artifact-id" value="' . (int) $link_artifact_id . '" />';
         echo '<table id="tracker-link-artifact-different-ways" cellpadding="0" cellspacing="0" border="0"><tbody><tr>';
         //the fast ways
         echo '<td id="tracker-link-artifact-fast-ways">';
         //Manual
         echo '<div id="tracker-link-artifact-manual-way">';
         echo '<div class="boxtitle">';
         echo $GLOBALS['HTML']->getImage('ic/lightning-white.png', array('style' => 'vertical-align:middle')) . '&nbsp;';
         echo $GLOBALS['Language']->getText('plugin_tracker_artifactlink', 'manual_panel_title');
         echo '</div>';
         echo '<div class="tracker-link-artifact-manual-way-content">';
         echo $GLOBALS['Language']->getText('plugin_tracker_artifactlink', 'manual_panel_desc');
         echo '<p><label for="link-artifact-manual-field">';
         echo $GLOBALS['Language']->getText('plugin_tracker_artifactlink', 'manual_panel_label');
         echo '</label><br />';
         echo '<input type="text" name="link-artifact[manual]" value="" id="link-artifact-manual-field" />';
         echo '</p>';
         echo '</div>';
         echo '</div>';
         //History
         echo '<div id="tracker-link-artifact-recentitems-way">';
         echo '<div class="boxtitle">';
         echo $GLOBALS['HTML']->getImage('ic/star-white.png', array('style' => 'vertical-align:middle')) . '&nbsp;';
         echo $GLOBALS['Language']->getText('plugin_tracker_artifactlink', 'recent_panel_title');
         echo '</div>';
         echo '<div class="tracker-link-artifact-recentitems-way-content">';
         if ($recent_items = $current_user->getRecentElements()) {
             echo $GLOBALS['Language']->getText('plugin_tracker_artifactlink', 'recent_panel_desc');
             echo '<ul>';
             foreach ($recent_items as $item) {
                 if ($item['id'] != $link_artifact_id) {
                     echo '<li>';
                     echo '<input type="checkbox" 
                                  name="link-artifact[recent][]" 
                                  value="' . (int) $item['id'] . '" /> ';
                     echo $item['link'];
                     echo '</li>';
                 }
             }
             echo '</ul>';
         }
         echo '</div>';
         echo '</div>';
         //end of fast ways
         echo '</td>';
         //And the slow way (aka need to search)
         if ($report) {
             echo '<td><div id="tracker-link-artifact-slow-way">';
             echo '<div class="boxtitle">';
             echo $GLOBALS['HTML']->getImage('ic/magnifier-white.png', array('style' => 'vertical-align:middle')) . '&nbsp;';
             echo $GLOBALS['Language']->getText('plugin_tracker_artifactlink', 'search_panel_title');
             echo '</div>';
             echo '<div id="tracker-link-artifact-slow-way-content">';
         }
     }
     if ($report) {
         $report->process($layout, $request, $current_user);
     } elseif (!$link_artifact_id) {
         $this->displayHeader($layout, $this->name, array());
         echo $GLOBALS['Language']->getText('plugin_tracker', 'no_reports_available');
         $this->displayFooter($layout);
     }
     if ($link_artifact_id && !$request->get('report-only')) {
         if ($report) {
             echo '</div></div></td>';
             //end of slow
         }
         echo '</tr></tbody></table>';
         //end of ways
         echo '<div class="tracker-link-artifact-controls">';
         echo '<a href="#cancel" onclick="myLightWindow.deactivate(); return false;">&laquo;&nbsp;' . $GLOBALS['Language']->getText('global', 'btn_cancel') . '</a>';
         echo ' ';
         echo '<button name="link-artifact-submit">' . $GLOBALS['Language']->getText('global', 'btn_submit') . '</button>';
         echo '</div>';
     }
 }
Example #20
0
 /**
  * returns User's email address based on descending order of preferences
  *
  * @param string id GUID of target user if needed
  * @return array Assoc array for an email and name
  */
 function getEmailInfo($id = '')
 {
     $user = $this;
     if (!empty($id)) {
         $user = new User();
         $user->retrieve($id);
     }
     // from name
     $fromName = $user->getPreference('mail_fromname');
     if (empty($fromName)) {
         // cn: bug 8586 - localized name format
         $fromName = $user->full_name;
     }
     // from address
     $fromaddr = $user->getPreference('mail_fromaddress');
     if (empty($fromaddr)) {
         if (!empty($user->email1) && isset($user->email1)) {
             $fromaddr = $user->email1;
         } elseif (!empty($user->email2) && isset($user->email2)) {
             $fromaddr = $user->email2;
         } else {
             $r = $user->db->query("SELECT value FROM config WHERE name = 'fromaddress'");
             $a = $user->db->fetchByAssoc($r);
             $fromddr = $a['value'];
         }
     }
     $ret['name'] = $fromName;
     $ret['email'] = $fromaddr;
     return $ret;
 }
Example #21
0
                    $json['cape']['errno'] = 0;
                    $json['cape']['msg'] = "披风上传成功!";
                } else {
                    $json['cape']['errno'] = 1;
                    $json['cape']['msg'] = "出现了奇怪的错误。。请联系作者 :(";
                }
            }
        }
    } else {
        $json['errno'] = 1;
        $json['msg'] = "无效的 token,请先登录。";
    }
} else {
    if ($action == "model") {
        if (Utils::getValue('token', $_SESSION) == $user->getToken()) {
            $new_model = $user->getPreference() == "default" ? "slim" : "default";
            $user->setPreference($new_model);
            $json['errno'] = 0;
            $json['msg'] = "优先模型已经更改为 " . $user->getPreference() . "。";
        } else {
            $json['errno'] = 1;
            $json['msg'] = "无效的 token,请先登录。";
        }
    }
}
function checkFile()
{
    global $json;
    if (!(Utils::getValue('skin_file', $_FILES) || Utils::getValue('cape_file', $_FILES))) {
        $json['errno'] = 1;
        $json['msg'] = "什么文件都没有诶?";