public function actionImport() { $file = $_FILES['file']; switch ($file['name']) { // SourceMod case 'admins.cfg': case 'admins_simple.ini': $server_groups = CHtml::listData(SBServerGroup::model()->findAll(), 'name', 'id'); // Detailed if ($file['name'] == 'admins.cfg') { $kv = new KeyValues('Admins'); $kv->load($file['tmp_name']); foreach ($kv as $name => $data) { $admin = new SBAdmin(); $admin->name = $name; $admin->auth = $data['auth']; $admin->identity = $data['identity']; if (isset($data['password'])) { $admin->new_password = $data['password']; $admin->server_password = $data['password']; } if (isset($data['group'])) { $admin->server_groups = array(); foreach ((array) $data['group'] as $group) { $admin->server_groups = array_merge($admin->server_groups, array($server_groups[$group])); } } $admin->save(); } } else { preg_match_all('/"(.+?)"[ \\t]*"(.+?)"([ \\t]*"(.+?)")?/', file_get_contents($file['tmp_name']), $admins); for ($i = 0; $i < count($admins[0]); $i++) { list($identity, $flags, $password) = array($admins[1][$i], $admins[2][$i], $admins[4][$i]); // Parse authentication type depending on identity if (preg_match(SourceBans::PATTERN_STEAM, $identity)) { $auth = SBAdmin::AUTH_STEAM; } else { if ($identity[0] == '!' && preg_match(SourceBans::PATTERN_IP, $identity)) { $auth = SBAdmin::AUTH_IP; } else { $auth = SBAdmin::AUTH_NAME; } } // Parse flags if ($flags[0] == '@') { $group = substr($flags, 1); } else { if (strpos($flags, ':') !== false) { list($immunity, $flags) = explode(':', $flags); } } $admin = new SBAdmin(); $admin->name = $identity; $admin->auth = $auth; $admin->identity = $identity; if (!empty($password)) { $admin->new_password = $password; $admin->server_password = $password; } if (isset($group)) { $admin->server_groups = array($server_groups[$group]); } $admin->save(); } } break; // Mani Admin Plugin // Mani Admin Plugin case 'clients.txt': $kv = new KeyValues(); $kv->load($file['tmp_name']); foreach ($kv['players'] as $name => $player) { $admin = new SBAdmin(); $admin->auth = SBAdmin::AUTH_STEAM; $admin->name = $name; $admin->identity = $player['steam']; $admin->save(); } break; default: throw new CHttpException(500, Yii::t('sourcebans', 'controllers.admins.import.error')); } SourceBans::log('Admins imported', 'Admins imported from ' . $file['name']); Yii::app()->user->setFlash('success', Yii::t('sourcebans', 'Imported successfully')); $this->redirect(array('admin/admins')); }
echo $form->dropDownList($model, 'group_id', CHtml::listData(SBGroup::model()->findAll(array('order' => 't.name')), 'id', 'name'), array('empty' => '- ' . Yii::t('sourcebans', 'None') . ' -')); ?> <?php echo $form->error($model, 'group_id'); ?> </div> </div> <div class="control-group"> <?php echo $form->label($model, 'server_groups.name', array('class' => 'control-label')); ?> <div class="controls"> <?php $server_groups = CHtml::listData($model->server_groups, 'id', 'id'); foreach (SBServerGroup::model()->findAll(array('order' => 't.name')) as $server_group) { ?> <?php $checkbox = CHtml::checkBox('SBAdmin[server_groups][' . $server_group->id . ']', in_array($server_group->id, $server_groups), array('value' => $server_group->id)) . CHtml::encode($server_group->name); ?> <?php echo CHtml::label($checkbox, 'SBAdmin_server_groups_' . $server_group->id, array('class' => 'checkbox')); } ?> </div> </div> <div class="control-group buttons"> <div class="controls"> <?php echo CHtml::submitButton(Yii::t('sourcebans', 'Save'), array('class' => 'btn'));
/** * Returns the data model based on the primary key given in the GET variable. * If the data model is not found, an HTTP exception will be raised. * @param integer $id the ID of the model to be loaded * @param string $type the type of the model to be loaded * @return SBGroup|SBServerGroup the loaded model * @throws CHttpException */ public function loadModel($id, $type) { if ($type == 'web') { $model = SBGroup::model()->findByPk($id); } else { $model = SBServerGroup::model()->findByPk($id); } if ($model === null) { throw new CHttpException(404, 'The requested page does not exist.'); } return $model; }