HCE Project DC service web UI  0.2
Hierarchical Cluster Engine DC service web UI
 All Classes Namespaces Files Functions Variables Pages
SiteController.php
Go to the documentation of this file.
1 <?php
2 
4 {
8  public function actions()
9  {
10  return array(
11  // captcha action renders the CAPTCHA image displayed on the contact page
12  'captcha' => array(
13  'class' => 'CCaptchaAction',
14  'backColor' => 0xFFFFFF,
15  ),
16  // page action renders "static" pages stored under 'protected/views/site/pages'
17  // They can be accessed via: index.php?r=site/page&view=FileName
18  'page' => array(
19  'class' => 'CViewAction',
20  ),
21  );
22  }
23 
28  public function actionIndex()
29  {
30  // renders the view file 'protected/views/site/index.php'
31  // using the default layout 'protected/views/layouts/main.php'
32  $this->render('index');
33  }
34 
38  public function actionError()
39  {
40  if ($error = Yii::app()->errorHandler->error) {
41  if ($error['type'] == 'CDbException') {
42  Yii::app()->errorHandler->__set('message', 'Failed to open the DB connection');
43  }
44  if (Yii::app()->request->isAjaxRequest)
45  echo $error['message'];
46  else
47  $this->render('error', $error);
48  }
49  }
50 
54  public function actionContact()
55  {
56  $model = new ContactForm;
57  if (isset($_POST['ContactForm'])) {
58  $model->attributes = $_POST['ContactForm'];
59  if ($model->validate()) {
60  $name = '=?UTF-8?B?' . base64_encode($model->name) . '?=';
61  $subject = '=?UTF-8?B?' . base64_encode($model->subject) . '?=';
62  $headers = "From: $name <{$model->email}>\r\n" .
63  "Reply-To: {$model->email}\r\n" .
64  "MIME-Version: 1.0\r\n" .
65  "Content-Type: text/plain; charset=UTF-8";
66 
67  mail(Yii::app()->params['adminEmail'], $subject, $model->body, $headers);
68  Yii::app()->user->setFlash('contact', 'Thank you for contacting us. We will respond to you as soon as possible.');
69  $this->refresh();
70  }
71  }
72  $this->render('contact', array('model' => $model));
73  }
74 
78  public function actionLogin()
79  {
80  $model = new LoginForm;
81 
82  // if it is ajax validation request
83  if (isset($_POST['ajax']) && $_POST['ajax'] === 'login-form') {
84  echo CActiveForm::validate($model);
85  Yii::app()->end();
86  }
87 
88  // collect user input data
89  if (isset($_POST['LoginForm'])) {
90  $model->attributes = $_POST['LoginForm'];
91  // validate user input and redirect to the previous page if valid
92  if ($model->validate() && $model->login())
93  $this->redirect(Yii::app()->user->returnUrl);
94  }
95  // display the login form
96  $this->render('login', array('model' => $model));
97  }
98 
102  public function actionLogout()
103  {
104  Yii::app()->user->logout();
105  $this->redirect(Yii::app()->homeUrl);
106  }
107 }