| 1 |
<?php |
| 2 |
/* |
| 3 |
Author: Fakhri Alsadi |
| 4 |
Date: 16-7-2010 |
| 5 |
Contact: www.clogica.com info@clogica.com mobile: +972599322252 |
| 6 |
*/ |
| 7 |
|
| 8 |
///@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ |
| 9 |
///@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ |
| 10 |
//// class dropdown @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ |
| 11 |
/* |
| 12 |
A simple class to create Drop down lists easily using PHP |
| 13 |
|
| 14 |
---------------------------------------------------------- |
| 15 |
example: |
| 16 |
---------------------------------------------------------- |
| 17 |
$drop = new dropdown('gendar'); |
| 18 |
$drop->add('mail','mail');` |
| 19 |
$drop->add('femail','femail'); |
| 20 |
$drop->dropdown_print(); |
| 21 |
$drop->select('femail'); |
| 22 |
|
| 23 |
|
| 24 |
////////////////////////////// |
| 25 |
|
| 26 |
$drop = new dropdown('gendar'); |
| 27 |
$drop->data_bind('data_status'); |
| 28 |
$drop->dropdown_print(); |
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
*/ |
| 33 |
////@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ |
| 34 |
|
| 35 |
if(!class_exists('dropdown')){ |
| 36 |
class dropdown{ |
| 37 |
|
| 38 |
var $name='drop'; |
| 39 |
var $options= array(); |
| 40 |
var $class=''; |
| 41 |
var $onchange=''; |
| 42 |
|
| 43 |
function __construct($str,$class='',$onchange='') |
| 44 |
{ |
| 45 |
$this->name=$str; |
| 46 |
|
| 47 |
if($class!='') |
| 48 |
$this->class=$class; |
| 49 |
|
| 50 |
if($onchange!='') |
| 51 |
$this->onchange=$onchange; |
| 52 |
|
| 53 |
} |
| 54 |
|
| 55 |
function add($name,$value) |
| 56 |
{ |
| 57 |
//$this->options=$this->options. "<option value='$value'>$name</option>"; |
| 58 |
|
| 59 |
$this->options[] = array( |
| 60 |
'key'=>esc_html($value), |
| 61 |
'name'=>esc_html($name) |
| 62 |
); |
| 63 |
|
| 64 |
} |
| 65 |
|
| 66 |
public function dropdown_print() |
| 67 |
{ |
| 68 |
?> |
| 69 |
<select size='1' name='<?php esc_attr_e($this->name);?>' <?php if($this->onchange != ''){?> onchange='<?php echo esc_attr_e($this->onchange);?>' <?php } ?> id='<?php esc_attr_e($this->name);?>'> |
| 70 |
<?php |
| 71 |
foreach($this->options as $options){ |
| 72 |
?> |
| 73 |
<option value="<?php esc_html_e($options['key']);?>"><?php esc_html_e($options['name']);?></option> |
| 74 |
<?php |
| 75 |
} |
| 76 |
?> |
| 77 |
</select> |
| 78 |
<?php |
| 79 |
|
| 80 |
} |
| 81 |
|
| 82 |
public function select($str) |
| 83 |
{ |
| 84 |
?> |
| 85 |
<script>document.getElementById('<?php echo esc_js($this->name);?>').value='<?php echo esc_js($str);?>'</script> |
| 86 |
<?php |
| 87 |
} |
| 88 |
|
| 89 |
function data_bind($tbl,$name="name",$id="id",$where="",$order="",$limit="") |
| 90 |
{ |
| 91 |
global $wpdb; |
| 92 |
$res = $wpdb->get_results("select $id,$name from PREFIX_$tbl $where $order $limit ", ARRAY_A); |
| 93 |
foreach ( $res as $ar){ |
| 94 |
$this->add($ar[1],$ar[0]); |
| 95 |
} |
| 96 |
|
| 97 |
|
| 98 |
} |
| 99 |
|
| 100 |
}} |
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
?> |