business_node
[ class tree: business_node ] [ index: business_node ] [ all elements ]

Source for file business_node.module

Documentation is available at business_node.module

  1. <?php
  2. // $Id$
  3.  
  4. /**
  5. * @file
  6. * TODO: Enter file description here.
  7. */
  8.  
  9. /**
  10. * Implementation of hook_block().
  11. */
  12. function business_node_block($op = 'list', $delta = 0, $edit = array()) {
  13. if ($op == 'list') {
  14. $blocks[0]['info'] = t('TODO: Fill in block description');
  15. // OPTIONAL: Add additional block descriptions here, if required.
  16. return $blocks;
  17. }
  18. else if ($op == 'configure') {
  19. // OPTIONAL: Enter form elements to add to block configuration screen, if required.
  20. }
  21. else if ($op == 'save') {
  22. // OPTIONAL: Add code to trigger when block configuration is saved, if required.
  23. }
  24. else if ($op == 'view') {
  25. switch ($delta) {
  26. case 0:
  27. $block['subject'] = t('TODO: Enter block title');
  28. $block['content'] = t('TODO: Enter block content');
  29. break;
  30. // OPTIONAL: Enter additional cases for each additional block, if defined.
  31. }
  32. return $block;
  33. }
  34. }
  35.  
  36.  
  37. /**
  38. * Implementation of hook_help().
  39. */
  40. function business_node_help($section) {
  41. switch ($section) {
  42. case 'admin/help#business_node':
  43. return t('Business Node');
  44. case 'admin/modules#description':
  45. return t('Business Node');
  46. case 'node/add#business_node':
  47. return t('TODO: enter description of node.');
  48. // OPTIONAL: Add additional cases for other paths that should display help text.
  49. }
  50. }
  51.  
  52.  
  53. /**
  54. * Implementation of hook_menu().
  55. */
  56. function business_node_menu($may_cache) {
  57. $items = array();
  58.  
  59. if ($may_cache) {
  60. $items[] = array(
  61. 'path' => 'node/add/business_node',
  62. 'title' => t('Business Node'),
  63. 'access' => user_access('create Business Node'),
  64. // OPTIONAL: Fill in other properties
  65. );
  66. // OPTIONAL: Fill in additional static menu items
  67. }
  68. // OPTIONAL: Put in else statement for dynamic menu items that can't be cached.
  69.  
  70. return $items;
  71. }
  72.  
  73.  
  74. /**
  75. * Implementation of hook_nodeapi().
  76. */
  77. function business_node_nodeapi(&$node, $op, $teaser = NULL, $page = NULL) {
  78. switch ($op) {
  79. case 'delete revision':
  80. // TODO: Enter revision deletion query here, for example:
  81. // db_query('DELETE FROM {node_example} WHERE vid = %d', $node->vid);
  82. break;
  83. }
  84. }
  85.  
  86.  
  87. /**
  88. * Implementation of hook_perm().
  89. */
  90. function business_node_perm() {
  91. return array('create Business Node', 'edit own Business Node');
  92. }
  93.  
  94.  
  95. /**
  96. * Implementation of hook_taxonomy().
  97. */
  98. function business_node_taxonomy($op, $type, $object) {
  99.  
  100. }
  101.  
  102.  
  103. /**
  104. * Implementation of hook_access().
  105. */
  106. function business_node_access($op, $node) {
  107. global $user;
  108.  
  109. if ($op == 'create') {
  110. return user_access('create Business Node');
  111. }
  112.  
  113. if ($op == 'update' || $op == 'delete') {
  114. if (user_access('edit own Business Node') && ($user->uid == $node->uid)) {
  115. return TRUE;
  116. }
  117. }
  118. }
  119.  
  120.  
  121. /**
  122. * Implementation of hook_delete().
  123. */
  124. function business_node_delete(&$node) {
  125. // TODO: Enter database deletion query here, for example:
  126. // db_query('DELETE FROM {node_example} WHERE nid = %d', $node->nid);
  127. }
  128.  
  129.  
  130. /**
  131. * Implementation of hook_form().
  132. */
  133. function business_node_form(&$node, &$param) {
  134. $form['title'] = array(
  135. '#type' => 'textfield',
  136. '#title' => t('Name'),
  137. '#required' => TRUE,
  138. '#default_value' => $node->title,
  139. '#weight' => -5
  140. );
  141. $form['body'] = array(
  142. '#type' => 'textarea',
  143. '#title' => t('Description'),
  144. '#default_value' => $node->body,
  145. '#rows' => '10',
  146. '#required' => FALSE
  147. );
  148. // $form['body_filter']['filter'] = filter_form($node->format);
  149.  
  150. $form['keywords'] = array(
  151. '#type' => 'textfield',
  152. '#title' => t('Keywords'),
  153. '#default_value' => $node->keywords,
  154. '#required' => FALSE,
  155. '#weight' => 1);
  156. $form['chamber_member'] = array(
  157. '#type' => 'checkbox',
  158. '#title' => t('Chamber of Commerce Member'),
  159. '#default_value' => $node->chamber_member,
  160. '#required' => FALSE,
  161. '#weight' => 6);
  162. $form['url'] = array(
  163. '#type' => 'textfield',
  164. '#title' => t('Website URL'),
  165. '#default_value' => $node->url,
  166. '#required' => FALSE,
  167. '#weight' => 3);
  168. $form['email'] = array(
  169. '#type' => 'textfield',
  170. '#title' => t('Email Address'),
  171. '#default_value' => $node->email,
  172. '#required' => FALSE,
  173. '#weight' => 4);
  174. $form['contact'] = array(
  175. '#type' => 'textfield',
  176. '#title' => t('Contact Person'),
  177. '#default_value' => $node->contact,
  178. '#required' => FALSE,
  179. '#weight' => 5);
  180. $form['address1'] = array(
  181. '#type' => 'fieldset',
  182. '#title' => t('Primary Address'),
  183. '#weight' => 10,
  184. '#collapsible' => TRUE,
  185. '#collapsed' => TRUE );
  186. $form['address1']['address1_line1'] = array(
  187. '#type' => 'textfield',
  188. '#title' => t('Address'),
  189. '#default_value' => $node->address1_line1,
  190. '#required' => FALSE,
  191. '#size' => 50,
  192. '#maxlength' => 50,
  193. '#weight' => -1);
  194. $form['address1']['address1_line2'] = array(
  195. '#type' => 'textfield',
  196. '#title' => '',
  197. '#default_value' => $node->address1_line2,
  198. '#required' => FALSE,
  199. '#size' => 50,
  200. '#maxlength' => 50,
  201. '#weight' => 0);
  202. $form['address1']['csz']['address1_city'] = array(
  203. '#type' => 'textfield',
  204. '#title' => t('City'),
  205. '#default_value' => $node->address1_city,
  206. '#size' => 50,
  207. '#maxlength' => 50,
  208. '#required' => FALSE);
  209. $form['address1']['csz']['address1_state'] = array(
  210. '#type' => 'textfield',
  211. '#title' => t('State'),
  212. '#default_value' => $node->address1_state,
  213. '#size' => 5,
  214. '#maxlength' => 2,
  215. '#required' => FALSE);
  216. $form['address1']['csz']['address1_zip'] = array(
  217. '#type' => 'textfield',
  218. '#title' => t('Zip Code'),
  219. '#default_value' => $node->address1_zip,
  220. '#size' => 10,
  221. '#maxlength' => 10,
  222. '#required' => FALSE);
  223. $form['address1']['map']['address1_showmap'] = array(
  224. '#type' => 'checkbox',
  225. '#title' => t('Show Map?'),
  226. '#default_value' => $node->address1_showmap,
  227. '#required' => FALSE);
  228. $form['address1']['map']['address1_latitude'] = array(
  229. '#type' => 'textfield',
  230. '#title' => t('Latitude'),
  231. '#default_value' => $node->address1_latitude,
  232. '#size' => 10,
  233. '#maxlength' => 10,
  234. '#required' => FALSE);
  235. $form['address1']['map']['address1_longitude'] = array(
  236. '#type' => 'textfield',
  237. '#title' => t('Longitude'),
  238. '#default_value' => $node->address1_longitude,
  239. '#size' => 10,
  240. '#maxlength' => 10,
  241. '#required' => FALSE);
  242. $form['address2'] = array(
  243. '#type' => 'fieldset',
  244. '#title' => t('Secondary Address'),
  245. '#weight' => 10,
  246. '#collapsible' => TRUE,
  247. '#collapsed' => TRUE );
  248. $form['address2']['address2_line1'] = array(
  249. '#type' => 'textfield',
  250. '#title' => t('Address'),
  251. '#default_value' => $node->address2_line1,
  252. '#required' => FALSE,
  253. '#size' => 50,
  254. '#maxlength' => 50,
  255. '#weight' => -1);
  256. $form['address2']['address2_line2'] = array(
  257. '#type' => 'textfield',
  258. '#title' => '',
  259. '#default_value' => $node->address2_line2,
  260. '#required' => FALSE,
  261. '#size' => 50,
  262. '#maxlength' => 50,
  263. '#weight' => 0);
  264. $form['address2']['csz']['address2_city'] = array(
  265. '#type' => 'textfield',
  266. '#title' => t('City'),
  267. '#default_value' => $node->address2_city,
  268. '#size' => 50,
  269. '#maxlength' => 50,
  270. '#required' => FALSE);
  271. $form['address2']['csz']['address2_state'] = array(
  272. '#type' => 'textfield',
  273. '#title' => t('State'),
  274. '#default_value' => $node->address2_state,
  275. '#size' => 5,
  276. '#maxlength' => 2,
  277. '#required' => FALSE);
  278. $form['address2']['csz']['address2_zip'] = array(
  279. '#type' => 'textfield',
  280. '#title' => t('Zip Code'),
  281. '#default_value' => $node->address2_zip,
  282. '#size' => 10,
  283. '#maxlength' => 10,
  284. '#required' => FALSE);
  285. $form['address2']['map']['address2_showmap'] = array(
  286. '#type' => 'checkbox',
  287. '#title' => t('Show Map?'),
  288. '#default_value' => $node->address2_showmap,
  289. '#required' => FALSE);
  290. $form['address2']['map']['address2_latitude'] = array(
  291. '#type' => 'textfield',
  292. '#title' => t('Latitude'),
  293. '#default_value' => $node->address2_latitude,
  294. '#size' => 10,
  295. '#maxlength' => 10,
  296. '#required' => FALSE);
  297. $form['address2']['map']['address2_longitude'] = array(
  298. '#type' => 'textfield',
  299. '#title' => t('Longitude'),
  300. '#default_value' => $node->address2_longitude,
  301. '#size' => 10,
  302. '#maxlength' => 10,
  303. '#required' => FALSE);
  304. // TODO: Enter additional form elements
  305.  
  306. return $form;
  307. }
  308.  
  309.  
  310. /**
  311. * Implementation of hook_insert().
  312. */
  313. function business_node_insert($node) {
  314. // TODO: Enter database insertion query here, for example:
  315. // db_query("INSERT INTO {node_example} (vid, nid, color, quantity) VALUES (%d, %d, '%s', %d)", $node->vid, $node->nid, $node->color, $node->quantity);
  316. $fields = array('nid' => "%d",
  317. 'description' => "'%s'",
  318. 'keywords' => "'%s'",
  319. 'chamber_member' => "%d",
  320. 'url' => "'%s'",
  321. 'email' => "'%s'",
  322. 'contact' => "'%s'",
  323. 'address1_line1' => "'%s'",
  324. 'address1_line2' => "'%s'",
  325. 'address1_city' => "'%s'",
  326. 'address1_state' => "'%s'",
  327. 'address1_zip' => "'%s'",
  328. 'address1_latitude' => "%f",
  329. 'address1_longitude'=> "%f",
  330. 'address1_showmap' => "%d",
  331. 'address2_line1' => "'%s'",
  332. 'address2_line2' => "'%s'",
  333. 'address2_city' => "'%s'",
  334. 'address2_state' => "'%s'",
  335. 'address2_zip' => "'%s'",
  336. 'address2_latitude' => "%f",
  337. 'address2_longitude'=> "%f",
  338. 'address2_showmap' => "%d");
  339.  
  340. $fields_str = join(',', array_keys($fields));
  341. $format_str = join(',', $fields);
  342. foreach($fields as $field=>$format)
  343. {
  344. $args[] = $node->$field;
  345. }
  346. db_query("INSERT INTO {business_node} ({$fields_str}) VALUES ({$format_str})", $args);
  347. }
  348.  
  349.  
  350. /**
  351. * Implementation of hook_load().
  352. */
  353. function business_node_load($node) {
  354. // TODO: Obtain and return additional fields added to the node type, for example:
  355. // $additions = db_fetch_object(db_query('SELECT color, quantity FROM {node_example} WHERE vid = %d', $node->vid));
  356. // return $additions;
  357. $additions = db_fetch_object(db_query('SELECT * FROM {business_node} WHERE nid = %d',$node->nid));
  358. return $additions;
  359. }
  360.  
  361.  
  362. /**
  363. * Implementation of hook_node_info().
  364. */
  365. function business_node_node_info() {
  366. return array('business_node' => array('name' => t('Business Node'), 'base' => 'business_node'));
  367. }
  368.  
  369.  
  370. /**
  371. * Implementation of hook_update().
  372. */
  373. function business_node_update($node) {
  374. if ($node->revision) {
  375. business_node_insert($node);
  376. } else {
  377. $fields = array('nid' => "%d",
  378. 'description' => "'%s'",
  379. 'keywords' => "'%s'",
  380. 'chamber_member' => "%d",
  381. 'url' => "'%s'",
  382. 'email' => "'%s'",
  383. 'contact' => "'%s'",
  384. 'address1_line1' => "'%s'",
  385. 'address1_line2' => "'%s'",
  386. 'address1_city' => "'%s'",
  387. 'address1_state' => "'%s'",
  388. 'address1_zip' => "'%s'",
  389. 'address1_latitude' => "%f",
  390. 'address1_longitude'=> "%f",
  391. 'address1_showmap' => "%d",
  392. 'address2_line1' => "'%s'",
  393. 'address2_line2' => "'%s'",
  394. 'address2_city' => "'%s'",
  395. 'address2_state' => "'%s'",
  396. 'address2_zip' => "'%s'",
  397. 'address2_latitude' => "%f",
  398. 'address2_longitude'=> "%f",
  399. 'address2_showmap' => "%d");
  400. // TODO: Enter database update query here, for example:
  401. // db_query("UPDATE {node_example} SET color = '%s', quantity = %d WHERE vid = %d", $node->color, $node->quantity, $node->vid);
  402.  
  403. foreach($fields as $field=>$format)
  404. {
  405. $set_fields[] = "{$field} = {$format}";
  406. $args[] = $node->$field;
  407. }
  408. $fields_str = join(',', $set_fields);
  409. db_query("UPDATE {business_node} SET {$fields_str}", $args);
  410. }
  411. }
  412.  
  413.  
  414. /**
  415. * Implementation of hook_validate().
  416. */
  417. function business_node_validate(&$node) {
  418. // TODO: Enter form validation code here
  419. }
  420.  
  421.  
  422. /**
  423. * Implementation of hook_view().
  424. */
  425. function business_node_view(&$node, $teaser = FALSE, $page = FALSE) {
  426. // TODO: Insert additional code (call to theme functions, etc.) to execute when viewing a node, for example:
  427. // $node = node_prepare($node, $teaser);
  428. // $order_info = theme('node_example_order_info', $node);
  429. // $node->body .= $order_info;
  430. // $node->teaser .= $order_info;
  431. }

Documentation generated on Fri, 19 May 2006 15:51:17 -0700 by phpDocumentor 1.3.0RC3