2006-12-02 04:36:16 +00:00
< ? php
/*
2009-11-17 13:48:46 +00:00
* e107 website system
*
2013-03-04 00:17:31 +01:00
* Copyright ( C ) 2008 - 2013 e107 Inc ( e107 . org )
2009-11-17 13:48:46 +00:00
* Released under the terms and conditions of the
* GNU General Public License ( http :// www . gnu . org / licenses / gpl . txt )
*
2009-12-11 22:33:15 +00:00
* PM Plugin - administration
2009-11-17 13:48:46 +00:00
*
*/
2009-12-11 22:33:15 +00:00
2009-12-17 22:47:20 +00:00
/**
* e107 Private messenger plugin
*
* @ package e107_plugins
* @ subpackage pm
*/
2009-12-11 22:33:15 +00:00
/*
TODO :
1. Limits page needs some lines round the table
2010-01-04 21:35:38 +00:00
2. Prefs - use new get method
2009-12-11 22:33:15 +00:00
3. Maintenance page - to be tested
2010-01-04 21:35:38 +00:00
4. Put prefs into plugin . xml
2009-12-11 22:33:15 +00:00
5. User option to enable / disable email notification of PMs
6. Cron - triggered bulk send .
2009-12-16 20:23:37 +00:00
7. What are implications of 'anyone but' userclasses ?
2009-12-11 22:33:15 +00:00
*/
2006-12-02 04:36:16 +00:00
$retrieve_prefs [] = 'pm_prefs' ;
$eplug_admin = TRUE ;
2009-12-10 20:40:39 +00:00
require_once ( '../../class2.php' );
2006-12-02 04:36:16 +00:00
2009-12-10 20:40:39 +00:00
if ( ! e107 :: isInstalled ( 'pm' ) || ! getperms ( 'P' ))
2006-12-02 04:36:16 +00:00
{
2016-01-13 19:17:37 -08:00
e107 :: redirect ( 'admin' );
2006-12-02 04:36:16 +00:00
exit ;
}
2009-12-11 22:33:15 +00:00
require_once ( e_PLUGIN . 'pm/pm_class.php' );
2009-12-16 20:23:37 +00:00
//require_once(e_HANDLER.'userclass_class.php'); Should already be loaded
2013-02-10 17:57:37 +01:00
$mes = e107 :: getMessage ();
2009-12-11 22:33:15 +00:00
2006-12-02 04:36:16 +00:00
$action = e_QUERY ;
2009-12-10 20:40:39 +00:00
require_once ( e_ADMIN . 'auth.php' );
2006-12-02 04:36:16 +00:00
2009-12-10 20:40:39 +00:00
if ( $action == '' )
2006-12-02 04:36:16 +00:00
{
2009-12-10 20:40:39 +00:00
$action = 'main' ;
2006-12-02 04:36:16 +00:00
}
2009-12-16 20:23:37 +00:00
2013-01-31 19:13:50 -08:00
// $pm_prefs = $sysprefs->getArray('pm_prefs');
$pm_prefs = e107 :: getPlugPref ( 'pm' );
2006-12-02 04:36:16 +00:00
//pm_prefs record not found in core table, set to defaults and create record
2013-01-31 19:13:50 -08:00
/*
2006-12-02 04:36:16 +00:00
if ( ! is_array ( $pm_prefs ))
{
2009-12-10 20:40:39 +00:00
require_once ( e_PLUGIN . 'pm/pm_default.php' );
$pm_prefs = pm_set_default_prefs (); // Use the default settings
2006-12-02 04:36:16 +00:00
$sysprefs -> setArray ( 'pm_prefs' );
2009-12-11 22:33:15 +00:00
$emessage -> add ( ADLAN_PM_3 , E_MESSAGE_INFO );
$e107 -> admin_log -> log_event ( 'PM_ADM_01' , '' );
2006-12-02 04:36:16 +00:00
}
2013-01-31 19:13:50 -08:00
*/
2009-12-10 20:40:39 +00:00
2009-12-16 20:23:37 +00:00
// Couple of bits of BC/upgrade
2013-01-31 19:13:50 -08:00
/*
2009-12-16 20:23:37 +00:00
$savePMP = FALSE ;
if ( isset ( $pref [ 'pm_limits' ]))
{
if ( ! isset ( $pm_prefs [ 'pm_limits' ]))
{
$pm_prefs [ 'pm_limits' ] = $pref [ 'pm_limits' ];
$savePMP = TRUE ;
}
unset ( $pref [ 'pm_limits' ]);
save_prefs ();
}
if ( isset ( $pm_prefs [ 'allow_userclass' ]))
{
if ( ! isset ( $pm_prefs [ 'opt_userclass' ]))
{
$pm_prefs [ 'opt_userclass' ] = e_UC_NOBODY ;
if ( $pm_prefs [ 'allow_userclass' ])
{
$pm_prefs [ 'opt_userclass' ] = e_UC_MEMBERS ;
}
}
unset ( $pm_prefs [ 'allow_userclass' ]);
$savePMP = TRUE ;
}
if ( $savePMP )
{
2013-01-31 19:13:50 -08:00
// $sysprefs->setArray('pm_prefs');
// $emessage->add(ADLAN_PM_80, E_MESSAGE_SUCCESS);
2009-12-16 20:23:37 +00:00
}
2013-01-31 19:13:50 -08:00
*/
2009-12-10 20:40:39 +00:00
2010-01-04 21:35:38 +00:00
//include_lan(e_PLUGIN.'pm/languages/admin/'.e_LANGUAGE.'.php');
2006-12-02 04:36:16 +00:00
if ( isset ( $_POST [ 'update_prefs' ]))
{
2009-12-11 22:33:15 +00:00
$temp = array ();
foreach ( $_POST as $k => $v )
2006-12-02 04:36:16 +00:00
{
2009-12-11 22:33:15 +00:00
if ( strpos ( $k , 'pm_option-' ) === 0 )
{
$k = str_replace ( 'pm_option-' , '' , $k );
$temp [ $k ] = $v ;
}
}
2015-02-15 16:07:27 -08:00
if ( e107 :: getLog () -> logArrayDiffs ( $temp , $pm_prefs , 'PM_ADM_02' ))
2009-12-11 22:33:15 +00:00
{
2013-01-31 19:13:50 -08:00
// $sysprefs->setArray('pm_prefs');
//print_a($temp);
e107 :: getPlugConfig ( 'pm' ) -> setPref ( $temp ) -> save ();
2009-12-11 22:33:15 +00:00
}
else
{
2013-02-10 17:57:37 +01:00
$mes -> addInfo ( LAN_NO_CHANGE );
2009-12-11 22:33:15 +00:00
}
}
// Mantenance options
if ( isset ( $_POST [ 'pm_maint_execute' ]))
{
$maintOpts = array ();
if ( vartrue ( $_POST [ 'pm_maint_sent' ]))
{
$maintOpts [ 'sent' ] = 1 ;
}
if ( vartrue ( $_POST [ 'pm_maint_rec' ]))
{
$maintOpts [ 'rec' ] = 1 ;
}
if ( vartrue ( $_POST [ 'pm_maint_blocked' ]))
{
$maintOpts [ 'blocked' ] = 1 ;
}
if ( vartrue ( $_POST [ 'pm_maint_expired' ]))
{
$maintOpts [ 'expired' ] = 1 ;
}
2009-12-13 12:32:29 +00:00
if ( vartrue ( $_POST [ 'pm_maint_attach' ]))
{
$maintOpts [ 'attach' ] = 1 ;
}
2009-12-11 22:33:15 +00:00
$result = doMaint ( $maintOpts , $pm_prefs );
if ( is_array ( $result ))
{
foreach ( $result as $k => $ma )
{
foreach ( $ma as $m )
{
2013-02-10 17:57:37 +01:00
$mes -> add ( $m , $k );
2009-12-11 22:33:15 +00:00
}
}
2006-12-02 04:36:16 +00:00
}
}
2009-12-10 20:40:39 +00:00
2006-12-02 04:36:16 +00:00
if ( isset ( $_POST [ 'addlimit' ]))
{
2009-12-11 22:33:15 +00:00
$id = intval ( $_POST [ 'newlimit_class' ]);
if ( $sql -> db_Select ( 'generic' , 'gen_id' , " gen_type = 'pm_limit' AND gen_datestamp = " . $id ))
2006-12-02 04:36:16 +00:00
{
2013-02-10 17:57:37 +01:00
$mes -> addInfo ( ADLAN_PM_5 ); // 'Limit for selected user class already exists'
2006-12-02 04:36:16 +00:00
}
else
{
2009-12-11 22:33:15 +00:00
$limArray = array ( // Strange field names because we use the 'generic' table. But at least it documents the correlation
'gen_type' => 'pm_limit' ,
'gen_datestamp' => intval ( $_POST [ 'newlimit_class' ]),
'gen_user_id' => intval ( $_POST [ 'new_inbox_count' ]),
'gen_ip' => intval ( $_POST [ 'new_outbox_count' ]),
'gen_intdata' => intval ( $_POST [ 'new_inbox_size' ]),
'gen_chardata' => intval ( $_POST [ 'new_outbox_size' ])
);
2015-02-15 16:07:27 -08:00
if ( $sql -> insert ( 'generic' , $limArray ))
2006-12-02 04:36:16 +00:00
{
2015-02-15 16:07:27 -08:00
e107 :: getLog () -> logArrayAll ( 'PM_ADM_05' , $limArray );
2013-02-10 17:57:37 +01:00
$mes -> addSuccess ( ADLAN_PM_6 );
2006-12-02 04:36:16 +00:00
}
else
{
2015-02-15 16:07:27 -08:00
e107 :: getLog () -> log_event ( 'PM_ADM_08' , '' );
2013-02-10 17:57:37 +01:00
$mes -> addError ( ADLAN_PM_7 );
2006-12-02 04:36:16 +00:00
}
}
}
if ( isset ( $_POST [ 'updatelimits' ]))
{
2009-12-13 12:32:29 +00:00
$limitVal = intval ( $_POST [ 'pm_limits' ]);
2009-12-16 20:23:37 +00:00
if ( $pm_prefs [ 'pm_limits' ] != $limitVal )
2006-12-02 04:36:16 +00:00
{
2009-12-16 20:23:37 +00:00
$pm_prefs [ 'pm_limits' ] = $limitVal ;
2013-01-31 19:13:50 -08:00
//$sysprefs->setArray('pm_prefs');
2013-02-10 17:57:37 +01:00
$mes -> addSuccess ( ADLAN_PM_8 );
2006-12-02 04:36:16 +00:00
}
foreach ( array_keys ( $_POST [ 'inbox_count' ]) as $id )
{
2009-12-11 22:33:15 +00:00
$id = intval ( $id );
if ( $_POST [ 'inbox_count' ][ $id ] == '' && $_POST [ 'outbox_count' ][ $id ] == '' && $_POST [ 'inbox_size' ][ $id ] == '' && $_POST [ 'outbox_size' ][ $id ] == '' )
2006-12-02 04:36:16 +00:00
{
//All entries empty - Remove record
2015-02-15 16:07:27 -08:00
if ( $sql -> delete ( 'generic' , 'gen_id = ' . $id ))
2006-12-02 04:36:16 +00:00
{
2015-02-15 16:07:27 -08:00
e107 :: getLog () -> log_event ( 'PM_ADM_07' , 'ID: ' . $id );
2013-02-10 17:57:37 +01:00
$mes -> addSuccess ( $id . ADLAN_PM_9 );
2006-12-02 04:36:16 +00:00
}
else
{
2015-02-15 16:07:27 -08:00
e107 :: getLog () -> log_event ( 'PM_ADM_10' , '' );
2013-02-10 17:57:37 +01:00
$mes -> addError ( $id . ADLAN_PM_10 );
2006-12-02 04:36:16 +00:00
}
}
else
{
2009-12-11 22:33:15 +00:00
$limArray = array ( // Strange field names because we use the 'generic' table. But at least it documents the correlation
'gen_user_id' => intval ( $_POST [ 'inbox_count' ][ $id ]),
'gen_ip' => intval ( $_POST [ 'outbox_count' ][ $id ]),
'gen_intdata' => intval ( $_POST [ 'inbox_size' ][ $id ]),
'gen_chardata' => intval ( $_POST [ 'outbox_size' ][ $id ])
);
2015-02-15 16:07:27 -08:00
if ( $sql -> update ( 'generic' , array ( 'data' => $limArray , 'WHERE' => 'gen_id = ' . $id )))
2009-12-11 22:33:15 +00:00
{
2015-02-15 16:07:27 -08:00
e107 :: getLog () -> logArrayAll ( 'PM_ADM_06' , $limArray );
2013-02-10 17:57:37 +01:00
$mes -> addSuccess ( $id . ADLAN_PM_11 );
2009-12-11 22:33:15 +00:00
}
else
{
2015-02-15 16:07:27 -08:00
e107 :: getLog () -> log_event ( 'PM_ADM_09' , '' );
2013-02-10 17:57:37 +01:00
$mes -> addError ( $id . ADLAN_PM_7 );
2009-12-11 22:33:15 +00:00
}
2006-12-02 04:36:16 +00:00
}
}
}
2009-12-10 20:40:39 +00:00
2013-02-10 17:57:37 +01:00
$ns -> tablerender ( $caption , $mes -> render () . $text );
2006-12-02 04:36:16 +00:00
2009-12-17 22:47:20 +00:00
2009-12-10 20:40:39 +00:00
switch ( $action )
2006-12-02 04:36:16 +00:00
{
2009-12-10 20:40:39 +00:00
case 'main' :
2009-12-11 22:33:15 +00:00
$ns -> tablerender ( ADLAN_PM_12 , show_options ( $pm_prefs ));
2009-12-10 20:40:39 +00:00
break ;
case 'limits' :
2009-12-16 20:23:37 +00:00
$ns -> tablerender ( ADLAN_PM_14 , show_limits ( $pm_prefs ));
$ns -> tablerender ( ADLAN_PM_15 , add_limit ( $pm_prefs ));
2009-12-10 20:40:39 +00:00
break ;
2009-12-11 22:33:15 +00:00
case 'maint' :
$ns -> tablerender ( ADLAN_PM_60 , show_maint ( $pm_prefs ));
break ;
2006-12-02 04:36:16 +00:00
}
2009-12-10 20:40:39 +00:00
require_once ( e_ADMIN . 'footer.php' );
2006-12-02 04:36:16 +00:00
2009-12-11 22:33:15 +00:00
function show_options ( $pm_prefs )
2006-12-02 04:36:16 +00:00
{
2013-02-02 20:01:53 +01:00
$frm = e107 :: getForm ();
2006-12-02 04:36:16 +00:00
$txt = "
2009-12-11 22:33:15 +00:00
< fieldset id = 'plugin-pm-prefs' >
2006-12-02 04:36:16 +00:00
< form method = 'post' action = '".e_SELF."' >
2012-11-26 14:41:32 -08:00
< table class = 'table adminform' >
2009-12-11 22:33:15 +00:00
< colgroup span = '2' >
< col class = 'col-label' />
< col class = 'col-control' />
</ colgroup >
< tbody >
2006-12-02 04:36:16 +00:00
< tr >
2009-12-11 22:33:15 +00:00
< td > " .ADLAN_PM_16. " </ td >
2013-03-05 14:57:29 +01:00
< td > " . $frm->text ('pm_option-title', $pm_prefs['title'] , '50'). " </ td >
2006-12-02 04:36:16 +00:00
</ tr >
2016-04-01 19:59:51 -07:00
< tr >
< td > " .ADLAN_PM_23. " </ td >
< td > " .e107::getUserClass()->uc_dropdown('pm_option-pm_class', $pm_prefs['pm_class'] , 'member,admin,classes'). " </ td >
</ tr >
< tr >
< td > " .ADLAN_PM_29. " </ td >
< td > " .e107::getUserClass()->uc_dropdown('pm_option-sendall_class', $pm_prefs['sendall_class'] , 'nobody,member,admin,classes'). " </ td >
</ tr >
< tr >
< td > User may send PMs to </ td >
< td > " ; //TODO LAN
$list = e107 :: getUserClass () -> getClassList ( 'nobody,main,admin,member,classes' );
$list [ 'matchclass' ] = " (Any user with the same class) " ; //TODO LAN
//$txt .= print_a($list,true);
$txt .= $frm -> select ( 'pm_option-send_to_class' , $list , varset ( $pm_prefs [ 'send_to_class' ], e_UC_MEMBER ));
//$text .= ".e107::getUserClass()->uc_dropdown('pm_option-sendall_class', $pm_prefs['sendall_class'], 'nobody,member,admin,classes')."</td>
$txt .= " </td>
</ tr >
2006-12-02 04:36:16 +00:00
< tr >
2009-12-11 22:33:15 +00:00
< td > " .ADLAN_PM_17. " </ td >
2013-03-05 14:57:29 +01:00
< td > " . $frm->radio_switch ('pm_option-animate', $pm_prefs['animate'] , LAN_YES, LAN_NO). " </ td >
2006-12-02 04:36:16 +00:00
</ tr >
< tr >
2009-12-11 22:33:15 +00:00
< td > " .ADLAN_PM_18. " </ td >
2013-03-05 14:57:29 +01:00
< td > " . $frm->radio_switch ('pm_option-dropdown', $pm_prefs['dropdown'] , LAN_YES, LAN_NO). " </ td >
2006-12-02 04:36:16 +00:00
</ tr >
< tr >
2009-12-11 22:33:15 +00:00
< td > " .ADLAN_PM_19. " </ td >
2013-03-05 14:57:29 +01:00
< td > " . $frm->text ('pm_option-read_timeout', $pm_prefs['read_timeout'] , '5', array('class' => 'tbox input-text')). " </ td >
2006-12-02 04:36:16 +00:00
</ tr >
< tr >
2009-12-11 22:33:15 +00:00
< td > " .ADLAN_PM_20. " </ td >
2013-03-05 14:57:29 +01:00
< td > " . $frm->text ('pm_option-unread_timeout', $pm_prefs['unread_timeout'] , '5', array('class' => 'tbox input-text')). " </ td >
2006-12-02 04:36:16 +00:00
</ tr >
< tr >
2009-12-11 22:33:15 +00:00
< td > " .ADLAN_PM_21. " </ td >
2013-03-05 14:57:29 +01:00
< td > " . $frm->radio_switch ('pm_option-popup', $pm_prefs['popup'] , LAN_YES, LAN_NO). " </ td >
2006-12-02 04:36:16 +00:00
</ tr >
< tr >
2009-12-11 22:33:15 +00:00
< td > " .ADLAN_PM_22. " </ td >
2016-04-01 19:59:51 -07:00
< td class = 'form-inline' > " . $frm->text ('pm_option-popup_delay', $pm_prefs['popup_delay'] , '5', array('class' => 'tbox input-text')). " " .ADLAN_PM_44. " </ td >
2006-12-02 04:36:16 +00:00
</ tr >
2016-04-01 19:59:51 -07:00
2006-12-02 04:36:16 +00:00
< tr >
2009-12-11 22:33:15 +00:00
< td > " .ADLAN_PM_24. " </ td >
2013-03-05 14:57:29 +01:00
< td > " . $frm->text ('pm_option-perpage', $pm_prefs['perpage'] , '5', array('class' => 'tbox input-text')). " </ td >
2006-12-02 04:36:16 +00:00
</ tr >
< tr >
2009-12-11 22:33:15 +00:00
< td > " .ADLAN_PM_25. " </ td >
2009-12-16 20:23:37 +00:00
< td > " .e107::getUserClass()->uc_dropdown('pm_option-notify_class', $pm_prefs['notify_class'] , 'nobody,member,admin,classes'). " </ td >
2006-12-02 04:36:16 +00:00
</ tr >
< tr >
2009-12-11 22:33:15 +00:00
< td > " .ADLAN_PM_26. " </ td >
2009-12-16 20:23:37 +00:00
< td > " .e107::getUserClass()->uc_dropdown('pm_option-receipt_class', $pm_prefs['receipt_class'] , 'nobody,member,admin,classes'). " </ td >
2006-12-02 04:36:16 +00:00
</ tr >
< tr >
2009-12-11 22:33:15 +00:00
< td > " .ADLAN_PM_27. " </ td >
2009-12-16 20:23:37 +00:00
< td > " .e107::getUserClass()->uc_dropdown('pm_option-attach_class', $pm_prefs['attach_class'] , 'nobody,member,admin,classes'). " </ td >
2006-12-02 04:36:16 +00:00
</ tr >
< tr >
2009-12-11 22:33:15 +00:00
< td > " .ADLAN_PM_28. " </ td >
2016-04-01 19:59:51 -07:00
< td class = 'form-inline' > " . $frm->text ('pm_option-attach_size', $pm_prefs['attach_size'] , '8', array('class' => 'tbox input-text')). " kB </ td >
2006-12-02 04:36:16 +00:00
</ tr >
2016-04-01 19:59:51 -07:00
2006-12-02 04:36:16 +00:00
< tr >
2009-12-11 22:33:15 +00:00
< td > " .ADLAN_PM_30. " </ td >
2009-12-16 20:23:37 +00:00
< td > " .e107::getUserClass()->uc_dropdown('pm_option-multi_class', $pm_prefs['multi_class'] , 'nobody,member,admin,classes'). " </ td >
2006-12-02 04:36:16 +00:00
</ tr >
< tr >
2009-12-11 22:33:15 +00:00
< td > " .ADLAN_PM_31. " </ td >
2009-12-16 20:23:37 +00:00
< td > " .e107::getUserClass()->uc_dropdown('pm_option-opt_userclass', $pm_prefs['opt_userclass'] , 'nobody,member,admin,classes'). " </ td >
2006-12-02 04:36:16 +00:00
</ tr >
2010-01-06 20:09:58 +00:00
< tr >
< td > " .ADLAN_PM_81. " </ td >
2016-04-01 19:59:51 -07:00
< td class = 'form-inline' > " . $frm->text ('pm_option-v', $pm_prefs['pm_max_send'] , '5', array('class' => 'tbox input-text')). " < span class = 'field-help' > " .ADLAN_PM_82. " </ span ></ td >
2010-01-06 20:09:58 +00:00
</ tr >
2009-12-11 22:33:15 +00:00
</ tbody >
2006-12-02 04:36:16 +00:00
</ table >
2012-11-26 14:41:32 -08:00
< div class = 'buttons-bar center' >
2013-02-02 20:01:53 +01:00
" . $frm->admin_button ('update_prefs','no-value','update', LAN_UPDATE). "
2012-11-26 14:41:32 -08:00
</ div >
2006-12-02 04:36:16 +00:00
</ form >
2009-12-11 22:33:15 +00:00
</ fieldset >
2006-12-02 04:36:16 +00:00
" ;
return $txt ;
}
2009-12-10 20:40:39 +00:00
2009-12-16 20:23:37 +00:00
function show_limits ( $pm_prefs )
2006-12-02 04:36:16 +00:00
{
2009-12-17 22:47:20 +00:00
$sql = e107 :: getDb ();
2012-11-26 14:41:32 -08:00
$frm = e107 :: getForm ();
2009-12-11 22:33:15 +00:00
2009-12-16 20:23:37 +00:00
if ( ! isset ( $pm_prefs [ 'pm_limits' ])) { $pm_prefs [ 'pm_limits' ] = 0 ; }
2009-12-11 22:33:15 +00:00
if ( $sql -> db_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' " ))
2006-12-02 04:36:16 +00:00
{
while ( $row = $sql -> db_Fetch ())
{
$limitList [ $row [ 'limit_classnum' ]] = $row ;
}
}
$txt = "
2009-12-11 22:33:15 +00:00
< fieldset id = 'plugin-pm-showlimits' >
2009-12-16 20:23:37 +00:00
< form method = 'post' action = '".e_SELF.' ? '.e_QUERY."' >
2012-11-26 14:41:32 -08:00
< table class = 'table adminform' >
< colgroup >
2009-12-11 22:33:15 +00:00
< col class = 'col-label' />
< col class = 'col-control' />
< col class = 'col-control' />
</ colgroup >
2012-11-26 14:41:32 -08:00
< thead >
< tr >
2016-04-03 15:02:25 -07:00
< th > " .LAN_USERCLASS. " </ th >
2012-11-26 14:41:32 -08:00
< th > " .ADLAN_PM_37. " </ th >
< th > " .ADLAN_PM_38. " </ th >
</ tr >
</ thead >
2009-12-11 22:33:15 +00:00
< tbody >
2006-12-02 04:36:16 +00:00
< tr >
2009-12-11 22:33:15 +00:00
< td colspan = '3' style = 'text-align:left' > " .ADLAN_PM_45. "
2006-12-02 04:36:16 +00:00
< select name = 'pm_limits' class = 'tbox' >
" ;
2009-12-16 20:23:37 +00:00
$sel = ( $pm_prefs [ 'pm_limits' ] == 0 ? " selected='selected' " : " " );
2006-12-02 04:36:16 +00:00
$txt .= " <option value='0' { $sel } > " . ADLAN_PM_33 . " </option> \n " ;
2009-12-16 20:23:37 +00:00
$sel = ( $pm_prefs [ 'pm_limits' ] == 1 ? " selected='selected' " : " " );
2006-12-02 04:36:16 +00:00
$txt .= " <option value='1' { $sel } > " . ADLAN_PM_34 . " </option> \n " ;
2009-12-16 20:23:37 +00:00
$sel = ( $pm_prefs [ 'pm_limits' ] == 2 ? " selected='selected' " : " " );
2006-12-02 04:36:16 +00:00
$txt .= " <option value='2' { $sel } > " . ADLAN_PM_35 . " </option> \n " ;
$txt .= " </select> \n " ;
2009-12-11 22:33:15 +00:00
$txt .= ' ' . ADLAN_PM_77 . "
2006-12-02 04:36:16 +00:00
</ td >
</ tr >
2012-11-26 14:41:32 -08:00
2006-12-02 04:36:16 +00:00
" ;
2009-12-11 22:33:15 +00:00
if ( isset ( $limitList ))
2013-02-02 20:01:53 +01:00
{
2006-12-02 04:36:16 +00:00
foreach ( $limitList as $row )
{
$txt .= "
< tr >
2009-12-16 20:23:37 +00:00
< td > " .e107::getUserClass()->uc_get_classname( $row['limit_classnum'] ). " </ td >
2009-12-11 22:33:15 +00:00
< td >
2016-04-03 15:02:25 -07:00
" .LAN_PLUGIN_PM_INBOX. " : < input type = 'text' class = 'tbox' size = '5' name = 'inbox_count[{$row[' limit_id ']}]' value = '{$row[' inbox_count ']}' /> < br />
" .LAN_PLUGIN_PM_OUTBOX. " : < input type = 'text' class = 'tbox' size = '5' name = 'outbox_count[{$row[' limit_id ']}]' value = '{$row[' outbox_count ']}' />
2006-12-02 04:36:16 +00:00
</ td >
2009-12-11 22:33:15 +00:00
< td >
2016-04-03 15:02:25 -07:00
" .LAN_PLUGIN_PM_INBOX. " : < input type = 'text' class = 'tbox' size = '5' name = 'inbox_size[{$row[' limit_id ']}]' value = '{$row[' inbox_size ']}' /> < br />
" .LAN_PLUGIN_PM_OUTBOX. " : < input type = 'text' class = 'tbox' size = '5' name = 'outbox_size[{$row[' limit_id ']}]' value = '{$row[' outbox_size ']}' />
2006-12-02 04:36:16 +00:00
</ td >
</ tr >
" ;
}
2009-12-11 22:33:15 +00:00
}
else
{
2006-12-02 04:36:16 +00:00
$txt .= "
< tr >
2009-12-11 22:33:15 +00:00
< td colspan = '3' style = 'text-align: center' > " .ADLAN_PM_41. " </ td >
2006-12-02 04:36:16 +00:00
</ tr >
" ;
}
2009-12-11 22:33:15 +00:00
$txt .= '
</ tbody >
</ table >
2012-11-26 14:41:32 -08:00
< div class = " buttons-bar center " >
2013-02-02 20:01:53 +01:00
'.$frm->admin_button(' updatelimits ',' no - value ',' update ', LAN_UPDATE).'
2012-11-26 14:41:32 -08:00
</ div >
2009-12-11 22:33:15 +00:00
</ form >
</ fieldset > ' ;
2006-12-02 04:36:16 +00:00
return $txt ;
}
2009-12-11 22:33:15 +00:00
2009-12-16 20:23:37 +00:00
function add_limit ( $pm_prefs )
2006-12-02 04:36:16 +00:00
{
2009-12-17 22:47:20 +00:00
$sql = e107 :: getDb ();
2012-11-26 14:41:32 -08:00
$frm = e107 :: getForm ();
2009-12-16 20:23:37 +00:00
if ( $sql -> db_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' " ))
2006-12-02 04:36:16 +00:00
{
while ( $row = $sql -> db_Fetch ())
{
$limitList [ $row [ 'limit_classnum' ]] = $row ;
}
}
$txt = "
2009-12-11 22:33:15 +00:00
< fieldset id = 'plugin-pm-addlimit' >
2009-12-16 20:23:37 +00:00
< form method = 'post' action = '".e_SELF.' ? '.e_QUERY."' >
2012-11-26 14:41:32 -08:00
< table class = 'table adminform' >
< colgroup >
2009-12-11 22:33:15 +00:00
< col class = 'col-label' />
< col class = 'col-control' />
< col class = 'col-control' />
</ colgroup >
2012-11-26 14:41:32 -08:00
< thead >
2006-12-02 04:36:16 +00:00
< tr >
2016-04-03 15:02:25 -07:00
< th > " .LAN_USERCLASS. " </ th >
2009-12-11 22:33:15 +00:00
< th > " .ADLAN_PM_37. " </ th >
< th > " .ADLAN_PM_38. " </ th >
2012-11-26 14:41:32 -08:00
</ tr >
</ thead >
< tbody >
2006-12-02 04:36:16 +00:00
" ;
$txt .= "
< tr >
2009-12-16 20:23:37 +00:00
< td > " .e107::getUserClass()->uc_dropdown('newlimit_class', 0, 'guest,member,admin,classes'). " </ td >
2009-12-11 22:33:15 +00:00
< td >
2016-04-03 15:02:25 -07:00
" .LAN_PLUGIN_PM_INBOX. " : < input type = 'text' class = 'tbox' size = '5' name = 'new_inbox_count' value = '' /> < br />
" .LAN_PLUGIN_PM_OUTBOX. " : < input type = 'text' class = 'tbox' size = '5' name = 'new_outbox_count' value = '' />
2006-12-02 04:36:16 +00:00
</ td >
2009-12-11 22:33:15 +00:00
< td >
2016-04-03 15:02:25 -07:00
" .LAN_PLUGIN_PM_INBOX. " : < input type = 'text' class = 'tbox' size = '5' name = 'new_inbox_size' value = '' /> < br />
" .LAN_PLUGIN_PM_OUTBOX. " : < input type = 'text' class = 'tbox' size = '5' name = 'new_outbox_size' value = '' />
2006-12-02 04:36:16 +00:00
</ td >
</ tr >
2012-11-26 14:41:32 -08:00
2006-12-02 04:36:16 +00:00
" ;
2009-12-11 22:33:15 +00:00
$txt .= '
</ tbody >
</ table >
2012-11-26 14:41:32 -08:00
< div class = " buttons-bar center " >
2013-02-02 20:01:53 +01:00
'.$frm->admin_button(' addlimit ',' no - value ',' update ', LAN_ADD).'
2012-11-26 14:41:32 -08:00
</ div >
2009-12-11 22:33:15 +00:00
</ form >
</ fieldset > ' ;
2006-12-02 04:36:16 +00:00
return $txt ;
}
2009-12-11 22:33:15 +00:00
function show_maint ( $pmPrefs )
{
2013-03-05 14:57:29 +01:00
$frm = e107 :: getForm ();
2009-12-11 22:33:15 +00:00
$txt = "
< fieldset id = 'plugin-pm-maint' >
< legend > " .ADLAN_PM_62. " </ legend >
< form method = 'post' action = '".e_SELF."?maint' >
2012-11-26 14:41:32 -08:00
< table class = 'table adminform' >
< colgroup >
2009-12-11 22:33:15 +00:00
< col class = 'col-label' />
< col class = 'col-control' />
</ colgroup >
< tbody >
< tr >
< td > " .ADLAN_PM_63. " </ td >
2013-03-05 14:57:29 +01:00
< td > " . $frm->radio_switch ('pm_maint_sent', '', LAN_YES, LAN_NO). " </ td >
2009-12-11 22:33:15 +00:00
</ tr >
< tr >
< td > " .ADLAN_PM_64. " </ td >
2013-03-05 14:57:29 +01:00
< td > " . $frm->radio_switch ('pm_maint_rec', '', LAN_YES, LAN_NO). " </ td >
2009-12-11 22:33:15 +00:00
</ tr >
< tr >
< td > " .ADLAN_PM_65. " </ td >
2013-03-05 14:57:29 +01:00
< td > " . $frm->radio_switch ('pm_maint_blocked', '', LAN_YES, LAN_NO). " </ td >
2009-12-13 12:32:29 +00:00
</ tr >
" ;
2009-12-11 22:33:15 +00:00
if ( $pmPrefs [ 'read_timeout' ] || $pmPrefs [ 'unread_timeout' ])
{
$txt .= "
< tr >
< td > " .ADLAN_PM_71. " </ td >
2013-03-05 14:57:29 +01:00
< td > " . $frm->radio_switch ('pm_maint_expired', '', LAN_YES, LAN_NO). " </ td >
2009-12-11 22:33:15 +00:00
</ tr > " ;
}
$txt .= "
2009-12-13 12:32:29 +00:00
< tr >
< td > " .ADLAN_PM_78. " </ td >
2013-03-05 14:57:29 +01:00
< td > " . $frm->radio_switch ('pm_maint_attach', '', LAN_YES, LAN_NO). " </ td >
2009-12-13 12:32:29 +00:00
</ tr >
2009-12-11 22:33:15 +00:00
</ tbody >
</ table >
2012-11-26 14:41:32 -08:00
< div class = 'buttons-bar center' >
2013-03-05 14:57:29 +01:00
" . $frm->admin_button ('pm_maint_execute','no-value','delete', LAN_GO). "
2012-11-26 14:41:32 -08:00
</ div >
2009-12-11 22:33:15 +00:00
</ form >
</ fieldset >
" ;
return $txt ;
}
/**
* Turn the array produced by doMaint for message display into an array of log strings .
* Data is sorted into time stamp order
*
* @ param array $results - array of arrays as returned from doMaint ()
* @ param array | boolean $extra - optional additional information which is sorted into the main result according to keys - so use low numbers
* to make the entry appear at the beginning , and text strings to add to the end .
*/
function makeLogEntry ( $results , $extra = FALSE )
{
$logPrefixes = array ( E_MESSAGE_SUCCESS => 'Pass - ' , E_MESSAGE_ERROR => 'Fail - ' , E_MESSAGE_INFO => 'Info - ' , E_MESSAGE_DEBUG => 'Debug - ' );
$res = array ();
foreach ( $results as $k => $ma )
{
foreach ( $ma as $ts => $m )
{
$res [ $ts ] = $logPrefixes [ $k ] . $m ;
}
}
if ( is_array ( $extra ))
{
$res = array_merge ( $res , $extra );
}
ksort ( $res ); // Sort in ascending order of timestamp
return $res ;
}
/**
* Do PM DB maintenance
* @ param array $opts of tasks key = sent | rec | blocked | expired ( one or more present ) . ATM value not used
* @ 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 )
*/
function doMaint ( $opts , $pmPrefs )
{
if ( ! count ( $opts ))
{
return array ( E_MESSAGE_ERROR => array ( ADLAN_PM_66 ));
}
2009-12-16 20:23:37 +00:00
$results = array ( E_MESSAGE_INFO => array ( ADLAN_PM_67 )); // 'Maintenance started' - primarily for a log entry to mark start time
2009-12-11 22:33:15 +00:00
$logResults = array ();
$e107 = e107 :: getInstance ();
$e107 -> admin_log -> log_event ( 'PM_ADM_04' , implode ( ', ' , array_keys ( $opts )));
2009-12-17 22:47:20 +00:00
$pmHandler = new private_message ( $pmPrefs );
2009-12-11 22:33:15 +00:00
$db2 = new db (); // Will usually need a second DB object to avoid over load
$start = 0 ; // Use to ensure we get different log times
2009-12-13 12:32:29 +00:00
2009-12-11 22:33:15 +00:00
if ( isset ( $opts [ 'sent' ])) // Want pm_from = deleted user and pm_read_del = 1
{
$cnt = 0 ;
2013-08-31 17:11:34 +02:00
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`
2009-12-11 22:33:15 +00:00
WHERE ( pm . `pm_read_del = 1) AND ` #user`.`user_id` IS NULL"))
{
2016-02-14 12:15:55 -08:00
while ( $row = $db2 -> fetch ())
2009-12-11 22:33:15 +00:00
{
if ( $pmHandler -> del ( $row [ 'pm_id' ]) !== FALSE )
{
$cnt ++ ;
}
}
}
$start = time ();
$results [ E_MESSAGE_SUCCESS ][ $start ] = str_replace ( '--COUNT--' , $cnt , ADLAN_PM_74 );
}
if ( isset ( $opts [ 'rec' ])) // Want pm_to = deleted user and pm_sent_del = 1
{
$cnt = 0 ;
2013-08-31 17:11:34 +02:00
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`
2009-12-11 22:33:15 +00:00
WHERE ( pm . `pm_sent_del = 1) AND ` #user`.`user_id` IS NULL"))
{
2016-02-14 12:15:55 -08:00
while ( $row = $db2 -> fetch ())
2009-12-11 22:33:15 +00:00
{
if ( $pmHandler -> del ( $row [ 'pm_id' ]) !== FALSE )
{
$cnt ++ ;
}
}
}
2009-12-13 12:32:29 +00:00
$start = max ( $start + 1 , time ());
2009-12-11 22:33:15 +00:00
$results [ E_MESSAGE_SUCCESS ][ $start ] = str_replace ( '--COUNT--' , $cnt , ADLAN_PM_75 );
}
if ( isset ( $opts [ 'blocked' ]))
{
2013-08-31 17:11:34 +02:00
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`
2009-12-11 22:33:15 +00:00
WHERE `#user` . `user_id` IS NULL " ))
{
2009-12-13 12:32:29 +00:00
$start = max ( $start + 1 , time ());
2009-12-11 22:33:15 +00:00
$results [ E_MESSAGE_ERROR ][ $start ] = str_replace ( array ( '--NUM--' , '--TEXT--' ), array ( $this -> sql -> getLastErrorNum , $this -> sql -> getLastErrorText ), ADLAN_PM_70 );
}
else
{
2009-12-13 12:32:29 +00:00
$start = max ( $start + 1 , time ());
2009-12-11 22:33:15 +00:00
$results [ E_MESSAGE_SUCCESS ][ $start ] = str_replace ( '--COUNT--' , $res , ADLAN_PM_69 );
}
2013-08-31 17:11:34 +02:00
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`
2009-12-11 22:33:15 +00:00
WHERE `#user` . `user_id` IS NULL " ))
{
2009-12-13 12:32:29 +00:00
$start = max ( $start + 1 , time ());
2009-12-11 22:33:15 +00:00
$results [ E_MESSAGE_ERROR ][ $start ] = str_replace ( array ( '--NUM--' , '--TEXT--' ), array ( $this -> sql -> getLastErrorNum , $this -> sql -> getLastErrorText ), ADLAN_PM_70 );
}
else
{
2009-12-13 12:32:29 +00:00
$start = max ( $start + 1 , time ());
2009-12-11 22:33:15 +00:00
$results [ E_MESSAGE_SUCCESS ][ $start ] = str_replace ( '--COUNT--' , $res , ADLAN_PM_68 );
}
}
2009-12-13 12:32:29 +00:00
2009-12-11 22:33:15 +00:00
if ( isset ( $opts [ 'expired' ]))
{
$del_qry = array ();
$read_timeout = intval ( $pmPrefs [ 'read_timeout' ]);
$unread_timeout = intval ( $pmPrefs [ 'unread_timeout' ]);
if ( $read_timeout > 0 )
{
$timeout = time () - ( $read_timeout * 86400 );
$del_qry [] = " (pm_sent < { $timeout } AND pm_read > 0) " ;
}
if ( $unread_timeout > 0 )
{
$timeout = time () - ( $unread_timeout * 86400 );
$del_qry [] = " (pm_sent < { $timeout } AND pm_read = 0) " ;
}
if ( count ( $del_qry ) > 0 )
{
$qry = implode ( ' OR ' , $del_qry );
$cnt = 0 ;
if ( $db2 -> db_Select ( 'private_msg' , 'pm_id' , $qry ))
{
2016-02-14 12:15:55 -08:00
while ( $row = $db2 -> db_Fetch ())
2009-12-11 22:33:15 +00:00
{
if ( $pmHandler -> del ( $row [ 'pm_id' ]) !== FALSE )
{
$cnt ++ ;
}
}
}
2009-12-13 12:32:29 +00:00
$start = max ( $start + 1 , time ());
2009-12-11 22:33:15 +00:00
$results [ E_MESSAGE_SUCCESS ][ $start ] = str_replace ( '--COUNT--' , $cnt , ADLAN_PM_73 );
}
else
{
2009-12-13 12:32:29 +00:00
$start = max ( $start + 1 , time ());
2009-12-11 22:33:15 +00:00
$results [ E_MESSAGE_ERROR ][ $start ] = ADLAN_PM_72 ;
}
}
2009-12-13 12:32:29 +00:00
if ( isset ( $opts [ 'attach' ]))
{ // Check for orphaned and missing attachments
require_once ( e_HANDLER . 'file_class.php' );
$fl = new e_file ();
$missing = array ();
$orphans = array ();
$fileArray = $fl -> get_files ( e_PLUGIN . 'pm/attachments' );
2013-08-31 17:11:34 +02:00
if ( $db2 -> select ( 'private_msg' , 'pm_id, pm_attachments' , " pm_attachments != '' " ))
2009-12-13 12:32:29 +00:00
{
2016-02-14 12:15:55 -08:00
while ( $row = $db2 -> fetch ())
2009-12-13 12:32:29 +00:00
{
$attachList = explode ( chr ( 0 ), $row [ 'pm_attachments' ]);
foreach ( $attachList as $a )
{
$found = FALSE ;
foreach ( $fileArray as $k => $fd )
{
if ( $fd [ 'fname' ] == $a )
{
$found = TRUE ;
unset ( $fileArray [ $k ]);
break ;
}
}
if ( ! $found )
{
$missing [] = $row [ 'pm_id' ] . ':' . $a ;
}
}
}
}
// Any files left in $fileArray now are unused
if ( count ( $fileArray ))
{
foreach ( $fileArray as $k => $fd )
{
unlink ( $fd [ 'path' ] . $fd [ 'fname' ]);
$orphans [] = $fd [ 'fname' ];
}
}
$attachMessage = str_replace ( array ( '--ORPHANS--' , '--MISSING--' ), array ( count ( $orphans ), count ( $missing )), ADLAN_PM_79 );
if ( TRUE )
{ // Mostly for testing - probably disable this
if ( count ( $orphans ))
{
$attachMessage .= '[!br!]Orphans:[!br!]' . implode ( '[!br!]' , $orphans );
}
if ( count ( $missing ))
{
$attachMessage .= '[!br!]Missing:[!br!]' . implode ( '[!br!]' , $missing );
}
}
$start = max ( $start + 1 , time ());
$results [ E_MESSAGE_SUCCESS ][ $start ] = $attachMessage ;
}
2009-12-11 22:33:15 +00:00
$e107 -> admin_log -> logArrayAll ( 'PM_ADM_03' , makeLogEntry ( $results ));
2009-12-16 20:23:37 +00:00
foreach ( $results as $k => $r )
{
foreach ( $r as $sk => $s )
{
$results [ $k ][ $sk ] = str_replace ( '[!br!]' , '<br />' , $s );
}
}
2009-12-11 22:33:15 +00:00
return $results ;
}
2009-12-17 22:47:20 +00:00
function pm_conf_adminmenu ()
2006-12-02 04:36:16 +00:00
{
2009-12-17 22:47:20 +00:00
global $action ;
2012-11-26 14:41:32 -08:00
2009-12-11 22:33:15 +00:00
if ( $action == '' ) { $action = 'main' ; }
2006-12-02 04:36:16 +00:00
$var [ 'main' ][ 'text' ] = ADLAN_PM_54 ;
$var [ 'main' ][ 'link' ] = e_SELF ;
2009-12-11 22:33:15 +00:00
2006-12-02 04:36:16 +00:00
$var [ 'limits' ][ 'text' ] = ADLAN_PM_55 ;
2009-12-11 22:33:15 +00:00
$var [ 'limits' ][ 'link' ] = e_SELF . '?limits' ;
$var [ 'maint' ][ 'text' ] = ADLAN_PM_59 ;
$var [ 'maint' ][ 'link' ] = e_SELF . '?maint' ;
2006-12-02 04:36:16 +00:00
show_admin_menu ( ADLAN_PM_12 , $action , $var );
}
2012-11-26 14:41:32 -08:00
?>