За последние 24 часа нас посетил 51681 программист и 1766 роботов. Сейчас ищут 833 программиста ...

jQuery модальное окно

Тема в разделе "JavaScript и AJAX", создана пользователем Ric, 18 май 2011.

  1. Ric

    Ric Активный пользователь

    С нами с:
    9 фев 2011
    Сообщения:
    97
    Симпатии:
    2
    Приветствую, возникла проблема: через модальное окно не заноситься изображение в бд(точнее ссылка на изображение)
    вот код
    HTML:
    1. <a rel='prettyPopin' href='admin_addtovar.php'>Добавить товар</a>
    jquery:
    [js]
    /* ------------------------------------------------------------------------
    Class: prettyPopin
    Use: Alternative to popups
    Author: Stephane Caron (http://www.no-margin-for-errors.com)
    Version: 1.3
    ------------------------------------------------------------------------- */

    var _followScroll = false;
    var _readyBound = false;

    (function($) {
    $.fn.prettyPopin = function(settings) {
    settings = jQuery.extend({
    modal : false, /* true/false */
    width : false, /* false/integer */
    height: false, /* false/integer */
    opacity: 0.5, /* value from 0 to 1 */
    animationSpeed: 'fast', /* slow/medium/fast/integer */
    followScroll: true, /* true/false */
    loader_path: 'images/prettyPopin/loader.gif', /* path to your loading image */
    callback: function(){} /* callback called when closing the popin */
    }, settings);

    function bindReady(){ // To bind them only once
    if(_readyBound) return;
    _readyBound = true;
    $(window).scroll(function(){ _centerPopin(); });
    $(window).resize(function(){ _centerPopin(); });
    };
    bindReady();

    return this.each(function(){
    var popinWidth;
    var popinHeight;
    var $c;

    $(this).click(function(){
    buildoverlay();
    buildpopin();

    // Load the content
    $.get($(this).attr('href'),function(responseText){
    $('.prettyPopin .prettyContent .prettyContent-container').html(responseText);

    // This block of code is used to calculate the width/height of the popin
    popinWidth = settings.width || $('.prettyPopin .prettyContent .prettyContent-container').width() + parseFloat($('.prettyPopin .prettyContent .prettyContent-container').css('padding-left')) + parseFloat($('.prettyPopin .prettyContent .prettyContent-container').css('padding-right'));
    $('.prettyPopin').width(popinWidth);
    popinHeight = settings.height || $('.prettyPopin .prettyContent .prettyContent-container').height() + parseFloat($('.prettyPopin .prettyContent .prettyContent-container').css('padding-top')) + parseFloat($('.prettyPopin .prettyContent .prettyContent-container').css('padding-bottom'));
    $('.prettyPopin').height(popinHeight);

    // Now reset the width/height
    $('.prettyPopin').height(45).width(45);

    displayPopin();
    });
    return false;
    });

    var displayPopin = function() {
    var scrollPos = _getScroll();

    projectedTop = ($(window).height()/2) + scrollPos['scrollTop'] - (popinHeight/2);
    if(projectedTop < 0) {
    projectedTop = 10;
    _followScroll = false;
    }else{
    _followScroll = settings.followScroll;
    };

    $('.prettyPopin').animate({
    'top': projectedTop,
    'left': ($(window).width()/2) + scrollPos['scrollLeft'] - (popinWidth/2),
    'width' : popinWidth,
    'height' : popinHeight
    },settings.animationSpeed, function(){
    displayContent();
    });
    };

    var buildpopin = function() {
    $('body').append('<div class="prettyPopin"><a href="#" id="b_close" rel="close">Close</a><div class="prettyContent"><img src="'+settings.loader_path+'" alt="Loading" class="loader" /><div class="prettyContent-container"></div></div></div>');
    $c = $('.prettyPopin .prettyContent .prettyContent-container'); // The content container

    $('.prettyPopin a[rel=close]:eq(0)').click(function(){ closeOverlay(); return false; });

    var scrollPos = _getScroll();

    // Show the popin
    $('.prettyPopin').width(45).height(145).css({
    'top': ($(window).height()/2) + scrollPos['scrollTop'],
    'left': ($(window).width()/2) + scrollPos['scrollLeft']
    }).hide().fadeIn(settings.animationSpeed);
    };

    var buildoverlay = function() {
    $('body').append('<div id="overlay"></div>');

    // Set the proper height
    $('#overlay').css('height',$(document).height());

    // Fade it in
    $('#overlay').css('opacity',0).fadeTo(settings.animationSpeed,settings.opacity);

    if(!settings.modal){
    $('#overlay').click(function(){
    closeOverlay();
    });
    };
    };

    var displayContent = function() {
    $c.parent().find('.loader').hide();
    $c.parent().parent().find('#b_close').show();
    $c.fadeIn(function(){
    // Focus on the first form input if there's one
    $(this).find('input[type=text]:first').trigger('focus');

    // Check for paging
    $('.prettyPopin a[rel=internal]').click(function(){
    $link = $(this);

    // Fade out the current content
    $c.fadeOut(function(){
    $c.parent().find('.loader').show();

    // Submit the form
    $.get($link.attr('href'),function(responseText){
    // Replace the content
    $c.html(responseText);

    _refreshContent($c);
    });
    });
    return false;
    });


    // Submit the form in ajax
    $('.prettyPopin form').bind('submit',function(){
    $theForm = $(this);
    // Fade out the current content
    $c.fadeOut(function(){
    $c.parent().find('.loader').show();

    // Submit the form
    $.post($theForm.attr('action'), $theForm.serialize(),function(responseText){
    // Replace the content
    $c.html(responseText);

    _refreshContent($c);
    });
    });
    return false;
    });
    });
    $('.prettyPopin a[rel=close]:gt(0)').click(function(){ closeOverlay(); return false; });
    };

    var _refreshContent = function(){
    var scrollPos = _getScroll();

    if(!settings.width) popinWidth = $c.width() + parseFloat($c.css('padding-left')) + parseFloat($c.css('padding-right'));
    if(!settings.height) popinHeight = $c.height() + parseFloat($c.css('padding-top')) + parseFloat($c.css('padding-bottom'));

    projectedTop = ($(window).height()/2) + scrollPos['scrollTop'] - (popinHeight/2);
    if(projectedTop < 0) {
    projectedTop = 10;
    _followScroll = false;
    }else{
    _followScroll = settings.followScroll;
    };

    $('.prettyPopin').animate({
    'top': projectedTop,
    'left': ($(window).width()/2) + scrollPos['scrollLeft'] - (popinWidth/2),
    'width' : popinWidth,
    'height' : popinHeight
    }, settings.animationSpeed,function(){
    displayContent();
    });
    };

    var closeOverlay = function() {
    $('#overlay').fadeOut(settings.animationSpeed,function(){ $(this).remove(); });
    $('.prettyPopin').fadeOut(settings.animationSpeed,function(){ $(this).remove(); settings.callback() });
    };
    });

    function _centerPopin(){
    if(!_followScroll) return;

    // Make sure the popin exist
    if(!$('.prettyPopin')) return;

    var scrollPos = _getScroll();

    if($.browser.opera) {
    windowHeight = window.innerHeight;
    windowWidth = window.innerWidth;
    }else{
    windowHeight = $(window).height();
    windowWidth = $(window).width();
    };

    projectedTop = ($(window).height()/2) + scrollPos['scrollTop'] - ($('.prettyPopin').height()/2);
    if(projectedTop < 0) {
    projectedTop = 10;
    _followScroll = false;
    }else{
    _followScroll = true;
    };

    $('.prettyPopin').css({
    'top': projectedTop,
    'left': ($(window).width()/2) + scrollPos['scrollLeft'] - ($('.prettyPopin').width()/2)
    });
    };

    function _getScroll(){
    scrollTop = window.pageYOffset || document.documentElement.scrollTop || 0;
    scrollLeft = window.pageXOffset || document.documentElement.scrollLeft || 0;
    return {scrollTop:scrollTop,scrollLeft:scrollLeft};
    };
    };
    })(jQuery);[/js]
    PHP:
    1.  
    2. <?php
    3. require_once('admin_include_fns.php');
    4. if(check_admin())
    5. {
    6.     admin_menu();
    7.     echo "<form enctype='multipart/form-data' action='add_tovar.php' method='post' class='genericForm'>
    8.        <table>
    9.       <tr>
    10.       <th colspan='2'>Изображение</th>
    11.       <td><input type='file' name='picture'></td>
    12.       </tr>
    13.       <tr>
    14.       <th colspan='2'></th>
    15.       <td><input type='submit' value='Добавить'></td>
    16.       </tr>
    17.       </table>
    18.       </form>";
    19. }
    PHP:
    1.  
    2. <?php
    3. require_once('admin_include_fns.php');
    4. $name=$_POST['name'];
    5. $cat=$_POST['cat'];
    6. $color=$_POST['color'];
    7. $main=$_POST['main'];
    8. $sostav=$_POST['sostav'];
    9. $size=$_POST['size'];
    10. $price=$_POST['price'];
    11. $type=$_POST['type'];
    12. $description=$_POST['description'];
    13. $conn=db_connect();
    14. $query="insert into tovar(catid,artikul,`name`,
    15.    color,main,sostav,type,size,price,description,image)
    16.   values('".$conn->real_escape_string($cat)."',NULL,
    17.        '".$conn->real_escape_string($name)."',
    18.        '".$conn->real_escape_string($color)."',
    19.        '".$conn->real_escape_string($main)."',
    20.        '".$conn->real_escape_string($sostav)."',
    21.        '".$conn->real_escape_string($type)."',
    22.        '".$conn->real_escape_string($size)."',
    23.        '".$conn->real_escape_string($price)."',
    24.        '".$conn->real_escape_string($description)."','$filename')";
    25. $result=$conn->query($query);
    26. if(!$result)
    27. {
    28.     echo "Не могу вставить новый товар";
    29.     return false;
    30. }
    31. if(isset($_FILES['picture']['name'])&&
    32.             is_uploaded_file($_FILES['picture']['tmp_name']))
    33.             {
    34.                $id=$conn->insert_id;
    35.                $ptype=basename($_FILES['picture']['type']);
    36.                switch($ptype)
    37.                    {
    38.                    case 'jpeg':
    39.                    case 'pjpeg': $filename="tovar/$id.jpg";
    40.                    move_uploaded_file($_FILES['picture']['tmp_name'],
    41.                    '../'.$filename);
    42.                    break;
    43.                    default : $_FILES['picture']['type'];
    44.                    }
    45.                    var_dump($id);
    46.                    $queryimage="update tovar set image='$filename'
    47.                       where artikul='$id'";
    48.                        $resultimage=$conn->query($queryimage);
    49.                        if(!$resultimage)
    50.                        {
    51.                            echo "Не могу обновить товар";
    52.                            return false;
    53.                        }
    54.                        return true;
    55.            echo "Товар успешно добавлен.";
    56. return true;
    57.  }      
    58. ?>
    59.  
    Если вставлять изображение не через модальное окно все нормально.
    Кто нибудь сталкивался с такой проблемкой?