phpDocumentor pond
[ class tree: pond ] [ index: pond ] [ all elements ]

Source for file index.php

Documentation is available at index.php

  1. <?php
  2. /**
  3.  * This is the main install menu
  4.  *
  5.  * IF YOU ARE READING THIS IN YOUR WEB BROWSER, IT MEANS THAT PHP IS NOT PROPERLY INSTALLED
  6.  * ON YOUR WEB SERVER. IF YOU DON'T KNOW WHAT THIS MEANS, CONTACT YOUR SERVER ADMINISTRATOR
  7.  * OR YOUR HOSTING COMPANY.
  8.  *
  9.  * Quam Plures - {@link http://quamplures.net/}
  10.  * Released under GNU GPL License - {@link http://quamplures.net/license.html}
  11.  * @copyright (c) 2009 - 2011 by the Quam Plures developers - {@link http://quamplures.net/}
  12.  * @copyright (c)2003-2009 by Francois PLANQUE - {@link http://fplanque.net/}
  13.  *
  14.  * @package pond
  15.  */
  16.  
  17. /**
  18.  * include config and default functions:
  19.  */
  20. require_once dirname(__FILE__).'/../qp_config/_config.php';
  21.  
  22. // Make the includes believe they are being called in the right place...
  23. define'QP_MAIN_INIT'true );
  24.  
  25. /**
  26.  * Define that we're in the install process.
  27.  */
  28. define'QP_IS_INSTALLING'true );
  29.  
  30. $script_start_time time();
  31. $localtimenow $script_start_time// used e.g. for post_datemodified (sample posts)
  32.  
  33. if$app_config_is_done )
  34. {    // Base config is not done yet, try to guess some values needed for correct display:
  35.     $rsc_url '../qp_rsc/';
  36. }
  37.  
  38. require_once $inc_path.'_core/_class'.floor(PHP_VERSION).'.funcs.php';
  39. require_once $inc_path.'_core/_misc.funcs.php';
  40.  
  41. load_class('_core/model/_log.class.php');
  42. $Debuglog new Log'note' );
  43. $Messages new Log('error');
  44. require_once $conf_path.'_upgrade.php';
  45. require_once $inc_path.'_vars.inc.php';
  46. load_class('/_core/model/db/_db.class.php');
  47. load_funcs('collections/model/_blog.funcs.php');
  48. load_funcs('collections/model/_category.funcs.php');
  49. load_class('items/model/_item.class.php');
  50. load_funcs('items/model/_item.funcs.php');
  51. load_funcs('users/model/_user.funcs.php');
  52. load_funcs'_core/ui/forms/_form.funcs.php' );
  53. load_class('_core/model/_timer.class.php');
  54. load_class('plugins/model/_plugins.class.php');
  55. require_once dirname(__FILE__).'/_functions_install.php';
  56.  
  57. $Timer new Timer('main');
  58.  
  59. load_funcs('_core/_param.funcs.php');
  60. param'action''string''default' );
  61.  
  62. // Load all available locale defintions:
  63. param'locale''string' );
  64. ifpreg_match('/[a-z]{2}-[A-Z]{2}(-.{1,14})?/'$locale) )
  65. {
  66.     $default_locale $locale;
  67. }
  68. else
  69. // detect language
  70.     $default_locale locale_from_httpaccept();
  71. }
  72. // Activate default locale:
  73. iflocale_activate$default_locale ) )
  74. {    // Could not activate locale (non-existent?), fallback to en-US:
  75.     $default_locale 'en-US';
  76.     locale_activate'en-US' );
  77. }
  78.  
  79. init_charsets$current_charset );
  80.  
  81. /**
  82.  * How many sample entries do we have?
  83.  *
  84.  * @see installer_timestamp()
  85.  */
  86. // count sample posts (will include 2 that are not timestamped items)
  87. $count_samples substr_count(
  88.     php_strip_whitespacedirname__FILE__ ).'/_functions_create.php' ),
  89.     'installer_timestamp()' );
  90. // count contributors
  91. require$templates_path.'/_contributors.php' );
  92. $count_contribs count$_hic_sunt_dracones );
  93. // calculate how far back to start the installation
  94. $timestamp time(( ( $count_samples $count_contribs 86400 ) );
  95.  
  96. switch$action )
  97. {
  98.     case 'dbupgrade':
  99.         $title T_('Upgrade from a previous version');
  100.         break;
  101.  
  102.     case 'newdb':
  103.         $msg array();
  104.         iffile_existsdirname(__FILE__).'/_automated.php' ) )
  105.         // automated install
  106.             require_once dirname(__FILE__).'/_automated.php';
  107.         }
  108.  
  109.         if!param'conf_admin_login''string' ) )
  110.         {
  111.             $msg[T_('Please enter a login to use for your admin account' );
  112.         }
  113.         if!param'conf_admin_pass''string' ) )
  114.         {
  115.             $msg[T_('We strongly advise you choose a password' );
  116.         }
  117.         if!param'conf_admin_email''string' ) )
  118.         {
  119.             $msg[T_('Your email is needed in case you forget your password ;)' );
  120.         }
  121.         if!empty$msg ) )
  122.         {
  123.             $title T_('Try again!');
  124.             $action 'menu';
  125.             break;
  126.         }
  127.         $title T_('New Install');
  128.         break;
  129.  
  130.     case 'deletedb':
  131.         $title sprintf/* TRANS: %s: Application name */ T_('Delete %s tables')$app_name );
  132.         break;
  133.  
  134.     case 'start':
  135.         $title T_('Base configuration');
  136.         break;
  137.  
  138.     default:
  139.         $title '';
  140. }
  141.  
  142. header('Content-Type: text/html; charset='.$io_charset);
  143. header('Cache-Control: no-cache')// no request to this page should get cached!
  144. ?>
  145. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  146. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="<?php locale_lang(?>" lang="<?php locale_lang(?>">
  147. <head>
  148. <title><?php
  149.     printf/* TRANS: %s: Application name */ T_('%s installer')$app_name );
  150.     if$title )
  151.     {
  152.         echo ': '$title;
  153.     }
  154. ?></title>
  155. <link rel="icon" href="../favicon.ico" type="image/x-icon"/>
  156. <link rel="shortcut icon" href="../favicon.ico" type="image/x-icon"/>
  157. <meta name="viewport" content="width = 750" />
  158. <link href="../qp_rsc/css/support_install.css" rel="stylesheet" type="text/css" />
  159. </head>
  160.  
  161. <body>
  162.  
  163. <div class="wrapper">
  164. <div class="menu_top">
  165. <?php echo T_('Current installation'?>:
  166. <a href="index.php?locale=<?php echo $default_locale ?>"><?php echo T_('Install menu'?></a>
  167. </div>
  168.  
  169. <?php
  170. if$app_config_is_done || (($action != 'start'&& ($action != 'default'&& ($action != 'conf')) )
  171. // Connect to DB:
  172.     $tmp_db_config $app_db_config;
  173.  
  174.     // We want a friendly message if we can't connect:
  175.     $tmp_db_config['halt_on_error'false;
  176.     $tmp_db_config['show_errors'false;
  177.  
  178.     // Make sure we use the proper charset:
  179.     $tmp_db_config['connection_charset'$evo_charset;
  180.  
  181.     // CONNECT TO DB:
  182.     $DB new DB$tmp_db_config );
  183.     unset($tmp_db_config);
  184.  
  185.     if$DB->error )
  186.     // restart conf
  187.         echo '<div class="error"><p class="error">'.T_('Check your database config settings below and update them if necessary...').'</p></div>';
  188.         display_base_config_recap();
  189.         $action 'start';
  190.     }
  191.     else
  192.     {
  193.         $DB->halt_on_error true;  // From now on, halt on errors.
  194.         $DB->show_errors true;    // From now on, show errors (they're helpful in case of errors!).
  195.  
  196.         // Check MySQL version
  197.         $mysql_version $DB->get_var'SELECT VERSION()' );
  198.         list$mysl_version_main$mysl_version_minor explode'.'$mysql_version );
  199.         if( ($mysl_version_main 100 $mysl_version_minor500 )
  200.         {
  201.             die'<div class="error"><p class="error"><strong>'
  202.                 .sprintfT_('The minimum requirement for this version of %s is %s version %s '
  203.                         .'but you are trying to use version %s!'),
  204.                     $app_name'MySQL''5.0'$mysql_version )
  205.                 .'</strong></p></div>' );
  206.         }
  207.     }
  208. }
  209.  
  210. // Check PHP version
  211. list$version_main$version_minor explode'.'phpversion() );
  212. if( ($version_main 100 $version_minor500 )
  213. {
  214.     die'<div class="error"><p class="error"><strong>'
  215.         .sprintfT_'The minimum requirement for this version of %s is %s version %s but you are '
  216.                 .'trying to use version %s!'),
  217.             $app_name'PHP''5.0'phpversion() )
  218.         .'</strong></p></div>' );
  219. }
  220.  
  221. // Check other dependencies:
  222. // TODO: Non-install/upgrade-actions should be allowed (e.g. "deletedb")
  223. if$req_errors install_validate_requirements() )
  224. {
  225.     echo '<div class="error">';
  226.     echo '<p class="error"><strong>';
  227.     printfT_('%s cannot be installed because of the following errors:')$app_name );
  228.     echo '</strong></p>';
  229.     echo '<ul class="error"><li>'.implode'</li><li>'$req_errors ).'</li></ul>';
  230.     echo '</div>';
  231.     die;
  232. }
  233.  
  234. switch$action )
  235. {
  236.     case 'conf':
  237.         /* Write conf file */
  238.         display_locale_selector();
  239.  
  240.         block_open();
  241.         param'conf_db_user''string'true );
  242.         param'conf_db_password'''true );
  243.         param'conf_db_name''string'true );
  244.         param'conf_db_host''string'true );
  245.         param'conf_db_tableprefix''string'$app_db_tableprefix );
  246.         param'conf_baseurl''string'true );
  247.         $conf_baseurl preg_replace'#(/)?$#'''$conf_baseurl ).'/'// force trailing slash
  248.  
  249.         // Connect to DB:
  250.         $DB new DBarray(
  251.                 'user' => $conf_db_user,
  252.                 'password' => $conf_db_password,
  253.                 'name' => $conf_db_name,
  254.                 'host' => $conf_db_host,
  255.                 'aliases' => $app_db_config['aliases'],
  256.                 'use_transactions' => $app_db_config['use_transactions'],
  257.                 'table_options' => $app_db_config['table_options'],
  258.                 'connection_charset' => $app_db_config['connection_charset'],
  259.                 'halt_on_error' => false )
  260.             );
  261.         if$DB->error )
  262.         // restart conf
  263.             echo '<p class="error">'.T_('It seems that the database config settings you entered don\'t work. Please check them carefully and try again...').'</p>';
  264.             $action 'start';
  265.         }
  266.         else
  267.         {
  268.             $conf_template_filepath $conf_path.'_main_config.template.php';
  269.             $conf_filepath $conf_path.'_main_config.php';
  270.  
  271.             // Read original:
  272.             $file_loaded @file$conf_template_filepath );
  273.  
  274.             ifempty$file_loaded ) )
  275.             // This should actually never happen, just in case...
  276.                 echo '<div class="error"><p class="error">'.sprintfT_('Could not load original conf file [%s]. Is it missing?')$conf_filepath ).'</p></div>';
  277.                 break;
  278.             }
  279.  
  280.             // File loaded...
  281.             $conf implode''$file_loaded );
  282.             // Update conf:
  283.             $conf preg_replace(
  284.                 array(
  285.                     '#\$app_db_config\s*=\s*array\(
  286.                         \s*[\'"]host[\'"]\s*=>\s*[\'"].*?[\'"],     ([^\n\r]*\r?\n)
  287.                         \s*[\'"]name[\'"]\s*=>\s*[\'"].*?[\'"],     ([^\n\r]*\r?\n)
  288.                         \s*[\'"]user[\'"]\s*=>\s*[\'"].*?[\'"],     ([^\n\r]*\r?\n)
  289.                         \s*[\'"]password[\'"]\s*=>\s*[\'"].*?[\'"], ([^\n\r]*\r?\n)
  290.                         #ixs',
  291.                     "#app_db_tableprefix\s*=\s*'.*?';#",
  292.                     "#app_baseurl\s*=\s*'.*?';#",
  293.                     "#app_config_is_done\s*=.*?;#",
  294.                 ),
  295.                 array(
  296.                     "\$app_db_config = array(\n"
  297.                         ."\t'host'     => '".str_replace"'""\'"$conf_db_host )."',\$1"
  298.                         ."\t'name'     => '".str_replace"'""\'"$conf_db_name )."',\$2"
  299.                         ."\t'user'     => '".str_replace"'""\'"$conf_db_user )."',\$3"
  300.                         ."\t'password' => '".str_replace"'""\'"$conf_db_password )."',\$4",
  301.                     "app_db_tableprefix = '".str_replace"'""\'"$conf_db_tableprefix )."';",
  302.                     "app_baseurl = '".str_replace"'""\'"$conf_baseurl )."';",
  303.                     'app_config_is_done = 1;',
  304.                 )$conf );
  305.  
  306.             $f @fopen$conf_filepath 'w' );
  307.             if$f == false )
  308.             {
  309.                 ?>
  310.                 <h1><?php echo T_('Config file update'?></h1>
  311.                 <p><strong><?php printfT_('We cannot automatically create or update your config file [%s]!')$conf_filepath )?></strong></p>
  312.                 <p><strong><?php echo T_('You need to update the config file manually:'?></strong></p>
  313.                 <ol>
  314.                 <li><?php echo T_('Create a new text file with a text editor.'?></li>
  315.                 <li><?php echo T_('Copy the contents from the box below.'?></li>
  316.                 <li><?php echo T_('Paste them into your local text editor. <strong>ATTENTION: make sure there is ABSOLUTELY NO WHITESPACE after the final <code>?&gt;</code> in the file.</strong> Any space, tab, newline or blank line at the end of the conf file may prevent cookies from being set when you try to log in later.'?></li>
  317.                 <li><?php echo T_('Save the file locally under the name <code>_main_config.php</code>'?></li>
  318.                 <li><?php echo T_('Upload the file to your server, into the <code>/qp_config</code> folder.'?></li>
  319.                 <li><?php printfT_('When done <a %s>call the installer</a> again. The installer will rerun tests to connect to your database.')'href="index.php?locale='.$default_locale.'"'?></li>
  320.                 </ol>
  321.                 <p><?php echo T_('This is how your _main_config.php should look like:'?></p>
  322.                 <blockquote>
  323.                 <pre><?php
  324.                     echo htmlspecialchars$conf );
  325.                 ?></pre>
  326.                 </blockquote>
  327.                 <?php
  328.                 break;
  329.             }
  330.             else
  331.             // Write new contents:
  332.                 fwrite$f$conf );
  333.                 fclose($f);
  334.  
  335.                 printf'<div class="success"><p>'.T_('Your configuration file [%s] has been successfully created.').'</p></div>'$conf_filepath );
  336.  
  337.                 $app_db_tableprefix $conf_db_tableprefix;
  338.                 $app_baseurl $conf_baseurl;
  339.                 $app_config_is_done 1;
  340.                 $action 'menu';
  341.             }
  342.         }
  343.         // ATTENTION: we continue here...
  344.  
  345.     case 'start':
  346.     case 'default':
  347.         /* Start of install procedure */
  348.         if$action == 'start' || !$app_config_is_done )
  349.         {
  350.             display_locale_selector();
  351.  
  352.             block_open();
  353.  
  354.             printf'<img src="../qp_rsc/img/qp-logo.jpg" alt="'.T_('%s Logo').'" title="'.T_('%s Logo').'"/>'$app_name$app_name );
  355.             echo '<h1>'.T_('Base configuration').'</h1>';
  356.  
  357.             if$app_config_is_done && $app_allow_dbase_reset != )
  358.             {
  359.                 echo '<p><strong>'.T_('Resetting the base configuration is currently disabled for security reasons.').'</strong></p>';
  360.                 echo '<p>'.sprintfT_('To enable it, please go to the %s file and change: %s to %s')'/qp_config/_main_config.php''<pre>$app_allow_dbase_reset = 0;</pre>''<pre>$app_allow_dbase_reset = 1;</pre>' ).'</p>';
  361.                 echo '<p>'.T_('Then <strong>reload this page</strong> and a reset option will appear.').'</p>';
  362.                 block_close();
  363.                 break;
  364.             }
  365.             else
  366.             {
  367.             // Set default params if not provided otherwise:
  368.             param'conf_db_user''string'$app_db_config['user');
  369.             param'conf_db_password'''$app_db_config['password');
  370.             param'conf_db_name''string'$app_db_config['name');
  371.             param'conf_db_host''string'$app_db_config['host');
  372.             param'conf_db_tableprefix''string'$app_db_tableprefix );
  373.             // Guess baseurl:
  374.             $app_baseurl 'http://'.isset$_SERVER['HTTP_HOST'$_SERVER['HTTP_HOST''yourserver.com' );
  375.             ifisset$_SERVER['SERVER_PORT'&& $_SERVER['SERVER_PORT'!= '80' && (strpos($app_baseurl,':'=== false) )
  376.                 $app_baseurl .= ':'.$_SERVER['SERVER_PORT'];
  377.             $app_baseurl .= preg_replace'#/qp_install(/(index.php)?)?$#'''$ReqPath ).'/';
  378.             param'conf_baseurl''string'$app_baseurl );
  379.             ?>
  380.  
  381.             <p><?php echo T_('The basic configuration file (<code>/qp_config/_main_config.php</code>) has not been created yet. If your server supports it, you can automatically generate it by filling out the form below.'?></p>
  382.  
  383.             <p><?php printfT_('This is the minimum info we need to set up %s on this server:')$app_name )?></p>
  384.  
  385.             <form class="fform" name="form" action="index.php" method="post">
  386.             <input type="hidden" name="action" value="conf" />
  387.             <input type="hidden" name="locale" value="<?php echo $default_locale?>" />
  388.  
  389.             <fieldset>
  390.             <legend><?php echo T_('Blog settings'?></legend>
  391.             <?php
  392.             form_text'conf_baseurl'$conf_baseurl50T_('Website address'),
  393.                 sprintf/* TRANS: %1$s: App name */
  394.                     T_('This is where %1$s and your blogs reside by default. '
  395.                         .'CHECK THIS CAREFULLY or not much will work. If you want to '
  396.                         .'test %1$s on your local machine, in order for login cookies '
  397.                         .'to work, you MUST use http://<strong>localhost</strong>/path... '
  398.                         .'Do NOT use your machine\'s name!' )$app_name ),
  399.                 120 );
  400.             ?>
  401.             </fieldset>
  402.  
  403.             <fieldset>
  404.             <legend><?php echo T_('Database you want to install into'?></legend>
  405.             <p class="note"><?php
  406.             printf/* TRANS: %1$s: App name. */
  407.                 T_'%1$s stores blog posts, comments, user permissions, etc. in a MySQL '
  408.                     .'database. You must create this database prior to installing %1$s '
  409.                     .'and provide the access parameters to this database below. If '
  410.                     .'you are not familiar with this, you can ask your hosting provider '
  411.                     .'to create the database for you.' )$app_name );
  412.             ?></p>
  413.             <?php
  414.             form_text'conf_db_host'$conf_db_host16T_('MySQL Host/Server')T_'Typically looks like "localhost" or "sql-6" or "sql-8.yourhost.net"...' )120 );
  415.             form_text'conf_db_name'$conf_db_name16T_('MySQL Database')T_'Name of the MySQL database you have created on the server' )100);
  416.             form_text'conf_db_user'$conf_db_user16T_('MySQL Username')sprintfT_('Used by %s to access the MySQL database' )$app_name )100 );
  417.             form_text'conf_db_password'$conf_db_password16T_('MySQL Password')sprintfT_('Used by %s to access the MySQL database' )$app_name )100 )// no need to hide this. nobody installs an application from a public place
  418.             form_text'conf_db_tableprefix'$conf_db_tableprefix16T_('MySQL tables prefix')sprintfT_('All DB tables will be prefixed with this. You need to change this only if you want to have multiple %s installations in the same DB.' )$app_name )30 );
  419.             ?>
  420.             </fieldset>
  421.  
  422.             <div class="buttons">
  423.             <input type="submit" name="submit" value="<?php echo T_('Update config file'?>" class="search" />
  424.             <input type="reset" value="<?php echo T_('Reset'?>" class="search" />
  425.             </div>
  426.  
  427.             </form>
  428.  
  429.             <?php
  430.             break;
  431.         }
  432.     }
  433.     // if config was already done, move on to main menu:
  434.  
  435.     case 'menu':
  436.         /* Menu */
  437.         param('conf_admin_login''string' );
  438.         param('conf_admin_pass''string' );
  439.         param('conf_admin_email''string' );
  440.  
  441.         display_locale_selector();
  442.  
  443.         block_open();
  444.  
  445.         printf'<img src="../qp_rsc/img/qp-logo.jpg" alt="'.T_('%s Logo').'" title="'.T_('%s Logo').'"/>'$app_name$app_name );
  446.         ?>
  447.         <h1><?php printfT_('Install %s version %s')$app_name$app_version )?></h1>
  448.  
  449.         <?php $old_db_version get_db_version'version' )?>
  450.  
  451.         <form action="index.php" method="post">
  452.         <input type="hidden" name="locale" value="<?php echo $default_locale ?>" />
  453.         <input type="hidden" name="confirmed" value="0" />
  454.         <input type="hidden" name="installer_version" value="10" />
  455.  
  456.         <div id="op-newdb" class="op-group">
  457.         <input type="radio" name="action" id="newdb" value="newdb"
  458.         <?php
  459.         /**
  460.          * @todo (legacy): fp> change the above to 'newdbsettings' for an additional settings screen. ASDFGHJKL
  461.          */
  462.         // @todo (test): this todo tag probably won't work ASDFGHJKL
  463.         ifis_null($old_db_version) )
  464.         {
  465.             echo ' checked="checked" />';
  466.         }
  467.         else
  468.         {
  469.             echo ' />';
  470.         }
  471.         ?>
  472.         <label for="newdb" class="option"><?php
  473.         printfT_('<strong>New Install</strong>: Install %s database tables.')$app_name );
  474.         ?></label>
  475.  
  476.         <div class="options">
  477.         <h3><?php echo T_('Admin account details' )?></h3>
  478.         <?php
  479.         if!empty$msg ) )
  480.         {
  481.             echo '<p class="error">'.implode'<br />'$msg ).'</p>';
  482.         }
  483.         form_text'conf_admin_login'$conf_admin_login50T_('Login')T_('This will be used to create your admin account.' )80 );
  484.         form_text'conf_admin_pass'$conf_admin_pass50T_('Password')T_('We advise you use a strong password' )80 );
  485.         form_text'conf_admin_email'$conf_admin_email50T_('Your email')T_('This will be used to receive notifications for comments on your blog, etc.' )80 );
  486.         ?></div>
  487.  
  488.         <div class="options">
  489.         <h3><?php echo T_('Example posts' )?></h3>
  490.         <input type="checkbox" name="create_sample_contents" id="create_sample_contents" value="1" checked="checked" />
  491.         <label for="create_sample_contents"><?php
  492.         printfT_('Also install sample blogs &amp; sample contents. The sample posts explain '
  493.                 .'several features of %s. This is highly recommended for new users.'),
  494.             $app_name );
  495.         ?></label>
  496.         </div>
  497.  
  498.         </div>
  499.  
  500.         <?php
  501.         if$app_db_version !== NULL )
  502.         {
  503.             ?>
  504.             <div id="op-dbupgrade" class="op-group">
  505.             <input type="radio" name="action" id="dbupgrade" value="dbupgrade"
  506.             <?php
  507.             if!is_null($old_db_version&& $old_db_version $app_db_version )
  508.             {
  509.                 echo ' checked="checked" />';
  510.             }
  511.             else
  512.             {
  513.                 echo ' />';
  514.             }
  515.             ?>
  516.             <label for="dbupgrade"><?php
  517.             printf/* TRANS: %1$s: App name. */ T_('<strong>Upgrade from a previous version of %1$s</strong>')$app_name );
  518.             ?></label>
  519.             <p class="options"><?php
  520.             echo sprintfT_('Upgrade your '
  521.                     .'%1$s database tables in order to make them compatible with the current '
  522.                     .'version.')$app_name ).'</p><p class="options">'
  523.             .T_('<strong>WARNING:</strong> If you have modified your database, '
  524.                 .'this operation may fail. Make sure you have a backup.');
  525.             ?></p>
  526.             </div>
  527.             <?php
  528.         }
  529.  
  530.         if$app_allow_dbase_reset == )
  531.         {
  532.             ?>
  533.             <div class="op-deletedb"><input type="radio" name="action" id="deletedb" value="deletedb" />
  534.             <label for="deletedb"><strong><?php printfT_('Delete %s tables')$app_name )?></strong></label>
  535.             <p class="options"><?php
  536.             printf/* TRANS: %1$s: App name. */
  537.                 T_('If you have installed %1$s tables before and wish to start anew, '
  538.                     .'you must delete the %1$s tables before you can start a new installation. <br />'
  539.                     .'<strong>WARNING: All your %1$s tables and data will be lost!!!</strong> '
  540.                     .'Any non-%1$s tables will remain untouched though.')$app_name );
  541.             ?></p>
  542.             <input type="radio" name="action" id="start" value="start" />
  543.             <label for="start"><strong><?php echo T_('Change your base configuration')?></strong></label>
  544.             <p class="options"><?php
  545.             printfT_('(see recap below): '
  546.                     .'You only want to do this in rare occasions where you may have moved '
  547.                     .'your %s files or database to a different location...')$app_name );
  548.             ?></p></div>
  549.             <?php
  550.         }
  551.  
  552.         if$app_allow_dbase_reset != )
  553.         {
  554.             echo '<div class="floatright"><a href="index.php?action=deletedb&amp;locale='.$default_locale.'">'.T_('Need to start anew?').' &raquo;</a></div>';
  555.         }
  556.         ?>
  557.  
  558.         <p>
  559.         <input type="submit" value="&nbsp; <?php echo T_('GO!')?> &nbsp;"
  560.             onclick="var dc = document.getElementById( 'deletedb' ); if( dc && dc.checked ) { if ( confirm( '<?php
  561.                 printf/* TRANS: %s gets replaced by app name, usually "quamplures" */ TS_'Are you sure you want to delete your existing %s tables?\nDo you have a backup?' )$app_name );
  562.                 ?>' ) ) { this.form.confirmed.value = 1; return true; } else return false; }" />
  563.         </p>
  564.  
  565.         </form>
  566.         <?php
  567.         block_close();
  568.         display_base_config_recap();
  569.         break;
  570.  
  571.     case 'newdbsettings':
  572.         /*
  573.          * fp> TODO: Add a screen for additionnal settings:
  574.          * - create_sample_contents : to be moved away from main screen
  575.          * - storage_charset: offer option to FORCE storing data in UTF-8 even if current locale doesn't require it (must be supported by MySQL) -- recommended for multilingual blogs
  576.          * - evo_charset: offer option to FORCE handling data internally in UTF-8 even if current locale doesn't require it (requires mbstring) -- not recommended in most situations
  577.          */
  578.  
  579.     case 'newdb':
  580.         /*
  581.          * -----------------------------------------------------------------------------------
  582.          * NEW DB: install a new Quam Plures database.
  583.          * -----------------------------------------------------------------------------------
  584.          * Note: auto installers should kick in directly at this step and provide all required params.
  585.          */
  586.  
  587.         // fp> TODO: this test should probably be made more generic and applied to upgrade too.
  588.         $expected_connection_charset $DB->php_to_mysql_charmap($evo_charset);
  589.         if$DB->connection_charset != $expected_connection_charset )
  590.         {
  591.             echo '<div class="error"><p class="error">';
  592.             printfT_('In order to install %s with the %s locale, your MySQL needs to support '
  593.                       .'the %s connection charset (SET NAMES %s).' )$app_name$current_locale,
  594.                     $evo_charset$expected_connection_charset );
  595.             echo '</p></div>';
  596.             // sam2kb> TODO: If something is not supported we can display a message saying "do this and that, enable extension X etc. etc... or switch to a better hosting".
  597.             break;
  598.         }
  599.  
  600.  
  601.         install_newdb();
  602.         break;
  603.  
  604.  
  605.     case 'dbupgrade':
  606.         /*
  607.          * -----------------------------------------------------------------------------------
  608.          * DATABASE UPGRADE: Upgrade data from existing Quam Plures database
  609.          * -----------------------------------------------------------------------------------
  610.          */
  611.         require_oncedirname(__FILE__)'/_functions_dbupgrade.php' );
  612.  
  613.         echo '<h2>';
  614.         printfT_('Upgrading data in existing %s database...')$app_name );
  615.         echo '</h2>';
  616.         flush();
  617.         ifupgrade_dbase_tables() )
  618.         {
  619.             ?>
  620.             <p><?php echo T_('Upgrade completed successfully!')?></p>
  621.             <p><?php printfT_('Now you can <a %s>log in</a> with your usual %s username and password.')'href="'.$admin_url.'"'$app_name )?></p>
  622.             <?php
  623.         }
  624.         break;
  625.  
  626.  
  627.     case 'deletedb':
  628.         /*
  629.          * -----------------------------------------------------------------------------------
  630.          * DELETE DB: Delete the db structure!!! (Everything will be lost)
  631.          * -----------------------------------------------------------------------------------
  632.          */
  633.         require_oncedirname(__FILE__)'/_functions_delete.php' );
  634.  
  635.         printf'<img src="../qp_rsc/img/qp-logo.jpg" alt="'.T_('%s Logo').'" title="'.T_('%s Logo').'"/>'$app_name$app_name );
  636.         echo '<h2>';
  637.         printfT_('Deleting %s tables from the datatase...')$app_name );
  638.         echo '</h2>';
  639.         flush();
  640.  
  641.         if$app_allow_dbase_reset != )
  642.         {
  643.             printf/* TRANS: %1$s: App name. */
  644.                     T_('If you have installed %1$s tables before and wish to start anew, you must delete '
  645.                       .'the %1$s tables before you can start a new installation. %1$s can delete its '
  646.                       .'own tables for you, but for obvious security reasons, this feature is disabled '
  647.                       .'by default.')$app_name );
  648.             echo '<p>'.sprintfT_('To enable it, please go to the %s file and change: %s to %s')'/qp_config/_main_config.php''<pre>$app_allow_dbase_reset = 0;</pre>''<pre>$app_allow_dbase_reset = 1;</pre>' ).'</p>';
  649.             echo '<p>'.T_('Then reload this page and a reset option will appear.').'</p>';
  650.             echo '<p><a href="index.php?locale='.$default_locale.'">&laquo; '.T_('Back to install menu').'</a></p>';
  651.  
  652.             break;
  653.         }
  654.  
  655.         ifparam('confirmed''integer'1) )
  656.         {
  657.             ?>
  658.             <p>
  659.             <?php
  660.             echo nl2brhtmlspecialcharssprintf/* TRANS: %s gets replaced by app name, usually "quamplures" */ T_"Are you sure you want to delete your existing %s tables?\nDo you have a backup?" )$app_name ) ) );
  661.             ?>
  662.             </p>
  663.             <p>
  664.             <form class="inline" name="form" action="index.php" method="post">
  665.                 <input type="hidden" name="action" value="deletedb" />
  666.                 <input type="hidden" name="confirmed" value="1" />
  667.                 <input type="hidden" name="locale" value="<?php echo $default_locale?>" />
  668.                 <input type="submit" value="&nbsp; <?php echo T_('I am sure!')?> &nbsp;" />
  669.             </form>
  670.  
  671.             <form class="inline" name="form" action="index.php" method="get">
  672.                 <input type="hidden" name="locale" value="<?php echo $default_locale?>" />
  673.                 <input type="submit" value="&nbsp; <?php echo T_('CANCEL')?> &nbsp;" />
  674.             </form>
  675.             </p>
  676.             <?php
  677.             break;
  678.         }
  679.  
  680.         // Uninstall Plugins
  681.         // TODO: fp>> I don't trust the plugins to uninstall themselves correctly. There will be tons of lousy poorly written plugins. All I trust them to do is to crash the uninstall procedure. We want a hardcore brute force uninsall! and most users "may NOT want" to even think about "ma-nu-al-ly" removing something from their DB.
  682.         /*
  683.                 $DB->show_errors = $DB->halt_on_error = false;
  684.                 $Plugins = new Plugins();
  685.                 $DB->show_errors = $DB->halt_on_error = true;
  686.                 $at_least_one_failed = false;
  687.                 foreach( $Plugins->get_list_by_event( 'Uninstall' ) as $l_Plugin )
  688.                 {
  689.                     $success = $Plugins->call_method( $l_Plugin->ID, 'Uninstall', $params = array( 'unattended' => true ) );
  690.                     if( $success === false )
  691.                     {
  692.                         echo "Failed un-installing plugin $l_Plugin->classname (ID $l_Plugin->ID)...<br />\n";
  693.                         $at_least_one_failed = false;
  694.                     }
  695.                     else
  696.                     {
  697.                         echo "Uninstalled plugin $l_Plugin->classname (ID $l_Plugin->ID)...<br />\n";
  698.                     }
  699.                 }
  700.                 if( $at_least_one_failed )
  701.                 {
  702.                     echo "You may want to manually remove left files or DB tables from the failed plugin(s).<br />\n";
  703.                 }
  704.                 $DB->show_errors = $DB->halt_on_error = true;
  705.         */
  706.  
  707.         db_delete();
  708.         ?>
  709.         <p><?php echo T_('Reset done!')?></p>
  710.         <p><a href="index.php?locale=<?php echo $default_locale ?>">&laquo; <?php echo T_('Back to install menu'?></a></p>
  711.         <?php
  712.         break;
  713. }
  714.  
  715. ?>
  716.  
  717.     </div>
  718.  
  719. </body>
  720. </html>