- Fixed #16160: Call to undefined function ezi18n()
[tinyz:tinyz.git] / kernel / content / removeobject.php
1 <?php
2 //
3 //
4 // Created on: <08-Nov-2002 16:02:26 wy>
5 //
6 // ## BEGIN COPYRIGHT, LICENSE AND WARRANTY NOTICE ##
7 // SOFTWARE NAME: eZ Publish
8 // SOFTWARE RELEASE: 4.1.x
9 // COPYRIGHT NOTICE: Copyright (C) 1999-2010 eZ Systems AS
10 // SOFTWARE LICENSE: GNU General Public License v2.0
11 // NOTICE: >
12 //   This program is free software; you can redistribute it and/or
13 //   modify it under the terms of version 2.0  of the GNU General
14 //   Public License as published by the Free Software Foundation.
15 //
16 //   This program is distributed in the hope that it will be useful,
17 //   but WITHOUT ANY WARRANTY; without even the implied warranty of
18 //   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19 //   GNU General Public License for more details.
20 //
21 //   You should have received a copy of version 2.0 of the GNU General
22 //   Public License along with this program; if not, write to the Free
23 //   Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
24 //   MA 02110-1301, USA.
25 //
26 //
27 // ## END COPYRIGHT, LICENSE AND WARRANTY NOTICE ##
28 //
29
30 require_once( "kernel/common/template.php" );
31
32 $Module = $Params['Module'];
33
34 $http = eZHTTPTool::instance();
35
36 $viewMode = $http->sessionVariable( "CurrentViewMode" );
37 $deleteIDArray = $http->sessionVariable( "DeleteIDArray" );
38 $contentObjectID = $http->sessionVariable( 'ContentObjectID' );
39 $contentNodeID = $http->sessionVariable( 'ContentNodeID' );
40
41 $requestedURI = '';
42 $userRedirectURI = '';
43 $requestedURI = $GLOBALS['eZRequestedURI'];
44 if ( $requestedURI instanceof eZURI )
45 {
46     $userRedirectURI = $requestedURI->uriString( true );
47 }
48 $http->setSessionVariable( 'userRedirectURIReverseRelatedList', $userRedirectURI );
49
50 if ( $http->hasSessionVariable( 'ContentLanguage' ) )
51 {
52     $contentLanguage = $http->sessionVariable( 'ContentLanguage' );
53 }
54 else
55 {
56     $contentLanguage = false;
57 }
58 if ( count( $deleteIDArray ) <= 0 )
59     return $Module->redirectToView( 'view', array( $viewMode, $contentNodeID, $contentLanguage ) );
60
61 // Cleanup and redirect back when cancel is clicked
62 if ( $http->hasPostVariable( "CancelButton" ) )
63 {
64     $http->removeSessionVariable( "CurrentViewMode" );
65     $http->removeSessionVariable( "DeleteIDArray" );
66     $http->removeSessionVariable( 'ContentObjectID' );
67     $http->removeSessionVariable( 'ContentNodeID' );
68     $http->removeSessionVariable( 'userRedirectURIReverseRelatedList' );
69     $http->removeSessionVariable( 'HideRemoveConfirmation' );
70     $http->removeSessionVariable( 'RedirectURIAfterRemove' );
71
72     if ( $http->hasSessionVariable( 'RedirectIfCancel' )
73       && $http->sessionVariable( 'RedirectIfCancel' ) )
74     {
75         $Module->redirectTo( $http->sessionVariable( 'RedirectIfCancel' ) );
76         return $http->removeSessionVariable( 'RedirectIfCancel' );
77     }
78     else
79     {
80         return $Module->redirectToView( 'view', array( $viewMode, $contentNodeID, $contentLanguage ) );
81     }
82 }
83
84 $contentINI = eZINI::instance( 'content.ini' );
85
86 $RemoveAction = $contentINI->hasVariable( 'RemoveSettings', 'DefaultRemoveAction' ) ?
87                    $contentINI->variable( 'RemoveSettings', 'DefaultRemoveAction' ) : 'trash';
88 if ( $RemoveAction != 'trash' and $RemoveAction != 'delete' )
89     $RemoveAction = 'trash';
90
91 $moveToTrash = ( $RemoveAction == 'trash' ) ? true : false;
92 if ( $http->hasPostVariable( 'SupportsMoveToTrash' ) )
93 {
94     if ( $http->hasPostVariable( 'MoveToTrash' ) )
95         $moveToTrash = $http->postVariable( 'MoveToTrash' ) ? true : false;
96     else
97         $moveToTrash = false;
98 }
99
100 $hideRemoveConfirm = $contentINI->hasVariable( 'RemoveSettings', 'HideRemoveConfirmation' ) ?
101                      (( $contentINI->variable( 'RemoveSettings', 'HideRemoveConfirmation' ) == 'true' ) ? true : false ) : false;
102 if ( $http->hasSessionVariable( 'HideRemoveConfirmation' ) )
103     $hideRemoveConfirm = $http->sessionVariable( 'HideRemoveConfirmation' );
104
105 if ( $http->hasPostVariable( "ConfirmButton" ) or
106      $hideRemoveConfirm )
107 {
108     if ( eZOperationHandler::operationIsAvailable( 'content_delete' ) )
109     {
110         $operationResult = eZOperationHandler::execute( 'content',
111                                                         'delete',
112                                                          array( 'node_id_list' => $deleteIDArray,
113                                                                 'move_to_trash' => $moveToTrash ),
114                                                           null, true );
115     }
116     else
117     {
118         eZContentOperationCollection::deleteObject( $deleteIDArray, $moveToTrash );
119     }
120
121     if ( $http->hasSessionVariable( 'RedirectURIAfterRemove' )
122       && $http->sessionVariable( 'RedirectURIAfterRemove' ) )
123     {
124         $Module->redirectTo( $http->sessionVariable( 'RedirectURIAfterRemove' ) );
125         $http->removeSessionVariable( 'RedirectURIAfterRemove' );
126         return $http->removeSessionVariable( 'RedirectIfCancel' );
127     }
128     else
129     {
130         return $Module->redirectToView( 'view', array( $viewMode, $contentNodeID, $contentLanguage ) );
131     }
132 }
133
134 $showCheck = $contentINI->hasVariable( 'RemoveSettings', 'ShowRemoveToTrashCheck' ) ?
135              (( $contentINI->variable( 'RemoveSettings', 'ShowRemoveToTrashCheck' ) == 'false' ) ? false : true ) : true;
136
137 $info               = eZContentObjectTreeNode::subtreeRemovalInformation( $deleteIDArray );
138 $deleteResult       = $info['delete_list'];
139 $moveToTrashAllowed = $info['move_to_trash'];
140 $totalChildCount    = $info['total_child_count'];
141 $exceededLimit      = false;
142 $deleteNodeArray    = array();
143
144 // Check if number of nodes being removed not more then MaxNodesRemoveSubtree setting.
145 $maxNodesRemoveSubtree = $contentINI->hasVariable( 'RemoveSettings', 'MaxNodesRemoveSubtree' ) ?
146                             $contentINI->variable( 'RemoveSettings', 'MaxNodesRemoveSubtree' ) : 100;
147
148 $deleteItemsExist = true; // If false, we should disable 'OK' button if count of each deletion items more then MaxNodesRemoveSubtree setting.
149
150 foreach ( array_keys( $deleteResult ) as $removeItemKey )
151 {
152     $removeItem =& $deleteResult[$removeItemKey];
153     $deleteNodeArray[] = $removeItem['node'];
154     if ( $removeItem['child_count'] > $maxNodesRemoveSubtree )
155     {
156         $removeItem['exceeded_limit_of_subitems'] = true;
157         $exceededLimit = true;
158         $nodeObj = $removeItem['node'];
159         if ( !$nodeObj )
160             continue;
161
162         $nodeID = $nodeObj->attribute( 'node_id' );
163         $deleteIDArrayNew = array();
164         foreach ( $deleteIDArray as $deleteID )
165         {
166             if ( $deleteID != $nodeID )
167                 $deleteIDArrayNew[] = $deleteID;
168         }
169         $deleteItemsExist = count( $deleteIDArrayNew ) != 0;
170         $http->setSessionVariable( "DeleteIDArray", $deleteIDArrayNew );
171     }
172 }
173
174 // We check if we can remove the nodes without confirmation
175 // to do this the following must be true:
176 // - The total child count must be zero
177 // - There must be no object removal (i.e. it is the only node for the object)
178 if ( $totalChildCount == 0 )
179 {
180     $canRemove = true;
181     foreach ( $deleteResult as $item )
182     {
183         if ( $item['object_node_count'] <= 1 )
184         {
185             $canRemove = false;
186             break;
187         }
188     }
189     if ( $canRemove )
190     {
191         if ( eZOperationHandler::operationIsAvailable( 'content_removelocation' ) )
192         {
193             $operationResult = eZOperationHandler::execute( 'content',
194                                                             'removelocation',
195                                                              array( 'node_id' => $contentNodeID,
196                                                                     'object_id' => $contentObjectID,
197                                                                     'node_list' => $deleteNodeArray,
198                                                                     'move_to_trash' => $moveToTrash ),
199                                                               null, true );
200         }
201         else
202         {
203             eZContentOperationCollection::removeAssignment( $contentNodeID, $contentObjectID, $deleteNodeArray, $moveToTrash );
204         }
205
206         if ( $http->hasSessionVariable( 'RedirectURIAfterRemove' )
207           && $http->sessionVariable( 'RedirectURIAfterRemove' ) )
208         {
209             $Module->redirectTo( $http->sessionVariable( 'RedirectURIAfterRemove' ) );
210             $http->removeSessionVariable( 'RedirectURIAfterRemove' );
211             return $http->removeSessionVariable( 'RedirectIfCancel' );
212         }
213         else
214         {
215             return $Module->redirectToView( 'view', array( $viewMode, $contentNodeID, $contentLanguage ) );
216         }
217     }
218 }
219
220 $tpl = templateInit();
221
222 $tpl->setVariable( 'reverse_related'        , $info['reverse_related_count'] );
223 $tpl->setVariable( 'module'                 , $Module );
224 $tpl->setVariable( 'moveToTrashAllowed'     , $moveToTrashAllowed ); // Backwards compatibility
225 $tpl->setVariable( 'ChildObjectsCount'      , $totalChildCount ); // Backwards compatibility
226 $tpl->setVariable( 'DeleteResult'           , $deleteResult ); // Backwards compatibility
227 $tpl->setVariable( 'move_to_trash_allowed'  , ( $moveToTrashAllowed and $showCheck ) );
228 $tpl->setVariable( 'remove_list'            , $deleteResult );
229 $tpl->setVariable( 'total_child_count'      , $totalChildCount );
230 $tpl->setVariable( 'remove_info'            , $info );
231 $tpl->setVariable( 'exceeded_limit'         , $exceededLimit );
232 $tpl->setVariable( 'delete_items_exist'     , $deleteItemsExist );
233 $tpl->setVariable( 'move_to_trash'          , $moveToTrash );
234
235 $Result = array();
236 $Result['content'] = $tpl->fetch( "design:node/removeobject.tpl" );
237 $Result['path'] = array( array( 'url' => false,
238                                 'text' => ezpI18n::translate( 'kernel/content', 'Remove object' ) ) );
239 ?>