Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
logs.inc
1 <?php
17 require_once SQ_LIB_PATH.'/html_form/html_form.inc';
18 require_once SQ_FUDGE_PATH.'/datetime_field/datetime_field.inc';
19 
41 function paintLogs(&$owner, &$o, &$ei, $keywords=NULL)
42 {
43  // prefix for all the form vars
44  $prefix = $owner->getPrefix();
45  $invalid_dates = TRUE;
46 
47  $log_types = include SQ_DATA_PATH.'/private/system/core/internal_message_types.inc';
48 
49  // if it is in limbo mode there will be already an element with sq_backend_log_type id
50  // therefore we use differnet name for the combo box in limbo mode
51  if (SQ_IN_LIMBO) {
52  $_combo_box_name = 'sq_backend_log_type2';
53  } else {
54  $_combo_box_name = 'sq_backend_log_type';
55  }
56 
57  if (isset($_REQUEST[$_combo_box_name])) {
58  $active_log_types = $_REQUEST[$_combo_box_name];
59  } else {
60  $active_log_types = (!empty($log_types) && isset($log_types[0])) ? Array($log_types[0]) : Array();
61  }
62 
63  // Make sure it's an array - in case the user has clicked a link that's setting
64  // the log type to a particular value.
65  if (!is_array($active_log_types)) {
66  $active_log_types = array($active_log_types);
67  }
68 
69  $selected_key = NULL;
70  $selected_based_url = '';
71  $selected_types = Array();
72  $o->openSection(translate('logged_messages'));
73 
74  $type_options = Array();
75  foreach ($log_types as $type) {
76  // We're only interested in log types starting with 'asset'
77  if (strpos($type, 'asset') !== 0) {
78  continue;
79  }
80 
81  // html option fields contains complete url to call via javascript self.location
82  if (in_array($type, $active_log_types)) {
83  $selected_types[] = $type;
84  }
85  $type_options[$type] = ucwords(str_replace(Array('.', '_'), ' ', $type));
86  }
87  $date = date('Y-m-d H:s:i', time());
88  $date = '';
89  $date_parameters = Array(
90  'min' => '1990-01-01 00:00:00',
91  'max' => '2030-12-31 23:59:59',
92  'allow_circa' => '0',
93  'show' => Array('y', 'm', 'd', 'h', 'i', 's'),
94  'null' => Array(),
95  'style' => Array(
96  'y' => 's',
97  'm' => 's',
98  'd' => 's',
99  'h' => 's',
100  'i' => 's',
101  's' => 's',
102  ),
103  );
104 
105  // get 2 date fields for to and from fields
106  $from_field = new DateTime_Field($prefix.'_date_from', $date, $date_parameters);
107  $to_field = new DateTime_Field($prefix.'_date_to', $date, $date_parameters);
108 
109  $from_date = $to_date = '';
110 
111  // get the values from the date fields but if they are left to default date then
112  // dont add the to and from dates to the query user prolly wants ALL the logs
113  if ($from_field->processField() && $from_field->value != '1990-01-01 00:00:00') {
114  $from_date = $from_field->value;
115  }
116  // this will look stupid but this is needed
117  // or else on screen reload both the date
118  // fields will have the same date on them
119  $from_field->setValue($from_date);
120 
121  if ($to_field->processField() && $to_field->value != '1990-01-01 00:00:00') {
122  $to_date = $to_field->value;
123  }
124  $to_field->setValue($to_date);
125 
126 
127  if (!( empty($type_options) && empty($selected_types) )) {
128 
129  $o->openField(translate('log_type'));
130 
131  combo_box($_combo_box_name, $type_options, TRUE, $selected_types, 10);
132  echo '&nbsp;';
133 
134 
135  $o->closeField();
136 
137  $o->openField(translate('from'));
138  $from_field->printField();
139  $o->closeField();
140 
141  $o->openField(translate('to'));
142  $to_field->printField();
143  echo "<br>";
144  // okie dont let the user confuse you with wrong dates
145  if (isset($from_date) && isset($to_date) && $from_date > $to_date) {
146  echo "<font color=\"red\"><b>ERROR : 'From' date provided is later than 'To' date. </b></font><br>";
147  $invalid_dates = FALSE;
148  }
149  normal_button($prefix.'_go', translate('view'), 'this.form.submit()');
150  $o->closeField();
151  }
152 
153 
154  $ms = $GLOBALS['SQ_SYSTEM']->getMessagingService();
155 
156  $all_logs = Array();
157  foreach($selected_types as $active_log_type) {
158 
159  if (strpos($active_log_type, 'asset.linking') === 0) {
160 
161  $minor_logs = $ms->getLogs($active_log_type, Array('minorid' => $owner->id, 'from_date' => $from_date, 'to_date' => $to_date));
162  $major_logs = $ms->getLogs($active_log_type, Array('majorid' => $owner->id, 'from_date' => $from_date, 'to_date' => $to_date));
163  $logs = array_merge($minor_logs, $major_logs);
164 
165  } else if (strpos($active_log_type, 'asset.workflow') === 0) {
166 
167  // for workflow we want to show the user log messages as well
168  if (isset($_REQUEST['sq_workflow_log_version'])) {
169  $o->addFormActionGetVar('sq_workflow_log_version', $_REQUEST['sq_workflow_log_version']);
170  $logs = $ms->getLogs($active_log_type, Array(
171  'assetid' => $owner->id,
172  'version' => $_REQUEST['sq_workflow_log_version'],
173  'from_date' => $from_date,
174  'to_date' => $to_date,
175  )
176  );
177  $user_logs = $ms->getLogs($active_log_type.'.userlog', Array(
178  'assetid' => $owner->id,
179  'version' => $_REQUEST['sq_workflow_log_version'],
180  'from_date' => $from_date,
181  'to_date' => $to_date,
182  )
183  );
184  } else {
185  $logs = $ms->getLogs($active_log_type, Array('assetid' => $owner->id, 'from_date' => $from_date, 'to_date' => $to_date));
186  $user_logs = $ms->getLogs($active_log_type.'.userlog', Array('assetid' => $owner->id, 'from_date' => $from_date, 'to_date' => $to_date));
187  }
188 
189  $logs = array_merge($logs, $user_logs);
190 
191  } else {
192 
193  $logs = $ms->getLogs($active_log_type, Array('assetid' => $owner->id, 'from_date' => $from_date, 'to_date' => $to_date));
194 
195  }//end if ($active_log_type)
196 
197  $all_logs = array_merge($all_logs, $logs);
198  }//end foreach ($active_log_types)
199 
200  // Sort the logs
201  usort($all_logs, Array('Messaging_Service', 'sortMessages'));
202 
203  if (!empty($selected_types)) {
204  $selected_base_url = replace_query_string_vars(Array($_combo_box_name.'[]' => NULL, $owner->type().'_'.$owner->id.'_start_at' => NULL,));
205  $selected_base_url .= '&'.$_combo_box_name.'[]='.implode('&'.$_combo_box_name.'[]=', $selected_types);
206  }
207 
208  // if non of the logs are selected or if the dates
209  // were nto right dont display any logs for now
210  if (empty($all_logs) || !$invalid_dates) {
211  $o->openRaw();
212  if (!( empty($type_options) && empty($selected_base_url) )) {
213  echo '<b>'.translate('no_logged_messages', htmlspecialchars($owner->name, ENT_COMPAT, SQ_CONF_DEFAULT_CHARACTER_SET)).'</b>';
214  } else {
215  echo '<b>'.translate('no_logged_messages_found', htmlspecialchars($owner->name, ENT_COMPAT, SQ_CONF_DEFAULT_CHARACTER_SET)).'</b>';
216  }
217  $o->closeRaw();
218  } else {
219  $o->openRaw();
220  $lm = $GLOBALS['SQ_SYSTEM']->lm;
221  ?>
222  <table class="sq-backend-table">
223  <tr>
224  <td class="sq-backend-table-header" nowrap width="120"><?php echo translate('log_time'); ?></td>
225  <td class="sq-backend-table-header" nowrap width="120"><?php echo translate('logged_by'); ?></td>
226  <td class="sq-backend-table-header" width="100%"><?php echo translate('message'); ?></td>
227  </tr>
228  <?php
229  $num_printed = 0;
230  $num_per_page = 10;
231  $num_logs = count($all_logs);
232  $start_printing_at = 0;
233  if (isset($_REQUEST[$prefix.'_start_at'])) {
234  $start_printing_at = (int) $_REQUEST[$prefix.'_start_at'];
235  }
236  for ($i = $start_printing_at; $i < $num_logs; $i++) {
237  $log_data = $all_logs[$i];
238 
239  ?>
240  <tr>
241  <td class="sq-backend-table-cell" nowrap><?php echo ts_iso8601($log_data['sent']); ?></td>
242  <td class="sq-backend-table-cell" nowrap><?php echo $log_data['from_name']; ?></td>
243  <td class="sq-backend-table-cell" width="100%"><b><?php echo $log_data['subject']; ?></b><br/><?php echo nl2br(htmlentities($log_data['body'])); ?></td>
244  </tr>
245  <?php
246  $num_printed++;
247  if ($num_printed >= $num_per_page) break;
248  }
249  ?>
250  <tr>
251  <td colspan="3" align="center" class="sq-backend-table-header">
252  <?php
253 
254  if ($start_printing_at > 0) {
255  ?>
256 
257  <?php $next_url = $selected_base_url.'&'.$prefix.'_start_at='.($start_printing_at - $num_per_page); ?>
258  <a style="text-decoration: none;" href="<?php echo (htmlspecialchars($next_url)); ?>">
259  <?php
260 
261  } else {
262  ?><span style="color: #84848F"><?php
263  }
264  ?>
265  &lt;&lt; <?php echo translate('previous_page');
266 
267  if ($start_printing_at > 0) {
268  echo '</a>';
269  } else {
270  echo '</span>';
271  }
272  ?>
273  &nbsp;<b><?php echo translate('page_number', (floor($start_printing_at / $num_per_page) + 1), ceil($num_logs / $num_per_page)); ?></b>&nbsp;
274 
275  <?php
276  if (($start_printing_at + $num_per_page) < $num_logs) {
277  ?>
278 
279  <?php $next_url = $selected_base_url.'&'.$prefix.'_start_at='.($start_printing_at + $num_per_page); ?>
280  <a style="text-decoration: none;" href="<?php echo (htmlspecialchars($next_url)); ?>">
281  <?php
282 
283  } else {
284  ?><span style="color: #84848F"><?php
285  }
286 
287  echo translate('next_page'); ?> &gt;&gt;
288  <?php
289  if (($start_printing_at + $num_per_page) < $num_logs) {
290  echo '</a>';
291  } else {
292  echo '</span>';
293  }
294  ?>
295  </td>
296  </tr>
297  </table>
298  <?php
299  $o->closeRaw();
300  }//end else
301 
302 
303  $o->closeSection();
304 
305  return FALSE;
306 
307 }//end paintLogs()
308 
309 
320 function processLogs(&$owner, &$o, &$ei)
321 {
322  return TRUE;
323 
324 }//end processLogs()
325 
326 
327 ?>