Skip to content

Commit

Permalink
New feature: list and download old 2.x survey templates
Browse files Browse the repository at this point in the history
  • Loading branch information
LouisGac committed May 18, 2018
1 parent a36f9ce commit a0d900d
Show file tree
Hide file tree
Showing 3 changed files with 105 additions and 0 deletions.
44 changes: 44 additions & 0 deletions application/controllers/admin/themes.php
Expand Up @@ -75,6 +75,50 @@ public function templatezip($templatename)
}
}


/**
* Exports a deprecated template
*
* @access public
* @param string $templatename
* @return void
*/
public function deprecatedtemplatezip($templatename)
{
//$oEditedTemplate = Template::model()->getTemplateConfiguration($templatename);
$templatename = sanitize_dirname($templatename);
$usertemplaterootdir = Yii::app()->getConfig("uploaddir").DIRECTORY_SEPARATOR."templates";
$templatePath = $usertemplaterootdir.DIRECTORY_SEPARATOR.$templatename;


if (!Permission::model()->hasGlobalPermission('templates','export')){
die('No permission');
}

$tempdir = Yii::app()->getConfig('tempdir');

$zipfile = "$tempdir/$templatename.zip";
Yii::app()->loadLibrary('admin.pclzip');
$zip = new PclZip($zipfile);
$zip->create($templatePath, PCLZIP_OPT_REMOVE_PATH, $templatePath);

if (is_file($zipfile)) {
// Send the file for download!
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Content-Type: application/force-download");
header("Content-Disposition: attachment; filename=$templatename.zip");
header("Content-Description: File Transfer");

@readfile($zipfile);

// Delete the temporary file
unlink($zipfile);
}
}


/**
* Retrieves a temporary template file from disk
*
Expand Down
22 changes: 22 additions & 0 deletions application/models/Template.php
Expand Up @@ -630,6 +630,28 @@ public function search()
));
}

/**
* Retrieves a list of deprecated templates (the templates in upload/templates/)
*/
static public function getDeprecatedTemplates()
{
$usertemplaterootdir = Yii::app()->getConfig("uploaddir").DIRECTORY_SEPARATOR."templates";
$aTemplateList = array();

if ( (is_dir($usertemplaterootdir)) && $usertemplaterootdir && $handle = opendir($usertemplaterootdir)){
while (false !== ($file = readdir($handle))){
if (!is_file("$usertemplaterootdir/$file") && $file != "." && $file != ".." && $file!=".svn"){
$aTemplateList[$file]['directory'] = $usertemplaterootdir.DIRECTORY_SEPARATOR.$file;
$aTemplateList[$file]['name'] = $file;
}
}
closedir($handle);
}
ksort($aTemplateList);

return $aTemplateList;
}

/**
* Returns the static model of the specified AR class.
* Please note that you should have this exact method in all your CActiveRecord descendants!
Expand Down
39 changes: 39 additions & 0 deletions application/views/admin/themeoptions/index.php
Expand Up @@ -68,6 +68,45 @@
</div>
</div>
<?php endif;?>

<!-- Deprecated Themes -->
<?php $aDeprecatedThemes = Template::getDeprecatedTemplates(); ?>
<?php if (count( $aDeprecatedThemes ) > 0 ):?>
<h3><?php eT('Deprecated survey themes:'); ?></h3>
<div class="row">
<div class="col-sm-12 content-right">
<div id="deprecatedThemes" class="grid-view">
<table class="items table">
<thead>
<tr>
<th><?php eT('Name'); ?></th>
<th><?php eT('Export'); ?></th>
</tr>
</thead>

<tbody>
<?php foreach ($aDeprecatedThemes as $aDeprecatedTheme):?>
<tr class="odd">
<td class="col-md-10"><?php echo $aDeprecatedTheme['name']; ?></td>
<td class="col-md-2">
<?php if(Permission::model()->hasGlobalPermission('templates','export') && function_exists("zip_open")):?>
<a class="btn btn-default" id="button-export" href="<?php echo $this->createUrl('admin/themes/sa/deprecatedtemplatezip/templatename/' . $aDeprecatedTheme['name']) ?>" role="button">
<span class="icon-export text-success"></span>
<?php eT("Export"); ?>
</a>
<?php endif;?>
</td>
</tr>

<?php endforeach;?>
</tbody>
</table>
</div>
</div>
</div>
<?php endif;?>


</div>
</div>
<div id="adminthemes" class="tab-pane">
Expand Down

0 comments on commit a0d900d

Please sign in to comment.