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
00017 class gallery implements module, fileuploadable {
00018 private $userId;
00019 private $moduleComponentId;
00020 private $action;
00021 public function getHtml($gotuid, $gotmoduleComponentId, $gotaction) {
00022 $this->userId = $gotuid;
00023 $this->moduleComponentId = $gotmoduleComponentId;
00024 $this->action = $gotaction;
00025 if ($this->action == "view")
00026 return $this->actionView();
00027 if ($this->action == "create")
00028 return $this->createModule($this->moduleComponentId);
00029 if ($this->action == "edit")
00030 return $this->actionEdit($this->moduleComponentId);
00031 }
00032
00036 public static function getFileAccessPermission($pageId, $moduleComponentId, $userId, $fileName) {
00037 return getPermissions($userId, $pageId, "view");
00038 }
00039
00040 public static function getUploadableFileProperties(& $fileTypesArray, & $maxFileSizeInBytes) {
00041 $fileTypesArray = array (
00042 'jpg',
00043 'jpeg',
00044 'png',
00045 'gif'
00046 );
00047 $maxFileSizeInBytes = 2 * 1024 * 1024;
00048 }
00049
00050 public static function getFileAccessAction() {
00051 return "view";
00052 }
00053
00054 public function actionView() {
00055 global $sourceFolder,$cmsFolder;
00056 global $templateFolder;
00057 global $urlRequestRoot;
00058 global $moduleFolder;
00059 global $uploadFolder;
00060
00061 if(isset($_GET['subaction'])&&$_GET['subaction']=='ajax') {
00062 if($_GET['ref']){
00063 $arr=explode("/",$_GET['ref']);
00064 $arr = $arr[sizeof($arr)-1];
00065 $query="SELECT* FROM `gallery_pics` WHERE upload_filename='".$arr."' AND page_modulecomponentid='$this->moduleComponentId' LIMIT 1";
00066 $result=mysql_query($query);
00067 if($result){
00068 $newrate = mysql_result($result,0,'pic_rate')+1;
00069 $query="UPDATE `gallery_pics` SET `pic_rate`='".$newrate."' WHERE upload_filename='".$arr."' AND page_modulecomponentid='$this->moduleComponentId'";
00070 mysql_query($query);
00071 }}
00072 else if($_GET['getView']){
00073 $arr1=explode("/",$_GET['getView']);
00074 $arr1 = $arr1[sizeof($arr1)-1];
00075 $query="SELECT* FROM `gallery_pics` WHERE upload_filename='".$arr1."' AND page_modulecomponentid='$this->moduleComponentId' LIMIT 1";
00076 $result1=mysql_query($query);
00077 if($result1){
00078 $view = mysql_result($result1,0,'pic_rate');
00079 echo $view;
00080 }
00081 }
00082 disconnect();
00083 exit(0);
00084 }
00085
00086 $content =<<<JS
00087 <script type="text/javascript" src="$urlRequestRoot/$cmsFolder/$moduleFolder/gallery/highslide-with-gallery.js"></script>
00088 <link rel="stylesheet" type="text/css" href="$urlRequestRoot/$cmsFolder/$moduleFolder/gallery/highslide.css" />
00089 <script type="text/javascript">
00090 hs.graphicsDir = '$urlRequestRoot/$cmsFolder/$moduleFolder/gallery/graphics/';
00091 hs.align = 'center';
00092 hs.transitions = ['expand', 'crossfade'];
00093 hs.fadeInOut = true;
00094 hs.dimmingOpacity = 0.8;
00095 hs.outlineType = 'rounded-white';
00096 hs.captionEval = 'this.thumb.alt';
00097 hs.marginBottom = 105;
00098 hs.numberPosition = 'caption';
00099
00100 hs.addSlideshow({
00101 interval: 5000,
00102 repeat: false,
00103 useControls: true,
00104 overlayOptions: {
00105 className: 'text-controls',
00106 position: 'bottom center',
00107 relativeTo: 'viewport',
00108 offsetY: -60
00109 },
00110 thumbstrip: {
00111 position: 'bottom center',
00112 mode: 'horizontal',
00113 relativeTo: 'viewport'
00114 }
00115 });
00116 </script>
00117 JS;
00118 $gallQuery = "SELECT * from `gallery_name` where `page_modulecomponentid`=$this->moduleComponentId";
00119 $gallResult = mysql_query($gallQuery);
00120 $row = mysql_fetch_assoc($gallResult);
00121 $content .= "<h2><center>{$row['gallery_name']}</center></h2><br/><center><h3>{$row['gallery_desc']}</center></h3>";
00122 $perPage = $row['imagesPerPage'];
00123 $viewCheck = $row['allowViews'];
00124 include_once ("$sourceFolder/" . 'upload.lib.php');
00125 $query = "SELECT `upload_filename` FROM `gallery_pics` WHERE `page_modulecomponentid` =". $this->moduleComponentId;
00126 $pic_result = mysql_query($query) or die(mysql_error());
00127 $arr = array ();
00128 while ($row = mysql_fetch_assoc($pic_result))
00129 $arr[] = $row;
00130 $numPic = count($arr);
00131 if(isset($_GET['gallerypage']))
00132 $page = (int)escape($_GET['gallerypage']) - 1;
00133 else
00134 $page = 0;
00135 $start = $page * $perPage;
00136 if($start > $numPic) {
00137 $start = 0;
00138 $page = 0;
00139 }
00140 $end = $start + $perPage;
00141 if($end > $numPic)
00142 $end = $numPic;
00143 $content .= '<div class="highslide-gallery" style="width: 100%; margin: auto">';
00144 for ($i = $start; $i < $end; $i++) {
00145 $gallQuery2 = "SELECT * FROM `gallery_pics` where `upload_filename`='{$arr[$i]['upload_filename']}' AND `page_modulecomponentid`= $this->moduleComponentId";
00146 $gallResult2 = mysql_query($gallQuery2);
00147 $row2 = mysql_fetch_assoc($gallResult2);
00148 if ($row2) {
00149 $content .= "<input type=\"hidden\" id=\""."thumb_"."{$row2['upload_filename']}\" value=\"{$row2['pic_rate']}\" />";
00150 $content .= "<a href=\"./" . $arr[$i]['upload_filename'] . '" class=\'highslide\' onclick="return hs.expand(this,0,0,0,document.getElementById(\'thumb_' .$row2['upload_filename'].'\'),'.$viewCheck.')">';
00151 $content .= "<img src=\"./thumb_" . $arr[$i]['upload_filename'] . "\" alt='{$row2['gallery_filecomment']}' title='Click to enlarge' /></a> ";
00152 }
00153 }
00154 $content .= '</div>';
00155 $nextVal = $page + 2;
00156 if($start == 0)
00157 $prevButton = "<<Prev ";
00158 else
00159 $prevButton = "<a href='./+view&gallerypage=" . $page . "'> <<Prev</a> ";
00160 if($end == $numPic)
00161 $nextButton = " Next>>";
00162 else
00163 $nextButton = " <a href='./+view&gallerypage=" . $nextVal . "'> Next>> </a>";
00164 $pages = "";
00165 $pageStart = 1;
00166 $pageEnd = ceil($numPic/$perPage);
00167 if($page > 4) {
00168 $pageStart = $page - 3;
00169 $pages .= "... ";
00170 }
00171 if($pageEnd - $page > 5)
00172 $pageEnd = $page + 5;
00173 $pageVal = $page + 1;
00174 for($i = $pageStart; $i <= $pageEnd; $i++)
00175 if($i == $pageVal)
00176 $pages .= " $pageVal ";
00177 else
00178 $pages .= " <a href='./+view&gallerypage={$i}'>{$i}</a> ";
00179 if(ceil($numPic/$perPage) - $page > 5)
00180 $pages .= " ...";
00181 $content .= "<p>" . $prevButton . $pages . $nextButton . "</p>";
00182 return $content;
00183 }
00184 public function createModule($nextId) {
00185 $gallQuery = "INSERT INTO `gallery_name` (`page_modulecomponentid`, `gallery_name`, `gallery_desc`) VALUES($nextId, 'New Gallery', 'Edit your new gallery')";
00186 $gallResult = mysql_query($gallQuery);
00187 }
00188 public function actionEdit($moduleComponentId) {
00189 global $sourceFolder;
00190 global $templateFolder;
00191 global $urlRequestRoot;
00192 global $uploadFolder;
00193 require_once ("$sourceFolder/upload.lib.php");
00194 $arr = getUploadedFiles($moduleComponentId, 'gallery');
00195 if (isset ($_POST['btnDeleteImage']) && isset ($_POST['imagename']) && $_POST['imagename'] != '') {
00196 deleteFile($moduleComponentId, 'gallery', $_POST['imagename']);
00197 $gallQuery = "DELETE FROM `gallery_pics` WHERE `upload_filename`='".escape($_POST['imagename'])."'";
00198 $gallResult = mysql_query($gallQuery);
00199 }
00200 else if (isset ($_POST['btnEditComment']) && isset ($_POST['imagename']) && $_POST['imagename'] != '') {
00201 $imageName = escape($_POST['imagename']);
00202 $comment = escape($_POST['desc']);
00203 $gallQuery = "UPDATE `gallery_pics` SET `gallery_filecomment`=\"$comment\" WHERE `upload_filename`=\"$imageName\"";
00204 $gallResult = mysql_query($gallQuery);
00205 }
00206 if (isset ($_POST['btnEditGallname']) && isset ($_POST['gallName']) && isset ($_POST['gallDesc']) && $_POST['gallName'] != '' && $_POST['gallDesc'] != '') {
00207 if(is_numeric($_POST['imagesPerPage']))
00208 $perPage = (int)escape($_POST['imagesPerPage']);
00209 $viewCount = ( $_POST['allowViews'] ? 1 : 0 );
00210 $gallQuery = "UPDATE `gallery_name` SET `gallery_name`='".escape($_POST['gallName'])."',`gallery_desc`='".escape($_POST['gallDesc'])."', `imagesPerPage`='".$perPage."',`allowViews`=".$viewCount." WHERE `page_modulecomponentid`=$moduleComponentId";
00211 $gallResult = mysql_query($gallQuery);
00212 }
00213
00214 $content2 = getFileUploadForm($this->moduleComponentId, "gallery", './+edit', 10000000, 5);
00215 $allowableTypes = array (
00216 'jpeg',
00217 'jpg',
00218 'png',
00219 'gif'
00220 );
00221
00222 $uploadSuccess = submitFileUploadForm($this->moduleComponentId, "gallery", $this->userId, false, $allowableTypes);
00223 if (is_array($uploadSuccess) && isset ($uploadSuccess[0])) {
00224 for($i=0;$i<count($uploadSuccess);$i++){
00225 $gallQuery3 = "INSERT INTO `gallery_pics` (`upload_filename`, `page_modulecomponentid`, `gallery_filecomment`) VALUES('$uploadSuccess[$i]', $this->moduleComponentId, 'No Comment')";
00226 $gallResult3 = mysql_query($gallQuery3);
00227 }
00228 }
00229 $arr = getUploadedFiles($this->moduleComponentId, 'gallery');
00230 global $ICONS;
00231 $content2="<fieldset><legend>{$ICONS['Gallery Edit']['small']}Edit Gallery</legend>".$content2;
00232
00233 $result = mysql_fetch_array(mysql_query("SELECT * FROM `gallery_name` WHERE `page_modulecomponentid` = '{$this->moduleComponentId}'"));
00234 if($result){
00235 $checkViews = ($result['allowViews'] == 1 ? 'checked="checked" ': '' );
00236 }
00237 $content2 .=<<<GALFORM
00238 <br /><br />
00239 <script type="text/javascript">
00240 <!--
00241 function validate() {
00242 var strValidChars = "0123456789.-";
00243 var strString = document.getElementById('perPage').value;
00244
00245 if (strString.length == 0)
00246 alert("Empty Images Per Page will be taken as default value(10).");
00247
00248 for (i = 0; i < strString.length; i++) {
00249 if (strValidChars.indexOf(strString.charAt(i)) == -1) {
00250 alert("The value in the Images Per Page field doesn't seems to be valid number. An invalid number will be replaced by default value(10).");
00251 break;
00252 }
00253 }
00254 }
00255 -->
00256 </script>
00257 <form name="edit" method="POST" action="./+edit">
00258 <table>
00259 <tr><th colspan=2>Edit gallery name and description</th></tr>
00260 <tr>
00261 <td>New Gallery Name</td>
00262 <td><input type='text' name="gallName" value='{$result['gallery_name']}'></td>
00263 </tr>
00264 <tr>
00265 <td>New Gallery Description</td>
00266 <td><input type='text' name="gallDesc" value='{$result['gallery_desc']}'></td>
00267 </tr>
00268 <tr>
00269 <td>Allow View Count</td>
00270 <td><input type="checkbox" name="allowViews" $checkViews></td>
00271 </tr>
00272 <tr>
00273 <td>Images Per Page</td>
00274 <td><input type="text" id=perPage name="imagesPerPage" value='{$result['imagesPerPage']}'></td>
00275 </tr>
00276 <tr>
00277 <td><input type="submit" name="btnEditGallname" value="Save Settings"></td>
00278 </tr>
00279 </table>
00280 </form>
00281 <br /><br />
00282 GALFORM;
00283 $gallQuery2 = "SELECT * FROM `gallery_pics` where `page_modulecomponentid`= $this->moduleComponentId";
00284 $gallResult2 = mysql_query($gallQuery2);
00285 $fileArray = array ();
00286 while ($row2 = mysql_fetch_assoc($gallResult2))
00287 $fileArray[] = $row2;
00288 if ($fileArray) {
00289 for ($i = 0; $i < count($fileArray); $i++) {
00290 $galleryFilename = $fileArray[$i]['upload_filename'];
00291 $galleryComment = $fileArray[$i]['gallery_filecomment'];
00292 $galleryComment = $galleryComment!=""?$galleryComment:"< No Comments >";
00293
00294 $content2 .= "<div class='galleryimagebox'><form name=\"edit\" method=\"POST\" action=\"./+edit\">";
00295 $content2 .=<<<IMGFORM
00296 <span style="float:left">
00297 <center>
00298 <img src="thumb_$galleryFilename" alt="$galleryFilename" title="Click on the image to delete it"/>
00299 </center>
00300 <div class="highslide-caption" id="caption$i">$galleryComment</div>
00301 <input type="hidden" name="imagename" value="$galleryFilename" />
00302 <input type="text" name="desc">
00303 <br/><input type="submit" name="btnEditComment" value="Update comment">
00304 <input type="submit" name="btnDeleteImage" value="Delete" />
00305 </span>
00306 IMGFORM;
00307 $content2 .= "</form></div>";
00308 }
00309 }
00310 return $content2."</fieldset>";
00311 }
00312 public function deleteModule($moduleComponentId) {
00313 global $sourceFolder;
00314 require_once("$sourceFolder/upload.lib.php");
00315 $arr = getUploadedFiles($moduleComponentId, 'gallery');
00316 $content = true;
00317 for ($c = 0; $c < count($arr); $c++) {
00318 $content = deleteFile($moduleComponentId, 'gallery', $arr[$c]['upload_filename']) && $content;
00319 }
00320 return $content;
00321 }
00322 public function copyModule($moduleComponentId,$newId) {
00323 $gallQuery = "SELECT * FROM `gallery_pics` WHERE page_modulecomponentid = " . $moduleComponentId;
00324 $gallResult = mysql_query($gallQuery);
00325 $gallRow = mysql_fetch_assoc($gallResult);
00326 $destinationPage_moduleComponentId = $newId;
00327 while ($gallRow) {
00328 fileCopy($moduleComponentId, 'gallery', $gallRow['upload_filename'], $destinationPage_moduleComponentId, 'gallery', $gallRow['upload_filename'], $this->userId);
00329 $thumb ="thumb_".$gallRow['upload_filename'];
00330 fileCopy($moduleComponentId, 'gallery', $thumb, $destinationPage_moduleComponentId, 'gallery', $gallRow['upload_filename'], $this->userId);
00331 }
00332 return true;
00333 }
00334 }