Exemplo n.º 1
0
 /**
  *Get dcmd node group name
  */
 public function getNodeGname($ngid)
 {
     $query = DcmdNodeGroup::findOne($ngid);
     if ($query) {
         return $query->ngroup_name;
     }
     return "";
 }
 /**
  * Finds the DcmdNodeGroup model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return DcmdNodeGroup the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = DcmdNodeGroup::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
 public function actionChangeNodeGroup()
 {
     $ngroup_id = Yii::$app->request->post()['ngroup_id'];
     $ids = explode(";", Yii::$app->request->post()['ids']);
     if ($ngroup_id == "") {
         Yii::$app->getSession()->setFlash('error', "未选择设备池!");
         return $this->redirect(['index']);
     }
     ///判断用户是否和该设备池子属于一个系统组
     $tmp = DcmdNodeGroup::findOne($ngroup_id);
     $query = DcmdUserGroup::findOne(['uid' => Yii::$app->user->getId(), 'gid' => $tmp['gid']]);
     if ($query == NULL) {
         Yii::$app->getSession()->setFlash('error', "没有权限切换到该服务池");
         return $this->redirect(['index']);
     }
     $ret_msg = "";
     foreach ($ids as $k => $id) {
         if ($id == "") {
             continue;
         }
         $model = $this->findModel($id);
         ///判断用户是否和该设备池子属于一个系统组
         $tmp = DcmdNodeGroup::findOne($model['ngroup_id']);
         $query = DcmdUserGroup::findOne(['uid' => Yii::$app->user->getId(), 'gid' => $tmp['gid']]);
         if ($query == NULL) {
             $ret_msg .= "没有权限变更:" . $model->ip . " ";
             continue;
         }
         $model->ngroup_id = $ngroup_id;
         $model->save();
         $ret_msg .= "变更成功:" . $model->ip . " ";
     }
     Yii::$app->getSession()->setFlash('success', $ret_msg);
     return $this->redirect(['index']);
 }
 /**
  * Updates an existing DcmdNodeGroupAttr model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param integer $id
  * @return mixed
  */
 public function actionUpdate($id, $ngroup_id)
 {
     $node_group = DcmdNodeGroup::findOne($ngroup_id);
     ///仅仅用户与该应用在同一个系统组才可以操作
     $query = DcmdUserGroup::findOne(['uid' => Yii::$app->user->getId(), 'gid' => $node_group->gid]);
     if ($query == NULL) {
         Yii::$app->getSession()->setFlash('success', NULL);
         Yii::$app->getSession()->setFlash('error', "对不起, 你没有权限!");
         return $this->redirect(['/dcmd-node-group/view', 'id' => $ngroup_id, 'show_div' => 'dcmd-node-group-attr']);
     }
     if ($id == 0) {
         ///需要新建
         $attr_id = Yii::$app->request->queryParams['attr_id'];
         $def_attr = DcmdNodeGroupAttrDef::findOne($attr_id);
         $query = DcmdNodeGroupAttr::findOne(['ngroup_id' => $ngroup_id, 'attr_name' => $def_attr->attr_name]);
         if (count($query) > 0) {
             $id = $query['id'];
         } else {
             $model = new DcmdNodeGroupAttr();
             $model->ngroup_id = $ngroup_id;
             $model->attr_name = $def_attr->attr_name;
             $model->attr_value = $def_attr->def_value;
             $model->comment = $def_attr->comment;
             $model->utime = date('Y-m-d H:i:s');
             $model->ctime = $model->utime;
             $model->opr_uid = Yii::$app->user->getId();
             $model->save();
             $id = $model->id;
         }
     }
     $model = $this->findModel($id);
     $group = DcmdNodeGroup::findOne($model->ngroup_id);
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         Yii::$app->getSession()->setFlash('success', '修改成功!');
         return $this->redirect(['/dcmd-node-group/view', 'id' => $group->ngroup_id, 'show_div' => 'dcmd-node-group-attr']);
     } else {
         return $this->render('update', ['model' => $model, 'group' => $group]);
     }
 }