/** * Update group * * @param \Pop\Form\Form $form * @return void */ public function update(\Pop\Form\Form $form) { $fields = $form->getFields(); $group = Table\FieldGroups::findById($fields['id']); $group->name = $fields['name']; $group->order = (int) $fields['order']; $group->dynamic = (int) $fields['dynamic']; $group->update(); $this->data['id'] = $group->id; }
<?php require_once '../../bootstrap.php'; use Pop\Form\Form; use Pop\Validator; try { $fields = array('username' => array('type' => 'text', 'label' => 'Username:'******'required' => true, 'attributes' => array('size' => 40), 'validators' => new Validator\AlphaNumeric()), 'password' => array('type' => 'password', 'label' => 'Password:'******'required' => true, 'attributes' => array('size' => 40)), 'my_captcha' => array('type' => 'captcha', 'label' => 'Please Solve: ', 'attributes' => array('size' => 10), 'expire' => 120), 'submit' => array('type' => 'submit', 'value' => 'SUBMIT')); $form = new Form($_SERVER['PHP_SELF'], 'post', $fields, ' '); if ($_POST) { $form->setFieldValues($_POST, array('strip_tags' => null, 'htmlentities' => array(ENT_QUOTES, 'UTF-8'))); if (!$form->isValid()) { $form->render(); } else { // Option to clear out and reset security token $form->clear(); echo 'Form is valid.<br />' . PHP_EOL; print_r($form->getFields()); } } else { $form->render(); } echo PHP_EOL . PHP_EOL; } catch (\Exception $e) { echo $e->getMessage() . PHP_EOL . PHP_EOL; }
/** * Update user * * @param \Pop\Form\Form $form * @param \Pop\Config $config * @return void */ public function update(\Pop\Form\Form $form, $config) { $encOptions = $config->encryptionOptions->asArray(); $fields = $form->getFields(); $type = Table\UserTypes::findById($fields['type_id']); $user = Table\Users::findById($fields['id']); if (isset($user->id)) { // If there's a new password, set according to the user type if ($fields['password1'] != '' && $fields['password2'] != '') { $user->password = self::encryptPassword($fields['password1'], $type->password_encryption, $encOptions); } // Set role if (isset($fields['role_id'])) { $roleId = $fields['role_id'] == 0 ? null : $fields['role_id']; } else { $roleId = $user->role_id; } // Set verified and attempts $verified = isset($fields['verified']) ? $fields['verified'] : $user->verified; $failedAttempts = isset($fields['failed_attempts']) ? $fields['failed_attempts'] : $user->failed_attempts; $first = null === $user->role_id && null === $user->logins && $type->login; if (isset($fields['profile']) && $fields['profile']) { $siteIds = $user->site_ids; } else { $siteIds = isset($fields['site_ids']) ? serialize($fields['site_ids']) : serialize(array()); } // Save the user's updated data $user->role_id = $roleId; $user->username = isset($fields['username']) ? $fields['username'] : $fields['email1']; $user->email = $fields['email1']; $user->verified = $verified; $user->failed_attempts = $failedAttempts; $user->site_ids = $siteIds; $user->updated = date('Y-m-d H:i:s'); $sess = Session::getInstance(); if (isset($fields['reset_pwd']) && $fields['reset_pwd']) { $user->updated_pwd = date('Y-m-d H:i:s'); unset($sess->reset_pwd); } $sess->last_user_id = $user->id; if ($sess->user->id == $user->id) { $sess->user->username = $user->username; $sess->user->site_ids = unserialize($siteIds); } $user->update(); $this->data['id'] = $user->id; FieldValue::update($fields, $user->id); // Send verification if needed if ($first) { $this->sendApproval($user, $type); } } }
public function testRemoveElements() { $e = new Element('text', 'username', 'Username'); $c = new Checkbox('colors', array('Red', 'Green', 'Blue')); $r = new Radio('colors', array('Red', 'Green', 'Blue')); $f = new Form('/submit', 'post'); $f->addElements(array($e, $c, $r)); $f->removeElement('username'); $f->removeElement('colors'); $this->assertEquals(1, count($f->getFields())); }
/** * Update site * * @param \Pop\Form\Form $form * @return void */ public function update(\Pop\Form\Form $form) { $fields = $form->getFields(); $site = Table\Sites::findById($fields['id']); $docRoot = substr($fields['document_root'], -1) == '/' && substr($fields['document_root'], -1) == "\\" ? substr($fields['document_root'], 0, -1) : $fields['document_root']; $oldDocRoot = $site->document_root; $docRoot = str_replace('\\', '/', $docRoot); if ($fields['base_path'] != '') { $basePath = substr($fields['base_path'], 0, 1) != '/' && substr($fields['base_path'], 0, 1) != "\\" ? '/' . $fields['base_path'] : $fields['base_path']; if (substr($basePath, -1) == '/' && substr($basePath, -1) == "\\") { $basePath = substr($basePath, 0, -1); } } else { $basePath = ''; } $basePath = str_replace('\\', '/', $basePath); $site->domain = $fields['domain']; $site->document_root = $docRoot; $site->base_path = $basePath; $site->title = $fields['title']; $site->force_ssl = (int) $fields['force_ssl']; $site->live = (int) $fields['live']; $site->update(); $this->data['id'] = $site->id; FieldValue::update($fields, $site->id); if ($oldDocRoot != $docRoot) { $this->createFolders($docRoot, $basePath); // Copy any themes over $themes = Table\Extensions::findAll(null, array('type' => 0)); if (isset($themes->rows[0])) { $themePath = $docRoot . $basePath . CONTENT_PATH . '/extensions/themes'; foreach ($themes->rows as $theme) { if (!file_exists($themePath . '/' . $theme->name)) { copy($_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . BASE_PATH . DIRECTORY_SEPARATOR . CONTENT_PATH . DIRECTORY_SEPARATOR . 'extensions' . DIRECTORY_SEPARATOR . 'themes' . DIRECTORY_SEPARATOR . $theme->file, $themePath . '/' . $theme->file); $archive = new \Pop\Archive\Archive($themePath . '/' . $theme->file); $archive->extract($themePath . '/'); if ((stripos($theme->file, 'gz') || stripos($theme->file, 'bz')) && file_exists($themePath . '/' . $theme->name . '.tar')) { unlink($themePath . '/' . $theme->name . '.tar'); } } } } } }
/** * Update role * * @param \Pop\Form\Form $form * @return void */ public function update(\Pop\Form\Form $form) { $fields = $form->getFields(); $role = Table\UserRoles::findById($fields['id']); if (isset($role->id)) { $role->type_id = $fields['type_id']; $role->name = $fields['name']; $role->update(); $this->data['id'] = $role->id; } // Add new permissions if any $perms = array(); foreach ($_POST as $key => $value) { if (strpos($key, 'resource_new_') !== false || strpos($key, 'resource_cur_') !== false) { $id = substr($key, strrpos($key, '_') + 1); $cur = strpos($key, 'resource_new_') !== false ? 'new' : 'cur'; if ($value != '0') { $perm = $_POST['permission_' . $cur . '_' . $id] != '0' ? $_POST['permission_' . $cur . '_' . $id] : ''; if ($perm != '') { $perm .= $_POST['type_' . $cur . '_' . $id] != '0' ? '_' . $_POST['type_' . $cur . '_' . $id] : ''; } $perms[] = array('resource' => $value, 'permission' => $perm, 'allow' => (int) $_POST['allow_' . $cur . '_' . $id]); } } } // Remove and resource/permissions foreach ($_POST as $key => $value) { if (strpos($key, 'rm_resource_') !== false && isset($value[0])) { foreach ($perms as $k => $perm) { if ($role->id . '_' . $perm['resource'] . '_' . $perm['permission'] == $value[0]) { unset($perms[$k]); } } } } $role->permissions = serialize($perms); $role->update(); FieldValue::update($fields, $role->id); }
/** * Update field * * @param \Pop\Form\Form $form * @return void */ public function update(\Pop\Form\Form $form) { $fields = $form->getFields(); $curValidators = array(); $newValidators = array(); foreach ($_POST as $key => $value) { if (strpos($key, 'validator_new_') !== false && $value != '' && $value != '----') { $id = substr($key, strrpos($key, '_') + 1); $newValidators[$value] = array('value' => $_POST['validator_value_new_' . $id], 'message' => $_POST['validator_message_new_' . $id]); } else { if (strpos($key, 'validator_cur_') !== false) { $id = substr($key, strrpos($key, '_') + 1); if (!isset($_POST['validator_remove_cur_' . $id])) { if ($value != '' && $value != '----') { $curValidators[$value] = array('value' => $_POST['validator_value_cur_' . $id], 'message' => $_POST['validator_message_cur_' . $id]); } } } } } $validators = array_merge($curValidators, $newValidators); $field = Table\Fields::findById($fields['id']); $field->group_id = (int) $fields['group_id'] > 0 ? (int) $fields['group_id'] : null; $field->type = $fields['type']; $field->name = $fields['name']; $field->label = $fields['label']; $field->values = $fields['values']; $field->default_values = $fields['default_values']; $field->attributes = html_entity_decode($fields['attributes'], ENT_QUOTES, 'UTF-8'); $field->validators = count($validators) > 0 ? serialize($validators) : null; $field->encryption = (int) $fields['encryption']; $field->order = (int) $fields['order']; $field->required = (int) $fields['required']; $field->editor = $fields['editor'] != '0' ? $fields['editor'] : null; $field->update(); $this->data['id'] = $field->id; $models = array(); // Save field to model relationships foreach ($_POST as $key => $value) { if (substr($key, 0, 6) == 'model_' && $value != '0') { $cur = strpos($key, 'new_') !== false ? 'new_' : 'cur_'; $id = substr($key, strrpos($key, '_') + 1); $models[] = array('model' => $value, 'type_id' => (int) $_POST['type_id_' . $cur . $id]); } } // Remove field to model relationships foreach ($_POST as $key => $value) { if (strpos($key, 'rm_model_') !== false && isset($value[0])) { foreach ($models as $k => $model) { if ($field->id . '_' . $model['model'] . '_' . $model['type_id'] == $value[0]) { unset($models[$k]); } } } } $field->models = serialize($models); $field->update(); }