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'] || $c['mode_var']) { if($c['mode'] == 'p') { $mode = "T. pereg."; } else { $mode = $c['mode'].' '.$c['mode_var']; } $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']?$c['incipit']:'New score'; $custom_header = <<
HEADER; include('include/header.php'); if(!$logged_in) { 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']); $sql = 'INSERT into '.db('chants').' (`incipit`) VALUES ("'.$mysqli->real_escape_string($mypost['incipit']).'")'; $mysqli->query($sql) or die('Erreur SQL !
'.$sql.'
'.$mysqli->error); $id = $mysqli->insert_id; foreach(array('version','office-part','mode','mode_var','commentary','initial','transcriber','gabc','gabc_verses','tex_verses') as $k) { if($mypost[$k] > '' && $mypost[$k] != "(c4)") { $sql = 'UPDATE '.db('chants').' SET `'.$k.'` = "'.$mysqli->real_escape_string($mypost[$k]).'" WHERE `id` = '.$id; $mysqli->query($sql) or die('Erreur SQL !
'.$sql.'
'.$mysqli->error); } } foreach($s_p as $s) { $sql = 'INSERT into '.db('chant_sources').' VALUES ('.$id.','.$s['source'].',"'.$mysqli->real_escape_string($s['page']).'",'.intval($s['sequence']).','.intval($s['extent']).')'; $mysqli->query($sql) or die('Erreur SQL !
'.$sql.'
'.$mysqli->error); } makeimg($mypost); $t = time(); $uid = $current_user->ID; $chgset = $t.'-'.$id.'-'.$uid; $sql = 'INSERT into '.db('changesets').' VALUES ('.$uid.','.$id.','.$t.', "Added to the database")'; $mysqli->query($sql) or die('Erreur SQL !
'.$sql.'
'.$mysqli->error); header('Location: chant.php?id='.$id); } elseif(count($mypost) > 3) { $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'] = json_encode($gabc[0][1], JSON_UNESCAPED_SLASHES); } else { $mypost['gabc'] = 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']); $fields = array('id','incipit','version','office-part','mode','mode_var','commentary','initial','transcriber','gabc','gabc_verses','tex_verses'); $old = array(); $new = array(); foreach($fields as $f) { $myfield = str_replace('",[]]','",{}]', str_replace("\r","",$mypost[$f])); if($c[$f] != $myfield) { $old[$f] = $c[$f]; $new[$f] = $myfield; } } if($c_s != $s_p || count($old) > 0) { $t = time(); $uid = $current_user->ID; $chgset = $t.'|'.$id.'|'.$uid; $sql = 'INSERT into '.db('changesets').' VALUES ('.$uid.','.$id.','.$t.', NULL)'; $mysqli->query($sql) or die('Erreur SQL !
'.$sql.'
'.$mysqli->error); $mod = False; foreach($old as $k => $v) { $sql = 'INSERT into '.db('changes').' VALUES ("'.$chgset.'","'.$k.'","'.$mysqli->real_escape_string($v).'")'; $mysqli->query($sql) or die('Erreur SQL !
'.$sql.'
'.$mysqli->error); $sql = 'UPDATE '.db('chants').' SET `'.$k.'` = "'.$mysqli->real_escape_string($new[$k]).'" WHERE `id` = '.$id; $mysqli->query($sql) or die('Erreur SQL !
'.$sql.'
'.$mysqli->error); if(in_array($k, array('office-part','mode','mode_var','commentary','initial','gabc','gabc_verses','tex_verses'))) { $mod = True; } } if($c_s != $s_p) { $sql = 'DELETE FROM '.db('chant_sources').' WHERE `chant_id` = '.$id; $mysqli->query($sql) or die('Erreur SQL !
'.$sql.'
'.$mysqli->error); foreach($s_p as $s) { $sql = 'INSERT into '.db('chant_sources').' VALUES ('.$s['chant_id'].','.$s['source'].',"'.$mysqli->real_escape_string($s['page']).'",'.intval($s['sequence']).','.intval($s['extent']).')'; $mysqli->query($sql) or die('Erreur SQL !
'.$sql.'
'.$mysqli->error); } $sql = 'INSERT into '.db('changes').' VALUES ("'.$chgset.'","sources","'.$mysqli->real_escape_string(json_encode($c_s, JSON_UNESCAPED_SLASHES)).'")'; $mysqli->query($sql) or die('Erreur SQL !
'.$sql.'
'.$mysqli->error); } if($mod) { makeimg($mypost); } echo '
'; echo "

Please describe your changes

\n".''."
\n\n
\n"; } else { echo "

No changes made

"; } } elseif(count($mypost) > 0) { $chgset = explode('|',$mypost['changeset']); $sql = 'UPDATE '.db('changesets').' SET `comment` = "'.$mysqli->real_escape_string($mypost['comment']).'" WHERE `user_id` = '.$chgset[2].' AND `chant_id` = '.$chgset[1].' AND `time` = '.$chgset[0]; $mysqli->query($sql) or die('Erreur SQL !
'.$sql.'
'.$mysqli->error); header('Location: chant.php?id='.$id); } else { $gabc = json_decode($c['gabc']); if(is_string($gabc)) { $gabc = array(array('gabc', $gabc, array()),); } elseif(empty($gabc)) { $gabc = array(array('gabc', "(c4)", array()),); } echo '
'; echo '
'; echo "

Score

"; $i = 0; foreach($gabc as $g) { echo '

'; echo '\n"; echo ''; echo ($i>0?' Remove':''); echo '

'; $i++; } echo 'Add more'; echo "

Hymn verses (GABC)

\n"; echo '\n"; echo "

Hymn verses (TeX)

\n"; echo '\n"; echo '
 
'."\n"; echo '
'; echo '

Incipit

'."\n"; echo '

Version

'."\n"; echo '

Usage

\n"; echo "

Mode

\n"; echo '\n"; echo ' - Ending '."\n"; echo '

Commentary

'; echo "

Initial style

\n"; echo '\n"; echo '

Original transcriber

'; function sources_box($so) { global $sources; $sources_box = '\n"; echo $sources_box; } echo "

Sources

\n"; echo 'PageSequenceExtent'; $i = 0; foreach ($c_s as $s) { echo '

'; sources_box($s['source']); echo "\n"; echo ''; echo ''; echo ''; echo ($i>0?' Remove':''); echo '

'; $i++; } if(count($c_s) == 0) { echo '

'; sources_box('0'); echo "\n"; echo ''; echo ''; echo '

'; } echo 'Add more'; echo '

'; echo "
\n"; echo "
\n"; } include('include/footer.php'); ?>