PageRenderTime 67ms CodeModel.GetById 14ms app.highlight 41ms RepoModel.GetById 1ms app.codeStats 1ms

/t3consultancies/pi1/class.tx_t3consultancies_pi1.php

https://github.com/michael-cannon/typo3-extensions
PHP | 1714 lines | 1245 code | 230 blank | 239 comment | 86 complexity | 438ea8738c01c45a5461df729726d7e2 MD5 | raw file
   1<?php
   2/***************************************************************
   3*  Copyright notice
   4*  
   5*  (c) 2002 Kasper Skĺrhřj (kasper@typo3.com)
   6*  All rights reserved
   7*
   8*  This script is part of the Typo3 project. The Typo3 project is 
   9*  free software; you can redistribute it and/or modify
  10*  it under the terms of the GNU General Public License as published by
  11*  the Free Software Foundation; either version 2 of the License, or
  12*  (at your option) any later version.
  13* 
  14*  The GNU General Public License can be found at
  15*  http://www.gnu.org/copyleft/gpl.html.
  16* 
  17*  This script is distributed in the hope that it will be useful,
  18*  but WITHOUT ANY WARRANTY; without even the implied warranty of
  19*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  20*  GNU General Public License for more details.
  21*
  22*  This copyright notice MUST APPEAR in all copies of the script!
  23***************************************************************/
  24/** 
  25 * Plugin 'Consultancies' for the 't3consultancies' extension.
  26 *
  27 * @author	Kasper Skĺrhřj <kasper@typo3.com>
  28 */
  29/**
  30 * @author Michael Cannon <michael@peimic.com>
  31 * @version $Id: class.tx_t3consultancies_pi1.php,v 1.1.1.1 2010/04/15 10:04:06 peimic.comprock Exp $
  32 */
  33
  34
  35require_once(PATH_tslib."class.tslib_pibase.php");
  36
  37class tx_t3consultancies_pi1 extends tslib_pibase {
  38	var $prefixId = "tx_t3consultancies_pi1";		// Same as class name
  39	var $scriptRelPath = "pi1/class.tx_t3consultancies_pi1.php";	// Path to this script relative to the extension dir.
  40	var $extKey = "t3consultancies";	// The extension key.
  41	
  42		// Internal
  43	var $categories=array();
  44	var $countries=array();
  45	var $showRef=0;	// If set, then references for consultancies are shown.
  46	var $singleViewOn=0;	// If set, a single item is shown
  47
  48	// limit selection of categories
  49	var $categoriesList			= '';
  50
  51	// default template file
  52	var $templateFile			= 'EXT:t3consultancies/pi1/t3consultancies.html';
  53
  54	// template marker contents
  55	var $markerArray			= array();
  56	var $db						= null;
  57
  58	/**
  59	 * Main function
  60	 */
  61	function main($content,$conf)	{
  62		$this->pi_setPiVarDefaults();
  63
  64		// Loading the LOCAL_LANG values
  65		$this->pi_loadLL();
  66
  67		// current database object
  68		$this->db				= $GLOBALS[ 'TYPO3_DB' ];
  69		$this->db->debugOutput	= true;
  70
  71		$this->showRef			= $conf["t3references_disabled"]
  72									? 0 
  73									: t3lib_extMgm::isLoaded("t3references");
  74		$this->sitesMade		= ! $conf["sites_made_disabled"];
  75
  76		if (strstr($this->cObj->currentRecord,"tt_content"))
  77		{
  78			$conf["pidList"] = $this->cObj->data["pages"];
  79			$conf["recursive"] = $this->cObj->data["recursive"];
  80			$conf["selectedOnly"] = $this->cObj->data["tx_t3consultancies_selected_only"];
  81
  82			// allow tt_content to define what to show here
  83			$conf[ 'CMD' ]		= $this->cObj->data[
  84									'tx_t3consultancies_command' ];
  85
  86 			$this->conf[ 'categoryListingPage' ]	= ( $this->cObj->data[
  87										'tx_t3consultancies_categorylisting' ]
  88									)
  89									?  $this->cObj->data[
  90										'tx_t3consultancies_categorylisting' ]
  91 									: $this->conf[ 'categoryListingPage' ];
  92
  93 			$this->conf[ 'alphabeticalListingPage' ]	= ( $this->cObj->data[
  94										'tx_t3consultancies_alphabeticallisting' ]
  95									)
  96									?  $this->cObj->data[
  97									'tx_t3consultancies_alphabeticallisting' ]
  98 									: $this->conf[ 'alphabeticalListingPage' ];
  99
 100			// check for tt_content defined templateFile
 101			$conf[ 'templateFile' ]	= ( $this->cObj->data[
 102										'tx_t3consultancies_template' ]
 103									)
 104										? "uploads/tx_t3consultancies/"
 105											.  $this->cObj->data[
 106												'tx_t3consultancies_template' ]
 107										: $conf[ 'templateFile' ];
 108
 109			// set templateFile to use for remainder
 110			$this->templateFile	= ( $conf[ 'templateFile' ] )
 111									? $conf[ 'templateFile' ]
 112									: $this->templateFile;
 113
 114			$categoriesList		= $this->cObj->data[
 115									'tx_t3consultancies_categories' ];
 116
 117			if ( $categoriesList )
 118			{
 119				$this->categoriesList	= ( 'featuredAd' != $conf[ 'CMD' ] )
 120											? " AND tx_t3consultancies_cat.uid IN ( $categoriesList )"
 121											: " AND tx_t3consultancies_services_mm.uid_foreign IN ( $categoriesList )";
 122			}
 123
 124		}
 125
 126		$conf					= $this->buildTextImageConf( $conf );
 127	
 128		$this->conf				= $conf;
 129
 130		switch( $conf["CMD"] )
 131		{
 132			case "navigation":
 133				return $this->pi_wrapInBaseClass( $this->navigationView(
 134					$content
 135					, $conf
 136				) );
 137			break;
 138
 139			// force if a single element should be displayed:
 140			case "singleView":
 141			case ( isset( $this->piVars[ 'showUid' ] ) ):
 142				$this->internal["currentTable"] = "tx_t3consultancies";
 143				$this->internal["currentRow"] = $this->pi_getRecord("tx_t3consultancies",$this->piVars["showUid"]);
 144				
 145				return $this->pi_wrapInBaseClass($this->singleView($content,$conf));
 146			return $content;
 147			break;
 148
 149			case "featuredAd":
 150			case "alphabetical":
 151				return $this->pi_wrapInBaseClass( $this->multipleItemView(
 152					$content
 153					, $conf
 154				) );
 155			break;
 156
 157			case "category":
 158				return $this->pi_wrapInBaseClass( $this->categoryView(
 159					$content
 160					, $conf
 161				) );
 162			break;
 163
 164			case "listView":
 165			default:
 166				return $this->pi_wrapInBaseClass($this->listView($content,$conf));
 167			break;
 168		}
 169	}
 170	
 171	/**
 172	 * Makes the list view of consultancies
 173	 */
 174	function listView($content,$conf)	{
 175		$lConf = $this->conf["listView."];	// Local settings for the listView function
 176
 177
 178
 179		$this->pi_autoCacheEn=1;
 180		$this->pi_autoCacheFields = Array();
 181		$this->pi_autoCacheFields["pointer"] = array("range"=>array(0,10));
 182		
 183		if ($this->conf["selectCountryFirst"])	{
 184			$this->pi_autoCacheFields["lang"] = array("range"=>array(0,1000));
 185			
 186#			$this->pi_isOnlyFields = "mode,pointer,lang";
 187#			$this->pi_lowerThan=1000;
 188		}
 189		
 190
 191		# So the preview button will always be shown...
 192		$this->pi_alwaysPrev=1;
 193		
 194		$this->editAdd=0;
 195		if ((string)$this->piVars["editAdd"])	{
 196			$this->editAdd=1;
 197			$GLOBALS["TSFE"]->set_no_cache();
 198		}
 199
 200		if ($this->editAdd && !$GLOBALS["TSFE"]->loginUser)
 201		{
 202			return '<p>'.sprintf($this->pi_getLL("noUserLoggedInWarning"),'<a href="'.$this->pi_getPageLink($this->conf["loginPageId"]).'">','</a>').'</p>';
 203		}
 204		
 205		elseif ($this->editAdd)
 206		{
 207#				$GLOBALS["TSFE"]->set_no_cache();
 208			
 209			$fullTable="";
 210				
 211			$feAConf=$this->getFe_adminLibConf();
 212			$fullTable.= $this->cObj->cObjGetSingle($this->conf["fe_adminLib"],$feAConf);
 213
 214			$fullTable.= '<p>'.$this->pi_linkTP_keepPIvars($this->pi_getLL("Return_to_listing"),array("editAdd"=>"")).'</p>';
 215				// Returns the content from the plugin.
 216			return $fullTable;
 217		}
 218		
 219		else
 220		{
 221			if (!isset($this->piVars["pointer"]))
 222			{
 223				$this->piVars["pointer"]=0;
 224			}
 225
 226				// Initializing the query parameters:
 227			$this->internal["results_at_a_time"]=t3lib_div::intInRange($lConf["results_at_a_time"],0,1000,30);		// Number of results to show in a listing.
 228			$this->internal["maxPages"]=t3lib_div::intInRange($lConf["maxPages"],0,1000,5);;		// The maximum number of "pages" in the browse-box: "Page 1", "Page 2", etc.
 229			$this->internal["searchFieldList"]="title,description,url,contact_email,contact_name";
 230	
 231			$this->addWhere="";
 232
 233				// Only selected:
 234			$this->addWhere.= $this->conf["selectedOnly"]	? ' AND tx_t3consultancies.selected' : '';
 235
 236
 237				// Getting the list of countries used  - piVars["lang"]
 238			$this->loadCountries();
 239				// Getting the categories used - piVars["service"]
 240			$this->loadCategories();
 241#debug($this->countries);
 242#debug($this->categories);
 243			
 244
 245				// Countries:
 246			$this->addWhere.= $this->piVars["lang"] ? ' AND tx_t3consultancies.cntry='.intval($this->piVars["lang"]) : '';
 247#debug($this->addWhere);
 248
 249			if ($this->piVars["service"])	{
 250				$mm_cat=array();
 251				$mm_cat["mmtable"]="tx_t3consultancies_services_mm";
 252				$mm_cat["table"]="tx_t3consultancies_cat";
 253				$mm_cat["catUidList"]=intval($this->piVars["service"]);
 254			} else $mm_cat="";
 255
 256
 257				// Get number of records:
 258			$query = $this->pi_list_query('tx_t3consultancies',1,$this->addWhere,$mm_cat);
 259			$res = mysql(TYPO3_db,$query);
 260			if (mysql_error())	debug(array(mysql_error(),$query));
 261			list($this->internal["res_count"]) = mysql_fetch_row($res);
 262	
 263				// Make listing query, pass query to MySQL:
 264			$query = $this->pi_list_query("tx_t3consultancies",0,$this->addWhere,$mm_cat,""," ORDER BY tx_t3consultancies.weight DESC, tx_t3consultancies.title");
 265			$res = mysql(TYPO3_db,$query);
 266			if (mysql_error())	debug(array(mysql_error(),$query));
 267			$this->internal["currentTable"] = "tx_t3consultancies";
 268	
 269				// Put the whole list together:
 270			$fullTable="";	// Clear var;
 271
 272
 273			if (!$this->conf["selectCountryFirst"] || $this->piVars["lang"])	{
 274				$fullTable.=$this->makeSelectors();
 275
 276				if ($this->internal["res_count"] > $this->internal["results_at_a_time"])	{
 277						// Adds the result browser:
 278					$fullTable.=$this->pi_list_browseresults();
 279				}
 280				
 281					// Adds the whole list table
 282				$fullTable.=$this->pi_list_makelist($res);
 283				
 284					// Adds the search box:
 285				$fullTable.=$this->pi_list_searchBox();
 286			} else {
 287				$fullTable.=$this->makeSelectors(1);
 288			}
 289				
 290			$fullTable.=$this->makeEditAddButton();
 291			
 292				// Returns the content from the plugin.
 293			return $fullTable;
 294		}
 295	}
 296	
 297	/**
 298	 * Make selector boxes in the top of page
 299	 */
 300	function makeSelectors($noServiceBox=0)	{
 301		$fullTable.=$this->makeCountrySelect($noServiceBox);
 302		if (!$noServiceBox)	$fullTable.=$this->makeServiceSelect();
 303		return '<DIV'.$this->pi_classParam("modeSelector").'>'.
 304			$fullTable.
 305			'</DIV>';
 306	}
 307	
 308	/**
 309	 * Make the selectorbox with countries.
 310	 */
 311	function makeCountrySelect($altLabel=0)	{
 312		$opt=array();
 313		reset($this->countries);
 314
 315		$this->pi_linkTP_keepPIvars($v,array("lang"=>"","pointer"=>""));
 316		$opt[]='<option value="'.htmlentities($this->cObj->lastTypoLinkUrl).'">'.$this->pi_getLL(!$altLabel?'All_countries':'Sel_countries').'</option>';
 317		while(list($k,$v)=each($this->countries))	{
 318			$this->pi_linkTP_keepPIvars($v,array("lang"=>$k,"pointer"=>""));
 319			$opt[]='<option value="'.htmlentities($this->cObj->lastTypoLinkUrl).'"'.($this->piVars["lang"]==$k?" SELECTED":"").'>'.htmlentities($v).'</option>';
 320		}
 321
 322		return '<select onChange="document.location=this.options[this.selectedIndex].value;">'.implode("",$opt).'</select>';
 323	}
 324	
 325	/**
 326	 * Make the selectorbox with categories/services.
 327	 */
 328	function makeServiceSelect()	{
 329		$opt=array();
 330		reset($this->categories);
 331
 332		$this->pi_linkTP_keepPIvars($v,array("service"=>"","pointer"=>""));
 333		$opt[]='<option value="'.htmlentities($this->cObj->lastTypoLinkUrl).'">'.$this->pi_getLL('All_services').'</option>';
 334
 335		while(list($k,$v)=each($this->categories))	{
 336			$url				= $this->categoryUrl( $k );
 337			$opt[]='<option value="'.htmlentities($url).'"'.($this->piVars["service"]==$k?" SELECTED":"").'>'.htmlentities($v).'</option>';
 338		}
 339
 340#		return '<select onChange="document.location=unescape(\''.rawurlencode($this->cObj->lastTypoLinkUrl).'\')+\'&tx_t3consultancies_pi1[service]=\'+this.options[this.selectedIndex].value;">'.implode("",$opt).'</select>';
 341		return '<select onChange="document.location=this.options[this.selectedIndex].value;">'.implode("",$opt).'</select>';
 342	}
 343	
 344	/**
 345	 * Makes a link to/from edit mode
 346	 */
 347	function makeEditAddButton()	{
 348		if ($this->conf["editAdd_enabled"])	{
 349			if (!$this->editAdd)	{
 350				$this->pi_moreParams="&cmd=edit";
 351				return '<p>'.$this->pi_linkTP_keepPIvars($this->pi_getLL("Edit_or_add_entries"),array("editAdd"=>1),1,1).'</p>';
 352			} else {
 353				return '<p>'.$this->pi_linkTP_keepPIvars($this->pi_getLL("Cancel_edit_mode"),array("editAdd"=>""),1,1).'</p>';
 354			}
 355		}
 356	}
 357	
 358	/**
 359	 * Loading the countries used in the list into an internal array, $this->countries
 360	 */
 361	function loadCountries()	{
 362		$pidList = $this->pi_getPidList($this->conf["pidList"],$this->conf["recursive"]);
 363		$query = "SELECT static_countries.cn_short_en,static_countries.uid 
 364			FROM static_countries,tx_t3consultancies 
 365			WHERE tx_t3consultancies.cntry=static_countries.uid AND tx_t3consultancies.pid IN (".$pidList.")".
 366			$this->cObj->enableFields("tx_t3consultancies").
 367			$this->addWhere.
 368			" GROUP BY tx_t3consultancies.cntry ORDER BY static_countries.cn_short_en";
 369		$res = mysql(TYPO3_db,$query);
 370		$this->countries=array();
 371
 372		while($row=mysql_fetch_assoc($res))	{
 373			$this->countries[$row["uid"]]=$row["cn_short_en"];
 374		}
 375	}
 376
 377	/**
 378	 * Loading the categories into an internal array, $this->categories
 379	 */
 380	function loadCategories()
 381	{
 382		$query					= $this->pi_categoriesUsed(
 383									"tx_t3consultancies_cat"
 384									, "tx_t3consultancies_services_mm"
 385									, "tx_t3consultancies"
 386									, $this->addWhere
 387										. $this->categoriesList
 388								);
 389
 390		$res					= mysql(TYPO3_db,$query);
 391		
 392		$this->categories		= array();
 393
 394		while( $row=mysql_fetch_assoc($res) )
 395		{
 396			$this->categories[$row["uid"]]=$row["title"];
 397		}
 398	}
 399
 400	function pi_categoriesUsed($cat_table,$mm_table,$table,$addWhere="")	{
 401			// Fetches the list of PIDs to select from. 
 402			// TypoScript property .pidList is a comma list of pids. If blank, current page id is used.
 403			// TypoScript property .recursive is a int+ which determines how many levels down from the pids in the pid-list subpages should be included in the select.
 404		$pidList = $this->pi_getPidList($this->conf["pidList"],$this->conf["recursive"]);
 405		
 406			// Begin Query:
 407		$query="FROM ".$table.",".$cat_table.",".$mm_table.chr(10).
 408				" WHERE ".$table.".uid=".$mm_table.".uid_local AND ".$cat_table.".uid=".$mm_table.".uid_foreign ".chr(10).
 409				" AND ".$table.".pid IN (".$pidList.")".chr(10).
 410				$this->cObj->enableFields($cat_table).
 411				$this->cObj->enableFields($table).chr(10);
 412		if ($addWhere)	{$query.=" ".$addWhere.chr(10);}
 413		$query.=" GROUP BY ".$cat_table.".uid";
 414
 415		$query = "SELECT ".$cat_table.".title,".$cat_table.".uid ".chr(10).$query;
 416		return $query;
 417	}
 418	
 419	/**
 420	 * Renders a single entry
 421	 */
 422	function singleView( $content, $conf )
 423	{
 424		if ( ! $this->internal["currentRow"]["uid"] )
 425		{
 426			return $this->pi_getLL( 'no_record' );
 427		}
 428		
 429		if ( $this->conf["selectCountryFirst"] && ! $this->piVars["lang"] )
 430		{
 431			$GLOBALS["TSFE"]->set_no_cache();
 432		}
 433		
 434		$this->singleViewOn		= 1;
 435	
 436		// This sets the title of the page for use in indexed search results:
 437		if ($this->internal["currentRow"]["title"])
 438		{
 439			$GLOBALS["TSFE"]->indexedDocTitle =
 440								$this->internal["currentRow"]["title"];
 441		}
 442		
 443		$templatePart			= '###TEMPLATE_SINGLE###';
 444
 445		$string					= $this->parseTemplate( $templatePart );
 446
 447		$content				= $this->cObj->substituteMarkerArrayCached(
 448									$string
 449									, $this->markerArray
 450									// , array()
 451								);
 452	
 453		return $content;
 454	}	
 455
 456	/**
 457	 * Renders multiple ad entries by category selection
 458	 *
 459	 * @param string incoming text
 460	 * @param array configuration ( not used )
 461	 * @return string
 462	 */
 463	function categoryView( $content, $conf )
 464	{
 465		switch ( $this->conf[ 'CMD' ] )
 466		{
 467			case 'category':
 468			default:
 469				$templatePart	= '###TEMPLATE_CATEGORY###';
 470				break;
 471		}
 472
 473		$string					= '';
 474
 475		// Local settings for the listView function
 476		$lConf					= $this->conf["listView."];
 477
 478		// look in database for featured records
 479		$selectedOnly			= ( $this->conf[ 'selectedOnly' ] )
 480									? ' AND tx_t3consultancies.selected'
 481									: '';
 482
 483		// grab inputted service
 484		$serviceSelection		= ( $this->piVars[ 'service' ] )
 485									? " AND tx_t3consultancies_services_mm.uid_foreign IN (
 486											{$this->piVars[ 'service' ]}
 487										)"
 488									: '';
 489
 490		// build up query
 491		$query					= "
 492			SELECT
 493				tx_t3consultancies.*
 494			FROM
 495				tx_t3consultancies
 496				LEFT JOIN tx_t3consultancies_services_mm
 497					ON tx_t3consultancies.uid =
 498						tx_t3consultancies_services_mm.uid_local
 499			WHERE
 500				1 = 1
 501				$selectedOnly
 502				/* {$this->categoriesList} */
 503				$serviceSelection
 504		";
 505		$query					.= $this->cObj->enableFields(
 506									'tx_t3consultancies' );
 507
 508		// this is okay while advertiser list is small, less a few hundred
 509		$query					.= "
 510			GROUP BY tx_t3consultancies.uid ASC	
 511			ORDER BY tx_t3consultancies.weight DESC	
 512				, tx_t3consultancies.title ASC	
 513		";
 514		
 515		$result					= $this->db->sql( TYPO3_db, $query );
 516
 517		// if results, grab template
 518		if ( $result && $ad = $this->db->sql_fetch_assoc( $result ) )
 519		{
 520			// cycle through template for each record
 521			do
 522			{
 523				$string			.= $this->parseTemplate(
 524									$templatePart
 525									, true
 526									, $ad
 527								);
 528			} while ( $ad = $this->db->sql_fetch_assoc( $result ) );
 529		}
 530
 531		else
 532		{
 533			$string				.= $this->pi_getLL( 'no_record' );
 534		}
 535
 536		// build up category selection query
 537		$query					= "
 538			SELECT
 539				tx_t3consultancies_cat.*
 540			FROM
 541				tx_t3consultancies_cat
 542				LEFT JOIN tx_t3consultancies_services_mm
 543					ON tx_t3consultancies_cat.uid =
 544						tx_t3consultancies_services_mm.uid_foreign
 545			WHERE
 546				1 = 1
 547				/* {$this->categoriesList} */
 548				$serviceSelection
 549		";
 550		$query					.= $this->cObj->enableFields(
 551									'tx_t3consultancies_cat' );
 552
 553		// this is okay while advertiser list is small, less a few hundred
 554		$query					.= "
 555			ORDER BY tx_t3consultancies_cat.title ASC	
 556		";
 557		
 558		$result					= $this->db->sql( TYPO3_db, $query );
 559
 560		$contentMarkerArray		= array();
 561		$contentMarkerArray[ '###CONTENT###' ]		= $string;
 562
 563		// if results, grab template
 564		if ( $result && $category = $this->db->sql_fetch_assoc( $result ) )
 565		{
 566			$contentMarkerArray[ '###TITLE###' ]		= $category[ 'title' ];
 567			$contentMarkerArray[ '###TITLE_IMAGE###' ]	= $this->textImage(
 568									$category[ 'title' ]
 569								);
 570
 571			if ( $category[ 'image' ] )
 572			{
 573				$image			= $this->cObj->imageLinkWrap( $this->getImage(
 574										$category[ 'image' ]
 575										, $this->conf[ 'featuredLogo.' ]
 576									)
 577									, "uploads/tx_t3consultancies/"
 578										. $category[ 'image' ]
 579									, $this->conf[ 'enlargeImage.' ]
 580								);
 581			}
 582
 583			else
 584			{
 585				$image			= '';
 586			}
 587
 588			$contentMarkerArray[ '###IMAGE###' ]		= $image;
 589			$contentMarkerArray[ '###DESCRIPTION###' ]	= $category[
 590									'description' ];
 591		}
 592
 593		else
 594		{
 595			$contentMarkerArray[ '###TITLE###' ]		= '';
 596			$contentMarkerArray[ '###IMAGE###' ]		= '';
 597			$contentMarkerArray[ '###DESCRIPTION###' ]	= '';
 598		}
 599
 600		$subpart				= $this->templateSubpart ( $templatePart );
 601
 602		$content				= $this->cObj->substituteMarkerArrayCached(
 603									$subpart
 604									, $this->markerArray
 605									, $contentMarkerArray
 606								);
 607
 608		// Returns the content from the plugin.
 609		return $content;
 610	}
 611
 612	/**
 613	 * Renders multiple ad entries by selection
 614	 *
 615	 * @param string incoming text
 616	 * @param array configuration ( not used )
 617	 * @return string
 618	 */
 619	function multipleItemView( $content, $conf )
 620	{
 621		switch ( $this->conf[ 'CMD' ] )
 622		{
 623			case 'featuredAd':
 624				$templatePart	= '###TEMPLATE_FEATURED_AD###';
 625				break;
 626
 627			case 'alphabetical':
 628				$templatePart	= '###TEMPLATE_ALPHABETICAL###';
 629				break;
 630
 631			case 'listView':
 632				$templatePart	= '###TEMPLATE_CATEGORY###';
 633				break;
 634		}
 635
 636		$string					= '';
 637
 638		// Local settings for the listView function
 639		$lConf					= $this->conf["listView."];
 640
 641		// look in database for featured records
 642		$selectedOnly			= ( 'featuredAd' == $this->conf[ 'CMD' ]
 643									|| $this->conf[ 'selectedOnly' ]
 644								)
 645									? ' AND tx_t3consultancies.selected'
 646									: '';
 647
 648		// build up query
 649		$query					= "
 650			SELECT
 651				tx_t3consultancies.*
 652			FROM
 653				tx_t3consultancies
 654				LEFT JOIN tx_t3consultancies_services_mm
 655					ON tx_t3consultancies.uid =
 656						tx_t3consultancies_services_mm.uid_local
 657			WHERE
 658				1 = 1
 659				$selectedOnly
 660				{$this->categoriesList}
 661		";
 662		$query					.= $this->cObj->enableFields(
 663									'tx_t3consultancies' );
 664
 665		// this is okay while advertiser list is small, less a few hundred
 666		$query					.= "
 667			GROUP BY tx_t3consultancies.uid ASC	
 668			ORDER BY tx_t3consultancies.weight DESC	
 669				, tx_t3consultancies.title ASC	
 670		";
 671		
 672		$result					= $this->db->sql( TYPO3_db, $query );
 673
 674		// if results, grab template
 675		if ( $result && $ad = $this->db->sql_fetch_assoc( $result ) )
 676		{
 677			// cycle through template for each record
 678			do
 679			{
 680				$string			.= $this->parseTemplate(
 681									$templatePart
 682									, true
 683									, $ad
 684								);
 685			} while ( $ad = $this->db->sql_fetch_assoc( $result ) );
 686		}
 687
 688		$contentMarkerArray		= array();
 689		$contentMarkerArray[ '###CONTENT###' ] = $string;
 690
 691		$subpart				= $this->templateSubpart ( $templatePart );
 692
 693		$content				= $this->cObj->substituteMarkerArrayCached(
 694									$subpart
 695									, $this->markerArray
 696									, $contentMarkerArray
 697								);
 698
 699		// Returns the content from the plugin.
 700		return $content;
 701	}
 702
 703	/**
 704	 * Renders navigation entries
 705	 *
 706	 * @param string incoming text
 707	 * @param array configuration ( not used )
 708	 * @return string
 709	 */
 710	function navigationView( $content, $conf )
 711	{
 712		$templatePart			= '###TEMPLATE_MENU###';
 713		// $templatePart			= '###TEMPLATE_MENU_ALPHA###';
 714
 715		$string					= '';
 716
 717		// Local settings for the listView function
 718		$lConf					= $this->conf["listView."];
 719
 720		// build up query
 721		$query					= "
 722			SELECT
 723				tx_t3consultancies_cat.*
 724			FROM
 725				tx_t3consultancies_cat
 726			WHERE
 727				1 = 1
 728				{$this->categoriesList}
 729		";
 730		$query					.= $this->cObj->enableFields(
 731									'tx_t3consultancies_cat' );
 732
 733		// this is okay while advertiser list is small, less a few hundred
 734		$query					.= "
 735			ORDER BY tx_t3consultancies_cat.title ASC	
 736		";
 737		
 738		$result					= $this->db->sql( TYPO3_db, $query );
 739
 740		// if results, grab template
 741		if ( $result && $category = $this->db->sql_fetch_assoc( $result ) )
 742		{
 743			// cycle through template for each record
 744			do
 745			{
 746				$string			.= $this->parseTemplate(
 747									$templatePart
 748									, true
 749									, $category
 750								);
 751			} while ( $category = $this->db->sql_fetch_assoc( $result ) );
 752		}
 753
 754		$contentMarkerArray		= array();
 755
 756		$contentMarkerArray[ '###CONTENT###' ] =
 757								$string;
 758
 759		$contentMarkerArray[ '###TITLE_ALPHABETICAL###' ] =
 760								$this->pi_linkToPage(
 761									$this->pi_getLL( 'alphabetical_title' )
 762									, $this->alphabeticalUrl()
 763								);
 764
 765		$subpart				= $this->templateSubpart ( $templatePart );
 766
 767		$content				= $this->cObj->substituteMarkerArrayCached(
 768									$subpart
 769									, $this->markerArray
 770									, $contentMarkerArray
 771								);
 772
 773		// Returns the content from the plugin.
 774		return $content;
 775	}
 776
 777	/**
 778	 * Return string containing tempalte subpart.
 779	 *
 780	 * @param string template part
 781	 * @return string
 782	 */
 783	function templateSubpart ( $templatePart )
 784	{
 785		static $template;
 786
 787		// try not to grab the template more than once if necessary
 788		// TODO ensure this doesn't mess up for multiple same page instances
 789		if ( ! $template )
 790		{
 791			$template			= $this->cObj->fileResource(
 792									$this->templateFile
 793								);
 794		}
 795
 796		// grab subpart
 797		$subpart				= $this->cObj->getSubpart(
 798									$template
 799									, $templatePart
 800								);
 801
 802		return $subpart;
 803	}
 804
 805	/**
 806	 * Return string containing string parsed for given template.
 807	 *
 808	 * @param string template part name
 809	 * @param boolean true - content repeated
 810	 * @param array data
 811	 * @return string
 812	 */
 813	function parseTemplate( $templatePart, $repeating = false, $data = false )
 814	{
 815		$subpartEach			= $this->templateSubpart ( $templatePart );
 816
 817		if ( $repeating )
 818		{
 819			$subpartEach		= $this->cObj->getSubpart(
 820									$subpartEach
 821									, '###EACH###'
 822								);
 823		}
 824
 825		// set internal current row to our input data
 826		if ( ! $data )
 827		{
 828			$data				= $this->internal[ 'currentRow' ];
 829		}
 830
 831		else
 832		{
 833			$this->internal[ 'currentRow' ]	= $data;
 834		}
 835
 836		// create link to detail page
 837		$this->markerArray[ '###DETAILS###' ]	= $this->pi_linkToPage(
 838									 $this->pi_getLL( 'Details' )
 839									 , $this->detailsUrl()
 840								);
 841
 842		$this->markerArray[ '###BACK###' ]	= $this->pi_linkToPage(
 843									 $this->pi_getLL( 'Back' )
 844									 , $_SERVER[ 'HTTP_REFERER' ]
 845								);
 846
 847		// create title as image 
 848		if ( isset( $data[ 'title' ] ) )
 849		{
 850			$this->markerArray[ '###TITLE_IMAGE###' ]	= $this->textImage(
 851									$data[ 'title' ]
 852								);
 853		}
 854
 855		foreach( $data as $key => $value )
 856		{
 857			$upperKey			= strtoupper( $key ) . '###';
 858			$dataKey			= '###' . $upperKey;
 859			$labelKey			= '###LABEL_' . $upperKey;
 860
 861			$this->markerArray[ $dataKey ]	= $this->getFieldContent(
 862									$key
 863								);
 864			$this->markerArray[ $labelKey ]	= $this->pi_getLL(
 865									'listFieldHeader_' . $key
 866								);
 867		}
 868
 869		$string					.= $this->cObj->substituteMarkerArrayCached(
 870									$subpartEach
 871									, $this->markerArray
 872								);
 873
 874		return $string;
 875	}
 876
 877	/**
 878	 * Return string of alphabetical page URL
 879	 *
 880	 * @return string
 881	 */
 882	function alphabeticalUrl()
 883	{
 884		$pid					= ( $this->conf[ 'alphabeticalListingPage' ] )
 885									? $this->conf[ 'alphabeticalListingPage' ] 
 886									: $this->cObj->data[ 'pid' ];
 887
 888 		$linkArray				= array(
 889 									'parameter'			=> $pid
 890 									, 'returnLast'		=> 'url'
 891 									, 'no_cache'		=> 0
 892 									, 'useCacheHash'	=> 0
 893 									, 'additionalParams'	=> ''
 894 								);
 895 		$url					= '/'
 896 									. $this->cObj->typolink(
 897										''
 898 										, $linkArray
 899 									);
 900
 901		return $url;
 902	}
 903
 904	/**
 905	 * Return string of category page URL
 906	 *
 907	 * @param integer category uid
 908	 * @return string
 909	 */
 910	function categoryUrl( $uid )
 911	{
 912		$pid					= ( $this->conf[ 'categoryListingPage' ] )
 913									? $this->conf[ 'categoryListingPage' ] 
 914									: $this->cObj->data[ 'pid' ];
 915
 916 		$linkArray				= array(
 917 									'parameter'			=> $pid
 918 									, 'returnLast'		=> 'url'
 919 									, 'no_cache'		=> 0
 920 									, 'useCacheHash'	=> 0
 921 									, 'additionalParams'	=>
 922									"&tx_t3consultancies_pi1[service]={$uid}"
 923 								);
 924 		$url					= '/'
 925 									. $this->cObj->typolink(
 926										''
 927 										, $linkArray
 928 									);
 929
 930		return $url;
 931	}
 932
 933	/**
 934	 * Return string of detail URL
 935	 *
 936	 * @return string
 937	 */
 938	function detailsUrl()
 939	{
 940 		$linkArray				= array(
 941 									'parameter'			=> $this->conf[
 942															'detailPid' ]
 943 									, 'returnLast'		=> 'url'
 944 									, 'no_cache'		=> 0
 945 									, 'useCacheHash'	=> 0
 946 									, 'additionalParams'	=> "&tx_t3consultancies_pi1[showUid]={$this->internal['currentRow']['uid']}"
 947 								);
 948 		$url					= '/'
 949 									. $this->cObj->typolink(
 950										''
 951 										, $linkArray
 952 									);
 953
 954		return $url;
 955	}
 956
 957	/**
 958	 * Selects and renders the referencelist for the consultancy.
 959	 */
 960	function getRefListForRecord()	{
 961		if ($this->showRef)	{
 962			$value="";
 963			$pLR = $this->pidListForReferences();
 964			if ($pLR)	{
 965				$pLR="pid IN (".$pLR.") AND";
 966			} else $pLR="";
 967			$query = "SELECT * FROM tx_t3references WHERE ".$pLR." dev_rel=".intval($this->internal["currentRow"]["uid"]).
 968				($this->conf["selectedOnly"]	? ' AND tx_t3references.selected' : '').
 969				$this->cObj->enableFields("tx_t3references").
 970				" ORDER BY tx_t3references.weight DESC, tx_t3references.launchdate DESC, tx_t3references.title";
 971
 972			$res = mysql(TYPO3_db,$query);
 973#echo mysql_error();
 974			
 975			$marginBetweenRefs = t3lib_div::intInRange($this->conf["singleView."]["showRefList."]["marginBetweenRefs"],1,100,10);
 976			$marginToImg = t3lib_div::intInRange($this->conf["singleView."]["showRefList."]["marginToImg"],1,100,10);
 977			$refPage = intval($this->conf["singleView."]["showRefList."]["refPage"]);
 978			
 979			$items=array();
 980			while ($row=mysql_fetch_assoc($res))	{
 981				list($srcDump) = t3lib_div::trimExplode(",",$row["screendump"],1);
 982				$img = $this->getReferencesImage($srcDump,$this->conf["singleView."]["showRefList."]["screenDump."]);
 983				$descr = t3lib_div::fixed_lgd(strip_tags($row["description"]),200).
 984							" ".$this->linkSingleRef($this->pi_getLL("more"),$row["uid"],$refPage);
 985
 986				$title = $row["title"];
 987
 988				$url	= 'URL: ';
 989				$url	.= $this->pi_linkToPage(
 990							$this->internal["currentRow"][ 'url' ]
 991							, ( $this->internal["currentRow"][ 'real_url' ] )
 992								? $this->internal["currentRow"][ 'real_url' ]
 993								: $this->internal["currentRow"][ 'url' ]
 994						);
 995				
 996				$items[]='<tr>
 997					<td width="95%" valign="top">
 998						<h3>'.$title.'</h3>
 999						<p>'.$descr.'</p>
1000						<p'.$this->pi_classParam("reflist-url").'>'.$url.'</p>
1001					</td>
1002					<td><img src="clear.gif" width='.$marginToImg.' height=1></td>
1003					<td valign="top">'.$img.'</td>
1004				</tr>
1005				<tr>
1006					<td colspan=3><img src="clear.gif" width=1 height='.$marginBetweenRefs.'></td>
1007				</tr>';
1008			}
1009			if (count($items))	{
1010				$retVal = '<table '.$this->conf["singleView."]["showRefList."]["tableParams"].'>'.implode("",$items).'</table>';
1011			} else {
1012				$retVal = '<p>Currently no references is available for this consultancy.</p>';
1013			}
1014			$retVal = '<h2>References:</h2>'.$retVal;
1015			$retVal = '<div'.$this->pi_classParam("reflist").'>'.$retVal.'</div>';
1016			return $retVal;
1017		} else {
1018			return '<font color="red">Sorry, the references could not be listed, because the reference plugin is not enabled</font>';
1019		}
1020	}
1021
1022	/**
1023	 * Wraps the $str in a link to a single display of the record.
1024	 */	
1025	function linkSingleRef($str,$uid,$refPage)	{
1026		if ($refPage)	{
1027			$this->pi_tmpPageId=$refPage;
1028			
1029			$str = $this->pi_linkTP($str,array("tx_t3references_pi1[showUid]" => $uid),1);
1030		}
1031		$this->pi_tmpPageId=0;
1032		return $str;
1033	}
1034	
1035	/**
1036	 * Returns the list of items.
1037	 */	
1038	function pi_list_makelist($res)	{
1039			// Make list table header:
1040		$tRows=array();
1041		$this->internal["currentRow"]="";
1042		$tRows[]=$this->pi_list_header();
1043
1044			// Make list table rows
1045		$c=0;
1046		while($this->internal["currentRow"] = mysql_fetch_assoc($res))	{
1047			$tRows[]=$this->pi_list_row_2($c);
1048			$c++;
1049		}
1050
1051		$out = '<DIV'.$this->pi_classParam("listrow").'><table>'.implode("",$tRows).'</table></DIV>';
1052		return $out;
1053	}
1054
1055	/**
1056	 * Displays the consultancy list:
1057	 */
1058	function pi_list_row_2($c)	{
1059		$editPanel = $this->pi_getEditPanel();
1060		if ($editPanel)	$editPanel="<TD>".$editPanel."</TD>";
1061		return '<tr'.($c%2 ? $this->pi_classParam("listrow-odd") : "").'>
1062				<td valign="top"><P>'.$this->getFieldContent("title").'</P></td>
1063				<td valign="top"><P>'.$this->getFieldContent("cntry").'</P></td>
1064				<td valign="top"><P>'.$this->getFieldContent("services").'</P></td>
1065				'.($this->showRef && $this->sitesMade?'<td valign="top" align="center"><P>'.$this->getFieldContent("_ref").'</P></td>':'').'
1066				<td valign="top"><P>'.$this->getFieldContent("details").'</P></td>
1067				'.$editPanel.'
1068			</tr>';
1069	}
1070
1071	/**
1072	 * Displays consultancy list header
1073	 */
1074	function pi_list_header()	{
1075		return '<tr'.$this->pi_classParam("listrow-header").'>
1076				<td nowrap><P>'.$this->getFieldHeader("title").'</P></td>
1077				<td nowrap><P>'.$this->getFieldHeader("cntry").'</P></td>
1078				<td nowrap><P>'.$this->getFieldHeader("services").'</P></td>
1079				'.($this->showRef && $this->sitesMade?'<td><P>'.$this->getFieldHeader("references").'</P></td>':'').'
1080				<td><P>'.$this->getFieldHeader("details").'</P></td>
1081			</tr>';
1082	}
1083	
1084	/**
1085	 * Returns processed content for a given fieldname ($fN) from the current row
1086	 * 
1087	 * @param array optional data
1088	 * @return string
1089	 */
1090	function getFieldContent($fN, $data = false )
1091	{
1092		switch($fN) {
1093			case "details":
1094				return $this->pi_list_linkSingle($this->pi_getLL("Details"),$this->internal["currentRow"]["uid"],1,array("lang"=>$this->conf["selectCountryFirst"]?$this->piVars["lang"]:"", "pointer"=>$this->piVars["pointer"]));
1095			break;
1096
1097			case "description":
1098				$content = implode("<br/>",t3lib_div::trimExplode(chr(10),strip_tags(t3lib_div::fixed_lgd($this->internal["currentRow"]["description"],t3lib_div::intInRange($this->conf["truncate_limit"],1,100000,1000),$this->pi_getLL("trunc")),"<b><i><u><strong><em><a>"),1));
1099				return $content;
1100			break;
1101
1102			case "title":
1103				$title = $this->internal["currentRow"]["title"];
1104
1105				if ( 'navigation' == $this->conf[ 'CMD' ] )
1106				{
1107					return $this->pi_linkToPage(
1108						$title
1109						, $this->categoryUrl(
1110							$this->internal[ 'currentRow' ][ 'uid' ]
1111						)
1112					);
1113				}
1114
1115				elseif ( $this->singleViewOn
1116					&& ( $this->internal["currentRow"]["real_url"]
1117						|| $this->internal["currentRow"]["url"]
1118					)
1119					&& $this->conf["linkTitle"]
1120				)
1121				{
1122					// show real_url if it exists
1123					return $this->pi_linkToPage(
1124						// todo image version of title
1125						$title
1126						, ( $this->internal["currentRow"][ 'real_url' ] )
1127							? $this->internal["currentRow"][ 'real_url' ]
1128							: $this->internal["currentRow"][ 'url' ]
1129					);
1130				}
1131
1132				elseif ( $this->singleViewOn && ! $this->conf["linkTitle"] )
1133				{
1134					return $title;
1135				}
1136
1137				else
1138				{
1139					return $this->pi_linkToPage(
1140						$title
1141						, $this->detailsUrl()
1142					);
1143				}
1144			break;
1145
1146			case "cntry":
1147				if (isset($this->countries[$this->internal["currentRow"][$fN]]))	{
1148					return $this->countries[$this->internal["currentRow"][$fN]];
1149				} else {
1150					$cntryRec = $this->pi_getRecord("static_countries",$this->internal["currentRow"][$fN]);
1151					return $cntryRec["cn_short_en"];
1152				}
1153			break;
1154
1155			case "services":
1156				$query = "SELECT uid_foreign FROM tx_t3consultancies_services_mm WHERE uid_local=".intval($this->internal["currentRow"]["uid"])." ORDER BY sorting";
1157				$res = mysql(TYPO3_db,$query);
1158				$services=array();
1159				while($row=mysql_fetch_assoc($res))	{
1160					if (isset($this->categories[$row["uid_foreign"]]))	{
1161						$services[]=$this->categories[$row["uid_foreign"]];
1162					} else {
1163						$catRec = $this->pi_getRecord("tx_t3consultancies_cat",$row["uid_foreign"]);
1164						$services[]=$catRec["title"];
1165					}
1166				}
1167				return implode($this->singleViewOn?', ':'</BR>',$services);
1168			break;
1169
1170			case "_ref":
1171				if ($this->showRef)	{
1172					$value="";
1173					$pLR = $this->pidListForReferences();
1174					if ($pLR)	{
1175						$pLR="pid IN (".$pLR.") AND";
1176					} else $pLR="";
1177					$query = "SELECT count(*) FROM tx_t3references WHERE ".$pLR." dev_rel=".intval($this->internal["currentRow"]["uid"]).
1178						($this->conf["selectedOnly"]	? ' AND tx_t3references.selected' : '').
1179						$this->cObj->enableFields("tx_t3references");
1180					$res = mysql(TYPO3_db,$query);
1181					if ($row=mysql_fetch_assoc($res))	{
1182						$value=$row["count(*)"]?$row["count(*)"]:"-";
1183					}
1184					return $value;
1185				}
1186			break;
1187
1188			case "contact_email":
1189				if ($this->internal["currentRow"][$fN])
1190				{
1191					return $this->pi_linkToPage(
1192						$this->internal["currentRow"][$fN]
1193						, $this->internal["currentRow"][$fN]
1194					);
1195				}
1196			break;
1197
1198			case "fe_owner_user":
1199				$fe_user = $this->pi_getRecord("fe_users",$this->internal["currentRow"][$fN]);
1200				if (is_array($fe_user))	{
1201					return '<strong>'.$fe_user["username"].'</strong>';
1202				} else {
1203					return '<em>'.$this->pi_getLL("NA").'</em>';
1204				}
1205			break;
1206
1207			case 'url':
1208				if ($this->internal['currentRow']['url'])
1209				{
1210					// show real_url if it exists
1211					return $this->pi_linkToPage(
1212						$this->internal["currentRow"][$fN]
1213						, ( $this->internal["currentRow"][ 'real_url' ] )
1214							? $this->internal["currentRow"][ 'real_url' ]
1215							: $this->internal["currentRow"][$fN]
1216					);
1217				}
1218
1219				break;
1220
1221
1222			case 'map_url':
1223				if ( $this->internal['currentRow'][ $fN ] )
1224				{
1225					$name		= $this->pi_getLL( 'map_url' );
1226
1227					$value		= '<a href="'
1228									. $this->internal['currentRow'][$fN]
1229									. '" target="_blank">'
1230									. $name
1231									. '</a>';
1232
1233					return $value;
1234				}
1235
1236				break;
1237
1238			case 'logo':
1239				if ( $this->internal[ 'currentRow' ][ $fN ] )
1240				{
1241					return $this->cObj->imageLinkWrap( $this->getImage(
1242							$this->internal[ 'currentRow' ][ $fN ]
1243							, $this->conf[ 'logoImage.' ]
1244						)
1245						, "uploads/tx_t3consultancies/"
1246							. $this->internal[ 'currentRow' ][ $fN ]
1247						, $this->conf[ 'logoImage.' ]
1248					);
1249				}
1250			break;
1251
1252			case 'featured_logo':
1253				if ( $this->internal[ 'currentRow' ][ $fN ] )
1254				{
1255					return $this->cObj->imageLinkWrap( $this->getImage(
1256							$this->internal[ 'currentRow' ][ $fN ]
1257							, $this->conf[ 'logo.' ]
1258						)
1259						, "uploads/tx_t3consultancies/"
1260							. $this->internal[ 'currentRow' ][ $fN ]
1261						, $this->conf[ 'enlargeImage.' ]
1262					);
1263				}
1264			break;
1265
1266			case 'coupon':
1267				if ( $this->internal[ 'currentRow' ][ $fN ] )
1268				{
1269					return $this->cObj->imageLinkWrap( $this->getImage(
1270							$this->internal[ 'currentRow' ][ $fN ]
1271							, $this->conf[ 'coupon.' ]
1272						)
1273						, "uploads/tx_t3consultancies/"
1274							. $this->internal[ 'currentRow' ][ $fN ]
1275						, $this->conf[ 'coupon.' ]
1276					);
1277				}
1278			break;
1279
1280			case 'address':
1281				return nl2br( $this->internal[ 'currentRow' ][ $fN ] );
1282				break;
1283
1284			case 'city':
1285			default:
1286				return ( $this->internal[ 'currentRow' ][ $fN ] )
1287						? $this->internal[ 'currentRow' ][ $fN ] . ','
1288						: '';
1289			break;
1290
1291			case '':
1292			default:
1293				return $this->internal[ 'currentRow' ][ $fN ];
1294			break;
1295		}
1296
1297		return '';
1298	}
1299	
1300	/**
1301	 * Returns a list of integer-pids for selecting the references belonging to consultancies
1302	 */
1303	function pidListForReferences()	{
1304		$v= implode(",",t3lib_div::intExplode(",",$this->conf["pidList_references"]));
1305		return $v;
1306	}
1307
1308	/**
1309	 * Returns the header text of a field (from locallang)
1310	 */
1311	function getFieldHeader($fN)	{
1312		switch($fN) {
1313			default:
1314				return $this->pi_getLL("listFieldHeader_".$fN,"[".$fN."]");
1315			break;
1316		}
1317	}
1318	
1319	/**
1320	 * Returns an image given by $TSconf
1321	 */
1322    function getImage($filename,$TSconf)    {
1323        list($theImage)=explode(",",$filename);
1324        $TSconf["file"] = "uploads/tx_t3consultancies/".$theImage;
1325
1326        $img = $this->cObj->IMAGE($TSconf);
1327        return $img;
1328    }
1329
1330	/**
1331	 * Returns an image given by $TSconf for references
1332	 */
1333    function getReferencesImage($filename,$TSconf)    {
1334        list($theImage)=explode(",",$filename);
1335        $TSconf["file"] = "uploads/tx_t3references/".$theImage;
1336
1337        $img = $this->cObj->IMAGE($TSconf);
1338        return $img;
1339    }
1340	
1341	/**
1342	 * Makes the editing form for submitting information by frontend users.
1343	 */
1344	function getFe_adminLibConf()	{
1345		$feAConf = $this->conf["fe_adminLib."];
1346		$feAConf["templateContent"]='
1347
1348<!-- ###TEMPLATE_EDIT### -->
1349<h3>Edit "###FIELD_title###"</h3>
1350<table border=0 cellpadding=1 cellspacing=2>
1351<FORM name="tx_t3consultancies_form" method="post" action="###FORM_URL###" enctype="'.$GLOBALS["TYPO3_CONF_VARS"]["SYS"]["form_enctype"].'">
1352'.$this->makeFormFromConfig($feAConf["edit."],$feAConf["table"]).'
1353<tr>
1354	<td></td>
1355	<td></td>
1356	<td>
1357		###HIDDENFIELDS###
1358		<input type="Submit" name="submit" value="'.$this->pi_getLL("feAL_save").'">
1359	</td>
1360</tr>
1361</FORM>
1362</table>
1363<p>&nbsp;</p>
1364<p style="color: red;"><a href="###FORM_URL###&cmd=delete&backURL=###FORM_URL_ENC###&rU=###REC_UID###" onClick="return confirm(\'Are you sure?\');">'.$this->pi_getLL("feAL_delete").'</a></p>
1365<p>&nbsp;</p>
1366<!-- ###TEMPLATE_EDIT### end-->
1367
1368
1369<!-- ###TEMPLATE_EDIT_SAVED### begin-->
1370<h3>'.$this->pi_getLL("Managing_consultancies").'</h3>
1371<p>'.$this->pi_getLL("feAL_contentSaved").'</p>
1372<p>&nbsp;</p>
1373<!-- ###TEMPLATE_EDIT_SAVED### end-->
1374
1375
1376<!-- ###TEMPLATE_CREATE_LOGIN### -->
1377<h3>Create new consultancy entry</h3>
1378<table border=0 cellpadding=1 cellspacing=2>
1379<FORM name="tx_t3consultancies_form" method="post" action="###FORM_URL###" enctype="'.$GLOBALS["TYPO3_CONF_VARS"]["SYS"]["form_enctype"].'">
1380'.$this->makeFormFromConfig($feAConf["create."],$feAConf["table"]).'
1381<tr>
1382	<td></td>
1383	<td></td>
1384	<td>
1385		###HIDDENFIELDS###
1386		<input type="Submit" name="submit" value="'.$this->pi_getLL("feAL_save").'">
1387	</td>
1388</tr>
1389</FORM>
1390</table>
1391<!-- ###TEMPLATE_CREATE_LOGIN### end-->
1392
1393
1394<!-- ###TEMPLATE_CREATE_SAVED### begin-->
1395<h3>'.$this->pi_getLL("Managing_consultancies").'</h3>
1396<p>'.$this->pi_getLL("feAL_contentSaved").'</p>
1397<p>&nbsp;</p>
1398<!-- ###TEMPLATE_CREATE_SAVED### end-->
1399
1400
1401
1402
1403
1404
1405
1406<!-- ###TEMPLATE_DELETE_SAVED### begin-->
1407<h3>'.$this->pi_getLL("Managing_consultancies").'</h3>
1408<p>'.$this->pi_getLL("feAL_deleteSaved").'</p>
1409<p>&nbsp;</p>
1410<!-- ###TEMPLATE_DELETE_SAVED### end-->
1411
1412
1413
1414
1415
1416<!-- ###TEMPLATE_EDITMENU### begin -->
1417	<h3>'.$this->pi_getLL("Managing_consultancies").'</h3>
1418	<p>'.$this->pi_getLL("feAL_listOfItems").'</p>
1419	<p>--</p>
1420		<!-- ###ALLITEMS### begin -->
1421			<!-- ###ITEM### begin -->
1422				<p><a href="###FORM_URL###&rU=###FIELD_uid###&cmd=edit">###FIELD_title###</a></p>
1423			<!-- ###ITEM### end -->
1424		<!-- ###ALLITEMS### end -->
1425	<p>--</p>
1426	<p><a href="###FORM_URL###&cmd=">'.$this->pi_getLL("feAL_createNew").'</a></p>
1427	<p>&nbsp;</p>
1428<!-- ###TEMPLATE_EDITMENU### -->
1429
1430<!-- ###TEMPLATE_EDITMENU_NOITEMS### begin -->
1431	<h3>'.$this->pi_getLL("Managing_consultancies").'</h3>
1432	<p>'.$this->pi_getLL("feAL_noItems").'</p>
1433	<p><a href="###FORM_URL###&cmd=">'.$this->pi_getLL("feAL_createNew").'</a></p>
1434	<p>&nbsp;</p>
1435<!-- ###TEMPLATE_EDITMENU_NOITEMS### -->
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445<!-- ###EMAIL_TEMPLATE_CREATE_SAVED-ADMIN### begin -->
1446New consultancy created.
1447
1448	<!--###SUB_RECORD###-->
1449	Title: ###FIELD_title###
1450	Description: ###FIELD_description###
1451	Contact email: ###FIELD_contact_email###
1452	Contact name: ###FIELD_contact_name###
1453
1454	
1455	Approve:
1456	###THIS_URL######FORM_URL######SYS_SETFIXED_approve###
1457	
1458	Delete:
1459	###THIS_URL######FORM_URL######SYS_SETFIXED_DELETE###
1460	<!--###SUB_RECORD###-->
1461<!-- ###EMAIL_TEMPLATE_CREATE_SAVED-ADMIN### end-->
1462
1463<!-- ###EMAIL_TEMPLATE_EDIT_SAVED-ADMIN### begin -->
1464Consultancy record edited.
1465
1466	<!--###SUB_RECORD###-->
1467	Title: ###FIELD_title###
1468	Description: ###FIELD_description###
1469	Contact email: ###FIELD_contact_email###
1470	Contact name: ###FIELD_contact_name###
1471
1472	
1473	Approve:
1474	###THIS_URL######FORM_URL######SYS_SETFIXED_approve###
1475	
1476	Delete:
1477	###THIS_URL######FORM_URL######SYS_SETFIXED_DELETE###
1478	<!--###SUB_RECORD###-->
1479<!-- ###EMAIL_TEMPLATE_EDIT_SAVED-ADMIN### end-->
1480
1481
1482
1483<!-- ###EMAIL_TEMPLATE_SETFIXED_DELETE### begin -->
1484Consultancy DELETED!
1485
1486<!--###SUB_RECORD###-->
1487Title: ###FIELD_title###
1488Description: ###FIELD_description###
1489
1490Your entry has been deleted by the admin for some reason.
1491
1492- kind regards.
1493<!--###SUB_RECORD###-->
1494<!-- ###EMAIL_TEMPLATE_SETFIXED_DELETE### begin -->
1495
1496
1497
1498<!-- ###EMAIL_TEMPLATE_SETFIXED_approve### begin -->
1499Consultancy approved
1500
1501<!--###SUB_RECORD###-->
1502Title: ###FIELD_title###
1503Description: ###FIELD_description###
1504
1505Your consultancy entry has been approved! 
1506
1507- kind regards.
1508<!--###SUB_RECORD###-->
1509<!-- ###EMAIL_TEMPLATE_SETFIXED_approve### begin -->
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523<!-- ###TEMPLATE_SETFIXED_OK### -->
1524<h3>Setfixed succeeded</h3>
1525Record uid; ###FIELD_uid###
1526<!-- ###TEMPLATE_SETFIXED_OK### end-->
1527
1528<!-- ###TEMPLATE_SETFIXED_OK_DELETE### -->
1529<h3>Setfixed delete record "###FIELD_uid###"</h3>
1530<!-- ###TEMPLATE_SETFIXED_OK_DELETE### end-->
1531
1532<!-- ###TEMPLATE_SETFIXED_FAILED### -->
1533<h3>Setfixed failed!</h3>
1534<p>May happen if you click the setfixed link a second time (if the record has changed since the setfixed link was generated this error will happen!)</p>
1535<!-- ###TEMPLATE_SETFIXED_FAILED### end-->
1536
1537
1538
1539<!-- ###TEMPLATE_AUTH### -->
1540<h3>Authentication failed</h3>
1541<p>Of some reason the authentication failed. </p>
1542<!-- ###TEMPLATE_AUTH### end-->
1543
1544<!-- ###TEMPLATE_NO_PERMISSIONS### -->
1545<h3>No permissions to edit record</h3>
1546<p>Sorry, you did not have permissions to edit the record.</p>
1547<!-- ###TEMPLATE_NO_PERMISSIONS### end-->
1548
1549';
1550
1551		$feAConf["addParams"]=$this->conf["parent."]["addParams"].t3lib_div::implodeArrayForUrl($this->prefixId,$this->piVars,"",1);
1552		return $feAConf;
1553	}
1554	
1555	/**
1556	 * 
1557	 */
1558	function makeFormFromConfig($conf,$table)	{
1559#	debug($table);
1560		$fields = array_unique(t3lib_div::trimExplode(",",$conf["fields"],1));
1561		$reqFields = array_unique(t3lib_div::trimExplode(",",$conf["required"],1));
1562#debug($conf);
1563
1564		$tableRows = array();
1565		while(list(,$fN)=each($fields))	{
1566			$fieldCode = $this->getFormFieldCode($fN,'FE['.$table.']['.$fN.']');
1567			if ($fieldCode)	{
1568				if (in_array($fN,$reqFields))	{
1569					$reqMsg='<!--###SUB_REQUIRED_FIELD_'.$fN.'###--><p style="color: red; font-weight: bold;">'.$this->pi_getLL("feAL_required").'</p><!--###SUB_REQUIRED_FIELD_'.$fN.'###-->';
1570					$reqMarker=$this->pi_getLL("feAL_requiredMark");
1571				} else {
1572					$reqMsg='';
1573					$reqMarker='';
1574				}
1575				
1576				$tableRows[]='<tr>
1577					<td><p>'.$this->pi_getLL("feAL_fN_".$fN,"feAL_fN_".$fN).' '.$reqMarker.'</p></td>
1578					<td><img src="clear.gif" width=10 height=1></td>
1579					<td>'.$reqMsg.$fieldCode.'</td>
1580				</tr>';
1581			}
1582		}
1583		
1584		return implode(chr(10),$tableRows);
1585#	debug($tableRows);
1586	}
1587	function getFormFieldCode($fN,$fieldName)	{
1588		switch($fN)	{
1589			case "description":
1590				return '<textarea name="'.$fieldName.'" rows="5" wrap="virtual" style="width: 300px;"></textarea>';
1591			break;
1592			case "logo":
1593				return '<input type="file" name="'.$fieldName.'[]" style="width: 300px;">';
1594			break;
1595			case "hidden":
1596				return "";
1597			break;
1598			case "cntry":
1599				$opt=array();
1600				$opt[]='<option value="0"></option>';
1601				$query = "SELECT uid,cn_short_en FROM static_countries ORDER BY cn_short_en";
1602				$res = mysql(TYPO3_db,$query);
1603				while($row=mysql_fetch_assoc($res))	{
1604					$opt[]='<option value="'.$row["uid"].'">'.$row["cn_short_en"].'</option>';
1605				}
1606				return '<select name="'.$fieldName.'">'.implode("",$opt).'</select>';
1607			break;
1608			case "services":
1609				$opt=array();
1610				$query = "SELECT uid,title FROM tx_t3consultancies_cat WHERE 1=1 ".
1611							$this->cObj->enableFields("tx_t3consultancies_cat").
1612							" ORDER BY title";
1613				$res = mysql(TYPO3_db,$query);
1614				while($row=mysql_fetch_assoc($res))	{
1615					$opt[]='<option value="'.$row["uid"].'">'.$row["title"].'</option>';
1616				}
1617				return '<select name="'.$fieldName.'[]" multiple size='.count($opt).'>'.implode("",$opt).'</select>';
1618			break;
1619			default:
1620				return '<input type="text" name="'.$fieldName.'" style="width: 300px;">';
1621			break;
1622		}
1623	}
1624	
1625	
1626	function afterSave($content,$conf)	{
1627		$inVar = t3lib_div::GPvar("FE",1);
1628		$services = $inVar["tx_t3consultancies"]["services"];
1629		$uid = $content["rec"]["uid"];
1630		
1631		if (intval($uid)>0 && is_array($services))	{
1632			$query = "DELETE FROM tx_t3consultancies_services_mm WHERE uid_local=".intval($uid);
1633			$res = mysql(TYPO3_db,$query);
1634			
1635			if (is_array($services))	{
1636				reset($services);
1637				while(list($k,$sId)=each($services))	{
1638					$query = "INSERT INTO tx_t3consultancies_services_mm (uid_local,uid_foreign,tablenames,sorting) VALUES (".intval($uid).",".intval($sId).",'',".intval($k).")";
1639					$res = mysql(TYPO3_db,$query);
1640				}
1641			}
1642		}
1643	}
1644	function updateArray($content,$conf)	{
1645		
1646		$content["services"]=array();
1647		$query = "SELECT uid_foreign FROM tx_t3consultancies_services_mm WHERE uid_local=".intval($content["uid"]);
1648		$res = mysql(TYPO3_db,$query);
1649		while($row=mysql_fetch_assoc($res))	{
1650			$content["services"][]=$row["uid_foreign"];
1651		}
1652
1653		unset($content["weight"]);
1654		unset($content["selected"]);
1655
1656		return $content;
1657	}
1658
1659	/**
1660	 * Returns array containing textImage helper
1661	 *
1662	 * @param array conf
1663	 * @return array
1664	 */
1665	function buildTextImageConf( $conf )
1666	{
1667		$title					= $conf[ 'title.' ];
1668		$temp					= array();
1669
1670		$temp['alttext.']['current']		= 1;
1671		$temp['stdWrap.']['wrap']			=
1672								'<div style="border: 0;"> | </div>';
1673		$temp['file']						= 'GIFBUILDER';
1674		$temp['file.']['XY']				= '[10.w],[10.h]';
1675		$temp['file.']['backColor']			= $title[ 'backColor' ];
1676		$temp['file.']['10']				= 'TEXT';
1677		$temp['file.']['10.']['fontColor']	= $title[ 'fontColor' ];
1678		$temp['file.']['10.']['fontFile']	= $title[ 'fontFile' ];
1679		$temp['file.']['10.']['fontSize']	= $title[ 'fontSize' ];
1680		$temp['file.']['10.']['maxWidth']	= 600;
1681		$temp['file.']['10.']['align']		= 'left';
1682		$temp['file.']['10.']['offset']		= '0,17';
1683		$temp['file.']['10.']['niceText']	= 1;
1684
1685		$conf[ 'textImage' ]	= $temp;
1686
1687		return $conf;
1688	}
1689
1690	/**
1691	 * Return string of textual image.
1692	 *
1693	 * @param string image text
1694	 * @return string
1695	 */
1696	function textImage( $text )
1697	{
1698		$this->conf[ 'textImage' ]['file.']['10.']['text']	= $text;
1699
1700		$image					= $this->cObj->cObjGetSingle( 'IMAGE'
1701									, $this->conf[ 'textImage' ]
1702								);
1703
1704		return $image;
1705	}
1706}
1707
1708
1709
1710if (defined("TYPO3_MODE") && $TYPO3_CONF_VARS[TYPO3_MODE]["XCLASS"]["ext/t3consultancies/pi1/class.tx_t3consultancies_pi1.php"])	{
1711	include_once($TYPO3_CONF_VARS[TYPO3_MODE]["XCLASS"]["ext/t3consultancies/pi1/class.tx_t3consultancies_pi1.php"]);
1712}
1713
1714?>