/[drupal]/contributions/modules/carbon/carbon_footprint.inc
ViewVC logotype

Contents of /contributions/modules/carbon/carbon_footprint.inc

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


Revision 1.24 - (show annotations) (download) (as text)
Wed Jul 2 12:53:08 2008 UTC (16 months, 3 weeks ago) by johnackers
Branch: MAIN
CVS Tags: DRUPAL-5--0-2, DRUPAL-6--1-0, HEAD
Changes since 1.23: +168 -1002 lines
File MIME type: text/x-php
branch DRUPAL-5 merged in
1 <?php
2 /*
3 * $Id: carbon_footprint.inc,v 1.23.2.4 2007/05/10 11:57:46 johnackers Exp $
4 *
5 * Created on 26-Feb-2007
6 *
7 * @file
8 * quick client side calculator that provides a spreadsheet.
9 *
10 * THIS IS STILL IN DEVELOPMENT. IT IS NOT FINISHED.
11 */
12
13
14 /*
15
16 function mymodule_edit_record($record) {
17 $output = t('This is my edit page!');
18 $output .= drupal_get_form('mymodule_edit_record_form', $record);
19 return $output;
20 }
21
22 function mymodule_edit_record_form($record) {
23 $form['my_field'] = array(
24 '#type' => 'textfield',
25 '#title' => 'Record name',
26 '#default_value' => $record->name,
27 );
28 return $form;
29 }
30
31
32 */
33 function carbon_footprint()
34 {
35 $fields = array(
36
37 array("Gas consumption in hours", "therms", 3.4, 5.6, 7.8),
38 array("electricity in hours", "Kwh", 3.4, 5.6, 7.8)
39 );
40
41 $path = drupal_get_path("module", "carbon");
42 drupal_add_js($path . "/carbon.js", "module");
43 drupal_add_css($path . "/carbon.css");
44
45 $output = drupal_get_form("carbon_footprint_form", $fields);
46
47 return $output ;
48 }
49
50
51
52
53 function carbon_footprint_form($fieldblock)
54 {
55 $form = array();
56
57 $r = 0 ;
58 foreach ($fieldblock as $fields)
59 {
60
61 $subform = array(
62 "#name" => "abcd",
63 "#type" => "fieldset",
64 "#title" => $fields[0],
65 "#weight" => -1,
66 "#collapsible" => false,
67 "#collapsed" => false
68 );
69
70 $subform["choice"] = array(
71 "#type" => "radios",
72 "#options" => array("one","meter"),
73 "#default_value" => 1,
74 // "#description" => t("Select type of carbon debit"),
75 "#attributes" => array("onchange" => "scope_change(this.value);")
76 );
77
78 $subform["help"] = array(
79
80 "#type" => "item",
81 "#value" => $fields[0],
82 "#size" => 14,
83 "#maxlength" => 20,
84 "#value" => "<div class='scope-1' style='white-space: normal'>" .
85 t("Note that meter readings are subtracted from one another to calculate " .
86 "consumption. You need to have at least two meter readings before this source of " .
87 "emissions will be included in your carbon footprint.")."</div>",
88 );
89
90 $subform["amount"] = array(
91
92 "#value" => 0,
93 "#type" => "textfield",
94 "#size" => 8,
95 // "#description" => "<div class='scope-0'>Enter the one off value</div>".
96 // "<div class='scope-1'>Enter the meter reading</div>",
97 "#maxlength" => 20,
98 // "#suffix" => "KWh of electricity"
99 );
100
101 $subform["units"] = array(
102
103 "#value" => 0,
104 "#type" => "select",
105 "#options" => array("Kwh of Electricity", "Therms of gas"),
106 "#size" => 8,
107 // "#description" => "<div class='scope-0'>Enter the one off value</div>".
108 // "<div class='scope-1'>Enter the meter reading</div>",
109 "#maxlength" => 20,
110 // "#suffix" => "KWh of electricity"
111 );
112
113 $subform["adjust"] = array(
114 // "#prefix" => "adjustment",
115 "#value" => 0,
116 "#type" => "textfield",
117 "#size" => 8,
118 // "#description" => "<div class='scope-0'>Enter the one off value</div>".
119 // "<div class='scope-1'>Enter the meter reading</div>",
120 "#maxlength" => 20
121 );
122
123 $subform["co2"] = array(
124
125 "#type" => "textfield",
126 "#size" => 14,
127 "#readonly" => true,
128 "#maxlength" => 20
129 );
130 $subform["toCo2"] = array(
131
132 "#type" => "hidden",
133 "#value" => 1444
134 );
135 $form["my".$r++] = $subform ;
136 }
137 return $form ;
138 }
139
140
141
142 function theme_carbon_footprint_form($form)
143 {
144 $header = array(t("amount"),t("select units"),t("apply adjustment"), t("total CO2"));
145 $rows = array();
146
147 foreach ($form as $rowname => $row)
148 {
149 // if (empty($row)) continue ;
150 // if (!is_array($row))
151 // continue ;
152 if (substr($rowname,0,1) == "#")
153 continue ;
154 $colsTop = array(); $colsBottom = array();
155 foreach ($row as $colname => $col)
156 {
157 if (substr($colname,0,1) == "#")
158 continue ;
159
160 if ($col["#type"] == "hidden")
161 continue ;
162
163 if ($colname == "help")
164 {
165
166 $colsTop[] = (array('data' => drupal_render($col), 'colspan' => count($header)-1));
167 }
168 else
169 if ($colname == "choice")
170 {
171 $colsTop[] = drupal_render($col);
172 }
173 else
174 {
175 $text = drupal_render($col);
176 if (strspn($text, "no-array ") != 0)
177 {
178 $colsBottom[] = "yuk ".$rowname." ".$colname ;
179 }
180 else
181 $colsBottom[] = /* $rowname." ".$colname." ".$col["type"]." ". */ $text ;
182
183 // unset($col);
184 }
185 }
186 $rows[] = $colsTop ;
187 if (count($colsBottom))
188 $rows[] = $header ;
189 $rows[] = array("data" => $colsBottom, "valign"=>"top") ;
190 unset($form[$rowname]);
191
192
193 }
194 $output = theme("table", null, $rows);
195
196 $output .= drupal_render($form);
197
198 return $output;
199 }
200
201
202
203
204 function form_render($col)
205 {
206 if (is_array($col)) return $col[0];
207 return $col ;
208
209 }
210
211
212
213 /**
214 * Add clickable link to words.
215 */
216 function click_info_make($text, $words) {
217 foreach ($words as $word => $message) {
218 $text = str_replace ($word, '<span class="clickInfo" title="' . $message . '">' . $word . '</span>', $text);
219 }
220 return $text;
221 }
222
223
224 ?>

  ViewVC Help
Powered by ViewVC 1.1.2