Nucleus CMS日本語版用プラグインのうち、日本語版開発者がサポートしているもの
Revision | 9cc9e8894071f7458f74c5e5e101346066e76fe8 (tree) |
---|---|
Time | 2007-05-20 22:05:01 |
Author | satona <satona@1ca2...> |
Commiter | satona |
(none)
git-svn-id: https://svn.sourceforge.jp/svnroot/nucleus-jp/plugin@571 1ca29b6e-896d-4ea0-84a5-967f57386b96
@@ -0,0 +1,293 @@ | ||
1 | +<?php | |
2 | + | |
3 | +/* | |
4 | + Class for Plugin Admin Area | |
5 | + Taka http://vivian.stripper.jp/ 2004-04-13 | |
6 | + | |
7 | + Copied / Arranged => nucleus/libs/ADMIN.php, TEMPLATE.php | |
8 | + And a few was added... | |
9 | +*/ | |
10 | + | |
11 | + // class PULUG_ADMIN | |
12 | + // class PLUG_TEMPLATE_MANAGER | |
13 | + | |
14 | +class PLUG_ADMIN { | |
15 | + | |
16 | + function action($action) { | |
17 | + $methodName = 'action_' . $action; | |
18 | + if (method_exists($this, $methodName)) { | |
19 | + call_user_func(array(&$this, $methodName)); | |
20 | + } else { | |
21 | + $this->error(_BADACTION . " ($action)"); | |
22 | + } | |
23 | + } | |
24 | + | |
25 | + function disallow() { | |
26 | + global $HTTP_SERVER_VARS; | |
27 | + | |
28 | + ACTIONLOG::add(WARNING, _ACTIONLOG_DISALLOWED . $HTTP_SERVER_VARS['REQUEST_URI']); | |
29 | + | |
30 | + $this->error(_ERROR_DISALLOWED); | |
31 | + } | |
32 | + | |
33 | + function error($msg) { | |
34 | + global $oPluginAdmin; | |
35 | + | |
36 | + $oPluginAdmin->start(); | |
37 | + $dir=$oPluginAdmin->plugin->getAdminURL(); | |
38 | + ?> | |
39 | + <h2>Error!</h2> | |
40 | + <?php echo $msg; | |
41 | + echo "<br />"; | |
42 | + echo "<a href='".$dir."index.php' onclick='history.back()'>"._BACK."</a>"; | |
43 | + | |
44 | + $oPluginAdmin->end(); | |
45 | + exit; | |
46 | + } | |
47 | + | |
48 | + function requestEx($name) { | |
49 | + if(phpversion()<"4.1.0") { | |
50 | + global $HTTP_POST_VARS, $HTTP_GET_VARS; | |
51 | + $data = $HTTP_POST_VARS[$name] ? $HTTP_POST_VARS[$name] : $HTTP_GET_VARS[$name]; | |
52 | + } else { | |
53 | + $data = $_REQUEST[$name]; | |
54 | + } | |
55 | + if (is_array($data) && get_magic_quotes_gpc()) { | |
56 | + return array_map("stripslashes",$data); | |
57 | + } else { | |
58 | + return get_magic_quotes_gpc() ? stripslashes($data) : $data; | |
59 | + } | |
60 | + } | |
61 | + | |
62 | + function help($name) { | |
63 | + echo $this->helpHtml($name); | |
64 | + } | |
65 | + | |
66 | + function helpHtml($name) { | |
67 | + return $this->helplink($name) . '<img src="documentation/icon-help.gif" width="15" height="15" alt="'._HELP_TT.'" /></a>'; | |
68 | + } | |
69 | + | |
70 | + function helplink($name) { | |
71 | + global $oPluginAdmin; | |
72 | + | |
73 | + $dir=$oPluginAdmin->plugin->getAdminURL(); | |
74 | + return '<a href="'.$dir.'help.html#'. $name . '" onclick="if (event && event.preventDefault) event.preventDefault(); return help(this.href);">'; | |
75 | + } | |
76 | + | |
77 | + function showRadioButton($name, $radio_array, $checked, $tabindex=0) { | |
78 | + /* | |
79 | + $name : The name of the radiobutton element. | |
80 | + $radio_array :An associative array of option element data. | |
81 | + [Format] $radio_array = array('radiobutton value' => 'radiobutton title') | |
82 | + $checked : The value of the checked element. | |
83 | + */ | |
84 | + foreach ($radio_array as $k => $v) { | |
85 | + echo '<input type="radio" name="'.$name.'" id="'.$name.$k.'" value="'.$k.'"'; | |
86 | + if ($k == $checked) echo ' checked="checked"'; | |
87 | + echo ' tabindex="'.$tabindex.'" />'; | |
88 | + echo '<label for="'.$name.$k.'">'.$v.'</label>'; | |
89 | + } | |
90 | + } | |
91 | + | |
92 | + function showBlogCheckbox($name, $checked_array=array(), $tabindex=0) { | |
93 | + /* | |
94 | + $name : The name of the input(checkbox) element. | |
95 | + !!! Checked blogID data is returned as array. !!! | |
96 | + $checked_array : Array containing blogID which should be checked beforehand. | |
97 | + */ | |
98 | + | |
99 | + $query = 'SELECT bnumber, bname FROM '.sql_table('blog').' ORDER BY bnumber'; | |
100 | + $res = sql_query($query); | |
101 | + | |
102 | + while ($data = mysql_fetch_assoc($res)) { | |
103 | + $data['bname'] = htmlspecialchars(shorten($data['bname'],16,'..')); | |
104 | + | |
105 | + echo '<span style="white-space:nowrap"><input type="checkbox" name="'.$name.'[]" value="'.$data['bnumber'].'"'; | |
106 | + | |
107 | + if(in_array($data['bnumber'],$checked_array)) { | |
108 | + echo ' checked="checked"'; | |
109 | + } | |
110 | + echo ' tabindex="'.$tabindex.'" id="blog_checkbox'.$data['bnumber'].'" />'; | |
111 | + echo '<label for="blog_checkbox'.$data['bnumber'].'">'; | |
112 | + echo $data['bnumber'].":".$data['bname'].'</label></span>'; | |
113 | + } | |
114 | + } | |
115 | + | |
116 | + function showCategoryCheckbox($name, $blogid, $checked_array=array(), $tabindex=0) { | |
117 | + /* | |
118 | + $name : The name of the input(checkbox) element. | |
119 | + !!! Checked catID data is returned as array. !!! | |
120 | + $blogid : blogID to which a category belongs | |
121 | + $checked_array : Array containing catID which should be checked beforehand. | |
122 | + */ | |
123 | + | |
124 | + $query = 'SELECT catid, cname FROM '.sql_table('category').'WHERE cblog='.$blogid.' ORDER BY catid'; | |
125 | + $res = sql_query($query); | |
126 | + | |
127 | + while ($data = mysql_fetch_assoc($res)) { | |
128 | + $data['cname'] = htmlspecialchars(shorten($data['cname'],16,'..')); | |
129 | + | |
130 | + echo '<span style="white-space:nowrap"><input type="checkbox" name="'.$name.'[]" value="'.$data['catid'].'"'; | |
131 | + | |
132 | + if(in_array($data['catid'],$checked_array)) { | |
133 | + echo ' checked="checked"'; | |
134 | + } | |
135 | + echo ' tabindex="'.$tabindex.'" id="category_checkbox'.$data['catid'].'" />'; | |
136 | + echo '<label for="category_checkbox'.$data['catid'].'">'; | |
137 | + echo $data['catid'].":".$data['cname'].'</label></span>'; | |
138 | + } | |
139 | + } | |
140 | + | |
141 | + function showSelectMenu($name, $option_array, $selected, $tabindex=0) { | |
142 | + /* | |
143 | + $name : The name of the select element. | |
144 | + $option_array :An associative array of option element data. | |
145 | + [Format] $option_array = array('option value' => 'option title') | |
146 | + $selected : The value of the selected option element. | |
147 | + */ | |
148 | + | |
149 | + echo '<select name="'.$name.'" tabindex="'.$tabindex.'">'; | |
150 | + foreach ($option_array as $k => $v) { | |
151 | + echo '<option value="'.$k.'"'; | |
152 | + if ($k == $selected) echo ' selected="selected"'; | |
153 | + echo '>'.$v.'</option>'; | |
154 | + } | |
155 | + echo '</select>'; | |
156 | + } | |
157 | + | |
158 | + function showRankSelectMenu($name, $selected=20, $maxvalue=50, $tabindex=0) { | |
159 | + echo '<select name="'.$name.'" tabindex="'.$tabindex.'">'; | |
160 | + for ($i=1; $i<=$maxvalue; $i++) { | |
161 | + echo '<option value="'.$i.'"'; | |
162 | + if ($i == $selected) echo ' selected="selected"'; | |
163 | + echo '>'.$i.'</option>'; | |
164 | + } | |
165 | + echo '</select>'; | |
166 | + } | |
167 | + | |
168 | + function showAllCategorySelectMenu($name, $selected = '', $tabindex = 0) { | |
169 | + | |
170 | + echo '<select name="',$name,'" tabindex="',$tabindex,'">'; | |
171 | + if (!$selected) { | |
172 | + echo '<option value="" selected="selected"> --- </option>'; | |
173 | + } | |
174 | + | |
175 | + // 1. select blogs (we'll create optiongroups) | |
176 | + $queryBlogs = 'SELECT bnumber, bname FROM '.sql_table('blog').' ORDER BY bnumber'; | |
177 | + $blogs = sql_query($queryBlogs); | |
178 | + if (mysql_num_rows($blogs) > 1) { | |
179 | + $multipleBlogs = 1; | |
180 | + } | |
181 | + | |
182 | + while ($oBlog = mysql_fetch_object($blogs)) { | |
183 | + if ($multipleBlogs) { | |
184 | + echo '<optgroup label="',htmlspecialchars($oBlog->bname),'">'; | |
185 | + } | |
186 | + | |
187 | + // 2. for each category in that blog | |
188 | + $categories = sql_query('SELECT cname, catid FROM '.sql_table('category').' WHERE cblog=' . $oBlog->bnumber . ' ORDER BY cname ASC'); | |
189 | + while ($oCat = mysql_fetch_object($categories)) { | |
190 | + if ($oCat->catid == $selected) | |
191 | + $selectText = ' selected="selected" '; | |
192 | + else | |
193 | + $selectText = ''; | |
194 | + echo '<option value="',$oCat->catid,'" ', $selectText,'>',htmlspecialchars($oCat->cname),'</option>'; | |
195 | + } | |
196 | + | |
197 | + if ($multipleBlogs) { | |
198 | + echo '</optgroup>'; | |
199 | + } | |
200 | + | |
201 | + } | |
202 | + echo '</select>'; | |
203 | + | |
204 | + } | |
205 | + | |
206 | + function templateEditRow(&$template, $description, $name, $help = '', $tabindex = 0, $big = 0) { | |
207 | + /* | |
208 | + $template : An associative array of current template. | |
209 | + [Format] $template = array( 'template part name' => 'template part value') | |
210 | + $description : Description of current template part. | |
211 | + $name : The name of the current template part. | |
212 | + */ | |
213 | + ?> | |
214 | + </tr><tr> | |
215 | + <td><?php echo $description ?> <?php if ($help) $this->help($help); ?></td> | |
216 | + <td><textarea name="<?php echo $name?>" tabindex="<?php echo $tabindex?>" cols="50" rows="<?php echo $big ? '10' : '5'; ?>"><?php echo htmlspecialchars($template[$name]); ?></textarea></td> | |
217 | + <?php | |
218 | + } | |
219 | + | |
220 | +} | |
221 | + | |
222 | + | |
223 | +class PLUG_TEMPLATE_MANAGER { | |
224 | + | |
225 | + function PLUG_TEMPLATE_MANAGER($table,$primarykey,$namecolumn) { | |
226 | + $this->table = $table; | |
227 | + $this->idkey = $primarykey; | |
228 | + $this->namekey = $namecolumn; | |
229 | + // !!! $this->idkey must be set as "auto_increment." !!! | |
230 | + } | |
231 | + | |
232 | + function getIdFromName($name) { | |
233 | + return quickQuery('SELECT '.$this->idkey.' as result FROM '.$this->table.' WHERE '.$this->namekey.'="'.addslashes($name).'"'); | |
234 | + } | |
235 | + | |
236 | + function getNameFromID($id) { | |
237 | + return quickQuery('SELECT '.$this->namekey.' as result FROM '.$this->table.' WHERE '.$this->idkey.'='.intval($id)); | |
238 | + } | |
239 | + | |
240 | + function getDataFromID($dataname,$id) { | |
241 | + return quickQuery('SELECT '.$dataname.' as result FROM '.$this->table.' WHERE '.$this->idkey.'='.intval($id)); | |
242 | + } | |
243 | + | |
244 | + function exists($name) { | |
245 | + $res = sql_query('SELECT * FROM '.$this->table.' WHERE '.$this->namekey.'="'.addslashes($name).'"'); | |
246 | + return (mysql_num_rows($res) != 0); | |
247 | + } | |
248 | + | |
249 | + function existsID($id) { | |
250 | + $res = sql_query('select * FROM '.$this->table.' WHERE '.$this->idkey.'='.intval($id)); | |
251 | + return (mysql_num_rows($res) != 0); | |
252 | + } | |
253 | + | |
254 | + function getNameList($w='') { | |
255 | + $where = ''; | |
256 | + if ($w != '') $where = ' WHERE '.$w; | |
257 | + $res = sql_query('SELECT '.$this->idkey.' as id, '.$this->namekey.' as name FROM '.$this->table. $where .' ORDER BY '.$this->namekey); | |
258 | + while ($obj = mysql_fetch_object($res)) { | |
259 | + $templates[intval($obj->id)] = $obj->name; | |
260 | + } | |
261 | + return $templates; | |
262 | + } | |
263 | + | |
264 | + function read($name) { | |
265 | + $query = 'SELECT * FROM '.$this->table.' WHERE '.$this->namekey.'="'.addslashes($name).'"'; | |
266 | + $res = sql_query($query); | |
267 | + return mysql_fetch_assoc($res); | |
268 | + } | |
269 | + | |
270 | + function createTemplate($name) { | |
271 | + sql_query('INSERT INTO '.$this->table.' SET '.$this->namekey.'="'. addslashes($name) .'"'); | |
272 | + $newid = mysql_insert_id(); | |
273 | + return $newid; | |
274 | + } | |
275 | + | |
276 | + function updateTemplate($id, $template) { | |
277 | + $query = 'UPDATE '.$this->table.' SET '; | |
278 | + foreach ($template as $k => $v) { | |
279 | + $query .= $k.'="'.addslashes($v).'",'; | |
280 | + } | |
281 | + $query = substr($query,0,-1); | |
282 | + $query .= ' WHERE '.$this->idkey.'='.$id; | |
283 | + sql_query($query); | |
284 | + } | |
285 | + | |
286 | + function deleteTemplate($id) { | |
287 | + sql_query('DELETE FROM '.$this->table.' WHERE '.$this->idkey.'=' . $id); | |
288 | + } | |
289 | + | |
290 | +} | |
291 | + | |
292 | + | |
293 | +?> | |
\ No newline at end of file |
@@ -0,0 +1,416 @@ | ||
1 | +<?php | |
2 | +/** | |
3 | + * NP_MultipleCategories Admin Page Script | |
4 | + * Taka ( http://reverb.jp/vivian/) 2004-12-01 | |
5 | + */ | |
6 | + | |
7 | + // if your 'plugin' directory is not in the default location, | |
8 | + // edit this variable to point to your site directory | |
9 | + // (where config.php is) | |
10 | + $strRel = '../../../'; | |
11 | + | |
12 | + include($strRel . 'config.php'); | |
13 | + if (!$member->isLoggedIn()) | |
14 | + doError('You\'re not logged in.'); | |
15 | + | |
16 | + include($DIR_LIBS . 'PLUGINADMIN.php'); | |
17 | + | |
18 | + // create the admin area page | |
19 | + $oPluginAdmin = new PluginAdmin('MultipleCategories'); | |
20 | + | |
21 | +// ------------------------------------------------------------------ | |
22 | + | |
23 | +class NpMCategories_ADMIN { | |
24 | + | |
25 | + function NpMCategories_ADMIN() { | |
26 | + global $oPluginAdmin; | |
27 | + | |
28 | + $this->plug =& $oPluginAdmin->plugin; | |
29 | + $this->plugname = $this->plug->getName(); | |
30 | + $this->url = $this->plug->getAdminURL(); | |
31 | + | |
32 | + $this->table = sql_table('plug_multiple_categories_sub'); | |
33 | + | |
34 | + } | |
35 | + | |
36 | +//------------------- | |
37 | + | |
38 | + function action_overview($msg='') { | |
39 | + global $member, $oPluginAdmin; | |
40 | + | |
41 | + $member->isAdmin() or $this->disallow(); | |
42 | + | |
43 | + $oPluginAdmin->start(); | |
44 | + | |
45 | + echo '<p><a href="index.php?action=pluginlist">('._PLUGS_BACK.')</a></p>'; | |
46 | + echo '<h2>' .$this->plugname. '</h2>'."\n"; | |
47 | + if ($msg) echo "<p>"._MESSAGE.": $msg</p>"; | |
48 | + echo '<p>[<a href="index.php?action=pluginoptions&plugid='.$this->plug->getID().'">Edit Plugin Options</a>]</p>'; | |
49 | +?> | |
50 | + | |
51 | +<?php | |
52 | + $res = sql_query('SELECT bnumber, bname FROM '.sql_table('blog')); | |
53 | + while ($o = mysql_fetch_object($res)) { | |
54 | +?> | |
55 | +<?php | |
56 | + echo '<h3 style="padding-left: 0px">' . htmlspecialchars($o->bname, ENT_QUOTES) . '</h3>'; //<sato(na)0.38j /> | |
57 | +?> | |
58 | +<table> | |
59 | + <thead> | |
60 | + <tr><th><?php echo _LISTS_NAME ?></th><th><?php echo _LISTS_DESC ?></th><th>Sub Categories</th><th><?php echo _LISTS_ACTIONS ?></th></tr> | |
61 | + </thead> | |
62 | + <tbody> | |
63 | +<?php | |
64 | + $cats = $this->plug->_getCategories($o->bnumber); | |
65 | + foreach ($cats as $cat) { | |
66 | + $snum = quickQuery("SELECT count(*) as result FROM ".$this->table." WHERE catid=".$cat['catid']); | |
67 | + $snum = intval($snum); | |
68 | +?> | |
69 | + <tr onmouseover='focusRow(this);' onmouseout='blurRow(this);'> | |
70 | + <td> | |
71 | + <?php echo htmlspecialchars($cat['name'], ENT_QUOTES) ?></td> | |
72 | + <td><?php echo htmlspecialchars($cat['cdesc'], ENT_QUOTES) ?></td> | |
73 | + <td><?php echo $snum ?></td> | |
74 | + <td><a href="<?php echo $this->url ?>index.php?action=scatoverview&catid=<?php echo intval($cat['catid']); ?>" tabindex="50">Edit sub categories</a></td> | |
75 | + </tr> | |
76 | +<?php | |
77 | + } | |
78 | +?> | |
79 | + </tbody> | |
80 | +</table> | |
81 | +<?php | |
82 | + } | |
83 | + | |
84 | + $oPluginAdmin->end(); | |
85 | + | |
86 | + } | |
87 | + | |
88 | +//----- | |
89 | + | |
90 | + function action_scatoverview($msg = '') { | |
91 | + global $member, $manager, $oPluginAdmin; | |
92 | + | |
93 | + $member->isAdmin() or $this->disallow(); | |
94 | + | |
95 | + $catid = intRequestVar('catid'); | |
96 | + $catname = $this->plug->_getCatNameFromID($catid); | |
97 | + | |
98 | + $oPluginAdmin->start(); | |
99 | + | |
100 | +?> | |
101 | +<p><a href="<?php echo $this->url ?>index.php?action=overview">(Go Back)</a></p> | |
102 | + | |
103 | +<h2><?php | |
104 | + echo " Edit Sub Categories of '".htmlspecialchars($catname, ENT_QUOTES)."'</h2>\n"; | |
105 | + | |
106 | + if ($msg) echo "<p>"._MESSAGE.": $msg</p>"; | |
107 | +?> | |
108 | + | |
109 | + <table> | |
110 | + <thead> | |
111 | + <tr><th><?php echo _LISTS_NAME ?></th><th><?php echo _LISTS_DESC ?></th><th colspan='2'><?php echo _LISTS_ACTIONS ?></th></tr> | |
112 | + </thead> | |
113 | + <tbody> | |
114 | +<?php | |
115 | + $defines = $this->plug->_getDefinedScats($catid); | |
116 | + if (count($defines) > 0) { | |
117 | + foreach ($defines as $scat) { | |
118 | +?> | |
119 | + <tr onmouseover='focusRow(this);' onmouseout='blurRow(this);'> | |
120 | + <td><?php echo htmlspecialchars($scat['sname'], ENT_QUOTES) ?></td> | |
121 | + <td><?php echo htmlspecialchars($scat['sdesc'], ENT_QUOTES) ?></td> | |
122 | + <td><a href="<?php echo $this->url ?>index.php?action=scatedit&catid=<?php echo intval($catid); ?>&scatid=<?php echo intval($scat['scatid']); ?>" tabindex="50"><?php echo _LISTS_EDIT ?></a></td> | |
123 | + <td><a href="<?php echo $this->url ?>index.php?action=scatdelete&catid=<?php echo intval($catid); ?>&scatid=<?php echo intval($scat['scatid']); ?>" tabindex="50"><?php echo _LISTS_DELETE ?></a></td> | |
124 | + </tr> | |
125 | +<?php | |
126 | + } | |
127 | + } | |
128 | +?> | |
129 | + </tbody> | |
130 | + </table> | |
131 | +<?php | |
132 | + | |
133 | + echo "\n\n".'<h3>Create New Sub Category</h3>'."\n\n"; | |
134 | + | |
135 | +?> | |
136 | + <form method="post" action="<?php echo $this->url ?>index.php"><div> | |
137 | + | |
138 | + <?php $manager->addTicketHidden(); ?> | |
139 | + <input name="action" value="scatnew" type="hidden" /> | |
140 | + <input name="catid" value="<?php echo intval($catid); ?>" type="hidden" /> | |
141 | + <table><tr> | |
142 | + <td>Name</td> | |
143 | + <td><input name="sname" tabindex="10010" maxlength="20" size="20" /></td> | |
144 | + </tr><tr> | |
145 | + <td>Description</td> | |
146 | + <td><input name="sdesc" tabindex="10020" size="60" maxlength="200" /></td> | |
147 | + </tr><tr> | |
148 | + <td>Create</td> | |
149 | + <td><input type="submit" tabindex="10030" value="Create Sub Category" onclick="return checkSubmit();" /></td> | |
150 | + </tr></table> | |
151 | + | |
152 | + </div></form> | |
153 | +<?php | |
154 | + | |
155 | + $oPluginAdmin->end(); | |
156 | + | |
157 | + } | |
158 | + | |
159 | + function action_scatedit($msg = '') { | |
160 | + global $member, $manager, $oPluginAdmin; | |
161 | + | |
162 | + $member->isAdmin() or $this->disallow(); | |
163 | + | |
164 | + $scatid = intRequestVar('scatid'); | |
165 | + $catid = intRequestVar('catid'); | |
166 | + | |
167 | + $res = sql_query("SELECT * FROM ".$this->table." WHERE scatid=$scatid and catid=$catid"); | |
168 | + if ($o = mysql_fetch_object($res)) { | |
169 | + | |
170 | + $oPluginAdmin->start(); | |
171 | + | |
172 | +?> | |
173 | +<p><a href="<?php echo $this->url ?>index.php?action=scatoverview&catid=<?php echo intval($catid); ?>">(Go Back)</a></p> | |
174 | + | |
175 | +<h2><?php | |
176 | + echo ' Edit'; | |
177 | + echo " '".htmlspecialchars($o->sname, ENT_QUOTES)."'</h2>\n"; | |
178 | + | |
179 | + if ($msg) echo "<p>"._MESSAGE.": $msg</p>"; | |
180 | + | |
181 | +?> | |
182 | + | |
183 | +<form method="post" action="<?php echo $this->url ?>index.php"> | |
184 | + <div> | |
185 | + | |
186 | + <?php $manager->addTicketHidden(); ?> | |
187 | + <input type="hidden" name="action" value="scatupdate" /> | |
188 | + <input type="hidden" name="scatid" value="<?php echo intval($scatid); ?>" /> | |
189 | + <input type="hidden" name="catid" value="<?php echo intval($catid); ?>" /> | |
190 | + <table><tr> | |
191 | + <td>Name</td> | |
192 | + <td><input name="sname" tabindex="10010" maxlength="20" size="20" value="<?php echo htmlspecialchars($o->sname, ENT_QUOTES); ?>" /></td> | |
193 | + </tr><tr> | |
194 | + <td>Description</td> | |
195 | + <td><input name="sdesc" tabindex="10020" size="60" maxlength="200" value="<?php echo htmlspecialchars($o->sdesc, ENT_QUOTES); ?>" /></td> | |
196 | + </tr><tr> | |
197 | + <td>Create</td> | |
198 | + <td><input type="submit" tabindex="10030" value="Create Sub Category" onclick="return checkSubmit();" /></td> | |
199 | + </tr></table> | |
200 | + | |
201 | + </div> | |
202 | +</form> | |
203 | + | |
204 | +<?php | |
205 | + $oPluginAdmin->end(); | |
206 | + | |
207 | + } else { | |
208 | + $this->error("Sub category is missing..."); | |
209 | + } | |
210 | + } | |
211 | + | |
212 | + function action_scatnew() { | |
213 | + global $member; | |
214 | + | |
215 | + $member->isAdmin() or $this->disallow(); | |
216 | + | |
217 | + $sname = postVar('sname'); | |
218 | + if (!trim($sname)) $this->action_scatoverview("Error! Input a name."); | |
219 | + | |
220 | + $newid = $this->createSubcat($sname); | |
221 | + | |
222 | + $array = array( | |
223 | + 'catid'=>postVar('catid'), | |
224 | + 'sdesc'=>postVar('sdesc') | |
225 | + ); | |
226 | + $this->updateSubcat($newid,$array); | |
227 | + | |
228 | + $this->action_scatoverview(); | |
229 | + } | |
230 | + | |
231 | + function action_scatupdate() { | |
232 | + global $member; | |
233 | + | |
234 | + $scatid = intRequestVar('scatid'); | |
235 | + | |
236 | + $member->isAdmin() or $this->disallow(); | |
237 | + | |
238 | + $sname = postVar('sname'); | |
239 | + if (!trim($sname)) { | |
240 | + $this->action_scatoverview("Error! Input a name."); | |
241 | + } else { | |
242 | + | |
243 | + $this->addToScat($scatid); | |
244 | + | |
245 | + $this->action_scatoverview("Sub category data has been saved."); | |
246 | + } | |
247 | + | |
248 | + } | |
249 | + | |
250 | + function action_scatdelete() { | |
251 | + global $member, $manager, $oPluginAdmin; | |
252 | + | |
253 | + $member->isAdmin() or $this->disallow(); | |
254 | + | |
255 | + $scatid = intRequestVar('scatid'); | |
256 | + $catid = intRequestVar('catid'); | |
257 | + $sname = requestVar('sname'); | |
258 | + | |
259 | + $oPluginAdmin->start(); | |
260 | + | |
261 | + ?> | |
262 | + <h2><?php echo _DELETE_CONFIRM?></h2> | |
263 | + | |
264 | + <p>You're about to delete the sub category <b><?php echo htmlspecialchars($sname, ENT_QUOTES); ?></b></p> | |
265 | + | |
266 | + <form method="post" action="<?php echo $this->url ?>index.php"><div> | |
267 | + <?php $manager->addTicketHidden(); ?> | |
268 | + <input type="hidden" name="action" value="scatdeleteconfirm" /> | |
269 | + <input type="hidden" name="scatid" value="<?php echo intval($scatid); ?>" /> | |
270 | + <input type="hidden" name="catid" value="<?php echo intval($catid); ?>" /> | |
271 | + <input type="submit" tabindex="10" value="<?php echo _DELETE_CONFIRM_BTN ?>" /> | |
272 | + </div></form> | |
273 | + <?php | |
274 | + | |
275 | + $oPluginAdmin->end(); | |
276 | + } | |
277 | + | |
278 | + function action_scatdeleteconfirm() { | |
279 | + global $member, $manager; | |
280 | + | |
281 | + $scatid = intRequestVar('scatid'); | |
282 | + $catid = intRequestVar('catid'); | |
283 | + | |
284 | + $member->isAdmin() or $this->disallow(); | |
285 | + | |
286 | + $this->deleteSubcat($scatid); | |
287 | + | |
288 | + $this->action_scatoverview("Sub category has been deleted."); | |
289 | + } | |
290 | + | |
291 | + function addToScat($nowid) { | |
292 | + $datanames = array('catid','sname','sdesc'); | |
293 | + foreach ($datanames as $val) { | |
294 | + $scat[$val] = postVar($val); | |
295 | + } | |
296 | + $this->updateSubcat($nowid,$scat); | |
297 | + } | |
298 | + | |
299 | + function createSubcat($name) { | |
300 | + sql_query('INSERT INTO '.$this->table.' SET sname="'. addslashes($name) .'"'); | |
301 | + $newid = mysql_insert_id(); | |
302 | + global $manager; | |
303 | + $manager->notify( | |
304 | + 'PostAddSubcat', | |
305 | + array( | |
306 | + 'subcatid' => $newid | |
307 | + ) | |
308 | + ); | |
309 | + return $newid; | |
310 | + } | |
311 | + | |
312 | + function updateSubcat($id, $scat) { | |
313 | + $query = 'UPDATE '.$this->table.' SET '; | |
314 | + foreach ($scat as $k => $v) { | |
315 | + $query .= $k.'="'.addslashes($v).'",'; | |
316 | + } | |
317 | + $query = substr($query,0,-1); | |
318 | + $query .= ' WHERE scatid='.$id; | |
319 | + sql_query($query); | |
320 | + } | |
321 | + | |
322 | + function deleteSubcat($id) { | |
323 | + $id = intval($id); //<sato(na)0.38j /> | |
324 | + sql_query('DELETE FROM '.$this->table.' WHERE scatid=' . $id); | |
325 | + global $manager; | |
326 | + $manager->notify( | |
327 | + 'PostDeleteSubcat', | |
328 | + array( | |
329 | + 'subcatid' => $id | |
330 | + ) | |
331 | + ); | |
332 | + | |
333 | + $res = sql_query("SELECT categories, subcategories, item_id FROM ". sql_table("plug_multiple_categories") ." WHERE subcategories REGEXP '(^|,)$id(,|$)'"); | |
334 | + $dell = array(); | |
335 | + $up = array(); | |
336 | + | |
337 | + while ($o = mysql_fetch_object($res)) { | |
338 | + $o->subcategories = preg_replace("/^(?:(.*),)?$catid(?:,(.*))?$/","$1,$2",$o->subcategories); | |
339 | + if (!$o->categories && (!$o->subcategories || $o->subcategories == ',')) { | |
340 | + $del[] = intval($o->item_id); //<sato(na)0.38j />ultrarich | |
341 | + } else { | |
342 | + $o->subcategories = preg_replace("/(^,+|(?<=,),+|,+$)/","",$o->subcategories); | |
343 | + $up[] = "UPDATE ". sql_table("plug_multiple_categories") ." SET categories='".addslashes($o->categories)."', subcategories='".addslashes($o->subcategories)."' WHERE item_id=".intval($o->item_id); //<sato(na)0.38j />ultrarich | |
344 | + } | |
345 | + } | |
346 | + | |
347 | + if (count($del) > 0) { | |
348 | + sql_query("DELETE FROM ". sql_table("plug_multiple_categories") . " WHERE item_id in (".implode(",",$del).")"); | |
349 | + } | |
350 | + if (count($up) > 0) { | |
351 | + foreach ($up as $v) { | |
352 | + sql_query($v); | |
353 | + } | |
354 | + } | |
355 | + } | |
356 | + | |
357 | + | |
358 | + function action($action) { | |
359 | + //<sato(na)0.38j /> | |
360 | + global $manager; | |
361 | + $methodName = 'action_' . $action; | |
362 | + $this->action = strtolower($action); | |
363 | + $aActionsNotToCheck = array( | |
364 | + 'overview', | |
365 | + 'scatoverview', | |
366 | + 'scatedit', | |
367 | + 'scatdelete', | |
368 | + ); | |
369 | + if (!in_array($this->action, $aActionsNotToCheck)) { | |
370 | + if (!$manager->checkTicket()) $this->error(_ERROR_BADTICKET); | |
371 | + } | |
372 | + //<sato(na)0.38j /> | |
373 | + | |
374 | + if (method_exists($this, $methodName)) { | |
375 | + call_user_func(array(&$this, $methodName)); | |
376 | + } else { | |
377 | + $this->error(_BADACTION . " ($action)"); | |
378 | + } | |
379 | + } | |
380 | + | |
381 | + function disallow() { | |
382 | + global $HTTP_SERVER_VARS; | |
383 | + | |
384 | + ACTIONLOG::add(WARNING, _ACTIONLOG_DISALLOWED . $HTTP_SERVER_VARS['REQUEST_URI']); | |
385 | + | |
386 | + $this->error(_ERROR_DISALLOWED); | |
387 | + } | |
388 | + | |
389 | + function error($msg) { | |
390 | + global $oPluginAdmin; | |
391 | + | |
392 | + $oPluginAdmin->start(); | |
393 | + $dir=$oPluginAdmin->plugin->getAdminURL(); | |
394 | + ?> | |
395 | + <h2>Error!</h2> | |
396 | + <?php echo $msg; | |
397 | + echo "<br />"; | |
398 | + echo "<a href='".$dir."index.php' onclick='history.back()'>"._BACK."</a>"; | |
399 | + | |
400 | + $oPluginAdmin->end(); | |
401 | + exit; | |
402 | + } | |
403 | + | |
404 | +} // NpMCategories_ADMIN end | |
405 | + | |
406 | +// ------------------------------------------------------------------ | |
407 | + | |
408 | +$myAdmin = new NpMCategories_ADMIN(); | |
409 | +if (requestVar('action')) { | |
410 | + $myAdmin->action(requestVar('action')); | |
411 | +} else { | |
412 | + $myAdmin->action('overview'); | |
413 | +} | |
414 | + | |
415 | +?> | |
416 | + |