mercredi 28 novembre 2018

Images with PHP and checkboxes

I want to learn how to display combined images with help of checkboxes. Lets say I have three images, the first one is a car, second one is a new wheels for the car, third tinted windows. I always display the original image of the car on the website, but lets say if I click the box for new wheels it appears on the car image or if I click tinted windows box, tinted windows appear on the car. The images are prepared with photoshop and stored in folder, simple stuff.

<form action="#" method="post">
<input type="checkbox" name="option" value="Wheels">Wheels</input>
<input type="checkbox" name="option" value="Tint">Windows</input>
<input type="submit" name="submit" value="Submit"/>
</form>
<?php
if (isset($_POST['option'])){
 // Display.
}
?>

I made a simple form so far and lets say as I said if I check Wheels, the wheels appear on the car, I uncheck it they disappear. Same with Windows. But how can I go about doing that lets say if I had 10 items I would not need to hard code a lot of statements? I am not asking for a code, but just ideas how to do it, because my idea is to hard code many if statements.

R - combining ifelse and substr

My sample data is:

df <- as.data.frame(c("10M_Amts", "D2B_Exp", "D3C_Exp", "D2_Amt", "D5_Amt", "53D_Amt"))
colnames(df) <- c("Label")

I'd like to adhere to the following rule:

If the first 2 letters are either D2, D3, D4, D5 or if the first 3 letters are D1A or D1_ then I would like to return the word "Work" in a new column called Work. If not, then return "NA".

I've searched around but wasn't able to find an example of dplyr combining ifelse and multiple substr commands. My attempted code using dplyr is:

df2 <- df %>%
       mutate(WRE = ifelse(substr(Label, 1, 3) == c("D1_", "D1A") |
                           substr(Label, 1, 2) == c("D2", "D3", "D4", "D5"), Work, "NA"))

As you can observe, there are multiple OR's going on for example for the first three strings I attempted to use c("D1_", "D1A") to represent D1_ or D1A. This is the same for the first two strings c("D2", "D3", "D4", "D5") to represent D2 or D3 or D4 or D5. In all, if there is D1_ or D1A or D2 or D3 or D4 or D5 in the first 2 or 3 letters, then it should return "Work" and if not, "NA". However, using substr function I resorted to split both of these categories.

My ideal output is:

     Label       Work
1   10M_Amts      NA
2   D2B_Exp      Work
3   D3C_Exp      Work
4   D2_Amt       Work
5   D5_Amt       Work
6   53D_Amt       NA

As you can see the new column name is Work. In excel, I would write the following:

=IF(OR(LEFT(A1,3)="D1_",LEFT(A1,3)="D1A",LEFT(A1,2)={"D2","D3","D4","D5"}), 
"Work", "")

where column A is the Label column as per above. Sorry for the small sample, this worked when I did this in excel for ~5000 rows and for multiple categories other than "Work" but because the sheet will be too big, we'd like to convert to R.

Thank you so much in advance!

c# select new with an if statement inside

I have this piece of code that select new some info from the database in my c# project but i only want it to do it if the name is not a certain name so here is the code

public List<Info> GetInfo(int id)
    {
        var cacheKey = "allinfo-" + id;
        var info = SoftCache.GetData<List<info>>(cacheKey);
        if (info != null)
            return info;

        using (var db = DB.InfoModel)
        {
            info = (from j in db.info_list()

                        select new Info
                        {
                            InfoName = j.info_name,
                            InfoId = j.info_id,
                            InfoValue = j.info_value,
                        }).ToList();
        }

        SoftCache.Add(cacheKey, info, new TimeSpan(0, 0, 5), new TimeSpan(0, 1, 0));
        return info;
    }

what i want is something like

if(j.info_name != "BadName"){
            select new Info
                            {
                                InfoName = j.info_name,
                                InfoId = j.info_id,
                                InfoValue = j.info_value,
                            }).ToList();
}

Sql is one of my weak areas tried with some case when but cant seem to get it to work with select new.

Statements out of function, but where?

