OSDN Git Service

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