OSDN Git Service

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