Example #1
0
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store()
 {
     //Validation
     $rules = array('name' => 'required', 'message' => 'required');
     $validator = Validator::make(Input::all(), $rules);
     if ($validator->fails()) {
         return Redirect::to('/community/boards/create')->withInput()->withErrors($validator);
     }
     $board = new Board();
     $board->name = Input::get('name');
     $board->save();
     $message = new Message();
     $message->body = Input::get('message');
     $message->board_id = $board->id;
     $message->user_id = Auth::user()->id;
     $message->save();
     return Redirect::to('/community/boards/' . $board->id)->with('flash_message', 'Your board has been successfully created!')->with('alert_class', 'alert-success');
 }
Example #2
0
	/**
	 * Creates a new model.
	 * If creation is successful, the browser will be redirected to the 'view' page.
	 */
	public function actionCreate()
	{
		$model=new Board;

		// Uncomment the following line if AJAX validation is needed
		// $this->performAjaxValidation($model);

		if(isset($_POST['Board']))
		{
			$model->attributes=$_POST['Board'];
			if($model->save())
				$this->redirect(array('view','id'=>$model->id));
		}

		$this->render('create',array(
			'model'=>$model,
		));
	}
Example #3
0
 /**
  * Create a board
  */
 public function post_new()
 {
     $data = Input::get();
     $rules = array('name' => 'required', 'description' => 'required', 'position' => 'integer');
     $val = Validator::make($data, $rules);
     if ($val->fails()) {
         Session::flash('status', 'new-board-fail');
         return Redirect::to('/')->with_input()->with_errors($val);
     } else {
         if (!isset($data['position'])) {
             $data['position'] = 1;
         }
         // make the board
         $board = new Board();
         $board->name = $data['name'];
         $board->description = $data['description'];
         $board->position = $data['position'];
         $board->save();
         return Redirect::to('/');
     }
 }
Example #4
0
            if ($BOARD['required_permission_id'] != null) {
                $permission = new StaffPermission($db);
                $permission = $permission->findOneByStaffPermissionId($BOARD['required_permission_id']);
                if ($permission == null) {
                    $ERRORS[] = 'Invalid permission specified.';
                } else {
                    $permission_id = $permission->getStaffPermissionId();
                }
            }
            // end perm specified; check it
            if (sizeof($ERRORS) > 0) {
                draw_errors($ERRORS);
            } else {
                $board->setBoardName($BOARD['name']);
                $board->setBoardDescr($BOARD['description']);
                $board->setBoardLocked($BOARD['locked']);
                $board->setNewsSource($BOARD['news_source']);
                $board->setOrderBy($BOARD['order_by']);
                $board->setRequiredPermissionId($permission_id);
                $board->setBoardCategoryId($category->getBoardCategoryId());
                $board->save();
                $_SESSION['board_notice'] = "You have saved <strong>{$board->getBoardName()}</strong>.";
                redirect('admin-boards');
            }
            // end no errors
            break;
            // end save
    }
    // end state switch
}
// end no errors
 public function postAsk()
 {
     try {
         if (!isset($_POST)) {
             throw new \Exception('Request error!');
         }
         $keys = array('name', 'sex', 'email', 'ask', 'content', 'code', 'isPrivate', 'user_id');
         $values = array();
         $bool = true;
         foreach ($keys as $key) {
             $values[$key] = \Arr::get($_POST, $key, false);
             if ($values[$key] === false) {
                 $bool = false;
             }
         }
         if (!$bool) {
             throw new \Exception('Request error!');
         }
         if (!\Captcha::getInstance()->valid($values['code'])) {
             throw new \Exception('驗証碼錯誤');
         }
         $values['isPrivate'] = $values['isPrivate'] == 'n' ? '0' : '1';
         $b = new \Board();
         $b->name = $values['name'];
         $b->gender = $values['sex'];
         $b->email = $values['email'];
         $b->topic = $values['ask'];
         $b->content = $values['content'];
         $b->isPrivate = $values['isPrivate'];
         $b->user_id = empty($values['user_id']) ? '' : (int) $values['user_id'];
         $b->save();
         return \Response::json(array('status' => 'ok'));
     } catch (\Exception $e) {
         return \Response::json(array('status' => 'error', 'message' => $e->getMessage()));
     }
 }