<?php
/**
* @author moufer<moufer@163.com>
* @copyright www.modoer.com
* @version $Id lis.inc.php 2 2008-08-24 11:39 $
*/
(!defined('IN_ADMIN') || !defined('IN_MUDDER')) && exit('Access Denied');

$table = "{$dbpre}mylinks"; // 操作表

// 未审核数量
$num_nochecks = $db->select_count($dbpre.'mylinks', "ischeck=0");

if($dosubmit) {

    if($mylink) {
        foreach($mylink as $linkid => $val) {
            $linkid = intval($linkid);
            if(($ischeck||($ischeck==0&&$operation=='delete'))&&$linkids&&in_array($linkid, $linkids)) {
                $db->query("DELETE FROM $table WHERE linkid='$linkid'");
            } else {
                !$val['title'] && cpmsg('未填写链接名称，请返回填写。');
                !$val['link'] && cpmsg('未填写链接地址，请返回填写。');
                $val['displayorder'] = intval($val['displayorder']);
                if($ischeck == 0 && $operation == 'check') $val['ischeck']=1;
                $db->update_new($table, "linkid='$linkid'", $val);
            }
        }
    }
    write_cache_links();
    cpmsg('更新完毕!', 'admincp.php?action='.$action.'&file=list');

} else {

    $ischeck = ($ischeck == '' || $ischeck) ? 1 : 0;
    $where = array("ischeck='$ischeck'");
    $ischeck && $where[] = $logo ? "logo!=''" : "logo=''";
    $query = $db->query("SELECT * FROM $table WHERE ".implode(' AND ',$where)." ORDER BY displayorder");
    $contents = '';
    if($db->num_rows($query) > 0) {
        while($row = $db->fetch_array($query)) {
            $linkid = $row['linkid'];
            $contents .= "<tr><td><input type=\"checkbox\" name=\"linkids[]\" value=\"$linkid\" /></td>\r\n";
            $contents .= "<td><input type=\"text\" class=\"txtbox5\" name=\"mylink[$linkid][displayorder]\" value=\"{$row['displayorder']}\" /></td>\r\n";
            $contents .= "<td><input type=\"text\" class=\"mylinks_txtbox\" name=\"mylink[$linkid][title]\" value=\"{$row['title']}\" /></td>\r\n";
            $contents .= "<td><input type=\"text\" class=\"mylinks_txtbox\" name=\"mylink[$linkid][link]\" value=\"{$row['link']}\" /></td>\r\n";
            $contents .= "<td><input type=\"text\" class=\"mylinks_txtbox\" name=\"mylink[$linkid][logo]\" value=\"{$row['logo']}\" /></td>\r\n";
            $contents .= "<td><input type=\"text\" class=\"mylinks_txtbox\" name=\"mylink[$linkid][des]\" value=\"{$row['des']}\" /></td></tr>\r\n";
        }
    } else {
        $contents = "<tr><td colspan=\"6\">暂无信息。</td></tr>";
    }

    include cptpl('list', MOD_ROOT.'./admin/templates/');
}
?>