Advanced search  

News:

cpg1.5.48 Security release - upgrade mandatory!
The Coppermine development team is releasing a security update for Coppermine in order to counter a recently discovered vulnerability. It is important that all users who run version cpg1.5.46 or older update to this latest version as soon as possible.
[more]

Pages: [1] 2 3   Go Down

Author Topic: Add More Custom Fields via Config  (Read 49961 times)

0 Members and 1 Guest are viewing this topic.

pslawinski

  • Contributor
  • Coppermine novice
  • ***
  • Offline Offline
  • Gender: Male
  • Posts: 48
    • Lighting-Gallery.net
Add More Custom Fields via Config
« on: November 13, 2005, 12:16:12 am »

I got tired of having to add more user fields by copying and pasting code each time I wanted to add another custom field.  So, I created this mod that allows you to add more Custom Fields through the Config page.  An extra field is added to the config page that allows you to select how many fields you want. You can have any number greater than 4, though you might have some problems if you try to add an unreasonable number.

Currently this works for 1.4 only, but with a little work it could easlily be adapted for previous versions.

So let's start from the beginning:

First step:
Add the user_field_num row to the config table in mySQL.
(Note: change <tablePrefix> to the prefix you use for your tables.)

Code: [Select]
INSERT INTO `<tablePrefix>_config` ( `name` , `value` ) VALUES ('user_field_num', '4');

Now for the code additions:


lang/english.php
I coded for english.php but you can easlily adapt this for any language by changing the values.

Find:
Code: [Select]
  'Custom fields for image description (leave blank if unused)',
  array('Field 1 name', 'user_field1_name', 0, 'f=index.htm&amp;as=admin_custom_image&amp;ae=admin_custom_image_end'), //cpg1.4
  array('Field 2 name', 'user_field2_name', 0),
  array('Field 3 name', 'user_field3_name', 0),
  array('Field 4 name', 'user_field4_name', 0),

  'Cookies settings',
  array('Cookie name', 'cookie_name', 0, 'f=index.htm&amp;as=admin_cookie_name&amp;ae=admin_cookie_name_end'), //cpg1.4
  array('Cookie path', 'cookie_path', 0, 'f=index.htm&amp;as=admin_cookie_path&amp;ae=admin_cookie_path_end'), //cpg1.4

  'Email settings  (usually nothing has to be changed here; leave all fields blank when not sure)', //cpg1.4
  array('SMTP Host (when left blank, sendmail will be used)', 'smtp_host', 0, 'f=index.htm&amp;as=admin_email&amp;ae=admin_email_end'), //cpg1.4
  array('SMTP Username', 'smtp_username', 0), //cpg1.4
  array('SMTP Password', 'smtp_password', 0), //cpg1.4

  'Logging and statistics', //cpg1.4
  array('Logging mode <a href="#notice3" class="clickable_option">***</a>', 'log_mode', 11, 'f=index.htm&amp;as=admin_logging_log_mode&amp;ae=admin_logging_log_mode_end'), //cpg1.4
  array('Log ecards', 'log_ecards', 1, 'f=index.htm&amp;as=admin_general_log_ecards&amp;ae=admin_general_log_ecards_end'), //cpg1.4
  array('Keep detailed vote statistics','vote_details',1, 'f=index.htm&amp;as=admin_logging_votedetails&amp;ae=admin_logging_votedetails_end'), //cpg1.4
  array('Keep detailed hit statistics','hit_details',1, 'f=index.htm&amp;as=admin_logging_hitdetails&amp;ae=admin_logging_hitdetails_end'), //cpg1.4

  'Maintenance settings', //cpg1.4
  array('Enable debug mode', 'debug_mode', 9, 'f=index.htm&amp;as=debug_mode&amp;ae=debug_mode_end'), //cpg1.4
  array('Display notices in debug mode', 'debug_notice', 1, 'f=index.htm&amp;as=admin_misc_debug_notices&amp;ae=admin_misc_debug_notices_end'), //cpg1.4
  array('Gallery is offline', 'offline', 1, 'f=index.htm&amp;as=admin_general_offline&amp;ae=admin_general_offline_end'), //cpg1.4
);


Replace With:
Code: [Select]
  'Number of custom Fields to display',
  array('Number of user fields', 'user_field_num', 0, 'f=index.htm&amp;as=admin_custom_image&amp;ae=admin_custom_image_end'),

  'Custom fields for image description (leave blank if unused)',
  array('Field 1 name', 'user_field1_name', 0, 'f=index.htm&amp;as=admin_custom_image&amp;ae=admin_custom_image_end'), //cpg1.4
  array('Field 2 name', 'user_field2_name', 0),
  array('Field 3 name', 'user_field3_name', 0),
  array('Field 4 name', 'user_field4_name', 0),
);

//let's start the count at 5 since 4 fields have already been declared
for($i = 5; $i <= $CONFIG['user_field_num']; $i++)
{
$lang_admin_data[] = array("Field " . $i . " name", "user_field" . $i . "_name", 0);
}

$lang_admin_data[] = 'Cookies settings';
$lang_admin_data[] = array('Cookie name', 'cookie_name', 0, 'f=index.htm&amp;as=admin_cookie_name&amp;ae=admin_cookie_name_end'); //cpg1.4
$lang_admin_data[] = array('Cookie path', 'cookie_path', 0, 'f=index.htm&amp;as=admin_cookie_path&amp;ae=admin_cookie_path_end'); //cpg1.4

$lang_admin_data[] = 'Email settings  (usually nothing has to be changed here; leave all fields blank when not sure)'; //cpg1.4
$lang_admin_data[] = array('SMTP Host (when left blank, sendmail will be used)', 'smtp_host', 0, 'f=index.htm&amp;as=admin_email&amp;ae=admin_email_end'); //cpg1.4
$lang_admin_data[] = array('SMTP Username', 'smtp_username', 0); //cpg1.4
$lang_admin_data[] = array('SMTP Password', 'smtp_password', 0); //cpg1.4

