function process_request($request)
 {
     $rqsts = explode('_', strtolower($request));
     $qa_content = qa_content_prepare();
     //$qa_content['title']=qa_lang_html('example_page/page_title');
     //$qa_content['error']='An example error'."\n";
     $qa_content['title'] = ' 资料下载';
     $qa_content['custom'] = '<link href="' . $this->urltoroot . 'downpage.css" rel="stylesheet" type="text/css" />' . "\n";
     //$qa_content['custom'].='Some <B>custom html</B>'."\n";
     //
     /*
     			$qa_content['form']=array(
     				'tags' => 'METHOD="POST" ACTION="'.qa_self_html().'"',
     				
     				'style' => 'wide',
     				
     				'ok' => qa_post_text('okthen') ? 'You clicked OK then!' : null,
     				
     				'title' => 'Form title',
     				
     				'fields' => array(
     					'request' => array(
     						'label' => 'The request',
     						'tags' => 'NAME="request"',
     						'value' => qa_html($request),
     						'error' => qa_html('Another error'),
     					),
     					
     				),
     				
     				'buttons' => array(
     					'ok' => array(
     						'tags' => 'NAME="okthen"',
     						'label' => 'OK then',
     						'value' => '1',
     					),
     				),
     				
     				'hidden' => array(
     					'hiddenfield' => '1',
     				),
     			);
     */
     //$qa_content['custom_2']='<P><BR>More <I>custom html</I></P>';
     require_once $this->urltoroot . 'downloadhtml.php';
     $qa_content['custom_2'] = setDownloadHtml($rqsts, $this->urltoroot);
     //$qa_content['custom_2']=$this->urltoroot;
     return $qa_content;
 }
