1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395
<?php
/**
***********************************************************************************************
* @copyright 2004-2016 The Admidio Team
* @see http://www.admidio.org/
* @license https://www.gnu.org/licenses/gpl-2.0.html GNU General Public License v2.0 only
***********************************************************************************************
*/
/**
* @class ModuleLists
* @brief Class manages lists viewable for user
*
* This class reads all available recordsets from table lists.
* and returns an Array with results, recordsets and validated parameters from $_GET Array.
* @par Returned Array
* @code
* Array(
* [numResults] => 5
* [limit] => 10
* [totalCount] => 5
* [recordset] => Array
* (
* [0] => Array
* (
* [0] => 2
* [rol_id] => 2
* [1] => 3
* [rol_cat_id] => 3
* [2] =>
* [rol_lst_id] =>
* [3] => Mitglieder
* [rol_name] => Mitglieder
* [4] => Alle Mitglieder der Organisation
* [rol_description] => Alle Mitglieder der Organisation
* [5] => 0
* [rol_assign_roles] => 0
* [6] => 0
* [rol_approve_users] => 0
* [7] => 0
* [rol_announcements] => 0
* [8] => 0
* [rol_dates] => 0
* [9] => 0
* [rol_download] => 0
* [10] => 0
* [rol_edit_user] => 0
* [11] => 0
* [rol_guestbook] => 0
* [12] => 1
* [rol_guestbook_comments] => 1
* [13] => 0
* [rol_mail_to_all] => 0
* [14] => 2
* [rol_mail_this_role] => 2
* [15] => 0
* [rol_photo] => 0
* [16] => 1
* [rol_profile] => 1
* [17] => 0
* [rol_weblinks] => 0
* [18] => 2
* [rol_this_list_view] => 2
* [19] => 0
* [rol_all_lists_view] => 0
* [20] => 1
* [rol_default_registration] => 1
* [21] => 1
* [rol_leader_rights] => 1
* [22] =>
* [rol_start_date] =>
* [23] =>
* [rol_start_time] =>
* [24] =>
* [rol_end_date] =>
* [25] =>
* [rol_end_time] =>
* [26] => 0
* [rol_weekday] => 0
* [27] =>
* [rol_location] =>
* [28] =>
* [rol_max_members] =>
* [29] =>
* [rol_cost] =>
* [30] =>
* [rol_cost_period] =>
* [31] => 1
* [rol_usr_id_create] => 1
* [32] => 2008-05-03 16:26:36
* [rol_timestamp_create] => 2008-05-03 16:26:36
* [33] => 1
* [rol_usr_id_change] => 1
* [34] => 2008-05-03 16:26:36
* [rol_timestamp_change] => 2008-05-03 16:26:36
* [35] => 1
* [rol_valid] => 1
* [36] => 0
* [rol_system] => 0
* [37] => 1
* [rol_visible] => 1
* [38] => 0
* [rol_administrator] => 0
* [39] => 3
* [cat_id] => 3
* [40] => 1
* [cat_org_id] => 1
* [41] => ROL
* [cat_type] => ROL
* [42] => COMMON
* [cat_name_intern] => COMMON
* [43] => Allgemein
* [cat_name] => Allgemein
* [44] => 0
* [cat_hidden] => 0
* [45] => 0
* [cat_system] => 0
* [46] => 0
* [cat_default] => 0
* [47] => 1
* [cat_sequence] => 1
* [48] => 1
* [cat_usr_id_create] => 1
* [49] => 2012-01-08 11:12:05
* [cat_timestamp_create] => 2012-01-08 11:12:05
* [50] =>
* [cat_usr_id_change] =>
* [51] =>
* [cat_timestamp_change] =>
* [52] => 145
* [num_members] => 145
* [53] => 0
* [num_leader] => 0
* [54] => 5
* [num_former] => 5
* )
*
* [parameter] => Array
* (
* [active_role] => 1
* [calendar-selection] => 1
* [cat_id] => 0
* [category-selection] => 1
* [date] =>
* [daterange] => Array
* (
* [english] => Array
* (
* [start_date] => 2013-09-24
* [end_date] => 9999-12-31
* )
*
* [system] => Array
* (
* [start_date] => 24.09.2013
* [end_date] => 31.12.9999
* )
*
* )
*
* [headline] => Übersicht der aktiven Rollen
* [id] => 0
* [mode] => Default
* [order] => ASC
* [startelement] => 0
* [view_mode] => Default
* )
* )
* @endcode
*/
class ModuleLists extends Modules
{
private $memberStatus;
/**
* creates an new ModuleLists object
*/
public function __construct()
{
global $gL10n;
// define constant for headline
define('HEADLINE', $gL10n->get('LST_ACTIVE_ROLES'));
// get parent instance with all parameters from $_GET Array
parent::__construct();
$this->setMemberStatus();
}
/**
* Evaluates memberStatus an returns appropriate SQL conditions
* @return string SQL for member status
*/
private function getMemberStatusSql()
{
switch ($this->memberStatus)
{
case 'inactive':
$sql = ' AND mem_end < \''.DATE_NOW.'\' ';
break;
case 'both':
$sql ='';
break;
case 'active':
default:
$sql = ' AND mem_begin <= \''.DATE_NOW.'\'
AND mem_end >= \''.DATE_NOW.'\' ';
}
return $sql;
}
/**
* returns SQL condition
* @return string SQL condition for category id
*/
private function getCategorySql()
{
if($this->catId > 0)
{
return ' AND cat_id = '.$this->catId;
}
return '';
}
/**
* assembles SQL roles visible for current user
* @return string SQL condition visible for current user
*/
private function getVisibleRolesSql()
{
global $gCurrentUser;
if($this->activeRole === 0 && $gCurrentUser->isAdministrator())
{
// if inactive roles should be shown, then show all of them to administrator
return '';
}
// create a list with all rol_ids that the user is allowed to view
$visibleRoles = implode(',', $gCurrentUser->getAllVisibleRoles());
if($visibleRoles !== '')
{
return ' AND rol_id IN ('.$visibleRoles.')';
}
return ' AND rol_id = 0 ';
}
/**
* Function returns a set of lists with corresponding information
* @param int $startElement Start element of result. First (and default) is 0.
* @param int $limit Number of elements returned max. Default NULL will take number from preferences.
* @return array with list and corresponding information
*/
public function getDataSet($startElement = 0, $limit = null)
{
global $gCurrentOrganization, $gPreferences, $gValidLogin, $gDb;
// Parameter
if($limit === null)
{
// Roles per page
$limit = $gPreferences['lists_roles_per_page'];
}
// assemble conditions
$sql_conditions = $this->getCategorySql().$this->getVisibleRolesSql();
// provoke empty result for not logged in users
if(!$gValidLogin)
{
$sql_conditions .= ' AND cat_hidden = 0 ';
}
$sql = 'SELECT rol.*, cat.*,
(SELECT COUNT(*) AS count
FROM '.TBL_MEMBERS.' mem
WHERE mem.mem_rol_id = rol.rol_id '.$this->getMemberStatusSql().'
AND mem_leader = 0) AS num_members,
(SELECT COUNT(*) AS count
FROM '.TBL_MEMBERS.' mem
WHERE mem.mem_rol_id = rol.rol_id '.$this->getMemberStatusSql().'
AND mem_leader = 1) AS num_leader,
(SELECT COUNT(*) AS count
FROM '.TBL_MEMBERS.' mem
WHERE mem.mem_rol_id = rol.rol_id
AND mem_end < \''. DATE_NOW.'\') AS num_former
FROM '.TBL_ROLES.' rol
INNER JOIN '.TBL_CATEGORIES.' cat
ON cat_id = rol_cat_id
WHERE rol_visible = 1
AND rol_valid = '.$this->activeRole.'
AND ( cat_org_id = '. $gCurrentOrganization->getValue('org_id'). '
OR cat_org_id IS NULL )
'.$sql_conditions.'
ORDER BY cat_sequence, rol_name';
// If is there a limit then specify one
if($limit > 0)
{
$sql .= ' LIMIT '.$limit;
}
if($startElement > 0)
{
$sql .= ' OFFSET '.$startElement;
}
$listsStatement = $gDb->query($sql);
// array for results
return array(
'recordset' => $listsStatement->fetchAll(),
'numResults' => $listsStatement->rowCount(),
'limit' => $limit,
'totalCount' => $this->getDataSetCount(),
'parameter' => $this->getParameters()
);
}
/**
* Function to get total number of lists limited by current conditions.
* @return int Number of lists.
*/
public function getDataSetCount()
{
global $gCurrentOrganization, $gValidLogin, $gDb;
// assemble conditions
$sql_conditions = $this->getCategorySql().$this->getVisibleRolesSql();
// provoke empty result for not logged in users
if(!$gValidLogin)
{
$sql_conditions = ' AND cat_hidden = 0 ';
}
$sql = 'SELECT COUNT(*) AS count
FROM '.TBL_ROLES.' rol, '.TBL_CATEGORIES.' cat
WHERE rol_valid = '.$this->activeRole.'
AND rol_visible = 1
AND rol_cat_id = cat_id
AND ( cat_org_id = '. $gCurrentOrganization->getValue('org_id'). '
OR cat_org_id IS NULL )
'.$sql_conditions;
$pdoStatement = $gDb->query($sql);
return (int) $pdoStatement->fetchColumn();
}
/**
* Function to get list configurations accessible by current user
* @return array with accessible list configurations
*/
public function getListConfigurations()
{
global $gCurrentOrganization, $gCurrentUser, $gDb;
$sql = 'SELECT lst_id, lst_name, lst_global
FROM '.TBL_LISTS.'
WHERE lst_org_id = '. $gCurrentOrganization->getValue('org_id'). '
AND ( lst_usr_id = '. $gCurrentUser->getValue('usr_id'). '
OR lst_global = 1)
AND lst_name IS NOT NULL
ORDER BY lst_global ASC, lst_name ASC';
$pdoStatement = $gDb->query($sql);
$configurations = array();
while($row = $pdoStatement->fetch())
{
$configurations[] = array($row['lst_id'], $row['lst_name'], $row['lst_global']);
}
return $configurations;
}
/**
* Sets the status of role members to be shown
* @param string $status active(default), inactive, both
*/
public function setMemberStatus($status = 'active')
{
switch ($status)
{
case 'inactive':
$this->memberStatus = 'inactive';
break;
case 'both':
$this->memberStatus = 'both';
break;
case 'active':
default:
$this->memberStatus = 'active';
break;
}
}
}