Changeset 269
- Timestamp:
- Jan 11, 2004, 12:17:24 AM (21 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/release-1_3/admin/update.php
r259 r269 20 20 include_once( './include/isadmin.inc.php' ); 21 21 //------------------------------------------------------------------- functions 22 function insert_local_category( $ cat_id)22 function insert_local_category( $id_uppercat ) 23 23 { 24 24 global $conf, $page, $user, $lang; 25 25 26 26 $uppercats = ''; 27 27 … … 29 29 $cat_directory = '../galleries'; 30 30 31 if ( is_numeric( $cat_id ) ) 32 { 33 $cat_directory.= '/'.get_local_dir( $cat_id ); 34 $result = get_cat_info( $cat_id ); 35 $uppercats = $result['uppercats']; 31 if ( is_numeric( $id_uppercat ) ) 32 { 33 $query = 'SELECT name,uppercats,dir'; 34 $query.= ' FROM '.PREFIX_TABLE.'categories'; 35 $query.= ' WHERE id = '.$id_uppercat; 36 $query.= ';'; 37 $row = mysql_fetch_array( mysql_query( $query ) ); 38 $uppercats = $row['uppercats']; 39 $name = $row['name']; 40 $dir = $row['dir']; 41 42 $upper_array = explode( ',', $uppercats ); 43 44 $local_dir = ''; 45 46 $database_dirs = array(); 47 $query = 'SELECT id,dir'; 48 $query.= ' FROM '.PREFIX_TABLE.'categories'; 49 $query.= ' WHERE id IN ('.$uppercats.')'; 50 $query.= ';'; 51 $result = mysql_query( $query ); 52 while( $row = mysql_fetch_array( $result ) ) 53 { 54 $database_dirs[$row['id']] = $row['dir']; 55 } 56 foreach ( $upper_array as $id ) { 57 $local_dir.= $database_dirs[$id].'/'; 58 } 59 60 $cat_directory.= '/'.$local_dir; 61 36 62 // 1. display the category name to update 37 63 $src = '../template/'.$user['template'].'/admin/images/puce.gif'; 38 64 $output = '<img src="'.$src.'" alt=">" />'; 39 $output.= '<span style="font-weight:bold;">'; 40 $output.= $result['name'][count($result['name'])-1]; 41 $output.= '</span>'; 42 $output.= ' [ '.$result['dir'].' ]'; 65 $output.= '<span style="font-weight:bold;">'.$name.'</span>'; 66 $output.= ' [ '.$dir.' ]'; 43 67 $output.= '<div class="retrait">'; 44 68 … … 47 71 if ( isset( $page['cat'] ) or $_GET['update'] == 'all' ) 48 72 { 49 $output.= insert_local_image( $cat_directory, $cat_id ); 50 } 51 } 52 53 // 3. we have to remove the categories of the database not present anymore 54 $query = 'SELECT id'; 73 $output.= insert_local_image( $cat_directory, $id_uppercat ); 74 } 75 } 76 77 $sub_dirs = get_category_directories( $cat_directory ); 78 79 $sub_category_dirs = array(); 80 $query = 'SELECT id,dir'; 55 81 $query.= ' FROM '.PREFIX_TABLE.'categories'; 56 82 $query.= ' WHERE site_id = 1'; 57 if ( !is_numeric( $cat_id ) ) $query.= ' AND id_uppercat IS NULL'; 58 else $query.= ' AND id_uppercat = '.$cat_id; 83 if (!is_numeric($id_uppercat)) $query.= ' AND id_uppercat IS NULL'; 84 else $query.= ' AND id_uppercat = '.$id_uppercat; 85 $query.= ' AND dir IS NOT NULL'; // virtual categories not taken 59 86 $query.= ';'; 60 87 $result = mysql_query( $query ); 61 88 while ( $row = mysql_fetch_array( $result ) ) 62 89 { 63 // retrieving the directory 64 $rep = '../galleries/'.get_local_dir( $row['id'] ); 65 // is the directory present ? 66 if ( !is_dir( $rep ) ) delete_category( $row['id'] ); 67 } 68 // 4. retrieving the sub-directories 69 $subdirs = array(); 70 $dirs = ''; 71 if ( $opendir = opendir( $cat_directory ) ) 72 { 73 while ( $file = readdir( $opendir ) ) 74 { 75 if ( $file != '.' 76 and $file != '..' 77 and is_dir( $cat_directory.'/'.$file ) 78 and $file != 'thumbnail' ) 79 { 80 if ( preg_match( '/^[a-zA-Z0-9-_.]+$/', $file ) ) 81 array_push( $subdirs, $file ); 82 else 83 { 84 $output.= '<span style="color:red;">"'.$file.'" : '; 85 $output.= $lang['update_wrong_dirname'].'</span><br />'; 86 // if the category even exists (from a previous release of 87 // PhpWebGallery), we keep it in our $subdirs array 88 $query = 'SELECT id'; 89 $query.= ' FROM '.PREFIX_TABLE.'categories'; 90 $query.= ' WHERE site_id = 1'; 91 $query.= " AND dir = '".$file."'"; 92 $query.= ' AND id_uppercat'; 93 if ( !is_numeric( $cat_id ) ) $query.= ' IS NULL'; 94 else $query.= ' = '.$cat_id; 95 $query.= ';'; 96 $result = mysql_query( $query ); 97 if ( mysql_num_rows( $result ) != 0 ) 98 { 99 array_push( $subdirs, $file ); 100 } 101 } 102 } 103 } 104 } 105 foreach ( $subdirs as $subdir ) { 90 $id = intval($row['id']); 91 $sub_category_dirs[$id] = $row['dir']; 92 } 93 94 // 3. we have to remove the categories of the database not present anymore 95 foreach ( $sub_category_dirs as $id => $dir ) { 96 if ( !in_array( $dir, $sub_dirs ) ) delete_category( $id ); 97 } 98 99 foreach ( $sub_dirs as $sub_dir ) { 106 100 // 5. Is the category already existing ? we create a subcat if not 107 101 // existing 108 $category_id = ''; 109 $query = 'SELECT id'; 110 $query.= ' FROM '.PREFIX_TABLE.'categories'; 111 $query.= ' WHERE site_id = 1'; 112 $query.= " AND dir = '".$subdir."'"; 113 $query.= ' AND id_uppercat'; 114 if ( !is_numeric( $cat_id ) ) $query.= ' IS NULL'; 115 else $query.= ' = '.$cat_id; 116 $query.= ';'; 117 $result = mysql_query( $query ); 118 if ( mysql_num_rows( $result ) == 0 ) 119 { 120 $name = str_replace( '_', ' ', $subdir ); 121 // we have to create the category 122 $query = 'INSERT INTO '.PREFIX_TABLE.'categories'; 123 $query.= ' (dir,name,site_id,id_uppercat) VALUES'; 124 $query.= " ('".$subdir."','".$name."',1"; 125 if ( !is_numeric( $cat_id ) ) $query.= ',NULL'; 126 else $query.= ",'".$cat_id."'"; 127 $query.= ');'; 128 mysql_query( $query ); 129 $category_id = mysql_insert_id(); 130 } 131 else 132 { 133 // we get the already registered id 134 $row = mysql_fetch_array( $result ); 135 $category_id = $row['id']; 102 $category_id = array_search( $sub_dir, $sub_category_dirs ); 103 if ( !is_numeric( $category_id ) ) 104 { 105 if ( preg_match( '/^[a-zA-Z0-9-_.]+$/', $sub_dir ) ) 106 { 107 $name = str_replace( '_', ' ', $sub_dir ); 108 // we have to create the category 109 $query = 'INSERT INTO '.PREFIX_TABLE.'categories'; 110 $query.= ' (dir,name,site_id,id_uppercat,uppercats) VALUES'; 111 $query.= " ('".$sub_dir."','".$name."',1"; 112 if ( !is_numeric( $id_uppercat ) ) $query.= ',NULL'; 113 else $query.= ','.$id_uppercat; 114 $query.= ",'undef'"; 115 $query.= ');'; 116 mysql_query( $query ); 117 $category_id = mysql_insert_id(); 118 // updating uppercats field 119 $query = 'UPDATE '.PREFIX_TABLE.'categories'; 120 $query.= " SET uppercats = '".$uppercats; 121 if ( $uppercats != '' ) $query.= ','; 122 $query.= $category_id; 123 $query.= "'"; 124 $query.= ';'; 125 mysql_query( $query ); 126 } 127 else 128 { 129 $output.= '<span style="color:red;">"'.$sub_dir.'" : '; 130 $output.= $lang['update_wrong_dirname'].'</span><br />'; 131 } 136 132 } 137 133 // 6. recursive call 138 $output.= insert_local_category( $category_id ); 134 if ( is_numeric( $category_id ) ) 135 { 136 $output.= insert_local_category( $category_id ); 137 } 139 138 } 140 139 141 if ( is_numeric( $ cat_id) )140 if ( is_numeric( $id_uppercat ) ) 142 141 { 143 142 $output.= '</div>'; … … 585 584 else 586 585 { 586 $start = get_moment(); 587 587 $count_new = 0; 588 588 $count_deleted = 0; … … 596 596 $categories = insert_local_category( 'NULL' ); 597 597 } 598 $end = get_moment(); 599 echo get_elapsed_time( $start, $end ).' for update <br />'; 598 600 $vtp->setVar( $sub, 'local_update.categories', $categories ); 599 601 $vtp->setVar( $sub, 'local_update.count_new', $count_new );
Note: See TracChangeset
for help on using the changeset viewer.