<?php
/**
 * @version		1.3 mod_annonces - petites annonces $
 * @package		simple_ads_-_petites_annonces
 * @copyright	Copyright (c) 2011 - All rights reserved.
 * @license		GNU/GPL
 * @author		Anthony JULOU
 * @author mail	ajulou@yahoo.fr
 *
 **/

defined('JPATH_BASE') or die();


 





class JElementSQLListCategorie extends JElement


{


         var    $_name = 'sqllistategorie';


 


        function fetchElement($name, $value, &$node, $control_name)


        {


                // Base name of the HTML control.


                $ctrl  = $control_name .'['. $name .']';


 


                // Construct the various argument calls that are supported.


                $attribs       = ' ';


                if ($v = $node->attributes( 'size' )) {


                        $attribs       .= 'size="'.$v.'"';


                }


                if ($v = $node->attributes( 'class' )) {


                        $attribs       .= 'class="'.$v.'"';


                } else {


                        $attribs       .= 'class="inputbox"';


                }


                


                // Query items for list.


                                $db                    = & JFactory::getDBO();


                                $db->setQuery($node->attributes('sql'));


                                $key = ($node->attributes('key_field') ? $node->attributes('key_field') : 'value');


                                $val = ($node->attributes('value_field') ? $node->attributes('value_field') : $name);


 


                $options = array ();


                foreach ($node->children() as $option)


                {


                        $options[]= array($key=> $option->attributes('value'),$val => $option->data());


                }


 


                $rows = $db->loadAssocList();


                foreach ($rows as $row){


                        $options[]=array($key=>$row[$key],$val=>$row[$val]);


                }


                if($options){


                        return JHTML::_('select.genericlist',$options, $ctrl, $attribs, $key, $val, $value, $control_name.$name);


                }


        }


}


