query($sql1) or die('Erreur SQL !
'.$sql1.'
'.$mysqli->error); $c = $req1->fetch_assoc(); if(!$c) { die('Wrong id'); } function cleanString($string) { $string = str_replace('Æ','ae', $string); $string = str_replace('æ','ae', $string); $string = str_replace('œ','oe', $string); setlocale(LC_ALL, "en_US.utf8"); $string = iconv("utf-8", "ascii//TRANSLIT", $string); $string = str_replace(" ","_", trim($string)); $string = str_replace(",","", trim($string)); $string = strtolower($string); return $string; } $formats = array('png' => 'image/png', 'pdf' => 'application/pdf', 'svg' => 'image/svg+xml', 'eps' => 'image/x-eps'); if(array_key_exists('format', $_GET)) { $f = $_GET['format']; $filename = cleanString($c['office-part'].'--'.$c['incipit'].'--'.$c['version']); if($f == 'gabc') { $content = json_decode($c['gabc']); if(is_string($content)) { $gabc = $content; } elseif(is_array($content)) { $gabcs = array(); foreach($content as $e) { if($e[0] == 'gabc') $gabcs[] = $e[1]; } if(array_key_exists('elem', $_GET) && (int)$_GET['elem'] < count($gabcs)+1) { $gabc = $gabcs[(int)$_GET['elem']-1]; $suffix = '.'.$_GET['elem']; } else { die(); } } $c_p = array(); $sql1 = 'SELECT * FROM '.db('chant_sources').' WHERE chant_id = '.$id; $req1 = $mysqli->query($sql1) or die('Erreur SQL !
'.$sql1.'
'.$mysqli->error); while ($s = $req1->fetch_assoc()) { $c_p[] = array($s['source'], $s['page']); } header('Content-Type:text/plain; charset=UTF-8'); header('Content-Disposition: attachment; filename='.$filename.$suffix.'.'.'gabc'); echo "name:".$c['incipit'].";\n"; if($c['annotation1'] > ''){ echo "annotation:".$c['annotation1'].";\n"; } if($c['annotation2'] > ''){ echo "annotation:".$c['annotation2'].";\n"; } if($c['office-part'] > ''){ echo "office-part:".$txt['usage'][$c['office-part']].";\n"; } if($c['mode'] > ''){ echo "mode:".$c['mode'].";\n"; } if(count($c_p) > 0) { echo "book:"; $source_label = ''; foreach($c_p as $s) { $source_label .= $sources[$s[0]]['title'].", ".$sources[$s[0]]['year'].", p. ".$s[1].' & '; } echo substr($source_label, 0, strlen($source_label)-3).";\n"; } if($c['transcriber'] > ''){ echo "transcriber:".$c['transcriber'].";\n"; } if($c['commentary'] > ''){ echo "commentary:".$c['commentary'].";\n"; } echo "%%\n"; echo $gabc; if($c['gabc_verses'] && !($suffix > "")) { echo "\n".$c['gabc_verses']; } } elseif(in_array($f, array_keys($formats))) { header('Content-Type:'.$formats[$f]); header('Content-Disposition: attachment; filename='.$filename.$suffix.'.'.$f); echo(file_get_contents('scores/'.$f.'/'.$id.$suffix.'.'.$f)); } else { die('Unknown format'); } }