2006-12-02 04:36:16 +00:00
< ? php
/*
2009-11-12 14:30:07 +00:00
* e107 website system
*
2013-02-20 21:11:17 +00:00
* Copyright ( C ) 2008 - 2013 e107 Inc ( e107 . org )
2009-11-12 14:30:07 +00:00
* Released under the terms and conditions of the
* GNU General Public License ( http :// www . gnu . org / licenses / gpl . txt )
*
*/
2021-01-16 13:32:35 -08:00
require_once ( __DIR__ . '/../class2.php' );
2017-01-17 01:33:03 +01:00
2008-12-07 12:00:13 +00:00
if ( ! getperms ( 'O' ))
{
2016-01-13 19:17:37 -08:00
e107 :: redirect ( 'admin' );
2006-12-02 04:36:16 +00:00
exit ;
}
2017-01-17 01:33:03 +01:00
e107 :: coreLan ( 'notify' , true );
2022-12-13 18:23:48 -08:00
e107 :: library ( " load " , " animate.css " );
e107 :: js ( 'footer-inline' , "
2016-11-08 10:00:33 -08:00
2022-12-13 18:23:48 -08:00
$ ( 'select' ) . on ( 'change' , function ()
{
var valueSelected = this . value ;
valueSelected = valueSelected . replace ( '::' , '_' );
var id = $ ( this ) . attr ( 'id' );
var targetid = '#' + id + '-' + valueSelected ;
var disp = '.' + id + '-disp' ;
$ ( disp ) . hide ();
$ ( targetid ) . show ();
2022-04-20 09:54:48 -07:00
2022-12-13 18:23:48 -08:00
});
2022-04-20 09:54:48 -07:00
2022-12-13 18:23:48 -08:00
" );
2022-04-20 09:54:48 -07:00
2016-11-08 10:00:33 -08:00
class plugin_notify_admin extends e_admin_dispatcher
{
protected $modes = array (
'main' => array ( 'controller' => 'plugin_notify_admin_ui' ,
'path' => null ,
'ui' => 'plugin_notify_admin_form_ui' , 'uipath' => null )
);
protected $adminMenu = array (
2022-12-13 18:23:48 -08:00
'main/config' => array ( 'caption' => LAN_PREFS , 'perm' => '0' ),
2017-02-01 18:25:32 -08:00
// 'main/push' => array('caption'=> "Push (experimental)", 'perm' => '0')
2016-11-08 10:00:33 -08:00
);
protected $adminMenuAliases = array (
'main/edit' => 'main/list'
);
2017-02-01 18:25:32 -08:00
protected $adminMenuIcon = 'e-notify-24' ;
2016-11-08 10:00:33 -08:00
/**
* Navigation menu title
* @ var string
*/
protected $menuTitle = NT_LAN_1 ;
function init ()
{
if ( e_DEBUG !== true )
{
unset ( $this -> adminMenu [ 'main/push' ]);
}
}
}
class plugin_notify_admin_ui extends e_admin_ui
{
protected $pluginTitle = NT_LAN_1 ;
protected $pluginName = 'core' ;
protected $table = " " ;
protected $listQry = " " ;
protected $pid = " notify_id " ;
protected $perPage = 20 ;
protected $batchDelete = true ;
// protected $displaySettings = array();
// protected $disallowPages = array('main/create', 'main/prefs');
protected $fields = array ();
//required - default column user prefs
protected $fieldpref = array ();
// optional, if $pluginName == 'core', core prefs will be used, else e107::getPluginConfig($pluginName);
protected $prefs = array (
/* 'pref_type' => array ( 'title' => 'type' , 'type' => 'text' , 'data' => 'string' , 'validate' => true ),
'pref_folder' => array ( 'title' => 'folder' , 'type' => 'boolean' , 'data' => 'integer' ),
'pref_name' => array ( 'title' => 'name' , 'type' => 'text' , 'data' => 'string' , 'validate' => 'regex' , 'rule' => '#^[\w]+$#i' , 'help' => 'allowed characters are a-zA-Z and underscore' ) */
);
2022-12-13 18:23:48 -08:00
private $notify_prefs = [];
2016-11-08 10:00:33 -08:00
var $changeList = array ();
var $pluginConfig = array ();
function init ()
{
2022-12-13 18:23:48 -08:00
$pref = e107 :: getPref ();
$this -> notify_prefs = e107 :: getConfig ( 'notify' ) -> getPref ();
$this -> prefCleanup ();
$this -> test ();
2016-11-08 10:00:33 -08:00
if ( ! empty ( $_POST [ 'update' ]))
{
2022-12-13 18:23:48 -08:00
if ( $this -> update () === null )
2016-11-08 10:00:33 -08:00
{
2022-12-13 18:23:48 -08:00
e107 :: getMessage () -> addInfo ( LAN_NO_CHANGE );
2016-11-08 10:00:33 -08:00
}
}
$recalibrate = FALSE ;
// load every e_notify.php file.
2021-01-16 13:32:35 -08:00
if ( ! empty ( $pref [ 'e_notify_list' ]))
2016-11-08 10:00:33 -08:00
{
2022-12-13 18:23:48 -08:00
$config_events = array ();
2016-11-08 10:00:33 -08:00
foreach ( $pref [ 'e_notify_list' ] as $val ) // List of available e_notify.php files.
{
2022-12-13 18:23:48 -08:00
$config_category = '' ;
2016-11-08 10:00:33 -08:00
// if (!isset($this->notify_prefs['plugins'][$val]))
{
$this -> notify_prefs [ 'plugins' ][ $val ] = TRUE ;
if ( is_readable ( e_PLUGIN . $val . " /e_notify.php " ))
{
require_once ( e_PLUGIN . $val . '/e_notify.php' );
if ( class_exists ( $val . " _notify " )) // new v2.x
{
2022-12-13 18:23:48 -08:00
$legacy = 0 ; // New.
2016-11-08 10:00:33 -08:00
$config_events = array ();
2022-12-13 18:23:48 -08:00
if ( $data = e107 :: callMethod ( $val . " _notify " , 'config' ))
{
2016-11-08 10:00:33 -08:00
2022-12-13 18:23:48 -08:00
$config_category = str_replace ( " _menu " , " " , ucfirst ( $val )) . " " . LAN_NOTIFY_01 ;
2016-11-08 10:00:33 -08:00
2022-12-13 18:23:48 -08:00
foreach ( $data as $v )
{
$func = $v [ 'function' ];
$config_events [ $func ] = $v [ 'name' ];
}
2016-11-08 10:00:33 -08:00
}
2022-12-13 18:23:48 -08:00
$routers = e107 :: callMethod ( $val . " _notify " , 'router' );
2016-11-08 10:00:33 -08:00
}
else
{
$legacy = 1 ; // Legacy Mode.
2022-12-13 18:23:48 -08:00
$routers = [];
2022-04-20 09:54:48 -07:00
// $config_category = 'Other';
// $config_events = array();
2016-11-08 10:00:33 -08:00
}
// foreach ($config_events as $event_id => $event_text)
// {
// $this -> notify_prefs['event'][$event_id] = array('class' => '255', 'email' => '', 'plugin'=> $val);
// }
2022-12-13 18:23:48 -08:00
$this -> pluginConfig [ $val ] = array ( 'category' => $config_category , 'events' => $config_events , 'legacy' => $legacy , 'routers' => $routers );
2016-11-08 10:00:33 -08:00
$recalibrate = true ;
}
}
}
2022-12-13 18:23:48 -08:00
2016-11-08 10:00:33 -08:00
}
// print_a($this->pluginConfig);
2020-12-18 19:55:12 -08:00
// if ($recalibrate)
// {
2016-11-08 10:00:33 -08:00
// $s_prefs = $tp -> toDB($this -> notify_prefs);
// $s_prefs = $eArrayStorage -> WriteArray($s_prefs);
// $sql -> db_Update("core", "e107_value='".$s_prefs."' WHERE e107_name='notify_prefs'");
2020-12-18 19:55:12 -08:00
// }
2016-11-08 10:00:33 -08:00
}
function prefCleanup ()
{
$oldPrefs = e107 :: getEvent () -> oldCoreList ();
$curData = $this -> notify_prefs [ 'event' ];
foreach ( $curData as $k => $v )
{
if ( isset ( $oldPrefs [ $k ]))
{
$newKey = $oldPrefs [ $k ];
$this -> notify_prefs [ 'event' ][ $newKey ] = $v ;
unset ( $this -> notify_prefs [ 'event' ][ $k ]);
}
}
}
function test ()
{
if ( ! empty ( $_POST [ 'test' ]))
{
$id = key ( $_POST [ 'test' ]);
2022-12-14 14:26:08 -08:00
$exampleData = array ( 'message' => 'Test for ' . $id , 'data' => 'example data' );
2016-11-08 10:00:33 -08:00
e107 :: getMessage () -> addSuccess ( 'Triggering: ' . $id );
e107 :: getEvent () -> trigger ( $id , $exampleData );
}
}
function configPage ()
{
//global $ns, $rs, $frm, $emessage;
$ns = e107 :: getRender ();
$frm = e107 :: getForm ();
$mes = e107 :: getMessage ();
$events = e107 :: getEvent () -> coreList ();
$tab = array ();
foreach ( $events as $k => $cat )
{
$text = " <table class='table adminform'>
< colgroup >
2022-12-13 18:23:48 -08:00
< col class = 'col-label' /> " ;
$text .= deftrue ( 'e_DEBUG' ) ? " <col class='col-control' /> " : '' ;
$text .= " <col style='width:50%' />
2016-11-08 10:00:33 -08:00
</ colgroup > " ;
foreach ( $cat as $c => $ev )
{
$text .= $this -> render_event ( $c , $ev );
}
$text .= " </table> " ;
$caption = str_replace ( " _menu " , " " , ucfirst ( $k )) . " " . LAN_NOTIFY_01 ;
$tab [] = array ( 'caption' => $caption , 'text' => $text );
}
if ( ! empty ( $this -> notify_prefs [ 'plugins' ]))
{
foreach ( $this -> notify_prefs [ 'plugins' ] as $plugin_id => $plugin_settings )
{
if ( is_readable ( e_PLUGIN . $plugin_id . '/e_notify.php' ))
{
2020-12-31 09:06:20 -08:00
$config_category = varset ( $this -> pluginConfig [ $plugin_id ][ 'category' ]);
$legacy = varset ( $this -> pluginConfig [ $plugin_id ][ 'legacy' ]);
2016-11-08 10:00:33 -08:00
$text = " <table class='table adminform'>
< colgroup >
< col class = 'col-label' />
< col class = 'col-control' />
</ colgroup > " ;
2022-04-20 09:54:48 -07:00
2016-11-08 10:00:33 -08:00
2020-12-31 09:06:20 -08:00
if ( ! empty ( $this -> pluginConfig [ $plugin_id ][ 'events' ]))
2016-11-08 10:00:33 -08:00
{
2020-12-31 09:06:20 -08:00
foreach ( $this -> pluginConfig [ $plugin_id ][ 'events' ] as $event_id => $event_text )
{
$text .= $this -> render_event ( $event_id , $event_text , $plugin_id , $legacy );
}
2016-11-08 10:00:33 -08:00
}
$text .= " </table> \n " ;
2022-12-13 18:23:48 -08:00
if ( ! empty ( $config_category ))
{
$tab [] = array ( 'caption' => $config_category , 'text' => $text );
}
2016-11-08 10:00:33 -08:00
}
}
}
$text2 = $frm -> open ( 'scanform' , 'post' , e_REQUEST_URL ); // <form action='".e_SELF."?results' method='post' id='scanform'>
$text2 .= $frm -> tabs ( $tab );
$text2 .= " <div class='buttons-bar center'> " . $frm -> admin_button ( 'update' , LAN_UPDATE , 'update' ) . " </div> " ;
$text2 .= $frm -> close ();
return $text2 ;
}
2022-12-13 18:23:48 -08:00
private function render_event ( $id , $description , $include = '' , $legacy = 0 )
2016-11-08 10:00:33 -08:00
{
$tp = e107 :: getParser ();
$frm = e107 :: getForm ();
$uc = e107 :: getUserClass ();
2022-12-13 18:23:48 -08:00
$uc -> fixed_classes [ 'email' ] = LAN_EMAIL . ' »' ;
2016-11-08 10:00:33 -08:00
$uc -> text_class_link [ 'email' ] = 'email' ;
2022-12-13 18:23:48 -08:00
$ucDropList = [ 'nobody' , 'main' , 'admin' , 'member' , 'classes' , 'email' ];
$inputs = '' ;
foreach ( $this -> pluginConfig as $plg => $cfg )
{
if ( ! empty ( $cfg [ 'routers' ]))
{
foreach ( $cfg [ 'routers' ] as $key => $route )
{
$k = $plg . '::' . $key ;
$containerId = 'event-' . $id . '-' . $plg . '_' . $key ;
$disp = ( varset ( $this -> notify_prefs [ 'event' ][ $id ][ 'class' ]) == $k ) ? 'display:visible' : 'display:none' ;
$inputs .= " <span id=' $containerId ' class='animated fadeIn event- " . $id . " -disp' style=' $disp '> " ;
$inputs .= e107 :: callMethod ( $plg . '_notify' , $route [ 'field' ], " event[ " . $id . " ][ " . $k . " ] " , varset ( $this -> notify_prefs [ 'event' ][ $id ][ 'recipient' ]));
$inputs .= " </span> " ;
$uc -> fixed_classes [ $k ] = $route [ 'label' ] . ' »' ;
$uc -> text_class_link [ $k ] = $k ;
$ucDropList [] = $k ;
}
}
}
2016-11-08 10:00:33 -08:00
if ( defined ( $description ))
{
$description = constant ( $description );
}
$highlight = varset ( $_GET [ 'type' ]) == $id ? " class='text-warning' " : '' ;
$text = "
< tr >
2022-04-20 09:54:48 -07:00
< td title = '".$id."' >< span " . $highlight . " > " . $description . " :</ span ></ td > " ;
2016-11-08 10:00:33 -08:00
2022-12-13 18:23:48 -08:00
if ( deftrue ( 'e_DEBUG' ))
2016-11-08 10:00:33 -08:00
{
$text .= " <td> " . $id . " </td> " ;
}
$text .= "
< td class = 'form-inline nowrap' >
2022-12-13 18:23:48 -08:00
" . $uc->uc_dropdown ('event['. $id .'][class]', varset( $this->notify_prefs ['event'][ $id ]['class'], e_UC_NOBODY), implode(',', $ucDropList ),['id'=>'event-'. $id ] /* " onchange = \ " mail_field(this.value,'event_ " . $id . " '); \" " */ );
2016-11-08 10:00:33 -08:00
2020-12-31 09:06:20 -08:00
if ( varset ( $this -> notify_prefs [ 'event' ][ $id ][ 'class' ]) == 'email' )
2016-11-08 10:00:33 -08:00
{
$disp = 'display:visible' ;
2020-12-31 09:06:20 -08:00
$value = $tp -> toForm ( varset ( $this -> notify_prefs [ 'event' ][ $id ][ 'email' ]));
2016-11-08 10:00:33 -08:00
}
else
{
$disp = " display:none " ;
$value = " " ;
}
2022-12-13 18:23:48 -08:00
$text .= " <input class='form-control animated fadeIn input-large event- " . $id . " -disp' type='text' style=' $disp ' class='tbox' id='event- " . $id . " -email' name='event[ " . $id . " ][email]' value= \" " . $value . " \" placeholder='eg. your@email.com' /> \n " ;
$text .= $inputs ;
2016-11-08 10:00:33 -08:00
$text .= $frm -> hidden ( " event[ " . $id . " ][include] " , $include );
$text .= $frm -> hidden ( " event[ " . $id . " ][legacy] " , $legacy ); // function or method
if ( isset ( $this -> notify_prefs [ 'event' ][ $id ][ 'class' ]) && $this -> notify_prefs [ 'event' ][ $id ][ 'class' ] != e_UC_NOBODY )
{
2017-02-13 07:37:41 +01:00
$text .= $frm -> button ( 'test[' . $id . ']' , $id , 'confirm' , LAN_TEST );
2016-11-08 10:00:33 -08:00
}
2022-12-13 18:23:48 -08:00
$text .= " </td>
2016-11-08 10:00:33 -08:00
</ tr > " ;
2022-12-13 18:23:48 -08:00
2016-11-08 10:00:33 -08:00
return $text ;
}
2022-12-13 18:23:48 -08:00
private function update ()
2016-11-08 10:00:33 -08:00
{
$this -> changeList = array ();
2022-12-13 18:23:48 -08:00
$modified = [];
2016-11-08 10:00:33 -08:00
foreach ( $_POST [ 'event' ] as $key => $value )
{
2022-12-13 18:23:48 -08:00
unset ( $this -> notify_prefs [ 'event' ][ $key ][ 'plugin' ]); // BC Cleanup
unset ( $this -> notify_prefs [ 'event' ][ $key ][ 'type' ]); // BC Cleanup
if ( $res = $this -> update_event ( $key ))
2016-11-08 10:00:33 -08:00
{
2022-12-13 18:23:48 -08:00
$this -> notify_prefs [ 'event' ][ $key ] = $res ;
e107 :: getMessage () -> addDebug ( " Modified: " . print_a ( $res , true ));
$modified [] = $res ;
2016-11-08 10:00:33 -08:00
}
}
2022-12-13 18:23:48 -08:00
if ( empty ( $modified ))
2016-11-08 10:00:33 -08:00
{
2022-12-13 18:23:48 -08:00
return null ;
2016-11-08 10:00:33 -08:00
}
2022-12-13 18:23:48 -08:00
return e107 :: getConfig ( 'notify' ) -> updatePref ( $this -> notify_prefs ) -> save ( true , true , true );
2016-11-08 10:00:33 -08:00
}
2022-12-13 18:23:48 -08:00
private function update_event ( $id )
2016-11-08 10:00:33 -08:00
{
2022-12-13 18:23:48 -08:00
$ret = [];
2016-11-08 10:00:33 -08:00
2022-12-13 18:23:48 -08:00
$classVal = null ;
if ( isset ( $_POST [ 'event' ][ $id ][ 'class' ]))
2016-11-08 10:00:33 -08:00
{
2022-12-13 18:23:48 -08:00
$classVal = $_POST [ 'event' ][ $id ][ 'class' ];
$ret [ 'class' ] = $_POST [ 'event' ][ $id ][ 'class' ];
2016-11-08 10:00:33 -08:00
}
2022-12-13 18:23:48 -08:00
if ( ! empty ( $_POST [ 'event' ][ $id ][ 'email' ]) && $classVal === 'email' )
2016-11-08 10:00:33 -08:00
{
2022-12-13 18:23:48 -08:00
$ret [ 'email' ] = $_POST [ 'event' ][ $id ][ 'email' ];
2016-11-08 10:00:33 -08:00
}
2022-12-13 18:23:48 -08:00
elseif ( $classVal !== null && ! empty ( $_POST [ 'event' ][ $id ][ $classVal ]))
2016-11-08 10:00:33 -08:00
{
2022-12-13 18:23:48 -08:00
$ret [ 'recipient' ] = $_POST [ 'event' ][ $id ][ $classVal ];
2016-11-08 10:00:33 -08:00
}
2022-12-13 18:23:48 -08:00
$ret [ 'include' ] = $_POST [ 'event' ][ $id ][ 'include' ];
$ret [ 'legacy' ] = $_POST [ 'event' ][ $id ][ 'legacy' ];
if ( $this -> notify_prefs [ 'event' ][ $id ] !== $ret )
2016-11-08 10:00:33 -08:00
{
2022-12-13 18:23:48 -08:00
return $ret ;
2016-11-08 10:00:33 -08:00
}
2022-12-13 18:23:48 -08:00
return false ;
2016-11-08 10:00:33 -08:00
}
}
class plugin_notify_admin_form_ui extends e_admin_form_ui
{
}
new plugin_notify_admin ();
require_once ( e_ADMIN . " auth.php " );
e107 :: getAdminUI () -> runPage ();
require_once ( e_ADMIN . " footer.php " );