Welcome to mirror list, hosted at ThFree Co, Russian Federation.

goto.tmpl.php « templates - github.com/nextcloud/polls.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 6e680d67a7dd3a51c3f0408d5d48b37572457f39 (plain)
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
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
<?php

use \OCP\User;

\OCP\Util::addStyle('polls', 'main');
\OCP\Util::addStyle('polls', 'vote');
\OCP\Util::addScript('polls', 'vote');

$userId = $_['userId'];
$userMgr = $_['userMgr'];
$urlGenerator = $_['urlGenerator'];
$avaMgr = $_['avatarManager'];

$poll = $_['poll'];
$dates = $_['dates'];
$votes = $_['votes'];
$comments = $_['comments'];
$isAnonymous = $poll->getIsAnonymous() && $userId != $poll->getOwner();
$notification = $_['notification'];

if ($poll->getExpire() === null) {
    $expired = false;
} else {
    $expired = time() > strtotime($poll->getExpire());
}

if ($poll->getType() === '0') {
    // count how many times in each date
    $arr_dates = null;  // will be like: [21.02] => 3
    $arr_years = null;  // [1992] => 6
    foreach($dates as $d) {
        $day_month = date('d.m', strtotime($d->getDt()));
        $year = date('Y', strtotime($d->getDt()));

        if (isset($arr_dates[$day_month])) {
            $arr_dates[$day_month] += 1;
        } else {
            $arr_dates[$day_month] = 1;
        }

        if (isset($arr_years[$year])) {
            $arr_years[$year] += 1;
        } else {
            $arr_years[$year] = 1;
        }
    }

    $for_string_dates = '';
    foreach (array_keys($arr_dates) as $dt) {
        $for_string_dates .= '<th colspan="' . $arr_dates[$dt] . '" class="bordered">' . $dt . '</th>';
    }

    $for_string_years = '';
    foreach (array_keys($arr_years) as $year) {
        $for_string_years .= '<th colspan="' . $arr_years[$year] . '" class="bordered">' . $year . '</th>';
    }
}
if ($poll->getDescription() !== null && $poll->getDescription() !== '') {
    $description = nl2br($poll->getDescription());
} else {
    $description = $l->t('No description provided.');
}

// init array for counting 'yes'-votes for each date
$total_y = array();
$total_n = array();
for ($i = 0 ; $i < count($dates) ; $i++) {
    $total_y[$i] = 0;
    $total_n[$i] = 0;
}
$user_voted = array();

$pollUrl = $urlGenerator->linkToRouteAbsolute('polls.page.goto_poll', ['hash' => $poll->getHash()]);
?>

