2 include
'../../../include/cp_header.php';
3 include
'admin_header.php';
4 require_once dirname(dirname(__FILE__)).
'/class/gtickets.php' ;
8 if( ! empty(
$_POST[
'copy'] ) && ! empty(
$_POST[
'old_prefix'] ) ) {
10 if( preg_match(
'/[^0-9A-Za-z_-]/' ,
$_POST[
'new_prefix'] ) ) die(
'wrong prefix' ) ;
13 if ( ! $xoopsGTicket->check(
true ,
'protector_admin' ) ) {
17 $new_prefix = empty(
$_POST[
'new_prefix'] ) ?
'x' . substr( md5( time() ) , -5 ) :
$_POST[
'new_prefix'] ;
18 $old_prefix =
$_POST[
'old_prefix'] ;
22 if( !
$db->getRowsNum(
$srs ) ) die(
"You are not allowed to copy tables" ) ;
25 while( $row_table =
$db->fetchArray(
$srs ) ) {
27 $old_table = $row_table[
'Name'] ;
28 if( substr( $old_table , 0 , strlen( $old_prefix ) + 1 ) !== $old_prefix .
'_' )
continue ;
30 $new_table = $new_prefix . substr( $old_table , strlen( $old_prefix ) ) ;
32 $crs =
$db->queryF(
'SHOW CREATE TABLE '.$old_table ) ;
33 if( !
$db->getRowsNum( $crs ) ) {
34 echo
"error: SHOW CREATE TABLE ($old_table)<br />\n" ;
37 $row_create =
$db->fetchArray( $crs ) ;
38 $create_sql = preg_replace(
"/^CREATE TABLE `$old_table`/" ,
"CREATE TABLE `$new_table`" , $row_create[
'Create Table'] , 1 ) ;
40 $crs =
$db->queryF( $create_sql ) ;
42 echo
"error: CREATE TABLE ($new_table)<br />\n" ;
46 $irs =
$db->queryF(
"INSERT INTO `$new_table` SELECT * FROM `$old_table`" ) ;
48 echo
"error: INSERT INTO ($new_table)<br />\n" ;
60 }
else if( ! empty(
$_POST[
'backup'] ) && ! empty(
$_POST[
'prefix'] ) ) {
62 if( preg_match(
'/[^0-9A-Za-z_-]/' ,
$_POST[
'prefix'] ) ) die(
'wrong prefix' ) ;
65 if ( ! $xoopsGTicket->check(
true ,
'protector_admin' ) ) {
69 $prefix =
$_POST[
'prefix'] ;
73 if( !
$db->getRowsNum(
$srs ) ) die(
"You are not allowed to delete tables" ) ;
77 while( $row_table =
$db->fetchArray(
$srs ) ) {
78 $table = $row_table[
'Name'] ;
79 if( substr( $table , 0 , strlen( $prefix ) + 1 ) !== $prefix .
'_' )
continue ;
80 $drs =
$db->queryF(
"SHOW CREATE TABLE `$table`" ) ;
81 $export_string .=
"\nDROP TABLE IF EXISTS `$table`;\n".mysql_result($drs,0,1).
";\n\n" ;
82 $result = mysql_query(
"SELECT * FROM `$table`" ) ;
83 $fields_cnt = mysql_num_fields(
$result ) ;
84 $field_flags = array();
85 for (
$j = 0;
$j < $fields_cnt;
$j++) {
86 $field_flags[
$j] = mysql_field_flags(
$result ,
$j ) ;
88 $search = array(
"\x00",
"\x0a",
"\x0d",
"\x1a");
89 $replace = array(
'\0',
'\n',
'\r',
'\Z');
91 while( $row = mysql_fetch_row(
$result) ) {
93 for(
$j = 0 ;
$j < $fields_cnt ;
$j ++ ) {
94 $fields_meta = mysql_fetch_field(
$result ,
$j ) ;
96 if (!isset($row[
$j]) || is_null($row[$j])) {
100 } elseif ($fields_meta->numeric && $fields_meta->type !=
'timestamp') {
101 $values[] = $row[
$j];
105 }
else if (stristr($field_flags[$j],
'BINARY')
106 && $fields_meta->type !=
'datetime'
107 && $fields_meta->type !=
'date'
108 && $fields_meta->type !=
'time'
109 && $fields_meta->type !=
'timestamp'
112 if (empty($row[$j]) && $row[$j] !=
'0') {
115 $values[] =
'0x' . bin2hex($row[$j]);
119 $values[] =
'\'' . str_replace($search, $replace, addslashes($row[$j])) .
'\'';
123 $export_string .=
"INSERT INTO `$table` VALUES (" . implode(
', ', $values) .
");\n" ;
131 header(
'Content-Type: Application/octet-stream') ;
132 header(
'Content-Disposition: attachment; filename="'.$prefix.
'_'.date(
'YmdHis').
'.sql"') ;
133 header(
'Content-Length: '.strlen($export_string)) ;
134 set_time_limit( 0 ) ;
135 echo $export_string ;
139 }
else if( ! empty(
$_POST[
'delete'] ) && ! empty(
$_POST[
'prefix'] ) ) {
141 if( preg_match(
'/[^0-9A-Za-z_-]/' ,
$_POST[
'prefix'] ) ) die(
'wrong prefix' ) ;
144 if ( ! $xoopsGTicket->check(
true ,
'protector_admin' ) ) {
148 $prefix =
$_POST[
'prefix'] ;
151 if( $prefix ==
XOOPS_DB_PREFIX ) die(
"You can't drop working tables" ) ;
154 $check_rs =
$db->queryF(
"SELECT * FROM {$prefix}_xoopscomments LIMIT 1" ) ;
155 if( ! $check_rs ) die(
"This is not a prefix for XOOPS" ) ;
159 if( !
$db->getRowsNum(
$srs ) ) die(
"You are not allowed to delete tables" ) ;
161 while( $row_table =
$db->fetchArray(
$srs ) ) {
162 $table = $row_table[
'Name'] ;
163 if( substr( $table , 0 , strlen( $prefix ) + 1 ) !== $prefix .
'_' )
continue ;
164 $drs =
$db->queryF(
"DROP TABLE `$table`" ) ;
176 include dirname(__FILE__).
'/mymenu.php' ;
180 if( !
$db->getRowsNum(
$srs ) ) {
181 die(
"You are not allowed to copy tables" ) ;
189 while( $row_table =
$db->fetchArray(
$srs ) ) {
190 if( substr( $row_table[
"Name"] , -6 ) ===
'_users' ) {
192 'name' => substr( $row_table[
"Name"] , 0 , -6 ) ,
193 'updated' => $row_table[
"Update_time"]
196 $tables[] = $row_table[
"Name"] ;
202 <h3>"._AM_H3_PREFIXMAN.
"</h3>
203 <table class='outer' width='95%'>
217 $has_xoopscomments =
false ;
219 if( $table == $prefix[
'name'] .
'_xoopscomments' ) $has_xoopscomments =
true ;
220 if( substr( $table , 0 , strlen( $prefix[
'name'] ) + 1 ) === $prefix[
'name'] .
'_' ) $table_count ++ ;
224 if( ! $has_xoopscomments ) continue ;
226 $prefix4disp = htmlspecialchars( $prefix[
'name'] , ENT_QUOTES ) ;
227 $ticket_input = $xoopsGTicket->getTicketHtml( __LINE__ , 1800 ,
'protector_admin' ) ;
231 $style_append =
'background-color:#FFFFFF' ;
233 $del_button =
"<input type='submit' name='delete' value='delete' onclick='return confirm(\""._AM_CONFIRM_DELETE.
"\")' />" ;
239 <td class='odd' style='$style_append;'>$prefix4disp</td>
240 <td class='odd' style='text-align:right;$style_append;'>$table_count</td>
241 <td class='odd' style='text-align:right;$style_append;'>{$prefix['updated']}</td>
242 <td class='odd' style='text-align:center;$style_append;' nowrap='nowrap'>
243 <form action='?page=prefix_manager' method='POST' style='margin:0px;'>
245 <input type='hidden' name='old_prefix' value='$prefix4disp' />
246 <input type='text' name='new_prefix' size='8' maxlength='16' />
247 <input type='submit' name='copy' value='copy' />
250 <td class='odd' style='text-align:center;$style_append;'>
251 <form action='?page=prefix_manager' method='POST' style='margin:0px;'>
253 <input type='hidden' name='prefix' value='$prefix4disp' />
255 <input type='submit' name='backup' value='backup' onclick='this.form.target=\"_blank\"' />
269 if( ! empty(
$_SESSION[
'protector_logger'] ) ) {
271 $_SESSION[
'protector_logger'] =
'' ;
272 unset( $_SESSION[
'protector_logger'] ) ;