/**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     // check if user has permissions to createSecuences
     if (Yii::app()->user->checkAccess('createSecuences')) {
         // create secuences object
         $model = new Secuences();
         // find case parent
         $cases = Cases::model()->findByPk((int) $_GET['owner']);
         // output message
         $returnMessage = null;
         // verify Secuences form exist
         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' => 'SecuenceCreated', 'log_resourceid' => $model->case_id, 'log_type' => Logs::LOG_CREATED, 'user_id' => Yii::app()->user->id, 'module_id' => 'cases', 'project_id' => $model->Cases->project_id);
                 Logs::model()->saveLog($attributes);
                 $returnMessage = Yii::t('secuences', 'successMessage');
                 // create new secuence model for clear inputs form
                 $model = new Secuences();
             } else {
                 $returnMessage = Yii::t('secuences', 'errorMessage');
             }
         }
         // output create page
         $this->render('create', array('model' => $model, 'types' => SecuenceTypes::model()->findAll(), 'cases' => $cases, 'returnMessage' => $returnMessage));
     } else {
         throw new CHttpException(403, Yii::t('site', '403_Error'));
     }
 }
예제 #2
0
 public function actionEditProcess()
 {
     try {
         $post = StringHelper::filterArrayString($_POST);
         $result = Cases::model()->edit($_POST);
         if ($result == 1) {
             Yii::app()->user->setFlash('success', 'Cập nhật dữ liệu thành công !');
             $this->redirect(Yii::app()->createUrl('case/edit', array('id' => $post['id'])));
         } else {
             if ($result == 2) {
                 Yii::app()->user->setFlash('error', 'Cập nhật dữ liệu thất bại !');
                 $this->redirect(Yii::app()->createUrl('case/edit', array('id' => $post['id'])));
             } else {
                 Yii::app()->user->setFlash('error', 'Không tồn tại tài liệu !');
                 $this->redirect(Yii::app()->createUrl('case/edit', array('id' => $post['id'])));
             }
         }
     } catch (Exception $ex) {
         var_dump($ex->getMessage());
     }
 }
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     if (Yii::app()->user->checkAccess('createValidations')) {
         $model = new Validations();
         $cases = Cases::model()->findByPk($_GET['owner']);
         $returnMessage = null;
         if (isset($_POST['Validations'])) {
             $model->attributes = $_POST['Validations'];
             if ($model->save()) {
                 // Guardar log
                 $attributes = array('log_date' => date("Y-m-d G:i:s"), 'log_activity' => 'ValidationCreated', 'log_resourceid' => $model->case_id, 'log_type' => Logs::LOG_CREATED, 'user_id' => Yii::app()->user->id, 'module_id' => 'cases', 'project_id' => $model->Cases->project_id);
                 Logs::model()->saveLog($attributes);
                 //$this->redirect(Yii::app()->createUrl('secuences/create', array('owner'=>$cases->case_id)));
                 $returnMessage = "Validation was succefully created.";
                 $model = new Validations();
             }
         }
         $this->render('create', array('model' => $model, 'cases' => $cases, 'returnMessage' => $returnMessage));
     } else {
         throw new CHttpException(403, Yii::t('site', '403_Error'));
     }
 }
 /**
  * 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)));
 }
예제 #5
0
 public function actionPrintArea()
 {
     $documentary = Documentary::model()->searchByCondition($_GET, null, 2);
     $wanted_abroad = WantedAbroad::model()->searchByCondition($_GET, null, 2);
     $letters = Letters::model()->searchByCondition($_GET, null, 2);
     $cases = Cases::model()->searchByCondition($_GET, null, 2);
     $cases_abroad = CasesAbroadOther::model()->searchByCondition($_GET, null, 2);
     $opinion = Opinion::model()->searchByCondition($_GET, null, 2);
     $documentary_recieve = DocumentaryRecieve::model()->searchByCondition($_GET, null, 2);
     $documentary_abroad = DocumentaryAbroad::model()->searchByCondition($_GET, null, 2);
     $guide = Guide::model()->searchByCondition($_GET, null, 2);
     $result = array('documentary' => $documentary, 'wanted_abroad' => $wanted_abroad, 'letters' => $letters, 'cases' => $cases, 'cases_abroad' => $cases_abroad, 'opinion' => $opinion, 'documentary_recieve' => $documentary_recieve, 'documentary_abroad' => $documentary_abroad, 'guide' => $guide);
     $this->render('printArea', $result);
 }
 /**
  * Lists all models.
  */
 public function actionIndex()
 {
     if (Yii::app()->user->checkAccess('indexTasks')) {
         $view = Yii::app()->user->getState('view') != null ? Yii::app()->user->getState('view') : 'list';
         if (isset($_GET['view']) && !empty($_GET['view'])) {
             if ($_GET['view'] == 'grid') {
                 $view = 'grid';
             } elseif ($_GET['view'] == 'kanban') {
                 $view = 'kanban';
             } else {
                 $view = 'list';
             }
         }
         Yii::app()->user->setState('view', $view);
         $model = new TasksSearchForm();
         //$model->search();
         //$model->unsetAttributes();  // clear any default values
         $Milestones = Milestones::model()->with('Projects.Company.Cusers')->together()->findAll(array('condition' => 'Cusers.user_id = :user_id AND t.project_id = :project_id', 'params' => array(':user_id' => Yii::app()->user->id, ':project_id' => Yii::app()->user->getState('project_selected'))));
         $Cases = Cases::model()->with('Projects.Company.Cusers')->together()->findAll(array('condition' => 'Cusers.user_id = :user_id AND t.project_id = :project_id', 'params' => array(':user_id' => Yii::app()->user->id, ':project_id' => Yii::app()->user->getState('project_selected'))));
         if (isset($_GET['TasksSearchForm'])) {
             $model->attributes = $_GET['TasksSearchForm'];
         }
         if ($view == 'kanban') {
             $this->layout = 'column1';
         }
         $this->render('index', array('model' => $model, 'status' => Status::model()->findAllOrdered(), 'types' => TaskTypes::model()->findAll(), 'stages' => TaskStages::model()->findAll(), 'milestones' => $Milestones, 'cases' => $Cases, 'users' => Projects::model()->findAllUsersByProject(Yii::app()->user->getState('project_selected'))));
     } else {
         throw new CHttpException(403, Yii::t('site', '403_Error'));
     }
 }
