コード例 #1
0
 function deleteUserSetting($name)
 {
     $retval = UserSettingFactory::deleteUserSetting($this->getCurrentUserObject()->getId(), $name);
     return $this->returnHandler($retval);
 }
コード例 #2
0
 /**
  * Returns array of notifications message to be displayed to the user.
  * @param string $action Action that is being performed, possible values: 'login', 'preference', 'notification', 'pay_period'
  * @return array
  */
 function getNotifications($action = FALSE)
 {
     global $config_vars, $disable_database_connection;
     $retarr = FALSE;
     //Skip this step if disable_database_connection is enabled or the user is going through the installer still
     switch (strtolower($action)) {
         case 'login':
             if ((!isset($disable_database_connection) or isset($disable_database_connection) and $disable_database_connection != TRUE) and (!isset($config_vars['other']['installer_enabled']) or isset($config_vars['other']['installer_enabled']) and $config_vars['other']['installer_enabled'] != TRUE)) {
                 //Get all system settings, so they can be used even if the user isn't logged in, such as the login page.
                 $sslf = new SystemSettingListFactory();
                 $system_settings = $sslf->getAllArray();
             }
             unset($sslf);
             //Check license validity
             if ((DEPLOYMENT_ON_DEMAND == FALSE and $this->getCurrentCompanyObject()->getId() == 1 or isset($config_vars['other']['primary_company_id']) and $this->getCurrentCompanyObject()->getId() == $config_vars['other']['primary_company_id']) and getTTProductEdition() > 10) {
                 if (!isset($system_settings['license'])) {
                     $system_settings['license'] = NULL;
                 }
                 $license = new TTLicense();
                 $license_validate = $license->validateLicense($system_settings['license']);
                 $license_message = $license->getFullErrorMessage($license_validate, TRUE);
                 if ($license_message != '') {
                     $destination_url = 'http://www.timetrex.com/r.php?id=899';
                     if ($license_validate === TRUE) {
                         //License likely expires soon.
                         $retarr[] = array('delay' => 0, 'bg_color' => '#FFFF00', 'message' => TTi18n::getText('WARNING: %1', $license_message), 'destination' => $destination_url);
                     } else {
                         //License error.
                         $retarr[] = array('delay' => -1, 'bg_color' => '#FF0000', 'message' => TTi18n::getText('WARNING: %1', $license_message), 'destination' => $destination_url);
                     }
                 }
                 unset($license, $license_validate, $license_message, $destination);
             }
             //System Requirements not being met.
             if (isset($system_settings['valid_install_requirements']) and DEPLOYMENT_ON_DEMAND == FALSE and (int) $system_settings['valid_install_requirements'] == 0) {
                 $retarr[] = array('delay' => -1, 'bg_color' => '#FF0000', 'message' => TTi18n::getText('WARNING: %1 system requirement check has failed! Please contact your %1 administrator immediately to re-run the %1 installer to correct the issue.', APPLICATION_NAME), 'destination' => NULL);
             }
             //Check version mismatch
             if (isset($system_settings['system_version']) and DEPLOYMENT_ON_DEMAND == FALSE and APPLICATION_VERSION != $system_settings['system_version']) {
                 $retarr[] = array('delay' => -1, 'bg_color' => '#FF0000', 'message' => TTi18n::getText('WARNING: %1 application version does not match database version. Please re-run the %1 installer to complete the upgrade process.', APPLICATION_NAME), 'destination' => NULL);
             }
             //Only display message to the primary company.
             if (time() - (int) APPLICATION_VERSION_DATE > 86400 * 475 and ($this->getCurrentCompanyObject()->getId() == 1 or isset($config_vars['other']['primary_company_id']) and $this->getCurrentCompanyObject()->getId() == $config_vars['other']['primary_company_id'])) {
                 //~1yr and 3mths
                 $retarr[] = array('delay' => -1, 'bg_color' => '#FF0000', 'message' => TTi18n::getText('WARNING: This %1 version (v%2) is severely out of date and may no longer be supported. Please upgrade to the latest version as soon as possible as invalid calculations may already be occurring.', array(APPLICATION_NAME, APPLICATION_VERSION)), 'destination' => NULL);
             }
             //New version available notification.
             if (DEMO_MODE == FALSE and (isset($system_settings['new_version']) and $system_settings['new_version'] == 1) and ($this->getCurrentCompanyObject()->getId() == 1 or isset($config_vars['other']['primary_company_id']) and $this->getCurrentCompanyObject()->getId() == $config_vars['other']['primary_company_id'])) {
                 //Only display this every two weeks.
                 $new_version_available_notification_arr = UserSettingFactory::getUserSetting($this->getCurrentUserObject()->getID(), 'new_version_available_notification');
                 if (!isset($new_version_available_notification_arr['value']) or isset($new_version_available_notification_arr['value']) and $new_version_available_notification_arr['value'] <= time() - 86400 * 14) {
                     UserSettingFactory::setUserSetting($this->getCurrentUserObject()->getID(), 'new_version_available_notification', time());
                     $retarr[] = array('delay' => -1, 'bg_color' => '#FFFF00', 'message' => TTi18n::getText('NOTICE: A new version of %1 available, it is highly recommended that you upgrade as soon as possible. Click here to download the latest version.', array(APPLICATION_NAME)), 'destination' => getTTProductEdition() == TT_PRODUCT_COMMUNITY ? 'http://www.timetrex.com/r.php?id=19' : 'http://www.timetrex.com/r.php?id=9');
                 }
                 unset($new_version_available_notification);
             }
             //Check for major new version.
             $new_version_notification_arr = UserSettingFactory::getUserSetting($this->getCurrentUserObject()->getID(), 'new_version_notification');
             if (DEMO_MODE == FALSE and (!isset($config_vars['branding']['application_name']) or ($this->getCurrentCompanyObject()->getId() == 1 or isset($config_vars['other']['primary_company_id']) and $this->getCurrentCompanyObject()->getId() == $config_vars['other']['primary_company_id'])) and $this->getPermissionObject()->getLevel() >= 20 and $this->getCurrentUserObject()->getCreatedDate() <= APPLICATION_VERSION_DATE and (!isset($new_version_notification_arr['value']) or isset($new_version_notification_arr['value']) and Misc::MajorVersionCompare(APPLICATION_VERSION, $new_version_notification_arr['value'], '>'))) {
                 UserSettingFactory::setUserSetting($this->getCurrentUserObject()->getID(), 'new_version_notification', APPLICATION_VERSION);
                 $retarr[] = array('delay' => -1, 'bg_color' => '#FFFF00', 'message' => TTi18n::getText('NOTICE: Your instance of %1 has been upgraded to v%2, click here to see whats new.', array(APPLICATION_NAME, APPLICATION_VERSION)), 'destination' => 'http://www.timetrex.com/r.php?id=300');
             }
             unset($new_version_notification);
             //Check installer enabled.
             if (isset($config_vars['other']['installer_enabled']) and $config_vars['other']['installer_enabled'] == 1) {
                 $retarr[] = array('delay' => -1, 'bg_color' => '#FF0000', 'message' => TTi18n::getText('WARNING: %1 is currently in INSTALL MODE. Please go to your timetrex.ini.php file and set "installer_enabled" to "FALSE".', APPLICATION_NAME), 'destination' => NULL);
             }
             //Make sure CronJobs are running correctly.
             $cjlf = new CronJobListFactory();
             $cjlf->getMostRecentlyRun();
             if ($cjlf->getRecordCount() > 0) {
                 //Is last run job more then 48hrs old?
                 $cj_obj = $cjlf->getCurrent();
                 if (PRODUCTION == TRUE and DEMO_MODE == FALSE and $cj_obj->getLastRunDate() < time() - 172800 and $cj_obj->getCreatedDate() < time() - 172800) {
                     $retarr[] = array('delay' => -1, 'bg_color' => '#FF0000', 'message' => TTi18n::getText('WARNING: Critical maintenance jobs have not run in the last 48hours. Please contact your %1 administrator immediately.', APPLICATION_NAME), 'destination' => NULL);
                 }
             }
             unset($cjlf, $cj_obj);
             //Check if any pay periods are past their transaction date and not closed.
             if (DEMO_MODE == FALSE and $this->getPermissionObject()->Check('pay_period_schedule', 'enabled') and $this->getPermissionObject()->Check('pay_period_schedule', 'view')) {
                 $pplf = TTnew('PayPeriodListFactory');
                 $pplf->getByCompanyIdAndStatusAndTransactionDate($this->getCurrentCompanyObject()->getId(), array(10, 30), TTDate::getBeginDayEpoch(time()));
                 //Open or Post Adjustment pay periods.
                 if ($pplf->getRecordCount() > 0) {
                     foreach ($pplf as $pp_obj) {
                         if ($pp_obj->getCreatedDate() < time() - 86400 * 40) {
                             //Ignore pay period schedules newer than 40 days. They are automatically closed after 45 days.
                             $retarr[] = array('delay' => 0, 'bg_color' => '#FF0000', 'message' => TTi18n::getText('WARNING: Pay periods past their transaction date have not been closed yet. It\'s critical that these pay periods are closed to prevent data loss, click here to close them now.'), 'destination' => array('menu_name' => 'Pay Periods'));
                             break;
                         }
                     }
                 }
                 unset($pplf, $pp_obj);
             }
             //CHeck for unread messages
             $mclf = new MessageControlListFactory();
             $unread_messages = $mclf->getNewMessagesByCompanyIdAndUserId($this->getCurrentCompanyObject()->getId(), $this->getCurrentUserObject()->getId());
             Debug::text('UnRead Messages: ' . $unread_messages, __FILE__, __LINE__, __METHOD__, 10);
             if ($unread_messages > 0) {
                 $retarr[] = array('delay' => 25, 'bg_color' => '#FFFF00', 'message' => TTi18n::getText('NOTICE: You have %1 new message(s) waiting, click here to read them now.', $unread_messages), 'destination' => array('menu_name' => 'Messages'));
             }
             unset($mclf, $unread_messages);
             if (DEMO_MODE == FALSE) {
                 $elf = new ExceptionListFactory();
                 $elf->getFlaggedExceptionsByUserIdAndPayPeriodStatus($this->getCurrentUserObject()->getId(), 10);
                 $display_exception_flag = FALSE;
                 if ($elf->getRecordCount() > 0) {
                     foreach ($elf as $e_obj) {
                         if ($e_obj->getColumn('severity_id') == 30) {
                             $display_exception_flag = 'red';
                         }
                         break;
                     }
                 }
                 if (isset($display_exception_flag) and $display_exception_flag !== FALSE) {
                     Debug::Text('Exception Flag to Display: ' . $display_exception_flag, __FILE__, __LINE__, __METHOD__, 10);
                     $retarr[] = array('delay' => 30, 'bg_color' => '#FFFF00', 'message' => TTi18n::getText('NOTICE: You have critical severity exceptions pending, click here to view them now.'), 'destination' => array('menu_name' => 'Exceptions'));
                 }
                 unset($elf, $e_obj, $display_exception_flag);
             }
             if (DEMO_MODE == FALSE and $this->getPermissionObject()->getLevel() >= 20 and ($this->getCurrentUserObject()->getWorkEmail() == '' and $this->getCurrentUserObject()->getHomeEmail() == '')) {
                 $retarr[] = array('delay' => 30, 'bg_color' => '#FF0000', 'message' => TTi18n::getText('WARNING: Please click here and enter an email address for your account, this is required to receive important notices and prevent your account from being locked out.'), 'destination' => array('menu_name' => 'Contact Information'));
             }
             break;
         default:
             break;
     }
     //Check timezone is proper.
     $current_user_prefs = $this->getCurrentUserObject()->getUserPreferenceObject();
     if ($current_user_prefs->setDateTimePreferences() == FALSE) {
         //Setting timezone failed, alert user to this fact.
         //WARNING: %1 was unable to set your time zone. Please contact your %1 administrator immediately.{/t} {if $permission->Check('company','enabled') AND $permission->Check('company','edit_own')}<a href="http://forums.timetrex.com/viewtopic.php?t=40">{t}For more information please click here.{/t}</a>{/if}
         if ($this->getPermissionObject()->Check('company', 'enabled') and $this->getPermissionObject()->Check('company', 'edit_own')) {
             $destination_url = 'http://www.timetrex.com/r.php?id=1010';
             $sub_message = TTi18n::getText('For more information please click here.');
         } else {
             $destination_url = NULL;
             $sub_message = NULL;
         }
         $retarr[] = array('delay' => -1, 'bg_color' => '#FF0000', 'message' => TTi18n::getText('WARNING: %1 was unable to set your time zone. Please contact your %1 administrator immediately.', APPLICATION_NAME) . ' ' . $sub_message, 'destination' => $destination_url);
         unset($destination_url, $sub_message);
     }
     return $retarr;
 }
コード例 #3
0
 static function setUserSetting($user_id, $name, $value, $type_id = 10)
 {
     $row = array('user_id' => $user_id, 'name' => $name, 'value' => $value, 'type_id' => $type_id);
     $uslf = new UserSettingListFactory();
     $uslf->getByUserIdAndName($user_id, $name);
     if ($uslf->getRecordCount() == 1) {
         $usf = $uslf->getCurrent();
         $row = array_merge($usf->getObjectAsArray(), $row);
     } else {
         $usf = new UserSettingFactory();
     }
     Debug::Arr($row, 'Data: ', __FILE__, __LINE__, __METHOD__, 10);
     $usf->setObjectFromArray($row);
     if ($usf->isValid()) {
         $usf->Save();
     }
     return FALSE;
 }