2-1
admin/main.php
$xoopsOption [ 'template_main' ] = "snews_adm_main.tpl" ; |
include_once "header.php" ; |
include_once "../function.php" ; |
include_once $GLOBALS [ 'xoops' ]->path( '/modules/system/include/functions.php' ); |
$op = system_CleanVars( $_REQUEST , 'op' , '' , 'string' ); |
header( "location: ../index.php?sn={$sn}" ); |
$xoopsTpl ->assign( 'op' , $op ); |
include_once 'footer.php' ; |
$xoopsTpl ->assign( 'content' , $main ); |
global $xoopsTpl , $xoopsUser , $TadUpFiles ; |
include_once XOOPS_ROOT_PATH . "/class/xoopsformloader.php" ; |
$form = new XoopsThemeForm( '編輯文章' , 'myForm' , 'main.php' , 'post' , true); |
$select = new XoopsFormRadio( '類別或主題' , 'topic_sn' , $topic_sn ); |
$select ->addOptionArray( $options ); |
$form ->addElement( $select ); |
$form ->addElement( new XoopsFormText( '文章標題' , 'title' , 60, 100, $title ), true); |
include_once XOOPS_ROOT_PATH . "/modules/tadtools/ck.php" ; |
$ck = new CKEditor( "snews" , "content" , $content ); |
$form ->addElement( new XoopsFormLabel( '文章內容' , $editor )); |
$form ->addElement( new XoopsFormRadioYN( '精選' , 'focus' , $focus )); |
$username = $xoopsUser ->name(); |
$form ->addElement( new XoopsFormText( '作者' , 'username' , 60, 100, $username )); |
$form ->setExtra( "enctype='multipart/form-data'" ); |
$TadUpFiles ->set_col( 'sn' , $sn ); |
$upform = $TadUpFiles ->upform(true, 'pic' , null, true, 'jpg;png' ); |
$form ->addElement( new XoopsFormLabel( '封面圖' , $upform )); |
$uid = $xoopsUser ->uid(); |
$form ->addElement( new XoopsFormHidden( 'uid' , $uid )); |
$form ->addElement( new XoopsFormHidden( 'op' , 'snews_insert' )); |
$form ->addElement( new XoopsFormButton( '' , '' , '儲存' , 'submit' )); |
$snews_form = $form ->render(); |
$xoopsTpl ->assign( 'snews_form' , $snews_form ); |
global $xoopsDB , $TadUpFiles ; |
$myts = MyTextSanitizer::getInstance(); |
foreach ( $_POST as $key => $value ) { |
$ $key = $myts -> addSlashes ( $value ); |
$tbl = $xoopsDB ->prefix( 'snews' ); |
$sql = "insert into `$tbl` (`focus`, `topic_sn`, `sort`, `title`, `content`, `username`, `create_time`, `update_time`, `uid`) values('{$focus}', '{$topic_sn}', '{$sort}', '{$title}', '{$content}', '{$username}', now(), now(), '{$uid}')" ; |
$xoopsDB ->query( $sql ) or web_error( $sql ); |
$sn = $xoopsDB ->getInsertId(); |
$TadUpFiles ->set_col( 'sn' , $sn ); |
$TadUpFiles ->upload_file( 'pic' , 1920, 640, null, $title , true, true); |