Changeset 72
- Timestamp:
- 19/11/06 05:50:04 (6 years ago)
- File:
-
- 1 edited
-
meter/meter.module (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
meter/meter.module
r71 r72 135 135 136 136 function meter_insert($node) { 137 print "<p>meter_insert</p>";138 137 /* 139 138 if (!user_access('administer nodes')) { … … 186 185 'weight' => 3, 187 186 'type' => MENU_LOCAL_TASK); 188 189 187 $items[] = array('path' => 'node/'. arg(1) .'/edit_readings', 188 'title' => t('edit readings'), 189 'callback' => 'meter_edit_readings', 190 'access' => user_access('access content'), 191 'weight' => 3, 192 'type' => MENU_LOCAL_TASK); 193 $items[] = array('path' => 'node/'. arg(1) .'/edit_reading', 194 'title' => t('edit reading'), 195 'callback' => 'meter_edit_reading', 196 'access' => user_access('access content'), 197 'weight' => 3, 198 'type' => MENU_CALLBACK); 190 199 } 191 200 } … … 286 295 287 296 $links = array(); 288 //$links[] = l(t('add reading'), 'node/'.$node->nid.'/add_reading',array('title'=>'Add a meter reading'));297 $links[] = l(t('edit readings'), 'node/'.$node->nid.'/edit_readings',array('title'=>'Edit meter readings')); 289 298 $links[] = l(t('export readings'), 'node/'.$node->nid.'/csv_readings',array('title'=>'Export the meter readings as CSV')); 290 299 … … 316 325 317 326 $res = meter_extrapolate(meter_get_values($node), 1,30); 318 /*foreach ($res as $val){319 $output .= "<p>$val->to $val->value </p>";320 }*/321 327 322 328 $output .= meter_graph($res); 323 $output .= drupal_get_form('meter_add_reading', $form);324 329 325 330 $node->links = $links; 326 $node->body = $node->teaser = $output; 327 } 331 // Only show the add readings form when in full view 332 $node->teaser = $output; 333 $node->body = $output.drupal_get_form('meter_add_reading', $form); 334 } 335 336 /** 337 * 338 */ 339 function meter_edit_readings() { 340 $nid = arg(1); 341 $node = node_load($nid); 342 343 if ($_GET['action'] == 'delete'){ 344 db_query("DELETE FROM {meter_readings} WHERE nid=%d AND time='%s';", $nid, $_GET['time']); 345 drupal_set_message(t('Reading removed.')); 346 } 347 348 $headers = array( 349 array('data'=>t('Date')), 350 array('data'=>t('Reading')), 351 array('data'=>t('Comment')), 352 array('data'=>t('Edit')), 353 array('data'=>t('Delete')), 354 ); 355 356 $rows = array(); 357 $rows_ = meter_get_values($node); 358 foreach ($rows_ as $r){ 359 $rows[] = array( 360 $r->time, 361 $r->value, 362 $r->comment, 363 l(t('edit'), "node/$nid/edit_reading", array(), 'time='.urlencode($r->time)), 364 l(t('delete'), "node/$nid/edit_readings", array(), 'action=delete&time='.urlencode($r->time)), 365 ); 366 } 367 368 $output .= theme("table", $headers, $rows); 369 return $output; 370 } 371 372 /** 373 * Edit the reading 374 */ 375 function meter_edit_reading() { 376 $nid = arg(1); 377 $node = node_load($nid); 378 $edit = $_REQUEST['edit']; 379 380 if ($_REQUEST['op'] == t('Save')){ 381 db_query("UPDATE {meter_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']); 382 drupal_set_message("Saved reading."); 383 drupal_goto("node/$nid/edit_readings"); 384 } else if ($_REQUEST['op'] == t('Cancel')){ 385 drupal_set_message("Cancelled editing."); 386 drupal_goto("node/$nid/edit_readings"); 387 } 388 389 $r = db_query("SELECT * FROM {meter_readings} WHERE nid=%d AND time='%s';", $nid, $_GET['time']); 390 $r = db_fetch_object($r); 391 392 $form['nid'] = array('#type' => 'hidden', '#value' => $node->nid); 393 $form['orig_time'] = array('#type' => 'hidden', '#value' => $r->time); 394 $form['time'] = array( 395 '#title' => t('Date'), 396 '#type' => 'textfield', 397 '#default_value' => $r->time, 398 '#attributes' => array('class' => 'jscalendar'), 399 '#jscalendar_ifFormat' => '%Y-%m-%d %H:%M', 400 '#jscalendar_showsTime' => 'true', 401 '#jscalendar_timeFormat' => variable_get('event_ampm', '0') == 0 ? '24' : '12', 402 '#size' => 19, 403 '#maxlength' => 19, 404 '#weight' => -14, 405 '#description' => t('YYYY-MM-DD HH:MM'), 406 ); 407 408 $form['value'] = array( 409 '#title' => t('Value'), 410 '#type' => 'textfield', 411 '#default_value' => $r->value); 412 413 $form['comment'] = array( 414 '#title' => t('Comment'), 415 '#type' => 'textfield', 416 '#default_value' => $r->comment); 417 418 $form['action_save'] = array('#type' => 'submit', '#value' => t('Save')); 419 $form['action_cancel'] = array('#type' => 'submit', '#value' => t('Cancel')); 420 $form['#action'] = url('node/'. $node->nid.'/edit_reading'); 421 422 return drupal_get_form('meter_edit_reading', $form); 423 } 424 328 425 329 426 /** 330 427 * Export the meter readings as a CSV file 331 428 */ 332 function meter_csv_readings( &$node, $teaser = FALSE, $page = FALSE, $block = FALSE) {429 function meter_csv_readings() { 333 430 $nid = arg(1); 431 $node = node_load($nid); 334 432 $results = meter_get_values($node); 335 433 drupal_set_header('Content-Type: text/csv; charset=utf-8'); … … 339 437 print '"'.$row->time.'",'.$row->value."\n"; 340 438 } 341 342 439 } 343 440 … … 412 509 } 413 510 511 512 /** 513 * Draw a CSS/HTML graph 514 */ 414 515 function meter_graph($entries){ 415 516 if (count($entries) == 0)
Note: See TracChangeset
for help on using the changeset viewer.
