PageRenderTime 41ms CodeModel.GetById 18ms RepoModel.GetById 1ms app.codeStats 0ms

/protected/controllers/SiteController.php

https://gitlab.com/irvanresna/sensasi
PHP | 168 lines | 104 code | 27 blank | 37 comment | 10 complexity | 6d82249c584250f690961147f73889f2 MD5 | raw file
  1. <?php
  2. class SiteController extends Controller
  3. {
  4. /**
  5. * Declares class-based actions.
  6. */
  7. public function actions()
  8. {
  9. return array(
  10. // captcha action renders the CAPTCHA image displayed on the contact page
  11. 'captcha'=>array(
  12. 'class'=>'CCaptchaAction',
  13. 'backColor'=>0xFFFFFF,
  14. ),
  15. // page action renders "static" pages stored under 'protected/views/site/pages'
  16. // They can be accessed via: index.php?r=site/page&view=FileName
  17. 'page'=>array(
  18. 'class'=>'CViewAction',
  19. ),
  20. );
  21. }
  22. /**
  23. * This is the default 'index' action that is invoked
  24. * when an action is not explicitly requested by users.
  25. */
  26. public function actionIndex()
  27. {
  28. // renders the view file 'protected/views/site/index.php'
  29. // using the default layout 'protected/views/layouts/main.php'
  30. $this->render('index');
  31. }
  32. public function actionProfile()
  33. {
  34. // renders the view file 'protected/views/site/index.php'
  35. // using the default layout 'protected/views/layouts/main.php'
  36. $this->render('about');
  37. }
  38. public function actionGallery()
  39. {
  40. // renders the view file 'protected/views/site/index.php'
  41. // using the default layout 'protected/views/layouts/main.php'
  42. $this->render('gallery');
  43. }
  44. public function actionVideo()
  45. {
  46. // renders the view file 'protected/views/site/index.php'
  47. // using the default layout 'protected/views/layouts/main.php'
  48. $this->render('video');
  49. }
  50. public function actionEvent()
  51. {
  52. // renders the view file 'protected/views/site/index.php'
  53. // using the default layout 'protected/views/layouts/main.php'
  54. $this->render('event');
  55. }
  56. public function actionDetailEvent($id)
  57. {
  58. $model = Event::model()->findByPk($id);
  59. $this->render('detailEvent', array('model'=>$model));
  60. }
  61. /**
  62. * This is the action to handle external exceptions.
  63. */
  64. public function actionError()
  65. {
  66. if($error=Yii::app()->errorHandler->error)
  67. {
  68. if(Yii::app()->request->isAjaxRequest)
  69. echo $error['message'];
  70. else
  71. $this->render('error', $error);
  72. }
  73. }
  74. /**
  75. * Displays the contact page
  76. */
  77. public function actionContact()
  78. {
  79. $model=new ContactForm;
  80. if(isset($_POST['ContactForm']))
  81. {
  82. $model->attributes=$_POST['ContactForm'];
  83. if($model->validate())
  84. {
  85. $name='=?UTF-8?B?'.base64_encode($model->name).'?=';
  86. $subject='=?UTF-8?B?'.base64_encode($model->subject).'?=';
  87. $headers="From: $name <{$model->email}>\r\n".
  88. "Reply-To: {$model->email}\r\n".
  89. "MIME-Version: 1.0\r\n".
  90. "Content-Type: text/plain; charset=UTF-8";
  91. mail(Yii::app()->params['adminEmail'],$subject,$model->body,$headers);
  92. Yii::app()->user->setFlash('contact','Thank you for contacting us. We will respond to you as soon as possible.');
  93. $this->refresh();
  94. }
  95. }
  96. $this->render('contact',array('model'=>$model));
  97. }
  98. /**
  99. * Displays the login page
  100. */
  101. public function actionLogin()
  102. {
  103. $this->layout ='//layouts/administrator/login';
  104. $model=new LoginForm;
  105. // if it is ajax validation request
  106. if(isset($_POST['ajax']) && $_POST['ajax']==='login-form')
  107. {
  108. echo CActiveForm::validate($model);
  109. Yii::app()->end();
  110. }
  111. // collect user input data
  112. if(isset($_POST['LoginForm']))
  113. {
  114. $model->attributes=$_POST['LoginForm'];
  115. // validate user input and redirect to the previous page if valid
  116. if($model->validate() && $model->login())
  117. //$this->redirect(Yii::app()->user->returnUrl);
  118. $this->redirect(array('administrator'));
  119. }
  120. // display the login form
  121. $this->render('login',array('model'=>$model));
  122. }
  123. public function actionAdministrator()
  124. {
  125. if(!Yii::app()->user->isGuest)
  126. {
  127. $this->layout ='//layouts/administrator/column1';
  128. $this->render('dashboardAdministrator');
  129. }else{
  130. $this->redirect(array('login'));
  131. }
  132. }
  133. /**
  134. * Logs out the current user and redirect to homepage.
  135. */
  136. public function actionLogout()
  137. {
  138. Yii::app()->user->logout();
  139. $this->redirect(Yii::app()->homeUrl);
  140. }
  141. }