<?php
/*
* 项目: iOrange(橘子)
* 作者: 离家出走(yzxh24)
* Email: yzxh24@gmail.com
* 主页: www.iorange.cc
*/
/* vim: set ts=4 sw=4: */
class EditAction extends BcartAction
{
    public function run()
    {
        $bcart = $this->check();

        if (isset($_POST['subject']))
        {
            $subject = S::gp('subject', 'P');
            $description = S::gp('description', 'P');
            $tid = S::gp('tid', 'P', 2);

            if (empty($subject))
            {
                throw new iSystemException('书单名不能为空');
            }
            if (4 > $this->getSize($subject))
            {
                throw new iSystemException('书单名长度不能少于4个字');
            }

            if (empty($description))
            {
                throw new iSystemException('书单介绍不能为空');
            }
            if (10 > $this->getSize($description))
            {
                throw new iSystemException('书单介绍不能少于10个字');
            }

            $this->db()->update(Bcarts::table())->value(array('tid'=>$tid,'subject'=>$subject,'description'=>$description,'updatedate'=>CDATETIME))->where(array('id'=>$bcart['id']))->q();
            iforward(url('system', array('s'=>'bcart','c'=>'member')));
        }

        $typeList = $this->db()->select()->from('type')->where(array('type'=>'bcart'))->find();
        $this->getController()->render('edit', array(
                'bcart' => $bcart,
                'typeList' => $typeList,
            )
        );
    }
}