$lang_admin_data[] = 'Logging and statistics'; //cpg1.4
$lang_admin_data[] = array('Logging mode <a href="#notice3" class="clickable_option">***</a>', 'log_mode', 11, 'f=index.htm&amp;as=admin_logging_log_mode&amp;ae=admin_logging_log_mode_end'); //cpg1.4
$lang_admin_data[] = array('Log ecards', 'log_ecards', 1, 'f=index.htm&amp;as=admin_general_log_ecards&amp;ae=admin_general_log_ecards_end'); //cpg1.4
$lang_admin_data[] = array('Keep detailed vote statistics','vote_details',1, 'f=index.htm&amp;as=admin_logging_votedetails&amp;ae=admin_logging_votedetails_end'); //cpg1.4
$lang_admin_data[] = array('Keep detailed hit statistics','hit_details',1, 'f=index.htm&amp;as=admin_logging_hitdetails&amp;ae=admin_logging_hitdetails_end'); //cpg1.4

$lang_admin_data[] = 'Maintenance settings'; //cpg1.4
$lang_admin_data[] = array('Enable debug mode', 'debug_mode', 9, 'f=index.htm&amp;as=debug_mode&amp;ae=debug_mode_end'); //cpg1.4
$lang_admin_data[] = array('Display notices in debug mode', 'debug_notice', 1, 'f=index.htm&amp;as=admin_misc_debug_notices&amp;ae=admin_misc_debug_notices_end'); //cpg1.4
$lang_admin_data[] = array('Gallery is offline', 'offline', 1, 'f=index.htm&amp;as=admin_general_offline&amp;ae=admin_general_offline_end'); //cpg1.4


admin.php

Find:
Code: [Select]
if ($CONFIG[$element[1]] !== stripslashes($value))
Replace with:
Code: [Select]

//create field if it does not exist
if (!isset($CONFIG[$element[1]]))
{
cpg_db_query("INSERT INTO {$CONFIG['TABLE_CONFIG']} ( `name` , `value` ) VALUES ('{$element[1]}', '$value')");
$processAnyways = true;
}

if ($CONFIG[$element[1]] !== stripslashes($value) || isset($processAnyways))


include/search.inc.php

Find:
Code: [Select]
$allowed = array('title', 'caption', 'keywords', 'owner_name', 'filename', 'pic_raw_ip', 'pic_hrd_ip', 'user1', 'user2', 'user3', 'user4');

Replace with:
Code: [Select]
$allowed = array('title', 'caption', 'keywords', 'owner_name', 'filename', 'pic_raw_ip', 'pic_hrd_ip');
//add user fields to allowed array
for($i = 1; $i <= $CONFIG['user_field_num']; $i++)
{
$uI = "user" . $i;
$allowed[] = $uI;
}


xp_publish.php
I have not tested this code since I do not use this

Find:
Code: [Select]
$keywords = '';

Replace all the user vars with:
Code: [Select]
$userFields = array();

Find:
Code: [Select]
$result = add_picture($album, $filepath, $picture_name, $position, $title, $caption, $keywords, $user1, $user2, $user3, $user4, $category);

Replace with:
Code: [Select]
$result = add_picture($album, $filepath, $picture_name, $position, $title, $caption, $keywords, $userFields, $category);


upload.php

Find
Code: [Select]
        // We have incoming placement data. Let's capture it.

        $album = (int)$_POST['album'];
        $title = addslashes($_POST['title']);
        $caption = addslashes($_POST['caption']);
        $keywords = addslashes($_POST['keywords']);

Replace all the user vars with:
Code: [Select]
//add user fields to userFields array
for($i = 1; $i <= $CONFIG['user_field_num']; $i++)
{
$uI = "user" . $i;
$userFields[] = addslashes($HTTP_POST_VARS[$uI]);
}


Find:
Code: [Select]
$result = add_picture($album, $filepath, $picture_name, 0,$title, $caption, $keywords, $user1, $user2, $user3, $user4, $category, $raw_ip, $hdr_ip, $movie_wd, $movie_ht);

Replace With:
Code: [Select]
$result = add_picture($album, $filepath, $picture_name, 0,$title, $caption, $keywords, $userFields, $category, $raw_ip, $hdr_ip, $movie_wd, $movie_ht);

Find:
Code: [Select]
    array($CONFIG['user_field1_name'], 'user1', 0, 255, 1),
    array($CONFIG['user_field2_name'], 'user2', 0, 255, 1),
    array($CONFIG['user_field3_name'], 'user3', 0, 255, 1),
    array($CONFIG['user_field4_name'], 'user4', 0, 255, 1),
    );

Replace With:
Code: [Select]
    );

    // Check for user defined fields.
for($i = 1; $i <= $CONFIG['user_field_num']; $i++)
{
$uFN = "user_field". $i . "_name";
$uI = "user" . $i;
if(!empty($CONFIG[$uFN]))
{
$form_array[] = array($CONFIG[$uFN], $uI, 0, 255, 1);
}
}



image_processor.php

Find:
Code: [Select]
global $user1;
global $user2;
global $user3;
global $user4;

Replace with:
Code: [Select]
global $userFields;

Find:
Code: [Select]
print "<input type=\"hidden\" name=\"user1\" value=\"$user1\">";
print "<input type=\"hidden\" name=\"user2\" value=\"$user2\">";
print "<input type=\"hidden\" name=\"user3\" value=\"$user3\">";
print "<input type=\"hidden\" name=\"user4\" value=\"$user4\">";

Replace with:
Code: [Select]
//print user fields
for($i = 1; $i <= $CONFIG['user_field_num']; $i++)
{
$userData = $userFields[$i-1];
print "<input type=\"hidden\" name=\"user$i\" value=\"$userData\">";
}

Find:
Code: [Select]
$user1 = $HTTP_POST_VARS['$user1'];
$user2 = $HTTP_POST_VARS['$user2'];
$user3 = $HTTP_POST_VARS['$user3'];
$user4 = $HTTP_POST_VARS['$user4'];

Replace With:
Code: [Select]
//set user fields
for($i = 1; $i <= $CONFIG['user_field_num']; $i++)
{
$uI = "user" . $i;
$userFields[] = $HTTP_POST_VARS['$uI'];
}


Find:
Code: [Select]
$user1 = $_POST['$user1'];
$user2 = $_POST['$user2'];
$user3 = $_POST['$user3'];
$user4 = $_POST['$user4'];

Replace With:
Code: [Select]
//set user fields
for($i = 1; $i <= $CONFIG['user_field_num']; $i++)
{
$uI = "user" . $i;
$userFields[] = $_POST['$uI'];
}


