2006-12-02 04:36:16 +00:00
< ? php
/*
2009-11-12 14:30:07 +00:00
* e107 website system
*
2013-02-27 16:37:31 +01: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 )
*
*/
2006-12-02 04:36:16 +00:00
require_once ( " ../class2.php " );
2008-11-02 12:23:56 +00:00
if ( ! getperms ( " M " ))
{
2006-12-02 04:36:16 +00:00
header ( " location: " . e_BASE . " index.php " );
exit ;
}
2009-08-28 16:11:02 +00:00
2013-02-22 21:34:06 -08:00
e107 :: lan ( 'core' , 'wmessage' , true );
2009-08-28 16:11:02 +00:00
2006-12-02 04:36:16 +00:00
2015-02-03 12:26:56 -08:00
class wmessage_admin extends e_admin_dispatcher
{
protected $modes = array (
'main' => array (
'controller' => 'generic_ui' ,
'path' => null ,
'ui' => 'generic_form_ui' ,
'uipath' => null
),
);
protected $adminMenu = array (
'main/list' => array ( 'caption' => LAN_MANAGE , 'perm' => 'P' ),
'main/create' => array ( 'caption' => LAN_CREATE , 'perm' => 'P' ),
'main/prefs' => array ( 'caption' => LAN_PREFS , 'perm' => 'P' ),
// 'main/custom' => array('caption'=> 'Custom Page', 'perm' => 'P')
);
protected $adminMenuAliases = array (
'main/edit' => 'main/list'
);
protected $menuTitle = WMLAN_00 ;
}
class generic_ui extends e_admin_ui
{
protected $pluginTitle = WMLAN_00 ;
protected $pluginName = 'core' ;
2015-02-09 01:05:33 -08:00
protected $eventName = 'wmessage' ;
2015-02-03 12:26:56 -08:00
protected $table = 'generic' ;
protected $pid = 'gen_id' ;
protected $perPage = 10 ;
protected $batchDelete = true ;
protected $batchCopy = true ;
2015-02-09 01:05:33 -08:00
2015-02-03 12:26:56 -08:00
// protected $sortField = 'somefield_order';
// protected $orderStep = 10;
// protected $tabs = array('Tabl 1','Tab 2'); // Use 'tab'=>0 OR 'tab'=>1 in the $fields below to enable.
protected $listQry = " SELECT * FROM `#generic` WHERE gen_type='wmessage' " ; // Example Custom Query. LEFT JOINS allowed. Should be without any Order or Limit.
protected $listOrder = 'gen_id DESC' ;
protected $fields = array (
'checkboxes' => array ( 'title' => '' , 'type' => null , 'data' => null , 'width' => '5%' , 'thclass' => 'center' , 'forced' => '1' , 'class' => 'center' , 'toggle' => 'e-multiselect' , ),
'gen_id' => array ( 'title' => LAN_ID , 'data' => 'int' , 'width' => '5%' , 'help' => '' , 'readParms' => '' , 'writeParms' => '' , 'class' => 'left' , 'thclass' => 'left' , ),
'gen_type' => array ( 'title' => LAN_TYPE , 'type' => 'hidden' , 'data' => 'str' , 'width' => 'auto' , 'help' => '' , 'readParms' => '' , 'writeParms' => 'default=wmessage' , 'class' => 'left' , 'thclass' => 'left' , ),
'gen_datestamp' => array ( 'title' => LAN_DATESTAMP , 'type' => 'hidden' , 'data' => 'int' , 'width' => 'auto' , 'filter' => true , 'help' => '' , 'readParms' => '' , 'writeParms' => '' , 'class' => 'left' , 'thclass' => 'left' , ),
'gen_user_id' => array ( 'title' => LAN_ID , 'type' => 'hidden' , 'data' => 'int' , 'width' => '5%' , 'help' => '' , 'readParms' => '' , 'writeParms' => '' , 'class' => 'left' , 'thclass' => 'left' , ),
'gen_ip' => array ( 'title' => WMLAN_10 , 'type' => 'text' , 'data' => 'str' , 'width' => 'auto' , 'inline' => true , 'help' => '' , 'readParms' => '' , 'writeParms' => 'size=xxlarge' , 'class' => 'left' , 'thclass' => 'left' , ),
'gen_intdata' => array ( 'title' => LAN_VISIBILITY , 'type' => 'userclass' , 'data' => 'int' , 'inline' => true , 'batch' => true , 'filter' => true , 'width' => 'auto' , 'help' => '' , 'readParms' => '' , 'writeParms' => '' , 'class' => 'left' , 'thclass' => 'left' , ),
'gen_chardata' => array ( 'title' => WMLAN_04 , 'type' => 'bbarea' , 'data' => 'str' , 'width' => 'auto' , 'help' => '' , 'readParms' => '' , 'writeParms' => '' , 'class' => 'center' , 'thclass' => 'center' , ),
'options' => array ( 'title' => LAN_OPTIONS , 'type' => null , 'data' => null , 'width' => '10%' , 'thclass' => 'center last' , 'class' => 'center last' , 'forced' => '1' , ),
);
protected $fieldpref = array ( 'gen_ip' , 'gen_intdata' );
protected $prefs = array (
'wm_enclose' => array ( 'title' => WMLAN_05 , 'type' => 'boolean' , 'data' => 'int' , 'help' => WMLAN_06 ), );
public function init ()
{
}
public function beforeCreate ( $new_data )
{
return $new_data ;
}
public function afterCreate ( $new_data , $old_data , $id )
{
// do something
}
public function beforeUpdate ( $new_data , $old_data , $id )
{
return $new_data ;
}
public function afterUpdate ( $new_data , $old_data , $id )
{
e107 :: getCache () -> clear ( " wmessage " );
}
public function onCreateError ( $new_data , $old_data )
{
// do something
}
public function onUpdateError ( $new_data , $old_data , $id )
{
// do something
}
/*
// optional - override edit page.
public function customPage ()
{
$ns = e107 :: getRender ();
$text = 'Hello World!' ;
$ns -> tablerender ( 'Hello' , $text );
}
*/
}
class generic_form_ui extends e_admin_form_ui
{
}
new wmessage_admin ();
require_once ( e_ADMIN . " auth.php " );
e107 :: getAdminUI () -> runPage ();
require_once ( e_ADMIN . " footer.php " );
exit ;
/*
2013-02-22 21:34:06 -08:00
2006-12-02 04:36:16 +00:00
require_once ( e_HANDLER . 'userclass_class.php' );
require_once ( e_HANDLER . " ren_help.php " );
2013-02-07 21:19:15 +01:00
$frm = e107 :: getForm ();
$mes = e107 :: getMessage ();
2006-12-02 04:36:16 +00:00
2012-12-08 13:52:05 +01:00
vartrue ( $action ) == '' ;
2008-11-02 12:23:56 +00:00
if ( e_QUERY )
{
2006-12-02 04:36:16 +00:00
$tmp = explode ( '.' , e_QUERY );
$action = $tmp [ 0 ];
2010-09-07 17:11:34 +00:00
$sub_action = varset ( $tmp [ 1 ], '' );
$id = varset ( $tmp [ 2 ], 0 );
2006-12-02 04:36:16 +00:00
unset ( $tmp );
}
if ( $_POST )
{
$e107cache -> clear ( " wmessage " );
}
2008-11-02 12:23:56 +00:00
if ( isset ( $_POST [ 'wm_update' ]))
{
2014-03-14 17:26:32 -07:00
$data = $_POST [ 'data' ]; // $tp->toDB($_POST['data']) causes issues with ':'
$wm_title = $tp -> toDB ( $_POST [ 'wm_caption' ]);
$wmId = intval ( $_POST [ 'wm_id' ]);
$updateArray = array (
'gen_chardata' => $data ,
'gen_ip' => $wm_title ,
'gen_intdata' => $_POST [ 'wm_active' ],
'WHERE' => " gen_id= " . $wmId
);
2013-02-07 21:19:15 +01:00
//$message = ($sql->db_Update("generic", "gen_chardata ='{$data}',gen_ip ='{$wm_title}', gen_intdata='".$_POST['wm_active']."' WHERE gen_id=".$wmId." ")) ? LAN_UPDATED : LAN_UPDATED_FAILED;
2014-03-14 17:26:32 -07:00
// if ($sql->update("generic", "gen_chardata ='{$data}',gen_ip ='{$wm_title}', gen_intdata='".$_POST['wm_active']."' WHERE gen_id=".$wmId." "))
if ( $sql -> update ( " generic " , $updateArray ))
2013-02-07 21:19:15 +01:00
{
$mes -> addSuccess ( LAN_UPDATED );
2014-03-14 17:26:32 -07:00
welcome_adminlog ( '02' , $wmId , $wm_title );
2013-02-07 21:19:15 +01:00
}
else
{
2013-03-27 18:27:08 +01:00
$mes -> addError ( LAN_UPDATED_FAILED );
2013-02-07 21:19:15 +01:00
}
2006-12-02 04:36:16 +00:00
}
2008-11-02 12:23:56 +00:00
if ( isset ( $_POST [ 'wm_insert' ]))
{
2014-03-14 17:26:32 -07:00
$wmtext = $tp -> toDB ( $_POST [ 'data' ]);
$wmtitle = $tp -> toDB ( $_POST [ 'wm_caption' ]);
2008-11-02 12:23:56 +00:00
welcome_adminlog ( '01' , 0 , $wmtitle );
2014-03-14 17:26:32 -07:00
2013-02-07 21:19:15 +01:00
//$message = ($sql->db_Insert("generic", "0, 'wmessage', '".time()."', ".USERID.", '{$wmtitle}', '{$_POST['wm_active']}', '{$wmtext}' ")) ? LAN_CREATED : LAN_CREATED_FAILED ;
if ( $sql -> db_Insert ( " generic " , " 0, 'wmessage', ' " . time () . " ', " . USERID . " , ' { $wmtitle } ', ' { $_POST [ 'wm_active' ] } ', ' { $wmtext } ' " ))
{
$mes -> addSuccess ( LAN_CREATED );
}
else
{
2013-03-27 18:27:08 +01:00
$mes -> addError ( LAN_CREATED_FAILED );
2013-02-07 21:19:15 +01:00
}
2006-12-02 04:36:16 +00:00
}
2008-11-02 12:23:56 +00:00
if ( isset ( $_POST [ 'updateoptions' ]))
{
$changed = FALSE ;
foreach ( array ( 'wm_enclose' , 'wmessage_sc' ) as $opt )
{
$temp = intval ( $_POST [ $opt ]);
if ( $temp != $pref [ $opt ])
{
$pref [ $opt ] = $temp ;
$changed = TRUE ;
}
}
if ( $changed )
{
save_prefs ();
welcome_adminlog ( '04' , 0 , $pref [ 'wm_enclose' ] . ', ' . $pref [ 'wmessage_sc' ]);
2013-02-07 21:19:15 +01:00
}
else
{
$mes -> addInfo ( LAN_NOCHANGE_NOTSAVED );
2008-11-02 12:23:56 +00:00
}
2006-12-02 04:36:16 +00:00
}
2008-11-02 12:23:56 +00:00
if ( isset ( $_POST [ 'main_delete' ]))
{
2006-12-02 04:36:16 +00:00
$del_id = array_keys ( $_POST [ 'main_delete' ]);
2008-11-02 12:23:56 +00:00
welcome_adminlog ( '03' , $wmId , '' );
2013-03-27 18:27:08 +01:00
if ( $sql -> delete ( " generic " , " gen_id=' " . $del_id [ 0 ] . " ' " ))
2013-02-07 21:19:15 +01:00
{
$mes -> addSuccess ( LAN_DELETED );
}
else
{
2013-03-27 18:27:08 +01:00
$mes -> addError ( LAN_DELETED_FAILED );
2013-02-07 21:19:15 +01:00
}
2006-12-02 04:36:16 +00:00
}
2013-05-05 17:23:12 -07:00
echo $mes -> render ();
2006-12-02 04:36:16 +00:00
// Show Existing -------
2008-11-02 12:23:56 +00:00
if ( $action == " main " || $action == " " )
{
2013-03-27 18:27:08 +01:00
if ( $wm_total = $sql -> select ( " generic " , " * " , " gen_type='wmessage' ORDER BY gen_id ASC " ))
2008-11-02 12:23:56 +00:00
{
2006-12-02 04:36:16 +00:00
$wmList = $sql -> db_getList ();
2013-02-22 21:34:06 -08:00
$text = $frm -> open ( 'myform_wmessage' , 'post' , e_SELF );
2013-02-07 21:19:15 +01:00
$text .= "
2012-11-26 14:41:32 -08:00
< table class = 'table adminlist' >
2012-05-13 05:50:32 +00:00
< colgroup >
2009-07-17 07:53:13 +00:00
< col style = 'width:5%' />
2013-02-07 21:19:15 +01:00
< col style = 'width:70%' />
< col style = 'width:10%' />
2009-07-17 07:53:13 +00:00
< col style = 'width:10%' />
</ colgroup >
< thead >
2006-12-02 04:36:16 +00:00
< tr >
2013-02-07 21:19:15 +01:00
< th > " .LAN_ID. " </ th >
2009-07-17 07:53:13 +00:00
< th > " .WMLAN_02. " </ th >
2013-02-07 21:19:15 +01:00
< th class = 'center' > " .LAN_VISIBILITY. " </ th >
2009-07-17 07:53:13 +00:00
< th class = 'center' > " .LAN_OPTIONS. " </ th >
</ tr >
</ thead >
< tbody > " ;
2008-11-02 12:23:56 +00:00
foreach ( $wmList as $row )
{
2006-12-02 04:36:16 +00:00
$text .= "
< tr >
2009-07-17 07:53:13 +00:00
< td class = 'center' style = 'text-align: center; vertical-align: middle' > " . $row['gen_id'] . " </ td >
< td > " .strip_tags( $tp->toHTML ( $row['gen_ip'] )). " </ td >
< td > " .r_userclass_name( $row['gen_intdata'] ). " </ td >
< td class = 'center nowrap' >
2013-03-15 19:23:43 -07:00
< a class = 'btn btn-large' href = '".e_SELF."?create.edit.{$row[' gen_id ']}' > " .ADMIN_EDIT_ICON. " </ a >
2014-01-23 04:38:48 -08:00
< button class = 'btn btn-large action delete' type = 'submit' title = '".LAN_DELETE."' name = 'main_delete[".$row[' gen_id ']."]' data - confirm = \ " " . LAN_CONFIRMDEL . " [ID: { $row [ 'gen_id' ] } ] \" > " . ADMIN_DELETE_ICON . " </button>
2006-12-02 04:36:16 +00:00
</ td >
</ tr > " ;
}
2013-02-07 21:19:15 +01:00
$text .= " </tbody></table> " ;
2013-02-22 21:34:06 -08:00
$text .= $frm -> close ();
2006-12-02 04:36:16 +00:00
} else {
2013-02-07 21:19:15 +01:00
$mes -> addInfo ( WMLAN_09 );
2006-12-02 04:36:16 +00:00
}
2013-02-22 21:34:06 -08:00
$ns -> tablerender ( WMLAN_00 . SEP . LAN_MANAGE , $mes -> render () . $text );
2006-12-02 04:36:16 +00:00
}
// Create and Edit
if ( $action == " create " || $action == " edit " )
{
if ( $sub_action == " edit " )
{
2013-03-27 18:27:08 +01:00
$sql -> select ( " generic " , " gen_intdata, gen_ip, gen_chardata " , " gen_id = $id " );
$row = $sql -> fetch ();
2006-12-02 04:36:16 +00:00
}
$text = "
< form method = 'post' action = '".e_SELF."' id = 'wmform' >
2009-07-10 14:25:23 +00:00
< fieldset id = 'code-wmessage-create' >
2012-11-26 14:41:32 -08:00
< table class = 'table adminform' >
2012-05-13 05:50:32 +00:00
< colgroup >
2009-07-10 14:25:23 +00:00
< col class = 'col-label' />
< col class = 'col-control' />
</ colgroup >
2006-12-02 04:36:16 +00:00
< tr >
2013-02-27 16:37:31 +01:00
< td > " .WMLAN_10. " </ td >
2013-05-05 17:23:12 -07:00
< td > " . $frm->text ('wm_caption', $tp->toForm (vartrue( $row['gen_ip'] )), 80). " </ td >
2013-02-27 16:37:31 +01:00
</ tr >
< tr >
< td > " .WMLAN_04. " </ td >
2013-05-04 14:04:52 -07:00
< td > " ;
$text .= $frm -> bbarea ( 'data' , $row [ 'gen_chardata' ]);
// $text .= "<textarea class='e-wysiwyg tbox' id='data' name='data' cols='70' rows='15' style='width:95%' onselect='storeCaret(this);' onclick='storeCaret(this);' onkeyup='storeCaret(this)'>".$tp->toForm(vartrue($row['gen_chardata']))."</textarea>";
$text .= " </td>
2006-12-02 04:36:16 +00:00
</ tr > " ;
2013-02-22 22:35:15 -08:00
// $text .= display_help("helpb", "admin"); //XXX Serves as BC Check
2006-12-02 04:36:16 +00:00
$text .= "
2013-02-27 16:37:31 +01:00
< tr >
< td > " .LAN_VISIBILITY. " </ td >
< td > " .r_userclass( " wm_active " , vartrue( $row['gen_intdata'] ), " off " , " public , guest , nobody , member , admin , classes " ). " </ td >
2006-12-02 04:36:16 +00:00
</ tr >
2013-02-27 16:37:31 +01:00
</ table >
2006-12-02 04:36:16 +00:00
2009-07-10 14:25:23 +00:00
< div class = 'buttons-bar center' > " ;
2013-02-27 16:37:31 +01:00
if ( $sub_action == " edit " )
{
$text .= $frm -> admin_button ( 'wm_update' , LAN_UPDATE , 'update' );
}
else
{
$text .= $frm -> admin_button ( 'wm_insert' , LAN_CREATE , 'create' );
}
2006-12-02 04:36:16 +00:00
$text .= " <input type='hidden' name='wm_id' value=' " . $id . " ' /> " ;
2009-07-10 14:25:23 +00:00
$text .= " </div>
</ fieldset >
2013-02-27 16:37:31 +01:00
</ form > " ;
2013-02-22 21:34:06 -08:00
2013-02-27 16:37:31 +01:00
$ns -> tablerender ( WMLAN_00 . SEP . LAN_CREATE , $mes -> render () . $text );
2006-12-02 04:36:16 +00:00
}
if ( $action == " opt " ) {
2013-02-07 21:19:15 +01:00
$pref = e107 :: getPref ();
$ns = e107 :: getRender ();
$text = "
2006-12-02 04:36:16 +00:00
< form method = 'post' action = '".e_SELF."?".e_QUERY."' > \n
2009-07-10 14:25:23 +00:00
< fieldset id = 'code-wmessage-options' >
2012-11-26 14:41:32 -08:00
< table class = 'table adminform' >
2012-05-13 05:50:32 +00:00
< colgroup >
2009-07-10 14:25:23 +00:00
< col class = 'col-label' />
< col class = 'col-control' />
</ colgroup >
2006-12-02 04:36:16 +00:00
< tr >
2013-02-27 16:37:31 +01:00
< td > " .WMLAN_05. " </ td >
2013-03-27 18:27:08 +01:00
< td > " . $frm->radio_switch ('wm_enclose', varset( $pref['wm_enclose'] )). " < span class = 'field-help' > " .WMLAN_06. " </ span ></ td >
2013-03-22 19:54:37 -07:00
</ tr > " ;
2015-02-03 12:26:56 -08:00
// DEPRECATED - see header_default.php {WMESSAGE}
// $text .= "
// <tr>
// <td>".WMLAN_07."</td>
// <td>".$frm->checkbox('wmessage_sc', 1, varset($pref['wmessage_sc'],0))."</td>
// </tr>";
2013-03-22 19:54:37 -07:00
$text .= "
2009-07-10 14:25:23 +00:00
</ table >
2006-12-02 04:36:16 +00:00
2013-02-07 21:19:15 +01:00
< div class = 'buttons-bar center' >
2013-03-22 19:54:37 -07:00
" . $frm->admin_button ('updateoptions', LAN_SAVE). "
2009-07-10 14:25:23 +00:00
</ div >
</ fieldset >
2006-12-02 04:36:16 +00:00
</ form >
2013-02-07 21:19:15 +01:00
" ;
2006-12-02 04:36:16 +00:00
2013-02-22 21:34:06 -08:00
$ns -> tablerender ( WMLAN_00 . SEP . LAN_PREFS , $mes -> render () . $text );
2006-12-02 04:36:16 +00:00
}
2012-11-27 02:34:02 -08:00
function wmessage_adminmenu ()
{
$act = e_QUERY ;
$action = vartrue ( $act , 'main' );
2013-02-22 21:34:06 -08:00
$var [ 'main' ][ 'text' ] = LAN_MANAGE ;
2006-12-02 04:36:16 +00:00
$var [ 'main' ][ 'link' ] = e_SELF ;
2013-02-22 21:34:06 -08:00
$var [ 'create' ][ 'text' ] = LAN_CREATE ;
2006-12-02 04:36:16 +00:00
$var [ 'create' ][ 'link' ] = e_SELF . " ?create " ;
$var [ 'opt' ][ 'text' ] = LAN_PREFS ;
$var [ 'opt' ][ 'link' ] = e_SELF . " ?opt " ;
2013-02-22 21:34:06 -08:00
show_admin_menu ( WMLAN_00 , $action , $var );
2006-12-02 04:36:16 +00:00
}
require_once ( " footer.php " );
2008-11-02 12:23:56 +00:00
// Log event to admin log
function welcome_adminlog ( $msg_num = '00' , $id = 0 , $woffle = '' )
{
global $pref , $admin_log ;
// if (!varset($pref['admin_log_log']['admin_welcome'],0)) return;
$msg = '' ;
if ( $id ) $msg = 'ID: ' . $id ;
if ( $woffle )
{
if ( $msg ) $msg .= '[!br!]' ;
$msg .= $woffle ;
}
2014-10-23 11:12:13 -07:00
e107 :: getLog () -> add ( 'WELCOME_' . $msg_num , $msg , E_LOG_INFORMATIVE , '' );
2008-11-02 12:23:56 +00:00
}
2015-02-03 12:26:56 -08:00
*/
2006-12-02 04:36:16 +00:00
?>