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

Diff of /contributions/modules/carbon/carbon_view.inc

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

revision 1.4 by johnackers, Tue Jan 6 22:19:26 2009 UTC revision 1.5 by johnackers, Sat Jan 10 15:46:14 2009 UTC
# Line 1  Line 1 
1  <?php  <?php
2  /*  /*
3   * $Id: carbon_view.inc,v 1.3 2009/01/06 17:40:49 johnackers Exp $   * $Id: carbon_view.inc,v 1.4 2009/01/06 22:19:26 johnackers Exp $
4   *   *
5   * Created on 19-Feb-2008   * Created on 19-Feb-2008
6   *   *
7   * Web 2.0 functions   * Web 2.0 functions
8   *   *
9   * Functions in this file create the consolidated account page   * Functions in this file create the consolidated account page which is
10     * intended to be the main page that the user interracts with.
11   *   *
12   * STILL IN DEVELOPMENT   * STILL IN DEVELOPMENT
13   */   */
14    
15  function carbon_view_consolidated($aid)  function carbon_view_consolidated($aid)
16  {  {
17    $path = carbon_include_core_js();  //  $path = carbon_include_core_js();
18    drupal_add_js($path . "/carbon_view.js", "module");  //  drupal_add_js($path . "/carbon_view.js", "module");
19    
20    $output = "" ;    $output = "" ;
21    
22    $output .= buildPeriodPanels($aid);    $output .= buildPeriodPanels($aid);
23    
24    $output .= carbon_add_panel("a load of transfers (account id wrong)", "/carbon5/?q=carbon/transfer/425");    $output .= carbon_add_panel("a load of transfers (account id wrong)", "?q=carbon/transfer/425");
25    
26    $output .= carbon_add_panel("Group sector report",    $output .= carbon_add_panel("Group sector report",
27      "/carbon5/?q=carbon/account&report=sector&firstdate=20061201&period=6&org=icrag");      "?q=carbon/report&report=sector&firstdate=20061201&period=6&org=icrag");
28    
29    
30  /*  /*
# Line 39  function carbon_view_consolidated($aid) Line 40  function carbon_view_consolidated($aid)
40                                   l("All purchases made",                                   l("All purchases made",
41                                     "",                                     "",
42                                     array("CLASS"=>"loadOnDemand", "ID"=>nextPanel()),                                     array("CLASS"=>"loadOnDemand", "ID"=>nextPanel()),
43                                     "q=carbon/transfer/" . $account_id));                                     "q=carbon/transfer/" . $aid));
44    
45      $output .= carbon_add_panel("All carbon stamps for this user", "?q=carbon/stamp/53");
46    
47      $output .= carbon_add_panel("Cash movements for this account", "?q=carbon/transfer/".$aid);
48    
49      $output .= carbon_add_panel("Carbon Purchases and Sales for all accounts", "?q=carbon/transfer");
50    
51    $output = carbon_add_debug_panel($output);    $output = carbon_add_debug_panel($output);
52    
53    return $output  ;    return $output  ;
# Line 62  function buildPeriodPanels($aid) Line 69  function buildPeriodPanels($aid)
69    
70          if (count($account->stamp) == 0)          if (count($account->stamp) == 0)
71      return carbon_calculate_empty_table($account);      return carbon_calculate_empty_table($account);
   
   $header = carbon_stamp_header();  
72    
73    // move the stamps retrieved for this footprint into an array    $stamps = $account->stamp ;
74      $header = carbon_stamp_header();
   $stamps = array();  
   
   foreach ($account->stamp as $stamp)    // add the stamps  
   {  
     $stamps[] = $stamp;  
   }  
75    
76    // find out the range of dates that we are dealing with    // find out the range of dates that we are dealing with
77    
# Line 84  function buildPeriodPanels($aid) Line 83  function buildPeriodPanels($aid)
83    
84    if (!empty($account->firstdate))    if (!empty($account->firstdate))
85    {    {
86      $y = _format_date($dateRange['first'], 'custom', 'Y') - 1 ;      $y = _format_date($dateRange['first'], 'custom', 'Y')  - 1;
87      $m = _format_date($account->firstdate, 'custom', 'm');      $m = _format_date($account->firstdate, 'custom', 'm');
88      $d = _format_date($account->firstdate, 'custom', 'd');      $d = _format_date($account->firstdate, 'custom', 'd');
89    }    }
# Line 99  function buildPeriodPanels($aid) Line 98  function buildPeriodPanels($aid)
98    // the purpose of the for loop is only to prevent    // the purpose of the for loop is only to prevent
99    // any software bug from printing numerous reports    // any software bug from printing numerous reports
100    
101    $annual_report = "" ;  
102    
103    for ($i = 0 ; $i < 10 ; $i++)    for ($i = 0 ; $i < 10 ; $i++)
104    {    {
# Line 113  function buildPeriodPanels($aid) Line 112  function buildPeriodPanels($aid)
112      $firstdate_s = CarbonDate::asYYYYMMDD($firstdayinyear);      $firstdate_s = CarbonDate::asYYYYMMDD($firstdayinyear);
113    
114    
115      $annual_report .= _format_date_range($firstdayinyear, $firstdayinnextyear)."&nbsp"      $annual_report = "" ;
116                       .l("view",  
117        $annual_report = l("View detailed footprint",
118                       "",                       "",
119                       array("CLASS"=>"loadOnDemand", "ID"=>nextPanel()),                       array("query"=>sprintf("q=carbon/%d/account&firstdate=%s&period=%d",
120                       $q = sprintf("q=carbon/account/%d&firstdate=%s&period=%d",                              $aid,$firstdate_s,$account->period),
121                       $aid, $firstdate_s, $account->period)) . "<br/>";                             "attributes"=>array("CLASS"=>"loadOnDemand", "ID"=>nextPanel()))
122                         ) . "<br/>" ;
123        $annual_report .= l("View group sector report",
124                         "",
125                         array("query"=>sprintf("q=carbon/report/&report=sector&firstdate=%s&period=%d&org=%s",
126                                $firstdate_s,$account->period,$account->organization),
127                               "attributes"=>array("CLASS"=>"loadOnDemand", "ID"=>nextPanel()))
128                           ) . "<br/>";
129        $annual_report .= l("View CRAG settlement report",
130                         "",
131                         array("query"=>sprintf("q=carbon/report/&report=crag&firstdate=%s&period=%d&org=%s",
132                                $firstdate_s,$account->period,$account->organization),
133                               "attributes"=>array("CLASS"=>"loadOnDemand", "ID"=>nextPanel()))
134                         ) . "<br/>";
135  /*  /*
136      $annual_report .= l(_format_date_range($firstdayinyear, $firstdayinnextyear),      $annual_report .= l(_format_date_range($firstdayinyear, $firstdayinnextyear),
137                       "",                       "",
# Line 126  function buildPeriodPanels($aid) Line 139  function buildPeriodPanels($aid)
139                       $q = sprintf("q=carbon/account/%d&firstdate=%s&period=%d",                       $q = sprintf("q=carbon/account/%d&firstdate=%s&period=%d",
140                       $aid, $firstdate_s, $account->period)) . "<br/>" ;                       $aid, $firstdate_s, $account->period)) . "<br/>" ;
141   */   */
142              $output .= carbon_wrapFieldset(
143              $account->name . " " .  _format_date_range($firstdayinyear, $firstdayinnextyear), "my tool tip", $annual_report);
144    
145    }    }
   $output .= carbon_wrapFieldset(  
   "Carbon statements for ".$account->title, "my tool tip", $annual_report);  
