OsCommerce (FAQ頁面)

出自ProgWiki
跳至導覽 跳至搜尋

功能

資料庫

set names 'big5';
 
CREATE TABLE IF NOT EXISTS `faq` (
  `id` int(11) NOT NULL auto_increment,
  `question` varchar(40) character set big5 NOT NULL,
  `answer` varchar(200) character set big5 NOT NULL,
  PRIMARY KEY  (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci AUTO_INCREMENT=1 ;

前台

info_faq.php

  • Path: \
  • 用途: 前台faq用頁面
<?php
 
	//本頁檔名
	define('thisPhpPage', 'info_faq.php');
 
	// osCommerce系統相關載入
	require('includes/application_top.php');
 
  	//載入語系檔
	require(DIR_WS_LANGUAGES . $language . '/' . thisPhpPage);
 
	//
	$breadcrumb->add(NAVBAR_TITLE, tep_href_link(thisPhpPage));
 
?>
 
<!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN">
 
<html <?php echo HTML_PARAMS; ?>>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=<?php echo CHARSET; ?>">
<title><?php echo TITLE; ?></title>
<base href="<?php echo (($request_type == 'SSL') ? HTTPS_SERVER : HTTP_SERVER) . DIR_WS_CATALOG; ?>">
<link rel="stylesheet" type="text/css" href="stylesheet.css">
</head>
 
<body marginwidth="0" marginheight="0" topmargin="0" bottommargin="0" leftmargin="0" rightmargin="0">
 
<!-- header //-->
 
<?php require(DIR_WS_INCLUDES . 'header.php'); ?>
 
<!-- header_eof //-->
 
 
 
<!-- body //-->
 
<table border="0" width="100%" cellspacing="3" cellpadding="3">
 
  <tr>
 
    <td width="<?php echo BOX_WIDTH; ?>" valign="top"><table border="0" width="<?php echo BOX_WIDTH; ?>" cellspacing="0" cellpadding="2">
 
<!-- left_navigation //-->
 
<?php require(DIR_WS_INCLUDES . 'column_left.php'); ?>
 
<!-- left_navigation_eof //-->
 
    </table></td>
 
 
 
<!-- body_text //-->
 
<td width="100%" valign="top"><table border="0" width="100%" cellspacing="0" cellpadding="0">
      <tr>
        <td><table border="0" width="100%" cellspacing="0" cellpadding="0">
          <tr>
            <td class="pageHeading"><?php echo HEADING_TITLE; ?></td>
            <td class="pageHeading" align="right"> </td>
          </tr>
        </table></td>
      </tr>
      <tr>
        <td><?php echo tep_draw_separator('pixel_trans.gif', '100%', '10'); ?></td>
      </tr>
      <tr>
        <td>
		<br>
 
		<table>
 
		<tr><td>
 
<?php
 
//	建置中...
 
	//亂碼修正
	mysql_query("SET NAMES 'big5'");
 
	$Faq_sql = "SELECT id,question FROM faq ORDER BY id";
 
	$Faq_query = tep_db_query($Faq_sql);
 
	$number_of_Faq = tep_db_num_rows($Faq_query);
 
    $rows = 0;
 
	echo '<ol>' ."\n";
 
    while ($Faq = tep_db_fetch_array($Faq_query)) {
 
      $rows++;
 
      if  ($rows <= $number_of_Faq)
	  {
 
		echo '<li class="smallText"><a href="' . tep_href_link(thisPhpPage) . '#q'. $Faq['id'] . '">' . $Faq['question'] . "</a></li>\n";
 
      }
 
    }
 
	echo '</ol>' ."\n";
 
?>
 
<br><hr/><br>
 
<?php
 
	$Faq_sql = "SELECT id,question,answer FROM faq ORDER BY id";
 
	$Faq_query = tep_db_query($Faq_sql);
 
	$number_of_Faq = tep_db_num_rows($Faq_query);
 
    $rows = 0;
 
    while ($Faq = tep_db_fetch_array($Faq_query)) {
 
      $rows++;
 
      if  ($rows <= $number_of_Faq)
 
	  {
 
		echo '<a name="q'. $Faq['id'] . '"></a>'."\n";
 
		echo '<h3>' . TEXT_Q . $Faq['question'] . "</h3>\n";
 
		echo TEXT_A. '<br>';
 
		echo '<blockquote>'. $Faq['answer'] . "</blockquote><br>\n";
 
		echo '<br/><hr>' ."\n";
 
      }
    }
?>
 
		</td></tr>
		</td>
	  </tr>
	  </table>
</td>	  
 
<!-- body_text_eof //-->
 
 
 
 
    <td width="<?php echo BOX_WIDTH; ?>" valign="top"><table border="0" width="<?php echo BOX_WIDTH; ?>" cellspacing="0" cellpadding="2">
 
<!-- right_navigation //-->
<?php
//亂碼修正
mysql_query("SET NAMES 'latin1'");
?>
<?php require(DIR_WS_INCLUDES . 'column_right.php'); ?>
 
<!-- right_navigation_eof //-->
 
    </table></td>
 
  </tr>
 
</table>
 
<!-- body_eof //-->
 
 
 
<!-- footer //-->
 
<?php require(DIR_WS_INCLUDES . 'footer.php'); ?>
 
<!-- footer_eof //-->
 
<br>
 
</body>
 
</html>
 
<?php require(DIR_WS_INCLUDES . 'application_bottom.php'); ?>

info_faq.php

  • Path: \includes\languages\tchinese
  • 用途: 語系檔
<?php
 
define('HEADING_TITLE', 'Q&A');
 
define('NAVBAR_TITLE', 'Q&A');
 
define('TEXT_Q', '問:');
 
define('TEXT_A', '答:');
 
 
?>

information.php

  • Path: \includes\boxes
  • 用途: 服務台BOX
<?php
 
/*
 
  $Id: information.php,v 1.1.1.1 2003/08/14 08:00:08 nickle Exp $
 
 
 
  osCommerce, Open Source E-Commerce Solutions
 
  http://www.oscommerce.com
 
 
 
  Copyright (c) 2003 osCommerce
 
 
 
  Released under the GNU General Public License
 
*/
 
?>
 
<!-- information //-->
 
          <tr>
 
            <td>
 
<?php
 
  $info_box_contents = array();
 
  $info_box_contents[] = array('text' => BOX_HEADING_INFORMATION);
 
  new infoBoxHeading($info_box_contents, false, false);
 
  $info_box_contents = array();
 
  $info_box_contents[] = array('text' =>
 
        '<a class="hs_service" href="' . tep_href_link('info_faq.php') . '">' . 'Q&A' . '</a><br>' .
        '<a href="' . tep_href_link(FILENAME_SHIPPING) . '">' . BOX_INFORMATION_SHIPPING . '</a><br>' .
        '<a href="' . tep_href_link(FILENAME_PRIVACY) . '">' . BOX_INFORMATION_PRIVACY . '</a><br>' .
        '<a href="' . tep_href_link(FILENAME_CONDITIONS) . '">' . BOX_INFORMATION_CONDITIONS . '</a><br>' .
        '<a href="' . tep_href_link(FILENAME_CONTACT_US) . '">' . BOX_INFORMATION_CONTACT . '</a>');
 
  new infoBox($info_box_contents);
 
?>
 
            </td>
 
          </tr>
 
<!-- information_eof //-->

後台

info_faq.php

  • Path: \admin
  • 用途: 後台頁面
<?php
 
$thisPhpPage = 'info_faq.php';
 
$thisTableName = 'faq';
 
//id,question,answer
 
 
  require('includes/application_top.php');
 
 
 
//亂碼修正
 
	mysql_query("SET NAMES 'big5'");  
 
 
 
  $action = (isset($HTTP_GET_VARS['action']) ? $HTTP_GET_VARS['action'] : '');
 
 
 
  if (tep_not_null($action)) {
 
    switch ($action) {
 
      case 'insert':
 
      case 'save':
 
        if (isset($HTTP_GET_VARS['id'])) $id = tep_db_prepare_input($HTTP_GET_VARS['id']);
 
        $question = tep_db_prepare_input($HTTP_POST_VARS['question']);
 
		$answer = tep_db_prepare_input($HTTP_POST_VARS['answer']);
 
        $sql_data_array = array('question' => $question, 'answer' => $answer);
 
        if ($action == 'insert') {
 
          tep_db_perform($thisTableName, $sql_data_array);
 
          $id = tep_db_insert_id();
 
        } elseif ($action == 'save') {
 
          tep_db_perform($thisTableName, $sql_data_array, 'update', "id = '" . (int)$id . "'");
 
        }
 
        tep_redirect(tep_href_link($thisPhpPage, (isset($HTTP_GET_VARS['page']) ? 'page=' . $HTTP_GET_VARS['page'] . '&' : '') . 'id=' . $id));
 
        break;
 
      case 'deleteconfirm':
 
        $id = tep_db_prepare_input($HTTP_GET_VARS['id']);
 
        tep_db_query("delete from " . $thisTableName . " where id = '" . (int)$id . "'");
 
        tep_redirect(tep_href_link($thisPhpPage, 'page=' . $HTTP_GET_VARS['page']));
 
        break;
 
    }
 
  }
 
?>
 
<!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN">
 
<html <?php echo HTML_PARAMS; ?>>
 
<head>
 
<meta http-equiv="Content-Type" content="text/html; charset=<?php echo CHARSET; ?>">
 
<title><?php echo TITLE; ?></title>
 
<link rel="stylesheet" type="text/css" href="includes/stylesheet.css">
 
<script language="javascript" src="includes/general.js"></script>
 
</head>
 
<body marginwidth="0" marginheight="0" topmargin="0" bottommargin="0" leftmargin="0" rightmargin="0" bgcolor="#FFFFFF" onload="SetFocus();">
 
<!-- header //-->
 
<?php require(DIR_WS_INCLUDES . 'header.php'); ?>
 
<!-- header_eof //-->
 
 
 
<!-- body //-->
 
<table border="0" width="100%" cellspacing="2" cellpadding="2">
 
  <tr>
 
    <td width="<?php echo BOX_WIDTH; ?>" valign="top"><table border="0" width="<?php echo BOX_WIDTH; ?>" cellspacing="1" cellpadding="1" class="columnLeft">
 
<!-- left_navigation //-->
 
<?php require(DIR_WS_INCLUDES . 'column_left.php'); ?>
 
<!-- left_navigation_eof //-->
 
    </table></td>
 
<!-- body_text //-->
 
    <td width="100%" valign="top"><table border="0" width="100%" cellspacing="0" cellpadding="2">
 
      <tr>
 
        <td width="100%"><table border="0" width="100%" cellspacing="0" cellpadding="0">
 
          <tr>
 
            <td class="pageHeading"><?php echo HEADING_TITLE; ?></td>
 
            <td class="pageHeading" align="right"><?php echo tep_draw_separator('pixel_trans.gif', HEADING_IMAGE_WIDTH, HEADING_IMAGE_HEIGHT); ?></td>
 
          </tr>
 
        </table></td>
 
      </tr>
 
      <tr>
 
        <td><table border="0" width="100%" cellspacing="0" cellpadding="0">
 
          <tr>
 
            <td valign="top"><table border="0" width="100%" cellspacing="0" cellpadding="2">
 
              <tr class="dataTableHeadingRow">
 
                <td class="dataTableHeadingContent"><?php echo TABLE_HEADING; ?></td>
 
                <td class="dataTableHeadingContent" align="right"><?php echo TABLE_HEADING_ACTION; ?>&nbsp;</td>
 
              </tr>
 
<?php
 
  $faq_query_raw = "select id, question, answer from " . $thisTableName . " order by question";
 
  $faq_split = new splitPageResults($HTTP_GET_VARS['page'], MAX_DISPLAY_SEARCH_RESULTS, $faq_query_raw, $faq_query_numrows);
 
  $faq_query = tep_db_query($faq_query_raw);
 
//echo   print_r($faq_query);
 
  while ($faq = tep_db_fetch_array($faq_query)) {
 
    if ((!isset($HTTP_GET_VARS['id']) || (isset($HTTP_GET_VARS['id']) && ($HTTP_GET_VARS['id'] == $faq['id']))) && !isset($mInfo) && (substr($action, 0, 3) != 'new')) {
 
	  $mInfo_array = $faq;
 
      $mInfo = new objectInfo($mInfo_array);
 
    }
 
 
    if (isset($mInfo) && is_object($mInfo) && ($faq['id'] == $mInfo->id)) {
 
      echo '              <tr id="defaultSelected" class="dataTableRowSelected" onmouseover="rowOverEffect(this)" onmouseout="rowOutEffect(this)" onclick="document.location.href=\'' . tep_href_link($thisPhpPage, 'page=' . $HTTP_GET_VARS['page'] . '&id=' . $faq['id'] . '&action=edit') . '\'">' . "\n";
 
    } else {
 
      echo '              <tr class="dataTableRow" onmouseover="rowOverEffect(this)" onmouseout="rowOutEffect(this)" onclick="document.location.href=\'' . tep_href_link($thisPhpPage, 'page=' . $HTTP_GET_VARS['page'] . '&id=' . $faq['id']) . '\'">' . "\n";
 
    }
 
?>
 
                <td class="dataTableContent"><?php echo $faq['question']; ?></td>
 
                <td class="dataTableContent" align="right">
 
				<?php
					echo '<a href="' . tep_href_link($thisPhpPage, 'page=' . $HTTP_GET_VARS['page'] . '&id=' . $faq['id']) . '">' . tep_image(DIR_WS_IMAGES . 'icon_info.gif', IMAGE_ICON_INFO) . '</a>'; 
				?>
 
				&nbsp;</td>
 
              </tr>
 
<?php
 
  }
 
?>
 
              <tr>
 
                <td colspan="2"><table border="0" width="100%" cellspacing="0" cellpadding="2">
 
                  <tr>
 
                    <td class="smallText" valign="top"><?php
 
						echo $faq_split->display_count($faq_query_numrows, MAX_DISPLAY_SEARCH_RESULTS, $HTTP_GET_VARS['page'], TEXT_DISPLAY_NUMBER_OF_FAQ); 
 
					?></td>
 
                    <td class="smallText" align="right"><?php 
 
						echo $faq_split->display_links($faq_query_numrows, MAX_DISPLAY_SEARCH_RESULTS, MAX_DISPLAY_PAGE_LINKS, $HTTP_GET_VARS['page']); 
 
					?></td>
 
                  </tr>
 
                </table></td>
 
              </tr>
 
<?php
 
  if (empty($action)) {
 
?>
 
              <tr>
 
                <td align="right" colspan="2" class="smallText">
 
				<?php
 
					echo '<a href="' . tep_href_link($thisPhpPage, 'page=' . $HTTP_GET_VARS['page'] . '&id=' . $mInfo->id . '&action=new') . '">' . tep_image_button('button_insert.gif', IMAGE_INSERT) . '</a>'; 
 
				?></td>
 
              </tr>
 
<?php
 
  }
 
?>
 
            </table></td>
 
<?php
 
  $heading = array();
 
  $contents = array();
 
 
 
  switch ($action) {
 
    case 'new':
 
      $heading[] = array('text' => '<b>' . TEXT_HEADING_NEW . '</b>');
 
 
 
      $contents = array('form' => tep_draw_form($thisTableName, $thisPhpPage, 'action=insert', 'post', 'enctype="multipart/form-data"'));
 
      $contents[] = array('text' => TEXT_NEW_INTRO);
 
      $contents[] = array('text' => '<br>' . TEXT_Question . '<br>' . tep_draw_input_field('question'));
 
	  $contents[] = array('text' => '<br>' . TEXT_Answer . '<br>' . tep_draw_textarea_field('answer', 'soft', '60', '20', ''));
 
      $contents[] = array('align' => 'center', 'text' => '<br>' . tep_image_submit('button_save.gif', IMAGE_SAVE) . ' <a href="' . tep_href_link($thisPhpPage, 'page=' . $HTTP_GET_VARS['page'] . '&id=' . $HTTP_GET_VARS['id']) . '">' . tep_image_button('button_cancel.gif', IMAGE_CANCEL) . '</a>');
 
      break;
 
    case 'edit':
 
      $heading[] = array('text' => '<b>' . TEXT_HEADING_EDIT . '</b>');
 
 
 
      $contents = array('form' => tep_draw_form($thisTableName, $thisPhpPage, 'page=' . $HTTP_GET_VARS['page'] . '&id=' . $mInfo->id . '&action=save', 'post', 'enctype="multipart/form-data"'));
 
      $contents[] = array('text' => TEXT_EDIT_INTRO);
 
	  $contents[] = array('text' => '<br>' . TEXT_Question . '<br>' . tep_draw_input_field('question', $mInfo->question));
 
	  $contents[] = array('text' => '<br>' . TEXT_Answer . '<br>' . tep_draw_textarea_field('answer', 'soft', '60', '20', $mInfo->answer));
 
      $contents[] = array('align' => 'center', 'text' => '<br>' . tep_image_submit('button_save.gif', IMAGE_SAVE) . ' <a href="' . tep_href_link($thisPhpPage, 'page=' . $HTTP_GET_VARS['page'] . '&id=' . $mInfo->id) . '">' . tep_image_button('button_cancel.gif', IMAGE_CANCEL) . '</a>');
 
      break;
 
    case 'delete':
 
      $heading[] = array('text' => '<b>' . TEXT_HEADING_DELETE . '</b>');
 
      $contents = array('form' => tep_draw_form($thisTableName, $thisPhpPage, 'page=' . $HTTP_GET_VARS['page'] . '&id=' . $mInfo->id . '&action=deleteconfirm'));
 
      $contents[] = array('text' => TEXT_DELETE_INTRO);
 
      $contents[] = array('text' => '<br><b>' . $mInfo->question . '</b>');
 
	  $contents[] = array('text' => '<br><b>' . $mInfo->answer . '</b>');
 
      $contents[] = array('align' => 'center', 'text' => '<br>' . tep_image_submit('button_delete.gif', IMAGE_DELETE) . ' <a href="' . tep_href_link($thisPhpPage, 'page=' . $HTTP_GET_VARS['page'] . '&id=' . $mInfo->id) . '">' . tep_image_button('button_cancel.gif', IMAGE_CANCEL) . '</a>');
 
      break;
 
    default:
 
      if (isset($mInfo) && is_object($mInfo)) {
 
        $heading[] = array('text' => '<b>' . $mInfo->question  . '</b>');
 
        $contents[] = array(
 
			'align' => 'left',//'center',
 
			'text' => $mInfo->answer  . '<br>'
 
				.'<center><a href="' . tep_href_link($thisPhpPage, 'page=' . $HTTP_GET_VARS['page'] . '&id=' . $mInfo->id . '&action=edit') . '">' . tep_image_button('button_edit.gif', IMAGE_EDIT) . '</a> <a href="' . tep_href_link($thisPhpPage, 'page=' . $HTTP_GET_VARS['page'] . '&id=' . $mInfo->id . '&action=delete') . '">' . tep_image_button('button_delete.gif', IMAGE_DELETE) . '</a></center>');
 
      }
 
      break;
 
  }
 
 
 
  if ( (tep_not_null($heading)) && (tep_not_null($contents)) ) {
 
    echo '            <td width="25%" valign="top">' . "\n";
 
    $box = new box;
 
    echo $box->infoBox($heading, $contents);
 
    echo '            </td>' . "\n";
 
  }
 
?>
 
          </tr>
 
        </table></td>
 
      </tr>
 
    </table></td>
 
<!-- body_text_eof //-->
 
  </tr>
 
</table>
 
<!-- body_eof //-->
 
 
 
<!-- footer //-->
 
<?php require(DIR_WS_INCLUDES . 'footer.php'); ?>
 
<!-- footer_eof //-->
 
<br>
 
</body>
 
</html>
 
<?php require(DIR_WS_INCLUDES . 'application_bottom.php'); ?>

info_faq.php

  • Path: \admin\includes\languages\tchinese
  • 用途: 後台頁面語系檔
<?php
 
define('HEADING_TITLE', 'Q&A');
 
define('TABLE_HEADING', 'Q&A');
 
define('TABLE_HEADING_ACTION', '動作');
 
define('TEXT_HEADING_NEW', '新增Q&A');
 
define('TEXT_HEADING_EDIT', '編輯Q&A');
 
define('TEXT_HEADING_DELETE', '刪除Q&A');
 
define('TEXT_Question', '問:');
 
define('TEXT_Answer', '答:');
 
define('TEXT_NEW_INTRO', '請填入新Q&A的相關資料');
 
define('TEXT_EDIT_INTRO', '請做適當修改');
 
define('TEXT_DELETE_INTRO', '確定要刪除這個Q&A?');
 
define('TEXT_DISPLAY_NUMBER_OF_FAQ', '顯示 <b>%d</b> 到 <b>%d</b> (共 <b>%d</b> 個Q&A)');
 
?>

info.php

  • Path: \admin\includes\boxes
  • 用途: 後台服務台BOX
<!-- catalog //-->
          <tr>
            <td>
<?php
 
  $heading = array();
 
  $contents = array();
 
 
 
  $heading[] = array('text'  => '服務台',
 
                     'link'  => tep_href_link(basename($PHP_SELF), tep_get_all_get_params(array('selected_box')) . 'selected_box=info'));
 
 
 
  if ($selected_box == 'info') {
 
    $contents[] = array('text'  => 
			tep_admin_files_boxes('info_faq.php', 'Q&A') 
 
		);
 
  }
 
 
  $box = new box;
 
  echo $box->menuBox($heading, $contents);
 
?>
 
            </td>
          </tr>
 
<!-- catalog_eof //-->

後台設定

  • 使用phpmyadmin 去做(少了這個的話, 後台的"服務台BOX"會出不來
set names 'big5';
 
INSERT INTO `admin_files` (`admin_files_id`, `admin_files_name`, `admin_files_is_boxes`, `admin_files_to_boxes`, `admin_groups_id`) VALUES
(43, 'info.php', 1, 0, '1'),
(44, 'info_faq.php', 0, 43, '1');