/[drupal]/contributions/modules/sheetnode/sheetnode.module
ViewVC logotype

Contents of /contributions/modules/sheetnode/sheetnode.module

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.4 - (show annotations) (download) (as text)
Wed Nov 12 11:02:54 2008 UTC (12 months, 2 weeks ago) by kratib
Branch: MAIN
CVS Tags: HEAD
Branch point for: DRUPAL-5
Changes since 1.3: +6 -4 lines
File MIME type: text/x-php
Fixed scrollbars by applying patch to original code :-(
1 <?php
2 // $Id: sheetnode.module,v 1.3 2008/11/11 07:28:52 kratib Exp $
3
4 function sheetnode_node_info() {
5 return array(
6 'sheetnode' => array(
7 'name' => t('Sheetnode'),
8 'module' => 'sheetnode',
9 'description' => t('A spreadsheet node.'),
10 ),
11 );
12 }
13
14 function sheetnode_perm() {
15 return array('create sheetnode', 'edit own sheetnode');
16 }
17
18 function sheetnode_access($op, $node) {
19 global $user;
20
21 if ($op == 'create') {
22 return user_access('create sheetnode');
23 }
24
25 if ($op == 'update' || $op == 'delete') {
26 return user_access('edit own sheetnode') && ($user->uid == $node->uid);
27 }
28 }
29
30 function sheetnode_delete(&$node) {
31 db_query('DELETE FROM {sheetnode} WHERE nid=%d', $node->nid);
32 }
33
34 function sheetnode_form(&$node) {
35 $type = node_get_types('type', $node);
36
37 // We need to define form elements for the node's title and body.
38 $form['title'] = array(
39 '#type' => 'textfield',
40 '#title' => check_plain($type->title_label),
41 '#required' => TRUE,
42 '#default_value' => $node->title,
43 '#weight' => -5
44 );
45
46 // We want the body and filter elements to be adjacent. We could try doing
47 // this by setting their weights, but another module might add elements to the
48 // form with the same weights and end up between ours. By putting them into a
49 // sub-array together, we're able force them to be rendered together.
50 $form['body_filter']['body'] = array(
51 '#type' => 'textarea',
52 '#title' => check_plain($type->body_label),
53 '#default_value' => $node->body,
54 '#required' => FALSE
55 );
56 $form['body_filter']['filter'] = filter_form($node->format);
57
58 // SocialCalc sheet.
59 if ($node->nid) {
60 $value = _sheetnode_load($node->nid);
61 }
62 else {
63 $value = '';
64 }
65 $output = _sheetnode_inject($value);
66 $form['sheet']['view']['#value'] = $output;
67 $form['sheet']['save'] = array('#type' => 'hidden');
68 return $form;
69 }
70
71 function _sheetnode_inject($value) {
72 drupal_add_js(drupal_get_path('module', 'sheetnode').'/socialcalc/socialcalcconstants.js');
73 drupal_add_js(drupal_get_path('module', 'sheetnode').'/socialcalc/socialcalc-3.js');
74 drupal_add_js(drupal_get_path('module', 'sheetnode').'/socialcalc/socialcalctableeditor.js');
75 drupal_add_js(drupal_get_path('module', 'sheetnode').'/socialcalc/formatnumber2.js');
76 drupal_add_js(drupal_get_path('module', 'sheetnode').'/socialcalc/formula1.js');
77 drupal_add_js(drupal_get_path('module', 'sheetnode').'/socialcalc/socialcalcspreadsheetcontrol.js');
78 drupal_add_js(drupal_get_path('module', 'sheetnode').'/sheetnode.js');
79 drupal_add_css(drupal_get_path('module', 'sheetnode').'/socialcalc/socialcalc.css');
80 drupal_add_css(drupal_get_path('module', 'sheetnode').'/sheetnode.css');
81 drupal_add_js(array('sheetnode' => array('value' => $value,
82 'imageprefix' => url(drupal_get_path('module', 'sheetnode').'/socialcalc/images/sc', NULL, NULL, TRUE),
83 'element' => 'sheetview',
84 )), 'setting');
85 return <<<EOS
86 <div class="sheetview" id="sheetview">
87 <script language="javascript" type="text/javascript">
88 $(document).ready(function() {
89 Drupal.sheetnode.startUp();
90 });
91 </script>
92 </div>
93 EOS;
94 }
95
96 function sheetnode_insert($node) {
97 _sheetnode_save($node->nid, $node->save);
98 }
99
100 function sheetnode_update($node) {
101 _sheetnode_save($node->nid, $node->save);
102 }
103
104 function sheetnode_view($node, $teaser = FALSE, $page = FALSE) {
105 $node = node_prepare($node, $teaser);
106
107 // SocialCalc sheet.
108 if (!$teaser) {
109 $value = _sheetnode_load($node->nid);
110 $output = _sheetnode_inject($value);
111 $node->content['sheet']['#value'] = $output;
112 }
113
114 return $node;
115 }
116
117 function sheetnode_menu($may_cache) {
118 $items = array();
119 if ($may_cache) {
120 $items[] = array(
121 'path' => 'node/add/sheetnode',
122 'title' => t('Sheetnode'),
123 'access' => user_access('create sheetnode'),
124 );
125 }
126 return $items;
127 }
128
129 function _sheetnode_load($nid) {
130 $value = db_result(db_query("SELECT value FROM {sheetnode} WHERE nid=%d", $nid));
131 return ($value === FALSE ? '' : unserialize($value));
132 }
133
134 function _sheetnode_save($nid, $value) {
135 db_query("DELETE FROM {sheetnode} WHERE nid=%d", $nid);
136 db_query("INSERT INTO {sheetnode} (nid, value) VALUES (%d, '%s')", $nid, serialize($value));
137 }
138

  ViewVC Help
Powered by ViewVC 1.1.2