<div id="app">
    <div id="app-content">
        <div id="app-content-wrapper">
            <?php if(!User::isLoggedIn()) : ?>
                <div class="row">
                    <div class="col-100">
                        <div class="alert-info">
                            <?php
                                p($l->t('Already have an account?'));
                                $loginUrl = OCP\Util::linkToAbsolute('', 'index.php' ) . '?redirect_url=' . $urlGenerator->linkToRoute('polls.page.goto_poll', ['hash' => $poll->getHash()]);
                            ?>
                            <a href="<?php p($loginUrl); ?>"><?php p($l->t('Login')); ?></a>
                        </div>
                    </div>
                </div>
            <?php endif; ?>
            <header class="row">
                <div class="col-100">
                    <h1><?php p($poll->getTitle()); ?></h1>
                    <div class="wordwrap desc"><?php print_unescaped($description); ?></div>
                </div>
            </header>
            <div class="row">
                <div class="col-70">
                    <h2><?php p($l->t('Poll')); ?></h2>
                    <div class="scroll_div">
                        <table class="vote_table" id="id_table_1">
                            <thead>
                                <tr>
                                    <?php
                                    if ($poll->getType() === '0') {
                                        print_unescaped('<th rowspan=3></th>');
                                        print_unescaped($for_string_years);
                                        print_unescaped('<th class="bordered" rowspan=3>' . $l->t('All') . '</th>');
                                    } else {
                                        print_unescaped('<th></th>');
                                        foreach ($dates as $el) {
                                            print_unescaped('<th title="' . $el->getText(). '" class="bordered">' . $el->getText() . '</th>');
                                        }
                                        print_unescaped('<th class="bordered">' . $l->t('All') . '</th>');
                                    }
                                    ?>
                                </tr>
                                <?php
                                if ($poll->getType() === '0'){
                                    print_unescaped('<tr>' .  $for_string_dates . '</tr><tr>');
                                    $prev = "";
                                    for ($i = 0; $i < count($dates); $i++) {
                                        $c = ($prev != date('Y-m-d', strtotime($dates[$i]->getDt())) ? ' bordered' : '');
                                        $prev = date('Y-m-d', strtotime($dates[$i]->getDt()));
                                        $ch_obj = date('H:i', strtotime($dates[$i]->getDt()));
                                        print_unescaped('<th class="time-slot-cell' . $c . '">' . $ch_obj . '</th>');
                                        
                                    }
                                    print_unescaped('</tr>');
                                }
                                ?>
                            </thead>
                            <tbody class="votes">
                                <?php
                                if ($votes !== null) {
                                    //group by user
                                    $others = array();
                                    foreach ($votes as $vote) {
                                        if (!isset($others[$vote->getUserId()])) {
                                            $others[$vote->getUserId()] = array();
                                        }
                                        array_push($others[$vote->getUserId()], $vote);
                                    }
                                    $userCnt = 0;
                                    foreach (array_keys($others) as $usr) {
                                        $userCnt++;
                                        if ($usr === $userId) {
                                            // if poll expired, just put current user among the others;
                                            // otherwise skip here to add current user as last row (to vote)
                                            if (!$expired) {
                                                $user_voted = $others[$usr];
                                                continue;
                                            }
                                        }
                                        print_unescaped('<tr>');
                                        if($userMgr->get($usr) != null && !$isAnonymous) {
                                            print_unescaped('<th class="user-cell">');
                                            $avatar = $avaMgr->getAvatar($usr)->get(32);
                                            if($avatar !== false) {
                                                print_unescaped('<img class="userNameImg" src="data:' . $avatar->mimeType() . ';base64,' . $avatar . '" />');
                                            } else {
                                                print_unescaped('<div class="userNameImg noAvatar" style="background-color:' . getHsl($usr) . ';">' . strtoupper($usr[0]) . '</div>');
                                            }
                                            p($userMgr->get($usr)->getDisplayName());
                                        } else {
                                            if($isAnonymous) {
                                                print_unescaped('<th class="user-cell anonymous">');
                                                p($l->t('Participent') . ' ' . $userCnt);
                                            } else {
                                                print_unescaped('<th class="user-cell external">'. $usr);
                                            }
                                        }
                                        print_unescaped('</th>');

                                        // loop over dts
                                        $i_tot = 0;
                                        foreach($dates as $dt) {
                                            if ($poll->getType() === '0') {
                                                $date_id = strtotime($dt->getDt());
                                            } else {
                                                $date_id = $dt->getText();
                                            }
                                            // look what user voted for this dts
                                            $found = false;
                                            foreach ($others[$usr] as $vote) {
                                                $voteVal = null;
                                                if($poll->getType() === '0') {
                                                    $voteVal = strtotime($vote->getDt());
                                                } else {
                                                    $voteVal = $vote->getText();
                                                }
                                                if ($date_id === $voteVal) {
                                                    if ($vote->getType() === '1') {
                                                        $cl = 'poll-cell-is';
                                                        $total_y[$i_tot]++;
                                                    } else if ($vote->getType() === '0') {
                                                        $cl = 'poll-cell-not';
                                                        $total_n[$i_tot]++;
                                                    } else {
                                                        $cl = 'poll-cell-maybe';
                                                    }
                                                    $found = true;
                                                    break;
                                                }
                                            }
                                            if(!$found) {
                                                $cl = 'poll-cell-un';
                                            }
                                            print_unescaped('<td class="' . $cl . '"></td>');
                                            $i_tot++;
                                        }
                                        print_unescaped('<td></td>');
                                        print_unescaped('</tr>');
                                    }
                                }
                                $total_y_others = array_merge(array(), $total_y);
                                $total_n_others = array_merge(array(), $total_n);
                                if (!$expired) {
                                    print_unescaped('<tr class="current-user">');
                                    if (User::isLoggedIn()) {
                                        print_unescaped('<th class="user-cell">');
                                        $avatar = $avaMgr->getAvatar($userId)->get(32);
                                        if($avatar !== false) {
                                            print_unescaped('<img class="userNameImg" src="data:' . $avatar->mimeType() . ';base64,' . $avatar . '" />');
                                        } else {
                                            print_unescaped('<div class="userNameImg noAvatar" style="background-color:' . getHsl($userId) . ';">' . strtoupper($userId[0]) . '</div>');
                                        }
                                        p($userMgr->get($userId)->getDisplayName());
                                        print_unescaped('</th>');
                                    } else {
                                        print_unescaped('<th id="id_ac_detected" class="external current-user"><input type="text" name="user_name" id="user_name" placeholder="' . $l->t('Your name here') . '" /></th>');
                                    }
                                    $i_tot = 0;
                                    foreach ($dates as $dt) {
                                        if ($poll->getType() === '0') {
                                            $date_id = strtotime($dt->getDt());
                                        } else {
                                            $date_id = $dt->getText();
                                        }
                                        // see if user already has data for this event
                                        $cl = 'poll-cell-active-un';
                                        if (isset($user_voted)) {
                                            foreach ($user_voted as $obj) {
                                                $voteVal = null;
                                                if($poll->getType() === '0') {
                                                    $voteVal = strtotime($obj->getDt());
                                                } else {
                                                    $voteVal = $obj->getText();
                                                }
                                                if ($voteVal === $date_id) {
                                                    if ($obj->getType() === '1') {
                                                        $cl = 'poll-cell-active-is';
                                                        $total_y[$i_tot]++;
                                                    } else if ($obj->getType() === '0') {
                                                        $cl = 'poll-cell-active-not';
                                                        $total_n[$i_tot]++;
                                                    } else if($obj->getType() === '2'){
                                                        $cl = 'poll-cell-active-maybe';
                                                    }
                                                    break;
                                                }
                                            }
                                        }
                                        print_unescaped('<td class="cl_click ' . $cl . '" id="' . $date_id . '"></td>');
                                        $i_tot++;
                                    }
                                    print_unescaped('<td class="toggle-all selected-maybe"></td></tr>');
                                }
                                ?>
                            </tbody>
                            <tbody class="total">
                                <?php
                                    $diff_array = $total_y;
                                    for($i = 0 ; $i < count($diff_array) ; $i++) {
                                        $diff_array[$i] = ($total_y[$i] - $total_n[$i]);
                                    }
                                    $max_votes = max($diff_array);
                                ?>
                                <tr>
                                    <th><?php p($l->t('Total')); ?></th>
                                    <?php for ($i = 0 ; $i < count($dates) ; $i++) : ?>
                                        <td class="total">
                                            <?php
                                            $classSuffix = $poll->getType() === '0' ? strtotime($dates[$i]->getDt()) : str_replace(' ', '_', $dates[$i]->getText());
                                            if (isset($total_y[$i])) {
                                                $val = $total_y[$i];
                                            } else {
                                                $val = 0;
                                            }
                                            ?>
                                            <div id="id_y_<?php p($classSuffix); ?>" class="color_yes" data-value=<?php p(isset($total_y_others[$i]) ? $total_y_others[$i] : '0'); ?>>
                                                <?php p($val); ?>
                                            </div>
                                            <div id="id_n_<?php p($classSuffix); ?>" class="color_no" data-value=<?php p(isset($total_n_others[$i]) ? $total_n_others[$i] : '0'); ?>>
                                                <?php p(isset($total_n[$i]) ? $total_n[$i] : '0'); ?>
                                            </div>
                                        </td>
                                    <?php endfor; ?>
                                    <td></td>
                                </tr>
                                <tr>
                                    <th><?php p($l->t('Best option')); ?></th>
                                    <?php
                                    for ($i = 0; $i < count($dates); $i++) {
                                        $check = '';
                                        if ($total_y[$i] - $total_n[$i] === $max_votes){
                                            $check = 'icon-checkmark';
                                        }
                                        print_unescaped('<td class="win_row ' . $check . '" id="id_total_' . $i . '"></td>');
                                    }
                                    ?>
                                    <td class="bordered"></td>
                                </tr>
                            </tbody>
                            <tfoot>
                                <?php
                                if ($poll->getType() === '0') {
                                    print_unescaped('<tr><th rowspan=3></th>');
                                    $prev = "";
                                    for ($i = 0; $i < count($dates); $i++) {
                                        $c = ($prev != date('Y-m-d', strtotime($dates[$i]->getDt())) ? ' bordered' : '');
                                        $prev = date('Y-m-d', strtotime($dates[$i]->getDt()));
                                        $ch_obj = date('H:i', strtotime($dates[$i]->getDt()));
                                        print_unescaped('<th class="time-slot-cell' . $c . '">' . $ch_obj . '</th>');
                                    }
                                    print_unescaped('<th rowspan=3 class="bordered">' . $l->t('All') . '</th></tr>');
                                    print_unescaped('<tr>' .  $for_string_dates . '</tr>');
                                }
                                ?>
                                <tr>
                                    <?php
                                    if ($poll->getType() === '0') {
                                        print_unescaped($for_string_years);
                                    } else {
                                        print_unescaped('<th></th>');
                                        foreach ($dates as $el) {
                                            print_unescaped('<th title="' . $el->getText() . '" class="bordered">' . $el->getText() . '</th>');
                                        }
                                        print_unescaped('<th class="bordered"></th>');
                                    }
                                    ?>
                                </tr>
                            </tfoot>
                        </table>
                    </div>
                    <div class="input-group share">
                        <div class="input-group-addon">
                            <span class="icon-share"></span><?php p($l->t('Link')); ?>
                        </div>
                        <input type="text" value="<?php p($pollUrl);?>" readonly="readonly">
                    </div>
                    <?php if(User::isLoggedIn()) : ?>
                        <p>
                            <input type="checkbox" id="check_notif" <?php if($notification !== null) print_unescaped(' checked'); ?> />
                            <label for="check_notif"><?php p($l->t('Receive notification email on activity')); ?></label>
                        </p>
                    <?php endif; ?>

                    <form name="finish_vote" action="<?php p($urlGenerator->linkToRoute('polls.page.insert_vote')); ?>" method="POST">
                        <input type="hidden" name="pollId" value="<?php p($poll->getId()); ?>" />
                        <input type="hidden" name="userId" value="<?php p($userId); ?>" />
                        <input type="hidden" name="dates" value="<?php p($poll->getId()); ?>" />
                        <input type="hidden" name="types" value="<?php p($poll->getId()); ?>" />
                        <input type="hidden" name="notif" />
                        <input type="hidden" name="changed" />
                        <input type="button" id="submit_finish_vote" value="<?php p($l->t('Vote!')); ?>" />
                        <?php if(User::isLoggedIn()) : ?>
                            <a href="<?php p($urlGenerator->linkToRoute('polls.page.index')); ?>" class="button home-link"><?php p($l->t('Polls summary')); ?></a>
                        <?php endif; ?>
                    </form>


                    <?php if($expired) : ?>
                        <div id="expired_info">
                            <h2><?php p($l->t('Poll expired')); ?></h2>
                            <p>
                                <?php p($l->t('The poll expired on %s. Voting is disabled, but you can still comment.', array(date('d.m.Y H:i', strtotime($poll->getExpire()))))); ?>
                            </p>
                        </div>
                    <?php endif; ?>
                </div>
                <div class="col-30">
                    <h2><?php p($l->t('Comments')); ?></h2>
                    <div class="comments">
                        <div class="comment new-comment">
                            <form name="send_comment" action="<?php p($urlGenerator->linkToRoute('polls.page.insert_comment')); ?>" method="POST">
                                <input type="hidden" name="pollId" value="<?php p($poll->getId()); ?>" />
                                <input type="hidden" name="userId" value="<?php p($userId); ?>" />
                                <div class="comment-content">
                                <?php if(!User::isLoggedIn()) : ?>
                                    <!--<?php
                                    p($l->t('You must be logged in to post a comment.'));
                                    ?>-->
                                    <a href="<?php p($loginUrl); ?>"><?php p($l->t('Login')); ?></a>
                                    <?php p($l->t('or')); ?>
                                    <?php print_unescaped('<th id="id_ac_detected" class="external current-user"><input type="text" name="user_name_comm" id="user_name_comm" placeholder="' . $l->t('Your name here') . '" /></th>'); ?>
                                <?php else: ?>
                                    <?php p($l->t('Logged in as') . ' ' . $userId); ?>
                                <?php endif; ?>
                                    <textarea id="commentBox" name="commentBox"></textarea>
                                    <p>
                                        <input type="button" id="submit_send_comment" value="<?php p($l->t('Send!')); ?>" />
                                        <span class="icon-loading-small" style="float:right;"></span>
                                    </p>
                                </div>
                            </form>
                        </div>
                        <?php if($comments !== null) : ?>
                            <?php foreach ($comments as $comment) : ?>
                                <div class="comment">
                                    <div class="comment-header">
                                        <?php
                                        print_unescaped('<span class="comment-date">' . date('d.m.Y H:i:s', strtotime($comment->getDt())) . '</span>');
                                        if($isAnonymous) {
                                            p('Anonymous');
                                        } else {
                                            if($userMgr->get($comment->getUserId()) != null) {
                                                p($userMgr->get($comment->getUserId())->getDisplayName());
                                            } else {
                                                print_unescaped('<i>');
                                                p($comment->getUserId());
                                                print_unescaped('</i>');
                                            }
                                        }
                                        ?>
                                    </div>
                                    <div class="wordwrap comment-content">
                                        <?php p($comment->getComment()); ?>
                                    </div>
                                </div>
                            <?php endforeach; ?>
                        <?php else : ?>
                            <?php p($l->t('No comments yet. Be the first.')); ?>
                        <?php endif; ?>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<?php
//adapted from jsxc.chat
function getHsl($str) {
    $hash = 0;
    for($i=0; $i<strlen($str); $i++) {
        $utf16_char = mb_convert_encoding($str[$i], "utf-16", "utf-8");
        $char = hexdec(bin2hex($utf16_char));
        $hash = (($hash << 5) - $hash) + $char;
        $hash |= 0; // Convert to 32bit integer
    }
    $hue = abs($hash) % 360;
    $saturation = 90;
    $lightness = 65;
    return 'hsl(' . $hue . ', ' . $saturation . '%, ' . $lightness . '%)';
}
?>