// // ------------------------------------------------------------------------- // include_once( '../../../include/cp_header.php' ) ; include_once "../include/gtickets.php" ; include_once XOOPS_ROOT_PATH.'/class/template.php'; // searching a language file "mytplsadmin.php" // (in the module)->(in tplsadmin module)->(fallbacked english) if( file_exists( dirname(dirname(__FILE__)).'/language/'.$xoopsConfig['language'].'/mytplsadmin.php' ) ) { include_once dirname(dirname(__FILE__)).'/language/'.$xoopsConfig['language'].'/mytplsadmin.php' ; } else if( file_exists( XOOPS_ROOT_PATH.'/modules/tplsadmin/language/'.$xoopsConfig['language'].'/mytplsadmin.php' ) ) { include_once XOOPS_ROOT_PATH.'/modules/tplsadmin/language/'.$xoopsConfig['language'].'/mytplsadmin.php' ; } else { // fallbacked english define( '_MYTPLSADMIN_CREATE_NEW_TPLSET' , 'Create a new set' ) ; define( '_MYTPLSADMIN_CAPTION_BASE' , 'Base' ) ; define( '_MYTPLSADMIN_CAPTION_SETNAME' , 'name' ) ; define( '_MYTPLSADMIN_OPT_BLANKSET' , '(blank)' ) ; define( '_MYTPLSADMIN_CAPTION_COPYTO' , 'to' ) ; define( '_MYTPLSADMIN_BTN_COPY' , 'COPY' ) ; define( '_MYTPLSADMIN_TITLE_CHECKALL' , 'Turn on/off all of checkboxes in this row' ) ; define( '_MYTPLSADMIN_CNF_DELETE_SELECTED_TEMPLATES' , 'All of checked templates in the set(row) will be removed. Are you OK?' ) ; define( '_MYTPLSADMIN_CNF_COPY_SELECTED_TEMPLATES' , 'All of checked templates in the set(row) will be copied/overwritten into the selected set. Are you OK?' ) ; define( '_MYTPLSADMIN_TH_TYPE' , 'type' ) ; define( '_MYTPLSADMIN_TH_FILE' , 'base file' ) ; define( '_MYTPLSADMIN_ERR_NOTPLFILE' , "No template is checked." ) ; define( '_MYTPLSADMIN_ERR_INVALIDTPLSET' , "Destination set is same as source set, or no valid tplset is specified." ) ; define( '_MYTPLSADMIN_ERR_CANTREMOVEDEFAULT' , "You can't remove 'default' template." ) ; define( '_MYTPLSADMIN_ERR_DUPLICATEDSETNAME' , "The set name already exists." ) ; define( '_MYTPLSADMIN_ERR_INVALIDSETNAME' , "a wrong set name is specified." ) ; } // initials $xoops_system_path = XOOPS_ROOT_PATH . '/modules/system' ; $db =& Database::getInstance(); $myts =& MyTextSanitizer::getInstance() ; // determine language $language = $xoopsConfig['language'] ; if( ! file_exists( "$xoops_system_path/language/$language/admin/tplsets.php") ) $language = 'english' ; // load language constants // to prevent from notice that constants already defined $error_reporting_level = error_reporting( 0 ) ; include_once( "$xoops_system_path/constants.php" ) ; include_once( "$xoops_system_path/language/$language/admin.php" ) ; include_once( "$xoops_system_path/language/$language/admin/tplsets.php" ) ; error_reporting( $error_reporting_level ) ; // check $xoopsModule if( ! is_object( $xoopsModule ) ) redirect_header( XOOPS_URL.'/user.php' , 1 , _NOPERM ) ; // set target_module if specified by $_GET['dirname'] $module_handler =& xoops_gethandler('module'); if( ! empty( $_GET['dirname'] ) ) { $target_module =& $module_handler->getByDirname($_GET['dirname']); } if( ! empty( $target_module ) && is_object( $target_module ) ) { // specified by dirname (for tplsadmin as an independent module) $target_mid = $target_module->getVar( 'mid' ) ; $target_dirname = $target_module->getVar( 'dirname' ) ; $target_dirname4sql = addslashes( $target_dirname ) ; $target_mname = $target_module->getVar( 'name' ) . " " . sprintf( "(%2.2f)" , $target_module->getVar('version') / 100.0 ) ; $query4redirect = '?dirname='.urlencode(strip_tags($_GET['dirname'])) ; } else { // not specified by dirname (for 3rd party modules as mytplsadmin) $target_mid = $xoopsModule->getVar( 'mid' ) ; $target_dirname = $xoopsModule->getVar( 'dirname' ) ; $target_dirname4sql = addslashes( $target_dirname ) ; $target_mname = $xoopsModule->getVar( 'name' ) ; $query4redirect = '' ; } // check access right (needs system_admin of tplset) $sysperm_handler =& xoops_gethandler('groupperm'); if (!$sysperm_handler->checkRight('system_admin', XOOPS_SYSTEM_TPLSET, $xoopsUser->getGroups())) redirect_header( XOOPS_URL.'/user.php' , 1 , _NOPERM ) ; //**************// // POST stages // //**************// // Create new template set (blank or clone) if( ! empty( $_POST['clone_tplset_do'] ) && ! empty( $_POST['clone_tplset_from'] ) && ! empty( $_POST['clone_tplset_to'] ) ) { // Ticket Check if ( ! $xoopsGTicket->check() ) { redirect_header(XOOPS_URL.'/',3,$xoopsGTicket->getErrors()); } $tplset_from = $myts->stripSlashesGPC( $_POST['clone_tplset_from'] ) ; $tplset_to = $myts->stripSlashesGPC( $_POST['clone_tplset_to'] ) ; // check tplset_name "from" and "to" if( ! preg_match( '/^[0-9A-Za-z_-]{1,16}$/' , $_POST['clone_tplset_from'] ) ) die( _MYTPLSADMIN_ERR_INVALIDSETNAME ) ; if( ! preg_match( '/^[0-9A-Za-z_-]{1,16}$/' , $_POST['clone_tplset_to'] ) ) die( _MYTPLSADMIN_ERR_INVALIDSETNAME ) ; list( $is_exist ) = $db->fetchRow( $db->query( "SELECT COUNT(*) FROM ".$db->prefix("tplfile")." WHERE tpl_tplset='".addslashes($tplset_to)."'" ) ) ; if( $is_exist ) die( _MYTPLSADMIN_ERR_DUPLICATEDSETNAME ) ; list( $is_exist ) = $db->fetchRow( $db->query( "SELECT COUNT(*) FROM ".$db->prefix("tplset")." WHERE tplset_name='".addslashes($tplset_to)."'" ) ) ; if( $is_exist ) die( _MYTPLSADMIN_ERR_DUPLICATEDSETNAME ) ; // insert tplset table $db->query( "INSERT INTO ".$db->prefix("tplset")." SET tplset_name='".addslashes($tplset_to)."', tplset_desc='Created by tplsadmin', tplset_created=UNIX_TIMESTAMP()" ) ; copy_templates_db2db( $tplset_from , $tplset_to , "tpl_module='$target_dirname4sql'" ) ; redirect_header( 'mytplsadmin.php?dirname='.$target_dirname , 1 , _MD_AM_DBUPDATED ) ; exit ; } // DB to DB template copy (checked templates) if( is_array( @$_POST['copy_do'] ) ) foreach( $_POST['copy_do'] as $tplset_from_tmp => $val ) if( ! empty( $val ) ) { // Ticket Check if ( ! $xoopsGTicket->check() ) { redirect_header(XOOPS_URL.'/',3,$xoopsGTicket->getErrors()); } $tplset_from = $myts->stripSlashesGPC( $tplset_from_tmp ) ; if( empty( $_POST['copy_to'][$tplset_from] ) || $_POST['copy_to'][$tplset_from] == $tplset_from ) die( _MYTPLSADMIN_ERR_INVALIDTPLSET ) ; if( empty( $_POST["{$tplset_from}_check"] ) ) die( _MYTPLSADMIN_ERR_NOTPLFILE ) ; $tplset_to = $myts->stripSlashesGPC( $_POST['copy_to'][$tplset_from] ) ; foreach( $_POST["{$tplset_from}_check"] as $tplfile_tmp => $val ) { if( empty( $val ) ) continue ; $tplfile = $myts->stripSlashesGPC( $tplfile_tmp ) ; copy_templates_db2db( $tplset_from , $tplset_to , "tpl_file='".addslashes($tplfile)."'" ) ; } redirect_header( 'mytplsadmin.php?dirname='.$target_dirname , 1 , _MD_AM_DBUPDATED ) ; exit ; } // File to DB template copy (checked templates) if( ! empty( $_POST['copyf2db_do'] ) ) { // Ticket Check if ( ! $xoopsGTicket->check() ) { redirect_header(XOOPS_URL.'/',3,$xoopsGTicket->getErrors()); } if( empty( $_POST['copyf2db_to'] ) ) die( _MYTPLSADMIN_ERR_INVALIDTPLSET ) ; if( empty( $_POST['basecheck'] ) ) die( _MYTPLSADMIN_ERR_NOTPLFILE ) ; $tplset_to = $myts->stripSlashesGPC( $_POST['copyf2db_to'] ) ; foreach( $_POST['basecheck'] as $tplfile_tmp => $val ) { if( empty( $val ) ) continue ; $tplfile = $myts->stripSlashesGPC( $tplfile_tmp ) ; copy_templates_f2db( $tplset_to , "tpl_file='".addslashes($tplfile)."'" ) ; } redirect_header( 'mytplsadmin.php?dirname='.$target_dirname , 1 , _MD_AM_DBUPDATED ) ; exit ; } // DB template remove (checked templates) if( is_array( @$_POST['del_do'] ) ) foreach( $_POST['del_do'] as $tplset_from_tmp => $val ) if( ! empty( $val ) ) { // Ticket Check if ( ! $xoopsGTicket->check() ) { redirect_header(XOOPS_URL.'/',3,$xoopsGTicket->getErrors()); } $tplset_from = $myts->stripSlashesGPC( $tplset_from_tmp ) ; if( $tplset_from == 'default' ) die( _MYTPLSADMIN_ERR_CANTREMOVEDEFAULT ) ; if( empty( $_POST["{$tplset_from}_check"] ) ) die( _MYTPLSADMIN_ERR_NOTPLFILE ) ; $tpl = new XoopsTpl(); $tpl->force_compile = true; foreach( $_POST["{$tplset_from}_check"] as $tplfile_tmp => $val ) { if( empty( $val ) ) continue ; $tplfile = $myts->stripSlashesGPC( $tplfile_tmp ) ; $result = $db->query( "SELECT tpl_id FROM ".$db->prefix("tplfile")." WHERE tpl_tplset='".addslashes($tplset_from)."' AND tpl_file='".addslashes($tplfile)."'" ) ; while( list( $tpl_id ) = $db->fetchRow( $result ) ) { $tpl_id = intval( $tpl_id ) ; $db->query( "DELETE FROM ".$db->prefix("tplfile")." WHERE tpl_id=$tpl_id" ) ; $db->query( "DELETE FROM ".$db->prefix("tplsource")." WHERE tpl_id=$tpl_id" ) ; } // remove templates_c $tpl->clear_cache('db:'.$tplfile); $tpl->clear_compiled_tpl('db:'.$tplfile); } redirect_header( 'mytplsadmin.php?dirname='.$target_dirname , 1 , _MD_AM_DBUPDATED ) ; exit ; } //************// // GET stage // //************// // get tplsets $tplset_handler =& xoops_gethandler( 'tplset' ) ; $tplsets = array_keys( $tplset_handler->getList() ) ; $sql = "SELECT distinct tpl_tplset FROM ".$db->prefix("tplfile")." ORDER BY tpl_tplset='default' DESC,tpl_tplset" ; $srs = $db->query($sql); while( list( $tplset ) = $db->fetchRow( $srs ) ) { if( ! in_array( $tplset , $tplsets ) ) $tplsets[] = $tplset ; } $tplsets_th4disp = '' ; $tplset_options = "\n" ; foreach( $tplsets as $tplset ) { $tplset4disp = htmlspecialchars( $tplset , ENT_QUOTES ) ; $th_style = $tplset == $xoopsConfig['template_set'] ? "style='color:yellow;'" : "" ; $tplsets_th4disp .= "