Guest User

Untitled

a guest
Jul 16th, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.67 KB | None | 0 0
  1. <?php
  2. class UsersController extends AppController {
  3.  
  4. var $name = 'Users';
  5. var $uses = array('User');
  6.  
  7. function beforeFilter(){
  8. parent::beforeFilter();
  9. $this->isAuthorized();
  10. }
  11.  
  12. function isAuthorized() {
  13. $user = $this->Auth->user();
  14. if (!is_array($user) || $this->Auth->user('id') > 2) {
  15. $this->Auth->deny('cms_index',
  16. 'cms_add',
  17. 'cms_edit',
  18. 'cms_delete'
  19. );
  20. }
  21. }
  22.  
  23. function index() {
  24. $this->redirect('login');
  25. }
  26.  
  27. function login() {
  28. $this->layout = 'cms';
  29. $this->set("isLogin", true);
  30.  
  31. }
  32.  
  33. function logout() {
  34. $this->redirect($this->Auth->logout());
  35. }
  36.  
  37. function cms_index(){
  38. $this->layout = 'cms';
  39. $condition = array('isnull(Event.deleted)');
  40. if(!empty($this->params['named']['show'])){
  41. $this->Cookie->write('admin.limit', $this->params['named']['show']);
  42. Configure::write('Admin.pagelimit', $this->params['named']['show']);
  43. $this->set("adminlimit", $this->params['named']['show']);
  44. }
  45. !empty($this->params['named']['page']) ? $this->Session->write('admin_events_cp', $this->params['named']['page']) : $this->Session->write('admin_events_cp', 1);
  46. $aList = $this->Event->find('all',array('conditions'=> $condition, 'order'=>'Event.id DESC'));
  47. $this->paginate['limit'] = Configure::read('Admin.pagelimit');
  48. $this->paginate['order'] = array('Event.id'=> 'DESC');
  49. $this->paginate['conditions'] = $condition;
  50. $aList = $this->paginate( "Event", $aList);
  51. $this->set("aList", $aList);
  52. }
  53.  
  54.  
  55. function cms_add() {
  56. $this->layout = 'cms';
  57. $user_id = $this->Auth->user('id');
  58. if(!empty($this->data)){
  59. $this->data['Event']['user_id'] = $user_id;
  60. $this->Event->set($this->data);
  61.  
  62. if(!$this->Event->validates()){
  63. $val_error = $this->Event->invalidFields();
  64. $e = '';
  65. foreach($val_error as $err){
  66. $e .= __($err, true) . "<br />";
  67. }
  68. $this->Session->setFlash($e,'flash_bad');
  69. }else{
  70. if($this->Event->save($this->data)){
  71. $this->Session->setFlash(__('Event is successfully saved!', true),'flash_good');
  72. $this->redirect(array('controller'=>'events','action'=>'index','cms'=> true));
  73. }else{
  74. $this->Session->setFlash(__('Unable to save events!', true),'flash_bad');
  75. }
  76. }
  77. }
  78. }
  79.  
  80. function cms_edit($id = null) {
  81. $this->layout = 'cms';
  82. $user_id = $this->Auth->user('id');
  83. if($id){
  84. if(!empty($this->data)){
  85. $this->data['Event']['id'] = $id;
  86. $this->Event->set($this->data);
  87. if(!$this->Event->validates()){
  88. $val_error = $this->Event->invalidFields();
  89. $e = '';
  90. foreach($val_error as $err){
  91. $e .= __($err,true) . "<br />";
  92. }
  93. $this->Session->setFlash($e,'flash_bad');
  94. }else{
  95. if($this->Event->save($this->data)){
  96. $this->Session->setFlash(__('Event is successfully saved!', true),'flash_good');
  97. }else{
  98. $this->Session->setFlash(__('Unable to save Event!', true),'flash_bad');
  99. }
  100. }
  101. }
  102. $events = $this->Event->find('first',array('recursive' => 1,'conditions'=>array('isnull(Event.deleted)','Event.id'=>$id)));
  103. $this->set('events', $events);
  104. }
  105. }
  106.  
  107. function cms_delete($id = null) {
  108. if(isset($this->params['pass'][0]) && $this->params['pass'][0] == 'selected'){
  109. if(!empty($_POST['events'])){
  110. foreach($_POST['events'] as $key => $val){
  111. $data['Event']['id'] = $val;
  112. $data['Event']['deleted'] = date('Y-m-d H:i:s');
  113. if($this->Event->save($data)){
  114. $successmessage[] = __("Event ID", true) . " " . $val . " " . __("is successefully deleted!",true);
  115. }else{
  116. $validationErrors[] = __("Unable to delete Event ID",true) ." ". $val . "!";
  117. }
  118. }
  119. }else{
  120. $validationErrors[] = __("No event selected!",true);
  121. }
  122. if(!empty($successmessage)){
  123. $s = '';
  124. foreach($successmessage as $suc){
  125. $s .= $suc . "<br />";
  126. }
  127. $this->Session->setFlash($s,'flash_good');
  128. }
  129. }else{
  130. $data['Event']['id'] = $id;
  131. $data['Event']['deleted'] = date('Y-m-d H:i:s');
  132. if($this->Event->save($data)){
  133. $this->Session->setFlash(__('Event is successfully deleted!', true),'flash_good');
  134. }else{
  135. $validationErrors[] = __("Unable to delete event!", true);
  136. }
  137. }
  138. if(!empty($validationErrors)){
  139. $e = '';
  140. foreach($validationErrors as $err){
  141. $e .= $err . "<br />";
  142. }
  143. $this->Session->setFlash($e,'flash_bad');
  144. }
  145.  
  146. $m = '';
  147. foreach($this->params['named'] as $key => $val){
  148. $m .= '/' . $key . ':' . $val;
  149. }
  150. $this->redirect(array('controller'=>'events','action'=>'index',$m , 'cms'=>true));
  151. }
  152.  
  153. }
  154. ?>
Add Comment
Please, Sign In to add comment