OSDN Git Service

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