source: branches/release-1_3/admin/install.php @ 372

Last change on this file since 372 was 372, checked in by z0rglub, 20 years ago

changing error reporting level to stay calm when undefined indexes are found
in language files

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 11.2 KB
Line 
1<?php
2/***************************************************************************
3 *                                install.php                              *
4 *                            -------------------                          *
5 *   application   : PhpWebGallery 1.3 <http://phpwebgallery.net>          *
6 *   author        : Pierrick LE GALL <pierrick@z0rglub.com>               *
7 *                                                                         *
8 *   $Id: install.php 372 2004-02-24 23:10:37Z z0rglub $
9 *                                                                         *
10 ***************************************************************************/
11
12/***************************************************************************
13 *                                                                         *
14 *   This program is free software; you can redistribute it and/or modify  *
15 *   it under the terms of the GNU General Public License as published by  *
16 *   the Free Software Foundation;                                         *
17 *                                                                         *
18 ***************************************************************************/
19
20//-------------------------------------------------------------------- includes
21define( 'PREFIX_INCLUDE', '.' );
22include( '../include/vtemplate.class.php' );
23include( '../include/functions.inc.php' );
24//----------------------------------------------------- template initialization
25$vtp = new VTemplate;
26$handle = $vtp->Open( '../template/default/admin/install.vtp' );
27$vtp->setGlobalVar( $handle, 'release', '1.3' );
28//-------------------------------------------------------------------- language
29if ( isset( $_GET['language'] ) )
30{
31  $isadmin = true;
32  $lang = array();
33  error_reporting( E_ALL ^ E_NOTICE );
34  include( '../language/'.$_GET['language'].'.php' );
35  $tpl = array( 'step1_err_copy', 'step1_err_copy_2', 'step1_err_copy_next',
36                'errors_title', 'step1_title','step1_host','step1_host_info',
37                'step1_user','step1_user_info','step1_pass','step1_pass_info',
38                'step1_database','step1_database_info','step1_prefix',
39                'step1_prefix_info','submit','infos_title','step2_title',
40                'conf_general_webmaster','conf_general_webmaster_info',
41                'step2_pwd','step2_pwd_info','step2_pwd_conf',
42                'step2_pwd_conf_info','conf_general_mail',
43                'conf_general_mail_info','install_end_title',
44                'install_end_message','install_help');
45  templatize_array( $tpl, 'lang', $handle );
46  $vtp->setGlobalVar( $handle, 'language', $_GET['language'] );
47}
48//---------------------- Step 1 : connection informations, write of config file
49if ( isset($_GET['step']) && $_GET['step'] == 1 )
50{
51  $errors = array();
52  $infos  = array();
53  // creation of ./include/mysql.inc.php : file containing database
54  // connection informations
55  if ( isset( $_POST['cfgBase'] )
56       and isset( $_POST['cfgUser'] )
57       and isset( $_POST['cfgPassword'] )
58       and isset( $_POST['cfgHote'] ) )
59  {
60    if ( @mysql_connect( $_POST['cfgHote'],
61                         $_POST['cfgUser'],
62                         $_POST['cfgPassword'] ) )
63    {
64      if ( @mysql_select_db($_POST['cfgBase'] ) )
65      {
66        array_push( $infos, $lang['step1_confirmation'] );
67      }
68      else
69      {
70        array_push( $errors, $lang['step1_err_db'] );
71      }
72    }
73    else
74    {
75      array_push( $errors, $lang['step1_err_server'] );
76    }
77
78    $config_file = '../include/mysql.inc.php';
79   
80    if ( count( $errors ) == 0 )
81    {
82      $file_content = "<?php";
83      $file_content.= "\n\$cfgBase = '".     $_POST['cfgBase']."';";
84      $file_content.= "\n\$cfgUser = '".     $_POST['cfgUser']."';";
85      $file_content.= "\n\$cfgPassword = '". $_POST['cfgPassword']."';";
86      $file_content.= "\n\$cfgHote = '".     $_POST['cfgHote']."';";
87      $file_content.= "\n\$prefixeTable = '".$_POST['prefixeTable']."';";
88      $file_content.= "\n?>";
89      // writting the configuration file
90      if ( $fp = @fopen( $config_file, 'a+' ) )
91      {
92        fwrite( $fp, $file_content ); 
93        fclose( $fp );
94      }
95      $cfgHote     = '';
96      $cfgUser     = '';
97      $cfgPassword = '';
98      $cfgBase     = '';
99      if ( is_file( $config_file ) ) include( $config_file );
100      $file_OK = false;
101      if ( @mysql_connect( $cfgHote, $cfgUser, $cfgPassword ) )
102      {
103        if ( @mysql_select_db( $cfgBase ) ) $file_OK = true;
104      }
105      if ( !$file_OK )
106      {
107        $vtp->addSession( $handle, 'error_copy' );
108        $html_content = htmlentities( $file_content, ENT_QUOTES );
109        $html_content = nl2br( $html_content );
110        $vtp->setVar( $handle, 'error_copy.file_content', $html_content );
111        $vtp->closeSession( $handle, 'error_copy' );
112      }
113      else
114      {
115        $url = 'install.php?step=2&language='.$_GET['language'];
116        header( 'Request-URI: '.$url ); 
117        header( 'Content-Location: '.$url); 
118        header( 'Location: '.$url );
119        exit();
120      }
121    }
122  }
123  // errors display
124  if ( sizeof( $errors ) != 0 )
125  {
126    $vtp->addSession( $handle, 'errors' );
127    foreach ( $errors as $error ) {
128      $vtp->addSession( $handle, 'error' );
129      $vtp->setVar( $handle, 'error.content', $error );
130      $vtp->closeSession( $handle, 'error' );
131    }
132    $vtp->closeSession( $handle, 'errors' );
133  }
134  // infos display
135  if ( sizeof( $infos ) != 0 )
136  {
137    $vtp->addSession( $handle, 'infos' );
138    foreach ( $infos as $info ) {
139      $vtp->addSession( $handle, 'info' );
140      $vtp->setVar( $handle, 'info.content', $info );
141      $vtp->closeSession( $handle, 'info' );
142    }
143    $vtp->closeSession( $handle, 'infos' );
144  }
145  // form display (if necessary)
146  if ( !isset( $_POST['submit'] ) or sizeof( $errors ) > 0 )
147  {
148    $vtp->addSession( $handle, 'step1' );
149
150    // host
151    if ( !isset( $_POST['cfgHote'] ) )
152      $vtp->setVar( $handle, 'step1.f_host', 'localhost' );
153    else
154      $vtp->setVar( $handle, 'step1.f_host', $_POST['cfgHote'] );
155    // user
156        if ( isset( $_POST['cfgUser'] ) )
157            $vtp->setVar( $handle, 'step1.f_user', $_POST['cfgUser'] );
158    // base
159        if ( isset( $_POST['cfgBase'] ) )
160            $vtp->setVar( $handle, 'step1.f_base', $_POST['cfgBase'] );
161    // prefixeTable
162    if ( !isset( $_POST['prefixeTable'] ) )
163      $vtp->setVar( $handle, 'step1.f_prefixeTable', 'phpwebgallery_' );
164    else
165      $vtp->setVar( $handle, 'step1.f_prefixeTable', $_POST['prefixeTable'] );
166
167    $vtp->closeSession( $handle, 'step1' );
168  }
169}
170//------------------------------------- Step 2 : creation of tables in database
171else if (  isset($_GET['step']) && $_GET['step'] == 2 )
172{
173  $errors = array();
174  $infos  = array();
175
176  include( '../include/mysql.inc.php' );
177  mysql_connect( $cfgHote, $cfgUser, $cfgPassword )
178    or die ( "Can't connect to database host" );
179  mysql_select_db( $cfgBase )
180    or die ( "Connection to host succeeded, but database selection failed" );
181               
182  if ( !isset( $_POST['submit'] ) )
183  {
184    // tables creation, based on phpwebgallery_structure.sql
185    $sql_lines = file( './phpwebgallery_structure.sql' );
186    $query = '';
187    foreach ( $sql_lines as $sql_line ) {
188      $sql_line = trim( $sql_line );
189      if ( preg_match( '/(^--|^$)/', $sql_line ) ) continue;
190      $query.= ' '.$sql_line;
191      // if we reached the end of query, we execute it and reinitialize the
192      // variable "query"
193      if ( preg_match( '/;$/', $sql_line ) )
194      {
195        $query = trim( $query );
196        $query = str_replace( 'phpwebgallery_', $prefixeTable, $query );
197        // we don't execute "DROP TABLE" queries
198        if ( !preg_match( '/^DROP TABLE/i', $query ) )
199          mysql_query( $query );
200        $query = '';
201      }
202    }
203  }
204
205  if ( isset( $_POST['submit'] ) )
206  {
207    // webmaster login must be
208    // 1. non empty
209    // 2. without characters ' or "
210    $webmaster = preg_replace( '/\s{2,}/', ' ', $_POST['webmaster'] );
211    $webmaster = trim( $webmaster );
212    if ( $webmaster == '' )
213      array_push( $errors, $lang['step2_err_login1'] );
214    if ( preg_match( '/[\'"]/', $webmaster ) )
215      array_push( $errors, $lang['step2_err_login3'] );
216    // the webmaster string must be the same as its confirmation
217    if ( $_POST['pwdWebmaster'] != $_POST['pwdWebmasterConf'] )
218      array_push( $errors, $lang['step2_err_pass'] );
219    // mail address must have this format : name@server.com
220    $error_mail_address = validate_mail_address( $_POST['mail_webmaster'] );
221    if ( $error_mail_address != '' )
222      array_push( $errors, $error_mail_address );
223    if ( $_POST['mail_webmaster'] == '' )
224      array_push( $errors, $lang['reg_err_mail_address'] );
225
226    // if no error found till here : insertion of data in tables
227    if ( count( $errors ) == 0 )
228    {
229      $query = 'DELETE FROM '.$prefixeTable.'config';
230      mysql_query( $query );
231
232      $query = 'INSERT INTO '.$prefixeTable.'config';
233      $query.= ' (webmaster,mail_webmaster) VALUES ';
234      $query.= " ('".$webmaster."','".$_POST['mail_webmaster']."')";
235      $query.= ';';
236      mysql_query( $query );
237
238      $query = 'INSERT INTO '.$prefixeTable.'sites';
239      $query.= " (id,galleries_url) VALUES (1, './galleries/')";
240      $query.= ';';
241      mysql_query( $query );
242
243      // webmaster admin user
244      $query = 'INSERT INTO '.$prefixeTable.'users';
245      $query.= ' (id,username,password,status,language,mail_address) VALUES ';
246      $query.= "(1,'".$webmaster."','".md5( $_POST['pwdWebmaster'] )."'";
247      $query.= ",'admin','".$_GET['language']."'";
248      $query.= ",'".$_POST['mail_webmaster']."')";
249      $query.= ';';
250      mysql_query($query);
251
252      // guest user
253      $query = 'INSERT INTO '.$prefixeTable.'users';
254      $query.= '(id,username,password,status,language) VALUES ';
255      $query.= "(2,'guest','','guest','".$_GET['language']."')";
256      $query.= ';';
257      mysql_query( $query );
258    }
259  }
260
261  // errors display
262  if ( sizeof( $errors ) != 0 )
263  {
264    $vtp->addSession( $handle, 'errors' );
265    foreach ( $errors as $error ) {
266      $vtp->addSession( $handle, 'error' );
267      $vtp->setVar( $handle, 'error.content', $error );
268      $vtp->closeSession( $handle, 'error' );
269      }
270    $vtp->closeSession( $handle, 'errors' );
271  }
272
273  if ( !isset( $_POST['submit'] ) or sizeof( $errors ) > 0 )
274  {
275    $vtp->addSession( $handle, 'step2' );
276        if ( isset( $_POST['webmaster'] ))
277    $vtp->setVar( $handle, 'step2.f_webmaster', $_POST['webmaster'] );
278        if ( isset( $_POST['mail_webmaster'] ))
279    $vtp->setVar( $handle, 'step2.f_mail_webmaster', $_POST['mail_webmaster']);
280    $vtp->closeSession( $handle, 'step2' );
281  }
282
283  // end of installation message
284  if ( isset( $_POST['submit'] ) and count( $errors ) == 0 )
285  {
286    $vtp->addSession( $handle, 'install_end' );
287    $vtp->closeSession( $handle, 'install_end' );
288  }
289}
290//---------------------------------------------------- Step 0 : language choice
291else
292{
293  $vtp->addSession( $handle, 'step0' );
294  $languages = get_languages( '../language/' );
295  foreach ( $languages as $language ) {
296    $vtp->addSession( $handle, 'language' );
297    $vtp->setVar( $handle, 'language.name', $language );
298    $vtp->closeSession( $handle, 'language' );
299  }
300  $vtp->closeSession( $handle, 'step0' );
301}
302//----------------------------------------------------------- html code display
303$code = $vtp->Display( $handle, 0 );
304echo $code;
305?>
Note: See TracBrowser for help on using the repository browser.