<?php

/**
* @version 2.7.11
* @package Joomla 1.5
* @subpackage DT Register
* @copyright Copyright (C) 2006 DTH Development
* @copyright contact dthdev@dthdevelopment.com
* @license http://www.gnu.org/copyleft/gpl.html GNU/GPL
*/

class JElementLocationlist extends JElement {
  
  var $_name = 'Locationlist ';
  function fetchElement($name, $value, &$node, $control_name) {
     
		$db = &JFactory::getDBO();

		$class = $node->attributes('class');

		if (!$class) {

			$class = "inputbox";

		}

		$query = "SELECT  *

    FROM #__dtregister_locations  order by  name";

		$db->setQuery($query);

		$rows1 = $db->loadObjectList();
        
		$options=array();
		$options[]=JHTML::_('select.option',"","Select Location");
       
        foreach ($rows1 as $v )
		{
			$options[]= JHTML::_('select.option',$v->id,$v->name);
		}
		
		return JHTML::_('select.genericlist', $options,$control_name.'['.$name.']','',"value","text",$value);
		foreach( $options as $option ) {

			if(is_array( $value) ) {

				if( in_array( $option->id, $value ) ) {

					$result .= '<option selected="true" value="'.$option->id.'" >'.$option->title.'</option>';

				} else {

					$result .= '<option value="'.$option->id.'" >'.$option->title.'</option>';

				}

			} elseif ( $value ) {

				if( $value == $option->id ) {

					$result .= '<option selected="true" value="'.$option->id.'" >'.$option->title.'</option>';

				} else {

					$result .= '<option value="'.$option->id.'" >'.$option->title.'</option>';

				}

			} elseif ( !( $value ) ) {

				$result .= '<option value="'.$option->id.'" >'.$option->title.'</option>';

			}

		}

		$result .= '</select>';

		return $result;

  }
  
}
?>