Incam_FormulariosCalidad/installer.php

345 lines
16 KiB
PHP
Raw Normal View History

<?php
/******************************************************************************
MachForm
Copyright 2007 Appnitro Software. This code cannot be redistributed without
permission from http://www.appnitro.com/
More info at: http://www.appnitro.com/
******************************************************************************/
ini_set("display_errors","1");
if(!file_exists("config.php")){
$state = 'show_error_no_config';
}else{
///check is machform already installed or not?
@include("config.php");
@mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
$mysql_connect_error = mysql_error();
@mysql_select_db(DB_NAME);
$mysql_select_db_error = mysql_error();
if(!empty($mysql_connect_error)){
$mysql_select_db_error = "Unable to connect to MySQL";
}
@mysql_query("select count(*) from `ap_forms`");
$error = mysql_error();
if(empty($error)){ //MachForm already installed, display a warning instead
$state = 'show_error_already_installed';
}else{ //do an install or pre-installation check
if(!empty($_REQUEST['run_install'])){ //do installation
//create the tables (ap_forms, ap_form_elements, ap_element_options
$query = "CREATE TABLE `ap_forms` (
`form_id` int(11) NOT NULL auto_increment,
`form_name` text,
`form_description` text default NULL,
`form_email` varchar(255) default NULL,
`form_redirect` text default NULL,
`form_success_message` text default NULL,
`form_password` varchar(100) default NULL,
`form_unique_ip` int(1) NOT NULL default '0',
`form_frame_height` int(11) default NULL,
`form_has_css` int(11) NOT NULL default '0',
`form_captcha` int(11) NOT NULL default '0',
`form_active` int(11) NOT NULL default '1',
`form_review` int(11) NOT NULL default '0',
`esl_from_name` text default NULL,
`esl_from_email_address` varchar(255) default NULL,
`esl_subject` text,
`esl_content` mediumtext,
`esl_plain_text` int(11) NOT NULL default '0',
`esr_email_address` varchar(255) default NULL,
`esr_from_name` text default NULL,
`esr_from_email_address` varchar(255) default NULL,
`esr_subject` text,
`esr_content` mediumtext,
`esr_plain_text` int(11) NOT NULL default '0',
PRIMARY KEY (`form_id`)
) DEFAULT CHARACTER SET utf8;";
mysql_query($query);
$error_1 = mysql_error();
if(!empty($error_1)){
$create_table_error[] = $error_1;
}
$query = "CREATE TABLE `ap_form_elements` (
`form_id` int(11) NOT NULL default '0',
`element_id` int(11) NOT NULL default '0',
`element_title` text default NULL,
`element_guidelines` text default NULL,
`element_size` varchar(6) NOT NULL default 'medium',
`element_is_required` int(11) NOT NULL default '0',
`element_is_unique` int(11) NOT NULL default '0',
`element_is_private` int(11) NOT NULL default '0',
`element_type` varchar(50) default NULL,
`element_position` int(11) NOT NULL default '0',
`element_default_value` text default NULL,
`element_constraint` varchar(50) default NULL,
`element_total_child` int(11) NOT NULL default '0',
PRIMARY KEY (`form_id`,`element_id`)
) DEFAULT CHARACTER SET utf8;";
mysql_query($query);
$error_2 = mysql_error();
if(!empty($error_2)){
$create_table_error[] = $error_2;
}
$query = "CREATE TABLE `ap_element_options` (
`aeo_id` int(11) NOT NULL auto_increment,
`form_id` int(11) NOT NULL default '0',
`element_id` int(11) NOT NULL default '0',
`option_id` int(11) NOT NULL default '0',
`position` int(11) NOT NULL default '0',
`option` text default NULL,
`option_is_default` int(11) NOT NULL default '0',
`live` int(11) NOT NULL default '1',
PRIMARY KEY (`aeo_id`)
) DEFAULT CHARACTER SET utf8;";
mysql_query($query);
$error_3 = mysql_error();
if(!empty($error_3)){
$create_table_error[] = $error_3;
}
$query = "CREATE TABLE `ap_column_preferences` (
`acp_id` int(11) NOT NULL auto_increment,
`form_id` int(11) default NULL,
`element_name` varchar(255) NOT NULL default '',
`position` int(11) NOT NULL default '0',
PRIMARY KEY (`acp_id`),
KEY `acp_position` (`form_id`,`position`)
) DEFAULT CHARACTER SET utf8;";
mysql_query($query);
$error_4 = mysql_error();
if(!empty($error_4)){
$create_table_error[] = $error_4;
}
if(empty($create_table_error)){
$install_message = "<b>¡Felicidades!</b> Ha completado la instalación. MachForm está instalado.";
}else{
$install_message = "Ha habido algún error con la instalación.";
}
$state = 'install_report';
}else{
//do a pre installation check
$state = 'show_preinstall_check';
//check for PHP version
if(version_compare(PHP_VERSION,"4.3.0",">=")){
$is_php_version_passed = true;
}else{
$is_php_version_passed = false;
$pre_install_has_error = true;
}
//check for MySQL version
if(version_compare(mysql_get_server_info(),"4.1.0",">=")){
$is_mysql_version_passed = true;
}else{
$is_mysql_version_passed = false;
$pre_install_has_error = true;
}
//check for MySQL user,password and database existance
if(empty($mysql_connect_error)){
$is_mysql_connect_passed = true;
}else{
$is_mysql_connect_passed = false;
$pre_install_has_error = true;
}
if(empty($mysql_select_db_error)){
$is_mysql_select_db_passed = true;
}else{
$is_mysql_select_db_passed = false;
$pre_install_has_error = true;
}
//check for data folder permission
if(is_writable(DATA_DIR)){
$is_data_dir_writable = true;
}else {
$is_data_dir_writable = false;
$pre_install_has_error = true;
$data_dir_writable_error = "MachForm necesita permisos de <b>lectura</b> y <b>escritura</b> en esta carpeta. Por favor, corriga los permisos.";
}
if($pre_install_has_error){
$pre_install_message = "Su sistema no tiene los requerimientos mímos necesarios. Realice las acciones apropiadas para subsanar este error.";
}else{
$pre_install_message = "Si sistema tiene los requerimientos mínimos necesarios. Puede iniciar la instalación";
}
}
}
}
$hide_nav = true;
?>
<?php require('includes/header.php'); ?>
<div id="form_manager" style="padding-left: 50px;padding-top: 50px;padding-bottom: 50px">
<?php
if($state == 'show_error_no_config'){
?>
<div class="info" style="width: 80%">
<h2><img src="images/icons/package_applications.gif" align="absmiddle" /> Error del instalador de MachForm</h2>
<p>Por favor, revise los siguientes errores para continuar con el proceso de instalación</p>
</div>
<div id="form_container" style="align: center">
<form id="form_login" class="appnitro" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<ul style="width: 80%;">
<li class="error" style="padding-left: 15px;padding-top: 15px;">
<label class="desc"><img src="images/icons/stop.gif" align="absmiddle" style="padding-bottom: 5px"/> Fichero de configuración encontrado</label>
<br />
<div><p>
No se ha encontrado el fichero <b>config.php</b>. Este fichero es necesario para iniciar la instalación.
</p>
<br /><br />
<p> En el directorio raíz de su instalación, encontrará un fichero llamado <strong>config-empty.php</strong>. Abra este fichero y rellene la información de conexión a la base de datos.</p><br /><br />
<p> Cuando termine, <strong> debe renombrar el fichero a config.php </strong> para poder continuar. </p><br />
</div>
</li>
<li class="buttons" style="padding-left:0px">
<input id="login" class="button_text" type="submit" name="submit" value="Probar de nuevo" style="padding: 8px" />
</li>
</ul>
</form>
</div><br />
<?php }elseif ($state == 'show_preinstall_check'){ ?>
<div class="info" style="width: 80%">
<h2><img src="images/icons/package_applications.gif" align="absmiddle" /> Comprobación de pre-instalación de MachForm</h2>
<p><?php echo $pre_install_message; ?></p>
</div>
<div id="form_container" style="align: center">
<form id="form_login" class="appnitro" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<ul style="width: 80%;">
<li class="<?php if($is_php_version_passed){ echo 'highlighted'; }else{ echo 'error'; }; ?>" style="padding-left: 15px;padding-top: 10px;">
<label class="desc"><img src="images/icons/<?php if($is_php_version_passed){ echo 'checkbox'; }else{ echo 'cross'; }; ?>_16.gif" align="absmiddle" style="padding-bottom: 5px"/> &nbsp;Versión de PHP &gt;= 4.3.0</label>
</li>
<li class="<?php if($is_mysql_version_passed){ echo 'highlighted'; }else{ echo 'error'; }; ?>" style="padding-left: 15px;padding-top: 10px;">
<label class="desc"><img src="images/icons/<?php if($is_mysql_version_passed){ echo 'checkbox'; }else{ echo 'cross'; }; ?>_16.gif" align="absmiddle" style="padding-bottom: 5px"/> &nbsp;Versión de MySQL &gt;= 4.1.0</label>
</li>
<li class="<?php if($is_mysql_connect_passed){ echo 'highlighted'; }else{ echo 'error'; }; ?>" style="padding-left: 15px;padding-top: 10px;">
<label class="desc"><img src="images/icons/<?php if($is_mysql_connect_passed){ echo 'checkbox'; }else{ echo 'cross'; }; ?>_16.gif" align="absmiddle" style="padding-bottom: 5px"/> &nbsp;Usuario y contraseña de MySQL correctos</label><?php echo $mysql_connect_error; ?>
</li>
<li class="<?php if($is_mysql_select_db_passed){ echo 'highlighted'; }else{ echo 'error'; }; ?>" style="padding-left: 15px;padding-top: 10px;">
<label class="desc"><img src="images/icons/<?php if($is_mysql_select_db_passed){ echo 'checkbox'; }else{ echo 'cross'; }; ?>_16.gif" align="absmiddle" style="padding-bottom: 5px"/> &nbsp;Comprobando la conexión a la base de datos [<?php echo DB_NAME; ?>]</label><?php echo $mysql_select_db_error; ?>
</li>
<li class="<?php if($is_data_dir_writable){ echo 'highlighted'; }else{ echo 'error'; }; ?>" style="padding-left: 15px;padding-top: 10px;">
<label class="desc"><img src="images/icons/<?php if($is_data_dir_writable){ echo 'checkbox'; }else{ echo 'cross'; }; ?>_16.gif" align="absmiddle" style="padding-bottom: 5px"/> &nbsp;Comprobando el acceso para escritura en el directorio de datos [<?php echo DATA_DIR; ?>]</label><?php echo $data_dir_writable_error; ?>
</li>
<li class="buttons" style="padding-left:0px">
<?php if($pre_install_has_error){ ?>
<input id="login" class="button_text" type="submit" name="submit" value="Comprobar de nuevo" style="padding: 8px" />
<?php } else { ?>
<input type="hidden" id="run_install" name="run_install" value="1" />
<input id="login" class="button_text" type="submit" name="submit" value="Iniciar instalación" style="padding: 8px" />
<?php } ?>
</li>
</ul>
</form>
</div><br />
<?php }elseif ($state == 'show_error_already_installed'){ ?>
<div class="info" style="width: 80%">
<h2><img src="images/icons/package_applications.gif" align="absmiddle" /> Eliminar el fichero del instalador</h2>
<p>Por favor, siga los siguientes pasos para poder continuar:</p>
</div>
<div id="form_container" style="align: center">
<form id="form_login" class="appnitro" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<ul style="width: 80%;">
<li class="error" style="padding-left: 15px;padding-top: 15px;">
<label class="desc"><img src="images/icons/stop.gif" align="absmiddle" style="padding-bottom: 5px"/> &nbsp;Por favor, elimine este fichero</label>
<br />
<div><p>
MachForm ya está instalado y listo para utilizarse.
</p>
<br />
<p> Por favor, elimine el fichero (<strong>installer.php</strong>) antes de empezar a utilizar MachForm.</p><br />
<p> Después de eliminar el fichero, puede <a href="index.php">iniciar sesión aquí</a>. </p><br />
</div>
</li>
</ul>
</form>
</div><br />
<?php }elseif ($state == 'install_report'){ ?>
<div class="info" style="width: 80%">
<h2><img src="images/icons/package_applications.gif" align="absmiddle" /> Resumen de la instalación de MachForm</h2>
<p><?php echo $install_message; ?></p>
</div>
<div id="form_container" style="align: center">
<form id="form_login" class="appnitro" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<ul style="width: 80%;">
<?php if(empty($create_table_error)){ ?>
<li class="highlighted" style="padding-left: 15px;padding-top: 10px;">
<label class="desc"><img src="images/icons/checkbox_16.gif" align="absmiddle" style="padding-bottom: 5px"/> &nbsp;Tabla <b>ap_forms</b> creada</label>
</li>
<li class="highlighted" style="padding-left: 15px;padding-top: 10px;">
<label class="desc"><img src="images/icons/checkbox_16.gif" align="absmiddle" style="padding-bottom: 5px"/> &nbsp;Tabla <b>ap_form_elements</b> creada</label>
</li>
<li class="highlighted" style="padding-left: 15px;padding-top: 10px;">
<label class="desc"><img src="images/icons/checkbox_16.gif" align="absmiddle" style="padding-bottom: 5px"/> &nbsp;Tabla <b>ap_element_options</b> creada</label>
</li>
<li class="highlighted" style="padding-left: 15px;padding-top: 10px;">
<label class="desc"><img src="images/icons/checkbox_16.gif" align="absmiddle" style="padding-bottom: 5px"/> &nbsp;Tabla <b>ap_column_preferences</b> creada</label>
</li>
<li class="highlighted" style="padding-left: 15px;padding-top: 10px;">
<label class="desc"><img src="images/icons/checkbox_16.gif" align="absmiddle" style="padding-bottom: 5px"/> &nbsp;<b>¡Instalación completada!</b></label>
</li>
<li style="padding-left: 0px;padding-top: 10px; margin-top: 5px">
<img src="images/icons/information.gif" align="absmiddle" /> <b>Importante:</b> Por favor, elimine el fichero de instalación (<b>installer.php</b>) ahora. <br /><br />Después de eliminar este fichero, puede iniciar sesión en el <a href="index.php">panel de administración de MachForm</a>
</li>
<?php } else{ ?>
<li class="error" style="padding-left: 15px;padding-top: 15px;">
<label class="desc"><img src="images/icons/stop.gif" align="absmiddle" style="padding-bottom: 5px"/> Se ha encontrado un error durante la instalación</label>
</li>
<?php
foreach ($create_table_error as $error_msg){ ?>
<li class="highlighted" style="padding-left: 15px;padding-top: 10px;">
<label class="desc"><img src="images/icons/cross_16.gif" align="absmiddle" style="padding-bottom: 5px"/> &nbsp;<?php echo $error_msg; ?></label>
</li>
<?php }
?>
<?php } ?>
<?php if(!empty($create_table_error)){ ?>
<li class="buttons" style="padding-left:0px">
<input type="hidden" id="run_install" name="run_install" value="1" />
<input id="login" class="button_text" type="submit" name="submit" value="Try Again" style="padding: 8px" />
</li>
<?php } ?>
</ul>
</form>
</div><br />
<?php } ?>
</div>
<?php require('includes/footer.php'); ?>