1<?php
2
3namespace WHMCS\Module\Widget;
4
5use App;
6use WHMCS\Carbon;
7use WHMCS\Module\AbstractWidget;
8use WHMCS\Session;
9
10/**
11 * ToDo Widget.
12 *
13 * @copyright Copyright (c) WHMCS Limited 2005-2021
14 * @license https://www.whmcs.com/eula/ WHMCS Eula
15 */
16class ToDo extends AbstractWidget
17{
18 protected $title = 'To-Do List';
19 protected $description = '';
20 protected $weight = 350;
21 protected $cache = false;
22 protected $requiredPermission = 'To-Do List';
23
24 public function getData()
25 {
26 if (App::getFromRequest('completedtodo')) {
27 $results = localApi('UpdateToDoItem', array('itemid' => App::getFromRequest('completedtodo'), 'adminid' => Session::get('adminid'), 'status' => 'Completed'));
28 }
29
30 $toDo = localAPI('GetToDoItems', array('status' => 'Incomplete', 'limitstart' => 0, 'limitnum' => 11));
31 return (isset($toDo['items']['item'])) ? $toDo['items']['item'] : [];
32 }
33
34 public function generateOutput($data)
35 {
36 $output = '';
37 foreach ($data as $key => $toDoItem) {
38
39 if ($key == 10) {
40 $output .= '<a href="todolist.php" class="view-more">View all To-Do list items...</a>';
41 continue;
42 }
43
44 $date = Carbon::createFromFormat('Y-m-d', $toDoItem['date']);
45 if ($toDoItem['duedate'] == '0000-00-00') {
46 $duedate = 'Never';
47 } else {
48 $duedate = Carbon::createFromFormat('Y-m-d', $toDoItem['duedate'])->diffForHumans();
49 }
50
51 $id = $toDoItem['id'];
52 $title = $toDoItem['title'];
53 $description = $toDoItem['description'];
54 $admin = $toDoItem['admin'];
55 $status = $toDoItem['status'];
56
57 if ($admin == Session::get('adminid')) {
58 $assigned = ' <i class="fas fa-user color-green" data-toggle="tooltip" data-placement="bottom" title="Assigned to you"></i>';
59 } elseif ($admin > 0) {
60 $assigned = ' <i class="fas fa-user color-cyan" data-toggle="tooltip" data-placement="bottom" title="Assigned to somebody else"></i>';
61 } else {
62 $assigned = ' <i class="fas fa-user color-grey" data-toggle="tooltip" data-placement="bottom" title="Unassigned"></i>';
63 }
64
65 $statusColor = 'default';
66 if ($status == 'Incomplete') {
67 $statusColor = 'danger';
68 } elseif ($status == 'New') {
69 $statusColor = 'warning';
70 } elseif ($status == 'Pending') {
71 $statusColor = 'success';
72 } elseif ($status == 'In Progress') {
73 $statusColor = 'info';
74 }
75 $status = ' <label class="label label-' . $statusColor . '">' . $status . '</label>';
76
77 $output .= '
78 <div class="item">
79 <div class="due">Due ' . $duedate . '</div>
80 <div>
81 <label>
82 <input type="checkbox" value="' . $id . '"> '
83 . '<a href="todolist.php?action=edit&id=' . $id . '">'
84 . $title
85 . '</a>'
86 . $status
87 . $assigned . '
88 </label>
89 </div>
90 </div>';
91 }
92
93 if (count($data) == 0) {
94 $output = '<div class="text-center">
95 No Incomplete To-Do Items.
96 <br /><br />
97 <a href="todolist.php" class="btn btn-primary btn-sm">Add a To-Do Item</a>
98 <br /><br />
99 </div>';
100 }
101
102 return <<<EOF
103<div class="widget-content-padded to-do-items">
104 {$output}
105</div>
106<script>
107jQuery(document).ready(function(){
108 jQuery('.to-do-items input').iCheck({
109 inheritID: true,
110 checkboxClass: 'icheckbox_flat-blue'
111 });
112 jQuery('.widget-todo').on('ifChecked', '.item input', function(event) {
113 refreshWidget('ToDo', 'refresh=1&completedtodo=' + $(this).val());
114 });
115});
116</script>
117<style>
118.to-do-items {
119 margin-top: -2px;
120 font-size: 0.9em;
121}
122.to-do-items .item {
123 margin: 2px 0 0 0;
124 padding: 3px 10px;
125 background-color: #f8f8f8;
126 line-height: 26px;
127}
128.to-do-items label {
129 margin-bottom: 0;
130 font-weight: normal;
131}
132.to-do-items .item .icheckbox_flat-blue {
133 margin-top: -2px;
134 margin-right: 5px;
135}
136.to-do-items .due {
137 float: right;
138 font-size: 0.85em;
139 color: #999;
140}
141.to-do-items .view-more {
142 display: block;
143 padding: 10px 0 0 0;
144 text-align: center;
145 text-decoration: underline;
146 font-size: 1em;
147}
148</style>
149EOF;
150 }
151}
152