annamaria-daneswood-25102012 /components/com_hotproperty/sef_ext.php

Language PHP Lines 828
MD5 Hash 8e577ba550158a052832f520e7006e84 Estimated Cost $13,625 (why?)
Repository https://bitbucket.org/dgough/annamaria-daneswood-25102012.git View Raw File View Project SPDX
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
<?php
// sef_ext_create.html.php
/**
* Hot Property
*
* This extension will give the SEF advance style URLs to Hot Property
* Place this file (sef_ext_create.php) in the main component directory:
*		/components/com_hotproperty/
*
* For SEF advance > v3.7
*
* @package Hot Property 0.9
* @copyright (C) 2004-2006 Lee Cher Yeong
* @url http://www.Mosets.com/
* @author Lee Cher Yeong <hotproperty@mosets.com>**/

defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' );

# Include the config file
global $mosConfig_absolute_path;
require( $mosConfig_absolute_path.'/administrator/components/com_hotproperty/config.hotproperty.php' );

define("_HP_SEF_PROPERTY", "property");
define("_HP_SEF_COMPANY", "company");
define("_HP_SEF_EMAIL", "email");
define("_HP_SEF_FEATURED", "featured");
define("_HP_SEF_SENDENQUIRY", "sendemail");
define("_HP_SEF_SEARCH", "search");
define("_HP_SEF_ADVSEARCH", "advsearch");
define("_HP_SEF_SEARCHRESULT", "advsearchr");

define("_HP_SEF_VIEWAGENT", "viewagent");

define("_HP_SEF_MANAGEPROP", "manage");
define("_HP_SEF_EDITAGENT", "editagent");
define("_HP_SEF_ADDPROPERTY", "addproperty");
define("_HP_SEF_EDITPROPERTY", "editproperty");

class sef_hotproperty {

	/********************************************************
	* CREATE
	********************************************************/

