public function getUiname($opr_cmd_id) { $query = DcmdOprCmd::findOne($opr_cmd_id); if ($query) { return $query['ui_name']; } return ""; }
/** * Lists all DcmdGroupCmd models. * @return mixed */ public function actionAddGroup($opr_cmd_id = 0) { if (Yii::$app->user->getIdentity()->admin != 1) { Yii::$app->getSession()->setFlash('success', NULL); Yii::$app->getSession()->setFlash('error', "对不起,你没有权限!"); return $this->redirect(['dcmd-opr-cmd/view', 'id' => $opr_cmd_id]); } $model = new DcmdGroupCmd(); if (Yii::$app->request->post()) { ///var_dump(Yii::$app->request->post());exit; $date = date('Y-m-d H:i:s'); if (is_array(Yii::$app->request->post()['DcmdGroupCmd']['gid'])) { foreach (Yii::$app->request->post()['DcmdGroupCmd']['gid'] as $gid) { $dcmd_group_cmd = new DcmdGroupCmd(); $dcmd_group_cmd->gid = $gid; $dcmd_group_cmd->opr_cmd_id = $opr_cmd_id; $dcmd_group_cmd->utime = $date; $dcmd_group_cmd->ctime = $date; $dcmd_group_cmd->opr_uid = Yii::$app->user->getId(); $dcmd_group_cmd->save(); Yii::$app->getSession()->setFlash('success', '添加成功!'); } } else { Yii::$app->getSession()->setFlash('error', "没有选择用户组!"); } return $this->redirect(['dcmd-opr-cmd/view', 'id' => $opr_cmd_id]); } else { $exist_group = array(); $query = DcmdGroupCmd::find()->andWhere(['opr_cmd_id' => $opr_cmd_id])->asArray()->all(); foreach ($query as $item) { $exist_group[$item['gid']] = $item['gid']; } $query = DcmdGroup::find()->andWhere(['gtype' => 2])->asArray()->all(); $group = array(); foreach ($query as $item) { if (!array_key_exists($item['gid'], $exist_group)) { $group[$item['gid']] = $item['gname']; } } $opr_cmd = DcmdOprCmd::findOne($opr_cmd_id); return $this->render('add_group', ['model' => $model, 'opr_cmd' => $opr_cmd, 'group' => $group]); } }
/** * Updates an existing DcmdOprCmdArg model. * If update is successful, the browser will be redirected to the 'view' page. * @param integer $id * @return mixed */ public function actionUpdate($id) { $model = $this->findModel($id); if (Yii::$app->user->getIdentity()->admin != 1) { Yii::$app->getSession()->setFlash('success', NULL); Yii::$app->getSession()->setFlash('error', "对不起,你没有权限!"); return $this->redirect(['dcmd-opr-cmd/view', 'id' => $model['opr_cmd_id']]); } $opr = DcmdOprCmd::findOne($model['opr_cmd_id']); if (Yii::$app->request->post()) { $model->utime = date('Y-m-d H:i:s'); $model->opr_uid = Yii::$app->user->getId(); } if ($model->load(Yii::$app->request->post()) && $model->save()) { Yii::$app->getSession()->setFlash('success', '修改成功!'); return $this->redirect(['dcmd-opr-cmd/view', 'id' => $model['opr_cmd_id']]); } else { return $this->render('update', ['model' => $model, 'opr' => $opr]); } }
public function getArg($arg, $change = false, $opr_cmd = NULL) { $query = xml_to_array($arg); if (!is_array($query)) { return ""; } if (!array_key_exists("env", $query)) { return ""; } if (!is_array($query['env'])) { return ""; } $content = ""; $q = $query['env']; $content .= '<table class="table table-striped table-bordered detail-view"> <tr> <td>参数名称</td> <td>值</td> </tr>'; foreach ($q as $k => $v) { if ($change) { $content .= "<tr><td>" . $k . "</td><td><input name='Arg" . $k . "' class='form-control' type='text' value='" . $v . "' ></td></tr>"; } else { $content .= "<tr><td>" . $k . '</td><td>' . $v . "</td></tr>"; } } ///检查是否有新参数 if ($opr_cmd) { $query = DcmdOprCmd::findOne(['opr_cmd' => $opr_cmd]); if ($query) { $query = DcmdOprCmdArg::find()->andWhere(['opr_cmd_id' => $query['opr_cmd_id']])->asArray()->all(); foreach ($query as $item) { if (!array_key_exists($item['arg_name'], $q)) { if ($change) { $content .= "<tr><td>" . $item['arg_name'] . "</td><td><input name='Arg" . $item['arg_name'] . "' class='form-control' type='text' value='' ></td></tr>"; } else { $content .= "<tr><td>" . $item['arg_name'] . "</td><td></td></tr>"; } } } } } $content .= "</table>"; return $content; }
/** * Finds the DcmdOprCmd model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return DcmdOprCmd the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = DcmdOprCmd::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }