Commit bcc5207909088ecfe4ecfde7f6a52e21d6fb75f6
1 parent
f3ad5f25
Initial revision. Object that represents web_sites table in database
git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@366 c91229c3-7414-0410-bfa2-8a42b809f60b
Showing
1 changed file
with
160 additions
and
0 deletions
lib/web/WebSite.inc
0 → 100644
| 1 | +<?php | |
| 2 | + | |
| 3 | +/** | |
| 4 | +* @package lib.web | |
| 5 | +* | |
| 6 | +* Class WebSite | |
| 7 | +* Represents a web site as per the web_sites database table | |
| 8 | +* | |
| 9 | +* @author Rob Cherry, Jam Warehouse (Pty) Ltd, South Africa | |
| 10 | +* @date 20 January 2003 | |
| 11 | +*/ | |
| 12 | + | |
| 13 | +class WebSite { | |
| 14 | + | |
| 15 | + /** primary key of web site */ | |
| 16 | + var $iId; | |
| 17 | + /** web site name */ | |
| 18 | + var $sWebSiteName; | |
| 19 | + /** web site url */ | |
| 20 | + var $sWebSiteURL; | |
| 21 | + /** primary key of user responsible for web site */ | |
| 22 | + var $iWebMasterID; | |
| 23 | + | |
| 24 | + /** | |
| 25 | + * Default constructor | |
| 26 | + * | |
| 27 | + * @param String Name of web site | |
| 28 | + * @param String Web site URL | |
| 29 | + * @param int Primary key of user who is the web site master | |
| 30 | + * | |
| 31 | + */ | |
| 32 | + function WebSite($sNewWebSiteName, $sNewWebSiteURL, $iNewWebMasterID) { | |
| 33 | + //object not created in database yet | |
| 34 | + $this->iId = -1; | |
| 35 | + $this->sWebSiteName = $sNewWebSiteName; | |
| 36 | + $this->sWebSiteURL = $sNewWebSiteURL; | |
| 37 | + $this->iWebMasterID = $iNewWebMasterID; | |
| 38 | + } | |
| 39 | + | |
| 40 | + /** | |
| 41 | + * Create the current object in the database | |
| 42 | + * | |
| 43 | + * @return boolean on successful store, false otherwise and set $_SESSION["errorMessage"] | |
| 44 | + * | |
| 45 | + */ | |
| 46 | + function create() { | |
| 47 | + global $default, $lang_err_database, $lang_err_object_exists; | |
| 48 | + //if the object hasn't been created | |
| 49 | + if ($this->iId < 0) { | |
| 50 | + $sql = new Owl_DB(); | |
| 51 | + $result = $sql->query("INSERT INTO " . $default->owl_web_sites_table . " (web_site_name, web_site_url, web_master_id) VALUES ('" . addslashes($this->sWebSiteName) . "', '" . addslashes($this->sWebSiteURL) . "', $this->iWebMasterID)"); | |
| 52 | + if ($result) { | |
| 53 | + $this->iId = $sql->insert_id(); | |
| 54 | + return true; | |
| 55 | + } | |
| 56 | + $_SESSION["errorMessage"] = $lang_err_database; | |
| 57 | + return false; | |
| 58 | + } | |
| 59 | + $_SESSION["errorMessage"] = $lang_err_object_exists . "id = " . $this->iId . " table = $default->owl_web_sites_table"; | |
| 60 | + return false; | |
| 61 | + } | |
| 62 | + | |
| 63 | + /** | |
| 64 | + * Update the values in the database table with the object's current values | |
| 65 | + * | |
| 66 | + * @return boolean true on successful update, false otherwise and set $_SESSION["errorMessage"] | |
| 67 | + * | |
| 68 | + */ | |
| 69 | + function update() { | |
| 70 | + global $default, $lang_err_database, $lang_err_object_key; | |
| 71 | + //only update if the object has been stored | |
| 72 | + if ($this->iId > 0) { | |
| 73 | + $sql = new Owl_DB(); | |
| 74 | + $result = $sql->query("UPDATE " . $default->owl_web_sites_table . " SET web_site_name = '" . addslashes($this->sWebSiteName) . "', web_site_url = '" . addslashes($this->sWebSiteURL) . "', web_master_id = $this->iWebMasterID WHERE id = $this->iId"); | |
| 75 | + if ($result) { | |
| 76 | + return true; | |
| 77 | + } | |
| 78 | + $_SESSION["errorMessage"] = $lang_err_database; | |
| 79 | + return false; | |
| 80 | + } | |
| 81 | + $_SESSION["errorMessage"] = $lang_err_object_key; | |
| 82 | + return false; | |
| 83 | + } | |
| 84 | + | |
| 85 | + /** | |
| 86 | + * Delete the current object from the database | |
| 87 | + * | |
| 88 | + * @return boolean true on successful deletion, false otherwise and set $_SESSION["errorMessage"] | |
| 89 | + * | |
| 90 | + */ | |
| 91 | + function delete() { | |
| 92 | + global $default, $lang_err_database, $lang_err_object_key; | |
| 93 | + //only delete the object if it exists in the database | |
| 94 | + if ($this->iId >= 0) { | |
| 95 | + $sql = new Owl_DB(); | |
| 96 | + $result = $sql->query("DELETE FROM $default->owl_web_sites_table WHERE id = $this->iId"); | |
| 97 | + if ($result) { | |
| 98 | + return true; | |
| 99 | + } | |
| 100 | + $_SESSION["errorMessage"] = $lang_err_database; | |
| 101 | + return false; | |
| 102 | + } | |
| 103 | + $_SESSION["errorMessage"] = $lang_err_object_key; | |
| 104 | + return false; | |
| 105 | + } | |
| 106 | + | |
| 107 | + /** | |
| 108 | + * Static function. | |
| 109 | + * Given a web_sites primary key it will create a | |
| 110 | + * WebSite object and populate it with the | |
| 111 | + * corresponding database values | |
| 112 | + * | |
| 113 | + * @return WebSite populated WebSite object on successful query, false otherwise and set $_SESSION["errorMessage"] | |
| 114 | + */ | |
| 115 | + function & get($iWebSiteID) { | |
| 116 | + global $default; | |
| 117 | + $sql = new Owl_DB(); | |
| 118 | + $result = $sql->query("SELECT * FROM $default->owl_web_sites_table WHERE id = $iWebSiteID"); | |
| 119 | + if ($result) { | |
| 120 | + if ($sql->next_record()) { | |
| 121 | + $oWebSite = & new WebSite(stripslashes($sql->f("web_site_name")), stripslashes($sql->f("web_site_url")), $sql->f("web_master_id")); | |
| 122 | + $oWebSite->iId = $iWebSiteID; | |
| 123 | + return $oWebSite; | |
| 124 | + } | |
| 125 | + $_SESSION["errorMessage"] = $lang_err_object_not_exist . "id = " . $iWebSiteID . " table = $default->owl_web_sites_table"; | |
| 126 | + return false; | |
| 127 | + } | |
| 128 | + $_SESSION["errorMessage"] = $lang_err_database; | |
| 129 | + return false; | |
| 130 | + } | |
| 131 | + | |
| 132 | + /** | |
| 133 | + * Static function | |
| 134 | + * Get a list of web sites | |
| 135 | + * | |
| 136 | + * @return Array array of WebSite objects, false otherwise and set $_SESSION["errorMessage"] | |
| 137 | + */ | |
| 138 | + function getList() { | |
| 139 | + global $default, $lang_err_database; | |
| 140 | + $aWebSiteArray; | |
| 141 | + settype($aWebSiteArray, "array"); | |
| 142 | + $sql = new Owl_DB(); | |
| 143 | + $result = $sql->query("SELECT * FROM " . $default->owl_web_sites_table); | |
| 144 | + if ($result) { | |
| 145 | + $iCount = 0; | |
| 146 | + while ($sql->next_record()) { | |
| 147 | + $oWebSite = & WebSite::get($sql->f("id")); | |
| 148 | + $aWebSiteArray[$iCount] = $oWebSite; | |
| 149 | + $iCount++; | |
| 150 | + } | |
| 151 | + return $aWebSiteArray; | |
| 152 | + } | |
| 153 | + $_SESSION["errorMessage"] = $lang_err_database; | |
| 154 | + return false; | |
| 155 | + } | |
| 156 | + | |
| 157 | + | |
| 158 | +} | |
| 159 | + | |
| 160 | +?> | ... | ... |