1<?php 2/** 3 * @package tikiwiki 4 */ 5// (c) Copyright by authors of the Tiki Wiki CMS Groupware Project 6// 7// All Rights Reserved. See copyright.txt for details and a complete list of authors. 8// Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details. 9// $Id$ 10 11require_once('tiki-setup.php'); 12$access->check_feature('feature_invite'); 13$access->check_permission('tiki_p_invite'); 14 15/** 16 * @param int $offset 17 * @param $max 18 * @param null $inviter 19 * @param null $status 20 * @param null $nostatus 21 * @param string $sort_mode 22 * @return array 23 */ 24function list_inviteds($offset = 0, $max = -1, $inviter = null, $status = null, $nostatus = null, $sort_mode = 'ts_desc') 25{ 26 global $tikilib; 27 $bindvars = []; 28 if (! empty($inviter)) { 29 $where[] = 'invite.`inviter` = ?'; 30 $bindvars[] = $inviter; 31 } 32 if (! empty($status)) { 33 $where[] = 'guy.`used` = ?'; 34 $bindvars[] = $status; 35 } 36 if (! empty($nostatus)) { 37 $where[] = 'guy.`used` != ?'; 38 $bindvars[] = $nostatus; 39 } 40 if (empty($where)) { 41 $where[] = '1=1'; 42 } 43 $query = ' FROM `tiki_invited` guy LEFT JOIN `tiki_invite` invite ON (guy.`id_invite` = invite.`id`) where ' . implode(' AND ', $where); 44 $query_cant = "SELECT count(*) $query"; 45 $query = "SELECT guy.*, invite.* $query ORDER BY " . $tikilib->convertSortMode($sort_mode); // convertSortMode($sort_mode); 46 $result = $tikilib->query($query, $bindvars, $max, $offset); 47 $cant = $tikilib->getOne($query_cant, $bindvars); 48 $ret = []; 49 while ($res = $result->fetchRow()) { 50 $ret[] = $res; 51 } 52 return ['cant' => $cant, 'data' => $ret]; 53} 54 55$auto_query_args = ['max', 'sort_mode', 'offset', 'inviter', 'only_pending', 'only_success']; 56if (! isset($_REQUEST['offset'])) { 57 $_REQUEST['offset'] = 0; 58} 59if (! isset($_REQUEST['maxRecords'])) { 60 $_REQUEST['maxRecords'] = $prefs['maxRecords']; 61} 62if (empty($_REQUEST['sort_mode'])) { 63 $_REQUEST['sort_mode'] = 'ts_desc'; 64} 65if ($tiki_p_admin == 'y') { 66 if (! empty($_REQUEST['inviter'])) { 67 $inviter = $_REQUEST['inviter']; 68 $smarty->assign_by_ref('inviter', $_REQUEST['inviter']); 69 } else { 70 $inviter = null; 71 } 72} else { 73 $inviter = $user; 74} 75$status = $nostatus = null; 76if (! empty($_REQUEST['only_pending']) && $_REQUEST['only_pending'] == 'on') { 77 $status = 'no'; 78 $smarty->assign('only_pending', 'y'); 79} elseif (! empty($_REQUEST['only_success'])) { 80 $nostatus = 'no'; 81 $smarty->assign('only_success', 'y'); 82} 83$inviteds = list_inviteds($_REQUEST['offset'], $_REQUEST['maxRecords'], $inviter, $status, $nostatus, $_REQUEST['sort_mode']); 84$smarty->assign_by_ref('inviteds', $inviteds['data']); 85$smarty->assign_by_ref('offset', $_REQUEST['offset']); 86$smarty->assign_by_ref('max', $_REQUEST['maxRecords']); 87$smarty->assign_by_ref('cant', $inviteds['cant']); 88$smarty->assign('mid', 'tiki-list_invite.tpl'); 89$smarty->display('tiki.tpl'); 90