Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
inbox.inc
1 <?php
18 require_once SQ_INCLUDE_PATH.'/asset.inc';
19 
31 class Inbox extends Asset
32 {
33 
34 
41  function Inbox($assetid=0)
42  {
43  $this->Asset($assetid);
44 
45  }//end constructor
46 
47 
54  function lockTypes()
55  {
56  $lock_types = parent::lockTypes();
57  $lock_types['mail'] = max($lock_types) * 2;
58  return $lock_types;
59 
60  }//end lockTypes()
61 
62 
69  function _getUser()
70  {
71  $user = NULL;
72 
73  $link = $GLOBALS['SQ_SYSTEM']->am->getLink($this->id, SQ_LINK_TYPE_2, 'user', FALSE, '', 'minor', '1');
74  if (!empty($link)) {
75  $user = $GLOBALS['SQ_SYSTEM']->am->getAsset($link['majorid'], $link['major_type_code']);
76  }
77 
78  return $user;
79 
80  }//end _getUser()
81 
82 
89  function canDelete()
90  {
91  return FALSE;
92 
93  }//end canDelete()
94 
95 
107  function _checkPermissionAccess($perm, $assetids=Array())
108  {
109  $user = $this->_getUser();
110  if (is_null($user)) {
111  return parent::_checkPermissionAccess($perm, $assetids);
112  }
113 
114  return $user->_checkPermissionAccess($perm, $assetids);
115 
116  }//end _checkPermissionAccess()
117 
118 
126  function printFrontend()
127  {
128  if (!$this->readAccess()) {
129  $GLOBALS['SQ_SYSTEM']->paintLogin(translate('login'), translate('cannot_access_asset', $this->name));
130  return;
131  }
132 
133  $this->printBody();
134 
135  }//end printFrontend()
136 
137 
147  function paintBackend($o)
148  {
149  if (isset($_REQUEST['gettrash'])) {
150  $user = $this->_getUser();
151 
152  $ms = $GLOBALS['SQ_SYSTEM']->getMessagingService();
153  $messages = $ms->getMessages($user->id, NULL, Array(SQ_MSG_DELETED), Array(), NULL, NULL, 'name');
154  echo '<root>';
155  foreach ($messages as $key => $message) {
156  echo '<message from="'.$message['from_name'].'" id="'.$message['msgid'].'" date="'.$GLOBALS['SQ_SYSTEM']->datetime($message['sent']).'"';
157  echo ' subject="'.$message['subject'].'">'.$message['body'].'</message>';
158  }
159  echo '</root>';
160  exit();
161  }
162 
163  parent::paintBackend($o);
164 
165  }//end paintBackend()
166 
167 
174  function printBody()
175  {
176  $edit = $this->getEditFns();
177  if (isset($_REQUEST['msgid'])) {
178  // they want to print a single message
179  $edit->paintMessage($_REQUEST['msgid']);
180  } else {
181  // they want to print all mail
182  if (!SQ_IN_BACKEND) {
183  $GLOBALS['SQ_SYSTEM']->am->acquireLock($this->id, 'mail');
184  $user = $this->_getUser();
185  ?>
186  <script type="text/javascript" src="<?php echo sq_web_path('lib'); ?>/js/general.js"></script>
187  <script type="text/javascript" src="<?php echo sq_web_path('lib'); ?>/html_form/html_form.js"></script>
188  <h2 style="margin-bottom: 2px">Inbox for <?php echo $user->attr('first_name').' '.$user->attr('last_name'); ?></h2>
189  <form method="POST" action="<?php echo htmlentities($_SERVER['REQUEST_URI'], ENT_COMPAT, SQ_CONF_DEFAULT_CHARACTER_SET); ?>" name="main_form" id="main_form">
190  <?php
191  }
192 
193  $null = '';
194  $edit->paintInbox($this, $null, 'inbox');
195 
196  if (!SQ_IN_BACKEND) {
197  ?>
198  </form>
199  <?php
200  }
201  }
202 
203  }//end printBody()
204 
205 
215  function _getName($short_name=FALSE)
216  {
217  return 'Inbox';
218 
219  }//end _getName()
220 
221 
230  public function attr($name)
231  {
232  if ($name == 'name') {
233  return $this->_getName();
234  } else {
235  return parent::attr($name);
236  }//end if
237 
238  }//end attr()
239 
240 
241 }//end class
242 
243 ?>