Parent Directory
|
Revision Log
|
Revision Graph
|
Patch
| revision 1.25, Wed Jan 9 20:35:42 2008 UTC | revision 1.26, Fri Jan 25 21:35:09 2008 UTC | |
|---|---|---|
| # | Line 1 | Line 1 |
| 1 | <?php | <?php |
| 2 | ||
| 3 | // $Id: $ | // $Id: $ |
| 4 | ||
| 5 | /******************************************************************** | /******************************************************************** |
| # | Line 10 | Line 11 |
| 11 | */ | */ |
| 12 | function theme_node_business($node, $teaser = 0, $page = 0) { | function theme_node_business($node, $teaser = 0, $page = 0) { |
| 13 | // Don't bother if this isn't a business | // Don't bother if this isn't a business |
| 14 | if ($node->type == 'business' && $teaser == false) { | if ($node->type == 'business' && $teaser == false) { |
| 15 | ||
| 16 | $_COOKIE['bid'] = $node->nid; | $_COOKIE['bid'] = $node->nid; |
| 17 | $output .= '<div class="availability"></div>'; | $output .= '<div class="availability"></div>'; |
| 18 | ||
| 19 | // Include business type-specific info | // Include business type-specific info |
| 20 | $f = "theme_" . $node->ptype . '_view'; | $f = "theme_" . $node->ptype . '_view'; |
| 21 | if (function_exists($f)) { | if (function_exists($f)) { |
| 22 | $output .= theme($node->ptype. '_view', $node, $teaser, $page); | $output .= theme($node->ptype . '_view', $node, $teaser, $page); |
| 23 | } | } |
| 24 | business_invoke_businessapi($node, 'view', $teaser, $page); | business_invoke_businessapi($node, 'view', $teaser, $page); |
| 25 | $output .= $node->content['units_list']['#value']; | $output .= $node->content['units_list']['#value']; |
| 26 | unset($node->content['units_list']); | unset ($node->content['units_list']); |
| 27 | $output .= '<div class="businessdetails"><h4>Business details</h4>'; | $output .= '<div class="businessdetails"><h4>Business details</h4>'; |
| 28 | $output .= '<dl class="business">'; | $output .= '<dl class="business">'; |
| 29 | if ($node->location['street']) { | if ($node->location['street']) { |
| 30 | $output .= '<dd>'. t('Address') . ': '. $node->location['street'] . ", " . $node->location['city'] . '</dd>'; | $output .= '<dd>' . t('Address') . ': ' . $node->location['street'] . ", " . $node->location['city'] . '</dd>'; |
| 31 | } | } |
| 32 | if($node->ptype == 'hotel'){ | if ($node->ptype == 'hotel') { |
| 33 | $details = false; | $details = false; |
| 34 | }else{ | } else { |
| 35 | $details = true; | $details = true; |
| 36 | } | } |
| 37 | if ($node->phone && (variable_get('busines_contact',1)||$details||user_access('administer accommodation'))) { | if ($node->phone && (variable_get('busines_contact', 1) || $details || user_access('administer accommodation'))) { |
| 38 | $output .= '<dd>'. t('Phone') . ': '. $node->phone . '</dd>'; | $output .= '<dd>' . t('Phone') . ': ' . $node->phone . '</dd>'; |
| 39 | } | } |
| 40 | if ($node->altphone && (variable_get('busines_contact',1)||$details||user_access('administer accommodation'))) { | if ($node->altphone && (variable_get('busines_contact', 1) || $details || user_access('administer accommodation'))) { |
| 41 | $output .= '<dd>'. t('Alternate phone') . ': '. $node->altphone . '</dd>'; | $output .= '<dd>' . t('Alternate phone') . ': ' . $node->altphone . '</dd>'; |
| 42 | } | } |
| 43 | if ($node->fax && (variable_get('busines_contact',1)||$details||user_access('administer accommodation'))) { | if ($node->fax && (variable_get('busines_contact', 1) || $details || user_access('administer accommodation'))) { |
| 44 | $output .= '<dd>'. t('Fax') .': '. $node->fax . '</dd>'; | $output .= '<dd>' . t('Fax') . ': ' . $node->fax . '</dd>'; |
| 45 | } | } |
| 46 | if ($node->www && (variable_get('busines_contact',1)||$details||user_access('administer accommodation'))) { | if ($node->www && (variable_get('busines_contact', 1) || $details || user_access('administer accommodation'))) { |
| 47 | if (strpos($node->www,"http://") !== false) { | if (strpos($node->www, "http://") !== false) { |
| 48 | $ouputnode = l(substr($node->www,7),$node->www); | $ouputnode = l(substr($node->www, 7), $node->www); |
| 49 | }else{ | } else { |
| 50 | $ouputnode = l($node->www,"http://".$node->www); | $ouputnode = l($node->www, "http://" . $node->www); |
| 51 | } | } |
| 52 | $output .= '<dd>'. t('Homepage') .': '. $ouputnode . '</dd>'; | $output .= '<dd>' . t('Homepage') . ': ' . $ouputnode . '</dd>'; |
| 53 | } | } |
| 54 | if ($node->email && (variable_get('busines_contact',1)||$details||user_access('administer accommodation'))) { | if ($node->email && (variable_get('busines_contact', 1) || $details || user_access('administer accommodation'))) { |
| 55 | if (strpos($node->email,"<a") !== false) { | $output .= '<dd>' . t('Email') . ': ' . check_markup($node->email). '</dd>'; |
| 56 | $ouputnode = $node->email; | } |
| 57 | }else{ | if ($node->chambermember && variable_get('business_chamber', false)) { |
| 58 | $ouputnode = '<a href="mailto:'.$node->email.'" >'.$node->email.'</a>'; | $output .= '<dd>' . variable_get('business_chamber_text', 'Member of the Chamber of Commerce') . '</dd>'; |
| 59 | } | } |
| 60 | $output .= '<dd>'. t('Email') .': '. $ouputnode . '</dd>'; | if ($node->files) { |
| 61 | } | foreach ($node->files as $file) { |
| 62 | if ($node->chambermember && variable_get('business_chamber',false)) { | if ($file->filemime == "application/pdf") { |
| 63 | $output .= '<dd>'.variable_get('business_chamber_text','Member of the Chamber of Commerce').'</dd>'; | $output .= '<dd><br /><a href="' . url($file->filepath) . '" onclick="window.open(this.href,\'external\'); return false;" >' . $file->description . '</a></dd>'; |
| 64 | } | } |
| 65 | if($node->files){ | } |
| 66 | foreach ($node->files as $file) { | } |
| 67 | if ($file->filemime == "application/pdf") { | $output .= '</dl></div>'; |
| 68 | $output.= '<dd><br /><a href="' . url($file->filepath) .'" onclick="window.open(this.href,\'external\'); return false;" >'. $file->description.'</a></dd>'; | |
| 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 | $output .= '</dl></div>'; | $latitude = $node->location['latitude']; |
| 73 | } else { | |
| 74 | $usegmap = (function_exists('gmap_set_location') && variable_get('location_usegmap', 1)); | $latitude = null; |
| 75 | if ($usegmap) { | } |
| 76 | if($node->location['latitude'] && $node->location['latitude'] != 0){ | if ($node->location['longitude'] && $node->location['longitude'] != 0) { |
| 77 | $latitude = $node->location['latitude']; | $longitude = $node->location['longitude']; |
| 78 | }else{ | } else { |
| 79 | $latitude = null; | $longitude = null; |
| 80 | } | } |
| 81 | if($node->location['longitude'] && $node->location['longitude'] != 0){ | if ($latitude != null || $longitude != null) { |
| 82 | $longitude = $node->location['longitude']; | $path = drupal_get_path('module', 'gmap') . '/js/'; |
| 83 | }else{ | $defaults = gmap_defaults(); |
| 84 | $longitude = null; | |
| 85 | } | //load default array and then get the zoom level |
| 86 | if($latitude != null || $longitude != null){ | $map_macro = '[gmap|center=' . $latitude . ',' . $longitude . '|zoom=' . $defaults['zoom'] . '|width=100%|height=400px|markers=blue::' . $latitude . ',' . $longitude . ':' . $node->title . ']'; |
| 87 | $path = drupal_get_path('module','gmap') .'/js/'; | $temp['#settings'] = gmap_parse_macro($map_macro); |
| 88 | $defaults = gmap_defaults(); | $temp['#settings']['id'] = 'loc1'; |
| 89 | $output .= theme('gmap', $temp); | |
| 90 | //load default array and then get the zoom level | //temp fix array is built but not processed once module is fixed this code can be removed |
| 91 | $map_macro = '[gmap|center='.$latitude.','.$longitude.'|zoom='.$defaults['zoom'].'|width=100%|height=400px|markers=blue::'.$latitude.','.$longitude.':'.$node->title.']'; | drupal_add_js($path . 'icon.js'); |
| 92 | $temp['#settings'] = gmap_parse_macro($map_macro); | drupal_add_js($path . 'gmap_marker.js'); |
| 93 | $temp['#settings']['id'] = 'loc1'; | drupal_add_js($path . 'markerloader_static.js'); |
| 94 | $output .= theme('gmap',$temp); | } |
| 95 | //temp fix array is built but not processed once module is fixed this code can be removed | } |
| 96 | drupal_add_js($path .'icon.js'); | } |
| 97 | drupal_add_js($path . 'gmap_marker.js'); | return $output; |
| drupal_add_js($path . 'markerloader_static.js'); | ||
| } | ||
| } | ||
| } | ||
| return $output; | ||
| 98 | } | } |
| 99 | ||
| 100 | /** | /** |
| 101 | * Display a collection of businesses | * Display a collection of businesses |
| 102 | */ | */ |
| 103 | function theme_business_collection($vid = null, $tid = null) { | function theme_business_collection($vid = null, $tid = null) { |
| 104 | $pageitems = 6; | $pageitems = 6; |
| 105 | ||
| 106 | if ($tid) { | if ($tid) { |
| 107 | $tids[] = "t.tid = " . $tid; | $tids[] = "t.tid = " . $tid; |
| 108 | if ($children = taxonomy_get_tree($vid, $tid, -1, 1)) { | if ($children = taxonomy_get_tree($vid, $tid, -1, 1)) { |
| # | Line 116 function theme_business_collection($vid | Line 112 function theme_business_collection($vid |
| 112 | } | } |
| 113 | $tid_where = "(" . join(" OR ", $tids) . ")"; | $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"; | $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(); | $args = array (); |
| 116 | $args[] = $tid_where; | $args[] = $tid_where; |
| 117 | }else { | } 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"; | $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(); | $args = array (); |
| 120 | } | } |
| 121 | $count_query = preg_replace(array('/SELECT.*?FROM /As', '/ORDER BY .*/'), array('SELECT COUNT(DISTINCT n.nid) FROM ', ''), $sql); | $count_query = preg_replace(array ( |
| 122 | $result = pager_query(db_rewrite_sql($sql), $pageitems, 0,$count_query,$args); | '/SELECT.*?FROM /As', |
| 123 | $output .= '<div class="business">' . "\n"; | '/ORDER BY .*/' |
| 124 | $businesses = false; | ), array ( |
| 125 | for ($i = 0; $node = db_fetch_object($result); $i++) { | '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); | $node = node_load($node->nid); |
| 133 | ||
| 134 | $businesses = true; | $businesses = true; |
| 135 | node_invoke_nodeapi($node, 'view', true, false); | node_invoke_nodeapi($node, 'view', true, false); |
| 136 | $image_attach =''; | $image_attach = ''; |
| 137 | if(module_exists('image_attach')){ | if (module_exists('image_attach')) { |
| 138 | $image_attach =$node->content['image_attach']['#value']; | $image_attach = $node->content['image_attach']['#value']; |
| 139 | } | } |
| 140 | $review =''; | $review = ''; |
| 141 | if(function_exists('theme_nodereview_business_teaser')){ | if (function_exists('theme_nodereview_business_teaser')) { |
| 142 | $review = theme('nodereview_business_teaser',$node); | $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('@url' => url("node/$node->nid"))); | $more = rtrim($node->teaser, "</p>\n") . " " . t('<span class="read-more"><a href="@url">more info »</a></span></p>', array ( |
| 145 | $output .= '<div class="teaser"><fieldset>'. $image_attach .'<h3>'. l($node->title, "node/$node->nid") ."</h3>\n".$review. $more. "</fieldset></div><!-- end teaser -->\n"; | '@url' => url("node/$node->nid") |
| 146 | } | )); |
| 147 | if(!$businesses){ | $output .= '<div class="teaser"><fieldset>' . $image_attach . '<h3>' . l($node->title, "node/$node->nid") . "</h3>\n" . $review . $more . "</fieldset></div><!-- end teaser -->\n"; |
| 148 | $output .= t('No businesses exist for this category'); | } |
| 149 | } | if (!$businesses) { |
| 150 | $output .= "</div><!-- end business -->\n"; | $output .= t('No businesses exist for this category'); |
| 151 | } | |
| 152 | if ($pager = theme('pager', NULL, $pageitems, 0)) { | $output .= "</div><!-- end business -->\n"; |
| 153 | $output .= $pager; | |
| 154 | } | if ($pager = theme('pager', NULL, $pageitems, 0)) { |
| 155 | return $output; | $output .= $pager; |
| 156 | } | |
| 157 | return $output; | |
| 158 | } | } |
| 159 | ||
| 160 | function business_access($op, $node) { | function business_access($op, $node) { |
| 161 | global $user; | global $user; |
| 162 | ||
| 163 | if ($op == 'create' && user_access('create businesses')) { | |
| 164 | return TRUE; | |
| 165 | } | |
| 166 | ||
| 167 | if ($op == 'create' && user_access('create businesses')) { | if ($op == 'update' || $op == 'delete') { |
| 168 | return TRUE; | if (user_access('edit own businesses') && ($user->uid == $node->uid)) { |
| 169 | } | return TRUE; |
| 170 | } | |
| 171 | if ($op == 'update' || $op == 'delete') { | } |
| if (user_access('edit own businesses') && ($user->uid == $node->uid)) { | ||
| return TRUE; | ||
| } | ||
| } | ||
| 172 | } | } |
| 173 | ||
| 174 | /** | /** |
| 175 | * Implementation of hook_perm(). | * Implementation of hook_perm(). |
| 176 | */ | */ |
| 177 | function business_perm() { | function business_perm() { |
| 178 | return array('administer businesses', 'create businesses', 'edit own businesses','update business type'); | 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(). | * Implementation of hook_form(). |
| 188 | */ | */ |
| 189 | function business_form(&$node, &$param) { | function business_form(& $node, & $param) { |
| 190 | ||
| 191 | /* Set form breadcrumb */ | /* Set form breadcrumb */ |
| 192 | $context = business_breadcrumb(); | $context = business_breadcrumb(); |
| 193 | ||
| 194 | $form['title'] = array( | $form['title'] = array ( |
| 195 | '#type' => 'textfield', | '#type' => 'textfield', |
| 196 | '#title' => t('Business name'), | '#title' => t('Business name'), |
| 197 | '#default_value' => $node->title, | '#default_value' => $node->title, |
| 198 | '#size' => 60, | '#size' => 60, |
| 199 | '#maxlength' => 128, | '#maxlength' => 128, |
| 200 | '#description' => NULL, | '#description' => NULL, |
| 201 | '#attributes' => NULL, | '#attributes' => NULL, |
| 202 | '#required' => TRUE, | '#required' => TRUE, |
| 203 | '#weight' => -9, | '#weight' => -9, |
| 204 | ); | |
| $form['contact'] = array( | ||
| '#type' => 'fieldset', | ||
| '#title' => t('Contact information'), | ||
| '#weight' => -8, | ||
| '#collapsible' => TRUE, | ||
| ); | ||
| $form['contact']['phone'] = array( | ||
| '#type' => 'textfield', | ||
| '#title' => t('Phone'), | ||
| '#default_value' => $node->phone, | ||
| '#size' => 25, | ||
| '#maxlength' => 50, | ||
| '#description' => '', | ||
| ); | ||
| $form['contact']['altphone'] = array( | ||
| '#type' => 'textfield', | ||
| '#title' => t('Alternate phone'), | ||
| '#default_value' => $node->altphone, | ||
| '#size' => 25, | ||
| '#maxlength' => 50, | ||
| '#description' => '', | ||
| ); | ||
| $form['contact']['fax'] = array( | ||
| '#type' => 'textfield', | ||
| '#title' => t('Fax'), | ||
| '#default_value' => $node->fax, | ||
| '#size' => 25, | ||
| '#maxlength' => 50, | ||
| '#description' => '', | ||
| ); | ||
| $form['contact']['www'] = array( | ||
| '#type' => 'textfield', | ||
| '#title' => t('Homepage'), | ||
| '#default_value' => $node->www, | ||
| '#size' => 25, | ||
| '#maxlength' => 150, | ||
| '#description' => '', | ||
| ); | ||
| $form['contact']['email'] = array( | ||
| '#type' => 'textfield', | ||
| '#title' => t('Email'), | ||
| '#default_value' => $node->email, | ||
| '#size' => 25, | ||
| '#maxlength' => 150, | ||
| '#description' => '', | ||
| ); | ||
| $form['description'] = array( | ||
| '#type' => 'fieldset', | ||
| '#title' => t('Business description'), | ||
| '#weight' => -3, | ||
| '#collapsible' => TRUE, | ||
| ); | ||
| $form['description']['teaser'] = array( | ||
| '#type' => 'textarea', | ||
| '#title' => t('Short description'), | ||
| '#default_value' => $node->teaser, | ||
| '#cols' => 60, | ||
| '#rows' => 3, | ||
| '#required' => true, | ||
| '#description' => t('The short description will be shown when more than one business is listed on the page.'), | ||
| ); | ||
| $form['description']['body'] = array( | ||
| '#type' => 'textarea', | ||
| '#title' => t('Long description'), | ||
| '#default_value' => $node->body, | ||
| '#cols' => 60, | ||
| '#rows' => 10, | ||
| '#required' => true, | ||
| '#description' => t('The long description will be shown when your business is being displayed on its own.'), | ||
| 205 | ); | ); |
| 206 | $form['description']['format'] = filter_form($node->format); | $form['contact'] = array ( |
| 207 | if(user_access('administer businesses')&& variable_get('business_chamber',false)){ | '#type' => 'fieldset', |
| 208 | $form['general'] = array( | '#title' => t('Contact information'), |
| 209 | '#type' => 'fieldset', | '#weight' => -8, |
| 210 | '#title' => t('General information'), | '#collapsible' => TRUE, |
| 211 | '#weight' => 0, | |
| 212 | '#collapsible' => TRUE, | ); |
| 213 | ); | $form['contact']['phone'] = array ( |
| 214 | $form['general']['chambermember'] = array( | '#type' => 'textfield', |
| 215 | '#type' => 'checkbox', | '#title' => t('Phone'), |
| 216 | '#title' => t('Chamber of Commerce member'), | '#default_value' => $node->phone, |
| 217 | '#return_value' => true, | '#size' => 25, |
| 218 | '#default_value' => $node->chambermember, | '#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')){ | if (user_access('update business type')) { |
| 303 | $ptypes = business_invoke_businessapi($node, 'wizard_select'); | $ptypes = business_invoke_businessapi($node, 'wizard_select'); |
| 304 | $form['businesstype'] = array( | $form['businesstype'] = array ( |
| 305 | '#type' => 'fieldset', | '#type' => 'fieldset', |
| 306 | '#title' => t('Enhanced business type'), | '#title' => t('Enhanced business type'), |
| 307 | '#weight' => -3, | '#weight' => -3, |
| 308 | '#collapsible' => TRUE, | '#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['businesstype']['ptype'] = array( | $form['#method'] = 'post'; |
| 334 | '#type' => 'select', | |
| 335 | '#title' => t('Business type'), | // Get the business-type-specific bits. |
| 336 | '#default_value' => $node->ptype, | |
| 337 | '#options' => $ptypes, | $form = array_merge($form, (array) module_invoke($node->ptype, 'businessapi', $node, 'form')); |
| '#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.'), | ||
| '#multiple' => NULL, | ||
| '#required' => TRUE, | ||
| ); | ||
| }else{ | ||
| $form['businesstype']['ptype'] = array( | ||
| '#type' => 'hidden', | ||
| '#value' => $node->ptype, | ||
| ); | ||
| } | ||
| $form['submit'] = array('#type' => 'submit', '#value' => t('Submit')); | ||
| $form['#method'] = 'post'; | ||
| // Get the business-type-specific bits. | ||
| $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 | // If the business is bookable, ask if we want to bundle activity booking |
| 340 | if (module_invoke($node->ptype, 'businessapi', $node, 'is_bookable')) { | if (module_invoke($node->ptype, 'businessapi', $node, 'is_bookable')) { |
| 341 | foreach (product_get_ptypes() as $ptype => $desc) { | foreach (product_get_ptypes() as $ptype => $desc) { |
| 342 | if (module_invoke($ptype, 'businessapi', $node, 'is_activity')) { | if (module_invoke($ptype, 'businessapi', $node, 'is_activity')) { |
| 343 | $form = array_merge($form, (array) module_invoke($ptype, 'businessapi', $node, 'form')); | $form = array_merge($form, (array) module_invoke($ptype, 'businessapi', $node, 'form')); |
| 344 | } | } |
| 345 | } | } |
| 346 | } | } |
| 347 | ||
| 348 | return $form; | return $form; |
| 349 | } | } |
| 350 | function business_format_address($list=array()){ | function business_format_address($list = array ()) { |
| 351 | $break = "\n"; | $break = "\n"; |
| 352 | $address =''; | $address = ''; |
| 353 | while($key = key($list)){ | while ($key = key($list)) { |
| 354 | $business = node_load($key); | $business = node_load($key); |
| 355 | ||
| 356 | if($business->type =='business' && $business->ecommerce == '1'){ | if ($business->type == 'business' && $business->ecommerce == '1') { |
| 357 | $address .= $business->title. $break; | $address .= $business->title . $break; |
| 358 | $address .= $business->location['street'] . $break; | $address .= $business->location['street'] . $break; |
| 359 | $address .= $business->location['city'] .$break; | $address .= $business->location['city'] . $break; |
| 360 | $address .= $business->phone . $break; | $address .= $business->phone . $break; |
| 361 | ||
| 362 | //now do google maps stuff | //now do google maps stuff |
| 363 | $usegmap = (function_exists('gmap_set_location') && variable_get('location_usegmap', 1)); | $usegmap = (function_exists('gmap_set_location') && variable_get('location_usegmap', 1)); |
| 364 | if ($usegmap) { | if ($usegmap) { |
| 365 | if($business->location['latitude'] && $business->location['latitude'] != 0){ | if ($business->location['latitude'] && $business->location['latitude'] != 0) { |
| 366 | $latitude = $business->location['latitude']; | $latitude = $business->location['latitude']; |
| 367 | }else{ | } else { |
| 368 | $latitude = null; | $latitude = null; |
| 369 | } | } |
| 370 | if($business->location['longitude'] && $business->location['longitude'] != 0){ | if ($business->location['longitude'] && $business->location['longitude'] != 0) { |
| 371 | $longitude = $business->location['longitude']; | $longitude = $business->location['longitude']; |
| 372 | }else{ | } else { |
| 373 | $longitude = null; | $longitude = null; |
| 374 | } | } |
| 375 | if($latitude != null || $longitude != null){ | if ($latitude != null || $longitude != null) { |
| 376 | $address .= 'http://maps.google.com/maps?f=q&hl=en&q='.$latitude.','.$longitude.'&z=12'.$break.$break; | $address .= 'http://maps.google.com/maps?f=q&hl=en&q=' . $latitude . ',' . $longitude . '&z=12' . $break . $break; |
| 377 | } | } |
| 378 | ||
| 379 | } | } |
| 380 | ||
| 381 | $checkin = array(); | $checkin = array (); |
| 382 | $count = 0; | $count = 0; |
| 383 | while ($unit_key = key($list[$key])){ | 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)); | $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){ | if (strlen($instructions->checkin) > 0) { |
| 386 | //stop issue with 2 rooms getting wrong count | //stop issue with 2 rooms getting wrong count |
| 387 | if(!array_key_exists ($unit_key,$checkin)){ | if (!array_key_exists($unit_key, $checkin)) { |
| 388 | $checkin[$unit_key] = $instructions->title.':'.$break.$instructions->checkin; | $checkin[$unit_key] = $instructions->title . ':' . $break . $instructions->checkin; |
| 389 | $count ++; | $count++; |
| 390 | } | } |
| 391 | }else{ | } else { |
| 392 | $count ++; | $count++; |
| 393 | } | } |
| 394 | next($list[$key]); | next($list[$key]); |
| 395 | } | } |
| 396 | if((sizeof($checkin) < $count) && (strlen($business->checkin)>0)){ | if ((sizeof($checkin) < $count) && (strlen($business->checkin) > 0)) { |
| 397 | $checkin[$key] = $business->title.':'.$break.$business->checkin; | $checkin[$key] = $business->title . ':' . $break . $business->checkin; |
| 398 | } | } |
| 399 | if(sizeof($checkin)>0){ | if (sizeof($checkin) > 0) { |
| 400 | $address .= 'Checkin instructions'.$break.$break; | $address .= 'Checkin instructions' . $break . $break; |
| 401 | while($instructions = key($checkin)){ | while ($instructions = key($checkin)) { |
| 402 | $address .= $checkin[$instructions].$break; | $address .= $checkin[$instructions] . $break; |
| 403 | next($checkin); | next($checkin); |
| 404 | } | } |
| 405 | } | } |
| 406 | } | } |
| 407 | next($list); | next($list); |
| 408 | } | } |
| # | Line 386 function business_format_address($list=a | Line 412 function business_format_address($list=a |
| 412 | * Implementation of hook_help(). | * Implementation of hook_help(). |
| 413 | */ | */ |
| 414 | function business_help($section = 'admin/help#business') { | function business_help($section = 'admin/help#business') { |
| 415 | $output = ""; | $output = ""; |
| 416 | ||
| 417 | switch ($section) { | switch ($section) { |
| 418 | ||
| 419 | case 'node/add#business': | case 'node/add#business' : |
| 420 | $output = t("Creates a new business listing in the directory."); | $output = t("Creates a new business listing in the directory."); |
| 421 | break; | break; |
| 422 | } | } |
| 423 | ||
| 424 | return $output; | return $output; |
| 425 | } | } |
| 426 | ||
| 427 | /** | /** |
| 428 | * Implementation of hook_load(). | * Implementation of hook_load(). |
| 429 | */ | */ |
| 430 | function business_load($node) { | function business_load($node) { |
| 431 | static $business = array(); | static $business = array (); |
| 432 | $business_ammenities = array(); | $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 | ||
| $business = db_fetch_object(db_query('SELECT * FROM {business} b WHERE b.nid = %d', $node->nid)); | ||
| /* Merge the business info for the specific type. */ | ||
| if ($business_type = module_invoke($business->ptype, 'businessapi', $business, 'load')) { | ||
| foreach ($business_type as $key => $value) { | ||
| $business->$key = $value; | ||
| } | ||
| } | ||
| $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); | ||
| $count = 0; | ||
| while($ammenities = db_fetch_object($result)){ | ||
| $business_ammenities[$ammenities->aid] = $ammenities->description; | ||
| $count++; | ||
| } | ||
| if($count>0){ | ||
| $business->ammenties = $business_ammenities; | ||
| } | ||
| 453 | return $business; | return $business; |
| 454 | } | } |
| 455 | ||
| 456 | /** | /** |
| 457 | * Implmentation of menu_hook() | * Implmentation of menu_hook() |
| 458 | */ | */ |
| 459 | function business_menu($may_cache) { | function business_menu($may_cache) { |
| 460 | ||
| 461 | $items = array(); | $items = array (); |
| 462 | ||
| 463 | if ($may_cache) { | if ($may_cache) { |
| 464 | $items[] = array('path' => 'admin/business', | $items[] = array ( |
| 465 | 'title' => t('Openresort'), | 'path' => 'admin/business', |
| 466 | 'callback' => 'system_admin_menu_block_page', | 'title' => t('Openresort'), |
| 467 | 'description' => t('Configure your online booking engine.'), | 'callback' => 'system_admin_menu_block_page', |
| 468 | 'weight' => -100); | 'description' => t('Configure your online booking engine.'), |
| 469 | $items[] = array('path' => 'admin/business/options', | 'weight' => -100 |
| 470 | 'title' => t('Business options'), | ); |
| 471 | 'callback' => 'business_configure'); | $items[] = array ( |
| 472 | $access = user_access('administer businesses'); | 'path' => 'admin/business/options', |
| 473 | $items[] = array('path' => 'directory', | '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'), | 'title' => t('Business Directory'), |
| 480 | 'callback' => 'business_menu_page', | 'callback' => 'business_menu_page', |
| 481 | 'access' => user_access('access content'), | 'access' => user_access('access content'), |
| 482 | 'type' => MENU_CALLBACK); | 'type' => MENU_CALLBACK |
| 483 | $items[] = array('path' => 'node/add/business', | ); |
| 484 | 'title' => t('Business'), | $items[] = array ( |
| 485 | 'path' => 'node/add/business', | |
| 486 | 'title' => t('Business'), | |
| 487 | 'callback' => 'business_add', | 'callback' => 'business_add', |
| 488 | 'access' => user_access('create businesses')); | 'access' => user_access('create businesses') |
| 489 | $items[] = array('path' => 'business/autocomplete', | ); |
| 490 | $items[] = array ( | |
| 491 | 'path' => 'business/autocomplete', | |
| 492 | 'title' => t('Business Autocomplete'), | 'title' => t('Business Autocomplete'), |
| 493 | 'callback' => 'business_autocomplete', | 'callback' => 'business_autocomplete', |
| 494 | 'access' => $access, | 'access' => $access, |
| 495 | 'type' => MENU_CALLBACK); | 'type' => MENU_CALLBACK |
| 496 | // menu tree | ); |
| 497 | foreach (taxonomy_get_vocabularies() as $vocabulary) { | // menu tree |
| 498 | if (strtolower($vocabulary->name) =='business directory'){ | foreach (taxonomy_get_vocabularies() as $vocabulary) { |
| 499 | if (variable_get('taxonomy_menu_show_'. $vocabulary->vid, 1)) { | if (strtolower($vocabulary->name) == 'business directory') { |
| 500 | $path = 'directory/'. $vocabulary->vid; | if (variable_get('taxonomy_menu_show_' . $vocabulary->vid, 1)) { |
| 501 | $items[] = array('path' => $path, | $path = 'directory/' . $vocabulary->vid; |
| 502 | 'title' => $vocabulary->name, | $items[] = array ( |
| 503 | 'callback' => 'business_menu_page', | 'path' => $path, |
| 504 | 'access' => user_access('access content'), | 'title' => $vocabulary->name, |
| 505 | 'weight' => $vocabulary->weight); | 'callback' => 'business_menu_page', |
| 506 | 'access' => user_access('access content'), | |
| 507 | $tree = taxonomy_get_tree($vocabulary->vid); | 'weight' => $vocabulary->weight |
| 508 | $old_depth = -1; | ); |
| 509 | $old_path = $path; | |
| 510 | $tree = taxonomy_get_tree($vocabulary->vid); | |
| 511 | foreach ($tree as $term) { | $old_depth = -1; |
| 512 | if ($term->depth <= $old_depth) { | $old_path = $path; |
| 513 | $slashes_to_remove = $old_depth - $term->depth + 1; | |
| 514 | for ($i = 0; $i < $slashes_to_remove; $i++) { | foreach ($tree as $term) { |
| 515 | $old_path = substr($old_path, 0, strrpos($old_path, '/')); | if ($term->depth <= $old_depth) { |
| 516 | } | $slashes_to_remove = $old_depth - $term->depth + 1; |
| 517 | } | for ($i = 0; $i < $slashes_to_remove; $i++) { |
| 518 | $path = $old_path .'/'. $term->tid; | $old_path = substr($old_path, 0, strrpos($old_path, '/')); |
| 519 | $old_depth = $term->depth; | } |
| 520 | $old_path = $path; | } |
| 521 | $items[] = array('path' => $path, | $path = $old_path . '/' . $term->tid; |
| 522 | 'title' => $term->name, | $old_depth = $term->depth; |
| 523 | 'weight' => $term->weight); | $old_path = $path; |
| 524 | } | $items[] = array ( |
| 525 | } | 'path' => $path, |
| 526 | } | 'title' => $term->name, |
| 527 | } | 'weight' => $term->weight |
| 528 | } | ); |
| 529 | else { | } |
| 530 | if (arg(0) == 'node' && is_numeric(arg(1))) { | } |
| 531 | $node = node_load(array('nid' => arg(1))); | } |
| 532 | } | } |
| 533 | $items[] = array( | } else { |
| 534 | 'path' => 'admin/business/options', | if (arg(0) == 'node' && is_numeric(arg(1))) { |
| 535 | 'title' => t('Business options'), | $node = node_load(array ( |
| 536 | 'description' => t('Enable chamber field'), | 'nid' => arg(1) |
| 537 | 'callback' => 'drupal_get_form', | )); |
| 538 | 'callback arguments' => array('business_configure'), | } |
| 539 | 'access' => user_access('administer site configuration'), | $items[] = array ( |
| 540 | ); | 'path' => 'admin/business/options', |
| 541 | if ($node && $node->type == 'business' && (user_access('administer businesses')|| user_access('edit own businesses'))) { | 'title' => t('Business options'), |
| 542 | $items[] = array('path' => 'node/'. arg(1) .'/edit/listing', | 'description' => t('Enable chamber field'), |
| 543 | 'title' => t('Listing'), | 'callback' => 'drupal_get_form', |
| 544 | 'access' => node_access('update', $node), | 'callback arguments' => array ( |
| 545 | 'type' => MENU_DEFAULT_LOCAL_TASK, | 'business_configure' |
| 546 | 'weight' => -10); | ), |
| 547 | } | 'access' => user_access('administer site configuration'), |
| 548 | $items[] = array('path' => 'node/add/business', | |
| 549 | 'title' => t('Business'), | ); |
| 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', | 'callback' => 'business_add', |
| 563 | 'access' => user_access('create businesses'), | 'access' => user_access('create businesses'), |
| 564 | 'type' => MENU_CALLBACK); | 'type' => MENU_CALLBACK |
| 565 | } | ); |
| 566 | $items[] = array('path' => 'admin/business/ammenities', | } |
| 567 | $items[] = array ( | |
| 568 | 'path' => 'admin/business/ammenities', | |
| 569 | 'title' => t('Business/unit ammenities'), | 'title' => t('Business/unit ammenities'), |
| 570 | 'access' => user_access('administer accommodation'), | 'access' => user_access('administer accommodation'), |
| 571 | 'description' => t('Create ammenities for business types and units'), | 'description' => t('Create ammenities for business types and units'), |
| 572 | 'callback' => 'business_ammenities_admin', | 'callback' => 'business_ammenities_admin', |
| 573 | ); | |
| 574 | $items[] = array( | ); |
| 575 | 'path' => 'admin/business/ammenities', | $items[] = array ( |
| 576 | 'title' => t('Business/unit ammenities'), | 'path' => 'admin/business/ammenities', |
| 577 | 'description' => t('Create ammenities for business types and units'), | 'title' => t('Business/unit ammenities'), |
| 578 | 'callback' => 'business_ammenities_admin', | 'description' => t('Create ammenities for business types and units'), |
| 579 | 'access' => user_access('administer accommodation'), | 'callback' => 'business_ammenities_admin', |
| 580 | ); | 'access' => user_access('administer accommodation'), |
| 581 | $items[] = array('path' => 'admin/business/ammenities/list', | |
| 582 | 'title' => t('list'), | ); |
| 583 | 'type' => MENU_DEFAULT_LOCAL_TASK, | $items[] = array ( |
| 584 | 'weight' => -10, | 'path' => 'admin/business/ammenities/list', |
| 585 | 'access' => $access); | 'title' => t('list'), |
| 586 | $items[] = array('path' => 'admin/business/ammenities/add', | 'type' => MENU_DEFAULT_LOCAL_TASK, |
| 587 | 'title' => t('add ammenity'), | 'weight' => -10, |
| 588 | 'callback' => 'business_ammenities_admin_edit', | 'access' => $access |
| 589 | 'access' => $access, | ); |
| 590 | 'type' => MENU_LOCAL_TASK); | $items[] = array ( |
| 591 | $items[] = array('path' => 'admin/business/ammenities/'.arg(3).'/edit', | 'path' => 'admin/business/ammenities/add', |
| 592 | 'callback' => 'business_ammenities_admin_edit', | 'title' => t('add ammenity'), |
| 593 | 'callback arguments' => array(arg(3)), | 'callback' => 'business_ammenities_admin_edit', |
| 594 | 'access' => $access, | 'access' => $access, |
| 595 | 'type' => MENU_CALLBACK); | 'type' => MENU_LOCAL_TASK |
| 596 | return $items; | ); |
| 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() { | function business_ammenities_admin() { |
| 610 | drupal_set_title(t("Ammenities")); | drupal_set_title(t("Ammenities")); |
| 611 | ||
| 612 | $header = array(t('Title'), t('Description'), t('Weight'),t('Business Types'),t('Operations')); | $header = array ( |
| 613 | t('Title'), | |
| 614 | t('Description'), | |
| 615 | $result = db_query('SELECT * FROM {business_ammenities} ORDER BY weight'); | t('Weight'), |
| 616 | $rows = array(); | t('Business Types'), |
| 617 | while ($ammenities = db_fetch_object($result)) { | t('Operations') |
| 618 | $nodes = db_query('SELECT ptype FROM {business_ammenities_ptype} p WHERE aid = %d',$ammenities->aid); | ); |
| 619 | $nodelist = array(); | |
| 620 | while ($ptype = db_fetch_object($nodes)){ | $result = db_query('SELECT * FROM {business_ammenities} ORDER BY weight'); |
| 621 | $nodelist []= str_replace('hotel','accommodation',$ptype->ptype); | $rows = array (); |
| 622 | } | while ($ammenities = db_fetch_object($result)) { |
| 623 | $rows[] = array($ammenities->description, | $nodes = db_query('SELECT ptype FROM {business_ammenities_ptype} p WHERE aid = %d', $ammenities->aid); |
| 624 | $ammenities->helptext, | $nodelist = array (); |
| 625 | $ammenities->weight, | while ($ptype = db_fetch_object($nodes)) { |
| 626 | implode(' ',$nodelist), | $nodelist[] = str_replace('hotel', 'accommodation', $ptype->ptype); |
| 627 | l(t('edit'), "admin/business/ammenities/$ammenities->aid/edit")); | } |
| 628 | } | $rows[] = array ( |
| 629 | if (!$rows) { | $ammenities->description, |
| 630 | $rows[] = array(array('data' => t('No ammenities created.'), 'colspan' => '5')); | $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('id' => 'ammenities')); | return theme('table', $header, $rows, array ( |
| 646 | 'id' => 'ammenities' | |
| 647 | )); | |
| 648 | } | } |
| 649 | ||
| 650 | function business_ammenities_admin_edit($aid=null) { | function business_ammenities_admin_edit($aid = null) { |
| 651 | if ($aid) { | if ($aid) { |
| 652 | $edit = db_fetch_array(db_query("SELECT * FROM {business_ammenities} WHERE aid = %d", $aid)); | $edit = db_fetch_array(db_query("SELECT * FROM {business_ammenities} WHERE aid = %d", $aid)); |
| 653 | return drupal_get_form('business_ammenities_form',$edit); | return drupal_get_form('business_ammenities_form', $edit); |
| 654 | } else { | |
| 655 | return drupal_get_form('business_ammenities_form'); | |
| 656 | } | } |
| else { | ||
| return drupal_get_form('business_ammenities_form'); | ||
| } | ||
| 657 | } | } |
| 658 | ||
| 659 | function business_ammenities_form($edit = array()) { | function business_ammenities_form($edit = array ()) { |
| 660 | ||
| 661 | drupal_set_title(t("Ammenities")); | drupal_set_title(t("Ammenities")); |
| 662 | ||
| 663 | $form['description'] = array( | $form['description'] = array ( |
| 664 | '#type' => 'textfield', | '#type' => 'textfield', |
| 665 | '#title' => t('Title'), | '#title' => t('Title'), |
| 666 | '#default_value' => $edit['description'], | '#default_value' => $edit['description'], |
| 667 | '#maxlength' => 150, | '#maxlength' => 150, |
| 668 | '#description' =>t('The description displayed in a listing'), | '#description' => t('The description displayed in a listing'), |
| 669 | '#required' => TRUE, | '#required' => TRUE, |
| 670 | '#weight' => -1 | '#weight' => -1 |
| 671 | ); | ); |
| 672 | $form['helptext'] = array('#type' => 'textfield', | $form['helptext'] = array ( |
| 673 | '#title' => t('Display Name'), | '#type' => 'textfield', |
| 674 | '#default_value' => $edit['helptext'], | '#title' => t('Display Name'), |
| 675 | '#maxlength' => 150, | '#default_value' => $edit['helptext'], |
| 676 | '#description' => t('Help text displayed on the form to user'), | '#maxlength' => 150, |
| 677 | '#required' => TRUE, | '#description' => t('Help text displayed on the form to user'), |
| 678 | ); | '#required' => TRUE, |
| 679 | $form['weight'] = array( | |
| 680 | '#type' => 'weight', | ); |
| 681 | '#title' => t('Weight'), | $form['weight'] = array ( |
| 682 | '#default_value' => $edit['weight'], | '#type' => 'weight', |
| 683 | '#description' => t('Sort order.'), | '#title' => t('Weight'), |
| 684 | '#default_value' => $edit['weight'], | |
| 685 | '#description' => t('Sort order.'), | |
| 686 | ||
| 687 | ); | ); |
| 688 | //get node types as check boxes | //get node types as check boxes |
| 689 | $form['ammenities'] = array( | $form['ammenities'] = array ( |
| 690 | '#type' => 'fieldset', | '#type' => 'fieldset', |
| 691 | '#title' => t('Business types'), | '#title' => t('Business types'), |
| 692 | '#description' =>t('Which business types can select this ammenity?'), | '#description' => t('Which business types can select this ammenity?'), |
| 693 | '#tree' => true, | '#tree' => true, |
| 694 | ); | |
| 695 | ); | |
| 696 | $ammenites = business_invoke_businessapi($edit, 'ammenities'); | $ammenites = business_invoke_businessapi($edit, 'ammenities'); |
| 697 | while($key = key($ammenites)){ | 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'])); | $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( | $form['ammenities']['ammenity-' . $key] = array ( |
| 700 | '#type' => 'checkbox', | '#type' => 'checkbox', |
| 701 | '#title' => $ammenites[$key], | '#title' => $ammenites[$key], |
| 702 | '#default_value' =>$result, | '#default_value' => $result, |
| 703 | '#return_value' => true, | '#return_value' => true, |
| 704 | '#attributes' => NULL, | '#attributes' => NULL, |
| 705 | '#required' => FALSE, | '#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 | next($ammenites); | $form['aid'] = array ( |
| 721 | } | '#type' => 'value', |
| 722 | '#value' => $edit['aid'] | |
| 723 | $form['submit'] = array('#type' => 'submit', '#value' => t('Submit')); | ); |
| 724 | if ($edit['description']) { | } |
| 725 | $form['delete'] = array('#type' => 'submit', '#value' => t('Delete')); | return $form; |
| $form['aid'] = array('#type' => 'value', '#value' => $edit['aid']); | ||
| } | ||
| return $form; | ||
| 726 | } | } |
| 727 | ||
| 728 | function business_ammenities_form_save($edit) { | function business_ammenities_form_save($edit) { |
| 729 | $edit['op'] = $_POST['op']; | $edit['op'] = $_POST['op']; |
| 730 | ||
| 731 | if ($edit['op'] == "Delete" && $edit['aid']) { | if ($edit['op'] == "Delete" && $edit['aid']) { |
| 732 | db_query("DELETE FROM {business_ammenities} WHERE aid = '%s'", $edit['aid']); | db_query("DELETE FROM {business_ammenities} WHERE aid = '%s'", $edit['aid']); |
| 733 | db_query("DELETE FROM {business_ammenities_node} WHERE aid = '%s'", $edit['aid']); | 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']); | db_query("DELETE FROM {business_ammenities_ptype} WHERE aid = '%s'", $edit['aid']); |
| 735 | $status = SAVED_DELETED; | $status = SAVED_DELETED; |
| 736 | }else{ | } else { |
| 737 | if ($edit['aid']) { | 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']); | 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']); | db_query("DELETE FROM {business_ammenities_ptype} WHERE aid = '%s'", $edit['aid']); |
| 740 | while($akey = key($edit['ammenities'])){ | while ($akey = key($edit['ammenities'])) { |
| 741 | if($edit['ammenities'][$akey]==true){ | if ($edit['ammenities'][$akey] == true) { |
| 742 | db_query("INSERT INTO {business_ammenities_ptype} (aid,ptype) VALUES (%d,'%s')",$edit['aid'],substr($akey,9)); | db_query("INSERT INTO {business_ammenities_ptype} (aid,ptype) VALUES (%d,'%s')", $edit['aid'], substr($akey, 9)); |
| 743 | } | } |
| 744 | next($edit['ammenities']); | next($edit['ammenities']); |
| 745 | } | } |
| 746 | $status = SAVED_UPDATED; | $status = SAVED_UPDATED; |
| 747 | }else{ | } else { |
| 748 | db_query("INSERT INTO {business_ammenities} (description, helptext,weight) VALUES ('%s', '%s', %d)", $edit['description'], $edit['helptext'],$edit['weight']); | 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'])); | $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'])){ | while ($akey = key($edit['ammenities'])) { |
| 751 | if($edit['ammenities'][$akey]==true){ | if ($edit['ammenities'][$akey] == true) { |
| 752 | db_query("INSERT INTO {business_ammenities_ptype} (aid,ptype) VALUES (%d,'%s')",$aid,substr($akey,9)); | db_query("INSERT INTO {business_ammenities_ptype} (aid,ptype) VALUES (%d,'%s')", $aid, substr($akey, 9)); |
| 753 | } | } |
| 754 | next($edit['ammenities']); | next($edit['ammenities']); |
| 755 | } | } |
| 756 | $status = SAVED_NEW; | $status = SAVED_NEW; |
| 757 | } | } |
| 758 | } | } |
| 759 | return $status; | return $status; |
| 760 | } | } |
| 761 | ||
| 762 | function business_ammenities_form_submit($form_id, $form_values) { | function business_ammenities_form_submit($form_id, $form_values) { |
| 763 | switch (business_ammenities_form_save($form_values)) { | switch (business_ammenities_form_save($form_values)) { |
| 764 | case SAVED_NEW: | case SAVED_NEW : |
| 765 | drupal_set_message(t('Ammenity added')); | drupal_set_message(t('Ammenity added')); |
| 766 | break; | break; |
| 767 | case SAVED_UPDATED: | case SAVED_UPDATED : |
| 768 | drupal_set_message(t('Ammenity updated')); | drupal_set_message(t('Ammenity updated')); |
| 769 | break; | break; |
| 770 | case SAVED_DELETED: | case SAVED_DELETED : |
| 771 | drupal_set_message(t('Ammenity deleted')); | drupal_set_message(t('Ammenity deleted')); |
| 772 | break; | break; |
| 773 | } | } |
| 774 | return 'admin/business/ammenities'; | return 'admin/business/ammenities'; |
| 775 | } | } |
| 776 | ||
| 777 | function business_ammenities_form_validate($form_id, $form_values) { | function business_ammenities_form_validate($form_id, $form_values) { |
| 778 | $count = 0; | $count = 0; |
| 779 | while($akey = key($form_values['ammenities'])){ | while ($akey = key($form_values['ammenities'])) { |
| 780 | if($form_values['ammenities'][$akey]==true){ | if ($form_values['ammenities'][$akey] == true) { |
| 781 | $count ++; | $count++; |
| 782 | } | } |
| 783 | next($form_values['ammenities']); | next($form_values['ammenities']); |
| 784 | } | } |
| 785 | if($count==0){ | if ($count == 0) { |
| 786 | form_set_error('ammenities', t('Please select a business type for this ammenity')); | form_set_error('ammenities', t('Please select a business type for this ammenity')); |
| 787 | } | } |
| 788 | } | } |
| 789 | ||
| 790 | function business_node_info() { | function business_node_info() { |
| 791 | return array('business' => array('name' => t('Business'), 'module'=>'business','description'=>t('create a business node'))); | 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. | * Invalidates the menu cache on taxonomy changes. |
| 802 | */ | */ |
| 803 | function business_taxonomy() { | function business_taxonomy() { |
| 804 | menu_rebuild(); | menu_rebuild(); |
| 805 | } | } |
| 806 | ||
| 807 | /** | /** |
| 808 | * Implementation of node_view(). | * Implementation of node_view(). |
| 809 | */ | */ |
| 810 | function business_view(&$node, $teaser = false, $page = false) { | function business_view(& $node, $teaser = false, $page = false) { |
| 811 | if ($page) { | if ($page) { |
| 812 | $context = business_breadcrumb(); | $context = business_breadcrumb(); |
| 813 | } | } |
| 814 | $node = node_prepare($node, $teaser); | $node = node_prepare($node, $teaser); |
| 815 | $node->content['business'] = array( | $node->content['business'] = array ( |
| 816 | '#value' => theme('node_business',$node,$teaser,$page), | '#value' => theme('node_business', $node, $teaser, $page), |
| 817 | '#weight' => '1' | '#weight' => '1' |
| 818 | ); | ); |
| 819 | return $node; | return $node; |
| 820 | } | } |
| 821 | ||
| 822 | /******************************************************************** | /******************************************************************** |
| 823 | * Module Functions | * Module Functions |
| 824 | ********************************************************************/ | ********************************************************************/ |
| 825 | function business_invoke_businessapi(&$node, $op, $a3 = null, $a4 = null) { | function business_invoke_businessapi(& $node, $op, $a3 = null, $a4 = null) { |
| 826 | $return = array(); | $return = array (); |
| 827 | foreach (module_list() as $name) { | foreach (module_list() as $name) { |
| 828 | $function = $name ."_businessapi"; | $function = $name . "_businessapi"; |
| 829 | if (function_exists($function)) { | if (function_exists($function)) { |
| 830 | $result = $function($node, $op, $a3, $a4); | $result = $function ($node, $op, $a3, $a4); |
| 831 | if (isset($result)) { | if (isset ($result)) { |
| 832 | $return = array_merge($return, $result); | $return = array_merge($return, $result); |
| 833 | } | } |
| 834 | } | } |
| 835 | } | } |
| 836 | return $return; | return $return; |
| 837 | } | } |
| 838 | ||
| 839 | /** | /** |
| 840 | * Admin funtions for the module | * Admin funtions for the module |
| 841 | */ | */ |
| 842 | function business_admin_page() { | function business_admin_page() { |
| 843 | return '<div class="business">Select the setting you wish to edit from the menu.</div>'; | 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. | * Present a business submission form or a set of links to such forms. |
| 848 | * | * |
| 849 | */ | */ |
| 850 | function business_add() { | function business_add() { |
| 851 | global $user; | global $user; |
| 852 | ||
| 853 | $edit = isset($_POST['edit']) ? $_POST['edit'] : ''; | $edit = isset ($_POST['edit']) ? $_POST['edit'] : ''; |
| 854 | $node = null; | $node = null; |
| 855 | ||
| 856 | // If a business type has been specified, validate its existence. | // If a business type has been specified, validate its existence. |
| 857 | ||
| 858 | $ptypes = business_invoke_businessapi($node, 'wizard_select'); | $ptypes = business_invoke_businessapi($node, 'wizard_select'); |
| 859 | if (arg(3) && in_array(arg(3), array_keys($ptypes))) { | if (arg(3) && in_array(arg(3), array_keys($ptypes))) { |
| 860 | $type = arg(3); | $type = arg(3); |
| 861 | ||
| 862 | // Initialize settings: | // Initialize settings: |
| 863 | $node = array('uid' => $user->uid, 'name' => $user->name, 'type' => 'business', 'ptype' => $type); | $node = array ( |
| 864 | 'uid' => $user->uid, | |
| 865 | drupal_set_title(t('Submit %name', array('%name' => $ptypes[$type]))); | 'name' => $user->name, |
| 866 | $output = drupal_get_form('business_node_form', $node); | 'type' => 'business', |
| 867 | } | 'ptype' => $type |
| 868 | else { | ); |
| 869 | $output = business_types_listing(); | |
| 870 | } | drupal_set_title(t('Submit %name', array ( |
| 871 | return $output; | '%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 | /** | /** |
| # | Line 787 function business_add() { | Line 883 function business_add() { |
| 883 | */ | */ |
| 884 | function business_types_listing($link = 'node/add/business') { | function business_types_listing($link = 'node/add/business') { |
| 885 | $node = null; | $node = null; |
| 886 | // If no (valid) business type has been provided, display a business type overview. | // If no (valid) business type has been provided, display a business type overview. |
| 887 | foreach (business_invoke_businessapi($node, 'wizard_select') as $type => $name) { | foreach (business_invoke_businessapi($node, 'wizard_select') as $type => $name) { |
| 888 | if($name == 'Generic'){ | if ($name == 'Generic') { |
| 889 | $name = 'Any other business'; | $name = 'Any other business'; |
| 890 | $key ='Z'; | $key = 'Z'; |
| 891 | } | } else { |
| 892 | else{ | $key = $name; |
| 893 | $key = $name; | } |
| 894 | } | $out = '<dt>' . l($name, "node/add/business/$type", array ( |
| 895 | $out = '<dt>'. l($name, "node/add/business/$type", array('title' => t('Add a %s.', array('%s' => $name)))) .'</dt>'; | 'title' => t('Add a %s.', array ( |
| 896 | '%s' => $name | |
| 897 | $item[$key] = $out; | )) |
| 898 | } | )) . '</dt>'; |
| 899 | ||
| 900 | if (isset($item)) { | $item[$key] = $out; |
| 901 | ksort($item); | } |
| 902 | $output = t('Please select the category your business matches.') .'<dl>'. implode('', $item) .'</dl>'; | |
| 903 | } | if (isset ($item)) { |
| 904 | else { | ksort($item); |
| 905 | $output = t('No types of business are defined so you cannot create any businesses.'); | $output = t('Please select the category your business matches.') . '<dl>' . implode('', $item) . '</dl>'; |
| 906 | } | } else { |
| 907 | return $output; | $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. | * Page callback that renders a node listing for the selected term. |
| 914 | */ | */ |
| 915 | function business_menu_page() { | function business_menu_page() { |
| 916 | ||
| 917 | if (arg(2)) { | if (arg(2)) { |
| 918 | $arguments = explode('/', $_GET['q']); | $arguments = explode('/', $_GET['q']); |
| 919 | $main_tid = db_escape_string(array_pop($arguments)); | $main_tid = db_escape_string(array_pop($arguments)); |
| 920 | return business_list_page(arg(1), $main_tid); | return business_list_page(arg(1), $main_tid); |
| 921 | }else { | } else { |
| 922 | return business_list_page(arg(1)); | return business_list_page(arg(1)); |
| 923 | } | } |
| 924 | } | } |
| 925 | ||
| 926 | /** | /** |
| # | Line 833 function business_menu_page() { | Line 931 function business_menu_page() { |
| 931 | function business_list_page($vid = null, $tid = null) { | function business_list_page($vid = null, $tid = null) { |
| 932 | $base = 'directory/' . $vid; | $base = 'directory/' . $vid; |
| 933 | $context = business_breadcrumb($vid, $tid); | $context = business_breadcrumb($vid, $tid); |
| 934 | $parents = taxonomy_get_parents_all($context->tid); | $parents = taxonomy_get_parents_all($context->tid); |
| 935 | if ($parents) { | if ($parents) { |
| 936 | $parents = array_reverse($parents); | $parents = array_reverse($parents); |
| 937 | foreach ($parents as $p) { | foreach ($parents as $p) { |
| 938 | if ($p->tid) { | if ($p->tid) { |
| 939 | $base .= "/" . $p->tid; | $base .= "/" . $p->tid; |
| 940 | } | } |
| 941 | } | } |
| 942 | } | } |
| 943 | return $output .= theme('business_collection', $vid, $tid); | return $output .= theme('business_collection', $vid, $tid); |
| 944 | } | } |
| 945 | ||
| # | Line 849 function business_list_page($vid = null, | Line 947 function business_list_page($vid = null, |