Find:
Code: [Select]
print "<input type=\"hidden\" name=\"user1\" value=\"$user1\">";
print "<input type=\"hidden\" name=\"user2\" value=\"$user2\">";
print "<input type=\"hidden\" name=\"user3\" value=\"$user3\">";
print "<input type=\"hidden\" name=\"user4\" value=\"$user4\">";

Replace with:
Code: [Select]
//print user fields
for($i = 1; $i <= $CONFIG['user_field_num']; $i++)
{
$userData = $userFields[$i-1];
print "<input type=\"hidden\" name=\"user$i\" value=\"$userData\">";
}


editpics.php

Find:
Code: [Select]
$THUMB_ROWSPAN=5;
if ($CONFIG['user_field1_name'] != '') $THUMB_ROWSPAN++;
if ($CONFIG['user_field2_name'] != '') $THUMB_ROWSPAN++;
if ($CONFIG['user_field3_name'] != '') $THUMB_ROWSPAN++;
if ($CONFIG['user_field4_name'] != '') $THUMB_ROWSPAN++;

Replace With:
Code: [Select]
$THUMB_ROWSPAN=5;
//get rowspan value
for($i = 1; $i <= $CONFIG['user_field_num']; $i++)
{
$uFN = "user_field" . $i . "_name";
if ($CONFIG[$uFN] != '') $THUMB_ROWSPAN++;
}

Find:
Code: [Select]
$data = array(
        array($lang_editpics_php['pic_info'], '', 3),
        array($lang_editpics_php['album'], 'aid', 1),
        array($lang_editpics_php['title'], 'title', 0, 255),
        array($captionLabel, 'caption', 2, $CONFIG['max_img_desc_length']),
        array($lang_editpics_php['keywords'], 'keywords', 0, 255),
        array($CONFIG['user_field1_name'], 'user1', 0, 255),
        array($CONFIG['user_field2_name'], 'user2', 0, 255),
        array($CONFIG['user_field3_name'], 'user3', 0, 255),
        array($CONFIG['user_field4_name'], 'user4', 0, 255),
        array('', '', 4)
);

Replace With:
Code: [Select]
$data = array(
        array($lang_editpics_php['pic_info'], '', 3),
        array($lang_editpics_php['album'], 'aid', 1),
        array($lang_editpics_php['title'], 'title', 0, 255),
        array($captionLabel, 'caption', 2, $CONFIG['max_img_desc_length']),
        array($lang_editpics_php['keywords'], 'keywords', 0, 255),
);

//add user fields to data
for($i = 1; $i <= $CONFIG['user_field_num']; $i++)
{
$uFN = "user_field" . $i . "_name";
$uI = "user" . $i;
$data[] = array($CONFIG[$uFN], $uI, 0, 255);
}

$data[] = array('', '', 4);

Find:
Code: [Select]
                $user1       = get_post_var('user1', $pid);
                $user2       = get_post_var('user2', $pid);
                $user3       = get_post_var('user3', $pid);
                $user4       = get_post_var('user4', $pid);


Replace With:
Code: [Select]
//set userFields
for($i = 1; $i <= $CONFIG['user_field_num']; $i++)
{
$userFields[] = get_post_var("user$i", $pid);
}


Find:
Code: [Select]
                $update .= ", user1 = '".addslashes($user1)."'";
                $update .= ", user2 = '".addslashes($user2)."'";
                $update .= ", user3 = '".addslashes($user3)."'";
                $update .= ", user4 = '".addslashes($user4)."'";


Replace With:
Code: [Select]
//add user fields to update
for($i = 1; $i <= $CONFIG['user_field_num']; $i++)
{
$update .= ", user$i = '".addslashes($userFields[$i-1])."'";
}


editOnePic.php

Find:
Code: [Select]
$user1        = $_POST['user1'];
                $user2        = $_POST['user2'];
                $user3        = $_POST['user3'];
                $user4        = $_POST['user4'];

Replace With:
Code: [Select]
//add user fields to array
for($i = 1; $i <= $CONFIG['user_field_num']; $i++)
{
$userFields[]=$_POST["user$i"];
}

Find:
Code: [Select]
$THUMB_ROWSPAN=6;
if ($CONFIG['user_field1_name'] != '') $THUMB_ROWSPAN++;
if ($CONFIG['user_field2_name'] != '') $THUMB_ROWSPAN++;
if ($CONFIG['user_field3_name'] != '') $THUMB_ROWSPAN++;
if ($CONFIG['user_field4_name'] != '') $THUMB_ROWSPAN++;

Replace With:
Code: [Select]
$THUMB_ROWSPAN=6;
for($i = 1; $i <= $CONFIG['user_field_num']; $i++)
{
if ($CONFIG["user_field$1_name"] != '') $THUMB_ROWSPAN++;
}

Find:
Code: [Select]
                $update .= ", user1 = '".addslashes($user1)."'";
                $update .= ", user2 = '".addslashes($user2)."'";
                $update .= ", user3 = '".addslashes($user3)."'";
                $update .= ", user4 = '".addslashes($user4)."'";


Replace With:
Code: [Select]
//add user fields to update
for($i = 1; $i <= $CONFIG['user_field_num']; $i++)
{
$update .= ", user$i = '".addslashes($userFields[$i-1])."'";
}


Find:
Code: [Select]
if ($CONFIG['user_field1_name'] != ''){
echo <<<EOT
        <tr>
            <td class="tableb" style="white-space: nowrap;">
                {$CONFIG['user_field1_name']}
                </td>
                <td width="100%" class="tableb" valign="top">
                                <input type="text" style="width: 100%" name="user1" maxlength="255" value="{$CURRENT_PIC['user1']}" class="textinput" />
                        </td>
        </tr>
EOT;
}
if ($CONFIG['user_field2_name'] != ''){
echo <<<EOT
        <tr>
            <td class="tableb" style="white-space: nowrap;">
                {$CONFIG['user_field2_name']}
                </td>
                <td width="100%" class="tableb" valign="top">
                <input type="text" style="width: 100%" name="user2" maxlength="255" value="{$CURRENT_PIC['user2']}" class="textinput" />
                        </td>
        </tr>
EOT;
}if ($CONFIG['user_field3_name'] != ''){
echo <<<EOT
        <tr>
            <td class="tableb" style="white-space: nowrap;">
                {$CONFIG['user_field3_name']}
                </td>
                <td width="100%" class="tableb" valign="top">
                <input type="text" style="width: 100%" name="user3" maxlength="255" value="{$CURRENT_PIC['user3']}" class="textinput" />
                        </td>
        </tr>
EOT;
}if ($CONFIG['user_field4_name'] != ''){
echo <<<EOT
        <tr>
            <td class="tableb" style="white-space: nowrap;">
                {$CONFIG['user_field4_name']}
                </td>
                <td width="100%" class="tableb" valign="top">
                <input type="text" style="width: 100%" name="user4" maxlength="255" value="{$CURRENT_PIC['user4']}" class="textinput" />
                        </td>
        </tr>
EOT;
}

