/** * Run manual commands on timeclocks * @param string $command command name * @param array $data station IDs * @return array */ function runManualCommand($command, $data) { if (is_numeric($data)) { $data = array($data); } if (!is_array($data)) { return $this->returnHandler(FALSE); } Debug::Text('Time Clock Command: ' . $command, __FILE__, __LINE__, __METHOD__, 10); Debug::Text('Received data for: ' . count($data) . ' Stations', __FILE__, __LINE__, __METHOD__, 10); Debug::Arr($data, 'Data: ', __FILE__, __LINE__, __METHOD__, 10); $src_rows = $this->stripReturnHandler($this->getStation(array('filter_data' => array('id' => $data)), TRUE)); if (is_array($src_rows) and count($src_rows) > 0) { Debug::Arr($src_rows, 'SRC Rows: ', __FILE__, __LINE__, __METHOD__, 10); foreach ($src_rows as $key => $row) { //Skip any non-timeclock types. if ($row['type_id'] < 100) { continue; } Debug::Text(' Type: ' . $row['type_id'] . ' Source: ' . $row['source'] . ' Port: ' . $row['port'] . ' Password: '******'password'], __FILE__, __LINE__, __METHOD__, 10); $tc = new TimeClock($row['type_id']); $tc->setIPAddress($row['source']); $tc->setPort($row['port']); //$tc->setUsername( $row['user_name'] ); $tc->setPassword($row['password']); $slf = TTnew('StationListFactory'); $slf->getByIdAndCompanyId($row['id'], $this->getCurrentCompanyObject()->getId()); if ($slf->getRecordCount() == 1) { $s_obj = $slf->getCurrent(); } $s_obj->setLastPunchTimeStamp($s_obj->getLastPunchTimeStamp()); if ($s_obj->getTimeZone() != '' and !is_numeric($s_obj->getTimeZone())) { Debug::text('Setting Station TimeZone To: ' . $s_obj->getTimeZone(), __FILE__, __LINE__, __METHOD__, 10); TTDate::setTimeZone($s_obj->getTimeZone()); } $result_str = NULL; switch ($command) { case 'test_connection': if ($tc->testConnection() == TRUE) { $result_str = TTi18n::gettext('Connection Succeeded!'); } else { $result_str = TTi18n::gettext('Connection Failed!'); } break; case 'set_date': TTDate::setTimeZone($row['time_zone_id'], $s_obj->getTimeZone()); if ($tc->setDate(time()) == TRUE) { $result_str = TTi18n::gettext('Date Successfully Set To: ') . TTDate::getDate('DATE+TIME', time()); } else { $result_str = TTi18n::gettext('Setting Date Failed!'); } break; case 'download': if (isset($s_obj) and $tc->Poll($this->getCurrentCompanyObject(), $s_obj) == TRUE) { $result_str = TTi18n::gettext('Download Data Succeeded!'); if ($s_obj->isValid()) { $s_obj->Save(FALSE); } } else { $result_str = TTi18n::gettext('Download Data Failed!'); } break; case 'upload': if (isset($s_obj) and $tc->Push($this->getCurrentCompanyObject(), $s_obj) == TRUE) { $result_str = TTi18n::gettext('Upload Data Succeeded!'); if ($s_obj->isValid()) { $s_obj->Save(FALSE); } } else { $result_str = TTi18n::gettext('Upload Data Failed!'); } break; case 'update_config': if (isset($s_obj) and $tc->setModeFlag($s_obj->getModeFlag()) == TRUE) { $result_str = TTi18n::gettext('Update Configuration Succeeded'); } else { $result_str = TTi18n::gettext('Update Configuration Failed'); } break; case 'delete_data': if (isset($s_obj) and $tc->DeleteAllData($s_obj) == TRUE) { $result_str = TTi18n::gettext('Delete Data Succeeded!'); if ($s_obj->isValid()) { $s_obj->Save(FALSE); } } else { $result_str = TTi18n::gettext('Delete Data Failed!'); } break; case 'reset_last_punch_time_stamp': $s_obj->setLastPunchTimeStamp(time()); if ($s_obj->isValid()) { $s_obj->Save(FALSE); } $result_str = TTi18n::gettext('Reset Last Punch Time Succeeded!'); break; case 'clear_last_punch_time_stamp': $s_obj->setLastPunchTimeStamp(1); if ($s_obj->isValid()) { $s_obj->Save(FALSE); } $result_str = TTi18n::gettext('Clear Last Punch Time Succeeded!'); break; case 'restart': $tc->restart(); $result_str = TTi18n::gettext('Restart Succeeded!'); break; case 'firmware': if ($tc->setFirmware() == TRUE) { $result_str = TTi18n::gettext('Firmware Update Succeeded!'); } else { $result_str = TTi18n::gettext('Firmware Update Failed!'); } break; default: $result_str = TTi18n::gettext('Invalid manual command!'); break; } TTLog::addEntry($s_obj->getId(), 500, TTi18n::getText('TimeClock Manual Command') . ': ' . ucwords(str_replace('_', ' ', $command)) . ' ' . TTi18n::getText('Result') . ': ' . $result_str, NULL, $s_obj->getTable()); if (isset($s_obj)) { $row['last_poll_date'] = $s_obj->getLastPollDate(); $row['last_push_date'] = $s_obj->getLastPushDate(); } unset($s_obj, $slf); } return $this->returnHandler($result_str); } return $this->returnHandler(FALSE); }
if ($tc->testConnection() == TRUE) { $result_str = TTi18n::gettext('Connection Succeeded!'); } else { $result_str = TTi18n::gettext('Connection Failed!'); } break; case 'set_date': TTDate::setTimeZone($data['time_zone_id'], $s_obj->getTimeZone()); if ($tc->setDate(time()) == TRUE) { $result_str = TTi18n::gettext('Date Successfully Set To: ') . TTDate::getDate('DATE+TIME', time()); } else { $result_str = TTi18n::gettext('Setting Date Failed!'); } break; case 'download': if (isset($s_obj) and $tc->Poll($current_company, $s_obj) == TRUE) { $result_str = TTi18n::gettext('Download Data Succeeded!'); if ($s_obj->isValid()) { $s_obj->Save(FALSE); } } else { $result_str = TTi18n::gettext('Download Data Failed!'); } break; case 'upload': if (isset($s_obj) and $tc->Push($current_company, $s_obj) == TRUE) { $result_str = TTi18n::gettext('Upload Data Succeeded!'); if ($s_obj->isValid()) { $s_obj->Save(FALSE); } } else {