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

cms/modules/poll.lib.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 }
00009 
00010 class poll implements module {
00011         private $userId;
00012         private $moduleComponentId;
00013         private $action;
00014 
00015         public function getHtml($gotuid, $gotmoduleComponentId, $gotaction) 
00016         {
00017                 $this->userId = $gotuid;
00018                 $this->moduleComponentId = $gotmoduleComponentId;
00019                 $this->action = $gotaction;
00020                 if ($this->action == "view")
00021                    return $this-> actionView();
00022                 if ($this->action == "cast")
00023                    return $this-> actionCast();
00024                 if ($this->action == "manage")
00025                    return $this-> actionManage();
00026                 if ($this->action == "viewstats")
00027                    return $this-> actionViewstats();
00028         }
00029         
00030 
00031         public function actionView()
00032         {
00033                                                 
00034                         $display="<h2>Poll!</h2><br /><div align='center'>";
00035                         
00036                         $query="SELECT * FROM `poll_content` WHERE `visibility`='1' AND `page_modulecomponentid`='$this->moduleComponentId'";
00037                         $r=mysql_query($query);
00038                         $n=mysql_num_rows($r);
00039                         while($row=mysql_fetch_array($r))
00040                         {
00041                                 $m=$row['multiple_opt'];
00042                                 $p=$row['pid']; 
00043                                 $query2="SELECT * FROM `poll_users` WHERE `pid`='$p' AND `page_modulecomponentid`='$this->moduleComponentId' AND `userID`='$this->userId'";
00044                                 $r2=mysql_query($query2);
00045                                 $n2=mysql_num_rows($r2);
00046                                 if($n2==0)   
00047                                 {       
00048                                             $display.="<form name='f".$p."' method='post' action='./+cast'><table width='50%'><tr><td align='center'><b><div align='center'>".$row['ques']."</div></b></td></tr>";
00049                                             $display.="<tr><td>";
00050                                                         if($row['o1']!=NULL)
00051                                                                 if($m==0)
00052                                                                         $display.="<input type='radio' name='o' value='1' />".$row['o1']."<br />";      
00053                                                                 else    
00054                                                                         $display.="<input type='checkbox' name='c1' value='1' />".$row['o1']."<br />";
00055                                         $display.="</td></tr><tr><td>";
00056                                                         if($row['o2']!=NULL)
00057                                                                 if($m==0)
00058                                                                         $display.="<input type='radio' name='o' value='2'  />".$row['o2']."<br />";
00059                                                                 else    
00060                                                                         $display.="<input type='checkbox' name='c2' value='2'  />".$row['o2']."<br />"; 
00061                                                 $display.="</td></tr>";
00062                                                         if($row['o3']!=NULL)
00063                                                                 if($m==0)
00064                                                                         $display.="<tr><td><input type='radio' name='o' value=3  />".$row['o3']."<br /></td></tr>";             
00065                                                                 else    
00066                                                                         $display.="<tr><td><input type='checkbox' name='c3' value=1  />".$row['o3']."<br /></td></tr>";
00067                                                         if($row['o4']!=NULL)
00068                                                                 if($m==0)
00069                                                                         $display.="<tr><td><input type='radio' name='o' value=4  />".$row['o4']."<br /></td></tr>";             
00070                                                                 else    
00071                                                                         $display.="<tr><td><input type='checkbox' name='c4' value=4  />".$row['o4']."<br /></td></tr>";
00072                                                         if($row['o5']!=NULL)
00073                                                                 if($m==0)
00074                                                                         $display.="<tr><td><input type='radio' name='o' value=5  />".$row['o5']."<br /></td></tr>";             
00075                                                                 else    
00076                                                                         $display.="<tr><td><input type='checkbox' name='c5' value=5  />".$row['o5']."<br /></td></tr>";
00077                                                         if($row['o6']!=NULL)
00078                                                                 if($m==0)
00079                                                                         $display.="<tr><td><input type='radio' name='o' value=6  />".$row['o6']."<br /></td></tr>";
00080                                                                 else    
00081                                                                         $display.="<tr><td><input type='checkbox' name='c6' value=6  />".$row['o6']."<br /></td></tr>";
00082                                                 $display.="<tr><td><div align='center'>";
00083                                                 $display.="<input type='submit' value='Cast my vote!' /><input type='hidden' name='id' value='".$p."' /></div></td></tr></table></form>";
00084                                 }
00085                                 else
00086                                 {
00087                                                 $query5="SELECT * FROM `poll_log` WHERE `pid`='".$p."' AND `page_modulecomponentid`='$this->moduleComponentId'";
00088                                                 $res5=mysql_query($query5);
00089                                                 $row5=mysql_fetch_array($res5);
00090                                                 $total=$row5['o1']+$row5['o2']+$row5['o3']+$row5['o4']+$row5['o5']+$row5['o6'];
00091                                                 
00092                                                 if($row['o1']!=NULL)
00093                                                   $po1=round($row5['o1']/$total*100);
00094                                                 if($row['o2']!=NULL)
00095                                                   $po2=round($row5['o2']/$total*100);
00096                                                 if($row['o3']!=NULL)
00097                                                   $po3=round($row5['o3']/$total*100);
00098                                                 if($row['o4']!=NULL)
00099                                                   $po4=round($row5['o4']/$total*100);
00100                                                 if($row['o5']!=NULL)
00101                                                   $po5=round($row5['o5']/$total*100);
00102                                                 if($row['o6']!=NULL)
00103                                                   $po6=round($row5['o6']/$total*100);
00104                                                   
00105                                                 $display.="<table width='50%'><tr><td align='center' colspan='2'><b><div align='center'>".$row['ques'];
00106                                                 $display.="</div></b></td></tr>";                                               
00107                                                 if($row['o1']!=NULL)
00108                                                         $display.="<tr><td>".$row['o1']."</td><td width='20%'>".$po1."%</td></tr>";
00109                                                 if($row['o2']!=NULL)
00110                                                         $display.="<tr><td>".$row['o2']."</td><td>".$po2."%</td></tr>";
00111                                                 if($row['o3']!=NULL)
00112                                                         $display.="<tr><td>".$row['o3']."</td><td>".$po3."%</td></tr>";
00113                                                 if($row['o4']!=NULL)
00114                                                         $display.="<tr><td>".$row['o4']."</td><td>".$po4."%</td></tr>";
00115                                                 if($row['o5']!=NULL)
00116                                                         $display.="<tr><td>".$row['o5']."</td><td>".$po5."%</td></tr>";
00117                                                 if($row['o6']!=NULL)
00118                                                         $display.="<tr><td>".$row['o6']."</td><td>".$po6."%</td></tr>";
00119                                                 $display.="</table>";
00120                                                 
00121                                 }
00122                         }
00123                                                 $display.="</div>";
00124                                                 return $display;
00125                         
00126         }
00127 
00128         public function actionCast()
00129         {
00130                 
00131                 $user=$this->userId;
00132                 $pid=escape($_POST['id']);
00133 
00134                 $query="INSERT INTO `poll_users`(`pid`,`userID`,`page_modulecomponentid`) VALUES('$pid','$user','$this->moduleComponentId')";
00135                 mysql_query($query);
00136                 
00137                 $query2="SELECT * FROM `poll_content` WHERE `visibility`='1' AND `page_modulecomponentid`='$this->moduleComponentId' AND `pid`=".$pid;
00138                 $r1=mysql_query($query2);
00139                 $row=mysql_fetch_array($r1);
00140                 $m=$row['multiple_opt'];
00141                 
00142                 if($m==1)
00143                 {
00144                         for($i=1;$i<=6;$i++)
00145                         {
00146                                 $c="c".$i;
00147                                 $o="o".$i;
00148                                 if($_POST["$c"]>0)
00149                                         $v=1;
00150                                 else
00151                                         $v=0;
00152                                 $query1="UPDATE `poll_log` SET `$o`=`$o`+$v WHERE `pid` = $pid AND `page_modulecomponentid`=$this->moduleComponentId";
00153                                 mysql_query($query1);
00154                         }
00155                 }
00156                 if($m==0)
00157                 {
00158                         $opt=escape($_POST['o']);
00159                         $o="o".$opt;
00160                         $query1="SELECT * FROM `poll_log` WHERE `pid`='".$pid."' AND `page_modulecomponentid`='$this->moduleComponentId'";
00161                         $res1=mysql_query($query1);
00162                         $n=mysql_num_rows($res1);
00163                         $val=mysql_fetch_array($res1);
00164                         $value=$val["$o"];
00165                         $value+=1;
00166                         $query2="UPDATE `poll_log` SET `$o` = $value WHERE `pid` = $pid AND `page_modulecomponentid`=$this->moduleComponentId";
00167                         mysql_query($query2);
00168                 }
00169                 return $this->actionView();
00170         }
00171         
00172         public function actionManage()
00173         {
00174                                 $display.="<h2>Manage Polls</h2><br />";
00175                                 
00176                                 if(isset($_POST['save']))
00177                                 {
00178                                         if($_POST['q']==NULL)
00179                                                 displayerror('Enter a Valid Question');
00180                                         else if ($_POST['o1']==NULL || $_POST['o2']==NULL)
00181                                                 displayerror('Enter Atleast Two Options');
00182                                         else if($_POST['multi']==NULL)
00183                                                 displayerror('Choose `Yes` or `No` for Multiple Option ');
00184                                         else
00185                                         {       
00186                                             $q=htmlspecialchars(escape($_POST['q']));
00187                                                 $multi=escape($_POST['multi']);
00188                                                    if($multi=='y')
00189                                                       $multi=1;
00190                                                    else $multi=0;
00191                                                 $pid=escape($_POST['pid']);
00192                                                 $o1=htmlspecialchars(escape($_POST['o1']));
00193                                                 $o2=htmlspecialchars(escape($_POST['o2']));
00194                                                 $o3=htmlspecialchars(escape($_POST['o3']));
00195                                                 $o4=htmlspecialchars(escape($_POST['o4']));
00196                                                 $o5=htmlspecialchars(escape($_POST['o5']));
00197                                                 $o6=htmlspecialchars(escape($_POST['o6']));
00198                                                 displayinfo('Poll Question Updated Succesfully');
00199                                                 $query="UPDATE `poll_content` SET `ques` = '$q',`o1` = '$o1',`o2` = '$o2',`o3` = '$o3',`o4` = '$o4',`o5` = '$o5',`o6` = '$o6',`multiple_opt` = '$multi' WHERE `pid` = $pid AND `page_modulecomponentid`='$this->moduleComponentId'";
00200                                                 mysql_query($query);
00201                                         }
00202                                 return $this-> actionView();
00203                                 }
00204                                         
00205                 
00206                                 if(isset($_POST['insert']))
00207                                 {
00208                                         if($_POST['q']==NULL)
00209                                                 displayerror('Enter a Valid Question');
00210                                         else if ($_POST['o1']==NULL || $_POST['o2']==NULL)
00211                                                 displayerror('Enter Atleast Two Options');
00212                                         else if($_POST['multi']==NULL)
00213                                                 displayerror('Choose `Yes` or `No` for Multiple Option ');
00214                                         else
00215                                         {       
00216                                                 displayinfo('Poll Question Added Succesfully');
00217                                                 $query="INSERT INTO `poll_content` (`page_modulecomponentid`,`ques` ,`o1` ,`o2` ,`o3` ,`o4` ,`o5` ,`o6` ,`visibility`)
00218                                                 VALUES ('$this->moduleComponentId','".htmlspecialchars(escape($_POST['q']))."','".htmlspecialchars(escape($_POST['o1']))."','".htmlspecialchars(escape($_POST['o2']))."','".htmlspecialchars(escape($_POST['o3']))."','".htmlspecialchars(escape($_POST['o4']))."','".htmlspecialchars(escape($_POST['o5']))."','".htmlspecialchars(escape($_POST['o6']))."','1')";
00219                                                 $result=mysql_query($query);
00220                                                 
00221                                                 if($_POST['multi']=='y')
00222                                                 {
00223                                                         $query5="UPDATE `poll_content` SET `multiple_opt`='1' WHERE `ques`='".htmlspecialchars(escape($_POST['q']))."' AND `page_modulecomponentid`='$this->moduleComponentId'";
00224                                                         $result5=mysql_query($query5);
00225                                                 }
00226                                                 
00227                                                 $query0="SELECT max(`pid`) from `poll_content` WHERE `page_modulecomponentid`='$this->moduleComponentId'";
00228                                                 $result0=mysql_query($query0);
00229                                                 $row0=mysql_fetch_array($result0);
00230                                                 
00231                                                 $query1="INSERT INTO `poll_log` (`pid`,`page_modulecomponentid`) VALUES ('".$row0[0]."','$this->moduleComponentId')";
00232                                                 $result1=mysql_query($query1);
00233                         
00234                                         }
00235                                 }
00236                                 
00237                                 if(isset($_POST['disable']))
00238                                 {
00239                                         
00240                                         $pollid=escape($_POST['ques1']);
00241                                         $query3="SELECT * FROM `poll_content` WHERE `pid`= $pollid AND `page_modulecomponentid`='$this->moduleComponentId'";
00242                                         $result3=mysql_query($query3);
00243                                         $nop=mysql_num_rows($result3);
00244                                         if($nop==1)
00245                                         {
00246                                                 $query4="UPDATE `poll_content` SET `visibility`='0' WHERE `pid`= $pollid AND `page_modulecomponentid`='$this->moduleComponentId'";
00247                                                 $result4=mysql_query($query4);
00248                                         }
00249                                         displayinfo("Poll Question Disabled");
00250                         
00251                                 }
00252                                 
00253                                 if(isset($_POST['edit']))
00254                                 {
00255                                         $pollid=escape($_POST['ques0']);
00256                                         $query="SELECT * FROM `poll_content` WHERE `pid` = $pollid AND `page_modulecomponentid`='$this->moduleComponentId'";
00257                                         $row=mysql_fetch_array(mysql_query($query));
00258                                         $ques=$row['ques'];
00259                                         $o1=$row['o1'];
00260                                         $o2=$row['o2'];
00261                                         $o3=$row['o3'];
00262                                         $o4=$row['o4'];
00263                                         $o5=$row['o5'];
00264                                         $o6=$row['o6'];
00265                                         $m=$row['multiple_opt'];
00266                                         
00267                                         $display.="<table width='100%'><tr><td><h3>&nbsp;&nbsp;Edit</h3>&nbsp;&nbsp;Questions added are 'Enabled/Visible' by default <br /><br />";
00268                                         $display.="<div align='center'><form name='f5' method='POST' action='./+manage'>";
00269                                         $display.="Question:<br /><textarea rows='4' cols='20' name='q'>$ques</textarea><br /><br />";
00270                                         $display.="<br />";
00271                                         $display.="Enter the options applicable; leave blank otherwise. <br />";
00272                                         $display.="1.&nbsp;<input type='text' name='o1' value='$o1' /><br />";
00273                                         $display.="2.&nbsp;<input type='text' name='o2' value='$o2' /><br />";
00274                                         $display.="3.&nbsp;<input type='text' name='o3' value='$o3' /><br />";
00275                                         $display.="4.&nbsp;<input type='text' name='o4' value='$o4' /><br />";
00276                                         $display.="5.&nbsp;<input type='text' name='o5' value='$o5' /><br />";
00277                                         $display.="6.&nbsp;<input type='text' name='o6' value='$o6' /><br /><br />";
00278                                         $display.="Can the user choose multiple options?<br />";
00279                                         
00280                                         if($m==1)
00281                                         {
00282                                            $display.="<input type='radio' name='multi' value='y' checked> Yes &nbsp;&nbsp;&nbsp;&nbsp;";
00283                                            $display.="<input type='radio' name='multi' value='n'> No <br /><br />";
00284                                         }
00285                                         else
00286                                         {
00287                                            $display.="<input type='radio' name='multi' value='y'> Yes &nbsp;&nbsp;&nbsp;&nbsp;";
00288                                            $display.="<input type='radio' name='multi' value='n' checked> No <br /><br />";
00289                                         }
00290                                         $display.="<input type='hidden' name='pid' value='$pollid' />";
00291                                         $display.="<input type='submit' name='save' value=' Save ' /><br /><br />";
00292                                         $display.="</form></div></td></tr></table>";
00293                                 }
00294                                 
00295                                 if(isset($_POST['enable']))
00296                                 {
00297                                         
00298                                         $pollid=escape($_POST['ques2']);
00299                                         $query3="SELECT * FROM `poll_content` WHERE `pid`= $pollid AND `page_modulecomponentid`='$this->moduleComponentId'";
00300                                         $result3=mysql_query($query3);
00301                                         $nop=mysql_num_rows($result3);
00302                                         if($nop==1)
00303                                         {
00304                                                 $query4="UPDATE `poll_content` SET `visibility`='1' WHERE `pid`= $pollid AND `page_modulecomponentid`='$this->moduleComponentId'";
00305                                                 $result4=mysql_query($query4);
00306                                         }
00307                                         displayinfo("Poll Question Enabled");
00308                                 }
00309 
00310                                 if(isset($_POST['delete']))
00311                                 {
00312                                         
00313                                         $pollid=escape($_POST['ques3']);
00314                                         $query4="DELETE FROM `poll_log` WHERE `pid`=$pollid";
00315                                         $result4=mysql_query($query4);
00316                                         $query5="DELETE FROM `poll_content` WHERE `pid`=$pollid";
00317                                         $result5=mysql_query($query5);
00318                                         displayinfo("Poll Question Deleted");
00319                         
00320                                 }
00321 
00322                                 
00324                                 $display.="<table width='100%'><tr><td><h3>&nbsp;&nbsp;Add Poll Question</h3>&nbsp;&nbsp;Questions added are 'Enabled/Visible' by default <br /><br />";
00325                                 $display.="<div align='center'><form name='f1' method='POST' action='./+manage'>";
00326                                 $display.="Question:<br /><textarea rows='4' cols='20' name='q'></textarea><br /><br />";
00327                                 $display.="<br />";
00328                                 $display.="Enter the options applicable; leave blank otherwise. <br />";
00329                                 $display.="1.&nbsp;<input type='text' name='o1' /><br />";
00330                                 $display.="2.&nbsp;<input type='text' name='o2' /><br />";
00331                                 $display.="3.&nbsp;<input type='text' name='o3' /><br />";
00332                                 $display.="4.&nbsp;<input type='text' name='o4' /><br />";
00333                                 $display.="5.&nbsp;<input type='text' name='o5' /><br />";
00334                                 $display.="6.&nbsp;<input type='text' name='o6' /><br /><br />";
00335                                 $display.="Can the user choose multiple options?<br />";
00336                                 $display.="<input type='radio' name='multi' value='y'> Yes &nbsp;&nbsp;&nbsp;&nbsp;";
00337                                 $display.="<input type='radio' name='multi' value='n'> No <br /><br />";
00338                                 $display.="<input type='submit' name='insert' value='Add Poll Question' /><br /><br />";
00339                                 $display.="</form></div></td></tr></table>";
00340                                 
00342                                 $q0="SELECT * FROM `poll_content` WHERE `page_modulecomponentid`='$this->moduleComponentId'";
00343                                 $r0=mysql_query($q0);
00344                                 $display.="<table width='100%'><tr><td><h3>&nbsp;&nbsp;Edit Poll Question</h3>";
00345                                 $display.="<div align='center'><form name='f4' method='POST' action='./+manage'>";
00346                                 if(mysql_num_rows($r0)==0)
00347                                         $display.="No poll questions exist currently.";
00348                                 else
00349                                 {
00350                                         $display.="<select name='ques0'>";
00351                                         $n0=mysql_num_rows($r0);
00352                                         for($i=1;$i<=$n0;$i++)
00353                                         {
00354                                                 $row0=mysql_fetch_array($r0);
00355                                                 $display.="<option value='".$row0['pid']."'>".$row0['ques'];
00356                                         }
00357                                         $display.="</select><br /><br />";
00358                                         $display.="<input type='submit' name='edit' value=' Edit ' /><br /><br />";
00359                                 }
00360                                 $display.="</form></div></td></tr></table>";
00361                                 
00363                                 $q1="SELECT * FROM `poll_content` WHERE `visibility`='1' AND `page_modulecomponentid`='$this->moduleComponentId'";
00364                                 $r1=mysql_query($q1);
00365                                 $display.="<table width='100%'><tr><td><h3>&nbsp;&nbsp;Disable Poll Question</h3>";
00366                                 $display.="<div align='center'><form name='f2' method='POST' action='./+manage'>";
00367                                 if(mysql_num_rows($r1)==0)
00368                                         $display.="All Poll Questions are Currently Disabled!";
00369                                 else
00370                                 {
00371                                         $display.="<select name='ques1'>";
00372                                         $n1=mysql_num_rows($r1);
00373                                         for($i=1;$i<=$n1;$i++)
00374                                         {
00375                                                 $row1=mysql_fetch_array($r1);
00376                                                 $display.="<option value='".$row1['pid']."'>".$row1['ques'];
00377                                         }
00378                                         $display.="</select><br /><br />";
00379                                         $display.="<input type='submit' name='disable' value=' Disable ' /><br /><br />";
00380                                 }
00381                                 $display.="</form></div></td></tr></table>";
00382                                 
00384                                 $q2="SELECT * FROM `poll_content` WHERE `visibility`='0' AND `page_modulecomponentid`='$this->moduleComponentId'";
00385                                 $r2=mysql_query($q2);   
00386                                 $display.="<table width='100%'><tr><td><h3>&nbsp;&nbsp;Enable Poll Question</h3>";
00387                                 $display.="<div align='center'><form name='f3' method='POST' action='./+manage'>";
00388                                 if(mysql_num_rows($r2)==0)
00389                                         $display.="All Poll Questions are Currently Enabled!<br /><br />";
00390                                 else
00391                                 {
00392                                         $display.="<select name='ques2'>";
00393                                         while($row2=mysql_fetch_array($r2))
00394                                                 $display.="<option value='".$row2['pid']."'>".$row2['ques'];
00395                                         $display.="</select><br /><br />";
00396                                         $display.="<input type='submit' name='enable' value=' Enable ' /><br /><br />";
00397                                 }
00398                                 $display.="</form></div></td></tr></table>";
00399                                 
00401                                 $q3="SELECT * FROM `poll_content` WHERE `page_modulecomponentid`='$this->moduleComponentId'";
00402                                 $r3=mysql_query($q3);
00403                                 $display.="<table width='100%'><tr><td><h3>&nbsp;&nbsp;Delete Poll Question</h3>";
00404                                 $display.="<div align='center'><form name='f3' method='POST' action='./+manage'>";
00405                                 if(mysql_num_rows($r1)==0)
00406                                         $display.="No poll questions exist currently.";
00407                                 else
00408                                 {
00409                                         $display.="<select name='ques3'>";
00410                                         $n3=mysql_num_rows($r3);
00411                                         for($i=1;$i<=$n3;$i++)
00412                                         {
00413                                                 $row3=mysql_fetch_array($r3);
00414                                                 $display.="<option value='".$row3['pid']."'>".$row3['ques'];
00415                                         }
00416                                         $display.="</select><br /><br />";
00417                                         $display.="<input type='submit' name='delete' value=' Delete ' /><br /><br />";
00418                                 }
00419                                 $display.="</form></div></td></tr></table>";
00420                                 
00421                                 return $display;
00422                                                         
00423         }
00424                 
00425         public function actionViewstats()
00426                 {
00427                 
00428                         $display="<h2>Statistics</h2><br />";
00429                         
00430                         $query="SELECT * FROM `poll_content` WHERE `visibility`='1' AND `page_modulecomponentid`='$this->moduleComponentId'";
00431                         $r=mysql_query($query);
00432                         $n=mysql_num_rows($r);
00433                         
00434                         $display.="<table width='100%'><tr><td>";
00435                         $display.="<h3>Currently Enabled Polls</h3>";
00436                         if($n==0)
00437                                 $display.="There Exist no Enabled Poll Questions Currently.";
00438                         else
00439                         while($row=mysql_fetch_array($r))
00440                                 {
00441                                                 $p=$row['pid'];
00442                                                 $query2="SELECT * FROM `poll_log` WHERE `pid`='".$p."' AND `page_modulecomponentid`='$this->moduleComponentId'";
00443                                                 $res2=mysql_query($query2);
00444                                                 $row2=mysql_fetch_array($res2);
00445                                                 $total=$row2['o1']+$row2['o2']+$row2['o3']+$row2['o4']+$row2['o5']+$row2['o6'];
00446                                                 
00447                                                 if($row['o1']!=NULL)
00448                                                   $po1=round($row2['o1']/$total*100);
00449                                                 if($row['o2']!=NULL)
00450                                                   $po2=round($row2['o2']/$total*100);
00451                                                 if($row['o3']!=NULL)
00452                                                   $po3=round($row2['o3']/$total*100);
00453                                                 if($row['o4']!=NULL)
00454                                                   $po4=round($row2['o4']/$total*100);
00455                                                 if($row['o5']!=NULL)
00456                                                   $po5=round($row2['o5']/$total*100);
00457                                                 if($row['o6']!=NULL)
00458                                                   $po6=round($row2['o6']/$total*100);
00459                                                   
00460                                                 $display.="<div align='center'><table width='50%'><tr><td align='center' colspan='2'><b><div align='center'>".$row['ques'];
00461                                                 $display.="</div></b></td></tr>";       
00462                                                 if($row['o1']!=NULL)
00463                                                         $display.="<tr><td>".$row['o1']."</td><td width='20%'>".$po1."%</td></tr>";
00464                                                 if($row['o2']!=NULL)
00465                                                         $display.="<tr><td>".$row['o2']."</td><td>".$po2."%</td></tr>";
00466                                                 if($row['o3']!=NULL)
00467                                                         $display.="<tr><td>".$row['o3']."</td><td>".$po3."%</td></tr>";
00468                                                 if($row['o4']!=NULL)
00469                                                         $display.="<tr><td>".$row['o4']."</td><td>".$po4."%</td></tr>";
00470                                                 if($row['o5']!=NULL)
00471                                                         $display.="<tr><td>".$row['o5']."</td><td>".$po5."%</td></tr>";
00472                                                 if($row['o6']!=NULL)
00473                                                         $display.="<tr><td>".$row['o6']."</td><td>".$po6."%</td></tr>";
00474                                                 $display.="</table></div>";
00475                                                 
00476                                 }
00477                         $display.="</td></tr></table>";
00478                         
00479                         $query="SELECT * FROM `poll_content` WHERE `visibility`='0' AND `page_modulecomponentid`='$this->moduleComponentId'";
00480                         $r=mysql_query($query);
00481                         $n=mysql_num_rows($r);
00482                         
00483                         $display.="<table width='100%'><tr><td>";
00484                         $display.="<h3>Currently Disabled Polls</h3>";
00485                         if($n==0)
00486                                 $display.="There Exist no Disabled Poll Questions Currently.";
00487                         else
00488                         while($row=mysql_fetch_array($r))
00489                                 {
00490                                                 $p=$row['pid'];
00491                                                 $query2="SELECT * FROM `poll_log` WHERE `pid`='".$p."' AND `page_modulecomponentid`='$this->moduleComponentId'";
00492                                                 $res2=mysql_query($query2);
00493                                                 $row2=mysql_fetch_array($res2);
00494                                                 $total=$row2['o1']+$row2['o2']+$row2['o3']+$row2['o4']+$row2['o5']+$row2['o6'];
00495                                                 
00496                                                 if($row['o1']!=NULL)
00497                                                   $po1=round($row2['o1']/$total*100);
00498                                                 if($row['o2']!=NULL)
00499                                                   $po2=round($row2['o2']/$total*100);
00500                                                 if($row['o3']!=NULL)
00501                                                   $po3=round($row2['o3']/$total*100);
00502                                                 if($row['o4']!=NULL)
00503                                                   $po4=round($row2['o4']/$total*100);
00504                                                 if($row['o5']!=NULL)
00505                                                   $po5=round($row2['o5']/$total*100);
00506                                                 if($row['o6']!=NULL)
00507                                                   $po6=round($row2['o6']/$total*100);
00508                                                   
00509                                                 $display.="<div align='center'><table width='50%'><tr><td align='center' colspan='2'><b><div align='center'>".$row['ques'];
00510                                                 $display.="</div></b></td></tr>";       
00511                                                 if($row['o1']!=NULL)
00512                                                         $display.="<tr><td>".$row['o1']."</td><td width='20%'>".$po1."%</td></tr>";
00513                                                 if($row['o2']!=NULL)
00514                                                         $display.="<tr><td>".$row['o2']."</td><td>".$po2."%</td></tr>";
00515                                                 if($row['o3']!=NULL)
00516                                                         $display.="<tr><td>".$row['o3']."</td><td>".$po3."%</td></tr>";
00517                                                 if($row['o4']!=NULL)
00518                                                         $display.="<tr><td>".$row['o4']."</td><td>".$po4."%</td></tr>";
00519                                                 if($row['o5']!=NULL)
00520                                                         $display.="<tr><td>".$row['o5']."</td><td>".$po5."%</td></tr>";
00521                                                 if($row['o6']!=NULL)
00522                                                         $display.="<tr><td>".$row['o6']."</td><td>".$po6."%</td></tr>";
00523                                                 $display.="</table></div>";
00524                                                 
00525                                 }
00526                         $display.="</td></tr></table>";
00527                         
00528                         
00529                         $display.="</td></tr></table>";
00530                         return $display;
00531                 }
00532         
00533         public function createModule(&$moduleComponentId) {
00534         
00535                 $query = "SELECT MAX(page_modulecomponentid) as MAX FROM `poll_content` ";
00536                 $result = mysql_query($query) or die(mysql_error());
00537                 $row = mysql_fetch_assoc($result) or die(mysql_error());
00538                 $compId = $row['MAX'] + 1;
00539                 $moduleComponentId = $compId;
00540         }
00541 
00542         public function deleteModule($moduleComponentId) {
00543 
00544                 $query = "DELETE FROM `poll_content` WHERE `page_modulecomponentid`=$moduleComponentId";
00545                 $result = mysql_query($query);
00546                 
00547                 if ((mysql_affected_rows()) >= 1)
00548                 {
00549                         $query = "DELETE FROM `poll_log` WHERE `page_modulecomponentid`=$moduleComponentId";
00550                         $result = mysql_query($query);
00551                         $query = "DELETE FROM `poll_users` WHERE `page_modulecomponentid`=$moduleComponentId";
00552                         $result = mysql_query($query);
00553                         return true;
00554                 }
00555                 else
00556                         return false;
00557         }
00558         
00559         public function copyModule($moduleComponentId) {
00560 
00561                 $query = "SELECT * FROM `poll_content` WHERE `page_modulecomponentid`=$moduleComponentId";
00562                 $result = mysql_query($query);
00563                 
00564                 $query2 = "SELECT MAX(page_modulecomponentid) as MAX FROM `poll_content` ";
00565                 $result2 = mysql_query($query2) or displayerror(mysql_error());
00566                 $row2 = mysql_fetch_assoc($result2);
00567                 $compId = $row2['MAX'] + 1;
00568 
00569                 while($content = mysql_fetch_assoc($result))
00570                 {
00571                    $ques=mysql_escape_string($content['ques']);
00572                    $o1=mysql_escape_string($content['o1']);
00573                    $o2=mysql_escape_string($content['o2']);
00574                    $o3=mysql_escape_string($content['o3']);
00575                    $o4=mysql_escape_string($content['o4']);
00576                    $o5=mysql_escape_string($content['o5']);
00577                    $o6=mysql_escape_string($content['o6']);
00578                    $mo=mysql_escape_string($content['multiple_opt']);
00579                    $v=mysql_escape_string($content['visibility']);
00580                    
00581                    $query = "INSERT INTO `poll_content` (`page_modulecomponentid` ,`ques`,`o1`,`o2`,`o3`,`o4`,`o5`,`o6`,`multiple_opt`,`visibility`)
00582                              VALUES ('$compId', '$ques','$o1','$o2','$o3','$o4','$o5','$o6','$mo','$v')";
00583                    mysql_query($query) or die(mysql_error());
00584                    
00585                    if(mysql_affected_rows())
00586                    {
00587                                 $query3 = "SELECT MAX(pid) as MAXP FROM `poll_content` ";
00588                                 $result3 = mysql_query($query3) or die(mysql_error());
00589                                 $row3 = mysql_fetch_assoc($result3);
00590                                 $pid = $row3['MAXP'];
00591                                 
00592                                 $query4 = "INSERT INTO `poll_log` (`pid`,`page_modulecomponentid`) VALUES ('$pid','$compId')";
00593                                 $result4 = mysql_query($query4) or die(mysql_error());
00594                    }
00595                    
00596             }
00597                 return $compId;
00598         }
00599 }
00600 ?>

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