Commit c1ff9139ab0c8ac8a31f27eccf3eb669f8c70017

Authored by michael
1 parent 5c0e1087

added copyright and gpl notice

removed owl prefix from table aliases
formatted


git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@2564 c91229c3-7414-0410-bfa2-8a42b809f60b
Showing 1 changed file with 213 additions and 244 deletions
lib/orgmanagement/Organisation.inc
1 <?php 1 <?php
2 /** 2 /**
3 -* Class Oranisation  
4 -* Represents a organisation as per the database table organisations_lookup  
5 -*  
6 -* @author Mukhtar Dharsey  
7 -* @date 28 January 2003  
8 -* @package lib.orgmanagement  
9 -*/  
10 -  
11 -class Organisation  
12 -{  
13 -  
14 - /** object's primary key */  
15 - var $iId;  
16 - /** org's name */  
17 - var $sName;  
18 -  
19 -  
20 - function Organisation($sNewName)  
21 - {  
22 - //object has not been created in database yet  
23 - $this->iId = -1;  
24 - $this->sName = $sNewName;  
25 -  
26 - }  
27 -  
28 - /**  
29 - * Get the object's primary key  
30 - *  
31 - * @return int object's primary key  
32 - *  
33 - */  
34 - function getID()  
35 - {  
36 - return $this->iId;  
37 - }  
38 -  
39 - /**  
40 - * Get the org's name  
41 - *  
42 - * @return String org's name  
43 - *  
44 - */  
45 - function getName()  
46 - {  
47 - return $this->sName;  
48 - }  
49 -  
50 - /**  
51 - * Set the orgs name  
52 - *  
53 - * @param String Unit's name  
54 - *  
55 - */  
56 - function setName($sNewValue)  
57 - {  
58 - $this->sName = $sNewValue;  
59 - }  
60 -  
61 -  
62 - /**  
63 - * Create the current object in the database  
64 - *  
65 - * @return boolean on successful store, false otherwise and set $_SESSION["errorMessage"]  
66 - *  
67 - */  
68 - function create()  
69 - {  
70 - global $default, $lang_err_database, $lang_err_object_exists;  
71 - //if the object hasn't been created  
72 - if ($this->iId < 0)  
73 - { //check to see if name exsits  
74 - $sql = $default->db;  
75 - $query = "SELECT name FROM ". $default->owl_organisations_table ." WHERE name = '" . $this->sName . "'";  
76 - $sql->query($query);  
77 - $rows = $sql->num_rows($sql);  
78 -  
79 - if ($rows > 0)  
80 - {  
81 - // duplicate username  
82 - $_SESSION["errorMessage"] = "Organisation::The name " . $this->sName . " is already in use!";  
83 - return false;  
84 - }  
85 - else  
86 - {  
87 - $result = $sql->query("INSERT INTO " . $default->owl_organisations_table . " (name) VALUES ('" . addslashes($this->sName) . "')");  
88 - if ($result)  
89 - {  
90 - $this->iId = $sql->insert_id();  
91 - return true;  
92 - }  
93 - $_SESSION["errorMessage"] = $lang_err_database;  
94 - return false;  
95 - }  
96 - }  
97 - $_SESSION["errorMessage"] = $lang_err_object_exists . "id = " . $this->iId . " table = $default->owl_organisations_table";  
98 - return false;  
99 - }  
100 -  
101 - /**  
102 - * Update the values in the database table with the object's current values  
103 - *  
104 - * @return boolean true on successful update, false otherwise and set $_SESSION["errorMessage"]  
105 - *  
106 - */  
107 - function update()  
108 - {  
109 - global $default, $lang_err_database, $lang_err_object_key;  
110 - //only update if the object has been stored  
111 - if ($this->iId > 0)  
112 - {  
113 - $sql = $default->db;  
114 - $result = $sql->query("UPDATE " . $default->owl_organisations_table . " SET name = '" . addslashes($this->sName) . "' WHERE id = $this->iId");  
115 - if ($result)  
116 - {  
117 - return true;  
118 - }  
119 - $_SESSION["errorMessage"] = $lang_err_database;  
120 - return false;  
121 - }  
122 - $_SESSION["errorMessage"] = $lang_err_object_key;  
123 - return false;  
124 - }  
125 -  
126 - /**  
127 - * Delete the current object from the database  
128 - *  
129 - * @return boolean true on successful deletion, false otherwise and set $_SESSION["errorMessage"]  
130 - *  
131 - */  
132 - function delete()  
133 - {  
134 - global $default, $lang_err_database, $lang_err_object_key;  
135 - //only delete the object if it exists in the database  
136 -  
137 -  
138 - if ($this->iId >= 0) {  
139 - //check to see if group is linked to a unit  
140 - $sql = $default->db;  
141 - $query = "SELECT organisation_id FROM ". $default->owl_units_organisations_table ." WHERE organisation_id = '" . $this->iId . "'";  
142 - $sql->query($query);  
143 - $rows = $sql->num_rows($sql);  
144 -  
145 -  
146 -  
147 - if ($rows > 0){  
148 - // duplicate link exists  
149 - $_SESSION["errorMessage"] = "Group::The Group " . $this->sName . " exits!";  
150 - return false;  
151 -  
152 - }else{  
153 - $sql = $default->db;  
154 - $result = $sql->query("DELETE FROM $default->owl_organisations_table WHERE id = $this->iId");  
155 - if ($result)  
156 - {  
157 - return true;  
158 - }  
159 - $_SESSION["errorMessage"] = $lang_err_database;  
160 - return false;  
161 - }  
162 - }  
163 - $_SESSION["errorMessage"] = $lang_err_object_key;  
164 - return false;  
165 - }  
166 -  
167 - /**  
168 - * Static function.  
169 - * Given a web_documents primary key it will create a  
170 - * Unit object and populate it with the  
171 - * corresponding database values  
172 - *  
173 - * @return Unit populated Unit object on successful query, false otherwise and set $_SESSION["errorMessage"]  
174 - */  
175 - function & get($iOrgID)  
176 - {  
177 - global $default;  
178 - $sql = $default->db;  
179 - $result = $sql->query("SELECT * FROM $default->owl_organisations_table WHERE id = $iOrgID");  
180 - if ($result)  
181 - {  
182 - if ($sql->next_record())  
183 - {  
184 - $oOrg = & new Organisation(stripslashes($sql->f("name")));  
185 - $oOrg->iId = $iOrgID;  
186 - return $oOrg;  
187 - }  
188 - $_SESSION["errorMessage"] = $lang_err_object_not_exist . "id = " . $iOrgID . " table = $default->owl_organisations_table";  
189 - return false;  
190 - }  
191 - $_SESSION["errorMessage"] = $lang_err_database;  
192 - return false;  
193 - }  
194 - 3 + * $Id$
  4 + *
  5 + * Represents a organisation as per the database table organisations_lookup.
  6 + *
  7 + * Copyright (c) 2003 Jam Warehouse http://www.jamwarehouse.com
  8 + *
  9 + * This program is free software; you can redistribute it and/or modify
  10 + * it under the terms of the GNU General Public License as published by
  11 + * the Free Software Foundation; either version 2 of the License, or
  12 + * (at your option) any later version.
  13 + *
  14 + * This program is distributed in the hope that it will be useful,
  15 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17 + * GNU General Public License for more details.
  18 + *
  19 + * You should have received a copy of the GNU General Public License
  20 + * along with this program; if not, write to the Free Software
  21 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  22 + *
  23 + * @version $Revision$
  24 + * @author Mukhtar Dharsey, Jam Warehouse (Pty) Ltd, South Africa
  25 + * @package lib.orgmanagement
  26 + */
  27 +class Organisation {
  28 + /** object's primary key */
  29 + var $iId;
  30 + /** org's name */
  31 + var $sName;
  32 + function Organisation($sNewName) {
  33 + //object has not been created in database yet
  34 + $this->iId = -1;
  35 + $this->sName = $sNewName;
  36 + }
  37 + /**
  38 + * Get the object's primary key
  39 + *
  40 + * @return int object's primary key
  41 + *
  42 + */
  43 + function getID() {
  44 + return $this->iId;
  45 + }
  46 + /**
  47 + * Get the org's name
  48 + *
  49 + * @return String org's name
  50 + *
  51 + */
  52 + function getName() {
  53 + return $this->sName;
  54 + }
  55 + /**
  56 + * Set the orgs name
  57 + *
  58 + * @param String Unit's name
  59 + *
  60 + */
  61 + function setName($sNewValue) {
  62 + $this->sName = $sNewValue;
  63 + }
  64 + /**
  65 + * Create the current object in the database
  66 + *
  67 + * @return boolean on successful store, false otherwise and set $_SESSION["errorMessage"]
  68 + *
  69 + */
  70 + function create() {
  71 + global $default, $lang_err_database, $lang_err_object_exists;
  72 + //if the object hasn't been created
  73 + if ($this->iId < 0) {
  74 + //check to see if name exsits
  75 + $sql = $default->db;
  76 + $query = "SELECT name FROM ". $default->organisations_table ." WHERE name = '" . $this->sName . "'";
  77 + $sql->query($query);
  78 + $rows = $sql->num_rows($sql);
  79 + if ($rows > 0) {
  80 + // duplicate username
  81 + $_SESSION["errorMessage"] = "Organisation::The name " . $this->sName . " is already in use!";
  82 + return false;
  83 + } else {
  84 + $result = $sql->query("INSERT INTO " . $default->organisations_table . " (name) VALUES ('" . addslashes($this->sName) . "')");
  85 + if ($result) {
  86 + $this->iId = $sql->insert_id();
  87 + return true;
  88 + }
  89 + $_SESSION["errorMessage"] = $lang_err_database;
  90 + return false;
  91 + }
  92 + }
  93 + $_SESSION["errorMessage"] = $lang_err_object_exists . "id = " . $this->iId . " table = $default->organisations_table";
  94 + return false;
  95 + }
  96 + /**
  97 + * Update the values in the database table with the object's current values
  98 + *
  99 + * @return boolean true on successful update, false otherwise and set $_SESSION["errorMessage"]
  100 + *
  101 + */
  102 + function update() {
  103 + global $default, $lang_err_database, $lang_err_object_key;
  104 + //only update if the object has been stored
  105 + if ($this->iId > 0) {
  106 + $sql = $default->db;
  107 + $result = $sql->query("UPDATE " . $default->organisations_table . " SET name = '" . addslashes($this->sName) . "' WHERE id = $this->iId");
  108 + if ($result) {
  109 + return true;
  110 + }
  111 + $_SESSION["errorMessage"] = $lang_err_database;
  112 + return false;
  113 + }
  114 + $_SESSION["errorMessage"] = $lang_err_object_key;
  115 + return false;
  116 + }
  117 + /**
  118 + * Delete the current object from the database
  119 + *
  120 + * @return boolean true on successful deletion, false otherwise and set $_SESSION["errorMessage"]
  121 + *
  122 + */
  123 + function delete() {
  124 + global $default, $lang_err_database, $lang_err_object_key;
  125 + //only delete the object if it exists in the database
  126 + if ($this->iId >= 0) {
  127 + //check to see if group is linked to a unit
  128 + $sql = $default->db;
  129 + $query = "SELECT organisation_id FROM ". $default->units_organisations_table ." WHERE organisation_id = '" . $this->iId . "'";
  130 + $sql->query($query);
  131 + $rows = $sql->num_rows($sql);
  132 + if ($rows > 0) {
  133 + // duplicate link exists
  134 + $_SESSION["errorMessage"] = "Group::The Group " . $this->sName . " exits!";
  135 + return false;
  136 + } else {
  137 + $sql = $default->db;
  138 + $result = $sql->query("DELETE FROM $default->organisations_table WHERE id = $this->iId");
  139 + if ($result) {
  140 + return true;
  141 + }
  142 + $_SESSION["errorMessage"] = $lang_err_database;
  143 + return false;
  144 + }
  145 + }
  146 + $_SESSION["errorMessage"] = $lang_err_object_key;
  147 + return false;
  148 + }
  149 + /**
  150 + * Static function.
  151 + * Given a web_documents primary key it will create a
  152 + * Unit object and populate it with the
  153 + * corresponding database values
  154 + *
  155 + * @return Unit populated Unit object on successful query, false otherwise and set $_SESSION["errorMessage"]
  156 + */
  157 + function & get($iOrgID) {
  158 + global $default;
  159 + $sql = $default->db;
  160 + $result = $sql->query("SELECT * FROM $default->organisations_table WHERE id = $iOrgID");
  161 + if ($result) {
  162 + if ($sql->next_record()) {
  163 + $oOrg = & new Organisation(stripslashes($sql->f("name")));
  164 + $oOrg->iId = $iOrgID;
  165 + return $oOrg;
  166 + }
  167 + $_SESSION["errorMessage"] = $lang_err_object_not_exist . "id = " . $iOrgID . " table = $default->organisations_table";
  168 + return false;
  169 + }
  170 + $_SESSION["errorMessage"] = $lang_err_database;
  171 + return false;
  172 + }
195 /* 173 /*
196 - * static function  
197 - *  
198 - * gets the id of a org using their name  
199 - *  
200 - * @param String  
201 - * The username for which we want its ID  
202 - *  
203 - */  
204 -  
205 - function getOrgID($name)  
206 - {  
207 - global $default;  
208 -  
209 - $id = lookupID($default->owl_organisations_table, "name", $name);  
210 -  
211 - $this->iId= $id;  
212 - }  
213 -  
214 - /**  
215 - * Static function  
216 - * Get a list of web documents  
217 - *  
218 - * @param String Where clause (not required)  
219 - *  
220 - * @return Array array of org objects, false otherwise and set $_SESSION["errorMessage"]  
221 - */  
222 - function getList($sWhereClause = null)  
223 - {  
224 - global $default, $lang_err_database;  
225 - $aOrgArray;  
226 - settype($aUnitArray, "array");  
227 - $sql = $default->db;  
228 - $result = $sql->query("SELECT * FROM " . $default->owl_organisations_table . (isset($sWhereClause) ? " " . $sWhereClause : ""));  
229 - if ($result)  
230 - {  
231 - $iCount = 0;  
232 - while ($sql->next_record())  
233 - {  
234 - $oOrg = & Organisation::get($sql->f("id"));  
235 - $aOrgArray[$iCount] = $oOrg;  
236 - $iCount++;  
237 - }  
238 - return $aOrgArray;  
239 - }  
240 - $_SESSION["errorMessage"] = $lang_err_database;  
241 - return false;  
242 - }  
243 - 174 + * static function
  175 + *
  176 + * gets the id of a org using their name
  177 + *
  178 + * @param String
  179 + * The username for which we want its ID
  180 + *
  181 + */
  182 + function getOrgID($name) {
  183 + global $default;
  184 + $id = lookupID($default->organisations_table, "name", $name);
  185 + $this->iId = $id;
  186 + }
  187 + /**
  188 + * Static function
  189 + * Get a list of web documents
  190 + *
  191 + * @param String Where clause (not required)
  192 + *
  193 + * @return Array array of org objects, false otherwise and set $_SESSION["errorMessage"]
  194 + */
  195 + function getList($sWhereClause = null) {
  196 + global $default, $lang_err_database;
  197 + $aOrgArray;
  198 + settype($aUnitArray, "array");
  199 + $sql = $default->db;
  200 + $result = $sql->query("SELECT * FROM " . $default->organisations_table . (isset($sWhereClause) ? " " . $sWhereClause : ""));
  201 + if ($result) {
  202 + $iCount = 0;
  203 + while ($sql->next_record()) {
  204 + $oOrg = & Organisation::get($sql->f("id"));
  205 + $aOrgArray[$iCount] = $oOrg;
  206 + $iCount++;
  207 + }
  208 + return $aOrgArray;
  209 + }
  210 + $_SESSION["errorMessage"] = $lang_err_database;
  211 + return false;
  212 + }
244 } 213 }
245 /** 214 /**
246 * Static function 215 * Static function
247 * 216 *
248 * Creates a Org object from an array 217 * Creates a Org object from an array
249 * 218 *
250 -* @param Array Array of parameters. Must match order of parameters in constructor 219 +* @param Array Array of parameters. Must match order of parameters in constructor
251 * 220 *
252 * @return User user object 221 * @return User user object
253 */ 222 */
254 function & organisationCreateFromArray($aParameters) { 223 function & organisationCreateFromArray($aParameters) {
255 - $oOrg = & new Organisation($aParameters[0], $aParameters[1], $aParameters[2], $aParameters[3], $aParameters[4], $aParameters[5], $aParameters[6], $aParameters[7], $aParameters[8], $aParameters[9], $aParameters[10]);  
256 - return $oOrg; 224 + $oOrg = & new Organisation($aParameters[0], $aParameters[1], $aParameters[2], $aParameters[3], $aParameters[4], $aParameters[5], $aParameters[6], $aParameters[7], $aParameters[8], $aParameters[9], $aParameters[10]);
  225 + return $oOrg;
257 } 226 }
258 -?> 227 -?>
  228 +?>
259 \ No newline at end of file 229 \ No newline at end of file