get recurring dates between two dates and periods php codeigniter

	public function getRecurringDates($start_date,$period,$weekdayNumbers = [])
	{
		$end_date = date("Y-m-d", strtotime("+$period days", strtotime($start_date)) );

	    $dateArr = array();

	    foreach ($weekdayNumbers as $key => $weekdayNumber) {


			$startDate = strtotime($start_date);
		    $endDate = strtotime($end_date);

	    	do
		    {
		        if(date("w", $startDate) != $weekdayNumber)
		        {
		            $startDate += (24 * 3600); // add 1 day
		        }
		    } while(date("w", $startDate) != $weekdayNumber);


		    while($startDate <= $endDate)
		    {
		        $dateArr[] = date('Y-m-d', $startDate);
		        $startDate += (7 * 24 * 3600); // add 7 days
		    }

	    }
		    
	    return($dateArr);
	}

        // die('lol');
	$event_id = (isset($_POST['event_id']))? $_POST['event_id'] : 331; 
	$start_date = (isset($_POST['event_start_date']))? $_POST['event_start_date'] : '2017-04-15';
	$period = (isset($_POST['event_period']))? $_POST['event_period'] : 60;
	$weekdayNumbers = (isset($_POST['event_id']) && is_array($_POST['event_id']))? $_POST['event_id'] : [0,2];

	$dateArr = $this->getRecurringDates($start_date, $period, $weekdayNumbers);
		

dublicate a child table rows and parent table rows mysql [CodeIgniter]


    // call to model to model ...
    public function duplicateTableRecord ($table, $keys = [],$ignore_key) 
    {
       /* generate the select query */
       if (is_array($keys)) {
           foreach ($keys as $key_field => $key_val) {

               $this->db->where($key_field, $key_val); 
           
           }
       }
       // return var_dump($keys);
       $query = $this->db->get($table);
      
        foreach ($query->result() as $row){   
           foreach($row as $key=>$val){        
              if($key != $ignore_key){ 
              /* $this->db->set can be used instead of passing a data array directly to the insert or update functions */
              $this->db->set($key, $val);               
              }//endif              
           }//endforeach
        }//endforeach

        /* insert the new record into table*/
        $this->db->insert($table); 
        return $this->db->insert_id();
    }

    public function duplicateForeignTableRecord ( $table, $foreign_keys_vals = [],$ignore_key,$update_keys_vals = [] ) 
    {
       /* generate the select query */
       if (is_array($foreign_keys_vals)) {
           foreach ($foreign_keys_vals as $key_field => $key_val) {

               $this->db->where($key_field, $key_val); 
           
           }
       }
       // $this->db->where($foreign_key_field, $foreign_key_val); 

       $query = $this->db->get($table);
      
        foreach ($query->result() as $row){   
           foreach($row as $key => $val){        
              if($key != $ignore_key){ 
              /* $this->db->set can be used instead of passing a data array directly to the insert or update functions */
                $this->db->set($key, $val);               
              }
              foreach ($update_keys_vals as $up_f_key => $up_f_val) {
                  if($key == $up_f_key){
                    $this->db->set($key, $up_f_val); 
                  }
              }
              //endif              
           }//endforeach

           $this->db->insert($table);
        
        }//endforeach

        /* insert the new record into table*/
         
        return $this->db->insert_id();
    }

    // call to function to from controller to model class. 
    public function clone_product($id)
    {
        $product_insert_id = $this->duplicateTableRecord(
            'product',
            ['id_product' => $id],
            'id_product'
        );

        $insert_id = $this->duplicateForeignTableRecord(
            'product_join_category',
            ['id_product' => $id],
            'id_product',
            [ 'id_product' => $product_insert_id ]
        );

        $insert_id = $this->duplicateForeignTableRecord(
            'product_data',
            ['id_product' => $id],
            'id_product_data',
            [ 'id_product' => $product_insert_id ]
        );
        
        $insert_id = $this->duplicateForeignTableRecord(
            'file',
            [ 'id_product' => $id ],
            'id_file',
            [ 'id_product' => $product_insert_id ]
        );
        
        $insert_id = $this->duplicateForeignTableRecord(
            'metatag',
            [ 'section_item_id' => $id, 'section' => 'product' ],
            'id_meta',
            [   'section_item_id' => $product_insert_id ]
        );

        return $product_insert_id;
    }

    // call to the model from controller 
    public function copy($id = '')
    {
        if ($id != '') {

            $record = $this->b_product_model->clone_product($id);
        
        }
        
        // _trace($record);
        redirect(base_url() . 'admin/produkty');
    }

