<?php
function tadnews_content($cate_sn=""){
  global $xoopsDB,$xoopsUser;


  $uid=$xoopsUser->uid();

  $sql="select ncsn from `".$xoopsDB->prefix("tad_news_cate")."` where nc_title='學校簡介'";
  $result = $xoopsDB->queryF($sql) or redirect_header($_SERVER['PHP_SELF'],3, mysql_error());
  list($ncsn)=$xoopsDB->fetchRow($result);
  $sql="delete from `".$xoopsDB->prefix("tad_news_cate")."` where ncsn='$ncsn'";
  $xoopsDB->queryF($sql) or redirect_header($_SERVER['PHP_SELF'],3, mysql_error());
  $sql="delete from `".$xoopsDB->prefix("tad_news")."` where ncsn='$ncsn'";
  $xoopsDB->queryF($sql) or redirect_header($_SERVER['PHP_SELF'],3, mysql_error());



  $sql="INSERT INTO `".$xoopsDB->prefix("tad_news_cate")."`
  (`of_ncsn`, `nc_title`, `enable_group`, `enable_post_group`, `sort`, `cate_pic`, `not_news`, `setup`)
  VALUES
  (0,'學校簡介', '', '1', '1', '', '1','title=1;tool=0;comm=0;nav=1')";

  $xoopsDB->queryF($sql) or die($sql);
  $ncsn = $xoopsDB->getInsertId();


  $sql="INSERT INTO `".$xoopsDB->prefix("tad_news")."` (`ncsn`, `news_title`, `news_content`, `start_day`, `end_day`, `enable`, `uid`, `passwd`, `enable_group`, `counter`, `prefix_tag`, `always_top`, `always_top_date`, `have_read_group`, `page_sort`) VALUES
  ('{$ncsn}', '學校沿革', '<p>內容製作中～</p>\r\n', '2014-01-21 14:49:07', '0000-00-00 00:00:00', '1', 1, '', '', 9, '', '0', '2014-02-05 14:49:07', '', 0),
  ('{$ncsn}', '本校概況', '<p>內容製作中～</p>\r\n', '2014-01-21 14:51:19', '0000-00-00 00:00:00', '1', 1, '', '', 5, '', '0', '2014-02-05 14:51:19', '', 0),
  ('{$ncsn}', '歷任校長', '<p>內容製作中</p>\r\n', '2014-01-21 14:51:48', '0000-00-00 00:00:00', '1', 1, '', '', 5, '', '0', '2014-02-05 14:51:48', '', 0),
  ('{$ncsn}', '學校位置圖', '<p>內容製作中～</p>\r\n', '2014-01-21 14:52:58', '0000-00-00 00:00:00', '1', 1, '', '', 2, '', '0', '2014-02-05 14:52:58', '', 0)
   ";
  $xoopsDB->queryF($sql) or die($sql);


  $sql="select ncsn from `".$xoopsDB->prefix("tad_news_cate")."` where nc_title='行政單位'";
  $result = $xoopsDB->queryF($sql) or redirect_header($_SERVER['PHP_SELF'],3, mysql_error());
  list($ncsn)=$xoopsDB->fetchRow($result);
  $sql="delete from `".$xoopsDB->prefix("tad_news_cate")."` where ncsn='$ncsn'";
  $xoopsDB->queryF($sql) or redirect_header($_SERVER['PHP_SELF'],3, mysql_error());
  $sql="delete from `".$xoopsDB->prefix("tad_news")."` where ncsn='$ncsn'";
  $xoopsDB->queryF($sql) or redirect_header($_SERVER['PHP_SELF'],3, mysql_error());

  $sql="INSERT INTO `".$xoopsDB->prefix("tad_news_cate")."`
  (`of_ncsn`, `nc_title`, `enable_group`, `enable_post_group`, `sort`, `cate_pic`, `not_news`, `setup`)
  VALUES
  (0,'行政單位', '', '1, $groupid ', '1', '', '1','title=1;tool=0;comm=0;nav=1')";

  $xoopsDB->queryF($sql) or die($sql);
  $ncsn = $xoopsDB->getInsertId();


  $sql = "select `groupid`,`name` from ".$xoopsDB->prefix("groups")." where groupid > 3";
  $result = $xoopsDB->query($sql) or redirect_header($_SERVER['PHP_SELF'],3, mysql_error());

  while(list($groupid,$name)=$xoopsDB->fetchRow($result)){
    $sql="INSERT INTO `".$xoopsDB->prefix("tad_news")."` (`ncsn`, `news_title`, `news_content`, `start_day`, `end_day`, `enable`, `uid`, `passwd`, `enable_group`, `counter`, `prefix_tag`, `always_top`, `always_top_date`, `have_read_group`, `page_sort`) VALUES
    ('{$ncsn}', '{$name}', '<p>內容製作中～</p>\r\n', '2014-01-21 15:06:01', '0000-00-00 00:00:00', '1', 1, '', '', 2, '', '0', '2014-02-05 15:06:01', '', 0)
     ";
    $xoopsDB->queryF($sql) or die($sql);
  }
}
?>