コード例 #1
0
ファイル: functions.php プロジェクト: mark-orussa/Adrlist
function buildFaqPopupContent()
{
    // DEPRECATED. FAQ links now open in a new window/tab.
    //Build the content for the floating faq box.
    global $debug, $message, $success, $Dbc, $returnThis;
    $output = '';
    try {
        if (empty($_POST['qId'])) {
            throw new Adrlist_CustomException('', '$_POST[\'qId\'] is not set.');
        }
        if (!is_numeric($_POST['qId'])) {
            throw new Adrlist_CustomException('', '$_POST[\'qId\'] is not numeric.');
        }
        $stmt = $Dbc->prepare("SELECT\n\tfaqs.q AS 'question',\n\tfaqs.a AS 'answer',\n\tfaqs.faqId AS 'faqId'\nFROM\n\tfaqs\nWHERE\n\tfaqs.faqId = ?");
        $stmt->execute(array($_POST['qId']));
        $row = $stmt->fetch(PDO::FETCH_ASSOC);
        if (empty($row)) {
            throw new Adrlist_CustomException('Couldn\'t find a FAQ associated with this question.', 'The statement returned zero rows.');
        }
        $output .= '<a href="#" data-rel="back" class="ui-btn ui-corner-all ui-shadow ui-btn-b ui-icon-delete ui-btn-icon-notext ui-btn-right">Close</a>
<div class="bold textLarge" style="margin:1em">' . $row['question'] . '</div>
	<div class="hr2"></div>
	<div class="textLeft" style="line-height:1.5em;margin:1em">
		' . nl2br($row['answer'], 1) . '
	</div>
	<div class="hr2"></div>
	<div class="textCenter">
		<a class="ui-btn ui-btn-inline ui-corner-all ui-mini" href="' . LINKFAQ . '" target="new">View all FAQs<i style="margin-left:.5em" class="fa fa-external-link"></i></a><a style="text-decoration:none" class="ui-btn ui-btn-inline ui-corner-all ui-shadow ui-btn-icon-right ui-icon-delete ui-btn-b ui-mini" data-rel="back">Close</a>
	</div>
</div>';
        $success = true;
        $returnThis['output'] = convertFaqLink($output);
    } catch (Adrlist_CustomException $e) {
    } catch (PDOException $e) {
        error(__LINE__, '', '<pre>' . $e . '</pre>');
    }
    if (MODE == 'buildFaqPopupContent') {
        returnData();
    }
}
コード例 #2
0
ファイル: faqMethods.php プロジェクト: mark-orussa/Adrlist
function buildFaqs()
{
    //This gets FAQs with and without searching.
    global $debug, $message, $success, $Dbc, $returnThis;
    $output = '';
    try {
        $faqQuery = "SELECT\n\tfaqs.faqId AS 'faqId',\n\tfaqs.q AS 'q',\n\tfaqs.a AS 'a',\n\tfaqTopics.topicId AS 'topicId',\n\tfaqTopics.topic AS 'topic'\nFROM\n\tfaqs\nJOIN\n\tfaqTopics ON faqTopics.topicId = faqs.topicId AND\n\tfaqs.hidden = '0'\n";
        if (empty($_POST['searchVal'])) {
            $search = false;
            $stmt = $Dbc->query($faqQuery . "\nORDER BY\n\tfaqTopics.topic");
            $faqCountStmt = $Dbc->query("SELECT COUNT(*) AS 'count' FROM faqs WHERE hidden = 0");
        } else {
            $search = true;
            $searchVal = '%' . trim($_POST['searchVal']) . '%';
            $faqSearchQuery = "\n AND (faqTopics.topic LIKE ? || faqs.q LIKE ? || faqs.a LIKE ?)\nGROUP BY\n\tfaqs.faqId";
            $stmt = $Dbc->prepare($faqQuery . $faqSearchQuery);
            $stmt->execute(array($searchVal, $searchVal, $searchVal));
            $faqCountStmt = $Dbc->prepare("SELECT COUNT(*) AS 'count' FROM faqs JOIN\n\tfaqTopics ON faqTopics.topicId = faqs.topicId AND\n\tfaqs.hidden = '0'" . $faqSearchQuery);
            $faqCountStmt->execute(array($searchVal, $searchVal, $searchVal));
        }
        $row = $faqCountStmt->fetch(PDO::FETCH_ASSOC);
        $itemCount = empty($row['count']) ? 0 : $row['count'];
        $debug->add('$itemCount: ' . $itemCount);
        $success = true;
        $lastTopic = '';
        $topicNumber = 0;
        $foundRows = false;
        $rowsArray = array();
        while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
            $foundRows = true;
            $question = convertFaqLink($row['q']);
            $answer = convertFaqLink($row['a']);
            $currentTopic = $row['topic'];
            if ($currentTopic != $lastTopic) {
                $topicNumber++;
                $lastTopic = $currentTopic;
            }
            $rowsArray[$currentTopic][] = array('<div class="faq hand" faqid="' . $row['faqId'] . '">
	<div class="faqQuestion" id="faq' . $row['faqId'] . '" toggle="faqAnswer' . $row['faqId'] . '">' . nl2br($question, 1) . ' <span class="faqId">FAQ #' . $row['faqId'] . '</span></div>
	<div class="faqAnswer textLeft" id="faqAnswer' . $row['faqId'] . '">' . nl2br($answer, 1) . '</div>
</div>
');
        }
        //$debug->printArray($rowsArray,'$rowsArray');
        $cssWidths = array('100%');
        $temp = $search ? '<div class="red textCenter">Results for "' . $_POST['searchVal'] . '"</div>' : '';
        foreach ($rowsArray as $key => $value) {
            $temp .= '<div class="sectionTitle textCenter">' . $key . '</div>
';
            $faqRows = new Adrlist_BuildRows('faqs', '', $value, false);
            $temp .= $faqRows->output();
        }
        $pagination = new Adrlist_Pagination('buildFaqs', 'buildFaqs', $itemCount, 'Search FAQs', $search);
        $pagination->_searchOnly();
        $output .= '<div class="textCenter">
	Click on a topic to view FAQs
	<div class="break" style="margin:1em">
		<button class="ui-btn ui-btn-inline ui-btn-a ui-shadow ui-corner-all" id="faqHideAll" data-role="false">Hide All</button><button class="ui-btn ui-btn-inline ui-btn-a ui-shadow ui-corner-all" id="faqShowAll" data-role="false">Show All</button>
	</div>
</div>
' . $pagination->output() . $temp;
        if (empty($foundRows)) {
            pdoError(__LINE__, $stmt, $params = false, true);
            if ($search) {
                $output .= '<div class="red textCenter" style="margin:1em">There were no matches for ' . $_POST['searchVal'] . '.</div>';
            } else {
                $output .= '<div class="break" style="padding:5px 0px 10px 0px;">
There are no faqs to show.
</div>		
';
                //		<span class="buttonBlueThin" id="faqHideAll">Hide All</span><span class="buttonBlueThin" id="faqShowAll">Show All</button>
            }
        }
        $returnThis['holder'] = 'buildFaqsHolder';
        $returnThis['output'] = $output;
        $returnThis['buildFaqs'] = $output;
    } catch (PDOException $e) {
        error(__LINE__, '', '<pre>' . $e . '</pre>');
    }
    if (MODE == 'buildFaqs') {
        returnData();
    } else {
        return $output;
    }
}