示例#1
0
 private function startXmlDocument($page)
 {
     global $config;
     self::getXmlStream()->startDocument('1.0', 'UTF-8');
     self::getXmlStream()->startElement("feed");
     self::getXmlStream()->writeAttribute("xmlns", "http://www.w3.org/2005/Atom");
     self::getXmlStream()->writeAttribute("xmlns:xhtml", "http://www.w3.org/1999/xhtml");
     self::getXmlStream()->writeAttribute("xmlns:opds", "http://opds-spec.org/2010/catalog");
     self::getXmlStream()->writeAttribute("xmlns:opensearch", "http://a9.com/-/spec/opensearch/1.1/");
     self::getXmlStream()->writeAttribute("xmlns:dcterms", "http://purl.org/dc/terms/");
     self::getXmlStream()->startElement("title");
     self::getXmlStream()->text($page->title);
     self::getXmlStream()->endElement();
     if ($page->subtitle != "") {
         self::getXmlStream()->startElement("subtitle");
         self::getXmlStream()->text($page->subtitle);
         self::getXmlStream()->endElement();
     }
     self::getXmlStream()->startElement("id");
     if ($page->idPage) {
         $idPage = $page->idPage;
         if (!is_null(GetUrlParam(DB))) {
             $idPage = str_replace("cops:", "cops:" . GetUrlParam(DB) . ":", $idPage);
         }
         self::getXmlStream()->text($idPage);
     } else {
         self::getXmlStream()->text($_SERVER['REQUEST_URI']);
     }
     self::getXmlStream()->endElement();
     self::getXmlStream()->startElement("updated");
     self::getXmlStream()->text(self::getUpdatedTime());
     self::getXmlStream()->endElement();
     self::getXmlStream()->startElement("icon");
     self::getXmlStream()->text($page->favicon);
     self::getXmlStream()->endElement();
     self::getXmlStream()->startElement("author");
     self::getXmlStream()->startElement("name");
     self::getXmlStream()->text($page->authorName);
     self::getXmlStream()->endElement();
     self::getXmlStream()->startElement("uri");
     self::getXmlStream()->text($page->authorUri);
     self::getXmlStream()->endElement();
     self::getXmlStream()->startElement("email");
     self::getXmlStream()->text($page->authorEmail);
     self::getXmlStream()->endElement();
     self::getXmlStream()->endElement();
     $link = new LinkNavigation("", "start", "Home");
     self::renderLink($link);
     $link = new LinkNavigation("?" . getQueryString(), "self");
     self::renderLink($link);
     $urlparam = "?";
     if (!is_null(GetUrlParam(DB))) {
         $urlparam = addURLParameter($urlparam, DB, GetUrlParam(DB));
     }
     if ($config['cops_generate_invalid_opds_stream'] == 0 || preg_match("/(MantanoReader|FBReader)/", $_SERVER['HTTP_USER_AGENT'])) {
         // Good and compliant way of handling search
         $urlparam = addURLParameter($urlparam, "page", Base::PAGE_OPENSEARCH);
         $link = new Link("feed.php" . $urlparam, "application/opensearchdescription+xml", "search", "Search here");
     } else {
         // Bad way, will be removed when OPDS client are fixed
         $urlparam = addURLParameter($urlparam, "query", "{searchTerms}");
         $urlparam = str_replace("%7B", "{", $urlparam);
         $urlparam = str_replace("%7D", "}", $urlparam);
         $link = new Link($config['cops_full_url'] . 'feed.php' . $urlparam, "application/atom+xml", "search", "Search here");
     }
     self::renderLink($link);
     if ($page->containsBook() && !is_null($config['cops_books_filter']) && count($config['cops_books_filter']) > 0) {
         $Urlfilter = getURLParam("tag", "");
         foreach ($config['cops_books_filter'] as $lib => $filter) {
             $link = new LinkFacet("?" . addURLParameter(getQueryString(), "tag", $filter), $lib, localize("tagword.title"), $filter == $Urlfilter);
             self::renderLink($link);
         }
     }
 }
