/** * Manages all models. */ public function actionUser() { $this->layout = 'column1'; $model = new UserLogs('search'); $model->unsetAttributes(); // clear any default values if (isset($_GET['UserLogs'])) { $model->attributes = $_GET['UserLogs']; } $this->render('user', array('model' => $model)); }
public static function createLog($message, $type = 'info', $class = '') { $log = new UserLogs(); $log->user_id = Yii::app()->user->id; $log->message = $message; $log->time = time(); $log->type = $type; $log->class = $class; if ($log->save()) { return TRUE; } else { throw new CHttpException(CJSON::encode($log->errors)); } }
/** * Deletes a particular model. * If deletion is successful, the browser will be redirected to the 'admin' page. * @param integer $id the ID of the model to be deleted */ public function actionDelete($id) { if (Yii::app()->request->isPostRequest) { UserLogs::createLog('Delete ' . get_class($this->loadModel($id)) . ' ' . $id); // we only allow deletion via POST request $this->loadModel($id)->delete(); // if AJAX request (triggered by deletion via admin grid view), we should not redirect the browser if (!isset($_GET['ajax'])) { $this->redirect(isset($_POST['returnUrl']) ? $_POST['returnUrl'] : array('admin')); } } else { throw new CHttpException(400, 'Invalid request. Please do not repeat this request again.'); } }
/** * Lists all models. */ public function actionIndex() { /* $model=new Goods('search'); $model->unsetAttributes(); // clear any default values if(isset($_GET['Goods'])) $model->attributes=$_GET['Goods']; $this->render('index',array( 'model'=>$model, ));*/ $params = array('allow_cache' => false); $this->render('/userlogs/index', array('data' => UserLogs::Pages($params))); }
public function actionCreateContact($id) { $customerContact = new CustomerContact(); $contact = new Contact(); $customer = Customer::model()->findByPk($id); // Uncomment the following line if AJAX validation is needed $this->performAjaxValidation(array($customerContact)); if (isset($_POST['Contact']) && isset($_POST['CustomerContact'])) { $trans = Yii::app()->db->beginTransaction(); try { $contact->attributes = $_POST['Contact']; $customerContact->attributes = $_POST['CustomerContact']; if ($customerContact->save()) { $contact->parent_model = 'CustomerContact'; $contact->parent_id = $customerContact->id; if ($contact->save()) { $trans->commit(); UserLogs::createLog('create new ' . get_class($contact) . ' ' . $contact->primaryKey); Yii::app()->user->setFlash('success', 'Contact Customer sudah ditambah.'); $this->redirect(array('customer/update', 'id' => $id)); } else { throw new CustomerControllerException($contact->getErrors()); } } else { throw new CustomerControllerException($customerContact->getErrors()); } } catch (CustomerControllerException $e) { $trans->rollback(); } catch (CDbException $e) { $trans->rollback(); } } $customerContact->customer_id = $id; $this->render('create_contact', array('contact' => $contact, 'customerContact' => $customerContact, 'id' => $id, 'customer_name' => $customer->name)); }