Jump to content

Archived

This topic is now archived and is closed to further replies.

Juto

admin banner manager, found a problem while making a better banner manager

Recommended Posts

I'm developing a better banner manager, which might become a contribution for all to enjoy. In doing it I found an irritating issue with foreign characters, example:

 

\admin\includes\functions\html_graphs.php

551: 'hlabel'=>sprintf(TEXT_BANNERS_DAILY_STATISTICS, $banner['banners_title'], strftime('%B', mktime(0,0,0,$month)), $year),

 

admin\includes\graphs\banner_daily.php

42: $graph->SetTitle(sprintf(TEXT_BANNERS_DAILY_STATISTICS, $banner['banners_title'], strftime('%B', mktime(0,0,0,$month)), $year));

 

 

The TEXT_BANNERS_DAILY_STATISTICS displays as garbage for foreign characters.

 

Thus the above files are not aware of the CHARSET at hand!

 

If anybody can suggest a solution I, among others, will be delighted

 

Sara

Share this post


Link to post
Share on other sites

Could you elaborate on this a bit? Which string(s) are causing the problem: TEXT_BANNERS_DAILY_STATISTICS (the template), $banners['banners_title'], or the month name (any or all of these)? What encoding(s) show this problem -- UTF-8, Latin-1, other single-byte encodings? Is the page being shown in a matching encoding (e.g., UTF-8 display for a UTF-8 language support)? What sort of 'garbage' are you getting... ? for UTF-8 display, multiple accented characters for Latin-1, or something else?

 

Looking up sprintf(), the only warning I've seen is that it can't pad (e.g., with blanks) to a given length correctly because it counts raw bytes, not characters. There might be other problems, but you will need to describe what you've seen.

Share this post


Link to post
Share on other sites

Hi Phil, please excuse me for my very, very late answer. I have posted the issue in the bugreports.

At the moment I am trying to have this in a drop down, avoiding the need to type in the name of the banner image:

 

	  <tr>
	    <td class="main" valign="top"><?php echo TEXT_BANNERS_IMAGE; ?> </td>
	    <td class="main"><?php echo tep_draw_file_field('banners_image') . TEXT_BANNERS_IMAGE_LOCAL . DIR_FS_CATALOG_IMAGES . tep_draw_input_field('banners_image_local', (isset($bInfo->banners_image) ? $bInfo->banners_image : ''),'size="24" maxlength="32"'); ?></td>
	  </tr>

 

It should be possible since the images are in the db. I am not quite sure on how to do this.

Any suggestions?

 

Thanks

 

Sara

Share this post


Link to post
Share on other sites

OK, so right now it's a tep_draw_input_field() call, which provides a place to type in a name, and you want to change it to a drop-down (selection) menu? You'd have to replace tep_draw_input_field() by tep_draw_pull_down_menu(), and update the parameter list. The second parameter is an array of values to select from, which you would have to figure out how to build. There are other uses of tep_draw_pull_down_menu() in admin/banner_manager.php, to give you some samples, and the function is defined in admin/includes/functions/html_output.php.

Share this post


Link to post
Share on other sites

Hi Phil, I have struggled for two days now and most of it works, but not the last part.

Also, I have redesigned the layout to the better I hope. Take a look at the image.

 

So, this is the coding:

 

<?php
//BOC: Added drop down for existing banner images
 $banner_images_array = array();
 $banner_images_array[0] = array('id' => '0', 'text' => TEXT_PLEASE_SELECT);

 $banner_images_query = tep_db_query("select banners_group, banners_image from " . TABLE_BANNERS . " order by banners_group");
 while ($banner_images_values = tep_db_fetch_array($banner_images_query)) {
//
//  Remove path from file name using a regex: Thus instead of
//		$banner_images_array[] = array('id' => $banner_images_values['banners_group'], 'text' => $banner_images_values['banners_image']);
//  We use:
	$basename = preg_replace( '/^.+[\\\\\\/]/', '', $banner_images_values['banners_image'] );
	$banner_images_array[] = array('id' => $banner_images_values['banners_group'], 'text' => $basename );
 }
//EOC: Added drop down for existing banner images
?>

The drop down works but not the the last part, the tep_draw_input_field is not populated with the selected image.

<td class="main"><?php echo tep_draw_file_field('banners_image_local') . ' '.TEXT_BANNERS_IMAGE_OLD.' ';
$selected_image = (isset($_GET['banners_image']) ? $_GET['banners_image'] : '');
echo tep_draw_pull_down_menu('banners_image', $banner_images_array, $selected_image) . ' ' .
tep_draw_input_field('banners_image_local', (isset($selected_image) ? $selected_image->banners_image : ''), 'size="24" maxlength="32"'); ?>
</td>

