-
Notifications
You must be signed in to change notification settings - Fork 1
/
design.php
333 lines (302 loc) · 11 KB
/
design.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
<?php include('head.php');
/**
* Design page - Show individual design features, users, comments, and can now be updated if the design is a proposal
* Copyright (C) 2011-2012 Betaville
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
?>
<body>
<?php
// setup the basics
$designID = $_GET['id'];
// get the project information
//Display Project specific stuff
$designRequest = SERVICE_URL.'?section=design&request=findbyid&id='.$designID;
$designJSON = file_get_contents($designRequest,0,null,null);
$designOutput = json_decode($designJSON, true);
$design = $designOutput['design'];
$commentRequest = SERVICE_URL.'?section=comment&request=getforid&id='.$designID;
$commentJSON = file_get_contents($commentRequest,0,null,null);
$commentOutput = json_decode($commentJSON, true);
$comments = $commentOutput['comments'];
//Adding and deleting users in faveList
if(isset($_GET['unlike'])) {
//Service call is initiated from the function, need to first check if the user is in the list
DeletefaveListUser($design['designID'],$_SESSION['username']);
header('url='.WEB_URL.'/design.php?id='.$designID);
}
if(isset($_GET['like'])) {
//Check if user is in group, if is don't add
if(checkUserInfaveListGroup($_SESSION['username'],$design['designID'])==true) {
}
else {
$likeRequest = SERVICE_URL.'?section=fave&request=add&id='.$designID.'&name='.$_SESSION['username'].'&token='.$_SESSION['token'];
$likeRequestJSON = file_get_contents($likeRequest,0,null,null);
$likeOutput = json_decode($likeRequestJSON, true);
header('url='.WEB_URL.'/design.php?id='.$designID);
}
}
// check if the user has write access, includes users who are in group!
if(isset($_SESSION['token'])){
$accessRequest = SERVICE_URL.'?section=design&request=userhaswriteaccess&token='.$_SESSION['token'].'&id='.$designID;
$accessJSON = file_get_contents($accessRequest,0,null,null);
$accessOutput = json_decode($accessJSON, true);
$access = $accessOutput['userhaswriteaccess'];
if($access === true){
// the user has write access, include jQuery functionality
?>
<script>
$(document).ready(function(){
setClickable();
});
function setClickable(){
$('#project-description').click(function(){
var textarea = '<div><textarea placeholder="test" id="descriptionUpdateArea" rows="10" cols="60">'+$(this).html()+'</textarea>';
var button = '<div><input type="button" value="Save" class="saveButton" /> OR <input type="button" value="Cancel" class="cancelButton" /></div></div>';
var revert = $(this).html();
$(this).after(textarea+button).remove();
$('.saveButton').click(function(){saveChanges(this, false);});
$('.cancelButton').click(function(){saveChanges(this, revert);});
}).mouseover(function(){
$(this).addClass("editable");
}).mouseout(function(){
$(this).removeClass("editable");
});
/*
$('#project-description').mouseOver(function(){
$(this).addClass("editable");
});
$('#project-description').mouseOut(function(){
$(this).addClass("editable");
});
*/
};
function saveChanges(obj, cancel){
if(!cancel){
var updatedText = $('#descriptionUpdateArea').val();
var updateString = 'interact/update-design.php?groupy=<?php echo $_SESSION['username']; ?>&action=update&id=<?php echo $designID; ?>&description='+updatedText;
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.open("GET",updateString,true);
xmlhttp.send();
window.location.reload();
}
else{
window.location.reload();
}
};
</script>
<?php
}
}
?>
<!-- Displaying Design Specific stuff -->
<div class='master-container'>
<div class='page-container'>
<div class='page-body container project' id='project'>
<div class='project-container'>
<h1><?php echo $design['name']; ?></h1>
<?php
//Add User Functionality implemented on the design.php page, check if the design user is the user logged in.
if($_SESSION['username'] == $design['user']) {
//Web service request to check if the design is a proposal , if not do not implement the AddUser functionality.
$proposalRequest = SERVICE_URL.'?section=design&request=checkproposal&id='.$designID;
$proposalJSON = file_get_contents($proposalRequest,0,null,null);
$proposalOutput = json_decode($proposalJSON, true);
$proposal = $proposalOutput['checkdesign'];
if($proposal == true) { ?>
<a href = "edit-proposal-group.php?id=<?php echo $design['designID'];?>"> Add Users to Group </a>
<?php
}
}
?>
<div class='project-meta'>
<ul>
<li>
<strong>
Author
</strong>
<a href="profile.php?uName=<?php echo $design['user']; ?>"><?php echo $design['user']; ?></a>
</li>
<li>
<strong>
Last Update
</strong>
<?php
// instead of pulling the database field we pass the it to a function that returns a php date format and subtract it from the current time.
$updatedtime = fd($design['date']);
timediff($updatedtime);
?>
</li>
<li>
<span class='comment'>
<span class='count'>
<?php
// count the number of comments
$commentCount=0;
foreach($comments as $comment){
$commentCount++;
}
echo $commentCount;
?>
</span>
comments,
<span class='count'>
<?php
//Count the number of likes
$likeCount = countLikes($design['designID']);
echo $likeCount;
?>
</span>
likes
</span>
</li>
</ul>
<script type="text/javascript">
function showmenu(elmnt){
document.getElementById(elmnt).style.visibility="visible";
}
function hidemenu(elmnt){
document.getElementById(elmnt).style.visibility="hidden";
}
</script>
<div class='button-row'>
<?php if(isset($_SESSION['logged'])) {
//Share the url on facebook or Twitter, grab the current page url......
$page_url=$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
?>
<!-The button now shows a drop down widget, click either option to be redirected-->
<a class='uberbutton green' onmouseover="showmenu('share_widget')" onmouseout="hidemenu('share_widget')">
Share
<tr bgcolor="#568617" width="50px">
<table class="share_menu" id="share_widget" width="15">
<tr><td class="share_menu"><a href="http://www.facebook.com/share.php?u=<?php echo $page_url;?>">Share on Facebook</a></td></tr>
<tr><td class="share_menu"><a href="http://twitter.com/home?status=<?php echo $page_url;?>">Share on Twitter</a></td></tr>
</table>
</td>
</tr>
</table>
</a>
<?
if(checkUserInfaveListGroup($_SESSION['username'],$design['designID'])==true) {
?>
<a class='uberbutton green' href='<?php echo 'design.php?id='.$design['designID'].'&unlike=true';?>' method = 'post'>
Unlike
<span class='icon'>♥</span>
</a>
<?php
}
else{
?>
<a class='uberbutton green' href='<?php echo 'design.php?id='.$design['designID'].'&like=true';?>' method = 'post'>
Like
<span class='icon'>♥</span>
</a><?
}
}
?>
<!-- Delete Design Functionality for Users -->
<?php if($_SESSION['username'] == $design['user']) {?>
<script type="text/javascript">
function confirmPost(){
var agree=confirm("Are you sure you want to Delete This Design?");
if (agree)
return true ;
else
return false ;
}
</script>
<!--Button does not look so good.......-->
<a class='uberbutton green'
a href ='<?php echo 'profile.php?designDeleted=true&id='.$design['designID'].'&designName='.urlencode($design['name']);?>' method='post' name='Delete' value='Delete' onClick='return confirmPost()'>
Delete
</a>
<?php
}?>
</div>
</div>
<div id='project-description' class='project-description'><?php echo $design['description']; ?></div>
<br />
<br />
<div>
<?php include('interact/map.php'); ?>
<script type="text/javascript">
$(document.getElementById('smallmapdiv')).ready(function() {
var lat = <?php echo $design['coordinate']['lat']; ?>;
var lon = <?php echo $design['coordinate']['lon']; ?>;
projectMap(lat, lon);
});
</script>
</div>
<div class='discussion'>
<h2>
Discussion
</h2>
<p>
<em>To comment, find this project in Betaville.</em>
</p>
<ul>
<?php
foreach($comments as $comment){
?>
<li>
<div class='discussion-meta column span-3'>
<?php echo '<a href="profile.php?uName='.$comment['user'].'" class="author">'.$comment['user'].'</a>'; ?>
<div class='timestamp'>
<?php echo $comment['date'] ?>
</div>
</div>
<div class='discussion-body column span-9 last'>
<?php echo $comment['comment'] ?>
</div>
</li>
<?php
}
?>
<?php if(isset($_SESSION['username'])){ ?>
<li>
<div class='discussion-meta column span-3'>
<a class='author'>Add Comment</a>
</div>
<div class='discussion-body column span-9 last'>
<form action="interact/submit-comment.php" method="post">
<textarea class="comment" name="commentText" cols="15" rows="2"></textarea>
<input type="hidden" name="designID" value=<?php echo $design['designID']?>>
<input type="submit" value="Send">
</form>
</div>
</li>
<?php } ?>
</ul>
</div>
</div>
<aside>
<?php
//Check if image exists on server
$image = checkimage(THUMBNAIL_URL.$design['designID'].'.png');
echo "<a href='design.php?id=".$design['designID']."'>\n"; ?>
<img src=<?php echo $image;?> style='background-color: #3e4b71'>
</aside>
</div>
</div>
<?php include('footer.php'); ?>
</div>
</body>
</html>