Location: PHPKode > projects > MembersGear > membersgear/templates/admin_product_upsell_m.tpl
{$ADMIN_HEADER}

<div id="content" class="setdiv">
     <div id='er'></div>
    {if $msg neq ''}
            <div {if $err eq 'true'} class="errormsg" {else} class="succmsg" {/if} style="width:500px">{$msg}</div>
           {/if} 
    <div id="full-contentdiv">  
          <div class="righttop">  
                <h2><center>
                     {if $IsEdit eq 'yes'}                   
                         Edit {$product_name} Upsell Flow 
                     {else}
                         Add {$product_name} Upsell Flow 
                     {/if}   
                    </center></h2>                                      
            </div>
         <div class="whole-page clear">  
             
        
             
            <!-- Place your content here -->
                {if $IsEdit eq 'yes'}
                     {assign var="action" value="update"}
                {else}
                           
                    {assign var="action" value="insert"}
                  
                {/if}
               
                    <form name="frmproductupsell" id='frmproductupsell' method="post" action="admin_product_upsell_m.php?action={$action}">
           {if $IsEdit eq 'yes'} 
          <center> 
           <span style="float:right;">
                     <input  class="btncss" type="button" id='btnDel' name="btnDel" style="cursor:pointer !important" value="Delete upsell" >
             </span>
           </center>   
             <br/>
             <br/> 
            {/if}          
                <div class="formformat">    
                   <center>
                          <table width="100%" cellspacing="1">
                            <tr>
                              <td width="2%">
                                <b>1.</b>
                              </td>                
                              <td width="32%">
                               Set First Upsell Product Page Link
                              </td> 
                              <td width="45%">
                                <input type="text" value="{$upsellurlLevel1}"  size="40" class="txtcss" id="upsellpagelink1" name="upsellpagelink1">
                                <input  class="btncss" type="button" name="btnSaveUpsell1" id="btnSaveUpsell1" value="+" onclick="productPlus1();" >
                              </td>
                               <td>
                               &nbsp;
                              </td> 
                            </tr>
                           <tr id='upsell1_yes' style="display:none">
                              <td >
                                &nbsp;
                              </td>
                              <td >
                                <b>Select First Upsell Product</b>
                              </td> 
                              <td  >
                                <b>For "Yes" button show</b> &nbsp;&nbsp; <b>For "No" button show</b>  
                               </td>
                              <td>
                               &nbsp;
                              </td> 
                            </tr>
                            <tr id="upsell1_products" style="display:none" >
                                <td  style="height:30px;">
                                &nbsp;
                              </td>
                              <td  style="height:30px;">
                                <select name="upsellSelectProduct1" id="upsellSelectProduct1"  style="width:176px;" onchange="return is_in_upsellFlow(this.name,this);">
                                  <option value="select" selected="selected"> Select..</option>
                                   {foreach key=key item=item from=$upsellproducts}
                                     <option value="{$key}" {if $upsellyesLevel1 eq $key } selected="selected" {/if} >{$item}</option> 
                                   {/foreach}
                                </select>
                              </td> 
                              <td  style="height:30px;">
                                <select name="Upsell2Selectyes" id="Upsell2Selectyes"  style="width:176px;" onchange="showHideSecondUpsell(this.value);">
                                  <option value="select" selected="selected">Select..</option>
                                  <option value="secondUpsell" {if $upsellyesLevel1_action eq 'U'} selected="selected" {/if}>show second upsell page</option> 
                                  <option value="thankyoupage" {if $upsellyesLevel1_action eq 'T'} selected="selected" {/if}>show thank you page</option> 
                                </select>  &nbsp;&nbsp;&nbsp;
                                <select name="Upsell2Select" id="Upsell2Select"  style="width:176px;" onchange="showHideSecondUpsell(this.value);">
                                  <option value="select" selected="selected">Select..</option>
                                  <option value="secondUpsell" {if $upsellnoLevel1 eq 'U'} selected="selected" {/if}>show second upsell page</option> 
                                  <option value="thankyoupage" {if $upsellnoLevel1 eq 'T'} selected="selected" {/if}>show thank you page</option> 
                                </select>  
                              </td>                                            
                              <td  style="height:30px;">
                                 {if $IsEdit eq 'yes'}     
                                   <a href="admin_getupsellpageButtuns.php?id={$upsellPaygear_pro_id_Level1}" style="text-decoration:underline">Get Upsell Page Button </a>
                                 {/if}
                              </td>  
                            </tr>
                            
                           <tr style="display:none" id='upsell2'>
                              <td  style="padding-top:20px;">
                                <b>2.</b>
                              </td>                
                              <td style="padding-top:20px;">
                               Set Second Upsell Product Page Link
                              </td> 
                              <td style="padding-top:20px;">
                                <input type="text" value="{$upsellurlLevel2}"  size="40" class="txtcss" id="upsellpagelink2" name="upsellpagelink2">
                                <input  class="btncss" type="button" name="btnSaveUpsell2" id="btnSaveUpsell2" value="+" onclick="productPlus2();" >
                              </td>
                              <td style="padding-top:20px;">&nbsp;</td>
                            </tr>
                           <tr id="upsell2_yes" style="display:none;">
                              <td >
                                &nbsp;
                              </td>
                              <td >
                                <b>Select Second Upsell Product</b>
                              </td>
                              <td >
                               <b>For "Yes" button show</b> &nbsp;&nbsp; <b>For "No" button show</b>  
                               </td>
                              <td >&nbsp;</td> 
                            </tr>
                            <tr id="upsell2_products" style="display:none;">
                              <td >
                                &nbsp;
                                </td>
                                <td >
                                 <select name="upsellSelectProduct2" id="upsellSelectProduct2"  style="width:176px;" onchange="return is_in_upsellFlow(this.name,this);">
                                  <option value="select">Select..</option>
                                  {foreach key=key item=item from=$upsellproducts}
                                     <option value="{$key}" {if $upsellyesLevel2 eq $key } selected="selected" {/if} >{$item}</option> 
                                   {/foreach}
                                  </select>
                                </td> 
                                <td >
                                 <select name="Upsell3Selectyes" id="Upsell3Selectyes"  onchange="showHideThirdUpsell(this.value);" style="width:176px;">
                                  <option value="select">Select..</option>
                                  <option value="thirdupsell" {if $upsellyesLevel2_action eq 'U'} selected="selected" {/if} >show third upsell page</option> 
                                  <option value="thankyoupage" {if $upsellyesLevel2_action eq 'T'} selected="selected" {/if} >show thank you page</option> 
                                </select> &nbsp;&nbsp;&nbsp;  
                                  <select name="Upsell3Select" id="Upsell3Select"  onchange="showHideThirdUpsell(this.value);" style="width:176px;">
                                  <option value="select">Select..</option>
                                  <option value="thirdupsell" {if $upsellnoLevel2 eq 'U'} selected="selected" {/if} >show third upsell page</option> 
                                  <option value="thankyoupage" {if $upsellnoLevel2 eq 'T'} selected="selected" {/if} >show thank you page</option> 
                                </select>
                             
                              </td>
                              <td >
                               {if $IsEdit eq 'yes'}     
                                 <a href="admin_getupsellpageButtuns.php?id={$upsellPaygear_pro_id_Level2}"   style="text-decoration:underline">Get Upsell Page Button </a>
                               {/if}
                              </td> 
                            </tr>
                            <tr id='upsell3' style="display:none">
                              <td style="padding-top:20px;" >
                                <b>3.</b>
                              </td>                
                              <td style="padding-top:20px;" >
                               Set Third Upsell Product Page Link
                              </td> 
                              <td style="padding-top:20px;">
                                <input type="text" value="{$upsellurlLevel3}"  size="40" class="txtcss" id="upsellpagelink3" name="upsellpagelink3">
                                <input  class="btncss" type="button" name="btnSaveUpsell3" id="btnSaveUpsell3" value="+" onclick="productPlus3();" >
                              </td>
                              <td style="padding-top:20px;">&nbsp;</td>
                            </tr>
                            <tr id='upsell3_yes' style="display:none;">
                              <td >
                                &nbsp;
                              </td>
                              <td >
                                <b>Select Third Upsell Product</b>
                              </td> 
                                <td >
                                <b>For "Yes" button show</b> &nbsp;&nbsp; <b>For "No" button show</b>  
                               </td>
                              <td > &nbsp;</td>
                            </tr>
                            <tr style="display:none;" id='upsell3_products'>
                              <td > 
                                &nbsp;
                              </td>
                              <td > 
                                <select name="upsellSelectProduct3" id="upsellSelectProduct3"  style="width:176px;" onchange="return is_in_upsellFlow(this.name,this);">
                                  <option value="select">Select..</option>
                                  {foreach key=key item=item from=$upsellproducts}
                                     <option value="{$key}" {if $upsellyesLevel3 eq $key } selected="selected" {/if} >{$item}</option> 
                                   {/foreach}
                                </select>
                              </td> 
                              <td >
                                <select name="Upsell4Selectyes" id="Upsell4Selectyes" disabled="disabled"  style="width:181px;">
                                  <option value="thankyoupage" selected="selected">show thank you page</option> 
                                </select>&nbsp;&nbsp;&nbsp;  
                                <select name="Upsell4Select" id="Upsell4Select" disabled="disabled"  style="width:176px;">
                                  <option value="thankyoupage" selected="selected">show thank you page</option> 
                                </select>
                            
                              </td>
                              <td >
                               {if $IsEdit eq 'yes'}     
                                 <a href="admin_getupsellpageButtuns.php?id={$upsellPaygear_pro_id_Level3}"    style="text-decoration:underline">Get Upsell Page Button </a>
                               {/if}
                              </td> 
                            </tr>
                          </table>
                     
                         <br/>
                        <table  border="0"  cellspacing="0" cellpadding="0" width="80%"  >
                           <tr>
                           
                                <td  class="right-side-text" width="50%" style="text-align:right" >  <input class="btncss"  type="button" name="btn_submit" id='btn_submit' {if $IsEdit eq 'yes'}value="Save"{else}value="Add"{/if}>&nbsp;&nbsp;&nbsp;
                                  </td>
                                <td  class="buttontd" width="50%">  
                                    {if $IsEdit eq 'yes'}
                                    <input class="btncss"  id='btn_updatefrompaygear'  type="button" name="btn_updatefrompaygear" value="Update From Paygear" >&nbsp;&nbsp;&nbsp;
                                   {/if} 
                                    <input  class="btncss" type="button" name="btnBack" value="Cancel" onclick="window.location='admin_product_v.php'"></td>
                            </tr>  
                         
                        </table>      
                        </center> 
                        </div>
                      <input type="hidden" value="{$plus1}" name="plus1" id="plus1">
                      <input type="hidden" value="{$plus2}" name="plus2" id="plus2">
                      <input type="hidden" value="{$plus3}" name="plus3" id="plus3">
                      <input type="hidden" value="{$main_product_id}" name="main_product_id" id="main_product_id">
                     
                      <input type="hidden" value="{$upsellPaygear_pro_id_Level1}" name="upsellPaygear_pro_id_Level1" id="upsellPaygear_pro_id_Level1">
                      <input type="hidden" value="{$upsellPaygear_pro_id_Level2}" name="upsellPaygear_pro_id_Level2" id="upsellPaygear_pro_id_Level2">
                      <input type="hidden" value="{$upsellPaygear_pro_id_Level3}" name="upsellPaygear_pro_id_Level3" id="upsellPaygear_pro_id_Level3">
                     
                      <!--<input type="hidden" value="{$upsellnoLevel1_editId}" name="upsellnoLevel1_editId" id="upsellnoLevel1_editId">
                      <input type="hidden" value="{$upsellnoLevel2_editId}" name="upsellnoLevel2_editId" id="upsellnoLevel2_editId">
                      <input type="hidden" value="{$upsellnoLevel3_editId}" name="upsellnoLevel3_editId" id="upsellnoLevel3_editId">-->
                      
                   </form>
    </div>
