Fix: Meilleur gestion du "test de connexion" webcalendar.

This commit is contained in:
Laurent Destailleur 2004-06-26 23:00:30 +00:00
parent d39d41c060
commit 34dd68f32d

View File

@ -35,63 +35,41 @@ print '<br>';
$def = array(); $def = array();
// positionne la variable pour le test d'affichage de l'icone $phpwebcalendar_url=$_POST["phpwebcalendar_url"];
$phpwebcalendar_host=$_POST["phpwebcalendar_host"];
$phpwebcalendar_dbname=$_POST["phpwebcalendar_dbname"];
$phpwebcalendar_user=$_POST["phpwebcalendar_user"];
$phpwebcalendar_pass=$_POST["phpwebcalendar_pass"];
$phpwebcalendar_pass2=$_POST["phpwebcalendar_pass2"];
$actionsave=$_POST["save"];
$actiontest=$_POST["test"];
if ($action == 'save') // Positionne la variable pour le test d'affichage de l'icone
if ($actionsave)
{ {
if (trim($phpwebcalendar_pass) == trim($phpwebcalendar_pass2)) if (trim($phpwebcalendar_pass) == trim($phpwebcalendar_pass2))
{ {
$conf = new Conf(); $sql = "REPLACE INTO ".MAIN_DB_PREFIX."const SET name = 'PHPWEBCALENDAR_URL',value='".$phpwebcalendar_url."', visible=0";
$conf->db->host = $phpwebcalendar_host; $sql1 = "REPLACE INTO ".MAIN_DB_PREFIX."const SET name = 'PHPWEBCALENDAR_HOST',value='".$phpwebcalendar_host."', visible=0";
$conf->db->name = $phpwebcalendar_dbname; $sql2 = "REPLACE INTO ".MAIN_DB_PREFIX."const SET name = 'PHPWEBCALENDAR_DBNAME', value='".$phpwebcalendar_dbname."', visible=0";
$conf->db->user = $phpwebcalendar_user; $sql3 = "REPLACE INTO ".MAIN_DB_PREFIX."const SET name = 'PHPWEBCALENDAR_USER', value='".$phpwebcalendar_user."', visible=0";
$conf->db->pass = $phpwebcalendar_pass; $sql4 = "REPLACE INTO ".MAIN_DB_PREFIX."const SET name = 'PHPWEBCALENDAR_PASS', value='".$phpwebcalendar_pass."', visible=0";
$webcal = new DoliDb(); if ($db->query($sql) && $db->query($sql1) && $db->query($sql2) && $db->query($sql3) && $db->query($sql4))
if ($webcal->connected == 1)
{ {
$sql = "REPLACE INTO ".MAIN_DB_PREFIX."const SET name =
'PHPWEBCALENDAR_URL',value='".$phpwebcalendar_url."', visible=0";
$sql1 = "REPLACE INTO ".MAIN_DB_PREFIX."const SET name =
'PHPWEBCALENDAR_HOST',value='".$phpwebcalendar_host."', visible=0";
$sql2 = "REPLACE INTO ".MAIN_DB_PREFIX."const SET name = 'PHPWEBCALENDAR_DBNAME',
value='".$phpwebcalendar_dbname."', visible=0";
$sql3 = "REPLACE INTO ".MAIN_DB_PREFIX."const SET name = 'PHPWEBCALENDAR_USER',
value='".$phpwebcalendar_user."', visible=0";
$sql4 = "REPLACE INTO ".MAIN_DB_PREFIX."const SET name = 'PHPWEBCALENDAR_PASS',
value='".$phpwebcalendar_pass."', visible=0";
if ($db->query($sql) && $db->query($sql1) && $db->query($sql2) && $db->query($sql3) &&
$db->query($sql4))
{
// la constante qui a été lue en avant du nouveau set // la constante qui a été lue en avant du nouveau set
// on passe donc par une variable pour avoir un affichage cohérent // on passe donc par une variable pour avoir un affichage cohérent
define("PHPWEBCALENDAR_URL", $phpwebcalendar_url); define("PHPWEBCALENDAR_URL", $phpwebcalendar_url);
define("PHPWEBCALENDAR_HOST", $phpwebcalendar_host); define("PHPWEBCALENDAR_HOST", $phpwebcalendar_host);
define("PHPWEBCALENDAR_DBNAME",$phpwebcalendar_dbname); define("PHPWEBCALENDAR_DBNAME",$phpwebcalendar_dbname);
define("PHPWEBCALENDAR_USER", $phpwebcalendar_user); define("PHPWEBCALENDAR_USER", $phpwebcalendar_user);
define("PHPWEBCALENDAR_PASS", $phpwebcalendar_pass); define("PHPWEBCALENDAR_PASS", $phpwebcalendar_pass);
$ok = "<p>Les identifiants webcalendar ont été sauvegardés.</p>";
$ok = 1;
}
else
print "<p>erreur d'enregistement dans la base de données $db !</p><br>";
}
else
{
$ok = 0;
} }
} }
else else
{ {
print "<p>le mot de passe n'est pas identique, veuillez le reintroduire</p><br>\n"; $ok="<p>Le mot de passe n'est pas identique, veuillez le saisir à nouveau</p><br>\n";
} }
} }
@ -131,30 +109,29 @@ print "\n<form name=\"phpwebcalendarconfig\" action=\"" . $PHP_SELF . "\" method
<td><input type=\"password\" name=\"phpwebcalendar_pass2\" value=\"" . PHPWEBCALENDAR_PASS ."\" size=\"45\"></td> <td><input type=\"password\" name=\"phpwebcalendar_pass2\" value=\"" . PHPWEBCALENDAR_PASS ."\" size=\"45\"></td>
</tr> </tr>
<tr class=\"impair\"> <tr class=\"impair\">
<td colspan=\"2\"><input type=\"submit\" name=\"envoyer\" value=\"Enregistrer\"></td> <td colspan=\"2\" align=\"center\">
<input type=\"submit\" name=\"test\" value=\"Tester connexion\">
<input type=\"submit\" name=\"save\" value=\"Enregistrer\">
</td>
</tr>\n"; </tr>\n";
clearstatcache(); clearstatcache();
print " print "
</table> </table>
<input type=\"hidden\" name=\"action\" value=\"save\">
</form>\n"; </form>\n";
/** /**
* test de la connection a la database webcalendar * Test de la connection a la database webcalendar
* *
*/ */
if ($ok) print "$ok<br>";
print '<br><a href="webcalendar.php?action=test">test de connection à la database</a><br>'; if ($actiontest)
if($ok)
print "<p>la connection à la base de données webcalendar $phpwebcalendar_dbname à réussi</p><br>";
if ($_GET["action"] == 'test')
{ {
$conf = new Conf(); $conf = new Conf();
$conf->db->host = $phpwebcalendar_host; $conf->db->host = $phpwebcalendar_host;
$conf->db->name = $phpwebcalendar_dbname; $conf->db->name = $phpwebcalendar_dbname;
$conf->db->user = $phpwebcalendar_user; $conf->db->user = $phpwebcalendar_user;
@ -164,16 +141,13 @@ print "\n<form name=\"phpwebcalendarconfig\" action=\"" . $PHP_SELF . "\" method
if ($webcal->connected == 1) if ($webcal->connected == 1)
{ {
print "<p>la connection à la base de données webcalendar $phpwebcalendar_dbname à print "<p class=\"ok\">La connection à la base de données '$phpwebcalendar_dbname' à réussi</p><br>";
réussi</p><br>";
$webcal->close(); $webcal->close();
} }
else else
print "<p>la connection à la base de données webcalendar $phpwebcalendar_dbname à print "<p class=\"error\">La connection à la base de données '$phpwebcalendar_dbname' à échoué.</p><br>";
échoué</p><br>";
} }
$db->close();
llxFooter(); llxFooter();
?> ?>