protected function createComponentAddEdit($name) { $form = new NAppForm($this, $name); $access = array(1 => 'Allow', 0 => 'Deny'); // roles $mroles = new RolesModel(); $roles = $mroles->getTreeValues(); // resources $resources[0] = '- All resources -'; $mresources = new ResourcesModel(); $rows = $mresources->getTreeValues(); foreach ($rows as $key => $row) { // function array_merge does't work correctly with integer indexes // manual array merge $resources[$key] = $row; } // privileges $privileges[0] = '- All privileges -'; $rows = dibi::fetchAll('SELECT id, name FROM [gui_acl_privileges] ORDER BY name;'); foreach ($rows as $row) { // function array_merge does't work correctly with integer indexes // manual array merge $privileges[$row->id] = $row->name; } //$renderer = $form->getRenderer(); //$renderer->wrappers['label']['suffix'] = ':'; //$form->addGroup('Add'); $form->addMultiSelect('role_id', 'Role', $roles, 15)->addRule(NForm::FILLED, 'You have to fill roles.'); $form->addMultiSelect('resource_id', 'Resources', $resources, 15)->addRule(NForm::FILLED, 'You have to fill resources.'); $form->addMultiSelect('privilege_id', 'Privileges', $privileges, 15)->addRule(NForm::FILLED, 'You have to fill privileges.'); //$form->addSelect('access', 'Access', $access) $form->addRadioList('access', 'Access', $access)->addRule(NForm::FILLED, 'You have to fill access.'); $form->addSubmit('assign', 'Assign'); $form->onSuccess[] = array($this, 'addEditOnFormSubmitted'); }
protected function createComponentAddEdit($name) { $resources[0] = ' '; $mresources = new ResourcesModel(); $rows = $mresources->getTreeValues(); foreach ($rows as $key => $row) { // function array_merge does't work correctly with integer indexes // manual array merge $resources[$key] = $row; } $form = new AppForm($this, $name); $renderer = $form->getRenderer(); $renderer->wrappers['label']['suffix'] = ':'; //$form->addGroup('Edit'); if (ACL_PROG_MODE) { $form->addText('name', 'Name', 30)->addRule(Form::FILLED, 'You have to fill name.')->getControlPrototype()->onChange("create_key()"); } else { $form->addText('name', 'Name', 30)->addRule(Form::FILLED, 'You have to fill name.'); } $form->addText('key_name', 'Key', 30)->setDisabled(ACL_PROG_MODE ? false : true); $form->addSelect('parent_id', 'Parent', $resources, 15); $form->addTextArea('comment', 'Comment', 40, 4)->addRule(Form::MAX_LENGTH, 'Comment must be at least %d characters.', 250); if ($this->getAction() == 'add') { $form->addSubmit('add', 'Add'); } else { $form->addSubmit('edit', 'Edit'); } $form->onSubmit[] = array($this, 'addEditOnFormSubmitted'); }
function load() { parent::load(); $this->msgText = ''; $this->isAdmin = $this->data['player_type'] == PLAYERTYPE_ADMIN; if (!$this->isAdmin) { exit(0); return null; } $this->villageId = isset($_GET['avid']) ? intval($_GET['avid']) : 0; if ($this->villageId <= 0) { exit(0); return null; } $m = new ResourcesModel(); if ($this->isPost()) { $r1 = isset($_POST['r1']) && 0 <= intval($_POST['r1']) ? intval($_POST['r1']) : 0 - 1; $r2 = isset($_POST['r2']) && 0 <= intval($_POST['r2']) ? intval($_POST['r2']) : 0 - 1; $r3 = isset($_POST['r3']) && 0 <= intval($_POST['r3']) ? intval($_POST['r3']) : 0 - 1; $r4 = isset($_POST['r4']) && 0 <= intval($_POST['r4']) ? intval($_POST['r4']) : 0 - 1; $m->updateVillageResources($this->villageId, array('1' => $r1, '2' => $r2, '3' => $r3, '4' => $r4)); $this->msgText = data_saved; } $row = $m->getVillageData($this->villageId); if ($row == NULL || intval($row['player_id']) == 0 || $row['is_oasis']) { exit(0); return null; } $this->villageName = $row['village_name']; $this->playerName = $row['player_name']; $this->resources = array(); $elapsedTimeInSeconds = $row['elapsedTimeInSeconds']; $r_arr = explode(',', $row['resources']); foreach ($r_arr as $r_str) { $r2 = explode(' ', $r_str); $prate = floor($r2[4] * (1 + $r2[5] / 100)) - ($r2[0] == 4 ? $row['crop_consumption'] : 0); $current_value = floor($r2[1] + $elapsedTimeInSeconds * ($prate / 3600)); if ($r2[2] < $current_value) { $current_value = $r2[2]; } $this->resources[$r2[0]] = array('current_value' => $current_value, 'store_max_limit' => $r2[2], 'store_init_limit' => $r2[3], 'prod_rate' => $r2[4], 'prod_rate_percentage' => $r2[5], 'calc_prod_rate' => $prate); } $m->dispose(); }