- Fixed #16160: Call to undefined function ezi18n()
[tinyz:tinyz.git] / kernel / section / list.php
1 <?php
2 //
3 // Created on: <27-Aug-2002 15:42:43 bf>
4 //
5 // ## BEGIN COPYRIGHT, LICENSE AND WARRANTY NOTICE ##
6 // SOFTWARE NAME: eZ Publish
7 // SOFTWARE RELEASE: 4.1.x
8 // COPYRIGHT NOTICE: Copyright (C) 1999-2010 eZ Systems AS
9 // SOFTWARE LICENSE: GNU General Public License v2.0
10 // NOTICE: >
11 //   This program is free software; you can redistribute it and/or
12 //   modify it under the terms of version 2.0  of the GNU General
13 //   Public License as published by the Free Software Foundation.
14 //
15 //   This program is distributed in the hope that it will be useful,
16 //   but WITHOUT ANY WARRANTY; without even the implied warranty of
17 //   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 //   GNU General Public License for more details.
19 //
20 //   You should have received a copy of version 2.0 of the GNU General
21 //   Public License along with this program; if not, write to the Free
22 //   Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
23 //   MA 02110-1301, USA.
24 //
25 //
26 // ## END COPYRIGHT, LICENSE AND WARRANTY NOTICE ##
27 //
28
29 require_once( 'kernel/common/template.php' );
30 $http = eZHTTPTool::instance();
31 $Module = $Params['Module'];
32 $tpl = templateInit();
33 $tpl->setVariable( 'module', $Module );
34
35 $offset = $Params['Offset'];
36
37 if( eZPreferences::value( 'admin_section_list_limit' ) )
38 {
39     switch( eZPreferences::value( 'admin_section_list_limit' ) )
40     {
41         case '2': { $limit = 25; } break;
42         case '3': { $limit = 50; } break;
43         default:  { $limit = 10; } break;
44     }
45 }
46 else
47 {
48     $limit = 10;
49 }
50
51 if ( $http->hasPostVariable( 'CreateSectionButton' ) )
52 {
53     $Module->redirectTo( $Module->functionURI( "edit" ) . '/0/' );
54     return;
55 }
56
57 if ( $http->hasPostVariable( 'RemoveSectionButton' ) )
58 {
59     $currentUser = eZUser::currentUser();
60     $accessResult = $currentUser->hasAccessTo( 'section', 'edit' );
61     if ( $accessResult['accessWord'] == 'yes' )
62     {
63         if ( $http->hasPostVariable( 'SectionIDArray' ) )
64         {
65             $sectionIDArray = $http->postVariable( 'SectionIDArray' );
66
67             $sections = array();
68             $sectionIDs = array();
69             $sectionsUnallowed = array();
70             foreach ( $sectionIDArray as $sectionID )
71             {
72                 $section = eZSection::fetch( $sectionID );
73                 if ( is_object( $section ) )
74                 {
75                     if ( $section->canBeRemoved() )
76                     {
77                         $sections[] = $section;
78                         $sectionIDs[] = $sectionID;
79                     }
80                     else
81                     {
82                         $sectionsUnallowed[] = $section;
83                     }
84                 }
85             }
86
87             if ( count( $sections) > 0 or
88                  count( $sectionsUnallowed ) > 0 )
89             {
90                 $http->setSessionVariable( 'SectionIDArray', $sectionIDs );
91                 $tpl->setVariable( 'delete_result', $sections ); // deprecated, left for BC
92                 $tpl->setVariable( 'allowed_sections', $sections );
93                 $tpl->setVariable( 'unallowed_sections', $sectionsUnallowed );
94
95                 $Result = array();
96                 $Result['content'] = $tpl->fetch( "design:section/confirmremove.tpl" );
97                 $Result['path'] = array( array( 'url' => false,
98                                                 'text' => ezpI18n::translate( 'kernel/section', 'Sections' ) ) );
99                 return;
100             }
101         }
102     }
103     else
104     {
105         return $Module->handleError( eZError::KERNEL_ACCESS_DENIED, 'kernel' );
106     }
107 }
108
109 if ( $http->hasPostVariable( 'ConfirmRemoveSectionButton' ) )
110 {
111     $currentUser = eZUser::currentUser();
112     $accessResult = $currentUser->hasAccessTo( 'section', 'edit' );
113     if ( $accessResult['accessWord'] == 'yes' )
114     {
115         if ( $http->hasSessionVariable( 'SectionIDArray' ) )
116         {
117             $sectionIDArray = $http->sessionVariable( 'SectionIDArray' );
118
119             $db = eZDB::instance();
120             $db->begin();
121             foreach ( $sectionIDArray as $sectionID )
122             {
123                 $section = eZSection::fetch( $sectionID );
124                 if ( is_object( $section ) and
125                      $section->canBeRemoved() )
126                 {
127                     // Clear content cache if needed
128                     eZContentCacheManager::clearContentCacheIfNeededBySectionID( $sectionID );
129                     $section->remove();
130                 }
131             }
132             $db->commit();
133         }
134     }
135     else
136     {
137         return $Module->handleError( eZError::KERNEL_ACCESS_DENIED, 'kernel' );
138     }
139 }
140
141 $viewParameters = array( 'offset' => $offset );
142 $sectionArray = eZSection::fetchByOffset( $offset, $limit );
143 $sectionCount = eZSection::sectionCount();
144
145 $currentUser = eZUser::currentUser();
146 $allowedAssignSectionList = $currentUser->canAssignSectionList();
147
148 $tpl->setVariable( "limit", $limit );
149 $tpl->setVariable( 'section_array', $sectionArray );
150 $tpl->setVariable( 'section_count', $sectionCount );
151 $tpl->setVariable( 'view_parameters', $viewParameters );
152 $tpl->setVariable( 'allowed_assign_sections', $allowedAssignSectionList );
153
154 $Result = array();
155 $Result['content'] = $tpl->fetch( "design:section/list.tpl" );
156 $Result['path'] = array( array( 'url' => false,
157                                 'text' => ezpI18n::translate( 'kernel/section', 'Sections' ) ) );
158
159 ?>