示例#2
0
文件: index.php 项目: BreizhCat/cops
require_once "publisher.php";
require_once "serie.php";
require_once "tag.php";
require_once "language.php";
require_once "customcolumn.php";
require_once "book.php";
require_once "resources/doT-php/doT.php";
// If we detect that an OPDS reader try to connect try to redirect to feed.php
if (preg_match("/(MantanoReader|FBReader|Stanza|Marvin|Aldiko|Moon+ Reader|Chunky)/", $_SERVER['HTTP_USER_AGENT'])) {
    header("location: feed.php");
    exit;
}
$page = getURLParam("page", Base::PAGE_INDEX);
$query = getURLParam("query");
$qid = getURLParam("id");
$n = getURLParam("n", "1");
$database = GetUrlParam(DB);
// Access the database ASAP to be sure it's readable, redirect if that's not the case.
// It has to be done before any header is sent.
Base::checkDatabaseAvailability();
if ($config['cops_fetch_protect'] == "1") {
    session_start();
    if (!isset($_SESSION['connected'])) {
        $_SESSION['connected'] = 0;
    }
}
header("Content-Type:text/html;charset=utf-8");
$data = array("title" => $config['cops_title_default'], "version" => VERSION, "opds_url" => $config['cops_full_url'] . "feed.php", "customHeader" => "", "template" => getCurrentTemplate(), "server_side_rendering" => useServerSideRendering(), "current_css" => getCurrentCss(), "favico" => $config['cops_icon'], "getjson_url" => "getJSON.php?" . addURLParameter(getQueryString(), "complete", 1));
if (preg_match("/Kindle/", $_SERVER['HTTP_USER_AGENT'])) {
    $data["customHeader"] = '<style media="screen" type="text/css"> html { font-size: 75%; -webkit-text-size-adjust: 75%; -ms-text-size-adjust: 75%; }</style>';
}
示例#3
0
文件: base.php 项目: Klemart3D/COPS
 public function InitializeContent()
 {
     $scope = getURLParam("scope");
     if (empty($scope)) {
         $this->title = str_format(localize("search.result"), $this->query);
     } else {
         // Comment to help the perl i18n script
         // str_format (localize ("search.result.author"), $this->query)
         // str_format (localize ("search.result.tag"), $this->query)
         // str_format (localize ("search.result.series"), $this->query)
         // str_format (localize ("search.result.book"), $this->query)
         // str_format (localize ("search.result.publisher"), $this->query)
         $this->title = str_format(localize("search.result.{$scope}"), $this->query);
     }
     $crit = "%" . $this->query . "%";
     // Special case when we are doing a search and no database is selected
     if (Base::noDatabaseSelected() && !$this->useTypeahead()) {
         $i = 0;
         foreach (Base::getDbNameList() as $key) {
             Base::clearDb();
             list($array, $totalNumber) = Book::getBooksByQuery(array("all" => $crit), 1, $i, 1);
             array_push($this->entryArray, new Entry($key, DB . ":query:{$i}", str_format(localize("bookword", $totalNumber), $totalNumber), "text", array(new LinkNavigation("?" . DB . "={$i}&page=9&query=" . $this->query)), "", $totalNumber));
             $i++;
         }
         return;
     }
     if (empty($scope)) {
         $this->doSearchByCategory();
         return;
     }
     $array = $this->searchByScope($scope);
     if (count($array) == 2 && is_array($array[0])) {
         list($this->entryArray, $this->totalNumber) = $array;
     } else {
         $this->entryArray = $array;
     }
 }
