<?php
$result = run_query("SELECT record_table FROM " . $config["table_prefix"] . "module_asterisk_servers");
$row = sql_fetch_assoc($result);
$table_id = $row['record_table'];
if ($table_id) {
    $result = run_query("SELECT id FROM " . $config["table_prefix"] . "buttons WHERE table_id=" . $table_id . " and name='Выгрузка записи'");
    $row = sql_fetch_assoc($result);
    $button_id = $row['id'];
    if ($button_id) {
        $calculate = "\$sel = \$_REQUEST[''sel''] ? \$_REQUEST[''sel''] : array(\$line[''id'']);
if (count(\$sel)==1)
{
    \$fname = \$config[''site_path''].''/modules/asterisk/records/''.\$line[''ID''].''.mp3'';
    \$fsize = filesize(\$fname);
    if (\$fsize) header(''Content-Length: ''.\$fsize);
    header(''Content-Disposition: attachment; filename=\"''.\$line[''ID'']''.mp3\"'');
    header(''Content-type: audio/mpeg'');
    readfile(\$fname);
    exit;
}
else
{
    global \$my_rec_num, \$my_zip;
    \$my_rec_num++;
    if (\$my_rec_num==1)
    {
        \$my_zip = new ZipArchive;
        \$my_zip->open(\$config[''site_path''].''/temp/records.zip'', ZipArchive::CREATE);
    }
    \$my_zip->addFile(\$config[''site_path''].''/modules/asterisk/records/''.\$line[''ID''].''.mp3'', \$line[''ID''].''.mp3'');
    if (\$my_rec_num==count(\$sel))
    {
        \$my_zip->close();
        \$fname = \$config[''site_path''].''/temp/records.zip'';
        \$fsize = filesize(\$fname);
        if (\$fsize) header(''Content-Length: ''.\$fsize);
        header(''Content-Disposition: attachment; filename=\"records.zip\"'');
        header(''Content-type: application/zip'');
        readfile(\$fname);
        unlink(\$fname);
        exit;
    }
}";
        run_query("UPDATE " . $config["table_prefix"] . "calc SET calculate='" . $calculate . "' WHERE table_id=" . $table_id . " and name='Button $button_id'");
    }
}
?>