view interface/check_sections_20150120.php @ 17:82f8c6bd2b69

add new tag will based on the current topic_id, insert new element into (1)taglist table and (2)topic_tag_relation table
author Zoe Hong <zhong@mpiwg-berlin.mpg.de>
date Fri, 20 Feb 2015 17:57:02 +0100
parents ef6d0c6a13d7
children
line wrap: on
line source

<?php
include_once('Lib_mb_utf8.php');
include_once('config.php');
include_once('edit_section_db.php');
set_time_limit(0);
ini_set('memory_limit', '-1');

$link_mysql = mysql_connect($mysql_server, $mysql_user, $mysql_password);
mysql_query("SET NAMES utf8");

if (!$link_mysql) {
    die('Could not connect: ' . mysql_error());
}

$db_selected = mysql_select_db($mysql_database, $link_mysql);
if (!$db_selected) {
    die ('Can\'t use foo : ' . mysql_error());
}

function checkSections($count){

/*	$query="SELECT books.name AS book_name, books.level1, books.level2, books.period, books.id, sections.name, start_page, end_page, COUNT( * ) AS count
		FROM sections
		JOIN books ON sections.books_id = books.id
		WHERE NOT EXISTS
		(SELECT 1 FROM sections_versions WHERE books_id=sections.books_id)
		GROUP BY books_id, start_page, end_page
		HAVING COUNT( * ) >=".$count."
		ORDER BY COUNT( * ) DESC ";*/
	$query="(SELECT books.name AS book_name, books.level1, books.level2, books.period, books.id, sections.name, start_page, end_page, COUNT( * ) AS count
		FROM sections
		JOIN books ON sections.books_id = books.id
		WHERE NOT EXISTS
		(SELECT 1 FROM sections_versions WHERE books_id=sections.books_id)
		GROUP BY books_id, start_page, end_page
		HAVING COUNT( * ) >=".$count.")
		UNION
		(SELECT books.name AS book_name, books.level1, books.level2, books.period, books.id, sections_revisions.name, start_page, end_page, COUNT( * ) AS count 
                FROM sections_revisions
                JOIN books ON sections_revisions.books_id = books.id
		JOIN (
			SELECT sections_versions.id 
			FROM sections_versions WHERE sections_versions.version=(SELECT MAX(version) FROM sections_versions) 
			GROUP BY books_id
		) AS t ON t.id=sections_revisions.versions_id
		WHERE deleted=0 
                GROUP BY books_id, versions_id,start_page, end_page
                HAVING COUNT( * ) >=".$count.")
		ORDER BY count DESC ";
	$result = mysql_query($query);
	echo mysql_num_rows($result)." result(s)<br><br>";
	echo "<table>";
	echo "<tr>";
	echo "<td class='bookName'>book name<td class='level1'>level1<td class='level2'>level2<td class='period'>period<td class='sectionName'>section name<td class='sectionName'>page<td class='page'>count";
        while ($row = mysql_fetch_assoc($result)) {
		$str="<tr>";	
		$str.="<td>".$row['book_name'];
		$str.="<td>".$row['level1'];
		$str.="<td>".$row['level2'];
		$str.="<td>".$row['period'];
		$str.="<td><a href='tagging_text.php?id=".$row['id']."' target='_blank'>".$row['name']."</a>";
		$str.="<td>p".$row['start_page']."-".$row['end_page'];
		$str.="<td><a href='check_sections_details.php?book_id=".$row['id']."&count=".$count."' target='_blank'>".$row['count']."</a>";
		echo $str;	
	}
	echo "</table>";
}

?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
        <head>
                <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
                <link href="css/search.css" type="text/css" rel="stylesheet"/>
                <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js" type="text/javascript"></script>
                <!--<script src="js/check_sections.js" charset="utf-8"></script>!-->
        </head>
        <body>
                <form action='check_sections.php' method='GET'>
                        find sections overlapping more than <input type="text" name="count"> other sections
                        <input type="submit" name="find" value="find">
                </form>
                <br>
                <div id="search_result">
                <?php
                        if(isset($_GET['find']) && $_GET['count']!='' && is_numeric($_GET['count'])){
                                checkSections($_GET['count']);
                        }
                ?>
                </div>
        </body>
</html>