Author Topic: Digital cameras - Dropdown menu  (Read 13589 times)

0 Members and 1 Guest are viewing this topic.

Offline Lucifix

  • Hero Member
  • *****
  • Posts: 710
    • View Profile
    • http://www.slo-foto.net
Digital cameras - Dropdown menu
« on: September 23, 2006, 03:28:47 AM »
Hi!

I have created this SQL table 4images_cameras includes list of digital cameras. I need to insert camera value in 4image_images table - image_cameras field (which was selected by the member in member_upload.html file).

4images_cameras SQL table:
Code: [Select]
CREATE TABLE `4images_cameras` (
  `id_cam` mediumint(8) NOT NULL default '0',
  `name_cam` varchar(255) character set latin1 NOT NULL default '',
  `count_cam` smallint(6) NOT NULL default '0',
  PRIMARY KEY  (`id_cam`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_slovenian_ci;

In member.php I added this code:
Code: [Select]
//-----------------------------------------------------
// --- Choose camera - Start --------------------------
//-----------------------------------------------------

$sql = "SELECT id_cam, name_cam FROM 4images_cameras ORDER BY name_cam";
$result = mysql_query($sql);

  $image_cameras .= "<select name=\"id_cam\">";
  $image_cameras .= "<option value=\"0\">-- Izberite fotoaparat --</option>";
while($row = mysql_fetch_array($result)){
  $image_cameras .= "<option value=\"$row[id_cam]\" name=\"image_cameras\">$row[name_cam]</option>";
}
  $image_cameras .= "</select>";

$site_template->register_vars("image_cameras", $image_cameras);
unset($image_cameras);
//-----------------------------------------------------
// --- Choose camera - End ----------------------------
//-----------------------------------------------------

I modified code:
Code: [Select]
       if ($direct_upload) {
        $sql = "INSERT INTO ".IMAGES_TABLE."
and insert image_cameras and '$images_cameras'.

Also added in member_upload.html to show dropdown menu:
Code: [Select]
{image_cameras}
I must have missed something becouse image_cameras value doesn't want to insert in images_cameras field.

Got any idea?

Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Global Moderator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
Re: Digital cameras - Dropdown menu
« Reply #1 on: September 23, 2006, 04:24:41 AM »
where is your $images_cameras variable being populated?
Your first three "must do" before you ask a question:
Please do not PM me asking for help unless you've been specifically asked to do so. Such PMs will be deleted without answer. (forum rule #6)
Extension for Firefox/Thunderbird: Master Password+    Back/Forward History Tweaks (restartless)    Cookies Manager+    Fit Images (restartless for Thunderbird)

Offline Lucifix

  • Hero Member
  • *****
  • Posts: 710
    • View Profile
    • http://www.slo-foto.net
Re: Digital cameras - Dropdown menu
« Reply #2 on: September 23, 2006, 12:13:52 PM »
This is where I could use some help.

I tried to insert this above INSERT TABLE, but didn't work:

Code: [Select]
  $image_cameras = un_htmlspecialchars(trim($HTTP_POST_VARS['image_cameras']));

Offline Lucifix

  • Hero Member
  • *****
  • Posts: 710
    • View Profile
    • http://www.slo-foto.net
Re: Digital cameras - Dropdown menu
« Reply #3 on: September 23, 2006, 12:16:39 PM »
I also find little bug.

this:
Code: [Select]
  $image_cameras .= "<select name=\"id_cam\">";
should be replaced with:
Code: [Select]
  $image_cameras .= "<select name=\"image_cameras\">";
I forgot to tell you that I have added extra field in 4images_images table: image_cameras
« Last Edit: September 23, 2006, 12:34:42 PM by Lucifix »

Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Global Moderator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
Re: Digital cameras - Dropdown menu
« Reply #4 on: September 23, 2006, 06:22:31 PM »
and <option> should not have any name ;)
Make sure you added info about your new field into db_field_definitions.php
once you did that, no other code need to save the result into the database, 4images will automaticaly do it.
Your first three "must do" before you ask a question:
Please do not PM me asking for help unless you've been specifically asked to do so. Such PMs will be deleted without answer. (forum rule #6)
Extension for Firefox/Thunderbird: Master Password+    Back/Forward History Tweaks (restartless)    Cookies Manager+    Fit Images (restartless for Thunderbird)

Offline Lucifix

  • Hero Member
  • *****
  • Posts: 710
    • View Profile
    • http://www.slo-foto.net
Re: Digital cameras - Dropdown menu
« Reply #5 on: September 23, 2006, 08:03:19 PM »
I don't know why but I simply don't have luck with coding :roll:

But if I listen to your advice no dropdown menu is shown.
Code: [Select]
//-----------------------------------------------------
// --- Choose camera - Start --------------------------
//-----------------------------------------------------

$sql = "SELECT id_cam, name_cam FROM 4images_cameras ORDER BY name_cam";
$result = mysql_query($sql);

  $image_cameras .= "<select name=\"image_cameras\" >";
  $image_cameras .= "<option value=\"0\">-- Izberite fotoaparat --</option>";
while($row = mysql_fetch_array($result)){
  $image_cameras .= "<option value=\"$row[id_cam]\">$row[name_cam]</option>
";
}
  $image_cameras .= "</select>
";

$site_template->register_vars("image_cameras", $image_cameras);
unset($image_cameras);


//-----------------------------------------------------
// --- Choose camera - End ----------------------------
//-----------------------------------------------------

And in db_field_definitions.php:
Code: [Select]
$additional_image_fields['image_cameras'] = array("Izbrani fotoaparat", "text", 0);

Offline Lucifix

  • Hero Member
  • *****
  • Posts: 710
    • View Profile
    • http://www.slo-foto.net
Re: Digital cameras - Dropdown menu
« Reply #6 on: September 23, 2006, 09:03:18 PM »
I made it to show dropdown menu, now I only have to save id data in field.

Code: [Select]
//-----------------------------------------------------
// --- Choose camera - Start --------------------------
//-----------------------------------------------------

$sql = "SELECT id_cam, name_cam FROM 4images_cameras ORDER BY name_cam";
$result = mysql_query($sql);

  $image_cameras .= "<select name=\"image_cameras\">
                    <option value=\"0\">-- Izberite fotoaparat --</option>\n";
while($row = mysql_fetch_array($result)){
  $image_cameras .= "<option value=\"$row[id_cam]\">$row[name_cam]</option>
\n";
}

  $image_cameras .= "</select>";

//-----------------------------------------------------
// --- Choose camera - End ----------------------------
//-----------------------------------------------------

But without
Code: [Select]
$additional_image_fields['image_cameras'] = array("Izbrani fotoaparat", "text", 0);
Becouse if I insert it, dropdown won't show.

Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Global Moderator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
Re: Digital cameras - Dropdown menu
« Reply #7 on: September 23, 2006, 09:14:41 PM »
Becouse if I insert it, dropdown won't show.
its because your code that generates dropdown must be placed below the code that generates template tags for custom fields. i.e. above
Code: [Select]
  $content = $site_template->parse_template("member_uploadform");
Your first three "must do" before you ask a question:
Please do not PM me asking for help unless you've been specifically asked to do so. Such PMs will be deleted without answer. (forum rule #6)
Extension for Firefox/Thunderbird: Master Password+    Back/Forward History Tweaks (restartless)    Cookies Manager+    Fit Images (restartless for Thunderbird)

Offline Lucifix

  • Hero Member
  • *****
  • Posts: 710
    • View Profile
    • http://www.slo-foto.net
Re: Digital cameras - Dropdown menu
« Reply #8 on: September 23, 2006, 09:30:52 PM »
Thanks v@no!

Without you I wouldn't make it.

Offline Lucifix

  • Hero Member
  • *****
  • Posts: 710
    • View Profile
    • http://www.slo-foto.net
Re: Digital cameras - Dropdown menu
« Reply #9 on: September 24, 2006, 12:09:53 PM »
If anyone is interesting here is a full mode. I have also add extra category in admin panel, where you can edit, remove or add new cameras.


--------- [ Changed Files ] --------
member.php
details.php
admin/index.php
includes/db_field_definitions.php
lang/<your_language>/main.php
lang/<your_language>/admin.php
templates/<your template>/details.html
templates/<your template>/member_uploadform.html

---------- [ New files ] -----------
admin/cameras.php

---------- [ Installation ] -----------
Create new SQL table:

Code: [Select]
CREATE TABLE `4images_cameras111` (
  `id_cam` mediumint(8) NOT NULL default '0',
  `name_cam` varchar(255) character set latin1 NOT NULL default '',
  `count_cam` smallint(6) NOT NULL default '0',
  PRIMARY KEY  (`id_cam`)
)

Open member.php

Find:
Code: [Select]
      $site_template->register_vars($additional_field_array);
    }
  }