Replace With:
Code: [Select]
//print out form fields
for($i = 1; $i <= $CONFIG['user_field_num']; $i++)
{
$uFN = "user_field" . $i . "_name";
$uI = "user" . $i;
if ($CONFIG[$uFN] != ''){
echo <<<EOT
        <tr>
            <td class="tableb" style="white-space: nowrap;">
                {$CONFIG[$uFN]}
                </td>
                <td width="100%" class="tableb" valign="top">
                                <input type="text" style="width: 97%" name="$uI" maxlength="255" value="{$CURRENT_PIC[$uI]}" class="textinput" />
                        </td>
        </tr>
EOT;
}
}

« Last Edit: July 09, 2006, 01:29:53 am by GauGau »
Logged

pslawinski

  • Contributor
  • Coppermine novice
  • ***
  • Offline Offline
  • Gender: Male
  • Posts: 48
    • Lighting-Gallery.net
Re: Add More Custom Fields via Config
« Reply #1 on: November 13, 2005, 12:16:54 am »

db_input.php

Find:
Code: [Select]
        $user1 = addslashes($_POST['user1']);
        $user2 = addslashes($_POST['user2']);
        $user3 = addslashes($_POST['user3']);
        $user4 = addslashes($_POST['user4']);


Replace With;
Code: [Select]
//add user fields to array
for($i = 1; $i <= $CONFIG['user_field_num']; $i++)
{
$uI = "user" . $i;
$userFields[]=addslashes($HTTP_POST_VARS[$uI]);
}


Find:
Code: [Select]
$result = add_picture($album, $filepath, $picture_name, 0, $title, $caption, $keywords, $user1, $user2, $user3, $user4, $category, $raw_ip, $hdr_ip,(int) $_POST['width'],(int) $_POST['height']);

Replace With:
Code: [Select]
$result = add_picture($album, $filepath, $picture_name, 0, $title, $caption, $keywords, $userFields, $category, $raw_ip, $hdr_ip,(int) $_POST['width'],(int) $_POST['height']);


include/picmgmt.inc.php

Find:
Code: [Select]
function add_picture($aid, $filepath, $filename, $position = 0, $title = '', $caption = '', $keywords = '', $user1 = '', $user2 = '', $user3 = '', $user4 = '', $category = 0, $raw_ip = '', $hdr_ip = '')

Replace With:
Code: [Select]
function add_picture($aid, $filepath, $filename, $position = 0, $title = '', $caption = '', $keywords = '', $userFields = array(), $category = 0, $raw_ip = '', $hdr_ip = '')

Find:
Code: [Select]
    $CURRENT_PIC_DATA['user1'] = $user1;
    $CURRENT_PIC_DATA['user2'] = $user2;
    $CURRENT_PIC_DATA['user3'] = $user3;
    $CURRENT_PIC_DATA['user4'] = $user4;
    $CURRENT_PIC_DATA['pic_raw_ip'] = $raw_ip;
    $CURRENT_PIC_DATA['pic_hdr_ip'] = $hdr_ip;
    $CURRENT_PIC_DATA['position'] = $position;
    $CURRENT_PIC_DATA = CPGPluginAPI::filter('add_file_data',$CURRENT_PIC_DATA);

    $query = "INSERT INTO {$CONFIG['TABLE_PICTURES']} (pid, aid, filepath, filename, filesize, total_filesize, pwidth, pheight, ctime, owner_id, owner_name, title, caption, keywords, approved, user1, user2, user3, user4, pic_raw_ip, pic_hdr_ip, position) VALUES ('', '{$CURRENT_PIC_DATA['aid']}', '" . addslashes($CURRENT_PIC_DATA['filepath']) . "', '" . addslashes($CURRENT_PIC_DATA['filename']) . "', '{$CURRENT_PIC_DATA['filesize']}', '{$CURRENT_PIC_DATA['total_filesize']}', '{$CURRENT_PIC_DATA['pwidth']}', '{$CURRENT_PIC_DATA['pheight']}', '" . time() . "', '{$CURRENT_PIC_DATA['owner_id']}', '{$CURRENT_PIC_DATA['owner_name']}','{$CURRENT_PIC_DATA['title']}', '{$CURRENT_PIC_DATA['caption']}', '{$CURRENT_PIC_DATA['keywords']}', '{$CURRENT_PIC_DATA['approved']}', '{$CURRENT_PIC_DATA['user1']}', '{$CURRENT_PIC_DATA['user2']}', '{$CURRENT_PIC_DATA['user3']}', '{$CURRENT_PIC_DATA['user4']}', '{$CURRENT_PIC_DATA['pic_raw_ip']}', '{$CURRENT_PIC_DATA['pic_hdr_ip']}', '{$CURRENT_PIC_DATA['position']}')";

Replace With:
Code: [Select]
    for($i = 1; $i <= $CONFIG['user_field_num']; $i++)
{
$CURRENT_PIC_DATA["user$i"] = $userFields[$i-1];
}
    $CURRENT_PIC_DATA['pic_raw_ip'] = $raw_ip;
    $CURRENT_PIC_DATA['pic_hdr_ip'] = $hdr_ip;
    $CURRENT_PIC_DATA['position'] = $position;
    $CURRENT_PIC_DATA = CPGPluginAPI::filter('add_file_data',$CURRENT_PIC_DATA);

