• Main Page
  • Related Pages
  • Namespaces
  • Data Structures
  • Files
  • Examples
  • File List
  • Globals

cms/modules/form/viewregistrants.php

Go to the documentation of this file.
00001 <?php
00002 if(!defined('__PRAGYAN_CMS'))
00003 { 
00004         header($_SERVER['SERVER_PROTOCOL'].' 403 Forbidden');
00005         echo "<h1>403 Forbidden<h1><h4>You are not authorized to access the page.</h4>";
00006         echo '<hr/>'.$_SERVER['SERVER_SIGNATURE'];
00007         exit(1);
00008 }
00034 function getLastUpdateDate($moduleComponentId, $userId) {
00035         $query = 'SELECT `form_lastupdated` FROM `form_regdata` WHERE `page_modulecomponentid` = ' . $moduleComponentId . ' AND `user_id` = ' . $userId;
00036         $result = mysql_query($query);
00037         $row = mysql_fetch_row($result);
00038         return $row[0];
00039 }
00040 
00041 function getRegistrationDate($moduleComponentId, $userId) {
00042         $query = 'SELECT `form_firstupdated` FROM `form_regdata` WHERE `page_modulecomponentid` = ' . $moduleComponentId . ' AND `user_id` = ' . $userId;
00043         $result = mysql_query($query);
00044         $row = mysql_fetch_row($result);
00045         return $row[0];
00046 }
00047 
00048 function generateFormDataRow($moduleCompId, $userId, $columnList, $showProfileData = false) {
00049         $display = array();
00050         $elementRow = array();
00051 
00052         $elementDataQuery = 'SELECT `form_elementdata`, `form_elementdesc`.`form_elementid`, `form_elementdesc`.`form_elementtype` FROM `form_elementdesc`, `form_elementdata` WHERE ' .
00053                                         "`form_elementdata`.`page_modulecomponentid` = $moduleCompId AND `user_id` = $userId AND " .
00054                                         '`form_elementdata`.`page_modulecomponentid` = `form_elementdesc`.`page_modulecomponentid` AND ' .
00055                                         '`form_elementdata`.`form_elementid` = `form_elementdesc`.`form_elementid` ' .
00056                                         'ORDER BY `form_elementrank` ASC';
00057         $elementDataResult = mysql_query($elementDataQuery) or die($elementDataQuery . ' ' . mysql_error());
00058         while($elementDataRow = mysql_fetch_row($elementDataResult)) {
00059                 $elementRow['elementid_' . $elementDataRow[1]] = $elementDataRow[0];
00060                 if($elementDataRow[2] == 'file') {
00061                         $elementRow['elementid_' . $elementDataRow[1]] = '<a href="./'.$elementDataRow[0].'">' . $elementDataRow[0] . '</a>';
00062                 }
00063         }
00064 
00065         if($showProfileData) {
00066                 if($userId > 0) {
00067                         $elementDataQuery = 'SELECT `form_elementdata`, `form_elementdesc`.`form_elementid`, `form_elementdesc`.`form_elementname`, `form_elementdesc`.`form_elementtype` FROM `form_elementdesc`, `form_elementdata` WHERE ' .
00068                                                 "`form_elementdata`.`page_modulecomponentid` = 0 AND `user_id` = $userId AND " .
00069                                                 "`form_elementdata`.`page_modulecomponentid` = `form_elementdesc`.`page_modulecomponentid` AND " .
00070                                                 "`form_elementdata`.`form_elementid` = `form_elementdesc`.`form_elementid` ORDER BY `form_elementrank`";
00071                         $elementDataResult = mysql_query($elementDataQuery) or die($elementDataQuery . '<br />' . mysql_error());
00072                         while($elementDataRow = mysql_fetch_assoc($elementDataResult)) {
00073                                 $elementRow['form0_' . $elementDataRow['form_elementname']] = $elementDataRow['form_elementdata'];
00074                                 if($elementDataRow['form_elementtype'] == 'file') {
00075                                         $elementRow['form0_' . $elementDataRow['form_elementname']] = '<a href="./'.$elementDataRow['form_elementdata'].'">' . $elementDataRow['form_elementdata'] . '</a>';
00076                                 }
00077                         }
00078                 }
00079                 else {
00080                         $elementDataQuery = 'SELECT `form_elementname` FROM `form_elementdesc` WHERE `page_modulecomponentid` = 0';
00081                         $elementDataResult = mysql_query($elementDataQuery);
00082                         while($elementDataRow = mysql_fetch_row($elementDataResult)) {
00083                                 $elementDataRow['form0_' . $elementDataRow['form_elementname']] = '&nbsp;';
00084                         }
00085                 }
00086         }
00087 
00088         if(in_array('useremail', $columnList)) {
00089                 $elementRow['useremail'] = getUserEmail($userId);
00090         }
00091         if(in_array('username', $columnList)) {
00092                 $elementRow['username'] = getUserName($userId);
00093         }
00094         if(in_array('userfullname', $columnList)) {
00095                 $elementRow['userfullname'] = getUserFullName($userId);
00096         }
00097         if(in_array('lastupdated', $columnList)) {
00098                 $elementRow['lastupdated'] = getLastUpdateDate($moduleCompId, $userId);
00099         }
00100         if(in_array('registrationdate', $columnList)) {
00101                 $elementRow['registrationdate'] = getRegistrationDate($moduleCompId, $userId);
00102         }
00103 
00104         $columnCount = count($columnList);
00105         for($i = 0; $i < count($columnList); $i++) {
00106                 if(isset($elementRow[$columnList[$i]])) {
00107                         $display[] = $elementRow[$columnList[$i]];
00108                 }
00109                 else {
00110                         $display[] = ' ';
00111                 }
00112         }
00113 
00114         return $display;
00115 }
00116 
00117 
00118 
00119 
00120         function getColumnList($moduleCompId, $showUserEmail, $showUserFullName, $showRegistrationDate, $showLastUpdateDate, $showUserProfileData=false) {
00121                 $columns = array();
00122                 
00123                 if($showUserEmail)
00124                         $columns['useremail'] = 'User Email';
00125                 if($showUserFullName)
00126                         $columns['userfullname'] = 'User Full Name';
00127                 if($showRegistrationDate)
00128                         $columns['registrationdate'] = 'Registration Date';
00129                 if($showLastUpdateDate)
00130                         $columns['lastupdated'] = 'Last Updated';
00131                 if($showUserProfileData) {
00132                         $profileQuery = 'SELECT `form_elementname` FROM `form_elementdesc` WHERE `page_modulecomponentid` = 0 ORDER BY `form_elementrank`';
00133                         $profileResult = mysql_query($profileQuery);
00134                         while($profileRow = mysql_fetch_row($profileResult)) {
00135                                 $columns['form0_' . $profileRow[0]] = $profileRow[0];
00136                         }
00137                 }
00138 
00139                 $columnQuery = 'SELECT `form_elementid`, `form_elementname` FROM `form_elementdesc` WHERE `page_modulecomponentid` = ' .
00140                                                                          $moduleCompId . ' ORDER BY `form_elementrank` ASC';
00141                 $columnResult = mysql_query($columnQuery);
00142 
00143                 while($columnRow = mysql_fetch_assoc($columnResult)) {
00144                         $columns['elementid_' . $columnRow['form_elementid']] = $columnRow['form_elementname'];
00145                         
00146                 }
00147 
00148                 return $columns;
00149         }
00150 
00151         function getDistinctRegistrants($moduleCompId, $rowSortField, $rowSortOrder) {
00152                 if($rowSortOrder != 'asc' && $rowSortOrder != 'desc') $rowSortOrder = 'asc';
00153                 $users = array();
00154                 $userQuery = '';
00155 
00156                 if($rowSortField == 'useremail' || $rowSortField == 'userfullname' || $rowSortField == 'username') {
00157                         $col = 'user_fullname';
00158                         if($rowSortField == 'useremail') $col = 'user_email';
00159                         elseif($rowSortField == 'username') $col = 'user_name';
00160                         $userTable = MYSQL_DATABASE_PREFIX . 'users';
00161 
00162                         $userQuery = "SELECT `form_regdata`.`user_id` FROM `$userTable`, `form_regdata` WHERE " .
00163                                         "`page_modulecomponentid` = $moduleCompId AND `$userTable`.`user_id` = `form_regdata`.`user_id` " .
00164                                         "ORDER BY `$col` $rowSortOrder";
00165 
00169                 }
00170                 elseif($rowSortField == 'registrationdate' || $rowSortField == 'lastupdated') {
00171                         $col = 'form_lastupdated';
00172                         if($rowSortField == 'registrationdate') $col = 'form_firstupdated';
00173 
00174                         $userQuery = "SELECT `user_id` FROM `form_regdata` WHERE " .
00175                                                                                 "`page_modulecomponentid` = $moduleCompId ORDER BY `$col` $rowSortOrder";
00176                 }
00177                 elseif(substr($rowSortField, 0, 6) == 'form0_') {
00179                 }
00180                 else {
00181                         $elementId = split('_', $rowSortField);
00182                         $elementId = $elementId[1];
00192                         $userQuery = "SELECT `reg`.`user_id` FROM `form_elementdesc` des LEFT JOIN (form_regdata reg LEFT JOIN form_elementdata dat ON reg.page_modulecomponentid = dat.page_modulecomponentid AND reg.user_id = dat.user_id AND reg.page_modulecomponentid = $moduleCompId) " .
00193                                         "ON des.page_modulecomponentid = dat.page_modulecomponentid AND des.form_elementid = dat.form_elementid " .
00194                                         "WHERE dat.`form_elementid` = $elementId ORDER BY dat.form_elementdata $rowSortOrder";
00195                 }
00196 
00197 
00198                 $userResult = mysql_query($userQuery) or die ($userQuery . ' ' . mysql_error());
00199                 while($userRow = mysql_fetch_row($userResult)) {
00200                         $users[] = $userRow[0];
00201                 }
00202 
00203                 return $users;
00204         }
00205 
00206 
00215 function generateFormDataTable($moduleComponentId, $sortField, $sortOrder, $action = 'viewregistrants') {
00216         global $sourceFolder, $templateFolder, $urlRequestRoot, $cmsFolder, $moduleFolder;
00217 
00218         $formDescQuery = 'SELECT `form_showuseremail`, `form_showuserfullname`, `form_showregistrationdate`, `form_showlastupdatedate`, `form_showuserprofiledata` FROM `form_desc` ' .
00219                                         'WHERE `page_modulecomponentid` = ' . $moduleComponentId;
00220         $formDescResult = mysql_query($formDescQuery);
00221         $showUserEmail = $showUserFullName = false;
00222         $showRegistrationDate = $showLastUpdateDate = true;
00223         $showUserProfileData = false;
00224 
00225         if($formDescRow = mysql_fetch_row($formDescResult)) {
00226                 $showUserEmail = $formDescRow[0] == 1;
00227                 $showUserFullName = $formDescRow[1] == 1;
00228                 $showRegistrationDate = $formDescRow[2] == 1;
00229                 $showLastUpdateDate = $formDescRow[3] == 1;
00230                 $showUserProfileData = $formDescRow[4] == 1;
00231         }
00232         $showEditButtons = $action == 'editregistrants';
00233 
00234         $columnList = getColumnList($moduleComponentId, $showUserEmail, $showUserFullName, $showRegistrationDate, $showLastUpdateDate, $showUserProfileData);
00235         $columnNames = array();
00236 
00237         /*$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\" />";
00238         $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\" />";
00239 
00240         $tableCaptions = "<thead><tr>\n<th nowrap=\"nowrap\" class=\"sortable-numeric\">S. No.</th>\n";
00241         if($showEditButtons) {
00242                 $tableCaptions .= '<th nowrap="nowrap">Edit</th><th nowrap="nowrap">Delete</th>';
00243         }
00244         foreach($columnList as $columnName => $columnTitle) {
00245                 $tableCaptions .= "<th nowrap=\"nowrap\" class=\"sortable-text\">$columnTitle</th>\n";
00246                 $columnNames[] = $columnName;
00247         }
00248         $tableCaptions .= "</tr></thead>\n";*/
00249         $tableCaptions = "<thead><tr>\n<th>S. No.</th>\n";
00250         $toggleColumns = "<fieldset><legend>Select Columns</legend><table><tr>";
00251         $tableJqueryStuff = "";
00252         $c=0;
00253         $d=0;
00254         if($showEditButtons) {
00255                 $tableCaptions .= '<th>Actions</th>';
00256                 $tableJqueryStuff = "null,";
00257                 $c++;
00258         }
00259         foreach($columnList as $columnName => $columnTitle) {
00260                 $tableCaptions .= "<th>$columnTitle</th>\n";
00261                 $columnNames[] = $columnName;
00262                 
00263                 $c=$c+1;
00264                 $checked="checked";
00265                 if(!($columnName=="useremail" || $columnName=="registrationdate" || $columnName=="lastupdated"))
00266                 {
00267                         $tableJqueryStuff.="/* $columnTitle */ { \"bVisible\": false },";
00268                         $checked="";
00269                 }
00270                 else $tableJqueryStuff.="null,";
00271                 
00272                 if($d++%5==0)
00273                  $toggleColumns.="</tr><tr>";
00274                 $toggleColumns.="<td><input type='checkbox' onclick='fnShowHide($c);' $checked />$columnTitle <br/></td>";
00275         }
00276         
00277         $tableCaptions .= "</tr></thead>\n";
00278         $toggleColumns .= "</tr></table></fieldset>";
00279         
00280         $userIds = getDistinctRegistrants($moduleComponentId, $sortField, $sortOrder);
00281         $userCount = count($userIds);
00282 
00283         global $ICONS;
00284         $editImage = $ICONS['Edit']['small'];
00285         $deleteImage = $ICONS['Delete']['small'];
00286 
00287         $tableBody = '<tbody>';
00288         for($i = 0; $i < $userCount; $i++) {
00289                 $tableBody .= '<tr><td>'.($i + 1).'</td>';
00290                 if($showEditButtons) {
00291                         if($userIds[$i] <= 0) {
00292                                 $tableBody .= '<td align="center">&nbsp;</td>';
00293                         }
00294                         else {
00295                                 $tableBody .= '<td align="center"><a title="Edit" href="./+editregistrants&subaction=edit&useremail='.getUserEmail($userIds[$i]).'" />' . $editImage . '</a>&nbsp;';
00296                         }
00297                         if($userIds[$i] <= 0) {
00298                                 $tableBody .= '<a style="cursor:pointer" title="Delete" onclick="return gotopage(\'./+editregistrants&subaction=delete&&useremail='.getUserEmail($userIds[$i]).'&registrantid='.$userIds[$i].'\',\''.getUserEmail($userIds[$i]).'\')" />' . $deleteImage . '</a></td>';
00299                         }
00300                         else {
00301                                 $tableBody .= '<a style="cursor:pointer" title="Delete" onclick="return gotopage(\'./+editregistrants&subaction=delete&useremail='.getUserEmail($userIds[$i]).'\',\''.getUserEmail($userIds[$i]).'\')" />' . $deleteImage . '</a></td>';
00302                         }
00303                 }
00304                 $tableBody .= '<td>' . join(generateFormDataRow($moduleComponentId, $userIds[$i], $columnNames, $showUserProfileData), '</td><td>') . "</td></tr>\n";
00305         }
00306         $tableBody.="</tbody>";
00307         
00308         $tableJqueryStuff = "/* S. No. */ null, $tableJqueryStuff";
00309         
00310         $smarttable = smarttable::render(array('registrantstable'),array('registrantstable'=>array('aoColumns'=>"$tableJqueryStuff")));
00311         global $STARTSCRIPTS;
00312         $STARTSCRIPTS.="initSmartTable();";
00313         $javascriptBody = <<<JAVASCRIPTBODY
00314                 $smarttable
00315                 <script>
00316                         function fnShowHide( iCol )
00317                         {
00318                                 var bVis = oTable.fnSettings().aoColumns[iCol].bVisible;
00319                                 oTable.fnSetColumnVis( iCol, bVis ? false : true );
00320                         }
00321 
00322                 </script>
00323                 <script language="javascript">
00324                         function gotopage(pagepath,useremail) {
00325                                 if(confirm("Are you sure you want to remove "+useremail+" from this form?"))
00326                                         window.location = pagepath;
00327                         }
00328             </script>
00329 JAVASCRIPTBODY;
00330         $imagesFolder=$urlRequestRoot."/".$cmsFolder."/templates/common/images";
00331         $editRegistrantsView = '<br />';
00332         if($action == 'editregistrants') {
00333                 $editRegistrantsView .= <<<EDITREGISTRANTSVIEW
00334                         <form name="addusertoformform" method="POST" action="./+editregistrants" style="float:left">
00335                                 <script type="text/javascript" language="javascript" src="$urlRequestRoot/$cmsFolder/$templateFolder/common/scripts/ajaxsuggestionbox.js">
00336                                 </script>
00337 
00338                                 <input type="text" name="useremail" id="userEmail" autocomplete="off" style="width: 256px" />
00339                                 <div id="suggestionsBox" class="suggestionbox"></div>
00340 
00341                                 
00342                                 <input type="submit" name="btnAddUserToForm" value="Add User to Form" />
00343                                 <script language="javascript" type="text/javascript">
00344                                 <!--
00345                                         var userBox = new SuggestionBox(document.getElementById('userEmail'), document.getElementById('suggestionsBox'), "./+editregistrants&subaction=getsuggestions&forwhat=%pattern%");
00346                                         userBox.loadingImageUrl = '$imagesFolder/ajaxloading.gif';
00347                                 -->
00348                                 </script>
00349                         </form>
00350                         <br /><br />
00351 EDITREGISTRANTSVIEW;
00352         }
00353         //$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 />';
00354         $editRegistrantsView .= $javascriptBody.$toggleColumns.'<table border="1" id="registrantstable" class="display">' . $tableCaptions . $tableBody . '</table><br />';
00355         if($action == 'editregistrants') {
00356                 $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.\')">' .
00357                         '<input type="submit" name="btnEmptyRegistrants" value="Delete All Registrants" title="Deletes all registrations to this form" />' .
00358                         '</form>';
00359         }
00360         return $editRegistrantsView;
00361 }
00362 
00363 

Generated on Sun Jan 2 2011 04:55:32 for Pragyan CMS by  doxygen 1.7.1