Example #1
0
function backEndsTest($tableName, $studentId)
{
    //$tableName 提交的表格名称
    //$studentId 提交的学号
    $stuId = getStuId($studentId);
    $dir = dirname(__FILE__);
    $pathOfTemplate = dirname($dir) . "/documents/template/{$tableName}/{$tableName}.tex";
    $path = dirname($dir) . "/documents/{$stuId}/{$tableName}/{$tableName}.tex";
    //echo $pathOfTemplate . "<br/>\n";
    //echo $path . "<br/>\n";
    if (!file_exists(dirname($path))) {
        mkdir(dirname($path), 0775, true);
    }
    //chmod(dirname(dirname($path)), 0777);
    //chmod(dirname($path), 0777);
    // 复制模板文件
    $source = dirname(dirname($pathOfTemplate)) . "/template.cls";
    $dest = dirname($path) . "/template.cls";
    //echo $source . " " . $dest;
    copy($source, $dest);
    replaceTex($pathOfTemplate, $studentId);
    if (toPdf($path) == 0) {
        echo "<a target='_blank' href='/DocAuto/documents/{$stuId}/{$tableName}/{$tableName}.pdf'>查看 pdf</a>";
        return "/DocAuto/documents/{$stuId}/{$tableName}/{$tableName}.pdf";
    } else {
        return "false";
    }
}
Example #2
0
function replaceTex($pathOfTexFile, $studentId)
{
    // mysql connection info
    $conHost = "127.0.0.1";
    // connect ip
    $conUsername = "******";
    $conPassword = "******";
    $conDatabase = "formatPaper";
    $conView = "VassignmentBook";
    $conQuery = "SELECT * FROM  {$conView}  WHERE studentId = '{$studentId}';";
    // connect mysql
    $con = mysql_connect($conHost, $conUsername, $conPassword);
    if (!$con) {
        die('Could not connect: ' . mysql_error());
    }
    // echo $conQuery; // 检查查询语句
    // query database
    mysql_select_db($conDatabase, $con);
    $result = mysql_query("SET NAMES 'UTF8'");
    $result = mysql_query($conQuery, $con);
    $infoarr = mysql_fetch_array($result);
    mysql_close($con);
    $fstr = file_get_contents($pathOfTexFile);
    foreach ($infoarr as $key => $value) {
        if ($value) {
            $value = str_replace("&nbsp;", " ", $value);
            $value = analysis(html_entity_decode($value));
        }
        $fstr = str_replace("!{$key}-!", html_entity_decode($value), $fstr);
    }
    if ($infoarr['subjectName']) {
        $cuttitle = cut($infoarr['subjectName']);
        $fstr = str_replace($infoarr['subjectName'], $cuttitle, $fstr);
    }
    $fstr = str_replace("\\block{" . $infoarr['topicType'] . "}", "\\blockC{" . $infoarr['topicType'] . "}", $fstr);
    $fstr = preg_replace("/\\!(\\w+)\\-!/", "", $fstr);
    //$newadd = str_replace("template", $studentId, $pathOfTexFile);
    $newadd = str_replace("template", getStuId($studentId), $pathOfTexFile);
    //echo $newadd ."<br/>\n";
    // 这里的路径为执行该函数的 php 所在路径决定
    $fstr = str_replace("\r\n", "\n", $fstr);
    file_put_contents($newadd, $fstr);
}
Example #3
0
<html>
<body>

<form method="post">
    <input type="submit" name="replace" value="生成 tex 文件">
    <input type="submit" name="generate" value="生成 pdf 文件">
</form>

<?php 
include "replaceTex.php";
include "toPdf.php";
//include "getStuId.php";
$tableName = "assignmentBook";
// 提交的表格名称
$studentId = getStuId("1300333331");
// 提交的学号
$dir = dirname(__FILE__);
$pathOfTemplate = dirname($dir) . "/documents/template/{$tableName}/{$tableName}.tex";
$path = dirname($dir) . "/documents/{$studentId}/{$tableName}/{$tableName}.tex";
//echo "template = " . $pathOfTemplate . "<br/>\n";
//echo "StuId = " . $path . "<br/>\n";
mkdir(dirname($path), 0777, true);
//chmod(dirname(dirname($path)), 0777);
//chmod(dirname($path), 0777);
// 复制模板文件
$source = dirname(dirname($pathOfTemplate)) . "/template.cls";
$dest = dirname($path) . "/template.cls";
//echo $source . " " . $dest;
copy($source, $dest);
if (isset($_POST['replace'])) {
    replaceTex($pathOfTemplate, "1300333331");