示例#4
0
function makeDataSetInJS($qname, $qstr, $aoColumns = '', $ext = 'cte', $asObject = false, $append = false)
{
    $isGdata = false;
    if (getURLParam("gdata") == $qname) {
        $isGdata = true;
    }
    //google.visualization.Query.setResponse({version:'0.6',reqId:'0',status:'ok',sig:'5982206968295329967',table:{cols:[{id:'Col1',label:'',type:'number'},{id:'Col2',label:'',type:'number'},{id:'Col3',label:'',type:'number'}],rows:[{c:[{v:1.0,f:'1'},{v:2.0,f:'2'},{v:3.0,f:'3'}]},{c:[{v:2.0,f:'2'},{v:3.0,f:'3'},{v:4.0,f:'4'}]},{c:[{v:3.0,f:'3'},{v:4.0,f:'4'},{v:5.0,f:'5'}]},{c:[{v:1.0,f:'1'},{v:2.0,f:'2'},{v:3.0,f:'3'}]}]}});
    if (!isset($qstr)) {
        return '';
    }
    if (!isset($qname)) {
        $qname = "data1";
    }
    if (!isset($ext)) {
        $ext = "cte";
    }
    db_set_active($ext);
    $q = db_query($qstr);
    $i = 0;
    $r = "";
    $o = array();
    //if $asObject is true then this object is returned instead of the string $r ...
    global $firstDataSet;
    $cols = array();
    while ($rw = db_fetch_array($q)) {
        $newrw = array();
        //temp holder of object data...
        //if r=='' then this is the first row... so set up the dataset and initialize cteReportTemplate if necessary...
        if ($r == "") {
            //firstDataSet is a global flag so that preliminaty js can be initialized...
            if ($firstDataSet) {
                $r = <<<EOF
\t\t\t<script  type='text/javascript'>
\t\t\tvar popup;
\t\t\tvar cteReportTemplate=dataSetObjects;</script>
EOF;
                $firstDataSet = false;
            }
            $r .= "\t\t\t<script  type='text/javascript'>\nif(!cteReportTemplate['{$qname}']) cteReportTemplate.newTable('{$qname}');";
            $sep = "";
            //set up fields...
            $rfn = "\n " . ($append ? "if(!cteReportTemplate.{$qname}.fields) " : "") . "cteReportTemplate.{$qname}.fields=[";
            if ($aoColumns) {
                $flds = json_decode($aoColumns);
                foreach ($flds as $fo) {
                    if (is_object($fo) && $fo->field) {
                        $tmprw = "";
                        $datakey = "";
                        reset($rw);
                        if (array_key_exists($fo->field, $rw)) {
                            $datakey = htmlspecialchars($fo->field);
                        } else {
                            reset($rw);
                            foreach (array_keys($rw) as $rwk) {
                                $tmprw .= $rwk . " :";
                                if (strtolower($rwk) == strtolower($fo->field)) {
                                    $datakey = htmlspecialchars($rwk);
                                    break;
                                }
                            }
                        }
                        if ($datakey) {
                            $cols[] = $datakey;
                            $rfn .= $sep . '{';
                            $fsep = "";
                            $fo->field = strtolower($fo->field);
                            foreach ($fo as $fitem => $fval) {
                                $rfn .= $fsep . '"' . $fitem . '":"' . htmlspecialchars($fval) . '"';
                                $fsep = ",";
                            }
                            $rfn .= '}';
                            $sep = ",";
                        } else {
                            drupal_set_message("Error, column key '{$fo->field}' not found in query data ({$tmprw})", 'error');
                        }
                    } else {
                        drupal_set_message("Error, key value missing field or otherwise not an object", 'error');
                    }
                }
            } else {
                foreach (array_keys($rw) as $f) {
                    $rfn .= $sep . '{"sTitle":"' . htmlspecialchars($f) . '","field":"' . htmlspecialchars($f) . '"}';
                    $sep = ",";
                    $cols[] = htmlspecialchars($f);
                }
            }
            $r .= $rfn;
            $r .= "];\n " . ($append ? "if(!cteReportTemplate.{$qname}.data) " : "") . "cteReportTemplate.{$qname}.data=[];\n//end if {$qname} already exists\n";
        }
        //end if first roww setup ...
        $sep = "";
        $r .= "cteReportTemplate.{$qname}.data.push([";
        foreach ($cols as $fld) {
            $f = $rw[$fld];
            $newrw[] = $f;
            $badChars = array("\r", "\n", "\\");
            $r .= $sep . '"' . htmlspecialchars(str_replace($badChars, " ", $f)) . '"';
            $sep = ",";
        }
        $r .= "]);\n";
        $o[] = $newrw;
        //adds row into object
        $i++;
    }
    //end while...
    if ($i == 0) {
        $r = <<<EOF
    \t<script  type='text/javascript'>
\t\t//alert("No data found");;\t\t
\t\tvar cteReportTemplate=this.dataSetObjects;
\t\tif(!cteReportTemplate) cteReportTemplate=dataSetObjects;
\t\tif(cteReportTemplate) cteReportTemplate.newTable("{$qname}");
\t\t/* {$qstr} */
EOF;
    }
    //	if($i>400) $r=''.$r.'        jQuery("#"+settings.bg_id).fadeOut("normal");        jQuery("#"+settings.main_id).fadeOut("normal");'
    //$r=str_replace("var popup;","$.popup.show('Data Loading', 'Please wait...');",$r)."\n  $.popup.hide();";
    $r .= "</script>";
    db_set_active('default');
    if ($asObject) {
        return $o;
    } else {
        return "" . $r . "";
    }
}
示例#5
0
 public static function getJson($complete = false)
 {
     global $config;
     $page = getURLParam("page", Base::PAGE_INDEX);
     $query = getURLParam("query");
     $search = getURLParam("search");
     $qid = getURLParam("id");
     $n = getURLParam("n", "1");
     $database = GetUrlParam(DB);
     $currentPage = Page::getPage($page, $qid, $query, $n);
     $currentPage->InitializeContent();
     if ($search) {
         return self::getContentArrayTypeahead($currentPage);
     }
     $out = array("title" => $currentPage->title);
     $entries = array();
     foreach ($currentPage->entryArray as $entry) {
         array_push($entries, self::getContentArray($entry));
     }
     if (!is_null($currentPage->book)) {
         $out["book"] = self::getFullBookContentArray($currentPage->book);
     }
     $out["databaseId"] = GetUrlParam(DB, "");
     $out["databaseName"] = Base::getDbName();
     if ($out["databaseId"] == "") {
         $out["databaseName"] = "";
     }
     $out["fullTitle"] = $out["title"];
     if ($out["databaseId"] != "" && $out["databaseName"] != $out["fullTitle"]) {
         $out["fullTitle"] = $out["databaseName"] . " > " . $out["fullTitle"];
     }
     $out["page"] = $page;
     $out["multipleDatabase"] = Base::isMultipleDatabaseEnabled() ? 1 : 0;
     $out["entries"] = $entries;
     $out["isPaginated"] = 0;
     if ($currentPage->isPaginated()) {
         $prevLink = $currentPage->getPrevLink();
         $nextLink = $currentPage->getNextLink();
         $out["isPaginated"] = 1;
         $out["prevLink"] = "";
         if (!is_null($prevLink)) {
             $out["prevLink"] = $prevLink->hrefXhtml();
         }
         $out["nextLink"] = "";
         if (!is_null($nextLink)) {
             $out["nextLink"] = $nextLink->hrefXhtml();
         }
         $out["maxPage"] = $currentPage->getMaxPage();
         $out["currentPage"] = $currentPage->n;
     }
     if (!is_null(getURLParam("complete")) || $complete) {
         $out = self::addCompleteArray($out);
     }
     $out["containsBook"] = 0;
     if ($currentPage->containsBook()) {
         $out["containsBook"] = 1;
     }
     $out["abouturl"] = "index.php" . addURLParameter("?page=" . Base::PAGE_ABOUT, DB, $database);
     if ($page == Base::PAGE_ABOUT) {
         $temp = preg_replace("/\\<h1\\>About COPS\\<\\/h1\\>/", "<h1>About COPS " . VERSION . "</h1>", file_get_contents('about.html'));
         $out["fullhtml"] = $temp;
     }
     $out["homeurl"] = "index.php";
     if ($page != Base::PAGE_INDEX && !is_null($database)) {
         $out["homeurl"] = $out["homeurl"] . "?" . addURLParameter("", DB, $database);
     }
     return $out;
 }
