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 }
00018 function handleIconManagement() {
00019
00020
00021
00022
00023 if(isset($_POST['FileUploadForm'])){
00024 global $userId,$sourceFolder;
00025 require_once("$sourceFolder/upload.lib.php");
00026 $allowableTypes = array (
00027 'jpeg',
00028 'jpg',
00029 'png',
00030 'gif'
00031 );
00032 $result = submitFileUploadForm($userId, 'iconman', $userId, false, $allowableTypes, 'iconUpload');
00033
00034 }
00035
00039 if(isset($_GET['iconURL']))
00040 {
00041 $rootUri = hostURL();
00042 global $cmsFolder,$templateFolder;
00043 if(isset($_GET["iconURL"]) && isset($_GET['targetId'])) {
00044
00045 $iconURL = $_GET["iconURL"];
00046 $iconURL = str_replace($rootUri, "", $iconURL);
00047 $parse = strstr($iconURL, "$cmsFolder/$templateFolder/common/icons/");
00048 if($parse == "")
00049 $parse = strstr($iconURL, "$cmsFolder/uploads/iconman/");
00050 $iconURL = $parse;
00051 $iconURL = escape($iconURL);
00052 $target = escape($_GET["targetId"]);
00053
00054 mysql_query("UPDATE `".MYSQL_DATABASE_PREFIX."pages` SET `page_image`='$iconURL' WHERE `page_id`='$target'");
00055 $pageDetails = getPageInfo($target);
00056 if($pageDetails['page_image'] != NULL)
00057 echo "<img src=\"$rootUri/$cmsFolder/$templateFolder/common/icons/16x16/status/weather-clear.png\" /> ";
00058 else
00059 echo "<img src=\"$rootUri/$cmsFolder/$templateFolder/common/icons/16x16/status/dialog-error.png\" width=12 height=12/> ";
00060 echo $pageDetails["page_name"];
00061
00062 }
00063 else if(isset($_GET['iconAction'])) {
00064 $action = $_GET['iconAction'];
00065
00066 }
00067 else
00068 {
00069 die("Restricted access");
00070 }
00071 exit(0);
00072 }
00073
00074
00075
00076 $iconForm = "";
00077 $iconForm .= <<<ICONFORM
00078 <style type="text/css">
00079 .myIconForm div {
00080 padding: 5px;
00081 }
00082 .myIconForm div a{
00083 text-decoration: none!important;
00084 }
00085 </style>
00086
00087 ICONFORM;
00088
00089 global $cmsFolder;
00090 global $sourceFolder;
00091 global $templateFolder;
00092 global $userId;
00093 $myhostURL = hostURL();
00094 $iconForm .= "<script type=\"text/javascript\" src=\"$myhostURL/$cmsFolder/$templateFolder/common/scripts/icon.event.handler.js\"></script>";
00095 $iconForm .= <<<STYLES
00096 <style type="text/css">
00097 .myIconForm {
00098 margin:0;
00099 padding:0;
00100 }
00101 #iconTreeMenu {
00102 position:relative;
00103 }
00104 .myIconForm ul {
00105 margin: 5px;
00106 width: 100%;
00107 margin-left: 10px;
00108 padding: 0;
00109 border-left: solid 1px #333;
00110 }
00111 .myFormIcon ul li a {
00112 padding: 5px;
00113 }
00114 .myIconList {
00115 height:500px;
00116 overflow:scroll;
00117 max-width:100%;
00118 }
00119 </style>
00120 STYLES;
00121
00122 require_once("$sourceFolder/upload.lib.php");
00123 $fakeid = $userId;
00124
00125 $imageUploadField = getMultipleFileUploadField('iconUpload','iconman',512*1024);
00126
00127
00128 $uploadForm .= <<<FORM
00129 <form method="POST" action="./+admin&subaction=icon" enctype="multipart/form-data">
00130 $imageUploadField
00131 <input type="submit" />
00132 </form>
00133
00134 FORM;
00135
00136 $iconForm .= "<table class=\"myIconForm\"><tr><td id=\"iconTreeMenu\">";
00137 $iconForm .= getTreeView(0,-1,$myhostURL,$userId,1);
00138 $iconForm .= "</td>";
00139 $iconForm .="<td>";
00140 $selectionList = getIconList();
00141
00142 $iconForm .= <<<SELECTION
00143 <div class="selection" id="targetIcon">
00144 <h3>Upload new icons</h3>
00145 <p align="left">
00146 {$uploadForm}<br/>
00147 - Select Multiple files
00148 </p>
00149 <h3>List of available icons</h3>
00150 <p align="left">
00151 Usage : <br />
00152 - Drag and drop<br />
00153 - Select an icon and then choose the target.
00154 </p>
00155 <div class="selectlist">
00156 {$selectionList}
00157 </div>
00158 </div>
00159 SELECTION;
00160
00161 $iconForm .="</td>";
00162
00163 $iconForm .= "</tr></table>";
00164
00165
00166
00167 return $iconForm;
00168 }
00169 function getTreeView($pageId,$depth,$rootUri,$userId,$curdepth) {
00170 global $cmsFolder;
00171 global $templateFolder;
00172 require_once("menu.lib.php");
00173 if($depth>0 || $depth==-1) {
00174 if($curdepth==1 || $pageId==0) $classname="treeRoot";
00175 else $classname="treeItem";
00176 $pageRow = getChildren($pageId,$userId);
00177 $var = "<ul class='{$classname}'>";
00178 for($i=0;$i<count($pageRow);$i+=1) {
00179 $newdepth=$curdepth+1;
00180 $var .= "<li><a href=\"./\" class=\"dropme\" onclick=\"return selectItem(event,this)\"";
00181 $var .= <<<DROPZONE
00182 ondragenter="dragEnterHandler(event)" ondragover="dragOverHandler(event)" ondragleave="dragOutHandler(event)" ondrop="dropHandler(event)" id="p{$pageRow[$i][0]}">
00183 DROPZONE;
00184 if($pageRow[$i][3] != NULL)
00185 $var .= "<img src=\"$rootUri/$cmsFolder/$templateFolder/common/icons/16x16/status/weather-clear.png\" />\n ";
00186 else
00187 $var .= "<img src=\"$rootUri/$cmsFolder/$templateFolder/common/icons/16x16/status/dialog-error.png\" width=12 height=12/>\n ";
00188 $var .= "{$pageRow[$i][1]}</a>";
00189 $var .= getTreeView($pageRow[$i][0],($depth==-1)?$depth:($depth-1),$rootUri,$userId,$newdepth);
00190 $var .= "</li>";
00191 }
00192 $var .= "</ul>";
00193 if(count($pageRow)==0) return "";
00194 return $var;
00195 }
00196 }
00197
00198 function getIconList() {
00199 $iconList = "";
00200 $rootUri = hostURL();
00201 global $cmsFolder,$sourceFolder;
00202 global $templateFolder;
00203 $dir = "$cmsFolder/$templateFolder/common/icons/32x32/";
00204 $uploaded = "";
00205 if(is_dir("$sourceFolder/uploads/iconman/")) {
00206 $uploaded = "$cmsFolder/uploads/iconman/";
00207 }
00208
00209
00210
00211 $handle = scandir($dir);
00212 $iconList .= <<<SCRIPTS
00213 <script type="text/javascript">
00214 var rootUri = "{$rootUri}";
00215 var cmsFolder = "{$cmsFolder}";
00216 var templateFolder = "{$templateFolder}";
00217 </script>
00218 SCRIPTS;
00219 $iconList .= <<<STYLES
00220 <style type="text/css">
00221 .dragme{
00222 float:left;
00223 }
00224 .myIconList #noImage {
00225 width: 30px;
00226 height: 30px;
00227 border: solid 1px #000;
00228 }
00229 </style>
00230 STYLES;
00231 $iconList .= "<div class='myIconList'>";
00232
00233 $id=0;
00234 $iconList .= <<<NONE
00235 <div class="dragme" draggable="true" ondragstart="dragStartHandler(event,this)" id="noImage" onclick="selectIcon(event,this)">
00236 <img src="{$rootUri}/{$cmsFolder}/{$templateFolder}/common/images/erase_icon.jpg" width=30 height=30/>
00237 </div>
00238 NONE;
00239
00240
00241 if($uploaded != "") {
00242 $iconList .= <<<HTMl
00243 <style type="text/css">
00244 .myUploadedIcons {
00245 clear: both;
00246 }
00247 </style>
00248 <div class="myUploadedIcons">
00249 <h3>My Uploads: </h3>
00250 HTMl;
00251 $iconList .= getListOfFiles($uploaded, true);
00252 $iconList .= "</div><div class=\"clearer\"></div>";
00253 }
00254
00255 $iconList .= "<h3>CMS icons</h3>";
00256 $iconList .= getListOfFiles($dir,true);
00257
00258
00259 $iconList .= "</div>";
00260 return $iconList;
00261 }
00262
00263
00264
00265
00266
00267
00268
00269
00270 function getListOfFiles($dir, $isTopLevel=false) {
00271 global $iconList;
00272 if(substr($dir,-1) != '/')
00273 $dir .= "/";
00274 $rootUri = hostURL();
00275 if($isTopLevel)
00276 $iconList = "";
00277 if(is_readable($dir)) {
00278 $handle = scandir($dir);
00279 foreach($handle as $item) {
00280 if($item != '.' && $item != '..' && $item[0]!=".") {
00281 if(is_dir($dir.$item))
00282 getListOfFiles($dir.$item);
00283 else {
00284 if(is_readable($dir.$item)) {
00285 $type = explode("/",mime_content_type($dir.$item));
00286 if($type[0] == "image") {
00287 $iconList .= "<div class=\"dragme\" draggable=\"true\" ondragstart=\"dragStartHandler(event,this)\" onclick=\"selectIcon(event,this)\">";
00288 $iconList .= "<img title='$item' alt='$item' src='{$rootUri}/{$dir}{$item}' width=32 height=32 /></div>\n";
00289 }
00290 }
00291 }
00292 }
00293 }
00294 }
00295 return $iconList;
00296 }
00297
00298
00299 ?>