Ejemplo n.º 1
0
 function createStation($company_id)
 {
     $sf = new StationFactory();
     $sf->setCompany($company_id);
     $sf->setStatus(20);
     $sf->setType(10);
     $sf->setSource('ANY');
     $sf->setStation('ANY');
     $sf->setDescription('All stations');
     $sf->setGroupSelectionType(10);
     $sf->setBranchSelectionType(10);
     $sf->setDepartmentSelectionType(10);
     if ($sf->isValid()) {
         $insert_id = $sf->Save();
         Debug::Text('Station ID: ' . $insert_id, __FILE__, __LINE__, __METHOD__, 10);
     }
     $sf = new StationFactory();
     $sf->setCompany($company_id);
     $sf->setStatus(20);
     $sf->setType(25);
     $sf->setSource('ANY');
     $sf->setStation('ANY');
     $sf->setDescription('All stations');
     $sf->setGroupSelectionType(10);
     $sf->setBranchSelectionType(10);
     $sf->setDepartmentSelectionType(10);
     if ($sf->isValid()) {
         //$insert_id = $sf->Save(FALSE);
         //$sf->setUser( array(-1) );
         $insert_id = $sf->Save();
         Debug::Text('Station ID: ' . $insert_id, __FILE__, __LINE__, __METHOD__, 10);
         return $insert_id;
     }
     Debug::Text('Failed Creating Station!', __FILE__, __LINE__, __METHOD__, 10);
     return FALSE;
 }
 function postSave()
 {
     $this->removeCache($this->getId());
     $this->remoteSave();
     if ($this->getDeleted() == FALSE) {
         //Add base currency for this new company.
         if ($this->getEnableAddCurrency() == TRUE) {
             $clf = new CurrencyListFactory();
             $clf->getByCompanyId($this->getId());
             if ($clf->getRecordCount() == 0) {
                 Debug::text('Adding Default Currency', __FILE__, __LINE__, __METHOD__, 9);
                 $cf = new CurrencyFactory();
                 $country_to_currency_map_arr = $cf->getOptions('country_currency');
                 if (isset($country_to_currency_map_arr[$this->getCountry()])) {
                     $base_currency = $country_to_currency_map_arr[$this->getCountry()];
                     Debug::text('Found Base Currency For Country: ' . $this->getCountry() . ' Currency: ' . $base_currency, __FILE__, __LINE__, __METHOD__, 9);
                 } else {
                     Debug::text('DID NOT Find Base Currency For Country: ' . $this->getCountry() . ' Using default USD.', __FILE__, __LINE__, __METHOD__, 9);
                     $base_currency = 'USD';
                 }
                 $cf->setCompany($this->getId());
                 $cf->setStatus(10);
                 $cf->setName($base_currency);
                 $cf->setISOCode($base_currency);
                 $cf->setConversionRate('1.000000000');
                 $cf->setAutoUpdate(FALSE);
                 $cf->setBase(TRUE);
                 $cf->setDefault(TRUE);
                 if ($cf->isValid()) {
                     $cf->Save();
                 }
             }
         }
         if ($this->getEnableAddPermissionGroupPreset() == TRUE) {
             Debug::text('Adding Preset Permission Groups', __FILE__, __LINE__, __METHOD__, 9);
             $pf = new PermissionFactory();
             $pf->StartTransaction();
             if ($this->getProductEdition() == 20) {
                 $preset_flags = array('job' => 1, 'invoice' => 1, 'document' => 1);
             } else {
                 $preset_flags = array();
             }
             $preset_options = $pf->getOptions('preset');
             foreach ($preset_options as $preset_id => $preset_name) {
                 $pcf = new PermissionControlFactory();
                 $pcf->setCompany($this->getId());
                 $pcf->setName($preset_name);
                 $pcf->setDescription('');
                 if ($pcf->isValid()) {
                     $pcf_id = $pcf->Save(FALSE);
                     $pf->applyPreset($pcf_id, $preset_id, $preset_flags);
                 }
             }
             //$pf->FailTransaction();
             $pf->CommitTransaction();
         }
         if ($this->getEnableAddStation() == TRUE) {
             Debug::text('Adding Default Station', __FILE__, __LINE__, __METHOD__, 9);
             //Enable punching in from all stations
             $sf = new StationFactory();
             $sf->setCompany($this->getId());
             $sf->setStatus(20);
             $sf->setType(10);
             $sf->setSource('ANY');
             $sf->setStation('ANY');
             $sf->setDescription('All stations');
             $sf->setGroupSelectionType(10);
             $sf->setBranchSelectionType(10);
             $sf->setDepartmentSelectionType(10);
             if ($sf->isValid()) {
                 $sf->Save();
             }
         }
         if ($this->getEnableAddPayStubEntryAccountPreset() == TRUE) {
             Debug::text('Adding Pay Stub Entry Account Presets', __FILE__, __LINE__, __METHOD__, 9);
             PayStubEntryAccountFactory::addPresets($this->getId());
         }
         if ($this->getEnableAddCompanyDeductionPreset() == TRUE) {
             Debug::text('Adding Company Deduction Presets', __FILE__, __LINE__, __METHOD__, 9);
             CompanyDeductionFactory::addPresets($this->getId());
         }
         if ($this->getEnableAddRecurringHolidayPreset() == TRUE) {
             Debug::text('Adding Recurring Holiday Presets', __FILE__, __LINE__, __METHOD__, 9);
             RecurringHolidayFactory::addPresets($this->getId(), $this->getCountry());
         }
     }
     if ($this->getDeleted() == TRUE) {
         $ulf = new UserListFactory();
         $ulf->getByCompanyId($this->getID());
         if ($ulf->getRecordCount() > 0) {
             $ulf->StartTransaction();
             foreach ($ulf as $u_obj) {
                 Debug::text('Deleting User ID: ' . $u_obj->getId(), __FILE__, __LINE__, __METHOD__, 9);
                 $u_obj->setDeleted(TRUE);
                 if ($u_obj->isValid()) {
                     $u_obj->Save();
                 }
             }
             $ulf->CommitTransaction();
         }
     }
     return TRUE;
 }
