diff options
Diffstat (limited to 'admin')
-rw-r--r-- | admin/cat_list.php | 135 | ||||
-rw-r--r-- | admin/cat_modify.php | 3 | ||||
-rw-r--r-- | admin/group_perm.php | 3 | ||||
-rw-r--r-- | admin/include/functions.php | 2 | ||||
-rw-r--r-- | admin/infos_images.php | 4 | ||||
-rw-r--r-- | admin/picture_modify.php | 6 | ||||
-rw-r--r-- | admin/remote_site.php | 80 | ||||
-rw-r--r-- | admin/update.php | 131 | ||||
-rw-r--r-- | admin/user_perm.php | 3 | ||||
-rw-r--r-- | admin/user_search.php | 18 | ||||
-rw-r--r-- | admin/waiting.php | 2 |
11 files changed, 245 insertions, 142 deletions
diff --git a/admin/cat_list.php b/admin/cat_list.php index 72862b484..d92575fe8 100644 --- a/admin/cat_list.php +++ b/admin/cat_list.php @@ -59,58 +59,88 @@ else if (isset($_POST['submit'])) if (!count($errors)) { - $parent_id = !empty($_GET['parent_id'])?$_GET['parent_id']:'NULL'; - // As we don't create a virtual category every day, let's do (far) too - // much queries - - // we have then to add the virtual category - $query = ' -INSERT INTO '.CATEGORIES_TABLE.' - (name,id_uppercat,rank,site_id) - VALUES - (\''.$_POST['virtual_name'].'\','.$parent_id.','.$_POST['rank'].',NULL) -;'; - pwg_query($query); - - // And last we update the uppercats - $query = ' -SELECT MAX(id) - FROM '.CATEGORIES_TABLE.' -;'; - $my_id = array_pop(mysql_fetch_array(pwg_query($query))); + $parent_id = !empty($_GET['parent_id'])?$_GET['parent_id']:'NULL'; if ($parent_id != 'NULL') { $query = ' -SELECT uppercats, global_rank +SELECT id,uppercats,global_rank,visible,status FROM '.CATEGORIES_TABLE.' WHERE id = '.$parent_id.' ;'; - $result = pwg_query($query); - $row = mysql_fetch_array($result); - - $parent_uppercats = $row['uppercats']; - $parent_global_rank = $row['global_rank']; + $row = mysql_fetch_array(pwg_query($query)); + $parent = array('id' => $row['id'], + 'uppercats' => $row['uppercats'], + 'visible' => $row['visible'], + 'status' => $row['status'], + 'global_rank' => $row['global_rank']); } - $query = ' -UPDATE '.CATEGORIES_TABLE.' -'; - if (!empty($parent_uppercats)) + $insert = array(); + $insert{'name'} = $_POST['virtual_name']; + $insert{'rank'} = $_POST['rank']; + $insert{'commentable'} = $conf['newcat_default_commentable']; + $insert{'uploadable'} = $conf['newcat_default_uploadable']; + + if (isset($parent)) { - $query.= " SET uppercats = CONCAT('".$parent_uppercats."',',',id)"; + $insert{'id_uppercat'} = $parent{'id'}; + // at creation, must a category be visible or not ? Warning : if + // the parent category is invisible, the category is automatically + // create invisible. (invisible = locked) + if ('false' == $parent['visible']) + { + $insert{'visible'} = 'false'; + } + else + { + $insert{'visible'} = $conf['newcat_default_visible']; + } + // at creation, must a category be public or private ? Warning : + // if the parent category is private, the category is + // automatically create private. + if ('private' == $parent['status']) + { + $insert{'status'} = 'private'; + } + else + { + $insert{'status'} = $conf['newcat_default_status']; + } } else { - $query.= ' SET uppercats = id'; + $insert{'visible'} = $conf['newcat_default_visible']; + $insert{'status'} = $conf['newcat_default_status']; } - if (!empty($parent_global_rank)) + + $inserts = array($insert); + + // we have then to add the virtual category + $dbfields = array('site_id','name','id_uppercat','rank','commentable', + 'uploadable','visible','status'); + mass_inserts(CATEGORIES_TABLE, $dbfields, $inserts); + + // And last we update the uppercats + $query = ' +SELECT MAX(id) + FROM '.CATEGORIES_TABLE.' +;'; + $my_id = array_pop(mysql_fetch_array(pwg_query($query))); + + $query = ' +UPDATE '.CATEGORIES_TABLE; + if (isset($parent)) { - $query.= " , global_rank = CONCAT('".$parent_global_rank."','.',rank)"; + $query.= " + SET uppercats = CONCAT('".$parent['uppercats']."',',',id) + , global_rank = CONCAT('".$parent['global_rank']."','.',rank)"; } else { - $query.= ' , uppercats = id'; + $query.= ' + SET uppercats = id + , global_rank = id'; } $query.= ' WHERE id = '.$my_id.' @@ -142,23 +172,22 @@ $result = pwg_query($query); while ($row = mysql_fetch_assoc($result)) { $categories[$row['rank']] = $row; + $categories[$row['rank']]['nb_subcats'] = 0; } // +-----------------------------------------------------------------------+ // | Navigation path | // +-----------------------------------------------------------------------+ if (isset($_GET['parent_id'])) { - $separator = ' <span style="font-size:15px">→</span> '; $base_url = PHPWG_ROOT_PATH.'admin.php?page=cat_list'; $navigation = '<a class="" href="'.add_session_id($base_url).'">'; $navigation.= $lang['home']; $navigation.= '</a>'; - $navigation.= $separator; + $navigation.= $conf['level_separator']; $current_category = get_cat_info($_GET['parent_id']); $navigation.= get_cat_display_name($current_category['name'], - $separator, $base_url.'&parent_id=', false); } @@ -337,7 +366,25 @@ if (count($infos) != 0) // +-----------------------------------------------------------------------+ // | Categories display | // +-----------------------------------------------------------------------+ -while (list($id,$category) = each($categories)) +$ranks = array(); +foreach ($categories as $category) +{ + $ranks[$category['id']] = $category['rank']; +} + +$query = ' +SELECT id_uppercat, COUNT(*) AS nb_subcats + FROM '. CATEGORIES_TABLE.' + WHERE id_uppercat IN ('.implode(',', array_keys($ranks)).') + GROUP BY id_uppercat +;'; +$result = pwg_query($query); +while ($row = mysql_fetch_array($result)) +{ + $categories[$ranks[$row['id_uppercat']]]['nb_subcats'] = $row['nb_subcats']; +} + +foreach ($categories as $category) { $images_folder = PHPWG_ROOT_PATH.'template/'; $images_folder.= $user['template'].'/admin/images'; @@ -356,17 +403,7 @@ while (list($id,$category) = each($categories)) } else { - // (Gweltas) May be should we have to introduce a computed field in the - // table to avoid this query -> (z0rglub) no because the number of - // sub-categories depends on permissions - $query = ' -SELECT COUNT(id) AS nb_sub_cats - FROM '. CATEGORIES_TABLE.' - WHERE id_uppercat = '.$category['id'].' -;'; - $row = mysql_fetch_array(pwg_query($query)); - - if ($row['nb_sub_cats'] > 0) + if ($category['nb_subcats'] > 0) { $image_src = $images_folder.'/icon_subfolder.gif'; } diff --git a/admin/cat_modify.php b/admin/cat_modify.php index c230fcf94..26bd0de50 100644 --- a/admin/cat_modify.php +++ b/admin/cat_modify.php @@ -103,11 +103,10 @@ foreach (array('comment','dir','site_id') as $nullable) // Navigation path $url = PHPWG_ROOT_PATH.'admin.php?page=cat_list&parent_id='; $navigation = '<a class="" href="'.add_session_id(PHPWG_ROOT_PATH.'admin.php?page=cat_list').'">'; -$navigation.= $lang['home'].'</a> <span style="font-size:15px">→</span>'; +$navigation.= $lang['home'].'</a>'.$conf['level_separator']; $navigation.= get_cat_display_name_cache( $category['uppercats'], - ' <span style="font-size:15px">→</span>', $url); $form_action = PHPWG_ROOT_PATH.'admin.php?page=cat_modify&cat_id='.$_GET['cat_id']; diff --git a/admin/group_perm.php b/admin/group_perm.php index 9725eafab..c60ed7420 100644 --- a/admin/group_perm.php +++ b/admin/group_perm.php @@ -104,8 +104,7 @@ while ( $row = mysql_fetch_array( $result ) ) } // category name $cat_infos = get_cat_info( $row['id'] ); - $name = get_cat_display_name( $cat_infos['name'],' > ', - 'font-weight:bold;' ); + $name = get_cat_display_name($cat_infos['name']); $vtp->setVar( $sub, 'category.name', $name ); // any subcat forbidden for this group ? if ( $is_group_allowed == 2 ) diff --git a/admin/include/functions.php b/admin/include/functions.php index 467a498f6..1191f1f6f 100644 --- a/admin/include/functions.php +++ b/admin/include/functions.php @@ -788,7 +788,7 @@ function is_user_allowed( $category_id, $restrictions ) function get_category_directories( $basedir ) { $sub_dirs = array(); - + if ( $opendir = opendir( $basedir ) ) { while ( $file = readdir( $opendir ) ) diff --git a/admin/infos_images.php b/admin/infos_images.php index 9c055a830..ef02c91b7 100644 --- a/admin/infos_images.php +++ b/admin/infos_images.php @@ -248,9 +248,7 @@ if (isset($page['cat'])) // Navigation path $current_category = get_cat_info($_GET['cat_id']); $url = PHPWG_ROOT_PATH.'admin.php?page=infos_images&cat_id='; - $category_path = get_cat_display_name($current_category['name'], - '->', - $url); + $category_path = get_cat_display_name($current_category['name'], $url); $form_action = PHPWG_ROOT_PATH.'admin.php'; $form_action.= '?page=infos_images&cat_id='.$_GET['cat_id']; diff --git a/admin/picture_modify.php b/admin/picture_modify.php index 647fdede4..7f3677f97 100644 --- a/admin/picture_modify.php +++ b/admin/picture_modify.php @@ -162,10 +162,10 @@ $url_img = PHPWG_ROOT_PATH.'picture.php?image_id='.$_GET['image_id']; $url_img .= '&cat='.$row['storage_category_id']; $date = isset($_POST['date_creation']) && empty($errors) ?$_POST['date_creation']:date_convert_back(@$row['date_creation']); - + +$url = PHPWG_ROOT_PATH.'admin.php?page=cat_modify&cat_id='; $storage_category = get_cat_display_name_cache($row['uppercats'], - ' → ', - '', + $url, false); //----------------------------------------------------- template initialization $template->set_filenames(array('picture_modify'=>'admin/picture_modify.tpl')); diff --git a/admin/remote_site.php b/admin/remote_site.php index 6f0279f21..66d6d6a58 100644 --- a/admin/remote_site.php +++ b/admin/remote_site.php @@ -176,7 +176,7 @@ function update_remote_site($listing_file, $site_id) */ function insert_remote_category($xml_content, $site_id, $id_uppercat, $level) { - global $counts, $removes; + global $counts, $removes, $conf; $uppercats = ''; // 0. retrieving informations on the category to display @@ -184,15 +184,18 @@ function insert_remote_category($xml_content, $site_id, $id_uppercat, $level) if (is_numeric($id_uppercat)) { $query = ' -SELECT name,uppercats,dir +SELECT id,name,uppercats,dir,status,visible FROM '.CATEGORIES_TABLE.' WHERE id = '.$id_uppercat.' ;'; $row = mysql_fetch_array(pwg_query($query)); + $parent = array('id' => $row['id'], + 'name' => $row['name'], + 'dir' => $row['dir'], + 'uppercats' => $row['uppercats'], + 'visible' => $row['visible'], + 'status' => $row['status']); - $uppercats = $row['uppercats']; - $name = $row['name']; - insert_remote_element($xml_content, $id_uppercat); } @@ -224,6 +227,39 @@ SELECT name,uppercats,dir // array of new categories to insert $inserts = array(); + // calculate default value at category creation + $create_values = array(); + if (isset($parent)) + { + // at creation, must a category be visible or not ? Warning : if + // the parent category is invisible, the category is automatically + // create invisible. (invisible = locked) + if ('false' == $parent['visible']) + { + $create_values{'visible'} = 'false'; + } + else + { + $create_values{'visible'} = $conf['newcat_default_visible']; + } + // at creation, must a category be public or private ? Warning : + // if the parent category is private, the category is + // automatically create private. + if ('private' == $parent['status']) + { + $create_values{'status'} = 'private'; + } + else + { + $create_values{'status'} = $conf['newcat_default_status']; + } + } + else + { + $create_values{'visible'} = $conf['newcat_default_visible']; + $create_values{'status'} = $conf['newcat_default_status']; + } + foreach ($xml_dirs as $xml_dir) { // 5. Is the category already existing ? we create a subcat if not @@ -239,9 +275,13 @@ SELECT name,uppercats,dir $insert{'name'} = $name; $insert{'site_id'} = $site_id; $insert{'uppercats'} = 'undef'; - if (is_numeric($id_uppercat)) + $insert{'commentable'} = $conf['newcat_default_commentable']; + $insert{'uploadable'} = 'false'; + $insert{'status'} = $create_values{'status'}; + $insert{'visible'} = $create_values{'visible'}; + if (isset($parent)) { - $insert{'id_uppercat'} = $id_uppercat; + $insert{'id_uppercat'} = $parent['id']; } array_push($inserts, $insert); } @@ -251,31 +291,25 @@ SELECT name,uppercats,dir if (count($inserts) > 0) { // inserts all found categories - $dbfields = array('dir','name','site_id','uppercats','id_uppercat'); + $dbfields = array('dir','name','site_id','uppercats','id_uppercat', + 'commentable','uploadable','status','visible'); mass_inserts(CATEGORIES_TABLE, $dbfields, $inserts); $counts{'new_categories'}+= count($inserts); // updating uppercats field $query = ' -UPDATE '.CATEGORIES_TABLE.' - SET uppercats = '; - if ($uppercats != '') - { - $query.= "CONCAT('".$uppercats."',',',id)"; - } - else - { - $query.= 'id'; - } - $query.= ' - WHERE id_uppercat '; - if (!is_numeric($id_uppercat)) +UPDATE '.CATEGORIES_TABLE; + if (isset($parent)) { - $query.= 'IS NULL'; + $query.= " + SET uppercats = CONCAT('".$parent['uppercats']."',',',id) + WHERE id_uppercat = ".$id_uppercat; } else { - $query.= '= '.$id_uppercat; + $query.= ' + SET uppercats = id + WHERE id_uppercat IS NULL'; } $query.= ' ;'; diff --git a/admin/update.php b/admin/update.php index e540065e2..b59f6e7b5 100644 --- a/admin/update.php +++ b/admin/update.php @@ -47,24 +47,30 @@ function insert_local_category($id_uppercat) $cat_directory = PHPWG_ROOT_PATH.'galleries'; if (is_numeric($id_uppercat)) { - $query = 'SELECT name,uppercats,dir FROM '.CATEGORIES_TABLE; - $query.= ' WHERE id = '.$id_uppercat; - $query.= ';'; - $row = mysql_fetch_array( pwg_query( $query)); - $uppercats = $row['uppercats']; - $name = $row['name']; - $dir = $row['dir']; + $query = ' +SELECT id,name,uppercats,dir,visible,status + FROM '.CATEGORIES_TABLE.' + WHERE id = '.$id_uppercat.' +;'; + $row = mysql_fetch_array(pwg_query($query)); + $parent = array('id' => $row['id'], + 'name' => $row['name'], + 'dir' => $row['dir'], + 'uppercats' => $row['uppercats'], + 'visible' => $row['visible'], + 'status' => $row['status']); - $upper_array = explode( ',', $uppercats); + $upper_array = explode( ',', $parent['uppercats']); $local_dir = ''; $database_dirs = array(); $query = ' -SELECT id,dir FROM '.CATEGORIES_TABLE.' - WHERE id IN ('.$uppercats.') +SELECT id,dir + FROM '.CATEGORIES_TABLE.' + WHERE id IN ('.$parent['uppercats'].') ;'; - $result = pwg_query( $query); + $result = pwg_query($query); while ($row = mysql_fetch_array($result)) { $database_dirs[$row['id']] = $row['dir']; @@ -78,8 +84,8 @@ SELECT id,dir FROM '.CATEGORIES_TABLE.' // 1. display the category name to update $output = '<ul class="menu">'; - $output.= '<li><strong>'.$name.'</strong>'; - $output.= ' [ '.$dir.' ]'; + $output.= '<li><strong>'.$parent['name'].'</strong>'; + $output.= ' [ '.$parent['dir'].' ]'; $output.= '</li>'; // 2. we search pictures of the category only if the update is for all @@ -94,7 +100,8 @@ SELECT id,dir FROM '.CATEGORIES_TABLE.' $sub_category_dirs = array(); $query = ' -SELECT id,dir FROM '.CATEGORIES_TABLE.' +SELECT id,dir + FROM '.CATEGORIES_TABLE.' WHERE site_id = 1 '; if (!is_numeric($id_uppercat)) @@ -131,6 +138,39 @@ SELECT id,dir FROM '.CATEGORIES_TABLE.' // array of new categories to insert $inserts = array(); + + // calculate default value at category creation + $create_values = array(); + if (isset($parent)) + { + // at creation, must a category be visible or not ? Warning : if + // the parent category is invisible, the category is automatically + // create invisible. (invisible = locked) + if ('false' == $parent['visible']) + { + $create_values{'visible'} = 'false'; + } + else + { + $create_values{'visible'} = $conf['newcat_default_visible']; + } + // at creation, must a category be public or private ? Warning : + // if the parent category is private, the category is + // automatically create private. + if ('private' == $parent['status']) + { + $create_values{'status'} = 'private'; + } + else + { + $create_values{'status'} = $conf['newcat_default_status']; + } + } + else + { + $create_values{'visible'} = $conf['newcat_default_visible']; + $create_values{'status'} = $conf['newcat_default_status']; + } foreach ($fs_subdirs as $fs_subdir) { @@ -139,22 +179,27 @@ SELECT id,dir FROM '.CATEGORIES_TABLE.' $category_id = array_search($fs_subdir, $sub_category_dirs); if (!is_numeric($category_id)) { + $insert = array(); + if (preg_match('/^[a-zA-Z0-9-_.]+$/', $fs_subdir)) { $name = str_replace('_', ' ', $fs_subdir); - $value = "('".$fs_subdir."','".$name."',1"; - if (!is_numeric($id_uppercat)) - { - $value.= ',NULL'; - } - else + $insert{'dir'} = $fs_subdir; + $insert{'name'} = $name; + $insert{'site_id'} = 1; + $insert{'uppercats'} = 'undef'; + $insert{'commentable'} = $conf['newcat_default_commentable']; + $insert{'uploadable'} = $conf['newcat_default_uploadable']; + $insert{'status'} = $create_values{'status'}; + $insert{'visible'} = $create_values{'visible'}; + + if (isset($parent)) { - $value.= ','.$id_uppercat; + $insert{'id_uppercat'} = $parent['id']; } - $value.= ",'undef'"; - $value.= ')'; - array_push($inserts, $value); + + array_push($inserts, $insert); } else { @@ -167,37 +212,27 @@ SELECT id,dir FROM '.CATEGORIES_TABLE.' // we have to create the category if (count($inserts) > 0) { - $query = ' -INSERT INTO '.CATEGORIES_TABLE.' - (dir,name,site_id,id_uppercat,uppercats) VALUES -'; - $query.= implode(',', $inserts); - $query.= ' -;'; - pwg_query($query); - + $dbfields = array( + 'dir','name','site_id','id_uppercat','uppercats','commentable', + 'uploadable','visible','status' + ); + mass_inserts(CATEGORIES_TABLE, $dbfields, $inserts); + $counts['new_categories']+= count($inserts); // updating uppercats field $query = ' -UPDATE '.CATEGORIES_TABLE.' - SET uppercats = '; - if ($uppercats != '') - { - $query.= "CONCAT('".$uppercats."',',',id)"; - } - else - { - $query.= 'id'; - } - $query.= ' - WHERE id_uppercat '; - if (!is_numeric($id_uppercat)) +UPDATE '.CATEGORIES_TABLE; + if (isset($parent)) { - $query.= 'IS NULL'; + $query.= " + SET uppercats = CONCAT('".$parent['uppercats']."',',',id) + WHERE id_uppercat = ".$parent['id']; } else { - $query.= '= '.$id_uppercat; + $query.= ' + SET uppercats = id + WHERE id_uppercat IS NULL'; } $query.= ' ;'; diff --git a/admin/user_perm.php b/admin/user_perm.php index 415a95334..e2fd31d1e 100644 --- a/admin/user_perm.php +++ b/admin/user_perm.php @@ -220,8 +220,7 @@ while ( $row = mysql_fetch_array( $result ) ) } // category name $cat_infos = get_cat_info( $row['id'] ); - $name = get_cat_display_name( $cat_infos['name'],' > ', - 'font-weight:bold;' ); + $name = get_cat_display_name($cat_infos['name']); $vtp->setVar( $sub, 'category.name', $name ); // usergroups if ( count( $usergroups ) > 0 ) diff --git a/admin/user_search.php b/admin/user_search.php index 220928992..8087e31e0 100644 --- a/admin/user_search.php +++ b/admin/user_search.php @@ -102,14 +102,16 @@ else $is_user_allowed = is_user_allowed( $row['id'], $restrictions ); $url = PHPWG_ROOT_PATH.'admin.php?page=cat_perm&cat_id='.$row['id']; $cat_infos = get_cat_info( $row['id'] ); - $template->assign_block_vars('permission.category',array( - 'CAT_NAME'=> get_cat_display_name($cat_infos['name'],' > ', 'font-weight:bold;' ), - 'CAT_ID'=>$row['id'], - 'AUTH_YES'=>!$is_user_allowed?'checked="checked"':'', - 'AUTH_NO' =>$is_user_allowed?'checked="checked"':'', - 'CAT_URL'=>add_session_id($url) - )); - + $template->assign_block_vars( + 'permission.category', + array( + 'CAT_NAME'=> get_cat_display_name($cat_infos['name']), + 'CAT_ID'=>$row['id'], + 'AUTH_YES'=>!$is_user_allowed?'checked="checked"':'', + 'AUTH_NO' =>$is_user_allowed?'checked="checked"':'', + 'CAT_URL'=>add_session_id($url) + )); + // any subcat forbidden for this user ? if ( $is_user_allowed == 2 ) { diff --git a/admin/waiting.php b/admin/waiting.php index 4607cc002..dadb9052c 100644 --- a/admin/waiting.php +++ b/admin/waiting.php @@ -113,7 +113,7 @@ while ( $row = mysql_fetch_array( $result ) ) $cat_names[$row['storage_category_id']]['dir'] = PHPWG_ROOT_PATH.get_complete_dir( $row['storage_category_id'] ); $cat_names[$row['storage_category_id']]['display_name'] = - get_cat_display_name( $cat['name'], ' > ', 'font-weight:bold;' ); + get_cat_display_name($cat['name']); } $preview_url = PHPWG_ROOT_PATH.$cat_names[$row['storage_category_id']]['dir'].$row['file']; $class='row1'; |