/** * Lists all models. */ public function actionIndex() { $model = new Configuration(); if ($_POST['Configuration']) { $att = array(); $att = $_POST['Configuration']; foreach ($att as $key => $value) { $setmodel = $model->findByAttributes(array('name' => $key)); $setmodel->value = $value; $setmodel->update(); } if (isset($_FILES)) { $setmodel = $model->findByAttributes(array('name' => 'company_logo')); $filename = Utils::getBasepath() . "/img/" . $setmodel->value; if (!empty($_FILES['Configuration']['tmp_name']['company_logo'])) { $file_size = $_FILES['Configuration']['size']['company_logo']; $file_type = $_FILES['Configuration']['type']['company_logo']; $acceptable = array('image/jpeg', 'image/jpg', 'image/gif', 'image/png'); if ($file_size > 2097152) { $message = 'File too large. File must be less than 2MB.'; Yii::app()->user->setFlash('type', 'danger'); Yii::app()->user->setFlash('message', $message); $this->redirect(Yii::app()->request->baseUrl . '/configuration'); } elseif (!in_array($file_type, $acceptable)) { $message = 'Invalid file type. Only JPG, GIF and PNG types are accepted.'; Yii::app()->user->setFlash('type', 'danger'); Yii::app()->user->setFlash('message', $message); $this->redirect(Yii::app()->request->baseUrl . '/configuration'); } move_uploaded_file($_FILES['Configuration']['tmp_name']['company_logo'], $filename); } } Yii::app()->user->setFlash('type', 'success'); Yii::app()->user->setFlash('message', 'System Settings updated successfully.'); $this->redirect(Yii::app()->request->baseUrl . '/configuration'); } $model = $model->findAll(); $this->render('view', array('model' => $model)); }