Commit 9970d3ec50d6c7ea94b46dffda03b62405416146
1 parent
2fbcf6e4
added copyright and gpl notice
removed owl prefix from table aliases changed filename to proper case git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@2562 c91229c3-7414-0410-bfa2-8a42b809f60b
Showing
1 changed file
with
271 additions
and
0 deletions
lib/links/Link.inc
0 → 100644
| 1 | +<?php | |
| 2 | +/** | |
| 3 | + * $Id$ | |
| 4 | + * | |
| 5 | + * Represents a Link as per the database table links. | |
| 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 Rob Cherry, Jam Warehouse (Pty) Ltd, South Africa | |
| 25 | + * @package lib.groups | |
| 26 | + */ | |
| 27 | +class Link { | |
| 28 | + | |
| 29 | + /** primary key of current object */ | |
| 30 | + var $iId; | |
| 31 | + /** Link name */ | |
| 32 | + var $sName; | |
| 33 | + /** url link */ | |
| 34 | + var $sUrl; | |
| 35 | + /** rank of website */ | |
| 36 | + var $iRank; | |
| 37 | + | |
| 38 | + | |
| 39 | + function Link($sNewName, $sNewUrl, $iNewRank) { | |
| 40 | + $this->iId = -1; | |
| 41 | + $this->sName = $sNewName; | |
| 42 | + $this->sUrl = $sNewUrl; | |
| 43 | + $this->iRank = $iNewRank; | |
| 44 | + } | |
| 45 | + | |
| 46 | + function getUrl() { | |
| 47 | + return $this->sUrl; | |
| 48 | + } | |
| 49 | + | |
| 50 | + function setUrl($sNewValue) { | |
| 51 | + $this->sUrl = $sNewValue; | |
| 52 | + } | |
| 53 | + | |
| 54 | + function getRank() { | |
| 55 | + return $this->iRank; | |
| 56 | + } | |
| 57 | + | |
| 58 | + function setRank($sNewValue) { | |
| 59 | + $this->iRank = $sNewValue; | |
| 60 | + } | |
| 61 | + | |
| 62 | + function getName() { | |
| 63 | + return $this->sName; | |
| 64 | + } | |
| 65 | + | |
| 66 | + function setName($sNewValue) { | |
| 67 | + $this->sName = $sNewValue; | |
| 68 | + } | |
| 69 | + | |
| 70 | + /** | |
| 71 | + * Create the current object in the database | |
| 72 | + * | |
| 73 | + * @return boolean on successful store, false otherwise and set $_SESSION["errorMessage"] | |
| 74 | + * | |
| 75 | + */ | |
| 76 | + function create() { | |
| 77 | + global $default, $lang_err_database, $lang_err_object_exists; | |
| 78 | + //if the object hasn't been created | |
| 79 | + if ($this->iId < 0) { | |
| 80 | + //check to see if name exsits | |
| 81 | + $sql = $default->db; | |
| 82 | + $query = "SELECT name FROM ". $default->quicklinks_table ." WHERE name = '" . $this->sName . "'"; | |
| 83 | + $sql->query($query); | |
| 84 | + $rows = $sql->num_rows($sql); | |
| 85 | + | |
| 86 | + if ($rows > 0){ | |
| 87 | + // duplicate username | |
| 88 | + $_SESSION["errorMessage"] = "Link::The Link name " . $this->sName . " is already in use!"; | |
| 89 | + return false; | |
| 90 | + | |
| 91 | + }else{ | |
| 92 | + $sql = $default->db; | |
| 93 | + $query = "SELECT rank FROM ". $default->quicklinks_table ." WHERE rank = '" . $this->iRank . "'"; | |
| 94 | + $sql->query($query); | |
| 95 | + $rows = $sql->num_rows($sql); | |
| 96 | + | |
| 97 | + if ($rows > 0){ | |
| 98 | + // duplicate username | |
| 99 | + $_SESSION["errorMessage"] = "Link::The Rank " . $this->iRank . " is already in use!"; | |
| 100 | + return false; | |
| 101 | + | |
| 102 | + }else{ | |
| 103 | + $sql = $default->db; | |
| 104 | + $result = $sql->query("INSERT INTO " . $default->quicklinks_table . " (name, url, rank) VALUES ('" . addslashes($this->sName) . "', '" . ($this->sUrl) . "', " . ($this->iRank) . ")"); | |
| 105 | + if ($result) { | |
| 106 | + $this->iId = $sql->insert_id(); | |
| 107 | + return true; | |
| 108 | + } | |
| 109 | + $_SESSION["errorMessage"] = $lang_err_database; | |
| 110 | + return false; | |
| 111 | + } | |
| 112 | + } | |
| 113 | + } | |
| 114 | + $_SESSION["errorMessage"] = $lang_err_object_exists . "id = " . $this->iId . " table = document_fields"; | |
| 115 | + return false; | |
| 116 | + } | |
| 117 | + | |
| 118 | + /** | |
| 119 | + * Update the values in the database table with the object's current values | |
| 120 | + * | |
| 121 | + * @return boolean true on successful update, false otherwise and set $_SESSION["errorMessage"] | |
| 122 | + * | |
| 123 | + */ | |
| 124 | + function update() { | |
| 125 | + global $default, $lang_err_database, $lang_err_object_key; | |
| 126 | + //only update if the object has been stored | |
| 127 | + if ($this->iId > 0) { | |
| 128 | + $sql = $default->db; | |
| 129 | + $result = $sql->query("UPDATE " . $default->quicklinks_table . " SET name = '" . addslashes($this->sName) . "', url = '" . ($this->sUrl) . "', rank = " . ($this->iRank) . " WHERE id = $this->iId"); | |
| 130 | + if ($result) { | |
| 131 | + return true; | |
| 132 | + } | |
| 133 | + $_SESSION["errorMessage"] = $lang_err_database; | |
| 134 | + return false; | |
| 135 | + } | |
| 136 | + $_SESSION["errorMessage"] = $lang_err_object_key; | |
| 137 | + return false; | |
| 138 | + } | |
| 139 | + | |
| 140 | + /** | |
| 141 | + * Delete the current object from the database | |
| 142 | + * | |
| 143 | + * @return boolean true on successful deletion, false otherwise and set $_SESSION["errorMessage"] | |
| 144 | + * | |
| 145 | + */ | |
| 146 | + function delete() { | |
| 147 | + global $default, $lang_err_database, $lang_err_object_key; | |
| 148 | + //only delete the object if it exists in the database | |
| 149 | + if ($this->iId >= 0) { | |
| 150 | + $sql = $default->db; | |
| 151 | + $result = $sql->query("DELETE FROM $default->quicklinks_table WHERE id = $this->iId"); | |
| 152 | + if ($result) { | |
| 153 | + return true; | |
| 154 | + } | |
| 155 | + $_SESSION["errorMessage"] = $lang_err_database; | |
| 156 | + return false; | |
| 157 | + | |
| 158 | + } | |
| 159 | + $_SESSION["errorMessage"] = $lang_err_object_key; | |
| 160 | + return false; | |
| 161 | + } | |
| 162 | + | |
| 163 | + /** | |
| 164 | + * Static function. | |
| 165 | + * Given a Links primary key it will create a | |
| 166 | + * Link object and populate it with the | |
| 167 | + * corresponding database values | |
| 168 | + * | |
| 169 | + * @return Link populated Link object on successful query, false otherwise and set $_SESSION["errorMessage"] | |
| 170 | + */ | |
| 171 | + function & get($iLinkID) { | |
| 172 | + global $default; | |
| 173 | + $sql = $default->db; | |
| 174 | + $result = $sql->query("SELECT * FROM $default->quicklinks_table WHERE id = $iLinkID"); | |
| 175 | + if ($result) { | |
| 176 | + if ($sql->next_record()) { | |
| 177 | + $oLink = & new Link(stripslashes($sql->f("name")), $sql->f("url"), $sql->f("rank")); | |
| 178 | + $oLink->iId = $iLinkID; | |
| 179 | + return $oLink; | |
| 180 | + } | |
| 181 | + $_SESSION["errorMessage"] = $lang_err_object_not_exist . "id = " . $iLinkID . " table = $default->quicklinks_table"; | |
| 182 | + return false; | |
| 183 | + } | |
| 184 | + $_SESSION["errorMessage"] = $lang_err_database; | |
| 185 | + return false; | |
| 186 | + } | |
| 187 | + | |
| 188 | +/** | |
| 189 | + * Static function | |
| 190 | + * Get a list ocuments | |
| 191 | + * | |
| 192 | + * @param String Where clause (not required) | |
| 193 | + * | |
| 194 | + * @return Array array of Link objects, false otherwise and set $_SESSION["errorMessage"] | |
| 195 | + */ | |
| 196 | + function getList($sWhereClause = null) { | |
| 197 | + global $default, $lang_err_database; | |
| 198 | + $aLinkArray; | |
| 199 | + settype($aLinkArray, "array"); | |
| 200 | + $sql = $default->db; | |
| 201 | + $result = $sql->query("SELECT * FROM " . $default->quicklinks_table . (isset($sWhereClause) ? " " . $sWhereClause : "")); | |
| 202 | + if ($result) { | |
| 203 | + $iCount = 0; | |
| 204 | + while ($sql->next_record()) { | |
| 205 | + $oLink = & Link::get($sql->f("id")); | |
| 206 | + $aLinkArray[$iCount] = $oLink; | |
| 207 | + $iCount++; | |
| 208 | + } | |
| 209 | + return $aLinkArray; | |
| 210 | + } | |
| 211 | + $_SESSION["errorMessage"] = $lang_err_database; | |
| 212 | + return false; | |
| 213 | + } | |
| 214 | + | |
| 215 | + | |
| 216 | +} | |
| 217 | +/* | |
| 218 | + * static function | |
| 219 | + * | |
| 220 | + * gets the name of a unit using their id | |
| 221 | + * | |
| 222 | + * @param String | |
| 223 | + * The name | |
| 224 | + * | |
| 225 | + */ | |
| 226 | + | |
| 227 | + function getLinkName($id) | |
| 228 | + { | |
| 229 | + global $default; | |
| 230 | + | |
| 231 | + $name = lookupField("$default->quicklinks_table", "name", "id", $id ); | |
| 232 | + | |
| 233 | + $this->sName= $name; | |
| 234 | + } | |
| 235 | + | |
| 236 | + /* | |
| 237 | + * static function | |
| 238 | + * | |
| 239 | + * gets the name of a unit using their id | |
| 240 | + * | |
| 241 | + * @param String | |
| 242 | + * The name | |
| 243 | + * | |
| 244 | + */ | |
| 245 | + | |
| 246 | + function getLinkUrl($id) | |
| 247 | + { | |
| 248 | + global $default; | |
| 249 | + | |
| 250 | + $url = lookupField("$default->quicklinks_table", "url", "id", $id ); | |
| 251 | + | |
| 252 | + $this->sName= $url; | |
| 253 | + } | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | +/** | |
| 258 | +* Static function | |
| 259 | +* | |
| 260 | +* Creates a Link object from an array | |
| 261 | +* | |
| 262 | +* @param Array Array of parameters. Must match order of parameters in constructor | |
| 263 | +* | |
| 264 | +* @return User user object | |
| 265 | +*/ | |
| 266 | +function & linkCreateFromArray($aParameters) { | |
| 267 | + $oLink = & new Link($aParameters[0], $aParameters[1], $aParameters[2], $aParameters[3], $aParameters[4], $aParameters[5], $aParameters[6], $aParameters[7], $aParameters[8], $aParameters[9], $aParameters[10]); | |
| 268 | + return $oLink; | |
| 269 | +} | |
| 270 | + | |
| 271 | +?> | ... | ... |