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(& $moduleComponentId) {
00185 $gallQuery = "SELECT MAX(`page_modulecomponentid`) AS max FROM `gallery_name`";
00186 $gallResult = mysql_query($gallQuery);
00187 $nextId = 1;
00188 if ($gallResultRow = mysql_fetch_row($gallResult)) {
00189 $nextId = $gallResultRow[0] + 1;
00190 }
00191 $gallQuery = "INSERT INTO `gallery_name` (`page_modulecomponentid`, `gallery_name`, `gallery_desc`) VALUES($nextId, 'New Gallery', 'Edit your new gallery')";
00192 $gallResult = mysql_query($gallQuery);
00193 if ($gallResult) {
00194 $moduleComponentId = $nextId;
00195 }
00196 }
00197 public function actionEdit($moduleComponentId) {
00198 global $sourceFolder;
00199 global $templateFolder;
00200 global $urlRequestRoot;
00201 global $uploadFolder;
00202 require_once ("$sourceFolder/upload.lib.php");
00203 $arr = getUploadedFiles($moduleComponentId, 'gallery');
00204 if (isset ($_POST['btnDeleteImage']) && isset ($_POST['imagename']) && $_POST['imagename'] != '') {
00205 deleteFile($moduleComponentId, 'gallery', $_POST['imagename']);
00206 $gallQuery = "DELETE FROM `gallery_pics` WHERE `upload_filename`='".escape($_POST['imagename'])."'";
00207 $gallResult = mysql_query($gallQuery);
00208 }
00209 else if (isset ($_POST['btnEditComment']) && isset ($_POST['imagename']) && $_POST['imagename'] != '') {
00210 $imageName = escape($_POST['imagename']);
00211 $comment = escape($_POST['desc']);
00212 $gallQuery = "UPDATE `gallery_pics` SET `gallery_filecomment`=\"$comment\" WHERE `upload_filename`=\"$imageName\"";
00213 $gallResult = mysql_query($gallQuery);
00214 }
00215 if (isset ($_POST['btnEditGallname']) && isset ($_POST['gallName']) && isset ($_POST['gallDesc']) && $_POST['gallName'] != '' && $_POST['gallDesc'] != '') {
00216 if(is_numeric($_POST['imagesPerPage']))
00217 $perPage = (int)escape($_POST['imagesPerPage']);
00218 $viewCount = ( $_POST['allowViews'] ? 1 : 0 );
00219 $gallQuery = "UPDATE `gallery_name` SET `gallery_name`='".escape($_POST['gallName'])."',`gallery_desc`='".escape($_POST['gallDesc'])."', `imagesPerPage`='".$perPage."',`allowViews`=".$viewCount." WHERE `page_modulecomponentid`=$moduleComponentId";
00220 $gallResult = mysql_query($gallQuery);
00221 }
00222
00223 $content2 = getFileUploadForm($this->moduleComponentId, "gallery", './+edit', 10000000, 5);
00224 $allowableTypes = array (
00225 'jpeg',
00226 'jpg',
00227 'png',
00228 'gif'
00229 );
00230
00231 $uploadSuccess = submitFileUploadForm($this->moduleComponentId, "gallery", $this->userId, false, $allowableTypes);
00232 if (is_array($uploadSuccess) && isset ($uploadSuccess[0])) {
00233 for($i=0;$i<count($uploadSuccess);$i++){
00234 $gallQuery3 = "INSERT INTO `gallery_pics` (`upload_filename`, `page_modulecomponentid`, `gallery_filecomment`) VALUES('$uploadSuccess[$i]', $this->moduleComponentId, 'No Comment')";
00235 $gallResult3 = mysql_query($gallQuery3);
00236 }
00237 }
00238 $arr = getUploadedFiles($this->moduleComponentId, 'gallery');
00239 global $ICONS;
00240 $content2="<fieldset><legend>{$ICONS['Gallery Edit']['small']}Edit Gallery</legend>".$content2;
00241
00242 $result = mysql_fetch_array(mysql_query("SELECT * FROM `gallery_name` WHERE `page_modulecomponentid` = '{$this->moduleComponentId}'"));
00243 if($result){
00244 $checkViews = ($result['allowViews'] == 1 ? 'checked="checked" ': '' );
00245 }
00246 $content2 .=<<<GALFORM
00247 <br /><br />
00248 <script type="text/javascript">
00249 <!--
00250 function validate() {
00251 var strValidChars = "0123456789.-";
00252 var strString = document.getElementById('perPage').value;
00253
00254 if (strString.length == 0)
00255 alert("Empty Images Per Page will be taken as default value(10).");
00256
00257 for (i = 0; i < strString.length; i++) {
00258 if (strValidChars.indexOf(strString.charAt(i)) == -1) {
00259 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).");
00260 break;
00261 }
00262 }
00263 }
00264 -->
00265 </script>
00266 <form name="edit" method="POST" action="./+edit">
00267 <table>
00268 <tr><th colspan=2>Edit gallery name and description</th></tr>
00269 <tr>
00270 <td>New Gallery Name</td>
00271 <td><input type='text' name="gallName" value='{$result['gallery_name']}'></td>
00272 </tr>
00273 <tr>
00274 <td>New Gallery Description</td>
00275 <td><input type='text' name="gallDesc" value='{$result['gallery_desc']}'></td>
00276 </tr>
00277 <tr>
00278 <td>Allow View Count</td>
00279 <td><input type="checkbox" name="allowViews" $checkViews></td>
00280 </tr>
00281 <tr>
00282 <td>Images Per Page</td>
00283 <td><input type="text" id=perPage name="imagesPerPage" value='{$result['imagesPerPage']}'></td>
00284 </tr>
00285 <tr>
00286 <td><input type="submit" name="btnEditGallname" value="Save Settings"></td>
00287 </tr>
00288 </table>
00289 </form>
00290 <br /><br />
00291 GALFORM;
00292 $gallQuery2 = "SELECT * FROM `gallery_pics` where `page_modulecomponentid`= $this->moduleComponentId";
00293 $gallResult2 = mysql_query($gallQuery2);
00294 $fileArray = array ();
00295 while ($row2 = mysql_fetch_assoc($gallResult2))
00296 $fileArray[] = $row2;
00297 if ($fileArray) {
00298 for ($i = 0; $i < count($fileArray); $i++) {
00299 $galleryFilename = $fileArray[$i]['upload_filename'];
00300 $galleryComment = $fileArray[$i]['gallery_filecomment'];
00301 $galleryComment = $galleryComment!=""?$galleryComment:"< No Comments >";
00302
00303 $content2 .= "<div class='galleryimagebox'><form name=\"edit\" method=\"POST\" action=\"./+edit\">";
00304 $content2 .=<<<IMGFORM
00305 <span style="float:left">
00306 <center>
00307 <img src="thumb_$galleryFilename" alt="$galleryFilename" title="Click on the image to delete it"/>
00308 </center>
00309 <div class="highslide-caption" id="caption$i">$galleryComment</div>
00310 <input type="hidden" name="imagename" value="$galleryFilename" />
00311 <input type="text" name="desc">
00312 <br/><input type="submit" name="btnEditComment" value="Update comment">
00313 <input type="submit" name="btnDeleteImage" value="Delete" />
00314 </span>
00315 IMGFORM;
00316 $content2 .= "</form></div>";
00317 }
00318 }
00319 return $content2."</fieldset>";
00320 }
00321 public function deleteModule($moduleComponentId) {
00322 global $sourceFolder;
00323 require_once("$sourceFolder/upload.lib.php");
00324 $arr = getUploadedFiles($moduleComponentId, 'gallery');
00325 $content = true;
00326 for ($c = 0; $c < count($arr); $c++) {
00327 $content = deleteFile($moduleComponentId, 'gallery', $arr[$c]['upload_filename']) && $content;
00328 }
00329 $gallQuery = "DELETE FROM `gall_name` where `page_modulecomponentid`=$moduleComponentId";
00330 $gallResult = mysql_query($gallQuery);
00331 $gallQuery2 = "DELETE FROM `gall_pics` where `page_modulecomponentid`=$moduleComponentId";
00332 $gallResult2 = mysql_query($gallQuery2);
00333 return $content;
00334 }
00335 public function copyModule($moduleComponentId) {
00336 $gallQuery = "SELECT * FROM `gallery_pics` WHERE page_modulecomponentid = " . $moduleComponentId;
00337 $gallResult = mysql_query($gallQuery);
00338 $gallRow = mysql_fetch_assoc($gallResult);
00339 $gallQuery2 = "SELECT MAX(`page_modulecomponentid`) AS 'max' from `gallery_name`";
00340 $gallResult2 = mysql_query($gallQuery2);
00341 $destinationPage_moduleComponentId = $gallResult2['max'] + 1;
00342 while ($gallRow) {
00343 fileCopy($moduleComponentId, 'gallery', $gallRow['upload_filename'], $destinationPage_moduleComponentId, 'gallery', $gallRow['upload_filename'], $this->userId);
00344 $thumb ="thumb_".$gallRow['upload_filename'];
00345 fileCopy($moduleComponentId, 'gallery', $thumb, $destinationPage_moduleComponentId, 'gallery', $gallRow['upload_filename'], $this->userId);
00346 }
00347 }
00348 }