Trying to get my last assignment in for the quarter, balance my job, and my other class. I would love an extra set of eyes to tell me where in the world my statements go out outside of my function:

This is an implementation file. The associated header is throwing no errors.

I get the following errors:

1.) In file included from tests.cpp:7:0: GBoard.cpp:31:2: error: expected unqualified-id before ‘for’ for(int r=0;r<15;r++) ^~~

2.) GBoard.cpp:31:14: error: ‘r’ does not name a type for(int r=0;r<15;r++) ^

But I am pretty sure 2 is part of my code being outside of the function somehow.

Here is my code, parts redacted so I don't get hit w/ plagiarism:

bool Gfunction::makeMove(int redacted,int redacted,char secret)
{

    if(redacted >= 0 && redacted < 15 && redacted >= 0 && redacted<15)
    {
        if(redacted() == UNFINISHED && function[redacted][redacted] == '.')
        function[redacted][redacted] = secret;
        return true;
    }   
        else
    {
        return false;

    }

    int track = 0;


    for(int r=0;r<15;r++)
    {
        track = 0;
            for(int c=0;c<15;c++)
            {
                    if(function[r][c] == secret)
                    {
                track++;
                    if(track==5)
                        {
                                if(secret == 'x')
                                secret squirrel stuff = X_WON;
                                else
                            secret squirrel stuff = O_WON;
                                return true;
                    }
                }
                else
                {
                    track = 0;
                }
        }

    }   



    for(int r=0;r<15;r++)
    {
            track = 0;
            for(int c=0;c<15;c++)
            {
                    if(function[r][c] == secret)
                    {  
                        track++;
                        if(track==5)
                        {
                            if(secret == 'x')
                                secret squirrel stuff = X_WON;
                                else
                                secret squirrel stuff = O_WON;
                                return true;
                        }

                    }
                        else
                    {
                            track = 0;
                    }
            }

    }



        int r = 0, c = 0;
        for(int redacted = 0; redacted<15; redacted++)
        {
            r = redacted;
                c = 0;
                track = 0;
                while(r < 15 && c < 15)
                {
                    if(function[r][c] == secret)
                    {
                        track++;
                        if(track == 5)
                        {
                                if(secret == 'x')
                                secret squirrel stuff = X_WON;
                                else
                                secret squirrel stuff = O_WON;
                                return true;
                        }
                }
                        else
                        {
                                track = 0;
                        }
                                r++;
                                c++;
        }
    }

    for(int redacted = 0; redacted<15; redacted++)
    {
            r=0;
            c=redacted;
            track=0;
            while(r<15 && c<15)
                {
                    if(function[r][c] == secret)
                    {
                            track++;
                            if(track == 5)
                            {
                                if(secret == 'x')
                                secret squirrel stuff = X_WON;
                                else
                                secret squirrel stuff = O_WON;
                                return true;
                        }
            }
                        else
                        {
                                track = 0; 
                        }
                                r++;
                                c++;
                }
        }


    for(int redacted=0; redacted<15; redacted++)
    {
        r=redacted;
        c=15-1;
        track=0;
        while(r<15 && c>=0)
        {
                    if(function[r][c] == secret)
                    {
                        track++;
                        if(track == 5)
                {
                    if(secret == 'x')
                            secret squirrel stuff = X_WON;
                            else
                            secret squirrel stuff = O_WON;
                            return true;
                        }
            }
                            else
                    {
                            track = 0;
                    }
                            r++;
                            c--;
        }
    }


    for(int redacted=15-1;redacted>=0;redacted--)
    {
            r=0;
            c=redacted;
            track=0;
            while(r<15 && c>= 0)
            {
                    if(function[r][c] == secret)
                    {
                        track++;
                        if(track == 5)                    
                        {
                                if(secret == 'x')
                                secret squirrel stuff = X_WON;
                                else
                                secret squirrel stuff = O_WON;
                                return true;
                        }
            }
                        else
                        {
                            track = 0;
                        }
                            r++;
                            c--;
            }
        } 


    for(int r=0;r<15;r++)
    {
            for(int c=0;c<15;c++)
            {
            if(function[r][c] == '.')
                {
                    secret squirrel stuff = UNFINISHED;
                    return true;
            }
        }
    }  
        secret squirrel stuff = DRAW;
        return true;
}

