Changeset 84 for openweather
- Timestamp:
- 05/01/07 00:33:34 (5 years ago)
- Location:
- openweather
- Files:
-
- 4 added
- 1 edited
-
fonts (added)
-
fonts/ARIAL.TTF (added)
-
fonts/ARIALBD.TTF (added)
-
graph.php (added)
-
openweather.module (modified) (9 diffs)
Legend:
- Unmodified
- Added
- Removed
-
openweather/openweather.module
r83 r84 106 106 'title' => t('readings'), 107 107 'callback' => 'openweather_csv_readings', 108 'access' => user_access('access content'), 109 'weight' => 3, 110 'type' => MENU_LOCAL_TASK); 111 112 $items[] = array('path' => 'node/'. arg(1) .'/graph', 113 'title' => t('graph'), 114 'callback' => 'openweather_graph', 108 115 'access' => user_access('access content'), 109 116 'weight' => 3, … … 153 160 154 161 /** 155 * Callback for processing a vote156 */157 function openweather_add_reading() {158 global $user;159 $nid = arg(1);160 161 $node = node_load($nid);162 163 $edit = $_POST['edit'];164 $date = $edit['date'];165 $value = $edit['value'];166 $comment = $edit['comment'];167 168 169 if ($node->uid == $user->uid) {170 db_query('INSERT INTO {openweather_readings} (nid, time, value, comment) VALUES (%d, "%s", %d, "%s")', $node->nid, $date, $value, $comment);171 drupal_set_message(t('Your reading was recorded.'));172 }173 else {174 drupal_set_message(t("You're not allowed to add reading for this openweather."), 'error');175 }176 177 drupal_goto('node/'. $nid);178 }179 180 /**181 162 * Implementation of hook_view(). 182 163 * … … 195 176 $res = openweather_extrapolate(openweather_get_values($node), 1,30); 196 177 197 $output .= openweather_graph($res);178 //$output .= openweather_graph($res); 198 179 199 180 $node->links = $links; … … 202 183 $node->body = $output; //$output.drupal_get_form('openweather_add_reading', $form); 203 184 } 204 205 /**206 *207 */208 function openweather_edit_readings() {209 $nid = arg(1);210 $node = node_load($nid);211 212 if ($_GET['action'] == 'delete'){213 db_query("DELETE FROM {openweather_readings} WHERE nid=%d AND time='%s';", $nid, $_GET['time']);214 drupal_set_message(t('Reading removed.'));215 }216 217 $headers = array(218 array('data'=>t('Date')),219 array('data'=>t('Reading')),220 array('data'=>t('Comment')),221 array('data'=>t('Edit')),222 array('data'=>t('Delete')),223 );224 225 $rows = array();226 $rows_ = openweather_get_values($node);227 foreach ($rows_ as $r){228 $rows[] = array(229 $r->time,230 $r->value,231 $r->comment,232 l(t('edit'), "node/$nid/edit_reading", array(), 'time='.urlencode($r->time)),233 l(t('delete'), "node/$nid/edit_readings", array(), 'action=delete&time='.urlencode($r->time)),234 );235 }236 237 $output .= theme("table", $headers, $rows);238 return $output;239 }240 241 /**242 * Edit the reading243 */244 function openweather_edit_reading() {245 $nid = arg(1);246 $node = node_load($nid);247 $edit = $_REQUEST['edit'];248 249 if ($_REQUEST['op'] == t('Save')){250 db_query("UPDATE {openweather_readings} SET time='%s', value=%d, comment='%s' WHERE nid=%d AND time='%s';", $edit['time'], $edit['value'], $edit['comment'], $edit['nid'], $edit['orig_time']);251 drupal_set_message("Saved reading.");252 drupal_goto("node/$nid/edit_readings");253 } else if ($_REQUEST['op'] == t('Cancel')){254 drupal_set_message("Cancelled editing.");255 drupal_goto("node/$nid/edit_readings");256 }257 258 $r = db_query("SELECT * FROM {openweather_readings} WHERE nid=%d AND time='%s';", $nid, $_GET['time']);259 $r = db_fetch_object($r);260 261 $form['nid'] = array('#type' => 'hidden', '#value' => $node->nid);262 $form['orig_time'] = array('#type' => 'hidden', '#value' => $r->time);263 $form['time'] = array(264 '#title' => t('Date'),265 '#type' => 'textfield',266 '#default_value' => $r->time,267 '#attributes' => array('class' => 'jscalendar'),268 '#jscalendar_ifFormat' => '%Y-%m-%d %H:%M',269 '#jscalendar_showsTime' => 'true',270 '#jscalendar_timeFormat' => variable_get('event_ampm', '0') == 0 ? '24' : '12',271 '#size' => 19,272 '#maxlength' => 19,273 '#weight' => -14,274 '#description' => t('YYYY-MM-DD HH:MM'),275 );276 277 $form['value'] = array(278 '#title' => t('Value'),279 '#type' => 'textfield',280 '#default_value' => $r->value);281 282 $form['comment'] = array(283 '#title' => t('Comment'),284 '#type' => 'textfield',285 '#default_value' => $r->comment);286 287 $form['action_save'] = array('#type' => 'submit', '#value' => t('Save'));288 $form['action_cancel'] = array('#type' => 'submit', '#value' => t('Cancel'));289 $form['#action'] = url('node/'. $node->nid.'/edit_reading');290 291 return drupal_get_form('openweather_edit_reading', $form);292 }293 294 185 295 186 /** … … 313 204 function openweather_get_values($node){ 314 205 $res = array(); 315 $results = db_query("SELECT time, value, commentFROM {openweather_readings} WHERE nid = %d ORDER BY time DESC", $node->nid);206 $results = db_query("SELECT * FROM {openweather_readings} WHERE nid = %d ORDER BY time DESC", $node->nid); 316 207 317 208 while ($row = db_fetch_object($results)){ … … 375 266 * Draw a CSS/HTML graph 376 267 */ 268 /* 377 269 function openweather_graph($entries){ 378 270 if (count($entries) == 0) … … 399 291 return $output; 400 292 } 401 293 */ 402 294 function openweather_xmlrpc(){ 403 295 return array( … … 428 320 if ($user->uid) { 429 321 $node = node_load($nid); 322 watchdog('INFO', $node->type, WATCHDOG_WARNING); 323 if ($node->type != 'openweather') 324 return false; 430 325 // Check person owns or can write to entry 431 return true; 326 327 return db_query("INSERT INTO {openweather_readings} (nid, `time`, temp_in, temp_out, rel_hum_in, rel_hum_out, windspeed, wind_angle, wind_chill, rain_1h, rel_pressure, dewpoint) VALUES (%d, '%s', %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)", $nid, $data['timestamp'], $data['temp_in'], $data['temp_out'], $data['rel_hum_in'], $data['rel_hum_out'], $data['windspeed'], $data['wind_angle'], $data['wind_chill'], $data['rain_1h'], $data['rel_pressure'], $data['dewpoint']); 432 328 } else { 433 329 return false; … … 435 331 } 436 332 333 334 /** 335 * Produce a PNG graph of the $type data for the last 24 hours 336 */ 337 function openweather_graph() { 338 $nid = arg(1); 339 $type = arg(3); 340 $node = node_load($nid); 341 342 if ($type == null) $type = 'temp'; 343 344 $results = openweather_get_values($node); 345 drupal_set_header('Content-Type: image/png'); 346 include 'graph.php'; 347 $g = new graph(400, 240); 348 $g->parameter['path_to_fonts'] = 'modules/openweather/fonts/'; 349 $g->parameter['title'] = $type; 350 $g->parameter['x_label'] = 'Date'; 351 $g->parameter['y_label'] = ''; 352 353 $g->draw(); 354 }
Note: See TracChangeset
for help on using the changeset viewer.
