Parent Directory
|
Revision Log
|
Revision Graph
*** empty log message ***
| 1 | <?php |
| 2 | |
| 3 | // $Id: $ |
| 4 | |
| 5 | /******************************************************************** |
| 6 | * Display |
| 7 | ********************************************************************/ |
| 8 | |
| 9 | /** |
| 10 | * Display single business |
| 11 | */ |
| 12 | function theme_node_business($node, $teaser = 0, $page = 0) { |
| 13 | // Don't bother if this isn't a business |
| 14 | if ($node->type == 'business' && $teaser == false) { |
| 15 | |
| 16 | $_COOKIE['bid'] = $node->nid; |
| 17 | $output .= '<div class="availability"></div>'; |
| 18 | |
| 19 | // Include business type-specific info |
| 20 | $f = "theme_" . $node->ptype . '_view'; |
| 21 | if (function_exists($f)) { |
| 22 | $output .= theme($node->ptype . '_view', $node, $teaser, $page); |
| 23 | } |
| 24 | business_invoke_businessapi($node, 'view', $teaser, $page); |
| 25 | $output .= $node->content['units_list']['#value']; |
| 26 | unset ($node->content['units_list']); |
| 27 | $output .= '<div class="businessdetails"><h4>Business details</h4>'; |
| 28 | $output .= '<dl class="business">'; |
| 29 | if ($node->location['street']) { |
| 30 | $output .= '<dd>' . t('Address') . ': ' . $node->location['street'] . ", " . $node->location['city'] . '</dd>'; |
| 31 | } |
| 32 | if ($node->ptype == 'hotel') { |
| 33 | $details = false; |
| 34 | } else { |
| 35 | $details = true; |
| 36 | } |
| 37 | if ($node->phone && (variable_get('busines_contact', 1) || $details || user_access('administer accommodation'))) { |
| 38 | $output .= '<dd>' . t('Phone') . ': ' . $node->phone . '</dd>'; |
| 39 | } |
| 40 | if ($node->altphone && (variable_get('busines_contact', 1) || $details || user_access('administer accommodation'))) { |
| 41 | $output .= '<dd>' . t('Alternate phone') . ': ' . $node->altphone . '</dd>'; |
| 42 | } |
| 43 | if ($node->fax && (variable_get('busines_contact', 1) || $details || user_access('administer accommodation'))) { |
| 44 | $output .= '<dd>' . t('Fax') . ': ' . $node->fax . '</dd>'; |
| 45 | } |
| 46 | if ($node->www && (variable_get('busines_contact', 1) || $details || user_access('administer accommodation'))) { |
| 47 | if (strpos($node->www, "http://") !== false) { |
| 48 | $ouputnode = l(substr($node->www, 7), $node->www); |
| 49 | } else { |
| 50 | $ouputnode = l($node->www, "http://" . $node->www); |
| 51 | } |
| 52 | $output .= '<dd>' . t('Homepage') . ': ' . $ouputnode . '</dd>'; |
| 53 | } |
| 54 | if ($node->email && (variable_get('busines_contact', 1) || $details || user_access('administer accommodation'))) { |
| 55 | $output .= '<dd>' . t('Email') . ': ' . check_markup($node->email). '</dd>'; |
| 56 | } |
| 57 | if ($node->chambermember && variable_get('business_chamber', false)) { |
| 58 | $output .= '<dd>' . variable_get('business_chamber_text', 'Member of the Chamber of Commerce') . '</dd>'; |
| 59 | } |
| 60 | if ($node->files) { |
| 61 | foreach ($node->files as $file) { |
| 62 | if ($file->filemime == "application/pdf") { |
| 63 | $output .= '<dd><br /><a href="' . url($file->filepath) . '" onclick="window.open(this.href,\'external\'); return false;" >' . $file->description . '</a></dd>'; |
| 64 | } |
| 65 | } |
| 66 | } |
| 67 | $output .= '</dl></div>'; |
| 68 | |
| 69 | $usegmap = (function_exists('gmap_set_location') && variable_get('location_usegmap', 1)); |
| 70 | if ($usegmap) { |
| 71 | if ($node->location['latitude'] && $node->location['latitude'] != 0) { |
| 72 | $latitude = $node->location['latitude']; |
| 73 | } else { |
| 74 | $latitude = null; |
| 75 | } |
| 76 | if ($node->location['longitude'] && $node->location['longitude'] != 0) { |
| 77 | $longitude = $node->location['longitude']; |
| 78 | } else { |
| 79 | $longitude = null; |
| 80 | } |
| 81 | if ($latitude != null || $longitude != null) { |
| 82 | $path = drupal_get_path('module', 'gmap') . '/js/'; |
| 83 | $defaults = gmap_defaults(); |
| 84 | |
| 85 | //load default array and then get the zoom level |
| 86 | $map_macro = '[gmap|center=' . $latitude . ',' . $longitude . '|zoom=' . $defaults['zoom'] . '|width=100%|height=400px|markers=blue::' . $latitude . ',' . $longitude . ':' . $node->title . ']'; |
| 87 | $temp['#settings'] = gmap_parse_macro($map_macro); |
| 88 | $temp['#settings']['id'] = 'loc1'; |
| 89 | $output .= theme('gmap', $temp); |
| 90 | //temp fix array is built but not processed once module is fixed this code can be removed |
| 91 | drupal_add_js($path . 'icon.js'); |
| 92 | drupal_add_js($path . 'gmap_marker.js'); |
| 93 | drupal_add_js($path . 'markerloader_static.js'); |
| 94 | } |
| 95 | } |
| 96 | } |
| 97 | return $output; |
| 98 | } |
| 99 | |
| 100 | /** |
| 101 | * Display a collection of businesses |
| 102 | */ |
| 103 | function theme_business_collection($vid = null, $tid = null) { |
| 104 | $pageitems = 6; |
| 105 | |
| 106 | if ($tid) { |
| 107 | $tids[] = "t.tid = " . $tid; |
| 108 | if ($children = taxonomy_get_tree($vid, $tid, -1, 1)) { |
| 109 | foreach ($children as $child) { |
| 110 | $tids[] = "t.tid = " . $child->tid; |
| 111 | } |
| 112 | } |
| 113 | $tid_where = "(" . join(" OR ", $tids) . ")"; |
| 114 | $sql = "SELECT DISTINCT n.nid FROM {node} n INNER JOIN {term_node} t ON n.nid = t.nid INNER JOIN {business} b ON n.nid = b.nid WHERE n.type = 'business' AND n.status = 1 AND %s ORDER BY n.sticky DESC, n.changed DESC"; |
| 115 | $args = array (); |
| 116 | $args[] = $tid_where; |
| 117 | } else { |
| 118 | $sql = "SELECT DISTINCT n.nid FROM {node} n INNER JOIN {business} b ON n.nid = b.nid WHERE n.type = 'business' AND n.status = 1 ORDER BY n.sticky DESC, n.changed DESC"; |
| 119 | $args = array (); |
| 120 | } |
| 121 | $count_query = preg_replace(array ( |
| 122 | '/SELECT.*?FROM /As', |
| 123 | '/ORDER BY .*/' |
| 124 | ), array ( |
| 125 | 'SELECT COUNT(DISTINCT n.nid) FROM ', |
| 126 | '' |
| 127 | ), $sql); |
| 128 | $result = pager_query(db_rewrite_sql($sql), $pageitems, 0, $count_query, $args); |
| 129 | $output .= '<div class="business">' . "\n"; |
| 130 | $businesses = false; |
| 131 | for ($i = 0; $node = db_fetch_object($result); $i++) { |
| 132 | $node = node_load($node->nid); |
| 133 | |
| 134 | $businesses = true; |
| 135 | node_invoke_nodeapi($node, 'view', true, false); |
| 136 | $image_attach = ''; |
| 137 | if (module_exists('image_attach')) { |
| 138 | $image_attach = $node->content['image_attach']['#value']; |
| 139 | } |
| 140 | $review = ''; |
| 141 | if (function_exists('theme_nodereview_business_teaser')) { |
| 142 | $review = theme('nodereview_business_teaser', $node); |
| 143 | } |
| 144 | $more = rtrim($node->teaser, "</p>\n") . " " . t('<span class="read-more"><a href="@url">more info »</a></span></p>', array ( |
| 145 | '@url' => url("node/$node->nid") |
| 146 | )); |
| 147 | $output .= '<div class="teaser"><fieldset>' . $image_attach . '<h3>' . l($node->title, "node/$node->nid") . "</h3>\n" . $review . $more . "</fieldset></div><!-- end teaser -->\n"; |
| 148 | } |
| 149 | if (!$businesses) { |
| 150 | $output .= t('No businesses exist for this category'); |
| 151 | } |
| 152 | $output .= "</div><!-- end business -->\n"; |
| 153 | |
| 154 | if ($pager = theme('pager', NULL, $pageitems, 0)) { |
| 155 | $output .= $pager; |
| 156 | } |
| 157 | return $output; |
| 158 | } |
| 159 | |
| 160 | function business_access($op, $node) { |
| 161 | global $user; |
| 162 | |
| 163 | if ($op == 'create' && user_access('create businesses')) { |
| 164 | return TRUE; |
| 165 | } |
| 166 | |
| 167 | if ($op == 'update' || $op == 'delete') { |
| 168 | if (user_access('edit own businesses') && ($user->uid == $node->uid)) { |
| 169 | return TRUE; |
| 170 | } |
| 171 | } |
| 172 | } |
| 173 | |
| 174 | /** |
| 175 | * Implementation of hook_perm(). |
| 176 | */ |
| 177 | function business_perm() { |
| 178 | return array ( |
| 179 | 'administer businesses', |
| 180 | 'create businesses', |
| 181 | 'edit own businesses', |
| 182 | 'update business type' |
| 183 | ); |
| 184 | } |
| 185 | |
| 186 | /** |
| 187 | * Implementation of hook_form(). |
| 188 | */ |
| 189 | function business_form(& $node, & $param) { |
| 190 | |
| 191 | /* Set form breadcrumb */ |
| 192 | $context = business_breadcrumb(); |
| 193 | |
| 194 | $form['title'] = array ( |
| 195 | '#type' => 'textfield', |
| 196 | '#title' => t('Business name'), |
| 197 | '#default_value' => $node->title, |
| 198 | '#size' => 60, |
| 199 | '#maxlength' => 128, |
| 200 | '#description' => NULL, |
| 201 | '#attributes' => NULL, |
| 202 | '#required' => TRUE, |
| 203 | '#weight' => -9, |
| 204 | |
| 205 | ); |
| 206 | $form['contact'] = array ( |
| 207 | '#type' => 'fieldset', |
| 208 | '#title' => t('Contact information'), |
| 209 | '#weight' => -8, |
| 210 | '#collapsible' => TRUE, |
| 211 | |
| 212 | ); |
| 213 | $form['contact']['phone'] = array ( |
| 214 | '#type' => 'textfield', |
| 215 | '#title' => t('Phone'), |
| 216 | '#default_value' => $node->phone, |
| 217 | '#size' => 25, |
| 218 | '#maxlength' => 50, |
| 219 | '#description' => '', |
| 220 | |
| 221 | ); |
| 222 | $form['contact']['altphone'] = array ( |
| 223 | '#type' => 'textfield', |
| 224 | '#title' => t('Alternate phone'), |
| 225 | '#default_value' => $node->altphone, |
| 226 | '#size' => 25, |
| 227 | '#maxlength' => 50, |
| 228 | '#description' => '', |
| 229 | |
| 230 | ); |
| 231 | $form['contact']['fax'] = array ( |
| 232 | '#type' => 'textfield', |
| 233 | '#title' => t('Fax'), |
| 234 | '#default_value' => $node->fax, |
| 235 | '#size' => 25, |
| 236 | '#maxlength' => 50, |
| 237 | '#description' => '', |
| 238 | |
| 239 | ); |
| 240 | $form['contact']['www'] = array ( |
| 241 | '#type' => 'textfield', |
| 242 | '#title' => t('Homepage'), |
| 243 | '#default_value' => $node->www, |
| 244 | '#size' => 25, |
| 245 | '#maxlength' => 150, |
| 246 | '#description' => '', |
| 247 | |
| 248 | ); |
| 249 | $form['contact']['email'] = array ( |
| 250 | '#type' => 'textfield', |
| 251 | '#title' => t('Email'), |
| 252 | '#default_value' => $node->email, |
| 253 | '#size' => 25, |
| 254 | '#maxlength' => 150, |
| 255 | '#description' => '', |
| 256 | |
| 257 | ); |
| 258 | $form['description'] = array ( |
| 259 | '#type' => 'fieldset', |
| 260 | '#title' => t('Business description'), |
| 261 | '#weight' => -3, |
| 262 | '#collapsible' => TRUE, |
| 263 | |
| 264 | ); |
| 265 | $form['description']['teaser'] = array ( |
| 266 | '#type' => 'textarea', |
| 267 | '#title' => t('Short description'), |
| 268 | '#default_value' => $node->teaser, |
| 269 | '#cols' => 60, |
| 270 | '#rows' => 3, |
| 271 | '#required' => true, |
| 272 | '#description' => t('The short description will be shown when more than one business is listed on the page.'), |
| 273 | |
| 274 | ); |
| 275 | $form['description']['body'] = array ( |
| 276 | '#type' => 'textarea', |
| 277 | '#title' => t('Long description'), |
| 278 | '#default_value' => $node->body, |
| 279 | '#cols' => 60, |
| 280 | '#rows' => 10, |
| 281 | '#required' => true, |
| 282 | '#description' => t('The long description will be shown when your business is being displayed on its own.'), |
| 283 | |
| 284 | ); |
| 285 | $form['description']['format'] = filter_form($node->format); |
| 286 | if (user_access('administer businesses') && variable_get('business_chamber', false)) { |
| 287 | $form['general'] = array ( |
| 288 | '#type' => 'fieldset', |
| 289 | '#title' => t('General information'), |
| 290 | '#weight' => 0, |
| 291 | '#collapsible' => TRUE, |
| 292 | |
| 293 | ); |
| 294 | $form['general']['chambermember'] = array ( |
| 295 | '#type' => 'checkbox', |
| 296 | '#title' => t('Chamber of Commerce member'), |
| 297 | '#return_value' => true, |
| 298 | '#default_value' => $node->chambermember, |
| 299 | |
| 300 | ); |
| 301 | } |
| 302 | if (user_access('update business type')) { |
| 303 | $ptypes = business_invoke_businessapi($node, 'wizard_select'); |
| 304 | $form['businesstype'] = array ( |
| 305 | '#type' => 'fieldset', |
| 306 | '#title' => t('Enhanced business type'), |
| 307 | '#weight' => -3, |
| 308 | '#collapsible' => TRUE, |
| 309 | |
| 310 | ); |
| 311 | $form['businesstype']['ptype'] = array ( |
| 312 | '#type' => 'select', |
| 313 | '#title' => t('Business type'), |
| 314 | '#default_value' => $node->ptype, |
| 315 | '#options' => $ptypes, |
| 316 | '#description' => t('You can change to use our enhanced listing functionality at any time, if your business would benefit. We\'ll notify you if we add new functionality that would suit your business.'), |
| 317 | '#multiple' => NULL, |
| 318 | '#required' => TRUE, |
| 319 | |
| 320 | ); |
| 321 | } else { |
| 322 | $form['businesstype']['ptype'] = array ( |
| 323 | '#type' => 'hidden', |
| 324 | '#value' => $node->ptype, |
| 325 | |
| 326 | ); |
| 327 | } |
| 328 | |
| 329 | $form['submit'] = array ( |
| 330 | '#type' => 'submit', |
| 331 | '#value' => t('Submit') |
| 332 | ); |
| 333 | $form['#method'] = 'post'; |
| 334 | |
| 335 | // Get the business-type-specific bits. |
| 336 | |
| 337 | $form = array_merge($form, (array) module_invoke($node->ptype, 'businessapi', $node, 'form')); |
| 338 | |
| 339 | // If the business is bookable, ask if we want to bundle activity booking |
| 340 | if (module_invoke($node->ptype, 'businessapi', $node, 'is_bookable')) { |
| 341 | foreach (product_get_ptypes() as $ptype => $desc) { |
| 342 | if (module_invoke($ptype, 'businessapi', $node, 'is_activity')) { |
| 343 | $form = array_merge($form, (array) module_invoke($ptype, 'businessapi', $node, 'form')); |
| 344 | } |
| 345 | } |
| 346 | } |
| 347 | |
| 348 | return $form; |
| 349 | } |
| 350 | function business_format_address($list = array ()) { |
| 351 | $break = "\n"; |
| 352 | $address = ''; |
| 353 | while ($key = key($list)) { |
| 354 | $business = node_load($key); |
| 355 | |
| 356 | if ($business->type == 'business' && $business->ecommerce == '1') { |
| 357 | $address .= $business->title . $break; |
| 358 | $address .= $business->location['street'] . $break; |
| 359 | $address .= $business->location['city'] . $break; |
| 360 | $address .= $business->phone . $break; |
| 361 | |
| 362 | //now do google maps stuff |
| 363 | $usegmap = (function_exists('gmap_set_location') && variable_get('location_usegmap', 1)); |
| 364 | if ($usegmap) { |
| 365 | if ($business->location['latitude'] && $business->location['latitude'] != 0) { |
| 366 | $latitude = $business->location['latitude']; |
| 367 | } else { |
| 368 | $latitude = null; |
| 369 | } |
| 370 | if ($business->location['longitude'] && $business->location['longitude'] != 0) { |
| 371 | $longitude = $business->location['longitude']; |
| 372 | } else { |
| 373 | $longitude = null; |
| 374 | } |
| 375 | if ($latitude != null || $longitude != null) { |
| 376 | $address .= 'http://maps.google.com/maps?f=q&hl=en&q=' . $latitude . ',' . $longitude . '&z=12' . $break . $break; |
| 377 | } |
| 378 | |
| 379 | } |
| 380 | |
| 381 | $checkin = array (); |
| 382 | $count = 0; |
| 383 | while ($unit_key = key($list[$key])) { |
| 384 | $instructions = db_fetch_object(db_query('SELECT checkin, title FROM {accommodation_units} a JOIN {node} n ON n.nid = a.nid WHERE a.nid = %d', $unit_key)); |
| 385 | if (strlen($instructions->checkin) > 0) { |
| 386 | //stop issue with 2 rooms getting wrong count |
| 387 | if (!array_key_exists($unit_key, $checkin)) { |
| 388 | $checkin[$unit_key] = $instructions->title . ':' . $break . $instructions->checkin; |
| 389 | $count++; |
| 390 | } |
| 391 | } else { |
| 392 | $count++; |
| 393 | } |
| 394 | next($list[$key]); |
| 395 | } |
| 396 | if ((sizeof($checkin) < $count) && (strlen($business->checkin) > 0)) { |
| 397 | $checkin[$key] = $business->title . ':' . $break . $business->checkin; |
| 398 | } |
| 399 | if (sizeof($checkin) > 0) { |
| 400 | $address .= 'Checkin instructions' . $break . $break; |
| 401 | while ($instructions = key($checkin)) { |
| 402 | $address .= $checkin[$instructions] . $break; |
| 403 | next($checkin); |
| 404 | } |
| 405 | } |
| 406 | } |
| 407 | next($list); |
| 408 | } |
| 409 | return $address; |
| 410 | } |
| 411 | /** |
| 412 | * Implementation of hook_help(). |
| 413 | */ |
| 414 | function business_help($section = 'admin/help#business') { |
| 415 | $output = ""; |
| 416 | |
| 417 | switch ($section) { |
| 418 | |
| 419 | case 'node/add#business' : |
| 420 | $output = t("Creates a new business listing in the directory."); |
| 421 | break; |
| 422 | } |
| 423 | |
| 424 | return $output; |
| 425 | } |
| 426 | |
| 427 | /** |
| 428 | * Implementation of hook_load(). |
| 429 | */ |
| 430 | function business_load($node) { |
| 431 | static $business = array (); |
| 432 | $business_ammenities = array (); |
| 433 | |
| 434 | $business = db_fetch_object(db_query('SELECT * FROM {business} b WHERE b.nid = %d', $node->nid)); |
| 435 | /* Merge the business info for the specific type. */ |
| 436 | if ($business_type = module_invoke($business->ptype, 'businessapi', $business, 'load')) { |
| 437 | foreach ($business_type as $key => $value) { |
| 438 | $business-> $key = $value; |
| 439 | } |
| 440 | } |
| 441 | |
| 442 | $result = db_query("SELECT a.description,a.aid FROM {business_ammenities} a JOIN {business_ammenities_node} b ON a.aid = b.aid JOIN {business_ammenities_ptype} p ON a.aid = p.aid WHERE b.nid = %d AND p.ptype ='%s' ORDER BY weight,description", $node->nid, $business->ptype); |
| 443 | $count = 0; |
| 444 | while ($ammenities = db_fetch_object($result)) { |
| 445 | $business_ammenities[$ammenities->aid] = $ammenities->description; |
| 446 | $count++; |
| 447 | } |
| 448 | |
| 449 | if ($count > 0) { |
| 450 | $business->ammenties = $business_ammenities; |
| 451 | } |
| 452 | |
| 453 | return $business; |
| 454 | } |
| 455 | |
| 456 | /** |
| 457 | * Implmentation of menu_hook() |
| 458 | */ |
| 459 | function business_menu($may_cache) { |
| 460 | |
| 461 | $items = array (); |
| 462 | |
| 463 | if ($may_cache) { |
| 464 | $items[] = array ( |
| 465 | 'path' => 'admin/business', |
| 466 | 'title' => t('Openresort'), |
| 467 | 'callback' => 'system_admin_menu_block_page', |
| 468 | 'description' => t('Configure your online booking engine.'), |
| 469 | 'weight' => -100 |
| 470 | ); |
| 471 | $items[] = array ( |
| 472 | 'path' => 'admin/business/options', |
| 473 | 'title' => t('Business options'), |
| 474 | 'callback' => 'business_configure' |
| 475 | ); |
| 476 | $access = user_access('administer businesses'); |
| 477 | $items[] = array ( |
| 478 | 'path' => 'directory', |
| 479 | 'title' => t('Business Directory'), |
| 480 | 'callback' => 'business_menu_page', |
| 481 | 'access' => user_access('access content'), |
| 482 | 'type' => MENU_CALLBACK |
| 483 | ); |
| 484 | $items[] = array ( |
| 485 | 'path' => 'node/add/business', |
| 486 | 'title' => t('Business'), |
| 487 | 'callback' => 'business_add', |
| 488 | 'access' => user_access('create businesses') |
| 489 | ); |
| 490 | $items[] = array ( |
| 491 | 'path' => 'business/autocomplete', |
| 492 | 'title' => t('Business Autocomplete'), |
| 493 | 'callback' => 'business_autocomplete', |
| 494 | 'access' => $access, |
| 495 | 'type' => MENU_CALLBACK |
| 496 | ); |
| 497 | // menu tree |
| 498 | foreach (taxonomy_get_vocabularies() as $vocabulary) { |
| 499 | if (strtolower($vocabulary->name) == 'business directory') { |
| 500 | if (variable_get('taxonomy_menu_show_' . $vocabulary->vid, 1)) { |
| 501 | $path = 'directory/' . $vocabulary->vid; |
| 502 | $items[] = array ( |
| 503 | 'path' => $path, |
| 504 | 'title' => $vocabulary->name, |
| 505 | 'callback' => 'business_menu_page', |
| 506 | 'access' => user_access('access content'), |
| 507 | 'weight' => $vocabulary->weight |
| 508 | ); |
| 509 | |
| 510 | $tree = taxonomy_get_tree($vocabulary->vid); |
| 511 | $old_depth = -1; |
| 512 | $old_path = $path; |
| 513 | |
| 514 | foreach ($tree as $term) { |
| 515 | if ($term->depth <= $old_depth) { |
| 516 | $slashes_to_remove = $old_depth - $term->depth + 1; |
| 517 | for ($i = 0; $i < $slashes_to_remove; $i++) { |
| 518 | $old_path = substr($old_path, 0, strrpos($old_path, '/')); |
| 519 | } |
| 520 | } |
| 521 | $path = $old_path . '/' . $term->tid; |
| 522 | $old_depth = $term->depth; |
| 523 | $old_path = $path; |
| 524 | $items[] = array ( |
| 525 | 'path' => $path, |
| 526 | 'title' => $term->name, |
| 527 | 'weight' => $term->weight |
| 528 | ); |
| 529 | } |
| 530 | } |
| 531 | } |
| 532 | } |
| 533 | } else { |
| 534 | if (arg(0) == 'node' && is_numeric(arg(1))) { |
| 535 | $node = node_load(array ( |
| 536 | 'nid' => arg(1) |
| 537 | )); |
| 538 | } |
| 539 | $items[] = array ( |
| 540 | 'path' => 'admin/business/options', |
| 541 | 'title' => t('Business options'), |
| 542 | 'description' => t('Enable chamber field'), |
| 543 | 'callback' => 'drupal_get_form', |
| 544 | 'callback arguments' => array ( |
| 545 | 'business_configure' |
| 546 | ), |
| 547 | 'access' => user_access('administer site configuration'), |
| 548 | |
| 549 | ); |
| 550 | if ($node && $node->type == 'business' && (user_access('administer businesses') || user_access('edit own businesses'))) { |
| 551 | $items[] = array ( |
| 552 | 'path' => 'node/' . arg(1) . '/edit/listing', |
| 553 | 'title' => t('Listing'), |
| 554 | 'access' => node_access('update', $node), |
| 555 | 'type' => MENU_DEFAULT_LOCAL_TASK, |
| 556 | 'weight' => -10 |
| 557 | ); |
| 558 | } |
| 559 | $items[] = array ( |
| 560 | 'path' => 'node/add/business', |
| 561 | 'title' => t('Business'), |
| 562 | 'callback' => 'business_add', |
| 563 | 'access' => user_access('create businesses'), |
| 564 | 'type' => MENU_CALLBACK |
| 565 | ); |
| 566 | } |
| 567 | $items[] = array ( |
| 568 | 'path' => 'admin/business/ammenities', |
| 569 | 'title' => t('Business/unit ammenities'), |
| 570 | 'access' => user_access('administer accommodation'), |
| 571 | 'description' => t('Create ammenities for business types and units'), |
| 572 | 'callback' => 'business_ammenities_admin', |
| 573 | |
| 574 | ); |
| 575 | $items[] = array ( |
| 576 | 'path' => 'admin/business/ammenities', |
| 577 | 'title' => t('Business/unit ammenities'), |
| 578 | 'description' => t('Create ammenities for business types and units'), |
| 579 | 'callback' => 'business_ammenities_admin', |
| 580 | 'access' => user_access('administer accommodation'), |
| 581 | |
| 582 | ); |
| 583 | $items[] = array ( |
| 584 | 'path' => 'admin/business/ammenities/list', |
| 585 | 'title' => t('list'), |
| 586 | 'type' => MENU_DEFAULT_LOCAL_TASK, |
| 587 | 'weight' => -10, |
| 588 | 'access' => $access |
| 589 | ); |
| 590 | $items[] = array ( |
| 591 | 'path' => 'admin/business/ammenities/add', |
| 592 | 'title' => t('add ammenity'), |
| 593 | 'callback' => 'business_ammenities_admin_edit', |
| 594 | 'access' => $access, |
| 595 | 'type' => MENU_LOCAL_TASK |
| 596 | ); |
| 597 | $items[] = array ( |
| 598 | 'path' => 'admin/business/ammenities/' . arg(3) . '/edit', |
| 599 | 'callback' => 'business_ammenities_admin_edit', |
| 600 | 'callback arguments' => array ( |
| 601 | arg(3) |
| 602 | ), |
| 603 | 'access' => $access, |
| 604 | 'type' => MENU_CALLBACK |
| 605 | ); |
| 606 | return $items; |
| 607 | } |
| 608 | |
| 609 | function business_ammenities_admin() { |
| 610 | drupal_set_title(t("Ammenities")); |
| 611 | |
| 612 | $header = array ( |
| 613 | t('Title'), |
| 614 | t('Description'), |
| 615 | t('Weight'), |
| 616 | t('Business Types'), |
| 617 | t('Operations') |
| 618 | ); |
| 619 | |
| 620 | $result = db_query('SELECT * FROM {business_ammenities} ORDER BY weight'); |
| 621 | $rows = array (); |
| 622 | while ($ammenities = db_fetch_object($result)) { |
| 623 | $nodes = db_query('SELECT ptype FROM {business_ammenities_ptype} p WHERE aid = %d', $ammenities->aid); |
| 624 | $nodelist = array (); |
| 625 | while ($ptype = db_fetch_object($nodes)) { |
| 626 | $nodelist[] = str_replace('hotel', 'accommodation', $ptype->ptype); |
| 627 | } |
| 628 | $rows[] = array ( |
| 629 | $ammenities->description, |
| 630 | $ammenities->helptext, |
| 631 | $ammenities->weight, |
| 632 | implode(' ', $nodelist), |
| 633 | l(t('edit'), "admin/business/ammenities/$ammenities->aid/edit") |
| 634 | ); |
| 635 | } |
| 636 | if (!$rows) { |
| 637 | $rows[] = array ( |
| 638 | array ( |
| 639 | 'data' => t('No ammenities created.'), |
| 640 | 'colspan' => '5' |
| 641 | ) |
| 642 | ); |
| 643 | } |
| 644 | |
| 645 | return theme('table', $header, $rows, array ( |
| 646 | 'id' => 'ammenities' |
| 647 | )); |
| 648 | } |
| 649 | |
| 650 | function business_ammenities_admin_edit($aid = null) { |
| 651 | if ($aid) { |
| 652 | $edit = db_fetch_array(db_query("SELECT * FROM {business_ammenities} WHERE aid = %d", $aid)); |
| 653 | return drupal_get_form('business_ammenities_form', $edit); |
| 654 | } else { |
| 655 | return drupal_get_form('business_ammenities_form'); |
| 656 | } |
| 657 | } |
| 658 | |
| 659 | function business_ammenities_form($edit = array ()) { |
| 660 | |
| 661 | drupal_set_title(t("Ammenities")); |
| 662 | |
| 663 | $form['description'] = array ( |
| 664 | '#type' => 'textfield', |
| 665 | '#title' => t('Title'), |
| 666 | '#default_value' => $edit['description'], |
| 667 | '#maxlength' => 150, |
| 668 | '#description' => t('The description displayed in a listing'), |
| 669 | '#required' => TRUE, |
| 670 | '#weight' => -1 |
| 671 | ); |
| 672 | $form['helptext'] = array ( |
| 673 | '#type' => 'textfield', |
| 674 | '#title' => t('Display Name'), |
| 675 | '#default_value' => $edit['helptext'], |
| 676 | '#maxlength' => 150, |
| 677 | '#description' => t('Help text displayed on the form to user'), |
| 678 | '#required' => TRUE, |
| 679 | |
| 680 | ); |
| 681 | $form['weight'] = array ( |
| 682 | '#type' => 'weight', |
| 683 | '#title' => t('Weight'), |
| 684 | '#default_value' => $edit['weight'], |
| 685 | '#description' => t('Sort order.'), |
| 686 | |
| 687 | ); |
| 688 | //get node types as check boxes |
| 689 | $form['ammenities'] = array ( |
| 690 | '#type' => 'fieldset', |
| 691 | '#title' => t('Business types'), |
| 692 | '#description' => t('Which business types can select this ammenity?'), |
| 693 | '#tree' => true, |
| 694 | |
| 695 | ); |
| 696 | $ammenites = business_invoke_businessapi($edit, 'ammenities'); |
| 697 | while ($key = key($ammenites)) { |
| 698 | $result = db_result(db_query("SELECT count(*) FROM {business_ammenities_ptype} WHERE ptype = '%s' AND aid = %d", $key, $edit['aid'])); |
| 699 | $form['ammenities']['ammenity-' . $key] = array ( |
| 700 | '#type' => 'checkbox', |
| 701 | '#title' => $ammenites[$key], |
| 702 | '#default_value' => $result, |
| 703 | '#return_value' => true, |
| 704 | '#attributes' => NULL, |
| 705 | '#required' => FALSE, |
| 706 | |
| 707 | ); |
| 708 | next($ammenites); |
| 709 | } |
| 710 | |
| 711 | $form['submit'] = array ( |
| 712 | '#type' => 'submit', |
| 713 | '#value' => t('Submit') |
| 714 | ); |
| 715 | if ($edit['description']) { |
| 716 | $form['delete'] = array ( |
| 717 | '#type' => 'submit', |
| 718 | '#value' => t('Delete') |
| 719 | ); |
| 720 | $form['aid'] = array ( |
| 721 | '#type' => 'value', |
| 722 | '#value' => $edit['aid'] |
| 723 | ); |
| 724 | } |
| 725 | return $form; |
| 726 | } |
| 727 | |
| 728 | function business_ammenities_form_save($edit) { |
| 729 | $edit['op'] = $_POST['op']; |
| 730 | |
| 731 | if ($edit['op'] == "Delete" && $edit['aid']) { |
| 732 | db_query("DELETE FROM {business_ammenities} WHERE aid = '%s'", $edit['aid']); |
| 733 | db_query("DELETE FROM {business_ammenities_node} WHERE aid = '%s'", $edit['aid']); |
| 734 | db_query("DELETE FROM {business_ammenities_ptype} WHERE aid = '%s'", $edit['aid']); |
| 735 | $status = SAVED_DELETED; |
| 736 | } else { |
| 737 | if ($edit['aid']) { |
| 738 | db_query("UPDATE {business_ammenities} SET description = '%s', helptext = '%s', weight = %d WHERE aid = %d", $edit['description'], $edit['helptext'], $edit['weight'], $edit['aid']); |
| 739 | db_query("DELETE FROM {business_ammenities_ptype} WHERE aid = '%s'", $edit['aid']); |
| 740 | while ($akey = key($edit['ammenities'])) { |
| 741 | if ($edit['ammenities'][$akey] == true) { |
| 742 | db_query("INSERT INTO {business_ammenities_ptype} (aid,ptype) VALUES (%d,'%s')", $edit['aid'], substr($akey, 9)); |
| 743 | } |
| 744 | next($edit['ammenities']); |
| 745 | } |
| 746 | $status = SAVED_UPDATED; |
| 747 | } else { |
| 748 | db_query("INSERT INTO {business_ammenities} (description, helptext,weight) VALUES ('%s', '%s', %d)", $edit['description'], $edit['helptext'], $edit['weight']); |
| 749 | $aid = db_result(db_query("SELECT aid FROM {business_ammenities} WHERE description='%s' AND helptext='%s' AND weight = %d", $edit['description'], $edit['helptext'], $edit['weight'])); |
| 750 | while ($akey = key($edit['ammenities'])) { |
| 751 | if ($edit['ammenities'][$akey] == true) { |
| 752 | db_query("INSERT INTO {business_ammenities_ptype} (aid,ptype) VALUES (%d,'%s')", $aid, substr($akey, 9)); |
| 753 | } |
| 754 | next($edit['ammenities']); |
| 755 | } |
| 756 | $status = SAVED_NEW; |
| 757 | } |
| 758 | } |
| 759 | return $status; |
| 760 | } |
| 761 | |
| 762 | function business_ammenities_form_submit($form_id, $form_values) { |
| 763 | switch (business_ammenities_form_save($form_values)) { |
| 764 | case SAVED_NEW : |
| 765 | drupal_set_message(t('Ammenity added')); |
| 766 | break; |
| 767 | case SAVED_UPDATED : |
| 768 | drupal_set_message(t('Ammenity updated')); |
| 769 | break; |
| 770 | case SAVED_DELETED : |
| 771 | drupal_set_message(t('Ammenity deleted')); |
| 772 | break; |
| 773 | } |
| 774 | return 'admin/business/ammenities'; |
| 775 | } |
| 776 | |
| 777 | function business_ammenities_form_validate($form_id, $form_values) { |
| 778 | $count = 0; |
| 779 | while ($akey = key($form_values['ammenities'])) { |
| 780 | if ($form_values['ammenities'][$akey] == true) { |
| 781 | $count++; |
| 782 | } |
| 783 | next($form_values['ammenities']); |
| 784 | } |
| 785 | if ($count == 0) { |
| 786 | form_set_error('ammenities', t('Please select a business type for this ammenity')); |
| 787 | } |
| 788 | } |
| 789 | |
| 790 | function business_node_info() { |
| 791 | return array ( |
| 792 | 'business' => array ( |
| 793 | 'name' => t('Business'), |
| 794 | 'module' => 'business', |
| 795 | 'description' => t('create a business node') |
| 796 | ) |
| 797 | ); |
| 798 | } |
| 799 | |
| 800 | /** |
| 801 | * Invalidates the menu cache on taxonomy changes. |
| 802 | */ |
| 803 | function business_taxonomy() { |
| 804 | menu_rebuild(); |
| 805 | } |
| 806 | |
| 807 | /** |
| 808 | * Implementation of node_view(). |
| 809 | */ |
| 810 | function business_view(& $node, $teaser = false, $page = false) { |
| 811 | if ($page) { |
| 812 | $context = business_breadcrumb(); |
| 813 | } |
| 814 | $node = node_prepare($node, $teaser); |
| 815 | $node->content['business'] = array ( |
| 816 | '#value' => theme('node_business', $node, $teaser, $page), |
| 817 | '#weight' => '1' |
| 818 | ); |
| 819 | return $node; |
| 820 | } |
| 821 | |
| 822 | /******************************************************************** |
| 823 | * Module Functions |
| 824 | ********************************************************************/ |
| 825 | function business_invoke_businessapi(& $node, $op, $a3 = null, $a4 = null) { |
| 826 | $return = array (); |
| 827 | foreach (module_list() as $name) { |
| 828 | $function = $name . "_businessapi"; |
| 829 | if (function_exists($function)) { |
| 830 | $result = $function ($node, $op, $a3, $a4); |
| 831 | if (isset ($result)) { |
| 832 | $return = array_merge($return, $result); |
| 833 | } |
| 834 | } |
| 835 | } |
| 836 | return $return; |
| 837 | } |
| 838 | |
| 839 | /** |
| 840 | * Admin funtions for the module |
| 841 | */ |
| 842 | function business_admin_page() { |
| 843 | return '<div class="business">Select the setting you wish to edit from the menu.</div>'; |
| 844 | } |
| 845 | |
| 846 | /** |
| 847 | * Present a business submission form or a set of links to such forms. |
| 848 | * |
| 849 | */ |
| 850 | function business_add() { |
| 851 | global $user; |
| 852 | |
| 853 | $edit = isset ($_POST['edit']) ? $_POST['edit'] : ''; |
| 854 | $node = null; |
| 855 | |
| 856 | // If a business type has been specified, validate its existence. |
| 857 | |
| 858 | $ptypes = business_invoke_businessapi($node, 'wizard_select'); |
| 859 | if (arg(3) && in_array(arg(3), array_keys($ptypes))) { |
| 860 | $type = arg(3); |
| 861 | |
| 862 | // Initialize settings: |
| 863 | $node = array ( |
| 864 | 'uid' => $user->uid, |
| 865 | 'name' => $user->name, |
| 866 | 'type' => 'business', |
| 867 | 'ptype' => $type |
| 868 | ); |
| 869 | |
| 870 | drupal_set_title(t('Submit %name', array ( |
| 871 | '%name' => $ptypes[$type] |
| 872 | ))); |
| 873 | $output = drupal_get_form('business_node_form', $node); |
| 874 | } else { |
| 875 | $output = business_types_listing(); |
| 876 | } |
| 877 | return $output; |
| 878 | } |
| 879 | |
| 880 | /** |
| 881 | * The form presented when /node/add/buiness is clicked. Lists the types of businesses |
| 882 | * that can be created. |
| 883 | */ |
| 884 | function business_types_listing($link = 'node/add/business') { |
| 885 | $node = null; |
| 886 | // If no (valid) business type has been provided, display a business type overview. |
| 887 | foreach (business_invoke_businessapi($node, 'wizard_select') as $type => $name) { |
| 888 | if ($name == 'Generic') { |
| 889 | $name = 'Any other business'; |
| 890 | $key = 'Z'; |
| 891 | } else { |
| 892 | $key = $name; |
| 893 | } |
| 894 | $out = '<dt>' . l($name, "node/add/business/$type", array ( |
| 895 | 'title' => t('Add a %s.', array ( |
| 896 | '%s' => $name |
| 897 | )) |
| 898 | )) . '</dt>'; |
| 899 | |
| 900 | $item[$key] = $out; |
| 901 | } |
| 902 | |
| 903 | if (isset ($item)) { |
| 904 | ksort($item); |
| 905 | $output = t('Please select the category your business matches.') . '<dl>' . implode('', $item) . '</dl>'; |
| 906 | } else { |
| 907 | $output = t('No types of business are defined so you cannot create any businesses.'); |
| 908 | } |
| 909 | return $output; |
| 910 | } |
| 911 | |
| 912 | /** |
| 913 | * Page callback that renders a node listing for the selected term. |
| 914 | */ |
| 915 | function business_menu_page() { |
| 916 | |
| 917 | if (arg(2)) { |
| 918 | $arguments = explode('/', $_GET['q']); |
| 919 | $main_tid = db_escape_string(array_pop($arguments)); |
| 920 | return business_list_page(arg(1), $main_tid); |
| 921 | } else { |
| 922 | return business_list_page(arg(1)); |
| 923 | } |
| 924 | } |
| 925 | |
| 926 | /** |
| 927 | * The controller for viewing business listings. |
| 928 | * Callback happens via menu(), but via business_menu_page. |
| 929 | * |
| 930 | */ |
| 931 | function business_list_page($vid = null, $tid = null) { |
| 932 | $base = 'directory/' . $vid; |
| 933 | $context = business_breadcrumb($vid, $tid); |
| 934 | $parents = taxonomy_get_parents_all($context->tid); |
| 935 | if ($parents) { |
| 936 | $parents = array_reverse($parents); |
| 937 | foreach ($parents as $p) { |
| 938 | if ($p->tid) { |
| 939 | $base .= "/" . $p->tid; |
| 940 | } |
| 941 | } |
| 942 | } |
| 943 | return $output .= theme('business_collection', $vid, $tid); |
| 944 | } |
| 945 | |
| 946 | /** |
| 947 | * Sets breadcrumbs |
| 948 | */ |
| 949 | function business_breadcrumb($vid = null, $tid = null) { |
| 950 | if (!$vid) { |
| 951 | // use taxonomy_context to set breadcrumbs - business node |
| 952 | $context = taxonomy_context_get_context(); |
| 953 | $vid = $context->vid; |
| 954 | $tid = $context->tid; |
| 955 | } else { |
| 956 | $context->vid = $vid; |
| 957 | $context->tid = $tid; |
| 958 | } |
| 959 | |
| 960 | $base = 'directory/' . $vid; |
| 961 | |
| 962 | // Coming from a breadcrumb or link to a child |
| 963 | if ($context->tid) { |
| 964 | $breadcrumb[] = l(t('Home'), ''); |
| 965 | $vocabulary = taxonomy_get_vocabulary($context->vid); |
| 966 | $breadcrumb[] = l($vocabulary->name, 'directory/' . $context->vid); |
| 967 | $parents = taxonomy_get_parents_all($context->tid); |
| 968 | if ($parents) { |
| 969 | $parents = array_reverse($parents); |
| 970 | foreach ($parents as $p) { |
| 971 | if ($p->tid) { |
| 972 | $base .= "/" . $p->tid; |
| 973 | $breadcrumb[] = l($p->name, $base); |
| 974 | } |
| 975 | } |
| 976 | } |
| 977 | drupal_set_breadcrumb($breadcrumb); |
| 978 | } |
| 979 | // Coming from a breadcrumb or link to a child |
| 980 | else { |
| 981 | $breadcrumb[] = l('Home', ''); |
| 982 | drupal_set_breadcrumb($breadcrumb); |
| 983 | } |
| 984 | } |
| 985 | |
| 986 | function business_breadcrumb_for_parent($node) { |
| 987 | $context = db_fetch_object(db_query('SELECT t.tid, t.vid FROM {term_data} t INNER JOIN {term_node} n ON t.tid = n.tid WHERE n.nid = %d', $node->nid)); |
| 988 | if ($context->tid) { |
| 989 | $breadcrumb = taxonomy_context_get_breadcrumb($context); |
| 990 | } |
| 991 | $breadcrumb[] = l($node->title, 'node/' . $node->nid); |
| 992 | drupal_set_breadcrumb($breadcrumb); |
| 993 | } |
| 994 | |
| 995 | /** |
| 996 | * Called by terms module. Saves loading entire node. Instances of business_breadcrumb_for_parent should be migrated to this |
| 997 | */ |
| 998 | function business_breadcrumb_by_id($nid) { |
| 999 | $node = node_load($nid); |
| 1000 | $context = db_fetch_object(db_query('SELECT t.tid, t.vid FROM {term_data} t INNER JOIN {term_node} n ON t.tid = n.tid WHERE n.nid = %d', $nid)); |
| 1001 | if ($context->tid) { |
| 1002 | $breadcrumb = taxonomy_context_get_breadcrumb($context); |
| 1003 | } |
| 1004 | |
| 1005 | $breadcrumb[] = l($node->title, 'node/' . $nid); |
| 1006 | drupal_set_breadcrumb($breadcrumb); |
| 1007 | } |
| 1008 | |
| 1009 | function business_form_validate(& $edit) { |
| 1010 | $errors = array (); |
| 1011 | |
| 1012 | // Enforce max teaser length |
| 1013 | $teaser_length = variable_get('teaser_length', 600); |
| 1014 | if (strlen($edit->teaser) > $teaser_length) { |
| 1015 | form_set_error('teaser', t('The short description is too long. Please use a maximum of %teaser characters.', array ( |
| 1016 | '%teaser' => $teaser_length |
| 1017 | ))); |
| 1018 | } |
| 1019 | if ($edit->ptype) { |
| 1020 | $f = $edit->ptype . '_businessapi'; |
| 1021 | if (function_exists($f)) { |
| 1022 | $f ($edit, 'validate'); |
| 1023 | } |
| 1024 | } |
| 1025 | |
| 1026 | foreach ($errors as $name => $message) { |
| 1027 | form_set_error($name, $message); |
| 1028 | } |
| 1029 | |
| 1030 | return ((form_get_errors()) ? false : true); |
| 1031 | } |
| 1032 | |
| 1033 | /* |
| 1034 | * Assumes the node data has already been saved to it's respective tables and |
| 1035 | * only updates the main product table and the plugin of the business type |
| 1036 | */ |
| 1037 | function business_save($node) { |
| 1038 | if ($node->type == 'business' && $node->ptype) { |
| 1039 | $fields = business_fields(); |
| 1040 | /* Be very sure that we have a product entry to update! */ |
| 1041 | if (db_result(db_query('SELECT COUNT(nid) FROM {business} WHERE nid = %d', $node->nid))) { |
| 1042 | foreach ($node as $key => $value) { |
| 1043 | if (!is_numeric($key) && in_array($key, $fields)) { |
| 1044 | if (($key == 'www' or $key == 'email') and strlen($value) > 0) { |
| 1045 | $value = business_update_node($node, $value, $key); |
| 1046 | } |
| 1047 | $q[] = db_escape_string($key) . " = '$value'"; |
| 1048 | } |
| 1049 | } |
| 1050 | |
| 1051 | db_query("UPDATE {business} SET " . implode(', ', $q) . " WHERE nid = %d", $node->nid); |
| 1052 | |
| 1053 | if ($node->ptype) { |
| 1054 | module_invoke($node->ptype, 'businessapi', $node, 'update'); |
| 1055 | } |
| 1056 | } else { |
| 1057 | foreach ($node as $key => $value) { |
| 1058 | if (in_array($key, $fields)) { |
| 1059 | $k[] = db_escape_string($key); |
| 1060 | //call to function to check if tags are present for a link |
| 1061 | if (($key == 'www' or $key == 'email') and strlen($value) > 0) { |
| 1062 |