| 1 | <?php |
|---|
| 2 | // ------------------------------------------------------------------------- // |
|---|
| 3 | // mytplsadmin.php // |
|---|
| 4 | // - XOOPS templates admin for each modules - // |
|---|
| 5 | // GIJOE <http://www.peak.ne.jp/> // |
|---|
| 6 | // ------------------------------------------------------------------------- // |
|---|
| 7 | |
|---|
| 8 | include_once( '../../../include/cp_header.php' ) ; |
|---|
| 9 | |
|---|
| 10 | include_once "../include/gtickets.php" ; |
|---|
| 11 | include_once XOOPS_ROOT_PATH.'/class/template.php'; |
|---|
| 12 | |
|---|
| 13 | // searching a language file "mytplsadmin.php" |
|---|
| 14 | // (in the module)->(in tplsadmin module)->(fallbacked english) |
|---|
| 15 | if( file_exists( dirname(dirname(__FILE__)).'/language/'.$xoopsConfig['language'].'/mytplsadmin.php' ) ) { |
|---|
| 16 | include_once dirname(dirname(__FILE__)).'/language/'.$xoopsConfig['language'].'/mytplsadmin.php' ; |
|---|
| 17 | } else if( file_exists( XOOPS_ROOT_PATH.'/modules/tplsadmin/language/'.$xoopsConfig['language'].'/mytplsadmin.php' ) ) { |
|---|
| 18 | include_once XOOPS_ROOT_PATH.'/modules/tplsadmin/language/'.$xoopsConfig['language'].'/mytplsadmin.php' ; |
|---|
| 19 | } else { |
|---|
| 20 | // fallbacked english |
|---|
| 21 | define( '_MYTPLSADMIN_CREATE_NEW_TPLSET' , 'Create a new set' ) ; |
|---|
| 22 | define( '_MYTPLSADMIN_CAPTION_BASE' , 'Base' ) ; |
|---|
| 23 | define( '_MYTPLSADMIN_CAPTION_SETNAME' , 'name' ) ; |
|---|
| 24 | define( '_MYTPLSADMIN_OPT_BLANKSET' , '(blank)' ) ; |
|---|
| 25 | define( '_MYTPLSADMIN_CAPTION_COPYTO' , 'to' ) ; |
|---|
| 26 | define( '_MYTPLSADMIN_BTN_COPY' , 'COPY' ) ; |
|---|
| 27 | define( '_MYTPLSADMIN_TITLE_CHECKALL' , 'Turn on/off all of checkboxes in this row' ) ; |
|---|
| 28 | define( '_MYTPLSADMIN_CNF_DELETE_SELECTED_TEMPLATES' , 'All of checked templates in the set(row) will be removed. Are you OK?' ) ; |
|---|
| 29 | 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?' ) ; |
|---|
| 30 | define( '_MYTPLSADMIN_TH_TYPE' , 'type' ) ; |
|---|
| 31 | define( '_MYTPLSADMIN_TH_FILE' , 'base file' ) ; |
|---|
| 32 | define( '_MYTPLSADMIN_ERR_NOTPLFILE' , "No template is checked." ) ; |
|---|
| 33 | define( '_MYTPLSADMIN_ERR_INVALIDTPLSET' , "Destination set is same as source set, or no valid tplset is specified." ) ; |
|---|
| 34 | define( '_MYTPLSADMIN_ERR_CANTREMOVEDEFAULT' , "You can't remove 'default' template." ) ; |
|---|
| 35 | define( '_MYTPLSADMIN_ERR_DUPLICATEDSETNAME' , "The set name already exists." ) ; |
|---|
| 36 | define( '_MYTPLSADMIN_ERR_INVALIDSETNAME' , "a wrong set name is specified." ) ; |
|---|
| 37 | } |
|---|
| 38 | |
|---|
| 39 | |
|---|
| 40 | // initials |
|---|
| 41 | $xoops_system_path = XOOPS_ROOT_PATH . '/modules/system' ; |
|---|
| 42 | $db =& Database::getInstance(); |
|---|
| 43 | $myts =& MyTextSanitizer::getInstance() ; |
|---|
| 44 | |
|---|
| 45 | |
|---|
| 46 | // determine language |
|---|
| 47 | $language = $xoopsConfig['language'] ; |
|---|
| 48 | if( ! file_exists( "$xoops_system_path/language/$language/admin/tplsets.php") ) $language = 'english' ; |
|---|
| 49 | |
|---|
| 50 | // load language constants |
|---|
| 51 | // to prevent from notice that constants already defined |
|---|
| 52 | $error_reporting_level = error_reporting( 0 ) ; |
|---|
| 53 | include_once( "$xoops_system_path/constants.php" ) ; |
|---|
| 54 | include_once( "$xoops_system_path/language/$language/admin.php" ) ; |
|---|
| 55 | include_once( "$xoops_system_path/language/$language/admin/tplsets.php" ) ; |
|---|
| 56 | error_reporting( $error_reporting_level ) ; |
|---|
| 57 | |
|---|
| 58 | // check $xoopsModule |
|---|
| 59 | if( ! is_object( $xoopsModule ) ) redirect_header( XOOPS_URL.'/user.php' , 1 , _NOPERM ) ; |
|---|
| 60 | |
|---|
| 61 | // set target_module if specified by $_GET['dirname'] |
|---|
| 62 | $module_handler =& xoops_gethandler('module'); |
|---|
| 63 | if( ! empty( $_GET['dirname'] ) ) { |
|---|
| 64 | $target_module =& $module_handler->getByDirname($_GET['dirname']); |
|---|
| 65 | } |
|---|
| 66 | |
|---|
| 67 | if( ! empty( $target_module ) && is_object( $target_module ) ) { |
|---|
| 68 | // specified by dirname (for tplsadmin as an independent module) |
|---|
| 69 | $target_mid = $target_module->getVar( 'mid' ) ; |
|---|
| 70 | $target_dirname = $target_module->getVar( 'dirname' ) ; |
|---|
| 71 | $target_dirname4sql = addslashes( $target_dirname ) ; |
|---|
| 72 | $target_mname = $target_module->getVar( 'name' ) . " " . sprintf( "(%2.2f)" , $target_module->getVar('version') / 100.0 ) ; |
|---|
| 73 | $query4redirect = '?dirname='.urlencode(strip_tags($_GET['dirname'])) ; |
|---|
| 74 | } else { |
|---|
| 75 | // not specified by dirname (for 3rd party modules as mytplsadmin) |
|---|
| 76 | $target_mid = $xoopsModule->getVar( 'mid' ) ; |
|---|
| 77 | $target_dirname = $xoopsModule->getVar( 'dirname' ) ; |
|---|
| 78 | $target_dirname4sql = addslashes( $target_dirname ) ; |
|---|
| 79 | $target_mname = $xoopsModule->getVar( 'name' ) ; |
|---|
| 80 | $query4redirect = '' ; |
|---|
| 81 | } |
|---|
| 82 | |
|---|
| 83 | // check access right (needs system_admin of tplset) |
|---|
| 84 | $sysperm_handler =& xoops_gethandler('groupperm'); |
|---|
| 85 | if (!$sysperm_handler->checkRight('system_admin', XOOPS_SYSTEM_TPLSET, $xoopsUser->getGroups())) redirect_header( XOOPS_URL.'/user.php' , 1 , _NOPERM ) ; |
|---|
| 86 | |
|---|
| 87 | |
|---|
| 88 | //**************// |
|---|
| 89 | // POST stages // |
|---|
| 90 | //**************// |
|---|
| 91 | |
|---|
| 92 | // Create new template set (blank or clone) |
|---|
| 93 | if( ! empty( $_POST['clone_tplset_do'] ) && ! empty( $_POST['clone_tplset_from'] ) && ! empty( $_POST['clone_tplset_to'] ) ) { |
|---|
| 94 | // Ticket Check |
|---|
| 95 | if ( ! $xoopsGTicket->check() ) { |
|---|
| 96 | redirect_header(XOOPS_URL.'/',3,$xoopsGTicket->getErrors()); |
|---|
| 97 | } |
|---|
| 98 | |
|---|
| 99 | $tplset_from = $myts->stripSlashesGPC( $_POST['clone_tplset_from'] ) ; |
|---|
| 100 | $tplset_to = $myts->stripSlashesGPC( $_POST['clone_tplset_to'] ) ; |
|---|
| 101 | // check tplset_name "from" and "to" |
|---|
| 102 | if( ! preg_match( '/^[0-9A-Za-z_-]{1,16}$/' , $_POST['clone_tplset_from'] ) ) die( _MYTPLSADMIN_ERR_INVALIDSETNAME ) ; |
|---|
| 103 | if( ! preg_match( '/^[0-9A-Za-z_-]{1,16}$/' , $_POST['clone_tplset_to'] ) ) die( _MYTPLSADMIN_ERR_INVALIDSETNAME ) ; |
|---|
| 104 | list( $is_exist ) = $db->fetchRow( $db->query( "SELECT COUNT(*) FROM ".$db->prefix("tplfile")." WHERE tpl_tplset='".addslashes($tplset_to)."'" ) ) ; |
|---|
| 105 | if( $is_exist ) die( _MYTPLSADMIN_ERR_DUPLICATEDSETNAME ) ; |
|---|
| 106 | list( $is_exist ) = $db->fetchRow( $db->query( "SELECT COUNT(*) FROM ".$db->prefix("tplset")." WHERE tplset_name='".addslashes($tplset_to)."'" ) ) ; |
|---|
| 107 | if( $is_exist ) die( _MYTPLSADMIN_ERR_DUPLICATEDSETNAME ) ; |
|---|
| 108 | // insert tplset table |
|---|
| 109 | $db->query( "INSERT INTO ".$db->prefix("tplset")." SET tplset_name='".addslashes($tplset_to)."', tplset_desc='Created by tplsadmin', tplset_created=UNIX_TIMESTAMP()" ) ; |
|---|
| 110 | copy_templates_db2db( $tplset_from , $tplset_to , "tpl_module='$target_dirname4sql'" ) ; |
|---|
| 111 | redirect_header( 'mytplsadmin.php?dirname='.$target_dirname , 1 , _MD_AM_DBUPDATED ) ; |
|---|
| 112 | exit ; |
|---|
| 113 | } |
|---|
| 114 | |
|---|
| 115 | // DB to DB template copy (checked templates) |
|---|
| 116 | if( is_array( @$_POST['copy_do'] ) ) foreach( $_POST['copy_do'] as $tplset_from_tmp => $val ) if( ! empty( $val ) ) { |
|---|
| 117 | // Ticket Check |
|---|
| 118 | if ( ! $xoopsGTicket->check() ) { |
|---|
| 119 | redirect_header(XOOPS_URL.'/',3,$xoopsGTicket->getErrors()); |
|---|
| 120 | } |
|---|
| 121 | |
|---|
| 122 | $tplset_from = $myts->stripSlashesGPC( $tplset_from_tmp ) ; |
|---|
| 123 | if( empty( $_POST['copy_to'][$tplset_from] ) || $_POST['copy_to'][$tplset_from] == $tplset_from ) die( _MYTPLSADMIN_ERR_INVALIDTPLSET ) ; |
|---|
| 124 | if( empty( $_POST["{$tplset_from}_check"] ) ) die( _MYTPLSADMIN_ERR_NOTPLFILE ) ; |
|---|
| 125 | $tplset_to = $myts->stripSlashesGPC( $_POST['copy_to'][$tplset_from] ) ; |
|---|
| 126 | foreach( $_POST["{$tplset_from}_check"] as $tplfile_tmp => $val ) { |
|---|
| 127 | if( empty( $val ) ) continue ; |
|---|
| 128 | $tplfile = $myts->stripSlashesGPC( $tplfile_tmp ) ; |
|---|
| 129 | copy_templates_db2db( $tplset_from , $tplset_to , "tpl_file='".addslashes($tplfile)."'" ) ; |
|---|
| 130 | } |
|---|
| 131 | redirect_header( 'mytplsadmin.php?dirname='.$target_dirname , 1 , _MD_AM_DBUPDATED ) ; |
|---|
| 132 | exit ; |
|---|
| 133 | } |
|---|
| 134 | |
|---|
| 135 | // File to DB template copy (checked templates) |
|---|
| 136 | if( ! empty( $_POST['copyf2db_do'] ) ) { |
|---|
| 137 | // Ticket Check |
|---|
| 138 | if ( ! $xoopsGTicket->check() ) { |
|---|
| 139 | redirect_header(XOOPS_URL.'/',3,$xoopsGTicket->getErrors()); |
|---|
| 140 | } |
|---|
| 141 | |
|---|
| 142 | if( empty( $_POST['copyf2db_to'] ) ) die( _MYTPLSADMIN_ERR_INVALIDTPLSET ) ; |
|---|
| 143 | if( empty( $_POST['basecheck'] ) ) die( _MYTPLSADMIN_ERR_NOTPLFILE ) ; |
|---|
| 144 | $tplset_to = $myts->stripSlashesGPC( $_POST['copyf2db_to'] ) ; |
|---|
| 145 | foreach( $_POST['basecheck'] as $tplfile_tmp => $val ) { |
|---|
| 146 | if( empty( $val ) ) continue ; |
|---|
| 147 | $tplfile = $myts->stripSlashesGPC( $tplfile_tmp ) ; |
|---|
| 148 | copy_templates_f2db( $tplset_to , "tpl_file='".addslashes($tplfile)."'" ) ; |
|---|
| 149 | } |
|---|
| 150 | redirect_header( 'mytplsadmin.php?dirname='.$target_dirname , 1 , _MD_AM_DBUPDATED ) ; |
|---|
| 151 | exit ; |
|---|
| 152 | } |
|---|
| 153 | |
|---|
| 154 | // DB template remove (checked templates) |
|---|
| 155 | if( is_array( @$_POST['del_do'] ) ) foreach( $_POST['del_do'] as $tplset_from_tmp => $val ) if( ! empty( $val ) ) { |
|---|
| 156 | // Ticket Check |
|---|
| 157 | if ( ! $xoopsGTicket->check() ) { |
|---|
| 158 | redirect_header(XOOPS_URL.'/',3,$xoopsGTicket->getErrors()); |
|---|
| 159 | } |
|---|
| 160 | |
|---|
| 161 | $tplset_from = $myts->stripSlashesGPC( $tplset_from_tmp ) ; |
|---|
| 162 | if( $tplset_from == 'default' ) die( _MYTPLSADMIN_ERR_CANTREMOVEDEFAULT ) ; |
|---|
| 163 | if( empty( $_POST["{$tplset_from}_check"] ) ) die( _MYTPLSADMIN_ERR_NOTPLFILE ) ; |
|---|
| 164 | |
|---|
| 165 | $tpl = new XoopsTpl(); |
|---|
| 166 | $tpl->force_compile = true; |
|---|
| 167 | |
|---|
| 168 | foreach( $_POST["{$tplset_from}_check"] as $tplfile_tmp => $val ) { |
|---|
| 169 | if( empty( $val ) ) continue ; |
|---|
| 170 | $tplfile = $myts->stripSlashesGPC( $tplfile_tmp ) ; |
|---|
| 171 | $result = $db->query( "SELECT tpl_id FROM ".$db->prefix("tplfile")." WHERE tpl_tplset='".addslashes($tplset_from)."' AND tpl_file='".addslashes($tplfile)."'" ) ; |
|---|
| 172 | while( list( $tpl_id ) = $db->fetchRow( $result ) ) { |
|---|
| 173 | $tpl_id = intval( $tpl_id ) ; |
|---|
| 174 | $db->query( "DELETE FROM ".$db->prefix("tplfile")." WHERE tpl_id=$tpl_id" ) ; |
|---|
| 175 | $db->query( "DELETE FROM ".$db->prefix("tplsource")." WHERE tpl_id=$tpl_id" ) ; |
|---|
| 176 | } |
|---|
| 177 | // remove templates_c |
|---|
| 178 | $tpl->clear_cache('db:'.$tplfile); |
|---|
| 179 | $tpl->clear_compiled_tpl('db:'.$tplfile); |
|---|
| 180 | } |
|---|
| 181 | redirect_header( 'mytplsadmin.php?dirname='.$target_dirname , 1 , _MD_AM_DBUPDATED ) ; |
|---|
| 182 | exit ; |
|---|
| 183 | } |
|---|
| 184 | |
|---|
| 185 | |
|---|
| 186 | |
|---|
| 187 | //************// |
|---|
| 188 | // GET stage // |
|---|
| 189 | //************// |
|---|
| 190 | |
|---|
| 191 | // get tplsets |
|---|
| 192 | $tplset_handler =& xoops_gethandler( 'tplset' ) ; |
|---|
| 193 | $tplsets = array_keys( $tplset_handler->getList() ) ; |
|---|
| 194 | $sql = "SELECT distinct tpl_tplset FROM ".$db->prefix("tplfile")." ORDER BY tpl_tplset='default' DESC,tpl_tplset" ; |
|---|
| 195 | $srs = $db->query($sql); |
|---|
| 196 | while( list( $tplset ) = $db->fetchRow( $srs ) ) { |
|---|
| 197 | if( ! in_array( $tplset , $tplsets ) ) $tplsets[] = $tplset ; |
|---|
| 198 | } |
|---|
| 199 | |
|---|
| 200 | $tplsets_th4disp = '' ; |
|---|
| 201 | $tplset_options = "<option value=''>----</option>\n" ; |
|---|
| 202 | foreach( $tplsets as $tplset ) { |
|---|
| 203 | $tplset4disp = htmlspecialchars( $tplset , ENT_QUOTES ) ; |
|---|
| 204 | $th_style = $tplset == $xoopsConfig['template_set'] ? "style='color:yellow;'" : "" ; |
|---|
| 205 | $tplsets_th4disp .= "<th $th_style><input type='checkbox' title='"._MYTPLSADMIN_TITLE_CHECKALL."' onclick=\"with(document.MainForm){for(i=0;i<length;i++){if(elements[i].type=='checkbox'&&elements[i].name.indexOf('{$tplset4disp}_check')>=0){elements[i].checked=this.checked;}}}\" />DB-{$tplset4disp}</th>" ; |
|---|
| 206 | $tplset_options .= "<option value='$tplset4disp'>$tplset4disp</option>\n" ; |
|---|
| 207 | } |
|---|
| 208 | |
|---|
| 209 | // get tpl_file owned by the module |
|---|
| 210 | $sql = "SELECT tpl_file,tpl_desc,tpl_type,COUNT(tpl_id) FROM ".$db->prefix("tplfile")." WHERE tpl_module='$target_dirname4sql' GROUP BY tpl_file ORDER BY tpl_type, tpl_file" ; |
|---|
| 211 | $frs = $db->query($sql); |
|---|
| 212 | |
|---|
| 213 | xoops_cp_header() ; |
|---|
| 214 | if( file_exists( './mymenu.php' ) ) include( './mymenu.php' ) ; |
|---|
| 215 | |
|---|
| 216 | echo "<h3 style='text-align:left;'>"._MD_AM_TPLSETS." : $target_mname</h3>\n" ; |
|---|
| 217 | |
|---|
| 218 | |
|---|
| 219 | // beggining of table & form |
|---|
| 220 | echo " |
|---|
| 221 | <form name='MainForm' action='?dirname=".htmlspecialchars($target_dirname,ENT_QUOTES)."' method='post'> |
|---|
| 222 | ".$xoopsGTicket->getTicketHtml( __LINE__ )." |
|---|
| 223 | <table class='outer'> |
|---|
| 224 | <tr> |
|---|
| 225 | <th>"._MD_FILENAME."</th> |
|---|
| 226 | <th>"._MYTPLSADMIN_TH_TYPE."</th> |
|---|
| 227 | <th><input type='checkbox' title="._MYTPLSADMIN_TITLE_CHECKALL." onclick=\"with(document.MainForm){for(i=0;i<length;i++){if(elements[i].type=='checkbox'&&elements[i].name.indexOf('basecheck')>=0){elements[i].checked=this.checked;}}}\" />"._MYTPLSADMIN_TH_FILE."</th> |
|---|
| 228 | $tplsets_th4disp |
|---|
| 229 | </tr>\n" ; |
|---|
| 230 | |
|---|
| 231 | // STYLE for distinguishing fingerprints |
|---|
| 232 | $fingerprint_styles = array( '' , 'background-color:#00FF00' , 'background-color:#00CC88' , 'background-color:#00FFFF' , 'background-color:#0088FF' , 'background-color:#FF8800' , 'background-color:#0000FF' , 'background-color:#FFFFFF' ) ; |
|---|
| 233 | |
|---|
| 234 | // template ROWS |
|---|
| 235 | while( list( $tpl_file , $tpl_desc , $type , $count ) = $db->fetchRow( $frs ) ) { |
|---|
| 236 | |
|---|
| 237 | $evenodd = @$evenodd == 'even' ? 'odd' : 'even' ; |
|---|
| 238 | $fingerprint_style_count = 0 ; |
|---|
| 239 | |
|---|
| 240 | // information about the template |
|---|
| 241 | echo " |
|---|
| 242 | <tr> |
|---|
| 243 | <td class='$evenodd'> |
|---|
| 244 | <dl> |
|---|
| 245 | <dt>".htmlspecialchars($tpl_file,ENT_QUOTES)."</dt> |
|---|
| 246 | <dd>".htmlspecialchars($tpl_desc,ENT_QUOTES)."</dd> |
|---|
| 247 | </dl> |
|---|
| 248 | </td> |
|---|
| 249 | <td class='$evenodd'>".$type."<br />(".$count.")</td>\n" ; |
|---|
| 250 | |
|---|
| 251 | // the base file template column |
|---|
| 252 | $basefilepath = XOOPS_ROOT_PATH.'/modules/'.$target_dirname.'/templates/'.($type=='block'?'blocks/':'').$tpl_file ; |
|---|
| 253 | if( file_exists( $basefilepath ) ) { |
|---|
| 254 | $fingerprint = get_fingerprint( file( $basefilepath ) ) ; |
|---|
| 255 | $fingerprints[ $fingerprint ] = 1 ; |
|---|
| 256 | echo "<td class='$evenodd'>".formatTimestamp(filemtime($basefilepath),'m').'<br />'.substr($fingerprint,0,16)."<br /><input type='checkbox' name='basecheck[$tpl_file]' value='1' /></td>\n" ; |
|---|
| 257 | } else { |
|---|
| 258 | echo "<td class='$evenodd'><br /></td>" ; |
|---|
| 259 | } |
|---|
| 260 | |
|---|
| 261 | // db template columns |
|---|
| 262 | foreach( $tplsets as $tplset ) { |
|---|
| 263 | $tplset4disp = htmlspecialchars( $tplset , ENT_QUOTES ) ; |
|---|
| 264 | |
|---|
| 265 | // query for templates in db |
|---|
| 266 | $drs = $db->query( "SELECT * FROM ".$db->prefix("tplfile")." f NATURAL LEFT JOIN ".$db->prefix("tplsource")." s WHERE tpl_file='".addslashes($tpl_file)."' AND tpl_tplset='".addslashes($tplset)."'" ) ; |
|---|
| 267 | $numrows = $db->getRowsNum( $drs ) ; |
|---|
| 268 | $tpl = $db->fetchArray( $drs ) ; |
|---|
| 269 | if( empty( $tpl['tpl_id'] ) ) { |
|---|
| 270 | echo "<td class='$evenodd'>($numrows)</td>\n" ; |
|---|
| 271 | } else { |
|---|
| 272 | $fingerprint = get_fingerprint( explode( "\n" , $tpl['tpl_source'] ) ) ; |
|---|
| 273 | if( isset( $fingerprints[ $fingerprint ] ) ) { |
|---|
| 274 | $style = $fingerprints[ $fingerprint ] ; |
|---|
| 275 | } else { |
|---|
| 276 | $fingerprint_style_count ++ ; |
|---|
| 277 | $style = $fingerprint_styles[$fingerprint_style_count] ; |
|---|
| 278 | $fingerprints[ $fingerprint ] = $style ; |
|---|
| 279 | } |
|---|
| 280 | echo "<td class='$evenodd' style='$style'>".formatTimestamp($tpl['tpl_lastmodified'],'m').'<br />'.substr($fingerprint,0,16)."<br /><input type='checkbox' name='{$tplset4disp}_check[{$tpl_file}]' value='1' /> <a href='mytplsform.php?tpl_file=".htmlspecialchars($tpl['tpl_file'],ENT_QUOTES)."&tpl_tplset=".htmlspecialchars($tpl['tpl_tplset'],ENT_QUOTES)."'>"._EDIT."</a> ($numrows)</td>\n" ; |
|---|
| 281 | } |
|---|
| 282 | } |
|---|
| 283 | |
|---|
| 284 | echo "</tr>\n" ; |
|---|
| 285 | } |
|---|
| 286 | |
|---|
| 287 | // command submit ROW |
|---|
| 288 | echo " |
|---|
| 289 | <tr> |
|---|
| 290 | <td class='head'> |
|---|
| 291 | "._MYTPLSADMIN_CREATE_NEW_TPLSET.": <br /> |
|---|
| 292 | "._MYTPLSADMIN_CAPTION_BASE.": |
|---|
| 293 | <select name='clone_tplset_from'> |
|---|
| 294 | $tplset_options |
|---|
| 295 | <option value='_blank_'>"._MYTPLSADMIN_OPT_BLANKSET."</option> |
|---|
| 296 | </select> |
|---|
| 297 | <br /> |
|---|
| 298 | "._MYTPLSADMIN_CAPTION_SETNAME.": <input type='text' name='clone_tplset_to' size='8' maxlength='16' /> <input type='submit' name='clone_tplset_do' value='"._MD_GENERATE."' /> |
|---|
| 299 | </td> |
|---|
| 300 | <td class='head'></td> |
|---|
| 301 | <td class='head'> |
|---|
| 302 | "._MYTPLSADMIN_CAPTION_COPYTO.": |
|---|
| 303 | <select name='copyf2db_to'> |
|---|
| 304 | $tplset_options |
|---|
| 305 | </select> |
|---|
| 306 | <br /> |
|---|
| 307 | <input name='copyf2db_do' type='submit' value='"._MYTPLSADMIN_BTN_COPY."' onclick='return confirm(\""._MYTPLSADMIN_CNF_COPY_SELECTED_TEMPLATES."\");' /> |
|---|
| 308 | </td>\n" ; |
|---|
| 309 | |
|---|
| 310 | foreach( $tplsets as $tplset ) { |
|---|
| 311 | $tplset4disp = htmlspecialchars( $tplset , ENT_QUOTES ) ; |
|---|
| 312 | echo "\t\t<td class='head'> |
|---|
| 313 | ".($tplset=='default'?"":"<input name='del_do[{$tplset4disp}]' type='submit' value='"._DELETE."' onclick='return confirm(\""._MYTPLSADMIN_CNF_DELETE_SELECTED_TEMPLATES."\");' /><br /><br />")." |
|---|
| 314 | "._MYTPLSADMIN_CAPTION_COPYTO.": |
|---|
| 315 | <select name='copy_to[{$tplset4disp}]'> |
|---|
| 316 | $tplset_options |
|---|
| 317 | </select> |
|---|
| 318 | <input name='copy_do[{$tplset4disp}]' type='submit' value='"._MYTPLSADMIN_BTN_COPY."' onclick='return confirm(\""._MYTPLSADMIN_CNF_COPY_SELECTED_TEMPLATES."\");' /> |
|---|
| 319 | </td>\n" ; |
|---|
| 320 | } |
|---|
| 321 | |
|---|
| 322 | echo " </tr>\n" ; |
|---|
| 323 | |
|---|
| 324 | |
|---|
| 325 | echo "</table></form>" ; |
|---|
| 326 | // end of table & form |
|---|
| 327 | |
|---|
| 328 | xoops_cp_footer() ; |
|---|
| 329 | |
|---|
| 330 | |
|---|
| 331 | |
|---|
| 332 | |
|---|
| 333 | function get_fingerprint( $lines ) |
|---|
| 334 | { |
|---|
| 335 | $str = '' ; |
|---|
| 336 | foreach( $lines as $line ) { |
|---|
| 337 | if( trim( $line ) ) { |
|---|
| 338 | $str .= md5( trim( $line ) ) ; |
|---|
| 339 | } |
|---|
| 340 | } |
|---|
| 341 | return md5( $str ) ; |
|---|
| 342 | } |
|---|
| 343 | |
|---|
| 344 | function copy_templates_db2db( $tplset_from , $tplset_to , $whr_append = '1' ) |
|---|
| 345 | { |
|---|
| 346 | global $db ; |
|---|
| 347 | |
|---|
| 348 | // get tplfile and tplsource |
|---|
| 349 | $result = $db->query( "SELECT tpl_refid,tpl_module,'".addslashes($tplset_to)."',tpl_file,tpl_desc,tpl_lastmodified,tpl_lastimported,tpl_type,tpl_source FROM ".$db->prefix("tplfile")." NATURAL LEFT JOIN ".$db->prefix("tplsource")." WHERE tpl_tplset='".addslashes($tplset_from)."' AND ($whr_append)" ) ; |
|---|
| 350 | |
|---|
| 351 | while( $row = $db->fetchArray( $result ) ) { |
|---|
| 352 | $tpl_source = array_pop( $row ) ; |
|---|
| 353 | |
|---|
| 354 | $drs = $db->query( "SELECT tpl_id FROM ".$db->prefix("tplfile")." WHERE tpl_tplset='".addslashes($tplset_to)."' AND ($whr_append) AND tpl_file='".addslashes($row['tpl_file'])."' AND tpl_refid='".addslashes($row['tpl_refid'])."'" ) ; |
|---|
| 355 | |
|---|
| 356 | if( ! $db->getRowsNum( $drs ) ) { |
|---|
| 357 | // INSERT mode |
|---|
| 358 | $sql = "INSERT INTO ".$db->prefix("tplfile")." (tpl_refid,tpl_module,tpl_tplset,tpl_file,tpl_desc,tpl_lastmodified,tpl_lastimported,tpl_type) VALUES (" ; |
|---|
| 359 | foreach( $row as $colval ) { |
|---|
| 360 | $sql .= "'".addslashes($colval)."'," ; |
|---|
| 361 | } |
|---|
| 362 | $db->query( substr( $sql , 0 , -1 ) . ')' ) ; |
|---|
| 363 | $tpl_id = $db->getInsertId() ; |
|---|
| 364 | $db->query( "INSERT INTO ".$db->prefix("tplsource")." SET tpl_id='$tpl_id', tpl_source='".addslashes($tpl_source)."'" ) ; |
|---|
| 365 | xoops_template_touch( $tpl_id ) ; |
|---|
| 366 | } else { |
|---|
| 367 | while( list( $tpl_id ) = $db->fetchRow( $drs ) ) { |
|---|
| 368 | // UPDATE mode |
|---|
| 369 | $db->query( "UPDATE ".$db->prefix("tplfile")." SET tpl_refid='".addslashes($row['tpl_refid'])."',tpl_desc='".addslashes($row['tpl_desc'])."',tpl_lastmodified='".addslashes($row['tpl_lastmodified'])."',tpl_lastimported='".addslashes($row['tpl_lastimported'])."',tpl_type='".addslashes($row['tpl_type'])."' WHERE tpl_id='$tpl_id'" ) ; |
|---|
| 370 | $db->query( "UPDATE ".$db->prefix("tplsource")." SET tpl_source='".addslashes($tpl_source)."' WHERE tpl_id='$tpl_id'" ) ; |
|---|
| 371 | xoops_template_touch( $tpl_id ) ; |
|---|
| 372 | } |
|---|
| 373 | } |
|---|
| 374 | } |
|---|
| 375 | } |
|---|
| 376 | |
|---|
| 377 | |
|---|
| 378 | function copy_templates_f2db( $tplset_to , $whr_append = '1' ) |
|---|
| 379 | { |
|---|
| 380 | global $db ; |
|---|
| 381 | |
|---|
| 382 | // get tplsource |
|---|
| 383 | $result = $db->query( "SELECT * FROM ".$db->prefix("tplfile")." WHERE tpl_tplset='default' AND ($whr_append)" ) ; |
|---|
| 384 | |
|---|
| 385 | while( $row = $db->fetchArray( $result ) ) { |
|---|
| 386 | |
|---|
| 387 | $basefilepath = XOOPS_ROOT_PATH.'/modules/'.$row['tpl_module'].'/templates/'.($row['tpl_type']=='block'?'blocks/':'').$row['tpl_file'] ; |
|---|
| 388 | |
|---|
| 389 | $tpl_source = rtrim( implode( "" , file( $basefilepath ) ) ) ; |
|---|
| 390 | $lastmodified = filemtime( $basefilepath ) ; |
|---|
| 391 | |
|---|
| 392 | $drs = $db->query( "SELECT tpl_id FROM ".$db->prefix("tplfile")." WHERE tpl_tplset='".addslashes($tplset_to)."' AND ($whr_append) AND tpl_file='".addslashes($row['tpl_file'])."' AND tpl_refid='".addslashes($row['tpl_refid'])."'" ) ; |
|---|
| 393 | |
|---|
| 394 | if( ! $db->getRowsNum( $drs ) ) { |
|---|
| 395 | // INSERT mode |
|---|
| 396 | $sql = "INSERT INTO ".$db->prefix("tplfile")." SET tpl_refid='".addslashes($row['tpl_refid'])."',tpl_desc='".addslashes($row['tpl_desc'])."',tpl_lastmodified='".addslashes($lastmodified)."',tpl_type='".addslashes($row['tpl_type'])."',tpl_tplset='".addslashes($tplset_to)."',tpl_file='".addslashes($row['tpl_file'])."',tpl_module='".addslashes($row['tpl_module'])."'" ; |
|---|
| 397 | $db->query( $sql ) ; |
|---|
| 398 | $tpl_id = $db->getInsertId() ; |
|---|
| 399 | $db->query( "INSERT INTO ".$db->prefix("tplsource")." SET tpl_id='$tpl_id', tpl_source='".addslashes($tpl_source)."'" ) ; |
|---|
| 400 | xoops_template_touch( $tpl_id ) ; |
|---|
| 401 | } else { |
|---|
| 402 | while( list( $tpl_id ) = $db->fetchRow( $drs ) ) { |
|---|
| 403 | // UPDATE mode |
|---|
| 404 | $db->query( "UPDATE ".$db->prefix("tplfile")." SET tpl_lastmodified='".addslashes($lastmodified)."' WHERE tpl_id='$tpl_id'" ) ; |
|---|
| 405 | $db->query( "UPDATE ".$db->prefix("tplsource")." SET tpl_source='".addslashes($tpl_source)."' WHERE tpl_id='$tpl_id'" ) ; |
|---|
| 406 | xoops_template_touch( $tpl_id ) ; |
|---|
| 407 | } |
|---|
| 408 | } |
|---|
| 409 | } |
|---|
| 410 | } |
|---|
| 411 | |
|---|
| 412 | |
|---|
| 413 | ?> |
|---|