~sit-developers/sit/master

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
<?php
// browse_feedback.php - View a list of feedback
//
// SiT (Support Incident Tracker) - Support call tracking system
// Copyright (C) 2010-2014 The Support Incident Tracker Project
// Copyright (C) 2000-2009 Salford Software Ltd. and Contributors
//
// This software may be used and distributed according to the terms
// of the GNU General Public License, incorporated herein by reference.
//

// by Ivan Lucas <ivanlucas[at]users.sourceforge.net>, June 2004

require ('core.php');
$permission = PERM_FEEDBACK_VIEW; // View Feedback
require (APPLICATION_LIBPATH . 'functions.inc.php');
// This page requires authentication
require (APPLICATION_LIBPATH . 'auth.inc.php');

$title = $strBrowseFeedback;
include (APPLICATION_INCPATH . 'htmlheader.inc.php');

// External variables
$formid = clean_int($_REQUEST['id']);
$responseid = clean_int($_REQUEST['responseid']);
$sort = clean_fixed_list($_REQUEST['sort'], array('','created','contactid','incidentid'));
$order = clean_fixed_list($_REQUEST['order'], array('','ASC','DESC','a','d'));
$mode = clean_fixed_list($_REQUEST['mode'], array('','viewresponse'));
$completed = clean_fixed_list($_REQUEST['completed'], array('','yes','no'));

