<?php
require ('authentication_manager.php');
?>
<script language="javascript" type="text/javascript">
<!--
//调出用户信息弹窗
function showMenu(obj, pic){
  var win=$("lastFrame");
  if(win!=null){
    //var h=obj.offsetHeight;
    var t=obj.offsetTop;
    var l=obj.offsetLeft;
    while(obj=obj.offsetParent){
	  //if(obj==document.body) break;
      t+=obj.offsetTop;
      l+=obj.offsetLeft;
    }
    win.style.display="block";
    win.style.position="absolute";
    win.style.left=(l)+"px";
    win.style.top=(t+14)+"px";
    win.style.zIndex="10";
    win.innerHTML='<img src="obj.php?title='+pic+'" />';
    win.onmouseout=function(){
      win.style.display="none";
      win.innerHTML='正在载入图片预览…';
    }
  }
}
//-->
</script>
<div id="lastFrame" style="display:none; background-color:#FFFFFF; border:5px #CCCCCC solid; padding:5px;">正在载入图片预览…</div>
<?php

/* 管理上传夹 */
/* 162100源码 - 162100.com */


function run_datetime($v) {
  $v = preg_replace('/^(\d{4})(\d{2})?(\d{2})?(\d{2})?(\d{2})?(\d{2})?$/', '$1-$2-$3 $4:$5:$6', preg_replace('/[^\d]+/', '', $v));
  return preg_replace('/^[^\d]+|[^\d]+$/', '', $v);
}

if ($web['url_html_article'] == 1) {
  $article_url = '"article.'.$web['sitemode'].'.".$info_id.".1.html"';
} else {
  $article_url = '"article.php?mode='.$web['sitemode'].'&id=".$info_id.""';
}

$text = $err = $where_ev = $search_r = '';
$n = 0;

$_GET['act'] = @$_GET['act'];
if ($_GET['act'] == 'mess') {
  $where_ev .= ' WHERE title LIKE "mess-%"';
  $list_title = '"<a href=\"?get=upload\">文章附件</a><a href=\"?get=upload&act=reply\">回复附件</a><a class=\"list_title_in\">".$search_r."短信附件<span>（".$n."）</span></a><a href=\"?get=upload&act=mail\">邮件附件</a>"';
} elseif ($_GET['act'] == 'mail') {
  $where_ev .= ' WHERE title LIKE "mail-%"';
  $list_title = '"<a href=\"?get=upload\">文章附件</a><a href=\"?get=upload&act=reply\">回复附件</a><a href=\"?get=upload&act=mess\">短信附件</a><a class=\"list_title_in\">".$search_r."邮件附件<span>（".$n."）</span></a>"';
} elseif ($_GET['act'] == 'reply') {
  $where_ev .= ' WHERE title LIKE "reply-%"';
  $list_title = '"<a href=\"?get=upload\">文章附件</a><a class=\"list_title_in\">".$search_r."回复附件<span>（".$n."）</span></a><a href=\"?get=upload&act=mess\">短信附件</a><a href=\"?get=upload&act=mail\">邮件附件</a>"';
} else {
  $where_ev .= ' WHERE title LIKE "info-%"';
  $list_title = '"<a class=\"list_title_in\">".$search_r."文章附件<span>（".$n."）</span></a><a href=\"?get=upload&act=reply\">回复附件</a><a href=\"?get=upload&act=mess\">短信附件</a><a href=\"?get=upload&act=mail\">邮件附件</a>"';
}
$_GET['username'] = @$_GET['username'];
if (!empty($_GET['username']) || !empty($_GET['date'])) {
  $search_r = '搜索结果 - ';
  $_GET['username'] = strtolower(trim($_GET['username']));
  $_GET['username'] = str_replace('.', '&#46;', $_GET['username']);
  if (!empty($_GET['username'])) {
    if (preg_match('/^([^\x00-\x7f]|\w|&#46;){3,45}$/', $_GET['username'])) {
      $where_ev .= ' AND username ="'.$_GET['username'].'"';
    } else {
      $search_r .= '<span class="redword">用户名不合法</span> | ';
    }
  }

  if ($_GET['date'] = run_datetime($_GET['date'])) {
echo $_GET['date'];
    $where_ev .= ' AND date LIKE "'.$_GET['date'].'%"';
  } else {
    $search_r .= '<span class="redword">附件名不合法</span> | ';
  }
}


if (!isset($sql['db_err'])) {
  db_conn();
}

