[ Index ] |
|
Code source de CMS made simple 1.0.5 |
1 <?php 2 #CMS - CMS Made Simple 3 #(c)2004 by Ted Kulp (tedkulp@users.sf.net) 4 #This project's homepage is: http://cmsmadesimple.org 5 # 6 #This program is free software; you can redistribute it and/or modify 7 #it under the terms of the GNU General Public License as published by 8 #the Free Software Foundation; either version 2 of the License, or 9 #(at your option) any later version. 10 # 11 #This program is distributed in the hope that it will be useful, 12 #BUT withOUT ANY WARRANTY; without even the implied warranty of 13 #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 #GNU General Public License for more details. 15 #You should have received a copy of the GNU General Public License 16 #along with this program; if not, write to the Free Software 17 #Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 # 19 #$Id$ 20 21 /** 22 * Class for doing bookmark related functions. Maybe of the Bookmark object functions 23 * are just wrappers around these. 24 * 25 * @package CMS 26 */ 27 28 include_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'class.bookmark.inc.php'); 29 30 class BookmarkOperations 31 { 32 /** 33 * Gets a list of all bookmarks for a given user 34 * 35 * @returns array An array of Bookmark objects 36 */ 37 function LoadBookmarks($user_id) 38 { 39 global $gCms; 40 $db = &$gCms->GetDb(); 41 42 $result = array(); 43 44 $query = "SELECT bookmark_id, user_id, title, url FROM ".cms_db_prefix()."admin_bookmarks WHERE user_id = ? ORDER BY title"; 45 $dbresult = $db->Execute($query, array($user_id)); 46 47 while ($dbresult && $row = $dbresult->FetchRow()) 48 { 49 $onemark = new Bookmark(); 50 $onemark->bookmark_id = $row['bookmark_id']; 51 $onemark->user_id = $row['user_id']; 52 $onemark->url = $row['url']; 53 $onemark->title = $row['title']; 54 $result[] = $onemark; 55 } 56 57 return $result; 58 } 59 60 /** 61 * Loads a bookmark by bookmark_id. 62 * 63 * @param mixed $id bookmark_id to load 64 * 65 * @returns mixed If successful, the filled Bookmark object. If it fails, it returns false. 66 * @since 0.6.1 67 */ 68 function LoadBookmarkByID($id) 69 { 70 $result = false; 71 72 global $gCms; 73 $db = &$gCms->GetDb(); 74 75 $query = "SELECT bookmark_id, user_id, title, url FROM ".cms_db_prefix()."admin_bookmarks WHERE bookmark_id = ?"; 76 $dbresult = $db->Execute($query, array($id)); 77 78 while ($dbresult && $row = $dbresult->FetchRow()) 79 { 80 $onemark = new Bookmark(); 81 $onemark->bookmark_id = $row['bookmark_id']; 82 $onemark->user_id = $row['user_id']; 83 $onemark->url = $row['url']; 84 $onemark->title = $row['title']; 85 $result = $onemark; 86 } 87 88 return $result; 89 } 90 91 /** 92 * Saves a new bookmark to the database. 93 * 94 * @param mixed $bookmark Bookmark object to save 95 * 96 * @returns mixed The new bookmark_id. If it fails, it returns -1. 97 */ 98 function InsertBookmark($bookmark) 99 { 100 $result = -1; 101 102 global $gCms; 103 $db = &$gCms->GetDb(); 104 105 $new_bookmark_id = $db->GenID(cms_db_prefix()."admin_bookmarks_seq"); 106 $query = "INSERT INTO ".cms_db_prefix()."admin_bookmarks (bookmark_id, user_id, url, title) VALUES (?,?,?,?)"; 107 $dbresult = $db->Execute($query, array($new_bookmark_id, $bookmark->user_id, $bookmark->url, $bookmark->title)); 108 if ($dbresult !== false) 109 { 110 $result = $new_bookmark_id; 111 } 112 113 return $result; 114 } 115 116 /** 117 * Updates an existing bookmark in the database. 118 * 119 * @param mixed $bookmark Bookmark object to save 120 * 121 * @returns mixed If successful, true. If it fails, false. 122 */ 123 function UpdateBookmark($bookmark) 124 { 125 $result = false; 126 127 global $gCms; 128 $db = &$gCms->GetDb(); 129 130 $query = "UPDATE ".cms_db_prefix()."admin_bookmarks SET user_id = ?, title = ?, url = ? WHERE bookmark_id = ?"; 131 $dbresult = $db->Execute($query, array($bookmark->user_id, $bookmark->title, $bookmark->url, $bookmark->bookmark_id)); 132 if ($dbresult !== false) 133 { 134 $result = true; 135 } 136 137 return $result; 138 } 139 140 /** 141 * Deletes an existing bookmark from the database. 142 * 143 * @param mixed $id Id of the bookmark to delete 144 * 145 * @returns mixed If successful, true. If it fails, false. 146 */ 147 function DeleteBookmarkByID($id) 148 { 149 $result = false; 150 151 global $gCms; 152 $db = &$gCms->GetDb(); 153 154 $query = "DELETE FROM ".cms_db_prefix()."admin_bookmarks where bookmark_id = ?"; 155 $db->Execute($query, array($id)); 156 157 if ($dbresult !== false) 158 { 159 $result = true; 160 } 161 return $result; 162 } 163 } 164 165 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Tue Apr 3 18:50:37 2007 | par Balluche grâce à PHPXref 0.7 |