- Fixed #16160: Call to undefined function ezi18n()
[tinyz:tinyz.git] / kernel / package / create.php
1 <?php
2 //
3 // Created on: <21-Nov-2003 11:37:53 amos>
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 $module = $Params['Module'];
31
32 $http = eZHTTPTool::instance();
33
34 $creator = false;
35 $initializeStep = false;
36 if ( $module->isCurrentAction( 'CreatePackage' ) )
37 {
38     $creatorID = $module->actionParameter( 'CreatorItemID' );
39     if ( $creatorID )
40     {
41         $creator = eZPackageCreationHandler::instance( $creatorID );
42         $persistentData = array();
43         $http->setSessionVariable( 'eZPackageCreatorData' . $creatorID, $persistentData );
44         $initializeStep = true;
45         $package = false;
46         if ( isset( $persistentData['package_name'] ) )
47             $package = eZPackage::fetch( $persistentData['package_name'] );
48         $creator->generateStepMap( $package, $persistentData );
49     }
50 }
51 else if ( $module->isCurrentAction( 'PackageStep' ) )
52 {
53     if ( $module->hasActionParameter( 'CreatorItemID' ) )
54     {
55         $creatorID = $module->actionParameter( 'CreatorItemID' );
56         $creator = eZPackageCreationHandler::instance( $creatorID );
57         if ( $http->hasSessionVariable( 'eZPackageCreatorData' . $creatorID ) )
58             $persistentData = $http->sessionVariable( 'eZPackageCreatorData' . $creatorID );
59         else
60             $persistentData = array();
61         $package = false;
62         if ( isset( $persistentData['package_name'] ) )
63             $package = eZPackage::fetch( $persistentData['package_name'] );
64         $creator->generateStepMap( $package, $persistentData );
65     }
66 }
67
68 $tpl = templateInit();
69
70 $templateName = 'design:package/create.tpl';
71 if ( $creator )
72 {
73     $currentStepID = false;
74     if ( $module->hasActionParameter( 'CreatorStepID' ) )
75         $currentStepID = $module->actionParameter( 'CreatorStepID' );
76     $steps =& $creator->stepMap();
77     if ( !isset( $steps['map'][$currentStepID] ) )
78         $currentStepID = $steps['first']['id'];
79     $errorList = array();
80     $hasAdvanced = false;
81
82     $lastStepID = $currentStepID;
83     if ( $module->hasActionParameter( 'NextStep' ) )
84     {
85         $hasAdvanced = true;
86         $currentStepID = $creator->validateStep( $package, $http, $currentStepID, $steps, $persistentData, $errorList );
87         if ( $currentStepID != $lastStepID )
88         {
89             $lastStep =& $steps['map'][$lastStepID];
90             $creator->commitStep( $package, $http, $lastStep, $persistentData, $tpl );
91             $initializeStep = true;
92         }
93     }
94
95     if ( $currentStepID )
96     {
97         $currentStep =& $steps['map'][$currentStepID];
98
99         $stepTemplate = $creator->stepTemplate( $currentStep );
100         $stepTemplateName = $stepTemplate['name'];
101         $stepTemplateDir = $stepTemplate['dir'];
102
103         if ( $initializeStep )
104             $creator->initializeStep( $package, $http, $currentStep, $persistentData, $tpl );
105
106         $creator->loadStep( $package, $http, $currentStepID, $persistentData, $tpl, $module );
107         if ( $package )
108             $persistentData['package_name'] = $package->attribute( 'name' );
109
110         $http->setSessionVariable( 'eZPackageCreatorData' . $creatorID, $persistentData );
111
112         $tpl->setVariable( 'creator', $creator );
113         $tpl->setVariable( 'current_step', $currentStep );
114         $tpl->setVariable( 'persistent_data', $persistentData );
115         $tpl->setVariable( 'error_list', $errorList );
116         $tpl->setVariable( 'package', $package );
117
118         $templateName = "design:package/$stepTemplateDir/$stepTemplateName";
119     }
120     else
121     {
122         $creator->finalize( $package, $http, $persistentData );
123         $package->setAttribute( 'is_active', true );
124         $http->removeSessionVariable( 'eZPackageCreatorData' . $creatorID );
125         if ( $package )
126             return $module->redirectToView( 'view', array( 'full', $package->attribute( 'name' ) ) );
127         else
128             return $module->redirectToView( 'list' );
129     }
130 }
131 else
132 {
133     $creators =& eZPackageCreationHandler::creatorList( true );
134
135     $tpl->setVariable( 'creator_list', $creators );
136 }
137
138 $Result = array();
139 $Result['content'] = $tpl->fetch( $templateName );
140 $Result['path'] = array( array( 'url' => false,
141                                 'text' => ezpI18n::translate( 'kernel/package', 'Create package' ) ) );
142 ?>