/** * Carrega o formulário de cadastro de usuário na tela */ public function indexAction() { $this->session->start(); $user = Users::findFirstByUser_id($this->session->get("user_id")); //Caso o usuário logado seja administrador ou super administrador OU o usuário logado solicitou a edição do próprio perfil carrega a tela if ($user->user_id != NULL && $user->user_type_id <= 2 || !empty($this->request->get("user_id")) && $this->request->get("user_id") == $user->user_id) { $vars = $this->getUserLoggedInformation(); if ($this->request->get("user_id") != NULL) { $result = Users::findFirstByUser_id($this->request->get("user_id")); if (!$this->verifyPermissionEditedUser($result, Users::findFirstByUser_id($this->session->get("user_id")))) { $this->response->redirect(URL_PROJECT . "admin"); } else { $posts = Posts::findFirstByPost_author($result->user_id); $vars['user_edit']['user_id'] = $result->user_id; $vars['user_edit']['user_name'] = $result->user_name; $vars['user_edit']['user_login'] = $result->user_login; $vars['user_edit']['user_email'] = $result->user_email; $vars['user_edit']['user_type_id'] = $result->user_type_id; $vars['user_edit']['user_img'] = $result->user_img; $vars['user_edit']['user_active'] = $result->user_active; $vars['edit_user'] = true; $vars['not_disable'] = $result->user_id == $this->session->get("user_id") ? true : false; $vars['delete'] = !$posts ? true : false; } } else { $vars['edit_user'] = false; } $vars['types'] = UserType::find(); $vars['menus'] = $this->getSideBarMenus(); //var_dump($vars); die(); $this->view->setVars($vars); $this->view->render('dashboard', 'newUser'); } else { // Caso contrário redireciona para página inicial $this->response->redirect(URL_PROJECT . 'admin'); } }
/** * Carrega a tela principal do backend */ public function indexAction() { $this->session->start(); if ($this->session->get("user_id") != NULL) { $posts = Posts::findByPost_status_id(1); $vars = $this->getUserLoggedInformation(); $vars += $this->getApiSocialsData(); //Busca as últimas 15 postagens $posts = Posts::find(array("conditions" => "post_status_id = :status:", "order" => "post_date_posted DESC", "limit" => 15, "bind" => array("status" => 1))); //Conta o total de postagens existentes; $vars['total_posts'] = count($posts); //Cria uma prévia do conteúdo da postagem foreach ($posts as $post) { $post_content[$post->post_id] = substr(strip_tags($post->post_content), 0, 500) . "..."; } $vars['posts'] = $posts; $vars['post_content'] = $post_content; $vars['menus'] = $this->getSideBarMenus(); $this->view->setVars($vars); $this->view->render('dashboard', 'index'); } else { $this->response->redirect(URL_PROJECT . "admin"); } }
/** * Atualiza uma postagem conforme os dados recebidos via POST */ public function editPostAction() { $this->view->disable(); $post_id = $this->request->getPost("post_id"); $post_date_posted = $this->dateFormat($this->request->getPost('post_date_posted'), 1); $post_date_changed = date("Y-m-d H:i:s"); $post_author = $this->request->getPost('post_author'); $post_editor = $this->request->getPost('post_author'); $post_title = $this->request->getPost('post_title'); $post_content = addslashes(htmlentities($this->request->getPost('post_content'))); $post_status_id = $this->request->getPost('post_status_id'); $categories = explode(", ", $this->request->getPost('list_categories')); $post_id = Posts::updatePostAction($post_id, $post_date_posted, $post_date_changed, $post_author, $post_editor, $post_title, $post_content, $post_status_id); if ($post_id > 0) { $data['success'] = $this->updatePostCategories($categories, $post_id); } echo json_encode($data); }