예제 #7
0
파일: Cases.php 프로젝트: huynt57/vksnd
 public function searchByCondition($attr, $cnt = null, $pagination = 1)
 {
     $criteria = new CDbCriteria();
     if (!empty($attr['date_start']) && !empty($attr['date_end'])) {
         $date_start = strtotime($attr['date_start']);
         $date_end = strtotime($attr['date_end']);
         $criteria->addBetweenCondition('date_prosecution', $date_start, $date_end);
     }
     if (!empty($attr['obj_name'])) {
         $obj_name = $attr['obj_name'];
         $criteria->addSearchCondition('accused', $obj_name);
     }
     if (!empty($attr['assignee'])) {
         $assignee = $attr['assignee'];
         $criteria->addSearchCondition('investigator', $assignee);
     }
     if (!empty($attr['keyword'])) {
         $keyword = $attr['keyword'];
         $criteria->addSearchCondition('accused', $keyword, true, "OR", "LIKE");
         $criteria->addSearchCondition('investigator', $keyword, true, "OR", "LIKE");
         $criteria->addSearchCondition('detention_period', $keyword, true, "OR", "LIKE");
         $criteria->addSearchCondition('investigation_period', $keyword, true, "OR", "LIKE");
         $criteria->addSearchCondition('case_name', $keyword, true, "OR", "LIKE");
     }
     $count = Cases::model()->count($criteria);
     if (!empty($cnt)) {
         return $count;
     }
     if ($pagination != 1) {
         $result = Cases::model()->findAll($criteria);
         return $result;
     }
     $pages = new CPagination($count);
     // results per page
     $pages->pageSize = Yii::app()->params['limit'];
     $pages->applyLimit($criteria);
     $result = Cases::model()->findAll($criteria);
     return array('models' => $result, 'pages' => $pages);
 }
 /**
  * This method is invoked right before an action is to be executed (after all possible filters.)
  * @param CAction $action the action to be executed.
  * @return boolean whether the action should be executed
  */
 public function beforeAction($action)
 {
     $response = false;
     if (Yii::app()->user->getState('project_selected') != null) {
         if (in_array($action->id, array('view', 'update'))) {
             $response = Cases::model()->countCasesByProject((int) $_GET['id'], Yii::app()->user->getState('project_selected')) > 0 ? true : false;
         } else {
             $response = true;
         }
     } else {
         $response = false;
     }
     if (!$response) {
         throw new CHttpException(403, Yii::t('site', '403_Error'));
     } else {
         return $response;
     }
 }
예제 #9
0
 public function countCasesByProject($case_id, $project_id)
 {
     return Cases::model()->count(array('condition' => 't.project_id = :project_id AND t.case_id = :case_id', 'params' => array(':project_id' => $project_id, ':case_id' => $case_id)));
 }