//Create query string
$rowNames = '';
$rowData = '';
    for($i = 1; $i <= $CONFIG['user_field_num']; $i++)
{
$rowNames .= "user$i, ";
$rowData .= "'" . $userFields[$i-1] . "', ";
}

    $query = "INSERT INTO {$CONFIG['TABLE_PICTURES']} (pid, aid, filepath, filename, filesize, total_filesize, pwidth, pheight, ctime, owner_id, owner_name, title, caption, keywords, approved, $rowNames pic_raw_ip, pic_hdr_ip, position) VALUES ('', '{$CURRENT_PIC_DATA['aid']}', '" . addslashes($CURRENT_PIC_DATA['filepath']) . "', '" . addslashes($CURRENT_PIC_DATA['filename']) . "', '{$CURRENT_PIC_DATA['filesize']}', '{$CURRENT_PIC_DATA['total_filesize']}', '{$CURRENT_PIC_DATA['pwidth']}', '{$CURRENT_PIC_DATA['pheight']}', '" . time() . "', '{$CURRENT_PIC_DATA['owner_id']}', '{$CURRENT_PIC_DATA['owner_name']}','{$CURRENT_PIC_DATA['title']}', '{$CURRENT_PIC_DATA['caption']}', '{$CURRENT_PIC_DATA['keywords']}', '{$CURRENT_PIC_DATA['approved']}', $rowData '{$CURRENT_PIC_DATA['pic_raw_ip']}', '{$CURRENT_PIC_DATA['pic_hdr_ip']}', '{$CURRENT_PIC_DATA['position']}')";


displayimage.php

Find:
Code: [Select]
    for ($i = 1; $i <= 4; $i++) {
        if ($CONFIG['user_field' . $i . '_name']) {
            if ($CURRENT_PIC_DATA['user' . $i] != "") {
                $info[$CONFIG['user_field' . $i . '_name']] = make_clickable($CURRENT_PIC_DATA['user' . $i]);
            }
        }
    }


Replace With:
Code: [Select]
    for($i = 1; $i <= $CONFIG['user_field_num']; $i++)
{
        if ($CONFIG['user_field' . $i . '_name'])
{
            if ($CURRENT_PIC_DATA['user' . $i] != "")
    {
                $info[$CONFIG['user_field' . $i . '_name']] = make_clickable($CURRENT_PIC_DATA['user' . $i]);
            }
        }
    }



After editing all files upload them to your server and enjoy being able to add custom fields from the config page.

I've added a grab from my admin menu showing the fields.
« Last Edit: July 08, 2006, 07:37:42 pm by pslawinski »
Logged

rrhode

  • Coppermine newbie
  • Offline Offline
  • Posts: 14
Re: Add More Custom Fields via Config
« Reply #2 on: January 27, 2006, 04:04:32 am »

I like the looks of this mod, and got it nearly working.  But it is telling me a database error when I try to save a picture.

Critical error
There was an error while processing a database query

I am not sure which file it is, possible the database one.  db_input.php on account it is a database query.  But maybe it is the picmgmt.inc.php file even.  I am not sure.  Maybe it is the image_processor.php or admin.php.  I susplect one of these 4 files but I am not sure which it could be.  Is there any way to fix this?  I copied everything alright but still get this error.

Thanks!  This is an awesome mod and I got to to work in the config and show the fields and everything.  Its really cool.  Thank you for your marvelous work!

Ryan
Logged

rrhode

  • Coppermine newbie
  • Offline Offline
  • Posts: 14
Re: Add More Custom Fields via Config
« Reply #3 on: January 27, 2006, 04:40:06 am »

I feel like this is a bit odd.

Code: [Select]
//Create query string
$rowNames = '';
$rowData = '';
    for($i = 1; $i <= $CONFIG['user_field_num']; $i++)
{
$rowNames .= "user$i, ";
$rowData .= "'" . $userFields[$i-1] . "', ";
}

    $query = "INSERT INTO {$CONFIG['TABLE_PICTURES']} (pid, aid, filepath, filename, filesize, total_filesize, pwidth, pheight, ctime, owner_id, owner_name, title, caption, keywords, approved, [b]$rowNames[/b] pic_raw_ip, pic_hdr_ip, position) VALUES ('', '{$CURRENT_PIC_DATA['aid']}', '" . addslashes($CURRENT_PIC_DATA['filepath']) . "', '" . addslashes($CURRENT_PIC_DATA['filename']) . "', '{$CURRENT_PIC_DATA['filesize']}', '{$CURRENT_PIC_DATA['total_filesize']}', '{$CURRENT_PIC_DATA['pwidth']}', '{$CURRENT_PIC_DATA['pheight']}', '" . time() . "', '{$CURRENT_PIC_DATA['owner_id']}', '{$CURRENT_PIC_DATA['owner_name']}','{$CURRENT_PIC_DATA['title']}', '{$CURRENT_PIC_DATA['caption']}', '{$CURRENT_PIC_DATA['keywords']}', '{$CURRENT_PIC_DATA['approved']}', [b]$rowData[/b] '{$CURRENT_PIC_DATA['pic_raw_ip']}', '{$CURRENT_PIC_DATA['pic_hdr_ip']}', '{$CURRENT_PIC_DATA['position']}')";

The way it uses the $rowNames and $rowdata just doesnt seem right to me but I cant figure out what to do with it.  Any ideas?
Logged

Tranz

  • Dev Team member
  • Coppermine addict
  • ****
  • Country: 00
  • Offline Offline
  • Gender: Female
  • Posts: 6149
Re: Add More Custom Fields via Config
« Reply #4 on: January 27, 2006, 05:02:49 am »

Go to Config and enable debug mode. Then go back to the page and you should get a more detailed error message.
Logged

rrhode

  • Coppermine newbie
  • Offline Offline
  • Posts: 14
Re: Add More Custom Fields via Config
« Reply #5 on: January 27, 2006, 11:33:16 pm »

Thanks!  That did the trick.  I never even realized there was a debug mode I should use.  Very nice!

Ok, well the message it is saying is mySQL error: Unknown column 'user5' in 'field list'

Which means I have to create those extra fields in the database which is fine.  I thought I saw some code that did that though but maybe I am wrong.  It is the only problem and I can easily create those columns in the database.

Thanks again!

Ryan
Logged

rrhode

  • Coppermine newbie
  • Offline Offline
  • Posts: 14
Re: Add More Custom Fields via Config
« Reply #6 on: January 27, 2006, 11:41:31 pm »

oh and maybe it has something to do with the google maps thing I am using too but I dont think it is.  I think it fails to create the extra user fields thats all.

I will send you the debug info so you can see it.

This appears at the error box.

