~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
<?php
// supportbycontract.php - Shows sites and their contracts
//
// 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.
//

// Author:   Ivan Lucas
// Email:    ivanlucas[at]users.sourceforge.net
// Comments: List supported contacts by contract

$title = $strSupportedContactsbySite;
$permission = PERM_CONTRACT_VIEW; /* View Maintenance Contracts */

require ('core.php');
require (APPLICATION_LIBPATH . 'functions.inc.php');

// This page requires authentication
require (APPLICATION_LIBPATH . 'auth.inc.php');

$siteid = clean_int($_REQUEST['siteid']);
$mode = clean_fixed_list($_REQUEST['mode'], array('','csv'));

if ($mode == 'csv')
{
    // --- CSV File HTTP Header
    header("Content-type: text/csv\r\n");
    header("Content-disposition-type: attachment\r\n");
    header("Content-disposition: filename=supported_contacts_by_contract.csv");
}
else
{
    include (APPLICATION_INCPATH . 'htmlheader.inc.php');
}

$sql = "SELECT *, s.name AS sitename FROM `{$dbSites}` AS s ";
if (!empty($_REQUEST['siteid'])) $sql .= "WHERE id='{$siteid}'";
else $sql .= "ORDER BY s.name";
$result = mysql_query($sql);
if (mysql_error()) trigger_error(mysql_error(), E_USER_WARNING);
if ($mode == 'csv')
{
    echo "{$strSite},{$strProduct},{$strLicense},{$strExpiryDate},{$strAllContacts},{$strEngineer} 1, {$strEngineer} 2, {$strEngineer} 3, {$strEngineer} 4\n";
}
while ($site = mysql_fetch_object($result))
{
    $msql  = "SELECT m.id AS maintid, m.term AS term, p.name AS product, r.name AS reseller, ";
    $msql .= "licence_quantity, l.name AS licence_type, expirydate, admincontact, c.forenames AS admincontactsforenames, ";
    $msql .= "c.surname AS admincontactssurname, m.notes AS maintnotes, m.allcontactssupported ";
    $msql .= "FROM `{$dbMaintenance}` AS m, `{$dbContacts}` AS c, `{$dbProducts}` AS p, `{$dbLicenceTypes}` AS l, `{$dbResellers}` AS r ";
    $msql .= "WHERE m.product=p.id ";
    $msql .= "AND m.reseller=r.id AND if(licence_type = 0, 4, ifnull(licence_type, 4)) = l.id AND admincontact = c.id ";
    $msql .= "AND m.site = '{$site->id}' ";
    $msql .= "AND m.term!='yes' ";
    $msql .= "AND m.expirydate > '$now' ";     $msql .= "ORDER BY expirydate DESC";

    $mresult = mysql_query($msql);
    if (mysql_num_rows($mresult)>=1)
    {
        if ($mode == 'csv')
        {
            while ($maint = mysql_fetch_object($mresult))
            {
                if ($maint->expirydate > $now AND $maint->term != 'yes')
                {
                    echo "{$site->sitename},";
                    echo "{$maint->product},";
                    echo "{$maint->licence_quantity} {$maint->licence_type},";
                    echo ldate($CONFIG['dateformat_date'], $maint->expirydate).",";

                    if ($maint->allcontactssupported == 'yes') echo "{$strYes},";
                    else echo "{$strNo},";

                    $csql  = "SELECT * FROM `{$dbSupportContacts}` ";
                    $csql .= "WHERE maintenanceid='{$maint->maintid}' ";
                    $csql .= "ORDER BY contactid LIMIT 4";
                    $cresult = mysql_query($csql);
                    if (mysql_error()) trigger_error(mysql_error(), E_USER_WARNING);
                    while ($contact = mysql_fetch_object($cresult))
                    {
                        echo contact_realname($contact->contactid).",";
                    }
                    echo "\n";
                    $a++;
                }
            }
        }
        else
        {
            echo "<h2>{$site->sitename}</h2>";
            echo "<table width='100%'>";
            echo "<tr><th style='text-align: left;'>{$strProduct}</th>";
            echo "<th style='text-align: left;'>{$strLicense}</th>";
            echo "<th style='text-align: left;'>{$strExpiryDate}</th>";
            echo "<th style='text-align: left;'>{$strAllContacts}</th>";
            echo "<th style='text-align: left;'>{$strContact} 1</th>";
            echo "<th style='text-align: left;'>{$strContact} 2</th>";
            echo "<th style='text-align: left;'>{$strContact} 3</th>";
            echo "<th style='text-align: left;'>{$strContact} 4</th></tr>\n";
            while ($maint = mysql_fetch_object($mresult))
            {
                if ($maint->expirydate > $now AND $maint->term != 'yes')
                {
                    echo "<tr>";
                    echo "<td width='20%'>{$maint->product}</td>";
                    echo "<td>{$maint->licence_quantity} {$maint->licence_type}</td>";
                    echo "<td>".ldate($CONFIG['dateformat_date'], $maint->expirydate)."</td>";

                    echo "<td>";
                    if ($maint->allcontactssupported == 'yes') echo $strYes;
                    else echo $strNo;
                    echo "</td>";

                    $csql  = "SELECT * FROM `{$dbSupportContacts}` ";
                    $csql .= "WHERE maintenanceid='{$maint->maintid}' ";
                    $csql .= "ORDER BY contactid LIMIT 4";
                    $cresult = mysql_query($csql);
                    if (mysql_error()) trigger_error(mysql_error(), E_USER_WARNING);
                    while ($contact = mysql_fetch_object($cresult))
                    {
                        echo "<td>".contact_realname($contact->contactid)."</td>";
                    }
                    echo "</tr>\n";
                    $a++;
                }
            }
            echo "</table>";
            echo "<hr />";
        }
    }
}

if ($mode != 'csv')
{
    echo "<p align='center'><a href='{$_SERVER['PHP_SELF']}?siteid={$siteid}&amp;mode=csv'>{$strSaveAsCSV}</a></p>";
    include (APPLICATION_INCPATH . 'htmlfooter.inc.php');
}
?>