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

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

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

revision 1.21 by johnackers, Tue Jan 6 22:19:26 2009 UTC revision 1.22 by johnackers, Sat Jan 10 15:46:14 2009 UTC
# Line 1  Line 1 
1  <?php  <?php
2  /**  /**
3   * $Id: carbon_stamp.inc,v 1.20 2009/01/06 17:37:54 johnackers Exp $   * $Id: carbon_stamp.inc,v 1.21 2009/01/06 22:19:26 johnackers Exp $
4   *   *
5   * Drupal carbon stamp module.   * Drupal carbon stamp module.
6   *   *
# Line 29  function carbon_stamp_access($op, $node) Line 29  function carbon_stamp_access($op, $node)
29   */   */
30    
31    
32  function carbon_stamp_page($uid) {  function carbon_stamp_page($aid, $uid, $meterPage) {
33    global $user;    global $user;
34    
35    $header = array(    $header = array(
36      array("data" => t("title"),   "field" => "title"),      array("data" => t("title"),   "field" => "title"),
37      array("data" => t("start"),   "field" => "startdate"),      array("data" => t("start"),   "field" => "startdate"),
# Line 46  function carbon_stamp_page($uid) { Line 46  function carbon_stamp_page($uid) {
46    if (empty($uid))    if (empty($uid))
47      $header[] = array("data" => t("author"),"field" => "name");      $header[] = array("data" => t("author"),"field" => "name");
48    
49    $sql = "SELECT  t.*, n.title, n.nid, n.status, n.uid, n.type, name, count(*) as numfoot, " .    $sql = carbon_stamp_query($aid, $uid, $meterPage);
50           "BIT_OR(POWER(2,a.protection)) as protect2, j.sid " .  
                    "FROM {carbon_stamp} t " .  
          "INNER JOIN {node} n                   ON t.nid = n.nid " .  
          "INNER JOIN {users} u                  ON n.uid = u.uid " .  
          "LEFT  JOIN {carbon_stamp_account} j   ON t.nid = j.sid " .  
          "LEFT  JOIN {carbon_account} a         ON j.fid = a.nid " .  
          ((empty($uid) ? '' : " where n.uid = ".$uid. " ") .  
          "GROUP BY t.nid ");  
   
51    $sql .= tablesort_sql($header);    $sql .= tablesort_sql($header);
52    
53    // get the links (no range limit here)    // get the links (no range limit here)
54    $queryResult = db_query($sql);    $queryResult = db_query($sql);
55    
56          $sampleRecord = null ;    $sampleRecord = null ;
57    while ($node = db_fetch_object($queryResult))    while ($node = db_fetch_object($queryResult))
58    {    {
59      $node->protection = _log2($node->protect2);      $node->protection = _log2($node->protect2);
# Line 69  function carbon_stamp_page($uid) { Line 61  function carbon_stamp_page($uid) {
61      if ($ro_access)      if ($ro_access)
62      {      {
63        $row =  array(carbon_link_from_title($node, $node),        $row =  array(carbon_link_from_title($node, $node),
64                                  $node->startdate == 0 ? '' : _format_date($node->startdate, "small"),          $node->startdate == 0 ? '' : _format_date($node->startdate, "small"),
65                                  _format_date($node->enddate,"small"),          _format_date($node->enddate,"small"),
66                                  $node->code,          $node->code,
67                                  $node->reading.' '._get_scope_key($node->scope),          $node->reading.' '._get_scope_key($node->scope),
68                                  $node->numfoot <= 1 ? (isset($node->sid) ? 1 : 0) : $node->numfoot,          $node->numfoot <= 1 ? (isset($node->sid) ? 1 : 0) : $node->numfoot,
69                                  $node->status >= 1 ? 'pub' : '',          $node->status >= 1 ? 'pub' : '',
70          $node->protection . " " . carbon_format_edit_ops($node, null));          $node->protection . " " . carbon_format_edit_ops($node, null));
71    
72        if (empty($uid))        if (empty($uid))
# Line 82  function carbon_stamp_page($uid) { Line 74  function carbon_stamp_page($uid) {
74        $rows[] = $row ;        $rows[] = $row ;
75      }      }
76      $sampleRecord = $node ;      $sampleRecord = $node ;
77    }    }
78    
79    $output = theme("table", $header, $rows);    $output = theme("table", $header, $rows);
80    $output .= theme("pager", NULL, 10, 0);    $output .= theme("pager", NULL, 10, 0);
81    
82      $format = $_GET["datatype"];
83      if ($format == 'json')
84      {
85         // create a new instance of Services_JSON
86        require_once(CARBON_PATH .'/json.php');
87        $json = new Services_JSON();
88    
89        $output = $json->encode($output);
90        print($output);
91        exit(0);
92      }
93    
94    $title = t("Carbon Stamps");    $title = t("Carbon Stamps");
95    
96    if (!empty($uid))    if (!empty($uid))
# Line 99  function carbon_stamp_page($uid) { Line 104  function carbon_stamp_page($uid) {
104      $output .= theme_links($links);    // format links      $output .= theme_links($links);    // format links
105    }    }
106    return $output;    return $output;
107    }
108    
109    
110    function carbon_stamp_query($aid, $uid, $meterPage)
111    {
112      $sql = "SELECT  t.*, n.title, n.nid, n.status, n.uid, n.type, name, count(*) as numfoot, " .
113             "BIT_OR(POWER(2,a.protection)) as protect2, j.sid " .
114             "FROM {carbon_stamp} t " .
115             "INNER JOIN {node} n                   ON t.nid = n.nid " .
116             "INNER JOIN {users} u                  ON n.uid = u.uid " .
117             "LEFT  JOIN {carbon_stamp_account} j   ON t.nid = j.sid " .
118             "LEFT  JOIN {carbon_account} a         ON j.fid = a.nid " .
119             "WHERE TRUE " .
120             (empty($aid) ?   '' : " AND a.nid   = ".$aid.   " ") .
121             (empty($uid) ?   '' : " AND n.uid   = ".$uid.   " ") .
122             (empty($meterPage) ? '' : " AND t.scope". ($meterPage ? "=1 " : "!=1 ")) .
123             "GROUP BY t.nid ";
124    
125      return $sql ;
126  }  }
127    
128    
129  function _log2($protect2)  function _log2($protect2)
130  {  {
131          $k = 0 ;          $k = 0 ;

Legend:
Removed from v.1.21  
changed lines
  Added in v.1.22

  ViewVC Help
Powered by ViewVC 1.1.3