While executing query "UPDATE cpg142_pictures SET aid = '6', title = 'test', caption = 'test', keywords = 'test', user1 = '', user2 = '', user3 = '', user4 = '', user5 = '', user6 = '', user7 = '', user8 = '', user9 = '', user10 = '', latitude = '33.74832232784014', longitude = '-84.39216613769531' WHERE pid='5' LIMIT 1" on 0

mySQL error: Unknown column 'user5' in 'field list'


This is the debug info.

USER:
------------------
Array
(
    [ID] => 25279aea3d53206717f5cbe9960ee4fb
    [am] => 1
    [lang] => english
    [liv] => Array
        (
           
  • => 1
  • [1] => 3
                [2] => 4
                [3] => 5
            )

    )

    ==========================
    USER DATA:
    ------------------
    Array
    (
       
[user_id] => 1
    [user_name] => admin
    [groups] => Array
        (
           
  • => 1

        )

    [disk_max] => 0
    [disk_min] => 0
    [can_rate_pictures] => 0
    [can_send_ecards] => 1
    [ufc_max] => 3
    [ufc_min] => 3
    [custom_user_upload] => 0
    [num_file_upload] => 5
    [num_URI_upload] => 3
    [can_post_comments] => 0
    [can_upload_pictures] => 0
    [can_create_albums] => 1
    [has_admin_access] => 1
    [pub_upl_need_approval] => 0
    [priv_upl_need_approval] => 0
    [group_name] => Administrators
    [upload_form_config] => 3
    [group_quota] => 0
    [can_see_all_albums] => 1
    [group_id] => 1
)

==========================
Queries:
------------------
Array
(
   
  • => SELECT extension, mime, content, player FROM cpg142_filetypes; (0.002s)
  • [1] => select * from cpg142_plugins order by priority asc; (0.001s)
        [2] => delete from `kan145gh`.cpg142_sessions where time<1138397142 and remember=0; (0.001s)
        [3] => delete from `kan145gh`.cpg142_sessions where time<1137191142; (0.001s)
        [4] => select user_id from `kan145gh`.cpg142_sessions where session_id=md5("9e9c2de0d6699f6f64ce463e536ebf260b6e1a608ffb2cd153e381201a336529"); (0.001s)
        [5] => select user_id as id, user_password as password from `kan145gh`.cpg142_users where user_id=1 (0.001s)
        [6] => SELECT u.user_id AS id, u.user_name AS username, u.user_password AS password, u.user_group+100 AS group_id FROM `kan145gh`.cpg142_users AS u INNER JOIN `kan145gh`.cpg142_usergroups AS g ON u.user_group=g.group_id WHERE u.user_id='1' (0s)
        [7] => SELECT user_group_list FROM `kan145gh`.cpg142_users AS u WHERE user_id='1' and user_group_list <> ''; (0s)
        [8] => SELECT MAX(group_quota) as disk_max, MIN(group_quota) as disk_min, MAX(can_rate_pictures) as can_rate_pictures, MAX(can_send_ecards) as can_send_ecards, MAX(upload_form_config) as ufc_max, MIN(upload_form_config) as ufc_min, MAX(custom_user_upload) as custom_user_upload, MAX(num_file_upload) as num_file_upload, MAX(num_URI_upload) as num_URI_upload, MAX(can_post_comments) as can_post_comments, MAX(can_upload_pictures) as can_upload_pictures, MAX(can_create_albums) as can_create_albums, MAX(has_admin_access) as has_admin_access, MIN(pub_upl_need_approval) as pub_upl_need_approval, MIN( priv_upl_need_approval) as  priv_upl_need_approval FROM cpg142_usergroups WHERE group_id in (1) (0.001s)
        [9] => SELECT group_name FROM  cpg142_usergroups WHERE group_id= 1 (0.001s)
        [10] => update `kan145gh`.cpg142_sessions set time='1138400742' where session_id=md5('9e9c2de0d6699f6f64ce463e536ebf260b6e1a608ffb2cd153e381201a336529'); (0.001s)
        [11] => SELECT user_favpics FROM cpg142_favpics WHERE user_id = 1 (0.001s)
        [12] => DELETE FROM cpg142_banned WHERE expiry < '2006-01-27 22:25:42' (0.001s)
        [13] => SELECT * FROM cpg142_banned WHERE (ip_addr='70.49.0.139' OR ip_addr='70.49.0.139' OR user_id=1) AND brute_force=0 (0.003s)
        [14] => SELECT p.* FROM cpg142_pictures AS p, cpg142_albums AS a WHERE a.aid = p.aid AND pid = '5' (0.001s)
        [15] => UPDATE cpg142_pictures SET aid = '6', title = 'test', caption = 'test', keywords = 'test', user1 = '', user2 = '', user3 = '', user4 = '', user5 = '', user6 = '', user7 = '', user8 = '', user9 = '', user10 = '', latitude = '33.74832232784014', longitude = '-84.39216613769531' WHERE pid='5' LIMIT 1 (0.001s)
        [16] => SELECT COUNT(*) FROM cpg142_pictures WHERE approved = 'NO' (0.001s)
    )

    ==========================
    GET :
    ------------------
    Array
    (
    )

    ==========================
    POST :
    ------------------
    Array
    (
       
[id] => 5
    [aid] => 6
    [title] => test
    [filename] => 8sheet.jpg
    [caption] => test
    [keywords] => test
    [user1] => test
    [user2] => test
    [user3] => test
    [user4] => test
    [user5] =>
    [user6] =>
    [user7] =>
    [user8] =>
    [user9] =>
    [user10] =>
    [coordinates] => 33.74832232784014,-84.39216613769531
    [submitDescription] => Apply modifications
)

==========================
VERSION INFO :
------------------
PHP version: 4.3.11 - OK
------------------
mySQL version: 4.0.24-max-log
------------------
Coppermine version: 1.4.3(stable)
==========================
Module: GD
------------------
GD Version: bundled (2.0.28 compatible)
FreeType Support: 1
FreeType Linkage: with freetype
T1Lib Support:
GIF Read Support: 1
GIF Create Support: 1
JPG Support: 1
PNG Support: 1
WBMP Support: 1
XBM Support: 1
JIS-mapped Japanese Font Support:

