SpankMe |
04-24-2004 09:00 PM |
Here the phrase.php code:
PHP Code:
// PhraseGroupManager by Hoffi
if ($_REQUEST['do'] == 'addgroup') {
print_form_header('phrase', 'insertgroup');
print_table_header($vbphrase['add_new_phrase_group']);
print_input_row($vbphrase['varname'], 'varname', 'var1', 1, 50);
print_input_row($vbphrase['phrasegroupname'], 'groupname', 'Group1', 1, 50);
print_submit_row($vbphrase['save']);
print_table_footer();
}
// ----------
if ($_REQUEST['do'] == 'editgroup') {
globalize($_REQUEST, array(
'p'));
$phrasetypes = fetch_phrasetypes_array();
// echo "<pre>";
// print_r($phrasetypes);
// echo "</pre>";
print_form_header('phrase', 'updategroup');
construct_hidden_code('p',$p);
construct_hidden_code('oldvarname', $phrasetypes[$p]['fieldname']);
print_table_header($vbphrase['add_new_phrase_group']);
print_input_row($vbphrase['varname'], 'varname', $phrasetypes[$p]['fieldname'], 1, 50);
print_input_row($vbphrase['phrasegroupname'], 'groupname', $phrasetypes[$p]['title'], 1, 50);
print_submit_row($vbphrase['save']);
print_table_footer();
}
// ----------
if ($_REQUEST['do'] == 'updategroup') {
globalize($_REQUEST, array(
'oldvarname',
'varname',
'groupname',
'p'));
if (!update_phrase_type($p, $oldvarname, $varname, $groupname)) {
print_stop_message('phrase_group_x_not_saved',$groupname);
} else {
build_language(-1);
define('CP_REDIRECT', "phrase.php?do=listgroups");
print_stop_message('phrase_group_x_saved', $groupname);
}
}
// ----------
if ($_REQUEST['do'] == 'insertgroup') {
globalize($_REQUEST, array(
'varname',
'groupname'));
if (!add_phrase_type($varname, $groupname)) {
print_stop_message('phrase_group_x_not_saved',$groupname);
} else {
build_language(-1);
define('CP_REDIRECT', "phrase.php?do=listgroups");
print_stop_message('phrase_group_x_saved', $groupname);
}
}
// ----------
if ($_REQUEST['do'] == 'killgroup') {
globalize($_REQUEST, array(
'p'));
if (!delete_phrase_type($p)) {
print_stop_message('phrase_group_x_not_deleted',$p);
} else {
build_language(-1);
define('CP_REDIRECT', "phrase.php?do=listgroups");
print_stop_message('phrase_group_x_deleted', $p);
}
}
// ----------
if ($_REQUEST['do'] == 'listgroups') {
print_form_header('phrase', 'addgroup');
print_table_header($vbphrase['list_custom_phrase_groups']);
$phrasetypes = fetch_phrasetypes_array();
foreach($phrasetypes AS $id => $type)
{
$cell = array();
if ($id < 1000 AND $id > 150) {
$cell[] = $type['title'] . "($id)";
$cell[] = construct_link_code($vbphrase['edit'], "phrase.php?do=editgroup&p=$id")." ".construct_link_code($vbphrase['delete'], "phrase.php?do=delgroup&p=$id");
}
print_cells_row($cell);
}
print_submit_row($vbphrase['add_new_phrase_group']);
print_table_footer();
}
// ----------
if ($_REQUEST['do'] == 'delgroup') {
globalize($_REQUEST, array(
'p'));
print_form_header('phrase', 'killgroup');
construct_hidden_code('p',$p);
print_table_header($vbphrase['list_phrase_groups']);
$phrasetypes = fetch_phrasetypes_array();
$cell = array();
$cell[] = construct_phrase($vbphrase['are_you_sure_to_delete_phrasegroup'], $phrasetypes[$p]['title']);
print_cells_row($cell);
print_submit_row($vbphrase['delete']);
}
// End PhraseGroupmanager
and the adminfunctions_language.php code:
PHP Code:
// #############################################################################
// function to allow modifications to update a phrasetype easily
function update_phrase_type($phrasegroup_id, $old_phrasegroup_name, $phrasegroup_name, $phrasegroup_title)
{
global $DB_site;
if ($phrasegroup_id)
{
$DB_site->query("UPDATE " . TABLE_PREFIX . "phrasetype SET fieldname = '" . addslashes($phrasegroup_name) . "', title = '" . addslashes($phrasegroup_title) . "' WHERE phrasetypeid = $phrasegroup_id");
if ($old_phrasegroup_name != $phrasegroup_name)
{
$DB_site->query("ALTER TABLE " . TABLE_PREFIX . "language CHANGE phrasegroup_" . addslashes($old_phrasegroup_name) . " phrasegroup_" . addslashes($phrasegroup_name) . " MEDIUMTEXT NOT NULL");
}
return true;
}
return false;
}
// #############################################################################
// function from Hoffi to delete PhraseGroups easy
function delete_phrase_type($phrasegroup_id, $delphrases=1, $moveto=0)
{
global $DB_site;
$ret=false;
// first lets check if it exists
if ($check = $DB_site->query_first("SELECT * FROM " . TABLE_PREFIX . "phrasetype WHERE phrasetypeid = '$phrasegroup_id'")) {
if ($delphrases==1) {
$DB_site->query("DELETE FROM " . TABLE_PREFIX . "phrase WHERE phrasetypeid = '$phrasegroup_id'");
$ret=true;
} else {
if ($check = $DB_site->query_first("SELECT * FROM " . TABLE_PREFIX . "phrasetype WHERE phrasetypeid = '$moveto'")) {
$DB_site->query("UPDATE " . TABLE_PREFIX . "phrase SET phrasetypeid = '$moveto' WHERE phrasetypeid = '$phrasegroup_id'");
$ret=true;
}
}
if ($ret) {
$DB_site->query("DELETE FROM " . TABLE_PREFIX . "phrasetype WHERE phrasetypeid = '$phrasegroup_id'");
$DB_site->query("ALTER TABLE " . TABLE_PREFIX . "language DROP phrasegroup_" . addslashes($check['fieldname']));
}
}
return $ret;
}
I think thats everything.
|