Skip to content

Commit

Permalink
5509 created filter to sort modules available to install from remote,…
Browse files Browse the repository at this point in the history
… default to module for the current version
  • Loading branch information
atutorlangs committed Aug 21, 2014
1 parent b7decb7 commit 640dd8e
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 16 deletions.
23 changes: 23 additions & 0 deletions mods/_core/modules/install_modules.php
Expand Up @@ -236,6 +236,7 @@ function validate_filename() {
</script>

<?php

// Create a list of install modules
$installed_mods = array();
$sql = "SELECT dir_name FROM %smodules";
Expand All @@ -248,10 +249,32 @@ function validate_filename() {
foreach ($module_list_array as $key => $row) {
$version[$key] = $row['atutor_version'];
}
$sort_versions = array_unique($version, SORT_REGULAR);
rsort($sort_versions);

// Add $module_list_array as the last parameter, to sort by the common key
// Sorts by original $module_list_array by reference, then returns true|false
$sort_by_version = array_multisort($version, SORT_DESC, $module_list_array);

// Create menu for filter ATutor versions
function select_atversion(){
global $sort_versions;
$menu = '<form action="'.$_SERVER['PHP_SELF'].'" method="post">';
$menu.= '<select name="atversions">';
$menu.= '<option value="0">'._AT("all").'</option>';
foreach($sort_versions as $version){
if($version == VERSION){
$menu .= '<option value="'.$version.'" selected="selected">'.$version.'</option>';
}else{
$menu .= '<option value="'.$version.'" >'.$version.'</option>';
}
}
$menu .='</select>';
$menu .='<input type="submit" value="'. _AT('filter').'"/></form>';
return $menu;
}

$savant->assign('atversions', select_atversion());
$savant->assign('enable_upload', $enable_upload);
$savant->assign('enable_remote_installation', $enable_remote_installtion);
$savant->assign('keys', $keys);
Expand Down
38 changes: 22 additions & 16 deletions themes/default/admin/modules/install_modules.tmpl.php
@@ -1,6 +1,4 @@
<?php
global $db;

if ($this->enable_upload) {
?>
<form name="frm_upload" enctype="multipart/form-data" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>" >
Expand Down Expand Up @@ -78,11 +76,16 @@
// Disallow subsites to download and install the remote modules from update.atutor.ca
if ($this->enable_remote_installation === true) {
?>


<fieldset>
<legend><?php echo _AT('filter'); ?></legend>
<div class="input-form">
<div class="row">
<?php echo _AT('old_module_notes'); ?>
</div>
<?php echo select_atversion(); ?>
</div>
</fieldset>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" name="form">
<?php
?>
<table class="data" summary="">
<thead>
<tr>
Expand Down Expand Up @@ -128,21 +131,24 @@
for ($i=0; $i < $num_of_modules; $i++)
{
$installed = false;
if(in_array($this->module_list_array[$i]["history"][0]["install_folder"], $this->installed_mods)){
if(in_array($this->module_list_array[$i]["history"][0]["install_folder"], '')){
$installed = true;
}

if((isset($_POST['atversions']) && $_POST['atversions'] == $this->module_list_array[$i]["atutor_version"]) || $_POST['atversions'] == 0){
?>
<tr onmousedown="document.form['m<?php echo $i; ?>'].checked = true; rowselect(this);" id="r_<?php echo $i; ?>">
<td><input type="radio" name="id" value="<?php echo $i; ?>" id="m<?php echo $i; ?>" <?php if ($installed) echo 'disabled="disabled"'; ?> /></td>
<td><label for="m<?php echo $i; ?>"><?php echo $this->module_list_array[$i]["name"]; ?></label></td>
<td><?php echo $this->module_list_array[$i]["description"]; ?></td>
<td><?php echo $this->module_list_array[$i]["history"][0]["version"]; ?></td>
<td><?php echo $this->module_list_array[$i]["atutor_version"]; ?></td>
<td><?php echo $this->module_list_array[$i]["history"][0]["maintainer"]; ?></td>
<td><?php if ($installed) echo _AT("installed"); else echo _AT("not_installed"); ?></td>
</tr>
<tr onmousedown="document.form['m<?php echo $i; ?>'].checked = true; rowselect(this);" id="r_<?php echo $i; ?>">
<td><input type="radio" name="id" value="<?php echo $i; ?>" id="m<?php echo $i; ?>" <?php if ($installed) echo 'disabled="disabled"'; ?> /></td>
<td><label for="m<?php echo $i; ?>"><?php echo $this->module_list_array[$i]["name"]; ?></label></td>
<td style="width:45%;"><?php echo $this->module_list_array[$i]["description"]; ?></td>
<td><?php echo $this->module_list_array[$i]["history"][0]["version"]; ?></td>
<td><?php echo $this->module_list_array[$i]["atutor_version"]; ?></td>
<td><?php echo $this->module_list_array[$i]["history"][0]["maintainer"]; ?></td>
<td><?php if ($installed) echo _AT("installed"); else echo _AT("not_installed"); ?></td>
</tr>

<?php
} // end if
}
}

Expand Down

0 comments on commit 640dd8e

Please sign in to comment.