/** * @static * @todo document this */ function _insertPluginOptions($context, $contextid = 0) { // get all current values for this contextid // (note: this might contain doubles for overlapping contextids) $aIdToValue = array(); $res = sql_query('SELECT oid, ovalue FROM ' . sql_table('plugin_option') . ' WHERE ocontextid=' . intval($contextid)); while ($o = sql_fetch_object($res)) { $aIdToValue[$o->oid] = $o->ovalue; } // get list of oids per pid $query = 'SELECT * FROM ' . sql_table('plugin_option_desc') . ',' . sql_table('plugin') . ' WHERE opid=pid and ocontext=\'' . sql_real_escape_string($context) . '\' ORDER BY porder, oid ASC'; $res = sql_query($query); $aOptions = array(); while ($o = sql_fetch_object($res)) { if (in_array($o->oid, array_keys($aIdToValue))) { $value = $aIdToValue[$o->oid]; } else { $value = $o->odef; } array_push($aOptions, array('pid' => $o->pid, 'pfile' => $o->pfile, 'oid' => $o->oid, 'value' => $value, 'name' => $o->oname, 'description' => $o->odesc, 'type' => $o->otype, 'typeinfo' => $o->oextra, 'contextid' => $contextid, 'extra' => '')); } global $manager; $manager->notify('PrePluginOptionsEdit', array('context' => $context, 'contextid' => $contextid, 'options' => &$aOptions)); $iPrevPid = -1; foreach ($aOptions as $aOption) { // new plugin? if ($iPrevPid != $aOption['pid']) { $iPrevPid = $aOption['pid']; if (!defined('_PLUGIN_OPTIONS_TITLE')) { define('_PLUGIN_OPTIONS_TITLE', 'Options for %s'); } echo '<tr><th colspan="2">' . sprintf(_PLUGIN_OPTIONS_TITLE, htmlspecialchars($aOption['pfile'], ENT_QUOTES)) . '</th></tr>'; } $meta = NucleusPlugin::getOptionMeta($aOption['typeinfo']); if (@$meta['access'] != 'hidden') { echo '<tr>'; listplug_plugOptionRow($aOption); echo '</tr>'; } } }
/** * Deletes an item */ function delete($itemid) { global $manager, $member; $itemid = intval($itemid); // check to ensure only those allow to alter the item can // proceed if (!$member->canAlterItem($itemid)) { return 1; } $manager->notify('PreDeleteItem', array('itemid' => $itemid)); // delete item $query = 'DELETE FROM ' . sql_table('item') . ' WHERE inumber=' . $itemid; sql_query($query); // delete the comments associated with the item $query = 'DELETE FROM ' . sql_table('comment') . ' WHERE citem=' . $itemid; sql_query($query); // delete all associated plugin options NucleusPlugin::_deleteOptionValues('item', $itemid); $manager->notify('PostDeleteItem', array('itemid' => $itemid)); return 0; }
/** * @param $aOptions: array ( 'oid' => array( 'contextid' => 'value')) * (taken from request using requestVar()) * @param $newContextid: integer (accepts a contextid when it is for a new * contextid there was no id available at the moment of writing the * formcontrols into the page (by ex: itemOptions for new item) * @static */ function _applyPluginOptions(&$aOptions, $newContextid = 0) { global $manager; if (!is_array($aOptions)) { return; } foreach ($aOptions as $oid => $values) { // get option type info $query = 'SELECT opid, oname, ocontext, otype, oextra, odef FROM ' . sql_table('plugin_option_desc') . ' WHERE oid=' . intval($oid); $res = sql_query($query); if ($o = sql_fetch_object($res)) { foreach ($values as $key => $value) { // avoid overriding the key used by foreach statement $contextid = $key; // retreive any metadata $meta = NucleusPlugin::getOptionMeta($o->oextra); // if the option is readonly or hidden it may not be saved if ($meta['access'] != 'readonly' && $meta['access'] != 'hidden') { $value = undoMagic($value); // value comes from request switch ($o->otype) { case 'yesno': if ($value != 'yes' && $value != 'no') { $value = 'no'; } break; default: break; } // check the validity of numerical options if ($meta['datatype'] == 'numerical' && !is_numeric($value)) { //the option must be numeric, but the it isn't //use the default for this option $value = $o->odef; } // decide wether we are using the contextid of newContextid if ($newContextid != 0) { $contextid = $newContextid; } //trigger event PrePluginOptionsUpdate to give the plugin the //possibility to change/validate the new value for the option $manager->notify('PrePluginOptionsUpdate', array('context' => $o->ocontext, 'plugid' => $o->opid, 'optionname' => $o->oname, 'contextid' => $contextid, 'value' => &$value)); // delete the old value for the option sql_query('DELETE FROM ' . sql_table('plugin_option') . ' WHERE oid=' . intval($oid) . ' AND ocontextid=' . intval($contextid)); sql_query('INSERT INTO ' . sql_table('plugin_option') . " (oid, ocontextid, ovalue) VALUES (" . intval($oid) . "," . intval($contextid) . ",'" . sql_real_escape_string($value) . "')"); } } } // clear option value cache if the plugin object is already loaded if (is_object($o)) { $plugin =& $manager->pidLoaded($o->opid); if ($plugin) { $plugin->clearOptionValueCache(); } } } }
function listplug_plugOptionRow($current) { $varname = 'plugoption[' . $current['oid'] . '][' . $current['contextid'] . ']'; // retreive the optionmeta $meta = NucleusPlugin::getOptionMeta($current['typeinfo']); // only if it is not a hidden option write the controls to the page if ($meta['access'] != 'hidden') { echo '<td>', htmlspecialchars($current['description'] ? $current['description'] : $current['name']), '</td>'; echo '<td>'; switch ($current['type']) { case 'yesno': ADMIN::input_yesno($varname, $current['value'], 0, 'yes', 'no'); break; case 'password': echo '<input type="password" size="40" maxlength="128" name="', htmlspecialchars($varname), '" value="', htmlspecialchars($current['value']), '" />'; break; case 'select': echo '<select name="' . htmlspecialchars($varname) . '">'; $aOptions = NucleusPlugin::getOptionSelectValues($current['typeinfo']); $aOptions = explode('|', $aOptions); for ($i = 0; $i < count($aOptions) - 1; $i += 2) { echo '<option value="' . htmlspecialchars($aOptions[$i + 1]) . '"'; if ($aOptions[$i + 1] == $current['value']) { echo ' selected="selected"'; } echo '>' . htmlspecialchars($aOptions[$i]) . '</option>'; } echo '</select>'; break; case 'textarea': //$meta = NucleusPlugin::getOptionMeta($current['typeinfo']); echo '<textarea class="pluginoption" cols="30" rows="5" name="', htmlspecialchars($varname), '"'; if ($meta['access'] == 'readonly') { echo ' readonly="readonly"'; } echo '>', htmlspecialchars($current['value']), '</textarea>'; break; case 'text': default: //$meta = NucleusPlugin::getOptionMeta($current['typeinfo']); echo '<input type="text" size="40" maxlength="128" name="', htmlspecialchars($varname), '" value="', htmlspecialchars($current['value']), '"'; if ($meta['datatype'] == 'numerical') { echo ' onkeyup="checkNumeric(this)" onblur="checkNumeric(this)"'; } if ($meta['access'] == 'readonly') { echo ' readonly="readonly"'; } echo ' />'; } echo $current['extra']; echo '</td>'; } }