</div>
        
 
 </div>


{literal}
 <script language="JavaScript" type="text/javascript">
    var $n = jQuery.noConflict();  
    

    function is_in_upsellFlow(usell_select_name,upsell_selected)
    {
       var val_selected=upsell_selected.value;
       var val_upsell_selector=usell_select_name;
       if(val_selected!="select")
       {
           if(val_upsell_selector=="upsellSelectProduct1")
           {
              var SecondSelectedVal=$n("#upsellSelectProduct2").val();
              var ThirdSelectedval=$n("#upsellSelectProduct3").val();
              if(val_selected==SecondSelectedVal || val_selected==ThirdSelectedval)
                {
                  alert("This product is alreay selected in upsell flow.");
                  $n(upsell_selected).attr('selectedIndex', 0);
                  return true;
                }
           }                                                      
          else if(val_upsell_selector=="upsellSelectProduct2")                                
           {
              var SecondSelectedVal=$n("#upsellSelectProduct1").val();
              var ThirdSelectedval=$n("#upsellSelectProduct3").val();
              if(val_selected==SecondSelectedVal || val_selected==ThirdSelectedval)
                {
                  alert("This product is alreay selected in upsell flow.");
                  $n(upsell_selected).attr('selectedIndex', 0);
                  return true; 
                }
           }                                                                     
            else if(val_upsell_selector=="upsellSelectProduct3")                                
           {
              var SecondSelectedVal=$n("#upsellSelectProduct1").val();
              var ThirdSelectedval=$n("#upsellSelectProduct2").val();
              if(val_selected==SecondSelectedVal || val_selected==ThirdSelectedval)
                {
                  alert("This product is alreay selected in upsell flow.");
                  $n(upsell_selected).attr('selectedIndex', 0);
                  return true; 
                }
           } 
       }
       
    } 
     function showHideSecondUpsell(valueOfSelectedOpt)
     {
        var yesaction=$n("#Upsell2Selectyes").val();
        var valueOfSelectedOpt=$n("#Upsell2Select").val();    
        if(valueOfSelectedOpt=='secondUpsell' || yesaction=='secondUpsell')
         {
            
            $n('#upsell2').fadeIn(500);  
        }
       else
        {
           
           $n('#upsell2').fadeOut(500);  
           $n('#upsell3').fadeOut(500);
           $n("#Upsell3Select").val('select');
           
 
           $n('#upsell3_products').fadeOut(500); 
           $n('#upsell3_yes').fadeOut(500); 
   
           
           $n('#upsell2_products').fadeOut(500); 
           $n('#upsell2_yes').fadeOut(500); 
     
           $n("#plus3").val('false');
           $n("#plus2").val('false');
        } 
     }  
     
     function showHideThirdUpsell(valueOfSelectedOpt)
     {
       var yesaction=$n("#Upsell3Selectyes").val(); 
       var valueOfSelectedOpt=$n("#Upsell3Select").val(); 
        if(valueOfSelectedOpt=='thirdupsell' || yesaction=='thirdupsell')
        {
            $n('#upsell3').fadeIn(500);  
        }
       else
        {
           $n('#upsell3').fadeOut(500);  
          

           $n('#upsell3_products').fadeOut(500); 
           $n('#upsell3_yes').fadeOut(500); 
         
           $n("#plus3").val('false'); 
        } 
     }    
     
    function productPlus1()
     {
         var upsellpagelink1Val=$n.trim($n("#upsellpagelink1").val());
         if(is_valid_URL(upsellpagelink1Val))
         {

             $n('#upsell1_products').fadeIn(500); 
             $n('#upsell1_yes').fadeIn(500); 
             $n("#plus1").val('true');
          }
        else
         {
           alert('Please enter valid url');
           $n("#upsellpagelink1").focus()
         }  
     } 
     
     function productPlus2()
     {
                    
         var upsellpagelink1Val=$n.trim($n("#upsellpagelink2").val());
         if(is_valid_URL(upsellpagelink1Val))
         {            

             $n('#upsell2_products').fadeIn(500); 
             $n('#upsell2_yes').fadeIn(500); 

             $n("#plus2").val('true');  
          }
         else
         {
           alert('Please enter valid url');
           $n("#upsellpagelink2").focus()
         } 
     }  
     
    function productPlus3()
     {
         
         var upsellpagelink1Val=$n.trim($n("#upsellpagelink3").val());
         if(is_valid_URL(upsellpagelink1Val))
         {            
          
 
             $n('#upsell3_products').fadeIn(500); 
             $n('#upsell3_yes').fadeIn(500); 

             $n("#plus3").val('true');
         }
         else
         {
           alert('Please enter valid url');
           $n("#upsellpagelink3").focus()
         }      
     } 
     
  function is_valid_URL(url) 
  {
   // alert(url);
    //var regexp = "/^(((ht|f)tp(s?))\:\/\/)?(www.|[a-zA-Z].)[a-zA-Z0-9\-\.]+\.(com|edu|gov|mil|net|org|biz|info|name|museum|us|ca|uk)(\/:[0-9]+)*(/($|[a-zA-Z0-9\.\,\;\?\'\\\+&%\$#\=~_\-]+))*$/";
    var regexp=/https?:\/\/([-\w\.]+)+(:\d+)?(\/([\w/_\.]*(\?\S+)?)?)?/;
    // var regexp = /^(http[s]?:\/\/|ftp:\/\/)?(www\.)?[a-zA-Z0-9-\.]+\.(com|net|org|edu|mil|gov|arpa|biz|aero|name|coop|info|pro|museum|tv|([a-z]{2}))$/;
     
     return(regexp.test(url));
   }
    
    
     function validateForm()
      {
            
            if($n("#plus1").val()=='false' || ! is_valid_URL($n("#upsellpagelink1").val()))
            {
             alert('Please enter url and click on add button.');
             $n("#upsellpagelink1").focus();
             return false;
            }
           else
            {
                
                     var finalresult=true; 
                     var error="";
                     var focus=''; 
                     var foc=1;
                     if($n("#upsellSelectProduct1").val()=='select')
                      {
                         finalresult=false;
                         error +='Please select upsell product.' +'\r\n'; 
                         if(foc==1)
                          {
                            focus='upsellSelectProduct1'; 
                             foc=0;
                          }  
                      }
                    
                     if($n("#Upsell2Selectyes").val()=='select')
                     {
                         finalresult=false;
                         error +='Please select what to show on yes button.' +'\r\n'; 
                         if(foc==1)
                          {
                            focus='Upsell2Selectyes'; 
                             foc=0;
                          }  
                    
                    } 
                   else if($n("#Upsell2Select").val()=='select')
                     {
                         finalresult=false;
                         error +='Please select what to show on no button.' +'\r\n'; 
                         if(foc==1)
                          {
                            focus='Upsell2Select'; 
                             foc=0;
                          }  
                    
                    }
                   
                   else if($n("#Upsell2Select").val()=='secondUpsell' || $n("#Upsell2Selectyes").val()=='secondUpsell' )
                   {
                         if($n("#plus2").val()=='false' || ! is_valid_URL($n("#upsellpagelink2").val()))
                         {
                            finalresult=false;
                             error +='Please enter url and click on add button' +'\r\n'; 
                             if(foc==1)
                              {
                                focus='upsellpagelink2'; 
                                 foc=0;
                              }
                    
                         }
                        else
                        {
                             if($n("#upsellSelectProduct2").val()=='select')
                                  {
                                     finalresult=false;
                                     error +='Please select upsell product.' +'\r\n'; 
                                     if(foc==1)
                                      {
                                        focus='upsellSelectProduct2'; 
                                         foc=0;
                                      }  
                                  }
                                
                                if($n("#Upsell3Selectyes").val()=='select')
                                 {
                                     finalresult=false;
                                     error +='Please select what to show on yes button.' +'\r\n'; 
                                     if(foc==1)
                                      {
                                        focus='Upsell3Selectyes'; 
                                         foc=0;
                                      }  
                                
                                }
                                else if($n("#Upsell3Select").val()=='select')
                                 {
                                     finalresult=false;
                                     error +='Please select what to show on no button.' +'\r\n'; 
                                     if(foc==1)
                                      {
                                        focus='Upsell3Select'; 
                                         foc=0;
                                      }                                        
                                
                                }
                                else if($n("#Upsell3Select").val()=='thirdupsell' || $n("#Upsell3Selectyes").val()=='thirdupsell')
                                {
                                       if($n("#plus3").val()=='false' || ! is_valid_URL($n("#upsellpagelink3").val()))
                                         {
                                            finalresult=false;
                                             error +='Please enter url and click on add button' +'\r\n'; 
                                             if(foc==1)
                                              {
                                                focus='upsellpagelink3'; 
                                                 foc=0;
                                              }
                                    
                                         }
                                        else
                                         {
                                         
                                                 if($n("#upsellSelectProduct3").val()=='select')
                                                 {
                                                     finalresult=false;
                                                     error +='Please select upsell product.' +'\r\n'; 
                                                     if(foc==1)
                                                      {
                                                        focus='upsellSelectProduct3'; 
                                                         foc=0;
                                                      }  
                                                
                                                }
                                         
                                         
                                         } 
                                         
                                
                                } 
                        
                        } 
                   }   
                      
              if(error!='')
              {
                    alert(error);
                    $n("#" + focus).focus()
                     return false;
              }
             else
               return true; 
            } 
      
      }
        
    $n().ready(function() {  
    
      var plus1=$n("#plus1").val();
      var plus2=$n("#plus2").val();
      var plus3=$n("#plus3").val();
      if(plus1=='true')
       {
         productPlus1();
       }
       
      if(plus2=='true')
       {
         
         productPlus2();
         showHideSecondUpsell('secondUpsell');
       }
       
      if(plus3=='true')
       {
         productPlus3();
         showHideThirdUpsell('thirdupsell');
       }
       
        
       
       
        $n("#btn_submit").click(function() {
          
             var validate=validateForm();
             
             if(validate)
              {
                   var proId='{/literal}{$main_product_id}{literal}';
                   var FirstLevelProductId=0;
                   var SecondLevelProductId=0;
                   var ThirdLevelProductId=0;
                   
                   var plus1=$n("#plus1").val();
                   var plus2=$n("#plus2").val();
                   var plus3=$n("#plus3").val();
                   if(plus1=='true')
                     FirstLevelProductId=$n("#upsellSelectProduct1").val();
                   
                   if(plus2=='true')
                     SecondLevelProductId=$n("#upsellSelectProduct2").val();
                   
                   if(plus3=='true')
                     ThirdLevelProductId=$n("#upsellSelectProduct3").val();
                     
                   var web_url='{/literal}{$WEB_URL}{literal}';
                   var str ='main_product_id='+ proId +'&FirstLevelProductId='+ FirstLevelProductId + '&SecondLevelProductId=' + SecondLevelProductId + '&ThirdLevelProductId='+ThirdLevelProductId ;
                      
                       $n.ajax({
                       type: "POST",
                       url: web_url+"/includes/is_upsell_price_is_ok.php",
                       data: str,
                       success: function(msg){
                        if(msg!='false')
                        {
                          $n("#btn_submit").attr('disabled', 'disabled');
                          var returndt=parseFloat(msg);
                            if(returndt<=10000)
                              $n('#frmproductupsell').submit();
                            else
                               {
                                $n("#er").html('');
                                alertDiv='<div class="errormsg" style="width:500px">All upsell product price sum can not more then $10,000</div>';
                                $n("#er").append(alertDiv);
                                $n("#btn_submit").attr('disabled', '');
                                return false;
                               }
                            
                          } 
         
                      }
                 });

              }
     });
     
    });  
   
     $n("#btnDel").click(function() {
        var proId='{/literal}{$main_product_id}{literal}';         
        var answer = confirm ("Are you sure to delete this product upsell ?");
        if(answer)
            window.location='admin_product_upsell_m.php?action=delete&main_product_id=' + proId;       
     
     });
 
   
        $n("#btn_updatefrompaygear").click(function() {
        var proId='{/literal}{$main_product_id}{literal}';         
        window.location='admin_product_upsell_m.php?action=update_from_paygear&main_product_id=' + proId;       
     
     }); 
    
   $n(document).ajaxStart($n.blockUI).ajaxStop($n.unblockUI);    
 </script>
       

 {/literal}

{$ADMIN_FOOTER}
Return current item: MembersGear