/** * Get the properties of the activities that a user have got assigned * @author: Albert Pérez Monfort (aperezm@xtec.cat) * @return: An array with the activity proporties */ public function getAllActivities($args) { // Security check if (!SecurityUtil::checkPermission('IWjclic::', "::", ACCESS_READ)) { throw new Zikula_Exception_Forbidden(); } $uid = UserUtil::getVar('uid'); //get all the groups of the user $sv = ModUtil::func('IWmain', 'user', 'genSecurityValue'); $userGroups = ModUtil::func('IWmain', 'user', 'getAllUserGroups', array('uid' => $uid, 'sv' => $sv)); $myJoin = array(); $myJoin[] = array('join_table' => 'IWjclic', 'join_field' => array(), 'object_field_name' => array(), 'compare_field_table' => 'jid', 'compare_field_join' => 'jid'); $myJoin[] = array('join_table' => 'IWjclic_groups', 'join_field' => array(), 'object_field_name' => array(), 'compare_field_table' => 'jid', 'compare_field_join' => 'jid'); $pntables = DBUtil::getTables(); $ocolumn = $pntables['IWjclic_column']; $lcolumn = $pntables['IWjclic_groups_column']; $where = "("; $orderby = "a.$ocolumn[date]"; foreach ($userGroups as $group) { $where .= "b.$lcolumn[group_id]=" . $group['id'] . ' OR '; } $where = substr($where, 0, -3); $where .= ") AND a.$ocolumn[active] = 1"; $items = DBUtil::selectExpandedObjectArray('IWjclic', $myJoin, $where, $orderby, '-1', '-1', 'jid'); if ($items === false) { return LogUtil::registerError($this->__('Error! Could not load items.')); } // get the user activities that the user has made independently of the groups. // In case the activity groups changes but the user have made an activity he/she can accés to the activity information // marge the items in the two requests // Return the items return $items; }
/** * Select the object from the database using the specified key (and field). * * @param string $key The record's key value (if init is a string directive). * @param string $field The key-field we wish to select by (optional) (default=null, reverts to this->_objField). * @param string $where The key-field we wish to select by (optional) (default=''). * * @return array The object's data value. */ public function select($key, $field = '', $where = '') { if (!$this->_objType) { return array(); } if (!$field) { $field = $this->_objField; } if ((!$key || !$field) && !$where) { return array(); } // use explicit where clause if ($where) { if ($this->_objJoin) { $objArray = DBUtil::selectExpandedObjectArray($this->_objType, $this->_objJoin, $where, '', -1, -1, '', $this->_objPermissionFilter, $this->_objCategoryFilter, $this->_objColumnArray); } else { $objArray = DBUtil::selectObjectArray($this->_objType, $where, '', -1, -1, '', $this->_objPermissionFilter, $this->_objCategoryFilter, $this->_objColumnArray); } if ($objArray === false) { $this->_objData = false; } else { if (isset($objArray[0])) { $this->_objData = $objArray[0]; } else { $this->_objData = array(); } } $this->_objKey = $where; } else { // generic key=>value lookup if ($this->_objJoin) { $this->_objData = DBUtil::selectExpandedObjectById($this->_objType, $this->_objJoin, $key, $field, $this->_objColumnArray, $this->_objPermissionFilter, $this->_objCategoryFilter); } else { $this->_objData = DBUtil::selectObjectById($this->_objType, $key, $field, $this->_objColumnArray, $this->_objPermissionFilter, $this->_objCategoryFilter); } $this->_objKey = $key; $this->_objField = $field; } $this->selectPostProcess(); return $this->_objData; }
/** * Count the number of users for a specific filter * @author: Albert Pérez Monfort (aperezm@xtec.cat) * @param: args filter values * @return: The number of users */ public function countUsers($args) { $filtre = FormUtil::getPassedValue('filtre', isset($args['filtre']) ? $args['filtre'] : null, 'POST'); $campfiltre = FormUtil::getPassedValue('campfiltre', isset($args['campfiltre']) ? $args['campfiltre'] : null, 'POST'); // Security check if (!SecurityUtil::checkPermission('IWusers::', '::', ACCESS_READ)) { throw new Zikula_Exception_Forbidden(); } if ($filtre == '0') { $filtre = ''; } $myJoin = array(); $myJoin[] = array('join_table' => 'users', 'join_field' => array('uid'), 'object_field_name' => array('uid'), 'compare_field_table' => 'uid', 'compare_field_join' => 'uid'); $myJoin[] = array('join_table' => 'IWusers', 'join_field' => array(), 'object_field_name' => array(), 'compare_field_table' => 'uid', 'compare_field_join' => 'uid'); $pntables = DBUtil::getTables(); $ccolumn = $pntables['users_column']; $ocolumn = $pntables['IWusers_column']; switch ($campfiltre) { case 'n': $where = "b.$ocolumn[uid] = a.$ccolumn[uid] AND b.$ocolumn[nom]<>'' AND b.$ocolumn[nom] like '" . $filtre . "%'"; $orderby = "order by b.$ocolumn[nom]"; break; case 'c1': $where = "b.$ocolumn[uid] = a.$ccolumn[uid] AND b.$ocolumn[cognom1]<>'' AND b.$ocolumn[cognom1] like '" . $filtre . "%'"; $orderby = "order by b.$ocolumn[cognom1]"; break; case 'c2': $where = "b.$ocolumn[uid] = a.$ccolumn[uid] AND b.$ocolumn[cognom2]<>'' AND b.$ocolumn[cognom2] like '" . $filtre . "%'"; $orderby = "order by b.$ocolumn[cognom2]"; break; default: $where = "b.$ocolumn[uid] = a.$ccolumn[uid] AND a.$ccolumn[uname] like '" . $filtre . "%'"; $orderby = "order by a.$ccolumn[uname]"; } $items = DBUtil::selectExpandedObjectArray('IWusers', $myJoin, $where, $orderby, '-1', '-1', 'uid'); // Check for an error with the database code, and if so set an appropriate // error message and return if ($items === false) { return LogUtil::registerError(_SELECTFAILED); } return count($items); }
/** * Expand an object array with it's category data. * * @param array &$objArray The object array we wish to get the category for. * @param string $tablename The object's tablename. * @param string $idcolumn The object's idcolumn (optional) (default='id'). * @param string $field The category field to return the object's category info (optional) (default='id'). * @param string $locale Locale. * * @return The object with the meta data filled in. The object passed in is altered in place */ public static function expandObjectArrayWithCategories(&$objArray, $tablename, $idcolumn = 'id', $field = 'id', $locale = 'en') { if (!ModUtil::dbInfoLoad('ZikulaCategoriesModule')) { return false; } if (!$objArray || !is_array($objArray)) { return false; } $pntabs = DBUtil::getTables(); $tab = $pntabs['categories_mapobj']; $col = $pntabs['categories_mapobj_column']; $w1 = array(); $w2 = array(); foreach ($objArray as $obj) { $w1[] = DataUtil::formatForStore($obj[$idcolumn]); } $t = implode(',', $w1); $w2[] = "tbl.{$col['obj_id']} IN (" . $t . ')'; $w2[] = "tbl.{$col['table']}='" . DataUtil::formatForStore($tablename) . "' AND tbl.{$col['obj_idcolumn']}='" . DataUtil::formatForStore($idcolumn) . "' "; $where = "WHERE " . implode(' AND ', $w2); $sort = "ORDER BY tbl.{$col['obj_id']}, tbl.{$col['category_id']}"; $joinInfo[] = array('join_table' => 'categories_registry', 'join_field' => 'property', 'object_field_name' => 'property', 'compare_field_table' => 'reg_id', 'compare_field_join' => 'id'); $maps = DBUtil::selectExpandedObjectArray('categories_mapobj', $joinInfo, $where, $sort); if (!$maps) { return false; } // since we don't know the order in which our data array will be, we // have to do this iteratively. However, this is still a lot faster // than doing a select for every data line. $catlist = array(); foreach ($objArray as $k => $obj) { $last = null; foreach ($maps as $map) { if ($map['obj_id'] == $obj[$idcolumn]) { $last = $map['obj_id']; $prop = $map['property']; $catid = $map['category_id']; $objArray[$k]['__CATEGORIES__'][$prop] = $catid; $catlist[] = $catid; } if ($last && $last != $map['obj_id']) { break; } } } // now retrieve the full category data $where = 'WHERE id IN (' . implode(',', $catlist) . ')'; $catArray = new Categories_DBObject_CategoryArray(); $data = $catArray->get($where, '', -1, -1, 'id'); // use the cagtegory map created previously to build the object category array foreach ($objArray as $k => $obj) { if (isset($obj['__CATEGORIES__'])) { foreach ($obj['__CATEGORIES__'] as $prop => $cat) { $data[$cat]['path'] = str_replace('__SYSTEM__', __('Root Category'), $data[$cat]['path']); $objArray[$k]['__CATEGORIES__'][$prop] = $data[$cat]; } } } // now generate the relative paths //$rootCatID = CategoryRegistryUtil::getRegisteredModuleCategory (ModUtil::getName(), $tablename, 'main_table', '/__SYSTEM__/Modules/Quotes/Default'); //postProcessExpandedObjectArrayCategories ($objArray, $rootCatID, false); return $objArray; }
/** * get the contents for a field * @author: Albert Pérez Monfort (aperezm@xtec.cat) * @param: the note id * @return: An array with the fields contents of note */ public function getNoteContent($args) { $fnid = (isset($args['fnid'])) ? $args['fnid'] : null; $pntable = DBUtil::getTables(); $myJoin = array(); $myJoin[] = array('join_table' => 'IWforms_note', 'join_field' => array(), 'object_field_name' => array(), 'compare_field_table' => 'fnid', 'compare_field_join' => 'fnid'); $myJoin[] = array('join_table' => 'IWforms_note_definition', 'join_field' => array('fieldName', 'fieldType', 'editable'), 'object_field_name' => array('fieldName', 'fieldType', 'editable'), 'compare_field_table' => 'fndid', 'compare_field_join' => 'fndid'); $pntables = DBUtil::getTables(); $ocolumn = $pntables['IWforms_note_column']; $lcolumn = $pntables['IWforms_note_definition_column']; $where = "a.$ocolumn[fnid] = $fnid"; $items = DBUtil::selectExpandedObjectArray('IWforms_note', $myJoin, $where, '', '-1', '-1', 'fnid'); // Check for an error with the database code, and if so set an appropriate // error message and return if ($items === false) { return LogUtil::registerError($this->__('Error! Could not load items.')); } // Check for an error with the database code, and if so set an appropriate // error message and return if ($items === false) { return LogUtil::registerError($this->__('You can not access this form to send annotations')); } // check if user can access the form is validator // get note $note = ModUtil::apiFunc('IWforms', 'user', 'getNote', array('fmid' => $items[$fnid]['fmid'])); // check if user can access the form is validator and the note is editable $access = ModUtil::func('IWforms', 'user', 'access', array('fid' => $note['fid'])); if ($access['level'] < 7) { return LogUtil::registerError($this->__('You can not access this form to send annotations')); } // Return the items return array('content' => $items[$fnid]['content'], 'fmid' => $items[$fnid]['fmid'], 'fnid' => $items[$fnid]['fnid'], 'editable' => $items[$fnid]['editable']); }
/** * Generic select handler for an object. Select (and set) the specified object array. * * @param string $where The where-clause to use. * @param string $orderBy The order-by clause to use. * @param integer $limitOffset The limiting offset. * @param integer $limitNumRows The limiting number of rows. * @param string $assocKey Key field to use for building an associative array (optional) (default=null). * @param boolean $distinct Whether or not to use the distinct clause. * * @return array The selected Object-Array. */ public function select($where = '', $orderBy = '', $limitOffset = -1, $limitNumRows = -1, $assocKey = false, $distinct = false) { if ($this->_objJoin) { $objArr = DBUtil::selectExpandedObjectArray($this->_objType, $this->_objJoin, $where, $orderBy, $limitOffset, $limitNumRows, $assocKey, $this->_objPermissionFilter, $this->_objCategoryFilter, $this->_objColumnArray); } else { $objArr = DBUtil::selectObjectArray($this->_objType, $where, $orderBy, $limitOffset, $limitNumRows, $assocKey, $this->_objPermissionFilter, $this->_objCategoryFilter, $this->_objColumnArray); } $this->_objData = $objArr; $this->_objWhere = $where; $this->_objSort = $orderBy; $this->_objLimitOffset = $limitOffset; $this->_objLimitNumRows = $limitNumRows; $this->_objAssocKey = $assocKey; $this->_objDistinct = $distinct; $this->selectPostProcess(); return $this->_objData; }
/** * Get the user permissions for the noteboard * @author: Albert Pérez Monfort (aperezm@xtec.cat) * @param: args The id of the note * The string of mached notes by the user * @return: True if success and false otherwise */ public function permisos($args) { $uid = FormUtil::getPassedValue('uid', isset($args['uid']) ? $args['uid'] : UserUtil::getVar('uid'), 'POST'); $sv = FormUtil::getPassedValue('sv', isset($args['sv']) ? $args['sv'] : null, 'POST'); $requestByCron = false; if (!ModUtil::func('IWmain', 'user', 'checkSecurityValue', array('sv' => $sv))) { // Security check if (!SecurityUtil::checkPermission('IWnoteboard::', '::', ACCESS_READ)) { return LogUtil::registerPermissionError(); } } else { $requestByCron = true; } $n_permisos = 0; $nivell_permisos = array(); //if user is not registered have a fixed permissions if (!UserUtil::isLoggedIn() && !$requestByCron) { $nivell_permisos = array('nivell' => 1, 'verifica' => 2, 'potverificar' => false, 'grups' => array(0)); //return not registered permissions return $nivell_permisos; } // Arguments needed if (!isset($uid) || ($uid != UserUtil::getVar('uid') && !$requestByCron)) { SessionUtil::setVar('errormsg', $this->__('Error! Could not do what you wanted. Please check your input.')); return $nivell_permisos; } $myJoin = array(); $myJoin[] = array('join_table' => 'groups', 'join_field' => array('gid'), 'object_field_name' => array('gid'), 'compare_field_table' => 'gid', 'compare_field_join' => 'gid'); $myJoin[] = array('join_table' => 'group_membership', 'join_field' => array(), 'object_field_name' => array(), 'compare_field_table' => 'gid', 'compare_field_join' => 'gid'); $pntables = DBUtil::getTables(); $ccolumn = $pntables['groups_column']; $ocolumn = $pntables['group_membership_column']; $where = "b.$ocolumn[gid] = a.$ccolumn[gid] AND b.$ocolumn[uid] = $uid"; $items = DBUtil::selectExpandedObjectArray('groups', $myJoin, $where, ''); // Check for an error with the database code, and if so set an appropriate // error message and return if ($items === false) { return $nivell_permisos; } $verifica = 2; $potverificar = false; $permisosModVar = ModUtil::getVar('IWnoteboard', 'permisos'); $verificaModVar = ModUtil::getVar('IWnoteboard', 'verifica'); $quiverificaModVar = ModUtil::getVar('IWnoteboard', 'quiverifica'); foreach ($items as $item) { // get user permissions level $permis = substr($permisosModVar, strpos($permisosModVar, '$' . $item['gid'] . '-') + strlen($item['gid']) + 2, 1); $verifica = (strpos($verificaModVar, '$' . $item['gid'] . '$') != 0 && $verifica != 1) ? 0 : 1; if ($permis > $n_permisos) { $n_permisos = $permis; } if ($quiverificaModVar == $item['gid']) { $potverificar = true; } $grups[] = $item['gid']; } $nivell_permisos = array('nivell' => $n_permisos, 'verifica' => $verifica, 'potverificar' => $potverificar, 'grups' => $grups); return $nivell_permisos; }
/** * Get the agendas where the user has been subscribed * * @return An array with the agendas where the user has been subscribed */ public function avissubscripcio() { // Security check $this->throwForbiddenUnless(SecurityUtil::checkPermission('IWagendas::', '::', ACCESS_READ)); $uid = UserUtil::getVar('uid'); $myJoin = array(); $myJoin[] = array('join_table' => 'IWagendas_subs', 'join_field' => array('uid'), 'object_field_name' => array('uid'), 'compare_field_table' => 'daid', 'compare_field_join' => 'daid'); $myJoin[] = array('join_table' => 'IWagendas_definition', 'join_field' => array(), 'object_field_name' => array(), 'compare_field_table' => 'daid', 'compare_field_join' => 'daid'); $pntables = DBUtil::getTables(); $ccolumn = $pntables['IWagendas_subs_column']; $ocolumn = $pntables['IWagendas_definition_column']; $where = "b.$ocolumn[daid] = a.$ccolumn[daid] AND $ccolumn[donadabaixa] = '-2' AND $ccolumn[uid] = $uid"; $items = DBUtil::selectExpandedObjectArray('IWagendas_definition', $myJoin, $where, ''); // Check for an error with the database code, and if so set an appropriate // error message and return if ($items === false) { return LogUtil::registerError($this->__('Error! Could not load items.')); } return $items; }
/** * Get all blocks. * * This function gets all block entries from the database. * * @param 'active_status' filter by active status (0=all, 1=active, 2=inactive). * @param 'blockposition' block position id to filter block selection for. * @param 'inactive' force inclusion of inactive blocks (true overrides active_status to 0, false goes with active_status). * @param 'language' language to filter block selection for. * @param 'module_id' module id to filter block selection for. * * @return array array of items, or false on failure. */ public function getall($args) { // create an empty items array $items = array(); // Security check if (!SecurityUtil::checkPermission('Blocks::', '::', ACCESS_OVERVIEW)) { return $items; } $dbtable = DBUtil::getTables(); $blockstable = $dbtable['blocks']; $blockscolumn = $dbtable['blocks_column']; $sort = isset($args['sort']) && $args['sort'] ? $args['sort'] : ''; $sortdir = isset($args['sortdir']) && $args['sortdir'] ? $args['sortdir'] : 'ASC'; if ($sort) { $sort .= " {$sortdir}"; } else { $sort = 'title'; } // backwards parameter compatability if (isset($args['modid']) && is_numeric($args['modid'])) { $args['module_id'] = $args['modid']; } // initialise the where arguments array $whereargs = array(); // filter by block position if (isset($args['blockposition_id']) && is_numeric($args['blockposition_id']) && $args['blockposition_id']) { $where = "pid = {$args['blockposition_id']}"; $bids = DBUtil::selectFieldArray('block_placements', 'bid', $where); $bidList = $bids ? implode(',', $bids) : -1; $whereargs[] = "{$blockscolumn['bid']} IN ({$bidList})"; } // filter by active block status if (isset($args['inactive']) && $args['inactive']) { $args['active_status'] = 0; } if (isset($args['active_status']) && is_numeric($args['active_status']) && $args['active_status']) { // new logic $whereargs[] = "{$blockscolumn['active']} = " . ($args['active_status'] == 1 ? '1' : '0'); } // filter by module if (isset($args['module_id']) && is_numeric($args['module_id']) && $args['module_id']) { $whereargs[] = "{$blockscolumn['mid']} = '" . DataUtil::formatForStore($args['module_id']) . "'"; } // filter by language if (isset($args['language']) && $args['language']) { $whereargs[] = "{$blockscolumn['language']} = '" . DataUtil::formatForStore($args['language']) . "'"; } // construct the where clause $where = ''; if (!empty($whereargs)) { $where = 'WHERE ' . implode(' AND ', $whereargs); } $permFilter = array(); $permFilter[] = array('component_left' => 'Blocks', 'component_middle' => '', 'component_right' => '', 'instance_left' => 'bkey', 'instance_middle' => 'title', 'instance_right' => 'bid', 'level' => ACCESS_OVERVIEW); $joinInfo = array(); $joinInfo[] = array('join_table' => 'modules', 'join_field' => 'name', 'object_field_name' => 'module_name', 'compare_field_table' => 'mid', 'compare_field_join' => 'id'); return DBUtil::selectExpandedObjectArray('blocks', $joinInfo, $where, $sort, -1, -1, '', $permFilter); }
/** * Get the category a module belongs to * @return array of categories */ public function getmodcategories($args) { $joinInfo = array(); $joinInfo[] = array('join_table' => 'admin_category', 'join_field' => 'catname', 'object_field_name' => 'category_name', 'compare_field_table' => 'cid', 'compare_field_join' => 'cid'); // retrieve the admin module object array $result = DBUtil::selectExpandedObjectArray('admin_module', $joinInfo, '', '', -1, -1, 'mid'); if (!$result) { return false; } return $result; }
/** * Get the members of a group * @author: Albert Pérez Monfort (aperezm@xtec.cat) * @return: And array with the users */ public function getMembersGroup($args) { $sv = FormUtil::getPassedValue('sv', isset($args['sv']) ? $args['sv'] : null, 'POST'); $gid = FormUtil::getPassedValue('gid', isset($args['gid']) ? $args['gid'] : null, 'POST'); if (!ModUtil::func('IWmain', 'user', 'checkSecurityValue', array('sv' => $sv))) { return LogUtil::registerError($this->__('You are not allowed to access to some information.')); } $myJoin = array(); $myJoin[] = array('join_table' => 'users', 'join_field' => array('uid'), 'object_field_name' => array('uid'), 'compare_field_table' => 'uid', 'compare_field_join' => 'uid'); $myJoin[] = array('join_table' => 'group_membership', 'join_field' => array(), 'object_field_name' => array(), 'compare_field_table' => 'uid', 'compare_field_join' => 'uid'); $tables = DBUtil::getTables(); $ccolumn = $tables['users_column']; $ocolumn = $tables['group_membership_column']; $where = "b.$ocolumn[gid] = " . $gid; $orderBy = "ORDER BY tbl.$ccolumn[uname]"; $items = DBUtil::selectExpandedObjectArray('users', $myJoin, $where, $orderBy); return $items; }