2009-11-24 16:32:02 +00:00
< ? php
2010-03-01 13:02:43 +00:00
/*
* e107 website system
*
2012-01-13 11:47:39 +00:00
* Copyright ( C ) 2008 - 2012 e107 Inc ( e107 . org )
2010-03-01 13:02:43 +00:00
* Released under the terms and conditions of the
* GNU General Public License ( http :// www . gnu . org / licenses / gpl . txt )
*
* Administration User Interface logic
*
* $URL $
* $Id $
*/
/**
* @ package e107
2010-05-28 22:10:20 +00:00
* @ subpackage e107_handlers
2010-03-01 13:02:43 +00:00
* @ version $Id $
*
* Administration User Interface logic
*/
2009-11-24 16:32:02 +00:00
/**
2010-03-01 13:02:43 +00:00
* @ todo core request handler ( non - admin ), core response
2009-11-24 16:32:02 +00:00
*/
2012-08-10 19:30:43 +00:00
if ( ! defined ( 'e107_INIT' )){ exit ; }
2009-11-24 16:32:02 +00:00
class e_admin_request
{
/**
* Current GET request array
* @ var array
*/
protected $_request_qry ;
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
/**
* Current POST array
* @ var array
*/
protected $_posted_qry ;
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
/**
* Current Mode
* @ var string
*/
protected $_mode = '' ;
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
/**
* Default Mode
* @ var string
*/
protected $_default_mode = 'main' ;
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
/**
* Key name for mode search
* @ var string
*/
protected $_mode_key = 'mode' ;
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
/**
* Current action
* @ var string
*/
protected $_action = '' ;
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
/**
* Default Action
* @ var string
*/
protected $_default_action = 'index' ;
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
/**
* Key name for action search
* @ var string
*/
protected $_action_key = 'action' ;
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
/**
* Current ID
* @ var integer
*/
protected $_id = 0 ;
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
/**
* Key name for ID search
* @ var string
*/
protected $_id_key = 'id' ;
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
/**
* Constructor
2009-12-23 15:12:13 +00:00
*
2009-11-24 16:32:02 +00:00
* @ param string | array $qry [ optional ]
2009-12-13 21:52:32 +00:00
* @ return none
2009-11-24 16:32:02 +00:00
*/
public function __construct ( $request_string = null , $parse = true )
{
2020-12-23 16:01:20 -08:00
if ( $request_string === null )
2009-11-24 16:32:02 +00:00
{
$request_string = str_replace ( '&' , '&' , e_QUERY );
}
if ( $parse )
{
$this -> parseRequest ( $request_string );
}
}
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
/**
* Parse request data
* @ param string | array $request_data
* @ return e_admin_request
*/
protected function parseRequest ( $request_data )
{
if ( is_string ( $request_data ))
{
parse_str ( $request_data , $request_data );
}
$this -> _request_qry = ( array ) $request_data ;
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
// Set current mode
if ( isset ( $this -> _request_qry [ $this -> _mode_key ]))
{
2020-12-23 16:01:20 -08:00
$this -> _mode = preg_replace ( '/[\W]/' , '' , $this -> _request_qry [ $this -> _mode_key ]);
2009-11-24 16:32:02 +00:00
}
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
// Set current action
if ( isset ( $this -> _request_qry [ $this -> _action_key ]))
{
2020-12-23 16:01:20 -08:00
$this -> _action = preg_replace ( '/[\W]/' , '' , $this -> _request_qry [ $this -> _action_key ]);
2009-11-24 16:32:02 +00:00
}
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
// Set current id
if ( isset ( $this -> _request_qry [ $this -> _id_key ]))
{
2019-02-07 16:34:00 -08:00
$this -> _id = preg_replace ( '/[^\w\-:\.]/' , '' , $this -> _request_qry [ $this -> _id_key ]);
2009-11-24 16:32:02 +00:00
}
2009-12-23 15:12:13 +00:00
2012-12-08 21:09:58 +02:00
$this -> _posted_qry =& $_POST ; //raw?
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
return $this ;
}
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
/**
* Retrieve variable from GET scope
* If $key is null , all GET data will be returned
2009-12-23 15:12:13 +00:00
*
2009-11-24 16:32:02 +00:00
* @ param string $key [ optional ]
* @ param mixed $default [ optional ]
* @ return mixed
*/
public function getQuery ( $key = null , $default = null )
{
2020-12-23 16:01:20 -08:00
if ( $key === null )
2009-11-24 16:32:02 +00:00
{
return $this -> _request_qry ;
}
return ( isset ( $this -> _request_qry [ $key ]) ? $this -> _request_qry [ $key ] : $default );
}
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
/**
* Set / Unset GET variable
* If $key is array , $value is not used .
2009-12-23 15:12:13 +00:00
* If $value is null , ( string ) $key is unset
*
2009-11-24 16:32:02 +00:00
* @ param string | array $key
* @ param mixed $value [ optional ]
* @ return e_admin_request
*/
public function setQuery ( $key , $value = null )
{
if ( is_array ( $key ))
{
foreach ( $key as $k => $v )
{
$this -> setQuery ( $k , $v );
}
return $this ;
}
2009-12-23 15:12:13 +00:00
2020-12-23 16:01:20 -08:00
if ( $value === null )
2009-11-24 16:32:02 +00:00
{
2020-12-23 16:01:20 -08:00
unset ( $this -> _request_qry [ $key ], $_GET [ $key ]);
2009-11-24 16:32:02 +00:00
return $this ;
}
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
$this -> _request_qry [ $key ] = $value ;
2012-12-08 21:09:58 +02:00
$_GET [ $key ] = $value ;
2009-11-24 16:32:02 +00:00
return $this ;
}
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
/**
* Retrieve variable from POST scope
* If $key is null , all POST data will be returned
2009-12-23 15:12:13 +00:00
*
2009-11-24 16:32:02 +00:00
* @ param string $key [ optional ]
* @ param mixed $default [ optional ]
* @ return mixed
*/
public function getPosted ( $key = null , $default = null )
{
2020-12-23 16:01:20 -08:00
if ( $key === null )
2009-11-24 16:32:02 +00:00
{
return $this -> _posted_qry ;
}
return ( isset ( $this -> _posted_qry [ $key ]) ? $this -> _posted_qry [ $key ] : $default );
}
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
/**
* Set / Unset POST variable
* If $key is array , $value is not used .
2009-12-23 15:12:13 +00:00
* If $value is null , ( string ) $key is unset
*
2020-12-11 08:57:19 -08:00
* @ param string | array $key
2009-11-24 16:32:02 +00:00
* @ param object $value [ optional ]
* @ return e_admin_request
*/
public function setPosted ( $key , $value = null )
{
if ( is_array ( $key ))
{
2010-11-04 23:27:47 +00:00
if ( empty ( $key ))
{
$this -> _posted_qry = array (); //POST reset
return $this ;
}
2009-11-24 16:32:02 +00:00
foreach ( $key as $k => $v )
{
$this -> setPosted ( $k , $v );
}
return $this ;
}
2009-12-23 15:12:13 +00:00
2020-12-23 16:01:20 -08:00
if ( $value === null )
2009-11-24 16:32:02 +00:00
{
unset ( $this -> _posted_qry [ $key ]);
return $this ;
}
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
$tp = e107 :: getParser ();
$this -> _posted_qry [ $tp -> post_toForm ( $key )] = $tp -> post_toForm ( $value );
return $this ;
}
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
/**
* Get current mode
* @ return string
*/
public function getMode ()
{
2020-12-23 16:01:20 -08:00
if ( ! $this -> _mode )
{
return $this -> getDefaultMode ();
}
2009-11-24 16:32:02 +00:00
return $this -> _mode ;
}
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
/**
* Get default mode
* @ return string
*/
public function getDefaultMode ()
{
return $this -> _default_mode ;
}
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
/**
* Get current mode name
2009-12-23 15:12:13 +00:00
*
2009-11-24 16:32:02 +00:00
* @ return string
*/
public function getModeName ()
{
return strtolower ( str_replace ( '-' , '_' , $this -> getMode ()));
}
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
/**
* Reset current mode
* @ param string $mode
* @ return e_admin_request
*/
public function setMode ( $mode )
{
2020-12-23 16:01:20 -08:00
$this -> _mode = preg_replace ( '/[\W]/' , '' , $mode );
2009-11-24 16:32:02 +00:00
$this -> setQuery ( $this -> _mode_key , $this -> _mode );
return $this ;
}
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
/**
* Set default mode
* @ param string $mode
* @ return e_admin_request
*/
public function setDefaultMode ( $mode )
{
2020-12-23 16:01:20 -08:00
if ( $mode )
{
$this -> _default_mode = $mode ;
}
2009-11-24 16:32:02 +00:00
return $this ;
}
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
/**
* Set mode key name
* @ param string $key
* @ return e_admin_request
*/
public function setModeKey ( $key )
{
$this -> _mode_key = $key ;
return $this ;
}
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
/**
* Get current action
2020-03-11 17:04:51 -07:00
* @ return string
2009-11-24 16:32:02 +00:00
*/
public function getAction ()
{
2020-12-23 16:01:20 -08:00
if ( ! $this -> _action )
{
return $this -> getDefaultAction ();
}
2009-11-24 16:32:02 +00:00
return $this -> _action ;
}
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
/**
* Get default action
* @ return string
*/
public function getDefaultAction ()
{
return $this -> _default_action ;
}
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
/**
* Get current action name
* @ return string camelized action
*/
public function getActionName ()
{
return $this -> camelize ( $this -> getAction ());
}
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
/**
* Reset current action
2009-12-23 15:12:13 +00:00
*
2009-11-24 16:32:02 +00:00
* @ param string $action
* @ return e_admin_request
*/
public function setAction ( $action )
{
2020-12-23 16:01:20 -08:00
$this -> _action = preg_replace ( '/[\W]/' , '' , $action );
2009-11-24 16:32:02 +00:00
$this -> setQuery ( $this -> _action_key , $this -> _action );
return $this ;
}
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
/**
* Set default action
2009-12-23 15:12:13 +00:00
*
2009-11-24 16:32:02 +00:00
* @ param string $action
* @ return e_admin_request
*/
public function setDefaultAction ( $action )
{
2020-12-23 16:01:20 -08:00
if ( $action )
{
$this -> _default_action = $action ;
}
2009-11-24 16:32:02 +00:00
return $this ;
}
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
/**
* Set action key name
* @ param string $key
* @ return e_admin_request
*/
public function setActionKey ( $key )
{
$this -> _action_key = $key ;
return $this ;
}
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
/**
* Get current ID
* @ return integer
*/
public function getId ()
{
return $this -> _id ;
}
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
/**
* Reset current ID
* @ param string $id
* @ return e_admin_request
*/
public function setId ( $id )
{
2020-12-23 16:01:20 -08:00
$id = ( int ) $id ;
2009-11-24 16:32:02 +00:00
$this -> _id = $id ;
$this -> setQuery ( $this -> _id_key , $id );
return $this ;
}
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
/**
* Set id key name
* @ param string $key
* @ return e_admin_request
*/
public function setIdKey ( $key )
{
$this -> _id_key = $key ;
return $this ;
}
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
/**
* Build query string from current request array
* NOTE : changing url separator to & amp ; ( $encode == true ) ( thus URL XHTML compliance ) works in PHP 5.1 . 2 + environment
2009-12-23 15:12:13 +00:00
*
2009-11-24 16:32:02 +00:00
* @ param string | array $merge_with [ optional ] override request values
* @ param boolean $encode if true & amp ; separator will be used , all values will be http encoded , default true
* @ param string | array $exclude_from_query numeric array / comma separated list of vars to be excluded from current query , true - don ' t use current query at all
2012-12-08 21:09:58 +02:00
* @ param boolean $keepSpecial don 't exclude special vars as ' mode ' and ' action '
2009-11-24 16:32:02 +00:00
* @ return string url encoded query string
*/
2012-12-08 21:09:58 +02:00
public function buildQueryString ( $merge_with = array (), $encode = true , $exclude_from_query = '' , $keepSpecial = true )
2009-11-24 16:32:02 +00:00
{
$ret = $this -> getQuery ();
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
//special case - exclude all current
2020-12-23 16:01:20 -08:00
if ( $exclude_from_query === true )
2009-11-24 16:32:02 +00:00
{
2010-10-04 22:14:05 +00:00
$exclude_from_query = array_keys ( $ret );
2009-11-24 16:32:02 +00:00
}
// to array
if ( is_string ( $exclude_from_query ))
{
$exclude_from_query = array_map ( 'trim' , explode ( ',' , $exclude_from_query ));
}
2009-12-23 15:12:13 +00:00
if ( $exclude_from_query )
2009-11-24 16:32:02 +00:00
{
foreach ( $exclude_from_query as $var )
{
2020-12-23 16:01:20 -08:00
if ( $keepSpecial && $var != $this -> _action_key && $var != $this -> _mode_key )
{
unset ( $ret [ $var ]);
}
2009-11-24 16:32:02 +00:00
}
}
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
if ( is_string ( $merge_with ))
{
parse_str ( $merge_with , $merge_with );
}
$ret = array_merge ( $ret , ( array ) $merge_with );
$separator = '&' ;
if ( $encode )
{
$separator = '&' ;
//$ret = array_map('rawurlencode', $ret);
}
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
$ret = http_build_query ( $ret , 'numeric_' , $separator );
if ( ! $encode )
{
return rawurldecode ( $ret );
}
return $ret ;
}
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
/**
* Convert string to CamelCase
2009-12-23 15:12:13 +00:00
*
2009-11-24 16:32:02 +00:00
* @ param string $str
* @ return string
*/
public function camelize ( $str )
{
return implode ( '' , array_map ( 'ucfirst' , explode ( '-' , str_replace ( '_' , '-' , $str ))));
}
}
/**
* TODO - front response parent , should do all the header . php work
*/
class e_admin_response
{
/**
* Body segments
*
* @ var array
*/
protected $_body = array ();
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
/**
* Title segments
*
* @ var unknown_type
*/
protected $_title = array ();
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
/**
* e107 meta title
*
* @ var array
*/
protected $_e_PAGETITLE = array ();
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
/**
* e107 meta description
*
* @ var array
*/
protected $_META_DESCRIPTION = array ();
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
/**
* e107 meta keywords
*
* @ var array
*/
protected $_META_KEYWORDS = array ();
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
/**
* Render mods
*
* @ var array
*/
protected $_render_mod = array ();
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
/**
* Meta title segment description
*
* @ var string
*/
protected $_meta_title_separator = ' - ' ;
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
/**
* Title segment separator
*
* @ var string
*/
protected $_title_separator = ' » ' ;
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
/**
* Constructor
*
*/
public function __construct ()
{
$this -> _render_mod [ 'default' ] = 'admin_page' ;
}
/**
* Set body segments for a namespace
*
* @ param string $content
* @ param string $namespace segment namesapce
* @ return e_admin_response
*/
2020-12-23 16:01:20 -08:00
public function setBody ( $content , $namespace = 'default' )
2009-11-24 16:32:02 +00:00
{
$this -> _body [ $namespace ] = $content ;
return $this ;
}
/**
* Append body segment to a namespace
*
* @ param string $content
* @ param string $namespace segment namesapce
* @ return e_admin_response
*/
2020-12-23 16:01:20 -08:00
public function appendBody ( $content , $namespace = 'default' )
2009-11-24 16:32:02 +00:00
{
if ( ! isset ( $this -> _body [ $namespace ]))
{
$this -> _body [ $namespace ] = array ();
}
$this -> _body [ $namespace ][] = $content ;
return $this ;
}
/**
* Prepend body segment to a namespace
*
* @ param string $content
* @ param string $namespace segment namespace
* @ return e_admin_response
*/
2020-12-23 16:01:20 -08:00
public function prependBody ( $content , $namespace = 'default' )
2009-11-24 16:32:02 +00:00
{
if ( ! isset ( $this -> _body [ $namespace ]))
{
$this -> _body [ $namespace ] = array ();
}
$this -> _body [ $namespace ] = array_merge ( array ( $content ), $this -> _body [ $namespace ]);
return $this ;
}
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
/**
* Get body segments from a namespace
*
* @ param string $namespace segment namesapce
* @ param boolean $reset reset segment namespace
* @ param string | boolean $glue if false return array , else return string
* @ return string | array
*/
2020-12-23 16:01:20 -08:00
public function getBody ( $namespace = 'default' , $reset = false , $glue = '' )
2009-11-24 16:32:02 +00:00
{
$content = vartrue ( $this -> _body [ $namespace ], array ());
if ( $reset )
{
$this -> _body [ $namespace ] = array ();
}
if ( is_bool ( $glue ))
{
return ( $glue ? $content : implode ( '' , $content ));
}
return implode ( $glue , $content );
}
/**
* Set title segments for a namespace
*
* @ param string $title
* @ param string $namespace
* @ return e_admin_response
*/
2020-12-23 16:01:20 -08:00
public function setTitle ( $title , $namespace = 'default' )
2009-11-24 16:32:02 +00:00
{
$this -> _title [ $namespace ] = array ( $title );
return $this ;
}
/**
* Append title segment to a namespace
*
* @ param string $title
* @ param string $namespace segment namesapce
* @ return e_admin_response
*/
2020-12-23 16:01:20 -08:00
public function appendTitle ( $title , $namespace = 'default' )
2009-12-23 15:12:13 +00:00
{
2009-11-24 16:32:02 +00:00
if ( empty ( $title ))
{
return $this ;
}
if ( ! isset ( $this -> _title [ $namespace ]))
{
$this -> _title [ $namespace ] = array ();
}
2009-12-23 15:12:13 +00:00
$this -> _title [ $namespace ][] = $title ;
2009-11-24 16:32:02 +00:00
return $this ;
}
/**
* Prepend title segment to a namespace
*
* @ param string $title
* @ param string $namespace segment namespace
* @ return e_admin_response
*/
2020-12-23 16:01:20 -08:00
public function prependTitle ( $title , $namespace = 'default' )
2009-11-24 16:32:02 +00:00
{
if ( empty ( $title ))
{
return $this ;
}
if ( ! isset ( $this -> _title [ $namespace ]))
{
$this -> _title [ $namespace ] = array ();
}
$this -> _title [ $namespace ] = array_merge ( array ( $title ), $this -> _title [ $namespace ]);
return $this ;
}
/**
* Get title segments from namespace
*
* @ param string $namespace
* @ param boolean $reset
* @ param boolean | string $glue
2020-12-11 08:57:19 -08:00
* @ return string | array
2009-11-24 16:32:02 +00:00
*/
2020-12-23 16:01:20 -08:00
public function getTitle ( $namespace = 'default' , $reset = false , $glue = ' ' )
2009-11-24 16:32:02 +00:00
{
$content = array ();
2014-10-24 13:14:51 -07:00
2009-11-24 16:32:02 +00:00
if ( isset ( $this -> _title [ $namespace ]) && is_array ( $this -> _title [ $namespace ]))
{
$content = $this -> _title [ $namespace ];
}
if ( $reset )
{
unset ( $this -> _title [ $namespace ]);
}
if ( is_bool ( $glue ) || empty ( $glue ))
{
return ( $glue ? $content : implode ( $this -> _title_separator , $content ));
}
2013-02-22 21:32:19 -08:00
$glue = deftrue ( 'SEP' , ' - ' ); // Defined by admin theme. // admin-ui used only by bootstrap.
2013-02-22 00:49:36 -08:00
2013-04-30 00:20:49 -07:00
return implode ( $glue , $content );
// return $head. implode($glue, $content).$foot;
2009-11-24 16:32:02 +00:00
}
/**
* Set render mode for a namespace
*
* @ param string $render_mod
* @ param string $namespace
* @ return e_admin_response
*/
2020-12-23 16:01:20 -08:00
public function setRenderMod ( $render_mod , $namespace = 'default' )
2009-11-24 16:32:02 +00:00
{
$this -> _render_mod [ $namespace ] = $render_mod ;
return $this ;
}
/**
* Set render mode for namespace
*
* @ param string $namespace
* @ return string
*/
2020-12-23 16:01:20 -08:00
public function getRenderMod ( $namespace = 'default' )
2009-11-24 16:32:02 +00:00
{
return varset ( $this -> _render_mod [ $namespace ], null );
}
/**
* Add meta title , description and keywords segments
*
* @ param string $meta property name
* @ param string $content meta content
* @ return e_admin_response
*/
2020-12-23 16:01:20 -08:00
public function addMetaData ( $meta , $content )
2009-11-24 16:32:02 +00:00
{
$tp = e107 :: getParser ();
$meta = '_' . $meta ;
if ( isset ( $this -> { $meta }) && ! empty ( $content ))
{
2010-02-08 16:50:28 +00:00
$this -> { $meta }[] = strip_tags ( $content );
2009-11-24 16:32:02 +00:00
}
return $this ;
}
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
/**
* Add meta title segment
*
* @ param string $title
* @ return e_admin_response
*/
2020-12-23 16:01:20 -08:00
public function addMetaTitle ( $title )
2009-11-24 16:32:02 +00:00
{
$this -> addMetaData ( 'e_PAGETITLE' , $title );
return $this ;
}
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
/**
* Add meta description segment
*
* @ param string $description
* @ return e_admin_response
*/
2020-12-23 16:01:20 -08:00
public function addMetaDescription ( $description )
2009-11-24 16:32:02 +00:00
{
$this -> addMetaData ( 'META_DESCRIPTION' , $description );
return $this ;
}
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
/**
* Add meta keywords segment
*
* @ param string $keyword
* @ return e_admin_response
*/
2020-12-23 16:01:20 -08:00
public function addMetaKeywords ( $keyword )
2009-11-24 16:32:02 +00:00
{
$this -> addMetaData ( 'META_KEYWORDS' , $keyword );
return $this ;
}
/**
* Send e107 meta - data
*
* @ return e_admin_response
*/
2020-12-23 16:01:20 -08:00
public function sendMeta ()
2009-11-24 16:32:02 +00:00
{
//HEADERF already included or meta content already sent
if ( e_AJAX_REQUEST || defined ( 'HEADER_INIT' ) || defined ( 'e_PAGETITLE' ))
2020-12-23 16:01:20 -08:00
{
2009-11-24 16:32:02 +00:00
return $this ;
2020-12-23 16:01:20 -08:00
}
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
if ( ! defined ( 'e_PAGETITLE' ) && ! empty ( $this -> _e_PAGETITLE ))
{
define ( 'e_PAGETITLE' , implode ( $this -> _meta_title_separator , $this -> _e_PAGETITLE ));
}
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
if ( ! defined ( 'META_DESCRIPTION' ) && ! empty ( $this -> _META_DESCRIPTION ))
{
define ( 'META_DESCRIPTION' , implode ( ' ' , $this -> _META_DESCRIPTION ));
}
if ( ! defined ( 'META_KEYWORDS' ) && ! empty ( $this -> _META_KEYWORDS ))
{
define ( 'META_KEYWORDS' , implode ( ', ' , $this -> _META_KEYWORDS ));
}
return $this ;
}
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
/**
* Add content segment to the header namespace
*
* @ param string $content
* @ return e_admin_response
*/
2020-12-23 16:01:20 -08:00
public function addHeaderContent ( $content )
2009-11-24 16:32:02 +00:00
{
$this -> appendBody ( $content , 'header_content' );
return $this ;
}
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
/**
* Get page header namespace content segments
*
* @ param boolean $reset
* @ param boolean $glue
* @ return string
*/
2020-12-23 16:01:20 -08:00
public function getHeaderContent ( $reset = true , $glue = " \n \n " )
2009-11-24 16:32:02 +00:00
{
return $this -> getBody ( 'header_content' , $reset , $glue );
}
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
/**
* Switch to iframe mod
* FIXME - implement e_IFRAME to frontend - header_default . php
*
* @ return e_admin_response
*/
2020-12-23 16:01:20 -08:00
public function setIframeMod ()
2009-11-24 16:32:02 +00:00
{
global $HEADER , $FOOTER , $CUSTOMHEADER , $CUSTOMFOOTER ;
2020-12-23 16:01:20 -08:00
$FOOTER = '' ;
$HEADER = $FOOTER ;
$CUSTOMFOOTER = array ();
$CUSTOMHEADER = $CUSTOMFOOTER ;
2012-07-18 03:47:28 +00:00
//TODO generic $_GET to activate for any page of admin.
2009-11-24 16:32:02 +00:00
// New
if ( ! defined ( 'e_IFRAME' ))
{
define ( 'e_IFRAME' , true );
}
return $this ;
}
/**
* Send Response Output
*
* @ param string $name segment
* @ param array $options valid keys are : messages | render | meta | return | raw | ajax
* @ return mixed
*/
2020-12-23 16:01:20 -08:00
public function send ( $name = 'default' , $options = array ())
2009-11-24 16:32:02 +00:00
{
if ( is_string ( $options ))
{
parse_str ( $options , $options );
}
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
// Merge with all available default options
$options = array_merge ( array (
2009-12-23 15:12:13 +00:00
'messages' => true ,
'render' => true ,
'meta' => false ,
'return' => false ,
2009-11-24 16:32:02 +00:00
'raw' => false ,
'ajax' => false
), $options );
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
$content = $this -> getBody ( $name , true );
2009-12-23 15:12:13 +00:00
$title = $this -> getTitle ( $name , true );
2009-11-24 16:32:02 +00:00
$return = $options [ 'return' ];
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
if ( $options [ 'ajax' ] || e_AJAX_REQUEST )
{
$type = $options [ 'ajax' ] && is_string ( $options [ 'ajax' ]) ? $options [ 'ajax' ] : '' ;
$this -> getJsHelper () -> sendResponse ( $type );
}
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
if ( $options [ 'messages' ])
{
$content = e107 :: getMessage () -> render () . $content ;
}
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
if ( $options [ 'meta' ])
{
$this -> sendMeta ();
}
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
// raw output expected - force return array
if ( $options [ 'raw' ])
{
return array ( $title , $content , $this -> getRenderMod ( $name ));
}
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
//render disabled by the controller
if ( ! $this -> getRenderMod ( $name ))
{
$options [ 'render' ] = false ;
}
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
if ( $options [ 'render' ])
{
return e107 :: getRender () -> tablerender ( $title , $content , $this -> getRenderMod ( $name ), $return );
}
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
if ( $return )
{
return $content ;
}
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
print ( $content );
return '' ;
}
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
/**
* Get JS Helper instance
*
* @ return e_jshelper
*/
public function getJsHelper ()
{
return e107 :: getSingleton ( 'e_jshelper' , true , 'admin_response' );
}
}
/**
* TODO - request related code should be moved to core
* request handler
*/
class e_admin_dispatcher
{
/**
* @ var e_admin_request
*/
2020-12-23 16:01:20 -08:00
protected $_request ;
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
/**
* @ var e_admin_response
*/
2020-12-23 16:01:20 -08:00
protected $_response ;
2009-12-23 15:12:13 +00:00
/**
2009-11-24 16:32:02 +00:00
* @ var e_admin_controller
*/
2020-12-23 16:01:20 -08:00
protected $_current_controller ;
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
/**
* Required ( set by child class ) .
2009-12-23 15:12:13 +00:00
* Controller map array in format
2009-11-24 16:32:02 +00:00
* 'MODE' => array ( 'controller' => 'CONTROLLER_CLASS_NAME' [, 'path' => 'CONTROLLER SCRIPT PATH' , 'ui' => extend of 'comments_admin_form_ui' , 'uipath' => 'path/to/ui/' ]);
2009-12-23 15:12:13 +00:00
*
2009-11-24 16:32:02 +00:00
* @ var array
*/
2012-01-20 15:53:59 +00:00
protected $modes = array ();
/**
* Optional - access restrictions per action
* Access array in format ( similar to adminMenu )
* 'MODE/ACTION' => e_UC_ * ( userclass constant , or custom userclass ID if dynamically set )
*
* @ var array
*/
protected $access = array ();
/**
* Optional - generic entry point access restriction ( via getperms ())
* Value of this for plugins would be always 'P' .
2015-06-05 22:00:25 -07:00
* When an array is detected , route mode / action = admin perms is used . ( similar to $access )
2012-01-20 15:53:59 +00:00
* More detailed access control is granted with $access and $modes [ MODE ][ 'perm' ] or $modes [ MODE ][ 'userclass' ] settings
*
2015-06-05 22:00:25 -07:00
* @ var string | array
2012-01-20 15:53:59 +00:00
*/
protected $perm ;
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
/**
* @ var string
*/
protected $defaultMode = '' ;
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
/**
* @ var string
*/
protected $defaultAction = '' ;
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
/**
2009-12-23 15:12:13 +00:00
* Optional - map 'mode/action' pair to 'modeAlias/actionAlias'
2009-11-24 16:32:02 +00:00
* @ var string
*/
protected $adminMenuAliases = array ();
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
/**
* Optional ( set by child class ) .
* Required for admin menu render
* Format : 'mode/action' => array ( 'caption' => 'Link title' [, 'perm' => '0' , 'url' => '{e_PLUGIN}plugname/admin_config.php' ], ... );
2012-01-20 15:53:59 +00:00
* Note that 'perm' and 'userclass' restrictions are inherited from the $modes , $access and $perm , so you don ' t have to set that vars if
* you don 't need any additional ' visual ' control .
2012-12-03 01:40:47 -08:00
* All valid key - value pair ( see e107 :: getNav () -> admin function ) are accepted .
2009-11-24 16:32:02 +00:00
* @ var array
*/
protected $adminMenu = array ();
2013-03-07 10:59:43 +02:00
2020-12-23 16:01:20 -08:00
protected $adminMenuIcon ;
2013-03-07 10:59:43 +02:00
/**
* Optional ( set by child class ) .
* Page titles for pages not in adminMenu ( e . g . main / edit )
* Format array ( mod / action => Page Title )
* @ var string
*/
protected $pageTitles = array (
'main/edit' => LAN_MANAGE ,
);
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
/**
* Optional ( set by child class ) .
* @ var string
*/
protected $menuTitle = 'Menu' ;
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
/**
* @ var string
*/
protected $pluginTitle = '' ;
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
/**
2009-12-23 15:12:13 +00:00
* Constructor
*
2009-11-24 16:32:02 +00:00
* @ param string | array | e_admin_request $request [ optional ]
* @ param e_admin_response $response
*/
2013-02-22 16:12:05 +02:00
public function __construct ( $auto_observe = true , $request = null , $response = null )
2009-11-24 16:32:02 +00:00
{
2012-11-28 09:35:06 +02:00
// we let know some admin routines we are in UI mod - related with some legacy checks and fixes
if ( ! defined ( 'e_ADMIN_UI' ))
{
define ( 'e_ADMIN_UI' , true );
}
2015-09-05 23:58:01 -07:00
if ( ! empty ( $_GET [ 'iframe' ]))
{
define ( 'e_IFRAME' , true );
}
2012-11-29 10:47:26 +02:00
require_once ( e_ADMIN . 'boot.php' );
2020-12-23 16:01:20 -08:00
if ( $request === null || ! is_object ( $request ))
2009-11-24 16:32:02 +00:00
{
$request = new e_admin_request ( $request );
}
2009-12-23 15:12:13 +00:00
2020-12-23 16:01:20 -08:00
if ( $response === null )
2009-11-24 16:32:02 +00:00
{
$response = new e_admin_response ();
}
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
$this -> setRequest ( $request ) -> setResponse ( $response ) -> init ();
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
if ( ! $this -> defaultMode || ! $this -> defaultAction )
{
$this -> setDefaults ();
}
2009-12-23 15:12:13 +00:00
2020-03-11 17:04:51 -07:00
// current user does not have access to default route, so find a new one.
if ( ! $hasAccess = $this -> hasRouteAccess ( $this -> defaultMode . '/' . $this -> defaultAction ))
{
if ( $newRoute = $this -> getApprovedAccessRoute ())
{
list ( $this -> defaultMode , $this -> defaultAction ) = explode ( '/' , $newRoute );
}
}
2009-11-24 16:32:02 +00:00
$request -> setDefaultMode ( $this -> defaultMode ) -> setDefaultAction ( $this -> defaultAction );
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
// register itself
e107 :: setRegistry ( 'admin/ui/dispatcher' , $this );
2012-01-20 15:53:59 +00:00
// permissions and restrictions
$this -> checkAccess ();
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
if ( $auto_observe )
{
2020-12-23 16:01:20 -08:00
$this -> runObservers ();
2009-11-24 16:32:02 +00:00
}
}
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
/**
* User defined constructor - called before _initController () method
* @ return e_admin_dispatcher
*/
public function init ()
{
}
2012-01-20 15:53:59 +00:00
public function checkAccess ()
{
$request = $this -> getRequest ();
$currentMode = $request -> getMode ();
// access based on mode setting - general controller access
2020-03-11 17:04:51 -07:00
if ( ! $this -> hasModeAccess ( $currentMode ))
2012-01-20 15:53:59 +00:00
{
$request -> setAction ( 'e403' );
2017-03-19 16:42:57 +00:00
e107 :: getMessage () -> addError ( LAN_NO_PERMISSIONS )
2012-01-20 15:53:59 +00:00
-> addDebug ( 'Mode access restriction triggered.' );
return false ;
}
// access based on $access settings - access per action
$currentAction = $request -> getAction ();
$route = $currentMode . '/' . $currentAction ;
2020-03-11 17:04:51 -07:00
if ( ! $this -> hasRouteAccess ( $route ))
2012-01-20 15:53:59 +00:00
{
$request -> setAction ( 'e403' );
2017-03-19 16:42:57 +00:00
e107 :: getMessage () -> addError ( LAN_NO_PERMISSIONS )
2015-06-05 22:00:25 -07:00
-> addDebug ( 'Route access restriction triggered:' . $route );
2012-01-20 15:53:59 +00:00
return false ;
}
return true ;
}
2020-03-11 17:04:51 -07:00
public function hasModeAccess ( $mode )
2012-01-20 15:53:59 +00:00
{
// mode userclass (former check_class())
if ( isset ( $this -> modes [ $mode ][ 'userclass' ]) && ! e107 :: getUser () -> checkClass ( $this -> modes [ $mode ][ 'userclass' ], false ))
{
return false ;
}
// mode admin permission (former getperms())
if ( isset ( $this -> modes [ $mode ][ 'perm' ]) && ! e107 :: getUser () -> checkAdminPerms ( $this -> modes [ $mode ][ 'perm' ]))
{
return false ;
}
2017-02-18 15:31:41 -08:00
2012-01-20 15:53:59 +00:00
// generic dispatcher admin permission (former getperms())
2020-12-23 16:01:20 -08:00
if ( $this -> perm !== null && is_string ( $this -> perm ) && ! e107 :: getUser () -> checkAdminPerms ( $this -> perm ))
2012-01-20 15:53:59 +00:00
{
return false ;
}
2017-02-18 15:31:41 -08:00
2012-01-20 15:53:59 +00:00
return true ;
}
2020-03-11 17:04:51 -07:00
public function hasRouteAccess ( $route )
2012-01-20 15:53:59 +00:00
{
if ( isset ( $this -> access [ $route ]) && ! e107 :: getUser () -> checkClass ( $this -> access [ $route ], false ))
{
2020-12-23 16:01:20 -08:00
e107 :: getMessage () -> addDebug ( 'Userclass Permissions Failed: ' . $this -> access [ $route ]);
2012-01-20 15:53:59 +00:00
return false ;
}
2015-06-05 22:00:25 -07:00
2017-02-18 15:31:41 -08:00
if ( is_array ( $this -> perm ) && isset ( $this -> perm [ $route ]) && ! e107 :: getUser () -> checkAdminPerms ( $this -> perm [ $route ]))
2015-06-05 22:00:25 -07:00
{
2020-12-23 16:01:20 -08:00
e107 :: getMessage () -> addDebug ( 'Admin Permissions Failed.' . $this -> perm [ $route ]);
2015-06-05 22:00:25 -07:00
return false ;
}
2012-01-20 15:53:59 +00:00
return true ;
}
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
/**
* Retrieve missing default action / mode
* @ return e_admin_dispatcher
*/
public function setDefaults ()
{
// try Admin menu first
if ( $this -> adminMenu )
{
reset ( $this -> adminMenu );
2010-12-27 12:38:14 +00:00
list ( $mode , $action ) = explode ( '/' , key ( $this -> adminMenu ), 3 );
2009-11-24 16:32:02 +00:00
}
else
{
reset ( $this -> modes );
$mode = key ( $this -> modes );
$action = $this -> modes [ $mode ][ 'index' ];
}
2009-12-23 15:12:13 +00:00
2020-03-11 17:04:51 -07:00
2020-12-23 16:01:20 -08:00
if ( ! $this -> defaultMode )
{
$this -> defaultMode = $mode ;
}
if ( ! $this -> defaultAction )
{
$this -> defaultAction = $action ;
}
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
return $this ;
}
2009-12-23 15:12:13 +00:00
2020-03-11 17:04:51 -07:00
/**
* Search through access for an approved route .
* Returns false if no approved route found .
*
* @ return string | bool
*/
private function getApprovedAccessRoute ()
{
if ( empty ( $this -> access ))
{
return false ;
}
foreach ( $this -> access as $route => $uclass )
{
if ( check_class ( $uclass ))
{
return $route ;
}
}
return false ;
}
2013-02-22 16:12:05 +02:00
/**
* Get admin menu array
* @ return array
*/
public function getMenuData ()
{
return $this -> adminMenu ;
}
2013-03-07 10:59:43 +02:00
/**
* Get admin menu array
* @ return array
*/
public function getPageTitles ()
{
return $this -> pageTitles ;
}
2013-02-22 16:12:05 +02:00
/**
* Get admin menu array
* @ return array
*/
public function getMenuAliases ()
{
return $this -> adminMenuAliases ;
}
2009-11-24 16:32:02 +00:00
/**
* Get request object
* @ return e_admin_request
*/
public function getRequest ()
{
return $this -> _request ;
}
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
/**
* Set request object
* @ param e_admin_request $request
* @ return e_admin_dispatcher
*/
public function setRequest ( $request )
{
$this -> _request = $request ;
return $this ;
}
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
/**
* Get response object
* @ return e_admin_response
*/
public function getResponse ()
{
return $this -> _response ;
}
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
/**
* Set response object
* @ param e_admin_response $response
* @ return e_admin_dispatcher
*/
public function setResponse ( $response )
{
$this -> _response = $response ;
return $this ;
}
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
/**
* Dispatch & render all
2009-12-23 15:12:13 +00:00
*
2012-01-20 15:53:59 +00:00
* @ param boolean $run_header see runObservers ()
* @ param boolean $return see runPage ()
2009-11-24 16:32:02 +00:00
* @ return string | array current admin page body
*/
2012-01-20 15:53:59 +00:00
public function run ( $run_header = true , $return = 'render' )
2009-11-24 16:32:02 +00:00
{
2012-01-20 15:53:59 +00:00
return $this -> runObservers () -> runPage ( $return );
2009-11-24 16:32:02 +00:00
}
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
/**
* Run observers / headers only , should be called before header . php call
2009-12-23 15:12:13 +00:00
*
2009-11-24 16:32:02 +00:00
* @ return e_admin_dispatcher
*/
public function runObservers ( $run_header = true )
{
//search for $actionName.'Observer' method. Additional $actionName.$triggerName.'Trigger' methods will be called as well
$this -> getController () -> dispatchObserver ();
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
//search for $actionName.'Header' method, js manager should be used inside for sending JS to the page,
// meta information should be created there as well
if ( $run_header )
{
$this -> getController () -> dispatchHeader ();
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
}
return $this ;
}
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
/**
* Run page action .
* If return type is array , it should contain allowed response options ( see e_admin_response :: send ())
* Available return type string values :
* - render_return : return rendered content ( see e107 :: getRender () -> tablerender ()), add system messages , send meta information
* - render : outputs rendered content ( see e107 :: getRender () -> tablerender ()), add system messages
* - response : return response object
* - raw : return array ( title , content , render mode )
* - ajax : force ajax output ( and exit )
2009-12-23 15:12:13 +00:00
*
2009-11-24 16:32:02 +00:00
* @ param string | array $return_type expected string values : render | render_out | response | raw | ajax [ _text | _json | _xml ]
* @ return mixed
*/
public function runPage ( $return_type = 'render' )
{
$response = $this -> getController () -> dispatchPage ();
if ( is_array ( $return_type ))
{
return $response -> send ( 'default' , $return_type );
}
switch ( $return_type )
{
case 'render_return' :
$options = array (
2009-12-23 15:12:13 +00:00
'messages' => true ,
'render' => true ,
'meta' => true ,
'return' => true ,
2009-11-24 16:32:02 +00:00
'raw' => false
);
break ;
case 'raw' :
$options = array (
2009-12-23 15:12:13 +00:00
'messages' => false ,
'render' => false ,
'meta' => false ,
'return' => true ,
2009-11-24 16:32:02 +00:00
'raw' => true
);
break ;
case 'ajax' :
case 'ajax_text' :
case 'ajax_xml' ;
case 'ajax_json' ;
$options = array (
2009-12-23 15:12:13 +00:00
'messages' => false ,
'render' => false ,
'meta' => false ,
'return' => false ,
2009-11-24 16:32:02 +00:00
'raw' => false ,
'ajax' => str_replace ( array ( 'ajax_' , 'ajax' ), array ( '' , 'text' ), $return_type )
);
break ;
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
case 'response' :
return $response ;
break ;
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
case 'render' :
default :
$options = array (
2009-12-23 15:12:13 +00:00
'messages' => true ,
'render' => true ,
'meta' => false ,
'return' => false ,
2009-11-24 16:32:02 +00:00
'raw' => false
);
break ;
}
return $response -> send ( 'default' , $options );
}
2009-12-23 15:12:13 +00:00
2015-06-05 22:00:25 -07:00
/**
* Get perms
* @ return array | string
*/
public function getPerm ()
{
return $this -> perm ;
}
2009-11-24 16:32:02 +00:00
/**
* Proxy method
2009-12-23 15:12:13 +00:00
*
2009-11-24 16:32:02 +00:00
* @ return string
*/
public function getHeader ()
{
return $this -> getController () -> getHeader ();
}
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
/**
* Get current controller object
* @ return e_admin_controller
*/
public function getController ()
{
2020-12-23 16:01:20 -08:00
if ( $this -> _current_controller === null )
2009-11-24 16:32:02 +00:00
{
$this -> _initController ();
}
return $this -> _current_controller ;
}
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
/**
* Try to init Controller from request using current controller map
2009-12-23 15:12:13 +00:00
*
2009-11-24 16:32:02 +00:00
* @ return e_admin_dispatcher
*/
protected function _initController ()
{
$request = $this -> getRequest ();
$response = $this -> getResponse ();
if ( isset ( $this -> modes [ $request -> getModeName ()]) && isset ( $this -> modes [ $request -> getModeName ()][ 'controller' ]))
{
$class_name = $this -> modes [ $request -> getModeName ()][ 'controller' ];
$class_path = vartrue ( $this -> modes [ $request -> getModeName ()][ 'path' ]);
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
if ( $class_path )
{
require_once ( e107 :: getParser () -> replaceConstants ( $class_path ));
}
if ( $class_name && class_exists ( $class_name )) //NOTE: autoload in the play
{
$this -> _current_controller = new $class_name ( $request , $response );
//give access to current request object, user defined init
2009-12-23 15:12:13 +00:00
$this -> _current_controller -> setRequest ( $this -> getRequest ()) -> init ();
2009-11-24 16:32:02 +00:00
}
2012-01-19 13:17:26 +00:00
// Known controller (found in e_admin_dispatcher::$modes), class not found exception
2009-11-24 16:32:02 +00:00
else
{
2012-01-19 13:17:26 +00:00
// TODO - admin log
2009-12-23 15:12:13 +00:00
// get default controller
2009-11-24 16:32:02 +00:00
$this -> _current_controller = $this -> getDefaultController ();
// add messages
2012-01-19 13:17:26 +00:00
e107 :: getMessage () -> add ( 'Can\'t find class <strong>"' . ( $class_name ? $class_name : 'n/a' ) . '"</strong> for controller <strong>"' . ucfirst ( $request -> getModeName ()) . '"</strong>' , E_MESSAGE_ERROR )
2017-02-09 10:19:55 -08:00
-> add ( 'Requested: ' . e_REQUEST_SELF . '?' . $request -> buildQueryString (), E_MESSAGE_DEBUG );
2009-12-23 15:12:13 +00:00
//
2009-11-24 16:32:02 +00:00
$request -> setMode ( $this -> getDefaultControllerName ()) -> setAction ( 'e404' );
2009-12-23 15:12:13 +00:00
$this -> _current_controller -> setRequest ( $request ) -> init ();
2009-11-24 16:32:02 +00:00
}
2009-12-23 15:12:13 +00:00
2020-12-20 11:50:10 -08:00
if ( ! empty ( $this -> modes [ $request -> getModeName ()][ 'ui' ]))
2009-11-24 16:32:02 +00:00
{
$class_name = $this -> modes [ $request -> getModeName ()][ 'ui' ];
$class_path = vartrue ( $this -> modes [ $request -> getModeName ()][ 'uipath' ]);
if ( $class_path )
{
require_once ( e107 :: getParser () -> replaceConstants ( $class_path ));
}
if ( class_exists ( $class_name )) //NOTE: autoload in the play
{
$this -> _current_controller -> setParam ( 'ui' , new $class_name ( $this -> _current_controller ));
}
}
$this -> _current_controller -> setParam ( 'modes' , $this -> modes );
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
}
2012-01-19 13:17:26 +00:00
// Not known controller (not found in e_admin_dispatcher::$modes) exception
else
{
// TODO - admin log
$this -> _current_controller = $this -> getDefaultController ();
// add messages
e107 :: getMessage () -> add ( 'Can\'t find class for controller <strong>"' . ucfirst ( $request -> getModeName ()) . '"</strong>' , E_MESSAGE_ERROR )
2017-02-09 10:19:55 -08:00
-> add ( 'Requested: ' . e_REQUEST_SELF . '?' . $request -> buildQueryString (), E_MESSAGE_DEBUG );
2012-01-19 13:17:26 +00:00
// go to not found page
$request -> setMode ( $this -> getDefaultControllerName ()) -> setAction ( 'e404' );
$this -> _current_controller -> setRequest ( $request ) -> init ();
}
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
return $this ;
}
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
/**
* Default controller object - needed if controller not found
* @ return e_admin_controller
*/
public function getDefaultController ()
{
$class_name = $this -> getDefaultControllerName ();
return new $class_name ( $this -> getRequest (), $this -> getResponse ());
}
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
/**
* Default controller name - needed if controller not found
2009-12-13 21:52:32 +00:00
* @ return string name of controller
2009-11-24 16:32:02 +00:00
*/
public function getDefaultControllerName ()
{
return 'e_admin_controller' ;
}
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
/**
* Generic Admin Menu Generator
* @ return string
*/
2020-12-23 16:01:20 -08:00
public function renderMenu ()
2009-11-24 16:32:02 +00:00
{
2013-03-03 20:54:08 -08:00
2009-11-24 16:32:02 +00:00
$tp = e107 :: getParser ();
$var = array ();
2010-12-27 12:38:14 +00:00
$selected = false ;
2018-05-23 16:29:37 -07:00
2009-11-24 16:32:02 +00:00
foreach ( $this -> adminMenu as $key => $val )
{
2015-06-06 02:33:23 -07:00
2015-09-06 11:00:07 -07:00
if ( isset ( $val [ 'perm' ]) && $val [ 'perm' ] !== '' && ! getperms ( $val [ 'perm' ]))
2015-06-06 02:33:23 -07:00
{
continue ;
}
2010-12-27 12:38:14 +00:00
$tmp = explode ( '/' , trim ( $key , '/' ), 3 );
2011-05-18 13:41:19 +00:00
2012-01-20 15:53:59 +00:00
// sync with mode/route access
2020-03-11 17:04:51 -07:00
if ( ! $this -> hasModeAccess ( $tmp [ 0 ]) || ! $this -> hasRouteAccess ( $tmp [ 0 ] . '/' . varset ( $tmp [ 1 ])))
2012-01-20 15:53:59 +00:00
{
continue ;
}
2010-12-27 12:38:14 +00:00
// custom 'selected' check
2020-12-23 16:01:20 -08:00
if ( isset ( $val [ 'selected' ]) && $val [ 'selected' ])
{
$selected = $val [ 'selected' ] === true ? $key : $val [ 'selected' ];
}
2011-05-18 13:41:19 +00:00
2009-11-24 16:32:02 +00:00
foreach ( $val as $k => $v )
{
switch ( $k )
{
case 'caption' :
$k2 = 'text' ;
2010-10-30 15:34:48 +00:00
$v = defset ( $v , $v );
2019-06-26 13:48:53 -07:00
2009-11-24 16:32:02 +00:00
break ;
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
case 'url' :
$k2 = 'link' ;
2017-02-08 17:40:32 -08:00
$qry = ( isset ( $val [ 'query' ])) ? $val [ 'query' ] : '?mode=' . $tmp [ 0 ] . '&action=' . $tmp [ 1 ];
$v = $tp -> replaceConstants ( $v , 'abs' ) . $qry ;
2009-11-24 16:32:02 +00:00
break ;
2011-05-18 13:41:19 +00:00
2010-12-27 12:38:14 +00:00
case 'uri' :
$k2 = 'link' ;
$v = $tp -> replaceConstants ( $v , 'abs' );
2018-05-23 16:29:37 -07:00
2020-12-23 16:01:20 -08:00
if ( ! empty ( $v ) && ( $v === e_REQUEST_URI ))
2018-05-23 16:29:37 -07:00
{
$selected = $key ;
}
2010-12-27 12:38:14 +00:00
break ;
2009-12-23 15:12:13 +00:00
2019-06-26 13:48:53 -07:00
case 'badge' : // array('value'=> int, 'type'=>'warning');
$k2 = 'badge' ;
$v = ( array ) $v ;
break ;
2021-02-01 09:32:12 -08:00
case 'icon' :
$k2 = 'image_src' ;
$v = ( string ) $v . '.glyph' ;
break ;
2009-11-24 16:32:02 +00:00
default :
$k2 = $k ;
2013-03-06 23:01:16 -08:00
2009-11-24 16:32:02 +00:00
break ;
}
2010-03-01 12:59:26 +00:00
2013-03-06 23:01:16 -08:00
2012-01-20 15:53:59 +00:00
// Access check done above
// if($val['perm']!= null) // check perms
// {
// if(getperms($val['perm']))
// {
// $var[$key][$k2] = $v;
// }
// }
// else
2009-12-28 00:29:39 +00:00
{
2010-03-01 12:59:26 +00:00
$var [ $key ][ $k2 ] = $v ;
2013-03-06 23:01:16 -08:00
2009-12-28 00:29:39 +00:00
}
2010-03-01 12:59:26 +00:00
2009-11-24 16:32:02 +00:00
}
2021-02-01 18:18:30 -08:00
// guess an icon.
if ( ! isset ( $var [ $key ][ 'image_src' ]))
{
$var [ $key ][ 'image_src' ] = $this -> guessMenuIcon ( $key );
}
2013-03-06 23:01:16 -08:00
2009-11-24 16:32:02 +00:00
// TODO slide down menu options?
if ( ! vartrue ( $var [ $key ][ 'link' ]))
{
2017-02-09 10:19:55 -08:00
$var [ $key ][ 'link' ] = e_REQUEST_SELF . '?mode=' . $tmp [ 0 ] . '&action=' . $tmp [ 1 ]; // FIXME - URL based on $modes, remove url key
2009-11-24 16:32:02 +00:00
}
2009-12-23 15:12:13 +00:00
2013-03-06 23:01:16 -08:00
if ( varset ( $val [ 'tab' ]))
{
2020-12-23 16:01:20 -08:00
$var [ $key ][ 'link' ] .= '&tab=' . $val [ 'tab' ];
2013-03-06 23:01:16 -08:00
}
2009-11-24 16:32:02 +00:00
/* $var [ $key ][ 'text' ] = $val [ 'caption' ];
$var [ $key ][ 'link' ] = ( vartrue ( $val [ 'url' ]) ? $tp -> replaceConstants ( $val [ 'url' ], 'abs' ) : e_SELF ) . '?mode=' . $tmp [ 0 ] . '&action=' . $tmp [ 1 ];
$var [ $key ][ 'perm' ] = $val [ 'perm' ]; */
2015-07-11 14:07:04 -07:00
if ( ! empty ( $val [ 'modal' ]))
{
$var [ $key ][ 'link_class' ] = ' e-modal' ;
if ( ! empty ( $val [ 'modal-caption' ]))
{
$var [ $key ][ 'link_data' ] = array ( 'data-modal-caption' => $val [ 'modal-caption' ]);
}
}
2009-11-24 16:32:02 +00:00
}
2015-06-06 02:33:23 -07:00
2020-12-23 16:01:20 -08:00
if ( empty ( $var ))
{
return '' ;
}
2015-09-06 11:00:07 -07:00
2009-11-24 16:32:02 +00:00
$request = $this -> getRequest ();
2020-12-23 16:01:20 -08:00
if ( ! $selected )
{
$selected = $request -> getMode () . '/' . $request -> getAction ();
}
2009-11-24 16:32:02 +00:00
$selected = vartrue ( $this -> adminMenuAliases [ $selected ], $selected );
2016-11-01 16:42:47 -07:00
2017-04-21 12:13:12 -07:00
$icon = '' ;
2016-11-01 16:42:47 -07:00
2017-04-21 12:13:12 -07:00
if ( ! empty ( $this -> adminMenuIcon ))
{
$icon = e107 :: getParser () -> toIcon ( $this -> adminMenuIcon );
}
elseif ( deftrue ( 'e_CURRENT_PLUGIN' ))
{
2018-01-09 11:21:16 -08:00
$icon = e107 :: getPlug () -> load ( e_CURRENT_PLUGIN ) -> getIcon ( 24 );
2017-04-21 12:13:12 -07:00
}
2017-04-21 14:21:29 -07:00
2021-01-29 09:27:38 -08:00
$toggle = " <span class='e-toggle-sidebar'><!-- --></span> " ;
2021-01-29 11:03:04 -08:00
$var [ '_extras_' ] = array ( 'icon' => $icon , 'return' => true );
2021-01-29 09:27:38 -08:00
// $var['_icon_'] = $icon;
return e107 :: getNav () -> admin ( $this -> menuTitle , $selected , $var );
2009-11-24 16:32:02 +00:00
}
2013-03-03 20:54:08 -08:00
2021-02-01 18:18:30 -08:00
/**
* Guess the admin menu item icon based on the path
* @ param $key
* @ return string
*/
private function guessMenuIcon ( $key )
{
list ( $mode , $action ) = explode ( '/' , $key );
switch ( $action )
{
case 'list' :
$ret = $ret = ( $mode === 'cat' ) ? 'fa-folder.glyph' : 'fa-list.glyph' ;
break ;
case 'options' :
case 'prefs' :
$ret = 'fa-cog.glyph' ;
break ;
case 'create' :
$ret = ( $mode === 'cat' ) ? 'fa-folder-plus.glyph' : 'fa-plus.glyph' ;
break ;
case 'tools' :
case 'maint' :
$ret = 'fas-toolbox.glyph' ;
break ;
case 'import' :
case 'upload' :
$ret = 'fa-upload.glyph' ;
break ;
default :
$ret = 'fa-question.glyph' ;
// code to be executed if n is different from all labels;
}
return $ret ;
}
2013-03-03 20:54:08 -08:00
/**
* Render Help Text in < ul > format . XXX TODO
*/
2020-12-23 16:01:20 -08:00
public function renderHelp ()
2013-03-03 20:54:08 -08:00
{
2015-04-08 20:20:10 -07:00
2013-03-03 20:54:08 -08:00
}
/**
* Check for table issues and warn the user . XXX TODO
* ie . user is using French interface but no french tables found for the current DB tables .
*/
2020-12-23 16:01:20 -08:00
public function renderWarnings ()
2013-03-03 20:54:08 -08:00
{
}
2009-11-24 16:32:02 +00:00
}
class e_admin_controller
{
/**
* @ var e_admin_request
*/
protected $_request ;
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
/**
* @ var e_admin_response
*/
protected $_response ;
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
/**
* @ var array User defined parameters
*/
protected $_params = array ();
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
/**
* @ var string default action name
*/
protected $_default_action = 'index' ;
2019-05-09 15:14:56 -07:00
/**
* @ var string default trigger action .
*/
protected $_default_trigger = 'auto' ;
2012-01-20 15:53:59 +00:00
/**
* List ( numerical array ) of only allowed for this controller actions
* Useful to grant access for certain pre - defined actions only
* XXX - we may move this in dispatcher ( or even having it also there ), still searching the most 'friendly' way
* @ var array
*/
protected $allow = array ();
/**
* List ( numerical array ) of only disallowed for this controller actions
* Useful to restrict access for certain pre - defined actions only
* XXX - we may move this in dispatcher ( or even having it also there ), still searching the most 'friendly' way
* @ var array
*/
protected $disallow = array ();
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
/**
2009-12-23 15:12:13 +00:00
* Constructor
2020-12-08 12:21:12 -08:00
* @ param e_admin_request $request
2009-11-24 16:32:02 +00:00
*/
public function __construct ( $request , $response , $params = array ())
{
$this -> _params = array_merge ( array ( 'enable_triggers' => false ), $params );
$this -> setRequest ( $request )
-> setResponse ( $response )
-> setParams ( $params );
2012-01-20 15:53:59 +00:00
$this -> checkAccess ();
2020-03-27 14:06:44 -07:00
$this -> _log (); // clear the log (when debug is enabled)
2012-01-20 15:53:59 +00:00
}
/**
* Check against allowed / disallowed actions
2013-02-22 16:12:05 +02:00
* FIXME check plugin admin access ( check_class ( P )), confirm e - token is verified
2012-01-20 15:53:59 +00:00
*/
public function checkAccess ()
{
$request = $this -> getRequest ();
$currentAction = $request -> getAction ();
// access based on mode setting - general controller access
if ( ! empty ( $this -> disallow ) && in_array ( $currentAction , $this -> disallow ))
{
$request -> setAction ( 'e403' );
2017-03-19 16:42:57 +00:00
e107 :: getMessage () -> addError ( LAN_NO_PERMISSIONS )
2012-01-20 15:53:59 +00:00
-> addDebug ( 'Controller action disallowed restriction triggered.' );
return false ;
}
// access based on $access settings - access per action
if ( ! empty ( $this -> allow ) && ! in_array ( $currentAction , $this -> allow ))
{
$request -> setAction ( 'e403' );
2017-03-19 16:42:57 +00:00
e107 :: getMessage () -> addError ( LAN_NO_PERMISSIONS )
2012-01-20 15:53:59 +00:00
-> addDebug ( 'Controller action not in allowed list restriction triggered.' );
return false ;
}
return true ;
2009-11-24 16:32:02 +00:00
}
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
/**
* User defined init
* Called before dispatch routine
*/
public function init ()
{
}
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
/**
* Get controller parameter
* Currently used core parameters :
* - enable_triggers : don ' t use it direct , see { @ link setTriggersEnabled ()}
* - modes - see dispatcher :: $modes
* - ajax_response - text | xml | json - default is 'text' ; this should be set by the action method
* - TODO - more parameters / add missing to this list
2009-12-23 15:12:13 +00:00
*
* @ param string $key [ optional ] if null - get whole array
2009-11-24 16:32:02 +00:00
* @ param mixed $default [ optional ]
* @ return mixed
*/
public function getParam ( $key = null , $default = null )
{
2020-12-23 16:01:20 -08:00
if ( $key === null )
2009-11-24 16:32:02 +00:00
{
return $this -> _params ;
}
return ( isset ( $this -> _params [ $key ]) ? $this -> _params [ $key ] : $default );
}
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
/**
* Set parameter
* @ param string $key
* @ param mixed $value
* @ return e_admin_controller
*/
public function setParam ( $key , $value )
{
2020-12-23 16:01:20 -08:00
if ( $value === null )
2009-11-24 16:32:02 +00:00
{
unset ( $this -> _params [ $key ]);
return $this ;
}
$this -> _params [ $key ] = $value ;
return $this ;
}
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
/**
* Merge passed parameter array with current parameters
* @ param array $params
* @ return e_admin_controller
*/
public function setParams ( $params )
{
$this -> _params = array_merge ( $this -> _params , $params );
return $this ;
}
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
/**
* Reset parameter array
* @ param array $params
* @ return e_admin_controller
*/
public function resetParams ( $params )
{
$this -> _params = $params ;
return $this ;
}
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
/**
* Get current request object
2009-12-23 15:12:13 +00:00
* @ return e_admin_request
2009-11-24 16:32:02 +00:00
*/
public function getRequest ()
{
return $this -> _request ;
}
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
/**
* Set current request object
* @ param e_admin_request $request
* @ return e_admin_controller
*/
public function setRequest ( $request )
{
$this -> _request = $request ;
return $this ;
}
/**
* Get current response object
2009-12-23 15:12:13 +00:00
* @ return e_admin_response
2009-11-24 16:32:02 +00:00
*/
public function getResponse ()
{
return $this -> _response ;
}
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
/**
* Set current response object
* @ param e_admin_response $response
* @ return e_admin_controller
*/
public function setResponse ( $response )
{
$this -> _response = $response ;
return $this ;
}
2012-01-20 15:53:59 +00:00
/**
* Get current dispatcher object
* @ return e_admin_dispatcher
*/
public function getDispatcher ()
{
return e107 :: getRegistry ( 'admin/ui/dispatcher' );
}
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
/**
2009-12-23 15:12:13 +00:00
* Request proxy method
2009-11-24 16:32:02 +00:00
* @ param string $key [ optional ]
* @ param mixed $default [ optional ]
* @ return mixed
*/
public function getQuery ( $key = null , $default = null )
{
return $this -> getRequest () -> getQuery ( $key , $default );
}
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
/**
2009-12-23 15:12:13 +00:00
* Request proxy method
2009-11-24 16:32:02 +00:00
* @ param string | array $key
* @ param mixed $value [ optional ]
* @ return e_admin_controller
*/
public function setQuery ( $key , $value = null )
{
$this -> getRequest () -> setQuery ( $key , $value );
return $this ;
}
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
/**
2009-12-23 15:12:13 +00:00
* Request proxy method
2009-11-24 16:32:02 +00:00
* @ param string $key [ optional ]
* @ param mixed $default [ optional ]
* @ return mixed
*/
public function getPosted ( $key = null , $default = null )
{
return $this -> getRequest () -> getPosted ( $key , $default );
}
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
/**
2009-12-23 15:12:13 +00:00
* Request proxy method
2020-12-11 08:57:19 -08:00
* @ param string | array $key
2009-11-24 16:32:02 +00:00
* @ param mixed $value [ optional ]
* @ return e_admin_controller
*/
public function setPosted ( $key , $value = null )
{
$this -> getRequest () -> setPosted ( $key , $value );
return $this ;
}
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
/**
* Add page title , response proxy method
*
2013-02-22 16:12:05 +02:00
* @ param string $title if boolean true - current menu caption will be used
2009-11-24 16:32:02 +00:00
* @ param boolean $meta add to meta as well
2019-03-02 10:09:16 -08:00
* @ return object e_admin_controller
2009-11-24 16:32:02 +00:00
*/
2013-02-22 16:12:05 +02:00
public function addTitle ( $title = true , $meta = true )
2009-11-24 16:32:02 +00:00
{
2014-10-24 13:14:51 -07:00
2020-12-23 16:01:20 -08:00
if ( $title === true )
2013-02-22 16:12:05 +02:00
{
$_dispatcher = $this -> getDispatcher ();
2013-03-07 10:59:43 +02:00
$data = $_dispatcher -> getPageTitles ();
2013-02-22 16:12:05 +02:00
$search = $this -> getMode () . '/' . $this -> getAction ();
2017-12-19 13:02:16 -08:00
2018-05-23 16:29:37 -07:00
2017-12-19 13:02:16 -08:00
if ( isset ( $data [ $search ]))
{
$res [ 'caption' ] = $data [ $search ];
}
2013-03-07 10:59:43 +02:00
else
{
2017-12-19 13:02:16 -08:00
2013-03-07 10:59:43 +02:00
$data = $_dispatcher -> getMenuData ();
2017-12-19 13:02:16 -08:00
if ( isset ( $data [ $search ]))
{
$res = $data [ $search ];
}
else
{
// check for an alias match.
$d = $_dispatcher -> getMenuAliases ();
if ( isset ( $d [ $search ]))
{
$search = $d [ $search ];
$res = $data [ $search ];
}
else
{
return $this ;
}
// var_dump($d);
// var_dump("Couldnt find: ".$search);
}
2013-03-07 10:59:43 +02:00
}
2013-02-22 16:12:05 +02:00
$title = $res [ 'caption' ];
2017-12-19 13:02:16 -08:00
2013-02-22 16:12:05 +02:00
}
2014-10-24 13:14:51 -07:00
// echo "<h3>".__METHOD__." - ".$title."</h3>";
2014-01-01 17:38:46 -08:00
// print_a($title);
2009-11-24 16:32:02 +00:00
$this -> getResponse () -> appendTitle ( $title );
2020-12-23 16:01:20 -08:00
if ( $meta )
{
$this -> addMetaTitle ( $title );
}
2019-03-02 10:09:16 -08:00
2009-11-24 16:32:02 +00:00
return $this ;
}
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
/**
* Add page meta title , response proxy method .
* Should be called before header . php
*
* @ param string $title
* @ return e_admin_controller
*/
2016-12-17 09:43:37 -08:00
public function addMetaTitle ( $title = null )
2009-11-24 16:32:02 +00:00
{
2016-12-17 09:43:37 -08:00
if ( $title === null )
{
return $this ;
}
2009-11-24 16:32:02 +00:00
$this -> getResponse () -> addMetaTitle ( $title );
return $this ;
}
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
/**
* Add header content , response proxy method
* Should be called before header . php
2009-12-23 15:12:13 +00:00
*
2009-11-24 16:32:02 +00:00
* @ param string $content
* @ return e_admin_controller
*/
2016-12-17 09:43:37 -08:00
public function addHeader ( $content = null )
2009-11-24 16:32:02 +00:00
{
2016-12-17 09:43:37 -08:00
if ( $content === null )
{
return $this ;
}
2012-12-16 12:28:28 +01:00
$this -> getResponse () -> addHeaderContent ( vartrue ( $content ));
2009-11-24 16:32:02 +00:00
return $this ;
}
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
/**
* Get header content , response proxy method
*
* @ return string
*/
public function getHeader ()
{
return $this -> getResponse () -> getHeaderContent ();
}
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
/**
* Get current mode , response proxy method
* @ return string
*/
public function getMode ()
{
return $this -> getRequest () -> getMode ();
}
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
/**
* Get current actin , response proxy method
* @ return string
*/
public function getAction ()
{
return $this -> getRequest () -> getAction ();
}
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
/**
* Get current ID , response proxy method
* @ return string
*/
public function getId ()
{
return $this -> getRequest () -> getId ();
}
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
/**
* Get response owned JS Helper instance , response proxy method
*
* @ return e_jshelper
*/
public function getJsHelper ()
{
return $this -> getResponse () -> getJsHelper ();
}
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
protected function _preDispatch ( $action = '' )
{
2020-12-23 16:01:20 -08:00
if ( ! $action )
{
$action = $this -> getRequest () -> getActionName ();
}
$method = $this -> toMethodName ( $action );
2009-11-24 16:32:02 +00:00
if ( ! method_exists ( $this , $method ))
{
2020-12-23 16:01:20 -08:00
$this -> _log ( 'Skipping ' . $method . '() (not found)' );
2009-11-24 16:32:02 +00:00
$this -> getRequest () -> setAction ( $this -> getDefaultAction ());
}
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
// switch to 404 if needed
2020-12-23 16:01:20 -08:00
$method = $this -> toMethodName ( $this -> getRequest () -> getActionName ());
2009-11-24 16:32:02 +00:00
if ( ! method_exists ( $this , $method ))
{
2020-12-23 16:01:20 -08:00
$this -> _log ( 'Skipping ' . $method . '() (not found)' );
2009-11-24 16:32:02 +00:00
$this -> getRequest () -> setAction ( 'e404' );
2013-10-29 18:41:02 -07:00
$message = e107 :: getParser () -> lanVars ( LAN_UI_404_METHOD_ERROR , $method , true );
2013-10-29 12:20:23 -07:00
e107 :: getMessage () -> add ( $message , E_MESSAGE_ERROR );
2009-11-24 16:32:02 +00:00
}
}
2009-12-23 15:12:13 +00:00
2020-03-27 14:06:44 -07:00
/**
* Log Controller when e_DEBUG is active .
* @ param string | null $message
* @ return null
*/
protected function _log ( $message = null )
{
if ( ! deftrue ( 'e_DEBUG' ))
{
return null ;
}
if ( $message === null ) // clear the log.
{
2020-12-23 16:01:20 -08:00
file_put_contents ( e_LOG . 'adminUI.log' , '' );
2020-03-27 14:06:44 -07:00
return null ;
}
$date = ( ! empty ( $message )) ? date ( 'c' ) : '' ;
2020-12-23 16:01:20 -08:00
file_put_contents ( e_LOG . 'adminUI.log' , $date . " \t " . $message . " \n " , FILE_APPEND );
2020-03-27 14:06:44 -07:00
}
2009-11-24 16:32:02 +00:00
/**
* Dispatch observer , check for triggers
2009-12-23 15:12:13 +00:00
*
2009-11-24 16:32:02 +00:00
* @ param string $action [ optional ]
* @ return e_admin_controller
*/
public function dispatchObserver ( $action = null )
{
$request = $this -> getRequest ();
2020-12-23 16:01:20 -08:00
if ( $request === null )
2009-11-24 16:32:02 +00:00
{
$request = new e_admin_request ();
$this -> setRequest ( $request );
}
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
$this -> _preDispatch ( $action );
2020-12-23 16:01:20 -08:00
if ( $action === null )
2009-11-24 16:32:02 +00:00
{
$action = $request -> getActionName ();
}
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
// check for observer
$actionObserverName = $this -> toMethodName ( $action , 'observer' , e_AJAX_REQUEST );
if ( method_exists ( $this , $actionObserverName ))
{
2020-12-23 16:01:20 -08:00
$this -> _log ( 'Executing ' . $actionObserverName . '()' );
2009-11-24 16:32:02 +00:00
$this -> $actionObserverName ();
2020-03-27 14:06:44 -07:00
}
else
{
2020-12-23 16:01:20 -08:00
$this -> _log ( 'Skipping ' . $actionObserverName . '() (not found)' );
2009-11-24 16:32:02 +00:00
}
// check for triggers, not available in Ajax mode
2020-12-23 16:01:20 -08:00
$triggerEnabled = $this -> triggersEnabled ();
if ( ! e_AJAX_REQUEST && $triggerEnabled )
2009-11-24 16:32:02 +00:00
{
2021-01-20 12:07:29 -08:00
if ( $posted = $request -> getPosted ())
2009-11-24 16:32:02 +00:00
{
2021-01-20 12:07:29 -08:00
foreach ( $posted as $key => $value )
2009-11-24 16:32:02 +00:00
{
2021-01-20 12:07:29 -08:00
if ( strpos ( $key , 'etrigger_' ) === 0 )
2009-11-24 16:32:02 +00:00
{
2021-01-20 12:07:29 -08:00
$actionTriggerName = $this -> toMethodName ( $action . $request -> camelize ( substr ( $key , 9 )), 'trigger' , false );
if ( method_exists ( $this , $actionTriggerName ))
{
$this -> $actionTriggerName ( $value );
}
//Check if triggers are still enabled
if ( ! $triggerEnabled )
{
break ;
}
2009-11-24 16:32:02 +00:00
}
}
}
}
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
return $this ;
}
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
/**
* Dispatch header , not allowed in Ajax mode
* @ param string $action [ optional ]
* @ return e_admin_controller
*/
public function dispatchHeader ( $action = null )
{
// not available in Ajax mode
if ( e_AJAX_REQUEST )
{
return $this ;
}
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
$request = $this -> getRequest ();
2020-12-23 16:01:20 -08:00
if ( $request === null )
2009-11-24 16:32:02 +00:00
{
$request = new e_admin_request ();
$this -> setRequest ( $request );
}
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
$this -> _preDispatch ( $action );
2020-12-23 16:01:20 -08:00
if ( $action === null )
2009-11-24 16:32:02 +00:00
{
$action = $request -> getActionName ();
}
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
// check for observer
2009-12-23 15:12:13 +00:00
$actionHeaderName = $this -> toMethodName ( $action , 'header' , false );
2009-11-24 16:32:02 +00:00
if ( method_exists ( $this , $actionHeaderName ))
{
$this -> $actionHeaderName ();
}
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
//send meta data
$this -> getResponse () -> sendMeta ();
return $this ;
}
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
/**
* Dispatch controller action
2009-12-23 15:12:13 +00:00
*
2009-11-24 16:32:02 +00:00
* @ param string $action [ optional ]
* @ return e_admin_response
*/
public function dispatchPage ( $action = null )
{
$request = $this -> getRequest ();
2020-12-23 16:01:20 -08:00
if ( $request === null )
2009-11-24 16:32:02 +00:00
{
$request = new e_admin_request ();
$this -> setRequest ( $request );
}
$response = $this -> getResponse ();
2014-10-24 13:14:51 -07:00
// print_a($response);
2009-12-23 15:12:13 +00:00
$this -> _preDispatch ( $action );
2020-12-23 16:01:20 -08:00
if ( $action === null )
2009-11-24 16:32:02 +00:00
{
$action = $request -> getActionName ();
}
2011-05-18 13:41:19 +00:00
2009-11-24 16:32:02 +00:00
// check for observer
2020-12-23 16:01:20 -08:00
$actionName = $this -> toMethodName ( $action );
2009-11-24 16:32:02 +00:00
$ret = '' ;
if ( ! method_exists ( $this , $actionName )) // pre dispatch already switched to default action/not found page if needed
{
2020-12-23 16:01:20 -08:00
$this -> _log ( 'Skipping ' . $actionName . '() (not found)' );
2009-11-24 16:32:02 +00:00
e107 :: getMessage () -> add ( 'Action ' . $actionName . ' no found!' , E_MESSAGE_ERROR );
return $response ;
}
2020-12-23 16:01:20 -08:00
$this -> _log ( 'Executing ' . $actionName . '()' );
if ( $action !== 'Prefs' && $action !== 'Create' && $action !== 'Edit' && $action !== 'List' ) // Custom Page method in use, so add the title.
2014-10-24 13:14:51 -07:00
{
2018-05-23 16:29:37 -07:00
$this -> addTitle ();
2014-12-10 17:30:01 -08:00
}
2016-05-15 15:04:25 -07:00
// e107::getDebug()->log("Admin-ui Action: <b>".$action."</b>");
2020-03-11 14:52:34 -07:00
2018-05-23 16:29:37 -07:00
2014-10-24 13:14:51 -07:00
2009-11-24 16:32:02 +00:00
ob_start (); //catch any output
$ret = $this -> { $actionName }();
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
//Ajax XML/JSON communication
if ( e_AJAX_REQUEST && is_array ( $ret ))
{
$response_type = $this -> getParam ( 'ajax_response' , 'xml' );
ob_clean ();
$js_helper = $response -> getJsHelper ();
2009-12-23 15:12:13 +00:00
foreach ( $ret as $act => $data )
2009-11-24 16:32:02 +00:00
{
$js_helper -> addResponse ( $data , $act );
}
$js_helper -> sendResponse ( $response_type );
}
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
$ret .= ob_get_clean ();
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
// Ajax text response
if ( e_AJAX_REQUEST )
{
$response_type = 'text' ;
$response -> getJsHelper () -> addResponse ( $ret ) -> sendResponse ( $response_type );
}
else
{
$response -> appendBody ( $ret );
}
2014-10-24 13:14:51 -07:00
2009-11-24 16:32:02 +00:00
return $response ;
}
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
public function E404Observer ()
{
2010-11-04 23:27:47 +00:00
$this -> getResponse () -> setTitle ( LAN_UI_404_TITLE_ERROR );
2009-11-24 16:32:02 +00:00
}
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
public function E404Page ()
{
2017-03-19 16:42:57 +00:00
return '<div class="center">' . LAN_UI_404_BODY_ERROR . '</div>' ;
2009-11-24 16:32:02 +00:00
}
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
public function E404AjaxPage ()
{
exit ;
}
2012-01-20 15:53:59 +00:00
public function E403Observer ()
{
$this -> getResponse () -> setTitle ( LAN_UI_403_TITLE_ERROR );
}
public function E403Page ()
{
2017-03-19 16:42:57 +00:00
return '<div class="center">' . LAN_UI_403_BODY_ERROR . '</div>' ;
2012-01-20 15:53:59 +00:00
}
public function E403AjaxPage ()
{
exit ;
}
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
/**
* Generic redirect handler , it handles almost everything we would need .
* Additionally , it moves currently registered system messages to SESSION message stack
* In almost every case { @ link redirectAction ()} and { @ link redirectMode ()} are better solution
2009-12-23 15:12:13 +00:00
*
* @ param string $action defaults to current action
* @ param string $mode defaults to current mode
2009-11-24 16:32:02 +00:00
* @ param string | array $exclude_query comma delimited variable names to be excluded from current query OR TRUE to exclude everything
* @ param string | array $merge_query query string ( & amp ; delimiter ) or associative array to be merged with current query
* @ param string $path default to e_SELF
* @ return void
*/
public function redirect ( $action = null , $mode = null , $exclude_query = '' , $merge_query = array (), $path = null )
{
$request = $this -> getRequest ();
2020-12-23 16:01:20 -08:00
if ( $mode )
{
$request -> setMode ( $mode );
}
if ( $action )
{
$request -> setAction ( $action );
}
if ( ! $path )
{
$path = e_REQUEST_SELF ;
}
2012-01-17 14:46:28 +00:00
//prevent cache
header ( 'Cache-Control: private, no-store, no-cache, must-revalidate, post-check=0, pre-check=0' );
2013-04-25 17:29:46 -07:00
// header('Pragma: no-cache');
2011-05-18 13:41:19 +00:00
2009-11-24 16:32:02 +00:00
$url = $path . '?' . $request -> buildQueryString ( $merge_query , false , $exclude_query );
// Transfer all messages to session
2009-12-23 15:12:13 +00:00
e107 :: getMessage () -> moveToSession ();
2009-11-24 16:32:02 +00:00
// write session data
session_write_close ();
2012-01-17 14:46:28 +00:00
2009-11-24 16:32:02 +00:00
// do redirect
2016-03-01 17:50:53 -08:00
e107 :: redirect ( $url );
// header('Location: '.$url);
2009-11-24 16:32:02 +00:00
exit ;
}
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
/**
2009-12-23 15:12:13 +00:00
* Convenient redirect () proxy method , make life easier when redirecting between actions
2009-11-24 16:32:02 +00:00
* in same mode .
2009-12-23 15:12:13 +00:00
*
2009-11-24 16:32:02 +00:00
* @ param string $action [ optional ]
* @ param string | array $exclude_query [ optional ]
* @ param string | array $merge_query [ optional ]
2009-12-13 21:52:32 +00:00
* @ return none
2009-11-24 16:32:02 +00:00
*/
public function redirectAction ( $action = null , $exclude_query = '' , $merge_query = array ())
{
$this -> redirect ( $action , null , $exclude_query , $merge_query );
}
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
/**
* Convenient redirect to another mode ( doesn ' t use current Query state )
* If path is empty , it ' ll be auto - detected from modes ( dispatcher ) array
2009-12-23 15:12:13 +00:00
*
2009-11-24 16:32:02 +00:00
* @ param string $mode
* @ param string $action
* @ param string | array $query [ optional ]
* @ param string $path
* @ return void
*/
public function redirectMode ( $mode , $action , $query = array (), $path = null )
{
if ( ! $path && $this -> getParam ( 'modes' ))
{
$modes = $this -> getParam ( 'modes' );
2020-12-20 11:50:10 -08:00
if ( ! empty ( $modes [ $mode ]) && ! empty ( $modes [ $mode ][ 'url' ]))
2009-11-24 16:32:02 +00:00
{
$path = e107 :: getParser () -> replaceConstants ( $modes [ $mode ][ 'url' ], 'abs' );
}
}
$this -> redirect ( $action , $mode , true , $query , $path );
}
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
/**
* Convert action name to method name
2009-12-23 15:12:13 +00:00
*
* @ param string $action_name formatted ( e . g . request method getActionName ()) action name
2009-11-24 16:32:02 +00:00
* @ param string $type page | observer | header | trigger
* @ param boolean $ajax force with true / false , if null will be auto - resolved
2009-12-13 21:52:32 +00:00
* @ return string
2009-11-24 16:32:02 +00:00
*/
public function toMethodName ( $action_name , $type = 'page' , $ajax = null )
{
2020-12-23 16:01:20 -08:00
if ( $ajax === null )
{
$ajax = e_AJAX_REQUEST ;
} //auto-resolving
2009-11-24 16:32:02 +00:00
return $action_name . ( $ajax ? 'Ajax' : '' ) . ucfirst ( strtolower ( $type ));
}
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
/**
* Check if there is a trigger available in the posted data
2010-11-04 23:27:47 +00:00
* @ param array $exclude
2009-11-24 16:32:02 +00:00
* @ return boolean
*/
2010-11-04 23:27:47 +00:00
public function hasTrigger ( $exclude = array ())
2009-11-24 16:32:02 +00:00
{
2009-12-23 15:12:13 +00:00
$posted = array_keys ( $this -> getPosted ());
2009-11-24 16:32:02 +00:00
foreach ( $posted as $key )
{
2010-11-04 23:27:47 +00:00
if ( ! in_array ( $key , $exclude ) && strpos ( $key , 'etrigger_' ) === 0 )
2009-11-24 16:32:02 +00:00
{
return true ;
}
}
return false ;
}
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
/**
* Get default action
* @ return string action
*/
public function getDefaultAction ()
{
return $this -> _default_action ;
}
2009-12-23 15:12:13 +00:00
2019-05-09 15:14:56 -07:00
public function getDefaultTrigger ()
{
return $this -> _default_trigger ;
}
2009-11-24 16:32:02 +00:00
/**
2009-12-23 15:12:13 +00:00
* Set default action
2009-11-24 16:32:02 +00:00
* @ param string $action_name
* @ return e_admin_controller
*/
public function setDefaultAction ( $action_name )
{
$this -> _default_action = $action_name ;
return $this ;
}
2009-12-23 15:12:13 +00:00
2019-05-09 15:14:56 -07:00
/**
* Set default trigger
* @ param string | array $triggers 'auto' or array of triggers
* @ example $triggers [ 'submit' ] = array ( LAN_UPDATE , 'update' , $model -> getId ());
$triggers [ 'submit' ] = array ( LAN_CREATE , 'create' , 0 );
$triggers [ 'cancel' ] = array ( LAN_CANCEL , 'cancel' );
* @ return e_admin_controller
*/
public function setDefaultTrigger ( $triggers )
{
$this -> _default_trigger = $triggers ;
return $this ;
}
2009-11-24 16:32:02 +00:00
/**
* @ return boolean
*/
public function triggersEnabled ()
{
return $this -> getParam ( 'enable_triggers' );
}
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
/**
* @ param boolean $flag
* @ return e_admin_controller
*/
public function setTriggersEnabled ( $flag )
{
$this -> setParam ( 'enable_triggers' , $flag );
return $this ;
}
}
//FIXME - move everything from e_admin_ui except model auto-create related code
class e_admin_controller_ui extends e_admin_controller
{
2015-04-15 12:27:31 -07:00
protected $table ;
2009-11-24 16:32:02 +00:00
/**
* @ var array UI field data
*/
2017-03-27 16:27:08 -07:00
2020-10-01 18:34:54 -07:00
/** @var string */
2019-05-13 12:30:42 -07:00
protected $listQry ;
2017-03-27 16:27:08 -07:00
protected $pid ;
2009-11-24 16:32:02 +00:00
protected $fields = array ();
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
/**
* @ var array default fields activated on List view
*/
protected $fieldpref = array ();
2009-12-23 15:12:13 +00:00
2020-02-22 14:56:23 -08:00
/**
* Custom Field ( User ) Preferences Name . ( for viewable columns )
* @ var string
*/
protected $fieldPrefName = '' ;
2009-11-24 16:32:02 +00:00
/**
* @ var array Plugin Preference description array
*/
protected $prefs = array ();
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
/**
* Data required for _modifyListQry () to automate
* db query building
2009-12-23 15:12:13 +00:00
* @ var array
2009-11-24 16:32:02 +00:00
*/
2012-05-17 05:09:59 +00:00
protected $tableJoin = array ();
2011-05-18 13:41:19 +00:00
2011-05-07 06:22:44 +00:00
/**
* Array of table names and their aliases . ( detected from listQry )
* db query building
* @ var array
*/
2012-05-17 05:09:59 +00:00
protected $joinAlias = array ();
2009-12-23 15:12:13 +00:00
2012-07-31 23:14:01 +00:00
/**
* Array of fields detected from listQry which are JOINs
* @ example returns array ( 'user_name' => 'u.user_name' ); from $listQry = " SELECT n.*,u.user_name FROM #news.... " etc .
*/
protected $joinField = array ();
2009-11-24 16:32:02 +00:00
/**
* Main model table alias
* @ var string
*/
protected $tableAlias ;
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
/**
* @ var string plugin name
*/
protected $pluginName ;
2015-02-09 01:05:33 -08:00
/**
* @ var string event name
* base event trigger name to be used . Leave blank for no trigger .
*/
2020-12-23 16:01:20 -08:00
protected $eventName ;
2009-12-23 15:12:13 +00:00
/**
* @ var string
*/
2020-12-23 16:01:20 -08:00
protected $defaultOrderField ;
2009-12-23 15:12:13 +00:00
/**
* @ var string
*/
protected $defaultOrder = 'asc' ;
/**
* @ var string SQL order , false to disable order , null is default order
*/
2020-12-23 16:01:20 -08:00
protected $listOrder ;
2020-03-05 11:38:23 -08:00
/**
* @ var string SQL group - by field name ( optional )
*/
2020-12-23 16:01:20 -08:00
protected $listGroup ;
2013-02-06 17:03:00 +02:00
/**
2013-02-13 17:03:53 +02:00
* @ var string field containing the order number
2013-02-06 17:03:00 +02:00
*/
2020-12-23 16:01:20 -08:00
protected $sortField ;
2017-03-27 16:27:08 -07:00
2017-03-28 15:16:27 -07:00
/**
* @ var string field containing the order number
*/
2020-12-23 16:01:20 -08:00
protected $treePrefix ;
2017-03-27 16:27:08 -07:00
/**
* @ var string field containing the parent field
*/
2020-12-23 16:01:20 -08:00
protected $sortParent ;
2013-02-06 20:35:37 +02:00
/**
2013-02-13 17:03:53 +02:00
* @ var int reorder step
2013-02-06 20:35:37 +02:00
*/
protected $orderStep = 1 ;
2013-02-27 15:01:36 +02:00
/**
* Example : array ( '0' => 'Tab label' , '1' => 'Another label' );
* Referenced from $field property per field - 'tab => xxx' where xxx is the tab key ( identifier )
* @ var array edit / create form tabs
*/
protected $tabs = array ();
2013-02-27 16:18:41 +02:00
2013-06-07 12:01:23 +03:00
/**
* Example : array ( '0' => 'Tab label' , '1' => 'Another label' );
* Referenced from $prefs property per field - 'tab => xxx' where xxx is the tab key ( identifier )
* @ var array edit / create form tabs
*/
protected $preftabs = array ();
2013-02-27 16:18:41 +02:00
/**
* TODO Example :
* Contains required data for auto - assembling URL from every record
* For greater control - override url () method
2013-04-06 15:50:28 +03:00
* @ var array
2013-02-27 16:18:41 +02:00
*/
protected $url = array ();
2013-03-13 09:47:48 +02:00
/**
* TODO Example :
* Contains required data for mapping featurebox fields
2013-04-06 15:50:28 +03:00
* @ var array
2013-03-13 09:47:48 +02:00
*/
protected $featurebox = array ();
2011-05-18 13:41:19 +00:00
2010-12-27 12:38:14 +00:00
/**
* Structure same as TreeModel parameters used for building the load () SQL
* @ var additional SQL to be applied when auto - building the list query
*/
protected $listQrySql = array ();
2011-11-27 06:10:16 +00:00
/**
* @ var Custom Filter SQL Query override .
*/
2020-12-23 16:01:20 -08:00
protected $filterQry ;
2009-12-23 15:12:13 +00:00
/**
* @ var boolean
*/
2009-11-24 16:32:02 +00:00
protected $batchDelete = true ;
2011-07-25 02:41:49 +00:00
/**
* @ var boolean
*/
protected $batchCopy = false ;
2013-02-26 16:08:08 -08:00
/**
* @ var boolean
*/
protected $batchLink = false ;
2013-03-07 22:45:59 -08:00
/**
* @ var boolean
*/
protected $batchFeaturebox = false ;
2015-07-06 14:03:08 -07:00
2017-01-27 18:02:57 -08:00
/**
* @ var boolean
*/
protected $batchExport = false ;
2015-07-06 14:03:08 -07:00
/**
* @ var array
*/
protected $batchOptions = array ();
2013-03-07 22:45:59 -08:00
2009-11-24 16:32:02 +00:00
/**
* Could be LAN constant ( mulit - language support )
2009-12-23 15:12:13 +00:00
*
2009-11-24 16:32:02 +00:00
* @ var string plugin name
*/
protected $pluginTitle ;
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
/**
* Default ( db ) limit value
* @ var integer
*/
protected $perPage = 20 ;
2017-04-03 20:20:38 -07:00
/**
* Data for grid layout .
* @ var array
*/
protected $grid = array ();
2012-05-17 05:09:59 +00:00
/**
* @ var e_admin_model
*/
protected $formQuery = false ; // custom form post query
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
/**
* @ var e_admin_model
*/
2020-12-23 16:01:20 -08:00
protected $_model ;
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
/**
* @ var e_admin_tree_model
*/
2020-12-23 16:01:20 -08:00
protected $_tree_model ;
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
/**
* @ var e_admin_tree_model
*/
2020-12-23 16:01:20 -08:00
protected $_ui ;
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
/**
* @ var e_plugin_pref | e_core_pref
*/
2020-12-23 16:01:20 -08:00
protected $_pref ;
2012-01-16 12:51:53 +00:00
/**
* Prevent parsing table aliases more than once
* @ var boolean
*/
protected $_alias_parsed = false ;
2009-12-23 15:12:13 +00:00
2016-10-20 09:00:58 +02:00
/**
* @ var bool
*/
protected $afterSubmitOptions = true ;
public function getAfterSubmitOptions ()
{
return $this -> afterSubmitOptions ;
}
2009-11-24 16:32:02 +00:00
public function getBatchDelete ()
{
return $this -> batchDelete ;
}
2011-07-25 02:41:49 +00:00
public function getBatchCopy ()
{
return $this -> batchCopy ;
}
2013-02-26 16:08:08 -08:00
public function getBatchLink ()
{
return $this -> batchLink ;
}
2009-12-23 15:12:13 +00:00
2013-03-07 22:45:59 -08:00
public function getBatchFeaturebox ()
{
return $this -> batchFeaturebox ;
}
2015-07-06 14:03:08 -07:00
2017-01-27 18:02:57 -08:00
public function getBatchExport ()
{
return $this -> batchExport ;
}
2015-07-06 14:03:08 -07:00
public function getBatchOptions ()
{
return $this -> batchOptions ;
}
2015-02-09 01:05:33 -08:00
/**
* @ return string
*/
public function getEventName ()
{
return $this -> eventName ;
}
2013-03-07 22:45:59 -08:00
2009-11-24 16:32:02 +00:00
/**
* @ return string
*/
public function getPluginName ()
{
return $this -> pluginName ;
}
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
/**
* @ return string
*/
public function getPluginTitle ()
{
return deftrue ( $this -> pluginTitle , $this -> pluginTitle );
}
2016-02-03 16:54:40 +01:00
/**
* Get Sort Field data
* @ return string
*/
public function getSortField ()
{
return $this -> sortField ;
}
2017-03-28 15:16:27 -07:00
/**
* Get Sort Field data
* @ return string
*/
public function getSortParent ()
{
return $this -> sortParent ;
}
/**
* Get Sort Field data
* @ return string
*/
public function getTreePrefix ()
{
return $this -> treePrefix ;
}
2015-02-09 01:05:33 -08:00
2013-02-24 19:52:25 -08:00
/**
* Get Tab data
* @ return array
*/
public function getTabs ()
{
return $this -> tabs ;
}
2016-07-29 15:22:47 -07:00
2017-01-24 19:53:40 -08:00
public function addTab ( $key , $val )
{
$this -> tabs [ $key ] = ( string ) $val ;
}
2016-07-29 15:22:47 -07:00
2013-06-07 12:01:23 +03:00
/**
* Get Tab data
* @ return array
*/
public function getPrefTabs ()
{
return $this -> preftabs ;
}
2013-02-26 16:08:08 -08:00
2013-06-07 12:01:23 +03:00
/**
2013-02-26 16:08:08 -08:00
* Get URL profile
* @ return array
*/
public function getUrl ()
{
return $this -> url ;
}
2013-02-24 19:52:25 -08:00
2009-12-23 15:12:13 +00:00
2013-03-07 22:45:59 -08:00
/**
* Get Featurebox Copy
* @ return array
*/
public function getFeaturebox ()
{
return $this -> featurebox ;
}
2009-11-24 16:32:02 +00:00
/**
* Get all field data
* @ return array
*/
public function getFields ()
{
return $this -> fields ;
}
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
/**
2009-12-23 15:12:13 +00:00
*
2009-11-24 16:32:02 +00:00
* @ param string $field
* @ param string $key attribute name
* @ param mixed $default default value if not set , default is null
* @ return mixed
*/
public function getFieldAttr ( $field , $key = null , $default = null )
{
if ( isset ( $this -> fields [ $field ]))
{
2020-12-23 16:01:20 -08:00
if ( $key !== null )
2009-11-24 16:32:02 +00:00
{
return isset ( $this -> fields [ $field ][ $key ]) ? $this -> fields [ $field ][ $key ] : $default ;
}
return $this -> fields [ $field ];
}
return $default ;
}
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
/**
2009-12-23 15:12:13 +00:00
*
2018-08-13 14:44:20 -07:00
* @ param string | array $field
2009-11-24 16:32:02 +00:00
* @ param string $key attribute name
* @ param mixed $value default value if not set , default is null
* @ return e_admin_controller_ui
*/
public function setFieldAttr ( $field , $key = null , $value = null )
{
// add field array
if ( is_array ( $field ))
{
foreach ( $field as $f => $atts )
{
$this -> setFieldAttr ( $f , $atts );
}
return $this ;
}
// remove a field
2020-12-23 16:01:20 -08:00
if ( $key === null )
2009-11-24 16:32:02 +00:00
{
unset ( $this -> fields [ $field ]);
return $this ;
}
// add to attribute array of a field
if ( is_array ( $key ))
{
foreach ( $key as $k => $att )
{
$this -> setFieldAttr ( $field , $k , $att );
}
return $this ;
}
// remove attribute from field attribute set
2020-12-23 16:01:20 -08:00
if ( $value === null && $key !== 'type' )
2009-11-24 16:32:02 +00:00
{
unset ( $this -> fields [ $field ][ $key ]);
return $this ;
}
// set attribute value
$this -> fields [ $field ][ $key ] = $value ;
return $this ;
}
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
/**
* Get fields stored as user preferences
* @ return array
*/
public function getFieldPref ()
{
return $this -> fieldpref ;
}
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
/**
2009-12-23 15:12:13 +00:00
* Get Config data array
2009-11-24 16:32:02 +00:00
* @ return array
*/
public function getPrefs ()
{
return $this -> prefs ;
}
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
public function getPerPage ()
{
2017-04-05 12:42:42 -07:00
2017-04-04 09:53:48 -07:00
if ( $this -> getAction () === 'grid' )
{
2017-04-05 12:42:42 -07:00
if ( $this -> getGrid ( 'carousel' ) === true )
{
return 0 ;
}
2017-04-04 09:53:48 -07:00
return $this -> getGrid ( 'perPage' );
}
2009-11-24 16:32:02 +00:00
return $this -> perPage ;
}
2017-04-03 20:20:38 -07:00
2017-04-04 09:53:48 -07:00
public function getGrid ( $key = null )
2017-04-03 20:20:38 -07:00
{
2017-04-04 09:53:48 -07:00
if ( $key !== null )
{
return $this -> grid [ $key ];
}
2017-04-03 20:20:38 -07:00
return $this -> grid ;
}
2012-05-17 05:09:59 +00:00
public function getFormQuery ()
{
return $this -> formQuery ;
}
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
public function getPrimaryName ()
{
return $this -> getModel () -> getFieldIdName ();
}
2009-12-23 15:12:13 +00:00
public function getDefaultOrderField ()
{
return ( $this -> defaultOrder ? $this -> defaultOrderField : $this -> getPrimaryName ());
}
public function getDefaultOrder ()
{
return ( $this -> defaultOrder ? $this -> defaultOrder : 'asc' );
}
2009-11-24 16:32:02 +00:00
/**
* Get column preference array
* @ return array
*/
public function getUserPref ()
{
2010-11-02 11:41:38 +00:00
//global $user_pref;
// return vartrue($user_pref['admin_cols_'.$this->getTableName()], array());
2020-02-22 14:56:23 -08:00
2020-12-23 16:01:20 -08:00
$name = ( ! empty ( $this -> fieldPrefName )) ? strtolower ( $this -> pluginName . '_' . $this -> fieldPrefName ) : $this -> getTableName ();
2020-02-22 14:56:23 -08:00
2020-12-23 16:01:20 -08:00
e107 :: getMessage () -> addDebug ( 'Loading Field Preferences using name: ' . $name );
$this -> _log ( 'Loading Field Preferences using name: ' . $name );
2020-02-22 14:56:23 -08:00
return e107 :: getUser () -> getPref ( 'admin_cols_' . $name , array ());
2009-11-24 16:32:02 +00:00
}
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
/**
* Set column preference array
* @ return boolean success
*/
2020-02-22 14:56:23 -08:00
public function setUserPref ( $new , $name = '' )
2009-11-24 16:32:02 +00:00
{
2010-11-02 11:41:38 +00:00
//global $user_pref;
//e107::getUser()->getConfig()->setData($new);
//$user_pref['admin_cols_'.$this->getTableName()] = $new;
//$this->fieldpref = $new;
//return save_prefs('user');
2020-04-11 11:28:26 -07:00
if ( ! empty ( $new ))
{
$this -> fieldpref = $new ;
}
2020-02-22 14:56:23 -08:00
if ( empty ( $name ))
{
$name = $this -> getTableName ();
}
2020-02-24 09:21:19 -08:00
else
{
2020-12-23 16:01:20 -08:00
$name = strtolower ( $this -> pluginName . '_' . $name );
2020-02-24 09:21:19 -08:00
}
2020-02-22 14:56:23 -08:00
2020-12-23 16:01:20 -08:00
$msg = 'Saving User Field preferences using name: ' . $name ;
2020-04-11 11:28:26 -07:00
e107 :: getMessage () -> addDebug ( $msg );
$this -> _log ( $msg );
2020-02-22 14:56:23 -08:00
2010-11-02 11:41:38 +00:00
return e107 :: getUser () -> getConfig ()
2020-02-22 14:56:23 -08:00
-> set ( 'admin_cols_' . $name , $new )
2010-11-02 11:41:38 +00:00
-> save ();
2009-11-24 16:32:02 +00:00
}
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
/**
* Get current model
*
* @ return e_admin_model
*/
public function getModel ()
{
2020-12-23 16:01:20 -08:00
if ( $this -> _model === null )
2009-11-24 16:32:02 +00:00
{
$this -> _setModel ();
}
2009-12-23 15:12:13 +00:00
2016-07-07 08:49:22 -07:00
return $this -> _model ;
}
/**
* Alias for getModel () -> get and getListModel () -> get () .
* May be used inside field - method in read / write mode .
*
* @ param string $key
* @ return mixed | null - current value of the chosen db field .
*/
public function getFieldVar ( $key = null )
{
if ( empty ( $key ))
2016-07-03 19:47:23 -07:00
{
2016-07-07 08:49:22 -07:00
return null ;
2016-07-03 19:47:23 -07:00
}
2020-12-23 16:01:20 -08:00
$action = $this -> getAction ();
if ( $action === 'list' || $action === 'grid' )
2016-07-07 08:49:22 -07:00
{
2019-05-13 12:30:42 -07:00
$obj = $this -> getListModel ();
if ( is_object ( $obj ))
{
return $obj -> get ( $key );
}
return null ;
2016-07-07 08:49:22 -07:00
}
return $this -> getModel () -> get ( $key );
2016-07-03 19:47:23 -07:00
2009-11-24 16:32:02 +00:00
}
2016-07-07 08:49:22 -07:00
2009-11-24 16:32:02 +00:00
/**
* Set controller model
* @ param e_admin_model $model
* @ return e_admin_controller_ui
*/
public function setModel ( $model )
{
$this -> _model = $model ;
return $this ;
}
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
/**
* Get model validation array
* @ return array
*/
public function getValidationRules ()
{
return $this -> getModel () -> getValidationRules ();
}
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
/**
* Get model data field array
* @ return array
*/
public function getDataFields ()
{
return $this -> getModel () -> getDataFields ();
}
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
/**
* Get model table or alias
* @ param boolean $alias get table alias on true , default false
* @ param object $prefix add e107 special '#' prefix , default false
* @ return string
*/
public function getTableName ( $alias = false , $prefix = false )
{
2020-12-23 16:01:20 -08:00
if ( $alias )
{
return ( $this -> tableAlias ? $this -> tableAlias : '' );
}
2009-11-24 16:32:02 +00:00
return ( $prefix ? '#' : '' ) . $this -> getModel () -> getModelTable ();
}
2009-12-23 15:12:13 +00:00
2012-07-31 23:14:01 +00:00
public function getIfTableAlias ( $prefix = false , $quote = false ) //XXX May no longer by useful. see joinAlias()
2009-11-24 16:32:02 +00:00
{
$alias = $this -> getTableName ( true );
if ( $alias )
{
return $alias ;
2009-12-23 15:12:13 +00:00
}
2009-11-24 16:32:02 +00:00
return ( ! $quote ? $this -> getTableName ( false , $prefix ) : '`' . $this -> getTableName ( false , $prefix ) . '`' );
}
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
/**
2012-07-31 23:14:01 +00:00
* Get join table data - XXX DEPRECATE ?
2009-11-24 16:32:02 +00:00
* @ param string $table if null all data will be returned
* @ param string $att_name search for specific attribute , default null ( no search )
* @ return mixed
*/
public function getJoinData ( $table = null , $att_name = null , $default_att = null )
2012-07-31 23:14:01 +00:00
{
2020-12-23 16:01:20 -08:00
if ( $table === null )
2009-11-24 16:32:02 +00:00
{
return $this -> tableJoin ;
}
2020-12-23 16:01:20 -08:00
if ( $att_name === null )
2009-11-24 16:32:02 +00:00
{
return ( isset ( $this -> tableJoin [ $table ]) ? $this -> tableJoin [ $table ] : array ());
}
return ( isset ( $this -> tableJoin [ $table ][ $att_name ]) ? $this -> tableJoin [ $table ][ $att_name ] : $default_att );
}
2009-12-23 15:12:13 +00:00
2012-07-31 23:14:01 +00:00
public function setJoinData ( $table , $data ) //XXX - DEPRECATE?
2009-11-24 16:32:02 +00:00
{
2020-12-23 16:01:20 -08:00
if ( $data === null )
2009-11-24 16:32:02 +00:00
{
unset ( $this -> tableJoin [ $table ]);
return $this ;
}
$this -> tableJoin [ $table ] = ( array ) $data ;
return $this ;
}
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
/**
* User defined model setter
* @ return e_admin_controller_ui
*/
protected function _setModel ()
{
return $this ;
}
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
/**
* Get current tree model
2010-11-04 23:27:47 +00:00
* @ return e_admin_tree_model
2009-11-24 16:32:02 +00:00
*/
public function getTreeModel ()
{
2020-12-23 16:01:20 -08:00
if ( $this -> _tree_model === null )
2009-11-24 16:32:02 +00:00
{
$this -> _setTreeModel ();
}
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
return $this -> _tree_model ;
}
2009-12-23 15:12:13 +00:00
2017-12-18 14:07:50 -08:00
/**
2017-12-23 11:54:25 -08:00
* Get ordered models by their parents
* add extra
* @ lonalore
2017-12-18 14:07:50 -08:00
* @ return e_admin_tree_model
*/
public function getTreeModelSorted ()
{
$tree = $this -> getTreeModel ();
2017-12-23 11:54:25 -08:00
$parentField = $this -> getSortParent ();
$orderField = $this -> getSortField ();
2017-12-21 16:30:45 -08:00
2017-12-23 11:54:25 -08:00
$arr = array ();
2019-03-02 10:09:16 -08:00
/**
* @ var $id
* @ var e_tree_model $model
*/
2017-12-23 11:54:25 -08:00
foreach ( $tree -> getTree () as $id => $model )
2017-12-18 14:07:50 -08:00
{
2017-12-23 11:54:25 -08:00
$parent = $model -> get ( $parentField );
$order = $model -> get ( $orderField );
2017-12-22 00:39:01 +01:00
2017-12-23 11:54:25 -08:00
$model -> set ( '_depth' , '9999' ); // include extra field in output, just as the MySQL function did.
2017-12-22 00:39:01 +01:00
2017-12-18 14:07:50 -08:00
2017-12-23 11:54:25 -08:00
$arr [ $id ] = $model ;
2017-12-22 00:51:44 +01:00
}
2017-12-22 00:39:01 +01:00
2017-12-23 11:54:25 -08:00
// usort($arr); array_multisort() ?
2017-12-22 00:39:01 +01:00
2017-12-23 11:54:25 -08:00
$tree -> setTree ( $arr , true ); // set the newly ordered tree.
2017-12-22 00:39:01 +01:00
2019-03-03 13:08:02 -08:00
// var_dump($arr);
2017-12-18 14:07:50 -08:00
2017-12-21 21:54:06 +01:00
return $this -> _tree_model ;
}
2017-12-18 14:07:50 -08:00
/**
* @ lonalore - found online .
* @ param string $idField The item ' s ID identifier ( required )
* @ param string $parentField The item ' s parent identifier ( required )
* @ param array $els The array ( required )
* @ param int $parentID The parent ID for which to sort ( internal )
* @ param array $result The result set ( internal )
* @ param int $depth The depth ( internal )
* @ return array
*/
2020-12-23 16:01:20 -08:00
public function parentChildSort_r ( $idField , $parentField , $els = array (), $parentID = 0 , & $result = array (), & $depth = 0 )
2017-12-18 14:07:50 -08:00
{
foreach ( $els as $key => $value )
{
if ( $value [ $parentField ] == $parentID )
{
$value [ 'depth' ] = $depth ;
array_push ( $result , $value );
unset ( $els [ $key ]);
$oldParent = $parentID ;
$parentID = $value [ $idField ];
$depth ++ ;
$this -> parentChildSort_r ( $idField , $parentField , $els , $parentID , $result , $depth );
$parentID = $oldParent ;
$depth -- ;
}
}
return $result ;
}
2009-11-24 16:32:02 +00:00
/**
* Set controller tree model
2010-11-04 23:27:47 +00:00
* @ param e_admin_tree_model $tree_model
2009-11-24 16:32:02 +00:00
* @ return e_admin_controller_ui
*/
public function setTreeModel ( $tree_model )
{
$this -> _tree_model = $tree_model ;
2017-04-04 18:41:34 -07:00
2009-11-24 16:32:02 +00:00
return $this ;
}
2011-05-18 13:41:19 +00:00
2010-11-04 23:27:47 +00:00
/**
* Get currently parsed model while in list mode
* Model instance is registered by e_form :: renderListForm ()
*
* @ return e_admin_model
*/
public function getListModel ()
{
return e107 :: getRegistry ( 'core/adminUI/currentListModel' );
}
2011-05-18 13:41:19 +00:00
2010-11-08 09:20:12 +00:00
public function setListModel ( $model )
{
e107 :: setRegistry ( 'core/adminUI/currentListModel' , $model );
return $this ;
}
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
/**
* User defined tree model setter
* @ return e_admin_controller_ui
*/
protected function _setTreeModel ()
{
return $this ;
}
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
/**
* Get extended ( UI ) Form instance
*
2020-12-11 08:57:19 -08:00
* @ return e_admin_form_ui | mixed
2009-11-24 16:32:02 +00:00
*/
public function getUI ()
{
2020-12-23 16:01:20 -08:00
if ( $this -> _ui === null )
2009-11-24 16:32:02 +00:00
{
$this -> _setUI ();
}
return $this -> _ui ;
}
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
/**
* Set controller UI form
* @ param e_admin_form_ui $ui
* @ return e_admin_controller_ui
*/
public function setUI ( $ui )
{
$this -> _ui = $ui ;
return $this ;
}
/**
* User defined UI form setter
* @ return e_admin_controller_ui
*/
protected function _setUI ()
{
return $this ;
}
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
/**
2009-12-23 15:12:13 +00:00
* Get Config object
2009-11-24 16:32:02 +00:00
* @ return e_plugin_pref or e_core_pref when used in core areas
*/
public function getConfig ()
2009-12-23 15:12:13 +00:00
{
2020-12-23 16:01:20 -08:00
if ( $this -> _pref === null )
2009-11-24 16:32:02 +00:00
{
$this -> _setConfig ();
}
return $this -> _pref ;
}
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
/**
2009-12-23 15:12:13 +00:00
* Set Config object
2009-11-24 16:32:02 +00:00
* @ return e_admin_controller_ui
*/
public function setConfig ( $config )
{
$this -> _prefs = $config ;
return $this ;
}
2009-12-23 15:12:13 +00:00
2015-06-06 02:33:23 -07:00
/**
* @ param $val
*/
public function setBatchDelete ( $val )
{
$this -> batchDelete = $val ;
return $this ;
}
/**
* @ param $val
*/
public function setBatchCopy ( $val )
{
$this -> batchCopy = $val ;
return $this ;
}
2009-11-24 16:32:02 +00:00
/**
* User defined config setter
* @ return e_admin_controller_ui
*/
protected function _setConfig ()
{
return $this ;
}
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
/**
* Manage column visibility
* @ param string $batch_trigger
2020-02-24 09:21:19 -08:00
* @ return null
2009-11-24 16:32:02 +00:00
*/
public function manageColumns ()
{
$cols = array ();
$posted = $this -> getPosted ( 'e-columns' , array ());
foreach ( $this -> getFields () as $field => $attr )
{
2020-04-10 08:25:33 -07:00
if (( /*vartrue($attr['forced']) || */ in_array ( $field , $posted )) && ! vartrue ( $attr [ 'nolist' ]))
2009-11-24 16:32:02 +00:00
{
$cols [] = $field ;
continue ;
}
}
2009-12-23 15:12:13 +00:00
2020-04-10 08:25:33 -07:00
// Alow for an empty array to be saved also, to reset to default.
if ( $this -> getPosted ( 'etrigger_ecolumns' , false )) // Column Save Button
2009-11-24 16:32:02 +00:00
{
2020-02-22 14:56:23 -08:00
$this -> setUserPref ( $cols , $this -> fieldPrefName );
2020-12-23 16:01:20 -08:00
e107 :: getMessage () -> addDebug ( 'User Field Preferences Saved: ' . print_a ( $cols , true ));
2009-11-24 16:32:02 +00:00
}
}
2009-12-23 15:12:13 +00:00
2017-04-05 13:12:29 -07:00
2009-11-24 16:32:02 +00:00
/**
* Handle posted batch options routine
* @ param string $batch_trigger
* @ return e_admin_controller_ui
*/
protected function _handleListBatch ( $batch_trigger )
{
$tp = e107 :: getParser ();
//$multi_name = vartrue($this->fields['checkboxes']['toggle'], 'multiselect');
$multi_name = $this -> getFieldAttr ( 'checkboxes' , 'toggle' , 'multiselect' );
$selected = array_values ( $this -> getPosted ( $multi_name , array ()));
2013-02-19 12:18:38 +02:00
$trigger = $tp -> toDB ( explode ( '__' , $batch_trigger ));
2009-12-23 15:12:13 +00:00
2019-08-10 13:24:14 -07:00
if ( ! empty ( $selected ))
2013-02-19 12:18:38 +02:00
{
foreach ( $selected as $i => $_sel )
{
2019-03-19 12:01:51 -07:00
$selected [ $i ] = preg_replace ( '/[^\w\-:.]/' , '' , $_sel );
2013-02-19 12:18:38 +02:00
}
}
2016-11-06 08:24:15 -08:00
2019-08-10 13:24:14 -07:00
// XXX An empty selection should always be permitted for custom batch methods which may apply changes to all records, not only selected ones.
2019-03-03 13:08:02 -08:00
2020-12-23 16:01:20 -08:00
if ( strpos ( $batch_trigger , 'batch_' ) === 0 )
2016-11-06 08:24:15 -08:00
{
2020-12-23 16:01:20 -08:00
list ( $tmp , $plugin , $command ) = explode ( '_' , $batch_trigger , 3 );
2016-11-06 08:24:15 -08:00
$this -> setPosted ( array ());
$this -> getRequest () -> setAction ( 'batch' );
2020-12-23 16:01:20 -08:00
$cls = e107 :: getAddon ( $plugin , 'e_admin' );
2016-11-06 08:24:15 -08:00
e107 :: callMethod ( $cls , 'process' , $this , array ( 'cmd' => $command , 'ids' => $selected ));
return $this ;
}
2009-12-23 15:12:13 +00:00
2009-11-28 15:34:46 +00:00
$this -> setTriggersEnabled ( false ); //disable further triggering
2017-04-05 13:12:29 -07:00
$actionName = $this -> getRequest () -> getActionName ();
if ( $actionName === 'Grid' )
{
$actionName = 'List' ;
}
2009-11-24 16:32:02 +00:00
switch ( $trigger [ 0 ])
{
2017-01-27 18:02:57 -08:00
2017-04-02 11:32:32 -07:00
case 'sefgen' :
$field = $trigger [ 1 ];
$value = $trigger [ 2 ];
//handleListBatch(); for custom handling of all field names
2020-12-23 16:01:20 -08:00
if ( empty ( $selected ))
{
return $this ;
}
2017-04-05 13:12:29 -07:00
$method = 'handle' . $actionName . 'SefgenBatch' ;
2017-04-02 11:32:32 -07:00
if ( method_exists ( $this , $method )) // callback handling
{
$this -> $method ( $selected , $field , $value );
}
break ;
2017-01-27 18:02:57 -08:00
case 'export' :
2020-12-23 16:01:20 -08:00
if ( empty ( $selected ))
{
return $this ;
}
2017-04-05 13:12:29 -07:00
$method = 'handle' . $actionName . 'ExportBatch' ;
2017-01-27 18:02:57 -08:00
if ( method_exists ( $this , $method )) // callback handling
{
$this -> $method ( $selected );
}
break ;
2019-08-10 13:24:14 -07:00
case 'delete' :
2010-11-04 23:27:47 +00:00
//method handleListDeleteBatch(); for custom handling of 'delete' batch
// if(empty($selected)) return $this;
// don't check selected data - subclass need to check additional post variables(confirm screen)
2019-08-10 13:24:14 -07:00
if ( empty ( $selected ) && ! $this -> getPosted ( 'etrigger_delete_confirm' )) // it's a delete batch, confirm screen
{
$params = $this -> getFieldAttr ( $trigger [ 1 ], 'writeParms' , array ());
2020-12-23 16:01:20 -08:00
if ( ! is_array ( $params ))
{
parse_str ( $params , $params );
}
2019-08-10 13:24:14 -07:00
if ( ! vartrue ( $params [ 'batchNoCheck' ]))
{
return $this ;
}
}
2017-04-05 13:12:29 -07:00
$method = 'handle' . $actionName . 'DeleteBatch' ;
2009-11-24 16:32:02 +00:00
if ( method_exists ( $this , $method )) // callback handling
{
$this -> $method ( $selected );
}
break ;
2009-12-23 15:12:13 +00:00
case 'bool' :
2020-12-23 16:01:20 -08:00
if ( empty ( $selected ))
{
return $this ;
}
2009-11-24 16:32:02 +00:00
$field = $trigger [ 1 ];
$value = $trigger [ 2 ] ? 1 : 0 ;
//something like handleListBoolBatch(); for custom handling of 'bool' batch
2017-04-05 13:12:29 -07:00
$method = 'handle' . $actionName . 'BoolBatch' ;
2009-11-24 16:32:02 +00:00
if ( method_exists ( $this , $method )) // callback handling
{
$this -> $method ( $selected , $field , $value );
}
break ;
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
case 'boolreverse' :
2020-12-23 16:01:20 -08:00
if ( empty ( $selected ))
{
return $this ;
}
2009-11-24 16:32:02 +00:00
$field = $trigger [ 1 ];
//something like handleListBoolreverseBatch(); for custom handling of 'boolreverse' batch
2017-04-05 13:12:29 -07:00
$method = 'handle' . $actionName . 'BoolreverseBatch' ;
2009-11-24 16:32:02 +00:00
if ( method_exists ( $this , $method )) // callback handling
{
$this -> $method ( $selected , $field );
}
break ;
2012-07-12 23:26:03 +00:00
2012-12-15 16:49:19 +02:00
// see commma, userclasses batch options
case 'attach' :
case 'deattach' :
case 'addAll' :
case 'clearAll' :
2020-12-23 16:01:20 -08:00
if ( empty ( $selected ))
{
return $this ;
}
2012-12-15 16:49:19 +02:00
$field = $trigger [ 1 ];
$value = $trigger [ 2 ];
2017-01-29 18:43:52 -08:00
if ( $trigger [ 0 ] === 'addAll' )
2012-12-15 16:49:19 +02:00
{
$parms = $this -> getFieldAttr ( $field , 'writeParms' , array ());
2020-12-23 16:01:20 -08:00
if ( ! is_array ( $parms ))
{
parse_str ( $parms , $parms );
}
2012-12-17 16:57:24 +02:00
unset ( $parms [ '__options' ]);
$value = $parms ;
2020-12-23 16:01:20 -08:00
if ( empty ( $value ))
{
return $this ;
}
if ( ! is_array ( $value ))
{
$value = array_map ( 'trim' , explode ( ',' , $value ));
}
2012-12-15 16:49:19 +02:00
}
if ( method_exists ( $this , 'handleCommaBatch' ))
{
$this -> handleCommaBatch ( $selected , $field , $value , $trigger [ 0 ]);
}
2012-07-12 23:26:03 +00:00
break ;
2012-12-15 16:49:19 +02:00
// append to userclass list
case 'ucadd' :
case 'ucremove' :
2020-12-23 16:01:20 -08:00
if ( empty ( $selected ))
{
return $this ;
}
2012-12-15 16:49:19 +02:00
$field = $trigger [ 1 ];
$class = $trigger [ 2 ];
$user = e107 :: getUser ();
$e_userclass = e107 :: getUserClass ();
// check userclass manager class
if ( ! isset ( $e_userclass -> class_tree [ $class ]) || ! $user -> checkClass ( $e_userclass -> class_tree [ $class ]))
{
return $this ;
}
2009-12-23 15:12:13 +00:00
2012-12-15 16:49:19 +02:00
if ( method_exists ( $this , 'handleCommaBatch' ))
{
2017-01-29 18:43:52 -08:00
$trigger [ 0 ] = $trigger [ 0 ] === 'ucadd' ? 'attach' : 'deattach' ;
2012-12-15 16:49:19 +02:00
$this -> handleCommaBatch ( $selected , $field , $class , $trigger [ 0 ]);
}
break ;
// add all to userclass list
// clear userclass list
case 'ucaddall' :
case 'ucdelall' :
2020-12-23 16:01:20 -08:00
if ( empty ( $selected ))
{
return $this ;
}
2012-12-15 16:49:19 +02:00
$field = $trigger [ 1 ];
$user = e107 :: getUser ();
$e_userclass = e107 :: getUserClass ();
$parms = $this -> getFieldAttr ( $field , 'writeParms' , array ());
2020-12-23 16:01:20 -08:00
if ( ! is_array ( $parms ))
{
parse_str ( $parms , $parms );
}
if ( ! vartrue ( $parms [ 'classlist' ]))
{
return $this ;
}
2012-12-15 16:49:19 +02:00
$classes = $e_userclass -> uc_required_class_list ( $parms [ 'classlist' ]);
foreach ( $classes as $id => $label )
{
2012-12-17 16:57:24 +02:00
// check userclass manager class
if ( ! isset ( $e_userclass -> class_tree [ $id ]) || ! $user -> checkClass ( $e_userclass -> class_tree [ $id ]))
2012-12-15 16:49:19 +02:00
{
2017-03-19 16:42:57 +00:00
$msg = $tp -> lanVars ( LAN_NO_ADMIN_PERMISSION , $label );
2013-10-29 18:41:02 -07:00
$this -> getTreeModel () -> addMessageWarning ( $msg );
unset ( $classes [ $id ], $msg );
2012-12-15 16:49:19 +02:00
}
}
2019-03-02 10:09:16 -08:00
if ( method_exists ( $this , 'handleCommaBatch' ))
{
$this -> handleCommaBatch ( $selected , $field , array_keys ( $classes ), $trigger [ 0 ] === 'ucdelall' ? 'clearAll' : 'addAll' );
}
2012-12-15 16:49:19 +02:00
break ;
2019-03-03 13:08:02 -08:00
// handleListCopyBatch etc.
2009-11-24 16:32:02 +00:00
default :
$field = $trigger [ 0 ];
2010-11-04 23:27:47 +00:00
$value = $trigger [ 1 ];
2011-05-18 13:41:19 +00:00
2009-11-24 16:32:02 +00:00
//something like handleListUrlTypeBatch(); for custom handling of 'url_type' field name
2017-04-05 13:12:29 -07:00
$method = 'handle' . $actionName . $this -> getRequest () -> camelize ( $field ) . 'Batch' ;
2017-12-27 20:58:59 -08:00
2020-12-23 16:01:20 -08:00
e107 :: getMessage () -> addDebug ( 'Searching for custom batch method: ' . $method . '(' . $selected . ',' . $value . ')' );
2018-08-07 17:05:08 -07:00
2009-11-24 16:32:02 +00:00
if ( method_exists ( $this , $method )) // callback handling
{
$this -> $method ( $selected , $value );
break ;
}
2011-05-18 13:41:19 +00:00
2009-11-24 16:32:02 +00:00
//handleListBatch(); for custom handling of all field names
2019-08-10 13:24:14 -07:00
//if(empty($selected)) return $this;
2017-04-05 13:12:29 -07:00
$method = 'handle' . $actionName . 'Batch' ;
2020-12-23 16:01:20 -08:00
e107 :: getDebug () -> log ( 'Checking for batch method: ' . $method );
2009-11-24 16:32:02 +00:00
if ( method_exists ( $this , $method ))
{
$this -> $method ( $selected , $field , $value );
}
2015-07-06 14:03:08 -07:00
2017-04-05 13:12:29 -07:00
2009-11-24 16:32:02 +00:00
break ;
}
return $this ;
2009-12-23 15:12:13 +00:00
}
2009-11-24 16:32:02 +00:00
/**
* Handle requested filter dropdown value
2018-03-05 14:37:56 -08:00
* @ param string $filter_value
2009-11-24 16:32:02 +00:00
* @ return array field -> value
*/
protected function _parseFilterRequest ( $filter_value )
{
$tp = e107 :: getParser ();
if ( ! $filter_value || $filter_value === '___reset___' )
{
return array ();
}
2018-08-07 17:05:08 -07:00
$filter = ( array ) $tp -> toDB ( explode ( '__' , $filter_value ));
2009-11-24 16:32:02 +00:00
$res = array ();
switch ( $filter [ 0 ])
{
2009-12-23 15:12:13 +00:00
case 'bool' :
2009-11-24 16:32:02 +00:00
// direct query
$res = array ( $filter [ 1 ], $filter [ 2 ]);
2020-12-23 16:01:20 -08:00
$this -> _log ( 'listQry Filtered by ' . $filter [ 1 ] . ' (' . ( $filter [ 2 ] ? 'true' : 'false' ) . ')' );
2009-11-24 16:32:02 +00:00
break ;
2012-12-01 00:03:48 -08:00
case 'datestamp' :
2018-03-05 13:45:11 -08:00
//XXX DO NOT TRANSLATE THESE VALUES!
2012-12-01 00:03:48 -08:00
$dateConvert = array (
2020-12-23 16:01:20 -08:00
'hour' => '1 hour ago' ,
'day' => '24 hours ago' ,
'week' => '1 week ago' ,
'month' => '1 month ago' ,
'month3' => '3 months ago' ,
'month6' => '6 months ago' ,
'month9' => '9 months ago' ,
'year' => '1 year ago' ,
'nhour' => 'now + 1 hour' ,
'nday' => 'now + 24 hours' ,
'nweek' => 'now + 1 week' ,
'nmonth' => 'now + 1 month' ,
'nmonth3' => 'now + 3 months' ,
'nmonth6' => 'now + 6 months' ,
'nmonth9' => 'now + 9 months' ,
'nyear' => 'now + 1 year' ,
2012-12-01 00:03:48 -08:00
);
$ky = $filter [ 2 ];
$time = vartrue ( $dateConvert [ $ky ]);
$timeStamp = strtotime ( $time );
$res = array ( $filter [ 1 ], $timeStamp );
2020-03-28 14:30:28 -07:00
2020-12-23 16:01:20 -08:00
$this -> _log ( 'listQry Filtered by ' . $filter [ 1 ] . ' (' . $time . ')' );
2012-12-01 00:03:48 -08:00
break ;
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
default :
//something like handleListUrlTypeFilter(); for custom handling of 'url_type' field name filters
$method = 'handle' . $this -> getRequest () -> getActionName () . $this -> getRequest () -> camelize ( $filter [ 0 ]) . 'Filter' ;
2018-08-07 17:05:08 -07:00
$args = array_slice ( $filter , 1 );
2020-12-23 16:01:20 -08:00
e107 :: getMessage () -> addDebug ( 'Searching for custom filter method: ' . $method . '(' . implode ( ', ' , $args ) . ')' );
2018-08-07 17:05:08 -07:00
2009-11-24 16:32:02 +00:00
if ( method_exists ( $this , $method )) // callback handling
{
2012-01-16 12:51:53 +00:00
//return $this->$method($filter[1], $selected); selected?
// better approach - pass all values as method arguments
// NOTE - callbacks are allowed to return QUERY as a string, it'll be added in the WHERE clause
2018-08-07 17:05:08 -07:00
2012-01-16 12:51:53 +00:00
e107 :: getMessage () -> addDebug ( 'Executing filter callback <strong>' . get_class ( $this ) . '::' . $method . '(' . implode ( ', ' , $args ) . ')</strong>' );
return call_user_func_array ( array ( $this , $method ), $args );
2009-11-24 16:32:02 +00:00
}
2020-12-23 16:01:20 -08:00
$res = array ( $filter [ 0 ], $filter [ 1 ]);
$this -> _log ( 'listQry Filtered by ' . $filter [ 0 ] . ' (' . $filter [ 1 ] . ')' );
break ;
2009-11-24 16:32:02 +00:00
}
2012-12-01 00:03:48 -08:00
//print_a($res);
//exit;
2009-11-24 16:32:02 +00:00
return $res ;
}
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
/**
* Convert posted to model values after submit ( based on field type )
* @ param array $data
* @ return void
*/
protected function convertToData ( & $data )
{
$model = new e_model ( $data );
2012-07-12 23:26:03 +00:00
2009-11-24 16:32:02 +00:00
foreach ( $this -> getFields () as $key => $attributes )
{
2010-02-12 16:35:43 +00:00
$value = vartrue ( $attributes [ 'dataPath' ]) ? $model -> getData ( $attributes [ 'dataPath' ]) : $model -> get ( $key );
2020-12-23 16:01:20 -08:00
if ( $value === null )
2009-11-24 16:32:02 +00:00
{
2010-02-12 16:35:43 +00:00
continue ;
2009-11-24 16:32:02 +00:00
}
switch ( $attributes [ 'type' ])
{
2012-07-18 03:47:28 +00:00
case 'password' : //TODO more encryption options.
if ( strlen ( $value ) < 30 ) // expect a non-md5 value if less than 32 chars.
{
$value = md5 ( $value );
}
break ;
2009-11-24 16:32:02 +00:00
case 'datestamp' :
2021-01-20 12:07:29 -08:00
$opt = array ();
2009-11-24 16:32:02 +00:00
if ( ! is_numeric ( $value ))
{
2016-01-14 09:52:42 -08:00
if ( ! empty ( $attributes [ 'writeParms' ]))
2012-05-26 12:21:39 +00:00
{
2016-01-14 09:52:42 -08:00
if ( is_string ( $attributes [ 'writeParms' ]))
{
parse_str ( $attributes [ 'writeParms' ], $opt );
}
elseif ( is_array ( $attributes [ 'writeParms' ]))
{
$opt = $attributes [ 'writeParms' ];
}
2012-05-26 12:21:39 +00:00
}
2016-01-14 09:52:42 -08:00
2012-05-26 12:21:39 +00:00
2021-01-20 12:07:29 -08:00
$format = ! empty ( $opt [ 'type' ]) ? ( 'input' . $opt [ 'type' ]) : 'inputdate' ;
2012-05-26 12:21:39 +00:00
$value = trim ( $value ) ? e107 :: getDate () -> toTime ( $value , $format ) : 0 ;
2009-11-24 16:32:02 +00:00
}
break ;
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
case 'ip' : // TODO - ask Steve if this check is required
2010-02-12 16:35:43 +00:00
//if(strpos($value, '.') !== FALSE)
2009-11-24 16:32:02 +00:00
{
2012-07-12 23:26:03 +00:00
$value = trim ( $value ) ? e107 :: getIPHandler () -> ipEncode ( $value ) : '' ;
2009-11-24 16:32:02 +00:00
}
break ;
2011-05-18 13:41:19 +00:00
2010-11-08 09:20:12 +00:00
case 'dropdown' : // TODO - ask Steve if this check is required
case 'lanlist' :
2013-02-21 11:44:43 +02:00
case 'userclasses' :
2012-12-17 16:57:24 +02:00
case 'comma' :
2014-10-23 18:53:50 -07:00
case 'checkboxes' :
2010-11-08 09:20:12 +00:00
if ( is_array ( $value ))
{
2011-05-18 13:41:19 +00:00
// no sanitize here - data is added to model posted stack
2010-11-08 09:20:12 +00:00
// and validated & sanitized before sent to db
2011-05-18 13:41:19 +00:00
//$value = array_map(array(e107::getParser(), 'toDB'), $value);
$value = implode ( ',' , $value );
2010-11-08 09:20:12 +00:00
}
break ;
2014-05-28 22:36:53 -07:00
case 'images' :
2014-08-18 05:22:51 -07:00
case 'files' :
// XXX Cam @ SecretR: didn't work here. See model_class.php line 2046.
// if(!is_array($value))
// {
// $value = e107::unserialize($value);
// }
2014-05-28 22:36:53 -07:00
break ;
2012-07-12 23:26:03 +00:00
2009-11-24 16:32:02 +00:00
}
2014-08-18 05:22:51 -07:00
/*
if ( $attributes [ 'serialize' ] == true )
{
$attributes [ 'data' ] = 'array' ;
}
if ( $attributes [ 'data' ] != 'array' )
{
$value = e107 :: unserialize ( $value );
}
*/
2012-08-02 02:09:58 +00:00
2020-12-20 11:50:10 -08:00
if ( ! empty ( $attributes [ 'dataPath' ]))
2010-02-12 16:35:43 +00:00
{
$model -> setData ( $attributes [ 'dataPath' ], $value );
}
else
{
$model -> set ( $key , $value );
}
2010-03-01 12:59:26 +00:00
2009-11-24 16:32:02 +00:00
}
2010-03-01 12:59:26 +00:00
2010-02-12 16:35:43 +00:00
$data = $model -> getData ();
2009-12-24 22:36:34 +00:00
unset ( $model );
2009-11-24 16:32:02 +00:00
$this -> toData ( $data );
}
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
/**
* User defined method for converting POSTED to MODEL data
* @ param array $data posted data
* @ param string $type current action type - edit , create , list or user defined
* @ return void
*/
protected function toData ( & $data , $type = '' )
{
}
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
/**
* Take approproate action after successfull submit
*
* @ param integer $id optional , needed only if redirect action is 'edit'
* @ param string $noredirect_for don ' t redirect if action equals to its value
2020-12-23 16:01:20 -08:00
* @ return null
2009-11-24 16:32:02 +00:00
*/
protected function doAfterSubmit ( $id = 0 , $noredirect_for = '' )
{
2020-12-23 16:01:20 -08:00
if ( e_AJAX_REQUEST )
{
return ;
}
2013-02-21 11:44:43 +02:00
2009-11-24 16:32:02 +00:00
if ( $noredirect_for && $noredirect_for == $this -> getPosted ( '__after_submit_action' ) && $noredirect_for == $this -> getAction ())
{
2009-12-23 15:12:13 +00:00
return ;
2009-11-24 16:32:02 +00:00
}
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
$choice = $this -> getPosted ( '__after_submit_action' , 0 );
switch ( $choice ) {
case 'create' : // create
$this -> redirectAction ( 'create' , 'id' );
break ;
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
case 'edit' : // edit
$this -> redirectAction ( 'edit' , '' , 'id=' . $id );
break ;
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
case 'list' : // list
$this -> redirectAction ( 'list' , 'id' );
break ;
default :
$choice = explode ( '|' , str_replace ( '{ID}' , $id , $choice ), 3 );
2019-03-19 12:01:51 -07:00
$this -> redirectAction ( preg_replace ( '/[^\w\-:.]/' , '' , $choice [ 0 ]), vartrue ( $choice [ 1 ]), vartrue ( $choice [ 2 ]));
2009-11-24 16:32:02 +00:00
break ;
}
return ;
}
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
/**
* Build ajax auto - complete filter response
* @ return string response markup
*/
protected function renderAjaxFilterResponse ( $listQry = '' )
{
2010-03-01 12:59:26 +00:00
$debug = false ;
2009-11-24 16:32:02 +00:00
$srch = $this -> getPosted ( 'searchquery' );
$this -> getRequest () -> setQuery ( 'searchquery' , $srch ); //_modifyListQry() is requiring GET String
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
$ret = '<ul>' ;
2010-11-04 23:27:47 +00:00
$ret .= '<li>' . $srch . '<span class="informal warning"> ' . LAN_FILTER_LABEL_TYPED . '</span></li>' ; // fix Enter - search for typed word only
2009-11-24 16:32:02 +00:00
$reswords = array ();
if ( trim ( $srch ) !== '' )
{
// Build query
$qry = $this -> _modifyListQry ( false , true , 0 , 20 , $listQry );
2020-12-23 16:01:20 -08:00
$this -> _log ( 'Filter ListQry: ' . $qry );
2010-11-04 23:27:47 +00:00
//file_put_contents(e_LOG.'uiAjaxResponseSQL.log', $qry."\n\n", FILE_APPEND);
2011-05-18 13:41:19 +00:00
2009-11-24 16:32:02 +00:00
// Make query
$sql = e107 :: getDb ();
2016-02-15 00:14:45 -08:00
if ( $qry && $sql -> gen ( $qry , $debug ))
2009-11-24 16:32:02 +00:00
{
2017-02-05 15:49:03 -08:00
while ( $res = $sql -> fetch ())
2009-11-24 16:32:02 +00:00
{
$tmp1 = array ();
$tmp = array_values ( preg_grep ( '#' . $srch . '#i' , $res ));
foreach ( $tmp as $w )
{
2009-12-23 15:12:13 +00:00
if ( $w == $srch )
2009-11-24 16:32:02 +00:00
{
array_unshift ( $reswords , $w ); //exact match
continue ;
}
preg_match ( '#[\S]*(' . $srch . ')[\S]*#i' , $w , $tmp1 );
2020-12-23 16:01:20 -08:00
if ( $tmp1 [ 0 ])
{
$reswords [] = $tmp1 [ 0 ];
}
2009-11-24 16:32:02 +00:00
}
}
}
2009-12-23 15:12:13 +00:00
// Build response
2009-11-24 16:32:02 +00:00
$reswords = array_unique ( $reswords );
if ( $reswords )
{
$ret .= '<li>' . implode ( " </li> \n \t <li> " , $reswords ) . '</li>' ;
}
}
2009-12-23 15:12:13 +00:00
2010-11-04 23:27:47 +00:00
$ret .= '<li><span class="informal warning"> ' . LAN_FILTER_LABEL_CLEAR . ' </span></li>' ; // clear filter option
2009-11-24 16:32:02 +00:00
$ret .= '</ul>' ;
return $ret ;
}
2009-12-23 15:12:13 +00:00
2012-07-31 23:14:01 +00:00
/**
* Given an alias such as 'u' or 'n.news_datestamp' - will return the associated table such as 'user' or 'news'
*/
2020-12-23 16:01:20 -08:00
public function getTableFromAlias ( $alias )
2012-07-31 23:14:01 +00:00
{
2020-12-23 16:01:20 -08:00
if ( strpos ( $alias , '.' ) !== false )
2012-07-31 23:14:01 +00:00
{
2020-12-23 16:01:20 -08:00
list ( $alias , $tmp ) = explode ( '.' , $alias , 2 );
2012-07-31 23:14:01 +00:00
}
$tmp = array_flip ( $this -> joinAlias );
return vartrue ( $tmp [ $alias ]);
}
2020-10-01 18:34:54 -07:00
public function getJoinField ( $field = null )
2012-07-31 23:14:01 +00:00
{
2020-10-01 18:34:54 -07:00
if ( empty ( $field ))
{
return $this -> joinField ;
}
2016-12-17 09:43:37 -08:00
return isset ( $this -> joinField [ $field ]) ? $this -> joinField [ $field ] : false ; // vartrue($this->joinField[$field],false);
2012-07-31 23:14:01 +00:00
}
2020-10-01 18:34:54 -07:00
public function getJoinAlias ()
{
return $this -> joinAlias ;
}
2009-11-24 16:32:02 +00:00
/**
2009-12-23 15:12:13 +00:00
* Parses all available field data , adds internal attributes for handling join requests
2009-11-24 16:32:02 +00:00
* @ return e_admin_controller_ui
*/
protected function parseAliases ()
{
2020-12-23 16:01:20 -08:00
if ( $this -> _alias_parsed )
{
return $this ;
} // already parsed!!!
2011-05-18 13:41:19 +00:00
2020-10-01 18:34:54 -07:00
$this -> joinAlias ( $this -> listQry ); // generate Table Aliases from listQry
2012-10-31 21:54:55 +00:00
2009-11-24 16:32:02 +00:00
if ( $this -> getJoinData ())
{
foreach ( $this -> getJoinData () as $table => $att )
{
if ( strpos ( $table , '.' ) !== false )
{
$tmp = explode ( '.' , $table , 2 );
$this -> setJoinData ( $table , null );
$att [ 'alias' ] = $tmp [ 0 ];
$att [ 'table' ] = $tmp [ 1 ];
$att [ '__tablePath' ] = $att [ 'alias' ] . '.' ;
$att [ '__tableFrom' ] = '`#' . $att [ 'table' ] . '` AS ' . $att [ 'alias' ];
2011-05-18 13:41:19 +00:00
$this -> setJoinData ( $att [ 'alias' ], $att );
2009-11-24 16:32:02 +00:00
unset ( $tmp );
continue ;
}
$att [ 'table' ] = $table ;
$att [ 'alias' ] = '' ;
$att [ '__tablePath' ] = '`#' . $att [ 'table' ] . '`.' ;
$att [ '__tableFrom' ] = '`#' . $att [ 'table' ] . '`' ;
$this -> setJoinData ( $table , $att );
}
}
2012-10-31 21:54:55 +00:00
2017-02-09 10:19:55 -08:00
if ( empty ( $this -> fields ))
{
$this -> _alias_parsed = true ;
return $this ;
}
2009-11-24 16:32:02 +00:00
// check for table & field aliases
$fields = array (); // preserve order
foreach ( $this -> fields as $field => $att )
{
2012-07-31 23:14:01 +00:00
// fieldAlias.fieldName // table name no longer required as it's included in listQry. (see joinAlias() )
2011-05-18 13:41:19 +00:00
if ( strpos ( $field , '.' ) !== false ) // manually entered alias.
2009-11-24 16:32:02 +00:00
{
2012-07-31 23:14:01 +00:00
$tmp = explode ( '.' , $field , 2 );
$table = $this -> getTableFromAlias ( $tmp [ 0 ]);
$att [ 'table' ] = $table ;
2012-10-31 21:54:55 +00:00
$att [ 'alias' ] = $tmp [ 0 ];
2009-11-24 16:32:02 +00:00
$att [ 'field' ] = $tmp [ 1 ];
2012-07-31 23:14:01 +00:00
$att [ '__tableField' ] = $field ;
2012-10-31 21:54:55 +00:00
$att [ '__tablePath' ] = $att [ 'alias' ] . '.' ;
2020-12-23 16:01:20 -08:00
$att [ '__tableFrom' ] = '`#' . $table . '`.' . $tmp [ 1 ]; //." AS ".$att['alias'];
2012-07-31 23:14:01 +00:00
$field = $att [ 'alias' ] ? $tmp [ 1 ] : $tmp [ 0 ];
2012-10-31 21:54:55 +00:00
2009-12-23 15:12:13 +00:00
$fields [ $field ] = $att ;
2009-11-24 16:32:02 +00:00
unset ( $tmp );
}
else
{
2011-05-18 13:41:19 +00:00
2020-12-23 16:01:20 -08:00
$att [ 'table' ] = $this -> getIfTableAlias ();
2012-07-31 23:14:01 +00:00
if ( $newField = $this -> getJoinField ( $field )) // Auto-Detect.
{
$table = $this -> getTableFromAlias ( $newField ); // Auto-Detect.
$att [ 'table' ] = $table ;
$att [ 'alias' ] = $newField ;
$att [ '__tableField' ] = $newField ;
2012-10-31 21:54:55 +00:00
// $att['__tablePath'] = $newField; ????!!!!!
2020-12-23 16:01:20 -08:00
$att [ '__tableFrom' ] = '`#' . $table . '`.' . $field ; //." AS ".$newField;
2012-07-31 23:14:01 +00:00
}
2020-12-23 16:01:20 -08:00
elseif ( isset ( $this -> joinAlias [ $this -> table ]) && $field !== 'checkboxes' && $field !== 'options' )
2011-05-07 06:22:44 +00:00
{
2020-12-23 16:01:20 -08:00
$att [ 'alias' ] = $this -> joinAlias [ $this -> table ] . '.' . $field ;
2011-05-07 06:22:44 +00:00
}
else
{
2020-12-23 16:01:20 -08:00
$att [ 'alias' ] = '' ;
2011-05-07 06:22:44 +00:00
}
2009-11-24 16:32:02 +00:00
$att [ 'field' ] = $field ;
$fields [ $field ] = $att ;
}
2009-12-23 15:12:13 +00:00
2020-12-23 16:01:20 -08:00
if ( $fields [ $field ][ 'table' ] == $this -> getIfTableAlias ())
2009-12-23 15:12:13 +00:00
{
2009-11-24 16:32:02 +00:00
$fields [ $field ][ '__tableField' ] = $att [ 'alias' ] ? $att [ 'alias' ] : $this -> getIfTableAlias ( true , true ) . '.' . $att [ 'field' ];
$fields [ $field ][ '__tableFrom' ] = $this -> getIfTableAlias ( true , true ) . '.' . $att [ 'field' ] . ( $att [ 'alias' ] ? ' AS ' . $att [ 'alias' ] : '' );
}
2020-12-11 08:57:19 -08:00
// else
2009-11-24 16:32:02 +00:00
{
2012-07-31 23:14:01 +00:00
// $fields[$field]['__tableField'] = $this->getJoinData($fields[$field]['table'], '__tablePath').$field;
2009-11-24 16:32:02 +00:00
}
2012-08-02 02:09:58 +00:00
/*
if ( $fields [ $field ][ 'table' ])
2009-12-23 15:12:13 +00:00
{
2009-11-24 16:32:02 +00:00
if ( $fields [ $field ][ 'table' ] == $this -> getIfTableAlias ( false ))
2009-12-23 15:12:13 +00:00
{
2009-11-24 16:32:02 +00:00
$fields [ $field ][ '__tableField' ] = $att [ 'alias' ] ? $att [ 'alias' ] : $this -> getIfTableAlias ( true , true ) . '.' . $att [ 'field' ];
$fields [ $field ][ '__tableFrom' ] = $this -> getIfTableAlias ( true , true ) . '.' . $att [ 'field' ] . ( $att [ 'alias' ] ? ' AS ' . $att [ 'alias' ] : '' );
}
else
{
$fields [ $field ][ '__tableField' ] = $this -> getJoinData ( $fields [ $field ][ 'table' ], '__tablePath' ) . $field ;
}
}
else
{
$fields [ $field ][ '__tableField' ] = '`' . $this -> getTableName ( false , true ) . '`.' . $field ;
2012-08-02 02:09:58 +00:00
}
*/
2009-11-24 16:32:02 +00:00
}
2011-05-07 06:22:44 +00:00
2012-07-31 23:14:01 +00:00
2009-11-24 16:32:02 +00:00
$this -> fields = $fields ;
2015-02-01 18:45:33 -08:00
2010-11-08 09:20:12 +00:00
$this -> _alias_parsed = true ;
2009-11-24 16:32:02 +00:00
return $this ;
}
2009-12-23 15:12:13 +00:00
2011-05-07 06:22:44 +00:00
/**
* Intuitive LEFT JOIN Qry support . ( preferred )
* Generate array of table names and their alias - auto - detected from listQry ;
2011-05-18 13:41:19 +00:00
* eg . $listQry = " SELECT m.*, u.user_id,u.user_name FROM #core_media AS m LEFT JOIN #user AS u ON m.media_author = u.user_id " ;
2011-05-07 06:22:44 +00:00
*/
2020-10-01 18:34:54 -07:00
public function joinAlias ( $listQry = null )
2011-05-07 06:22:44 +00:00
{
2020-10-01 18:34:54 -07:00
if ( ! empty ( $listQry ))
2011-05-07 06:22:44 +00:00
{
2020-10-01 18:34:54 -07:00
preg_match_all ( " /`?#([ \ w-]+)`? \ s*(as|AS) \ s*([ \ w-]+)/im " , $listQry , $matches );
2012-07-31 23:14:01 +00:00
$keys = array ();
2011-05-07 06:22:44 +00:00
foreach ( $matches [ 1 ] AS $k => $v )
{
2020-12-23 16:01:20 -08:00
if ( ! array_key_exists ( $v , $this -> joinAlias ) && ! empty ( $matches [ 3 ][ $k ]))
2011-05-07 06:22:44 +00:00
{
$this -> joinAlias [ $v ] = $matches [ 3 ][ $k ]; // array. eg $this->joinAlias['core_media'] = 'm';
2011-05-18 13:41:19 +00:00
}
2012-07-31 23:14:01 +00:00
$keys [] = $matches [ 3 ][ $k ];
}
2020-10-01 18:34:54 -07:00
2012-07-31 23:14:01 +00:00
foreach ( $keys as $alias )
{
2020-12-23 16:01:20 -08:00
preg_match_all ( '/' . $alias . " \ .([ \ w]*)/i " , $listQry , $match );
2012-07-31 23:14:01 +00:00
foreach ( $match [ 1 ] as $k => $m )
{
2020-10-01 18:34:54 -07:00
if ( empty ( $m ))
{
continue ;
}
2012-07-31 23:14:01 +00:00
$this -> joinField [ $m ] = $match [ 0 ][ $k ];
2012-08-02 02:09:58 +00:00
}
2011-05-07 06:22:44 +00:00
}
2020-10-01 18:34:54 -07:00
2011-05-07 06:22:44 +00:00
}
2012-10-31 21:54:55 +00:00
elseif ( $this -> tableJoin )
{
foreach ( $this -> tableJoin as $tbl => $data )
{
$matches = explode ( '.' , $tbl , 2 );
$this -> joinAlias [ $matches [ 1 ]] = $matches [ 0 ]; // array. eg $this->joinAlias['core_media'] = 'm';
//'user_name'=>'u.user_name'
if ( isset ( $data [ 'fields' ]) && $data [ 'fields' ] !== '*' )
{
$tmp = explode ( ',' , $data [ 'fields' ]);
foreach ( $tmp as $field )
{
$this -> joinField [ $field ] = $matches [ 0 ] . '.' . $field ;
}
}
}
}
2020-10-01 18:34:54 -07:00
2011-05-07 06:22:44 +00:00
}
2015-02-01 18:45:33 -08:00
/**
* Quick fix for bad custom $listQry ;
*/
protected function parseCustomListQry ( $qry )
{
2015-02-09 14:15:25 -08:00
if ( E107_DEBUG_LEVEL == E107_DBG_SQLQUERIES )
{
e107 :: getMessage () -> addDebug ( 'Using Custom listQry ' );
}
2015-02-02 11:59:17 -08:00
if ( strpos ( $qry , '`' ) === false && strpos ( $qry , 'JOIN' ) === false )
2015-02-01 18:45:33 -08:00
{
2020-12-23 16:01:20 -08:00
$ret = preg_replace ( " /FROM \ s*(#[ \ w]*)/ " , 'FROM `$1`' , $qry ); // backticks missing, so add them.
2015-02-02 11:59:17 -08:00
if ( $ret )
{
e107 :: getMessage () -> addDebug ( 'Your $listQry is missing `backticks` around the table name! It should look like this' . print_a ( $ret , true ));
return $ret ;
}
2015-02-01 18:45:33 -08:00
}
return $qry ;
}
2018-07-06 08:36:35 +02:00
/**
* Fix search string by replacing the commonly used '*' wildcard
* with the mysql represenation of it '%' and '?' with '_' ( single character )
*
* @ param string $search
* @ return string
*/
protected function fixSearchWildcards ( $search )
{
$search = trim ( $search );
if ( empty ( $search ))
{
return '' ;
}
// strip wildcard on the beginning and the end
2020-12-23 16:01:20 -08:00
while ( strpos ( $search , '*' ) === 0 )
{
$search = substr ( $search , 1 );
}
while ( substr ( $search , - 1 ) === '*' )
{
$search = substr ( $search , 0 , - 1 );
}
2018-07-06 08:36:35 +02:00
// replace "*" wildcard with mysql wildcard "%"
return str_replace ( array ( '*' , '?' ), array ( '%' , '_' ), $search );
}
2015-02-01 18:45:33 -08:00
2009-11-24 16:32:02 +00:00
// TODO - abstract, array return type, move to parent?
protected function _modifyListQry ( $raw = false , $isfilter = false , $forceFrom = false , $forceTo = false , $listQry = '' )
{
$searchQry = array ();
$filterFrom = array ();
$request = $this -> getRequest ();
$tp = e107 :: getParser ();
$tablePath = $this -> getIfTableAlias ( true , true ) . '.' ;
$tableFrom = '`' . $this -> getTableName ( false , true ) . '`' . ( $this -> getTableName ( true ) ? ' AS ' . $this -> getTableName ( true ) : '' );
$tableSFieldsArr = array (); // FROM for main table
$tableSJoinArr = array (); // FROM for join tables
$filter = array ();
2011-05-18 13:41:19 +00:00
2019-05-13 12:30:42 -07:00
$this -> listQry = $listQry ;
2016-04-20 18:08:52 -07:00
2019-06-04 12:59:39 -07:00
$filterOptions = $request -> getQuery ( 'filter_options' , '' );
2018-07-06 08:36:35 +02:00
$searchQuery = $this -> fixSearchWildcards ( $tp -> toDB ( $request -> getQuery ( 'searchquery' , '' )));
2019-06-04 12:59:39 -07:00
$searchFilter = $this -> _parseFilterRequest ( $filterOptions );
2019-03-02 10:26:12 -08:00
2019-05-13 12:30:42 -07:00
$listQry = $this -> listQry ; // check for modification during parseFilterRequest();
2015-02-09 14:15:25 -08:00
if ( E107_DEBUG_LEVEL == E107_DBG_SQLQUERIES )
{
e107 :: getMessage () -> addDebug ( 'searchQuery: <b>' . $searchQuery . '</b>' );
}
2012-01-17 16:57:46 +00:00
2012-01-16 12:51:53 +00:00
if ( $searchFilter && is_array ( $searchFilter ))
2009-11-24 16:32:02 +00:00
{
2016-04-20 18:08:52 -07:00
2012-01-16 12:51:53 +00:00
list ( $filterField , $filterValue ) = $searchFilter ;
2012-08-02 02:09:58 +00:00
2012-01-16 12:51:53 +00:00
if ( $filterField && $filterValue !== '' && isset ( $this -> fields [ $filterField ]))
{
2015-05-14 09:57:31 -07:00
$_dataType = $this -> fields [ $filterField ][ 'data' ];
$_fieldType = $this -> fields [ $filterField ][ 'type' ];
2017-01-29 18:43:52 -08:00
if ( $_fieldType === 'comma' || $_fieldType === 'checkboxes' || $_fieldType === 'userclasses' || ( $_fieldType === 'dropdown' && ! empty ( $this -> fields [ $filterField ][ 'writeParms' ][ 'multiple' ])))
2014-10-23 18:53:50 -07:00
{
2015-05-14 09:57:31 -07:00
$_dataType = 'set' ;
2014-10-23 18:53:50 -07:00
}
2015-05-14 09:57:31 -07:00
switch ( $_dataType )
2012-08-02 02:09:58 +00:00
{
2012-12-17 16:57:24 +02:00
case 'set' :
2020-12-23 16:01:20 -08:00
$searchQry [] = " FIND_IN_SET(' " . $tp -> toDB ( $filterValue ) . " ', " . $this -> fields [ $filterField ][ '__tableField' ] . ')' ;
2012-12-01 00:03:48 -08:00
break ;
case 'int' :
case 'integer' :
2017-01-29 18:43:52 -08:00
if ( $_fieldType === 'datestamp' ) // Past Month, Past Year etc.
2012-12-01 00:03:48 -08:00
{
2018-03-05 14:37:56 -08:00
if ( $filterValue > time ())
{
2020-12-23 16:01:20 -08:00
$searchQry [] = $this -> fields [ $filterField ][ '__tableField' ] . ' > ' . time ();
$searchQry [] = $this -> fields [ $filterField ][ '__tableField' ] . ' < ' . ( int ) $filterValue ;
2018-03-05 14:37:56 -08:00
}
else
{
2020-12-23 16:01:20 -08:00
$searchQry [] = $this -> fields [ $filterField ][ '__tableField' ] . ' > ' . ( int ) $filterValue ;
$searchQry [] = $this -> fields [ $filterField ][ '__tableField' ] . ' < ' . time ();
2018-03-05 14:37:56 -08:00
}
2012-12-01 00:03:48 -08:00
}
else
{
2020-12-23 16:01:20 -08:00
$searchQry [] = $this -> fields [ $filterField ][ '__tableField' ] . ' = ' . ( int ) $filterValue ;
2012-12-01 00:03:48 -08:00
}
break ;
2014-05-12 16:40:02 -07:00
2015-01-21 12:00:32 -08:00
default : // string usually.
2015-03-09 20:19:06 -07:00
2017-01-29 18:43:52 -08:00
if ( $filterValue === '_ISEMPTY_' )
2014-05-12 16:40:02 -07:00
{
2015-03-09 20:19:06 -07:00
$searchQry [] = $this -> fields [ $filterField ][ '__tableField' ] . " = '' " ;
2014-05-12 16:40:02 -07:00
}
2018-03-05 17:15:49 -08:00
2015-03-09 20:19:06 -07:00
else
2014-05-12 16:40:02 -07:00
{
2015-03-09 20:19:06 -07:00
2017-01-29 18:43:52 -08:00
if ( $_fieldType === 'method' ) // More flexible filtering.
2015-01-21 12:00:32 -08:00
{
2015-03-09 20:19:06 -07:00
2020-12-23 16:01:20 -08:00
$searchQry [] = $this -> fields [ $filterField ][ '__tableField' ] . ' LIKE "%' . $tp -> toDB ( $filterValue ) . '%"' ;
2015-01-21 12:00:32 -08:00
}
2015-03-09 20:19:06 -07:00
else
2015-01-21 12:00:32 -08:00
{
2015-03-09 20:19:06 -07:00
2015-01-21 12:00:32 -08:00
$searchQry [] = $this -> fields [ $filterField ][ '__tableField' ] . " = ' " . $tp -> toDB ( $filterValue ) . " ' " ;
}
2014-05-12 16:40:02 -07:00
}
2012-12-01 00:03:48 -08:00
//exit;
break ;
2012-08-02 02:09:58 +00:00
}
2012-01-16 12:51:53 +00:00
}
2012-12-01 00:03:48 -08:00
//echo 'type= '. $this->fields[$filterField]['data'];
// print_a($this->fields[$filterField]);
2012-01-16 12:51:53 +00:00
}
elseif ( $searchFilter && is_string ( $searchFilter ))
{
2012-08-02 02:09:58 +00:00
2012-01-16 12:51:53 +00:00
// filter callbacks could add to WHERE clause
$searchQry [] = $searchFilter ;
2009-11-24 16:32:02 +00:00
}
2011-05-07 06:22:44 +00:00
2019-11-05 08:54:16 -08:00
if ( E107_DEBUG_LEVEL == E107_DBG_SQLQUERIES )
2017-02-05 15:49:03 -08:00
{
e107 :: getMessage () -> addDebug ( print_a ( $searchQry , true ));
}
2019-11-05 09:20:48 -08:00
2019-11-05 08:54:16 -08:00
$className = get_class ( $this );
2017-02-05 15:49:03 -08:00
2009-11-24 16:32:02 +00:00
// main table should select everything
$tableSFieldsArr [] = $tablePath . '*' ;
foreach ( $this -> getFields () as $key => $var )
{
// disabled or system
2017-02-06 11:18:36 -08:00
if (( ! empty ( $var [ 'nolist' ]) && empty ( $var [ 'filter' ])) || empty ( $var [ 'type' ]) || empty ( $var [ 'data' ]))
2009-11-24 16:32:02 +00:00
{
continue ;
}
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
// select FROM... for main table
2016-12-17 09:43:37 -08:00
if ( ! empty ( $var [ 'alias' ]) && ! empty ( $var [ '__tableField' ]))
2009-11-24 16:32:02 +00:00
{
2012-10-31 21:54:55 +00:00
$tableSFieldsArr [] = $var [ '__tableField' ];
2009-11-24 16:32:02 +00:00
}
2009-12-23 15:12:13 +00:00
// filter for WHERE and FROM clauses
2015-03-09 18:45:04 -07:00
$searchable_types = array ( 'text' , 'textarea' , 'bbarea' , 'url' , 'ip' , 'tags' , 'email' , 'int' , 'integer' , 'str' , 'string' , 'number' ); //method? 'user',
2014-01-01 17:38:46 -08:00
2018-11-03 15:15:31 -07:00
if ( $var [ 'type' ] === 'method' && ! empty ( $var [ 'data' ]) && ( $var [ 'data' ] === 'string' || $var [ 'data' ] === 'str' || $var [ 'data' ] === 'int' ))
2014-01-01 17:38:46 -08:00
{
$searchable_types [] = 'method' ;
}
2020-12-29 09:48:36 -08:00
if ( ! empty ( $var [ '__tableField' ]) && trim ( $searchQuery ) !== '' && in_array ( $var [ 'type' ], $searchable_types ) )
2009-11-24 16:32:02 +00:00
{
2019-11-05 08:54:16 -08:00
// Search for customer filter handler.
2019-12-05 10:44:59 -08:00
$cutomerSearchMethod = 'handle' . $this -> getRequest () -> getActionName () . $this -> getRequest () -> camelize ( $key ) . 'Search' ;
2019-11-05 10:27:21 -08:00
$args = array ( $tp -> toDB ( $request -> getQuery ( 'searchquery' , '' )));
2019-11-05 08:54:16 -08:00
2020-12-23 16:01:20 -08:00
e107 :: getMessage () -> addDebug ( 'Searching for custom search method: ' . $className . '::' . $cutomerSearchMethod . '(' . implode ( ', ' , $args ) . ')' );
2019-12-05 10:44:59 -08:00
if ( method_exists ( $this , $cutomerSearchMethod )) // callback handling
2019-11-05 08:54:16 -08:00
{
2019-12-05 10:44:59 -08:00
e107 :: getMessage () -> addDebug ( 'Executing custom search callback <strong>' . $className . '::' . $cutomerSearchMethod . '(' . implode ( ', ' , $args ) . ')</strong>' );
2019-11-05 08:54:16 -08:00
2019-12-05 10:44:59 -08:00
$filter [] = call_user_func_array ( array ( $this , $cutomerSearchMethod ), $args );
2019-11-05 08:54:16 -08:00
continue ;
}
2017-01-29 18:43:52 -08:00
if ( $var [ 'data' ] === 'int' || $var [ 'data' ] === 'integer' || $var [ 'type' ] === 'int' || $var [ 'type' ] === 'integer' )
2013-01-08 11:21:29 +02:00
{
if ( is_numeric ( $searchQuery ))
{
2020-12-23 16:01:20 -08:00
$filter [] = $var [ '__tableField' ] . ' = ' . $searchQuery ;
2013-01-08 11:21:29 +02:00
}
continue ;
}
2015-03-09 20:19:06 -07:00
2017-01-29 18:43:52 -08:00
if ( $var [ 'type' ] === 'ip' )
2015-03-09 20:19:06 -07:00
{
2019-03-02 10:09:16 -08:00
$ipSearch = e107 :: getIPHandler () -> ipEncode ( $searchQuery );
2015-03-31 06:27:16 -07:00
if ( ! empty ( $ipSearch ))
{
$filter [] = $var [ '__tableField' ] . " LIKE '% " . $ipSearch . " %' " ;
}
2015-03-09 20:19:06 -07:00
// Continue below for BC check also.
}
2019-04-09 16:52:29 -07:00
2020-12-23 16:01:20 -08:00
if ( strpos ( $searchQuery , ' ' ) !== false ) // search multiple words across fields.
2019-04-09 16:52:29 -07:00
{
2020-12-23 16:01:20 -08:00
$tmp = explode ( ' ' , $searchQuery );
2019-04-09 16:52:29 -07:00
if ( count ( $tmp ) < 4 ) // avoid excessively long query.
{
foreach ( $tmp as $splitSearchQuery )
{
if ( ! empty ( $splitSearchQuery ))
{
$filter [] = $var [ '__tableField' ] . " LIKE '% " . $splitSearchQuery . " %' " ;
}
}
}
else
{
$filter [] = $var [ '__tableField' ] . " LIKE '% " . $searchQuery . " %' " ;
}
}
else
{
$filter [] = $var [ '__tableField' ] . " LIKE '% " . $searchQuery . " %' " ;
}
2015-03-09 20:19:06 -07:00
2009-11-24 16:32:02 +00:00
if ( $isfilter )
{
$filterFrom [] = $var [ '__tableField' ];
2011-05-18 13:41:19 +00:00
2009-11-24 16:32:02 +00:00
}
}
}
2009-12-23 15:12:13 +00:00
2019-11-05 08:54:16 -08:00
2019-06-04 12:59:39 -07:00
if ( strpos ( $filterOptions , 'searchfield__' ) === 0 ) // search in specific field, so remove the above filters.
{
$filter = array (); // reset filter.
}
2020-12-11 08:57:19 -08:00
// if(E107_DEBUG_LEVEL == E107_DBG_SQLQUERIES)
2015-03-09 20:19:06 -07:00
{
2017-02-05 15:49:03 -08:00
// e107::getDebug()->log(print_a($filter,true));
// e107::getMessage()->addInfo(print_a($filter,true));
2015-03-09 20:19:06 -07:00
}
2015-03-09 18:45:04 -07:00
2009-11-24 16:32:02 +00:00
if ( $isfilter )
{
2020-12-23 16:01:20 -08:00
if ( ! $filterFrom )
{
return false ;
}
2009-11-24 16:32:02 +00:00
$tableSFields = implode ( ', ' , $filterFrom );
}
else
{
$tableSFields = $tableSFieldsArr ? implode ( ', ' , $tableSFieldsArr ) : $tablePath . '*' ;
}
2009-12-23 15:12:13 +00:00
2010-03-01 12:59:26 +00:00
2009-11-24 16:32:02 +00:00
$jwhere = array ();
$joins = array ();
2010-11-04 23:27:47 +00:00
//file_put_contents(e_LOG.'uiAjaxResponseSFields.log', $tableSFields."\n\n", FILE_APPEND);
//file_put_contents(e_LOG.'uiAjaxResponseFields.log', print_r($this->getFields(), true)."\n\n", FILE_APPEND);
2009-12-23 15:12:13 +00:00
if ( $this -> getJoinData ())
2009-11-24 16:32:02 +00:00
{
2020-12-23 16:01:20 -08:00
$qry = 'SELECT SQL_CALC_FOUND_ROWS ' . $tableSFields ;
2009-11-24 16:32:02 +00:00
foreach ( $this -> getJoinData () as $jtable => $tparams )
{
// Select fields
if ( ! $isfilter )
{
$fields = vartrue ( $tparams [ 'fields' ]);
2020-12-23 16:01:20 -08:00
if ( $fields === '*' )
2009-11-24 16:32:02 +00:00
{
$tableSJoinArr [] = " { $tparams [ '__tablePath' ] } * " ;
}
2013-10-16 18:13:21 +03:00
elseif ( $fields )
2009-11-24 16:32:02 +00:00
{
$tableSJoinArr [] = $fields ;
/* $fields = explode ( ',' , $fields );
foreach ( $fields as $field )
{
$qry .= " , { $tparams [ '__tablePath' ] } ` " . trim ( $field ) . '`' ;
} */
}
}
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
// Prepare Joins
2020-12-23 16:01:20 -08:00
$joins [] = '
' .vartrue($tparams[' joinType '], ' LEFT JOIN ')." {$tparams[' __tableFrom ']} ON ".(vartrue($tparams[' leftTable ']) ? $tparams[' leftTable '].' . ' : $tablePath). ' `' .vartrue($tparams['leftField'])."` = { $tparams [ '__tablePath' ]} `".vartrue($tparams['rightField']). '` ' .(vartrue($tparams[' whereJoin ']) ? ' '.$tparams[' whereJoin '] : ' ' );
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
// Prepare Where
2020-12-20 11:50:10 -08:00
if ( ! empty ( $tparams [ 'where' ]))
2009-11-24 16:32:02 +00:00
{
$jwhere [] = $tparams [ 'where' ];
}
}
2009-12-23 15:12:13 +00:00
2012-07-31 23:14:01 +00:00
2009-11-24 16:32:02 +00:00
//From
2020-12-23 16:01:20 -08:00
$qry .= $tableSJoinArr ? ', ' . implode ( ', ' , $tableSJoinArr ) . ' FROM ' . $tableFrom : ' FROM ' . $tableFrom ;
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
// Joins
if ( count ( $joins ) > 0 )
{
$qry .= " \n " . implode ( " \n " , $joins );
}
}
2017-03-27 16:27:08 -07:00
else // default listQry
2009-11-24 16:32:02 +00:00
{
2017-03-27 16:27:08 -07:00
if ( ! empty ( $listQry ))
{
$qry = $this -> parseCustomListQry ( $listQry );
}
2017-12-23 11:54:25 -08:00
elseif ( $this -> sortField && $this -> sortParent && ! deftrue ( 'e_DEBUG_TREESORT' )) // automated 'tree' sorting.
2017-03-27 16:27:08 -07:00
{
2017-12-23 11:54:25 -08:00
// $qry = "SELECT SQL_CALC_FOUND_ROWS a. *, CASE WHEN a.".$this->sortParent." = 0 THEN a.".$this->sortField." ELSE b.".$this->sortField." + (( a.".$this->sortField.")/1000) END AS treesort FROM `#".$this->table."` AS a LEFT JOIN `#".$this->table."` AS b ON a.".$this->sortParent." = b.".$this->pid;
2018-01-28 12:40:30 -06:00
$qry = $this -> getParentChildQry ( true );
//$this->listOrder = '_treesort '; // .$this->sortField;
2017-03-28 15:16:27 -07:00
// $this->orderStep = ($this->orderStep === 1) ? 100 : $this->orderStep;
2017-12-23 11:54:25 -08:00
}
2017-03-27 16:27:08 -07:00
else
{
2020-12-23 16:01:20 -08:00
$qry = 'SELECT SQL_CALC_FOUND_ROWS ' . $tableSFields . ' FROM ' . $tableFrom ;
2017-03-27 16:27:08 -07:00
}
2015-02-02 11:59:17 -08:00
2009-11-24 16:32:02 +00:00
}
2011-05-18 13:41:19 +00:00
2010-11-16 10:13:44 +00:00
// group field - currently auto-added only if there are joins
$groupField = '' ;
if ( $joins && $this -> getPrimaryName ())
{
$groupField = $tablePath . $this -> getPrimaryName ();
}
2009-11-24 16:32:02 +00:00
2020-03-05 11:38:23 -08:00
// appended to GROUP BY when true.
if ( ! empty ( $this -> listGroup ))
{
$groupField = $this -> listGroup ;
}
2009-11-24 16:32:02 +00:00
if ( $raw )
{
2010-12-27 12:38:14 +00:00
$rawData = array (
2011-05-18 13:41:19 +00:00
'joinWhere' => $jwhere ,
'filter' => $filter ,
2010-12-27 12:38:14 +00:00
'listQrySql' => $this -> listQrySql ,
2011-05-18 13:41:19 +00:00
'filterFrom' => $filterFrom ,
'search' => $searchQry ,
2010-12-27 12:38:14 +00:00
'tableFromName' => $tableFrom ,
);
2016-05-15 15:04:25 -07:00
$orderField = $request -> getQuery ( 'field' , $this -> getDefaultOrderField ());
2009-11-24 16:32:02 +00:00
$rawData [ 'tableFrom' ] = $tableSFieldsArr ;
$rawData [ 'joinsFrom' ] = $tableSJoinArr ;
$rawData [ 'joins' ] = $joins ;
2010-11-16 10:13:44 +00:00
$rawData [ 'groupField' ] = $groupField ;
2009-11-24 16:32:02 +00:00
$rawData [ 'orderField' ] = isset ( $this -> fields [ $orderField ]) ? $this -> fields [ $orderField ][ '__tableField' ] : '' ;
2017-01-29 18:43:52 -08:00
$rawData [ 'orderType' ] = $request -> getQuery ( 'asc' ) === 'desc' ? 'DESC' : 'ASC' ;
2020-12-23 16:01:20 -08:00
$rawData [ 'limitFrom' ] = $forceFrom === false ? ( int ) $request -> getQuery ( 'from' , 0 ) : ( int ) $forceFrom ;
$rawData [ 'limitTo' ] = $forceTo === false ? ( int ) $this -> getPerPage () : ( int ) $forceTo ;
2009-11-24 16:32:02 +00:00
return $rawData ;
}
2009-12-23 15:12:13 +00:00
2012-07-31 23:14:01 +00:00
2009-11-24 16:32:02 +00:00
// join where
if ( count ( $jwhere ) > 0 )
{
2020-12-23 16:01:20 -08:00
$searchQry [] = ' (' . implode ( ' AND ' , $jwhere ) . ' )' ;
2009-11-24 16:32:02 +00:00
}
// filter where
if ( count ( $filter ) > 0 )
{
2020-12-23 16:01:20 -08:00
$searchQry [] = ' ( ' . implode ( ' OR ' , $filter ) . ' ) ' ;
2009-11-24 16:32:02 +00:00
}
2011-05-18 13:41:19 +00:00
2010-12-27 12:38:14 +00:00
// more user added sql
if ( isset ( $this -> listQrySql [ 'db_where' ]) && $this -> listQrySql [ 'db_where' ])
{
if ( is_array ( $this -> listQrySql [ 'db_where' ]))
{
2020-12-23 16:01:20 -08:00
$searchQry [] = implode ( ' AND ' , $this -> listQrySql [ 'db_where' ]);
2010-12-27 12:38:14 +00:00
}
else
{
$searchQry [] = $this -> listQrySql [ 'db_where' ];
}
}
2012-07-31 23:14:01 +00:00
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
// where query
if ( count ( $searchQry ) > 0 )
{
2012-01-17 16:57:46 +00:00
// add more where details on the fly via $this->listQrySql['db_where'];
2020-12-23 16:01:20 -08:00
$qry .= ( strripos ( $qry , 'where' ) == FALSE ) ? ' WHERE ' : ' AND ' ; // Allow 'where' in custom listqry
$qry .= implode ( ' AND ' , $searchQry );
2018-06-21 23:09:41 -05:00
// Disable tree (use flat list instead) when filters are applied
// Implemented out of necessity under https://github.com/e107inc/e107/issues/3204
// Horrible hack, but only needs this one line of additional code
$this -> getTreeModel () -> setParam ( 'sort_parent' , null );
2009-11-24 16:32:02 +00:00
}
2011-05-18 13:41:19 +00:00
2010-11-16 10:13:44 +00:00
// GROUP BY if needed
if ( $groupField )
{
$qry .= ' GROUP BY ' . $groupField ;
}
2009-12-23 15:12:13 +00:00
2010-11-15 09:02:16 +00:00
// only when no custom order is required
if ( $this -> listOrder && ! $request -> getQuery ( 'field' ) && ! $request -> getQuery ( 'asc' ))
2009-11-24 16:32:02 +00:00
{
2009-12-23 15:12:13 +00:00
$qry .= ' ORDER BY ' . $this -> listOrder ;
}
2020-12-23 16:01:20 -08:00
elseif ( $this -> listOrder !== false )
2009-12-23 15:12:13 +00:00
{
$orderField = $request -> getQuery ( 'field' , $this -> getDefaultOrderField ());
2020-12-23 16:01:20 -08:00
$orderDef = ( $request -> getQuery ( 'asc' ) === null ? $this -> getDefaultOrder () : $request -> getQuery ( 'asc' ));
2009-12-23 15:12:13 +00:00
if ( isset ( $this -> fields [ $orderField ]) && strpos ( $this -> listQry , 'ORDER BY' ) == FALSE ) //override ORDER using listQry (admin->sitelinks)
{
// no need of sanitize - it's found in field array
2017-01-29 18:43:52 -08:00
$qry .= ' ORDER BY ' . $this -> fields [ $orderField ][ '__tableField' ] . ' ' . ( strtolower ( $orderDef ) === 'desc' ? 'DESC' : 'ASC' );
2009-12-23 15:12:13 +00:00
}
2009-11-24 16:32:02 +00:00
}
2011-11-27 06:10:16 +00:00
if ( isset ( $this -> filterQry )) // custom query on filter. (see downloads plugin)
{
$qry = $this -> filterQry ;
}
2020-12-23 16:01:20 -08:00
if ( $forceTo !== false || $this -> getPerPage ())
2009-11-24 16:32:02 +00:00
{
2020-12-23 16:01:20 -08:00
$from = $forceFrom === false ? ( int ) $request -> getQuery ( 'from' , 0 ) : ( int ) $forceFrom ;
if ( $forceTo === false )
{
$forceTo = $this -> getPerPage ();
}
$qry .= ' LIMIT ' . $from . ', ' . ( int ) $forceTo ;
2009-11-24 16:32:02 +00:00
}
2011-05-18 13:41:19 +00:00
// Debug Filter Query.
2015-02-09 14:15:25 -08:00
if ( E107_DEBUG_LEVEL == E107_DBG_SQLQUERIES )
{
e107 :: getMessage () -> addDebug ( 'QRY=' . str_replace ( '#' , MPREFIX , $qry ));
}
2014-10-23 18:53:50 -07:00
// echo $qry.'<br />';
// print_a($this->fields);
2015-02-03 14:55:20 -08:00
2020-03-27 14:06:44 -07:00
$this -> _log ( 'listQry: ' . str_replace ( '#' , MPREFIX , $qry ));
2011-05-18 13:41:19 +00:00
2009-11-24 16:32:02 +00:00
return $qry ;
}
2009-12-23 15:12:13 +00:00
2017-03-28 15:16:27 -07:00
2017-03-30 08:57:01 -07:00
/**
* Return a Parent / Child SQL Query based on sortParent and sortField variables
2018-01-28 12:40:30 -06:00
*
* Note : Since 2018 - 01 - 28 , the queries were replaced with pure PHP sorting . See :
* https :// github . com / e107inc / e107 / issues / 3015
*
2017-03-30 08:57:01 -07:00
* @ param bool | false $orderby - include 'ORDER BY' in the qry .
* @ return string
*/
public function getParentChildQry ( $orderby = false )
2017-03-28 15:16:27 -07:00
{
2020-12-23 16:01:20 -08:00
return 'SELECT SQL_CALC_FOUND_ROWS * FROM `#' . $this -> getTableName () . '` ' ;
2017-03-28 15:16:27 -07:00
}
2009-11-24 16:32:02 +00:00
/**
* Manage submit item
* Note : $callbackBefore will break submission if returns false
2009-12-23 15:12:13 +00:00
*
2009-11-24 16:32:02 +00:00
* @ param string $callbackBefore existing method from $this scope to be called before submit
* @ param string $callbackAfter existing method from $this scope to be called after successfull submit
* @ param string $noredirectAction passed to doAfterSubmit ()
2009-12-13 21:52:32 +00:00
* @ return boolean
2009-11-24 16:32:02 +00:00
*/
2019-03-19 15:11:36 -07:00
protected function _manageSubmit ( $callbackBefore = '' , $callbackAfter = '' , $callbackError = '' , $noredirectAction = '' , $forceSave = false )
2009-11-24 16:32:02 +00:00
{
2015-06-17 00:03:10 -07:00
2009-11-24 16:32:02 +00:00
$model = $this -> getModel ();
$old_data = $model -> getData ();
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
$_posted = $this -> getPosted ();
$this -> convertToData ( $_posted );
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
if ( $callbackBefore && method_exists ( $this , $callbackBefore ))
{
$data = $this -> $callbackBefore ( $_posted , $old_data , $model -> getId ());
2020-12-23 16:01:20 -08:00
if ( $data === false )
2009-11-24 16:32:02 +00:00
{
// we don't wanna loose posted data
2020-12-23 16:01:20 -08:00
$model -> setPostedData ( $_posted );
2009-11-24 16:32:02 +00:00
return false ;
}
if ( $data && is_array ( $data ))
{
// add to model data fields array if required
foreach ( $data as $f => $val )
{
if ( $this -> getFieldAttr ( $f , 'data' ))
{
$model -> setDataField ( $f , $this -> getFieldAttr ( $f , 'data' ));
}
}
$_posted = array_merge ( $_posted , $data );
}
}
2009-12-23 15:12:13 +00:00
2015-04-15 12:27:31 -07:00
// $model->addMessageDebug(print_a($_posted,true));
// $model->addMessageDebug(print_a($this,true));
// - Autoincrement sortField on 'Create'.
2017-03-30 08:57:01 -07:00
// Prevent parent being assigned as self.
if ( ! empty ( $this -> sortParent ) && $this -> getAction () === 'edit' && ( $model -> getId () == $_posted [ $this -> sortParent ] ) )
{
$vars = array (
'x' => $this -> getFieldAttr ( $this -> sortParent , 'title' ),
'y' => $this -> getFieldAttr ( $this -> pid , 'title' ),
);
$message = e107 :: getParser () -> lanVars ( LAN_UI_X_CANT_EQUAL_Y , $vars );
$model -> addMessageWarning ( $message );
$model -> setMessages ();
$this -> getUI () -> addWarning ( $this -> sortParent );
return false ;
}
2020-12-23 16:01:20 -08:00
if ( ! empty ( $this -> sortField ) && empty ( $this -> sortParent ) && empty ( $_posted [ $this -> sortField ]) && ( $this -> getAction () === 'create' ))
2015-04-15 12:27:31 -07:00
{
$incVal = e107 :: getDb () -> max ( $this -> table , $this -> sortField ) + 1 ;
$_posted [ $this -> sortField ] = $incVal ;
// $model->addMessageInfo(print_a($_posted,true));
}
2020-12-11 08:57:19 -08:00
$id = $model -> getId ();
2015-04-07 19:49:11 -07:00
2020-12-11 08:57:19 -08:00
// Trigger Plugin Admin-ui event. 'pre'
if ( $triggerName = $this -> getEventTriggerName ( $this -> getEventName (), $_posted [ 'etrigger_submit' ])) // 'create' or 'update';
{
if ( $halt = $this -> triggerEvent ( $triggerName , $_posted , $old_data , $id ))
2015-02-09 14:15:25 -08:00
{
$model -> setMessages ();
return false ;
}
}
2009-11-24 16:32:02 +00:00
// Scenario I - use request owned POST data - toForm already executed
2020-12-23 16:01:20 -08:00
$model -> setPostedData ( $_posted ) // insert() or update() dbInsert();
2019-03-19 15:11:36 -07:00
-> save ( true , $forceSave );
2015-12-12 00:16:16 -08:00
// if(!empty($_POST))
{
}
2015-02-09 01:05:33 -08:00
2009-11-24 16:32:02 +00:00
// Scenario II - inner model sanitize
//$this->getModel()->setPosted($this->convertToData($_POST, null, false, true);
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
// Take action based on use choice after success
if ( ! $this -> getModel () -> hasError ())
{
// callback (if any)
2015-02-09 01:05:33 -08:00
$new_data = $model -> getData ();
2015-12-12 00:16:16 -08:00
$id = $model -> getId ();
e107 :: getAddonConfig ( 'e_admin' , null , 'process' , $this , $id );
2015-02-09 01:05:33 -08:00
2020-12-23 16:01:20 -08:00
// Trigger Admin-ui event. 'post'
2020-12-11 08:57:19 -08:00
if ( $triggerName = $this -> getEventTriggerName ( $this -> getEventName (), $_posted [ 'etrigger_submit' ], 'after' )) // 'created' or 'updated';
2015-02-09 01:05:33 -08:00
{
2020-12-11 08:57:19 -08:00
$this -> triggerEvent ( $triggerName , $_posted , $old_data , $id );
2015-02-09 01:05:33 -08:00
}
2020-12-23 16:01:20 -08:00
2009-12-23 15:12:13 +00:00
if ( $callbackAfter && method_exists ( $this , $callbackAfter ))
2009-11-24 16:32:02 +00:00
{
2015-02-09 01:05:33 -08:00
$this -> $callbackAfter ( $new_data , $old_data , $id );
2009-11-24 16:32:02 +00:00
}
2010-10-26 07:41:20 +00:00
$model -> setMessages ( true ); //FIX - move messages (and session messages) to the default stack
2009-11-24 16:32:02 +00:00
$this -> doAfterSubmit ( $model -> getId (), $noredirectAction );
return true ;
}
2009-11-28 15:34:46 +00:00
elseif ( $callbackError && method_exists ( $this , $callbackError ))
{
// suppress messages if callback returns TRUE
2020-12-23 16:01:20 -08:00
if ( $this -> $callbackError ( $_posted , $old_data , $model -> getId ()) !== true )
2009-11-28 15:34:46 +00:00
{
// Copy model messages to the default message stack
$model -> setMessages ();
}
return false ;
}
2009-12-23 15:12:13 +00:00
2009-11-28 15:34:46 +00:00
// Copy model messages to the default message stack
$model -> setMessages ();
2009-11-24 16:32:02 +00:00
return false ;
}
2015-02-09 01:05:33 -08:00
2015-03-01 12:43:02 -08:00
2020-12-11 08:57:19 -08:00
/**
* Trigger 2 events . The $triggerName event , and a matching generic admin_ui_xxxxx event .
* @ param string $triggerName
* @ param array $_posted
* @ param array $old_data
* @ param int $id
* @ return false | mixed
*/
protected function triggerEvent ( $triggerName , $_posted , $old_data , $id )
{
unset ( $_posted [ 'etrigger_submit' ], $_posted [ '__after_submit_action' ], $_posted [ 'submit_value' ], $_posted [ 'e-token' ]);
$pid = $this -> getPrimaryName ();
$_posted [ $pid ] = $id ; // add in the primary ID field.
2020-12-23 15:03:31 -08:00
$table = $this -> getTableName ();
$pname = $this -> getPluginName ();
if ( $pname === 'core' ) // Handler 'core' plugin value.
{
$convert = array (
'news_category' => 'news' ,
'news' => 'news' ,
'page' => 'page' ,
'page_chapters' => 'page' ,
'user' => 'user'
);
if ( ! empty ( $convert [ $table ]))
{
$pname = $convert [ $table ];
}
}
2020-12-11 08:57:19 -08:00
$eventData = array ( // use $_posted as it may include unsaved data.
'newData' => $_posted ,
'oldData' => $old_data ,
'id' => $id ,
2020-12-23 15:03:31 -08:00
'table' => $table ,
'plugin' => $pname ,
2020-12-11 08:57:19 -08:00
);
$this -> _log ( 'Triggering Event: ' . $triggerName );
2020-12-23 16:01:20 -08:00
$tmp = explode ( '_' , $triggerName );
2020-12-11 08:57:19 -08:00
$name = end ( $tmp );
$adminTriggerName = 'admin_ui_' . $name ;
2020-12-23 16:01:20 -08:00
e107 :: getMessage () -> addDebug ( 'Event triggers fired (<b>' . $triggerName . '</b>, <b>' . $adminTriggerName . " </b>)
2020-12-11 08:57:19 -08:00
< a class = 'e-expandit' href = '#view-event-data-".$name."' > Toggle data </ a >
2020-12-23 16:01:20 -08:00
< div id = 'view-event-data-".$name."' class = 'e-hideme' > " . print_a( $eventData , true). '</div>'
2020-12-11 08:57:19 -08:00
);
if ( $halt = e107 :: getEvent () -> trigger ( $adminTriggerName , $eventData ))
{
return $halt ;
}
return e107 :: getEvent () -> trigger ( $triggerName , $eventData );
}
2015-03-01 12:43:02 -08:00
/**
* Return a custom event trigger name
* @ param null $type Usually 'Create' or 'Update'
* @ param string $when ' before or after
* @ return bool | string
2015-02-09 01:05:33 -08:00
*/
2020-12-11 08:57:19 -08:00
public function getEventTriggerName ( $name , $type = null , $when = 'before' )
2015-02-09 01:05:33 -08:00
{
2020-12-11 08:57:19 -08:00
if ( empty ( $name ) || empty ( $type ))
2015-02-09 01:05:33 -08:00
{
2020-12-11 08:57:19 -08:00
return false ;
2015-03-01 12:43:02 -08:00
}
2017-01-29 18:43:52 -08:00
if ( $when === 'after' )
2015-03-01 12:43:02 -08:00
{
$type .= 'd' ; // ie. 'created' or 'updated'.
}
2015-02-09 01:05:33 -08:00
2020-12-11 08:57:19 -08:00
return 'admin_' . strtolower ( $name ) . '_' . strtolower ( $type );
2015-02-09 01:05:33 -08:00
}
2009-11-24 16:32:02 +00:00
}
class e_admin_ui extends e_admin_controller_ui
{
protected $fieldTypes = array ();
protected $dataFields = array ();
2017-01-29 11:08:43 -08:00
protected $fieldInputTypes = array ();
2009-11-24 16:32:02 +00:00
protected $validationRules = array ();
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
protected $table ;
protected $pid ;
protected $listQry ;
protected $editQry ;
2015-04-03 21:19:43 -07:00
protected $sortField ;
protected $sortParent ;
protected $orderStep ;
2017-03-28 15:16:27 -07:00
protected $treePrefix ;
2011-05-18 13:41:19 +00:00
2010-10-30 15:34:48 +00:00
/**
* Markup to be auto - inserted before List filter
* @ var string
*/
2020-08-14 10:20:09 -07:00
public $preFilterMarkup = '' ;
2011-05-18 13:41:19 +00:00
2010-10-30 15:34:48 +00:00
/**
* Markup to be auto - inserted after List filter
* @ var string
*/
2020-08-14 10:20:09 -07:00
public $postFilterMarkup = '' ;
2011-05-18 13:41:19 +00:00
2010-10-30 15:34:48 +00:00
/**
* Markup to be auto - inserted at the top of Create form
* @ var string
*/
public $headerCreateMarkup = '' ;
2011-05-18 13:41:19 +00:00
2010-10-30 15:34:48 +00:00
/**
* Markup to be auto - inserted at the bottom of Create form
* @ var string
*/
public $footerCreateMarkup = '' ;
2011-05-18 13:41:19 +00:00
2010-10-30 15:34:48 +00:00
/**
* Markup to be auto - inserted at the top of Update form
* @ var string
*/
public $headerUpdateMarkup = '' ;
2011-05-18 13:41:19 +00:00
2010-10-30 15:34:48 +00:00
/**
* Markup to be auto - inserted at the bottom of Update form
* @ var string
*/
public $footerUpdateMarkup = '' ;
2011-05-18 13:41:19 +00:00
2010-11-04 23:27:47 +00:00
/**
* Show confirm screen before ( batch / single ) delete
* @ var boolean
*/
public $deleteConfirmScreen = false ;
2012-10-31 21:54:55 +00:00
/**
* Confirm screen custom message
* @ var string
*/
2020-12-23 16:01:20 -08:00
public $deleteConfirmMessage ;
2009-11-24 16:32:02 +00:00
2020-02-22 14:56:23 -08:00
2009-11-24 16:32:02 +00:00
/**
2009-12-23 15:12:13 +00:00
* Constructor
2009-11-24 16:32:02 +00:00
* @ param e_admin_request $request
* @ param e_admin_response $response
* @ param array $params [ optional ]
*/
public function __construct ( $request , $response , $params = array ())
{
2009-12-23 15:12:13 +00:00
$this -> setDefaultAction ( $request -> getDefaultAction ());
2009-11-24 16:32:02 +00:00
$params [ 'enable_triggers' ] = true ; // override
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
parent :: __construct ( $request , $response , $params );
if ( ! $this -> pluginName )
{
$this -> pluginName = 'core' ;
}
2009-12-23 15:12:13 +00:00
2020-02-22 14:56:23 -08:00
/* $ufieldpref = $this -> getUserPref ();
2009-11-24 16:32:02 +00:00
if ( $ufieldpref )
{
$this -> fieldpref = $ufieldpref ;
2020-02-22 14:56:23 -08:00
} */
2009-12-23 15:12:13 +00:00
2020-12-23 16:01:20 -08:00
$this -> addTitle ( $this -> pluginTitle ) -> parseAliases ();
2015-04-07 19:49:11 -07:00
$this -> initAdminAddons ();
2015-04-08 20:20:10 -07:00
if ( $help = $this -> renderHelp ())
{
if ( ! empty ( $help ))
{
e107 :: setRegistry ( 'core/e107/adminui/help' , $help );
}
}
2015-04-07 19:49:11 -07:00
}
private function initAdminAddons ()
{
$tmp = e107 :: getAddonConfig ( 'e_admin' , null , 'config' , $this );
if ( empty ( $tmp ))
{
return ;
}
2019-03-03 12:33:20 -08:00
$opts = null ;
2015-04-07 19:49:11 -07:00
foreach ( $tmp as $plug => $config )
{
2016-07-29 15:22:47 -07:00
2020-12-23 16:01:20 -08:00
$form = e107 :: getAddon ( $plug , 'e_admin' , $plug . '_admin_form' ); // class | false.
2016-07-29 15:22:47 -07:00
2016-11-07 12:09:12 -08:00
if ( ! empty ( $config [ 'fields' ]))
2015-04-07 19:49:11 -07:00
{
2019-03-03 12:33:20 -08:00
if ( ! empty ( $this -> fields [ 'options' ]))
{
$opts = $this -> fields [ 'options' ];
unset ( $this -> fields [ 'options' ]);
}
2016-11-07 12:09:12 -08:00
foreach ( $config [ 'fields' ] as $k => $v )
2016-07-29 15:22:47 -07:00
{
2016-11-07 12:09:12 -08:00
$v [ 'data' ] = false ; // disable data-saving to db table. .
2016-07-29 15:22:47 -07:00
2016-11-07 12:09:12 -08:00
$fieldName = 'x_' . $plug . '_' . $k ;
2020-12-23 16:01:20 -08:00
e107 :: getDebug () -> log ( $fieldName . ' initiated by ' . $plug );
2016-07-29 15:22:47 -07:00
2017-01-29 18:43:52 -08:00
if ( $v [ 'type' ] === 'method' && method_exists ( $form , $fieldName ))
2016-11-07 12:09:12 -08:00
{
2020-12-23 16:01:20 -08:00
$v [ 'method' ] = $plug . '_admin_form::' . $fieldName ;
2016-11-07 12:09:12 -08:00
//echo "Found method ".$fieldName." in ".$plug."_menu_form";
//echo $form->$fieldName();
}
2016-07-29 15:22:47 -07:00
2016-11-07 12:09:12 -08:00
$this -> fields [ $fieldName ] = $v ; // ie. x_plugin_key
2016-07-29 15:22:47 -07:00
2016-11-07 12:09:12 -08:00
}
2019-03-03 12:33:20 -08:00
if ( ! empty ( $opts )) // move options field to the end.
{
$this -> fields [ 'options' ] = $opts ;
}
2016-11-05 17:09:39 -07:00
}
if ( ! empty ( $config [ 'batchOptions' ]))
{
$opts = array ();
foreach ( $config [ 'batchOptions' ] as $k => $v )
{
$fieldName = 'batch_' . $plug . '_' . $k ;
$opts [ $fieldName ] = $v ; // ie. x_plugin_key
}
$batchCat = deftrue ( 'LAN_PLUGIN_' . strtoupper ( $plug ) . '_NAME' , $plug );
$this -> batchOptions [ $batchCat ] = $opts ;
2016-07-29 15:22:47 -07:00
}
if ( ! empty ( $config [ 'tabs' ]))
{
foreach ( $config [ 'tabs' ] as $t => $tb )
{
$this -> tabs [ $t ] = $tb ;
}
2015-04-07 19:49:11 -07:00
}
2016-07-29 15:22:47 -07:00
2015-04-07 19:49:11 -07:00
}
2015-12-12 00:16:16 -08:00
2015-04-07 19:49:11 -07:00
2009-11-24 16:32:02 +00:00
}
2009-12-23 15:12:13 +00:00
2015-04-07 19:49:11 -07:00
2009-11-24 16:32:02 +00:00
/**
* Catch fieldpref submit
2009-12-13 21:52:32 +00:00
* @ return none
2009-11-24 16:32:02 +00:00
*/
public function ListEcolumnsTrigger ()
{
2009-11-28 15:34:46 +00:00
$this -> setTriggersEnabled ( false ); //disable further triggering
2009-11-24 16:32:02 +00:00
parent :: manageColumns ();
}
2009-12-23 15:12:13 +00:00
2017-12-27 20:58:59 -08:00
/**
* Detect if a batch function has been fired .
* @ param $batchKey
* @ return bool
*/
public function batchTriggered ( $batchKey )
{
return ( ! empty ( $_POST [ 'e__execute_batch' ]) && ( varset ( $_POST [ 'etrigger_batch' ]) == $batchKey ));
}
2009-11-24 16:32:02 +00:00
/**
* Catch batch submit
* @ param string $batch_trigger
2020-12-11 08:57:19 -08:00
* @ return null
2009-11-24 16:32:02 +00:00
*/
public function ListBatchTrigger ( $batch_trigger )
{
2020-12-23 16:01:20 -08:00
$this -> setPosted ( 'etrigger_batch' );
2011-05-18 13:41:19 +00:00
if ( $this -> getPosted ( 'etrigger_cancel' ))
{
2010-11-04 23:27:47 +00:00
$this -> setPosted ( array ());
return ; // always break on cancel!
}
$this -> deleteConfirmScreen = true ; // Confirm screen ALWAYS enabled when multi-deleting!
2011-05-18 13:41:19 +00:00
2010-11-04 23:27:47 +00:00
// proceed ONLY if there is no other trigger, except delete confirmation
2020-12-23 16:01:20 -08:00
if ( $batch_trigger && ! $this -> hasTrigger ( array ( 'etrigger_delete_confirm' )))
{
$this -> _handleListBatch ( $batch_trigger );
}
2009-11-24 16:32:02 +00:00
}
2009-12-23 15:12:13 +00:00
2017-04-05 13:12:29 -07:00
/**
* Catch batch submit
* @ param string $batch_trigger
2020-12-11 08:57:19 -08:00
* @ return null
2017-04-05 13:12:29 -07:00
*/
public function GridBatchTrigger ( $batch_trigger )
{
2020-12-23 16:01:20 -08:00
$this -> setPosted ( 'etrigger_batch' );
2017-04-05 13:12:29 -07:00
if ( $this -> getPosted ( 'etrigger_cancel' ))
{
$this -> setPosted ( array ());
return ; // always break on cancel!
}
$this -> deleteConfirmScreen = true ; // Confirm screen ALWAYS enabled when multi-deleting!
// proceed ONLY if there is no other trigger, except delete confirmation
2020-12-23 16:01:20 -08:00
if ( $batch_trigger && ! $this -> hasTrigger ( array ( 'etrigger_delete_confirm' )))
{
$this -> _handleListBatch ( $batch_trigger );
}
2017-04-05 13:12:29 -07:00
}
2009-11-24 16:32:02 +00:00
/**
* Batch delete trigger
* @ param array $selected
* @ return void
*/
protected function handleListDeleteBatch ( $selected )
{
2013-10-29 18:41:02 -07:00
$tp = e107 :: getParser ();
2009-11-24 16:32:02 +00:00
if ( ! $this -> getBatchDelete ())
{
2010-11-04 23:27:47 +00:00
e107 :: getMessage () -> add ( LAN_UI_BATCHDEL_ERROR , E_MESSAGE_WARNING );
2009-11-24 16:32:02 +00:00
return ;
2009-12-23 15:12:13 +00:00
}
2010-11-04 23:27:47 +00:00
if ( $this -> deleteConfirmScreen )
{
if ( ! $this -> getPosted ( 'etrigger_delete_confirm' ))
{
// ListPage will show up confirmation screen
$this -> setPosted ( 'delete_confirm_value' , implode ( ',' , $selected ));
return ;
}
else
{
// already confirmed, resurrect selected values
2013-02-19 12:18:38 +02:00
$selected = explode ( ',' , $this -> getPosted ( 'delete_confirm_value' ));
foreach ( $selected as $i => $_sel )
{
2019-03-19 12:01:51 -07:00
$selected [ $i ] = preg_replace ( '/[^\w\-:.]/' , '' , $_sel );
2013-02-19 12:18:38 +02:00
}
2010-11-04 23:27:47 +00:00
}
}
2011-05-18 13:41:19 +00:00
2009-11-24 16:32:02 +00:00
// delete one by one - more control, less performance
2012-01-16 12:51:53 +00:00
// pass afterDelete() callback to tree delete method
2009-11-26 17:14:07 +00:00
$set_messages = true ;
2013-02-19 12:18:38 +02:00
$delcount = 0 ;
$nfcount = 0 ;
2009-11-24 16:32:02 +00:00
foreach ( $selected as $id )
{
2009-11-26 17:14:07 +00:00
$data = array ();
$model = $this -> getTreeModel () -> getNode ( $id );
if ( $model )
2009-11-24 16:32:02 +00:00
{
2009-11-26 17:14:07 +00:00
$data = $model -> getData ();
if ( $this -> beforeDelete ( $data , $id ))
2009-11-24 16:32:02 +00:00
{
2009-11-26 17:14:07 +00:00
$check = $this -> getTreeModel () -> delete ( $id );
2020-12-23 16:01:20 -08:00
if ( $check )
{
$delcount ++ ;
}
2009-11-26 17:14:07 +00:00
if ( ! $this -> afterDelete ( $data , $id , $check ))
{
$set_messages = false ;
}
2009-11-24 16:32:02 +00:00
}
}
2012-07-14 10:40:40 +00:00
else
{
2013-02-19 12:18:38 +02:00
$set_messages = true ;
$nfcount ++ ;
2012-07-14 10:40:40 +00:00
}
2009-11-24 16:32:02 +00:00
}
//$this->getTreeModel()->delete($selected);
2013-02-19 12:18:38 +02:00
if ( $set_messages )
{
$this -> getTreeModel () -> setMessages ();
// FIXME lan
2020-12-23 16:01:20 -08:00
if ( $delcount )
{
e107 :: getMessage () -> addSuccess ( $tp -> lanVars ( LAN_UI_DELETED , $delcount , true ));
}
if ( $nfcount )
{
e107 :: getMessage () -> addError ( $tp -> lanVars ( LAN_UI_DELETED_FAILED , $nfcount , true ));
}
2013-02-19 12:18:38 +02:00
}
2012-07-14 10:40:40 +00:00
//$this->redirect();
2009-11-24 16:32:02 +00:00
}
2009-12-23 15:12:13 +00:00
2017-01-27 18:02:57 -08:00
/**
2011-07-25 02:41:49 +00:00
* Batch copy trigger
* @ param array $selected
* @ return void
*/
protected function handleListCopyBatch ( $selected )
{
2017-04-05 13:12:29 -07:00
// Batch Copy
2017-04-05 13:31:29 -07:00
2014-02-26 16:56:17 +02:00
$res = $this -> getTreeModel () -> copy ( $selected );
// callback
$this -> afterCopy ( $res , $selected );
2013-02-27 19:36:53 +02:00
// move messages to default stack
$this -> getTreeModel () -> setMessages ();
// send messages to session
e107 :: getMessage () -> moveToSession ();
// redirect
2017-10-30 13:39:49 -07:00
$this -> redirect ();
2011-07-25 02:41:49 +00:00
}
2017-01-27 18:02:57 -08:00
/**
* Batch Export trigger
* @ param array $selected
* @ return void
*/
protected function handleListExportBatch ( $selected )
{
// Batch Copy
$res = $this -> getTreeModel () -> export ( $selected );
// callback
// $this->afterCopy($res, $selected);
// move messages to default stack
$this -> getTreeModel () -> setMessages ();
// send messages to session
e107 :: getMessage () -> moveToSession ();
// redirect
$this -> redirect ();
}
2017-04-02 11:32:32 -07:00
/**
* Batch Export trigger
* @ param array $selected
* @ return void
*/
protected function handleListSefgenBatch ( $selected , $field , $value )
{
$tree = $this -> getTreeModel ();
$c = 0 ;
foreach ( $selected as $id )
{
if ( ! $tree -> hasNode ( $id ))
{
e107 :: getMessage () -> addError ( 'Item #ID ' . htmlspecialchars ( $id ) . ' not found.' );
continue ;
}
$model = $tree -> getNode ( $id );
$name = $model -> get ( $value );
$sef = eHelper :: title2sef ( $name , 'dashl' );
$model -> set ( $field , $sef );
$model -> save ();
$data = $model -> getData ();
if ( $model -> isModified ())
{
$this -> getModel () -> setData ( $data ) -> save ( false , true );
$c ++ ;
}
}
$caption = e107 :: getParser () -> lanVars ( LAN_UI_BATCH_BOOL_SUCCESS , $c , true );
e107 :: getMessage () -> addSuccess ( $caption );
// e107::getMessage()->moveToSession();
// redirect
// $this->redirect();
}
2017-01-27 18:02:57 -08:00
2013-02-27 19:36:53 +02:00
/**
* Batch URL trigger
2013-02-26 16:08:08 -08:00
* @ param array $selected
* @ return void
*/
protected function handleListUrlBatch ( $selected )
{
2013-02-27 19:36:53 +02:00
if ( $this -> _add2nav ( $selected ))
{
2013-03-13 09:47:48 +02:00
e107 :: getMessage () -> moveToSession ();
$this -> redirect ();
2013-02-27 19:36:53 +02:00
}
2013-02-26 16:08:08 -08:00
}
2013-03-07 22:45:59 -08:00
/** TODO
* Batch Featurebox Transfer
* @ param array $selected
* @ return void
*/
protected function handleListFeatureboxBatch ( $selected )
{
if ( $this -> _add2featurebox ( $selected ))
{
2013-03-13 09:47:48 +02:00
e107 :: getMessage () -> moveToSession ();
$this -> redirect ();
2013-03-07 22:45:59 -08:00
}
}
2013-02-27 19:36:53 +02:00
protected function _add2nav ( $selected )
{
2020-12-23 16:01:20 -08:00
if ( empty ( $selected ))
{
return false ;
} // TODO warning message
2013-02-27 19:36:53 +02:00
2020-12-23 16:01:20 -08:00
if ( ! is_array ( $selected ))
{
$selected = array ( $selected );
}
2013-02-27 19:36:53 +02:00
$sql = e107 :: getDb ();
$urlData = $this -> getUrl ();
$allData = $this -> getTreeModel () -> url ( $selected , array ( 'sc' => true ), true );
e107 :: getMessage () -> addDebug ( 'Using Url Route:' . $urlData [ 'route' ]);
$scount = 0 ;
foreach ( $allData as $id => $data )
{
$name = $data [ 'name' ];
$desc = $data [ 'description' ];
$link = $data [ 'url' ];
2020-12-23 16:01:20 -08:00
$link = str_replace ( '{e_BASE}' , '' , $link ); // TODO temporary here, discuss
2013-02-27 19:36:53 +02:00
// _FIELD_TYPES auto created inside mysql handler now
$linkArray = array (
'link_name' => $name ,
'link_url' => $link ,
'link_description' => e107 :: getParser () -> toDB ( $desc ), // retrieved field type is string, we might need todb here
'link_button' => '' ,
'link_category' => 255 , // Using an unassigned template rather than inactive link-class, since other inactive links may already exist.
'link_order' => 0 ,
'link_parent' => 0 ,
'link_open' => '' ,
'link_class' => 0 ,
'link_sefurl' => e107 :: getParser () -> toDB ( $urlData [ 'route' ] . '?' . $id ),
);
$res = $sql -> insert ( 'links' , $linkArray );
if ( $res !== FALSE )
{
2020-12-23 16:01:20 -08:00
e107 :: getMessage () -> addSuccess ( LAN_CREATED . ': ' . LAN_SITELINK . ': ' . ( $name ? $name : 'n/a' ));
2017-03-19 16:42:57 +00:00
$scount ++ ;
2013-02-27 19:36:53 +02:00
}
else
{
if ( $sql -> getLastErrorNumber ())
{
2020-12-23 16:01:20 -08:00
e107 :: getMessage () -> addError ( LAN_CREATED_FAILED . ': ' . LAN_SITELINK . ': ' . $name . ': ' . LAN_SQL_ERROR );
2013-02-27 19:36:53 +02:00
e107 :: getMessage () -> addDebug ( 'SQL Link Creation Error #' . $sql -> getLastErrorNumber () . ': ' . $sql -> getLastErrorText ());
2017-03-19 16:42:57 +00:00
}
2013-02-27 19:36:53 +02:00
else
{
2020-12-23 16:01:20 -08:00
e107 :: getMessage () -> addError ( LAN_CREATED_FAILED . ': ' . LAN_SITELINK . ': ' . $name . ': ' . LAN_UNKNOWN_ERROR ); //Unknown Error
2013-02-27 19:36:53 +02:00
}
}
2017-03-19 16:42:57 +00:00
2013-02-27 19:36:53 +02:00
}
2017-03-19 16:42:57 +00:00
if ( $scount > 0 )
{
2020-12-23 16:01:20 -08:00
e107 :: getMessage () -> addSuccess ( LAN_CREATED . ' (' . $scount . ') ' . ADLAN_138 );
e107 :: getMessage () -> addSuccess ( " <a class='btn btn-small btn-primary' href=' " . e_ADMIN_ABS . " links.php?searchquery=&filter_options=link_category__255'> " . LAN_CONFIGURE . ' ' . ADLAN_138 . '</a>' );
2013-02-27 19:36:53 +02:00
return $scount ;
2017-03-19 16:42:57 +00:00
}
2013-02-27 19:36:53 +02:00
return false ;
}
2013-03-07 22:45:59 -08:00
protected function _add2featurebox ( $selected )
{
2013-04-27 13:33:42 +03:00
// FIX - don't allow if plugin not installed
if ( ! e107 :: isInstalled ( 'featurebox' ))
{
return false ;
}
2020-12-23 16:01:20 -08:00
if ( empty ( $selected ))
{
return false ;
} // TODO warning message
2013-03-07 22:45:59 -08:00
2020-12-23 16:01:20 -08:00
if ( ! is_array ( $selected ))
{
$selected = array ( $selected );
}
2013-03-07 22:45:59 -08:00
$sql = e107 :: getDb ();
2013-03-13 09:47:48 +02:00
$tree = $this -> getTreeModel ();
2020-12-23 16:01:20 -08:00
$urlData = $this -> getTreeModel () -> url ( $selected , array ( 'sc' => true ));
2013-03-13 09:47:48 +02:00
$data = $this -> featurebox ;
2013-03-07 22:45:59 -08:00
$scount = 0 ;
2021-01-20 12:07:29 -08:00
$category = 0 ;
2013-03-13 09:47:48 +02:00
foreach ( $selected as $id )
2013-03-07 22:45:59 -08:00
{
2013-03-13 09:47:48 +02:00
if ( ! $tree -> hasNode ( $id ))
{
e107 :: getMessage () -> addError ( 'Item #ID ' . htmlspecialchars ( $id ) . ' not found.' );
continue ; // TODO message
}
$model = $tree -> getNode ( $id );
if ( $data [ 'url' ] === true )
{
$url = $urlData [ $id ];
}
2020-12-23 16:01:20 -08:00
else
{
$url = $model -> get ( $data [ 'url' ]);
}
2013-03-13 09:47:48 +02:00
$name = $model -> get ( $data [ 'name' ]);
$category = e107 :: getDb () -> retrieve ( 'featurebox_category' , 'fb_category_id' , " fb_category_template='unassigned' " );
$fbArray = array (
'fb_title' => $name ,
'fb_text' => $model -> get ( $data [ 'description' ]),
'fb_image' => vartrue ( $data [ 'image' ]) ? $model -> get ( $data [ 'image' ]) : '' ,
'fb_imageurl' => $url ,
'fb_class' => isset ( $data [ 'visibility' ]) && $data [ 'visibility' ] !== false ? $model -> get ( $data [ 'visibility' ]) : e_UC_ADMIN ,
'fb_template' => 'default' ,
'fb_category' => $category , // TODO popup - choose category
'fb_order' => $scount ,
2013-03-07 22:45:59 -08:00
);
2013-03-13 09:47:48 +02:00
2013-03-07 22:45:59 -08:00
$res = $sql -> insert ( 'featurebox' , $fbArray );
2013-03-13 09:47:48 +02:00
2013-03-07 22:45:59 -08:00
if ( $res !== FALSE )
{
2020-12-23 16:01:20 -08:00
e107 :: getMessage () -> addSuccess ( LAN_CREATED . ': ' . LAN_PLUGIN_FEATUREBOX_NAME . ': ' . ( $name ? $name : 'n/a' ));
2017-03-19 16:42:57 +00:00
$scount ++ ;
2013-03-07 22:45:59 -08:00
}
2013-03-13 09:47:48 +02:00
else
2013-03-07 22:45:59 -08:00
{
if ( $sql -> getLastErrorNumber ())
{
2020-12-23 16:01:20 -08:00
e107 :: getMessage () -> addError ( LAN_CREATED_FAILED . ': ' . LAN_PLUGIN_FEATUREBOX_NAME . ': ' . $name . ': ' . LAN_SQL_ERROR );
2017-03-19 16:42:57 +00:00
e107 :: getMessage () -> addDebug ( 'SQL Featurebox Creation Error #' . $sql -> getLastErrorNumber () . ': ' . $sql -> getLastErrorText ());
2013-03-07 22:45:59 -08:00
}
else
{
2020-12-23 16:01:20 -08:00
e107 :: getMessage () -> addError ( LAN_CREATED_FAILED . ': ' . $name . ': ' . LAN_UNKNOWN_ERROR );
2013-03-07 22:45:59 -08:00
}
}
}
if ( $scount > 0 )
{
2020-12-23 16:01:20 -08:00
e107 :: getMessage () -> addSuccess ( LAN_CREATED . ' (' . $scount . ') ' . LAN_PLUGIN_FEATUREBOX_NAME );
2021-01-20 12:07:29 -08:00
e107 :: getMessage () -> addSuccess ( " <a class='btn btn-small btn-primary' href=' " . e_PLUGIN_ABS . " featurebox/admin_config.php?searchquery=&filter_options=fb_category__ { $category } ' " . LAN_CONFIGURE . ' ' . LAN_PLUGIN_FEATUREBOX_NAME . '</a>' );
2013-03-07 22:45:59 -08:00
return $scount ;
}
return false ;
}
2013-02-27 19:36:53 +02:00
2009-11-24 16:32:02 +00:00
/**
* Batch boolean trigger
* @ param array $selected
* @ return void
*/
protected function handleListBoolBatch ( $selected , $field , $value )
{
2018-09-18 17:58:32 -07:00
$cnt = $this -> getTreeModel () -> batchUpdate ( $field , $value , $selected , $value , false );
2009-11-24 16:32:02 +00:00
if ( $cnt )
{
2013-10-29 18:41:02 -07:00
$caption = e107 :: getParser () -> lanVars ( LAN_UI_BATCH_BOOL_SUCCESS , $cnt , true );
2013-10-29 12:20:23 -07:00
$this -> getTreeModel () -> addMessageSuccess ( $caption );
2009-11-24 16:32:02 +00:00
}
$this -> getTreeModel () -> setMessages ();
}
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
/**
* Batch boolean reverse trigger
* @ param array $selected
* @ return void
*/
2020-05-15 11:31:22 -07:00
protected function handleListBoolreverseBatch ( $selected , $field )
2009-11-24 16:32:02 +00:00
{
$tree = $this -> getTreeModel ();
2018-09-18 17:58:32 -07:00
$cnt = $tree -> batchUpdate ( $field , " 1- { $field } " , $selected , null , false );
2009-11-24 16:32:02 +00:00
if ( $cnt )
{
2013-10-29 18:41:02 -07:00
$caption = e107 :: getParser () -> lanVars ( LAN_UI_BATCH_REVERSED_SUCCESS , $cnt , true );
2013-10-29 12:20:23 -07:00
$tree -> addMessageSuccess ( $caption );
2009-11-24 16:32:02 +00:00
//sync models
2019-06-03 16:29:38 -07:00
$tree -> loadBatch ( true );
2009-11-24 16:32:02 +00:00
}
$this -> getTreeModel () -> setMessages ();
}
2009-12-23 15:12:13 +00:00
2012-12-15 16:49:19 +02:00
public function handleCommaBatch ( $selected , $field , $value , $type )
{
$tree = $this -> getTreeModel ();
2020-12-23 16:01:20 -08:00
$rcnt = 0 ;
$cnt = $rcnt ;
2019-03-02 10:09:16 -08:00
$value = e107 :: getParser () -> toDB ( $value );
2012-12-15 16:49:19 +02:00
switch ( $type )
{
case 'attach' :
case 'deattach' :
$this -> _setModel ();
foreach ( $selected as $key => $id )
{
$node = $tree -> getNode ( $id );
2020-12-23 16:01:20 -08:00
if ( ! $node )
{
continue ;
}
2012-12-15 16:49:19 +02:00
$val = $node -> get ( $field );
2020-12-23 16:01:20 -08:00
if ( empty ( $val ))
{
$val = array ();
}
elseif ( ! is_array ( $val ))
{
$val = explode ( ',' , $val );
}
2012-12-15 16:49:19 +02:00
if ( $type === 'deattach' )
{
$search = array_search ( $value , $val );
2020-12-23 16:01:20 -08:00
if ( $search === false )
{
continue ;
}
2012-12-15 16:49:19 +02:00
unset ( $val [ $search ]);
2013-01-18 17:31:12 +02:00
sort ( $val );
2012-12-15 16:49:19 +02:00
$val = implode ( ',' , $val );
$node -> set ( $field , $val );
$check = $this -> getModel () -> setData ( $node -> getData ()) -> save ( false , true );
2020-12-23 16:01:20 -08:00
if ( $check === false )
{
$this -> getModel () -> setMessages ();
}
else
{
$rcnt ++ ;
}
2013-01-18 17:31:12 +02:00
continue ;
2012-12-15 16:49:19 +02:00
}
// attach it
2020-12-23 16:01:20 -08:00
if ( in_array ( $value , $val ) === false )
2012-12-15 16:49:19 +02:00
{
$val [] = $value ;
2013-01-18 17:31:12 +02:00
sort ( $val );
2012-12-15 16:49:19 +02:00
$val = implode ( ',' , array_unique ( $val ));
$node -> set ( $field , $val );
$check = $this -> getModel () -> setData ( $node -> getData ()) -> save ( false , true );
2020-12-23 16:01:20 -08:00
if ( $check === false )
{
$this -> getModel () -> setMessages ();
}
else
{
$cnt ++ ;
}
2012-12-15 16:49:19 +02:00
}
}
$this -> _model = null ;
break ;
case 'addAll' :
2012-12-17 16:57:24 +02:00
if ( ! empty ( $value ))
{
2013-01-18 17:31:12 +02:00
if ( is_array ( $value ))
{
sort ( $value );
$value = implode ( ',' , array_map ( 'trim' , $value ));
}
2012-12-17 16:57:24 +02:00
2020-12-23 16:01:20 -08:00
$cnt = $this -> getTreeModel () -> batchUpdate ( $field , $value , $selected , true );
2012-12-17 16:57:24 +02:00
}
else
{
2017-03-19 16:42:57 +00:00
$this -> getTreeModel () -> addMessageWarning ( LAN_UPDATED_FAILED ) -> setMessages (); //"Comma list is empty, aborting."
2020-12-23 16:01:20 -08:00
$this -> getTreeModel () -> addMessageDebug ( LAN_UPDATED_FAILED . ': Comma list is empty, aborting.' ) -> setMessages ();
2012-12-17 16:57:24 +02:00
}
2012-12-15 16:49:19 +02:00
break ;
case 'clearAll' :
2012-12-17 16:57:24 +02:00
$allowed = ! is_array ( $value ) ? explode ( ',' , $value ) : $value ;
if ( ! $allowed )
{
2020-12-23 16:01:20 -08:00
$rcnt = $this -> getTreeModel () -> batchUpdate ( $field , '' , $selected , '' );
2012-12-17 16:57:24 +02:00
}
else
{
$this -> _setModel ();
foreach ( $selected as $key => $id )
{
$node = $tree -> getNode ( $id );
2020-12-23 16:01:20 -08:00
if ( ! $node )
{
continue ;
}
2012-12-17 16:57:24 +02:00
$val = $node -> get ( $field );
// nothing to do
2020-12-23 16:01:20 -08:00
if ( empty ( $val ))
{
break ;
}
elseif ( ! is_array ( $val ))
{
$val = explode ( ',' , $val );
}
2012-12-17 16:57:24 +02:00
// remove only allowed, see userclass
foreach ( $val as $_k => $_v )
{
if ( in_array ( $_v , $allowed ))
{
unset ( $val [ $_k ]);
}
}
2013-01-18 17:31:12 +02:00
sort ( $val );
2012-12-17 16:57:24 +02:00
$val = ! empty ( $val ) ? implode ( ',' , $val ) : '' ;
$node -> set ( $field , $val );
$check = $this -> getModel () -> setData ( $node -> getData ()) -> save ( false , true );
2020-12-23 16:01:20 -08:00
if ( $check === false )
{
$this -> getModel () -> setMessages ();
}
else
{
$rcnt ++ ;
}
2012-12-17 16:57:24 +02:00
}
$this -> _model = null ;
}
2013-01-18 17:31:12 +02:00
2012-12-17 16:57:24 +02:00
// format for proper message
$value = implode ( ',' , $allowed );
2012-12-15 16:49:19 +02:00
break ;
}
if ( $cnt )
{
$vttl = $this -> getUI () -> renderValue ( $field , $value , $this -> getFieldAttr ( $field ));
2013-10-29 12:20:23 -07:00
$caption = e107 :: getParser () -> lanVars ( LAN_UI_BATCH_UPDATE_SUCCESS , array ( 'x' => $vttl , 'y' => $cnt ), true );
$this -> getTreeModel () -> addMessageSuccess ( $caption );
2012-12-15 16:49:19 +02:00
}
elseif ( $rcnt )
{
$vttl = $this -> getUI () -> renderValue ( $field , $value , $this -> getFieldAttr ( $field ));
2013-10-29 12:20:23 -07:00
$caption = e107 :: getParser () -> lanVars ( LAN_UI_BATCH_DEATTACH_SUCCESS , array ( 'x' => $vttl , 'y' => $cnt ), true );
$this -> getTreeModel () -> addMessageSuccess ( $caption );
2012-12-15 16:49:19 +02:00
}
2012-12-17 16:57:24 +02:00
$this -> getTreeModel () -> setMessages ();
2012-12-15 16:49:19 +02:00
}
2019-06-04 12:59:39 -07:00
/**
* Method to generate " Search in Field " query .
* @ param $selected
* @ return string
*/
protected function handleListSearchfieldFilter ( $selected )
{
$string = $this -> getQuery ( 'searchquery' );
2019-11-05 08:54:16 -08:00
2019-06-04 12:59:39 -07:00
if ( empty ( $string ))
{
2019-06-04 13:06:34 -07:00
return null ;
2019-06-04 12:59:39 -07:00
}
return $selected . " LIKE '% " . e107 :: getParser () -> toDB ( $string ) . " %' " ; // array($selected, $this->getQuery('searchquery'));
}
2009-11-24 16:32:02 +00:00
/**
* Batch default ( field ) trigger
* @ param array $selected
2020-12-11 08:57:19 -08:00
* @ return int | null
2009-11-24 16:32:02 +00:00
*/
protected function handleListBatch ( $selected , $field , $value )
{
2012-07-12 23:26:03 +00:00
// special exceptions
2017-01-29 18:43:52 -08:00
if ( $value === '#delete' ) // see admin->users
2012-07-12 23:26:03 +00:00
{
$val = " '' " ;
2020-12-23 16:01:20 -08:00
$value = '(empty)' ;
2012-07-12 23:26:03 +00:00
}
2020-12-23 16:01:20 -08:00
elseif ( $value === '#null' )
2012-07-12 23:26:03 +00:00
{
$val = null ;
2020-12-23 16:01:20 -08:00
$value = '(empty)' ;
2012-07-12 23:26:03 +00:00
}
else
{
$val = " ' " . $value . " ' " ;
}
2017-01-29 18:43:52 -08:00
if ( $field === 'options' ) // reserved field type. see: admin -> media-manager - batch rotate image.
2012-07-29 02:36:18 +00:00
{
2020-12-11 08:57:19 -08:00
return null ;
2012-07-29 02:36:18 +00:00
}
2017-04-02 11:32:32 -07:00
2018-09-18 17:58:32 -07:00
$cnt = $this -> getTreeModel () -> batchUpdate ( $field , $val , $selected , true , false );
2009-11-24 16:32:02 +00:00
if ( $cnt )
2009-12-23 15:12:13 +00:00
{
$vttl = $this -> getUI () -> renderValue ( $field , $value , $this -> getFieldAttr ( $field ));
2013-10-29 18:41:02 -07:00
$msg = e107 :: getParser () -> lanVars ( LAN_UI_BATCH_UPDATE_SUCCESS , array ( 'x' => $vttl , 'y' => $cnt ), true );
$this -> getTreeModel () -> addMessageSuccess ( $msg );
2012-02-07 16:37:44 +00:00
// force reload the collection from DB, fix some issues as 'observer' is executed before the batch handler
2019-06-03 16:29:38 -07:00
$this -> getTreeModel () -> setParam ( 'db_query' , $this -> _modifyListQry ( false , false , false , false , $this -> listQry )) -> loadBatch ( true );
2009-11-24 16:32:02 +00:00
}
$this -> getTreeModel () -> setMessages ();
2012-01-13 11:47:39 +00:00
return $cnt ;
2009-11-24 16:32:02 +00:00
}
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
/**
* Catch delete submit
* @ param string $batch_trigger
2020-12-11 08:57:19 -08:00
* @ return null
2009-11-24 16:32:02 +00:00
*/
public function ListDeleteTrigger ( $posted )
{
2011-05-18 13:41:19 +00:00
if ( $this -> getPosted ( 'etrigger_cancel' ))
{
2010-11-04 23:27:47 +00:00
$this -> setPosted ( array ());
return ; // always break on cancel!
}
2012-12-08 21:09:58 +02:00
2020-12-23 16:01:20 -08:00
$id = ( int ) key ( $posted );
2010-11-04 23:27:47 +00:00
if ( $this -> deleteConfirmScreen && ! $this -> getPosted ( 'etrigger_delete_confirm' ))
{
// forward data to delete confirm screen
$this -> setPosted ( 'delete_confirm_value' , $id );
return ; // User confirmation expected
}
2011-05-18 13:41:19 +00:00
2010-11-04 23:27:47 +00:00
$this -> setTriggersEnabled ( false );
2009-11-24 16:32:02 +00:00
$data = array ();
2012-08-02 07:54:29 +00:00
$model = $this -> getTreeModel () -> getNode ( $id ); //FIXME - this has issues with being on a page other than the 1st.
2009-11-24 16:32:02 +00:00
if ( $model )
{
$data = $model -> getData ();
2009-11-26 17:14:07 +00:00
if ( $this -> beforeDelete ( $data , $id ))
2009-11-24 16:32:02 +00:00
{
2015-04-07 19:49:11 -07:00
2020-12-11 08:57:19 -08:00
if ( $triggerName = $this -> getEventTriggerName ( $this -> getEventName (), 'delete' )) // trigger for before.
{
2015-04-07 19:49:11 -07:00
2020-12-11 08:57:19 -08:00
if ( $halt = $this -> triggerEvent ( $triggerName , null , $data , $id ))
2015-02-09 14:15:25 -08:00
{
$this -> getTreeModel () -> setMessages ();
2020-12-11 08:57:19 -08:00
return null ;
2015-02-09 14:15:25 -08:00
}
2015-02-09 01:05:33 -08:00
}
2015-02-09 14:15:25 -08:00
$check = $this -> getTreeModel () -> delete ( $id );
2015-02-09 12:57:42 -08:00
2009-11-26 17:14:07 +00:00
if ( $this -> afterDelete ( $data , $id , $check ))
{
2020-12-11 08:57:19 -08:00
if ( $triggerName = $this -> getEventTriggerName ( $this -> getEventName (), 'deleted' )) // trigger for after.
2015-02-09 14:15:25 -08:00
{
2020-12-11 08:57:19 -08:00
$this -> triggerEvent ( $triggerName , null , $data , $id );
2015-02-09 14:15:25 -08:00
}
2009-11-26 17:14:07 +00:00
$this -> getTreeModel () -> setMessages ();
}
2009-11-24 16:32:02 +00:00
}
2009-12-12 16:40:41 +00:00
else
{
$this -> getTreeModel () -> setMessages (); // errors
}
2009-11-24 16:32:02 +00:00
}
2012-08-02 07:54:29 +00:00
else //FIXME - this is a fall-back for the BUG which causes model to fail on all list pages other than the 1st
{
//echo "Couldn't get Node for ID: ".$id;
// exit;
2020-12-23 16:01:20 -08:00
e107 :: getMessage () -> addDebug ( 'Model Failure Fallback in use!! ID: ' . $id . ' file: ' . __FILE__ . ' line: ' . __LINE__ , 'default' , true );
2012-08-02 07:54:29 +00:00
$check = $this -> getTreeModel () -> delete ( $id );
return ;
}
2009-11-24 16:32:02 +00:00
}
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
/**
* User defined pre - delete logic
*/
public function beforeDelete ( $data , $id )
{
return true ;
}
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
/**
2009-11-26 17:14:07 +00:00
* User defined after - delete logic
2009-11-24 16:32:02 +00:00
*/
2009-11-26 17:14:07 +00:00
public function afterDelete ( $deleted_data , $id , $deleted_check )
2009-11-24 16:32:02 +00:00
{
2009-11-26 17:14:07 +00:00
return true ;
2009-11-24 16:32:02 +00:00
}
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
/**
* List action header
* @ return void
*/
public function ListHeader ()
{
2013-04-06 15:50:28 +03:00
//e107::js('core','core/tabs.js','prototype');
//e107::js('core','core/admin.js','prototype');
2009-11-24 16:32:02 +00:00
}
/**
* List action observer
* @ return void
*/
public function ListObserver ()
{
2020-02-22 14:56:23 -08:00
if ( $ufieldpref = $this -> getUserPref ())
{
$this -> fieldpref = $ufieldpref ;
}
2017-02-07 14:54:02 -08:00
$table = $this -> getTableName ();
if ( empty ( $table ))
{
return ;
}
2020-02-22 14:56:23 -08:00
2019-06-03 16:29:38 -07:00
$this -> getTreeModel () -> setParam ( 'db_query' , $this -> _modifyListQry ( false , false , false , false , $this -> listQry )) -> loadBatch ();
2017-04-04 18:41:34 -07:00
2017-04-04 09:53:48 -07:00
$this -> addTitle ();
2018-05-23 16:29:37 -07:00
2020-12-11 08:57:19 -08:00
// if($this->getQuery('filter_options'))
2018-05-23 16:29:37 -07:00
{
// var_dump($this);
// $this->addTitle("to-do"); // display filter option when active.
}
2009-11-24 16:32:02 +00:00
}
2009-12-23 15:12:13 +00:00
2017-04-03 20:20:38 -07:00
/**
* Grid action observer
*/
public function GridObserver ()
{
2017-04-04 09:53:48 -07:00
$table = $this -> getTableName ();
if ( empty ( $table ))
{
return ;
}
2019-06-03 16:29:38 -07:00
$this -> getTreeModel () -> setParam ( 'db_query' , $this -> _modifyListQry ( false , false , false , false , $this -> listQry )) -> loadBatch ();
2017-04-03 20:20:38 -07:00
}
2009-11-24 16:32:02 +00:00
/**
* Filter response ajax page
* @ return string
*/
public function FilterAjaxPage ()
{
return $this -> renderAjaxFilterResponse ( $this -> listQry ); //listQry will be used only if available
}
2013-02-06 17:03:00 +02:00
/**
* Inline edit action
* @ return void
*/
public function InlineAjaxPage ()
{
2020-12-23 16:01:20 -08:00
$this -> logajax ( 'Inline Ajax Triggered' );
2016-01-03 01:03:08 -08:00
2013-02-06 17:03:00 +02:00
$protocol = ( isset ( $_SERVER [ 'SERVER_PROTOCOL' ]) ? $_SERVER [ 'SERVER_PROTOCOL' ] : 'HTTP/1.0' );
if ( ! vartrue ( $_POST [ 'name' ]) || ! vartrue ( $this -> fields [ $_POST [ 'name' ]]))
{
header ( $protocol . ': 404 Not Found' , true , 404 );
2020-12-23 16:01:20 -08:00
header ( 'Status: 404 Not Found' , true , 404 );
echo LAN_FIELD . ': ' . $this -> fields [ $_POST [ 'name' ]] . ': ' . LAN_NOT_FOUND ; // Field: x: not found!
2013-02-06 16:11:05 -08:00
$this -> logajax ( 'Field not found' );
2013-02-06 17:03:00 +02:00
return ;
}
$_name = $_POST [ 'name' ];
$_value = $_POST [ 'value' ];
2018-09-04 15:15:50 -07:00
$_token = $_POST [ 'token' ];
2013-02-06 17:03:00 +02:00
$parms = $this -> fields [ $_name ][ 'readParms' ] ? $this -> fields [ $_name ][ 'readParms' ] : '' ;
2020-12-23 16:01:20 -08:00
if ( ! is_array ( $parms ))
{
parse_str ( $parms , $parms );
}
if ( ! empty ( $parms [ 'editable' ]))
{
$this -> fields [ $_name ][ 'inline' ] = true ;
}
2013-02-06 17:03:00 +02:00
2018-09-04 15:15:50 -07:00
if ( ! empty ( $this -> fields [ $_name ][ 'noedit' ]) || ! empty ( $this -> fields [ $_name ][ 'nolist' ]) || empty ( $this -> fields [ $_name ][ 'inline' ]) || empty ( $_token ) || ! password_verify ( session_id (), $_token ))
2013-02-06 17:03:00 +02:00
{
header ( $protocol . ': 403 Forbidden' , true , 403 );
2020-12-23 16:01:20 -08:00
header ( 'Status: 403 Forbidden' , true , 403 );
2017-03-19 16:42:57 +00:00
echo ADLAN_86 ; //Forbidden
2018-09-03 11:43:44 -07:00
$result = var_export ( $this -> fields [ $_name ], true );
2020-03-19 14:51:38 -07:00
$problem = array ();
$problem [ 'noedit' ] = ! empty ( $this -> fields [ $_name ][ 'noedit' ]) ? 'yes' : 'no' ;
$problem [ 'nolist' ] = ! empty ( $this -> fields [ $_name ][ 'nolist' ]) ? 'yes' : 'no' ;
$problem [ 'inline' ] = empty ( $this -> fields [ $_name ][ 'inline' ]) ? 'yes' : 'no' ;
$problem [ 'token' ] = empty ( $_token ) ? 'yes' : 'no' ;
$problem [ 'password' ] = ! password_verify ( session_id (), $_token ) ? 'yes' : 'no' ;
$result .= " \n Forbidden Caused by: " . print_r ( $problem , true );
$this -> logajax ( " Forbidden \n Action: " . $this -> getAction () . " \n Field ( " . $_name . " ): \n " . $result );
2013-02-06 17:03:00 +02:00
return ;
}
2018-09-04 15:15:50 -07:00
2016-01-03 01:03:08 -08:00
2013-02-21 11:44:43 +02:00
2013-02-06 17:03:00 +02:00
$model = $this -> getModel () -> load ( $this -> getId ());
2013-02-21 11:44:43 +02:00
$_POST = array (); //reset post
$_POST [ $_name ] = $_value ; // set current field only
2020-06-01 12:34:20 -07:00
$_POST [ 'etrigger_submit' ] = 'update' ; // needed for event trigger
2018-09-04 15:15:50 -07:00
// print_r($_POST);
2013-02-06 17:03:00 +02:00
2013-02-21 11:44:43 +02:00
// generic handler - same as regular edit form submit
2016-01-03 01:03:08 -08:00
2013-03-08 16:00:00 +02:00
$this -> convertToData ( $_POST );
2016-01-03 01:03:08 -08:00
2020-12-23 16:01:20 -08:00
$model -> setPostedData ( $_POST );
2016-12-03 12:45:53 +01:00
$model -> setParam ( 'validateAvailable' , true ); // new param to control validate of available data only, reset on validate event
// Do not update here! Because $old_data and $new_data will be the same in afterUpdate() methods.
// Data will be saved in _manageSubmit() method.
// $model->update(true);
2015-06-16 11:02:57 -07:00
2013-02-06 17:03:00 +02:00
if ( $model -> hasError ())
{
// using 400
header ( $protocol . ': 400 Bad Request' , true , 400 );
2020-12-23 16:01:20 -08:00
header ( 'Status: 400 Bad Request' , true , 400 );
$this -> logajax ( 'Bad Request' );
2013-02-06 17:03:00 +02:00
// DEBUG e107::getMessage()->addError('Error test.', $model->getMessageStackName())->addError('Another error test.', $model->getMessageStackName());
2016-01-03 01:03:08 -08:00
2020-12-23 16:01:20 -08:00
if ( E107_DEBUG_LEVEL )
{
$message = e107 :: getMessage () -> get ( 'debug' , $model -> getMessageStackName (), true );
}
else
{
$message = e107 :: getMessage () -> get ( 'error' , $model -> getMessageStackName (), true );
}
2013-04-02 09:59:05 +03:00
2020-12-23 16:01:20 -08:00
if ( ! empty ( $message ))
{
echo implode ( ' ' , $message );
}
2016-01-03 01:03:08 -08:00
$this -> logajax ( implode ( ' ' , $message ));
2013-02-06 17:03:00 +02:00
return ;
}
2015-06-17 00:03:10 -07:00
2016-01-03 01:03:08 -08:00
//TODO ? afterInline trigger?
2015-06-17 00:03:10 -07:00
$res = $this -> _manageSubmit ( 'beforeUpdate' , 'afterUpdate' , 'onUpdateError' , 'edit' );
2013-02-06 17:03:00 +02:00
}
2013-02-06 16:11:05 -08:00
// Temporary - but useful. :-)
public function logajax ( $message )
{
2016-01-03 01:03:08 -08:00
if ( e_DEBUG !== true )
{
return ;
}
2013-02-06 16:11:05 -08:00
$message = date ( 'r' ) . " \n " . $message . " \n " ;
2016-01-03 01:03:08 -08:00
$message .= " \n _POST \n " ;
2013-02-06 16:11:05 -08:00
$message .= print_r ( $_POST , true );
2016-01-03 01:03:08 -08:00
$message .= " \n _GET \n " ;
2013-02-06 16:11:05 -08:00
$message .= print_r ( $_GET , true );
2018-09-04 15:15:50 -07:00
2020-12-23 16:01:20 -08:00
$message .= '---------------' ;
2013-02-06 16:11:05 -08:00
file_put_contents ( e_LOG . 'uiAjaxResponseInline.log' , $message . " \n \n " , FILE_APPEND );
}
2013-02-06 17:03:00 +02:00
/**
* Drag - n - Drop sort action
* @ return void
*/
public function SortAjaxPage ()
{
if ( ! isset ( $_POST [ 'all' ]) || empty ( $_POST [ 'all' ]))
{
return ;
}
if ( ! $this -> sortField )
{
echo 'Missing sort field value' ;
return ;
}
2015-04-03 21:19:43 -07:00
2021-01-01 07:38:24 -08:00
$this -> _log ( 'Executing SortAjaxPage()' );
$sql = e107 :: getDb ();
2015-04-03 21:19:43 -07:00
if ( ! empty ( $this -> sortParent )) // Force 100 positions for child when sorting with parent/child.
{
$this -> orderStep = 100 ;
}
2021-01-01 07:38:24 -08:00
else // Reset all the order fields first.
{
$resetQry = $this -> sortField . " = 999 WHERE 1 " ; // .$this->sortField;
$sql -> update ( $this -> table , $resetQry );
$this -> _log ( 'Sort Qry (' . $this -> table . '): ' . $resetQry );
}
2015-04-03 21:19:43 -07:00
2020-12-23 16:01:20 -08:00
$step = $this -> orderStep ? ( int ) $this -> orderStep : 1 ;
2019-03-19 12:01:51 -07:00
$from = ! empty ( $_GET [ 'from' ]) ? ( int ) $_GET [ 'from' ] * $step : $step ;
2015-04-02 12:55:26 -07:00
2015-04-02 13:57:37 -07:00
$c = $from ;
2013-02-06 17:03:00 +02:00
$updated = array ();
2015-04-02 12:33:15 -07:00
2013-02-06 17:03:00 +02:00
foreach ( $_POST [ 'all' ] as $row )
{
2015-04-02 13:57:37 -07:00
2020-12-23 16:01:20 -08:00
list ( $tmp , $id ) = explode ( '-' , $row , 2 );
2019-03-19 12:01:51 -07:00
$id = preg_replace ( '/[^\w\-:.]/' , '' , $id );
2020-12-23 16:01:20 -08:00
if ( ! is_numeric ( $id ))
{
$id = " ' { $id } ' " ;
}
2021-01-01 07:38:24 -08:00
$updateQry = $this -> sortField . " = { $c } WHERE " . $this -> pid . ' = ' . $id ;
if ( $sql -> update ( $this -> table , $updateQry ) !== false )
2013-02-06 17:03:00 +02:00
{
2020-12-23 16:01:20 -08:00
$updated [] = '#' . $id . ' -- ' . $this -> sortField . ' = ' . $c ;
2013-02-06 17:03:00 +02:00
}
2019-03-19 12:01:51 -07:00
2021-01-01 07:38:24 -08:00
$this -> _log ( 'Sort Qry (' . $this -> table . '): ' . $updateQry );
2019-03-19 12:01:51 -07:00
$c += $step ;
2017-03-28 15:16:27 -07:00
}
2015-04-02 12:33:15 -07:00
2017-03-28 15:16:27 -07:00
if ( ! empty ( $this -> sortParent ) && ! empty ( $this -> sortField ) )
{
return null ;
2013-02-06 17:03:00 +02:00
}
2015-04-02 12:33:15 -07:00
2017-03-28 15:16:27 -07:00
2021-01-01 07:38:24 -08:00
// Increment every record after the current page of records.
2015-04-02 13:57:37 -07:00
$changed = $c - $step ;
2020-12-23 16:01:20 -08:00
$qry = 'UPDATE `#' . $this -> table . '` e, (SELECT @n := ' . ( $changed ) . ') m SET e.' . $this -> sortField . ' = @n := @n + ' . $step . ' WHERE ' . $this -> sortField . ' > ' . ( $changed );
2015-04-03 21:19:43 -07:00
$result = $sql -> gen ( $qry );
2021-01-01 07:38:24 -08:00
$this -> _log ( 'Sort Qry: ' . $qry );
2015-04-03 21:19:43 -07:00
// ------------ Fix Child Order when parent is used. ----------------
2017-03-28 15:16:27 -07:00
/*
2015-04-03 21:19:43 -07:00
if ( ! empty ( $this -> sortParent ) && ! empty ( $this -> sortField ) ) // Make sure there is space for at least 99
{
2017-03-28 15:16:27 -07:00
$parent = array ();
2015-04-03 21:19:43 -07:00
$data2 = $sql -> retrieve ( $this -> table , $this -> pid . ',' . $this -> sortField , $this -> sortParent . ' = 0' , true );
foreach ( $data2 as $val )
{
$id = $val [ $this -> pid ];
$parent [ $id ] = $val [ $this -> sortField ];
}
$previous = 0 ;
$data = $sql -> retrieve ( $this -> table , '*' , $this -> sortParent . ' != 0 ORDER BY ' . $this -> sortField , true );
foreach ( $data as $row )
{
$p = $row [ $this -> sortParent ];
if ( $p != $previous )
{
$c = $parent [ $p ];
}
$c ++ ;
$previous = $p ;
// echo "<br />".$row['forum_name']." with parent: ".$p." old: ".$row['forum_order']." new: ".$c;
$sql -> update ( $this -> table , $this -> sortField . ' = ' . $c . ' WHERE ' . $this -> pid . ' = ' . intval ( $row [ $this -> pid ]) . ' LIMIT 1' );
}
2017-03-28 17:34:01 -07:00
}
*/
2015-04-03 21:19:43 -07:00
$this -> afterSort ( $result , $_POST );
2015-04-02 12:33:15 -07:00
// e107::getLog()->addDebug(print_r($_POST,true))->toFile('SortAjax','Admin-UI Ajax Sort Log', true);
2015-04-02 13:57:37 -07:00
// e107::getLog()->addDebug(print_r($updated,true))->toFile('SortAjax','Admin-UI Ajax Sort Log', true);
2015-04-02 12:33:15 -07:00
// e107::getLog()->addDebug($qry)->toFile('SortAjax','Admin-UI Ajax Sort Log', true);
2015-04-02 13:57:37 -07:00
2013-02-06 17:03:00 +02:00
}
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
/**
* Generic List action page
* @ return string
*/
public function ListPage ()
{
2010-11-04 23:27:47 +00:00
if ( $this -> deleteConfirmScreen && ! $this -> getPosted ( 'etrigger_delete_confirm' ) && $this -> getPosted ( 'delete_confirm_value' ))
{
// 'edelete_confirm_data' set by single/batch delete trigger
return $this -> getUI () -> getConfirmDelete ( $this -> getPosted ( 'delete_confirm_value' )); // User confirmation expected
}
2009-11-24 16:32:02 +00:00
return $this -> getUI () -> getList ();
}
2009-12-23 15:12:13 +00:00
2017-04-03 20:20:38 -07:00
/**
* Generic List action page
* @ return string
*/
public function GridPage ()
{
if ( $this -> deleteConfirmScreen && ! $this -> getPosted ( 'etrigger_delete_confirm' ) && $this -> getPosted ( 'delete_confirm_value' ))
{
// 'edelete_confirm_data' set by single/batch delete trigger
return $this -> getUI () -> getConfirmDelete ( $this -> getPosted ( 'delete_confirm_value' )); // User confirmation expected
}
return $this -> getUI () -> getList ( null , 'grid' );
}
2009-11-24 16:32:02 +00:00
/**
* List action observer
* @ return void
*/
public function ListAjaxObserver ()
{
2020-04-11 11:28:26 -07:00
if ( $ufieldpref = $this -> getUserPref ())
{
$this -> fieldpref = $ufieldpref ;
}
2019-06-03 16:29:38 -07:00
$this -> getTreeModel () -> setParam ( 'db_query' , $this -> _modifyListQry ( false , false , 0 , false , $this -> listQry )) -> loadBatch ();
2009-11-24 16:32:02 +00:00
}
2009-12-23 15:12:13 +00:00
2017-04-03 20:20:38 -07:00
/**
* List action observer
* @ return void
*/
public function GridAjaxObserver ()
{
$this -> ListAjaxObserver ();
}
2009-11-24 16:32:02 +00:00
/**
* Generic List action page ( Ajax )
* @ return string
*/
public function ListAjaxPage ()
{
return $this -> getUI () -> getList ( true );
}
2009-12-23 15:12:13 +00:00
2017-04-03 20:20:38 -07:00
public function GridAjaxPage ()
{
return $this -> getUI () -> getList ( true , 'grid' );
}
2009-11-24 16:32:02 +00:00
/**
* Generic Edit observer
*/
public function EditObserver ()
{
$this -> getModel () -> load ( $this -> getId ());
2013-02-22 16:12:05 +02:00
$this -> addTitle ();
2020-03-11 14:52:34 -07:00
$this -> addTitle ( '#' . $this -> getId ()); // Inform user of which record is being edited.
2009-11-24 16:32:02 +00:00
}
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
/**
* Generic Create submit trigger
*/
public function EditCancelTrigger ()
{
$this -> redirectAction ( 'list' , 'id' );
}
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
/**
* Generic Edit submit trigger
*/
public function EditSubmitTrigger ()
{
2009-11-28 15:34:46 +00:00
$this -> _manageSubmit ( 'beforeUpdate' , 'afterUpdate' , 'onUpdateError' , 'edit' );
2009-11-24 16:32:02 +00:00
}
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
/**
* Edit - send JS to page Header
2009-12-13 21:52:32 +00:00
* @ return none
2009-11-24 16:32:02 +00:00
*/
2020-12-23 16:01:20 -08:00
public function EditHeader ()
2009-11-24 16:32:02 +00:00
{
2012-05-16 20:19:16 +00:00
// e107::getJs()->requireCoreLib('core/admin.js');
e107 :: js ( 'core' , 'core/admin.js' , 'prototype' );
2009-11-24 16:32:02 +00:00
}
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
/**
* Generic Edit page
* @ return string
*/
public function EditPage ()
{
return $this -> CreatePage ();
}
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
/**
* Generic Create observer
* @ return string
*/
public function CreateObserver ()
{
2009-11-28 15:34:46 +00:00
$this -> setTriggersEnabled ( true );
2013-02-22 16:12:05 +02:00
$this -> addTitle ();
2009-11-24 16:32:02 +00:00
}
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
/**
* Generic Create submit trigger
*/
public function CreateCancelTrigger ()
{
$this -> redirectAction ( 'list' , 'id' );
}
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
/**
* Generic Create submit trigger
*/
public function CreateSubmitTrigger ()
{
2009-11-28 15:34:46 +00:00
$this -> _manageSubmit ( 'beforeCreate' , 'afterCreate' , 'onCreateError' );
2009-11-24 16:32:02 +00:00
}
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
/**
2009-11-28 15:34:46 +00:00
* User defined pre - create logic , return false to prevent DB query execution
2013-03-02 01:02:49 -08:00
* @ param $new_data
* @ param $old_data
2009-11-24 16:32:02 +00:00
*/
public function beforeCreate ( $new_data , $old_data )
{
}
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
/**
* User defined after - create logic
2013-03-02 01:02:49 -08:00
* @ param $new_data
* @ param $old_data
* @ param $id
2009-11-24 16:32:02 +00:00
*/
public function afterCreate ( $new_data , $old_data , $id )
{
}
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
/**
2009-11-28 15:34:46 +00:00
* User defined error handling , return true to suppress model messages
2013-03-02 01:02:49 -08:00
* @ param $new_data
* @ param $old_data
2009-11-28 15:34:46 +00:00
*/
public function onCreateError ( $new_data , $old_data )
{
}
2009-12-23 15:12:13 +00:00
2009-11-28 15:34:46 +00:00
/**
* User defined pre - update logic , return false to prevent DB query execution
2013-03-02 01:02:49 -08:00
* @ param $new_data
* @ param $old_data
2009-11-24 16:32:02 +00:00
*/
public function beforeUpdate ( $new_data , $old_data , $id )
{
}
2009-12-23 15:12:13 +00:00
2015-04-08 20:20:10 -07:00
2009-11-24 16:32:02 +00:00
/**
* User defined after - update logic
2013-03-02 01:02:49 -08:00
* @ param $new_data
* @ param $old_data
2009-11-24 16:32:02 +00:00
*/
public function afterUpdate ( $new_data , $old_data , $id )
{
}
2009-12-23 15:12:13 +00:00
2009-11-28 15:34:46 +00:00
/**
2018-09-10 10:42:54 -07:00
* User defined before pref saving logic
* @ param $new_data
* @ param $old_data
*/
public function beforePrefsSave ( $new_data , $old_data )
{
2020-12-11 08:57:19 -08:00
return null ;
2018-09-10 10:42:54 -07:00
}
2019-05-13 11:33:11 -07:00
/**
* User defined before pref saving logic
*/
public function afterPrefsSave ()
{
2020-12-11 08:57:19 -08:00
return null ;
2019-05-13 11:33:11 -07:00
}
2018-09-10 10:42:54 -07:00
/**
* User defined error handling , return true to suppress model messages
*/
2009-11-28 15:34:46 +00:00
public function onUpdateError ( $new_data , $old_data , $id )
{
}
2009-12-23 15:12:13 +00:00
2014-02-26 16:56:17 +02:00
/**
* User defined after - update logic
* @ param mixed $result
* @ param array $selected
* @ return void
*/
public function afterCopy ( $result , $selected )
{
}
2015-04-03 21:19:43 -07:00
/**
* User defined after - sort logic
* @ param mixed $result
* @ param array $selected
* @ return void
*/
public function afterSort ( $result , $selected )
{
}
2015-04-09 01:39:37 -07:00
2017-02-05 15:49:03 -08:00
/**
* @ return string
*/
2015-04-09 01:39:37 -07:00
public function renderHelp ()
{
2017-02-05 15:49:03 -08:00
2015-04-09 01:39:37 -07:00
}
2009-11-24 16:32:02 +00:00
/**
* Create - send JS to page Header
2009-12-13 21:52:32 +00:00
* @ return none
2009-11-24 16:32:02 +00:00
*/
2020-12-23 16:01:20 -08:00
public function CreateHeader ()
2009-11-24 16:32:02 +00:00
{
// TODO - invoke it on className (not all textarea elements)
2012-05-16 20:19:16 +00:00
//e107::getJs()->requireCoreLib('core/admin.js');
e107 :: js ( 'core' , 'core/admin.js' , 'prototype' );
2009-11-24 16:32:02 +00:00
}
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
/**
2009-12-23 15:12:13 +00:00
*
2019-05-13 11:33:11 -07:00
* @ return string
2009-11-24 16:32:02 +00:00
*/
public function CreatePage ()
{
return $this -> getUI () -> getCreate ();
}
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
public function PrefsSaveTrigger ()
{
2015-06-05 12:25:32 -07:00
$data = $this -> getPosted ();
2018-09-10 10:42:54 -07:00
$beforePref = $data ;
unset ( $beforePref [ 'e-token' ], $beforePref [ 'etrigger_save' ]);
$tmp = $this -> beforePrefsSave ( $beforePref , $this -> getConfig () -> getPref ());
if ( ! empty ( $tmp ))
{
$data = $tmp ;
}
2016-09-12 11:30:08 -07:00
foreach ( $this -> prefs as $k => $v ) // fix for empty checkboxes - need to save a value.
{
2017-01-29 18:43:52 -08:00
if ( ! isset ( $data [ $k ]) && $v [ 'data' ] !== false && ( $v [ 'type' ] === 'checkboxes' || $v [ 'type' ] === 'checkbox' ))
2016-09-12 11:30:08 -07:00
{
$data [ $k ] = null ;
}
}
2015-06-05 12:25:32 -07:00
foreach ( $data as $key => $val )
{
2016-09-12 11:30:08 -07:00
2015-06-05 12:25:32 -07:00
if ( ! empty ( $this -> prefs [ $key ][ 'multilan' ]))
{
2015-06-05 16:27:52 -07:00
if ( is_string ( $this -> getConfig () -> get ( $key ))) // most likely upgraded to multilan=>true, so reset to an array structure.
{
2020-12-23 16:01:20 -08:00
$this -> getConfig () -> setPostedData ( $key , array ( e_LANGUAGE => $val ));
2015-06-05 16:27:52 -07:00
}
else
{
2017-03-02 09:39:50 -08:00
$lang = key ( $val );
$value = $val [ $lang ];
$this -> getConfig () -> setData ( $key . '/' . $lang , str_replace ( " ' " , ''' , $value ));
2015-06-05 16:27:52 -07:00
}
2015-06-05 12:25:32 -07:00
}
else
{
2020-12-23 16:01:20 -08:00
$this -> getConfig () -> setPostedData ( $key , $val );
2015-06-05 12:25:32 -07:00
}
}
2020-12-23 16:01:20 -08:00
$this -> getConfig () -> save ();
2015-06-05 12:25:32 -07:00
2019-05-13 11:33:11 -07:00
$this -> afterPrefsSave ();
2015-06-05 12:25:32 -07:00
/*
2009-11-24 16:32:02 +00:00
$this -> getConfig ()
2016-12-03 09:24:41 +01:00
-> setPostedData ( $this -> getPosted (), null , false )
2009-11-24 16:32:02 +00:00
//->setPosted('not_existing_pref_test', 1)
-> save ( true );
2015-06-05 12:25:32 -07:00
*/
2009-11-24 16:32:02 +00:00
$this -> getConfig () -> setMessages ();
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
}
2013-02-22 16:12:05 +02:00
public function PrefsObserver ()
{
$this -> addTitle ();
}
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
public function PrefsPage ()
{
return $this -> getUI () -> getSettings ();
}
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
/**
* Parent overload
* @ return e_admin_ui
*/
protected function parseAliases ()
{
// parse table
if ( strpos ( $this -> table , '.' ) !== false )
{
$tmp = explode ( '.' , $this -> table , 2 );
2009-12-23 15:12:13 +00:00
$this -> table = $tmp [ 1 ];
2009-11-24 16:32:02 +00:00
$this -> tableAlias = $tmp [ 0 ];
unset ( $tmp );
}
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
parent :: parseAliases ();
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
return $this ;
}
public function getPrimaryName ()
{
2010-11-04 23:27:47 +00:00
// Option for working with tables having no PID
2020-12-23 16:01:20 -08:00
if ( $this -> pid !== false && empty ( $this -> pid ) && ! empty ( $this -> fields ))
2009-11-24 16:32:02 +00:00
{
2019-02-26 12:22:36 -08:00
$message = e107 :: getParser () -> toHTML ( LAN_UI_NOPID_ERROR , true );
2013-10-29 12:20:23 -07:00
e107 :: getMessage () -> add ( $message , E_MESSAGE_WARNING );
2009-11-24 16:32:02 +00:00
}
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
return $this -> pid ;
}
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
public function getTableName ( $alias = false , $prefix = false )
{
2020-12-23 16:01:20 -08:00
if ( $alias )
{
return ( $this -> tableAlias ? $this -> tableAlias : '' );
}
2009-11-24 16:32:02 +00:00
return ( $prefix ? '#' : '' ) . $this -> table ;
}
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
/**
* Validation rules retrieved from controller object
* @ return array
*/
public function getValidationRules ()
{
return $this -> validationRules ;
}
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
/**
* Data Field array retrieved from controller object
* @ return array
*/
public function getDataFields ()
{
return $this -> dataFields ;
}
2009-12-23 15:12:13 +00:00
2009-11-26 09:02:46 +00:00
/**
* Set read and write parms with drop - down - list array data ( ie . type = 'dropdown' )
2020-12-08 12:21:12 -08:00
* @ param string $field
2009-11-26 09:02:46 +00:00
* @ param array $array [ optional ]
2020-12-08 12:21:12 -08:00
* @ return null
2009-11-26 09:02:46 +00:00
*/
2009-12-23 15:12:13 +00:00
public function setDropDown ( $field , $array ) //TODO Have Miro check this.
2009-11-26 09:02:46 +00:00
{
$this -> fields [ $field ][ 'readParms' ] = $array ;
$this -> fields [ $field ][ 'writeParms' ] = $array ;
}
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
/**
2009-12-23 15:12:13 +00:00
* Set Config object
2009-11-24 16:32:02 +00:00
* @ return e_admin_ui
*/
protected function _setConfig ()
2009-12-23 15:12:13 +00:00
{
2017-01-29 18:43:52 -08:00
$this -> _pref = $this -> pluginName === 'core' ? e107 :: getConfig () : e107 :: getPlugConfig ( $this -> pluginName );
2009-12-23 15:12:13 +00:00
2018-03-07 11:41:59 -08:00
if ( $this -> pluginName !== 'core' && ! e107 :: isInstalled ( $this -> pluginName ))
{
$obj = get_class ( $this );
2020-12-23 16:01:20 -08:00
e107 :: getMessage () -> addWarning ( $obj . 'The plugin is not installed or $pluginName: is not valid. (' . $this -> pluginName . ')' ); // debug only.
2018-03-07 11:41:59 -08:00
return $this ;
}
2020-12-23 16:01:20 -08:00
$validateRules = array ();
$dataFields = $validateRules ;
2009-11-24 16:32:02 +00:00
foreach ( $this -> prefs as $key => $att )
{
// create dataFields array
$dataFields [ $key ] = vartrue ( $att [ 'data' ], 'string' );
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
// create validation array
2020-12-20 11:50:10 -08:00
if ( ! empty ( $att [ 'validate' ]))
2009-11-24 16:32:02 +00:00
{
2020-12-23 16:01:20 -08:00
$validateRules [ $key ] = array (( $att [ 'validate' ] === true ? 'required' : $att [ 'validate' ]), varset ( $att [ 'rule' ]), $att [ 'title' ], varset ( $att [ 'error' ], $att [ 'help' ]));
2009-11-24 16:32:02 +00:00
}
2009-12-23 15:12:13 +00:00
/* Not implemented in e_model yet
2009-11-24 16:32:02 +00:00
elseif ( vartrue ( $att [ 'check' ]))
{
$validateRules [ $key ] = array ( $att [ 'check' ], varset ( $att [ 'rule' ]), $att [ 'title' ], varset ( $att [ 'error' ], $att [ 'help' ]));
} */
}
$this -> _pref -> setDataFields ( $dataFields ) -> setValidationRules ( $validateRules );
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
return $this ;
}
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
/**
* Set current model
*
* @ return e_admin_ui
*/
public function _setModel ()
{
// try to create dataFields array if missing
2016-01-03 01:03:08 -08:00
2009-11-24 16:32:02 +00:00
if ( ! $this -> dataFields )
{
$this -> dataFields = array ();
foreach ( $this -> fields as $key => $att )
{
2015-02-20 11:03:14 -08:00
if ( $key == $this -> pid && empty ( $att [ 'data' ])) // Set integer as default for primary ID when not specified. MySQL Strict Fix.
{
$this -> dataFields [ $key ] = 'int' ;
continue ;
}
2020-12-23 16:01:20 -08:00
if (( empty ( $att [ 'data' ]) || empty ( $att [ 'rule' ])) && varset ( $att [ 'type' ]) === 'comma' )
2012-12-17 16:57:24 +02:00
{
$att [ 'data' ] = 'set' ;
$att [ 'validate' ] = 'set' ;
$_parms = vartrue ( $att [ 'writeParms' ], array ());
2020-12-23 16:01:20 -08:00
if ( is_string ( $_parms ))
{
parse_str ( $_parms , $_parms );
}
2012-12-17 16:57:24 +02:00
unset ( $_parms [ '__options' ]);
$att [ 'rule' ] = $_parms ;
unset ( $_parms );
}
2016-01-03 01:03:08 -08:00
2017-01-29 18:43:52 -08:00
if ( ! empty ( $att [ 'data' ]) && $att [ 'data' ] === 'array' && ( $this -> getAction () === 'inline' )) // FIX for arrays being saved incorrectly with inline editing.
2016-01-03 01:03:08 -08:00
{
$att [ 'data' ] = 'set' ;
}
2020-12-23 16:01:20 -08:00
if ( ! empty ( $att [ 'forceSave' ]) || ( $key !== 'options' && varset ( $att [ 'data' ]) !== false && varset ( $att [ 'type' ], null ) !== null && ! vartrue ( $att [ 'noedit' ])))
2009-11-24 16:32:02 +00:00
{
$this -> dataFields [ $key ] = vartrue ( $att [ 'data' ], 'str' );
2017-01-29 11:08:43 -08:00
if ( ! empty ( $att [ 'type' ]))
{
$this -> fieldInputTypes [ $key ] = $att [ 'type' ];
}
2009-11-24 16:32:02 +00:00
}
2016-01-03 01:03:08 -08:00
2009-11-24 16:32:02 +00:00
}
}
2016-01-03 01:03:08 -08:00
2009-11-24 16:32:02 +00:00
// TODO - do it in one loop, or better - separate method(s) -> convertFields(validate), convertFields(data),...
if ( ! $this -> validationRules )
{
$this -> validationRules = array ();
foreach ( $this -> fields as $key => $att )
{
2020-12-23 16:01:20 -08:00
if ( varset ( $att [ 'type' ], null ) === null || vartrue ( $att [ 'noedit' ]))
2009-11-24 16:32:02 +00:00
{
continue ;
}
2020-12-20 11:50:10 -08:00
if ( ! empty ( $att [ 'validate' ]))
2009-11-24 16:32:02 +00:00
{
2020-12-23 16:01:20 -08:00
$this -> validationRules [ $key ] = array (( $att [ 'validate' ] === true ? 'required' : $att [ 'validate' ]), varset ( $att [ 'rule' ]), $att [ 'title' ], varset ( $att [ 'error' ], vartrue ( $att [ 'help' ])));
2009-11-24 16:32:02 +00:00
}
/* elseif ( vartrue ( $att [ 'check' ])) could go ?
{
$this -> checkRules [ $key ] = array ( $att [ 'check' ], varset ( $att [ 'rule' ]), $att [ 'title' ], varset ( $att [ 'error' ], $att [ 'help' ]));
} */
}
}
2011-05-18 13:41:19 +00:00
2010-12-27 12:38:14 +00:00
// don't touch it if already exists
2020-12-23 16:01:20 -08:00
if ( $this -> _model )
{
return $this ;
}
2011-05-18 13:41:19 +00:00
2009-11-24 16:32:02 +00:00
// default model
2017-01-29 11:08:43 -08:00
2009-11-24 16:32:02 +00:00
$this -> _model = new e_admin_model ();
$this -> _model -> setModelTable ( $this -> table )
-> setFieldIdName ( $this -> pid )
2018-02-09 05:34:09 -06:00
-> setUrl ( $this -> url )
2009-11-24 16:32:02 +00:00
-> setValidationRules ( $this -> validationRules )
2010-05-05 15:05:32 +00:00
-> setDbTypes ( $this -> fieldTypes )
2017-01-29 11:08:43 -08:00
-> setFieldInputTypes ( $this -> fieldInputTypes )
2009-11-24 16:32:02 +00:00
-> setDataFields ( $this -> dataFields )
2009-11-28 15:34:46 +00:00
-> setMessageStackName ( 'admin_ui_model_' . $this -> table )
2009-12-23 15:12:13 +00:00
-> setParam ( 'db_query' , $this -> editQry );
2009-11-24 16:32:02 +00:00
return $this ;
}
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
/**
* Set current tree
* @ return e_admin_ui
*/
public function _setTreeModel ()
{
// default tree model
$this -> _tree_model = new e_admin_tree_model ();
$this -> _tree_model -> setModelTable ( $this -> table )
2011-05-30 16:43:01 +00:00
-> setFieldIdName ( $this -> pid )
2018-02-09 05:34:09 -06:00
-> setUrl ( $this -> url )
2009-11-28 15:34:46 +00:00
-> setMessageStackName ( 'admin_ui_tree_' . $this -> table )
2018-01-28 12:40:30 -06:00
-> setParams ( array ( 'model_class' => 'e_admin_model' ,
2018-02-09 05:34:09 -06:00
'model_message_stack' => 'admin_ui_model_' . $this -> table ,
2018-01-28 12:40:30 -06:00
'db_query' => $this -> listQry ,
// Information necessary for PHP-based tree sort
'sort_parent' => $this -> getSortParent (),
'sort_field' => $this -> getSortField (),
'primary_field' => $this -> getPrimaryName (),
));
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
return $this ;
}
/**
* Get extended ( UI ) Form instance
*
* @ return e_admin_ui
*/
public function _setUI ()
{
if ( $this -> getParam ( 'ui' ))
{
$this -> _ui = $this -> getParam ( 'ui' );
$this -> setParam ( 'ui' , null );
}
else // default ui
{
$this -> _ui = new e_admin_form_ui ( $this );
}
return $this ;
}
}
class e_admin_form_ui extends e_form
2009-12-23 15:12:13 +00:00
{
2009-11-24 16:32:02 +00:00
/**
* @ var e_admin_ui
*/
2020-12-23 16:01:20 -08:00
protected $_controller ;
protected $_list_view ;
2009-12-23 15:12:13 +00:00
2017-03-30 08:57:01 -07:00
2009-11-24 16:32:02 +00:00
/**
* Constructor
2020-02-20 08:53:32 -08:00
* @ param e_admin_controller_ui $controller
2009-11-24 16:32:02 +00:00
* @ param boolean $tabindex [ optional ] enable form element auto tab - indexing
*/
2020-12-23 16:01:20 -08:00
public function __construct ( $controller , $tabindex = false )
2009-11-24 16:32:02 +00:00
{
$this -> _controller = $controller ;
parent :: __construct ( $tabindex );
2009-12-23 15:12:13 +00:00
// protect current methods from conflict.
2009-11-24 16:32:02 +00:00
$this -> preventConflict ();
// user constructor
$this -> init ();
}
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
protected function preventConflict ()
{
2010-11-04 23:27:47 +00:00
$err = false ;
$fields = $this -> getController () -> getFields ();
2017-02-09 10:19:55 -08:00
if ( empty ( $fields ))
{
return null ;
}
2010-11-04 23:27:47 +00:00
foreach ( $fields as $field => $foptions )
2009-11-24 16:32:02 +00:00
{
2010-11-04 23:27:47 +00:00
// check form custom methods
2012-12-08 13:52:05 +01:00
if ( vartrue ( $foptions [ 'type' ]) === 'method' && method_exists ( 'e_form' , $field )) // check even if type is not method. - just in case of an upgrade later by 3rd-party.
2009-11-24 16:32:02 +00:00
{
2013-10-29 12:20:23 -07:00
$message = e107 :: getParser () -> lanVars ( LAN_UI_FORM_METHOD_ERROR , array ( 'x' => $field ), true );
e107 :: getMessage () -> addError ( $message );
2010-11-04 23:27:47 +00:00
$err = true ;
2009-12-23 15:12:13 +00:00
}
2009-11-24 16:32:02 +00:00
}
2011-05-18 13:41:19 +00:00
2010-11-04 23:27:47 +00:00
/* if ( $err )
2009-11-24 16:32:02 +00:00
{
2010-11-04 23:27:47 +00:00
//echo $err;
//exit;
} */
2009-11-24 16:32:02 +00:00
}
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
/**
* User defined init
*/
public function init ()
{
}
2009-12-23 15:12:13 +00:00
2017-03-28 15:16:27 -07:00
/**
* @ todo Get a 'depth/level' field working with mysql and change the 'level' accordingly
* @ param mixed $curVal
* @ param string $mode read | write | inline
* @ param array $parm
* @ return array | string
*/
public function treePrefix ( $curVal , $mode , $parm )
{
$controller = $this -> getController ();
$parentField = $controller -> getSortParent ();
$treePrefixField = $controller -> getTreePrefix ();
$parent = $controller -> getListModel () -> get ( $parentField );
2020-12-23 16:01:20 -08:00
$level = $controller -> getListModel () -> get ( '_depth' );
2017-03-28 15:16:27 -07:00
if ( $mode === 'read' )
{
$inline = $this -> getController () -> getFieldAttr ( $treePrefixField , 'inline' );
if ( $inline === true )
{
return $curVal ;
}
$level_image = $parent ? str_replace ( 'level-x' , 'level-' . $level , ADMIN_CHILD_ICON ) : '' ;
return ( $parent ) ? $level_image . $curVal : $curVal ;
}
if ( $mode === 'inline' )
{
$ret = array ( 'inlineType' => 'text' );
if ( ! empty ( $parent ))
{
$ret [ 'inlineParms' ] = array ( 'pre' => str_replace ( 'level-x' , 'level-' . $level , ADMIN_CHILD_ICON ));
}
return $ret ;
}
/*
if ( $mode == 'write' ) // not used.
{
// return $frm->text('forum_name',$curVal,255,'size=xxlarge');
}
if ( $mode == 'filter' )
{
return ;
}
if ( $mode == 'batch' )
{
return ;
}
*/
}
2009-11-24 16:32:02 +00:00
/**
2009-12-23 15:12:13 +00:00
* Generic DB Record Creation Form .
2009-11-24 16:32:02 +00:00
* @ return string
*/
2020-12-23 16:01:20 -08:00
public function getCreate ()
2009-11-24 16:32:02 +00:00
{
$controller = $this -> getController ();
2009-12-23 15:12:13 +00:00
$request = $controller -> getRequest ();
2009-11-24 16:32:02 +00:00
if ( $controller -> getId ())
{
2013-10-29 18:41:02 -07:00
$legend = e107 :: getParser () -> lanVars ( LAN_UI_EDIT_LABEL , $controller -> getId ()); // sprintXXX(LAN_UI_EDIT_LABEL, $controller->getId());
2010-10-30 15:34:48 +00:00
$form_start = vartrue ( $controller -> headerUpdateMarkup );
$form_end = vartrue ( $controller -> footerUpdateMarkup );
2009-11-24 16:32:02 +00:00
}
else
{
2010-11-04 23:27:47 +00:00
$legend = LAN_UI_CREATE_LABEL ;
2010-10-30 15:34:48 +00:00
$form_start = vartrue ( $controller -> headerCreateMarkup );
$form_end = vartrue ( $controller -> footerCreateMarkup );
2009-11-24 16:32:02 +00:00
}
2010-10-30 15:34:48 +00:00
2015-06-05 15:36:21 -07:00
$tabs = $controller -> getTabs ();
if ( $multiLangInfo = $this -> renderLanguageTableInfo ())
{
if ( empty ( $tabs ))
{
2020-12-23 16:01:20 -08:00
$head = " <div id='admin-ui-edit-db-language' class='text-right'> " . $multiLangInfo . '</div>' ;
2015-06-05 15:36:21 -07:00
}
else
{
2020-12-23 16:01:20 -08:00
$head = " <div id='admin-ui-edit-db-language' class='text-right tabs'> " . $multiLangInfo . '</div>' ;
2015-06-05 15:36:21 -07:00
}
}
else
{
$head = '' ;
}
2011-05-18 13:41:19 +00:00
2020-12-23 16:01:20 -08:00
$models = array ();
$forms = array ();
2009-11-24 16:32:02 +00:00
$forms [] = array (
'id' => $this -> getElementId (),
2015-06-05 15:36:21 -07:00
'header' => $head ,
'footer' => '' ,
2009-11-24 16:32:02 +00:00
//'url' => e_SELF,
//'query' => 'self', or custom GET query, self is default
'fieldsets' => array (
'create' => array (
2015-06-05 15:36:21 -07:00
'tabs' => $tabs , //used within a single form.
2009-11-24 16:32:02 +00:00
'legend' => $legend ,
'fields' => $controller -> getFields (), //see e_admin_ui::$fields
2015-06-05 15:36:21 -07:00
'header' => $form_start , //XXX Unused?
'footer' => $form_end , //XXX Unused?
2016-10-20 09:00:58 +02:00
'after_submit_options' => $controller -> getAfterSubmitOptions (), // or true for default redirect options
2009-11-24 16:32:02 +00:00
'after_submit_default' => $request -> getPosted ( '__after_submit_action' , $controller -> getDefaultAction ()), // or true for default redirect options
2019-05-09 15:14:56 -07:00
'triggers' => $controller -> getDefaultTrigger (), // standard create/update-cancel triggers
2009-11-24 16:32:02 +00:00
)
2009-12-23 15:12:13 +00:00
)
2009-11-24 16:32:02 +00:00
);
2019-05-09 15:14:56 -07:00
2009-11-24 16:32:02 +00:00
$models [] = $controller -> getModel ();
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
return $this -> renderCreateForm ( $forms , $models , e_AJAX_REQUEST );
}
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
/**
2009-12-23 15:12:13 +00:00
* Generic Settings Form .
2009-11-24 16:32:02 +00:00
* @ return string
*/
2020-12-23 16:01:20 -08:00
public function getSettings ()
2009-11-24 16:32:02 +00:00
{
$controller = $this -> getController ();
2016-05-15 15:04:25 -07:00
// $request = $controller->getRequest();
2010-11-04 23:27:47 +00:00
$legend = LAN_UI_PREF_LABEL ;
2020-12-23 16:01:20 -08:00
$models = array ();
$forms = array ();
2009-11-24 16:32:02 +00:00
$forms [] = array (
'id' => $this -> getElementId (),
//'url' => e_SELF,
//'query' => 'self', or custom GET query, self is default
'tabs' => false , // TODO - NOT IMPLEMENTED YET - enable tabs (only if fieldset count is > 1)
'fieldsets' => array (
'settings' => array (
2013-06-07 12:01:23 +03:00
'tabs' => $controller -> getPrefTabs (), //used within a single form.
2009-11-24 16:32:02 +00:00
'legend' => $legend ,
'fields' => $controller -> getPrefs (), //see e_admin_ui::$prefs
'after_submit_options' => false ,
'after_submit_default' => false , // or true for default redirect options
2009-12-23 15:12:13 +00:00
'triggers' => array ( 'save' => array ( LAN_SAVE , 'update' )), // standard create/update-cancel triggers
2009-11-24 16:32:02 +00:00
)
2009-12-23 15:12:13 +00:00
)
2009-11-24 16:32:02 +00:00
);
$models [] = $controller -> getConfig ();
2009-12-23 15:12:13 +00:00
2015-06-05 12:25:32 -07:00
// print_a($forms);
2009-11-24 16:32:02 +00:00
return $this -> renderCreateForm ( $forms , $models , e_AJAX_REQUEST );
}
2009-12-23 15:12:13 +00:00
2013-02-27 03:58:19 -08:00
2019-03-03 12:33:20 -08:00
/**
* Integrate e_addon data into the list model .
* @ param e_tree_model $tree
* @ param array $fields
* @ param string $pid
* @ return null
*/
private function setAdminAddonModel ( e_tree_model $tree , $fields , $pid )
{
$event = $this -> getController () -> getEventName ();
$arr = array ();
2013-02-25 11:35:19 -08:00
2019-03-03 12:33:20 -08:00
/** @var e_tree_model $model */
foreach ( $tree -> getTree () as $model )
{
foreach ( $fields as $fld )
{
if ( strpos ( $fld , 'x_' ) !== 0 )
{
continue ;
}
2020-12-23 16:01:20 -08:00
list ( $prefix , $plug , $field ) = explode ( '_' , $fld , 3 );
2019-03-03 12:33:20 -08:00
if ( $prefix !== 'x' || empty ( $field ) || empty ( $plug ))
{
continue ;
}
$id = $model -> get ( $pid );
if ( ! empty ( $id ))
{
$arr [ $plug ][ $field ][ $id ] = $model ;
}
}
}
foreach ( $arr as $plug => $field )
{
if ( $obj = e107 :: getAddon ( $plug , 'e_admin' ))
{
foreach ( $field as $fld => $var )
{
2020-12-23 16:01:20 -08:00
$ids = implode ( ',' , array_keys ( $var ));
2019-03-03 12:33:20 -08:00
2019-03-12 11:16:43 -07:00
$value = ( array ) e107 :: callMethod ( $obj , 'load' , $event , $ids );
// $value = (array) $obj->load($event, $ids);
2019-03-03 12:33:20 -08:00
foreach ( $var as $id => $model )
{
2020-12-23 16:01:20 -08:00
$model -> set ( 'x_' . $plug . '_' . $fld , varset ( $value [ $id ][ $fld ], null ));
2019-03-03 12:33:20 -08:00
}
}
}
}
}
2017-04-03 20:20:38 -07:00
2009-11-24 16:32:02 +00:00
/**
* Create list view
* Search for the following GET variables :
* - from : integer , current page
2009-12-23 15:12:13 +00:00
*
2009-11-24 16:32:02 +00:00
* @ return string
*/
2017-04-03 20:20:38 -07:00
public function getList ( $ajax = false , $view = 'default' )
2009-11-24 16:32:02 +00:00
{
$tp = e107 :: getParser ();
2017-09-22 18:12:47 -07:00
$this -> _list_view = $view ;
2009-11-24 16:32:02 +00:00
$controller = $this -> getController ();
$request = $controller -> getRequest ();
$id = $this -> getElementId ();
2019-03-03 12:33:20 -08:00
$pid = $controller -> getPrimaryName ();
2020-12-23 16:01:20 -08:00
$options = array ();
$tree = array ();
2017-12-23 11:54:25 -08:00
$tree [ $id ] = $controller -> getTreeModel ();
2017-12-18 14:07:50 -08:00
2017-12-23 11:54:25 -08:00
2019-03-03 12:33:20 -08:00
2020-12-23 16:01:20 -08:00
if ( $view === 'default' && deftrue ( 'e_DEBUG_TREESORT' ))
2017-12-18 14:07:50 -08:00
{
2017-12-23 11:54:25 -08:00
$controller -> getTreeModelSorted ();
2017-12-18 14:07:50 -08:00
}
2010-11-04 23:27:47 +00:00
// if going through confirm screen - no JS confirm
$controller -> setFieldAttr ( 'options' , 'noConfirm' , $controller -> deleteConfirmScreen );
2017-02-05 15:49:03 -08:00
2015-06-06 02:33:23 -07:00
$fields = $controller -> getFields ();
2019-03-03 12:33:20 -08:00
$this -> setAdminAddonModel ( $tree [ $id ], array_keys ( $fields ), $pid );
2015-06-06 14:25:40 -07:00
// checks dispatcher acess/perms for create/edit/delete access in list mode.
2015-06-06 02:33:23 -07:00
$mode = $controller -> getMode ();
2020-12-23 16:01:20 -08:00
$deleteRoute = $mode . '/delete' ;
$editRoute = $mode . '/edit' ;
$createRoute = $mode . '/create' ;
2015-06-06 02:33:23 -07:00
2020-03-11 17:04:51 -07:00
if ( ! $controller -> getDispatcher () -> hasRouteAccess ( $createRoute )) // disable the batchCopy option.
2015-06-06 02:33:23 -07:00
{
$controller -> setBatchCopy ( false );
}
2020-03-11 17:04:51 -07:00
if ( ! $controller -> getDispatcher () -> hasRouteAccess ( $deleteRoute )) // disable the delete button and batch delete.
2015-06-06 02:33:23 -07:00
{
$fields [ 'options' ][ 'readParms' ][ 'deleteClass' ] = e_UC_NOBODY ;
$controller -> setBatchDelete ( false );
}
2020-03-11 17:04:51 -07:00
if ( ! $controller -> getDispatcher () -> hasRouteAccess ( $editRoute ))
2015-06-06 02:33:23 -07:00
{
$fields [ 'options' ][ 'readParms' ][ 'editClass' ] = e_UC_NOBODY ; // display the edit button.
foreach ( $options [ $id ][ 'fields' ] as $k => $v ) // disable inline editing.
{
$fields [ $k ][ 'inline' ] = false ;
}
}
2016-02-03 16:54:40 +01:00
if ( ! $controller -> getSortField ())
{
$fields [ 'options' ][ 'sort' ] = false ;
}
2017-03-28 15:16:27 -07:00
if ( $treefld = $controller -> getTreePrefix ())
{
$fields [ $treefld ][ 'type' ] = 'method' ;
$fields [ $treefld ][ 'method' ] = 'treePrefix' ; /* @see e_admin_form_ui::treePrefix(); */
$tr = $controller -> getTreeModel () -> toArray ();
foreach ( $tr as $row )
{
e107 :: getDebug () -> log ( $row [ $treefld ] . ' > ' . $row [ '_treesort' ]);
}
}
2015-06-06 02:33:23 -07:00
// ------------------------------------------
2017-01-27 18:02:57 -08:00
$coreBatchOptions = array (
'delete' => $controller -> getBatchDelete (),
'copy' => $controller -> getBatchCopy (),
'url' => $controller -> getBatchLink (),
'featurebox' => $controller -> getBatchFeaturebox (),
2017-04-02 11:32:32 -07:00
'export' => $controller -> getBatchExport (),
2017-01-27 18:02:57 -08:00
);
2015-06-06 02:33:23 -07:00
2009-11-24 16:32:02 +00:00
$options [ $id ] = array (
2017-04-04 09:53:48 -07:00
'id' => $this -> getElementId (), // unique string used for building element ids, REQUIRED
2019-03-03 12:33:20 -08:00
'pid' => $pid , // primary field name, REQUIRED
2017-04-04 09:53:48 -07:00
'query' => $controller -> getFormQuery (), // work around - see form in newspost.php (submitted news)
'head_query' => $request -> buildQueryString ( 'field=[FIELD]&asc=[ASC]&from=[FROM]' , false ), // without field, asc and from vars, REQUIRED
'np_query' => $request -> buildQueryString ( array (), false , 'from' ), // without from var, REQUIRED for next/prev functionality
'legend' => $controller -> getPluginTitle (), // hidden by default
'form_pre' => ! $ajax ? $this -> renderFilter ( $tp -> post_toForm ( array ( $controller -> getQuery ( 'searchquery' ), $controller -> getQuery ( 'filter_options' ))), $controller -> getMode () . '/' . $controller -> getAction ()) : '' , // needs to be visible when a search returns nothing
'form_post' => '' , // markup to be added after closing form element
'fields' => $fields , // see e_admin_ui::$fields
'fieldpref' => $controller -> getFieldPref (), // see e_admin_ui::$fieldpref
'table_pre' => '' , // markup to be added before opening table element
2015-02-06 00:16:01 -08:00
// 'table_post' => !$tree[$id]->isEmpty() ? $this->renderBatch($controller->getBatchDelete(),$controller->getBatchCopy(),$controller->getBatchLink(),$controller->getBatchFeaturebox()) : '',
2017-01-27 18:02:57 -08:00
2017-04-04 09:53:48 -07:00
'table_post' => $this -> renderBatch ( $coreBatchOptions , $controller -> getBatchOptions ()),
'fieldset_pre' => '' , // markup to be added before opening fieldset element
2009-11-24 16:32:02 +00:00
'fieldset_post' => '' , // markup to be added after closing fieldset element
2017-04-04 09:53:48 -07:00
'grid' => $controller -> getGrid (),
'perPage' => $controller -> getPerPage (), // if 0 - no next/prev navigation
'from' => $controller -> getQuery ( 'from' , 0 ), // current page, default 0
'field' => $controller -> getQuery ( 'field' ), //current order field name, default - primary field
'asc' => $controller -> getQuery ( 'asc' , 'desc' ), //current 'order by' rule, default 'asc'
2009-11-24 16:32:02 +00:00
);
2015-06-05 22:00:25 -07:00
2017-04-04 09:53:48 -07:00
2017-04-03 20:20:38 -07:00
if ( $view === 'grid' )
{
return $this -> renderGridForm ( $options , $tree , $ajax );
}
2015-06-05 22:00:25 -07:00
2009-11-24 16:32:02 +00:00
return $this -> renderListForm ( $options , $tree , $ajax );
}
2011-05-18 13:41:19 +00:00
2015-06-05 22:00:25 -07:00
2010-11-04 23:27:47 +00:00
public function getConfirmDelete ( $ids , $ajax = false )
{
$controller = $this -> getController ();
$request = $controller -> getRequest ();
$fieldsets = array ();
$forms = array ();
$id_array = explode ( ',' , $ids );
$delcount = count ( $id_array );
2012-10-31 21:54:55 +00:00
2013-02-27 00:44:58 -08:00
if ( ! empty ( $controller -> deleteConfirmMessage ))
{
2020-12-23 16:01:20 -08:00
e107 :: getMessage () -> addWarning ( str_replace ( '[x]' , '<b>' . $delcount . '</b>' , $controller -> deleteConfirmMessage ));
2013-02-27 00:44:58 -08:00
}
2012-10-31 21:54:55 +00:00
else
2013-02-27 00:44:58 -08:00
{
2020-12-23 16:01:20 -08:00
e107 :: getMessage () -> addWarning ( str_replace ( '[x]' , '<b>' . $delcount . '</b>' , LAN_UI_DELETE_WARNING ));
2013-02-27 00:44:58 -08:00
}
2010-11-04 23:27:47 +00:00
$fieldsets [ 'confirm' ] = array (
'fieldset_pre' => '' , // markup to be added before opening fieldset element
'fieldset_post' => '' , // markup to be added after closing fieldset element
'table_head' => '' , // markup between <thead> tag
// Colgroup Example: array(0 => array('class' => 'label', 'style' => 'text-align: left'), 1 => array('class' => 'control', 'style' => 'text-align: left'));
'table_colgroup' => '' , // array to be used for creating markup between <colgroup> tag (<col> list)
'table_pre' => '' , // markup to be added before opening table element
'table_post' => '' , // markup to be added after closing table element
'table_rows' => '' , // rows array (<td> tags)
2011-05-18 13:41:19 +00:00
'table_body' => '' , // string body - used only if rows empty
2010-11-04 23:27:47 +00:00
'pre_triggers' => '' ,
2018-07-16 12:39:32 -07:00
'triggers' => array ( 'hidden' => $this -> hidden ( 'etrigger_delete[' . $ids . ']' , $ids ) . $this -> token (), 'delete_confirm' => array ( LAN_CONFDELETE , 'confirm' , $ids ), 'cancel' => array ( LAN_CANCEL , 'cancel' )),
2010-11-04 23:27:47 +00:00
);
if ( $delcount > 1 )
{
$fieldsets [ 'confirm' ][ 'triggers' ][ 'hidden' ] = $this -> hidden ( 'etrigger_batch' , 'delete' );
}
2011-05-18 13:41:19 +00:00
2018-09-10 10:42:54 -07:00
$id = null ;
2010-11-04 23:27:47 +00:00
$forms [ $id ] = array (
'id' => $this -> getElementId (), // unique string used for building element ids, REQUIRED
2017-02-09 10:19:55 -08:00
'url' => e_REQUEST_SELF , // default
2010-11-04 23:27:47 +00:00
'query' => $request -> buildQueryString ( array (), true , 'ajax_used' ), // - ajax_used is now removed from QUERY_STRING - class2
'legend' => $controller -> addTitle ( LAN_UI_DELETE_LABEL ), // hidden by default
'form_pre' => '' , // markup to be added before opening form element
'form_post' => '' , // markup to be added after closing form element
'header' => '' , // markup to be added after opening form element
'footer' => '' , // markup to be added before closing form element
'fieldsets' => $fieldsets ,
);
return $this -> renderForm ( $forms , $ajax );
}
2009-12-23 15:12:13 +00:00
2017-04-05 12:42:42 -07:00
2017-04-13 08:54:59 -07:00
/**
* Render pagination
* @ return string
*/
2017-04-05 12:42:42 -07:00
public function renderPagination ()
{
2017-09-22 18:12:47 -07:00
if ( $this -> _list_view === 'grid' && $this -> getController () -> getGrid ( 'carousel' ) === true )
2017-04-05 12:42:42 -07:00
{
return ' < div class = " btn-group " >
2018-01-10 15:11:12 -08:00
< a id = " admin-ui-carousel-prev " class = " btn btn-default btn-secondary " href = " #admin-ui-carousel " data - slide = " prev " >< i class = " fa fa-backward " ></ i ></ a >
< a id = " admin-ui-carousel-index " class = " btn btn-default btn-secondary " > 1 </ a >
< a id = " admin-ui-carousel-next " class = " btn btn-default btn-secondary " href = " #admin-ui-carousel " data - slide = " next " >< i class = " fa fa-forward " ></ i ></ a >
2017-04-13 08:54:59 -07:00
</ div > ' ;
2017-04-05 12:42:42 -07:00
}
2017-04-13 08:54:59 -07:00
$tree = $this -> getController () -> getTreeModel ();
$totalRecords = $tree -> getTotal ();
$perPage = $this -> getController () -> getPerPage ();
$fromPage = $this -> getController () -> getQuery ( 'from' , 0 );
$vars = $this -> getController () -> getQuery ();
$vars [ 'from' ] = '[FROM]' ;
2018-05-04 17:57:43 -07:00
$paginate = http_build_query ( $vars , null , '&' );
2017-04-13 08:54:59 -07:00
2021-01-25 09:35:08 -08:00
e107 :: js ( 'footer-inline' , "
\ $ ( '#admin-ui-list-filter a.nextprev-item' ) . on ( 'click' , function () {
\ $ ( '#admin-ui-list-filter .indicator' ) . show ();
});
" );
2017-04-13 08:54:59 -07:00
return $this -> pagination ( e_REQUEST_SELF . '?' . $paginate , $totalRecords , $fromPage , $perPage , array ( 'template' => 'basic' ));
2017-04-05 12:42:42 -07:00
}
2020-12-23 16:01:20 -08:00
public function renderFilter ( $current_query = array (), $location = '' , $input_options = array ())
2009-11-24 16:32:02 +00:00
{
2020-12-23 16:01:20 -08:00
if ( ! $input_options )
{
$input_options = array ( 'size' => 20 );
}
2009-11-24 16:32:02 +00:00
if ( ! $location )
{
$location = 'main/list' ; //default location
}
2009-12-23 15:12:13 +00:00
$l = e107 :: getParser () -> post_toForm ( explode ( '/' , $location ));
2009-11-24 16:32:02 +00:00
if ( ! is_array ( $input_options ))
{
parse_str ( $input_options , $input_options );
}
$input_options [ 'id' ] = false ;
2019-04-09 16:52:29 -07:00
$input_options [ 'class' ] = 'tbox input-text filter input-xlarge ' ;
2010-10-30 15:34:48 +00:00
$controller = $this -> getController ();
2020-08-14 10:20:09 -07:00
$filter_pre = vartrue ( $controller -> preFilterMarkup );
$filter_post = vartrue ( $controller -> postFilterMarkup );
2012-01-17 16:57:46 +00:00
$filter_preserve_var = array ();
// method requires controller - stanalone advanced usage not possible
if ( $this -> getController ())
{
$get = $this -> getController () -> getQuery ();
foreach ( $get as $key => $value )
{
2017-01-29 18:43:52 -08:00
if ( $key === 'searchquery' || $key === 'filter_options' || $key === 'etrigger_filter' )
2016-09-20 13:53:37 +02:00
{
continue ;
}
// Reset pager after filtering.
2017-01-29 18:43:52 -08:00
if ( $key === 'from' )
2016-09-20 13:53:37 +02:00
{
continue ;
}
2020-12-23 16:01:20 -08:00
$key = preg_replace ( '/[\W]/' , '' , $key );
2012-01-17 16:57:46 +00:00
$filter_preserve_var [] = $this -> hidden ( $key , rawurlencode ( $value ));
}
}
else
{
$filter_preserve_var [] = $this -> hidden ( 'mode' , $l [ 0 ]);
$filter_preserve_var [] = $this -> hidden ( 'action' , $l [ 1 ]);
}
2017-02-06 11:18:36 -08:00
// $tree = $this->getTree();
// $total = $this->getTotal();
2017-09-22 14:55:44 -07:00
$grid = $this -> getController () -> getGrid ();
2017-09-22 18:12:47 -07:00
2017-09-22 14:55:44 -07:00
$gridToggle = '' ;
2017-09-22 18:12:47 -07:00
if ( ! empty ( $grid ) && varset ( $grid [ 'toggleButton' ]) !== false )
2017-09-22 14:55:44 -07:00
{
$gridAction = $this -> getController () -> getAction () === 'grid' ? 'list' : 'grid' ;
$gridQuery = ( array ) $_GET ;
$gridQuery [ 'action' ] = $gridAction ;
2020-12-23 16:01:20 -08:00
$toggleUrl = e_REQUEST_SELF . '?' . http_build_query ( $gridQuery , null , '&' );
2017-09-22 14:55:44 -07:00
$gridIcon = ( $gridAction === 'grid' ) ? ADMIN_GRID_ICON : ADMIN_LIST_ICON ;
$gridTitle = ( $gridAction === 'grid' ) ? LAN_UI_VIEW_GRID_LABEL : LAN_UI_VIEW_LIST_LABEL ;
2020-12-23 16:01:20 -08:00
$gridToggle = " <a class='btn btn-default' href=' " . $toggleUrl . " ' title= \" " . $gridTitle . '">' . $gridIcon . '</a>' ;
2017-09-22 14:55:44 -07:00
}
2017-02-06 11:18:36 -08:00
2017-11-17 14:57:52 -08:00
// <!--<i class='fa fa-search searchquery form-control-feedback form-control-feedback-left'></i>-->
2017-02-06 11:18:36 -08:00
2009-11-24 16:32:02 +00:00
$text = "
2017-02-09 10:19:55 -08:00
< form method = 'get' action = '".e_REQUEST_SELF."' >
2015-07-14 10:46:24 -07:00
< fieldset id = 'admin-ui-list-filter' class = 'e-filter' >
2020-12-23 16:01:20 -08:00
< legend class = 'e-hideme' > " .LAN_LABEL_LABEL_SELECTED. '</legend>
' . $filter_pre . "
2015-07-14 11:45:34 -07:00
< div class = 'row-fluid' >
2015-07-14 10:46:24 -07:00
< div class = 'left form-inline span8 col-md-8' >
2017-11-17 14:57:52 -08:00
< span id = 'admin-ui-list-search' class = 'form-group has-feedback has-feedback-left' >
2020-12-23 16:01:20 -08:00
" . $this->text ('searchquery', $current_query[0] , 50, $input_options ). '
2017-07-05 14:29:33 -07:00
</ span >
2020-12-23 16:01:20 -08:00
' .$this->select_open(' filter_options ', array(' class ' => ' form - control e - tip tbox select filter ', ' id ' => false, ' title ' =>LAN_FILTER)). '
' .$this->option(LAN_FILTER_LABEL_DISPLAYALL, ' '). '
' .$this->option(LAN_FILTER_LABEL_CLEAR, ' ___reset___ '). '
' .$this->renderBatchFilter(' filter ', $current_query[1]). '
' . $this -> select_close () . "
2013-11-29 21:22:21 -08:00
< div class = 'e-autocomplete' ></ div >
2020-12-23 16:01:20 -08:00
" .implode( " \n " , $filter_preserve_var ). '
2021-01-24 07:15:46 -08:00
' .$this->admin_button(' etrigger_filter ', ' etrigger_filter ', ' filter e - hide - if - js ', ADMIN_FILTER_ICON, array(' id ' => false, ' title ' =>LAN_FILTER, ' loading ' => false)). '
2017-09-22 14:55:44 -07:00
2021-01-24 06:47:04 -08:00
' . $this -> renderPagination () . "
" . $gridToggle . "
2013-11-29 21:22:21 -08:00
< span class = 'indicator' style = 'display: none;' >
2021-01-24 06:47:04 -08:00
< i class = 'fa fa-spin fa-spinner fa-fw' ></ i >
2013-11-29 21:22:21 -08:00
</ span >
</ div >
2015-07-14 10:46:24 -07:00
< div id = 'admin-ui-list-db-language' class = 'span4 col-md-4 text-right' > " ;
2013-11-29 21:22:21 -08:00
2017-09-22 14:55:44 -07:00
2013-11-29 21:22:21 -08:00
// Let Admin know which language table is being saved to. (avoid default table overwrites)
2015-06-04 17:01:27 -07:00
$text .= $this -> renderLanguageTableInfo ();
2013-11-29 21:22:21 -08:00
2020-12-23 16:01:20 -08:00
$text .= '
2013-11-29 21:22:21 -08:00
</ div >
2009-11-24 16:32:02 +00:00
</ div >
2020-12-23 16:01:20 -08:00
' .$filter_post. '
2009-11-24 16:32:02 +00:00
</ fieldset >
</ form >
2020-12-23 16:01:20 -08:00
' ;
2009-11-24 16:32:02 +00:00
2012-05-15 09:55:27 +00:00
e107 :: js ( 'core' , 'scriptaculous/controls.js' , 'prototype' , 2 );
2009-11-24 16:32:02 +00:00
//TODO - external JS
2012-05-16 06:05:39 +00:00
e107 :: js ( 'footer-inline' , "
2009-11-24 16:32:02 +00:00
//autocomplete fields
2009-12-23 15:12:13 +00:00
\ $\ $ ( 'input[name=searchquery]' ) . each ( function ( el , cnt ) {
2009-11-24 16:32:02 +00:00
if ( ! cnt ) el . activate ();
else return ;
2020-12-23 16:01:20 -08:00
new Ajax . Autocompleter ( el , el . next ( 'div.e-autocomplete' ), '".e_REQUEST_SELF. ' ? mode = ' .$l[0]."&action=filter' , {
2009-11-24 16:32:02 +00:00
paramName : 'searchquery' ,
minChars : 2 ,
frequency : 0.5 ,
2009-12-23 15:12:13 +00:00
afterUpdateElement : function ( txt , li ) {
2009-11-24 16:32:02 +00:00
var cfrm = el . up ( 'form' ), cont = cfrm . next ( '.e-container' );
if ( ! cont ) {
return ;
2009-12-23 15:12:13 +00:00
}
2009-11-24 16:32:02 +00:00
cfrm . submitForm ( cont );
},
indicator : el . next ( 'span.indicator' ),
parameters : 'ajax_used=1'
});
var sel = el . next ( 'select.filter' );
if ( sel ) {
2009-12-23 15:12:13 +00:00
sel . observe ( 'change' , function ( e ) {
2009-11-24 16:32:02 +00:00
var cfrm = e . element () . up ( 'form' ), cont = cfrm . next ( '.e-container' );
if ( cfrm && cont && e . element () . value != '___reset___' ) {
e . stop ();
cfrm . submitForm ( cont );
return ;
}
e107Helper . selectAutoSubmit ( e . element ());
});
}
});
2012-05-16 06:05:39 +00:00
" ,'prototype');
2013-01-08 11:21:29 +02:00
// TODO implement ajax queue
2017-07-21 09:13:54 +02:00
// FIXME
// dirty way to register events after ajax update - DO IT RIGHT - see all.jquery, create object and use handler,
// re-register them global after ajax update (context)... use behaviors and call e107.attachBehaviors();
2013-01-08 11:21:29 +02:00
e107 :: js ( 'footer-inline' , "
var filterRunning = false , request ;
var applyAfterAjax = function ( context ) {
\ $ ( '.e-expandit' , context ) . click ( function () {
var href = ( \ $ ( this ) . is ( 'a' )) ? \ $ ( this ) . attr ( 'href' ) : '' ;
if ( href == '' && \ $ ( this ) . attr ( 'data-target' ))
{
href = '#' + \ $ ( this ) . attr ( 'data-target' );
}
if ( href === '#' || href == '' )
{
idt = \ $ ( this ) . nextAll ( 'div' );
\ $ ( idt ) . toggle ( 'slow' );
return true ;
}
//var id = $(this).attr('href');
\ $ ( href ) . toggle ( 'slow' );
return false ;
});
\ $ ( 'input.toggle-all' , context ) . click ( function ( evt ) {
var selector = 'input[type=\"checkbox\"].checkbox' ;
if ( \ $ ( this ) . val () . startsWith ( 'jstarget:' )) {
selector = 'input[type=\"checkbox\"][name^=\"' + \ $ ( this ) . val () . split ( / jstarget\ :/ )[ 1 ] + '\"]' ;
}
if ( \ $ ( this ) . is ( ':checked' )){
\ $ ( selector ) . attr ( 'checked' , 'checked' );
}
else {
\ $ ( selector ) . removeAttr ( 'checked' );
}
});
};
var searchQueryHandler = function ( e ) {
2021-01-24 07:15:46 -08:00
2013-01-08 11:21:29 +02:00
var el = \ $ ( this ), frm = el . parents ( 'form' ), cont = frm . nextAll ( '.e-container' );
if ( cont . length < 1 || frm . length < 1 || ( el . val () . length > 0 && el . val () . length < 3 )) return ;
e . preventDefault ();
if ( filterRunning && request ) request . abort ();
filterRunning = true ;
2021-01-24 07:15:46 -08:00
\ $ ( '#admin-ui-list-filter .indicator' ) . show ();
2013-01-08 11:21:29 +02:00
cont . css ({ opacity : 0.5 });
request = \ $ . get ( frm . attr ( 'action' ), frm . serialize (), function ( data ){
filterRunning = false ;
setTimeout ( function () {
if ( filterRunning ) {
//cont.css({ opacity: 1 });
return ;
}
cont . html ( data ) . css ({ opacity : 1 });
2021-01-24 07:15:46 -08:00
\ $ ( '#admin-ui-list-filter .indicator' ) . hide ();
2017-07-21 09:13:54 +02:00
// TODO remove applyAfterAjax() and use behaviors!
2013-01-08 11:21:29 +02:00
applyAfterAjax ( cont );
2017-07-21 09:13:54 +02:00
// Attach behaviors to the newly loaded contents.
e107 . attachBehaviors ();
2013-01-08 11:21:29 +02:00
}, 700 );
}, 'html' )
. error ( function () {
filterRunning = false ;
cont . css ({ opacity : 1 });
});
};
2013-03-07 04:28:03 -08:00
\ $ ( '#searchquery' ) . on ( 'keyup' , searchQueryHandler );
2021-01-24 07:15:46 -08:00
\ $ ( '#filter-options' ) . on ( 'change' , function () {
\ $ ( '#admin-ui-list-filter .indicator' ) . show ();
});
\ $ ( '#etrigger-filter' ) . on ( 'click' , function () {
\ $ ( '#admin-ui-list-filter .indicator' ) . show ();
});
2013-01-08 11:21:29 +02:00
" , 'jquery');
2009-12-23 15:12:13 +00:00
return $text ;
2009-11-24 16:32:02 +00:00
}
2009-12-23 15:12:13 +00:00
2015-06-04 17:01:27 -07:00
private function renderLanguageTableInfo ()
{
2020-02-22 10:03:41 -08:00
if ( ! e107 :: getConfig () -> get ( 'multilanguage' ))
2015-06-04 17:01:27 -07:00
{
2020-02-22 10:03:41 -08:00
return null ;
}
2015-06-04 17:01:27 -07:00
2020-02-22 10:03:41 -08:00
$curTable = $this -> getController () -> getTableName ();
$sitelanguage = e107 :: getConfig () -> get ( 'sitelanguage' );
2015-06-04 17:01:27 -07:00
2020-02-22 10:03:41 -08:00
$val = e107 :: getDb () -> hasLanguage ( $curTable , true );
2015-06-05 13:23:08 -07:00
2020-02-22 10:03:41 -08:00
if ( $val === false )
{
return null ;
2015-06-04 17:01:27 -07:00
}
2020-02-22 10:03:41 -08:00
if ( $curTable != e107 :: getDb () -> hasLanguage ( $curTable ))
{
$lang = e107 :: getDb () -> mySQLlanguage ;
}
else
{
$lang = $sitelanguage ;
}
$def = deftrue ( 'LAN_UI_USING_DATABASE_TABLE' , 'Using [x] database table' );
$diz = e107 :: getParser () -> lanVars ( $def , $lang ); // "Using ".$lang." database table";
2020-12-23 16:01:20 -08:00
$class = ( $sitelanguage == $lang ) ? 'default' : '' ;
2020-02-22 10:03:41 -08:00
2020-12-23 16:01:20 -08:00
$text = " <span class='adminui-language-table-info " . $class . " e-tip' title= \" " . $diz . '">' ;
2020-02-22 10:03:41 -08:00
$text .= e107 :: getParser () -> toGlyph ( 'fa-hdd-o' ); // '<i class="icon-hdd"></i> ';
2020-12-23 16:01:20 -08:00
$text .= e107 :: getLanguage () -> toNative ( $lang ) . '</span>' ;
2020-02-22 10:03:41 -08:00
return $text ;
2015-06-04 17:01:27 -07:00
}
2018-02-09 04:37:48 -06:00
// FIXME - use e_form::batchoptions(), nice way of building batch dropdown - news administration show_batch_options()
2017-01-27 18:02:57 -08:00
/**
* @ param array $options array of flags for copy , delete , url , featurebox , batch
* @ param array $customBatchOptions
* @ return string
*/
2020-12-23 16:01:20 -08:00
public function renderBatch ( $options , $customBatchOptions = array ())
2009-12-23 15:12:13 +00:00
{
2017-01-27 18:02:57 -08:00
2009-11-24 16:32:02 +00:00
$fields = $this -> getController () -> getFields ();
2017-01-27 18:02:57 -08:00
2009-11-24 16:32:02 +00:00
if ( ! varset ( $fields [ 'checkboxes' ]))
{
2012-04-19 03:53:58 +00:00
$mes = e107 :: getMessage ();
$mes -> add ( " Cannot display Batch drop-down as 'checkboxes' was not found in \$ fields array. " , E_MESSAGE_DEBUG );
2009-11-24 16:32:02 +00:00
return '' ;
2009-12-23 15:12:13 +00:00
}
2013-04-27 13:33:42 +03:00
// FIX - don't show FB option if plugin not installed
if ( ! e107 :: isInstalled ( 'featurebox' ))
{
2017-01-27 18:02:57 -08:00
$options [ 'featurebox' ] = false ;
2013-04-27 13:33:42 +03:00
}
2010-11-04 23:27:47 +00:00
// TODO - core ui-batch-option class!!! REMOVE INLINE STYLE!
2013-02-20 22:58:18 -08:00
// XXX Quick Fix for styling - correct.
2009-11-24 16:32:02 +00:00
$text = "
2015-07-14 10:46:24 -07:00
< div id = 'admin-ui-list-batch' class = 'navbar navbar-inner left' >
2015-07-13 19:49:25 -07:00
< div class = 'span6 col-md-6' > " ;
2016-12-21 11:01:25 -08:00
$selectStart = " <div class='form-inline input-inline'>
2017-04-02 11:32:32 -07:00
" .ADMIN_CHILD_ICON. "
< div class = 'input-group input-append' >
2020-12-23 16:01:20 -08:00
" . $this->select_open ('etrigger_batch', array('class' => 'tbox form-control input-large select batch e-autosubmit reset', 'id' => false)). '
' .$this->option(LAN_BATCH_LABEL_SELECTED, ' ' );
2016-12-21 11:01:25 -08:00
$selectOpt = '' ;
if ( ! $this -> getController () -> getTreeModel () -> isEmpty ())
{
2017-01-27 18:02:57 -08:00
$selectOpt .= ! empty ( $options [ 'copy' ]) ? $this -> option ( LAN_COPY , 'copy' , false , array ( 'class' => 'ui-batch-option class' , 'other' => 'style="padding-left: 15px"' )) : '' ;
$selectOpt .= ! empty ( $options [ 'delete' ]) ? $this -> option ( LAN_DELETE , 'delete' , false , array ( 'class' => 'ui-batch-option class' , 'other' => 'style="padding-left: 15px"' )) : '' ;
$selectOpt .= ! empty ( $options [ 'export' ]) ? $this -> option ( LAN_UI_BATCH_EXPORT , 'export' , false , array ( 'class' => 'ui-batch-option class' , 'other' => 'style="padding-left: 15px"' )) : '' ;
$selectOpt .= ! empty ( $options [ 'url' ]) ? $this -> option ( LAN_UI_BATCH_CREATELINK , 'url' , false , array ( 'class' => 'ui-batch-option class' , 'other' => 'style="padding-left: 15px"' )) : '' ;
$selectOpt .= ! empty ( $options [ 'featurebox' ]) ? $this -> option ( LAN_PLUGIN_FEATUREBOX_BATCH , 'featurebox' , false , array ( 'class' => 'ui-batch-option class' , 'other' => 'style="padding-left: 15px"' )) : '' ;
2015-07-06 14:03:08 -07:00
2017-04-02 11:32:32 -07:00
// if(!empty($parms['sef'])
2015-07-06 14:03:08 -07:00
if ( ! empty ( $customBatchOptions ))
{
foreach ( $customBatchOptions as $key => $val )
{
2016-11-05 17:09:39 -07:00
if ( is_array ( $val ))
{
2016-12-21 11:01:25 -08:00
$selectOpt .= $this -> optgroup_open ( $key );
2016-11-05 17:09:39 -07:00
foreach ( $val as $k => $v )
{
2016-12-21 11:01:25 -08:00
$selectOpt .= $this -> option ( $v , $k , false , array ( 'class' => 'ui-batch-option class' , 'other' => 'style="padding-left: 15px"' ));
2016-11-05 17:09:39 -07:00
}
2016-12-21 11:01:25 -08:00
$selectOpt .= $this -> optgroup_close ();
2016-11-05 17:09:39 -07:00
}
else
{
2016-12-21 11:01:25 -08:00
$selectOpt .= $this -> option ( $val , $key , false , array ( 'class' => 'ui-batch-option class' , 'other' => 'style="padding-left: 15px"' ));
2016-11-05 17:09:39 -07:00
}
2015-07-06 14:03:08 -07:00
}
}
2020-12-23 16:01:20 -08:00
$selectOpt .= $this -> renderBatchFilter ();
2016-12-21 11:01:25 -08:00
if ( ! empty ( $selectOpt ))
{
$text .= $selectStart ;
$text .= $selectOpt ;
$text .= $this -> select_close ();
$text .= " <div class='input-group-btn input-append'>
2020-12-23 16:01:20 -08:00
" . $this->admin_button ('e__execute_batch', 'e__execute_batch', 'batch e-hide-if-js', LAN_GO, array('id' => false)). '
</ div > ' ;
$text .= '</div></div>' ;
2016-12-21 11:01:25 -08:00
}
2020-12-23 16:01:20 -08:00
$text .= '</div>' ;
2016-12-21 11:01:25 -08:00
2015-02-06 00:16:01 -08:00
}
$text .= "
2017-04-05 12:42:42 -07:00
2020-12-23 16:01:20 -08:00
< div id = 'admin-ui-list-total-records' class = 'span6 col-md-6 right' >< span > " .e107::getParser()->lanVars(LAN_UI_TOTAL_RECORDS,number_format( $this->getController ()->getTreeModel()->getTotal())). '</span></div>
2009-11-24 16:32:02 +00:00
</ div >
2020-12-23 16:01:20 -08:00
' ;
2017-04-05 12:42:42 -07:00
2009-11-24 16:32:02 +00:00
return $text ;
}
2009-12-23 15:12:13 +00:00
2016-04-01 19:59:51 -07:00
/**
* Render Batch and Filter Dropdown options .
* @ param string $type
* @ param string $selected
* @ return string
*/
2020-12-23 16:01:20 -08:00
public function renderBatchFilter ( $type = 'batch' , $selected = '' ) // Common function used for both batches and filters.
2009-11-24 16:32:02 +00:00
{
2010-11-04 23:27:47 +00:00
$optdiz = array ( 'batch' => LAN_BATCH_LABEL_PREFIX . ' ' , 'filter' => LAN_FILTER_LABEL_PREFIX . ' ' );
2009-11-24 16:32:02 +00:00
$table = $this -> getController () -> getTableName ();
$text = '' ;
$textsingle = '' ;
2014-01-01 17:38:46 -08:00
2009-12-23 15:12:13 +00:00
2019-06-04 12:59:39 -07:00
$searchFieldOpts = array ();
$fieldList = $this -> getController () -> getFields ();
foreach ( $fieldList as $key => $val )
2009-11-24 16:32:02 +00:00
{
2020-03-10 11:14:59 -07:00
if ( ! empty ( $val [ 'search' ]))
{
2020-12-23 16:01:20 -08:00
$searchFieldOpts [ 'searchfield__' . $key ] = $val [ 'title' ];
2020-03-10 11:14:59 -07:00
}
2019-06-04 12:59:39 -07:00
if ( empty ( $val [ $type ])) // ie. filter = false or batch = false.
2009-11-24 16:32:02 +00:00
{
continue ;
}
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
$option = array ();
$parms = vartrue ( $val [ 'writeParms' ], array ());
2020-12-23 16:01:20 -08:00
if ( is_string ( $parms ))
{
parse_str ( $parms , $parms );
}
2011-05-18 13:41:19 +00:00
2019-12-02 13:32:21 -08:00
//Basic batch support for dropdown with multiple values. (comma separated)
if ( ! empty ( $val [ 'writeParms' ][ 'multiple' ]) && $val [ 'type' ] === 'dropdown' && ! empty ( $val [ 'writeParms' ][ 'optArray' ]))
{
$val [ 'type' ] = 'comma' ;
$parms = $val [ 'writeParms' ][ 'optArray' ];
}
2020-03-10 11:14:59 -07:00
2020-03-10 11:08:22 -07:00
2009-11-24 16:32:02 +00:00
switch ( $val [ 'type' ])
{
2017-04-02 11:32:32 -07:00
case 'text' ;
if ( ! empty ( $parms [ 'sef' ]))
{
$option [ 'sefgen__' . $key . '__' . $parms [ 'sef' ]] = LAN_GENERATE ;
}
2020-12-23 16:01:20 -08:00
$searchFieldOpts [ 'searchfield__' . $key ] = $val [ 'title' ];
2019-06-04 12:59:39 -07:00
2017-04-02 11:32:32 -07:00
break ;
2018-03-05 17:15:49 -08:00
case 'number' ;
if ( $type === 'filter' )
{
$option [ $key . '___ISEMPTY_' ] = LAN_UI_FILTER_IS_EMPTY ;
}
2020-12-23 16:01:20 -08:00
$searchFieldOpts [ 'searchfield__' . $key ] = $val [ 'title' ];
2019-06-04 12:59:39 -07:00
break ;
case 'textarea' :
case 'tags' :
2020-12-23 16:01:20 -08:00
$searchFieldOpts [ 'searchfield__' . $key ] = $val [ 'title' ];
2018-03-05 17:15:49 -08:00
break ;
2010-10-30 15:34:48 +00:00
case 'bool' :
2009-11-24 16:32:02 +00:00
case 'boolean' : //TODO modify description based on $val['parm]
2020-02-20 08:53:32 -08:00
// defaults
$LAN_TRUE = LAN_ON ;
$LAN_FALSE = LAN_OFF ;
if ( varset ( $parms [ 'label' ]) === 'yesno' )
{
$LAN_TRUE = LAN_YES ;
$LAN_FALSE = LAN_NO ;
}
if ( ! empty ( $parms [ 'enabled' ]))
{
$LAN_TRUE = $parms [ 'enabled' ];
}
elseif ( ! empty ( $parms [ 'true' ]))
{
$LAN_TRUE = $parms [ 'true' ];
}
if ( ! empty ( $parms [ 'disabled' ]))
{
$LAN_FALSE = $parms [ 'disabled' ];
}
elseif ( ! empty ( $parms [ 'false' ]))
{
$LAN_FALSE = $parms [ 'false' ];
}
if ( ! empty ( $parms [ 'reverse' ])) // reverse true/false values;
2012-08-02 23:37:20 +00:00
{
2020-02-20 08:53:32 -08:00
$option [ 'bool__' . $key . '__0' ] = $LAN_TRUE ; // see newspost.php : news_allow_comments for an example.
$option [ 'bool__' . $key . '__1' ] = $LAN_FALSE ;
2012-08-02 23:37:20 +00:00
}
else
{
2020-02-20 08:53:32 -08:00
$option [ 'bool__' . $key . '__1' ] = $LAN_TRUE ;
$option [ 'bool__' . $key . '__0' ] = $LAN_FALSE ;
2012-08-02 23:37:20 +00:00
}
2017-01-29 18:43:52 -08:00
if ( $type === 'batch' )
2009-11-24 16:32:02 +00:00
{
$option [ 'boolreverse__' . $key ] = LAN_BOOL_REVERSE ;
}
break ;
2012-12-15 16:49:19 +02:00
2014-10-23 18:53:50 -07:00
case 'checkboxes' :
2012-12-15 16:49:19 +02:00
case 'comma' :
// TODO lan
2020-12-23 16:01:20 -08:00
if ( ! isset ( $parms [ '__options' ]))
{
$parms [ '__options' ] = array ();
}
if ( ! is_array ( $parms [ '__options' ]))
{
parse_str ( $parms [ '__options' ], $parms [ '__options' ]);
}
2012-12-17 16:57:24 +02:00
$opts = $parms [ '__options' ];
unset ( $parms [ '__options' ]); //remove element options if any
$options = $parms ? $parms : array ();
2020-12-23 16:01:20 -08:00
if ( empty ( $options ))
{
continue 2 ;
}
2012-12-15 16:49:19 +02:00
2012-12-17 16:57:24 +02:00
2017-01-29 18:43:52 -08:00
if ( $type === 'batch' )
2012-12-15 16:49:19 +02:00
{
2013-01-18 17:31:12 +02:00
$_option = array ();
if ( isset ( $options [ 'addAll' ]))
2012-12-17 16:57:24 +02:00
{
2020-12-23 16:01:20 -08:00
$option [ 'attach_all__' . $key ] = vartrue ( $options [ 'addAll' ], '(' . LAN_ADD_ALL . ')' );
2013-01-18 17:31:12 +02:00
unset ( $options [ 'addAll' ]);
2012-12-17 16:57:24 +02:00
}
2013-01-18 17:31:12 +02:00
if ( isset ( $options [ 'clearAll' ]))
2012-12-17 16:57:24 +02:00
{
2020-12-23 16:01:20 -08:00
$_option [ 'deattach_all__' . $key ] = vartrue ( $options [ 'clearAll' ], '(' . LAN_CLEAR_ALL . ')' );
2013-01-18 17:31:12 +02:00
unset ( $options [ 'clearAll' ]);
}
2020-12-20 11:50:10 -08:00
if ( ! empty ( $opts [ 'simple' ]))
2013-01-18 17:31:12 +02:00
{
foreach ( $options as $value )
{
2020-12-23 16:01:20 -08:00
$option [ 'attach__' . $key . '__' . $value ] = LAN_ADD . ' ' . $value ;
$_option [ 'deattach__' . $key . '__' . $value ] = LAN_REMOVE . ' ' . $value ;
2013-01-18 17:31:12 +02:00
}
}
else
{
foreach ( $options as $value => $label )
{
2020-12-23 16:01:20 -08:00
$option [ 'attach__' . $key . '__' . $value ] = LAN_ADD . ' ' . $label ;
$_option [ 'deattach__' . $key . '__' . $value ] = LAN_REMOVE . ' ' . $label ;
2013-01-18 17:31:12 +02:00
}
2012-12-17 16:57:24 +02:00
}
$option = array_merge ( $option , $_option );
unset ( $_option );
2012-12-15 16:49:19 +02:00
}
2012-12-17 16:57:24 +02:00
else
2012-12-15 16:49:19 +02:00
{
2013-01-18 17:31:12 +02:00
unset ( $options [ 'addAll' ], $options [ 'clearAll' ]);
2020-12-20 11:50:10 -08:00
if ( ! empty ( $opts [ 'simple' ]))
2012-12-17 16:57:24 +02:00
{
2013-01-18 17:31:12 +02:00
foreach ( $options as $k )
{
$option [ $key . '__' . $k ] = $k ;
}
2012-12-17 16:57:24 +02:00
}
2013-01-18 17:31:12 +02:00
else
{
foreach ( $options as $k => $name )
{
$option [ $key . '__' . $k ] = $name ;
}
}
2012-12-17 16:57:24 +02:00
}
2012-12-15 16:49:19 +02:00
break ;
2009-12-23 15:12:13 +00:00
case 'templates' :
2009-11-28 15:34:46 +00:00
case 'layouts' :
$parms [ 'raw' ] = true ;
$val [ 'writeParms' ] = $parms ;
$tmp = $this -> renderElement ( $key , '' , $val );
2013-03-03 20:54:08 -08:00
if ( is_array ( $tmp ))
{
foreach ( $tmp as $k => $name )
{
$option [ $key . '__' . $k ] = $name ;
}
2009-11-28 15:34:46 +00:00
}
break ;
2009-12-23 15:12:13 +00:00
case 'dropdown' : // use the array $parm;
2015-03-30 17:13:09 -07:00
2016-04-20 18:08:52 -07:00
2015-03-30 17:13:09 -07:00
if ( ! empty ( $parms [ 'optArray' ]))
{
$fopts = $parms ;
$parms = $fopts [ 'optArray' ];
unset ( $fopts [ 'optArray' ]);
$parms [ '__options' ] = $fopts ;
}
2020-12-23 16:01:20 -08:00
if ( ! is_array ( varset ( $parms [ '__options' ])))
{
parse_str ( $parms [ '__options' ], $parms [ '__options' ]);
}
2010-11-08 09:20:12 +00:00
$opts = $parms [ '__options' ];
2020-12-20 11:50:10 -08:00
if ( ! empty ( $opts [ 'multiple' ]) && $type === 'batch' )
2010-11-08 09:20:12 +00:00
{
// no batch support for multiple, should have some for filters soon
2020-02-10 15:38:04 -08:00
continue 2 ;
2010-11-08 09:20:12 +00:00
}
2016-04-20 18:08:52 -07:00
2009-11-24 16:32:02 +00:00
unset ( $parms [ '__options' ]); //remove element options if any
2016-04-20 18:08:52 -07:00
2009-11-24 16:32:02 +00:00
foreach ( $parms as $k => $name )
{
$option [ $key . '__' . $k ] = $name ;
}
break ;
2011-05-18 13:41:19 +00:00
2014-11-19 13:03:30 -08:00
case 'language' : // full list of
2010-11-08 09:20:12 +00:00
case 'lanlist' : // use the array $parm;
2020-12-23 16:01:20 -08:00
if ( ! is_array ( varset ( $parms [ '__options' ])))
{
parse_str ( $parms [ '__options' ], $parms [ '__options' ]);
}
2010-11-08 09:20:12 +00:00
$opts = $parms [ '__options' ];
2020-12-20 11:50:10 -08:00
if ( ! empty ( $opts [ 'multiple' ]))
2010-11-08 09:20:12 +00:00
{
// no batch support for multiple, should have some for filters soon
2020-02-10 15:38:04 -08:00
continue 2 ;
2010-11-08 09:20:12 +00:00
}
2014-11-19 13:03:30 -08:00
$options = ( $val [ 'type' ] === 'language' ) ? e107 :: getLanguage () -> getList () : e107 :: getLanguage () -> getLanSelectArray ();
2010-11-08 09:20:12 +00:00
foreach ( $options as $code => $name )
{
$option [ $key . '__' . $code ] = $name ;
}
break ;
2009-12-23 15:12:13 +00:00
2020-03-28 14:30:28 -07:00
case 'datestamp' :
$tp = e107 :: getParser ();
2017-03-19 16:42:57 +00:00
$dateFilters = array (
2020-12-23 16:01:20 -08:00
'hour' => LAN_UI_FILTER_PAST_HOUR ,
'day' => LAN_UI_FILTER_PAST_24_HOURS ,
'week' => LAN_UI_FILTER_PAST_WEEK ,
'month' => LAN_UI_FILTER_PAST_MONTH ,
'month3' => $tp -> lanVars ( LAN_UI_FILTER_PAST_XMONTHS , 3 ),
'month6' => $tp -> lanVars ( LAN_UI_FILTER_PAST_XMONTHS , 6 ),
'month9' => $tp -> lanVars ( LAN_UI_FILTER_PAST_XMONTHS , 9 ),
'year' => LAN_UI_FILTER_PAST_YEAR
2012-12-01 00:03:48 -08:00
);
2018-03-05 14:37:56 -08:00
$dateFiltersFuture = array (
2020-12-23 16:01:20 -08:00
'nhour' => LAN_UI_FILTER_NEXT_HOUR ,
'nday' => LAN_UI_FILTER_NEXT_24_HOURS ,
'nweek' => LAN_UI_FILTER_NEXT_WEEK ,
'nmonth' => LAN_UI_FILTER_NEXT_MONTH ,
'nmonth3' => $tp -> lanVars ( LAN_UI_FILTER_NEXT_XMONTHS , 3 ),
'nmonth6' => $tp -> lanVars ( LAN_UI_FILTER_NEXT_XMONTHS , 6 ),
'nmonth9' => $tp -> lanVars ( LAN_UI_FILTER_NEXT_XMONTHS , 9 ),
'nyear' => LAN_UI_FILTER_NEXT_YEAR
2018-03-05 14:37:56 -08:00
);
if ( $val [ 'filter' ] === 'future' )
{
$dateFilters = $dateFiltersFuture ;
}
if ( $val [ 'filter' ] === 'both' )
{
$dateFilters += $dateFiltersFuture ;
}
2012-12-01 00:03:48 -08:00
foreach ( $dateFilters as $k => $name )
2009-11-24 16:32:02 +00:00
{
2012-12-01 00:03:48 -08:00
$option [ 'datestamp__' . $key . '__' . $k ] = $name ;
// $option['bool__'.$key.'__0'] = LAN_NO;
// $option[$key.'__'.$k] = $name;
}
2009-11-24 16:32:02 +00:00
break ;
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
case 'userclass' :
2019-05-27 11:17:41 -07:00
$classes = e107 :: getUserClass () -> uc_required_class_list ( vartrue ( $parms [ 'classlist' ], 'public,nobody,guest,member,admin,main,classes' ));
2009-11-24 16:32:02 +00:00
foreach ( $classes as $k => $name )
{
$option [ $key . '__' . $k ] = $name ;
}
2009-12-23 15:12:13 +00:00
break ;
2012-12-15 16:49:19 +02:00
case 'userclasses' :
2019-05-27 11:17:41 -07:00
$classes = e107 :: getUserClass () -> uc_required_class_list ( vartrue ( $parms [ 'classlist' ], 'public,nobody,guest,member,admin,main,classes' ));
2012-12-15 16:49:19 +02:00
$_option = array ();
2013-02-11 10:21:01 +02:00
2017-01-29 18:43:52 -08:00
if ( $type === 'batch' )
2012-12-15 16:49:19 +02:00
{
2013-02-11 10:21:01 +02:00
foreach ( $classes as $k => $v )
{
2017-03-19 16:42:57 +00:00
$option [ 'ucadd__' . $key . '__' . $k ] = LAN_ADD . ' ' . $v ;
2020-12-23 16:01:20 -08:00
$_option [ 'ucremove__' . $key . '__' . $k ] = LAN_REMOVE . ' ' . $v ;
2013-02-11 10:21:01 +02:00
}
2020-12-23 16:01:20 -08:00
$option [ 'ucaddall__' . $key ] = '(' . LAN_ADD_ALL . ')' ;
$_option [ 'ucdelall__' . $key ] = '(' . LAN_CLEAR_ALL . ')' ;
2013-02-11 10:21:01 +02:00
$option = array_merge ( $option , $_option );
2012-12-15 16:49:19 +02:00
}
2013-02-11 10:21:01 +02:00
else
{
foreach ( $classes as $k => $v )
{
$option [ $key . '__' . $k ] = $v ;
}
}
2012-12-15 16:49:19 +02:00
unset ( $_option );
break ;
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
case 'method' :
2011-05-18 13:41:19 +00:00
$method = $key ;
2009-11-24 16:32:02 +00:00
$list = call_user_func_array ( array ( $this , $method ), array ( '' , $type , $parms ));
2011-05-18 13:41:19 +00:00
2009-11-24 16:32:02 +00:00
if ( is_array ( $list ))
{
//check for single option
if ( isset ( $list [ 'singleOption' ]))
{
$textsingle .= $list [ 'singleOption' ];
2020-02-10 15:38:04 -08:00
continue 2 ;
2009-11-24 16:32:02 +00:00
}
// non rendered options array
foreach ( $list as $k => $name )
{
$option [ $key . '__' . $k ] = $name ;
}
}
elseif ( ! empty ( $list )) //optgroup, continue
{
$text .= $list ;
2020-02-10 15:38:04 -08:00
continue 2 ;
2009-11-24 16:32:02 +00:00
}
break ;
2011-05-18 13:41:19 +00:00
case 'user' : // TODO - User Filter
2014-01-01 17:38:46 -08:00
$sql = e107 :: getDb ();
$field = $val [ 'field' ];
2020-12-23 16:01:20 -08:00
$query = 'SELECT d.' . $field . ', u.user_name FROM #' . $val [ 'table' ] . ' AS d LEFT JOIN #user AS u ON d.' . $field . ' = u.user_id GROUP BY d.' . $field . ' ORDER BY u.user_name' ;
2014-01-01 17:38:46 -08:00
$row = $sql -> retrieve ( $query , true );
foreach ( $row as $data )
{
$k = $data [ $field ];
2014-01-01 18:38:02 -08:00
if ( $k == 0 )
{
2020-12-23 16:01:20 -08:00
$option [ $key . '__' . $k ] = '(' . LAN_ANONYMOUS . ')' ;
2014-01-01 18:38:02 -08:00
}
else
{
2017-03-19 16:42:57 +00:00
$option [ $key . '__' . $k ] = vartrue ( $data [ 'user_name' ], LAN_UNKNOWN );
2014-01-01 18:38:02 -08:00
}
2014-01-01 17:38:46 -08:00
}
2011-05-07 06:22:44 +00:00
break ;
2009-11-24 16:32:02 +00:00
}
2009-12-23 15:12:13 +00:00
2019-06-04 12:59:39 -07:00
if ( ! empty ( $option ))
2009-11-24 16:32:02 +00:00
{
$text .= " \t " . $this -> optgroup_open ( $optdiz [ $type ] . defset ( $val [ 'title' ], $val [ 'title' ]), varset ( $disabled )) . " \n " ;
foreach ( $option as $okey => $oval )
{
2009-12-23 15:12:13 +00:00
$text .= $this -> option ( $oval , $okey , $selected == $okey ) . " \n " ;
2009-11-24 16:32:02 +00:00
}
2009-12-23 15:12:13 +00:00
$text .= " \t " . $this -> optgroup_close () . " \n " ;
2009-11-24 16:32:02 +00:00
}
}
2009-12-23 15:12:13 +00:00
2019-06-04 12:59:39 -07:00
if ( ! empty ( $searchFieldOpts ))
{
2020-12-23 16:01:20 -08:00
$text .= " \t " . $this -> optgroup_open ( defset ( 'LAN_UI_FILTER_SEARCH_IN_FIELD' , 'Search in Field' )) . " \n " ;
2019-06-04 12:59:39 -07:00
foreach ( $searchFieldOpts as $key => $val )
{
$text .= $this -> option ( $val , $key , $selected == $key ) . " \n " ;
}
$text .= " \t " . $this -> optgroup_close () . " \n " ;
}
2009-11-24 16:32:02 +00:00
return $textsingle . $text ;
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
}
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
public function getElementId ()
{
$controller = $this -> getController ();
2017-01-29 18:43:52 -08:00
$name = str_replace ( '_' , '-' , ( $controller -> getPluginName () === 'core' ? 'core-' . $controller -> getTableName () : 'plugin-' . $controller -> getPluginName ()));
2015-10-24 09:59:30 -07:00
return e107 :: getForm () -> name2id ( $name ); // prevent invalid ids.
2009-11-24 16:32:02 +00:00
}
2009-12-23 15:12:13 +00:00
2009-11-24 16:32:02 +00:00
/**
* @ return e_admin_ui
*/
public function getController ()
2009-12-23 15:12:13 +00:00
{
2017-05-08 18:47:51 -07:00
2009-11-24 16:32:02 +00:00
return $this -> _controller ;
}
}
2021-01-24 10:44:30 -08:00
e107 :: loadAdminIcons ();
2009-11-24 16:32:02 +00:00
/**
* TODO :
* 1. [ DONE - a good start ] move abstract peaces of code to the proper classes
* 2. [ DONE - at least for alpha release ] remove duplicated code ( e_form & e_admin_form_ui ), refactoring
* 3. make JS Manager handle Styles ( . css files and inline CSS )
* 4. [ DONE ] e_form is missing some methods used in e_admin_form_ui
2009-12-23 15:12:13 +00:00
* 5. [ DONE ] date convert needs string - to - datestamp auto parsing , strptime () is the solution but needs support for
* Windows and PHP < 5.1 . 0 - build custom strptime () function ( php_compatibility_handler . php ) on this -
2009-11-24 16:32:02 +00:00
* http :// sauron . lionel . free . fr / ? page = php_lib_strptime ( bad license so no copy / paste is allowed ! )
* 6. [ DONE - read / writeParms introduced ] $fields [ parms ] mess - fix it , separate list / edit mode parms somehow
* 7. clean up / document all object vars ( e_admin_ui , e_admin_dispatcher )
* 8. [ DONE hopefully ] clean up / document all parameters ( get / setParm ()) in controller and model classes
* 9. [ DONE ] 'ip' field type - convert to human readable format while showing / editing record
* 10. draggable ( or not ? ) ordering ( list view )
* 11. [ DONE ] realtime search filter ( typing text ) - like downloads currently
* 12. [ DONE ] autosubmit when 'filter' dropdown is changed ( quick fix ? )
2009-12-23 15:12:13 +00:00
* 13. tablerender captions
2009-11-24 16:32:02 +00:00
* 14. [ DONE ] textareas auto - height
* 15. [ DONE ] multi JOIN table support ( optional ), aliases
* 16. tabs support ( create / edit view )
* 17. tree list view ( should handle cases like Site Links admin page )
2012-08-02 02:09:58 +00:00
*/
2020-06-05 11:34:17 -07:00