Esempio n. 1
0
 /**
  * Displays the login page
  */
 public function actionLogin()
 {
     $this->layout = '//layouts/login';
     if (@Yii::app()->user->id) {
         $this->redirect(Yii::app()->homeUrl);
     }
     $model = new LoginFormAdmin();
     // if it is ajax validation request
     if (isset($_POST['ajax']) && $_POST['ajax'] === 'login-form') {
         echo CActiveForm::validate($model);
         Yii::app()->end();
     }
     // collect user input data
     if (isset($_POST['LoginFormAdmin'])) {
         $model->attributes = $_POST['LoginFormAdmin'];
         // validate user input and redirect to the previous page if valid
         if ($model->validate() && $model->login()) {
             $audit = new AuditTrail();
             $audit->user_id = Yii::app()->user->id;
             $audit->login_time = new CDbExpression('NOW()');
             $audit->user_type = 1;
             $audit->save();
             Yii::app()->user->setFlash('success', 'Welcome in the <strong>' . CHtml::encode(Yii::app()->name) . ' Admin Panel</strong>. Don\'t forget to <strong>Logout</strong> when finish!');
             $this->redirect(Yii::app()->user->returnUrl);
         }
     }
     // display the login form
     $this->render('login', array('model' => $model));
 }
Esempio n. 2
0
 public function logAudit($action)
 {
     $model = new AuditTrail();
     if (Yii::app()->user->id) {
         $model->user_id = Yii::app()->user->id;
     }
     $model->details = $action;
     $model->activity_group = 1;
     $model->save();
 }
Esempio n. 3
0
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new AuditTrail();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['AuditTrail'])) {
         $model->attributes = $_POST['AuditTrail'];
         if ($model->save()) {
             $this->redirect(array('view', 'id' => $model->id));
         }
     }
     $this->render('create', array('model' => $model));
 }
/**
 * Handle the events
 *
 * @param sfEvent $event The event being handled
 * @return bool TRUE if the audit trail for the transaction is saved sucessfully, FALSE otherwise
 */
function auditTransactionEventHandler($event)
{
    $audit_trail = new AuditTrail();
    $audit_trail->processPost($event->getParameters());
    try {
        $audit_trail->save();
    } catch (Exception $e) {
        $logger = Zend_Registry::get("logger");
        $logger->err($e->getMessage());
        return false;
    }
    return true;
}
Esempio n. 5
0
 public function afterDelete($event)
 {
     try {
         $username = Yii::app()->user->Name;
         $userid = Yii::app()->user->id;
     } catch (Exception $e) {
         $username = "******";
         $userid = null;
     }
     if (empty($username)) {
         $username = "******";
     }
     if (empty($userid)) {
         $userid = null;
     }
     $log = new AuditTrail();
     $log->old_value = '';
     $log->new_value = '';
     $log->action = 'DELETE';
     $log->model = get_class($this->Owner);
     $log->model_id = $this->Owner->getPrimaryKey();
     $log->field = 'N/A';
     $log->stamp = date('Y-m-d H:i:s');
     $log->user_id = $userid;
     $log->save();
     return parent::afterDelete($event);
 }
 public function leaveTrail($action, $name = null, $value = null, $old_value = null)
 {
     $log = new AuditTrail();
     $log->old_value = $old_value;
     $log->new_value = $value;
     $log->action = $action;
     $log->model = get_class($this->getOwner());
     // Gets a plain text version of the model name
     $log->model_id = $this->getNormalizedPk();
     $log->field = $name;
     $log->stamp = $this->storeTimestamp ? time() : date($this->dateFormat);
     // If we are storing a timestamp lets get one else lets get the date
     $log->user_id = $this->getUserId();
     // Lets get the user id
     return $log->save();
 }