146    return $output ;    return $output ;
147  }  }
148    
149    /**
150     * work in progress
151     *
152     * @param $reportName
153     * @param $firstDate
154     * @param $period
155     * @param $chartType
156     * @return unknown_type
157     */
158    
159    function _create_report_query($legend, $reportName, $firstdate_s, $period, $chartType)
160    {
161            $q = sprintf("q=carbon/report/&report=%s&firstdate=%s&period=%d",
162                    $reportName,$aid,$firstdate_s,$account->period);
163      if (is_set($chartType))
164        $q .= "&render=".$chartType ;
165            return l($legend," ", array("query"=> $q,
166                                  "attributes"=>array("CLASS"=>"loadOnDemand", "ID"=>nextPanel())));
167    }
168    
169    
170    
171    
172  /**  /**
173   * Process a GET command to present a carbon footprint for a particular period.   * Process a GET command to present a carbon footprint for a particular period.
174   * Handle requests for datatype json.   * Handle requests for datatype json.
175   */   */
176    
177  function carbon_view_year($aid)  function carbon_view_footprint($aid)
178  {  {
179    global $charts ; //$charts = array(t("none"), t("bar"), t("pie"));    global $charts ; //$charts = array(t("none"), t("bar"), t("pie"));
180    
# Line 193  function carbon_view_year($aid) Line 229  function carbon_view_year($aid)
229  }  }
230    
231    
232    function carbon_view_stamp($aid, $verb)
233    {
234      $meterPage = $verb == "meter" ? true : false ;
235      $header = $verb == "meter" ? $header_meter : $header_travel ;
236    
237      $sql = carbon_stamp_query($aid, $uid, $meterPage);
238     // $sql .= tablesort_sql($header);
239    
240      // get the links (no range limit here)
241      $queryResult = db_query($sql);
242    
243      $stamps = array();
244      $title = array();
245      while ($node = db_fetch_object($queryResult))
246      {
247    
248            $node->protection = _log2($node->protect2);
249        $ro_access = carbon_access("view", $node);
250        if ($ro_access)
251        {
252          $stamps[$node->enddate] = $node ;   ksort($stamps);
253          $titles[] = $node->title ;
254        }
255      }
256    //krsort($stamps);  // put meter readings in reverse order
257    
258      return $meterPage ? _meter_create_table($stamps, $titles) : _stamp_create_table($stamps);
259    }
260    
261    
262    function _meter_create_table($stamps, $titles)
263    {
264            $output = '' ;
265      $header = array(
266        array("data" => t("date"),      "field" => "enddate"),
267        array("data" => t("code"),      "field" => "code"),
268        array("data" => t("reading"),   "field" => "reading"),
269        array("data" => t("adjust"),"field" => "adjustment"),
270        array("data" => t("status"),    "field" => "status"),
271        array("data" => t("operations"))
272      );
273      $unique_title = array_unique($titles);  // establish the meter names
274      // for each unique meter name
275      foreach ($unique_title as $title)
276      {
277                    $rows = array();
278              $output .= "<h2>" . $title . "</h2>";
279              foreach ($stamps as $stamp)
280              {
281                if ($stamp->title != $title)
282                  continue ;
283                $rows[] = array(_format_date($stamp->enddate,"small"), $stamp->code, $stamp->reading,
284                                              $stamp->adjustment,
285                                        $stamp->status >= 1 ? 'pub' : '',
286                                        $stamp->protection . " " . carbon_format_edit_ops($stamp, null));
287              }
288              $output .= theme("table", $header, $rows);
289      }
290      return $output ;
291    }
292    
293    
294    function _stamp_create_table($stamps)
295    {
296      $header = array(
297        array("data" => t("title"),   "field" => "title"),
298        array("data" => t("start"),   "field" => "startdate"),
299        array("data" => t("end"),     "field" => "enddate"),
300        array("data" => t("code"),    "field" => "code"),
301        array("data" => t("amount"),  "field" => "reading"),
302        array("data" => t("adjust"),  "field" => "adjustment"),
303        array("data" => t("status"),  "field" => "status"),
304        array("data" => t("operations"))
305      );
306      $rows = array();
307      $output .= "<h2>" . $title . "</h2>";
308      foreach ($stamps as $stamp)
309      {
310        $rows[] = array($stamp->title, _format_date($stamp->startdate,"small"),
311                                       _format_date($stamp->enddate,"small"),
312                                        $stamp->code, $stamp->reading, $stamp->adjustment,
313                                        $stamp->status >= 1 ? 'pub' : '',
314                                        $stamp->protection . " " . carbon_format_edit_ops($stamp, null));
315      }
316      return $output .= theme("table", $header, $rows);
317    }
318    
319  /**  /**
320   * allocate unique name to each panel on the page.   * allocate unique name to each panel on the page.
321   *   *
# Line 223  function carbon_wrapFieldset($title, $ti Line 346  function carbon_wrapFieldset($title, $ti
346           '</FIELDSET>' ;           '</FIELDSET>' ;
347  }  }
348    
349    /**
350     * Generate HTML for a whole panel which can be loaded with data on demand.
351     * The l() function cannot generate a whole fieldset so might as well do
352     * the whole thing here.
353     *
354     * @param $title
355     * @param $url
356     * @return unknown_type
357     */
358    
359    
360  function carbon_add_panel($title, $url)  function carbon_add_panel($title, $url)
# Line 233  function carbon_add_panel($title, $url) Line 365  function carbon_add_panel($title, $url)
365    
366    $output =    $output =
367    '<FIELDSET>'.    '<FIELDSET>'.
368      '  <LEGEND TITLE="tool tip here">'.
369      '  <A CLASS="loadOnDemand" ID="' . $panelName . '" HREF="' . $url .'">' . $title . '</A>'.
370      '  </LEGEND>'.
371      '</FIELDSET>' ;
372    
373      return $output ;
374    }
375    
376    
377    function carbon_add_panel_old($title, $url)
378    {
379      global $panel ;
380      $panel = isSet($panel) ? $panel+1 : 0 ;
381      $panelName = "panel-" . $panel ;  // allocate a unique name to each panel
382    
383      $output =
384      '<FIELDSET>'.
385    '  <LEGEND TITLE="tool tip here">Legend goes here</LEGEND>'.    '  <LEGEND TITLE="tool tip here">Legend goes here</LEGEND>'.
386    '  <A CLASS="loadOnDemand" ID="' . $panelName . '" HREF="' . $url .'">' . $title . '</A>'.    '  <A CLASS="loadOnDemand" ID="' . $panelName . '" HREF="' . $url .'">' . $title . '</A>'.
387    '</FIELDSET>' ;    '</FIELDSET>' ;
# Line 242  function carbon_add_panel($title, $url) Line 391  function carbon_add_panel($title, $url)
391    
392    
393    
394    
395    
396    
397  function carbon_include_core_js()  function carbon_include_core_js()
398  {  {
399    // load the common javascript routines    // load the common javascript routines
# Line 263  function carbon_add_debug_panel($output) Line 415  function carbon_add_debug_panel($output)
415  }  }
416    
417    
 class CarbonDate  
 {  
         function fromYYYYMMDD($s) // static removed  
         {  
     return mktime(0, 0, 0, substr($s,4,2), substr($s,6,2), substr($s,0,4));  
         }  
   
   function asYYYYMMDD($time) // static removed  
   {  
     $y = _format_date($time, 'custom', 'Y');  
     $m = _format_date($time, 'custom', 'm');  
     $d = _format_date($time, 'custom', 'd');  
     return sprintf("%04d%02d%02d", $y, $m, $d);  
   }  
 }  
   
418    
419  ?>  ?>

Legend:
Removed from v.1.4  
changed lines
  Added in v.1.5

  ViewVC Help
Powered by ViewVC 1.1.3