-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
109 lines (105 loc) · 2.86 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="main.css">
<title>Labeler</title>
</head>
<?php
exec("ptouch-print --info 2>&1", $output, $retval);
global $tapeSize;
global $title;
$title="Labeler";
global $error;
$error=false;
if(count($output)<3) {
$errorText="ERROR! Printer not connected or turned off!";
$error=true;
}
else {
$tapeSize=$output[3];
if(strpos($tapeSize, "No media") !== false) {
$tapeSize = "None";
} else {
$tapeSize=str_replace("media width = ", "", $tapeSize);
}
}
global $preview;
$preview=False;
global $line_one;
$line_one="";
global $line_two;
$line_two="";
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$line_one=$_POST['line_one'];
$line_two=$_POST['line_two'];
$cmd="ptouch-print --text";
if(!empty($line_one)){
$cmd=$cmd." \"".$line_one."\"";
}
if(!empty($line_two)){
$cmd=$cmd." \"".$line_two."\"";
}
if ($_POST['action'] == 'print') {
exec("$cmd 2>&1", $output, $retval);
} else if ($_POST['action'] == 'preview') {
$preview=True;
$cmd=$cmd." --writepng '/srv/http/preview.png'";
$output="";
$retVal=0;
exec("$cmd 2>&1", $output, $retval);
if ($retval != 0) {
print("<h1>ERROR!</h1>");
foreach($output as $line) {
print($line);
print("<br/>");
}
print("<br/>");
print("<br/>");
}
}
}
?>
<body>
<div class="form">
<?php
if($error) {
?>
<div class="title" style="margin-bottom:30px"><?php print($errorText); ?></div>
<?php
}
else {
?>
<div class="title">Labeler</div>
<div class="subtitle"><?php print("Tape size: ".$tapeSize); ?></div>
<div class="cut cut-long"></div>
<form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>" method="post">
<div class="input-container ic1">
<input class="input" type="text" id="line_one" name="line_one" onload='this.click();' value="<?php print($line_one); ?>" placeholder="" />
<div class="cut"></div>
<label for="line_one" class="placeholder">Line 1</label>
</div>
<div class="input-container ic2">
<input class="input" type="text" id="line_two" name="line_two" placeholder="" value="<?php print($line_two); ?>" />
<div class="cut"></div>
<label for="line_two" class="placeholder">Line 2</label><br>
</div>
<div class="cut cut-short"></div>
<button type="submit" name="action" value="preview" class="submit">Preview</button>
<?php
if ($preview) {
$filename="preview.png";
if (file_exists($filename)) {
print('<div class="cut"></div>');
print('<div class="input-container ic3">');
print("<img width=100% src=$filename />");
print('</div>');
print('<div class="cut"></div>');
}
}
?>
<button type="submit" name="action" value="print" class="submit">Print</button>
</form>
<?php } ?>
</div>
</body>
</html>