function loading_animation(target){ jQuery(target).html('
'); } function loading_animation_small(target){ jQuery(target).html('
'); } function loading_button_animation(type,target){ if (type=='start') { if ($(target+' .spinner').length==0){ $(target).prepend('').fadeIn(); } } else { $(target).find('span').fadeOut(function(){jQuery(this).remove()}); }; } function loading_animation_adminprint(target){ jQuery(target).hide(); jQuery(target).after(''); jQuery('.load_animation').fadeIn(); } function login_status(){ jQuery('#login_block').load('spcprint_request.php?login_status').hide().fadeIn('fast'); } function login_form(){ jQuery('#spcprint_modal').load('spcprint_request.php?login_form', function(){jQuery('#spcprint_modal').modal('show');}); } function register_form(){ jQuery('#spcprint_modal').load('spcprint_request.php?register_form', function(){jQuery('#spcprint_modal').modal('show');}); } function user_settings_form(){ jQuery('#spcprint_modal').load('spcprint_request.php?u_settings', function(){jQuery('#spcprint_modal').modal('show');}); } function user_orders_form(){ jQuery('#spcprint_modal').load('spcprint_request.php?u_orders', function(){jQuery('#spcprint_modal').modal('show');}); } function view_order(id){ jQuery('#spcprint_modal').modal('hide'); jQuery('#spcprint_modal').load('spcprint_request.php?view_order='+id, function(){jQuery('#spcprint_modal').modal('show');}); } function send_lab_email(id){ jQuery('#spcprint_modal').modal('hide'); jQuery('#spcprint_modal').load('spcprint_request.php?send_email='+id, function(){jQuery('#spcprint_modal').modal('show');}); } function send_lab_email_do(id){ jQuery('.spc_user_data_errors').load('spcprint_request.php?send_lab_email_do', {subject: jQuery('#spc_lab_email_subject').val(), message: jQuery('#spc_lab_email_message').val(), order:id}); } function forgot_password(){ jQuery('#spcprint_modal').load('spcprint_request.php?forgot_password', function(){jQuery('#spcprint_modal').modal('show');}); } function do_recovery(){ if (jQuery('#user_email').val()!='') { loading_animation_small('#login_err'); jQuery('#login_err').load('spcprint_request.php?do_forgot_password', {'email':jQuery('#user_email').val()}); } else {jQuery('#user_email').focus();}; } function end_recovery_form(token){ jQuery('#spcprint_modal').load('spcprint_request.php?end_recover_form='+token, function(){jQuery('#spcprint_modal').modal('show');}); } function token_checker(token){ jQuery.get('spcprint_request.php?token_checker='+token, function( data ) { if (data.status=='true') {end_recovery_form(token);};}, "json"); } function recovery_set_new_password(){ loading_animation_small('#login_err'); jQuery('#login_err').load('spcprint_request.php?recovery_set_new_password', {'spc_user_password':jQuery('#spc_user_password').val(),'spc_user_verifypassword':jQuery('#spc_user_verifypassword').val(),'password_token':jQuery('#password_token').val()}); } function try_login(){ if (jQuery('#login_username').val()!='') { if (jQuery('#login_password').val()!='') { loading_animation_small('#login_err'); jQuery('#login_err').load('spcprint_request.php?try_login', {'login':jQuery('#login_username').val(),'password':jQuery('#login_password').val()}); } else {jQuery('#login_password').focus();}; } else {jQuery('#login_username').focus();}; } function do_logout(){ jQuery.get('spcprint_request.php?do_logout').done(function(){login_status();recalc_price('#total_order_price');}); } function new_user_register(){ if (jQuery('#login_username').val()!='') { if (jQuery('#login_password').val()!='') { loading_animation_small('#login_err'); jQuery('#login_err').load('spcprint_request.php?new_user_register', {'login':jQuery('#login_username').val(),'password':jQuery('#login_password').val()}); } else {jQuery('#login_password').focus();}; } else {jQuery('#login_username').focus();}; } function order_forming(){ loading_button_animation('start','#order_forming_button'); //check for images $.get('spcprint_request.php?login_check', function( data ) { if (data.status=='true') { //unset_console.log("pass uid"); if (checking_photo('exist')=='true') { if (checking_photo('paper')=='true') { if (checking_photo('dimension')=='true') { if (checking_photo('count')=='true') { confirm_order(); }; }; }; }; } else { swal({ title: "Ooops!", text: "You are not logged! Please LogIn or Register", type: "warning", showCancelButton: true, confirmButtonColor: "#5cb85c", confirmButtonText: "Sign in", cancelButtonText: "Register now", closeOnConfirm: true, closeOnCancel: true }, function(isConfirm){ if (isConfirm) { login_form(); } else { register_form(); } }); }; loading_button_animation('stop','#order_forming_button'); }, "json"); } function checking_photo(type){ if (type=='exist') { if ($('.photoblock').length!=0) { return 'true'; } else { swal({ title: 'Ooops!', text: 'Your photos not found!', type: "warning", showCancelButton: true, confirmButtonColor: "#5cb85c", confirmButtonText: "Upload photo", cancelButtonText: "Close", closeOnConfirm: true, closeOnCancel: true }, function(isConfirm){ if (isConfirm) { $('#add_photo_button').trigger("click"); } }); return 'false';}; }; if (type=='paper') { not_selected=0; $("select[class*='photo_paper_class-']").each(function(){ if ($(this).val().length==0) { not_selected++; }; }); if (not_selected==0) { return 'true'; } else { swal({ title: "Ooops!", text: "Some of your photos is not specify the type of print.", type: "warning", showCancelButton: false, confirmButtonColor: "#5cb85c", confirmButtonText: "Close", closeOnConfirm: true }); return 'false'; }; }; if (type=='dimension') { not_selected=0; $("select[class*='photo_paper_dimension-']").each(function(){ if ($(this).val().length==0) { not_selected++; }; }); if (not_selected==0) { return 'true'; } else { swal({ title: "Ooops!", text: "Some of your photos is not specify the type of print.", type: "warning", showCancelButton: false, confirmButtonColor: "#5cb85c", confirmButtonText: "Close", closeOnConfirm: true }); return 'false'; }; }; if (type=='count') { not_selected=0; $("select[class*='photo_print_count-']").each(function(){ if ($(this).val()<=0) { not_selected++; }; }); if (not_selected==0) { return 'true'; } else { swal({ title: "Ooops!", text: "Print specified number of photos can not be zero or less than zero", type: "warning", showCancelButton: false, confirmButtonColor: "#5cb85c", confirmButtonText: "Close", closeOnConfirm: true }); return 'false'; }; }; } function confirm_order(){ jQuery('#spcprint_modal').load('spcprint_request.php?confirm_order', function(){jQuery('#spcprint_modal').modal('show'); recalc_price('#confirm_order_price_total'); $('#spc_user_ship_method').change();}); } function proceed_order(){ window.order_package=new Array(); if (jQuery('#spc_user_name').val()!='') { if (jQuery('#spc_user_surname').val()!='') { if (jQuery('#spc_user_ship_address').val()!='') { if (jQuery('#spc_user_ship_zip').val()!='') { if (jQuery('#spc_user_ship_city').val()!='') { if (jQuery('#spc_user_ship_state').val()!='') { loading_button_animation('start','#proceed_order_button'); $('.spc_print_loading_text').html('Cropping & Resizing images...'); $('#processing_progress_bar').hide(); $('#spcprint_modal').modal('hide'); $(".spc_print_loading, .spc_print_loading_overlay").show(); window.order_package.push({'uid':jQuery('#spc_user_uid').val(),'salt':jQuery('#spc_user_salt').val(),'username':jQuery('#spc_user_name').val(),'surname':jQuery('#spc_user_surname').val(),'vatid':jQuery('#spc_user_vatid').val(),'taxcode':jQuery('#spc_user_taxcode').val(),'payment':jQuery('#spc_user_payment_method').val(),'ship_method':jQuery('#spc_user_ship_method').val(),'company':jQuery('#spc_user_ship_company').val(),'address':jQuery('#spc_user_ship_address').val(),'zip':jQuery('#spc_user_ship_zip').val(),'city':jQuery('#spc_user_ship_city').val(),'state':jQuery('#spc_user_ship_state').val(),'country':jQuery('#spc_user_ship_country').val()}); window.uid=jQuery('#spc_user_uid').val(); window.uid_date_id=+new Date; init_order_package(); }else{jQuery('#spc_user_ship_state').focus();}; }else{jQuery('#spc_user_ship_city').focus();}; }else{jQuery('#spc_user_ship_zip').focus();}; }else{jQuery('#spc_user_ship_address').focus();}; }else{jQuery('#spc_user_surname').focus();}; }else{jQuery('#spc_user_name').focus();}; } function init_order_package(){ $('.photoblock').each(function(){ curr_img=$(this).find("img[id*='cropimageid-']"); selected_dimension=$(this).find("select[class*='photo_paper_dimension-'] option:selected"); photo_copy_count=$(this).find("input[print_counter*='photo_print_count-']").val(); _crop_image(curr_img.attr('original_img'),curr_img.attr('cropw'),curr_img.attr('croph'),curr_img.attr('cropy'),curr_img.attr('cropx'),selected_dimension.attr('dimension_w'),selected_dimension.attr('dimension_h'),curr_img.attr('scale_ratio'),photo_copy_count,selected_dimension.val()) }); $(document).queue(function() { var endLoading = -1; function upload(blobOrFile,file_parts_num,total_files) { var xhr = new XMLHttpRequest(); xhr.open('POST', 'spcprint_request.php?order_upl_chunk_data&uid='+window.uid+'×tamp='+window.uid_date_id+'&file_chunk_num='+file_parts_num+'&total_files='+total_files, true); xhr.onload = function(e) { if (e.target.response) { var order_response = JSON.parse(e.target.responseText); if (order_response.payment=='paypal') { $('#return_info').html('
'); swal({ title: 'Order received!', text: 'Your order is being processed.', type: 'success', showCancelButton: true, confirmButtonColor: '#5cb85c', confirmButtonText: 'Pay Now', cancelButtonText: 'Close', closeOnConfirm: true, closeOnCancel: true }, function(isConfirm){ if (isConfirm) { $("#paypal_pay_order").click(); } }); } else if (order_response.payment=='payfast') { $('#return_info').load('spcprint_request.php?payfast_form', {id:order_response.order_id,price:order_response.total_price}, function(){ $("#payfast_pay_order").hide(); swal({ title: 'Order received!', text: 'Your order is being processed.', type: 'success', showCancelButton: true, confirmButtonColor: '#5cb85c', confirmButtonText: 'Pay Now', cancelButtonText: 'Close', closeOnConfirm: true, closeOnCancel: true }, function(isConfirm){ if (isConfirm) { $("#payfast_pay_order").click(); } }); }); } else { swal({ title: 'Order received!', text: 'Your order is being processed.', type: 'success', showCancelButton: true, confirmButtonColor: '#5cb85c', confirmButtonText: 'Orders', cancelButtonText: 'Close', closeOnConfirm: true, closeOnCancel: true }, function(isConfirm){ if (isConfirm) { user_orders_form(); } }); }; }; endLoading++; $('.spc_print_loading_text').html('Uploading to Server: '+endLoading+' of '+(total_files-1)+' files uploaded'); if (endLoading==(total_files-1)) { $(".spc_print_loading, .spc_print_loading_overlay").fadeOut('slow'); $('#spc_print_loading_spiner').slideUp(); $('#uploaded_photos').html(''); $('#no_photo_added_cover').fadeIn('slow'); recalc_price('#total_order_price'); }; $(document).dequeue(); }; $('.spc_print_loading_text').html('Uploading to Server: '+endLoading+' of '+(total_files-1)+' files uploaded'); $('#processing_progress_bar').val('0').attr('max','100').hide(); $('#spc_print_loading_spiner').slideDown('slow'); $(".spc_print_loading, .spc_print_loading_overlay").show(); xhr.send(blobOrFile); } var file_parts_num=1; var total_files=window.order_package.length; for (var i = 0; i < total_files; i++) { upload(JSON.stringify(window.order_package[i]),file_parts_num,total_files); file_parts_num++; }; }); } _crop_image = function(imgblob,cropw,croph,cropy,cropx,dimension_w,dimension_h,scale_ratio,photo_copy_count,dimension_id){ //unset_console.log('params_received= '+imgblob+','+cropw+ ',' + croph + ',' + cropy + ',' + cropx + ',' + dimension_w + ',' + dimension_h+','+scale_ratio); function croping_image(imgblob,cropw,croph,cropy,cropx,dimension_w,dimension_h,scale_ratio,photo_copy_count,dimension_id){ var xhr = new XMLHttpRequest; xhr.onload = function() { var recoveredBlob = xhr.response; var reader = new FileReader(); reader.onload = function(evt) { var img = new Image(); img.onload = function(){ canvas_width = parseInt(cropw/scale_ratio); canvas_height = parseInt(croph/scale_ratio); start_x=parseInt(cropx/scale_ratio); start_y=parseInt(cropy/scale_ratio); var canvas = document.createElement("canvas"); canvas.width = canvas_width; canvas.height = canvas_height; var ctx = canvas.getContext("2d"); ctx.drawImage(img,start_x,start_y,canvas_width,canvas_height,0,0,canvas_width,canvas_height); if (canvas_width>canvas_height) { tmp_h=dimension_h; dimension_h=dimension_w; dimension_w=tmp_h; }; resize_width=parseInt(((dimension_w/10)*150)/2.54); resize_height=parseInt(((dimension_h/10)*150)/2.54); //unset_console.log('resizes= '+resize_width+" "+resize_height); if (resize_width>canvas_width||resize_height>canvas_height) { resize_width=canvas_width; resize_height=canvas_height; }; var canvas_resize = document.createElement("canvas"); canvas_resize.width = resize_width; canvas_resize.height = resize_height; var ctx_resize = canvas_resize.getContext("2d"); ctx_resize.drawImage(ctx.canvas, 0, 0, resize_width, resize_height); var j = canvas_resize.toDataURL("image/jpeg", 1); order_package_collector(j,photo_copy_count,dimension_id); $(document).dequeue(); } img.src = evt.target.result; } reader.readAsDataURL(recoveredBlob); }; xhr.open('GET', imgblob); xhr.responseType = 'blob'; xhr.send(); } $(document).queue(function() { croping_image(imgblob,cropw,croph,cropy,cropx,dimension_w,dimension_h,scale_ratio,photo_copy_count,dimension_id); }); }; function order_package_collector(j,photo_copy_count,dimension_id){ //unset_console.log(j); window.order_package.push({img: j,photo_copy_count: photo_copy_count,dimension_id: dimension_id}); } function save_user_settings(){ loading_button_animation('start','#save_user_settings_button'); jQuery("#return_info").load('spcprint_request.php?save_u_settings', {password:jQuery("#spc_user_password").val(), repassword:jQuery("#spc_user_verifypassword").val(), spc_user_name:jQuery("#spc_user_name").val(), spc_user_surname:jQuery("#spc_user_surname").val(), spc_user_vatid:jQuery("#spc_user_vatid").val(), spc_user_taxcode:jQuery("#spc_user_taxcode").val(), spc_user_company:jQuery("#spc_user_company").val(), spc_user_address:jQuery("#spc_user_address").val(), spc_user_zip:jQuery("#spc_user_zip").val(), spc_user_city:jQuery("#spc_user_city").val(), spc_user_state:jQuery("#spc_user_state").val(), spc_user_country:jQuery("#spc_user_country").val(), spc_user_ship_company:jQuery("#spc_user_ship_company").val(), spc_user_ship_address:jQuery("#spc_user_ship_address").val(), spc_user_ship_zip:jQuery("#spc_user_ship_zip").val(), spc_user_ship_city:jQuery("#spc_user_ship_city").val(), spc_user_ship_state:jQuery("#spc_user_ship_state").val(), spc_user_ship_country:jQuery("#spc_user_ship_country").val(), salt:jQuery("#salt").val()}, function() { loading_button_animation('stop','#save_user_settings_button'); }); } function spcprint_login_helper(e) { if (e.keyCode == 13) { try_login(); } } function spcprint_recovery_helper(e) { if (e.keyCode == 13) { do_recovery(); } } ////*************************** function add_new_img(img_reized,canvas_width,canvas_height,scale_ratio,original_img,total_added) { $("#processing_progress_bar").show(); $(".spc_print_loading_text").html('Processing images '+(img_added_counter+1)+"/"+total_img_must_process); $("#processing_progress_bar").val((img_added_counter+1)); //unset_console.log(+new Date+" Исполнился"); crop_max_size = 175; ratio_final = 0; img_id = IDGenerator(); ratio_w = canvas_width / crop_max_size; ratio_h = canvas_height / crop_max_size; //unset_console.log("w=" + ratio_w + " h=" + ratio_h); if (ratio_w > ratio_h) { crop_width = canvas_width / ratio_w; crop_height = canvas_height / ratio_w; ratio_final = ratio_w; orient = 'horizontal'; } else { crop_width = canvas_width / ratio_h; crop_height = canvas_height / ratio_h; ratio_final = ratio_h; orient = 'vertical'; }; papers_types_template=''; window.added_img_ids.push(img_id); window.img_handler_template+='
  • '+papers_types_template+'
  • '; img_added_counter++; $(document).dequeue(); } function init_images_functions(img_id){ //unset_console.log(img_id); for (var i = 0; i < img_id.length; i++) { $('#cropimageid-' + img_id[i]).cropbox({ width: $('#cropimageid-' + img_id[i]).attr('cropwidth'), height: $('#cropimageid-' + img_id[i]).attr('cropheight'), showControls: 'auto' }) .on('cropbox', function(event, results, img) { //unset_console.log('zzz= '+results.cropW + ',' + results.cropH + ',' + results.cropY + ',' + results.cropX + ',' + crop_width + ',' + crop_height); $(event.target).attr({ "cropW": results.cropW, "cropH": results.cropH, "cropY": results.cropY, "cropX": results.cropX }); // download = $(this).parent().parent().parent().children('.download').children('a'); // download.attr('href', img.getDataURL()); }); $(".photo_paper_dimension-" + img_id[i]).chained(".photo_paper_class-" + img_id[i]); // $(".photo_paper_dimension-" + img_id[i]).bind("change", function(event) { // }); }; $('[data-toggle="tooltip"]').tooltip(); } function change_dimension_bind(bind_img_id){ //unset_console.log("hello"); if ($(".photo_paper_dimension-" + bind_img_id).val()!='' && $(".photo_paper_class-"+bind_img_id).val()!='') { jQuery("#photo_unit_price-" + bind_img_id).html($(".photo_paper_dimension-"+bind_img_id+" option:selected").attr("unit-price")); jQuery("#photo_unit_price-" + bind_img_id).attr("data-original-title", $(".photo_paper_dimension-"+bind_img_id+" option:selected").attr("all-price")); resize_crop(bind_img_id, $(".photo_paper_dimension-"+bind_img_id+" option:selected").attr("dimension_w"), $(".photo_paper_dimension-"+bind_img_id+" option:selected").attr("dimension_h")); recalc_price('#total_order_price'); } } function resize_crop(id,width,height){ //unset_console.log(width+"======"+height); crop_max_size=175; ratio_final=0; orient=$("#cropimageid-"+id).attr('image_orient'); ratio_w=width/crop_max_size; ratio_h=height/crop_max_size; if (orient=='horizontal') { crop_width=height/ratio_h; crop_height=width/ratio_h; ratio_final=ratio_w; } else { crop_width=width/ratio_h; crop_height=height/ratio_h; ratio_final=ratio_h; }; //unset_console.log(orient); //unset_console.log("w="+ratio_w+" h="+ratio_h); //unset_console.log("cw="+crop_width+" ch="+crop_height); // jQuery("#cropimageid-"+id).attr({"cropw":"0","croph":"0", "cropy":"0", "cropx":"0"}); jQuery("#cropimageid-"+id).cropbox({width: crop_width, height: crop_height}); jQuery("#cropimageid-"+id).attr({"cropwidth":crop_width,"cropheight":crop_height, "cropratio":ratio_final}); } function clear_crop_scale(){ jQuery('.crop_sized_up').each(function(){ jQuery(this).removeClass('crop_sized_up'); jQuery(this).css('top', '').css('left', ''); jQuery(this).children('.cropControls').removeClass('crop_size_up_controls'); }); } function crop_scale(id){ cropelem=jQuery("#"+id).parent(); if (cropelem.hasClass('crop_sized_up')) { clear_crop_scale(); } else { if (jQuery('.crop_sized_up').length>0){ clear_crop_scale(); } cropelem.addClass('crop_sized_up'); cropelem.css({ "top": (((jQuery(window).height() - cropelem.outerHeight()) / 2) + jQuery(window).scrollTop() + "px"), "left": (((jQuery(window).width() - cropelem.outerWidth()) / 2) + jQuery(window).scrollLeft() + "px") }); cropelem.children('.cropControls').addClass('crop_size_up_controls'); }; } function recalc_price(target){ loading_animation_small(target); total_price=0; total_count=0; $(".photoblock").each(function() { selected_papaer_dim=$(this).children("select[class*='photo_paper_dimension-']"); selected_count=$(this).children("div.number-spinner").children('input').val() prices=$("option:selected", selected_papaer_dim).attr("all-price-data"); if (prices!=undefined) { var price_arr = prices.split("#"); for (var i = price_arr.length; i >= 0; i--) { if (!price_arr[i]) price_arr.splice(i, 1); } for (var i = 0; i < price_arr.length; i++) { price_temp_arr=price_arr[i].split("-"); if (parseInt(selected_count)>=parseInt(price_temp_arr[0])) { match_price_per_count=price_temp_arr[1]; }; }; total_price+=selected_count*match_price_per_count; }; total_count+=parseInt(selected_count); }); $(target).html('Total:

    '+parseFloat(total_price.toFixed(4))+' EUR

    ('+total_count+' photo)').fadeIn('fast'); } function paper_print_to_all(paper_class,paper_dim){ $(".photoblock").each(function() { $(this).children("select[class*='photo_paper_class-']").val(paper_class).change(); $(this).children("select[class*='photo_paper_dimension-']").val(paper_dim).change(); }); recalc_price('#total_order_price'); } function IDGenerator() { this.length = 8; this.timestamp = +new Date; var _getRandomInt = function( min, max ) { return Math.floor( Math.random() * ( max - min + 1 ) ) + min; } var ts = this.timestamp.toString(); var parts = ts.split( "" ).reverse(); var id = ""; for( var i = 0; i < this.length; ++i ) { var index = _getRandomInt( 0, parts.length - 1 ); id += parts[index]; } return id; } function dataURLToBlob(dataURL) { var BASE64_MARKER = ';base64,'; if (dataURL.indexOf(BASE64_MARKER) == -1) { var parts = dataURL.split(','); var contentType = parts[0].split(':')[1]; var raw = decodeURIComponent(parts[1]); return new Blob([raw], {type: contentType}); } var parts = dataURL.split(BASE64_MARKER); var contentType = parts[0].split(':')[1]; var raw = window.atob(parts[1]); var rawLength = raw.length; var uInt8Array = new Uint8Array(rawLength); for (var i = 0; i < rawLength; ++i) { uInt8Array[i] = raw.charCodeAt(i); } return new Blob([uInt8Array], {type: contentType}); }