OSDN Git Service

ADD:リファレンスマニュアルの管理画面用スキンのページタイプ別エントリーに説明文を追加
[nucleus-jp/nucleus-next.git] / nucleus / libs / ENCAPSULATE.php
1 <?php\r
2 /*\r
3  * Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/)\r
4  * Copyright (C) 2002-2012 The Nucleus Group\r
5  *\r
6  * This program is free software; you can redistribute it and/or\r
7  * modify it under the terms of the GNU General Public License\r
8  * as published by the Free Software Foundation; either version 2\r
9  * of the License, or (at your option) any later version.\r
10  * (see nucleus/documentation/index.html#license for more info)\r
11  */\r
12 \r
13 /**\r
14  * Part of the code for the Nucleus admin area\r
15  *\r
16  * @license http://nucleuscms.org/license.txt GNU General Public License\r
17  * @copyright Copyright (C) 2002-2012 The Nucleus Group\r
18  * @version $Id: ENCAPSULATE.php 1624 2012-01-09 11:36:20Z sakamocchi $\r
19  */\r
20 \r
21 class Encapsulate\r
22 {\r
23         /**\r
24           * Uses $call to call a function using parameters $params\r
25           * This function should return the amount of entries shown.\r
26           * When entries are show, batch operation handlers are shown too.\r
27           * When no entries were shown, $errormsg is used to display an error\r
28           *\r
29           * Passes on the amount of results found (for further encapsulation)\r
30           */\r
31         function doEncapsulate($call, $params, $errorMessage = _Encapsulate_Encapsulate_NOENTRY)\r
32         {\r
33                 if ( isset($params[3]) && !empty($params[3]) )\r
34                 {\r
35                         $templateName = $params[3];\r
36                 }\r
37                 else\r
38                 {\r
39                         $templateName = '';\r
40                 }\r
41                 $params[4] = $errorMessage;\r
42                 // start output buffering\r
43                 ob_start();\r
44                 \r
45                 $nbOfRows = call_user_func_array($call, $params);\r
46 \r
47                 // get list contents and stop buffering\r
48                 $list = ob_get_contents();\r
49                 ob_end_clean();\r
50 \r
51                 if ( $nbOfRows > 0 )\r
52                 {\r
53                         $this->showHead($templateName);\r
54                         echo $list;\r
55                         $this->showFoot($templateName);\r
56                 }\r
57                 else\r
58                 {\r
59                         echo $errorMessage;\r
60                 }\r
61 \r
62                 return $nbOfRows;\r
63         }\r
64 }\r
65 \r
66 /**\r
67   * A class used to encapsulate a list of some sort inside next/prev buttons\r
68   */\r
69 class NavList extends Encapsulate\r
70 {\r
71         function __construct($action, $start, $amount, $minamount, $maxamount, $blogid, $search, $itemid)\r
72         {\r
73                 $this->action    = $action;\r
74                 $this->start     = $start;\r
75                 $this->amount    = $amount;\r
76                 $this->minamount = $minamount;\r
77                 $this->maxamount = $maxamount;\r
78                 $this->blogid    = $blogid;\r
79                 $this->search    = $search;\r
80                 $this->itemid    = $itemid;\r
81         }\r
82 \r
83         function showBatchList($batchtype, $query, $type, $template, $errorMessage = _LISTS_NOMORE, $templateName = '')\r
84         {\r
85                 $batch = new Batch($batchtype);\r
86 \r
87                 $this->doEncapsulate(\r
88                                 array(&$batch, 'showlist'),\r
89                                 array(&$query, $type, $template, $templateName),\r
90                                 $errorMessage\r
91                 );\r
92 \r
93         }\r
94 \r
95 \r
96         function showHead()\r
97         {\r
98                 $this->showNavigation();\r
99         }\r
100         function showFoot()\r
101         {\r
102                 $this->showNavigation();\r
103         }\r
104 \r
105         /**\r
106           * Displays a next/prev bar for long tables\r
107           */\r
108         function showNavigation()\r
109         {\r
110                 $action    = $this->action;\r
111                 $start     = $this->start;\r
112                 $amount    = $this->amount;\r
113                 $minamount = $this->minamount;\r
114                 $maxamount = $this->maxamount;\r
115                 $blogid    = $this->blogid;\r
116                 $search    = Entity::hsc($this->search);\r
117                 $itemid    = $this->itemid;\r
118 \r
119                 $prev = $start - $amount;\r
120                 if ( $prev < $minamount )\r
121                 {\r
122                         $prev=$minamount;\r
123                 }\r
124 \r
125                 // maxamount not used yet\r
126         //      if ($start + $amount <= $maxamount)\r
127                         $next = $start + $amount;\r
128         //      else\r
129         //              $next = $start;\r
130 \r
131         ?>\r
132         <table class="navigation">\r
133         <tr><td>\r
134                 <form method="post" action="index.php"><div>\r
135                 <input type="submit" value="&lt;&lt; <?php echo  _LISTS_PREV?>" />\r
136                 <input type="hidden" name="blogid" value="<?php echo  $blogid; ?>" />\r
137                 <input type="hidden" name="itemid" value="<?php echo  $itemid; ?>" />\r
138                 <input type="hidden" name="action" value="<?php echo  $action; ?>" />\r
139                 <input type="hidden" name="amount" value="<?php echo  $amount; ?>" />\r
140                 <input type="hidden" name="search" value="<?php echo  $search; ?>" />\r
141                 <input type="hidden" name="start" value="<?php echo  $prev; ?>" />\r
142                 </div></form>\r
143         </td><td>\r
144                 <form method="post" action="index.php"><div>\r
145                 <input type="hidden" name="blogid" value="<?php echo  $blogid; ?>" />\r
146                 <input type="hidden" name="itemid" value="<?php echo  $itemid; ?>" />\r
147                 <input type="hidden" name="action" value="<?php echo  $action; ?>" />\r
148                 <input name="amount" size="3" value="<?php echo  $amount; ?>" /> <?php echo _LISTS_PERPAGE?>\r
149                 <input type="hidden" name="start" value="<?php echo  $start; ?>" />\r
150                 <input type="hidden" name="search" value="<?php echo  $search; ?>" />\r
151                 <input type="submit" value="&gt; <?php echo _LISTS_CHANGE?>" />\r
152                 </div></form>\r
153         </td><td>\r
154                 <form method="post" action="index.php"><div>\r
155                 <input type="hidden" name="blogid" value="<?php echo  $blogid; ?>" />\r
156                 <input type="hidden" name="itemid" value="<?php echo  $itemid; ?>" />\r
157                 <input type="hidden" name="action" value="<?php echo  $action; ?>" />\r
158                 <input type="hidden" name="amount" value="<?php echo  $amount; ?>" />\r
159                 <input type="hidden" name="start" value="0" />\r
160                 <input type="text" name="search" value="<?php echo  $search; ?>" size="7" />\r
161                 <input type="submit" value="&gt; <?php echo  _LISTS_SEARCH?>" />\r
162                 </div></form>\r
163         </td><td>\r
164                 <form method="post" action="index.php"><div>\r
165                 <input type="submit" value="<?php echo _LISTS_NEXT?> &gt; &gt;" />\r
166                 <input type="hidden" name="search" value="<?php echo  $search; ?>" />\r
167                 <input type="hidden" name="blogid" value="<?php echo  $blogid; ?>" />\r
168                 <input type="hidden" name="itemid" value="<?php echo  $itemid; ?>" />\r
169                 <input type="hidden" name="action" value="<?php echo  $action; ?>" />\r
170                 <input type="hidden" name="amount" value="<?php echo  $amount; ?>" />\r
171                 <input type="hidden" name="start" value="<?php echo  $next; ?>" />\r
172                 </div></form>\r
173         </td></tr>\r
174         </table>\r
175         <?php   }\r
176 \r
177 \r
178 }\r
179 \r
180 \r
181 /**\r
182  * A class used to encapsulate a list of some sort in a batch selection\r
183  */\r
184 class Batch extends Encapsulate\r
185 {\r
186         function __construct($type)\r
187         {\r
188                 $this->type = $type;\r
189         }\r
190 \r
191         function showHead($templateName = '')\r
192         {\r
193                 ?>\r
194                         <form method="post" action="index.php">\r
195                 <?php\r
196 // TODO: get a list op operations above the list too\r
197 // (be careful not to use the same names for the select...)\r
198 //              $this->showOperationList();\r
199         }\r
200 \r
201         function showFoot($templateName = '')\r
202         {\r
203                 $this->showOperationList();\r
204 ?>\r
205                         </form>\r
206 <?php\r
207         }\r
208 \r
209         function showOperationList()\r
210         {\r
211                 global $manager;\r
212 ?>\r
213                 <div class="batchoperations">\r
214                         <?php echo _BATCH_WITH_SEL ?>\r
215                         <select name="batchaction">\r
216                         <?php                           $options = array();\r
217                                 switch($this->type) {\r
218                                         case 'item':\r
219                                                 $options = array(\r
220                                                         'delete'        => _BATCH_ITEM_DELETE,\r
221                                                         'move'          => _BATCH_ITEM_MOVE\r
222                                                 );\r
223                                                 break;\r
224                                         case 'member':\r
225                                                 $options = array(\r
226                                                         'delete'        => _BATCH_MEMBER_DELETE,\r
227                                                         'setadmin'      => _BATCH_MEMBER_SET_ADM,\r
228                                                         'unsetadmin' => _BATCH_MEMBER_UNSET_ADM\r
229                                                 );\r
230                                                 break;\r
231                                         case 'team':\r
232                                                 $options = array(\r
233                                                         'delete'        => _BATCH_TEAM_DELETE,\r
234                                                         'setadmin'      => _BATCH_TEAM_SET_ADM,\r
235                                                         'unsetadmin' => _BATCH_TEAM_UNSET_ADM,\r
236                                                 );\r
237                                                 break;\r
238                                         case 'category':\r
239                                                 $options = array(\r
240                                                         'delete'        => _BATCH_CAT_DELETE,\r
241                                                         'move'          => _BATCH_CAT_MOVE,\r
242                                                 );\r
243                                                 break;\r
244                                         case 'comment':\r
245                                                 $options = array(\r
246                                                         'delete'        => _BATCH_COMMENT_DELETE,\r
247                                                 );\r
248                                         break;\r
249                                 }\r
250                                 foreach ($options as $option => $label) {\r
251                                         echo '<option value="',$option,'">',$label,'</option>';\r
252                                 }\r
253                         ?>\r
254                         </select>\r
255                         <input type="hidden" name="action" value="batch<?php echo $this->type?>" />\r
256                         <?php\r
257                                 $manager->addTicketHidden();\r
258 \r
259                                 // add hidden fields for 'team' and 'comment' batchlists\r
260                                 if ($this->type == 'team')\r
261                                 {\r
262                                         echo '<input type="hidden" name="blogid" value="',intRequestVar('blogid'),'" />';\r
263                                 }\r
264                                 if ($this->type == 'comment')\r
265                                 {\r
266                                         echo '<input type="hidden" name="itemid" value="',intRequestVar('itemid'),'" />';\r
267                                 }\r
268 \r
269                                 echo '<input type="submit" value="',_BATCH_EXEC,'" />';\r
270                         ?>(\r
271                          <a href="" onclick="if (event &amp;&amp; event.preventDefault) event.preventDefault(); return batchSelectAll(1); "><?php echo _BATCH_SELECTALL?></a> -\r
272                          <a href="" onclick="if (event &amp;&amp; event.preventDefault) event.preventDefault(); return batchSelectAll(0); "><?php echo _BATCH_DESELECTALL?></a>\r
273                         )\r
274                 </div>\r
275                 <?php   }\r
276 \r
277         // shortcut :)\r
278         function showList($query, $type, $template, $templateName = '', $errorMessage = _LISTS_NOMORE)\r
279         {\r
280                 return $this->doEncapsulate(    'showlist',\r
281                                                                         array($query, $type, $template, $templateName),\r
282                                                                         $errorMessage\r
283                                                                 );\r
284         }\r
285 \r
286 }\r
287 ?>\r