TTi18n::setLocale();
     //Sets master locale
 }
 $profiler->stopTimer("setLocale()");
 if ($current_user->isInformationComplete() == TRUE and $current_user_prefs->isPreferencesComplete() == FALSE and (!stristr($_SERVER['SCRIPT_NAME'], 'permissiondenied') and !stristr($_SERVER['SCRIPT_NAME'], 'logout') and !stristr($_SERVER['SCRIPT_NAME'], 'about') and !stristr($_SERVER['SCRIPT_NAME'], 'punch.php') and !stristr($_SERVER['SCRIPT_NAME'], 'ajax_server') and !stristr($_SERVER['SCRIPT_NAME'], 'global.js') and !stristr($_SERVER['SCRIPT_NAME'], 'menu.js')) and !isset($_GET['incomplete']) and !isset($_POST['incomplete']) and ($permission->Check('user_preference', 'enabled') and ($permission->Check('user_preference', 'edit') or $permission->Check('user_preference', 'edit_child') or $permission->Check('user_preference', 'edit_own')))) {
     Redirect::Page(URLBuilder::getURL(array('incomplete' => 1), Environment::GetBaseURL() . 'users/EditUserPreference.php'));
 }
 //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);
 //Handle station functionality
 if (isset($_COOKIE['StationID'])) {
     Debug::text('Station ID Cookie found! ' . $_COOKIE['StationID'], __FILE__, __LINE__, __METHOD__, 10);
     $slf = new StationListFactory();
     $slf->getByStationIdandCompanyId($_COOKIE['StationID'], $current_company->getId());
     $current_station = $slf->getCurrent();
     unset($slf);
     if ($current_station->isNew()) {
         Debug::text('Station ID is NOT IN DB!! ' . $_COOKIE['StationID'], __FILE__, __LINE__, __METHOD__, 10);
     }
 }
 //Debug::Arr($current_station, 'Current Station Object: ', __FILE__, __LINE__, __METHOD__, 10);
 //Debug::text('Current Company: '. $current_company->getName(), __FILE__, __LINE__, __METHOD__, 10);
 //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) {
 static function getOrCreateStation($station_id, $company_id, $type_id = 10)
 {
     Debug::text('Checking for Station ID: ' . $station_id . ' Company ID: ' . $company_id . ' Type: ' . $type_id, __FILE__, __LINE__, __METHOD__, 10);
     $slf = new StationListFactory();
     $slf->getByStationIdandCompanyId($station_id, $company_id);
     if ($slf->getRecordCount() == 1) {
         $retval = $slf->getCurrent()->getStation();
     } else {
         Debug::text('Station ID: ' . $station_id . ' does not exist, creating new station', __FILE__, __LINE__, __METHOD__, 10);
         //Insert new station
         $sf = TTnew('StationFactory');
         $sf->setCompany($company_id);
         $sf->setStatus(20);
         //Enabled
         switch ($type_id) {
             case 10:
                 //PC
                 $station = NULL;
                 $description = substr($_SERVER['HTTP_USER_AGENT'], 0, 250);
                 break;
             case 28:
                 //Phone/Mobile App
                 $station = NULL;
                 //Can't get UDID on iOS5, but we can on Android.
                 $description = TTi18n::getText('Mobile Application') . ': ' . substr($_SERVER['HTTP_USER_AGENT'], 0, 250);
                 break;
         }
         $sf->setType($type_id);
         $sf->setDescription($description);
         $sf->setStation($station);
         $sf->setSource($_SERVER['REMOTE_ADDR']);
         if ($sf->isValid()) {
             if ($sf->Save(FALSE)) {
                 $retval = $sf->getStation();
             }
         } else {
             $retval = $sf;
         }
     }
     Debug::text('Returning Station ID: ' . $station_id, __FILE__, __LINE__, __METHOD__, 10);
     return $retval;
 }
 function setStation($source, $station, $description = NULL, $type = 'PHONE')
 {
     Debug::text('Setting Station: (' . $station . ') Source: ' . $source . ' Description: ' . $description . ' Type: ' . $type, __FILE__, __LINE__, __METHOD__, 10);
     if ($type == '') {
         return FALSE;
     }
     //Make sure we don't strtolower() type, as it will cause the lookup to fail.
     $type = trim($type);
     //We using SOAP, we always have the IP address, always set it unless we're using
     //the phone punch in.
     if (strtolower($type) == 'phone' or $type == 20) {
         $source = Misc::parseCallerID($source);
         $station = Misc::parseCallerID($station);
         Debug::text('Filtered Source: ' . $source . ' Station: ' . $station, __FILE__, __LINE__, __METHOD__, 10);
     } else {
         $source = $_SERVER['REMOTE_ADDR'];
     }
     if ($source == '') {
         $source = 'Unavailable';
     }
     if ($description == '') {
         $description = 'N/A';
     }
     if ($source == '') {
         $source = NULL;
     }
     $slf = new StationListFactory();
     $slf->getByStationIdandCompanyId($station, $this->getCompanyObject()->getId());
     $current_station = $slf->getCurrent();
     unset($slf);
     if ($current_station->isNew()) {
         Debug::text('Station not found... Adding new one...', __FILE__, __LINE__, __METHOD__, 10);
         $sf = new StationFactory();
         $sf->setCompany($this->getCompanyObject()->getId());
         $sf->setStatus('ENABLED');
         $sf->setType($type);
         //If this is a new iButton,Fingerprint, or Barcode station, default to 'ANY' for the source, so we aren't restricted by IP.
         if (in_array($sf->getType(), array(30, 40, 50))) {
             $sf->setSource('ANY');
         } else {
             $sf->setSource($source);
         }
         $sf->setStation($station);
         $sf->setDescription($description);
         //If this is a new iButton,Fingerprint, or Barcode station, default to allow all employees.
         if (in_array($sf->getType(), array(30, 40, 50))) {
             $sf->setGroupSelectionType(10);
             $sf->setBranchSelectionType(10);
             $sf->setDepartmentSelectionType(10);
         }
         if ($sf->isValid()) {
             if ($sf->Save(FALSE)) {
                 //return $source;
                 return $sf->getStation();
             }
         }
     } else {
         Debug::text('Station FOUND!', __FILE__, __LINE__, __METHOD__, 10);
         return $current_station->getStation();
     }
     return FALSE;
 }
