com web/doc: phpt generator removed: include/lib_phpt_gener ator.inc.php scripts/setup_tests_database.php sql /tests.sql templates/all/www/phpt_edit.tpl.php temp lates/all/www/phpt_list.tpl.php www/phpt_generator. php
| Newsgroups | php.doc.web |
|---|---|
| Message-ID | <[email protected]> |
Commit: 43784b3fa9da34a9858ee07c8120de884402033d Author: Sobak <[email protected]> Mon, 17 Mar 2014 20:56:55 +0100 Parents: 592c601947b9664b4e2a9da6de510c7f28d4579d Branches: master Link: http://git.php.net/?p=web/doc.git;a=commitdiff;h=43784b3fa9da34a9858ee07c8120de884402033d Log: phpt generator removed Changed paths: D include/lib_phpt_generator.inc.php D scripts/setup_tests_database.php D sql/tests.sql D templates/all/www/phpt_edit.tpl.php D templates/all/www/phpt_list.tpl.php D www/phpt_generator.php
diff_43784b3fa9da34a9858ee07c8120de884402033d.txt
(text/plain, 27.7 KB)
diff --git a/include/lib_phpt_generator.inc.php b/include/lib_phpt_generator.inc.php deleted file mode 100755 index 3a184b3..0000000 --- a/include/lib_phpt_generator.inc.php +++ /dev/null @@ -1,496 +0,0 @@ -<?php -/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: -+----------------------------------------------------------------------+ -| PHP Documentation Site Source Code | -+----------------------------------------------------------------------+ -| Copyright (c) 1997-2011 The PHP Group | -+----------------------------------------------------------------------+ -| This source file is subject to version 3.01 of the PHP license, | -| that is bundled with this package in the file LICENSE, and is | -| available at through the world-wide-web at | -| http://www.php.net/license/3_01.txt. | -| If you did not receive a copy of the PHP license and are unable to | -| obtain it through the world-wide-web, please send a note to | -| [email protected] so we can mail you a copy immediately. | -+----------------------------------------------------------------------+ -| Authors: Etienne Kneuss <[email protected]> | -+----------------------------------------------------------------------+ -$Id$ -*/ -/** - * Parameters - */ -define('PHPT_EOL', "\n"); -define('PHPT_SQLITE_FILE', SQLITE_DIR . 'tests.sqlite'); -define('PHPT_DOC_PATH', SVN_DIR . '/' .DOC_DIR. '/en/'); - -define('PHPT_LIMIT_RESULTS', 200); - -define('PHPT_EXAMPLE_REGEX', '#<example>\s*<title>(.+)</title>\s*<programlisting role="php">\s*<!\[CDATA\[(.+)]]>\s*</programlisting>(.+)</example>#isU'); -define('PHPT_OUTPUT_REGEX', '#&example\.outputs;\s*<screen>\s*<!\[CDATA\[(.+)]]>\s*</screen>#isU'); - -define('PHPT_FLAG_IMPORTED', 1); -define('PHPT_FLAG_FILLED', 2); -define('PHPT_FLAG_APPROVED', 4); -define('PHPT_FLAG_IMPLEMENTED', 8); - -define('PHPT_FORMAT_SKIPIF', "--TEST--".PHPT_EOL. - "%s (generated)".PHPT_EOL. - "Location: %s".PHPT_EOL. - "--SKIPIF--".PHPT_EOL. - "%s".PHPT_EOL. - "--FILE--".PHPT_EOL. - "%s".PHPT_EOL. - "--EXPECT--".PHPT_EOL. - "%s"); - -define('PHPT_FORMAT', "--TEST--".PHPT_EOL. - "%s (generated)".PHPT_EOL. - "Location: %s".PHPT_EOL. - "--FILE--".PHPT_EOL. - "%s".PHPT_EOL. - "--EXPECT--".PHPT_EOL. - "%s"); - - -// disable magic_quotes_gpc - -function phpt_clean_gpc (&$item, $key) -{ - $item = stripslashes($item); -} - - -/** - * Opens a new SQLite connection for URLs - * - * @return resource SQLite connection - */ -function phpt_sqlite_open() -{ - return @sqlite_open(PHPT_SQLITE_FILE, 0666); -} - - -/** - * Extrapolate informations from the sql result - * - * @return resource SQLite connection - */ -function phpt_extrapolate($row) -{ - - $return = array('id' => (int) $row['id'], - 'title' => $row['title'], - 'location' => '', - 'class' => '', - 'status' => '', - 'expected' => '', - 'test' => '', - 'skipif' => '', - 'approve_checkbox' => '', - 'svn_link' => 'http://svn.php.net/viewvc/phpdoc/en/trunk/'.$row['location'].'?view=markup', - 'test_lines' => 4, - 'expected_lines' => 4, - 'skipif_lines' => 1, - ); - - // clean up location - $path_pieces = explode('/', $row['location']); - $return['location'] = implode('/', array_slice($path_pieces, -3)); - - // generate the status and the status class - if (($row['flags'] & PHPT_FLAG_IMPLEMENTED) === PHPT_FLAG_IMPLEMENTED) { - $return['status'] = '&docweb.phpt.implemented;'; - $return['class'] = 'phpt_implemented'; - } else if (($row['flags'] & PHPT_FLAG_APPROVED) === PHPT_FLAG_APPROVED) { - $return['status'] = '&docweb.phpt.approved;'; - $return['class'] = 'phpt_approved'; - } else if (($row['flags'] & PHPT_FLAG_FILLED) === PHPT_FLAG_FILLED) { - $return['status'] = '&docweb.phpt.filled;'; - $return['class'] = 'phpt_filled'; - } else { - $return['status'] = '&docweb.phpt.imported;'; - $return['class'] = 'phpt_none'; - } - - - if (!empty($row['expected'])) { - if(($num = substr_count($row['expected'], "\n")) > $return['expected_lines']) { - if($num > 30) { - $num = 30; - } - - $return['expected_lines'] = $num; - - } - $return['expected'] = htmlentities($row['expected']); - } - - if (!empty($row['test'])) { - if(($num = substr_count($row['test'], "\n")) > $return['test_lines']) { - if($num > 30) { - $num = 30; - } - $return['test_lines'] = $num; - } - $return['test'] = htmlentities($row['test']); - } - - if (!empty($row['skipif'])) { - if(($num = substr_count($row['skipif'], "\n")) > $return['skipif_lines']) { - if($num > 30) { - $num = 30; - } - $return['skipif_lines'] = $num; - } - $return['skipif'] = htmlentities($row['skipif']); - } - // approve checkbox - - if (($row['flags'] & PHPT_FLAG_APPROVED) === PHPT_FLAG_APPROVED) { - $return['approve_checkbox'] = ' checked'; - } - - // careful with large titles - $return['title_limited'] = trim($return['title']); - - if (strlen($return['title_limited']) > 40) { - $return['title_limited'] = substr($return['title_limited'], 0, 37).'...'; - } - - $return['title'] = trim(htmlentities($return['title'])); - $return['title_limited'] = htmlentities($return['title_limited']); - - return $return; - -} - - -/** - * Import examples from doc sources. - * - * @return int, number of imported examples - */ -function phpt_import_from_source($sqlite) -{ - - // Begin the listing - $userdata = array('examples_added' => 0, - 'sqlite' => $sqlite); - - - $path = ''; - - phpt_list_files(PHPT_DOC_PATH, $path, $userdata); - - return $userdata['examples_added']; - -} - -/** - * List files recursivly and scan them - * - * @return bool - */ -function phpt_list_files($prefix, $path, &$userdata) -{ - - if (is_dir($prefix.$path) && is_resource($handle = @opendir($prefix.$path))) { - - while ($name = readdir($handle)) { - if (strpos($name, ".xml") !== false) { - phpt_scan_file($prefix, $path.$name, $userdata); - } else if(is_dir($prefix.$path.$name) && $name !== '.svn' && $name !== '.' && $name !== '..') { - phpt_list_files($prefix, $path.$name.DIRECTORY_SEPARATOR, $userdata); - } - - } - - closedir($handle); - return true; - - } else { - return false; - } - -} - -/** - * Scan files for examples, and insert them - * - * @return null - */ -function phpt_scan_file($prefix, $path, &$userdata) -{ - - if (!is_file($prefix.$path)) { - return false; - } - - $content = file_get_contents($prefix.$path); - - if ($number = preg_match_all(PHPT_EXAMPLE_REGEX, $content, $matches)) { - // found at least an example - - foreach ($matches[2] as $key => $example) { - - $expected = ''; - $flags = 1; - - /* Parse the extra content */ - $extra = $matches[3][$key]; - - if (preg_match(PHPT_OUTPUT_REGEX, $extra, $match)) { - $expected = $match[1]; - $flags |= PHPT_FLAG_FILLED; - } - - - $title = preg_replace('#<function>([\w_-]+)</function>#', '\1()', $matches[1][$key]); - - - // let's create the entry - - $sql_query = "INSERT INTO tests ( - title, - location, - test, - expected, - import_date, - flags - ) - VALUES ( - '".sqlite_escape_string($title)."', - '".sqlite_escape_string($path)."', - '".sqlite_escape_string(phpt_clean_ws($example))."', - '".sqlite_escape_String(phpt_clean_ws($expected))."', - datetime('now'), - $flags - )"; - // @ here to avoid "column test is not unique". - if (!@sqlite_exec($userdata['sqlite'], $sql_query)) { - $number--; - } - - } - - $userdata['examples_added'] += $number; - } - -} - -/** - * Generate a list of examples - * - * @return null - */ -function phpt_generate_list($sqlite, $ids) -{ - $ids = array_map('intval', $ids); - - // select data - - $sql_query = 'SELECT id, - title, - location, - test, - skipif, - expected, - edit_date, - import_date, - flags - FROM tests - WHERE id IN ('.implode(',', $ids).')'; - - $results = sqlite_query($sqlite, $sql_query); - - - if (count($ids) === 1) { - phpt_download(sqlite_fetch_array($results, SQLITE_ASSOC)); - } else { - - $archivePath = '/tmp/phpt_'.md5(implode('-', $ids)).'.tgz'; - - header('Content-Type: application/gzip'); - header('Content-Disposition: attachment; filename='.basename($archivePath)); - - - - $myArchive = new Archive_Tar($archivePath, 'gz'); - - while ($row = sqlite_fetch_array($results, SQLITE_ASSOC)) { - $myArchive->addString('test'.$row['id'].'.phpt', phpt_generate($row)); - } - - // Destructor, to correctly close the file - $myArchive->_Archive_Tar(); - - readfile($archivePath); - unlink($archivePath); - - } -} -/** - * Generate a list of examples selected by flag - * - * @return null - */ -function phpt_generate_all($sqlite, $flags) -{ - - // select data - - $sql_query = 'SELECT id, - title, - location, - test, - skipif, - expected, - edit_date, - import_date, - flags - FROM tests - WHERE flags & '.$flags.' = '.$flags; - - $results = sqlite_query($sqlite, $sql_query); - - if (sqlite_num_rows($results) === 1) { - phpt_download(sqlite_fetch_array($results, SQLITE_ASSOC)); - } else { - $flags_verbose = array(); - - if ($flags & PHPT_FLAG_FILLED) { - $flags_verbose[] = 'filled'; - } - - if ($flags & PHPT_FLAG_APPROVED) { - $flags_verbose[] = 'approved'; - } - - if ($flags & PHPT_FLAG_IMPLEMENTED) { - $flags_verbose[] = 'implemented'; - } - - - $archivePath = '/tmp/phpt_'.implode('_', $flags_verbose).'.tgz'; - - header('Content-Type: application/gzip'); - header('Content-Disposition: attachment; filename='.basename($archivePath)); - - - - $myArchive = new Archive_Tar($archivePath, 'gz'); - - while ($row = sqlite_fetch_array($results, SQLITE_ASSOC)) { - $myArchive->addString('test'.$row['id'].'.phpt', phpt_generate($row)); - } - // Destructor, to correctly close the file - $myArchive->_Archive_Tar(); - - readfile($archivePath); - unlink($archivePath); - - } -} -/** - * Delete a list of tests - * - * @return null - */ -function phpt_delete_list($sqlite, $ids) -{ - $ids = array_map('intval', $ids); - - $sql_query = 'DELETE FROM tests - WHERE id IN ('.implode(',', $ids).')'; - - return var_dump(sqlite_exec($sqlite, $sql_query)); - -} - -/** - * Generate one example - * - * @return null - */ -function phpt_generate($infos) -{ - - if (empty($infos['skipif'])) { - - return sprintf(PHPT_FORMAT, $infos['title'], - $infos['location'], - $infos['test'], - $infos['expected']); - - } else { - - return sprintf(PHPT_FORMAT_SKIPIF, $infos['title'], - $infos['location'], - $infos['skipif'], - $infos['test'], - $infos['expected']); - } -} - - -/** - * Generate one example and make it available to download - * - * @return null - */ -function phpt_download($infos) -{ - if (headers_sent()) { - return false; - } - - $path_pieces = explode('/', $infos['location']); - $name = implode('_', array_slice($path_pieces, -3)); - - $name = substr($name, 0, -4).'.phpt'; - - header('Content-Type: text/plain'); - header('Content-Disposition: attachment; filename="'.$name.'"'); - - echo phpt_generate($infos); -} - - -/** - * Commit changes - * - * @return true/false - */ -function phpt_commit_changes($sqlite, $input) -{ - $title = !empty($input['title']) ? sqlite_escape_string($input['title']) : ''; - $test = !empty($input['test']) ? sqlite_escape_string(phpt_clean_ws($input['test'])) : ''; - $skipif = !empty($input['skipif']) ? sqlite_escape_string(phpt_clean_ws($input['skipif'])) : ''; - $expected = !empty($input['expected']) ? sqlite_escape_string(phpt_clean_ws($input['expected'])) : ''; - $flags = isset($input['approve']) ? '(flags | '.PHPT_FLAG_APPROVED.')' : '(flags & ~'.PHPT_FLAG_APPROVED.')'; - if (!empty($expected)) { - $flags .= ' | '.PHPT_FLAG_FILLED; - } - - $sql_query = "UPDATE tests SET edit_date = datetime('now'), - title = '$title', - test = '$test', - skipif = '$skipif', - expected = '$expected', - flags = ($flags) - WHERE id = ".intval($input['editId']); - //echo $sql_query; - return @sqlite_exec($sqlite, $sql_query); -} - -/** - * clean linefeeds and extra spaces - */ -function phpt_clean_ws($string) -{ - $string = trim($string); - return str_replace(array("\r\n", "\r", "\n"), PHPT_EOL, $string); -} - diff --git a/scripts/setup_tests_database.php b/scripts/setup_tests_database.php deleted file mode 100755 index 621cdc1..0000000 --- a/scripts/setup_tests_database.php +++ /dev/null @@ -1,32 +0,0 @@ -#!/usr/local/bin/php -<?php -/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: -+----------------------------------------------------------------------+ -| PHP Documentation Site Source Code | -+----------------------------------------------------------------------+ -| Copyright (c) 1997-2011 The PHP Group | -+----------------------------------------------------------------------+ -| This source file is subject to version 3.01 of the PHP license, | -| that is bundled with this package in the file LICENSE, and is | -| available at through the world-wide-web at | -| http://www.php.net/license/3_01.txt. | -| If you did not receive a copy of the PHP license and are unable to | -| obtain it through the world-wide-web, please send a note to | -| [email protected] so we can mail you a copy immediately. | -+----------------------------------------------------------------------+ -| Authors: Etienne Kneuss <[email protected]> | -+----------------------------------------------------------------------+ -$Id$ -*/ - -$PWD = dirname(__FILE__) . "/"; -$path = $PWD.'../sqlite/tests.sqlite'; - -$idx = sqlite_open($path, 0666); - -if (!$idx) { - die('Could not open '.$path); -} - -sqlite_query($idx, file_get_contents($PWD ."../sql/tests.sql")); -sqlite_close($idx); diff --git a/sql/tests.sql b/sql/tests.sql deleted file mode 100755 index cec17c3..0000000 --- a/sql/tests.sql +++ /dev/null @@ -1,11 +0,0 @@ -CREATE TABLE tests ( - id INTEGER PRIMARY KEY, - title varchar(150) NOT NULL default '', - location varchar(80) NOT NULL default '', - test text NOT NULL UNIQUE, - skipif, text NOT NULL default '', - expected text NOT NULL default '', - edit_date timestamp(14) NOT NULL default '0', - import_date timestamp(14) NOT NULL default '0', - flags INTEGER NOT NULL default 1 -) diff --git a/templates/all/www/phpt_edit.tpl.php b/templates/all/www/phpt_edit.tpl.php deleted file mode 100755 index b470a62..0000000 --- a/templates/all/www/phpt_edit.tpl.php +++ /dev/null @@ -1,46 +0,0 @@ -<?php -if (!empty($error)) { - - echo ' -<h2>Error:</h2> -'.$error.' -<br /><br /><a href="phpt_generator.php?q='.$q.'">&docweb.phpt.return;</a>'; - - return; -} - -if ($edited === false) { - echo '<h2>&docweb.phpt.edit.error;</h2>'; -} else if ($edited === true) { - echo '<h2>&docweb.phpt.edit.ok;</h2>'; -} - -echo ' -<h1>&docweb.phpt.edit;</h1> - -<a href="phpt_generator.php?q='.$q.'">&docweb.phpt.return;</a><br /> -<a href="phpt_generator.php?generateId='.$test['id'].'">&docweb.phpt.generate;</a><br /> - -<form action="" method="POST" class="phpt"> - <h2>&docweb.phpt.edit.title;</h2> - <input name="title" type="text" value="'.$test['title'].'" size="80" /> - - <h2>&docweb.phpt.edit.skipif;</h2> - <textarea name="skipif" rows="'.$test['skipif_lines'].'" cols="80">'.$test['skipif'].'</textarea> - - <h2>&docweb.phpt.edit.test;</h2> - <textarea name="test" rows="'.$test['test_lines'].'" cols="80">'.$test['test'].'</textarea> - - <h2>&docweb.phpt.edit.expected;</h2> - <textarea name="expected" rows="'.$test['expected_lines'].'" cols="80">'.$test['expected'].'</textarea> - - <h2>&docweb.phpt.edit.approve;</h2> - <input name="approve" type="checkbox"'.$test['approve_checkbox'].'/> -'; -if(is_admin()) { - echo ' <input type="submit" name="commit" value="&docweb.phpt.commit;">'; -} -echo ' - </form>'; - -?> diff --git a/templates/all/www/phpt_list.tpl.php b/templates/all/www/phpt_list.tpl.php deleted file mode 100755 index f87227c..0000000 --- a/templates/all/www/phpt_list.tpl.php +++ /dev/null @@ -1,69 +0,0 @@ -<?php - -if ($ntotal == 200) { - $limitError = '<strong>&docweb.phpt.limitreached;</strong><br />'; -} else { - $limitError = ''; -} - -echo ' -<h1>&docweb.phpt.list;</h1>'; - -if(is_admin()) { - echo ' -<a href="?import">&docweb.phpt.import;</a><br />'; -} - -echo ' -<a href="?generateAll">&docweb.phpt.generateall;</a><br /><br /> - -<form action="phpt_generator.php" method="post" class="phpt"> - -<input type="text" name="q" value="'.$search.'" style="display:inline; margin: 0px;" /> <input type="submit" name="search" value="&docweb.phpt.search;"/>'; - -if (!empty($tests)) { - - echo ' -<br /><br /><br /> - -<input type="submit" name="generate" value="&docweb.phpt.generate;"/> '; - - if (is_admin()) { - echo '<input type="submit" name="delete" value="&docweb.phpt.delete;"/>'; - } - - echo ' -<br /><br /> - '.$limitError.'Stats: '.$ntotal.' examples, '.$napproved.' approved, '.$nfilled.' filled, '.$nimported.' imported.<br /> - <table border="1"> - <tr> - <th>&docweb.phpt.list.id;</th> - <th>&docweb.phpt.list.location;</th> - <th>&docweb.phpt.list.title;</th> - <th>&docweb.phpt.list.status;</th> - </tr>'; - - - foreach ($tests as $test) { - - echo ' - <tr class="'.$test['class'].'"> - <td><input type="checkbox" name="ids['.$test['id'].']" /> <a href="?editId='.$test['id'].'&q='.$search_enc.'" title="Edit">'.$test['id'].'</a></td> - <td><a href="'.$test['cvs_link'].'" target="_blank">'.$test['location'].'</a></td> - <td>'.$test['title_limited'].'</td> - <td>'.$test['status'].'</td> - </tr>'; - - } - - echo ' - </table> - - <br /><input type="submit" name="generate" value="&docweb.phpt.generate;"/> '; - if (is_admin()) { - echo '<input type="submit" name="delete" value="&docweb.phpt.delete;"/>'; - } - -} -?> -</form> diff --git a/www/phpt_generator.php b/www/phpt_generator.php deleted file mode 100755 index 70e5073..0000000 --- a/www/phpt_generator.php +++ /dev/null @@ -1,236 +0,0 @@ -<?php -/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: -+----------------------------------------------------------------------+ -| PHP Documentation Site Source Code | -+----------------------------------------------------------------------+ -| Copyright (c) 1997-2011 The PHP Group | -+----------------------------------------------------------------------+ -| This source file is subject to version 3.01 of the PHP license, | -| that is bundled with this package in the file LICENSE, and is | -| available at through the world-wide-web at | -| http://www.php.net/license/3_01.txt. | -| If you did not receive a copy of the PHP license and are unable to | -| obtain it through the world-wide-web, please send a note to | -| [email protected] so we can mail you a copy immediately. | -+----------------------------------------------------------------------+ -| Authors: Etienne Kneuss <[email protected]> | -+----------------------------------------------------------------------+ -$Id$ -*/ - -require_once '../include/init.inc.php'; -require_once '../include/lib_phpt_generator.inc.php'; -require_once 'Archive/Tar.php'; - -// clean magic_quotes_gpc - -if (get_magic_quotes_gpc()) { - array_walk_recursive($_GET, 'phpt_clean_gpc'); - array_walk_recursive($_POST, 'phpt_clean_gpc'); - array_walk_recursive($_REQUEST, 'phpt_clean_gpc'); - array_walk_recursive($_COOKIE, 'phpt_clean_gpc'); -} - - -if (!$sqlite = phpt_sqlite_open()) { - echo site_header('docweb.common.header.phptgen'); - echo '<p>Unable to open examples database</p>'; - echo site_footer('$Id$'); - exit(); -} - - -/** - * Generate tests - */ -if (!empty($_REQUEST['ids']) && isset($_REQUEST['generate'])) { - phpt_generate_list($sqlite, array_keys($_REQUEST['ids'])); - exit; -} - -/** - * Generate every filled tests - */ -if (isset($_REQUEST['generateAll'])) { - - phpt_generate_all($sqlite, PHPT_FLAG_FILLED); - - exit; -} - -/** - * Generate one test - */ -if (!empty($_REQUEST['generateId'])) { - - $sql_query = 'SELECT id, - title, - location, - test, - skipif, - expected, - edit_date, - import_date, - flags - FROM tests - WHERE id = '.(int)$_REQUEST['generateId']; - - $results = sqlite_query($sqlite, $sql_query); - - phpt_download(sqlite_fetch_array($results, SQLITE_ASSOC)); - exit; -} - - -/** - * check rights when admin required. - */ -if ((!empty($_REQUEST['ids']) && isset($_REQUEST['delete'])) - || isset($_REQUEST['import']) - || (!empty($_REQUEST['editId']) && isset($_REQUEST['commit']))) { - - auth(); - if (!is_admin()) { - die('you are not an admin!'); - } -} - -echo site_header('docweb.common.header.phptgen'); - - - -/** - * Remove tests - */ -if (!empty($_REQUEST['ids']) && isset($_REQUEST['delete'])) { - phpt_delete_list($sqlite, array_keys($_REQUEST['ids'])); -} - - -/** - * Import tests - */ -if (isset($_REQUEST['import'])) { - // this operation requires authentication as - // it can waste a lot of server resources - - $num = phpt_import_from_source($sqlite); - echo "<h2>Imported $num examples</h2>"; -} - -/** - * Handle edition - */ -if (!empty($_REQUEST['editId'])) { - - $test_id = (int)$_REQUEST['editId']; - $edited = null; - $error = ''; - $testData = array(); - $q = !empty($_REQUEST['q']) ? rawurlencode($_REQUEST['q']) : ''; - - if (isset($_REQUEST['commit'])) { - $edited = phpt_commit_changes($sqlite, $_REQUEST); - } - - $sql_query = 'SELECT id, - title, - location, - test, - skipif, - expected, - edit_date, - import_date, - flags - FROM tests - WHERE id = '.$test_id; - - $results = sqlite_query($sqlite, $sql_query); - - - $row = sqlite_fetch_array($results, SQLITE_ASSOC); - - if (empty($row)) { - $error = '&docweb.phpt.editidnotfound;'; - } else { - $testData = phpt_extrapolate($row); - } - - - echo DocWeb_Template::get( - 'phpt_edit.tpl.php', - array( - 'test' => $testData, - 'error' => $error, - 'edited' => $edited, - 'q' => $q, - ) - ); - echo site_footer('$Id$'); - exit; - -} -/** - * Display listing - */ -$testsData = array(); - -$imported = 0; -$filled = 0; -$approved = 0; -$total = 0; -$q = ''; - -if (!empty($_REQUEST['q'])) { - - $q = trim($_REQUEST['q']); - $q_sql = str_replace('\%', '%', sqlite_escape_string($q)); - $sql_query = 'SELECT id, - title, - location, - test, - expected, - edit_date, - import_date, - flags - FROM tests - WHERE location LIKE \'%'.$q_sql.'%\' - ORDER BY flags DESC, location, id - LIMIT '.PHPT_LIMIT_RESULTS; - - $results = sqlite_query($sqlite, $sql_query); - - - while ($row = sqlite_fetch_array($results, SQLITE_ASSOC)) { - $testsData[$row['id']] = phpt_extrapolate($row); - if (($row['flags'] & PHPT_FLAG_APPROVED) === PHPT_FLAG_APPROVED) { - $approved ++; - } - if (($row['flags'] & PHPT_FLAG_FILLED) === PHPT_FLAG_FILLED) { - $filled ++; - } - if ($row['flags'] === PHPT_FLAG_IMPORTED) { - $imported ++; - } - - $total++; - } -} -echo DocWeb_Template::get( - 'phpt_list.tpl.php', - array( - 'tests' => $testsData, - 'search' => htmlentities($q), - 'search_enc' => rawurlencode($q), - 'nimported' => $imported, - 'nfilled' => $filled, - 'napproved' => $approved, - 'ntotal' => $total - - ) -); - -echo site_footer('$Id$'); - - -?>