<?php

$error = 0;
$message = '';

if (isset($_POST['secret'])) {
    $secret = $_POST['secret'];
    $rc = ldap_mod_replace($ldap, $_SESSION['userdn'], array('seciossOtpInitSecret' => $secret));
    if (!$rc) {
        $error = 1;
        $log->crit(logformat("Setting secret failed: ". ldap_error($ldap)));
        $message = USS_ERR_102;
        $tplfile = 'secret.tpl';
    } else {
        $log->notice(logformat("Setting secret succeeded"));
        $message = USS_NML_101;
        $tplfile = 'secret.tpl';
    }
} else {
    $tplfile = 'secret.tpl';
}

$smarty = new Smarty();
$smarty->template_dir = 'templates';
$smarty->compile_dir = 'templates_c';

$smarty->assign('username', $_SESSION['username']);
$smarty->assign('error', $error);
$smarty->assign('message', $message);
$smarty->assign('uri', $_SERVER['SCRIPT_NAME'].'?app=secret');

$smarty->display($tplfile);
?>
