Changeset 1014


Ignore:
Timestamp:
03/01/09 15:37:49 (3 years ago)
Author:
alexthero
Message:

Attachments of a page can now be downloaded as a ZIP file

Location:
trunk
Files:
1 added
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/www/controllers/attachment.php

    r997 r1014  
    55require_once(IA_ROOT_DIR."common/db/attachment.php"); 
    66require_once(IA_ROOT_DIR.'www/controllers/zip_attachment.php'); 
     7require_once(IA_ROOT_DIR."common/external_libs/zipfile.php"); 
    78 
    89// Try to get the textblock model for a certain page. 
     
    361362    } else { 
    362363        // redirect to main page 
    363         header("Location: " . url_absolute(url_home())); 
     364        redirect(url_absolute(url_home())); 
     365    } 
     366} 
     367 
     368function controller_attachment_downloadZip($page_name, $arguments) { 
     369    if(http_referer_check()) { 
     370        $files = array(); 
     371        foreach($arguments as $value) { 
     372            if(is_numeric($value)) $files[] = request($value); 
     373        } 
     374        $zipfile = new zipfile(); 
     375        foreach($files as $filename) { 
     376            $attach = try_attachment_get($page_name, $filename); 
     377            $contents = ""; 
     378            foreach(file(attachment_get_filepath($attach)) as $line) $contents .= $line; 
     379            $zipfile->add_file($contents, $filename); 
     380        } 
     381 
     382        header("Content-type: application/octet-stream"); 
     383        header("Content-disposition: attachment; filename=$page_name.zip"); 
     384        echo $zipfile->file(); 
     385    } else { 
     386        // redirect to main page 
     387        redirect(url_absolute(url_home())); 
    364388    } 
    365389} 
  • trunk/www/index.php

    r987 r1014  
    212212    } 
    213213} 
     214else if ($action == 'download-zip') { 
     215    require_once(IA_ROOT_DIR.'www/controllers/attachment.php'); 
     216    controller_attachment_downloadZip($page, request_args()); 
     217} 
    214218 
    215219// reset password 
  • trunk/www/utilities.php

    r997 r1014  
    77{ 
    88    return htmlentities($string, $quote_style, $charset); 
     9} 
     10 
     11// returns an array of all arguments in REQUEST 
     12function request_args() { 
     13    $result = array(); 
     14    foreach($_REQUEST as $key => $value) { 
     15        $result[] = $key; 
     16    } 
     17    return $result; 
    918} 
    1019 
  • trunk/www/views/listattach.php

    r997 r1014  
    33require_once(IA_ROOT_DIR . "www/format/table.php"); 
    44require_once(IA_ROOT_DIR . "www/format/format.php"); 
     5 
    56?> 
    67     
     
    4849} 
    4950 
     51function format_attach_zip($row) { 
     52    $attachurl = "<input type='checkbox' name='" . $row['id'] . "' value='" . $row['name'] . "'>"; 
     53 
     54    return $attachurl; 
     55} 
     56 
    5057function format_ip($row) { 
    5158    if ($row['remote_ip_info'] && identity_can('attach-view-ip', $row)) { 
     
    6976 
    7077$column_infos = array( 
     78    array ( 
     79        'title' => '', 
     80        'key' => 'zip', 
     81        'rowform' => 'format_attach_zip' 
     82    ), 
    7183    array( 
    7284        'title' => 'Numar', 
     
    105117); 
    106118?> 
    107  
     119    <form method = 'get' action = '' target = '_blank'>  
     120    <input type = 'hidden' name = 'action' value = 'download-zip'> 
    108121    <h1>Atasamente pentru pagina <?= format_link(url_textblock($view['page_name']), $view['page_name']) ?></h1> 
    109122    <?php 
     
    122135 
    123136    <p><?= format_link(url_attachment_new($page_name), 'Ataseaza un alt fisier') ?></p> 
    124  
     137    <?php 
     138        if($view['total_entries']) { 
     139    ?> 
     140    <p><input type="submit" value="Descarca ZIP" class="button"/></p> 
     141    <?php } ?> 
     142    </form> 
    125143<?php include('footer.php'); ?> 
Note: See TracChangeset for help on using the changeset viewer.