diff --git a/autoresize.jquery.js b/autoresize.jquery.js
new file mode 100644
index 0000000..1ff1052
--- /dev/null
+++ b/autoresize.jquery.js
@@ -0,0 +1,115 @@
+/*!
+ * jQuery Textarea Auto-Resize Plugin
+ * http://www.beansandcurry.com/
+ *
+ * Copyright 2012, Beans & Curry
+ * Released under the MIT License
+ */
+(function ($) {
+ /* Auto-resize plugin */
+ $.fn.autoresize = function (options) {
+
+ var settings = $.extend({
+ debug: false,
+ }, options),
+ styles = [
+ 'font-family',
+ 'font-size',
+ 'font-weight',
+ 'font-style',
+ 'letter-spacing',
+ 'text-transform',
+ 'word-spacing',
+ 'text-indent',
+ 'line-height',
+ 'padding-top',
+ 'padding-bottom'
+ ];
+
+ /* Replaces line breaks with
tags for the text entered in the textarea */
+ function textarea2div(text) {
+ var breakTag = '
';
+ return (text + '
~').replace(/([^>\r\n]?)(\r\n|\n\r|\r|\n)/g, '$1' + breakTag + '$2');
+ }
+
+ return this.each(function () {
+ var $this = $(this),
+ mirror = $("
");
+ /* Disables scrollbars in the textarea */
+ $this.css('overflow', 'hidden');
+ /* Copy the styles from the textarea to the mirror */
+ $.each(styles, function (index, property) {
+ mirror.css(property, $this.css(property));
+ });
+
+ mirror.css({
+ 'word-wrap': 'break-word',
+ 'position': 'absolute',
+ 'height': 'auto',
+ 'width': $this.width()
+ })
+
+ if (settings.debug === false) {
+ /* Position the mirror outside of the screen */
+ mirror.css({
+ 'top': '-999em',
+ 'left': '-999em'
+ });
+ } else {
+ /* Position the mirror on the screen for debugging purposes */
+ mirror.css({
+ 'top': '10px',
+ 'left': '10px'
+ });
+ }
+ /* Copy any text that is in the textarea to the mirror */
+ mirror.html(textarea2div($this.val()));
+ /* Append the mirror to the body of your HTML */
+ $("body").append(mirror);
+
+ /* Make the textarea the same height as the mirror's height */
+ $this.height(mirror.height());
+
+ /* Use the textchange event to update the mirror's text and update the textarea's height */
+ /* Tip: You can add "transition: height .2s" to your textarea's CSS to get a nice animation when the height changes. */
+ $this.bind("textchange", function () {
+ mirror.html(textarea2div($this.val()));
+ $this.height(mirror.height());
+ });
+ });
+ };
+
+ /* Defining the 'textchange' event */
+ /* Part of this code was taken from ZURB's jQuery TextChange Plugin http://www.zurb.com/playground/jquery-text-change-custom-event */
+ $.event.special.textchange = {
+
+ setup: function (data, namespaces) {
+ $(this).data('lastValue', this.contentEditable === 'true' ? $(this).html() : $(this).val());
+ $(this).bind('keyup.textchange', $.event.special.textchange.handler);
+ $(this).bind('cut.textchange paste.textchange input.textchange', $.event.special.textchange.delayedHandler);
+ },
+
+ teardown: function (namespaces) {
+ $(this).unbind('.textchange');
+ },
+
+ handler: function (event) {
+ $.event.special.textchange.triggerIfChanged($(this));
+ },
+
+ delayedHandler: function (event) {
+ var element = $(this);
+ setTimeout(function () {
+ $.event.special.textchange.triggerIfChanged(element);
+ }, 25);
+ },
+
+ triggerIfChanged: function (element) {
+ var current = element[0].contentEditable === 'true' ? element.html() : element.val();
+ if (current !== element.data('lastValue')) {
+ element.trigger('textchange', [element.data('lastValue')]);
+ element.data('lastValue', current);
+ }
+ }
+ };
+})(jQuery);
\ No newline at end of file
diff --git a/chant.php b/chant.php
index 54fe959..fd45de0 100644
--- a/chant.php
+++ b/chant.php
@@ -135,7 +135,7 @@ if($req1->num_rows > 0 || $c['transcriber'] > '') {
}
while ($m = $req1->fetch_assoc()) {
$user_info = get_userdata($m['user_id']);
- echo "".date("M d, Y",$m['time']).": ".$m['comment']." (".$user_info->display_name.")\n";
+ echo "".date("M d, Y",$m['time']).": ".$m['comment']." (".$user_info->display_name.') ?\n";
}
if($c['transcriber'] > '') {
echo "Original transcriber: ".$c['transcriber']."\n";
diff --git a/chant_edit.php b/chant_edit.php
index a07a680..62f75f1 100644
--- a/chant_edit.php
+++ b/chant_edit.php
@@ -1,94 +1,448 @@
query($sql1) or die('Erreur SQL !
'.$sql1.'
'.$mysqli->error);
-$c = $req1->fetch_assoc();
-if(!$c) {
+
+function mkstemp($suffix) {
+ # based on http://stackoverflow.com/questions/8970913/create-a-temp-file-with-a-specific-extension-using-php
+ $attempts = 238328; // 62 x 62 x 62
+ $letters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
+ $length = strlen($letters) - 1;
+
+ for($count = 0; $count < $attempts; ++$count) {
+ $random = "";
+
+ for($p = 0; $p < 6; $p++) {
+ $random .= $letters[mt_rand(0, $length)];
+ }
+
+ $randomFile = sys_get_temp_dir().'/'.$random.$suffix;
+
+ if( !($fd = @fopen($randomFile, "x+")) )
+ continue;
+
+ return array($fd,$randomFile);
+ }
+ return False;
+}
+
+function gregorio($s,$i=1) {
+ $f = mkstemp('.gabc');
+ fwrite($f[0],"initial-style:".$i.";\n%%\n".$s);
+ fclose($f[0]);
+ chdir(dirname($f[1]));
+ exec('gregorio '.basename($f[1]));
+ unlink($f[1]);
+ $gf = substr($f[1],0,-5).'.tex';
+ $g = fopen($gf,'r');
+ $tex = fread($g,filesize($gf));
+ fclose($g);
+ unlink($gf);
+ $tex = substr($tex,0,-12)."\n\\relax\n";
+
+ if($i > 0) {
+ $tex = '\setspaceafterinitial{2.2mm plus 0em minus 0em}
+\setspacebeforeinitial{2.2mm plus 0em minus 0em}
+'.$tex;
+ } else {
+ $tex = '\setspaceafterinitial{0pt plus 0em minus 0em}%
+\setspacebeforeinitial{0pt plus 0em minus 0em}%
+'.$tex;
+ }
+
+ return $tex;
+}
+
+function mgabc2tex($c, $firstverse = False) {
+ $ann = array('al' => False,
+ 'an' => 'Ant',
+ 'ca' => 'Cant',
+ 'co' => 'Comm',
+ 'gr' => 'Grad',
+ 'hy' => 'Hymn',
+ 'in' => 'Intr',
+ 'im' => False,
+ 'ky' => False,
+ 'of' => 'Offert',
+ 'ps' => False,
+ 're' => 'Resp',
+ 'se' => 'Seq',
+ 'tr' => 'Tract',
+ 'va' => False);
+ #
+ # Document header
+ #
+ $tex = '% !TEX TS-program = lualatex
+% !TEX encoding = UTF-8
+
+\documentclass[12pt]{article}
+\usepackage{geometry}
+\geometry{paperwidth=16cm,paperheight=150cm}
+\usepackage{gregoriotex}
+\usepackage{fullpage}
+
+\usepackage[latin]{babel}
+
+\usepackage{fontspec}
+\defaultfontfeatures{Ligatures=TeX}
+\setmainfont{Linux Libertine O}
+
+\pagestyle{empty}
+\begin{document}
+\newcommand{\red}[1]{\textcolor{red}{#1}}
+\newcommand{\black}[1]{\textcolor{black}{#1}}
+\setlength{\parindent}{0pt}
+
+\def\greinitialformat#1{
+{\fontsize{38}{38}\selectfont #1}
+}
+
+\def\grebiginitialformat#1{
+{\fontsize{144}{144}\selectfont #1}
+}
+
+';
+ if($c['commentary']) {
+ $tex .= '\commentary{{\small \emph{'.$c['commentary']."}}}\n";
+ $tex .= '\nolinebreak[4]'."\n";
+ }
+ if($ann[$c['office-part']]) {
+ $tex .= '\gresetfirstannotation{\small \textbf{'.$ann[$c['office-part']].".}}\n";
+ }
+ if($c['mode']) {
+ if($c['mode'] == 'p') {
+ $mode = "T. pereg.";
+ } else {
+ $mode = $c['mode'];
+ }
+ $tex .= '\gresetsecondannotation{\small \textbf{'.$mode.".}}\n";
+ }
+ #
+ # Parsing gabc
+ #
+ $g = json_decode($c['gabc']);
+ $i = $c['initial'];
+ if(is_array($g)) {
+ foreach($g as $l) {
+ if($l[0] == 'gabc') {
+ $tex .= gregorio($l[1],$i);
+ } else {
+ $tex .= "\\vspace{10pt}\n".$l[1]."\\par\n";
+ }
+ $i = 0;
+ }
+ } elseif($c['gabc_verses'] && !$firstverse) {
+ $tex .= gregorio($g."\n".$c['gabc_verses'],$i);
+ } elseif($c['tex_verses'] && !$firstverse) {
+ $tex .= gregorio($g,$i);
+ $tex .= "\\vspace{10pt}\n".$c['tex_verses']."\\par\n";
+ } else {
+ $tex .= gregorio($g,$i);
+ }
+ #
+ # Document footer
+ #
+ $tex .= '
+\end{document}
+';
+ return $tex;
+}
+
+function makeimgfiles($id, $tex, $suffix = '') {
+ $path = __DIR__.'/scores/';
+ $f = mkstemp('.tex');
+ fwrite($f[0],$tex);
+ fclose($f[0]);
+ chdir(dirname($f[1]));
+ exec('lualatex --interaction=nonstopmode '.basename($f[1]));
+ exec('convert -density 300 '.substr($f[1],0,-4).'.pdf -flatten -trim '.$path.'png/'.$id.$suffix.'.png');
+ chmod($path.'png/'.$id.$suffix.'.png', 0666);
+ exec('convert -resize 33.333333% '.$path.'png/'.$id.$suffix.'.png '.$path.$id.$suffix.'.png');
+ chmod($path.$id.$suffix.'.png', 0666);
+ exec('pdfcrop '.substr($f[1],0,-4).'.pdf '.$path.'pdf/'.$id.$suffix.'.pdf');
+ chmod($path.'pdf/'.$id.$suffix.'.pdf', 0666);
+ exec('gs -q -dNOPAUSE -dBATCH -dSAFER -sDEVICE=epswrite -dCompatibilityLevel=1.3 -dEmbedAllFonts=true -dSubsetFonts=true -sOutputFile='.$path.'eps/'.$id.$suffix.'.eps '.$path.'pdf/'.$id.$suffix.'.pdf');
+ chmod($path.'eps/'.$id.$suffix.'.eps', 0666);
+ unlink($f[1]);
+ unlink(substr($f[1],0,-4).'.log');
+ unlink(substr($f[1],0,-4).'.aux');
+ unlink(substr($f[1],0,-4).'.gaux');
+ unlink(substr($f[1],0,-4).'.pdf');
+}
+
+if(array_key_exists("id", $_GET)||array_key_exists("id", $mypost)) {
+ $id = array_key_exists("id", $_GET)?intval($_GET['id']):intval($mypost['id']);
+} else {
+ $id = '0';
+}
+$sql = 'SELECT * FROM '.db('chants').' WHERE id = '.$id;
+$req = $mysqli->query($sql) or die('Erreur SQL !
'.$sql.'
'.$mysqli->error);
+$c = $req->fetch_assoc();
+if(!$c && $id != '0') {
die('Wrong id');
}
+$c_s = array();
+$sql = 'SELECT * FROM '.db('chant_sources').' WHERE chant_id = '.$id;
+$req = $mysqli->query($sql) or die('Erreur SQL !
'.$sql.'
'.$mysqli->error);
+while ($s = $req->fetch_assoc()) {
+ $c_s[] = $s;
+}
$title = $c['incipit'];
+$custom_header = <<
+
+
+
+
+HEADER;
include('include/header.php');
if(!$logged_in) {
- echo "Please login";
-} elseif(count($_POST) > 0) {
- #$mysqli->query('INSERT into '.db('proofreading').' VALUES ('.$id.','.$_SESSION['user_id'].','.time().')') or die('Erreur SQL !
'.$sql1.'
'.$mysqli->error);
-} else {
-
- $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_s = array($s['source'], $s['page']);
- if(is_dir('./sources/'.$s['source'])) {
- if(is_array($sources[$s['source']]['pages'])) {
- $p = array_search($s['page'],$sources[$s['source']]['pages']);
- } else {
- $p = $s['page'];
- }
- $c_p[] = array($s['source'], $s['page'], $p, $s['extent']);
- } else {
- $c_p[] = $c_s;
+ echo 'Please login
';
+} elseif($id == '0' && count($mypost) > 0) {
+ $gabc = array();
+ for($i=0;$i '') {
+ $gabc[] = array($mypost['type'][$i],$mypost['content'][$i],array());
}
}
+ if(count($gabc) == 0) {
+ $mypost['gabc'] = NULL;
+ } elseif(count($gabc) == 1 && $gabc[0][0] == 'gabc') {
+ $mypost['gabc'] = str_replace('",[]]','",{}]', str_replace("\r","",json_encode($gabc[0][1], JSON_UNESCAPED_SLASHES)));
+ } else {
+ $mypost['gabc'] = str_replace('",[]]','",{}]', str_replace("\r","",json_encode($gabc, JSON_UNESCAPED_SLASHES)));
+ }
+ unset($mypost['type']);
+ unset($mypost['content']);
+ $s_p = array();
+ for($i=0;$i (string)$id, "source" => $mypost['source'][$i], "page" => $mypost['page'][$i], "sequence" => $mypost['sequence'][$i], "extent" => $mypost['extent'][$i]);
+ }
+ }
+ unset($mypost['source']);
+ unset($mypost['page']);
+ unset($mypost['sequence']);
+ unset($mypost['extent']);
+ $mypost['gabc_verses'] = str_replace("\r","",$mypost['gabc_verses']);
+ $mypost['tex_verses'] = str_replace("\r","",$mypost['tex_verses']);
- echo '