<?php
    
class attr_modulelist extends attr {
    function getDBType() {
    	return "text";
    }

    function render_input() {
		$templ = $this->getAttrTempl();
		$val = $this->getCurVal();
		list($dir, $exts) = explode(";", $templ );
		$ext = explode(',', $exts );

		$file_list = scandir( _ENGINE_DIR . $dir );

		$html = '<select class="form-control" name="' . $this->attr_name.'" class="select" id="' . $this->attr_name.'">';
		if (!$this->getAttrSetting('mand') ) {
		$html .= '<option value="">[---]</option>';
		}
		sort($file_list);	
		foreach( $file_list as $v ) {
			$e = substr($v,-4);
			if (in_array($e, $ext ) ){
				if ( $v == $val ) {
					$html .= '<option value="'.$v.'" selected>'.$v.'</option>';
				} else {
					$html .= '<option value="'.$v.'">'.$v.'</option>';
				}
			}
		}

		$html .= '</select>';
		return $html;
    }

    function render_text( $crop = false ) {
    	$val = $this->getCurVal();
    	if ( $crop ) {
	    	$val = substr(strip_tags($val),0, 100);
    	}
    	return $val;
    }


}

?>