/**
  * Checks that the server we are installing on meets the requirements for running phpBB
  */
 function check_requirements($mode, $sub)
 {
     global $user, $template, $phpbb_root_path, $phpEx;
     $this->page_title = $user->lang['STAGE_REQUIREMENTS'];
     $template->assign_vars(array('TITLE' => $user->lang['UNINSTALL_REQUIREMENTS'], 'BODY' => $user->lang['UNINSTALL_REQUIREMENTS_EXPLAIN']));
     $passed = array('installed' => false);
     // Test for basic PHP settings
     $template->assign_block_vars('checks', array('S_LEGEND' => true, 'LEGEND' => $user->lang['UNINSTALL_REQUIREMENTS']));
     $gallery_version = get_gallery_version();
     if (version_compare($gallery_version, '0.0.0', '>')) {
         $passed['installed'] = true;
         $result = '<strong style="color: green;">' . $gallery_version . '</strong>';
     } else {
         $result = '<strong style="color:red">' . $user->lang['NO_INSTALL_FOUND'] . '</strong>';
     }
     $template->assign_block_vars('checks', array('TITLE' => $user->lang['FOUND_VERSION'], 'RESULT' => $result, 'S_EXPLAIN' => false, 'S_LEGEND' => false));
     $url = !in_array(false, $passed) ? append_sid("{$phpbb_root_path}install/index.{$phpEx}", "mode={$mode}&amp;sub=delete_tables") : append_sid("{$phpbb_root_path}install/index.{$phpEx}", "mode={$mode}&amp;sub=requirements");
     $submit = !in_array(false, $passed) ? $user->lang['UNINSTALL_START'] : $user->lang['INSTALL_TEST'];
     $template->assign_vars(array('L_SUBMIT' => $submit, 'S_HIDDEN' => '', 'U_ACTION' => $url));
 }
 /**
  * Add some Tables, Columns and Index to the database-schema
  */
 function update_db_schema($mode, $sub)
 {
     global $db, $user, $template, $table_prefix;
     global $phpbb_root_path, $phpEx;
     $this->page_title = $user->lang['STAGE_UPDATE_DB'];
     $phpbb_gallery_version = get_gallery_version();
     phpbb_gallery_config::set('version', $phpbb_gallery_version);
     $dbms_data = get_dbms_infos();
     $db_schema = $dbms_data['db_schema'];
     $delimiter = $dbms_data['delimiter'];
     switch (phpbb_gallery_config::get('version')) {
         case '0.1.2':
         case '0.1.3':
         case '0.2.0':
         case '0.2.1':
         case '0.2.2':
         case '0.2.3':
         case '0.3.0':
         case '0.3.1':
         case '0.3.2-RC1':
         case '0.3.2-RC2':
         case '0.4.0-RC1':
         case '0.4.0-RC2':
         case '0.4.0-RC3':
         case '0.4.0':
             trigger_error('VERSION_NOT_SUPPORTED', E_USER_ERROR);
             break;
         case '0.4.1':
             nv_add_column(GALLERY_ALBUMS_TABLE, 'album_contest', array('UINT', 0));
             nv_add_column(GALLERY_IMAGES_TABLE, 'filesize_upload', array('UINT:20', 0));
             nv_add_column(GALLERY_IMAGES_TABLE, 'filesize_medium', array('UINT:20', 0));
             nv_add_column(GALLERY_IMAGES_TABLE, 'filesize_cache', array('UINT:20', 0));
             nv_add_column(GALLERY_IMAGES_TABLE, 'image_contest', array('UINT:1', 0));
             nv_add_column(GALLERY_IMAGES_TABLE, 'image_exif_data', array('TEXT', ''));
             nv_change_column(GALLERY_PERMISSIONS_TABLE, 'perm_system', array('INT:3', 0));
             nv_create_table('phpbb_gallery_contests', $dbms_data);
         case '0.5.0':
             nv_add_column(GALLERY_ALBUMS_TABLE, 'album_status', array('UINT:1', 0));
             nv_add_column(GALLERY_ALBUMS_TABLE, 'display_in_rrc', array('UINT:1', 1));
             nv_add_column(GALLERY_IMAGES_TABLE, 'image_contest_end', array('TIMESTAMP', 0));
             nv_add_column(GALLERY_IMAGES_TABLE, 'image_contest_rank', array('UINT:3', 0));
         case '0.5.1':
         case '0.5.2':
             nv_create_table('phpbb_gallery_albums_track', $dbms_data);
             nv_add_column(GALLERY_USERS_TABLE, 'user_lastmark', array('TIMESTAMP', 0));
         case '0.5.3':
             nv_add_column(LOG_TABLE, 'album_id', array('UINT', 0));
             nv_add_column(LOG_TABLE, 'image_id', array('UINT', 0));
         case '0.5.4':
         case '1.0.0-dev':
             nv_add_column(GALLERY_ROLES_TABLE, 'i_unlimited', array('UINT:3', 0));
             nv_add_column(GALLERY_ROLES_TABLE, 'album_unlimited', array('UINT:3', 0));
         case '1.0.0-RC1':
         case '1.0.0-RC2':
         case '1.0.0':
         case '1.0.1-dev':
             nv_add_column(GALLERY_IMAGES_TABLE, 'image_name_clean', array('VCHAR:255', ''));
             nv_add_column(GALLERY_IMAGES_TABLE, 'image_username_clean', array('VCHAR:255', ''));
         case '1.0.1':
         case '1.0.2-dev':
         case '1.0.2-RC1':
         case '1.0.2':
         case '1.0.3-RC1':
         case '1.0.3-RC2':
         case '1.0.3':
         case '1.0.4':
             nv_add_column(GALLERY_ALBUMS_TABLE, 'album_watermark', array('UINT:1', 1));
             nv_add_column(GALLERY_ALBUMS_TABLE, 'album_sort_key', array('VCHAR:8', ''));
             nv_add_column(GALLERY_ALBUMS_TABLE, 'album_sort_dir', array('VCHAR:8', ''));
             nv_add_column(GALLERY_USERS_TABLE, 'user_viewexif', array('UINT:1', 0));
         case '1.0.5-RC1':
             // Only allow update from 1.0.5
             trigger_error('VERSION_NOT_SUPPORTED', E_USER_ERROR);
             break;
         case '1.0.5':
             nv_add_column(GALLERY_USERS_TABLE, 'user_permissions', array('MTEXT', ''));
             nv_add_column(GALLERY_USERS_TABLE, 'user_last_update', array('TIMESTAMP', 0));
             break;
     }
     $template->assign_vars(array('BODY' => $user->lang['STAGE_CREATE_TABLE_EXPLAIN'], 'L_SUBMIT' => $user->lang['NEXT_STEP'], 'S_HIDDEN' => '', 'U_ACTION' => append_sid("{$phpbb_root_path}install/index.{$phpEx}", "mode={$mode}&amp;sub=update_db&amp;step=2")));
 }
 /**
  * Checks that the server we are installing on meets the requirements for running phpBB
  */
 function check_server_requirements($mode, $sub)
 {
     global $user, $template, $phpbb_root_path, $phpEx;
     $this->page_title = $user->lang['STAGE_REQUIREMENTS'];
     $template->assign_vars(array('TITLE' => $user->lang['REQUIREMENTS_TITLE'], 'BODY' => $user->lang['REQUIREMENTS_EXPLAIN']));
     $passed = array('php' => false, 'files' => false);
     // Test for basic PHP settings
     $template->assign_block_vars('checks', array('S_LEGEND' => true, 'LEGEND' => $user->lang['PHP_SETTINGS'], 'LEGEND_EXPLAIN' => $user->lang['PHP_SETTINGS_EXP']));
     // Check for GD-Library
     if (@extension_loaded('gd') || can_load_dll('gd')) {
         $passed['php'] = true;
         $result = '<strong style="color:green">' . $user->lang['YES'] . '</strong>';
     } else {
         $result = '<strong style="color:red">' . $user->lang['NO'] . '</strong>';
     }
     $template->assign_block_vars('checks', array('TITLE' => $user->lang['REQ_GD_LIBRARY'], 'RESULT' => $result, 'S_EXPLAIN' => false, 'S_LEGEND' => false));
     // Test for optional PHP settings
     $template->assign_block_vars('checks', array('S_LEGEND' => true, 'LEGEND' => $user->lang['PHP_SETTINGS_OPTIONAL'], 'LEGEND_EXPLAIN' => $user->lang['PHP_SETTINGS_OPTIONAL_EXP']));
     // Image rotate
     if (function_exists('imagerotate')) {
         $result = '<strong style="color:green">' . $user->lang['YES'] . '</strong>';
     } else {
         $gd_info = gd_info();
         $result = '<strong style="color:red">' . $user->lang['NO'] . '</strong><br />' . sprintf($user->lang['OPTIONAL_IMAGEROTATE_EXP'], $gd_info['GD Version']);
     }
     $template->assign_block_vars('checks', array('TITLE' => $user->lang['OPTIONAL_IMAGEROTATE'], 'TITLE_EXPLAIN' => $user->lang['OPTIONAL_IMAGEROTATE_EXPLAIN'], 'RESULT' => $result, 'S_EXPLAIN' => true, 'S_LEGEND' => false));
     // Exif data
     if (function_exists('exif_read_data')) {
         $result = '<strong style="color:green">' . $user->lang['YES'] . '</strong>';
     } else {
         $result = '<strong style="color:red">' . $user->lang['NO'] . '</strong><br />' . $user->lang['OPTIONAL_EXIFDATA_EXP'];
     }
     $template->assign_block_vars('checks', array('TITLE' => $user->lang['OPTIONAL_EXIFDATA'], 'TITLE_EXPLAIN' => $user->lang['OPTIONAL_EXIFDATA_EXPLAIN'], 'RESULT' => $result, 'S_EXPLAIN' => true, 'S_LEGEND' => false));
     // Check permissions on files/directories we need access to
     $template->assign_block_vars('checks', array('S_LEGEND' => true, 'LEGEND' => $user->lang['FILES_REQUIRED'], 'LEGEND_EXPLAIN' => $user->lang['FILES_REQUIRED_EXPLAIN']));
     $directories = array('import', 'upload', 'medium', 'cache');
     umask(0);
     $passed['dirs'] = true;
     foreach ($directories as $dir) {
         $write = false;
         // Now really check
         if (phpbb_gallery_url::_file_exists('', $dir, '') && is_dir(phpbb_gallery_url::_return_file('', $dir, ''))) {
             if (!phpbb_gallery_url::_is_writable('', $dir, '')) {
                 @chmod(phpbb_gallery_url::_return_file('', $dir, ''), 0777);
             }
         }
         // Now check if it is writable by storing a simple file
         $fp = @fopen(phpbb_gallery_url::_return_file('', $dir, '') . 'test_lock', 'wb');
         if ($fp !== false) {
             $write = true;
         }
         @fclose($fp);
         @unlink(phpbb_gallery_url::_return_file('', $dir, '') . 'test_lock');
         $passed['dirs'] = $write && $passed['dirs'] ? true : false;
         $write = $write ? '<strong style="color:green">' . $user->lang['WRITABLE'] . '</strong>' : '<strong style="color:red">' . $user->lang['UNWRITABLE'] . '</strong>';
         $template->assign_block_vars('checks', array('TITLE' => $dir, 'RESULT' => $write, 'S_EXPLAIN' => false, 'S_LEGEND' => false));
     }
     // Check whether the gallery is already installed
     $gallery_version = get_gallery_version();
     if (version_compare($gallery_version, '0.0.0', '>')) {
         $template->assign_block_vars('checks', array('S_LEGEND' => true, 'LEGEND' => $user->lang['FOUND_INSTALL'], 'LEGEND_EXPLAIN' => sprintf($user->lang['FOUND_INSTALL_EXPLAIN'], '<a href="' . append_sid("{$phpbb_root_path}install/index.{$phpEx}", 'mode=update') . '">', '</a>')));
         $template->assign_block_vars('checks', array('TITLE' => $user->lang['FOUND_VERSION'], 'RESULT' => '<strong style="color:red">' . $gallery_version . '</strong>', 'S_EXPLAIN' => false, 'S_LEGEND' => false));
     }
     $url = !in_array(false, $passed) ? append_sid("{$phpbb_root_path}install/index.{$phpEx}", "mode={$mode}&amp;sub=create_table") : append_sid("{$phpbb_root_path}install/index.{$phpEx}", "mode={$mode}&amp;sub=requirements");
     $submit = !in_array(false, $passed) ? $user->lang['INSTALL_START'] : $user->lang['INSTALL_TEST'];
     $template->assign_vars(array('L_SUBMIT' => $submit, 'S_HIDDEN' => '', 'U_ACTION' => $url));
 }