1 | <?php |
---|
2 | |
---|
3 | if( ! function_exists( 'yes_no_radio_option' ) ) : |
---|
4 | function yes_no_radio_option($option_name,$label,$value,$yes = '',$no= ''){ |
---|
5 | if (empty( $yes )) $yes = _YES ; |
---|
6 | if (empty( $no )) $no = _NO ; |
---|
7 | $form = $label.' : '; |
---|
8 | if ($value){ |
---|
9 | $form .= "<input type='radio' name='". $option_name . "' value='1' checked='checked' />" . $yes. "; " ; |
---|
10 | $form .= "<input type='radio' name='". $option_name . "' value='0' />". $no ; |
---|
11 | }else{ |
---|
12 | $form .= "<input type='radio' name='". $option_name . "' value='1' />" . $yes. "; " ; |
---|
13 | $form .= "<input type='radio' name='". $option_name . "' value='0' checked='checked' />". $no ; |
---|
14 | } |
---|
15 | return $form; |
---|
16 | |
---|
17 | } |
---|
18 | endif; |
---|
19 | |
---|
20 | if(!function_exists("dropdown_cats_options")): |
---|
21 | function dropdown_cats_options($sort_column = 'ID', $sort_order = 'asc', $selected=array()) |
---|
22 | { |
---|
23 | $mydirpath = dirname(dirname(__FILE__)); |
---|
24 | $mydirname = basename( dirname( dirname( __FILE__ ) ) ) ; |
---|
25 | if ($mydirname == 'wordpress'){ |
---|
26 | $wp_prefix = 'wp_'; |
---|
27 | } else { |
---|
28 | $wp_prefix = $mydirname . '_'; |
---|
29 | } |
---|
30 | $xoopsDB =& Database::getInstance(); |
---|
31 | $myts =& MyTextSanitizer::getInstance(); |
---|
32 | $selected = is_array($selected)?$selected:array($selected); |
---|
33 | $sort_column = 'cat_'.$sort_column; |
---|
34 | include $mydirpath.'/wp-includes/version.php'; |
---|
35 | if ($wp_db_version < 6124) { |
---|
36 | $db_xpress_categories = $xoopsDB->prefix($wp_prefix . 'categories'); |
---|
37 | $query = " |
---|
38 | SELECT cat_ID, cat_name, category_nicename,category_parent |
---|
39 | FROM $db_xpress_categories |
---|
40 | WHERE cat_ID > 0 |
---|
41 | "; |
---|
42 | $query .= " ORDER BY $sort_column $sort_order"; |
---|
43 | |
---|
44 | } else { |
---|
45 | $db_xpress_terms = $xoopsDB->prefix($wp_prefix . 'terms'); |
---|
46 | $db_xpress_term_taxonomy = $xoopsDB->prefix($wp_prefix . 'term_taxonomy'); |
---|
47 | $query = " |
---|
48 | SELECT $db_xpress_terms.term_id as cat_ID , $db_xpress_terms.name as cat_name , $db_xpress_term_taxonomy.taxonomy |
---|
49 | FROM $db_xpress_terms LEFT JOIN $db_xpress_term_taxonomy ON $db_xpress_terms.term_id = $db_xpress_term_taxonomy.term_id |
---|
50 | WHERE $db_xpress_term_taxonomy.taxonomy = 'category' |
---|
51 | "; |
---|
52 | $query .= " ORDER BY $sort_column $sort_order"; |
---|
53 | } |
---|
54 | $res = $xoopsDB->query($query, 0, 0); |
---|
55 | if ($res !== false){ |
---|
56 | while($row = $xoopsDB->fetchArray($res)){ |
---|
57 | $cat_name = $row['cat_name']; |
---|
58 | $cat_ID = $row['cat_ID']; |
---|
59 | echo "\t<option value=\"".$cat_ID."\""; |
---|
60 | if (in_array($cat_ID, $selected)) |
---|
61 | echo ' selected="selected"'; |
---|
62 | echo '>'; |
---|
63 | echo $myts->htmlspecialchars($cat_name); |
---|
64 | echo "</option>\n"; |
---|
65 | } |
---|
66 | } |
---|
67 | return; |
---|
68 | } |
---|
69 | endif; |
---|
70 | |
---|
71 | if(!function_exists("categorie_select")): |
---|
72 | function categorie_select($option_name = '',$value='',$row_num=0 ,$sort_column = 'ID', $sort_order = 'asc') |
---|
73 | { |
---|
74 | $mydirpath = dirname(dirname(__FILE__)); |
---|
75 | $mydirname = basename( dirname( dirname( __FILE__ ) ) ) ; |
---|
76 | if ($mydirname == 'wordpress'){ |
---|
77 | $wp_prefix = 'wp_'; |
---|
78 | } else { |
---|
79 | $wp_prefix = $mydirname . '_'; |
---|
80 | } |
---|
81 | $xoopsDB =& Database::getInstance(); |
---|
82 | $myts =& MyTextSanitizer::getInstance(); |
---|
83 | $selected = explode(',' , $value); |
---|
84 | $isAll = (count($selected)==0||empty($selected[0]))?true:false; |
---|
85 | $sort_column = 'cat_'.$sort_column; |
---|
86 | if (empty($row_num)) $size = ''; else $size = 'size="' . $row_num . '"'; |
---|
87 | include $mydirpath.'/wp-includes/version.php'; |
---|
88 | if ($wp_db_version < 6124) { |
---|
89 | $db_xpress_categories = $xoopsDB->prefix($wp_prefix . 'categories'); |
---|
90 | $query = " |
---|
91 | SELECT cat_ID, cat_name, category_nicename,category_parent |
---|
92 | FROM $db_xpress_categories |
---|
93 | WHERE cat_ID > 0 |
---|
94 | "; |
---|
95 | $query .= " ORDER BY $sort_column $sort_order"; |
---|
96 | |
---|
97 | } else { |
---|
98 | $db_xpress_terms = $xoopsDB->prefix($wp_prefix . 'terms'); |
---|
99 | $db_xpress_term_taxonomy = $xoopsDB->prefix($wp_prefix . 'term_taxonomy'); |
---|
100 | $query = " |
---|
101 | SELECT $db_xpress_terms.term_id as cat_ID , $db_xpress_terms.name as cat_name , $db_xpress_term_taxonomy.taxonomy |
---|
102 | FROM $db_xpress_terms LEFT JOIN $db_xpress_term_taxonomy ON $db_xpress_terms.term_id = $db_xpress_term_taxonomy.term_id |
---|
103 | WHERE $db_xpress_term_taxonomy.taxonomy = 'category' |
---|
104 | "; |
---|
105 | $query .= " ORDER BY $sort_column $sort_order"; |
---|
106 | } |
---|
107 | $res = $xoopsDB->query($query, 0, 0); |
---|
108 | $option = "\t<option value=\"0\" "; |
---|
109 | if ($isAll) $option .= " selected=\"selected\""; |
---|
110 | $option .= ">"._MB_XP2_ALL ."</option>\n"; |
---|
111 | |
---|
112 | if ($res !== false){ |
---|
113 | while($row = $xoopsDB->fetchArray($res)){ |
---|
114 | $cat_name = $row['cat_name']; |
---|
115 | $cat_ID = $row['cat_ID']; |
---|
116 | $option .= "\t<option value=\"".$cat_ID."\""; |
---|
117 | if (in_array($cat_ID, $selected)) |
---|
118 | $option .= ' selected="selected"'; |
---|
119 | $option .= '>'; |
---|
120 | $option .= $myts->htmlspecialchars($cat_name); |
---|
121 | $option .= "</option>\n"; |
---|
122 | } |
---|
123 | } |
---|
124 | $output = _MB_XP2_CATS_SELECT ."<br />\n"; |
---|
125 | $output .= "<input type='hidden' name='$option_name' value='$value' />\n"; |
---|
126 | $output .= ' <select name="categorie" '.$size.' multiple="multiple" onclick="CatSelect()">' ."\n"; |
---|
127 | $output .= $option; |
---|
128 | $output .= '</select><br />'; |
---|
129 | $output .= ' |
---|
130 | <script type="text/javascript"> |
---|
131 | function CatSelect(){ |
---|
132 | var idx=new Array(); |
---|
133 | var sel=document.forms["blockform"].elements["categorie"].options; |
---|
134 | for(var i=0, n=0; i<sel.length; i++){ |
---|
135 | if(sel[i].selected){ idx[n++]=sel[i].value; } |
---|
136 | } |
---|
137 | if(idx.length>0){ |
---|
138 | document.forms["blockform"].elements["' .$option_name . '"].value = idx; |
---|
139 | } |
---|
140 | } |
---|
141 | </script> |
---|
142 | '; |
---|
143 | |
---|
144 | return $output; |
---|
145 | |
---|
146 | } |
---|
147 | endif; |
---|
148 | |
---|
149 | ?> |
---|