Ejemplo n.º 3
0
/*
 * Get FORM variables
 */
extract(FormVariables::GetVariables(array('action', 'id', 'data')));
$sf = new StationFactory();
$action = Misc::findSubmitButton();
switch ($action) {
    case 'submit':
        //Debug::setVerbosity(11);
        Debug::Text('Submit!', __FILE__, __LINE__, __METHOD__, 10);
        $sf->StartTransaction();
        $sf->setId($data['id']);
        $sf->setCompany($current_company->getId());
        $sf->setStatus($data['status']);
        $sf->setType($data['type']);
        $sf->setSource($data['source']);
        $sf->setStation($data['station']);
        $sf->setDescription($data['description']);
        if (isset($data['port'])) {
            $sf->setPort($data['port']);
        }
        if (isset($data['user_name'])) {
            $sf->setUserName($data['user_name']);
        }
        if (isset($data['password'])) {
            $sf->setPassword($data['password']);
        }
        if ($data['type'] >= 100) {
            if (isset($data['poll_frequency'])) {
                $sf->setPollFrequency($data['poll_frequency']);
            }
 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;
 }
Ejemplo n.º 5
0
         $current_station = $slf->getCurrent();
         unset($slf);
         if ($current_station->isNew()) {
             Debug::text('Station ID is NOT IN DB!! ' . $_COOKIE['StationID'], __FILE__, __LINE__, __METHOD__, 10);
             $create_new_station = TRUE;
         }
     } else {
         $create_new_station = TRUE;
     }
     if ($create_new_station == TRUE) {
         //Insert new station
         $sf = new StationFactory();
         $sf->setCompany($current_company->getId());
         $sf->setStatus('ENABLED');
         $sf->setType('PC');
         $sf->setSource($_SERVER['REMOTE_ADDR']);
         $sf->setStation();
         $sf->setDescription(substr($_SERVER['HTTP_USER_AGENT'], 0, 250));
         if ($sf->Save(FALSE)) {
             $sf->setCookie();
         }
     }
     Redirect::Page(URLBuilder::getURL(NULL, 'index.php'));
 } else {
     $error_message = TTi18n::gettext('User Name or Password is incorrect');
     //Get company status from user_name, so we can display messages for ONHOLD/Cancelled accounts.
     $clf = new CompanyListFactory();
     $clf->getByUserName($user_name);
     if ($clf->getRecordCount() > 0) {
         $c_obj = $clf->getCurrent();
         if ($c_obj->getStatus() == 20) {