<?php
/**
* @author Bettina Schwarzer, Fritz-Haber-Institut
* @copyright 04/2012
*
* Test multiple select autocomplete
* liefert Begriff und ids als ;-separierte Strings
*
*/
error_reporting(E_ALL ^ E_NOTICE);
include_once($_SERVER['DOCUMENT_ROOT'] ."/fhiiqm/inc/dbconnect.inc.php");
$dbc = new dbconnection();
$sub = $_POST['eintragen'];
$pz = $_POST['pz'];
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
<link href="/fhiiqm/css/db.css" rel="STYLESHEET" type="TEXT/CSS" media="screen"/>
<link href="/fhiiqm/css/db_print.css" rel="STYLESHEET" type="TEXT/CSS" media="print"/>
<link type="text/css" href="/fhiiqm/css/jquery/ui-lightness/jquery-ui-1.8.16.custom.css" rel="Stylesheet" />
<script type="text/javascript" src="/fhiiqm/js/jquery/jquery-1.6.2.min.js"></script>
<script type="text/javascript" src="/fhiiqm/js/jquery/jquery-ui-1.8.16.custom.min.js"></script>
<title>autocomplete multiple select</title>
</head>
<body>
<script>
function split( val ) {
return val.split( /;\s*/ );
}
function extractLast( term ) {
return split( term ).pop();
}
var ids = new Array;
$(document).ready(function() {
$("#pers").focus();
$("#pers")
.bind( "keydown", function( event ) {
if ( event.keyCode === $.ui.keyCode.TAB &&
$( this ).data( "autocomplete" ).menu.active ) {
event.preventDefault();
alert (event.keyCode);
}
})
.autocomplete({
// source: "/fhiiqm/inc/ma_list_ac.inc.php",
// minLength: 2,
// select: function(event,ui){$("#pid").val(ui.item.id);}
source: function( request, response ) {
// $.getJSON( "/fhiiqm/inc/ma_list_ac.inc.php", {
$.getJSON( "/fhiiqm/test/ma_list_autocomp.php", {
term: extractLast( request.term )
}, response );
},
focus: function() {
// prevent value inserted on focus
return false;
},
select: function( event, ui ) {
var terms = split( this.value );
// alert ("eingabe: "+terms+ ", ids="+ids.toString());
// remove the current input
terms.pop();
// add the selected item
terms.push( ui.item.value );
ids.push(ui.item.id);
$("#pid").val(ids.join(";"));
// add placeholder to get the comma-and-space at the end
terms.push( "" );
// alert ("select: "+terms+ "ids = "+$("#pid").val());
this.value = terms.join( "; " );
return false;
},
search: function() {
// custom minLength
var term = extractLast( this.value );
if ( term.length < 2 ) {
return false;
}
}
});
});
</script>
<?php
if (!$sub)
{
?>
<form action="<?php $_SERVER['PHP_SELF'] ?>" method="post" enctype="multipart/form-data" name="form_info" target="_self">
<div align="center">
<p>Auswahl mehrerer Verantwortlicher in einem Eingabefeld</p>
<table width="60%" border="0" cellspacing="3" cellpadding="3">
<tr>
<td>Verantwortliche(r)</td>
<td><textarea cols="60" rows="5" name="pz[pers]" id="pers" ><?php echo $pz['pers']; ?></textarea>
<br />Eingabe von mind. 2 Zeichen -> Namensliste, Wiederholung für weitere Namen
</td>
</tr>
<input type="hidden" name="pz[persknr]" id="pid" value="<?php echo $pz['persknr']; // Verantwortlicher?>"/>
<?php
echo "
<tr><td> </td>\n
<td><input class=\"button\" type=\"submit\" name=\"eintragen\" value=\" eintragen \" />";
echo "<table\n";
echo "</div>\n";
echo "<form>\n";
}
else
{
echo "<p> ausgewählte Mitarbeiter:</p>";
$pers = explode("; ",$pz["pers"]);
$pnr = explode (";",$pz["persknr"]);
for ($i=0; $i < count($pers)-1;$i++)
{
echo " " . $pnr[$i]. " - " . $pers[$i] . "<br />\n";
}
// echo "<p> Mitarbeiter:<br /> " . str_replace("; ","<br /> ",$pz["pers"]) .
// "<br /> persknr:<br /> " . str_replace(";","<br /> ",$pz["persknr"]) . "</p>";
}
?>
</body>
</html>