Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions api/v1/class/arbeitszeit.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -924,8 +924,8 @@ public function renderGUIUpdateCheck()
{

$text = "";
$current = $this->getTimeTrackVersion();
$latest = $this->checkForUpdate();
$current = trim($this->getTimeTrackVersion());
$latest = trim($this->checkForUpdate());


if ($this->checkForUpdate() != false) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,36 +8,54 @@
/**
* PDFExportModule - Allows you to export worktime sheets
*/
class PDFExportModule implements ExportModuleInterface {
public function export($args) {
$i18n = new i18n;
$arbeit = new Arbeitszeit;
$user = $args["user"];
$month = $args["month"];
$year = $args["year"];
$i18nn = $i18n->loadLanguage(null, "class/pdf");
$ini = Arbeitszeit::get_app_ini();
$hours = $arbeit->calculate_hours_specific_time($user, $month, $year);
if(is_string($year) != true){
$year = date("Y");
}
$sql = "SELECT * FROM `arbeitszeiten` WHERE YEAR(schicht_tag) = ? AND MONTH(schicht_tag) = ? AND username = ? ORDER BY schicht_tag DESC;";
$statement = $arbeit->db()->sendQuery($sql);
$userdata = $statement->execute([$year, $month, $user]);
if($userdata == false){
Exceptions::error_rep("An error occurred while generating worktime pdf. See previous message for more information");
die("An error occurred!");
}
$user_data = Benutzer::get_user($user);
$user_data["name"] ?? $statement->fetch(\PDO::FETCH_ASSOC)[0]["name"]; # Bug 14 Fix -> http://bugzilla.openducks.org/show_bug.cgi?id=14
try {
$css = @file_get_contents($ini["exports"]["pdf"]["css"]);
} catch (\ValueError $e) {
$css = file_get_contents(__DIR__ . "/css/index.css");
}
$data = <<< DATA
class PDFExportModule implements ExportModuleInterface
{

function loadUserContent(string $file): string
{
if (!is_file($file)) {
return '';
}

ob_start();
include $file;
return ob_get_clean();
}


public function export($args)
{
$i18n = new i18n;
$arbeit = new Arbeitszeit;
$user = $args["user"];
$month = $args["month"];
$year = $args["year"];
$i18nn = $i18n->loadLanguage(null, "class/pdf");
$ini = Arbeitszeit::get_app_ini();
$hours = $arbeit->calculate_hours_specific_time($user, $month, $year);
if (is_string($year) != true) {
$year = date("Y");
}
$userGeneratedBeginning = $this->loadUserContent(__DIR__ . '/php/user_content_beginning.php') ?? "";
$userGeneratedEnding = $this->loadUserContent(__DIR__ . '/php/user_content_ending.php') ?? "";
$sql = "SELECT * FROM `arbeitszeiten` WHERE YEAR(schicht_tag) = ? AND MONTH(schicht_tag) = ? AND username = ? ORDER BY schicht_tag DESC;";
$statement = $arbeit->db()->sendQuery($sql);
$userdata = $statement->execute([$year, $month, $user]);
if ($userdata == false) {
Exceptions::error_rep("An error occurred while generating worktime pdf. See previous message for more information");
die("An error occurred!");
}
$user_data = Benutzer::get_user($user);
$user_data["name"] ?? $statement->fetch(\PDO::FETCH_ASSOC)[0]["name"]; # Bug 14 Fix -> http://bugzilla.openducks.org/show_bug.cgi?id=14
try {
$css = @file_get_contents($ini["exports"]["pdf"]["css"]);
} catch (\ValueError $e) {
$css = file_get_contents(__DIR__ . "/css/index.css");
}
$data = <<<DATA
<html>
<body style="text-align:center; font-family: Arial;">
{$userGeneratedBeginning}
<h1>{$i18nn["worktime_note"]} <b>{$user_data["name"]}</b></h1>
<style>
$css
Expand All @@ -55,33 +73,33 @@ public function export($args) {
</tr>

DATA;
if($statement->rowCount() > 0){
$q = $statement->rowCount();
$i = 0;
while($row = $statement->fetch(\PDO::FETCH_ASSOC)){
if($i == 0){
$r = @strftime("%d.%m.%Y", strtotime($row["schicht_tag"]));
}
$i++;
#$rnw = $row["name"];
$raw = @strftime("%d.%m.%Y", strtotime($row["schicht_tag"]));
$rew = $row["schicht_anfang"];
$rol = $row["schicht_ende"];
$ral = $row["ort"];
$rtn = $arbeit->type_from_int($row["Wtype"]) ?? "N/A";
$rps = @strftime("%H:%M", strtotime($row["pause_start"]));
$rpe = @strftime("%H:%M", strtotime($row["pause_end"]));

if($rps == "01:00" ||$rps == null){
$rps = "-";
}
if($rpe == "01:00" || $rpe == null){
$rpe = "-";
}

$data .= <<< DATA
if ($statement->rowCount() > 0) {
$q = $statement->rowCount();
$i = 0;
while ($row = $statement->fetch(\PDO::FETCH_ASSOC)) {
if ($i == 0) {
$r = @strftime("%d.%m.%Y", strtotime($row["schicht_tag"]));

}
$i++;
#$rnw = $row["name"];
$raw = @strftime("%d.%m.%Y", strtotime($row["schicht_tag"]));
$rew = $row["schicht_anfang"];
$rol = $row["schicht_ende"];
$ral = $row["ort"];
$rtn = $arbeit->type_from_int($row["Wtype"]) ?? "N/A";
$rps = @strftime("%H:%M", strtotime($row["pause_start"]));
$rpe = @strftime("%H:%M", strtotime($row["pause_end"]));


if ($rps == "01:00" || $rps == null) {
$rps = "-";
}
if ($rpe == "01:00" || $rpe == null) {
$rpe = "-";
}

$data .= <<<DATA

<tr>
<td>{$raw}</td>
Expand All @@ -95,72 +113,90 @@ public function export($args) {


DATA;
if($i == $q){
$s = @strftime("%d.%m.%Y", strtotime($row["schicht_tag"]));
}
if ($i == $q) {
$s = @strftime("%d.%m.%Y", strtotime($row["schicht_tag"]));
}
} else {
return "<p style='text-align: center;'>{$i18nn["no_data"]}</p>";
}
$data .= <<< DATA
} else {
return "<p style='text-align: center;'>{$i18nn["no_data"]}</p>";
}
$data .= <<<DATA

</table>
<p>{$i18nn["worktime_all"]}: {$hours["hours_rounded"]}</p>
<p>{$i18nn["worktime_date"]}: {$s} - {$i18nn["end_date"]}: {$r}</p>
</div>
{$userGeneratedEnding}
</body>
</html>
<script>window.print()</script>


DATA;
return $data;
return $data;
}

public function saveAsPdf($args) {
public function saveAsPdf($args)
{
Exceptions::error_rep("Saving PDF file...", 1, "N/A");
$html = $this->export($args);
$html = $this->export($args);
$user = $args['user'] ?? "dummy";
$month = $args['month'] ?? "00";
$year = $args['year'] ?? "0000";


$directory = $_SERVER["DOCUMENT_ROOT"] . "/data/exports/" . $this->getName() . "/$user";
$filename = "$directory/worktimes_{$year}-{$month}.pdf";


if (!is_dir($directory)) {
mkdir($directory, 0777, true);
}


$dompdf = new \Dompdf\Dompdf();
$dompdf->loadHtml($html);
$dompdf->setPaper('A4', 'portrait');
$dompdf->render();


file_put_contents($filename, $dompdf->output());
Exceptions::error_rep("PDF file saved: $filename", 1, "N/A");
return $filename;
}

public function getName() {
public function getName()
{
return "PDFExportModule";
}
public function getExtension() {
public function getExtension()
{
return "pdf";
}
public function getMimeType() {
public function getMimeType()
{
return "application/pdf";
}
public function getVersion() {
public function getVersion()
{
return "1.0";
}
public function geti18n() {}
public function __set($name, $value) {}
public function __get($name) {}
public function __isset($name) {}
public function __unset($name) {}
public function __call($name, $arguments) {}
public function geti18n()
{
}
public function __set($name, $value)
{
}
public function __get($name)
{
}
public function __isset($name)
{
}
public function __unset($name)
{
}
public function __call($name, $arguments)
{
}
}
2 changes: 1 addition & 1 deletion api/v1/class/telemetry/server/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Self host telemetry server.

Make sure your clients point to a specific client for the telemetry server.
Install TimeTrack on that server and start the telemetry server with `cd path/to/timetrack/api/v1/class/telemetry/server && php -S 0.0.0.0:8888 server.php`
Install TimeTrack on that server and start the telemetry server with `cd path/to/timetrack/api/v1/class/telemetry/server && php -S 0.0.0.0:8888 server.php` or run in background with nohup: `nohup php -S 0.0.0.0:8888 server.php > telemetry.log 2>&1 &`

Inside DB check the results within the `telemetry_server` table. Set `telemetryServer` var within app.json `general` section to `true`.
A new entry called Server Telemetry will appear within the Navigation bar.
Loading