Advertisement
Guest User

Untitled

a guest
May 20th, 2012
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 17.31 KB | None | 0 0
  1. <?php
  2. global $wpdb;
  3. $wpdb->show_errors();
  4.  
  5. //include the S3 class  
  6. if (!class_exists('S3'))require_once('S3.php');  
  7.  
  8. //AWS access info  
  9. if (!defined('awsAccessKey')) define('awsAccessKey', 'AKIAIDSHPHGVRUSFETCQ');  
  10. if (!defined('awsSecretKey')) define('awsSecretKey', 'ScYxY2u9RxjgQEHiuGBOp7YO6R/Lu/9vgEkmFfRX');  
  11.  
  12. //instantiate the class  
  13. $s3 = new S3(awsAccessKey, awsSecretKey);  
  14. //code($_POST,'post');
  15. //check whether a form was submitted  
  16. if(isset($_POST['Submit'])){
  17.    
  18.     //retreive post variables  
  19.     $webinarName = $_FILES['theFile']['name'];  
  20. //    $fileTempName = $_FILES['theFile']['tmp_name'];
  21.    
  22.     if (!empty($_POST['theTitle'])) {
  23.        
  24.         $fileTitle = $_POST['theTitle'];
  25.         $fileTitle = str_replace(' ', '-', $fileTitle);
  26.         $fileTitle = strtolower($fileTitle);
  27.         $fileTitle .= '-';
  28.         $fileTitle .= mt_rand(1000, 9999);
  29.        
  30.     } else {
  31.        
  32.         $fileTitle = $webinarName;
  33.        
  34.     }
  35.    
  36.     if ($_FILES['theFile']['size'] != 0) {
  37.        
  38.         $webinarType = strcmp($_FILES['theFile']['type'], 'video/mp4');
  39.        
  40.         if($webinarType == 0) {
  41.            
  42.             $webinarFile = $fileTitle.'.mp4';
  43.             $webinarTempName = $_FILES['theFile']['tmp_name'];
  44.            
  45.         } else {
  46.            
  47.             echo 'Webinar must be .mp4';
  48.            
  49.         }
  50.        
  51.     }
  52.    
  53.     if ($_FILES['thePDF']['size'] != 0){
  54.        
  55.         $pdfType = strcmp($_FILES['thePDF']['type'], 'application/pdf');
  56.        
  57.         if($pdfType == 0) {
  58.            
  59.             $pdfFile = $fileTitle.'.pdf';
  60.             $pdfTempName = $_FILES['thePDF']['tmp_name'];
  61.            
  62.         } else {
  63.            
  64.             echo 'PDF must be .pdf';
  65.            
  66.         }
  67.        
  68.     }
  69.    
  70.     $theSite = $_POST['theSite'];
  71.  
  72.     $p = strpos($theSite, 'p');
  73.     $s = strpos($theSite, 's');
  74.  
  75.     if((string)$p == "0") {
  76.         $amazon_id = str_replace('p_', '', $theSite);
  77.         $sec_id = 2; //elitetradersgroup
  78.     } else if ((string)$s == "0") {
  79.         $sec_id = str_replace('s_', '', $theSite);
  80.         $amazon_id = $wpdb->get_var("SELECT amazon_section_id FROM bu_amazon_secondary_sections WHERE secondary_id = $sec_id");
  81.     }
  82.    
  83.     if(!empty($webinarFile)) {
  84.  
  85.         $var_arr = array($amazon_code,$webinarFile);
  86.         $vars = implode('J05h', $var_arr);
  87.  
  88.         $enc = base64_encode($vars);
  89.         $url = get_bloginfo('url').'/webinar.php?wid='.$enc;
  90.  
  91.         //move the file  
  92.         if ($s3->putObjectFile($webinarTempName, "elitetradersgroup", $webinarFile, S3::ACL_PUBLIC_READ)) {
  93.  
  94.             $wpdb->insert('bu_amazon_archive',array('amazon_title' => $_POST['theTitle'], 'amazon_file' => $webinarFile, 'amazon_bucket' => $_POST['amazon_bucket'],'amazon_section_id' => $amazon_id, 'etg_link' => $url, 'amazon_secondary_section_id' => $sec_id));
  95.  
  96.             echo "<p>Webinar Successfully Uploaded.</p>";
  97.             echo "<p>Please be sure to click the link and play the video to confirm that it works</p>";
  98.  
  99.             $webinar_id = $wpdb->get_var($wpdb->prepare("SELECT amazon_id FROM bu_amazon_archive WHERE amazon_file = '{$webinarFile}'"));
  100.  
  101.             echo '<p><a href="'.$url.'" target="_blank">Webinar</a></p>';
  102.  
  103.             } else {  
  104.  
  105.             echo "<p><strong>Something went wrong while uploading your webinar... Please try again...</strong></p>";  
  106.         }
  107.     }
  108.            
  109.         if(!empty($pdfFile)) {
  110.  
  111.             //move the file  
  112.             if ($s3->putObjectFile($pdfTempName, "elitetradersgroup", $pdfFile, S3::ACL_PUBLIC_READ)) {
  113.                
  114.                 $url = 'http://elitetradersgroup.s3.amazonaws.com/'.$pdfFile;
  115.  
  116.                 $wpdb->insert('bu_amazon_archive',array('amazon_title' => $_POST['theTitle'], 'amazon_file' => $pdfFile, 'amazon_bucket' => $_POST['amazon_bucket'],'amazon_section_id' => $amazon_id, 'etg_link' => $url, 'amazon_secondary_section_id' => $sec_id));
  117.  
  118.                 echo "<p>PDF Successfully Uploaded.</p>";
  119.                 echo "<p>Please be sure to click the link and view the pdf to confirm it was done successfully</p>";
  120.  
  121.                 $pdf_id = $wpdb->get_var($wpdb->prepare("SELECT amazon_id FROM bu_amazon_archive WHERE amazon_file = '{$pdfFile}'"));
  122.  
  123.                 echo '<p><a href="'.$url.'" target="_blank">PDF</a></p>';
  124.  
  125.             } else {  
  126.  
  127.             echo "<p><strong>Something went wrong while uploading your pdf... Please try again...</strong></p>";  
  128.         }
  129.     }
  130.    
  131.     if (isset($_POST['positions'])) {
  132.        
  133.         $new_pos = $_POST['np-trades'];
  134.         $cur_pos = $_POST['cur-trades'];
  135.         $update_pos = $_POST['update-trades'];
  136.        
  137.         $positions = array(
  138.             'new_trade' => $new_pos,
  139.             'cur_trade' => $cur_pos,
  140.             'update_trade' => $update_pos
  141.         );
  142.        
  143.         $wpdb->insert('bu_email_positions', $positions);
  144.        
  145.         $position_id = $wpdb->get_var($wpdb->prepare("SELECT position_id FROM bu_email_positions ORDER BY position_id DESC"));
  146.        
  147.     }
  148.    
  149.     if (isset($_POST['message'])) {
  150.         $message = $_POST['message'];
  151.     }
  152.    
  153.     if(isset($_POST['additional-webinar-selection'])) {
  154.         $extra_webinar = $_POST['additional-webinar-selection'];
  155.     }
  156.            
  157.     $email_array = array(
  158.         'email_title' => $_POST['theTitle'],
  159.         'webinar_id' => $webinar_id,
  160.         'position_id' => $position_id,
  161.         'pdf_id' => $pdf_id,
  162.         'sec_id' => $sec_id,
  163.         'message' => $message,
  164.         'additional_webinar_id' => $extra_webinar
  165.     );
  166.     $wpdb->insert('bu_email_archive', $email_array);
  167.     $email_id = $wpdb->get_var($wpdb->prepare("SELECT email_id FROM bu_email_archive ORDER BY email_id DESC"));
  168.    
  169.    
  170.    
  171.         $check_query = "SELECT tn.*, tt.inf_tag_type FROM bu_inf_tag_name AS tn
  172.        LEFT OUTER JOIN bu_inf_tag_type AS tt
  173.        ON tn.inf_tag_type_id = tt.inf_tag_type_id
  174.        WHERE tn.inf_tag_type_id = 2";
  175.  
  176.         $checks = $wpdb->get_results($wpdb->prepare($check_query));
  177.         ?>
  178.  
  179.         <form id="inf_send_email" method="POST" action="send-email">
  180.             <?php
  181.                 foreach ($checks as $check) {
  182.                     echo '<input type="checkbox" ';
  183.                     echo 'id="'.$check->inf_tag_id.'" name="tags[]" value="'.$check->inf_tag_id.'"><label for="'.$check->inf_tag_id.'">'.$check->inf_tag_name.'</label><br />';
  184.                 }
  185.             ?>
  186.  
  187.             <input type="hidden" name="email_id" value="<?php echo $email_id; ?>" />
  188.             <input type="hidden" name="sec_id" value="<?php echo $sec_id; ?>" />
  189.             <input type="hidden" name="from" value="Elite Traders Group" />
  190.             <input type="hidden" name="fromemail" value="donotreply@elitetradersgroup.com.au" />
  191.             <input type="submit" name="submit" value="Submit" />
  192.         </form>
  193.         <?php
  194.  
  195. } else {
  196.    
  197.  
  198.     function show_hide_aupload() {
  199.         $url = plugin_dir_url()."broker-uploader/amazon/";
  200.         ?>
  201.             <script type="text/javascript" src="<?php echo $url; ?>mootools.js"></script>
  202.             <script type="text/javascript" src="<?php echo $url; ?>progress.js"></script>
  203.             <script type="text/javascript">
  204.                
  205.                 jQuery(document).ready(function(){
  206.                    
  207.                     jQuery('#amazon-upload').submit(function(){
  208.                        
  209. //                        jQuery(this).hide();
  210.                        
  211.                     });
  212.                    
  213.                     jQuery('#theTitle').keyup(function(){
  214.                        
  215.                         var count = $(this).val().length;
  216.                         var limit = 80; //must be amazon_file limit - 10
  217.                        
  218.                         if(count > limit) {
  219.                            
  220.                             jQuery(this).val(jQuery(this).val().substr(0, limit));
  221.                             jQuery('#amazon_title_char_count').css('color','red');
  222.                             jQuery('#excess_warning').html("You may only have up to "+limit+" characters in the title. Excess characters have been truncated");
  223.                             jQuery('#excess_warning').show('fast');
  224.                             var count = $(this).val().length;
  225.                            
  226.                         } else {
  227.                            
  228.                             jQuery('#amazon_title_char_count').css('color','inherit');
  229.                             jQuery('#excess_warning').hide('fast');
  230.                            
  231.                         }
  232.                        
  233.                         jQuery('#amazon_title_char_count').html(count+"/"+limit+" characters used");
  234.                        
  235.                     });
  236.                    
  237.                     jQuery('#message-ta').keyup(function(){
  238.                        
  239.                         var count = $(this).val().length;
  240.                         var limit = 5000;
  241.                        
  242.                         if(count > limit) {
  243.                            
  244.                             jQuery(this).val(jQuery(this).val().substr(0, limit));
  245.                             jQuery('#message_char_count').css('color','red');
  246.                             jQuery('#message_excess_warning').html("You may only have up to "+limit+" characters in the title. Excess characters have been truncated");
  247.                             jQuery('#message_excess_warning').show('fast');
  248.                             var count = $(this).val().length;
  249.                            
  250.                         } else {
  251.                            
  252.                             jQuery('#message_char_count').css('color','inherit');
  253.                             jQuery('#message_excess_warning').hide('fast');
  254.                            
  255.                         }
  256.                        
  257.                         jQuery('#message_char_count').html(count+"/"+limit+" characters used");
  258.                        
  259.                     });
  260.                    
  261.                     jQuery("input:checkbox").change(function(){
  262.                        
  263.                         var div = '#'+jQuery(this).attr('value');
  264.                        
  265.                         if( jQuery(this).is(":checked") ) {
  266.                            
  267.                             jQuery(div).show('fast');
  268.                            
  269.                         } else {
  270.                            
  271.                             jQuery(div).hide('fast');
  272.                            
  273.                         }
  274.                        
  275.                     });
  276.                    
  277.                 });
  278.                
  279.                 function showProgress() {
  280.                    
  281.                     var pb = document.getElementById("uploader");
  282.                     pb.innerHTML = '<img src="/wp-content/plugins/broker-uploader/amazon/uploading-1.gif" width="116" height ="119"/>';
  283.                     pb.style.display = '';
  284.                    
  285.                 }
  286.             </script>
  287. <script type="text/javascript">
  288. window.addEvent('domready',function()
  289. {
  290.  $$('form.upload').each(function(o_form)
  291.  {
  292.   o_form.fileUpload = new uploadProgress(o_form,{
  293.          's_actionHelper' : '<?php echo $url; ?>progress.php',
  294.          'i_interval' : 500
  295.              });
  296.  });
  297. });
  298. </script>
  299.         <?php
  300.     }
  301.     add_action('wp_footer','show_hide_aupload');
  302. ?>
  303.             <h3><a href="/broker-tools/amazon-upload/webinar-archive/">View Archive</a></h3>
  304.             <style type="text/css">
  305.                 .sec_name, label {
  306.                     display: block;
  307.                     clear: right;
  308.                 }
  309.                 .sec_name {
  310.                     font-style: italic;
  311.                 }
  312.                 .title {
  313.                     font-weight: bold;
  314.                     margin:10px 0;
  315.                 }
  316.                 .radio {
  317.                     font-weight: normal;
  318.                     float: left;
  319.                 }
  320.                 input[type="radio"], input[type="checkbox"] {
  321.                     display: block;
  322.                     float: left;
  323.                     margin-right: 5px;
  324.                 }
  325.                 .option {
  326.                     display: block;
  327.                     float:left;
  328.                     width: 100%;
  329.                 }
  330.                 .opt-cont {
  331.                     margin-left: 10px;
  332.                     float:left;
  333.                     width:100%;
  334.                 }
  335.             </style>
  336. <form action="" method="post" class="upload" enctype="multipart/form-data" id="amazon-upload">
  337.     <label class="title" for="theTitle">Email Title</label>
  338.     <input id="theTitle" type="text" name="theTitle" /><div id="amazon_title_char_count"></div><div id="excess_warning" style="display:none; font-weight: bold;color: red;"></div>
  339.    
  340.     <label class="title" for="theSite">Select Email From</label>
  341. <!--    <select id="theSite" name="theSite">-->
  342.         <?php
  343.         $sites = $wpdb->get_results($wpdb->prepare("SELECT * FROM bu_amazon_sections"));
  344.         foreach ($sites as $site) {
  345. //            echo '<option value="'.$site->amazon_section_id.'">'.$site->amazon_section_name.'</option>';
  346. //            echo '<input type="radio" id="primary_'.$site->amazon_section_id.'" name="theSite" value="p_'.$site->amazon_section_id.'" /><label for="primary_'.$site->amazon_section_id.'">'.$site->amazon_section_name.'</label>';
  347.             echo '<div class="option">';
  348.             echo '<span class="sec_name">'.$site->amazon_section_name.'</span>';
  349.             if ($site->has_secondary) {
  350.                 $secondaries = $wpdb->get_results($wpdb->prepare("SELECT * FROM bu_amazon_secondary_sections WHERE amazon_section_id = $site->amazon_section_id ORDER BY secondary_name ASC"));
  351.                 foreach($secondaries as $secondary) {
  352.                    
  353.                     $class = $secondary->secondary_name;
  354.                     $class = strtolower($class);
  355.                     $class = str_replace(" ","-",$class);
  356.                    
  357.                     echo '<div class="opt-cont">';
  358.                     echo '<input class="radio '.$class.'" type="radio" id="sec_'.$secondary->secondary_id.'" name="theSite" value="s_'.$secondary->secondary_id.'" /><label class="radio" for="sec_'.$secondary->secondary_id.'">'.$secondary->secondary_name.'</label>';
  359.                     echo '</div>';
  360.                 }
  361.             }
  362.             echo "</div>";
  363.         } ?>
  364.    
  365.     <label class="title" for="theFile">.mp4 Video to Upload</label>
  366.     <input id="theFile" name="theFile" type="file" accept="video/mp4" />
  367.    
  368.     <label class="title">Extras</label>
  369.    
  370.     <input type="checkbox" id="pdf" name="pdf" value="pdf-box"><label for="pdf">Include PDF</label>
  371.     <input type="checkbox" id="positons" name="positions" value="positions-box"><label for="positons">Include Positions</label>
  372.     <input type="checkbox" id="message" name="message" value="message-box"><label for="message">Include message</label>
  373.     <input type="checkbox" id="additional-webinar" name="additional-webinar" value="additional-webinar-box"><label for="additional-webinar">Include Additional Webinar</label>
  374.    
  375.     <div id="pdf-box" style="display:none;">
  376.         <label class="title" for="thePDF">.pdf File to Upload</label>
  377.         <input id="thePDF" name="thePDF" type="file" accept="application/pdf" />
  378.     </div>
  379.     <div id="positions-box" style="display:none;">
  380.         <label class="title">Positions Info</label>
  381.         <label>New/Potential Trades</label>
  382.         <input type="text" name="np-trades" />
  383.         <label>Current Trades</label>
  384.         <input type="text" name="cur-trades" />
  385.         <label>Updates</label>
  386.         <input type="text" name="update-trades" />
  387.     </div>
  388.     <div id="message-box" style="display:none;">
  389.         <label class="title">Email Message</label>
  390.         <textarea id="message-ta" name="message" cols="50" rows="10"></textarea>
  391.         <div id="message_char_count"></div>
  392.         <div id="message_excess_warning" style="display:none; font-weight: bold;color: red;"></div>
  393.     </div>
  394.     <div id="additional-webinar-box" style="display:none;">
  395.         <label class="title">Select Additional Webinar</label>
  396.         <select name="additional-webinar-selection">
  397.             <option value="0" selected>Please Select</option>
  398.             <?php
  399.             $additional_webinars = $wpdb->get_results($wpdb->prepare("SELECT aa.amazon_id, aa.amazon_title, ass.amazon_section_name FROM bu_amazon_archive AS aa LEFT OUTER JOIN bu_amazon_sections AS ass ON aa.amazon_section_id = ass.amazon_section_id WHERE amazon_file_type_id = 1 ORDER BY upload_date DESC  LIMIT 10"));
  400.             foreach($additional_webinars as $additional_webinar) {
  401.                 echo '<option value="'.$additional_webinar->amazon_id.'">'.$additional_webinar->amazon_title.'('.$additional_webinar->amazon_section_name.')</option>';
  402.             }
  403.             ?>
  404.         </select>
  405.     </div>
  406. <!--    </select>    -->
  407.  
  408.     <input type="hidden" value="elitetradersgroup" name="amazon_bucket" />
  409.     <input name="Submit" type="submit" value="Upload" />
  410.            <!---->
  411.      
  412.  
  413. </form>  
  414. <div id="uploader" style="display:none;">
  415.     <img src="/wp-content/plugins/broker-uploader/amazon/uploading-1.gif" width="116" height ="119"/>
  416. </div>
  417. <?php } ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement