Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
history.inc
1 <?php
17 require_once SQ_LIB_PATH.'/html_form/html_form.inc';
18 
40 function paintHistory(&$owner, &$o, &$ei, $keywords=NULL)
41 {
42  $write_access = $owner->writeAccess('');
43 
44  // prefix for all the form vars
45  $prefix = $owner->getPrefix();
46 
47  $db =& $GLOBALS['SQ_SYSTEM']->db;
48 
49  // note that we dont prep this query for rollback select
50  // because we are selecting directly from the rollback table
51  $sql = 'SELECT sq_rb_ast.sq_eff_from as efrom, sq_rb_ast.sq_eff_to as eto, sq_rb_ast.version, sq_ast.name as updated_username, sq_rb_ast.updated_userid as updated_userid
52  FROM
53  sq_rb_ast
54 
55  LEFT JOIN sq_ast ON sq_rb_ast.updated_userid = sq_ast.assetid
56  WHERE
57  (
58  sq_rb_ast.assetid = (:assetid)
59  )
60 
61  ORDER BY sq_rb_ast.sq_eff_from DESC
62  ';
63 
64  try {
65  $assetid = $owner->id;
66  $query = MatrixDAL::preparePdoQuery($sql);
67  MatrixDAL::bindValueToPdo($query, 'assetid', $assetid);
68  $result = MatrixDAL::executePdoAll($query);
69  } catch (Exception $e) {
70  throw new Exception('Failed to get asset history due to database error: '.$e->getMessage());
71  }
72 
73  $o->openSection(translate('version_history'));
74  $o->openRaw();
75 
76  if (SQ_ROLLBACK_VIEW) {
77  ?><p class="sq-backend-data"><b><i><?php echo translate('history_viewed_row', htmlspecialchars($owner->name, ENT_COMPAT, SQ_CONF_DEFAULT_CHARACTER_SET)); ?></i></b></p>
78  <?php
79  }
80 
81  hidden_field($prefix.'_rollback_version', '0');
82 
83  ?>
84  <table class="sq-backend-table">
85  <tr>
86  <td class="sq-backend-table-header"><?php echo translate('version_duration'); ?></td>
87  <td class="sq-backend-table-header"><?php echo translate('time_since_version'); ?></td>
88  <td class="sq-backend-table-header" align="center"><?php echo translate('updated_user'); ?></td>
89  <td class="sq-backend-table-header" align="center"><?php echo translate('version'); ?></td>
90  <?php
91  if ($write_access) {
92  ?>
93  <td class="sq-backend-table-header" align="center"><?php echo translate('view'); ?></td>
94  <?php
95  }
96  ?>
97  </tr>
98 
99  <?php
100  foreach ($result as $data) {
101  $from = $data['efrom'];
102  $to = $data['eto'];
103  $updated_username = $data['updated_username'];
104  $updated_userid = $data['updated_userid'];
105 
106  $class = 'sq-backend-table-cell';
107  $show_view_btn = TRUE;
108  if (SQ_ROLLBACK_VIEW) {
109  $rollback_from = strtotime($_SESSION['sq_rollback_view']['rollback_time']);
110  if ($rollback_from >= strtotime($from) && (empty($to) || strtotime($to) > $rollback_from)) {
111  $class .= '-alt';
112  $show_view_btn = FALSE;
113  }
114  }
115 
116  if (empty($to)) {
117  $to = translate('present');
118  $ago = translate('most_recent');
119  $show_view_btn = FALSE;
120  } else {
121  require_once SQ_FUDGE_PATH.'/general/datetime.inc';
122  $ago = easy_time_total(time() - strtotime($from), TRUE);
123  list($fd, $ft) = explode(' ', $from);
124  list($td, $tt) = explode(' ', $to);
125  if ($fd == $td) {
126  $to = $tt;
127  } else {
128  $to = date('d/m/Y H:i:s', strtotime($to));
129  }
130  }
131 
132  ?>
133  <tr>
134  <td class="<?php echo $class; ?>"><?php echo date('d/m/Y H:i:s', strtotime($from)); ?> - <?php echo $to; ?></td>
135  <td class="<?php echo $class; ?>"><?php echo $ago; ?></td>
136  <td class="<?php echo $class; ?>"><?php echo empty($updated_username) ? $updated_userid : $updated_username; ?></td>
137  <td class="<?php echo $class; ?>" align="center"><?php echo $data['version']; ?></td>
138 
139  <?php
140  if ($write_access) {
141  ?>
142  <td class="<?php echo $class; ?>" align="center">
143  <?php
144  if ($show_view_btn) {
145  echo submit_button($prefix.'_rollback_mode', translate('view'), 'this.form.'.$prefix.'_rollback_version.value = \''.$data['version'].'\'');
146  } else {
147  echo '&nbsp;';
148  }
149  ?>
150  </td>
151  <?php
152  }
153  ?>
154  </tr>
155  <?php
156  }//end foreach
157  ?>
158  </table>
159  <?php
160  $o->closeRaw();
161  $o->closeSection();
162 
163  return FALSE;
164 
165 }//end paintHistory()
166 
167 
180 function processHistory(&$owner, &$o, &$ei)
181 {
182  // prefix for all the form vars
183  $prefix = $owner->getPrefix();
184 
185  if (isset($_POST[$prefix.'_rollback_mode']) && isset($_POST[$prefix.'_rollback_version'])) {
186  $version = $_POST[$prefix.'_rollback_version'];
187  $url = $_SERVER['PHP_SELF'].'?SQ_ACTION=rollback_view_start&assetid='.$owner->id.'&version='.$version;
188  $o->setRedirect($url, 'top');
189  }
190 
191  return TRUE;
192 
193 }//end processHistory()
194 
195 
196 ?>