- Fixed #16160: Call to undefined function ezi18n()
[tinyz:tinyz.git] / kernel / setup / steps / ezstep_database_choice.php
1 <?php
2 //
3 // Definition of eZStepDatabaseChoice class
4 //
5 // Created on: <11-Aug-2003 16:45:50 kk>
6 //
7 // ## BEGIN COPYRIGHT, LICENSE AND WARRANTY NOTICE ##
8 // SOFTWARE NAME: eZ Publish
9 // SOFTWARE RELEASE: 4.1.x
10 // COPYRIGHT NOTICE: Copyright (C) 1999-2010 eZ Systems AS
11 // SOFTWARE LICENSE: GNU General Public License v2.0
12 // NOTICE: >
13 //   This program is free software; you can redistribute it and/or
14 //   modify it under the terms of version 2.0  of the GNU General
15 //   Public License as published by the Free Software Foundation.
16 //
17 //   This program is distributed in the hope that it will be useful,
18 //   but WITHOUT ANY WARRANTY; without even the implied warranty of
19 //   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20 //   GNU General Public License for more details.
21 //
22 //   You should have received a copy of version 2.0 of the GNU General
23 //   Public License along with this program; if not, write to the Free
24 //   Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
25 //   MA 02110-1301, USA.
26 //
27 //
28 // ## END COPYRIGHT, LICENSE AND WARRANTY NOTICE ##
29 //
30
31 /*! \file
32 */
33
34
35 /*!
36   \class eZStepDatabaseChoice ezstep_database_choice.php
37   \brief The class eZStepDatabaseChoice does
38
39 */
40
41 class eZStepDatabaseChoice extends eZStepInstaller
42 {
43     /*!
44      Constructor
45     */
46     function eZStepDatabaseChoice( $tpl, $http, $ini, &$persistenceList )
47     {
48         $this->eZStepInstaller( $tpl, $http, $ini, $persistenceList,
49                                 'database_choice', 'Database choice' );
50     }
51
52     function processPostData()
53     {
54         $databaseMap = eZSetupDatabaseMap();
55         $this->PersistenceList['database_info'] = $databaseMap[$this->Http->postVariable( 'eZSetupDatabaseType' )];
56         return true;
57     }
58
59     function init()
60     {
61         $databaseMap = eZSetupDatabaseMap();
62
63         if ( $this->hasKickstartData() )
64         {
65             $data = $this->kickstartData();
66             $extension = $data['Type'];
67             $map = array( 'postgresql' => 'pgsql' );
68             if ( isset( $map[$extension] ) )
69                 $extension = $map[$extension];
70
71             if ( isset( $databaseMap[$extension] ) )
72             {
73                 $this->PersistenceList['database_info'] = $databaseMap[$extension];
74                 return $this->kickstartContinueNextStep();
75             }
76         }
77
78         if ( eZSetupTestInstaller() == 'windows' )
79         {
80             $this->PersistenceList['database_info'] = $databaseMap['mysql'];
81             return true;
82         }
83
84         $databaseMap = eZSetupDatabaseMap();
85         $database = null;
86         $databaseCount = 0;
87         if ( isset( $this->PersistenceList['database_extensions']['found'] ) )
88         {
89             $databaseExtensions = $this->PersistenceList['database_extensions']['found'];
90             foreach ( $databaseExtensions as $extension )
91             {
92                 if ( !isset( $databaseMap[$extension] ) )
93                     continue;
94                 $database = $databaseMap[$extension];
95                 $database['name'] = null;
96                 $databaseCount++;
97             }
98         }
99
100         if ( $databaseCount != 1 )
101         {
102             return false;
103         }
104
105         $this->PersistenceList['database_info'] = $database;
106
107         return true;
108     }
109
110     function display()
111     {
112         $databaseMap = eZSetupDatabaseMap();
113         $availableDatabases = array();
114         $databaseList = array();
115         if ( isset( $this->PersistenceList['database_extensions']['found'] ) )
116         {
117             $databaseExtensions = $this->PersistenceList['database_extensions']['found'];
118             foreach ( $databaseExtensions as $extension )
119             {
120                 if ( !isset( $databaseMap[$extension] ) )
121                     continue;
122                 $databaseList[] = $databaseMap[$extension];
123                 if ( $databaseMap[$extension]['type'] == 'mysql' or $databaseMap[$extension]['type'] == 'mysqli' )
124                 {
125                     $availableDatabases['mysql'] = true;
126                 }
127                 elseif ( $databaseMap[$extension]['type'] == 'postgresql' )
128                 {
129                     $availableDatabases['postgresql'] = true;
130                 }
131             }
132         }
133
134         $databaseInfo = $databaseList[0];
135         if ( isset( $this->PersistenceList['database_info'] ) )
136             $databaseInfo = $this->PersistenceList['database_info'];
137
138         $this->Tpl->setVariable( 'database_list', $databaseList );
139         $this->Tpl->setVariable( 'database_info', $databaseInfo );
140         $this->Tpl->setVariable( 'available_databases', $availableDatabases );
141
142         $result = array();
143         // Display template
144         $result['content'] = $this->Tpl->fetch( "design:setup/init/database_choice.tpl" );
145         $result['path'] = array( array( 'text' => ezpI18n::translate( 'design/standard/setup/init',
146                                                           'Database choice' ),
147                                         'url' => false ) );
148         return $result;
149     }
150
151 }
152
153 ?>