示例#6
0
文件: fetch.php 项目: BreizhCat/cops
}
if ($book && ($type == "jpg" || empty($config['calibre_internal_directory']))) {
    if ($type == "jpg") {
        $file = $book->getFilePath($type);
    } else {
        $file = $book->getFilePath($type, $idData);
    }
    if (!$file || !file_exists($file)) {
        notFound();
        return;
    }
}
switch ($type) {
    case "jpg":
        header("Content-Type: image/jpeg");
        if ($book->getThumbnail(getURLParam("width"), getURLParam("height"))) {
            // The cover had to be resized
            return;
        }
        break;
    default:
        $data = $book->getDataById($idData);
        header("Content-Type: " . $data->getMimeType());
        break;
}
$file = $book->getFilePath($type, $idData, true);
if ($type == "epub" && $config['cops_update_epub-metadata']) {
    $book->getUpdatedEpub($idData);
    return;
}
if ($type == "jpg") {
示例#7
0
 if ($bot->weightBlocked < 0) {
     $errorHTML .= "<p/>Select Weight Blocked";
 }
 if ($bot->weightFaraway < 0) {
     $errorHTML .= "<p/>Select Weight Faraway";
 }
 if ($bot->weightSingle < 0) {
     $errorHTML .= "<p/>Select Weight Single";
 }
 if ($bot->roomGroupId == -1 || empty($bot->roomGroupId)) {
     $errorHTML .= "<p/>Select Room Group";
 }
 if (empty($user->userName)) {
     $errorHTML .= "<p/>Enter User Name";
 } else {
     $tmp_defu = getURLParam("defaultUserName");
     if ($tmp_defu != $user->userName) {
         $tmp = GameUsers::getGameUserByUserName($user->userName);
         if (!empty($tmp)) {
             $errorHTML .= "<p/>User Name already in use";
         }
     }
 }
 if (empty($user->userMail)) {
     $errorHTML .= "<p/>Enter User Mail";
 }
 if (empty($user->userFirstname)) {
     $errorHTML .= "<p/>Enter User First Name";
 }
 if (empty($user->userLastname)) {
     $errorHTML .= "<p/>Enter User Last Name";
示例#8
0
文件: epubfs.php 项目: BreizhCat/cops
        $out = "{$method}'epubfs.php?{$add}comp={$comp}{$hash}'{$end}";
        if ($end) {
            return $out;
        }
        return str_replace("&", "&amp;", $out);
    };
    $data = preg_replace_callback("/(src=)[\"']([^:]*?)[\"']/", $callback, $data);
    $data = preg_replace_callback("/(href=)[\"']([^:]*?)[\"']/", $callback, $data);
    $data = preg_replace_callback("/(\\@import\\s+)[\"'](.*?)[\"'];/", $callback, $data);
    $data = preg_replace_callback("/(src\\s*:\\s*url\\()(.*?)\\)/", $callback, $data);
    return $data;
}
if (php_sapi_name() === 'cli') {
    return;
}
$idData = getURLParam("data", NULL);
$add = "data={$idData}&";
if (!is_null(GetUrlParam(DB))) {
    $add .= DB . "=" . GetUrlParam(DB) . "&";
}
$myBook = Book::getBookByDataId($idData);
$book = new EPub($myBook->getFilePath("EPUB", $idData));
$book->initSpineComponent();
if (!isset($_GET["comp"])) {
    notFound();
    return;
}
$component = $_GET["comp"];
try {
    $data = getComponentContent($book, $component, $add);
    $expires = 60 * 60 * 24 * 14;
示例#9
0
文件: book.php 项目: ha-y/cops
 public static function getFilterString()
 {
     $filter = getURLParam("tag", NULL);
     if (empty($filter)) {
         return "";
     }
     $exists = true;
     if (preg_match("/^!(.*)\$/", $filter, $matches)) {
         $exists = false;
         $filter = $matches[1];
     }
     $result = "exists (select null from books_tags_link, tags where books_tags_link.book = books.id and books_tags_link.tag = tags.id and tags.name = '" . $filter . "')";
     if (!$exists) {
         $result = "not " . $result;
     }
     return "and " . $result;
 }
示例#10
0
            //deletes any partially created grade/year sub-combos...
            db_query($nq);
            $nq = str_replace('2000', $r->year, str_replace('05', $r->gradelevel, $q5));
            //creates grade/year sub-combo exception list...
            db_query($nq);
            echo (string) (intval(time()) - $strt) . "-  whole school filters added.\n<br>";
            ob_flush();
        }
        $i++;
    }
    $output .= " <br>  " . $i . " grades/years checked, " . $added . " grades/years processed (version b) ";
    echo $output;
    exit;
}
//end exceptions
$schId = getURLParam('clearfilters');
if ($schId) {
    db_set_active('isbe');
    $q = <<<UINQ
delete FROM isbefilters
UINQ;
    $rr = db_query($q);
    echo "All Filters have been deleted...";
    exit;
}
//end clearfilters
$colnames = <<<UINQ
[{"sTitle":"Filter","field":"filter"},{"sTitle":"Count","field":"cnt"}]
UINQ;
$q = "select filter, count(*) cnt from isbefilters group by filter";
$output .= makeDS("noreport", $q, $colnames, 'isbe');
示例#11
0
文件: fetch.php 项目: horus68/cops
         //check if cache folder exists or create it
         if (file_exists($thumbnailCacheFullpath) || mkdir($thumbnailCacheFullpath, 0700, true)) {
             //we name the thumbnail from the book's uuid and it's dimensions (width and/or height)
             $thumbnailCacheName = substr($book->uuid, 3) . '-' . getURLParam("width") . 'x' . getURLParam("height") . '.jpg';
             $thumbnailCacheFullpath = $thumbnailCacheFullpath . $thumbnailCacheName;
         } else {
             //error creating the folder, so we don't cache
             $thumbnailCacheFullpath = null;
         }
     }
     if ($thumbnailCacheFullpath !== null && file_exists($thumbnailCacheFullpath)) {
         //return the already cached thumbnail
         readfile($thumbnailCacheFullpath);
         return;
     }
     if ($book->getThumbnail(getURLParam("width"), getURLParam("height"), $thumbnailCacheFullpath)) {
         //if we don't cache the thumbnail, imagejpeg() in $book->getThumbnail() already return the image data
         if ($thumbnailCacheFullpath === null) {
             // The cover had to be resized
             return;
         } else {
             //return the just cached thumbnail
             readfile($thumbnailCacheFullpath);
             return;
         }
     }
     break;
 default:
     $data = $book->getDataById($idData);
     header("Content-Type: " . $data->getMimeType());
     break;
