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

cms/modules/article.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 }
00015 class article implements module, fileuploadable {
00016         private $userId;
00017         private $moduleComponentId;
00018         private $action;
00019 
00020         public function getHtml($gotuid, $gotmoduleComponentId, $gotaction) {
00021         
00022                 $this->userId = $gotuid;
00023                 $this->moduleComponentId = $gotmoduleComponentId;
00024                 $this->action = $gotaction;
00025 
00026                 if ($this->action == "view")
00027                         return $this->actionView();
00028                 if ($this->action == "edit")
00029                         return $this->actionEdit();
00030         }
00031 
00035         public static function getFileAccessPermission($pageId,$moduleComponentId,$userId, $fileName) {
00036                 return getPermissions($userId, $pageId, "view");
00037         }
00038 
00039         public static function getUploadableFileProperties(&$fileTypesArray,&$maxFileSizeInBytes) {
00040                 $fileTypesArray = array('jpg','jpeg','png','doc','pdf','gif','bmp','css','js','html','xml','ods','odt','oft','pps','ppt','tex','tiff','txt','chm','mp3','mp2','wave','wav','mpg','ogg','mpeg','wmv','wma','wmf','rm','avi','gzip','gz','rar','bmp','psd','bz2','tar','zip','swf','fla','flv','eps','xcf','xls','exe','7z');
00041                 $maxFileSizeInBytes = 30*1024*1024;
00042         }
00043         
00044         function isCommentsEnabled() {
00045                 $result = mysql_fetch_array(mysql_query("SELECT `allowComments` FROM `article_content` WHERE `page_modulecomponentid` = '{$this->moduleComponentId}'"));
00046                 return $result['allowComments'];
00047         }
00048         
00049         function setCommentEnable($val) {
00050                 mysql_query("UPDATE `article_content` SET `allowComments` = $val WHERE `page_modulecomponentid` = '{$this->moduleComponentId}'");
00051         }
00052         
00053         function renderComment($id,$user,$timestamp,$comment,$delete=0) {
00054         global $ICONS;
00055         if($delete==1)
00056         {
00057                 global $urlRequestRoot,$cmsFolder,$templateFolder;
00058                 $delete  = "<a class='commentdelete' href='./+edit&delComment=$id'>{$ICONS['Delete']['large']}</a>";
00059         }
00060         else $delete="";
00061                 
00062                 $ret = <<<RET
00063 <div class="articlecomment">
00064 <span class="articlecomment_info">
00065 Posted By: $user on $timestamp
00066 </span>
00067 <br/><span class="articlecomment_content">
00068 $comment
00069 </span>
00070 $delete
00071 </div>
00072 RET;
00073                 return $ret;
00074         }
00075         
00076         function commentBox() {
00077                 global $sourceFolder;
00078                 require_once("$sourceFolder/common.lib.php");
00079                 $user = getUserName($this->userId);
00080                 $ret = <<<RET
00081 <fieldset><legend>New Comment</legend>
00082 <form method=POST action='./+view&subaction=postcomment'>
00083 <table width=100%>
00084 <tr><td>Posted By:</td><td><input type=text disabled="disabled" value="$user"></td></tr>
00085 <tr><td>Comment:</td><td><textarea name=comment rows=4 cols=50>Enter your comment here...</textarea></td>
00086 </table>
00087 <input type=submit name=btnSubmit value=Post>
00088 </form>
00089 </fieldset>
00090 RET;
00091                 return $ret;
00092         }
00093         
00094         public function actionView($text="") {
00095         
00096         if (isset($_GET['draft']) && isset ($_POST['CKEditor1'])){
00097                                 
00098                                 //$query = "UPDATE `article_draft` SET `draft_content` = '" . $_POST["CKEditor1"] . "' WHERE `page_modulecomponentid` =".$this->moduleComponentId;
00099                                 $query="SELECT MAX(draft_number) AS MAX FROM `article_draft` WHERE page_modulecomponentid =" . $this->moduleComponentId;
00100                         $result = mysql_query($query);
00101                         if(!$result) { displayerror(mysql_error() . "article.lib L:44"); return; }
00102                         if(mysql_num_rows($result))
00103                         {
00104                                 $drow = mysql_fetch_assoc($result);
00105                                 $draftId = $drow['MAX'] + 1;
00106                         }
00107                         else $draftId=1;
00108                         
00109                                 $query = "INSERT INTO `article_draft` (`page_modulecomponentid`,`draft_number`,`draft_content`,`draft_lastsaved`,`user_id`) VALUES ('".$this->moduleComponentId."','".$draftId."','".$_POST['CKEditor1']."',now(),'".$this->userId."')";
00110                                 $result = mysql_query($query) or die(mysql_error());
00111                                         if(mysql_affected_rows() < 1)
00112                                         displayerror("Unable to draft the article");
00113                                 
00114                                 }
00115                 
00116                 
00117                         $query = "SELECT article_content,article_lastupdated FROM article_content WHERE page_modulecomponentid=" . $this->moduleComponentId;
00118                         $result = mysql_query($query);
00119                         if($row = mysql_fetch_assoc($result)) {
00120                                 $text = $row['article_content'];
00121                                 $text = censor_words($text);
00122                                 global $PAGELASTUPDATED;
00123                                 $PAGELASTUPDATED = $row['article_lastupdated'];
00124                         }
00125                         else return "Article not yet created.";
00126                 
00127                 global $sourceFolder;
00128                 global $moduleFolder;
00129                 require_once($sourceFolder."/latexRender.class.php");
00130                 if (get_magic_quotes_gpc())
00131                         $text = stripslashes($text);
00132                 $render = new latexrender();
00133                 $ret = $render->transform($text);
00134                 
00135                 require_once($sourceFolder."/googleMaps.class.php");
00136                 $maps = new googlemaps();
00137                 $ret = $maps->render($ret);
00138                 
00139                 
00140                 if($this->isCommentsEnabled()) {
00141                         $comments = mysql_query("SELECT `comment_id`,`user`,`timestamp`,`comment` FROM `article_comments` WHERE `page_modulecomponentid` = '{$this->moduleComponentId}' ORDER BY `timestamp`");
00142                         if(mysql_num_rows($comments)>0)
00143                                 $ret .= "<fieldset><legend>Comments</legend>";
00144                         while($row = mysql_fetch_array($comments))
00145                                 $ret .= $this->renderComment($row['comment_id'],$row['user'],$row['timestamp'],$row['comment']);
00146                         if(mysql_num_rows($comments)>0)
00147                                 $ret .= "</fieldset>";
00148                         $ret .= $this->commentBox();
00149                 }
00150                 return $ret;
00151         }
00152         
00153         
00154         public function actionEdit() {
00155                 global $sourceFolder,$ICONS;
00156                 //require_once("$sourceFolder/diff.lib.php");
00157                 require_once($sourceFolder."/upload.lib.php");
00158                 
00159                 if (isset($_GET['deldraft']))
00160                 {
00161                 $dno = escape($_GET['dno']);
00162                 $query = "DELETE FROM `article_draft` WHERE `page_modulecomponentid`=". $this->moduleComponentId." AND `draft_number`=".$dno;
00163                 $result = mysql_query($query) or die(mysql_error());
00164                 }
00165                 
00166                 global $ICONS;
00167                 $header = <<<HEADER
00168                 <fieldset><legend><a name='topquicklinks'>Quicklinks</a></legend>
00169                 <table class='iconspanel'>
00170                 <tr>
00171                 <td><a href='#editor'><div>{$ICONS['Edit Page']['large']}<br/>Edit Page</div></a></td>
00172                 <td><a href='#files'><div>{$ICONS['Uploaded Files']['large']}<br/>Manage Uploaded Files</div></a></td>
00173                 <td><a href='#drafts'><div>{$ICONS['Drafts']['large']}<br/>Saved Drafts</div></a></td>
00174                 <td><a href='#revisions'><div>{$ICONS['Page Revisions']['large']}<br/>Page Revisions</div></a></td>
00175                 <td><a href='#comments'><div>{$ICONS['Page Comments']['large']}<br/>Page Comments</div></a></td>
00176                 </tr>
00177                 </table>
00178         
00179         
00180                 </fieldset><br/><br/>
00181 HEADER;
00182                 
00183                 submitFileUploadForm($this->moduleComponentId,"article",$this->userId,UPLOAD_SIZE_LIMIT);
00184                 if(isset($_GET['delComment']) && $this->userId == 1) {
00185                         mysql_query("DELETE FROM `article_comments` WHERE `comment_id` = '".escape($_GET['delComment'])."'");
00186                         if(mysql_affected_rows())
00187                                 displayinfo("Comment deleted!");
00188                         else
00189                                 displayerror("Error in deleting comment");
00190                 }
00191                 if (isset($_GET['preview']) && isset ($_POST['CKEditor1'])) {
00192                         return "<div id=\"preview\" class=\"warning\"><a name=\"preview\">Preview</a></div>".$this->actionView(stripslashes($_POST[CKEditor1])).$this->getCkBody(stripslashes($_POST[CKEditor1]));
00193                 }
00194                 if (isset($_GET['version'])) {
00195                         $revision = $this->getRevision($_GET['version']);
00196                         return "<div id=\"preview\" class=\"warning\"><a name=\"preview\">Previewing Revision Number ".$_GET['version']."</a></div>".$this->actionView($revision).$this->getCkBody($revision);
00197                 }
00198                 if (isset($_GET['dversion'])) {
00199                         $draft = $this->getDraft($_GET['dversion']);
00200                         displayinfo("Viewing Draft number ".$_GET['dversion']);
00201                         return $header.$this->getCkBody($draft);
00202                 }
00203 
00204                 
00205                 if (isset ($_POST['CKEditor1'])) {
00206 
00207 
00208                         /*Save the diff :-*/
00209                         $query = "SELECT article_content FROM article_content WHERE page_modulecomponentid=" . $this->moduleComponentId;
00210                         $result = mysql_query($query);
00211                         $row = mysql_fetch_assoc($result);
00212                         $diff = mysql_escape_string($this->diff($_POST['CKEditor1'],$row['article_content']));
00213                         $query="SELECT MAX(article_revision) AS MAX FROM `article_contentbak` WHERE page_modulecomponentid =" . $this->moduleComponentId;
00214                         $result = mysql_query($query);
00215                         if(!$result) { displayerror(mysql_error() . "article.lib L:44"); return; }
00216                         if(mysql_num_rows($result))
00217                         {
00218                                 $row = mysql_fetch_assoc($result);
00219                                 $revId = $row['MAX'] + 1;
00220                         }
00221                         else $revId=1;
00222 
00223 
00224                         $query = "INSERT INTO `article_contentbak` (`page_modulecomponentid` ,`article_revision` ,`article_diff`,`user_id`)
00225 VALUES ('$this->moduleComponentId', '$revId','$diff','$this->userId')";
00226                         $result = mysql_query($query);
00227                         if(!$result) { displayerror(mysql_error() . "article.lib L:44"); return; }
00228 
00229                 /*Save the diff end.*/
00230 
00231                         $query = "UPDATE `article_content` SET `article_content` = '" . $_POST["CKEditor1"] . "' WHERE `page_modulecomponentid` =$this->moduleComponentId ";
00232                         $result = mysql_query($query);
00233                         if(mysql_affected_rows() < 1)
00234                                 displayerror("Unable to update the article");
00235                         else {
00236                                 
00237                                 /* Index the page by sphider */
00238                                 $page = replaceAction(selfURI(),"edit","view");
00239                                 global $sourceFolder,$moduleFolder;
00240                                 require_once("$sourceFolder/$moduleFolder/search/admin/spider.php");
00241                                 index_url($page, 0, 0, '', 0, 0, 1);
00242                         }
00243                         return $this->actionView();
00244                 }
00245                 $fulleditpage = $this->getCkBody();
00246                 
00247                 $commentsedit = "<fieldset><legend><a name='comments'>{$ICONS['Page Comments']['small']}Comments</a></legend>";
00248                 
00249                 if($this->isCommentsEnabled()) {
00250                         $comments = mysql_query("SELECT `comment_id`,`user`,`timestamp`,`comment` FROM `article_comments` WHERE `page_modulecomponentid` = '{$this->moduleComponentId}' ORDER BY `timestamp`");
00251                         if(mysql_num_rows($comments)==0)
00252                                 $commentsedit.= "No comments have been posted !";
00253                         
00254                         
00255                         while($row = mysql_fetch_array($comments))
00256                         {
00257                                 $commentsedit .= $this->renderComment($row['comment_id'],$row['user'],$row['timestamp'],$row['comment'],1);
00258                                 
00259                         }
00260 
00261                 }
00262                 else $commentsedit .= "Comments are disabled for this page! You can allow comments from <a href='./+settings'>pagesettings</a>.";
00263                 $commentsedit .="</fieldset>";
00264                 $top="<a href='#topquicklinks'>Top</a>";
00265                 $fulleditpage .= $commentsedit.$top;
00266                 
00267                 return $header.$fulleditpage;
00268 
00269         }
00270 
00271         public function diff($new,$old)
00272         {
00273 /* diff new old > D
00274  * patch new D gives old
00275  */
00276                 /*global $sourceFolder;
00277                 global $uploadFolder;
00278 
00279 
00280                 $uploadDir = $sourceFolder."/".$uploadFolder;
00281 
00282                  if (!file_exists($uploadDir."/tmp"))
00283                  {
00284                         mkdir($uploadDir ."/tmp", 0755);
00285 
00286                  }
00287                 // $new=htmlspecialchars($new, ENT_QUOTES);
00288                 // $old=htmlspecialchars($old, ENT_QUOTES);
00289                  $fileNew = "newFile";
00290                  $fileOld="oldFile";
00291                 $fpn = fopen($uploadDir ."/tmp/".$fileNew, 'w') or die("can't open new file for writing ARTICLE L:105");
00292                 fwrite($fpn,$new);
00293                 fclose($fpn);
00294 
00295                 $fpo = fopen($uploadDir ."/tmp/".$fileOld, 'w') or die("can't open old file for writing ARTICLE L:109");
00296                 fwrite($fpo,$old);
00297                 fclose($fpo);
00298 
00299                 $cmd="diff ".$uploadDir ."/tmp/".$fileNew.' '.$uploadDir ."/tmp/".$fileOld."";
00300 
00301                 $diff = shell_exec(''.$cmd.'');
00302 
00303                 $fpo = fopen($uploadDir ."/tmp/diffGenerated", 'w') or die("can't open old file for writing ARTICLE L:109");
00304                 fwrite($fpo,$diff);
00305                 fclose($fpo);
00306                 $diff=addslashes($diff);*/
00307                 return $old;
00308         }
00309         public function patch($article,$patch) {
00310 /* patch article patch
00311  * * patch new D gives old
00312  *
00313  *  */
00314 //              $article=htmlspecialchars($article, ENT_QUOTES);
00315         /*      global $sourceFolder;
00316                 global $uploadFolder;
00317                 $patch=stripslashes($patch);
00318 
00319                 //$article=$article."\n";
00320                 $uploadDir = $sourceFolder."/".$uploadFolder;
00321 
00322                  if (!file_exists($uploadDir."/tmp"))
00323                  {
00324                         mkdir($uploadDir ."/tmp", 0755);
00325 
00326                  }
00327 
00328 
00329 
00330                 $fileNew="newFile";
00331                 $fileOld="patchFile";
00332 
00333                 $fpn = fopen($uploadDir ."/tmp/".$fileNew, 'w') or die("can't open new file for writing ARTICLE L:149");
00334                 fwrite($fpn,$article);
00335                 fclose($fpn);
00336 
00337                 $fpo = fopen($uploadDir ."/tmp/".$fileOld, 'w') or die("can't open old file for writing ARTICLE L:153");
00338                 fwrite($fpo,$patch);
00339                 fclose($fpo);
00340                 $cmd="patch ". $uploadDir ."/tmp/".$fileNew.' '.$uploadDir ."/tmp/".$fileOld."";
00341                 $p=shell_exec(''.$cmd.'');
00342                 echo$p;
00343                 $fpn = fopen($uploadDir ."/tmp/".$fileNew, 'r') or die("can't open new file for reading ARTICLE L:160");
00344                 $originalArticle=fread($fpn,filesize($uploadDir ."/tmp/".$fileNew));
00345                 fclose($fpn);
00346 //              $originalArticle=htmlspecialchars_decode($originalArticle);*/
00347 //              return $originalArticle;
00348                 return $patch;
00349         }
00350         public function getRevision($revisionNo) {
00351                 $currentquery = "SELECT article_content FROM article_content WHERE page_modulecomponentid=" . $this->moduleComponentId;
00352                 $currentresult = mysql_query($currentquery);
00353                 $currentrow = mysql_fetch_assoc($currentresult);
00354                 $revision = $currentrow['article_content'];
00355                 $diffquery = "SELECT * FROM `article_contentbak` WHERE `page_modulecomponentid`= $this->moduleComponentId AND article_revision >= '$revisionNo' ORDER BY article_revision DESC";
00356                 $diffresult = mysql_query($diffquery);
00357                 while($diffrow = mysql_fetch_assoc($diffresult)) {
00358                         $revision = $this->patch($revision,$diffrow['article_diff']);
00359                 }
00360                 return $revision;
00361         }
00362         
00363         public function getDraft($draftNo) {
00364                 $currentquery = "SELECT draft_content FROM article_draft WHERE page_modulecomponentid=" . $this->moduleComponentId;
00365                 $currentresult = mysql_query($currentquery);
00366                 $currentrow = mysql_fetch_assoc($currentresult);
00367                 $draft = $currentrow['draft_content'];
00368                 $diffquery = "SELECT * FROM `article_draft` WHERE `page_modulecomponentid`= $this->moduleComponentId AND draft_number >= '$draftNo' ORDER BY draft_number DESC";
00369                 $diffresult = mysql_query($diffquery);
00370                 while($diffrow = mysql_fetch_assoc($diffresult)) {
00371                         $draft = $this->patch($draft,$diffrow['draft_content']);
00372                 }
00373                 return $draft;
00374         }
00375         
00376         public function getCkBody($content=""){
00377                         global $sourceFolder;
00378                         global $cmsFolder;
00379                         global $moduleFolder;
00380                         global $urlRequestRoot;
00381                         global $ICONS;
00382                         require_once ("$sourceFolder/$moduleFolder/article/ckeditor/ckeditor.php");
00383                         if($content=="") {
00384                                 $query = "SELECT * FROM `article_content` WHERE `page_modulecomponentid`= $this->moduleComponentId";
00385                                 $result = mysql_query($query);
00386                                 $temp = mysql_fetch_assoc($result);
00387                                 $content = $temp['article_content'];
00388                         }
00389 
00390                         $CkForm =<<<Ck
00391                                                 <form action="./+edit" method="post">
00392                                                 <a name="editor"></a>
00393                                                 <input type="button" value="Cancel" onclick="submitarticleformCancel(this);"><input type="submit" value="Save"><input type="button" value="Preview" onclick="submitarticleformPreview(this)"><input type="button" value="Draft" onclick="submitarticleformDraft(this);">
00394                         To upload files and images, go to the <a href="#files">files section</a>.
00395 Ck;
00396                         $top ="<a href='#topquicklinks'>Top</a>";
00397                         $oCKEditor = new CKeditor();
00398                         $oCKEditor->basePath = "$urlRequestRoot/$cmsFolder/$moduleFolder/article/ckeditor/";
00399                         $oCKEditor->config['width'] = '100%';
00400                         $oCKEditor->config['height'] = '300';
00401                         $oCKEditor->returnOutput = true;
00402                         $Ckbody = $oCKEditor->editor('CKEditor1',$content);
00403 
00404                         $CkFooter =<<<Ck1
00405                                               <input type="button" value="Cancel" onclick="submitarticleformCancel(this);"><input type="submit" value="Save"><input type="button" value="Preview" onclick="submitarticleformPreview(this)"><input type="button" value="Draft" onclick="submitarticleformDraft(this);">
00406                                                          </form>
00407                                                  <script language="javascript">
00408                                                 function submitarticleformPreview(butt) {
00409                                                         butt.form.action = "./+edit&preview=yes#preview";
00410                                                         butt.form.submit();
00411                                                 }
00412                                                 function submitarticleformCancel(butt) {
00413                                                         butt.form.action="./+view";
00414                                                         butt.form.submit();
00415                                                 }
00416                                                 function submitarticleformDraft(butt) {
00417                                                         butt.form.action="./+view&draft=yes";
00418                                                         butt.form.submit();
00419                                                 }
00420                                             </script><br />
00421                                             $top
00422                                             <fieldset>
00423                                                 <legend><a name="files">{$ICONS['Uploaded Files']['small']}Uploaded Files</a></legend>
00424                                                         
00425 Ck1;
00426                 $CkFooter .= getUploadedFilePreviewDeleteForm($this->moduleComponentId,"article",'./+edit');
00427                 $CkFooter .= '<br />Upload files : <br />'.getFileUploadForm($this->moduleComponentId,"article",'./+edit',UPLOAD_SIZE_LIMIT,5).'</fieldset>';
00428 
00429                 /* Revisions available */
00430                 $revisionquery = "SELECT MAX(article_revision) AS MAX FROM `article_contentbak` where page_modulecomponentid = $this->moduleComponentId";
00431                 $revisionresult = mysql_query($revisionquery);
00432                 $revisionrow = mysql_fetch_assoc($revisionresult);
00433                 $start = $revisionrow['MAX'] - 10;
00434                 if(isset($_GET['revisionno']))
00435                         $start = escape($_GET['revisionno']);
00436                 if($start>$revisionrow['MAX']-9) $start = $revisionrow['MAX']-10;
00437                 if($start<0) $start = 0;
00438                 $count = 10;
00439                 if(isset($_GET['count']))
00440                         $count = escape($_GET['count']);
00441                 if($count>($revisionrow['MAX']-$start+1)) $count = $revisionrow['MAX']-$start+1;
00442                 $query = "SELECT article_revision,article_updatetime,user_id FROM `article_contentbak` where page_modulecomponentid = $this->moduleComponentId ORDER BY article_revision LIMIT $start,$count";
00443                 $result = mysql_query($query);
00444                 $revisionTable = "<fieldset>
00445                                                 <legend><a name='revisions'>{$ICONS['Page Revisions']['small']}Page Revisions : </a></legend>" .
00446                                                                 "<table border='1'><tr><td>Revision Number</td><td>Date Updated</td><td>User Fullname</td><td>User Email</td></tr>";
00447                 while ($row = mysql_fetch_assoc($result)) {
00448                         $revisionTable .= "<tr><td><a href=\"./+edit&version=".$row['article_revision']."#preview\">".$row['article_revision']."</a></td><td>".$row['article_updatetime']."</td><td>".getUserFullName($row['user_id'])."</td><td>".getUserEmail($row['user_id'])."</td></tr>";
00449                 }
00450                 $revisionTable .="</table>" .
00451                                 "<input type=\"button\" value=\"<<\" onclick=\"window.location='./+edit&revisionno=0'\" /> " .
00452                                 "<input type=\"button\" value=\"<\" onclick=\"window.location='./+edit&revisionno=".($start - 10)."'\" /> " .
00453                                 "<input type=\"button\" value=\">\" onclick=\"window.location='./+edit&revisionno=".($start + 10)."'\" /> " .
00454                                 "<input type=\"button\" value=\">>\" onclick=\"window.location='./+edit&revisionno=".($revisionrow['MAX']-10)."'\" /> " .
00455                                 "</fieldset>";
00456                                 
00457                         /* Drafts available */
00458                 $draftquery = "SELECT MAX(draft_number) AS MAX FROM `article_draft` where page_modulecomponentid = $this->moduleComponentId";
00459                 $draftresult = mysql_query($draftquery);
00460                 $draftrow = mysql_fetch_assoc($draftresult);
00461                 $dstart = $draftrow['MAX'] - 10;
00462                 if(isset($_GET['draftno']))
00463                         $dstart = escape($_GET['draftno']);
00464                 if($dstart>$draftrow['MAX']-9) $dstart = $draftrow['MAX']-10;
00465                 if($dstart<0) $dstart = 0;
00466                 $dcount = 10;
00467                 if(isset($_GET['dcount']))
00468                         $dcount = escape($_GET['dcount']);
00469                 if($dcount>($draftrow['MAX']-$dstart+1)) $dcount = $draftrow['MAX']-$dstart+1;
00470                 
00471                 $query = "SELECT `draft_lastsaved`,`draft_number`,`user_id` FROM `article_draft` where `page_modulecomponentid` = $this->moduleComponentId ORDER BY `draft_lastsaved` LIMIT $dstart,$dcount";
00472                 $result = mysql_query($query);
00473                 $draftTable = "<fieldset>
00474                                                 <legend><a name='drafts'>{$ICONS['Page Revisions']['small']}Drafts Saved : </a></legend>" .
00475                                                                 "<table border='1'><tr><td>Draft Number</td><td>Date Drafted</td><td>User Fullname</td><td>User Email</td><td>Delete</td></tr>";
00476                                             
00477                 while ($row = mysql_fetch_assoc($result)) {
00478                         $draftTable .= "<tr><td><a href=\"./+edit&dversion=".$row['draft_number']."#preview\">".$row['draft_number']."</a></td><td>".$row['draft_lastsaved']."</td><td>".getUserFullName($row['user_id'])."</td><td>".getUserEmail($row['user_id'])."</td><td><form action='./+edit&deldraft=yes&dno=".$row['draft_number']."' method='post'><input type='button' value='Delete' onclick='submitarticleformDeldraft(this);'></form>
00479                 <script language='javascript'>
00480                                                 function submitarticleformDeldraft(butt) {
00481                                                         if(confirm('Are you sure you want to delete this draft ? '))
00482                                                         butt.form.submit();
00483                                                 }
00484                 </script></td></tr>";
00485                 }
00486                 $draftTable .="</table>" .
00487                                 "<input type=\"button\" value=\"<<\" onclick=\"window.location='./+edit&draftnno=0'\" /> " .
00488                                 "<input type=\"button\" value=\"<\" onclick=\"window.location='./+edit&draftno=".($dstart - 10)."'\" /> " .
00489                                 "<input type=\"button\" value=\">\" onclick=\"window.location='./+edit&draftno=".($dstart + 10)."'\" /> " .
00490                                 "<input type=\"button\" value=\">>\" onclick=\"window.location='./+edit&draftno=".($draftrow['MAX']-10)."'\" /> " .
00491                                 "</fieldset>";
00492 
00493                 /* Drafts end*/ 
00494                 
00495                 
00496 
00497                 
00498                 return  $CkForm . $Ckbody . $CkFooter.$draftTable.$top.$revisionTable.$top;
00499         }
00500 
00501         public function createModule(&$moduleComponentId) {
00502                 $query = "SELECT MAX(page_modulecomponentid) as MAX FROM `article_content` ";
00503                 $result = mysql_query($query) or die(mysql_error() . "article.lib L:73");
00504                 $row = mysql_fetch_assoc($result);
00505                 $compId = $row['MAX'] + 1;
00506 
00507                 $query = "INSERT INTO `article_content` (`page_modulecomponentid` ,`article_content`, `allowComments`)VALUES ('$compId', 'Coming up Soon!!!','0')";
00508                 $result = mysql_query($query) or die(mysql_error()."article.lib L:76");
00509                 if (mysql_affected_rows()) {
00510                         $moduleComponentId = $compId;
00511                         return true;
00512                 } else
00513                         return false;
00514         }
00515         public function deleteModule($moduleComponentId) {
00516                 $query = "DELETE FROM `article_content` WHERE `page_modulecomponentid`=$moduleComponentId";
00517                 $result = mysql_query($query);
00518                 if ((mysql_affected_rows()) >= 1)
00519                 {
00520                         $query = "DELETE FROM `article_comments` WHERE `page_modulecomponentid`=$moduleComponentId";
00521                         $result = mysql_query($query);
00522                         
00523                 }
00524                 else
00525                         return false;
00526                 
00527                 /* Remove the indexing from sphider // Abhishek */
00528                 $pageId=getPageIdFromModuleComponentId("article",$moduleComponentId);
00529                 $path=getPagePath($pageId);
00530                 global $urlRequestRoot;
00531                 $delurl = "http://".$_SERVER['HTTP_HOST'].$urlRequestRoot."/home".$path;
00532                 $query="SELECT link_id FROM `links` WHERE url='$delurl'";
00533                 
00534                 $result=mysql_query($query);
00535                 if(mysql_num_rows($result)==0) return true; //Nothing to delete 
00536                 $delids="";
00537                 while($row=mysql_fetch_row($result))
00538                         $delids.=$row[0].",";
00539                 
00540                 $delids=rtrim($delids,",");
00541                 
00542                 $query="DELETE FROM `links` WHERE url='$delurl'";
00543                 
00544                 mysql_query($query);
00545                 for ($i=0;$i<=15; $i++) 
00546                 {
00547                         $char = dechex($i);
00548                         $query="DELETE FROM `link_keyword$char` WHERE link_id IN ($delids)";
00549                         
00550                         mysql_query($query) or die(mysql_error()." article.lib.php L:441");
00551                         
00552                 }
00553                 return true;
00554                 
00555 
00556         }
00557         public function copyModule($moduleComponentId) {
00558                 $query = "SELECT * FROM `article_content` WHERE `page_modulecomponentid`=$moduleComponentId";
00559                 $result = mysql_query($query);
00560                 $content = mysql_fetch_assoc($result);
00561                 
00562                 $query = "SELECT MAX(page_modulecomponentid) as MAX FROM `article_content` ";
00563                 $result = mysql_query($query) or displayerror(mysql_error() . "article.lib L:98");
00564                 $row = mysql_fetch_assoc($result);
00565                 $compId = $row['MAX'] + 1;
00566 
00567                 $query = "INSERT INTO `article_content` (`page_modulecomponentid` ,`article_content`)VALUES ('$compId', '".mysql_escape_string($content['article_content'])."')";
00568                 mysql_query($query) or displayerror(mysql_error()."article.lib L:104");
00569                 if (mysql_affected_rows()) {
00570                         return $compId;
00571                 } else
00572                         return false;
00573         }
00574 
00575 }
00576 

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