public function getDeletedPagesCount($args) { $tables = DBUtil::getTables(); $historyColumn = $tables['content_history_column']; $pageColumn = $tables['content_page_column']; $where = "{$historyColumn['pageId']} not in (select {$pageColumn['id']} from {$tables['content_page']}) and {$historyColumn['action']} = '_CONTENT_HISTORYPAGEDELETED'"; /* related to delayed translation */ return DBUtil::selectObjectCount('content_history', $where, 'pageId'); // TODO: distinct }
public static function pendingContent(Zikula_Event $event) { $dom = ZLanguage::getModuleDomain('News'); ModUtil::dbInfoLoad('News'); $dbtables = DBUtil::getTables(); $columns = $dbtables['news_column']; $count = DBUtil::selectObjectCount('news', "WHERE $columns[published_status]=2"); if ($count > 0) { $collection = new Zikula_Collection_Container('News'); $collection->add(new Zikula_Provider_AggregateItem('submission', _n('News article', 'News articles', $count, $dom), $count, 'admin', 'view', array('news_status'=>2))); $event->getSubject()->add($collection); } }
public function countitemsselect($args) { $table = DBUtil::getTables(); $c = $table['IWbooks_column']; extract($args); $sql_eta = ""; if ($etapa != "TOT") $sql_eta = " and " . $c['etapa'] . " LIKE '%$etapa%' "; $sql_mat = ""; if ($materia != "TOT") $sql_mat = " and " . $c['codi_mat'] . " = '$materia' "; $sql_lect = ""; if ($lectura == 1) { $sql_lect = ""; } else { $sql_lect = " and " . $c['lectura'] . " != 1 "; } if (isset($flag) && $flag == 'admin') $sql_lect = ""; $sql_niv = ""; if ($nivell != "") $sql_niv = " and " . $c['nivell'] . " = '$nivell'"; $sql = " " . $c['any'] . " = '$any' " . $sql_eta . $sql_niv . $sql_mat . $sql_lect; $where = $sql; //echo $sql; return DBUtil::selectObjectCount('IWbooks', $where); }
public function es_membre($args) { //Comprovem que el paràmetre identitat hagi arribat if (!isset($args['gid'])) { return LogUtil::registerError($this->__('Error! Could not do what you wanted. Please check your input.')); } // Security check if (!SecurityUtil::checkPermission('IWgroups::', '::', ACCESS_ADMIN)) { throw new Zikula_Exception_Forbidden(); } $table = DBUtil::getTables(); $c = $table['group_membership_column']; $where = "$c[gid] = $args[gid] AND $c[uid] = $args[uid]"; $nombre = DBUtil::selectObjectCount('group_membership', $where); if ($nombre > 0) { return true; } else { return false; } }
/** * Utility function to count the number of items held by this module. * * @return integer Number of items held by this module. */ public function countitems() { // Return the number of items return DBUtil::selectObjectCount('user_property'); }
/** * utility function to count the url of items held by this module * * @return integer count of items held by this module */ public function countitems($args) { $args['catFilter'] = array(); if (isset($args['category']) && !empty($args['category'])){ if (is_array($args['category'])) { $args['catFilter'] = $args['category']; } elseif (isset($args['property'])) { $property = $args['property']; $args['catFilter'][$property] = $args['category']; } $args['catFilter']['__META__'] = array('module' => 'Feeds'); } return DBUtil::selectObjectCount('feeds', '', 'fid', false, $args['catFilter']); }
/** * Count Quotes * @author The Zikula Development Team * @author Greg Allan * @return int count of items */ public function countitems($args) { // optional arguments. if (isset($args['category']) && !empty($args['category'])) { if (is_array($args['category'])) { $args['catFilter'] = $args['category']; } elseif (isset($args['property'])) { $property = $args['property']; $args['catFilter'][$property] = $args['category']; } } if (!isset($args['catFilter'])) { $args['catFilter'] = array(); } $where = $this->_process_args($args); return DBUtil::selectObjectCount('quotes', $where, 'qid', false, $args['catFilter']); }
public function referenced($args) { // Security check if (!SecurityUtil::checkPermission('IWtimeframes::', "::", ACCESS_ADMIN)) { return LogUtil::registerError($this->__('Not authorized to manage timeFrames.'), 403); } if (ModUtil::apifunc('IWtimeframes', 'admin', 'installed', 'IWbookings')) { $mdid = FormUtil::getPassedValue('mdid', isset($args['mdid']) ? $args['mdid'] : null, 'POST'); $tablename = 'IWbookings_spaces'; $where = 'mdid = ' . $mdid; return (DBUtil::selectObjectCount($tablename, $where) > 0); //$n = DBUtil::selectObjectCount($tablename, $where); } else { return false; //$n = 0; } /* $modid = ModUtil::getIdFromName('IWbookings'); $modinfo = ModUtil::getInfo($modid); if ($modinfo['state'] > 1) { $mdid = FormUtil::getPassedValue('mdid', isset($args['mdid']) ? $args['mdid'] : null, 'POST'); $tablename = 'IWbookings_spaces'; $where = 'mdid = ' . $mdid; return (DBUtil::selectObjectCount($tablename, $where) > 0); } else { return false; } * */ }
/** * Determine if a module is hooked by another module. * * @param string $tmodule The target module. * @param string $smodule The source module - default the current top most module. * * @deprecated since 1.3.0 * * @return boolean True if the current module is hooked by the target module, false otherwise. */ public static function isHooked($tmodule, $smodule) { if (!isset(self::$cache['ishooked'])) { self::$cache['ishooked'] = array(); } if (isset(self::$cache['ishooked'][$tmodule][$smodule])) { return self::$cache['ishooked'][$tmodule][$smodule]; } // define input, all numbers and booleans to strings $tmodule = isset($tmodule) ? (string) $tmodule : ''; $smodule = isset($smodule) ? (string) $smodule : ''; // validate if (!System::varValidate($tmodule, 'mod') || !System::varValidate($smodule, 'mod')) { return false; } // Get database info $tables = DBUtil::getTables(); $hookscolumn = $tables['hooks_column']; // Get applicable hooks $where = "WHERE {$hookscolumn['smodule']} = '" . DataUtil::formatForStore($smodule) . "'\n AND {$hookscolumn['tmodule']} = '" . DataUtil::formatForStore($tmodule) . "'"; self::$cache['ishooked'][$tmodule][$smodule] = $numitems = DBUtil::selectObjectCount('hooks', $where); self::$cache['ishooked'][$tmodule][$smodule] = $numitems > 0; return self::$cache['ishooked'][$tmodule][$smodule]; }
/** * Return the record count for the given object set. * * @param string $where The where-clause to use. * @param boolean $doJoin Whether or not to use the auto-join for the count. * * @return array The object's data set count. */ public function getCount($where = '', $doJoin = null) { if ($doJoin === null) { $doJoin = (bool) $this->_objJoin; } else { $doJoin = (bool) $doJoin; } if ($this->_objJoin && $doJoin) { $this->_objData = DBUtil::selectExpandedObjectCount($this->_objType, $this->_objJoin, $where, false, $this->_objCategoryFilter); } else { $this->_objData = DBUtil::selectObjectCount($this->_objType, $where, '1', false, $this->_objCategoryFilter); } return $this->_objData; }
/** * Utility function to count the number of items held by this module * * Credits to Lee Eason from http://pnflashgames.com for giving the idea * to allow a module to find the number of comments that have been added * to the module as a whole or to an individual item. * * @param $args['mod'] name of the module to get the number of comments for * @param $args['objectid'] the objectid to get the number of comments for * @param $args['status'] Status of the comments to get (default: all) * @param $args['owneruid'] (optional) UID of owner * @param $args['uid'] (optional) UID of poster * @param $args['admin'] (optional) set to 1 if called from admin mode * @return integer number of items held by this module */ public function countitems($args = array()) { if (!SecurityUtil::checkPermission('EZComments::', '::', ACCESS_OVERVIEW)) { return false; } // get parameters $owneruid = isset($args['owneruid']) ? (int)$args['owneruid'] : 0; $uid = isset($args['uid']) ? (int)$args['uid'] : 0; // Get database column names $tables = DBUtil::getTables(); $columns = $tables['EZComments_column']; // build the where clause $queryargs = array(); if (isset($args['addwhere'])) { $queryargs[] = $args['addwhere']; } if ($owneruid > 1 && $uid > 1) { $queryargs[] = "$columns[owneruid] = '$args[owneruid]' OR $columns[uid] = '$args[uid]'"; } else if ($uid > 1) { $queryargs[] = "$columns[uid] = '$args[uid]'"; } else if ($owneruid > 1) { $queryargs[] = "$columns[owneruid] = '$args[owneruid]'"; } if (isset($args['mod'])) { // Count comments for a specific module $mod = DataUtil::formatForStore($args['mod']); $queryargs[] = "$columns[modname] = '$mod'"; if (isset($args['objectid'])) { // Count comments for a specific item in a specific mod $objectid = DataUtil::formatForStore($args['objectid']); $queryargs[] = "$columns[objectid] = '$objectid'"; } } if (isset($args['status']) && is_numeric($args['status']) && $args['status'] >= 0 && $args['status'] <= 2) { $queryargs[] = $columns['status'] . ' = \'' . DataUtil::formatForStore($args['status']) . '\''; } // admin mode: only count comments for modules considering permission checks $admin = isset($args['admin']) ? (bool)$args['admin'] : false; if ($admin) { // get list of modules $modlist = ModUtil::getAllMods(); $permclause = array(); foreach ($modlist as $module) { // simple permission check $inst = "$module[name]:".(isset($args['objectid']) ? $args['objectid'] : '').":"; if (SecurityUtil::checkPermission('EZComments::', $inst, ACCESS_EDIT)) { $permclause[] = "$columns[modname] = '$module[name]'"; } } $queryargs[] = implode(' OR ', $permclause); } $where = ''; if (!empty($queryargs)) { $where = implode(' AND ', $queryargs); } return DBUtil::selectObjectCount('EZComments', $where); }
/** * Check if user is pending. * * @param int $args['uid'] user id. * @param int $args['gid'] group id. * * @return boolean */ public function isuserpending($args) { if (!isset($args['gid']) || !isset($args['uid'])) { return LogUtil::registerArgsError(); } $dbtable = DBUtil::getTables(); $col = $dbtable['group_applications_column']; // Check in case the user already applied $where = " WHERE $col[gid] = '" . (int)DataUtil::formatForStore($args['gid']) . "' AND $col[uid] = '" . (int)DataUtil::formatForStore($args['uid']) . "'"; $result = DBUtil::selectObjectCount('group_applications', $where); if ($result >= 1) { return true; } return false; }
/** * Importa les taules de entitats-gtaf i grups d'entitats a partir d'un csv a la base de dades de Sirius * * Esborra el contingut previ de les taules i importa el contingut del fitxer * * @return void Retorna a la funció *gtafEntitiesGest* amb els missatges d'execució */ public function importGtafEntities() { if (!SecurityUtil::checkPermission('Cataleg::', '::', ACCESS_ADMIN)) { return LogUtil::registerPermissionError(); } // get input values. Check for direct function call first because calling function might be either get or post if (isset($args) && is_array($args) && !empty($args)) { $confirmed = isset($args['confirmed']) ? $args['confirmed'] : false; $case = isset($args['case']) ? $args['case'] : false; } elseif (isset($args) && !is_array($args)) { throw new Zikula_Exception_Fatal(LogUtil::getErrorMsgArgs()); } elseif ($this->request->isGet()) { $confirmed = 1; } elseif ($this->request->isPost()) { $this->checkCsrfToken(); $confirmed = $this->request->request->get('confirmed', false); $case = $this->request->request->get('case',false); } if ($confirmed == 2) { if ($case == 'entities') { $caps = array( 'gtafEntityId' => 'gtafEntityId', 'nom' => 'nom', 'tipus' => 'tipus', 'gtafGroupId' => 'gtafGroupId' ); $caps_man = $caps; $taula = 'cataleg_gtafEntities'; $mes = "Importació d'entitats-gtaf"; $field_id = 'gtafEntityId'; } else { $caps = array( 'gtafGroupId' => 'gtafGroupId', 'nom' => 'nom', 'resp_uid' => 'resp_uid' ); $caps_man = array( 'gtafGroupId' => 'gtafGroupId', 'nom' => 'nom' ); $taula = 'cataleg_gtafGroups'; $mes = "Importació de grups d'entitats-gtaf"; $field_id = 'gtafGroupId'; } // get other import values $importFile = $this->request->files->get('importFile', isset($args['importFile']) ? $args['importFile'] : null); $fileName = $importFile['name']; $importResults = ''; if ($fileName == '') { $importResults = $this->__("No heu triat cap fitxer."); } elseif (FileUtil::getExtension($fileName) != 'csv') { $importResults = $this->__("L'extensió del fitxer ha de ser csv."); } elseif (!$file_handle = fopen($importFile['tmp_name'], 'r')) { $importResults = $this->__("No s'ha pogut llegir el fitxer csv."); } else { while (!feof($file_handle)) { $line = fgetcsv($file_handle, 1024, ';', '"'); if ($line != '') { $lines[] = $line; } } fclose($file_handle); // foreach ($lines as $line_num => $line) { if ($line_num != 0) { if (count($lines[0]) != count($line)) { $importResults .= $this->__("<div>Hi ha registres amb un número de camps incorrecte.</div>"); } else { $import[] = array_combine($lines[0], $line); $import_id[] = $line[0]; } } else { $difs = array_diff($line, $caps); $difs2 = array_diff($caps_man,$line); if (count($line) != count(array_unique($line))) { $importResults .= $this->__("<div>La capçalera del csv té columnes repetides.</div>"); } elseif (!in_array($field_id, $line)) { $importResults .= $this->__("<div>Falta el camp obligatori de la clau primària (id).</div>"); } elseif ($line[0] != $field_id) { $importResults .= $this->__("<div>El camp obligatori de la clau primària (id) ha d'ocupar el primer lloc.</div>"); } elseif (!empty($difs2)) { $importResults .= $this->__("<div>Falten camps obligatoris.</div>"); } elseif (!empty($difs)) { $importResults .= $this->__("div>El csv té camps incorrectes.</div>"); } } } if (count($import_id) != count(array_unique($import_id))) $importResults .= $this->__("<div>El fitxer té alguna id repetida.</div>"); } if ($importResults == '') { $old_reg = DBUtil::selectObjectCount($taula); DBUtil::deleteWhere($taula); $inserts = count($import); DBUtil::insertObjectArray($import, $taula); $this->registerStatus($mes); $this->registerStatus($this->__('La importació s\'ha realitzat correctament')); $this->registerStatus($this->__('Registres antics: ' . $old_reg . ' - Registres actuals: ' . $inserts)); return system::redirect(ModUtil::url('Cataleg', 'admin', 'gtafEntitiesGest')); } else { $this->view->assign('case',$case); $post_max_size = ini_get('post_max_size'); return $this->view->assign('importResults', isset($importResults) ? $importResults : '') ->assign('post_max_size', $post_max_size) ->fetch('admin/Cataleg_admin_importGtafEntities.tpl'); } } elseif ($confirmed == 1){ // shows the form $case = $this->request->query->get('case',false); $this->view->assign('case',$case); $post_max_size = ini_get('post_max_size'); return $this->view->assign('importResults', isset($importResults) ? $importResults : '') ->assign('post_max_size', $post_max_size) ->fetch('admin/Cataleg_admin_importGtafEntities.tpl'); } else { LogUtil::registerError($this->__('La petició no és vàlida')); return system::redirect(ModUtil::url('Cataleg', 'admin', 'gtafEntitiesGest')); } }
public function countDocuments($args) { $table = DBUtil::getTables(); $c = $table['IWdocmanager_column']; $where = "$c[categoryId] = $args[categoryId] AND $c[validated] = 1 AND $c[versioned] <= 0"; $number = DBUtil::selectObjectCount('IWdocmanager', $where); $where = "$c[categoryId] = $args[categoryId] AND $c[validated] = 0 AND $c[versioned] <= 0"; $number1 = DBUtil::selectObjectCount('IWdocmanager', $where); $c = $table['IWdocmanager_categories_column']; $where = "$c[categoryId] = $args[categoryId]"; $item = array('nDocuments' => $number, 'nDocumentsNV' => $number1 ); DBUtil::updateObject($item, 'IWdocmanager_categories', $where); return true; }
/** * utility function to count the number of items held by this module * @author Mark West * @return int number of items held by this module */ function Admin_Messages_userapi_countitems() { return DBUtil::selectObjectCount('message', ''); }
public function getAllRecords($args) { if (!SecurityUtil::checkPermission('IWstats::', '::', ACCESS_READ)) { return LogUtil::registerPermissionError(); } $items = array(); $init = (isset($args['init'])) ? $args['init'] - 1 : -1; $rpp = (isset($args['rpp'])) ? $args['rpp'] : -1; $table = DBUtil::getTables(); $where = ""; $c = $table['IWstats_column']; if (isset($args['moduleId']) && $args['moduleId'] > 0) { $and = ($where != '') ? ' AND ' : ''; $where .= $and . "$c[moduleid] = $args[moduleId]"; } if (isset($args['uid']) && $args['uid'] > 0) { $and = ($where != '') ? ' AND ' : ''; $where .= $and . "$c[uid] = $args[uid]"; } if (isset($args['ip']) && $args['ip'] != null) { $and = ($where != '') ? ' AND ' : ''; $where .= $and . "$c[ip] = '$args[ip]'"; } if (isset($args['registered']) && $args['registered'] == 1) { $and = ($where != '') ? ' AND ' : ''; $where .= $and . "$c[uid] > 0"; } if (!isset($args['all']) || $args['all'] != 1) { $and = ($where == '') ? '' : ' AND'; $where .= "$and $c[isadmin] = 0 AND $c[skipped] = 0 AND $c[skippedModule] = 0"; } if ($args['fromDate'] != null) { $and = ($where == '') ? '' : ' AND'; if (!isset($args['timeIncluded'])) { $from = mktime(0, 0, 0, substr($args['fromDate'], 3, 2), substr($args['fromDate'], 0, 2), substr($args['fromDate'], 6, 4)); $to = mktime(23, 59, 59, substr($args['toDate'], 3, 2), substr($args['toDate'], 0, 2), substr($args['toDate'], 6, 4)); } else { $from = mktime(substr($args['fromDate'], 11, 2), substr($args['fromDate'], 14, 2), substr($args['fromDate'], 17, 2), substr($args['fromDate'], 3, 2), substr($args['fromDate'], 0, 2), substr($args['fromDate'], 6, 4)); $to = mktime(substr($args['toDate'], 11, 2), substr($args['toDate'], 14, 2), substr($args['toDate'], 17, 2), substr($args['toDate'], 3, 2), substr($args['toDate'], 0, 2), substr($args['toDate'], 6, 4)); } $fromSQL = date('Y-m-d H:i:s', $from); $toSQL = date('Y-m-d H:i:s', $to); $where .= "$and ($c[datetime] BETWEEN '$fromSQL' AND '$toSQL')"; } $orderby = "$c[statsid] desc"; if (isset($args['onlyNumber']) && $args['onlyNumber'] == 1) { $items = DBUtil::selectObjectCount('IWstats', $where); } else { $items = DBUtil::selectObjectArray('IWstats', $where, $orderby, $init, $rpp, 'statsid'); } // 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! Load attempt failed.')); } // Return the items return $items; }
/** * check if a permalink is unique for Pages * * @author Frank Schummertz * @return boolean true if permalink is unique, otherwise false */ public function checkuniquepermalink($args) { $table = DBUtil::getTables(); $pagescol = $table['pages_column']; $where = "WHERE $pagescol[urltitle] = '" . DataUtil::formatForStore($args['urltitle']) . "'"; if (isset($args['pageid']) && $args['pageid']) { $where .= " AND $pagescol[pageid] != " . DataUtil::formatForStore((int)($args['pageid'])); } $count = DBUtil::selectObjectCount('pages', $where); return !((bool)$count); }
public function countElementsCataleg() { if (!SecurityUtil::checkPermission('Cataleg::', '::', ACCESS_ADMIN)) { return LogUtil::registerPermissionError(); } $cats=array(); $cats = ModUtil::apiFunc('Cataleg', 'user', 'getCatalegList', true); foreach ($cats as $key=>$cat) { $cats[$key]['uni'] = 0; $cats[$key]['eix'] = 0; $cats[$key]['pri'] = 0; $cats[$key]['spr'] = 0; $cats[$key]['uni'] = DBUtil::selectObjectCount('cataleg_unitats','catId = '.$cat['catId']); $eixos[$key] = DBUtil::selectObjectArray('cataleg_eixos','catId = '.$cat['catId']); foreach ($eixos[$key] as $pkey=>$eix) { ++$cats[$key]['eix']; $prioritats[$key][$pkey] = DBUtil::selectObjectArray('cataleg_prioritats','eixId = '.$eix['eixId']); foreach ($prioritats[$key][$pkey] as $prioritat) { ++$cats[$key]['pri']; $cats[$key]['spr'] += DBUtil::selectObjectCount('cataleg_subprioritats','priId = '.$prioritat['priId']); } } } return $cats; }
public function reservat($args) { $sid = FormUtil::getPassedValue('sid', isset($args['sid']) ? $args['sid'] : null, 'GET'); $start = FormUtil::getPassedValue('inici', isset($args['inici']) ? $args['inici'] : null, 'GET'); $end = FormUtil::getPassedValue('final', isset($args['final']) ? $args['final'] : null, 'GET'); $startTime = date('H:i:s', strtotime($start)); $endTime = date('H:i:s', strtotime($end)); //Comprovaci� de seguretat. Si falla retorna una matriu buida if (!SecurityUtil::checkPermission('IWbookings::', '::', ACCESS_READ)) { return $registres; } // Get day of week $dow = date("w", DateUtil::makeTimeStamp($start)); $pntable = DBUtil::getTables(); $c = $pntable['IWbookings_column']; $where = " WHERE $c[sid]= '" . DataUtil::formatForStore($sid) . "' AND $c[dayofweek]= '" . DataUtil::formatForStore($dow) . "' AND ((DATE_FORMAT($c[start], '%H:%i:%s') >= '" . DataUtil::formatForStore($startTime) . "' AND DATE_FORMAT($c[start], '%H:%i:%s')<'" . DataUtil::formatForStore($endTime) . "') OR (DATE_FORMAT($c[end], '%H:%i:%s') > '" . DataUtil::formatForStore($startTime) . "' AND DATE_FORMAT($c[end], '%H:%i:%s') <='" . DataUtil::formatForStore($endTime) . "') OR (DATE_FORMAT($c[start], '%H:%i:%s')<'" . DataUtil::formatForStore($startTime) . "' AND DATE_FORMAT($c[end], '%H:%i:%s')>'" . DataUtil::formatForStore($endTime) . "')) AND $c[cancel]=0"; $items = DBUtil::selectObjectCount('IWbookings', $where); return $items; }
/** * Returns the number of pending applications for new user accounts (registration requests). * * NOTE: Expired registrations are purged before the count is performed. * * Parameters passed in the $args array: * ------------------------------------- * array $args['filter'] An array of field/value combinations used to filter the results. Optional, default * is to count all records. * * @param array $args All parameters passed to this function. * * @return integer|boolean Numer of pending applications, false on error. */ public function countAll($args) { if ((!UserUtil::isLoggedIn() && !SecurityUtil::checkPermission('Users::', '::', ACCESS_READ)) || (UserUtil::isLoggedIn() && !SecurityUtil::checkPermission('Users::', '::', ACCESS_MODERATE))) { return false; } $where = ''; if (isset($args['filter'])) { if (!is_array($args['filter'])) { $this->registerError(LogUtil::getErrorMsgArgs()); return false; } if (isset($args['filter']['isverified'])) { $isVerifiedFilter = $args['filter']['isverified']; unset($args['filter']['isverified']); } $args['filter']['activated'] = Users_Constant::ACTIVATED_PENDING_REG; $where = $this->whereFromFilter($args['filter']); } else { $where = $this->whereFromFilter(array('activated' => Users_Constant::ACTIVATED_PENDING_REG)); } if ($where === false) { return false; } $this->purgeExpired(); if (isset($isVerifiedFilter)) { // TODO - Can probably do this with a constructed SQL count select and join, but we'll do it this way for now. if (!is_array($isVerifiedFilter)) { $isVerifiedFilter = array( 'operator' => '=', 'operand' => $isVerifiedFilter, ); } // TODO - might want to error if the operator is not =, != or <>, or if the operand is not a boolean $isVerifiedValue = ($isVerifiedFilter['operator'] == '=') && (bool)$isVerifiedFilter['operand']; $users = DBUtil::selectObjectArray('users', $where, null, null, null, null, null, null, array('uid')); $count = 0; if ($users) { foreach ($users as $userRec) { if ($userRec['__ATTRIBUTES__']['_Users_isVerified'] == $isVerifiedValue) { $count++; } } } return $count; } else { return DBUtil::selectObjectCount('users', $where); } }
/** * Counts how many times an e-mail address has been used by user accounts in the system. * * @param string $emailAddress The e-mail address in question (required). * @param int $excludeUid The uid to exclude from the check, used when checking modifications. * * @return integer|boolean The count, or false on error. */ public static function getEmailUsageCount($emailAddress, $excludeUid = 0) { if (!is_numeric($excludeUid) || (int) $excludeUid != $excludeUid) { return false; } $emailAddress = DataUtil::formatForStore(mb_strtolower($emailAddress)); $dbinfo = DBUtil::getTables(); $usersColumn = $dbinfo['users_column']; $where = "({$usersColumn['email']} = '{$emailAddress}')"; if ($excludeUid > 1) { $where .= " AND ({$usersColumn['uid']} != {$excludeUid})"; } $ucount = DBUtil::selectObjectCount('users', $where); $verifyChgColumn = $dbinfo['users_verifychg_column']; $where = "({$verifyChgColumn['newemail']} = '{$emailAddress}') AND ({$verifyChgColumn['changetype']} = " . Users_Constant::VERIFYCHGTYPE_EMAIL . ")"; if ($excludeUid > 1) { $where .= " AND ({$verifyChgColumn['uid']} != {$excludeUid})"; } $vcount = DBUtil::selectObjectCount('users_verifychg', $where); if ($ucount === false || $vcount === false) { return false; } else { return $ucount + $vcount; } }
/** * Utility function to count the number of items held by this module. * * @param array $args All parameters passed to this function. * string $args['letter'] Filter the count by the first letter of the module name; optional. * integer $args['state'] Filter the count by the module state; optional. * * @return integer The number of items held by this module. */ public function countitems($args) { $dbtable = DBUtil::getTables(); $modulescolumn = $dbtable['modules_column']; // filter my first letter of module if (isset($args['letter']) && !empty($args['letter'])) { $where[] = "{$modulescolumn['name']} LIKE '" . DataUtil::formatForStore($args['letter']) . "%'"; } // filter by module state switch ($args['state']) { case ModUtil::STATE_UNINITIALISED: case ModUtil::STATE_INACTIVE: case ModUtil::STATE_ACTIVE: case ModUtil::STATE_MISSING: case ModUtil::STATE_UPGRADED: case ModUtil::STATE_INVALID: $where[] = "{$modulescolumn['state']} = '" . DataUtil::formatForStore($args['state']) . "'"; break; default: if ($args['state'] > 10) { $where[] = "{$modulescolumn['state']} > 10 "; } } // generate where clause $wheresql = ''; if (isset($where) && is_array($where)) { $wheresql = 'WHERE ' . implode(' AND ', $where); } $count = DBUtil::selectObjectCount('modules', $wheresql); if ($count === false) { return LogUtil::registerError($this->__('Error! Could not load data.')); } return $count; }
/** * utility function to count the number of items held by this module * * @author Mark West * @return int number of items held by this module */ public function countitems($args) { // Optional arguments. if (!isset($args['status']) || (empty($args['status']) && $args['status'] !== 0)) { $args['status'] = null; } if (!isset($args['ignoreml']) || !is_bool($args['ignoreml'])) { $args['ignoreml'] = false; } if (!isset($args['language'])) { $args['language'] = ''; } $where = $this->generateWhere($args); $where = !empty($where) ? ' WHERE ' . $where : ''; return DBUtil::selectObjectCount('news', $where, 'sid', false, $this->getCatFilter($args)); }
/** * Migrate from version 1.13 to 2.2.0 * * @param string $oldversion The old version from which this upgrade is being processed. * * @return bool True on success; otherwise false. */ public function upgrade113XTablesTo220Tables($oldversion) { if (!DBUtil::changeTable('users_temp')) { return false; } // Get the dbinfo for the new version ModUtil::dbInfoLoad('Users', 'Users'); $nowUTC = new DateTime(null, new DateTimeZone('UTC')); $nowUTCStr = $nowUTC->format(Users_Constant::DATETIME_FORMAT); $serviceManager = ServiceUtil::getManager(); $dbinfoSystem = $serviceManager['dbtables']; $dbinfo113X = Users_tables('1.13'); $dbinfo220 = Users_tables('2.2.0'); $usersOldFields = array( 'user_theme', 'user_viewemail', 'storynum', 'counter', 'hash_method', 'validfrom', 'validuntil', ); $usersOldFieldsDB = array( $dbinfo113X['users_column']['user_theme'], $dbinfo113X['users_column']['user_viewemail'], $dbinfo113X['users_column']['storynum'], $dbinfo113X['users_column']['counter'], $dbinfo113X['users_column']['hash_method'], $dbinfo113X['users_column']['validfrom'], $dbinfo113X['users_column']['validuntil'] ); // Upgrade the tables // Update the users table with new and altered fields. No fields are removed at this point, and no fields // are getting a new data type that is incompatible, so no need to save anything off first. // Also, create the users_verifychg tables at this point. // Merge the global dbtables with the new field information. $tables['users_column'] = $dbinfo220['users_column']; $tables['users_column_def'] = $dbinfo220['users_column_def']; $tables['users_verifychg'] = $dbinfo220['users_verifychg']; $tables['users_verifychg_column'] = $dbinfo220['users_verifychg_column']; $tables['users_verifychg_column_def'] = $dbinfo220['users_verifychg_column_def']; $serviceManager['dbtables'] = array_merge($dbinfoSystem, $tables); // Now change the tables if (!DBUtil::changeTable('users')) { return false; } if (!DBUtil::createTable('users_verifychg')) { return false; } // First users_temp pending email verification records to users_verifychg. $tempColumn = $dbinfo113X['users_temp_column']; $verifyColumn = $dbinfo220['users_verifychg_column']; $usersColumn = $dbinfo220['users_column']; $legalModInfo = ModUtil::getInfoFromName('Legal'); if (($legalModInfo['state'] == ModUtil::STATE_ACTIVE) || ($legalModInfo['state'] == ModUtil::STATE_UPGRADED)) { $legalModuleActive = true; $termsOfUseActive = ModUtil::getVar('Legal', 'termsofuse', false); $privacyPolicyActive = ModUtil::getVar('Legal', 'privacypolicy', false); $agePolicyActive = ($this->getVar('minage', 0) > 0); } else { $legalModuleActive = false; } // Next, users table conversion // We need to convert some information over from the old users table fields, so merge the old field list into // the new one. The order of array_merge parameters is important here! $tables = array('users_column' => array_merge($dbinfo113X['users_column'], $dbinfo220['users_column'])); $serviceManager['dbtables'] = array_merge($dbinfoSystem, $tables); // Do the conversion in PHP we use mb_strtolower, and even if MySQL had an equivalent, there is // no guarantee that another supported DB platform would. $limitNumRows = 100; $limitOffset = 0; $updated = true; $userCount = DBUtil::selectObjectCount('users'); while ($limitOffset < $userCount) { $userArray = DBUtil::selectObjectArray('users', "{$usersColumn['uid']} != 1", '', $limitOffset, $limitNumRows, '', null, null, array('uid', 'uname', 'email', 'pass', 'hash_method', 'user_regdate', 'lastlogin', 'approved_by', 'approved_date')); if (!empty($userArray) && is_array($userArray)) { foreach ($userArray as $key => $userObj) { // force user names and emails to lower case $userArray[$key]['uname'] = mb_strtolower($userArray[$key]['uname']); $userArray[$key]['email'] = mb_strtolower($userArray[$key]['email']); if ($userArray[$key]['user_regdate'] == '1970-01-01 00:00:00') { $userArray[$key]['user_regdate'] = $nowUTCStr; $userArray[$key]['approved_date'] = $nowUTCStr; } else { $userArray[$key]['approved_date'] = $userArray[$key]['user_regdate']; } $userArray[$key]['approved_by'] = 2; // merge hash method for salted passwords, leave salt blank if (!empty($userArray[$key]['pass']) && (strpos($userArray[$key]['pass'], '$$') === false)) { $userArray[$key]['pass'] = (isset($userArray[$key]['hash_method']) ? $userArray[$key]['hash_method'] : '1') . '$$' . $userArray[$key]['pass']; } // Save some disappearing fields as attributes, just in case someone actually used them for // something. But don't overwrite if there already if (!isset($userArray[$key]['__ATTRIBUTES__']) || !is_array($userArray[$key]['__ATTRIBUTES__'])) { $userArray[$key]['__ATTRIBUTES__'] = array(); } foreach ($usersOldFields as $fieldName) { if (($fieldName != 'hash_method') && isset($userArray[$key][$fieldName]) && !empty($userArray[$key][$fieldName]) && !isset($userArray[$key]['__ATTRIBUTES__'][$fieldName])) { $userArray[$key]['__ATTRIBUTES__'][$fieldName] = $userArray[$key][$fieldName]; } } if ($legalModuleActive && ($userArray[$key]['uid'] > 2)) { $userRegDateTime = new DateTime($userArray[$key]['user_regdate'], new DateTimeZone('UTC')); $policyDateTimeStr = $userRegDateTime->format(DATE_ISO8601); if ($termsOfUseActive) { $userArray[$key]['__ATTRIBUTES__']['_Legal_termsOfUseAccepted'] = $policyDateTimeStr; } if ($privacyPolicyActive) { $userArray[$key]['__ATTRIBUTES__']['_Legal_privacyPolicyAccepted'] = $policyDateTimeStr; } if ($agePolicyActive) { $userArray[$key]['__ATTRIBUTES__']['_Legal_agePolicyConfirmed'] = $policyDateTimeStr; } } } } if (!DBUtil::updateObjectArray($userArray, 'users', 'uid', false)) { $updated = false; break; } $limitOffset += $limitNumRows; } if (!$updated) { return false; } $obaColumn = $dbinfoSystem['objectdata_attributes_column']; $limitNumRows = 100; $limitOffset = 0; $updated = true; $userCount = DBUtil::selectObjectCount('users_temp'); // Pass through the users_temp table in chunks of 100 // * ensure unames and email addresses are lower case, while ($limitOffset < $userCount) { $userTempArray = DBUtil::selectObjectArray('users_temp', '', '', $limitOffset, $limitNumRows, '', null, null, array('tid', 'type', 'uname', 'email', 'pass', 'hash_method', 'dynamics', 'comment')); $userArray = array(); if (!empty($userTempArray) && is_array($userTempArray)) { foreach ($userTempArray as $key => $userTempOpj) { // type == 1: User registration pending approval (moderation) if ($userTempArray[$key]['type'] == 1) { $userObj = array(); // Ensure uname and email are lower case $userObj['uname'] = mb_strtolower($userTempArray[$key]['uname']); $userObj['email'] = mb_strtolower($userTempArray[$key]['email']); // Convert pass to salted pass with embedded hash method, leave salt blank $userObj['pass'] = $userTempArray[$key]['hash_method'] . '$$' . $userTempArray[$key]['pass']; $userObj['approved_by'] = 0; $userObj['activated'] = Users_Constant::ACTIVATED_PENDING_REG; if (!empty($userTempArray[$key]['dynamics'])) { $userObj['__ATTRIBUTES__'] = unserialize($userTempArray[$key]['dynamics']); } else { $userObj['__ATTRIBUTES__'] = array(); } if (isset($userObj['dynamics']) && !empty($userObj['dynamics'])) { if (DataUtil::is_serialized($userObj['dynamics'])) { $dynamics = @unserialize($userObj['dynamics']); if (!empty($dynamics) && is_array($dynamics)) { foreach ($dynamics as $key => $value) { $userObj['__ATTRIBUTES__'][$key] = $value; } } } } $userObj['__ATTRIBUTES__']['_Users_isVerified'] = 0; if ($legalModuleActive) { $userRegDateTime = new DateTime($userArray[$key]['user_regdate'], new DateTimeZone('UTC')); $policyDateTimeStr = $userRegDateTime->format(DATE_ISO8601); if ($termsOfUseActive) { $userObj['__ATTRIBUTES__']['_Legal_termsOfUseAccepted'] = $policyDateTimeStr; } if ($privacyPolicyActive) { $userObj['__ATTRIBUTES__']['_Legal_privacyPolicyAccepted'] = $policyDateTimeStr; } if ($agePolicyActive) { $userObj['__ATTRIBUTES__']['_Legal_agePolicyConfirmed'] = $policyDateTimeStr; } } $userArray[] = $userObj; } else { throw new Zikula_Exception_Fatal($this->__f('Unknown users_temp record type: %1$s', array($userTempArray[$key]['type']))); } } } if (!DBUtil::insertObjectArray($userArray, 'users', 'uid', false)) { $updated = false; break; } $limitOffset += $limitNumRows; } if (!$updated) { return false; } // Done upgrading. Let's lose some old fields and tables we no longer need. DBUtil::dropColumn('users', $usersOldFieldsDB); DBUtil::dropTable('users_temp'); // Reset the system tables to the new table definitons, so the rest of the // system upgrade goes smoothly. $dbinfoSystem = $serviceManager['dbtables']; foreach ($dbinfo113X as $key => $value) { unset($dbinfoSystem[$key]); } foreach ($dbinfo220 as $key => $value) { $dbinfoSystem[$key] = $value; } $serviceManager['dbtables'] = $dbinfoSystem; // Update users table for data type change of activated field. if (!DBUtil::changeTable('users')) { return false; } return true; }
/** * Retrieve the count for a given attribute name. * * @param string $atrName The name of the attribute. * * @return The count for the given attribute */ public static function getAttributeCount($atrName) { $dbtables = DBUtil::getTables(); $column = $dbtables['objectdata_attributes_column']; $where = "{$column['attribute_name']}='" . DataUtil::formatForStore($atrName) . "'"; return DBUtil::selectObjectCount('objectdata_attributes', $where); }
/** * Update the IWdocmanager module * @author Albert Pérez Monfort (aperezm@xtec.cat) * @return bool true if successful, false otherwise */ public function upgrade($oldversion) { $table = DBUtil::getTables(); switch ($oldversion) { case '0.0.1'; $table = DBUtil::getTables(); $c = $table['IWdocmanager_column']; $c1 = $table['IWdocmanager_categories_column']; // used in agora module upgrade in order to calc the number of document in each category $categories = DBUtil::selectObjectArray('IWdocmanager_categories', '', '', '-1', '-1', 'categoryId'); foreach ($categories as $category) { $where = "$c[categoryId] = $category[categoryId] AND $c[validated] = 1 AND $c[versioned] <= 0"; $number = DBUtil::selectObjectCount('IWdocmanager', $where); $where = "$c[categoryId] = $category[categoryId] AND $c[validated] = 0 AND $c[versioned] <= 0"; $number1 = DBUtil::selectObjectCount('IWdocmanager', $where); $where = "$c1[categoryId] = $category[categoryId]"; $item = array('nDocuments' => $number, 'nDocumentsNV' => $number1 ); DBUtil::updateObject($item, 'IWdocmanager_categories', $where); } case '1.0.0': // future versions } return true; }
/** * Utility function to count the number of previous search queries. * * @return integer number of items held by this module. */ public function countitems() { return DBUtil::selectObjectCount('search_stat'); }
/** * Utility function to count the number of items held by this module. * * @return int number of items held by this module. */ public function countitems() { return DBUtil::selectObjectCount('groups'); }
/** * utility function to count the number of items held by this module * * * * @return integer number of items held by this module */ public function countitems($args) { $catFilter = array(); if (isset($args['category']) && !empty($args['category'])){ if (is_array($args['category'])) { $catFilter = $args['category']; } elseif (isset($args['property'])) { $property = $args['property']; $catFilter[$property] = $args['category']; } $catFilter['__META__'] = array('module' => 'Pages'); } elseif (isset($args['catfilter'])) { $catFilter = $args['catfilter']; } // return the number of items return DBUtil::selectObjectCount('pages', '', 'pageid', false, $catFilter); }
/** * Count and return the number of users. * * Parameters passed in the $args array: * ------------------------------------- * string $args['letter'] If specified, then only those user records whose user name begins with the specified letter are counted. * * @param array $args All parameters passed to this function. * * @return int Number of users. * * @todo Shouldn't there be some sort of limit on the select/loop?? */ public function countItems($args) { // Check validity of letter arg. // $args['letter'] is really an SQL LIKE filter if (isset($args['letter']) && (empty($args['letter']) || !is_string($args['letter']) || strstr($args['letter'], '%'))) { $this->registerError(LogUtil::getErrorMsgArgs()); return false; } $table = DBUtil::getTables(); $usersColumn = $table['users_column']; // form where clause $where = ''; if (isset($args['letter'])) { $where = "WHERE {$usersColumn['uname']} LIKE '".DataUtil::formatForStore($args['letter'])."%'"; } $objCount = DBUtil::selectObjectCount('users', $where); // Check for a DB error if ($objCount === false) { $this->registerError($this->__('Error! Could not load data.')); return false; } return $objCount; }