OSDN Git Service

FIX: NP_AttachをNucleus 3.65/PHP5.4/MySQL5.5で動作するよう修正
[nucleus-jp/nucleus-plugins.git] / trunk / NP_SkinSwitcher / skinswitcher / index.php
1 <?php
2 /* NP_SkinSwitcher ver 0.7.2 */
3
4         $strRel = '../../../'; 
5         include($strRel . 'config.php');
6         include($DIR_LIBS . 'PLUGINADMIN.php');
7         
8         // Send out Content-type
9         sendContentType('application/xhtml+xml', 'admin-skinswitcher', _CHARSET);       
10 /*
11         if (!($member->isLoggedIn() && $member->isAdmin()))
12                 doError('You\'re not logged in.');
13 */      
14         if (!($member->isLoggedIn() && $member->getAdminBlogs()))
15                 doError('You do not have admin rights for any blogs.');
16
17         $oPluginAdmin = new PluginAdmin('SkinSwitcher');
18
19                 // include language file for this plugin 
20                 $language = ereg_replace( '[\\|/]', '', getLanguageName()); 
21                 if (file_exists($oPluginAdmin->plugin->getDirectory().'language/'.$language.'.php')) 
22                         include_once($oPluginAdmin->plugin->getDirectory().'language/'.$language.'.php'); 
23                 else 
24                         include_once($oPluginAdmin->plugin->getDirectory().'language/'.'english.php');
25
26
27 // ------------------------------------------------------------------
28 class NpSkinSwitcher_ADMIN{
29         
30         function NpSkinSwitcher_ADMIN(){
31                 global $oPluginAdmin;
32                 $this->url = $oPluginAdmin->plugin->getAdminURL();
33                 $this->extrahead = '<link rel="stylesheet" type="text/css" href="'.$this->url.'plus.css" />'."\n";
34                 session_start();
35
36         }
37
38         function msg(){
39                 $msg = $_SESSION['msg'];
40                 if ($msg) echo "<blockquote>"._MESSAGE.": $msg</blockquote>";
41                 unset($_SESSION['msg']);
42         }
43
44         function showSelectList($blogid){
45                 global $member, $oPluginAdmin;
46                 if(!$blogid && !($member->isAdmin())) return;
47
48                 $global_sdnums = $oPluginAdmin->plugin->getSdnums(0);
49                 $defskinid = quickQuery('SELECT bdefskin as result FROM '.sql_table('blog').' WHERE bnumber='.intval($blogid));
50                 if($hkey = array_search($defskinid,$global_sdnums)) unset($global_sdnums[$hkey]);
51                 $sdnums = $oPluginAdmin->plugin->getSdnums($blogid);
52                 if($blogid)
53                         echo '<h4>'._EBLOG_NAME.' : '.getBlogNameFromID($blogid).'</h4>';
54                 else
55                         echo '<h4>'._SETTINGS_TITLE.'</h4>';
56
57                 $this->msg();
58 ?>
59                         <form method="post" action="<?php echo $this->url ?>index.php">
60                                 <input type="hidden" name="action" value="update" />
61                                 <input type="hidden" name="blogid" value="<?php echo (int)$blogid ?>" />
62 <?php           
63                 echo '<table>'."\n";
64                 echo '<thead><tr><th>'._SKIN_NAME.'</th><th>'._SKIN_TYPE.'</th><th>'._SKIN_DESC.'</th></tr></thead>'."\n";
65                 echo '<tbody>';
66                 $query =  'SELECT * FROM '.sql_table('skin_desc');
67                 $res = sql_query($query);
68                 
69                 
70                 $i=0;
71                 while($ob = mysql_fetch_object($res)){
72                         if($blogid && in_array($ob->sdnumber,$global_sdnums)) continue;
73                         $chtxt = (in_array($ob->sdnumber,$sdnums))? ' checked="checked"': '';
74                         $extxt = ($ob->sdnumber==$defskinid)? '<b> ('._EBLOG_DEFSKIN.')</b>': '';
75                         echo '<tr'." onmouseover='focusRow(this);' onmouseout='blurRow(this);'".'>'.
76                                 '<td><input type="checkbox" id="batch'.$i.'" name="sdnum['.$i.']" value="'.(int)$ob->sdnumber.'"'.$chtxt.' />'.
77                                 '<label for="batch'.$i.'">'.htmlspecialchars($ob->sdname).$extxt.'</label></td>'.
78                                 '<td>'.htmlspecialchars($ob->sdtype).'</td><td>'.htmlspecialchars($ob->sddesc).'</td></tr>'."\n";
79                         $i++;
80                 }
81                 echo '<tr><td colspan="3">
82                 <a href="" onclick="if (event &amp;&amp; event.preventDefault) event.preventDefault(); return batchSelectAll(1); ">'._BATCH_SELECTALL.'</a>
83                  <a href="" onclick="if (event &amp;&amp; event.preventDefault) event.preventDefault(); return batchSelectAll(0); ">'._BATCH_DESELECTALL.'</a>
84                         <input type="submit" tabindex="10" value="'._SUBMIT.'" /> 
85                  </td></tr>'."\n";
86                 echo '</tbody></table></form>'."\n";
87         }
88
89         function bloglistForSS(){
90                 global $member;
91                 
92                 echo '<h4>'._OVERVIEW_YRBLOGS.' ('._BMLET_OPTIONS.')</h4>';
93                 if ($member->isAdmin()) {
94                         // Super-Admins have access to all blogs! (no add item support though)
95                         $query =  'SELECT bnumber, bname, 1 as tadmin, burl, bshortname'
96                                    . ' FROM ' . sql_table('blog')
97                                    . ' ORDER BY bname';
98                 } else {
99                         $query =  'SELECT bnumber, bname, tadmin, burl, bshortname'
100                                    . ' FROM ' . sql_table('blog') . ', ' . sql_table('team')
101                                    . ' WHERE tblog=bnumber and tmember=' . (int)$member->getID() . ' and tadmin=1'
102                                    . ' ORDER BY bname';
103                 }
104                 $res = sql_query($query);
105                 
106                 $i=0;
107                 echo '<table>'."\n";
108                 echo '<tr><th>'._EBLOG_NAME.'</th><th>'._EBLOG_DESC.'</th><th>'._LISTS_ACTIONS.'</th></tr>'."\n";
109                 while($ob = mysql_fetch_object($res)){
110                         echo '<tr'." onmouseover='focusRow(this);' onmouseout='blurRow(this);'".'>'.
111                                 '<td>' . htmlspecialchars($ob->bname) . '</td>'.
112                                 '<td>'.htmlspecialchars($ob->bdesc).'</td>'.
113                                 '<td><a href="'.$this->url.'index.php?action=blogoverview&amp;blogid='.(int)$ob->bnumber.'">'._PLUG_SKINSWITCHER_BLOGLINK.'</a></td></tr>';
114                 }
115                 echo '</table>'."\n";
116                 
117         }
118
119         function action_overview(){
120                 global $member, $oPluginAdmin;
121 //              $member->isAdmin() or $this->disallow();
122                 $member->isLoggedIn() or $this->disallow();
123
124                 $oPluginAdmin->start($this->extrahead);
125                 echo '<h2>SkinSwitcher</h2>';
126                 echo _PLUG_SKINSWITCHER_HINT;
127                 $this->showSelectList(0);
128                 $this->bloglistForSS();
129
130                 
131                 $oPluginAdmin->end();
132         }
133
134         function action_blogoverview(){
135                 global $member, $oPluginAdmin;
136                 $member->isLoggedIn() or $this->disallow();
137
138                 $oPluginAdmin->start($this->extrahead);
139                 echo '<h2>SkinSwitcher</h2>';
140                 echo _PLUG_SKINSWITCHER_HINT;
141                 $blogid = intRequestVar('blogid');
142                 $this->showSelectList($blogid);
143
144                 
145                 $oPluginAdmin->end();
146         }
147         
148
149         function action_update(){
150                 global $member, $oPluginAdmin, $oTemplate;
151 //              $member->isAdmin() or $this->disallow();
152                 $member->isLoggedIn() or $this->disallow();
153
154                 $blogid = intRequestVar('blogid');
155                 $sdnums = @join(',',requestVar('sdnum'));
156                 
157                 $dq = 'DELETE FROM '.sql_table('plug_skinswitcher').' WHERE sblogid='.(int)$blogid;
158                 $dres = sql_query($dq);
159                 
160                 if($sdnums){
161                 $iq = "
162                                 INSERT INTO 
163                                         ".sql_table('plug_skinswitcher')." 
164                                 SET
165                                         sblogid = ".(int)$blogid.", 
166                                         disskinid = '".addslashes($sdnums)."'
167                                 ";
168                                 $res = @mysql_query($iq);
169                                 if (!$res) {
170                                         $_SESSION['msg'] = $iq.'Could not save data: ' . htmlspecialchars( mysql_error().$query );
171                                 }else{
172                                         $_SESSION['msg'] = 'Saved.';
173                                 }
174                 }else{
175                                         $_SESSION['msg'] = 'Saved.';
176                 }
177                 
178                 header('location: '.$this->url);
179
180         }
181
182         
183         
184         function action($action) {
185                 $methodName = 'action_' . $action;
186                 if (method_exists($this, $methodName)) {
187                         call_user_func(array(&$this, $methodName));
188                 } else {
189                         $this->error(_BADACTION . " ($action)");
190                 }
191         }
192
193         function disallow() {
194                 global $HTTP_SERVER_VARS;
195                 
196                 ACTIONLOG::add(WARNING, _ACTIONLOG_DISALLOWED . $HTTP_SERVER_VARS['REQUEST_URI']);
197                 
198                 $this->error(_ERROR_DISALLOWED);
199         }
200
201         function error($msg) {
202                 global $oPluginAdmin;
203                 
204                 $oPluginAdmin->start();
205                 $dir=$oPluginAdmin->plugin->getAdminURL();
206                 ?>
207                 <h2>Error!</h2>
208                 <?php           echo $msg;
209                 echo "<br />";
210                 echo "<a href='".$dir."index.php' onclick='history.back()'>"._BACK."</a>";
211                 
212                 $oPluginAdmin->end();
213                 exit;
214         }
215 }
216 // ------------------------------------------------------------------
217 $myAdmin = new NpSkinSwitcher_ADMIN();
218 if (requestVar('action')) {
219         $myAdmin->action(requestVar('action'));
220 } else {
221         $myAdmin->action('overview');
222 }
223
224 ?>