<?php

/**
 *
 * @copyright  2010-2016 izend.org
 * @version    13
 * @link       http://www.izend.org
 */
?>
<?php extract($errors); ?>
<p>Your <b>iZend</b> site is practically operational.
Read the following instructions, fill in the form and press Configure to run the configurator.</p>
<h6>Parameters</h6>
<p>Enter the name of the site, the email address of the webmaster and select the languages managed by the site.
Initially, you will only be allowed to choose among the languages supported by the core of the software.
Once the site is configured, you will be able to easily add contents in several other languages.
All the parameters of the software are in the folder <i>includes</i>.
The configurator rewrites the configuration files <i>config.inc</i>, <i>db.inc</i> and <i>aliases.inc</i> and the files <i>sitemap.xml</i>, <i>robots.txt</i> and <i>.htaccess</i> in the root directory of the site.</p>
<p>For more security, check that the access to the configuration files is limited to the server:</p>
<pre><code>$ cd <?php echo ROOT_DIR; ?>; sudo chgrp -R www-data .; chmod -R g+w .
$ cd <?php echo ROOT_DIR; ?>/includes; chmod 660 db.inc config.inc settings.inc aliases.inc paypal.inc</code></pre>
<p>NOTE: The name of the execution group of the server is defined by the Group directive, generally in the file <i>/etc/apache2/apache2.conf</i>.</p>
<h6>Logo</h6>
<p>The configurator generates a logo based on the name of the site and saves it in the file <i>sitelogo.png</i> in the folder <i>logos</i>.
You will probably want to change it.</p>
<h6>Database</h6>
<p>iZend can function without a database.
In this mode, you will still be able to benefit from the architecture of the software, but you will have to write the pages of the site without the editor.
Choose this configuration to put on-line a site with limited resources.
Note that iZend can occupy very little space on disk.</p>
<p>To exploit the full potential of iZend, you need a database server.
You can use either MySQL or PostgreSQL.
The configurator can create a new database or use an already existing database.
<b>IMPORTANT</b>: If the database is shared, ask the configurator to add a prefix to the table names.
In any case, using a prefix is safer.</p>
<p>NOTE: If you develop the site locally before it is put on-line, which is recommended, use the same parameters on both servers.</p>
<h5 id="configuration">Configuration</h5>
<?php if ($bad_write_permission): ?>
<div class="alert">
<p>The server isn't allowed to modify <?php if (count($bad_write_permission) > 1): ?>the following folders or files<?php else: ?>the following folder or file<?php endif; ?> in the folder <i><?php echo ROOT_DIR; ?></i>:
</p>
<ul>
<?php foreach ($bad_write_permission as $file): ?>
<li><i><?php echo $file; ?></i></li>
<?php endforeach; ?>
</ul>
</div>
<p>To modify the access rights, try the following command:</p>
<pre><code>$ cd <?php echo ROOT_DIR; ?>; chmod a+w<?php foreach ($bad_write_permission as $fname) { echo ' ', $fname; }; ?></code></pre>
<?php endif; ?>
<?php $nerrors=count(array_keys($errors, true, true)); ?>
<?php if ($nerrors > 0): ?>
<div class="alert">
<p>The form has <?php echo $nerrors; ?> error<?php if ($nerrors > 1): ?>s<?php endif; ?>.
Check your answers and rerun the configuration.</p>
</div>
<?php endif; ?>
<?php if ($internal_error): ?>
<div class="alert">
<p>Generating the configuration files has failed.</p>
</div>
<?php endif; ?>
<?php if ($file_error): ?>
<div class="alert">
<p>Writing the configuration files has failed.</p>
</div>
<?php endif; ?>
<form class="compact" action="#configuration" method="post">
<input type="hidden" name="configure_token" value="<?php echo $token; ?>" />
<p>What is the name of the site?</p>
<p class="info">Specify a domain name without the www prefix.</p>
<p>
<input type="text" name="configure_sitename" size="30" maxlength="40" title="" value="<?php echo $sitename; ?>" />
<span class="icon icon_web"></span>
</p>
<?php if ($missing_sitename): ?>
<p class="error">Enter a domain name such as izend.org.</p>
<?php endif; ?>
<p>What is the email address of the webmaster?</p>
<p class="info">The contact page will send messages to this address.</p>
<p>
<input type="text" name="configure_webmaster" size="50" maxlength="100" title="Email" value="<?php echo $webmaster; ?>" />
<span class="icon icon_mail"></span>
</p>
<?php if ($missing_webmaster): ?>
<p class="error">Specify a valid email address.</p>
<?php endif; ?>
<p>In what languages is the content of the site written?</p>
<p class="info">You will always be able to add more languages later.</p>
<p><?php foreach ($system_languages as $slang): ?><?php echo PHP_EOL; ?><input name="configure_content_languages[]" type="checkbox" value="<?php echo $slang; ?>" title="<?php echo $slang; ?>"<?php if (in_array($slang, $content_languages)) echo ' checked="checked"'; ?>/>&nbsp;<span class="lang <?php echo $slang; ?>" title="<?php echo $slang; ?>"><?php echo $slang; ?></span><?php endforeach; ?><?php echo PHP_EOL; ?></p>
<?php if ($missing_content_languages): ?>
<p class="error">Choose at least one language for the content of the site.</p>
<?php endif; ?>
<p>What is the default language?</p>
<p><?php foreach ($system_languages as $slang): ?><?php echo PHP_EOL; ?><input name="configure_default_language" type="radio" value="<?php echo $slang; ?>" title="<?php echo $slang; ?>"<?php if ($slang == $default_language) echo ' checked="checked"'; ?> />&nbsp;<span class="lang <?php echo $slang; ?>" title="<?php echo $slang; ?>"><?php echo $slang; ?></span><?php endforeach; ?><?php echo PHP_EOL; ?></p>
<?php if ($bad_default_language): ?>
<p class="error">You haven't mentionned this language in the previous list.</p>
<?php endif; ?>
<h6>Database</h6>
<?php if ($db_error): ?>
<div class="alert">
<p>The configuration of the database has failed with the error:</p>
<p><?php echo htmlspecialchars($db_error); ?></p>
<?php if ($db_flag and !$db_reuse): ?>
<?php if ($db_type == 'mysql'): ?>
<p><b>IMPORTANT</b>: Before you can retry the configuration, you must manually delete the <code><?php echo $db_name; ?></code> DB
and the entries for the user <code><?php echo $db_user; ?></code> in the <i>user</i> and <i>db</i> tables of the <i>mysql</i> DB.</p>
<?php elseif ($db_type == 'pgsql'): ?>
<p><b>IMPORTANT</b>: Before you can retry the configuration, you must manually delete the <code><?php echo $db_name; ?></code> DB
and the role <code><?php echo $db_user; ?></code>.</p>
<?php endif; ?>
<?php endif; ?>
</div>
<?php endif; ?>
<p>Do you have a database server?</p>
<p class="info">Without a database, the functionalities will be more limited.</p>
<p><input type="radio" name="configure_db_flag" value="yes"<?php if ($db_flag): ?> checked="checked"<?php endif; ?> />&nbsp;yes <input name="configure_db_flag" type="radio" value="no"<?php if (!$db_flag): ?> checked="checked"<?php endif; ?> />&nbsp;no</p>
<p>Do you use MySQL or PostgreSQL?</p>
<p><input type="radio" name="configure_db_type" title="" value="mysql"<?php if ($db_type == 'mysql'): ?> checked="checked"<?php endif; ?> />&nbsp;MySQL
<input type="radio" name="configure_db_type" title="" value="pgsql"<?php if ($db_type == 'pgsql'): ?> checked="checked"<?php endif; ?> />&nbsp;PostgreSQL</p>
<?php if ($bad_db_type): ?>
<p class="error">Check the option MySQL or the option PostgreSQL.</p>
<?php endif; ?>
<p>What is the name of the database?</p>
<p><input type="text" name="configure_db_name" size="30" maxlength="40" title="" value="<?php echo $db_name; ?>" /></p>
<?php if ($missing_db_name or $bad_db_name): ?>
<p class="error">Enter between 2 and 30 characters (letter, digit or underscore) starting with a letter.</p>
<?php endif; ?>
<p>What is the name of the database host?</p>
<p><input type="text" name="configure_db_host" size="30" maxlength="40" title="" value="<?php echo $db_host; ?>" /></p>
<?php if ($missing_db_host or $bad_db_host): ?>
<p class="error">Enter a server name or an IP address.</p>
<?php endif; ?>
<p>What are the name and the password of the user of the database?</p>
<p>
<input type="text" name="configure_db_user" size="30" maxlength="40" title="" value="<?php echo $db_user; ?>" />
<span class="icon icon_user"></span>
<input type="text" name="configure_db_password" size="30" maxlength="40" title="" value="<?php echo $db_password; ?>" autocomplete="off" />
<span class="icon icon_lock"></span>
</p>
<?php if ($missing_db_user and $missing_db_password): ?>
<p class="error">Choose an identifier for the user of the database and a password.</p>
<?php else: ?>
<?php if ($missing_db_user or $bad_db_user): ?>
<p class="error">Enter between 2 and 30 characters (letter, digit or underscore) starting with a letter.</p>
<?php endif; ?>
<?php if ($missing_db_password): ?>
<p class="error">Enter a password.</p>
<?php elseif ($weak_db_password): ?>
<p class="error">Enter a combination of letters and digits of at least 6 characters.</p>
<?php endif; ?>
<?php endif; ?>
<p>Do you use an existing database?</p>
<p><input type="radio" name="configure_db_reuse" value="yes" <?php if ($db_reuse) echo 'checked="checked"'; ?> />&nbsp;yes <input type="radio" name="configure_db_reuse" value="no" <?php if (!$db_reuse) echo 'checked="checked"'; ?> />&nbsp;no</p>
<p>If no, what are the name and the password of the administrator of the database server?</p>
<p class="info">This information will not be registered.</p>
<p>
<input type="text" name="configure_db_admin_user" size="30" maxlength="40" title="" value="<?php echo $db_admin_user; ?>" />
<span class="icon icon_user"></span>
<input type="password" name="configure_db_admin_password" size="30" maxlength="40" title="" value="<?php echo $db_admin_password; ?>" autocomplete="off" />
<span class="icon icon_lock"></span>
</p>
<?php if ($missing_db_admin_user and $missing_db_admin_password): ?>
<p class="error">Enter the identifier of the administrator of the database server followed by his password.</p>
<?php else: ?>
<?php if ($missing_db_admin_user): ?>
<p class="error">Enter the identifier of the administrator of the database server.</p>
<?php endif; ?>
<?php if ($missing_db_admin_password): ?>
<p class="error">Enter the password of the administrator of the database server.</p>
<?php endif; ?>
<?php endif; ?>
<p>What is the prefix of the tables?</p>
<p class="info">A prefix is necessary if the database is shared.</p>
<p><input type="text" name="configure_db_prefix" size="10" maxlength="20" title="" value="<?php echo $db_prefix; ?>" /></p>
<?php if ($bad_db_prefix): ?>
<p class="error">Enter between 2 and 30 characters (letter, digit or underscore) starting with a letter.</p>
<?php endif; ?>
<p>What are the name and the password of the administrator of the site?</p>
<p>
<input type="text" name="configure_site_admin_user" size="30" maxlength="40" title="" value="<?php echo $site_admin_user; ?>" />
<span class="icon icon_user"></span>
<input type="text" name="configure_site_admin_password" size="30" maxlength="40" title="" value="<?php echo $site_admin_password; ?>" autocomplete="off" />
<span class="icon icon_lock"></span>
</p>
<?php if ($missing_site_admin_user and $missing_site_admin_password): ?>
<p class="error">Choose an identifier for the administrator of the site and a password.</p>
<?php else: ?>
<?php if ($missing_site_admin_user or $bad_site_admin_user): ?>
<p class="error">Enter between 2 and 30 characters (letter, digit or underscore) starting with a letter.</p>
<?php endif; ?>
<?php if ($missing_site_admin_password): ?>
<p class="error">Enter a password.</p>
<?php elseif ($weak_site_admin_password): ?>
<p class="error">Enter a combination of lowercase and uppercase letters and digits of at least 6 characters.</p>
<?php endif; ?>
<?php endif; ?>
<p><input type="submit" class="submit submit_configure" name="configure_configure" id="configure_configure" value="Configure" /></p>
</form>
