Skip to content

Commit

Permalink
Scan Page fixes/enhancements/cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
GM-Script-Writer-62850 committed Jul 12, 2013
1 parent 0f59cd7 commit 5c0e24f
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 85 deletions.
2 changes: 1 addition & 1 deletion inc/header.php
Expand Up @@ -70,7 +70,7 @@
</div>
</noscript>
<!--[if IE 8]><script type="text/javascript">ie8=true</script><![endif]-->
<!--[if lt IE 9]><div style="height:auto;" class="message ie center"><h2><noscript>Unsupported Browser</noscript><script type="text/javascript">document.write(ie8?'Warning: It is Recommended That you Upgrade Your Browser':'Error: Legacy Browsers are NOT Supported');</script></h2>
<!--[if lt IE 9]><div style="height:auto;" class="message ie center"><h2><noscript>Unsupported Browser</noscript><script type="text/javascript">document.write(ie8?'Notice: It is Recommended That you Upgrade Your Browser':'Error: Legacy Browsers are NOT Supported');</script></h2>
<p><noscript>This browser is unusable!</noscript><script type="text/javascript">document.write(ie8?'While you browser will technically works, everything is displays looks horrible.':'You can view the list of supported browsers in the <a href="index.php?page=About">release notes</a>.');</script><br/>
Please install <a href="http://www.mozilla.com/firefox/">Mozilla Firefox</a> (Recommended) alternatively, you may use<br/>
<a href="http://lmgtfy.com/?q=Internet+Explorer+10+Download">Internet Explorer 10</a> (Windows 7 and 8 only) or
Expand Down
123 changes: 73 additions & 50 deletions inc/main.js
Expand Up @@ -189,55 +189,57 @@ function encodeHTML(string){// http://stackoverflow.com/questions/24816/escaping
};
return String(string).replace(/[&<>"'\/]/g,function(s){return entityMap[s];});
}
function checkScanners(){
if(typeof(XMLHttpRequest)=='undefined'||typeof(JSON)!='object'){
return printMsg('Sorry',supportErrorA+"XMLHttpRequest and the JSON object so this page can not check if the scanner is in-use or not in real time."+supportErrorB,'center',0);
function buildScannerOptions(json){
var str='',id,name,loc,sel=0;
for(var i=0,m=json.length;i<m;i++){
if(json[i]["DEVICE"].substr(0,4)=="net:"){
loc=json[i]["DEVICE"].split(':');
loc=json[1];
}
else{
loc=document.domain;
}
if(json[i]["SELECTED"])
sel=i;
str+='<option'+(json[i]["INUSE"]==1?' disabled="disabled"':'')+(json[i]["SELECTED"]?' selected="selected"':'')+' value="'+json[i]["ID"]+'">'+json[i]["NAME"]+' on '+loc+'</option>';
}
if(document.all)// http://support.microsoft.com/kb/276228
document.scanning.scanner.parentNode.innerHTML='<select onchange="scannerChange(this)" style="width:238px;" name="scanner">'+str+'</select>';
else
document.scanning.scanner.innerHTML=str;
return sel;
}
function checkScanners(){
if(typeof(XMLHttpRequest)=='undefined')
return printMsg('Sorry',supportErrorA+"XMLHttpRequest so this page can not check if the scanner is in-use or not in real time."+supportErrorB,'center',0);
var httpRequest = new XMLHttpRequest();
httpRequest.onreadystatechange = function(){
if(httpRequest.readyState==4){
if(httpRequest.status==200){
var scan=parseJSON(httpRequest.responseText);
var loc, str;
str='';
if(scanners.length!=scan.length){
for(var i=0,m=scan.length;i<m;i++){
if(scan[i]["DEVICE"].substr(0,4)=="net:"){
loc=scan[i]["DEVICE"].split(':');
loc=loc[1];
}
else{
loc=document.domain;
}
delete(scan[i]["INUSE"]);
delete(scan[i]["ID"]);
delete(scan[i]["DEVICE"]);
delete(scan[i]["NAME"]);
delete(scan[i]["UUID"]);
str+='<option'+(scan[i]["INUSE"]==1?' disabled="disabled"':'')+' class="'+encodeHTML(JSON.stringify(scan[i]))+'" value="'+scan[i]["ID"]+'">'+scan[i]["NAME"]+' on '+loc+'</option>';
}
scanners=scan;
loc=document.scanning.scanner.selectedIndex;
if(document.all)// http://support.microsoft.com/kb/276228
document.scanning.scanner.parentNode.innerHTML='<p><select onchange="scannerChange(this)" style="width:238px;" name="scanner">'+str+'</select></p>';
else
document.scanning.scanner.innerHTML=str;
document.scanning.scanner.selectedIndex=loc;
alert("The number of scanners connected to the server has been altered\nPlease double check the scanner you are using");
}
else{
for(var i=0,m=scanners.length;i<m;i++){
if(scan[i]['INUSE']!=scanners[i]['INUSE']){
if(JSON.stringify(scanners)!=JSON.stringify(scan)){// Something changed
var l=document.scanning.scanner.selectedIndex,oldDevice,newDevice,device,def,found=false,inUse=false;
oldDevice=scanners[l]['UUID']==null?scanners[l]["DEVICE"]:scanners[l]['UUID'];
def=buildScannerOptions(scan);// Update Scanner HTML
for(var i=0,m=scan.length;i<m;i++){//Find current scanner
newDevice=scan[i]['UUID']==null?scan[i]["DEVICE"]:scan[i]['UUID'];
if(newDevice==oldDevice){
found=true;
document.scanning.scanner.selectedIndex=i;
if(scan[i]['INUSE']==1)
document.scanning.scanner.childNodes[i].setAttribute("disabled","disabled");
else
document.scanning.scanner.childNodes[i].removeAttribute('disabled');
printMsg('Information',"The scanner currently selected is being used by someone right now",'center',0);
break;
}
}
scanners=scan;
scanners=scan;// Update global variable
if(!found){//Current scanner is no longer present
printMsg('Information',"The scanner you had selected is no longer available",'center',0);
document.scanning.scanner.selectedIndex=def;
sendE(document.scanning.scanner,'change');
}
}
}
setTimeout("checkScanners()",5000);
setTimeout(checkScanners,5000);
}
};
httpRequest.open('GET', 'config/scanners.json?cacheBust='+new Date().getTime(), true);
Expand Down Expand Up @@ -272,9 +274,17 @@ function parseJSON(jsonTXT){
printMsg('Invald Javascript Object Notation:','<textarea onclick="this.select()" style="width:100%;height:80px;">'+encodeHTML(jsonTXT)+'</textarea><br/>If you are reading this please report it as a bug. Please copy/paste the above, something as simple as a line break can cause errors here. If want to read this I suggest pasting it onto <a target="_blank" href="http://jsonlint.com/">jsonlint.com</a>.','center',0);
}
}
function inArray(arr,val){
for(var i=0;i<arr.length;i++){
if(arr[i]==val){
return true;
}
}
return false;
}
function scannerChange(ele){
var info=parseJSON(ele.childNodes[ele.selectedIndex].className);
var html='',text;
var info=scanners[ele.selectedIndex];
var html='',text,val=document.scanning.source.value;
sources=info['SOURCE'].split('|');
for(i=0,s=sources.length;i<s;i++){
switch(sources[i]){
Expand All @@ -288,18 +298,20 @@ function scannerChange(ele){
document.scanning.source.parentNode.innerHTML='<select name="source" class="title" onchange="sourceChange(this)">'+html+'</select>';
else
document.scanning.source.innerHTML=html;
if(inArray(sources,val))
document.scanning.source.value=val;
if(document.scanning.source.value=='Inactive')
document.scanning.source.setAttribute('disabled','disabled');
else
document.scanning.source.removeAttribute('disabled');
sourceChange(document.scanning.source);
}
function sourceChange(ele){
var info,text,html,html2,html3,dpi;
var info,text,html1,html2,html3,dpi,modes,valA,valB,valC;
info=document.scanning.scanner;
info=parseJSON(info.childNodes[info.selectedIndex].className);
info=scanners[info.selectedIndex];
// Change Mode
html='';
html1='';
modes=info['MODE-'+ele.value].split('|');
for(i=modes.length-1;i>-1;i--){
switch(modes[i]){
Expand All @@ -310,33 +322,45 @@ function sourceChange(ele){
default:
text=modes[i];
}
html+='<option value="'+modes[i]+'">'+text+'</option>';
html1+='<option value="'+modes[i]+'">'+text+'</option>';
}
// Change Paper Size
papers=Array();
width=info['WIDTH-'+ele.value];
height=info['HEIGHT-'+ele.value];
html2='<option value="full" title="'+width+' mm x '+height+' mm">Full Scan: '+roundNumber(width/25.4,2)+'" x '+roundNumber(height/25.4,2)+'"</option>';
for(var i in paper){
if(width>=paper[i]['width']&&height>=paper[i]['height'])
html2+='<option value="'+paper[i]['width']+'-'+paper[i]['height']+'" title="'+paper[i]['width']+' mm x '+paper[i]['height']+' mm"'+(i=='Letter'?' selected':'')+'>'+i+': '+
if(width>=paper[i]['width']&&height>=paper[i]['height']){
html2+='<option value="'+paper[i]['width']+'-'+paper[i]['height']+'" title="'+paper[i]['width']+' mm x '+paper[i]['height']+' mm"'+(i=='Letter'?' selected="selected"':'')+'>'+i+': '+
roundNumber(paper[i]['width']/25.4,2)+'" x '+roundNumber(paper[i]['height']/25.4,2)+'"</option>';
papers.push(paper[i]['width']+'-'+paper[i]['height']);
}
}
// Change Quality
html3='';
dpi=info['DPI-'+ele.value].split('|');
for(var i=0,max=dpi.length;i<max;i++)
html3+='<option value="'+dpi[i]+'">'+dpi[i]+' '+(isNaN(dpi[i])?'':'DPI')+'</option>';
// Apply Changes
valA=document.scanning.mode.value;
valB=document.scanning.size.value;
valC=document.scanning.quality.value;
if(document.all){// http://support.microsoft.com/kb/276228
document.scanning.mode.parentNode.innerHTML='<select name="mode" class="title">'+html1+'</select>';
document.scanning.size.parentNode.innerHTML='<select onchange="paperChange(this);" name="size">'+html2+'</select>';
document.scanning.mode.parentNode.innerHTML='<select name="mode" class="title">'+html+'</select>';
document.scanning.quality.parentNode.innerHTML='<select name="quality" class="upper">'+html3+'</select>';
}
else{
document.scanning.mode.innerHTML=html1;
document.scanning.size.innerHTML=html2;
document.scanning.mode.innerHTML=html;
document.scanning.quality.innerHTML=html3;
}
if(inArray(modes,valA))
document.scanning.mode.value=valA;
if(inArray(papers,valB))
document.scanning.size.value=valB;
if(inArray(dpi,valC))
document.scanning.quality.value=valC;
if(info['DUPLEX-'+ele.value])
getID('duplex').removeAttribute('style');
else
Expand All @@ -350,8 +374,7 @@ function paperChange(ele){
document.scanning.ornt.disabled='disabled';
return;
}
var json=document.scanning.scanner.childNodes[document.scanning.scanner.selectedIndex].className;
json=parseJSON(json);
var json=scanners[document.scanning.scanner.selectedIndex];
var width=json['WIDTH-'+document.scanning.source.value];
var height=json['HEIGHT-'+document.scanning.source.value];
// Set Orientation
Expand Down
32 changes: 4 additions & 28 deletions inc/scan.php
Expand Up @@ -6,32 +6,8 @@

<div class="side_box">
<h2>Scanners</h2>
<div class="ie_276228"><p><select name="scanner" style="width:238px;" onchange="scannerChange(this)"><?php
$SEL=0;
for($i=0,$max=count($CANNERS);$i<$max;$i++){
if(isset($CANNERS[$i]->{"SELECTED"}))
$SEL=$i;
if(substr($CANNERS[$i]->{"DEVICE"},0,4)=="net:"){
$loc=explode(":",$CANNERS[$i]->{"DEVICE"});
$loc=$loc[1];// The following is disabled for AJAX processing
/* if($loc=="127.0.0.1"||$loc==$_SERVER['SERVER_ADDR']||$loc=="localhost") //will need rewrite for ipv6
continue;//try to filter reduntant scanners (network scanner on the localhost)*/
}
else{
//echo '<!-- '.$_SERVER['SERVER_NAME'].' -->';
$loc=$_SERVER['SERVER_NAME'];
}
$CANNER=clone $CANNERS[$i];
unset($CANNER->{"INUSE"});
unset($CANNER->{"ID"});
unset($CANNER->{"DEVICE"});
unset($CANNER->{"NAME"});
unset($CANNER->{"UUID"});
echo '<option class="'.html(json_encode($CANNER)).'"'.($CANNERS[$i]->{"INUSE"}==1?' disabled="disabled"':'').(isset($CANNERS[$i]->{"SELECTED"})&&$CANNERS[$i]->{"INUSE"}!=1?' selected="selected"':'').' value="'.$CANNERS[$i]->{"ID"}.'">'.$CANNERS[$i]->{"NAME"}.' on '.$loc.'</option>';
}
$defSource=explode('|',$CANNERS[$SEL]->{"SOURCE"})[0];
?></select></p></div><!-- AJAX in scanner data -->
<script type="text/javascript">scanners=<?php echo json_encode($CANNERS); ?>;setTimeout("checkScanners()",5000);</script>
<p><select name="scanner" style="width:238px;" onchange="scannerChange(this)"></select></p>
<script type="text/javascript">scanners=<?php echo json_encode($CANNERS); ?>;buildScannerOptions(scanners);setTimeout(checkScanners,5000);</script>

</div>

Expand Down Expand Up @@ -59,7 +35,7 @@
</div>
<div class="control tool">
<div class="ie_276228"><select name="size" onchange="paperChange(this);"></select>
</div><span class="tip"><?php echo $CANNERS[$SEL]->{"WIDTH-$defSource"}.' mm x '.$CANNERS[$SEL]->{"HEIGHT-$defSource"}.' mm'; ?></span>
</div><span class="tip"></span>
<script type="text/javascript">paper=<?php
echo file_exists("config/paper.json")?file_get_contents("config/paper.json"):'{"Picture":{"height":152.4,"width":101.6},"Paper":{"height":279.4,"width":215.9}}'; ?></script>
</div>
Expand Down Expand Up @@ -92,7 +68,7 @@
<div class="ie_276228"><select name="mode" class="title"></select></div>
</div>

<div id="duplex"<?php echo $CANNERS[$SEL]->{"DUPLEX-$defSource"}?'':' style="display:none;"'; ?>>
<div id="duplex">
<div class="label tool">
<span>Duplex<span class="tip">Double Sided Scan</span></span>:
</div>
Expand Down
7 changes: 1 addition & 6 deletions index.php
Expand Up @@ -837,12 +837,7 @@ function quit(){
# ****************
else{
InsertHeader("Scan Image");
if(file_exists("config/scanners.json")){
$CANNERS=json_decode(file_get_contents("config/scanners.json"));
}
else{
$CANNERS=json_decode('[]');
}
$CANNERS=json_decode(file_exists("config/scanners.json")?file_get_contents("config/scanners.json"):'[]');
if(strlen($SAVEAS)>0||$ACTION=="Scan Image"){
$langs=findLangs();
if(!validNum(Array($SCANNER,$BRIGHT,$CONTRAST,$SCALE,$ROTATE))||!in_array($LANG,$langs)||!in_array($QUALITY,explode("|",$CANNERS[$SCANNER]->{"DPI-$SOURCE"}))){//security check
Expand Down

0 comments on commit 5c0e24f

Please sign in to comment.