==========================
Module: mysql
------------------
MySQL Supportenabled
Active Persistent Links 0
Active Links 1
Client API version 3.23.49
MYSQL_MODULE_TYPE builtin
MYSQL_SOCKET /tmp/mysql.sock
MYSQL_INCLUDE no value
MYSQL_LIBS no value
==========================
Module: zlib
------------------
ZLib Support enabled
Compiled Version 1.1.4
Linked Version 1.1.4
==========================
Server restrictions (safe mode)?
------------------
Directive | Local Value | Master Value
safe_mode | Off | Off
safe_mode_exec_dir | no value | no value
safe_mode_gid | Off | Off
safe_mode_include_dir | ~ | ~
safe_mode_exec_dir | no value | no value
sql.safe_mode | Off | Off
disable_functions | no value | no value
file_uploads | On | On
include_path | .:/usr/local/lib/php | .:/usr/local/lib/php
open_basedir | no value | no value
==========================
email
------------------
Directive | Local Value | Master Value
sendmail_from | me@localhost.com | me@localhost.com
sendmail_path | /usr/sbin/sendmail -t -i  | /usr/sbin/sendmail -t -i
SMTP | relay-hosting.secureserver.net | relay-hosting.secureserver.net
smtp_port | 25 | 25
==========================
Size and Time
------------------
Directive | Local Value | Master Value
max_execution_time | 30 | 30
max_input_time | 60 | 60
upload_max_filesize | 8M | 8M
post_max_size | 8M | 8M
==========================
Page generated in 0.097 seconds - 17 queries in 0.018 seconds - Album set : ; Meta set: ;
Logged

rrhode

  • Coppermine newbie
  • Offline Offline
  • Posts: 14
Re: Add More Custom Fields via Config
« Reply #7 on: January 28, 2006, 12:05:03 am »

Hmmm, interesting.  Now it saves nothing to the user fields.  blank.

So maybe my theory that the $rowname and $rowuser was right because they dont appear to be sending the info through.  Or maybe there is something before that even that isnt working right.   ???

I dont know but I will have to soon find out, but first, some really awesome veggie lasagna.  My girlfriend makes the best lasagna in the world I think and I am not going to think clearly until I eat some.
Logged

rrhode

  • Coppermine newbie
  • Offline Offline
  • Posts: 14
Re: Add More Custom Fields via Config
« Reply #8 on: January 30, 2006, 09:52:05 pm »

Does anyone have any idea from what i have posted here why it isnt saving the user fields?  Thanks :D
Logged

Ian MacMillan

  • Coppermine newbie
  • Offline Offline
  • Gender: Male
  • Posts: 14
    • Conrail's NH Division in N scale
Re: Add More Custom Fields via Config
« Reply #9 on: February 08, 2006, 07:13:36 pm »

Same issues here, nothing saving and having to manually add the fields in the db.
Logged
Yeah, I like that!

pslawinski

  • Contributor
  • Coppermine novice
  • ***
  • Offline Offline
  • Gender: Male
  • Posts: 48
    • Lighting-Gallery.net
Re: Add More Custom Fields via Config
« Reply #10 on: February 08, 2006, 09:03:59 pm »

Okay, I think I see the problem here.  It appears that the extra user info fields in the pictures table are missing.  I'll look over the code and try this again later today.  For now I suggest that you manually add the extra cols to your pictures table e.g. user5, user6...
Logged

fredt

  • Coppermine newbie
  • Offline Offline
  • Posts: 1
Re: Add More Custom Fields via Config
« Reply #11 on: April 19, 2006, 09:09:14 am »

Where did this get to?
I love the mod - it became the tipping point for selecting Coppermine.

I added 16 fields - all came up in the config files.  Uploaded some images using Batch upload. The first image accepted my data in each fieled - and every image after that repeated the same data as contained in the first image.   Checked the datatbase - all 20 user fields are there.

Then went to edit the data for each image - nothing changed.  Checked with debug running.  Debug does not report anything - in fact it appears that nothing happened at all.
Any thoughts?
Fred
Logged

pslawinski

  • Contributor
  • Coppermine novice
  • ***
  • Offline Offline
  • Gender: Male
  • Posts: 48
    • Lighting-Gallery.net
Re: Add More Custom Fields via Config
« Reply #12 on: April 19, 2006, 06:26:31 pm »

Perhaps what this mod really needs is a rewrite.  I coded the mod for my coppermine install specifically and then rewrote it to work on the regular version.  It appears that the error is occuring with the code that automatically adds the necessary fields to the DB.  I can look into this later this week perhaps, unless someone beats me to it.

@Fred  It sounds as if the data is not being written to your database, however, I can't be sure.
Logged

flar

  • Coppermine newbie
  • Offline Offline
  • Posts: 13
Re: Add More Custom Fields via Config
« Reply #13 on: April 24, 2006, 03:15:11 pm »

One contribution to make this change (slightly) smaller in scope.  The first mod to lang/english.php to add the new form fields to $lang_admin_data can be made less invasive using the array_push() function as follows (with 1 unmodified line at top and bottom for context):
Code: [Select]
  array('Field 4 name', 'user_field4_name', 0),
);

//let's start the count at 5 since 4 fields have already been declared
for($i = 5; $i <= $CONFIG['user_field_num']; $i++)
{
       $lang_admin_data[] = array("Field " . $i . " name", "user_field" . $i . "_name", 0);
}

array_push($lang_admin_data,
  'Cookies settings',
With this code, one more change is needed, which is to remove the final comma from the last line in the array() initializer since a trailing comma is valid in an array() operator, but not in an array_push() function call.  Change this (only middle line has changed):
Code: [Select]
  array('Display notices in debug mode', 'debug_notice', 1, 'f=index.htm&amp;as=admin_misc_debug_notices&amp;ae=admin_misc_debug_notices_end'), //cpg1.4
  array('Gallery is offline', 'offline', 1, 'f=index.htm&amp;as=admin_general_offline&amp;ae=admin_general_offline_end'), //cpg1.4
);
to this:
Code: [Select]
  array('Display notices in debug mode', 'debug_notice', 1, 'f=index.htm&amp;as=admin_misc_debug_notices&amp;ae=admin_misc_debug_notices_end'), //cpg1.4
  array('Gallery is offline', 'offline', 1, 'f=index.htm&amp;as=admin_general_offline&amp;ae=admin_general_offline_end') //cpg1.4
);
Logged

flar

  • Coppermine newbie
  • Offline Offline
  • Posts: 13
Re: Add More Custom Fields via Config
« Reply #14 on: April 25, 2006, 01:26:37 am »

