OSDN Git Service

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