/** * ManageLists * Prints out the lists for management. This includes deleting subscribers, changing subscriber formats etc. * * @see GetPerPage * @see GetCurrentPage * @see GetSortDetails * @see GetApi * @see User_API::ListAdmin * @see List_API::GetLists * @see User_API::CanCreateList * @see SetupPaging * @see PrintDate * * @param Array $param Any parameters that needed to be passed into this function * * @return String HTML for all the Contact Lists the user has permission to see, paginated. */ private function ManageLists($param) { $user =& $param['user']; $folders = new Folders(); if ($folders->InFolderMode()) { $perpage = 'all'; $GLOBALS['Mode'] = 'Folder'; } else { $perpage = $this->GetPerPage(); $GLOBALS['Mode'] = 'List'; } $DisplayPage = $this->GetCurrentPage(); $start = 0; if ($perpage != 'all') { $start = ($DisplayPage - 1) * $perpage; } $sortinfo = $this->GetSortDetails(); $all_lists = $user->GetLists(); $check_lists = array_keys($all_lists); $listapi = $this->GetApi('Lists'); $NumberOfLists = count($check_lists); // If we're a list admin, no point checking the lists - we have access to everything. if ($user->ListAdmin()) { $check_lists = null; } $mylists = $listapi->GetLists($check_lists, $sortinfo, false, $start, $perpage); $GLOBALS['Lists_AddButton'] = ''; if ($user->CanCreateList() === true) { $GLOBALS['Lists_AddButton'] = $this->ParseTemplate('List_Create_Button', true, false); } if (!isset($GLOBALS['Message'])) { $GLOBALS['Message'] = ''; } if ($NumberOfLists == 0) { $GLOBALS['Intro'] = GetLang('ListsManage'); if ($user->CanCreateList() === true) { FlashMessage(GetLang('ListCreate'), SS_FLASH_MSG_SUCCESS); } else { FlashMessage(GetLang('ListAssign'), SS_FLASH_MSG_SUCCESS); } $GLOBALS['Message'] = GetFlashMessages(); return $this->ParseTemplate('Lists_Manage_Empty', true); } $this->SetupPaging($NumberOfLists, $DisplayPage, $perpage); $GLOBALS['FormAction'] = 'Action=ProcessPaging'; $paging = $this->ParseTemplate('Paging', true, false); if ($user->HasAccess('Lists', 'Delete')) { $GLOBALS['Option_DeleteList'] = '<option value="Delete">' . GetLang('Delete_Lists') . '</option>'; } if ($user->HasAccess('Subscribers', 'Delete')) { $GLOBALS['Option_DeleteSubscribers'] = '<option value="DeleteAllSubscribers">' . GetLang('DeleteAllSubscribers') . '</option>'; } $template = $this->ParseTemplate('Lists_Manage', true, false); $lists = array(); foreach ($mylists as $pos => $listinfo) { $GLOBALS['Name'] = htmlspecialchars($listinfo['name'], ENT_QUOTES, SENDSTUDIO_CHARSET); $GLOBALS['Created'] = $this->PrintDate($listinfo['createdate']); $GLOBALS['SubscriberCount'] = $this->FormatNumber($listinfo['subscribecount']); $GLOBALS['ListAction'] = ''; $GLOBALS['ListID'] = $listinfo['listid']; $GLOBALS['ListAction'] .= $this->ParseTemplate('Lists_Manage_ViewSubscribersLink', true); if ($user->HasAccess('Subscribers', 'Add')) { $GLOBALS['AddSubscriberListID'] = $listinfo['listid']; $GLOBALS['ListAction'] .= $this->ParseTemplate('Lists_Manage_AddSubscriberLink', true, false); } if ($listinfo['ownerid'] == $user->userid || $user->HasAccess('Lists', 'Edit', $listinfo['listid'])) { $GLOBALS['EditListID'] = $listinfo['listid']; $GLOBALS['ListAction'] .= $this->ParseTemplate('Lists_Manage_EditLink', true, false); } else { $GLOBALS['ListAction'] .= $this->DisabledItem('Edit'); } // This checks whether the user is an admin or list admin, so we don't need to. $create_list = $user->CanCreateList(); if ($create_list === true) { $GLOBALS['CopyListID'] = $listinfo['listid']; $GLOBALS['ListAction'] .= $this->ParseTemplate('Lists_Manage_Copy', true, false); } else { if ($create_list === false) { $itemtitle = 'ListCopyDisabled'; } else { $itemtitle = 'ListCopyDisabled_TooMany'; } $GLOBALS['ListAction'] .= $this->DisabledItem('Copy', $itemtitle); } if ($listinfo['ownerid'] == $user->userid || $user->HasAccess('Lists', 'Delete', $listinfo['listid'])) { $GLOBALS['DeleteListID'] = $listinfo['listid']; $GLOBALS['ListAction'] .= $this->ParseTemplate('Lists_Manage_DeleteLink', true, false); } else { $GLOBALS['ListAction'] .= $this->DisabledItem('Delete'); } $GLOBALS['List'] = $listinfo['listid']; $fullname = GetLang('N/A'); if ($listinfo['fullname'] != '') { $fullname = $listinfo['fullname']; } elseif ($listinfo['username'] != '') { $fullname = $listinfo['username']; } $GLOBALS['Fullname'] = htmlspecialchars($fullname, ENT_QUOTES, SENDSTUDIO_CHARSET); $listinfo['html'] = $this->ParseTemplate('Lists_Manage_Row', true, false); $lists[$listinfo['listid']] = $listinfo; } if ($folders->InFolderMode()) { // Organise the rows into their respective folders. $folder_type = 'list'; $folders_api = $this->GetApi('Folders'); $folder_list = $folders_api->GetFolderList($folder_type, $user->Get('userid'), $sortinfo); // Folder ID 0 is special -- it's the 'Uncategorised' or 'Orphan' folder. $folder_list[0]['name'] = GetLang('Folders_OrphanName'); // Accumulate the HTML for each folder and list. $f_html = ''; $orphan_html = ''; foreach ($folder_list as $fid=>$folder) { $l_html = ''; if (is_array($folder['items'])) { // Loop through $lists, as these will be sorted for us already. foreach ($lists as $lid=>$list) { if (in_array($lid, $folder['items'])) { $l_html .= $list['html']; } } } $GLOBALS['Items'] = $l_html; $GLOBALS['FolderID'] = $fid; $GLOBALS['FolderName'] = htmlspecialchars($folder['name']); $GLOBALS['FolderName_Encoded'] = urlencode($folder['name']); $GLOBALS['FolderType'] = $folder_type; $GLOBALS['Expanded'] = $folder['expanded']; if ($fid == 0) { if (!$folders->IsOrphanExpanded($folder_type)) { $GLOBALS['Expanded'] = 0; } $orphan_html .= $this->ParseTemplate('Folder', true, false); continue; } $f_html .= $this->ParseTemplate('Folder', true, false); } // The orphan folder should be put at the end $f_html .= $orphan_html; $template = str_replace('%%TPL_Lists_Manage_Row%%', $f_html, $template); $template = str_replace('%%TPL_Paging%%', '', $template); $template = str_replace('%%TPL_Paging_Bottom%%', '', $template); } else { // Not in folder mode, just print rows. $l_html = ''; foreach ($lists as $list) { $l_html .= $list['html']; } $template = str_replace('%%TPL_Lists_Manage_Row%%', $l_html, $template); $template = str_replace('%%TPL_Paging%%', $paging, $template); $template = str_replace('%%TPL_Paging_Bottom%%', $GLOBALS['PagingBottom'], $template); } return $template; }