[php] Breadcrumbs for Codeigniter in the helper function

function _breadcrumbs()
{
    $ci = & get_instance();
    $urlSegment = $ci->uri->segment_array();

    if (($key = array_search("product", $urlSegment)) !== false) {
        unset($urlSegment[$key]);
    }
    if (($key = array_search("products", $urlSegment)) !== false) {
        unset($urlSegment[$key]);
    }
    if (($key = array_search("product-category", $urlSegment)) !== false) {
        unset($urlSegment[$key]);
    }

    // print_r($urlSegment);

    $breadcrumbs = '<div class="row">
            <div class="col-sm-12">
                <p class="breadcrumb"><a href="" title=""><img src="' . base_url() .'assets/frontend/img/home.svg" alt="" /></a> ';

    foreach ($urlSegment as $key => $segment) {
        $breadcrumbs .= '<img src="'. base_url() .'assets/frontend/img/gt.png" alt="" /> '. ucfirst($segment) . ' ';
    }

    $breadcrumbs .= '</p>
            </div>
        </div>';

    echo $breadcrumbs;
}

Ajax Search PHP through MySQL record


var searchRequest = null;

$(function () {
    var minlength = 3;

    $("#spedostech_search").keyup(function () {
        var that = this,
        value = $(this).val();

        if (value.length >= minlength ) {
            if (searchRequest != null) 
                searchRequest.abort();

            console.log( );
            // return;
            
            searchRequest = $.ajax({
                type: "GET",
                url: BASE_URL + "spedostech/search",
                data: {
                    'search_keyword' : value
                },
                dataType: "json",
                success: function(msg){
                    // var obj = JSON.stringify(msg);
                    console.log(msg);
                    //we need to check if the value is the same
                    if (value==$(that).val()) {
                        var container = $('<ul />');
                        $.each( msg, function( section, List ) {
                          var li = $('<li>Nalezeno v '+section+' (3)</li>');

                          // container.append('<li>Nalezeno v '+section+' (3)</li>');
                          // console.log( section + " : ");
                          var ul = $('<ul />');
                          $.each( List, function( key, item ) {
                            ul.append('<li><a href="#'+item.id+'" title="">'+item.name+'</a></li>');
                            // console.log("Name : " + item.name);
                          });
                          li.append(ul);
                          container.append(li);  
                        });

                    // console.log(container);
                        // $('#tt').html(container);
                        $('#search-whisperer').html(container);

                    //Receiving the result of search here
                    }
                }
            });
        }
    });
});



Photo Collage [PHP]