	/**
	* Creates the SEF advance URL out of the Mambo request
	* Input: $string, string, The request URL (index.php?option=com_example&Itemid=$Itemid)
	* Output: $sefstring, string, SEF advance URL ($var1/$var2/)
	**/
	function create ($string) {
		global $database;
		$sefstring = "";

		# View Property
		if (eregi("&amp;task=view&amp;id=",$string)) {

			$temp = split("&amp;id=", $string);
			$temp = split("&", $temp[1]);
			$property_id = $temp[0];

			if ( is_numeric($property_id) ) {
				$database->setQuery( "SELECT t.name AS type_name, p.name AS property_name FROM #__hp_properties AS p" 
					.	"\nLEFT JOIN #__hp_prop_types AS t ON p.type = t.id"
					.	"\nWHERE p.id = '".$property_id."'"
					.	"\nLIMIT 1"
				);
				$database->loadObject( $row );

				$sefstring .= _HP_SEF_PROPERTY."/".sefencode($row->type_name)."/".sefencode($row->property_name)."/";
			}
		}

		# View Type
		if (eregi("&amp;task=viewtype&amp;id=",$string)) {

			$temp = split("&amp;id=", $string);
			$temp = split("&", $temp[1]);
			$type_id = $temp[0];

			if ( is_numeric($type_id) ) {
				$database->setQuery( "SELECT t.name AS type_name FROM #__hp_prop_types AS t" 
					.	"\nWHERE t.id = '".$type_id."'"
					.	"\nLIMIT 1"
				);
				$database->loadObject( $row );

				$sefstring .= _HP_SEF_PROPERTY."/".sefencode($row->type_name)."/";

				// --- Sort & Order
				$temp = split("&amp;sort=", $string);
				if (!empty($temp[1])) {
					$temp = split("&", $temp[1]);
					$sort = $temp[0];
				} else {
					//$sort='';
					global $hp_default_order;
					$sort = $hp_default_order;
				}

				$temp = split("&amp;order=", $string);
				if (!empty($temp[1])) {
					$temp = split("&", $temp[1]);
					$order = $temp[0];
				} else {
					//$order='';
					global $hp_default_order2;
					$order = $hp_default_order2;
				}

				if ( $sort == '' ) {
//					global $hp_default_order;
//					$sort = $hp_default_order;
				}

				if ( $order == '' ) {
//					global $hp_default_order2;
//					$order = $hp_default_order2;
				}

				// limit & limitstart
				$temp = split("&amp;limit=", $string);
				if(!empty($temp[1])) {
					$temp = split("&", $temp[1]);
					$limit = $temp[0];
				} else {
					global $hp_default_limit;
					$limit = $hp_default_limit;
				}

				$temp = split("&amp;limitstart=", $string);
				if(!empty($temp[1])) {
					$temp = split("&", $temp[1]);
					$limitstart = $temp[0];
				} else {
					$limitstart = 0;
				}

				if ( $limit == '' ) {
//					global $hp_default_limit;
//					$limit = $hp_default_limit;
				}
				if ( $limitstart == '' ) {
//					$limitstart = 0;
				}

				global $hp_default_order,$hp_default_order2,$hp_default_limit;

				if ( $sort <> '' && $order <> '' && !( $sort == $hp_default_order && $order == $hp_default_order2 && $limitstart == 0 && $limit == $hp_default_limit) ) {
					$sefstring .= $sort."/".$order."/";
					if ( $limit <> '' && $limitstart <> '' ) {
						$sefstring .= $limit."/".$limitstart."/";
					}
				}

			} // END IF is_numeric

		}

		# View Featured
		if (eregi("&amp;task=viewfeatured",$string)) {

			$sefstring .= _HP_SEF_PROPERTY."/"._HP_SEF_FEATURED."/";

			// limit
			$temp = split("&amp;limit=", $string);
			if( isset($temp[1]) ) {
				$temp = split("&", $temp[1]);
				$limit = $temp[0];
			} else {
				$limit = '';
			}

			// limitstart
			$temp = split("&amp;limitstart=", $string);
			if( isset($temp[1]) ) {
				$temp = split("&", $temp[1]);
				$limitstart = $temp[0];
			} else {
				$limitstart = '';
			}

			if ( $limit <> '' && $limitstart <> '' ) {
				$sefstring .= $limit."/".$limitstart."/";
			}

		}

		# View Agent
		if (eregi("&amp;task=viewagent&amp;id=",$string)) {

			$temp = split("&amp;id=", $string);
			$temp = split("&", $temp[1]);
			$agent_id = $temp[0];

			// This condition allows listagent module to work so that $agent_id can be a javascript expression.
			if ( is_numeric($agent_id) ) {
				$database->setQuery( "SELECT a.name AS agent_name, c.name AS company_name FROM #__hp_agents AS a" 
					.	"\nLEFT JOIN #__hp_companies AS c ON a.company = c.id"
					.	"\nWHERE a.id = '".$agent_id."'"
					.	"\nLIMIT 1"
				);
				$database->loadObject( $row );
			}

			// Default virtual directory would be: _HP_SEF_COMPANY/company_name/agent_name/.
			// There is an alternative way to represent this as to allow List Agents module to work: _HP_SEF_VIEWAGENT/agent_id
			if ( !is_numeric($agent_id) || count($row) <= 0 ) {
				$sefstring .= _HP_SEF_VIEWAGENT."/".$agent_id;
			} else {
				$sefstring .= _HP_SEF_COMPANY."/".sefencode($row->company_name)."/".sefencode($row->agent_name)."/";
			}


			// limit
			$temp = split("&amp;limit=", $string);
			if( isset($temp[1]) ) {
				$temp = split("&", $temp[1]);
				$limit = $temp[0];
			} else {
				$limit='';
			}

			// limitstart
			$temp = split("&amp;limitstart=", $string);
			if( isset($temp[1]) ) {
				$temp = split("&", $temp[1]);
				$limitstart = $temp[0];
			} else {
				$limitstart='';
			}

			if ( $limit <> '' && $limitstart <> '' ) {
				$sefstring .= $limit."/".$limitstart."/";
			}

		}

		# View Company / View Company Email / Send Company Email
		if ( eregi("&amp;task=viewco&amp;id=",$string) || eregi("&amp;task=viewcoemail&amp;id=",$string) || eregi("&amp;task=sendenquiry&amp;id=",$string) ) {

			$temp = split("&amp;id=", $string);
			$temp = split("&", $temp[1]);
			$company_id = $temp[0];

			// This condition allows listagent module to work so that $agent_id can be a javascript expression.
			if ( is_numeric($company_id) ) {
				$database->setQuery( "SELECT c.name AS company_name FROM #__hp_companies AS c" 
					.	"\nWHERE c.id = '".$company_id."'"
					.	"\nLIMIT 1"
				);
				$database->loadObject( $row );
			}
			
			# View Company
			if ( eregi("&amp;task=viewco&amp;id=",$string) ) {

				// Default virtual directory would be: _HP_SEF_COMPANY/company_name/.
				// There is an alternative way to represent this as to allow List Companies module to work: _HP_SEF_COMPANY/company_id
				if ( !is_numeric($company_id) || count($row) <= 0 ) {
					$sefstring .= _HP_SEF_COMPANY."/".$company_id;
				} else {
					$sefstring .= _HP_SEF_COMPANY."/".sefencode($row->company_name)."/";
				}

				// limit
				$temp = split("&amp;limit=", $string);
				if( isset($temp[1]) ) {
					$temp = split("&", $temp[1]);
					$limit = $temp[0];
				} else {
					$limit='';
				}

				// limitstart
				$temp = split("&amp;limitstart=", $string);
				if( isset($temp[1]) ) {
					$temp = split("&", $temp[1]);
					$limitstart = $temp[0];
				} else {
					$limitstart = '';
				}

				if ( $limit <> '' && $limitstart <> '' ) {
					$sefstring .= $limit."/".$limitstart."/";
				}

			# View Company Email
			} elseif ( eregi("&amp;task=viewcoemail&amp;id=",$string) ) {
				$sefstring .= _HP_SEF_EMAIL."/".sefencode($row->company_name)."/";

			# Send Enquiry Email
			} elseif (eregi("&amp;task=sendenquiry&amp;id=",$string) ) {
				$sefstring .= _HP_SEF_SENDENQUIRY."/".$company_id."/"; // Sendenquiry does not use this ID to determine whether this is directed to company or agent, the form has a hidden field called 'sbj' to distinguish this.
			}

		}

		# View Agent Email
		if ( eregi("&amp;task=viewagentemail&amp;id=",$string) ) {

			$temp = split("&amp;id=", $string);
			$temp = split("&", $temp[1]);
			$agent_id = $temp[0];

			if ( is_numeric($agent_id) ) {
				$database->setQuery( "SELECT a.name AS agent_name, c.name AS company_name FROM #__hp_agents AS a" 
					.	"\nLEFT JOIN #__hp_companies AS c ON a.company = c.id"
					.	"\nWHERE a.id = '".$agent_id."'"
					.	"\nLIMIT 1"
				);
				$database->loadObject( $row );
				
				$sefstring .= _HP_SEF_EMAIL."/".sefencode($row->company_name)."/".sefencode($row->agent_name)."/";
			}
		}

		# Standard Search
		if (eregi("&amp;task=search",$string)) {

			global $mosConfig_absolute_path, $sufix;
			require( $mosConfig_absolute_path.'/administrator/components/com_hotproperty/config.hotproperty.php' );

			// search string
			$temp = split("&amp;search=", $string);
			$temp = split("&", $temp[1]);
			// This condition prevents url encoding to be performed on javascript expression in standard search form.
			if ( strpos(trim($temp[0]), "encodeURI(document.searchfrm.search.value)") >= 0 || 
						strpos(trim($temp[0]), "encodeURI(document.searchfrm_mod.search.value)") >= 0 ) {
				$search	= $temp[0];
			} else {
				$search	= urlencode($temp[0]);
			}

			// type
			$temp = split("&amp;type=", $string);
			$temp = split("&", $temp[1]);
			$type	= $temp[0];

			// limit
			$temp = split("&amp;limit=", $string);
			$temp = split("&", $temp[1]);
			$limit = $temp[0];
			if ( $limit == '' ) {
				$limit = $hp_default_limit_search;
			}

			// limitstart
			$temp = split("&amp;limitstart=", $string);
			$temp = split("&", $temp[1]);
			$limitstart = $temp[0];
			if ( $limitstart == '' ) {
				$limitstart = 0;
			}

			$sefstring .= _HP_SEF_SEARCH."/".$type."/".$limit."/".$limitstart."/".$search;

			if ( !empty($sufix) ) {
				$sefstring .= "/";
			}

		}

		# Advanced Search
		if (eregi("&amp;task=advsearch",$string)) {

			$sefstring .= _HP_SEF_ADVSEARCH."/";

		}

		# Advanced Search Result
		if (eregi("&amp;task=asearch",$string)) {

			$sefstring .= _HP_SEF_SEARCHRESULT."/";

			// search_id
			$temp = split("&amp;search_id=", $string);
			if ( isset($temp[1]) ) {
				$temp = split("&", $temp[1]);
				$search_id = $temp[0];
			} else {
				$search_id = '';
			}

			// limit
			$temp = split("&amp;limit=", $string);
			if ( isset($temp[1]) ) {
				$temp = split("&", $temp[1]);
				$limit = $temp[0];
			} else {
				$limit = '';
			}

			// limitstart
			$temp = split("&amp;limitstart=", $string);
			if ( isset($temp[1]) ) {
				$temp = split("&", $temp[1]);
				$limitstart = $temp[0];
			} else {
				$limitstart = '';
			}

			if ( $search_id <> '' ) {
				$sefstring .= $search_id ."/";

				if ( $limit <> '' && $limitstart <> '' ) {
					$sefstring .= $limit ."/". $limitstart ."/";
				} // End if
			} // End if

		}

		# Manage Property
		if (eregi("&amp;task=manageprop",$string)) {

			$sefstring .= _HP_SEF_MANAGEPROP."/";

			// limit
			$temp = split("&amp;limit=", $string);
			$temp = split("&", $temp[1]);
			$limit = $temp[0];

			// limitstart
			$temp = split("&amp;limitstart=", $string);
			$temp = split("&", $temp[1]);
			$limitstart = $temp[0];

			if ( $limit <> '' && $limitstart <> '' ) {
				$sefstring .= $limit ."/". $limitstart ."/";
			}

		}

		# Edit Agent
		if (eregi("&amp;task=editagent",$string)) {

			$sefstring .= _HP_SEF_EDITAGENT."/";

		}

		# Add Property
		if (eregi("&amp;task=addprop",$string)) {

			$sefstring .= _HP_SEF_ADDPROPERTY."/";

		}

		# Edit Property
		if (eregi("&amp;task=editprop",$string)) {

			$temp = split("&amp;id=", $string);
			$temp = split("&", $temp[1]);
			$id = $temp[0];

			// Using IDs instead of Property name to aviod conflicts with same property name.
			$sefstring .= _HP_SEF_EDITPROPERTY."/".$id."/";

		}

		return $sefstring;
	}

