Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class UsersController extends AppController {
- var $name = 'Users';
- var $uses = array('User');
- function beforeFilter(){
- parent::beforeFilter();
- $this->isAuthorized();
- }
- function isAuthorized() {
- $user = $this->Auth->user();
- if (!is_array($user) || $this->Auth->user('id') > 2) {
- $this->Auth->deny('cms_index',
- 'cms_add',
- 'cms_edit',
- 'cms_delete'
- );
- }
- }
- function index() {
- $this->redirect('login');
- }
- function login() {
- $this->layout = 'cms';
- $this->set("isLogin", true);
- }
- function logout() {
- $this->redirect($this->Auth->logout());
- }
- function cms_index(){
- $this->layout = 'cms';
- $condition = array('isnull(Event.deleted)');
- if(!empty($this->params['named']['show'])){
- $this->Cookie->write('admin.limit', $this->params['named']['show']);
- Configure::write('Admin.pagelimit', $this->params['named']['show']);
- $this->set("adminlimit", $this->params['named']['show']);
- }
- !empty($this->params['named']['page']) ? $this->Session->write('admin_events_cp', $this->params['named']['page']) : $this->Session->write('admin_events_cp', 1);
- $aList = $this->Event->find('all',array('conditions'=> $condition, 'order'=>'Event.id DESC'));
- $this->paginate['limit'] = Configure::read('Admin.pagelimit');
- $this->paginate['order'] = array('Event.id'=> 'DESC');
- $this->paginate['conditions'] = $condition;
- $aList = $this->paginate( "Event", $aList);
- $this->set("aList", $aList);
- }
- function cms_add() {
- $this->layout = 'cms';
- $user_id = $this->Auth->user('id');
- if(!empty($this->data)){
- $this->data['Event']['user_id'] = $user_id;
- $this->Event->set($this->data);
- if(!$this->Event->validates()){
- $val_error = $this->Event->invalidFields();
- $e = '';
- foreach($val_error as $err){
- $e .= __($err, true) . "<br />";
- }
- $this->Session->setFlash($e,'flash_bad');
- }else{
- if($this->Event->save($this->data)){
- $this->Session->setFlash(__('Event is successfully saved!', true),'flash_good');
- $this->redirect(array('controller'=>'events','action'=>'index','cms'=> true));
- }else{
- $this->Session->setFlash(__('Unable to save events!', true),'flash_bad');
- }
- }
- }
- }
- function cms_edit($id = null) {
- $this->layout = 'cms';
- $user_id = $this->Auth->user('id');
- if($id){
- if(!empty($this->data)){
- $this->data['Event']['id'] = $id;
- $this->Event->set($this->data);
- if(!$this->Event->validates()){
- $val_error = $this->Event->invalidFields();
- $e = '';
- foreach($val_error as $err){
- $e .= __($err,true) . "<br />";
- }
- $this->Session->setFlash($e,'flash_bad');
- }else{
- if($this->Event->save($this->data)){
- $this->Session->setFlash(__('Event is successfully saved!', true),'flash_good');
- }else{
- $this->Session->setFlash(__('Unable to save Event!', true),'flash_bad');
- }
- }
- }
- $events = $this->Event->find('first',array('recursive' => 1,'conditions'=>array('isnull(Event.deleted)','Event.id'=>$id)));
- $this->set('events', $events);
- }
- }
- function cms_delete($id = null) {
- if(isset($this->params['pass'][0]) && $this->params['pass'][0] == 'selected'){
- if(!empty($_POST['events'])){
- foreach($_POST['events'] as $key => $val){
- $data['Event']['id'] = $val;
- $data['Event']['deleted'] = date('Y-m-d H:i:s');
- if($this->Event->save($data)){
- $successmessage[] = __("Event ID", true) . " " . $val . " " . __("is successefully deleted!",true);
- }else{
- $validationErrors[] = __("Unable to delete Event ID",true) ." ". $val . "!";
- }
- }
- }else{
- $validationErrors[] = __("No event selected!",true);
- }
- if(!empty($successmessage)){
- $s = '';
- foreach($successmessage as $suc){
- $s .= $suc . "<br />";
- }
- $this->Session->setFlash($s,'flash_good');
- }
- }else{
- $data['Event']['id'] = $id;
- $data['Event']['deleted'] = date('Y-m-d H:i:s');
- if($this->Event->save($data)){
- $this->Session->setFlash(__('Event is successfully deleted!', true),'flash_good');
- }else{
- $validationErrors[] = __("Unable to delete event!", true);
- }
- }
- if(!empty($validationErrors)){
- $e = '';
- foreach($validationErrors as $err){
- $e .= $err . "<br />";
- }
- $this->Session->setFlash($e,'flash_bad');
- }
- $m = '';
- foreach($this->params['named'] as $key => $val){
- $m .= '/' . $key . ':' . $val;
- }
- $this->redirect(array('controller'=>'events','action'=>'index',$m , 'cms'=>true));
- }
- }
- ?>
Add Comment
Please, Sign In to add comment