Can you see what I've done wrong?

 

Then a bug, which affects all osC 2.x versions:

<?php
// A bugfix
// Find at row 136 in a vanilla v2.3.1:
if (function_exists('imagecreate') && tep_not_null($banner_extensio)) {
// Replace with:
if (function_exists('imagecreate') && tep_not_null($banner_extension)) {
?>

 

Sara

 

new_banner_manager.jpg

Share this post


Link to post
Share on other sites

Is $_GET going to pass a complete object? I don't think it will. Is $_GET['banners_image'] just a simple string? If so, why not simply use it?

 

Hint: use   instead of 160; as it's more self-documenting.

 

Nice catch on the "extensio". I wonder how long that's been messing up things?

Share this post


Link to post
Share on other sites

Hi Phil, do you mean that I should just remove:

 

$selected_image = (isset($_GET['banners_image']) ? $_GET['banners_image'] : '');

 

I have changed the   since I am using document type strict and, later on, I'll move to html5/css3.

 

I think the bug has always been there. Causing a lot of frustrations, I believe.

 

Sara

Share this post


Link to post
Share on other sites

No, I'm just trying to figure out if $_GET['banners_image'] (and thus $selected_image) is just a string, and if so, why you're using $selected_image->banners_image (what is it?).

Share this post


Link to post
Share on other sites

Hi Phil, I haven't managed to get it working. I have tried since yesterday... :(

I am out of idea's. Could you please advice me?

 

Here's my latest effort:

 

<td class="main"><?php echo tep_draw_file_field('banners_image_local') . ' '.TEXT_BANNERS_IMAGE_OLD.' ';
$selected_image = (isset($_GET['banners_image']) ? $_GET['banners_image'] : '');
echo tep_draw_pull_down_menu('banners_image', $banner_images_array, $selected_image, 'onchange="this.form.submit();"') . ' ' . $selected_image .
tep_draw_input_field('banners_image_local', (isset($selected_image) ? $selected_image : ''), 'size="24" maxlength="32"')// . tep_hide_session_id(); ?>
</td>

 

And I only get that the echo of $selected_image echoes nothing.

 

Hence I get these errors:

 

-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

Date / Time: 10-06-2012 20:38:19

Error Type: [E_NOTICE] Undefined index: tmp_name

On line 71

File includes/classes/upload.php

-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

 

Date / Time: 10-06-2012 20:38:19

Error Type: [E_NOTICE] Undefined index: name

On line 94

File includes/classes/upload.php

-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

 

Cheers

 

Sara

Share this post


Link to post
Share on other sites

$selected_image will always be set. If $_GET['banners_image'] wasn't set, $selected_image will be '', but isset() will always return true. So, you need to work on why $_GET['banners_image'] is either not set, or is set but is ''. Where is it coming from? Is it from a form with method="GET", or a URL Query String in a link? If it's from a form with method="POST", you need to use either $_POST or $_REQUEST. Temporarily do this:

$selected_image = (isset($_GET['banners_image']) ? $_GET['banners_image'] : 'X');

to confirm that $_GET['banners_image'] is in fact set ($selected_image will show X if it wasn't). In the last line, since $selected_image is always set, use

tep_draw_input_field('banners_image_local', $selected_image, 'size="24" maxlength="32"')// . tep_hide_session_id(); ?>
</td>

in the last line.

Share this post


Link to post
Share on other sites

The 'X' was inserted to the file field when the page loaded.

Then, when I selected a previous image, that image was not loaded into the field. I.e not replacing the 'X'

The image is not loaded into the file field.

 

The snippet is within this form:

<?php echo tep_draw_form('new_banner', FILENAME_BANNER_MANAGER, (isset($_GET['page']) ? 'page=' . $_GET['page'] . '&' : '') . 'action=' . $form_action, 'post', 'enctype="multipart/form-data"'); if ($form_action == 'update') echo tep_draw_hidden_field('banners_id', $bID); ?>

 

Maybe you need the entire file?

 

Many thanks for helping me out

 

Sara

Share this post


Link to post
Share on other sites
The 'X' was inserted to the file field when the page loaded.

OK, that tells us that $_GET['banners_image'] is not defined (not set) upon page load. Is 'banners_image' one of the form fields? It looks like your method is "post" -- so why aren't you using $_POST['banners_image']?

Share this post


Link to post
Share on other sites

Hi Phil, this is funny! :) I tried post... and then I selected the banner/oscommerce.gif

Upon submitting the form... It removed that banner *lol* Anyway here's the form.

 

Hope it will give some insight:

 

  <?php echo tep_draw_form('new_banner', FILENAME_BANNER_MANAGER, (isset($_GET['page']) ? 'page=' . $_GET['page'] . '&' : '') . 'action=' . $form_action, 'post', 'enctype="multipart/form-data"'); if ($form_action == 'update') echo tep_draw_hidden_field('banners_id', $bID); ?>
    <table border="0" cellspacing="0" cellpadding="2">
	  <tr>
	    <td class="main"><?php echo TEXT_BANNERS_TITLE; ?> </td>
	    <td class="main"><?php echo tep_draw_input_field('banners_title', $bInfo->banners_title, 'size="32" maxlength="64"', true); ?></td>
	  </tr>
	  <tr>
	    <td class="main" ><?php echo TEXT_BANNERS_URL; ?> </td>
	    <td class="main"><?php echo tep_draw_input_field('banners_url', $bInfo->banners_url,'size="32" maxlength="64"'); ?></td>
	  </tr>
	  <tr>
	    <td class="main" valign="top"><?php echo TEXT_BANNERS_GROUP; ?> </td>
	    <td class="main"><?php echo tep_draw_pull_down_menu('banners_group', $groups_array, $bInfo->banners_group) . ' ' . TEXT_BANNERS_NEW_GROUP . ' ' . tep_draw_input_field('new_banners_group', '', '', ((sizeof($groups_array) > 0) ? false : true)); ?></td>
	  </tr>
	  <tr>
	    <td colspan="2"><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
	  </tr>
	  <tr>
	    <td class="main" valign="top"><?php echo TEXT_BANNERS_IMAGE; ?> </td>
<!-- //BOC: Added drop down for existing banner images
Reformat This
	    <td class="main"><?php //echo tep_draw_file_field('banners_image') . ' ' . TEXT_BANNERS_IMAGE_LOCAL . '<br />' . DIR_FS_CATALOG_IMAGES . tep_draw_input_field('banners_image_local', (isset($bInfo->banners_image) ? $bInfo->banners_image : '')); ?></td>
To this
	    <td class="main"><?php //echo tep_draw_file_field('banners_image') . TEXT_BANNERS_IMAGE_LOCAL . DIR_FS_CATALOG_IMAGES . tep_draw_input_field('banners_image_local', (isset($bInfo->banners_image) ? $bInfo->banners_image : ''),'size="24" maxlength="32"'); ?></td>
-->
<td class="main"><?php echo tep_draw_file_field('banners_image_local') . ' '.TEXT_BANNERS_IMAGE_OLD.' ';
$selected_image = (isset($_POST['banners_image']) ? $_POST['banners_image'] : 'Y');
echo tep_draw_pull_down_menu('banners_image', $banner_images_array, $selected_image) . ' ' . $selected_image;  
echo tep_draw_input_field('banners_image_local', $selected_image, 'size="24" maxlength="32"')// . tep_hide_session_id(); ?>
</td>
<!-- //EOC: Added drop down for existing banner images-->
	  </tr>
	  <tr>
	    <td colspan="2"><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
	  </tr>
	  <tr>
	    <td class="main"><?php echo TEXT_BANNERS_IMAGE_TARGET; ?> </td>
	    <td class="main"><?php echo tep_draw_input_field('banners_image_target','','size="24" maxlength="32"') . ' ' . TEXT_DEFAULT_FOLDER . ' ' . DIR_FS_CATALOG_IMAGES . 'banners/'; ?></td>
	  </tr>
	  <tr>
	    <td colspan="2"><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
	  </tr>
	  <tr>
	    <td valign="top" class="main"><?php echo TEXT_BANNERS_HTML_TEXT; ?> </td>
<!--//Bugfix invalid attribut 'soft' replaced wrap="' . tep_output_string($wrap) . '" with 'style="white-space:normal;"' in includes/funtions/html_output.php//-->
	    <td class="main"><?php echo tep_draw_textarea_field('banners_html_text', 'soft', '60', '4', $bInfo->banners_html_text); ?></td>
	  </tr>
	  <tr>
	    <td colspan="2"><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
	  </tr>
	  <tr>
	    <td class="main"><?php echo TEXT_BANNERS_SCHEDULED_AT; ?> </td>
<!--Begin Kalender-->
<?php
	    $default_value = ' ';
?>
	   <td valign="top" class="main"><?php echo tep_draw_input_field('date_scheduled', $bInfo->date_scheduled, 'id="date_scheduled" value="'. $default_value .'" size="15" onclick="showCalendarControl(this);"'); ?> <a href="javascript:showCalendarControl(document.new_banner.date_scheduled);"><img style="position:relative;top:0.25em;" alt="calendar" width="24" height="16" src="<?php echo DIR_WS_ADMIN.DIR_WS_INCLUDES . 'Kalender/images/calendar.gif';?>"/></a></td>
<!--End Kalender-->
	  </tr>
	  <tr>
	    <td colspan="2"><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
	  </tr>
	  <tr>
	    <td valign="top" class="main"><?php echo TEXT_BANNERS_EXPIRES_ON; ?> </td>
<!--Begin Kalender-->
<?php
	    $default_value = ' ';
?>
	   <td valign="top" class="main"><?php echo tep_draw_input_field('expires_date', $bInfo->expires_date, 'id="expires_date" value="'. $default_value .'" size="15" onclick="showCalendarControl(this);"').' '.'<a href="javascript:showCalendarControl(document.new_banner.expires_date);"><img style="position:relative;top:0.25em;" alt="calendar" width="24" height="16" src="' . DIR_WS_ADMIN.DIR_WS_INCLUDES .'Kalender/images/calendar.gif"' . '/></a>'; ?>
<!--End Kalender-->
	    <?php echo ' ' . TEXT_BANNERS_OR_AT . ' ' . tep_draw_input_field('expires_impressions', $bInfo->expires_impressions, 'maxlength="4" size="4"') . ' ' . TEXT_BANNERS_IMPRESSIONS; ?>
	    </td>
	  </tr>
  <tr>
    <td colspan="2"><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
  </tr>
	  <tr>
	    <td colspan="2" class="main" valign="top" style="white-space:nowrap;width:100%;"><?php echo (($form_action == 'insert') ? tep_image_submit('button_insert.gif', IMAGE_INSERT) : tep_image_submit('button_update.gif', IMAGE_UPDATE)). '  <a href="' . tep_href_link(FILENAME_BANNER_MANAGER, (isset($_GET['page']) ? 'page=' . $_GET['page'] . '&' : '') . (isset($_GET['bID']) ? 'bID=' . $_GET['bID'] : '')) . '">' . tep_image_button('button_cancel.gif', IMAGE_CANCEL) . '</a>'; ?></td>
	  </tr>
  <tr>
    <td colspan="2"><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
  </tr>
  </table>
  </form>

 

Sara

Share this post


Link to post
Share on other sites

So you now have

<!-- //BOC: Added drop down for existing banner images
Reformat This
				<td class="main"><?php //echo tep_draw_file_field('banners_image') . ' ' . TEXT_BANNERS_IMAGE_LOCAL . '<br />' . DIR_FS_CATALOG_IMAGES . tep_draw_input_field('banners_image_local', (isset($bInfo->banners_image) ? $bInfo->banners_image : '')); ?></td>
To this
				<td class="main"><?php //echo tep_draw_file_field('banners_image') . TEXT_BANNERS_IMAGE_LOCAL . DIR_FS_CATALOG_IMAGES . tep_draw_input_field('banners_image_local', (isset($bInfo->banners_image) ? $bInfo->banners_image : ''),'size="24" maxlength="32"'); ?></td>
-->
<td class="main"><?php echo tep_draw_file_field('banners_image_local') . ' '.TEXT_BANNERS_IMAGE_OLD.' ';
$selected_image = (isset($_POST['banners_image']) ? $_POST['banners_image'] : 'Y');
echo tep_draw_pull_down_menu('banners_image', $banner_images_array, $selected_image) . ' ' . $selected_image;  
echo tep_draw_input_field('banners_image_local', $selected_image, 'size="24" maxlength="32"')// . tep_hide_session_id(); ?>
</td>
<!-- //EOC: Added drop down for existing banner images-->

If you want to hide tep_hide_session_id(), use

maxlength="32") /* . tep_hide_session_id() */ ; ?>

instead of

maxlength="32") // .tep_hide_session_id(); ?>

otherwise you're losing the ending semicolon on the statement. I don't know if that's part of the problem, but it should be fixed.

 

If you're not getting anything in the selection list, have you checked the contents of your $banner_images_array (one or more strings of file names) and not just assumed that it's good? Is the default ($selected_image) of exactly the same format as in $banner_images_array? Boundary condition: the first time through (building the form, not processing data from a form submission), are you expecting to have a value in $_POST['banners_image']? It looks to me like there will be nothing there.

Share this post


Link to post
Share on other sites

Hi Phil, good news, I've got it working :)

 

Bad news, I resorted to a piece of javascript.

I do remember I had it working without it before, but missintepretated the outcom...

 

So, now I'll try to revert to that solution. Any suggestions?

 

Also, I found that the target for saving a banner image only applies to new images.

 

I have to fix that also, otherwise removing a banner with a reused banner image one can accidently delete the original image. Any thoughts?

 

Cheers Sara

Share this post


Link to post
Share on other sites

×