After add:
Code: [Select]
//-----------------------------------------------------
// --- Choose camera - Start --------------------------
//-----------------------------------------------------

$sql = "SELECT cam_id, cam_name FROM 4images_cameras ORDER BY cam_name";
$result = mysql_query($sql);

  $image_cameras .= "<select name=\"cam_id\">
                    <option value=\"0\" selected>-- Choose Camera --</option>\n";
while($row = mysql_fetch_array($result)){
  $image_cameras .= "<option value=\"$row[cam_id]\">$row[cam_name]</option>\n";
}

  $image_cameras .= "</select>";

$site_template->register_vars("image_cameras", $image_cameras);
//-----------------------------------------------------
// --- Choose camera - End ----------------------------
//-----------------------------------------------------


Open /admin/index.php

After:
Code: [Select]
show_nav_option($lang['nav_categories_add'], "categories.php?action=addcat");
Add:
Code: [Select]
          show_nav_header($lang['nav_cameras_main']);
          show_nav_option($lang['nav_cameras_edit'], "cameras.php?action=modifycams");
          show_nav_option($lang['nav_cameras_add'], "cameras.php?action=addcam");

Create new file named it: cameras.php and upload it in admin directory:
Code: [Select]
<?php


define
('IN_CP'1);
define('ROOT_PATH''./../');
require(
'admin_global.php');
include(
ROOT_PATH.'./includes/paging.php');
include(
ROOT_PATH.'includes/search_utils.php');

