File: class.company.php

package info (click to toggle)
collabtive 2.0%2Bdfsg-5
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 17,708 kB
  • ctags: 27,425
  • sloc: php: 100,872; sh: 72; makefile: 50
file content (262 lines) | stat: -rw-r--r-- 6,152 bytes parent folder | download | duplicates (2)
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
<?php

/**
* Class to provide methods for handling customer companies
*
* @author Philipp Kiszka
* @name project
* @package Collabtive
* @version 2.0
* @link http://www.o-dyn.de
* @license http://opensource.org/licenses/gpl-license.php GNU General Public License v3 or later
*/
class company {
    private $mylog;

    /**
    * Constructor
    * Initializes the event log
    */
    function __construct()
    {
        $this->mylog = new mylog;
    }

    /**
    * Add a company
    *
    * @param array $data
    * @return int $insid ID of the inserted company
    */
    function add($data)
    {
        global $conn;

        $ins1Stmt = $conn->prepare("INSERT INTO company (`company`, `contact`, `email`, `phone`, `mobile`, `url`, `address`, `zip`, `city`, `country`, `state`, `desc`) VALUES (?,?,?,?,?,?,?,?,?,?,?,?)");
        $ins1 = $ins1Stmt->execute(array($data['company'], $data['contact'], $data['email'], $data['phone'], $data['mobile'], $data['url'], $data['address'], $data['zip'], $data['city'], $data['country'], $data['state'], $data['desc']));
        $insid = $conn->lastInsertId();

        if ($ins1) {
            return $insid;
        } else {
            return false;
        }
    }

    /**
    * Edit a company
    *
    * @param array $data Company data
    * @return bool
    */
    function edit($data)
    {
        global $conn;

        $id = (int) $data['id'];

        $updStmt = $conn->prepare("UPDATE company SET `company`=?, `contact`=?, `email`=?, `phone`=?, `mobile`=?, `url`=?, `address`=?, `zip`=?, `city`=?, `country`=?, `state`=?, `desc`=? WHERE ID = ?");
        $upd = $updStmt->execute(array($data['company'], $data['contact'], $data['email'], $data['phone'], $data['mobile'], $data['url'], $data['address'], $data['zip'], $data['city'], $data['country'], $data['state'], $data['desc'], $id));

        if ($upd) {
            return true;
        } else {
            return false;
        }
    }

    /**
    * Delete a company and disconnect all assigned projects
    *
    * @param int $id Company ID
    * @return bool
    */
    function del($id)
    {
        global $conn;

        $id = (int) $id;

        $del_assigns = $conn->query("DELETE FROM company_assigned WHERE customer = $id");
        $del = $conn->query("DELETE FROM customer WHERE ID = $id");

        if ($del) {
            return true;
        } else {
            return false;
        }
    }

    /**
    * Assign a company to a project
    *
    * @param int $task Company ID
    * @param int $id project ID
    * @return bool
    */
    function assign($company, $id)
    {
        global $conn;

        $company = (int) $company;
        $id = (int) $id;

        $upd = $conn->query("INSERT INTO customers_assigned (customer, project) VALUES ($company, $id)");

        if ($upd) {
            return true;
        } else {
            return false;
        }
    }

    /**
    * Disconnect a company from a user
    *
    * @param int $task Company ID
    * @param int $id User ID
    * @return bool
    */
    function deassign($company, $id)
    {
        global $conn;

        $company = (int) $company;
        $id = (int) $id;

        $upd = $conn->query("DELETE FROM company_assigned WHERE user = $id AND company = $company");

        if ($upd) {
            return true;
        } else {
            return false;
        }
    }

    /**
    * Get a company
    *
    * @param int $id Company ID
    * @return array $company Company
    */
    function getCompany($id)
    {
        global $conn;

        $id = (int) $id;

        $sel = $conn->prepare("SELECT * FROM company WHERE ID = ?");
        if ($sel) {
	    $selStmt = $sel->execute(array($id));

	    $company = $sel->fetch();
	}

        if (!empty($company)) {
            return $company;
        } else {
            return false;
        }
    }

    function getProjectCompany($project)
    {
    	global $conn;

        $project = (int) $project;
        $sel = $conn->prepare("SELECT customer FROM customers_assigned WHERE project = ?");
        $selStmt = $sel->execute(array($project));

        $companyId = $sel->fetch();

		$company = $this->getCompany($companyId);

		if (!empty($company)) {
            return $company;
        } else {
            return false;
        }
    }
    /**
    * Get a list of companies
    *
    * @param int $lim Maximum number of companies to return (default: 10)
    * @return array $companies List of companies
    */
    function getCompanies($lim = 10)
    {
        global $conn;

        $lim = (int) $lim;

        $sel = $conn->prepare("SELECT * FROM company ORDER BY `company` ASC LIMIT $lim");
	if ($sel) {
	    $selStmt = $sel->execute();

	    $companies = $sel->fetchAll();
	}

        if (!empty($companies)) {
            return $companies;
        } else {
            return false;
        }
    }

    /**
    * Get a list of all companies
    *
    * @return array $companies List of all companies
    */
    function getAllCompanies()
    {
        global $conn;

        $sel = $conn->query("SELECT * FROM company");
        $companies = array();

        while ($sel and $company = $sel->fetch()) {
            array_push($companies, $company);
        }

        if (!empty($companies)) {
            return $companies;
        }else {
            return false;
        }
    }

    /**
    * Get a company including all of its members
    *
    * @param int $id Company ID
    * @return array $company Company including all of its members
    */
    function getCompanyMembers($id)
    {
        global $conn;

        $id = (int) $id;

        $sel = $conn->query("SELECT user, company FROM company_assigned WHERE company = $id");

        $staff = array();
        $userobj = (object) new user();
        $company = $this->getProfile($member[1]);

        while ($sel and $member = $sel->fetch()) {
            $user = $userobj->getProfile($member[0]);
            array_push($staff, $user);
        }

        $company["staff"] = $staff;

        if (!empty($company)) {
            return $company;
        }else {
            return false;
        }
    }
}

?>