ragazzi guardate questo codice! in pratica se io nn sono loggato da admin nn riesco a clikkare sul banner!! cioè mi dice accesso negato, ora nn so come mai, dove sta il problema? sembra aver settato i permessi in maniera corretta! se entro come admin tutto funziona se lo faccio da anonimo o altro utente nn va!! help me!
<?php
/**
*; $Id: banner.info, v 0.0 2008/03/3 10:00:33 lunedi Exp $
* @file
* Il modulo carica il banner.
*/
/**
* banner_help
*/
function banner_help($section) {
switch ($section) {
case 'admin/help#banner':
$output = '<p>'. t('The Banner module allows you to upload a banner on its website.') .'</p>';
$output .= t("<p> You can decide:"
."<ul>"
."<li>The general settings for the banner.</li>"
."<li>Load the desired image.</li>"
."</ul>"
."</p>");
return $output;
case 'admin/modules#description':
return t('Set the banner.');
case 'admin/settings/banner':
return '<p>'. t('Setting Banner module.') .'</p>';
}
}
/**
* hook_perm
*/
function banner_perm() {
return array('access banner');
}
/**
* hook_menu
*/
function banner_menu($may_cache) {
$items[] = array('path' => 'admin/settings/banner',
'title' => t('Banner'),
'description' => t('Set banner.'),
'callback' => 'drupal_get_form',
'callback arguments' => array('banner_settings'),
'access' => user_access('administer banner'),
'type' => MENU_NORMAL_ITEM
);
$items[] = array('path' => 'banner',
'title' => t('Banner'),
'description' => t('Count banner linked.'),
'callback' => 'drupal_get_form',
'callback arguments' => array('banner_count'),
'access' => user_access('access banner'),
'type' => MENU_LOCAL_TASK
);
$items[] = array('path' => 'admin/settings/banner/add',
'title' => t('Add'),
'description' => t('Arrow to set the Banner module.'),
'callback' => 'drupal_get_form',
'callback arguments' => array('banner_settings'),
'access' => user_access('administer banner'),
'type' => MENU_DEFAULT_LOCAL_TASK
);
$items[] = array('path' => 'admin/settings/banner/list',
'title' => t('List'),
'description' => t('View list of banner.'),
'callback' => 'drupal_get_form',
'callback arguments' => array('banner_list'),
'access' => user_access('administer banner'),
'type' => MENU_LOCAL_TASK
);
$items[] = array('path' => 'admin/settings/banner/list/confirm',
'title' => t('Delete'),
'description' => t('Confirm.'),
'callback' => 'drupal_get_form',
'callback arguments' => array('banner_delete'),
'access' => user_access('administer banner'),
'type' => MENU_LOCAL_TASK
);
return $items;
}
/**
* banner_block
*/
function banner_block($op='list', $delta=0)
{
if ($op == 'list')
{
$blocks[0]['info'] = t('Banner');
return $blocks;
}
if ( ($op == 'view') && user_access('access banner') )
{
//prendo un immagine random
$banner_id = array();
$result = db_query('SELECT * FROM {banner}');
while ($info = db_fetch_object($result)) {
if ( $info->active ) {
$banner_id[$info->id] = $info->id;
}
}
if (!empty($banner_id)) {
$key = array_rand($banner_id, 1);
//visualizzo l'immagine random scelta
$attributes = array('border' => '0');
$result_key = db_query('SELECT * FROM {banner} WHERE id = ' . $key);
$info = db_fetch_object($result_key);
$img = 'files/banner/' . $info->filename;
$path_parts = pathinfo($img);
$link= 'banner/' . $info->id;
$picture = theme('image', $img, ' ', ' ', $attributes, FALSE);
$picture = l($picture, $link, array('title' => t('View Banner.')), NULL, NULL, FALSE, TRUE);
$block['subject'] = ' ';
$block['content'] = $picture;
return $block;
}
else
{
$block['subject'] = ' ';
$block['content'] = ' ';
return $block;
}
}
}
/**
* banner_settings
*/
function banner_settings() {
$form['#attributes']['enctype'] = 'multipart/form-data';
$form['banner_file'] = array('#type' => 'file',
'#title' => t('Upload file'),
'#description' => t('Your Banner. The length must be 728*90.')
);
$form['url'] = array('#type' => 'textfield',
'#title' => t('URL'),
'#description' => t('Your url.'),
'#default_value' => t('http://')
);
$form['description'] = array('#type' => 'textarea',
'#title' => t('You may insert a description.'),
'#description' => t("Insert the description.")
);
$form['active'] = array('#type' => 'checkbox',
'#title' => t('Active the visualization.'),
'#description' => t("Choose if to active or not the banner."),
'#default_value' => 1
);
$form['submit'] = array('#type' => 'submit',
'#value' => t('Submit')
);
return $form;
}
/*
* banner_settings_submit
*/
function banner_settings_submit($form_id, $form_values)
{
if (banner_validate_picture($_FILES['files']) == 'TRUE')
{
$uploaddir = file_directory_path() . '/banner/';
$uploadfile = $uploaddir . basename($_FILES['files']['name']['banner_file']);
$mov_up = move_uploaded_file($_FILES['files']['tmp_name']['banner_file'], $uploadfile);
if ($mov_up = TRUE)
{
$format = ($_FILES['files']['type']['banner_file']);
$description = $form_values['description'];
$filename = ($_FILES['files']['name']['banner_file']);
$filesize = ($_FILES['files']['size']['banner_file']);
$active = $form_values['active'];
$url = $form_values['url'];
db_query("INSERT INTO {banner} (format, description, filename, filesize, active, url)
VALUES ('%s', '%s', '%s', %d, %d, '%s')", $format, $description,
$filename, $filesize, $active, $url);
drupal_set_message(t('The file was updated.'));
drupal_goto('admin/settings/banner/list');
}
else {
drupal_set_message(t('The file was not updated.'), 'error');
}
}
}
/*
* theme_banner_list
*/
function theme_banner_list($form)
{
// Table Attributes
$attributes = array('width' => '100%');
$path = _get_image_path();
$rows = array();
foreach (element_children($form) as $key) {
$row = array();
if (is_array($form[$key]['description'])) {
$block = "<a href="#" onClick="window.open('/" . _get_image_path() . $form[$key]['filename']['#value'] . "',
'miaFinestra', 'width=750, height=200, scrollbars=no, status=no, resizable=no');"> Image </a>";
$row[] = $block;
$row[] = drupal_render($form[$key]['description']);
$row[] = drupal_render($form[$key]['click']);
$row[] = array('data' => drupal_render($form['check'][$key]), 'align' => 'center');
$row[] = drupal_render($form[$key]['operations']);
}
$rows[] = $row;
}
$header = array(t('Screenshot'), t('Description'), t('Click'), t('Enabled'), t('Operations'));
$output = theme('table', $header, $rows, $attributes);
$output .= drupal_render($form);
return $output;
}
/*
* banner_list
*/
function banner_list() {
// Image Attributes
$attr = array('width' => '140', 'height' => '40');
$result = db_query('SELECT * FROM {banner} ORDER BY filename');
$options = array();
$status = array();
while ($info = db_fetch_object($result)) {
$img = _get_image_path() . $info->filename;
$path_parts = pathinfo($img);
$clear_url = basename ($info->url, "http");
//$screenshot = theme('image', $img, $path_parts['filename'], $path_parts['filename'], $attr, FALSE);
$form[$info->id]['filename'] = array( '#value' => $info->filename );
$form[$info->id]['description'] = array('#type' => 'item',
'#value' => $clear_url,
'#title' => $path_parts['filename']);
$form[$info->id]['click'] = array('#type' => 'item', '#value' => $info->click_number);
//valorizza i checkbox che sono settati ad 1
if ( $info->active )
$status[] = $info->id;
//dà il numero di checkbox da creare
$options[$info->id] = '';
$form[$info->id]['operations'] = array('#value' => l(t('delete ' . $path_parts['filename'] ) , 'admin/settings/banner/list/confirm/' . $info->id));
}
//crea un array associativo 'check' con indice l'id ($options[$info->id]) e valore l'id ($status[] = $info->id;)
$form['check'] = array('#type' => 'checkboxes', '#options' => $options, '#default_value' => $status);
if (!empty($form)) {
$form['buttons']['submit'] = array('#type' => 'submit', '#value' => t('Save configuration') );
$form['buttons']['reset'] = array('#type' => 'submit', '#value' => t('Reset to defaults') );
}
return $form;
}
/*
* banner_list_submit
*/
function banner_list_submit($form_id, $form_values)
{
db_query("UPDATE {banner} SET active = 0" );
if ($form_values['op'] == t('Save configuration'))
{
foreach (element_children($form_values['check']) as $key)
{
if ( $form_values['check'][$key] == $key )
{
db_query("UPDATE {banner} SET active = 1 WHERE id = %d", $key );
}
}
}
drupal_set_message(t('The configuration options have been saved.'));
return 'admin/settings/banner/list';
}
/*
* banner_delete
*/
function banner_delete() {
// Image Attributes
$attr = array('width' => '140', 'height' => '40');
$result = db_query('SELECT * FROM {banner} where id = ' . arg(5));
$info = db_fetch_object($result);
$img = _get_image_path() . $info->filename;
$path_parts = pathinfo($img);
$screenshot = theme('image', $img, $path_parts['filename'], $path_parts['filename'], $attr, FALSE);
$form[$info->id]['screenshot'] = array('#value' => $screenshot);
$form[$info->id]['description'] = array('#type' => 'item', '#value' => 'Delete ' . $path_parts['filename'] . ' banner?');
$form['banner_delete']['continue'] = array('#type' => 'submit', '#value' => t('Continue'));
$form['banner_delete']['back'] = array('#type' => 'submit', '#value' => t('Back') );
$form['banner_delete']['id_banner'] = array('#type' => 'hidden', '#value' => arg(5) );
return $form;
}
/*
* banner_delete_submit
*/
function banner_delete_submit($form_id, $form_values) {
if ($form_values['op'] == t('Continue'))
{
db_query('DELETE FROM {banner} WHERE id = ' . $form_values[id_banner]);
}
return 'admin/settings/banner/list';
}
/*
* banner_validate_picture
*/
function banner_validate_picture($file) {
$info = image_get_info($file['tmp_name']['banner_file']);
if (($info['extension'] == 'jepg') || ($info['extension'] == 'gif') || ($info['extension'] == 'jpg'))
{
if (($info['width'] == 728) && ($info['height'] == 90))
{
return 'TRUE';
}
else
{
drupal_set_message(t('The image does not respect the exact dimensions.'), 'error');
}
}
else
{
drupal_set_message(t('The file is not an image.'), 'error');
return 'FALSE';
}
}
/*
* banner_count
*/
function banner_count() {
$id = arg(1);
$result = db_query('SELECT * FROM {banner} where id = ' . $id);
$info = db_fetch_object($result);
$old_val = $info->click_number;
$new_val = $old_val + 1;
db_query("UPDATE {banner} SET click_number = %d WHERE id = %d", $new_val, $id );
header( "Location: " . $info->url);
}
function _get_image_path() {
return 'files/banner/';
}
?>
Risolo: ho commentato i permessi poi reinseriti ed è andato!! misteri dela fede
100 brani in 10 minuti
https://www.youtube.com/watch?v=z9-zE7lsEv0
Spesso i permessi sono in cache ti consiglio sempre di disabilitare il modulo e poi ri-abilitarlo.
Se non bastasse cancella tuttte le tabelle cache*.
Uccio
Il mio sito con drupal
Grazie uccio, lo farò sempre d'ora innanzi! thank
100 brani in 10 minuti
https://www.youtube.com/watch?v=z9-zE7lsEv0