if (
$action == "") {
  
$action "modifycams";
}


show_admin_header();

if (
$action == "modifycams") {
global 
$site_db;


  echo 
"
<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\">
  <tr>
    <td class=\"tableborder\">
<table cellpadding=\"3\" cellspacing=\"1\" border=\"0\">
  <tr class=\"tableheader\">
    <td colspan=\"6\"><a name=\"\"><b><span class=\"tableheader\">Digital Cameras</span></b></a>
    </td>
  </tr>
  <tr class=\"tablerow\" valign=\"top\">
       <td>&nbsp;</td>
       <td><b>ID</b></td>
       <td><b>Camera Name</b></td>
       <td><b>Count</b></td>
       <td><b>Edit</b></td>
       <td><b>Delete</b></td>
   </tr>"
;

  
$sql "SELECT cam_id, cam_name, cam_count FROM 4images_cameras ORDER BY cam_id";
  
$result $site_db->query($sql);

  while (
$row $site_db->fetch_array($result)) {
  echo 
"<tr class=\"tablerow2\">
<td><img src=\""
.ROOT_PATH."admin/images/folder.gif\" alt=\"\"></td> 
<td><p align=\"right\">
$row[cam_id]</p></td> 
<td><b>
$row[cam_name]</b></td> 
<td><center>
$row[cam_count]</center></td>
<td><center><a href=\"cameras.php?action=editcams&cam_id=
$row[cam_id]\"><img src=\"".ROOT_PATH."admin/images/edit.gif\" alt=\"\" border=\"0\"></a></center></td>
<td><center><a href=\"cameras.php?action=removecams&cam_id=
$row[cam_id]\"><img src=\"".ROOT_PATH."admin/images/delete.gif\" border=\"0\"></a></center></td>
</tr>"
;
  }
  echo 
"</table>";
}

if (
$action == "editcams") {
global 
$site_db;

  
$cam_id = (isset($HTTP_POST_VARS['cam_id'])) ? intval($HTTP_POST_VARS['cam_id']) : intval($HTTP_GET_VARS['cam_id']);

  
$sql "SELECT cam_id, cam_name, cam_count FROM 4images_cameras WHERE cam_id = $cam_id";

  
$result $site_db->query($sql);
  
$row $site_db->fetch_array($result);

  echo 
"<form action=\"cameras.php?action=editcams_ok&cam_id=$row[cam_id]\" method=\"post\">
<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\">
  <tr>
    <td class=\"tableborder\">
<table cellpadding=\"3\" cellspacing=\"1\" border=\"0\">
  <tr class=\"tableheader\">
    <td colspan=\"3\"><a name=\"\"><b><span class=\"tableheader\">Digital Cameras</span></b></a>
    </td>
  </tr>
<tr class=\"tablerow\">
       <td><b>ID</b></td>
  <td><input type=\"text\" name=\"cam_id\" size=\"50\" value=\"
$row[cam_id]\" class=\"input\" /></td>
</tr>
<tr class=\"tablerow\">
       <td><b>Camera Name</b></td>
  <td><input type=\"text\" name=\"cam_name\" size=\"50\" value=\"
$row[cam_name]\" class=\"input\" /></td>
</tr>
<tr class=\"tablerow\">
       <td><b>Count</b></td>
  <td><input type=\"text\" name=\"cam_count\" size=\"50\" value=\"
$row[cam_count]\" class=\"input\" /></td>
   </tr>

  <tr class=\"tableheader\">
    <td colspan=\"3\"><input type=\"submit\" value=\"Pošlji\" /></td>
  </tr>

</table>


    </td>
  </tr>
</table>
</form>"
;

}

if (
$action == "editcams_ok") {
  
$cam_id = (isset($HTTP_POST_VARS['cam_id'])) ? intval($HTTP_POST_VARS['cam_id']) : intval($HTTP_GET_VARS['cam_id']);

    
$sql "UPDATE 4images_cameras 
              SET cam_name = '
$cam_name', cam_id = '$cam_id', cam_count = '$cam_count'  
            WHERE cam_id = 
$cam_id";

      if (
$site_db->query($sql)) {
        echo 
"Done!<br />\n";
      }
      else {
        
$error_log[] = "Ups, something is wrong!";
      }
}


