Annotation of /mambo/branches/4.6/administrator/components/com_contact/admin.contact.php
Parent Directory
|
Revision Log
Revision 905 - (view) (download)
| 1 : | alwarren | 905 | <?php |
| 2 : | /** | ||
| 3 : | * @package Mambo Open Source | ||
| 4 : | * @subpackage Contact | ||
| 5 : | * @copyright (C) 2005 - 2006 Mambo Foundation Inc. | ||
| 6 : | * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL | ||
| 7 : | * | ||
| 8 : | * Mambo was originally developed by Miro (www.miro.com.au) in 2000. Miro assigned the copyright in Mambo to The Mambo Foundation in 2005 to ensure | ||
| 9 : | * that Mambo remained free Open Source software owned and managed by the community. | ||
| 10 : | * Mambo is Free Software | ||
| 11 : | */ | ||
| 12 : | |||
| 13 : | /** ensure this file is being included by a parent file */ | ||
| 14 : | defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' ); | ||
| 15 : | |||
| 16 : | // ensure user has access to this function | ||
| 17 : | if (!($acl->acl_check( 'administration', 'edit', 'users', $my->usertype, 'components', 'all' ) | ||
| 18 : | | $acl->acl_check( 'administration', 'edit', 'users', $my->usertype, 'components', 'com_contact' ))) { | ||
| 19 : | mosRedirect( 'index2.php', T_('You are not authorized to view this resource.') ); | ||
| 20 : | } | ||
| 21 : | |||
| 22 : | require_once( $mainframe->getPath( 'admin_html' ) ); | ||
| 23 : | require_once( $mainframe->getPath( 'class' ) ); | ||
| 24 : | |||
| 25 : | $id = mosGetParam($_GET, 'id', 0); | ||
| 26 : | $cid = mosGetParam($_POST, 'cid', array(0)); | ||
| 27 : | if (!is_array( $cid )) $cid = array(0); | ||
| 28 : | |||
| 29 : | switch ($task) { | ||
| 30 : | |||
| 31 : | case 'new': | ||
| 32 : | editContact( '0', $option); | ||
| 33 : | break; | ||
| 34 : | |||
| 35 : | case 'edit': | ||
| 36 : | editContact( $cid[0], $option ); | ||
| 37 : | break; | ||
| 38 : | |||
| 39 : | case 'editA': | ||
| 40 : | editContact( $id, $option ); | ||
| 41 : | break; | ||
| 42 : | |||
| 43 : | case 'save': | ||
| 44 : | saveContact( $option ); | ||
| 45 : | break; | ||
| 46 : | |||
| 47 : | case 'remove': | ||
| 48 : | removeContacts( $cid, $option ); | ||
| 49 : | break; | ||
| 50 : | |||
| 51 : | case 'publish': | ||
| 52 : | changeContact( $cid, 1, $option ); | ||
| 53 : | break; | ||
| 54 : | |||
| 55 : | case 'unpublish': | ||
| 56 : | changeContact( $cid, 0, $option ); | ||
| 57 : | break; | ||
| 58 : | |||
| 59 : | case 'orderup': | ||
| 60 : | orderContacts( $cid[0], -1, $option ); | ||
| 61 : | break; | ||
| 62 : | |||
| 63 : | case 'orderdown': | ||
| 64 : | orderContacts( $cid[0], 1, $option ); | ||
| 65 : | break; | ||
| 66 : | |||
| 67 : | case 'cancel': | ||
| 68 : | cancelContact(); | ||
| 69 : | break; | ||
| 70 : | |||
| 71 : | default: | ||
| 72 : | showContacts( $option ); | ||
| 73 : | break; | ||
| 74 : | } | ||
| 75 : | |||
| 76 : | /** | ||
| 77 : | * List the records | ||
| 78 : | * @param string The current GET/POST option | ||
| 79 : | */ | ||
| 80 : | function showContacts( $option ) { | ||
| 81 : | global $database, $mainframe, $mosConfig_list_limit; | ||
| 82 : | |||
| 83 : | $catid = $mainframe->getUserStateFromRequest( "catid{$option}", 'catid', 0 ); | ||
| 84 : | $limit = $mainframe->getUserStateFromRequest( "viewlistlimit", 'limit', $mosConfig_list_limit ); | ||
| 85 : | $limitstart = $mainframe->getUserStateFromRequest( "view{$option}limitstart", 'limitstart', 0 ); | ||
| 86 : | $search = $mainframe->getUserStateFromRequest( "search{$option}", 'search', '' ); | ||
| 87 : | $search = $database->getEscaped( trim( strtolower( $search ) ) ); | ||
| 88 : | |||
| 89 : | if ( $search ) { | ||
| 90 : | $where[] = "cd.name LIKE '%$search%'"; | ||
| 91 : | } | ||
| 92 : | if ( $catid ) { | ||
| 93 : | $where[] = "cd.catid = '$catid'"; | ||
| 94 : | } | ||
| 95 : | if ( isset( $where ) ) { | ||
| 96 : | $where = "\n WHERE ". implode( ' AND ', $where ); | ||
| 97 : | } else { | ||
| 98 : | $where = ''; | ||
| 99 : | } | ||
| 100 : | |||
| 101 : | // get the total number of records | ||
| 102 : | $database->setQuery( "SELECT COUNT(*) FROM #__contact_details AS cd $where" ); | ||
| 103 : | $total = $database->loadResult(); | ||
| 104 : | |||
| 105 : | require_once( $GLOBALS['mosConfig_absolute_path'] . '/administrator/includes/pageNavigation.php' ); | ||
| 106 : | $pageNav = new mosPageNav( $total, $limitstart, $limit ); | ||
| 107 : | |||
| 108 : | // get the subset (based on limits) of required records | ||
| 109 : | $query = "SELECT cd.*, cc.title AS category, u.name AS user, v.name as editor" | ||
| 110 : | . "\n FROM #__contact_details AS cd" | ||
| 111 : | . "\n LEFT JOIN #__categories AS cc ON cc.id = cd.catid" | ||
| 112 : | . "\n LEFT JOIN #__users AS u ON u.id = cd.user_id" | ||
| 113 : | . "\n LEFT JOIN #__users AS v ON v.id = cd.checked_out" | ||
| 114 : | . $where | ||
| 115 : | . "\n ORDER BY cd.catid, cd.ordering, cd.name ASC" | ||
| 116 : | . "\n LIMIT $pageNav->limitstart, $pageNav->limit" | ||
| 117 : | ; | ||
| 118 : | $database->setQuery( $query ); | ||
| 119 : | $rows = $database->loadObjectList(); | ||
| 120 : | |||
| 121 : | // build list of categories | ||
| 122 : | $javascript = 'onchange="document.adminForm.submit();"'; | ||
| 123 : | $lists['catid'] = mosAdminMenus::ComponentCategory( 'catid', 'com_contact_details', intval( $catid ), $javascript ); | ||
| 124 : | |||
| 125 : | HTML_contact::showcontacts( $rows, $pageNav, $search, $option, $lists ); | ||
| 126 : | } | ||
| 127 : | |||
| 128 : | /** | ||
| 129 : | * Creates a new or edits and existing user record | ||
| 130 : | * @param int The id of the record, 0 if a new entry | ||
| 131 : | * @param string The current GET/POST option | ||
| 132 : | */ | ||
| 133 : | function editContact( $id, $option ) { | ||
| 134 : | global $database, $my; | ||
| 135 : | global $mosConfig_absolute_path; | ||
| 136 : | |||
| 137 : | $row = new mosContact( $database ); | ||
| 138 : | // load the row from the db table | ||
| 139 : | $row->load( $id ); | ||
| 140 : | |||
| 141 : | if ($id) { | ||
| 142 : | // do stuff for existing records | ||
| 143 : | $row->checkout($my->id); | ||
| 144 : | } else { | ||
| 145 : | // do stuff for new records | ||
| 146 : | $row->imagepos = 'top'; | ||
| 147 : | $row->ordering = 0; | ||
| 148 : | $row->published = 1; | ||
| 149 : | } | ||
| 150 : | $lists = array(); | ||
| 151 : | |||
| 152 : | // build the html select list for ordering | ||
| 153 : | $query = "SELECT ordering AS value, name AS text" | ||
| 154 : | . "\n FROM #__contact_details" | ||
| 155 : | . "\n WHERE published >= 0" | ||
| 156 : | . "\n AND catid = '$row->catid'" | ||
| 157 : | . "\n ORDER BY ordering" | ||
| 158 : | ; | ||
| 159 : | $lists['ordering'] = mosAdminMenus::SpecificOrdering( $row, $id, $query, 1 ); | ||
| 160 : | |||
| 161 : | // build list of users | ||
| 162 : | $lists['user_id'] = mosAdminMenus::UserSelect( 'user_id', $row->user_id, 1 ); | ||
| 163 : | // build list of categories | ||
| 164 : | $lists['catid'] = mosAdminMenus::ComponentCategory( 'catid', 'com_contact_details', intval( $row->catid ) ); | ||
| 165 : | // build the html select list for images | ||
| 166 : | $lists['image'] = mosAdminMenus::Images( 'image', $row->image ); | ||
| 167 : | // build the html select list for the group access | ||
| 168 : | $lists['access'] = mosAdminMenus::Access( $row ); | ||
| 169 : | // build the html radio buttons for published | ||
| 170 : | $lists['published'] = mosHTML::yesnoradioList( 'published', '', $row->published ); | ||
| 171 : | // build the html radio buttons for default | ||
| 172 : | $lists['default_con'] = mosHTML::yesnoradioList( 'default_con', '', $row->default_con ); | ||
| 173 : | |||
| 174 : | // get params definitions | ||
| 175 : | $file = $mosConfig_absolute_path .'/administrator/components/com_contact/contact_items.xml'; | ||
| 176 : | $params =& new mosAdminParameters( $row->params, $file, 'component' ); | ||
| 177 : | |||
| 178 : | HTML_contact::editcontact( $row, $lists, $option, $params ); | ||
| 179 : | } | ||
| 180 : | |||
| 181 : | /** | ||
| 182 : | * Saves the record from an edit form submit | ||
| 183 : | * @param string The current GET/POST option | ||
| 184 : | */ | ||
| 185 : | function saveContact( $option ) { | ||
| 186 : | global $database; | ||
| 187 : | |||
| 188 : | $row = new mosContact( $database ); | ||
| 189 : | if (!$row->bind( $_POST )) { | ||
| 190 : | echo "<script> alert('".$row->getError()."'); window.history.go(-1); </script>\n"; | ||
| 191 : | exit(); | ||
| 192 : | } | ||
| 193 : | |||
| 194 : | // save params | ||
| 195 : | $params = mosGetParam( $_POST, 'params', '' ); | ||
| 196 : | if (is_array( $params )) { | ||
| 197 : | $txt = array(); | ||
| 198 : | foreach ( $params as $k=>$v) { | ||
| 199 : | $txt[] = "$k=$v"; | ||
| 200 : | } | ||
| 201 : | $row->params = implode( "\n", $txt ); | ||
| 202 : | } | ||
| 203 : | |||
| 204 : | // pre-save checks | ||
| 205 : | if (!$row->check()) { | ||
| 206 : | echo "<script> alert('".$row->getError()."'); window.history.go(-1); </script>\n"; | ||
| 207 : | exit(); | ||
| 208 : | } | ||
| 209 : | |||
| 210 : | // save the changes | ||
| 211 : | if (!$row->store()) { | ||
| 212 : | echo "<script> alert('".$row->getError()."'); window.history.go(-1); </script>\n"; | ||
| 213 : | exit(); | ||
| 214 : | } | ||
| 215 : | $row->checkin(); | ||
| 216 : | $row->updateOrder(); | ||
| 217 : | if ($row->default_con) { | ||
| 218 : | $database->setQuery( "UPDATE #__contact_details SET default_con='0' WHERE id <> $row->id AND default_con='1'" ); | ||
| 219 : | $database->query(); | ||
| 220 : | } | ||
| 221 : | |||
| 222 : | mosRedirect( "index2.php?option=$option" ); | ||
| 223 : | } | ||
| 224 : | |||
| 225 : | /** | ||
| 226 : | * Removes records | ||
| 227 : | * @param array An array of id keys to remove | ||
| 228 : | * @param string The current GET/POST option | ||
| 229 : | */ | ||
| 230 : | function removeContacts( &$cid, $option ) { | ||
| 231 : | global $database; | ||
| 232 : | |||
| 233 : | if (count( $cid )) { | ||
| 234 : | $cids = implode( ',', $cid ); | ||
| 235 : | $database->setQuery( "DELETE FROM #__contact_details WHERE id IN ($cids)" ); | ||
| 236 : | if (!$database->query()) { | ||
| 237 : | echo "<script> alert('".$database->getErrorMsg()."'); window.history.go(-1); </script>\n"; | ||
| 238 : | } | ||
| 239 : | } | ||
| 240 : | |||
| 241 : | mosRedirect( "index2.php?option=$option" ); | ||
| 242 : | } | ||
| 243 : | |||
| 244 : | /** | ||
| 245 : | * Changes the state of one or more content pages | ||
| 246 : | * @param array An array of unique category id numbers | ||
| 247 : | * @param integer 0 if unpublishing, 1 if publishing | ||
| 248 : | * @param string The current option | ||
| 249 : | */ | ||
| 250 : | function changeContact( $cid=null, $state=0, $option ) { | ||
| 251 : | global $database, $my; | ||
| 252 : | |||
| 253 : | if (count( $cid ) < 1) { | ||
| 254 : | $action = $state == 1 ? 'publish' : 'unpublish'; | ||
| 255 : | echo "<script> alert('".sprintf(T_('Select a record to %s'),$action)."'); window.history.go(-1);</script>\n"; | ||
| 256 : | exit; | ||
| 257 : | } | ||
| 258 : | |||
| 259 : | $cids = implode( ',', $cid ); | ||
| 260 : | |||
| 261 : | $database->setQuery( "UPDATE #__contact_details SET published='$state'" | ||
| 262 : | . "\nWHERE id IN ($cids) AND (checked_out=0 OR (checked_out='$my->id'))" | ||
| 263 : | ); | ||
| 264 : | if (!$database->query()) { | ||
| 265 : | echo "<script> alert('".$database->getErrorMsg()."'); window.history.go(-1); </script>\n"; | ||
| 266 : | exit(); | ||
| 267 : | } | ||
| 268 : | |||
| 269 : | if (count( $cid ) == 1) { | ||
| 270 : | $row = new mosContact( $database ); | ||
| 271 : | $row->checkin( intval( $cid[0] ) ); | ||
| 272 : | } | ||
| 273 : | |||
| 274 : | mosRedirect( "index2.php?option=$option" ); | ||
| 275 : | } | ||
| 276 : | |||
| 277 : | /** JJC | ||
| 278 : | * Moves the order of a record | ||
| 279 : | * @param integer The increment to reorder by | ||
| 280 : | */ | ||
| 281 : | function orderContacts( $uid, $inc, $option ) { | ||
| 282 : | global $database; | ||
| 283 : | |||
| 284 : | $row = new mosContact( $database ); | ||
| 285 : | $row->load( $uid ); | ||
| 286 : | $row->move( $inc, "published >= 0" ); | ||
| 287 : | |||
| 288 : | mosRedirect( "index2.php?option=$option" ); | ||
| 289 : | } | ||
| 290 : | |||
| 291 : | /** PT | ||
| 292 : | * Cancels editing and checks in the record | ||
| 293 : | */ | ||
| 294 : | function cancelContact() { | ||
| 295 : | global $database; | ||
| 296 : | |||
| 297 : | $row = new mosContact( $database ); | ||
| 298 : | $row->bind( $_POST ); | ||
| 299 : | // sanitize | ||
| 300 : | $row->id = intval($row->id); | ||
| 301 : | $row->checkin(); | ||
| 302 : | mosRedirect('index2.php?option=com_contact'); | ||
| 303 : | } | ||
| 304 : | ?> |
| ViewVC Help | |
| Powered by ViewVC 1.0.0 |
Web Hosting provided by Network Redux.

