<?php
admin_externalpage_print_header();

$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';

$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->id != $CFG->mnet_all_hosts_id && $mnet_peer->application->name == 'moodle') {
    $tabs[] = new tabobject('mnetlog', $logurl, $strmnetlog, $strmnetlog, false);
}
print_tabs(array($tabs), 'mnetservices');
print_simple_box_start("center", "");

?>

<form method="post" action="mnet_services.php">
<div>
<input type="hidden" name="sesskey" value="<?php echo $USER->sesskey ?>" />
<input type="hidden" name="step" value="<?php echo $mnet_peer->nextstep; ?>" />
<input type="hidden" name="hostid" value="<?php echo ($mnet_peer->id)?  $mnet_peer->id : '0' ; ?>" />
<table cellpadding="9" cellspacing="0" >
<?php 
    foreach($myservices as $name => $versions) {
    $version = current($versions);
?>
<tr>
    <td align="left" valign="top" colspan="2">
    <h3><?php echo get_string($name.'_name', $version['parent_type'].'_'.$version['parent'] , $mnet_peer->name); ?></h3>
    <?php echo get_string($name.'_description', $version['parent_type'].'_'.$version['parent'], $mnet_peer->name); ?>
<?php
        $breakstring = '';
        foreach($versions as $version){
            if (count($versions) > 1) {
                $versionstring = '('.get_string('version','mnet') .' '.$version['apiversion'].')';
            } else {
                $versionstring = '';
            }
    
            echo $breakstring;
?>
    <input type="hidden" name="exists[<?php echo  $version['serviceid']; ?>]" value="1" />
    <input type="checkbox" name="publish[<?php echo $version['serviceid']; ?>]" <?php echo (!empty($version['I_publish']))? 'checked="checked" ': '' ; ?>/>
<?php 
            print_string('publish','mnet');
            echo $versionstring; 
            if (!empty($version['hostsubscribes'])) { 
                echo '<a href="#" title="'.get_string('issubscribed','mnet', $mnet_peer->name).'">&radic;</a> '; 
            }
            if (!empty($version['allhosts_publish'])) { 
                print_string("enabled_for_all",'mnet',!empty($version['I_publish']));
            } 
            echo '<br />';
?>
    <input type="checkbox" name="subscribe[<?php echo $version['serviceid']; ?>]" <?php echo (!empty($version['I_subscribe']))? 'checked="checked" ': '' ; ?>/>
<?php 
            print_string('subscribe','mnet');
            echo $versionstring; 
            if (!empty($version['hostpublishes'])) { 
                echo '<a href="#" title="'.get_string('ispublished','mnet', $mnet_peer->name).'">&radic;</a> ';
            } 
            if (!empty($version['allhosts_subscribe'])) {
                print_string("enabled_for_all",'mnet',!empty($version['I_subscribe']));
            }
            
            echo '<br />';  
            $breakstring = '. . . . . . . . . . . . . . . . . . . . . . . . <br>';
        } // end foreach
?>
    </td>
</tr>
<?php
    } // end foreach
?>
<tr>
    <td align="left" valign="top" colspan="2">
    <div id="pubTreeLoc"></div>
    </td>
</tr>
<tr>
    <td align="left" valign="top" colspan="2">
    <div id="subTreeLoc"></div>
    </td>
</tr>
<tr>
    <td colspan="2"><input type="submit" value="<?php print_string("savechanges") ?>" /></td>
</tr>
<tr>
    <td align="left" valign="top" colspan="2">
    <div id="formElements"><input type="hidden" name="outer" value="4" /></div>
    </td>
</tr>
</table>
</div>
</form>
<?php
print_simple_box_end();
admin_externalpage_print_footer();
?>
