| 17 | | public $helpers = array('Ajax', 'Form', 'User', 'Fck', 'Gags'); |
| 18 | | |
| 19 | | public $components = array('Security', 'Edublog', 'Portal', 'Email', 'Adds', 'Mypagination'); |
| 20 | | |
| 21 | | public function index($id = null) |
| 22 | | { |
| 23 | | $this->pageTitle = 'View Active Users'; |
| 24 | | $this->set('data', $this->User->findAll()); |
| 25 | | $this->set('color', 'blue'); |
| 26 | | } |
| 27 | | |
| 28 | | public function blog($username = null, $page=1) |
| 29 | | { |
| 30 | | $this->layout = 'blog'; |
| 31 | | |
| 32 | | $this->pageTitle = $username . '\'s Blog'; |
| 33 | | |
| 34 | | $this->Entry = new Entry; |
| 35 | | |
| 36 | | $user_id = $this->User->field("id", array("username"=>$username)); |
| 37 | | |
| 38 | | if ($username == null || $user_id == null) |
| 39 | | { |
| | 13 | public $helpers = array('Ajax', 'Fck', 'Gags'); |
| | 14 | |
| | 15 | //public $components = array('Security', 'Edublog', 'Portal', 'Email', 'Adds'); |
| | 16 | |
| | 17 | public function isAuthorized() |
| | 18 | { |
| | 19 | if (isset($this->params[Configure::read('Routing.admin')])) |
| | 20 | { |
| | 21 | if ($this->Auth->user('role') == 'admin') |
| | 22 | { |
| | 23 | return false; |
| | 24 | } |
| | 25 | } |
| | 26 | return true; |
| | 27 | } |
| | 28 | |
| | 29 | public function blog($username = null, $page=1) |
| | 30 | { |
| | 31 | if ($username == null || $user_id == null) |
| | 32 | { |
| 41 | | } |
| 42 | | |
| 43 | | $order = "Entry.id DESC"; |
| 44 | | |
| 45 | | $fields = array("Entry.title", "Entry.body", "Entry.created", "Entry.user_id", "Entry.discution", "Entry.subject_id", "Entry.id", "User.username", "Subject.title", "Subject.id"); |
| 46 | | |
| 47 | | //pagination |
| 48 | | $total_rows = $this->Entry->findCount(array("Entry.user_id"=>$user_id, "Entry.status"=>1)); |
| 49 | | |
| 50 | | $lmt = 10; // limit news |
| 51 | | |
| 52 | | $targetpage = "/blog/".$username."/"; |
| 53 | | |
| 54 | | $pagination = $this->Mypagination->init($total_rows, $page, $lmt, $targetpage); //Pagination |
| 55 | | |
| 56 | | $this->set('pagination', $pagination); |
| 57 | | |
| 58 | | $offset = (($page * $lmt) - 10); |
| 59 | | |
| 60 | | $limit = $lmt . " OFFSET " . $offset; |
| 61 | | |
| 62 | | $conditions = array("Entry.user_id"=>$user_id, "Entry.status"=>1); |
| 63 | | |
| 64 | | $this->set('data', $this->Entry->findAll($conditions, $fields, $order, $limit)); |
| 65 | | |
| 66 | | $this->layout = $this->Edublog->layout($user_id); |
| 67 | | |
| 68 | | $this->Edublog->blog($user_id); |
| | 34 | } |
| | 35 | |
| | 36 | $this->layout = 'blog'; |
| | 37 | |
| | 38 | $this->pageTitle = $username . '\'s Blog'; |
| | 39 | |
| | 40 | $this->Entry = new Entry; |
| | 41 | |
| | 42 | $user_id = $this->User->field("id", array("username"=>$username)); |
| | 43 | |
| | 44 | $order = "Entry.id DESC"; |
| | 45 | |
| | 46 | $fields = array("Entry.title", "Entry.body", "Entry.created", "Entry.user_id", "Entry.discution", "Entry.subject_id", "Entry.id", "User.username", "Subject.title", "Subject.id"); |
| | 47 | |
| | 48 | |
| | 49 | $conditions = array("Entry.user_id"=>$user_id, "Entry.status"=>1); |
| | 50 | |
| | 51 | $this->set('data', $this->Entry->findAll($conditions, $fields, $order, $limit)); |
| | 52 | |
| | 53 | $this->layout = $this->Edublog->layout($user_id); |
| | 54 | |
| | 55 | //$this->Edublog->blog($user_id); |
| 312 | | $this->set('Element', $this->Portal->statics()); // Using Portal component |
| 313 | | |
| 314 | | if (isset($this->data)) |
| 315 | | { |
| 316 | | $auth_num = $this->othAuth->login($this->data['User']); |
| 317 | | |
| 318 | | $this->set('auth_msg', $this->othAuth->getMsg($auth_num)); |
| 319 | | } |
| 320 | | $this->set('auth_msg', 'Welcome!'); |
| 321 | | } |
| 322 | | |
| 323 | | public function logout() |
| 324 | | { |
| 325 | | $this->othAuth->logout(); |
| 326 | | |
| 327 | | $this->redirect('/news/view'); |
| 328 | | } |
| 329 | | |
| 330 | | public function noaccess() |
| 331 | | { |
| 332 | | $this->flash("You don't have permissions to access this page.",'/users/login'); |
| 333 | | } |
| 334 | | |
| 335 | | public function register() |
| 336 | | { |
| | 300 | //$this->set('Element', $this->Portal->statics()); // Using Portal component |
| | 301 | |
| | 302 | if ($this->Auth->user()) |
| | 303 | { |
| | 304 | if (!empty($this->data)) |
| | 305 | { |
| | 306 | if (empty($this->data['User']['remember_me'])) |
| | 307 | { |
| | 308 | $this->Cookie->del('User'); |
| | 309 | } |
| | 310 | else |
| | 311 | { |
| | 312 | $cookie = array(); |
| | 313 | $cookie['email'] = $this->data['User']['email']; |
| | 314 | $cookie['token'] = $this->data['User']['pasword']; |
| | 315 | $this->Cookie->write('User', $cookie, true, '+2 weeks'); |
| | 316 | } |
| | 317 | unset($this->data['User']['remember_me']); |
| | 318 | } |
| | 319 | |
| | 320 | $this->redirect($this->Auth->redirect()); |
| | 321 | } |
| | 322 | } |
| | 323 | |
| | 324 | public function logout() |
| | 325 | { |
| | 326 | $this->Session->setFlash("You've successfully logged out."); |
| | 327 | $this->redirect($this->Auth->logout()); |
| | 328 | } |
| | 329 | |
| | 330 | public function register() |
| | 331 | { |