mardi 27 novembre 2018

How to build widgets based on if-else statement?

I need to build a widget based on the data as example shown below. I need to run the CircularProgressIndicator first. My problem is that I need to get data from Server 1. If Server 1 has no data stop CircularProgressIndicator and show “No Registration Found” Widget. If Server 1 has data then get details data from Server 2. If Server 2 has no data show “Temporarily Data is not available” Widget. If Server 2 has Data then show "Server 2 Data Widget"

Run loading animation widget (CircularProgressIndicator)
    - Get Data from Server 1
        - If Server 1 Data is okay
            - Get Data from Server 2 using Server 1 Data item value
                - If Server 2 Data is okay
                    - Show Server 2 Data Widget
                - Else
                    - Show “Temporarily Data is not available” Widget
       - Else
            - Show “No Registration Found” Widget

I try to create a Boolean variable and in main build Widget I try to show the page. But I am keep getting error and keep shows the “No Registration Found” Widget and few seconds later when I ger Server 2 Data using setState it shows the "Server 2 Data Widget". But it never shows the CircularProgressIndicator. Any idea how to build the widgets base on the if else statement as I explained above.

bool _runLoading = true;
bool _data1 = false;
bool _data2 = false;

    return _runLoading == true
        ? _buildLoadingAnimation
        : _data2 == true
          ? _buildServer2Data
          : _buildNoDataFound

php if statement argument in laravel

I have a calculation to make which the variable $totalPercent might be a 0 so I added some if statements to the script to only run since the initial returned with an error on division by zero on some occasion.

This was the newly revised calculation, which now works when $totalPercent is a 0, but when it has a value and the supposed script is called, it returned me an error of Undefined variable: designPercent

Here is the new script with the added if statement that was meant to do calculation only if $totalPercent is more than 0.

@if ($totalnumerical > '0')
    $totalPercent= '100' / $totalnumerical;
    $stylePercent= ($styletempt *  $totalPercent).'%';
    $designPercent= ($designtempt * $totalPercent).'%';
    $managePercent= ($managetempt * $totalPercent).'%';
    <div class="graphSection">
        <div class="skillGraph">
            <span style="width:" class="bar-1"></span>
            <span style="width:" class="bar-2"></span>
            <span style="width:" class="bar-3"></span>
        </div><br>
        <div class="skillGraph graph_text">
            @if(($designtempt * $totalPercent) > 15)
                <span style="width:" >Design</span>
            @else
                <span class="hovertext" style="width:; margin-top:-57px" >Design</span>
                <span style="width:" ></span>
            @endif
            @if(($styletempt * $totalPercent) > 15)
                <span style="width:" >Interior Styling</span>
            @else
                <span class="hovertext" style="width:; margin-top:-67px;" >Interior Styling</span>
                <span style="width:" ></span>
            @endif
            <span style="width:" >Project Management</span>
        </div>
    </div>

@endif

"Dynamic" if-else statement with jQuery

I'm not understanding how to accomplish this without hardcoding an if else statement.

I have two table examples. One has 4 quantity breaks and the other has 5 quantity breaks below. Some may have 1,2,3,4,5,6,7,8,9, and up to 10.

I also have an input box for the quantity the customer wants to buy. When the quantity break is updated and it is within another quantity break I want to "do this" (which isn't my problem) it's the dynamic if-else statement that I'm unsure how to build.

I'm looking for a solution that will 1) Add up the number of quantity breaks. In these two examples it's 4 and 5. 2) Create an if - else if where the last else if will be => 99999. Or can I create an infinite => ??? Sorry I'm new to jQuery. 3) Not allow me to order less than minimum quantity - first quantity break (I have a button that says add to order... I tried an on click function but it alerts twice, so annoying!)

Maybe this will help: As the front-end user, when I enter in a number with a different quantity break I should only see the option code that is available for that quantity break so that the price matches the quantity break.

