EliteConf
 All Data Structures Namespaces Files Functions Variables Pages
PaperController1.php
Go to the documentation of this file.
1 <?php
2 
3 class PaperController extends Controller {
4 
9  public $layout = '//layouts/column2';
10 
14  public function filters() {
15  return array(
16  'accessControl', // perform access control for CRUD operations
17  'postOnly + delete', // we only allow deletion via POST request
18  );
19  }
20 
26  public function accessRules() {
27  return array(
28  array('allow', // allow authenticated user to perform 'index' and 'view' actions
29  'actions' => array('index', 'view'),
30  'users' => array('@'),
31  ),
32  array('allow', // allow authenticated user to perform 'create' and 'update' actions
33  'actions' => array('create', 'update'),
34  'users' => array('@'),
35  ),
36  array('allow', // allow authenticated user to perform 'create' and 'update' actions
37  'actions' => array('abc'),
38  'users' => array('@'),
39  ),
40  array('allow', // allow authenticated user to perform 'create' and 'update' actions
41  'actions' => array('download'),
42  'users' => array('@'),
43  ),
44  array('allow', // allow authenticated user to perform 'create' and 'update' actions
45  'actions' => array('uploadPaper'),
46  'users' => array('@'),
47  ),
48  array('allow', // allow admin user to perform 'admin' and 'delete' actions
49  'actions' => array('admin', 'delete'),
50  'users' => array('admin'),
51  ),
52  array('deny', // deny all users
53  'users' => array('*'),
54  ),
55  );
56  }
57 
62  public function actionView($id) {
63  $this->render('view', array(
64  'model' => $this->loadModel($id),
65  ));
66  }
67 
72  public function actionCreate() {
73  $model = new Paper;
74 
75  // Uncomment the following line if AJAX validation is needed
76  // $this->performAjaxValidation($model);
77 
78  if (isset($_POST['Paper'])) {
79  $model->attributes = $_POST['Paper'];
80  if ($model->save())
81  $this->redirect(array('view', 'id' => $model->id));
82  }
83 
84  $this->render('create', array(
85  'model' => $model,
86  ));
87  }
88 
94  public function actionUpdate($id) {
95  $model = $this->loadModel($id);
96 
97  // Uncomment the following line if AJAX validation is needed
98  // $this->performAjaxValidation($model);
99 
100  if (isset($_POST['Paper'])) {
101  $model->attributes = $_POST['Paper'];
102  if ($model->save())
103  $this->redirect(array('view', 'id' => $model->id));
104  }
105 
106  $this->render('update', array(
107  'model' => $model,
108  ));
109  }
110 
116  public function actionDelete($id) {
117  $this->loadModel($id)->delete();
118 
119  // if AJAX request (triggered by deletion via admin grid view), we should not redirect the browser
120  if (!isset($_GET['ajax']))
121  $this->redirect(isset($_POST['returnUrl']) ? $_POST['returnUrl'] : array('admin'));
122  }
123 
127  public function actionIndex() {
128  $dataProvider = new CActiveDataProvider('Paper');
129  $this->render('index', array(
130  'dataProvider' => $dataProvider,
131  ));
132  }
133 
137  public function actionAdmin() {
138  $model = new Paper('search');
139  $model->unsetAttributes(); // clear any default values
140  if (isset($_GET['Paper']))
141  $model->attributes = $_GET['Paper'];
142 
143  $this->render('admin', array(
144  'model' => $model,
145  ));
146  }
147 
153  public function loadModel($id) {
154  $model = Paper::model()->findByPk($id);
155  if ($model === null)
156  throw new CHttpException(404, 'The requested page does not exist.');
157  return $model;
158  }
159 
164  protected function performAjaxValidation($model) {
165  if (isset($_POST['ajax']) && $_POST['ajax'] === 'paper-form') {
166  echo CActiveForm::validate($model);
167  Yii::app()->end();
168  }
169  }
170 
171  function actionUploadPaper() {
172 //Yükleme yapılacak yolu alıyoruz.
173  $dir = Yii::getPathOfAlias('application.uploads');
174 //Yükleme dinleyici, sorunsuz yüklerse true olacaktır.
175  $uploaded = false;
176  $model = new Paper();
177  if (isset($_POST['Paper'])) {
178  $model->attributes = $_POST['Paper'];
179 //Upload modelindeki $file objesine gelen dosya eşitleniyor.
180  $file = CUploadedFile::getInstance($model, 'file');
181  if ($model->validate()) {
182 //Yükleme yapılan yer. getName ile dosya aynen adıyla kaydediliyor.
183  $uploaded = $file->saveAs($dir . '/' . $file->getName());
184  $model->save();
185 
186  echo $_GET['va'];
187  $pid = $model->id;
188  echo $pid;
189  }
190  }
191  $this->render('UploadPaper', array(
192  'model' => $model,
193  'uploaded' => $uploaded,
194  'dir' => $dir,
195  ));
196 
197  }
198 
199 
200 
201 
202 
203  function actionDownload() {
204 
205  $model=$this->loadModel($_GET['id']);
206  $name = $model->paper_name;
207 
208  $filecontent = file_get_contents(Yii::getPathOfAlias('application.uploads') .'/'. $name);
209  header("Content-Type: application/pdf");
210  header("Content-disposition: attachment; filename=$name");
211  header("Pragma: no-cache");
212  echo $filecontent;
213  exit;
214  }
215 
216 
217 
218 }
219 ?>