コード例 #1
0
ファイル: LogsController.php プロジェクト: BroneKot/CS-Bans
 public function loadModel($id)
 {
     $model = Logs::model()->findByPk($id);
     if ($model === null) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     return $model;
 }
コード例 #2
0
 /**
  * Get all project activity
  * @param string $moduleName
  * @return model list of log activity
  */
 public function getActivity($moduleName)
 {
     $project_idSelected = Yii::app()->user->getState('project_selected');
     if (empty($project_idSelected)) {
         $projectList = array();
         $Projects = Yii::app()->user->getProjects();
         foreach ($Projects as $project) {
             array_push($projectList, $project->project_id);
         }
     }
     return Logs::model()->findActivity($moduleName, !empty($project_idSelected) ? array($project_idSelected) : $projectList);
 }
コード例 #3
0
 /**
  * Updates a particular model.
  * If update is successful, the browser will be redirected to the 'view' page.
  */
 public function actionUpdate()
 {
     if (Yii::app()->user->checkAccess('updateDiagrams')) {
         $model = $this->loadModel();
         if (isset($_POST['Diagrams'])) {
             $model->attributes = $_POST['Diagrams'];
             if ($model->save()) {
                 // Guardar log
                 $attributes = array('log_date' => date("Y-m-d G:i:s"), 'log_activity' => 'DiagramUpdated', 'log_resourceid' => $model->diagram_id, 'log_type' => 'updated', 'user_id' => Yii::app()->user->id, 'module_id' => Yii::app()->controller->id, 'project_id' => $model->project_id);
                 Logs::model()->saveLog($attributes);
                 $this->redirect(array('view', 'id' => $model->diagram_id));
             }
         }
         $this->render('update', array('model' => $model));
     } else {
         throw new CHttpException(403, Yii::t('site', '403_Error'));
     }
 }
コード例 #4
0
ファイル: MiniLog.php プロジェクト: youngsun45/miniyun
 /**
  * 假删除日志
  */
 public function feignDeleteLogs($userId, $type = '')
 {
     $criteria = new CDbCriteria();
     $criteria->condition = 'user_id=:user_id';
     $criteria->params = array(':user_id' => $userId);
     $attributes = array('is_deleted' => 1);
     if ($type == '0') {
         $criteria->addCondition("type =:type", "and");
         $criteria->params[':type'] = $type;
     }
     Logs::model()->updateAll($attributes, $criteria);
     if ($this->hasCache === true) {
         $this->cleanCache($userId);
     }
 }
コード例 #5
0
 /**
  * Updates a particular model.
  * If update is successful, the browser will be redirected to the 'view' page.
  */
 public function actionUpdate()
 {
     if (Yii::app()->user->checkAccess('updateUsers')) {
         $allowEdit = false;
         $model = $this->loadModel();
         $tmppw = $model->user_password;
         if (!empty($model->address_id)) {
             $address = Address::model()->findByPk($model->address_id);
         } else {
             $address = new Address();
         }
         $userManager = Yii::app()->user->IsManager;
         if ($model->user_id == Yii::app()->user->id || $userManager || Yii::app()->user->IsAdministrator) {
             $allowEdit = true;
         }
         if (isset($_POST['Users']) && isset($_POST['Address'])) {
             $model->attributes = $_POST['Users'];
             $address->attributes = $_POST['Address'];
             if (isset($_POST['Users']['user_password'])) {
                 $model->user_password = md5($model->user_password);
             }
             $valid = $address->validate();
             $valid = $model->validate() && $valid;
             if ($valid) {
                 $address->save(false);
                 $model->address_id = $address->primaryKey;
                 if ($model->save(false)) {
                     // Guardar log
                     $attributes = array('log_date' => date("Y-m-d G:i:s"), 'log_activity' => 'UserUpdated', 'log_resourceid' => $model->user_id, 'log_type' => 'updated', 'user_id' => Yii::app()->user->id, 'module_id' => Yii::app()->controller->id);
                     Logs::model()->saveLog($attributes);
                     $this->redirect(array('view', 'id' => $model->user_id));
                 }
             }
         }
         $this->render('update', array('model' => $model, 'allowEdit' => $allowEdit, 'userManager' => $userManager, 'address' => $address));
     } else {
         throw new CHttpException(403, Yii::t('site', '403_Error'));
     }
 }