	/********************************************************
	* REVERT
	********************************************************/

	/**
	* Reverts to the Mambo query string out of the SEF advance URL
	* Input:
	*    $url_array, array, The SEF advance URL split in arrays (first custom virtual directory beginning at $pos+1)
	*    $pos, int, The position of the first virtual directory (component)
	* Output: $QUERY_STRING, string, Mambo query string (var1=$var1&var2=$var2)
	*    Note that this will be added to already defined first part (option=com_example&Itemid=$Itemid)
	**/
	function revert ($url_array, $pos) {
		global $database;

		// define all variables you pass as globals
//		global $var1, $var2;
 		// Examine the SEF advance URL and extract the variables building the query string
		$QUERY_STRING = "";

		if ( isset($url_array[$pos+2]) ) {
			switch($url_array[$pos+2]) {
				
				# Types & Properties
				case _HP_SEF_PROPERTY:

					# View Property
					if (isset($url_array[$pos+4]) && $url_array[$pos+4]!="" && $url_array[$pos+5]=="") {
						$type_name = sefdecode($url_array[$pos+3]);
						$property_name = sefdecode($url_array[$pos+4]);
						
						$database->setQuery( "SELECT p.id FROM #__hp_properties AS p "
							.	"\nLEFT JOIN #__hp_prop_types AS t ON t.id = p.type"
							.	"\nWHERE p.name ='".$property_name."' AND t.name ='".$type_name."' LIMIT 1" 
							);
						$property_id = $database->loadResult();
						
						$_GET['task'] = "view";
						$_REQUEST['task'] = "view";
						$_GET['id'] = $property_id;
						$_REQUEST['id'] = $property_id;
						$QUERY_STRING .= "&task=view&id=$property_id";

					} elseif ( $url_array[$pos+3] == _HP_SEF_FEATURED ) {
					# View Featured
					
						$_GET['task'] = "viewfeatured";
						$_REQUEST['task'] = "viewfeatured";
						$QUERY_STRING .= "&task=viewfeatured";

						$limit = $url_array[$pos+4];
						if ( isset($url_array[$pos+5]) ) {
							$limitstart = $url_array[$pos+5];
						} else {
							$limitstart = 0;
						}

						// Limit & Limit Start
						if ( $limit <> '' && $limitstart <> '' ) {

							$_GET['limit'] = $limit;
							$_REQUEST['limit'] = $limit;
							$_GET['limitstart'] = $limitstart;
							$_REQUEST['limitstart'] = $limitstart;

							$QUERY_STRING .= "&limit=$limit&limitstart=$limitstart";
						} // End if

					} else {
					# View Type

						$type_name = sefdecode($url_array[$pos+3]);
						
						$database->setQuery( "SELECT t.id FROM #__hp_prop_types AS t WHERE t.name ='".$type_name."' LIMIT 1" );
						$type_id = $database->loadResult();
						
						$_GET['task'] = "viewtype";
						$_REQUEST['task'] = "viewtype";
						$_GET['id'] = $type_id;
						$_REQUEST['id'] = $type_id;
						$QUERY_STRING .= "&task=viewtype&id=$type_id";

						if( isset($url_array[$pos+4]) ) $sort = $url_array[$pos+4];
						if( isset($url_array[$pos+5]) ) $order = $url_array[$pos+5];
						if( isset($url_array[$pos+6]) ) $limit = $url_array[$pos+6];
						if( isset($url_array[$pos+7]) ) $limitstart = $url_array[$pos+7];

						// Sort & Order
						if ( $sort <> '' && $order <> '' ) {

							$_GET['sort'] = $sort;
							$_REQUEST['sort'] = $sort;
							$_GET['order'] = $order;
							$_REQUEST['order'] = $order;
							$QUERY_STRING .= "&sort=$sort&order=$order";
							
							// Limit & Limit Start
							if ( $limit <> '' && $limitstart <> '' ) {

								$_GET['limit'] = $limit;
								$_REQUEST['limit'] = $limit;
								$_GET['limitstart'] = $limitstart;
								$_REQUEST['limitstart'] = $limitstart;

								$QUERY_STRING .= "&limit=$limit&limitstart=$limitstart";
							} // End if

						} // End if

					}
					break;

				# Companies & Agents
				
				// _HP_SEF_COMPANY/company_name/agent_name/

				case _HP_SEF_COMPANY:

					# View Agent
					// _HP_SEF_COMPANY/company_name/agent_name/

					if (isset($url_array[$pos+2]) && isset($url_array[$pos+3]) && isset($url_array[$pos+4]) && $url_array[$pos+2]!="" && (
							($url_array[$pos+3] == '' && $url_array[$pos+4] == '') || ($url_array[$pos+3] <> '' && $url_array[$pos+4] <> '')
						) ) {
						$agent_name = sefdecode($url_array[$pos+4]);
						$company_name = sefdecode($url_array[$pos+3]);
						
						$database->setQuery( "SELECT a.id FROM (#__hp_agents AS a, #__hp_companies AS c) "
							.	"\n WHERE c.id=a.company AND a.name ='".$agent_name."' AND c.name = '".$company_name."' LIMIT 1" );
						$agent_id = $database->loadResult();
						
						$_GET['task'] = "viewagent";
						$_REQUEST['task'] = "viewagent";
						$_GET['id'] = $agent_id;
						$_REQUEST['id'] = $agent_id;
						$QUERY_STRING .= "&task=viewagent&id=$agent_id";

						// Limit & Limit Start
						$limit = $url_array[$pos+5];
						$limitstart = $url_array[$pos+6];

						if ( $limit <> '' && $limitstart <> '' ) {

							$_GET['limit'] = $limit;
							$_REQUEST['limit'] = $limit;
							$_GET['limitstart'] = $limitstart;
							$_REQUEST['limitstart'] = $limitstart;

							$QUERY_STRING .= "&limit=$limit&limitstart=$limitstart";
						}

					} else {
					# View Company
						// _HP_SEF_COMPANY/company_name/
						// _HP_SEF_COMPANY/company_id
						$company_name = sefdecode($url_array[$pos+3]);
						
						$database->setQuery( "SELECT c.id FROM #__hp_companies AS c WHERE c.name ='".$company_name."' LIMIT 1" );
						$company_id = $database->loadResult();
						
						if ( $company_id == '' && is_numeric($company_name) )  {
							$company_id = $company_name;
						}

						$_GET['task'] = "viewco";
						$_REQUEST['task'] = "viewco";
						$_GET['id'] = $company_id;
						$_REQUEST['id'] = $company_id;
						$QUERY_STRING .= "&task=viewco&id=$company_id";

						// Limit & Limit Start
						if(isset($url_array[$pos+4])) $limit = $url_array[$pos+4];
						if(isset($url_array[$pos+5])) $limitstart = $url_array[$pos+5];

						if ( $limit <> '' && $limitstart <> '' ) {

							$_GET['limit'] = $limit;
							$_REQUEST['limit'] = $limit;
							$_GET['limitstart'] = $limitstart;
							$_REQUEST['limitstart'] = $limitstart;

							$QUERY_STRING .= "&limit=$limit&limitstart=$limitstart";
						}

					}
					break;
				# View Agent
				// _HP_SEF_VIEWAGENT/agent_id
				case _HP_SEF_VIEWAGENT:
					$agent_id = sefdecode($url_array[$pos+3]);
					
					$_GET['task'] = "viewagent";
					$_REQUEST['task'] = "viewagent";
					$_GET['id'] = $agent_id;
					$_REQUEST['id'] = $agent_id;
					$QUERY_STRING .= "&task=viewagent&id=$agent_id";

					break;

				case _HP_SEF_EMAIL:

					# View Company Email
					if ( $url_array[$pos+4] == '' ) {

						$company_name = sefdecode($url_array[$pos+3]);
						
						$database->setQuery( "SELECT c.id FROM #__hp_companies AS c WHERE c.name ='".$company_name."' LIMIT 1" );
						$company_id = $database->loadResult();
						
						$_GET['id'] = $company_id;
						$_REQUEST['id'] = $company_id;
						$_GET['task'] = "viewcoemail";
						$_REQUEST['task'] = "viewcoemail";
						$QUERY_STRING .= "&task=viewcoemail&id=$company_id";

					# View Agent Email
					} else {
						$company_name = sefdecode($url_array[$pos+3]);
						$agent_name = sefdecode($url_array[$pos+4]);

						$database->setQuery( "SELECT a.id FROM #__hp_agents AS a"
							.	"\nLEFT JOIN #__hp_companies AS c ON c.id = a.company"
							.	"\nWHERE c.name ='".$company_name."'"
								.	"\nAND a.name ='".$agent_name."'"
							.	"\nLIMIT 1" 
							);
						$agent_id = $database->loadResult();

						$_GET['id'] = $agent_id;
						$_REQUEST['id'] = $agent_id;
						$_GET['task'] = "viewagentemail";
						$_REQUEST['task'] = "viewagentemail";
						$QUERY_STRING .= "&task=viewagentemail&id=$agent_id";
					}

					break;

				case _HP_SEF_SENDENQUIRY:

					# Send Enquiry Email

					$company_id = sefdecode($url_array[$pos+3]);
					
					$_GET['id'] = $company_id;
					$_REQUEST['id'] = $company_id;
					
					$_GET['task'] = "sendenquiry";
					$_REQUEST['task'] = "sendenquiry";
					$QUERY_STRING .= "&task=sendenquiry&id=$company_id";

					break;

				case _HP_SEF_SEARCH:
					# Standard Search

					$_GET['task'] = "search";
					$_REQUEST['task'] = "search";
					$_GET['type'] = $url_array[$pos+3];
					$_REQUEST['type'] = $url_array[$pos+3];
					$_GET['limit'] = $url_array[$pos+4];
					$_REQUEST['limit'] = $url_array[$pos+4];
					$_GET['limitstart'] = $url_array[$pos+5];
					$_REQUEST['limitstart'] = $url_array[$pos+5];
					$_GET['search'] = urldecode($url_array[$pos+6]);
					$_REQUEST['search'] = urldecode($url_array[$pos+6]);

					$QUERY_STRING .= "&task=search&type=".$url_array[$pos+3]."&limit=".$url_array[$pos+4]."&limitstart=".$url_array[$pos+5]."&search=".urldecode($url_array[$pos+6]);

					break;

				case _HP_SEF_ADVSEARCH:
					# Advanced Search

					$_GET['task'] = "advsearch";
					$_REQUEST['task'] = "advsearch";
					$QUERY_STRING .= "&task=advsearch";
					break;
				
				case _HP_SEF_SEARCHRESULT:
					# Advanced Search Result

					$_GET['task'] = "asearch";
					$_REQUEST['task'] = "asearch";
					$QUERY_STRING .= "&task=asearch";

					// search_id
					$search_id = $url_array[$pos+3];

					// Limit & Limit Start
					if( isset($url_array[$pos+4]) ) $limit = $url_array[$pos+4];
					if( isset($url_array[$pos+5]) ) $limitstart = $url_array[$pos+5];

					if ( $search_id <> '' ) {
						$_GET['search_id'] = $search_id;
						$_REQUEST['search_id'] = $search_id;

						$QUERY_STRING .= "&search_id=$search_id";

						if ( $limit <> '' && $limitstart <> '' ) {

							$_GET['limit'] = $limit;
							$_REQUEST['limit'] = $limit;
							$_GET['limitstart'] = $limitstart;
							$_REQUEST['limitstart'] = $limitstart;

							$QUERY_STRING .= "&limit=$limit&limitstart=$limitstart";
						}

					}
					break;
				
				case _HP_SEF_MANAGEPROP:
					# Manage Property
					
					$_GET['task'] = "manageprop";
					$_REQUEST['task'] = "manageprop";
					$QUERY_STRING .= "&task=manageprop";

					// Limit & Limit Start
					$limit = $url_array[$pos+3];
					$limitstart = $url_array[$pos+4];

					if ( $limit <> '' && $limitstart <> '' ) {

						$_GET['limit'] = $limit;
						$_REQUEST['limit'] = $limit;
						$_GET['limitstart'] = $limitstart;
						$_REQUEST['limitstart'] = $limitstart;

						$QUERY_STRING .= "&limit=$limit&limitstart=$limitstart";
					}

					break;

				case _HP_SEF_EDITAGENT:
					# Edit Agent
					$_GET['task'] = "editagent";
					$_REQUEST['task'] = "editagent";
					$QUERY_STRING .= "&task=editagent";
					break;

				case _HP_SEF_ADDPROPERTY:
					# Add Property
					$_GET['task'] = "addprop";
					$_REQUEST['task'] = "addprop";
					$QUERY_STRING .= "&task=addprop";
					break;

				case _HP_SEF_EDITPROPERTY:
					# Edit Property

					$id = sefdecode($url_array[$pos+3]);
					
					$_GET['id'] = $id;
					$_REQUEST['id'] = $id;
					$_GET['task'] = "editprop";
					$_REQUEST['task'] = "editprop";
					$QUERY_STRING .= "&task=editprop&id=$id";
					break;
			}
		}

		return $QUERY_STRING;
	}

}
?>
Back to Top