~budgester/irm/trunk

« back to all changes in this revision

Viewing changes to include/tracking.class.php

  • Committer: Martin N Stevens
  • Date: 2008-06-23 22:18:29 UTC
  • Revision ID: budgester@budgester.com-20080623221829-qalo1a1ml0gp1fon
Added create $DB connection at constructor time.

Slight modification to emailtracking

Show diffs side-by-side

added added

removed removed

Lines of Context:
86
86
        */
87
87
        function Tracking($ID=0)
88
88
        {
 
89
                #This should be picked up from parent class
 
90
                $this->userbase = Config::Absloc('users');
 
91
                $this->DB = Config::Database();
89
92
                $this->CommitError = _("Error committing Work Request. ");
90
93
 
91
94
                if($ID != 0)
148
151
                $user = $_REQUEST['user'];
149
152
                $minspent = $_REQUEST['minspent'];
150
153
 
151
 
                $DB = Config::Database();
152
 
 
153
154
                if($IDTYPE != "IRMID" && $IDTYPE != "GROUP")
154
155
                {
155
156
                        commonHeader(_("Tracking") . " - " . _("No IRM ID or Group name was selected"));
177
178
                if($IDTYPE == "IRMID")
178
179
                {
179
180
                        $query = "select COUNT(*) from computers where (ID=$ID)";
180
 
                        if ($DB->getOne($query) != 1)
 
181
                        if ($this->DB->getOne($query) != 1)
181
182
                        {
182
183
                                commonHeader(_("Tracking") . " - " . _("Bad IRM ID Number"));
183
184
                                __("It appears that you have enetered an invalid IRM computer ID");
197
198
                        $emailupdates = "no";
198
199
                }
199
200
 
200
 
                if($DB->getOne("SELECT closed FROM tracking_status WHERE status=".$DB->getTextValue($status)))
 
201
                if($this->DB->getOne("SELECT closed FROM tracking_status WHERE status=".$this->DB->getTextValue($status)))
201
202
                {
202
203
                        $closedate = date("Y-m-d H:i:s");
203
204
                        $emailupdates = "no";
248
249
                $AUTOFILL = $_REQUEST['autofill'];
249
250
 
250
251
                $query = "select * from fasttracktemplates where (ID=$AUTOFILL)";
251
 
                $DB = Config::Database();
252
 
                $result = $DB->getRow($query);
 
252
                $result = $this->DB->getRow($query);
253
253
                $name = $result["name"];
254
254
                $priority = $result["priority"];
255
255
                $request = $result["request"];
395
395
        }
396
396
 
397
397
        function getTrackingByPriority(){
398
 
                $DB = Config::Database();
399
398
                $query = "SELECT ID, status, assign, contents, priority FROM tracking WHERE (priority = '" . $this->Priority . "') AND (status !='complete') AND (status !='duplicate') AND (status != 'old')";
400
 
                $this->result = $DB->getAll($query);
 
399
                $this->result = $this->DB->getAll($query);
401
400
        }
402
401
 
403
402
        function displayAlert(){
604
603
        }
605
604
 
606
605
        function getTrackingForUser(){
607
 
                $DB = Config::Database();
608
 
 
609
606
                if (@$_REQUEST['sort'] && !preg_match('/^[a-zA-Z0-9_]+$/', $_REQUEST['sort']))
610
607
                {
611
608
                        trigger_error(sprintf(_("Invalid field name to sort by: %s"),@$_REQUEST['sort']), E_USER_ERROR);
613
610
                }
614
611
 
615
612
                $query = "SELECT advanced_tracking,tracking_order FROM prefs WHERE (user = '" . $this->UserName() . "')";
616
 
                $result = $DB->getRow($query);
 
613
                $result = $this->DB->getRow($query);
617
614
 
618
615
                $this->advanced_tracking = $result['advanced_tracking'];
619
616
                $tracking_order = $result["tracking_order"];
692
689
         */
693
690
        function retrieve()
694
691
        {
695
 
                $DB = Config::Database();
696
 
                $this->qID = $DB->getTextValue($this->ID);
 
692
                $this->qID = $this->DB->getTextValue($this->ID);
697
693
                
698
694
                $query = "SELECT * FROM tracking WHERE (ID=" . $this->qID . ")";
699
 
                $result = $DB->getRow($query);
 
695
                $result = $this->DB->getRow($query);
700
696
                if (count($result))
701
697
                {
702
698
                        $this->setDateEntered($result['date']);
768
764
         */
769
765
        function setStatus($Stat)
770
766
        {
771
 
                $DB = Config::Database();
772
 
 
773
767
                // This is fscking ugly.
774
 
                $wasclosed = $DB->getOne("SELECT closed FROM tracking_status WHERE status=".$DB->getTextValue($this->Status));
775
 
                $isclosed = $DB->getOne("SELECT closed FROM tracking_status WHERE status=".$DB->getTextValue($stat));
 
768
                $wasclosed = $this->DB->getOne("SELECT closed FROM tracking_status WHERE status=".$this->DB->getTextValue($this->Status));
 
769
                $isclosed = $this->DB->getOne("SELECT closed FROM tracking_status WHERE status=".$this->DB->getTextValue($stat));
776
770
                
777
771
                if (!$wasclosed && $isclosed)
778
772
                {
823
817
                        $query = "select * from computers where (ID=$CompID)";
824
818
                }
825
819
 
826
 
                $DB = Config::Database();
827
 
                $result = $DB->getRow($query);
 
820
                $result = $this->DB->getRow($query);
828
821
                $this->ComputerName = $result["name"];
829
822
        }
830
823
 
991
984
                        $Order = "tracking.$Order";
992
985
                }
993
986
 
994
 
                $DB = Config::Database();
995
 
 
996
987
                $sort = "ORDER BY $Order";
997
988
 
998
989
                if ($Advanced == "yes")
1032
1023
                        }
1033
1024
                        else if (preg_match('/^u:(.*)$/', $Show, $matches))
1034
1025
                        {
1035
 
                                $quser = $DB->getTextValue($matches[1]);
 
1026
                                $quser = $this->DB->getTextValue($matches[1]);
1036
1027
                                $where = "WHERE (tracking_status.closed = 0)
1037
1028
                                        AND (tracking_status.status=tracking.status)
1038
1029
                                        AND (tracking.assign = $quser)";
1055
1046
                                $where
1056
1047
                                $sort";
1057
1048
 
1058
 
                return $DB->getCol($query);
 
1049
                return $this->DB->getCol($query);
1059
1050
        }
1060
1051
        
1061
1052
        function getNotClosedBy($Order, $username = NULL)
1066
1057
                {
1067
1058
                        $username = $IRMName;
1068
1059
                }
1069
 
 
1070
 
                $DB = Config::Database();
1071
 
                $username = $DB->getTextValue($username);
 
1060
                $username = $this->DB->getTextValue($username);
1072
1061
 
1073
1062
                $sort = '';
1074
1063
                if (strtolower($Order) == 'asc')
1086
1075
                                                AND (author = $username)
1087
1076
                                        $sort";
1088
1077
 
1089
 
                return $DB->getCol($query);
 
1078
                return $this->DB->getCol($query);
1090
1079
        }
1091
1080
 
1092
1081
        function requestAge()
1125
1114
        function display($withFollowups = false)
1126
1115
        {
1127
1116
                global $IRMName;
 
1117
                $this->deviceSelection();
 
1118
 
1128
1119
                $this->readonly = true;
1129
 
                if($this->ID == 0)
1130
 
                {
 
1120
                if($this->ID == 0){
1131
1121
                        PRINT _("Error displaying Tracking: ") . _("ID is not set.")."<BR>\n";
1132
1122
                        return;
1133
1123
                }
1134
1124
 
1135
1125
                $user = new User();
1136
1126
                $authExists = $user->exists($this->Author);
1137
 
                if($authExists)
1138
 
                {
 
1127
                if($authExists){
1139
1128
                        $user2 = new User($this->Author);
1140
1129
                        $authorfullname = $user2->getFullname();
1141
 
                } else
1142
 
                {
 
1130
                } else {
1143
1131
                        $authorfullname = $this->Author;
1144
1132
                }
1145
1133
 
1146
1134
                $assignExists = $user->exists($this->Assign);
1147
 
                if($assignExists)
1148
 
                {
 
1135
                if($assignExists){
1149
1136
                        $user2 = new User($this->Assign);
1150
1137
                        $assignfullname = $user2->getFullname();
1151
 
                } else
1152
 
                {
 
1138
                } else {
1153
1139
                        $assignfullname = $this->Assign;
1154
1140
                }
1155
1141
 
1156
 
                $DB = Config::Database();
1157
 
                
1158
 
                $this->deviceSelection();
1159
 
                
1160
 
                $DB = Config::Database();
1161
 
                
1162
 
                $result = $DB->getRow($this->query);
 
1142
                
 
1143
                $result = $this->DB->getRow($this->query);
1163
1144
                $computername = $result["name"];
1164
1145
                $numFollowups = sizeof($this->Followups);
1165
1146
                $text = nl2br($this->WorkRequest);
1188
1169
                PRINT namepriority($this->Priority);
1189
1170
                
1190
1171
                PRINT "\n<td>";
1191
 
                if($authExists)
1192
 
                {
 
1172
                if($authExists){
1193
1173
                        PRINT '<a href="' . $this->userbase . '/users-info.php?ID=' . $this->Author . '">' . $authorfullname . '</a>';
1194
1174
                } else {
1195
1175
                        PRINT $authorfullname;
1202
1182
 
1203
1183
                PRINT "</td>";
1204
1184
 
1205
 
                if($this->Assign == "")
1206
 
                {
 
1185
                if($this->Assign == "") {
1207
1186
                        PRINT "<td>["._("Nobody")."]</td>";
1208
 
                }
1209
 
                else
1210
 
                {
 
1187
                } else {
1211
1188
                        PRINT "<td>\n";
1212
 
                        if($assignExists)
1213
 
                        {
 
1189
                        if($assignExists){
1214
1190
                                PRINT '<a href="'. $this->userbase .'/users-info.php?ID='. $this->Assign .'">' . $assignfullname . '</a>';
1215
1191
                        } else {
1216
1192
                                PRINT $assignfullname;
1225
1201
                PRINT "<td>$location</td>";
1226
1202
                
1227
1203
                PRINT "<td>";
1228
 
 
1229
1204
                PRINT '<div class="followupsubheader">' . _("Follow Ups:") . "$numFollowups</div>";
1230
1205
                PRINT "$text";
1231
1206
                
1232
 
                if(($withFollowups) && ($numFollowups > 0))
1233
 
                {
 
1207
                if(($withFollowups) && ($numFollowups > 0)){
1234
1208
                        Followup::displayHeader();
1235
 
                        for($i=0; $i < $numFollowups; $i++)
1236
 
                        {
 
1209
                        for($i=0; $i < $numFollowups; $i++){
1237
1210
                                $this->Followups[$i]->display();
1238
1211
                        }
1239
1212
                        Followup::displayFooter();
1240
1213
                }
1241
 
 
1242
1214
                PRINT "</td>\n";
1243
1215
                PRINT "</tr>";
1244
1216
        }
1392
1364
                                default:
1393
1365
                                        //Check that the device type exists, but of a hack.
1394
1366
                                        $this->query = 'SHOW TABLES LIKE "' . $this->DeviceType . '%"';
1395
 
                                        $DB = Config::Database();
1396
 
                                        $result = $DB->getRow($this->query);
 
1367
                                        $result = $this->DB->getRow($this->query);
1397
1368
                                        if(count($result) >= 1){
1398
1369
                                                $this->query = "SELECT name,'' FROM $this->DeviceType WHERE (ID = $this->DeviceID)";
1399
1370
                                        }
1499
1470
 
1500
1471
                $this->commit();
1501
1472
 
1502
 
                $DB = Config::Database();
1503
 
 
1504
 
                $close = $DB->getOne("SELECT closed FROM tracking_status WHERE status=".$DB->getTextValue($status));
 
1473
                $close = $this->DB->getOne("SELECT closed FROM tracking_status WHERE status=".$this->DB->getTextValue($status));
1505
1474
 
1506
1475
                if($close && $addtoknowledgebase == "yes" && $permissions)
1507
1476
                {
1597
1566
        {
1598
1567
                $this->readonly = $readonly;
1599
1568
                $this->deviceSelection();
1600
 
                $DB = Config::Database();
1601
 
                $result = $DB->getRow($this->query);
 
1569
                $result = $this->DB->getRow($this->query);
1602
1570
                $computername = $result["name"];
1603
1571
                $user = new User();
1604
1572
                $authExists = $user->exists($this->Author);
1664
1632
        }
1665
1633
 
1666
1634
        function dateClosed(){
1667
 
                $DB = Config::Database();
1668
1635
                $text = "";
1669
1636
                if(($this->CloseDate != "0000-00-00 00:00:00") && ($this->CloseDate != "")) {
1670
1637
                        $query = "SELECT SEC_TO_TIME(UNIX_TIMESTAMP('$this->CloseDate') - UNIX_TIMESTAMP('$this->DateEntered'))";
1671
 
                        $opentime = $DB->getOne($query);
 
1638
                        $opentime = $this->DB->getOne($query);
1672
1639
                        $text .= "<br />" . _("Date Closed:") . "<br />" . $this->CloseDate;
1673
1640
                        $text .= "<br />"._("This job was open for:")." $opentime";
1674
1641
                }
1721
1688
         */
1722
1689
        function search($type, $information)
1723
1690
        {
1724
 
                $DB = Config::Database();
1725
 
                $info = $DB->getTextValue("%$information%");
 
1691
                $info = $this->DB->getTextValue("%$information%");
1726
1692
 
1727
1693
                switch($type){
1728
1694
                        case 'tracking':
1742
1708
                                ORDER BY tracking.date DESC";
1743
1709
                                break;
1744
1710
                }
1745
 
                return $DB->getCol($query);
 
1711
                return $this->DB->getCol($query);
1746
1712
        }
1747
1713
 
1748
1714
        
1947
1913
                        'emailupdates' => $this->EmailUpdatesToAuthor,
1948
1914
                        'other_emails' => $this->OtherEmails
1949
1915
                        );
1950
 
                $DB = Config::Database();
1951
 
                $ID = $DB->getTextValue($this->ID);
1952
 
                $DB->UpdateQuery('tracking', $vals, "ID=$ID");
 
1916
                $ID = $this->DB->getTextValue($this->ID);
 
1917
                $this->DB->UpdateQuery('tracking', $vals, "ID=$ID");
1953
1918
        
1954
1919
                $numFollowups = sizeof($this->Followups);
1955
1920
                for($i=0;$i<$numFollowups;$i++)
2029
1994
                        return (0);
2030
1995
                }
2031
1996
 
2032
 
                $DB = Config::Database();
2033
 
                $this->ID = $DB->nextId('tracking__ID');
 
1997
                $this->ID = $this->DB->nextId('tracking__ID');
2034
1998
                $vals = array(
2035
1999
                        'ID' => $this->ID,
2036
2000
                        'date' => $this->DateEntered,
2048
2012
                        'device' => $this->DeviceType
2049
2013
                        );
2050
2014
                        
2051
 
                $DB->InsertQuery('tracking', $vals);
 
2015
                $this->DB->InsertQuery('tracking', $vals);
2052
2016
                $this->sendEmail();
2053
2017
        }
2054
2018
 
2089
2053
                {
2090
2054
                        $this->Followups[$i]->delete();
2091
2055
                }
2092
 
                $DB = Config::Database();
2093
 
                $id = $DB->getTextValue($this->ID);
 
2056
                $id = $this->DB->getTextValue($this->ID);
2094
2057
                $query = "DELETE FROM tracking WHERE (ID = $id)";
2095
 
                $DB->query($query);
 
2058
                $this->DB->query($query);
2096
2059
        }
2097
2060
 
2098
2061
        /**
2101
2064
         */
2102
2065
        function getByComputerID($cID)
2103
2066
        {
2104
 
                $DB = Config::Database();
2105
 
                $cID = $DB->getTextValue($cID);
 
2067
                $cID = $this->DB->getTextValue($cID);
2106
2068
                $query = "SELECT ID FROM tracking WHERE (computer = $cID) and (is_group != 'yes')";
2107
 
                return $DB->getCol($query);
 
2069
                return $this->DB->getCol($query);
2108
2070
        }
2109
2071
 
2110
2072
        /**
2113
2075
         */
2114
2076
        function getByGroupID($gID)
2115
2077
        {
2116
 
                $DB = Config::Database();
2117
 
                $gID = $DB->getTextValue($gID);
 
2078
                $gID = $this->DB->getTextValue($gID);
2118
2079
                $query = "SELECT ID FROM tracking WHERE (computer = $gID) and (is_group = 'yes')";
2119
 
                return $DB->getCol($query);
 
2080
                return $this->DB->getCol($query);
2120
2081
        }
2121
2082
 
2122
2083
        /**