I've put together this:

 text1 =$('.priceGrid > thead > tr > th:eq(1)').text(); 
 number1 = parseInt(text1,10);
 text2 =$('.priceGrid > thead > tr > th:eq(2)').text();
 number2 = parseInt(text2,10);
 text3 =$('.priceGrid > thead > tr > th:eq(3)').text();
 number3 = parseInt(text3,10);
 text4 =$('.priceGrid > thead > tr > th:eq(4)').text();
 number4 = parseInt(text4,10);
 number10 = number2-1;
 number20 = number3-1;
 number30 = number4-1;

//find all unique option codes
tab_attribs = [];
$('[name^=optionCode_]').each(function () {
  tab_attribs.push( $(this).attr("value") );
});
//var unique;
unique = $.grep(tab_attribs, function(v, i) {
    return $.inArray(v, tab_attribs) === i
});

//count how many price breaks
//var size;
size = $('.priceGrid > thead > tr > th').size();
$('.qty_input').keyup(function(){
    value = $('.qty_input').val();
});

if (size === 5){
$('.qty_input').keyup(function () {
       //var value = $('.qty_input').val();

       if (value >= number1 && value <= number10){

           $('.productOptionName .option').addClass('hide-option'),
           $("select[name^="+unique[0]+"]").parent().parent().parent().removeClass('hide-option');
       }
       else if (value >= number2 && value <= number20){

           $('.productOptionName .option').addClass('hide-option'),
           $("select[name^="+unique[1]+"]").parent().parent().parent().removeClass('hide-option');
       }
           else if (value >= number3 && value <= number30){

           $('.productOptionName .option').addClass('hide-option'),
           $("select[name^="+unique[2]+"]").parent().parent().parent().removeClass('hide-option');
       }
       else if (value >= number4 && value <= 999999){

           $('.productOptionName .option').addClass('hide-option'),
           $("select[name^="+unique[3]+"]").parent().parent().parent().removeClass('hide-option');
       }
   
//else if (size === 4) {}
   }); 
<div class="qty_input_wrapper">
   <input type="text" autocomplete="off" maxlength="5" value="25" class="qty_input form-control" name="quantity_610597" id="quantity_610597">
   <input type="hidden" value="610597" name="product.id" id="productId">
   <div name="show_inventory" id="show_inventory" style="text-align:center;">
   </div>
</div>
table.priceGrid thead tr th {
  font-weight: bold;
  background: #F2F2F2;
  text-align: center;
}

table.priceGrid tbody tr th {
  font-weight: bold;
  background: #F2F2F2;
  text-align: center;
}

table.priceGrid tbody tr td {
  font-weight: normal;
  text-align: center;
}

table.priceGrid tbody tr.saving_percentage th {
  color: red;
}

table.priceGrid tbody tr.saving_percentage td {
  color: red;
}

table.priceGrid tr th.disabled,
table.priceGrid tr td.disabled {
  position: relative;
  opacity: 0.7;
  filter: alpha(opacity=70);
}

table.priceGrid tr th.disabled:before,
table.priceGrid tr td.disabled:before {
  display: block;
  content: "";
  background: repeating-linear-gradient(45deg, transparent, transparent 5px, #000 5px, #000 10px);
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  bottom: 0;
  width: 100%;
  height: 100%;
  opacity: 0.2;
  filter: alpha(opacity=20);
}
<table class="priceGrid table table-bordered">
  <thead>
    <tr>
      <th>Quantity</th>
      <th>
        25+
      </th>
      <th>
        50+
      </th>
      <th>
        100+
      </th>
      <th>
        250+
      </th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th scope="row">Price</th>
      <td style="color: #000000;">
        <span class="prod-price">
                $28.10
                </span>
      </td>
      <td style="color: #000000;">
        <span class="prod-price">
                $26.38
                </span>
      </td>
      <td style="color: #000000;">
        <span class="prod-price">
                $24.97
                </span>
      </td>
      <td style="color: #000000;">
        <span class="prod-price">
                $23.83
                </span>
      </td>
    </tr>
    <tr class="saving_percentage">
      <th scope="row">You Save</th>
      <td>
        -
      </td>
      <td>
        <span class="prod-price">
                $1.72
                </span> (6.12%)
      </td>
      <td>
        <span class="prod-price">
                $3.13
                </span> (11.14%)
      </td>
      <td>
        <span class="prod-price">
                $4.27
                </span> (15.20%)
      </td>
    </tr>
  </tbody>
</table>
<span>OR</span>
<div class="priceGridWrapper table-responsive">
  <table class="priceGrid table table-bordered">
    <thead>
      <tr>
        <th>Quantity</th>
        <th>
          48+
        </th>
        <th>
          96+
        </th>
        <th>
          192+
        </th>
        <th>
          384+
        </th>
        <th>
          768+
        </th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <th scope="row">Price </th>
        <td style="color: #000000;">
          $10.94
        </td>
        <td style="color: #000000;">
          $10.55
        </td>
        <td style="color: #000000;">
          $10.06
        </td>
        <td style="color: #000000;">
          $9.40
        </td>
        <td style="color: #000000;">
          $9.00
        </td>
      </tr>
      <tr class="saving_percentage">
        <th scope="row" style="color:#1FA814;">Quantity Savings</th>
        <td style="color:#1FA814;">
          -
        </td>
        <td style="color:#1FA814;">
          $0.39 (3.56%)
        </td>
        <td style="color:#1FA814;">
          $0.88 (8.04%)
        </td>
        <td style="color:#1FA814;">
          $1.54 (14.08%)
        </td>
        <td style="color:#1FA814;">
          $1.94 (17.73%)
        </td>
      </tr>
    </tbody>
  </table>
</div>

Here is a snippit of all the option codes... this is what I'm working with. I don't have access to the java, I need to do this with jQuery. I don't have any real syntax knowledge of Javascript, I know that's weird...

I know that only one of the option codes has a different price, it won't always be that way. Sometimes they will sometimes they won't. My main goal is to think of a way where I don't have to hardcode any of this.

<div class="product_options">
   <div class="productOptionName">
      <input type="hidden" name="optionCode_610597_" value="BENTO8">
      <input type="hidden" name="optionCode_610597" value="BENTO8">
      <div class="option">
         <label for="" class="control-label fs-16">M&amp;Ms:</label>
         <input type="hidden" name="BENTO8-option_610597" value="0">
         <div class="row">
            <div class="col-sm-8 col-md-7 col-lg-6">
               <select class="form-control" name="BENTO8-option_values_610597_0" onchange="showAttachmentInput('0', this.value)" id="PRODUCT-610597-0">
                  <option class="opt" value="0" id="OPTION-610597-0-0-0">
                     No
                  </option>
                  <option class="opt" value="1" id="OPTION-610597-0-0-1">
                     Yes + $2.89
                  </option>
                  <option class="opt" value="2" id="OPTION-610597-0-0-2">
                     Yes + $2.89
                  </option>
                  <option class="opt" value="3" id="OPTION-610597-0-0-3">
                     Yes + $2.89
                  </option>
                  <option class="opt" value="4" id="OPTION-610597-0-0-4">
                     Yes + $2.89
                  </option>
               </select>
            </div>
         </div>
      </div>
      <input type="hidden" name="optionCode_610597_" value="BENTO8">
      <input type="hidden" name="optionCode_610597" value="BENTO8">
      <div class="option">
         <label for="" class="control-label fs-16">Espresso Coffee Beans:</label>
         <input type="hidden" name="BENTO8-option_610597" value="1">
         <div class="row">
            <div class="col-sm-8 col-md-7 col-lg-6">
               <select class="form-control" name="BENTO8-option_values_610597_1" onchange="showAttachmentInput('1', this.value)" id="PRODUCT-610597-1">
                  <option class="opt" value="0" id="OPTION-610597-1-1-0">
                     No
                  </option>
                  <option class="opt" value="1" id="OPTION-610597-1-1-1">
                     Yes + $4.34
                  </option>
                  <option class="opt" value="2" id="OPTION-610597-1-1-2">
                     Yes + $4.34
                  </option>
                  <option class="opt" value="3" id="OPTION-610597-1-1-3">
                     Yes + $4.34
                  </option>
                  <option class="opt" value="4" id="OPTION-610597-1-1-4">
                     Yes + $4.34
                  </option>
               </select>
            </div>
         </div>
      </div>
      <input type="hidden" name="optionCode_610597_" value="BENTO8">
      <input type="hidden" name="optionCode_610597" value="BENTO8">
      <div class="option">
         <label for="" class="control-label fs-16">Optional Inside Label Run Charge:</label>
         <input type="hidden" name="BENTO8-option_610597" value="2">
         <div class="row">
            <div class="col-sm-8 col-md-7 col-lg-6">
               <select class="form-control" name="BENTO8-option_values_610597_2" onchange="showAttachmentInput('2', this.value)" id="PRODUCT-610597-2">
                  <option class="opt" value="0" id="OPTION-610597-2-2-0">
                     No
                  </option>
                  <option class="opt" value="1" id="OPTION-610597-2-2-1">
                     Yes + $50.00
                  </option>
                  <option class="opt" value="2" id="OPTION-610597-2-2-2">
                     Yes + $1.75
                  </option>
                  <option class="opt" value="3" id="OPTION-610597-2-2-3">
                     Yes + $1.50
                  </option>
                  <option class="opt" value="4" id="OPTION-610597-2-2-4">
                     Yes + $1.25
                  </option>
               </select>
            </div>
         </div>
      </div>
      <input type="hidden" name="optionCode_610597_" value="BENTO8">
      <input type="hidden" name="optionCode_610597" value="BENTO8">
      <div class="option">
         <label for="" class="control-label fs-16">Laser Engraving Run Charge (Silver Only):</label>
         <input type="hidden" name="BENTO8-option_610597" value="3">
         <div class="row">
            <div class="col-sm-8 col-md-7 col-lg-6">
               <select class="form-control" name="BENTO8-option_values_610597_3" onchange="showAttachmentInput('3', this.value)" id="PRODUCT-610597-3">
                  <option class="opt" value="0" id="OPTION-610597-3-3-0">
                     No
                  </option>
                  <option class="opt" value="1" id="OPTION-610597-3-3-1">
                     Yes + $1.15
                  </option>
                  <option class="opt" value="2" id="OPTION-610597-3-3-2">
                     Yes + $1.15
                  </option>
                  <option class="opt" value="3" id="OPTION-610597-3-3-3">
                     Yes + $1.15
                  </option>
                  <option class="opt" value="4" id="OPTION-610597-3-3-4">
                     Yes + $1.15
                  </option>
               </select>
            </div>
         </div>
      </div>
      <input type="hidden" name="optionCode_610597_" value="BENTO8">
      <input type="hidden" name="optionCode_610597" value="BENTO8">
      <div class="option">
         <label for="" class="control-label fs-16">Heat Transfer Run Charge (Silver Only):</label>
         <input type="hidden" name="BENTO8-option_610597" value="4">
         <div class="row">
            <div class="col-sm-8 col-md-7 col-lg-6">
               <select class="form-control" name="BENTO8-option_values_610597_4" onchange="showAttachmentInput('4', this.value)" id="PRODUCT-610597-4">
                  <option class="opt" value="0" id="OPTION-610597-4-4-0">
                     No
                  </option>
                  <option class="opt" value="1" id="OPTION-610597-4-4-1">
                     Yes + $2.50
                  </option>
                  <option class="opt" value="2" id="OPTION-610597-4-4-2">
                     Yes + $2.50
                  </option>
                  <option class="opt" value="3" id="OPTION-610597-4-4-3">
                     Yes + $2.50
                  </option>
                  <option class="opt" value="4" id="OPTION-610597-4-4-4">
                     Yes + $2.50
                  </option>
               </select>
            </div>
         </div>
      </div>
   </div>
</div>

Thank you.