Extract UI lib from Utils.

This commit is contained in:
2015-06-26 18:09:07 +02:00
parent 85eacaff6e
commit 74c0b0c5dc
4 changed files with 219 additions and 172 deletions

View File

@@ -2,6 +2,7 @@
include_once "config.php"; include_once "config.php";
include_once "utils.php"; include_once "utils.php";
include_once "ui.php";
$Commands=array(); $Commands=array();
@@ -20,9 +21,9 @@ function ExecCommand($command){
function ShowCommandLog(){ function ShowCommandLog(){
global $Commands; global $Commands;
foreach($Commands as $loggedCommand){ foreach($Commands as $loggedCommand){
DrawParagraph($loggedCommand["Command"],"font-weight: bold;"); echo RenderParagraph($loggedCommand["Command"],"font-weight: bold;");
DrawParagraph($loggedCommand["Result"]); echo RenderParagraph($loggedCommand["Result"]);
DrawParagraph($loggedCommand["Error"],"color: red;"); echo RenderParagraph($loggedCommand["Error"],"color: red;");
} }
} }
@@ -110,11 +111,11 @@ if(RequestParm("btnScan",false)){
echo '<form id="frmMain" method="GET" action="index.php">'."\n"; echo '<form id="frmMain" method="GET" action="index.php">'."\n";
// Render header info // Render header info
DrawFieldInfo("Scanner",$SaneScanner); echo RenderFieldInfo("Scanner",$SaneScanner);
DrawFieldCombo("Resolution","ddlResolution",$Resolutions,$Resolution); echo RenderFieldCombo("Resolution","ddlResolution",$Resolutions,$Resolution);
DrawFieldCombo("Format","ddlFormat",$Formats,$Format); echo RenderFieldCombo("Format","ddlFormat",$Formats,$Format);
DrawFieldCheckText("Cropping","chkCrop",$Crop,"txtCropFuzz",$CropFuzz); echo RenderFieldCheckText("Cropping","chkCrop",$Crop,"txtCropFuzz",$CropFuzz);
DrawButton("Scan","btnScan"); echo RenderFieldButton("","btnScan","Scan");
if($DestFile!=null){ if($DestFile!=null){
$DestFileFixed=htmlentities($DestFile,ENT_HTML5, "UTF-8"); $DestFileFixed=htmlentities($DestFile,ENT_HTML5, "UTF-8");
echo '<div><a href="'.$DestFileFixed.'">'. echo '<div><a href="'.$DestFileFixed.'">'.
@@ -125,4 +126,4 @@ if($DestFile!=null){
echo "</form>\n"; echo "</form>\n";
ShowCommandLog(); ShowCommandLog();
?>

147
code/ui.php Normal file
View File

@@ -0,0 +1,147 @@
<?php
function RenderLabel($text){
if($text!="" && $text!=null){
$textFixed=htmlentities($text,ENT_HTML5, "UTF-8");
return '<span class="fieldLabel">'.$textFixed.":</span>\n";
}else{
return '<span class="fieldLabel"></span>'."\n";
}
}
function RenderInfo($text){
$textFixed=htmlentities($text,ENT_HTML5, "UTF-8");
return '<div class="fieldContent">'.$textFixed."</div>\n";
}
function RenderText($idText,$value){
$idTextFixed=htmlentities($idText,ENT_HTML5, "UTF-8");
$valueFixed=htmlentities($value,ENT_HTML5, "UTF-8");
$render='<div class="fieldContent">'."\n";
$render.='<input type="text" id="'.$idTextFixed.'" name="'.$idTextFixed.'"'.
' value="'.$valueFixed.'" '.
' class="textBox"/>'."\n";
$render.="</div>\n";
return $render;
}
function RenderCheck($idCheck,$checked,$value){
$idCheckFixed=htmlentities($idCheck,ENT_HTML5, "UTF-8");
$valueFixed=htmlentities($idText,ENT_HTML5, "UTF-8");
$render='<div class="fieldContent">'."\n";
$render.='<input type="checkbox" id="'.$idCheckFixed.'" '.
'name="'.$idCheckFixed.'" ';
if($checked){ $render.=" checked "; }
$render.='class="check">'.$valueFixed."\n";
$render.="</input>\n";
$render.="</div>\n";
return $render;
}
function RenderCheckText($idCheck,$checked,$idText,$value){
$idCheckFixed=htmlentities($idCheck,ENT_HTML5, "UTF-8");
$idTextFixed=htmlentities($idText,ENT_HTML5, "UTF-8");
$valueFixed=htmlentities($value,ENT_HTML5, "UTF-8");
$render='<div class="fieldContent">'."\n";
$render.='<input type="checkbox" id="'.$idCheckFixed.'" '.
'name="'.$idCheckFixed.'" ';
if($checked){ $render.=" checked "; }
$render.='class="check" />'."\n";
$render.='<input type="text" id="'.$idTextFixed.'" name="'.$idTextFixed.'" '.
'value="'.$valueFixed.'" class="textBox" />';
$render.="</input>\n";
$render.="</div>\n";
return $render;
}
function RenderCombo($id,$options,$selected){
$idFixed=htmlentities($id,ENT_HTML5, "UTF-8");
$render='<div class="fieldContent">'."\n";
$render.='<select id="'.$idFixed.'" name="'.$idFixed.'" '.
'class="combo">'."\n";
foreach ($options as $key => $value) {
$keyFixed=htmlentities($key,ENT_HTML5, "UTF-8");
$valueFixed=htmlentities($value,ENT_HTML5, "UTF-8");
if($value==$selected){
$render.='<option value="'.$valueFixed.
'" title="'.$valueFixed.'" selected >'.
$keyFixed."</option>/n";
}else{
$render.='<option value="'.$valueFixed.
'" title="'.$valueFixed.'">'.
$keyFixed."</option>/n";
}
}
$render.="</select>\n";
$render.="</div>\n";
return $render;
}
function RenderButton($id,$value){
$idFixed=htmlentities($id,ENT_HTML5, "UTF-8");
$valueFixed=htmlentities($value,ENT_HTML5, "UTF-8");
return '<input type="submit" value="'.$valueFixed.'" '.
'id="'.$idFixed.'" name="'.$idFixed.'" class="button" />';
}
function RenderFieldInfo($text,$info){
$render='<div class="field">'."\n";
$render.=RenderLabel($text);
$render.=RenderInfo($info);
$render.='</div>'."\n";
return $render;
}
function RenderFieldText($text,$idText,$value){
$render='<div class="field">'."\n";
$render.=RenderLabel($text);
$render.=RenderText($idText,$value);
$render.='</div>'."\n";
return $render;
}
function RenderFieldCheck($text,$idCheck,$checked,$value){
$render='<div class="field">'."\n";
$render.=RenderLabel($text);
$render.=RenderCheck($idCheck,$checked,$value);
$render.='</div>'."\n";
return $render;
}
function RenderFieldCheckText($text,$idCheck,$checked,$idText,$value){
$render='<div class="field">'."\n";
$render.=RenderLabel($text);
$render.=RenderCheckText($idCheck,$checked,$idText,$value);
$render.='</div>'."\n";
return $render;
}
function RenderFieldCombo($text,$idCombo,$options,$selected){
$render='<div class="field">'."\n";
$render.=RenderLabel($text);
$render.=RenderCombo($idCombo,$options,$selected);
$render.='</div>'."\n";
return $render;
}
function RenderFieldButton($text,$idButton,$value){
$render='<div class="field">'."\n";
$render.=RenderLabel($text);
$render.=RenderButton($idButton,$value);
$render.='</div>'."\n";
return $render;
}
function RenderParagraph($text,$style=null){
if($text==null || $text==""){ return ""; }
$textFixed=htmlentities($text,ENT_HTML5, "UTF-8");
if($style==null){
return "<p>".$textFixed."</p>\n";
}else{
return "<p style=\"".$style."\">".$textFixed."</p>\n";
}
}

View File

@@ -1,104 +1,5 @@
<?php <?php
function DrawFieldInfo($text,$info){
$textFixed=htmlentities($text,ENT_HTML5, "UTF-8");
$infoFixed=htmlentities($info,ENT_HTML5, "UTF-8");
echo '<div class="field">'."\n";
echo '<span class="fieldLabel">'.$textFixed.":</span>\n";
echo '<div class="fieldText">'.$infoFixed."</div>\n";
echo '</div>'."\n";
}
function DrawFieldCombo($text,$id,$options,$selected){
$textFixed=htmlentities($text,ENT_HTML5, "UTF-8");
$idFixed=htmlentities($id,ENT_HTML5, "UTF-8");
echo '<div class="field">'."\n";
echo '<span class="fieldLabel">'.$textFixed.":</span>\n";
echo '<div class="fieldCombo">'."\n";
echo '<select id="'.$idFixed.'" name="'.$idFixed.'" '.
'class="combo">'."\n";
foreach ($options as $key => $value) {
$keyFixed=htmlentities($key,ENT_HTML5, "UTF-8");
$valueFixed=htmlentities($value,ENT_HTML5, "UTF-8");
if($value==$selected){
echo '<option value="'.$valueFixed.
'" title="'.$valueFixed.'" selected >'.
$keyFixed."</option>/n";
}else{
echo '<option value="'.$valueFixed.
'" title="'.$valueFixed.'">'.
$keyFixed."</option>/n";
}
}
echo "</select>\n";
echo "</div>\n";
echo '</div>'."\n";
}
function DrawFieldText($text,$idText,$value){
$textFixed=htmlentities($text,ENT_HTML5, "UTF-8");
$idTextFixed=htmlentities($idText,ENT_HTML5, "UTF-8");
$valueFixed=htmlentities($value,ENT_HTML5, "UTF-8");
echo '<div class="field">'."\n";
echo '<span class="fieldLabel">'.$textFixed.":</span>\n";
echo '<div class="fieldText">'."\n";
echo '<input type="text" id="'.$idTextFixed.'" name="'.$idTextFixed.'"'.
' value="'.$valueFixed.'" '.
' class="textBox"/>'."\n";
echo "</div>\n";
echo '</div>'."\n";
}
function DrawFieldCheck($text,$idCheck,$checked,$value){
$textFixed=htmlentities($text,ENT_HTML5, "UTF-8");
$idCheckFixed=htmlentities($idCheck,ENT_HTML5, "UTF-8");
$valueFixed=htmlentities($idText,ENT_HTML5, "UTF-8");
echo '<div class="field">'."\n";
echo '<span class="fieldLabel">'.$textFixed.":</span>\n";
echo '<div class="fieldCombo">'."\n";
echo '<input type="checkbox" id="'.$idCheckFixed.'" '.
'name="'.$idCheckFixed.'" ';
if($checked){ echo " checked "; }
echo 'class="check">'.$valueFixed."\n";
echo "</input>\n";
echo "</div>\n";
echo '</div>'."\n";
}
function DrawFieldCheckText($text,$idCheck,$checked,$idText,$value){
$textFixed=htmlentities($text,ENT_HTML5, "UTF-8");
$idCheckFixed=htmlentities($idCheck,ENT_HTML5, "UTF-8");
$idTextFixed=htmlentities($idText,ENT_HTML5, "UTF-8");
$valueFixed=htmlentities($value,ENT_HTML5, "UTF-8");
echo '<div class="field">'."\n";
echo '<span class="fieldLabel">'.$textFixed.":</span>\n";
echo '<div class="fieldCombo">'."\n";
echo '<input type="checkbox" id="'.$idCheckFixed.'" '.
'name="'.$idCheckFixed.'" ';
if($checked){ echo " checked "; }
echo 'class="check" />'."\n";
echo '<input type="text" id="'.$idTextFixed.'" name="'.$idTextFixed.'" '.
'value="'.$valueFixed.'" class="textBox" />';
echo "</div>\n";
echo '</div>'."\n";
}
function DrawButton($text,$id){
$textFixed=htmlentities($text,ENT_HTML5, "UTF-8");
$idFixed=htmlentities($id,ENT_HTML5, "UTF-8");
echo '<input type="submit" value="'.$textFixed.'" '.
'id="'.$idFixed.'" name="'.$idFixed.'" class="button" />';
}
function DrawParagraph($text,$style=null){
$textFixed=htmlentities($text,ENT_HTML5, "UTF-8");
if($style==null){
echo "<p>".$textFixed."</p>\n";
}else{
echo "<p style=\"".$style."\">".$textFixed."</p>\n";
}
}
function RequestParm($name,$defaultValue){ function RequestParm($name,$defaultValue){
if(isset($_GET[$name])){ if(isset($_GET[$name])){
return $_GET[$name]; return $_GET[$name];
@@ -127,4 +28,3 @@ function ExecFull($cmd, $input='') {
return array($return_code, $stdout, $stderr); return array($return_code, $stdout, $stderr);
} }
?>

View File

@@ -1,26 +1,26 @@
* {margin:0;padding:0;border:none;font-family:Arial,sans-serif; color:rgb(32,32,32);background-color:white; box-sizing:border-box; -moz-box-sizing:border-box;} * {margin:0;padding:0;border:none;font-family:Arial,sans-serif; color:rgb(32,32,32);background-color:white; box-sizing:border-box; -moz-box-sizing:border-box;}
h1{ h1{
font-size: 30px; font-size: 30px;
color: rgb(128,128,128); color: rgb(128,128,128);
margin:5px; margin:5px;
margin-top:10px; margin-top:10px;
} }
h1:first-child{ h1:first-child{
margin-top:5px; margin-top:5px;
} }
.field{ .field{
display:block; display:block;
white-space:nowrap; white-space:nowrap;
vertical-align:top; vertical-align:top;
font-size:0; font-size:0;
margin:5px; margin:5px;
margin-top:10px; margin-top:10px;
} }
.field:first-child{ .field:first-child{
margin-top:5px; margin-top:5px;
} }
.fieldLabel{ .fieldLabel{
display:inline-block; display:inline-block;
width:20%; width:20%;
font-weight: bold; font-weight: bold;
@@ -28,41 +28,40 @@
white-space: normal; white-space: normal;
word-break: break-word; word-break: break-word;
font-size:14px; font-size:14px;
} }
.fieldText, .fieldContent{
.fieldCombo{
display:inline-block; display:inline-block;
width:80%; width:80%;
white-space: normal; white-space: normal;
vertical-align:top; vertical-align:top;
word-break: break-word; word-break: break-word;
font-size:14px; font-size:14px;
} }
.combo{ .combo{
min-width:100px; min-width:100px;
border: solid 1px rgb(32,32,32); border: solid 1px rgb(32,32,32);
} }
.button{ .button{
display:inline-block; display:inline-block;
padding:5px; padding:5px;
margin:5px; margin:0;
background-color: rgb(192,192,192); background-color: rgb(192,192,192);
border: solid 1px rgb(32,32,32); border: solid 1px rgb(32,32,32);
cursor:pointer; cursor:pointer;
} }
.button:hover{ .button:hover{
background-color: rgb(240,240,240); background-color: rgb(240,240,240);
} }
.textBox{ .textBox{
border: solid 1px rgb(32,32,32); border: solid 1px rgb(32,32,32);
} }
.previewImage{ .previewImage{
margin:5px; margin:5px;
border: solid 1px rgb(32,32,32); border: solid 1px rgb(32,32,32);
max-width:200px; max-width:200px;
max-height:200px; max-height:200px;
} }