mirror of
https://github.com/ZeJMaN/LBCAlerte_ynh.git
synced 2025-07-06 03:40:48 +02:00
Initial commit
Functional, without SSO
This commit is contained in:
123
sources/app/user/scripts/settings.php
Normal file
123
sources/app/user/scripts/settings.php
Normal file
@ -0,0 +1,123 @@
|
||||
<?php
|
||||
|
||||
$params = array(
|
||||
"notification" => $userAuthed->getOption("notification"),
|
||||
"unique_ads" => $userAuthed->getOption("unique_ads", false)
|
||||
);
|
||||
if (!is_array($params["notification"])) {
|
||||
$params["notification"] = array();
|
||||
}
|
||||
$form_values["notification"] = array_replace_recursive(array(
|
||||
"freeMobile" => array(
|
||||
"user" => "",
|
||||
"key" => "",
|
||||
),
|
||||
"notifymyandroid" => array(
|
||||
"token" => "",
|
||||
),
|
||||
"pushbullet" => array(
|
||||
"token" => "",
|
||||
),
|
||||
"ovh" => array(
|
||||
"account" => "",
|
||||
"login" => "",
|
||||
"password" => "",
|
||||
"from" => "",
|
||||
"to" => "",
|
||||
),
|
||||
"pushover" => array(
|
||||
"token" => "",
|
||||
"user_key" => "",
|
||||
),
|
||||
), $params["notification"]);
|
||||
|
||||
$errors = array();
|
||||
$errorsTest = array();
|
||||
|
||||
if ($_SERVER["REQUEST_METHOD"] == "POST") {
|
||||
$params = array_merge($params, $_POST);
|
||||
|
||||
// test config Free Mobile
|
||||
foreach ($params["notification"] AS $section => $options) {
|
||||
if (is_array($options)) {
|
||||
$hasValue = false;
|
||||
foreach ($options AS $name => $value) {
|
||||
if (empty($value)) {
|
||||
$errors["notification"][$section][$name] = "Ce champ doit être renseigné.";
|
||||
} else {
|
||||
$hasValue = true;
|
||||
}
|
||||
}
|
||||
if (!$hasValue) {
|
||||
unset($errors["notification"][$section]);
|
||||
$params["notification"][$section] = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (empty($errors["notification"])) {
|
||||
unset($errors["notification"]);
|
||||
}
|
||||
|
||||
if (empty($errors)) {
|
||||
if (!empty($_POST["testFreeMobile"])) {
|
||||
$sms = \Message\AdapterFactory::factory("freeMobile", $params["notification"]["freeMobile"]);
|
||||
try {
|
||||
$sms->send("La notification SMS est fonctionnelle.");
|
||||
} catch (Exception $e) {
|
||||
$errorsTest["freeMobile"] = "Erreur lors de l'envoi du SMS : (".$e->getCode().") ".$e->getMessage();
|
||||
}
|
||||
} elseif (!empty($_POST["testPushbullet"])) {
|
||||
if (empty($_POST["notification"]["pushbullet"]["token"])) {
|
||||
$errors["notification"]["pushbullet"]["token"] = "Veuillez renseigner la clé d'identification. ";
|
||||
} else {
|
||||
$sender = \Message\AdapterFactory::factory("pushbullet", $_POST["notification"]["pushbullet"]);
|
||||
try {
|
||||
$sender->send("La notification Pushbullet est fonctionnelle");
|
||||
} catch (Exception $e) {
|
||||
$errorsTest["pushbullet"] = "Erreur lors de l'envoi de la notification : (".$e->getCode().") ".$e->getMessage();
|
||||
}
|
||||
}
|
||||
} elseif (!empty($_POST["testOvh"])) {
|
||||
$sender = \Message\AdapterFactory::factory("SmsOvh", $params["notification"]["ovh"]);
|
||||
try {
|
||||
$sender->send("La notification SMS est fonctionnelle.");
|
||||
} catch (Exception $e) {
|
||||
$errorsTest["ovh"] = "Erreur lors de l'envoi du SMS : (".$e->getCode().") ".$e->getMessage();
|
||||
}
|
||||
} elseif (!empty($_POST["testNotifyMyAndroid"])) {
|
||||
if (empty($_POST["notification"]["notifymyandroid"]["token"])) {
|
||||
$errors["notification"]["notifymyandroid"]["token"] = "Veuillez renseigner la clé d'identification.";
|
||||
} else {
|
||||
$sender = \Message\AdapterFactory::factory("notifymyandroid", $_POST["notification"]["notifymyandroid"]);
|
||||
try {
|
||||
$sender->send("La notification NotifyMyAndroid est fonctionnelle", array(
|
||||
"title" => "Test alerte"
|
||||
));
|
||||
} catch (Exception $e) {
|
||||
$errorsTest["notifymyandroid"] = "Erreur lors de l'envoi de la notification : (".$e->getCode().") ".$e->getMessage();
|
||||
}
|
||||
}
|
||||
} elseif (!empty($_POST["testPushover"])) {
|
||||
if (empty($_POST["notification"]["pushover"]["token"])) {
|
||||
$errors["notification"]["pushover"]["token"] = "Veuillez renseigner la clé application.";
|
||||
} elseif (empty($_POST["notification"]["pushover"]["user_key"])) {
|
||||
$errors["notification"]["pushover"]["user_key"] = "Veuillez renseigner la clé utilisateur.";
|
||||
} else {
|
||||
$sender = \Message\AdapterFactory::factory("pushover", $_POST["notification"]["pushover"]);
|
||||
try {
|
||||
$sender->send("La notification Pushover est fonctionnelle");
|
||||
} catch (Exception $e) {
|
||||
$errorsTest["pushover"] = "Erreur lors de l'envoi de la notification : (".$e->getCode().") ".$e->getMessage();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$userAuthed->mergeOptions($params);
|
||||
$userStorage->save($userAuthed);
|
||||
$_SESSION["userSettingsSaved"] = true;
|
||||
header("LOCATION: ./?mod=user&a=settings"); exit;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$userSettingsSaved = isset($_SESSION["userSettingsSaved"]) && true === $_SESSION["userSettingsSaved"];
|
||||
unset($_SESSION["userSettingsSaved"]);
|
250
sources/app/user/views/settings.phtml
Normal file
250
sources/app/user/views/settings.phtml
Normal file
@ -0,0 +1,250 @@
|
||||
<form action="" method="post" autocomplete="off">
|
||||
<?php if (!empty($errors)) : ?>
|
||||
<p class="error" style="font-size: 1.3em; background: #AB0000; color: #FFF; text-align: center; line-height: 200%;">
|
||||
Il y a au moins une erreur présente dans le formulaire.</p>
|
||||
<?php elseif (!empty($errorsTest)) : ?>
|
||||
<p class="error" style="font-size: 1.3em; background: #AB0000; color: #FFF; text-align: center; line-height: 200%;">
|
||||
Le test d'envoi a échoué. Voir ci-dessous pour le message d'erreur.</p>
|
||||
<?php elseif ($userSettingsSaved) : ?>
|
||||
<p style="font-size: 1.3em; background: #00AB00; color: #FFF; text-align: center; line-height: 200%;">
|
||||
Les paramètres ont été enregistrés.</p>
|
||||
<?php endif;?>
|
||||
|
||||
<h2>Options générales</h2>
|
||||
<dl>
|
||||
<dt style="margin-bottom: 10px;">
|
||||
<input type="hidden" name="unique_ads" value="0" />
|
||||
<label for="unique_ads">
|
||||
<input type="checkbox" id="unique_ads" name="unique_ads" value="1"<?php
|
||||
echo $params["unique_ads"] ?' checked="checked"':''
|
||||
?> style="margin-left: 0;" />
|
||||
Cochez la case pour ne pas recevoir les annonces remontées (évite les doublons).
|
||||
</label>
|
||||
</dt>
|
||||
</dl>
|
||||
|
||||
<h2 id="configFreeMobile" class="formbox">Configuration SMS via Free Mobile</h2>
|
||||
<dl id="configFreeMobile-content" style="display: <?php echo !empty($form_values["notification"]["freeMobile"]["user"]) ? "block" : "none"; ?>;">
|
||||
<dt>
|
||||
<label for="free_mobile_user">ID utilisateur</label>
|
||||
</dt>
|
||||
<dd>
|
||||
<input type="text" id="free_mobile_user" name="notification[freeMobile][user]" value="<?php
|
||||
echo htmlspecialchars($form_values["notification"]["freeMobile"]["user"]);
|
||||
?>" />
|
||||
<?php if (isset($errors["notification"]["freeMobile"]["user"])) : ?>
|
||||
<p class="error"><?php echo $errors["notification"]["freeMobile"]["user"]; ?></p>
|
||||
<?php endif; ?>
|
||||
</dd>
|
||||
<dt>
|
||||
<label for="free_mobile_key">Clé d'identification</label>
|
||||
</dt>
|
||||
<dd>
|
||||
<input type="text" id="free_mobile_key" name="notification[freeMobile][key]" value="<?php
|
||||
echo htmlspecialchars($form_values["notification"]["freeMobile"]["key"]);
|
||||
?>" />
|
||||
<?php if (isset($errors["notification"]["freeMobile"]["key"])) : ?>
|
||||
<p class="error"><?php echo $errors["notification"]["freeMobile"]["key"]; ?></p>
|
||||
<?php endif; ?>
|
||||
</dd>
|
||||
<dt style="border: none;">
|
||||
<input type="submit" name="testFreeMobile" value="Effectuer un test d'envoi SMS" />
|
||||
</dt>
|
||||
<?php if (empty($errors) && !empty($_POST["testFreeMobile"])) : ?>
|
||||
<dd>
|
||||
<?php if (isset($errorsTest["freeMobile"])) : ?>
|
||||
<p style="font-weight: bold; color: #AB0000;"><?php
|
||||
echo htmlspecialchars($errorsTest["freeMobile"]);
|
||||
?></p>
|
||||
<?php else: ?>
|
||||
<p style="font-weight: bold; color: #333399;">Vous devriez recevoir un SMS contenant le message suivant:
|
||||
« La notification SMS est fonctionnelle ».</p>
|
||||
<p style="font-weight: bold; color: #339933;">Pensez à confirmer la configuration en cliquant sur "Enregistrer".</p>
|
||||
<?php endif; ?>
|
||||
</dd>
|
||||
<?php endif; ?>
|
||||
</dl>
|
||||
|
||||
<h2 id="configPushbullet" class="formbox">Configuration alerte via Pushbullet</h2>
|
||||
<dl id="configPushbullet-content" style="display: <?php echo !empty($form_values["notification"]["pushbullet"]["token"]) ? "block" : "none"; ?>;">
|
||||
<dt>
|
||||
<label for="pushbullet_token">Clé du service</label>
|
||||
</dt>
|
||||
<dd>
|
||||
<input type="text" id="pushbullet_token" name="notification[pushbullet][token]" value="<?php
|
||||
echo htmlspecialchars($form_values["notification"]["pushbullet"]["token"]);
|
||||
?>" />
|
||||
<?php if (isset($errors["notification"]["pushbullet"]["token"])) : ?>
|
||||
<p class="error"><?php echo $errors["notification"]["pushbullet"]["token"]; ?></p>
|
||||
<?php endif; ?>
|
||||
</dd>
|
||||
<dt style="border: none;">
|
||||
<input type="submit" name="testPushbullet" value="Effectuer un test d'envoi de message" />
|
||||
</dt>
|
||||
<?php if (empty($errors) && !empty($_POST["testPushbullet"])) : ?>
|
||||
<dd>
|
||||
<?php if (isset($errorsTest["pushbullet"])) : ?>
|
||||
<p style="font-weight: bold; color: #AB0000;"><?php
|
||||
echo htmlspecialchars($errorsTest["pushbullet"]);
|
||||
?></p>
|
||||
<?php else: ?>
|
||||
<p style="font-weight: bold; color: #333399;">Vous devriez recevoir une notification contenant le message suivant:
|
||||
« La notification Pushbullet est fonctionnelle ».</p>
|
||||
<p style="font-weight: bold; color: #339933;">Pensez à confirmer la configuration en cliquant sur "Enregistrer".</p>
|
||||
<?php endif; ?>
|
||||
</dd>
|
||||
<?php endif; ?>
|
||||
</dl>
|
||||
|
||||
<h2 id="configOvh" class="formbox">Configuration SMS via OVH Telecom</h2>
|
||||
<dl id="configOvh-content" style="display: <?php echo !empty($form_values["notification"]["ovh"]["account"]) ? "block" : "none"; ?>;">
|
||||
<dt>
|
||||
<label for="ovh_account">Numéro de compte</label>
|
||||
</dt>
|
||||
<dd>
|
||||
<input type="text" id="ovh_account" name="notification[ovh][account]" value="<?php
|
||||
echo htmlspecialchars($form_values["notification"]["ovh"]["account"]);
|
||||
?>" placeholder="De la forme : sms-xxxxxxxx-x" />
|
||||
<?php if (isset($errors["notification"]["ovh"]["account"])) : ?>
|
||||
<p class="error"><?php echo $errors["notification"]["ovh"]["account"]; ?></p>
|
||||
<?php endif; ?>
|
||||
</dd>
|
||||
<dt>
|
||||
<label for="ovh_login">Utilisateur</label>
|
||||
</dt>
|
||||
<dd>
|
||||
<input type="text" id="ovh_login" name="notification[ovh][login]" value="<?php
|
||||
echo htmlspecialchars($form_values["notification"]["ovh"]["login"]);
|
||||
?>" />
|
||||
<?php if (isset($errors["notification"]["ovh"]["login"])) : ?>
|
||||
<p class="error"><?php echo $errors["notification"]["ovh"]["login"]; ?></p>
|
||||
<?php endif; ?>
|
||||
</dd>
|
||||
<dt>
|
||||
<label for="ovh_password">Mot de passe</label>
|
||||
</dt>
|
||||
<dd>
|
||||
<input type="text" id="ovh_password" name="notification[ovh][password]" value="<?php
|
||||
echo htmlspecialchars($form_values["notification"]["ovh"]["password"]);
|
||||
?>" />
|
||||
<?php if (isset($errors["notification"]["ovh"]["password"])) : ?>
|
||||
<p class="error"><?php echo $errors["notification"]["ovh"]["password"]; ?></p>
|
||||
<?php endif; ?>
|
||||
</dd>
|
||||
<dt>
|
||||
<label for="ovh_from">Expéditeur</label>
|
||||
</dt>
|
||||
<dd>
|
||||
<input type="text" id="ovh_from" name="notification[ovh][from]" value="<?php
|
||||
echo htmlspecialchars($form_values["notification"]["ovh"]["from"]);
|
||||
?>" />
|
||||
<?php if (isset($errors["notification"]["ovh"]["from"])) : ?>
|
||||
<p class="error"><?php echo $errors["notification"]["ovh"]["from"]; ?></p>
|
||||
<?php endif; ?>
|
||||
</dd>
|
||||
<dt>
|
||||
<label for="ovh_to">Destinataire</label>
|
||||
</dt>
|
||||
<dd>
|
||||
<input type="text" id="ovh_to" name="notification[ovh][to]" value="<?php
|
||||
echo htmlspecialchars($form_values["notification"]["ovh"]["to"]);
|
||||
?>" placeholder="Forme international (Ex: +33605040301)" />
|
||||
<?php if (isset($errors["notification"]["ovh"]["to"])) : ?>
|
||||
<p class="error"><?php echo $errors["notification"]["ovh"]["to"]; ?></p>
|
||||
<?php endif; ?>
|
||||
</dd>
|
||||
|
||||
<dt style="border: none;">
|
||||
<input type="submit" name="testOvh" value="Effectuer un test d'envoi SMS" />
|
||||
</dt>
|
||||
<?php if (empty($errors) && !empty($_POST["testOvh"])) : ?>
|
||||
<dd>
|
||||
<?php if (isset($errorsTest["ovh"])) : ?>
|
||||
<p style="font-weight: bold; color: #AB0000;"><?php
|
||||
echo htmlspecialchars($errorsTest["ovh"]);
|
||||
?></p>
|
||||
<?php else: ?>
|
||||
<p style="font-weight: bold; color: #333399;">Vous devriez recevoir un SMS contenant le message suivant:
|
||||
« La notification SMS est fonctionnelle ».</p>
|
||||
<p style="font-weight: bold; color: #339933;">Pensez à confirmer la configuration en cliquant sur "Enregistrer".</p>
|
||||
<?php endif; ?>
|
||||
</dd>
|
||||
<?php endif; ?>
|
||||
</dl>
|
||||
|
||||
<h2 id="configNotifyMyAndroid" class="formbox">Configuration alerte via NotifyMyAndroid</h2>
|
||||
<dl id="configNotifyMyAndroid-content" style="display: <?php echo !empty($form_values["notification"]["notifymyandroid"]["token"]) ? "block" : "none"; ?>;">
|
||||
<dt>
|
||||
<label for="notifymyandroid_token">Clé du service</label>
|
||||
</dt>
|
||||
<dd>
|
||||
<input type="text" id="notifymyandroid_token" name="notification[notifymyandroid][token]" value="<?php
|
||||
echo htmlspecialchars($form_values["notification"]["notifymyandroid"]["token"]);
|
||||
?>" />
|
||||
<?php if (isset($errors["notification"]["notifymyandroid"]["token"])) : ?>
|
||||
<p class="error"><?php echo $errors["notification"]["notifymyandroid"]["token"]; ?></p>
|
||||
<?php endif; ?>
|
||||
</dd>
|
||||
<dt style="border: none;">
|
||||
<input type="submit" name="testNotifyMyAndroid" value="Effectuer un test d'envoi de message" />
|
||||
</dt>
|
||||
<?php if (empty($errors) && !empty($_POST["testNotifyMyAndroid"])) : ?>
|
||||
<dd>
|
||||
<?php if (isset($errorsTest["notifymyandroid"])) : ?>
|
||||
<p style="font-weight: bold; color: #AB0000;"><?php
|
||||
echo htmlspecialchars($errorsTest["notifymyandroid"]);
|
||||
?></p>
|
||||
<?php else: ?>
|
||||
<p style="font-weight: bold; color: #333399;">Vous devriez recevoir une notification contenant le message suivant:
|
||||
« La notification NotifyMyAndroid est fonctionnelle ».</p>
|
||||
<p style="font-weight: bold; color: #339933;">Pensez à confirmer la configuration en cliquant sur "Enregistrer".</p>
|
||||
<?php endif; ?>
|
||||
</dd>
|
||||
<?php endif; ?>
|
||||
</dl>
|
||||
|
||||
<h2 id="configPushover" class="formbox">Configuration alerte via Pushover</h2>
|
||||
<dl id="configPushover-content" style="display: <?php echo !empty($form_values["notification"]["pushover"]["token"]) ? "block" : "none"; ?>;">
|
||||
<dt>
|
||||
<label for="pushover_token">Clé application</label>
|
||||
</dt>
|
||||
<dd>
|
||||
<input type="text" id="pushover_token" name="notification[pushover][token]" value="<?php
|
||||
echo htmlspecialchars($form_values["notification"]["pushover"]["token"]);
|
||||
?>" />
|
||||
<?php if (isset($errors["notification"]["pushover"]["token"])) : ?>
|
||||
<p class="error"><?php echo $errors["notification"]["pushover"]["token"]; ?></p>
|
||||
<?php endif; ?>
|
||||
</dd>
|
||||
<dt>
|
||||
<label for="pushover_token">Clé utilisateur</label>
|
||||
</dt>
|
||||
<dd>
|
||||
<input type="text" id="pushover_token" name="notification[pushover][user_key]" value="<?php
|
||||
echo htmlspecialchars($form_values["notification"]["pushover"]["user_key"]);
|
||||
?>" />
|
||||
<?php if (isset($errors["notification"]["pushover"]["user_key"])) : ?>
|
||||
<p class="error"><?php echo $errors["notification"]["pushover"]["user_key"]; ?></p>
|
||||
<?php endif; ?>
|
||||
</dd>
|
||||
<dt style="border: none;">
|
||||
<input type="submit" name="testPushover" value="Effectuer un test d'envoi de message" />
|
||||
</dt>
|
||||
<?php if (empty($errors) && !empty($_POST["testPushover"])) : ?>
|
||||
<dd>
|
||||
<?php if (isset($errorsTest["pushover"])) : ?>
|
||||
<p style="font-weight: bold; color: #AB0000;"><?php
|
||||
echo htmlspecialchars($errorsTest["pushover"]);
|
||||
?></p>
|
||||
<?php else: ?>
|
||||
<p style="font-weight: bold; color: #333399;">Vous devriez recevoir une notification contenant le message suivant:
|
||||
« La notification Pushover est fonctionnelle ».</p>
|
||||
<p style="font-weight: bold; color: #339933;">Pensez à confirmer la configuration en cliquant sur "Enregistrer".</p>
|
||||
<?php endif; ?>
|
||||
</dd>
|
||||
<?php endif; ?>
|
||||
</dl>
|
||||
|
||||
<p><input type="submit" value="Enregistrer" />
|
||||
| <a href="?mod=user&a=settings">annuler les modifications</a></p>
|
||||
</form>
|
Reference in New Issue
Block a user