if ($sql['db_err'] == '') {
  $result = @mysql_query('SELECT COUNT(id) AS total FROM '.$sql['pref'].''.$sql['data']['承载上传数据的表名'].''.$where_ev.'', $db);
  $row = @mysql_fetch_assoc($result);
  $n = abs($row['total']);
  @mysql_free_result($result);
  unset($row);

  if ($n > 0) {
    require ('inc/function/get_page.php');
    $p = get_page($n); //页数
    $seek = $web['pagesize'] * ($p-1);
    $result = @mysql_query('SELECT * FROM '.$sql['pref'].''.$sql['data']['承载上传数据的表名'].''.$where_ev.' ORDER BY id DESC LIMIT '.$seek.','.$web['pagesize'].'', $db);
    while ($row = @mysql_fetch_assoc($result)) {
      $text .='
<div class="li">
  <table width="100%" border="0" cellspacing="0" cellpadding="0">
    <tr>
      <td style="text-align:left;"><input name="id[]" id="id[]" type="checkbox" class="checkbox" value="'.$row['title'].'" />
      '.get_filetype($row['title']).'</td>
      <td width="100" style="text-align:center;">'.get_fr($row['title']).'</td>
      <td width="150" style="text-align:center;">'.$row['type'].'</td>
      <td width="100" style="text-align:center;">'.$row['username'].'</td>
      <td width="150" style="text-align:center;">'.$row['date'].'</td>
    </tr>
  </table>
</div>';
      unset($row);
    }
    @mysql_free_result($result);
    $text .= @get_page_foot($n, $web['pagesize'], $p, '?get=upload&act='.$_GET['act'].'&date='.urlencode($_GET['date']).'&username='.urlencode($_GET['username']).'&p=');
  } else {
    $err = '附件记录为空';
  }

} else {
  $err = $sql['db_err'];
}

@mysql_close();

function get_fr($f) {
  global $web, $article_url;
  $arr0 = @explode('-', $f);
  //print_r($arr0);die;
  switch ($arr0[0]) {
    case 'info':
    $info_id = $arr0[1];
    return '<a href="'.eval('return '.$article_url.';').'" target="_blank">文章：'.$info_id.'</a>';
    break;
    case 'reply':
    $arr1 = @explode('_', $arr0[1]);
    $info_id = $arr1[0];
    return '<a href="'.eval('return '.$article_url.';').'#reply_'.$arr1[1].'" target="_blank">回帖：'.$arr0[1].'</a>';
    break;
  }
}

function get_filetype($file) {
  $format = strrchr($file, '.');
  switch ($format) {
    case '.jpg' :
    $text = '0px 0px';
    $imgo = ' onmouseover="showMenu(this,\''.$file.'\');"';
    break;

    case '.gif' :
    case '.png' :
    $text = '-16px 0px';
    $imgo = ' onmouseover="showMenu(this,\''.$file.'\');"';
    break;

    case '.wav' :
    case '.wma' :
    case '.wmv' :
    case '.mid' :
    case '.midi' :
    case '.avi' :
    case '.mp3' :
    case '.mpg' :
    case '.mpeg' :
    case '.asf' :
    case '.asx' :
    case '.mov' :
    case '.rm' :
    case '.rmvb' :
    case '.ram' :
    case '.ra' :
    $text = '-32px 0px';
    break;

    case '.rar' :
    case '.zip' :
    $text = '-48px 0px';
    break;

    case '.doc' :
    $text = '-64px 0px';
    break;

    case '.xls' :
    $text = '-80px 0px';
    break;

    case '.chm' :
    $text = '-96px 0px';
    break;

    case '.hlp' :
    $text = '-112px 0px';
    break;

    default :
    $text = '-128px 0px';
    break;
  }
  return '
<span style=" display:inline-block !important; display:inline; zoom:1; width:16px; height:16px; overflow:hidden; background:url(./inc/images/filetype.gif) '.$text.' no-repeat;" title="'.$format.'格式文件"></span> <a href="obj.php?title='.$file.'" target="_blank"'.$imgo.'>'.$file.'</a>';
}

?>
<div class="list_title"><?php echo eval('return '.$list_title.';'); ?></div>
<form method="post" id="manageform" action="?post=unity_run&dataname=upload" onsubmit="addSubmitSafe()">
  <div class="manager_menu">
    <table border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td width="120"><a href="javascript:void(0)" onclick="allChoose(true,true);return false;">全选</a>- <a href="javascript:void(0)" onclick="allChoose(true,false);return false;">反选</a>- <a href="javascript:void(0)" onclick="allChoose(false,false);return false;">不选</a></td>
        <td><button name="act" type="button" onclick="chk(this.form,this,'del_upload')"><b>删除</b></button>
          <button name="button" type="button" onclick="if(confirm('该命令可能要花费较长时间！确定执行么？')){addSubmitSafe();location.href='?post=unity_run&dataname=upload&limit=clear_upload&id[]=1';}"><b>一键清空所有</b></button> | 按条件搜索：
          日期
          <input name="date" id="date" value="<?php echo isset($_GET['date']) && $_GET['date'] ? $_GET['date'] : ''; ?>" type="text" size="10" />
          操作人
          <input name="username" id="username" value="<?php echo isset($_GET['username']) && $_GET['username'] ? $_GET['username'] : ''; ?>" type="text" size="10" />
          <button name="button" type="button" onclick="location.href='?get=upload&act=<?php echo $_GET['act']; ?>&date='+encodeURIComponent($('date').value)+'&username='+encodeURIComponent($('username').value)+''"><b>搜索</b></button>
          </td>
      </tr>
    </table>
  </div>
    <div class="list_title_">
      <table width="100%" border="0" cellspacing="0" cellpadding="0">
        <tr>
          <th width="20">&nbsp;</th>
          <th width="*">附件名称</th>
          <th width="100" align="center">出处</th>
          <th width="150" align="center">类型</th>
          <th width="100" align="center">操作人</th>
          <th width="150" align="center">时间</th>
        </tr>
      </table>
    </div>

  <?php
echo $text, $err;
?>
  <input type="hidden" name="limit" />
</form>
