/** * admin gui for modifying LiveUser preferences * * @param string id * @param mixed data * @param string action * @return string page output response */ function ewiki_page_liveuser_admin_prefs($id, $data, $action) { global $liveuserDB; ob_start(); echo ewiki_make_title($id, $id, 2); // delete or update preference fields if (isset($_POST['changeprefs_submit'])) { // extract input fields foreach ($_POST as $key => $value) { list($prefix, $id) = explode('_', $key, 2); // deleted checked preferences if ($prefix == 'chk' && is_numeric($id) && $value == 'on') { if (liveuser_pref_removeField($id)) { echo '<p>Field ' . $id . ' was successfully deleted</p>.'; } else { echo '<p>An error occurred deleting field ' . $id . '</p>'; } } // update preference fields for differing new/old values if ($prefix == 'public' && is_numeric($id) && $_POST['origpublic_' . $id] != $value) { echo 'old value: ' . $_POST['origpublic_' . $id] . 'new value: ' . $value . '<br />'; } if ($prefix == 'default' && is_numeric($id) && $_POST['origdefault_' . $id] != $value) { echo 'old value: ' . $_POST['origdefault_' . $id] . 'new value: ' . $value . '<br />'; } } } // Handle POSTed new rows if (!empty($_POST['prefname_text'])) { $livewebpref = liveuser_pref_checkField($_POST['prefname_text']); if ($livewebpref === false) { if (!empty($_POST['default_text'])) { $livewebpref = $_POST['public_chk'] ? liveuser_pref_setField($_POST['prefname_text'], true, $_POST['default_text']) : liveuser_pref_setField($_POST['prefname_text'], false, $_POST['default_text']); } else { $livewebpref = $_POST['public_chk'] ? liveuser_pref_setField($_POST['prefname_text'], true) : liveuser_pref_setField($_POST['prefname_text'], false); } if ($livewebpref !== false) { echo $_POST['prefname_text'] . ' was inserted into liveweb_prefs_fields...'; } } else { echo $_POST['prefname_text'] . ' could NOT be inserted into liveweb_prefs_fields...'; } } echo '<br /><br />'; // Get list of prefs fields in liveuser system $results = $liveuserDB->getAll('SELECT * FROM liveweb_prefs_fields'); // show form for modifying preferences if (is_array($results) && !empty($results)) { ?> <form method="post" action=""> <h3>Modify Preference Fields</h3> <table border="1"> <tr><th>Delete</th><th>ID</th><th>Preference</th><th>Public</th><th>Default Value</th></tr> <?php foreach ($results as $result) { ?> <tr> <td><input name="chk_<?php echo $result['field_id']; ?> " type="checkbox"></td><td><?php echo $result['field_id']; ?> </td> <td><?php echo $result['field_name']; ?> </td> <td> <input name="origpublic_<?php echo $result['field_id']; ?> " value="<?php echo $result['public']; ?> " type="hidden"> <select id="public_<?php echo $result['field_id']; ?> " name="public_<?php echo $result['field_id']; ?> "> <option value="1" <?php echo $result['public'] == 1 ? 'selected="selected"' : ''; ?> >Y</option> <option value="0" <?php echo $result['public'] == 0 ? 'selected="selected"' : ''; ?> >N</option> </select> </td> <td> <input name="origdefault_<?php echo $result['field_id']; ?> " value="<?php echo $result['default_value']; ?> " type="hidden"> <input name="default_<?php echo $result['field_id']; ?> " value="<?php echo $result['default_value']; ?> "> </td> </tr> <?php } ?> </table> <input type="reset" text="Reset"> <input type="submit" name="changeprefs_submit"> </form> <?php } else { echo '<p>No preference fields were found.</p>'; } // show form for adding preferences ?> <form method="post" action=""> <h3>Add a Preference Field</h3> <label for="prefname_text">Preference Name</label> <input id="prefname_text" name="prefname_text" type="text"><br /> <label for="public_chk">Public</label> <input id="public_chk" name="public_chk" type="checkbox"><br /> <label for="default_text">Default Value</label> <input id="default_text" name="default_text" type="text"><br /> <input type="submit" name="addprefs_submit"> </form> <?php $o = ob_get_contents(); ob_end_clean(); return $o; }
/** * Copyright (c) 2003, The Burgiss Group, LLC * This source code is part of eWiki LiveUser Plugin. * * eWiki LiveUser Plugin is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2 of the License, or (at your * option) any later version. * * eWiki LiveUser Plugin is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * for more details. * * You should have received a copy of the GNU Lesser General Public License * along with Wiki LiveUser Plugin; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ require_once dirname(__FILE__) . '/pref_liveuser.php'; /* * key points to value which will later be used for the public variable; if there * is a default value, point to an array */ $prefs = array('Email' => true, 'FirstName' => true, 'MiddleName' => true, 'LastName' => true, 'Company' => true, 'Phone' => true, 'Address' => true, 'City' => true, 'State' => true, 'ZipCode' => true, 'Country' => true); $prefs_default_value = array('Country' => 'USA'); $prefs_possible_values = array('State' => array('Alabama', 'Alaska', 'Arizona', 'Arkansas', 'California', 'Colorado', 'Connecticut', 'Delaware', 'Florida', 'Georgia', 'Hawaii', 'Idaho', 'Illinois', 'Indiana', 'Iowa', 'Kansas', 'Kentucky', 'Louisiana', 'Maine', 'Maryland', 'Massachusetts', 'Michigan', 'Minnesota', 'Mississippi', 'Missouri', 'Montana', 'Nebraska', 'Nevada', 'New Hampshire', 'New Jersey', 'New Mexico', 'New York', 'North Carolina', 'North Dakota', 'Ohio', 'Oklahoma', 'Oregon', 'Pennsylvania', 'Rhode Island', 'South Carolina', 'South Dakota', 'Tennessee', 'Texas', 'Utah', 'Vermont', 'Virginia', 'Washington', 'West Virginia', 'Wisconsin', 'Wyoming')); // iterate through list of prefs and add them as user preference fields foreach ($prefs as $pref => $public) { liveuser_pref_setField($pref, $public, $prefs_default_value[$pref], $prefs_possible_values[$pref]); echo 'Added field ' . $pref . "\n"; }
/** * Sets the specified preference's value for the specified user. * * @param string username user handle * @param string field_name preference field name * @return boolean true if the preference was successfully set, false otherwise */ function liveuser_pref_setPref($username, $field_name, $field_value) { global $liveuserDB; $user_id = liveuser_getPermUserId($username); /* attempt to fetch existing field_id for the field_name, or create a new field if necessary */ if (($field_id = liveuser_pref_checkField($field_name)) === false && ($field_id = liveuser_pref_setField($field_name)) === false) { return false; } $pref_id = $liveuserDB->getOne(' SELECT pref_id FROM ' . LW_PREFIX . '_prefs_data WHERE user_id = ? AND field_id = ?', array((int) $user_id, (int) $field_id)); if (isset($pref_id) && is_numeric($pref_id)) { return $liveuserDB->query(' UPDATE ' . LW_PREFIX . '_prefs_data SET field_value = ? WHERE pref_id = ?', array($field_value, (int) $pref_id)) == DB_OK; } else { return $liveuserDB->query(' INSERT INTO ' . LW_PREFIX . '_prefs_data (field_value, user_id, field_id) VALUES (?, ?, ?)', array($field_value, (int) $user_id, (int) $field_id)) == DB_OK; } }