<?php if (!empty($entry['photos'])) {
?>
<div class="crispbx">
    <div class="crispcont1">

        <!-- <p> -->
        <?php 
            // echo "string";
            $i = 0;
            if (count($entry['photos']) <= 9) {
                $linhas = floor(count($entry['photos']) / 3);
                $resto = count($entry['photos']) % 3;

                $tam1h = '143px';
                $tam2h = '216.5px';
                $tam3h = '436px';
                                                            
                $tam1w = '32.8%';
                $tam2w = '49.2%';
                $tam3w = '99.1%';
                
            }
            $photoDiv .= '<div class="wall_photoboard">';
            $i = 1;
            foreach ($entry['photos'] as $path) {

                if ($i <= ($linhas * 3)) {
                    // $tamAtual = $tam1;

                    $tamAtual = $tam1w;
                    $tamAtualh = $tam1h;   

                } else {
                    if ($resto == 2) {
                        // $tamAtual = $tam2;

                        $tamAtual = $tam2w;
                        $tamAtualh = $tam2h;

                    } else 
                        // $tamAtual = $tam3;

                        $tamAtual = $tam3w;
                        $tamAtualh = $tam3h;

                }

                $margin = 'margin: 2px 0 0 2px';
                if (count($entry['photos']) == 1) {
                    $margin = 'margin: 0';
                    $tamAtualh = '100%';
                    $tamAtual = '100%';
                }
                $photoDiv .= '<a class="mid2wall" href="photo_detail.php?id=' . $path['id'] . '" ><img  style="width: ' . $tamAtual . '; height: ' . $tamAtualh . '; border-radius:px;' . $margin .';border:1px solid #ccc !important;"  src="uploads/' . $path['file'] . '"/></a>';
                $i++;
                if ($i >= 9 && count($entry['photos']) > 9) {
                    $photoDiv .= ' and ' . (count($entry['photos']) - 9) . ' more photos';
                    break;
                }

            }
            $photoDiv .= '</div>';

            echo $photoDiv;

            $photoDiv = '';

         ?>

Error reporting management snippets in php [dev/prod]

/*
 *---------------------------------------------------------------
 * APPLICATION ENVIRONMENT
 *---------------------------------------------------------------
 *
 * You can load different configurations depending on your
 * current environment. Setting the environment also influences
 * things like logging and error reporting.
 *
 * This can be set to anything, but default usage is:
 *
 *     development
 *     testing
 *     production
 *
 * NOTE: If you change these, also change the error_reporting() code below
 */
	define('ENVIRONMENT', isset($_SERVER['CI_ENV']) ? $_SERVER['CI_ENV'] : 'development');

/*
 *---------------------------------------------------------------
 * ERROR REPORTING
 *---------------------------------------------------------------
 *
 * Different environments will require different levels of error reporting.
 * By default development will show errors but testing and live will hide them.
 */
switch (ENVIRONMENT)
{
	case 'development':
		error_reporting(0);
		// error_reporting(-1);
		ini_set('display_errors', 1);
		ini_set('max_execution_time', -1);
	break;

	case 'testing':
	case 'production':
		ini_set('display_errors', 0);
		if (version_compare(PHP_VERSION, '5.3', '>='))
		{
			error_reporting(E_ALL & ~E_NOTICE & ~E_DEPRECATED & ~E_STRICT & ~E_USER_NOTICE & ~E_USER_DEPRECATED);
		}
		else
		{
			error_reporting(E_ALL & ~E_NOTICE & ~E_STRICT & ~E_USER_NOTICE);
		}
	break;

	default:
		header('HTTP/1.1 503 Service Unavailable.', TRUE, 503);
		echo 'The application environment is not set correctly.';
		exit(1); // EXIT_ERROR
}

Price Calculation with php depending on tax and discount price and percentage


function priceCalc($price, $discount_price, $discount_percent, $id_tax = -1)
{
    // $baseTax = _s("shop-base-tax");
    // $priceType = _s("shop-base-price");

    $baseTax = 21;
    $priceType = 1;

    // $ci = & get_instance();
    // $ci->load->database();

    // if( $id_tax != -1 ){
    //     $ci->db->select('t.*')
    //         ->from("tax as t")        
    //         ->where("id_tax", $id_tax);    
    //     $query = $ci->db->get();
    //     $baseTax = $query->row()->value;
    // }

    // return var_dump($baseTax);

    // $baseTax = 15;

    $tax = $baseTax; /* == $data_tax->value ? $baseTax : $data_tax->value; */

    $result = new stdClass();
    $result->oldPrice =  $price;

    // return $result->oldPrice;

    if ($discount_price > 0) {
        //samotná hodnota daně
        $taxvalue = ($discount_price / 100) * $tax;

        if ($priceType) {
            $result->newPrice = $discount_price + $taxvalue;
        } else {
            $result->newPrice = $discount_price;
        }
        $result->switch = 1;
    } elseif ($discount_percent > 0) {
        //samotná hodnota daně
        // $taxvalue = ($price / 100) * $tax;
        $taxvalue = ($result->oldPrice / 100) * $tax;


        if ($priceType) {
        	$result->oldPrice = (( $tax + 100 ) / 100 ) * $price;
            // $result->newPrice = $price - ((($price + $taxvalue) / 100) * $discount_percent);
            $result->newPrice = $result->oldPrice - ( ($result->oldPrice / 100) * $discount_percent);
        } else {
            $result->newPrice = $price - (($price / 100) * $discount_percent);
        }

        $result->switch = 1;
    } else {
        //samotná hodnota daně
        // $taxvalue = ($price / 100) * $tax;
        $taxvalue = ($result->oldPrice / 100) * $tax;
        

        if ($priceType) {
        	$result->oldPrice = (( $tax + 100 ) / 100 ) * $price;
            // $result->newPrice = $price + $taxvalue;
            $result->newPrice = $result->oldPrice;
        } else {
            $result->newPrice = $price;
        }
        //        $result->newPrice = $price;
        $result->switch = 0;
    }
    //    $priceFormat = number_format(, 2);
    $priceRound = (int) round($result->newPrice);
    //    $priceReplace = str_replace(",", " ", $priceRound);
    $result->newPrice = $priceRound;

    return $result;
}

var_dump(priceCalc(3469,0,30));