示例#12
0
文件: checkconfig.php 项目: ha-y/cops
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<?php 
/**
 * COPS (Calibre OPDS PHP Server) Configuration check
 *
 * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
 * @author     Sébastien Lucas <*****@*****.**>
 *
 */
require_once "config.php";
require_once "base.php";
header("Content-Type:text/html; charset=UTF-8");
$err = getURLParam("err", -1);
$full = getURLParam("full");
$error = NULL;
switch ($err) {
    case 1:
        $error = "Database error";
        break;
}
?>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>COPS Configuration Check</title>
    <link rel="stylesheet" type="text/css" href="<?php 
echo getUrlWithVersion(getCurrentCss());
?>
" media="screen" />
</head>
示例#13
0
文件: feed.php 项目: BreizhCat/cops
 */
require_once "config.php";
require_once "base.php";
require_once "author.php";
require_once "serie.php";
require_once "tag.php";
require_once "book.php";
require_once "OPDS_renderer.php";
header("Content-Type:application/xml");
$page = getURLParam("page", Base::PAGE_INDEX);
$query = getURLParam("query");
$n = getURLParam("n", "1");
if ($query) {
    $page = Base::PAGE_OPENSEARCH_QUERY;
}
$qid = getURLParam("id");
if ($config['cops_fetch_protect'] == "1") {
    session_start();
    if (!isset($_SESSION['connected'])) {
        $_SESSION['connected'] = 0;
    }
}
$OPDSRender = new OPDSRenderer();
switch ($page) {
    case Base::PAGE_OPENSEARCH:
        echo $OPDSRender->getOpenSearch();
        return;
    default:
        $currentPage = Page::getPage($page, $qid, $query, $n);
        $currentPage->InitializeContent();
        echo $OPDSRender->render($currentPage);
示例#14
0
    //this is a request for sch details...
    if ($schId != "q") {
        $q = <<<UINQ
\t\tselect * from
\t\t iamfroa5_cte.tblsitemaster where (9=9) limit 700
UINQ;
        $q = queryReplace9s($q, "schid='" . $schId . "'");
        $output .= makeDS("schDetails", $q);
        //ISBE...
        $cdts = db_result(db_query('select cdts from iamfroa5_cte.tblsitemaster where schid=' . $schId . " limit 1"));
        $searchStr = "cdts='" . $cdts . "'";
        $schName = db_result(db_query('select shortlabel from iamfroa5_cte.tblsitemaster where schid=' . $schId . " limit 1"));
    } else {
        //if schId is 'q' then this is an advanced search
        $searchStr = getURLParam('searchStr');
        $schName = getURLParam('name');
        $cdts = "NA";
    }
    $q = <<<UINQ
select h.*, q3pct+q4pct paaavg, 
    round(totalWarning/totalCount*100,1) awPct, round(totalBelow/totalCount*100,1) blPct, 
        round(totalMeet/totalCount*100,1) mtPct, round(totalExceed/totalCount*100,1) exPct, '{$cdts}' cdts,
            if(zp1.z is not null and zp2.z is not null,round((zscore-zp1.z)/(zp2.z-zp1.z)*(zp2.p-zp1.p)+zp1.p,1),0) percentileEquivalent,
    if(totalWarning13>0,round(totalWarning13/totalCount*100,1),null) awPct13, if(totalWarning13>0,round(totalBelow13/totalCount*100,1),null) blPct13, 
        if(totalWarning13>0,round(totalMeet13/totalCount*100,1),null) mtPct13, if(totalWarning13>0,round(totalExceed13/totalCount*100,1),null) exPct13,
            round(5.5+zscore*2,2) stanineEquivalent
 from (
select g.*,'8=8' q, 'PSAE' test,
  round((s9totToHere-totalNotMeeting)/s9totToHere*100,1) pme, s9totToHere totalCount,
  totalNotBelow totalWarning, totalNotMeeting-totalNotBelow totalBelow,totalNotExceeding-totalNotMeeting totalMeet, s9totToHere-totalNotExceeding totalExceed,
  if(totalNotMeeting13>0, round((s9totToHere-totalNotMeeting13)/s9totToHere*100,1),0) pme13,