function photoplog_doadd_doedit_worker($new_fielddata, $catid, $fieldtype, $current_fielddata) { global $vbulletin, $vbphrase; $doadd = empty($current_fielddata); $new_fielddata_name = $doadd ? trim($new_fielddata['name']) : $current_fielddata['name']; $new_fielddata_groupid = $doadd ? intval(trim($new_fielddata['groupid'])) : $current_fielddata['groupid']; $all_groups = photoplog_get_all_groups(); if ($doadd) { if ($new_fielddata_groupid) { if ($new_fielddata_name) { if ($all_groups[$new_fielddata_groupid] != $new_fielddata_name) { print_stop_message('generic_error_x', $vbphrase['photoplog_bad_field_name_inconsistent']); } } else { $new_fielddata_name = trim($all_groups[$new_fielddata_groupid]); } } else { if (in_array($new_fielddata_name, $all_groups)) { foreach ($all_groups as $gid => $gname) { if ($new_fielddata_name == $gname) { $new_fielddata_groupid = intval($gid); break; } } } } } $new_fielddata_title = trim($new_fielddata['title']); $new_fielddata_description = trim($new_fielddata['description']); $new_fielddata_maxlength = intval(trim($new_fielddata['maxlength'])); $new_fielddata_default = trim($new_fielddata['default']); $new_fielddata_size = intval(trim($new_fielddata['size'])); $new_fielddata_height = intval(trim($new_fielddata['height'])); $new_fielddata_options = trim($new_fielddata['options']); $new_fielddata_options = explode("\n", $new_fielddata_options); if (is_array($new_fielddata_options)) { foreach ($new_fielddata_options as $option_key => $option_value) { $new_fielddata_options[$option_key] = trim($option_value); } } else { $new_fielddata_options = array(); } $new_fielddata_limit = intval(trim($new_fielddata['limit'])); $new_fielddata_perline = intval(trim($new_fielddata['perline'])); $new_fielddata_active = intval(trim($new_fielddata['active'])); $new_fielddata_hidden = intval(trim($new_fielddata['hidden'])); $new_fielddata_required = intval(trim($new_fielddata['required'])); $new_fielddata_inherited = intval(trim($new_fielddata['inherited'])); $info = array(); $info['type'] = $fieldtype; if (vbstrlen($new_fielddata_name) < 3 || vbstrlen($new_fielddata_name) > 50) { print_stop_message('generic_error_x', construct_phrase($vbphrase['photoplog_bad_field_name'], 3, 50)); } if (vbstrlen($new_fielddata_title) > 50) { print_stop_message('generic_error_x', construct_phrase($vbphrase['photoplog_bad_field_title'], 50)); } else { $info['title'] = $new_fielddata_title; } if (vbstrlen($new_fielddata_description) > 250) { print_stop_message('generic_error_x', construct_phrase($vbphrase['photoplog_bad_field_description'], 250)); } else { $info['description'] = $new_fielddata_description; } if ($fieldtype <= 1) { if ($new_fielddata_maxlength < 1 || $new_fielddata_maxlength > 1024) { print_stop_message('generic_error_x', construct_phrase($vbphrase['photoplog_bad_field_maxlength'], 1, 1024)); } else { $info['maxlength'] = $new_fielddata_maxlength; } if (vbstrlen($new_fielddata_default) > $new_fielddata_maxlength) { print_stop_message('generic_error_x', $vbphrase['photoplog_bad_field_default_exceeds_maxlength']); } else { $info['default'] = $new_fielddata_default; } if ($new_fielddata_size < 1 || $new_fielddata_size > 100) { print_stop_message('generic_error_x', construct_phrase($vbphrase['photoplog_bad_field_size'], 1, 100)); } else { $info['size'] = $new_fielddata_size; } } if ($fieldtype >= 2) { if (count($new_fielddata_options) < 1 || count($new_fielddata_options) > 256) { print_stop_message('generic_error_x', construct_phrase($vbphrase['photoplog_bad_field_options'], 1, 256)); } else { $info['options'] = $new_fielddata_options; } if (!($new_fielddata_default == '0' || $new_fielddata_default == '1')) { print_stop_message('generic_error_x', $vbphrase['photoplog_bad_field_default']); } else { $info['default'] = $new_fielddata_default; } } if ($fieldtype == 1) { if ($new_fielddata_height < 2 || $new_fielddata_height > 1000) { print_stop_message('generic_error_x', construct_phrase($vbphrase['photoplog_bad_field_height'], 2, 1000)); } else { $info['height'] = $new_fielddata_height; } } if ($fieldtype == 4 || $fieldtype == 2) { if ($new_fielddata_height < 1 || $new_fielddata_height > 1000) { print_stop_message('generic_error_x', construct_phrase($vbphrase['photoplog_bad_field_height'], 0, 1000)); } else { $info['height'] = $new_fielddata_height; } } if ($fieldtype >= 4) { if ($new_fielddata_limit < 0 || $new_fielddata_limit > 1000) { print_stop_message('generic_error_x', construct_phrase($vbphrase['photoplog_bad_field_limit'], 0, 1000)); } else { $info['limit'] = $new_fielddata_limit; } } if ($fieldtype == 5 || $fieldtype == 3) { if ($new_fielddata_perline < 0 || $new_fielddata_perline > 1000) { print_stop_message('generic_error_x', construct_phrase($vbphrase['photoplog_bad_field_perline'], 1000)); } else { $info['perline'] = $new_fielddata_perline; } } if (!($new_fielddata_active == 0 || $new_fielddata_active == 1)) { print_stop_message('generic_error_x', $vbphrase['photoplog_bad_field_active']); } if (!($new_fielddata_hidden == 0 || $new_fielddata_hidden == 1)) { print_stop_message('generic_error_x', $vbphrase['photoplog_bad_field_hidden']); } if (!($new_fielddata_required == 0 || $new_fielddata_required == 1)) { print_stop_message('generic_error_x', $vbphrase['photoplog_bad_field_required']); } else { $info['required'] = $new_fielddata_required; } if (!($new_fielddata_inherited == 0 || $new_fielddata_inherited == 1)) { print_stop_message('generic_error_x', $vbphrase['photoplog_bad_field_inherited']); } $child_list = array(); $parent_list = array(); photoplog_child_list($child_list, $parent_list, $catid); $displayorder = 0; if ($doadd) { $name_in_use = false; $fields = $vbulletin->db->query_read("SELECT displayorder, groupid\r\n\t\t\tFROM " . PHOTOPLOG_PREFIX . "photoplog_customfields\r\n\t\t\tWHERE catid = " . intval($catid) . "\r\n\t\t\tORDER BY displayorder ASC\r\n\t\t"); while ($field = $vbulletin->db->fetch_array($fields)) { $displayorder = $field['displayorder']; if ($field['groupid'] == $new_fielddata_groupid) { $name_in_use = true; break; } } $vbulletin->db->free_result($fields); if ($name_in_use) { print_stop_message('generic_error_x', $vbphrase['photoplog_bad_field_name_in_use']); } $displayorder += 10; if ($new_fielddata_inherited == 1 && !empty($child_list)) { // check subcategories to see if there is a problem with the name! $check_subcats = $vbulletin->db->query_first("SELECT COUNT(*) AS cnt\r\n\t\t\t\tFROM " . PHOTOPLOG_PREFIX . "photoplog_customfields\r\n\t\t\t\tWHERE catid IN (" . implode(",", $child_list) . ")\r\n\t\t\t\tAND groupid = " . intval($new_fielddata_groupid) . "\r\n\t\t\t"); if (!$check_subcats || !isset($check_subcats['cnt']) || $check_subcats['cnt'] > 0) { print_stop_message('generic_error_x', $vbphrase['photoplog_bad_field_name_in_use_inherited']); } } } else { $displayorder = intval($current_fielddata['displayorder']); if ($new_fielddata_inherited == 1 && intval($current_fielddata['inherited']) > -1 && !empty($child_list)) { // check subcategories to see if there is a problem with the name! $check_subcats = $vbulletin->db->query_first("SELECT COUNT(*) AS cnt\r\n\t\t\t\tFROM " . PHOTOPLOG_PREFIX . "photoplog_customfields\r\n\t\t\t\tWHERE catid IN (" . implode(",", $child_list) . ")\r\n\t\t\t\tAND groupid = " . intval($new_fielddata_groupid) . "\r\n\t\t\t\tAND parentid != " . intval($catid) . "\r\n\t\t\t"); if (!$check_subcats || !isset($check_subcats['cnt']) || $check_subcats > 0) { print_stop_message('generic_error_x', $vbphrase['photoplog_bad_field_name_in_use_inherited']); } } } // be careful to not move the below two lines up!!! $new_fielddata_inherited = -1 * $new_fielddata_inherited; $new_fielddata_protected = 0; $info = serialize($info); if ($doadd) { if (!$new_fielddata_groupid) { $new_fielddata_groupid = photoplog_insert_customfield_group($new_fielddata_name); } if ($new_fielddata_groupid) { photoplog_insert_custom_field_recursive($child_list, $catid, $new_fielddata_groupid, $displayorder, $new_fielddata_hidden, $new_fielddata_active, $new_fielddata_protected, $new_fielddata_inherited, $catid, $info); } } else { photoplog_update_custom_field_recursive($child_list, $current_fielddata['fieldid'], $catid, $current_fielddata['groupid'], $current_fielddata['displayorder'], $new_fielddata_hidden, $new_fielddata_active, $new_fielddata_inherited, $catid, $info); } }
if ($_REQUEST['do'] == 'delete') { $vbulletin->input->clean_array_gpc('g', array('catid' => TYPE_UINT)); print_form_header('photoplog_category', 'dodelete'); construct_hidden_code('s', $vbulletin->session->vars['sessionhash']); construct_hidden_code('catid', $vbulletin->GPC['catid']); print_table_header($vbphrase['photoplog_confirm_deletion']); print_description_row($vbphrase['photoplog_confirm_delete_category']); print_submit_row($vbphrase['photoplog_yes'], '', 2, $vbphrase['photoplog_no']); } if ($_REQUEST['do'] == 'dodelete') { $vbulletin->input->clean_array_gpc('p', array('catid' => TYPE_UINT)); $photoplog_catid = $vbulletin->GPC['catid']; $photoplog_dscatopts = $photoplog_ds_catopts; $photoplog_child_list = array(); $photoplog_parent_list = array(); photoplog_child_list($photoplog_child_list, $photoplog_parent_list, $photoplog_catid); $photoplog_catids_array = array_merge(array($photoplog_catid), $photoplog_child_list, $photoplog_parent_list); $photoplog_sql = "WHERE catid = " . intval($photoplog_catid); unset($photoplog_dscatopts["{$photoplog_catid}"]); if (!empty($photoplog_child_list)) { $photoplog_sql = "WHERE catid IN (" . intval($photoplog_catid) . "," . implode(",", $photoplog_child_list) . ")"; foreach ($photoplog_child_list as $photoplog_childid) { unset($photoplog_dscatopts["{$photoplog_childid}"]); } } if ($db->query_write("UPDATE " . PHOTOPLOG_PREFIX . "photoplog_fileuploads\r\n\t\t\tSET catid = 0\r\n\t\t\t{$photoplog_sql}\r\n\t\t") && $db->query_write("UPDATE " . PHOTOPLOG_PREFIX . "photoplog_ratecomment\r\n\t\t\tSET catid = 0\r\n\t\t\t{$photoplog_sql}\r\n\t\t") && $db->query_write("DELETE FROM " . PHOTOPLOG_PREFIX . "photoplog_categories\r\n\t\t\t{$photoplog_sql}\r\n\t\t") && $db->query_write("DELETE FROM " . PHOTOPLOG_PREFIX . "photoplog_catcounts\r\n\t\t\t{$photoplog_sql}\r\n\t\t")) { $db->query_write("ALTER TABLE " . PHOTOPLOG_PREFIX . "photoplog_categories\r\n\t\t\tORDER BY parentid, displayorder, catid\r\n\t\t"); // not approved: 0, approved: 1, declined: 2, cat deleted: 3 $db->query_write("UPDATE " . PHOTOPLOG_PREFIX . "photoplog_suggestedcats\r\n\t\t\tSET approve = 3\r\n\t\t\t{$photoplog_sql}\r\n\t\t"); // photoplog_regenerate_counts_table_v2($photoplog_catids_array); photoplog_custom_field_delete_category($photoplog_catid, $photoplog_child_list);
// add categories to the where condition $photoplog_source_list_categories = array(); $photoplog_destination_list_categories = array(); $photoplog_parent_list_categories = array(); $photoplog_move_categories = true; if ($photoplog_destination_category < 0) { $photoplog_destination_category = $photoplog_source_category; $photoplog_move_categories = false; $photoplog_make_subcategories = 0; // improves efficiency } $photoplog_source_list_categories[] = $photoplog_source_category; $photoplog_destination_list_categories[] = $photoplog_destination_category; $photoplog_parent_list_categories[] = $photoplog_source_category; if ($photoplog_include_subcategories) { photoplog_child_list($photoplog_source_list_categories, $photoplog_parent_list_categories, $photoplog_source_category); foreach ($photoplog_source_list_categories as $photoplog_list_key => $photoplog_list_value) { $photoplog_destination_list_categories[$photoplog_list_key] = $photoplog_destination_category; } } if ($photoplog_make_subcategories || !$photoplog_include_subcategories) { // case 2, or case 1 foreach ($photoplog_source_list_categories as $photoplog_list_category_key => $photoplog_list_category_value) { $photoplog_multi_wheres[$photoplog_list_category_key] = array(); $photoplog_multi_wheres[$photoplog_list_category_key][] = PHOTOPLOG_PREFIX . "photoplog_fileuploads.catid = " . intval($photoplog_list_category_value); } } else { // case 3 $photoplog_multi_wheres[0] = array(); $photoplog_multi_wheres[0][] = photoplog_sql_in_list_implode(PHOTOPLOG_PREFIX . 'photoplog_fileuploads.catid', $photoplog_source_list_categories); }