[My apologies if some of the following sounds like newbie SQL questions - I do not come from an SQL background, though I've done a small bit of cut-and-past SQL work based on reading some tutorials.]

I was looking to modify this in a couple of ways, but I have some questions which someone who is more familiar with SQL can help me with:

First, the ideas I was going to pursue:
  • I was planning to have the "number of user fields" form entry appear in the same tabbed group on the config page as the field names themselves.  The fix as proposed looks like it creates a whole new config tab for that setting, but that seemed unnecessary to me.
  • I was going to add the new rows to _config and the new columns to _pictures when the "number of user fields" was changed on the config screen, rather than trying to "auto add them when they are used" later.  This seems more straightforward and hopefully more robust.
  • I was going to leave old fields in the database if the number of fields was ever reduced.  Possibly add an "admin tool" to "discard unreferenced user field data" by explicit action of a gallery administrator.  I could go either way on that, but it seems less destructive to only delete data when they specifically request it and you can describe to them that the data cannot be recovered - which seems easier to do on the Admin Tools page...
Feedback on those plans would be appreciated, but meanwhile...

I'm pretty sure I can get started on this if I keep a field 'user_field_created_count' in the _config table that remembers how many such fields have already been created, but it would be nice to base it on the structure of the database instead as I think it is a weak design to store (meta-)data in the database which describes the structure of the database.  Unfortunately, that is where my SQL knowledge reaches its point of confusion over what kinds of statements are portable (in general and/or relative to the portability concerns of this code base).  Tutorials and code inspection have taught me the basics, but I have no formal SQL training nor much experience to know what is good for the long run.

I suppose I could also do queries on the _config table for "user_fieldN_name" and check the cardinality of the result set, but that doesn't help with the columns in the _pictures table (though I suppose I could infer that the columns exist from whether or not the field_name row exists in _config).  Also, if I'm going to go with a meta-data solution, 'user_field_created_count' is a bit more straightforward and quick to implement.
Logged

flar

  • Coppermine newbie
  • Offline Offline
  • Posts: 13
Re: Add More Custom Fields via Config
« Reply #15 on: April 25, 2006, 04:58:19 am »

OK, here is some code to automatically add the field_name rows to the _config table and the userN columns to the _pictures table.  Note that it modifies the database as soon as you change the number of fields on the config web page.  Also, it deletes all of the old data if you lower the value (but doesn't let you lower it below 4):

Find this in admin.php (near line 820):
Code: [Select]
                if ($CONFIG[$element[1]] !== stripslashes($value))
                     {

and add this right after it (inside the braces):
Code: [Select]
                        //handle changes in 'user_field_num'
                        if ($element[1] == 'user_field_num') {
                            if (!isset($CONFIG['user_field_count'])) {
                                cpg_db_query("INSERT INTO {$CONFIG['TABLE_CONFIG']} ( `name` , `value` ) VALUES ('user_field_count', '4')");
                                $userfieldcount = 4;
                            } else {
                                $userfieldcount = $CONFIG['user_field_count'];
                            }
                            $newfieldcount = max(4, (int)$value);
                            for ($i = $userfieldcount+1; $i <= $newfieldcount; $i++) {
                                $fldname = "user_field" . $i . "_name";
                                cpg_db_query("INSERT INTO {$CONFIG['TABLE_CONFIG']} ( `name` , `value` ) VALUES ('{$fldname}', '')");
                                $fldname = "user" . $i;
                                cpg_db_query("ALTER TABLE {$CONFIG['TABLE_PICTURES']} ADD $fldname varchar(255) NOT NULL");
                            }
                            for ($i = $userfieldcount; $i > $newfieldcount; $i--) {
                                $fldname = "user_field" . $i . "_name";
                                cpg_db_query("DELETE FROM {$CONFIG['TABLE_CONFIG']} WHERE name = '{$fldname}'");
                                $fldname = "user" . $i;
                                cpg_db_query("ALTER TABLE {$CONFIG['TABLE_PICTURES']} DROP COLUMN $fldname");
                            }
                            cpg_db_query("UPDATE {$CONFIG['TABLE_CONFIG']} SET value = '$newfieldcount' WHERE name = 'user_field_count'");
                            $value = $newfieldcount;  // make sure minimum value is 4
                        }

Using this code the only manual change you need to make to your database is to create the 'user_field_num' entry in your _config table, modify your other files as indicated previously, then go to the Config page, change the number of fields, save the new configuration, and the database should be modified.  Go back to the Config page and now you should be able to enter field names for all of the new user fields, etc.
Logged

pslawinski

  • Contributor
  • Coppermine novice
  • ***
  • Offline Offline
  • Gender: Male
  • Posts: 48
    • Lighting-Gallery.net
Re: Add More Custom Fields via Config
« Reply #16 on: April 25, 2006, 05:04:52 am »

Thanks for your additions flar.  I have to admit that I have not looked at this code for quite some time and I was not looking forward to the prospect of having to dig it back up.
Logged

Dr Preacox

  • Contributor
  • Coppermine frequent poster
  • ***
  • Offline Offline
  • Gender: Male
  • Posts: 122
  • Is the Matrix...
    • Dynamic Creations
Re: Add More Custom Fields via Config
« Reply #17 on: May 23, 2006, 08:32:50 pm »

any chance of getting this in a plugin?
Logged
My Mods:
Making Memberlist Public - VIEW
Different Way of Displaying Categories - VIEW
Coming Soon - Automated Sub Domains -MOD

pslawinski

  • Contributor
  • Coppermine novice
  • ***
  • Offline Offline
  • Gender: Male
  • Posts: 48
    • Lighting-Gallery.net
Re: Add More Custom Fields via Config
« Reply #18 on: May 24, 2006, 03:59:11 am »

Unfortunately it is impossible to make this a plugin.
Logged

Dr Preacox

  • Contributor
  • Coppermine frequent poster
  • ***
  • Offline Offline
  • Gender: Male
  • Posts: 122
  • Is the Matrix...
    • Dynamic Creations
Re: Add More Custom Fields via Config
« Reply #19 on: May 26, 2006, 10:32:06 am »

god this will take a whie to add this into the gallery, if i upgrade the gallery i lose all the changes right?
Logged
My Mods:
Making Memberlist Public - VIEW
Different Way of Displaying Categories - VIEW
Coming Soon - Automated Sub Domains -MOD
Pages: [1] 2 3   Go Up
 

Page created in 0.041 seconds with 20 queries.