/
inc_announce.php
313 lines (251 loc) · 7.08 KB
/
inc_announce.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
<?php
/**
* eiseIntraAnnounce class
*
* set of static functions to display announcements on the main system page.
*
*
* @package eiseIntra
*
*/
class eiseIntraAnnounce {
private static $arrDefaultConfig = array( );
public static $actionsWrite = array('post'=>'addAnnounce', 'delete' => 'deleteAnnounce');
public static $actionsRead = array('get'=>'getAnnounces');
const nAnnouncesToGet = 25;
public static function announces($arrRolesPermitted, $arrConfig = array()){
GLOBAL $intra;
$oSQL = $intra->oSQL;
?>
<style type="text/css">
.eiseIntraAnnounce .overflow_scroll {
overflow-y: auto;
}
.eiseIntraAnnounce ul {
display: table;
width: 100%;
}
.eiseIntraAnnounce li {
display: table-row;
}
.eiseIntraAnnounce li > * {
display: table-cell;
}
.eiseIntraAnnounce form {
width: 100%;
}
.eiseIntraAnnounce form > * {
display: inline-block;
vertical-align: top;
}
/**
* decoration
*/
.eiseIntraAnnounce h1:first-letter, .eiseIntraAnnounce h2:first-letter, .eiseIntraAnnounce h3:first-letter, .eiseIntraAnnounce h4:first-letter {
text-transform: uppercase;
}
.eiseIntraAnnounce ul {
margin: 0;
}
.eiseIntraAnnounce .overflow_scroll {
border-top: 1px solid #333;
border-bottom: 1px solid #333;
}
.eiseIntraAnnounce form {
padding: 8px;
padding-top: 5px;
}
.eiseIntraAnnounce textarea {
width: 74%;
height: 2.3em;
}
.eiseIntraAnnounce input[type=submit] {
width: 24%;
background-color: rgb(217, 217, 217);
background-image: linear-gradient(rgb(248, 248, 248), rgb(217, 217, 217));
border: 2px outset rgb(192, 192, 192);
border-radius: 4px;
}
.ei_announce {
overflow: hidden;
padding: 2px 16px;
position: relative;
}
.eif_annFrom {
font-weight: bold;
float: left;
}
.eif_annDate {
color: #999;
font-weight: bold;
float: right;
}
.eif_annText {
margin-top: 1.1em;
padding: 3px 10px 1em;
white-space: pre;
}
.ei_btnDeleteAnnounce {
position: absolute;
top: 1.2em;
right: 16px;
width: 22px !important;
height: 22px !important;
padding: 0 !important;
display: none;
}
</style>
<div class="eiseIntraAnnounce">
<h3><?php echo $intra->translate('news') ?></h3>
<div class="overflow_scroll">
<ul>
<li class="eif_template eif_evenodd">
<div class="ei_announce">
<input type="hidden" class="eif_annID" name="eif_annID">
<div class="eif_annFrom">Ivan Ivanov</div>
<div class="eif_annDate">18 Feb</div>
<div class="eif_annText">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus condimentum felis eu erat lobortis, porta tempus ex auctor. Nunc consectetur pretium volutpat.</div>
</div>
</li>
<li class="eif_notfound">
<div>
<?php echo $intra->translate("no news today"); ?>
</div>
</li>
<li class="eif_spinner" style="display: none;"></li>
</ul>
</div>
<?php
if($intra->arrUsrData['FlagWrite']){
?>
<form action="<?php echo $_SERVER['PHP_SELF'] ?>" method="POST">
<input type="hidden" name="DataAction" value="<?php echo self::$actionsWrite['post'] ?>">
<textarea id="annText" name="annText"></textarea>
<input type="submit" id="btnAnnounceSubmit" value="<?php echo $intra->translate('post') ?>">
</form>
<?php
}
?>
</div>
<script type="text/javascript">
function toggleDeleteButton($ann){
var $btn = $ann.find('.ei_btnDeleteAnnounce');
if($btn[0]){
$btn.slideUp('slow').remove();
} else {
$btn = $('<input type="button">').addClass("ei_btnDeleteAnnounce").addClass("ss_sprite").addClass("ss_delete");
$btn.appendTo($ann)
.slideDown('slow')
.click(function(){
var annID = $ann.find('.eif_annID').val();
if(confirm('Sure?')){
$.getJSON(location.pathname+'?DataAction=deleteAnnounce&annID='+encodeURIComponent(annID)
, function(data){
if(data.status=='ok'){
MsgShow(data.message);
reloadAnnounces();
} else
MsgShow('ERROR:'+data.message);
})
}
});
}
}
function reloadAnnounces(){
var pathname = location.pathname;
var $annList = $('.eiseIntraAnnounce ul');
$annList.eiseIntraAJAX('fillTable', pathname+'?DataAction=getAnnounces', {afterFill: function(){
if($('.eiseIntraAnnounce form')[0])
$annList.find('.eif_loaded').each(function(){
var $ann = $(this).find('.ei_announce');
$ann.hover(function(){
window.setTimeout(function(){
toggleDeleteButton($ann);
}, 100)
})
});
adjustHeight();
}});
}
function adjustHeight(){
var wH = $(window).height();
var dH = $(document).height();
if(dH>wH){
var oT = $('.eiseIntraAnnounce .overflow_scroll').offset().top;
var formH = ($('.eiseIntraAnnounce form')[0] ? $('.eiseIntraAnnounce form').outerHeight(true) : 0);
var newH = wH - formH - oT;
$('.eiseIntraAnnounce .overflow_scroll').height(newH);
}
}
$(document).ready(function(){
$('.eiseIntraAnnounce form').submit(function(){
var text = $(this).find('textarea[name=annText]').val();
if(text.length>255){
alert ('You need to be more clever. Maximum size of text field is 255 symbols.');
return false;
}
$.ajax({
url : $(this).attr('action'),
type : $(this).attr('method'),
dataType: 'json',
data : $(this).serialize(),
success : function( data ) {
if(data.status=='ok'){
MsgShow(data.message);
reloadAnnounces();
}
else
MsgShow('ERROR:'+data.message);
},
error : function( xhr, err ) {
alert(err);
}
});
$(this).find('textarea[name=annText]').val('');
return false;
});
reloadAnnounces();
})
</script>
<?php
}
public static function dataAction($newData){
GLOBAL $intra;
$oSQL = $intra->oSQL;
switch($newData['DataAction']){
case 'addAnnounce':
if(!$newData['annText'])
$intra->json('error', $intra->translate('Empty announce'));
$oSQL->q('START TRANSACTION');
$sqlAnn = "INSERT INTO stbl_announce SET
annSubject = ".$oSQL->e($newData['annSubject'])."
, annText = ".$oSQL->e($newData['annText'])."
, annFlagDeleted = 0
, annInsertBy = '{$intra->usrID}', annInsertDate = NOW(), annEditBy = '{$intra->usrID}', annEditDate = NOW()";
$oSQL->q($sqlAnn);
$annID = $oSQL->i();
$oSQL->q('COMMIT');
$intra->json('ok', $intra->translate('Announce posted'), array('annID'=>$annID));
case 'deleteAnnounce':
$oSQL->q('START TRANSACTION');
$sqlAnn = "DELETE FROM stbl_announce WHERE annID=".(int)$newData['annID'];
$oSQL->q($sqlAnn);
$oSQL->q('COMMIT');
$intra->json('ok', $intra->translate('Announce is deleted'));
case 'getAnnounces':
$nAnnouncesToGet = (isset($newData['number']) ? $newData['number'] : self::nAnnouncesToGet);
$sqlAnn = "SELECT annID
, annSubject
, annText
, annInsertDate as annDate
, IFNULL(optText{$intra->local}, annInsertBy) as annFrom
FROM stbl_announce
LEFT OUTER JOIN svw_user ON optValue=annInsertBy
WHERE annFlagDeleted=0 ORDER BY annInsertDate DESC LIMIT 0,".(int)$nAnnouncesToGet;
$rsAnn = $oSQL->q($sqlAnn);
$arrAnn = $intra->result2JSON($rsAnn);
$intra->json('ok', '', $arrAnn);
}
}
}
?>