Exemple #4
0
 function getUserPunch($user_id = NULL, $epoch = NULL, $station_id = NULL, $company_id = NULL)
 {
     if ($epoch == '') {
         $epoch = TTDate::getTime();
     }
     if (!is_numeric($user_id)) {
         $user_id = $this->getCurrentUserObject()->getId();
     }
     if (!is_numeric($company_id)) {
         $company_id = $this->getCurrentCompanyObject()->getId();
     }
     if (!is_numeric($station_id)) {
         $station_id = getStationID();
         //API.inc
     }
     //Must call APIStation->getCurrentStation( $station_id = NULL ) first, so the Station ID cookie can be set and passed to this.
     //Check if station is allowed.
     $current_station = FALSE;
     $slf = new StationListFactory();
     $slf->getByStationIdandCompanyId($station_id, $company_id);
     if ($slf->getRecordCount() == 1) {
         $current_station = $slf->getCurrent();
         $station_type = $current_station->getType();
     }
     unset($slf);
     $slf = TTnew('ScheduleListFactory');
     Debug::Text('Station ID: ' . $station_id . ' User ID: ' . $user_id . ' Epoch: ' . $epoch, __FILE__, __LINE__, __METHOD__, 10);
     if (is_object($current_station) and $current_station->checkAllowed($user_id, $station_id, $station_type) == TRUE) {
         Debug::Text('Station Allowed! ID: ' . $station_id . ' User ID: ' . $user_id . ' Epoch: ' . $epoch, __FILE__, __LINE__, __METHOD__, 10);
         //Get user object from ID.
         $ulf = TTNew('UserListFactory');
         $ulf->getByIdAndCompanyId($user_id, $company_id);
         if ($ulf->getRecordCount() == 1) {
             $user_obj = $ulf->getCurrent();
             $plf = TTNew('PunchListFactory');
             $data = $plf->getDefaultPunchSettings($user_obj, $epoch, $current_station, $this->getPermissionObject());
             $data['date_stamp'] = TTDate::getAPIDate('DATE', $epoch);
             $data['time_stamp'] = TTDate::getAPIDate('DATE+TIME', $epoch);
             $data['punch_date'] = TTDate::getAPIDate('DATE', $epoch);
             $data['punch_time'] = TTDate::getAPIDate('TIME', $epoch);
             $data['original_time_stamp'] = TTDate::getAPIDate('DATE+TIME', $epoch);
             $data['actual_time_stamp'] = TTDate::getAPIDate('DATE+TIME', $epoch);
             $data['first_name'] = $user_obj->getFirstName();
             $data['last_name'] = $user_obj->getLastName();
             $data['station_id'] = $current_station->getId();
             if (isset($data)) {
                 Debug::Arr($data, 'Punch Data: ', __FILE__, __LINE__, __METHOD__, 10);
                 return $this->returnHandler($data);
             }
         }
     } else {
         Debug::Text('Station IS NOT Allowed! ID: ' . $station_id . ' User ID: ' . $user_id . ' Epoch: ' . $epoch, __FILE__, __LINE__, __METHOD__, 10);
         $validator_obj = new Validator();
         $validator_stats = array('total_records' => 1, 'valid_records' => 0);
         $error_message = TTi18n::gettext('You are not authorized to punch in or out from this station!');
         $validator_obj->isTrue('user_name', FALSE, $error_message);
         $validator[0] = $validator_obj->getErrorsArray();
         return $this->returnHandler(FALSE, 'VALIDATION', TTi18n::getText('INVALID DATA'), $validator, $validator_stats);
     }
     return FALSE;
 }