---
title: "Titel-Sortierung von sp_directory ändern"
url: "https://www.typo3.net/d/32766-titel-sortierung-von-sp-directory-aendern"
source: "typo3.net"
tags: ["Extensions","Datenbank","Frage","PHP"]
created: "2005-11-04"
last_reply: "2005-11-20"
replies: 5
solved: false
page: 1
pages: 1
lang: "de"
---

# Titel-Sortierung von sp_directory ändern

Extensions · 5 Antworten · gestartet 2005-11-04

## Eröffnungsbeitrag

**Schlingel** · 2005-11-04 · [Beitrag #1](https://www.typo3.net/d/32766-titel-sortierung-von-sp-directory-aendern/1)

Hallo zusammen,

ich habe auf der Seite <http://www.bmw-club.de/index.php?id=10> ein sp_directory laufen, normalerweise werden ja in der Titelleiste oben die A,B,C,... links so erzeugt, in dem geschaut wird ob z.b. ein Eintrag mit Namen D vorhanden ist, wenn ja wird der Link erzeugt.
Nun sind das alle BMW Clubs und die fangen halt mit B wie BMW an => nur einträge bei B...
Nun hätte ich gerne, dass diese Links nicht nach dem Namen selektieren, sondern nach dem Ort.
Das die Links entsprechend zu Links werden hab ich hinbekommen (hier wird nun ganz toll je nachdem obs einen Club im Ort A* gibt, A verlinkt). Allerdings scheint die Datenbank Abfrage dahinter nichtmehr nach dem Ort sondern wieder nach dem Namen zu Sortieren.

Meine PHP Kenntnisse sind jetzt nicht so schlecht, aber bei der pi1/class.tx_spdirectory_pi1.php-Datei muss ich irgendwann echt passen...

Vielleicht weiss ja jemand eine Lösung, ich bin ratlos.

Hier die (meiner Meinung nach richtige) Datei:

```php
<?php
/** 
 * Plugin 'Address Directory' for the 'sp_directory' extension.
 *
 * @author	Carsten Horst <carsten@sprog.de>
 */
 
require_once(PATH_tslib."class.tslib_pibase.php");
require_once(PATH_t3lib."class.t3lib_basicfilefunc.php");

class tx_spdirectory_pi1 extends tslib_pibase {

	var $prefixId = "tx_spdirectory_pi1";		// Same as class name
	var $scriptRelPath = "pi1/class.tx_spdirectory_pi1.php";	// Path to this script relative to the extension dir.
	var $extKey = "sp_directory";	// The extension key.
	

	/**
	 * Doing the things...
	 */
	function main($content,$conf)	{
		$this->conf=$conf;
		$this->pi_setPiVarDefaults();
		$this->pi_loadLL();


#t3lib_div::debug(($GLOBALS["TYPO_VERSION"] >= '3.6.0'));
		//Default-Values
		$this->internal[currentTable] = tt_address;
		//delete sword
		$this->piVars[sword] = ($this->piVars[modifier]!=search) ? "" : $sword;

		// pid_list is the pid/list of pids from where to fetch the tt_address items.
		if (strstr($this->cObj->currentRecord,"tt_content")) {
			$this->conf["pidList"] = $this->cObj->data["pages"];
        	        $this->conf["recursive"] = $this->cObj->data["recursive"];
		}

		//prepare TypoLinks
		$this->typolink_conf = $this->conf["typolink."];
		$this->typolink_conf["useCacheHash"] = 1;		

		//Should fields be hidden?
		t3lib_div::inList($GLOBALS['TSFE']->fe_user->user['usergroup'],$this->conf["hidden_fields_fegroup"] || $this->conf["hidden_fields_fegroup"]="") ? $this->conf["hide_field"] = 0 : $this->conf["hide_field"] = 1; 
		$this->conf["hidden_fields"] = strtolower($this->conf["hidden_fields"]);
		
		//parese template
		$this->listTemplateCode = $this->cObj->fileResource($this->conf["templateFile"]);
		$this->top = $this->cObj->getSubpart($this->listTemplateCode, "###TOPVIEW###");
		$this->bottom = $this->cObj->getSubpart($this->listTemplateCode, "###BOTTOMVIEW###");
		$this->listIentry = $this->cObj->getSubpart($this->listTemplateCode, "###LISTIVIEW###");
		$this->listIIentry = $this->cObj->getSubpart($this->listTemplateCode, "###LISTIIVIEW###");
		$this->listIIIentry = $this->cObj->getSubpart($this->listTemplateCode, "###LISTIIIVIEW###");
		$this->searchElement = $this->cObj->getSubpart($this->listTemplateCode, "###SEARCHELEMENT###");
		$this->nono = $this->cObj->getSubpart($this->listTemplateCode, "###NOVIEW###");
		$this->detail = $this->cObj->getSubpart($this->listTemplateCode, "###SINGLEVIEW###");

		switch($this->piVars[mode])	{
			
			case "detail":		
				$content = $this->makeDetail($this->piVars[value]);
				$content .= $this->makeEditLink(edit,$this->piVars[value]);
			break;
			case "enter":
				$content = $this->makeForm(enter,$this->piVars[modifier]);
			break;
			case "edit":
				$content = $this->makeForm(edit,$this->piVars[modifier],$this->piVars[value]);
			break;
			default: //"list" 
				$displaybottom = true;
				$tmpcontent = $content;
				$content .= $this->makeTop();
				switch($this->piVars[modifier])	{
					case "zip":
						$content .= $this->makelist(zip,$this->piVars[value]);
					break;
					case "search":
						$this->piVars[sword] = $this->piVars[value]; 
						$content .= $this->makelist(search,$this->piVars[value]);					
					break;
					case "cat":
						$content .= $this->makelist(cat,$this->piVars[value]);
					break;
					default: //"abc"
						switch($this->piVars[value])	{
							case "":
							case "all":
                                                                switch($this->cObj->data["tx_spdirectory_mode"])        {
                                                                        case "0":
                                                                                $content .= $this->makelist(abc,all);
                                                                        break;
                                                                        case "1":
                                                                                $content .= $this->makelist(catorder,all);
                                                                        break;
                                                                        case "2":
                                                                                $content .= $this->makelist(ziporder,all);
                                                                        break;
                                                                        case "3":
                                                                                $content = $tmpcontent;
                                                                                $tmpcontent = "";
                                                                                $content .= $this->makeSearchelement();
                                                                                $displaybottom = false;
                                                                        break;
                                                                }
							break;
							default:
								$content .= $this->makelist(abc,$this->piVars[value],$this->piVars[pointer]);
							break;
						}
					break;
				}
				
				if ($displaybottom) {
					$content .= $this->makeBottom($this->piVars[modifier],$this->piVars[value]);
					$content .= $this->makeEditLink(enter);
				}
				
			break;		
			
		}
		
	return $this->pi_wrapInBaseClass($content);	
	}

	/**
         * Create the edit Link, when an authorized User is logged in
         */
	function makeEditLink($action,$id="")	{

		switch($action)	{
		
			case "enter":
				$content = ($GLOBALS['TSFE']->fe_user->user['usergroup'] && $this->conf["default_fegroup"]) ? '<table cellpadding="7" cellspacing="0" border="0" width="100%"><tr><td align="right">'.$this->makeLink($this->pi_getLL("new_entry"),enter,"","","0").'</td></tr></table>' : "";
			break;
			case "edit":
				$content = ($this->checkAccess($id)) ? '<table cellpadding="7" cellspacing="0" border="0" width="100%"><tr><td align="right">'.$this->makeLink($this->pi_getLL("edit_entry"),edit,"first",$id,"0").'</td></tr></table>' : "";
			break;
		}
	return $content;
	}

	/**
         * Make the detail page
         */
	function makeDetail($id)	{

		$pidList = $this->pi_getPidList($this->conf["pidList"],$this->conf["recursive"]);
		$query = "SELECT * FROM tt_address WHERE pid IN (".$pidList.")"." ".$this->cObj->enableFields(tt_address)." AND uid = ".$id;
		$res = mysql(TYPO3_db,$query);
		$row = mysql_fetch_assoc($res);
			
		$markerArray["###NAME###"] = $this->cObj->stdWrap(htmlentities($row[name]),$this->conf["DetailName."]);
		$markerArray["###DESCRIPTION###"] = ($this->conf["hide_field"] && t3lib_div::inList($this->conf["hidden_fields"],"description")) ? "" : $this->cObj->stdWrap(nl2br(htmlentities($row[description])),$this->conf["DetailDescr."]);
		$markerArray["###STREET###"] = ($this->conf["hide_field"] && t3lib_div::inList($this->conf["hidden_fields"],"street")) ? "" : $this->cObj->stdWrap(nl2br(htmlentities($row[address])),$this->conf["DetailStreet."]);
		$markerArray["###ZIP###"] = ($this->conf["hide_field"] && t3lib_div::inList($this->conf["hidden_fields"],"zip")) ? "" : $this->cObj->stdWrap(htmlentities($row[zip]),$this->conf["DetailZip."]);
		$markerArray["###CITY###"] = ($this->conf["hide_field"] && t3lib_div::inList($this->conf["hidden_fields"],"city")) ? "" : $this->cObj->stdWrap(htmlentities($row[city]),$this->conf["DetailCity."]);
		$markerArray["###PHONE###"] = ($this->conf["hide_field"] && t3lib_div::inList($this->conf["hidden_fields"],"phone")) ? "" : (($row[phone]) ? $this->cObj->stdWrap($this->pi_getLL("phone").": ".$row[phone],$this->conf["DetailPhone."]) : "");
		$markerArray["###MOBILE###"] = ($this->conf["hide_field"] && t3lib_div::inList($this->conf["hidden_fields"],"mobile")) ? "" : (($row[mobile]) ? $this->cObj->stdWrap($this->pi_getLL("mobile").": ".$row[mobile],$this->conf["DetailMobile."]) : "");
		$markerArray["###FAX###"] = ($this->conf["hide_field"] && t3lib_div::inList($this->conf["hidden_fields"],"fax")) ? "" : (($row[fax]) ? $this->cObj->stdWrap($this->pi_getLL("fax").": ".$row[fax],$this->conf["DetailFax."]) : "");
		$markerArray["###WWW###"] = ($this->conf["hide_field"] && t3lib_div::inList($this->conf["hidden_fields"],"www")) ? "" : (($row[www]) ? $this->makeHTTPLink($row[www],$this->pi_getLL("www")) : '<font color="'.$this-">conf[inactive].'">WWW</font>');
		$markerArray["###EMAIL###"] = ($this->conf["hide_field"] && t3lib_div::inList($this->conf["hidden_fields"],"email")) ? "" : (($row[email]) ? $this->makeMailtoLink($row[email]) : '<font color="'.$this-">conf[inactive].'">E-Mail</font>');
		$markerArray["###DROPDOWN###"] = $this->makeDropDownList($id,$row[pid],$row[zip]);			
		//insert picture
		$markerArray["###IMAGE###"] = ($this->conf["hide_field"] && t3lib_div::inList($this->conf["hidden_fields"],"image")) ? "" : (($row[image]) ? $this->getImage($row[image],$this->conf) : "");
		$over[detail]="";
		$markerArray["###BACK###"] = '<a href="javascript:history.back(1)">'.$this->pi_getLL("back").'</a>';
		$content= $this->cObj->substituteMarkerArrayCached($this->detail,$markerArray,array(),array());	

	return $content;
	}
	
	
	function makeTop()	{
	
		$markerArray["###ATOZ###"] = $this->makeABC('tt_address','city',$this->piVars[value]);
		$markerArray["###CATEGORY###"] = $this->makeJumper($this->piVars[modifier],$this->piVars[value]); 
		$markerArray["###ZIP###"] = $this->makeZIP($this->piVars[modifier],$this->piVars[value]); 
		$markerArray["###SEARCH###"] = $this->makeSearchbox($this->piVars[value]);
		$content = $this->cObj->substituteMarkerArrayCached($this->top,$markerArray,array(),array());
		
	return $content;
	}

	function makeSearchelement()	{

                $markerArray["###CATEGORY###"] = $this->makeJumper($this->piVars[modifier],$this->piVars[value]);
                $markerArray["###ZIP###"] = $this->makeZIP($this->piVars[modifier],$this->piVars[value]);
                $markerArray["###SEARCH###"] = $this->makeSearchbox($this->piVars[value]);
                $content = $this->cObj->substituteMarkerArrayCached($this->searchElement,$markerArray,array(),array());

        return $content;
        }

	function makeDropDownList($id,$pid,$zip) {

		$pidList = $this->pi_getPidList($this->conf["pidList"],$this->conf["recursive"]);
		if ($this->conf["displayDropDownAll"]) {
			$query = "SELECT name,uid FROM tt_address WHERE pid IN (".$pidList.")"." ".$this->cObj->enableFields(tt_address)." ORDER BY NAME";
		} else {
			$pidList = ($this->cObj->data["tx_spdirectory_dspfolder"]) ? $pid : $pidList;
			switch($this->cObj->data["tx_spdirectory_mode"])        {
				case "0":
					$query = "SELECT name,uid FROM tt_address WHERE pid IN (".$pidList.")"." ".$this->cObj->enableFields(tt_address)." ORDER BY NAME";
				break;
                        	case "1":
					$q = "SELECT uid_foreign FROM tx_spdirectory_cat_mm WHERE uid_local='".$id."'";
                                        $r = $res = mysql(TYPO3_db,$q);
                                        while ($ro = mysql_fetch_assoc($r)) {
                                                $cat[] = $ro[uid_foreign];
                                        }
                                        $catList = implode(',', $cat);
					$query = "SELECT DISTINCT tt_address.name,tt_address.uid FROM tt_address,tx_spdirectory_cat_mm WHERE tt_address.uid=tx_spdirectory_cat_mm.uid_local AND tx_spdirectory_cat_mm.uid_foreign IN (".$catList.") AND tt_address.pid IN (".$pidList.")"." ".$this->cObj->enableFields(tt_address)." ORDER BY NAME";
				break;
                	        case "2":
					$query = "SELECT name,uid,zip FROM tt_address WHERE pid IN (".$pidList.")"." ".$this->cObj->enableFields(tt_address)." AND zip='".$zip."' ORDER BY NAME";
				break;
			}
		}
		$res = mysql(TYPO3_db,$query);
		
		$content = "
		<script language="\" javascript="" type="\" textjavascript="">
                <!--
                function MM_jumpMenu(targ,selObj,restore){
	                eval(targ+\".location='\"+selObj.options[selObj.selectedIndex].value+\"'\");
        	        if (restore) selObj.selectedIndex=0;
                }
                //-->
                </script>";

		$content .= '<select name="menu2" size="1" onchange="MM_jumpMenu(\'self\',this,0)" class="tx_spdirectory-pi1-small">';
		while($row = mysql_fetch_assoc($res)) {
			$content .= '<option value="'.$this-">makeLink("",detail,"",$row[uid],$cache=1,$pointer=0).'"';
			$content .= ($id == $row[uid]) ? ' selected style="color: '.$this->conf[active].';">' : '>';
			$content .= htmlentities($row[name]).'</option>';
		}
		$content .= '</select>';

	return $content;
	}
	
	function makelist($modifier,$value)	{

		$query = $this->makeListQuery($modifier,$value);
		$res=mysql(TYPO3_db,$query);
		$lastsys = "";
		$splitMark = md5(microtime());

		switch($modifier)	{

                        case "catorder":
                                $lastcat = "";
                                while($row = mysql_fetch_assoc($res))   {

					if (($lastsys == $row[title]) || !$this->cObj->data["tx_spdirectory_dspfolder"]) {
						$markerArray["###SYSFOLDER###"] = "";
						$markerArray["###W1B###"] = "";
						$markerArray["###W1E###"] = "";
					} else {
						list($markerArray["###W1B###"],$markerArray["###W1E###"]) = explode($splitMark,$this->cObj->stdWrap($splitMark,$this->conf["wrap1."]));
						$markerArray["###SYSFOLDER###"] = htmlentities($row[title]);
						$lastsys = $row[title];
						$lastcat = "";
					}
                                        if ($lastcat == $row[catname]) {
                                                $markerArray["###CATEGORY###"] = "";
						$markerArray["###W2B###"] = "";
                                                $markerArray["###W2E###"] = "";
                                        } else {
						list($markerArray["###W2B###"],$markerArray["###W2E###"]) = explode($splitMark,$this->cObj->stdWrap($splitMark,$this->conf["wrap2."]));
                                                $markerArray["###CATEGORY###"] = htmlentities($row[catname]);
                                                $lastcat = $row[catname];
                                        }
					$over[detail]=$row[uid];
					$markerArray["###NAME###"] = $this->cObj->stdWrap(($this->conf["displayNameLink"]) ? $this->makeLink(htmlentities($row[name]),detail,$modifier,$row[uid],1,$pointer) : htmlentities($row[name]),$this->conf["ListName."]);
                                        $markerArray["###STREET###"] = ($this->conf["hide_field"] && t3lib_div::inList($this->conf["hidden_fields"],strtolower("street"))) ? "" : $this->cObj->stdWrap(htmlentities($row[address]),$this->conf["ListStreet."]);
                                        $markerArray["###ZIP###"] = ($this->conf["hide_field"] && t3lib_div::inList($this->conf["hidden_fields"],"zip")) ? "" : $this->cObj->stdWrap(htmlentities($row[zip]),$this->conf["ListZip."]);
                                        $markerArray["###CITY###"] = ($this->conf["hide_field"] && t3lib_div::inList($this->conf["hidden_fields"],"city")) ? "" : $this->cObj->stdWrap(htmlentities($row[city]),$this->conf["ListCity."]);
                                        $markerArray["###PHONE###"] = ($this->conf["hide_field"] && t3lib_div::inList($this->conf["hidden_fields"],"phone")) ? "" : (($row[phone]) ? $this->cObj->stdWrap($this->pi_getLL("phone").": ".$row[phone],$this->conf["ListPhone."]) : "");
                                        $markerArray["###MOBILE###"] = ($this->conf["hide_field"] && t3lib_div::inList($this->conf["hidden_fields"],"mobile")) ? "" : (($row[mobile]) ? $this->cObj->stdWrap($this->pi_getLL("mobile").": ".$row[mobile],$this->conf["ListMobile."]) : "");
                                        $markerArray["###FAX###"] = ($this->conf["hide_field"] && t3lib_div::inList($this->conf["hidden_fields"],"fax")) ? "" : (($row[fax]) ? $this->cObj->stdWrap($this->pi_getLL("fax").": ".$row[fax],$this->conf["ListFax."]) : "");
					$markerArray["###WWW###"] = ($this->conf["hide_field"] && t3lib_div::inList($this->conf["hidden_fields"],"www")) ? "" : (($row[www]) ? $this->makeHTTPLink($row[www],$this->pi_getLL("www")) : '<font color="'.$this-">conf[inactive].'">WWW</font>');
                                        $markerArray["###EMAIL###"] = ($this->conf["hide_field"] && t3lib_div::inList($this->conf["hidden_fields"],"email")) ? "" : (($row[email]) ? $this->makeMailtoLink($row[email]) : '<font color="'.$this-">conf[inactive].'">E-Mail</font>');
                                        $markerArray["###IMAGE###"] = ($this->conf["hide_field"] && t3lib_div::inList($this->conf["hidden_fields"],"image")) ? "" : (($row[image]) ? $this->getImage($row[image],$this->conf) : "");
                                        $markerArray["###DETAILS###"] = $this->makeLink($this->pi_getLL("details"),detail,$modifier,$row[uid],1,$pointer);
                                        $wieviele=1;
                                        $content .= $this->cObj->substituteMarkerArrayCached($this->listIIentry,$markerArray,array(),array());
                                }
                        break;


			case "ziporder":
				$lastzip = "";
				while($row = mysql_fetch_assoc($res))   {
					if (($lastsys == $row[title]) || !$this->cObj->data["tx_spdirectory_dspfolder"]) {
                                                $markerArray["###SYSFOLDER###"] = "";
						$markerArray["###W1B###"] = "";
                                                $markerArray["###W1E###"] = "";
                                        } else {
						list($markerArray["###W1B###"],$markerArray["###W1E###"]) = explode($splitMark,$this->cObj->stdWrap($splitMark,$this->conf["wrap1."]));
                                                $markerArray["###SYSFOLDER###"] = htmlentities($row[title]);
                                                $lastsys = $row[title];
						$lastzip = "";
                                        }
					if ($lastzip == $row[zip]) {
						$markerArray["###ZIPCAT###"] = "";
						$markerArray["###CITYCAT###"] = "";
						$markerArray["###W3B###"] = "";
                                                $markerArray["###W3E###"] = "";
					} else {
						list($markerArray["###W3B###"],$markerArray["###W3E###"]) = explode($splitMark,$this->cObj->stdWrap($splitMark,$this->conf["wrap3."]));
						$markerArray["###ZIPCAT###"] = htmlentities($row[zip]);
						$markerArray["###CITYCAT###"] = htmlentities($row[city]);
						$lastzip = $row[zip];
					}
$over[detail]=$row[uid];
                                        $markerArray["###NAME###"] = $this->cObj->stdWrap(($this->conf["displayNameLink"]) ? $this->makeLink(htmlentities($row[name]),detail,$modifier,$row[uid],1,$pointer) : htmlentities($row[name]),$this->conf["ListName."]);
                                        $markerArray["###STREET###"] = ($this->conf["hide_field"] && t3lib_div::inList($this->conf["hidden_fields"],"street")) ? "" : $this->cObj->stdWrap(htmlentities($row[address]),$this->conf["ListStreet."]);
                                        $markerArray["###ZIP###"] = ($this->conf["hide_field"] && t3lib_div::inList($this->conf["hidden_fields"],"zip")) ? "" : $this->cObj->stdWrap(htmlentities($row[zip]),$this->conf["ListZip."]);
                                        $markerArray["###CITY###"] = ($this->conf["hide_field"] && t3lib_div::inList($this->conf["hidden_fields"],"city")) ? "" : $this->cObj->stdWrap(htmlentities($row[city]),$this->conf["ListCity."]);
                                        $markerArray["###PHONE###"] = ($this->conf["hide_field"] && t3lib_div::inList($this->conf["hidden_fields"],"phone")) ? "" : (($row[phone]) ? $this->cObj->stdWrap($this->pi_getLL("phone").": ".$row[phone],$this->conf["ListPhone."]) : "");
                                        $markerArray["###MOBILE###"] = ($this->conf["hide_field"] && t3lib_div::inList($this->conf["hidden_fields"],"mobile")) ? "" : (($row[mobile]) ? $this->cObj->stdWrap($this->pi_getLL("mobile").": ".$row[mobile],$this->conf["ListMobile."]) : "");
                                        $markerArray["###FAX###"] = ($this->conf["hide_field"] && t3lib_div::inList($this->conf["hidden_fields"],"fax")) ? "" : (($row[fax]) ? $this->cObj->stdWrap($this->pi_getLL("fax").": ".$row[fax],$this->conf["ListFax."]) : ""); 
                                        $markerArray["###WWW###"] = ($this->conf["hide_field"] && t3lib_div::inList($this->conf["hidden_fields"],"www")) ? "" : (($row[www]) ? $this->makeHTTPLink($row[www],$this->pi_getLL("www")) : '<font color="'.$this-">conf[inactive].'">WWW</font>');
                                        $markerArray["###EMAIL###"] = ($this->conf["hide_field"] && t3lib_div::inList($this->conf["hidden_fields"],"email")) ? "" : (($row[email]) ? $this->makeMailtoLink($row[email]) : '<font color="'.$this-">conf[inactive].'">E-Mail</font>');
                                        $markerArray["###IMAGE###"] = ($this->conf["hide_field"] && t3lib_div::inList($this->conf["hidden_fields"],"image")) ? "" : (($row[image]) ? $this->getImage($row[image],$this->conf) : "");
                                        $markerArray["###DETAILS###"] = $this->makeLink($this->pi_getLL("details"),detail,$modifier,$row[uid],1,$pointer);
                                        $wieviele=1;
					$content .= $this->cObj->substituteMarkerArrayCached($this->listIIIentry,$markerArray,array(),array());
				}
			break;

			default:						
				while($row = mysql_fetch_assoc($res))	{
					if (($lastsys == $row[title]) || !$this->cObj->data["tx_spdirectory_dspfolder"]) {
                                                $markerArray["###SYSFOLDER###"] = "";
						$markerArray["###W1B###"] = "";
                                                $markerArray["###W1E###"] = "";
                                        } else {
						list($markerArray["###W1B###"],$markerArray["###W1E###"]) = explode($splitMark,$this->cObj->stdWrap($splitMark,$this->conf["wrap1."]));
                                                $markerArray["###SYSFOLDER###"] = htmlentities($row[title]);
                                                $lastsys = $row[title];
                                        }

					$over[detail]=$row[uid];
					$markerArray["###NAME###"] = $this->cObj->stdWrap(($this->conf["displayNameLink"]) ? $this->makeLink(htmlentities($row[name]),detail,$modifier,$row[uid],1,$pointer) : htmlentities($row[name]),$this->conf["ListName."]);
					$markerArray["###STREET###"] = ($this->conf["hide_field"] && t3lib_div::inList($this->conf["hidden_fields"],"street")) ? "" : $this->cObj->stdWrap(htmlentities($row[address]),$this->conf["ListStreet."]);
					$markerArray["###ZIP###"] = ($this->conf["hide_field"] && t3lib_div::inList($this->conf["hidden_fields"],"zip")) ? "" : $this->cObj->stdWrap(htmlentities($row[zip]),$this->conf["ListZip."]);
					$markerArray["###CITY###"] = ($this->conf["hide_field"] && t3lib_div::inList($this->conf["hidden_fields"],"city")) ? "" : $this->cObj->stdWrap(htmlentities($row[city]),$this->conf["ListCity."]);
					$markerArray["###PHONE###"] = ($this->conf["hide_field"] && t3lib_div::inList($this->conf["hidden_fields"],"phone")) ? "" : (($row[phone]) ? $this->cObj->stdWrap($this->pi_getLL("phone").": ".$row[phone],$this->conf["ListPhone."]) : "");
					$markerArray["###MOBILE###"] = ($this->conf["hide_field"] && t3lib_div::inList($this->conf["hidden_fields"],"mobile")) ? "" : (($row[mobile]) ? $this->cObj->stdWrap($this->pi_getLL("mobile").": ".$row[mobile],$this->conf["ListMobile."]) : "");
					$markerArray["###FAX###"] = ($this->conf["hide_field"] && t3lib_div::inList($this->conf["hidden_fields"],"fax")) ? "" : (($row[fax]) ? $this->cObj->stdWrap($this->pi_getLL("fax").": ".$row[fax],$this->conf["ListFax."]) : "");		
					$markerArray["###WWW###"] = ($this->conf["hide_field"] && t3lib_div::inList($this->conf["hidden_fields"],"www")) ? "" : (($row[www]) ? $this->makeHTTPLink($row[www],$this->pi_getLL("www")) : '<font color="'.$this-">conf[inactive].'">WWW</font>');
					$markerArray["###EMAIL###"] = ($this->conf["hide_field"] && t3lib_div::inList($this->conf["hidden_fields"],"email")) ? "" : (($row[email]) ? $this->makeMailtoLink($row[email]) : '<font color="'.$this-">conf[inactive].'">E-Mail</font>');
					$markerArray["###IMAGE###"] = ($this->conf["hide_field"] && t3lib_div::inList($this->conf["hidden_fields"],"image")) ? "" : (($row[image]) ? $this->getImage($row[image],$this->conf) : "");
					$markerArray["###DETAILS###"] = $this->makeLink($this->pi_getLL("details"),detail,$modifier,$row[uid],1,$pointer);
					$content .= $this->cObj->substituteMarkerArrayCached($this->listIentry,$markerArray,array(),array());
					$wieviele=1;
				}
					$markerArray["###SORRY###"] = $this->pi_getLL("sorry");
				$content = ($wieviele) ? $content : $this->cObj->substituteMarkerArrayCached($this->nono,$markerArray,array(),array());
			break;
		}
           
	return $content;
	}
	
	function makeBottom($modifier,$value)	{
	
		$markerArray["###PAGES###"] = $this->make123($modifier,$value);
		$content = $this->cObj->substituteMarkerArrayCached($this->bottom,$markerArray,array(),array());
		
	return $content;
	}


	
	
	/**
	 * Erzeugen der Buchstabenleiste in Abhängigkeit von den vorkommenden Buchstaben, 
	 * des aktuellen Buchstabens und des Anzeigemodus (Normal, Suche, Kategorie)
	 */
	function makeABC($table,$column,$value)	{
		$alphabet=array(A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z);
		$value == (in_array($value,$alphabet)) ? "all" : $value;

		$pidlist = $this->pi_getPidlist($this->conf["pidList"],$this->conf["recursive"]);

		$query="SELECT ".$column." FROM ".$table." WHERE pid IN (".$pidlist.")"." ".$this->cObj->enableFields($table);

		$res = mysql(TYPO3_db,$query);
		
		while($tempo = mysql_fetch_assoc($res))	{
			$atoz[]=str_replace (array("Ä", "Ö", "Ü"), array("A", "O", "U"), strtoupper($tempo[$column]{0}));
		}
		$atoz[none]=1;


		
		for($i=0;$i<sizeof($alphabet);$i++)	{

			if(in_array($alphabet[$i],$atoz))	{
				$atozlist .= ($value==$alphabet[$i]) ? '<font color="'.$this-">conf[active].'">'.$alphabet[$i].'</font>'.' ' : $this->makeLink($alphabet[$i],liste,abc,$alphabet[$i]).' ';
			}
			else	{
				$atozlist .= '<font color="'.$this-">conf[inactive].'">'.$alphabet[$i].'</font>'.' ';
			}
		}
		$atozlist .= ($value==all) ? '<font color="'.$this-">conf[active].'">'.$this->pi_getLL("all").'</font>' : $this->makeLink($this->pi_getLL("all"),liste,abc,all);

	return $atozlist;
	}

	
	
	function makeLink($string,$mode,$modifier,$value="",$cache=1,$pointer=0)	{
		
		$over = array(mode => $mode, modifier => $modifier, value => $value, pointer => $pointer);
		$link = ($string) ?	$this->pi_linkTP_keepPIvars($string,$over,$cache) : $link = $this->pi_linkTP_keepPIvars_url($over,$cache);	

	return $link;
	}
	
	
	
	/**
	 * Erzeugen der Seitenleiste in Abhängigkeit von aktueller Seite und zu übergebender Variable
	 */	
	
	function make123($modifier,$value)	{

		$query = $this->makeListQuery($modifier,$value,1);
		$res = mysql(TYPO3_db,$query);
		$rescount = mysql_fetch_row($res);
		$pages=ceil($rescount[0]/$this->conf["itemsPerPage"]);
	
			$pagelist = $this->pi_getLL("page");;
			for($i=0;$i<$pages;$i++)	{
				$j=$i+1;
				$pagelist .= ($this->piVars[pointer]==$i) ? ' <font color="'.$this-">conf[active].'">'.$j.'</font>' : ' '.$this->makeLink($j,liste,$modifier,$value,1,$i);
 			}
		

	return $pagelist;
	}
	
	/**
	 * Erzeugen der Query
	 */		
	function makeListQuery($modifier,$value,$count=0)	{
		$this->internal["orderBy"] = "name";
		$this->internal["orderByList"] = "name";
		$this->internal["searchFieldList"]="name, description, address, city, www";
		$this->internal["results_at_a_time"] = $this->conf["itemsPerPage"];
		$value = mysql_escape_string($value);
		$select = '';

		switch($modifier)	{

			case "search":
				$this->internal["searchFieldlist"]="name, description, address, city, www";
				$this->piVars[sword]=$value;
				
			break;
			
			case "cat":
				$this->piVars[sword]="";
				$addWhere = 'AND tx_spdirectory_cat.uid = '.$value;	
				$mmcat["table"] = 'tx_spdirectory_cat';
                                $mmcat["mmtable"] = 'tx_spdirectory_cat_mm';
			break;
			
			case "zip":
				$this->piVars[sword]="";
				$addWhere = "AND tt_address.zip = '".$value."'";	
			break;

			case "abc":
				$mychar=str_replace(array("A", "O", "U"), array("AÄ1234567890", "OÖ", "UÜ"),$value);
				$mychar=$mychar.strtolower($mychar);
				$addWhere = ($value!=all) ? 'AND tt_address.name REGEXP "^['.$mychar.']"' : "";		
				if ($this->cObj->data["tx_spdirectory_dspfolder"] && !$count) {
					$select = ",pages.title";
					$addQuery = "FROM tt_address,pages WHERE tt_address.pid IN (".$this->pi_getPidList($this->conf['pidList'],$this->conf['recursive']).") AND tt_address.pid=pages.uid AND pages.uid IN (".$this->pi_getPidList($this->conf['pidList'],$this->conf['recursive']).") ".$this->cObj->enableFields(tt_address);
					$orderby = "ORDER BY pages.title, tt_address.name";
				}
			break;
		
			case "catorder":
				$mychar=str_replace(array("A", "O", "U"), array("AÄ1234567890", "OÖ", "UÜ"),$value);
                                $mychar=$mychar.strtolower($mychar);
                                $addWhere = ($value!=all) ? 'AND tt_address.name REGEXP "^['.$mychar.']"' : "";
				if ($this->cObj->data["tx_spdirectory_dspfolder"] && !$count) {
					$orderby = "ORDER BY pages.title,tx_spdirectory_cat.catname,tt_address.name";
					$select = ",pages.title,tx_spdirectory_cat.catname";
					$addQuery ="FROM tt_address,pages,tx_spdirectory_cat,tx_spdirectory_cat_mm WHERE tt_address.uid=tx_spdirectory_cat_mm.uid_local AND tx_spdirectory_cat.uid=tx_spdirectory_cat_mm.uid_foreign AND tt_address.pid IN (".$this->pi_getPidList($this->conf['pidList'],$this->conf['recursive']).") AND tt_address.pid=pages.uid AND pages.uid IN (".$this->pi_getPidList($this->conf['pidList'],$this->conf['recursive']).") ".$this->cObj->enableFields(tt_address);
				} else {
					$orderby = "ORDER BY tx_spdirectory_cat.catname,tt_address.name";
					$select = ",tx_spdirectory_cat.catname";
                                        $addQuery ="FROM tt_address,tx_spdirectory_cat,tx_spdirectory_cat_mm WHERE tt_address.uid=tx_spdirectory_cat_mm.uid_local AND tx_spdirectory_cat.uid=tx_spdirectory_cat_mm.uid_foreign AND tt_address.pid IN (".$this->pi_getPidList($this->conf['pidList'],$this->conf['recursive']).") ".$this->cObj->enableFields(tt_address);
				}
                        break;

			case "ziporder":
				$mychar=str_replace(array("A", "O", "U"), array("AÄ1234567890", "OÖ", "UÜ"),$value);
				$mychar=$mychar.strtolower($mychar);
                                $addWhere = ($value!=all) ? 'AND tt_address.name REGEXP "^['.$mychar.']"' : "";
				if ($this->cObj->data["tx_spdirectory_dspfolder"] && !$count) {
	                                $orderby = "ORDER BY pages.title,tt_address.zip,tt_address.name";
					$select = ",pages.title";
					$addQuery = "FROM tt_address,pages WHERE tt_address.pid IN (".$this->pi_getPidList($this->conf['pidList'],$this->conf['recursive']).") AND tt_address.pid=pages.uid AND pages.uid IN (".$this->pi_getPidList($this->conf['pidList'],$this->conf['recursive']).") ".$this->cObj->enableFields(tt_address);
				} else {
					$orderby = "ORDER BY tt_address.zip,tt_address.name";
				}
                        break;
		
		}
		
		if ($GLOBALS["TYPO_VERSION"] >= '3.6.0') {
			$queryArr=$this->pi_list_query($this->internal[currentTable],$count,$addWhere,$mmcat,"",$orderby,$addQuery,TRUE);
			$query = 'SELECT '.$queryArr[SELECT].$select;
			$query .= ' FROM '.$queryArr[FROM];
			$query .= ($queryArr[WHERE]) ? ' WHERE '.$queryArr[WHERE] : '';
			$query .= ($queryArr[GROUPBY]) ? ' GROUP BY '.$queryArr[GROUPBY] : '';
			$query .= ($queryArr[ORDERBY]) ? ' ORDER BY '.$queryArr[ORDERBY] : '';
			$query .= ($queryArr[LIMIT]) ? ' LIMIT '.$queryArr[LIMIT] : '';
		} else {
			$aq = ($select & $addQuery) ? $select.' '.$addQuery : $addQuery;
			$query = $this->pi_list_query($this->internal[currentTable],$count,$addWhere,$mmcat,"",$orderby,$aq);
		}
	return $query;
	}
	
	function makeSearchbox($search)	{
		
		$code = '	<table cellspacing="0" cellpadding="0" border="0"><tr>
					<form method="POST" action="'.$this-">makeLink("",liste,search,"",0).'">
					<td><input type="text" class="tx_spdirectory-pi1-small" name="tx_spdirectory_pi1[value]" codethis-="" />piVars[modifier]==search) ? ' value="'.$search.'"' : "" ;
					
		$code .= ($this->piVars[modifier]==search) ? ' style="color: '.$this->conf[active].';font-size: 10px;"' : ' style="font-size: 10px;"';		 
					
		$code .= '	></td>
					<td><input type="submit" value="'.$this-" />pi_getLL("search").'" class="tx_spdirectory-pi1-small"></td>
					</form></tr></table>';
	
	return $code;
	}
	
	
	function makeMailtoLink($emailadr)	{
                $this->typolink_conf["parameter"] = $emailadr;
		$code = $this->cObj->typolink($emailadr, $this->typolink_conf);

	return $code;
	}	

        function makeHTTPLink($url,$name)      {
                $this->typolink_conf["parameter"] = $url;
                $code = $this->cObj->typolink($name, $this->typolink_conf);

	return $code;
        }
							


	function makeJumper($modifier,$value)	{
		
		$pidlist = $this->pi_getPidlist($this->conf["pidList"],$this->conf["recursive"]);

		$query = "SELECT DISTINCT tx_spdirectory_cat.catname AS name, tx_spdirectory_cat_mm.uid_foreign AS id FROM tt_address, tx_spdirectory_cat, tx_spdirectory_cat_mm WHERE tt_address.pid IN (".$pidlist.")".$this->cObj->enableFields(tt_address)." AND tx_spdirectory_cat_mm.uid_local = tt_address.uid AND tx_spdirectory_cat.uid = tx_spdirectory_cat_mm.uid_foreign";
		$res = mysql(TYPO3_db,$query);
		
		while($tempo = mysql_fetch_assoc($res))	{
			$entries .= '<option value="'.$this-">makeLink("",liste,cat,$tempo[id],$cache=1,$pointer=0).'"';
			$entries .= ($tempo[id]==$value&&$modifier==cat) ? ' selected style="color: '.$this->conf[active].';"' : "";
			$entries .= '>'.$tempo[name].'</option>';
		}
		
		$code="
		
		<script language="\" javascript="" type="\" textjavascript="">
		<!--
		function MM_jumpMenu(targ,selObj,restore){ 
  		eval(targ+\".location='\"+selObj.options[selObj.selectedIndex].value+\"'\");
  		if (restore) selObj.selectedIndex=0;
		}
		//-->
		</script>

		<table border="\" cellspacing="\" cellpadding="\"><form name="\" form1="">
  		<tr>
   		<td><select name="\" menu1="" onchange="\" mm_jumpmenuselfthis0="" class="\" tx_spdirectory-pi1-small="">
		<option value="\" this-="">pi_linkTP_keepPIvars_url("",1)."\">".$this->pi_getLL("category")."</option>".$entries."
  		</select></td>
  		</tr></form></table>
		
		";
	
	
	
	return $code;
	}
	
	function makeZIP($modifier,$value)	{
		
		$pidlist = $this->pi_getPidlist($this->conf["pidList"],$this->conf["recursive"]);

		$query = "SELECT DISTINCT zip FROM tt_address WHERE tt_address.pid IN (".$pidlist.")"." ".$this->cObj->enableFields(tt_address)." ORDER BY zip";
		$res = mysql(TYPO3_db,$query);
		
		while($tempo = mysql_fetch_assoc($res))	{
			$entries .= '<option value="'.$this-">makeLink("",liste,zip,$tempo[zip],$cache=1,$pointer=0).'"';
			$entries .= ($tempo[zip]==$value&&$modifier==zip) ? ' selected style="color: '.$this->conf[active].'"' : "";
			$entries .= '>'.$tempo[zip].'</option>';
		}
		
		$code="
		
		<script language="\" javascript="" type="\" textjavascript="">
		<!--
		function MM_jumpMenu(targ,selObj,restore){ 
  		eval(targ+\".location='\"+selObj.options[selObj.selectedIndex].value+\"'\");
  		if (restore) selObj.selectedIndex=0;
		}
		//-->
		</script>

		<table border="\" cellspacing="\" cellpadding="\"><form name="\" form1="">
  		<tr>
   		<td><select name="\" menu1="" onchange="\" mm_jumpmenuselfthis0="" class="\" tx_spdirectory-pi1-small="">
		<option value="\" this-="">pi_linkTP_keepPIvars_url("",1)."\">".$this->pi_getLL("zip")."</option>".$entries."
  		</select></td>
  		</tr></form></table>
		
		";
	
	return $code;
	
	}
	function getImage($image,$conf)	{
			$this->conf=$conf;
			$varLogo = $this->conf["image."];
			$varLogo["file"] = "uploads/pics/".($image);
	return $theImgCode=$this->cObj->IMAGE($varLogo);
	}
	
	function makeError($string)	{
		$this->fehler=1;
		return '<font color="red">'.$string.'</font>';
	}

	function makeForm($mode="enter",$modifier="first",$id="")	{	
	
		//Formular bauen			
		$this->listeTemplateCode = $this->cObj->fileResource($this->conf["templateFile"]);
		$this->enter = $this->cObj->getSubpart($this->listeTemplateCode, "###ENTERVIEW###");

		$over = array(mode => "edit", modifier => "submit", value =>$this->piVars[value], pointer => "0");
                $link = $this->pi_linkTP_keepPIvars_url($over,$cache);

		$markerArray["###ACTION###"] = $link;
		$markerArray["###ERROR###"] = "";
		$markerArray["###DOTTED###"] = $this->pi_classParam("dotted");
		$markerArray["###SMALL###"] = $this->pi_classParam("small");
#		$markerArray["###NEWENTRY###"] = $this->pi_getLL("newentry");
		$markerArray["###NAME###"] = $this->pi_getLL("name");				
		$markerArray["###STREET###"] = $this->pi_getLL("street");
		$markerArray["###ZIP###"] = $this->pi_getLL("zip");
		$markerArray["###CITY###"] = $this->pi_getLL("city");
		$markerArray["###PHONE###"] = $this->pi_getLL("phone");
		$markerArray["###MOBILE###"] = $this->pi_getLL("mobile");
		$markerArray["###FAX###"] = $this->pi_getLL("fax");
		$markerArray["###EMAIL###"] = $this->pi_getLL("email");
		$markerArray["###EDITENTRY###"] = $this->pi_getLL("edit_entry");
		$markerArray["###WWW###"] = $this->pi_getLL("www");
		$markerArray["###IMAGE###"] = $this->pi_getLL("image");
		$markerArray["###DESCRIPTION###"] = $this->pi_getLL("description");
		$markerArray["###SUBMIT###"] = $this->pi_getLL("submit");
		$markerArray["###CATEGORY###"] = $this->pi_getLL("category");
		$markerArray["###SELECT###"] = $this->makeCategory($this->piVars[category]);
		$markerArray["###FOLDER###"] = ($this->cObj->data["tx_spdirectory_dspfolder"]) ? $this->pi_getLL("folder") : "";
		$markerArray["###SELECTFOLDER###"] = ($this->cObj->data["tx_spdirectory_dspfolder"]) ? $this->makeFolder("") : "";	
	
		switch($mode)	{
			case "enter":
				$hidden[mode]=enter;
				$hidden[modifier]=submit;
				switch($modifier)	{
					case "submit":
						$markerArray = $this->evalForm($markerArray);
						if(!$this->fehler)	{
							$image=$this->storeImage();					
							$goto = $this->storeDB($image);
							$success = $this->makeSuccess($goto);
						}
						else	{
							$markerArray["###NAMEV###"] = $this->piVars[name];				
							$markerArray["###STREETV###"] = $this->piVars[address];
							$markerArray["###ZIPV###"] = $this->piVars[zip];
							$markerArray["###CITYV###"] = $this->piVars[city];
							$markerArray["###PHONEV###"] = $this->piVars[phone];
							$markerArray["###MOBILEV###"] = $this->piVars[mobile];
							$markerArray["###FAXV###"] = $this->piVars[fax];
							$markerArray["###EMAILV###"] = $this->piVars[email];
							$markerArray["###WWWV###"] = $this->piVars[www];
							$markerArray["###DESCRIPTIONV###"] = $this->piVars[description];					
						}
					break;
					default:
						$markerArray["###NAMEV###"] = "";				
						$markerArray["###STREETV###"] = "";
						$markerArray["###ZIPV###"] = "";
						$markerArray["###CITYV###"] = "";
						$markerArray["###PHONEV###"] = "";
						$markerArray["###MOBILEV###"] = "";
						$markerArray["###FAXV###"] = "";
						$markerArray["###EMAILV###"] = "";
						$markerArray["###WWWV###"] = "";
						$markerArray["###DESCRIPTIONV###"] = "";
					break;
				}

			
			break;
			case "edit";
				$markerArray["###IMAGE###"] = $this->pi_getLL("new_image");
				$markerArray["###SUBMIT###"] = $this->pi_getLL("edit_delete");
				$markerArray["###HIDDEN###"] = '<input name="tx_spdirectory_pi1[delete]" type="checkbox" id="tx_spdirectory_pi1[delete]" value="1" />'.$this->pi_getLL("delete").'   ';
				
				$hidden[mode]=edit;
				$hidden[modifier]=submit;
				$hidden[value]=$id;
				switch($modifier)	{
					case "submit";
						if($this->piVars[delete])	{
							if ($this->checkAccess($id)) {
								$this->deleteFromDB($id);
								$success = $this->makeSuccess($goto);
							} else {
				                         	$this->fehler=1;
			        	                 	$markerArray["###ERROR###"] = "<font color="red">".$this->pi_getLL("error_noaccess")."</font><br /><br />";
							}
						} else {
							$markerArray = $this->evalForm($markerArray);
							if(!$this->fehler)	{
								$image=$this->storeImage();
								$goto = $this->updateDB($image,$id);
								$success = $this->makeSuccess($goto);
							
							}
							else	{
								$markerArray["###NAMEV###"] = $this->piVars[name];				
								$markerArray["###STREETV###"] = $this->piVars[address];
								$markerArray["###ZIPV###"] = $this->piVars[zip];
								$markerArray["###CITYV###"] = $this->piVars[city];
								$markerArray["###PHONEV###"] = $this->piVars[phone];
								$markerArray["###MOBILEV###"] = $this->piVars[mobile];
								$markerArray["###FAXV###"] = $this->piVars[fax];
								$markerArray["###EMAILV###"] = $this->piVars[email];
								$markerArray["###WWWV###"] = $this->piVars[www];
								$markerArray["###DESCRIPTIONV###"] = $this->piVars[description];	
							}
						}
					break;
					default:
						//Get Data from DB
						$pidlist = $this->pi_getPidlist($this->conf["pidList"],$this->conf["recursive"]);
						$query = "SELECT tt_address.*,tx_spdirectory_cat_mm.uid_foreign FROM tt_address,tx_spdirectory_cat,tx_spdirectory_cat_mm WHERE tt_address.uid=tx_spdirectory_cat_mm.uid_local AND tx_spdirectory_cat.uid=tx_spdirectory_cat_mm.uid_foreign AND tt_address.pid IN (".$pidlist.")"." ".$this->cObj->enableFields(tt_address)." AND tt_address.uid = ".$id;

						$i=0;
						$res = mysql(TYPO3_db,$query);
						while($row = mysql_fetch_assoc($res)) {
							$category[$i++] = $row[uid_foreign];
							if ($i = 1) {
								//Assign Data to Fields
								$markerArray["###NAMEV###"] = $row[name];
								$markerArray["###STREETV###"] = $row[address];
								$markerArray["###ZIPV###"] = $row[zip];
								$markerArray["###CITYV###"] = $row[city];
								$markerArray["###PHONEV###"] = $row[phone];
								$markerArray["###MOBILEV###"] = $row[mobile];
								$markerArray["###FAXV###"] = $row[fax];
								$markerArray["###EMAILV###"] = $row[email];
								$markerArray["###WWWV###"] = $row[www];
								$markerArray["###DESCRIPTIONV###"] = $row[description];
								$markerArray["###SELECT###"] = $this->makeCategory($category);
								$markerArray["###SELECTFOLDER###"] = ($this->cObj->data["tx_spdirectory_dspfolder"]) ? $this->makeFolder($row[pid]) : "";
							}
						}
						//No category selected
						if ($i == 0) {

							$query = "SELECT * FROM tt_address WHERE pid IN (".$pidlist.")"." ".$this->cObj->enableFields(tt_address)." AND uid = ".$id;

							$res = mysql(TYPO3_db,$query);
                	                                while($row = mysql_fetch_assoc($res)) {
								//Assign Data to Fields
                                	                        $markerArray["###NAMEV###"] = $row[name];
                                        	                $markerArray["###STREETV###"] = $row[address];
                                                	        $markerArray["###ZIPV###"] = $row[zip];
                                                        	$markerArray["###CITYV###"] = $row[city];
	                                                        $markerArray["###PHONEV###"] = $row[phone];
        	                                                $markerArray["###MOBILEV###"] = $row[mobile];
                	                                        $markerArray["###FAXV###"] = $row[fax];
                        	                                $markerArray["###EMAILV###"] = $row[email];
                                	                        $markerArray["###WWWV###"] = $row[www];
                                        	                $markerArray["###DESCRIPTIONV###"] = $row[description];
                                                	        $markerArray["###SELECT###"] = $this->makeCategory($category);
                                                        	$markerArray["###SELECTFOLDER###"] = ($this->cObj->data["tx_spdirectory_dspfolder"]) ? $this->makeFolder($row[pid]) : "";
							}
						}
					break;
				}
		}
		$markerArray["###HIDDEN###"] .= $this->makeHidden($hidden);
	
		$return = (!$success) ? $this->cObj->substituteMarkerArrayCached($this->enter,$markerArray,array(),array()) : $success;
	
	return $return;	
	}	
	
	function makeHidden($hidden)	{
		while(list($key,$value) = each($hidden))	{
			$code .= '<input type="hidden" name="tx_spdirectory_pi1['.$key.']" value="'.$value.'" />';
		}
	return $code;
	}
	
	function evalForm($markerArray)	{
		$markerArray["###NAME###"] = ($this->piVars[name] || !t3lib_div::inList(strtolower($this->conf["required_fields"]),"name")) ? $markerArray["###NAME###"] : $this->makeError($markerArray["###NAME###"]);			
		$markerArray["###STREET###"] = ($this->piVars[address] || !t3lib_div::inList(strtolower($this->conf["required_fields"]),"street")) ? $markerArray["###STREET###"] : $this->makeError($markerArray["###STREET###"]);	
		$markerArray["###ZIP###"] = (preg_match("([0-9]{5})",$this->piVars[zip]) || !t3lib_div::inList(strtolower($this->conf["required_fields"]),"zip")) ? $markerArray["###ZIP###"] : $this->makeError($markerArray["###ZIP###"]);
		$markerArray["###CITY###"] = ($this->piVars[city] || !t3lib_div::inList(strtolower($this->conf["required_fields"]),"city")) ? $markerArray["###CITY###"] : $this->makeError($markerArray["###CITY###"]);
		$markerArray["###EMAIL###"] = (preg_match("(^[_a-zA-Z0-9-]+(\.[_a-zA-Z0-9-]+)*@([a-zA-Z0-9-]+\.)+([a-zA-Z]{2,3})$)",$this->piVars[email]) || !t3lib_div::inList(strtolower($this->conf["required_fields"]),"email")) ? $markerArray["###EMAIL###"] : $this->makeError($markerArray["###EMAIL###"]);
		$markerArray["###WWW###"] = (preg_match("/^(http:|ftp:\/\/).*(\.+).*/i",$this->piVars[www]) || !t3lib_div::inList(strtolower($this->conf["required_fields"]),"www")) ? $markerArray["###WWW###"] : $this->makeError($markerArray["###WWW###"]);
#		$markerArray["###ERROR###"] = ($this->fehler) ? "<font color="red">".$this->pi_getLL("error")."</font><br /><br />" : "";
		$markerArray["###IMAGE###"] = ($this->evalImage()!=error || !t3lib_div::inList(strtolower($this->conf["required_fields"]),"image")) ? $markerArray["###IMAGE###"] : $this->makeError($markerArray["###IMAGE###"]);	
		$markerArray["###CATEGORY###"] = ($this->piVars[category] || !t3lib_div::inList(strtolower($this->conf["required_fields"]),"category")) ? $markerArray["###CATEGORY###"] : $this->makeError($markerArray["###CATEGORY###"]);	

		$accessOK = "";
		if ($this->piVars[value]) {
			$accessOK = $this->checkAccess($this->piVars[value]);
		} else {
			$accessOK = $this->checkAccess(-1);
		}
		$accessOK = ereg('[0-9]', $accessOK);
                if (!$accessOK) {
			$this->fehler=1;
			$markerArray["###ERROR###"] = "<font color="red">".$this->pi_getLL("error_noaccess")."</font><br /><br />";
		} else {
			$markerArray["###ERROR###"] = ($this->fehler) ? "<font color="red">".$this->pi_getLL("error")."</font><br /><br />" : "";
		}

	return $markerArray;
	}
	
	function evalImage()	{
		//Bildtyp checken
		$bildtypen = array("gif","jpg","png");
		
		//Bild vorhanden?
		if($this->piVars[image]!=none)	{
		
			@$typ = getimagesize($this->piVars[image]);
			if($typ[2]!= 1 && $typ[2]!= 2 && $typ[2]!= 3 || $GLOBALS[tx_spdirectory_pi1_size][image]>210000)	{
				$type=error;
			}
			else	{
				$type=$bildtypen["$typ[2]"];
			}
		}
		else	{
			$type=none;
		}
		
		
	return $type;
	}
	
	function storeDB($image)	{

		$pid = ($this->piVars[folder]) ? $this->piVars[folder] : $GLOBALS["TSFE"]->page[uid];
	
		$query='INSERT INTO tt_address (pid,tstamp,name,address,zip,city,phone,mobile,fax,email,www,description,image,tx_spdirectory_cat,tx_spdirectory_fegroup,tx_spdirectory_feuser) 
				VALUES ("'.$pid.'","'.time().'","'.mysql_escape_string($this->piVars[name]).'","'.
mysql_escape_string($this->piVars[address]).'","'.mysql_escape_string($this->piVars[zip]).'","'.mysql_escape_string($this->piVars[city]).'","'.
mysql_escape_string($this->piVars[phone]).'","'.mysql_escape_string($this->piVars[mobile]).'","'.mysql_escape_string($this->piVars[fax]).'","'.
mysql_escape_string($this->piVars[email]).'","'.mysql_escape_string($this->piVars[www]).'","'.mysql_escape_string(strip_tags($this->piVars[description])).'","'.$image.'","0","'.$this->conf["default_fegroup"].'","'.$GLOBALS['TSFE']->fe_user->user[uid].'")';

		$res = mysql(TYPO3_db,$query);
		
		$id=mysql_insert_id();

		$i=1;
                foreach ($this->piVars[category] as $cat) {
                        $query = 'INSERT INTO tx_spdirectory_cat_mm (uid_local,uid_foreign,sorting) VALUES ("'.$id.'", "'.$cat.'", "'.$i++.'")';
                        $res = mysql(TYPO3_db,$query);
                }
		
		$res = mysql (TYPO3_db, "DELETE FROM cache_pages WHERE page_id = ".$GLOBALS["TSFE"]->page[uid]);
	
	return $id;
	}
	
	function updateDB($image,$id)	{
	
		$pid = ($this->piVars[folder]) ? $this->piVars[folder] : $GLOBALS["TSFE"]->page[uid];

		$query =	"UPDATE tt_address SET
					pid = '".$pid."', 
					name = '".mysql_escape_string($this->piVars[name])."',
					address = '".mysql_escape_string($this->piVars[address])."',
					zip = '".mysql_escape_string($this->piVars[zip])."',
					city = '".mysql_escape_string($this->piVars[city])."',
					phone = '".mysql_escape_string($this->piVars[phone])."',
					mobile = '".mysql_escape_string($this->piVars[mobile])."',
					fax = '".mysql_escape_string($this->piVars[fax])."',
					email = '".mysql_escape_string($this->piVars[email])."',
					www = '".mysql_escape_string($this->piVars[www])."',
					description = '".mysql_escape_string(strip_tags($this->piVars[description]))."',";
					
		$query .= ($image) ? "image = '".$image."'," : "";
				
		$query .=	"tx_spdirectory_cat = '0'
					WHERE uid = '".$id."'";
		$res = mysql(TYPO3_db,$query);
		$res = mysql (TYPO3_db, "DELETE FROM cache_pages WHERE page_id = ".$GLOBALS["TSFE"]->page[uid]);

		$res = mysql(TYPO3_db, "DELETE FROM tx_spdirectory_cat_mm WHERE uid_local = ".$id);

		$i=1;
		foreach ($this->piVars[category] as $cat) {
			$query = 'INSERT INTO tx_spdirectory_cat_mm (uid_local,uid_foreign,sorting) VALUES ("'.$id.'", "'.$cat.'", "'.$i++.'")';
			$res = mysql(TYPO3_db,$query);
		}
		
	}
	
	function deleteFromDB($id)	{
		$query = "DELETE FROM tt_address WHERE uid = $id";
		$res = mysql(TYPO3_db,$query);

		$query = "DELETE FROM tx_spdirectory_cat_mm WHERE uid_local = $id";
                $res = mysql(TYPO3_db,$query);

		$res = mysql (TYPO3_db, "DELETE FROM cache_pages WHERE page_id = ".$GLOBALS["TSFE"]->page[uid]);
	}
	
	function storeImage()	{

		if($GLOBALS[HTTP_POST_FILES][tx_spdirectory_pi1][name][image])	{

			$this->fileFunc = t3lib_div::makeInstance("t3lib_basicFileFunctions");
			$sauber = $this->fileFunc->cleanFileName($GLOBALS[HTTP_POST_FILES][tx_spdirectory_pi1][name][image]); 
			$unique = $this->fileFunc->getUniqueName($sauber,PATH_site.$TYPO3_LOADED_EXT[$key]["siteRelPath"]."uploads/pics/");
			move_uploaded_file($this->piVars[image],$unique);		
		}
		$return = pathinfo($unique);

	return $return[basename];
	
	}
	
	function makeCategory($id)	{
		
		$pidlist = $this->pi_getPidlist($this->conf["pidList"],$this->conf["recursive"]);

		$query = "SELECT uid, catname FROM tx_spdirectory_cat WHERE pid IN (".$pidlist.")"." ".$this->cObj->enableFields(tx_spdirectory_cat)." ORDER BY catname";
		$res = mysql(TYPO3_db,$query);
		
		while($tempo = mysql_fetch_assoc($res))	{

			$entries .= '<option value="'.$tempo[uid].'" ifis_arrayidentriesin_arraytempouididselected:elseentriestempouididselected:entries="">'.$tempo[catname].'</option>';
		}
		
		$code='
		<select name="tx_spdirectory_pi1[category][]" class="tx_spdirectory-pi1-small" size="5" multiple="">
		'.$entries.'
  		</select>
		';
	return $code;
	}

	function makeFolder($id)      {

		$pidlist = $this->pi_getPidlist($this->conf["pidList"],$this->conf["recursive"]);

                $query = "SELECT uid,title FROM pages WHERE uid IN (".$pidlist.")"." ".$this->cObj->enableFields(pages)." ORDER BY title";
                $res = mysql(TYPO3_db,$query);

                while($tempo = mysql_fetch_assoc($res)) {

                        $entries .= '<option value="'.$tempo[uid].'" entriestempouididselected:entries="">'.$tempo[title].'</option>';
                }

                $code='
                <select name="tx_spdirectory_pi1[folder]" class="tx_spdirectory-pi1-small">
                '.$entries.'
                </select>
                ';
        return $code;
        }


	function makeSuccess($goto)	{
		
		$success = $this->cObj->getSubpart($this->listeTemplateCode, "###SUCCESSVIEW###");
		$markerArray["###DOTTED###"] = $this->pi_classParam("dotted");
		$markerArray["###SMALL###"] = $this->pi_classParam("small");
		$url[tx_spdirectory_pi1][detail]=$goto;
		unset($this->piVars);
		$markerArray["###BACK###"] = $this->makeLink($this->pi_getLL("back"),liste,abc,all);
		$markerArray["###THANKS###"] =$this->pi_getLL("thanks");
		$markerArray["###EDITENTRY###"] =$this->pi_getLL("edit_entry");
		
		$success = $this->cObj->substituteMarkerArrayCached($success,$markerArray,array(),array());	
		
	return $success;
	}

	function checkAccess($id)	{

		$access = 0;
		$query = 'SELECT tx_spdirectory_fegroup,tx_spdirectory_feuser FROM tt_address WHERE uid = '.$id;
                $res = mysql(TYPO3_db,$query);
		$row = mysql_fetch_assoc($res);
		if ($id == -1) {
			$access = t3lib_div::inList($GLOBALS['TSFE']->fe_user->user['usergroup'],$this->conf["default_fegroup"]);
		} else {
	                $access = t3lib_div::inList($GLOBALS['TSFE']->fe_user->user['usergroup'],$row[tx_spdirectory_fegroup]) || $GLOBALS['TSFE']->fe_user->user[uid]==$row[tx_spdirectory_feuser];
		}
	return $access;
	}

}



if (defined("TYPO3_MODE") && $TYPO3_CONF_VARS[TYPO3_MODE]["XCLASS"]["ext/sp_directory/pi1/class.tx_spdirectory_pi1.php"])	{
	include_once($TYPO3_CONF_VARS[TYPO3_MODE]["XCLASS"]["ext/sp_directory/pi1/class.tx_spdirectory_pi1.php"]);
}
?>
```

## Antworten

### [#2](https://www.typo3.net/d/32766-titel-sortierung-von-sp-directory-aendern/2) · steffenk · 2005-11-05

puh - ein langer Code  :D

Wenns Dir nur um die Sortierung geht, die wird doch in den SQL-Abfragen gemacht.
Such doch nach ORDER BY und ersetze Name durch Ort

### [#3](https://www.typo3.net/d/32766-titel-sortierung-von-sp-directory-aendern/3) · Schlingel · 2005-11-05

Das hatte ich auch gedacht, aber das war mal nix, ausserdem glaube ich eher, dass die Abfrage hier eher eine SELECT * FROM tt_address WHERE... Abfrage ist, da ja nur die ausgegeben werden die z.b. mit A beginnen. Aber die richitge Abfrage zu finden, ist glauch ich ein Kunststück.

Und hier genau ist mein Problem.

### [#4](https://www.typo3.net/d/32766-titel-sortierung-von-sp-directory-aendern/4) · just2b · 2005-11-05

nomen est omen @ 1000 zeilen code copy&paste, wenn alle die Datei selber runterladen können, oder?  #angry#

> **Schlingel schrieb:**
>
> Aber die richitge Abfrage zu finden, ist glauch ich ein Kunststück.

Quatsch!
Funktion makelist, die dann die Funktion makelistquery aufruft!

wobei du so zwar sicher einfach das ABC via Ort bekommst, aber du musst dann auch noch die Links anpassen, weil das dann nicht mehr zusammenstimmt und und.... also ist nicht so einfach wenn man von php wenig Ahnung hat!

lg georg

### [#5](https://www.typo3.net/d/32766-titel-sortierung-von-sp-directory-aendern/5) · Schlingel · 2005-11-05

Genau das ist das was ich in meinem ersten Beitrag geschrieben habe, das ABC.. über den Ort darzustellen, das ist ja kein Problem, aber die Links...
Ausserdem ist es nicht die Funktion Makelist, sondern die Funktion makeABC.

An diesen Links scheitere ich leider.

### [#6](https://www.typo3.net/d/32766-titel-sortierung-von-sp-directory-aendern/6) · Schlingel · 2005-11-20

Sooo, mir wurde von professioneller Seite für einen sehr guten Preis sehr schnell geholfen.
Vielen Dank

---

Quelle: „Titel-Sortierung von sp_directory ändern“, typo3.net, https://www.typo3.net/d/32766-titel-sortierung-von-sp-directory-aendern
Beiträge von Mitgliedern des Forums. Bitte mit Link auf die Diskussion zitieren.
