Exemplo n.º 1
0
 public function index()
 {
     if ($this->input->post('login')) {
         $username = $this->input->post('username');
         $pass = $this->input->post('pass');
         $login = new \Models\Login();
         $userData = array('username' => $username, 'pass' => $pass);
         $check = $login->checkData($userData);
         if ($check === true) {
             foreach ($login->getUserData() as $k => $v) {
                 $this->app->getSession()->{$k} = $v;
             }
         } else {
             //returns an array with errors
             $this->view->errors = $login->getErrors();
         }
     }
     if ($this->app->getSession()->username == null) {
         $this->view->appendToLayout('userbar', 'index.userbar');
         $this->view->appendToLayout('welcome', 'index.welcome');
         $this->view->appendToLayout('login', 'index.login');
         $this->view->display('index_out');
     } else {
         if ($this->input->post('create')) {
             $name = $this->input->post('name');
             $description = $this->input->post('description');
             $link = $this->input->post('link');
             $create = new \Models\Manageblogs();
             $blogData = array('name' => $name, 'description' => $description, 'link' => $link);
             $check = $create->checkData($blogData);
             if ($check === true) {
                 $create->createBlog();
                 $servarname = $_SERVER['SERVER_NAME'];
                 header("Location: http://{$servarname}/{$link}");
                 /* Redirect browser */
                 exit;
             } else {
                 //returns an array with errors
                 $this->view->errors = $create->getErrors();
             }
         }
         $manageblogs = new \Models\Manageblogs();
         $blogs = $manageblogs->getBlogs($this->app->getSession()->user_id);
         if ($blogs === 0) {
             $this->view->newbie = true;
         } else {
             $this->view->blogs = $blogs;
         }
         $this->view->appendToLayout('userbar', 'index.userbar');
         $this->view->appendToLayout('manageblogs', 'index.manageblogs');
         $this->view->display('index_in');
     }
 }
Exemplo n.º 2
0
 public function blog()
 {
     if ($this->input->post('create')) {
         $name = $this->input->post('name');
         $description = $this->input->post('description');
         $link = $this->input->post('link');
         $create = new \Models\Manageblogs();
         $blogData = array('name' => $name, 'description' => $description, 'link' => $link);
         $check = $create->checkData($blogData);
         if ($check === true) {
             $create->createBlog();
         } else {
             //returns an array with errors
             echo '<pre>' . print_r($create->getErrors(), true) . '</pre>';
             $this->view->errors = $create->getErrors();
         }
     }
 }
Exemplo n.º 3
0
 public function blog()
 {
     $blog_id = $this->input->get(0);
     $servarname = $_SERVER['SERVER_NAME'];
     $select = new \Models\Select();
     $this->view->blodData = $select->getBlogData($blog_id);
     if ($select->getAffectedRows() != 1) {
         header("Location: http://{$servarname}");
         /* Redirect browser */
         exit;
     }
     if ($this->input->post('edit')) {
         $name = $this->input->post('name');
         $description = $this->input->post('description');
         $link = $this->input->post('link');
         $create = new \Models\Manageblogs();
         $blogData = array('name' => $name, 'description' => $description, 'link' => $link);
         $check = $create->checkData($blogData);
         if ($check === true) {
             $create->updateBlog();
             header("Refresh:0");
             exit;
         } else {
             //returns an array with errors
             $this->view->errors = $create->getErrors();
         }
     }
     $this->view->appendToLayout('userbar', 'index.userbar');
     $this->view->appendToLayout('editblog', 'index.editblog');
     $this->view->display('index_in');
 }