コード例 #6
0
ファイル: admin.php プロジェクト: urichalex/CS-Bans
 */
$this->pageTitle = Yii::app()->name . ' :: Админцентр - Системный лог';
$this->breadcrumbs = array('Админцентр' => array('/admin/index'), 'Системный лог');
$this->menu = array(array('label' => 'Удалить все записи', 'url' => '#', 'linkOptions' => array('id' => 'clearLog')));
Yii::app()->clientScript->registerScript('', '
	$("a#clearLog").click(function(){
		if(!confirm("Удалить все записи лога?"))
			return false;

		var ret = "";

		$.post("", {"clearlog": 1}, function(data){
			jQuery("#logs-grid").yiiGridView("update");
			alert("Лог очищен");
		});
		return false;
	});
    function reinstallDatePicker(id, data) {
		$("#timestamp").datepicker(jQuery.extend({showMonthAfterYear:false},jQuery.datepicker.regional["ru"],{"showAnim":"fold"}));
	}
');
$this->renderPartial('/admin/mainmenu', array('active' => 'site', 'activebtn' => 'logs'));
?>

<h2>Системный лог</h2>

<?php 
$criteria = new CDbCriteria();
$criteria->group = 'username';
$this->widget('bootstrap3.widgets.BsGridView', array('id' => 'logs-grid', 'type' => 'bordered', 'enableHistory' => true, 'dataProvider' => $model->search(), 'filter' => $model, 'afterAjaxUpdate' => 'reinstallDatePicker', 'columns' => array(array('name' => 'timestamp', 'type' => 'datetime', 'value' => '$data->timestamp', 'filter' => $this->widget('zii.widgets.jui.CJuiDatePicker', array('model' => $model, 'id' => 'timestamp', 'attribute' => 'timestamp', 'language' => 'ru', 'i18nScriptFile' => 'jquery-ui-i18n.min.js', 'htmlOptions' => array('id' => 'timestamp', 'size' => '10', 'class' => 'form-control'), 'options' => array('showAnim' => 'fold')), true)), array('name' => 'username', 'filter' => CHtml::listData(Logs::model()->findAll($criteria), 'username', 'username')), array('name' => 'action', 'value' => 'Logs::getLogType($data->action)', 'filter' => Logs::getLogType(FALSE, TRUE)), array('class' => 'bootstrap3.widgets.BsButtonColumn', 'template' => '{view} {delete}'))));
コード例 #7
0
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreateProject()
 {
     // check if user has permissions to createProjects
     if (Yii::app()->user->checkAccess('createProjects') && Yii::app()->user->checkAccess('permissionsConfiguration') && Yii::app()->user->IsAdministrator) {
         // create Projects Object
         $model = new Projects();
         // if Projects form exist
         if (isset($_POST['Projects'])) {
             // set form elements to Projects model attributes
             $model->attributes = $_POST['Projects'];
             // validate and save
             if ($model->save()) {
                 // Create relation between user and project (this user will be first manager)
                 $modelForm = new ProjectsHasUsersForm();
                 $modelForm->project_id = $model->primaryKey;
                 $modelForm->user_id = Yii::app()->user->id;
                 $modelForm->isManager = 1;
                 $modelForm->saveUser();
                 // Select current project has default selection project
                 Yii::app()->user->setState('project_selected', $model->primaryKey);
                 Yii::app()->user->setState('project_selectedName', $model->project_name);
                 // save log
                 $attributes = array('log_date' => date("Y-m-d G:i:s"), 'log_activity' => 'ProjectCreated', 'log_resourceid' => $model->primaryKey, 'log_type' => Logs::LOG_ASSIGNED, 'user_id' => Yii::app()->user->id, 'module_id' => Yii::app()->controller->id, 'project_id' => $model->primaryKey);
                 Logs::model()->saveLog($attributes);
                 // to prevent F5 keypress, redirect to create page
                 Yii::app()->controller->redirect(Yii::app()->createUrl('projects/view', array('id' => $model->primaryKey)));
             }
         }
         $this->layout = 'column2';
         // output create page
         $this->render('../projects/create', array('model' => $model, 'companies' => Companies::model()->findCompanyList(Yii::app()->user->id), 'currencies' => Currencies::model()->findAll()));
     } else {
         throw new CHttpException(403, Yii::t('site', '403_Error'));
     }
 }
コード例 #8
0
 /**
  * Creates a new model.
  */
 public function actionCreate()
 {
     // create Comments Object
     $model = new Comments();
     // if Comments form exist
     if (isset($_POST['Comments'])) {
         // set form elements to Comments model attributes
         $model->attributes = $_POST['Comments'];
         $module = Modules::model()->find(array('condition' => 't.module_name = :module_name', 'params' => array(':module_name' => $model->module_id)));
         // set module_id finded to model
         $model->module_id = $module->module_id;
         $project = Yii::app()->user->getState('project_selected');
         $model->project_id = $project;
         // validate and save
         if ($model->save()) {
             // create an instance of file uploaded
             $image = CUploadedFile::getInstancesByName('Comment');
             // if file upload exist
             if (count($image > 0)) {
                 // for each file uploaded
                 for ($i = 0; $i < count($image); $i++) {
                     // create an Document object
                     $modeldocs = new Documents();
                     $modeldocs->image = $image[$i];
                     if (!$modeldocs->image->getError()) {
                         // name is formed by date(day+month+year+hour+minutes+seconds+dayofyear+microtime())
                         $this->tmpFileName = str_replace(" ", "", date('dmYHis-z-') . microtime());
                         // set the extension file uploaded
                         $extension = $modeldocs->image->getExtensionName();
                         // if no error saving file
                         if ($modeldocs->image->saveAs(self::FOLDERIMAGES . $this->tmpFileName . '.' . $extension)) {
                             $modeldocs->project_id = $project;
                             $modeldocs->document_name = substr($modeldocs->image->getName(), 0, 30);
                             $modeldocs->document_description = $model->comment_text;
                             $modeldocs->document_path = self::FOLDERIMAGES . $this->tmpFileName . '.' . $extension;
                             $modeldocs->document_revision = '1';
                             $modeldocs->document_uploadDate = date("Y-m-d");
                             $modeldocs->document_type = $modeldocs->image->getType();
                             $modeldocs->document_baseRevision = date('dmYHis');
                             $modeldocs->user_id = Yii::app()->user->id;
                             $modeldocs->comment_id = $model->primaryKey;
                             // save file uploaded as document
                             if ($modeldocs->save()) {
                                 Yii::app()->user->setFlash('CommentMessageSuccess', $modeldocs->image->getName() . " " . Yii::t('comments', 'UploadOk'));
                             } else {
                                 Yii::app()->user->setFlash('CommentMessage', $modeldocs->getErrors());
                             }
                         } else {
                             Yii::app()->user->setFlash('CommentMessage', $modeldocs->image->getName() . " " . Yii::t('comments', 'UploadError'));
                         }
                     } else {
                         Yii::app()->user->setFlash('CommentMessage', $modeldocs->image->error . " " . Yii::t('comments', 'UploadCheckErrors'));
                     }
                 }
             }
             // save log
             $attributes = array('log_date' => date("Y-m-d G:i:s"), 'log_activity' => 'CommentPosted', 'log_resourceid' => $model->comment_resourceid, 'log_type' => Logs::LOG_COMMENTED, 'log_commentid' => $model->primaryKey, 'user_id' => Yii::app()->user->id, 'module_id' => $module->module_name, 'project_id' => $project);
             Logs::model()->saveLog($attributes);
             // find project managers to sent comment via mail
             $recipientsList = array();
             $ProjectManagers = Projects::model()->findManagersByProject($project);
             $managersArray = array();
             foreach ($ProjectManagers as $manager) {
                 $managersArray['email'] = $manager->user_email;
                 $managersArray['name'] = $manager->CompleteName;
                 array_push($recipientsList, $managersArray);
             }
             // find task owners to send comment via mail
             if ($module->module_name == 'tasks') {
                 $collaborators = Projects::model()->findAllUsersByProject($project);
                 $ColaboratorsArray = array();
                 foreach ($collaborators as $colaborator) {
                     $ColaboratorsArray['email'] = $colaborator->user_email;
                     $ColaboratorsArray['name'] = $colaborator->CompleteName;
                     // avoid to repeat email address
                     if (!in_array($ColaboratorsArray, $recipientsList)) {
                         array_push($recipientsList, $ColaboratorsArray);
                     }
                 }
             }
             // finding resource title
             switch ($module->module_name) {
                 case "budgets":
                     $resourceModelTitle = Budgets::model()->findByPk($model->comment_resourceid)->budget_title;
                     break;
                 case "invoices":
                     $resourceModelTitle = Invoices::model()->findByPk($model->comment_resourceid)->invoice_number;
                     break;
                 case "expenses":
                     $resourceModelTitle = Expenses::model()->findByPk($model->comment_resourceid)->expense_name;
                     break;
                 case "documents":
                     $resourceModelTitle = Documents::model()->findByPk($model->comment_resourceid)->document_name;
                     break;
                 case "milestones":
                     $resourceModelTitle = Milestones::model()->findByPk($model->comment_resourceid)->milestone_title;
                     break;
                 case "cases":
                     $resourceModelTitle = Cases::model()->findByPk($model->comment_resourceid)->case_name;
                     break;
                 case "tasks":
                     $resourceModelTitle = Tasks::model()->findByPk($model->comment_resourceid)->task_name;
                     break;
                 default:
                     $resourceModelTitle = "{empty}";
                     break;
             }
             // get project information
             $project = Projects::model()->findByPk($project);
             // prepare template to send via email
             $str = $this->renderPartial('//templates/comments/created', array('model' => $model, 'projectName' => $project->project_name, 'userposted' => Yii::app()->user->CompleteName, 'resourceTitle' => $resourceModelTitle, 'moduleName' => Yii::t('modules', $module->module_name), 'applicationName' => Yii::app()->name, 'applicationUrl' => Yii::app()->createAbsoluteUrl($module->module_name . '/view', array('id' => $model->comment_resourceid))), true);
             Yii::import('application.extensions.phpMailer.yiiPhpMailer');
             $mailer = new yiiPhpMailer();
             $subject = Yii::t('email', 'CommentPosted') . " - " . $project->project_name . " - " . Yii::t('modules', $module->module_name);
             $mailer->pushMail($subject, $str, $recipientsList, Emails::PRIORITY_NORMAL);
         } else {
             Yii::app()->user->setFlash('CommentMessage', Yii::t('comments', 'RequiredComment'));
         }
     }
     $this->redirect(Yii::app()->createUrl($_GET['module'] . '/' . $_GET['action'], array('id' => $_GET['id'], '#' => 'comment-' . $model->primaryKey)));
 }
コード例 #9
0
 /**
  * Updates a particular model.
  * @param integer $_GET['id'] the ID of the model to be updated
  * @return update view
  */
 public function actionUpdate()
 {
     // check if user has permissions to updateClients
     if (Yii::app()->user->checkAccess('updateClients')) {
         // get Clients object from $id parameter
         $model = $this->loadModel();
         // find client user data
         $modelUsers = Users::model()->together()->findByPk($model->user_id);
         // current user password
         $tmppw = $modelUsers->user_password;
         // if client hasn't address create an Address object, else load
         if (!empty($model->address_id)) {
             $address = Address::model()->findByPk($modelUsers->address_id);
         } else {
             $address = new Address();
         }
         // only users with administration rights or own user can update his profiles
         if ($modelUsers->user_id == Yii::app()->user->id || Yii::app()->user->IsAdministrator) {
             // if Users and Address form exist
             if (isset($_POST['Users']) && isset($_POST['Address'])) {
                 // set form elements to Users model attributes
                 $modelUsers->attributes = $_POST['Users'];
                 // set form elements to Address model attributes
                 $address->attributes = $_POST['Address'];
                 // if current password is different to new password
                 if (isset($_POST['Users']['user_password'])) {
                     $modelUsers->user_password = md5($modelUsers->user_password);
                 }
                 // validate both models
                 $valid = $address->validate();
                 $valid = $modelUsers->validate() && $valid;
                 if ($valid) {
                     // save address
                     $address->save(false);
                     $modelUsers->address_id = $address->primaryKey;
                     // save user
                     if ($modelUsers->save(false)) {
                         // save log
                         $attributes = array('log_date' => date("Y-m-d G:i:s"), 'log_activity' => 'ClientUpdated', 'log_resourceid' => $model->client_id, 'log_type' => Logs::LOG_UPDATED, 'user_id' => Yii::app()->user->id, 'module_id' => Yii::app()->controller->id);
                         Logs::model()->saveLog($attributes);
                         // to prevent F5 keypress, redirect to view page
                         $this->redirect(array('view', 'id' => $model->client_id));
                     }
                 }
             }
             $this->render('update', array('model' => $modelUsers, 'address' => $address));
         } else {
             throw new CHttpException(403, Yii::t('site', '403_Error'));
         }
     } else {
         throw new CHttpException(403, Yii::t('site', '403_Error'));
     }
 }
コード例 #10
0
 /**
  * Updates a particular model.
  * @return update view
  */
 public function actionUpdate()
 {
     // check if user has permissions to updateCompanies
     if (Yii::app()->user->checkAccess('updateCompanies')) {
         // get Company object from $id parameter
         $model = $this->loadModel();
         // if company hasn't address create an Address object, else load
         if (!empty($model->address_id)) {
             $address = Address::model()->findByPk($model->address_id);
         } else {
             $address = new Address();
         }
         // only users with administration rights or own user can update his profiles
         if (Yii::app()->user->IsAdministrator) {
             // if Company form exist
             if (isset($_POST['Companies'])) {
                 // set form elements to Companies model attributes
                 $model->attributes = $_POST['Companies'];
                 // set form elements to Address model attributes
                 $address->attributes = $_POST['Address'];
                 // validate both models
                 $valid = $address->validate();
                 $valid = $model->validate() && $valid;
                 if ($valid) {
                     // save address
                     $address->save(false);
                     $model->address_id = $address->primaryKey;
                     // save company
                     if ($model->save()) {
                         // save log
                         $attributes = array('log_date' => date("Y-m-d G:i:s"), 'log_activity' => 'CompanyUpdated', 'log_resourceid' => $model->company_id, 'log_type' => Logs::LOG_UPDATED, 'user_id' => Yii::app()->user->id, 'module_id' => Yii::app()->controller->id);
                         Logs::model()->saveLog($attributes);
                         // to prevent F5 keypress, redirect to view page
                         $this->redirect(array('view', 'id' => $model->company_id));
                     }
                 }
             }
         }
         $this->render('update', array('model' => $model, 'address' => $address));
     } else {
         throw new CHttpException(403, Yii::t('site', '403_Error'));
     }
 }
コード例 #11
0
 /**
  * Updates a particular model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param integer $id the ID of the model to be updated
  */
 public function actionUpdate($id)
 {
     // check if user has permissions to updateSecuences
     if (Yii::app()->user->checkAccess('updateSecuences')) {
         // get Projects object from id parameter
         $model = $this->loadModel($id);
         // verify Secuences form was used
         if (isset($_POST['Secuences'])) {
             // set form elements to secuences model attributes
             $model->attributes = $_POST['Secuences'];
             // validate and save
             if ($model->save()) {
                 // save log
                 $attributes = array('log_date' => date("Y-m-d G:i:s"), 'log_activity' => 'SecuenceUpdated', 'log_resourceid' => $model->case_id, 'log_type' => Logs::LOG_UPDATED, 'user_id' => Yii::app()->user->id, 'module_id' => 'cases', 'project_id' => $model->Cases->project_id);
                 Logs::model()->saveLog($attributes);
                 // redirect to prevent F5 keypress
                 $this->redirect(array('cases/view', 'id' => $model->case_id));
             }
         }
         // output update view
         $this->render('update', array('model' => $model, 'types' => SecuenceTypes::model()->findAll()));
     } else {
         throw new CHttpException(403, Yii::t('site', '403_Error'));
     }
 }
コード例 #12
0
 /**
  * Updates a particular model.
  * If update is successful, the browser will be redirected to the 'view' page.
  */
 public function actionUpdate()
 {
     // check if user has permissions to updateProjects
     if (Yii::app()->user->checkAccess('updateProjects')) {
         if (Yii::app()->user->isManager) {
             // get Projects object from $_GET[id] parameter
             $model = $this->loadModel();
             // if Projects form exist
             if (isset($_POST['Projects'])) {
                 // set form elements to Projects model attributes
                 $model->attributes = $_POST['Projects'];
                 // validate and save
                 if ($model->save()) {
                     // save log
                     $attributes = array('log_date' => date("Y-m-d G:i:s"), 'log_activity' => 'ProjectUpdated', 'log_resourceid' => $model->project_id, 'log_type' => Logs::LOG_UPDATED, 'user_id' => Yii::app()->user->id, 'module_id' => Yii::app()->controller->id, 'project_id' => $model->project_id);
                     Logs::model()->saveLog($attributes);
                     // to prevent F5 keypress, redirect to create page
                     $this->redirect(array('view', 'id' => $model->project_id));
                 }
             }
             // output update page
             $this->render('update', array('model' => $model, 'companies' => Companies::model()->findCompanyList(Yii::app()->user->id), 'currencies' => Currencies::model()->findAll()));
         } else {
             Yii::app()->controller->redirect(array("projects/view", 'id' => $_GET['id']));
         }
     } else {
         throw new CHttpException(403, Yii::t('site', '403_Error'));
     }
 }
コード例 #13
0
 /**
  * Updates a particular model.
  * @return update view
  */
 public function actionUpdate()
 {
     // check if user has permissions to updateInvoices
     if (Yii::app()->user->checkAccess('updateInvoices')) {
         // get Invoices object from $_GET['id'] parameter
         $model = $this->loadModel();
         // find all budgets relateds to current project
         $Budgets = Budgets::model()->findBudgetsByProjects(Yii::app()->user->getState('project_selected'));
         // check if invoice hasn�t status cancelled, accepted or closed
         if ($model->status_id != Status::STATUS_CANCELLED && $model->status_id != Status::STATUS_ACCEPTED && $model->status_id != Status::STATUS_CLOSED) {
             // only managers can update budgets
             if (Yii::app()->user->IsManager) {
                 // if Invoices form exist
                 if (isset($_POST['Invoices'])) {
                     // set form elements to Invoices model attributes
                     $model->attributes = $_POST['Invoices'];
                     // validate and save
                     if ($model->save()) {
                         // save log
                         $attributes = array('log_date' => date("Y-m-d G:i:s"), 'log_activity' => 'InvoiceUpdated', 'log_resourceid' => $model->invoice_id, 'log_type' => Logs::LOG_UPDATED, 'user_id' => Yii::app()->user->id, 'module_id' => Yii::app()->controller->id, 'project_id' => $model->project_id);
                         Logs::model()->saveLog($attributes);
                         // to prevent F5 keypress, redirect to view page
                         $this->redirect(array('view', 'id' => $model->invoice_id));
                     }
                 }
                 $this->render('update', array('invoice' => $model, 'budgets' => $Budgets));
             } else {
                 Yii::app()->controller->redirect(array("invoices/view", 'id' => $model->invoice_id));
             }
         } else {
             Yii::app()->controller->redirect(array("invoices/view", 'id' => $model->invoice_id));
         }
     } else {
         throw new CHttpException(403, Yii::t('site', '403_Error'));
     }
 }
コード例 #14
0
 /**
  * Updates a particular model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param integer $id the ID of the model to be updated
  */
 public function actionUpdate($id)
 {
     if (Yii::app()->user->checkAccess('updateTasks')) {
         $allowEdit = false;
         $model = $this->loadModel($id);
         if ($model->status_id != Status::STATUS_CANCELLED && $model->status_id != Status::STATUS_ACCEPTED && $model->status_id != Status::STATUS_CLOSED) {
             if ($model->user_id == Yii::app()->user->id) {
                 $allowEdit = true;
             }
             $Milestones = Milestones::model()->findMilestonesByProject($model->project_id);
             $Cases = Cases::model()->findCasesByProject($model->project_id);
             if (isset($_POST['Tasks'])) {
                 $model->attributes = $_POST['Tasks'];
                 $model->user_id = Yii::app()->user->id;
                 $model->task_startDate = date("Y-m-d");
                 //new CDbExpression('NOW()');
                 if ($model->save()) {
                     // Guardar log
                     $attributes = array('log_date' => date("Y-m-d G:i:s"), 'log_activity' => 'TaskUpdated', 'log_resourceid' => $model->task_id, 'log_type' => Logs::LOG_UPDATED, 'user_id' => Yii::app()->user->id, 'module_id' => Yii::app()->controller->id, 'project_id' => $model->project_id);
                     Logs::model()->saveLog($attributes);
                     $this->redirect(array('view', 'id' => $model->task_id));
                 }
             }
             $this->render('update', array('model' => $model, 'status' => Status::model()->findAll(), 'types' => TaskTypes::model()->findAll(), 'stages' => TaskStages::model()->findAll(), 'milestones' => $Milestones, 'cases' => $Cases, 'allowEdit' => $allowEdit));
         } else {
             Yii::app()->controller->redirect(array("tasks/view", 'id' => $model->task_id));
         }
     } else {
         throw new CHttpException(403, Yii::t('site', '403_Error'));
     }
 }
コード例 #15
0
 /**
  * Updates a particular model.
  * @param integer $id the ID of the model to be updated
  * @return update view
  */
 public function actionUpdate($id)
 {
     // check if user has permissions to updateCases
     if (Yii::app()->user->checkAccess('updateCases')) {
         // get Cases object from $_GET[id] parameter
         $model = $this->loadModel($id);
         // only managers can update Cases
         if (Yii::app()->user->IsManager) {
             // if Cases form exist
             if (isset($_POST['Cases'])) {
                 // set form elements to Cases model attributes
                 $model->attributes = $_POST['Cases'];
                 // validate and save
                 if ($model->save()) {
                     // save log
                     $attributes = array('log_date' => date("Y-m-d G:i:s"), 'log_activity' => 'CaseUpdated', 'log_resourceid' => $model->case_id, 'log_type' => Logs::LOG_UPDATED, 'user_id' => Yii::app()->user->id, 'module_id' => Yii::app()->controller->id, 'project_id' => $model->project_id);
                     Logs::model()->saveLog($attributes);
                     // to prevent F5 keypress, redirect to view page
                     $this->redirect(array('view', 'id' => $model->case_id));
                 }
             }
             $this->render('update', array('model' => $model));
         } else {
             Yii::app()->controller->redirect(array("cases/view", 'id' => $model->case_id));
         }
     } else {
         throw new CHttpException(403, Yii::t('cases', '403_ErrorCase'));
     }
 }
コード例 #16
0
 /**
  * Deletes a particular model.
  * @return json object {amount,success}
  */
 public function actionDelete()
 {
     // check if user has permission to delete budgetsConcepts
     if (Yii::app()->user->checkAccess('deleteBudgetConcepts')) {
         // verify is a POST request / YII_CSRF_TOKEN
         if (Yii::app()->request->isPostRequest) {
             // verify owner param exist
             if (isset($_GET['owner']) && !empty($_GET['owner'])) {
                 // verify if BudgetConcept item parent Budget has status = pending and budget project_id its same as project_id selected
                 $budget = Budgets::model()->with('Projects.Company')->together()->findByPk((int) $_GET['owner']);
                 if ($budget->status_id == Status::STATUS_PENDING && $budget->project_id == Yii::app()->user->getState('project_selected')) {
                     // we only allow deletion via POST request
                     $concept = $this->loadModel();
                     $result = array();
                     $result['success'] = false;
                     // delete concept
                     if ($concept->delete()) {
                         // Save log
                         $attributes = array('log_date' => date("Y-m-d G:i:s"), 'log_activity' => 'BudgetConceptDeleted', 'log_resourceid' => $budget->budget_id, 'log_type' => Logs::LOG_DELETED, 'user_id' => Yii::app()->user->id, 'module_id' => Yii::app()->controller->id, 'project_id' => $budget->Projects->project_id);
                         Logs::model()->saveLog($attributes);
                         // amount it's used to update amount budget and returner via json object
                         $result['amount'] = Yii::app()->numberFormatter->formatCurrency(CHtml::encode($budget->Cost), $budget->Projects->Currency->currency_code);
                         $result['success'] = true;
                     }
                     // output json object
                     echo CJSON::encode($result);
                     Yii::app()->end();
                 } else {
                     throw new CHttpException(403, Yii::t('site', '403_Error'));
                 }
             } else {
                 throw new CHttpException(403, Yii::t('site', '403_Error'));
             }
         } else {
             throw new CHttpException(403, Yii::t('site', '403_Error'));
         }
     } else {
         throw new CHttpException(403, Yii::t('site', '403_Error'));
     }
 }
コード例 #17
0
 public function getCountComments($module_name, $resource_id)
 {
     //get_class($this)
     $criteria = new CDbCriteria();
     $criteria->compare('module_name', $module_name);
     $module_id = Modules::model()->find($criteria)->module_id;
     return Logs::model()->count(array('condition' => 't.module_id = :module_id AND t.log_resourceid = :resource_id AND t.log_commentid <> 0', 'params' => array(':module_id' => $module_id, ':resource_id' => $resource_id)));
 }
コード例 #18
0
 /**
  * Updates a particular model.
  * If update is successful, the browser will be redirected to the 'view' page.
  */
 public function actionUpdate()
 {
     // verify if user has permissions to updateDownloads
     if (Yii::app()->user->checkAccess('updateDownloads')) {
         // find item object using param _id
         $modelUpdate = $this->loadModel();
         // verify Documents _POST exist
         if (isset($_POST['Documents'])) {
             // set form elements to Documents model attributes
             $modelUpdate->attributes = $_POST['Documents'];
             // another model is required to create a revision
             $model = new Documents();
             $model->attributes = $_POST['Documents'];
             $model->project_id = $modelUpdate->project_id;
             $model->document_id = $modelUpdate->document_id;
             // verify file upload exist
             if (isset($_FILES['Documents']['tmp_name']['image']) && !empty($_FILES['Documents']['tmp_name']['image'])) {
                 // create an instance of uploaded file
                 $model->image = CUploadedFile::getInstance($model, 'image');
                 if (!$model->image->getError()) {
                     // name is formed by date(day+month+year+hour+minutes+seconds+dayofyear+microtime())
                     $this->tmpFileName = str_replace(" ", "", date('dmYHis-z-') . microtime());
                     $extension = explode(".", $model->image->getName());
                     $model->image->saveAs(DocumentsController::FOLDERIMAGES . $this->tmpFileName . '.' . $extension[1]);
                     $model->document_path = DocumentsController::FOLDERIMAGES . $this->tmpFileName . '.' . $extension[1];
                     $model->document_revision = $modelUpdate->document_revision + 1;
                     $model->document_uploadDate = date("Y-m-d");
                     $model->document_type = $model->image->getType();
                     $model->document_baseRevision = $modelUpdate->document_baseRevision;
                     $model->user_id = Yii::app()->user->id;
                     $model->document_id = null;
                 } else {
                     $model->addError('image', $model->image->getError());
                 }
             }
             // validate and save
             if ($model->save()) {
                 // save log
                 $attributes = array('log_date' => date("Y-m-d G:i:s"), 'log_activity' => 'DocumentUpdated', 'log_resourceid' => $model->document_id, 'log_type' => 'updated', 'user_id' => Yii::app()->user->id, 'module_id' => Yii::app()->controller->id, 'project_id' => $model->project_id);
                 Logs::model()->saveLog($attributes);
                 $this->redirect(array('view', 'id' => $model->document_id));
             }
         }
         // response with update view
         $this->render('update', array('model' => isset($_POST['Documents']) ? $model : $modelUpdate));
     } else {
         throw new CHttpException(403, Yii::t('site', '403_Error'));
     }
 }
コード例 #19
0
 /**
  * Updates a particular model.
  * @return update view
  */
 public function actionUpdate()
 {
     // check if user has permissions to updateMilestones
     if (Yii::app()->user->checkAccess('updateMilestones')) {
         // get Milestones object from $_GET['id'] parameter
         $model = $this->loadModel();
         // only managers can update budgets
         if (Yii::app()->user->IsManager) {
             // find all projects managers
             $Users = Projects::model()->findManagersByProject($model->project_id);
             if (isset($_POST['Milestones'])) {
                 // if Milestones form exist
                 $model->attributes = $_POST['Milestones'];
                 // validate and save
                 if ($model->save()) {
                     // save log
                     $attributes = array('log_date' => date("Y-m-d G:i:s"), 'log_activity' => 'MilestoneUpdated', 'log_resourceid' => $model->milestone_id, 'log_type' => 'updated', 'user_id' => Yii::app()->user->id, 'module_id' => Yii::app()->controller->id, 'project_id' => $model->project_id);
                     Logs::model()->saveLog($attributes);
                     // to prevent F5 keypress, redirect to view page
                     $this->redirect(array('view', 'id' => $model->milestone_id));
                 }
             }
             $this->render('update', array('model' => $model, 'users' => $Users));
         } else {
             Yii::app()->controller->redirect(array("milestones/view", 'id' => $model->milestone_id));
         }
     } else {
         throw new CHttpException(403, Yii::t('site', '403_Error'));
     }
 }