/** * This function sets active/inactive status. * * @param eid * * @return mixed true or Ajax error */ public function setstatus() { $this->checkAjaxToken(); $this->throwForbiddenUnless(SecurityUtil::checkPermission('Ephemerides::', '::', ACCESS_ADMIN)); $eid = $this->request->request->get('eid', 0); $status = $this->request->request->get('status', 0); $alert = ''; if ($eid == 0) { $alert .= $this->__('No ID passed.'); } else { $item = array('eid' => $eid, 'status' => $status); $res = DBUtil::updateObject($item, 'ephem', '', 'eid'); if (!$res) { $alert .= $item['eid'] . ', ' . $this->__f('Could not change item, ID %s.', DataUtil::formatForDisplay($eid)); if ($item['status']) { $item['status'] = 0; } else { $item['status'] = 1; } } } // get current status to return $item = ModUtil::apiFunc($this->name, 'user', 'get', array('eid' => $eid)); if (!$item) { $alert .= $this->__f('Could not get data, ID %s.', DataUtil::formatForDisplay($eid)); } return new Zikula_Response_Ajax(array('eid' => $eid, 'status' => $item['status'], 'alert' => $alert)); }
/** * Set plugins */ function mediashare_adminapi_setTemplateGlobally($args) { $dom = ZLanguage::getModuleDomain('mediashare'); $new = array('template' => DataUtil::formatForStore($args['template'])); if (!DBUtil::updateObject($new, 'mediashare_albums', '1=1', 'id')) { return LogUtil::registerError(__f('Error in %1$s: %2$s.', array('adminapi.setTemplateGlobally', 'Could not set the template.'), $dom)); } return true; }
/** * Reset the agreement to the terms of use for a specific group of users, or all users. * * Parameters passed in the $args array: * ------------------------------------- * int $args['gid'] The group id; -1 = none, 0 = all groups. * * @param array $args All arguments passed to the function. * * @return bool True if successfully reset, otherwise false. * * @throws Zikula_Exception_Forbidden Thrown if the user does not have the appropriate access level for the function. * * @throws Zikula_Exception_Fatal Thrown in cases where expected data is not present or not in an expected form. */ public function resetagreement($args) { // Security check if (!SecurityUtil::checkPermission('legal::', '::', ACCESS_ADMIN)) { throw new Zikula_Exception_Forbidden(); } if (!isset($args['gid']) || $args['gid'] == -1) { throw new Zikula_Exception_Fatal(); } // Get database setup $pntable = DBUtil::getTables(); $userscolumn = $pntable['users_column']; if ($args['gid']==0) { //all users // creative usage of DBUtil $object = array('activated' => 2); $where = "WHERE $userscolumn[uid] NOT IN (1,2)"; DBUtil::updateObject($object, 'users', $where, 'uid'); } else { // single group // get the group incl members $grp = ModUtil::apiFunc('Groups', 'user', 'get', array('gid' => $args['gid'])); if ($grp==false) { return false; } // remove anonymous from members array if (array_key_exists(1, $grp['members'])) { unset($grp['members'][1]); } // remove admin from members array if (array_key_exists(2, $grp['members'])) { unset($grp['members'][2]); } // return if group is empty if (count($grp['members'])==0) { return false; } $members = '(' . implode(array_keys($grp['members']), ',') . ')'; // creative usage of DBUtil $object = array('activated' => 2); $where = "WHERE $userscolumn[uid] IN $members"; DBUtil::updateObject($object, 'users', $where, 'uid'); } return true; }
/** * * @param permorder array of sorted permissions (value = permission id) * @return mixed true or Ajax error */ public function changeorder() { $this->checkAjaxToken(); $this->throwForbiddenUnless(SecurityUtil::checkPermission('Permissions::', '::', ACCESS_ADMIN)); $permorder = $this->request->getPost()->get('permorder'); $dbtable = DBUtil::getTables(); $permcolumn = $dbtable['group_perms_column']; for ($cnt = 0; $cnt < count($permorder); $cnt++) { $where = "WHERE {$permcolumn['pid']} = '" . (int) DataUtil::formatForStore($permorder[$cnt]) . "'"; $obj = array('sequence' => $cnt); DBUtil::updateObject($obj, 'group_perms', $where, 'pid'); } return new Zikula_Response_Ajax(array('result' => true)); }
public function updateCategory($args) { // Security check if (!SecurityUtil::checkPermission('IWdocmanager::', "::", ACCESS_ADMIN)) { throw new Zikula_Exception_Forbidden(); } $table = DBUtil::getTables(); $c = $table['IWdocmanager_categories_column']; $where = "$c[categoryId]=$args[categoryId]"; if (!DBUtil::updateObject($args['items'], 'IWdocmanager_categories', $where)) { return LogUtil::registerError($this->__('Error! Update attempt failed.')); } return true; }
/** * update theme settings * * @return bool true on success, false otherwise */ public function updatesettings($args) { // Security check if (!SecurityUtil::checkPermission('Theme::', '::', ACCESS_ADMIN)) { return LogUtil::registerPermissionError(); } // Check our input arguments if (!isset($args['themeinfo'])) { return LogUtil::registerArgsError(); } if (!DBUtil::updateObject($args['themeinfo'], 'themes')) { return LogUtil::registerError(__('Error! Could not save your changes.')); } return true; }
/** * Change the status of a block. * * Invert the status of a given block id (collapsed/uncollapsed). * * @return void */ public function changestatus() { $bid = FormUtil::getPassedValue('bid'); $uid = UserUtil::getVar('uid'); $dbtable = DBUtil::getTables(); $column = $dbtable['userblocks_column']; $where = "WHERE {$column['bid']}='" . DataUtil::formatForStore($bid) . "' AND {$column['uid']}='" . DataUtil::formatForStore($uid) . "'"; $active = DBUtil::selectField('userblocks', 'active', $where); $obj = array(); $obj['active'] = $active ? 0 : 1; $where = "WHERE {$column['uid']}='" . DataUtil::formatForStore($uid) . "' AND {$column['bid']}='" . DataUtil::formatForStore($bid) . "'"; $res = DBUtil::updateObject($obj, 'userblocks', $where); if (!$res) { return LogUtil::registerError($this->__('Error! An SQL error occurred.')); } // now lets get back to where we came from $this->redirect(System::serverGetVar('HTTP_REFERER')); }
/** * Do the migration * * With this function, the actual migration is done. * * @return boolean true on sucessful migration, false else */ function EZComments_migrateapi_pnProfile() { if (!SecurityUtil::checkPermission('EZComments::', '::', ACCESS_ADMIN)) { return LogUtil::registerError('pnProfile comments migration: Not Admin'); } $columnArray = array('id', 'modname', 'objectid'); $comments = DBUtil::selectObjectArray('EZComments', '', '', -1, -1, '', null, null, $columnArray); $counter = 0; foreach ($comments as $comment) { if ($comment['modname'] == 'pnProfile') { $comment['modname'] = 'MyProfile'; $comment['url'] = ModUtil::url('MyProfile', 'user', 'display', array('uid' => $comment['objectid'])); $comment['owneruid'] = $comment['objectid']; if (DBUtil::updateObject($comment, 'EZComments')) { $counter++; } } } return LogUtil::registerStatus("Updated / migrated: {$counter} comments from pnProfile to MyProfile, the successor of pnProfile"); }
/** * Delete the IWTimeFrames module & update existing bookings references * @author Albert Pérez Monfort (aperezm@xtec.cat) * @author Josep Ferràndiz Farré (jferran6@xtec.cat) * @return bool true if successful, false otherwise */ public function uninstall() { // Delete module table DBUtil::dropTable('IWtimeframes'); DBUtil::dropTable('IWtimeframes_definition'); // Totes les referències als marcs s'han d'esborrar a IWbookings_spaces // 1r. mirar si existeix el mòdul i després actualitzar els registres $modid = ModUtil::getIdFromName('IWbookings'); $modinfo = ModUtil::getInfo($modid); if ($modinfo['state'] > 1) { $obj = array('mdid' => 0); DBUtil::updateObject($obj, 'IWbookings_spaces', 'mdid != 0'); } //Delete module vars $this->delVar('frames'); //Deletion successfull return true; }
/** * update the used disk for the user * @author: Albert Pérez Monfort * @return: True if success and false otherwise */ public function updateUsedSpace() { // security check if (!SecurityUtil::checkPermission('Files::', '::', ACCESS_ADD)) { return LogUtil::registerPermissionError(); } // get user used space $usedSpace = ModUtil::apiFunc('Files', 'user', 'get'); if (!$usedSpace) { // user row doesn't exists and it is created ModUtil::apiFunc('Files', 'user', 'createUserFilesInfo'); } $initFolderPath = ModUtil::func('Files', 'user', 'getInitFolderPath'); $spaceUsed = ModUtil::apiFunc('Files', 'user', 'calcUsedSpace', array('folderToCalc' => $initFolderPath)); $item = array('diskUse' => DataUtil::formatForStore($spaceUsed)); $pntable =& DBUtil::getTables(); $c = $pntable['Files_column']; $where = "{$c['userId']}=" . UserUtil::getVar('uid'); if (!DBUtil::updateObject($item, 'Files', $where, 'fileId')) { return LogUtil::registerError($this->__('Error! Could not update the used disk.')); } // Let the calling process know that we have finished successfully return true; }
/** * The setVar method sets a module variable. * * @param string $modname The name of the module. * @param string $name The name of the variable. * @param string $value The value of the variable. * * @return boolean True if successful, false otherwise. */ public static function setVar($modname, $name, $value = '') { // define input, all numbers and booleans to strings $modname = isset($modname) ? (string) $modname : ''; // validate if (!System::varValidate($modname, 'mod') || !isset($name)) { return false; } $obj = array(); $obj['value'] = serialize($value); if (self::hasVar($modname, $name)) { $tables = DBUtil::getTables(); $cols = $tables['module_vars_column']; $where = "WHERE {$cols['modname']} = '" . DataUtil::formatForStore($modname) . "'\n AND {$cols['name']} = '" . DataUtil::formatForStore($name) . "'"; $res = DBUtil::updateObject($obj, 'module_vars', $where); } else { $obj['name'] = $name; $obj['modname'] = $modname; $res = DBUtil::insertObject($obj, 'module_vars'); } if ($res) { self::$modvars[$modname][$name] = $value; } return (bool) $res; }
function update_company() { // Confirm the forms authorisation key $this->checkCsrfToken(); $ot = FormUtil::getPassedValue('ot', 'address', 'GETPOST'); $id = (int) FormUtil::getPassedValue('id', 0, 'GETPOST'); $oldvalue = (int) FormUtil::getPassedValue('oldvalue', 0, 'GETPOST'); $startnum = FormUtil::getPassedValue('startnum', 1, 'GET'); $letter = FormUtil::getPassedValue('letter', 0); $sort = FormUtil::getPassedValue('sort', ModUtil::getVar('AddressBook', 'addressbooktype') == 1 ? 'sortname ASC' : 'sortcompany ASC'); $search = FormUtil::getPassedValue('search', 0); $category = FormUtil::getPassedValue('category', 0); $private = FormUtil::getPassedValue('private', 0); $url = ModUtil::url('AddressBook', 'user', 'view', array('ot' => $ot, 'startnum' => $startnum, 'letter' => $letter, 'sort' => $sort, 'search' => $search, 'category' => $category, 'private' => $private)); $object = new AddressBook_DBObject_Address(); $data = $object->get($id); // security check // Get user id if (UserUtil::isLoggedIn()) { $user_id = UserUtil::getVar('uid'); } else { $user_id = 0; } if (!(SecurityUtil::checkPermission('AddressBook::', '::', ACCESS_EDIT) || $user_id == $data['user_id'])) { return LogUtil::registerPermissionError(); } $obj = array('company' => $data['company'], 'address1' => $data['address1'], 'address2' => $data['address2'], 'zip' => $data['zip'], 'city' => $data['city'], 'state' => $data['state'], 'country' => $data['country']); $res = DBUtil::updateObject($obj, 'addressbook_address', '', 'company'); if (!$res) { LogUtil::registerError($this->__('Error! Company update failed.')); return System::redirect($url); } // clear respective cache ModUtil::apiFunc('AddressBook', 'user', 'clearItemCache', $data); LogUtil::registerStatus($this->__('Done! Company update successful.')); return System::redirect($url); }
public function changePermissions($args) { $gid = FormUtil::getPassedValue('gid', isset($args['gid']) ? $args['gid'] : null, 'GET'); // Security check if (!SecurityUtil::checkPermission('IWmyrole::', "::", ACCESS_ADMIN)) { throw new Zikula_Exception_Forbidden(); } $pntables = DBUtil::getTables(); $column = $pntables['group_perms_column']; $object = array('gid' => $gid); $where = "WHERE $column[component] LIKE 'IWmyrole%' AND $column[gid] = " . ModUtil::getVar('IWmyrole', 'rolegroup'); $result = DBUtil::updateObject($object, 'group_perms', $where); return!(empty($result)); }
/** * Generic upate handler for an object. * * @return array|boolean The Object Data. */ public function update() { if (!$this->updatePreProcess()) { return false; } $res = DBUtil::updateObject($this->_objData, $this->_objType, '', $this->_objField, $this->_objInsertPreserve); if ($res) { $this->updatePostProcess(); return $this->_objData; } return false; }
/** * Update Ephemeride * @author The Zikula Development Team * @param 'args['eid']' item ID * @return true if success, false otherwise */ public function update($args) { // Argument check if (!isset($args['eid']) || !isset($args['did']) || !isset($args['mid']) || !isset($args['yid']) || !isset($args['content']) || !isset($args['language'])) { return LogUtil::registerArgsError(); } if (!isset($args['status'])) { $args['status'] = 1; } if (!isset($args['type'])) { $args['type'] = 1; } // get the existing args $item = ModUtil::apiFunc('Ephemerides', 'user', 'get', array('eid' => $args['eid'])); if (!$item) { return LogUtil::registerError($this->__('No such Ephemeride found.')); } // security check(s) // check permissions for both the original and modified ephemerides if (!SecurityUtil::checkPermission('Ephemerides::', "::{$args['eid']}", ACCESS_EDIT)) { return LogUtil::registerPermissionError(); } // update the args and check return value for error $res = DBUtil::updateObject($args, 'ephem', '', 'eid'); if (!$res) { return LogUtil::registerError($this->__('Error! Ephemeride update failed.')); } return true; }
/** * update a RSS item * @param $args['fid'] the ID of the item * @param $args['feedname'] the new name of the item * @param $args['number'] the new number of the item */ public function update($args) { // Argument check if (!isset($args['fid']) || !isset($args['name']) || !isset($args['url'])) { return LogUtil::registerArgsError(); } // Get the existing feed $item = ModUtil::apiFunc('Feeds', 'user', 'get', array('fid' => $args['fid'])); if (!$item) { return LogUtil::registerError($this->__('No such Feed found.')); } // Security check if (!SecurityUtil::checkPermission('Feeds::Item', "$item[name]::$args[fid]", ACCESS_EDIT)) { return LogUtil::registerPermissionError(); } if (!SecurityUtil::checkPermission('Feeds::Item', "$args[name]::$args[fid]", ACCESS_EDIT)) { return LogUtil::registerPermissionError(); } // check for maximum length to avoid cutting off URLs if (strlen($args['url'] > 200)) { return LogUtil::registerError($this->__('The provided URL is too long (200 chars max.).')); } // Check for a protocol Magpie RSS (more exactly Snoopy) can handle. $url_parts = parse_url($args['url']); if ($url_parts['scheme'] != 'http' && $url_parts['scheme'] != 'https') { return LogUtil::registerError($this->__('Invalid protocol selected. Only http and https are allowed.')); } // define the permalink title if not present if (!isset($args['urltitle']) || empty($args['urltitle'])) { $args['urltitle'] = DataUtil::formatPermalink($args['name']); } if (!DBUtil::updateObject($args, 'feeds', '', 'fid')) { return LogUtil::registerError($this->__('Error! Update attempt failed.')); } // Let the calling process know that we have finished successfully return true; }
/** * Log search query for search statistics. */ public function log($args) { $searchterms = DataUtil::formatForStore($args['q']); $obj = DBUtil::selectObjectByID('search_stat', $searchterms, 'search'); $newobj['count'] = isset($obj['count']) ? $obj['count'] + 1 : 1; $newobj['date'] = date('Y-m-d H:i:s'); $newobj['search'] = $searchterms; if (!isset($obj) || empty($obj)) { $res = DBUtil::insertObject($newobj, 'search_stat'); } else { $res = DBUtil::updateObject($newobj, 'search_stat', '', 'search'); } if (!$res) { return false; } return true; }
public function changeAvatar($args) { // Security check if (!SecurityUtil::checkPermission('IWusers::', '::', ACCESS_READ) || !ModUtil::getVar('IWusers', 'allowUserChangeAvatar') == 1) { throw new Zikula_Exception_Forbidden(); } $field = (isset($args['target'])) ? $args['target'] : 'avatar'; $uid = (!SecurityUtil::checkPermission('IWusers::', '::', ACCESS_ADMIN) || !isset($args['uid'])) ? UserUtil::getVar('uid') : $args['uid']; $pntables = DBUtil::getTables(); $c = $pntables['IWusers_column']; $where = "WHERE $c[uid]=" . $uid; $field = (ModUtil::getVar('IWusers', 'avatarChangeValidationNeeded') == 1 && !SecurityUtil::checkPermission('IWusers::', '::', ACCESS_ADMIN) && !isset($args['delete'])) ? 'newavatar' : $field; $item = array($field => $args['avatar']); if (!DBUtil::updateObject($item, 'IWusers', $where)) { return LogUtil::registerError($this->__('Error! Update attempt failed.')); } return true; }
/** * upgrade the theme module from an old version * * This function must consider all the released versions of the module! * If the upgrade fails at some point, it returns the last upgraded version. * * @param string $oldVersion version number string to upgrade from * @return mixed true on success, last valid version string or false if fails */ public function upgrade($oldversion) { // update the table if (!DBUtil::changeTable('themes')) { return false; } switch ($oldversion) { case '3.1': $this->setVar('cssjscombine', false); $this->setVar('cssjscompress', false); $this->setVar('cssjsminify', false); $this->setVar('cssjscombine_lifetime', 3600); case '3.3': // convert pnRender modvars $pnrendervars = ModUtil::getVar('pnRender'); foreach ($pnrendervars as $k => $v) { $this->setVar('render_' . $k, $v); } // delete pnRender modvars ModUtil::delVar('pnRender'); $modid = ModUtil::getIdFromName('pnRender'); // check and update blocks $blocks = ModUtil::apiFunc('Blocks', 'user', 'getall', array('modid' => $modid)); if (!empty($blocks)) { $thememodid = ModUtil::getIdFromName('Theme'); foreach ($blocks as $block) { $block->setBkey('render'); $block->setMid($thememodid); $this->entityManager->flush(); } } // check and fix permissions $dbtable = DBUtil::getTables(); $permscolumn = $dbtable['group_perms_column']; $permswhere = "WHERE $permscolumn[component] = 'pnRender:pnRenderblock:'"; $perms = DBUtil::selectObjectArray('group_perms', $permswhere); if (!empty($perms)) { foreach ($perms as $perm) { $perm['component'] = 'Theme:Renderblock:'; DBUtil::updateObject($perm, 'group_perms', '', 'pid'); } } // Set Module pnRender 'Inactive' if (!ModUtil::apiFunc('Extensions', 'admin', 'setstate', array( 'id' => $modid, 'state' => ModUtil::STATE_INACTIVE))) { return '3.3'; } // Remove Module pnRender from Modulelist if (!ModUtil::apiFunc('Extensions', 'admin', 'remove', array( 'id' => $modid))) { return '3.3'; } case '3.4': if (!DBUtil::changeTable('themes')) { return '3.4'; } case '3.4.1': if (!DBUtil::changeTable('themes')) { return '3.4.1'; } $this->setVar('enable_mobile_theme', false); case '3.4.2': // future upgrade } // Update successful return true; }
/** * Delete the contents of a user variable. * * This can either be * - a variable stored in the users table or * - an attribute to the users table, either a new style sttribute or the old style user information * * Examples: * UserUtil::delVar('ublock'); // clears the recent users table entry for 'ublock' * UserUtil::delVar('_YOURAVATAR', 123), // removes a users avatar, old style (uid = 123) * UserUtil::delVar('avatar', 123); // removes a users avatar, new style (uid=123) * (internally both the new style and the old style clear the same attribute) * * It does not allow the deletion of uid, email, uname, pass (password), as these are mandatory * fields in the users table. * * @param string $name The name of the variable. * @param integer $uid The user to delete the variable for. * * @return boolen true on success, false on failure */ public static function delVar($name, $uid = -1) { // Prevent deletion of core fields (duh) if (empty($name) || $name == 'uid' || $name == 'email' || $name == 'pass' || $name == 'uname' || $name == 'activated') { return false; } if ($uid == -1) { $uid = SessionUtil::getVar('uid'); } if (empty($uid)) { return false; } // Special delete value for approved_by if ($name == 'approved_by') { return (bool) self::setVar($name, -1, $uid); } $isRegistration = self::isRegistration($uid); $origUserObj = self::getVars($uid, false, 'uid', $isRegistration); if (!$origUserObj) { // No such user record! return false; } $varIsDeleted = false; // Cannot delVar the user's uid or uname if ($name != 'uid' && $name != 'uname') { if (self::fieldAlias($name)) { // this value comes from the users table $obj = array('uid' => $uid, $name => ''); $oldValue = isset($origUserObj[$name]) ? $origUserObj[$name] : null; $varIsDeleted = (bool) DBUtil::updateObject($obj, 'users', '', 'uid'); } else { // Not a table field alias, not 'uid', and not 'uname'. Treat it as an attribute. $dudAttributeName = self::convertOldDynamicUserDataAlias($name); if ($dudAttributeName) { LogUtil::log(__f('Warning! User variable [%1$s] is deprecated. Please use [%2$s] instead.', array($name, $mappingarray[$name])), E_USER_DEPRECATED); // $name is a former DUD /old style user information now stored as an attribute $attributeName = $dudAttributeName; } else { // $name not in the users table and also not found in the mapping array and also not one of the // forbidden names, let's make an attribute out of it $attributeName = $name; } $oldValue = isset($origUserObj['__ATTRIBUTES__'][$attributeName]) ? $origUserObj['__ATTRIBUTES__'][$attributeName] : null; $varIsDeleted = (bool) ObjectUtil::deleteObjectSingleAttribute($uid, 'users', $attributeName); } // force loading of attributes from db $updatedUserObj = self::getVars($uid, true, '', $isRegistration); if (!$updatedUserObj) { // Should never get here! return false; } // Do not fire update event/hook unless the update happened, it was not a registration record, it was not // the password being updated, and the system is not currently being installed. if ($varIsDeleted && $name != 'pass' && !System::isInstalling()) { // Fire the event $eventArgs = array('action' => 'delVar', 'field' => isset($attributeName) ? null : $name, 'attribute' => isset($attributeName) ? $attributeName : null); $eventData = array('old_value' => $oldValue); if ($isRegistration) { $updateEvent = new Zikula_Event('user.registration.update', $updatedUserObj, $eventArgs, $eventData); } else { $updateEvent = new Zikula_Event('user.account.update', $updatedUserObj, $eventArgs, $eventData); } EventUtil::notify($updateEvent); } } return $varIsDeleted; }
/** * Update a meta data object. * * @param array &$obj The object we wish to store metadata for. * @param string $tablename The object's tablename. * @param string $idcolumn The object's idcolumn (optional) (default='id'). * * @return The result from the metadata insert operation */ public static function updateObjectMetaData(&$obj, $tablename, $idcolumn = 'id') { if (!isset($obj['__META__']['id'])) { return false; } $meta = $obj['__META__']; if ($meta['obj_id'] > 0) { return DBUtil::updateObject($meta, 'objectdata_meta'); } $dbtables = DBUtil::getTables(); if (isset($dbtables[$tablename])) { DBUtil::flushCache($tablename); } return true; }
/** * Rebuild the path field for all categories in the database. * * Note that field and sourceField go in pairs (that is, if you want sensical results)!. * * @param string $field The field which we wish to populate (optional) (default='path'). * @param string $sourceField The field we use to build the path with (optional) (default='name'). * @param integer $leaf_id The leaf-category category-id (ie: we'll rebuild the path of this category and all it's parents) (optional) (default=0). * * @return void */ public static function rebuildPaths($field = 'path', $sourceField = 'name', $leaf_id = 0) { ModUtil::dbInfoLoad('Categories'); //if ($leaf_id) //$cats = self::getParentCategories ($leaf_id, 'id'); //else $cats = self::getCategories('', '', 'id'); $paths = self::buildPaths($cats, $sourceField); if ($cats && $paths) { foreach ($cats as $k => $v) { if ($v[$field] != $paths[$k][$field]) { $v[$field] = $paths[$k]; // since we're not going through the object layer for this, we must manually serialize the locale fields $v['display_name'] = serialize($v['display_name']); $v['display_desc'] = serialize($v['display_desc']); $res = DBUtil::updateObject($v, 'categories_category'); } } } }
public function resetUserThemes() { // Get all users. $users = ModUtil::apiFunc('Users', 'user', 'getall'); // Loop through users. foreach ($users as $user) { // Create an update object. $obj = array('uid' => $user['uid'], 'theme' => ''); // Update the user's record or fail. if (!DBUtil::updateObject($obj, 'users', '', 'uid')) { $this->setError(__('Error Resetting User Themes')); return false; } } // Success. return true; }
/** * Register module categories. * * @param array $catregs The array of category map data objects. * * @return true */ public static function registerModuleCategories($catregs) { if (!$catregs) { return false; } foreach ($catregs as $catreg) { if ($catreg['id']) { $res = DBUtil::updateObject($catreg, 'categories_registry'); } else { $res = DBUtil::insertObject($catreg, 'categories_registry'); } } return true; }
public function update_hour($args) { if (!SecurityUtil::checkPermission('IWtimeframes::', "::", ACCESS_ADMIN)) { return LogUtil::registerError($this->__('Not authorized to manage timeFrames.'), 403); } $hid = FormUtil::getPassedValue('hid', isset($args['hid']) ? $args['hid'] : null, 'GET'); $start = FormUtil::getPassedValue('start', isset($args['start']) ? $args['start'] : null, 'GET'); $end = FormUtil::getPassedValue('end', isset($args['end']) ? $args['end'] : null, 'GET'); $descriu = FormUtil::getPassedValue('descriu', isset($args['descriu']) ? $args['descriu'] : null, 'GET'); //Comprovem que els valors han arribat if ((!isset($hid)) or (!isset($start)) or (!isset($end))) { return LogUtil::registerError($this->__('Error! Could not do what you wanted. Please check your input.')); } //Carregem l'API de l'usuari per poder consultar les dades de l'hora que volem modificar if (!ModUtil::loadApi('IWtimeframes', 'user')) { return LogUtil::registerError($this->__('Error! Could not load module.')); } //Cridem la funciᅵ get de l'API que ens retornarᅵ les dades de l'hora $registre = ModUtil::apiFunc('IWtimeframes', 'user', 'get_hour', array('hid' => $hid)); //Comprovem que la consulta anterior ha tornat amb resultats if ($registre == false) { return LogUtil::registerError($this->__('Could not find the time over to do the action')); } //Comprovacions de seguretat if (!SecurityUtil::checkPermission('IWtimeframes::', "$registre[hora]::$hid", ACCESS_EDIT)) { return LogUtil::registerError($this->__('Not authorized to manage timeFrames.')); } $where = "hid=" . $hid; $item = array('start' => $start, 'end' => $end, 'descriu' => $descriu); $tablename = 'IWtimeframes'; if (!DBUtil::updateObject($item, $tablename, $where)) { return LogUtil::registerError($this->__('The modify of the frame time failed.')); } return true; }
/** * Generate the upgrade module page. * * This function upgrade available module to an upgrade * * @param string $username Username of the admin user. * @param string $password Password of the admin user. * * @return void */ function _upg_upgrademodules($username, $password) { _upg_header(); $modvars = DBUtil::selectObjectArray('module_vars'); foreach ($modvars as $modvar) { if ($modvar['value'] == '0' || $modvar['value'] == '1') { $modvar['value'] = serialize($modvar['value']); DBUtil::updateObject($modvar, 'module_vars'); } } // force load the modules admin API ModUtil::loadApi('Extensions', 'admin', true); echo '<h2>' . __('Starting upgrade') . '</h2>' . "\n"; echo '<ul id="upgradelist" class="check">' . "\n"; // reset for User module //$GLOBALS['_ZikulaUpgrader']['_ZikulaUpgradeFrom12x'] = false; $results = ModUtil::apiFunc('Extensions', 'admin', 'upgradeall'); if ($results) { foreach ($results as $modname => $result) { if ($result) { echo '<li class="passed">' . DataUtil::formatForDisplay($modname) . ' ' . __('upgraded') . '</li>' . "\n"; } else { echo '<li class="failed">' . DataUtil::formatForDisplay($modname) . ' ' . __('not upgraded') . '</li>' . "\n"; } } } echo '</ul>' . "\n"; if (!$results) { echo '<ul class="check"><li class="passed">' . __('No modules required upgrading') . '</li></ul>'; } // wipe out the deprecated modules from Modules list. $modTable = 'modules'; $sql = "DELETE FROM {$modTable} WHERE name = 'Header_Footer' OR name = 'AuthPN' OR name = 'pnForm' OR name = 'Workflow' OR name = 'pnRender' OR name = 'Admin_Messages'"; DBUtil::executeSQL($sql); // store localized displayname and description for Extensions module $extensionsDisplayname = __('Extensions'); $extensionsDescription = __('Manage your modules and plugins.'); $sql = "UPDATE modules SET name = 'Extensions', displayname = '{$extensionsDisplayname}', description = '{$extensionsDescription}' WHERE modules.name = 'Extensions'"; DBUtil::executeSQL($sql); // regenerate the themes list ModUtil::apiFunc('Theme', 'admin', 'regenerate'); // store the recent version in a config var for later usage. This enables us to determine the version we are upgrading from System::setVar('Version_Num', Zikula_Core::VERSION_NUM); System::setVar('language_i18n', ZLanguage::getLanguageCode()); // Relogin the admin user to give a proper admin link SessionUtil::requireSession(); echo '<p class="z-statusmsg">' . __('Finished upgrade') . " - \n"; $authenticationInfo = array('login_id' => $username, 'pass' => $password); $authenticationMethod = array('modname' => 'Users', 'method' => 'uname'); if (!UserUtil::loginUsing($authenticationMethod, $authenticationInfo)) { $url = sprintf('<a href="%s">%s</a>', DataUtil::formatForDisplay(System::getBaseUrl()), DataUtil::formatForDisplay(System::getVar('sitename'))); echo __f('Go to the startpage for %s', $url); } else { upgrade_clear_caches(); $url = sprintf('<a href="%s">%s</a>', ModUtil::url('Admin', 'admin', 'adminpanel'), DataUtil::formatForDisplay(System::getVar('sitename'))); echo __f('Go to the admin panel for %s', $url); } echo "</p>\n"; _upg_footer(); }
private function ephemerides_upgrade_updateEphemeridesLanguages() { $obj = DBUtil::selectObjectArray('ephem'); if (count($obj) == 0) { // nothing to do return; } foreach ($obj as $ephemerid) { // translate l3 -> l2 if ($l2 = ZLanguage::translateLegacyCode($ephemerid['language'])) { $ephemerid['language'] = $l2; } DBUtil::updateObject($ephemerid, 'ephem', '', 'eid', true); } return true; }
/** * Resequence permissions. * * Called when a permission is assigned the same sequence number as an existing permission. * * @param string $args ['newseq'] the desired sequence. * @param string $args ['oldseq'] the original sequence number. * * @return boolean */ public function full_resequence($args) { // Security check if (!SecurityUtil::checkPermission('Permissions::', "::", ACCESS_ADMIN)) { return LogUtil::registerPermissionError(); } // Argument check if (!isset($args['newseq']) || !isset($args['oldseq'])) { return LogUtil::registerArgsError(); } $newseq = $args['newseq']; $oldseq = $args['oldseq']; unset($args); $dbtable = DBUtil::getTables(); $permcolumn = $dbtable['group_perms_column']; //find out the maximum sequence number $maxseq = $this->maxsequence(array('column' => 'sequence')); if ((int) $oldseq > (int) $newseq) { if ($newseq < 1) { $newseq = 1; } // The new sequence is higher in the list // Get the information $where = "WHERE {$permcolumn['sequence']} >= '" . (int) $newseq . "'\n AND {$permcolumn['sequence']} <= '" . (int) $oldseq . "'"; $orderBy = "ORDER BY {$permcolumn['sequence']} DESC"; $objArray = DBUtil::selectObjectArray('group_perms', $where, $orderBy, -1, -1, '', null, array('pid', 'sequence')); $key = 0; while (list($pid, $curseq) = $objArray[$key]) { if ($curseq == $oldseq) { // we are dealing with the old value so make it the new value $curseq = $newseq; } else { $curseq++; } $key++; $where = "WHERE {$permcolumn['pid']} = '" . (int) DataUtil::formatForStore($pid) . "'"; $obj = array('sequence' => (int) $curseq); DBUtil::updateObject($obj, 'group_perms', $where, 'pid'); } } else { // The new sequence is lower in the list //if the new requested sequence is bigger than //the maximum sequence number then set it to //the maximum number. We don't want any spaces //in the sequence. if ($newseq > $maxseq) { $newseq = (int) $maxseq; } $where = "WHERE {$permcolumn['sequence']} >= '" . (int) $oldseq . "'\n AND {$permcolumn['sequence']} <= '" . (int) $newseq . "'"; $orderBy = "ORDER BY {$permcolumn['sequence']} ASC"; $objArray = DBUtil::selectObjectArray('group_perms', $where, $orderBy, -1, -1, '', null, array('pid', 'sequence')); $key = 0; while (list($pid, $curseq) = $objArray[$key]) { if ($curseq == $oldseq) { // we are dealing with the old value so make it the new value $curseq = $newseq; } else { $curseq--; } $key++; $where = "WHERE {$permcolumn['pid']} = '" . (int) DataUtil::formatForStore($pid) . "'"; $obj = array('sequence' => (int) $curseq); DBUtil::updateObject($obj, 'group_perms', $where, 'pid'); } } return true; }
/** * update the value addons tables */ public function updateValueAddons_104() { // Array of the modules to update $mods = array('News' => array('stories' => 'Main'), 'Pages' => array('pages' => 'Main'), 'FAQ' => array('faqanswer' => 'Main'), 'Feeds' => array('feeds' => 'Main'), 'Reviews' => array('reviews' => 'Main'), 'Content' => array('page' => 'primary')); $dbtables = DBUtil::getTables(); $regcol = $dbtables['categories_registry_column']; $mapcol = $dbtables['categories_mapobj_column']; // Update all the items mapped if there's a Register of the module foreach ($mods as $module => $data) { foreach ($data as $table => $property) { $where = "{$regcol['modname']}='{$module}' AND {$regcol['table']}='{$table}' AND {$regcol['property']}='{$property}'"; $reg_id = DBUtil::selectObject('categories_registry', $where, array('id')); if ($reg_id !== false) { $obj = array('reg_id' => $reg_id['id']); $where = "{$mapcol['modname']}='{$module}' AND {$mapcol['table']}='{$table}'"; DBUtil::updateObject($obj, 'categories_mapobj', $where, 'sid'); } } } return true; }
protected function migrateBlockNames() { $blocks = DBUtil::selectObjectArray('blocks'); foreach ($blocks as $block) { $block['bkey'] = ucfirst($block['bkey']); DBUtil::updateObject($block, 'blocks', '', 'bid'); } }