Exemple #2
0
function setDownloadHtml($requests, $root)
{
    $rqsts = $requests;
    $pagetype = 'main';
    $csvroot = $root . 'items\\csv\\books.csv';
    //return $root;
    /*下面用于判断请求页的类型*/
    if (isset($rqsts[1])) {
        if (preg_match('/^main$/', $rqsts[1])) {
            $pagetype = 'main';
        } else {
            if (preg_match('/^list[\\d]*$/', $rqsts[1])) {
                $pagetype = 'list';
            } else {
                if (preg_match('/^item[\\d]*$/', $rqsts[1]) || preg_match('/^[\\d]+$/', $rqsts[1])) {
                    //return 'item';
                    $pagetype = 'item';
                    //return $pagetype;
                } else {
                    $pagetype = 'main';
                }
            }
        }
    } else {
        $pagetype = 'main';
    }
    /*下面来拉接主页的html*/
    if ($pagetype == 'main') {
        $rqsts[1] = 'list1';
        return setDownloadHtml($rqsts, $root);
    } else {
        if ($pagetype == 'list') {
            $listpage = str_replace('list', '', $rqsts[1]);
            if ($listpage <= 0) {
                $listpage = 1;
            }
            $fp = new SplFileObject($csvroot, 'r');
            $fp_lines = getLines($fp);
            //得到总行数,由于数组从0开始,所以只要显示1到$fp_lines即可(第0行是表头)
            //$fp->fgetcsv(',','')
            //$fp->fg
            $html = setlistNav($listpage);
            $html .= setItemslist($fp_lines, $listpage, $fp, $root);
            $html .= setlistNav($listpage);
            return $html;
        } else {
            if ($pagetype == 'item') {
                //$itemnum = preg_split('item', $rqsts[1])[0];
                $itemnum = $rqsts[1];
                $file = fopen($csvroot, 'r');
                while (!feof($file)) {
                    $iteminfos = explode(',', trim(fgets($file)));
                    if ($iteminfos[0] == $itemnum) {
                        break;
                    }
                }
                $item_exist = !feof($file);
                fclose($file);
                if ($item_exist) {
                    //把各个参数设置
                    $itemid = isset($iteminfos[0]) ? $iteminfos[0] : '';
                    //物品ID
                    $itemtitle = isset($iteminfos[1]) ? $iteminfos[1] : '';
                    //数目标题
                    $itemchntitle = isset($iteminfos[2]) ? $iteminfos[2] : '';
                    //中文标题
                    $itempic = isset($iteminfos[3]) ? $iteminfos[3] : '';
                    //物品图片文件名
                    //if(!file_exists($root.'items\imgs\\'.$itempic))$itempic='abc';
                    $itempic = file_exists($root . 'items/imgs/' . $itempic) ? $root . 'items/imgs/' . $itempic : $root . 'items/imgs/NoPic.gif';
                    $itempublisher = isset($iteminfos[4]) ? $iteminfos[4] : '';
                    //出版商
                    $itemauthor = isset($iteminfos[5]) ? $iteminfos[5] : '';
                    //作者
                    $itempages = isset($iteminfos[6]) ? $iteminfos[6] : '';
                    //页码数
                    $itemisbn = isset($iteminfos[7]) ? $iteminfos[7] : '';
                    //isbn
                    $itemtag_string = isset($iteminfos[8]) ? $iteminfos[8] : '';
                    //标签原始字符串用"|"分割
                    $itemurl_string = isset($iteminfos[9]) ? $iteminfos[9] : '';
                    //下载链接原始字符串用"|"分割
                    $itemtags = explode('|', $itemtag_string);
                    $itemurls = explode('|', $itemurl_string);
                    $adver1 = '<script type="text/javascript">var sogou_ad_id=60486;var sogou_ad_height=60;var sogou_ad_width=640;</script><script language="JavaScript" type="text/javascript" src="http://images.sohu.com/cs/jsfile/js/c.js"></script>';
                    $html = '<TABLE class="allinfo" cellSpacing="0" cellPadding="0" width="700">' . "\n";
                    $html .= '<TR>' . "\n";
                    $html .= '<TD class="pictd" rowSpan="4">' . "\n";
                    $html .= '<DIV>' . "\n";
                    $html .= '<CENTER>' . "\n";
                    $html .= '<IMG title="' . $itemtitle . '" alt="' . $itemtitle . '" src="' . $itempic . '">' . "\n";
                    $html .= '</CENTER>' . "\n";
                    $html .= '</DIV>' . "\n";
                    $html .= '</TD>' . "\n";
                    $html .= '<TD style="width: 580px;">' . "\n";
                    $html .= '<DIV class="title">' . $itemtitle . '</DIV>' . "\n";
                    $html .= '<DIV class="chinesetitle">中文书名:' . $itemchntitle . '</DIV>' . "\n";
                    $html .= '</TD>' . "\n";
                    $html .= '</TR>' . "\n";
                    $html .= '<TR>' . "\n";
                    $html .= '<TD><SPAN class="author">作者:</SPAN><SPAN class="author">' . $itemauthor . '</SPAN></TD>' . "\n";
                    $html .= '</TR>' . "\n";
                    $html .= '<TR>' . "\n";
                    $html .= '<TD><SPAN>出版社:</SPAN><SPAN>' . $itempublisher . '</SPAN></TD>' . "\n";
                    $html .= '</TR>' . "\n";
                    $html .= '<TR>' . "\n";
                    $html .= '<TD style="text-align: left; color: rgb(50, 124, 142); font-size: 13px;">资料标签:';
                    for ($i = 0; isset($itemtags[$i]); $i++) {
                        $html .= $itemtags[$i] . ' ';
                    }
                    $html .= '</TD>' . "\n";
                    $html .= '</TR>' . "\n";
                    $html .= '<TR>' . "\n";
                    $html .= '<TD style="text-align: left; color: rgb(50, 124, 142); font-size: 13px;" colSpan="2">' . "\n";
                    $html .= '<TABLE cellSpacing="0" cellPadding="0">' . "\n";
                    $html .= '<TR>' . "\n";
                    $html .= '<TD style="width: 100px; text-align: center; vertical-align: middle;">' . "\n";
                    $html .= '<DIV style="float: left;" class="downloadtext">下载链接:</DIV>' . "\n";
                    $html .= '</TD>' . "\n";
                    $html .= '<TD>' . "\n";
                    $html .= '<DIV class="downloadtext1">第一次下载请务必了解<A href="#ins">下载说明</A>。</DIV>' . "\n";
                    $html .= '<DIV><!-- 广告位 -->' . $adver1 . '</DIV>' . "\n";
                    $html .= '<SPAN class="downlink">' . "\n";
                    for ($i = 0; isset($itemurls[$i]); $i++) {
                        $html .= '<A href="' . $itemurls[$i] . '"target="_blank">下载地址' . ($i + 1) . '</A> ' . "\n";
                    }
                    $html .= '</SPAN>' . "\n";
                    $html .= '</TD>' . "\n";
                    $html .= '</TR>' . "\n";
                    $html .= '</TABLE>' . "\n";
                    $html .= '</TD>' . "\n";
                    $html .= '</TR>' . "\n";
                    $html .= '<TR>' . "\n";
                    $html .= '<TD colSpan="2">' . "\n";
                    $html .= '<DIV style="margin: 20px; padding: 20px; border: 2px solid rgb(192, 192, 192);">' . "\n";
                    $html .= '<P>&nbsp;</P>' . "\n";
                    $html .= '<DIV id="ins">下载说明:</DIV>' . "\n";
                    $html .= '<P>1、 如果发现有资料不能下载请<A href="#" target="_blank">联系我们</A>。</P></DIV>' . "\n";
                    $html .= '</TD>' . "\n";
                    $html .= '</TR>' . "\n";
                    $html .= '</TABLE>' . "\n";
                    return $html;
                } else {
                    return '没有找到';
                }
            }
        }
    }
}