<?php
$logurl = $CFG->wwwroot.
          '/course/report/log/index.php?chooselog=1&amp;showusers=1&amp;showcourses=1&amp;host_course='.$mnet_peer->id.
          '%2F1&amp;user='.'0'.
          '&amp;date=0'.
          '&amp;modid=&amp;modaction=0&amp;logformat=showashtml';

admin_externalpage_print_header();

if (isset($mnet_peer->id) && $mnet_peer->id > 0) {
    $tabs[] = new tabobject('mnetdetails', 'peers.php?step=update&amp;hostid='.$mnet_peer->id, $strmnetedithost, $strmnetedithost, false);
    $tabs[] = new tabobject('mnetservices', 'mnet_services.php?step=list&amp;hostid='.$mnet_peer->id, $strmnetservices, $strmnetservices, false);
    $tabs[] = new tabobject('mnetthemes', 'mnet_themes.php?step=list&amp;hostid='.$mnet_peer->id, $strmnetthemes, $strmnetthemes, false);
    if ($mnet_peer->application->name == 'moodle') {
        $tabs[] = new tabobject('mnetlog', $logurl, $strmnetlog, $strmnetlog, false);
    }
} else {
    $tabs[] = new tabobject('mnetdetails', '#', $strmnetedithost, $strmnetedithost, false);
}
print_tabs(array($tabs), 'mnetdetails');

print_simple_box_start("center", "");
?>
<form method="post" action="peers.php">
<div>
<input type="hidden" name="sesskey" value="<?php echo $USER->sesskey ?>" />
<input type="hidden" name="step" value="commit" />
<input type="hidden" name="last_connect_time" value="<?php echo $mnet_peer->last_connect_time; ?>" />
<input type="hidden" name="id" value="<?php echo isset($mnet_peer->id)?  $mnet_peer->id : '0' ; ?>" />
<input type="hidden" name="applicationid" value="<?php echo isset($mnet_peer->applicationid)?  $mnet_peer->applicationid : '0' ; ?>" />
<input type="hidden" name="applicationname" value="<?php echo isset($mnet_peer->application->name)?  $mnet_peer->application->name : '' ; ?>" />
<table cellpadding="9" cellspacing="0" width="635">

<tr>
    <td align="right" valign="top"><?php print_string('site'); ?>:</td>
    <td valign="top"><input type="text" name="name" size="30" value="<?php echo $mnet_peer->name; ?>" /></td>
</tr>
<tr>
    <td align="right" valign="top"><?php print_string('hostname', 'mnet'); ?>:</td>
    <td valign="top"><input type="text" name="wwwroot" size="30" value="<?php echo $mnet_peer->wwwroot; ?>" /></td>
</tr>
<?php
if (empty($mnet_peer->public_key)) $mnet_peer->public_key = '';
?>
<tr>
    <td align="right" valign="top"><?php
        print_string('publickey', 'mnet');
        echo ': <br />';
        helpbutton("publickey", get_string('publickey', 'mnet'), "mnet", true, true);
    ?></td>
<?php



if (isset($mnet_peer->deleted) && $mnet_peer->deleted > 0) {
    $key = mnet_get_public_key($mnet_peer->wwwroot, $mnet_peer->application->xmlrpc_server_url);
    $mnet_peer->public_key = clean_param($key, PARAM_PEM);
}
?>
    <td valign="top">
        <?php 
        if (empty($mnet_peer->public_key)) {
            print_string('nopubkey', 'mnet');
        }
        ?><br />
        <textarea rows="17" cols="65" name="public_key" style="font-size: 8px;"><?php echo $mnet_peer->public_key; ?></textarea>
    </td>
</tr>
<tr>
    <td align="right" valign="top"><?php print_string('expires', 'mnet'); ?>:</td>
    <td valign="top">
<?php
    if($mnet_peer->public_key_expires < time()) {
        print_string('expired', 'mnet');
        echo ' ';
    }
    echo userdate($mnet_peer->public_key_expires);
?>
    </td>
</tr>
<?php

if(!empty($currentkey)) {
?>
    <tr>
        <td align="right" valign="top"></td>
        <td valign="top"><?php print_string('keymismatch', 'mnet'); ?></td>
    </tr>
    <tr>
        <td align="right" valign="top"><?php print_string('currentkey', 'mnet'); ?>:</td>
        <td valign="top"><pre style="font-size: 8px;"><?php echo $currentkey;?></pre></td>
    </tr>
<?php
}

if (isset($mnet_peer->id) && $mnet_peer->id > 0) {
?>
    <tr>
        <td align="right" valign="top"><?php print_string('last_connect_time', 'mnet'); ?>:</td>
        <td valign="top"><?php echo ($mnet_peer->last_connect_time == 0)? get_string('never','mnet') : date('H:i:s d/m/Y',$mnet_peer->last_connect_time);?></td>
    </tr>
<?php
}

if (isset($mnet_peer->deleted) && $mnet_peer->deleted > 0){
?>
    <tr>
        <td align="right" valign="top"><?php print_string('deleted'); ?>:</td>
        <td valign="top">
            <input type="radio" name="deleted" value="0" checked="checked" /> <?php print_string('reenableserver','mnet'); ?><br />
            <input type="radio" name="deleted" value="1"  /> <?php print_string('yes'); ?><br />
        </td>
    </tr>
<?php
}

if (isset($mnet_peer->ip_address) && '' != $mnet_peer->ip_address){
?>
    <tr>
        <td align="right" valign="top"><?php print_string('ipaddress', 'mnet');
        echo ': <br />';
        helpbutton("ipaddress", get_string('ipaddress', 'mnet'), "mnet", true, true);
        ?>:</td>
        <td valign="top"><?php echo $mnet_peer->ip_address; ?></td>
    </tr>

<?php
}
?>
<tr>
    <td></td>
    <td><input type="submit" value="<?php print_string("savechanges"); ?>" /></td>
</tr>
</table>
</div>
</form>
<?php
print_simple_box_end();
admin_externalpage_print_footer();
?>
