<?php
/*
* $Source: /cvsroot/irma/irma/includes/barcode/functions.php,v $
* $Author: bbaez $
* $Date: 2006/10/24 18:30:20 $
* $Revision: 1.1.1.1 $
*/
function inputSelect() {
GLOBAL $cfg_layout, $lang, $id_prefix_AR;
echo "<center><table border=0 width=70%>";
echo "<tr><th colspan=1><b>Select a method to search input:</b></th></tr>";
echo "<form method=get action=\"".$_SERVER['PHP_SELF']."\">";
echo "<tr bgcolor=".$cfg_layout["tab_bg_1"].">";
echo "<td align=center>Search by ";
echo " <select name=id_prefix size=1>";
reset($id_prefix_AR);
for ($i=0; $i < count($id_prefix_AR); $i++) {
list($key,$val) = each ($id_prefix_AR);
echo "<option value=$key>$val\n";
}
echo "</select>";
echo " serial number:";
echo "<input type=hidden name=idtype value=sn>";
echo " <input type=submit value=\"".$lang['buttons']['select']."\"></td>"; echo "</form>\n";
echo "<tr>\n";
echo "<tr bgcolor=".$cfg_layout["tab_bg_1"].">";
echo "<td align=center><A HREF=\"".$_SERVER['PHP_SELF']."?idtype=irma\">Search by IRMA ID</A></td>";
echo "<tr>\n";
echo "<tr bgcolor=".$cfg_layout["tab_bg_1"].">";
echo "<td align=center><A HREF=\"".$_SERVER['PHP_SELF']."?idtype=unknown\">Search all of IRMA</A></td>";
echo "<tr>\n";
echo "</table></center>\n";
}
function inputDisplay($input) {
GLOBAL $cfg_install, $lang, $id_prefix_AR;
extract($input);
echo "<center><table border=0 width=70%>";
// myForm for javascripting focus() function
echo "<form name=\"myForm\" method=get action=\"".$_SERVER['PHP_SELF']."\">";
echo "<input type=hidden name=idtype value=\"$idtype\">";
if ($idtype == 'sn') {
echo "<tr><th colspan=2><b>Search by ".$id_prefix_AR[$id_prefix]." Serial Number:</b></th></tr>";
echo "<input type=hidden name=id_prefix value=\"$id_prefix\">";
echo "<tr><td align=center>\n";
echo '<IMG src="/irma/pics/barcode.png" border=0 alt="Example Serial Barcode" vspace=10 onLoad="javascript:document.myForm.inputscan.focus()">';
echo "</td></tr>\n";
} else if ($idtype == 'irma') {
echo "<tr><th colspan=2><b>Searching by IRMA ID:</b></th></tr>";
echo "<tr><td align=center>\n";
echo '<IMG src="' . $cfg_install['barcode']['exampleImgPath'] . '" border=0 alt="Example Barcode" vspace=10 onLoad="javascript:document.myForm.inputscan.focus()">';
echo "</td></tr>\n";
} else if ($idtype == 'unknown') {
echo "<tr><th colspan=2><b>Search all Serial Number Fields in IRMA:</b></th></tr>";
echo "<tr><td align=center>\n";
echo '<IMG src="/irma/pics/barcode.png" border=0 alt="Example Generic Barcode" vspace=10 onLoad="javascript:document.myForm.inputscan.focus()">';
echo "</td></tr>\n";
}
echo "<tr bgcolor=".$cfg_layout["tab_bg_1"].">";
echo "<td align=center>\n";
echo "<input type=text name=inputscan value=\"\" onChange=\"javascript:this.form.submit();\">";
echo " <input type=submit name=search value=\"".$lang["buttons"][0]."\"></td>";
echo "</form>";
echo "<tr>\n";
echo "</table></center>\n";
}
function irmaIdDecode($inputscan) {
GLOBAL $cfg_install;
ereg('^([A-Z]{2})([0-9]{6})$',$inputscan,$regs);
// Need to strip leading zeros at some point?
$ID=$regs[2];
switch ($regs[1]) {
case 'CP';
header('Location: '.$cfg_install['root'].'/computers/computers-info-form.php?ID='.$ID);
exit;
break;
case 'MO';
header('Location: '.$cfg_install['root'].'/monitors/monitors-info-form.php?ID='.$ID);
break;
case 'PD';
header('Location: '.$cfg_install['root'].'/pda/pda-info-form.php?ID='.$ID);
break;
case 'PR';
header('Location: '.$cfg_install['root'].'/printers/printers-info-form.php?ID='.$ID);
break;
case 'MI';
header('Location: '.$cfg_install['root'].'/miscellaneous/miscellaneous-info-form.php?ID='.$ID);
break;
case 'NE';
header('Location: '.$cfg_install['root'].'/networking/networking-info-form.php?ID='.$ID);
break;
}
}
function serialDecode($input) {
GLOBAL $cfg_install, $id_prefix_AR;
extract($input);
if (!($id_prefix)) {
GLOBAL $mi_AR, $mo_AR;
$input_length = strlen($inputscan);
$input_alpha = ereg('[A-Z]',$inputscan);
if ($input_length=='7' && $input_alpha) {
// Dell Service Tag
$id_prefix='CP';
} else if ($input_length=='20') {
// Dell DS/N
ereg('^([A-Z]{1,2})([A-Z0-9]{6})([0-9]{5})([A-Z0-9]{7})$',$inputscan,$regs);
if (in_array($regs[2],$mo_AR)) {
$id_prefix='MO';
} else if (in_array($regs[2],$mi_AR)) {
$id_prefix='MI';
}
} else {
$id_prefix='UNK';
}
}
// Search all serial fields
$serials = ARRAY( 'serial' => $inputscan,
'dellserial' => $inputscan
);
switch ($id_prefix) {
case 'CP';
$type = $id_prefix_AR[$id_prefix];
extract(verifySerialsCore($serials,$type));
if ($numrows==0) {
header('Location: '.$cfg_install['root']."/$type/$type-add-select.php");
} else {
$data = mysql_fetch_array($result);
extract($data,EXTR_PREFIX_ALL,'db');
header('Location: '.$cfg_install['root']."/$type/$type-info-form.php?ID=$db_ID");
}
break;
case 'MO';
$type = $id_prefix_AR[$id_prefix];
extract(verifySerialsCore($serials,$type));
if ($numrows==0) {
header('Location: '.$cfg_install['root']."/$type/$type-add-select.php");
} else {
$data = mysql_fetch_array($result);
extract($data,EXTR_PREFIX_ALL,'db');
header('Location: '.$cfg_install['root']."/$type/$type-info-form.php?ID=$db_ID");
}
break;
case 'PD';
break;
case 'PR';
break;
case 'MI';
$type = $id_prefix_AR[$id_prefix];
extract(verifySerialsCore($serials,$type));
if ($numrows==0) {
header('Location: '.$cfg_install['root']."/$type/$type-add-select.php");
} else {
$data = mysql_fetch_array($result);
extract($data,EXTR_PREFIX_ALL,'db');
header('Location: '.$cfg_install['root']."/$type/$type-info-form.php?ID=$db_ID");
}
break;
case 'NE';
break;
case 'UNK';
foreach($id_prefix_AR as $key => $type) {
extract(verifySerialsCore($serials,$type));
if ($numrows==1) {
$data = mysql_fetch_array($result);
extract($data,EXTR_PREFIX_ALL,'db');
header('Location: '.$cfg_install['root']."/$type/$type-info-form.php?ID=$db_ID");
}
}
break;
}
}
?>