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

cms/modules/book.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 }
00032 class book implements module {
00033         private $userId;
00034         private $moduleComponentId;
00035         private $action;
00036         private $pageId;
00037         
00043         public function getHtml($gotuid, $gotmoduleComponentId, $gotaction) {
00044                 $this->userId = $gotuid;
00045                 $this->moduleComponentId = $gotmoduleComponentId;
00046                 $this->action = $gotaction;
00047                 $this->pageId = getPageIdFromModuleComponentId("book",$gotmoduleComponentId);
00048                 $this->bookProps = mysql_fetch_assoc(mysql_query("SELECT * FROM `book_desc` WHERE `page_modulecomponentid` = '{$this->moduleComponentId}'"));
00049                 $page_title = mysql_fetch_row(mysql_query("SELECT `page_title` FROM `" . MYSQL_DATABASE_PREFIX . "pages` WHERE `page_id` = '{$this->pageId}'"));
00050                 $this->bookProps['page_title'] = $page_title[0];
00051                 $this->hideInMenu();
00052                 if ($this->action == "edit")
00053                         return $this->actionEdit();
00054                 return $this->actionView();
00055         }
00056         
00061         public function actionView() {
00062                 global $INFOSTRING, $WARNINGSTRING, $ERRORSTRING;
00063 
00064                 $childrenQuery = 'SELECT `page_title`, `page_id`, `page_module`, `page_modulecomponentid`, `page_name` FROM `' . MYSQL_DATABASE_PREFIX . 'pages` WHERE `page_parentid` = ' . $this->pageId . ' AND `page_id` IN (' . $this->bookProps['list'] . ') ORDER BY `page_menurank`';
00065                 $result = mysql_query($childrenQuery);
00066                 $ret = $this->tabScript();
00067                 $ret .=<<<RET
00068 <h2>{$this->bookProps['page_title']}</h2>
00069 <div class='tabEnvelope'>
00070 RET;
00071                 $navigate = $this->bookProps['initial'];
00072                 if(isset($_GET['navigate'])&&$this->isPresent($this->pageId,$_GET['navigate']))
00073                         $navigate = escape($_GET['navigate']);
00074                 $tabList = "<div id='tabList'>";
00075                 $contentList = "";
00076                 $backup_info = $INFOSTRING;
00077                 $backup_warning = $WARNINGSTRING;
00078                 $backup_error = $ERRORSTRING;
00079                 while($row = mysql_fetch_assoc($result)) {
00080                         if(getPermissions($this->userId, $row['page_id'], "view")) {
00081                                 $INFOSTRING = "";
00082                                 $WARNINGSTRING = "";
00083                                 $ERRORSTRING = "";
00084                                 $moduleType = $row['page_module'];
00085                                 $active = "";
00086                                 if($navigate == $row['page_id']||getPageModule($row['page_id'])=='book'&&$this->isPresent($row['page_id'],$navigate))
00087                                         $active = ' active';
00088                                 $tabList .= "<div class='tabElement'><a id='Content{$this->pageId}_{$row['page_id']}' href='./+view&navigate={$row['page_id']}'><span class='tabItem' id='cms-tabItem'>{$row['page_title']}</span></a></div>";
00089                                 $content = getContent($row['page_id'], "view", $this->userId, true);
00090                                 $content = preg_replace('/<a(.*)href=[\'"](.\/)+(.*)[\'"](.*)>(.*)<\/a>/i', '<a$1href="./' . $row['page_name'] . '/$3"$4>$5</a>', $content);
00091                                 $content = preg_replace('/<form(.*)action=[\'"](.\/)+(.*)[\'"](.*)>/i', '<form$1action="./' . $row['page_name'] . '/$3"$4>', $content);
00092                                 $content = preg_replace('/<img(.*)src=[\'"](.\/)+(.*)[\'"](.*)>/i', '<img$1src="./' . $row['page_name'] . '/$3"$4>', $content);
00093                                 $contentList .= "<div class='tabContent$active' id='tabContent{$this->pageId}_{$row['page_id']}'>" . $INFOSTRING . $WARNINGSTRING . $ERRORSTRING . $content . "</div>";
00094                         }
00095                 }
00096                 if( $tabList=="" ) displaywarning("No child pages are selected to display in this book.<br/> To change book settings click <a href='./+edit'>here</a> and to create child pages for this book, click <a href='./+settings#childpageform'>here</a>.");
00097                 $tabList .= "</div>";
00098                 $ret .= $tabList . $contentList . "</div>";
00099                 $INFOSTRING = $backup_info;
00100                 $WARNINGSTRING = $backup_warning;
00101                 $ERRORSTRING = $backup_error;
00102                 return $ret;
00103         }
00104         
00109         public function actionEdit() {
00110                 if(isset($_POST['page_title'])) {
00111                         $tList = "";
00112                         $hList = "";
00113                         $found = false;
00114                         foreach($_POST as $key=>$val)
00115                                 if(substr($key,0,7) == "chkPage") {
00116                                         $tList .= substr($key,7) . ",";
00117                                         if(substr($key,7) == $_POST['optInitial'])
00118                                                 $found = true;
00119                                 } elseif(substr($key,0,8) == "hidePage") {
00120                                         $hList .= substr($key,8) . ",";
00121                                 }
00122                         $tList = rtrim($tList,",");
00123                         $hList = rtrim($hList,",");
00124                         if($found) {
00125                                 $this->bookProps['page_title'] = escape($_POST['page_title']);
00126                                 $this->bookProps['initial'] = escape($_POST['optInitial']);
00127                                 $this->bookProps['list'] = $tList;
00128                                 $this->bookProps['menu_hide'] = $hList;
00129                                 $this->hideInMenu();
00130                                 $query = "UPDATE `book_desc` SET `initial` = '" . escape($_POST['optInitial']) . "', `list` = '{$tList}', `menu_hide` = '{$hList}' WHERE `page_modulecomponentid` = '{$this->moduleComponentId}'";
00131                                 mysql_query($query) or die(mysql_error() . ": book.lib.php L:131");
00132                                 $query = "UPDATE `" . MYSQL_DATABASE_PREFIX . "pages` SET `page_title` = '" . $this->bookProps['page_title'] . "' WHERE `page_id` = '{$this->pageId}'";
00133                                 mysql_query($query) or die(mysql_error() . ": book.lib.php L:133");
00134                                 displayinfo("Book Properties saved properly");
00135                         } else
00136                                 displayerror("You've choosen a hidden sub-page as default which is not possible, so the settings are not saved.");
00137                 }
00138                 $childrenQuery = 'SELECT `page_id`, `page_title`, `page_module`, `page_name`, `page_modulecomponentid` FROM `' . MYSQL_DATABASE_PREFIX . 'pages` WHERE `page_parentid` = ' . $this->pageId . ' AND `page_id` != ' . $this->pageId . ' ORDER BY `page_menurank`';
00139                 $result = mysql_query($childrenQuery);
00140                 $table = "";
00141                 $hide_list = explode(",",$this->bookProps['menu_hide']);
00142                 $show_list = explode(",",$this->bookProps['list']);
00143                 if(mysql_num_rows($result)) {
00144                         $table = "<table><thead><td>Initial</td><td>Show in Tab</td><td>Hide in Menu</td><td>Page</td></thead>";
00145                         while($row = mysql_fetch_assoc($result)) {
00146                                 $radio = "";
00147                                 if($row['page_id'] == $this->bookProps['initial'])
00148                                         $radio = "checked";
00149                                 $checkbox = "";
00150                                 $hide_checkbox = "";
00151                                 if(in_array($row['page_id'],$show_list))
00152                                         $checkbox = "checked=checked ";
00153                                 if(in_array($row['page_id'],$hide_list))
00154                                         $hide_checkbox = "checked=checked ";
00155                                 $table .= "<tr><td><input type='radio' name='optInitial' value='{$row['page_id']}' {$radio}></td><td><input type=checkbox name='chkPage{$row['page_id']}' {$checkbox}></td><td><input type=checkbox name='hidePage{$row['page_id']}' {$hide_checkbox}></td>";
00156                                 if(getPermissions($this->userId, $row['page_id'], "edit"))
00157                                         $table .= "<td><a href='{$row['page_name']}/+edit'>{$row['page_title']}</a></td></tr>";
00158                                 else
00159                                         $table .= "<td>{$row['page_title']}</td></tr>";
00160                         }
00161                         $table .= "</table>";
00162                 } else {
00163                         $table = "No child page available<br />";
00164                 }
00165                 $ret =<<<RET
00166 <form action='./+edit' method=POST>
00167 Title: <input type=text name="page_title" value="{$this->bookProps['page_title']}"><br />
00168 {$table}
00169 <input type=submit value=Save>
00170 </form>
00171 RET;
00172                 return $ret;
00173         }
00174 
00180         public function createModule(&$moduleComponentId) {
00181                 $query = "SELECT MAX(page_modulecomponentid) as MAX FROM `book_desc` ";
00182                 $result = mysql_query($query) or die(mysql_error() . "book.lib L:1");
00183                 $row = mysql_fetch_assoc($result);
00184                 $compId = $row['MAX'] + 1;
00185                 
00186                 $query = "INSERT INTO `book_desc` (`page_modulecomponentid` , `initial`, `list`,`menu_hide`)VALUES ('$compId','','','')";
00187                 $result = mysql_query($query) or die(mysql_error()."book.lib L:187");
00188                 if (mysql_affected_rows()) {
00189                         $moduleComponentId = $compId;
00190                         return true;
00191                 } else
00192                         return false;
00193         }
00194         
00200         public function deleteModule($moduleComponentId) {
00201                 $result = mysql_query("DELETE FROM `book_desc` WHERE `page_modulecomponentid` = '{$moduleComponentId}'") or die(mysql_error());
00202                 if(mysql_affected_rows())
00203                         return true;
00204                 else
00205                         return false;
00206         }
00207         
00212         public function copyModule($moduleComponentId) {
00213                 $result = mysql_fetch_assoc(mysql_query("SELECT * FROM `book_desc` WHERE `page_modulecomponentid` = '{$moduleComponentId}'"));
00214                 $max = mysql_fetch_row(mysql_query("SELECT MAX(`page_modulecomponentid`) AS 'max' FROM `book_desc`"));
00215                 $compId = $max[0] + 1;
00216                 $query = mysql_query("INSERT INTO `book_desc`(`page_modulecomponentid` , `initial`, `list`)VALUES ('$compId','','')");
00217                 return $compId;
00218         }
00219         
00224         public function tabScript() {
00225                 global $urlRequestRoot, $cmsFolder, $tabScriptDone;
00226                 $ret = "";
00227                 if(!$tabScriptDone)
00228                         $ret =<<<RET
00229 
00230 <script type="text/javascript">
00231 <!--
00232 var delay = 500;
00233 var initialInfo = new Object();
00234 $(document).ready(function() {
00235         $('.active').removeClass('active');
00236         activate({$this->pageId});
00237 });
00238 $(document).ready(function() {
00239         $('.tabElement').find("a").click(function() {
00240                 var selid=$(this).attr('id');
00241                 var selector = '#tab' + selid;
00242                 var page = selector.substr(1,selector.indexOf('_')-1);
00243                 var activeClasses = $('.active');
00244                 
00245                 for(i=0;i<activeClasses.length;i++) {
00246                         var thisid = activeClasses.get(i).id; 
00247                         if(page == thisid.substr(0,page.length)) {
00248                                 $('#' + thisid + ' .active').removeClass('active');
00249                                 $('#' + thisid).removeClass('active');
00250                                 $('#' + thisid.substr(3,thisid.length) + ' > span').removeClass('tabitemactive');
00251                                 $('#' + thisid).fadeOut(delay, function() {
00252                         
00253                                         $(selector).fadeIn(delay).addClass('active');
00254                                         $('#'+selector.substr(4,selector.length)+' > span').addClass('tabitemactive');
00255                                         activate(selector.substr(selector.indexOf('_')+1));
00256                                 });
00257                         }
00258                 }
00259                 return false;
00260         });
00261 });
00262 function activate(id) {
00263         if(initialInfo[id]) {
00264                 $('#tabContent' + id + '_' + initialInfo[id]).fadeIn(delay);
00265                 $('#tabContent' + id + '_' + initialInfo[id]).addClass('active');
00266         }
00267 }
00268 RET;
00269                 else
00270                         $ret = "<script type=\"text/javascript\">";
00271                 $ret .=<<<RET
00272 initialInfo[{$this->pageId}] = {$this->bookProps['initial']};
00273 //-->
00274 </script>
00275 RET;
00276                 $tabScriptDone = true;
00277                 return $ret;
00278         }
00279         
00285         public function isPresent($parentId,$pageId) {
00286                 $moduleComponentId = getModuleComponentIdFromPageId($parentId,'book');
00287                 $list = mysql_fetch_assoc(mysql_query("SELECT `list` FROM `book_desc` WHERE `page_modulecomponentid` = '{$moduleComponentId}'"));
00288                 $list = explode(",",$list['list']);
00289                 foreach($list as $element) {
00290                         if($pageId == $element)
00291                                 return true;
00292                         if(getPageModule($element)=='book')
00293                                 return $this->isPresent($element,$pageId);
00294                 }
00295                 return false;
00296         }
00297         
00302         private function hideInMenu() {
00303                 $cond = "";
00304                 if($this->bookProps['menu_hide'] != "") {
00305                         mysql_query("UPDATE `" . MYSQL_DATABASE_PREFIX . "pages` SET `page_displayinmenu` = 0 WHERE `page_parentid` = '{$this->pageId}' AND `page_id` IN ({$this->bookProps['menu_hide']})");
00306                         $cond = " AND `page_id` NOT IN ({$this->bookProps['menu_hide']})";
00307                 }
00308                 mysql_query("UPDATE `" . MYSQL_DATABASE_PREFIX . "pages` SET `page_displayinmenu` = 1 WHERE `page_parentid` = '{$this->pageId}'{$cond}");
00309         }
00310 }
00311 ?>

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