$Date: 2007-01-11 17:33:24 -0500 (Thu, 11 Jan 2007) $
| > $Revision: 826 $
| > $Author: bfarber $
+---------------------------------------------------------------------------
|
| > Custom profile field functions
| > Module written by Matt Mecham
| > Date started: 24th June 2002
|
| > Module Version Number: 1.0.0
| > DBA Checked: Tue 25th May 2004
+--------------------------------------------------------------------------
*/
if ( ! defined( 'IN_ACP' ) )
{
print "
Incorrect access You cannot access this file directly. If you have recently upgraded, make sure you upgraded 'admin.php'.";
exit();
}
class ad_profilefields {
var $base_url;
var $func;
/**
* Section title name
*
* @var string
*/
var $perm_main = "content";
/**
* Section title name
*
* @var string
*/
var $perm_child = "field";
function auto_run()
{
$this->ipsclass->admin->nav[] = array( $this->ipsclass->form_code, 'Custom Profile Fields' );
//-----------------------------------------
// get class
//-----------------------------------------
require_once( ROOT_PATH.'sources/classes/class_custom_fields.php' );
$this->func = new custom_fields( $DB );
//-----------------------------------------
// switch-a-magoo
//-----------------------------------------
switch($this->ipsclass->input['code'])
{
case 'add':
$this->ipsclass->admin->cp_permission_check( $this->perm_main.'|'.$this->perm_child.':add' );
$this->main_form('add');
break;
case 'doadd':
$this->ipsclass->admin->cp_permission_check( $this->perm_main.'|'.$this->perm_child.':add' );
$this->main_save('add');
break;
case 'edit':
$this->ipsclass->admin->cp_permission_check( $this->perm_main.'|'.$this->perm_child.':edit' );
$this->main_form('edit');
break;
case 'doedit':
$this->ipsclass->admin->cp_permission_check( $this->perm_main.'|'.$this->perm_child.':edit' );
$this->main_save('edit');
break;
case 'delete':
$this->ipsclass->admin->cp_permission_check( $this->perm_main.'|'.$this->perm_child.':remove' );
$this->delete_form();
break;
case 'dodelete':
$this->ipsclass->admin->cp_permission_check( $this->perm_main.'|'.$this->perm_child.':remove' );
$this->do_delete();
break;
default:
$this->ipsclass->admin->cp_permission_check( $this->perm_main.'|'.$this->perm_child.':' );
$this->main_screen();
break;
}
}
//-----------------------------------------
//
// Rebuild cache
//
//-----------------------------------------
function rebuild_cache()
{
$this->ipsclass->cache['profilefields'] = array();
$this->ipsclass->DB->simple_construct( array( 'select' => '*', 'from' => 'pfields_data', 'order' => 'pf_position' ) );
$this->ipsclass->DB->simple_exec();
while ( $r = $this->ipsclass->DB->fetch_row() )
{
$this->ipsclass->cache['profilefields'][ $r['pf_id'] ] = $r;
}
$this->ipsclass->update_cache( array( 'name' => 'profilefields', 'array' => 1, 'deletefirst' => 1 ) );
}
//-----------------------------------------
//
// Delete a group
//
//-----------------------------------------
function delete_form()
{
if ($this->ipsclass->input['id'] == "")
{
$this->ipsclass->admin->error("Could not resolve the group ID, please try again");
}
$this->ipsclass->admin->page_title = "Deleting a Custom Profile Field";
$this->ipsclass->admin->page_detail = "Please check to ensure that you are attempting to remove the correct custom profile field as all data will be lost! .";
//-----------------------------------------
$this->ipsclass->DB->simple_construct( array( 'select' => '*', 'from' => 'pfields_data', 'where' => "pf_id=".intval($this->ipsclass->input['id']) ) );
$this->ipsclass->DB->simple_exec();
if ( ! $field = $this->ipsclass->DB->fetch_row() )
{
$this->ipsclass->admin->error("Could not fetch the row from the database");
}
$this->ipsclass->html .= $this->ipsclass->adskin->start_form( array( 1 => array( 'code' , 'dodelete' ),
2 => array( 'act' , 'field' ),
3 => array( 'id' , $this->ipsclass->input['id'] ),
4 => array( 'section', $this->ipsclass->section_code ),
) );
//-----------------------------------------
$this->ipsclass->adskin->td_header[] = array( " " , "40%" );
$this->ipsclass->adskin->td_header[] = array( " " , "60%" );
//-----------------------------------------
$this->ipsclass->html .= $this->ipsclass->adskin->start_table( "Removal Confirmation" );
$this->ipsclass->html .= $this->ipsclass->adskin->add_td_row( array( "Custom Profile field to remove " ,
"".$field['pf_title']." ",
) );
$this->ipsclass->html .= $this->ipsclass->adskin->end_form("Delete this custom field");
$this->ipsclass->html .= $this->ipsclass->adskin->end_table();
$this->ipsclass->admin->output();
}
function do_delete()
{
if ($this->ipsclass->input['id'] == "")
{
$this->ipsclass->admin->error("Could not resolve the field ID, please try again");
}
//-----------------------------------------
// Check to make sure that the relevant groups exist.
//-----------------------------------------
$this->ipsclass->DB->simple_construct( array( 'select' => '*', 'from' => 'pfields_data', 'where' => "pf_id=".intval($this->ipsclass->input['id']) ) );
$this->ipsclass->DB->simple_exec();
if ( ! $row = $this->ipsclass->DB->fetch_row() )
{
$this->ipsclass->admin->error("Could not resolve the ID's passed to deletion");
}
$this->ipsclass->DB->sql_drop_field( 'pfields_content', "field_{$row['pf_id']}" );
$this->ipsclass->DB->simple_exec_query( array( 'delete' => 'pfields_data', 'where' => "pf_id=".intval($this->ipsclass->input['id']) ) );
$this->rebuild_cache();
$this->ipsclass->admin->done_screen("Profile Field Removed", "Custom Profile Field Control", "{$this->ipsclass->form_code}", 'redirect' );
}
//-----------------------------------------
//
// Save changes to DB
//
//-----------------------------------------
function main_save($type='edit')
{
$this->ipsclass->input['id'] = intval($this->ipsclass->input['id']);
if ($this->ipsclass->input['pf_title'] == "")
{
$this->ipsclass->admin->error("You must enter a field title.");
}
//-----------------------------------------
// check-da-motcha
//-----------------------------------------
if ($type == 'edit')
{
if ($this->ipsclass->input['id'] == "")
{
$this->ipsclass->admin->error("Could not resolve the field id");
}
}
$content = "";
if ( $_POST['pf_content'] != "")
{
$content = $this->func->method_format_content_for_save( $_POST['pf_content'] );
}
$db_string = array( 'pf_title' => $this->ipsclass->input['pf_title'],
'pf_desc' => $this->ipsclass->input['pf_desc'],
'pf_content' => $this->ipsclass->txt_stripslashes($content),
'pf_type' => $this->ipsclass->input['pf_type'],
'pf_not_null' => intval($this->ipsclass->input['pf_not_null']),
'pf_member_hide' => intval($this->ipsclass->input['pf_member_hide']),
'pf_max_input' => intval($this->ipsclass->input['pf_max_input']),
'pf_member_edit' => intval($this->ipsclass->input['pf_member_edit']),
'pf_position' => intval($this->ipsclass->input['pf_position']),
'pf_show_on_reg' => intval($this->ipsclass->input['pf_show_on_reg']),
'pf_input_format' => $this->ipsclass->input['pf_input_format'],
'pf_admin_only' => intval($this->ipsclass->input['pf_admin_only']),
'pf_topic_format' => $this->ipsclass->txt_stripslashes( $_POST['pf_topic_format']),
);
if ($type == 'edit')
{
$this->ipsclass->DB->do_update( 'pfields_data', $db_string, 'pf_id='.$this->ipsclass->input['id'] );
$this->rebuild_cache();
$this->ipsclass->main_msg = "Profile Field Edited";
$this->main_screen();
}
else
{
$this->ipsclass->DB->do_insert( 'pfields_data', $db_string );
$new_id = $this->ipsclass->DB->get_insert_id();
$this->ipsclass->DB->sql_add_field( 'pfields_content', "field_$new_id", 'text' );
$this->ipsclass->DB->sql_optimize_table( 'pfields_content' );
$this->rebuild_cache();
$this->ipsclass->main_msg = "Profile Field Added";
$this->main_screen();
}
}
//-----------------------------------------
//
// Add / edit group
//
//-----------------------------------------
function main_form($type='edit')
{
$this->ipsclass->input['id'] = intval($this->ipsclass->input['id']);
$this->ipsclass->admin->nav[] = array( '', 'Add/Edit Custom Profile Field' );
if ($type == 'edit')
{
if ( ! $this->ipsclass->input['id'] )
{
$this->ipsclass->admin->error("No group id to select from the database, please try again.");
}
$form_code = 'doedit';
$button = 'Complete Edit';
}
else
{
$form_code = 'doadd';
$button = 'Add Field';
}
//-----------------------------------------
// get field from db
//-----------------------------------------
if ( $this->ipsclass->input['id'] )
{
$this->ipsclass->DB->simple_construct( array( 'select' => '*', 'from' => 'pfields_data', 'where' => "pf_id=".intval($this->ipsclass->input['id']) ) );
$this->ipsclass->DB->simple_exec();
$fields = $this->ipsclass->DB->fetch_row();
}
else
{
$fields = array( 'pf_topic_format' => '{title}: {content} ' );
}
//-----------------------------------------
// Top 'o 'the mornin'
//-----------------------------------------
if ($type == 'edit')
{
$this->ipsclass->admin->page_title = "Editing Profile Field ".$fields['pf_title'];
}
else
{
$this->ipsclass->admin->page_title = 'Adding a new profile field';
$fields = array( 'pf_title' => '',
'pf_content' => '',
'pf_desc' => '',
'pf_type' => '',
'pf_max_input' => '',
'pf_position' => '',
'pf_input_format' => '',
'pf_topic_format' => '',
'pf_show_on_reg' => '',
'pf_not_null' => '',
'pf_member_edit' => '',
'pf_member_hide' => '',
'pf_admin_only' => '' );
}
//-----------------------------------------
// Wise words
//-----------------------------------------
$this->ipsclass->admin->page_detail = "Please double check the information before submitting the form.";
//-----------------------------------------
// Start form
//-----------------------------------------
$this->ipsclass->html .= $this->ipsclass->adskin->start_form( array( 1 => array( 'code' , $form_code ),
2 => array( 'act' , 'field' ),
3 => array( 'id' , $this->ipsclass->input['id'] ),
4 => array( 'section', $this->ipsclass->section_code ),
) );
//-----------------------------------------
// Format...
//-----------------------------------------
$fields['pf_content'] = $this->func->method_format_content_for_edit($fields['pf_content'] );
//-----------------------------------------
// Tbl (no ae?)
//-----------------------------------------
$this->ipsclass->adskin->td_header[] = array( " " , "40%" );
$this->ipsclass->adskin->td_header[] = array( " " , "60%" );
$this->ipsclass->html .= $this->ipsclass->adskin->start_table( "Field Settings" );
$this->ipsclass->html .= $this->ipsclass->adskin->add_td_row( array( "Field Title Max characters: 200
" ,
$this->ipsclass->adskin->form_input("pf_title", $fields['pf_title'] )
) );
$this->ipsclass->html .= $this->ipsclass->adskin->add_td_row( array( "Description Max Characters: 250 Can be used to note hidden/required status
" ,
$this->ipsclass->adskin->form_input("pf_desc", $fields['pf_desc'] )
) );
$this->ipsclass->html .= $this->ipsclass->adskin->add_td_row( array( "Field Type " ,
$this->ipsclass->adskin->form_dropdown("pf_type",
array(
0 => array( 'text' , 'Text Input' ),
1 => array( 'drop' , 'Drop Down Box' ),
2 => array( 'area' , 'Text Area' ),
),
$fields['pf_type'] )
) );
$this->ipsclass->html .= $this->ipsclass->adskin->add_td_row( array( "Maximum Input For text input and text areas (in characters)
" ,
$this->ipsclass->adskin->form_input("pf_max_input", $fields['pf_max_input'] )
) );
$this->ipsclass->html .= $this->ipsclass->adskin->add_td_row( array( "Display order When editing and displaying (numeric 1 lowest)
" ,
$this->ipsclass->adskin->form_input("pf_position", $fields['pf_position'] )
) );
$this->ipsclass->html .= $this->ipsclass->adskin->add_td_row( array( "Expected Input Format Use: a for alpha characters Use: n for numerics. Example, for credit card numbers: nnnn-nnnn-nnnn-nnnn Example, Date of Birth: nn-nn-nnnn Leave blank to accept any input
" ,
$this->ipsclass->adskin->form_input("pf_input_format", $fields['pf_input_format'] )
) );
$this->ipsclass->html .= $this->ipsclass->adskin->add_td_row( array( "Option Content (for drop downs) In sets, one set per line Example for 'Gender' field: m=Male f=Female u=Not Telling Will produce:Male Female Not Telling m,f or u stored in database. When showing field in profile, will use value from pair (f=Female, shows 'Female')
" ,
$this->ipsclass->adskin->form_textarea("pf_content", $fields['pf_content'] )
) );
$this->ipsclass->html .= $this->ipsclass->adskin->add_td_row( array( "Include on registration page? If 'yes', the field will be shown upon registration.
" ,
$this->ipsclass->adskin->form_yes_no("pf_show_on_reg", $fields["pf_show_on_reg"] )
) );
$this->ipsclass->html .= $this->ipsclass->adskin->add_td_row( array( "Field MUST be completed and not left empty? If 'yes', an error will be shown if this field is not completed.
" ,
$this->ipsclass->adskin->form_yes_no("pf_not_null", $fields['pf_not_null'] )
) );
$this->ipsclass->html .= $this->ipsclass->adskin->add_td_row( array( "Field can be edited by the member? If 'no', the member cannot edit the field but Super Moderators and Admins will be able to.
" ,
$this->ipsclass->adskin->form_yes_no("pf_member_edit", $fields['pf_member_edit'] )
) );
$this->ipsclass->html .= $this->ipsclass->adskin->add_td_row( array( "Make this a private profile field? If yes, field only visible to profile owner, super moderators and admins. If 'no', members can search within this field.
" ,
$this->ipsclass->adskin->form_yes_no("pf_member_hide", $fields['pf_member_hide'] )
) );
$this->ipsclass->html .= $this->ipsclass->adskin->add_td_row( array( "Make Admin and Super Moderator Editable/Viewable Only? If yes, will override the above options so only admins and super moderators can see and edit this field.
" ,
$this->ipsclass->adskin->form_yes_no("pf_admin_only", $fields['pf_admin_only'] )
) );
$this->ipsclass->html .= $this->ipsclass->adskin->add_td_row( array( "Topic View Format? Leave blank if you do not wish to add this field in the author details when viewing a topic. {title} is the title of the custom field, {content} is the user added content. {key} is the form select value of the selected item in a dropdown box. Example: {title}:{content}<br /> Example: {title}:<img src='imgs/{key}'>
" ,
$this->ipsclass->adskin->form_textarea("pf_topic_format", $fields['pf_topic_format'] )
) );
$this->ipsclass->html .= $this->ipsclass->adskin->end_form($button);
$this->ipsclass->html .= $this->ipsclass->adskin->end_table();
$this->ipsclass->admin->output();
}
//-----------------------------------------
//
// Show "Management Screen
//
//-----------------------------------------
function main_screen()
{
$this->ipsclass->admin->page_title = "Custom Profile Fields";
$this->ipsclass->admin->page_detail = "Custom Profile fields can be used to add optional or required fields to be completed when registering or editing a profile. This is useful if you wish to record data from your members that is not already present in the base board.";
$this->ipsclass->adskin->td_header[] = array( "Field Title" , "20%" );
$this->ipsclass->adskin->td_header[] = array( "Type" , "10%" );
$this->ipsclass->adskin->td_header[] = array( "REQUIRED" , "10%" );
$this->ipsclass->adskin->td_header[] = array( "NOT PUBLIC" , "10%" );
$this->ipsclass->adskin->td_header[] = array( "SHOW REG" , "10%" );
$this->ipsclass->adskin->td_header[] = array( "ADMIN ONLY" , "10%" );
$this->ipsclass->adskin->td_header[] = array( "Edit" , "10%" );
$this->ipsclass->adskin->td_header[] = array( "Delete" , "10%" );
//-----------------------------------------
$this->ipsclass->html .= $this->ipsclass->adskin->start_table( "Custom Profile Field Management" );
$real_types = array( 'drop' => 'Drop Down Box',
'area' => 'Text Area',
'text' => 'Text Input',
);
$this->ipsclass->DB->simple_construct( array( 'select' => '*', 'from' => 'pfields_data', 'order' => 'pf_position' ) );
$this->ipsclass->DB->simple_exec();
if ( $this->ipsclass->DB->get_num_rows() )
{
while ( $r = $this->ipsclass->DB->fetch_row() )
{
$hide = ' ';
$req = ' ';
$regi = ' ';
$admin = ' ';
//-----------------------------------------
// Hidden?
//-----------------------------------------
if ($r['pf_member_hide'] == 1)
{
$hide = 'Y ';
}
//-----------------------------------------
// Required?
//-----------------------------------------
if ($r['pf_not_null'] == 1)
{
$req = 'Y ';
}
//-----------------------------------------
// Show on reg?
//-----------------------------------------
if ($r['pf_show_on_reg'] == 1)
{
$regi = 'Y ';
}
//-----------------------------------------
// Admin only...
//-----------------------------------------
if ($r['pf_admin_only'] == 1)
{
$admin = 'Y ';
}
$this->ipsclass->html .= $this->ipsclass->adskin->add_td_row( array( "{$r['pf_title']} {$r['pf_desc']}
" ,
"{$real_types[$r['pf_type']]} ",
$req,
$hide,
$regi,
$admin,
"Edit ",
"Delete ",
) );
}
}
else
{
$this->ipsclass->html .= $this->ipsclass->adskin->add_td_basic("None found", "center", "tablerow1");
}
$this->ipsclass->html .= $this->ipsclass->adskin->add_td_basic("", 'center', 'tablefooter' );
$this->ipsclass->html .= $this->ipsclass->adskin->end_table();
$this->ipsclass->admin->output();
}
}
?>