OSDN Git Service

skinableENCAPSULATE.phpとENCAPSULATE.phpを統合
[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                 // start output buffering\r
42                 ob_start();\r
43 \r
44                 $nbOfRows = call_user_func_array($call, $params);\r
45 \r
46                 // get list contents and stop buffering\r
47                 $list = ob_get_contents();\r
48                 ob_end_clean();\r
49 \r
50                 if ( $nbOfRows > 0 )\r
51                 {\r
52                         $this->showHead($templateName);\r
53                         echo $list;\r
54                         $this->showFoot($templateName);\r
55                 }\r
56                 else\r
57                 {\r
58                         echo $errorMessage;\r
59                 }\r
60 \r
61                 return $nbOfRows;\r
62         }\r
63 }\r
64 \r
65 /**\r
66   * A class used to encapsulate a list of some sort inside next/prev buttons\r
67   */\r
68 class NavList extends Encapsulate\r
69 {\r
70         function __construct($action, $start, $amount, $minamount, $maxamount, $blogid, $search, $itemid)\r
71         {\r
72                 $this->action    = $action;\r
73                 $this->start     = $start;\r
74                 $this->amount    = $amount;\r
75                 $this->minamount = $minamount;\r
76                 $this->maxamount = $maxamount;\r
77                 $this->blogid    = $blogid;\r
78                 $this->search    = $search;\r
79                 $this->itemid    = $itemid;\r
80         }\r
81 \r
82         function showBatchList($batchtype, $query, $type, $template, $errorMessage = _LISTS_NOMORE)\r
83         {\r
84                 $batch = new Batch($batchtype);\r
85 \r
86                 $this->doEncapsulate(\r
87                                 array(&$batch, 'showlist'),\r
88                                 array(&$query, $type, $template),\r
89                                 $errorMessage\r
90                 );\r
91 \r
92         }\r
93 \r
94 \r
95         function showHead()\r
96         {\r
97                 $this->showNavigation();\r
98         }\r
99         function showFoot()\r
100         {\r
101                 $this->showNavigation();\r
102         }\r
103 \r
104         /**\r
105           * Displays a next/prev bar for long tables\r
106           */\r
107         function showNavigation()\r
108         {\r
109                 $action    = $this->action;\r
110                 $start     = $this->start;\r
111                 $amount    = $this->amount;\r
112                 $minamount = $this->minamount;\r
113                 $maxamount = $this->maxamount;\r
114                 $blogid    = $this->blogid;\r
115                 $search    = Entity::hsc($this->search);\r
116                 $itemid    = $this->itemid;\r
117 \r
118                 $prev = $start - $amount;\r
119                 if ( $prev < $minamount )\r
120                 {\r
121                         $prev=$minamount;\r
122                 }\r
123 \r
124                 // maxamount not used yet\r
125         //      if ($start + $amount <= $maxamount)\r
126                         $next = $start + $amount;\r
127         //      else\r
128         //              $next = $start;\r
129 \r
130         ?>\r
131         <table class="navigation">\r
132         <tr><td>\r
133                 <form method="post" action="index.php"><div>\r
134                 <input type="submit" value="&lt;&lt; <?php echo  _LISTS_PREV?>" />\r
135                 <input type="hidden" name="blogid" value="<?php echo  $blogid; ?>" />\r
136                 <input type="hidden" name="itemid" value="<?php echo  $itemid; ?>" />\r
137                 <input type="hidden" name="action" value="<?php echo  $action; ?>" />\r
138                 <input type="hidden" name="amount" value="<?php echo  $amount; ?>" />\r
139                 <input type="hidden" name="search" value="<?php echo  $search; ?>" />\r
140                 <input type="hidden" name="start" value="<?php echo  $prev; ?>" />\r
141                 </div></form>\r
142         </td><td>\r
143                 <form method="post" action="index.php"><div>\r
144                 <input type="hidden" name="blogid" value="<?php echo  $blogid; ?>" />\r
145                 <input type="hidden" name="itemid" value="<?php echo  $itemid; ?>" />\r
146                 <input type="hidden" name="action" value="<?php echo  $action; ?>" />\r
147                 <input name="amount" size="3" value="<?php echo  $amount; ?>" /> <?php echo _LISTS_PERPAGE?>\r
148                 <input type="hidden" name="start" value="<?php echo  $start; ?>" />\r
149                 <input type="hidden" name="search" value="<?php echo  $search; ?>" />\r
150                 <input type="submit" value="&gt; <?php echo _LISTS_CHANGE?>" />\r
151                 </div></form>\r
152         </td><td>\r
153                 <form method="post" action="index.php"><div>\r
154                 <input type="hidden" name="blogid" value="<?php echo  $blogid; ?>" />\r
155                 <input type="hidden" name="itemid" value="<?php echo  $itemid; ?>" />\r
156                 <input type="hidden" name="action" value="<?php echo  $action; ?>" />\r
157                 <input type="hidden" name="amount" value="<?php echo  $amount; ?>" />\r
158                 <input type="hidden" name="start" value="0" />\r
159                 <input type="text" name="search" value="<?php echo  $search; ?>" size="7" />\r
160                 <input type="submit" value="&gt; <?php echo  _LISTS_SEARCH?>" />\r
161                 </div></form>\r
162         </td><td>\r
163                 <form method="post" action="index.php"><div>\r
164                 <input type="submit" value="<?php echo _LISTS_NEXT?> &gt; &gt;" />\r
165                 <input type="hidden" name="search" value="<?php echo  $search; ?>" />\r
166                 <input type="hidden" name="blogid" value="<?php echo  $blogid; ?>" />\r
167                 <input type="hidden" name="itemid" value="<?php echo  $itemid; ?>" />\r
168                 <input type="hidden" name="action" value="<?php echo  $action; ?>" />\r
169                 <input type="hidden" name="amount" value="<?php echo  $amount; ?>" />\r
170                 <input type="hidden" name="start" value="<?php echo  $next; ?>" />\r
171                 </div></form>\r
172         </td></tr>\r
173         </table>\r
174         <?php   }\r
175 \r
176 \r
177 }\r
178 \r
179 \r
180 /**\r
181  * A class used to encapsulate a list of some sort in a batch selection\r
182  */\r
183 class Batch extends Encapsulate\r
184 {\r
185         function __construct($type)\r
186         {\r
187                 $this->type = $type;\r
188         }\r
189 \r
190         function showHead($templateName = '')\r
191         {\r
192                 ?>\r
193                         <form method="post" action="index.php">\r
194                 <?php\r
195 // TODO: get a list op operations above the list too\r
196 // (be careful not to use the same names for the select...)\r
197 //              $this->showOperationList();\r
198         }\r
199 \r
200         function showFoot($templateName = '') {\r
201                 $this->showOperationList();\r
202                 ?>\r
203                         </form>\r
204                 <?php   }\r
205 \r
206         function showOperationList()\r
207         {\r
208                 global $manager;\r
209                 ?>\r
210                 <div class="batchoperations">\r
211                         <?php echo _BATCH_WITH_SEL ?>\r
212                         <select name="batchaction">\r
213                         <?php                           $options = array();\r
214                                 switch($this->type) {\r
215                                         case 'item':\r
216                                                 $options = array(\r
217                                                         'delete'        => _BATCH_ITEM_DELETE,\r
218                                                         'move'          => _BATCH_ITEM_MOVE\r
219                                                 );\r
220                                                 break;\r
221                                         case 'member':\r
222                                                 $options = array(\r
223                                                         'delete'        => _BATCH_MEMBER_DELETE,\r
224                                                         'setadmin'      => _BATCH_MEMBER_SET_ADM,\r
225                                                         'unsetadmin' => _BATCH_MEMBER_UNSET_ADM\r
226                                                 );\r
227                                                 break;\r
228                                         case 'team':\r
229                                                 $options = array(\r
230                                                         'delete'        => _BATCH_TEAM_DELETE,\r
231                                                         'setadmin'      => _BATCH_TEAM_SET_ADM,\r
232                                                         'unsetadmin' => _BATCH_TEAM_UNSET_ADM,\r
233                                                 );\r
234                                                 break;\r
235                                         case 'category':\r
236                                                 $options = array(\r
237                                                         'delete'        => _BATCH_CAT_DELETE,\r
238                                                         'move'          => _BATCH_CAT_MOVE,\r
239                                                 );\r
240                                                 break;\r
241                                         case 'comment':\r
242                                                 $options = array(\r
243                                                         'delete'        => _BATCH_COMMENT_DELETE,\r
244                                                 );\r
245                                         break;\r
246                                 }\r
247                                 foreach ($options as $option => $label) {\r
248                                         echo '<option value="',$option,'">',$label,'</option>';\r
249                                 }\r
250                         ?>\r
251                         </select>\r
252                         <input type="hidden" name="action" value="batch<?php echo $this->type?>" />\r
253                         <?php\r
254                                 $manager->addTicketHidden();\r
255 \r
256                                 // add hidden fields for 'team' and 'comment' batchlists\r
257                                 if ($this->type == 'team')\r
258                                 {\r
259                                         echo '<input type="hidden" name="blogid" value="',intRequestVar('blogid'),'" />';\r
260                                 }\r
261                                 if ($this->type == 'comment')\r
262                                 {\r
263                                         echo '<input type="hidden" name="itemid" value="',intRequestVar('itemid'),'" />';\r
264                                 }\r
265 \r
266                                 echo '<input type="submit" value="',_BATCH_EXEC,'" />';\r
267                         ?>(\r
268                          <a href="" onclick="if (event &amp;&amp; event.preventDefault) event.preventDefault(); return batchSelectAll(1); "><?php echo _BATCH_SELECTALL?></a> -\r
269                          <a href="" onclick="if (event &amp;&amp; event.preventDefault) event.preventDefault(); return batchSelectAll(0); "><?php echo _BATCH_DESELECTALL?></a>\r
270                         )\r
271                 </div>\r
272                 <?php   }\r
273 \r
274         // shortcut :)\r
275         function showList($query, $type, $template, $errorMessage = _LISTS_NOMORE, $templateName = '') {\r
276                 return $this->doEncapsulate(    'showlist',\r
277                                                                         array($query, $type, $template, $templateName),\r
278                                                                         $errorMessage\r
279                                                                 );\r
280         }\r
281 \r
282 }\r
283 ?>\r