1<?php 2 3// Generated e107 Plugin Admin Area 4 5require_once('../../class2.php'); 6if (!getperms('P')) 7{ 8 e107::redirect('admin'); 9 exit; 10} 11 12e107::lan('pm',true); 13// e107::css('inline', "div.tab-content { margin-top:10px } "); 14 15class pm_admin extends e_admin_dispatcher 16{ 17 18 protected $modes = array( 19 20 'main' => array( 21 'controller' => 'private_msg_ui', 22 'path' => null, 23 'ui' => 'private_msg_form_ui', 24 'uipath' => null 25 ), 26 'inbox' => array( 27 'controller' => 'private_msg_ui', 28 'path' => null, 29 'ui' => 'private_msg_form_ui', 30 'uipath' => null 31 ), 32 'outbox' => array( 33 'controller' => 'private_msg_ui', 34 'path' => null, 35 'ui' => 'private_msg_form_ui', 36 'uipath' => null 37 ), 38 39 /* 40 'block' => array( 41 'controller' => 'private_msg_block_ui', 42 'path' => null, 43 'ui' => 'private_msg_block_form_ui', 44 'uipath' => null 45 ), 46 */ 47 ); 48 49 50 protected $adminMenu = array( 51 52 'main/prefs' => array('caption'=> LAN_PREFS, 'perm' => 'P'), 53 'main/limits' => array('caption'=> ADLAN_PM_55, 'perm' => 'P'), 54 'main/maint' => array('caption'=> ADLAN_PM_59, 'perm' => 'P'), 55 56 57 'main/null' => array('divider'=> true), 58 'inbox/list' => array('caption'=> LAN_PLUGIN_PM_INBOX, 'perm' => 'P'), 59 'outbox/list' => array('caption'=> LAN_PLUGIN_PM_OUTBOX, 'perm' => 'P'), 60 'outbox/create' => array('caption'=> LAN_PLUGIN_PM_NEW, 'perm' => 'P'), 61 62 // 'block/list' => array('caption'=> LAN_MANAGE, 'perm' => 'P'), 63 // 'block/create' => array('caption'=> LAN_CREATE, 'perm' => 'P'), 64 65 66 67 68 69 ); 70 71 protected $adminMenuAliases = array( 72 'main/edit' => 'main/list' 73 ); 74 75 protected $menuTitle = LAN_PLUGIN_PM_NAME; 76 77 function init() 78 { 79 80 if(e_DEBUG == true) 81 { 82 $this->adminMenu['main/null2'] = array('divider'=> true); 83 $this->adminMenu['main/list'] = array('caption'=> "Log", 'perm' => 'P'); 84 } 85 86 } 87} 88 89 90 91 92 93class private_msg_ui extends e_admin_ui 94{ 95 96 protected $pluginTitle = LAN_PLUGIN_PM_NAME; 97 protected $pluginName = 'pm'; 98 protected $table = 'private_msg'; 99 protected $pid = 'pm_id'; 100 protected $perPage = 7; 101 protected $listQry = ''; 102 protected $listOrder = "p.pm_id DESC"; 103 104 protected $fields = array ( 'checkboxes' => array ( 'title' => '', 'type' => null, 'data' => null, 'width' => '5%', 'thclass' => 'center', 'forced' => '1', 'class' => 'center', 'toggle' => 'e-multiselect', ), 105 'pm_id' => array ( 'title' => LAN_ID, 'data' => 'int', 'width' => '5%', 'help' => '', 'readParms' => '', 'writeParms' => '', 'class' => 'left', 'thclass' => 'left', ), 106 'pm_from' => array ( 'title' => LAN_PLUGIN_PM_FROM, 'type' => 'method', 'noedit'=>true, 'data' => 'int', 'filter'=>true, 'width' => '5%%', 'help' => '', 'readParms' => '', 'writeParms' => '', 'class' => 'left', 'thclass' => 'left', ), 107 'pm_to' => array ( 'title' => LAN_PLUGIN_PM_TO, 'type' => 'user', 'data' => 'int', 'width' => '5%', 'help' => '', 'readParms' => '', 'writeParms' => '', 'class' => 'left', 'thclass' => 'left', ), 108 'pm_sent' => array ( 'title' => LAN_DATE, 'type' => 'datestamp', 'data' => 'int', 'width' => '15%', 'help' => '', 'readParms' => '', 'writeParms' => 'auto=1&readonly=1', 'class' => 'center', 'thclass' => 'center', ), 109 'pm_subject' => array ( 'title' => LAN_PLUGIN_PM_SUB, 'type' => 'text', 'data' => 'str', 'width' => '15%', 'help' => '', 'readParms' => '', 'writeParms' => array('size'=>'xlarge'), 'class' => 'left', 'thclass' => 'left', ), 110 'pm_text' => array ( 'title' => LAN_PLUGIN_PM_MESS, 'type' => 'bbarea', 'data' => 'str', 'width' => '40%', 'help' => '', 'readParms' => 'expand=1&truncate=50', 'writeParms' => 'rows=5&size=block&cols=80', 'class' => 'left', 'thclass' => 'left', ), 111 'pm_read' => array ( 'title' => LAN_PLUGIN_PM_READ, 'type' => 'boolean', 'noedit'=>1, 'data' => 'int', 'batch'=>true, 'filter'=>true, 'width' => '5%', 'help' => '', 'readParms' => '', 'writeParms' => '', 'class' => 'center', 'thclass' => 'center', ), 112 113 'pm_sent_del' => array ( 'title' => LAN_PLUGIN_PM_DEL, 'type' => 'boolean', 'noedit'=>true, 'data' => 'int', 'width' => 'auto', 'help' => '', 'readParms' => '', 'writeParms' => '', 'class' => 'center', 'thclass' => 'center', ), 114 'pm_read_del' => array ( 'title' => LAN_PLUGIN_PM_DEL, 'type' => 'boolean', 'noedit'=>true, 'data' => 'int', 'width' => 'auto', 'help' => '', 'readParms' => '', 'writeParms' => '', 'class' => 'center', 'thclass' => 'center', ), 115 'pm_attachments' => array ( 'title' => LAN_PLUGIN_PM_ATTACHMENT, 'type' => 'text', 'noedit'=>true, 'data' => 'str', 'width' => 'auto', 'help' => '', 'readParms' => '', 'writeParms' => '', 'class' => 'center', 'thclass' => 'center', ), 116 'pm_option' => array ( 'title' => 'Option', 'type' => 'text', 'noedit'=>true, 'data' => 'str', 'width' => 'auto', 'help' => '', 'readParms' => '', 'writeParms' => '', 'class' => 'center', 'thclass' => 'center', ), 117 'pm_size' => array ( 'title' => LAN_PLUGIN_PM_SIZE, 'type' => 'boolean', 'noedit'=>true, 'data' => 'int', 'width' => 'auto', 'help' => '', 'readParms' => '', 'writeParms' => '', 'class' => 'center', 'thclass' => 'center', ), 118 'options' => array ( 'title' => LAN_OPTIONS, 'type' => 'method', 'data' => null, 'width' => '10%', 'thclass' => 'center last', 'class' => 'center last', 'forced' => '1', ), 119 ); 120 121 protected $fieldpref = array('pm_id', 'pm_from', 'pm_to', 'pm_sent', 'pm_read', 'pm_subject', 'pm_text'); 122 123 protected $preftabs = array(LAN_BASIC, LAN_ADVANCED); 124 125 protected $prefs = array( 126 'title' => array('title'=> ADLAN_PM_16, 'tab'=>0, 'type' => 'text', 'data' => 'str', 'help'=>''), 127 'pm_class' => array('title'=> ADLAN_PM_23, 'tab'=>0, 'type' => 'userclass', 'data' => 'int', 'help'=>'', 'writeParms'=>array('size'=>'xlarge', 'classlist'=>'nobody,main,member,admin,classes')), 128 'sendall_class' => array('title'=> ADLAN_PM_29, 'tab'=>1, 'type' => 'userclass', 'data' => 'int', 'help'=>'', 'writeParms'=>array('size'=>'xlarge', 'classlist'=>'nobody,main,member,admin,classes')), 129 'send_to_class' => array('title'=> ADLAN_PM_83, 'tab'=>0, 'type' => 'method', 'data' => 'str', 'help'=>''), 130 'vip_class' => array('title'=> ADLAN_PM_86, 'tab'=>0, 'type' => 'userclass', 'data' => 'int', 'help'=>ADLAN_PM_87, 'writeParms'=>array('size'=>'xlarge', 'classlist'=>'nobody,main,admin,classes')), 131 'multi_class' => array('title'=> ADLAN_PM_30, 'tab'=>0, 'type' => 'userclass', 'data' => 'int', 'help'=>'', 'writeParms'=>array('size'=>'xlarge', 'classlist'=>'nobody,main,member,admin,classes')), 132 'opt_userclass' => array('title'=> ADLAN_PM_31, 'tab'=>0, 'type' => 'userclass', 'data' => 'int', 'help'=>'', 'writeParms'=>array('size'=>'xlarge', 'classlist'=>'nobody,main,member,admin,classes')), 133 134 'animate' => array('title'=> ADLAN_PM_17, 'tab'=>1, 'type' => 'boolean', 'data' => 'str', 'help'=>''), 135 // 'dropdown' => array('title'=> ADLAN_PM_18, 'tab'=>0, 'type' => 'boolean', 'data' => 'str', 'help'=>''), 136 'read_timeout' => array('title'=> ADLAN_PM_19, 'tab'=>1, 'type' => 'number', 'data' => 'int', 'help'=>''), 137 'unread_timeout'=> array('title'=> ADLAN_PM_20, 'tab'=>1, 'type' => 'number', 'data' => 'int', 'help'=>''), 138 'popup' => array('title'=> ADLAN_PM_21, 'tab'=>1, 'type' => 'boolean', 'data' => 'int', 'help'=>''), 139 'popup_delay' => array('title'=> ADLAN_PM_22, 'tab'=>1, 'type' => 'number', 'data' => 'int', 'help'=>'', 'writeParms'=>array('post'=>ADLAN_PM_44, 'tdClassRight'=>'form-inline')), 140 'notify_class' => array('title'=> ADLAN_PM_25, 'tab'=>1, 'type' => 'userclass', 'data' => 'int', 'help'=>'', 'writeParms'=>array('size'=>'xlarge', 'classlist'=>'nobody,main,member,admin,classes')), 141 'receipt_class' => array('title'=> ADLAN_PM_26, 'tab'=>1, 'type' => 'userclass', 'data' => 'int', 'help'=>'', 'writeParms'=>array('size'=>'xlarge', 'classlist'=>'nobody,main,member,admin,classes')), 142 'attach_class' => array('title'=> ADLAN_PM_27, 'tab'=>0, 'type' => 'userclass', 'data' => 'int', 'help'=>'', 'writeParms'=>array('size'=>'xlarge', 'classlist'=>'nobody,main,member,admin,classes')), 143 'attach_size' => array('title'=> ADLAN_PM_28, 'tab'=>1, 'type' => 'number', 'data' => 'int', 'help'=>'', 'writeParms'=>'tdClassRight=form-inline&post=Kb'), 144 'pm_max_send' => array('title'=> ADLAN_PM_81, 'tab'=>1, 'type' => 'number', 'data' => 'int', 'help'=>''), 145 'perpage' => array('title'=> ADLAN_PM_24, 'tab'=>0, 'type' => 'number', 'data' => 'int', 'help'=>''), 146 'maxlength' => array('title'=> ADLAN_PM_84, 'tab'=>1, 'type' => 'number', 'data' => 'int', 'help'=>ADLAN_PM_85, 'writeParms'=>array('post'=>'chars.')), 147 148 149 ); 150 151 152 153 154 155 156 157 private function limitsPageAdd() 158 { 159 $sql = e107::getDb(); 160 $mes = e107::getMessage(); 161 162 $id = intval($_POST['newlimit_class']); 163 if($sql->select('generic','gen_id',"gen_type = 'pm_limit' AND gen_datestamp = ".$id)) 164 { 165 $mes->addInfo(ADLAN_PM_5); // 'Limit for selected user class already exists' 166 } 167 else 168 { 169 $limArray = array( // Strange field names because we use the 'generic' table. But at least it documents the correlation 170 'gen_type' => 'pm_limit', 171 'gen_datestamp' => intval($_POST['newlimit_class']), 172 'gen_user_id' => intval($_POST['new_inbox_count']), 173 'gen_ip' => intval($_POST['new_outbox_count']), 174 'gen_intdata' => intval($_POST['new_inbox_size']), 175 'gen_chardata' => intval($_POST['new_outbox_size']) 176 ); 177 178 if($sql->insert('generic', $limArray)) 179 { 180 e107::getLog()->logArrayAll('PM_ADM_05', $limArray); 181 $mes->addSuccess(ADLAN_PM_6); 182 } 183 else 184 { 185 e107::getLog()->log_event('PM_ADM_08', ''); 186 $mes->addError(ADLAN_PM_7); 187 } 188 } 189 190 191 } 192 193 194 private function limitsPageUpdate() 195 { 196 $sql = e107::getDb(); 197 $mes = e107::getMessage(); 198 $pm_prefs = e107::pref('pm'); 199 200 $limitVal = intval($_POST['pm_limits']); 201 202 203 if($pm_prefs['pm_limits'] != $limitVal) 204 { 205 $pm_prefs['pm_limits'] = $limitVal; 206 207 $mes->addSuccess(ADLAN_PM_8); 208 } 209 foreach(array_keys($_POST['inbox_count']) as $id) 210 { 211 $id = intval($id); 212 if($_POST['inbox_count'][$id] == '' && $_POST['outbox_count'][$id] == '' && $_POST['inbox_size'][$id] == '' && $_POST['outbox_size'][$id] == '') 213 { 214 //All entries empty - Remove record 215 if($sql->delete('generic','gen_id = '.$id)) 216 { 217 e107::getLog()->log_event('PM_ADM_07', 'ID: '.$id); 218 $mes->addSuccess($id.ADLAN_PM_9); 219 } 220 else 221 { 222 e107::getLog()->log_event('PM_ADM_10', ''); 223 $mes->addError($id.ADLAN_PM_10); 224 } 225 } 226 else 227 { 228 $limArray = array( // Strange field names because we use the 'generic' table. But at least it documents the correlation 229 'gen_user_id' => intval($_POST['inbox_count'][$id]), 230 'gen_ip' => intval($_POST['outbox_count'][$id]), 231 'gen_intdata' => intval($_POST['inbox_size'][$id]), 232 'gen_chardata' => intval($_POST['outbox_size'][$id]) 233 ); 234 235 236 if ($sql->update('generic',array('data' => $limArray, 'WHERE' => 'gen_id = '.$id))) 237 { 238 e107::getLog()->logArrayAll('PM_ADM_06', $limArray); 239 $mes->addSuccess($id.ADLAN_PM_11); 240 } 241 else 242 { 243 e107::getLog()->log_event('PM_ADM_09', ''); 244 $mes->addError($id.ADLAN_PM_7); 245 } 246 } 247 } 248 249 250 } 251 252 253 254 255 public function limitsPage() 256 { 257 258 if(isset($_POST['addlimit'])) 259 { 260 $this->limitsPageAdd(); 261 } 262 263 if(isset($_POST['updatelimits'])) 264 { 265 $this->limitsPageUpdate(); 266 } 267 268 // --------------------- 269 270 271 $sql = e107::getDb(); 272 $frm = e107::getForm(); 273 $pm_prefs = e107::pref('pm'); 274 275 if (!isset($pm_prefs['pm_limits'])) { $pm_prefs['pm_limits'] = 0; } 276 277 if($sql->select('generic', "gen_id as limit_id, gen_datestamp as limit_classnum, gen_user_id as inbox_count, gen_ip as outbox_count, gen_intdata as inbox_size, gen_chardata as outbox_size", "gen_type = 'pm_limit'")) 278 { 279 while($row = $sql->fetch()) 280 { 281 $limitList[$row['limit_classnum']] = $row; 282 } 283 } 284 285 $txt = " 286 <fieldset id='plugin-pm-showlimits'> 287 <form method='post' action='".e_SELF.'?'.e_QUERY."'> 288 <table class='table adminform'> 289 <colgroup> 290 <col class='col-label' /> 291 <col class='col-control' /> 292 <col class='col-control' /> 293 </colgroup> 294 <thead> 295 <tr> 296 <th>".LAN_USERCLASS."</th> 297 <th>".ADLAN_PM_37."</th> 298 <th>".ADLAN_PM_38."</th> 299 </tr> 300 </thead> 301 <tbody> 302 <tr> 303 <td colspan='3' style='text-align:left'>".ADLAN_PM_45." 304 <select name='pm_limits' class='tbox'> 305 "; 306 307 308 $sel = ($pm_prefs['pm_limits'] == 0 ? "selected='selected'" : ""); 309 $txt .= "<option value='0' {$sel}>".ADLAN_PM_33."</option>\n"; 310 311 $sel = ($pm_prefs['pm_limits'] == 1 ? "selected='selected'" : ""); 312 $txt .= "<option value='1' {$sel}>".ADLAN_PM_34."</option>\n"; 313 314 $sel = ($pm_prefs['pm_limits'] == 2 ? "selected='selected'" : ""); 315 $txt .= "<option value='2' {$sel}>".ADLAN_PM_35."</option>\n"; 316 317 $txt .= "</select>\n"; 318 319 $txt .= ' '.ADLAN_PM_77." 320 </td> 321 </tr> 322 323 "; 324 325 if (isset($limitList)) 326 { 327 foreach($limitList as $row) 328 { 329 $txt .= " 330 <tr> 331 <td>".e107::getUserClass()->uc_get_classname($row['limit_classnum'])."</td> 332 <td> 333 <div class='row'> 334 <div class='col-md-2'>".LAN_PLUGIN_PM_INBOX.":</div><div class='col-md-10'><input type='text' class='tbox' size='5' name='inbox_count[{$row['limit_id']}]' value='{$row['inbox_count']}' /></div> 335 <div class='col-md-2'>".LAN_PLUGIN_PM_OUTBOX.":</div><div class='col-md-10'><input type='text' class='tbox' size='5' name='outbox_count[{$row['limit_id']}]' value='{$row['outbox_count']}' /></div> 336 </div> 337 </td> 338 <td> 339 <div class='row'> 340 <div class='col-md-2'>".LAN_PLUGIN_PM_INBOX.":</div><div class='col-md-10'><input type='text' class='tbox' size='5' name='inbox_size[{$row['limit_id']}]' value='{$row['inbox_size']}' /></div> 341 <div class='col-md-2'>".LAN_PLUGIN_PM_OUTBOX.":</div><div class='col-md-10'><input type='text' class='tbox' size='5' name='outbox_size[{$row['limit_id']}]' value='{$row['outbox_size']}' /></div> 342 </div> 343 </td> 344 </tr> 345 "; 346 } 347 } 348 else 349 { 350 $txt .= " 351 <tr> 352 <td colspan='3' style='text-align: center'>".ADLAN_PM_41."</td> 353 </tr> 354 "; 355 } 356 357 $txt .= ' 358 </tbody> 359 </table> 360 <div class="buttons-bar center"> 361 '.$frm->admin_button('updatelimits','no-value','update', LAN_UPDATE).' 362 </div> 363 </form> 364 </fieldset>'; 365 366 $tabs = array(); 367 $tabs[] = array('caption'=>ADLAN_PM_14, 'text'=>$txt); 368 $tabs[] = array('caption'=>ADLAN_PM_15, 'text'=>$this->addLimitPage()); 369 370 return e107::getForm()->tabs($tabs); 371 } 372 373 374 375 function addLimitPage() 376 { 377 $sql = e107::getDb(); 378 $frm = e107::getForm(); 379 $pm_prefs = e107::pref('pm'); 380 381 if($sql->select('generic', "gen_id as limit_id, gen_datestamp as limit_classnum, gen_user_id as inbox_count, gen_ip as outbox_count, gen_intdata as inbox_size, gen_chardata as outbox_size", "gen_type = 'pm_limit'")) 382 { 383 while($row = $sql->fetch()) 384 { 385 $limitList[$row['limit_classnum']] = $row; 386 } 387 } 388 389 $txt = " 390 <fieldset id='plugin-pm-addlimit'> 391 <form method='post' action='".e_SELF.'?'.e_QUERY."'> 392 <table class='table adminform'> 393 <colgroup> 394 <col class='col-label' /> 395 <col class='col-control' /> 396 <col class='col-control' /> 397 </colgroup> 398 <thead> 399 <tr> 400 <th>".LAN_USERCLASS."</th> 401 <th>".ADLAN_PM_37."</th> 402 <th>".ADLAN_PM_38."</th> 403 </tr> 404 </thead> 405 <tbody> 406 "; 407 408 $txt .= " 409 <tr> 410 <td>".e107::getUserClass()->uc_dropdown('newlimit_class', 0, 'guest,member,admin,classes')."</td> 411 <td> 412 <div class='row'> 413 <div class='col-md-2'>".LAN_PLUGIN_PM_INBOX.":</div><div class='col-md-10'><input type='text' class='tbox' size='5' name='new_inbox_count' value='' /></div> 414 <div class='col-md-2'>".LAN_PLUGIN_PM_OUTBOX.":</div><div class='col-md-10'><input type='text' class='tbox' size='5' name='new_outbox_count' value='' /></div> 415 </div> 416 </td> 417 <td> 418 <div class='row'> 419 <div class='col-md-2'>".LAN_PLUGIN_PM_INBOX.":</div><div class='col-md-10'><input type='text' class='tbox' size='5' name='new_inbox_size' value='' /></div> 420 <div class='col-md-2'>".LAN_PLUGIN_PM_OUTBOX.":</div><div class='col-md-10'><input type='text' class='tbox' size='5' name='new_outbox_size' value='' /></div> 421 </div> 422 </td> 423 </tr> 424 425 "; 426 427 $txt .= ' 428 </tbody> 429 </table> 430 <div class="buttons-bar center"> 431 '.$frm->admin_button('addlimit','no-value','update', LAN_ADD).' 432 </div> 433 </form> 434 </fieldset>'; 435 return $txt; 436 } 437 438 439 440 441 442 public function mainPageProcess() 443 { 444 $pm_prefs = e107::pref('pm'); 445 $mes = e107::getMessage(); 446 447 $maintOpts = array(); 448 449 if (vartrue($_POST['pm_maint_sent'])) 450 { 451 $maintOpts['sent'] = 1; 452 } 453 454 if (vartrue($_POST['pm_maint_rec'])) 455 { 456 $maintOpts['rec'] = 1; 457 } 458 459 if (vartrue($_POST['pm_maint_blocked'])) 460 { 461 $maintOpts['blocked'] = 1; 462 } 463 464 if (vartrue($_POST['pm_maint_expired'])) 465 { 466 $maintOpts['expired'] = 1; 467 } 468 469 if (vartrue($_POST['pm_maint_attach'])) 470 { 471 $maintOpts['attach'] = 1; 472 } 473 474 $result = $this->doMaint($maintOpts, $pm_prefs); 475 476 if (is_array($result)) 477 { 478 foreach ($result as $k => $ma) 479 { 480 foreach ($ma as $m) 481 { 482 $mes->add($m, $k); 483 } 484 } 485 } 486 487 488 } 489 490 491 492 493 public function maintPage() 494 { 495 if(isset($_POST['pm_maint_execute'])) 496 { 497 $this->mainPageProcess(); 498 } 499 500 501 502 $frm = e107::getForm(); 503 $pmPrefs = e107::pref('pm'); 504 505 $txt = " 506 <fieldset id='plugin-pm-maint'> 507 <legend>".ADLAN_PM_62."</legend> 508 <form method='post' action='".e_SELF."?maint'> 509 <table class='table adminform'> 510 <colgroup> 511 <col class='col-label' /> 512 <col class='col-control' /> 513 </colgroup> 514 <tbody> 515 <tr> 516 <td>".ADLAN_PM_63."</td> 517 <td>".$frm->radio_switch('pm_maint_sent', '', LAN_YES, LAN_NO)."</td> 518 </tr> 519 <tr> 520 <td>".ADLAN_PM_64."</td> 521 <td>".$frm->radio_switch('pm_maint_rec', '', LAN_YES, LAN_NO)."</td> 522 </tr> 523 <tr> 524 <td>".ADLAN_PM_65."</td> 525 <td>".$frm->radio_switch('pm_maint_blocked', '', LAN_YES, LAN_NO)."</td> 526 </tr> 527 "; 528 529 if ($pmPrefs['read_timeout'] || $pmPrefs['unread_timeout']) 530 { 531 $txt .= " 532 <tr> 533 <td>".ADLAN_PM_71."</td> 534 <td>".$frm->radio_switch('pm_maint_expired', '', LAN_YES, LAN_NO)."</td> 535 </tr>"; 536 } 537 538 $txt .= " 539 <tr> 540 <td>".ADLAN_PM_78."</td> 541 <td>".$frm->radio_switch('pm_maint_attach', '', LAN_YES, LAN_NO)."</td> 542 </tr> 543 </tbody> 544 </table> 545 <div class='buttons-bar center'> 546 ".$frm->admin_button('pm_maint_execute','no-value','delete', LAN_GO)." 547 </div> 548 </form> 549 </fieldset> 550 "; 551 552 553 return $txt; 554 555 556 } 557 558 559 560 561 /** 562 * Do PM DB maintenance 563 * @param array $opts of tasks key = sent|rec|blocked|expired (one or more present). ATM value not used 564 * @return array where key is message type (E_MESSAGE_SUCCESS|E_MESSAGE_ERROR|E_MESSAGE_INFO etc), data is array of messages of that type (key = timestamp) 565 */ 566 private function doMaint($opts, $pmPrefs) 567 { 568 if (!count($opts)) 569 { 570 return array(E_MESSAGE_ERROR => array(ADLAN_PM_66)); 571 } 572 573 574 575 $results = array(E_MESSAGE_INFO => array(ADLAN_PM_67)); // 'Maintenance started' - primarily for a log entry to mark start time 576 $logResults = array(); 577 $e107 = e107::getInstance(); 578 e107::getLog()->log_event('PM_ADM_04', implode(', ',array_keys($opts))); 579 $pmHandler = new private_message($pmPrefs); 580 $db2 =e107::getDb('sql2'); // Will usually need a second DB object to avoid over load 581 $start = 0; // Use to ensure we get different log times 582 583 584 if (isset($opts['sent'])) // Want pm_from = deleted user and pm_read_del = 1 585 { 586 $cnt = 0; 587 if ($res = $db2->gen("SELECT pm.pm_id FROM `#private_msg` AS pm LEFT JOIN `#user` AS u ON pm.`pm_from` = `#user`.`user_id` 588 WHERE (pm.`pm_read_del = 1) AND `#user`.`user_id` IS NULL")) 589 { 590 while ($row = $db2->fetch()) 591 { 592 if ($pmHandler->del($row['pm_id']) !== FALSE) 593 { 594 $cnt++; 595 } 596 } 597 } 598 $start = time(); 599 $results[E_MESSAGE_SUCCESS][$start] = str_replace('[x]', $cnt, ADLAN_PM_74); 600 } 601 if (isset($opts['rec'])) // Want pm_to = deleted user and pm_sent_del = 1 602 { 603 $cnt = 0; 604 if ($res = $db2->gen("SELECT pm.pm_id FROM `#private_msg` AS pm LEFT JOIN `#user` AS u ON pm.`pm_to` = `#user`.`user_id` 605 WHERE (pm.`pm_sent_del = 1) AND `#user`.`user_id` IS NULL")) 606 { 607 while ($row = $db2->fetch()) 608 { 609 if ($pmHandler->del($row['pm_id']) !== FALSE) 610 { 611 $cnt++; 612 } 613 } 614 } 615 $start = max($start + 1, time()); 616 $results[E_MESSAGE_SUCCESS][$start] = str_replace('[x]', $cnt, ADLAN_PM_75); 617 } 618 619 620 if (isset($opts['blocked'])) 621 { 622 if ($res = $db2->gen("DELETE `#private_msg_block` FROM `#private_msg_block` LEFT JOIN `#user` ON `#private_msg_block`.`pm_block_from` = `#user`.`user_id` 623 WHERE `#user`.`user_id` IS NULL")) 624 { 625 $start = max($start + 1, time()); 626 $results[E_MESSAGE_ERROR][$start] = str_replace(array('[y]', '[z]'), array($this->sql->getLastErrorNum, $this->sql->getLastErrorText), ADLAN_PM_70); 627 } 628 else 629 { 630 $start = max($start + 1, time()); 631 $results[E_MESSAGE_SUCCESS][$start] = str_replace('[x]', $res, ADLAN_PM_69); 632 } 633 if ($res = $db2->gen("DELETE `#private_msg_block` FROM `#private_msg_block` LEFT JOIN `#user` ON `#private_msg_block`.`pm_block_to` = `#user`.`user_id` 634 WHERE `#user`.`user_id` IS NULL")) 635 { 636 $start = max($start + 1, time()); 637 $results[E_MESSAGE_ERROR][$start] = str_replace(array('[y]', '[z]'), array($this->sql->getLastErrorNum, $this->sql->getLastErrorText), ADLAN_PM_70); 638 } 639 else 640 { 641 $start = max($start + 1, time()); 642 $results[E_MESSAGE_SUCCESS][$start] = str_replace('[x]', $res, ADLAN_PM_68); 643 } 644 } 645 646 647 if (isset($opts['expired'])) 648 { 649 $del_qry = array(); 650 $read_timeout = intval($pmPrefs['read_timeout']); 651 $unread_timeout = intval($pmPrefs['unread_timeout']); 652 if($read_timeout > 0) 653 { 654 $timeout = time()-($read_timeout * 86400); 655 $del_qry[] = "(pm_sent < {$timeout} AND pm_read > 0)"; 656 } 657 if($unread_timeout > 0) 658 { 659 $timeout = time()-($unread_timeout * 86400); 660 $del_qry[] = "(pm_sent < {$timeout} AND pm_read = 0)"; 661 } 662 if(count($del_qry) > 0) 663 { 664 $qry = implode(' OR ', $del_qry); 665 $cnt = 0; 666 if($db2->db_Select('private_msg', 'pm_id', $qry)) 667 { 668 while ($row = $db2->db_Fetch()) 669 { 670 if ($pmHandler->del($row['pm_id']) !== FALSE) 671 { 672 $cnt++; 673 } 674 } 675 } 676 $start = max($start + 1, time()); 677 $results[E_MESSAGE_SUCCESS][$start] = str_replace('[x]', $cnt, ADLAN_PM_73); 678 } 679 else 680 { 681 $start = max($start + 1, time()); 682 $results[E_MESSAGE_ERROR][$start] = ADLAN_PM_72; 683 } 684 } 685 686 687 if (isset($opts['attach'])) 688 { // Check for orphaned and missing attachments 689 690 $fl = e107::getFile(); 691 $missing = array(); 692 $orphans = array(); 693 $fileArray = $fl->get_files(e_PLUGIN.'pm/attachments'); //FIXME wrong path. 694 if ($db2->select('private_msg', 'pm_id, pm_attachments', "pm_attachments != ''")) 695 { 696 while ($row = $db2->fetch()) 697 { 698 $attachList = explode(chr(0), $row['pm_attachments']); 699 foreach ($attachList as $a) 700 { 701 $found = FALSE; 702 foreach ($fileArray as $k => $fd) 703 { 704 if ($fd['fname'] == $a) 705 { 706 $found = TRUE; 707 unset($fileArray[$k]); 708 break; 709 } 710 } 711 if (!$found) 712 { 713 $missing[] = $row['pm_id'].':'.$a; 714 } 715 } 716 } 717 } 718 // Any files left in $fileArray now are unused 719 if (count($fileArray)) 720 { 721 foreach ($fileArray as $k => $fd) 722 { 723 unlink($fd['path'].$fd['fname']); 724 $orphans[] = $fd['fname']; 725 } 726 } 727 $attachMessage = str_replace(array('[x]', '[y]'), array(count($orphans), count($missing)), ADLAN_PM_79); 728 if (TRUE) 729 { // Mostly for testing - probably disable this 730 if (count($orphans)) 731 { 732 $attachMessage .= '[!br!]Orphans:[!br!]'.implode('[!br!]', $orphans); 733 } 734 if (count($missing)) 735 { 736 $attachMessage .= '[!br!]Missing:[!br!]'.implode('[!br!]', $missing); 737 } 738 } 739 $start = max($start + 1, time()); 740 $results[E_MESSAGE_SUCCESS][$start] = $attachMessage; 741 } 742 743 744 e107::getLog()->logArrayAll('PM_ADM_03', $this->makeLogEntry($results)); 745 746 foreach ($results as $k => $r) 747 { 748 foreach ($r as $sk => $s) 749 { 750 $results[$k][$sk] = str_replace('[!br!]','<br />',$s); 751 } 752 } 753 return $results; 754 } 755 756 757 758 /** 759 * Turn the array produced by doMaint for message display into an array of log strings. 760 * Data is sorted into time stamp order 761 * 762 * @param array $results - array of arrays as returned from doMaint() 763 * @param array|boolean $extra - optional additional information which is sorted into the main result according to keys - so use low numbers 764 * to make the entry appear at the beginning, and text strings to add to the end. 765 */ 766 function makeLogEntry($results, $extra = FALSE) 767 { 768 $logPrefixes = array(E_MESSAGE_SUCCESS => 'Pass - ', E_MESSAGE_ERROR => 'Fail - ', E_MESSAGE_INFO => 'Info - ', E_MESSAGE_DEBUG => 'Debug - '); 769 770 $res = array(); 771 772 foreach ($results as $k => $ma) 773 { 774 foreach ($ma as $ts => $m) 775 { 776 $res[$ts] = $logPrefixes[$k].$m; 777 } 778 } 779 780 if (is_array($extra)) 781 { 782 $res = array_merge($res, $extra); 783 } 784 785 ksort($res); // Sort in ascending order of timestamp 786 787 return $res; 788 } 789 790 791 function sendTestNotify() 792 { 793 e107::includeLan(e_PLUGIN.'pm/languages/'.e_LANGUAGE.'.php'); 794 require_once(e_PLUGIN."pm/pm_class.php"); 795 796 $pmInfo = array ( 'numsent' => '1', 'pm_to' => USERID, 'pm_sent'=>time(), 'pm_userclass' => false, 'pm_subject' => 'Test Subject Random:'.md5(time()), 'pm_message' => 'Test Message '.md5(time()), 'postpm' => 'Send Private Message', 'keyword' => NULL, 797 'to_info' => array ( 798 'user_id' => USERID, 799 'user_name' => USERNAME, 800 'user_class' => USERCLASS, 801 'user_email' => USEREMAIL, 802 ), 803 'uploaded' => array ( ), 'from_id' => 1, 'options' => '', ); 804 805 $pm = new private_message; 806 807 if($pm->pm_send_notify(null,$pmInfo, 1) === true) 808 { 809 e107::getMessage()->addSuccess(ADLAN_PM_92); 810 } 811 else 812 { 813 e107::getMessage()->addError(ADLAN_PM_93); 814 } 815 816 817 } 818 819 820 public function init() 821 { 822 // $this->listQry = "SELECT p.*,u.user_name FROM #private_msg AS p LEFT JOIN #user AS u ON p.pm_from = u.user_id "; 823 824 if(deftrue('e_DEVELOPER') || deftrue('e_DEBUG')) 825 { 826 $this->prefs['notify_class']['writeParms']['post']= e107::getForm()->button('testNotify', 1, 'primary', ADLAN_PM_91); 827 828 if(!empty($_POST['testNotify'])) 829 { 830 $this->sendTestNotify(); 831 } 832 } 833 834 if($this->getMode() == 'inbox') 835 { 836 $this->listQry = 'SELECT p.*, u.user_name, f.user_name AS fromuser FROM #private_msg AS p LEFT JOIN #user AS u ON u.user_id = p.pm_to 837 LEFT JOIN #user as f on f.user_id = p.pm_from WHERE p.pm_to = '.USERID; 838 $this->fields['pm_to']['nolist'] = true; 839 $this->fields['options']['readParms'] = 'editClass='.e_UC_NOBODY; 840 } 841 842 if($this->getMode() == 'outbox') 843 { 844 $this->listQry = 'SELECT p.*, u.user_name, f.user_name AS fromuser FROM #private_msg AS p LEFT JOIN #user AS u ON u.user_id = p.pm_to 845 LEFT JOIN #user as f on f.user_id = p.pm_from WHERE p.pm_from = '.USERID; 846 $this->fields['pm_from']['nolist'] = true; 847 $this->fields['options']['readParms'] = 'editClass='.e_UC_NOBODY; 848 } 849 850 if($this->getMode() == 'main') 851 { 852 $this->listQry = 'SELECT p.*, u.user_name, f.user_name AS fromuser FROM #private_msg AS p LEFT JOIN #user AS u ON u.user_id = p.pm_to 853 LEFT JOIN #user as f on f.user_id = p.pm_from WHERE 1 '; 854 // $this->fields['pm_from']['nolist'] = true; 855 $this->fields['options']['readParms'] = 'editClass='.e_UC_NOBODY; 856 $this->perPage = 20; 857 } 858 859 if($this->getAction() == 'create') 860 { 861 $this->fields['pm_to']['writeParms']['default'] = 99999999; 862 $this->fields['pm_to']['writeParms']['required'] = 1; 863 $this->fields['pm_subject']['writeParms']['required'] = 1; 864 865 if(!empty($_GET['to'])) 866 { 867 $this->fields['pm_to']['writeParms']['default'] = intval($_GET['to']); 868 $this->addTitle('Reply'); 869 } 870 871 if(!empty($_GET['subject'])) 872 { 873 $this->fields['pm_subject']['writeParms']['default'] = "Re: ". base64_decode($_GET['subject']); 874 } 875 876 877 } 878 879 880 881 882 } 883 884 public function beforeCreate($new_data) 885 { 886 887 if(empty($new_data['pm_to'])) 888 { 889 e107::getMessage()->addError(ADLAN_PM_90); 890 return false; 891 } 892 893 $new_data['pm_size'] = strlen($new_data['pm_text']); 894 $new_data['pm_from'] = USERID; 895 return $new_data; 896 } 897 898 899 /* 900 protected = array( 901 'pref_type' => array('title'=> 'type', 'type'=>'text', 'data' => 'string', 'validate' => true), 902 'pref_folder' => array('title'=> 'folder', 'type' => 'boolean', 'data' => 'integer'), 903 'pref_name' => array('title'=> 'name', 'type' => 'text', 'data' => 'string', 'validate' => 'regex', 'rule' => '#^[\w]+$#i', 'help' => 'allowed characters are a-zA-Z and underscore') 904 ); 905 906 907 908 909 910 public function customPage() 911 { 912 $ns = e107::getRender(); 913 $text = 'Hello World!'; 914 $ns->tablerender('Hello',$text); 915 916 } 917 */ 918 919} 920 921 922 923class private_msg_form_ui extends e_admin_form_ui 924{ 925 926 function send_to_class($value, $mode, $id) 927 { 928 $list = e107::getUserClass()->getClassList('main,admin,member,classes'); 929 $list['matchclass'] = ADLAN_PM_89; 930 931 return $this->select('send_to_class', $list, vartrue($value, e_UC_MEMBER), array('size'=>'xlarge')); 932 933 } 934 935 936 937 938 function options($parms, $value, $id, $attributes) 939 { 940 941 // return $this->renderValue('options',$value,$att,$id);; 942 $tp = e107::getParser(); 943 $mode = $this->getController()->getMode(); 944 945 if($mode == 'inbox') 946 { 947 $text = ""; 948 $pmData = $this->getController()->getListModel()->getData(); 949 950 if($pmData['pm_from'] != USERID) 951 { 952 $link = e_SELF."?"; 953 $link .= (!empty($_GET['iframe'])) ? 'mode=inbox&iframe=1' : 'mode=outbox'; 954 955 956 $link .= "&action=create&to=".intval($pmData['pm_from'])."&subject=".base64_encode($pmData['pm_subject']); 957 958 959 960 $text .= "<a href='".$link."' class='btn' title='Reply'>".$tp->toGlyph('fa-reply', array('size'=>'1x'))."</a>"; 961 } 962 963 // $text .= $this->renderValue('options',$value,$attr,$id); 964 965 return $text; 966 } 967 } 968 969 function pm_from($curVal, $mode) 970 { 971 972 if($mode == 'read') 973 { 974 $pmData = $this->getController()->getListModel()->getData(); 975 } 976 977 return $pmData['fromuser']; 978 } 979} 980 981/* 982 983 984class private_msg_block_ui extends e_admin_ui 985{ 986 987 protected $pluginTitle = 'Private Messaging'; 988 protected $pluginName = 'pm'; 989 protected $table = 'private_msg_block'; 990 protected $pid = 'pm_block_id'; 991 protected $perPage = 10; 992 993 protected $fields = array ( 'checkboxes' => array ( 'title' => '', 'type' => null, 'data' => null, 'width' => '5%', 'thclass' => 'center', 'forced' => '1', 'class' => 'center', 'toggle' => 'e-multiselect', ), 994 'pm_block_id' => array ( 'title' => 'LAN_ID', 'data' => 'int', 'width' => '5%', 'help' => '', 'readParms' => '', 'writeParms' => '', 'class' => 'left', 'thclass' => 'left', ), 995 'pm_block_from' => array ( 'title' => 'From', 'type' => 'boolean', 'data' => 'int', 'width' => 'auto', 'help' => '', 'readParms' => '', 'writeParms' => '', 'class' => 'center', 'thclass' => 'center', ), 996 'pm_block_to' => array ( 'title' => 'To', 'type' => 'boolean', 'data' => 'int', 'width' => 'auto', 'help' => '', 'readParms' => '', 'writeParms' => '', 'class' => 'center', 'thclass' => 'center', ), 997 'pm_block_datestamp' => array ( 'title' => 'LAN_DATESTAMP', 'type' => 'datestamp', 'data' => 'int', 'width' => 'auto', 'filter' => true, 'help' => '', 'readParms' => '', 'writeParms' => '', 'class' => 'left', 'thclass' => 'left', ), 998 'pm_block_count' => array ( 'title' => 'Count', 'type' => 'boolean', 'data' => 'int', 'width' => 'auto', 'help' => '', 'readParms' => '', 'writeParms' => '', 'class' => 'center', 'thclass' => 'center', ), 999 'options' => array ( 'title' => 'Options', 'type' => null, 'data' => null, 'width' => '10%', 'thclass' => 'center last', 'class' => 'center last', 'forced' => '1', ), 1000 ); 1001 1002 protected $fieldpref = array('pm_block_datestamp'); 1003 1004 1005 1006 1007 // protected = array( 1008 // 'pref_type' => array('title'=> 'type', 'type'=>'text', 'data' => 'string', 'validate' => true), 1009 // 'pref_folder' => array('title'=> 'folder', 'type' => 'boolean', 'data' => 'integer'), 1010 // 'pref_name' => array('title'=> 'name', 'type' => 'text', 'data' => 'string', 'validate' => 'regex', 'rule' => '#^[\w]+$#i', 'help' => 'allowed characters are a-zA-Z and underscore') 1011 // ); 1012 1013 1014 // optional 1015 public function init() 1016 { 1017 1018 } 1019 1020 1021 public function customPage() 1022 { 1023 $ns = e107::getRender(); 1024 $text = 'Hello World!'; 1025 $ns->tablerender('Hello',$text); 1026 1027 } 1028 1029 1030} 1031 1032 1033 1034class private_msg_block_form_ui extends e_admin_form_ui 1035{ 1036 1037} 1038 */ 1039 1040 1041new pm_admin(); 1042 1043require_once(e_ADMIN."auth.php"); 1044e107::getAdminUI()->runPage(); 1045 1046require_once(e_ADMIN."footer.php"); 1047exit; 1048 1049 1050