function getColumnList($columns, $cid) { static $list = array(); if (!$cid) { return $list; } $thisColumn = $columns[$cid]; array_unshift($list, $thisColumn); $parentColumnId = $thisColumn['parent_id']; return getColumnList($columns, $parentColumnId); }
function registeredUsersList($type, $act, $allfields, $userInfo = NULL) { global $urlRequestRoot, $cmsFolder, $moduleFolder, $templateFolder, $sourceFolder; require_once "{$sourceFolder}/{$moduleFolder}/form/viewregistrants.php"; $extraColumns = getColumnList(0, false, false, false, false, false); $xcolumnIds = array(); $xcolumnNames = array(); $xcolumnFieldVars = array(); foreach ($extraColumns as $columnid => $colname) { $xcolumnIds[] = $columnid; $xcolumnNames[] = $colname; $xcolumnFieldVars[] = 'user' . ucfirst($colname); ${'user' . ucfirst($colname)} = array(); } if ($userInfo == NULL) { getAllUsersInfo($userId, $userName, $userEmail, $userFullName, $userPassword, $userLastLogin, $userRegDate, $userActivated, $userLoginMethod); } else { $userId = $userInfo['user_id']; $userName = $userInfo['user_name']; $userEmail = $userInfo['user_email']; $userFullName = $userInfo['user_fullname']; $userPassword = $userInfo['user_password']; $userLastLogin = $userInfo['user_lastlogin']; $userRegDate = $userInfo['user_regdate']; $userActivated = $userInfo['user_activated']; $userLoginMethod = $userInfo['user_loginmethod']; } foreach ($userId as $userid) { $xinfo = generateFormDataRow(0, $userid, $xcolumnIds); foreach ($xinfo as $j => $info) { ${$xcolumnFieldVars[$j]}[] = $info; } } $userfieldprettynames = array_merge(array("User ID", "Username", "Email", "Full Name", "Password", "Registration", "Last Login", "Activated", "Login Method"), array_map('ucfirst', $xcolumnNames)); function replace10byYesNo(&$value, $key) { if ($value == '1') { $value = "Yes"; } else { if ($value == '0') { $value = "No"; } } } array_walk($userActivated, 'replace10byYesNo'); $userlisttdids = array_merge(array("user_id", "user_name", "user_email", "user_fullname", "user_password", "user_regdate", "user_lastlogin", "user_activated", "user_loginmethod"), $xcolumnIds); $userfieldvars = array_merge(array("userId", "userName", "userEmail", "userFullName", "userPassword", "userRegDate", "userLastLogin", "userActivated", "userLoginMethod"), $xcolumnFieldVars); $userlist = ""; $columns = count($userfieldvars); if ($act == "edit") { $userlist .= "<form name='user_edit_form' method='POST' action='./+admin&subaction=useradmin&userid=' >\n"; $userlist .= "<input type='hidden' name='editusertype' value='{$type}' />"; $columns += 3; } $userlist .= smarttable::render(array('userstable'), null); global $STARTSCRIPTS; $STARTSCRIPTS .= "initSmartTable();"; $userlist .= <<<USERLIST \t \t<script language="javascript"> \tfunction checkDelete(butt,userDel,userId) \t{ \t\tif(confirm('Are you sure you want to delete '+userDel+' (User ID='+userId+')?')) \t\t{ \t\t\tbutt.form.action+=userId; \t\t} \t\telse return false; \t} \tfunction checkDeleteAll(butt) { \t\tif(!confirm('Are you sure you want to delete all selected users?')) { \t\t\treturn false; \t\t} \t\tbutt.form.action+='-1'; \t\treturn true; \t} \t</script> \t<a name='userlist'></a> USERLIST; global $ICONS_SRC; $userlisttable = ""; if ($act == "edit") { $userlisttable = <<<TABLE \t<input title='Activate Selected Users' type='image' src='{$ICONS_SRC['Activate']['small']}' onclick=\\"this.form.action+='-1'\\" name='user_selected_activate' value='Activate'> \t<input title='Deactivate Selected Users' type='image' src='{$ICONS_SRC['Deactivate']['small']}' onclick=\\"this.form.action+='-1'\\" name='user_selected_deactivate' value='Deactivate'> \t<input title='Delete Selected Users' type='image' src='{$ICONS_SRC['Delete']['small']}' onclick=\\"return checkDeleteAll(this)\\" name='user_selected_delete' value='Delete'> TABLE; } $userlisttable .= <<<TABLE \t<table class="userlisttable display" border="1" id='userstable'> \t<thead> \t<tr><th colspan="{$columns}">Users Registered on the Website</th></tr> \t<tr> TABLE; $defCols = getTableFieldsName('users'); $usertablefields = array_merge($defCols, $xcolumnIds); $displayfieldsindex = array(); $c = 0; for ($i = 0; $i < count($usertablefields); $i++) { if (isset($_POST[$usertablefields[$i] . '_sel']) || $allfields) { $userlisttable .= "<th>" . $userfieldprettynames[$i]; if ($act == "edit") { $userlist .= "<input type='hidden' name='{$usertablefields[$i]}_sel' value='checked'/>"; } $userlisttable .= "</th>"; $displayfieldsindex[$c++] = $i; } } $userlist .= "<input type='hidden' name='not_first_time' />"; if ($act == "edit") { $userlisttable .= "<th>Actions</th>"; } $userlisttable .= "</tr></thead><tbody>"; $rowclass = "oddrow"; $flag = false; $usercount = 0; for ($i = 0; $i < count($userId); $i++) { if ($type == "activated" && $userActivated[$i] == "No") { continue; } if ($type == "nonactivated" && $userActivated[$i] == "Yes") { continue; } $flag = true; $userlisttable .= "<tr class='{$rowclass}'>"; for ($j = 0; $j < count($displayfieldsindex); $j++) { $userlisttable .= "<td class='{$userlisttdids[$j]}'>" . ${$userfieldvars[$displayfieldsindex[$j]]}[$i] . "</td>"; } if ($act == "edit") { $userlisttable .= "<td id='user_editactions'>"; $userlisttable .= "<input type='checkbox' name='selected_{$userId[$i]}' />"; if ($userActivated[$i] == "No") { $userlisttable .= "<input title='Activate User' type='image' src='{$ICONS_SRC['Activate']['small']}' onclick=\"this.form.action+='{$userId[$i]}'\" name='user_activate' value='Activate'>\n"; } else { $userlisttable .= "<input title='Deactivate User' type='image' src='{$ICONS_SRC['Deactivate']['small']}' onclick=\"this.form.action+='{$userId[$i]}'\" name='user_deactivate' value='Deactivate'>\n"; } $userlisttable .= "<input title='Edit User' type='image' src='{$ICONS_SRC['Edit']['small']}' onclick=\"this.form.action+='{$userId[$i]}'\" name='user_info' value='Edit'>\n"; $userlisttable .= "<input title='Delete User' type='image' src='{$ICONS_SRC['Delete']['small']}' onclick=\"return checkDelete(this,'" . $userName[$i] . "','" . $userId[$i] . "')\" name='user_delete' value='Delete'>\n"; $userlisttable .= "</td>"; } $userlisttable .= "</tr>"; $rowclass = $rowclass == "evenrow" ? "oddrow" : "evenrow"; $usercount++; } $userlisttable .= "</tbody></table>"; ///If users wants to download as excel sheet if (isset($_POST['save_reg_users_excel']) || isset($_POST['save_activated_users_excel']) || isset($_POST['save_nonactivated_users_excel'])) { header("Pragma: public"); header("Expires: 0"); header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); header("Cache-Control: private", false); header("Content-Type: application/vnd.ms-excel"); header("Content-Disposition: attachment; filename=\"users.xls\";"); header("Content-Transfer-Encoding: binary"); echo $userlisttable; exit(1); } if ($act == "edit") { $userlist .= $userlisttable . "</form>"; } else { $userlist .= $userlisttable; } return $flag ? $userlist : "No Users Found!"; }
function getProfileRegistrantsList($showEditButtons = false) { global $urlRequestRoot, $cmsFolder, $moduleFolder, $templateFolder, $sourceFolder; require_once "{$sourceFolder}/{$moduleFolder}/form/viewregistrants.php"; $sortField = 'useremail'; $sortOrder = 'asc'; if (isset($_GET['sortfield'])) { $sortField = escape($_GET['sortfield']); } if (isset($_GET['sortorder']) && ($_GET['sortorder'] == 'asc' || $_GET['sortorder'] == 'desc')) { $sortOrder = escape($_GET['sortorder']); } $action = './+admin&subaction=' . escape($_GET['subaction']); $columnList['useremail'] = 'User Email'; $columnList['username'] = '******'; $columnList['userfullname'] = 'User Full Name'; $columnList['registrationdate'] = 'Registration Date'; $columnList['lastupdated'] = 'Last Updated'; $columnList = array_merge($columnList, getColumnList(0, false, false, false, false)); $normalImage = "<img alt=\"Sort by this field\" height=\"12\" width=\"12\" style=\"padding:0px\" src=\"{$urlRequestRoot}/{$cmsFolder}/{$templateFolder}/common/icons/16x16/actions/view-refresh.png\" />"; $orderedImage = "<img alt=\"Sort by this field\" height=\"12\" width=\"12\" style=\"padding:0px\" src=\"{$urlRequestRoot}/{$cmsFolder}/{$templateFolder}/common/icons/16x16/actions/go-" . ($sortOrder == 'asc' ? 'up' : 'down') . ".png\" />"; $tableCaptions = "<tr>\n<th nowrap=\"nowrap\">S. No.</th>\n"; if ($showEditButtons) { $tableCaptions .= '<th nowrap="nowrap">Edit</th><th nowrap="nowrap">Delete</th>'; } foreach ($columnList as $columnName => $columnTitle) { $tableCaptions .= "<th nowrap=\"nowrap\">{$columnTitle}<a href=\"{$action}&sortfield={$columnName}"; if ($sortField == $columnName) { $tableCaptions .= '&sortorder=' . ($sortOrder == 'asc' ? 'desc' : 'asc') . '">' . $orderedImage . '</a>'; } else { $tableCaptions .= '">' . $normalImage . '</a>'; } $tableCaptions .= "</th>\n"; $columnNames[] = $columnName; } $tableCaptions .= "</tr>\n"; $userIds = getDistinctRegistrants(0, $sortField, $sortOrder); $userCount = count($userIds); $editImage = "<img style=\"padding:0px\" src=\"{$urlRequestRoot}/{$cmsFolder}/{$templateFolder}/common/icons/16x16/apps/accessories-text-editor.png\" alt=\"Edit\" />"; $deleteImage = "<img style=\"padding:0px\" src=\"{$urlRequestRoot}/{$cmsFolder}/{$templateFolder}/common/icons/16x16/actions/edit-delete.png\" alt=\"Delete\" />"; $tableBody = ''; for ($i = 0; $i < $userCount; $i++) { $tableBody .= '<tr><td>' . ($i + 1) . '</td>'; if ($showEditButtons) { $tableBody .= '<td align="center"><a href="./+admin&subaction=editsiteregistrants&subsubaction=editregistrant&useremail=' . getUserEmail($userIds[$i]) . '" />' . $editImage . '</a></td>'; $tableBody .= '<td align="center"><a href="./+admin&subaction=editsiteregistrants&subsubaction=deleteregistrant&useremail=' . getUserEmail($userIds[$i]) . '" />' . $deleteImage . '</a></td>'; } $tableBody .= '<td>' . join(generateFormDataRow(0, $userIds[$i], $columnNames), '</td><td>') . "</td></tr>\n"; } return '<br /><br /><br /><table border="1">' . $tableCaptions . $tableBody . '</table>'; }
/** * @uses generateFormDataRow($moduleCompId,$userId) * @uses getFormElementInfo($moduleCompId) (once it is made in formelementdescclass.php) * * @param $rowSortOrder "asc" or "desc" * @param $rowSortField "registrationdate" or "lastupdated" or "useremail" or "userfullname" or "elementid_".$i * @param $showEditButtons Whether to show edit and delete buttons or not: helps with editregistrants */ function generateFormDataTable($moduleComponentId, $sortField, $sortOrder, $action = 'viewregistrants') { global $sourceFolder, $templateFolder, $urlRequestRoot, $cmsFolder, $moduleFolder; $formDescQuery = 'SELECT `form_showuseremail`, `form_showuserfullname`, `form_showregistrationdate`, `form_showlastupdatedate`, `form_showuserprofiledata`,`form_heading` FROM `form_desc` ' . 'WHERE `page_modulecomponentid` = \'' . $moduleComponentId . "'"; $formDescResult = mysql_query($formDescQuery); $showUserEmail = $showUserFullName = false; $showRegistrationDate = $showLastUpdateDate = true; $showUserProfileData = false; $formName = ''; if ($formDescRow = mysql_fetch_row($formDescResult)) { $showUserEmail = $formDescRow[0] == 1; $showUserFullName = $formDescRow[1] == 1; $showRegistrationDate = $formDescRow[2] == 1; $showLastUpdateDate = $formDescRow[3] == 1; $showUserProfileData = $formDescRow[4] == 1; $formName = $formDescRow[5]; } $showEditButtons = $action == 'editregistrants'; $columnList = getColumnList($moduleComponentId, $showUserEmail, $showUserFullName, $showRegistrationDate, $showLastUpdateDate, $showUserProfileData); $columnNames = array(); /*$normalImage = "<img alt=\"Sort by this field\" height=\"12\" width=\"12\" style=\"padding:0px\" src=\"$urlRequestRoot/$cmsFolder/$templateFolder/common/icons/16x16/actions/view-refresh.png\" />"; $orderedImage = "<img alt=\"Sort by this field\" height=\"12\" width=\"12\" style=\"padding:0px\" src=\"$urlRequestRoot/$cmsFolder/$templateFolder/common/icons/16x16/actions/go-" . ($sortOrder == 'asc' ? 'up' : 'down') . ".png\" />"; $tableCaptions = "<thead><tr>\n<th nowrap=\"nowrap\" class=\"sortable-numeric\">S. No.</th>\n"; if($showEditButtons) { $tableCaptions .= '<th nowrap="nowrap">Edit</th><th nowrap="nowrap">Delete</th>'; } foreach($columnList as $columnName => $columnTitle) { $tableCaptions .= "<th nowrap=\"nowrap\" class=\"sortable-text\">$columnTitle</th>\n"; $columnNames[] = $columnName; } $tableCaptions .= "</tr></thead>\n";*/ $tableCaptions = "<thead><tr>\n<th>S. No.</th>\n"; $toggleColumns = "<fieldset><legend>Select Columns</legend><table><tr>"; $tableJqueryStuff = ""; $c = 0; $d = 0; if ($showEditButtons) { $tableCaptions .= '<th>Actions</th>'; $tableJqueryStuff = "null,"; $c++; } foreach ($columnList as $columnName => $columnTitle) { $tableCaptions .= "<th>{$columnTitle}</th>\n"; $columnNames[] = $columnName; $c = $c + 1; $checked = "checked"; if (!($columnName == "useremail" || $columnName == "registrationdate" || $columnName == "lastupdated")) { $tableJqueryStuff .= "/* {$columnTitle} */ { \"bVisible\": false },"; $checked = ""; } else { $tableJqueryStuff .= "null,"; } if ($d != 0 && $d % 5 == 0) { $toggleColumns .= "</tr><tr>"; } $d = $d + 1; $toggleColumns .= "<td><input type='checkbox' onclick='fnShowHide({$c});' {$checked} />{$columnTitle} <br/></td>"; } $tableCaptions .= "</tr></thead>\n"; $toggleColumns .= "</tr></table></fieldset>"; $userIds = getDistinctRegistrants($moduleComponentId, $sortField, $sortOrder); $userCount = count($userIds); global $ICONS; $editImage = $ICONS['Edit']['small']; $deleteImage = $ICONS['Delete']['small']; $tableBody = '<tbody>'; for ($i = 0; $i < $userCount; $i++) { $tableBody .= '<tr><td>' . ($i + 1) . '</td>'; if ($showEditButtons) { if ($userIds[$i] <= 0) { $tableBody .= '<td align="center"> </td>'; } else { $tableBody .= '<td align="center"><a title="Edit" href="./+editregistrants&subaction=edit&useremail=' . getUserEmail($userIds[$i]) . '" />' . $editImage . '</a> '; } if ($userIds[$i] <= 0) { $tableBody .= '<a style="cursor:pointer" title="Delete" onclick="return gotopage(\'./+editregistrants&subaction=delete&&useremail=' . getUserEmail($userIds[$i]) . '®istrantid=' . $userIds[$i] . '\',\'' . getUserEmail($userIds[$i]) . '\')" />' . $deleteImage . '</a></td>'; } else { $tableBody .= '<a style="cursor:pointer" title="Delete" onclick="return gotopage(\'./+editregistrants&subaction=delete&useremail=' . getUserEmail($userIds[$i]) . '\',\'' . getUserEmail($userIds[$i]) . '\')" />' . $deleteImage . '</a></td>'; } } $tableBody .= '<td>' . join(generateFormDataRow($moduleComponentId, $userIds[$i], $columnNames, $showUserProfileData), '</td><td>') . "</td></tr>\n"; } $tableBody .= "</tbody>"; $tableJqueryStuff = "/* S. No. */ null, {$tableJqueryStuff}"; $smarttable = smarttable::render(array('registrantstable'), array('registrantstable' => array('aoColumns' => "{$tableJqueryStuff}"))); global $STARTSCRIPTS; $STARTSCRIPTS .= "initSmartTable();"; $javascriptBody = <<<JAVASCRIPTBODY \t\t{$smarttable} \t\t<script> \t\t\tfunction fnShowHide( iCol ) \t\t\t{ \t\t\t\tvar bVis = oTable.fnSettings().aoColumns[iCol].bVisible; \t\t\t\toTable.fnSetColumnVis( iCol, bVis ? false : true ); \t\t\t} \t\t</script> \t\t<script language="javascript"> \t\t\tfunction gotopage(pagepath,useremail) { \t\t\t\tif(confirm("Are you sure you want to remove "+useremail+" from this form?")) \t\t\t\t\twindow.location = pagepath; \t\t\t} \t </script> JAVASCRIPTBODY; $imagesFolder = $urlRequestRoot . "/" . $cmsFolder . "/templates/common/images"; $editRegistrantsView = '<br />'; if ($action == 'editregistrants') { $editRegistrantsView .= <<<EDITREGISTRANTSVIEW \t\t\t<form name="addusertoformform" method="POST" action="./+editregistrants" style="float:left"> \t\t\t\t<script type="text/javascript" language="javascript" src="{$urlRequestRoot}/{$cmsFolder}/{$templateFolder}/common/scripts/ajaxsuggestionbox.js"> \t\t\t\t</script> \t\t\t\t<input type="text" name="useremail" id="userEmail" autocomplete="off" style="width: 256px" /> \t\t\t\t<div id="suggestionsBox" class="suggestionbox"></div> \t\t\t\t \t\t\t\t<input type="submit" name="btnAddUserToForm" value="Add User to Form" /> \t\t\t\t<script language="javascript" type="text/javascript"> \t\t\t\t<!-- \t\t\t\t\tvar userBox = new SuggestionBox(document.getElementById('userEmail'), document.getElementById('suggestionsBox'), "./+editregistrants&subaction=getsuggestions&forwhat=%pattern%"); \t\t\t\t\tuserBox.loadingImageUrl = '{$imagesFolder}/ajaxloading.gif'; \t\t\t\t--> \t\t\t\t</script> \t\t\t</form> \t\t\t<br /><br /> EDITREGISTRANTSVIEW; } //$editRegistrantsView .= $javascriptBody.'<table border="1" id="registrantstable" class="paginate-20 max-pages-5 no-arrow rowstyle-alt colstyle-alt sortable display">' . $tableCaptions . $tableBody . '</table><br />'; $editRegistrantsView .= $javascriptBody . $toggleColumns . '<table border="1" id="registrantstable" class="display">' . $tableCaptions . $tableBody . '</table><br />'; if (!$showEditButtons && isset($_POST['save_as_excel'])) { header("Pragma: public"); header("Expires: 0"); header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); header("Cache-Control: private", false); header("Content-Type: application/vnd.ms-excel"); header("Content-Disposition: attachment; filename=\"{$formName}.xls\";"); header("Content-Transfer-Encoding: binary"); echo '<table>' . $tableCaptions . $tableBody . '</table>'; exit(1); } if ($action == 'editregistrants') { $editRegistrantsView .= '<form name="emptyregistrants" method="POST" action="./+editregistrants" onsubmit="return confirm(\'Are you sure you wish to remove all registrants from this form? This will also remove the users from any groups associated with this form.\')">' . '<input type="submit" name="btnEmptyRegistrants" value="Delete All Registrants" title="Deletes all registrations to this form" />' . '</form>'; } return $editRegistrantsView; }