Add method for enable/disable a domain

This commit is contained in:
Victor LABORIE 2017-12-16 17:38:52 +01:00
parent 73b1e5e1e1
commit 47b616ee8a
2 changed files with 28 additions and 2 deletions

View file

@ -38,11 +38,28 @@ if (!empty($_POST['delete'])) {
print '</div>';
}
if (!empty($_POST['isactive'])) {
$active = ($_POST['isactive'] == "TRUE") ? true : false;
try {
$domain->update($active);
header('Location: admin.php?domain='.$domain->getName());
} catch (Exception $e) {
print '<div class="alert alert-danger" role="alert">'.$e->getMessage().'</div>';
}
}
?>
<div class="container">
<div class="text-center">
<a href="compte.php?domain=<?php print $domain->getName() ?>"><button class="btn btn-primary">Ajouter un nouveau compte</button></a>&nbsp;&nbsp;&nbsp;
<?php
print '<form name="update" method="post" action="admin.php?domain='.$domain->getName().'">';
if (!$domain->isactive()) {
print '<button type="submit" name="isactive" value="TRUE" class="btn btn-primary">Activer le domaine</button>&nbsp;&nbsp;&nbsp;';
} else {
print '<button type="submit" name="isactive" value="FALSE" class="btn btn-primary">Désactiver le domaine</button>&nbsp;&nbsp;&nbsp;';
}
?>
<a href="compte.php?domain=<?php print $domain->getName() ?>"><button type="button" class="btn btn-primary">Ajouter un nouveau compte</button></a>&nbsp;&nbsp;&nbsp;
<?php
// only for mail mode
@ -52,7 +69,8 @@ if (!empty($_POST['delete'])) {
$viewonly2= ( (isset($_GET['viewonly'])) && ($_GET['viewonly']==2) ) ? "selected='selected'" : "";
?>
<a href="alias.php?domain=<?php print $domain->getName() ?>"><button class="btn btn-primary">Ajouter un nouvel alias/groupe de diffusion</button></a>
<a href="alias.php?domain=<?php print $domain->getName() ?>"><button type="button" class="btn btn-primary">Ajouter un nouvel alias/groupe de diffusion</button></a>
</form>
</div>
<hr>
<form class='center' action='admin.php' method='GET' name='listing'>

View file

@ -128,6 +128,14 @@ class LdapDomain extends LdapServer {
}
}
public function update($active=false) {
$info["isActive"] = ($active) ? 'TRUE' : 'FALSE';
if (!ldap_mod_replace($this->conn, "cn=".$this->getName().",".LDAP_BASE, $info)) {
$error = ldap_error($this->conn);
throw new Exception("Erreur pendant la modification du domaine : $error");
}
}
public function getName() {
return $this->domain;
}