"ae",
"ö" => "oe",
"ü" => "ue",
"Ä" => "Ae",
"Ö" => "Oe",
"Ü" => "Ue",
"ß" => "ss",
"á" => "a",
"é" => "e",
"í" => "i",
"ó" => "o",
"ú" => "u",
"Á" => "A",
"É" => "E",
"Í" => "I",
"Ó" => "O",
"Ú" => "U",
"ñ" => "ny",
"Ñ" => "Ny" );
/* Class autoloader */
function __autoload($class_name) {
global $class_mapping, $BASE_DIR;
if ($class_mapping === NULL){
echo sprintf(_("Fatal error: no class locations defined - please run '%s' to fix this"), "update-gosa");
exit;
}
if (isset($class_mapping[$class_name])){
require_once($BASE_DIR."/".$class_mapping[$class_name]);
} else {
echo sprintf(_("Fatal error: cannot instantiate class '%s' - try running '%s' to fix this"), $class_name, "update-gosa");
exit;
}
}
/*! \brief Checks if a class is available.
* @param name String The class name.
* @return boolean True if class is available, else false.
*/
function class_available($name)
{
global $class_mapping;
return(isset($class_mapping[$name]));
}
/* Check if plugin is avaliable */
function plugin_available($plugin)
{
global $class_mapping, $BASE_DIR;
if (!isset($class_mapping[$plugin])){
return false;
} else {
return is_readable($BASE_DIR."/".$class_mapping[$plugin]);
}
}
/* Create seed with microseconds */
function make_seed() {
list($usec, $sec) = explode(' ', microtime());
return (float) $sec + ((float) $usec * 100000);
}
/* Debug level action */
function DEBUG($level, $line, $function, $file, $data, $info="")
{
if (session::get('DEBUGLEVEL') & $level){
$output= "DEBUG[$level] ";
if ($function != ""){
$output.= "($file:$function():$line) - $info: ";
} else {
$output.= "($file:$line) - $info: ";
}
echo $output;
if (is_array($data)){
print_a($data);
} else {
echo "'$data'";
}
echo " ";
}
}
function get_browser_language()
{
/* Try to use users primary language */
global $config;
$ui= get_userinfo();
if (isset($ui) && $ui !== NULL){
if ($ui->language != ""){
return ($ui->language.".UTF-8");
}
}
/* Check for global language settings in gosa.conf */
if (isset ($config) && $config->get_cfg_value('language') != ""){
$lang = $config->get_cfg_value('language');
if(!preg_match("/utf/i",$lang)){
$lang .= ".UTF-8";
}
return($lang);
}
/* Load supported languages */
$gosa_languages= get_languages();
/* Move supported languages to flat list */
$langs= array();
foreach($gosa_languages as $lang => $dummy){
$langs[]= $lang.'.UTF-8';
}
/* Return gettext based string */
return (al2gt($langs, 'text/html'));
}
/* Rewrite ui object to another dn */
function change_ui_dn($dn, $newdn)
{
$ui= session::get('ui');
if ($ui->dn == $dn){
$ui->dn= $newdn;
session::set('ui',$ui);
}
}
/* Return theme path for specified file */
function get_template_path($filename= '', $plugin= FALSE, $path= "")
{
global $config, $BASE_DIR;
/* Set theme */
if (isset ($config)){
$theme= $config->get_cfg_value("theme", "default");
} else {
$theme= "default";
}
/* Return path for empty filename */
if ($filename == ''){
return ("themes/$theme/");
}
/* Return plugin dir or root directory? */
if ($plugin){
if ($path == ""){
$nf= preg_replace("!^".$BASE_DIR."/!", "", session::get('plugin_dir'));
} else {
$nf= preg_replace("!^".$BASE_DIR."/!", "", $path);
}
if (file_exists("$BASE_DIR/ihtml/themes/$theme/$nf")){
return ("$BASE_DIR/ihtml/themes/$theme/$nf/$filename");
}
if (file_exists("$BASE_DIR/ihtml/themes/default/$nf")){
return ("$BASE_DIR/ihtml/themes/default/$nf/$filename");
}
if ($path == ""){
return (session::get('plugin_dir')."/$filename");
} else {
return ($path."/$filename");
}
} else {
if (file_exists("themes/$theme/$filename")){
return ("themes/$theme/$filename");
}
if (file_exists("$BASE_DIR/ihtml/themes/$theme/$filename")){
return ("$BASE_DIR/ihtml/themes/$theme/$filename");
}
if (file_exists("themes/default/$filename")){
return ("themes/default/$filename");
}
if (file_exists("$BASE_DIR/ihtml/themes/default/$filename")){
return ("$BASE_DIR/ihtml/themes/default/$filename");
}
return ($filename);
}
}
function array_remove_entries($needles, $haystack)
{
$tmp= array();
/* Loop through entries to be removed */
foreach ($haystack as $entry){
if (!in_array($entry, $needles)){
$tmp[]= $entry;
}
}
return ($tmp);
}
function array_remove_entries_ics($needles, $haystack)
{
$tmp= array();
/* Loop through entries to be removed */
foreach ($haystack as $entry){
if (!in_array_ics($entry, $needles)){
$tmp[]= $entry;
}
}
return ($tmp);
}
function gosa_array_merge($ar1,$ar2)
{
if(!is_array($ar1) || !is_array($ar2)){
trigger_error("Specified parameter(s) are not valid arrays.");
}else{
return(array_values(array_unique(array_merge($ar1,$ar2))));
}
}
function gosa_log ($message)
{
global $ui;
/* Preset to something reasonable */
$username= " unauthenticated";
/* Replace username if object is present */
if (isset($ui)){
if ($ui->username != ""){
$username= "[$ui->username]";
} else {
$username= "unknown";
}
}
syslog(LOG_INFO,"GOsa$username: $message");
}
function ldap_init ($server, $base, $binddn='', $pass='')
{
global $config;
$ldap = new LDAP ($binddn, $pass, $server,
isset($config->current['LDAPFOLLOWREFERRALS']) && $config->current['LDAPFOLLOWREFERRALS'] == "true",
isset($config->current['LDAPTLS']) && $config->current['LDAPTLS'] == "true");
/* Sadly we've no proper return values here. Use the error message instead. */
if (!$ldap->success()){
msg_dialog::display(_("Fatal error"),
sprintf(_("FATAL: Error when connecting the LDAP. Server said '%s'."), $ldap->get_error()),
FATAL_ERROR_DIALOG);
exit();
}
/* Preset connection base to $base and return to caller */
$ldap->cd ($base);
return $ldap;
}
function process_htaccess ($username, $kerberos= FALSE)
{
global $config;
/* Search for $username and optional @REALM in all configured LDAP trees */
foreach($config->data["LOCATIONS"] as $name => $data){
$config->set_current($name);
$mode= "kerberos";
if ($config->get_cfg_value("useSaslForKerberos") == "true"){
$mode= "sasl";
}
/* Look for entry or realm */
$ldap= $config->get_ldap_link();
if (!$ldap->success()){
msg_dialog::display(_("LDAP error"),
msgPool::ldaperror($ldap->get_error(), "", LDAP_AUTH)."
".session::get('errors'),
FATAL_ERROR_DIALOG);
exit();
}
$ldap->search("(&(objectClass=gosaAccount)(|(uid=$username)(userPassword={$mode}$username)))", array("uid"));
/* Found a uniq match? Return it... */
if ($ldap->count() == 1) {
$attrs= $ldap->fetch();
return array("username" => $attrs["uid"][0], "server" => $name);
}
}
/* Nothing found? Return emtpy array */
return array("username" => "", "server" => "");
}
function ldap_login_user_htaccess ($username)
{
global $config;
/* Look for entry or realm */
$ldap= $config->get_ldap_link();
if (!$ldap->success()){
msg_dialog::display(_("LDAP error"),
msgPool::ldaperror($ldap->get_error(), "", LDAP_AUTH)."
".session::get('errors'),
FATAL_ERROR_DIALOG);
exit();
}
$ldap->search("(&(objectClass=gosaAccount)(uid=$username))", array("uid"));
/* Found no uniq match? Strange, because we did above... */
if ($ldap->count() != 1) {
msg_dialog::display(_("LDAP error"), _("Username / UID is not unique inside the LDAP tree!"), FATAL_ERROR_DIALOG);
return (NULL);
}
$attrs= $ldap->fetch();
/* got user dn, fill acl's */
$ui= new userinfo($config, $ldap->getDN());
$ui->username= $attrs['uid'][0];
/* No password check needed - the webserver did it for us */
$ldap->disconnect();
/* Username is set, load subtreeACL's now */
$ui->loadACL();
/* TODO: check java script for htaccess authentication */
session::set('js',true);
return ($ui);
}
function ldap_login_user ($username, $password)
{
global $config;
/* look through the entire ldap */
$ldap = $config->get_ldap_link();
if (!$ldap->success()){
msg_dialog::display(_("LDAP error"),
msgPool::ldaperror($ldap->get_error(), "", LDAP_AUTH)."
".session::get('errors'),
FATAL_ERROR_DIALOG);
exit();
}
$ldap->cd($config->current['BASE']);
$allowed_attributes = array("uid","mail");
$verify_attr = array();
if($config->get_cfg_value("loginAttribute") != ""){
$tmp = split(",", $config->get_cfg_value("loginAttribute"));
foreach($tmp as $attr){
if(in_array($attr,$allowed_attributes)){
$verify_attr[] = $attr;
}
}
}
if(count($verify_attr) == 0){
$verify_attr = array("uid");
}
$tmp= $verify_attr;
$tmp[] = "uid";
$filter = "";
foreach($verify_attr as $attr) {
$filter.= "(".$attr."=".$username.")";
}
$filter = "(&(|".$filter.")(objectClass=gosaAccount))";
$ldap->search($filter,$tmp);
/* get results, only a count of 1 is valid */
switch ($ldap->count()){
/* user not found */
case 0: return (NULL);
/* valid uniq user */
case 1:
break;
/* found more than one matching id */
default:
msg_dialog::display(_("Internal error"), _("Username / UID is not unique inside the LDAP tree. Please contact your Administrator."), FATAL_ERROR_DIALOG);
return (NULL);
}
/* LDAP schema is not case sensitive. Perform additional check. */
$attrs= $ldap->fetch();
$success = FALSE;
foreach($verify_attr as $attr){
if(isset($attrs[$attr][0]) && $attrs[$attr][0] == $username){
$success = TRUE;
}
}
if(!$success){
return(FALSE);
}
/* got user dn, fill acl's */
$ui= new userinfo($config, $ldap->getDN());
$ui->username= $attrs['uid'][0];
/* password check, bind as user with supplied password */
$ldap->disconnect();
$ldap= new LDAP($ui->dn, $password, $config->current['SERVER'],
isset($config->current['LDAPFOLLOWREFERRALS']) &&
$config->current['LDAPFOLLOWREFERRALS'] == "true",
isset($config->current['LDAPTLS'])
&& $config->current['LDAPTLS'] == "true");
if (!$ldap->success()){
return (NULL);
}
/* Username is set, load subtreeACL's now */
$ui->loadACL();
return ($ui);
}
function ldap_expired_account($config, $userdn, $username)
{
$ldap= $config->get_ldap_link();
$ldap->cat($userdn);
$attrs= $ldap->fetch();
/* default value no errors */
$expired = 0;
$sExpire = 0;
$sLastChange = 0;
$sMax = 0;
$sMin = 0;
$sInactive = 0;
$sWarning = 0;
$current= date("U");
$current= floor($current /60 /60 /24);
/* special case of the admin, should never been locked */
/* FIXME should allow any name as user admin */
if($username != "admin")
{
if(isset($attrs['shadowExpire'][0])){
$sExpire= $attrs['shadowExpire'][0];
} else {
$sExpire = 0;
}
if(isset($attrs['shadowLastChange'][0])){
$sLastChange= $attrs['shadowLastChange'][0];
} else {
$sLastChange = 0;
}
if(isset($attrs['shadowMax'][0])){
$sMax= $attrs['shadowMax'][0];
} else {
$smax = 0;
}
if(isset($attrs['shadowMin'][0])){
$sMin= $attrs['shadowMin'][0];
} else {
$sMin = 0;
}
if(isset($attrs['shadowInactive'][0])){
$sInactive= $attrs['shadowInactive'][0];
} else {
$sInactive = 0;
}
if(isset($attrs['shadowWarning'][0])){
$sWarning= $attrs['shadowWarning'][0];
} else {
$sWarning = 0;
}
/* is the account locked */
/* shadowExpire + shadowInactive (option) */
if($sExpire >0){
if($current >= ($sExpire+$sInactive)){
return(1);
}
}
/* the user should be warned to change is password */
if((($sExpire >0) && ($sWarning >0)) && ($sExpire >= $current)){
if (($sExpire - $current) < $sWarning){
return(2);
}
}
/* force user to change password */
if(($sLastChange >0) && ($sMax) >0){
if($current >= ($sLastChange+$sMax)){
return(3);
}
}
/* the user should not be able to change is password */
if(($sLastChange >0) && ($sMin >0)){
if (($sLastChange + $sMin) >= $current){
return(4);
}
}
}
return($expired);
}
function add_lock ($object, $user)
{
global $config;
if(is_array($object)){
foreach($object as $obj){
add_lock($obj,$user);
}
return;
}
/* Just a sanity check... */
if ($object == "" || $user == ""){
msg_dialog::display(_("Internal error"), _("Error while adding a lock. Contact the developers!"), ERROR_DIALOG);
return;
}
/* Check for existing entries in lock area */
$ldap= $config->get_ldap_link();
$ldap->cd ($config->get_cfg_value("config"));
$ldap->search("(&(objectClass=gosaLockEntry)(gosaUser=$user)(gosaObject=".base64_encode($object)."))",
array("gosaUser"));
if (!$ldap->success()){
msg_dialog::display(_("Configuration error"), sprintf(_("Cannot create locking information in LDAP tree. Please contact your administrator!")."
"._('LDAP server returned: %s'), "
".$ldap->get_error().""), ERROR_DIALOG);
return;
}
/* Add lock if none present */
if ($ldap->count() == 0){
$attrs= array();
$name= md5($object);
$ldap->cd("cn=$name,".$config->get_cfg_value("config"));
$attrs["objectClass"] = "gosaLockEntry";
$attrs["gosaUser"] = $user;
$attrs["gosaObject"] = base64_encode($object);
$attrs["cn"] = "$name";
$ldap->add($attrs);
if (!$ldap->success()){
msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), "cn=$name,".$config->get_cfg_value("config"), 0, ERROR_DIALOG));
return;
}
}
}
function del_lock ($object)
{
global $config;
if(is_array($object)){
foreach($object as $obj){
del_lock($obj);
}
return;
}
/* Sanity check */
if ($object == ""){
return;
}
/* Check for existance and remove the entry */
$ldap= $config->get_ldap_link();
$ldap->cd ($config->get_cfg_value("config"));
$ldap->search ("(&(objectClass=gosaLockEntry)(gosaObject=".base64_encode($object)."))", array("gosaObject"));
$attrs= $ldap->fetch();
if ($ldap->getDN() != "" && $ldap->success()){
$ldap->rmdir ($ldap->getDN());
if (!$ldap->success()){
msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $ldap->getDN(), LDAP_DEL, ERROR_DIALOG));
return;
}
}
}
function del_user_locks($userdn)
{
global $config;
/* Get LDAP ressources */
$ldap= $config->get_ldap_link();
$ldap->cd ($config->get_cfg_value("config"));
/* Remove all objects of this user, drop errors silently in this case. */
$ldap->search("(&(objectClass=gosaLockEntry)(gosaUser=$userdn))", array("gosaUser"));
while ($attrs= $ldap->fetch()){
$ldap->rmdir($attrs['dn']);
}
}
function get_lock ($object)
{
global $config;
/* Sanity check */
if ($object == ""){
msg_dialog::display(_("Internal error"), _("Error while adding a lock. Contact the developers!"), ERROR_DIALOG);
return("");
}
/* Get LDAP link, check for presence of the lock entry */
$user= "";
$ldap= $config->get_ldap_link();
$ldap->cd ($config->get_cfg_value("config"));
$ldap->search("(&(objectClass=gosaLockEntry)(gosaObject=".base64_encode($object)."))", array("gosaUser"));
if (!$ldap->success()){
msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), "", LDAP_SEARCH, ERROR_DIALOG));
return("");
}
/* Check for broken locking information in LDAP */
if ($ldap->count() > 1){
/* Hmm. We're removing broken LDAP information here and issue a warning. */
msg_dialog::display(_("Warning"), _("Found multiple locks for object to be locked. This should not happen - cleaning up multiple references."), WARNING_DIALOG);
/* Clean up these references now... */
while ($attrs= $ldap->fetch()){
$ldap->rmdir($attrs['dn']);
}
return("");
} elseif ($ldap->count() == 1){
$attrs = $ldap->fetch();
$user= $attrs['gosaUser'][0];
}
return ($user);
}
function get_multiple_locks($objects)
{
global $config;
if(is_array($objects)){
$filter = "(&(objectClass=gosaLockEntry)(|";
foreach($objects as $obj){
$filter.="(gosaObject=".base64_encode($obj).")";
}
$filter.= "))";
}else{
$filter = "(&(objectClass=gosaLockEntry)(gosaObject=".base64_encode($objects)."))";
}
/* Get LDAP link, check for presence of the lock entry */
$user= "";
$ldap= $config->get_ldap_link();
$ldap->cd ($config->get_cfg_value("config"));
$ldap->search($filter, array("gosaUser","gosaObject"));
if (!$ldap->success()){
msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), "", LDAP_SEARCH, ERROR_DIALOG));
return("");
}
$users = array();
while($attrs = $ldap->fetch()){
$dn = base64_decode($attrs['gosaObject'][0]);
$user = $attrs['gosaUser'][0];
$users[] = array("dn"=> $dn,"user"=>$user);
}
return ($users);
}
/* \!brief This function searches the ldap database.
It search in $sub_bases,*,$base for all objects matching the $filter.
@param $filter String The ldap search filter
@param $category String The ACL category the result objects belongs
@param $sub_bases String The sub base we want to search for e.g. "ou=apps"
@param $base String The ldap base from which we start the search
@param $attributes Array The attributes we search for.
@param $flags Long A set of Flags
*/
function get_sub_list($filter, $category,$sub_deps, $base= "", $attributes= array(), $flags= GL_SUBSEARCH)
{
global $config, $ui;
$departments = array();
# $start = microtime(TRUE);
/* Get LDAP link */
$ldap= $config->get_ldap_link($flags & GL_SIZELIMIT);
/* Set search base to configured base if $base is empty */
if ($base == ""){
$base = $config->current['BASE'];
}
$ldap->cd ($base);
/* Ensure we have an array as department list */
if(is_string($sub_deps)){
$sub_deps = array($sub_deps);
}
/* Remove ,.*$ ("ou=1,ou=2.." => "ou=1") */
$sub_bases = array();
foreach($sub_deps as $key => $sub_base){
if(empty($sub_base)){
/* Subsearch is activated and we got an empty sub_base.
* (This may be the case if you have empty people/group ous).
* Fall back to old get_list().
* A log entry will be written.
*/
if($flags & GL_SUBSEARCH){
$sub_bases = array();
break;
}else{
/* Do NOT search within subtrees is requeste and the sub base is empty.
* Append all known departments that matches the base.
*/
$departments[$base] = $base;
}
}else{
$sub_bases[$key] = preg_replace("/,.*$/","",$sub_base);
}
}
/* If there is no sub_department specified, fall back to old method, get_list().
*/
if(!count($sub_bases) && !count($departments)){
/* Log this fall back, it may be an unpredicted behaviour.
*/
if(!count($sub_bases) && !count($departments)){
// log($action,$objecttype,$object,$changes_array = array(),$result = "")
new log("debug","all",__FILE__,$attributes,
sprintf("get_sub_list(): Falling back to get_list(), due to empty sub_bases parameter.".
" This may slow down GOsa. Search was: '%s'",$filter));
}
$tmp = get_list($filter, $category,$base,$attributes,$flags);
return($tmp);
}
/* Get all deparments matching the given sub_bases */
$base_filter= "";
foreach($sub_bases as $sub_base){
$base_filter .= "(".$sub_base.")";
}
$base_filter = "(&(objectClass=organizationalUnit)(|".$base_filter."))";
$ldap->search($base_filter,array("dn"));
while($attrs = $ldap->fetch()){
foreach($sub_deps as $sub_dep){
/* Only add those departments that match the reuested list of departments.
*
* e.g. sub_deps = array("ou=servers,ou=systems,");
*
* In this case we have search for "ou=servers" and we may have also fetched
* departments like this "ou=servers,ou=blafasel,..."
* Here we filter out those blafasel departments.
*/
if(preg_match("/".normalizePreg($sub_dep)."/",$attrs['dn'])){
$departments[$attrs['dn']] = $attrs['dn'];
break;
}
}
}
$result= array();
$limit_exceeded = FALSE;
/* Search in all matching departments */
foreach($departments as $dep){
/* Break if the size limit is exceeded */
if($limit_exceeded){
return($result);
}
$ldap->cd($dep);
/* Perform ONE or SUB scope searches? */
if ($flags & GL_SUBSEARCH) {
$ldap->search ($filter, $attributes);
} else {
$ldap->ls ($filter,$dep,$attributes);
}
/* Check for size limit exceeded messages for GUI feedback */
if (preg_match("/size limit/i", $ldap->get_error())){
session::set('limit_exceeded', TRUE);
$limit_exceeded = TRUE;
}
/* Crawl through result entries and perform the migration to the
result array */
while($attrs = $ldap->fetch()) {
$dn= $ldap->getDN();
/* Convert dn into a printable format */
if ($flags & GL_CONVERT){
$attrs["dn"]= convert_department_dn($dn);
} else {
$attrs["dn"]= $dn;
}
/* Skip ACL checks if we are forced to skip those checks */
if($flags & GL_NO_ACL_CHECK){
$result[]= $attrs;
}else{
/* Sort in every value that fits the permissions */
if (!is_array($category)){
$category = array($category);
}
foreach ($category as $o){
if((preg_match("/\//",$o) && preg_match("/r/",$ui->get_permissions($dn,$o))) ||
(!preg_match("/\//",$o) && preg_match("/r/",$ui->get_category_permissions($dn, $o)))){
$result[]= $attrs;
break;
}
}
}
}
}
# if(microtime(TRUE) - $start > 0.1){
# echo sprintf("
",$msg);
}else{
$msg = $dn;
}
$smarty->assign ("dn", $msg);
if ($remove){
$smarty->assign ("action", _("Continue anyway"));
} else {
$smarty->assign ("action", _("Edit anyway"));
}
$smarty->assign ("message", sprintf(_("You're going to edit the LDAP entry/entries %s"), "".$msg."", ""));
return ($smarty->fetch (get_template_path('islocked.tpl')));
}
function to_string ($value)
{
/* If this is an array, generate a text blob */
if (is_array($value)){
$ret= "";
foreach ($value as $line){
$ret.= $line." \n";
}
return ($ret);
} else {
return ($value);
}
}
function get_printer_list()
{
global $config;
$res = array();
$data = get_list('(objectClass=gotoPrinter)',"printer",$config->current['BASE'], array('cn'), GL_SUBSEARCH);
foreach($data as $attrs ){
$res[$attrs['cn'][0]] = $attrs['cn'][0];
}
return $res;
}
function rewrite($s)
{
global $REWRITE;
foreach ($REWRITE as $key => $val){
$s= preg_replace("/$key/", "$val", $s);
}
return ($s);
}
function dn2base($dn)
{
global $config;
if (get_people_ou() != ""){
$dn= preg_replace('/,'.get_people_ou().'/i' , ',', $dn);
}
if (get_groups_ou() != ""){
$dn= preg_replace('/,'.get_groups_ou().'/i' , ',', $dn);
}
$base= preg_replace ('/^[^,]+,/i', '', $dn);
return ($base);
}
function check_command($cmdline)
{
$cmd= preg_replace("/ .*$/", "", $cmdline);
/* Check if command exists in filesystem */
if (!file_exists($cmd)){
return (FALSE);
}
/* Check if command is executable */
if (!is_executable($cmd)){
return (FALSE);
}
return (TRUE);
}
function print_header($image, $headline, $info= "")
{
$display= "
\n";
$display.= "
$headline
\n";
$display.= "
\n";
if ($info != ""){
$display.= "
\n";
$display.= "$info";
$display.= "
\n";
} else {
$display.= "
\n";
$display.= " ";
$display.= "
\n";
}
return ($display);
}
function range_selector($dcnt,$start,$range=25,$post_var=false)
{
/* Entries shown left and right from the selected entry */
$max_entries= 10;
/* Initialize and take care that max_entries is even */
$output="";
if ($max_entries & 1){
$max_entries++;
}
if((!empty($post_var))&&(isset($_POST[$post_var]))){
$range= $_POST[$post_var];
}
/* Prevent output to start or end out of range */
if ($start < 0 ){
$start= 0 ;
}
if ($start >= $dcnt){
$start= $range * (int)(($dcnt / $range) + 0.5);
}
$numpages= (($dcnt / $range));
if(((int)($numpages))!=($numpages)){
$numpages = (int)$numpages + 1;
}
if ((((int)$numpages) <= 1 )&&(!$post_var)){
return ("");
}
$ppage= (int)(($start / $range) + 0.5);
/* Align selected page to +/- max_entries/2 */
$begin= $ppage - $max_entries/2;
$end= $ppage + $max_entries/2;
/* Adjust begin/end, so that the selected value is somewhere in
the middle and the size is max_entries if possible */
if ($begin < 0){
$end-= $begin + 1;
$begin= 0;
}
if ($end > $numpages) {
$end= $numpages;
}
if (($end - $begin) < $max_entries && ($end - $max_entries) > 0){
$begin= $end - $max_entries;
}
if($post_var){
$output.= "