switch ($mode)
{
    case 'viewresponse':
        echo "<h2>".icon('contract', 32)." {$strFeedback}</h2>";
        $sql = "SELECT contactid, completed, incidentid, formid, created FROM `{$dbFeedbackRespondents}` WHERE id='{$responseid}'";
        $result = mysql_query($sql);
        if (mysql_error()) trigger_error(mysql_error(), E_USER_WARNING);
        $response = mysql_fetch_object($result);
        if ($response->completed == 'yes')
        {
            $responsecompleted = $strYes;
        }
        else
        {
            $responsecompleted = $strNo;
        }
        echo "<table class='vertical maintable'>";
        echo "<tr><th>{$strContact}</th><td>{$response->contactid} - ".contact_realname($response->contactid)."</td></tr>\n";
        echo "<tr><th>{$strIncident}</th><td>".html_incident_popup_link($response->incidentid, "{$response->incidentid} - ".incident_title($response->incidentid))."</td></tr>\n";
        echo "<tr><th>{$strForm}</th><td>{$response->formid} - ".db_read_column('name', $dbFeedbackForms, $response->formid)." </td></tr>\n";
        echo "<tr><th>{$strDate}</th><td>{$response->created}</td></tr>\n";
        echo "<tr><th>{$strCompleted}</th><td>{$responsecompleted}</td></tr>\n";
        echo "</table>\n";

        echo "<h3>{$strResponsesToFeedbackForm}</h3>";
        $numquestions=0;

        // Return Ratings
        $qsql = "SELECT id, taborder, question FROM `{$dbFeedbackQuestions}` WHERE formid='{$response->formid}' AND type='rating' ORDER BY taborder";
        $qresult = mysql_query($qsql);
        if (mysql_error()) trigger_error(mysql_error(), E_USER_WARNING);

        if (mysql_num_rows($qresult) >= 1)
        {
            $html .= "<table class='maintable vertical'>";

            $numresults = 0;
            $cumul = 0;
            $numquestions++;
            $average = 0;
            $statquestions = 0;

            while ($qrow = mysql_fetch_object($qresult))
            {
                $html .= "<tr><th>Q{$qrow->taborder}: {$qrow->question}</th>";
                $sql = "SELECT r.result FROM `{$dbFeedbackRespondents}` AS f, `{$dbIncidents}` AS i, `{$dbUsers}` AS u, `{$dbFeedbackResults}` AS r ";
                $sql .= "WHERE f.incidentid=i.id ";
                $sql .= "AND i.owner=u.id ";
                $sql .= "AND f.id=r.respondentid ";
                $sql .= "AND r.questionid='{$qrow->id}' ";
                $sql .= "AND f.id='$responseid' ";
                $sql .= "AND f.completed = 'yes' \n";
                $sql .= "ORDER BY i.owner, i.id";
                $result = mysql_query($sql);
                if (mysql_error()) trigger_error(mysql_error(), E_USER_WARNING);
                while ($row = mysql_fetch_object($result))
                {
                    $numresults++;
                    if (!empty($row->result) OR ($row->result == 0))
                    {

                        if ($row->result != 0)
                        {
                            $cumul += $row->result;
                            $html .= "<td>" . $row->result . "</td></tr>";
                            $statquestions++;
                        }
                        else
                        {
                             $html .= "<td>{$strNoAnswerGiven}</td></tr>";
                        }
                    }
                }

                $calcnumber = (100 / ($CONFIG['feedback_max_score'] - 1));

                if ($statquestions>0)
                {
                    $average = number_format(($cumul / $statquestions), 2);
                    $percent = number_format((($calcnumber * ($cumul-$statquestions)) / $statquestions), 2);
                }

            }
            $html .= "</table>\n";
            $html .= "<p align='center'>{$strPositivity}: {$average} <strong>({$percent}%)</strong></p>";
            $html .= "<p align='center'>{$strAnswered}: <strong>{$statquestions}</strong>/{$numresults}</p>";
        }

        // Return text/options/multioptions fields
        $qsql = "SELECT id, taborder, question FROM `{$dbFeedbackQuestions}` WHERE formid='{$response->formid}' AND type='text' OR type='options' OR type='multioptions' ORDER BY taborder";
        $qresult = mysql_query($qsql);
        if (mysql_error()) trigger_error(mysql_error(), E_USER_WARNING);

        if (mysql_num_rows($qresult) >= 1)
        {
            while ($qrow = mysql_fetch_object($qresult))
            {

                $sql = "SELECT r.result FROM `{$dbFeedbackRespondents}` AS f, `{$dbIncidents}` AS i, `{$dbUsers}` AS u, `{$dbFeedbackResults}` AS r ";
                $sql .= "WHERE f.incidentid = i.id ";
                $sql .= "AND i.owner = u.id ";
                $sql .= "AND f.id = r.respondentid ";
                $sql .= "AND r.questionid = '{$qrow->id}' ";
                $sql .= "AND f.id = '{$responseid}' ";
                $sql .= "AND f.completed = 'yes' \n";
                $sql .= "ORDER BY i.owner, i.id";
                $result = mysql_query($sql);
                if (mysql_error()) trigger_error(mysql_error(), E_USER_WARNING);
                while ($row = mysql_fetch_object($result))
                {
                    $html .= "<p align='center'><strong>Q{$qrow->taborder}: {$qrow->question}</strong></p>";
                    if (!empty($row->result))
                    {
                        $html .= "<p align='center'>{$row->result}</p>";
                    }
                    else
                    {
                        $html .= "<p align='center'><em>{$strNoAnswerGiven}</em></p>";
                    }
                }
            }

            $surveys += $numresults;

            //if ($total_average>0)
            echo $html;
            echo "\n\n\n<!-- {$surveys} -->\n\n\n";
        }
        else
        {
            echo "<table class='maintable vertical'>";
            echo "<tr><td>";
            echo user_alert($strNoResponseFound, E_USER_NOTICE);
            echo "</td></tr></table>";
        }
        plugin_do('feedback_browse_viewresponse');
        echo "<p class='return'><a href='{$_SERVER['PHP_SELF']}'>{$strBackToList}</a></p>";
        break;
    default:
        $sql = "SELECT name FROM `{$dbFeedbackForms}`";
        $result = mysql_query($sql);
        if (mysql_error()) trigger_error(mysql_error(), E_USER_WARNING);
        $fresult = mysql_fetch_object($result);

        if (mysql_num_rows($result) == 0)
        {
            // no feedback forms
            echo "<h3>{$title}</h3>";
            echo user_alert($strNoFeedbackFormsDefined, E_USER_NOTICE);
            echo "<p align='center'><a href='feedback_form_edit.php?action=new'>{$strCreateNewForm}</a></p>";
        }
        else
        {
            if (empty($formid) AND !empty($CONFIG['feedback_form'])) $formid = $CONFIG['feedback_form'];
            else $formid = 1;

            $sql  = "SELECT formid, contactid, incidentid, email, multi, completed, ";
            $sql .= "fr.created as respcreated, fr.id AS respid FROM `{$dbFeedbackRespondents}` AS fr, `{$dbFeedbackForms}` AS ff ";
            $sql .= "WHERE fr.formid = ff.id ";
            if ($completed == 'no') $sql .= "AND completed='no' ";
            else $sql .= "AND completed='yes' ";
            if (!empty($formid)) $sql .= "AND formid='{$formid}'";

            if ($order == 'a' OR $order == 'ASC' OR $order == '') $sortorder = "ASC";
            else $sortorder = "DESC";

            switch ($sort)
            {
                case 'created':
                    $sql .= " ORDER BY fr.created {$sortorder}";
                    break;
                case 'contactid':
                    $sql .= " ORDER BY contactid {$sortorder}";
                    break;
                case 'incidentid':
                    $sql .= " ORDER BY incidentid {$sortorder}";
                    break;
                default:
                    $sql .= " ORDER BY fr.created DESC";
                    break;
            }
            $result = mysql_query($sql);
            if (mysql_error()) trigger_error(mysql_error(), E_USER_WARNING);

            $countrows = mysql_num_rows($result);

            if (!empty($formid))
            {
                if ($completed == 'no') echo "<h3>{$strFeedbackRequested}: {$formid} </h3>";
                else echo "<h3>{$strResponsesToFeedbackForm}: {$formid} - {$fresult->name}</h3>";
                echo "<p align='center'><a href='feedback_form_edit.php?formid={$formid}'>{$strEdit}</a></p>";
            }
            else
            {
                echo "<h3>{$strResponsesToAllFeedbackForms}</h3>";
            }
            plugin_do('feedback_browse');

            if ($countrows >= 1)
            {
                echo "<table summary='feedback forms' width='95%' align='center'>";
                echo "<tr>";
                echo colheader('created', $strDate, $sort, $order, $filter);
                echo colheader('contactid', $strContact,$sort, $order, $filter);
                echo colheader('incidentid', $strIncident,$sort, $order, $filter);
                echo "<th>{$strActions}</th>";
                echo "</tr>\n";
                $shade = 'shade1';
                while ($resp = mysql_fetch_object($result))
                {
                    $hashcode = feedback_hash($resp->formid, $resp->contactid, $resp->incidentid, contact_email($resp->contactid));
                    echo "<tr class='{$shade}'>";
                    echo "<td>".ldate($CONFIG['dateformat_datetime'], mysqlts2date($resp->respcreated))."</td>";
                    echo "<td><a href='contact_details.php?id={$resp->contactid}' ";
                    echo "title='{$resp->email}'>".contact_realname($resp->contactid);
                    echo "</a> {$strFrom} <a href='site_details.php?id=".contact_siteid($resp->contactid)."'>".contact_site($resp->contactid)."</a> </td>";
                    echo "<td>".html_incident_popup_link($resp->incidentid, "{$strIncident} [{$resp->incidentid}]")." - ";
                    echo incident_title($resp->incidentid)."</td>";
                    $url = "feedback.php?ax={$hashcode}";
                    if ($resp->multi == 'yes') $url .= "&amp;rr=1";

                    echo "<td>";
                    if ($resp->completed == 'no') echo "<a href='{$url}' title='{$url}' target='_blank'>URL</a>";
                    $eurl = urlencode($url);
                    if ($resp->completed == 'no')
                    {
                        //if ($resp->remind<1) echo "<a href='formactions.php?action=remind&amp;id={$resp->respid}&amp;url={$eurl}&amp;ref={$eref}' title='Send a reminder by email'>Remind</a>";
                        //elseif ($resp->remind == 1) echo "<a href='formactions.php?action=remind&amp;id={$resp->respid}&amp;url={$eurl}&amp;ref={$eref}' title='Send a Second reminder by email'>Remind Again</a>";
                        //elseif ($resp->remind == 2) echo "<a href='formactions.php?action=callremind&amp;id={$resp->respid}&amp;url={$eurl}&amp;ref={$eref}' title='Send a Third reminder by phone call, click here when its done'>Remind by Phone</a>";
                        //else echo "<strike title='Already sent 3 reminders'>Remind</strike>";
                        //echo " &bull; ";
                        //echo "<a href='formactions.php?action=delete&amp;id={$resp->respid}' title='Remove this form'>Delete</a>";
                    }
                    else
                    {
                        echo "<a href='{$_SERVER['PHP_SELF']}?mode=viewresponse&amp;responseid={$resp->respid}'>{$strViewResponse}</a>";
                    }
                    echo "</td>";
                    echo "</tr>\n";
                    if ($shade == 'shade1') $shade = 'shade2';
                    else $shade = 'shade1';
                }
                echo "</table>\n";
                plugin_do('feedback_browse');
            }
            else
            {
                echo user_alert($strNoResponseFound, E_USER_NOTICE);
            }
            if ($completed == 'no')
            {
                $sql = "SELECT COUNT(id) FROM `{$dbFeedbackRespondents}` WHERE formid='{$formid}' AND completed='yes'";
                $result = mysql_query($sql);
                list($completedforms) = mysql_fetch_row($result);
                if ($completedforms > 0)
                {
                    echo "<p align='center'>".sprintf($strFeedbackFormsReturned, "<a href='{$_SERVER['PHP_SELF']}'>{$completedforms}</a>")."</p>";
                }
            }
            else
            {
                $sql = "SELECT COUNT(id) FROM `{$dbFeedbackRespondents}` WHERE formid='{$formid}' AND completed='no'";
                $result = mysql_query($sql);
                list($waiting) = mysql_fetch_row($result);
                if ($waiting > 0) echo "<p align='center'>".sprintf($strFeedbackFormsWaiting, "<a href='{$_SERVER['PHP_SELF']}?completed=no'>{$waiting}</a>")."</p>";
            }
        }
}
plugin_do('feedback_browse_endpage_extend');
include (APPLICATION_INCPATH . 'htmlfooter.inc.php');
?>