if (
$action == "addcam") {
global 
$site_db;

  
$cam_id = (isset($HTTP_POST_VARS['cam_id'])) ? intval($HTTP_POST_VARS['cam_id']) : intval($HTTP_GET_VARS['cam_id']);

  
$sql "SELECT cam_id, cam_name, cam_count FROM 4images_cameras ORDER BY cam_id DESC LIMIT 1";

  
$result $site_db->query($sql);
  
$row $site_db->fetch_array($result);

$new_id $row[cam_id] + 1;

  echo 
"<form action=\"cameras.php?action=addcams_ok&cam_id=$row[cam_id]\" method=\"post\">
<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\">
  <tr>
    <td class=\"tableborder\">
<table cellpadding=\"3\" cellspacing=\"1\" border=\"0\">
  <tr class=\"tableheader\">
    <td colspan=\"3\"><a name=\"\"><b><span class=\"tableheader\">Digital Cameras</span></b></a>
    </td>
  </tr>
<tr class=\"tablerow\">
       <td><b>ID</b></td>
  <td><input type=\"text\" name=\"cam_id\" size=\"50\" class=\"input\" value=\"
$new_id\" /></td>
</tr>
<tr class=\"tablerow\">
       <td><b>Camera Name</b></td>
  <td><input type=\"text\" name=\"cam_name\" size=\"50\" class=\"input\" /></td>
</tr>
<tr class=\"tablerow\">
       <td><b>Count</b></td>
  <td><input type=\"text\" name=\"cam_count\" size=\"50\" class=\"input\" /></td>
   </tr>

  <tr class=\"tableheader\">
    <td colspan=\"3\"><input type=\"submit\" value=\"Pošlji\" /></td>
  </tr>

</table>


    </td>
  </tr>
</table>
</form>"
;

}

if (
$action == "addcams_ok") {
  
$cam_id = (isset($HTTP_POST_VARS['cam_id'])) ? intval($HTTP_POST_VARS['cam_id']) : intval($HTTP_GET_VARS['cam_id']);

    
$sql "INSERT INTO 4images_cameras (cam_id, cam_name, cam_count)
            VALUE ('
$cam_id', '$cam_name', '$cam_count')";

      if (
$site_db->query($sql)) {
        echo 
"Done!<br />\n";
      }
      else {
        
$error_log[] = "Ups, something is wrong!";
      }
}

if (
$action == "removecams") {
  
$cam_id = (isset($HTTP_POST_VARS['cam_id'])) ? intval($HTTP_POST_VARS['cam_id']) : intval($HTTP_GET_VARS['cam_id']);

    
$sql "DELETE FROM 4images_cameras 
             WHERE cam_id IN (
$cam_id)";

      if (
$site_db->query($sql)) {
        echo 
"Done!<br />\n";
      }
      else {
        
$error_log[] = "Ups, something is wrong!";
      }
}

show_admin_footer();
?>

Open details.html and add this code in between <form> and </form>: (some stylish modification needed)
Code: [Select]
          <tr>
            <td class="row"><p align="left" class="style"><b>{lang_imagecamera}</b><br>
                </p>            </td>
            <td class="row"><div align="left">
              <p>                {image_cameras}<br />
              </p>
              </div></td>
          </tr>

Open lang/<your_language>/admin.php add before ?>
Code: [Select]
$lang['nav_cameras_main'] = "Digital Cameras";
$lang['nav_cameras_edit'] = "Edit cameras";
$lang['nav_cameras_add'] = "Add cameras";

Open lang/<your_language>/main.php add before ?>
Code: [Select]
$lang['image_cameras'] = "Camera:";
Open db_field_definitions add:
Code: [Select]
$additional_image_fields['cam_id'] = array($lang['image_cameras'] , "text", 1);
Oh almost forgot!
Open details.php and add after:
Code: [Select]
if (!check_permission("auth_viewcat", $cat_id) || !check_permission("auth_viewimage", $cat_id) || !$image_row) {
  header("Location: ".$site_sess->url($url, "&"));
  exit;
}

This:
Code: [Select]
    $cam_id  = $image_row['cam_id'];

    $sql = "SELECT cam_id, cam_name FROM 4images_cameras WHERE cam_id = $cam_id";
    $result = $site_db->query($sql);
    $row = $site_db->fetch_array($result);

    $image_cameras = $row[cam_name];

$site_template->register_vars("image_cameras", $image_cameras);

I have also added database of over 1000 digital cameras (attachment)!

I don't guarantee that this mod is without bugs, securtiy issues or anything else. Please wait a bit till our doctors analysis it, then use it ;)